I'm trying to improve the jumptable for my simple REPL environment.
Basically I'm mapping every ASCII character to some routine as such:
Code:
.segment "JUMPTABLE"
CMD_JUMPTABLE:
.word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.word cmd_noop, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, cmd_printmem
.word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, cmd_jmp, 0, 0, cmd_printmem, 0, 0
.word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.code
; ...
; Register A contains ASCII character code
asl a ; jumptable addresses are word-sized
tax
jmp (CMD_JUMPTABLE, X)
This works, but I really want to get rid of all the zeroes and do something like this:
Code:
.segment "JUMPTABLE"
.align $100
JUMPTABLE_START:
.repeat 128
.word $0
.endrepeat
; The following lines are pseudocode.
JUMPTABLE_START + ' ' = .word cmd_noop
JUMPTABLE_START + 'j' = .word cmd_jmp
JUMPTABLE_START + 'm' = .word cmd_printmem
JUMPTABLE_START + '?' = .word cmd_printmem
Any thoughts on whether this is achievable with ca65?