From 02cbabcd735e6367b87fa4401f7a5df89813a6f7 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Fri, 3 Nov 2023 01:01:14 +0200 Subject: Add graphics mode selector --- asm/bootstrap.atk16 | 69 +++++--- asm/text_mode.atk16 | 17 ++ digital/atk16.dig | 371 ++++++++++++++++++++++++++++++++++------ digital/atk16_graphics_mode.dig | 311 +++++++++++++++++++++++++++++++++ digital/atk16_mem.dig | 6 +- digital/atk16_ppu.dig | 253 ++++++++++++++++----------- src/asm_ops.py | 4 +- src/asm_pass3.py | 19 +- 8 files changed, 872 insertions(+), 178 deletions(-) create mode 100644 asm/text_mode.atk16 create mode 100644 digital/atk16_graphics_mode.dig diff --git a/asm/bootstrap.atk16 b/asm/bootstrap.atk16 index 813ebb5..2aa5d88 100644 --- a/asm/bootstrap.atk16 +++ b/asm/bootstrap.atk16 @@ -1,42 +1,65 @@ -@let stack_segment 0x8000 -@let vector_table 0x10 -@let mmio_segment 0xE000 -@let terminal_addr 0xE000 -@let keyboard_addr 0xE001 -@let sprite_mem 0xE800 +; vector table fields +@let vector_table 0x10 +@let vt_ISRO 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 + +; 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 + +; graphics mode settings +@let gr_disabled_mode 0b00 +@let gr_text_mode 0b01 +@let gr_sprite_mode 0b10 @address vector_table - keyboard_isr ; 0x10 ISR0 - hlt_isr ; 0x11 ISR1 - hlt_isr ; 0x12 ISR2 - hlt_isr ; 0x13 ISR3 - stack_segment ; 0x14 Stack address - 0x0 ; 0x15 - terminal_addr ; 0x16 Terminal peripheral address - keyboard_addr ; 0x17 Keyboard peripheral address + 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 @label hlt_isr ldi 0x55 RE hlt @label keyboard_isr - spu RA ; use RA, RB + spu RA ; use RA, RB spu RB - ldi 0x17 RA ; RA := 0x17 Keyboard peripheral address pointer - ldr RA RA ; RA := 0xE001 Keyboard peripheral address deref - ldr RA RA ; RA := <16-bit keyboard character code> from MMIO register - ldi 0x16 RB ; RB := 0x16 Terminal peripheral address pointer - ldr RB RB ; RB := 0xE000 Terminal peripheral address deref - str RA RB ; terminal <- character code - spo RB ; restore RA, RB + ldi vt_kb_pp_addr RA ; RA := 0x17 Keyboard peripheral address pointer + ldr RA RA ; RA := 0xE001 Keyboard peripheral address deref + ldr RA RA ; RA := <16-bit keyboard character code> from MMIO register + ldi vt_term_pp_addr RB ; RB := 0x16 Terminal peripheral address pointer + ldr RB RB ; RB := 0xE000 Terminal peripheral address deref + str RA RB ; terminal <- character code + spo RB ; restore RA, RB spo RA rti @label program_segment @address 0x0 ; set up stack pointer to point to beginning of stack segment - ldi 0x14 RA + ldi vt_stack_addr RA ldr RA RF +; set graphics mode to disabled + ldi vt_gr_mode_addr RA + ldr RA RA + ldi gr_disabled_mode RB + str RB RA +; jump to main (user defined) jpi main @address program_segment diff --git a/asm/text_mode.atk16 b/asm/text_mode.atk16 new file mode 100644 index 0000000..05b4fd3 --- /dev/null +++ b/asm/text_mode.atk16 @@ -0,0 +1,17 @@ +@opt stack_pointer RF +@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 + ; set graphics mode to gr_text_mode + ldi vt_gr_mode_addr RA + ldr RA RA + ldi gr_text_mode RB + str RB RA + +@label loop + jpi loop diff --git a/digital/atk16.dig b/digital/atk16.dig index 1b9dcc5..323ef10 100644 --- a/digital/atk16.dig +++ b/digital/atk16.dig @@ -1223,11 +1223,6 @@ - - Break - - - Tunnel @@ -1267,11 +1262,6 @@ - - atk16_ppu.dig - - - Tunnel @@ -1402,12 +1392,122 @@ 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 + + + + + + Multiplexer + + + Selector Bits + 2 + + + Bits + 8 + + + + + + Tunnel + + + rotation + + + + NetName + GRMODE + + + + + + atk16_ppu.dig + + + + + Tunnel + + + rotation + + + + NetName + CLK + + + Tunnel @@ -1421,7 +1521,7 @@ MMIO_IE - + Tunnel @@ -1435,7 +1535,7 @@ MMIO_S - + Tunnel @@ -1449,7 +1549,7 @@ MMIO_OE - + Tunnel @@ -1463,7 +1563,78 @@ DBUS - + + + + Splitter + + + Input Splitting + 2,2,2,1,1 + + + + + + Tunnel + + + rotation + + + + NetName + PCLK + + + + + + VGA + + + + + Tunnel + + + rotation + + + + NetName + PCLK + + + + + + Splitter + + + Input Splitting + 8 + + + Output Splitting + 2,2,2,1,1 + + + + + + Const + + + Value + 0 + + + Bits + 8 + + + @@ -1499,10 +1670,6 @@ - - - - @@ -1527,14 +1694,26 @@ - - - - + + + + + + + + + + + + + + + + @@ -1559,6 +1738,18 @@ + + + + + + + + + + + + @@ -1615,6 +1806,14 @@ + + + + + + + + @@ -1647,6 +1846,10 @@ + + + + @@ -1659,10 +1862,6 @@ - - - - @@ -1687,6 +1886,10 @@ + + + + @@ -1731,6 +1934,18 @@ + + + + + + + + + + + + @@ -1763,6 +1978,18 @@ + + + + + + + + + + + + @@ -1785,10 +2012,6 @@ - - - - @@ -1807,6 +2030,10 @@ + + + + @@ -1843,6 +2070,10 @@ + + + + @@ -1851,10 +2082,6 @@ - - - - @@ -1879,6 +2106,10 @@ + + + + @@ -1887,10 +2118,6 @@ - - - - @@ -1935,6 +2162,18 @@ + + + + + + + + + + + + @@ -1995,6 +2234,26 @@ + + + + + + + + + + + + + + + + + + + + @@ -2015,6 +2274,14 @@ + + + + + + + + @@ -2039,10 +2306,6 @@ - - - - @@ -2059,6 +2322,14 @@ + + + + + + + + @@ -2075,10 +2346,6 @@ - - - - @@ -2173,12 +2440,16 @@ - + + + + + @@ -2203,6 +2474,10 @@ + + + + diff --git a/digital/atk16_graphics_mode.dig b/digital/atk16_graphics_mode.dig new file mode 100644 index 0000000..2d05dd6 --- /dev/null +++ b/digital/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/atk16_mem.dig b/digital/atk16_mem.dig index a3d8b5e..4c1db35 100644 --- a/digital/atk16_mem.dig +++ b/digital/atk16_mem.dig @@ -35,9 +35,9 @@ Data - 4014,2a00,6026,13*8000,1a,18,18,18,8000,0,e000,e001,4855,f000 -,3140,1b48,3148,1b48,4017,2000,2000,4216,2240,3040,1b49,2340,1b49 -,2140,e000,61ff + 4014,2a00,4017,2000,4200,3008,6022,9*8000,1a,18,18,18,8000,e000 +,e001,e002,4855,f000,3140,1b48,3148,1b48,4016,2000,2000,4215,2240 +,3040,1b49,2340,1b49,2140,e000,4017,2000,4201,3008,61ff diff --git a/digital/atk16_ppu.dig b/digital/atk16_ppu.dig index d9064dd..c2cbdba 100644 --- a/digital/atk16_ppu.dig +++ b/digital/atk16_ppu.dig @@ -553,95 +553,6 @@ sprite mem, starting from 0x0800 - - VGA - - - - - Tunnel - - - rotation - - - - NetName - PCLK - - - - - - Tunnel - - - rotation - - - - NetName - HSYNC - - - - - - Tunnel - - - rotation - - - - NetName - VSYNC - - - - - - Tunnel - - - rotation - - - - NetName - PR - - - - - - Tunnel - - - rotation - - - - NetName - PG - - - - - - Tunnel - - - rotation - - - - NetName - PB - - - - Const @@ -991,6 +902,142 @@ sprite mem, starting from 0x0800 + + Out + + + Label + PR + + + Bits + 2 + + + + + + Out + + + Label + PG + + + Bits + 2 + + + + + + Out + + + Label + PB + + + Bits + 2 + + + + + + Out + + + Label + HSYNC + + + + + + Out + + + Label + VSYNC + + + Bits + 2 + + + + + + Tunnel + + + rotation + + + + NetName + PB + + + + + + Tunnel + + + rotation + + + + NetName + PR + + + + + + Tunnel + + + rotation + + + + NetName + PG + + + + + + Tunnel + + + rotation + + + + NetName + HSYNC + + + + + + Tunnel + + + rotation + + + + NetName + VSYNC + + + + @@ -1026,12 +1073,8 @@ sprite mem, starting from 0x0800 - - - - - - + + @@ -1057,6 +1100,10 @@ sprite mem, starting from 0x0800 + + + + @@ -1134,8 +1181,8 @@ sprite mem, starting from 0x0800 - - + + @@ -1177,6 +1224,10 @@ sprite mem, starting from 0x0800 + + + + @@ -1241,10 +1292,6 @@ sprite mem, starting from 0x0800 - - - - @@ -1253,6 +1300,10 @@ sprite mem, starting from 0x0800 + + + + diff --git a/src/asm_ops.py b/src/asm_ops.py index 78ec356..a2631e3 100644 --- a/src/asm_ops.py +++ b/src/asm_ops.py @@ -76,8 +76,8 @@ def make_jpi(meta: Meta, symbols: Symbols, imm: str) -> int: 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}") + #print("symbols:", symbols) + #print(meta, imm, f"0x{imm_e:>0x}") word = (0b0110 << 12) + \ imm_e return word diff --git a/src/asm_pass3.py b/src/asm_pass3.py index 5221f6d..edfd79f 100644 --- a/src/asm_pass3.py +++ b/src/asm_pass3.py @@ -50,7 +50,7 @@ def pass_3(result2: Result2) -> Result3: 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 = "\n".join(map(lambda l: " ".join(l.parts), rows_with_same_addr)) + 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, @@ -58,3 +58,20 @@ def pass_3(result2: Result2) -> Result3: 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) -- cgit v1.3