diff --git a/projects/nibble-dice-tracker.tal b/projects/nibble-dice-tracker.tal index fa2f5b7..1b66030 100644 --- a/projects/nibble-dice-tracker.tal +++ b/projects/nibble-dice-tracker.tal @@ -182,12 +182,86 @@ RTN #01 ;update-dev JSR2 #02 ;update-dev JSR2 - ( ,draw-columns JSR ) - ( inc framecount ) .framecount LDZ2 #0001 ADD2 .framecount STZ2 BRK +@on-controller ( -> ) + .Controller/button DEI + DUP #10 AND ;&up JCN2 + DUP #20 AND ;&down JCN2 + DUP #40 AND ;&left JCN2 + DUP #80 AND ;&right JCN2 + DUP #01 AND ;&inc-nibble JCN2 ( ctrl ) + DUP #02 AND ;&dec-nibble JCN2 ( alt ) + POP + + .Controller/key DEI + DUP LIT 'j EQU ,&down JCN + DUP LIT 'k EQU ,&up JCN + DUP LIT 'h EQU ,&left JCN + DUP LIT 'l EQU ,&right JCN + DUP LIT '+ EQU ,&inc-nibble JCN + DUP LIT '- EQU ,&dec-nibble JCN + DUP #2f GTH ,&check-dec-digit JCN + POP BRK + &check-dec-digit + DUP #3a LTH ,&assign-dec-digit JCN + DUP #60 GTH ,&check-hex-digit JCN + POP BRK + &check-hex-digit + DUP LIT 'g LTH ,&assign-hex-digit JCN + &done + POP BRK + + &down + inc-ptr-reg-byt + ,&close JMP + &up + dec-ptr-reg-byt + ,&close JMP + &left + inc-ptr-reg-nib + ,&close JMP + &right + dec-ptr-reg-nib + ,&close JMP + &inc-nibble ( increment nibble ) + #01 ;add-to-nibble JSR2 + ,&close JMP + &dec-nibble ( dec nibble ) + #ff ;add-to-nibble JSR2 + ,&close JMP + &assign-dec-digit + DUP ( previous cases still carry the key in the stack ) + #30 SUB + ;assign-to-nibble JSR2 + ,&close JMP + &assign-hex-digit + DUP ( previous cases still carry the key in the stack ) + #57 SUB + ;assign-to-nibble JSR2 + + &close + ( only draw updated columns ) + .ptr-register-nibbles LDZ DUP + #10 MOD DUP #01 GTH ,&check-mod-is-0f JCN + &mod-is-0-or-1 + POP ( if the pointer is at 0 or 1 of a column, also update previous column ) + DUP #02 SUB #10 DIV ;draw-column JSR2 + ,&draw-current-column JMP + + &check-mod-is-0f + ( if the pointer is at e or f of a column, also update next column ) + #0e LTH ,&draw-current-column JCN + DUP #02 ADD #10 DIV ;draw-column JSR2 + ,&draw-current-column JMP + + &draw-current-column + #10 DIV ( divide pointer over 16 to find column number ) + ;draw-column JSR2 +BRK + @update-dev ( devnum -- ) @@ -289,83 +363,7 @@ RTN ,&color LDR .Screen/color DEO RTN -@on-controller ( -> ) - .Controller/button DEI - DUP #10 AND ;&up JCN2 - DUP #20 AND ;&down JCN2 - DUP #40 AND ;&left JCN2 - DUP #80 AND ;&right JCN2 - DUP #01 AND ;&inc-nibble JCN2 ( ctrl ) - DUP #02 AND ;&dec-nibble JCN2 ( alt ) - POP - .Controller/key DEI - DUP LIT 'j EQU ;&down JCN2 - DUP LIT 'k EQU ;&up JCN2 - DUP LIT 'h EQU ;&left JCN2 - DUP LIT 'l EQU ;&right JCN2 - DUP LIT '+ EQU ;&inc-nibble JCN2 - DUP LIT '- EQU ;&dec-nibble JCN2 - DUP #2f GTH ,&check-dec-digit JCN - POP BRK - &check-dec-digit - DUP #3a LTH ;&assign-dec-digit JCN2 - DUP #60 GTH ,&check-hex-digit JCN - POP BRK - &check-hex-digit - DUP LIT 'g LTH ;&assign-hex-digit JCN2 - &done - POP BRK - - &down - inc-ptr-reg-byt - ,&close JMP - &up - dec-ptr-reg-byt - ,&close JMP - &left - inc-ptr-reg-nib - ,&close JMP - &right - dec-ptr-reg-nib - ,&close JMP - &inc-nibble ( increment nibble ) - #01 ;add-to-nibble JSR2 - ,&close JMP - &dec-nibble ( dec nibble ) - #ff ;add-to-nibble JSR2 - ,&close JMP - &assign-dec-digit - DUP ( previous cases still carry the key in the stack ) - #30 SUB - ;assign-to-nibble JSR2 - ,&close JMP - &assign-hex-digit - DUP ( previous cases still carry the key in the stack ) - #57 SUB - ;assign-to-nibble JSR2 - - &close - ( only draw updated columns ) - .ptr-register-nibbles LDZ DUP - #10 MOD DUP #01 GTH ,&check-mod-is-0f JCN - &mod-is-0-or-1 - POP - DUP #02 SUB #10 DIV ,draw-column JSR - ,&draw-current-column JMP - - &check-mod-is-0f - #0e LTH ,&draw-current-column JCN - DUP #02 ADD #10 DIV ,draw-column JSR - ,&draw-current-column JMP - - &draw-current-column - #10 DIV - ,draw-column JSR - BRK - - -BRK @draw-column ( num -- ) diff --git a/roms/nibble-dice-tracker.rom b/roms/nibble-dice-tracker.rom index ea42f2f..d3d1f8c 100644 Binary files a/roms/nibble-dice-tracker.rom and b/roms/nibble-dice-tracker.rom differ