EVENT__main_init = 1 EVENT__start = 1 EVENT__nextframe = 1 EVENT__resetswitch = 1 EVENT__postframe = 1 EVENT__SetHorizPos = 1 EVENT__preframe = 1 EVENT__kernel = 1 EVENT__kerneldraw = 1 EVENT__kernelsetup = 1 EVENT__joybutton = 1 EVENT__FontTable = 1 EVENT__compute2digit = 1 EVENT__fetchdigit = 1 EVENT__FontTablePF = 1 EVENT__FontTablePFFancy = 1 EVENT__AddBCD4 = 1 .scope Main .zeropage BCDScore6_digits_b0: .res 1 BCDScore6_digits_b8: .res 1 BCDScore6_digits_b16: .res 1 PFColor_pfcolor_b0: .res 1 .res 1 .res 1 BGColor_bgcolor_b0: .res 1 BCDScore2_digits_b0: .res 1 .res 1 TEMP: Kernel6Digit__2__tmp: .res 1 .res 1 .res 1 .res 1 .res 1 .res 1 .res 1 .res 1 .res 1 .res 1 .res 1 .res 1 .res 1 .res 1 .res 1 Kernel2Digit__4__tmp: .res 1 .res 1 .res 1 .code Main__INITDATA: .byte 86 .byte 52 .byte 18 .byte 60 .byte 206 .byte 62 .byte 2 .byte 36 .byte 86 __Start: ;;; start action Init__main_init__1 .include "vcs-ca65.h" .macpack longbranch .define PAL 0 __NMI: __Reset: __BRK: CLEAN_START ldy #9 : lda Main__INITDATA-1,y sta BCDScore6_digits_b0-1,y dey bne :- ;;; start action FrameLoop__start__2 FrameLoop__start__2__NextFrame: FRAME_START ;;; start action Kernel6Digit__preframe__3 Digit0 = Kernel6Digit__2__tmp+0 Digit1 = Kernel6Digit__2__tmp+2 Digit2 = Kernel6Digit__2__tmp+4 Digit3 = Kernel6Digit__2__tmp+6 Digit4 = Kernel6Digit__2__tmp+8 Digit5 = Kernel6Digit__2__tmp+10 Kernel6Digit__preframe__3__BCD0 = Kernel6Digit__2__tmp+12 Kernel6Digit__preframe__3__BCD1 = Kernel6Digit__2__tmp+13 Kernel6Digit__preframe__3__BCD2 = Kernel6Digit__2__tmp+14 lda BCDScore6_digits_b0 sta Kernel6Digit__preframe__3__BCD0 lda BCDScore6_digits_b8 sta Kernel6Digit__preframe__3__BCD1 lda BCDScore6_digits_b16 sta Kernel6Digit__preframe__3__BCD2 ldx #0 ; leftmost bitmap ldy #2 ; start from most-sigificant BCD value Kernel6Digit__preframe__3__Loop: lda Kernel6Digit__preframe__3__BCD0,y ; get BCD value and #$f0 ; isolate high nibble (* 16) lsr ; shift right 1 bit (* 8) clc adc #FontTable adc #0 sta Digit0+1,x ; store pointer hi byte inx inx ; next bitmap pointer lda Kernel6Digit__preframe__3__BCD0,y ; get BCD value (again) and #$f ; isolate low nibble asl asl asl ; * 8 clc adc #FontTable adc #0 sta Digit0+1,x ; store pointer hi byte inx inx ; next bitmap pointer dey ; next BCD value bpl Kernel6Digit__preframe__3__Loop ; repeat until < 0 ;;; end action Kernel6Digit__preframe__3 KERNEL_START ;;; start action Kernel6Digit__kernel__4 lda PFColor_pfcolor_b0 sta COLUP0 sta COLUP1 lda #3 sta NUSIZ0 sta NUSIZ1 ; set horizontal position of player objects sta WSYNC sta HMCLR SLEEPR 24 sta RESP0 sta RESP1 lda #$10 sta HMP1 sta WSYNC sta HMOVE SLEEPR 24 ; wait 24 cycles between write to HMOVE and HMxxx sta HMCLR lda #1 sta VDELP0 sta VDELP1 ;;; end action Kernel6Digit__kernel__4 ;;; start action Kernel6Digit__kernel__5 ; Display the resulting 48x8 bitmap ; using the Digit0-5 pointers. Kernel6Digit__kernel__5__LoopCount = Kernel6Digit__2__tmp+12 Kernel6Digit__kernel__5__Temp = Kernel6Digit__2__tmp+13 lda BGColor_bgcolor_b0 sta WSYNC sta COLUBK lda #7 sta Kernel6Digit__kernel__5__LoopCount SLEEPR 20 ; TODO? Kernel6Digit__kernel__5__BigLoop: ldy Kernel6Digit__kernel__5__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 Kernel6Digit__kernel__5__Temp ; B5 -> temp lda (Digit4),y ; load B4 tax ; -> X lda (Digit3),y ; load B3 -> A ldy Kernel6Digit__kernel__5__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 Kernel6Digit__kernel__5__LoopCount ; go to next line bpl Kernel6Digit__kernel__5__BigLoop ; repeat until < 0 lda #0 ; clear the sprite registers sta WSYNC sta GRP0 sta GRP1 sta GRP0 sta GRP1 sta COLUBK ;;; end action Kernel6Digit__kernel__5 ;;; start action Kernel2Digit__kernel__6 lda #$02 sta CTRLPF ; TODO: should be constants ; and it's wrong, too! lda PFColor_pfcolor_b0+0 sta COLUP0 lda PFColor_pfcolor_b0+1 sta COLUP1 ;;; end action Kernel2Digit__kernel__6 ;;; start action Kernel2Digit__kernel__7 lda #7 sta Kernel2Digit__4__tmp+0 Kernel2Digit__kernel__7__Loop: ldx #0 sta WSYNC ;;; start action Kernel2Digit__compute2digit__8 lda Kernel2Digit__4__tmp+1 ; load 1st pf sta PF1 ; store 1st pf ; first digit lda BCDScore2_digits_b0 + 0 pha and #$0f asl asl asl ;;; start action Kernel2Digit__fetchdigit__9 adc Kernel2Digit__4__tmp+0 tay ; TODO: select your own? lda FontTablePF,y ;;; end action Kernel2Digit__fetchdigit__9 and #$0f ldy Kernel2Digit__4__tmp+2 ; load 2nd pf sta Kernel2Digit__4__tmp+1 + 0 ; second digit pla and #$f0 lsr sty PF1 ; store 2nd pf ;;; start action Kernel2Digit__fetchdigit__10 adc Kernel2Digit__4__tmp+0 tay ; TODO: select your own? lda FontTablePF,y ;;; end action Kernel2Digit__fetchdigit__10 and #$f0 ora Kernel2Digit__4__tmp+1 + 0 sta Kernel2Digit__4__tmp+1 + 0 ;;; end action Kernel2Digit__compute2digit__8 inx ;;; start action Kernel2Digit__compute2digit__11 lda Kernel2Digit__4__tmp+1 ; load 1st pf sta PF1 ; store 1st pf ; first digit lda BCDScore2_digits_b0 + 1 pha and #$0f asl asl asl ;;; start action Kernel2Digit__fetchdigit__12 adc Kernel2Digit__4__tmp+0 tay ; TODO: select your own? lda FontTablePF,y ;;; end action Kernel2Digit__fetchdigit__12 and #$0f ldy Kernel2Digit__4__tmp+2 ; load 2nd pf sta Kernel2Digit__4__tmp+1 + 1 ; second digit pla and #$f0 lsr sty PF1 ; store 2nd pf ;;; start action Kernel2Digit__fetchdigit__13 adc Kernel2Digit__4__tmp+0 tay ; TODO: select your own? lda FontTablePF,y ;;; end action Kernel2Digit__fetchdigit__13 and #$f0 ora Kernel2Digit__4__tmp+1 + 1 sta Kernel2Digit__4__tmp+1 + 1 ;;; end action Kernel2Digit__compute2digit__11 ; playfield dec Kernel2Digit__4__tmp+0 bpl Kernel2Digit__kernel__7__Loop ; dex ; stx PF1 ;;; end action Kernel2Digit__kernel__7 KERNEL_END ;;; start action JoyButton__postframe__14 lda INPT4 ;read button input bmi JoyButton__postframe__14__NotPressed ;;; start action IncScore__joybutton__15 ;;; start action BCDMath__AddBCD4__16 .ifnblank $0210 lda #<$0210 ldy #>$0210 .endif ; Adds value to 6-BCD-digit score. ; A = 1st BCD digit ; Y = 2nd BCD digit sed ; enter BCD mode clc ; clear carry adc BCDScore6_digits_b0 sta BCDScore6_digits_b0 tya adc BCDScore6_digits_b8 sta BCDScore6_digits_b8 lda BCDScore6_digits_b16 adc #0 sta BCDScore6_digits_b16 cld ; exit BCD mode ;;; end action BCDMath__AddBCD4__16 ;;; end action IncScore__joybutton__15 JoyButton__postframe__14__NotPressed: ;;; end action JoyButton__postframe__14 FRAME_END jmp FrameLoop__start__2__NextFrame ; loop to next frame ;;; end action FrameLoop__start__2 ; start main routine .segment "VECTORS" Return: .word $6060 VecNMI: VecReset: .word Main::__Reset VecBRK: .word Main::__BRK ;;; end action Init__main_init__1 FontTable: ;;; start action FontTable__FontTable__17 ; Font table for digits 0-9 (8x8 pixels) ;;{w:8,h:8,count:10,brev:1,flip:1};; .byte $00,$3c,$66,$66,$76,$6e,$66,$3c,$00,$7e,$18,$18,$18,$38,$18,$18 .byte $00,$7e,$60,$30,$0c,$06,$66,$3c,$00,$3c,$66,$06,$1c,$06,$66,$3c .byte $00,$06,$06,$7f,$66,$1e,$0e,$06,$00,$3c,$66,$06,$06,$7c,$60,$7e .byte $00,$3c,$66,$66,$7c,$60,$66,$3c,$00,$18,$18,$18,$18,$0c,$66,$7e .byte $00,$3c,$66,$66,$3c,$66,$66,$3c,$00,$3c,$66,$06,$3e,$66,$66,$3c ;;; end action FontTable__FontTable__17 FontTablePF: ;;; start action FontTablePF__FontTablePF__18 ; Font table for digits 0-9 (4x8 pixels) ;;{w:8,h:8,count:10,brev:1,flip:1};; .byte $00,$00,$EE,$AA,$AA,$AA,$EE,$00 .byte $00,$00,$22,$22,$22,$22,$22,$00 .byte $00,$00,$EE,$88,$EE,$22,$EE,$00 .byte $00,$00,$EE,$22,$66,$22,$EE,$00 .byte $00,$00,$22,$22,$EE,$AA,$AA,$00 .byte $00,$00,$EE,$22,$EE,$88,$EE,$00 .byte $00,$00,$EE,$AA,$EE,$88,$EE,$00 .byte $00,$00,$22,$22,$22,$22,$EE,$00 .byte $00,$00,$EE,$AA,$EE,$AA,$EE,$00 .byte $00,$00,$EE,$22,$EE,$AA,$EE,$00 ;; ;;; end action FontTablePF__FontTablePF__18 .endscope Main__Start = Main::__Start