Browse Source

ch376-native: reverted usb keyboard extensions

pull/592/head
Dean Netherton 9 months ago
parent
commit
253b92377d
  1. 6
      Source/HBIOS/Config/RCEZ80_std.asm
  2. 3
      Source/HBIOS/ch376-native/keyboard.s
  3. 43
      Source/HBIOS/ch376-native/keyboard/kyb-init.c.s
  4. 338
      Source/HBIOS/ch376-native/keyboard/kyb_driver.c.s
  5. 1
      Source/HBIOS/ch376-native/source-doc/keyboard/kyb-init.c
  6. 74
      Source/HBIOS/ch376-native/source-doc/keyboard/kyb_driver.asm
  7. 48
      Source/HBIOS/ch376-native/source-doc/keyboard/kyb_driver.c
  8. 8
      Source/HBIOS/ch376-native/source-doc/keyboard/kyb_driver.h
  9. 17
      Source/HBIOS/ch376kyb.asm

6
Source/HBIOS/Config/RCEZ80_std.asm

@ -55,7 +55,7 @@ CRTACT .SET FALSE ; ACTIVATE CRT (VDU,CVDU,PROPIO,ETC) AT STARTUP
VDAEMU_SERKBD .SET $FF ; VDA EMULATION: SERIAL KBD UNIT #, OR $FF FOR HW KBD VDAEMU_SERKBD .SET $FF ; VDA EMULATION: SERIAL KBD UNIT #, OR $FF FOR HW KBD
;; ;;
TMSENABLE .SET TRUE ; TMS: ENABLE TMS9918 VIDEO/KBD DRIVER (TMS.ASM) TMSENABLE .SET TRUE ; TMS: ENABLE TMS9918 VIDEO/KBD DRIVER (TMS.ASM)
TMSMODE .SET TMSMODE_MSX ;UKY ; TMS: DRIVER MODE: TMSMODE_[SCG|N8|MSX|MSXKBD|MSXMKY|MBC|COLECO|DUO|NABU|MSXUKY]
TMSMODE .SET TMSMODE_MSXUKY ; TMS: DRIVER MODE: TMSMODE_[SCG|N8|MSX|MSXKBD|MSXMKY|MBC|COLECO|DUO|NABU|MSXUKY]
TMS80COLS .SET TRUE ; TMS: ENABLE 80 COLUMN SCREEN, REQUIRES V9958 TMS80COLS .SET TRUE ; TMS: ENABLE 80 COLUMN SCREEN, REQUIRES V9958
TMSTIMENABLE .SET FALSE ; TMS: ENABLE TIMER INTERRUPTS (REQUIRES IM1) TMSTIMENABLE .SET FALSE ; TMS: ENABLE TIMER INTERRUPTS (REQUIRES IM1)
VRCENABLE .SET FALSE ; VRC: ENABLE VGARC VIDEO/KBD DRIVER (VRC.ASM) VRCENABLE .SET FALSE ; VRC: ENABLE VGARC VIDEO/KBD DRIVER (VRC.ASM)
@ -88,8 +88,8 @@ CH0USBENABLE .SET FALSE ; CH375: ENABLE CH375 USB DRIVER
CH1USBENABLE .SET FALSE ; CH376: ENABLE CH376 USB DRIVER CH1USBENABLE .SET FALSE ; CH376: ENABLE CH376 USB DRIVER
CHNATIVEENABLE .SET TRUE ; CH376: ENABLE CH376 NATIVE USB DRIVER CHNATIVEENABLE .SET TRUE ; CH376: ENABLE CH376 NATIVE USB DRIVER
CHNATIVEFORCE .SET TRUE ; CH376: DISABLE AUTO-DETECTION OF MODULE - ASSUME ITS INSTALLED CHNATIVEFORCE .SET TRUE ; CH376: DISABLE AUTO-DETECTION OF MODULE - ASSUME ITS INSTALLED
CHSCSIENABLE .SET FALSE ; CH376: ENABLE CH376 NATIVE MASS STORAGE DEVICES (REQUIRES CHNATIVEENABLE)
CHSCSIENABLE .SET TRUE ; CH376: ENABLE CH376 NATIVE MASS STORAGE DEVICES (REQUIRES CHNATIVEENABLE)
CHUFIENABLE .SET TRUE ; CH376: ENABLE CH376 NATIVE UFI FLOPPY DISK DEVICES (REQUIRES CHNATIVEENABLE) CHUFIENABLE .SET TRUE ; CH376: ENABLE CH376 NATIVE UFI FLOPPY DISK DEVICES (REQUIRES CHNATIVEENABLE)
CHNATIVEEZ80 .SET TRUE
CHNATIVEEZ80 .SET FALSE
EZ80TIMER .SET EZ80TMR_INT ; EZ80: TIMER TICK MODEL: EZ80TMR_[INT|FIRM] EZ80TIMER .SET EZ80TMR_INT ; EZ80: TIMER TICK MODEL: EZ80TMR_[INT|FIRM]

3
Source/HBIOS/ch376-native/keyboard.s

@ -9,6 +9,3 @@
#IF (!CHNATIVEEZ80) #IF (!CHNATIVEEZ80)
#include "ch376-native/keyboard/kyb_driver.c.s" #include "ch376-native/keyboard/kyb_driver.c.s"
#ENDIF #ENDIF
#IF (!CHNATIVEEZ80)
#include "ch376-native/source-doc/keyboard/kyb_driver.asm"
#ENDIF

43
Source/HBIOS/ch376-native/keyboard/kyb-init.c.s

