diff --git a/assets/misc/ps2_modeset_2_to_ascii.ods b/assets/misc/ps2_modeset_2_to_ascii.ods new file mode 100644 index 0000000..03f3b89 Binary files /dev/null and b/assets/misc/ps2_modeset_2_to_ascii.ods differ diff --git a/pat80-computer/software/z80-assembly/os/drivers/ps2_keyboard.asm b/pat80-computer/software/z80-assembly/os/drivers/ps2_keyboard.asm index be469d6..d5fcd57 100644 --- a/pat80-computer/software/z80-assembly/os/drivers/ps2_keyboard.asm +++ b/pat80-computer/software/z80-assembly/os/drivers/ps2_keyboard.asm @@ -3,9 +3,9 @@ ; Based on PS/2 protocol as documented on http://www.lucadavidian.com/2017/11/15/interfacing-ps2-keyboard-to-a-microcontroller/ ; ; The CLK and Data pin of the PS/2 keyboard are fed into two cascated serial-in parallel-out shift registers. -; Their outputs are connected to the Pat80 data bus via a buffer activated by the selected -; I/O EN signal and their RESET is connected to I/O Address line 0 of the keyboard I/O port. -; Being RESET active low, they will be erased when the PAT80 reads (or writes) anything at address 0 +; Their outputs are connected to the Pat80 data bus via a buffer activated by the selected +; I/O EN signal and their RESET is connected to I/O Address line 0 of the keyboard I/O port. +; Being RESET active low, they will be erased when the PAT80 reads (or writes) anything at address 0 ; of the keyboard I/0 port. ; ; Thus, the read cycle is: @@ -20,7 +20,7 @@ ; behave strangely (will drop next pressed key). This is not a problem, as the computer, once completed, will ; have a 60% keyboard, without any of the unusable keys. -include 'ps2_keyboard_scancodeset2.asm' ; PS/2 Scan Codeset 2 mappings +include 'drivers/ps2_keyboard_scancodeset2.asm' ; PS/2 Scan Codeset 2 mappings ; config (IO port 1) PS2KEYB_CLEAR_REG: EQU IO_2 @@ -35,19 +35,20 @@ PS2KEYB_BREAK: EQU 0xF0 - %10000000 ; The MSB is dropped: see NOTE on intro a PS2Keyb_readc: in a, (PS2KEYB_DATA_REG) ; reads a character add a, 0 - jp z, Term_readc ; if char is 0 (NULL), user didn't press any key: wait for character - ; we found something, allow the keyboard to complete data transmission + jp z, PS2Keyb_readc ; if char is 0 (NULL), user didn't press any key: wait for character + ; we found something, but it may still be shifting in bits. Allow the keyboard to complete data transmission ld a, PS2KEYB_TRANSMISSION_DURATION/5 ; every cycle is 5 CPU cycles ps2keyb_readc_waitloop: sub 1 jr nz, ps2keyb_readc_waitloop ; data transmission should now be complete. ; check if code is a Break Code. If it is, discard next key as it is a released key - ld c, a ; save a + in a, (PS2KEYB_DATA_REG) ; re-reads the character (it should now be complete) + ld c, a ; save a, because it will be modified by next compare cp PS2KEYB_BREAK ; compare a with Break Code jp z, ps2keyb_readc_discard ; if it is a Break Code, jump to discarder routine ; we read a valid character: clean key registers - in a, PS2KEYB_CLEAR_REG + in a, (PS2KEYB_CLEAR_REG) ; now we will convert keycode in c to ASCII code ld hl, PS2KEYB_SCANCODESET_ASCII_MAP ; load start of codeset to ascii map ld b, 0 ; reset b, as we are going to do a sum with bc (where c contains the read scancode) @@ -56,7 +57,7 @@ PS2Keyb_readc: ret ; returns in the a register ps2keyb_readc_discard: ; clean key registers - in a, PS2KEYB_CLEAR_REG + in a, (PS2KEYB_CLEAR_REG) ps2keyb_readc_discard_waitfordata: ; wait for next non-0 keycode and discards it (it is the code of the released key) in a, (PS2KEYB_DATA_REG) ; reads a character @@ -68,5 +69,5 @@ PS2Keyb_readc: sub 1 jr nz, ps2keyb_readc_discard_waitloop ; data transmission should now be complete, throw away key code - in a, PS2KEYB_CLEAR_REG + in a, (PS2KEYB_CLEAR_REG) jp PS2Keyb_readc ; go back and wait for another keycode diff --git a/pat80-computer/software/z80-assembly/os/drivers/ps2_keyboard_scancodeset2.asm b/pat80-computer/software/z80-assembly/os/drivers/ps2_keyboard_scancodeset2.asm index c5ead3e..443cc21 100644 --- a/pat80-computer/software/z80-assembly/os/drivers/ps2_keyboard_scancodeset2.asm +++ b/pat80-computer/software/z80-assembly/os/drivers/ps2_keyboard_scancodeset2.asm @@ -2,136 +2,136 @@ ; ; Keycodes 0 to 83 -.db PS2KEYB_SCANCODESET_ASCII_MAP: .db 0 ; (Unused) -.db 0 ; F9 -.db 0 ; (Control key) -.db 0 ; F5 -.db 0 ; F3 -.db 0 ; F1 -.db 0 ; F2 -.db 0 ; F12 -.db 0 ; (Control key) -.db 0 ; F10 -.db 0 ; F8 -.db 0 ; F6 -.db 0 ; F4 -.db 9 ; TAB -.db 96 ; ` -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 0 ; L ALT -.db 0 ; L SHFT -.db 0 ; (Control key) -.db 0 ; L CTRL -.db 1 ; Q -.db 2 ; 1 -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 3 ; Z -.db 4 ; S -.db 65 ; A -.db 66 ; W -.db 67 ; 2 -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 68 ; C -.db 69 ; X -.db 70 ; D -.db 71 ; E -.db 72 ; 4 -.db 73 ; 3 -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 32 ; SPACE -.db 33 ; V -.db 34 ; F -.db 35 ; T -.db 36 ; R -.db 37 ; 5 -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 38 ; N -.db 39 ; B -.db 40 ; H -.db 41 ; G -.db 42 ; Y -.db 43 ; 6 -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 44 ; M -.db 45 ; J -.db 46 ; U -.db 47 ; 7 -.db 48 ; 8 -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 44 ; , -.db 45 ; K -.db 46 ; I -.db 47 ; O -.db 48 ; 0 -.db 49 ; 9 -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 46 ; . -.db 47 ; / -.db 48 ; L -.db 59 ; ; -.db 60 ; P -.db 45 ; - -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 39 ; ' -.db 0 ; (Unused) -.db 91 ; [ -.db 61 ; = -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 0 ; CAPS -.db 0 ; R SHFT -.db 10 ; ENTER -.db 93 ; ] -.db 0 ; (Unused) -.db 92 ; \ -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 8 ; BKSP -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 9 ; KP 1 -.db 0 ; (Unused) -.db 10 ; KP 4 -- NOTE: shadowed by break code (see the NOTE in ps2_keyboard.asm) -.db 11 ; KP 7 -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 0 ; (Unused) -.db 48 ; KP 0 -.db 46 ; KP . -.db 47 ; KP 2 -.db 48 ; KP 5 -.db 49 ; KP 6 -.db 50 ; KP 8 -.db 27 ; ESC -.db 0 ; NUM -.db 0 ; F11 -.db 43 ; KP + -.db 44 ; KP 3 +PS2KEYB_SCANCODESET_ASCII_MAP: DB 0 ; (Unused) +DB 0 ; F9 +DB 0 ; (Control key) +DB 0 ; F5 +DB 0 ; F3 +DB 0 ; F1 +DB 0 ; F2 +DB 0 ; F12 +DB 0 ; (Control key) +DB 0 ; F10 +DB 0 ; F8 +DB 0 ; F6 +DB 0 ; F4 +DB 9 ; TAB +DB 96 ; ` +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 0 ; L ALT +DB 0 ; L SHFT +DB 0 ; (Control key) +DB 0 ; L CTRL +DB 1 ; Q +DB 2 ; 1 +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 3 ; Z +DB 4 ; S +DB 65 ; A +DB 66 ; W +DB 67 ; 2 +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 68 ; C +DB 69 ; X +DB 70 ; D +DB 71 ; E +DB 72 ; 4 +DB 73 ; 3 +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 32 ; SPACE +DB 33 ; V +DB 34 ; F +DB 35 ; T +DB 36 ; R +DB 37 ; 5 +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 38 ; N +DB 39 ; B +DB 40 ; H +DB 41 ; G +DB 42 ; Y +DB 43 ; 6 +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 44 ; M +DB 45 ; J +DB 46 ; U +DB 47 ; 7 +DB 48 ; 8 +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 44 ; , +DB 45 ; K +DB 46 ; I +DB 47 ; O +DB 48 ; 0 +DB 49 ; 9 +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 46 ; . +DB 47 ; / +DB 48 ; L +DB 59 ; ; +DB 60 ; P +DB 45 ; - +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 39 ; ' +DB 0 ; (Unused) +DB 91 ; [ +DB 61 ; = +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 0 ; CAPS +DB 0 ; R SHFT +DB 10 ; ENTER +DB 93 ; ] +DB 0 ; (Unused) +DB 92 ; \ +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 8 ; BKSP +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 9 ; KP 1 +DB 0 ; (Unused) +DB 10 ; KP 4 -- NOTE: shadowed by break code (see the NOTE in ps2_keyboard.asm) +DB 11 ; KP 7 +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 0 ; (Unused) +DB 48 ; KP 0 +DB 46 ; KP . +DB 47 ; KP 2 +DB 48 ; KP 5 +DB 49 ; KP 6 +DB 50 ; KP 8 +DB 27 ; ESC +DB 0 ; NUM +DB 0 ; F11 +DB 43 ; KP + +DB 44 ; KP 3 ; The following codes are unrecognized by PAT80, as it uses only 7 bits (see the NOTE in ps2_keyboard.asm) -; .db 45 ; KP - -; .db 42 ; KP * -; .db 43 ; KP 9 -; .db 0 ; SCROLL -; .db 0 ; (Control key) -; .db 0 ; (Control key) -; .db 0 ; (Control key) -; .db 0 ; (Control key) -; .db 0 ; F7 \ No newline at end of file +; DB 45 ; KP - +; DB 42 ; KP * +; DB 43 ; KP 9 +; DB 0 ; SCROLL +; DB 0 ; (Control key) +; DB 0 ; (Control key) +; DB 0 ; (Control key) +; DB 0 ; (Control key) +; DB 0 ; F7 \ No newline at end of file diff --git a/pat80-computer/software/z80-assembly/os/main.asm b/pat80-computer/software/z80-assembly/os/main.asm index 3ef0ea5..0680b6e 100644 --- a/pat80-computer/software/z80-assembly/os/main.asm +++ b/pat80-computer/software/z80-assembly/os/main.asm @@ -116,9 +116,19 @@ Sysinit: call Sys_Beep ; Run memory monitor - ei ; enable maskabpe interrupts - im 1 ; set interrupt mode 1 (on interrupt jumps to 0x38) - rst 0x38 ; throw fake interrupt: jump to interrupt routine to start monitor + ; ei ; enable maskabpe interrupts + ; im 1 ; set interrupt mode 1 (on interrupt jumps to 0x38) + ; rst 0x38 ; throw fake interrupt: jump to interrupt routine to start monitor + + ; Keyboard test + ld a, 0x3E + call Sys_Printc + ktestloop: + call Sys_Readc + call Sys_Printc + ld a, 46 + call Sys_Printc + jp ktestloop ; User exited from memory monitor without loading a program. Do nothing. mloop: