@@ 1,15 @@
+COM_ASM := kbdinfo.asm
+
+RASM ?= rasm.exe
+RASMFLAGS ?= -xr -wu
+
+COM_OUT := $(patsubst %.asm,%.com,$(COM_ASM))
+
+all: $(COM_OUT)
+
+clean:
+ $(RM) $(COM_OUT)
+
+%.com: %.asm
+ $(RASM) $(RASMFLAGS) -ob $@ $<
+
@@ 1,79 @@
+; vim:set ft=z80:
+
+ BDOS equ $0005
+ _CONOUT equ $02
+ _STROUT equ $09
+
+ PSGREGS equ $0A0
+ PSGSTAT equ $0A1
+
+ org $100
+
+ ld a, ($002C) ; Read keyboard information from BIOS ROM
+ and %111 ; Pick only the three least significant bits
+
+ ld e, a ; de = a
+ ld d, 0
+
+ ld hl, kbdversion
+ add hl, de ; now hl points to the offset value
+
+ ld e, (hl) ; load offset from kbdversion
+ ld d, 0
+
+ ld hl, kbdversion
+ add hl, de ; hl now points to the string we want to show
+
+ ld c, _STROUT
+ ld de, hl
+ call BDOS
+
+ cp 0 ; For Japanese models, find out JIS/ANSI from PSG
+ jr nz, .exit ; For other models, bail out
+
+ ld c, _CONOUT
+ ld e, ' '
+ call BDOS
+
+ ld a, 14 ; BIOS function RDPSG garbles output, use PSG ports instead
+ di
+ out (PSGREGS), a
+ in a, (PSGSTAT)
+ ei
+
+ ld de, kbdversion_jp_ansi
+ bit 6, a
+ jr z, .isjis
+ ld de, kbdversion_jp_jis
+.isjis:
+ ld c, _STROUT
+ call BDOS
+
+.exit:
+ ret
+
+kbdversion:
+ db (kbdversion_jp - kbdversion)
+ db (kbdversion_xw - kbdversion)
+ db (kbdversion_fr - kbdversion)
+ db (kbdversion_en - kbdversion)
+ db (kbdversion_de - kbdversion)
+ db (kbdversion_es - kbdversion)
+
+kbdversion_jp:
+ db "Japanese$"
+kbdversion_xw:
+ db "International (QWERTY/other)$"
+kbdversion_fr:
+ db "French (AZERTY)$"
+kbdversion_en:
+ db "English$"
+kbdversion_de:
+ db "German (DIN)$"
+kbdversion_es:
+ db "Spanish$"
+
+kbdversion_jp_jis:
+ db "JIS$"
+kbdversion_jp_ansi:
+ db "ANSI$"