Code: Select all
JSR readNextChar ; just to increment the pointer to an actual instruction
JMP ($0022) ; indirect through the pointer
Code: Select all
JSR readNextChar ; just to increment the pointer to an actual instruction
JMP ($0022) ; indirect through the pointer
Code: Select all
JSR readNextChar ; just to increment the pointer to an actual instruction
JMP ($0022) ; indirect through the pointer
Code: Select all
next_char: ; main loop
JSR show_digits
JSR waitKbdControls
CMP ch_escape ; <Escape> breaks
BEQ break
CMP ch_return ; <Return> is a valid char, concludes input (if possible)
BEQ .send_event
CMP ch_left ; <Left> removes last digit
BEQ .send_event
check_is_number ; only chars <0> to <9> allowed
BCC next_char ; carry cleared if not in <0> to <9>
.send_event:
STA event ; dispatch event
JSR dispatch_event
LDA state ; check if we should exit, i.e. user has entered a number
CMP s_exit
BEQ exit
JMP next_char
dispatch_event:
LDA state ; state index into RTS table
ASL ; table has 16bit addresses
TAX
LDA rts_table+1,X ; push hibyte first
PHA
LDA rts_table,X ; push lobyte second, will be popped first by RTS
PHA
LDA event ; state subroutines get the event in A
RTS
state_hasNone:
...
RTS
state_hasOne:
...
RTS
state_hasTwo:
...
RTS
state_exit:
...
RTS
rts_table:
.word state_hasNone-1
.word state_hasOne-1
.word state_hasTwo-1
.word state_exit-1