@ -48,7 +48,7 @@ _USB_MODULE_LEDS .EQU 0xff8a
;-------------------------------------------------------- ;--------------------------------------------------------
; code ; code
;-------------------------------------------------------- ;--------------------------------------------------------
;source-doc/keyboard/kyb-init.c:6: uint8_t keyboard_init(void) __sdcccall(1) {
;source-doc/keyboard/kyb-init.c:6: void keyboard_init(void) __sdcccall(1) {
; --------------------------------- ; ---------------------------------
; Function keyboard_init ; Function keyboard_init
; --------------------------------- ; ---------------------------------
@ -57,59 +57,44 @@ _keyboard_init:
ld ix,0 ld ix,0
add ix,sp add ix,sp
dec sp dec sp
;source-doc/keyboard/kyb-init.c:7: uint8_t index = 1;
;source-doc/keyboard/kyb-init.c:9: do { ;source-doc/keyboard/kyb-init.c:9: do {
ld c,0x01
ld (ix-1),c
ld (ix-1),0x01
l_keyboard_init_00103: l_keyboard_init_00103:
;source-doc/keyboard/kyb-init.c:10: usb_device_type t = usb_get_device_type(index); ;source-doc/keyboard/kyb-init.c:10: usb_device_type t = usb_get_device_type(index);
ld e, c
ld d,0x00
push bc
push de
push de
ld l,(ix-1)
ld h,0x00
push hl
push hl
call _usb_get_device_type call _usb_get_device_type
pop af pop af
ld a, l ld a, l
pop de
pop bc
pop hl
;source-doc/keyboard/kyb-init.c:12: if (t == USB_IS_KEYBOARD) { ;source-doc/keyboard/kyb-init.c:12: if (t == USB_IS_KEYBOARD) {
sub 0x04 sub 0x04
jr NZ,l_keyboard_init_00104 jr NZ,l_keyboard_init_00104
;source-doc/keyboard/kyb-init.c:13: print_string("\r\nUSB: KEYBOARD @ $"); ;source-doc/keyboard/kyb-init.c:13: print_string("\r\nUSB: KEYBOARD @ $");
push de
push hl
ld hl,kyb_init_str_0 ld hl,kyb_init_str_0
call _print_string call _print_string
pop de
pop hl
;source-doc/keyboard/kyb-init.c:14: print_uint16(index); ;source-doc/keyboard/kyb-init.c:14: print_uint16(index);
ex de, hl
call _print_uint16 call _print_uint16
;source-doc/keyboard/kyb-init.c:15: print_string(" $"); ;source-doc/keyboard/kyb-init.c:15: print_string(" $");
ld hl,kyb_init_str_1 ld hl,kyb_init_str_1
call _print_string call _print_string
;source-doc/keyboard/kyb-init.c:17: usb_kyb_init(index); ;source-doc/keyboard/kyb-init.c:17: usb_kyb_init(index);
ld a,(ix-1) ld a,(ix-1)
push af
inc sp
call _usb_kyb_init call _usb_kyb_init
inc sp
;source-doc/keyboard/kyb-init.c:18: return 1;
ld a,0x01
jr l_keyboard_init_00106
l_keyboard_init_00104: l_keyboard_init_00104:
;source-doc/keyboard/kyb-init.c:20: } while (++index != MAX_NUMBER_OF_DEVICES + 1);
inc c
ld (ix-1),c
ld a, c
;source-doc/keyboard/kyb-init.c:19: } while (++index != MAX_NUMBER_OF_DEVICES + 1);
inc (ix-1)
ld a,(ix-1)
sub 0x07 sub 0x07
jr NZ,l_keyboard_init_00103 jr NZ,l_keyboard_init_00103
;source-doc/keyboard/kyb-init.c:22: print_string("\r\nUSB: KEYBOARD: NOT FOUND$");
;source-doc/keyboard/kyb-init.c:21: print_string("\r\nUSB: KEYBOARD: NOT FOUND$");
ld hl,kyb_init_str_2 ld hl,kyb_init_str_2
call _print_string call _print_string
;source-doc/keyboard/kyb-init.c:23: return 0;
xor a
l_keyboard_init_00106:
;source-doc/keyboard/kyb-init.c:24: }
;source-doc/keyboard/kyb-init.c:22: }
inc sp inc sp
pop ix pop ix
ret ret

338
Source/HBIOS/ch376-native/keyboard/kyb_driver.c.s

@ -41,14 +41,6 @@ _write_index:
DEFS 1 DEFS 1
_read_index: _read_index:
DEFS 1 DEFS 1
_alt_write_index:
DEFS 1
_alt_read_index:
DEFS 1
_reports:
DEFS 64
_queued_report:
DEFS 2
_report: _report:
DEFS 8 DEFS 8
_previous: _previous:
@ -68,110 +60,77 @@ _previous:
;-------------------------------------------------------- ;--------------------------------------------------------
; code ; code
;-------------------------------------------------------- ;--------------------------------------------------------
;source-doc/keyboard/kyb_driver.c:28: #define EI __asm__("EI")
;source-doc/keyboard/kyb_driver.c:23: #define EI __asm__("EI")
; --------------------------------- ; ---------------------------------
; Function report_diff ; Function report_diff
; --------------------------------- ; ---------------------------------
_report_diff: _report_diff:
;source-doc/keyboard/kyb_driver.c:29:
;source-doc/keyboard/kyb_driver.c:24:
ld de,_report+0 ld de,_report+0
;source-doc/keyboard/kyb_driver.c:30: static uint8_t report_diff() __sdcccall(1) {
;source-doc/keyboard/kyb_driver.c:33:
;source-doc/keyboard/kyb_driver.c:25: static uint8_t report_diff() __sdcccall(1) {
;source-doc/keyboard/kyb_driver.c:28:
ld b,0x08 ld b,0x08
ld hl,_previous ld hl,_previous
l_report_diff_00103: l_report_diff_00103:
;source-doc/keyboard/kyb_driver.c:34: uint8_t i = sizeof(report);
;source-doc/keyboard/kyb_driver.c:29: uint8_t i = sizeof(report);
ld a, (de) ld a, (de)
inc de inc de
ld c, (hl) ld c, (hl)
inc hl inc hl
sub c sub c
jr Z,l_report_diff_00104 jr Z,l_report_diff_00104
;source-doc/keyboard/kyb_driver.c:35: do {
;source-doc/keyboard/kyb_driver.c:30: do {
ld a,0x01 ld a,0x01
jr l_report_diff_00106 jr l_report_diff_00106
l_report_diff_00104: l_report_diff_00104:
;source-doc/keyboard/kyb_driver.c:36: if (*a++ != *b++)
;source-doc/keyboard/kyb_driver.c:31: if (*a++ != *b++)
djnz l_report_diff_00103 djnz l_report_diff_00103
;source-doc/keyboard/kyb_driver.c:38: } while (--i != 0);
;source-doc/keyboard/kyb_driver.c:33: } while (--i != 0);
xor a xor a
l_report_diff_00106: l_report_diff_00106:
;source-doc/keyboard/kyb_driver.c:39:
;source-doc/keyboard/kyb_driver.c:34:
ret ret
;source-doc/keyboard/kyb_driver.c:41: }
; ---------------------------------
; Function report_put
; ---------------------------------
_report_put:
;source-doc/keyboard/kyb_driver.c:42:
ld a, (_alt_write_index)
inc a
and 0x07
ld c, a
;source-doc/keyboard/kyb_driver.c:44: uint8_t next_write_index = (alt_write_index + 1) & KEYBOARD_BUFFER_SIZE_MASK;
ld a,(_alt_read_index)
sub c
ret Z
;source-doc/keyboard/kyb_driver.c:45:
ld de,_reports+0
ld hl, (_alt_write_index)
ld h,0x00
add hl, hl
add hl, hl
add hl, hl
add hl, de
ex de, hl
push bc
ld bc,0x0008
ld hl,_report
ldir
pop bc
;source-doc/keyboard/kyb_driver.c:46: if (next_write_index != alt_read_index) { // Check if buffer is not full
ld hl,_alt_write_index
ld (hl), c
;source-doc/keyboard/kyb_driver.c:48: alt_write_index = next_write_index;
ret
;source-doc/keyboard/kyb_driver.c:50: }
;source-doc/keyboard/kyb_driver.c:36: }
; --------------------------------- ; ---------------------------------
; Function keyboard_buf_put ; Function keyboard_buf_put
; --------------------------------- ; ---------------------------------
_keyboard_buf_put: _keyboard_buf_put:
ld c, a ld c, a
;source-doc/keyboard/kyb_driver.c:51:
;source-doc/keyboard/kyb_driver.c:37:
ld b,0x00 ld b,0x00
ld hl,+(_report + 2) ld hl,+(_report + 2)
add hl, bc add hl, bc
;source-doc/keyboard/kyb_driver.c:52: static void keyboard_buf_put(const uint8_t indx) __sdcccall(1) {
;source-doc/keyboard/kyb_driver.c:38: static void keyboard_buf_put(const uint8_t indx) __sdcccall(1) {
ld a,(hl) ld a,(hl)
ld c,a ld c,a
cp 0x80 cp 0x80
jr NC,l_keyboard_buf_put_00111 jr NC,l_keyboard_buf_put_00111
or a or a
;source-doc/keyboard/kyb_driver.c:53: const uint8_t key_code = report.keyCode[indx];
;source-doc/keyboard/kyb_driver.c:39: const uint8_t key_code = report.keyCode[indx];
jr Z,l_keyboard_buf_put_00111 jr Z,l_keyboard_buf_put_00111
;source-doc/keyboard/kyb_driver.c:57: // if already reported, just skip it
;source-doc/keyboard/kyb_driver.c:58: uint8_t i = 6;
;source-doc/keyboard/kyb_driver.c:43: // if already reported, just skip it
;source-doc/keyboard/kyb_driver.c:44: uint8_t i = 6;
ld b,0x06 ld b,0x06
ld hl,+(_previous + 2) ld hl,+(_previous + 2)
l_keyboard_buf_put_00106: l_keyboard_buf_put_00106:
;source-doc/keyboard/kyb_driver.c:59: uint8_t *a = previous.keyCode;
;source-doc/keyboard/kyb_driver.c:45: uint8_t *a = previous.keyCode;
ld a, (hl) ld a, (hl)
inc hl inc hl
sub c sub c
;source-doc/keyboard/kyb_driver.c:60: do {
;source-doc/keyboard/kyb_driver.c:46: do {
ret Z ret Z
;source-doc/keyboard/kyb_driver.c:61: if (*a++ == key_code)
;source-doc/keyboard/kyb_driver.c:47: if (*a++ == key_code)
djnz l_keyboard_buf_put_00106 djnz l_keyboard_buf_put_00106
;source-doc/keyboard/kyb_driver.c:63: } while (--i != 0);
;source-doc/keyboard/kyb_driver.c:49: } while (--i != 0);
ld a, (_write_index) ld a, (_write_index)
inc a inc a
and 0x07 and 0x07
ld b, a ld b, a
;source-doc/keyboard/kyb_driver.c:64:
;source-doc/keyboard/kyb_driver.c:50:
ld a,(_read_index) ld a,(_read_index)
sub b sub b
ret Z ret Z
;source-doc/keyboard/kyb_driver.c:65: uint8_t next_write_index = (write_index + 1) & KEYBOARD_BUFFER_SIZE_MASK;
;source-doc/keyboard/kyb_driver.c:51: uint8_t next_write_index = (write_index + 1) & KEYBOARD_BUFFER_SIZE_MASK;
ld de,_buffer+0 ld de,_buffer+0
ld hl, (_write_index) ld hl, (_write_index)
ld h,0x00 ld h,0x00
@ -186,101 +145,66 @@ l_keyboard_buf_put_00106:
inc de inc de
ld a, l ld a, l
ld (de), a ld (de), a
;source-doc/keyboard/kyb_driver.c:66: if (next_write_index != read_index) { // Check if buffer is not full
;source-doc/keyboard/kyb_driver.c:52: if (next_write_index != read_index) { // Check if buffer is not full
ld hl,_write_index ld hl,_write_index
ld (hl), b ld (hl), b
l_keyboard_buf_put_00111: l_keyboard_buf_put_00111:
;source-doc/keyboard/kyb_driver.c:68: write_index = next_write_index;
;source-doc/keyboard/kyb_driver.c:54: write_index = next_write_index;
ret ret
;source-doc/keyboard/kyb_driver.c:70: }
;source-doc/keyboard/kyb_driver.c:56: }
; --------------------------------- ; ---------------------------------
; Function usb_kyb_buf_size
; Function usb_kyb_status
; --------------------------------- ; ---------------------------------
_usb_kyb_buf_size:
;source-doc/keyboard/kyb_driver.c:71:
_usb_kyb_status:
;source-doc/keyboard/kyb_driver.c:57:
DI DI
;source-doc/keyboard/kyb_driver.c:76: uint8_t alt_size;
ld a,(_alt_write_index)
ld hl,_alt_read_index
sub (hl)
jr C,l_usb_kyb_buf_size_00102
;source-doc/keyboard/kyb_driver.c:77:
ld a,(_alt_write_index)
ld hl,_alt_read_index
sub (hl)
ld d, a
jr l_usb_kyb_buf_size_00103
l_usb_kyb_buf_size_00102:
;source-doc/keyboard/kyb_driver.c:79: alt_size = alt_write_index - alt_read_index;
ld hl, (_alt_read_index)
ld a,0x08
sub l
ld hl, (_alt_write_index)
add a, l
ld d, a
l_usb_kyb_buf_size_00103:
;source-doc/keyboard/kyb_driver.c:81: alt_size = KEYBOARD_BUFFER_SIZE - alt_read_index + alt_write_index;
ld a, d
or a
jr Z,l_usb_kyb_buf_size_00105
;source-doc/keyboard/kyb_driver.c:82:
ld a, (_alt_read_index)
inc a
and 0x07
ld (_alt_read_index),a
l_usb_kyb_buf_size_00105:
;source-doc/keyboard/kyb_driver.c:84: alt_read_index = (alt_read_index + 1) & KEYBOARD_BUFFER_SIZE_MASK;
;source-doc/keyboard/kyb_driver.c:61: uint8_t size;
ld a,(_write_index) ld a,(_write_index)
ld hl,_read_index ld hl,_read_index
sub (hl) sub (hl)
jr C,l_usb_kyb_buf_size_00107
;source-doc/keyboard/kyb_driver.c:85:
jr C,l_usb_kyb_status_00102
;source-doc/keyboard/kyb_driver.c:62:
ld a,(_write_index) ld a,(_write_index)
ld hl,_read_index ld hl,_read_index
sub (hl) sub (hl)
ld e, a
jr l_usb_kyb_buf_size_00108
l_usb_kyb_buf_size_00107:
;source-doc/keyboard/kyb_driver.c:87: size = write_index - read_index;
jr l_usb_kyb_status_00103
l_usb_kyb_status_00102:
;source-doc/keyboard/kyb_driver.c:64: size = write_index - read_index;
ld hl, (_read_index) ld hl, (_read_index)
ld a,0x08 ld a,0x08
sub l sub l
ld hl, (_write_index) ld hl, (_write_index)
add a, l add a, l
ld e, a
l_usb_kyb_buf_size_00108:
;source-doc/keyboard/kyb_driver.c:89: size = KEYBOARD_BUFFER_SIZE - read_index + write_index;
l_usb_kyb_status_00103:
;source-doc/keyboard/kyb_driver.c:66: size = KEYBOARD_BUFFER_SIZE - read_index + write_index;
EI EI
;source-doc/keyboard/kyb_driver.c:90:
xor a
xor a
ex de, hl
;source-doc/keyboard/kyb_driver.c:91: EI;
;source-doc/keyboard/kyb_driver.c:67:
;source-doc/keyboard/kyb_driver.c:68: EI;
ret ret
;source-doc/keyboard/kyb_driver.c:93: }
;source-doc/keyboard/kyb_driver.c:70: }
; --------------------------------- ; ---------------------------------
; Function usb_kyb_buf_get_next
; Function usb_kyb_read
; --------------------------------- ; ---------------------------------
_usb_kyb_buf_get_next:
_usb_kyb_read:
push ix push ix
ld ix,0 ld ix,0
add ix,sp add ix,sp
push af push af
push af push af
;source-doc/keyboard/kyb_driver.c:94:
;source-doc/keyboard/kyb_driver.c:71:
ld a,(_write_index) ld a,(_write_index)
ld hl,_read_index ld hl,_read_index
sub (hl) sub (hl)
jr NZ,l_usb_kyb_buf_get_next_00102
;source-doc/keyboard/kyb_driver.c:95: uint32_t usb_kyb_buf_get_next() {
jr NZ,l_usb_kyb_read_00102
;source-doc/keyboard/kyb_driver.c:72: uint32_t usb_kyb_read() {
ld hl,0xff00 ld hl,0xff00
ld e, l ld e, l
ld d, l ld d, l
jr l_usb_kyb_buf_get_next_00103
l_usb_kyb_buf_get_next_00102:
;source-doc/keyboard/kyb_driver.c:97: return 0x0000FF00; // H = -1, D, E, L = 0
jr l_usb_kyb_read_00103
l_usb_kyb_read_00102:
;source-doc/keyboard/kyb_driver.c:74: return 0x0000FF00; // H = -1, D, E, L = 0
DI DI
;source-doc/keyboard/kyb_driver.c:98:
;source-doc/keyboard/kyb_driver.c:75:
ld bc,_buffer+0 ld bc,_buffer+0
ld hl, (_read_index) ld hl, (_read_index)
ld h,0x00 ld h,0x00
@ -289,23 +213,23 @@ l_usb_kyb_buf_get_next_00102:
ld c, (hl) ld c, (hl)
inc hl inc hl
ld b, (hl) ld b, (hl)
;source-doc/keyboard/kyb_driver.c:99: DI;
;source-doc/keyboard/kyb_driver.c:100: const uint8_t modifier_key = buffer[read_index] >> 8;
;source-doc/keyboard/kyb_driver.c:76: DI;
;source-doc/keyboard/kyb_driver.c:77: const uint8_t modifier_key = buffer[read_index] >> 8;
ld a, (_read_index) ld a, (_read_index)
inc a inc a
and 0x07 and 0x07
ld hl,_read_index ld hl,_read_index
ld (hl), a ld (hl), a
;source-doc/keyboard/kyb_driver.c:101: const uint8_t key_code = buffer[read_index] & 255;
;source-doc/keyboard/kyb_driver.c:78: const uint8_t key_code = buffer[read_index] & 255;
EI EI
;source-doc/keyboard/kyb_driver.c:107: // L: KeyCode aka scan code
;source-doc/keyboard/kyb_driver.c:84: // L: KeyCode aka scan code
push bc push bc
ld l, c ld l, c
ld a, b ld a, b
call _scancode_to_char call _scancode_to_char
ld e, a ld e, a
pop bc pop bc
;source-doc/keyboard/kyb_driver.c:110: /* D = modifier, e-> char, H = 0, L=>code */
;source-doc/keyboard/kyb_driver.c:87: /* D = modifier, e-> char, H = 0, L=>code */
xor a xor a
ld (ix-1),b ld (ix-1),b
xor a xor a
@ -321,57 +245,54 @@ l_usb_kyb_buf_get_next_00102:
ld (ix-1),a ld (ix-1),a
pop hl pop hl
push hl push hl
l_usb_kyb_buf_get_next_00103:
;source-doc/keyboard/kyb_driver.c:111:
l_usb_kyb_read_00103:
;source-doc/keyboard/kyb_driver.c:88:
ld sp, ix ld sp, ix
pop ix pop ix
ret ret
;source-doc/keyboard/kyb_driver.c:113: }
;source-doc/keyboard/kyb_driver.c:90: }
; --------------------------------- ; ---------------------------------
; Function usb_kyb_flush ; Function usb_kyb_flush
; --------------------------------- ; ---------------------------------
_usb_kyb_flush: _usb_kyb_flush:
;source-doc/keyboard/kyb_driver.c:114:
;source-doc/keyboard/kyb_driver.c:91:
DI DI
;source-doc/keyboard/kyb_driver.c:115: uint8_t usb_kyb_flush() __sdcccall(1) {
xor a
ld (_alt_read_index),a
ld (_alt_write_index),a
;source-doc/keyboard/kyb_driver.c:92: uint8_t usb_kyb_flush() __sdcccall(1) {
xor a xor a
ld (_read_index),a ld (_read_index),a
ld (_write_index),a ld (_write_index),a
;source-doc/keyboard/kyb_driver.c:118:
;source-doc/keyboard/kyb_driver.c:95:
ld de,_previous+0 ld de,_previous+0
;source-doc/keyboard/kyb_driver.c:119: uint8_t i = sizeof(previous);
;source-doc/keyboard/kyb_driver.c:120: uint8_t *a = (uint8_t *)previous;
;source-doc/keyboard/kyb_driver.c:96: uint8_t i = sizeof(previous);
;source-doc/keyboard/kyb_driver.c:97: uint8_t *a = (uint8_t *)previous;
ld b,0x08 ld b,0x08
ld hl,_report ld hl,_report
l_usb_kyb_flush_00101: l_usb_kyb_flush_00101:
;source-doc/keyboard/kyb_driver.c:121: uint8_t *b = (uint8_t *)report;
;source-doc/keyboard/kyb_driver.c:98: uint8_t *b = (uint8_t *)report;
xor a xor a
ld (de), a ld (de), a
inc de inc de
;source-doc/keyboard/kyb_driver.c:122: do {
;source-doc/keyboard/kyb_driver.c:99: do {
ld (hl),0x00 ld (hl),0x00
inc hl inc hl
;source-doc/keyboard/kyb_driver.c:123: *a++ = 0;
;source-doc/keyboard/kyb_driver.c:100: *a++ = 0;
djnz l_usb_kyb_flush_00101 djnz l_usb_kyb_flush_00101
;source-doc/keyboard/kyb_driver.c:125: } while (--i != 0);
;source-doc/keyboard/kyb_driver.c:102: } while (--i != 0);
EI EI
;source-doc/keyboard/kyb_driver.c:127: EI;
;source-doc/keyboard/kyb_driver.c:104: EI;
xor a xor a
;source-doc/keyboard/kyb_driver.c:128:
;source-doc/keyboard/kyb_driver.c:105:
ret ret
;source-doc/keyboard/kyb_driver.c:130: }
;source-doc/keyboard/kyb_driver.c:107: }
; --------------------------------- ; ---------------------------------
; Function usb_kyb_tick ; Function usb_kyb_tick
; --------------------------------- ; ---------------------------------
_usb_kyb_tick: _usb_kyb_tick:
;source-doc/keyboard/kyb_driver.c:131:
;source-doc/keyboard/kyb_driver.c:108:
ld hl,_in_critical_usb_section ld hl,_in_critical_usb_section
ld a, (hl) ld a, (hl)
or a or a
;source-doc/keyboard/kyb_driver.c:132: void usb_kyb_tick(void) {
;source-doc/keyboard/kyb_driver.c:109: void usb_kyb_tick(void) {
jr NZ,l_usb_kyb_tick_00112 jr NZ,l_usb_kyb_tick_00112
;././source-doc/base-drv//ch376.h:111: ;././source-doc/base-drv//ch376.h:111:
ld l,0x0b ld l,0x0b
@ -384,7 +305,7 @@ _usb_kyb_tick:
ld a,0x1f ld a,0x1f
ld bc,_CH376_DATA_PORT ld bc,_CH376_DATA_PORT
out (c), a out (c), a
;source-doc/keyboard/kyb_driver.c:135:
;source-doc/keyboard/kyb_driver.c:112:
ld bc,_report+0 ld bc,_report+0
ld hl, (_keyboard_config) ld hl, (_keyboard_config)
ld a,0x08 ld a,0x08
@ -409,81 +330,63 @@ _usb_kyb_tick:
ld a,0xdf ld a,0xdf
ld bc,_CH376_DATA_PORT ld bc,_CH376_DATA_PORT
out (c), a out (c), a
;source-doc/keyboard/kyb_driver.c:137: result = usbdev_dat_in_trnsfer_0((device_config *)keyboard_config, (uint8_t *)&report, 8);
;source-doc/keyboard/kyb_driver.c:114: result = usbdev_dat_in_trnsfer_0((device_config *)keyboard_config, (uint8_t *)&report, 8);
ld hl,_result ld hl,_result
ld a, (hl) ld a, (hl)
or a or a
jr NZ,l_usb_kyb_tick_00112 jr NZ,l_usb_kyb_tick_00112
;source-doc/keyboard/kyb_driver.c:138: ch_configure_nak_retry_3s();
;source-doc/keyboard/kyb_driver.c:115: ch_configure_nak_retry_3s();
call _report_diff call _report_diff
or a or a
jr Z,l_usb_kyb_tick_00112 jr Z,l_usb_kyb_tick_00112
;source-doc/keyboard/kyb_driver.c:139: if (result == 0) {
call _report_put
;source-doc/keyboard/kyb_driver.c:141: report_put();
;source-doc/keyboard/kyb_driver.c:117: if (report_diff()) {
ld b,0x06 ld b,0x06
l_usb_kyb_tick_00103: l_usb_kyb_tick_00103:
;source-doc/keyboard/kyb_driver.c:142: uint8_t i = 6;
;source-doc/keyboard/kyb_driver.c:118: uint8_t i = 6;
ld a, b ld a, b
dec a dec a
push bc push bc
call _keyboard_buf_put call _keyboard_buf_put
pop bc pop bc
;source-doc/keyboard/kyb_driver.c:143: do {
;source-doc/keyboard/kyb_driver.c:119: do {
djnz l_usb_kyb_tick_00103 djnz l_usb_kyb_tick_00103
;source-doc/keyboard/kyb_driver.c:144: keyboard_buf_put(i - 1);
;source-doc/keyboard/kyb_driver.c:120: keyboard_buf_put(i - 1);
ld de,_previous ld de,_previous
ld bc,0x0008 ld bc,0x0008
ld hl,_report ld hl,_report
ldir ldir
l_usb_kyb_tick_00112: l_usb_kyb_tick_00112:
;source-doc/keyboard/kyb_driver.c:147: }
;source-doc/keyboard/kyb_driver.c:123: }
ret ret
;source-doc/keyboard/kyb_driver.c:149: }
;source-doc/keyboard/kyb_driver.c:125: }
; --------------------------------- ; ---------------------------------
; Function usb_kyb_init ; Function usb_kyb_init
; --------------------------------- ; ---------------------------------
_usb_kyb_init: _usb_kyb_init:
push ix
ld ix,0
add ix,sp
;source-doc/keyboard/kyb_driver.c:151: usb_error usb_kyb_init(const uint8_t dev_index) {
ld a,(ix+4)
;source-doc/keyboard/kyb_driver.c:126:
call _get_usb_device_config call _get_usb_device_config
ex de, hl ex de, hl
ld (_keyboard_config), hl ld (_keyboard_config), hl
;source-doc/keyboard/kyb_driver.c:153: keyboard_config = (device_config_keyboard *)get_usb_device_config(dev_index);
;source-doc/keyboard/kyb_driver.c:128: keyboard_config = (device_config_keyboard *)get_usb_device_config(dev_index);
ld hl,_keyboard_config + 1 ld hl,_keyboard_config + 1
ld a, (hl) ld a, (hl)
dec hl dec hl
or (hl) or (hl)
jr NZ,l_usb_kyb_init_00102
;source-doc/keyboard/kyb_driver.c:154:
ld l,0x0f
jr l_usb_kyb_init_00106
l_usb_kyb_init_00102:
;source-doc/keyboard/kyb_driver.c:156: return USB_ERR_OTHER;
;source-doc/keyboard/kyb_driver.c:129:
ret Z
;source-doc/keyboard/kyb_driver.c:131: return;
ld a,0x01 ld a,0x01
push af push af
inc sp inc sp
ld hl, (_keyboard_config) ld hl, (_keyboard_config)
call _hid_set_protocol call _hid_set_protocol
ld l, a
or a
jr NZ,l_usb_kyb_init_00105
;source-doc/keyboard/kyb_driver.c:157:
;source-doc/keyboard/kyb_driver.c:132:
ld a,0x80 ld a,0x80
push af push af
inc sp inc sp
ld hl, (_keyboard_config) ld hl, (_keyboard_config)
call _hid_set_idle call _hid_set_idle
ld l, a
;source-doc/keyboard/kyb_driver.c:159: return hid_set_idle(keyboard_config, 0x80);
;source-doc/keyboard/kyb_driver.c:160:
l_usb_kyb_init_00105:
l_usb_kyb_init_00106:
;source-doc/keyboard/kyb_driver.c:161: done:
pop ix
;source-doc/keyboard/kyb_driver.c:133: hid_set_protocol(keyboard_config, 1);
ret ret
_keyboard_config: _keyboard_config:
DEFW +0x0000 DEFW +0x0000
@ -507,77 +410,6 @@ _write_index:
DEFB +0x00 DEFB +0x00
_read_index: _read_index:
DEFB +0x00 DEFB +0x00
_alt_write_index:
DEFB +0x00
_alt_read_index:
DEFB +0x00
_reports:
DEFB +0x00
DEFB +0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
DEFB 0x00
_queued_report:
DEFW +0x0000
_report: _report:
DEFB +0x00 DEFB +0x00
DEFB +0x00 DEFB +0x00

1
Source/HBIOS/ch376-native/source-doc/keyboard/kyb-init.c

@ -20,5 +20,6 @@ uint8_t keyboard_init(void) __sdcccall(1) {
} while (++index != MAX_NUMBER_OF_DEVICES + 1); } while (++index != MAX_NUMBER_OF_DEVICES + 1);
print_string("\r\nUSB: KEYBOARD: NOT FOUND$"); print_string("\r\nUSB: KEYBOARD: NOT FOUND$");
return 0; return 0;
} }

74
Source/HBIOS/ch376-native/source-doc/keyboard/kyb_driver.asm

@ -1,74 +0,0 @@
;
; Inputs:
; None
;
; Outputs:
; A: Status / Codes Pending
; B: Number of buffered usb reports
; A': USB Report Modifier Key State (valid if B > 0)
; B', C', D', E', H', L': USB Report's 6 key codes (valid only if B > 0)
;
; Return a count of the number of key Codes Pending (A) in the keyboard buffer.
; If it is not possible to determine the actual number in the buffer, it is
; acceptable to return 1 to indicate there are key codes available to read and
; 0 if there are none available.
; The value returned in register A is used as both a Status (A) code and the
; return value. Negative values (bit 7 set) indicate a standard HBIOS result
; (error) code. Otherwise, the return value represents the number of key codes
; pending.
;
; USB Keyboard Extension:
; Returns the current USB HID keyboard report data.
; Register B contains the number of buffered reports available:
; B = 0: No reports available
; B > 0: At least one report available (will be consumed after reading)
; When a report is available (B > 0):
; A': Contains modifier key states
; B',C',D',E',H',L': Contains up to 6 concurrent key codes
; See USB HID Usage Tables specification for key codes
_usb_kyb_report:
exx
ld hl, (_alt_read_index)
ld h,0x00
add hl, hl
add hl, hl
add hl, hl
ld bc,_reports
add hl, bc
push hl ; address of potential que'd next usb report
call _usb_kyb_buf_size
ld a, l
ld b, h
ex af, af'
ld a, b
or a
pop iy ; retrieve the next que'd usb_report address
jr z, no_queued_reports
ld a, (iy)
ex af, af'
exx
ld b, (iy+2)
ld c, (iy+3)
ld d, (iy+4)
ld e, (iy+5)
ld h, (iy+6)
ld l, (iy+7)
exx
ret
no_queued_reports:
ex af, af'
exx
ld bc, 0
ld d, b
ld e, b
ld l, b
ld h, b
exx
ret

48
Source/HBIOS/ch376-native/source-doc/keyboard/kyb_driver.c

@ -16,13 +16,8 @@ static modifier_and_code_t buffer[KEYBOARD_BUFFER_SIZE] = {0};
static uint8_t write_index = 0; static uint8_t write_index = 0;
static uint8_t read_index = 0; static uint8_t read_index = 0;
static uint8_t alt_write_index = 0;
static uint8_t alt_read_index = 0;
static keyboard_report_t reports[KEYBOARD_BUFFER_SIZE] = {{0}};
static keyboard_report_t *queued_report = NULL;
static keyboard_report_t report = {0};
static keyboard_report_t previous = {0};
static keyboard_report_t report = {0};
static keyboard_report_t previous = {0};
#define DI __asm__("DI") #define DI __asm__("DI")
#define EI __asm__("EI") #define EI __asm__("EI")
@ -40,15 +35,6 @@ static uint8_t report_diff() __sdcccall(1) {
return false; return false;
} }
static void report_put() {
uint8_t next_write_index = (alt_write_index + 1) & KEYBOARD_BUFFER_SIZE_MASK;
if (next_write_index != alt_read_index) { // Check if buffer is not full
reports[alt_write_index] = report;
alt_write_index = next_write_index;
}
}
static void keyboard_buf_put(const uint8_t indx) __sdcccall(1) { static void keyboard_buf_put(const uint8_t indx) __sdcccall(1) {
const uint8_t key_code = report.keyCode[indx]; const uint8_t key_code = report.keyCode[indx];
if (key_code >= 0x80 || key_code == 0) if (key_code >= 0x80 || key_code == 0)
@ -69,19 +55,10 @@ static void keyboard_buf_put(const uint8_t indx) __sdcccall(1) {
} }
} }
uint16_t usb_kyb_buf_size() {
uint8_t usb_kyb_status() __sdcccall(1) {
DI; DI;
uint8_t size; uint8_t size;
uint8_t alt_size;
if (alt_write_index >= alt_read_index)
alt_size = alt_write_index - alt_read_index;
else
alt_size = KEYBOARD_BUFFER_SIZE - alt_read_index + alt_write_index;
if (alt_size != 0)
alt_read_index = (alt_read_index + 1) & KEYBOARD_BUFFER_SIZE_MASK;
if (write_index >= read_index) if (write_index >= read_index)
size = write_index - read_index; size = write_index - read_index;
@ -89,10 +66,10 @@ uint16_t usb_kyb_buf_size() {
size = KEYBOARD_BUFFER_SIZE - read_index + write_index; size = KEYBOARD_BUFFER_SIZE - read_index + write_index;
EI; EI;
return (uint16_t)alt_size << 8 | (uint16_t)size;
return size;
} }
uint32_t usb_kyb_buf_get_next() {
uint32_t usb_kyb_read() {
if (write_index == read_index) // Check if buffer is empty if (write_index == read_index) // Check if buffer is empty
return 0x0000FF00; // H = -1, D, E, L = 0 return 0x0000FF00; // H = -1, D, E, L = 0
@ -114,7 +91,7 @@ uint32_t usb_kyb_buf_get_next() {
uint8_t usb_kyb_flush() __sdcccall(1) { uint8_t usb_kyb_flush() __sdcccall(1) {
DI; DI;
write_index = read_index = alt_write_index = alt_read_index = 0;
write_index = read_index = 0;
uint8_t i = sizeof(previous); uint8_t i = sizeof(previous);
uint8_t *a = (uint8_t *)previous; uint8_t *a = (uint8_t *)previous;
@ -138,7 +115,6 @@ void usb_kyb_tick(void) {
ch_configure_nak_retry_3s(); ch_configure_nak_retry_3s();
if (result == 0) { if (result == 0) {
if (report_diff()) { if (report_diff()) {
report_put();
uint8_t i = 6; uint8_t i = 6;
do { do {
keyboard_buf_put(i - 1); keyboard_buf_put(i - 1);
@ -148,16 +124,12 @@ void usb_kyb_tick(void) {
} }
} }
usb_error usb_kyb_init(const uint8_t dev_index) {
uint8_t result;
void usb_kyb_init(const uint8_t dev_index) __sdcccall(1) {
keyboard_config = (device_config_keyboard *)get_usb_device_config(dev_index); keyboard_config = (device_config_keyboard *)get_usb_device_config(dev_index);
if (keyboard_config == NULL) if (keyboard_config == NULL)
return USB_ERR_OTHER;
CHECK(hid_set_protocol(keyboard_config, 1));
return hid_set_idle(keyboard_config, 0x80);
return;
done:
return result;
hid_set_protocol(keyboard_config, 1);
hid_set_idle(keyboard_config, 0x80);
} }

8
Source/HBIOS/ch376-native/source-doc/keyboard/kyb_driver.h

@ -4,9 +4,9 @@
#include <ch376.h> #include <ch376.h>
#include <stdint.h> #include <stdint.h>
extern usb_error usb_kyb_init(const uint8_t dev_index);
extern uint8_t usb_kyb_flush() __sdcccall(1);
extern uint32_t usb_kyb_buf_get_next();
// extern <registers> usb_kyb_report();
extern void usb_kyb_init(const uint8_t dev_index) __sdcccall(1);
extern uint8_t usb_kyb_flush() __sdcccall(1);
extern uint8_t usb_kyb_status() __sdcccall(1);
extern uint32_t usb_kyb_read();
#endif #endif

17
Source/HBIOS/ch376kyb.asm

@ -91,9 +91,6 @@ VEC_CHUKB_TICK:
; ;
; Outputs: ; Outputs:
; A: Status / Codes Pending ; A: Status / Codes Pending
; B: Number of buffered usb reports
; A': USB Report Modifier Key State (valid if B > 0)
; B', C', D', E', H', L': USB Report's 6 key codes (valid only if B > 0)
; ;
; Return a count of the number of key Codes Pending (A) in the keyboard buffer. ; Return a count of the number of key Codes Pending (A) in the keyboard buffer.
; If it is not possible to determine the actual number in the buffer, it is ; If it is not possible to determine the actual number in the buffer, it is
@ -104,17 +101,7 @@ VEC_CHUKB_TICK:
; (error) code. Otherwise, the return value represents the number of key codes ; (error) code. Otherwise, the return value represents the number of key codes
; pending. ; pending.
; ;
; USB Keyboard Extension:
; Returns the current USB HID keyboard report data.
; Register B contains the number of buffered reports available:
; B = 0: No reports available
; B > 0: At least one report available (will be consumed after reading)
; When a report is available (B > 0):
; A': Contains modifier key states
; B',C',D',E',H',L': Contains up to 6 concurrent key codes
; See USB HID Usage Tables specification for key codes
UKY_STAT .EQU _usb_kyb_report
UKY_STAT: .EQU _usb_kyb_status
; ### Function 0x4D -- Video Keyboard Flush (VDAKFL) ; ### Function 0x4D -- Video Keyboard Flush (VDAKFL)
; ;
@ -164,7 +151,7 @@ UKY_FLUSH .EQU _usb_kyb_flush
; function keys and arrows, are returned as reserved codes. ; function keys and arrows, are returned as reserved codes.
; ;
UKY_READ: UKY_READ:
CALL _usb_kyb_buf_get_next
CALL _usb_kyb_read
LD A, H LD A, H
OR A OR A
JR NZ, UKY_READ JR NZ, UKY_READ

Loading…
Cancel
Save