From 601ddee38b04238c64a675f365980f70f92a7cd4 Mon Sep 17 00:00:00 2001 From: Dean Netherton Date: Sun, 20 Oct 2024 12:18:26 +1100 Subject: [PATCH] usb-keyboard: working (limited) --- .vscode/settings.json | 3 +- Source/HBIOS/ch376-native/Makefile | 9 +- Source/HBIOS/ch376-native/base-drv.s | 1 + Source/HBIOS/ch376-native/base-drv/ch376.c.s | 357 ++++++++---------- .../HBIOS/ch376-native/base-drv/class_hid.c.s | 254 ------------- .../{print.c.s => critical-section.c.s} | 55 +-- .../ch376-native/base-drv/dev_transfers.c.s | 285 +++++++------- .../HBIOS/ch376-native/base-drv/enumerate.c.s | 285 +++++++------- .../ch376-native/base-drv/enumerate_hub.c.s | 110 +++--- .../HBIOS/ch376-native/base-drv/protocol.c.s | 172 +++++---- .../HBIOS/ch376-native/base-drv/transfers.c.s | 202 +++++----- .../HBIOS/ch376-native/base-drv/usb-init.c.s | 10 +- Source/HBIOS/ch376-native/cruntime.asm | 122 +++--- Source/HBIOS/ch376-native/keyboard.s | 1 + .../HBIOS/ch376-native/keyboard/class_hid.c.s | 43 +-- .../keyboard/class_hid_keyboard.c.s | 343 +++++++++++++++++ .../HBIOS/ch376-native/keyboard/kyb-init.c.s | 326 ++++++++++++++-- .../ch376-native/scsi-drv/class_scsi.c.s | 323 ++++++++-------- .../HBIOS/ch376-native/scsi-drv/scsi-init.c.s | 8 +- .../ch376-native/source-doc/base-drv/ch376.c | 27 +- .../ch376-native/source-doc/base-drv/ch376.h | 9 +- .../source-doc/base-drv/critical-section.c | 8 + .../source-doc/base-drv/critical-section.h | 13 + .../source-doc/base-drv/dev_transfers.c | 24 +- .../source-doc/base-drv/dev_transfers.h | 3 +- .../source-doc/base-drv/enumerate.c | 21 +- .../source-doc/base-drv/enumerate_hub.c | 2 + .../source-doc/base-drv/protocol.c | 17 +- .../source-doc/base-drv/transfers.c | 51 ++- .../ch376-native/source-doc/base-drv/z80.h | 11 - .../source-doc/convert-for-uz80as.sh | 3 +- .../HBIOS/ch376-native/source-doc/depends.d | 8 +- .../source-doc/keyboard/class_hid.c | 15 +- .../source-doc/keyboard/class_hid_keyboard.c | 343 +++++++++++++++++ .../source-doc/keyboard/kyb-init.c | 81 +++- .../source-doc/scsi-drv/class_scsi.c | 13 +- .../source-doc/scsi-drv/scsi-init.c | 1 - .../source-doc/ufi-drv/class_ufi.c | 18 +- .../ch376-native/source-doc/ufi-drv/usb_cbi.c | 21 +- .../HBIOS/ch376-native/ufi-drv/class_ufi.c.s | 160 ++++---- Source/HBIOS/ch376-native/ufi-drv/usb_cbi.c.s | 87 +++-- Source/HBIOS/ch376kyb.asm | 76 +++- Source/HBIOS/hbios.asm | 15 +- 43 files changed, 2397 insertions(+), 1539 deletions(-) delete mode 100644 Source/HBIOS/ch376-native/base-drv/class_hid.c.s rename Source/HBIOS/ch376-native/base-drv/{print.c.s => critical-section.c.s} (63%) create mode 100644 Source/HBIOS/ch376-native/keyboard/class_hid_keyboard.c.s create mode 100644 Source/HBIOS/ch376-native/source-doc/base-drv/critical-section.c create mode 100644 Source/HBIOS/ch376-native/source-doc/base-drv/critical-section.h create mode 100644 Source/HBIOS/ch376-native/source-doc/keyboard/class_hid_keyboard.c diff --git a/.vscode/settings.json b/.vscode/settings.json index 70be832d..e489b984 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,6 +17,7 @@ "class_scsi.h": "c", "z80.h": "c", "dev_transfers.h": "c", - "usb-base-drv.h": "c" + "usb-base-drv.h": "c", + "critical-section.h": "c" } } diff --git a/Source/HBIOS/ch376-native/Makefile b/Source/HBIOS/ch376-native/Makefile index 27dd21f7..6cb8f757 100644 --- a/Source/HBIOS/ch376-native/Makefile +++ b/Source/HBIOS/ch376-native/Makefile @@ -22,8 +22,13 @@ all: $(ASSDIR)base-drv.s $(ASSDIR)scsi-drv.s $(ASSDIR)ufi-drv.s $(ASSDIR)keyboar clean: @rm -rf base-drv - @rm -rf scsi-drv - @rm -rf ufi-drv + rm -rf scsi-drv + rm -rf ufi-drv + rm -rf keyboard + rm ufi-drv.s + rm scsi-drv.s + rm base-drv.s + rm keyboard.s $(ASSDIR)base-drv.s: @echo "Creating base-drv.s" diff --git a/Source/HBIOS/ch376-native/base-drv.s b/Source/HBIOS/ch376-native/base-drv.s index 45005e37..cb623d53 100644 --- a/Source/HBIOS/ch376-native/base-drv.s +++ b/Source/HBIOS/ch376-native/base-drv.s @@ -1,5 +1,6 @@ ; Generated File -- not to be modify directly #include "ch376-native/base-drv/dev_transfers.c.s" +#include "ch376-native/base-drv/critical-section.c.s" #include "ch376-native/base-drv/enumerate.c.s" #include "ch376-native/base-drv/usb_state.c.s" #include "ch376-native/base-drv/class_hub.c.s" diff --git a/Source/HBIOS/ch376-native/base-drv/ch376.c.s b/Source/HBIOS/ch376-native/base-drv/ch376.c.s index 4ef2b7d7..8e731447 100644 --- a/Source/HBIOS/ch376-native/base-drv/ch376.c.s +++ b/Source/HBIOS/ch376-native/base-drv/ch376.c.s @@ -56,256 +56,232 @@ _result: ; --------------------------------- _ch_command: ;source-doc/base-drv/./ch376.c:10: while ((CH376_COMMAND_PORT & PARA_STATE_BUSY) && --counter != 0) - ld h,0xff + ld c,0xff l_ch_command_00102: ld a, +((_CH376_COMMAND_PORT) / 256) in a, (((_CH376_COMMAND_PORT) & 0xFF)) bit 4, a jr Z,l_ch_command_00104 - dec h - jr Z,l_ch_command_00104 -;source-doc/base-drv/./ch376.c:11: delay(); - push hl - call _delay - pop hl - jr l_ch_command_00102 + dec c + jr NZ,l_ch_command_00102 l_ch_command_00104: -;source-doc/base-drv/./ch376.c:21: delay(); - push hl - call _delay - pop hl -;source-doc/base-drv/./ch376.c:22: CH376_COMMAND_PORT = command; +;source-doc/base-drv/./ch376.c:21: CH376_COMMAND_PORT = command; ld a, l ld bc,_CH376_COMMAND_PORT out (c),a -;source-doc/base-drv/./ch376.c:23: delay(); - call _delay -;source-doc/base-drv/./ch376.c:24: delay(); - call _delay -;source-doc/base-drv/./ch376.c:25: delay(); - call _delay -;source-doc/base-drv/./ch376.c:26: delay(); -;source-doc/base-drv/./ch376.c:27: } - jp _delay -;source-doc/base-drv/./ch376.c:31: usb_error ch_long_wait_int_and_get_status(void) { return ch_wait_int_and_get_status(5000); } +;source-doc/base-drv/./ch376.c:22: } + ret +;source-doc/base-drv/./ch376.c:26: usb_error ch_long_wait_int_and_get_status(void) { return ch_wait_int_and_get_status(5000); } ; --------------------------------- ; Function ch_long_wait_int_and_get_status ; --------------------------------- _ch_long_wait_int_and_get_statu: ld hl,0x1388 jp _ch_wait_int_and_get_status -;source-doc/base-drv/./ch376.c:33: usb_error ch_short_wait_int_and_get_statu(void) { return ch_wait_int_and_get_status(100); } +;source-doc/base-drv/./ch376.c:28: usb_error ch_short_wait_int_and_get_statu(void) { return ch_wait_int_and_get_status(100); } ; --------------------------------- ; Function ch_short_wait_int_and_get_statu ; --------------------------------- _ch_short_wait_int_and_get_stat: ld hl,0x0064 jp _ch_wait_int_and_get_status -;source-doc/base-drv/./ch376.c:35: usb_error ch_very_short_wait_int_and_get_(void) { return ch_wait_int_and_get_status(10); } +;source-doc/base-drv/./ch376.c:30: usb_error ch_very_short_wait_int_and_get_(void) { return ch_wait_int_and_get_status(10); } ; --------------------------------- ; Function ch_very_short_wait_int_and_get_ ; --------------------------------- _ch_very_short_wait_int_and_get: ld hl,0x000a jp _ch_wait_int_and_get_status -;source-doc/base-drv/./ch376.c:37: usb_error ch_get_status(void) { +;source-doc/base-drv/./ch376.c:32: usb_error ch_get_status(void) { ; --------------------------------- ; Function ch_get_status ; --------------------------------- _ch_get_status: -;source-doc/base-drv/./ch376.c:38: ch_command(CH_CMD_GET_STATUS); +;source-doc/base-drv/./ch376.c:33: ch_command(CH_CMD_GET_STATUS); ld l,0x22 call _ch_command -;source-doc/base-drv/./ch376.c:39: delay(); - call _delay -;source-doc/base-drv/./ch376.c:40: delay(); - call _delay -;source-doc/base-drv/./ch376.c:41: delay(); - call _delay -;source-doc/base-drv/./ch376.c:42: delay(); - call _delay -;source-doc/base-drv/./ch376.c:43: uint8_t ch_status = CH376_DATA_PORT; +;source-doc/base-drv/./ch376.c:34: uint8_t ch_status = CH376_DATA_PORT; ld a, +((_CH376_DATA_PORT) / 256) in a, (((_CH376_DATA_PORT) & 0xFF)) -;source-doc/base-drv/./ch376.c:45: if (ch_status >= USB_FILERR_MIN && ch_status <= USB_FILERR_MAX) +;source-doc/base-drv/./ch376.c:36: if (ch_status >= USB_FILERR_MIN && ch_status <= USB_FILERR_MAX) ld l,a sub 0x41 jr C,l_ch_get_status_00102 ld a,0xb4 sub l -;source-doc/base-drv/./ch376.c:46: return ch_status; +;source-doc/base-drv/./ch376.c:37: return ch_status; jr NC,l_ch_get_status_00126 l_ch_get_status_00102: -;source-doc/base-drv/./ch376.c:48: if (ch_status == CH_CMD_RET_SUCCESS) +;source-doc/base-drv/./ch376.c:39: if (ch_status == CH_CMD_RET_SUCCESS) ld a, l -;source-doc/base-drv/./ch376.c:49: return USB_ERR_OK; +;source-doc/base-drv/./ch376.c:40: return USB_ERR_OK; sub 0x51 jr NZ,l_ch_get_status_00105 ld l,a jr l_ch_get_status_00126 l_ch_get_status_00105: -;source-doc/base-drv/./ch376.c:51: if (ch_status == CH_USB_INT_SUCCESS) +;source-doc/base-drv/./ch376.c:42: if (ch_status == CH_USB_INT_SUCCESS) ld a, l -;source-doc/base-drv/./ch376.c:52: return USB_ERR_OK; +;source-doc/base-drv/./ch376.c:43: return USB_ERR_OK; sub 0x14 jr NZ,l_ch_get_status_00107 ld l,a jr l_ch_get_status_00126 l_ch_get_status_00107: -;source-doc/base-drv/./ch376.c:54: if (ch_status == CH_USB_INT_CONNECT) +;source-doc/base-drv/./ch376.c:45: if (ch_status == CH_USB_INT_CONNECT) ld a, l sub 0x15 jr NZ,l_ch_get_status_00109 -;source-doc/base-drv/./ch376.c:55: return USB_INT_CONNECT; +;source-doc/base-drv/./ch376.c:46: return USB_INT_CONNECT; ld l,0x81 jr l_ch_get_status_00126 l_ch_get_status_00109: -;source-doc/base-drv/./ch376.c:57: if (ch_status == CH_USB_INT_DISK_READ) +;source-doc/base-drv/./ch376.c:48: if (ch_status == CH_USB_INT_DISK_READ) ld a, l sub 0x1d jr NZ,l_ch_get_status_00111 -;source-doc/base-drv/./ch376.c:58: return USB_ERR_DISK_READ; +;source-doc/base-drv/./ch376.c:49: return USB_ERR_DISK_READ; ld l,0x1d jr l_ch_get_status_00126 l_ch_get_status_00111: -;source-doc/base-drv/./ch376.c:60: if (ch_status == CH_USB_INT_DISK_WRITE) +;source-doc/base-drv/./ch376.c:51: if (ch_status == CH_USB_INT_DISK_WRITE) ld a, l sub 0x1e jr NZ,l_ch_get_status_00113 -;source-doc/base-drv/./ch376.c:61: return USB_ERR_DISK_WRITE; +;source-doc/base-drv/./ch376.c:52: return USB_ERR_DISK_WRITE; ld l,0x1e jr l_ch_get_status_00126 l_ch_get_status_00113: -;source-doc/base-drv/./ch376.c:63: if (ch_status == CH_USB_INT_DISCONNECT) { +;source-doc/base-drv/./ch376.c:54: if (ch_status == CH_USB_INT_DISCONNECT) { ld a, l sub 0x16 jr NZ,l_ch_get_status_00115 -;source-doc/base-drv/./ch376.c:64: ch_cmd_set_usb_mode(5); +;source-doc/base-drv/./ch376.c:55: ch_cmd_set_usb_mode(5); ld l,0x05 call _ch_cmd_set_usb_mode -;source-doc/base-drv/./ch376.c:65: return USB_ERR_NO_DEVICE; +;source-doc/base-drv/./ch376.c:56: return USB_ERR_NO_DEVICE; ld l,0x05 jr l_ch_get_status_00126 l_ch_get_status_00115: -;source-doc/base-drv/./ch376.c:68: if (ch_status == CH_USB_INT_BUF_OVER) +;source-doc/base-drv/./ch376.c:59: if (ch_status == CH_USB_INT_BUF_OVER) ld a, l sub 0x17 jr NZ,l_ch_get_status_00117 -;source-doc/base-drv/./ch376.c:69: return USB_ERR_DATA_ERROR; +;source-doc/base-drv/./ch376.c:60: return USB_ERR_DATA_ERROR; ld l,0x04 jr l_ch_get_status_00126 l_ch_get_status_00117: -;source-doc/base-drv/./ch376.c:71: ch_status &= 0x2F; +;source-doc/base-drv/./ch376.c:62: ch_status &= 0x2F; ld a, l and 0x2f -;source-doc/base-drv/./ch376.c:73: if (ch_status == 0x2A) +;source-doc/base-drv/./ch376.c:64: if (ch_status == 0x2A) cp 0x2a jr NZ,l_ch_get_status_00119 -;source-doc/base-drv/./ch376.c:74: return USB_ERR_NAK; +;source-doc/base-drv/./ch376.c:65: return USB_ERR_NAK; ld l,0x01 jr l_ch_get_status_00126 l_ch_get_status_00119: -;source-doc/base-drv/./ch376.c:76: if (ch_status == 0x2E) +;source-doc/base-drv/./ch376.c:67: if (ch_status == 0x2E) cp 0x2e jr NZ,l_ch_get_status_00121 -;source-doc/base-drv/./ch376.c:77: return USB_ERR_STALL; +;source-doc/base-drv/./ch376.c:68: return USB_ERR_STALL; ld l,0x02 jr l_ch_get_status_00126 l_ch_get_status_00121: -;source-doc/base-drv/./ch376.c:79: ch_status &= 0x23; +;source-doc/base-drv/./ch376.c:70: ch_status &= 0x23; and 0x23 -;source-doc/base-drv/./ch376.c:81: if (ch_status == 0x20) +;source-doc/base-drv/./ch376.c:72: if (ch_status == 0x20) cp 0x20 jr NZ,l_ch_get_status_00123 -;source-doc/base-drv/./ch376.c:82: return USB_ERR_TIMEOUT; +;source-doc/base-drv/./ch376.c:73: return USB_ERR_TIMEOUT; ld l,0x03 jr l_ch_get_status_00126 l_ch_get_status_00123: -;source-doc/base-drv/./ch376.c:84: if (ch_status == 0x23) +;source-doc/base-drv/./ch376.c:75: if (ch_status == 0x23) sub 0x23 jr NZ,l_ch_get_status_00125 -;source-doc/base-drv/./ch376.c:85: return USB_TOKEN_OUT_OF_SYNC; +;source-doc/base-drv/./ch376.c:76: return USB_TOKEN_OUT_OF_SYNC; ld l,0x07 jr l_ch_get_status_00126 l_ch_get_status_00125: -;source-doc/base-drv/./ch376.c:87: return USB_ERR_UNEXPECTED_STATUS_FROM_; +;source-doc/base-drv/./ch376.c:78: return USB_ERR_UNEXPECTED_STATUS_FROM_; ld l,0x08 l_ch_get_status_00126: -;source-doc/base-drv/./ch376.c:88: } +;source-doc/base-drv/./ch376.c:79: } ret -;source-doc/base-drv/./ch376.c:90: void ch_cmd_reset_all(void) { ch_command(CH_CMD_RESET_ALL); } +;source-doc/base-drv/./ch376.c:81: void ch_cmd_reset_all(void) { ch_command(CH_CMD_RESET_ALL); } ; --------------------------------- ; Function ch_cmd_reset_all ; --------------------------------- _ch_cmd_reset_all: ld l,0x05 jp _ch_command -;source-doc/base-drv/./ch376.c:109: uint8_t ch_probe(void) { +;source-doc/base-drv/./ch376.c:100: uint8_t ch_probe(void) { ; --------------------------------- ; Function ch_probe ; --------------------------------- _ch_probe: -;source-doc/base-drv/./ch376.c:111: do { +;source-doc/base-drv/./ch376.c:102: do { ld c,0x05 l_ch_probe_00103: -;source-doc/base-drv/./ch376.c:94: ch_command(CH_CMD_CHECK_EXIST); +;source-doc/base-drv/./ch376.c:85: ch_command(CH_CMD_CHECK_EXIST); push bc ld l,0x06 call _ch_command pop bc -;source-doc/base-drv/./ch376.c:95: CH376_DATA_PORT = (uint8_t)~0x55; +;source-doc/base-drv/./ch376.c:86: CH376_DATA_PORT = (uint8_t)~0x55; ld a,0xaa push bc ld bc,_CH376_DATA_PORT out (c),a call _delay pop bc -;source-doc/base-drv/./ch376.c:97: complement = CH376_DATA_PORT; +;source-doc/base-drv/./ch376.c:88: complement = CH376_DATA_PORT; ld a, +((_CH376_DATA_PORT) / 256) in a, (((_CH376_DATA_PORT) & 0xFF)) -;source-doc/base-drv/./ch376.c:98: return complement == 0x55; +;source-doc/base-drv/./ch376.c:89: return complement == 0x55; sub 0x55 jr NZ,l_ch_probe_00102 -;source-doc/base-drv/./ch376.c:112: if (ch_cmd_check_exist()) -;source-doc/base-drv/./ch376.c:113: return true; +;source-doc/base-drv/./ch376.c:103: if (ch_cmd_check_exist()) +;source-doc/base-drv/./ch376.c:104: return true; ld l,0x01 jr l_ch_probe_00107 l_ch_probe_00102: -;source-doc/base-drv/./ch376.c:115: delay_medium(); +;source-doc/base-drv/./ch376.c:106: delay_medium(); push bc call _delay_medium pop bc -;source-doc/base-drv/./ch376.c:116: } while (--i != 0); +;source-doc/base-drv/./ch376.c:107: } while (--i != 0); dec c jr NZ,l_ch_probe_00103 -;source-doc/base-drv/./ch376.c:118: return false; +;source-doc/base-drv/./ch376.c:109: return false; ld l,0x00 l_ch_probe_00107: -;source-doc/base-drv/./ch376.c:119: } +;source-doc/base-drv/./ch376.c:110: } ret -;source-doc/base-drv/./ch376.c:121: uint8_t ch_cmd_set_usb_mode(const uint8_t mode) __z88dk_fastcall { +;source-doc/base-drv/./ch376.c:112: uint8_t ch_cmd_set_usb_mode(const uint8_t mode) __z88dk_fastcall { ; --------------------------------- ; Function ch_cmd_set_usb_mode ; --------------------------------- _ch_cmd_set_usb_mode: ld c, l -;source-doc/base-drv/./ch376.c:122: uint8_t result = 0; +;source-doc/base-drv/./ch376.c:113: uint8_t result = 0; ld b,0x00 -;source-doc/base-drv/./ch376.c:124: CH376_COMMAND_PORT = CH_CMD_SET_USB_MODE; +;source-doc/base-drv/./ch376.c:115: CH376_COMMAND_PORT = CH_CMD_SET_USB_MODE; ld a,0x15 push bc ld bc,_CH376_COMMAND_PORT out (c),a call _delay pop bc -;source-doc/base-drv/./ch376.c:126: CH376_DATA_PORT = mode; +;source-doc/base-drv/./ch376.c:117: CH376_DATA_PORT = mode; ld a, c push bc ld bc,_CH376_DATA_PORT out (c),a call _delay pop bc -;source-doc/base-drv/./ch376.c:131: while (result != CH_CMD_RET_SUCCESS && result != CH_CMD_RET_ABORT && --count != 0) { +;source-doc/base-drv/./ch376.c:122: while (result != CH_CMD_RET_SUCCESS && result != CH_CMD_RET_ABORT && --count != 0) { ld c,0x7f l_ch_cmd_set_usb_mode_00103: ld a, b @@ -324,17 +300,17 @@ l_ch_cmd_set_usb_mode_00147: jr Z,l_ch_cmd_set_usb_mode_00105 dec c jr Z,l_ch_cmd_set_usb_mode_00105 -;source-doc/base-drv/./ch376.c:132: result = CH376_DATA_PORT; +;source-doc/base-drv/./ch376.c:123: result = CH376_DATA_PORT; ld a, +((_CH376_DATA_PORT) / 256) in a, (((_CH376_DATA_PORT) & 0xFF)) ld b, a -;source-doc/base-drv/./ch376.c:133: delay(); +;source-doc/base-drv/./ch376.c:124: delay(); push bc call _delay pop bc jr l_ch_cmd_set_usb_mode_00103 l_ch_cmd_set_usb_mode_00105: -;source-doc/base-drv/./ch376.c:136: return (result == CH_CMD_RET_SUCCESS) ? USB_ERR_OK : USB_ERR_FAIL; +;source-doc/base-drv/./ch376.c:127: return (result == CH_CMD_RET_SUCCESS) ? USB_ERR_OK : USB_ERR_FAIL; ld a, e or a jr Z,l_ch_cmd_set_usb_mode_00108 @@ -343,24 +319,24 @@ l_ch_cmd_set_usb_mode_00105: l_ch_cmd_set_usb_mode_00108: ld l,0x0e l_ch_cmd_set_usb_mode_00109: -;source-doc/base-drv/./ch376.c:137: } +;source-doc/base-drv/./ch376.c:128: } ret -;source-doc/base-drv/./ch376.c:139: uint8_t ch_cmd_get_ic_version(void) { +;source-doc/base-drv/./ch376.c:130: uint8_t ch_cmd_get_ic_version(void) { ; --------------------------------- ; Function ch_cmd_get_ic_version ; --------------------------------- _ch_cmd_get_ic_version: -;source-doc/base-drv/./ch376.c:140: ch_command(CH_CMD_GET_IC_VER); +;source-doc/base-drv/./ch376.c:131: ch_command(CH_CMD_GET_IC_VER); ld l,0x01 call _ch_command -;source-doc/base-drv/./ch376.c:141: return CH376_DATA_PORT & 0x1f; +;source-doc/base-drv/./ch376.c:132: return CH376_DATA_PORT & 0x1f; ld a, +((_CH376_DATA_PORT) / 256) in a, (((_CH376_DATA_PORT) & 0xFF)) and 0x1f ld l, a -;source-doc/base-drv/./ch376.c:142: } +;source-doc/base-drv/./ch376.c:133: } ret -;source-doc/base-drv/./ch376.c:144: void ch_issue_token(const uint8_t toggle_bit, const uint8_t endpoint, const ch376_pid pid) { +;source-doc/base-drv/./ch376.c:135: void ch_issue_token(const uint8_t toggle_bit, const uint8_t endpoint, const ch376_pid pid) { ; --------------------------------- ; Function ch_issue_token ; --------------------------------- @@ -368,22 +344,14 @@ _ch_issue_token: push ix ld ix,0 add ix,sp -;source-doc/base-drv/./ch376.c:145: ch_command(CH_CMD_ISSUE_TKN_X); +;source-doc/base-drv/./ch376.c:136: ch_command(CH_CMD_ISSUE_TKN_X); ld l,0x4e call _ch_command -;source-doc/base-drv/./ch376.c:146: delay(); - call _delay -;source-doc/base-drv/./ch376.c:147: delay(); - call _delay -;source-doc/base-drv/./ch376.c:148: CH376_DATA_PORT = toggle_bit; +;source-doc/base-drv/./ch376.c:137: CH376_DATA_PORT = toggle_bit; ld a,(ix+4) ld bc,_CH376_DATA_PORT out (c),a -;source-doc/base-drv/./ch376.c:149: delay(); - call _delay -;source-doc/base-drv/./ch376.c:150: delay(); - call _delay -;source-doc/base-drv/./ch376.c:151: CH376_DATA_PORT = endpoint << 4 | pid; +;source-doc/base-drv/./ch376.c:138: CH376_DATA_PORT = endpoint << 4 | pid; ld a,(ix+5) add a, a add a, a @@ -392,19 +360,16 @@ _ch_issue_token: or (ix+6) ld bc,_CH376_DATA_PORT out (c),a -;source-doc/base-drv/./ch376.c:152: delay(); - call _delay -;source-doc/base-drv/./ch376.c:153: delay(); -;source-doc/base-drv/./ch376.c:154: } +;source-doc/base-drv/./ch376.c:139: } pop ix - jp _delay -;source-doc/base-drv/./ch376.c:156: void ch_issue_token_in(const endpoint_param *const endpoint) __z88dk_fastcall { + ret +;source-doc/base-drv/./ch376.c:141: void ch_issue_token_in(const endpoint_param *const endpoint) __z88dk_fastcall { ; --------------------------------- ; Function ch_issue_token_in ; --------------------------------- _ch_issue_token_in: ex de, hl -;source-doc/base-drv/./ch376.c:157: ch_issue_token(endpoint->toggle ? 0x80 : 0x00, endpoint->number, CH_PID_IN); +;source-doc/base-drv/./ch376.c:142: ch_issue_token(endpoint->toggle ? 0x80 : 0x00, endpoint->number, CH_PID_IN); ld l, e ld h, d ld a, (hl) @@ -430,15 +395,15 @@ l_ch_issue_token_in_00104: call _ch_issue_token pop af inc sp -;source-doc/base-drv/./ch376.c:158: } +;source-doc/base-drv/./ch376.c:143: } ret -;source-doc/base-drv/./ch376.c:160: void ch_issue_token_out(const endpoint_param *const endpoint) __z88dk_fastcall { +;source-doc/base-drv/./ch376.c:145: void ch_issue_token_out(const endpoint_param *const endpoint) __z88dk_fastcall { ; --------------------------------- ; Function ch_issue_token_out ; --------------------------------- _ch_issue_token_out: ex de, hl -;source-doc/base-drv/./ch376.c:161: ch_issue_token(endpoint->toggle ? 0x40 : 0x00, endpoint->number, CH_PID_OUT); +;source-doc/base-drv/./ch376.c:146: ch_issue_token(endpoint->toggle ? 0x40 : 0x00, endpoint->number, CH_PID_OUT); ld l, e ld h, d ld a, (hl) @@ -464,9 +429,9 @@ l_ch_issue_token_out_00104: call _ch_issue_token pop af inc sp -;source-doc/base-drv/./ch376.c:162: } +;source-doc/base-drv/./ch376.c:147: } ret -;source-doc/base-drv/./ch376.c:164: void ch_issue_token_out_ep0(void) { ch_issue_token(0x40, 0, CH_PID_OUT); } +;source-doc/base-drv/./ch376.c:149: void ch_issue_token_out_ep0(void) { ch_issue_token(0x40, 0, CH_PID_OUT); } ; --------------------------------- ; Function ch_issue_token_out_ep0 ; --------------------------------- @@ -482,7 +447,7 @@ _ch_issue_token_out_ep0: pop af inc sp ret -;source-doc/base-drv/./ch376.c:166: void ch_issue_token_in_ep0(void) { ch_issue_token(0x80, 0, CH_PID_IN); } +;source-doc/base-drv/./ch376.c:151: void ch_issue_token_in_ep0(void) { ch_issue_token(0x80, 0, CH_PID_IN); } ; --------------------------------- ; Function ch_issue_token_in_ep0 ; --------------------------------- @@ -498,7 +463,7 @@ _ch_issue_token_in_ep0: pop af inc sp ret -;source-doc/base-drv/./ch376.c:168: void ch_issue_token_setup(void) { ch_issue_token(0, 0, CH_PID_SETUP); } +;source-doc/base-drv/./ch376.c:153: void ch_issue_token_setup(void) { ch_issue_token(0, 0, CH_PID_SETUP); } ; --------------------------------- ; Function ch_issue_token_setup ; --------------------------------- @@ -516,7 +481,7 @@ _ch_issue_token_setup: pop af inc sp ret -;source-doc/base-drv/./ch376.c:170: usb_error ch_data_in_transfer(uint8_t *buffer, int16_t buffer_size, endpoint_param *const endpoint) { +;source-doc/base-drv/./ch376.c:155: usb_error ch_data_in_transfer(uint8_t *buffer, int16_t buffer_size, endpoint_param *const endpoint) { ; --------------------------------- ; Function ch_data_in_transfer ; --------------------------------- @@ -525,38 +490,39 @@ _ch_data_in_transfer: ld ix,0 add ix,sp push af -;source-doc/base-drv/./ch376.c:174: if (buffer_size == 0) +;source-doc/base-drv/./ch376.c:158: if (buffer_size == 0) ld a,(ix+7) or (ix+6) jr NZ,l_ch_data_in_transfer_00102 -;source-doc/base-drv/./ch376.c:175: return USB_ERR_OK; +;source-doc/base-drv/./ch376.c:159: return USB_ERR_OK; ld l,0x00 - jp l_ch_data_in_transfer_00110 + jp l_ch_data_in_transfer_00111 l_ch_data_in_transfer_00102: -;source-doc/base-drv/./ch376.c:177: USB_MODULE_LEDS = 0x01; +;source-doc/base-drv/./ch376.c:161: USB_MODULE_LEDS = 0x01; ld a,0x01 ld bc,_USB_MODULE_LEDS out (c),a -;source-doc/base-drv/./ch376.c:178: do { +;source-doc/base-drv/./ch376.c:162: do { ld c,(ix+8) ld b,(ix+9) inc sp inc sp push bc l_ch_data_in_transfer_00107: -;source-doc/base-drv/./ch376.c:179: ch_issue_token_in(endpoint); +;source-doc/base-drv/./ch376.c:163: ch_issue_token_in(endpoint); push bc ld l, c ld h, b call _ch_issue_token_in call _ch_long_wait_int_and_get_statu - ld a, l pop bc - ld l, a -;source-doc/base-drv/./ch376.c:182: CHECK(result); + ld a, l + ld (_result), a +;source-doc/base-drv/./ch376.c:166: CHECK(result); + ld a,(_result) or a jr NZ,l_ch_data_in_transfer_00110 -;source-doc/base-drv/./ch376.c:184: endpoint->toggle = !endpoint->toggle; +;source-doc/base-drv/./ch376.c:168: endpoint->toggle = !endpoint->toggle; ld e, c ld d, b pop hl @@ -570,32 +536,32 @@ l_ch_data_in_transfer_00107: and 0xfe or l ld (de), a -;source-doc/base-drv/./ch376.c:186: count = ch_read_data(buffer); +;source-doc/base-drv/./ch376.c:170: count = ch_read_data(buffer); push bc ld l,(ix+4) ld h,(ix+5) call _ch_read_data ld e, a pop bc -;source-doc/base-drv/./ch376.c:188: if (count == 0) { +;source-doc/base-drv/./ch376.c:172: if (count == 0) { ld a, e -;source-doc/base-drv/./ch376.c:189: USB_MODULE_LEDS = 0x00; +;source-doc/base-drv/./ch376.c:173: USB_MODULE_LEDS = 0x00; or a jr NZ,l_ch_data_in_transfer_00106 ld bc,_USB_MODULE_LEDS out (c),a -;source-doc/base-drv/./ch376.c:190: return USB_ERR_DATA_ERROR; +;source-doc/base-drv/./ch376.c:174: return USB_ERR_DATA_ERROR; ld l,0x04 - jr l_ch_data_in_transfer_00110 + jr l_ch_data_in_transfer_00111 l_ch_data_in_transfer_00106: -;source-doc/base-drv/./ch376.c:193: buffer += count; +;source-doc/base-drv/./ch376.c:177: buffer += count; ld a,(ix+4) add a, e ld (ix+4),a - jr NC,l_ch_data_in_transfer_00147 + jr NC,l_ch_data_in_transfer_00148 inc (ix+5) -l_ch_data_in_transfer_00147: -;source-doc/base-drv/./ch376.c:194: buffer_size -= count; +l_ch_data_in_transfer_00148: +;source-doc/base-drv/./ch376.c:178: buffer_size -= count; ld d,0x00 ld a,(ix+6) sub e @@ -603,26 +569,32 @@ l_ch_data_in_transfer_00147: ld a,(ix+7) sbc a, d ld (ix+7),a -;source-doc/base-drv/./ch376.c:195: } while (buffer_size > 0); +;source-doc/base-drv/./ch376.c:179: } while (buffer_size > 0); xor a cp (ix+6) sbc a,(ix+7) - jp PO, l_ch_data_in_transfer_00148 + jp PO, l_ch_data_in_transfer_00149 xor 0x80 -l_ch_data_in_transfer_00148: +l_ch_data_in_transfer_00149: jp M, l_ch_data_in_transfer_00107 -;source-doc/base-drv/./ch376.c:197: USB_MODULE_LEDS = 0x00; +;source-doc/base-drv/./ch376.c:181: USB_MODULE_LEDS = 0x00; ld a,0x00 ld bc,_USB_MODULE_LEDS out (c),a -;source-doc/base-drv/./ch376.c:199: return USB_ERR_OK; +;source-doc/base-drv/./ch376.c:183: return USB_ERR_OK; ld l,0x00 + jr l_ch_data_in_transfer_00111 +;source-doc/base-drv/./ch376.c:184: done: l_ch_data_in_transfer_00110: -;source-doc/base-drv/./ch376.c:200: } +;source-doc/base-drv/./ch376.c:185: return result; + ld hl,_result + ld l, (hl) +l_ch_data_in_transfer_00111: +;source-doc/base-drv/./ch376.c:186: } ld sp, ix pop ix ret -;source-doc/base-drv/./ch376.c:202: usb_error ch_data_in_transfer_n(uint8_t *const buffer, int8_t *const buffer_size, endpoint_param *const endpoint) { +;source-doc/base-drv/./ch376.c:188: usb_error ch_data_in_transfer_n(uint8_t *const buffer, int8_t *const buffer_size, endpoint_param *const endpoint) { ; --------------------------------- ; Function ch_data_in_transfer_n ; --------------------------------- @@ -630,20 +602,21 @@ _ch_data_in_transfer_n: push ix ld ix,0 add ix,sp -;source-doc/base-drv/./ch376.c:206: USB_MODULE_LEDS = 0x01; +;source-doc/base-drv/./ch376.c:192: USB_MODULE_LEDS = 0x01; ld a,0x01 ld bc,_USB_MODULE_LEDS out (c),a -;source-doc/base-drv/./ch376.c:208: ch_issue_token_in(endpoint); +;source-doc/base-drv/./ch376.c:194: ch_issue_token_in(endpoint); ld l,(ix+8) ld h,(ix+9) call _ch_issue_token_in -;source-doc/base-drv/./ch376.c:210: CHECK(ch_long_wait_int_and_get_status()); +;source-doc/base-drv/./ch376.c:196: CHECK(ch_long_wait_int_and_get_status()); call _ch_long_wait_int_and_get_statu - ld a,l + ld a, l + ld b,a or a jr NZ,l_ch_data_in_transfer_n_00103 -;source-doc/base-drv/./ch376.c:212: endpoint->toggle = !endpoint->toggle; +;source-doc/base-drv/./ch376.c:198: endpoint->toggle = !endpoint->toggle; ld e,(ix+8) ld d,(ix+9) ld c, e @@ -658,25 +631,30 @@ _ch_data_in_transfer_n: and 0xfe or e ld (bc), a -;source-doc/base-drv/./ch376.c:214: count = ch_read_data(buffer); +;source-doc/base-drv/./ch376.c:200: count = ch_read_data(buffer); ld l,(ix+4) ld h,(ix+5) call _ch_read_data -;source-doc/base-drv/./ch376.c:216: *buffer_size = count; +;source-doc/base-drv/./ch376.c:202: *buffer_size = count; ld c,(ix+6) ld b,(ix+7) ld (bc), a -;source-doc/base-drv/./ch376.c:218: USB_MODULE_LEDS = 0x00; +;source-doc/base-drv/./ch376.c:204: USB_MODULE_LEDS = 0x00; ld a,0x00 ld bc,_USB_MODULE_LEDS out (c),a -;source-doc/base-drv/./ch376.c:220: return USB_ERR_OK; +;source-doc/base-drv/./ch376.c:206: return USB_ERR_OK; ld l,0x00 + jr l_ch_data_in_transfer_n_00104 +;source-doc/base-drv/./ch376.c:207: done: l_ch_data_in_transfer_n_00103: -;source-doc/base-drv/./ch376.c:221: } +;source-doc/base-drv/./ch376.c:208: return result; + ld l, b +l_ch_data_in_transfer_n_00104: +;source-doc/base-drv/./ch376.c:209: } pop ix ret -;source-doc/base-drv/./ch376.c:223: usb_error ch_data_out_transfer(const uint8_t *buffer, int16_t buffer_length, endpoint_param *const endpoint) { +;source-doc/base-drv/./ch376.c:211: usb_error ch_data_out_transfer(const uint8_t *buffer, int16_t buffer_length, endpoint_param *const endpoint) { ; --------------------------------- ; Function ch_data_out_transfer ; --------------------------------- @@ -686,7 +664,7 @@ _ch_data_out_transfer: add ix,sp push af dec sp -;source-doc/base-drv/./ch376.c:226: const uint8_t max_packet_size = calc_max_packet_size(endpoint->max_packet_sizex); +;source-doc/base-drv/./ch376.c:214: const uint8_t max_packet_size = calc_max_packet_size(endpoint->max_packet_sizex); ld c,(ix+8) ld b,(ix+9) ld e, c @@ -694,44 +672,42 @@ _ch_data_out_transfer: inc de ld a, (de) ld (ix-3),a -;source-doc/base-drv/./ch376.c:228: USB_MODULE_LEDS = 0x02; +;source-doc/base-drv/./ch376.c:216: USB_MODULE_LEDS = 0x02; ld a,0x02 push bc ld bc,_USB_MODULE_LEDS out (c),a pop bc -;source-doc/base-drv/./ch376.c:230: while (buffer_length > 0) { +;source-doc/base-drv/./ch376.c:218: while (buffer_length > 0) { ld (ix-2),c ld (ix-1),b l_ch_data_out_transfer_00103: xor a cp (ix+6) sbc a,(ix+7) - jp PO, l_ch_data_out_transfer_00138 + jp PO, l_ch_data_out_transfer_00139 xor 0x80 -l_ch_data_out_transfer_00138: +l_ch_data_out_transfer_00139: jp P, l_ch_data_out_transfer_00105 -;source-doc/base-drv/./ch376.c:231: const uint8_t size = max_packet_size < buffer_length ? max_packet_size : buffer_length; - ld e,(ix-3) - ld d,0x00 - ld a, e - sub (ix+6) +;source-doc/base-drv/./ch376.c:219: const uint8_t size = max_packet_size < buffer_length ? max_packet_size : buffer_length; + ld d,(ix-3) + ld e,0x00 ld a, d + sub (ix+6) + ld a, e sbc a,(ix+7) - jp PO, l_ch_data_out_transfer_00139 + jp PO, l_ch_data_out_transfer_00140 xor 0x80 -l_ch_data_out_transfer_00139: - jp P, l_ch_data_out_transfer_00108 - jr l_ch_data_out_transfer_00109 -l_ch_data_out_transfer_00108: - ld e,(ix+6) - ld d,(ix+7) +l_ch_data_out_transfer_00140: + jp P, l_ch_data_out_transfer_00109 + jr l_ch_data_out_transfer_00110 l_ch_data_out_transfer_00109: -;source-doc/base-drv/./ch376.c:232: buffer = ch_write_data(buffer, size); + ld d,(ix+6) +l_ch_data_out_transfer_00110: +;source-doc/base-drv/./ch376.c:220: buffer = ch_write_data(buffer, size); push bc push de - ld a, e - push af + push de inc sp ld l,(ix+4) ld h,(ix+5) @@ -743,15 +719,15 @@ l_ch_data_out_transfer_00109: pop bc ld (ix+4),l ld (ix+5),h -;source-doc/base-drv/./ch376.c:233: buffer_length -= size; - ld d,0x00 +;source-doc/base-drv/./ch376.c:221: buffer_length -= size; + ld e,0x00 ld a,(ix+6) - sub e + sub d ld (ix+6),a ld a,(ix+7) - sbc a, d + sbc a, e ld (ix+7),a -;source-doc/base-drv/./ch376.c:234: ch_issue_token_out(endpoint); +;source-doc/base-drv/./ch376.c:222: ch_issue_token_out(endpoint); push bc ld l, c ld h, b @@ -762,7 +738,7 @@ l_ch_data_out_transfer_00109: ld l, a or a jr NZ,l_ch_data_out_transfer_00106 -;source-doc/base-drv/./ch376.c:238: endpoint->toggle = !endpoint->toggle; +;source-doc/base-drv/./ch376.c:226: endpoint->toggle = !endpoint->toggle; ld e, c ld d, b ld l,(ix-2) @@ -778,33 +754,34 @@ l_ch_data_out_transfer_00109: ld (de), a jr l_ch_data_out_transfer_00103 l_ch_data_out_transfer_00105: -;source-doc/base-drv/./ch376.c:241: USB_MODULE_LEDS = 0x00; +;source-doc/base-drv/./ch376.c:229: USB_MODULE_LEDS = 0x00; ld a,0x00 ld bc,_USB_MODULE_LEDS out (c),a -;source-doc/base-drv/./ch376.c:243: return USB_ERR_OK; +;source-doc/base-drv/./ch376.c:231: return USB_ERR_OK; ld l,0x00 +;source-doc/base-drv/./ch376.c:232: done: +;source-doc/base-drv/./ch376.c:233: return result; l_ch_data_out_transfer_00106: -;source-doc/base-drv/./ch376.c:244: } +;source-doc/base-drv/./ch376.c:234: } ld sp, ix pop ix ret -;source-doc/base-drv/./ch376.c:246: void ch_set_usb_address(const uint8_t device_address) __z88dk_fastcall { +;source-doc/base-drv/./ch376.c:236: void ch_set_usb_address(const uint8_t device_address) __z88dk_fastcall { ; --------------------------------- ; Function ch_set_usb_address ; --------------------------------- _ch_set_usb_address: -;source-doc/base-drv/./ch376.c:247: ch_command(CH_CMD_SET_USB_ADDR); +;source-doc/base-drv/./ch376.c:237: ch_command(CH_CMD_SET_USB_ADDR); push hl ld l,0x13 call _ch_command pop hl -;source-doc/base-drv/./ch376.c:248: CH376_DATA_PORT = device_address; +;source-doc/base-drv/./ch376.c:238: CH376_DATA_PORT = device_address; ld a, l ld bc,_CH376_DATA_PORT out (c),a -;source-doc/base-drv/./ch376.c:249: delay(); -;source-doc/base-drv/./ch376.c:250: } - jp _delay +;source-doc/base-drv/./ch376.c:239: } + ret _result: DEFB +0x00 diff --git a/Source/HBIOS/ch376-native/base-drv/class_hid.c.s b/Source/HBIOS/ch376-native/base-drv/class_hid.c.s deleted file mode 100644 index 6d750eec..00000000 --- a/Source/HBIOS/ch376-native/base-drv/class_hid.c.s +++ /dev/null @@ -1,254 +0,0 @@ -; -; Generated from source-doc/base-drv/./class_hid.c.asm -- not to be modify directly -; -; -;-------------------------------------------------------- -; File Created by SDCC : free open source ISO C Compiler -; Version 4.4.0 #14648 (Linux) -;-------------------------------------------------------- -; Processed by Z88DK -;-------------------------------------------------------- - - -;-------------------------------------------------------- -; Public variables in this module -;-------------------------------------------------------- -;-------------------------------------------------------- -; Externals used -;-------------------------------------------------------- -;-------------------------------------------------------- -; special function registers -;-------------------------------------------------------- -_CH376_DATA_PORT .EQU 0xff88 -_CH376_COMMAND_PORT .EQU 0xff89 -_USB_MODULE_LEDS .EQU 0xff8a -;-------------------------------------------------------- -; ram data -;-------------------------------------------------------- -;-------------------------------------------------------- -; ram data -;-------------------------------------------------------- - -#IF 0 - -; .area _INITIALIZED removed by z88dk - - -#ENDIF - -;-------------------------------------------------------- -; absolute external ram data -;-------------------------------------------------------- -;-------------------------------------------------------- -; global & static initialisations -;-------------------------------------------------------- -;-------------------------------------------------------- -; Home -;-------------------------------------------------------- -;-------------------------------------------------------- -; code -;-------------------------------------------------------- -;source-doc/base-drv/./class_hid.c:6: usb_error hid_set_protocol(const device_config_keyboard *const dev, const uint8_t protocol) __sdcccall(1) { -; --------------------------------- -; Function hid_set_protocol -; --------------------------------- -_hid_set_protocol: - push ix - ld ix,0 - add ix,sp - push af - push af - push af - push af - ex de, hl -;source-doc/base-drv/./class_hid.c:9: cmd = cmd_hid_set; - push de - ex de, hl - ld hl,2 - add hl, sp - ex de, hl - ld hl,_cmd_hid_set - ld bc,0x0008 - ldir - pop de -;source-doc/base-drv/./class_hid.c:11: cmd.bRequest = HID_SET_PROTOCOL; - ld (ix-7),0x0b -;source-doc/base-drv/./class_hid.c:12: cmd.bValue[0] = protocol; - ld a,(ix+4) - ld (ix-6),a -;source-doc/base-drv/./class_hid.c:14: result = usb_control_transfer(&cmd, NULL, dev->address, dev->max_packet_size); - ld l, e - ld h, d - inc hl - ld c, (hl) - ex de, hl - ld a, (hl) - rlca - rlca - rlca - rlca - and 0x0f - ld h, c - push hl - inc sp - push af - inc sp - ld hl,0x0000 - push hl - ld hl,4 - add hl, sp - push hl - call _usb_control_transfer - pop af - pop af - pop af - ld a, l -;source-doc/base-drv/./class_hid.c:16: RETURN_CHECK(result); -;source-doc/base-drv/./class_hid.c:17: } - ld sp, ix - pop ix - pop hl - inc sp - jp (hl) -_cmd_hid_set: - DEFB +0x21 - DEFB +0x0b - DEFB +0x00 - DEFB +0x00 - DEFB +0x00 - DEFB +0x00 - DEFW +0x0000 -;source-doc/base-drv/./class_hid.c:19: usb_error hid_set_idle(const device_config_keyboard *const dev, const uint8_t duration) __sdcccall(1) { -; --------------------------------- -; Function hid_set_idle -; --------------------------------- -_hid_set_idle: - push ix - ld ix,0 - add ix,sp - push af - push af - push af - push af - ex de, hl -;source-doc/base-drv/./class_hid.c:22: cmd = cmd_hid_set; - push de - ex de, hl - ld hl,2 - add hl, sp - ex de, hl - ld hl,_cmd_hid_set - ld bc,0x0008 - ldir - pop de -;source-doc/base-drv/./class_hid.c:24: cmd.bRequest = HID_SET_IDLE; - ld (ix-7),0x0a -;source-doc/base-drv/./class_hid.c:25: cmd.bValue[0] = duration; - ld a,(ix+4) - ld (ix-6),a -;source-doc/base-drv/./class_hid.c:27: result = usb_control_transfer(&cmd, NULL, dev->address, dev->max_packet_size); - ld l, e - ld h, d - inc hl - ld c, (hl) - ex de, hl - ld a, (hl) - rlca - rlca - rlca - rlca - and 0x0f - ld h, c - push hl - inc sp - push af - inc sp - ld hl,0x0000 - push hl - ld hl,4 - add hl, sp - push hl - call _usb_control_transfer - pop af - pop af - pop af - ld a, l -;source-doc/base-drv/./class_hid.c:29: RETURN_CHECK(result); -;source-doc/base-drv/./class_hid.c:30: } - ld sp, ix - pop ix - pop hl - inc sp - jp (hl) -;source-doc/base-drv/./class_hid.c:32: usb_error hid_get_input_report(const device_config_keyboard *const dev, uint8_t const *report) __sdcccall(1) { -; --------------------------------- -; Function hid_get_input_report -; --------------------------------- -_hid_get_input_report: - push ix - ld ix,0 - add ix,sp - ld c, l - ld b, h - ld hl, -9 - add hl, sp - ld sp, hl - ld l, c - ld h, b -;source-doc/base-drv/./class_hid.c:35: cmd = cmd_hid_set; - push de - push hl - ex de, hl - ld hl,4 - add hl, sp - ex de, hl - ld hl,_cmd_hid_set - ld bc,0x0008 - ldir - pop bc - pop de -;source-doc/base-drv/./class_hid.c:37: cmd.bmRequestType = 0xA1; - ld (ix-9),0xa1 -;source-doc/base-drv/./class_hid.c:38: cmd.bValue[0] = 1; - ld (ix-7),0x01 -;source-doc/base-drv/./class_hid.c:39: cmd.bValue[1] = 1; - ld (ix-6),0x01 -;source-doc/base-drv/./class_hid.c:40: cmd.bRequest = HID_GET_REPORT; - ld (ix-8),0x01 -;source-doc/base-drv/./class_hid.c:41: cmd.wLength = 8; - ld (ix-3),0x08 - xor a - ld (ix-2),a -;source-doc/base-drv/./class_hid.c:43: result = usb_control_transfer(&cmd, report, dev->address, dev->max_packet_size); - ld l, c - ld h, b - inc hl - ld a, (hl) - ld (ix-1),a - ld l, c - ld h, b - ld a, (hl) - rlca - rlca - rlca - rlca - and 0x0f - ld h,(ix-1) - push hl - inc sp - push af - inc sp - push de - ld hl,4 - add hl, sp - push hl - call _usb_control_transfer - pop af - pop af - pop af - ld a, l -;source-doc/base-drv/./class_hid.c:45: RETURN_CHECK(result); -;source-doc/base-drv/./class_hid.c:46: } - ld sp, ix - pop ix - ret diff --git a/Source/HBIOS/ch376-native/base-drv/print.c.s b/Source/HBIOS/ch376-native/base-drv/critical-section.c.s similarity index 63% rename from Source/HBIOS/ch376-native/base-drv/print.c.s rename to Source/HBIOS/ch376-native/base-drv/critical-section.c.s index 12d60c89..97ea4e02 100644 --- a/Source/HBIOS/ch376-native/base-drv/print.c.s +++ b/Source/HBIOS/ch376-native/base-drv/critical-section.c.s @@ -1,5 +1,5 @@ ; -; Generated from source-doc/base-drv/./print.c.asm -- not to be modify directly +; Generated from source-doc/base-drv/./critical-section.c.asm -- not to be modify directly ; ; ;-------------------------------------------------------- @@ -30,6 +30,8 @@ ; .area _INITIALIZED removed by z88dk +_in_critical_usb_section: + DEFS 1 #ENDIF @@ -45,42 +47,21 @@ ;-------------------------------------------------------- ; code ;-------------------------------------------------------- -;source-doc/base-drv/./print.c:3: void print_device_mounted(const char *const description, const uint8_t count) { +;source-doc/base-drv/./critical-section.c:6: void critical_begin() { in_critical_usb_section++; } ; --------------------------------- -; Function print_device_mounted +; Function critical_begin ; --------------------------------- -_print_device_mounted: - push ix - ld ix,0 - add ix,sp -;source-doc/base-drv/./print.c:4: print_string("\r\n $"); - ld hl,print_str_0 - call _print_string -;source-doc/base-drv/./print.c:5: print_uint16(count); - ld e,(ix+6) - ld d,0x00 - ex de, hl - call _print_uint16 -;source-doc/base-drv/./print.c:6: print_string(description); - ld l,(ix+4) - ld h,(ix+5) - call _print_string -;source-doc/base-drv/./print.c:7: if (count > 1) - ld a,0x01 - sub (ix+6) - jr NC,l_print_device_mounted_00103 -;source-doc/base-drv/./print.c:8: print_string("S$"); - ld hl,print_str_1 - call _print_string -l_print_device_mounted_00103: -;source-doc/base-drv/./print.c:9: } - pop ix +_critical_begin: + ld hl,_in_critical_usb_section + inc (hl) ret -print_str_0: - DEFB 0x0d - DEFB 0x0a - DEFM " $" - DEFB 0x00 -print_str_1: - DEFM "S$" - DEFB 0x00 +;source-doc/base-drv/./critical-section.c:8: void critical_end() { in_critical_usb_section--; } +; --------------------------------- +; Function critical_end +; --------------------------------- +_critical_end: + ld hl,_in_critical_usb_section + dec (hl) + ret +_in_critical_usb_section: + DEFB +0x00 diff --git a/Source/HBIOS/ch376-native/base-drv/dev_transfers.c.s b/Source/HBIOS/ch376-native/base-drv/dev_transfers.c.s index 962ed8e1..2412ace0 100644 --- a/Source/HBIOS/ch376-native/base-drv/dev_transfers.c.s +++ b/Source/HBIOS/ch376-native/base-drv/dev_transfers.c.s @@ -48,7 +48,7 @@ _USB_MODULE_LEDS .EQU 0xff8a ;-------------------------------------------------------- ; code ;-------------------------------------------------------- -;source-doc/base-drv/./dev_transfers.c:28: usb_error usbdev_control_transfer(device_config *const device, const setup_packet *const cmd_packet, uint8_t *const buffer) { +;source-doc/base-drv/./dev_transfers.c:31: usb_error usbdev_control_transfer(device_config *const device, const setup_packet *const cmd_packet, uint8_t *const buffer) { ; --------------------------------- ; Function usbdev_control_transfer ; --------------------------------- @@ -56,7 +56,7 @@ _usbdev_control_transfer: push ix ld ix,0 add ix,sp -;source-doc/base-drv/./dev_transfers.c:29: return usb_control_transfer(cmd_packet, buffer, device->address, device->max_packet_size); +;source-doc/base-drv/./dev_transfers.c:32: return usb_control_transfer(cmd_packet, buffer, device->address, device->max_packet_size); ld e,(ix+4) ld d,(ix+5) ld l, e @@ -84,10 +84,10 @@ _usbdev_control_transfer: pop af pop af pop af -;source-doc/base-drv/./dev_transfers.c:30: } +;source-doc/base-drv/./dev_transfers.c:33: } pop ix ret -;source-doc/base-drv/./dev_transfers.c:32: usb_error usbdev_blk_out_trnsfer(device_config *const dev, const uint8_t *const buffer, const uint16_t buffer_size) { +;source-doc/base-drv/./dev_transfers.c:35: usb_error usbdev_blk_out_trnsfer(device_config *const dev, const uint8_t *const buffer, const uint16_t buffer_size) { ; --------------------------------- ; Function usbdev_blk_out_trnsfer ; --------------------------------- @@ -96,22 +96,27 @@ _usbdev_blk_out_trnsfer: ld ix,0 add ix,sp push af -;source-doc/base-drv/./dev_transfers.c:36: endpoint_param *const endpoint = &dev->endpoints[ENDPOINT_BULK_OUT]; - ld c,(ix+4) - ld b,(ix+5) - ld hl,0x0003 - add hl, bc - ex (sp), hl -;source-doc/base-drv/./dev_transfers.c:38: result = usb_data_out_transfer(buffer, buffer_size, dev->address, endpoint); - ld l, c - ld h, b + push af +;source-doc/base-drv/./dev_transfers.c:37: endpoint_param *const endpoint = &dev->endpoints[ENDPOINT_BULK_OUT]; + ld a,(ix+4) + ld (ix-4),a + ld a,(ix+5) + ld (ix-3),a + ld a,(ix-4) + add a,0x03 + ld (ix-2),a + ld a,(ix-3) + adc a,0x00 + ld (ix-1),a +;source-doc/base-drv/./dev_transfers.c:39: result = usb_data_out_transfer(buffer, buffer_size, dev->address, endpoint); + pop hl + push hl ld a, (hl) rlca rlca rlca rlca and 0x0f - push bc pop de pop hl push hl @@ -130,19 +135,19 @@ _usbdev_blk_out_trnsfer: pop af pop af inc sp - ld d, l - pop bc -;source-doc/base-drv/./dev_transfers.c:40: if (result == USB_ERR_STALL) { - ld a, d + ld a, l + ld (_result), a +;source-doc/base-drv/./dev_transfers.c:41: if (result == USB_ERR_STALL) { + ld a,(_result) sub 0x02 jr NZ,l_usbdev_blk_out_trnsfer_00102 -;source-doc/base-drv/./dev_transfers.c:41: usbtrn_clear_endpoint_halt(endpoint->number, dev->address, dev->max_packet_size); - ld l, c - ld h, b +;source-doc/base-drv/./dev_transfers.c:42: usbtrn_clear_endpoint_halt(endpoint->number, dev->address, dev->max_packet_size); + pop hl + push hl inc hl ld d, (hl) - ld l, c - ld h, b + pop hl + push hl ld a, (hl) rlca rlca @@ -150,8 +155,8 @@ _usbdev_blk_out_trnsfer: rlca and 0x0f ld b, a - pop hl - push hl + ld l,(ix-2) + ld h,(ix-1) ld a, (hl) rrca and 0x07 @@ -164,22 +169,26 @@ _usbdev_blk_out_trnsfer: call _usbtrn_clear_endpoint_halt pop af inc sp -;source-doc/base-drv/./dev_transfers.c:42: endpoint->toggle = 0; +;source-doc/base-drv/./dev_transfers.c:43: endpoint->toggle = 0; + pop de pop hl push hl + push de res 0, (hl) -;source-doc/base-drv/./dev_transfers.c:43: return USB_ERR_STALL; +;source-doc/base-drv/./dev_transfers.c:44: return USB_ERR_STALL; ld l,0x02 - jr l_usbdev_blk_out_trnsfer_00103 + jr l_usbdev_blk_out_trnsfer_00104 l_usbdev_blk_out_trnsfer_00102: -;source-doc/base-drv/./dev_transfers.c:46: RETURN_CHECK(result); - ld l, d -l_usbdev_blk_out_trnsfer_00103: -;source-doc/base-drv/./dev_transfers.c:47: } +;source-doc/base-drv/./dev_transfers.c:47: RETURN_CHECK(result); +;source-doc/base-drv/./dev_transfers.c:50: return result; + ld hl,_result + ld l, (hl) +l_usbdev_blk_out_trnsfer_00104: +;source-doc/base-drv/./dev_transfers.c:51: } ld sp, ix pop ix ret -;source-doc/base-drv/./dev_transfers.c:49: usb_error usbdev_bulk_in_transfer(device_config *const dev, uint8_t *const buffer, uint8_t *const buffer_size) { +;source-doc/base-drv/./dev_transfers.c:53: usb_error usbdev_bulk_in_transfer(device_config *const dev, uint8_t *const buffer, uint8_t *const buffer_size) { ; --------------------------------- ; Function usbdev_bulk_in_transfer ; --------------------------------- @@ -188,22 +197,27 @@ _usbdev_bulk_in_transfer: ld ix,0 add ix,sp push af -;source-doc/base-drv/./dev_transfers.c:53: endpoint_param *const endpoint = &dev->endpoints[ENDPOINT_BULK_IN]; - ld c,(ix+4) - ld b,(ix+5) - ld hl,0x0006 - add hl, bc - ex (sp), hl -;source-doc/base-drv/./dev_transfers.c:55: result = usb_data_in_transfer_n(buffer, buffer_size, dev->address, endpoint); - ld l, c - ld h, b + push af +;source-doc/base-drv/./dev_transfers.c:54: endpoint_param *const endpoint = &dev->endpoints[ENDPOINT_BULK_IN]; + ld a,(ix+4) + ld (ix-4),a + ld a,(ix+5) + ld (ix-3),a + ld a,(ix-4) + add a,0x06 + ld (ix-2),a + ld a,(ix-3) + adc a,0x00 + ld (ix-1),a +;source-doc/base-drv/./dev_transfers.c:56: result = usb_data_in_transfer_n(buffer, buffer_size, dev->address, endpoint); + pop hl + push hl ld a, (hl) rlca rlca rlca rlca and 0x0f - push bc pop de pop hl push hl @@ -222,19 +236,19 @@ _usbdev_bulk_in_transfer: pop af pop af inc sp - ld d, l - pop bc -;source-doc/base-drv/./dev_transfers.c:57: if (result == USB_ERR_STALL) { - ld a, d + ld a, l + ld (_result), a +;source-doc/base-drv/./dev_transfers.c:58: if (result == USB_ERR_STALL) { + ld a,(_result) sub 0x02 jr NZ,l_usbdev_bulk_in_transfer_00102 -;source-doc/base-drv/./dev_transfers.c:58: usbtrn_clear_endpoint_halt(endpoint->number, dev->address, dev->max_packet_size); - ld l, c - ld h, b +;source-doc/base-drv/./dev_transfers.c:59: usbtrn_clear_endpoint_halt(endpoint->number, dev->address, dev->max_packet_size); + pop hl + push hl inc hl ld d, (hl) - ld l, c - ld h, b + pop hl + push hl ld a, (hl) rlca rlca @@ -242,8 +256,8 @@ _usbdev_bulk_in_transfer: rlca and 0x0f ld b, a - pop hl - push hl + ld l,(ix-2) + ld h,(ix-1) ld a, (hl) rrca and 0x07 @@ -256,22 +270,26 @@ _usbdev_bulk_in_transfer: call _usbtrn_clear_endpoint_halt pop af inc sp -;source-doc/base-drv/./dev_transfers.c:59: endpoint->toggle = 0; +;source-doc/base-drv/./dev_transfers.c:60: endpoint->toggle = 0; + pop de pop hl push hl + push de res 0, (hl) -;source-doc/base-drv/./dev_transfers.c:60: return USB_ERR_STALL; +;source-doc/base-drv/./dev_transfers.c:61: return USB_ERR_STALL; ld l,0x02 - jr l_usbdev_bulk_in_transfer_00103 + jr l_usbdev_bulk_in_transfer_00104 l_usbdev_bulk_in_transfer_00102: -;source-doc/base-drv/./dev_transfers.c:63: RETURN_CHECK(result); - ld l, d -l_usbdev_bulk_in_transfer_00103: -;source-doc/base-drv/./dev_transfers.c:64: } +;source-doc/base-drv/./dev_transfers.c:64: RETURN_CHECK(result); +;source-doc/base-drv/./dev_transfers.c:66: return result; + ld hl,_result + ld l, (hl) +l_usbdev_bulk_in_transfer_00104: +;source-doc/base-drv/./dev_transfers.c:67: } ld sp, ix pop ix ret -;source-doc/base-drv/./dev_transfers.c:66: usb_error usbdev_dat_in_trnsfer(device_config *const device, +;source-doc/base-drv/./dev_transfers.c:69: usb_error usbdev_dat_in_trnsfer(device_config *const device, ; --------------------------------- ; Function usbdev_dat_in_trnsfer ; --------------------------------- @@ -280,35 +298,35 @@ _usbdev_dat_in_trnsfer: ld ix,0 add ix,sp push af -;source-doc/base-drv/./dev_transfers.c:73: endpoint_param *const endpoint = &device->endpoints[endpoint_type]; - ld c,(ix+4) - ld b,(ix+5) - ld e, c - ld d, b - inc de - inc de - inc de - push de + push af +;source-doc/base-drv/./dev_transfers.c:74: endpoint_param *const endpoint = &device->endpoints[endpoint_type]; + ld a,(ix+4) + ld (ix-4),a + ld a,(ix+5) + ld (ix-3),a + pop bc + push bc + inc bc + inc bc + inc bc ld a,(ix+10) ld e, a add a, a add a, e - pop de - add a, e + add a, c ld (ix-2),a ld a,0x00 - adc a, d + adc a, b ld (ix-1),a -;source-doc/base-drv/./dev_transfers.c:75: result = usb_data_in_transfer(buffer, buffer_size, device->address, endpoint); - ld l, c - ld h, b +;source-doc/base-drv/./dev_transfers.c:76: result = usb_data_in_transfer(buffer, buffer_size, device->address, endpoint); + pop hl + push hl ld a, (hl) rlca rlca rlca rlca and 0x0f - push bc pop de pop hl push hl @@ -327,19 +345,19 @@ _usbdev_dat_in_trnsfer: pop af pop af inc sp - ld d, l - pop bc -;source-doc/base-drv/./dev_transfers.c:77: if (result == USB_ERR_STALL) { - ld a, d + ld a, l + ld (_result), a +;source-doc/base-drv/./dev_transfers.c:78: if (result == USB_ERR_STALL) { + ld a,(_result) sub 0x02 jr NZ,l_usbdev_dat_in_trnsfer_00102 -;source-doc/base-drv/./dev_transfers.c:78: usbtrn_clear_endpoint_halt(endpoint->number, device->address, device->max_packet_size); - ld l, c - ld h, b +;source-doc/base-drv/./dev_transfers.c:79: usbtrn_clear_endpoint_halt(endpoint->number, device->address, device->max_packet_size); + pop hl + push hl inc hl ld d, (hl) - ld l, c - ld h, b + pop hl + push hl ld a, (hl) rlca rlca @@ -347,8 +365,8 @@ _usbdev_dat_in_trnsfer: rlca and 0x0f ld b, a - pop hl - push hl + ld l,(ix-2) + ld h,(ix-1) ld a, (hl) rrca and 0x07 @@ -361,22 +379,26 @@ _usbdev_dat_in_trnsfer: call _usbtrn_clear_endpoint_halt pop af inc sp -;source-doc/base-drv/./dev_transfers.c:79: endpoint->toggle = 0; +;source-doc/base-drv/./dev_transfers.c:80: endpoint->toggle = 0; + pop de pop hl push hl + push de res 0, (hl) -;source-doc/base-drv/./dev_transfers.c:80: return USB_ERR_STALL; +;source-doc/base-drv/./dev_transfers.c:81: return USB_ERR_STALL; ld l,0x02 - jr l_usbdev_dat_in_trnsfer_00103 + jr l_usbdev_dat_in_trnsfer_00104 l_usbdev_dat_in_trnsfer_00102: -;source-doc/base-drv/./dev_transfers.c:83: RETURN_CHECK(result); - ld l, d -l_usbdev_dat_in_trnsfer_00103: -;source-doc/base-drv/./dev_transfers.c:84: } +;source-doc/base-drv/./dev_transfers.c:84: RETURN_CHECK(result); +;source-doc/base-drv/./dev_transfers.c:86: return result; + ld hl,_result + ld l, (hl) +l_usbdev_dat_in_trnsfer_00104: +;source-doc/base-drv/./dev_transfers.c:87: } ld sp, ix pop ix ret -;source-doc/base-drv/./dev_transfers.c:86: usb_error usbdev_dat_in_trnsfer_0(device_config *const device, uint8_t *const buffer, const uint8_t buffer_size) __sdcccall(1) { +;source-doc/base-drv/./dev_transfers.c:89: usb_error usbdev_dat_in_trnsfer_0(device_config *const device, uint8_t *const buffer, const uint8_t buffer_size) { ; --------------------------------- ; Function usbdev_dat_in_trnsfer_0 ; --------------------------------- @@ -386,53 +408,57 @@ _usbdev_dat_in_trnsfer_0: add ix,sp push af push af - ld c, l - ld b, h - ld (ix-2),e - ld (ix-1),d ;source-doc/base-drv/./dev_transfers.c:90: endpoint_param *const endpoint = &device->endpoints[0]; - ld hl,0x0003 - add hl, bc - ex (sp), hl + ld a,(ix+4) + ld (ix-4),a + ld a,(ix+5) + ld (ix-3),a + ld a,(ix-4) + add a,0x03 + ld (ix-2),a + ld a,(ix-3) + adc a,0x00 + ld (ix-1),a ;source-doc/base-drv/./dev_transfers.c:92: result = usb_data_in_transfer(buffer, buffer_size, device->address, endpoint); - ld l, c - ld h, b + pop hl + push hl ld a, (hl) rlca rlca rlca rlca and 0x0f - ld e,(ix+4) - ld d,0x00 - push bc - ld l,(ix-4) - ld h,(ix-3) + ld c,(ix+8) + ld b,0x00 + pop de + pop hl + push hl + push de push hl push af inc sp - push de - ld l,(ix-2) - ld h,(ix-1) + push bc + ld l,(ix+6) + ld h,(ix+7) push hl call _usb_data_in_transfer pop af pop af pop af inc sp - ld d, l - pop bc + ld a, l + ld (_result), a ;source-doc/base-drv/./dev_transfers.c:94: if (result == USB_ERR_STALL) { - ld a, d + ld a,(_result) sub 0x02 jr NZ,l_usbdev_dat_in_trnsfer_0_00102 ;source-doc/base-drv/./dev_transfers.c:95: usbtrn_clear_endpoint_halt(endpoint->number, device->address, device->max_packet_size); - ld l, c - ld h, b + pop hl + push hl inc hl ld d, (hl) - ld l, c - ld h, b + pop hl + push hl ld a, (hl) rlca rlca @@ -440,8 +466,8 @@ _usbdev_dat_in_trnsfer_0: rlca and 0x0f ld b, a - pop hl - push hl + ld l,(ix-2) + ld h,(ix-1) ld a, (hl) rrca and 0x07 @@ -455,19 +481,20 @@ _usbdev_dat_in_trnsfer_0: pop af inc sp ;source-doc/base-drv/./dev_transfers.c:96: endpoint->toggle = 0; + pop de pop hl push hl + push de res 0, (hl) ;source-doc/base-drv/./dev_transfers.c:97: return USB_ERR_STALL; - ld a,0x02 + ld l,0x02 jr l_usbdev_dat_in_trnsfer_0_00103 l_usbdev_dat_in_trnsfer_0_00102: -;source-doc/base-drv/./dev_transfers.c:100: RETURN_CHECK(result); - ld a, d +;source-doc/base-drv/./dev_transfers.c:100: return result; + ld hl,_result + ld l, (hl) l_usbdev_dat_in_trnsfer_0_00103: ;source-doc/base-drv/./dev_transfers.c:101: } ld sp, ix pop ix - pop hl - inc sp - jp (hl) + ret diff --git a/Source/HBIOS/ch376-native/base-drv/enumerate.c.s b/Source/HBIOS/ch376-native/base-drv/enumerate.c.s index 91a0e9bc..f1e3e0e0 100644 --- a/Source/HBIOS/ch376-native/base-drv/enumerate.c.s +++ b/Source/HBIOS/ch376-native/base-drv/enumerate.c.s @@ -532,12 +532,14 @@ _op_capture_hub_driver_interfac: ex de, hl call _configure_usb_hub ld a, l +;source-doc/base-drv/./enumerate.c:97: done: l_op_capture_hub_driver_interfa: -;source-doc/base-drv/./enumerate.c:97: } +;source-doc/base-drv/./enumerate.c:98: return result; +;source-doc/base-drv/./enumerate.c:99: } ld sp, ix pop ix ret -;source-doc/base-drv/./enumerate.c:99: usb_error op_cap_drv_intf(_working *const working) __z88dk_fastcall { +;source-doc/base-drv/./enumerate.c:101: usb_error op_cap_drv_intf(_working *const working) __z88dk_fastcall { ; --------------------------------- ; Function op_cap_drv_intf ; --------------------------------- @@ -552,7 +554,7 @@ _op_cap_drv_intf: ld sp, hl ld (ix-2),c ld (ix-1),b -;source-doc/base-drv/./enumerate.c:102: const interface_descriptor *const interface = (interface_descriptor *)working->ptr; +;source-doc/base-drv/./enumerate.c:104: const interface_descriptor *const interface = (interface_descriptor *)working->ptr; ld l,(ix-2) ld h,(ix-1) ld de,0x001b @@ -563,7 +565,7 @@ _op_cap_drv_intf: dec hl ld c, e ld b, d -;source-doc/base-drv/./enumerate.c:104: working->ptr += interface->bLength; +;source-doc/base-drv/./enumerate.c:106: working->ptr += interface->bLength; ld a, (bc) add a, e ld e, a @@ -572,7 +574,7 @@ _op_cap_drv_intf: ld (hl), e inc hl ld (hl), a -;source-doc/base-drv/./enumerate.c:105: working->endpoint_count = interface->bNumEndpoints; +;source-doc/base-drv/./enumerate.c:107: working->endpoint_count = interface->bNumEndpoints; ld a,(ix-2) add a,0x17 ld e, a @@ -587,7 +589,7 @@ _op_cap_drv_intf: inc hl ld a, (hl) ld (de), a -;source-doc/base-drv/./enumerate.c:106: working->p_current_device = NULL; +;source-doc/base-drv/./enumerate.c:108: working->p_current_device = NULL; ld a,(ix-2) add a,0x1d ld (ix-4),a @@ -600,7 +602,7 @@ _op_cap_drv_intf: ld (hl), a inc hl ld (hl), a -;source-doc/base-drv/./enumerate.c:108: switch (working->usb_device) { +;source-doc/base-drv/./enumerate.c:110: switch (working->usb_device) { ld l,(ix-2) ld h,(ix-1) inc hl @@ -610,27 +612,26 @@ _op_cap_drv_intf: jr Z,l_op_cap_drv_intf_00104 sub 0x0f jr NZ,l_op_cap_drv_intf_00107 -;source-doc/base-drv/./enumerate.c:110: CHECK(op_capture_hub_driver_interface(working)) +;source-doc/base-drv/./enumerate.c:112: CHECK(op_capture_hub_driver_interface(working)) ld l,(ix-2) ld h,(ix-1) call _op_capture_hub_driver_interfac or a jr Z,l_op_cap_drv_intf_00112 - ld l, a - jr l_op_cap_drv_intf_00115 -;source-doc/base-drv/./enumerate.c:114: case USB_IS_UNKNOWN: { + jr l_op_cap_drv_intf_00113 +;source-doc/base-drv/./enumerate.c:116: case USB_IS_UNKNOWN: { l_op_cap_drv_intf_00104: -;source-doc/base-drv/./enumerate.c:116: memset(&unkown_dev_cfg, 0, sizeof(device_config)); +;source-doc/base-drv/./enumerate.c:118: memset(&unkown_dev_cfg, 0, sizeof(device_config)); push bc ld hl,2 add hl, sp ld b,0x0c -l_op_cap_drv_intf_00169: +l_op_cap_drv_intf_00154: ld (hl),0x00 inc hl - djnz l_op_cap_drv_intf_00169 + djnz l_op_cap_drv_intf_00154 pop bc -;source-doc/base-drv/./enumerate.c:117: working->p_current_device = &unkown_dev_cfg; +;source-doc/base-drv/./enumerate.c:119: working->p_current_device = &unkown_dev_cfg; ld hl,0 add hl, sp ex de, hl @@ -639,7 +640,7 @@ l_op_cap_drv_intf_00169: ld (hl), e inc hl ld (hl), d -;source-doc/base-drv/./enumerate.c:118: CHECK(configure_device(working, interface, &unkown_dev_cfg)); +;source-doc/base-drv/./enumerate.c:120: CHECK(configure_device(working, interface, &unkown_dev_cfg)); ld hl,0 add hl, sp push hl @@ -654,29 +655,29 @@ l_op_cap_drv_intf_00169: ld a, l or a jr Z,l_op_cap_drv_intf_00112 - jr l_op_cap_drv_intf_00115 -;source-doc/base-drv/./enumerate.c:122: default: { + jr l_op_cap_drv_intf_00113 +;source-doc/base-drv/./enumerate.c:124: default: { l_op_cap_drv_intf_00107: -;source-doc/base-drv/./enumerate.c:123: device_config *dev_cfg = find_first_free(); +;source-doc/base-drv/./enumerate.c:125: device_config *dev_cfg = find_first_free(); push bc call _find_first_free ex de, hl pop bc -;source-doc/base-drv/./enumerate.c:124: if (dev_cfg == NULL) +;source-doc/base-drv/./enumerate.c:126: if (dev_cfg == NULL) ld a, d or e jr NZ,l_op_cap_drv_intf_00109 -;source-doc/base-drv/./enumerate.c:125: return USB_ERR_OUT_OF_MEMORY; +;source-doc/base-drv/./enumerate.c:127: return USB_ERR_OUT_OF_MEMORY; ld l,0x83 - jr l_op_cap_drv_intf_00115 + jr l_op_cap_drv_intf_00114 l_op_cap_drv_intf_00109: -;source-doc/base-drv/./enumerate.c:126: working->p_current_device = dev_cfg; +;source-doc/base-drv/./enumerate.c:128: working->p_current_device = dev_cfg; ld l,(ix-4) ld h,(ix-3) ld (hl), e inc hl ld (hl), d -;source-doc/base-drv/./enumerate.c:127: CHECK(configure_device(working, interface, dev_cfg)); +;source-doc/base-drv/./enumerate.c:129: CHECK(configure_device(working, interface, dev_cfg)); push de push bc ld l,(ix-2) @@ -688,32 +689,29 @@ l_op_cap_drv_intf_00109: pop af ld a, l or a -;source-doc/base-drv/./enumerate.c:130: } - jr NZ,l_op_cap_drv_intf_00115 + jr NZ,l_op_cap_drv_intf_00113 +;source-doc/base-drv/./enumerate.c:132: } l_op_cap_drv_intf_00112: -;source-doc/base-drv/./enumerate.c:132: CHECK(op_parse_endpoint(working)); +;source-doc/base-drv/./enumerate.c:134: result = op_parse_endpoint(working); ld l,(ix-2) ld h,(ix-1) call _op_parse_endpoint - or a - jr Z,l_op_cap_drv_intf_00114 +;source-doc/base-drv/./enumerate.c:136: done: +l_op_cap_drv_intf_00113: +;source-doc/base-drv/./enumerate.c:137: return result; ld l, a - jr l_op_cap_drv_intf_00115 l_op_cap_drv_intf_00114: -;source-doc/base-drv/./enumerate.c:134: return result; - ld l, a -l_op_cap_drv_intf_00115: -;source-doc/base-drv/./enumerate.c:135: } +;source-doc/base-drv/./enumerate.c:138: } ld sp, ix pop ix ret -;source-doc/base-drv/./enumerate.c:137: usb_error op_id_class_drv(_working *const working) __sdcccall(1) { +;source-doc/base-drv/./enumerate.c:140: usb_error op_id_class_drv(_working *const working) __sdcccall(1) { ; --------------------------------- ; Function op_id_class_drv ; --------------------------------- _op_id_class_drv: ex de, hl -;source-doc/base-drv/./enumerate.c:139: const interface_descriptor *const ptr = (const interface_descriptor *)working->ptr; +;source-doc/base-drv/./enumerate.c:141: const interface_descriptor *const ptr = (const interface_descriptor *)working->ptr; ld l, e ld h, d ld bc,0x001c @@ -721,16 +719,16 @@ _op_id_class_drv: ld a, (hl) dec hl ld l, (hl) -;source-doc/base-drv/./enumerate.c:141: working->usb_device = ptr->bLength > 5 ? identify_class_driver(working) : 0; + ld h, a +;source-doc/base-drv/./enumerate.c:143: working->usb_device = ptr->bLength > 5 ? identify_class_driver(working) : 0; ld c, e ld b, d inc bc inc bc - ld h, a ld l, (hl) ld a,0x05 sub l - jr NC,l_op_id_class_drv_00105 + jr NC,l_op_id_class_drv_00103 push bc push de push de @@ -739,18 +737,15 @@ _op_id_class_drv: ld a, l pop de pop bc - jr l_op_id_class_drv_00106 -l_op_id_class_drv_00105: + jr l_op_id_class_drv_00104 +l_op_id_class_drv_00103: xor a -l_op_id_class_drv_00106: +l_op_id_class_drv_00104: ld (bc), a -;source-doc/base-drv/./enumerate.c:143: CHECK(op_cap_drv_intf(working)); +;source-doc/base-drv/./enumerate.c:145: return op_cap_drv_intf(working); ex de, hl call _op_cap_drv_intf ld a, l - or a - ret NZ -;source-doc/base-drv/./enumerate.c:145: return result; ;source-doc/base-drv/./enumerate.c:146: } ret ;source-doc/base-drv/./enumerate.c:148: usb_error op_get_cfg_desc(_working *const working) __sdcccall(1) { @@ -762,65 +757,81 @@ _op_get_cfg_desc: ld ix,0 add ix,sp push af - ex de, hl -;source-doc/base-drv/./enumerate.c:151: memset(working->config.buffer, 0, MAX_CONFIG_SIZE); - ld hl,0x001f - add hl, de - ex (sp), hl + push af + ld (ix-2),l + ld (ix-1),h +;source-doc/base-drv/./enumerate.c:149: memset(working->config.buffer, 0, MAX_CONFIG_SIZE); + ld a,(ix-2) + add a,0x1f + ld (ix-4),a + ld a,(ix-1) + adc a,0x00 + ld (ix-3),a pop hl push hl ld b,0x8c -l_op_get_cfg_desc_00121: +l_op_get_cfg_desc_00113: ld (hl),0x00 inc hl - djnz l_op_get_cfg_desc_00121 -;source-doc/base-drv/./enumerate.c:153: const uint8_t max_packet_size = working->desc.bMaxPacketSize0; - ld c, e - ld b, d + djnz l_op_get_cfg_desc_00113 +;source-doc/base-drv/./enumerate.c:151: const uint8_t max_packet_size = working->desc.bMaxPacketSize0; + pop hl + pop bc + push bc + push hl inc bc inc bc inc bc ld hl,7 add hl, bc - ld a, (hl) -;source-doc/base-drv/./enumerate.c:156: working->config.buffer)); - ld c, e - ld b, d + ld d, (hl) +;source-doc/base-drv/./enumerate.c:154: working->config.buffer)); + pop hl + pop bc + push bc + push hl ld hl,24 add hl, bc - ld b, (hl) - ld l, e - ld h, d + ld a, (hl) + pop hl + pop bc push bc - ld bc,0x0015 + push hl + ld hl,21 add hl, bc - pop bc - ld c, (hl) - push de - ld l,(ix-2) - ld h,(ix-1) + ld b, (hl) + pop hl + push hl push hl ld h,0x8c push hl inc sp + push de + inc sp push af inc sp push bc + inc sp call _usbtrn_gfull_cfg_desc pop af pop af pop af ld a, l - pop de + ld (_result), a + ld a,(_result) or a - jr NZ,l_op_get_cfg_desc_00105 -;source-doc/base-drv/./enumerate.c:158: working->ptr = (working->config.buffer + sizeof(config_descriptor)); - ld hl,0x001b + jr NZ,l_op_get_cfg_desc_00103 +;source-doc/base-drv/./enumerate.c:156: working->ptr = (working->config.buffer + sizeof(config_descriptor)); + pop de + pop hl + push hl + push de + ld de,0x001b add hl, de - ld a, e + ld a,(ix-2) add a,0x1f ld c, a - ld a, d + ld a,(ix-1) adc a,0x00 ld b, a ld a, c @@ -831,31 +842,37 @@ l_op_get_cfg_desc_00121: ld (hl), c inc hl ld (hl), a -;source-doc/base-drv/./enumerate.c:159: working->interface_count = working->config.desc.bNumInterfaces; - ld hl,0x0016 +;source-doc/base-drv/./enumerate.c:157: working->interface_count = working->config.desc.bNumInterfaces; + ld a,(ix-2) + add a,0x16 + ld c, a + ld a,(ix-1) + adc a,0x00 + ld b, a + pop de + push de + ld hl,4 add hl, de - ld c, l - ld b, h - pop hl - push hl - inc hl - inc hl - inc hl - inc hl ld a, (hl) ld (bc), a -;source-doc/base-drv/./enumerate.c:161: CHECK(op_id_class_drv(working)); - ex de, hl +;source-doc/base-drv/./enumerate.c:159: return op_id_class_drv(working); + pop de + pop hl + push hl + push de call _op_id_class_drv - or a - jr NZ,l_op_get_cfg_desc_00105 -;source-doc/base-drv/./enumerate.c:163: return result; -l_op_get_cfg_desc_00105: -;source-doc/base-drv/./enumerate.c:164: } + jr l_op_get_cfg_desc_00104 +;source-doc/base-drv/./enumerate.c:160: done: +l_op_get_cfg_desc_00103: +;source-doc/base-drv/./enumerate.c:161: return result; + ld hl,_result + ld a, (hl) +l_op_get_cfg_desc_00104: +;source-doc/base-drv/./enumerate.c:162: } ld sp, ix pop ix ret -;source-doc/base-drv/./enumerate.c:166: usb_error read_all_configs(enumeration_state *const state) { +;source-doc/base-drv/./enumerate.c:164: usb_error read_all_configs(enumeration_state *const state) { ; --------------------------------- ; Function read_all_configs ; --------------------------------- @@ -866,18 +883,18 @@ _read_all_configs: ld hl, -171 add hl, sp ld sp, hl -;source-doc/base-drv/./enumerate.c:171: memset(&working, 0, sizeof(_working)); +;source-doc/base-drv/./enumerate.c:169: memset(&working, 0, sizeof(_working)); ld hl,0 add hl, sp ex de, hl ld l, e ld h, d ld b,0xab -l_read_all_configs_00148: +l_read_all_configs_00149: ld (hl),0x00 inc hl - djnz l_read_all_configs_00148 -;source-doc/base-drv/./enumerate.c:172: working.state = state; + djnz l_read_all_configs_00149 +;source-doc/base-drv/./enumerate.c:170: working.state = state; ld l, e ld h, d ld a,(ix+4) @@ -885,57 +902,53 @@ l_read_all_configs_00148: inc hl ld a,(ix+5) ld (hl), a -;source-doc/base-drv/./enumerate.c:174: CHECK(usbtrn_get_descriptor(&working.desc)); +;source-doc/base-drv/./enumerate.c:172: CHECK(usbtrn_get_descriptor(&working.desc)); push de ld hl,5 add hl, sp push hl call _usbtrn_get_descriptor pop af - ld c, l + ld a, l pop de - ld a, c or a - jr Z,l_read_all_configs_00102 - ld l, c - jr l_read_all_configs_00111 -l_read_all_configs_00102: -;source-doc/base-drv/./enumerate.c:176: state->next_device_address++; + jr NZ,l_read_all_configs_00108 +;source-doc/base-drv/./enumerate.c:174: state->next_device_address++; ld a,(ix+4) - ld c,(ix+5) + ld b,(ix+5) ld l, a - ld h, c - ld b, (hl) - inc b + ld h, b + ld c, (hl) + inc c ld l, a - ld h, c - ld (hl), b -;source-doc/base-drv/./enumerate.c:177: working.current_device_address = state->next_device_address; + ld h, b + ld (hl), c +;source-doc/base-drv/./enumerate.c:175: working.current_device_address = state->next_device_address; ld hl,0x0018 add hl, de - ld (hl), b -;source-doc/base-drv/./enumerate.c:178: CHECK(usbtrn_set_address(working.current_device_address)); + ld (hl), c +;source-doc/base-drv/./enumerate.c:176: CHECK(usbtrn_set_address(working.current_device_address)); push de - ld l, b + ld l, c call _usbtrn_set_address - pop de ld a, l -;source-doc/base-drv/./enumerate.c:180: for (uint8_t config_index = 0; config_index < working.desc.bNumConfigurations; config_index++) { + pop de +;source-doc/base-drv/./enumerate.c:178: for (uint8_t config_index = 0; config_index < working.desc.bNumConfigurations; config_index++) { or a - jr NZ,l_read_all_configs_00111 + jr NZ,l_read_all_configs_00108 ld c,a -l_read_all_configs_00109: +l_read_all_configs_00110: ld hl,20 add hl, sp ld b, (hl) ld a, c sub b jr NC,l_read_all_configs_00107 -;source-doc/base-drv/./enumerate.c:181: working.config_index = config_index; +;source-doc/base-drv/./enumerate.c:179: working.config_index = config_index; ld hl,0x0015 add hl, de ld (hl), c -;source-doc/base-drv/./enumerate.c:183: CHECK(op_get_cfg_desc(&working)); +;source-doc/base-drv/./enumerate.c:181: CHECK(op_get_cfg_desc(&working)); push bc push de ld hl,4 @@ -944,17 +957,19 @@ l_read_all_configs_00109: pop de pop bc or a - jr Z,l_read_all_configs_00110 - ld l, a - jr l_read_all_configs_00111 -l_read_all_configs_00110: -;source-doc/base-drv/./enumerate.c:180: for (uint8_t config_index = 0; config_index < working.desc.bNumConfigurations; config_index++) { + jr NZ,l_read_all_configs_00108 +;source-doc/base-drv/./enumerate.c:178: for (uint8_t config_index = 0; config_index < working.desc.bNumConfigurations; config_index++) { inc c - jr l_read_all_configs_00109 + jr l_read_all_configs_00110 l_read_all_configs_00107: -;source-doc/base-drv/./enumerate.c:186: return USB_ERR_OK; +;source-doc/base-drv/./enumerate.c:184: return USB_ERR_OK; ld l,0x00 -l_read_all_configs_00111: + jr l_read_all_configs_00112 +;source-doc/base-drv/./enumerate.c:185: done: +l_read_all_configs_00108: +;source-doc/base-drv/./enumerate.c:186: return result; + ld l, a +l_read_all_configs_00112: ;source-doc/base-drv/./enumerate.c:187: } ld sp, ix pop ix @@ -989,17 +1004,9 @@ _enumerate_all_devices: ;source-doc/base-drv/./enumerate.c:197: work_area->count_of_detected_usb_devices = state.next_device_address; ld a, (de) ld ((_x + 1)),a -;source-doc/base-drv/./enumerate.c:199: CHECK(result); - ld a, c - or a - jr Z,l_enumerate_all_devices_00102 - ld l, c - jr l_enumerate_all_devices_00103 -l_enumerate_all_devices_00102: -;source-doc/base-drv/./enumerate.c:201: return result; +;source-doc/base-drv/./enumerate.c:200: return result; ld l, c -l_enumerate_all_devices_00103: -;source-doc/base-drv/./enumerate.c:202: } +;source-doc/base-drv/./enumerate.c:201: } inc sp pop ix ret diff --git a/Source/HBIOS/ch376-native/base-drv/enumerate_hub.c.s b/Source/HBIOS/ch376-native/base-drv/enumerate_hub.c.s index 69ffc3bd..7a66b97e 100644 --- a/Source/HBIOS/ch376-native/base-drv/enumerate_hub.c.s +++ b/Source/HBIOS/ch376-native/base-drv/enumerate_hub.c.s @@ -246,14 +246,14 @@ _configure_usb_hub: add ix,sp ld c, l ld b, h - ld hl, -15 + ld hl, -14 add hl, sp ld sp, hl - ld (ix-3),c - ld (ix-2),b + ld (ix-2),c + ld (ix-1),b ;source-doc/base-drv/./enumerate_hub.c:45: const device_config_hub *const hub_config = working->hub_config; - ld c,(ix-3) - ld b,(ix-2) + ld c,(ix-2) + ld b,(ix-1) ld hl,25 add hl, bc ld c, (hl) @@ -267,85 +267,84 @@ _configure_usb_hub: ld l, c ld h, b call _hub_get_descriptor - ld e, a pop bc - ld a, e or a - jr Z,l_configure_usb_hub_00102 - ld l, e - jp l_configure_usb_hub_00129 -l_configure_usb_hub_00102: + jp NZ, l_configure_usb_hub_00129 ;source-doc/base-drv/./enumerate_hub.c:49: uint8_t i = hub_description.bNbrPorts; - ld a,(ix-13) - ld (ix-1),a + ld d,(ix-12) ;source-doc/base-drv/./enumerate_hub.c:50: do { l_configure_usb_hub_00126: ;source-doc/base-drv/./enumerate_hub.c:51: CHECK(hub_clear_feature(hub_config, FEAT_PORT_POWER, i)); push bc - ld d,(ix-1) + push de ld e,0x08 push de push bc call _hub_clear_feature pop af pop af - pop bc ld a, l + pop de + pop bc or a - jp NZ,l_configure_usb_hub_00129 + jp NZ, l_configure_usb_hub_00129 ;source-doc/base-drv/./enumerate_hub.c:53: CHECK(hub_set_feature(hub_config, FEAT_PORT_POWER, i)); push bc - ld d,(ix-1) + push de ld e,0x08 push de push bc call _hub_set_feature pop af pop af - pop bc ld a, l + pop de + pop bc or a - jp NZ,l_configure_usb_hub_00129 + jp NZ, l_configure_usb_hub_00129 ;source-doc/base-drv/./enumerate_hub.c:55: hub_clear_feature(hub_config, FEAT_PORT_RESET, i); push bc - ld d,(ix-1) + push de ld e,0x04 push de push bc call _hub_clear_feature pop af pop af + pop de pop bc ;source-doc/base-drv/./enumerate_hub.c:57: CHECK(hub_set_feature(hub_config, FEAT_PORT_RESET, i)); push bc - ld d,(ix-1) + push de ld e,0x04 push de push bc call _hub_set_feature pop af pop af - pop bc ld a, l + pop de + pop bc or a - jp NZ,l_configure_usb_hub_00129 + jp NZ, l_configure_usb_hub_00129 ;source-doc/base-drv/./enumerate_hub.c:59: CHECK(hub_get_status_port(hub_config, i, &port_status)); push bc - ld hl,10 + push de + ld hl,12 add hl, sp push hl - ld a,(ix-1) - push af + push de inc sp push bc call _hub_get_status_port pop af pop af inc sp - pop bc ld a, l + pop de + pop bc or a - jp NZ,l_configure_usb_hub_00129 + jp NZ, l_configure_usb_hub_00129 ;source-doc/base-drv/./enumerate_hub.c:61: if (port_status.wPortStatus.port_connection) { ld hl,8 add hl, sp @@ -354,105 +353,122 @@ l_configure_usb_hub_00126: jr Z,l_configure_usb_hub_00124 ;source-doc/base-drv/./enumerate_hub.c:62: CHECK(hub_clear_feature(hub_config, HUB_FEATURE_PORT_CONNECTION_CHA, i)); push bc - ld d,(ix-1) + push de ld e,0x10 push de push bc call _hub_clear_feature pop af pop af - pop bc ld a, l + pop de + pop bc or a jr NZ,l_configure_usb_hub_00129 ;source-doc/base-drv/./enumerate_hub.c:64: CHECK(hub_clear_feature(hub_config, FEAT_PORT_ENABLE_CHANGE, i)); push bc - ld d,(ix-1) + push de ld e,0x11 push de push bc call _hub_clear_feature pop af pop af - pop bc ld a, l + pop de + pop bc or a jr NZ,l_configure_usb_hub_00129 ;source-doc/base-drv/./enumerate_hub.c:66: CHECK(hub_clear_feature(hub_config, FEAT_PORT_RESET_CHANGE, i)); push bc - ld d,(ix-1) + push de ld e,0x14 push de push bc call _hub_clear_feature pop af pop af - pop bc ld a, l + pop de + pop bc or a jr NZ,l_configure_usb_hub_00129 ;source-doc/base-drv/./enumerate_hub.c:67: delay_short(); push bc + push de call _delay_short + pop de pop bc ;source-doc/base-drv/./enumerate_hub.c:69: CHECK(hub_get_status_port(hub_config, i, &port_status)); push bc - ld hl,10 + push de + ld hl,12 add hl, sp push hl - ld a,(ix-1) - push af + push de inc sp push bc call _hub_get_status_port pop af pop af inc sp - pop bc ld a, l + pop de + pop bc or a jr NZ,l_configure_usb_hub_00129 ;source-doc/base-drv/./enumerate_hub.c:70: delay_short(); push bc + push de call _delay_short + pop de pop bc ;source-doc/base-drv/./enumerate_hub.c:72: CHECK(read_all_configs(working->state)); - ld l,(ix-3) - ld h,(ix-2) - ld e, (hl) + ld l,(ix-2) + ld h,(ix-1) + ld a, (hl) inc hl - ld d, (hl) + ld h, (hl) + ld l, a push bc push de + push hl call _read_all_configs pop af - pop bc ld a, l + pop de + pop bc or a jr Z,l_configure_usb_hub_00127 jr l_configure_usb_hub_00129 l_configure_usb_hub_00124: ;source-doc/base-drv/./enumerate_hub.c:75: CHECK(hub_clear_feature(hub_config, FEAT_PORT_POWER, i)); push bc - ld d,(ix-1) + push de ld e,0x08 push de push bc call _hub_clear_feature pop af pop af - pop bc ld a, l + pop de + pop bc or a jr NZ,l_configure_usb_hub_00129 l_configure_usb_hub_00127: ;source-doc/base-drv/./enumerate_hub.c:77: } while (--i != 0); - dec (ix-1) + dec d jp NZ, l_configure_usb_hub_00126 ;source-doc/base-drv/./enumerate_hub.c:79: return USB_ERR_OK; ld l,0x00 + jr l_configure_usb_hub_00130 +;source-doc/base-drv/./enumerate_hub.c:80: done: l_configure_usb_hub_00129: -;source-doc/base-drv/./enumerate_hub.c:80: } +;source-doc/base-drv/./enumerate_hub.c:81: return result; + ld l, a +l_configure_usb_hub_00130: +;source-doc/base-drv/./enumerate_hub.c:82: } ld sp, ix pop ix ret diff --git a/Source/HBIOS/ch376-native/base-drv/protocol.c.s b/Source/HBIOS/ch376-native/base-drv/protocol.c.s index a7e42b9c..0ffb9902 100644 --- a/Source/HBIOS/ch376-native/base-drv/protocol.c.s +++ b/Source/HBIOS/ch376-native/base-drv/protocol.c.s @@ -59,26 +59,18 @@ _usbtrn_get_descriptor: ld hl, -8 add hl, sp ld sp, hl -;source-doc/base-drv/./protocol.c:32: cmd = cmd_get_device_descriptor; +;source-doc/base-drv/./protocol.c:31: cmd = cmd_get_device_descriptor; ld hl,0 add hl, sp ex de, hl ld hl,_cmd_get_device_descriptor ld bc,0x0008 ldir -;source-doc/base-drv/./protocol.c:33: cmd.wLength = 8; +;source-doc/base-drv/./protocol.c:32: cmd.wLength = 8; ld (ix-2),0x08 xor a ld (ix-1),a -;source-doc/base-drv/./protocol.c:35: debugger(); - PUSH AF - PUSH BC - XOR A - LD B, 7 - DEFB 0x49, 0xD7 - POP BC - POP AF -;source-doc/base-drv/./protocol.c:36: result = usb_control_transfer(&cmd, (uint8_t *)buffer, 0, 8); +;source-doc/base-drv/./protocol.c:34: result = usb_control_transfer(&cmd, (uint8_t *)buffer, 0, 8); ld c,(ix+4) ld b,(ix+5) ld e, c @@ -99,11 +91,13 @@ _usbtrn_get_descriptor: pop af pop af pop bc -;source-doc/base-drv/./protocol.c:38: CHECK(result); ld a, l + ld (_result), a +;source-doc/base-drv/./protocol.c:36: CHECK(result); + ld a,(_result) or a jr NZ,l_usbtrn_get_descriptor_00103 -;source-doc/base-drv/./protocol.c:40: cmd = cmd_get_device_descriptor; +;source-doc/base-drv/./protocol.c:38: cmd = cmd_get_device_descriptor; ld hl,0 add hl, sp ex de, hl @@ -112,11 +106,11 @@ _usbtrn_get_descriptor: ld bc,0x0008 ldir pop bc -;source-doc/base-drv/./protocol.c:41: cmd.wLength = 18; +;source-doc/base-drv/./protocol.c:39: cmd.wLength = 18; ld (ix-2),0x12 xor a ld (ix-1),a -;source-doc/base-drv/./protocol.c:42: result = usb_control_transfer(&cmd, (uint8_t *)buffer, 0, buffer->bMaxPacketSize0); +;source-doc/base-drv/./protocol.c:40: result = usb_control_transfer(&cmd, (uint8_t *)buffer, 0, buffer->bMaxPacketSize0); ld e,(ix+4) ld d,(ix+5) ld hl,7 @@ -135,9 +129,15 @@ _usbtrn_get_descriptor: pop af pop af pop af -;source-doc/base-drv/./protocol.c:44: RETURN_CHECK(result); + ld a, l + ld (_result), a +;source-doc/base-drv/./protocol.c:42: RETURN_CHECK(result); +;source-doc/base-drv/./protocol.c:44: done: l_usbtrn_get_descriptor_00103: -;source-doc/base-drv/./protocol.c:45: } +;source-doc/base-drv/./protocol.c:45: return result; + ld hl,_result + ld l, (hl) +;source-doc/base-drv/./protocol.c:46: } ld sp, ix pop ix ret @@ -149,7 +149,7 @@ _cmd_get_device_descriptor: DEFB +0x00 DEFB +0x00 DEFW +0x0008 -;source-doc/base-drv/./protocol.c:53: usb_error usbtrn_get_descriptor2(device_descriptor *const buffer, const uint8_t device_address) { +;source-doc/base-drv/./protocol.c:54: usb_error usbtrn_get_descriptor2(device_descriptor *const buffer, const uint8_t device_address) { ; --------------------------------- ; Function usbtrn_get_descriptor2 ; --------------------------------- @@ -157,34 +157,33 @@ _usbtrn_get_descriptor2: push ix ld ix,0 add ix,sp - ld hl, -13 + ld hl, -8 add hl, sp ld sp, hl ;source-doc/base-drv/./protocol.c:56: cmd = cmd_get_device_descriptor; - ld hl,2 + ld hl,0 add hl, sp ex de, hl ld hl,_cmd_get_device_descriptor ld bc,0x0008 ldir ;source-doc/base-drv/./protocol.c:57: cmd.wLength = 8; - ld (ix-5),0x08 + ld (ix-2),0x08 xor a - ld (ix-4),a -;source-doc/base-drv/./protocol.c:59: result = usb_control_transfer(&cmd, (uint8_t *)buffer, device_address, 8); - ld a,(ix+4) - ld (ix-2),a - ld a,(ix+5) ld (ix-1),a - ld c,(ix-2) - ld b,(ix-1) +;source-doc/base-drv/./protocol.c:59: result = usb_control_transfer(&cmd, (uint8_t *)buffer, device_address, 8); + ld c,(ix+4) + ld b,(ix+5) + ld e, c + ld d, b + push bc ld a,0x08 push af inc sp ld a,(ix+6) push af inc sp - push bc + push de ld hl,6 add hl, sp push hl @@ -192,59 +191,57 @@ _usbtrn_get_descriptor2: pop af pop af pop af - ld (ix-12),l - ld (ix-3),l + pop bc + ld a, l + ld (_result), a ;source-doc/base-drv/./protocol.c:61: CHECK(result); - ld a,(ix-12) + ld a,(_result) or a - jr Z,l_usbtrn_get_descriptor2_00102 - ld l,(ix-3) - jr l_usbtrn_get_descriptor2_00103 -l_usbtrn_get_descriptor2_00102: + jr NZ,l_usbtrn_get_descriptor2_00103 ;source-doc/base-drv/./protocol.c:63: cmd = cmd_get_device_descriptor; - ex de, hl - ld hl,2 + ld hl,0 add hl, sp ex de, hl + push bc ld hl,_cmd_get_device_descriptor ld bc,0x0008 ldir + pop bc ;source-doc/base-drv/./protocol.c:64: cmd.wLength = 18; - ld (ix-5),0x12 + ld (ix-2),0x12 xor a - ld (ix-4),a + ld (ix-1),a ;source-doc/base-drv/./protocol.c:65: RETURN_CHECK(usb_control_transfer(&cmd, (uint8_t *)buffer, device_address, buffer->bMaxPacketSize0)); - ld a,(ix+4) - ld (ix-13),a - ld a,(ix+5) - ld (ix-12),a - pop hl - push hl - ld de,0x0007 + ld e,(ix+4) + ld d,(ix+5) + ld hl,7 add hl, de ld a, (hl) - ld (ix-3),a push af inc sp ld a,(ix+6) push af inc sp - ld l,(ix-2) - ld h,(ix-1) - push hl - ld hl,6 + push bc + ld hl,4 add hl, sp push hl call _usb_control_transfer pop af pop af pop af + ld a, l + ld (_result), a +;source-doc/base-drv/./protocol.c:66: done: l_usbtrn_get_descriptor2_00103: -;source-doc/base-drv/./protocol.c:66: } +;source-doc/base-drv/./protocol.c:67: return result; + ld hl,_result + ld l, (hl) +;source-doc/base-drv/./protocol.c:68: } ld sp, ix pop ix ret -;source-doc/base-drv/./protocol.c:76: usb_error usbtrn_set_address(const uint8_t device_address) __z88dk_fastcall { +;source-doc/base-drv/./protocol.c:78: usb_error usbtrn_set_address(const uint8_t device_address) __z88dk_fastcall { ; --------------------------------- ; Function usbtrn_set_address ; --------------------------------- @@ -257,7 +254,7 @@ _usbtrn_set_address: push af push af ld c, l -;source-doc/base-drv/./protocol.c:78: cmd = cmd_set_device_address; +;source-doc/base-drv/./protocol.c:80: cmd = cmd_set_device_address; ld hl,0 add hl, sp ex de, hl @@ -266,9 +263,9 @@ _usbtrn_set_address: ld bc,0x0008 ldir pop bc -;source-doc/base-drv/./protocol.c:79: cmd.bValue[0] = device_address; +;source-doc/base-drv/./protocol.c:81: cmd.bValue[0] = device_address; ld (ix-6),c -;source-doc/base-drv/./protocol.c:81: return usb_control_transfer(&cmd, 0, 0, 0); +;source-doc/base-drv/./protocol.c:83: return usb_control_transfer(&cmd, 0, 0, 0); xor a push af inc sp @@ -281,7 +278,7 @@ _usbtrn_set_address: add hl, sp push hl call _usb_control_transfer -;source-doc/base-drv/./protocol.c:82: } +;source-doc/base-drv/./protocol.c:84: } ld sp,ix pop ix ret @@ -293,7 +290,7 @@ _cmd_set_device_address: DEFB +0x00 DEFB +0x00 DEFW +0x0000 -;source-doc/base-drv/./protocol.c:92: usb_error usbtrn_set_configuration(const uint8_t device_address, const uint8_t max_packet_size, const uint8_t configuration) { +;source-doc/base-drv/./protocol.c:94: usb_error usbtrn_set_configuration(const uint8_t device_address, const uint8_t max_packet_size, const uint8_t configuration) { ; --------------------------------- ; Function usbtrn_set_configuration ; --------------------------------- @@ -304,7 +301,7 @@ _usbtrn_set_configuration: ld hl, -8 add hl, sp ld sp, hl -;source-doc/base-drv/./protocol.c:94: cmd = cmd_set_configuration; +;source-doc/base-drv/./protocol.c:96: cmd = cmd_set_configuration; ld hl,0 add hl, sp ld c, l @@ -316,10 +313,10 @@ _usbtrn_set_configuration: ld bc,0x0008 ldir pop bc -;source-doc/base-drv/./protocol.c:95: cmd.bValue[0] = configuration; +;source-doc/base-drv/./protocol.c:97: cmd.bValue[0] = configuration; ld a,(ix+6) ld (ix-6),a -;source-doc/base-drv/./protocol.c:97: return usb_control_transfer(&cmd, 0, device_address, max_packet_size); +;source-doc/base-drv/./protocol.c:99: return usb_control_transfer(&cmd, 0, device_address, max_packet_size); ld h,(ix+5) ld l,(ix+4) push hl @@ -327,7 +324,7 @@ _usbtrn_set_configuration: push hl push bc call _usb_control_transfer -;source-doc/base-drv/./protocol.c:98: } +;source-doc/base-drv/./protocol.c:100: } ld sp,ix pop ix ret @@ -339,7 +336,7 @@ _cmd_set_configuration: DEFB +0x00 DEFB +0x00 DEFW +0x0000 -;source-doc/base-drv/./protocol.c:112: usb_error usbtrn_get_config_descriptor(config_descriptor *const buffer, +;source-doc/base-drv/./protocol.c:114: usb_error usbtrn_get_config_descriptor(config_descriptor *const buffer, ; --------------------------------- ; Function usbtrn_get_config_descriptor ; --------------------------------- @@ -350,7 +347,7 @@ _usbtrn_get_config_descriptor: ld hl, -8 add hl, sp ld sp, hl -;source-doc/base-drv/./protocol.c:118: cmd = cmd_get_config_descriptor; +;source-doc/base-drv/./protocol.c:120: cmd = cmd_get_config_descriptor; ld hl,0 add hl, sp ld c, l @@ -362,14 +359,14 @@ _usbtrn_get_config_descriptor: ld bc,0x0008 ldir pop bc -;source-doc/base-drv/./protocol.c:119: cmd.bValue[0] = config_index; +;source-doc/base-drv/./protocol.c:121: cmd.bValue[0] = config_index; ld a,(ix+6) ld (ix-6),a -;source-doc/base-drv/./protocol.c:120: cmd.wLength = (uint16_t)buffer_size; +;source-doc/base-drv/./protocol.c:122: cmd.wLength = (uint16_t)buffer_size; ld e,(ix+7) ld (ix-2),e ld (ix-1),0x00 -;source-doc/base-drv/./protocol.c:122: RETURN_CHECK(usb_control_transfer(&cmd, (uint8_t *)buffer, device_address, max_packet_size)); +;source-doc/base-drv/./protocol.c:124: return usb_control_transfer(&cmd, (uint8_t *)buffer, device_address, max_packet_size); ld e,(ix+4) ld d,(ix+5) ld h,(ix+9) @@ -378,7 +375,7 @@ _usbtrn_get_config_descriptor: push de push bc call _usb_control_transfer -;source-doc/base-drv/./protocol.c:123: } +;source-doc/base-drv/./protocol.c:125: } ld sp,ix pop ix ret @@ -390,7 +387,7 @@ _cmd_get_config_descriptor: DEFB +0x00 DEFB +0x00 DEFW +0x0000 -;source-doc/base-drv/./protocol.c:125: usb_error usbtrn_gfull_cfg_desc(const uint8_t config_index, +;source-doc/base-drv/./protocol.c:127: usb_error usbtrn_gfull_cfg_desc(const uint8_t config_index, ; --------------------------------- ; Function usbtrn_gfull_cfg_desc ; --------------------------------- @@ -398,7 +395,7 @@ _usbtrn_gfull_cfg_desc: push ix ld ix,0 add ix,sp -;source-doc/base-drv/./protocol.c:133: max_packet_size)); +;source-doc/base-drv/./protocol.c:134: max_packet_size)); ld c,(ix+8) ld b,(ix+9) push bc @@ -418,22 +415,24 @@ _usbtrn_gfull_cfg_desc: pop af pop bc ld a, l + ld (_result), a + ld a,(_result) or a jr NZ,l_usbtrn_gfull_cfg_desc_00107 -;source-doc/base-drv/./protocol.c:135: uint8_t max_length = ((config_descriptor *)buffer)->wTotalLength; +;source-doc/base-drv/./protocol.c:136: uint8_t max_length = ((config_descriptor *)buffer)->wTotalLength; ld l, c ld h, b inc hl inc hl ld d, (hl) -;source-doc/base-drv/./protocol.c:136: if (max_length > max_buffer_size) +;source-doc/base-drv/./protocol.c:137: if (max_length > max_buffer_size) ld a,(ix+7) sub d jr NC,l_usbtrn_gfull_cfg_desc_00104 -;source-doc/base-drv/./protocol.c:137: max_length = max_buffer_size; +;source-doc/base-drv/./protocol.c:138: max_length = max_buffer_size; ld d,(ix+7) l_usbtrn_gfull_cfg_desc_00104: -;source-doc/base-drv/./protocol.c:139: CHECK(usbtrn_get_config_descriptor((config_descriptor *)buffer, config_index, max_length, device_address, max_packet_size)); +;source-doc/base-drv/./protocol.c:140: CHECK(usbtrn_get_config_descriptor((config_descriptor *)buffer, config_index, max_length, device_address, max_packet_size)); ld h,(ix+6) ld l,(ix+5) push hl @@ -448,15 +447,23 @@ l_usbtrn_gfull_cfg_desc_00104: pop af pop af ld a, l -;source-doc/base-drv/./protocol.c:141: return USB_ERR_OK; + ld (_result), a + ld a,(_result) +;source-doc/base-drv/./protocol.c:142: return USB_ERR_OK; or a jr NZ,l_usbtrn_gfull_cfg_desc_00107 ld l,a + jr l_usbtrn_gfull_cfg_desc_00108 +;source-doc/base-drv/./protocol.c:143: done: l_usbtrn_gfull_cfg_desc_00107: -;source-doc/base-drv/./protocol.c:142: } +;source-doc/base-drv/./protocol.c:144: return result; + ld hl,_result + ld l, (hl) +l_usbtrn_gfull_cfg_desc_00108: +;source-doc/base-drv/./protocol.c:145: } pop ix ret -;source-doc/base-drv/./protocol.c:146: usb_error usbtrn_clear_endpoint_halt(const uint8_t endpoint_number, const uint8_t device_address, const uint8_t max_packet_size) { +;source-doc/base-drv/./protocol.c:149: usb_error usbtrn_clear_endpoint_halt(const uint8_t endpoint_number, const uint8_t device_address, const uint8_t max_packet_size) { ; --------------------------------- ; Function usbtrn_clear_endpoint_halt ; --------------------------------- @@ -467,7 +474,7 @@ _usbtrn_clear_endpoint_halt: ld hl, -8 add hl, sp ld sp, hl -;source-doc/base-drv/./protocol.c:148: cmd = usb_cmd_clear_endpoint_halt; +;source-doc/base-drv/./protocol.c:151: cmd = usb_cmd_clear_endpoint_halt; ld hl,0 add hl, sp ld c, l @@ -479,10 +486,10 @@ _usbtrn_clear_endpoint_halt: ld bc,0x0008 ldir pop bc -;source-doc/base-drv/./protocol.c:149: cmd.bIndex[0] = endpoint_number; +;source-doc/base-drv/./protocol.c:152: cmd.bIndex[0] = endpoint_number; ld a,(ix+4) ld (ix-4),a -;source-doc/base-drv/./protocol.c:151: usb_error result = usb_control_transfer(&cmd, (uint8_t *)0, device_address, max_packet_size); +;source-doc/base-drv/./protocol.c:154: return usb_control_transfer(&cmd, (uint8_t *)0, device_address, max_packet_size); ld h,(ix+6) ld l,(ix+5) push hl @@ -490,8 +497,7 @@ _usbtrn_clear_endpoint_halt: push hl push bc call _usb_control_transfer -;source-doc/base-drv/./protocol.c:153: RETURN_CHECK(result); -;source-doc/base-drv/./protocol.c:154: } +;source-doc/base-drv/./protocol.c:155: } ld sp,ix pop ix ret diff --git a/Source/HBIOS/ch376-native/base-drv/transfers.c.s b/Source/HBIOS/ch376-native/base-drv/transfers.c.s index a080f748..199747fe 100644 --- a/Source/HBIOS/ch376-native/base-drv/transfers.c.s +++ b/Source/HBIOS/ch376-native/base-drv/transfers.c.s @@ -139,14 +139,15 @@ _usb_control_transfer: jr NZ,l_usb_control_transfer_00102 ;source-doc/base-drv/./transfers.c:57: return USB_ERR_OTHER; ld l,0x0f - jp l_usb_control_transfer_00113 + jp l_usb_control_transfer_00114 l_usb_control_transfer_00102: -;source-doc/base-drv/./transfers.c:59: ch_set_usb_address(device_address); +;source-doc/base-drv/./transfers.c:59: critical_begin(); push bc + call _critical_begin ld l,(ix+8) call _ch_set_usb_address pop bc -;source-doc/base-drv/./transfers.c:61: ch_write_data((const uint8_t *)cmd_packet, sizeof(setup_packet)); +;source-doc/base-drv/./transfers.c:63: ch_write_data((const uint8_t *)cmd_packet, sizeof(setup_packet)); ld e,(ix+4) ld d,(ix+5) push bc @@ -160,25 +161,25 @@ l_usb_control_transfer_00102: call _ch_issue_token_setup call _ch_short_wait_int_and_get_stat pop bc -;source-doc/base-drv/./transfers.c:64: CHECK(result); +;source-doc/base-drv/./transfers.c:66: CHECK(result); ld a, l or a jr NZ,l_usb_control_transfer_00113 -;source-doc/base-drv/./transfers.c:66: const uint16_t length = cmd_packet->wLength; +;source-doc/base-drv/./transfers.c:68: const uint16_t length = cmd_packet->wLength; ld hl,6 add hl, bc ld c, (hl) inc hl ld b, (hl) -;source-doc/base-drv/./transfers.c:69: ? (transferIn ? ch_data_in_transfer(buffer, length, &endpoint) : ch_data_out_transfer(buffer, length, &endpoint)) +;source-doc/base-drv/./transfers.c:71: ? (transferIn ? ch_data_in_transfer(buffer, length, &endpoint) : ch_data_out_transfer(buffer, length, &endpoint)) ld a, b or c - jr Z,l_usb_control_transfer_00115 + jr Z,l_usb_control_transfer_00116 ld e,(ix+6) ld d,(ix+7) ld a,(ix-1) or a - jr Z,l_usb_control_transfer_00117 + jr Z,l_usb_control_transfer_00118 ld hl,0 add hl, sp push hl @@ -188,8 +189,8 @@ l_usb_control_transfer_00102: pop af pop af pop af - jr l_usb_control_transfer_00118 -l_usb_control_transfer_00117: + jr l_usb_control_transfer_00119 +l_usb_control_transfer_00118: ld hl,0 add hl, sp push hl @@ -199,59 +200,62 @@ l_usb_control_transfer_00117: pop af pop af pop af -l_usb_control_transfer_00118: - jr l_usb_control_transfer_00116 -l_usb_control_transfer_00115: -;source-doc/base-drv/./transfers.c:70: : USB_ERR_OK; - ld l,0x00 +l_usb_control_transfer_00119: + jr l_usb_control_transfer_00117 l_usb_control_transfer_00116: -;source-doc/base-drv/./transfers.c:72: CHECK(result) +;source-doc/base-drv/./transfers.c:72: : USB_ERR_OK; + ld l,0x00 +l_usb_control_transfer_00117: +;source-doc/base-drv/./transfers.c:74: CHECK(result) ld a, l or a jr NZ,l_usb_control_transfer_00113 -;source-doc/base-drv/./transfers.c:74: if (transferIn) { +;source-doc/base-drv/./transfers.c:76: if (transferIn) { ld a,(ix-1) or a jr Z,l_usb_control_transfer_00112 -;source-doc/base-drv/./transfers.c:75: ch_command(CH_CMD_WR_HOST_DATA); +;source-doc/base-drv/./transfers.c:77: ch_command(CH_CMD_WR_HOST_DATA); ld l,0x2c call _ch_command -;source-doc/base-drv/./transfers.c:76: CH376_DATA_PORT = 0; +;source-doc/base-drv/./transfers.c:78: CH376_DATA_PORT = 0; ld a,0x00 ld bc,_CH376_DATA_PORT out (c),a -;source-doc/base-drv/./transfers.c:77: delay(); - call _delay -;source-doc/base-drv/./transfers.c:78: ch_issue_token_out_ep0(); +;source-doc/base-drv/./transfers.c:79: ch_issue_token_out_ep0(); call _ch_issue_token_out_ep0 -;source-doc/base-drv/./transfers.c:79: result = ch_long_wait_int_and_get_status(); /* sometimes we get STALL here - seems to be ok to ignore */ +;source-doc/base-drv/./transfers.c:80: result = ch_long_wait_int_and_get_status(); /* sometimes we get STALL here - seems to be ok to ignore */ call _ch_long_wait_int_and_get_statu -;source-doc/base-drv/./transfers.c:81: if (result == USB_ERR_OK || result == USB_ERR_STALL) +;source-doc/base-drv/./transfers.c:82: if (result == USB_ERR_OK || result == USB_ERR_STALL) { ld a, l or a jr Z,l_usb_control_transfer_00108 ld a, l sub 0x02 - jr NZ,l_usb_control_transfer_00109 + jr NZ,l_usb_control_transfer_00113 l_usb_control_transfer_00108: -;source-doc/base-drv/./transfers.c:82: return USB_ERR_OK; +;source-doc/base-drv/./transfers.c:83: result = USB_ERR_OK; ld l,0x00 +;source-doc/base-drv/./transfers.c:84: goto done; jr l_usb_control_transfer_00113 -l_usb_control_transfer_00109: -;source-doc/base-drv/./transfers.c:84: RETURN_CHECK(result); - jr l_usb_control_transfer_00113 +;source-doc/base-drv/./transfers.c:87: RETURN_CHECK(result); l_usb_control_transfer_00112: -;source-doc/base-drv/./transfers.c:87: ch_issue_token_in_ep0(); +;source-doc/base-drv/./transfers.c:90: ch_issue_token_in_ep0(); call _ch_issue_token_in_ep0 -;source-doc/base-drv/./transfers.c:88: result = ch_long_wait_int_and_get_status(); +;source-doc/base-drv/./transfers.c:91: result = ch_long_wait_int_and_get_status(); call _ch_long_wait_int_and_get_statu -;source-doc/base-drv/./transfers.c:90: RETURN_CHECK(result); +;source-doc/base-drv/./transfers.c:95: done: l_usb_control_transfer_00113: -;source-doc/base-drv/./transfers.c:91: } +;source-doc/base-drv/./transfers.c:96: critical_end(); + push hl + call _critical_end + pop hl +;source-doc/base-drv/./transfers.c:97: return result; +l_usb_control_transfer_00114: +;source-doc/base-drv/./transfers.c:98: } ld sp, ix pop ix ret -;source-doc/base-drv/./transfers.c:94: usb_dat_in_trnsfer_ext(uint8_t *buffer, const uint16_t buffer_size, const uint8_t device_address, endpoint_param *const endpoint) { +;source-doc/base-drv/./transfers.c:101: usb_dat_in_trnsfer_ext(uint8_t *buffer, const uint16_t buffer_size, const uint8_t device_address, endpoint_param *const endpoint) { ; --------------------------------- ; Function usb_dat_in_trnsfer_ext ; --------------------------------- @@ -259,26 +263,26 @@ _usb_dat_in_trnsfer_ext: push ix ld ix,0 add ix,sp -;source-doc/base-drv/./transfers.c:95: if (buffer != 0 && (uint16_t)buffer < LOWER_SAFE_RAM_ADDRESS) +;source-doc/base-drv/./transfers.c:102: if (buffer != 0 && (uint16_t)buffer < LOWER_SAFE_RAM_ADDRESS) ld a,(ix+5) or (ix+4) jr Z,l_usb_dat_in_trnsfer_ext_00102 ld a,(ix+5) sub 0x80 jr NC,l_usb_dat_in_trnsfer_ext_00102 -;source-doc/base-drv/./transfers.c:96: return USB_BAD_ADDRESS; +;source-doc/base-drv/./transfers.c:103: return USB_BAD_ADDRESS; ld l,0x82 jr l_usb_dat_in_trnsfer_ext_00106 l_usb_dat_in_trnsfer_ext_00102: -;source-doc/base-drv/./transfers.c:98: if ((uint16_t)endpoint < LOWER_SAFE_RAM_ADDRESS) +;source-doc/base-drv/./transfers.c:105: if ((uint16_t)endpoint < LOWER_SAFE_RAM_ADDRESS) ld a,(ix+10) sub 0x80 jr NC,l_usb_dat_in_trnsfer_ext_00105 -;source-doc/base-drv/./transfers.c:99: return USB_BAD_ADDRESS; +;source-doc/base-drv/./transfers.c:106: return USB_BAD_ADDRESS; ld l,0x82 jr l_usb_dat_in_trnsfer_ext_00106 l_usb_dat_in_trnsfer_ext_00105: -;source-doc/base-drv/./transfers.c:101: return usb_data_in_transfer(buffer, buffer_size, device_address, endpoint); +;source-doc/base-drv/./transfers.c:108: return usb_data_in_transfer(buffer, buffer_size, device_address, endpoint); ld l,(ix+9) ld h,(ix+10) push hl @@ -297,10 +301,10 @@ l_usb_dat_in_trnsfer_ext_00105: pop af inc sp l_usb_dat_in_trnsfer_ext_00106: -;source-doc/base-drv/./transfers.c:102: } +;source-doc/base-drv/./transfers.c:109: } pop ix ret -;source-doc/base-drv/./transfers.c:105: usb_dat_in_trns_n_ext(uint8_t *buffer, uint16_t *buffer_size, const uint8_t device_address, endpoint_param *const endpoint) { +;source-doc/base-drv/./transfers.c:112: usb_dat_in_trns_n_ext(uint8_t *buffer, uint16_t *buffer_size, const uint8_t device_address, endpoint_param *const endpoint) { ; --------------------------------- ; Function usb_dat_in_trns_n_ext ; --------------------------------- @@ -308,34 +312,34 @@ _usb_dat_in_trns_n_ext: push ix ld ix,0 add ix,sp -;source-doc/base-drv/./transfers.c:106: if (buffer != 0 && ((uint16_t)buffer & 0xC000) == 0) +;source-doc/base-drv/./transfers.c:113: if (buffer != 0 && ((uint16_t)buffer & 0xC000) == 0) ld a,(ix+5) or (ix+4) jr Z,l_usb_dat_in_trns_n_ext_00102 ld a,(ix+5) and 0xc0 jr NZ,l_usb_dat_in_trns_n_ext_00102 -;source-doc/base-drv/./transfers.c:107: return USB_BAD_ADDRESS; +;source-doc/base-drv/./transfers.c:114: return USB_BAD_ADDRESS; ld l,0x82 jr l_usb_dat_in_trns_n_ext_00108 l_usb_dat_in_trns_n_ext_00102: -;source-doc/base-drv/./transfers.c:109: if (((uint16_t)endpoint & 0xC000) == 0) +;source-doc/base-drv/./transfers.c:116: if (((uint16_t)endpoint & 0xC000) == 0) ld a,(ix+10) and 0xc0 jr NZ,l_usb_dat_in_trns_n_ext_00105 -;source-doc/base-drv/./transfers.c:110: return USB_BAD_ADDRESS; +;source-doc/base-drv/./transfers.c:117: return USB_BAD_ADDRESS; ld l,0x82 jr l_usb_dat_in_trns_n_ext_00108 l_usb_dat_in_trns_n_ext_00105: -;source-doc/base-drv/./transfers.c:112: if (((uint16_t)buffer_size & 0xC000) == 0) +;source-doc/base-drv/./transfers.c:119: if (((uint16_t)buffer_size & 0xC000) == 0) ld a,(ix+7) and 0xc0 jr NZ,l_usb_dat_in_trns_n_ext_00107 -;source-doc/base-drv/./transfers.c:113: return USB_BAD_ADDRESS; +;source-doc/base-drv/./transfers.c:120: return USB_BAD_ADDRESS; ld l,0x82 jr l_usb_dat_in_trns_n_ext_00108 l_usb_dat_in_trns_n_ext_00107: -;source-doc/base-drv/./transfers.c:115: return usb_data_in_transfer_n(buffer, buffer_size, device_address, endpoint); +;source-doc/base-drv/./transfers.c:122: return usb_data_in_transfer_n(buffer, buffer_size, device_address, endpoint); ld c,(ix+6) ld b,(ix+7) ld l,(ix+9) @@ -354,10 +358,10 @@ l_usb_dat_in_trns_n_ext_00107: pop af inc sp l_usb_dat_in_trns_n_ext_00108: -;source-doc/base-drv/./transfers.c:116: } +;source-doc/base-drv/./transfers.c:123: } pop ix ret -;source-doc/base-drv/./transfers.c:128: usb_data_in_transfer(uint8_t *buffer, const uint16_t buffer_size, const uint8_t device_address, endpoint_param *const endpoint) { +;source-doc/base-drv/./transfers.c:135: usb_data_in_transfer(uint8_t *buffer, const uint16_t buffer_size, const uint8_t device_address, endpoint_param *const endpoint) { ; --------------------------------- ; Function usb_data_in_transfer ; --------------------------------- @@ -365,10 +369,12 @@ _usb_data_in_transfer: push ix ld ix,0 add ix,sp -;source-doc/base-drv/./transfers.c:129: ch_set_usb_address(device_address); +;source-doc/base-drv/./transfers.c:136: critical_begin(); + call _critical_begin +;source-doc/base-drv/./transfers.c:138: ch_set_usb_address(device_address); ld l,(ix+8) call _ch_set_usb_address -;source-doc/base-drv/./transfers.c:131: return ch_data_in_transfer(buffer, buffer_size, endpoint); +;source-doc/base-drv/./transfers.c:140: result = ch_data_in_transfer(buffer, buffer_size, endpoint); ld l,(ix+9) ld h,(ix+10) push hl @@ -382,10 +388,17 @@ _usb_data_in_transfer: pop af pop af pop af -;source-doc/base-drv/./transfers.c:132: } + ld a, l + ld (_result), a +;source-doc/base-drv/./transfers.c:142: critical_end(); + call _critical_end +;source-doc/base-drv/./transfers.c:144: return result; + ld hl,_result + ld l, (hl) +;source-doc/base-drv/./transfers.c:145: } pop ix ret -;source-doc/base-drv/./transfers.c:144: usb_data_in_transfer_n(uint8_t *buffer, uint8_t *const buffer_size, const uint8_t device_address, endpoint_param *const endpoint) { +;source-doc/base-drv/./transfers.c:157: usb_data_in_transfer_n(uint8_t *buffer, uint8_t *const buffer_size, const uint8_t device_address, endpoint_param *const endpoint) { ; --------------------------------- ; Function usb_data_in_transfer_n ; --------------------------------- @@ -393,10 +406,12 @@ _usb_data_in_transfer_n: push ix ld ix,0 add ix,sp -;source-doc/base-drv/./transfers.c:145: ch_set_usb_address(device_address); +;source-doc/base-drv/./transfers.c:158: critical_begin(); + call _critical_begin +;source-doc/base-drv/./transfers.c:160: ch_set_usb_address(device_address); ld l,(ix+8) call _ch_set_usb_address -;source-doc/base-drv/./transfers.c:147: return ch_data_in_transfer_n(buffer, buffer_size, endpoint); +;source-doc/base-drv/./transfers.c:162: result = ch_data_in_transfer_n(buffer, buffer_size, endpoint); ld l,(ix+9) ld h,(ix+10) push hl @@ -410,59 +425,17 @@ _usb_data_in_transfer_n: pop af pop af pop af -;source-doc/base-drv/./transfers.c:148: } - pop ix - ret -;source-doc/base-drv/./transfers.c:151: usb_dat_out_trns_ext(const uint8_t *buffer, uint16_t buffer_size, const uint8_t device_address, endpoint_param *const endpoint) { -; --------------------------------- -; Function usb_dat_out_trns_ext -; --------------------------------- -_usb_dat_out_trns_ext: - push ix - ld ix,0 - add ix,sp -;source-doc/base-drv/./transfers.c:153: if (buffer != 0 && (uint16_t)buffer < LOWER_SAFE_RAM_ADDRESS) - ld a,(ix+5) - or (ix+4) - jr Z,l_usb_dat_out_trns_ext_00102 - ld a,(ix+5) - sub 0x80 - jr NC,l_usb_dat_out_trns_ext_00102 -;source-doc/base-drv/./transfers.c:154: return USB_BAD_ADDRESS; - ld l,0x82 - jr l_usb_dat_out_trns_ext_00106 -l_usb_dat_out_trns_ext_00102: -;source-doc/base-drv/./transfers.c:156: if ((uint16_t)endpoint < LOWER_SAFE_RAM_ADDRESS) - ld a,(ix+10) - sub 0x80 - jr NC,l_usb_dat_out_trns_ext_00105 -;source-doc/base-drv/./transfers.c:157: return USB_BAD_ADDRESS; - ld l,0x82 - jr l_usb_dat_out_trns_ext_00106 -l_usb_dat_out_trns_ext_00105: -;source-doc/base-drv/./transfers.c:159: return usb_data_out_transfer(buffer, buffer_size, device_address, endpoint); - ld l,(ix+9) - ld h,(ix+10) - push hl - ld a,(ix+8) - push af - inc sp - ld l,(ix+6) - ld h,(ix+7) - push hl - ld l,(ix+4) - ld h,(ix+5) - push hl - call _usb_data_out_transfer - pop af - pop af - pop af - inc sp -l_usb_dat_out_trns_ext_00106: -;source-doc/base-drv/./transfers.c:160: } + ld a, l + ld (_result), a +;source-doc/base-drv/./transfers.c:164: critical_end(); + call _critical_end +;source-doc/base-drv/./transfers.c:166: return result; + ld hl,_result + ld l, (hl) +;source-doc/base-drv/./transfers.c:167: } pop ix ret -;source-doc/base-drv/./transfers.c:172: usb_data_out_transfer(const uint8_t *buffer, uint16_t buffer_size, const uint8_t device_address, endpoint_param *const endpoint) { +;source-doc/base-drv/./transfers.c:179: usb_data_out_transfer(const uint8_t *buffer, uint16_t buffer_size, const uint8_t device_address, endpoint_param *const endpoint) { ; --------------------------------- ; Function usb_data_out_transfer ; --------------------------------- @@ -470,10 +443,12 @@ _usb_data_out_transfer: push ix ld ix,0 add ix,sp -;source-doc/base-drv/./transfers.c:173: ch_set_usb_address(device_address); +;source-doc/base-drv/./transfers.c:180: critical_begin(); + call _critical_begin +;source-doc/base-drv/./transfers.c:182: ch_set_usb_address(device_address); ld l,(ix+8) call _ch_set_usb_address -;source-doc/base-drv/./transfers.c:175: return ch_data_out_transfer(buffer, buffer_size, endpoint); +;source-doc/base-drv/./transfers.c:184: result = ch_data_out_transfer(buffer, buffer_size, endpoint); ld l,(ix+9) ld h,(ix+10) push hl @@ -487,6 +462,13 @@ _usb_data_out_transfer: pop af pop af pop af -;source-doc/base-drv/./transfers.c:176: } + ld a, l + ld (_result), a +;source-doc/base-drv/./transfers.c:186: critical_end(); + call _critical_end +;source-doc/base-drv/./transfers.c:188: return result; + ld hl,_result + ld l, (hl) +;source-doc/base-drv/./transfers.c:189: } pop ix ret diff --git a/Source/HBIOS/ch376-native/base-drv/usb-init.c.s b/Source/HBIOS/ch376-native/base-drv/usb-init.c.s index 5145ebfc..625480b2 100644 --- a/Source/HBIOS/ch376-native/base-drv/usb-init.c.s +++ b/Source/HBIOS/ch376-native/base-drv/usb-init.c.s @@ -68,21 +68,17 @@ _usb_host_bus_reset: call _ch_cmd_set_usb_mode ;source-doc/base-drv/./usb-init.c:16: delay_20ms(); call _delay_20ms -;source-doc/base-drv/./ch376.h:160: ch_command(CH_CMD_WRITE_VAR8); +;source-doc/base-drv/./ch376.h:163: ch_command(CH_CMD_WRITE_VAR8); ld l,0x0b call _ch_command -;source-doc/base-drv/./ch376.h:161: CH376_DATA_PORT = CH_VAR_RETRY_TIMES; +;source-doc/base-drv/./ch376.h:164: CH376_DATA_PORT = CH_VAR_RETRY_TIMES; ld a,0x25 ld bc,_CH376_DATA_PORT out (c),a -;source-doc/base-drv/./ch376.h:162: delay(); - call _delay -;source-doc/base-drv/./ch376.h:163: CH376_DATA_PORT = retry << 6 | (number_of_retries & 0x1F); +;source-doc/base-drv/./ch376.h:165: CH376_DATA_PORT = retry << 6 | (number_of_retries & 0x1F); ld a,0xdf ld bc,_CH376_DATA_PORT out (c),a -;source-doc/base-drv/./ch376.h:164: delay(); - call _delay ;source-doc/base-drv/./usb-init.c:20: return USB_ERR_OK; ld l,0x00 ;source-doc/base-drv/./usb-init.c:21: } diff --git a/Source/HBIOS/ch376-native/cruntime.asm b/Source/HBIOS/ch376-native/cruntime.asm index 29e2060e..85904a82 100644 --- a/Source/HBIOS/ch376-native/cruntime.asm +++ b/Source/HBIOS/ch376-native/cruntime.asm @@ -27,26 +27,6 @@ _memset_callee: pop hl ret -; _strlen_fastcall: - -; ; enter: hl = char *s -; ; -; ; exit : hl = length -; ; bc = -(length + 1) -; ; a = 0 -; ; z flag set if 0 length -; ; carry reset -; ; -; ; uses : af, bc, hl - -; xor a -; ld c,a -; ld b,a -; cpir -; ld hl,$ffff -; sbc hl,bc - -; ret _memcpy_callee: @@ -84,51 +64,83 @@ zero_n: pop hl ret -; _strcat_callee: -; pop hl -; pop de -; ex (sp),hl +; ; =============================================================== +; ; Stefano Bodrato +; ; aralbrec: accommodate nmos z80 bug +; ; =============================================================== +; ; +; ; void z80_push_di(void) +; ; +; ; Save the current ei/di status on the stack and disable ints. +; ; +; ; =============================================================== - -; ; enter : hl = char *s2 = src -; ; de = char *s1 = dst -; ; -; ; exit : hl = char *s1 = dst -; ; de = ptr in s1 to terminating 0 +; ____sdcc_cpu_push_di: + +; ; exit : stack = ei_di_status ; ; -; ; uses : af, bc, de, hl +; ; uses : af -; push de ; save dst +; ex (sp),hl +; push hl + +; ld a,i + +; di + +; push af +; pop hl ; hl = ei_di status + +; pop af ; af = ret +; ex (sp),hl ; restore hl, push ei_di_status + +; push af -; ex de,hl -; call __str_locate_nul ; a = 0 -; ex de,hl +; ret -; loop: ; append s2 to s1 -; cp (hl) -; ldi -; jr NZ,loop -; ENDIF +; ; =============================================================== +; ; Stefano Bodrato +; ; =============================================================== +; ; +; ; void z80_pop_ei(void) +; ; +; ; Pop the ei_di_status from the stack and restore the di/ei +; ; state to what it was previously when a push was called. +; ; +; ; The "ei" in the function name has no bearing on what the +; ; function does; the name is meant to balance "z80_push_di". +; ; +; ; =============================================================== -; pop hl ; hl = dst -; dec de -; ret +; ____sdcc_cpu_pop_ei: -; __str_locate_nul: -; ; enter : hl = char *s +; ; enter : stack = ei_di_status, ret ; ; -; ; exit : hl = ptr in s to terminating 0 -; ; bc = -(strlen + 1) -; ; a = 0 -; ; carry reset +; ; uses : af + +; ex (sp),hl +; pop af ; af = old hl + +; ex (sp),hl ; hl = ei_di_status +; push af + +; ex (sp),hl ; hl restored + +; ____sdcc_cpu_pop_ei_jp: +; ; enter : stack = ret, ei_di_status ; ; -; ; uses : af, bc, hl +; ; uses : af + +; pop af ; af = ei_di_status + +; jp PO, di_state + +; ei_state: +; ei +; ret -; xor a -; ld c,a -; ld b,a -; cpir -; dec hl +; di_state: +; di ; ret diff --git a/Source/HBIOS/ch376-native/keyboard.s b/Source/HBIOS/ch376-native/keyboard.s index 5e459709..cc9a7b76 100644 --- a/Source/HBIOS/ch376-native/keyboard.s +++ b/Source/HBIOS/ch376-native/keyboard.s @@ -1,3 +1,4 @@ ; Generated File -- not to be modify directly #include "ch376-native/keyboard/kyb-init.c.s" #include "ch376-native/keyboard/class_hid.c.s" +#include "ch376-native/keyboard/class_hid_keyboard.c.s" diff --git a/Source/HBIOS/ch376-native/keyboard/class_hid.c.s b/Source/HBIOS/ch376-native/keyboard/class_hid.c.s index 38fa0e15..73072f3e 100644 --- a/Source/HBIOS/ch376-native/keyboard/class_hid.c.s +++ b/Source/HBIOS/ch376-native/keyboard/class_hid.c.s @@ -61,7 +61,7 @@ _hid_set_protocol: push af push af ex de, hl -;source-doc/keyboard/./class_hid.c:9: cmd = cmd_hid_set; +;source-doc/keyboard/./class_hid.c:8: cmd = cmd_hid_set; push de ex de, hl ld hl,2 @@ -71,12 +71,12 @@ _hid_set_protocol: ld bc,0x0008 ldir pop de -;source-doc/keyboard/./class_hid.c:11: cmd.bRequest = HID_SET_PROTOCOL; +;source-doc/keyboard/./class_hid.c:10: cmd.bRequest = HID_SET_PROTOCOL; ld (ix-7),0x0b -;source-doc/keyboard/./class_hid.c:12: cmd.bValue[0] = protocol; +;source-doc/keyboard/./class_hid.c:11: cmd.bValue[0] = protocol; ld a,(ix+4) ld (ix-6),a -;source-doc/keyboard/./class_hid.c:14: result = usb_control_transfer(&cmd, NULL, dev->address, dev->max_packet_size); +;source-doc/keyboard/./class_hid.c:13: return usb_control_transfer(&cmd, NULL, dev->address, dev->max_packet_size); ld l, e ld h, d inc hl @@ -103,8 +103,7 @@ _hid_set_protocol: pop af pop af ld a, l -;source-doc/keyboard/./class_hid.c:16: RETURN_CHECK(result); -;source-doc/keyboard/./class_hid.c:17: } +;source-doc/keyboard/./class_hid.c:14: } ld sp, ix pop ix pop hl @@ -118,7 +117,7 @@ _cmd_hid_set: DEFB +0x00 DEFB +0x00 DEFW +0x0000 -;source-doc/keyboard/./class_hid.c:19: usb_error hid_set_idle(const device_config_keyboard *const dev, const uint8_t duration) __sdcccall(1) { +;source-doc/keyboard/./class_hid.c:16: usb_error hid_set_idle(const device_config_keyboard *const dev, const uint8_t duration) __sdcccall(1) { ; --------------------------------- ; Function hid_set_idle ; --------------------------------- @@ -131,7 +130,7 @@ _hid_set_idle: push af push af ex de, hl -;source-doc/keyboard/./class_hid.c:22: cmd = cmd_hid_set; +;source-doc/keyboard/./class_hid.c:18: cmd = cmd_hid_set; push de ex de, hl ld hl,2 @@ -141,12 +140,12 @@ _hid_set_idle: ld bc,0x0008 ldir pop de -;source-doc/keyboard/./class_hid.c:24: cmd.bRequest = HID_SET_IDLE; +;source-doc/keyboard/./class_hid.c:20: cmd.bRequest = HID_SET_IDLE; ld (ix-7),0x0a -;source-doc/keyboard/./class_hid.c:25: cmd.bValue[0] = duration; +;source-doc/keyboard/./class_hid.c:21: cmd.bValue[0] = duration; ld a,(ix+4) ld (ix-6),a -;source-doc/keyboard/./class_hid.c:27: result = usb_control_transfer(&cmd, NULL, dev->address, dev->max_packet_size); +;source-doc/keyboard/./class_hid.c:23: return usb_control_transfer(&cmd, NULL, dev->address, dev->max_packet_size); ld l, e ld h, d inc hl @@ -173,14 +172,13 @@ _hid_set_idle: pop af pop af ld a, l -;source-doc/keyboard/./class_hid.c:29: RETURN_CHECK(result); -;source-doc/keyboard/./class_hid.c:30: } +;source-doc/keyboard/./class_hid.c:24: } ld sp, ix pop ix pop hl inc sp jp (hl) -;source-doc/keyboard/./class_hid.c:32: usb_error hid_get_input_report(const device_config_keyboard *const dev, uint8_t const *report) __sdcccall(1) { +;source-doc/keyboard/./class_hid.c:26: usb_error hid_get_input_report(const device_config_keyboard *const dev, uint8_t const *report) __sdcccall(1) { ; --------------------------------- ; Function hid_get_input_report ; --------------------------------- @@ -195,7 +193,7 @@ _hid_get_input_report: ld sp, hl ld l, c ld h, b -;source-doc/keyboard/./class_hid.c:35: cmd = cmd_hid_set; +;source-doc/keyboard/./class_hid.c:28: cmd = cmd_hid_set; push de push hl ex de, hl @@ -207,19 +205,19 @@ _hid_get_input_report: ldir pop bc pop de -;source-doc/keyboard/./class_hid.c:37: cmd.bmRequestType = 0xA1; +;source-doc/keyboard/./class_hid.c:30: cmd.bmRequestType = 0xA1; ld (ix-9),0xa1 -;source-doc/keyboard/./class_hid.c:38: cmd.bValue[0] = 1; +;source-doc/keyboard/./class_hid.c:31: cmd.bValue[0] = 1; ld (ix-7),0x01 -;source-doc/keyboard/./class_hid.c:39: cmd.bValue[1] = 1; +;source-doc/keyboard/./class_hid.c:32: cmd.bValue[1] = 1; ld (ix-6),0x01 -;source-doc/keyboard/./class_hid.c:40: cmd.bRequest = HID_GET_REPORT; +;source-doc/keyboard/./class_hid.c:33: cmd.bRequest = HID_GET_REPORT; ld (ix-8),0x01 -;source-doc/keyboard/./class_hid.c:41: cmd.wLength = 8; +;source-doc/keyboard/./class_hid.c:34: cmd.wLength = 8; ld (ix-3),0x08 xor a ld (ix-2),a -;source-doc/keyboard/./class_hid.c:43: result = usb_control_transfer(&cmd, report, dev->address, dev->max_packet_size); +;source-doc/keyboard/./class_hid.c:36: return usb_control_transfer(&cmd, report, dev->address, dev->max_packet_size); ld l, c ld h, b inc hl @@ -247,8 +245,7 @@ _hid_get_input_report: pop af pop af ld a, l -;source-doc/keyboard/./class_hid.c:45: RETURN_CHECK(result); -;source-doc/keyboard/./class_hid.c:46: } +;source-doc/keyboard/./class_hid.c:37: } ld sp, ix pop ix ret diff --git a/Source/HBIOS/ch376-native/keyboard/class_hid_keyboard.c.s b/Source/HBIOS/ch376-native/keyboard/class_hid_keyboard.c.s new file mode 100644 index 00000000..84695f4c --- /dev/null +++ b/Source/HBIOS/ch376-native/keyboard/class_hid_keyboard.c.s @@ -0,0 +1,343 @@ +; +; Generated from source-doc/keyboard/./class_hid_keyboard.c.asm -- not to be modify directly +; +; +;-------------------------------------------------------- +; File Created by SDCC : free open source ISO C Compiler +; Version 4.4.0 #14648 (Linux) +;-------------------------------------------------------- +; Processed by Z88DK +;-------------------------------------------------------- + + +;-------------------------------------------------------- +; Public variables in this module +;-------------------------------------------------------- +;-------------------------------------------------------- +; Externals used +;-------------------------------------------------------- +;-------------------------------------------------------- +; special function registers +;-------------------------------------------------------- +;-------------------------------------------------------- +; ram data +;-------------------------------------------------------- +;-------------------------------------------------------- +; ram data +;-------------------------------------------------------- + +#IF 0 + +; .area _INITIALIZED removed by z88dk + +_scancodes_shift_table: + DEFS 128 +_scancodes_table: + DEFS 128 + +#ENDIF + +;-------------------------------------------------------- +; absolute external ram data +;-------------------------------------------------------- +;-------------------------------------------------------- +; global & static initialisations +;-------------------------------------------------------- +;-------------------------------------------------------- +; Home +;-------------------------------------------------------- +;-------------------------------------------------------- +; code +;-------------------------------------------------------- +;source-doc/keyboard/./class_hid_keyboard.c:335: char scancode_to_char(const uint8_t modifier_keys, const uint8_t code) __sdcccall(1) { +; --------------------------------- +; Function scancode_to_char +; --------------------------------- +_scancode_to_char: + ld c, a + ld e, l +;source-doc/keyboard/./class_hid_keyboard.c:336: if (code >= 0x80) + ld a, e + sub 0x80 + jr C,l_scancode_to_char_00102 +;source-doc/keyboard/./class_hid_keyboard.c:337: return 0; + xor a + jr l_scancode_to_char_00105 +l_scancode_to_char_00102: +;source-doc/keyboard/./class_hid_keyboard.c:339: if (modifier_keys & (KEY_MOD_LSHIFT | KEY_MOD_RSHIFT)) + ld a, c + and 0x22 + jr Z,l_scancode_to_char_00104 +;source-doc/keyboard/./class_hid_keyboard.c:340: return scancodes_shift_table[code]; + ld hl,_scancodes_shift_table + ld d,0x00 + add hl, de + ld a, (hl) + jr l_scancode_to_char_00105 +l_scancode_to_char_00104: +;source-doc/keyboard/./class_hid_keyboard.c:342: return scancodes_table[code]; + ld hl,_scancodes_table + ld d,0x00 + add hl, de + ld a, (hl) +l_scancode_to_char_00105: +;source-doc/keyboard/./class_hid_keyboard.c:343: } + ret +_scancodes_shift_table: + DEFB +0x00 + DEFB +0x00 + DEFB +0x00 + DEFB +0x00 + DEFB +0x41 + DEFB +0x42 + DEFB +0x43 + DEFB +0x44 + DEFB +0x45 + DEFB +0x46 + DEFB +0x47 + DEFB +0x48 + DEFB +0x49 + DEFB +0x4a + DEFB +0x4b + DEFB +0x4c + DEFB +0x4d + DEFB +0x4e + DEFB +0x4f + DEFB +0x50 + DEFB +0x51 + DEFB +0x52 + DEFB +0x53 + DEFB +0x54 + DEFB +0x55 + DEFB +0x56 + DEFB +0x57 + DEFB +0x58 + DEFB +0x59 + DEFB +0x5a + DEFB +0x21 + DEFB +0x40 + DEFB +0x23 + DEFB +0x24 + DEFB +0x25 + DEFB +0x5e + DEFB +0x26 + DEFB +0x2a + DEFB +0x28 + DEFB +0x29 + DEFB +0x0d + DEFB +0x1b + DEFB +0x08 + DEFB +0x09 + DEFB +0x20 + DEFB +0x5f + DEFB +0x2b + DEFB +0x7b + DEFB +0x7d + DEFB +0x7c + DEFB +0x7e + DEFB +0x3a + DEFB +0x22 + DEFB +0x7e + DEFB +0x3c + DEFB +0x3e + DEFB +0x3f + 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 +0x2f + DEFB +0x2a + DEFB +0x2d + DEFB +0x2b + DEFB +0x0d + DEFB +0x31 + DEFB +0x32 + DEFB +0x33 + DEFB +0x34 + DEFB +0x35 + DEFB +0x36 + DEFB +0x37 + DEFB +0x38 + DEFB +0x39 + DEFB +0x30 + DEFB +0x2e + DEFB +0x5c + DEFB +0x00 + DEFB +0x00 + DEFB +0x3d + 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 +_scancodes_table: + DEFB +0x00 + DEFB +0x00 + DEFB +0x00 + DEFB +0x00 + DEFB +0x61 + DEFB +0x62 + DEFB +0x63 + DEFB +0x64 + DEFB +0x65 + DEFB +0x66 + DEFB +0x67 + DEFB +0x68 + DEFB +0x69 + DEFB +0x6a + DEFB +0x6b + DEFB +0x6c + DEFB +0x6d + DEFB +0x6e + DEFB +0x6f + DEFB +0x70 + DEFB +0x71 + DEFB +0x72 + DEFB +0x73 + DEFB +0x74 + DEFB +0x75 + DEFB +0x76 + DEFB +0x77 + DEFB +0x78 + DEFB +0x79 + DEFB +0x7a + DEFB +0x31 + DEFB +0x32 + DEFB +0x33 + DEFB +0x34 + DEFB +0x35 + DEFB +0x36 + DEFB +0x37 + DEFB +0x38 + DEFB +0x39 + DEFB +0x30 + DEFB +0x0d + DEFB +0x1b + DEFB +0x08 + DEFB +0x09 + DEFB +0x20 + DEFB +0x2d + DEFB +0x3d + DEFB +0x5b + DEFB +0x5d + DEFB +0x5c + DEFB +0x23 + DEFB +0x3b + DEFB +0x27 + DEFB +0x60 + DEFB +0x2c + DEFB +0x2e + DEFB +0x2f + 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 +0x2f + DEFB +0x2a + DEFB +0x2d + DEFB +0x2b + DEFB +0x0d + DEFB +0x31 + DEFB +0x32 + DEFB +0x33 + DEFB +0x34 + DEFB +0x35 + DEFB +0x36 + DEFB +0x37 + DEFB +0x38 + DEFB +0x39 + DEFB +0x30 + DEFB +0x2e + DEFB +0x5c + DEFB +0x00 + DEFB +0x00 + DEFB +0x3d + 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 diff --git a/Source/HBIOS/ch376-native/keyboard/kyb-init.c.s b/Source/HBIOS/ch376-native/keyboard/kyb-init.c.s index ac8491a6..86a694de 100644 --- a/Source/HBIOS/ch376-native/keyboard/kyb-init.c.s +++ b/Source/HBIOS/ch376-native/keyboard/kyb-init.c.s @@ -33,6 +33,18 @@ _USB_MODULE_LEDS .EQU 0xff8a ; .area _INITIALIZED removed by z88dk +_keyboard_config: + DEFS 2 +_buffer: + DEFS 16 +_write_index: + DEFS 1 +_read_index: + DEFS 1 +_active: + DEFS 1 +_report: + DEFS 8 #ENDIF @@ -48,76 +60,81 @@ _USB_MODULE_LEDS .EQU 0xff8a ;-------------------------------------------------------- ; code ;-------------------------------------------------------- -;source-doc/keyboard/./kyb-init.c:8: void keyboard_init(void) { +;source-doc/keyboard/./kyb-init.c:11: void keyboard_init(void) { ; --------------------------------- ; Function keyboard_init ; --------------------------------- _keyboard_init: -;source-doc/keyboard/./kyb-init.c:10: uint8_t index = 1; -;source-doc/keyboard/./kyb-init.c:11: do { - ld bc,0x0101 +;source-doc/keyboard/./kyb-init.c:13: uint8_t index = 1; + ld c,0x01 +;source-doc/keyboard/./kyb-init.c:14: keyboard_config = NULL; + xor a + ld hl,_keyboard_config + ld (hl), a + inc hl + ld (hl), a +;source-doc/keyboard/./kyb-init.c:16: do { + ld b,0x01 l_keyboard_init_00105: -;source-doc/keyboard/./kyb-init.c:12: device_config_keyboard *const keyboard_config = (device_config_keyboard *)get_usb_device_config(index); +;source-doc/keyboard/./kyb-init.c:17: keyboard_config = (device_config_keyboard *)get_usb_device_config(index); push bc ld a, b call _get_usb_device_config + ex de, hl pop bc -;source-doc/keyboard/./kyb-init.c:14: if (keyboard_config == NULL) - ld a, d - or e + ld (_keyboard_config), hl +;source-doc/keyboard/./kyb-init.c:19: if (keyboard_config == NULL) + ld hl,_keyboard_config + 1 + ld a, (hl) + dec hl + or (hl) jr Z,l_keyboard_init_00107 -;source-doc/keyboard/./kyb-init.c:17: const usb_device_type t = keyboard_config->type; - ld l, e - ld h, d +;source-doc/keyboard/./kyb-init.c:22: const usb_device_type t = keyboard_config->type; + ld hl, (_keyboard_config) ld a, (hl) and 0x0f -;source-doc/keyboard/./kyb-init.c:19: if (t == USB_IS_KEYBOARD) { +;source-doc/keyboard/./kyb-init.c:24: if (t == USB_IS_KEYBOARD) { sub 0x04 jr NZ,l_keyboard_init_00106 -;source-doc/keyboard/./kyb-init.c:20: print_string("\r\nUSB: KEYBOARD @ $"); +;source-doc/keyboard/./kyb-init.c:25: print_string("\r\nUSB: KEYBOARD @ $"); push bc - push de ld hl,kyb_init_str_0 call _print_string - pop de pop bc -;source-doc/keyboard/./kyb-init.c:21: print_uint16(index); +;source-doc/keyboard/./kyb-init.c:26: print_uint16(index); ld h,0x00 - push de ld l, c call _print_uint16 +;source-doc/keyboard/./kyb-init.c:27: print_string(" $"); ld hl,kyb_init_str_1 call _print_string - pop de -;source-doc/keyboard/./kyb-init.c:25: hid_set_protocol(keyboard_config, 1); - push de +;source-doc/keyboard/./kyb-init.c:29: hid_set_protocol(keyboard_config, 1); ld a,0x01 push af inc sp - ex de,hl + ld hl, (_keyboard_config) call _hid_set_protocol - pop de -;source-doc/keyboard/./kyb-init.c:26: hid_set_idle(keyboard_config, 0x80); +;source-doc/keyboard/./kyb-init.c:30: hid_set_idle(keyboard_config, 0x80); ld a,0x80 push af inc sp - ex de, hl + ld hl, (_keyboard_config) call _hid_set_idle -;source-doc/keyboard/./kyb-init.c:27: return; +;source-doc/keyboard/./kyb-init.c:31: return; jr l_keyboard_init_00108 l_keyboard_init_00106: -;source-doc/keyboard/./kyb-init.c:29: } while (++index != MAX_NUMBER_OF_DEVICES + 1); +;source-doc/keyboard/./kyb-init.c:33: } while (++index != MAX_NUMBER_OF_DEVICES + 1); inc b ld a,b ld c,a sub 0x07 jr NZ,l_keyboard_init_00105 l_keyboard_init_00107: -;source-doc/keyboard/./kyb-init.c:31: print_string("\r\nUSB: KEYBOARD: NOT FOUND$"); +;source-doc/keyboard/./kyb-init.c:35: print_string("\r\nUSB: KEYBOARD: NOT FOUND$"); ld hl,kyb_init_str_2 jp _print_string l_keyboard_init_00108: -;source-doc/keyboard/./kyb-init.c:32: } +;source-doc/keyboard/./kyb-init.c:36: } ret kyb_init_str_0: DEFB 0x0d @@ -132,3 +149,256 @@ kyb_init_str_2: DEFB 0x0a DEFM "USB: KEYBOARD: NOT FOUND$" DEFB 0x00 +;source-doc/keyboard/./kyb-init.c:48: void keyboard_buf_put(const uint8_t modifier_keys, const uint8_t key_code) { +; --------------------------------- +; Function keyboard_buf_put +; --------------------------------- +_keyboard_buf_put: + push ix + ld ix,0 + add ix,sp +;source-doc/keyboard/./kyb-init.c:49: if (key_code >= 0x80 || key_code == 0) + ld a,(ix+5) + sub 0x80 + jr NC,l_keyboard_buf_put_00106 + ld a,(ix+5) + or a +;source-doc/keyboard/./kyb-init.c:50: return; // ignore ??? + jr Z,l_keyboard_buf_put_00106 +;source-doc/keyboard/./kyb-init.c:52: uint8_t next_write_index = (write_index + 1) & KEYBOARD_BUFFER_SIZE_MASK; + ld a,(_write_index) + inc a + and 0x07 + ld b, a +;source-doc/keyboard/./kyb-init.c:53: if (next_write_index != read_index) { // Check if buffer is not full + ld a,(_read_index) + sub b + jr Z,l_keyboard_buf_put_00106 +;source-doc/keyboard/./kyb-init.c:54: buffer[write_index].modifier_keys = modifier_keys; + ld de,_buffer+0 + ld hl,_write_index + ld l, (hl) + ld h,0x00 + add hl, hl + add hl, de + ld a,(ix+4) + ld (hl), a +;source-doc/keyboard/./kyb-init.c:55: buffer[write_index].key_code = key_code; + ld hl,_write_index + ld l, (hl) + ld h,0x00 + add hl, hl + add hl, de + ex de, hl + inc de + ld a,(ix+5) + ld (de), a +;source-doc/keyboard/./kyb-init.c:56: write_index = next_write_index; + ld hl,_write_index + ld (hl), b +l_keyboard_buf_put_00106: +;source-doc/keyboard/./kyb-init.c:58: } + pop ix + ret +;source-doc/keyboard/./kyb-init.c:60: uint8_t keyboard_buf_size() __sdcccall(1) { +; --------------------------------- +; Function keyboard_buf_size +; --------------------------------- +_keyboard_buf_size: +;source-doc/keyboard/./kyb-init.c:61: if (write_index >= read_index) + ld a,(_write_index) + ld hl,_read_index + sub (hl) + jr C,l_keyboard_buf_size_00102 +;source-doc/keyboard/./kyb-init.c:62: return write_index - read_index; + ld a,(_write_index) + ld hl,_read_index + sub (hl) + jr l_keyboard_buf_size_00103 +l_keyboard_buf_size_00102: +;source-doc/keyboard/./kyb-init.c:64: return KEYBOARD_BUFFER_SIZE - read_index + write_index; + ld hl,_read_index + ld c, (hl) + ld a,0x08 + sub c + ld hl,_write_index + ld c, (hl) + add a, c +l_keyboard_buf_size_00103: +;source-doc/keyboard/./kyb-init.c:65: } + ret +;source-doc/keyboard/./kyb-init.c:67: uint32_t keyboard_buf_get_next() { +; --------------------------------- +; Function keyboard_buf_get_next +; --------------------------------- +_keyboard_buf_get_next: + push ix + ld ix,0 + add ix,sp + push af + push af +;source-doc/keyboard/./kyb-init.c:68: if (write_index == read_index) // Check if buffer is empty + ld a,(_write_index) + ld hl,_read_index + sub (hl) + jr NZ,l_keyboard_buf_get_next_00102 +;source-doc/keyboard/./kyb-init.c:69: return 255 << 8; + ld hl,0xff00 + ld e, h + ld d, h + jr l_keyboard_buf_get_next_00103 +l_keyboard_buf_get_next_00102: +;source-doc/keyboard/./kyb-init.c:71: const uint8_t modifier_key = buffer[read_index].modifier_keys; + ld bc,_buffer+0 + ld hl,_read_index + ld l, (hl) + ld h,0x00 + add hl, hl + add hl, bc + ld d, (hl) +;source-doc/keyboard/./kyb-init.c:72: const uint8_t key_code = buffer[read_index].key_code; + inc hl + ld e, (hl) +;source-doc/keyboard/./kyb-init.c:73: read_index = (read_index + 1) & KEYBOARD_BUFFER_SIZE_MASK; + ld hl,_read_index + ld a, (hl) + inc a + and 0x07 + ld (hl), a +;source-doc/keyboard/./kyb-init.c:74: const unsigned char c = scancode_to_char(modifier_key, key_code); + push de + ld l, e + ld a, d + call _scancode_to_char + pop de +;source-doc/keyboard/./kyb-init.c:76: return (uint32_t)modifier_key << 24 | (uint32_t)c << 16 | key_code; + ld (ix-1),d + ld (ix-4),0x00 + ld (ix-3),0x00 + ld (ix-2),0x00 + ld l, a + ld a,(ix-1) + ld (ix-4),e + ld (ix-3),0x00 + ld (ix-2),0x00 + ld (ix-1),0x00 + pop de + push de + ld h, a + ex de, hl +l_keyboard_buf_get_next_00103: +;source-doc/keyboard/./kyb-init.c:77: } + ld sp, ix + pop ix + ret +;source-doc/keyboard/./kyb-init.c:79: void keyboard_buf_flush() { +; --------------------------------- +; Function keyboard_buf_flush +; --------------------------------- +_keyboard_buf_flush: +;source-doc/keyboard/./kyb-init.c:80: write_index = 0; + ld hl,_write_index + ld (hl),0x00 +;source-doc/keyboard/./kyb-init.c:81: read_index = 0; + ld hl,_read_index + ld (hl),0x00 +;source-doc/keyboard/./kyb-init.c:82: } + ret +;source-doc/keyboard/./kyb-init.c:88: void keyboard_tick(void) { +; --------------------------------- +; Function keyboard_tick +; --------------------------------- +_keyboard_tick: +;source-doc/keyboard/./kyb-init.c:89: if (is_in_critical_section()) + ld hl,_in_critical_usb_section + ld a, (hl) + or a +;source-doc/keyboard/./kyb-init.c:90: return; + ret NZ +;././source-doc/base-drv//ch376.h:163: ch_command(CH_CMD_WRITE_VAR8); + ld l,0x0b + call _ch_command +;././source-doc/base-drv//ch376.h:164: CH376_DATA_PORT = CH_VAR_RETRY_TIMES; + ld a,0x25 + ld bc,_CH376_DATA_PORT + out (c),a +;././source-doc/base-drv//ch376.h:165: CH376_DATA_PORT = retry << 6 | (number_of_retries & 0x1F); + ld a,0x1f + ld bc,_CH376_DATA_PORT + out (c),a +;source-doc/keyboard/./kyb-init.c:93: result = usbdev_dat_in_trnsfer_0((device_config *)keyboard_config, (uint8_t *)report, 8); + ld bc,_report + ld hl, (_keyboard_config) + ld a,0x08 + push af + inc sp + push bc + push hl + call _usbdev_dat_in_trnsfer_0 + pop af + pop af + inc sp + ld a, l + ld (_result), a +;././source-doc/base-drv//ch376.h:163: ch_command(CH_CMD_WRITE_VAR8); + ld l,0x0b + call _ch_command +;././source-doc/base-drv//ch376.h:164: CH376_DATA_PORT = CH_VAR_RETRY_TIMES; + ld a,0x25 + ld bc,_CH376_DATA_PORT + out (c),a +;././source-doc/base-drv//ch376.h:165: CH376_DATA_PORT = retry << 6 | (number_of_retries & 0x1F); + ld a,0xdf + ld bc,_CH376_DATA_PORT + out (c),a +;source-doc/keyboard/./kyb-init.c:95: if (result == 0) + ld hl,_result + ld a, (hl) + or a + ret NZ +;source-doc/keyboard/./kyb-init.c:96: keyboard_buf_put(report.bModifierKeys, report.keyCode[0]); + ld a, (_report + 2) + ld hl,_report + 0 + ld b, (hl) + push af + inc sp + push bc + inc sp + call _keyboard_buf_put + pop af +;source-doc/keyboard/./kyb-init.c:97: } + ret +_keyboard_config: + DEFW +0x0000 +_buffer: + 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 +_write_index: + DEFB +0x00 +_read_index: + DEFB +0x00 +_active: + DEFB +0x00 +_report: + DEFB +0x00 + DEFB +0x00 + DEFB 0x00 + DEFB 0x00 + DEFB 0x00 + DEFB 0x00 + DEFB 0x00 + DEFB 0x00 diff --git a/Source/HBIOS/ch376-native/scsi-drv/class_scsi.c.s b/Source/HBIOS/ch376-native/scsi-drv/class_scsi.c.s index 58af4d5a..ede7d8ac 100644 --- a/Source/HBIOS/ch376-native/scsi-drv/class_scsi.c.s +++ b/Source/HBIOS/ch376-native/scsi-drv/class_scsi.c.s @@ -62,7 +62,7 @@ _cbw: ;-------------------------------------------------------- ; code ;-------------------------------------------------------- -;source-doc/scsi-drv/./class_scsi.c:11: usb_error do_scsi_cmd(device_config_storage *const dev, +;source-doc/scsi-drv/./class_scsi.c:12: usb_error do_scsi_cmd(device_config_storage *const dev, ; --------------------------------- ; Function do_scsi_cmd ; --------------------------------- @@ -70,10 +70,10 @@ _do_scsi_cmd: push ix ld ix,0 add ix,sp - ld hl, -10 + ld hl, -8 add hl, sp ld sp, hl -;source-doc/scsi-drv/./class_scsi.c:16: cbw->dCBWTag[0] = next_tag++; +;source-doc/scsi-drv/./class_scsi.c:17: cbw->dCBWTag[0] = next_tag++; ld c,(ix+6) ld b,(ix+7) ld hl,0x0004 @@ -91,25 +91,29 @@ _do_scsi_cmd: ld (hl), e inc hl ld (hl), d -;source-doc/scsi-drv/./class_scsi.c:18: if (!send) +;source-doc/scsi-drv/./class_scsi.c:19: if (!send) bit 0,(ix+10) jr NZ,l_do_scsi_cmd_00102 -;source-doc/scsi-drv/./class_scsi.c:19: cbw->bmCBWFlags = 0x80; +;source-doc/scsi-drv/./class_scsi.c:20: cbw->bmCBWFlags = 0x80; ld hl,0x000c add hl, bc ld (hl),0x80 l_do_scsi_cmd_00102: -;source-doc/scsi-drv/./class_scsi.c:22: &dev->endpoints[ENDPOINT_BULK_OUT])); +;source-doc/scsi-drv/./class_scsi.c:22: critical_begin(); + push bc + call _critical_begin + pop bc +;source-doc/scsi-drv/./class_scsi.c:25: &dev->endpoints[ENDPOINT_BULK_OUT])); ld a,(ix+4) - ld (ix-8),a + ld (ix-6),a ld a,(ix+5) - ld (ix-7),a - ld a,(ix-8) + ld (ix-5),a + ld a,(ix-6) add a,0x03 - ld (ix-6),a - ld a,(ix-7) + ld (ix-4),a + ld a,(ix-5) adc a,0x00 - ld (ix-5),a + ld (ix-3),a pop de pop hl push hl @@ -123,8 +127,8 @@ l_do_scsi_cmd_00102: ld e,(ix+6) ld d,(ix+7) push bc - ld l,(ix-6) - ld h,(ix-5) + ld l,(ix-4) + ld h,(ix-3) push hl push af inc sp @@ -139,63 +143,53 @@ l_do_scsi_cmd_00102: pop bc ld a, l ld (_result), a - ld hl,_result - ld a, (hl) + ld a,(_result) or a - jr Z,l_do_scsi_cmd_00104 - ld l, (hl) - jp l_do_scsi_cmd_00119 -l_do_scsi_cmd_00104: -;source-doc/scsi-drv/./class_scsi.c:24: if (cbw->dCBWDataTransferLength != 0) { + jp NZ, l_do_scsi_cmd_00120 +;source-doc/scsi-drv/./class_scsi.c:27: if (cbw->dCBWDataTransferLength != 0) { ld hl,8 add hl, bc - ld c, (hl) - inc hl - ld b, (hl) - inc hl ld e, (hl) inc hl ld d, (hl) -;source-doc/scsi-drv/./class_scsi.c:27: &dev->endpoints[ENDPOINT_BULK_IN])); - ld a,(ix-8) + inc hl + ld c, (hl) + inc hl + ld b, (hl) +;source-doc/scsi-drv/./class_scsi.c:30: &dev->endpoints[ENDPOINT_BULK_IN])); + ld a,(ix-6) add a,0x06 - ld (ix-4),a - ld a,(ix-7) + ld (ix-2),a + ld a,(ix-5) adc a,0x00 - ld (ix-3),a -;source-doc/scsi-drv/./class_scsi.c:24: if (cbw->dCBWDataTransferLength != 0) { - ld a, d - or e - or b + ld (ix-1),a +;source-doc/scsi-drv/./class_scsi.c:27: if (cbw->dCBWDataTransferLength != 0) { + ld a, b or c + or d + or e jr Z,l_do_scsi_cmd_00113 -;source-doc/scsi-drv/./class_scsi.c:27: &dev->endpoints[ENDPOINT_BULK_IN])); - ld (ix-2),c - ld (ix-1),b +;source-doc/scsi-drv/./class_scsi.c:30: &dev->endpoints[ENDPOINT_BULK_IN])); ld c,(ix+8) ld b,(ix+9) -;source-doc/scsi-drv/./class_scsi.c:25: if (!send) { +;source-doc/scsi-drv/./class_scsi.c:28: if (!send) { bit 0,(ix+10) jr NZ,l_do_scsi_cmd_00110 -;source-doc/scsi-drv/./class_scsi.c:27: &dev->endpoints[ENDPOINT_BULK_IN])); - pop de - pop hl - push hl - push de +;source-doc/scsi-drv/./class_scsi.c:30: &dev->endpoints[ENDPOINT_BULK_IN])); + ld l,(ix-6) + ld h,(ix-5) ld a, (hl) rlca rlca rlca rlca and 0x0f - ld l,(ix-4) - ld h,(ix-3) - push hl - push af - inc sp ld l,(ix-2) ld h,(ix-1) push hl + push af + inc sp + push de push bc call _usb_data_in_transfer pop af @@ -204,32 +198,26 @@ l_do_scsi_cmd_00104: inc sp ld a, l ld (_result), a - ld hl,_result - ld a, (hl) + ld a,(_result) or a jr Z,l_do_scsi_cmd_00113 - ld l, (hl) - jp l_do_scsi_cmd_00119 + jp l_do_scsi_cmd_00120 l_do_scsi_cmd_00110: -;source-doc/scsi-drv/./class_scsi.c:31: &dev->endpoints[ENDPOINT_BULK_OUT])); - pop de - pop hl - push hl - push de +;source-doc/scsi-drv/./class_scsi.c:34: &dev->endpoints[ENDPOINT_BULK_OUT])); + ld l,(ix-6) + ld h,(ix-5) ld a, (hl) rlca rlca rlca rlca and 0x0f - ld l,(ix-6) - ld h,(ix-5) + ld l,(ix-4) + ld h,(ix-3) push hl push af inc sp - ld l,(ix-2) - ld h,(ix-1) - push hl + push de push bc call _usb_data_out_transfer pop af @@ -238,14 +226,11 @@ l_do_scsi_cmd_00110: inc sp ld a, l ld (_result), a - ld hl,_result - ld a, (hl) + ld a,(_result) or a - jr Z,l_do_scsi_cmd_00113 - ld l, (hl) - jr l_do_scsi_cmd_00119 + jr NZ,l_do_scsi_cmd_00120 l_do_scsi_cmd_00113: -;source-doc/scsi-drv/./class_scsi.c:36: usb_data_in_transfer((uint8_t *)&csw, sizeof(_scsi_command_status_wrapper), dev->address, &dev->endpoints[ENDPOINT_BULK_IN])); +;source-doc/scsi-drv/./class_scsi.c:39: usb_data_in_transfer((uint8_t *)&csw, sizeof(_scsi_command_status_wrapper), dev->address, &dev->endpoints[ENDPOINT_BULK_IN])); pop de pop hl push hl @@ -257,8 +242,8 @@ l_do_scsi_cmd_00113: rlca and 0x0f ld b, a - ld l,(ix-4) - ld h,(ix-3) + ld l,(ix-2) + ld h,(ix-1) push hl push bc inc sp @@ -273,14 +258,10 @@ l_do_scsi_cmd_00113: inc sp ld a, l ld (_result), a - ld hl,_result - ld a, (hl) + ld a,(_result) or a - jr Z,l_do_scsi_cmd_00115 - ld l, (hl) - jr l_do_scsi_cmd_00119 -l_do_scsi_cmd_00115: -;source-doc/scsi-drv/./class_scsi.c:38: if (csw.bCSWStatus != 0 && csw.dCSWTag[0] != cbw->dCBWTag[0]) + jr NZ,l_do_scsi_cmd_00120 +;source-doc/scsi-drv/./class_scsi.c:41: if (csw.bCSWStatus != 0 && csw.dCSWTag[0] != cbw->dCBWTag[0]) ld a, (_csw + 12) or a jr Z,l_do_scsi_cmd_00117 @@ -294,18 +275,26 @@ l_do_scsi_cmd_00115: cp a sbc hl, bc jr Z,l_do_scsi_cmd_00117 -;source-doc/scsi-drv/./class_scsi.c:39: return USB_ERR_FAIL; - ld l,0x0e - jr l_do_scsi_cmd_00119 +;source-doc/scsi-drv/./class_scsi.c:42: result = USB_ERR_FAIL; + ld hl,_result + ld (hl),0x0e + jr l_do_scsi_cmd_00120 l_do_scsi_cmd_00117: -;source-doc/scsi-drv/./class_scsi.c:41: return USB_ERR_OK; - ld l,0x00 -l_do_scsi_cmd_00119: -;source-doc/scsi-drv/./class_scsi.c:42: } +;source-doc/scsi-drv/./class_scsi.c:44: result = USB_ERR_OK; + ld hl,_result + ld (hl),0x00 +;source-doc/scsi-drv/./class_scsi.c:46: done: +l_do_scsi_cmd_00120: +;source-doc/scsi-drv/./class_scsi.c:47: critical_end(); + call _critical_end +;source-doc/scsi-drv/./class_scsi.c:48: return result; + ld hl,_result + ld l, (hl) +;source-doc/scsi-drv/./class_scsi.c:49: } ld sp, ix pop ix ret -;source-doc/scsi-drv/./class_scsi.c:46: usb_error get_scsi_read_capacity(device_config_storage *const dev, scsi_read_capacity_result *cap_result) { +;source-doc/scsi-drv/./class_scsi.c:53: usb_error get_scsi_read_capacity(device_config_storage *const dev, scsi_read_capacity_result *cap_result) { ; --------------------------------- ; Function get_scsi_read_capacity ; --------------------------------- @@ -316,31 +305,31 @@ _get_scsi_read_capacity: ld hl, -27 add hl, sp ld sp, hl -;source-doc/scsi-drv/./class_scsi.c:48: cbw_scsi.cbw = scsi_command_block_wrapper; +;source-doc/scsi-drv/./class_scsi.c:55: cbw_scsi.cbw = scsi_command_block_wrapper; ld hl,0 add hl, sp ex de, hl ld hl,_scsi_command_block_wrapper ld bc,0x000f ldir -;source-doc/scsi-drv/./class_scsi.c:49: cbw_scsi.read_capacity = scsi_read_capacity; +;source-doc/scsi-drv/./class_scsi.c:56: cbw_scsi.read_capacity = scsi_read_capacity; ld hl,15 add hl, sp ex de, hl ld hl,_scsi_read_capacity ld bc,0x000c ldir -;source-doc/scsi-drv/./class_scsi.c:51: cbw_scsi.cbw.bCBWLUN = 0; +;source-doc/scsi-drv/./class_scsi.c:58: cbw_scsi.cbw.bCBWLUN = 0; ld (ix-14),0x00 -;source-doc/scsi-drv/./class_scsi.c:52: cbw_scsi.cbw.bCBWCBLength = sizeof(_scsi_read_capacity); +;source-doc/scsi-drv/./class_scsi.c:59: cbw_scsi.cbw.bCBWCBLength = sizeof(_scsi_read_capacity); ld (ix-13),0x0c -;source-doc/scsi-drv/./class_scsi.c:53: cbw_scsi.cbw.dCBWDataTransferLength = sizeof(scsi_read_capacity_result); +;source-doc/scsi-drv/./class_scsi.c:60: cbw_scsi.cbw.dCBWDataTransferLength = sizeof(scsi_read_capacity_result); ld (ix-19),0x08 xor a ld (ix-18),a ld (ix-17),a ld (ix-16),a -;source-doc/scsi-drv/./class_scsi.c:55: return do_scsi_cmd(dev, &cbw_scsi.cbw, cap_result, false); +;source-doc/scsi-drv/./class_scsi.c:62: return do_scsi_cmd(dev, &cbw_scsi.cbw, cap_result, false); ld c,(ix+6) ld b,(ix+7) xor a @@ -354,11 +343,11 @@ _get_scsi_read_capacity: ld h,(ix+5) push hl call _do_scsi_cmd -;source-doc/scsi-drv/./class_scsi.c:56: } +;source-doc/scsi-drv/./class_scsi.c:63: } ld sp,ix pop ix ret -;source-doc/scsi-drv/./class_scsi.c:60: usb_error scsi_inquiry(device_config_storage *const dev, scsi_inquiry_result *inq_result) { +;source-doc/scsi-drv/./class_scsi.c:67: usb_error scsi_inquiry(device_config_storage *const dev, scsi_inquiry_result *inq_result) { ; --------------------------------- ; Function scsi_inquiry ; --------------------------------- @@ -369,31 +358,31 @@ _scsi_inquiry: ld hl, -27 add hl, sp ld sp, hl -;source-doc/scsi-drv/./class_scsi.c:62: cbw_scsi.cbw = scsi_command_block_wrapper; +;source-doc/scsi-drv/./class_scsi.c:69: cbw_scsi.cbw = scsi_command_block_wrapper; ld hl,0 add hl, sp ex de, hl ld hl,_scsi_command_block_wrapper ld bc,0x000f ldir -;source-doc/scsi-drv/./class_scsi.c:63: cbw_scsi.inquiry = scsi_packet_inquiry; +;source-doc/scsi-drv/./class_scsi.c:70: cbw_scsi.inquiry = scsi_packet_inquiry; ld hl,15 add hl, sp ex de, hl ld hl,_scsi_packet_inquiry ld bc,0x000c ldir -;source-doc/scsi-drv/./class_scsi.c:65: cbw_scsi.cbw.bCBWLUN = 0; +;source-doc/scsi-drv/./class_scsi.c:72: cbw_scsi.cbw.bCBWLUN = 0; ld (ix-14),0x00 -;source-doc/scsi-drv/./class_scsi.c:66: cbw_scsi.cbw.bCBWCBLength = sizeof(_scsi_packet_inquiry); +;source-doc/scsi-drv/./class_scsi.c:73: cbw_scsi.cbw.bCBWCBLength = sizeof(_scsi_packet_inquiry); ld (ix-13),0x0c -;source-doc/scsi-drv/./class_scsi.c:67: cbw_scsi.cbw.dCBWDataTransferLength = 0x24; +;source-doc/scsi-drv/./class_scsi.c:74: cbw_scsi.cbw.dCBWDataTransferLength = 0x24; ld (ix-19),0x24 xor a ld (ix-18),a ld (ix-17),a ld (ix-16),a -;source-doc/scsi-drv/./class_scsi.c:69: return do_scsi_cmd(dev, &cbw_scsi.cbw, inq_result, false); +;source-doc/scsi-drv/./class_scsi.c:76: return do_scsi_cmd(dev, &cbw_scsi.cbw, inq_result, false); ld c,(ix+6) ld b,(ix+7) xor a @@ -407,11 +396,11 @@ _scsi_inquiry: ld h,(ix+5) push hl call _do_scsi_cmd -;source-doc/scsi-drv/./class_scsi.c:70: } +;source-doc/scsi-drv/./class_scsi.c:77: } ld sp,ix pop ix ret -;source-doc/scsi-drv/./class_scsi.c:72: usb_error scsi_test(device_config_storage *const dev) { +;source-doc/scsi-drv/./class_scsi.c:79: usb_error scsi_test(device_config_storage *const dev) { ; --------------------------------- ; Function scsi_test ; --------------------------------- @@ -422,14 +411,14 @@ _scsi_test: ld hl, -27 add hl, sp ld sp, hl -;source-doc/scsi-drv/./class_scsi.c:74: cbw_scsi.cbw = scsi_command_block_wrapper; +;source-doc/scsi-drv/./class_scsi.c:81: cbw_scsi.cbw = scsi_command_block_wrapper; ld hl,0 add hl, sp ex de, hl ld hl,_scsi_command_block_wrapper ld bc,0x000f ldir -;source-doc/scsi-drv/./class_scsi.c:75: memset(&cbw_scsi.test, 0, sizeof(_scsi_packet_test)); +;source-doc/scsi-drv/./class_scsi.c:82: memset(&cbw_scsi.test, 0, sizeof(_scsi_packet_test)); ld hl,15 add hl, sp ld b,0x0c @@ -437,11 +426,11 @@ l_scsi_test_00103: ld (hl),0x00 inc hl djnz l_scsi_test_00103 -;source-doc/scsi-drv/./class_scsi.c:77: cbw_scsi.cbw.bCBWLUN = 0; +;source-doc/scsi-drv/./class_scsi.c:84: cbw_scsi.cbw.bCBWLUN = 0; ld (ix-14),0x00 -;source-doc/scsi-drv/./class_scsi.c:78: cbw_scsi.cbw.bCBWCBLength = sizeof(_scsi_packet_test); +;source-doc/scsi-drv/./class_scsi.c:85: cbw_scsi.cbw.bCBWCBLength = sizeof(_scsi_packet_test); ld (ix-13),0x0c -;source-doc/scsi-drv/./class_scsi.c:79: cbw_scsi.cbw.dCBWDataTransferLength = 0; +;source-doc/scsi-drv/./class_scsi.c:86: cbw_scsi.cbw.dCBWDataTransferLength = 0; ld hl,8 add hl, sp ex de, hl @@ -453,7 +442,7 @@ l_scsi_test_00103: ld (de), a inc de ld (de), a -;source-doc/scsi-drv/./class_scsi.c:81: return do_scsi_cmd(dev, &cbw_scsi.cbw, 0, false); +;source-doc/scsi-drv/./class_scsi.c:88: return do_scsi_cmd(dev, &cbw_scsi.cbw, 0, false); xor a push af inc sp @@ -466,11 +455,11 @@ l_scsi_test_00103: ld h,(ix+5) push hl call _do_scsi_cmd -;source-doc/scsi-drv/./class_scsi.c:82: } +;source-doc/scsi-drv/./class_scsi.c:89: } ld sp,ix pop ix ret -;source-doc/scsi-drv/./class_scsi.c:86: usb_error scsi_request_sense(device_config_storage *const dev, scsi_sense_result *const sens_result) { +;source-doc/scsi-drv/./class_scsi.c:93: usb_error scsi_request_sense(device_config_storage *const dev, scsi_sense_result *const sens_result) { ; --------------------------------- ; Function scsi_request_sense ; --------------------------------- @@ -481,31 +470,31 @@ _scsi_request_sense: ld hl, -27 add hl, sp ld sp, hl -;source-doc/scsi-drv/./class_scsi.c:88: cbw_scsi.cbw = scsi_command_block_wrapper; +;source-doc/scsi-drv/./class_scsi.c:95: cbw_scsi.cbw = scsi_command_block_wrapper; ld hl,0 add hl, sp ex de, hl ld hl,_scsi_command_block_wrapper ld bc,0x000f ldir -;source-doc/scsi-drv/./class_scsi.c:89: cbw_scsi.request_sense = scsi_packet_request_sense; +;source-doc/scsi-drv/./class_scsi.c:96: cbw_scsi.request_sense = scsi_packet_request_sense; ld hl,15 add hl, sp ex de, hl ld hl,_scsi_packet_request_sense ld bc,0x000c ldir -;source-doc/scsi-drv/./class_scsi.c:91: cbw_scsi.cbw.bCBWLUN = 0; +;source-doc/scsi-drv/./class_scsi.c:98: cbw_scsi.cbw.bCBWLUN = 0; ld (ix-14),0x00 -;source-doc/scsi-drv/./class_scsi.c:92: cbw_scsi.cbw.bCBWCBLength = sizeof(_scsi_packet_request_sense); +;source-doc/scsi-drv/./class_scsi.c:99: cbw_scsi.cbw.bCBWCBLength = sizeof(_scsi_packet_request_sense); ld (ix-13),0x0c -;source-doc/scsi-drv/./class_scsi.c:93: cbw_scsi.cbw.dCBWDataTransferLength = sizeof(scsi_sense_result); +;source-doc/scsi-drv/./class_scsi.c:100: cbw_scsi.cbw.dCBWDataTransferLength = sizeof(scsi_sense_result); ld (ix-19),0x12 xor a ld (ix-18),a ld (ix-17),a ld (ix-16),a -;source-doc/scsi-drv/./class_scsi.c:95: return do_scsi_cmd(dev, &cbw_scsi.cbw, sens_result, false); +;source-doc/scsi-drv/./class_scsi.c:102: return do_scsi_cmd(dev, &cbw_scsi.cbw, sens_result, false); ld c,(ix+6) ld b,(ix+7) xor a @@ -519,11 +508,11 @@ _scsi_request_sense: ld h,(ix+5) push hl call _do_scsi_cmd -;source-doc/scsi-drv/./class_scsi.c:96: } +;source-doc/scsi-drv/./class_scsi.c:103: } ld sp,ix pop ix ret -;source-doc/scsi-drv/./class_scsi.c:98: usb_error scsi_sense_init(device_config_storage *const dev) { +;source-doc/scsi-drv/./class_scsi.c:105: usb_error scsi_sense_init(device_config_storage *const dev) { ; --------------------------------- ; Function scsi_sense_init ; --------------------------------- @@ -534,7 +523,9 @@ _scsi_sense_init: ld hl, -18 add hl, sp ld sp, hl -;source-doc/scsi-drv/./class_scsi.c:102: while ((result = scsi_test(dev)) && --counter > 0) +;source-doc/scsi-drv/./class_scsi.c:109: critical_begin(); + call _critical_begin +;source-doc/scsi-drv/./class_scsi.c:110: while ((result = scsi_test(dev)) && --counter > 0) ld c,0x03 l_scsi_sense_init_00102: push bc @@ -550,7 +541,7 @@ l_scsi_sense_init_00102: jr Z,l_scsi_sense_init_00104 dec c jr Z,l_scsi_sense_init_00104 -;source-doc/scsi-drv/./class_scsi.c:103: scsi_request_sense(dev, &response); +;source-doc/scsi-drv/./class_scsi.c:111: scsi_request_sense(dev, &response); push bc ld hl,2 add hl, sp @@ -564,14 +555,16 @@ l_scsi_sense_init_00102: pop bc jr l_scsi_sense_init_00102 l_scsi_sense_init_00104: -;source-doc/scsi-drv/./class_scsi.c:105: return result; +;source-doc/scsi-drv/./class_scsi.c:112: critical_end(); + call _critical_end +;source-doc/scsi-drv/./class_scsi.c:114: return result; ld hl,_result ld l, (hl) -;source-doc/scsi-drv/./class_scsi.c:106: } +;source-doc/scsi-drv/./class_scsi.c:115: } ld sp, ix pop ix ret -;source-doc/scsi-drv/./class_scsi.c:110: usb_error scsi_read(device_config_storage *const dev, uint8_t *const buffer) { +;source-doc/scsi-drv/./class_scsi.c:119: usb_error scsi_read(device_config_storage *const dev, uint8_t *const buffer) { ; --------------------------------- ; Function scsi_read ; --------------------------------- @@ -580,36 +573,36 @@ _scsi_read: ld ix,0 add ix,sp push af -;source-doc/scsi-drv/./class_scsi.c:111: memset(&cbw, 0, sizeof(cbw_scsi_read_write)); +;source-doc/scsi-drv/./class_scsi.c:120: memset(&cbw, 0, sizeof(cbw_scsi_read_write)); ld hl,_cbw ld b,0x1b l_scsi_read_00112: ld (hl),0x00 inc hl djnz l_scsi_read_00112 -;source-doc/scsi-drv/./class_scsi.c:112: cbw.cbw = scsi_command_block_wrapper; +;source-doc/scsi-drv/./class_scsi.c:121: cbw.cbw = scsi_command_block_wrapper; ld de,_cbw ld hl,_scsi_command_block_wrapper ld bc,0x000f ldir -;source-doc/scsi-drv/./class_scsi.c:114: cbw.cbw.bCBWLUN = 0; +;source-doc/scsi-drv/./class_scsi.c:123: cbw.cbw.bCBWLUN = 0; ld hl,_cbw + 13 ld (hl),0x00 -;source-doc/scsi-drv/./class_scsi.c:115: cbw.cbw.bCBWCBLength = sizeof(_scsi_packet_read_write); +;source-doc/scsi-drv/./class_scsi.c:124: cbw.cbw.bCBWCBLength = sizeof(_scsi_packet_read_write); ld hl,_cbw + 14 ld (hl),0x0c -;source-doc/scsi-drv/./class_scsi.c:116: cbw.cbw.dCBWDataTransferLength = 512; +;source-doc/scsi-drv/./class_scsi.c:125: cbw.cbw.dCBWDataTransferLength = 512; ld hl,0x0200 ld ((_cbw + 8)), hl ld h, l ld ((_cbw + 8)+2), hl -;source-doc/scsi-drv/./class_scsi.c:118: cbw.scsi_cmd.operation_code = 0x28; // read operation +;source-doc/scsi-drv/./class_scsi.c:127: cbw.scsi_cmd.operation_code = 0x28; // read operation ld hl,_cbw + 15 ld (hl),0x28 -;source-doc/scsi-drv/./class_scsi.c:119: cbw.scsi_cmd.transfer_len[1] = 1; +;source-doc/scsi-drv/./class_scsi.c:128: cbw.scsi_cmd.transfer_len[1] = 1; ld hl,_cbw + 23 ld (hl),0x01 -;source-doc/scsi-drv/./class_scsi.c:120: cbw.scsi_cmd.lba[0] = dev->current_lba >> 24; +;source-doc/scsi-drv/./class_scsi.c:129: cbw.scsi_cmd.lba[0] = dev->current_lba >> 24; ld c,(ix+4) ld b,(ix+5) ld hl,0x000c @@ -622,7 +615,7 @@ l_scsi_read_00112: inc hl ld a, (hl) ld ((_cbw + 17)),a -;source-doc/scsi-drv/./class_scsi.c:121: cbw.scsi_cmd.lba[1] = dev->current_lba >> 16; +;source-doc/scsi-drv/./class_scsi.c:130: cbw.scsi_cmd.lba[1] = dev->current_lba >> 16; pop hl push hl inc hl @@ -631,19 +624,19 @@ l_scsi_read_00112: dec hl ld a, (hl) ld ((_cbw + 18)),a -;source-doc/scsi-drv/./class_scsi.c:122: cbw.scsi_cmd.lba[2] = dev->current_lba >> 8; +;source-doc/scsi-drv/./class_scsi.c:131: cbw.scsi_cmd.lba[2] = dev->current_lba >> 8; pop hl push hl inc hl ld d, (hl) ld hl, +(_cbw + 19) ld (hl), d -;source-doc/scsi-drv/./class_scsi.c:123: cbw.scsi_cmd.lba[3] = dev->current_lba; +;source-doc/scsi-drv/./class_scsi.c:132: cbw.scsi_cmd.lba[3] = dev->current_lba; pop hl push hl ld a, (hl) ld ((_cbw + 20)),a -;source-doc/scsi-drv/./class_scsi.c:125: result = do_scsi_cmd(dev, &cbw.cbw, buffer, false); +;source-doc/scsi-drv/./class_scsi.c:134: result = do_scsi_cmd(dev, &cbw.cbw, buffer, false); ld e,(ix+6) ld d,(ix+7) xor a @@ -660,11 +653,11 @@ l_scsi_read_00112: inc sp ld a, l ld (_result), a -;source-doc/scsi-drv/./class_scsi.c:127: if (result == USB_ERR_OK) +;source-doc/scsi-drv/./class_scsi.c:136: if (result == USB_ERR_OK) ld a,(_result) or a jr NZ,l_scsi_read_00102 -;source-doc/scsi-drv/./class_scsi.c:128: dev->current_lba++; +;source-doc/scsi-drv/./class_scsi.c:137: dev->current_lba++; pop hl push hl ld c, (hl) @@ -690,14 +683,14 @@ l_scsi_read_00114: inc hl ld (hl), d l_scsi_read_00102: -;source-doc/scsi-drv/./class_scsi.c:129: return result; +;source-doc/scsi-drv/./class_scsi.c:138: return result; ld hl,_result ld l, (hl) -;source-doc/scsi-drv/./class_scsi.c:130: } +;source-doc/scsi-drv/./class_scsi.c:139: } ld sp, ix pop ix ret -;source-doc/scsi-drv/./class_scsi.c:132: usb_error scsi_write(device_config_storage *const dev, uint8_t *const buffer) { +;source-doc/scsi-drv/./class_scsi.c:141: usb_error scsi_write(device_config_storage *const dev, uint8_t *const buffer) { ; --------------------------------- ; Function scsi_write ; --------------------------------- @@ -706,36 +699,36 @@ _scsi_write: ld ix,0 add ix,sp push af -;source-doc/scsi-drv/./class_scsi.c:133: memset(&cbw, 0, sizeof(cbw_scsi_read_write)); +;source-doc/scsi-drv/./class_scsi.c:142: memset(&cbw, 0, sizeof(cbw_scsi_read_write)); ld hl,_cbw ld b,0x1b l_scsi_write_00112: ld (hl),0x00 inc hl djnz l_scsi_write_00112 -;source-doc/scsi-drv/./class_scsi.c:134: cbw.cbw = scsi_command_block_wrapper; +;source-doc/scsi-drv/./class_scsi.c:143: cbw.cbw = scsi_command_block_wrapper; ld de,_cbw ld hl,_scsi_command_block_wrapper ld bc,0x000f ldir -;source-doc/scsi-drv/./class_scsi.c:136: cbw.cbw.bCBWLUN = 0; +;source-doc/scsi-drv/./class_scsi.c:145: cbw.cbw.bCBWLUN = 0; ld hl,_cbw + 13 ld (hl),0x00 -;source-doc/scsi-drv/./class_scsi.c:137: cbw.cbw.bCBWCBLength = sizeof(_scsi_packet_read_write); +;source-doc/scsi-drv/./class_scsi.c:146: cbw.cbw.bCBWCBLength = sizeof(_scsi_packet_read_write); ld hl,_cbw + 14 ld (hl),0x0c -;source-doc/scsi-drv/./class_scsi.c:138: cbw.cbw.dCBWDataTransferLength = 512; +;source-doc/scsi-drv/./class_scsi.c:147: cbw.cbw.dCBWDataTransferLength = 512; ld hl,0x0200 ld ((_cbw + 8)), hl ld h, l ld ((_cbw + 8)+2), hl -;source-doc/scsi-drv/./class_scsi.c:140: cbw.scsi_cmd.operation_code = 0x2A; // write operation +;source-doc/scsi-drv/./class_scsi.c:149: cbw.scsi_cmd.operation_code = 0x2A; // write operation ld hl,_cbw + 15 ld (hl),0x2a -;source-doc/scsi-drv/./class_scsi.c:141: cbw.scsi_cmd.transfer_len[1] = 1; +;source-doc/scsi-drv/./class_scsi.c:150: cbw.scsi_cmd.transfer_len[1] = 1; ld hl,_cbw + 23 ld (hl),0x01 -;source-doc/scsi-drv/./class_scsi.c:142: cbw.scsi_cmd.lba[0] = dev->current_lba >> 24; +;source-doc/scsi-drv/./class_scsi.c:151: cbw.scsi_cmd.lba[0] = dev->current_lba >> 24; ld c,(ix+4) ld b,(ix+5) ld hl,0x000c @@ -748,7 +741,7 @@ l_scsi_write_00112: inc hl ld a, (hl) ld ((_cbw + 17)),a -;source-doc/scsi-drv/./class_scsi.c:143: cbw.scsi_cmd.lba[1] = dev->current_lba >> 16; +;source-doc/scsi-drv/./class_scsi.c:152: cbw.scsi_cmd.lba[1] = dev->current_lba >> 16; pop hl push hl inc hl @@ -757,19 +750,19 @@ l_scsi_write_00112: dec hl ld a, (hl) ld ((_cbw + 18)),a -;source-doc/scsi-drv/./class_scsi.c:144: cbw.scsi_cmd.lba[2] = dev->current_lba >> 8; +;source-doc/scsi-drv/./class_scsi.c:153: cbw.scsi_cmd.lba[2] = dev->current_lba >> 8; pop hl push hl inc hl ld d, (hl) ld hl, +(_cbw + 19) ld (hl), d -;source-doc/scsi-drv/./class_scsi.c:145: cbw.scsi_cmd.lba[3] = dev->current_lba; +;source-doc/scsi-drv/./class_scsi.c:154: cbw.scsi_cmd.lba[3] = dev->current_lba; pop hl push hl ld a, (hl) ld ((_cbw + 20)),a -;source-doc/scsi-drv/./class_scsi.c:147: result = do_scsi_cmd(dev, &cbw.cbw, buffer, true); +;source-doc/scsi-drv/./class_scsi.c:156: result = do_scsi_cmd(dev, &cbw.cbw, buffer, true); ld e,(ix+6) ld d,(ix+7) ld a,0x01 @@ -786,11 +779,11 @@ l_scsi_write_00112: inc sp ld a, l ld (_result), a -;source-doc/scsi-drv/./class_scsi.c:149: if (result == USB_ERR_OK) +;source-doc/scsi-drv/./class_scsi.c:158: if (result == USB_ERR_OK) ld a,(_result) or a jr NZ,l_scsi_write_00102 -;source-doc/scsi-drv/./class_scsi.c:150: dev->current_lba++; +;source-doc/scsi-drv/./class_scsi.c:159: dev->current_lba++; pop hl push hl ld c, (hl) @@ -816,14 +809,14 @@ l_scsi_write_00114: inc hl ld (hl), d l_scsi_write_00102: -;source-doc/scsi-drv/./class_scsi.c:151: return result; +;source-doc/scsi-drv/./class_scsi.c:160: return result; ld hl,_result ld l, (hl) -;source-doc/scsi-drv/./class_scsi.c:152: } +;source-doc/scsi-drv/./class_scsi.c:161: } ld sp, ix pop ix ret -;source-doc/scsi-drv/./class_scsi.c:154: usb_error scsi_eject(device_config_storage *const dev) { +;source-doc/scsi-drv/./class_scsi.c:163: usb_error scsi_eject(device_config_storage *const dev) { ; --------------------------------- ; Function scsi_eject ; --------------------------------- @@ -834,14 +827,14 @@ _scsi_eject: ld hl, -21 add hl, sp ld sp, hl -;source-doc/scsi-drv/./class_scsi.c:156: cbw_scsi.cbw = scsi_command_block_wrapper; +;source-doc/scsi-drv/./class_scsi.c:165: cbw_scsi.cbw = scsi_command_block_wrapper; ld hl,0 add hl, sp ex de, hl ld hl,_scsi_command_block_wrapper ld bc,0x000f ldir -;source-doc/scsi-drv/./class_scsi.c:158: memset(&cbw_scsi.eject, 0, sizeof(_scsi_packet_eject)); +;source-doc/scsi-drv/./class_scsi.c:167: memset(&cbw_scsi.eject, 0, sizeof(_scsi_packet_eject)); ld hl,15 add hl, sp ld b,0x06 @@ -849,17 +842,17 @@ l_scsi_eject_00103: ld (hl),0x00 inc hl djnz l_scsi_eject_00103 -;source-doc/scsi-drv/./class_scsi.c:160: cbw_scsi.eject.operation_code = 0x1B; +;source-doc/scsi-drv/./class_scsi.c:169: cbw_scsi.eject.operation_code = 0x1B; ld (ix-6),0x1b -;source-doc/scsi-drv/./class_scsi.c:161: cbw_scsi.eject.loej = 1; +;source-doc/scsi-drv/./class_scsi.c:170: cbw_scsi.eject.loej = 1; ld hl,19 add hl, sp set 1, (hl) -;source-doc/scsi-drv/./class_scsi.c:163: cbw_scsi.cbw.bCBWLUN = 0; +;source-doc/scsi-drv/./class_scsi.c:172: cbw_scsi.cbw.bCBWLUN = 0; ld (ix-8),0x00 -;source-doc/scsi-drv/./class_scsi.c:164: cbw_scsi.cbw.bCBWCBLength = sizeof(_scsi_packet_eject); +;source-doc/scsi-drv/./class_scsi.c:173: cbw_scsi.cbw.bCBWCBLength = sizeof(_scsi_packet_eject); ld (ix-7),0x06 -;source-doc/scsi-drv/./class_scsi.c:165: cbw_scsi.cbw.dCBWDataTransferLength = 0; +;source-doc/scsi-drv/./class_scsi.c:174: cbw_scsi.cbw.dCBWDataTransferLength = 0; ld hl,8 add hl, sp ex de, hl @@ -871,7 +864,7 @@ l_scsi_eject_00103: ld (de), a inc de ld (de), a -;source-doc/scsi-drv/./class_scsi.c:167: return do_scsi_cmd(dev, &cbw_scsi.cbw, 0, false); +;source-doc/scsi-drv/./class_scsi.c:176: return do_scsi_cmd(dev, &cbw_scsi.cbw, 0, false); xor a push af inc sp @@ -884,7 +877,7 @@ l_scsi_eject_00103: ld h,(ix+5) push hl call _do_scsi_cmd -;source-doc/scsi-drv/./class_scsi.c:168: } +;source-doc/scsi-drv/./class_scsi.c:177: } ld sp,ix pop ix ret diff --git a/Source/HBIOS/ch376-native/scsi-drv/scsi-init.c.s b/Source/HBIOS/ch376-native/scsi-drv/scsi-init.c.s index 78c5ef49..ca652a68 100644 --- a/Source/HBIOS/ch376-native/scsi-drv/scsi-init.c.s +++ b/Source/HBIOS/ch376-native/scsi-drv/scsi-init.c.s @@ -88,23 +88,23 @@ l_chscsi_init_00105: ld hl,scsi_init_str_1 call _print_string pop de -;source-doc/scsi-drv/./scsi-init.c:29: scsi_sense_init(storage_device); +;source-doc/scsi-drv/./scsi-init.c:28: scsi_sense_init(storage_device); push de push de call _scsi_sense_init pop af pop de -;source-doc/scsi-drv/./scsi-init.c:30: dio_add_entry(ch_scsi_fntbl, storage_device); +;source-doc/scsi-drv/./scsi-init.c:29: dio_add_entry(ch_scsi_fntbl, storage_device); ld hl,_ch_scsi_fntbl call _dio_add_entry l_chscsi_init_00106: -;source-doc/scsi-drv/./scsi-init.c:33: } while (++index != MAX_NUMBER_OF_DEVICES + 1); +;source-doc/scsi-drv/./scsi-init.c:32: } while (++index != MAX_NUMBER_OF_DEVICES + 1); inc (ix-1) ld a,(ix-1) sub 0x07 jr NZ,l_chscsi_init_00105 l_chscsi_init_00108: -;source-doc/scsi-drv/./scsi-init.c:34: } +;source-doc/scsi-drv/./scsi-init.c:33: } inc sp pop ix ret diff --git a/Source/HBIOS/ch376-native/source-doc/base-drv/ch376.c b/Source/HBIOS/ch376-native/source-doc/base-drv/ch376.c index 4c7b52d1..c939f819 100644 --- a/Source/HBIOS/ch376-native/source-doc/base-drv/ch376.c +++ b/Source/HBIOS/ch376-native/source-doc/base-drv/ch376.c @@ -8,7 +8,7 @@ usb_error result = 0; void ch_command(const uint8_t command) __z88dk_fastcall { uint8_t counter = 255; while ((CH376_COMMAND_PORT & PARA_STATE_BUSY) && --counter != 0) - delay(); + ; // if (counter == 0) { // It appears that the Ch376 has become blocked @@ -18,12 +18,7 @@ void ch_command(const uint8_t command) __z88dk_fastcall { // return; // } - delay(); CH376_COMMAND_PORT = command; - delay(); - delay(); - delay(); - delay(); } extern usb_error ch_wait_int_and_get_status(const int16_t timeout) __z88dk_fastcall; @@ -36,10 +31,6 @@ usb_error ch_very_short_wait_int_and_get_status(void) { return ch_wait_int_and_g usb_error ch_get_status(void) { ch_command(CH_CMD_GET_STATUS); - delay(); - delay(); - delay(); - delay(); uint8_t ch_status = CH376_DATA_PORT; if (ch_status >= USB_FILERR_MIN && ch_status <= USB_FILERR_MAX) @@ -143,14 +134,8 @@ uint8_t ch_cmd_get_ic_version(void) { void ch_issue_token(const uint8_t toggle_bit, const uint8_t endpoint, const ch376_pid pid) { ch_command(CH_CMD_ISSUE_TKN_X); - delay(); - delay(); CH376_DATA_PORT = toggle_bit; - delay(); - delay(); CH376_DATA_PORT = endpoint << 4 | pid; - delay(); - delay(); } void ch_issue_token_in(const endpoint_param *const endpoint) __z88dk_fastcall { @@ -168,8 +153,7 @@ void ch_issue_token_in_ep0(void) { ch_issue_token(0x80, 0, CH_PID_IN); } void ch_issue_token_setup(void) { ch_issue_token(0, 0, CH_PID_SETUP); } usb_error ch_data_in_transfer(uint8_t *buffer, int16_t buffer_size, endpoint_param *const endpoint) { - uint8_t count; - usb_error result; + uint8_t count; if (buffer_size == 0) return USB_ERR_OK; @@ -197,6 +181,8 @@ usb_error ch_data_in_transfer(uint8_t *buffer, int16_t buffer_size, endpoint_par USB_MODULE_LEDS = 0x00; return USB_ERR_OK; +done: + return result; } usb_error ch_data_in_transfer_n(uint8_t *const buffer, int8_t *const buffer_size, endpoint_param *const endpoint) { @@ -218,6 +204,8 @@ usb_error ch_data_in_transfer_n(uint8_t *const buffer, int8_t *const buffer_size USB_MODULE_LEDS = 0x00; return USB_ERR_OK; +done: + return result; } usb_error ch_data_out_transfer(const uint8_t *buffer, int16_t buffer_length, endpoint_param *const endpoint) { @@ -241,10 +229,11 @@ usb_error ch_data_out_transfer(const uint8_t *buffer, int16_t buffer_length, end USB_MODULE_LEDS = 0x00; return USB_ERR_OK; +done: + return result; } void ch_set_usb_address(const uint8_t device_address) __z88dk_fastcall { ch_command(CH_CMD_SET_USB_ADDR); CH376_DATA_PORT = device_address; - delay(); } diff --git a/Source/HBIOS/ch376-native/source-doc/base-drv/ch376.h b/Source/HBIOS/ch376-native/source-doc/base-drv/ch376.h index 88d38dc5..5695c11e 100644 --- a/Source/HBIOS/ch376-native/source-doc/base-drv/ch376.h +++ b/Source/HBIOS/ch376-native/source-doc/base-drv/ch376.h @@ -96,11 +96,14 @@ extern usb_error result; { \ result = fn; \ if (result != USB_ERR_OK) \ - return result; \ + goto done; \ } #define RETURN_CHECK(fn) \ - { return fn; } + { \ + result = fn; \ + goto done; \ + } #define TRACE_USB_ERROR(result) @@ -159,9 +162,7 @@ extern usb_error ch_data_out_transfer(const uint8_t *buffer, int16_t buffer_leng inline void ch_configure_nak_retry(const ch_nak_retry_type retry, const uint8_t number_of_retries) { ch_command(CH_CMD_WRITE_VAR8); CH376_DATA_PORT = CH_VAR_RETRY_TIMES; - delay(); CH376_DATA_PORT = retry << 6 | (number_of_retries & 0x1F); - delay(); } #define ch_configure_nak_retry_indefinite() ch_configure_nak_retry(CH_NAK_RETRY_INDEFINITE, 0x1F) diff --git a/Source/HBIOS/ch376-native/source-doc/base-drv/critical-section.c b/Source/HBIOS/ch376-native/source-doc/base-drv/critical-section.c new file mode 100644 index 00000000..37ad03b2 --- /dev/null +++ b/Source/HBIOS/ch376-native/source-doc/base-drv/critical-section.c @@ -0,0 +1,8 @@ +#include "critical-section.h" +#include + +uint8_t in_critical_usb_section = 0; + +void critical_begin() { in_critical_usb_section++; } + +void critical_end() { in_critical_usb_section--; } diff --git a/Source/HBIOS/ch376-native/source-doc/base-drv/critical-section.h b/Source/HBIOS/ch376-native/source-doc/base-drv/critical-section.h new file mode 100644 index 00000000..2ddb3961 --- /dev/null +++ b/Source/HBIOS/ch376-native/source-doc/base-drv/critical-section.h @@ -0,0 +1,13 @@ +#ifndef __CRITICAL_BLOCKS_H__ +#define __CRITICAL_BLOCKS_H__ + +#include + +extern uint8_t in_critical_usb_section; + +void critical_begin(); +void critical_end(); + +#define is_in_critical_section() (in_critical_usb_section != 0) + +#endif diff --git a/Source/HBIOS/ch376-native/source-doc/base-drv/dev_transfers.c b/Source/HBIOS/ch376-native/source-doc/base-drv/dev_transfers.c index e30284ea..9abc2988 100644 --- a/Source/HBIOS/ch376-native/source-doc/base-drv/dev_transfers.c +++ b/Source/HBIOS/ch376-native/source-doc/base-drv/dev_transfers.c @@ -16,6 +16,9 @@ #include "protocol.h" #include +#include + +#include "ez80-helpers.h" /** * @brief Perform a USB control transfer (in or out) * See https://www.beyondlogic.org/usbnutshell/usb4.shtml for a description of the USB control transfer @@ -31,8 +34,6 @@ usb_error usbdev_control_transfer(device_config *const device, const setup_packe usb_error usbdev_blk_out_trnsfer(device_config *const dev, const uint8_t *const buffer, const uint16_t buffer_size) { - usb_error result; - endpoint_param *const endpoint = &dev->endpoints[ENDPOINT_BULK_OUT]; result = usb_data_out_transfer(buffer, buffer_size, dev->address, endpoint); @@ -44,12 +45,12 @@ usb_error usbdev_blk_out_trnsfer(device_config *const dev, const uint8_t *const } RETURN_CHECK(result); + +done: + return result; } usb_error usbdev_bulk_in_transfer(device_config *const dev, uint8_t *const buffer, uint8_t *const buffer_size) { - - usb_error result; - endpoint_param *const endpoint = &dev->endpoints[ENDPOINT_BULK_IN]; result = usb_data_in_transfer_n(buffer, buffer_size, dev->address, endpoint); @@ -61,6 +62,8 @@ usb_error usbdev_bulk_in_transfer(device_config *const dev, uint8_t *const buffe } RETURN_CHECK(result); +done: + return result; } usb_error usbdev_dat_in_trnsfer(device_config *const device, @@ -68,8 +71,6 @@ usb_error usbdev_dat_in_trnsfer(device_config *const device, const uint16_t buffer_size, const usb_endpoint_type endpoint_type) { - usb_error result; - endpoint_param *const endpoint = &device->endpoints[endpoint_type]; result = usb_data_in_transfer(buffer, buffer_size, device->address, endpoint); @@ -81,12 +82,11 @@ usb_error usbdev_dat_in_trnsfer(device_config *const device, } RETURN_CHECK(result); +done: + return result; } -usb_error usbdev_dat_in_trnsfer_0(device_config *const device, uint8_t *const buffer, const uint8_t buffer_size) __sdcccall(1) { - - usb_error result; - +usb_error usbdev_dat_in_trnsfer_0(device_config *const device, uint8_t *const buffer, const uint8_t buffer_size) { endpoint_param *const endpoint = &device->endpoints[0]; result = usb_data_in_transfer(buffer, buffer_size, device->address, endpoint); @@ -97,5 +97,5 @@ usb_error usbdev_dat_in_trnsfer_0(device_config *const device, uint8_t *const bu return USB_ERR_STALL; } - RETURN_CHECK(result); + return result; } diff --git a/Source/HBIOS/ch376-native/source-doc/base-drv/dev_transfers.h b/Source/HBIOS/ch376-native/source-doc/base-drv/dev_transfers.h index 0c0a92eb..8eda8748 100644 --- a/Source/HBIOS/ch376-native/source-doc/base-drv/dev_transfers.h +++ b/Source/HBIOS/ch376-native/source-doc/base-drv/dev_transfers.h @@ -62,7 +62,6 @@ extern usb_error usbdev_dat_in_trnsfer(device_config *const device, const uint16_t buffer_size, const usb_endpoint_type endpoint_type); -extern usb_error usbdev_dat_in_trnsfer_0(device_config *const device, uint8_t *const buffer, const uint8_t buffer_size) - __sdcccall(1); +extern usb_error usbdev_dat_in_trnsfer_0(device_config *const device, uint8_t *const buffer, const uint8_t buffer_size); #endif diff --git a/Source/HBIOS/ch376-native/source-doc/base-drv/enumerate.c b/Source/HBIOS/ch376-native/source-doc/base-drv/enumerate.c index 86eca0a6..8393ec65 100644 --- a/Source/HBIOS/ch376-native/source-doc/base-drv/enumerate.c +++ b/Source/HBIOS/ch376-native/source-doc/base-drv/enumerate.c @@ -94,6 +94,8 @@ usb_error op_capture_hub_driver_interface(_working *const working) __sdcccall(1) hub_config.type = USB_IS_HUB; CHECK(configure_device(working, interface, (device_config *const)&hub_config)); RETURN_CHECK(configure_usb_hub(working)); +done: + return result; } usb_error op_cap_drv_intf(_working *const working) __z88dk_fastcall { @@ -129,25 +131,21 @@ usb_error op_cap_drv_intf(_working *const working) __z88dk_fastcall { } } - CHECK(op_parse_endpoint(working)); + result = op_parse_endpoint(working); +done: return result; } usb_error op_id_class_drv(_working *const working) __sdcccall(1) { - usb_error result; const interface_descriptor *const ptr = (const interface_descriptor *)working->ptr; working->usb_device = ptr->bLength > 5 ? identify_class_driver(working) : 0; - CHECK(op_cap_drv_intf(working)); - - return result; + return op_cap_drv_intf(working); } usb_error op_get_cfg_desc(_working *const working) __sdcccall(1) { - usb_error result; - memset(working->config.buffer, 0, MAX_CONFIG_SIZE); const uint8_t max_packet_size = working->desc.bMaxPacketSize0; @@ -158,8 +156,8 @@ usb_error op_get_cfg_desc(_working *const working) __sdcccall(1) { working->ptr = (working->config.buffer + sizeof(config_descriptor)); working->interface_count = working->config.desc.bNumInterfaces; - CHECK(op_id_class_drv(working)); - + return op_id_class_drv(working); +done: return result; } @@ -184,6 +182,8 @@ usb_error read_all_configs(enumeration_state *const state) { } return USB_ERR_OK; +done: + return result; } usb_error enumerate_all_devices(void) { @@ -196,8 +196,7 @@ usb_error enumerate_all_devices(void) { work_area->count_of_detected_usb_devices = state.next_device_address; - CHECK(result); - +done: return result; } diff --git a/Source/HBIOS/ch376-native/source-doc/base-drv/enumerate_hub.c b/Source/HBIOS/ch376-native/source-doc/base-drv/enumerate_hub.c index 63cde3bc..d838c452 100644 --- a/Source/HBIOS/ch376-native/source-doc/base-drv/enumerate_hub.c +++ b/Source/HBIOS/ch376-native/source-doc/base-drv/enumerate_hub.c @@ -77,4 +77,6 @@ usb_error configure_usb_hub(_working *const working) __z88dk_fastcall { } while (--i != 0); return USB_ERR_OK; +done: + return result; } diff --git a/Source/HBIOS/ch376-native/source-doc/base-drv/protocol.c b/Source/HBIOS/ch376-native/source-doc/base-drv/protocol.c index e5c5101c..73f96a85 100644 --- a/Source/HBIOS/ch376-native/source-doc/base-drv/protocol.c +++ b/Source/HBIOS/ch376-native/source-doc/base-drv/protocol.c @@ -27,12 +27,10 @@ const setup_packet cmd_get_device_descriptor = {0x80, 6, {0, 1}, {0, 0}, 8}; * @return usb_error USB_ERR_OK if all good, otherwise specific error code */ usb_error usbtrn_get_descriptor(device_descriptor *const buffer) { - usb_error result; setup_packet cmd; cmd = cmd_get_device_descriptor; cmd.wLength = 8; - debugger(); result = usb_control_transfer(&cmd, (uint8_t *)buffer, 0, 8); CHECK(result); @@ -42,6 +40,9 @@ usb_error usbtrn_get_descriptor(device_descriptor *const buffer) { result = usb_control_transfer(&cmd, (uint8_t *)buffer, 0, buffer->bMaxPacketSize0); RETURN_CHECK(result); + +done: + return result; } /** @@ -51,7 +52,6 @@ usb_error usbtrn_get_descriptor(device_descriptor *const buffer) { * @return usb_error USB_ERR_OK if all good, otherwise specific error code */ usb_error usbtrn_get_descriptor2(device_descriptor *const buffer, const uint8_t device_address) { - usb_error result; setup_packet cmd; cmd = cmd_get_device_descriptor; cmd.wLength = 8; @@ -63,6 +63,8 @@ usb_error usbtrn_get_descriptor2(device_descriptor *const buffer, const uint8_t cmd = cmd_get_device_descriptor; cmd.wLength = 18; RETURN_CHECK(usb_control_transfer(&cmd, (uint8_t *)buffer, device_address, buffer->bMaxPacketSize0)); +done: + return result; } const setup_packet cmd_set_device_address = {0x00, 5, {0, 0}, {0, 0}, 0}; @@ -119,7 +121,7 @@ usb_error usbtrn_get_config_descriptor(config_descriptor *const buffer, cmd.bValue[0] = config_index; cmd.wLength = (uint16_t)buffer_size; - RETURN_CHECK(usb_control_transfer(&cmd, (uint8_t *)buffer, device_address, max_packet_size)); + return usb_control_transfer(&cmd, (uint8_t *)buffer, device_address, max_packet_size); } usb_error usbtrn_gfull_cfg_desc(const uint8_t config_index, @@ -127,7 +129,6 @@ usb_error usbtrn_gfull_cfg_desc(const uint8_t config_index, const uint8_t max_packet_size, const uint8_t max_buffer_size, uint8_t *const buffer) { - usb_error result; CHECK(usbtrn_get_config_descriptor((config_descriptor *)buffer, config_index, sizeof(config_descriptor), device_address, max_packet_size)); @@ -139,6 +140,8 @@ usb_error usbtrn_gfull_cfg_desc(const uint8_t config_index, CHECK(usbtrn_get_config_descriptor((config_descriptor *)buffer, config_index, max_length, device_address, max_packet_size)); return USB_ERR_OK; +done: + return result; } const setup_packet usb_cmd_clear_endpoint_halt = {2, 1, {0, 0}, {255, 0}, 0}; // ;byte 4 is the endpoint to be cleared @@ -148,7 +151,5 @@ usb_error usbtrn_clear_endpoint_halt(const uint8_t endpoint_number, const uint8_ cmd = usb_cmd_clear_endpoint_halt; cmd.bIndex[0] = endpoint_number; - usb_error result = usb_control_transfer(&cmd, (uint8_t *)0, device_address, max_packet_size); - - RETURN_CHECK(result); + return usb_control_transfer(&cmd, (uint8_t *)0, device_address, max_packet_size); } diff --git a/Source/HBIOS/ch376-native/source-doc/base-drv/transfers.c b/Source/HBIOS/ch376-native/source-doc/base-drv/transfers.c index c19efcc5..a8df10ac 100644 --- a/Source/HBIOS/ch376-native/source-doc/base-drv/transfers.c +++ b/Source/HBIOS/ch376-native/source-doc/base-drv/transfers.c @@ -13,11 +13,11 @@ #include "transfers.h" #include "ch376.h" #include "delay.h" -#include "z80.h" -#include - #include "ez80-helpers.h" #include "print.h" +#include "z80.h" +#include +#include #define LOWER_SAFE_RAM_ADDRESS 0x8000 @@ -56,6 +56,8 @@ usb_error usb_control_transfer(const setup_packet *const cmd_packet, if (transferIn && buffer == 0) return USB_ERR_OTHER; + critical_begin(); + ch_set_usb_address(device_address); ch_write_data((const uint8_t *)cmd_packet, sizeof(setup_packet)); @@ -74,12 +76,13 @@ usb_error usb_control_transfer(const setup_packet *const cmd_packet, if (transferIn) { ch_command(CH_CMD_WR_HOST_DATA); CH376_DATA_PORT = 0; - delay(); ch_issue_token_out_ep0(); result = ch_long_wait_int_and_get_status(); /* sometimes we get STALL here - seems to be ok to ignore */ - if (result == USB_ERR_OK || result == USB_ERR_STALL) - return USB_ERR_OK; + if (result == USB_ERR_OK || result == USB_ERR_STALL) { + result = USB_ERR_OK; + goto done; + } RETURN_CHECK(result); } @@ -88,6 +91,10 @@ usb_error usb_control_transfer(const setup_packet *const cmd_packet, result = ch_long_wait_int_and_get_status(); RETURN_CHECK(result); + +done: + critical_end(); + return result; } usb_error @@ -126,9 +133,15 @@ usb_dat_in_trns_n_ext(uint8_t *buffer, uint16_t *buffer_size, const uint8_t devi */ usb_error usb_data_in_transfer(uint8_t *buffer, const uint16_t buffer_size, const uint8_t device_address, endpoint_param *const endpoint) { + critical_begin(); + ch_set_usb_address(device_address); - return ch_data_in_transfer(buffer, buffer_size, endpoint); + result = ch_data_in_transfer(buffer, buffer_size, endpoint); + + critical_end(); + + return result; } /** @@ -142,21 +155,15 @@ usb_data_in_transfer(uint8_t *buffer, const uint16_t buffer_size, const uint8_t */ usb_error usb_data_in_transfer_n(uint8_t *buffer, uint8_t *const buffer_size, const uint8_t device_address, endpoint_param *const endpoint) { - ch_set_usb_address(device_address); + critical_begin(); - return ch_data_in_transfer_n(buffer, buffer_size, endpoint); -} + ch_set_usb_address(device_address); -usb_error -usb_dat_out_trns_ext(const uint8_t *buffer, uint16_t buffer_size, const uint8_t device_address, endpoint_param *const endpoint) { + result = ch_data_in_transfer_n(buffer, buffer_size, endpoint); - if (buffer != 0 && (uint16_t)buffer < LOWER_SAFE_RAM_ADDRESS) - return USB_BAD_ADDRESS; + critical_end(); - if ((uint16_t)endpoint < LOWER_SAFE_RAM_ADDRESS) - return USB_BAD_ADDRESS; - - return usb_data_out_transfer(buffer, buffer_size, device_address, endpoint); + return result; } /** @@ -170,7 +177,13 @@ usb_dat_out_trns_ext(const uint8_t *buffer, uint16_t buffer_size, const uint8_t */ usb_error usb_data_out_transfer(const uint8_t *buffer, uint16_t buffer_size, const uint8_t device_address, endpoint_param *const endpoint) { + critical_begin(); + ch_set_usb_address(device_address); - return ch_data_out_transfer(buffer, buffer_size, endpoint); + result = ch_data_out_transfer(buffer, buffer_size, endpoint); + + critical_end(); + + return result; } diff --git a/Source/HBIOS/ch376-native/source-doc/base-drv/z80.h b/Source/HBIOS/ch376-native/source-doc/base-drv/z80.h index d9eaf0bb..a086bfeb 100644 --- a/Source/HBIOS/ch376-native/source-doc/base-drv/z80.h +++ b/Source/HBIOS/ch376-native/source-doc/base-drv/z80.h @@ -3,15 +3,4 @@ #include -#define EI __asm__("EI"); -#define DI __asm__("DI"); -#define HALT __asm__("HALT"); - -typedef void (*jump_fn_t)(void) __z88dk_fastcall; - -typedef struct { - uint8_t jump_op_code; // JMP or CALL - jump_fn_t address; -} z80_jump_t; - #endif diff --git a/Source/HBIOS/ch376-native/source-doc/convert-for-uz80as.sh b/Source/HBIOS/ch376-native/source-doc/convert-for-uz80as.sh index c94c67c0..3403b826 100755 --- a/Source/HBIOS/ch376-native/source-doc/convert-for-uz80as.sh +++ b/Source/HBIOS/ch376-native/source-doc/convert-for-uz80as.sh @@ -29,7 +29,8 @@ sed -E \ -e 's/\s+or\s+a,\((ix\+[0-9-]+)\)/\tor\t\(\1\)/g' \ -e 's/\s+or\s+a,\((ix\-[0-9-]+)\)/\tor\t\(\1\)/g' \ -e 's/\s+or\s+a,\((iy\+[0-9-]+)\)/\tor\t\(\1\)/g' \ - -e 's/\s+or\s+a,\((hl)\)/\tor\t\(\1\)/g' \ + -e 's/\s+or\s+a,\s*\((hl)\)/\tor\t\(\1\)/g' \ + -e 's/\s+sub\s+a,\s*\((hl)\)/\tsub\t\(\1\)/g' \ -e 's/\s+cp\s+a,(0x[0-9A-Fa-f]{2})/\tcp\t\1/g' \ -e 's/\s+or\s+a,(0x[0-9A-Fa-f]{2})/\tor\t\1/g' \ -e 's/\s+xor\s+a,(0x[0-9A-Fa-f]{2})/\txor\t\1/g' \ diff --git a/Source/HBIOS/ch376-native/source-doc/depends.d b/Source/HBIOS/ch376-native/source-doc/depends.d index 9c073580..084400b5 100644 --- a/Source/HBIOS/ch376-native/source-doc/depends.d +++ b/Source/HBIOS/ch376-native/source-doc/depends.d @@ -1,5 +1,6 @@ ./base-drv/dev_transfers.c: base-drv/dev_transfers.c ././source-doc/base-drv/dev_transfers.h ././source-doc/base-drv/ch376.h ././source-doc/base-drv/ch376inc.h ././source-doc/base-drv/delay.h ././source-doc/base-drv/transfers.h ././source-doc/base-drv/protocol.h +./base-drv/critical-section.c: base-drv/critical-section.c ././source-doc/base-drv/critical-section.h ./base-drv/enumerate.c: base-drv/enumerate.c ././source-doc/base-drv/enumerate.h ././source-doc/base-drv/ch376.h ././source-doc/base-drv/ch376inc.h ././source-doc/base-drv/delay.h ././source-doc/base-drv/protocol.h ././source-doc/base-drv/dev_transfers.h ././source-doc/base-drv/transfers.h ././source-doc/base-drv/usb_state.h ././source-doc/base-drv/enumerate_hub.h ././source-doc/base-drv/enumerate_storage.h ././source-doc/base-drv/work-area.h ././source-doc/base-drv/print.h ./base-drv/usb_state.c: base-drv/usb_state.c ././source-doc/base-drv/usb_state.h ././source-doc/base-drv/ch376.h ././source-doc/base-drv/ch376inc.h ././source-doc/base-drv/delay.h ././source-doc/base-drv/protocol.h ././source-doc/base-drv/dev_transfers.h ././source-doc/base-drv/transfers.h ././source-doc/base-drv/work-area.h ./base-drv/class_hub.c: base-drv/class_hub.c ././source-doc/base-drv/class_hub.h ././source-doc/base-drv/ch376.h ././source-doc/base-drv/ch376inc.h ././source-doc/base-drv/delay.h ././source-doc/base-drv/protocol.h ././source-doc/base-drv/dev_transfers.h ././source-doc/base-drv/transfers.h ././source-doc/base-drv/usb_state.h @@ -14,15 +15,16 @@ ./ufi-drv/ufi-init.c: ufi-drv/ufi-init.c ././source-doc/ufi-drv/class_ufi.h ././source-doc/base-drv//transfers.h ././source-doc/ufi-drv/usb_cbi.h ./ufi-drv/usb_cbi.c: ufi-drv/usb_cbi.c ././source-doc/ufi-drv/usb_cbi.h ./ufi-drv/class_ufi.c: ufi-drv/class_ufi.c ././source-doc/ufi-drv/class_ufi.h ././source-doc/base-drv//transfers.h ././source-doc/ufi-drv/usb_cbi.h -./keyboard/kyb-init.c: keyboard/kyb-init.c ././source-doc/base-drv//ch376inc.h ././source-doc/base-drv//delay.h ././source-doc/keyboard/class_hid.h ././source-doc/keyboard/class_hid_keyboard.h +./keyboard/kyb-init.c: keyboard/kyb-init.c ././source-doc/keyboard/class_hid.h ././source-doc/base-drv//transfers.h ././source-doc/keyboard/class_hid_keyboard.h ./keyboard/class_hid.c: keyboard/class_hid.c ././source-doc/keyboard/class_hid.h ././source-doc/base-drv//transfers.h +./keyboard/class_hid_keyboard.c: keyboard/class_hid_keyboard.c ././source-doc/keyboard/class_hid_keyboard.h ./scsi-drv/scsi-init.c: scsi-drv/scsi-init.c ././source-doc/scsi-drv/class_scsi.h ././source-doc/base-drv//ch376inc.h ././source-doc/base-drv//delay.h ././source-doc/base-drv//transfers.h ./scsi-drv/class_scsi.c: scsi-drv/class_scsi.c ././source-doc/scsi-drv/class_scsi.h ././source-doc/base-drv//ch376inc.h ././source-doc/base-drv//delay.h ././source-doc/base-drv//transfers.h ## -./base-drv.s: base-drv/./dev_transfers.c.s base-drv/./enumerate.c.s base-drv/./usb_state.c.s base-drv/./class_hub.c.s base-drv/./enumerate_storage.c.s base-drv/./enumerate_hub.c.s base-drv/./usb-base-drv.c.s base-drv/./transfers.c.s base-drv/./ch376.c.s base-drv/./protocol.c.s base-drv/./work-area.c.s base-drv/./usb-init.c.s +./base-drv.s: base-drv/./dev_transfers.c.s base-drv/./critical-section.c.s base-drv/./enumerate.c.s base-drv/./usb_state.c.s base-drv/./class_hub.c.s base-drv/./enumerate_storage.c.s base-drv/./enumerate_hub.c.s base-drv/./usb-base-drv.c.s base-drv/./transfers.c.s base-drv/./ch376.c.s base-drv/./protocol.c.s base-drv/./work-area.c.s base-drv/./usb-init.c.s ## ./scsi-drv.s: scsi-drv/./scsi-init.c.s scsi-drv/./class_scsi.c.s ## ./ufi-drv.s: ufi-drv/./ufi-init.c.s ufi-drv/./usb_cbi.c.s ufi-drv/./class_ufi.c.s ## -./keyboard.s: keyboard/./kyb-init.c.s keyboard/./class_hid.c.s +./keyboard.s: keyboard/./kyb-init.c.s keyboard/./class_hid.c.s keyboard/./class_hid_keyboard.c.s diff --git a/Source/HBIOS/ch376-native/source-doc/keyboard/class_hid.c b/Source/HBIOS/ch376-native/source-doc/keyboard/class_hid.c index b8ccd822..781d9d9f 100644 --- a/Source/HBIOS/ch376-native/source-doc/keyboard/class_hid.c +++ b/Source/HBIOS/ch376-native/source-doc/keyboard/class_hid.c @@ -4,33 +4,26 @@ const setup_packet cmd_hid_set = {0x21, HID_SET_PROTOCOL, {0, 0}, {0, 0}, 0}; usb_error hid_set_protocol(const device_config_keyboard *const dev, const uint8_t protocol) __sdcccall(1) { - usb_error result; setup_packet cmd; cmd = cmd_hid_set; cmd.bRequest = HID_SET_PROTOCOL; cmd.bValue[0] = protocol; - result = usb_control_transfer(&cmd, NULL, dev->address, dev->max_packet_size); - - RETURN_CHECK(result); + return usb_control_transfer(&cmd, NULL, dev->address, dev->max_packet_size); } usb_error hid_set_idle(const device_config_keyboard *const dev, const uint8_t duration) __sdcccall(1) { - usb_error result; setup_packet cmd; cmd = cmd_hid_set; cmd.bRequest = HID_SET_IDLE; cmd.bValue[0] = duration; - result = usb_control_transfer(&cmd, NULL, dev->address, dev->max_packet_size); - - RETURN_CHECK(result); + return usb_control_transfer(&cmd, NULL, dev->address, dev->max_packet_size); } usb_error hid_get_input_report(const device_config_keyboard *const dev, uint8_t const *report) __sdcccall(1) { - usb_error result; setup_packet cmd; cmd = cmd_hid_set; @@ -40,7 +33,5 @@ usb_error hid_get_input_report(const device_config_keyboard *const dev, uint8_t cmd.bRequest = HID_GET_REPORT; cmd.wLength = 8; - result = usb_control_transfer(&cmd, report, dev->address, dev->max_packet_size); - - RETURN_CHECK(result); + return usb_control_transfer(&cmd, report, dev->address, dev->max_packet_size); } diff --git a/Source/HBIOS/ch376-native/source-doc/keyboard/class_hid_keyboard.c b/Source/HBIOS/ch376-native/source-doc/keyboard/class_hid_keyboard.c new file mode 100644 index 00000000..6db81605 --- /dev/null +++ b/Source/HBIOS/ch376-native/source-doc/keyboard/class_hid_keyboard.c @@ -0,0 +1,343 @@ +#include "class_hid_keyboard.h" + +#define ESC 0x1B + +/** + * scan codes sourced from https://deskthority.net/wiki/Scancode + * + */ +char scancodes_shift_table[128] = { + 0x00, /*Reserved*/ + 0x00, /*Reserved*/ + 0x00, /*Reserved*/ + 0x00, /*Reserved*/ + + /* 0x04 */ + 'A', + 'B', + 'C', + 'D', + 'E', + 'F', + 'G', + 'H', + + /* 0x0C */ + 'I', + 'J', + 'K', + 'L', + 'M', + 'N', + 'O', + 'P', + + /* 0X14 */ + 'Q', + 'R', + 'S', + 'T', + 'U', + 'V', + 'W', + 'X', + + /* 0X1C */ + 'Y', + 'Z', + '!', + '@', + '#', + '$', + '%', + '^', + + /* 0x24 */ + '&', + '*', + '(', + ')', + '\r', + ESC, + '\b', + '\t', + + /* 0x2C */ + ' ', + '_', + '+', + '{', + '}', + '|', + '~', + ':', + + /* 0x34 */ + '"', + '~', + '<', + '>', + '?', + 0x00 /*CAPSLOCK*/, + 0x00 /* F1 */, + 0x00 /* F2 */, + + /* 0x3C */ + 0x00 /* F3 */, + 0x00 /* F4 */, + 0x00 /* F5 */, + 0x00 /* F6 */, + 0x00 /* F7 */, + 0x00 /* F8 */, + 0x00 /* F9 */, + 0x00 /* F10 */, + + /* 0x44 */ + 0x00 /* F11 */, + 0x00 /* F12 */, + 0x00 /* PRINTSCREEN */, + 0x00 /* SCROLLLOCK */, + 0x00 /* PAUSE */, + 0x00 /* INSERT */, + 0x00 /* HOME */, + 0x00 /* PAGEUP */, + + /* 0x4C */ + 0x00 /* DELETE */, + 0x00 /* END */, + 0x00 /* PAGEDOWN */, + 0x00 /* RIGHT */, + 0x00 /* LEFT */, + 0x00 /* DOWN */, + 0x00 /* UP */, + 0x00 /* NUMLOCK */, + + /* 0x54 */ + '/' /* KP / */, + '*' /* KP * */, + '-' /* KP - */, + '+' /* KP + */, + '\r' /* KP ENTER */, + '1' /* KP 1 */, + '2' /* KP 2 */, + '3' /* KP 3 */, + + /* 0x5C */ + '4' /* KP 4 */, + '5' /* KP 5 */, + '6' /* KP 6 */, + '7' /* KP 7 */, + '8' /* KP 8 */, + '9' /* KP 9 */, + '0' /* KP 0 */, + '.' /* KP . */, + + /* 0x64 */ + '\\', + 0x00 /* MENU */, + 0x00 /* POWER */, + '=' /* KP = */, + 0x00 /* F13 */, + 0x00 /* F14 */, + 0x00 /* F15 */, + 0x00 /* F16 */, + + /* 0x6C */ + 0x00 /* F17 */, + 0x00 /* F18 */, + 0x00 /* F19 */, + 0x00 /* F20 */, + 0x00 /* F21 */, + 0x00 /* F22 */, + 0x00 /* F23 */, + 0x00 /* F24 */, + + /* 0x74 */ + 0x00 /* EXECUTE */, + 0x00 /* HELP */, + 0x00 /* MENU */, + 0x00 /* SELECT */, + 0x00 /* STOP */, + 0x00 /* AGAIN */, + 0x00 /* UNDO */, + 0x00 /* CUT */, + + /* 0x7C */ + 0x00 /* COPY */, + 0x00 /* PASTE */, + 0x00 /* FIND */, + 0x00 /* MUTE */, +}; + +char scancodes_table[128] = { + 0x00, /*Reserved*/ + 0x00, /*Reserved*/ + 0x00, /*Reserved*/ + 0x00, /*Reserved*/ + + /* 0x04 */ + 'a', + 'b', + 'c', + 'd', + 'e', + 'f', + 'g', + 'h', + + /* 0x0C */ + 'i', + 'j', + 'k', + 'l', + 'm', + 'n', + 'o', + 'p', + + /* 0x14 */ + 'q', + 'r', + 's', + 't', + 'u', + 'v', + 'w', + 'x', + + /* 0x1C */ + 'y', + 'z', + '1', + '2', + '3', + '4', + '5', + '6', + + /* 0x24 */ + '7', + '8', + '9', + '0', + '\r', + ESC, + '\b', + '\t', + + /* 0x2C */ + ' ', + '-', + '=', + '[', + ']', + '\\', + '#', + ';', + + /* 0x34 */ + '\'', + '`', + ',', + '.', + '/', + 0x00 /*CAPSLOCK*/, + 0x00 /* F1 */, + 0x00 /* F2 */, + + /* 0x3C */ + 0x00 /* F3 */, + 0x00 /* F4 */, + 0x00 /* F5 */, + 0x00 /* F6 */, + 0x00 /* F7 */, + 0x00 /* F8 */, + 0x00 /* F9 */, + 0x00 /* F10 */, + + /* 0x44 */ + 0x00 /* F11 */, + 0x00 /* F12 */, + 0x00 /* PRINTSCREEN */, + 0x00 /* SCROLLLOCK */, + 0x00 /* PAUSE */, + 0x00 /* INSERT */, + 0x00 /* HOME */, + 0x00 /* PAGEUP */, + + /* 0x4C */ + 0x00 /* DELETE */, + 0x00 /* END */, + 0x00 /* PAGEDOWN */, + 0x00 /* RIGHT */, + 0x00 /* LEFT */, + 0x00 /* DOWN */, + 0x00 /* UP */, + 0x00 /* NUMLOCK */, + + /* 0x54 */ + '/' /* KP / */, + '*' /* KP * */, + '-' /* KP - */, + '+' /* KP + */, + '\r' /* KP ENTER */, + '1' /* KP 1 */, + '2' /* KP 2 */, + '3' /* KP 3 */, + + /* 0x5C */ + '4' /* KP 4 */, + '5' /* KP 5 */, + '6' /* KP 6 */, + '7' /* KP 7 */, + '8' /* KP 8 */, + '9' /* KP 9 */, + '0' /* KP 0 */, + '.' /* KP . */, + + /* 0x64 */ + '\\', + 0x00 /* MENU */, + 0x00 /* POWER */, + '=' /* KP = */, + 0x00 /* F13 */, + 0x00 /* F14 */, + 0x00 /* F15 */, + 0x00 /* F16 */, + + /* 0x6C */ + 0x00 /* F17 */, + 0x00 /* F18 */, + 0x00 /* F19 */, + 0x00 /* F20 */, + 0x00 /* F21 */, + 0x00 /* F22 */, + 0x00 /* F23 */, + 0x00 /* F24 */, + + /* 0x74 */ + 0x00 /* EXECUTE */, + 0x00 /* HELP */, + 0x00 /* MENU */, + 0x00 /* SELECT */, + 0x00 /* STOP */, + 0x00 /* AGAIN */, + 0x00 /* UNDO */, + 0x00 /* CUT */, + + /* 0x7C */ + 0x00 /* COPY */, + 0x00 /* PASTE */, + 0x00 /* FIND */, + 0x00 /* MUTE */, +}; + +char scancode_to_char(const uint8_t modifier_keys, const uint8_t code) __sdcccall(1) { + if (code >= 0x80) + return 0; + + if (modifier_keys & (KEY_MOD_LSHIFT | KEY_MOD_RSHIFT)) + return scancodes_shift_table[code]; + + return scancodes_table[code]; +} diff --git a/Source/HBIOS/ch376-native/source-doc/keyboard/kyb-init.c b/Source/HBIOS/ch376-native/source-doc/keyboard/kyb-init.c index 6b4bfa82..cb5b4de7 100644 --- a/Source/HBIOS/ch376-native/source-doc/keyboard/kyb-init.c +++ b/Source/HBIOS/ch376-native/source-doc/keyboard/kyb-init.c @@ -1,15 +1,20 @@ #include "class_hid.h" #include "class_hid_keyboard.h" +#include #include #include #include #include +static device_config_keyboard *keyboard_config = 0; + void keyboard_init(void) { - uint8_t index = 1; + uint8_t index = 1; + keyboard_config = NULL; + do { - device_config_keyboard *const keyboard_config = (device_config_keyboard *)get_usb_device_config(index); + keyboard_config = (device_config_keyboard *)get_usb_device_config(index); if (keyboard_config == NULL) break; @@ -21,7 +26,6 @@ void keyboard_init(void) { print_uint16(index); print_string(" $"); - // keyboard_config->drive_index = usb_device_count++; hid_set_protocol(keyboard_config, 1); hid_set_idle(keyboard_config, 0x80); return; @@ -31,24 +35,63 @@ void keyboard_init(void) { print_string("\r\nUSB: KEYBOARD: NOT FOUND$"); } -// void drv_timi_keyboard(void) { -// _usb_state *const p = get_usb_work_area(); -// if (p->active) -// return; +#define KEYBOARD_BUFFER_SIZE 8 +#define KEYBOARD_BUFFER_SIZE_MASK 7 +typedef struct { + uint8_t modifier_keys; + uint8_t key_code; +} keyboard_event; +keyboard_event buffer[KEYBOARD_BUFFER_SIZE] = {{0}}; +uint8_t write_index = 0; +uint8_t read_index = 0; -// p->active = true; +void keyboard_buf_put(const uint8_t modifier_keys, const uint8_t key_code) { + if (key_code >= 0x80 || key_code == 0) + return; // ignore ??? -// device_config_keyboard *const keyboard_config = (device_config_keyboard *)find_device_config(USB_IS_KEYBOARD); + uint8_t next_write_index = (write_index + 1) & KEYBOARD_BUFFER_SIZE_MASK; + if (next_write_index != read_index) { // Check if buffer is not full + buffer[write_index].modifier_keys = modifier_keys; + buffer[write_index].key_code = key_code; + write_index = next_write_index; + } +} -// keyboard_report report; +uint8_t keyboard_buf_size() __sdcccall(1) { + if (write_index >= read_index) + return write_index - read_index; -// ch_configure_nak_retry_disable(); -// const usb_error result = usbdev_data_in_transfer_ep0((device_config *)keyboard_config, (uint8_t *)report, 8); -// ch_configure_nak_retry_3s(); -// if (result == 0) { -// const char c = scancode_to_char(report.bModifierKeys, report.keyCode[0]); -// key_put_into_buf(c); -// } + return KEYBOARD_BUFFER_SIZE - read_index + write_index; +} + +uint32_t keyboard_buf_get_next() { + if (write_index == read_index) // Check if buffer is empty + return 255 << 8; + + const uint8_t modifier_key = buffer[read_index].modifier_keys; + const uint8_t key_code = buffer[read_index].key_code; + read_index = (read_index + 1) & KEYBOARD_BUFFER_SIZE_MASK; + 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; +} -// p->active = false; -// } +void keyboard_buf_flush() { + write_index = 0; + read_index = 0; +} + +uint8_t active = 0; + +keyboard_report report = {0}; + +void keyboard_tick(void) { + if (is_in_critical_section()) + return; + + ch_configure_nak_retry_disable(); + result = usbdev_dat_in_trnsfer_0((device_config *)keyboard_config, (uint8_t *)report, 8); + ch_configure_nak_retry_3s(); + if (result == 0) + keyboard_buf_put(report.bModifierKeys, report.keyCode[0]); +} diff --git a/Source/HBIOS/ch376-native/source-doc/scsi-drv/class_scsi.c b/Source/HBIOS/ch376-native/source-doc/scsi-drv/class_scsi.c index c554e345..b4f34fc2 100644 --- a/Source/HBIOS/ch376-native/source-doc/scsi-drv/class_scsi.c +++ b/Source/HBIOS/ch376-native/source-doc/scsi-drv/class_scsi.c @@ -1,4 +1,5 @@ #include "class_scsi.h" +#include #include #include #include @@ -18,6 +19,8 @@ usb_error do_scsi_cmd(device_config_storage *const dev, if (!send) cbw->bmCBWFlags = 0x80; + critical_begin(); + CHECK(usb_data_out_transfer((uint8_t *)cbw, sizeof(_scsi_command_block_wrapper) + 16, dev->address, &dev->endpoints[ENDPOINT_BULK_OUT])); @@ -36,9 +39,13 @@ usb_error do_scsi_cmd(device_config_storage *const dev, usb_data_in_transfer((uint8_t *)&csw, sizeof(_scsi_command_status_wrapper), dev->address, &dev->endpoints[ENDPOINT_BULK_IN])); if (csw.bCSWStatus != 0 && csw.dCSWTag[0] != cbw->dCBWTag[0]) - return USB_ERR_FAIL; + result = USB_ERR_FAIL; + else + result = USB_ERR_OK; - return USB_ERR_OK; +done: + critical_end(); + return result; } _scsi_read_capacity scsi_read_capacity = {0x25, 0, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0}}; @@ -99,8 +106,10 @@ usb_error scsi_sense_init(device_config_storage *const dev) { scsi_sense_result response; uint8_t counter = 3; + critical_begin(); while ((result = scsi_test(dev)) && --counter > 0) scsi_request_sense(dev, &response); + critical_end(); return result; } diff --git a/Source/HBIOS/ch376-native/source-doc/scsi-drv/scsi-init.c b/Source/HBIOS/ch376-native/source-doc/scsi-drv/scsi-init.c index 37f951a4..9838812f 100644 --- a/Source/HBIOS/ch376-native/source-doc/scsi-drv/scsi-init.c +++ b/Source/HBIOS/ch376-native/source-doc/scsi-drv/scsi-init.c @@ -25,7 +25,6 @@ void chscsi_init(void) { print_uint16(index); print_string(" $"); - // storage_device->drive_index = usb_device_count++; scsi_sense_init(storage_device); dio_add_entry(ch_scsi_fntbl, storage_device); } diff --git a/Source/HBIOS/ch376-native/source-doc/ufi-drv/class_ufi.c b/Source/HBIOS/ch376-native/source-doc/ufi-drv/class_ufi.c index ed5f265a..1a5048b8 100644 --- a/Source/HBIOS/ch376-native/source-doc/ufi-drv/class_ufi.c +++ b/Source/HBIOS/ch376-native/source-doc/ufi-drv/class_ufi.c @@ -41,8 +41,9 @@ usb_error ufi_test_unit_ready(device_config *const storage_device, ufi_request_s result = usb_execute_cbi(storage_device, (uint8_t *)&ufi_cmd_request_sense, false, sizeof(ufi_request_sense_response), (uint8_t *)response, NULL); - RETURN_CHECK(result); +done: + return result; } usb_error ufi_request_sense(device_config *const storage_device, ufi_request_sense_response const *response) { @@ -53,6 +54,8 @@ usb_error ufi_request_sense(device_config *const storage_device, ufi_request_sen (uint8_t *)response, NULL); RETURN_CHECK(result); +done: + return result; } usb_error ufi_read_frmt_caps(device_config *const storage_device, ufi_format_capacities_response const *response) { @@ -78,6 +81,8 @@ usb_error ufi_read_frmt_caps(device_config *const storage_device, ufi_format_cap TRACE_USB_ERROR(result); RETURN_CHECK(result); +done: + return result; } usb_error ufi_inquiry(device_config *const storage_device, ufi_inquiry_response const *response) { @@ -88,6 +93,8 @@ usb_error ufi_inquiry(device_config *const storage_device, ufi_inquiry_response usb_execute_cbi(storage_device, (uint8_t *)&ufi_cmd_inquiry, false, sizeof(ufi_inquiry_response), (uint8_t *)response, NULL); RETURN_CHECK(result); +done: + return result; } usb_error ufi_read_write_sector(device_config *const storage_device, @@ -106,6 +113,8 @@ usb_error ufi_read_write_sector(device_config *const storage_device, usb_error result = usb_execute_cbi(storage_device, (uint8_t *)&cmd, send, 512 * sector_count, (uint8_t *)buffer, sense_codes); RETURN_CHECK(result); +done: + return result; } /** @@ -149,17 +158,16 @@ usb_error ufi_format(device_config *const storage_device, // trace_printf("ufi_format: %d, %02X %02X (len: %d)\r\n", result, sense_codes.bASC, sense_codes.bASCQ, sizeof(parameter_list)); RETURN_CHECK(result); +done: + return result; } usb_error ufi_send_diagnostics(device_config *const storage_device) { - usb_error result; ufi_send_diagnostic_command ufi_cmd_send_diagnostic; ufi_cmd_send_diagnostic = _ufi_cmd_send_diagnostic; - result = usb_execute_cbi(storage_device, (uint8_t *)&ufi_cmd_send_diagnostic, true, 0, NULL, NULL); - - RETURN_CHECK(result); + return usb_execute_cbi(storage_device, (uint8_t *)&ufi_cmd_send_diagnostic, true, 0, NULL, NULL); } uint32_t convert_from_msb_first(const uint8_t *const buffer) { diff --git a/Source/HBIOS/ch376-native/source-doc/ufi-drv/usb_cbi.c b/Source/HBIOS/ch376-native/source-doc/ufi-drv/usb_cbi.c index bf43a45e..e4b76046 100644 --- a/Source/HBIOS/ch376-native/source-doc/ufi-drv/usb_cbi.c +++ b/Source/HBIOS/ch376-native/source-doc/ufi-drv/usb_cbi.c @@ -2,6 +2,7 @@ #include "dev_transfers.h" #include "protocol.h" #include +#include setup_packet cbi2_adsc = {0x21, 0, {0, 0}, {255, 0}, 12}; // ;4th byte is interface number @@ -13,26 +14,27 @@ usb_error usb_execute_cbi(device_config *const storage_device, uint8_t *const buffer, uint8_t *const sense_codes) { - usb_error result; - const uint8_t interface_number = storage_device->interface_number; setup_packet adsc; adsc = cbi2_adsc; adsc.bIndex[0] = interface_number; + critical_begin(); + result = usbdev_control_transfer(storage_device, &adsc, (uint8_t *const)cmd); if (result == USB_ERR_STALL) { if (sense_codes != NULL) usbdev_dat_in_trnsfer(storage_device, sense_codes, 2, ENDPOINT_INTERRUPT_IN); - return USB_ERR_STALL; + result = USB_ERR_STALL; + goto done; } if (result != USB_ERR_OK) { TRACE_USB_ERROR(result); - return result; + goto done; } if (send) { @@ -40,14 +42,14 @@ usb_error usb_execute_cbi(device_config *const storage_device, if (result != USB_ERR_OK) { TRACE_USB_ERROR(result); - return result; + goto done; } } else { result = usbdev_dat_in_trnsfer(storage_device, buffer, buffer_size, ENDPOINT_BULK_IN); if (result != USB_ERR_OK) { TRACE_USB_ERROR(result); - return result; + goto done; } } @@ -56,9 +58,12 @@ usb_error usb_execute_cbi(device_config *const storage_device, if (result != USB_ERR_OK) { TRACE_USB_ERROR(result); - return result; + // goto done; } } - return USB_ERR_OK; +done: + critical_end(); + + return result; } diff --git a/Source/HBIOS/ch376-native/ufi-drv/class_ufi.c.s b/Source/HBIOS/ch376-native/ufi-drv/class_ufi.c.s index f911d4c2..4f118b63 100644 --- a/Source/HBIOS/ch376-native/ufi-drv/class_ufi.c.s +++ b/Source/HBIOS/ch376-native/ufi-drv/class_ufi.c.s @@ -196,10 +196,10 @@ _ufi_test_unit_ready: ld l, e ld h, d ld b,0x0c -l_ufi_test_unit_ready_00103: +l_ufi_test_unit_ready_00104: ld (hl),0x00 inc hl - djnz l_ufi_test_unit_ready_00103 + djnz l_ufi_test_unit_ready_00104 ;source-doc/ufi-drv/./class_ufi.c:37: usb_execute_cbi(storage_device, (uint8_t *)&ufi_cmd_request_test_unit_ready, false, 0, NULL, NULL); ld hl,0x0000 push hl @@ -245,12 +245,12 @@ l_ufi_test_unit_ready_00103: ld h,(ix+5) push hl call _usb_execute_cbi -;source-doc/ufi-drv/./class_ufi.c:45: RETURN_CHECK(result); -;source-doc/ufi-drv/./class_ufi.c:46: } +;source-doc/ufi-drv/./class_ufi.c:46: return result; +;source-doc/ufi-drv/./class_ufi.c:47: } ld sp,ix pop ix ret -;source-doc/ufi-drv/./class_ufi.c:48: usb_error ufi_request_sense(device_config *const storage_device, ufi_request_sense_response const *response) { +;source-doc/ufi-drv/./class_ufi.c:49: usb_error ufi_request_sense(device_config *const storage_device, ufi_request_sense_response const *response) { ; --------------------------------- ; Function ufi_request_sense ; --------------------------------- @@ -261,7 +261,7 @@ _ufi_request_sense: ld hl, -12 add hl, sp ld sp, hl -;source-doc/ufi-drv/./class_ufi.c:50: ufi_cmd_request_sense = _ufi_cmd_request_sense; +;source-doc/ufi-drv/./class_ufi.c:51: ufi_cmd_request_sense = _ufi_cmd_request_sense; ld hl,0 add hl, sp ld c, l @@ -273,7 +273,7 @@ _ufi_request_sense: ld bc,0x000c ldir pop bc -;source-doc/ufi-drv/./class_ufi.c:52: usb_error result = usb_execute_cbi(storage_device, (uint8_t *)&ufi_cmd_request_sense, false, sizeof(ufi_request_sense_response), +;source-doc/ufi-drv/./class_ufi.c:53: usb_error result = usb_execute_cbi(storage_device, (uint8_t *)&ufi_cmd_request_sense, false, sizeof(ufi_request_sense_response), ld e,(ix+6) ld d,(ix+7) ld hl,0x0000 @@ -289,12 +289,12 @@ _ufi_request_sense: ld h,(ix+5) push hl call _usb_execute_cbi -;source-doc/ufi-drv/./class_ufi.c:55: RETURN_CHECK(result); -;source-doc/ufi-drv/./class_ufi.c:56: } +;source-doc/ufi-drv/./class_ufi.c:58: return result; +;source-doc/ufi-drv/./class_ufi.c:59: } ld sp,ix pop ix ret -;source-doc/ufi-drv/./class_ufi.c:58: usb_error ufi_read_frmt_caps(device_config *const storage_device, ufi_format_capacities_response const *response) { +;source-doc/ufi-drv/./class_ufi.c:61: usb_error ufi_read_frmt_caps(device_config *const storage_device, ufi_format_capacities_response const *response) { ; --------------------------------- ; Function ufi_read_frmt_caps ; --------------------------------- @@ -305,14 +305,14 @@ _ufi_read_frmt_caps: ld hl, -24 add hl, sp ld sp, hl -;source-doc/ufi-drv/./class_ufi.c:62: ufi_cmd_read_format_capacities = _ufi_cmd_read_format_capacities; +;source-doc/ufi-drv/./class_ufi.c:65: ufi_cmd_read_format_capacities = _ufi_cmd_read_format_capacities; ld hl,0 add hl, sp ex de, hl ld hl,__ufi_cmd_read_format_capacitie ld bc,0x000c ldir -;source-doc/ufi-drv/./class_ufi.c:63: result = usb_execute_cbi(storage_device, (uint8_t *)&ufi_cmd_read_format_capacities, false, 12, (uint8_t *)response, NULL); +;source-doc/ufi-drv/./class_ufi.c:66: result = usb_execute_cbi(storage_device, (uint8_t *)&ufi_cmd_read_format_capacities, false, 12, (uint8_t *)response, NULL); ld c,(ix+6) ld b,(ix+7) push bc @@ -337,24 +337,26 @@ _ufi_read_frmt_caps: pop af pop af inc sp + ld e, l pop bc -;source-doc/ufi-drv/./class_ufi.c:66: CHECK(result); - ld a, l +;source-doc/ufi-drv/./class_ufi.c:69: CHECK(result); + ld a,e + ld d,a or a jr NZ,l_ufi_read_frmt_caps_00103 -;source-doc/ufi-drv/./class_ufi.c:68: const uint8_t available_length = response->capacity_list_length; +;source-doc/ufi-drv/./class_ufi.c:71: const uint8_t available_length = response->capacity_list_length; ld e,(ix+6) ld d,(ix+7) ld hl,3 add hl, de ld e, (hl) -;source-doc/ufi-drv/./class_ufi.c:70: const uint8_t max_length = +;source-doc/ufi-drv/./class_ufi.c:73: const uint8_t max_length = ld a,0x24 sub e - jr NC,l_ufi_read_frmt_caps_00105 + jr NC,l_ufi_read_frmt_caps_00106 ld e,0x24 -l_ufi_read_frmt_caps_00105: -;source-doc/ufi-drv/./class_ufi.c:74: memcpy(&cmd, &ufi_cmd_read_format_capacities, sizeof(cmd)); +l_ufi_read_frmt_caps_00106: +;source-doc/ufi-drv/./class_ufi.c:77: memcpy(&cmd, &ufi_cmd_read_format_capacities, sizeof(cmd)); push de push bc ex de, hl @@ -367,9 +369,9 @@ l_ufi_read_frmt_caps_00105: ldir pop bc pop de -;source-doc/ufi-drv/./class_ufi.c:75: cmd.allocation_length[1] = max_length; +;source-doc/ufi-drv/./class_ufi.c:78: cmd.allocation_length[1] = max_length; ld (ix-4),e -;source-doc/ufi-drv/./class_ufi.c:77: result = usb_execute_cbi(storage_device, (uint8_t *)&cmd, false, max_length, (uint8_t *)response, NULL); +;source-doc/ufi-drv/./class_ufi.c:80: result = usb_execute_cbi(storage_device, (uint8_t *)&cmd, false, max_length, (uint8_t *)response, NULL); ld d,0x00 ld hl,0x0000 push hl @@ -391,13 +393,16 @@ l_ufi_read_frmt_caps_00105: pop af pop af inc sp -;source-doc/ufi-drv/./class_ufi.c:80: RETURN_CHECK(result); + ld d, l +;source-doc/ufi-drv/./class_ufi.c:84: done: l_ufi_read_frmt_caps_00103: -;source-doc/ufi-drv/./class_ufi.c:81: } +;source-doc/ufi-drv/./class_ufi.c:85: return result; + ld l, d +;source-doc/ufi-drv/./class_ufi.c:86: } ld sp, ix pop ix ret -;source-doc/ufi-drv/./class_ufi.c:83: usb_error ufi_inquiry(device_config *const storage_device, ufi_inquiry_response const *response) { +;source-doc/ufi-drv/./class_ufi.c:88: usb_error ufi_inquiry(device_config *const storage_device, ufi_inquiry_response const *response) { ; --------------------------------- ; Function ufi_inquiry ; --------------------------------- @@ -408,7 +413,7 @@ _ufi_inquiry: ld hl, -12 add hl, sp ld sp, hl -;source-doc/ufi-drv/./class_ufi.c:85: ufi_cmd_inquiry = _ufi_cmd_inquiry; +;source-doc/ufi-drv/./class_ufi.c:90: ufi_cmd_inquiry = _ufi_cmd_inquiry; ld hl,0 add hl, sp ld c, l @@ -420,7 +425,7 @@ _ufi_inquiry: ld bc,0x000c ldir pop bc -;source-doc/ufi-drv/./class_ufi.c:87: usb_error result = +;source-doc/ufi-drv/./class_ufi.c:92: usb_error result = ld e,(ix+6) ld d,(ix+7) ld hl,0x0000 @@ -436,12 +441,12 @@ _ufi_inquiry: ld h,(ix+5) push hl call _usb_execute_cbi -;source-doc/ufi-drv/./class_ufi.c:90: RETURN_CHECK(result); -;source-doc/ufi-drv/./class_ufi.c:91: } +;source-doc/ufi-drv/./class_ufi.c:97: return result; +;source-doc/ufi-drv/./class_ufi.c:98: } ld sp,ix pop ix ret -;source-doc/ufi-drv/./class_ufi.c:93: usb_error ufi_read_write_sector(device_config *const storage_device, +;source-doc/ufi-drv/./class_ufi.c:100: usb_error ufi_read_write_sector(device_config *const storage_device, ; --------------------------------- ; Function ufi_read_write_sector ; --------------------------------- @@ -452,33 +457,33 @@ _ufi_read_write_sector: ld hl, -12 add hl, sp ld sp, hl -;source-doc/ufi-drv/./class_ufi.c:100: memset(&cmd, 0, sizeof(cmd)); +;source-doc/ufi-drv/./class_ufi.c:107: memset(&cmd, 0, sizeof(cmd)); ld hl,0 add hl, sp ld b,0x0c -l_ufi_read_write_sector_00112: +l_ufi_read_write_sector_00113: ld (hl),0x00 inc hl - djnz l_ufi_read_write_sector_00112 -;source-doc/ufi-drv/./class_ufi.c:101: cmd.operation_code = send ? 0x2A : 0x28; + djnz l_ufi_read_write_sector_00113 +;source-doc/ufi-drv/./class_ufi.c:108: cmd.operation_code = send ? 0x2A : 0x28; bit 0,(ix+6) - jr Z,l_ufi_read_write_sector_00103 + jr Z,l_ufi_read_write_sector_00104 ld a,0x2a - jr l_ufi_read_write_sector_00104 -l_ufi_read_write_sector_00103: - ld a,0x28 + jr l_ufi_read_write_sector_00105 l_ufi_read_write_sector_00104: + ld a,0x28 +l_ufi_read_write_sector_00105: ld (ix-12),a -;source-doc/ufi-drv/./class_ufi.c:102: cmd.lba[2] = sector_number >> 8; +;source-doc/ufi-drv/./class_ufi.c:109: cmd.lba[2] = sector_number >> 8; ld a,(ix+8) ld (ix-8),a -;source-doc/ufi-drv/./class_ufi.c:103: cmd.lba[3] = sector_number & 0xFF; +;source-doc/ufi-drv/./class_ufi.c:110: cmd.lba[3] = sector_number & 0xFF; ld a,(ix+7) ld (ix-7),a -;source-doc/ufi-drv/./class_ufi.c:104: cmd.transfer_length[1] = sector_count; +;source-doc/ufi-drv/./class_ufi.c:111: cmd.transfer_length[1] = sector_count; ld a,(ix+9) ld (ix-4),a -;source-doc/ufi-drv/./class_ufi.c:106: usb_error result = usb_execute_cbi(storage_device, (uint8_t *)&cmd, send, 512 * sector_count, (uint8_t *)buffer, sense_codes); +;source-doc/ufi-drv/./class_ufi.c:113: usb_error result = usb_execute_cbi(storage_device, (uint8_t *)&cmd, send, 512 * sector_count, (uint8_t *)buffer, sense_codes); ld a,(ix+9) add a, a ld c,0x00 @@ -500,12 +505,12 @@ l_ufi_read_write_sector_00104: ld h,(ix+5) push hl call _usb_execute_cbi -;source-doc/ufi-drv/./class_ufi.c:108: RETURN_CHECK(result); -;source-doc/ufi-drv/./class_ufi.c:109: } +;source-doc/ufi-drv/./class_ufi.c:117: return result; +;source-doc/ufi-drv/./class_ufi.c:118: } ld sp,ix pop ix ret -;source-doc/ufi-drv/./class_ufi.c:118: usb_error ufi_format(device_config *const storage_device, +;source-doc/ufi-drv/./class_ufi.c:127: usb_error ufi_format(device_config *const storage_device, ; --------------------------------- ; Function ufi_format ; --------------------------------- @@ -516,17 +521,17 @@ _ufi_format: ld hl, -26 add hl, sp ld sp, hl -;source-doc/ufi-drv/./class_ufi.c:125: memset(¶meter_list, 0, sizeof(parameter_list)); +;source-doc/ufi-drv/./class_ufi.c:134: memset(¶meter_list, 0, sizeof(parameter_list)); ld hl,2 add hl, sp push hl ld b,0x0c -l_ufi_format_00103: +l_ufi_format_00104: ld (hl),0x00 inc hl - djnz l_ufi_format_00103 + djnz l_ufi_format_00104 pop bc -;source-doc/ufi-drv/./class_ufi.c:128: cmd = _ufi_cmd_format; +;source-doc/ufi-drv/./class_ufi.c:137: cmd = _ufi_cmd_format; ld hl,14 add hl, sp ex de, hl @@ -535,14 +540,14 @@ l_ufi_format_00103: ld bc,0x000c ldir pop bc -;source-doc/ufi-drv/./class_ufi.c:131: cmd.track_number = track_number; +;source-doc/ufi-drv/./class_ufi.c:140: cmd.track_number = track_number; ld a,(ix+7) ld (ix-10),a -;source-doc/ufi-drv/./class_ufi.c:132: cmd.interleave[1] = 0; +;source-doc/ufi-drv/./class_ufi.c:141: cmd.interleave[1] = 0; ld (ix-8),0x00 -;source-doc/ufi-drv/./class_ufi.c:133: cmd.parameter_list_length[1] = sizeof(parameter_list); +;source-doc/ufi-drv/./class_ufi.c:142: cmd.parameter_list_length[1] = sizeof(parameter_list); ld (ix-4),0x0c -;source-doc/ufi-drv/./class_ufi.c:135: parameter_list.defect_list_header.side = side; +;source-doc/ufi-drv/./class_ufi.c:144: parameter_list.defect_list_header.side = side; ld e, c ld d, b inc de @@ -553,36 +558,36 @@ l_ufi_format_00103: and 0xfe or l ld (de), a -;source-doc/ufi-drv/./class_ufi.c:136: parameter_list.defect_list_header.immediate = 0; +;source-doc/ufi-drv/./class_ufi.c:145: parameter_list.defect_list_header.immediate = 0; ld l, e ld h, d res 1, (hl) -;source-doc/ufi-drv/./class_ufi.c:137: parameter_list.defect_list_header.reserved2 = 0; +;source-doc/ufi-drv/./class_ufi.c:146: parameter_list.defect_list_header.reserved2 = 0; ld l, e ld h, d ld a, (hl) and 0xf3 ld (hl), a -;source-doc/ufi-drv/./class_ufi.c:138: parameter_list.defect_list_header.single_track = 1; +;source-doc/ufi-drv/./class_ufi.c:147: parameter_list.defect_list_header.single_track = 1; ld l, e ld h, d set 4, (hl) -;source-doc/ufi-drv/./class_ufi.c:139: parameter_list.defect_list_header.dcrt = 1; +;source-doc/ufi-drv/./class_ufi.c:148: parameter_list.defect_list_header.dcrt = 1; ld l, e ld h, d set 5, (hl) -;source-doc/ufi-drv/./class_ufi.c:140: parameter_list.defect_list_header.extend = 0; +;source-doc/ufi-drv/./class_ufi.c:149: parameter_list.defect_list_header.extend = 0; ld l, e ld h, d res 6, (hl) -;source-doc/ufi-drv/./class_ufi.c:141: parameter_list.defect_list_header.fov = 1; +;source-doc/ufi-drv/./class_ufi.c:150: parameter_list.defect_list_header.fov = 1; ex de, hl set 7, (hl) -;source-doc/ufi-drv/./class_ufi.c:142: parameter_list.defect_list_header.defect_list_length_msb = 0; +;source-doc/ufi-drv/./class_ufi.c:151: parameter_list.defect_list_header.defect_list_length_msb = 0; ld (ix-22),0x00 -;source-doc/ufi-drv/./class_ufi.c:143: parameter_list.defect_list_header.defect_list_length_lsb = 8; +;source-doc/ufi-drv/./class_ufi.c:152: parameter_list.defect_list_header.defect_list_length_lsb = 8; ld (ix-21),0x08 -;source-doc/ufi-drv/./class_ufi.c:144: memcpy(¶meter_list.format_descriptor, (void *)format, sizeof(ufi_format_capacity_descriptor)); +;source-doc/ufi-drv/./class_ufi.c:153: memcpy(¶meter_list.format_descriptor, (void *)format, sizeof(ufi_format_capacity_descriptor)); ld e,(ix+8) ld d,(ix+9) push bc @@ -595,7 +600,7 @@ l_ufi_format_00103: ld bc,0x0008 ldir pop bc -;source-doc/ufi-drv/./class_ufi.c:146: usb_error result = usb_execute_cbi(storage_device, (uint8_t *)&cmd, true, sizeof(parameter_list), (uint8_t *)¶meter_list, +;source-doc/ufi-drv/./class_ufi.c:155: usb_error result = usb_execute_cbi(storage_device, (uint8_t *)&cmd, true, sizeof(parameter_list), (uint8_t *)¶meter_list, ld hl,0 add hl, sp push hl @@ -612,12 +617,12 @@ l_ufi_format_00103: ld h,(ix+5) push hl call _usb_execute_cbi -;source-doc/ufi-drv/./class_ufi.c:151: RETURN_CHECK(result); -;source-doc/ufi-drv/./class_ufi.c:152: } +;source-doc/ufi-drv/./class_ufi.c:162: return result; +;source-doc/ufi-drv/./class_ufi.c:163: } ld sp,ix pop ix ret -;source-doc/ufi-drv/./class_ufi.c:154: usb_error ufi_send_diagnostics(device_config *const storage_device) { +;source-doc/ufi-drv/./class_ufi.c:165: usb_error ufi_send_diagnostics(device_config *const storage_device) { ; --------------------------------- ; Function ufi_send_diagnostics ; --------------------------------- @@ -628,7 +633,7 @@ _ufi_send_diagnostics: ld hl, -12 add hl, sp ld sp, hl -;source-doc/ufi-drv/./class_ufi.c:158: ufi_cmd_send_diagnostic = _ufi_cmd_send_diagnostic; +;source-doc/ufi-drv/./class_ufi.c:168: ufi_cmd_send_diagnostic = _ufi_cmd_send_diagnostic; ld hl,0 add hl, sp ld c, l @@ -640,7 +645,7 @@ _ufi_send_diagnostics: ld bc,0x000c ldir pop bc -;source-doc/ufi-drv/./class_ufi.c:160: result = usb_execute_cbi(storage_device, (uint8_t *)&ufi_cmd_send_diagnostic, true, 0, NULL, NULL); +;source-doc/ufi-drv/./class_ufi.c:170: return usb_execute_cbi(storage_device, (uint8_t *)&ufi_cmd_send_diagnostic, true, 0, NULL, NULL); ld hl,0x0000 push hl push hl @@ -653,12 +658,11 @@ _ufi_send_diagnostics: ld h,(ix+5) push hl call _usb_execute_cbi -;source-doc/ufi-drv/./class_ufi.c:162: RETURN_CHECK(result); -;source-doc/ufi-drv/./class_ufi.c:163: } +;source-doc/ufi-drv/./class_ufi.c:171: } ld sp,ix pop ix ret -;source-doc/ufi-drv/./class_ufi.c:165: uint32_t convert_from_msb_first(const uint8_t *const buffer) { +;source-doc/ufi-drv/./class_ufi.c:173: uint32_t convert_from_msb_first(const uint8_t *const buffer) { ; --------------------------------- ; Function convert_from_msb_first ; --------------------------------- @@ -668,40 +672,40 @@ _convert_from_msb_first: add ix,sp push af push af -;source-doc/ufi-drv/./class_ufi.c:167: uint8_t *p_output = ((uint8_t *)&result); +;source-doc/ufi-drv/./class_ufi.c:175: uint8_t *p_output = ((uint8_t *)&result); ld hl,0 add hl, sp ex de, hl -;source-doc/ufi-drv/./class_ufi.c:168: const uint8_t *p_input = buffer + 3; +;source-doc/ufi-drv/./class_ufi.c:176: const uint8_t *p_input = buffer + 3; ld c,(ix+4) ld b,(ix+5) inc bc inc bc inc bc -;source-doc/ufi-drv/./class_ufi.c:170: *p_output++ = *p_input--; +;source-doc/ufi-drv/./class_ufi.c:178: *p_output++ = *p_input--; ld a, (bc) dec bc ld (de), a inc de -;source-doc/ufi-drv/./class_ufi.c:171: *p_output++ = *p_input--; +;source-doc/ufi-drv/./class_ufi.c:179: *p_output++ = *p_input--; ld a, (bc) dec bc ld (de), a inc de -;source-doc/ufi-drv/./class_ufi.c:172: *p_output++ = *p_input--; +;source-doc/ufi-drv/./class_ufi.c:180: *p_output++ = *p_input--; ld a, (bc) ld (de), a inc de -;source-doc/ufi-drv/./class_ufi.c:173: *p_output = *p_input--; +;source-doc/ufi-drv/./class_ufi.c:181: *p_output = *p_input--; dec bc ld a, (bc) ld (de), a -;source-doc/ufi-drv/./class_ufi.c:175: return result; +;source-doc/ufi-drv/./class_ufi.c:183: return result; pop hl push hl ld e,(ix-2) ld d,(ix-1) -;source-doc/ufi-drv/./class_ufi.c:176: } +;source-doc/ufi-drv/./class_ufi.c:184: } ld sp, ix pop ix ret diff --git a/Source/HBIOS/ch376-native/ufi-drv/usb_cbi.c.s b/Source/HBIOS/ch376-native/ufi-drv/usb_cbi.c.s index 134682ce..c9e23468 100644 --- a/Source/HBIOS/ch376-native/ufi-drv/usb_cbi.c.s +++ b/Source/HBIOS/ch376-native/ufi-drv/usb_cbi.c.s @@ -50,7 +50,7 @@ _cbi2_adsc: ;-------------------------------------------------------- ; code ;-------------------------------------------------------- -;source-doc/ufi-drv/./usb_cbi.c:9: usb_error usb_execute_cbi(device_config *const storage_device, +;source-doc/ufi-drv/./usb_cbi.c:10: usb_error usb_execute_cbi(device_config *const storage_device, ; --------------------------------- ; Function usb_execute_cbi ; --------------------------------- @@ -61,7 +61,7 @@ _usb_execute_cbi: ld hl, -8 add hl, sp ld sp, hl -;source-doc/ufi-drv/./usb_cbi.c:18: const uint8_t interface_number = storage_device->interface_number; +;source-doc/ufi-drv/./usb_cbi.c:17: const uint8_t interface_number = storage_device->interface_number; ld c,(ix+4) ld b,(ix+5) ld l, c @@ -69,7 +69,7 @@ _usb_execute_cbi: inc hl inc hl ld e, (hl) -;source-doc/ufi-drv/./usb_cbi.c:21: adsc = cbi2_adsc; +;source-doc/ufi-drv/./usb_cbi.c:20: adsc = cbi2_adsc; push de push bc ex de, hl @@ -81,9 +81,13 @@ _usb_execute_cbi: ldir pop bc pop de -;source-doc/ufi-drv/./usb_cbi.c:22: adsc.bIndex[0] = interface_number; +;source-doc/ufi-drv/./usb_cbi.c:21: adsc.bIndex[0] = interface_number; ld (ix-4),e -;source-doc/ufi-drv/./usb_cbi.c:24: result = usbdev_control_transfer(storage_device, &adsc, (uint8_t *const)cmd); +;source-doc/ufi-drv/./usb_cbi.c:23: critical_begin(); + push bc + call _critical_begin + pop bc +;source-doc/ufi-drv/./usb_cbi.c:25: result = usbdev_control_transfer(storage_device, &adsc, (uint8_t *const)cmd); ld l,(ix+6) ld h,(ix+7) push hl @@ -96,14 +100,16 @@ _usb_execute_cbi: pop af pop af ld a, l -;source-doc/ufi-drv/./usb_cbi.c:26: if (result == USB_ERR_STALL) { - cp 0x02 + ld (_result), a +;source-doc/ufi-drv/./usb_cbi.c:27: if (result == USB_ERR_STALL) { + ld a,(_result) + sub 0x02 jr NZ,l_usb_execute_cbi_00104 -;source-doc/ufi-drv/./usb_cbi.c:27: if (sense_codes != NULL) +;source-doc/ufi-drv/./usb_cbi.c:28: if (sense_codes != NULL) ld a,(ix+14) or (ix+13) jr Z,l_usb_execute_cbi_00102 -;source-doc/ufi-drv/./usb_cbi.c:28: usbdev_dat_in_trnsfer(storage_device, sense_codes, 2, ENDPOINT_INTERRUPT_IN); +;source-doc/ufi-drv/./usb_cbi.c:29: usbdev_dat_in_trnsfer(storage_device, sense_codes, 2, ENDPOINT_INTERRUPT_IN); ld a,0x02 push af inc sp @@ -121,21 +127,20 @@ _usb_execute_cbi: pop af inc sp l_usb_execute_cbi_00102: -;source-doc/ufi-drv/./usb_cbi.c:30: return USB_ERR_STALL; - ld l,0x02 - jp l_usb_execute_cbi_00118 +;source-doc/ufi-drv/./usb_cbi.c:31: result = USB_ERR_STALL; + ld hl,_result + ld (hl),0x02 +;source-doc/ufi-drv/./usb_cbi.c:32: goto done; + jp l_usb_execute_cbi_00116 l_usb_execute_cbi_00104: -;source-doc/ufi-drv/./usb_cbi.c:33: if (result != USB_ERR_OK) { +;source-doc/ufi-drv/./usb_cbi.c:35: if (result != USB_ERR_OK) { + ld a,(_result) or a - jr Z,l_usb_execute_cbi_00106 -;source-doc/ufi-drv/./usb_cbi.c:35: return result; - ld l, a - jr l_usb_execute_cbi_00118 -l_usb_execute_cbi_00106: -;source-doc/ufi-drv/./usb_cbi.c:38: if (send) { + jp NZ, l_usb_execute_cbi_00116 +;source-doc/ufi-drv/./usb_cbi.c:40: if (send) { bit 0,(ix+8) jr Z,l_usb_execute_cbi_00112 -;source-doc/ufi-drv/./usb_cbi.c:39: result = usbdev_blk_out_trnsfer(storage_device, buffer, buffer_size); +;source-doc/ufi-drv/./usb_cbi.c:41: result = usbdev_blk_out_trnsfer(storage_device, buffer, buffer_size); ld l,(ix+9) ld h,(ix+10) push hl @@ -149,14 +154,16 @@ l_usb_execute_cbi_00106: pop af pop af pop af -;source-doc/ufi-drv/./usb_cbi.c:41: if (result != USB_ERR_OK) { ld a, l + ld (_result), a +;source-doc/ufi-drv/./usb_cbi.c:43: if (result != USB_ERR_OK) { + ld a,(_result) or a jr Z,l_usb_execute_cbi_00113 -;source-doc/ufi-drv/./usb_cbi.c:43: return result; - jr l_usb_execute_cbi_00118 +;source-doc/ufi-drv/./usb_cbi.c:45: goto done; + jr l_usb_execute_cbi_00116 l_usb_execute_cbi_00112: -;source-doc/ufi-drv/./usb_cbi.c:46: result = usbdev_dat_in_trnsfer(storage_device, buffer, buffer_size, ENDPOINT_BULK_IN); +;source-doc/ufi-drv/./usb_cbi.c:48: result = usbdev_dat_in_trnsfer(storage_device, buffer, buffer_size, ENDPOINT_BULK_IN); ld a,0x01 push af inc sp @@ -174,17 +181,19 @@ l_usb_execute_cbi_00112: pop af pop af inc sp -;source-doc/ufi-drv/./usb_cbi.c:48: if (result != USB_ERR_OK) { ld a, l + ld (_result), a +;source-doc/ufi-drv/./usb_cbi.c:50: if (result != USB_ERR_OK) { + ld a,(_result) or a -;source-doc/ufi-drv/./usb_cbi.c:50: return result; - jr NZ,l_usb_execute_cbi_00118 + jr NZ,l_usb_execute_cbi_00116 +;source-doc/ufi-drv/./usb_cbi.c:52: goto done; l_usb_execute_cbi_00113: -;source-doc/ufi-drv/./usb_cbi.c:54: if (sense_codes != NULL) { +;source-doc/ufi-drv/./usb_cbi.c:56: if (sense_codes != NULL) { ld a,(ix+14) or (ix+13) - jr Z,l_usb_execute_cbi_00117 -;source-doc/ufi-drv/./usb_cbi.c:55: result = usbdev_dat_in_trnsfer(storage_device, sense_codes, 2, ENDPOINT_INTERRUPT_IN); + jr Z,l_usb_execute_cbi_00116 +;source-doc/ufi-drv/./usb_cbi.c:57: result = usbdev_dat_in_trnsfer(storage_device, sense_codes, 2, ENDPOINT_INTERRUPT_IN); ld a,0x02 push af inc sp @@ -201,16 +210,16 @@ l_usb_execute_cbi_00113: pop af pop af inc sp -;source-doc/ufi-drv/./usb_cbi.c:57: if (result != USB_ERR_OK) { ld a, l - or a -;source-doc/ufi-drv/./usb_cbi.c:59: return result; - jr NZ,l_usb_execute_cbi_00118 -l_usb_execute_cbi_00117: -;source-doc/ufi-drv/./usb_cbi.c:63: return USB_ERR_OK; - ld l,0x00 -l_usb_execute_cbi_00118: -;source-doc/ufi-drv/./usb_cbi.c:64: } + ld (_result), a +;source-doc/ufi-drv/./usb_cbi.c:65: done: +l_usb_execute_cbi_00116: +;source-doc/ufi-drv/./usb_cbi.c:66: critical_end(); + call _critical_end +;source-doc/ufi-drv/./usb_cbi.c:68: return result; + ld hl,_result + ld l, (hl) +;source-doc/ufi-drv/./usb_cbi.c:69: } ld sp, ix pop ix ret diff --git a/Source/HBIOS/ch376kyb.asm b/Source/HBIOS/ch376kyb.asm index 9111a045..c6a3c706 100644 --- a/Source/HBIOS/ch376kyb.asm +++ b/Source/HBIOS/ch376kyb.asm @@ -15,8 +15,67 @@ #include "./ch376-native/keyboard.s" +; COUNT FOR INTERRUPT HANDLER TO TRIGGER KEYBOARD SCANNER (EG: SCAN KEYBOARD ONLY EVERY 3RD INTERRUPT (3/60)) +SCAN_INT_PERIOD: .EQU 3 + +; VDP-INTERUPT COUNTER THAT COUNTS FROM SCAN_INT_PERIOD TO 0, WHEN IT REACHES ZERO, THE +; KEYBOARD MATRIX IS SCANNED, AND THE COUNTERS IS RESET AT SCAN_INT_PERIOD +UKY_SCNCNT: .DB SCAN_INT_PERIOD + + .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +UKY_INTSTK: ; 128 bytes for keyboard interrupt stack - need ~52 bytes??? + +CHUKB_INIT: + ; INSTALL INTERRUPT HANDLER + LD HL, (VEC_TICK+1) + LD (VEC_CHUKB_TICK+1), HL + + LD HL, CHUKB_TICK + LD (VEC_TICK+1), HL + + JP _keyboard_init + +CHUKB_TICK: + LD A, (UKY_SCNCNT) ; SCAN THE KEYBOARD EVERY 'SCAN_INT_PERIOD' INTERRUPTS. + DEC A + LD (UKY_SCNCNT), A + JR NZ, VEC_CHUKB_TICK + + LD A, SCAN_INT_PERIOD + LD (UKY_SCNCNT), A + + ; we gonna need a bigger stack + + EZ80_UTIL_DEBUG + + LD (UKY_INT_SP),SP ; SAVE ORIGINAL STACK FRAME + LD SP,UKY_INTSTK ; USE DEDICATED INT STACK FRAME IN HI MEM + + CALL _keyboard_tick + + LD SP, $FFFF ; RESTORE ORIGINAL STACK FRAME +UKY_INT_SP .EQU $ - 2 +; + + +VEC_CHUKB_TICK: + JP HB_TICK -CHUKB_INIT .EQU _keyboard_init ; ### Function 0x4C -- Keyboard Status (VDAKST) ; @@ -36,8 +95,7 @@ CHUKB_INIT .EQU _keyboard_init ; pending. ; UKY_STAT: - XOR A - RET + JP _keyboard_buf_size ; ### Function 0x4D -- Video Keyboard Flush (VDAKFL) ; @@ -50,6 +108,8 @@ UKY_STAT: ; Purged and all contents discarded. The Status (A) is a standard HBIOS result code. ; UKY_FLUSH: + CALL _keyboard_buf_flush + XOR A RET ; ; ### Function 0x4E -- Video Keyboard Read (VDAKRD) @@ -87,4 +147,14 @@ UKY_FLUSH: ; function keys and arrows, are returned as reserved codes as described at the start of this section. ; UKY_READ: + HB_DI + CALL _keyboard_buf_get_next + HB_EI + LD A, H + OR A + JR NZ, UKY_READ + LD C, 0 + LD D, 0 + ; LD E, 'A' + XOR A RET diff --git a/Source/HBIOS/hbios.asm b/Source/HBIOS/hbios.asm index 2cee1798..5140109b 100644 --- a/Source/HBIOS/hbios.asm +++ b/Source/HBIOS/hbios.asm @@ -1929,7 +1929,7 @@ ROMRESUME: LD A,BID_IMG2 ; S100 MONITOR BANK LD IX,HWMON_IMGLOC ; EXECUTION RESUMES HERE CALL HBX_BNKCALL ; CONTINUE IN RAM BANK, DO NOT RETURN - HALT ; WE SHOULD NOT COME BACK HERE! + JR $ ; HALT WE SHOULD NOT COME BACK HERE! ; S100MON_SKIP: ; RESTORE DEFAULT RELOAD REGISTER VALUE (PROBABLY NOT NEEDED) @@ -2084,7 +2084,7 @@ MBC_SINGLE: LD A,BID_BIOS ; BIOS BANK ID LD IX,HB_START1 ; EXECUTION RESUMES HERE CALL HBX_BNKCALL ; CONTINUE IN RAM BANK, DO NOT RETURN - HALT ; WE SHOULD NOT COME BACK HERE! + JR $ ; HALT WE SHOULD NOT COME BACK HERE! #ENDIF ; ; EXECUTION RESUMES HERE AFTER SWITCH TO RAM BANK @@ -3884,7 +3884,7 @@ INITSYS4: #ENDIF LD IX,0 ; ENTER AT ADDRESS 0 CALL HBX_BNKCALL ; GO THERE - HALT ; WE SHOULD NEVER COME BACK! + JR $ ; HALT WE SHOULD NEVER COME BACK! ; ;-------------------------------------------------------------------------------------------------- ; TABLE OF RECOVERY MODE INITIALIZATION ENTRY POINTS @@ -5415,7 +5415,7 @@ SYS_RESWARM: #ENDIF LD IX,0 ; ENTER AT ADDRESS 0 CALL HBX_BNKCALL ; GO THERE - HALT ; WE SHOULD NEVER COME BACK! + JR $ ; HALT WE SHOULD NEVER COME BACK! #ENDIF ; ; RESTART SYSTEM AS THOUGH POWER HAD JUST BEEN TURNED ON @@ -6946,7 +6946,7 @@ SYSHALT: LD DE,STR_HALT CALL WRITESTR DI - HALT + JR $ ; HALT ; ;-------------------------------------------------------------------------------------------------- ; INTERRUPT MANAGEMENT SUPPORT @@ -7056,7 +7056,6 @@ HB_BADINTCNT .DB 0 CALL NEWLINE ;CALL CONTINUE OR $FF ; SIGNAL INTERRUPT HANDLED - EZ80_UTIL_DEBUG RET ; ;-------------------------------------------------------------------------------------------------- @@ -7393,7 +7392,7 @@ Z280_DIAG: ; ;RETIL DI - HALT + JR $ ; HALT ; Z280_BADINTSTR .TEXT "BAD INT $" Z280_SSTEPSTR .TEXT "SINGLE STEP $" @@ -7463,7 +7462,7 @@ Z280_PRIVINST4: ; ; GO NO FURTHER DI - HALT + JR $ ; HALT ; Z280_PRIVINSTX: ; RESTORE REGISTERS