;NavNet high-level API routines include "ti83plus.inc" include "equates.inc" include "usb8x.inc" include "settings.inc" SEGMENT Main GLOBALS ON PUBLIC AboutNavNet,NavNetInit,NavNetGetErrors,NavNetKill EXTERN NavNetCallback,HandleServicePacket,RequestInputData EXTERN DispHexA,DispHexHL,IPutC,DispHexB AboutNavNet: ;Retrieves information about NavNet driver. ;Outputs: ; H: major version of driver ; L: minor version of driver ; BC: size of buffer required for driver (usually 384 bytes) ld h,MAJOR_NAVNET_VERSION ld l,MINOR_NAVNET_VERSION ld bc,NAVNET_DRIVER_SIZE ret NavNetGetErrors: ;Gets the last 8 errors from the NavNet driver. ;Outputs: HL => area of memory containing error codes (sorted by most recent) ld hl,(NavNetMemPtr) ld bc,offErrorCode add hl,bc ret NavNetInit: ;Initializes the NavNet driver and TI-Nspire/CAS device. ;Inputs: ; HL => location of your USBDriverCall (ex. "ld hl,USBDriverCall") ; DE => buffer for driver to use ;Outputs: ; Returns carry flag set if problems ld (iy+nspire8xFlags),0 ld (NavNetNCallPtr),hl ld (NavNetMemPtr),de ld (usb8xMemPtr),bc ;Reset our internal memory ex de,hl ld bc,NAVNET_DRIVER_SIZE B_CALL MemClear ;Set up NavNet callback routine ld hl,NavNetCallbackRAM ld de,(NavNetMemPtr) ld bc,NavNetCallbackRAMEnd-NavNetCallbackRAM push de ldir pop de N_CALL SetCallBack ld hl,nnFlashPage+1-NavNetCallbackRAM add hl,de in a,(6) ld (hl),a ;Initialize USB device N_CALL HostInit ld a,errUSBHostInit jr c,ThrowNavNetError ;Get the config descriptor containing the endpoint information ld hl,(NavNetMemPtr) ld de,offDescScratchSpace add hl,de ld b,descConfig push hl N_CALL ReadDescriptor pop hl ld a,errReadDescriptor jr c,ThrowNavNetError ;Configure the device ld de,5 add hl,de ld b,(hl) push hl N_CALL ConfigureDevice pop hl ld a,errConfigureDevice jr c,ThrowNavNetError ;Set up the incoming/outgoing pipes push hl pop ix ld bc,4 add ix,bc setupPipesLoop: ld a,(ix+1) or a jr z,setupPipesDone cp 05h ;endpoint descriptor jr nz,restartPipesLoop ld b,(ix+2) ld a,(ix+3) and 3 add a,a add a,a add a,a add a,a ld c,a ld d,(ix+4) srl d srl d srl d jr nz,$F inc d $$: ld e,(ix+6) push de push hl bit 7,b res 7,b jr z,isOutPipe ld hl,(NavNetMemPtr) ld de,offInPipe add hl,de xor a cp (hl) jr nz,$F ;HACK: Don't store it twice, because the first one's probably right ld (hl),b $$: pop hl pop de N_CALL SetupInPipe jr restartPipesLoop isOutPipe: ld hl,(NavNetMemPtr) ld de,offOutPipe add hl,de ld (hl),b pop hl pop de N_CALL SetupOutPipe restartPipesLoop: ld b,0 ld c,(ix+0) add ix,bc jr setupPipesLoop setupPipesDone: ;Set up driver memory ld ix,(NavNetMemPtr) ld (ix+offDataInAddr),00h ld (ix+offDataInAddr+1),0D0h ld (ix+offNumBytesReceived),0 ld (ix+offNumBytesReceived+1),0 ld (ix+offPacketsInQueue),0 ld (ix+offSequenceNumber),1 ld (ix+offServiceID),02h ld (ix+offServiceID+1),80h ld (ix+offEventsLeft),0 ld (ix+offErrorCode),0 ;Start receiving data from the device call RequestInputData ;Wait until we've handled the device's address assignment request $$: ei halt call _ProcessNavNetEvents bit addressSent,(iy+nspire8xFlags) jr z,$B xor a ret NavNetKill: ;Kills the NavNet driver. ;Outputs: Returns carry flag set if problems $$: ei halt call _ProcessNavNetEvents jr c,$F in a,(4) bit 3,a scf ret z jr $B $$: N_CALL HostKill xor a ret ProcessNavNetEvents: ;Processes any queued packets/events from the TI-Nspire/CAS. push ix push af push bc push de push hl call _ProcessNavNetEvents pop hl pop de pop bc pop af pop ix ret _ProcessNavNetEvents: DISAVE call __ProcessNavNetEvents EIRESTORE ret __ProcessNavNetEvents: ld ix,(NavNetMemPtr) ld a,(ix+offPacketsInQueue) or a scf ret z ;Process the current packet ld a,03h out (5),a ld ix,0D000h+512 ld h,(ix+4) ld l,(ix+5) ld b,(ix+14) xor a out (5),a ;Handle packet going to service HL push bc push hl push hl ld b,h N_CALL LogCustom pop hl ld b,l N_CALL LogCustom pop hl pop bc ld de,0D281h B_CALL cphlde push hl push bc call z,PNNETest pop bc pop hl call HandleServicePacket DequeuePacket: ld ix,(NavNetMemPtr) dec (ix+offPacketsInQueue) ld a,(ix+offPacketsInQueue) or a ret z ld b,(ix+offPacketsInQueue) sla b ld c,0 ld hl,0D000h+512+512 ld de,0D000h+512 ld a,03h out (5),a ldir xor a out (5),a ret PNNETest: ld hl,0 ld (curRow),hl di ld a,03h out (5),a ld hl,0D000h+512 ld de,bootTemp ld bc,64 ldir xor a out (5),a ld hl,bootTemp ld b,64 call DispHexB ret ThrowNavNetError: ld hl,(NavNetMemPtr) ld bc,offErrorCode+7-1 add hl,bc ld d,h ld e,l inc de ld bc,7 lddr ld ix,(NavNetMemPtr) ld (ix+offErrorCode),a scf ret MakeNCall: push hl ld hl,(NavNetNCallPtr) ex hl,(sp) ret NavNetCallbackRAM: in a,(6) push af nnFlashPage: ld a,0 out (6),a call NavNetCallback pop af out (6),a ret NavNetCallbackRAMEnd: