aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--atk16_asm/asm_pass3.py14
-rw-r--r--atk16_asm/builtin_asm/bootstrap.atk1656
-rw-r--r--resources/asm/text_mode.atk1614
3 files changed, 50 insertions, 34 deletions
diff --git a/atk16_asm/asm_pass3.py b/atk16_asm/asm_pass3.py
index ec8b20c..a3f9537 100644
--- a/atk16_asm/asm_pass3.py
+++ b/atk16_asm/asm_pass3.py
@@ -50,12 +50,22 @@ def pass_3(result2: Result2) -> Result3:
original_text=original_text,
)
+ # On address conflict, if override_mode is True, the last definition wins
+ # otherwise, an exception is raised
+ override_mode = False
+
for line in result2.lines:
keyword, *args = line.parts
match keyword:
case "@address":
address = eval_expr(symbols, args[0])
continue
+ case "@begin_override":
+ override_mode = True
+ continue
+ case "@end_override":
+ override_mode = False
+ continue
case "@label":
label = args[0]
if label in symbols:
@@ -67,6 +77,10 @@ def pass_3(result2: Result2) -> Result3:
symbols[args[0]] = eval_expr(symbols, args[1])
continue
case _:
+ if override_mode:
+ # TODO this is a bit inefficient, but works
+ result_lines = list(filter(lambda l: l.address != address, result_lines))
+
dbg_original_text = " ".join(line.original_parts)
dbg_expanded_text = " ".join(line.parts)
save_dbg_source(address, line.src_file, line.line_num, dbg_expanded_text, dbg_original_text)
diff --git a/atk16_asm/builtin_asm/bootstrap.atk16 b/atk16_asm/builtin_asm/bootstrap.atk16
index 9b024e6..94eed4c 100644
--- a/atk16_asm/builtin_asm/bootstrap.atk16
+++ b/atk16_asm/builtin_asm/bootstrap.atk16
@@ -1,18 +1,5 @@
@let SP RH
-; vector table fields
-@let vector_table 0x10
-@let vt_ISR0 0x10 ; ISR0
-@let vt_ISR1 0x11 ; ISR1
-@let vt_ISR2 0x12 ; ISR2
-@let vt_ISR3 0x13 ; ISR3
-@let vt_stack_addr 0x14 ; Stack address
-@let vt_term_pp_addr 0x15 ; Terminal peripheral address
-@let vt_kb_pp_addr 0x16 ; Keyboard peripheral address
-@let vt_gr_mode_addr 0x17 ; Graphics mode setting address
-@let vt_sprite_mem 0x18 ; Sprite memory address
-@let vt_text_mem 0x19 ; Text memory buffer address
-
; memory segments
@let stack_segment 0x8000
@let mmio_segment 0xE000
@@ -29,8 +16,21 @@
@let gr_text_mode 0b01
@let gr_sprite_mode 0b10
+; vector table fields
+@let vector_table 0x10
+@let vt_ISR0 0x10 ; ISR0
+@let vt_ISR1 0x11 ; ISR1
+@let vt_ISR2 0x12 ; ISR2
+@let vt_ISR3 0x13 ; ISR3
+@let vt_stack_addr 0x14 ; Stack address
+@let vt_term_pp_addr 0x15 ; Terminal peripheral address
+@let vt_kb_pp_addr 0x16 ; Keyboard peripheral address
+@let vt_gr_mode_addr 0x17 ; Graphics mode setting address
+@let vt_sprite_mem 0x18 ; Sprite memory address
+@let vt_text_mem 0x19 ; Text memory buffer address
+
@address vector_table
- keyboard_isr ; 0x10
+ hlt_isr ; 0x10
hlt_isr ; 0x11
hlt_isr ; 0x12
hlt_isr ; 0x13
@@ -45,19 +45,21 @@
ldi 0x55 RE
hlt
-@label keyboard_isr
- spu RA
- spu RB
- ldi vt_kb_pp_addr RA ; RA := Keyboard peripheral address pointer
- ldr RA RA ; RA := Keyboard peripheral address deref
- ldr RA RA ; RA := <16-bit keyboard character code> from MMIO register
- ldi vt_term_pp_addr RB ; RB := Terminal peripheral address pointer
- ldr RB RB ; RB := Terminal peripheral address deref
- str RA RB ; terminal <- character code (ASCII?)
- mov RA RE ; RE := character code (for debugging)
- spo RB
- spo RA
- rti
+; Example ISR for keyboard to terminal
+; @label keyboard_to_terminal_isr
+; spu RA
+; spu RB
+; ldi vt_kb_pp_addr RA ; RA := Keyboard peripheral address pointer
+; ldr RA RA ; RA := Keyboard peripheral address deref
+; ldr RA RA ; RA := <16-bit keyboard character code> from MMIO register
+; ldi vt_term_pp_addr RB ; RB := Terminal peripheral address pointer
+; ldr RB RB ; RB := Terminal peripheral address deref
+; str RA RB ; terminal <- character code (ASCII?)
+; mov RA RE ; RE := character code (for debugging)
+; spo RB
+; spo RA
+; rti
+
@label program_segment
; define short prelude that sets up vital instructions
diff --git a/resources/asm/text_mode.atk16 b/resources/asm/text_mode.atk16
index f20eac9..3fc40d2 100644
--- a/resources/asm/text_mode.atk16
+++ b/resources/asm/text_mode.atk16
@@ -1,11 +1,6 @@
-@opt stack_pointer RG
-@opt csr_scratch RH
-@use ext_std:*
@use ext_string_io:*
-; bootstrap code (must be called to set up mandatory data)
-; will jump to label main
-@include bootstrap
+@include %bootstrap
@label main
cursor_to_line RC 1
@@ -21,7 +16,7 @@
@label loop
jpi loop
-@label keyboard_isr
+@label my_keyboard_isr
stack_stash RA RB RD
ldi vt_kb_pp_addr RA ; RA := Keyboard peripheral address pointer
ldr RA RA ; RA := Keyboard peripheral address deref
@@ -56,3 +51,8 @@
@label keyboard_isr_end
stack_restore RA RB RD
rti
+
+@address vt_ISR0
+@begin_override
+ my_keyboard_isr
+@end_override