;Dummy Nspire responder in peripheral mode ;For testing only include "settings.inc" include "ti83plus.inc" include "equates.inc" SEGMENT Main GLOBALS ON EXTERN receiveAndWriteUSBData,DispHexB,sendUSBData_BCbytesFromHL,IPutC EXTERN Init,InitializePeriphUSB,USBactivityHook,PutSApp DoPeripheralModeTest: B_CALL ClrLCDFull B_CALL HomeUp ld hl,sWaiting call PutSApp call InitializePeriphUSB ; jr c,Init ld hl,calcNspireDeviceDescriptor ld (deviceDescAddress),hl ld hl,calcNspireConfigDescriptor ld (configDescAddress),hl ld hl,HandleIncomingNspireData ld (callbackAddress),hl ld hl,USBactivityHook in a,(6) B_CALL EnableUSBActivityHook periphKeyLoop: B_CALL GetKey cp kClear jr z,$F cp kQuit jr z,periphKeyLoop cp kYequ jr z,DoTest jr periphKeyLoop $$: B_CALL DisableUSBActivityHook B_CALL KillUSB B_CALL KillUSBDevice jr Init DoTest: ld hl,responseTest ld de,ramCode ld bc,64 ldir ld hl,ramCode ld bc,responseTestEnd-responseTest call sendUSBData_BCbytesFromHL ld a,5 call c,IPutC jr periphKeyLoop HandleIncomingNspireData: ;Receive BC bytes di ;just to be on the safe side ld hl,appData res 4,(iy+43h) push bc call receiveAndWriteUSBData ld hl,0 ld (curRow),hl B_CALL ClrLCDFull pop de ld hl,64 or a sbc hl,de jr nc,$F ld de,64 $$: ld b,e ld hl,appData call DispHexB ld ix,appData ld h,(ix+8) ld l,(ix+9) ld de,4020h B_CALL cphlde jr z,handle4020h ret handle4020h: ; ld hl,response4020h ; ld de,ramCode ; ld bc,64 ; ldir ; ld hl,ramCode ; ld bc,DispHexB-response4020h ; call sendUSBData_BCbytesFromHL ; ld a,5 ; call c,IPutC ld hl,response4020h_2 ld de,ramCode ld bc,64 ldir ld hl,ramCode ld bc,responseTest-response4020h_2 call sendUSBData_BCbytesFromHL ld a,5 call c,IPutC ld a,6 call IPutC ret response4020h: DB 54h,0FDh,64h,01h,00h,0FFh,64h,00h,80h,01h,20h,40h,02h,0Ah,01h,07h,40h,20h response4020h_2: DB 54h,0FDh,64h,01h,40h,20h,64h,00h,80h,01h,96h,7Fh,0Bh,00h,03h,1Eh,03h,2Eh,74h,6Eh,73h,00h,2Eh,74h,6Eh,6Fh,00h responseTest: DB 54h,0FDh,64h,01h,40h,29h,64h,00h,80h,01h,96h,7Fh,0Bh,00h,03h,1Eh,03h,2Eh,74h,6Eh,73h,00h,2Eh,74h,6Eh,6Fh,00h responseTestEnd: calcNspireDeviceDescriptor: DB 12h ;size of descriptor DB 01h ;device descriptor type DW 0200h ;USB version DB 00h ;bDeviceClass DB 00h ;bDeviceSubClass DB 00h ;bDeviceProtocol DB 40h ;bMaxPacketSize0 DW 0451h ;wVendorID DW 0E012h ;wProductID DW 0100h ;device release number DB 01h ;manufacturer string index DB 02h ;product string index DB 00h ;serial number string index DB 01h ;bNumConfigurations calcNspireConfigDescriptor: DB 09h ;size of descriptor DB 02h ;config descriptor type DW 32 ;total length of all descriptors ; DB 3+calcNspireConfigDescriptorEnd-calcNspireConfigDescriptorStart calcNspireConfigDescriptorStart: DB 01h ;number of interfaces DB 01h ;configuration number DB 00h ;configuration string index DB 10000000b ;bmAttributes DB 50 ;bMaxPower (100mA) ; DB 03h ; DB 09h ; DB 01h ;Interface descriptor DB 09h ;size of descriptor DB 04h ;interface descriptor type DB 00h ;interface number DB 00h ;bAlternateSetting DB 03h ;bNumEndpoints DB 0FFh ;bInterfaceClass DB 02h ;bInterfaceSubClass DB 00h ;bInterfaceProtocol DB 00h ;interface string index ;Endpoint descriptor (in) DB 07h ;size of descriptor DB 05h ;endpoint descriptor type DB 10000001b ;bEndpointAddress DB 02h ;bulk endpoint DW 0040h ;wMaxPacketSize DB 00h ;bInterval ;Endpoint descriptor (out) DB 07h ;size of descriptor DB 05h ;endpoint descriptor type DB 00000010b ;bEndpointAddress DB 02h ;bulk endpoint DW 0040h ;wMaxPacketSize DB 00h ;bInterval ;Endpoint descriptor (in) DB 07h ;size of descriptor DB 05h ;endpoint descriptor type DB 10000011b ;bEndpointAddress DB 02h ;bulk endpoint DW 0040h ;wMaxPacketSize DB 00h ;bInterval calcNspireConfigDescriptorEnd: sWaiting: DB "Waiting",0CEh,0