diff --git a/keymap/asm/411.bin.lzsa b/keymap/asm/411.bin.lzsa deleted file mode 100644 index ad2f51d3..00000000 Binary files a/keymap/asm/411.bin.lzsa and /dev/null differ diff --git a/keymap/asm/411.s b/keymap/asm/411.s deleted file mode 100644 index 545801a0..00000000 --- a/keymap/asm/411.s +++ /dev/null @@ -1,32 +0,0 @@ -; Commander X16 PETSCII/ISO Keyboard Table -; ***this file is auto-generated!*** -; -; Name: Japanese -; Locale: ja-JP -; KLID: 411 - -.segment "KBDMETA" - - .byte "JA-JP", 0, 0, 0, 0, 0, 0, 0, 0, 0 - .word kbtab_411 - -.segment "KBDTABLES" - -kbtab_411: - .incbin "asm/411.bin.lzsa" - -; PETSCII -; ~~~~~~~ -; C64 keyboard regressions: -; chars: '£π←' -; graph: '\xa4\xa6\xa8\xa9\xba' <--- *** THIS IS BAD! *** -; Keys outside of PETSCII: -; '\_{|}~' - -; ISO -; ~~~ -; Keys outside of ISO-8859-15 (and -16): -; --none-- -; Non-reachable ISO-8859-15: -; ' ¡¢£€¥Š§š©ª«¬­®¯°±²³Žµ¶·ž¹º»ŒœŸ¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ' - diff --git a/keymap/asm/ja-jp.bin.lzsa b/keymap/asm/ja-jp.bin.lzsa new file mode 100644 index 00000000..68b523b9 Binary files /dev/null and b/keymap/asm/ja-jp.bin.lzsa differ diff --git a/keymap/asm/ja-jp.s b/keymap/asm/ja-jp.s new file mode 100644 index 00000000..6b6df375 --- /dev/null +++ b/keymap/asm/ja-jp.s @@ -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. diff --git a/keymap/ja-jp_gen.py b/keymap/ja-jp_gen.py new file mode 100644 index 00000000..cb6f71d6 --- /dev/null +++ b/keymap/ja-jp_gen.py @@ -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") \ No newline at end of file diff --git a/keymap/keymap.s b/keymap/keymap.s index 83685390..b292a1a7 100644 --- a/keymap/keymap.s +++ b/keymap/keymap.s @@ -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 diff --git a/keymap/make_keytab_asm.sh b/keymap/make_keytab_asm.sh index 45a04e1f..72ff26d7 100755 --- a/keymap/make_keytab_asm.sh +++ b/keymap/make_keytab_asm.sh @@ -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