;NavNet callback routine include "ti83plus.inc" include "equates.inc" include "usb8x.inc" include "settings.inc" SEGMENT Main GLOBALS ON PUBLIC NavNetCallback EXTERN MakeNCall,__ProcessNavNetEvents,DoLog2 NavNetCallback: DISAVE push ix ld a,b cp cbStall jr z,cbHandleStall cp cbNak jr z,cbHandleNAK cp cbNewData jr nz,cbHandleUnknown ld a,e or a jr z,cbExit ;Uh...we didn't receive anything? Why would this happen? ;Store the new data just received set receivingPacket,(iy+nspire8xFlags) ld ix,(NavNetMemPtr) ld b,0 ld c,e ld l,(ix+offNumBytesReceived) ld h,(ix+offNumBytesReceived+1) add hl,bc ld (ix+offNumBytesReceived),l ld (ix+offNumBytesReceived+1),h ld e,(ix+offDataInAddr) ld d,(ix+offDataInAddr+1) ld hl,(usb8xMemPtr) ld a,03h out (5),a ldir xor a out (5),a ld (ix+offDataInAddr),e ld (ix+offDataInAddr+1),d ;See if we have enough of the packet to determine whether we can even be done ld bc,16 ld l,(ix+offNumBytesReceived) ld h,(ix+offNumBytesReceived+1) or a sbc hl,bc jr c,cbRequestMore ;See if we have received a complete packet ld a,03h out (5),a ld hl,0D000h+12 ld c,(hl) xor a out (5),a ld hl,16 add hl,bc ld e,(ix+offNumBytesReceived) ld d,(ix+offNumBytesReceived+1) ;HL is the total packet size ;DE is the bytes received so far or a sbc hl,de ;If not, request more data and exit jr c,$F ;Hopefully this never happens... jr nz,cbRequestMore $$: ;We have a total packet! res receivingPacket,(iy+nspire8xFlags) ;Add it to our queue of packets to process ld d,(ix+offPacketsInQueue) sla d inc d inc d ld e,0 ld hl,0D000h add hl,de ex de,hl ld hl,0D000h ld bc,512 ld a,03h out (5),a ldir xor a out (5),a inc (ix+offPacketsInQueue) ;Reset our pointers ld (ix+offDataInAddr),0 ld (ix+offDataInAddr+1),0D0h ld (ix+offNumBytesReceived),0 ld (ix+offNumBytesReceived+1),0 cbRequestMore: ;Need moar data... call RequestInputData jr cbExit cbHandleStall: cbHandleNAK: cbHandleUnknown: ;Uh...oops? cbExit:;call __ProcessNavNetEvents pop ix EIRESTORE ret RequestInputData: ld ix,(NavNetMemPtr) ld b,(ix+offInPipe) N_CALL ReqData ret