A rogue-like in 6809 assembly (pt. 2)

Continued from part 1.

Chapter 4 of Assembly Language Programming for the CoCo3 describes several useful video registers. The first one I picked on was $FF9A, the Border Color. Setting this register to 0 cleared my screen border color to black:

lda #0
sta $FF9A

The next challenge is modifying the default palette such that setting the background color of the screen to 0 will make the entire level background go black. Here’s where I am now:

There is a document by Chris Lomont on Color Computer 1/2/3 Hardware Programming that contains details on the color palette registers at $FFB0-$FFBF; 8 background colors followed by 8 foreground colors. Setting $FFB0 to 0 allows me to clear the background to black:

lda #0
sta $FFB0

I think I am ultimately going to reconfigure the palette for this game to approximate DawnBringer’s 16-color palette, as seen here.

One may ask at this point, how do I know what color is associated with each number?

10 WIDTH 80
20 FOR N=0 TO 63
50 A$=INKEY$:IF A$="" GOTO 50

One day I’m going dig up a Color Computer 3 color chart, but somehow this just felt easier. Run the program and hit a key until you find a color you like.

The premise of the game, as of this week, is that you find yourself stuck in a prison cell in an underground orc facility. You have to find some way to break out of the cell, defeat the guards, find the keys to the exit tunnel (and the path to the tunnel itself), and get out. All without starving to death. What’s a rogue-like without a hunger counter?

I pulled the base-10 number writer from my last post, making some adjustments due to high-resolution text memory existing on a different page of memory and needing 2 bytes per character instead of 1.

Each level will use a single screen. Scrolling levels are being pushed to version 2. I am also hoping to store all level data in memory. No saving or loading of game data (also for version 2). If you die you have to start over, but I won’t make you insert another quarter!

An idea I am toying with for managing level data: Rather than storing tile and monster information in an off-screen location, treat the screen itself as the level data. Every visible tile contains 16-bits of data. I may be able to do something like treating the background color as the health counter for monsters. We’ll see.

There is a sound effect that plays when you first start the game, just before the player “@” is shown, and another that plays when the hunger counter goes to 0. These work by first enabling bit-3 at $FF23, then toggling the most significant 6-bits of $FF20. e.g. this example will play the falling siren sound effect I’m using when the player dies:

; Bit-3 enables audio.
PORT_EnableAudio	equ	$FF23

; Top 6-bits control speaker volume.
PORT_Audio		equ	$FF20

; A: Current speaker volume.
; B: Holds the delay; used to control frequency.
; Y: Used to control decay rate.
    ; Turn off IRQ and FIRQ for better sound quality.
	orcc	#$50
    ; Turn off disk motor (also for better sound quality).
    ; Since FIRQ is disabled it won't turn off by itself.
	clr	$FF40

    ; Grab the current value of the I/O port
	lda	PORT_EnableAudio
	ora	#%00001000		; Activate bit-3 to turn on audio.
	sta	PORT_EnableAudio	; Set the new value of the I/O port.

	ldy	#16

	lda	#$FF			; Maximum volume.
	ldb	#1			; Start with minimum initial delay.
    ; Reverse volume to product a square wave.
	sta	PORT_Audio		; Send to sound port.

	pshs	B			; Save B.
    ; Delay.  For small B, frequency is higher.
	bne	Delay			; For large B, frequency is lower.
	puls	B			; Restore B.

	leay	-1,Y
	bne	NoDecay
	ldy	#16			; Reset the decay counter.

    ; Increase delay, which lowers the frequency.
	bne	Loop			; Keep playing until B=0.
	;bra	Loop			; Play sound repeatedly.

	puls	PC
	end	Start

I found that resetting the keyboard column strobe register on PIA0 ($FF00) to $FF disabled audio. I have no idea why. Even more troubling, I found that the keyboard control code continues to operate without resetting the column strobe. The good news is that I can use the keyboard and speaker at the same time, bad news it that I do not yet completely understand why.

You are welcome to try out the attached download. Run the game, admire the buttery sound-effects and how the easily the player collides into every single wall (#). Right now the walls are the only thing that stops the player from running a muck over the entire world; in the next article I’m hoping to implement a better message log (maybe something that respects line feeds), and some kind of mechanism for opening/closing the doors (+, -).



Many thanks to Paul Thayer for forwarding me a .DSK that will display the entire Color Computer 3 palette! But with every new discovery comes a new mystery: How did he get all 64 colors to display simultaneously? I suspect that he somehow forced the hardware to give up pixel space in favor of color space, much as the other screen modes shift memory between pixels and colors.

One thought on “A rogue-like in 6809 assembly (pt. 2)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s