From 549901c85044b6ccd912688d6be007c2fdacc6c6 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Tue, 20 Feb 2024 16:55:14 +0200 Subject: Refactor dir structure --- asm/aoc23_1a.atk16 | 554 --------------------------------------- asm/aoc23_1a.py | 48 ---- asm/ast_compiler_bootstrap.atk16 | 74 ------ asm/atk16.py | 39 --- asm/bootstrap.atk16 | 71 ----- asm/ext_std.py | 157 ----------- asm/ext_string_io.py | 56 ---- asm/fibo.atk16 | 57 ---- asm/idle_loop.atk16 | 10 - asm/sum.atk16 | 32 --- asm/test_py_src.atk16 | 301 --------------------- asm/test_py_src.py | 36 --- asm/text_mode.atk16 | 58 ---- 13 files changed, 1493 deletions(-) delete mode 100644 asm/aoc23_1a.atk16 delete mode 100644 asm/aoc23_1a.py delete mode 100644 asm/ast_compiler_bootstrap.atk16 delete mode 100644 asm/atk16.py delete mode 100644 asm/bootstrap.atk16 delete mode 100644 asm/ext_std.py delete mode 100644 asm/ext_string_io.py delete mode 100644 asm/fibo.atk16 delete mode 100644 asm/idle_loop.atk16 delete mode 100644 asm/sum.atk16 delete mode 100644 asm/test_py_src.atk16 delete mode 100644 asm/test_py_src.py delete mode 100644 asm/text_mode.atk16 (limited to 'asm') diff --git a/asm/aoc23_1a.atk16 b/asm/aoc23_1a.atk16 deleted file mode 100644 index 78c4622..0000000 --- a/asm/aoc23_1a.atk16 +++ /dev/null @@ -1,554 +0,0 @@ -;; BEGIN BOOTSTRAP - -@use ext_std:* - -@let sp RH ; stack pointer (points to empty slot at top of stack) -@let fp RG ; frame pointer (points to base of currently active frame) - -@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 - -@let stack_segment 0x8000 -@let mmio_segment 0xE000 -@let terminal_addr 0xE000 -@let keyboard_addr 0xE001 -@let gr_mode_addr 0xE002 -@let sprite_mem 0xE800 -@let text_mem 0xF800 - -@let gr_disabled_mode 0b00 -@let gr_text_mode 0b01 -@let gr_sprite_mode 0b10 - -@address 0x0 - ldi vt_stack_addr RA - ldr RA SP - mov SP FP - jpi program_segment - -@address vector_table - keyboard_isr ; 0x10 - hlt_isr ; 0x11 - hlt_isr ; 0x12 - hlt_isr ; 0x13 - stack_segment ; 0x14 - terminal_addr ; 0x15 - keyboard_addr ; 0x16 - gr_mode_addr ; 0x17 - sprite_mem ; 0x18 - text_mem ; 0x19 - -@label hlt_isr - hlt - -@label keyboard_isr - spu RA - spu RB - ldi vt_kb_pp_addr RA - ldr RA RA - ldr RA RA - ldi vt_term_pp_addr RB - ldr RB RB - str RA RB - spo RB - spo RA - rti - -@label program_segment - ldi vt_gr_mode_addr RA - ldr RA RA - ldi gr_disabled_mode RB - str RB RA - - jpi main - -;; END BOOTSTRAP - -@label int_0 - 8 -@label graphics_no_mode - 0 -@label graphics_text_mode - 1 -@label graphics_sprite_mode - 2 -@label graphics_mode_pp - 23 -@label text_mem_pp - 25 -@label input_p - 36864 -@label input_elem_size - 256 -@label int_1 - 49 -@label int_2 - 97 -@label int_3 - 98 -@label int_4 - 99 -@label int_5 - 50 - - - -@label main -; stack frame with offsets -; graphics_mode_p 0 -; text_mem_p 1 -; row_p 2 -; i 3 -; first 4 -; last 5 -; char_p 6 -; char 7 - ldi int_0 RA - ldr RA RA - add SP RA SP -; -; assigning graphics_mode_p at FP + 0 -; evaluating value to be assigned -; -; Builtin call load [] -; (GRAPHICS_MODE_PP) - ldi graphics_mode_pp RC - ldr RC RC - spu RC -; (load) dereferencing top of stack - spo RC - ldr RC RC - spu RC -; assigning stack address (FP + 0) := top of stack - spo RA - ldi 0 RB - add RB FP RB - str RA RB -; -; assigning text_mem_p at FP + 1 -; evaluating value to be assigned -; -; Builtin call load [] -; (TEXT_MEM_PP) - ldi text_mem_pp RC - ldr RC RC - spu RC -; (load) dereferencing top of stack - spo RC - ldr RC RC - spu RC -; assigning stack address (FP + 1) := top of stack - spo RA - ldi 1 RB - add RB FP RB - str RA RB -; -; Builtin call store [, ] -; (graphics_mode_p) - ldi 0 RA - add FP RA RA - ldr RA RA - spu RA -; (GRAPHICS_TEXT_MODE) - ldi graphics_text_mode RA - ldr RA RA - spu RA - spo RB - spo RA - str RB RA - ldi 0 RA - spu RA -; popping free-standing Expr result from stack - spo RA -; -; Builtin call store [, ] -; -; BinOp lhs -; (INPUT_P) - ldi input_p RA - ldr RA RA - spu RA -; BinOp rhs -; - ldi 0 RA - spu RA - spo RB - spo RA - add RA RB RA - spu RA -; - ldi int_1 RA - ldr RA RA ; int_1 = 49 - spu RA - spo RB - spo RA - str RB RA - ldi 0 RA - spu RA -; popping free-standing Expr result from stack - spo RA -; -; Builtin call store [, ] -; -; BinOp lhs -; (INPUT_P) - ldi input_p RA - ldr RA RA - spu RA -; BinOp rhs -; - ldi 1 RA - spu RA - spo RB - spo RA - add RA RB RA - spu RA -; - ldi int_2 RA - ldr RA RA ; int_2 = 97 - spu RA - spo RB - spo RA - str RB RA - ldi 0 RA - spu RA -; popping free-standing Expr result from stack - spo RA -; -; Builtin call store [, ] -; -; BinOp lhs -; (INPUT_P) - ldi input_p RA - ldr RA RA - spu RA -; BinOp rhs -; - ldi 2 RA - spu RA - spo RB - spo RA - add RA RB RA - spu RA -; - ldi int_3 RA - ldr RA RA ; int_3 = 98 - spu RA - spo RB - spo RA - str RB RA - ldi 0 RA - spu RA -; popping free-standing Expr result from stack - spo RA -; -; Builtin call store [, ] -; -; BinOp lhs -; (INPUT_P) - ldi input_p RA - ldr RA RA - spu RA -; BinOp rhs -; - ldi 3 RA - spu RA - spo RB - spo RA - add RA RB RA - spu RA -; - ldi int_4 RA - ldr RA RA ; int_4 = 99 - spu RA - spo RB - spo RA - str RB RA - ldi 0 RA - spu RA -; popping free-standing Expr result from stack - spo RA -; -; Builtin call store [, ] -; -; BinOp lhs -; (INPUT_P) - ldi input_p RA - ldr RA RA - spu RA -; BinOp rhs -; - ldi 4 RA - spu RA - spo RB - spo RA - add RA RB RA - spu RA -; - ldi int_5 RA - ldr RA RA ; int_5 = 50 - spu RA - spo RB - spo RA - str RB RA - ldi 0 RA - spu RA -; popping free-standing Expr result from stack - spo RA -; -; Builtin call store [, ] -; -; BinOp lhs -; (INPUT_P) - ldi input_p RA - ldr RA RA - spu RA -; BinOp rhs -; - ldi 5 RA - spu RA - spo RB - spo RA - add RA RB RA - spu RA -; - ldi 0 RA - spu RA - spo RB - spo RA - str RB RA - ldi 0 RA - spu RA -; popping free-standing Expr result from stack - spo RA -; -; assigning row_p at FP + 2 -; evaluating value to be assigned -; (INPUT_P) - ldi input_p RC - ldr RC RC - spu RC -; assigning stack address (FP + 2) := top of stack - spo RA - ldi 2 RB - add RB FP RB - str RA RB -; -; assigning i at FP + 3 -; evaluating value to be assigned -; - ldi 0 RC - spu RC -; assigning stack address (FP + 3) := top of stack - spo RA - ldi 3 RB - add RB FP RB - str RA RB -; -; assigning first at FP + 4 -; evaluating value to be assigned -; -; Builtin call load [] -; (row_p) - ldi 2 RC - add FP RC RC - ldr RC RC - spu RC -; (load) dereferencing top of stack - spo RC - ldr RC RC - spu RC -; assigning stack address (FP + 4) := top of stack - spo RA - ldi 4 RB - add RB FP RB - str RA RB -; -; assigning last at FP + 5 -; evaluating value to be assigned -; - ldi 0 RC - spu RC -; assigning stack address (FP + 5) := top of stack - spo RA - ldi 5 RB - add RB FP RB - str RA RB -; -@label while_test_6 -; - ldi 1 RB - spu RB - spo RA - addi RA 0 RA - bri zero While_else_7 -; -; assigning char_p at FP + 6 -; evaluating value to be assigned -; -; BinOp lhs -; (INPUT_P) - ldi input_p RC - ldr RC RC - spu RC -; BinOp rhs -; (i) - ldi 3 RC - add FP RC RC - ldr RC RC - spu RC - spo RD - spo RC - add RC RD RC - spu RC -; assigning stack address (FP + 6) := top of stack - spo RA - ldi 6 RB - add RB FP RB - str RA RB -; -; assigning char at FP + 7 -; evaluating value to be assigned -; -; Builtin call load [] -; (char_p) - ldi 6 RC - add FP RC RC - ldr RC RC - spu RC -; (load) dereferencing top of stack - spo RC - ldr RC RC - spu RC -; assigning stack address (FP + 7) := top of stack - spo RA - ldi 7 RB - add RB FP RB - str RA RB -; -; -; (char) - ldi 7 RA - add FP RA RA - ldr RA RA - spu RA -; - ldi 0 RA - spu RA -; Comparing - spo RA - addi RA 0 RA - bri zero If_false_branch_11 -; - jpi While_end_8 - jpi If_end_branch_12 -@label if_false_branch_11 -@label if_end_branch_12 -; -; assigning last at FP + 5 -; evaluating value to be assigned -; (char) - ldi 7 RC - add FP RC RC - ldr RC RC - spu RC -; assigning stack address (FP + 5) := top of stack - spo RA - ldi 5 RB - add RB FP RB - str RA RB -; -; assigning i at FP + 3 -; evaluating value to be assigned -; -; BinOp lhs -; (i) - ldi 3 RC - add FP RC RC - ldr RC RC - spu RC -; BinOp rhs -; - ldi 1 RC - spu RC - spo RD - spo RC - add RC RD RC - spu RC -; assigning stack address (FP + 3) := top of stack - spo RA - ldi 3 RB - add RB FP RB - str RA RB - jpi While_test_6 -@label while_else_7 -@label while_end_8 -; -; Builtin call store [, ] -; -; BinOp lhs -; (text_mem_p) - ldi 1 RA - add FP RA RA - ldr RA RA - spu RA -; BinOp rhs -; - ldi 0 RA - spu RA - spo RB - spo RA - add RA RB RA - spu RA -; (first) - ldi 4 RA - add FP RA RA - ldr RA RA - spu RA - spo RB - spo RA - str RB RA - ldi 0 RA - spu RA -; popping free-standing Expr result from stack - spo RA -; -; Builtin call store [, ] -; -; BinOp lhs -; (text_mem_p) - ldi 1 RA - add FP RA RA - ldr RA RA - spu RA -; BinOp rhs -; - ldi 1 RA - spu RA - spo RB - spo RA - add RA RB RA - spu RA -; (last) - ldi 5 RA - add FP RA RA - ldr RA RA - spu RA - spo RB - spo RA - str RB RA - ldi 0 RA - spu RA -; popping free-standing Expr result from stack - spo RA - mov FP SP - hlt diff --git a/asm/aoc23_1a.py b/asm/aoc23_1a.py deleted file mode 100644 index 12e3953..0000000 --- a/asm/aoc23_1a.py +++ /dev/null @@ -1,48 +0,0 @@ -import atk16 - -GRAPHICS_NO_MODE: atk16.ConstWord16 = 0 -GRAPHICS_TEXT_MODE: atk16.ConstWord16 = 1 -GRAPHICS_SPRITE_MODE: atk16.ConstWord16 = 2 - -GRAPHICS_MODE_PP: atk16.ConstWord16 = 0x17 -TEXT_MEM_PP: atk16.ConstWord16 = 0x19 - -graphics_mode_p = atk16.load(GRAPHICS_MODE_PP) -text_mem_p = atk16.load(TEXT_MEM_PP) - -atk16.store(graphics_mode_p, GRAPHICS_TEXT_MODE) - -INPUT_P: atk16.ConstWord16 = 0x9000 -INPUT_ELEM_SIZE: atk16.ConstWord16 = 256 - -# 1a example - -atk16.store(INPUT_P + 0, "1") -atk16.store(INPUT_P + 1, "a") -atk16.store(INPUT_P + 2, "b") -atk16.store(INPUT_P + 3, "c") -atk16.store(INPUT_P + 4, "2") -atk16.store(INPUT_P + 5, "\0") -# atk16.store_const_vec(INPUT_P + 0, "1abc2\0") -# atk16.store_const_vec(INPUT_P + 256, "pqr3stu8vwx\0") -# atk16.store_const_vec(INPUT_P + 512, "a1b2c3d4e5f\0") -# atk16.store_const_vec(INPUT_P + 768, "treb7uchet\0") - -row_p = INPUT_P -i = 0 - -first = atk16.load(row_p) -last = 0 - -while True: - char_p = INPUT_P + i - char = atk16.load(char_p) - - if char == "\0": - break - - last = char - i += 1 - -atk16.store(text_mem_p + 0, first) -atk16.store(text_mem_p + 1, last) \ No newline at end of file diff --git a/asm/ast_compiler_bootstrap.atk16 b/asm/ast_compiler_bootstrap.atk16 deleted file mode 100644 index 2e112eb..0000000 --- a/asm/ast_compiler_bootstrap.atk16 +++ /dev/null @@ -1,74 +0,0 @@ -;; BEGIN BOOTSTRAP - -@use ext_std:* - -@let sp RH ; stack pointer (points to empty slot at top of stack) -@let fp RG ; frame pointer (points to base of currently active frame) - -@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 - -@let stack_segment 0x8000 -@let mmio_segment 0xE000 -@let terminal_addr 0xE000 -@let keyboard_addr 0xE001 -@let gr_mode_addr 0xE002 -@let sprite_mem 0xE800 -@let text_mem 0xF800 - -@let gr_disabled_mode 0b00 -@let gr_text_mode 0b01 -@let gr_sprite_mode 0b10 - -@address 0x0 - ldi vt_stack_addr RA - ldr RA SP - mov SP FP - jpi program_segment - -@address vector_table - keyboard_isr ; 0x10 - hlt_isr ; 0x11 - hlt_isr ; 0x12 - hlt_isr ; 0x13 - stack_segment ; 0x14 - terminal_addr ; 0x15 - keyboard_addr ; 0x16 - gr_mode_addr ; 0x17 - sprite_mem ; 0x18 - text_mem ; 0x19 - -@label hlt_isr - hlt - -@label keyboard_isr - spu RA - spu RB - ldi vt_kb_pp_addr RA - ldr RA RA - ldr RA RA - ldi vt_term_pp_addr RB - ldr RB RB - str RA RB - spo RB - spo RA - rti - -@label program_segment - ldi vt_gr_mode_addr RA - ldr RA RA - ldi gr_disabled_mode RB - str RB RA - - jpi main - -;; END BOOTSTRAP \ No newline at end of file diff --git a/asm/atk16.py b/asm/atk16.py deleted file mode 100644 index 9aa3c55..0000000 --- a/asm/atk16.py +++ /dev/null @@ -1,39 +0,0 @@ -from typing import Literal, Any, TypeVar, NewType, Never, Callable, Generic, overload, cast -Char = Literal['\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\t', '\n', '\x0b', '\x0c', '\r', '\x0e', '\x0f', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', ' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', '\x7f', '\x80', '\x81', '\x82', '\x83', '\x84', '\x85', '\x86', '\x87', '\x88', '\x89', '\x8a', '\x8b', '\x8c', '\x8d', '\x8e', '\x8f', '\x90', '\x91', '\x92', '\x93', '\x94', '\x95', '\x96', '\x97', '\x98', '\x99', '\x9a', '\x9b', '\x9c', '\x9d', '\x9e', '\x9f', '\xa0', '¡', '¢', '£', '¤', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '\xad', '®', '¯', '°', '±', '²', '³', '´', 'µ', '¶', '·', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ'] -Void = Literal[0] -Word16 = int -ConstWord16 = int - -def store(p: Word16, value: Word16 | Char) -> Void: - raise NotImplementedError - -@overload -def store_const_vec(p: Word16, value: list[Word16]) -> Void: ... -@overload -def store_const_vec(p: Word16, value: list[Char]) -> Void: ... -@overload -def store_const_vec(p: Word16, value: str) -> Void: ... - -def store_const_vec(p, value) -> Void: - raise NotImplementedError - -def load(p: Word16) -> Word16: - raise NotImplementedError - -T = TypeVar("T") -def call_inline(expr: T) -> T: - """Inline the function call `expr` at the callsite. - This can lead to a larger output size but avoids having to do a subroutine call.""" - raise NotImplementedError - -def asm(asm: str): - """Inject ATK16 assembly `asm` into the compiled output.""" - raise NotImplementedError - -def ord(char: Char) -> int: - """Convert char to int""" - raise NotImplementedError - -def const(word: Word16) -> ConstWord16: - """When used in an assignment such as `A = const(0xFF)`, stores the value as a globally accessible constant.""" - raise NotImplementedError \ No newline at end of file diff --git a/asm/bootstrap.atk16 b/asm/bootstrap.atk16 deleted file mode 100644 index 4e5cd24..0000000 --- a/asm/bootstrap.atk16 +++ /dev/null @@ -1,71 +0,0 @@ -; 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 -@let terminal_addr 0xE000 -@let keyboard_addr 0xE001 -@let gr_mode_addr 0xE002 -@let sprite_mem 0xE800 -@let text_mem 0xF800 ; to 0xFFFF -; note: sprite memory & text memory can use the same space -; since they are never used at the same time - -; graphics mode settings -@let gr_disabled_mode 0b00 -@let gr_text_mode 0b01 -@let gr_sprite_mode 0b10 - -@address vector_table - keyboard_isr ; 0x10 - hlt_isr ; 0x11 - hlt_isr ; 0x12 - hlt_isr ; 0x13 - stack_segment ; 0x14 - terminal_addr ; 0x15 - keyboard_addr ; 0x16 - gr_mode_addr ; 0x17 - sprite_mem ; 0x18 - text_mem ; 0x19 - -@label hlt_isr - ldi 0x55 RE - hlt - -@label keyboard_isr - stack_stash RA 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) - stack_restore RA RB - rti -@label program_segment - -; define short prelude that sets up vital instructions -; NOTE: must be shorter than the vector table offset -@address 0x0 -; set up stack pointer to point to beginning of stack segment - ldi vt_stack_addr RA - ldr RA SP - jpi program_segment - -@address program_segment -; set graphics mode to disabled - set_graphics_mode gr_disabled_mode -; jump to main (user defined) - jpi main diff --git a/asm/ext_std.py b/asm/ext_std.py deleted file mode 100644 index 247e605..0000000 --- a/asm/ext_std.py +++ /dev/null @@ -1,157 +0,0 @@ -from asm_ops import * - -def expand_add(left: str, right: str, target: str) -> ExpandResult: - return [["alr", "al_plus", left, right, target]] - -def expand_sub(left: str, right: str, target: str) -> ExpandResult: - return [["alr", "al_minus", left, right, target]] - -def expand_addi(left: str, imm: str, target: str) -> ExpandResult: - return [["ali", "al_plus", left, imm, target]] - -def expand_subi(left: str, imm: str, target: str) -> ExpandResult: - return [["ali", "al_minus", left, imm, target]] - -def expand_not(reg: str, target: str) -> ExpandResult: - return [["alr", "al_xor", reg, "0xFFFF", target]] - -def expand_noti(imm: str, target: str) -> ExpandResult: - return [["ali", "al_xor", imm, "0xFFFF", target]] - -def expand_and(left: str, right: str, target: str) -> ExpandResult: - return [["alr", "al_and", left, right, target]] - -def expand_andi(left: str, imm: str, target: str) -> ExpandResult: - return [["ali", "al_and", left, imm, target]] - -def expand_or(left: str, right: str, target: str) -> ExpandResult: - return [["alr", "al_or", left, right, target]] - -def expand_ori(left: str, imm: str, target: str) -> ExpandResult: - return [["ali", "al_or", left, imm, target]] - -def expand_xor(left: str, imm: str, target: str) -> ExpandResult: - return [["alr", "al_xor", left, imm, target]] - -def expand_xori(left: str, right: str, target: str) -> ExpandResult: - return [["ali", "al_xor", left, right, target]] - -def expand_sll(left: str, right: str, target: str) -> ExpandResult: - return [["alr", "al_sll", left, right, target]] - -def expand_slr(left: str, right: str, target: str) -> ExpandResult: - return [["alr", "al_slr", left, right, target]] - -def expand_sar(left: str, right: str, target: str) -> ExpandResult: - return [["alr", "al_sar", left, right, target]] - -def expand_slli(left: str, imm: str, target: str) -> ExpandResult: - return [["ali", "al_sll", left, imm, target]] - -def expand_slri(left: str, imm: str, target: str) -> ExpandResult: - return [["ali", "al_slr", left, imm, target]] - -def expand_sari(left: str, imm: str, target: str) -> ExpandResult: - return [["ali", "al_sar", left, imm, target]] - -def expand_inc(reg: str) -> ExpandResult: - return [["ali", "al_plus", reg, "1", reg]] - -def expand_dec(reg: str) -> ExpandResult: - return [["ali", "al_minus", reg, "1", reg]] - -def expand_mov(from_reg: str, to_reg: str) -> ExpandResult: - return [["ali", "al_plus", from_reg, "0", to_reg]] - -def expand_nop() -> ExpandResult: - return [["ali", "al_plus", "RA", "0", "RA"]] - -def expand_spu(reg: str) -> ExpandResult: - return [["str", reg, "SP"]] + expand_inc("SP") - -def expand_spo(reg: str) -> ExpandResult: - return expand_dec("SP") + [["ldr", "SP", reg]] - -def expand_sinc(imm: str) -> ExpandResult: - return expand_addi("SP", imm, "SP") - -def expand_sdec(imm: str) -> ExpandResult: - return expand_subi("SP", imm, "SP") - -def expand_csr(addr_reg: str, stratch_reg: str): - return [ - ["lpc", stratch_reg], - *expand_addi(stratch_reg, "4", stratch_reg), - *expand_spu(stratch_reg), - ["jpr", addr_reg] - ] - -def expand_csi(addr_imm: str, stratch_reg: str): - return [ - ["lpc", stratch_reg], - *expand_addi(stratch_reg, "4", stratch_reg), - *expand_spu(stratch_reg), - ["jpi", addr_imm] - ] - -def expand_rsr(stratch_reg: str): - return expand_spo(stratch_reg) + [["jpr", stratch_reg]] - - -def stack_stash(*rs: str): - result: ExpandResult = [] - for r in rs: - result += expand_spu(r) - - return result - -def stack_restore(*rs: str): - result: ExpandResult = [] - for r in rs: - prefix = expand_spu(r) - result = prefix + result - - return result - -def set_graphics_mode(mode: str): - return [ - ["ldi", "vt_gr_mode_addr", "RA"], - ["ldr", "RA", "RA"], - ["ldi", mode, "RB"], - ["str", "RB", "RA"], - ] - -expansions: OpExpansionDict = { - "add": expand_add, - "sub": expand_sub, - "addi": expand_addi, - "subi": expand_subi, - "not": expand_not, - "noti": expand_noti, - "and": expand_and, - "andi": expand_andi, - "or": expand_or, - "ori": expand_ori, - "xor": expand_xor, - "xori": expand_xori, - "sll": expand_sll, - "slr": expand_slr, - "sar": expand_sar, - "slli": expand_slli, - "slri": expand_slri, - "sari": expand_sari, - "inc": expand_inc, - "dec": expand_dec, - "mov": expand_mov, - "nop": expand_nop, - "spu": expand_spu, - "spo": expand_spo, - "sinc": expand_sinc, - "sdec": expand_sdec, - "csr": expand_csr, - "csi": expand_csi, - "rsr": expand_rsr, - "stack_stash": stack_stash, - "stack_restore": stack_restore, - "set_graphics_mode": set_graphics_mode, -} diff --git a/asm/ext_string_io.py b/asm/ext_string_io.py deleted file mode 100644 index 519077d..0000000 --- a/asm/ext_string_io.py +++ /dev/null @@ -1,56 +0,0 @@ -from asm_ops import * -from ext_std import * - -def to_char_code(c: str): - return ord(c) - -_counter = 0 -def get_unique_name(prefix: str): - global _counter - ret = f"{prefix}_{_counter}" - _counter += 1 - return ret - -def expand_put_char(cursor_reg: str, scratch_reg: str, c: str) -> ExpandResult: - c = c.strip("\"") - return [ - ["ldi", str(to_char_code(c)), scratch_reg], - ["str", scratch_reg, cursor_reg], - *expand_addi(cursor_reg, "1", cursor_reg), - ] - -def expand_put_string(cursor_reg: str, scratch_reg: str, *rest: str) -> ExpandResult: - string = " ".join(rest) - string = string.strip("\"") - result: ExpandResult = [] - for c in string: - result += expand_put_char(cursor_reg, scratch_reg, c) - - return result - -def expand_cursor_to_line(cursor_reg: str, line: int) -> ExpandResult: - lbl_data = get_unique_name("cursor_to_line_data") - lbl_jmpover = get_unique_name("cursor_to_line_jmpover") - line_width = 64 - return [ - ["jpi", lbl_jmpover], - ["@label", lbl_data], - [f"text_mem + {line} * {line_width}"], - ["@label", lbl_jmpover], - ["ldi", lbl_data, cursor_reg], - ["ldr", cursor_reg, cursor_reg], - ] - -def expand_new_line(cursor_reg: str) -> ExpandResult: - return [ - *expand_slri(cursor_reg, "6", cursor_reg), - *expand_addi(cursor_reg, "1", cursor_reg), - *expand_slli(cursor_reg, "6", cursor_reg), - ] - -expansions: OpExpansionDict = { - "put_char": expand_put_char, - "cursor_to_line": expand_cursor_to_line, - "put_string": expand_put_string, - "new_line": expand_new_line, -} diff --git a/asm/fibo.atk16 b/asm/fibo.atk16 deleted file mode 100644 index 34999a9..0000000 --- a/asm/fibo.atk16 +++ /dev/null @@ -1,57 +0,0 @@ -@opt stack_pointer RG -@opt csr_scratch RH -@use ext_std:* - -; bootstrap code (must be called to setup mandatory data) -; will jump to label main -@include bootstrap - -@label main -; call fibo subroutine with parameter 10 - ldi 10 RA - csi fibo - hlt - -@label fibo -;;; subroutine fibo -;;; param RA N -;;; return RA Nth fibonacci number - -; store RB, RC on stack - spu RB - spu RC -; if n < 2, return n - subi RA 2 RA - bri sign fibo_early -; store also RD on stack - spu RD -; a = 0 - ldi 0 RB -; b = 1 - ldi 1 RC -@label fibo_loop -; v = a + b - add RB RC RD -; a = b - mov RC RB -; b = v - mov RD RC -; n -= 1 - dec RA -; loop while n > 0 - bri zero fibo_done - jpi fibo_loop -@label fibo_early -; restore used registers - spo RC - spo RB -; return from subroutine - rsr -@label fibo_done - mov RD RA -; restore used registers - spo RD - spo RC - spo RB -; return from subroutine - rsr diff --git a/asm/idle_loop.atk16 b/asm/idle_loop.atk16 deleted file mode 100644 index dd7d879..0000000 --- a/asm/idle_loop.atk16 +++ /dev/null @@ -1,10 +0,0 @@ -@opt stack_pointer RG -@opt csr_scratch RH -@use ext_std:* - -; bootstrap code (must be called to setup mandatory data) -; will jump to label main -@include bootstrap - -@label main - jpi main diff --git a/asm/sum.atk16 b/asm/sum.atk16 deleted file mode 100644 index 1bc3277..0000000 --- a/asm/sum.atk16 +++ /dev/null @@ -1,32 +0,0 @@ -@use ext_std:* -; Program: sum two values and store the result in RAM - -; ROM (and program execution) starts at offset 0x0 -@address 0x0 - jpi program - -@label ram_offset - 0x8000 ; store ram offset for later memory access - -@label program - ldi 10 RA ; RA := 10 - ldi 20 RB ; RB := 20 - add RA RB RC ; RC := RA + RB - ldi ram_offset RD ; store address of ram_offset in RD - ldr RD RD ; dereference ram_offset address -@label debug - str RC RD ; store RC in RAM - -; Check that 10 + 20 = 30 - mov RC RA ; RA := result of sum - ldi 30 RB ; RB := 30 - sub RA RB RC ; RC := RA - RB - bri zero success ; if result is zero, jump to success - - ldi 2 RA ; RA := 2 to signal failure - hlt - -; Else -@label success - ldi 1 RA ; RA := 1 to signal success - hlt diff --git a/asm/test_py_src.atk16 b/asm/test_py_src.atk16 deleted file mode 100644 index c38d1ca..0000000 --- a/asm/test_py_src.atk16 +++ /dev/null @@ -1,301 +0,0 @@ -;; BEGIN BOOTSTRAP - -@use ext_std:* - -@let sp RH ; stack pointer (points to empty slot at top of stack) -@let fp RG ; frame pointer (points to base of currently active frame) - -@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 - -@let stack_segment 0x8000 -@let mmio_segment 0xE000 -@let terminal_addr 0xE000 -@let keyboard_addr 0xE001 -@let gr_mode_addr 0xE002 -@let sprite_mem 0xE800 -@let text_mem 0xF800 - -@let gr_disabled_mode 0b00 -@let gr_text_mode 0b01 -@let gr_sprite_mode 0b10 - -@address 0x0 - ldi vt_stack_addr RA - ldr RA SP - mov SP FP - jpi program_segment - -@address vector_table - keyboard_isr ; 0x10 - hlt_isr ; 0x11 - hlt_isr ; 0x12 - hlt_isr ; 0x13 - stack_segment ; 0x14 - terminal_addr ; 0x15 - keyboard_addr ; 0x16 - gr_mode_addr ; 0x17 - sprite_mem ; 0x18 - text_mem ; 0x19 - -@label hlt_isr - ldi 0x55 RE - hlt - -@label keyboard_isr - spu RA - spu RB - ldi vt_kb_pp_addr RA - ldr RA RA - ldr RA RA - ldi vt_term_pp_addr RB - ldr RB RB - str RA RB - spo RB - spo RA - rti - -@label program_segment - ldi vt_gr_mode_addr RA - ldr RA RA - ldi gr_disabled_mode RB - str RB RA - - jpi main - -;; END BOOTSTRAP - -@label text_mode - 1 -@label graphics_mode_addr_p - 23 -@label text_mem_addr_p - 25 -@label int_0 - 65 -@label int_6 - 26 - -; -@label nth_letter -; stack frame with offsets -; n 0 -; -; -; BinOp lhs -; -; Builtin call ord [] -; - ldi int_0 RC - ldr RC RC ; int_0 = 65 - spu RC -; BinOp rhs -; (n) - ldi 0 RC - add FP RC RC - ldr RC RC - spu RC - spo RD - spo RC - add RC RD RC - spu RC -; return value is on top of stack -; return from function - subi FP 1 FP - ldr FP RB - jpr RB - -@label main -; stack frame with offsets -; graphics_mode_addr 0 -; text_mem_addr 1 -; i 2 - addi SP 3 SP -; -; assigning graphics_mode_addr at FP + 0 -; evaluating value to be assigned -; -; Builtin call load [] -; (GRAPHICS_MODE_ADDR_P) - ldi graphics_mode_addr_p RC - ldr RC RC - spu RC -; (load) dereferencing top of stack - spo RC - ldr RC RC - spu RC -; assigning stack address (FP + 0) := top of stack - spo RA - ldi 0 RB - add RB FP RB - str RA RB -; -; assigning text_mem_addr at FP + 1 -; evaluating value to be assigned -; -; Builtin call load [] -; (TEXT_MEM_ADDR_P) - ldi text_mem_addr_p RC - ldr RC RC - spu RC -; (load) dereferencing top of stack - spo RC - ldr RC RC - spu RC -; assigning stack address (FP + 1) := top of stack - spo RA - ldi 1 RB - add RB FP RB - str RA RB -; -; Builtin call store [, ] -; (graphics_mode_addr) - ldi 0 RA - add FP RA RA - ldr RA RA - spu RA -; (TEXT_MODE) - ldi text_mode RA - ldr RA RA - spu RA - spo RB - spo RA - str RB RA - ldi 0 RA - spu RA -; popping free-standing Expr result from stack - spo RA -; -; assigning i at FP + 2 -; evaluating value to be assigned -; - ldi 0 RC - spu RC -; assigning stack address (FP + 2) := top of stack - spo RA - ldi 2 RB - add RB FP RB - str RA RB -; -@label while_test_1 -; -; (i) - ldi 2 RB - add FP RB RB - ldr RB RB - spu RB -; - ldi int_6 RB - ldr RB RB ; int_6 = 26 - spu RB -; Comparing - spo RC - spo RB - sub RB RC RB - bri carry Compare_true_4 - ldi 0 RB - spu RB - jpi Compare_end_5 -@label compare_true_4 - ldi 1 RB - spu RB -@label compare_end_5 - spo RA - addi RA 0 RA - bri zero While_else_2 -; -; Builtin call store [, ] -; -; BinOp lhs -; (text_mem_addr) - ldi 1 RA - add FP RA RA - ldr RA RA - spu RA -; BinOp rhs -; (i) - ldi 2 RA - add FP RA RA - ldr RA RA - spu RA - spo RB - spo RA - add RA RB RA - spu RA -; -; Call function nth_letter - spu FP - ldi 0 RA - spu RA -; (i) - ldi 2 RA - add FP RA RA - ldr RA RA - spu RA - subi SP 2 FP -; set up return address and jump to subroutine - lpc RA - addi RA 4 RA - str RA FP - addi FP 1 FP - jpi nth_letter - spo RA - mov FP SP - spo FP - spu RA - spo RB - spo RA - str RB RA - ldi 0 RA - spu RA -; popping free-standing Expr result from stack - spo RA -; -; assigning i at FP + 2 -; evaluating value to be assigned -; -; BinOp lhs -; (i) - ldi 2 RC - add FP RC RC - ldr RC RC - spu RC -; BinOp rhs -; - ldi 1 RC - spu RC - spo RD - spo RC - add RC RD RC - spu RC -; assigning stack address (FP + 2) := top of stack - spo RA - ldi 2 RB - add RB FP RB - str RA RB - jpi While_test_1 -@label while_else_2 -@label while_end_3 -; -@label while_test_7 -; - ldi 1 RB - spu RB - spo RA - addi RA 0 RA - bri zero While_else_8 -; - jpi While_test_7 -@label while_else_8 -@label while_end_9 - mov FP SP - hlt diff --git a/asm/test_py_src.py b/asm/test_py_src.py deleted file mode 100644 index 619d22e..0000000 --- a/asm/test_py_src.py +++ /dev/null @@ -1,36 +0,0 @@ -# TODO: actual imports, not just `import atk16` -from atk16 import * - -GRAPHICS_NO_MODE: ConstWord16 = 0 -GRAPHICS_TEXT_MODE: ConstWord16 = 1 -GRAPHICS_SPRITE_MODE: ConstWord16 = 2 - -GRAPHICS_MODE_PP: ConstWord16 = 0x17 -TEXT_MEM_PP: ConstWord16 = 0x19 - -TEXT_MEM_PP: ConstWord16 = 0x19 - -# asm( -# "@label keyboard_isr" -# " spu RA" - -# " spo RA" -# ) - -# set_isr(0, "keyboard_isr") - -graphics_mode_p = load(GRAPHICS_MODE_PP) -text_mem_p = load(TEXT_MEM_PP) - -store(graphics_mode_p, GRAPHICS_TEXT_MODE) - -def nth_letter(n: int) -> int: - return ord('A') + n - -i = 0 -while i < 26: - store(text_mem_p + i, nth_letter(i)) - i += 1 - -while True: - pass diff --git a/asm/text_mode.atk16 b/asm/text_mode.atk16 deleted file mode 100644 index f20eac9..0000000 --- a/asm/text_mode.atk16 +++ /dev/null @@ -1,58 +0,0 @@ -@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 - -@label main - cursor_to_line RC 1 - put_string RC RB " HELLO #vaincoodijutut" - new_line RC - put_string RC RB " »»»» BY @kal_jan »»»»" - new_line RC - new_line RC - put_string RC RB " > " - - set_graphics_mode gr_text_mode - -@label loop - jpi loop - -@label 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 - 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 - - mov RA RD ; RD := character code - subi RD 5 RD ; if code == 10 (enter key), then run newline handler - subi RD 5 RD - bri zero keyboard_isr_newline - - mov RA RD ; if code == 8 (backspace key), then run backspace handler - subi RD 5 RD - subi RD 3 RD - - bri zero keyboard_isr_backspace - str RA RC ; else code is not special; write it to text buffer - addi RC 1 RC - jpi keyboard_isr_end - -@label keyboard_isr_newline - new_line RC - put_string RC RB " > " - jpi keyboard_isr_end - -@label keyboard_isr_backspace - subi RC 1 RC - put_char RC RB " " - subi RC 1 RC - -@label keyboard_isr_end - stack_restore RA RB RD - rti -- cgit v1.3