aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2023-11-03 23:24:50 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2023-11-03 23:24:50 +0200
commit49327432b456c3110064556ac4613b49be54b925 (patch)
treeae1d75b210b6168010c6a21332795907fc7c2f4d
parentbef9b09493403187079f4b8ec6633f5258376f44 (diff)
Fix character code mapping
-rw-r--r--.gitignore2
-rw-r--r--Makefile4
-rw-r--r--asm/bootstrap.atk1622
-rw-r--r--asm/ext_string_io.py5
-rw-r--r--asm/text_mode.atk1635
-rw-r--r--charset.txtbin3415 -> 23058 bytes
-rw-r--r--digital/atk16_mem.dig24
-rw-r--r--digital/atk16_tpu.dig83
-rw-r--r--ibm_cga_8x8.ttfbin0 -> 35952 bytes
-rw-r--r--src/charmem.py12
-rw-r--r--src/convert_ttf.py52
11 files changed, 195 insertions, 44 deletions
diff --git a/.gitignore b/.gitignore
index 4d37b72..951eb43 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,5 @@ out/
*.pyc
.DS_Store
+
+venv/
diff --git a/Makefile b/Makefile
index 9fdc5e2..1f084a0 100644
--- a/Makefile
+++ b/Makefile
@@ -18,6 +18,10 @@ gen-ucode:
gen-charmem:
$(py) src/charmem.py $(out)
+# make convert-ttf in=font.ttf out=charset.txt
+convert-ttf:
+ $(py) src/convert_ttf.py $(in) $(out)
+
# make test
test:
$(py) src/test_alu.py digital/atk16_alu.dig
diff --git a/asm/bootstrap.atk16 b/asm/bootstrap.atk16
index 9d69872..a65fc99 100644
--- a/asm/bootstrap.atk16
+++ b/asm/bootstrap.atk16
@@ -43,17 +43,17 @@
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 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
diff --git a/asm/ext_string_io.py b/asm/ext_string_io.py
index 7b026ba..dd17123 100644
--- a/asm/ext_string_io.py
+++ b/asm/ext_string_io.py
@@ -2,8 +2,7 @@ from asm_ops import *
from ext_std import expand_addi
def to_char_code(c: str):
- if c == " " or c == "%SPACE": return 0
- else: return ord(c) - 64
+ return ord(c)
_counter = 0
def get_unique_name(prefix: str):
@@ -17,7 +16,7 @@ def expand_put_char(cursor_reg: str, scratch_reg: str, c: str) -> ExpandResult:
return [
["ldi", str(to_char_code(c)), scratch_reg],
["str", scratch_reg, cursor_reg],
- *expand_addi("RA", "1", "RA"),
+ *expand_addi(cursor_reg, "1", cursor_reg),
]
def expand_put_string(cursor_reg: str, scratch_reg: str, *rest: str) -> ExpandResult:
diff --git a/asm/text_mode.atk16 b/asm/text_mode.atk16
index fa4f297..7ec9fef 100644
--- a/asm/text_mode.atk16
+++ b/asm/text_mode.atk16
@@ -8,12 +8,39 @@
@include bootstrap
@label main
- cursor_to_line RA 1
- put_string RA RB " HELLO CORECAMP"
- cursor_to_line RA 2
- put_string RA RB " BY JAN"
+ cursor_to_line RC 1
+ put_string RC RB " HELLO CORECAMP"
+ cursor_to_line RC 2
+ put_string RC RB " BY JAN"
+ cursor_to_line RC 4
+ put_string RC RB " > "
set_graphics_mode gr_text_mode
@label loop
jpi loop
+
+@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 RC
+ mov RA RD
+ addi RC 1 RC
+
+ subi RA 5 RA
+ subi RA 5 RA
+ bri zero keyboard_isr_clear
+ jpi keyboard_isr_end
+@label keyboard_isr_clear
+ ; cursor_to_line RC 4
+ ; put_string RC RB " "
+ cursor_to_line RC 4
+ put_string RC RB " > "
+@label keyboard_isr_end
+ stack_restore RA RB
+ rti
diff --git a/charset.txt b/charset.txt
index 5b0a02f..bee1e3d 100644
--- a/charset.txt
+++ b/charset.txt
Binary files differ
diff --git a/digital/atk16_mem.dig b/digital/atk16_mem.dig
index 0e2c2f2..34d3292 100644
--- a/digital/atk16_mem.dig
+++ b/digital/atk16_mem.dig
@@ -35,18 +35,18 @@
</entry>
<entry>
<string>Data</string>
- <data>4014,2a00,6029,13*8000,1c,1a,1a,1a,8000,e000,e001,e002,e800,f800
-,4855,f000,3140,1b48,3148,1b48,4016,2000,2000,4215,2240,3040,1800
-,3148,1b48,3140,1b48,e000,4017,2000,4200,3008,6000,6001,f840,4032
-,2000,4200,3008,1008,4208,3008,1008,4205,3008,1008,420c,3008,1008
-,420c,3008,1008,420f,3008,1008,4200,3008,1008,4216,3008,1008,4201
-,3008,1008,4209,3008,1008,420e,3008,1008,4203,3008,1008,420f,3008
-,1008,420f,3008,1008,4204,3008,1008,4209,3008,1008,420a,3008,1008
-,4215,3008,1008,4214,3008,1008,4215,3008,1008,4214,3008,1008,6001
-,f880,4075,2000,4200,3008,1008,4202,3008,1008,4205,3008,1008,420e
-,3008,1008,4209,3008,1008,4213,3008,1008,4200,3008,1008,4202,3008
-,1008,4209,3008,1008,4202,3008,1008,4205,3008,1008,420c,3008,1008
-,4209,3008,1008,4017,2000,4201,3008,61ff</data>
+ <data>4014,2a00,6019,13*8000,7d,1a,1a,1a,8000,e000,e001,e002,e800,f800
+,4855,f000,4017,2000,4200,3008,6000,6001,f840,4422,2480,4220,3088
+,1488,4248,3088,1488,4245,3088,1488,424c,3088,1488,424c,3088,1488
+,424f,3088,1488,4220,3088,1488,4243,3088,1488,424f,3088,1488,4252
+,3088,1488,4245,3088,1488,4243,3088,1488,4241,3088,1488,424d,3088
+,1488,4250,3088,1488,6001,f880,4453,2480,4220,3088,1488,4242,3088
+,1488,4259,3088,1488,4220,3088,1488,424a,3088,1488,4241,3088,1488
+,424e,3088,1488,6001,f900,446c,2480,4220,3088,1488,423e,3088,1488
+,4220,3088,1488,4017,2000,4201,3008,61ff,3140,1b48,3148,1b48,4016
+,2000,2000,4215,2240,3080,1600,1488,1029,1029,8401,600d,6001,f900
+,448e,2480,4220,3088,1488,423e,3088,1488,4220,3088,1488,3148,1b48
+,3140,1b48,e000</data>
</entry>
</elementAttributes>
<pos x="740" y="100"/>
diff --git a/digital/atk16_tpu.dig b/digital/atk16_tpu.dig
index b28c3f5..bb623df 100644
--- a/digital/atk16_tpu.dig
+++ b/digital/atk16_tpu.dig
@@ -339,15 +339,80 @@
</entry>
<entry>
<string>Data</string>
- <data>8*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,36,63,63,0,33,33,33
-,1e,c,c,1e,0,7f,63,31,18,4c,66,7f</data>
+ <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
+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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</data>
</entry>
<entry>
<string>intFormat</string>
diff --git a/ibm_cga_8x8.ttf b/ibm_cga_8x8.ttf
new file mode 100644
index 0000000..9f29ec5
--- /dev/null
+++ b/ibm_cga_8x8.ttf
Binary files differ
diff --git a/src/charmem.py b/src/charmem.py
index 551ba85..aaac122 100644
--- a/src/charmem.py
+++ b/src/charmem.py
@@ -19,17 +19,19 @@ with open("charset.txt", "r") as f:
header_chars = lines[0]
charset: list[list[str]] = []
-CHAR_HEIGHT_BITS = 3
-CHAR_HEIGHT = 2 ** CHAR_HEIGHT_BITS
+
+CHAR_HEIGHT = 8
CHAR_WIDTH = 8
-i = CHAR_HEIGHT
+i = 0
while i < len(lines):
+ i += 1 # skip comment line
char = lines[i:i+CHAR_HEIGHT]
for row in char:
- assert len(row) == CHAR_WIDTH
+ 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
+ i += CHAR_HEIGHT + 1
CHAR_N = len(charset)
diff --git a/src/convert_ttf.py b/src/convert_ttf.py
new file mode 100644
index 0000000..c1135cb
--- /dev/null
+++ b/src/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 <infile.ttf> <outfile.txt>")
+ 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')