;Link port send/receive routines include "settings.inc" include "ti83plus.inc" include "equates.inc" SEGMENT Main GLOBALS ON EXTERN DispHexA,BCALL_replacement,BCALL_replacementStart,BCALL_replacementEnd,currentOffset,currentPage EXTERN DispHexHL,unlockFlash silentLinkHook: add a,e ld hl,silentLinkHandler call APP_PUSH_ERRORH B_CALL ContinueGetByte B_CALL Get3Bytes ld a,(header+1) ld hl,linkHandlerTable ld b,NUMBER_OF_PACKETS $$: cp (hl) inc hl jr z,$F inc hl inc hl djnz $B ; call DispHexA ;*** TESTING ;Send "refused" packet (don't care whether other device wants it) ld a,5 ld de,1 B_CALL CancelTransmission exitSilentLinkHook: call APP_POP_ERRORH silentLinkHandler: res indicOnly,(iy+indicFlags) xor a ret $$: B_CALL ldhlind ld de,exitSilentLinkHook push de jp (hl) linkHandlerTable: DB 68h DW readyPacket DB 2Dh DW deviceInfoPacket DB 87h DW remoteControlPacket DB 06h DW varHeaderPacket linkHandlerTableEnd: NUMBER_OF_PACKETS EQU (linkHandlerTableEnd-linkHandlerTable)/3 ;Link Packet Handlers ;------------------------------------------------------------------------------ readyPacket: B_CALL SendAck ret deviceInfoPacket: B_CALL SendAck B_CALL Get4BytesNC cp 09h scf ret nz B_CALL SendAck B_CALL GetBaseVer ld hl,ioData ld (hl),a inc hl ld (hl),b inc hl B_CALL GetBootVer ld (hl),a inc hl ld (hl),b inc hl push hl B_CALL Chk_Batt_Low ld a,2 jr nz,$F ld a,3 $$: pop hl ld (hl),a ld (sndRecState),a ;needs to not be 08h B_CALL GetHWVer inc hl ld (hl),a ld de,(localLanguage) inc hl ld (hl),e inc hl ld (hl),d inc hl ld (hl),0 inc hl ld (hl),0 inc hl ld (hl),0 ld a,15h ld hl,ioData ld de,11 B_CALL SendRAMCmd ret remoteControlPacket: B_CALL SendAck B_CALL SendAck ret varHeaderPacket: B_CALL GetSmallPacket ld hl,BCALL_replacementStart ld de,BCALL_replacement ld bc,BCALL_replacementEnd-BCALL_replacementStart ldir call unlockFlash di xor a ld ix,_EraseFlashPage-4000h call BCALL_replacement ld a,4 ld ix,_EraseFlashPage-4000h call BCALL_replacement ld a,74h ld ix,_EraseFlashPage-4000h call BCALL_replacement ld a,78h ld ix,_EraseFlashPage-4000h call BCALL_replacement ld a,7Ch ld ix,_EraseFlashPage-4000h call BCALL_replacement ld h,9 call Send4Bytes call Get4Bytes ;Some other header call Get4Bytes ld bc,(header+2) $$: push bc call ReceiveByte pop bc dec bc ld a,b or c jr nz,$B call ReceiveByte call ReceiveByte ld h,56h call Send4Bytes receiveOSLoop: call Get4Bytes ld a,(header+1) cp 92h jr z,receiveOSDone ld bc,(header+2) ld hl,appData $$: push bc push hl call ReceiveByte pop hl pop bc ld (hl),a inc hl dec bc ld a,b or c jr nz,$B call ReceiveByte call ReceiveByte ld h,56h call Send4Bytes ld h,09h call Send4Bytes call Get4Bytes ld hl,(appData+6) ld (currentOffset),hl ld a,(appData+8) cp 8 jr c,$F or 60h $$: ld (currentPage),a call Get4Bytes ld bc,(header+2) ld hl,appData $$: push bc push hl call ReceiveByte pop hl pop bc ld (hl),a inc hl dec bc ld a,b or c jr nz,$B call ReceiveByte call ReceiveByte ld de,(currentOffset) ld a,(currentPage) ; ld hl,7 ;*** TESTING ; ld (curRow),hl ;*** TESTING ; call DispHexA ;*** TESTING ; ex de,hl ;*** TESTING ; call DispHexHL ;*** TESTING ; ex de,hl ;*** TESTING ld hl,appData ld bc,256 ;bad to hard-code ld ix,_WriteFlashUnsafe-4000h call BCALL_replacement ld h,56h call Send4Bytes jr receiveOSLoop receiveOSDone: ld h,56h call Send4Bytes xor a ld de,0056h ld b,5Ah ld ix,_WriteAByte-4000h call BCALL_replacement ;Reboot jp 0053h ;------------------------------------------------------------------------------ ;Send/Receive Routines ;------------------------------------------------------------------------------ Get4Bytes: call ReceiveByte ld (header),a call ReceiveByte ld (header+1),a call ReceiveByte ld (header+2),a call ReceiveByte ld (header+3),a ret Send4Bytes: push hl ld a,73h call SendByte pop af call SendByte xor a call SendByte xor a SendByte: ld c,a SendByteC: call enableLinkAssist call resetDelayCounter call resetDelayCounter SendByteLoop: ld a,0FAh ld (9C86h),a ;not sure what this is in a,(9) bit 5,a jr z,$F ld a,c out (0Dh),a or a ret $$: call NZifTimeout jr z,SendByteLoop B_JUMP ErrLinkXmit ReceiveByte: di call ReceiveByteToC call RecAByteIO_sub ret c ret nz jr z,ReceiveByte RecAByteIO_sub: cp 1 ld a,c jr nz,$F cp 0E0h jr z,$F B_JUMP ErrLinkXmit $$: cp 0E0h ret nz in a,(9) bit 6,a jr nz,$F and 19h jr nz,CtoAret call sub_6C7F jr c,enableLinkAssistCtoA jr nz,enableLinkAssistCtoA $$: call sub_6CD5 xor a ret CtoAret: ld a,c ret enableLinkAssistCtoA: call enableLinkAssist ld a,c or a ret enableLinkAssist: bit 0,(iy+3Eh) ret nz set 0,(iy+3Eh) in a,(9) xor a out (8),a ret errLinkXmit: B_JUMP ErrLinkXmit ReceiveByteToC: call enableLinkAssist call resetDelayCounter call resetDelayCounter receive_loop: ld a,0 ld (9C86h),a call NZifTimeout jr nz,errLinkXmit in a,(9) bit 6,a jr nz,transmission_error and 11h jr z,receive_loop in a,(0Ah) ld c,a ld a,0 ret transmission_error: and 11h jr z,errLinkXmit in a,(0Ah) ld c,a ld a,1 ret resetDelayCounter: push hl ld hl,0FFFFh in a,(20h) and 1 jr nz,$F ld hl,6800h $$: ld (9CACh),hl pop hl ret NZifTimeout: push hl ld h,2 delay_loop: dec h jr nz,delay_loop ld hl,(9CACh) dec hl ld (9CACh),hl ld a,l or h jr nz,not_timed_out_yet ld a,1 jr timeout not_timed_out_yet: ld a,0 timeout: or a pop hl ret sub_6C7F: push hl ld hl,28h in a,(20h) and 1 jr nz,$F ld l,10h $$: dec hl ld a,h or l jr z,scfP1CtoAret in a,(9) bit 6,a jr nz,xorAP1CtoAret bit 4,a jr nz,$F and 8 jr z,$B in a,(9) bit 6,a jr nz,xorAP1CtoAret and 19h jr z,$B jr nz,$F xorAP1CtoAret: xor a $$: pop hl ld a,c ret scfP1CtoAret: scf jr $B sub_6CD5: call sub_6CF6 call sub_6C49 jr c,errLinkXmit call sub_6C09 loc_6CE4: call ReceiveByteToC ld d,a ld a,c cp 1 push af push de call ReceiveByteToC pop de ld e,a pop af ld b,a ld a,c ret sub_6CF6: in a,(9) and 99h ret nz loc_6D00: res 0,(iy+3Eh) ld a,80h out (8),a ret sub_6C49: push hl ld hl,39h ld a,(20h) and 1 jr nz,loc_6C5C loc_6C59: ld hl,17h loc_6C5C: dec hl ld a,h or l jr nz,loc_6C6A in a,(0) and 3 jr z,loc_6C5C loc_6C67: pop hl ld a,c ret loc_6C6A: scf jr loc_6C67 sub_6C09: ld a,80h out (8),a xor a out (8),a in a,(9) set 0,(iy+3Eh) xor a ret ;------------------------------------------------------------------------------