Advertisement
commandblockguy

Untitled

Oct 10th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. usbRangeLow     := $D13FD8
  2. qhFreeList      := $D13FD8
  3. qtdFreeList     := $D13FDB
  4. setupPacket     := $D13FDE
  5. unalloc0        := $D13FE6 ; 26 bytes
  6. periodicList        := $D14000 ; 4K aligned, 1K
  7. alignedPoolLow      := $D14400 ; 32b aligned
  8. qhHead          := $D17702
  9. alignedPoolHigh     := $D17740
  10. unalloc1        := $D17740 ; 119 bytes
  11. usbSillyState       := $D177B7 ; needs to not be $55 so nothing else gets clobbered
  12. unalloc2        := $D177B8 ; 4 bytes
  13. usbRangeHigh        := $D177BC
  14.  
  15. devEndpoints        := 0
  16. devHubPorts     := devEndpoints+16
  17. devAddr         := devHubPorts+1
  18. devSpeed        := devAddr+1
  19. devHubInfo      := devSpeed+1
  20. devParent       := devHubInfo+2
  21. devChildren     := devParent+3
  22. devSibling      := devChildren+3
  23. devSize         := devSibling+3
  24.  
  25. qtdNext         := 0
  26. qtdAltNext      := qtdNext+4
  27. bQtdAltNext     := 2
  28. qtdStatus       := qtdAltNext+4
  29. bQtdStatus      := 3
  30. qtdPid          := qtdStatus+1
  31. qtdLen          := qtdPid+1
  32. qtdBufPtr       := qtdLen+2
  33. qtdSize         := qtdBufPtr+20
  34.  
  35. bQtdStatusActive    := 7
  36. bmQtdStatusActive   := 1 shl bQtdStatusActive
  37. bQtdStatusHalted    := 6
  38. bmQtdStatusHalted   := 1 shl bQtdStatusHalted
  39. bQtdStatusBufErr    := 5
  40. bmQtdStatusBufErr   := 1 shl bQtdStatusBufErr
  41. bQtdStatusBabble    := 4
  42. bmQtdStatusBabble   := 1 shl bQtdStatusBabble
  43. bQtdStatusXactErr   := 3
  44. bmQtdStatusXactErr  := 1 shl bQtdStatusXactErr
  45. bQtdStatusMissedUframe  := 2
  46. bmQtdStatusMissedUframe := 1 shl bQtdStatusMissedUframe
  47. bQtdStatusSplitState    := 1
  48. bmQtdStatusSplitState   := 1 shl bQtdStatusSplitState
  49.  
  50. qhOff           := 1 shl 1
  51. qhNext          := -qhOff
  52. qhAddr          := qhNext+4
  53. qhEndPt         := qhAddr+1
  54. qhMaxPktLen     := qhEndPt+1
  55. qhSmask         := qhMaxPktLen+2
  56. qhCmask         := qhSmask+1
  57. qhHubAddr       := qhCmask+1
  58. qhHubPort       := qhHubAddr+1
  59. qhCurQtd        := qhHubPort+1
  60. qhOverlay       := qhCurQtd+4
  61. qhDir           := qhOverlay+qtdSize
  62. qhType          := qhDir+1
  63. qhPrev          := qhType+1
  64. qhFirstQtd      := qhPrev+3
  65. qhLastQtd       := qhFirstQtd+3
  66. qhSize          := qhLastQtd+3
  67.  
  68. bmRequestType       := 0
  69. bRequest        := 1
  70. wValue          := 2
  71. wIndex          := 4
  72. wLength         := 6
  73.  
  74. reqTypeGetStat      := 0
  75. reqTypeClrFeat      := 1
  76. reqTypeSetFeat      := 3
  77. reqTypeSetAddr      := 5
  78. reqTypeGetDesc      := 6
  79. reqTypeSetDesc      := 7
  80. reqTypeGetConf      := 8
  81. reqTypeSetConf      := 9
  82. reqTypeGetIface     := 10
  83. reqTypeSetIface     := 11
  84. reqTypeSyncFrame    := 12
  85.  
  86. descTypeDev     := 1
  87. descTypeConf        := 2
  88. descTypeStr     := 3
  89. descTypeIface       := 4
  90. descTypeEndpt       := 5
  91. descTypeDevQual     := 6
  92. descTypeOtherConf   := 7
  93. descTypeIfacePwr    := 8
  94.  
  95. bLength         := 0
  96. bDescriptorType     := bLength+1
  97.  
  98. bcdUSB          := bDescriptorType+1
  99. bDeviceClass        := bcdUSB+2
  100. bDeviceSubClass     := bDeviceClass+1
  101. bDeviceProtocol     := bDeviceSubClass+1
  102. bMaxPacketSize0     := bDeviceProtocol+6
  103.  
  104. idVendor        := bMaxPacketSize0+1
  105. idProduct       := idVendor+2
  106. bcdDevice       := idProduct+2
  107. iManufacturer       := bcdDevice+2
  108. iProduct        := iManufacturer+1
  109. iSerialNumber       := iProduct+1
  110. bNumConfigurations  := iSerialNumber+1
  111. descLenDev      := bNumConfigurations+1
  112.  
  113. bNumQualConfigurations  := bDeviceProtocol+1
  114. bQualReserved       := bNumQualConfigurations+1
  115. descLenDevQual      := bQualReserved+1
  116.  
  117. wTotalLength        := bDescriptorType+1
  118. bNumInterfaces      := wTotalLength+2
  119. bConfigurationValue := bNumInterfaces+1
  120. iConfiguration      := bConfigurationValue+1
  121. bmInterfaceAttributes   := iConfiguration+1
  122. bMaxPower       := bmInterfaceAttributes+1
  123. descLenConf     := bMaxPower+1
  124.  
  125. bInterfaceNumber    := bDescriptorType+1
  126. bAlternateSetting   := bInterfaceNumber+1
  127. bNumEndpoints       := bAlternateSetting+1
  128. bInterfaceClass     := bNumEndpoints+1
  129. bInterfaceSubClass  := bInterfaceClass+1
  130. bInterfaceProtocol  := bInterfaceSubClass+1
  131. iInterface      := bInterfaceProtocol+1
  132. descLenIface        := iInterface+1
  133.  
  134. bEndpointAddress    := bDescriptorType+1
  135. bmEndpointAttributes    := bEndpointAddress+1
  136. wMaxPacketSize      := bmEndpointAttributes+1
  137. bInterval       := wMaxPacketSize+2
  138. descLenEndpt        := bInterval+1
  139.  
  140. usbInit:
  141.     ld  hl,mpTmrCtrl
  142.     res bTmr3Enable,(hl)
  143.     xor a,a
  144.     ld  (usbSillyState),a
  145.     call    debugStr
  146.     db  'waiting for usb...',0
  147.     call    debugNewLine
  148. .waitPlug:
  149.     call    _usb_SelfPowered
  150.     jr  nz,.waitPlug
  151.     call    usbChipReset
  152.     ld  hl,periodicList
  153.     ld  (mpUsbPeriodicListBase),hl
  154.     xor a,a
  155.     ld  b,a
  156.     inc a
  157. .fill:
  158.     ld  (hl),a
  159.     inc hl
  160.     inc hl
  161.     inc hl
  162.     inc hl
  163.     djnz    .fill
  164. ;   ld  hl,alignedPoolLow
  165.     ld  e,a
  166.     ld  c,a
  167. .check:
  168.     ld  l,qhOff
  169.     ld  (hl),bc
  170.     push    hl
  171.     pop bc
  172.     ld  a,64
  173. .loop:
  174.     ld  l,a
  175.     ld  (hl),de
  176.     push    hl
  177.     pop de
  178.     add a,32
  179.     jr  nz,.loop
  180.     ld  l,a
  181.     inc h
  182.     ld  a,h
  183.     cp  a,(alignedPoolHigh shr 8) and $FF
  184.     jr  nz,.check
  185.     ld  (qhFreeList),bc
  186.     ld  (qtdFreeList),de
  187.     ld  ix,qhHead
  188. ;   lea hl,ix+qhNext
  189.     ld  (hl),ix
  190.     ld  (ix+qhEndPt),1 shl 7
  191.     ld  (ix+qhOverlay+qtdNext),1
  192.     ld  (ix+qhOverlay+qtdAltNext),1
  193.     ld  (ix+qhOverlay+qtdStatus),bmQtdStatusHalted
  194.     ld  (ix+qhPrev),ix
  195.     ld  (mpUsbAsyncListAddr),hl
  196.     ld  hl,mpUsbCmd
  197.     ld  (hl),(1 shl 5) or (1 shl 4) or (2 shl 2) or (1 shl 0)
  198. ;   jr  usbWaitForConnection
  199.  
  200. usbWaitForConnection:
  201.     call    usbBusPower
  202. ;   call    debugStr
  203. ;   db  'Waiting for connection...',0
  204. ;   call    debugNewLine
  205.     ld  hl,mpUsbPortSC
  206. .wait:
  207.     bit 0,(hl)
  208.     jr  z,.wait
  209.     call    usbBusReset
  210.     ld  ix,ep0Desc
  211.     lea iy,ix+devRoot-ep0Desc
  212.     xor a,a
  213.     ld  (reqSetAddr+wValue),a
  214.     ld  (iy+devAddr),a
  215.     ld  a,(mpUsbOtgCsr+2)
  216.     and a,3 shl 6
  217.     rrca
  218.     rrca
  219.     ld  (iy+devSpeed),a
  220.     call    qhInit
  221.     ld  hl,reqSetAddr+wValue
  222.     inc (hl)
  223.     call    pe,debugAbort
  224.     ld  a,ixh
  225.     ld  (iy+devEndpoints+0),a
  226.     ld  a,(hl)
  227.     ld  (iy+devAddr),a
  228.     push    af
  229.     call    qtdAlloc
  230.     push    hl
  231.     ld  de,reqGetDevDesc8
  232.     call    controlTransferAdd
  233.     ld  de,reqSetAddr
  234.     call    controlTransferAdd
  235.     call    debugStr
  236.     db  'Transfers added...',0
  237.     call    debugNewLine
  238.     call    qhWait
  239.     call    z,debugAbort
  240.     pop iy
  241.     pop af
  242.     ld  (ix+qhAddr),a
  243.     ld  a,(iy+7)
  244.     ld  (ix+qhMaxPktLen),a
  245.     lea hl,iy
  246. ;   call    debugStr
  247. ;   db  'Device descriptor received: ',0
  248. ;   call    debugHexBlockHL
  249. ;   db  8
  250. ;   call    debugNewLine
  251.     jp  qtdFree
  252.  
  253. usbCleanup:
  254.     ld  hl,mpUsbCmd
  255.     ld  (hl),h
  256.     ld  hl,usbRangeLow
  257.     ld  bc,usbRangeHigh-usbRangeLow
  258.     jp  _MemClear
  259.  
  260. usbChipReset:
  261. ;   call    debugStr
  262. ;   db  'Resetting chip...',0
  263. ;   call    debugNewLine
  264.     ld  a,7
  265.     ld  (mpUsbIdle),a
  266.     ld  de,$2B0
  267.     ld  hl,mpUsbDevCtrl+1
  268.     ld  (hl),2
  269.     dec hl
  270.     ld  (hl),$B0
  271. ;   jr  usbHostReset
  272.  
  273. usbHostReset:
  274. ;   call    debugStr
  275. ;   db  'Waiting for host to stop...',0
  276. ;   call    debugNewLine
  277.     ld  hl,mpUsbCmd
  278.     ld  (hl),h
  279.     ld  l,usbSts+1
  280. .wait_stop:
  281.     bit 12-8,(hl)
  282.     jr  z,.wait_stop
  283. ;   call    debugStr
  284. ;   db  'Waiting for host to reset...',0
  285. ;   call    debugNewLine
  286.     ld  l,usbCmd
  287.     ld  (hl),(2 shl 2) or (1 shl 1)
  288. .wait_host:
  289.     bit 1,(hl)
  290.     jr  nz,.wait_host
  291.     ret
  292.  
  293. usbBusPower:
  294.     call    debugStr
  295.     db  'Powering bus...',0
  296.     call    debugNewLine
  297.     call    $21B70
  298.     ld  hl,mpUsbOtgCsr
  299.     res 5,(hl)
  300.     set 4,(hl)
  301.     ret
  302.  
  303. usbBusReset:
  304. ;   call    debugStr
  305. ;   db  'Resetting bus...',0
  306. ;   call    debugNewLine
  307.     ld  hl,mpUsbPortSC+1
  308.     set 0,(hl)
  309.     call    _Delay10ms
  310.     res 0,(hl)
  311. .wait:
  312.     bit 0,(hl)
  313.     jr  nz,.wait
  314.     ret
  315.  
  316. ; Input:
  317. ;  ix = hub dev
  318. ; Output:
  319. ;  af = ?
  320. ;  bc = ?
  321. ;  hl = ?
  322. ;  iy = ?
  323. hubPortsInit:
  324.     ld  b,(ix+devHubPorts)
  325.     lea iy,ix-3
  326. .clear:
  327.     call    qtdAlloc
  328.     ld  (iy+devSibling),hl
  329.     push    hl
  330.     pop iy
  331.     push    bc
  332.     ld  bc,devParent+1
  333.     call    _MemClear
  334.     ld  (hl),ix
  335.     ld  (iy+devChildren),1
  336.     pop bc
  337.     djnz    .clear
  338.     ld  (iy+devSibling),1
  339.     ret
  340.  
  341. ; Input:
  342. ;  iy = dev
  343. ; Output:
  344. ;  cf = done
  345. ;  iy = next dev
  346. devLoad:
  347.     scf
  348.     bit 0,(iy+devParent)
  349.     ret nz
  350.     ld  iy,(iy+devParent)
  351. devNext:
  352.     bit 0,(iy+devSibling)
  353.     jr  nz,devLoad
  354. .sibling:
  355.     ld  iy,(iy+devSibling)
  356. .children:
  357.     or  a,a
  358.     bit 0,(iy+devChildren)
  359.     ret nz
  360.     lea iy,iy-3
  361.     jr  .sibling
  362.  
  363. ; Output:
  364. ;  iy = first dev
  365. devFirst:
  366.     ld  iy,devRoot
  367.     jr  devNext.children
  368.  
  369. ; Input:
  370. ;  ix = config desc
  371. ;  iy = dev
  372. ; Output:
  373. ;  a = ?
  374. ;  bc = ?
  375. ;  de = ?
  376. ;  hl = ?
  377. ;  ix = qh
  378. devSelectConfig:
  379.     ld  a,(ix+bDescriptorType)
  380.     cp  a,2
  381.     ret nz
  382.     ld  a,(ix+bLength)
  383.     cp  a,9
  384.     ret c
  385.     ld  a,(ix+bConfigurationValue)
  386.     ld  de,reqSetConf+wValue
  387.     ld  (de),a
  388.     dec de
  389.     dec de;reqSetConf
  390.     push    ix
  391.     push    iy
  392.     call    controlDefaultTransfer
  393.     pop iy
  394.     ex  (sp),ix
  395.     call    .next
  396.     pop ix
  397.     call    c,debugAbort
  398.     jp  qhWait
  399. .next:
  400.     or  a,a
  401.     sbc hl,hl
  402.     ex  de,hl
  403.     ld  hl,(ix+wTotalLength)
  404. .loop:
  405.     ld  a,(ix+bLength)
  406.     cp  a,2
  407.     ret c
  408.     ld  e,a
  409.     sbc.s   hl,de
  410.     ret c
  411.     ld  a,(ix+bDescriptorType)
  412.     cp  a,5
  413.     jr  nz,.skip
  414.     ld  a,(ix+bLength)
  415.     cp  a,7
  416.     ret c
  417.     push    de
  418.     push    hl
  419.     push    ix
  420.     call    qhInit
  421.     pop ix
  422.     pop hl
  423.     pop de
  424. .skip:
  425.     ld  a,l
  426.     or  a,h
  427.     ret z
  428.     add ix,de
  429.     jr  .loop
  430.  
  431. ; Input:
  432. ;  a = index
  433. ;  iy = dev
  434. ; Output:
  435. ;  hl = desc size
  436. getConfigDescTotalLength:
  437.     ld  de,reqGetConfDesc4+wValue
  438.     ld  (de),a
  439.     dec de
  440.     dec de;reqGetConfDesc4
  441.     ld  hl,setupPacket
  442.     call    controlDefaultTransfer
  443.     call    qhWait
  444.     ld  hl,(setupPacket+wTotalLength)
  445.     inc hl
  446.     dec.s   hl
  447.     ret
  448.  
  449. ; Output:
  450. ;  f = ?
  451. ;  de = ?
  452. ;  hl = qh
  453. qhAlloc:
  454.     ld  hl,(qhFreeList)
  455.     bit 0,l
  456.     call    nz,debugAbort   ; could malloc, but would require 255 + sizeof qh to properly align (though you would get free qtds I guess)
  457.     ld  de,(hl)
  458.     ld  (qhFreeList),de
  459.     ret
  460.  
  461. ; Input:
  462. ;  ix = qh
  463. ; Output:
  464. ;  zf = error
  465. ;  af = ?
  466. ;  bc = ?
  467. ;  de = ?
  468. ;  hl = ?
  469. qhWait:
  470.     ld  hl,(ix+qhFirstQtd)
  471. .wait:
  472. ;   debugCallStr    'Waiting for transfer '
  473. ;   debugCall   debugHexUHL
  474. ;   debugCallLine   ' to complete...'
  475.     ld  de,(hl) ; FIXME: short packets!!!
  476.     bit 0,e
  477.     ret nz
  478.     set bQtdStatus,l
  479. .status:
  480.     bit 7,(hl)
  481.     jr  nz,.status
  482.     ld  a,(hl)
  483.     res bQtdStatus,l
  484.     call    qtdFree
  485.     ex  de,hl
  486.     ld  (ix+qhFirstQtd),hl
  487.     bit 6,a
  488.     jr  z,.wait
  489.     call    debugAbort
  490.  
  491. ; Input:
  492. ;  ix = qh
  493. ; Output:
  494. ;  a = err bits
  495. ;  f = ?
  496. ;  bc = ?
  497. ;  de = ?
  498. ;  hl = ?
  499. qhReap:
  500.     ld  hl,(ix+qhFirstQtd)
  501.     xor a,a
  502.     jr  .wait
  503. .loop:
  504.     and a,(bmQtdStatusHalted or bmQtdStatusBufErr or bmQtdStatusBabble or bmQtdStatusXactErr or bmQtdStatusMissedUframe) shl 1
  505.     jr  nz,.skip
  506.     set bQtdStatus,l
  507. .shift: ld  a,(hl)
  508.     rlca
  509.     jr  c,.shift
  510.     res bQtdStatus,l
  511. .skip:
  512.     call    qtdFree
  513.     ex  de,hl
  514.     ld  (ix+qhFirstQtd),hl
  515. .wait:
  516. ;   debugCallStr    'Waiting for transfer '
  517. ;   debugCall   debugHexUHL
  518. ;   debugCallLine   ' to complete...'
  519.     ld  de,(hl) ; FIXME: short packets!!!
  520.     bit 0,e
  521.     jr  z,.loop
  522.     ld  (ix+qhOverlay+qtdNext),hl ; flush any pending transactions
  523.     ld  (ix+qhOverlay+qtdAltNext),hl
  524.     ld  (ix+qhOverlay+qtdStatus),0 ; clear pipe halt
  525.     ret
  526.  
  527. ; Input:
  528. ;  ix = ep desc
  529. ;  iy = dev
  530. ; Output:
  531. ;  af = ?
  532. ;  bc = ?
  533. ;  de = ?
  534. ;  hl = ?
  535. ;  ix = qh
  536. qhInit:
  537.     call    qhAlloc
  538.     ld  bc,(ix+bEndpointAddress)
  539.     ld  de,(iy+devAddr)
  540.     push    hl;qh
  541.     inc hl
  542.     inc hl;qh+qhAddr
  543.     ld  (hl),e
  544.     ld  a,c
  545.     and a,$f
  546.     or  a,d
  547.     bit 1,b;(ix+bmEndpointAttributes)
  548.     jr  nz,.skip
  549.     or  a,1 shl 6
  550. .skip:
  551.     inc hl;qh+qhEndPt
  552.     ld  (hl),a
  553.     ld  de,(ix+wMaxPacketSize)
  554.     inc hl;qh+qhMaxPktLen
  555.     ld  (hl),e
  556.     bit 5,a
  557.     ld  a,b
  558.     ld  e,4 shl 4
  559.     jr  nz,.next
  560.     ld  e,1 shl 3
  561.     rrca
  562. .next:
  563.     rrca
  564.     jr  nc,.check
  565.     ld  e,0
  566. .check:
  567.     ld  a,d
  568.     and a,7
  569.     or  a,e
  570.     inc hl;qh+qhMaxPktLen+1
  571.     ld  (hl),a
  572.     ld  de,(iy+devHubInfo-1)
  573.     ld  a,b
  574.     and a,1
  575.     inc hl;qh+qhSmask
  576.     ld  (hl),a
  577.     rrca
  578.     sbc a,a
  579.     and a,7 shl 2
  580.     ld  e,a
  581.     inc hl;qh+qhCmask
  582.     ld  (hl),de
  583.     ld  a,c
  584.     and a,$f
  585.     add a,iyl
  586.     push    iy
  587.     ld  iyl,a
  588.     ld  a,(iy)
  589.     ld  (iy),h
  590.     pop iy
  591.     ld  h,a
  592.     pop ix;qh
  593.     push    hl
  594.     call    qtdInitDummy
  595.     ld  (ix+qhOverlay+qtdNext),hl
  596.     ld  (ix+qhOverlay+qtdAltNext),1
  597.     ld  (ix+qhOverlay+qtdStatus),0
  598.     ld  (ix+qhOverlay+qtdLen+1),0;dt
  599.     ld  (ix+qhDir),bc
  600.     ld  bc,qhHead
  601.     ld  (ix+qhPrev),bc
  602.     ld  (ix+qhFirstQtd),hl
  603.     ld  (ix+qhLastQtd),hl
  604.     ld  hl,(qhHead+qhNext)
  605.     ld  (ix+qhNext),hl
  606.     ld  l,qhOff+qhPrev
  607.     ld  (hl),ix
  608.     ld  (qhHead+qhNext),ix
  609.     pop de
  610.     ld  a,d
  611.     or  a,a
  612.     ret z
  613.     ld  hl,mpUsbCmd
  614.     set 6,(hl)
  615.     ld  l,usbSts
  616. .loop:
  617.     bit 5,(hl)
  618.     jr  z,.loop
  619.     ex  de,hl
  620.     ld  l,qhOff
  621. ;   jr  qhFree
  622.  
  623. ; Input:
  624. ;  hl = qh
  625. ; Output:
  626. ;  bc = ?
  627. qhFree:
  628.     bit 0,l
  629.     call    nz,debugAbort
  630.     ld  bc,(qhFreeList)
  631.     ld  (hl),bc
  632.     ld  (qhFreeList),hl
  633.     ret
  634.  
  635. ; Output:
  636. ;  f = ?
  637. ;  hl = qtd
  638. qtdAlloc:
  639.     push    de
  640.     ld  hl,(qtdFreeList)
  641.     bit 0,l
  642.     call    nz,debugAbort   ; could malloc more I guess, or requisition a qh (would help dynamically fix the ratio)
  643.     ld  de,(hl)
  644.     ld  (qtdFreeList),de
  645.     pop de
  646.     ret
  647.  
  648. ; Input:
  649. ;  hl = qtd
  650. ; Output:
  651. ;  bc = ?
  652. qtdFree:
  653.     bit 0,l
  654.     call    nz,debugAbort
  655.     ld  bc,(qtdFreeList)
  656.     ld  (hl),bc
  657.     ld  (qtdFreeList),hl
  658.     ret
  659.  
  660. ; Output:
  661. ;  f = ?
  662. ;  hl = qtd
  663. qtdInitDummy:
  664.     call    qtdAlloc
  665.     set bQtdStatus,l
  666.     ld  (hl),bmQtdStatusHalted
  667.     res bQtdStatus,l
  668.     ld  (hl),1
  669.     ret
  670.  
  671. ; Input:
  672. ;  a = ep
  673. ;  iy = dev
  674. ; Output:
  675. ;  af = ?
  676. ;  ix = qh
  677. ;  iy = ?
  678. epGetQh:
  679.     and a,$f
  680.     or  a,iyl
  681.     ld  iyl,a
  682.     ld  a,(iy)
  683.     ld  ix,qhHead
  684.     ld  ixh,a
  685.     ret
  686.  
  687. ; Input:
  688. ;  a = length
  689. ;  b = type
  690. ;  hl = buf
  691. ;  iy = dev
  692. ; Output:
  693. ;
  694. getDefaultDesc:
  695.     ld  c,0
  696.  
  697. ; Input:
  698. ;  a = length
  699. ;  b = type
  700. ;  c = index
  701. ;  hl = buf
  702. ;  iy = dev
  703. ; Output:
  704. ;
  705. getDesc:
  706.     ld  de,0
  707.  
  708. ; Input:
  709. ;  a = length
  710. ;  b = type
  711. ;  c = index
  712. ;  de = language
  713. ;  hl = buf
  714. ;  iy = dev
  715. ; Output:
  716. ;
  717. getStrDesc:
  718.     push    hl;buf
  719.     ld  hl,setupPacket+bmRequestType
  720.     push    hl;setupPacket
  721.     ld  (hl),$80
  722.     inc hl;setupPacket+bRequest
  723.     ld  (hl),6
  724.     inc hl;setupPacket+wValue
  725.     ld  (hl),bc
  726.     inc hl
  727.     inc hl;setupPacket+wIndex
  728.     ld  (hl),de
  729.     inc hl
  730.     inc hl;setupPacket+wLength
  731.     ld  (hl),a
  732.     inc hl
  733.     ld  (hl),0
  734.     pop de;setupPacket
  735.     pop hl;buf
  736.     call    controlDefaultTransfer
  737.     jp  qhWait
  738.  
  739. ; Input:
  740. ;  de = req
  741. ;  hl = buf
  742. ;  iy = dev
  743. ; Output:
  744. ;  af = ?
  745. ;  bc = ?
  746. ;  de = ?
  747. ;  hl = ?
  748. ;  ix = qh
  749. ;  iy = ?
  750. controlDefaultTransfer:
  751.     xor a,a
  752.  
  753. ; Input:
  754. ;  a = ep
  755. ;  de = req
  756. ;  hl = buf
  757. ;  iy = dev
  758. ; Output:
  759. ;  af = ?
  760. ;  bc = ?
  761. ;  de = ?
  762. ;  hl = ?
  763. ;  ix = qh
  764. ;  iy = ?
  765. controlTransfer:
  766.     call    epGetQh
  767.  
  768. ; Input:
  769. ;  de = req
  770. ;  hl = buf
  771. ;  ix = qh
  772. ; Output:
  773. ;  af = ?
  774. ;  bc = ?
  775. ;  de = ?
  776. ;  hl = ?
  777. ;  iy = ?
  778. controlTransferAdd:
  779.     ld  a,(de)
  780.     push    af
  781.     push    hl
  782.     ld  hl,wLength
  783.     add hl,de
  784.     inc.s   bc
  785.     ld  c,(hl)
  786.     inc hl
  787.     ld  b,(hl)
  788.     push    bc
  789.     ld  bc,8
  790.     ld  a,2
  791.     call    .ready
  792.     pop bc
  793.     pop de
  794.     pop hl
  795.     push    hl
  796.     ld  a,b
  797.     or  a,c
  798.     ld  a,h
  799.     call    nz,bulkTransferAddEnter
  800.     pop af
  801.     rlca
  802.     and a,1
  803.     xor a,(3 shl 2) or 1
  804.     ld  bc,1 shl 15
  805. .ready:
  806.     call    qtdInitDummy
  807.     jr  qtdInit
  808.  
  809. .add:
  810.     push    de
  811.     add hl,bc
  812.     ld  bc,(ix+qhMaxPktLen)
  813.     sla c
  814.     ld  a,b
  815.     rla
  816.     and a,$f
  817.     ld  d,a
  818.     ld  e,c
  819.     dec de
  820.     and a,d
  821.     ld  b,a
  822.     ld  a,c
  823.     and a,e
  824.     or  a,b
  825.     jr  z,.test
  826.     push    hl
  827.     ld  a,h
  828.     ld  c,l
  829.     sbc hl,hl
  830.     inc.s   de
  831.     ld  b,16
  832. .loop:
  833.     sla c
  834.     rla
  835.     adc hl,hl
  836.     sbc hl,de
  837.     jr  nc,.check
  838.     add hl,de
  839. .check:
  840.     djnz    .loop
  841.     ex  de,hl
  842.     pop hl
  843.     or  a,a
  844.     sbc hl,de
  845.     jr  .next
  846. .test:
  847.     ld  a,e
  848.     cpl
  849.     and a,l
  850.     ld  l,a
  851.     ld  a,d
  852.     cpl
  853.     and a,h
  854.     ld  h,a
  855. .next:
  856.     pop de
  857.     pop af
  858.     push    hl
  859.     pop bc
  860.     add hl,de
  861.     ex  (sp),hl
  862.     sbc hl,bc
  863.     push    hl
  864.     call    qtdInitDummy
  865.     push    iy
  866.     call    bulkTransferAddEnter.add
  867.     pop iy
  868.     pop bc
  869.     pop de
  870.     pop hl
  871.     jr  bulkTransferAddEnter.init
  872.  
  873. ; Input:
  874. ;  a = ep
  875. ;  bc = len
  876. ;  de = buf
  877. ;  iy = dev
  878. ; Output:
  879. ;  af = ?
  880. ;  bc = ?
  881. ;  de = ?
  882. ;  hl = ?
  883. ;  ix = qh
  884. ;  iy = ?
  885. bulkTransfer:
  886.     call    epGetQh
  887.  
  888. ; Input:
  889. ;  bc = len
  890. ;  de = buf
  891. ;  ix = qh
  892. ; Output:
  893. ;  af = ?
  894. ;  bc = ?
  895. ;  de = ?
  896. ;  hl = ?
  897. ;  iy = ?
  898. bulkTransferAdd:
  899.     ld  a,(ix+qhDir)
  900. bulkTransferAddEnter:
  901.     rlca
  902.     and a,1
  903.     call    qtdInitDummy
  904.     push    hl
  905.     pop iy
  906. .init:
  907.     push    bc
  908.     push    af
  909.     ld  a,d
  910.     and a,$f
  911.     xor a,$4f
  912.     inc a
  913.     sbc hl,hl
  914.     ld  h,a
  915.     ld  l,e
  916.     sbc hl,bc
  917.     jr  c,controlTransferAdd.add
  918.     pop af
  919.     pop bc
  920.     lea hl,iy
  921. .add:
  922.     set 7,b
  923.     db  $fd
  924.  
  925. ; Input:
  926. ;  a = ioc or cpage or cerr or pid
  927. ;  bc = dt or len
  928. ;  de = buf
  929. ;  hl = next qtd
  930. ;  ix = qh
  931. ;  hl/iy = alt next qtd
  932. ; Output:
  933. ;  af = ?
  934. ;  b = ?
  935. ;  de = ?
  936. ;  hl = ?
  937. ;  iy = qtd
  938. qtdInit:
  939.     push    hl
  940.     ld  iy,(ix+qhLastQtd)
  941.     ld  (ix+qhLastQtd),hl
  942.     ld  (iy+qtdNext),hl
  943.     pop hl
  944.     ld  (iy+qtdAltNext),hl
  945.     ld  (iy+qtdPid),a
  946.     ld  (iy+qtdLen),bc
  947.     lea hl,iy+qtdBufPtr
  948.     ld  b,5
  949. .loop:
  950.     ld  (hl),de
  951.     ld  a,l
  952.     add a,4
  953.     ld  l,a
  954.     ld  a,d
  955.     or  a,$f
  956.     ld  d,a
  957.     ld  e,$ff
  958.     inc de
  959.     djnz    .loop
  960.     ld  (iy+qtdStatus),bmQtdStatusActive
  961.     ret
  962.  
  963. reqGetDevDesc8:
  964.     db  $80,reqTypeGetDesc,0,descTypeDev,0,0,8,0
  965. reqSetAddr:
  966.     db  $00,reqTypeSetAddr,0,0,0,0,0,0
  967. reqGetConfDesc4:
  968.     db  $80,reqTypeGetDesc,0,descTypeConf,0,0,4,0
  969. reqSetConf:
  970.     db  $00,reqTypeSetConf,0,0,0,0,0,0
  971. ep0Desc:
  972.     db  descLenEndpt,descTypeEndpt,0,0,8,0,0
  973.     align   16
  974. devRoot:
  975.     ds  devHubInfo
  976.     db  1 shl 7,1 shl 6
  977.     db  1,0,0,1,0,0,1,0,0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement