added hexadecimal keys

This commit is contained in:
sejo 2021-07-14 14:43:18 -05:00
parent 5ec1853300
commit 06d08c7596
2 changed files with 68 additions and 20 deletions

View File

@ -10,6 +10,7 @@
* Arrow key right, or 'l': move cursor to next nibble
* 'Ctrl' or '+': increment nibble
* 'Alt' or '-': decrement nibble
* '0' to '9' and 'a' to 'f': assign value to nibble
more info: https://compudanzas.net/nibble_dice_tracker.html
)
@ -290,25 +291,32 @@ RTN
@on-controller ( -> )
.Controller/button DEI
DUP #10 AND ,&up JCN
DUP #20 AND ,&down JCN
DUP #40 AND ,&left JCN
DUP #80 AND ,&right JCN
DUP #01 AND ,&inc-nibble JCN ( ctrl )
DUP #02 AND ,&dec-nibble JCN ( alt )
POP
&keys
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 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
( registers )
&down
inc-ptr-reg-byt
,&close JMP
@ -322,14 +330,24 @@ RTN
dec-ptr-reg-nib
,&close JMP
&inc-nibble ( increment nibble )
#01 ,add-to-nibble JSR
#01 ;add-to-nibble JSR2
,&close JMP
&dec-nibble ( dec nibble )
#ff ,add-to-nibble JSR
#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
.ptr-register-nibbles LDZ DUP
#10 MOD DUP #01 GTH ,&check-mod-is-0f JCN
&mod-is-0-or-1
POP
@ -344,9 +362,12 @@ RTN
&draw-current-column
#10 DIV
,draw-column JSR
POP BRK
BRK
BRK
@draw-column ( num -- )
STHk
#02 MUL ( create offset for x position )
@ -385,6 +406,33 @@ RTN
STA
RTN
@assign-to-nibble ( x -- ) ( assing x to nibble pointed by ptr-register-nibbles )
,&num STR
,&start JMP
&num $1
&start
#00
.ptr-register-nibbles LDZ ( get register address )
#01 SFT ;registers ADD2 ( calculate register address+offset )
STH2k ( store and keep address+offset )
LDA ( get register contents )
DUP ( duplicate byte )
#04 SFT .high-nibble STZ ( store high nibble )
#0f AND .low-nibble STZ ( store low nibble )
.ptr-register-nibbles LDZ
#01 AND ( are we in high 1 or low 0 nibble? )
,&inc-high-nibble JCN
&inc-low-nibble
,&num LDR .low-nibble STZ
,&finish JMP
&inc-high-nibble
,&num LDR .high-nibble STZ
&finish
.high-nibble LDZ #40 SFT .low-nibble LDZ ORA ( reassemble byte )
STH2r ( recover byte address )
STA
RTN
@draw-bytes ( x2 y2 ptr-offset -- )
( can be modified to be: x2 y2 ptr-addrZ ptr-offset bytesaddrA -- )
;registers ,&addr STR2 ( starting address of bytes )

Binary file not shown.