//#resource "vcs-ca65.h" import "vcslib.ecs" component BCDScore2 digits: 0..$ff scorecolor: 0..$ff end component BCDScore4 digits: 0..0xffff end component BCDScore6 digits: 0..0xffffff end system Kernel6Digit locals 15 on preframe do with [BCDScore6] --- Digit0 = {{$0}} Digit1 = {{$2}} Digit2 = {{$4}} Digit3 = {{$6}} Digit4 = {{$8}} Digit5 = {{$10}} @BCD0 = {{$12}} @BCD1 = {{$13}} @BCD2 = {{$14}} lda {{get digits 0}} sta @BCD0 lda {{get digits 8}} sta @BCD1 lda {{get digits 16}} sta @BCD2 ldx #0 ; leftmost bitmap ldy #2 ; start from most-sigificant BCD value @Loop: lda @BCD0,y ; get BCD value and #$f0 ; isolate high nibble (* 16) lsr ; shift right 1 bit (* 8) clc adc #<{{^FontTable}} sta Digit0,x ; store pointer lo byte lda #>{{^FontTable}} adc #0 sta Digit0+1,x ; store pointer hi byte inx inx ; next bitmap pointer lda @BCD0,y ; get BCD value (again) and #$f ; isolate low nibble asl asl asl ; * 8 clc adc #<{{^FontTable}} sta Digit0,x ; store pointer lo byte lda #>{{^FontTable}} adc #0 sta Digit0+1,x ; store pointer hi byte inx inx ; next bitmap pointer dey ; next BCD value bpl @Loop ; repeat until < 0 --- on kernel do with [BCDScore6,PFColor] --- lda {{ [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 :- ; repeat until < 0 lda #0 ; clear the sprite registers sta WSYNC sta GRP0 sta GRP1 sta GRP0 sta GRP1 sta COLUBK --- end resource FontTable --- ; 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 --- system Kernel2Digit locals 3 on preframe do once --- lda #0 sta {{$1}} sta {{$2}} --- on kernel do select [BCDScore2] --- lda #$02 sta CTRLPF ; TODO: should be constants ; and it's wrong, too! lda {{1 inx {{!compute2digit 1}} .else {{!compute2digit 0}} .endif ; playfield dec {{$0}} jpl @Loop ; dex ; stx PF1 --- on compute2digit do once --- lda {{$1}} ; load 1st pf sta PF1 ; store 1st pf ; first digit lda {{{{arg 0}} .endif --- on AddBCD4 do with [BCDScore6] --- ; Adds value to 6-BCD-digit score. ; A = 1st BCD digit ; Y = 2nd BCD digit sed ; enter BCD mode clc ; clear carry adc {{get digits}} sta {{set digits}} tya adc {{get digits 8}} sta {{set digits 8}} lda {{get digits 16}} adc #0 sta {{set digits 16}} cld ; exit BCD mode --- on AddBCD2 do once --- .ifnblank {{arg 0}} lda #<{{arg 0}} .endif --- on SubBCD2 do once --- .ifnblank {{arg 0}} lda #<{{arg 0}} .endif --- on AddBCD2 do with [BCDScore2] --- sed ; enter BCD mode clc ; clear carry adc {{get digits}} sta {{set digits}} cld ; exit BCD mode bcc :+ lda #$99 sta {{set digits}} : --- on SubBCD2 do with [BCDScore2] --- ; TODO? tay lda {{get digits}} sty {{set digits}} sed ; enter BCD mode sec ; set carry sbc {{get digits}} sta {{set digits}} cld ; exit BCD mode bcs :+ lda #0 sta {{set digits}} : --- end demo Main using FrameLoop using Kernel6Digit using Kernel2Digit using JoyButton, BCDMath entity [Player,BCDScore6,PFColor,BGColor] init digits = 0x123456 init pfcolor = $3c init bgcolor = $02 end entity [BCDScore2] init digits = 0x24 init scorecolor = $ce end entity [BCDScore2] init digits = 0x56 init scorecolor = $3e end system IncScore on joybutton do with [Player,BCDScore6] --- {{!AddBCD4 $0210}} --- end end demo