From d956f3841ad867d631fbe2324cb6e280bc9b2a66 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Fri, 3 Nov 2023 14:59:15 +0200 Subject: Get text rendering working --- Makefile | 4 + asm/text_mode.atk16 | 4 +- charset.txt | 208 ++++++++++++++++++ digital/atk16_mem.dig | 2 +- digital/atk16_tpu.dig | 591 ++++++++++++++++++++++++++++++++++++-------------- src/charmem.py | 60 +++++ src/charset.py | 14 -- src/charset.txt | 208 ------------------ 8 files changed, 705 insertions(+), 386 deletions(-) create mode 100644 charset.txt create mode 100644 src/charmem.py delete mode 100644 src/charset.py delete mode 100644 src/charset.txt diff --git a/Makefile b/Makefile index f3366b0..9fdc5e2 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,10 @@ assemble: gen-ucode: $(py) src/ucode.py $(out) +# make gen-charmem out=out/charmem.bin +gen-charmem: + $(py) src/charmem.py $(out) + # make test test: $(py) src/test_alu.py digital/atk16_alu.dig diff --git a/asm/text_mode.atk16 b/asm/text_mode.atk16 index b48305a..8fbdb83 100644 --- a/asm/text_mode.atk16 +++ b/asm/text_mode.atk16 @@ -8,8 +8,8 @@ @label main ; set graphics mode to sprite mode - set_graphics_mode gr_sprite_mode - ;set_graphics_mode gr_text_mode + ; set_graphics_mode gr_sprite_mode + set_graphics_mode gr_text_mode @label loop jpi loop diff --git a/charset.txt b/charset.txt new file mode 100644 index 0000000..0b68a45 --- /dev/null +++ b/charset.txt @@ -0,0 +1,208 @@ +% ABCDEFGHIJKLMNOPQRSTUVWXYZ + + + + + + + + ## +# # +# # +#### +# # +# # +# # + +## +# # +# # +### +# # +# # +#### + + ## +# # +# +# +# +# # + ## + +#### +# +# +## +# +# +#### + +#### +# +# +## +# +# +# + + ## +# # +# +# +# ## +# # + ## + +# # +# # +#### +# # +# # +# # +# # + +### + # + # + # + # + # +### + + ### + # + # + # + # +# # + ## + +# # +# # +## +# # +# # +# # +# # + +# +# +# +# +# +# +#### + +# # +#### +#### +# # +# # +# # +# # + +# # +## # +## # +# ## +# ## +# # +# # + + ## +# # +# # +# # +# # +# # + ## + +### +# # +# # +### +# +# +# + + ## +# # +# # +# # +# ## + ### + # + +### +# # +# # +### +## +# # +# # + + ## +# # +# + ## + # +# # + ## + +### + # + # + # + # + # + # + +# # +# # +# # +# # +# # +# # + ### + +# # +# # +# # +# # +# # +# # + ## + +# # +# # +# # +# # +#### +#### +# # + +# # +# # + ## +# # +# # +# # +# # + +# # +# # +# # + ### + # +# # + ### + +#### + # + # + # + # +# +#### + \ No newline at end of file diff --git a/digital/atk16_mem.dig b/digital/atk16_mem.dig index 1fa106b..c3f000a 100644 --- a/digital/atk16_mem.dig +++ b/digital/atk16_mem.dig @@ -37,7 +37,7 @@ Data 4014,2a00,6027,13*8000,1a,18,18,18,8000,e000,e001,e002,4855,f000 ,3140,1b48,3148,1b48,4016,2000,2000,4215,2240,3040,1800,3148,1b48 -,3140,1b48,e000,4017,2000,4200,3008,6000,4017,2000,4202,3008,61ff +,3140,1b48,e000,4017,2000,4200,3008,6000,4017,2000,4201,3008,61ff diff --git a/digital/atk16_tpu.dig b/digital/atk16_tpu.dig index 684996b..6b6030c 100644 --- a/digital/atk16_tpu.dig +++ b/digital/atk16_tpu.dig @@ -247,7 +247,7 @@ - ROM + RAMDualPort AddrBits @@ -255,56 +255,84 @@ Label - CHARMEM + TEXTMEM Bits 8 - + + + + Tunnel + + + rotation + + + + NetName + Y + + + Splitter Input Splitting - 8,3 + 8 Output Splitting - 11 + 3,5 - + - VDD + Splitter - rotation - + Input Splitting + 5,6 + + + Output Splitting + 11 - + - RAMDualPort + Tunnel - AddrBits - 11 + rotation + - Label - TEXTMEM + NetName + TY + + + + + Tunnel + - Bits - 8 + rotation + + + + NetName + TX - + Tunnel @@ -315,106 +343,139 @@ NetName - Y + CCOLOR - + Splitter Input Splitting - 8 + 1,1 Output Splitting - 5,3 + 2 - + - Tunnel + Ground - NetName - CY + rotation + + + + Bits + 8 - + - Tunnel + Ground - NetName - TY + rotation + - + - Tunnel + VDD rotation - + + + + + + Tunnel + NetName - X + CHAR_S - + - Splitter + Tunnel - Input Splitting - 9 - - - Output Splitting - 6,3 + NetName + Y - + Tunnel NetName - TX + TY - + Tunnel NetName - CX + CY - + + + + Counter + + + Bits + 3 + + + + + + And + + + inverterConfig + + In_1 + In_2 + + + + Inputs + 3 + + + Splitter Input Splitting - 5,6 + 3 Output Splitting - 11 + 1,1,1 - + Tunnel @@ -425,96 +486,140 @@ NetName - TY + PCLK - + - Tunnel + VDD rotation - + + + + + + Counter + - NetName - TX + Bits + 6 - + Tunnel - - rotation - - NetName - CCOLOR + CX - + - Splitter + VDD - Input Splitting - 1,1 + rotation + + + + + + Ground + - Output Splitting - 2 + rotation + - + - BitSelector + Tunnel - Selector Bits - 3 + NetName + TX - + Tunnel NetName - CX + COVF - + + + + Not + + Tunnel + + rotation + + NetName - CCOLOR + COVF - + - Ground + Probe - rotation - + intFormat + dec + + + + + + EEPROM + + + AddrBits + 11 + + + Label + CHARMEM Bits 8 + + Data + 6,9,9,f,9,9,9,0,3,5,5,7,9,9,f,0,6,9,1,1,1,9,6,0,f,1,1,3,1,1,f +,0,f,1,1,3,1,1,1,0,6,9,1,1,d,9,6,0,9,9,f,4*9,0,7,5*2,7,0,e,4*8 +,9,6,0,9,5,3,5,5,9,9,0,6*1,f,0,9,f,f,4*9,0,9,b,b,d,d,9,9,0,6,5*9 +,6,0,7,9,9,7,1,1,1,0,6,9,9,9,d,e,8,0,7,9,9,7,3,5,9,0,6,9,1,6,8 +,9,6,0,7,6*2,0,6*9,e,0,6*9,6,0,4*9,f,f,9,0,9,9,6,4*9,0,9,9,9,e +,8,9,e,0,f,8,8,4,2,1,f + + + intFormat + bin + - + Ground @@ -524,41 +629,55 @@ - + - Tunnel + VDD rotation - - - - NetName - CLK + - + VDD rotation - + - + + + + Splitter + + + Input Splitting + 3,8 + + + Output Splitting + 11 + + + Tunnel + + rotation + + NetName CHAR_S - + Tunnel @@ -572,31 +691,57 @@ CY - + - Tunnel + BitSelector - rotation - + Selector Bits + 3 + + + + + Tunnel + NetName - CHAR_S + CX - + Tunnel NetName - Y + CCOLOR - + + + + Probe + + + intFormat + bin + + + + + + Probe + + + + + Probe + + @@ -617,57 +762,41 @@ - - - - - - - - - - - - - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - - @@ -677,36 +806,36 @@ - - + + - - - - - - + + + + + + - - + + - - + + - - + + @@ -721,32 +850,132 @@ - - + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + @@ -756,21 +985,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + - - + + diff --git a/src/charmem.py b/src/charmem.py new file mode 100644 index 0000000..25eeec9 --- /dev/null +++ b/src/charmem.py @@ -0,0 +1,60 @@ +#!/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_BITS = 3 +CHAR_HEIGHT = 2 ** CHAR_HEIGHT_BITS +CHAR_WIDTH = 5 + +i = CHAR_HEIGHT +while i < len(lines): + char = lines[i:i+CHAR_HEIGHT] + for row in char: + assert len(row) == CHAR_WIDTH + charset.append(char) + i += CHAR_HEIGHT + +CHAR_N = len(charset) + +TOTAL_BYTEARRAY_SIZE = CHAR_N * CHAR_HEIGHT +print("TOTAL_BYTEARRAY_SIZE:", TOTAL_BYTEARRAY_SIZE) + +def string_to_byte(input_string: str): + # Replace spaces with '0' and '#' with '1' + binary_string = input_string.replace(' ', '0').replace('#', '1') + "000" + + # 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/charset.py b/src/charset.py deleted file mode 100644 index 628a983..0000000 --- a/src/charset.py +++ /dev/null @@ -1,14 +0,0 @@ -def gen_charset(file = "charset.txt"): - with open(file, "r") as f: - lines = [s.strip("\n") for s in f.readlines()] - - result: list[list[str]] = [] - i = 0 - while i < len(lines): - char = lines[i:i+8] - result.append(char) - i += 8 - - print(result) - -gen_charset() diff --git a/src/charset.txt b/src/charset.txt deleted file mode 100644 index 0b68a45..0000000 --- a/src/charset.txt +++ /dev/null @@ -1,208 +0,0 @@ -% ABCDEFGHIJKLMNOPQRSTUVWXYZ - - - - - - - - ## -# # -# # -#### -# # -# # -# # - -## -# # -# # -### -# # -# # -#### - - ## -# # -# -# -# -# # - ## - -#### -# -# -## -# -# -#### - -#### -# -# -## -# -# -# - - ## -# # -# -# -# ## -# # - ## - -# # -# # -#### -# # -# # -# # -# # - -### - # - # - # - # - # -### - - ### - # - # - # - # -# # - ## - -# # -# # -## -# # -# # -# # -# # - -# -# -# -# -# -# -#### - -# # -#### -#### -# # -# # -# # -# # - -# # -## # -## # -# ## -# ## -# # -# # - - ## -# # -# # -# # -# # -# # - ## - -### -# # -# # -### -# -# -# - - ## -# # -# # -# # -# ## - ### - # - -### -# # -# # -### -## -# # -# # - - ## -# # -# - ## - # -# # - ## - -### - # - # - # - # - # - # - -# # -# # -# # -# # -# # -# # - ### - -# # -# # -# # -# # -# # -# # - ## - -# # -# # -# # -# # -#### -#### -# # - -# # -# # - ## -# # -# # -# # -# # - -# # -# # -# # - ### - # -# # - ### - -#### - # - # - # - # -# -#### - \ No newline at end of file -- cgit v1.3