Add working macro system

This commit is contained in:
Dominic Grimm 2022-09-02 11:33:46 +02:00
parent 6adb943754
commit 1ff9a6c44b
No known key found for this signature in database
GPG key ID: A6C051C716D2CE65
19 changed files with 1258 additions and 571 deletions

52
lib/core.asm Normal file
View file

@ -0,0 +1,52 @@
; hence core lib
core:
.define NULL, 0x0000
.define VOID, NULL
.define FALSE, NULL
.define TRUE, 0x0001
.define CORE_U8_MAX, 0x00ff
.define CORE_U16_MAX, 0xffff
.define CORE_KB, 1024
core_mem:
.define CORE_MEM_PRG, (0 * CORE_KB)
.define CORE_MEM_ST, (32 * CORE_KB)
.define CORE_MEM_MEM, (40 * CORE_KB)
.define CORE_MEM_OUT, (56 * CORE_KB)
.define CORE_MEM_CHR, (56 * CORE_KB + 1)
.define CORE_MEM_KEY, (56 * CORE_KB + 2)
core_reg:
.define CORE_REG_PC, 0x0
.define CORE_REG_OPC, 0x1
.define CORE_REG_ARG, 0x2
.define CORE_REG_S, 0x3
.define CORE_REG_SP, 0x4
.define CORE_REG_A, 0x5
.define CORE_REG_B, 0x6
.define CORE_REG_C, 0x7
.define CORE_REG_D, 0x8
core_alu:
.define CORE_ALU_NOT, 0x00
.define CORE_ALU_AND, 0x01
.define CORE_ALU_OR, 0x02
.define CORE_ALU_XOR, 0x03
.define CORE_ALU_LSH, 0x04
.define CORE_ALU_RSH, 0x05
.define CORE_ALU_ADD, 0x06
.define CORE_ALU_SUB, 0x07
.define CORE_ALU_MUL, 0x08
.define CORE_ALU_DIV, 0x09
.define CORE_ALU_CMP, 0x0a
.define CORE_ALU_EQ, 0x0b
.define CORE_ALU_LT, 0x0c
.define CORE_ALU_GT, 0x0d
.define CORE_ALU_LEQ, 0x0e
.define CORE_ALU_GEQ, 0x0f
.define CORE_ALU_BOL, 0x10
.define CORE_ALU_INV, 0x11
.define CORE_ALU_RND, 0x12

19
lib/main.asm Normal file
View file

@ -0,0 +1,19 @@
; "main function" like definition macro
.requires "$lib/core.asm"
.requires "$lib/std.asm"
.define main_local_jump_main, (CORE_MEM_ST - 3 - 1)
.macro jump_main
.std_jump main_local_jump_main
.endmacro
.macro main
main:
.org main_local_jump_main
ts main
tlr CORE_REG_PC
.org main
.endmacro

62
lib/std.asm Normal file
View file

@ -0,0 +1,62 @@
; hence standard lib
.requires "$lib/core.asm"
std:
.macro std_tclr
ts NULL
.endmacro
.macro std_rclr, std_rclr_arg_0_reg
ts NULL
tlr std_rclr_arg_0_reg
.endmacro
.macro std_alu, std_alu_arg_0_op
ts std_alu_arg_0_op
alu
.endmacro
.macro std_get, std_get_arg_0_addr
ts std_get_arg_0_addr
get
.endmacro
.macro std_set, std_set_arg_0_addr
ts std_set_arg_0_addr
set
.endmacro
.macro std_cp, std_cp_arg_0_from, std_cp_arg_1_to
tsr std_cp_arg_0_from
tlr std_cp_arg_1_to
.endmacro
.macro std_mv, std_mv_arg_0_from, std_cp_arg_1_to
tsr std_cp_arg_0_from
tlr std_cp_arg_1_to
.std_rclr std_cp_arg_1_to
.endmacro
.macro std_rset, std_init_arg_0_reg, std_init_arg_1_val
ts std_init_arg_1_val
tlr std_init_arg_0_reg
.endmacro
.macro std_jump, std_jump_arg_0_label
.std_rset CORE_REG_PC, std_jump_arg_0_label
.endmacro
.macro std_cond_jump, std_cond_jump_arg_0_label
ts std_cond_jump_arg_0_label
tlrc CORE_REG_PC
.endmacro
.macro std_stop
.std_rset CORE_REG_PC, 0xffff
.endmacro
.macro std_inc, std_inc_arg_0_reg
.std_rset std_inc_arg_0_reg, 1
.std_alu CORE_ALU_ADD
.endmacro