A C64 Game - Step 30


And a new cosmetic refinement, high score name entry. Now the entry is done on a title screen like layout, with a blinking cursor as well.

This requires setting the screen up similar to the title screen (with the raster split between bitmap logo and text mode).



Now it pays off that we had the IRQ initialisation tucked away in a subroutine. Inside the check for highscore routine we sprinkle a few changes. The other parts were mostly in place already (highscore placement, name entry).


First, calling InitTitleIRQ sets up the screen mode. During name entry we also add a blinking cursor. This is for now rather simply implemented as calling EOR (XOR) on the current cursor char.


Highscore entry:

          jsr InitTitleIRQ
ldy PARAM3
ldx #0
stx PARAM3
jmp .ShowChar

.GetNextChar
sty PARAM4

;blink cursor
jsr WaitFrame
lda PARAM3
clc
adc #6
tay
lda (ZEROPAGE_POINTER_4),y
eor #123
sta (ZEROPAGE_POINTER_4),y

;restore Y
ldy PARAM4

;use ROM routines, read char
jsr KERNAL_GETIN
beq .GetNextChar

;return pressed?
cmp #13
beq .EnterPressed

;DEL pressed?
cmp #20
bne .NotDel

;DEL pressed
ldy PARAM4
ldx PARAM3
beq .GetNextChar
dec PARAM3
dey
dex
lda #32
sta HIGHSCORE_NAME,y
jmp .ShowChar

.NotDel
ldy PARAM4

;pressed key >= 32 or <‍= 96?
cmp #32
bcc .GetNextChar
cmp #96
bcs .GetNextChar

;max length reached already?
ldx PARAM3
cpx #HIGHSCORE_NAME_SIZE
bcs .GetNextChar

;save text
sta HIGHSCORE_NAME,y
iny
inx

.ShowChar
stx PARAM3
sty PARAM4

;display high scores
;x,y pos of name
lda #6
sta PARAM1
lda #10
sta PARAM2

lda #<‍HIGHSCORE_NAME
sta ZEROPAGE_POINTER_1
lda #>HIGHSCORE_NAME
sta ZEROPAGE_POINTER_1 + 1
jsr DisplayText

ldx PARAM3
ldy PARAM4
jmp .GetNextChar

.EnterPressed
;fill entry with blanks
lda #32
ldx PARAM3
ldy PARAM4

.FillNextChar
cpx #HIGHSCORE_NAME_SIZE
beq .FilledUp

sta HIGHSCORE_NAME,y
iny
inx
jmp .FillNextChar

.FilledUp
jsr SaveScores
jmp TitleScreenWithoutIRQ



At the end of the routine, where we used to jump to the title screen before we now do not need to setup the IRQ any more. Since we're always low on memory we use the power of goto to jump smackdab into the previous TitleScreen routine. This does nothing else but skip the IRQ initialisation call:

!zone TitleScreen
TitleScreen
jsr InitTitleIRQ

TitleScreenWithoutIRQ...



Note that this is something that I've done on several occasions. Write sub routines in a way that you can use them for several use cases. There's always a trade off between nice generic reusable code (with a bit more overhead) and specialised routines, which may need to be written more than once.


step30.zip