📄 counter.lst
字号:
019E 91 C7 [10] call USBSendROMBuffer
01A0 80 B4 [05] jmp USBEventEP0End
01A2
01A2 USBEventEP0SetupGetDescriptorString5:
01A2 16 05 [04] cmp a,5
01A4 B1 B4 [05] jnz USBEventEP0SetupGetDescriptorEnd ; No
01A6
01A6 ;*********************************************
01A6 ; Get String 5 Descriptor Event
01A6 ;*********************************************
01A6 ; Descriptor pointer
01A6 19 81 [04] mov a,(USBStringDescription5 -USBSendROMBufferBase)
01A8 31 2A [05] mov [gbUSBSendBuffer],a
01AA
01AA ; Descriptor size
01AA 19 3E [04] mov a,3Eh ;[USBStringDescription5]
01AC 31 29 [05] mov [gbUSBSendBytes],a
01AE
01AE ; Check request size field
01AE 91 B6 [10] call USBSendDescriptorCheckLength
01B0
01B0 ; Send buffer
01B0 91 C7 [10] call USBSendROMBuffer
01B2 80 B4 [05] jmp USBEventEP0End
01B4
01B4 USBEventEP0SetupGetDescriptorEnd:
01B4 ; Unsupported Get request !!!
01B4 80 B8 [05] jmp USBEventEP0Stall
01B6
01B6 ;//$PAGE
01B6 ;********************************************************
01B6 ; USBSendDescriptorCheckLength()
01B6 ; @func Check and update send length for Get Descriptor
01B6 ; requests on end point 0.
01B6 ; @parm BYTE | gbUSBSendBytes | Number of bytes to send.
01B6 ;********************************************************
01B6 USBSendDescriptorCheckLength:
01B6
01B6 ; High byte set? (Assume <255 bytes)
01B6 1A 77 [06] mov a,[USBEndP0FIFO_7]
01B8 16 00 [04] cmp a,0
01BA B1 C6 [05] jnz USBSendDescriptorCheckLengthEnd ; Yes
01BC
01BC ; Check size
01BC 1A 76 [06] mov a,[USBEndP0FIFO_6]
01BE 17 29 [06] cmp a,[gbUSBSendBytes]
01C0 A1 C6 [05] jz USBSendDescriptorCheckLengthEnd ; equal
01C2 D1 C6 [05] jnc USBSendDescriptorCheckLengthEnd ; greater than
01C4
01C4 ; New size
01C4 31 29 [05] mov [gbUSBSendBytes],a
01C6
01C6 USBSendDescriptorCheckLengthEnd:
01C6 3F [08] ret
01C7
01C7 ;//$PAGE
01C7 ;********************************************************
01C7 ; USBSendROMBuffer()
01C7 ; @func Send a number of ROM bytes on end point 0.
01C7 ; @parm BYTE | gbUSBSendBytes | Number of bytes to send.
01C7 ; @parm BYTE | gbUSBSendBuffer | Offset from ROM base
01C7 ; of data to send.
01C7 ; @comm assumes IN packets are ignored in the interrupt routine
01C7 ; @devnote Enables interrupts
01C7 ;********************************************************
01C7 USBSendROMBuffer:
01C7
01C7 ; Clear flag
01C7 19 00 [04] mov a,0h
01C9 2A 14 [05] iowr USBEndP0RxStatus
01CB
01CB ; Enable interrupts
01CB 1A 20 [06] mov a,[gbSysInterruptMask]
01CD 10 F7 [04] and a,~SysIntUSBEndP0
01CF 2A 20 [05] iowr SysInterrupt
01D1
01D1 ; Auto ACK OUT packet (This would be a Status Out)
01D1 19 08 [04] mov a,USBControlAckStatusData
01D3 2A 13 [05] iowr USBControl
01D5
01D5 ; Initialize sequence
01D5 19 00 [04] mov a,0h
01D7 31 28 [05] mov [gbUSBSendSequence],a
01D9
01D9 ; Send count
01D9 1A 29 [06] mov a,[gbUSBSendBytes]
01DB
01DB USendROMBufferLoop:
01DB ; One 8-byte chunk or less left?
01DB 16 08 [04] cmp a,08h
01DD A1 F5 [05] jz USendROMBufferLoopDone ; exactly 8 bytes left, branch
01DF C1 F5 [05] jc USendROMBufferLoopDone ; less than 8 bytes left, branch
01E1
01E1 ; more than 8 bytes left, fall through and loop
01E1 ; until there are 8 bytes or less.
01E1 ; Save count
01E1 2D [05] push a
01E2
01E2 ; Send 8 byte chunk
01E2 19 08 [04] mov a,08h
01E4 31 29 [05] mov [gbUSBSendBytes],a
01E6 91 F8 [10] call _USBSendROMBuffer
01E8
01E8 ; Check for OUT packet cancelling send
01E8 29 14 [05] iord USBEndP0RxStatus
01EA 10 02 [04] and a,USBEndP0RxOut
01EC
01EC ; Restore count
01EC 2B [04] pop a
01ED
01ED ; Handle exception: OUT packet cancel send
01ED B1 F7 [05] jnz USendROMBufferLoopExit ; Cancelled
01EF
01EF ; Save bytes left
01EF 07 08 [04] sub a,08h
01F1 31 29 [05] mov [gbUSBSendBytes],a
01F3 81 DB [05] jmp USendROMBufferLoop
01F5
01F5 USendROMBufferLoopDone:
01F5 ; Send last 8 or less bytes
01F5 91 F8 [10] call _USBSendROMBuffer
01F7
01F7 USendROMBufferLoopExit:
01F7 3F [08] ret
01F8
01F8 ;//$PAGE
01F8 ;********************************************************
01F8 ; _USBSendROMBuffer()
01F8 ; @func Buffer and inialize USB send of up
01F8 ; to 8 bytes of ROM data on end point 0.
01F8 ; @comm affects gbUSBSendBytes & gbUSBSendBuffer
01F8 ;********************************************************
01F8 _USBSendROMBuffer:
01F8
01F8 ; Save x
01F8 2E [05] push x
01F9
01F9 ; Initialize
01F9 1C 00 [04] mov x,0h
01FB
01FB _USendROMBufferLoop:
01FB ; Any more?
01FB 19 00 [04] mov a,0h
01FD 17 29 [06] cmp a,[gbUSBSendBytes]
01FF 1F [04] XPAGE
0200 A2 0F [05] jz _USendROMBufferLoopDone ; No more
0202 27 29 [07] dec [gbUSBSendBytes]
0204
0204 ; Move bytes to FIFO
0204 1A 2A [06] mov a,[gbUSBSendBuffer]
0206 F2 64 [14] index USBSendROMBufferBase
0208 32 70 [06] mov [x +USBEndP0FIFO],a
020A 22 [04] inc x
020B
020B ; Next byte
020B 23 2A [07] inc [gbUSBSendBuffer]
020D 81 FB [05] jmp _USendROMBufferLoop
020F
020F _USendROMBufferLoopDone:
020F ; Re-enable reception
020F 19 00 [04] mov a,0h
0211 2A 14 [05] iowr USBEndP0RxStatus
0213
0213 ; Toggle sequence
0213 19 40 [04] mov a,USBEndP0TxSequence
0215 37 28 [07] xor [gbUSBSendSequence],a
0217
0217 ; Send bytes
0217 2E [05] push x
0218 2B [04] pop a
0219 0E 28 [06] or a,[gbUSBSendSequence]
021B 0D 80 [04] or a,USBEndP0TxRespond
021D 2A 10 [05] iowr USBEndP0TxConfig
021F
021F ; The FIFO is loaded, go and wait untill it's read
021F 92 2D [10] call USBSendWaitForComplete
0221
0221 _USendROMBufferEnd:
0221 ; Restore and exit
0221 2C [04] pop x
0222 3F [08] ret
0223
0223 ;//$PAGE
0223 ;********************************************************
0223 ; USBSendACK()
0223 ; func Respond to a "USB Status In" with a zero byte buffer with
0223 ; Sequence field set) on end point 0.
0223 ; Called by SetAddress and SetConfig commands
0223 ;********************************************************
0223 USBSendACK:
0223
0223 ; Status response to Status In is to send a zero byte packet
0223 19 C0 [04] mov a,USBEndP0TxRespond | USBEndP0TxSequence
0225 2A 10 [05] iowr USBEndP0TxConfig
0227
0227 ; Enable interrupts
0227 1A 20 [06] mov a,[gbSysInterruptMask]
0229 2A 20 [05] iowr SysInterrupt
022B
022B ; Wait for send complete
022B 82 2D [05] jmp USBSendWaitForComplete
022D
022D ;********************************************************
022D ; USBSendWaitForComplete()
022D ; @func Wait for send to complete on end point 0.
022D ;********************************************************
022D
022D ; At some point, either the 0 data will be ACK'd or a SETUP
022D ; will come in.
022D ; Either event will cause the "Enable Respond
022D ; to In Packets" to be reset, and we will fall out of the loop.
022D ; In either case, an EP0 IRQ will be generated (5.9.2.2 in Cyp
022D ; device spec) if EP0 irq is enabled.
022D
022D USBSendWaitForComplete:
022D
022D ; Poll the send complete bit
022D ; This will be reset when the data has been sent to the host
022D ; and the host has ACK's, or the host has sent another SETUP
022D ; which should terminate this activity in any case.
022D 29 10 [05] iord USBEndP0TxConfig
022F 10 80 [04] and a,USBEndP0TxRespond
0231 A2 3B [05] jz USBSendWaitComplete
0233
0233 ; Check for OUT packet cancelling send. A STATUS OUT should
0233 ; terminate any pending IN's. A Setup could also set the Out bit.
0233 29 14 [05] iord USBEndP0RxStatus
0235 10 02 [04] and a,USBEndP0RxOut
0237 B2 3B [05] jnz USBSendWaitComplete ; Cancelled
0239
0239 ; Keep waiting
0239 82 2D [05] jmp USBSendWaitForComplete
023B
023B USBSendWaitComplete:
023B 3F [08] ret
023C
023C ;********************************************************
023C ; USBEventEP0VendorRqst()
023C ; @func Vendor request on end point zero.
023C ; @devnote Runs in interrupt disabled context.
023C ;********************************************************
023C USBEventEP0VendorRqst:
023C
023C ; Save it
023C 2E [05] push x
023D
023D ; Check Protocol
023D 1A 71 [06] mov a,[USBEndP0FIFO_1]
023F 16 00 [04] cmp a,0h
0241 B0 B8 [05] jnz USBEventEP0Stall ; No
0243
0243 ;*********************************************
0243 ; Reset Counter Event
0243 ;*********************************************
0243 ; Initialize Counter
0243 19 00 [04] mov a,0
0245 31 2D [05] mov [gbButtonClicks],a ; Initial state of 0, no button pushed
0247 31 78 [05] mov [USBEndP1FIFO_0],a
0249
0249 29 11 [05] iord USBEndP1TxConfig
024B 10 40 [04] and a,40h
024D 0D 91 [04] or a,91h
024F 2A 11 [05] iowr USBEndP1TxConfig
0251
0251 ;USBEventEP0VendorRqstFinish:
0251
0251 ; Protocol ACK
0251 19 42 [04] mov a,42h
0253 31 70 [05] mov [USBEndP0FIFO_0],a
0255
0255 ; Auto ACK OUT packet
0255 19 08 [04] mov a,USBControlAckStatusData
0257 2A 13 [05] iowr USBControl
0259
0259 ; Send bytes as Data1
0259 19 08 [04] mov a,8
025B 0D 40 [04] or a,USBEndP0TxSequence
025D 0D 80 [04] or a,USBEndP0TxRespond
025F 2A 10 [05] iowr USBEndP0TxConfig
0261
0261 ;call USBSendWaitForComplete
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -