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 --- Makefile | 22 +- 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 - atk16-asm/asm_eval.py | 47 + atk16-asm/asm_ops.py | 154 + atk16-asm/asm_pass0.py | 50 + atk16-asm/asm_pass1.py | 48 + atk16-asm/asm_pass2.py | 40 + atk16-asm/asm_pass3.py | 78 + atk16-asm/asm_pass4.py | 61 + atk16-asm/assembler.py | 82 + atk16-asm/optimizer.py | 189 ++ atk16-asm/tokenizer.py | 47 + atk16-ast-walking-compiler/compiler.py | 716 +++++ atk16-bytecode-compiler/bytecode_compiler.py | 220 ++ atk16-utils/charmem.py | 63 + atk16-utils/convert_ttf.py | 52 + atk16-utils/dig_install.py | 60 + atk16-utils/ucode.py | 112 + charset.txt | Bin 23058 -> 0 bytes digital-diagrams/atk16.dig | 2748 ++++++++++++++++ digital-diagrams/atk16_alu.dig | 1695 ++++++++++ digital-diagrams/atk16_alu_carryfix.dig | 270 ++ digital-diagrams/atk16_alu_fo.dig | 494 +++ digital-diagrams/atk16_alu_fz.dig | 192 ++ digital-diagrams/atk16_alu_inputs.dig | 215 ++ digital-diagrams/atk16_decoder.dig | 364 +++ digital-diagrams/atk16_graphics_mode.dig | 311 ++ digital-diagrams/atk16_irc.dig | 341 ++ digital-diagrams/atk16_jump_unit.dig | 193 ++ digital-diagrams/atk16_mem.dig | 949 ++++++ digital-diagrams/atk16_mem_mux.dig | 276 ++ digital-diagrams/atk16_peripherals.dig | 852 +++++ digital-diagrams/atk16_ppu.dig | 827 +++++ digital-diagrams/atk16_ppu_palette.dig | 225 ++ digital-diagrams/atk16_ppu_sprite_eval.dig | 4325 ++++++++++++++++++++++++++ digital-diagrams/atk16_regbank.dig | 1499 +++++++++ digital-diagrams/atk16_tpu.dig | 1165 +++++++ digital-diagrams/atk16_ucode_addr.dig | 741 +++++ digital-diagrams/atk16_vga_sync.dig | 999 ++++++ digital/atk16.dig | 2748 ---------------- digital/atk16_alu.dig | 1695 ---------- digital/atk16_alu_carryfix.dig | 270 -- digital/atk16_alu_fo.dig | 494 --- digital/atk16_alu_fz.dig | 192 -- digital/atk16_alu_inputs.dig | 215 -- digital/atk16_decoder.dig | 364 --- digital/atk16_graphics_mode.dig | 311 -- digital/atk16_irc.dig | 341 -- digital/atk16_jump_unit.dig | 193 -- digital/atk16_mem.dig | 949 ------ digital/atk16_mem_mux.dig | 276 -- digital/atk16_peripherals.dig | 852 ----- digital/atk16_ppu.dig | 827 ----- digital/atk16_ppu_palette.dig | 225 -- digital/atk16_ppu_sprite_eval.dig | 4325 -------------------------- digital/atk16_regbank.dig | 1499 --------- digital/atk16_tpu.dig | 1165 ------- digital/atk16_ucode_addr.dig | 741 ----- digital/atk16_vga_sync.dig | 999 ------ ibm_cga_8x8.ttf | Bin 35952 -> 0 bytes resources/asm/aoc23_1a.atk16 | 554 ++++ resources/asm/aoc23_1a.py | 48 + resources/asm/ast_compiler_bootstrap.atk16 | 74 + resources/asm/bootstrap.atk16 | 71 + resources/asm/ext_std.py | 157 + resources/asm/ext_string_io.py | 56 + resources/asm/fibo.atk16 | 57 + resources/asm/idle_loop.atk16 | 10 + resources/asm/sum.atk16 | 32 + resources/asm/test_py_src.atk16 | 301 ++ resources/asm/text_mode.atk16 | 58 + resources/charset.txt | Bin 0 -> 23058 bytes resources/ibm_cga_8x8.ttf | Bin 0 -> 35952 bytes resources/py/atk16.py | 39 + resources/py/test_py_src.py | 36 + src/asm_eval.py | 47 - src/asm_ops.py | 154 - src/asm_pass0.py | 50 - src/asm_pass1.py | 48 - src/asm_pass2.py | 40 - src/asm_pass3.py | 78 - src/asm_pass4.py | 61 - src/assembler.py | 82 - src/ast_compiler.py | 716 ----- src/bytecode_compiler.py | 220 -- src/charmem.py | 63 - src/convert_ttf.py | 52 - src/dig_install.py | 60 - src/optimizer.py | 189 -- src/tokenizer.py | 47 - src/ucode.py | 112 - 103 files changed, 22206 insertions(+), 22202 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 create mode 100644 atk16-asm/asm_eval.py create mode 100644 atk16-asm/asm_ops.py create mode 100644 atk16-asm/asm_pass0.py create mode 100644 atk16-asm/asm_pass1.py create mode 100644 atk16-asm/asm_pass2.py create mode 100644 atk16-asm/asm_pass3.py create mode 100644 atk16-asm/asm_pass4.py create mode 100755 atk16-asm/assembler.py create mode 100644 atk16-asm/optimizer.py create mode 100644 atk16-asm/tokenizer.py create mode 100644 atk16-ast-walking-compiler/compiler.py create mode 100644 atk16-bytecode-compiler/bytecode_compiler.py create mode 100644 atk16-utils/charmem.py create mode 100644 atk16-utils/convert_ttf.py create mode 100644 atk16-utils/dig_install.py create mode 100755 atk16-utils/ucode.py delete mode 100644 charset.txt create mode 100644 digital-diagrams/atk16.dig create mode 100644 digital-diagrams/atk16_alu.dig create mode 100644 digital-diagrams/atk16_alu_carryfix.dig create mode 100644 digital-diagrams/atk16_alu_fo.dig create mode 100644 digital-diagrams/atk16_alu_fz.dig create mode 100644 digital-diagrams/atk16_alu_inputs.dig create mode 100644 digital-diagrams/atk16_decoder.dig create mode 100644 digital-diagrams/atk16_graphics_mode.dig create mode 100644 digital-diagrams/atk16_irc.dig create mode 100644 digital-diagrams/atk16_jump_unit.dig create mode 100644 digital-diagrams/atk16_mem.dig create mode 100644 digital-diagrams/atk16_mem_mux.dig create mode 100644 digital-diagrams/atk16_peripherals.dig create mode 100644 digital-diagrams/atk16_ppu.dig create mode 100644 digital-diagrams/atk16_ppu_palette.dig create mode 100644 digital-diagrams/atk16_ppu_sprite_eval.dig create mode 100644 digital-diagrams/atk16_regbank.dig create mode 100644 digital-diagrams/atk16_tpu.dig create mode 100644 digital-diagrams/atk16_ucode_addr.dig create mode 100644 digital-diagrams/atk16_vga_sync.dig delete mode 100644 digital/atk16.dig delete mode 100644 digital/atk16_alu.dig delete mode 100644 digital/atk16_alu_carryfix.dig delete mode 100644 digital/atk16_alu_fo.dig delete mode 100644 digital/atk16_alu_fz.dig delete mode 100644 digital/atk16_alu_inputs.dig delete mode 100644 digital/atk16_decoder.dig delete mode 100644 digital/atk16_graphics_mode.dig delete mode 100644 digital/atk16_irc.dig delete mode 100644 digital/atk16_jump_unit.dig delete mode 100644 digital/atk16_mem.dig delete mode 100644 digital/atk16_mem_mux.dig delete mode 100644 digital/atk16_peripherals.dig delete mode 100644 digital/atk16_ppu.dig delete mode 100644 digital/atk16_ppu_palette.dig delete mode 100644 digital/atk16_ppu_sprite_eval.dig delete mode 100644 digital/atk16_regbank.dig delete mode 100644 digital/atk16_tpu.dig delete mode 100644 digital/atk16_ucode_addr.dig delete mode 100644 digital/atk16_vga_sync.dig delete mode 100644 ibm_cga_8x8.ttf create mode 100644 resources/asm/aoc23_1a.atk16 create mode 100644 resources/asm/aoc23_1a.py create mode 100644 resources/asm/ast_compiler_bootstrap.atk16 create mode 100644 resources/asm/bootstrap.atk16 create mode 100644 resources/asm/ext_std.py create mode 100644 resources/asm/ext_string_io.py create mode 100644 resources/asm/fibo.atk16 create mode 100644 resources/asm/idle_loop.atk16 create mode 100644 resources/asm/sum.atk16 create mode 100644 resources/asm/test_py_src.atk16 create mode 100644 resources/asm/text_mode.atk16 create mode 100644 resources/charset.txt create mode 100644 resources/ibm_cga_8x8.ttf create mode 100644 resources/py/atk16.py create mode 100644 resources/py/test_py_src.py delete mode 100644 src/asm_eval.py delete mode 100644 src/asm_ops.py delete mode 100644 src/asm_pass0.py delete mode 100644 src/asm_pass1.py delete mode 100644 src/asm_pass2.py delete mode 100644 src/asm_pass3.py delete mode 100644 src/asm_pass4.py delete mode 100755 src/assembler.py delete mode 100644 src/ast_compiler.py delete mode 100644 src/bytecode_compiler.py delete mode 100644 src/charmem.py delete mode 100644 src/convert_ttf.py delete mode 100644 src/dig_install.py delete mode 100644 src/optimizer.py delete mode 100644 src/tokenizer.py delete mode 100755 src/ucode.py diff --git a/Makefile b/Makefile index df72879..cc2267b 100644 --- a/Makefile +++ b/Makefile @@ -8,31 +8,35 @@ start-digital: # make assemble asm=src/program.atk16 out=out/program.bin assemble: - $(py) src/assembler.py $(asm) $(out) + $(py) atk16-asm/assembler.py $(asm) $(out) # make gen-ucode out=out/ucode.bin gen-ucode: - $(py) src/ucode.py $(out) + $(py) atk16-utils/ucode.py $(out) # make gen-charmem out=out/charmem.bin gen-charmem: - $(py) src/charmem.py $(out) + $(py) atk16-utils/charmem.py $(out) # make convert-ttf in=font.ttf out=charset.txt convert-ttf: - $(py) src/convert_ttf.py $(in) $(out) + $(py) atk16-utils/convert_ttf.py $(in) $(out) # make dig-install bin=out/program.bin dig=digital/atk16_mem.dig label=MEM_ROM dig-install: - $(py) src/dig_install.py $(bin) $(dig) $(label) + $(py) atk16-utils/dig_install.py $(bin) $(dig) $(label) -# make compile-py-to-atk16 in=asm/test_py_src.py out=asm/test_py_src.atk16 -compile-py-to-atk16: - $(py) src/ast_compiler.py $(in) $(out) +# make ast-compile in=asm/test_py_src.py out=asm/test_py_src.atk16 +ast-compile: + $(py) atk16-ast-walking-compiler/compiler.py $(in) $(out) + +# make bytecode-compile in=asm/test_py_src.py out=asm/test_py_src.atk16 +bytecode-compile: + $(py) atk16-bytecode-compiler/compiler.py $(in) $(out) # make test test: - $(py) src/test_alu.py digital/atk16_alu.dig + $(py) atk16-asm/test_alu.py digital-diagrams/atk16_alu.dig run-single-test: java -cp $(digital_path) CLI test -verbose -circ $(circ) -tests $(tests) 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 diff --git a/atk16-asm/asm_eval.py b/atk16-asm/asm_eval.py new file mode 100644 index 0000000..c05fc03 --- /dev/null +++ b/atk16-asm/asm_eval.py @@ -0,0 +1,47 @@ +constants: dict[str, str] = { + # Registers + "ra": "0", + "rb": "1", + "rc": "2", + "rd": "3", + "re": "4", + "rf": "5", + "rg": "6", + "rh": "7", + # ALU instructions + "al_plus": "0", + "al_minus": "1", + "al_and": "2", + "al_or": "3", + "al_xor": "4", + "al_slr": "5", + "al_sar": "6", + "al_sll": "7", + # ALU flags + "carry": "0", + "overflow": "1", + "zero": "2", + "sign": "3", +} + +Symbols = dict[str, int] + +def check_size(bits: int, val: int) -> None: + if val >= 2 ** bits: + raise Exception(f"Value does not fit in {bits} bits: 0x{val:>04x}") + +def eval_symbol(symbols: Symbols, c: str) -> str: + if c in symbols: + return str(symbols[c]) + + if c in constants: + return constants[c] + + return c + +def eval_expr(symbols: Symbols, expr: str, bits: int = 16) -> int: + expr = expr.lower() + expr = eval_symbol(symbols, expr) + ret = eval(expr, symbols.copy()) # eval as Python expr + check_size(bits, ret) + return ret diff --git a/atk16-asm/asm_ops.py b/atk16-asm/asm_ops.py new file mode 100644 index 0000000..885c275 --- /dev/null +++ b/atk16-asm/asm_ops.py @@ -0,0 +1,154 @@ +from typing import Callable +from asm_eval import * +from dataclasses import dataclass + +@dataclass +class Meta: + address: int + +def make_alr(meta: Meta, symbols: Symbols, alu_op: str, left: str, right: str, target: str) -> int: + """ALR 0000 TTTL LLRR RSSS""" + target_e = eval_expr(symbols, target, bits=3) + left_e = eval_expr(symbols, left, bits=3) + right_e = eval_expr(symbols, right, bits=3) + alu_op_e = eval_expr(symbols, alu_op, bits=3) + word = (0b0000 << 12) + \ + (target_e << 9) + \ + (left_e << 6) + \ + (right_e << 3) + \ + alu_op_e + return word + +def make_ali(meta: Meta, symbols: Symbols, alu_op: str, left: str, imm: str, target: str) -> int: + """ALI 0001 TTTL LLII ISSS""" + target_e = eval_expr(symbols, target, bits=3) + left_e = eval_expr(symbols, left, bits=3) + imm_e = eval_expr(symbols, imm, bits=3) + alu_op_e = eval_expr(symbols, alu_op, bits=3) + word = (0b0001 << 12) + \ + (target_e << 9) + \ + (left_e << 6) + \ + (imm_e << 3) + \ + alu_op_e + return word + +def make_ldr(meta: Meta, symbols: Symbols, addr_reg: str, to_reg: str) -> int: + """LDR 0010 TTTR RRXX XXXX""" + to_reg_e = eval_expr(symbols, to_reg, bits=3) + addr_reg_e = eval_expr(symbols, addr_reg, bits=3) + word = (0b0010 << 12) + \ + (to_reg_e << 9) + \ + (addr_reg_e << 6) + return word + +def make_str(meta: Meta, symbols: Symbols, from_reg: str, addr_reg: str) -> int: + """STR 0011 XXXL LLRR RXXX""" + from_reg_e = eval_expr(symbols, from_reg, bits=3) + addr_reg_e = eval_expr(symbols, addr_reg, bits=3) + word = (0b0011 << 12) + \ + (addr_reg_e << 6) + \ + (from_reg_e << 3) + return word + +def make_ldi(meta: Meta, symbols: Symbols, imm: str, to_reg: str) -> int: + """LDI 0100 TTTI IIII IIII""" + to_reg_e = eval_expr(symbols, to_reg, bits=3) + imm_e = eval_expr(symbols, imm, bits=9) + word = (0b0100 << 12) + \ + (to_reg_e << 9) + \ + imm_e + return word + +def make_jpr(meta: Meta, symbols: Symbols, addr_reg: str) -> int: + """JPR 0101 XXXR RRXX XXXX""" + addr_reg_e = eval_expr(symbols, addr_reg, bits=3) + word = (0b0101 << 12) + \ + (addr_reg_e << 6) + return word + +def make_jpi(meta: Meta, symbols: Symbols, imm: str) -> int: + """JPI 0110 XXXI IIII IIII""" + imm_e = eval_expr(symbols, imm, bits=9) + imm_e = imm_e - meta.address - 1 + imm_e = imm_e & (0b111111111) + #print("symbols:", symbols) + #print(meta, imm, f"0x{imm_e:>0x}") + word = (0b0110 << 12) + \ + imm_e + return word + +def make_brr(meta: Meta, symbols: Symbols, flag_s: str, addr_reg: str) -> int: + """brr 0111 XFFR RRXX XXXX""" + flag_s_e = eval_expr(symbols, flag_s, bits=2) + addr_reg_e = eval_expr(symbols, addr_reg, bits=3) + word = (0b0111 << 12) + \ + (flag_s_e << 9) + \ + (addr_reg_e << 6) + return word + +def make_bri(meta: Meta, symbols: Symbols, flag_s: str, imm: str) -> int: + """BRI 1000 XFFI IIII IIII""" + flag_s_e = eval_expr(symbols, flag_s, bits=2) + imm_e = eval_expr(symbols, imm, bits=9) + imm_e = imm_e - meta.address - 1 + imm_e = imm_e & (0b111111111) + word = (0b1000 << 12) + \ + (flag_s_e << 9) + \ + imm_e + return word + +def make_lpc(meta: Meta, symbols: Symbols, target: str) -> int: + """LPC 1001 TTTX XXXX XXXX""" + target_e = eval_expr(symbols, target, bits=3) + word = (0b1001 << 12) + \ + (target_e << 9) + return word + +def make_rti(meta: Meta, symbols: Symbols) -> int: + """RTI 1110 XXXX XXXX XXXX""" + word = (0b1110 << 12) + return word + +def make_hlt(meta: Meta, symbols: Symbols) -> int: + """HLT 1111 XXXX XXXX XXXX""" + word = (0b1111 << 12) + return word + +OpWordDict = dict[str, Callable[..., int]] +operations: OpWordDict = { + "alr": make_alr, + "ali": make_ali, + "ldr": make_ldr, + "str": make_str, + "ldi": make_ldi, + "jpr": make_jpr, + "jpi": make_jpi, + "brr": make_brr, + "bri": make_bri, + "lpc": make_lpc, + "rti": make_rti, + "hlt": make_hlt, +} + +ExpandResult = list[list[str]] +ExpandFn = Callable[..., ExpandResult] +OpExpansionDict = dict[str, ExpandFn] + +def expand_id(*parts: str) -> ExpandResult: + return [list(parts)] + +default_expansions: OpExpansionDict = { + "alr": lambda *args: expand_id("alr", *args), + "ali": lambda *args: expand_id("ali", *args), + "ldr": lambda *args: expand_id("ldr", *args), + "str": lambda *args: expand_id("str", *args), + "ldi": lambda *args: expand_id("ldi", *args), + "jpr": lambda *args: expand_id("jpr", *args), + "jpi": lambda *args: expand_id("jpi", *args), + "brr": lambda *args: expand_id("brr", *args), + "bri": lambda *args: expand_id("bri", *args), + "lpc": lambda *args: expand_id("lpc", *args), + "rti": lambda *args: expand_id("rti", *args), + "hlt": lambda *args: expand_id("hlt", *args), +} + diff --git a/atk16-asm/asm_pass0.py b/atk16-asm/asm_pass0.py new file mode 100644 index 0000000..f5b6b0b --- /dev/null +++ b/atk16-asm/asm_pass0.py @@ -0,0 +1,50 @@ +from dataclasses import dataclass +import os.path +from asm_ops import * +from asm_eval import * +from tokenizer import * + +@dataclass +class Result0Line: + line_num: int + src_file: str + line: str + +@dataclass +class Result0: + lines: list[Result0Line] + +def pass_0(lines: list[str], file_name: str) -> Result0: + result_lines: list[Result0Line] = [] + + for (line_num, line) in enumerate(lines): + line = line.split(";")[0].strip() + if line == "": continue + + keyword, *args = tokenize(line) + + match keyword: + case "@include": + asm_file_name = args[0] + path = os.path.join(os.path.dirname(file_name), asm_file_name + ".atk16") + with open(path, "r") as f: + incl_lines = f.readlines() + + incl_result0 = pass_0(incl_lines, asm_file_name) + for incl_line in incl_result0.lines: + result_lines.append(Result0Line( + src_file=incl_line.src_file, + line_num=incl_line.line_num, + line=incl_line.line + )) + + case _: + result_lines.append(Result0Line( + src_file=file_name, + line_num=line_num, + line=line + )) + + return Result0( + lines=result_lines + ) diff --git a/atk16-asm/asm_pass1.py b/atk16-asm/asm_pass1.py new file mode 100644 index 0000000..0b06738 --- /dev/null +++ b/atk16-asm/asm_pass1.py @@ -0,0 +1,48 @@ +import importlib +import sys +import os.path +from dataclasses import dataclass +from asm_ops import * +from asm_eval import * +from asm_pass0 import * +from tokenizer import tokenize + +@dataclass +class Result1Line: + line_num: int + src_file: str + parts: list[str] + +@dataclass +class Result1: + lines: list[Result1Line] + operations: OpExpansionDict + +def pass_1(result0: Result0) -> Result1: + result_lines: list[Result1Line] = [] + operations: OpExpansionDict = default_expansions.copy() + + for line in result0.lines: + keyword, *args = tokenize(line.line) + match keyword: + case "@use": + module_name, ops = args[0].split(":") + ops_split = ops.split(",") + sys.path.append(os.path.dirname(line.src_file)) + module = importlib.import_module(module_name) + mod_expansions: OpExpansionDict = module.expansions + for op in mod_expansions: + expansion = mod_expansions[op] + if ops == "*" or op in ops_split: + operations[op] = expansion + case _: + result_lines.append(Result1Line( + src_file=line.src_file, + line_num=line.line_num, + parts=[keyword, *args] + )) + + return Result1( + operations=operations, + lines=result_lines + ) diff --git a/atk16-asm/asm_pass2.py b/atk16-asm/asm_pass2.py new file mode 100644 index 0000000..e2ad4ec --- /dev/null +++ b/atk16-asm/asm_pass2.py @@ -0,0 +1,40 @@ +from dataclasses import dataclass +from asm_ops import * +from asm_eval import * +from asm_pass1 import * + +@dataclass +class Result2Line: + line_num: int + src_file: str + parts: list[str] + original_parts: list[str] + +@dataclass +class Result2: + lines: list[Result2Line] + operations: OpExpansionDict + +def pass_2(result1: Result1) -> Result2: + result_lines: list[Result2Line] = [] + + for line in result1.lines: + keyword, *args = line.parts + if keyword in result1.operations: + fn = result1.operations[keyword] + output: list[list[str]] = fn(*args) + else: + output = [line.parts] + + for (idx, parts) in enumerate(output): + result_lines.append(Result2Line( + line_num=line.line_num, + src_file=line.src_file, + parts=parts, + original_parts=line.parts if idx == 0 else ["..."] + )) + + return Result2( + operations=result1.operations, + lines=result_lines + ) diff --git a/atk16-asm/asm_pass3.py b/atk16-asm/asm_pass3.py new file mode 100644 index 0000000..9c8cb34 --- /dev/null +++ b/atk16-asm/asm_pass3.py @@ -0,0 +1,78 @@ +from dataclasses import dataclass +from asm_ops import * +from asm_eval import * +from asm_pass2 import * + +@dataclass +class Result3Line: + line_num: int + src_file: str + address: int + parts: list[str] + original_parts: list[str] + +@dataclass +class Result3: + lines: list[Result3Line] + operations: OpExpansionDict + symbols: dict[str, int] + +def pass_3(result2: Result2) -> Result3: + result_lines: list[Result3Line] = [] + symbols: dict[str, int] = {} + address = 0 + + for line in result2.lines: + keyword, *args = line.parts + match keyword: + case "@address": + address = eval_expr(symbols, args[0]) + continue + case "@label": + label = args[0] + if label in symbols: + raise Exception(f"When defining label {label} as {address:>04x}, symbol {label} already defined as {symbols[label]:>04x}") + symbols[args[0]] = address + continue + case "@let": + symbols[args[0]] = eval_expr(symbols, args[1]) + continue + case _: + result_lines.append(Result3Line( + line_num=line.line_num, + src_file=line.src_file, + parts=line.parts, + address=address, + original_parts=line.original_parts, + )) + address += 1 + + result_lines.sort(key=lambda l: l.address) + for result_line in result_lines: + rows_with_same_addr = list(filter(lambda l: l.address == result_line.address, result_lines)) + n = len(rows_with_same_addr) + if n > 1: + formatted = format_overlapping_rows(rows_with_same_addr) + raise Exception(f"Overlapping segments: address 0x{result_line.address:>04x} has conflicting definitions:\n{formatted}") + return Result3( + operations=result2.operations, + lines=result_lines, + symbols=symbols, + ) + +def format_overlapping_rows(rows: list[Result3Line]) -> str: + longest_val = 0 + for row in rows: + joined = " ".join(row.parts) + if len(joined) > longest_val: + longest_val = len(joined) + + first_col_width = longest_val + 4 + + results: list[str] = [] + for row in rows: + joined = " ".join(row.parts) + result = joined + (first_col_width - len(joined)) * " " + f" ({row.src_file}:{row.line_num})" + results.append(result) + + return "\n".join(results) diff --git a/atk16-asm/asm_pass4.py b/atk16-asm/asm_pass4.py new file mode 100644 index 0000000..2fff870 --- /dev/null +++ b/atk16-asm/asm_pass4.py @@ -0,0 +1,61 @@ +from dataclasses import dataclass +from asm_ops import * +from asm_eval import * +from asm_pass3 import * + +@dataclass +class Result4Line: + line_num: int + src_file: str + address: int + word: int + text: str + original_text: str + +@dataclass +class Result4: + lines: list[Result4Line] + operations: OpExpansionDict + symbols: dict[str, int] + +def pass_4(result3: Result3) -> Result4: + result_lines: list[Result4Line] = [] + + for line in result3.lines: + keyword, *args = line.parts + meta = Meta( + address=line.address, + ) + + text = " ".join([keyword, *args]) + original_text = " ".join(line.original_parts) + + if keyword in operations: + fn = operations[keyword] + word = fn(meta, result3.symbols, *args) + result_lines.append(Result4Line( + line_num=line.line_num, + src_file=line.src_file, + address=line.address, + word=word, + text=text, + original_text=original_text, + )) + else: + try: + result_lines.append(Result4Line( + line_num=line.line_num, + src_file=line.src_file, + address=line.address, + word=eval_expr(result3.symbols, keyword), + text=text, + original_text=original_text, + )) + except: + raise Exception(f"Invalid assembly at {line.src_file}:{line.line_num + 1}\n\n{line}") + + return Result4( + operations=result3.operations, + symbols=result3.symbols, + lines=result_lines, + ) diff --git a/atk16-asm/assembler.py b/atk16-asm/assembler.py new file mode 100755 index 0000000..c678ba0 --- /dev/null +++ b/atk16-asm/assembler.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +# Assemble ATK16 assembly to bytecode + +import sys +from asm_ops import * +from asm_eval import * +from asm_pass0 import pass_0 +from asm_pass1 import pass_1 +from asm_pass2 import pass_2 +from asm_pass3 import pass_3 +from asm_pass4 import pass_4 + +if len(sys.argv) != 3: + print("usage: assembler.py # read from file") + print(" assembler.py - # read from stdin") + sys.exit(1) + +infile_path = sys.argv[1] +outfile_path = sys.argv[2] + +src = "" +if (infile_path == "-"): + for line in sys.stdin: + src += line +else: + with open(infile_path, "r") as f: + src = f.read() + +src_lines = src.splitlines() + +### Utils + +def parse(line: str) -> list[str]: + depth = 0 + result: list[str] = [] + acc: str = "" + for c in line: + if c.isspace() and depth == 0: + result.append(acc) + acc = "" + elif c == "(": + depth += 1 + acc += "(" + elif c == ")": + depth -= 1 + acc += ")" + else: + acc += c + + result.append(acc) + return list(filter(lambda x: len(x) > 0, result)) + +result0 = pass_0(src_lines, infile_path) +result1 = pass_1(result0) +result2 = pass_2(result1) +result3 = pass_3(result2) +result4 = pass_4(result3) + +nop = bytearray([0b1000_0000, 0]) +result = bytearray() +# initially one nop +result.extend(nop) + +for line in result4.lines: + for (symbol, symbol_value) in result4.symbols.items(): + if line.address == symbol_value: + print(f"{symbol}:") + + if len(result) < 2 * line.address + 1: + result.extend((2 * line.address + 1 - len(result)) * nop) + + out_line = f"{line.address:>08x} 0x{line.word:>04x} {line.text}" + out_spaces_n = (42 - len(out_line)) + out_spaces = out_spaces_n * " " if out_spaces_n > 0 else 4 * " " + print(f"{out_line}{out_spaces}{line.original_text}") + result[2 * line.address + 0] = ((line.word >> 8) & 0xff) + result[2 * line.address + 1] = ((line.word >> 0) & 0xff) + +with open(outfile_path, "wb") as f: + f.write(result) + +print(f"Wrote {len(result)} bytes to {outfile_path}") diff --git a/atk16-asm/optimizer.py b/atk16-asm/optimizer.py new file mode 100644 index 0000000..0ee2837 --- /dev/null +++ b/atk16-asm/optimizer.py @@ -0,0 +1,189 @@ +from tokenizer import tokenize + +def format_asm_row(asm: str) -> str: + if not (asm.startswith("@") or asm.startswith(";")) and not asm.startswith(" ") and len(asm) > 0: + return " " + asm + else: + return asm + +class Optimizer: + def __init__(self): + pass + + def optimize(self, asm_str: str): + asm = asm_str.split("\n") + asm = [row.strip() for row in asm] + asm = [self.strip_comment(row) for row in asm] + asm = [row for row in asm if not len(row) == 0] + asm = [tokenize(row, retain_curlies=True) for row in asm] + asm = self.compact_spu_spo_pattern(asm) + + # TODO: not safe when setting loading SP and FP + # ldr RA SP + # mov RA FP + # gets optimized to + # ldr RA FP + #asm = self.compact_target_mov_pattern(asm) + #asm = self.compact_target_mov_pattern(asm) + + # TODO: not safe at all. E.g. breaks a while True: pass loop + #asm = self.compact_mov_source_pattern(asm) + #asm = self.compact_mov_source_pattern(asm) + + asm = self.compact_spu_load_spo_pattern(asm) + # asm = self.convert_alr_to_ali(asm) + result = "\n".join([format_asm_row(" ".join(row)) for row in asm]) + + return result + + def strip_comment(self, row: str): + ret: str = "" + for c in row: + if c == ";": break + ret += c + + return ret + + def compact_spu_spo_pattern(self, asm: list[list[str]]) -> list[list[str]]: + i = 0 + result: list[list[str]] = [] + while i < len(asm): + current = asm[i] + next = asm[i + 1] if i + 1 < len(asm) else None + i += 1 + if current[0].startswith("@") or next is None: + result.append(current) + continue + + if current[0] == "spu" and next[0] == "spo": + print("=== compact_spu_spo_pattern") + print(current) + print(next) + + arg_current = current[1] + arg_next = next[1] + + print("=== arg_current:", arg_current) + print("=== arg_next:", arg_next) + + if arg_current == arg_next: + print("=== pass") + pass # remove both spu and spo + else: + print("=== mov") + mov = ["mov", arg_current, arg_next] + result.append(mov) + print("=== mov:", mov) + + print("=== last of result:", result[len(result) - 1]) + print() + i += 1 + continue + + result.append(current) + + return result + + def compact_target_mov_pattern(self, asm: list[list[str]]) -> list[list[str]]: + ops_with_target = ["ldi", "ldr", "add", "sub", "addi", "subi", "and", "or", "xor", "sll", "slr", "sar", "slli", "slri", "sari", "inc", "dec", "mov", "ali", "alr", "lpc"] + i = 0 + result: list[list[str]] = [] + while i < len(asm): + current = asm[i] + next = asm[i + 1] if i + 1 < len(asm) else None + i += 1 + if current[0].startswith("@") or next is None: + result.append(current) + continue + + if current[0] in ops_with_target and next[0] == "mov": + + op_op, op_operands, op_target_reg = current[0], current[1:len(current) - 1], current[len(current) - 1] + mov_from_reg, mov_to_reg = next[1], next[2] + + if op_target_reg == mov_from_reg: + ret = [op_op, *op_operands, mov_to_reg] + result.append(ret) + i += 1 + continue + + result.append(current) + + return result + + def compact_mov_source_pattern(self, asm: list[list[str]]) -> list[list[str]]: + ops_with_source = ["str", "ldr", "add", "sub", "addi", "subi", "and", "or", "xor", "sll", "slr", "sar", "slli", "slri", "sari", "mov", "ali", "alr"] + i = 0 + result: list[list[str]] = [] + while i < len(asm): + current = asm[i] + next = asm[i + 1] if i + 1 < len(asm) else None + i += 1 + if current[0].startswith("@") or next is None: + result.append(current) + continue + + if current[0] == "mov" and next[0] in ops_with_source: + mov_from_reg, mov_to_reg = current[1], current[2] + op_op, op_source_reg, op_operands = next[0], next[1], next[2:] + + if op_source_reg == mov_to_reg: + ret = [op_op, op_source_reg, *op_operands] + result.append(ret) + i += 1 + continue + + result.append(current) + + return result + + def compact_spu_load_spo_pattern(self, asm: list[list[str]]) -> list[list[str]]: + # spu RA + # ldi int_7 RA + # ldr RA RB + # spo RA + # OR + # spu RA + # ldi 3 RB + # spo RA + + i = 0 + result: list[list[str]] = [] + while i < len(asm): + instr0 = asm[i] + instr1 = asm[i + 1] if i + 1 < len(asm) else None + instr2 = asm[i + 2] if i + 2 < len(asm) else None + instr3 = asm[i + 3] if i + 3 < len(asm) else None + i += 1 + if instr0[0].startswith("@") or instr1 is None or instr2 is None or instr3 is None: + result.append(instr0) + continue + + if instr0[0] == "spu" and instr1[0] == "ldi" and instr2[0] == "ldr" and instr3[0] == "spo": + spu_op, spu_reg = instr0 + ldi_op, ldi_imm, ldi_target_reg = instr1 + ldr_op, ldr_from_reg, ldr_to_reg = instr2 + spo_op, spo_reg = instr3 + + if spu_reg == spo_reg and ldi_target_reg == ldr_from_reg and ldr_from_reg != ldr_to_reg: + ret0 = f"ldi {ldi_imm} {ldr_to_reg}".split() + ret1 = f"ldr {ldr_to_reg} {ldr_to_reg}".split() + result.append(ret0) + result.append(ret1) + i += 3 + continue + + elif instr0[0] == "spu" and instr1[0] == "ldi" and instr2[0] == "spo": + spu_op, spu_reg = instr0 + ldi_op, ldi_imm, ldi_target_reg = instr1 + spo_op, spo_reg = instr2 + + if spu_reg == spo_reg and ldi_target_reg != spu_reg: + ret0 = f"ldi {ldi_imm} {ldi_target_reg}".split() + result.append(ret0) + i += 2 + continue + + result.append(instr0) + + return result diff --git a/atk16-asm/tokenizer.py b/atk16-asm/tokenizer.py new file mode 100644 index 0000000..cf31b56 --- /dev/null +++ b/atk16-asm/tokenizer.py @@ -0,0 +1,47 @@ +def tokenize(line: str, retain_curlies = False) -> list[str]: + cur: str = "" + result: list[str] = [] + is_py_expr = False + is_string = False + idx = 0 + while idx < len(line): + c = line[idx] + if not is_py_expr and c == "$": + is_py_expr = True + if retain_curlies: + cur += "${" + idx += 1 + elif is_py_expr and c == "$": + raise Exception("Unexpected start of python expr while already parsing a python expression:\n" + line) + elif not is_py_expr and c == "}": + raise Exception("Unexpected end of python expr while not parsing a python expression:\n" + line) + elif is_py_expr and c == "}": + is_py_expr = False + if retain_curlies: + cur += c + result.append(cur) + cur = "" + elif is_py_expr: + cur += c + elif not is_string and c == "\"": + cur += "\"" + is_string = True + elif is_string and c == "\"": + cur += "\"" + is_string = False + result.append(cur) + cur = "" + elif is_string: + cur += c + elif c == " " or c == "\t": + result.append(cur) + cur = "" + else: + cur += c + + idx += 1 + + if len(cur) > 0: + result.append(cur) + + return [r for r in result if r != ""] \ No newline at end of file diff --git a/atk16-ast-walking-compiler/compiler.py b/atk16-ast-walking-compiler/compiler.py new file mode 100644 index 0000000..1634bed --- /dev/null +++ b/atk16-ast-walking-compiler/compiler.py @@ -0,0 +1,716 @@ +#!/usr/bin/env python3 +# Generate .atk16 assembly from a subset of Python + +import sys +import ast + +from dataclasses import dataclass +from typing import Literal, Set, cast, Any, TypeAlias, TypeVar +from collections import OrderedDict + + +if len(sys.argv) != 3: + print("usage: compiler.py ") + sys.exit(1) + +infile_path = sys.argv[1] +outfile_path = sys.argv[2] + +Label = str +StackOffset = int +RegChar = Literal["A", "B", "C", "D", "E", "F", "G", "H"] + +@dataclass +class Reg(): + reg: RegChar + + def __str__(self): + return f"R{self.reg}" + +ALL_REGS: list[RegChar] = ["A", "B", "C", "D", "E", "F", "G", "H"] +FRAME_POINTER_REG_CHAR: RegChar = "G" # points to base of stack frame +FRAME_POINTER_REG = Reg(FRAME_POINTER_REG_CHAR) +STACK_POINTER_REG_CHAR: RegChar = "H" +STACK_POINTER_REG = Reg(STACK_POINTER_REG_CHAR) +SPECIAL_REGS: list[RegChar] = [FRAME_POINTER_REG_CHAR, STACK_POINTER_REG_CHAR] +GENERIC_REGS: OrderedDict[RegChar, None] = OrderedDict() +for char in ALL_REGS: + if char not in SPECIAL_REGS: + GENERIC_REGS[cast(RegChar, char)] = None + +def format_asm_row(asm: str) -> str: + if not (asm.startswith("@") or asm.startswith(";")) and not asm.startswith(" ") and len(asm) > 0: + return " " + asm + else: + return asm + +class Compiler(ast.NodeVisitor): + def __init__(self): + self.const_asm: list[str] = [] + self.program_asm: list[str] = [ + "@label main" + ] + self.function_def_asms: list[str] = [] + self.currently_emitting_asm_list = self.program_asm + + self.local_bindings: dict[str, StackOffset] = {} + self.const_bindings: dict[str, Label] = {} + + self.unique_name_counter = 0 + self.latest_break_target: Label | None = None + + self.reserved_regs: OrderedDict[RegChar, None] = OrderedDict() + + def get_unique_name(self, prefix: str): + ret = f"{prefix}_{self.unique_name_counter}" + self.unique_name_counter += 1 + return ret + + def assign_const(self, name: str, value: int): + prev_currently_emitting_asm_list = self.currently_emitting_asm_list + self.currently_emitting_asm_list = self.const_asm + + self.emit_label(name) + self.emit(f"{value}") + + self.const_bindings[name] = name + + self.currently_emitting_asm_list = prev_currently_emitting_asm_list + + def emit(self, asm: str): + asm = asm.strip() + asm = format_asm_row(asm) + + self.currently_emitting_asm_list.append(asm) + + def emit_label(self, label_name: str): + label_name = label_name.lower() + self.emit(f"@label {label_name}") + + def alloc_reg(self) -> Reg: + for reg in GENERIC_REGS: + if not reg in self.reserved_regs: + self.reserved_regs[reg] = None + return Reg(reg) + + raise Exception("Ran out of registers, TODO use stack") + + def free_reg(self, reg: Reg): + self.reserved_regs.pop(reg.reg) + + class RegContextManager: + def __init__(self, compiler): + self.compiler = compiler + + def __enter__(self) -> Reg: + self.reg = self.compiler.alloc_reg() + return self.reg + + def __exit__(self, exc_type, exc_value, exc_tb): + self.compiler.free_reg(self.reg) + + def allocated_reg(self): + return Compiler.RegContextManager(self) + + def compile(self, bootstrap_asm: str, source: str) -> str: + tree = ast.parse(source) + print(ast.dump(tree, indent=4)) + self.visit(tree) + return "\n".join([ + bootstrap_asm, + "", + "\n".join(self.const_asm), + "", + "\n".join(self.function_def_asms), + "", + "\n".join(self.program_asm), + "" + ]) + + def generic_visit(self, node: ast.AST) -> Any: + raise NotImplementedError(f"type {type(node)}, value: {node}") + + def emit_builtin_call(self, name: str, args: list[ast.expr]): + self.emit(f"; Builtin call {name} {args}") + match name: + case "asm": + match args: + case [ast.Constant(str(value))]: + self.emit(value) + + # return None + with self.allocated_reg() as arg: + self.emit(f"ldi 0 {arg}") + self.emit(f"spu {arg}") + + case other: raise Exception(f"asm: invalid args: {other}") + + case "store": + if len(args) != 2: + raise Exception("Invalid number of arguments to store: " + str(len(args))) + + # Evaluate args before call + for arg in args: + self.visit(arg) + + with self.allocated_reg() as arg1, self.allocated_reg() as arg2: + self.emit(f"spo {arg2}") + self.emit(f"spo {arg1}") + self.emit(f"str {arg2} {arg1}") + + # return None + self.emit(f"ldi 0 {arg1}") + self.emit(f"spu {arg1}") + + case "load": + if len(args) != 1: + raise Exception("Invalid number of arguments to load: " + str(len(args))) + + self.visit(args[0]) + + self.emit("; (load) dereferencing top of stack") + with self.allocated_reg() as arg: + self.emit(f"spo {arg}") + self.emit(f"ldr {arg} {arg}") + self.emit(f"spu {arg}") + + case "ord": + if len(args) != 1: + raise Exception("Invalid number of arguments to ord: " + str(len(args))) + + self.visit(args[0]) + + case other: + raise Exception(f"Unknown builtin: {other}") + + def eval_int_constant_and_spu(self, value: int): + with self.allocated_reg() as reg: + if value >= 0 and value < 8: + self.emit(f"ldi {value} {reg}") + else: + name = self.get_unique_name("int") + self.assign_const(name, value) + self.emit(f"ldi {name} {reg}") + self.emit(f"ldr {reg} {reg} ; {name} = {value}") + + self.emit(f"spu {reg}") + + def emit_add_imm(self, reg1: str, addend: int, target_reg: str): + if addend >= 0 and addend < 8: + self.emit(f"addi {reg1} {addend} {target_reg}") + else: + name = self.get_unique_name("int") + self.assign_const(name, addend) + + with self.allocated_reg() as addend_reg: + self.emit(f"ldi {name} {addend_reg}") + self.emit(f"ldr {addend_reg} {addend_reg}") + self.emit(f"add {reg1} {addend_reg} {target_reg}") + + def visit_Module(self, node: ast.Module): + stmts = node.body + frame_names = self.collect_local_variables(stmts) + + self.emit("; stack frame with offsets") + for offset, name in enumerate(frame_names): + self.local_bindings[name] = offset + self.emit(f"; {name} {offset}") + + self.emit_add_imm("SP", len(frame_names), "SP") + + for stmt in stmts: + if type(stmt) == ast.Expr and type(stmt.value) != ast.Call: + self.emit("; NOP top-level expression") + continue + + self.visit(stmt) + + self.emit(f"mov FP SP") + self.emit("hlt") + + def visit_Expr(self, expr: ast.Expr): + self.visit(expr.value) + + with self.allocated_reg() as reg: + self.emit("; popping free-standing Expr result from stack") + self.emit(f"spo {reg}") + + def visit_UnaryOp(self, node: ast.UnaryOp): + self.emit(f"; {node.op}") + self.visit(node.operand) + match node.op: + case ast.Not(): + with self.allocated_reg() as reg1, self.allocated_reg() as reg2: + self.emit(f"spo {reg1}") + self.emit(f"ldi 1 {reg2}") + self.emit(f"andi {reg1} 1 {reg1}") + self.emit(f"xor {reg1} {reg2} {reg1}") + self.emit(f"spu {reg1}") + + case ast.Invert(): # aka bitwise not + with self.allocated_reg() as reg1: + self.emit(f"spo {reg1}") + self.emit(f"not {reg1}") + self.emit(f"spu {reg1}") + + case ast.UAdd(): # +a + pass # nop + + case ast.USub(): # -a + with self.allocated_reg() as reg1: + self.emit(f"spo {reg1}") + self.emit(f"not {reg1}") + self.emit(f"addi {reg1} 1 {reg1}") + self.emit(f"spu {reg1}") + + case other: + raise NotImplementedError(f"Unhandled UnaryOp: {other}") + + def visit_BoolOp(self, node: ast.BoolOp): + self.emit(f"; {node.op}") + + match node.op: + case ast.And(): + label_short_circuit = self.get_unique_name("And_short_circuit") + + with self.allocated_reg() as reg: + for arg in node.values: + self.emit(f"; And operand {arg}") + self.visit(arg) + + self.emit(f"spo {reg}") + self.emit(f"addi {reg} 0 {reg}") + self.emit(f"bri zero {label_short_circuit}") + + self.emit_label(label_short_circuit) + self.emit(f"spu {reg}") + + case ast.Or(): + label_short_circuit = self.get_unique_name("Or_short_circuit") + + with self.allocated_reg() as reg1, self.allocated_reg() as reg2: + for arg in node.values: + self.emit(f"; Or operand {arg}") + self.visit(arg) + + self.emit(f"spo {reg1}") + self.emit(f"subi {reg1} 1 {reg2}") + self.emit(f"bri carry {label_short_circuit}") + + self.emit_label(label_short_circuit) + self.emit(f"spu {reg1}") + + case other: + raise NotImplementedError(f"Unhandled BoolOp: {other}") + + def visit_BinOp(self, node: ast.BinOp): + self.emit(f"; {node.op}") + + self.emit(f"; BinOp lhs {node}") + self.visit(node.left) + self.emit(f"; BinOp rhs {node}") + self.visit(node.right) + + with self.allocated_reg() as reg1, self.allocated_reg() as reg2: + self.emit(f"spo {reg2}") + self.emit(f"spo {reg1}") + + match node.op: + case ast.Add(): + self.emit(f"add {reg1} {reg2} {reg1}") + case ast.Sub(): + self.emit(f"sub {reg1} {reg2} {reg1}") + case ast.BitAnd(): + self.emit(f"and {reg1} {reg2} {reg1}") + case ast.BitOr(): + self.emit(f"or {reg1} {reg2} {reg1}") + case ast.BitXor(): + self.emit(f"xor {reg1} {reg2} {reg1}") + case ast.LShift(): + self.emit(f"sll {reg1} {reg2} {reg1}") + case ast.RShift(): + self.emit(f"slr {reg1} {reg2} {reg1}") + case other: + raise NotImplementedError(f"Unhandled BinOp: {other}") + + self.emit(f"spu {reg1}") + + def visit_Constant(self, node: ast.Constant): + self.emit(f"; {node}") + match node.value: + case bool(value): + int_value = 1 if value else 0 + self.eval_int_constant_and_spu(int_value) + case int(value): + self.eval_int_constant_and_spu(value) + case str(value): + if len(value) > 1: + raise Exception("Invalid string, only single char values allowed: " + value) + + c = value[0] + int_value = ord(c) + self.eval_int_constant_and_spu(int_value) + case other: + raise NotImplementedError(f"Unhandled Constant: {other}") + + def visit_If(self, node: ast.If): + self.emit(f"; {node}") + + self.visit(node.test) + label_false = self.get_unique_name("If_false_branch") + label_end = self.get_unique_name("If_end_branch") + + with self.allocated_reg() as reg: + self.emit(f"spo {reg}") + self.emit(f"addi {reg} 0 {reg}") + self.emit(f"bri zero {label_false}") + + for true_branch_stmt in node.body: + if type(true_branch_stmt) == ast.Expr and type(true_branch_stmt.value) != ast.Call: + self.emit("; NOP top-level expression") + continue + + self.visit(true_branch_stmt) + + self.emit(f"jpi {label_end}") + self.emit_label(label_false) + + for false_branch_stmt in node.orelse: + if type(false_branch_stmt) == ast.Expr and type(false_branch_stmt.value) != ast.Call: + self.emit("; NOP top-level expression") + continue + + self.visit(false_branch_stmt) + + self.emit_label(label_end) + + def visit_Compare(self, node: ast.Compare): + self.emit(f"; {node}") + + if len(node.ops) > 1: + raise Exception("Multiple compare ops not supported") + + if len(node.comparators) > 1: + raise Exception("Multiple comparators not supported") + + op = node.ops[0] + left = node.left + right = node.comparators[0] + + label_true = self.get_unique_name("Compare_true") + label_end = self.get_unique_name("Compare_end") + + self.visit(left) + self.visit(right) + + self.emit(f"; Comparing {left} {op} {right}") + with self.allocated_reg() as reg_lhs, self.allocated_reg() as reg_rhs: + match op: + case ast.Lt(): # lhs < rhs + self.emit(f"spo {reg_rhs}") + self.emit(f"spo {reg_lhs}") + + self.emit(f"sub {reg_lhs} {reg_rhs} {reg_lhs}") + self.emit(f"bri carry {label_true}") + + # false branch + self.emit(f"ldi 0 {reg_lhs}") + self.emit(f"spu {reg_lhs}") + self.emit(f"jpi {label_end}") + + # true branch + self.emit_label(label_true) + self.emit(f"ldi 1 {reg_lhs}") + self.emit(f"spu {reg_lhs}") + + self.emit_label(label_end) + + def visit_While(self, node: ast.While): + self.emit(f"; {node}") + + label_test = self.get_unique_name("While_test") + label_else = self.get_unique_name("While_else") + label_end = self.get_unique_name("While_end") + + prev_break_target = self.latest_break_target + self.latest_break_target = label_end + + with self.allocated_reg() as reg: + self.emit_label(label_test) + self.visit(node.test) + self.emit(f"spo {reg}") + self.emit(f"addi {reg} 0 {reg}") + self.emit(f"bri zero {label_else}") + + for body_stmt in node.body: + if type(body_stmt) == ast.Expr and type(body_stmt.value) != ast.Call: + self.emit("; NOP top-level expression") + continue + + self.visit(body_stmt) + + self.emit(f"jpi {label_test}") + + self.emit_label(label_else) + + for else_stmt in node.orelse: + self.visit(else_stmt) + + self.emit_label(label_end) + + self.latest_break_target = prev_break_target + + def visit_Pass(self, node: ast.Pass): + self.emit(f"; {node}") + pass + + def visit_Break(self, node: ast.Break): + self.emit(f"; {node}") + + if self.latest_break_target is None: + raise Exception("Invalid break: no break target defined, i.e. no place to break out to") + + self.emit(f"jpi {self.latest_break_target}") + + def visit_For(self, node: ast.For): + raise Exception("For loops not supported. Consider using a while loop instead.") + + def visit_Lambda(self, node: ast.Lambda): + raise Exception("Lambda functions not supported. Consider using a named function instead.") + + def collect_local_variables(self, stmts: list[ast.stmt]): + result: list[str] = [] + symbols: list[str] = [] + for stmt in stmts: + match stmt: + case ast.Assign(targets=[ast.Name(name)]): + symbols.append(name) + case ast.Assign(other): + raise Exception(f"Unsupported assignment in function definition body: {other}") + case ast.While(body=body): + symbols += self.collect_local_variables(body) + case ast.If(body=tb, orelse=fb): + symbols += self.collect_local_variables(tb) + symbols += self.collect_local_variables(fb) + case other: pass + + for symbol in symbols: + if symbol not in result: + result.append(symbol) + + return result + + def visit_FunctionDef(self, node: ast.FunctionDef): + prev_currently_emitting_asm_list = self.currently_emitting_asm_list + self.currently_emitting_asm_list = self.function_def_asms + self.emit(f"; {node}") + + fn_name = node.name + fn_params = [str(param.arg) for param in node.args.args] + fn_stmts = node.body + + # Add a "return None" to the end to make sure the function returns + if len(fn_stmts) == 0 or type(fn_stmts[len(fn_stmts) - 1]) != ast.Return: + fn_stmts.append(ast.Return(value=None)) + + if len(node.args.kwonlyargs) > 0 or len(node.args.posonlyargs) > 0 or len(node.args.kw_defaults) > 0 or len(node.args.defaults) > 0: + raise Exception("Only simple positional args are supported for now in function definitions.") + + self.emit_label(fn_name) + local_var_names = self.collect_local_variables(fn_stmts) + frame_names = fn_params + local_var_names + + # Move stack pointer to accommodate local variables + if len(local_var_names) > 0: + self.emit_add_imm("SP", len(local_var_names), "SP") + + prev_local_bindings = self.local_bindings + self.local_bindings = {} + self.emit("; stack frame with offsets") + for offset, name in enumerate(frame_names): + self.local_bindings[name] = offset + self.emit(f"; {name} {offset}") + + for stmt in fn_stmts: + self.visit(stmt) + + self.local_bindings = prev_local_bindings + self.currently_emitting_asm_list = prev_currently_emitting_asm_list + + def visit_Return(self, node: ast.Return): + self.emit(f"; {node}") + + with self.allocated_reg() as reg1, self.allocated_reg() as reg2: + if node.value is not None: + self.visit(node.value) + else: + self.emit(f"ldi 0 {reg1}") + self.emit(f"spu {reg1}") + + self.emit(f"; return value is on top of stack") + + self.emit(f"; return from function") + self.emit(f"subi FP 1 FP") + self.emit(f"ldr FP {reg2}") + self.emit(f"jpr {reg2}") + + def visit_Call(self, node: ast.Call): + self.emit(f"; {node}") + + match node.func: + case ast.Attribute(ast.Name(id="atk16"), attr): + self.emit_builtin_call(attr, node.args) + case ast.Name(name): + self.emit(f"; Call function {name}") + + # Push the current FP + self.emit("spu FP") + #self.emit("mov SP FP") # BUG: FP needs to be moved AFTER EVALING ARGS! args depend on FP in calling frame if there are names to resolve! + + # Reserve a stack slot for the return address + # FP will point to this slot + with self.allocated_reg() as reg: + self.emit(f"ldi 0 {reg}") + self.emit(f"spu {reg}") + + # Evaluate args before call, pushing them to stack + for arg in node.args: + self.visit(arg) + + self.emit(f"subi SP {1 + len(node.args)} FP") + + with self.allocated_reg() as reg: + self.emit("; set up return address and jump to subroutine") + self.emit(f"lpc {reg}") + self.emit(f"addi {reg} 4 {reg}") # imm must equal number of primitive instrs from lpc until jpi + self.emit(f"str {reg} FP") + self.emit(f"addi FP 1 FP") + self.emit(f"jpi {name}") + # ...after return from call... + self.emit(f"spo {reg}") + + self.emit("mov FP SP") # move stack pointer to base of stack frame, i.e. top of previous frame + self.emit("spo FP") # restore FP of previous frame + self.emit(f"spu {reg}") + + case other: + raise NotImplementedError(f"Unhandled Call: {other}") + + def resolve_name(self, name: str) -> Label | StackOffset: + if name in self.local_bindings: + return self.local_bindings[name] + + if name in self.const_bindings: + return self.const_bindings[name] + + raise Exception(f"{name} is unbound") + + def visit_Name(self, node: ast.Name): + self.emit(f"; {node} ({node.id})") + + name = node.id.lower() + addr = self.resolve_name(name) + + with self.allocated_reg() as reg: + match addr: + case Label(label): + self.emit(f"ldi {label} {reg}") + case StackOffset(offset): + self.emit(f"ldi {offset} {reg}") + self.emit(f"add FP {reg} {reg}") + case other: + raise Exception(f"Unsupported addr value: {other}") + + self.emit(f"ldr {reg} {reg}") + self.emit(f"spu {reg}") + + def visit_Assign(self, node: ast.Assign): + self.emit(f"; {node}") + + targets = node.targets + value = node.value + match targets: + case [ast.Name(name)]: + offset = self.resolve_name(name) + + if type(offset) != StackOffset: + raise Exception(f"Invalid address {offset} for name {name}. Can only assign to stack offsets.") + + self.emit(f"; assigning {name} at FP + {offset}") + + with self.allocated_reg() as reg1, self.allocated_reg() as reg2: + self.emit(f"; evaluating value to be assigned") + self.visit(value) + self.emit(f"; assigning stack address (FP + {offset}) := top of stack") + self.emit(f"spo {reg1}") # value + + self.emit(f"ldi {offset} {reg2}") + self.emit(f"add {reg2} FP {reg2}") # address + self.emit(f"str {reg1} {reg2}") + + case other: + raise Exception(f"Unsupported assign targets: {other}") + + def visit_AugAssign(self, node: ast.AugAssign): + op = node.op + lhs = node.target + rhs = node.value + + if type(lhs) != ast.Name: + raise Exception("AugAssign to non-Name lhs not yet supported!") + + # construct bin op and assignment + bin_op = ast.BinOp(left=lhs, op=op, right=rhs) + assign = ast.Assign(targets=[lhs], value=bin_op) + + self.visit(assign) + + def visit_Import(self, node: ast.Import) -> Any: + match node.names: + case [ast.alias(name="atk16")]: + return + case other: + raise NotImplementedError(f"Unsupported import {other}") + + def visit_AnnAssign(self, node: ast.AnnAssign): + match node: + case ast.AnnAssign( + target=ast.Name(name), + annotation=ast.Attribute( + value=ast.Name(id="atk16"), + attr="ConstWord16"), + value=ast.Constant(value) # TODO: constant folding + ): + if type(value) == int: + self.assign_const(name.lower(), value) + return + + raise NotImplementedError("Unhandled AnnAssign:\n" + ast.dump(node, indent=4)) + + def get_module_exports(self, node: ast.Module): + result: list[str] = [] + for stmt in node.body: + match stmt: + case ast.FunctionDef(name): + result.append(name) + case _: + # only function exported since recognizing which assignments are constants is kinda hard + pass + + return result + +with open(infile_path, "r") as f: + source_py = f.read() + +with open("asm/ast_compiler_bootstrap.atk16", "r") as f: + bootstrap_asm = f.read() + +compiler = Compiler() +asm_out = compiler.compile( + bootstrap_asm, + source_py, +) + +with open(outfile_path, "w") as f: + f.write(asm_out) + diff --git a/atk16-bytecode-compiler/bytecode_compiler.py b/atk16-bytecode-compiler/bytecode_compiler.py new file mode 100644 index 0000000..42cf8dc --- /dev/null +++ b/atk16-bytecode-compiler/bytecode_compiler.py @@ -0,0 +1,220 @@ +#!/usr/bin/env python3 +# Generate .atk16 assembly from Python bytecode + +import sys +import dis + +from dataclasses import dataclass +from typing import Literal, Set, cast, Any +from collections import OrderedDict + +if len(sys.argv) != 3: + print("usage: compiler.py ") + sys.exit(1) + +infile_path = sys.argv[1] +outfile_path = sys.argv[2] + +with open(infile_path, "r") as f: + source_py = f.read() + +compiled_code = compile(source_py, infile_path, 'exec') +disassembled = dis.get_instructions(compiled_code) + +co_consts = compiled_code.co_consts +co_names = compiled_code.co_names +print("### Constants") +print(co_consts) +print("\n### Names") +print(co_names) +print("\n### Instructions") +instrs: list[tuple[str, int | None]] = [] +for instr in disassembled: + print(f"{instr.opname}\t{instr.arg}") + instrs.append((instr.opname, instr.arg)) + +### compile +asm_out: list[str] = [] +def emit(stmt: str) -> int: + ret = len(asm_out) + asm_out.append(stmt) + return ret + +_counter = 0 +def get_unique_name(prefix: str): + global _counter + ret = f"{prefix}_{_counter}" + _counter += 1 + return ret + +@dataclass +class Label: + label: str + + def __str__(self): + return f"@label {self.label}" + +RegChar = Literal["A", "B", "C", "D", "E", "F", "G", "H"] +GENERIC_REGS_LST: list[RegChar] = ["A", "B", "C", "D", "E", "F"] +GENERIC_REGS: OrderedDict[RegChar, None] = OrderedDict() +for char in GENERIC_REGS_LST: + GENERIC_REGS[cast(RegChar, char)] = None + +@dataclass +class Reg: + reg: RegChar + + def __str__(self): + return f"R{self.reg}" + +Value = Label | Reg + +reserved_regs: OrderedDict[RegChar, None] = OrderedDict() +def alloc_reg() -> Reg: + for reg in GENERIC_REGS: + if not reg in reserved_regs: + reserved_regs[reg] = None + return Reg(reg) + + raise Exception("Ran out of registers, TODO use stack") + +def free_reg(reg: Reg): + reserved_regs.pop(reg.reg) + +def emit_serialize_const(const: Any): + match const: + case int(v): + emit(f" {v}") + case str(v): + if len(v) > 1: + raise Exception("Cannot serialize const string: " + v) + + emit(f" {ord(v[0])}") + case _: + print(f"warn: cannot serialize {type(const)} ({const}), emitting zero") + emit(" 0") + +STACK_POINTER_REG = Reg('H') +emit(f"@let SP {STACK_POINTER_REG}") +emit("@use ext_std:*") +emit("@include bootstrap") + +py_consts_addr = emit("@label py_consts") + +for const_i, const in enumerate(co_consts): + emit(f"; {const_i}: {const}") + emit_serialize_const(const) + +emit("@label atk_store") +_reg_value = alloc_reg() +_reg_addr = alloc_reg() +emit(f" str RB RA") +emit(f" rsr") +free_reg(_reg_value) +free_reg(_reg_addr) + +emit("@label atk_enable_text_mode") +emit(" set_graphics_mode gr_text_mode") +emit(" rsr") + +emit("@label main") + +instr_i = 0 + +def instr_pop(): + global instr_i + ret = instrs[instr_i] + instr_i += 1 + return ret + +def instr_pop_expect(opcode: str, arg: int | None = -1): + ret_op, ret_arg = instr_pop() + if ret_op != opcode: + raise Exception(f"Expected opcode {opcode}, got {ret_op}") + if arg != -1 and arg != ret_arg: + raise Exception(f"Expected instruction arg {arg}, got {ret_arg}") + return ret_op, ret_arg + +def instr_peek(): + return instrs[instr_i] + +def instr_peek_expect(opcode: str, arg: int | None = -1): + ret_op, ret_arg = instr_peek() + if ret_op != opcode: + raise Exception(f"Expected {opcode}, got {ret_op}") + if arg != -1 and arg != ret_arg: + raise Exception(f"Expected instruction arg {arg}, got {ret_arg}") + return ret_op, ret_arg + +instr_pop_expect("RESUME") +instr_pop_expect("LOAD_CONST", 0) +instr_pop_expect("LOAD_CONST", 1) +instr_pop_expect("IMPORT_NAME", 0) +instr_pop_expect("IMPORT_STAR", None) + +while instr_i < len(instrs): + opcode, arg = instr_pop() + emit(f"; {opcode} {arg}") + match opcode: + case "LOAD_CONST": + reg = alloc_reg() + emit(f" ldi ${{py_consts + {cast(int, arg)}}} {reg}") + emit(f" ldr {reg} {reg}") + emit(f" spu {reg}") + free_reg(reg) + case "PUSH_NULL": + reg = alloc_reg() + emit(f" ldi 0 {reg}") + emit(f" spu {reg}") + free_reg(reg) + case "LOAD_NAME": + name = co_names[cast(int, arg)] + reg = alloc_reg() + emit(f" ldi {name} {reg}") + emit(f" spu {reg}") + free_reg(reg) + case "CALL": + arg_count = cast(int, arg) + # if arg_count > len(GENERIC_REGS_LST): + # raise Exception(f"Function calls with > {len(GENERIC_REGS_LST)} arguments not supported") + + regs_to_restore: list[tuple[Reg, Reg]] = [] + for j in range(arg_count): + i = arg_count - j - 1 + ith_reg_char = GENERIC_REGS_LST[i] + ith_reg = Reg(ith_reg_char) + if ith_reg_char in reserved_regs: + reg = alloc_reg() + emit(f" mov {ith_reg} {reg}") + regs_to_restore.append((reg, ith_reg)) + + emit(f" spo {ith_reg}") + reserved_regs[ith_reg_char] = None # manually reserve ith_reg + + fn_reg = alloc_reg() + emit(f" spo {fn_reg}") + # emit(f" ldr {fn_reg} {fn_reg}") + emit(f" csr {fn_reg}") + free_reg(fn_reg) + + for from_reg, ith_reg in regs_to_restore: + emit(f" mov {from_reg} {ith_reg}") + + for j in range(arg_count): + i = arg_count - j - 1 + ith_reg_char = GENERIC_REGS_LST[i] + ith_reg = Reg(ith_reg_char) + free_reg(ith_reg) + + case "POP_TOP": + reg = alloc_reg() + emit(f" spo {reg}") + free_reg(reg) + case _: + print(f"Skipping not implemented opcode: {opcode}") + +emit("@label keep_alive") +emit(" jpi keep_alive") + +with open(outfile_path, "w") as f: + f.write("\n".join(asm_out)) diff --git a/atk16-utils/charmem.py b/atk16-utils/charmem.py new file mode 100644 index 0000000..aaac122 --- /dev/null +++ b/atk16-utils/charmem.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +# Generate .bin file with ATK16 CPU TPU charmem data + +# Addressed by _CCC CCCC CYYY +# Data width 8bit: ___X XXXX +# where _ = unused, C = 8bit character code, Y = character y coordinate, X = pixel value + +import sys + +if len(sys.argv) != 2: + print("usage: charmem.py ") + sys.exit(1) + +outfile_path = sys.argv[1] + +with open("charset.txt", "r") as f: + lines = [s.strip("\n") for s in f.readlines()] + +header_chars = lines[0] + +charset: list[list[str]] = [] + +CHAR_HEIGHT = 8 +CHAR_WIDTH = 8 + +i = 0 +while i < len(lines): + i += 1 # skip comment line + char = lines[i:i+CHAR_HEIGHT] + for row in char: + if len(row) != CHAR_WIDTH: + raise Exception(f"char row number {i} has width != {CHAR_WIDTH}: {len(row)}\n" + row + "\n" + "\n".join(char)) + charset.append(char) + i += CHAR_HEIGHT + 1 + +CHAR_N = len(charset) + +TOTAL_BYTEARRAY_SIZE = CHAR_N * CHAR_HEIGHT + +def string_to_byte(input_string: str): + # Replace spaces with '0' and '#' with '1' + binary_string = input_string.replace(' ', '0').replace('█', '1') + + assert(len(input_string) == CHAR_WIDTH) + + # Check if the string contains only '0' or '1' + if not all(c in '01' for c in binary_string): + raise ValueError("Input string must contain only spaces and '█' characters.") + + # Convert the binary string to an unsigned integer byte + return int(binary_string[::-1], 2) + + +res_b = bytearray(TOTAL_BYTEARRAY_SIZE) +for cn, char in enumerate(charset): + for cy in range(0, CHAR_HEIGHT): + addr = (cn << 3) + cy + byte = string_to_byte(char[cy]) + print(f"{byte:>08b}") + res_b[addr] = byte + +with open(outfile_path, "wb") as f: + f.write(res_b) diff --git a/atk16-utils/convert_ttf.py b/atk16-utils/convert_ttf.py new file mode 100644 index 0000000..c1135cb --- /dev/null +++ b/atk16-utils/convert_ttf.py @@ -0,0 +1,52 @@ +from PIL import Image, ImageFont, ImageDraw + +import sys + +if len(sys.argv) != 3: + print("usage: convert_ttf.py ") + sys.exit(1) + +# Define the font file and size +font_file = sys.argv[1] +out_file = sys.argv[2] +font_size = 8 # 8x8 pixels + +# Create a font object +font = ImageFont.truetype(font_file, font_size) + + +# backspace 0x8, tab 0x9, newline 0xA, space 0x20 + +# Define the characters to render +#characters = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' + +def to_char_code(i: int) -> str: + if i == 10: + return " " + return chr(i) + +characters = [to_char_code(i) for i in range(0, 256)] + + +# Open a file to write the bitmaps to +with open(out_file, 'w') as bitmap_file: + for char_idx, char in enumerate(characters): + # Create a new image with a white background + image = Image.new('1', (8, 8), 1) + + # Create a drawing context + draw = ImageDraw.Draw(image) + + # Draw the character + draw.text((0, 0), char, font=font, fill=0) + + # Convert the image to a list of 0's and 1's + pixels = image.getdata() + bitmap = [1 if pixel == 0 else 0 for pixel in pixels] + + # Write the bitmap to the file + bitmap_file.write(f'Character {char_idx}: {char}\n') + for i in range(0, 64, 8): + row = bitmap[i:i+8] + bitmap_file.write(''.join(str(bit) for bit in row) + '\n') + bitmap_file.write('\n') diff --git a/atk16-utils/dig_install.py b/atk16-utils/dig_install.py new file mode 100644 index 0000000..c32229b --- /dev/null +++ b/atk16-utils/dig_install.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +# Install a generated .bin file into a memory chip in a .dig circuit file + +import sys +from typing import cast +import xml.etree.ElementTree as ET + +if len(sys.argv) != 4: + print("usage: dig_install.py ") + sys.exit(1) + +infile = sys.argv[1] +circuitfile = sys.argv[2] +chip_label = sys.argv[3] + +with open(infile, "rb") as f: + program_bytes = f.read() + +i = 0 +program_words: list[str] = [] +while i < len(program_bytes): + hi_byte = program_bytes[i] + lo_byte = program_bytes[i + 1] + word = f"{hi_byte:>02x}{lo_byte:>02x}" + #print(word) + program_words.append(word) + i += 2 + +program_data = ",".join(program_words) +print("program_data:", program_data) + +tree = ET.parse(circuitfile) +root = tree.getroot() + +# Iterate through each 'visualElement' element +def find_data_element(root: ET.Element) -> ET.Element: + is_correct_visual_element = False + for visual_element in root.findall('.//visualElement'): + element_attributes = visual_element.find('elementAttributes') + if element_attributes is None: continue + + entries = list(element_attributes) + for entry in entries: + strings = entry.findall("string") + is_label_entry = len(strings) == 2 and strings[0].text == "Label" and strings[1].text == chip_label + if is_label_entry and not is_correct_visual_element: + is_correct_visual_element = True + continue + + is_data_entry = len(strings) == 1 and strings[0].text == "Data" + if is_data_entry and is_correct_visual_element: + data_element = entry.findall("data")[0] + return data_element + + raise Exception(f"No data entry matching label {chip_label} found in tree") + +data_element = find_data_element(root) +data_element.text = program_data + +tree.write(circuitfile) \ No newline at end of file diff --git a/atk16-utils/ucode.py b/atk16-utils/ucode.py new file mode 100755 index 0000000..07d0554 --- /dev/null +++ b/atk16-utils/ucode.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python3 +# Generate .bin file with ATK16 CPU microcode + +# Addressed by OOOO BUUU +# where O = opcode, B = branch flag, U = microsequencer value + +import sys + +if len(sys.argv) != 2: + print("usage: ucode.py ") + sys.exit(1) + +outfile_path = sys.argv[1] + +PC_CO = 1 << 0 +PC_IE = 1 << 1 +PC_OE = 1 << 2 +MAR_IE = 1 << 3 +MEM_IE = 1 << 4 +MEM_OE = 1 << 5 +RW_IE = 1 << 6 +R1_OE = 1 << 7 +R2_OE = 1 << 8 +IR_IE = 1 << 9 +IM_M = 1 << 10 +LI_OE = 1 << 11 +ALU_OE = 1 << 12 +FR_IE = 1 << 13 +HALT = 1 << 14 +US_RS = 1 << 15 +ISRA_OE = 1 << 16 +IM_DS = 1 << 17 +IM_EN = 1 << 18 +IPC_IE = 1 << 19 +IPC_OE = 1 << 20 +NOP5 = 1 << 21 +NOP6 = 1 << 22 +NOP7 = 1 << 23 + +BRANCH_FLAG_STATES_N = 2 +UCODE_N: int = 2**3 +CONTROL_WORD_SIZE = 3 + +def not_branch(bs: list[int]) -> list[list[int]]: + return BRANCH_FLAG_STATES_N * [bs] + +def branch(false_branch: list[int], true_branch: list[int]) -> list[list[int]]: + return [false_branch, true_branch] + +fetch = [PC_OE|MAR_IE, MEM_OE|IR_IE|PC_CO] + +def nop(): + return not_branch([*fetch, US_RS, 0, 0, 0, 0, 0]) + +ucode = [ + # ALR 0000 TTTL LLRR RSSS + not_branch([*fetch, ALU_OE|FR_IE|RW_IE, US_RS, 0, 0, 0, 0]), + # ALI 0001 TTTL LLII ISSS + not_branch([*fetch, IM_M|ALU_OE|FR_IE|RW_IE, US_RS, 0, 0, 0, 0]), + # LDR 0010 TTTR RRXX XXXX + not_branch([*fetch, R1_OE|MAR_IE, MEM_OE|RW_IE, US_RS, 0, 0, 0]), + # STR 0011 XXXL LLRR RXXX + not_branch([*fetch, R1_OE|MAR_IE, R2_OE|MEM_IE, US_RS, 0, 0, 0]), + # LDI 0100 TTTI IIII IIII + not_branch([*fetch, LI_OE|RW_IE, US_RS, 0, 0, 0, 0]), + # JPR 0101 XXXR RRXX XXXX + not_branch([*fetch, R1_OE|PC_IE, US_RS, 0, 0, 0, 0]), + # JPI 0110 XXXI IIII IIII + not_branch([*fetch, IM_M|LI_OE|PC_IE, US_RS, 0, 0, 0, 0]), + # BRR 0111 XFFR RRXX XXXX + branch([*fetch, US_RS, 0, 0, 0, 0, 0], + [*fetch, R1_OE|PC_IE, US_RS, 0, 0, 0, 0]), + # BRI 1000 XFFI IIII IIII + branch([*fetch, US_RS, 0, 0, 0, 0, 0], + [*fetch, IM_M|LI_OE|PC_IE, US_RS, 0, 0, 0, 0]), + # LPC 1001 TTTX XXXX XXXX + not_branch([*fetch, PC_OE|RW_IE, US_RS, 0, 0, 0, 0]), + # NOP 1010 XXXX XXXX XXXX + nop(), + # NOP 1011 XXXX XXXX XXXX + nop(), + # ISRP0 1100 XXXX XXXX XXXX + not_branch([IM_EN|PC_OE|IPC_IE, ISRA_OE|MAR_IE, MEM_OE|PC_IE, US_RS, 0, 0, 0, 0]), + # ISRP1 1101 XXXX XXXX XXXX + not_branch([IM_EN|PC_OE|IPC_IE, ISRA_OE|MAR_IE, MEM_OE|PC_IE, US_RS, 0, 0, 0, 0]), + # RTI 1110 XXXX XXXX XXXX + not_branch([*fetch, IM_DS|IPC_OE|PC_IE, US_RS, 0, 0, 0, 0]), + # HLT 1111 XXXX XXXX XXXX + not_branch([*fetch, HALT, 0, 0, 0, 0, 0]), +] + +INST_N = len(ucode) +TOTAL_BYTEARRAY_SIZE = INST_N * BRANCH_FLAG_STATES_N * UCODE_N * CONTROL_WORD_SIZE + +res_b = bytearray(TOTAL_BYTEARRAY_SIZE) + +for i in range(INST_N): + for j in range(BRANCH_FLAG_STATES_N): + for k in range(UCODE_N): + for l in range(CONTROL_WORD_SIZE): + idx = l + \ + k * CONTROL_WORD_SIZE + \ + j * CONTROL_WORD_SIZE * UCODE_N + \ + i * CONTROL_WORD_SIZE * UCODE_N * BRANCH_FLAG_STATES_N + cword = ucode[i][j][k] + assert len(ucode[i][j]) == 8 + cbyte = (cword >> (8 * (CONTROL_WORD_SIZE - l - 1))) & 0xff + print(f"inst: {i:>04b}, idx: {idx:>04x}, cbyte: {cbyte:>08b}") + res_b[idx] = cbyte + +with open(outfile_path, "wb") as f: + f.write(res_b) diff --git a/charset.txt b/charset.txt deleted file mode 100644 index bee1e3d..0000000 Binary files a/charset.txt and /dev/null differ diff --git a/digital-diagrams/atk16.dig b/digital-diagrams/atk16.dig new file mode 100644 index 0000000..87f7ddb --- /dev/null +++ b/digital-diagrams/atk16.dig @@ -0,0 +1,2748 @@ + + + 2 + + + romContent + + + + + + view1 + + + 0.8446671195652201 + 0.0 + 0.0 + 0.8446671195652201 + 481.55870489058793 + 445.5141438507956 + + + + + view2 + + + 0.8446671195652201 + 0.0 + 0.0 + 0.8446671195652201 + 481.55870489058793 + 445.5141438507956 + + + + + view3 + + + 0.8446671195652201 + 0.0 + 0.0 + 0.8446671195652201 + 481.55870489058793 + 445.5141438507956 + + + + + showDataTable + true + + + + + Register + + + valueIsProbe + true + + + Label + MAR + + + Bits + 16 + + + + + + CounterPreset + + + valueIsProbe + true + + + Label + PC + + + Bits + 16 + + + isProgramCounter + true + + + + + + Ground + + + rotation + + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + atk16_mem.dig + + + Label + MEMORY + + + + + + atk16_jump_unit.dig + + + + + Probe + + + Label + PC + + + + + + atk16_decoder.dig + + + shapeType + CUSTOM + + + + + + Tunnel + + + NetName + FLAG_S + + + + + + Tunnel + + + rotation + + + + NetName + IR_IE + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Tunnel + + + rotation + + + + NetName + LI_OE + + + + + + Tunnel + + + rotation + + + + NetName + RW_IE + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + atk16_regbank.dig + + + + + Driver + + + Bits + 16 + + + flipSelPos + true + + + + + + Tunnel + + + NetName + R2_OE + + + + + + Driver + + + Bits + 16 + + + flipSelPos + true + + + + + + Tunnel + + + NetName + R1_OE + + + + + + atk16_alu_inputs.dig + + + + + Tunnel + + + rotation + + + + NetName + IM_M + + + + + + atk16_alu.dig + + + shapeType + SIMPLE + + + Label + ALU + + + + + + Driver + + + Bits + 16 + + + + + + Register + + + valueIsProbe + true + + + Label + FR + + + Bits + 4 + + + + + + Tunnel + + + rotation + + + + NetName + FR_IE + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Tunnel + + + NetName + ALU_OE + + + + + + Tunnel + + + NetName + FR_Q + + + + + + Counter + + + valueIsProbe + true + + + Label + Microsequencer + + + Bits + 3 + + + + + + VDD + + + rotation + + + + + + + Not + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Driver + + + Bits + 16 + + + flipSelPos + true + + + + + + Probe + + + Label + Bus + + + + + + Tunnel + + + rotation + + + + NetName + MAR_IE + + + + + + Tunnel + + + rotation + + + + NetName + PC_OE + + + + + + Tunnel + + + rotation + + + + NetName + IM_M + + + + + + Tunnel + + + rotation + + + + NetName + OPCODE + + + + + + Probe + + + Label + OPCODE + + + + + + Tunnel + + + rotation + + + + NetName + PC_CO + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Ground + + + rotation + + + + + + + Tunnel + + + rotation + + + + NetName + PC_IE + + + + + + Splitter + + + mirror + true + + + Input Splitting + 24 + + + Output Splitting + 1*24 + + + + + + Tunnel + + + NetName + PC_CO + + + + + + Tunnel + + + NetName + PC_IE + + + + + + Tunnel + + + NetName + PC_OE + + + + + + Tunnel + + + NetName + MAR_IE + + + + + + Tunnel + + + NetName + MEM_IE + + + + + + Tunnel + + + NetName + MEM_OE + + + + + + Tunnel + + + NetName + R1_OE + + + + + + Tunnel + + + NetName + IR_IE + + + + + + Tunnel + + + NetName + ALU_OE + + + + + + Tunnel + + + NetName + US_RS + + + + + + Tunnel + + + NetName + FR_IE + + + + + + Tunnel + + + NetName + RW_IE + + + + + + Stop + + + + + Tunnel + + + NetName + LI_OE + + + + + + Tunnel + + + NetName + IM_M + + + + + + Tunnel + + + NetName + R2_OE + + + + + + atk16_ucode_addr.dig + + + + + Tunnel + + + rotation + + + + NetName + FLAG_S + + + + + + Tunnel + + + rotation + + + + NetName + FR_Q + + + + + + Tunnel + + + rotation + + + + NetName + OPCODE + + + + + + Tunnel + + + NetName + OPCODE + + + + + + Tunnel + + + rotation + + + + NetName + US_Q + + + + + + Tunnel + + + NetName + ISRA_OE + + + + + + Tunnel + + + rotation + + + + NetName + IM_EN + + + + + + Tunnel + + + rotation + + + + NetName + IM_DS + + + + + + Tunnel + + + NetName + IPC_IE + + + + + + Tunnel + + + NetName + IPC_OE + + + + + + Driver + + + Bits + 16 + + + flipSelPos + true + + + + + + Tunnel + + + NetName + ISRA_OE + + + + + + Const + + + Value + 4 + + + Bits + 14 + + + intFormat + hex + + + + + + Tunnel + + + rotation + + + + NetName + IT_N + + + + + + Splitter + + + Input Splitting + 2,14 + + + Output Splitting + 16 + + + + + + Register + + + Label + IPC + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + IPC_IE + + + + + + Driver + + + Bits + 16 + + + flipSelPos + true + + + + + + Tunnel + + + NetName + IPC_OE + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Tunnel + + + NetName + IM_EN + + + + + + Tunnel + + + NetName + IM_DS + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Tunnel + + + rotation + + + + NetName + MEM_IE + + + + + + Tunnel + + + rotation + + + + NetName + MEM_OE + + + + + + Tunnel + + + NetName + DBUS + + + + + + Probe + + + Label + MMIO_S + + + + + + Tunnel + + + NetName + MMIO_IE + + + + + + Tunnel + + + NetName + MMIO_OE + + + + + + Tunnel + + + NetName + MMIO_S + + + + + + atk16_peripherals.dig + + + + + Tunnel + + + rotation + + + + NetName + MMIO_OE + + + + + + Tunnel + + + rotation + + + + NetName + IT_N + + + + + + Tunnel + + + rotation + + + + NetName + IM_DS + + + + + + Counter + + + Label + CLK divider /16 + + + Bits + 4 + + + + + + Tunnel + + + NetName + CLK + + + + + + VDD + + + rotation + + + + + + + Ground + + + + + Clock + + + runRealTime + true + + + Frequency + 25175000 + + + + + + Tunnel + + + NetName + IT_N + + + + + + EEPROM + + + AddrBits + 8 + + + Label + UCODE + + + Bits + 24 + + + Data + c,221,3040,8000,4*0,c,221,3040,8000,4*0,c,221,3440,8000,4*0,c +,221,3440,8000,4*0,c,221,88,60,8000,0,0,0,c,221,88,60,8000,0,0,0 +,c,221,88,110,8000,0,0,0,c,221,88,110,8000,0,0,0,c,221,840,8000 +,4*0,c,221,840,8000,4*0,c,221,82,8000,4*0,c,221,82,8000,4*0,c +,221,c02,8000,4*0,c,221,c02,8000,4*0,c,221,8000,5*0,c,221,82,8000 +,4*0,c,221,8000,5*0,c,221,c02,8000,4*0,c,221,44,8000,4*0,c,221 +,44,8000,4*0,c,221,8000,5*0,c,221,8000,5*0,c,221,8000,5*0,c,221 +,8000,5*0,c0004,10008,22,8000,4*0,c0004,10008,22,8000,4*0,c0004 +,10008,22,8000,4*0,c0004,10008,22,8000,4*0,c,221,120002,8000,4*0 +,c,221,120002,8000,4*0,c,221,4000,5*0,c,221,4000 + + + + + + VDD + + + rotation + + + + + + + Ground + + + rotation + + + + + + + VDD + + + rotation + + + + + + + Tunnel + + + NetName + DBUS + + + + + + Tunnel + + + rotation + + + + NetName + MMIO_IE + + + + + + Tunnel + + + rotation + + + + NetName + MMIO_S + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Tunnel + + + rotation + + + + NetName + MMIO_IE + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + atk16_graphics_mode.dig + + + + + Tunnel + + + rotation + + + + NetName + MMIO_S + + + + + + Tunnel + + + NetName + PCLK + + + + + + Probe + + + Label + GRAPHICS MODE + + + + + + Tunnel + + + NetName + GRMODE + + + + + + atk16_ppu.dig + + + + + Splitter + + + Input Splitting + 2,2,2 + + + Output Splitting + 6 + + + + + + Tunnel + + + rotation + + + + NetName + DBUS + + + + + + Tunnel + + + rotation + + + + NetName + PCLK + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Tunnel + + + rotation + + + + NetName + PCLK + + + + + + Tunnel + + + rotation + + + + NetName + MMIO_IE + + + + + + Tunnel + + + rotation + + + + NetName + MMIO_OE + + + + + + Tunnel + + + rotation + + + + NetName + MMIO_S + + + + + + atk16_tpu.dig + + + + + Tunnel + + + rotation + + + + NetName + MMIO_IE + + + + + + Tunnel + + + rotation + + + + NetName + MMIO_OE + + + + + + Tunnel + + + rotation + + + + NetName + MMIO_S + + + + + + VGA + + + + + Splitter + + + Input Splitting + 6 + + + Output Splitting + 2,2,2 + + + + + + Tunnel + + + rotation + + + + NetName + PCLK + + + + + + Splitter + + + Input Splitting + 2,2,2 + + + Output Splitting + 6 + + + + + + Multiplexer + + + Selector Bits + 2 + + + Bits + 6 + + + + + + Tunnel + + + rotation + + + + NetName + GRMODE + + + + + + Const + + + Value + 0 + + + Bits + 6 + + + + + + Probe + + + intFormat + dec + + + + + + Probe + + + intFormat + dec + + + + + + atk16_vga_sync.dig + + + + + Tunnel + + + rotation + + + + NetName + DBUS + + + + + + Tunnel + + + rotation + + + + NetName + PCLK + + + + + + Tunnel + + + rotation + + + + NetName + US_RS + + + + + + Reset + + + invertOutput + false + + + + + + Or + + + + + Break + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_alu.dig b/digital-diagrams/atk16_alu.dig new file mode 100644 index 0000000..0f40f94 --- /dev/null +++ b/digital-diagrams/atk16_alu.dig @@ -0,0 +1,1695 @@ + + + 2 + + + romContent + + + + + + Width + 5 + + + + + Add + + + Label + PLUS + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + A + + + + + + Tunnel + + + rotation + + + + NetName + B + + + + + + Ground + + + + + Tunnel + + + NetName + Y + + + + + + Tunnel + + + NetName + FC + + + + + + Driver + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + S0 + + + + + + Driver + + + + + Tunnel + + + rotation + + + + NetName + S0 + + + + + + atk16_alu_fo.dig + + + Label + Overflow flag + + + + + + Tunnel + + + rotation + + + + NetName + A + + + + + + Tunnel + + + rotation + + + + NetName + B + + + + + + Ground + + + + + Tunnel + + + NetName + Y + + + + + + Tunnel + + + NetName + FC + + + + + + Driver + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + S1 + + + + + + Driver + + + + + Tunnel + + + rotation + + + + NetName + S1 + + + + + + Sub + + + Label + MINUS + + + Bits + 16 + + + + + + And + + + Bits + 16 + + + + + + Text + + + Description + AND + + + + + + Tunnel + + + rotation + + + + NetName + A + + + + + + Tunnel + + + rotation + + + + NetName + B + + + + + + Driver + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + S2 + + + + + + Tunnel + + + NetName + Y + + + + + + Or + + + Bits + 16 + + + + + + Text + + + Description + OR + + + + + + Tunnel + + + rotation + + + + NetName + A + + + + + + Tunnel + + + rotation + + + + NetName + B + + + + + + Driver + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + S3 + + + + + + Tunnel + + + NetName + Y + + + + + + XOr + + + Bits + 16 + + + + + + Text + + + Description + XOR + + + + + + Tunnel + + + rotation + + + + NetName + A + + + + + + Tunnel + + + rotation + + + + NetName + B + + + + + + Driver + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + S4 + + + + + + Tunnel + + + NetName + Y + + + + + + BarrelShifter + + + Label + LOG SHIFT RIGHT + + + Bits + 16 + + + direction + right + + + + + + Tunnel + + + rotation + + + + NetName + A + + + + + + Tunnel + + + rotation + + + + NetName + B_L5 + + + + + + Driver + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + S5 + + + + + + Tunnel + + + NetName + Y + + + + + + BarrelShifter + + + Label + ARI SHIFT RIGHT + + + Bits + 16 + + + barrelShifterMode + arithmetic + + + direction + right + + + + + + Tunnel + + + rotation + + + + NetName + A + + + + + + Driver + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + S6 + + + + + + Tunnel + + + NetName + Y + + + + + + BarrelShifter + + + Label + LOG SHIFT LEFT + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + A + + + + + + Driver + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + S7 + + + + + + Tunnel + + + NetName + Y + + + + + + Tunnel + + + rotation + + + + NetName + B_L5 + + + + + + Tunnel + + + rotation + + + + NetName + B_L5 + + + + + + Tunnel + + + rotation + + + + NetName + B15 + + + + + + Tunnel + + + rotation + + + + NetName + Y15 + + + + + + Tunnel + + + rotation + + + + NetName + A15 + + + + + + Tunnel + + + NetName + FO + + + + + + Text + + + Description + Sign flag + + + + + + Tunnel + + + rotation + + + + NetName + Y15 + + + + + + Tunnel + + + NetName + FS + + + + + + atk16_alu_fz.dig + + + Label + Zero flag + + + + + + Tunnel + + + rotation + + + + NetName + Y + + + + + + Tunnel + + + NetName + FZ + + + + + + Tunnel + + + rotation + + + + NetName + S1 + + + + + + Testcase + + + Label + PLUS test + + + Testdata + + A B S FLAGS Y +0x1 0x2 0 0b0000 0x3 +0xff 0x1 0 0b0000 0x100 +0x1 0xffff 0 0b0101 0x0 +0x4000 0x4000 0 0b1010 0x8000 + + + + + + + Testcase + + + Label + MINUS test + + + Testdata + + A B S FLAGS Y +0x10 0x1 1 0b0000 0xF +0x1 0x0 1 0b0000 0x1 +0x0 0x1 1 0b1001 0xFFFF +0x8000 0x1 1 0b0010 0x7FFF + + + + + + + In + + + Description + LHS of binary ALU operation + + + Label + A + + + Bits + 16 + + + + + + In + + + Description + RHS of binary ALU operation + + + Label + B + + + Bits + 16 + + + + + + In + + + Description + ALU operation code + + + Label + S + + + Bits + 3 + + + + + + Text + + + Description + S Y +0 A + B +1 A - B +2 A and B +3 A or B +4 A xor B +5 A >> B # logical +6 A >>> B # arithmetic +7 A << B + + + + + + Decoder + + + Selector Bits + 3 + + + flipSelPos + true + + + + + + Tunnel + + + NetName + S0 + + + + + + Tunnel + + + NetName + S1 + + + + + + Tunnel + + + NetName + S2 + + + + + + Tunnel + + + NetName + S3 + + + + + + Tunnel + + + NetName + S4 + + + + + + Tunnel + + + NetName + S5 + + + + + + Tunnel + + + NetName + S6 + + + + + + Tunnel + + + NetName + S7 + + + + + + Tunnel + + + rotation + + + + NetName + A + + + + + + Splitter + + + Input Splitting + 16 + + + Output Splitting + 15,1 + + + + + + Tunnel + + + rotation + + + + NetName + B + + + + + + Splitter + + + Input Splitting + 16 + + + Output Splitting + 15,1 + + + + + + Splitter + + + Input Splitting + 16 + + + Output Splitting + 5 + + + + + + Tunnel + + + NetName + B_L5 + + + + + + Tunnel + + + NetName + A15 + + + + + + Tunnel + + + NetName + B15 + + + + + + Splitter + + + Input Splitting + 16 + + + Output Splitting + 15,1 + + + + + + Tunnel + + + rotation + + + + NetName + Y + + + + + + Tunnel + + + NetName + Y15 + + + + + + Out + + + Description + Output + + + Label + Y + + + Bits + 16 + + + + + + Splitter + + + Input Splitting + 1*4 + + + Output Splitting + 4 + + + + + + Out + + + Label + FLAGS + + + Bits + 4 + + + + + + Tunnel + + + rotation + + + + NetName + FO + + + + + + Tunnel + + + rotation + + + + NetName + FZ + + + + + + Tunnel + + + rotation + + + + NetName + FS + + + + + + Tunnel + + + rotation + + + + NetName + FC + + + + + + PullDown + + + rotation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_alu_carryfix.dig b/digital-diagrams/atk16_alu_carryfix.dig new file mode 100644 index 0000000..1c22602 --- /dev/null +++ b/digital-diagrams/atk16_alu_carryfix.dig @@ -0,0 +1,270 @@ + + + 2 + + + + Out + + + Label + Y + + + Inputs + 1 + + + + + + Or + + + wideShape + true + + + + + + And + + + wideShape + true + + + Inputs + 3 + + + + + + And + + + wideShape + true + + + Inputs + 3 + + + + + + In + + + rotation + + + + Label + S2 + + + + + + Not + + + rotation + + + + + + + In + + + rotation + + + + Label + S1 + + + + + + Not + + + rotation + + + + + + + In + + + rotation + + + + Label + S0 + + + + + + Not + + + rotation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_alu_fo.dig b/digital-diagrams/atk16_alu_fo.dig new file mode 100644 index 0000000..ecf0021 --- /dev/null +++ b/digital-diagrams/atk16_alu_fo.dig @@ -0,0 +1,494 @@ + + + 2 + + + Label + alu_fo + + + romContent + + + + + + Width + 4 + + + + + Testcase + + + Testdata + + A15 B15 Y15 ~A/S FO +0 0 0 0 0 +0 0 1 0 1 +0 1 0 0 0 +0 1 1 0 0 +1 0 0 0 0 +1 0 1 0 0 +1 1 0 0 1 +1 1 1 0 0 +0 0 0 1 0 +0 0 1 1 0 +0 1 0 1 0 +0 1 1 1 1 +1 0 0 1 1 +1 0 1 1 0 +1 1 0 1 0 +1 1 1 1 0 + + + + + + + + Out + + + Label + FO + + + Inputs + 1 + + + + + + Or + + + wideShape + true + + + Inputs + 4 + + + + + + And + + + wideShape + true + + + Inputs + 4 + + + + + + And + + + wideShape + true + + + Inputs + 4 + + + + + + And + + + wideShape + true + + + Inputs + 4 + + + + + + And + + + wideShape + true + + + Inputs + 4 + + + + + + In + + + rotation + + + + Label + ~A/S + + + + + + Not + + + rotation + + + + + + + In + + + rotation + + + + Label + A15 + + + + + + Not + + + rotation + + + + + + + In + + + rotation + + + + Label + B15 + + + + + + Not + + + rotation + + + + + + + In + + + rotation + + + + Label + Y15 + + + + + + Not + + + rotation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_alu_fz.dig b/digital-diagrams/atk16_alu_fz.dig new file mode 100644 index 0000000..2da652a --- /dev/null +++ b/digital-diagrams/atk16_alu_fz.dig @@ -0,0 +1,192 @@ + + + 2 + + + Label + alu_fz + + + romContent + + + + + + + + In + + + Label + Y + + + Bits + 16 + + + + + + Splitter + + + Input Splitting + 16 + + + Output Splitting + 4*4 + + + + + + Splitter + + + Input Splitting + 4 + + + Output Splitting + 1*4 + + + + + + Out + + + Label + FZ + + + + + + Testcase + + + Testdata + + Y FZ +0x0 1 +0x1 0 +0xff 0 + + + + + + + NOr + + + Inputs + 4 + + + + + + Or + + + Bits + 4 + + + Inputs + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_alu_inputs.dig b/digital-diagrams/atk16_alu_inputs.dig new file mode 100644 index 0000000..310bafb --- /dev/null +++ b/digital-diagrams/atk16_alu_inputs.dig @@ -0,0 +1,215 @@ + + + 2 + + + Description + Maps the R1 input to the A output. Uses OPCODE parity to mux either the R2 input (even parity) or the RW_S input, here acting as a small immediate value, to the B output. + + + romContent + + + + + + Width + 5 + + + + + In + + + Description + Register 1 value from regbank + + + Label + R1 + + + Bits + 16 + + + + + + In + + + Description + Register 2 value from regbank + + + Label + R2 + + + Bits + 16 + + + + + + Multiplexer + + + Bits + 16 + + + + + + In + + + Description + Register 2 selector + + + Label + R2_S + + + Bits + 3 + + + + + + In + + + Description + Immediate mode on? + + + Label + IM_M + + + + + + Out + + + Description + Output A + + + Label + A + + + Bits + 16 + + + + + + Out + + + Description + Output B + + + Label + B + + + Bits + 16 + + + + + + Splitter + + + Input Splitting + 3,13 + + + Output Splitting + 16 + + + + + + Ground + + + Bits + 13 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_decoder.dig b/digital-diagrams/atk16_decoder.dig new file mode 100644 index 0000000..b8eb088 --- /dev/null +++ b/digital-diagrams/atk16_decoder.dig @@ -0,0 +1,364 @@ + + + 2 + + + romContent + + + + + + Width + 5 + + + + + Register + + + valueIsProbe + true + + + Label + IR + + + Bits + 16 + + + + + + In + + + Label + DBUS + + + Bits + 16 + + + isHighZ + true + + + + + + In + + + Description + Instruction register input enable + + + Label + IR_IE + + + + + + In + + + Label + CLK + + + + + + Splitter + + + splitterSpreading + 2 + + + Input Splitting + 16 + + + Output Splitting + 3,3,3,3,4 + + + + + + Tunnel + + + NetName + DBUS + + + + + + Tunnel + + + rotation + + + + NetName + DBUS + + + + + + Out + + + Description + Opcode + + + Label + OP + + + Bits + 4 + + + + + + Out + + + Description + Write register selection + + + Label + RW_S + + + Bits + 3 + + + + + + Out + + + Description + ALU selection code + + + Label + ALU_S + + + Bits + 3 + + + + + + Out + + + Description + Read register 1 selection + + + Label + R1_S + + + Bits + 3 + + + + + + Out + + + Description + Read register 2 selection + + + Label + R2_S + + + Bits + 3 + + + + + + Splitter + + + Input Splitting + 16 + + + Output Splitting + 9, + + + + + + Driver + + + Bits + 16 + + + flipSelPos + true + + + + + + Tunnel + + + NetName + DBUS + + + + + + In + + + Description + Low 9 bits immediate value output enable + + + Label + LI_OE + + + + + + Testcase + + + Testdata + + CLK DBUS IR_IE LI_OE OP RW_S R1_S R2_S ALU_S +C 0b0000001010011000 1 0 0 1 2 3 0 + + + + + + + BitExtender + + + inputBits + 9 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_graphics_mode.dig b/digital-diagrams/atk16_graphics_mode.dig new file mode 100644 index 0000000..2d05dd6 --- /dev/null +++ b/digital-diagrams/atk16_graphics_mode.dig @@ -0,0 +1,311 @@ + + + 2 + + + romContent + + + + + + Width + 5 + + + + + In + + + Label + DBUS + + + Bits + 16 + + + + + + Out + + + Description + 00 disabled +01 text mode +10 sprite mode +11 undefined + + + Label + MODE + + + Bits + 2 + + + + + + Register + + + Label + GRAPHICS MODE + + + Bits + 2 + + + + + + And + + + Inputs + 13 + + + + + + Splitter + + + Input Splitting + 13 + + + Output Splitting + 1*13 + + + + + + And + + + + + Splitter + + + Input Splitting + 16 + + + Output Splitting + 2,14 + + + + + + In + + + Label + MMIO_S + + + Bits + 13 + + + + + + In + + + Label + MMIO_IE + + + + + + Const + + + Value + 2 + + + Bits + 13 + + + + + + XNOr + + + Bits + 13 + + + + + + In + + + Label + CLK + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_irc.dig b/digital-diagrams/atk16_irc.dig new file mode 100644 index 0000000..0037fa0 --- /dev/null +++ b/digital-diagrams/atk16_irc.dig @@ -0,0 +1,341 @@ + + + 2 + + + romContent + + + + + + Width + 5 + + + + + In + + + Description + IRQ lines + + + Label + IRQ + + + Bits + 4 + + + + + + In + + + Description + PC value + + + Label + PC + + + Bits + 16 + + + + + + Splitter + + + Input Splitting + 4 + + + Output Splitting + 1*4 + + + + + + Text + + + Description + Some IRQ active? + + + + + + In + + + Label + MAR_IE + + + + + + And + + + + + Multiplexer + + + Bits + 16 + + + + + + Out + + + Label + DBUS + + + Bits + 16 + + + + + + Driver + + + Bits + 16 + + + flipSelPos + true + + + + + + In + + + Label + PC_OE + + + + + + PriorityEncoder + + + Selector Bits + 2 + + + + + + Const + + + Value + 17 + + + Bits + 16 + + + + + + Multiplexer + + + Selector Bits + 2 + + + Bits + 16 + + + + + + Const + + + Value + 16 + + + Bits + 16 + + + + + + Const + + + Value + 18 + + + Bits + 16 + + + + + + Const + + + Value + 19 + + + Bits + 16 + + + + + + Testcase + + + Testdata + + IRQ PC MAR_IE PC_OE DBUS +0b0000 0x5 0 0 Z +0b0000 0x5 0 1 0x5 +0b0001 0x5 0 1 0x5 +0b0001 0x5 1 1 0x10 +0b0101 0x5 1 1 0x12 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_jump_unit.dig b/digital-diagrams/atk16_jump_unit.dig new file mode 100644 index 0000000..4ccd266 --- /dev/null +++ b/digital-diagrams/atk16_jump_unit.dig @@ -0,0 +1,193 @@ + + + 2 + + + Description + Uses OPCODE parity to choose between relative addressing mode (even parity) or absolute addressing mode (odd parity). + + + romContent + + + + + + Width + 5 + + + + + In + + + Description + Jump address + + + Label + ADDR + + + Bits + 16 + + + + + + In + + + Description + PC value + + + Label + PC + + + Bits + 16 + + + + + + In + + + Description + Immediate mode on? + + + Label + IM_M + + + + + + Out + + + Description + Result PC value + + + Label + PC_RES + + + Bits + 16 + + + + + + Add + + + Bits + 16 + + + + + + Multiplexer + + + Bits + 16 + + + + + + Ground + + + + + Testcase + + + Testdata + + PC ADDR IM_M PC_RES +10 20 0 20 +10 20 1 30 + + + + + + + Not + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_mem.dig b/digital-diagrams/atk16_mem.dig new file mode 100644 index 0000000..6ff9810 --- /dev/null +++ b/digital-diagrams/atk16_mem.dig @@ -0,0 +1,949 @@ + + 2 + + + romContent + + + + + + Width + 7 + + + + + EEPROM + + + AddrBits + 15 + + + isProgramMemory + true + + + Label + MEM_ROM + + + Bits + 16 + + + Data + 4014,2e00,1dc0,6026,8000,8000,8000,8000,8000,8000,8000,8000,8000,8000,8000,8000,001b,001a,001a,001a,8000,e000,e001,e002,e800,f800,f000,31c0,1fc8,31c8,1fc8,4016,2000,2000,4215,2240,3040,1fc9,23c0,1fc9,21c0,e000,4017,2000,4200,3008,600d,0008,0000,0001,0002,0017,0019,9000,0100,0031,0061,0062,0063,0032,402f,2000,0fc0,4433,2480,31d0,1fc8,1fc9,25c0,2480,31d0,1fc8,1fc9,21c0,4200,0270,3040,4434,2480,31d0,1fc8,1fc9,25c0,2480,31d0,1fc8,1fc9,21c0,4201,0270,3040,4000,0180,2000,31c0,1fc8,4031,2000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,4035,2000,31c0,1fc8,4000,31c0,1fc8,1fc9,23c0,1fc9,21c0,0008,31c0,1fc8,4037,2000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,4035,2000,31c0,1fc8,4001,31c0,1fc8,1fc9,23c0,1fc9,21c0,0008,31c0,1fc8,4038,2000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,4035,2000,31c0,1fc8,4002,31c0,1fc8,1fc9,23c0,1fc9,21c0,0008,31c0,1fc8,4039,2000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,4035,2000,31c0,1fc8,4003,31c0,1fc8,1fc9,23c0,1fc9,21c0,0008,31c0,1fc8,403a,2000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,4035,2000,31c0,1fc8,4004,31c0,1fc8,1fc9,23c0,1fc9,21c0,0008,31c0,1fc8,403b,2000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,4035,2000,31c0,1fc8,4005,31c0,1fc8,1fc9,23c0,1fc9,21c0,0008,31c0,1fc8,4000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,4435,2480,31d0,1fc8,1fc9,21c0,4202,0270,3040,4400,31d0,1fc8,1fc9,21c0,4203,0270,3040,4402,0590,2480,31d0,1fc8,1fc9,25c0,2480,31d0,1fc8,1fc9,21c0,4204,0270,3040,4400,31d0,1fc8,1fc9,21c0,4205,0270,3040,4201,31c8,1fc8,1fc9,21c0,1000,8451,4435,2480,31d0,1fc8,4403,0590,2480,31d0,1fc8,1fc9,27c0,1fc9,25c0,0498,31d0,1fc8,1fc9,21c0,4206,0270,3040,4406,0590,2480,31d0,1fc8,1fc9,25c0,2480,31d0,1fc8,1fc9,21c0,4207,0270,3040,4007,0180,2000,31c0,1fc8,4000,31c0,1fc8,1fc9,21c0,1000,8402,6020,6000,4407,0590,2480,31d0,1fc8,1fc9,21c0,4205,0270,3040,4403,0590,2480,31d0,1fc8,4401,31d0,1fc8,1fc9,27c0,1fc9,25c0,0498,31d0,1fc8,1fc9,21c0,4203,0270,3040,61a8,4001,0180,2000,31c0,1fc8,4000,31c0,1fc8,1fc9,23c0,1fc9,21c0,0008,31c0,1fc8,4004,0180,2000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,4001,0180,2000,31c0,1fc8,4001,31c0,1fc8,1fc9,23c0,1fc9,21c0,0008,31c0,1fc8,4005,0180,2000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,1f80,f000 + + + + + + Ground + + + rotation + + + + + + + VDD + + + rotation + + + + + + + VDD + + + rotation + + + + + + + In + + + Description + Address + + + Label + ADDR + + + Bits + 16 + + + + + + Splitter + + + Input Splitting + 16 + + + Output Splitting + 13,1,1,1 + + + + + + atk16_mem_mux.dig + + + + + Splitter + + + Input Splitting + 13,1,1 + + + Output Splitting + 15 + + + + + + Splitter + + + Input Splitting + 1,1 + + + Output Splitting + 2 + + + + + + Demultiplexer + + + Selector Bits + 2 + + + Bits + 15 + + + + + + Probe + + + Label + ROM_OUT + + + + + + Driver + + + Bits + 16 + + + flipSelPos + true + + + + + + Demultiplexer + + + Selector Bits + 2 + + + flipSelPos + true + + + + + + Tunnel + + + NetName + RAM_IE + + + + + + In + + + Description + Data bus + + + Label + DBUS + + + Bits + 16 + + + isHighZ + true + + + + + + Tunnel + + + NetName + CLK + + + + + + RAMDualPort + + + AddrBits + 15 + + + Label + MEM_RAM + + + Bits + 16 + + + + + + VDD + + + rotation + + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Tunnel + + + rotation + + + + NetName + RAM_IE + + + + + + Tunnel + + + rotation + + + + NetName + DBUS + + + + + + Probe + + + Label + RAM_OUT + + + + + + Driver + + + Bits + 16 + + + + + + In + + + Description + Clock + + + Label + CLK + + + + + + Out + + + Description + Memory-mapped I/O word input enable + + + Label + MMIO_IE + + + + + + Out + + + Description + Memory-mapped I/O word output enable + + + Label + MMIO_OE + + + + + + Tunnel + + + NetName + MMIO_S + + + + + + Testcase + + + Testdata + + CLK ADDR MEM_IE MEM_OE DBUS DBUS_out + +# read ROM +program(0xFF) +C 0x0 0 1 Z 0xFF + +# read RAM +memory MEM_RAM(0x0)=0x55; +C 0 0 0 Z X +C 0x8000 0 1 Z 0x55 + +# write to RAM +C 0x8000 1 0 0xAA 0xAA +C 0x8000 0 1 Z 0xAA + + + + + + + + In + + + Description + Memory input enable + + + Label + MEM_IE + + + + + + In + + + Description + Memory output enable + + + Label + MEM_OE + + + + + + And + + + rotation + + + + + + + Tunnel + + + NetName + RAM_OE + + + + + + Tunnel + + + NetName + MEM_OE + + + + + + Tunnel + + + NetName + MEM_OE + + + + + + Tunnel + + + NetName + DBUS + + + + + + And + + + rotation + + + + + + + Tunnel + + + NetName + ROM_OE + + + + + + Tunnel + + + NetName + MEM_OE + + + + + + Tunnel + + + NetName + DBUS + + + + + + Tunnel + + + NetName + DBUS + + + + + + Decoder + + + Selector Bits + 2 + + + flipSelPos + true + + + + + + Tunnel + + + NetName + ROM_OE + + + + + + Tunnel + + + NetName + RAM_OE + + + + + + Tunnel + + + NetName + MMIO_OE + + + + + + Tunnel + + + NetName + MMIO_IE + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + MEM_OE + + + + + + Tunnel + + + rotation + + + + NetName + MMIO_OE + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + MEM_IE + + + + + + Tunnel + + + rotation + + + + NetName + MMIO_IE + + + + + + Out + + + Description + Memory-mapped I/O word selector + + + Label + MMIO_S + + + Bits + 13 + + + + + + Tunnel + + + rotation + + + + NetName + MMIO_S + + + + + + Tunnel + + + NetName + MEM_IE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_mem_mux.dig b/digital-diagrams/atk16_mem_mux.dig new file mode 100644 index 0000000..d4be584 --- /dev/null +++ b/digital-diagrams/atk16_mem_mux.dig @@ -0,0 +1,276 @@ + + + 2 + + + + Out + + + Label + X + + + Inputs + 1 + + + + + + And + + + wideShape + true + + + Inputs + 3 + + + + + + Out + + + Label + Y + + + Inputs + 1 + + + + + + Or + + + wideShape + true + + + + + + And + + + wideShape + true + + + + + + And + + + wideShape + true + + + + + + In + + + rotation + + + + Label + C + + + + + + In + + + rotation + + + + Label + B + + + + + + Not + + + rotation + + + + + + + In + + + rotation + + + + Label + A + + + + + + Not + + + rotation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_peripherals.dig b/digital-diagrams/atk16_peripherals.dig new file mode 100644 index 0000000..c8eb7b5 --- /dev/null +++ b/digital-diagrams/atk16_peripherals.dig @@ -0,0 +1,852 @@ + + + 2 + + + romContent + + + + + + Width + 6 + + + + + Splitter + + + Input Splitting + 1*4 + + + Output Splitting + 4 + + + + + + Out + + + Label + IRQ + + + Bits + 4 + + + + + + RS_FF_AS + + + + + Tunnel + + + rotation + + + + NetName + IRQ0 + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + IM_DS + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + IM_DS + + + + + + RS_FF_AS + + + + + Tunnel + + + rotation + + + + NetName + IRQ1 + + + + + + RS_FF_AS + + + + + Tunnel + + + rotation + + + + NetName + IRQ2 + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + IM_DS + + + + + + RS_FF_AS + + + + + Tunnel + + + rotation + + + + NetName + IRQ3 + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + IM_DS + + + + + + Decoder + + + Selector Bits + 2 + + + + + + Comparator + + + Bits + 13 + + + + + + Const + + + Value + 0 + + + Bits + 13 + + + + + + And + + + + + Terminal + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Tunnel + + + rotation + + + + NetName + DBUS + + + + + + Tunnel + + + rotation + + + + NetName + IE + + + + + + Tunnel + + + rotation + + + + NetName + S + + + + + + Keyboard + + + + + Tunnel + + + NetName + IRQ0 + + + + + + Tunnel + + + NetName + DBUS + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Comparator + + + Bits + 13 + + + + + + Const + + + Bits + 13 + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + OE + + + + + + Tunnel + + + rotation + + + + NetName + S + + + + + + Ground + + + + + Tunnel + + + NetName + IRQ1 + + + + + + Ground + + + + + Tunnel + + + NetName + IRQ2 + + + + + + Ground + + + + + Tunnel + + + NetName + IRQ3 + + + + + + In + + + Label + IM_DS + + + + + + Tunnel + + + NetName + IM_DS + + + + + + In + + + Label + IT_N + + + Bits + 2 + + + + + + In + + + Label + OE + + + + + + Tunnel + + + NetName + OE + + + + + + In + + + Label + IE + + + + + + Tunnel + + + NetName + IE + + + + + + In + + + Label + S + + + Bits + 13 + + + + + + Tunnel + + + NetName + S + + + + + + In + + + Label + CLK + + + + + + Tunnel + + + NetName + CLK + + + + + + Out + + + Label + DBUS + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + DBUS + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_ppu.dig b/digital-diagrams/atk16_ppu.dig new file mode 100644 index 0000000..e6e7608 --- /dev/null +++ b/digital-diagrams/atk16_ppu.dig @@ -0,0 +1,827 @@ + + + 2 + + + romContent + + + + + + Width + 7 + + + + + RAMDualPort + + + AddrBits + 7 + + + Label + SPRITE MEM + + + Bits + 16 + + + + + + Text + + + Description + 8 bits tile pattern index +10 bits Y position +10 bits X position +1 bit H flip +1 bit V flip +1 bit behind background? (priority) +1 bit palette select += total 4 bytes per sprite +x 64 sprites += 128 words + + + + + + Text + + + Description + 2**7 selector addresses for +sprite mem, starting from 0x0800 + + + + + + In + + + Label + MMIO_IE + + + + + + In + + + Label + MMIO_OE + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + In + + + Description + MMI/O selector + + + Label + MMIO_S + + + Bits + 13 + + + + + + Tunnel + + + rotation + + + + NetName + DBUS + + + + + + Tunnel + + + rotation + + + + NetName + SMEMBUS + + + + + + Splitter + + + Input Splitting + 13 + + + Output Splitting + 11,1,1 + + + + + + And + + + inverterConfig + + In_2 + + + + + + + Tunnel + + + rotation + + + + NetName + SM_QUERY + + + + + + Ground + + + Bits + 11 + + + + + + RAMDualPort + + + AddrBits + 9 + + + Label + SCAN BUFFER + + + Bits + 4 + + + + + + Tunnel + + + rotation + + + + NetName + X + + + + + + Splitter + + + mirror + true + + + Input Splitting + 4 + + + Output Splitting + 1*4 + + + + + + atk16_ppu_palette.dig + + + + + Splitter + + + Input Splitting + 1,1 + + + Output Splitting + 2 + + + + + + Splitter + + + Input Splitting + 1,1 + + + Output Splitting + 2 + + + + + + Splitter + + + Input Splitting + 1,1 + + + Output Splitting + 2 + + + + + + Tunnel + + + NetName + PR + + + + + + Tunnel + + + NetName + PG + + + + + + Tunnel + + + NetName + PB + + + + + + Ground + + + rotation + + + + Bits + 4 + + + + + + Ground + + + rotation + + + + + + + Counter + + + + + Tunnel + + + rotation + + + + NetName + PCLK + + + + + + VDD + + + + + Ground + + + + + Text + + + Description + TODO + + + + + + Tunnel + + + rotation + + + + NetName + SMEMBUS + + + + + + Ground + + + rotation + + + + Bits + 7 + + + + + + Text + + + Description + TODO: 8x8x4 tile pattern memory + + + + + + VDD + + + rotation + + + + + + + Probe + + + Label + SCAN BUF + + + + + + Out + + + Label + PR + + + Bits + 2 + + + + + + Out + + + Label + PG + + + Bits + 2 + + + + + + Out + + + Label + PB + + + Bits + 2 + + + + + + Tunnel + + + rotation + + + + NetName + PB + + + + + + Tunnel + + + rotation + + + + NetName + PR + + + + + + Tunnel + + + rotation + + + + NetName + PG + + + + + + In + + + Description + Pixel clock + + + Label + PCLK + + + + + + Tunnel + + + NetName + PCLK + + + + + + In + + + Description + CPU clock + + + Label + CLK + + + + + + Tunnel + + + NetName + CLK + + + + + + Tunnel + + + NetName + DBUS + + + + + + In + + + Description + Data bus + + + Label + DBUS + + + Bits + 16 + + + + + + In + + + Description + X pixel + + + Label + X + + + Bits + 9 + + + + + + Tunnel + + + NetName + X + + + + + + In + + + Description + Y pixel + + + Label + Y + + + Bits + 8 + + + + + + Tunnel + + + NetName + Y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_ppu_palette.dig b/digital-diagrams/atk16_ppu_palette.dig new file mode 100644 index 0000000..40101b7 --- /dev/null +++ b/digital-diagrams/atk16_ppu_palette.dig @@ -0,0 +1,225 @@ + + + 2 + + + romContent + + + + + + Width + 6 + + + + + Out + + + Label + YR1 + + + Inputs + 1 + + + + + + Out + + + Label + YR0 + + + Inputs + 1 + + + + + + Out + + + Label + YG1 + + + Inputs + 1 + + + + + + Out + + + Label + YG0 + + + Inputs + 1 + + + + + + Out + + + Label + YB1 + + + Inputs + 1 + + + + + + Out + + + Label + YB0 + + + Inputs + 1 + + + + + + In + + + rotation + + + + Label + R0 + + + + + + In + + + rotation + + + + Label + G1 + + + + + + In + + + rotation + + + + Label + G0 + + + + + + In + + + rotation + + + + Label + B0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_ppu_sprite_eval.dig b/digital-diagrams/atk16_ppu_sprite_eval.dig new file mode 100644 index 0000000..c765847 --- /dev/null +++ b/digital-diagrams/atk16_ppu_sprite_eval.dig @@ -0,0 +1,4325 @@ + + + 2 + + + + Tunnel + + + NetName + PCLK + + + + + + Clock + + + Frequency + 20 + + + runRealTime + true + + + + + + In + + + Label + PCLK + + + + + + Rectangle + + + Label + Stage 1 Secondary Clear + + + RectHeight + 15 + + + RectWidth + 35 + + + + + + Tunnel + + + NetName + NPCLK + + + + + + Not + + + + + Break + + + + + Break + + + + + Text + + + Description + State machine & sequencer: +SQ0 transition current state if conditions match +SQ1 read from memory A +SQ2 read from memory B +SQ3 write to memory +SQ4 counter inc + +Sequencer clocked by falling edge (NPCLK) +Everything else clocked by rising edge (PCLK) + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + ST_SECCLR + + + + + + Tunnel + + + rotation + + + + NetName + OVF_SECCLR + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + ST_EVAL + + + + + + Or + + + Inputs + 3 + + + + + + And + + + Inputs + 3 + + + + + + Tunnel + + + NetName + CLK_STAGE + + + + + + Tunnel + + + rotation + + + + NetName + PCLK + + + + + + Tunnel + + + rotation + + + + NetName + SQ_TRANS + + + + + + Counter + + + Label + STAGE + + + Bits + 2 + + + + + + Decoder + + + Selector Bits + 2 + + + flipSelPos + true + + + + + + Tunnel + + + NetName + ST_SECCLR + + + + + + VDD + + + + + Tunnel + + + NetName + ST_EVAL + + + + + + Tunnel + + + NetName + ST_RENDER + + + + + + Or + + + + + Tunnel + + + rotation + + + + NetName + CLK_STAGE + + + + + + Tunnel + + + rotation + + + + NetName + RST + + + + + + Or + + + + + Tunnel + + + rotation + + + + NetName + OVF_EVAL + + + + + + Tunnel + + + rotation + + + + NetName + OVF_SMN + + + + + + Tunnel + + + NetName + STAGE + + + + + + Multiplexer + + + Selector Bits + 2 + + + + + + Tunnel + + + NetName + SEC_C + + + + + + Ground + + + rotation + + + + + + + Tunnel + + + rotation + + + + NetName + STAGE + + + + + + Tunnel + + + rotation + + + + NetName + CLK_WRITE + + + + + + Tunnel + + + rotation + + + + NetName + CLK_READA + + + + + + Multiplexer + + + Selector Bits + 2 + + + + + + Tunnel + + + NetName + SEC_str + + + + + + VDD + + + rotation + + + + + + + Ground + + + rotation + + + + + + + Multiplexer + + + Selector Bits + 2 + + + + + + Tunnel + + + NetName + SEC_ld + + + + + + VDD + + + rotation + + + + + + + Multiplexer + + + Selector Bits + 2 + + + + + + Tunnel + + + NetName + SB_C + + + + + + Ground + + + rotation + + + + + + + Ground + + + rotation + + + + + + + Tunnel + + + rotation + + + + NetName + STAGE + + + + + + Multiplexer + + + Selector Bits + 2 + + + + + + Tunnel + + + NetName + SB_str + + + + + + Multiplexer + + + Selector Bits + 2 + + + + + + Tunnel + + + NetName + SB_ld + + + + + + VDD + + + rotation + + + + + + + Counter + + + Label + SEC CLR ADDR + + + Bits + 4 + + + + + + Or + + + + + Tunnel + + + rotation + + + + NetName + RST + + + + + + Tunnel + + + rotation + + + + NetName + CLK_WRITE + + + + + + Driver + + + Bits + 3 + + + + + + Tunnel + + + NetName + SEC_A + + + + + + Tunnel + + + NetName + ST_SECCLR + + + + + + Driver + + + Bits + 32 + + + + + + Tunnel + + + NetName + ST_SECCLR + + + + + + Tunnel + + + NetName + SEC_Din + + + + + + Ground + + + Bits + 32 + + + + + + Probe + + + + + Tunnel + + + rotation + + + + NetName + ST_SECCLR + + + + + + VDD + + + rotation + + + + + + + Ground + + + rotation + + + + + + + Ground + + + rotation + + + + + + + RAMDualPort + + + AddrBits + 3 + + + Label + SECONDARY + + + Bits + 32 + + + + + + Probe + + + Label + SEC_D + + + + + + Tunnel + + + rotation + + + + NetName + SEC_ld + + + + + + Tunnel + + + rotation + + + + NetName + SEC_str + + + + + + Tunnel + + + rotation + + + + NetName + SEC_A + + + + + + Tunnel + + + rotation + + + + NetName + SEC_Din + + + + + + Tunnel + + + rotation + + + + NetName + SEC_C + + + + + + RAMDualPort + + + AddrBits + 7 + + + Label + SCAN BUFFER + + + Bits + 16 + + + + + + Probe + + + Label + SB_D + + + + + + Tunnel + + + rotation + + + + NetName + SB_A + + + + + + Tunnel + + + rotation + + + + NetName + SB_Din + + + + + + Tunnel + + + rotation + + + + NetName + SB_str + + + + + + Tunnel + + + rotation + + + + NetName + SB_C + + + + + + Tunnel + + + rotation + + + + NetName + SB_ld + + + + + + Tunnel + + + rotation + + + + NetName + SB_A + + + + + + Tunnel + + + rotation + + + + NetName + SB_Din + + + + + + Ground + + + rotation + + + + Bits + 7 + + + + + + Ground + + + rotation + + + + Bits + 16 + + + + + + Out + + + Description + Scanline buffer data + + + Label + SB_D + + + Bits + 9 + + + + + + Ground + + + Bits + 9 + + + + + + Multiplexer + + + Selector Bits + 2 + + + + + + Tunnel + + + NetName + SM_C + + + + + + Ground + + + rotation + + + + + + + Tunnel + + + rotation + + + + NetName + STAGE + + + + + + Multiplexer + + + Selector Bits + 2 + + + + + + Tunnel + + + NetName + SM_str + + + + + + Multiplexer + + + Selector Bits + 2 + + + + + + Tunnel + + + NetName + SM_ld + + + + + + VDD + + + rotation + + + + + + + Tunnel + + + NetName + ST_IDLE + + + + + + Ground + + + rotation + + + + + + + Ground + + + rotation + + + + + + + Tunnel + + + rotation + + + + NetName + CLK_READA + + + + + + Rectangle + + + RectHeight + 40 + + + Label + Stage 2 Evaluate sprites + + + RectWidth + 35 + + + + + + Counter + + + Label + SMN + + + Bits + 7 + + + + + + Probe + + + + + Or + + + + + Tunnel + + + rotation + + + + NetName + RST + + + + + + Tunnel + + + rotation + + + + NetName + CLK_WRITE + + + + + + Tunnel + + + rotation + + + + NetName + SM_D + + + + + + Splitter + + + Input Splitting + 32 + + + Output Splitting + 8,10,10,1,1,1,1 + + + + + + Sub + + + Bits + 10 + + + + + + Ground + + + + + Tunnel + + + rotation + + + + NetName + SCY + + + + + + Comparator + + + Bits + 10 + + + + + + Const + + + Value + 8 + + + Bits + 10 + + + + + + Tunnel + + + NetName + YMATCH + + + + + + Tunnel + + + NetName + OVF_SMN + + + + + + Tunnel + + + rotation + + + + NetName + ST_EVAL + + + + + + Splitter + + + Input Splitting + 7 + + + Output Splitting + 6,1 + + + + + + Tunnel + + + NetName + SM_A + + + + + + Tunnel + + + NetName + ST_SECCLR + + + + + + LED + + + rotation + + + + + + + Tunnel + + + NetName + ST_EVAL + + + + + + LED + + + rotation + + + + + + + Multiplexer + + + Selector Bits + 2 + + + + + + Tunnel + + + NetName + TM_C + + + + + + Ground + + + rotation + + + + + + + Ground + + + rotation + + + + + + + Tunnel + + + rotation + + + + NetName + STAGE + + + + + + Multiplexer + + + Selector Bits + 2 + + + + + + Tunnel + + + NetName + TM_str + + + + + + Multiplexer + + + Selector Bits + 2 + + + + + + Tunnel + + + NetName + TM_ld + + + + + + VDD + + + rotation + + + + + + + Ground + + + rotation + + + + + + + RAMDualPort + + + AddrBits + 11 + + + Label + TILE MEM + + + Bits + 32 + + + + + + Tunnel + + + rotation + + + + NetName + TM_C + + + + + + Tunnel + + + rotation + + + + NetName + TM_str + + + + + + Tunnel + + + rotation + + + + NetName + TM_ld + + + + + + Text + + + Description + Tile mem addr: +8 bits select tile +3 bits select row in tile += 11 bits total + + + + + + Tunnel + + + rotation + + + + NetName + TM_Din + + + + + + Ground + + + rotation + + + + Bits + 32 + + + + + + Probe + + + Label + TM_D + + + + + + Tunnel + + + rotation + + + + NetName + TM_A + + + + + + Tunnel + + + rotation + + + + NetName + TM_Din + + + + + + Text + + + Description + 8 bits tile pattern index +10 bits Y position +10 bits X position +1 bit H flip +1 bit V flip +1 bit behind background? (priority) +1 bit palette select += total 4 bytes per sprite +x 64 sprites += 128 words + + + + + + RAMDualPort + + + AddrBits + 6 + + + Label + SPRITE MEM H + + + Bits + 16 + + + + + + Tunnel + + + NetName + SM_D + + + + + + Tunnel + + + rotation + + + + NetName + DBUS + + + + + + Tunnel + + + rotation + + + + NetName + SM_A + + + + + + Tunnel + + + rotation + + + + NetName + SM_C + + + + + + Tunnel + + + rotation + + + + NetName + SM_ld + + + + + + Tunnel + + + rotation + + + + NetName + SM_str + + + + + + RAMDualPort + + + AddrBits + 6 + + + Label + SPRITE MEM L + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + DBUS + + + + + + Tunnel + + + rotation + + + + NetName + SM_A + + + + + + Tunnel + + + rotation + + + + NetName + SM_C + + + + + + Tunnel + + + rotation + + + + NetName + SM_ld + + + + + + Tunnel + + + rotation + + + + NetName + SM_str + + + + + + Splitter + + + Input Splitting + 16,16 + + + Output Splitting + 32 + + + + + + Probe + + + + + Counter + + + Label + Sequencer + + + Bits + 3 + + + + + + Decoder + + + Selector Bits + 3 + + + flipSelPos + true + + + + + + Tunnel + + + NetName + SQ_TRANS + + + + + + Tunnel + + + NetName + SQ_READA + + + + + + Tunnel + + + NetName + SQ_READB + + + + + + VDD + + + rotation + + + + + + + Tunnel + + + NetName + SQ_WRITE + + + + + + Or + + + + + Tunnel + + + rotation + + + + NetName + NPCLK + + + + + + Tunnel + + + rotation + + + + NetName + RST + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + SQ_READA + + + + + + Tunnel + + + rotation + + + + NetName + PCLK + + + + + + Tunnel + + + NetName + CLK_READA + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + ST_RENDER + + + + + + Tunnel + + + rotation + + + + NetName + OVF_RENDER + + + + + + Tunnel + + + NetName + SEC_D + + + + + + Splitter + + + Input Splitting + 4 + + + Output Splitting + 3,1 + + + + + + Tunnel + + + NetName + OVF_SECCLR + + + + + + Tunnel + + + NetName + SQ_CLR + + + + + + Or + + + + + Tunnel + + + rotation + + + + NetName + SQ_CLR + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + SQ_READB + + + + + + Tunnel + + + rotation + + + + NetName + PCLK + + + + + + Tunnel + + + NetName + CLK_READB + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + SQ_WRITE + + + + + + Tunnel + + + rotation + + + + NetName + PCLK + + + + + + Tunnel + + + NetName + CLK_WRITE + + + + + + Splitter + + + Input Splitting + 8,10,10,1,1,1,1 + + + Output Splitting + 32 + + + + + + Driver + + + Bits + 32 + + + + + + Tunnel + + + NetName + ST_EVAL + + + + + + Tunnel + + + NetName + SEC_Din + + + + + + In + + + Description + Scanline Y (0..524) + + + Label + SCY + + + Bits + 10 + + + + + + Tunnel + + + NetName + SCY + + + + + + In + + + Label + DBUS + + + Bits + 16 + + + + + + Tunnel + + + NetName + DBUS + + + + + + In + + + Description + Reset sprite evaluator + + + Label + RST + + + + + + Tunnel + + + NetName + RST + + + + + + And + + + Inputs + 3 + + + + + + Tunnel + + + rotation + + + + NetName + YMATCH + + + + + + Tunnel + + + rotation + + + + NetName + SQ_WRITE + + + + + + Tunnel + + + rotation + + + + NetName + PCLK + + + + + + Counter + + + Label + SEC ADDR + + + Bits + 4 + + + + + + Or + + + + + Tunnel + + + rotation + + + + NetName + RST + + + + + + Probe + + + + + Tunnel + + + NetName + OVF_EVAL + + + + + + Tunnel + + + rotation + + + + NetName + ST_EVAL + + + + + + Splitter + + + Input Splitting + 4 + + + Output Splitting + 3,1 + + + + + + Driver + + + Bits + 3 + + + + + + Tunnel + + + NetName + SEC_A + + + + + + Tunnel + + + NetName + ST_EVAL + + + + + + Rectangle + + + RectHeight + 30 + + + Label + Stage 3 Render line to scanbuf + + + RectWidth + 35 + + + + + + Tunnel + + + NetName + ST_RENDER + + + + + + LED + + + rotation + + + + + + + Counter + + + Label + SEC ADDR + + + Bits + 4 + + + + + + Probe + + + + + Tunnel + + + NetName + OVF_RENDER + + + + + + Tunnel + + + rotation + + + + NetName + ST_RENDER + + + + + + Or + + + + + Tunnel + + + rotation + + + + NetName + RST + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + SQ_READA + + + + + + Tunnel + + + rotation + + + + NetName + PCLK + + + + + + Splitter + + + Input Splitting + 4 + + + Output Splitting + 3,1 + + + + + + Driver + + + Bits + 3 + + + + + + Tunnel + + + NetName + SEC_A + + + + + + Tunnel + + + NetName + ST_RENDER + + + + + + Tunnel + + + rotation + + + + NetName + SEC_D + + + + + + Splitter + + + Input Splitting + 32 + + + Output Splitting + 8,10,10,1,1,1,1 + + + + + + Tunnel + + + NetName + ST_IDLE + + + + + + LED + + + rotation + + + + + + + Text + + + Description + Stage 4 Idle + + + + + + Tunnel + + + NetName + TM_A + + + + + + Driver + + + Bits + 11 + + + + + + Tunnel + + + NetName + ST_RENDER + + + + + + Splitter + + + Input Splitting + 3,8 + + + Output Splitting + 11 + + + + + + Splitter + + + Input Splitting + 10 + + + Output Splitting + 3,7 + + + + + + Tunnel + + + NetName + TM_D + + + + + + Tunnel + + + rotation + + + + NetName + CLK_READB + + + + + + Or + + + + + Tunnel + + + rotation + + + + NetName + CLK_WRITE + + + + + + Tunnel + + + rotation + + + + NetName + CLK_READB + + + + + + Tunnel + + + rotation + + + + NetName + SM_A + + + + + + Probe + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_regbank.dig b/digital-diagrams/atk16_regbank.dig new file mode 100644 index 0000000..5af841b --- /dev/null +++ b/digital-diagrams/atk16_regbank.dig @@ -0,0 +1,1499 @@ + + + 2 + + + romContent + + + + + + Width + 5 + + + + + In + + + Description + Data bus in + + + Label + Din + + + Bits + 16 + + + + + + Out + + + Description + Read register 1 data out + + + Label + D1 + + + Bits + 16 + + + + + + Out + + + Description + Read register 2 data out + + + Label + D2 + + + Bits + 16 + + + + + + Multiplexer + + + Selector Bits + 3 + + + Bits + 16 + + + + + + In + + + Description + Write register input enable + + + Label + RW_IE + + + + + + Multiplexer + + + Selector Bits + 3 + + + Bits + 16 + + + + + + In + + + Description + Write register select + + + Label + RW_S + + + Bits + 3 + + + + + + In + + + Description + Clock + + + Label + CLK + + + + + + In + + + Description + Read register 1 select + + + Label + R1_S + + + Bits + 3 + + + + + + Tunnel + + + NetName + Din + + + + + + Tunnel + + + NetName + RW_IE + + + + + + Register + + + valueIsProbe + true + + + Label + RA + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + Din + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Tunnel + + + NetName + Q1 + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + RW_IE + + + + + + Tunnel + + + rotation + + + + NetName + RW_A + + + + + + Register + + + valueIsProbe + true + + + Label + RB + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + Din + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Tunnel + + + NetName + Q2 + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + RW_IE + + + + + + Tunnel + + + rotation + + + + NetName + RW_B + + + + + + Register + + + valueIsProbe + true + + + Label + RC + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + Din + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Tunnel + + + NetName + Q3 + + + + + + And + + + + + Register + + + valueIsProbe + true + + + Label + RD + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + Din + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Tunnel + + + NetName + Q4 + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + RW_IE + + + + + + Tunnel + + + rotation + + + + NetName + RW_D + + + + + + Register + + + valueIsProbe + true + + + Label + RE + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + Din + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Tunnel + + + NetName + Q5 + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + RW_IE + + + + + + Tunnel + + + rotation + + + + NetName + RW_E + + + + + + Register + + + valueIsProbe + true + + + Label + RF + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + Din + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Tunnel + + + NetName + Q6 + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + RW_IE + + + + + + Tunnel + + + rotation + + + + NetName + RW_F + + + + + + Tunnel + + + rotation + + + + NetName + RW_IE + + + + + + Tunnel + + + rotation + + + + NetName + RW_C + + + + + + Decoder + + + Selector Bits + 3 + + + + + + In + + + Description + Read register 2 select + + + Label + R2_S + + + Bits + 3 + + + + + + Tunnel + + + NetName + CLK + + + + + + Testcase + + + Testdata + + CLK Din RW_IE RW_S R1_S R2_S D1 D2 +# store and read from RA works +C 0xF 1 1 0 X X X +C 0 0 0 1 X 0xF X +C 0x5 1 1 1 X 0x5 X +C 0 0 0 1 X 0x5 X + + + + + + + + Register + + + valueIsProbe + true + + + Label + RG + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + Din + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Tunnel + + + NetName + Q7 + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + RW_IE + + + + + + Tunnel + + + rotation + + + + NetName + RW_G + + + + + + Register + + + valueIsProbe + true + + + Label + RH + + + Bits + 16 + + + + + + Tunnel + + + rotation + + + + NetName + Din + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Tunnel + + + NetName + Q8 + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + RW_IE + + + + + + Tunnel + + + rotation + + + + NetName + RW_H + + + + + + Tunnel + + + NetName + RW_A + + + + + + Tunnel + + + NetName + RW_B + + + + + + Tunnel + + + NetName + RW_C + + + + + + Tunnel + + + NetName + RW_D + + + + + + Tunnel + + + NetName + RW_E + + + + + + Tunnel + + + NetName + RW_F + + + + + + Tunnel + + + NetName + RW_G + + + + + + Tunnel + + + NetName + RW_H + + + + + + Tunnel + + + rotation + + + + NetName + Q1 + + + + + + Tunnel + + + rotation + + + + NetName + Q2 + + + + + + Tunnel + + + rotation + + + + NetName + Q3 + + + + + + Tunnel + + + rotation + + + + NetName + Q4 + + + + + + Tunnel + + + rotation + + + + NetName + Q5 + + + + + + Tunnel + + + rotation + + + + NetName + Q6 + + + + + + Tunnel + + + rotation + + + + NetName + Q7 + + + + + + Tunnel + + + rotation + + + + NetName + Q8 + + + + + + Tunnel + + + rotation + + + + NetName + Q1 + + + + + + Tunnel + + + rotation + + + + NetName + Q2 + + + + + + Tunnel + + + rotation + + + + NetName + Q3 + + + + + + Tunnel + + + rotation + + + + NetName + Q4 + + + + + + Tunnel + + + rotation + + + + NetName + Q5 + + + + + + Tunnel + + + rotation + + + + NetName + Q6 + + + + + + Tunnel + + + rotation + + + + NetName + Q7 + + + + + + Tunnel + + + rotation + + + + NetName + Q8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_tpu.dig b/digital-diagrams/atk16_tpu.dig new file mode 100644 index 0000000..f6b6398 --- /dev/null +++ b/digital-diagrams/atk16_tpu.dig @@ -0,0 +1,1165 @@ + + + 2 + + + romContent + + + + + + Width + 6 + + + + + Out + + + Label + PR + + + Bits + 2 + + + + + + Out + + + Label + PG + + + Bits + 2 + + + + + + Out + + + Label + PB + + + Bits + 2 + + + + + + In + + + Label + MMIO_IE + + + + + + In + + + Label + MMIO_OE + + + + + + In + + + Description + MMI/O selector + + + Label + MMIO_S + + + Bits + 13 + + + + + + Tunnel + + + NetName + MMIO_IE + + + + + + Tunnel + + + NetName + MMIO_OE + + + + + + Tunnel + + + NetName + MMIO_S + + + + + + In + + + Description + Data bus + + + Label + DBUS + + + Bits + 16 + + + + + + In + + + Description + X pixel + + + Label + X + + + Bits + 9 + + + + + + Tunnel + + + NetName + X + + + + + + In + + + Description + Y pixel + + + Label + Y + + + Bits + 8 + + + + + + RAMDualPort + + + AddrBits + 11 + + + Label + TEXTMEM + + + Bits + 8 + + + + + + Tunnel + + + rotation + + + + NetName + Y + + + + + + Splitter + + + Input Splitting + 8 + + + Output Splitting + 3,5 + + + + + + Tunnel + + + rotation + + + + NetName + CCOLOR + + + + + + Splitter + + + Input Splitting + 1,1 + + + Output Splitting + 2 + + + + + + VDD + + + rotation + + + + + + + Tunnel + + + NetName + CHAR_S + + + + + + Tunnel + + + NetName + Y + + + + + + Tunnel + + + NetName + TY + + + + + + Tunnel + + + NetName + CY + + + + + + Probe + + + intFormat + dec + + + + + + EEPROM + + + AddrBits + 11 + + + Label + CHARMEM + + + Bits + 8 + + + Data + 8*0,7e,81,a5,81,bd,99,81,7e,7e,ff,db,ff,c3,e7,ff,7e,36,7f,7f,7f +,3e,1c,8,0,8,1c,3e,7f,3e,1c,8,0,1c,3e,1c,7f,7f,6b,8,1c,8,8,1c +,3e,7f,3e,8,1c,0,0,18,3c,3c,18,0,0,ff,ff,e7,c3,c3,e7,ff,ff,0,3c +,66,42,42,66,3c,9*0,f0,e0,f0,be,33,33,33,1e,3c,66,66,66,3c,18 +,7e,18,fc,cc,fc,c,c,e,f,7,fe,c6,fe,c6,c6,e6,67,3,18,db,3c,e7,e7 +,3c,db,18,1,7,1f,7f,1f,7,1,0,40,70,7c,7f,7c,70,40,0,18,3c,7e,18,18 +,7e,3c,18,5*66,0,66,0,fe,db,db,de,d8,d8,d8,0,7c,c6,1c,36,36,1c +,33,1e,4*0,7e,7e,7e,0,18,3c,7e,18,7e,3c,18,ff,18,3c,7e,4*18,0 +,4*18,7e,3c,18,0,0,18,30,7f,30,18,0,0,0,c,6,7f,6,c,4*0,3,3,3,7f +,0,0,0,24,66,ff,66,24,0,0,0,18,3c,7e,ff,ff,0,0,0,ff,ff,7e,3c,18 +,10*0,c,1e,1e,c,c,0,c,0,36,36,36,5*0,36,36,7f,36,7f,36,36,0,c +,3e,3,1e,30,1f,c,0,0,63,33,18,c,66,63,0,1c,36,1c,6e,3b,33,6e,0 +,6,6,3,5*0,18,c,6,6,6,c,18,0,6,c,18,18,18,c,6,0,0,66,3c,ff,3c +,66,0,0,0,c,c,3f,c,c,7*0,c,c,6,0,0,0,3f,9*0,c,c,0,60,30,18,c,6 +,3,1,0,3e,63,73,7b,6f,67,3e,0,c,e,4*c,3f,0,1e,33,30,1c,6,33,3f +,0,1e,33,30,1c,30,33,1e,0,38,3c,36,33,7f,30,78,0,3f,3,1f,30,30 +,33,1e,0,1c,6,3,1f,33,33,1e,0,3f,33,30,18,c,c,c,0,1e,33,33,1e +,33,33,1e,0,1e,33,33,3e,30,18,e,0,0,c,c,0,0,c,c,0,0,c,c,0,0,c,c +,6,18,c,6,3,6,c,18,0,0,0,3f,0,0,3f,0,0,6,c,18,30,18,c,6,0,1e,33 +,30,18,c,0,c,0,3e,63,7b,7b,7b,3,1e,0,c,1e,33,33,3f,33,33,0,3f +,66,66,3e,66,66,3f,0,3c,66,3,3,3,66,3c,0,1f,36,66,66,66,36,1f +,0,7f,46,16,1e,16,46,7f,0,7f,46,16,1e,16,6,f,0,3c,66,3,3,73,66 +,7c,0,33,33,33,3f,33,33,33,0,1e,5*c,1e,0,78,30,30,30,33,33,1e +,0,67,66,36,1e,36,66,67,0,f,6,6,6,46,66,7f,0,63,77,7f,7f,6b,63,63 +,0,63,67,6f,7b,73,63,63,0,1c,36,63,63,63,36,1c,0,3f,66,66,3e,6,6 +,f,0,1e,33,33,33,3b,1e,38,0,3f,66,66,3e,36,66,67,0,1e,33,6,c,18 +,33,1e,0,3f,2d,4*c,1e,0,6*33,3f,0,5*33,1e,c,0,63,63,63,6b,7f,77 +,63,0,63,63,36,1c,1c,36,63,0,33,33,33,1e,c,c,1e,0,7f,63,31,18 +,4c,66,7f,0,1e,5*6,1e,0,3,6,c,18,30,60,40,0,1e,5*18,1e,0,8,1c +,36,63,11*0,ff,c,c,18,7*0,1e,30,3e,33,6e,0,7,6,6,3e,66,66,3b,0,0,0 +,1e,33,3,33,1e,0,38,30,30,3e,33,33,6e,0,0,0,1e,33,3f,3,1e,0,1c +,36,6,f,6,6,f,0,0,0,6e,33,33,3e,30,1f,7,6,36,6e,66,66,67,0,c,0 +,e,c,c,c,1e,0,30,0,30,30,30,33,33,1e,7,6,66,36,1e,36,67,0,e,5*c +,1e,0,0,0,33,7f,7f,6b,63,0,0,0,1f,4*33,0,0,0,1e,33,33,33,1e,0,0,0 +,3b,66,66,3e,6,f,0,0,6e,33,33,3e,30,78,0,0,3b,6e,66,6,f,0,0,0 +,3e,3,1e,30,1f,0,8,c,3e,c,c,2c,18,0,0,0,4*33,6e,0,0,0,33,33,33 +,1e,c,0,0,0,63,6b,7f,7f,36,0,0,0,63,36,1c,36,63,0,0,0,33,33,33 +,3e,30,1f,0,0,3f,19,c,26,3f,0,38,c,c,7,c,c,38,0,18,18,18,0,18,18,18 +,0,7,c,c,38,c,c,7,0,6e,3b,7*0,8,1c,36,63,63,7f,0,0,fe,4*82,fe +,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0 +,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe +,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82 +,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe +,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0 +,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe +,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82 +,fe,0,0,fe,4*82,fe,9*0,18,18,0,4*18,0,18,18,7e,3,3,7e,18,18,1c +,36,26,f,6,67,3f,0,0,fe,4*82,fe,0,33,33,1e,3f,c,3f,c,c,0,fe,4*82 +,fe,0,7c,c6,1c,36,36,1c,33,1e,0,fe,4*82,fe,0,0,fe,4*82,fe,0,3c +,36,36,7c,0,7e,0,0,0,cc,66,33,66,cc,5*0,3f,30,30,0,0,0,fe,4*82 +,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,1c,36,36,1c,4*0,c,c,3f,c,c +,0,3f,0,e,18,c,6,1e,4*0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,4*66,3e +,6,3,fe,db,db,de,d8,d8,d8,5*0,18,4*0,fe,4*82,fe,0,0,fe,4*82,fe +,0,1c,36,36,1c,0,3e,0,0,0,33,66,cc,66,33,0,0,c3,63,33,db,ec,f6 +,f3,c0,c3,63,33,7b,cc,66,33,f0,0,fe,4*82,fe,0,c,0,c,6,3,33,1e +,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0 +,63,1c,36,63,7f,63,63,0,c,c,0,1e,33,3f,33,0,7c,36,33,7f,33,33 +,73,0,1e,33,3,33,1e,18,30,1e,0,fe,4*82,fe,0,38,0,3f,6,1e,6,3f +,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0 +,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,3f,0,33,37,3f,3b,33 +,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0 +,c3,18,3c,66,66,3c,18,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82 +,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,33,0,4*33,1e,0,0,fe,4*82,fe +,0,0,fe,4*82,fe,0,0,1e,33,1f,33,1f,3,3,7,0,1e,30,3e,33,7e,0,38 +,0,1e,30,3e,33,7e,0,7e,c3,3c,60,7c,66,fc,0,0,fe,4*82,fe,0,33,0 +,1e,30,3e,33,7e,0,c,c,1e,30,3e,33,7e,0,0,0,fe,30,fe,33,fe,0,0,0 +,1e,3,3,1e,30,1c,7,0,1e,33,3f,3,1e,0,38,0,1e,33,3f,3,1e,0,7e,c3 +,3c,66,7e,6,3c,0,33,0,1e,33,3f,3,1e,0,7,0,e,c,c,c,1e,0,1c,0,e +,c,c,c,1e,0,3e,63,1c,18,18,18,3c,0,33,0,e,c,c,c,1e,0,0,fe,4*82 +,fe,0,0,1f,0,1f,33,33,33,0,0,7,0,1e,33,33,1e,0,0,38,0,1e,33,33 +,1e,0,1e,33,0,1e,33,33,1e,0,0,fe,4*82,fe,0,0,33,0,1e,33,33,1e +,0,c,c,0,3f,0,c,c,0,0,fe,4*82,fe,0,0,7,0,33,33,33,7e,0,0,38,0 +,33,33,33,7e,0,1e,33,0,33,33,33,7e,0,0,33,0,33,33,33,7e,0,0,fe +,4*82,fe,0,0,fe,4*82,fe,0,0,33,0,33,33,3e,30,1f + + + intFormat + bin + + + + + + Ground + + + rotation + + + + + + + VDD + + + rotation + + + + + + + VDD + + + rotation + + + + + + + Splitter + + + Input Splitting + 3,8 + + + Output Splitting + 11 + + + + + + Tunnel + + + rotation + + + + NetName + CHAR_S + + + + + + Tunnel + + + rotation + + + + NetName + CY + + + + + + BitSelector + + + Selector Bits + 3 + + + + + + Tunnel + + + NetName + CX + + + + + + Tunnel + + + NetName + CCOLOR + + + + + + Probe + + + intFormat + bin + + + + + + Probe + + + + + Probe + + + + + Multiplexer + + + Bits + 11 + + + + + + Tunnel + + + rotation + + + + NetName + TY + + + + + + And + + + Inputs + 3 + + + + + + Splitter + + + Input Splitting + 13 + + + Output Splitting + 11,1,1 + + + + + + Tunnel + + + rotation + + + + NetName + MMIO_S + + + + + + Tunnel + + + NetName + MMIOADDR + + + + + + Tunnel + + + rotation + + + + NetName + MMIOADDR + + + + + + Tunnel + + + rotation + + + + NetName + MMIOMATCH + + + + + + Tunnel + + + rotation + + + + NetName + DBUS_L8 + + + + + + Splitter + + + Input Splitting + 16 + + + Output Splitting + 8,8 + + + + + + Tunnel + + + NetName + DBUS_L8 + + + + + + Tunnel + + + NetName + MMIOMATCH + + + + + + Tunnel + + + rotation + + + + NetName + MMIO_IE + + + + + + Counter + + + Label + CLK divider /4 + + + + + + VDD + + + rotation + + + + + + + Ground + + + + + In + + + Description + Pixel clock + + + Label + PCLK + + + + + + Tunnel + + + NetName + CLK + + + + + + Tunnel + + + rotation + + + + NetName + X + + + + + + Splitter + + + Input Splitting + 9 + + + Output Splitting + 3,6 + + + + + + Tunnel + + + NetName + TX + + + + + + Tunnel + + + NetName + CX + + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + + + + Tunnel + + + rotation + + + + NetName + TX + + + + + + Splitter + + + Input Splitting + 6,5 + + + Output Splitting + 11 + + + + + + VDD + + + rotation + + + + Bits + 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_ucode_addr.dig b/digital-diagrams/atk16_ucode_addr.dig new file mode 100644 index 0000000..682c90e --- /dev/null +++ b/digital-diagrams/atk16_ucode_addr.dig @@ -0,0 +1,741 @@ + + + 2 + + + romContent + + + + + + Width + 6 + + + + + In + + + Description + Flag selector from instruction + + + Label + FLAG_S + + + Bits + 3 + + + + + + In + + + Description + Flag register output value + + + Label + FR_Q + + + Bits + 4 + + + + + + In + + + Description + OPCODE + + + Label + OP + + + Bits + 4 + + + + + + Tunnel + + + NetName + OP + + + + + + Tunnel + + + NetName + FLAG_S + + + + + + Tunnel + + + NetName + FR_Q + + + + + + In + + + Description + Microsequencer value + + + Label + US_Q + + + Bits + 3 + + + + + + Tunnel + + + NetName + US_Q + + + + + + In + + + Description + Interrupt request bus + + + Label + IRQ + + + Bits + 4 + + + + + + PriorityEncoder + + + Selector Bits + 2 + + + Label + Interrupts + + + + + + Splitter + + + Input Splitting + 4 + + + Output Splitting + 1*4 + + + + + + Multiplexer + + + Bits + 5 + + + + + + Splitter + + + Input Splitting + 3,5 + + + + + + Tunnel + + + rotation + + + + NetName + US_Q + + + + + + Out + + + Label + ADDR + + + Bits + 8 + + + + + + And + + + + + Tunnel + + + rotation + + + + NetName + OP + + + + + + Splitter + + + Input Splitting + 1,4 + + + Output Splitting + 5 + + + + + + Tunnel + + + rotation + + + + NetName + FC + + + + + + Splitter + + + Input Splitting + 2,3 + + + Output Splitting + 5 + + + + + + BitSelector + + + Selector Bits + 2 + + + + + + Tunnel + + + rotation + + + + NetName + FLAG_S + + + + + + Splitter + + + rotation + + + + Input Splitting + 3 + + + Output Splitting + 2, + + + + + + Tunnel + + + rotation + + + + NetName + FR_Q + + + + + + Tunnel + + + NetName + FC + + + + + + Out + + + Description + Interrupt number + + + rotation + + + + Label + IT_N + + + Bits + 2 + + + + + + Out + + + Label + INT_ACTIVE + + + + + + In + + + Description + Interrupt mask assert active + + + Label + IM_EN + + + + + + In + + + Description + Interrupt mask assert not active + + + Label + IM_DS + + + + + + RS_FF_AS + + + valueIsProbe + true + + + Label + INT MASK + + + + + + D_FF + + + + + Comparator + + + Bits + 3 + + + + + + Const + + + Value + 0 + + + Bits + 3 + + + + + + Tunnel + + + rotation + + + + NetName + US_Q + + + + + + Const + + + Value + 6 + + + Bits + 3 + + + intFormat + bin + + + + + + Register + + + Label + INT LINE + + + Bits + 2 + + + + + + VDD + + + rotation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-diagrams/atk16_vga_sync.dig b/digital-diagrams/atk16_vga_sync.dig new file mode 100644 index 0000000..7d42dea --- /dev/null +++ b/digital-diagrams/atk16_vga_sync.dig @@ -0,0 +1,999 @@ + + + 2 + + + romContent + + + + + + Width + 7 + + + + + Comparator + + + Bits + 10 + + + + + + Const + + + Value + 798 + + + Bits + 10 + + + intFormat + dec + + + + + + Counter + + + Bits + 10 + + + + + + VDD + + + rotation + + + + + + + Comparator + + + Bits + 10 + + + + + + Const + + + Value + 113 + + + Bits + 10 + + + intFormat + dec + + + + + + Comparator + + + Bits + 10 + + + + + + Const + + + Value + 16 + + + Bits + 10 + + + intFormat + dec + + + + + + NAnd + + + + + Tunnel + + + NetName + HSYNC + + + + + + Const + + + Value + 160 + + + Bits + 10 + + + intFormat + dec + + + + + + Sub + + + Bits + 10 + + + + + + Ground + + + + + Comparator + + + Bits + 10 + + + + + + Const + + + Value + 523 + + + Bits + 10 + + + intFormat + dec + + + + + + Counter + + + Bits + 10 + + + + + + VDD + + + rotation + + + + + + + Comparator + + + Bits + 10 + + + + + + Const + + + Value + 10 + + + Bits + 10 + + + intFormat + dec + + + + + + Comparator + + + Bits + 10 + + + + + + Const + + + Value + 13 + + + Bits + 10 + + + intFormat + dec + + + + + + Tunnel + + + NetName + VSYNC + + + + + + NAnd + + + + + Const + + + Value + 45 + + + Bits + 10 + + + intFormat + dec + + + + + + Sub + + + Bits + 10 + + + + + + Ground + + + + + Splitter + + + Input Splitting + 10 + + + Output Splitting + 1,8,1 + + + + + + Splitter + + + Input Splitting + 10 + + + Output Splitting + 1,9 + + + + + + Text + + + Description + Div 2 + + + + + + Text + + + Description + Div 2 + + + + + + In + + + Label + PCLK + + + + + + Probe + + + intFormat + dec + + + + + + Probe + + + intFormat + dec + + + + + + Out + + + Label + HSYNC + + + + + + Out + + + Label + VSYNC + + + + + + Tunnel + + + rotation + + + + NetName + HSYNC + + + + + + Tunnel + + + rotation + + + + NetName + VSYNC + + + + + + Out + + + Label + X + + + Bits + 9 + + + intFormat + dec + + + + + + Tunnel + + + rotation + + + + NetName + Y + + + + + + Out + + + Label + Y + + + Bits + 8 + + + intFormat + dec + + + + + + Tunnel + + + rotation + + + + NetName + X + + + + + + Comparator + + + Bits + 9 + + + + + + Const + + + Value + 319 + + + Bits + 9 + + + intFormat + dec + + + + + + Multiplexer + + + Bits + 9 + + + + + + Const + + + Value + 511 + + + Bits + 9 + + + intFormat + dec + + + + + + Tunnel + + + NetName + X + + + + + + Const + + + Value + 239 + + + Bits + 8 + + + intFormat + dec + + + + + + Multiplexer + + + Bits + 8 + + + + + + Const + + + Value + 255 + + + Bits + 8 + + + intFormat + dec + + + + + + Tunnel + + + NetName + Y + + + + + + Comparator + + + Bits + 8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital/atk16.dig b/digital/atk16.dig deleted file mode 100644 index 87f7ddb..0000000 --- a/digital/atk16.dig +++ /dev/null @@ -1,2748 +0,0 @@ - - - 2 - - - romContent - - - - - - view1 - - - 0.8446671195652201 - 0.0 - 0.0 - 0.8446671195652201 - 481.55870489058793 - 445.5141438507956 - - - - - view2 - - - 0.8446671195652201 - 0.0 - 0.0 - 0.8446671195652201 - 481.55870489058793 - 445.5141438507956 - - - - - view3 - - - 0.8446671195652201 - 0.0 - 0.0 - 0.8446671195652201 - 481.55870489058793 - 445.5141438507956 - - - - - showDataTable - true - - - - - Register - - - valueIsProbe - true - - - Label - MAR - - - Bits - 16 - - - - - - CounterPreset - - - valueIsProbe - true - - - Label - PC - - - Bits - 16 - - - isProgramCounter - true - - - - - - Ground - - - rotation - - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - atk16_mem.dig - - - Label - MEMORY - - - - - - atk16_jump_unit.dig - - - - - Probe - - - Label - PC - - - - - - atk16_decoder.dig - - - shapeType - CUSTOM - - - - - - Tunnel - - - NetName - FLAG_S - - - - - - Tunnel - - - rotation - - - - NetName - IR_IE - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Tunnel - - - rotation - - - - NetName - LI_OE - - - - - - Tunnel - - - rotation - - - - NetName - RW_IE - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - atk16_regbank.dig - - - - - Driver - - - Bits - 16 - - - flipSelPos - true - - - - - - Tunnel - - - NetName - R2_OE - - - - - - Driver - - - Bits - 16 - - - flipSelPos - true - - - - - - Tunnel - - - NetName - R1_OE - - - - - - atk16_alu_inputs.dig - - - - - Tunnel - - - rotation - - - - NetName - IM_M - - - - - - atk16_alu.dig - - - shapeType - SIMPLE - - - Label - ALU - - - - - - Driver - - - Bits - 16 - - - - - - Register - - - valueIsProbe - true - - - Label - FR - - - Bits - 4 - - - - - - Tunnel - - - rotation - - - - NetName - FR_IE - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Tunnel - - - NetName - ALU_OE - - - - - - Tunnel - - - NetName - FR_Q - - - - - - Counter - - - valueIsProbe - true - - - Label - Microsequencer - - - Bits - 3 - - - - - - VDD - - - rotation - - - - - - - Not - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Driver - - - Bits - 16 - - - flipSelPos - true - - - - - - Probe - - - Label - Bus - - - - - - Tunnel - - - rotation - - - - NetName - MAR_IE - - - - - - Tunnel - - - rotation - - - - NetName - PC_OE - - - - - - Tunnel - - - rotation - - - - NetName - IM_M - - - - - - Tunnel - - - rotation - - - - NetName - OPCODE - - - - - - Probe - - - Label - OPCODE - - - - - - Tunnel - - - rotation - - - - NetName - PC_CO - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Ground - - - rotation - - - - - - - Tunnel - - - rotation - - - - NetName - PC_IE - - - - - - Splitter - - - mirror - true - - - Input Splitting - 24 - - - Output Splitting - 1*24 - - - - - - Tunnel - - - NetName - PC_CO - - - - - - Tunnel - - - NetName - PC_IE - - - - - - Tunnel - - - NetName - PC_OE - - - - - - Tunnel - - - NetName - MAR_IE - - - - - - Tunnel - - - NetName - MEM_IE - - - - - - Tunnel - - - NetName - MEM_OE - - - - - - Tunnel - - - NetName - R1_OE - - - - - - Tunnel - - - NetName - IR_IE - - - - - - Tunnel - - - NetName - ALU_OE - - - - - - Tunnel - - - NetName - US_RS - - - - - - Tunnel - - - NetName - FR_IE - - - - - - Tunnel - - - NetName - RW_IE - - - - - - Stop - - - - - Tunnel - - - NetName - LI_OE - - - - - - Tunnel - - - NetName - IM_M - - - - - - Tunnel - - - NetName - R2_OE - - - - - - atk16_ucode_addr.dig - - - - - Tunnel - - - rotation - - - - NetName - FLAG_S - - - - - - Tunnel - - - rotation - - - - NetName - FR_Q - - - - - - Tunnel - - - rotation - - - - NetName - OPCODE - - - - - - Tunnel - - - NetName - OPCODE - - - - - - Tunnel - - - rotation - - - - NetName - US_Q - - - - - - Tunnel - - - NetName - ISRA_OE - - - - - - Tunnel - - - rotation - - - - NetName - IM_EN - - - - - - Tunnel - - - rotation - - - - NetName - IM_DS - - - - - - Tunnel - - - NetName - IPC_IE - - - - - - Tunnel - - - NetName - IPC_OE - - - - - - Driver - - - Bits - 16 - - - flipSelPos - true - - - - - - Tunnel - - - NetName - ISRA_OE - - - - - - Const - - - Value - 4 - - - Bits - 14 - - - intFormat - hex - - - - - - Tunnel - - - rotation - - - - NetName - IT_N - - - - - - Splitter - - - Input Splitting - 2,14 - - - Output Splitting - 16 - - - - - - Register - - - Label - IPC - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - IPC_IE - - - - - - Driver - - - Bits - 16 - - - flipSelPos - true - - - - - - Tunnel - - - NetName - IPC_OE - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Tunnel - - - NetName - IM_EN - - - - - - Tunnel - - - NetName - IM_DS - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Tunnel - - - rotation - - - - NetName - MEM_IE - - - - - - Tunnel - - - rotation - - - - NetName - MEM_OE - - - - - - Tunnel - - - NetName - DBUS - - - - - - Probe - - - Label - MMIO_S - - - - - - Tunnel - - - NetName - MMIO_IE - - - - - - Tunnel - - - NetName - MMIO_OE - - - - - - Tunnel - - - NetName - MMIO_S - - - - - - atk16_peripherals.dig - - - - - Tunnel - - - rotation - - - - NetName - MMIO_OE - - - - - - Tunnel - - - rotation - - - - NetName - IT_N - - - - - - Tunnel - - - rotation - - - - NetName - IM_DS - - - - - - Counter - - - Label - CLK divider /16 - - - Bits - 4 - - - - - - Tunnel - - - NetName - CLK - - - - - - VDD - - - rotation - - - - - - - Ground - - - - - Clock - - - runRealTime - true - - - Frequency - 25175000 - - - - - - Tunnel - - - NetName - IT_N - - - - - - EEPROM - - - AddrBits - 8 - - - Label - UCODE - - - Bits - 24 - - - Data - c,221,3040,8000,4*0,c,221,3040,8000,4*0,c,221,3440,8000,4*0,c -,221,3440,8000,4*0,c,221,88,60,8000,0,0,0,c,221,88,60,8000,0,0,0 -,c,221,88,110,8000,0,0,0,c,221,88,110,8000,0,0,0,c,221,840,8000 -,4*0,c,221,840,8000,4*0,c,221,82,8000,4*0,c,221,82,8000,4*0,c -,221,c02,8000,4*0,c,221,c02,8000,4*0,c,221,8000,5*0,c,221,82,8000 -,4*0,c,221,8000,5*0,c,221,c02,8000,4*0,c,221,44,8000,4*0,c,221 -,44,8000,4*0,c,221,8000,5*0,c,221,8000,5*0,c,221,8000,5*0,c,221 -,8000,5*0,c0004,10008,22,8000,4*0,c0004,10008,22,8000,4*0,c0004 -,10008,22,8000,4*0,c0004,10008,22,8000,4*0,c,221,120002,8000,4*0 -,c,221,120002,8000,4*0,c,221,4000,5*0,c,221,4000 - - - - - - VDD - - - rotation - - - - - - - Ground - - - rotation - - - - - - - VDD - - - rotation - - - - - - - Tunnel - - - NetName - DBUS - - - - - - Tunnel - - - rotation - - - - NetName - MMIO_IE - - - - - - Tunnel - - - rotation - - - - NetName - MMIO_S - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Tunnel - - - rotation - - - - NetName - MMIO_IE - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - atk16_graphics_mode.dig - - - - - Tunnel - - - rotation - - - - NetName - MMIO_S - - - - - - Tunnel - - - NetName - PCLK - - - - - - Probe - - - Label - GRAPHICS MODE - - - - - - Tunnel - - - NetName - GRMODE - - - - - - atk16_ppu.dig - - - - - Splitter - - - Input Splitting - 2,2,2 - - - Output Splitting - 6 - - - - - - Tunnel - - - rotation - - - - NetName - DBUS - - - - - - Tunnel - - - rotation - - - - NetName - PCLK - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Tunnel - - - rotation - - - - NetName - PCLK - - - - - - Tunnel - - - rotation - - - - NetName - MMIO_IE - - - - - - Tunnel - - - rotation - - - - NetName - MMIO_OE - - - - - - Tunnel - - - rotation - - - - NetName - MMIO_S - - - - - - atk16_tpu.dig - - - - - Tunnel - - - rotation - - - - NetName - MMIO_IE - - - - - - Tunnel - - - rotation - - - - NetName - MMIO_OE - - - - - - Tunnel - - - rotation - - - - NetName - MMIO_S - - - - - - VGA - - - - - Splitter - - - Input Splitting - 6 - - - Output Splitting - 2,2,2 - - - - - - Tunnel - - - rotation - - - - NetName - PCLK - - - - - - Splitter - - - Input Splitting - 2,2,2 - - - Output Splitting - 6 - - - - - - Multiplexer - - - Selector Bits - 2 - - - Bits - 6 - - - - - - Tunnel - - - rotation - - - - NetName - GRMODE - - - - - - Const - - - Value - 0 - - - Bits - 6 - - - - - - Probe - - - intFormat - dec - - - - - - Probe - - - intFormat - dec - - - - - - atk16_vga_sync.dig - - - - - Tunnel - - - rotation - - - - NetName - DBUS - - - - - - Tunnel - - - rotation - - - - NetName - PCLK - - - - - - Tunnel - - - rotation - - - - NetName - US_RS - - - - - - Reset - - - invertOutput - false - - - - - - Or - - - - - Break - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_alu.dig b/digital/atk16_alu.dig deleted file mode 100644 index 0f40f94..0000000 --- a/digital/atk16_alu.dig +++ /dev/null @@ -1,1695 +0,0 @@ - - - 2 - - - romContent - - - - - - Width - 5 - - - - - Add - - - Label - PLUS - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - A - - - - - - Tunnel - - - rotation - - - - NetName - B - - - - - - Ground - - - - - Tunnel - - - NetName - Y - - - - - - Tunnel - - - NetName - FC - - - - - - Driver - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - S0 - - - - - - Driver - - - - - Tunnel - - - rotation - - - - NetName - S0 - - - - - - atk16_alu_fo.dig - - - Label - Overflow flag - - - - - - Tunnel - - - rotation - - - - NetName - A - - - - - - Tunnel - - - rotation - - - - NetName - B - - - - - - Ground - - - - - Tunnel - - - NetName - Y - - - - - - Tunnel - - - NetName - FC - - - - - - Driver - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - S1 - - - - - - Driver - - - - - Tunnel - - - rotation - - - - NetName - S1 - - - - - - Sub - - - Label - MINUS - - - Bits - 16 - - - - - - And - - - Bits - 16 - - - - - - Text - - - Description - AND - - - - - - Tunnel - - - rotation - - - - NetName - A - - - - - - Tunnel - - - rotation - - - - NetName - B - - - - - - Driver - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - S2 - - - - - - Tunnel - - - NetName - Y - - - - - - Or - - - Bits - 16 - - - - - - Text - - - Description - OR - - - - - - Tunnel - - - rotation - - - - NetName - A - - - - - - Tunnel - - - rotation - - - - NetName - B - - - - - - Driver - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - S3 - - - - - - Tunnel - - - NetName - Y - - - - - - XOr - - - Bits - 16 - - - - - - Text - - - Description - XOR - - - - - - Tunnel - - - rotation - - - - NetName - A - - - - - - Tunnel - - - rotation - - - - NetName - B - - - - - - Driver - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - S4 - - - - - - Tunnel - - - NetName - Y - - - - - - BarrelShifter - - - Label - LOG SHIFT RIGHT - - - Bits - 16 - - - direction - right - - - - - - Tunnel - - - rotation - - - - NetName - A - - - - - - Tunnel - - - rotation - - - - NetName - B_L5 - - - - - - Driver - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - S5 - - - - - - Tunnel - - - NetName - Y - - - - - - BarrelShifter - - - Label - ARI SHIFT RIGHT - - - Bits - 16 - - - barrelShifterMode - arithmetic - - - direction - right - - - - - - Tunnel - - - rotation - - - - NetName - A - - - - - - Driver - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - S6 - - - - - - Tunnel - - - NetName - Y - - - - - - BarrelShifter - - - Label - LOG SHIFT LEFT - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - A - - - - - - Driver - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - S7 - - - - - - Tunnel - - - NetName - Y - - - - - - Tunnel - - - rotation - - - - NetName - B_L5 - - - - - - Tunnel - - - rotation - - - - NetName - B_L5 - - - - - - Tunnel - - - rotation - - - - NetName - B15 - - - - - - Tunnel - - - rotation - - - - NetName - Y15 - - - - - - Tunnel - - - rotation - - - - NetName - A15 - - - - - - Tunnel - - - NetName - FO - - - - - - Text - - - Description - Sign flag - - - - - - Tunnel - - - rotation - - - - NetName - Y15 - - - - - - Tunnel - - - NetName - FS - - - - - - atk16_alu_fz.dig - - - Label - Zero flag - - - - - - Tunnel - - - rotation - - - - NetName - Y - - - - - - Tunnel - - - NetName - FZ - - - - - - Tunnel - - - rotation - - - - NetName - S1 - - - - - - Testcase - - - Label - PLUS test - - - Testdata - - A B S FLAGS Y -0x1 0x2 0 0b0000 0x3 -0xff 0x1 0 0b0000 0x100 -0x1 0xffff 0 0b0101 0x0 -0x4000 0x4000 0 0b1010 0x8000 - - - - - - - Testcase - - - Label - MINUS test - - - Testdata - - A B S FLAGS Y -0x10 0x1 1 0b0000 0xF -0x1 0x0 1 0b0000 0x1 -0x0 0x1 1 0b1001 0xFFFF -0x8000 0x1 1 0b0010 0x7FFF - - - - - - - In - - - Description - LHS of binary ALU operation - - - Label - A - - - Bits - 16 - - - - - - In - - - Description - RHS of binary ALU operation - - - Label - B - - - Bits - 16 - - - - - - In - - - Description - ALU operation code - - - Label - S - - - Bits - 3 - - - - - - Text - - - Description - S Y -0 A + B -1 A - B -2 A and B -3 A or B -4 A xor B -5 A >> B # logical -6 A >>> B # arithmetic -7 A << B - - - - - - Decoder - - - Selector Bits - 3 - - - flipSelPos - true - - - - - - Tunnel - - - NetName - S0 - - - - - - Tunnel - - - NetName - S1 - - - - - - Tunnel - - - NetName - S2 - - - - - - Tunnel - - - NetName - S3 - - - - - - Tunnel - - - NetName - S4 - - - - - - Tunnel - - - NetName - S5 - - - - - - Tunnel - - - NetName - S6 - - - - - - Tunnel - - - NetName - S7 - - - - - - Tunnel - - - rotation - - - - NetName - A - - - - - - Splitter - - - Input Splitting - 16 - - - Output Splitting - 15,1 - - - - - - Tunnel - - - rotation - - - - NetName - B - - - - - - Splitter - - - Input Splitting - 16 - - - Output Splitting - 15,1 - - - - - - Splitter - - - Input Splitting - 16 - - - Output Splitting - 5 - - - - - - Tunnel - - - NetName - B_L5 - - - - - - Tunnel - - - NetName - A15 - - - - - - Tunnel - - - NetName - B15 - - - - - - Splitter - - - Input Splitting - 16 - - - Output Splitting - 15,1 - - - - - - Tunnel - - - rotation - - - - NetName - Y - - - - - - Tunnel - - - NetName - Y15 - - - - - - Out - - - Description - Output - - - Label - Y - - - Bits - 16 - - - - - - Splitter - - - Input Splitting - 1*4 - - - Output Splitting - 4 - - - - - - Out - - - Label - FLAGS - - - Bits - 4 - - - - - - Tunnel - - - rotation - - - - NetName - FO - - - - - - Tunnel - - - rotation - - - - NetName - FZ - - - - - - Tunnel - - - rotation - - - - NetName - FS - - - - - - Tunnel - - - rotation - - - - NetName - FC - - - - - - PullDown - - - rotation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_alu_carryfix.dig b/digital/atk16_alu_carryfix.dig deleted file mode 100644 index 1c22602..0000000 --- a/digital/atk16_alu_carryfix.dig +++ /dev/null @@ -1,270 +0,0 @@ - - - 2 - - - - Out - - - Label - Y - - - Inputs - 1 - - - - - - Or - - - wideShape - true - - - - - - And - - - wideShape - true - - - Inputs - 3 - - - - - - And - - - wideShape - true - - - Inputs - 3 - - - - - - In - - - rotation - - - - Label - S2 - - - - - - Not - - - rotation - - - - - - - In - - - rotation - - - - Label - S1 - - - - - - Not - - - rotation - - - - - - - In - - - rotation - - - - Label - S0 - - - - - - Not - - - rotation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_alu_fo.dig b/digital/atk16_alu_fo.dig deleted file mode 100644 index ecf0021..0000000 --- a/digital/atk16_alu_fo.dig +++ /dev/null @@ -1,494 +0,0 @@ - - - 2 - - - Label - alu_fo - - - romContent - - - - - - Width - 4 - - - - - Testcase - - - Testdata - - A15 B15 Y15 ~A/S FO -0 0 0 0 0 -0 0 1 0 1 -0 1 0 0 0 -0 1 1 0 0 -1 0 0 0 0 -1 0 1 0 0 -1 1 0 0 1 -1 1 1 0 0 -0 0 0 1 0 -0 0 1 1 0 -0 1 0 1 0 -0 1 1 1 1 -1 0 0 1 1 -1 0 1 1 0 -1 1 0 1 0 -1 1 1 1 0 - - - - - - - - Out - - - Label - FO - - - Inputs - 1 - - - - - - Or - - - wideShape - true - - - Inputs - 4 - - - - - - And - - - wideShape - true - - - Inputs - 4 - - - - - - And - - - wideShape - true - - - Inputs - 4 - - - - - - And - - - wideShape - true - - - Inputs - 4 - - - - - - And - - - wideShape - true - - - Inputs - 4 - - - - - - In - - - rotation - - - - Label - ~A/S - - - - - - Not - - - rotation - - - - - - - In - - - rotation - - - - Label - A15 - - - - - - Not - - - rotation - - - - - - - In - - - rotation - - - - Label - B15 - - - - - - Not - - - rotation - - - - - - - In - - - rotation - - - - Label - Y15 - - - - - - Not - - - rotation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_alu_fz.dig b/digital/atk16_alu_fz.dig deleted file mode 100644 index 2da652a..0000000 --- a/digital/atk16_alu_fz.dig +++ /dev/null @@ -1,192 +0,0 @@ - - - 2 - - - Label - alu_fz - - - romContent - - - - - - - - In - - - Label - Y - - - Bits - 16 - - - - - - Splitter - - - Input Splitting - 16 - - - Output Splitting - 4*4 - - - - - - Splitter - - - Input Splitting - 4 - - - Output Splitting - 1*4 - - - - - - Out - - - Label - FZ - - - - - - Testcase - - - Testdata - - Y FZ -0x0 1 -0x1 0 -0xff 0 - - - - - - - NOr - - - Inputs - 4 - - - - - - Or - - - Bits - 4 - - - Inputs - 4 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_alu_inputs.dig b/digital/atk16_alu_inputs.dig deleted file mode 100644 index 310bafb..0000000 --- a/digital/atk16_alu_inputs.dig +++ /dev/null @@ -1,215 +0,0 @@ - - - 2 - - - Description - Maps the R1 input to the A output. Uses OPCODE parity to mux either the R2 input (even parity) or the RW_S input, here acting as a small immediate value, to the B output. - - - romContent - - - - - - Width - 5 - - - - - In - - - Description - Register 1 value from regbank - - - Label - R1 - - - Bits - 16 - - - - - - In - - - Description - Register 2 value from regbank - - - Label - R2 - - - Bits - 16 - - - - - - Multiplexer - - - Bits - 16 - - - - - - In - - - Description - Register 2 selector - - - Label - R2_S - - - Bits - 3 - - - - - - In - - - Description - Immediate mode on? - - - Label - IM_M - - - - - - Out - - - Description - Output A - - - Label - A - - - Bits - 16 - - - - - - Out - - - Description - Output B - - - Label - B - - - Bits - 16 - - - - - - Splitter - - - Input Splitting - 3,13 - - - Output Splitting - 16 - - - - - - Ground - - - Bits - 13 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_decoder.dig b/digital/atk16_decoder.dig deleted file mode 100644 index b8eb088..0000000 --- a/digital/atk16_decoder.dig +++ /dev/null @@ -1,364 +0,0 @@ - - - 2 - - - romContent - - - - - - Width - 5 - - - - - Register - - - valueIsProbe - true - - - Label - IR - - - Bits - 16 - - - - - - In - - - Label - DBUS - - - Bits - 16 - - - isHighZ - true - - - - - - In - - - Description - Instruction register input enable - - - Label - IR_IE - - - - - - In - - - Label - CLK - - - - - - Splitter - - - splitterSpreading - 2 - - - Input Splitting - 16 - - - Output Splitting - 3,3,3,3,4 - - - - - - Tunnel - - - NetName - DBUS - - - - - - Tunnel - - - rotation - - - - NetName - DBUS - - - - - - Out - - - Description - Opcode - - - Label - OP - - - Bits - 4 - - - - - - Out - - - Description - Write register selection - - - Label - RW_S - - - Bits - 3 - - - - - - Out - - - Description - ALU selection code - - - Label - ALU_S - - - Bits - 3 - - - - - - Out - - - Description - Read register 1 selection - - - Label - R1_S - - - Bits - 3 - - - - - - Out - - - Description - Read register 2 selection - - - Label - R2_S - - - Bits - 3 - - - - - - Splitter - - - Input Splitting - 16 - - - Output Splitting - 9, - - - - - - Driver - - - Bits - 16 - - - flipSelPos - true - - - - - - Tunnel - - - NetName - DBUS - - - - - - In - - - Description - Low 9 bits immediate value output enable - - - Label - LI_OE - - - - - - Testcase - - - Testdata - - CLK DBUS IR_IE LI_OE OP RW_S R1_S R2_S ALU_S -C 0b0000001010011000 1 0 0 1 2 3 0 - - - - - - - BitExtender - - - inputBits - 9 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_graphics_mode.dig b/digital/atk16_graphics_mode.dig deleted file mode 100644 index 2d05dd6..0000000 --- a/digital/atk16_graphics_mode.dig +++ /dev/null @@ -1,311 +0,0 @@ - - - 2 - - - romContent - - - - - - Width - 5 - - - - - In - - - Label - DBUS - - - Bits - 16 - - - - - - Out - - - Description - 00 disabled -01 text mode -10 sprite mode -11 undefined - - - Label - MODE - - - Bits - 2 - - - - - - Register - - - Label - GRAPHICS MODE - - - Bits - 2 - - - - - - And - - - Inputs - 13 - - - - - - Splitter - - - Input Splitting - 13 - - - Output Splitting - 1*13 - - - - - - And - - - - - Splitter - - - Input Splitting - 16 - - - Output Splitting - 2,14 - - - - - - In - - - Label - MMIO_S - - - Bits - 13 - - - - - - In - - - Label - MMIO_IE - - - - - - Const - - - Value - 2 - - - Bits - 13 - - - - - - XNOr - - - Bits - 13 - - - - - - In - - - Label - CLK - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_irc.dig b/digital/atk16_irc.dig deleted file mode 100644 index 0037fa0..0000000 --- a/digital/atk16_irc.dig +++ /dev/null @@ -1,341 +0,0 @@ - - - 2 - - - romContent - - - - - - Width - 5 - - - - - In - - - Description - IRQ lines - - - Label - IRQ - - - Bits - 4 - - - - - - In - - - Description - PC value - - - Label - PC - - - Bits - 16 - - - - - - Splitter - - - Input Splitting - 4 - - - Output Splitting - 1*4 - - - - - - Text - - - Description - Some IRQ active? - - - - - - In - - - Label - MAR_IE - - - - - - And - - - - - Multiplexer - - - Bits - 16 - - - - - - Out - - - Label - DBUS - - - Bits - 16 - - - - - - Driver - - - Bits - 16 - - - flipSelPos - true - - - - - - In - - - Label - PC_OE - - - - - - PriorityEncoder - - - Selector Bits - 2 - - - - - - Const - - - Value - 17 - - - Bits - 16 - - - - - - Multiplexer - - - Selector Bits - 2 - - - Bits - 16 - - - - - - Const - - - Value - 16 - - - Bits - 16 - - - - - - Const - - - Value - 18 - - - Bits - 16 - - - - - - Const - - - Value - 19 - - - Bits - 16 - - - - - - Testcase - - - Testdata - - IRQ PC MAR_IE PC_OE DBUS -0b0000 0x5 0 0 Z -0b0000 0x5 0 1 0x5 -0b0001 0x5 0 1 0x5 -0b0001 0x5 1 1 0x10 -0b0101 0x5 1 1 0x12 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_jump_unit.dig b/digital/atk16_jump_unit.dig deleted file mode 100644 index 4ccd266..0000000 --- a/digital/atk16_jump_unit.dig +++ /dev/null @@ -1,193 +0,0 @@ - - - 2 - - - Description - Uses OPCODE parity to choose between relative addressing mode (even parity) or absolute addressing mode (odd parity). - - - romContent - - - - - - Width - 5 - - - - - In - - - Description - Jump address - - - Label - ADDR - - - Bits - 16 - - - - - - In - - - Description - PC value - - - Label - PC - - - Bits - 16 - - - - - - In - - - Description - Immediate mode on? - - - Label - IM_M - - - - - - Out - - - Description - Result PC value - - - Label - PC_RES - - - Bits - 16 - - - - - - Add - - - Bits - 16 - - - - - - Multiplexer - - - Bits - 16 - - - - - - Ground - - - - - Testcase - - - Testdata - - PC ADDR IM_M PC_RES -10 20 0 20 -10 20 1 30 - - - - - - - Not - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_mem.dig b/digital/atk16_mem.dig deleted file mode 100644 index 6ff9810..0000000 --- a/digital/atk16_mem.dig +++ /dev/null @@ -1,949 +0,0 @@ - - 2 - - - romContent - - - - - - Width - 7 - - - - - EEPROM - - - AddrBits - 15 - - - isProgramMemory - true - - - Label - MEM_ROM - - - Bits - 16 - - - Data - 4014,2e00,1dc0,6026,8000,8000,8000,8000,8000,8000,8000,8000,8000,8000,8000,8000,001b,001a,001a,001a,8000,e000,e001,e002,e800,f800,f000,31c0,1fc8,31c8,1fc8,4016,2000,2000,4215,2240,3040,1fc9,23c0,1fc9,21c0,e000,4017,2000,4200,3008,600d,0008,0000,0001,0002,0017,0019,9000,0100,0031,0061,0062,0063,0032,402f,2000,0fc0,4433,2480,31d0,1fc8,1fc9,25c0,2480,31d0,1fc8,1fc9,21c0,4200,0270,3040,4434,2480,31d0,1fc8,1fc9,25c0,2480,31d0,1fc8,1fc9,21c0,4201,0270,3040,4000,0180,2000,31c0,1fc8,4031,2000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,4035,2000,31c0,1fc8,4000,31c0,1fc8,1fc9,23c0,1fc9,21c0,0008,31c0,1fc8,4037,2000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,4035,2000,31c0,1fc8,4001,31c0,1fc8,1fc9,23c0,1fc9,21c0,0008,31c0,1fc8,4038,2000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,4035,2000,31c0,1fc8,4002,31c0,1fc8,1fc9,23c0,1fc9,21c0,0008,31c0,1fc8,4039,2000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,4035,2000,31c0,1fc8,4003,31c0,1fc8,1fc9,23c0,1fc9,21c0,0008,31c0,1fc8,403a,2000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,4035,2000,31c0,1fc8,4004,31c0,1fc8,1fc9,23c0,1fc9,21c0,0008,31c0,1fc8,403b,2000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,4035,2000,31c0,1fc8,4005,31c0,1fc8,1fc9,23c0,1fc9,21c0,0008,31c0,1fc8,4000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,4435,2480,31d0,1fc8,1fc9,21c0,4202,0270,3040,4400,31d0,1fc8,1fc9,21c0,4203,0270,3040,4402,0590,2480,31d0,1fc8,1fc9,25c0,2480,31d0,1fc8,1fc9,21c0,4204,0270,3040,4400,31d0,1fc8,1fc9,21c0,4205,0270,3040,4201,31c8,1fc8,1fc9,21c0,1000,8451,4435,2480,31d0,1fc8,4403,0590,2480,31d0,1fc8,1fc9,27c0,1fc9,25c0,0498,31d0,1fc8,1fc9,21c0,4206,0270,3040,4406,0590,2480,31d0,1fc8,1fc9,25c0,2480,31d0,1fc8,1fc9,21c0,4207,0270,3040,4007,0180,2000,31c0,1fc8,4000,31c0,1fc8,1fc9,21c0,1000,8402,6020,6000,4407,0590,2480,31d0,1fc8,1fc9,21c0,4205,0270,3040,4403,0590,2480,31d0,1fc8,4401,31d0,1fc8,1fc9,27c0,1fc9,25c0,0498,31d0,1fc8,1fc9,21c0,4203,0270,3040,61a8,4001,0180,2000,31c0,1fc8,4000,31c0,1fc8,1fc9,23c0,1fc9,21c0,0008,31c0,1fc8,4004,0180,2000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,4001,0180,2000,31c0,1fc8,4001,31c0,1fc8,1fc9,23c0,1fc9,21c0,0008,31c0,1fc8,4005,0180,2000,31c0,1fc8,1fc9,23c0,1fc9,21c0,3008,4000,31c0,1fc8,1fc9,21c0,1f80,f000 - - - - - - Ground - - - rotation - - - - - - - VDD - - - rotation - - - - - - - VDD - - - rotation - - - - - - - In - - - Description - Address - - - Label - ADDR - - - Bits - 16 - - - - - - Splitter - - - Input Splitting - 16 - - - Output Splitting - 13,1,1,1 - - - - - - atk16_mem_mux.dig - - - - - Splitter - - - Input Splitting - 13,1,1 - - - Output Splitting - 15 - - - - - - Splitter - - - Input Splitting - 1,1 - - - Output Splitting - 2 - - - - - - Demultiplexer - - - Selector Bits - 2 - - - Bits - 15 - - - - - - Probe - - - Label - ROM_OUT - - - - - - Driver - - - Bits - 16 - - - flipSelPos - true - - - - - - Demultiplexer - - - Selector Bits - 2 - - - flipSelPos - true - - - - - - Tunnel - - - NetName - RAM_IE - - - - - - In - - - Description - Data bus - - - Label - DBUS - - - Bits - 16 - - - isHighZ - true - - - - - - Tunnel - - - NetName - CLK - - - - - - RAMDualPort - - - AddrBits - 15 - - - Label - MEM_RAM - - - Bits - 16 - - - - - - VDD - - - rotation - - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Tunnel - - - rotation - - - - NetName - RAM_IE - - - - - - Tunnel - - - rotation - - - - NetName - DBUS - - - - - - Probe - - - Label - RAM_OUT - - - - - - Driver - - - Bits - 16 - - - - - - In - - - Description - Clock - - - Label - CLK - - - - - - Out - - - Description - Memory-mapped I/O word input enable - - - Label - MMIO_IE - - - - - - Out - - - Description - Memory-mapped I/O word output enable - - - Label - MMIO_OE - - - - - - Tunnel - - - NetName - MMIO_S - - - - - - Testcase - - - Testdata - - CLK ADDR MEM_IE MEM_OE DBUS DBUS_out - -# read ROM -program(0xFF) -C 0x0 0 1 Z 0xFF - -# read RAM -memory MEM_RAM(0x0)=0x55; -C 0 0 0 Z X -C 0x8000 0 1 Z 0x55 - -# write to RAM -C 0x8000 1 0 0xAA 0xAA -C 0x8000 0 1 Z 0xAA - - - - - - - - In - - - Description - Memory input enable - - - Label - MEM_IE - - - - - - In - - - Description - Memory output enable - - - Label - MEM_OE - - - - - - And - - - rotation - - - - - - - Tunnel - - - NetName - RAM_OE - - - - - - Tunnel - - - NetName - MEM_OE - - - - - - Tunnel - - - NetName - MEM_OE - - - - - - Tunnel - - - NetName - DBUS - - - - - - And - - - rotation - - - - - - - Tunnel - - - NetName - ROM_OE - - - - - - Tunnel - - - NetName - MEM_OE - - - - - - Tunnel - - - NetName - DBUS - - - - - - Tunnel - - - NetName - DBUS - - - - - - Decoder - - - Selector Bits - 2 - - - flipSelPos - true - - - - - - Tunnel - - - NetName - ROM_OE - - - - - - Tunnel - - - NetName - RAM_OE - - - - - - Tunnel - - - NetName - MMIO_OE - - - - - - Tunnel - - - NetName - MMIO_IE - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - MEM_OE - - - - - - Tunnel - - - rotation - - - - NetName - MMIO_OE - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - MEM_IE - - - - - - Tunnel - - - rotation - - - - NetName - MMIO_IE - - - - - - Out - - - Description - Memory-mapped I/O word selector - - - Label - MMIO_S - - - Bits - 13 - - - - - - Tunnel - - - rotation - - - - NetName - MMIO_S - - - - - - Tunnel - - - NetName - MEM_IE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_mem_mux.dig b/digital/atk16_mem_mux.dig deleted file mode 100644 index d4be584..0000000 --- a/digital/atk16_mem_mux.dig +++ /dev/null @@ -1,276 +0,0 @@ - - - 2 - - - - Out - - - Label - X - - - Inputs - 1 - - - - - - And - - - wideShape - true - - - Inputs - 3 - - - - - - Out - - - Label - Y - - - Inputs - 1 - - - - - - Or - - - wideShape - true - - - - - - And - - - wideShape - true - - - - - - And - - - wideShape - true - - - - - - In - - - rotation - - - - Label - C - - - - - - In - - - rotation - - - - Label - B - - - - - - Not - - - rotation - - - - - - - In - - - rotation - - - - Label - A - - - - - - Not - - - rotation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_peripherals.dig b/digital/atk16_peripherals.dig deleted file mode 100644 index c8eb7b5..0000000 --- a/digital/atk16_peripherals.dig +++ /dev/null @@ -1,852 +0,0 @@ - - - 2 - - - romContent - - - - - - Width - 6 - - - - - Splitter - - - Input Splitting - 1*4 - - - Output Splitting - 4 - - - - - - Out - - - Label - IRQ - - - Bits - 4 - - - - - - RS_FF_AS - - - - - Tunnel - - - rotation - - - - NetName - IRQ0 - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - IM_DS - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - IM_DS - - - - - - RS_FF_AS - - - - - Tunnel - - - rotation - - - - NetName - IRQ1 - - - - - - RS_FF_AS - - - - - Tunnel - - - rotation - - - - NetName - IRQ2 - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - IM_DS - - - - - - RS_FF_AS - - - - - Tunnel - - - rotation - - - - NetName - IRQ3 - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - IM_DS - - - - - - Decoder - - - Selector Bits - 2 - - - - - - Comparator - - - Bits - 13 - - - - - - Const - - - Value - 0 - - - Bits - 13 - - - - - - And - - - - - Terminal - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Tunnel - - - rotation - - - - NetName - DBUS - - - - - - Tunnel - - - rotation - - - - NetName - IE - - - - - - Tunnel - - - rotation - - - - NetName - S - - - - - - Keyboard - - - - - Tunnel - - - NetName - IRQ0 - - - - - - Tunnel - - - NetName - DBUS - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Comparator - - - Bits - 13 - - - - - - Const - - - Bits - 13 - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - OE - - - - - - Tunnel - - - rotation - - - - NetName - S - - - - - - Ground - - - - - Tunnel - - - NetName - IRQ1 - - - - - - Ground - - - - - Tunnel - - - NetName - IRQ2 - - - - - - Ground - - - - - Tunnel - - - NetName - IRQ3 - - - - - - In - - - Label - IM_DS - - - - - - Tunnel - - - NetName - IM_DS - - - - - - In - - - Label - IT_N - - - Bits - 2 - - - - - - In - - - Label - OE - - - - - - Tunnel - - - NetName - OE - - - - - - In - - - Label - IE - - - - - - Tunnel - - - NetName - IE - - - - - - In - - - Label - S - - - Bits - 13 - - - - - - Tunnel - - - NetName - S - - - - - - In - - - Label - CLK - - - - - - Tunnel - - - NetName - CLK - - - - - - Out - - - Label - DBUS - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - DBUS - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_ppu.dig b/digital/atk16_ppu.dig deleted file mode 100644 index e6e7608..0000000 --- a/digital/atk16_ppu.dig +++ /dev/null @@ -1,827 +0,0 @@ - - - 2 - - - romContent - - - - - - Width - 7 - - - - - RAMDualPort - - - AddrBits - 7 - - - Label - SPRITE MEM - - - Bits - 16 - - - - - - Text - - - Description - 8 bits tile pattern index -10 bits Y position -10 bits X position -1 bit H flip -1 bit V flip -1 bit behind background? (priority) -1 bit palette select -= total 4 bytes per sprite -x 64 sprites -= 128 words - - - - - - Text - - - Description - 2**7 selector addresses for -sprite mem, starting from 0x0800 - - - - - - In - - - Label - MMIO_IE - - - - - - In - - - Label - MMIO_OE - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - In - - - Description - MMI/O selector - - - Label - MMIO_S - - - Bits - 13 - - - - - - Tunnel - - - rotation - - - - NetName - DBUS - - - - - - Tunnel - - - rotation - - - - NetName - SMEMBUS - - - - - - Splitter - - - Input Splitting - 13 - - - Output Splitting - 11,1,1 - - - - - - And - - - inverterConfig - - In_2 - - - - - - - Tunnel - - - rotation - - - - NetName - SM_QUERY - - - - - - Ground - - - Bits - 11 - - - - - - RAMDualPort - - - AddrBits - 9 - - - Label - SCAN BUFFER - - - Bits - 4 - - - - - - Tunnel - - - rotation - - - - NetName - X - - - - - - Splitter - - - mirror - true - - - Input Splitting - 4 - - - Output Splitting - 1*4 - - - - - - atk16_ppu_palette.dig - - - - - Splitter - - - Input Splitting - 1,1 - - - Output Splitting - 2 - - - - - - Splitter - - - Input Splitting - 1,1 - - - Output Splitting - 2 - - - - - - Splitter - - - Input Splitting - 1,1 - - - Output Splitting - 2 - - - - - - Tunnel - - - NetName - PR - - - - - - Tunnel - - - NetName - PG - - - - - - Tunnel - - - NetName - PB - - - - - - Ground - - - rotation - - - - Bits - 4 - - - - - - Ground - - - rotation - - - - - - - Counter - - - - - Tunnel - - - rotation - - - - NetName - PCLK - - - - - - VDD - - - - - Ground - - - - - Text - - - Description - TODO - - - - - - Tunnel - - - rotation - - - - NetName - SMEMBUS - - - - - - Ground - - - rotation - - - - Bits - 7 - - - - - - Text - - - Description - TODO: 8x8x4 tile pattern memory - - - - - - VDD - - - rotation - - - - - - - Probe - - - Label - SCAN BUF - - - - - - Out - - - Label - PR - - - Bits - 2 - - - - - - Out - - - Label - PG - - - Bits - 2 - - - - - - Out - - - Label - PB - - - Bits - 2 - - - - - - Tunnel - - - rotation - - - - NetName - PB - - - - - - Tunnel - - - rotation - - - - NetName - PR - - - - - - Tunnel - - - rotation - - - - NetName - PG - - - - - - In - - - Description - Pixel clock - - - Label - PCLK - - - - - - Tunnel - - - NetName - PCLK - - - - - - In - - - Description - CPU clock - - - Label - CLK - - - - - - Tunnel - - - NetName - CLK - - - - - - Tunnel - - - NetName - DBUS - - - - - - In - - - Description - Data bus - - - Label - DBUS - - - Bits - 16 - - - - - - In - - - Description - X pixel - - - Label - X - - - Bits - 9 - - - - - - Tunnel - - - NetName - X - - - - - - In - - - Description - Y pixel - - - Label - Y - - - Bits - 8 - - - - - - Tunnel - - - NetName - Y - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_ppu_palette.dig b/digital/atk16_ppu_palette.dig deleted file mode 100644 index 40101b7..0000000 --- a/digital/atk16_ppu_palette.dig +++ /dev/null @@ -1,225 +0,0 @@ - - - 2 - - - romContent - - - - - - Width - 6 - - - - - Out - - - Label - YR1 - - - Inputs - 1 - - - - - - Out - - - Label - YR0 - - - Inputs - 1 - - - - - - Out - - - Label - YG1 - - - Inputs - 1 - - - - - - Out - - - Label - YG0 - - - Inputs - 1 - - - - - - Out - - - Label - YB1 - - - Inputs - 1 - - - - - - Out - - - Label - YB0 - - - Inputs - 1 - - - - - - In - - - rotation - - - - Label - R0 - - - - - - In - - - rotation - - - - Label - G1 - - - - - - In - - - rotation - - - - Label - G0 - - - - - - In - - - rotation - - - - Label - B0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_ppu_sprite_eval.dig b/digital/atk16_ppu_sprite_eval.dig deleted file mode 100644 index c765847..0000000 --- a/digital/atk16_ppu_sprite_eval.dig +++ /dev/null @@ -1,4325 +0,0 @@ - - - 2 - - - - Tunnel - - - NetName - PCLK - - - - - - Clock - - - Frequency - 20 - - - runRealTime - true - - - - - - In - - - Label - PCLK - - - - - - Rectangle - - - Label - Stage 1 Secondary Clear - - - RectHeight - 15 - - - RectWidth - 35 - - - - - - Tunnel - - - NetName - NPCLK - - - - - - Not - - - - - Break - - - - - Break - - - - - Text - - - Description - State machine & sequencer: -SQ0 transition current state if conditions match -SQ1 read from memory A -SQ2 read from memory B -SQ3 write to memory -SQ4 counter inc - -Sequencer clocked by falling edge (NPCLK) -Everything else clocked by rising edge (PCLK) - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - ST_SECCLR - - - - - - Tunnel - - - rotation - - - - NetName - OVF_SECCLR - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - ST_EVAL - - - - - - Or - - - Inputs - 3 - - - - - - And - - - Inputs - 3 - - - - - - Tunnel - - - NetName - CLK_STAGE - - - - - - Tunnel - - - rotation - - - - NetName - PCLK - - - - - - Tunnel - - - rotation - - - - NetName - SQ_TRANS - - - - - - Counter - - - Label - STAGE - - - Bits - 2 - - - - - - Decoder - - - Selector Bits - 2 - - - flipSelPos - true - - - - - - Tunnel - - - NetName - ST_SECCLR - - - - - - VDD - - - - - Tunnel - - - NetName - ST_EVAL - - - - - - Tunnel - - - NetName - ST_RENDER - - - - - - Or - - - - - Tunnel - - - rotation - - - - NetName - CLK_STAGE - - - - - - Tunnel - - - rotation - - - - NetName - RST - - - - - - Or - - - - - Tunnel - - - rotation - - - - NetName - OVF_EVAL - - - - - - Tunnel - - - rotation - - - - NetName - OVF_SMN - - - - - - Tunnel - - - NetName - STAGE - - - - - - Multiplexer - - - Selector Bits - 2 - - - - - - Tunnel - - - NetName - SEC_C - - - - - - Ground - - - rotation - - - - - - - Tunnel - - - rotation - - - - NetName - STAGE - - - - - - Tunnel - - - rotation - - - - NetName - CLK_WRITE - - - - - - Tunnel - - - rotation - - - - NetName - CLK_READA - - - - - - Multiplexer - - - Selector Bits - 2 - - - - - - Tunnel - - - NetName - SEC_str - - - - - - VDD - - - rotation - - - - - - - Ground - - - rotation - - - - - - - Multiplexer - - - Selector Bits - 2 - - - - - - Tunnel - - - NetName - SEC_ld - - - - - - VDD - - - rotation - - - - - - - Multiplexer - - - Selector Bits - 2 - - - - - - Tunnel - - - NetName - SB_C - - - - - - Ground - - - rotation - - - - - - - Ground - - - rotation - - - - - - - Tunnel - - - rotation - - - - NetName - STAGE - - - - - - Multiplexer - - - Selector Bits - 2 - - - - - - Tunnel - - - NetName - SB_str - - - - - - Multiplexer - - - Selector Bits - 2 - - - - - - Tunnel - - - NetName - SB_ld - - - - - - VDD - - - rotation - - - - - - - Counter - - - Label - SEC CLR ADDR - - - Bits - 4 - - - - - - Or - - - - - Tunnel - - - rotation - - - - NetName - RST - - - - - - Tunnel - - - rotation - - - - NetName - CLK_WRITE - - - - - - Driver - - - Bits - 3 - - - - - - Tunnel - - - NetName - SEC_A - - - - - - Tunnel - - - NetName - ST_SECCLR - - - - - - Driver - - - Bits - 32 - - - - - - Tunnel - - - NetName - ST_SECCLR - - - - - - Tunnel - - - NetName - SEC_Din - - - - - - Ground - - - Bits - 32 - - - - - - Probe - - - - - Tunnel - - - rotation - - - - NetName - ST_SECCLR - - - - - - VDD - - - rotation - - - - - - - Ground - - - rotation - - - - - - - Ground - - - rotation - - - - - - - RAMDualPort - - - AddrBits - 3 - - - Label - SECONDARY - - - Bits - 32 - - - - - - Probe - - - Label - SEC_D - - - - - - Tunnel - - - rotation - - - - NetName - SEC_ld - - - - - - Tunnel - - - rotation - - - - NetName - SEC_str - - - - - - Tunnel - - - rotation - - - - NetName - SEC_A - - - - - - Tunnel - - - rotation - - - - NetName - SEC_Din - - - - - - Tunnel - - - rotation - - - - NetName - SEC_C - - - - - - RAMDualPort - - - AddrBits - 7 - - - Label - SCAN BUFFER - - - Bits - 16 - - - - - - Probe - - - Label - SB_D - - - - - - Tunnel - - - rotation - - - - NetName - SB_A - - - - - - Tunnel - - - rotation - - - - NetName - SB_Din - - - - - - Tunnel - - - rotation - - - - NetName - SB_str - - - - - - Tunnel - - - rotation - - - - NetName - SB_C - - - - - - Tunnel - - - rotation - - - - NetName - SB_ld - - - - - - Tunnel - - - rotation - - - - NetName - SB_A - - - - - - Tunnel - - - rotation - - - - NetName - SB_Din - - - - - - Ground - - - rotation - - - - Bits - 7 - - - - - - Ground - - - rotation - - - - Bits - 16 - - - - - - Out - - - Description - Scanline buffer data - - - Label - SB_D - - - Bits - 9 - - - - - - Ground - - - Bits - 9 - - - - - - Multiplexer - - - Selector Bits - 2 - - - - - - Tunnel - - - NetName - SM_C - - - - - - Ground - - - rotation - - - - - - - Tunnel - - - rotation - - - - NetName - STAGE - - - - - - Multiplexer - - - Selector Bits - 2 - - - - - - Tunnel - - - NetName - SM_str - - - - - - Multiplexer - - - Selector Bits - 2 - - - - - - Tunnel - - - NetName - SM_ld - - - - - - VDD - - - rotation - - - - - - - Tunnel - - - NetName - ST_IDLE - - - - - - Ground - - - rotation - - - - - - - Ground - - - rotation - - - - - - - Tunnel - - - rotation - - - - NetName - CLK_READA - - - - - - Rectangle - - - RectHeight - 40 - - - Label - Stage 2 Evaluate sprites - - - RectWidth - 35 - - - - - - Counter - - - Label - SMN - - - Bits - 7 - - - - - - Probe - - - - - Or - - - - - Tunnel - - - rotation - - - - NetName - RST - - - - - - Tunnel - - - rotation - - - - NetName - CLK_WRITE - - - - - - Tunnel - - - rotation - - - - NetName - SM_D - - - - - - Splitter - - - Input Splitting - 32 - - - Output Splitting - 8,10,10,1,1,1,1 - - - - - - Sub - - - Bits - 10 - - - - - - Ground - - - - - Tunnel - - - rotation - - - - NetName - SCY - - - - - - Comparator - - - Bits - 10 - - - - - - Const - - - Value - 8 - - - Bits - 10 - - - - - - Tunnel - - - NetName - YMATCH - - - - - - Tunnel - - - NetName - OVF_SMN - - - - - - Tunnel - - - rotation - - - - NetName - ST_EVAL - - - - - - Splitter - - - Input Splitting - 7 - - - Output Splitting - 6,1 - - - - - - Tunnel - - - NetName - SM_A - - - - - - Tunnel - - - NetName - ST_SECCLR - - - - - - LED - - - rotation - - - - - - - Tunnel - - - NetName - ST_EVAL - - - - - - LED - - - rotation - - - - - - - Multiplexer - - - Selector Bits - 2 - - - - - - Tunnel - - - NetName - TM_C - - - - - - Ground - - - rotation - - - - - - - Ground - - - rotation - - - - - - - Tunnel - - - rotation - - - - NetName - STAGE - - - - - - Multiplexer - - - Selector Bits - 2 - - - - - - Tunnel - - - NetName - TM_str - - - - - - Multiplexer - - - Selector Bits - 2 - - - - - - Tunnel - - - NetName - TM_ld - - - - - - VDD - - - rotation - - - - - - - Ground - - - rotation - - - - - - - RAMDualPort - - - AddrBits - 11 - - - Label - TILE MEM - - - Bits - 32 - - - - - - Tunnel - - - rotation - - - - NetName - TM_C - - - - - - Tunnel - - - rotation - - - - NetName - TM_str - - - - - - Tunnel - - - rotation - - - - NetName - TM_ld - - - - - - Text - - - Description - Tile mem addr: -8 bits select tile -3 bits select row in tile -= 11 bits total - - - - - - Tunnel - - - rotation - - - - NetName - TM_Din - - - - - - Ground - - - rotation - - - - Bits - 32 - - - - - - Probe - - - Label - TM_D - - - - - - Tunnel - - - rotation - - - - NetName - TM_A - - - - - - Tunnel - - - rotation - - - - NetName - TM_Din - - - - - - Text - - - Description - 8 bits tile pattern index -10 bits Y position -10 bits X position -1 bit H flip -1 bit V flip -1 bit behind background? (priority) -1 bit palette select -= total 4 bytes per sprite -x 64 sprites -= 128 words - - - - - - RAMDualPort - - - AddrBits - 6 - - - Label - SPRITE MEM H - - - Bits - 16 - - - - - - Tunnel - - - NetName - SM_D - - - - - - Tunnel - - - rotation - - - - NetName - DBUS - - - - - - Tunnel - - - rotation - - - - NetName - SM_A - - - - - - Tunnel - - - rotation - - - - NetName - SM_C - - - - - - Tunnel - - - rotation - - - - NetName - SM_ld - - - - - - Tunnel - - - rotation - - - - NetName - SM_str - - - - - - RAMDualPort - - - AddrBits - 6 - - - Label - SPRITE MEM L - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - DBUS - - - - - - Tunnel - - - rotation - - - - NetName - SM_A - - - - - - Tunnel - - - rotation - - - - NetName - SM_C - - - - - - Tunnel - - - rotation - - - - NetName - SM_ld - - - - - - Tunnel - - - rotation - - - - NetName - SM_str - - - - - - Splitter - - - Input Splitting - 16,16 - - - Output Splitting - 32 - - - - - - Probe - - - - - Counter - - - Label - Sequencer - - - Bits - 3 - - - - - - Decoder - - - Selector Bits - 3 - - - flipSelPos - true - - - - - - Tunnel - - - NetName - SQ_TRANS - - - - - - Tunnel - - - NetName - SQ_READA - - - - - - Tunnel - - - NetName - SQ_READB - - - - - - VDD - - - rotation - - - - - - - Tunnel - - - NetName - SQ_WRITE - - - - - - Or - - - - - Tunnel - - - rotation - - - - NetName - NPCLK - - - - - - Tunnel - - - rotation - - - - NetName - RST - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - SQ_READA - - - - - - Tunnel - - - rotation - - - - NetName - PCLK - - - - - - Tunnel - - - NetName - CLK_READA - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - ST_RENDER - - - - - - Tunnel - - - rotation - - - - NetName - OVF_RENDER - - - - - - Tunnel - - - NetName - SEC_D - - - - - - Splitter - - - Input Splitting - 4 - - - Output Splitting - 3,1 - - - - - - Tunnel - - - NetName - OVF_SECCLR - - - - - - Tunnel - - - NetName - SQ_CLR - - - - - - Or - - - - - Tunnel - - - rotation - - - - NetName - SQ_CLR - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - SQ_READB - - - - - - Tunnel - - - rotation - - - - NetName - PCLK - - - - - - Tunnel - - - NetName - CLK_READB - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - SQ_WRITE - - - - - - Tunnel - - - rotation - - - - NetName - PCLK - - - - - - Tunnel - - - NetName - CLK_WRITE - - - - - - Splitter - - - Input Splitting - 8,10,10,1,1,1,1 - - - Output Splitting - 32 - - - - - - Driver - - - Bits - 32 - - - - - - Tunnel - - - NetName - ST_EVAL - - - - - - Tunnel - - - NetName - SEC_Din - - - - - - In - - - Description - Scanline Y (0..524) - - - Label - SCY - - - Bits - 10 - - - - - - Tunnel - - - NetName - SCY - - - - - - In - - - Label - DBUS - - - Bits - 16 - - - - - - Tunnel - - - NetName - DBUS - - - - - - In - - - Description - Reset sprite evaluator - - - Label - RST - - - - - - Tunnel - - - NetName - RST - - - - - - And - - - Inputs - 3 - - - - - - Tunnel - - - rotation - - - - NetName - YMATCH - - - - - - Tunnel - - - rotation - - - - NetName - SQ_WRITE - - - - - - Tunnel - - - rotation - - - - NetName - PCLK - - - - - - Counter - - - Label - SEC ADDR - - - Bits - 4 - - - - - - Or - - - - - Tunnel - - - rotation - - - - NetName - RST - - - - - - Probe - - - - - Tunnel - - - NetName - OVF_EVAL - - - - - - Tunnel - - - rotation - - - - NetName - ST_EVAL - - - - - - Splitter - - - Input Splitting - 4 - - - Output Splitting - 3,1 - - - - - - Driver - - - Bits - 3 - - - - - - Tunnel - - - NetName - SEC_A - - - - - - Tunnel - - - NetName - ST_EVAL - - - - - - Rectangle - - - RectHeight - 30 - - - Label - Stage 3 Render line to scanbuf - - - RectWidth - 35 - - - - - - Tunnel - - - NetName - ST_RENDER - - - - - - LED - - - rotation - - - - - - - Counter - - - Label - SEC ADDR - - - Bits - 4 - - - - - - Probe - - - - - Tunnel - - - NetName - OVF_RENDER - - - - - - Tunnel - - - rotation - - - - NetName - ST_RENDER - - - - - - Or - - - - - Tunnel - - - rotation - - - - NetName - RST - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - SQ_READA - - - - - - Tunnel - - - rotation - - - - NetName - PCLK - - - - - - Splitter - - - Input Splitting - 4 - - - Output Splitting - 3,1 - - - - - - Driver - - - Bits - 3 - - - - - - Tunnel - - - NetName - SEC_A - - - - - - Tunnel - - - NetName - ST_RENDER - - - - - - Tunnel - - - rotation - - - - NetName - SEC_D - - - - - - Splitter - - - Input Splitting - 32 - - - Output Splitting - 8,10,10,1,1,1,1 - - - - - - Tunnel - - - NetName - ST_IDLE - - - - - - LED - - - rotation - - - - - - - Text - - - Description - Stage 4 Idle - - - - - - Tunnel - - - NetName - TM_A - - - - - - Driver - - - Bits - 11 - - - - - - Tunnel - - - NetName - ST_RENDER - - - - - - Splitter - - - Input Splitting - 3,8 - - - Output Splitting - 11 - - - - - - Splitter - - - Input Splitting - 10 - - - Output Splitting - 3,7 - - - - - - Tunnel - - - NetName - TM_D - - - - - - Tunnel - - - rotation - - - - NetName - CLK_READB - - - - - - Or - - - - - Tunnel - - - rotation - - - - NetName - CLK_WRITE - - - - - - Tunnel - - - rotation - - - - NetName - CLK_READB - - - - - - Tunnel - - - rotation - - - - NetName - SM_A - - - - - - Probe - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_regbank.dig b/digital/atk16_regbank.dig deleted file mode 100644 index 5af841b..0000000 --- a/digital/atk16_regbank.dig +++ /dev/null @@ -1,1499 +0,0 @@ - - - 2 - - - romContent - - - - - - Width - 5 - - - - - In - - - Description - Data bus in - - - Label - Din - - - Bits - 16 - - - - - - Out - - - Description - Read register 1 data out - - - Label - D1 - - - Bits - 16 - - - - - - Out - - - Description - Read register 2 data out - - - Label - D2 - - - Bits - 16 - - - - - - Multiplexer - - - Selector Bits - 3 - - - Bits - 16 - - - - - - In - - - Description - Write register input enable - - - Label - RW_IE - - - - - - Multiplexer - - - Selector Bits - 3 - - - Bits - 16 - - - - - - In - - - Description - Write register select - - - Label - RW_S - - - Bits - 3 - - - - - - In - - - Description - Clock - - - Label - CLK - - - - - - In - - - Description - Read register 1 select - - - Label - R1_S - - - Bits - 3 - - - - - - Tunnel - - - NetName - Din - - - - - - Tunnel - - - NetName - RW_IE - - - - - - Register - - - valueIsProbe - true - - - Label - RA - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - Din - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Tunnel - - - NetName - Q1 - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - RW_IE - - - - - - Tunnel - - - rotation - - - - NetName - RW_A - - - - - - Register - - - valueIsProbe - true - - - Label - RB - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - Din - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Tunnel - - - NetName - Q2 - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - RW_IE - - - - - - Tunnel - - - rotation - - - - NetName - RW_B - - - - - - Register - - - valueIsProbe - true - - - Label - RC - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - Din - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Tunnel - - - NetName - Q3 - - - - - - And - - - - - Register - - - valueIsProbe - true - - - Label - RD - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - Din - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Tunnel - - - NetName - Q4 - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - RW_IE - - - - - - Tunnel - - - rotation - - - - NetName - RW_D - - - - - - Register - - - valueIsProbe - true - - - Label - RE - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - Din - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Tunnel - - - NetName - Q5 - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - RW_IE - - - - - - Tunnel - - - rotation - - - - NetName - RW_E - - - - - - Register - - - valueIsProbe - true - - - Label - RF - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - Din - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Tunnel - - - NetName - Q6 - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - RW_IE - - - - - - Tunnel - - - rotation - - - - NetName - RW_F - - - - - - Tunnel - - - rotation - - - - NetName - RW_IE - - - - - - Tunnel - - - rotation - - - - NetName - RW_C - - - - - - Decoder - - - Selector Bits - 3 - - - - - - In - - - Description - Read register 2 select - - - Label - R2_S - - - Bits - 3 - - - - - - Tunnel - - - NetName - CLK - - - - - - Testcase - - - Testdata - - CLK Din RW_IE RW_S R1_S R2_S D1 D2 -# store and read from RA works -C 0xF 1 1 0 X X X -C 0 0 0 1 X 0xF X -C 0x5 1 1 1 X 0x5 X -C 0 0 0 1 X 0x5 X - - - - - - - - Register - - - valueIsProbe - true - - - Label - RG - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - Din - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Tunnel - - - NetName - Q7 - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - RW_IE - - - - - - Tunnel - - - rotation - - - - NetName - RW_G - - - - - - Register - - - valueIsProbe - true - - - Label - RH - - - Bits - 16 - - - - - - Tunnel - - - rotation - - - - NetName - Din - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Tunnel - - - NetName - Q8 - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - RW_IE - - - - - - Tunnel - - - rotation - - - - NetName - RW_H - - - - - - Tunnel - - - NetName - RW_A - - - - - - Tunnel - - - NetName - RW_B - - - - - - Tunnel - - - NetName - RW_C - - - - - - Tunnel - - - NetName - RW_D - - - - - - Tunnel - - - NetName - RW_E - - - - - - Tunnel - - - NetName - RW_F - - - - - - Tunnel - - - NetName - RW_G - - - - - - Tunnel - - - NetName - RW_H - - - - - - Tunnel - - - rotation - - - - NetName - Q1 - - - - - - Tunnel - - - rotation - - - - NetName - Q2 - - - - - - Tunnel - - - rotation - - - - NetName - Q3 - - - - - - Tunnel - - - rotation - - - - NetName - Q4 - - - - - - Tunnel - - - rotation - - - - NetName - Q5 - - - - - - Tunnel - - - rotation - - - - NetName - Q6 - - - - - - Tunnel - - - rotation - - - - NetName - Q7 - - - - - - Tunnel - - - rotation - - - - NetName - Q8 - - - - - - Tunnel - - - rotation - - - - NetName - Q1 - - - - - - Tunnel - - - rotation - - - - NetName - Q2 - - - - - - Tunnel - - - rotation - - - - NetName - Q3 - - - - - - Tunnel - - - rotation - - - - NetName - Q4 - - - - - - Tunnel - - - rotation - - - - NetName - Q5 - - - - - - Tunnel - - - rotation - - - - NetName - Q6 - - - - - - Tunnel - - - rotation - - - - NetName - Q7 - - - - - - Tunnel - - - rotation - - - - NetName - Q8 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_tpu.dig b/digital/atk16_tpu.dig deleted file mode 100644 index f6b6398..0000000 --- a/digital/atk16_tpu.dig +++ /dev/null @@ -1,1165 +0,0 @@ - - - 2 - - - romContent - - - - - - Width - 6 - - - - - Out - - - Label - PR - - - Bits - 2 - - - - - - Out - - - Label - PG - - - Bits - 2 - - - - - - Out - - - Label - PB - - - Bits - 2 - - - - - - In - - - Label - MMIO_IE - - - - - - In - - - Label - MMIO_OE - - - - - - In - - - Description - MMI/O selector - - - Label - MMIO_S - - - Bits - 13 - - - - - - Tunnel - - - NetName - MMIO_IE - - - - - - Tunnel - - - NetName - MMIO_OE - - - - - - Tunnel - - - NetName - MMIO_S - - - - - - In - - - Description - Data bus - - - Label - DBUS - - - Bits - 16 - - - - - - In - - - Description - X pixel - - - Label - X - - - Bits - 9 - - - - - - Tunnel - - - NetName - X - - - - - - In - - - Description - Y pixel - - - Label - Y - - - Bits - 8 - - - - - - RAMDualPort - - - AddrBits - 11 - - - Label - TEXTMEM - - - Bits - 8 - - - - - - Tunnel - - - rotation - - - - NetName - Y - - - - - - Splitter - - - Input Splitting - 8 - - - Output Splitting - 3,5 - - - - - - Tunnel - - - rotation - - - - NetName - CCOLOR - - - - - - Splitter - - - Input Splitting - 1,1 - - - Output Splitting - 2 - - - - - - VDD - - - rotation - - - - - - - Tunnel - - - NetName - CHAR_S - - - - - - Tunnel - - - NetName - Y - - - - - - Tunnel - - - NetName - TY - - - - - - Tunnel - - - NetName - CY - - - - - - Probe - - - intFormat - dec - - - - - - EEPROM - - - AddrBits - 11 - - - Label - CHARMEM - - - Bits - 8 - - - Data - 8*0,7e,81,a5,81,bd,99,81,7e,7e,ff,db,ff,c3,e7,ff,7e,36,7f,7f,7f -,3e,1c,8,0,8,1c,3e,7f,3e,1c,8,0,1c,3e,1c,7f,7f,6b,8,1c,8,8,1c -,3e,7f,3e,8,1c,0,0,18,3c,3c,18,0,0,ff,ff,e7,c3,c3,e7,ff,ff,0,3c -,66,42,42,66,3c,9*0,f0,e0,f0,be,33,33,33,1e,3c,66,66,66,3c,18 -,7e,18,fc,cc,fc,c,c,e,f,7,fe,c6,fe,c6,c6,e6,67,3,18,db,3c,e7,e7 -,3c,db,18,1,7,1f,7f,1f,7,1,0,40,70,7c,7f,7c,70,40,0,18,3c,7e,18,18 -,7e,3c,18,5*66,0,66,0,fe,db,db,de,d8,d8,d8,0,7c,c6,1c,36,36,1c -,33,1e,4*0,7e,7e,7e,0,18,3c,7e,18,7e,3c,18,ff,18,3c,7e,4*18,0 -,4*18,7e,3c,18,0,0,18,30,7f,30,18,0,0,0,c,6,7f,6,c,4*0,3,3,3,7f -,0,0,0,24,66,ff,66,24,0,0,0,18,3c,7e,ff,ff,0,0,0,ff,ff,7e,3c,18 -,10*0,c,1e,1e,c,c,0,c,0,36,36,36,5*0,36,36,7f,36,7f,36,36,0,c -,3e,3,1e,30,1f,c,0,0,63,33,18,c,66,63,0,1c,36,1c,6e,3b,33,6e,0 -,6,6,3,5*0,18,c,6,6,6,c,18,0,6,c,18,18,18,c,6,0,0,66,3c,ff,3c -,66,0,0,0,c,c,3f,c,c,7*0,c,c,6,0,0,0,3f,9*0,c,c,0,60,30,18,c,6 -,3,1,0,3e,63,73,7b,6f,67,3e,0,c,e,4*c,3f,0,1e,33,30,1c,6,33,3f -,0,1e,33,30,1c,30,33,1e,0,38,3c,36,33,7f,30,78,0,3f,3,1f,30,30 -,33,1e,0,1c,6,3,1f,33,33,1e,0,3f,33,30,18,c,c,c,0,1e,33,33,1e -,33,33,1e,0,1e,33,33,3e,30,18,e,0,0,c,c,0,0,c,c,0,0,c,c,0,0,c,c -,6,18,c,6,3,6,c,18,0,0,0,3f,0,0,3f,0,0,6,c,18,30,18,c,6,0,1e,33 -,30,18,c,0,c,0,3e,63,7b,7b,7b,3,1e,0,c,1e,33,33,3f,33,33,0,3f -,66,66,3e,66,66,3f,0,3c,66,3,3,3,66,3c,0,1f,36,66,66,66,36,1f -,0,7f,46,16,1e,16,46,7f,0,7f,46,16,1e,16,6,f,0,3c,66,3,3,73,66 -,7c,0,33,33,33,3f,33,33,33,0,1e,5*c,1e,0,78,30,30,30,33,33,1e -,0,67,66,36,1e,36,66,67,0,f,6,6,6,46,66,7f,0,63,77,7f,7f,6b,63,63 -,0,63,67,6f,7b,73,63,63,0,1c,36,63,63,63,36,1c,0,3f,66,66,3e,6,6 -,f,0,1e,33,33,33,3b,1e,38,0,3f,66,66,3e,36,66,67,0,1e,33,6,c,18 -,33,1e,0,3f,2d,4*c,1e,0,6*33,3f,0,5*33,1e,c,0,63,63,63,6b,7f,77 -,63,0,63,63,36,1c,1c,36,63,0,33,33,33,1e,c,c,1e,0,7f,63,31,18 -,4c,66,7f,0,1e,5*6,1e,0,3,6,c,18,30,60,40,0,1e,5*18,1e,0,8,1c -,36,63,11*0,ff,c,c,18,7*0,1e,30,3e,33,6e,0,7,6,6,3e,66,66,3b,0,0,0 -,1e,33,3,33,1e,0,38,30,30,3e,33,33,6e,0,0,0,1e,33,3f,3,1e,0,1c -,36,6,f,6,6,f,0,0,0,6e,33,33,3e,30,1f,7,6,36,6e,66,66,67,0,c,0 -,e,c,c,c,1e,0,30,0,30,30,30,33,33,1e,7,6,66,36,1e,36,67,0,e,5*c -,1e,0,0,0,33,7f,7f,6b,63,0,0,0,1f,4*33,0,0,0,1e,33,33,33,1e,0,0,0 -,3b,66,66,3e,6,f,0,0,6e,33,33,3e,30,78,0,0,3b,6e,66,6,f,0,0,0 -,3e,3,1e,30,1f,0,8,c,3e,c,c,2c,18,0,0,0,4*33,6e,0,0,0,33,33,33 -,1e,c,0,0,0,63,6b,7f,7f,36,0,0,0,63,36,1c,36,63,0,0,0,33,33,33 -,3e,30,1f,0,0,3f,19,c,26,3f,0,38,c,c,7,c,c,38,0,18,18,18,0,18,18,18 -,0,7,c,c,38,c,c,7,0,6e,3b,7*0,8,1c,36,63,63,7f,0,0,fe,4*82,fe -,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0 -,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe -,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82 -,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe -,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0 -,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe -,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82 -,fe,0,0,fe,4*82,fe,9*0,18,18,0,4*18,0,18,18,7e,3,3,7e,18,18,1c -,36,26,f,6,67,3f,0,0,fe,4*82,fe,0,33,33,1e,3f,c,3f,c,c,0,fe,4*82 -,fe,0,7c,c6,1c,36,36,1c,33,1e,0,fe,4*82,fe,0,0,fe,4*82,fe,0,3c -,36,36,7c,0,7e,0,0,0,cc,66,33,66,cc,5*0,3f,30,30,0,0,0,fe,4*82 -,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,1c,36,36,1c,4*0,c,c,3f,c,c -,0,3f,0,e,18,c,6,1e,4*0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,4*66,3e -,6,3,fe,db,db,de,d8,d8,d8,5*0,18,4*0,fe,4*82,fe,0,0,fe,4*82,fe -,0,1c,36,36,1c,0,3e,0,0,0,33,66,cc,66,33,0,0,c3,63,33,db,ec,f6 -,f3,c0,c3,63,33,7b,cc,66,33,f0,0,fe,4*82,fe,0,c,0,c,6,3,33,1e -,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0 -,63,1c,36,63,7f,63,63,0,c,c,0,1e,33,3f,33,0,7c,36,33,7f,33,33 -,73,0,1e,33,3,33,1e,18,30,1e,0,fe,4*82,fe,0,38,0,3f,6,1e,6,3f -,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0 -,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,3f,0,33,37,3f,3b,33 -,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0 -,c3,18,3c,66,66,3c,18,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,0,fe,4*82 -,fe,0,0,fe,4*82,fe,0,0,fe,4*82,fe,0,33,0,4*33,1e,0,0,fe,4*82,fe -,0,0,fe,4*82,fe,0,0,1e,33,1f,33,1f,3,3,7,0,1e,30,3e,33,7e,0,38 -,0,1e,30,3e,33,7e,0,7e,c3,3c,60,7c,66,fc,0,0,fe,4*82,fe,0,33,0 -,1e,30,3e,33,7e,0,c,c,1e,30,3e,33,7e,0,0,0,fe,30,fe,33,fe,0,0,0 -,1e,3,3,1e,30,1c,7,0,1e,33,3f,3,1e,0,38,0,1e,33,3f,3,1e,0,7e,c3 -,3c,66,7e,6,3c,0,33,0,1e,33,3f,3,1e,0,7,0,e,c,c,c,1e,0,1c,0,e -,c,c,c,1e,0,3e,63,1c,18,18,18,3c,0,33,0,e,c,c,c,1e,0,0,fe,4*82 -,fe,0,0,1f,0,1f,33,33,33,0,0,7,0,1e,33,33,1e,0,0,38,0,1e,33,33 -,1e,0,1e,33,0,1e,33,33,1e,0,0,fe,4*82,fe,0,0,33,0,1e,33,33,1e -,0,c,c,0,3f,0,c,c,0,0,fe,4*82,fe,0,0,7,0,33,33,33,7e,0,0,38,0 -,33,33,33,7e,0,1e,33,0,33,33,33,7e,0,0,33,0,33,33,33,7e,0,0,fe -,4*82,fe,0,0,fe,4*82,fe,0,0,33,0,33,33,3e,30,1f - - - intFormat - bin - - - - - - Ground - - - rotation - - - - - - - VDD - - - rotation - - - - - - - VDD - - - rotation - - - - - - - Splitter - - - Input Splitting - 3,8 - - - Output Splitting - 11 - - - - - - Tunnel - - - rotation - - - - NetName - CHAR_S - - - - - - Tunnel - - - rotation - - - - NetName - CY - - - - - - BitSelector - - - Selector Bits - 3 - - - - - - Tunnel - - - NetName - CX - - - - - - Tunnel - - - NetName - CCOLOR - - - - - - Probe - - - intFormat - bin - - - - - - Probe - - - - - Probe - - - - - Multiplexer - - - Bits - 11 - - - - - - Tunnel - - - rotation - - - - NetName - TY - - - - - - And - - - Inputs - 3 - - - - - - Splitter - - - Input Splitting - 13 - - - Output Splitting - 11,1,1 - - - - - - Tunnel - - - rotation - - - - NetName - MMIO_S - - - - - - Tunnel - - - NetName - MMIOADDR - - - - - - Tunnel - - - rotation - - - - NetName - MMIOADDR - - - - - - Tunnel - - - rotation - - - - NetName - MMIOMATCH - - - - - - Tunnel - - - rotation - - - - NetName - DBUS_L8 - - - - - - Splitter - - - Input Splitting - 16 - - - Output Splitting - 8,8 - - - - - - Tunnel - - - NetName - DBUS_L8 - - - - - - Tunnel - - - NetName - MMIOMATCH - - - - - - Tunnel - - - rotation - - - - NetName - MMIO_IE - - - - - - Counter - - - Label - CLK divider /4 - - - - - - VDD - - - rotation - - - - - - - Ground - - - - - In - - - Description - Pixel clock - - - Label - PCLK - - - - - - Tunnel - - - NetName - CLK - - - - - - Tunnel - - - rotation - - - - NetName - X - - - - - - Splitter - - - Input Splitting - 9 - - - Output Splitting - 3,6 - - - - - - Tunnel - - - NetName - TX - - - - - - Tunnel - - - NetName - CX - - - - - - Tunnel - - - rotation - - - - NetName - CLK - - - - - - Tunnel - - - rotation - - - - NetName - TX - - - - - - Splitter - - - Input Splitting - 6,5 - - - Output Splitting - 11 - - - - - - VDD - - - rotation - - - - Bits - 2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_ucode_addr.dig b/digital/atk16_ucode_addr.dig deleted file mode 100644 index 682c90e..0000000 --- a/digital/atk16_ucode_addr.dig +++ /dev/null @@ -1,741 +0,0 @@ - - - 2 - - - romContent - - - - - - Width - 6 - - - - - In - - - Description - Flag selector from instruction - - - Label - FLAG_S - - - Bits - 3 - - - - - - In - - - Description - Flag register output value - - - Label - FR_Q - - - Bits - 4 - - - - - - In - - - Description - OPCODE - - - Label - OP - - - Bits - 4 - - - - - - Tunnel - - - NetName - OP - - - - - - Tunnel - - - NetName - FLAG_S - - - - - - Tunnel - - - NetName - FR_Q - - - - - - In - - - Description - Microsequencer value - - - Label - US_Q - - - Bits - 3 - - - - - - Tunnel - - - NetName - US_Q - - - - - - In - - - Description - Interrupt request bus - - - Label - IRQ - - - Bits - 4 - - - - - - PriorityEncoder - - - Selector Bits - 2 - - - Label - Interrupts - - - - - - Splitter - - - Input Splitting - 4 - - - Output Splitting - 1*4 - - - - - - Multiplexer - - - Bits - 5 - - - - - - Splitter - - - Input Splitting - 3,5 - - - - - - Tunnel - - - rotation - - - - NetName - US_Q - - - - - - Out - - - Label - ADDR - - - Bits - 8 - - - - - - And - - - - - Tunnel - - - rotation - - - - NetName - OP - - - - - - Splitter - - - Input Splitting - 1,4 - - - Output Splitting - 5 - - - - - - Tunnel - - - rotation - - - - NetName - FC - - - - - - Splitter - - - Input Splitting - 2,3 - - - Output Splitting - 5 - - - - - - BitSelector - - - Selector Bits - 2 - - - - - - Tunnel - - - rotation - - - - NetName - FLAG_S - - - - - - Splitter - - - rotation - - - - Input Splitting - 3 - - - Output Splitting - 2, - - - - - - Tunnel - - - rotation - - - - NetName - FR_Q - - - - - - Tunnel - - - NetName - FC - - - - - - Out - - - Description - Interrupt number - - - rotation - - - - Label - IT_N - - - Bits - 2 - - - - - - Out - - - Label - INT_ACTIVE - - - - - - In - - - Description - Interrupt mask assert active - - - Label - IM_EN - - - - - - In - - - Description - Interrupt mask assert not active - - - Label - IM_DS - - - - - - RS_FF_AS - - - valueIsProbe - true - - - Label - INT MASK - - - - - - D_FF - - - - - Comparator - - - Bits - 3 - - - - - - Const - - - Value - 0 - - - Bits - 3 - - - - - - Tunnel - - - rotation - - - - NetName - US_Q - - - - - - Const - - - Value - 6 - - - Bits - 3 - - - intFormat - bin - - - - - - Register - - - Label - INT LINE - - - Bits - 2 - - - - - - VDD - - - rotation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/digital/atk16_vga_sync.dig b/digital/atk16_vga_sync.dig deleted file mode 100644 index 7d42dea..0000000 --- a/digital/atk16_vga_sync.dig +++ /dev/null @@ -1,999 +0,0 @@ - - - 2 - - - romContent - - - - - - Width - 7 - - - - - Comparator - - - Bits - 10 - - - - - - Const - - - Value - 798 - - - Bits - 10 - - - intFormat - dec - - - - - - Counter - - - Bits - 10 - - - - - - VDD - - - rotation - - - - - - - Comparator - - - Bits - 10 - - - - - - Const - - - Value - 113 - - - Bits - 10 - - - intFormat - dec - - - - - - Comparator - - - Bits - 10 - - - - - - Const - - - Value - 16 - - - Bits - 10 - - - intFormat - dec - - - - - - NAnd - - - - - Tunnel - - - NetName - HSYNC - - - - - - Const - - - Value - 160 - - - Bits - 10 - - - intFormat - dec - - - - - - Sub - - - Bits - 10 - - - - - - Ground - - - - - Comparator - - - Bits - 10 - - - - - - Const - - - Value - 523 - - - Bits - 10 - - - intFormat - dec - - - - - - Counter - - - Bits - 10 - - - - - - VDD - - - rotation - - - - - - - Comparator - - - Bits - 10 - - - - - - Const - - - Value - 10 - - - Bits - 10 - - - intFormat - dec - - - - - - Comparator - - - Bits - 10 - - - - - - Const - - - Value - 13 - - - Bits - 10 - - - intFormat - dec - - - - - - Tunnel - - - NetName - VSYNC - - - - - - NAnd - - - - - Const - - - Value - 45 - - - Bits - 10 - - - intFormat - dec - - - - - - Sub - - - Bits - 10 - - - - - - Ground - - - - - Splitter - - - Input Splitting - 10 - - - Output Splitting - 1,8,1 - - - - - - Splitter - - - Input Splitting - 10 - - - Output Splitting - 1,9 - - - - - - Text - - - Description - Div 2 - - - - - - Text - - - Description - Div 2 - - - - - - In - - - Label - PCLK - - - - - - Probe - - - intFormat - dec - - - - - - Probe - - - intFormat - dec - - - - - - Out - - - Label - HSYNC - - - - - - Out - - - Label - VSYNC - - - - - - Tunnel - - - rotation - - - - NetName - HSYNC - - - - - - Tunnel - - - rotation - - - - NetName - VSYNC - - - - - - Out - - - Label - X - - - Bits - 9 - - - intFormat - dec - - - - - - Tunnel - - - rotation - - - - NetName - Y - - - - - - Out - - - Label - Y - - - Bits - 8 - - - intFormat - dec - - - - - - Tunnel - - - rotation - - - - NetName - X - - - - - - Comparator - - - Bits - 9 - - - - - - Const - - - Value - 319 - - - Bits - 9 - - - intFormat - dec - - - - - - Multiplexer - - - Bits - 9 - - - - - - Const - - - Value - 511 - - - Bits - 9 - - - intFormat - dec - - - - - - Tunnel - - - NetName - X - - - - - - Const - - - Value - 239 - - - Bits - 8 - - - intFormat - dec - - - - - - Multiplexer - - - Bits - 8 - - - - - - Const - - - Value - 255 - - - Bits - 8 - - - intFormat - dec - - - - - - Tunnel - - - NetName - Y - - - - - - Comparator - - - Bits - 8 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ibm_cga_8x8.ttf b/ibm_cga_8x8.ttf deleted file mode 100644 index 9f29ec5..0000000 Binary files a/ibm_cga_8x8.ttf and /dev/null differ diff --git a/resources/asm/aoc23_1a.atk16 b/resources/asm/aoc23_1a.atk16 new file mode 100644 index 0000000..78c4622 --- /dev/null +++ b/resources/asm/aoc23_1a.atk16 @@ -0,0 +1,554 @@ +;; 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/resources/asm/aoc23_1a.py b/resources/asm/aoc23_1a.py new file mode 100644 index 0000000..12e3953 --- /dev/null +++ b/resources/asm/aoc23_1a.py @@ -0,0 +1,48 @@ +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/resources/asm/ast_compiler_bootstrap.atk16 b/resources/asm/ast_compiler_bootstrap.atk16 new file mode 100644 index 0000000..2e112eb --- /dev/null +++ b/resources/asm/ast_compiler_bootstrap.atk16 @@ -0,0 +1,74 @@ +;; 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/resources/asm/bootstrap.atk16 b/resources/asm/bootstrap.atk16 new file mode 100644 index 0000000..4e5cd24 --- /dev/null +++ b/resources/asm/bootstrap.atk16 @@ -0,0 +1,71 @@ +; 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/resources/asm/ext_std.py b/resources/asm/ext_std.py new file mode 100644 index 0000000..247e605 --- /dev/null +++ b/resources/asm/ext_std.py @@ -0,0 +1,157 @@ +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/resources/asm/ext_string_io.py b/resources/asm/ext_string_io.py new file mode 100644 index 0000000..519077d --- /dev/null +++ b/resources/asm/ext_string_io.py @@ -0,0 +1,56 @@ +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/resources/asm/fibo.atk16 b/resources/asm/fibo.atk16 new file mode 100644 index 0000000..34999a9 --- /dev/null +++ b/resources/asm/fibo.atk16 @@ -0,0 +1,57 @@ +@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/resources/asm/idle_loop.atk16 b/resources/asm/idle_loop.atk16 new file mode 100644 index 0000000..dd7d879 --- /dev/null +++ b/resources/asm/idle_loop.atk16 @@ -0,0 +1,10 @@ +@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/resources/asm/sum.atk16 b/resources/asm/sum.atk16 new file mode 100644 index 0000000..1bc3277 --- /dev/null +++ b/resources/asm/sum.atk16 @@ -0,0 +1,32 @@ +@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/resources/asm/test_py_src.atk16 b/resources/asm/test_py_src.atk16 new file mode 100644 index 0000000..c38d1ca --- /dev/null +++ b/resources/asm/test_py_src.atk16 @@ -0,0 +1,301 @@ +;; 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/resources/asm/text_mode.atk16 b/resources/asm/text_mode.atk16 new file mode 100644 index 0000000..f20eac9 --- /dev/null +++ b/resources/asm/text_mode.atk16 @@ -0,0 +1,58 @@ +@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 diff --git a/resources/charset.txt b/resources/charset.txt new file mode 100644 index 0000000..bee1e3d Binary files /dev/null and b/resources/charset.txt differ diff --git a/resources/ibm_cga_8x8.ttf b/resources/ibm_cga_8x8.ttf new file mode 100644 index 0000000..9f29ec5 Binary files /dev/null and b/resources/ibm_cga_8x8.ttf differ diff --git a/resources/py/atk16.py b/resources/py/atk16.py new file mode 100644 index 0000000..9aa3c55 --- /dev/null +++ b/resources/py/atk16.py @@ -0,0 +1,39 @@ +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/resources/py/test_py_src.py b/resources/py/test_py_src.py new file mode 100644 index 0000000..619d22e --- /dev/null +++ b/resources/py/test_py_src.py @@ -0,0 +1,36 @@ +# 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/src/asm_eval.py b/src/asm_eval.py deleted file mode 100644 index c05fc03..0000000 --- a/src/asm_eval.py +++ /dev/null @@ -1,47 +0,0 @@ -constants: dict[str, str] = { - # Registers - "ra": "0", - "rb": "1", - "rc": "2", - "rd": "3", - "re": "4", - "rf": "5", - "rg": "6", - "rh": "7", - # ALU instructions - "al_plus": "0", - "al_minus": "1", - "al_and": "2", - "al_or": "3", - "al_xor": "4", - "al_slr": "5", - "al_sar": "6", - "al_sll": "7", - # ALU flags - "carry": "0", - "overflow": "1", - "zero": "2", - "sign": "3", -} - -Symbols = dict[str, int] - -def check_size(bits: int, val: int) -> None: - if val >= 2 ** bits: - raise Exception(f"Value does not fit in {bits} bits: 0x{val:>04x}") - -def eval_symbol(symbols: Symbols, c: str) -> str: - if c in symbols: - return str(symbols[c]) - - if c in constants: - return constants[c] - - return c - -def eval_expr(symbols: Symbols, expr: str, bits: int = 16) -> int: - expr = expr.lower() - expr = eval_symbol(symbols, expr) - ret = eval(expr, symbols.copy()) # eval as Python expr - check_size(bits, ret) - return ret diff --git a/src/asm_ops.py b/src/asm_ops.py deleted file mode 100644 index 885c275..0000000 --- a/src/asm_ops.py +++ /dev/null @@ -1,154 +0,0 @@ -from typing import Callable -from asm_eval import * -from dataclasses import dataclass - -@dataclass -class Meta: - address: int - -def make_alr(meta: Meta, symbols: Symbols, alu_op: str, left: str, right: str, target: str) -> int: - """ALR 0000 TTTL LLRR RSSS""" - target_e = eval_expr(symbols, target, bits=3) - left_e = eval_expr(symbols, left, bits=3) - right_e = eval_expr(symbols, right, bits=3) - alu_op_e = eval_expr(symbols, alu_op, bits=3) - word = (0b0000 << 12) + \ - (target_e << 9) + \ - (left_e << 6) + \ - (right_e << 3) + \ - alu_op_e - return word - -def make_ali(meta: Meta, symbols: Symbols, alu_op: str, left: str, imm: str, target: str) -> int: - """ALI 0001 TTTL LLII ISSS""" - target_e = eval_expr(symbols, target, bits=3) - left_e = eval_expr(symbols, left, bits=3) - imm_e = eval_expr(symbols, imm, bits=3) - alu_op_e = eval_expr(symbols, alu_op, bits=3) - word = (0b0001 << 12) + \ - (target_e << 9) + \ - (left_e << 6) + \ - (imm_e << 3) + \ - alu_op_e - return word - -def make_ldr(meta: Meta, symbols: Symbols, addr_reg: str, to_reg: str) -> int: - """LDR 0010 TTTR RRXX XXXX""" - to_reg_e = eval_expr(symbols, to_reg, bits=3) - addr_reg_e = eval_expr(symbols, addr_reg, bits=3) - word = (0b0010 << 12) + \ - (to_reg_e << 9) + \ - (addr_reg_e << 6) - return word - -def make_str(meta: Meta, symbols: Symbols, from_reg: str, addr_reg: str) -> int: - """STR 0011 XXXL LLRR RXXX""" - from_reg_e = eval_expr(symbols, from_reg, bits=3) - addr_reg_e = eval_expr(symbols, addr_reg, bits=3) - word = (0b0011 << 12) + \ - (addr_reg_e << 6) + \ - (from_reg_e << 3) - return word - -def make_ldi(meta: Meta, symbols: Symbols, imm: str, to_reg: str) -> int: - """LDI 0100 TTTI IIII IIII""" - to_reg_e = eval_expr(symbols, to_reg, bits=3) - imm_e = eval_expr(symbols, imm, bits=9) - word = (0b0100 << 12) + \ - (to_reg_e << 9) + \ - imm_e - return word - -def make_jpr(meta: Meta, symbols: Symbols, addr_reg: str) -> int: - """JPR 0101 XXXR RRXX XXXX""" - addr_reg_e = eval_expr(symbols, addr_reg, bits=3) - word = (0b0101 << 12) + \ - (addr_reg_e << 6) - return word - -def make_jpi(meta: Meta, symbols: Symbols, imm: str) -> int: - """JPI 0110 XXXI IIII IIII""" - imm_e = eval_expr(symbols, imm, bits=9) - imm_e = imm_e - meta.address - 1 - imm_e = imm_e & (0b111111111) - #print("symbols:", symbols) - #print(meta, imm, f"0x{imm_e:>0x}") - word = (0b0110 << 12) + \ - imm_e - return word - -def make_brr(meta: Meta, symbols: Symbols, flag_s: str, addr_reg: str) -> int: - """brr 0111 XFFR RRXX XXXX""" - flag_s_e = eval_expr(symbols, flag_s, bits=2) - addr_reg_e = eval_expr(symbols, addr_reg, bits=3) - word = (0b0111 << 12) + \ - (flag_s_e << 9) + \ - (addr_reg_e << 6) - return word - -def make_bri(meta: Meta, symbols: Symbols, flag_s: str, imm: str) -> int: - """BRI 1000 XFFI IIII IIII""" - flag_s_e = eval_expr(symbols, flag_s, bits=2) - imm_e = eval_expr(symbols, imm, bits=9) - imm_e = imm_e - meta.address - 1 - imm_e = imm_e & (0b111111111) - word = (0b1000 << 12) + \ - (flag_s_e << 9) + \ - imm_e - return word - -def make_lpc(meta: Meta, symbols: Symbols, target: str) -> int: - """LPC 1001 TTTX XXXX XXXX""" - target_e = eval_expr(symbols, target, bits=3) - word = (0b1001 << 12) + \ - (target_e << 9) - return word - -def make_rti(meta: Meta, symbols: Symbols) -> int: - """RTI 1110 XXXX XXXX XXXX""" - word = (0b1110 << 12) - return word - -def make_hlt(meta: Meta, symbols: Symbols) -> int: - """HLT 1111 XXXX XXXX XXXX""" - word = (0b1111 << 12) - return word - -OpWordDict = dict[str, Callable[..., int]] -operations: OpWordDict = { - "alr": make_alr, - "ali": make_ali, - "ldr": make_ldr, - "str": make_str, - "ldi": make_ldi, - "jpr": make_jpr, - "jpi": make_jpi, - "brr": make_brr, - "bri": make_bri, - "lpc": make_lpc, - "rti": make_rti, - "hlt": make_hlt, -} - -ExpandResult = list[list[str]] -ExpandFn = Callable[..., ExpandResult] -OpExpansionDict = dict[str, ExpandFn] - -def expand_id(*parts: str) -> ExpandResult: - return [list(parts)] - -default_expansions: OpExpansionDict = { - "alr": lambda *args: expand_id("alr", *args), - "ali": lambda *args: expand_id("ali", *args), - "ldr": lambda *args: expand_id("ldr", *args), - "str": lambda *args: expand_id("str", *args), - "ldi": lambda *args: expand_id("ldi", *args), - "jpr": lambda *args: expand_id("jpr", *args), - "jpi": lambda *args: expand_id("jpi", *args), - "brr": lambda *args: expand_id("brr", *args), - "bri": lambda *args: expand_id("bri", *args), - "lpc": lambda *args: expand_id("lpc", *args), - "rti": lambda *args: expand_id("rti", *args), - "hlt": lambda *args: expand_id("hlt", *args), -} - diff --git a/src/asm_pass0.py b/src/asm_pass0.py deleted file mode 100644 index f5b6b0b..0000000 --- a/src/asm_pass0.py +++ /dev/null @@ -1,50 +0,0 @@ -from dataclasses import dataclass -import os.path -from asm_ops import * -from asm_eval import * -from tokenizer import * - -@dataclass -class Result0Line: - line_num: int - src_file: str - line: str - -@dataclass -class Result0: - lines: list[Result0Line] - -def pass_0(lines: list[str], file_name: str) -> Result0: - result_lines: list[Result0Line] = [] - - for (line_num, line) in enumerate(lines): - line = line.split(";")[0].strip() - if line == "": continue - - keyword, *args = tokenize(line) - - match keyword: - case "@include": - asm_file_name = args[0] - path = os.path.join(os.path.dirname(file_name), asm_file_name + ".atk16") - with open(path, "r") as f: - incl_lines = f.readlines() - - incl_result0 = pass_0(incl_lines, asm_file_name) - for incl_line in incl_result0.lines: - result_lines.append(Result0Line( - src_file=incl_line.src_file, - line_num=incl_line.line_num, - line=incl_line.line - )) - - case _: - result_lines.append(Result0Line( - src_file=file_name, - line_num=line_num, - line=line - )) - - return Result0( - lines=result_lines - ) diff --git a/src/asm_pass1.py b/src/asm_pass1.py deleted file mode 100644 index 0b06738..0000000 --- a/src/asm_pass1.py +++ /dev/null @@ -1,48 +0,0 @@ -import importlib -import sys -import os.path -from dataclasses import dataclass -from asm_ops import * -from asm_eval import * -from asm_pass0 import * -from tokenizer import tokenize - -@dataclass -class Result1Line: - line_num: int - src_file: str - parts: list[str] - -@dataclass -class Result1: - lines: list[Result1Line] - operations: OpExpansionDict - -def pass_1(result0: Result0) -> Result1: - result_lines: list[Result1Line] = [] - operations: OpExpansionDict = default_expansions.copy() - - for line in result0.lines: - keyword, *args = tokenize(line.line) - match keyword: - case "@use": - module_name, ops = args[0].split(":") - ops_split = ops.split(",") - sys.path.append(os.path.dirname(line.src_file)) - module = importlib.import_module(module_name) - mod_expansions: OpExpansionDict = module.expansions - for op in mod_expansions: - expansion = mod_expansions[op] - if ops == "*" or op in ops_split: - operations[op] = expansion - case _: - result_lines.append(Result1Line( - src_file=line.src_file, - line_num=line.line_num, - parts=[keyword, *args] - )) - - return Result1( - operations=operations, - lines=result_lines - ) diff --git a/src/asm_pass2.py b/src/asm_pass2.py deleted file mode 100644 index e2ad4ec..0000000 --- a/src/asm_pass2.py +++ /dev/null @@ -1,40 +0,0 @@ -from dataclasses import dataclass -from asm_ops import * -from asm_eval import * -from asm_pass1 import * - -@dataclass -class Result2Line: - line_num: int - src_file: str - parts: list[str] - original_parts: list[str] - -@dataclass -class Result2: - lines: list[Result2Line] - operations: OpExpansionDict - -def pass_2(result1: Result1) -> Result2: - result_lines: list[Result2Line] = [] - - for line in result1.lines: - keyword, *args = line.parts - if keyword in result1.operations: - fn = result1.operations[keyword] - output: list[list[str]] = fn(*args) - else: - output = [line.parts] - - for (idx, parts) in enumerate(output): - result_lines.append(Result2Line( - line_num=line.line_num, - src_file=line.src_file, - parts=parts, - original_parts=line.parts if idx == 0 else ["..."] - )) - - return Result2( - operations=result1.operations, - lines=result_lines - ) diff --git a/src/asm_pass3.py b/src/asm_pass3.py deleted file mode 100644 index 9c8cb34..0000000 --- a/src/asm_pass3.py +++ /dev/null @@ -1,78 +0,0 @@ -from dataclasses import dataclass -from asm_ops import * -from asm_eval import * -from asm_pass2 import * - -@dataclass -class Result3Line: - line_num: int - src_file: str - address: int - parts: list[str] - original_parts: list[str] - -@dataclass -class Result3: - lines: list[Result3Line] - operations: OpExpansionDict - symbols: dict[str, int] - -def pass_3(result2: Result2) -> Result3: - result_lines: list[Result3Line] = [] - symbols: dict[str, int] = {} - address = 0 - - for line in result2.lines: - keyword, *args = line.parts - match keyword: - case "@address": - address = eval_expr(symbols, args[0]) - continue - case "@label": - label = args[0] - if label in symbols: - raise Exception(f"When defining label {label} as {address:>04x}, symbol {label} already defined as {symbols[label]:>04x}") - symbols[args[0]] = address - continue - case "@let": - symbols[args[0]] = eval_expr(symbols, args[1]) - continue - case _: - result_lines.append(Result3Line( - line_num=line.line_num, - src_file=line.src_file, - parts=line.parts, - address=address, - original_parts=line.original_parts, - )) - address += 1 - - result_lines.sort(key=lambda l: l.address) - for result_line in result_lines: - rows_with_same_addr = list(filter(lambda l: l.address == result_line.address, result_lines)) - n = len(rows_with_same_addr) - if n > 1: - formatted = format_overlapping_rows(rows_with_same_addr) - raise Exception(f"Overlapping segments: address 0x{result_line.address:>04x} has conflicting definitions:\n{formatted}") - return Result3( - operations=result2.operations, - lines=result_lines, - symbols=symbols, - ) - -def format_overlapping_rows(rows: list[Result3Line]) -> str: - longest_val = 0 - for row in rows: - joined = " ".join(row.parts) - if len(joined) > longest_val: - longest_val = len(joined) - - first_col_width = longest_val + 4 - - results: list[str] = [] - for row in rows: - joined = " ".join(row.parts) - result = joined + (first_col_width - len(joined)) * " " + f" ({row.src_file}:{row.line_num})" - results.append(result) - - return "\n".join(results) diff --git a/src/asm_pass4.py b/src/asm_pass4.py deleted file mode 100644 index 2fff870..0000000 --- a/src/asm_pass4.py +++ /dev/null @@ -1,61 +0,0 @@ -from dataclasses import dataclass -from asm_ops import * -from asm_eval import * -from asm_pass3 import * - -@dataclass -class Result4Line: - line_num: int - src_file: str - address: int - word: int - text: str - original_text: str - -@dataclass -class Result4: - lines: list[Result4Line] - operations: OpExpansionDict - symbols: dict[str, int] - -def pass_4(result3: Result3) -> Result4: - result_lines: list[Result4Line] = [] - - for line in result3.lines: - keyword, *args = line.parts - meta = Meta( - address=line.address, - ) - - text = " ".join([keyword, *args]) - original_text = " ".join(line.original_parts) - - if keyword in operations: - fn = operations[keyword] - word = fn(meta, result3.symbols, *args) - result_lines.append(Result4Line( - line_num=line.line_num, - src_file=line.src_file, - address=line.address, - word=word, - text=text, - original_text=original_text, - )) - else: - try: - result_lines.append(Result4Line( - line_num=line.line_num, - src_file=line.src_file, - address=line.address, - word=eval_expr(result3.symbols, keyword), - text=text, - original_text=original_text, - )) - except: - raise Exception(f"Invalid assembly at {line.src_file}:{line.line_num + 1}\n\n{line}") - - return Result4( - operations=result3.operations, - symbols=result3.symbols, - lines=result_lines, - ) diff --git a/src/assembler.py b/src/assembler.py deleted file mode 100755 index c678ba0..0000000 --- a/src/assembler.py +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env python3 -# Assemble ATK16 assembly to bytecode - -import sys -from asm_ops import * -from asm_eval import * -from asm_pass0 import pass_0 -from asm_pass1 import pass_1 -from asm_pass2 import pass_2 -from asm_pass3 import pass_3 -from asm_pass4 import pass_4 - -if len(sys.argv) != 3: - print("usage: assembler.py # read from file") - print(" assembler.py - # read from stdin") - sys.exit(1) - -infile_path = sys.argv[1] -outfile_path = sys.argv[2] - -src = "" -if (infile_path == "-"): - for line in sys.stdin: - src += line -else: - with open(infile_path, "r") as f: - src = f.read() - -src_lines = src.splitlines() - -### Utils - -def parse(line: str) -> list[str]: - depth = 0 - result: list[str] = [] - acc: str = "" - for c in line: - if c.isspace() and depth == 0: - result.append(acc) - acc = "" - elif c == "(": - depth += 1 - acc += "(" - elif c == ")": - depth -= 1 - acc += ")" - else: - acc += c - - result.append(acc) - return list(filter(lambda x: len(x) > 0, result)) - -result0 = pass_0(src_lines, infile_path) -result1 = pass_1(result0) -result2 = pass_2(result1) -result3 = pass_3(result2) -result4 = pass_4(result3) - -nop = bytearray([0b1000_0000, 0]) -result = bytearray() -# initially one nop -result.extend(nop) - -for line in result4.lines: - for (symbol, symbol_value) in result4.symbols.items(): - if line.address == symbol_value: - print(f"{symbol}:") - - if len(result) < 2 * line.address + 1: - result.extend((2 * line.address + 1 - len(result)) * nop) - - out_line = f"{line.address:>08x} 0x{line.word:>04x} {line.text}" - out_spaces_n = (42 - len(out_line)) - out_spaces = out_spaces_n * " " if out_spaces_n > 0 else 4 * " " - print(f"{out_line}{out_spaces}{line.original_text}") - result[2 * line.address + 0] = ((line.word >> 8) & 0xff) - result[2 * line.address + 1] = ((line.word >> 0) & 0xff) - -with open(outfile_path, "wb") as f: - f.write(result) - -print(f"Wrote {len(result)} bytes to {outfile_path}") diff --git a/src/ast_compiler.py b/src/ast_compiler.py deleted file mode 100644 index fe6f5a6..0000000 --- a/src/ast_compiler.py +++ /dev/null @@ -1,716 +0,0 @@ -#!/usr/bin/env python3 -# Generate .atk16 assembly from a subset of Python - -import sys -import ast - -from dataclasses import dataclass -from typing import Literal, Set, cast, Any, TypeAlias, TypeVar -from collections import OrderedDict - - -if len(sys.argv) != 3: - print("usage: ast_compiler.py ") - sys.exit(1) - -infile_path = sys.argv[1] -outfile_path = sys.argv[2] - -Label = str -StackOffset = int -RegChar = Literal["A", "B", "C", "D", "E", "F", "G", "H"] - -@dataclass -class Reg(): - reg: RegChar - - def __str__(self): - return f"R{self.reg}" - -ALL_REGS: list[RegChar] = ["A", "B", "C", "D", "E", "F", "G", "H"] -FRAME_POINTER_REG_CHAR: RegChar = "G" # points to base of stack frame -FRAME_POINTER_REG = Reg(FRAME_POINTER_REG_CHAR) -STACK_POINTER_REG_CHAR: RegChar = "H" -STACK_POINTER_REG = Reg(STACK_POINTER_REG_CHAR) -SPECIAL_REGS: list[RegChar] = [FRAME_POINTER_REG_CHAR, STACK_POINTER_REG_CHAR] -GENERIC_REGS: OrderedDict[RegChar, None] = OrderedDict() -for char in ALL_REGS: - if char not in SPECIAL_REGS: - GENERIC_REGS[cast(RegChar, char)] = None - -def format_asm_row(asm: str) -> str: - if not (asm.startswith("@") or asm.startswith(";")) and not asm.startswith(" ") and len(asm) > 0: - return " " + asm - else: - return asm - -class Compiler(ast.NodeVisitor): - def __init__(self): - self.const_asm: list[str] = [] - self.program_asm: list[str] = [ - "@label main" - ] - self.function_def_asms: list[str] = [] - self.currently_emitting_asm_list = self.program_asm - - self.local_bindings: dict[str, StackOffset] = {} - self.const_bindings: dict[str, Label] = {} - - self.unique_name_counter = 0 - self.latest_break_target: Label | None = None - - self.reserved_regs: OrderedDict[RegChar, None] = OrderedDict() - - def get_unique_name(self, prefix: str): - ret = f"{prefix}_{self.unique_name_counter}" - self.unique_name_counter += 1 - return ret - - def assign_const(self, name: str, value: int): - prev_currently_emitting_asm_list = self.currently_emitting_asm_list - self.currently_emitting_asm_list = self.const_asm - - self.emit_label(name) - self.emit(f"{value}") - - self.const_bindings[name] = name - - self.currently_emitting_asm_list = prev_currently_emitting_asm_list - - def emit(self, asm: str): - asm = asm.strip() - asm = format_asm_row(asm) - - self.currently_emitting_asm_list.append(asm) - - def emit_label(self, label_name: str): - label_name = label_name.lower() - self.emit(f"@label {label_name}") - - def alloc_reg(self) -> Reg: - for reg in GENERIC_REGS: - if not reg in self.reserved_regs: - self.reserved_regs[reg] = None - return Reg(reg) - - raise Exception("Ran out of registers, TODO use stack") - - def free_reg(self, reg: Reg): - self.reserved_regs.pop(reg.reg) - - class RegContextManager: - def __init__(self, compiler): - self.compiler = compiler - - def __enter__(self) -> Reg: - self.reg = self.compiler.alloc_reg() - return self.reg - - def __exit__(self, exc_type, exc_value, exc_tb): - self.compiler.free_reg(self.reg) - - def allocated_reg(self): - return Compiler.RegContextManager(self) - - def compile(self, bootstrap_asm: str, source: str) -> str: - tree = ast.parse(source) - print(ast.dump(tree, indent=4)) - self.visit(tree) - return "\n".join([ - bootstrap_asm, - "", - "\n".join(self.const_asm), - "", - "\n".join(self.function_def_asms), - "", - "\n".join(self.program_asm), - "" - ]) - - def generic_visit(self, node: ast.AST) -> Any: - raise NotImplementedError(f"type {type(node)}, value: {node}") - - def emit_builtin_call(self, name: str, args: list[ast.expr]): - self.emit(f"; Builtin call {name} {args}") - match name: - case "asm": - match args: - case [ast.Constant(str(value))]: - self.emit(value) - - # return None - with self.allocated_reg() as arg: - self.emit(f"ldi 0 {arg}") - self.emit(f"spu {arg}") - - case other: raise Exception(f"asm: invalid args: {other}") - - case "store": - if len(args) != 2: - raise Exception("Invalid number of arguments to store: " + str(len(args))) - - # Evaluate args before call - for arg in args: - self.visit(arg) - - with self.allocated_reg() as arg1, self.allocated_reg() as arg2: - self.emit(f"spo {arg2}") - self.emit(f"spo {arg1}") - self.emit(f"str {arg2} {arg1}") - - # return None - self.emit(f"ldi 0 {arg1}") - self.emit(f"spu {arg1}") - - case "load": - if len(args) != 1: - raise Exception("Invalid number of arguments to load: " + str(len(args))) - - self.visit(args[0]) - - self.emit("; (load) dereferencing top of stack") - with self.allocated_reg() as arg: - self.emit(f"spo {arg}") - self.emit(f"ldr {arg} {arg}") - self.emit(f"spu {arg}") - - case "ord": - if len(args) != 1: - raise Exception("Invalid number of arguments to ord: " + str(len(args))) - - self.visit(args[0]) - - case other: - raise Exception(f"Unknown builtin: {other}") - - def eval_int_constant_and_spu(self, value: int): - with self.allocated_reg() as reg: - if value >= 0 and value < 8: - self.emit(f"ldi {value} {reg}") - else: - name = self.get_unique_name("int") - self.assign_const(name, value) - self.emit(f"ldi {name} {reg}") - self.emit(f"ldr {reg} {reg} ; {name} = {value}") - - self.emit(f"spu {reg}") - - def emit_add_imm(self, reg1: str, addend: int, target_reg: str): - if addend >= 0 and addend < 8: - self.emit(f"addi {reg1} {addend} {target_reg}") - else: - name = self.get_unique_name("int") - self.assign_const(name, addend) - - with self.allocated_reg() as addend_reg: - self.emit(f"ldi {name} {addend_reg}") - self.emit(f"ldr {addend_reg} {addend_reg}") - self.emit(f"add {reg1} {addend_reg} {target_reg}") - - def visit_Module(self, node: ast.Module): - stmts = node.body - frame_names = self.collect_local_variables(stmts) - - self.emit("; stack frame with offsets") - for offset, name in enumerate(frame_names): - self.local_bindings[name] = offset - self.emit(f"; {name} {offset}") - - self.emit_add_imm("SP", len(frame_names), "SP") - - for stmt in stmts: - if type(stmt) == ast.Expr and type(stmt.value) != ast.Call: - self.emit("; NOP top-level expression") - continue - - self.visit(stmt) - - self.emit(f"mov FP SP") - self.emit("hlt") - - def visit_Expr(self, expr: ast.Expr): - self.visit(expr.value) - - with self.allocated_reg() as reg: - self.emit("; popping free-standing Expr result from stack") - self.emit(f"spo {reg}") - - def visit_UnaryOp(self, node: ast.UnaryOp): - self.emit(f"; {node.op}") - self.visit(node.operand) - match node.op: - case ast.Not(): - with self.allocated_reg() as reg1, self.allocated_reg() as reg2: - self.emit(f"spo {reg1}") - self.emit(f"ldi 1 {reg2}") - self.emit(f"andi {reg1} 1 {reg1}") - self.emit(f"xor {reg1} {reg2} {reg1}") - self.emit(f"spu {reg1}") - - case ast.Invert(): # aka bitwise not - with self.allocated_reg() as reg1: - self.emit(f"spo {reg1}") - self.emit(f"not {reg1}") - self.emit(f"spu {reg1}") - - case ast.UAdd(): # +a - pass # nop - - case ast.USub(): # -a - with self.allocated_reg() as reg1: - self.emit(f"spo {reg1}") - self.emit(f"not {reg1}") - self.emit(f"addi {reg1} 1 {reg1}") - self.emit(f"spu {reg1}") - - case other: - raise NotImplementedError(f"Unhandled UnaryOp: {other}") - - def visit_BoolOp(self, node: ast.BoolOp): - self.emit(f"; {node.op}") - - match node.op: - case ast.And(): - label_short_circuit = self.get_unique_name("And_short_circuit") - - with self.allocated_reg() as reg: - for arg in node.values: - self.emit(f"; And operand {arg}") - self.visit(arg) - - self.emit(f"spo {reg}") - self.emit(f"addi {reg} 0 {reg}") - self.emit(f"bri zero {label_short_circuit}") - - self.emit_label(label_short_circuit) - self.emit(f"spu {reg}") - - case ast.Or(): - label_short_circuit = self.get_unique_name("Or_short_circuit") - - with self.allocated_reg() as reg1, self.allocated_reg() as reg2: - for arg in node.values: - self.emit(f"; Or operand {arg}") - self.visit(arg) - - self.emit(f"spo {reg1}") - self.emit(f"subi {reg1} 1 {reg2}") - self.emit(f"bri carry {label_short_circuit}") - - self.emit_label(label_short_circuit) - self.emit(f"spu {reg1}") - - case other: - raise NotImplementedError(f"Unhandled BoolOp: {other}") - - def visit_BinOp(self, node: ast.BinOp): - self.emit(f"; {node.op}") - - self.emit(f"; BinOp lhs {node}") - self.visit(node.left) - self.emit(f"; BinOp rhs {node}") - self.visit(node.right) - - with self.allocated_reg() as reg1, self.allocated_reg() as reg2: - self.emit(f"spo {reg2}") - self.emit(f"spo {reg1}") - - match node.op: - case ast.Add(): - self.emit(f"add {reg1} {reg2} {reg1}") - case ast.Sub(): - self.emit(f"sub {reg1} {reg2} {reg1}") - case ast.BitAnd(): - self.emit(f"and {reg1} {reg2} {reg1}") - case ast.BitOr(): - self.emit(f"or {reg1} {reg2} {reg1}") - case ast.BitXor(): - self.emit(f"xor {reg1} {reg2} {reg1}") - case ast.LShift(): - self.emit(f"sll {reg1} {reg2} {reg1}") - case ast.RShift(): - self.emit(f"slr {reg1} {reg2} {reg1}") - case other: - raise NotImplementedError(f"Unhandled BinOp: {other}") - - self.emit(f"spu {reg1}") - - def visit_Constant(self, node: ast.Constant): - self.emit(f"; {node}") - match node.value: - case bool(value): - int_value = 1 if value else 0 - self.eval_int_constant_and_spu(int_value) - case int(value): - self.eval_int_constant_and_spu(value) - case str(value): - if len(value) > 1: - raise Exception("Invalid string, only single char values allowed: " + value) - - c = value[0] - int_value = ord(c) - self.eval_int_constant_and_spu(int_value) - case other: - raise NotImplementedError(f"Unhandled Constant: {other}") - - def visit_If(self, node: ast.If): - self.emit(f"; {node}") - - self.visit(node.test) - label_false = self.get_unique_name("If_false_branch") - label_end = self.get_unique_name("If_end_branch") - - with self.allocated_reg() as reg: - self.emit(f"spo {reg}") - self.emit(f"addi {reg} 0 {reg}") - self.emit(f"bri zero {label_false}") - - for true_branch_stmt in node.body: - if type(true_branch_stmt) == ast.Expr and type(true_branch_stmt.value) != ast.Call: - self.emit("; NOP top-level expression") - continue - - self.visit(true_branch_stmt) - - self.emit(f"jpi {label_end}") - self.emit_label(label_false) - - for false_branch_stmt in node.orelse: - if type(false_branch_stmt) == ast.Expr and type(false_branch_stmt.value) != ast.Call: - self.emit("; NOP top-level expression") - continue - - self.visit(false_branch_stmt) - - self.emit_label(label_end) - - def visit_Compare(self, node: ast.Compare): - self.emit(f"; {node}") - - if len(node.ops) > 1: - raise Exception("Multiple compare ops not supported") - - if len(node.comparators) > 1: - raise Exception("Multiple comparators not supported") - - op = node.ops[0] - left = node.left - right = node.comparators[0] - - label_true = self.get_unique_name("Compare_true") - label_end = self.get_unique_name("Compare_end") - - self.visit(left) - self.visit(right) - - self.emit(f"; Comparing {left} {op} {right}") - with self.allocated_reg() as reg_lhs, self.allocated_reg() as reg_rhs: - match op: - case ast.Lt(): # lhs < rhs - self.emit(f"spo {reg_rhs}") - self.emit(f"spo {reg_lhs}") - - self.emit(f"sub {reg_lhs} {reg_rhs} {reg_lhs}") - self.emit(f"bri carry {label_true}") - - # false branch - self.emit(f"ldi 0 {reg_lhs}") - self.emit(f"spu {reg_lhs}") - self.emit(f"jpi {label_end}") - - # true branch - self.emit_label(label_true) - self.emit(f"ldi 1 {reg_lhs}") - self.emit(f"spu {reg_lhs}") - - self.emit_label(label_end) - - def visit_While(self, node: ast.While): - self.emit(f"; {node}") - - label_test = self.get_unique_name("While_test") - label_else = self.get_unique_name("While_else") - label_end = self.get_unique_name("While_end") - - prev_break_target = self.latest_break_target - self.latest_break_target = label_end - - with self.allocated_reg() as reg: - self.emit_label(label_test) - self.visit(node.test) - self.emit(f"spo {reg}") - self.emit(f"addi {reg} 0 {reg}") - self.emit(f"bri zero {label_else}") - - for body_stmt in node.body: - if type(body_stmt) == ast.Expr and type(body_stmt.value) != ast.Call: - self.emit("; NOP top-level expression") - continue - - self.visit(body_stmt) - - self.emit(f"jpi {label_test}") - - self.emit_label(label_else) - - for else_stmt in node.orelse: - self.visit(else_stmt) - - self.emit_label(label_end) - - self.latest_break_target = prev_break_target - - def visit_Pass(self, node: ast.Pass): - self.emit(f"; {node}") - pass - - def visit_Break(self, node: ast.Break): - self.emit(f"; {node}") - - if self.latest_break_target is None: - raise Exception("Invalid break: no break target defined, i.e. no place to break out to") - - self.emit(f"jpi {self.latest_break_target}") - - def visit_For(self, node: ast.For): - raise Exception("For loops not supported. Consider using a while loop instead.") - - def visit_Lambda(self, node: ast.Lambda): - raise Exception("Lambda functions not supported. Consider using a named function instead.") - - def collect_local_variables(self, stmts: list[ast.stmt]): - result: list[str] = [] - symbols: list[str] = [] - for stmt in stmts: - match stmt: - case ast.Assign(targets=[ast.Name(name)]): - symbols.append(name) - case ast.Assign(other): - raise Exception(f"Unsupported assignment in function definition body: {other}") - case ast.While(body=body): - symbols += self.collect_local_variables(body) - case ast.If(body=tb, orelse=fb): - symbols += self.collect_local_variables(tb) - symbols += self.collect_local_variables(fb) - case other: pass - - for symbol in symbols: - if symbol not in result: - result.append(symbol) - - return result - - def visit_FunctionDef(self, node: ast.FunctionDef): - prev_currently_emitting_asm_list = self.currently_emitting_asm_list - self.currently_emitting_asm_list = self.function_def_asms - self.emit(f"; {node}") - - fn_name = node.name - fn_params = [str(param.arg) for param in node.args.args] - fn_stmts = node.body - - # Add a "return None" to the end to make sure the function returns - if len(fn_stmts) == 0 or type(fn_stmts[len(fn_stmts) - 1]) != ast.Return: - fn_stmts.append(ast.Return(value=None)) - - if len(node.args.kwonlyargs) > 0 or len(node.args.posonlyargs) > 0 or len(node.args.kw_defaults) > 0 or len(node.args.defaults) > 0: - raise Exception("Only simple positional args are supported for now in function definitions.") - - self.emit_label(fn_name) - local_var_names = self.collect_local_variables(fn_stmts) - frame_names = fn_params + local_var_names - - # Move stack pointer to accommodate local variables - if len(local_var_names) > 0: - self.emit_add_imm("SP", len(local_var_names), "SP") - - prev_local_bindings = self.local_bindings - self.local_bindings = {} - self.emit("; stack frame with offsets") - for offset, name in enumerate(frame_names): - self.local_bindings[name] = offset - self.emit(f"; {name} {offset}") - - for stmt in fn_stmts: - self.visit(stmt) - - self.local_bindings = prev_local_bindings - self.currently_emitting_asm_list = prev_currently_emitting_asm_list - - def visit_Return(self, node: ast.Return): - self.emit(f"; {node}") - - with self.allocated_reg() as reg1, self.allocated_reg() as reg2: - if node.value is not None: - self.visit(node.value) - else: - self.emit(f"ldi 0 {reg1}") - self.emit(f"spu {reg1}") - - self.emit(f"; return value is on top of stack") - - self.emit(f"; return from function") - self.emit(f"subi FP 1 FP") - self.emit(f"ldr FP {reg2}") - self.emit(f"jpr {reg2}") - - def visit_Call(self, node: ast.Call): - self.emit(f"; {node}") - - match node.func: - case ast.Attribute(ast.Name(id="atk16"), attr): - self.emit_builtin_call(attr, node.args) - case ast.Name(name): - self.emit(f"; Call function {name}") - - # Push the current FP - self.emit("spu FP") - #self.emit("mov SP FP") # BUG: FP needs to be moved AFTER EVALING ARGS! args depend on FP in calling frame if there are names to resolve! - - # Reserve a stack slot for the return address - # FP will point to this slot - with self.allocated_reg() as reg: - self.emit(f"ldi 0 {reg}") - self.emit(f"spu {reg}") - - # Evaluate args before call, pushing them to stack - for arg in node.args: - self.visit(arg) - - self.emit(f"subi SP {1 + len(node.args)} FP") - - with self.allocated_reg() as reg: - self.emit("; set up return address and jump to subroutine") - self.emit(f"lpc {reg}") - self.emit(f"addi {reg} 4 {reg}") # imm must equal number of primitive instrs from lpc until jpi - self.emit(f"str {reg} FP") - self.emit(f"addi FP 1 FP") - self.emit(f"jpi {name}") - # ...after return from call... - self.emit(f"spo {reg}") - - self.emit("mov FP SP") # move stack pointer to base of stack frame, i.e. top of previous frame - self.emit("spo FP") # restore FP of previous frame - self.emit(f"spu {reg}") - - case other: - raise NotImplementedError(f"Unhandled Call: {other}") - - def resolve_name(self, name: str) -> Label | StackOffset: - if name in self.local_bindings: - return self.local_bindings[name] - - if name in self.const_bindings: - return self.const_bindings[name] - - raise Exception(f"{name} is unbound") - - def visit_Name(self, node: ast.Name): - self.emit(f"; {node} ({node.id})") - - name = node.id.lower() - addr = self.resolve_name(name) - - with self.allocated_reg() as reg: - match addr: - case Label(label): - self.emit(f"ldi {label} {reg}") - case StackOffset(offset): - self.emit(f"ldi {offset} {reg}") - self.emit(f"add FP {reg} {reg}") - case other: - raise Exception(f"Unsupported addr value: {other}") - - self.emit(f"ldr {reg} {reg}") - self.emit(f"spu {reg}") - - def visit_Assign(self, node: ast.Assign): - self.emit(f"; {node}") - - targets = node.targets - value = node.value - match targets: - case [ast.Name(name)]: - offset = self.resolve_name(name) - - if type(offset) != StackOffset: - raise Exception(f"Invalid address {offset} for name {name}. Can only assign to stack offsets.") - - self.emit(f"; assigning {name} at FP + {offset}") - - with self.allocated_reg() as reg1, self.allocated_reg() as reg2: - self.emit(f"; evaluating value to be assigned") - self.visit(value) - self.emit(f"; assigning stack address (FP + {offset}) := top of stack") - self.emit(f"spo {reg1}") # value - - self.emit(f"ldi {offset} {reg2}") - self.emit(f"add {reg2} FP {reg2}") # address - self.emit(f"str {reg1} {reg2}") - - case other: - raise Exception(f"Unsupported assign targets: {other}") - - def visit_AugAssign(self, node: ast.AugAssign): - op = node.op - lhs = node.target - rhs = node.value - - if type(lhs) != ast.Name: - raise Exception("AugAssign to non-Name lhs not yet supported!") - - # construct bin op and assignment - bin_op = ast.BinOp(left=lhs, op=op, right=rhs) - assign = ast.Assign(targets=[lhs], value=bin_op) - - self.visit(assign) - - def visit_Import(self, node: ast.Import) -> Any: - match node.names: - case [ast.alias(name="atk16")]: - return - case other: - raise NotImplementedError(f"Unsupported import {other}") - - def visit_AnnAssign(self, node: ast.AnnAssign): - match node: - case ast.AnnAssign( - target=ast.Name(name), - annotation=ast.Attribute( - value=ast.Name(id="atk16"), - attr="ConstWord16"), - value=ast.Constant(value) # TODO: constant folding - ): - if type(value) == int: - self.assign_const(name.lower(), value) - return - - raise NotImplementedError("Unhandled AnnAssign:\n" + ast.dump(node, indent=4)) - - def get_module_exports(self, node: ast.Module): - result: list[str] = [] - for stmt in node.body: - match stmt: - case ast.FunctionDef(name): - result.append(name) - case _: - # only function exported since recognizing which assignments are constants is kinda hard - pass - - return result - -with open(infile_path, "r") as f: - source_py = f.read() - -with open("asm/ast_compiler_bootstrap.atk16", "r") as f: - bootstrap_asm = f.read() - -compiler = Compiler() -asm_out = compiler.compile( - bootstrap_asm, - source_py, -) - -with open(outfile_path, "w") as f: - f.write(asm_out) - diff --git a/src/bytecode_compiler.py b/src/bytecode_compiler.py deleted file mode 100644 index 0492ddb..0000000 --- a/src/bytecode_compiler.py +++ /dev/null @@ -1,220 +0,0 @@ -#!/usr/bin/env python3 -# Generate .atk16 assembly from a subset of Python - -import sys -import dis - -from dataclasses import dataclass -from typing import Literal, Set, cast, Any -from collections import OrderedDict - -if len(sys.argv) != 3: - print("usage: compiler.py ") - sys.exit(1) - -infile_path = sys.argv[1] -outfile_path = sys.argv[2] - -with open(infile_path, "r") as f: - source_py = f.read() - -compiled_code = compile(source_py, infile_path, 'exec') -disassembled = dis.get_instructions(compiled_code) - -co_consts = compiled_code.co_consts -co_names = compiled_code.co_names -print("### Constants") -print(co_consts) -print("\n### Names") -print(co_names) -print("\n### Instructions") -instrs: list[tuple[str, int | None]] = [] -for instr in disassembled: - print(f"{instr.opname}\t{instr.arg}") - instrs.append((instr.opname, instr.arg)) - -### compile -asm_out: list[str] = [] -def emit(stmt: str) -> int: - ret = len(asm_out) - asm_out.append(stmt) - return ret - -_counter = 0 -def get_unique_name(prefix: str): - global _counter - ret = f"{prefix}_{_counter}" - _counter += 1 - return ret - -@dataclass -class Label: - label: str - - def __str__(self): - return f"@label {self.label}" - -RegChar = Literal["A", "B", "C", "D", "E", "F", "G", "H"] -GENERIC_REGS_LST: list[RegChar] = ["A", "B", "C", "D", "E", "F"] -GENERIC_REGS: OrderedDict[RegChar, None] = OrderedDict() -for char in GENERIC_REGS_LST: - GENERIC_REGS[cast(RegChar, char)] = None - -@dataclass -class Reg: - reg: RegChar - - def __str__(self): - return f"R{self.reg}" - -Value = Label | Reg - -reserved_regs: OrderedDict[RegChar, None] = OrderedDict() -def alloc_reg() -> Reg: - for reg in GENERIC_REGS: - if not reg in reserved_regs: - reserved_regs[reg] = None - return Reg(reg) - - raise Exception("Ran out of registers, TODO use stack") - -def free_reg(reg: Reg): - reserved_regs.pop(reg.reg) - -def emit_serialize_const(const: Any): - match const: - case int(v): - emit(f" {v}") - case str(v): - if len(v) > 1: - raise Exception("Cannot serialize const string: " + v) - - emit(f" {ord(v[0])}") - case _: - print(f"warn: cannot serialize {type(const)} ({const}), emitting zero") - emit(" 0") - -STACK_POINTER_REG = Reg('H') -emit(f"@let SP {STACK_POINTER_REG}") -emit("@use ext_std:*") -emit("@include bootstrap") - -py_consts_addr = emit("@label py_consts") - -for const_i, const in enumerate(co_consts): - emit(f"; {const_i}: {const}") - emit_serialize_const(const) - -emit("@label atk_store") -_reg_value = alloc_reg() -_reg_addr = alloc_reg() -emit(f" str RB RA") -emit(f" rsr") -free_reg(_reg_value) -free_reg(_reg_addr) - -emit("@label atk_enable_text_mode") -emit(" set_graphics_mode gr_text_mode") -emit(" rsr") - -emit("@label main") - -instr_i = 0 - -def instr_pop(): - global instr_i - ret = instrs[instr_i] - instr_i += 1 - return ret - -def instr_pop_expect(opcode: str, arg: int | None = -1): - ret_op, ret_arg = instr_pop() - if ret_op != opcode: - raise Exception(f"Expected opcode {opcode}, got {ret_op}") - if arg != -1 and arg != ret_arg: - raise Exception(f"Expected instruction arg {arg}, got {ret_arg}") - return ret_op, ret_arg - -def instr_peek(): - return instrs[instr_i] - -def instr_peek_expect(opcode: str, arg: int | None = -1): - ret_op, ret_arg = instr_peek() - if ret_op != opcode: - raise Exception(f"Expected {opcode}, got {ret_op}") - if arg != -1 and arg != ret_arg: - raise Exception(f"Expected instruction arg {arg}, got {ret_arg}") - return ret_op, ret_arg - -instr_pop_expect("RESUME") -instr_pop_expect("LOAD_CONST", 0) -instr_pop_expect("LOAD_CONST", 1) -instr_pop_expect("IMPORT_NAME", 0) -instr_pop_expect("IMPORT_STAR", None) - -while instr_i < len(instrs): - opcode, arg = instr_pop() - emit(f"; {opcode} {arg}") - match opcode: - case "LOAD_CONST": - reg = alloc_reg() - emit(f" ldi ${{py_consts + {cast(int, arg)}}} {reg}") - emit(f" ldr {reg} {reg}") - emit(f" spu {reg}") - free_reg(reg) - case "PUSH_NULL": - reg = alloc_reg() - emit(f" ldi 0 {reg}") - emit(f" spu {reg}") - free_reg(reg) - case "LOAD_NAME": - name = co_names[cast(int, arg)] - reg = alloc_reg() - emit(f" ldi {name} {reg}") - emit(f" spu {reg}") - free_reg(reg) - case "CALL": - arg_count = cast(int, arg) - # if arg_count > len(GENERIC_REGS_LST): - # raise Exception(f"Function calls with > {len(GENERIC_REGS_LST)} arguments not supported") - - regs_to_restore: list[tuple[Reg, Reg]] = [] - for j in range(arg_count): - i = arg_count - j - 1 - ith_reg_char = GENERIC_REGS_LST[i] - ith_reg = Reg(ith_reg_char) - if ith_reg_char in reserved_regs: - reg = alloc_reg() - emit(f" mov {ith_reg} {reg}") - regs_to_restore.append((reg, ith_reg)) - - emit(f" spo {ith_reg}") - reserved_regs[ith_reg_char] = None # manually reserve ith_reg - - fn_reg = alloc_reg() - emit(f" spo {fn_reg}") - # emit(f" ldr {fn_reg} {fn_reg}") - emit(f" csr {fn_reg}") - free_reg(fn_reg) - - for from_reg, ith_reg in regs_to_restore: - emit(f" mov {from_reg} {ith_reg}") - - for j in range(arg_count): - i = arg_count - j - 1 - ith_reg_char = GENERIC_REGS_LST[i] - ith_reg = Reg(ith_reg_char) - free_reg(ith_reg) - - case "POP_TOP": - reg = alloc_reg() - emit(f" spo {reg}") - free_reg(reg) - case _: - print(f"Skipping not implemented opcode: {opcode}") - -emit("@label keep_alive") -emit(" jpi keep_alive") - -with open(outfile_path, "w") as f: - f.write("\n".join(asm_out)) diff --git a/src/charmem.py b/src/charmem.py deleted file mode 100644 index aaac122..0000000 --- a/src/charmem.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env python3 -# Generate .bin file with ATK16 CPU TPU charmem data - -# Addressed by _CCC CCCC CYYY -# Data width 8bit: ___X XXXX -# where _ = unused, C = 8bit character code, Y = character y coordinate, X = pixel value - -import sys - -if len(sys.argv) != 2: - print("usage: charmem.py ") - sys.exit(1) - -outfile_path = sys.argv[1] - -with open("charset.txt", "r") as f: - lines = [s.strip("\n") for s in f.readlines()] - -header_chars = lines[0] - -charset: list[list[str]] = [] - -CHAR_HEIGHT = 8 -CHAR_WIDTH = 8 - -i = 0 -while i < len(lines): - i += 1 # skip comment line - char = lines[i:i+CHAR_HEIGHT] - for row in char: - if len(row) != CHAR_WIDTH: - raise Exception(f"char row number {i} has width != {CHAR_WIDTH}: {len(row)}\n" + row + "\n" + "\n".join(char)) - charset.append(char) - i += CHAR_HEIGHT + 1 - -CHAR_N = len(charset) - -TOTAL_BYTEARRAY_SIZE = CHAR_N * CHAR_HEIGHT - -def string_to_byte(input_string: str): - # Replace spaces with '0' and '#' with '1' - binary_string = input_string.replace(' ', '0').replace('█', '1') - - assert(len(input_string) == CHAR_WIDTH) - - # Check if the string contains only '0' or '1' - if not all(c in '01' for c in binary_string): - raise ValueError("Input string must contain only spaces and '█' characters.") - - # Convert the binary string to an unsigned integer byte - return int(binary_string[::-1], 2) - - -res_b = bytearray(TOTAL_BYTEARRAY_SIZE) -for cn, char in enumerate(charset): - for cy in range(0, CHAR_HEIGHT): - addr = (cn << 3) + cy - byte = string_to_byte(char[cy]) - print(f"{byte:>08b}") - res_b[addr] = byte - -with open(outfile_path, "wb") as f: - f.write(res_b) diff --git a/src/convert_ttf.py b/src/convert_ttf.py deleted file mode 100644 index c1135cb..0000000 --- a/src/convert_ttf.py +++ /dev/null @@ -1,52 +0,0 @@ -from PIL import Image, ImageFont, ImageDraw - -import sys - -if len(sys.argv) != 3: - print("usage: convert_ttf.py ") - sys.exit(1) - -# Define the font file and size -font_file = sys.argv[1] -out_file = sys.argv[2] -font_size = 8 # 8x8 pixels - -# Create a font object -font = ImageFont.truetype(font_file, font_size) - - -# backspace 0x8, tab 0x9, newline 0xA, space 0x20 - -# Define the characters to render -#characters = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' - -def to_char_code(i: int) -> str: - if i == 10: - return " " - return chr(i) - -characters = [to_char_code(i) for i in range(0, 256)] - - -# Open a file to write the bitmaps to -with open(out_file, 'w') as bitmap_file: - for char_idx, char in enumerate(characters): - # Create a new image with a white background - image = Image.new('1', (8, 8), 1) - - # Create a drawing context - draw = ImageDraw.Draw(image) - - # Draw the character - draw.text((0, 0), char, font=font, fill=0) - - # Convert the image to a list of 0's and 1's - pixels = image.getdata() - bitmap = [1 if pixel == 0 else 0 for pixel in pixels] - - # Write the bitmap to the file - bitmap_file.write(f'Character {char_idx}: {char}\n') - for i in range(0, 64, 8): - row = bitmap[i:i+8] - bitmap_file.write(''.join(str(bit) for bit in row) + '\n') - bitmap_file.write('\n') diff --git a/src/dig_install.py b/src/dig_install.py deleted file mode 100644 index c32229b..0000000 --- a/src/dig_install.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env python3 -# Install a generated .bin file into a memory chip in a .dig circuit file - -import sys -from typing import cast -import xml.etree.ElementTree as ET - -if len(sys.argv) != 4: - print("usage: dig_install.py ") - sys.exit(1) - -infile = sys.argv[1] -circuitfile = sys.argv[2] -chip_label = sys.argv[3] - -with open(infile, "rb") as f: - program_bytes = f.read() - -i = 0 -program_words: list[str] = [] -while i < len(program_bytes): - hi_byte = program_bytes[i] - lo_byte = program_bytes[i + 1] - word = f"{hi_byte:>02x}{lo_byte:>02x}" - #print(word) - program_words.append(word) - i += 2 - -program_data = ",".join(program_words) -print("program_data:", program_data) - -tree = ET.parse(circuitfile) -root = tree.getroot() - -# Iterate through each 'visualElement' element -def find_data_element(root: ET.Element) -> ET.Element: - is_correct_visual_element = False - for visual_element in root.findall('.//visualElement'): - element_attributes = visual_element.find('elementAttributes') - if element_attributes is None: continue - - entries = list(element_attributes) - for entry in entries: - strings = entry.findall("string") - is_label_entry = len(strings) == 2 and strings[0].text == "Label" and strings[1].text == chip_label - if is_label_entry and not is_correct_visual_element: - is_correct_visual_element = True - continue - - is_data_entry = len(strings) == 1 and strings[0].text == "Data" - if is_data_entry and is_correct_visual_element: - data_element = entry.findall("data")[0] - return data_element - - raise Exception(f"No data entry matching label {chip_label} found in tree") - -data_element = find_data_element(root) -data_element.text = program_data - -tree.write(circuitfile) \ No newline at end of file diff --git a/src/optimizer.py b/src/optimizer.py deleted file mode 100644 index 0ee2837..0000000 --- a/src/optimizer.py +++ /dev/null @@ -1,189 +0,0 @@ -from tokenizer import tokenize - -def format_asm_row(asm: str) -> str: - if not (asm.startswith("@") or asm.startswith(";")) and not asm.startswith(" ") and len(asm) > 0: - return " " + asm - else: - return asm - -class Optimizer: - def __init__(self): - pass - - def optimize(self, asm_str: str): - asm = asm_str.split("\n") - asm = [row.strip() for row in asm] - asm = [self.strip_comment(row) for row in asm] - asm = [row for row in asm if not len(row) == 0] - asm = [tokenize(row, retain_curlies=True) for row in asm] - asm = self.compact_spu_spo_pattern(asm) - - # TODO: not safe when setting loading SP and FP - # ldr RA SP - # mov RA FP - # gets optimized to - # ldr RA FP - #asm = self.compact_target_mov_pattern(asm) - #asm = self.compact_target_mov_pattern(asm) - - # TODO: not safe at all. E.g. breaks a while True: pass loop - #asm = self.compact_mov_source_pattern(asm) - #asm = self.compact_mov_source_pattern(asm) - - asm = self.compact_spu_load_spo_pattern(asm) - # asm = self.convert_alr_to_ali(asm) - result = "\n".join([format_asm_row(" ".join(row)) for row in asm]) - - return result - - def strip_comment(self, row: str): - ret: str = "" - for c in row: - if c == ";": break - ret += c - - return ret - - def compact_spu_spo_pattern(self, asm: list[list[str]]) -> list[list[str]]: - i = 0 - result: list[list[str]] = [] - while i < len(asm): - current = asm[i] - next = asm[i + 1] if i + 1 < len(asm) else None - i += 1 - if current[0].startswith("@") or next is None: - result.append(current) - continue - - if current[0] == "spu" and next[0] == "spo": - print("=== compact_spu_spo_pattern") - print(current) - print(next) - - arg_current = current[1] - arg_next = next[1] - - print("=== arg_current:", arg_current) - print("=== arg_next:", arg_next) - - if arg_current == arg_next: - print("=== pass") - pass # remove both spu and spo - else: - print("=== mov") - mov = ["mov", arg_current, arg_next] - result.append(mov) - print("=== mov:", mov) - - print("=== last of result:", result[len(result) - 1]) - print() - i += 1 - continue - - result.append(current) - - return result - - def compact_target_mov_pattern(self, asm: list[list[str]]) -> list[list[str]]: - ops_with_target = ["ldi", "ldr", "add", "sub", "addi", "subi", "and", "or", "xor", "sll", "slr", "sar", "slli", "slri", "sari", "inc", "dec", "mov", "ali", "alr", "lpc"] - i = 0 - result: list[list[str]] = [] - while i < len(asm): - current = asm[i] - next = asm[i + 1] if i + 1 < len(asm) else None - i += 1 - if current[0].startswith("@") or next is None: - result.append(current) - continue - - if current[0] in ops_with_target and next[0] == "mov": - - op_op, op_operands, op_target_reg = current[0], current[1:len(current) - 1], current[len(current) - 1] - mov_from_reg, mov_to_reg = next[1], next[2] - - if op_target_reg == mov_from_reg: - ret = [op_op, *op_operands, mov_to_reg] - result.append(ret) - i += 1 - continue - - result.append(current) - - return result - - def compact_mov_source_pattern(self, asm: list[list[str]]) -> list[list[str]]: - ops_with_source = ["str", "ldr", "add", "sub", "addi", "subi", "and", "or", "xor", "sll", "slr", "sar", "slli", "slri", "sari", "mov", "ali", "alr"] - i = 0 - result: list[list[str]] = [] - while i < len(asm): - current = asm[i] - next = asm[i + 1] if i + 1 < len(asm) else None - i += 1 - if current[0].startswith("@") or next is None: - result.append(current) - continue - - if current[0] == "mov" and next[0] in ops_with_source: - mov_from_reg, mov_to_reg = current[1], current[2] - op_op, op_source_reg, op_operands = next[0], next[1], next[2:] - - if op_source_reg == mov_to_reg: - ret = [op_op, op_source_reg, *op_operands] - result.append(ret) - i += 1 - continue - - result.append(current) - - return result - - def compact_spu_load_spo_pattern(self, asm: list[list[str]]) -> list[list[str]]: - # spu RA - # ldi int_7 RA - # ldr RA RB - # spo RA - # OR - # spu RA - # ldi 3 RB - # spo RA - - i = 0 - result: list[list[str]] = [] - while i < len(asm): - instr0 = asm[i] - instr1 = asm[i + 1] if i + 1 < len(asm) else None - instr2 = asm[i + 2] if i + 2 < len(asm) else None - instr3 = asm[i + 3] if i + 3 < len(asm) else None - i += 1 - if instr0[0].startswith("@") or instr1 is None or instr2 is None or instr3 is None: - result.append(instr0) - continue - - if instr0[0] == "spu" and instr1[0] == "ldi" and instr2[0] == "ldr" and instr3[0] == "spo": - spu_op, spu_reg = instr0 - ldi_op, ldi_imm, ldi_target_reg = instr1 - ldr_op, ldr_from_reg, ldr_to_reg = instr2 - spo_op, spo_reg = instr3 - - if spu_reg == spo_reg and ldi_target_reg == ldr_from_reg and ldr_from_reg != ldr_to_reg: - ret0 = f"ldi {ldi_imm} {ldr_to_reg}".split() - ret1 = f"ldr {ldr_to_reg} {ldr_to_reg}".split() - result.append(ret0) - result.append(ret1) - i += 3 - continue - - elif instr0[0] == "spu" and instr1[0] == "ldi" and instr2[0] == "spo": - spu_op, spu_reg = instr0 - ldi_op, ldi_imm, ldi_target_reg = instr1 - spo_op, spo_reg = instr2 - - if spu_reg == spo_reg and ldi_target_reg != spu_reg: - ret0 = f"ldi {ldi_imm} {ldi_target_reg}".split() - result.append(ret0) - i += 2 - continue - - result.append(instr0) - - return result diff --git a/src/tokenizer.py b/src/tokenizer.py deleted file mode 100644 index cf31b56..0000000 --- a/src/tokenizer.py +++ /dev/null @@ -1,47 +0,0 @@ -def tokenize(line: str, retain_curlies = False) -> list[str]: - cur: str = "" - result: list[str] = [] - is_py_expr = False - is_string = False - idx = 0 - while idx < len(line): - c = line[idx] - if not is_py_expr and c == "$": - is_py_expr = True - if retain_curlies: - cur += "${" - idx += 1 - elif is_py_expr and c == "$": - raise Exception("Unexpected start of python expr while already parsing a python expression:\n" + line) - elif not is_py_expr and c == "}": - raise Exception("Unexpected end of python expr while not parsing a python expression:\n" + line) - elif is_py_expr and c == "}": - is_py_expr = False - if retain_curlies: - cur += c - result.append(cur) - cur = "" - elif is_py_expr: - cur += c - elif not is_string and c == "\"": - cur += "\"" - is_string = True - elif is_string and c == "\"": - cur += "\"" - is_string = False - result.append(cur) - cur = "" - elif is_string: - cur += c - elif c == " " or c == "\t": - result.append(cur) - cur = "" - else: - cur += c - - idx += 1 - - if len(cur) > 0: - result.append(cur) - - return [r for r in result if r != ""] \ No newline at end of file diff --git a/src/ucode.py b/src/ucode.py deleted file mode 100755 index 07d0554..0000000 --- a/src/ucode.py +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/env python3 -# Generate .bin file with ATK16 CPU microcode - -# Addressed by OOOO BUUU -# where O = opcode, B = branch flag, U = microsequencer value - -import sys - -if len(sys.argv) != 2: - print("usage: ucode.py ") - sys.exit(1) - -outfile_path = sys.argv[1] - -PC_CO = 1 << 0 -PC_IE = 1 << 1 -PC_OE = 1 << 2 -MAR_IE = 1 << 3 -MEM_IE = 1 << 4 -MEM_OE = 1 << 5 -RW_IE = 1 << 6 -R1_OE = 1 << 7 -R2_OE = 1 << 8 -IR_IE = 1 << 9 -IM_M = 1 << 10 -LI_OE = 1 << 11 -ALU_OE = 1 << 12 -FR_IE = 1 << 13 -HALT = 1 << 14 -US_RS = 1 << 15 -ISRA_OE = 1 << 16 -IM_DS = 1 << 17 -IM_EN = 1 << 18 -IPC_IE = 1 << 19 -IPC_OE = 1 << 20 -NOP5 = 1 << 21 -NOP6 = 1 << 22 -NOP7 = 1 << 23 - -BRANCH_FLAG_STATES_N = 2 -UCODE_N: int = 2**3 -CONTROL_WORD_SIZE = 3 - -def not_branch(bs: list[int]) -> list[list[int]]: - return BRANCH_FLAG_STATES_N * [bs] - -def branch(false_branch: list[int], true_branch: list[int]) -> list[list[int]]: - return [false_branch, true_branch] - -fetch = [PC_OE|MAR_IE, MEM_OE|IR_IE|PC_CO] - -def nop(): - return not_branch([*fetch, US_RS, 0, 0, 0, 0, 0]) - -ucode = [ - # ALR 0000 TTTL LLRR RSSS - not_branch([*fetch, ALU_OE|FR_IE|RW_IE, US_RS, 0, 0, 0, 0]), - # ALI 0001 TTTL LLII ISSS - not_branch([*fetch, IM_M|ALU_OE|FR_IE|RW_IE, US_RS, 0, 0, 0, 0]), - # LDR 0010 TTTR RRXX XXXX - not_branch([*fetch, R1_OE|MAR_IE, MEM_OE|RW_IE, US_RS, 0, 0, 0]), - # STR 0011 XXXL LLRR RXXX - not_branch([*fetch, R1_OE|MAR_IE, R2_OE|MEM_IE, US_RS, 0, 0, 0]), - # LDI 0100 TTTI IIII IIII - not_branch([*fetch, LI_OE|RW_IE, US_RS, 0, 0, 0, 0]), - # JPR 0101 XXXR RRXX XXXX - not_branch([*fetch, R1_OE|PC_IE, US_RS, 0, 0, 0, 0]), - # JPI 0110 XXXI IIII IIII - not_branch([*fetch, IM_M|LI_OE|PC_IE, US_RS, 0, 0, 0, 0]), - # BRR 0111 XFFR RRXX XXXX - branch([*fetch, US_RS, 0, 0, 0, 0, 0], - [*fetch, R1_OE|PC_IE, US_RS, 0, 0, 0, 0]), - # BRI 1000 XFFI IIII IIII - branch([*fetch, US_RS, 0, 0, 0, 0, 0], - [*fetch, IM_M|LI_OE|PC_IE, US_RS, 0, 0, 0, 0]), - # LPC 1001 TTTX XXXX XXXX - not_branch([*fetch, PC_OE|RW_IE, US_RS, 0, 0, 0, 0]), - # NOP 1010 XXXX XXXX XXXX - nop(), - # NOP 1011 XXXX XXXX XXXX - nop(), - # ISRP0 1100 XXXX XXXX XXXX - not_branch([IM_EN|PC_OE|IPC_IE, ISRA_OE|MAR_IE, MEM_OE|PC_IE, US_RS, 0, 0, 0, 0]), - # ISRP1 1101 XXXX XXXX XXXX - not_branch([IM_EN|PC_OE|IPC_IE, ISRA_OE|MAR_IE, MEM_OE|PC_IE, US_RS, 0, 0, 0, 0]), - # RTI 1110 XXXX XXXX XXXX - not_branch([*fetch, IM_DS|IPC_OE|PC_IE, US_RS, 0, 0, 0, 0]), - # HLT 1111 XXXX XXXX XXXX - not_branch([*fetch, HALT, 0, 0, 0, 0, 0]), -] - -INST_N = len(ucode) -TOTAL_BYTEARRAY_SIZE = INST_N * BRANCH_FLAG_STATES_N * UCODE_N * CONTROL_WORD_SIZE - -res_b = bytearray(TOTAL_BYTEARRAY_SIZE) - -for i in range(INST_N): - for j in range(BRANCH_FLAG_STATES_N): - for k in range(UCODE_N): - for l in range(CONTROL_WORD_SIZE): - idx = l + \ - k * CONTROL_WORD_SIZE + \ - j * CONTROL_WORD_SIZE * UCODE_N + \ - i * CONTROL_WORD_SIZE * UCODE_N * BRANCH_FLAG_STATES_N - cword = ucode[i][j][k] - assert len(ucode[i][j]) == 8 - cbyte = (cword >> (8 * (CONTROL_WORD_SIZE - l - 1))) & 0xff - print(f"inst: {i:>04b}, idx: {idx:>04x}, cbyte: {cbyte:>08b}") - res_b[idx] = cbyte - -with open(outfile_path, "wb") as f: - f.write(res_b) -- cgit v1.3