Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KEYMAP] Add Katakana Keyboard #364

Merged
merged 2 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed keymap/asm/411.bin.lzsa
Binary file not shown.
32 changes: 0 additions & 32 deletions keymap/asm/411.s

This file was deleted.

Binary file added keymap/asm/ja-jp.bin.lzsa
Binary file not shown.
34 changes: 34 additions & 0 deletions keymap/asm/ja-jp.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
; Commander X16 PETSCII/ISO Keyboard Table
;
; This definition file is NOT auto generated. `ja-jp.bin.lzsa` is generated by patching the ABC/X16.
; see `ja-jp_gen.py` to audit the patching process
;
; Name: Japanese
; Locale: ja-JP
;

.segment "KBDMETA"

.byte "JA-JP", 0, 0, 0, 0, 0, 0, 0, 0, 0
.word kbtab_jajp

.segment "KBDTABLES"

kbtab_jajp:
.incbin "asm/ja-jp.bin.lzsa"

; PETSCII
; ~~~~~~~
; In petscii mode, the entire layout works exactly the same as the default ABC/X16 layout
; (although note that the CapsLock is disabled across the entire layout)

; ISO
; ~~~
; In ISO mode, this layout acts like a rudimentary IME, that allows the user to type katakana using romaji.
; dakuten and handakuten can be typed using ' and ; keys respectively and HAVE TO be typed manually (IME only produces diacriticless kana)

; small kana are produced by holding shift while typing. ン and small ッ can be produced by either Shift+n and Shift+t,
; or by pressing space after pressing n or t respectively.

; All of the JIS X 0201 interpunction can be typed without holding shift or alt key.
; By holding alt key, user can produce every character from the CX16 JIS Extensions (codepoints $E0-$FF) as well as the missing ASCII punctation.
104 changes: 104 additions & 0 deletions keymap/ja-jp_gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# This is a python script, that creates `ja-jp.bin` file. see CX16 documentation about keyboard layout format for more context about the inner workings
# and see `ja-jp.s` file for the general description of this layout.

# this is metadata, that's going to be appended bellow everything else in the keyboard file
deadkeys=[
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, #Disables CapsLock in the entire layout

0x80, 0x12, 0x07, 0xB1, 0xDC, 0xB5, 0xA6, # wa wo
0x80, 0x14, 0x0D, 0xB1, 0xD7, 0xB2, 0xD8, 0xB3, 0xD9, 0xB4, 0xDA, 0xB5, 0xDB, # ra ri ru re ro
0x80, 0x15, 0x0F, 0xB1, 0xC0, 0xB2, 0xC1, 0xB3, 0xC2, 0xB4, 0xC3, 0xB5, 0xC4, 0x20, 0xAF, # ta ti tu te to, t␣=ッ(small tsu)
0x80, 0x16, 0x09, 0xB1, 0xD4, 0xB3, 0xD5, 0xB5, 0xD6, # ya yu yo
0x81, 0x16, 0x0F, 0xB1, 0xAC, 0xB3, 0xAD, 0xB5, 0xAE, 0xA7, 0xAC, 0xA9, 0xAD, 0xAB, 0xAE, # small ya yu yo
0x80, 0x1A, 0x0D, 0xB1, 0xCA, 0xB2, 0xCB, 0xB3, 0xCC, 0xB4, 0xCD, 0xB5, 0xCE, # pa pi pu pe po (same as h*)
0x80, 0x20, 0x0D, 0xB1, 0xBB, 0xB2, 0xBC, 0xB3, 0xBD, 0xB4, 0xBE, 0xB5, 0xBF, # sa si su se so
0x80, 0x21, 0x0D, 0xB1, 0xC0, 0xB2, 0xC1, 0xB3, 0xC2, 0xB4, 0xC3, 0xB5, 0xC4, # da di du de do (same as t*, except of small tsu)
0x80, 0x22, 0x07, 0xB3, 0xCC, 0x20, 0xCC, # fu, f␣=フ (this allows for interesting stuff, such as fァ=ファ)
0x80, 0x23, 0x0D, 0xB1, 0xB6, 0xB2, 0xB7, 0xB3, 0xB8, 0xB4, 0xB9, 0xB5, 0xBA, # ga gi gu ge go (same as k*)
0x80, 0x24, 0x0D, 0xB1, 0xCA, 0xB2, 0xCB, 0xB3, 0xCC, 0xB4, 0xCD, 0xB5, 0xCE, # ha hi hu he ho
0x80, 0x25, 0x07, 0xB2, 0xBC, 0x20, 0xBC, # ji (shi), j␣=シ
0x80, 0x26, 0x0D, 0xB1, 0xB6, 0xB2, 0xB7, 0xB3, 0xB8, 0xB4, 0xB9, 0xB5, 0xBA, # ka ki ku ke ko
0x80, 0x2E, 0x0D, 0xB1, 0xBB, 0xB2, 0xBC, 0xB3, 0xBD, 0xB4, 0xBE, 0xB5, 0xBF, # za zi zu ze zo (same as s*)
0x80, 0x32, 0x0D, 0xB1, 0xCA, 0xB2, 0xCB, 0xB3, 0xCC, 0xB4, 0xCD, 0xB5, 0xCE, # ba bi bu be bo (same as h*)
0x80, 0x33, 0x0F, 0xB1, 0xC5, 0xB2, 0xC6, 0xB3, 0xC7, 0xB4, 0xC8, 0xB5, 0xC9, 0x20, 0xDD, # na ni nu ne no, n␣=ン
0x80, 0x34, 0x0D, 0xB1, 0xCF, 0xB2, 0xD0, 0xB3, 0xD1, 0xB4, 0xD2, 0xB5, 0xD3, # ma mi mu me mo

# Empty space in the deadkey area. Could be repurposed in the future.
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,


b'J'[0], b'A'[0], b'-'[0], b'J'[0], b'P'[0], 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
]
assert len(deadkeys)==0xFE, "Incorect size of the `deadkey` array. Correct the contents immediately!"

