processor 6502 include "vcs.h" include "macro.h" include "xmacro.h" seg.u Variables org $80 Temp .byte LoopCount .byte ; counts scanline when drawing ; Pointers to bitmap for each digit Digit0 .word Digit1 .word Digit2 .word Digit3 .word Digit4 .word Digit5 .word BCDScore hex 000000 THREE_COPIES equ %011 ; for NUSIZ registers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; seg Code org $f000 Start CLEAN_START NextFrame VERTICAL_SYNC TIMER_SETUP 37 lda #$18 sta COLUP0 lda #$28 sta COLUP1 lda #THREE_COPIES sta NUSIZ0 sta NUSIZ1 ; set horizontal position of player objects sta WSYNC SLEEP 26 sta RESP0 sta RESP1 lda #$10 sta HMP1 sta WSYNC sta HMOVE sta HMCLR lda #1 sta VDELP0 sta VDELP1 TIMER_WAIT TIMER_SETUP 192 jsr GetDigitPtrs ; get pointers jsr DrawDigits ; draw digits TIMER_WAIT TIMER_SETUP 30 lda #1 ldx #0 ldy #0 jsr AddScore TIMER_WAIT jmp NextFrame ; Adds value to 6-BCD-digit score. ; A = 1st BCD digit ; X = 2nd BCD digit ; Y = 3rd BCD digit AddScore subroutine sed ; enter BCD mode clc ; clear carry sta Temp lda BCDScore adc Temp sta BCDScore stx Temp lda BCDScore+1 adc Temp sta BCDScore+1 sty Temp lda BCDScore+2 adc Temp sta BCDScore+2 cld ; exit BCD mode rts GetDigitPtrs subroutine ldx #0 ; leftmost bitmap ldy #2 ; start from most-sigificant BCD value .Loop lda BCDScore,y ; get BCD value and #$f0 ; isolate high nibble (* 16) lsr ; shift right 1 bit (* 8) sta Digit0,x ; store pointer lo byte lda #>FontTable sta Digit0+1,x ; store pointer hi byte inx inx ; next bitmap pointer lda BCDScore,y ; get BCD value (again) and #$f ; isolate low nibble asl asl asl ; * 8 sta Digit0,x ; store pointer lo byte lda #>FontTable sta Digit0+1,x ; store pointer hi byte inx inx ; next bitmap pointer dey ; next BCD value bpl .Loop ; repeat until < 0 rts ; Display the resulting 48x8 bitmap ; using the Digit0-5 pointers. DrawDigits subroutine sta WSYNC SLEEP 40 ; start near end of scanline lda #7 sta LoopCount BigLoop ldy LoopCount ; counts backwards lda (Digit0),y ; load B0 (1st sprite byte) sta GRP0 ; B0 -> [GRP0] lda (Digit1),y ; load B1 -> A sta GRP1 ; B1 -> [GRP1], B0 -> GRP0 sta WSYNC ; sync to next scanline lda (Digit2),y ; load B2 -> A sta GRP0 ; B2 -> [GRP0], B1 -> GRP1 lda (Digit5),y ; load B5 -> A sta Temp ; B5 -> temp lda (Digit4),y ; load B4 tax ; -> X lda (Digit3),y ; load B3 -> A ldy Temp ; load B5 -> Y sta GRP1 ; B3 -> [GRP1]; B2 -> GRP0 stx GRP0 ; B4 -> [GRP0]; B3 -> GRP1 sty GRP1 ; B5 -> [GRP1]; B4 -> GRP0 sta GRP0 ; ?? -> [GRP0]; B5 -> GRP1 dec LoopCount ; go to next line bpl BigLoop ; repeat until < 0 lda #0 ; clear the sprite registers sta GRP0 sta GRP1 sta GRP0 sta GRP1 rts ; Font table for digits 0-9 (8x8 pixels) align $100 ; make sure data doesn't cross page boundary FontTable hex 003c6666766e663c007e181818381818 hex 007e60300c06663c003c66061c06663c hex 0006067f661e0e06003c6606067c607e hex 003c66667c60663c00181818180c667e hex 003c66663c66663c003c66063e66663c ; Epilogue org $fffc .word Start .word Start