use macros for CPU-specific jumptable generation

This commit is contained in:
FeralChild64 committed 2020-06-06 10:09:25 +02:00
1 parent f560e26c65
commit f5b4e554ac
3 files changed
+236 -496

No files matched your search

+37
View File
@@ -42,6 +42,43 @@
//
// Macros for generating jumptables
//
#if !HAS_OPCODES_65C02
.macro put_jumptable_lo(list)
{
.for (var i = 0; i < list.size(); i++)
{
.byte mod((list.get(i) - 1), $100)
}
}
.macro put_jumptable_hi(list)
{
.for (var i = 0; i < list.size(); i++)
{
.byte floor((list.get(i) - 1) / $100)
}
}
#else // HAS_OPCODES_65C02
.macro put_jumptable(list)
{
.for (var i = 0; i < list.size(); i++)
{
.word list.get(i)
}
}
#endif
//
// Trick to skip a 2-byte instruction
//
+162 -429
View File
@@ -7,457 +7,190 @@
//
.const command_list = List().add(
// $80 - $8F
cmd_end,
cmd_for,
cmd_next,
cmd_data,
cmd_inputhash,
cmd_input,
cmd_dim,
cmd_read,
cmd_let,
cmd_goto,
cmd_run,
cmd_if,
cmd_restore,
cmd_gosub,
cmd_return,
cmd_rem,
// $90-$9F
cmd_stop,
cmd_on,
cmd_wait,
cmd_load,
cmd_save,
cmd_verify,
cmd_def,
cmd_poke,
cmd_printhash,
cmd_print,
cmd_cont,
cmd_list,
cmd_clr,
cmd_cmd,
cmd_sys,
cmd_open,
// $A0-$AF
cmd_close,
cmd_get,
cmd_new,
cmd_tab,
cmd_to,
cmd_fn,
cmd_spc,
cmd_then,
cmd_not,
cmd_step,
cmd_plus,
cmd_minus,
cmd_mult,
cmd_div,
cmd_exponent,
cmd_and,
// $B0-$BF
cmd_or,
cmd_greater,
cmd_equal,
cmd_less,
cmd_sgn,
cmd_int,
cmd_abs,
cmd_usr,
cmd_fre,
cmd_pos,
cmd_sqr,
cmd_rnd,
cmd_log,
cmd_exp,
cmd_cos,
cmd_sin,
// $C0-$CF
cmd_tan,
cmd_atn,
cmd_peek,
cmd_len,
cmd_str,
cmd_val,
cmd_asc,
cmd_chr,
cmd_left,
cmd_right,
cmd_mid,
cmd_go,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
// $D0-$DF
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
// $E0-$EF
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
// $F0-$FF
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented,
cmd_unimplemented
)
#if !HAS_OPCODES_65C02
command_jumptable_lo:
// $80 - $8F
.byte <(cmd_end-1)
.byte <(cmd_for-1)
.byte <(cmd_next-1)
.byte <(cmd_data-1)
.byte <(cmd_inputhash-1)
.byte <(cmd_input-1)
.byte <(cmd_dim-1)
.byte <(cmd_read-1)
.byte <(cmd_let-1)
.byte <(cmd_goto-1)
.byte <(cmd_run-1)
.byte <(cmd_if-1)
.byte <(cmd_restore-1)
.byte <(cmd_gosub-1)
.byte <(cmd_return-1)
.byte <(cmd_rem-1)
// $90-$9F
.byte <(cmd_stop-1)
.byte <(cmd_on-1)
.byte <(cmd_wait-1)
.byte <(cmd_load-1)
.byte <(cmd_save-1)
.byte <(cmd_verify-1)
.byte <(cmd_def-1)
.byte <(cmd_poke-1)
.byte <(cmd_printhash-1)
.byte <(cmd_print-1)
.byte <(cmd_cont-1)
.byte <(cmd_list-1)
.byte <(cmd_clr-1)
.byte <(cmd_cmd-1)
.byte <(cmd_sys-1)
.byte <(cmd_open-1)
// $A0-$AF
.byte <(cmd_close-1)
.byte <(cmd_get-1)
.byte <(cmd_new-1)
.byte <(cmd_tab-1)
.byte <(cmd_to-1)
.byte <(cmd_fn-1)
.byte <(cmd_spc-1)
.byte <(cmd_then-1)
.byte <(cmd_not-1)
.byte <(cmd_step-1)
.byte <(cmd_plus-1)
.byte <(cmd_minus-1)
.byte <(cmd_mult-1)
.byte <(cmd_div-1)
.byte <(cmd_exponent-1)
.byte <(cmd_and-1)
// $B0-$BF
.byte <(cmd_or-1)
.byte <(cmd_greater-1)
.byte <(cmd_equal-1)
.byte <(cmd_less-1)
.byte <(cmd_sgn-1)
.byte <(cmd_int-1)
.byte <(cmd_abs-1)
.byte <(cmd_usr-1)
.byte <(cmd_fre-1)
.byte <(cmd_pos-1)
.byte <(cmd_sqr-1)
.byte <(cmd_rnd-1)
.byte <(cmd_log-1)
.byte <(cmd_exp-1)
.byte <(cmd_cos-1)
.byte <(cmd_sin-1)
// $C0-$CF
.byte <(cmd_tan-1)
.byte <(cmd_atn-1)
.byte <(cmd_peek-1)
.byte <(cmd_len-1)
.byte <(cmd_str-1)
.byte <(cmd_val-1)
.byte <(cmd_asc-1)
.byte <(cmd_chr-1)
.byte <(cmd_left-1)
.byte <(cmd_right-1)
.byte <(cmd_mid-1)
.byte <(cmd_go-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
// $D0-$DF
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
// $E0-$EF
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
// $F0-$FF
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
.byte <(cmd_unimplemented-1)
put_jumptable_lo(command_list)
command_jumptable_hi:
// $80 - $8F
.byte >(cmd_end-1)
.byte >(cmd_for-1)
.byte >(cmd_next-1)
.byte >(cmd_data-1)
.byte >(cmd_inputhash-1)
.byte >(cmd_input-1)
.byte >(cmd_dim-1)
.byte >(cmd_read-1)
.byte >(cmd_let-1)
.byte >(cmd_goto-1)
.byte >(cmd_run-1)
.byte >(cmd_if-1)
.byte >(cmd_restore-1)
.byte >(cmd_gosub-1)
.byte >(cmd_return-1)
.byte >(cmd_rem-1)
// $90-$9F
.byte >(cmd_stop-1)
.byte >(cmd_on-1)
.byte >(cmd_wait-1)
.byte >(cmd_load-1)
.byte >(cmd_save-1)
.byte >(cmd_verify-1)
.byte >(cmd_def-1)
.byte >(cmd_poke-1)
.byte >(cmd_printhash-1)
.byte >(cmd_print-1)
.byte >(cmd_cont-1)
.byte >(cmd_list-1)
.byte >(cmd_clr-1)
.byte >(cmd_cmd-1)
.byte >(cmd_sys-1)
.byte >(cmd_open-1)
// $A0-$AF
.byte >(cmd_close-1)
.byte >(cmd_get-1)
.byte >(cmd_new-1)
.byte >(cmd_tab-1)
.byte >(cmd_to-1)
.byte >(cmd_fn-1)
.byte >(cmd_spc-1)
.byte >(cmd_then-1)
.byte >(cmd_not-1)
.byte >(cmd_step-1)
.byte >(cmd_plus-1)
.byte >(cmd_minus-1)
.byte >(cmd_mult-1)
.byte >(cmd_div-1)
.byte >(cmd_exponent-1)
.byte >(cmd_and-1)
// $B0-$BF
.byte >(cmd_or-1)
.byte >(cmd_greater-1)
.byte >(cmd_equal-1)
.byte >(cmd_less-1)
.byte >(cmd_sgn-1)
.byte >(cmd_int-1)
.byte >(cmd_abs-1)
.byte >(cmd_usr-1)
.byte >(cmd_fre-1)
.byte >(cmd_pos-1)
.byte >(cmd_sqr-1)
.byte >(cmd_rnd-1)
.byte >(cmd_log-1)
.byte >(cmd_exp-1)
.byte >(cmd_cos-1)
.byte >(cmd_sin-1)
// $C0-$CF
.byte >(cmd_tan-1)
.byte >(cmd_atn-1)
.byte >(cmd_peek-1)
.byte >(cmd_len-1)
.byte >(cmd_str-1)
.byte >(cmd_val-1)
.byte >(cmd_asc-1)
.byte >(cmd_chr-1)
.byte >(cmd_left-1)
.byte >(cmd_right-1)
.byte >(cmd_mid-1)
.byte >(cmd_go-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
// $D0-$DF
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
// $E0-$EF
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
// $F0-$FF
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
.byte >(cmd_unimplemented-1)
put_jumptable_hi(command_list)
#else // HAS_OPCODES_65C02
__before_command_jumptable:
.if (mod(*, $2) == 1) { brk } // align code so that vector never crosses page boundary
command_jumptable:
// $80 - $8F
.word cmd_end
.word cmd_for
.word cmd_next
.word cmd_data
.word cmd_inputhash
.word cmd_input
.word cmd_dim
.word cmd_read
.word cmd_let
.word cmd_goto
.word cmd_run
.word cmd_if
.word cmd_restore
.word cmd_gosub
.word cmd_return
.word cmd_rem
// $90-$9F
.word cmd_stop
.word cmd_on
.word cmd_wait
.word cmd_load
.word cmd_save
.word cmd_verify
.word cmd_def
.word cmd_poke
.word cmd_printhash
.word cmd_print
.word cmd_cont
.word cmd_list
.word cmd_clr
.word cmd_cmd
.word cmd_sys
.word cmd_open
// $A0-$AF
.word cmd_close
.word cmd_get
.word cmd_new
.word cmd_tab
.word cmd_to
.word cmd_fn
.word cmd_spc
.word cmd_then
.word cmd_not
.word cmd_step
.word cmd_plus
.word cmd_minus
.word cmd_mult
.word cmd_div
.word cmd_exponent
.word cmd_and
// $B0-$BF
.word cmd_or
.word cmd_greater
.word cmd_equal
.word cmd_less
.word cmd_sgn
.word cmd_int
.word cmd_abs
.word cmd_usr
.word cmd_fre
.word cmd_pos
.word cmd_sqr
.word cmd_rnd
.word cmd_log
.word cmd_exp
.word cmd_cos
.word cmd_sin
// $C0-$CF
.word cmd_tan
.word cmd_atn
.word cmd_peek
.word cmd_len
.word cmd_str
.word cmd_val
.word cmd_asc
.word cmd_chr
.word cmd_left
.word cmd_right
.word cmd_mid
.word cmd_go
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
// $D0-$DF
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
// $E0-$EF
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
// $F0-$FF
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
.word cmd_unimplemented
put_jumptable(command_list)
// Make sure routine size is always the same - build system limitation
.if (__before_command_jumptable == command_jumptable) { brk }
#endif
@@ -40,59 +40,49 @@ __chrout_screen_jumptable_quote_guard:
__chrout_screen_jumptable_codes_end:
.const chrout_list = List().add(
chrout_screen_CLR,
chrout_screen_HOME,
chrout_screen_SHIFT_OFF,
chrout_screen_SHIFT_ON,
chrout_screen_TXT,
chrout_screen_GFX,
chrout_screen_RVS_OFF,
chrout_screen_RVS_ON,
chrout_screen_CRSR_RIGHT,
chrout_screen_CRSR_LEFT,
chrout_screen_CRSR_DOWN,
chrout_screen_CRSR_UP,
chrout_screen_INS,
#if CONFIG_EDIT_STOPQUOTE
chrout_screen_STOP,
#endif
#if CONFIG_EDIT_TABULATORS
chrout_screen_TAB_BW,
chrout_screen_TAB_FW,
#endif
chrout_screen_DEL,
chrout_screen_RETURN
)
#if !HAS_OPCODES_65C02
chrout_screen_jumptable_lo:
.byte <(chrout_screen_CLR - 1)
.byte <(chrout_screen_HOME - 1)
.byte <(chrout_screen_SHIFT_OFF - 1)
.byte <(chrout_screen_SHIFT_ON - 1)
.byte <(chrout_screen_TXT - 1)
.byte <(chrout_screen_GFX - 1)
.byte <(chrout_screen_RVS_OFF - 1)
.byte <(chrout_screen_RVS_ON - 1)
.byte <(chrout_screen_CRSR_RIGHT - 1)
.byte <(chrout_screen_CRSR_LEFT - 1)
.byte <(chrout_screen_CRSR_DOWN - 1)
.byte <(chrout_screen_CRSR_UP - 1)
.byte <(chrout_screen_INS - 1)
#if CONFIG_EDIT_STOPQUOTE
.byte <(chrout_screen_STOP - 1)
#endif
#if CONFIG_EDIT_TABULATORS
.byte <(chrout_screen_TAB_BW - 1)
.byte <(chrout_screen_TAB_FW - 1)
#endif
.byte <(chrout_screen_DEL - 1)
.byte <(chrout_screen_RETURN - 1)
put_jumptable_lo(chrout_list)
chrout_screen_jumptable_hi:
.byte >(chrout_screen_CLR - 1)
.byte >(chrout_screen_HOME - 1)
.byte >(chrout_screen_SHIFT_OFF - 1)
.byte >(chrout_screen_SHIFT_ON - 1)
.byte >(chrout_screen_TXT - 1)
.byte >(chrout_screen_GFX - 1)
.byte >(chrout_screen_RVS_OFF - 1)
.byte >(chrout_screen_RVS_ON - 1)
.byte >(chrout_screen_CRSR_RIGHT - 1)
.byte >(chrout_screen_CRSR_LEFT - 1)
.byte >(chrout_screen_CRSR_DOWN - 1)
.byte >(chrout_screen_CRSR_UP - 1)
.byte >(chrout_screen_INS - 1)
#if CONFIG_EDIT_STOPQUOTE
.byte >(chrout_screen_STOP - 1)
#endif
#if CONFIG_EDIT_TABULATORS
.byte >(chrout_screen_TAB_BW - 1)
.byte >(chrout_screen_TAB_FW - 1)
#endif
.byte >(chrout_screen_DEL - 1)
.byte >(chrout_screen_RETURN - 1)
put_jumptable_hi(chrout_list)
#else // HAS_OPCODES_65C02
#else
__before_chrout_screen_jumptable:
@@ -100,31 +90,11 @@ __before_chrout_screen_jumptable:
chrout_screen_jumptable:
.word chrout_screen_CLR
.word chrout_screen_HOME
.word chrout_screen_SHIFT_OFF
.word chrout_screen_SHIFT_ON
.word chrout_screen_TXT
.word chrout_screen_GFX
.word chrout_screen_RVS_OFF
.word chrout_screen_RVS_ON
.word chrout_screen_CRSR_RIGHT
.word chrout_screen_CRSR_LEFT
.word chrout_screen_CRSR_DOWN
.word chrout_screen_CRSR_UP
.word chrout_screen_INS
#if CONFIG_EDIT_STOPQUOTE
.word chrout_screen_STOP
#endif
#if CONFIG_EDIT_TABULATORS
.word chrout_screen_TAB_BW
.word chrout_screen_TAB_FW
#endif
.word chrout_screen_DEL
.word chrout_screen_RETURN
put_jumptable(chrout_list)
// Make sure routine size is always the same - build system limitation
.if (__before_chrout_screen_jumptable == chrout_screen_jumptable) { brk }
#endif