2023-04-02 10:39:35 +00:00
|
|
|
; Generated by Henceforth 0.1.0 (https://git.dergrimm.net/dergrimm/hence.git)
|
|
|
|
|
2023-03-23 16:59:10 +00:00
|
|
|
.include "$lib/core.asm"
|
|
|
|
.include "$lib/std.asm"
|
2023-03-24 20:13:40 +00:00
|
|
|
|
2023-04-04 18:22:36 +00:00
|
|
|
.define PLACEHOLDER_U8, CORE_U8_MAX
|
|
|
|
.define PLACEHOLDER_U16, CORE_U16_MAX
|
|
|
|
|
2023-04-01 17:20:32 +00:00
|
|
|
.define_eval prev, OFFSET
|
2023-04-04 18:22:36 +00:00
|
|
|
ts PLACEHOLDER_U16
|
2023-04-01 17:20:32 +00:00
|
|
|
tlr CORE_REG_PC
|
|
|
|
.define_eval diff, (OFFSET - prev)
|
|
|
|
.define_eval MAIN_JUMPER, (CORE_MEM_PRG_END - diff)
|
|
|
|
.org prev
|
|
|
|
.delete prev, diff
|
|
|
|
|
2023-04-03 09:42:45 +00:00
|
|
|
.define_eval prev, OFFSET
|
2023-04-04 18:22:36 +00:00
|
|
|
.bytes PLACEHOLDER_U16, PLACEHOLDER_U16
|
|
|
|
.bytes PLACEHOLDER_U16
|
2023-04-03 09:42:45 +00:00
|
|
|
.define_eval JUMP_TABLE_CONDITIONS_SIZE, (OFFSET - prev)
|
|
|
|
.org prev
|
|
|
|
.delete prev
|
|
|
|
|
2023-04-04 18:22:36 +00:00
|
|
|
.define_eval JUMP_TABLE_WORDS_SIZE, (3 * 2)
|
2023-04-03 09:42:45 +00:00
|
|
|
.define_eval JUMP_TABLE_PTR, (MAIN_JUMPER - JUMP_TABLE_CONDITIONS_SIZE - JUMP_TABLE_WORDS_SIZE)
|
|
|
|
|
|
|
|
.debug JUMP_TABLE_CONDITIONS_SIZE, JUMP_TABLE_WORDS_SIZE, (JUMP_TABLE_CONDITIONS_SIZE + JUMP_TABLE_WORDS_SIZE / 2), JUMP_TABLE_PTR
|
|
|
|
|
|
|
|
.define_eval counter, 0
|
|
|
|
; jump table
|
|
|
|
; conditions
|
|
|
|
.define_eval jump_table_conditions_if_0, (JUMP_TABLE_PTR + counter)
|
|
|
|
.define_eval counter, (counter + 2)
|
|
|
|
.define_eval jump_table_conditions_else_0, (JUMP_TABLE_PTR + counter)
|
|
|
|
.define_eval counter, (counter + 2)
|
2023-04-04 12:07:21 +00:00
|
|
|
.define_eval jump_table_conditions_if_1, (JUMP_TABLE_PTR + counter)
|
|
|
|
.define_eval counter, (counter + 2)
|
2023-04-04 18:22:36 +00:00
|
|
|
|
|
|
|
; words
|
|
|
|
.define_eval jump_table_words_0, (JUMP_TABLE_PTR + counter)
|
|
|
|
.define_eval counter, (counter + 1)
|
|
|
|
.define_eval jump_table_words_1, (JUMP_TABLE_PTR + counter)
|
|
|
|
.define_eval counter, (counter + 1)
|
|
|
|
.define_eval jump_table_words_2, (JUMP_TABLE_PTR + counter)
|
|
|
|
.define_eval counter, (counter + 1)
|
2023-04-03 09:42:45 +00:00
|
|
|
.delete counter
|
|
|
|
|
|
|
|
.define_eval MEM_JUMP_TABLE_LEN, (JUMP_TABLE_CONDITIONS_SIZE + JUMP_TABLE_WORDS_SIZE / 2)
|
2023-04-02 12:32:11 +00:00
|
|
|
.define_eval MEM_JUMP_TABLE_PTR, CORE_MEM_MEM
|
|
|
|
.define_eval MEM_JUMP_TABLE_END, (MEM_JUMP_TABLE_PTR + MEM_JUMP_TABLE_LEN)
|
|
|
|
|
|
|
|
.define_eval MEM_LOOP_DEPTH, (MEM_JUMP_TABLE_END + 1)
|
2023-04-01 17:20:32 +00:00
|
|
|
.define_eval MEM_LOOP_I, (MEM_LOOP_DEPTH + 1)
|
|
|
|
.define_eval MEM_LOOP_J, (MEM_LOOP_I + 1)
|
2023-03-24 20:13:40 +00:00
|
|
|
|
2023-04-01 17:20:32 +00:00
|
|
|
.define_eval MEM_CALL_STACK_LEN, 16
|
|
|
|
.define_eval MEM_CALL_STACK_PTR, (MEM_LOOP_J + 1)
|
|
|
|
.define_eval MEM_CALL_STACK_END, (MEM_CALL_STACK_PTR + MEM_CALL_STACK_LEN)
|
|
|
|
|
|
|
|
.define_eval MEM_ALLOC_PTR, (MEM_CALL_STACK_END + 1)
|
|
|
|
|
|
|
|
.macro stack_transfer_alu
|
|
|
|
.std_ld
|
|
|
|
tlr CORE_REG_B
|
|
|
|
.std_ld
|
|
|
|
tlr CORE_REG_A
|
|
|
|
.endmacro
|
2023-03-24 20:13:40 +00:00
|
|
|
|
2023-04-04 18:22:36 +00:00
|
|
|
.macro jump_table_pull_ptr, jump_table_pull_ptr_arg_0_ptr, jump_table_pull_ptr_arg_1_counter
|
|
|
|
ts jump_table_pull_ptr_arg_0_ptr
|
2023-04-03 09:42:45 +00:00
|
|
|
tls
|
2023-04-04 18:22:36 +00:00
|
|
|
|
|
|
|
ts 8
|
|
|
|
tlr CORE_REG_B
|
|
|
|
.std_get jump_table_pull_ptr_arg_0_ptr
|
|
|
|
tlr CORE_REG_A
|
|
|
|
ts CORE_ALU_LSH
|
|
|
|
alu
|
|
|
|
tlr CORE_REG_A
|
|
|
|
|
2023-04-04 12:07:21 +00:00
|
|
|
.std_get (jump_table_pull_ptr_arg_0_ptr + 1)
|
2023-04-04 18:22:36 +00:00
|
|
|
tlr CORE_REG_B
|
|
|
|
ts CORE_ALU_OR
|
|
|
|
alu
|
|
|
|
tlr CORE_REG_A
|
|
|
|
|
2023-04-03 09:42:45 +00:00
|
|
|
tls
|
|
|
|
dbg
|
|
|
|
pop
|
|
|
|
pop
|
2023-04-04 12:07:21 +00:00
|
|
|
.endmacro
|
|
|
|
|
2023-04-04 18:22:36 +00:00
|
|
|
.define_eval counter, 0
|
2023-04-04 12:07:21 +00:00
|
|
|
; setup jump table
|
|
|
|
; conditions
|
2023-04-04 18:22:36 +00:00
|
|
|
.jump_table_pull_ptr jump_table_conditions_if_0, counter
|
|
|
|
.define_eval counter, (counter + 1)
|
|
|
|
.jump_table_pull_ptr jump_table_conditions_else_0, counter
|
|
|
|
.define_eval counter, (counter + 1)
|
|
|
|
.jump_table_pull_ptr jump_table_conditions_if_1, counter
|
|
|
|
.define_eval counter, (counter + 1)
|
|
|
|
|
|
|
|
; words
|
|
|
|
.jump_table_pull_ptr jump_table_words_0, counter
|
|
|
|
.define_eval counter, (counter + 1)
|
|
|
|
.jump_table_pull_ptr jump_table_words_1, counter
|
|
|
|
.define_eval counter, (counter + 1)
|
|
|
|
.jump_table_pull_ptr jump_table_words_2, counter
|
|
|
|
.define_eval counter, (counter + 1)
|
|
|
|
.delete counter
|
2023-04-04 12:07:21 +00:00
|
|
|
|
2023-04-04 18:22:36 +00:00
|
|
|
.delete_macro jump_table_pull_ptr
|
2023-04-04 12:07:21 +00:00
|
|
|
|
|
|
|
.macro self_ref, self_ref_arg_0_ptr
|
|
|
|
.std_rset CORE_REG_A, self_ref_arg_0_ptr
|
|
|
|
.std_set self_ref_arg_0_ptr
|
|
|
|
.endmacro
|
2023-04-02 12:32:11 +00:00
|
|
|
|
|
|
|
; reference MEM_CALL_STACK_PTR to itself
|
2023-04-04 12:07:21 +00:00
|
|
|
.self_ref MEM_CALL_STACK_PTR
|
2023-03-24 20:13:40 +00:00
|
|
|
|
2023-04-02 12:32:11 +00:00
|
|
|
; reference MEM_ALLOC_PTR to itself
|
2023-04-04 12:07:21 +00:00
|
|
|
.self_ref MEM_ALLOC_PTR
|
|
|
|
|
|
|
|
.delete_macro self_ref
|
2023-03-24 20:13:40 +00:00
|
|
|
|
2023-04-01 17:20:32 +00:00
|
|
|
.std_jump MAIN_JUMPER
|
2023-03-24 20:13:40 +00:00
|
|
|
|
2023-03-23 16:59:10 +00:00
|
|
|
call_stack_jump:
|
2023-03-24 20:13:40 +00:00
|
|
|
.std_get MEM_CALL_STACK_PTR
|
|
|
|
tlr CORE_REG_A
|
|
|
|
.std_rset CORE_REG_B, 1
|
|
|
|
.std_alu CORE_ALU_ADD
|
|
|
|
tlr CORE_REG_A
|
|
|
|
tlr CORE_REG_B
|
|
|
|
.std_set MEM_CALL_STACK_PTR
|
|
|
|
|
|
|
|
tsr CORE_REG_D
|
|
|
|
tlr CORE_REG_A
|
|
|
|
tsr CORE_REG_B
|
|
|
|
set
|
|
|
|
tsr CORE_REG_C
|
|
|
|
tlr CORE_REG_PC
|
|
|
|
|
2023-03-23 16:59:10 +00:00
|
|
|
return_call_stack_jump:
|
2023-03-24 20:13:40 +00:00
|
|
|
.std_get MEM_CALL_STACK_PTR
|
|
|
|
tlr CORE_REG_A
|
|
|
|
tlr CORE_REG_C
|
|
|
|
.std_rset CORE_REG_B, 1
|
|
|
|
.std_alu CORE_ALU_SUB
|
|
|
|
tlr CORE_REG_A
|
|
|
|
.std_set MEM_CALL_STACK_PTR
|
|
|
|
|
|
|
|
tsr CORE_REG_C
|
|
|
|
get
|
|
|
|
tlr CORE_REG_PC
|
|
|
|
|
2023-04-02 10:39:35 +00:00
|
|
|
.macro call_stack_jump, call_stack_jump_arg_0_label
|
2023-04-01 17:20:32 +00:00
|
|
|
.std_rset CORE_REG_C, call_stack_jump_arg_0_label
|
2023-04-04 12:07:21 +00:00
|
|
|
.std_rset CORE_REG_D, (OFFSET + 7)
|
2023-04-01 17:20:32 +00:00
|
|
|
ts call_stack_jump
|
|
|
|
tlr CORE_REG_PC
|
|
|
|
.endmacro
|
|
|
|
|
2023-04-02 10:39:35 +00:00
|
|
|
.macro call_stack_jump_cond_if, call_stack_jump_cond_if_arg_0_if_label
|
2023-03-24 20:13:40 +00:00
|
|
|
.std_ld
|
|
|
|
tlr CORE_REG_A
|
2023-04-01 17:20:32 +00:00
|
|
|
.std_rset CORE_REG_C, call_stack_jump_cond_if_arg_0_if_label
|
2023-04-04 12:07:21 +00:00
|
|
|
.std_rset CORE_REG_D, (OFFSET + 7)
|
2023-04-01 17:20:32 +00:00
|
|
|
ts call_stack_jump
|
|
|
|
tlrc CORE_REG_PC
|
2023-03-24 20:13:40 +00:00
|
|
|
.endmacro
|
|
|
|
|
2023-04-02 10:39:35 +00:00
|
|
|
.define_eval prev, OFFSET
|
|
|
|
.std_ld
|
|
|
|
tlr CORE_REG_A
|
2023-04-04 18:22:36 +00:00
|
|
|
.std_rset CORE_REG_C, PLACEHOLDER_U16
|
|
|
|
.std_rset CORE_REG_D, PLACEHOLDER_U16
|
2023-04-02 10:39:35 +00:00
|
|
|
ts call_stack_jump
|
|
|
|
tlrc CORE_REG_PC
|
|
|
|
|
2023-04-04 18:22:36 +00:00
|
|
|
.std_rset CORE_REG_C, PLACEHOLDER_U16
|
|
|
|
.std_rset CORE_REG_D, PLACEHOLDER_U16
|
2023-04-02 10:39:35 +00:00
|
|
|
ts call_stack_jump
|
|
|
|
tlr CORE_REG_PC
|
|
|
|
.define_eval CALL_STACK_JUMP_COND_IF_ELSE_SIZE, (OFFSET - prev)
|
|
|
|
.org prev
|
|
|
|
.delete prev
|
|
|
|
|
|
|
|
.macro call_stack_jump_cond_if_else, call_stack_jump_cond_if_else_arg_0_if_label, call_stack_jump_cond_if_else_arg_1_else_label
|
|
|
|
.define_eval prev, OFFSET
|
|
|
|
.define offset_till_end, (OFFSET - prev * -1 + CALL_STACK_JUMP_COND_IF_ELSE_SIZE)
|
|
|
|
|
2023-04-01 17:20:32 +00:00
|
|
|
.std_ld
|
|
|
|
tlr CORE_REG_A
|
|
|
|
.std_rset CORE_REG_C, call_stack_jump_cond_if_else_arg_0_if_label
|
2023-04-02 10:39:35 +00:00
|
|
|
.std_rset CORE_REG_D, (OFFSET + offset_till_end)
|
2023-04-01 17:20:32 +00:00
|
|
|
ts call_stack_jump
|
|
|
|
tlrc CORE_REG_PC
|
|
|
|
|
|
|
|
.std_rset CORE_REG_C, call_stack_jump_cond_if_else_arg_1_else_label
|
2023-04-02 10:39:35 +00:00
|
|
|
.std_rset CORE_REG_D, (OFFSET + offset_till_end)
|
2023-03-24 20:13:40 +00:00
|
|
|
ts call_stack_jump
|
|
|
|
tlr CORE_REG_PC
|
2023-04-01 17:20:32 +00:00
|
|
|
|
2023-04-02 10:39:35 +00:00
|
|
|
.delete prev, offset_till_end
|
2023-03-24 20:13:40 +00:00
|
|
|
.endmacro
|
|
|
|
|
|
|
|
.macro return_call_stack_jump
|
|
|
|
.std_jump return_call_stack_jump
|
|
|
|
.endmacro
|
|
|
|
|
|
|
|
; data
|
|
|
|
; strings
|
2023-04-04 12:07:21 +00:00
|
|
|
data_strings_0:
|
|
|
|
.bytes 0x48
|
|
|
|
.bytes 0x65
|
|
|
|
.bytes 0x6c
|
|
|
|
.bytes 0x6c
|
|
|
|
.bytes 0x6f
|
|
|
|
.bytes 0x20
|
|
|
|
.bytes 0x77
|
|
|
|
.bytes 0x6f
|
|
|
|
.bytes 0x72
|
|
|
|
.bytes 0x6c
|
|
|
|
.bytes 0x64
|
|
|
|
.bytes 0x21
|
|
|
|
data_strings_end_0:
|
|
|
|
|
2023-03-24 20:13:40 +00:00
|
|
|
|
|
|
|
; conditions
|
2023-04-01 17:20:32 +00:00
|
|
|
; condition: 0
|
|
|
|
conditions_if_0:
|
2023-04-03 09:42:45 +00:00
|
|
|
push 69
|
2023-04-01 17:20:32 +00:00
|
|
|
.std_ld
|
|
|
|
tlr CORE_REG_A
|
|
|
|
.std_set CORE_MEM_OUT
|
|
|
|
.return_call_stack_jump
|
|
|
|
|
|
|
|
conditions_else_0:
|
2023-04-03 09:42:45 +00:00
|
|
|
push 420
|
2023-04-01 17:20:32 +00:00
|
|
|
.std_ld
|
|
|
|
tlr CORE_REG_A
|
|
|
|
.std_set CORE_MEM_OUT
|
|
|
|
.return_call_stack_jump
|
|
|
|
|
2023-04-04 12:07:21 +00:00
|
|
|
; condition: 1
|
|
|
|
conditions_if_1:
|
|
|
|
push 32
|
|
|
|
.std_ld
|
|
|
|
tlr CORE_REG_A
|
|
|
|
.std_set CORE_MEM_OUT
|
|
|
|
.std_rset CORE_REG_A, '\n'
|
|
|
|
.std_set CORE_MEM_CHR
|
|
|
|
.return_call_stack_jump
|
|
|
|
|
2023-03-24 20:13:40 +00:00
|
|
|
|
|
|
|
; words
|
2023-04-04 12:07:21 +00:00
|
|
|
words_0:
|
|
|
|
push 40
|
|
|
|
push 2
|
|
|
|
.stack_transfer_alu
|
|
|
|
.std_alu CORE_ALU_ADD
|
|
|
|
tls
|
|
|
|
.return_call_stack_jump
|
|
|
|
|
2023-04-04 18:22:36 +00:00
|
|
|
words_1:
|
|
|
|
push 32
|
|
|
|
.return_call_stack_jump
|
|
|
|
|
|
|
|
words_2:
|
|
|
|
push 4875
|
|
|
|
push 8748
|
|
|
|
dbg
|
|
|
|
.return_call_stack_jump
|
|
|
|
|
2023-04-04 12:07:21 +00:00
|
|
|
|
|
|
|
; static jump table
|
|
|
|
.define_eval prev, OFFSET
|
|
|
|
; conditions
|
|
|
|
; condition: 0
|
|
|
|
.org jump_table_conditions_if_0
|
|
|
|
.bytes conditions_if_0
|
|
|
|
.org jump_table_conditions_else_0
|
|
|
|
.bytes conditions_else_0
|
|
|
|
|
|
|
|
; condition: 1
|
|
|
|
.org jump_table_conditions_if_1
|
|
|
|
.bytes conditions_if_1
|
|
|
|
|
2023-04-04 18:22:36 +00:00
|
|
|
|
|
|
|
; words
|
|
|
|
.org jump_table_words_0
|
|
|
|
.bytes words_0
|
|
|
|
|
|
|
|
.org jump_table_words_1
|
|
|
|
.bytes words_1
|
|
|
|
|
|
|
|
.org jump_table_words_2
|
|
|
|
.bytes words_2
|
|
|
|
|
2023-04-04 12:07:21 +00:00
|
|
|
.org prev
|
|
|
|
.delete prev
|
2023-03-24 20:13:40 +00:00
|
|
|
|
|
|
|
; main
|
2023-04-01 17:20:32 +00:00
|
|
|
main:
|
|
|
|
.org MAIN_JUMPER
|
|
|
|
ts main
|
|
|
|
tlr CORE_REG_PC
|
2023-03-24 20:13:40 +00:00
|
|
|
|
2023-04-01 17:20:32 +00:00
|
|
|
.org main
|
2023-04-03 09:42:45 +00:00
|
|
|
push 42
|
|
|
|
tls
|
2023-04-02 12:32:11 +00:00
|
|
|
.stack_transfer_alu
|
2023-04-03 09:42:45 +00:00
|
|
|
.std_alu CORE_ALU_EQ
|
2023-04-02 12:32:11 +00:00
|
|
|
tls
|
|
|
|
dbg
|
2023-04-03 09:42:45 +00:00
|
|
|
.call_stack_jump_cond_if_else conditions_if_0, conditions_else_0
|
|
|
|
.std_rset CORE_REG_A, '\n'
|
|
|
|
.std_set CORE_MEM_CHR
|
2023-04-04 12:07:21 +00:00
|
|
|
push 1
|
|
|
|
dbg
|
|
|
|
.call_stack_jump_cond_if conditions_if_1
|
|
|
|
.call_stack_jump words_0
|
|
|
|
dbg
|
|
|
|
.call_stack_jump words_0
|
|
|
|
dbg
|
|
|
|
.std_rset CORE_REG_A, ' '
|
|
|
|
.std_set CORE_MEM_CHR
|
|
|
|
.std_rset CORE_REG_B, data_strings_0
|
|
|
|
loop_strings_0:
|
|
|
|
tsr CORE_REG_B
|
|
|
|
get
|
|
|
|
tlr CORE_REG_A
|
|
|
|
.std_set CORE_MEM_CHR
|
|
|
|
.std_rset CORE_REG_A, 1
|
|
|
|
.std_alu CORE_ALU_ADD
|
|
|
|
tlr CORE_REG_B
|
|
|
|
.std_rset CORE_REG_A, data_strings_end_0
|
|
|
|
.std_alu CORE_ALU_GT
|
|
|
|
tlr CORE_REG_A
|
|
|
|
.std_cond_jump loop_strings_0
|
|
|
|
.std_rset CORE_REG_A, '\n'
|
|
|
|
.std_set CORE_MEM_CHR
|
|
|
|
.std_rset CORE_REG_A, ' '
|
|
|
|
.std_set CORE_MEM_CHR
|
|
|
|
set
|
|
|
|
.std_rset CORE_REG_B, data_strings_0
|
|
|
|
loop_strings_0:
|
|
|
|
tsr CORE_REG_B
|
|
|
|
get
|
|
|
|
tlr CORE_REG_A
|
|
|
|
.std_set CORE_MEM_CHR
|
|
|
|
.std_rset CORE_REG_A, 1
|
|
|
|
.std_alu CORE_ALU_ADD
|
|
|
|
tlr CORE_REG_B
|
|
|
|
.std_rset CORE_REG_A, data_strings_end_0
|
|
|
|
.std_alu CORE_ALU_GT
|
|
|
|
tlr CORE_REG_A
|
|
|
|
.std_cond_jump loop_strings_0
|
|
|
|
.std_rset CORE_REG_A, '\n'
|
|
|
|
.std_set CORE_MEM_CHR
|
2023-04-04 18:22:36 +00:00
|
|
|
.call_stack_jump words_2
|
|
|
|
.call_stack_jump words_1
|
|
|
|
.call_stack_jump words_2
|
|
|
|
.call_stack_jump words_1
|
2023-03-23 16:59:10 +00:00
|
|
|
.std_stop
|