# arrays bellow are the keyboard layout definitions in ISO mode. 0x80 is a placeholder value, that tells the patcher to keep the value of the original.
# this makes the script futureproof. Any other value represents a JIS X0201 character to be typed. For the sake of clarity, Layout of the bytes in these arrays
# are aligned in a way, that resembles the physical keyboard:

# ~ 1 2 3 4 5 6 7 8 9 0 - =
# q w e r t y u i o p [ ] \
# a s d f g h j k l ; "
# \ z x c v b n m , . /

# regular state. produces vowels, numbers, all JIS punctation. has dead keys for constonants
st_normal=[
0x60, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0xB0, 0x3D, 0x80, 0x80, 0x80,
0x00, 0x00, 0xB4, 0x00, 0x00, 0x00, 0xB3, 0xB2, 0xB5, 0x00, 0xA2, 0xA3, 0x5C, 0x80,
0xB1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDF, 0xDE, 0x80, 0x80, 0x80,
0x5C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA4, 0xA1, 0xA5
]
assert len(st_normal)==0x37

# When shift. produces all small kana, ン, punctation is the same as in US keyboard.
st_shift=[
0x7E, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x80, 0x80, 0x80,
0x00, 0x00, 0xAA, 0x00, 0xAF, 0x00, 0xA9, 0xA8, 0xAB, 0x00, 0x7B, 0x7D, 0x7C, 0x80,
0xA7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3A, 0x22, 0x80, 0x80, 0x80,
0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDD, 0x00, 0x3C, 0x3E, 0x3F
]
assert len(st_shift)==0x37

# When alt. Produces all Extra characters specific to CX16 implementation of the standard (0xE0-0xFF) and remaining ASCII punctation.
st_alt=[
0xF0, 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xED, 0xEE, 0xEF, 0x2D, 0x00, 0x80, 0x80, 0x80,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0x5B, 0x5D, 0xFC, 0x80,
0x00, 0xEC, 0x00, 0x00, 0x00, 0x00, 0xFD, 0x00, 0xEA, 0x3B, 0x27, 0x80, 0x80, 0x80,
0xFC, 0xF8, 0xF9, 0xFA, 0xFB, 0xFE, 0xFF, 0xEB, 0x2C, 0x2E, 0x2F
]
assert len(st_alt)==0x37

# This one is completely blank.
st_shalt=[
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
]
assert len(st_shalt)==0x37

tables={0x80:st_normal, 0x81:st_shift, 0xC6:st_alt, 0xC7:st_shalt}

abc_k=open("asm/99409.bin", "rb")
abc=abc_k.read()
abc_k.close()

jp_k=open("asm/ja-jp.bin", "wb")

print("\"ja-jp_gen.py\" script started. Make sure tables $80, $81 and $C6 get patched:")

for i in range(0,0x580,128):
if abc[i] in tables:
jp_k.write(bytes([abc[i]]))
for j in range(0,len(tables[abc[i]])):
if tables[abc[i]][j]==0x80:
jp_k.write(bytes([abc[i+1+j]]))
else:
jp_k.write(bytes([tables[abc[i]][j]]))
jp_k.write(abc[i+2+j:i+128])
print("${:X}".format(abc[i]), "patched")
else:
jp_k.write(abc[i:i+128])

jp_k.write(bytes(deadkeys))
jp_k.close()
print("\"ja-jp_gen.py\" finished")
2 changes: 1 addition & 1 deletion keymap/keymap.s
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
.include "asm/40B.s" ; Finnish
.include "asm/416.s" ; Portuguese (Brazil ABNT)
.include "asm/405.s" ; Czech
.include "asm/411.s" ; Japanese
.include "asm/ja-jp.s" ; Japanese
.include "asm/40C.s" ; French
.include "asm/807.s" ; Swiss German
.include "asm/10409.s" ; Dvorak
Expand Down
7 changes: 6 additions & 1 deletion keymap/make_keytab_asm.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
layouts="99409 20409 809 41D 407 406 410 415 414 40E 40A 40B 416 405 411 40C 807 10409 425 80C 1009 40F 816 41A 41B 424 426 427 "
layouts="99409 20409 809 41D 407 406 410 415 414 40E 40A 40B 416 405 40C 807 10409 425 80C 1009 40F 816 41A 41B 424 426 427 "

for layout in $layouts; do
filename=$(ls klc/${layout}\ *.klc)
echo $filename
python3 klc_to_asm.py "$filename" asm/$layout.s asm/$layout.bin asm/$layout.bin.lzsa
if [ $layout = 99409 ]; then
python3 ja-jp_gen.py
lzsa -f 2 -r --prefer-ratio asm/ja-jp.bin asm/ja-jp.bin.lzsa
rm asm/ja-jp.bin
fi
lzsa -f 2 -r --prefer-ratio asm/$layout.bin asm/$layout.bin.lzsa
rm asm/$layout.bin
done
Loading