diff --git a/Source/HBIOS/ch376-native/Makefile b/Source/HBIOS/ch376-native/Makefile index a0989a7e..d16b6405 100644 --- a/Source/HBIOS/ch376-native/Makefile +++ b/Source/HBIOS/ch376-native/Makefile @@ -66,14 +66,20 @@ $$(ASSDIR)$(1).s: for dep in $$^; do dep=$$$${dep#*/} dep=$$$${dep#*/} - echo '#include "'ch376-native/$(1)/$$$${dep}'"' >> $$(ASSDIR)$(1).s + if [ -n "$$$${dep%%*.asm}" ]; then + echo '#include "'ch376-native/$(1)/$$$${dep}'"' >> $$(ASSDIR)$(1).s + else + echo '#include "'ch376-native/source-doc/$(1)/$$$${dep}'"' >> $$(ASSDIR)$(1).s + fi done $$(ASSDIR)$(1)/%.c.asm: $$(SRC)$(1)/%.c; $$(compile) +# $$(ASSDIR)$(1)/%.asm: $$(SRC)$(1)/%.asm; echo $$@ $$< $(1)_C_FILES := $$(wildcard $$(SRC)$(1)/*.c) -$(1)_S_FILES := $$(patsubst ./source-doc/%, ./%, $$($(1)_C_FILES:.c=.c.s)) -./$(1).s: $$($(1)_S_FILES) +$(1)_ASM_FILES := $$(wildcard $$(SRC)$(1)/*.asm) +$(1)_C_S_FILES := $$(patsubst ./source-doc/%, ./%, $$($(1)_C_FILES:.c=.c.s)) +./$(1).s: $$($(1)_C_S_FILES) $$($(1)_ASM_FILES) endef $(eval $(call build_subsystem,base-drv)) diff --git a/Source/HBIOS/ch376-native/keyboard.s b/Source/HBIOS/ch376-native/keyboard.s index af3a439c..8ceed645 100644 --- a/Source/HBIOS/ch376-native/keyboard.s +++ b/Source/HBIOS/ch376-native/keyboard.s @@ -3,3 +3,4 @@ #include "ch376-native/keyboard/class_hid_keyboard.c.s" #include "ch376-native/keyboard/kyb-init.c.s" #include "ch376-native/keyboard/kyb_driver.c.s" +#include "ch376-native/source-doc/keyboard/kyb_driver.asm" diff --git a/Source/HBIOS/ch376-native/keyboard/kyb_driver.c.s b/Source/HBIOS/ch376-native/keyboard/kyb_driver.c.s index f262150b..ded935b2 100644 --- a/Source/HBIOS/ch376-native/keyboard/kyb_driver.c.s +++ b/Source/HBIOS/ch376-native/keyboard/kyb_driver.c.s @@ -68,51 +68,51 @@ _previous: ;-------------------------------------------------------- ; code ;-------------------------------------------------------- -;source-doc/keyboard/kyb_driver.c:26: +;source-doc/keyboard/kyb_driver.c:28: #define EI __asm__("EI") ; --------------------------------- ; Function report_diff ; --------------------------------- _report_diff: -;source-doc/keyboard/kyb_driver.c:27: static uint8_t report_diff() __sdcccall(1) { +;source-doc/keyboard/kyb_driver.c:29: ld de,_report+0 -;source-doc/keyboard/kyb_driver.c:28: uint8_t *a = (uint8_t *)&report; -;source-doc/keyboard/kyb_driver.c:31: uint8_t i = sizeof(report); +;source-doc/keyboard/kyb_driver.c:30: static uint8_t report_diff() __sdcccall(1) { +;source-doc/keyboard/kyb_driver.c:33: ld b,0x08 ld hl,_previous l_report_diff_00103: -;source-doc/keyboard/kyb_driver.c:32: do { +;source-doc/keyboard/kyb_driver.c:34: uint8_t i = sizeof(report); ld a, (de) inc de ld c, (hl) inc hl sub c jr Z,l_report_diff_00104 -;source-doc/keyboard/kyb_driver.c:33: if (*a++ != *b++) +;source-doc/keyboard/kyb_driver.c:35: do { ld a,0x01 jr l_report_diff_00106 l_report_diff_00104: -;source-doc/keyboard/kyb_driver.c:34: return true; +;source-doc/keyboard/kyb_driver.c:36: if (*a++ != *b++) djnz l_report_diff_00103 -;source-doc/keyboard/kyb_driver.c:36: +;source-doc/keyboard/kyb_driver.c:38: } while (--i != 0); xor a l_report_diff_00106: -;source-doc/keyboard/kyb_driver.c:37: return false; - ret ;source-doc/keyboard/kyb_driver.c:39: + ret +;source-doc/keyboard/kyb_driver.c:41: } ; --------------------------------- ; Function report_put ; --------------------------------- _report_put: -;source-doc/keyboard/kyb_driver.c:40: static void 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:42: +;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:43: if (next_write_index != alt_read_index) { // Check if buffer is not full +;source-doc/keyboard/kyb_driver.c:45: ld de,_reports+0 ld hl, (_alt_write_index) ld h,0x00 @@ -126,52 +126,52 @@ _report_put: ld hl,_report ldir pop bc -;source-doc/keyboard/kyb_driver.c:44: reports[alt_write_index] = report; +;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:46: } +;source-doc/keyboard/kyb_driver.c:48: alt_write_index = next_write_index; ret -;source-doc/keyboard/kyb_driver.c:48: +;source-doc/keyboard/kyb_driver.c:50: } ; --------------------------------- ; Function keyboard_buf_put ; --------------------------------- _keyboard_buf_put: ld c, a -;source-doc/keyboard/kyb_driver.c:49: static void keyboard_buf_put(const uint8_t indx) __sdcccall(1) { +;source-doc/keyboard/kyb_driver.c:51: ld b,0x00 ld hl,+(_report + 2) add hl, bc -;source-doc/keyboard/kyb_driver.c:50: const uint8_t key_code = report.keyCode[indx]; +;source-doc/keyboard/kyb_driver.c:52: static void keyboard_buf_put(const uint8_t indx) __sdcccall(1) { ld a,(hl) ld c,a cp 0x80 jr NC,l_keyboard_buf_put_00111 or a -;source-doc/keyboard/kyb_driver.c:51: if (key_code >= 0x80 || key_code == 0) +;source-doc/keyboard/kyb_driver.c:53: const uint8_t key_code = report.keyCode[indx]; jr Z,l_keyboard_buf_put_00111 -;source-doc/keyboard/kyb_driver.c:55: uint8_t i = 6; -;source-doc/keyboard/kyb_driver.c:56: uint8_t *a = previous.keyCode; +;source-doc/keyboard/kyb_driver.c:57: // if already reported, just skip it +;source-doc/keyboard/kyb_driver.c:58: uint8_t i = 6; ld b,0x06 ld hl,+(_previous + 2) l_keyboard_buf_put_00106: -;source-doc/keyboard/kyb_driver.c:57: do { +;source-doc/keyboard/kyb_driver.c:59: uint8_t *a = previous.keyCode; ld a, (hl) inc hl sub c -;source-doc/keyboard/kyb_driver.c:58: if (*a++ == key_code) +;source-doc/keyboard/kyb_driver.c:60: do { ret Z -;source-doc/keyboard/kyb_driver.c:59: return; +;source-doc/keyboard/kyb_driver.c:61: if (*a++ == key_code) djnz l_keyboard_buf_put_00106 -;source-doc/keyboard/kyb_driver.c:61: +;source-doc/keyboard/kyb_driver.c:63: } while (--i != 0); ld a, (_write_index) inc a and 0x07 ld b, a -;source-doc/keyboard/kyb_driver.c:62: uint8_t next_write_index = (write_index + 1) & KEYBOARD_BUFFER_SIZE_MASK; +;source-doc/keyboard/kyb_driver.c:64: ld a,(_read_index) sub b ret Z -;source-doc/keyboard/kyb_driver.c:63: if (next_write_index != read_index) { // Check if buffer is not full +;source-doc/keyboard/kyb_driver.c:65: uint8_t next_write_index = (write_index + 1) & KEYBOARD_BUFFER_SIZE_MASK; ld de,_buffer+0 ld hl, (_write_index) ld h,0x00 @@ -186,30 +186,32 @@ l_keyboard_buf_put_00106: inc de ld a, l ld (de), a -;source-doc/keyboard/kyb_driver.c:64: buffer[write_index] = (uint16_t)report.bModifierKeys << 8 | (uint16_t)key_code; +;source-doc/keyboard/kyb_driver.c:66: if (next_write_index != read_index) { // Check if buffer is not full ld hl,_write_index ld (hl), b l_keyboard_buf_put_00111: -;source-doc/keyboard/kyb_driver.c:66: } +;source-doc/keyboard/kyb_driver.c:68: write_index = next_write_index; ret -;source-doc/keyboard/kyb_driver.c:68: +;source-doc/keyboard/kyb_driver.c:70: } ; --------------------------------- ; Function usb_kyb_buf_size ; --------------------------------- _usb_kyb_buf_size: -;source-doc/keyboard/kyb_driver.c:72: +;source-doc/keyboard/kyb_driver.c:71: + 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:73: if (alt_write_index >= alt_read_index) +;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:75: else +;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 @@ -217,29 +219,29 @@ l_usb_kyb_buf_size_00102: add a, l ld d, a l_usb_kyb_buf_size_00103: -;source-doc/keyboard/kyb_driver.c:77: +;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:78: if (alt_size != 0) +;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:80: +;source-doc/keyboard/kyb_driver.c:84: alt_read_index = (alt_read_index + 1) & KEYBOARD_BUFFER_SIZE_MASK; ld a,(_write_index) ld hl,_read_index sub (hl) jr C,l_usb_kyb_buf_size_00107 -;source-doc/keyboard/kyb_driver.c:81: if (write_index >= read_index) +;source-doc/keyboard/kyb_driver.c:85: ld a,(_write_index) ld hl,_read_index sub (hl) ld e, a jr l_usb_kyb_buf_size_00108 l_usb_kyb_buf_size_00107: -;source-doc/keyboard/kyb_driver.c:83: else +;source-doc/keyboard/kyb_driver.c:87: size = write_index - read_index; ld hl, (_read_index) ld a,0x08 sub l @@ -247,13 +249,15 @@ l_usb_kyb_buf_size_00107: add a, l ld e, a l_usb_kyb_buf_size_00108: -;source-doc/keyboard/kyb_driver.c:85: +;source-doc/keyboard/kyb_driver.c:89: size = KEYBOARD_BUFFER_SIZE - read_index + write_index; + EI +;source-doc/keyboard/kyb_driver.c:90: xor a xor a ex de, hl -;source-doc/keyboard/kyb_driver.c:86: return (uint16_t)alt_size << 8 | (uint16_t)size; +;source-doc/keyboard/kyb_driver.c:91: EI; ret -;source-doc/keyboard/kyb_driver.c:88: +;source-doc/keyboard/kyb_driver.c:93: } ; --------------------------------- ; Function usb_kyb_buf_get_next ; --------------------------------- @@ -263,18 +267,20 @@ _usb_kyb_buf_get_next: add ix,sp push af push af -;source-doc/keyboard/kyb_driver.c:89: uint32_t usb_kyb_buf_get_next() { +;source-doc/keyboard/kyb_driver.c:94: ld a,(_write_index) ld hl,_read_index sub (hl) jr NZ,l_usb_kyb_buf_get_next_00102 -;source-doc/keyboard/kyb_driver.c:90: if (write_index == read_index) // Check if buffer is empty +;source-doc/keyboard/kyb_driver.c:95: uint32_t usb_kyb_buf_get_next() { ld hl,0xff00 ld e, 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:92: +;source-doc/keyboard/kyb_driver.c:97: return 0x0000FF00; // H = -1, D, E, L = 0 + DI +;source-doc/keyboard/kyb_driver.c:98: ld bc,_buffer+0 ld hl, (_read_index) ld h,0x00 @@ -283,20 +289,23 @@ l_usb_kyb_buf_get_next_00102: ld c, (hl) inc hl ld b, (hl) -;source-doc/keyboard/kyb_driver.c:93: const uint8_t modifier_key = buffer[read_index] >> 8; -;source-doc/keyboard/kyb_driver.c:94: const uint8_t key_code = buffer[read_index] & 255; +;source-doc/keyboard/kyb_driver.c:99: DI; +;source-doc/keyboard/kyb_driver.c:100: const uint8_t modifier_key = buffer[read_index] >> 8; ld a, (_read_index) inc a and 0x07 - ld (_read_index),a -;source-doc/keyboard/kyb_driver.c:101: + ld hl,_read_index + ld (hl), a +;source-doc/keyboard/kyb_driver.c:101: const uint8_t key_code = buffer[read_index] & 255; + EI +;source-doc/keyboard/kyb_driver.c:107: // L: KeyCode aka scan code push bc ld l, c ld a, b call _scancode_to_char ld e, a pop bc -;source-doc/keyboard/kyb_driver.c:103: /* D = modifier, e-> char, H = 0, L=>code */ +;source-doc/keyboard/kyb_driver.c:110: /* D = modifier, e-> char, H = 0, L=>code */ xor a ld (ix-1),b xor a @@ -313,50 +322,56 @@ l_usb_kyb_buf_get_next_00102: pop hl push hl l_usb_kyb_buf_get_next_00103: -;source-doc/keyboard/kyb_driver.c:104: return (uint32_t)modifier_key << 24 | (uint32_t)c << 16 | key_code; +;source-doc/keyboard/kyb_driver.c:111: ld sp, ix pop ix ret -;source-doc/keyboard/kyb_driver.c:106: +;source-doc/keyboard/kyb_driver.c:113: } ; --------------------------------- ; Function usb_kyb_flush ; --------------------------------- _usb_kyb_flush: -;source-doc/keyboard/kyb_driver.c:107: void usb_kyb_flush() { +;source-doc/keyboard/kyb_driver.c:114: + 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 xor a ld (_read_index),a ld (_write_index),a -;source-doc/keyboard/kyb_driver.c:110: uint8_t i = sizeof(previous); +;source-doc/keyboard/kyb_driver.c:118: ld de,_previous+0 -;source-doc/keyboard/kyb_driver.c:111: uint8_t *a = (uint8_t *)previous; -;source-doc/keyboard/kyb_driver.c:112: uint8_t *b = (uint8_t *)report; +;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; ld b,0x08 ld hl,_report l_usb_kyb_flush_00101: -;source-doc/keyboard/kyb_driver.c:113: do { +;source-doc/keyboard/kyb_driver.c:121: uint8_t *b = (uint8_t *)report; xor a ld (de), a inc de -;source-doc/keyboard/kyb_driver.c:114: *a++ = 0; +;source-doc/keyboard/kyb_driver.c:122: do { ld (hl),0x00 inc hl -;source-doc/keyboard/kyb_driver.c:115: *b++ = 0; +;source-doc/keyboard/kyb_driver.c:123: *a++ = 0; djnz l_usb_kyb_flush_00101 -;source-doc/keyboard/kyb_driver.c:116: } while (--i != 0); +;source-doc/keyboard/kyb_driver.c:125: } while (--i != 0); + EI +;source-doc/keyboard/kyb_driver.c:127: EI; + xor a +;source-doc/keyboard/kyb_driver.c:128: ret -;source-doc/keyboard/kyb_driver.c:118: +;source-doc/keyboard/kyb_driver.c:130: } ; --------------------------------- ; Function usb_kyb_tick ; --------------------------------- _usb_kyb_tick: -;source-doc/keyboard/kyb_driver.c:119: void usb_kyb_tick(void) { +;source-doc/keyboard/kyb_driver.c:131: ld hl,_in_critical_usb_section ld a, (hl) or a -;source-doc/keyboard/kyb_driver.c:120: if (is_in_critical_section()) +;source-doc/keyboard/kyb_driver.c:132: void usb_kyb_tick(void) { jr NZ,l_usb_kyb_tick_00112 ;././source-doc/base-drv//ch376.h:111: ld l,0x0b @@ -369,7 +384,7 @@ _usb_kyb_tick: ld a,0x1f ld bc,_CH376_DATA_PORT out (c), a -;source-doc/keyboard/kyb_driver.c:123: ch_configure_nak_retry_disable(); +;source-doc/keyboard/kyb_driver.c:135: ld bc,_report+0 ld hl, (_keyboard_config) ld a,0x08 @@ -394,37 +409,37 @@ _usb_kyb_tick: ld a,0xdf ld bc,_CH376_DATA_PORT out (c), a -;source-doc/keyboard/kyb_driver.c:125: ch_configure_nak_retry_3s(); +;source-doc/keyboard/kyb_driver.c:137: result = usbdev_dat_in_trnsfer_0((device_config *)keyboard_config, (uint8_t *)&report, 8); ld hl,_result ld a, (hl) or a jr NZ,l_usb_kyb_tick_00112 -;source-doc/keyboard/kyb_driver.c:126: if (result == 0) { +;source-doc/keyboard/kyb_driver.c:138: ch_configure_nak_retry_3s(); call _report_diff or a jr Z,l_usb_kyb_tick_00112 -;source-doc/keyboard/kyb_driver.c:127: if (report_diff()) { +;source-doc/keyboard/kyb_driver.c:139: if (result == 0) { call _report_put -;source-doc/keyboard/kyb_driver.c:129: uint8_t i = 6; +;source-doc/keyboard/kyb_driver.c:141: report_put(); ld b,0x06 l_usb_kyb_tick_00103: -;source-doc/keyboard/kyb_driver.c:130: do { +;source-doc/keyboard/kyb_driver.c:142: uint8_t i = 6; ld a, b dec a push bc call _keyboard_buf_put pop bc -;source-doc/keyboard/kyb_driver.c:131: keyboard_buf_put(i - 1); +;source-doc/keyboard/kyb_driver.c:143: do { djnz l_usb_kyb_tick_00103 -;source-doc/keyboard/kyb_driver.c:132: } while (--i != 0); +;source-doc/keyboard/kyb_driver.c:144: keyboard_buf_put(i - 1); ld de,_previous ld bc,0x0008 ld hl,_report ldir l_usb_kyb_tick_00112: -;source-doc/keyboard/kyb_driver.c:135: } +;source-doc/keyboard/kyb_driver.c:147: } ret -;source-doc/keyboard/kyb_driver.c:137: +;source-doc/keyboard/kyb_driver.c:149: } ; --------------------------------- ; Function usb_kyb_init ; --------------------------------- @@ -432,22 +447,22 @@ _usb_kyb_init: push ix ld ix,0 add ix,sp -;source-doc/keyboard/kyb_driver.c:139: uint8_t result; +;source-doc/keyboard/kyb_driver.c:151: usb_error usb_kyb_init(const uint8_t dev_index) { ld a,(ix+4) call _get_usb_device_config ex de, hl ld (_keyboard_config), hl -;source-doc/keyboard/kyb_driver.c:141: +;source-doc/keyboard/kyb_driver.c:153: keyboard_config = (device_config_keyboard *)get_usb_device_config(dev_index); ld hl,_keyboard_config + 1 ld a, (hl) dec hl or (hl) jr NZ,l_usb_kyb_init_00102 -;source-doc/keyboard/kyb_driver.c:142: if (keyboard_config == NULL) +;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:144: +;source-doc/keyboard/kyb_driver.c:156: return USB_ERR_OTHER; ld a,0x01 push af inc sp @@ -456,18 +471,18 @@ l_usb_kyb_init_00102: ld l, a or a jr NZ,l_usb_kyb_init_00105 -;source-doc/keyboard/kyb_driver.c:145: CHECK(hid_set_protocol(keyboard_config, 1)); +;source-doc/keyboard/kyb_driver.c:157: ld a,0x80 push af inc sp ld hl, (_keyboard_config) call _hid_set_idle ld l, a -;source-doc/keyboard/kyb_driver.c:147: -;source-doc/keyboard/kyb_driver.c:148: done: +;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:149: return result; +;source-doc/keyboard/kyb_driver.c:161: done: pop ix ret _keyboard_config: diff --git a/Source/HBIOS/ch376-native/source-doc/keyboard/kyb_driver.asm b/Source/HBIOS/ch376-native/source-doc/keyboard/kyb_driver.asm new file mode 100644 index 00000000..9285b572 --- /dev/null +++ b/Source/HBIOS/ch376-native/source-doc/keyboard/kyb_driver.asm @@ -0,0 +1,74 @@ + +; +; 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 + + diff --git a/Source/HBIOS/ch376-native/source-doc/keyboard/kyb_driver.c b/Source/HBIOS/ch376-native/source-doc/keyboard/kyb_driver.c index 64ba8968..b16735f4 100644 --- a/Source/HBIOS/ch376-native/source-doc/keyboard/kyb_driver.c +++ b/Source/HBIOS/ch376-native/source-doc/keyboard/kyb_driver.c @@ -24,6 +24,9 @@ static keyboard_report_t *queued_report = NULL; static keyboard_report_t report = {0}; static keyboard_report_t previous = {0}; +#define DI __asm__("DI") +#define EI __asm__("EI") + static uint8_t report_diff() __sdcccall(1) { uint8_t *a = (uint8_t *)&report; uint8_t *b = (uint8_t *)&previous; @@ -67,6 +70,8 @@ static void keyboard_buf_put(const uint8_t indx) __sdcccall(1) { } uint16_t usb_kyb_buf_size() { + DI; + uint8_t size; uint8_t alt_size; @@ -83,6 +88,7 @@ uint16_t usb_kyb_buf_size() { else size = KEYBOARD_BUFFER_SIZE - read_index + write_index; + EI; return (uint16_t)alt_size << 8 | (uint16_t)size; } @@ -90,10 +96,11 @@ uint32_t usb_kyb_buf_get_next() { if (write_index == read_index) // Check if buffer is empty return 0x0000FF00; // H = -1, D, E, L = 0 + DI; const uint8_t modifier_key = buffer[read_index] >> 8; const uint8_t key_code = buffer[read_index] & 255; read_index = (read_index + 1) & KEYBOARD_BUFFER_SIZE_MASK; - + EI; // D: Modifier keys - aka Keystate // E: ASCII Code // H: 0 @@ -101,10 +108,12 @@ uint32_t usb_kyb_buf_get_next() { const unsigned char c = scancode_to_char(modifier_key, key_code); /* D = modifier, e-> char, H = 0, L=>code */ + return (uint32_t)modifier_key << 24 | (uint32_t)c << 16 | key_code; } -void usb_kyb_flush() { +uint8_t usb_kyb_flush() __sdcccall(1) { + DI; write_index = read_index = alt_write_index = alt_read_index = 0; uint8_t i = sizeof(previous); @@ -114,6 +123,10 @@ void usb_kyb_flush() { *a++ = 0; *b++ = 0; } while (--i != 0); + + EI; + + return 0; } void usb_kyb_tick(void) { diff --git a/Source/HBIOS/ch376-native/source-doc/keyboard/kyb_driver.h b/Source/HBIOS/ch376-native/source-doc/keyboard/kyb_driver.h index 8d3b4f1f..0e3ef51e 100644 --- a/Source/HBIOS/ch376-native/source-doc/keyboard/kyb_driver.h +++ b/Source/HBIOS/ch376-native/source-doc/keyboard/kyb_driver.h @@ -5,8 +5,8 @@ #include extern usb_error usb_kyb_init(const uint8_t dev_index); -extern void usb_kyb_flush(); +extern uint8_t usb_kyb_flush() __sdcccall(1); extern uint32_t usb_kyb_buf_get_next(); -extern uint16_t usb_kyb_buf_size(); +// extern usb_kyb_report(); #endif diff --git a/Source/HBIOS/ch376kyb.asm b/Source/HBIOS/ch376kyb.asm index 917a28f9..b368ac77 100644 --- a/Source/HBIOS/ch376kyb.asm +++ b/Source/HBIOS/ch376kyb.asm @@ -76,7 +76,6 @@ UKY_INT_SP .EQU $ - 2 VEC_CHUKB_TICK: JP HB_TICK - ; ### Function 0x4C -- Keyboard Status (VDAKST) ; ; Inputs: @@ -107,50 +106,7 @@ VEC_CHUKB_TICK: ; B',C',D',E',H',L': Contains up to 6 concurrent key codes ; See USB HID Usage Tables specification for key codes -UKY_STAT: - 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 - - HB_DI - call _usb_kyb_buf_size - HB_EI - 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 +UKY_STAT .EQU _usb_kyb_report ; ### Function 0x4D -- Video Keyboard Flush (VDAKFL) ; @@ -162,12 +118,8 @@ no_queued_reports: ; ; Purged and all contents discarded. The Status (A) is a standard HBIOS result code. ; -UKY_FLUSH: - HB_DI - CALL _usb_kyb_flush - HB_EI - XOR A - RET +UKY_FLUSH .EQU _usb_kyb_flush + ; ; ### Function 0x4E -- Video Keyboard Read (VDAKRD) ; @@ -204,9 +156,7 @@ UKY_FLUSH: ; function keys and arrows, are returned as reserved codes. ; UKY_READ: - HB_DI CALL _usb_kyb_buf_get_next - HB_EI LD A, H OR A JR NZ, UKY_READ