diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2024-04-26 15:40:14 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2024-04-26 15:40:14 +0300 |
| commit | 7ca56c1a730fcecd0fe3af5e6b652fa09514a18b (patch) | |
| tree | e2ef6a4d28fa26adf11e00d138ef21b8316497f6 /resources/asm/ext_string_io.py | |
| parent | 2b18b320e97260f1d27143a37fe14953cf62e56d (diff) | |
Refactor project structure, add README and LICENSE
Diffstat (limited to 'resources/asm/ext_string_io.py')
| -rw-r--r-- | resources/asm/ext_string_io.py | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/resources/asm/ext_string_io.py b/resources/asm/ext_string_io.py deleted file mode 100644 index e00ac78..0000000 --- a/resources/asm/ext_string_io.py +++ /dev/null @@ -1,55 +0,0 @@ -from atk16_asm.asm_ops 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, -} |
