;Hook code include "settings.inc" include "ti83plus.inc" include "equates.inc" SEGMENT Main GLOBALS ON EXTERN PutSApp,IGetKey,DispHexA,DispHexArray,loadAppVar,IPutS,DispHexHL,translatePage,VPutSApp,DoLog EXTERN varNameBackup lockdownLinkHook: add a,e ld hl,silentLinkHandler call APP_PUSH_ERRORH doLockdown: ; B_CALL GetSmallPacket ld e,0 in a,(0) set 0,(iy+3Eh) B_CALL RejectCommand jr exitSilentLinkHook ;(appData): ;0 = Respond normally ;1 = Ignore all communication ;2 = Reject all communication ;3 = Stealth mode ;4 = When activity, run program ;5 = Alternate remote program ;appData+1: ; zero-terminated program name silentLinkHook: add a,e ld hl,silentLinkHandler call APP_PUSH_ERRORH ; call loadAppVar ; ld hl,appData+1 ; rst 20h ; ld a,(appData) ; dec a ; jr z,exitSilentLinkHook ; dec a ; jr z,doLockdown ; dec a ; dec a ; jr z,executeProgram xor a ld (appData),a ld (iy+linkFlags),0 B_CALL ContinueGetByte B_CALL Get3Bytes ld a,(header+1) ld hl,linkHandlerTable ld b,NUMBER_OF_PACKETS $$: cp (hl) jr z,$F inc hl inc hl djnz $B exitSilentLinkHook: call APP_POP_ERRORH silentLinkHandler: res indicOnly,(iy+indicFlags) xor a ret $$: B_CALL ldhlind jp (hl) readyPacket: ; ld b,68h ; call DoLog B_CALL SendAck jr exitSilentLinkHook enableKeyEcho: ld a,(appData) cp 3 jr z,$F set 5,(iy+33h) $$: B_CALL SendAck jr exitSilentLinkHook disableKeyEcho: ld a,(appData) cp 3 jr z,$F res 5,(iy+33h) $$: B_CALL SendAck jr exitSilentLinkHook enableLockdown: ld a,(appData) cp 3 jr z,$F ld hl,lockdownLinkHook in a,(6) B_CALL EnableLinkActivityHook $$: B_CALL SendAck jr exitSilentLinkHook disableLockdown: ld a,(appData) cp 3 jr z,$F res 4,(iy+33h) $$: B_CALL SendAck jr exitSilentLinkHook getDeviceInfo: call sendDeviceInfo jr exitSilentLinkHook remoteControl: B_CALL SendAck B_CALL SendAck call APP_POP_ERRORH ld a,(appData) cp 3 jr z,exitSilentLinkHook ld a,(header+3) ld (keyExtend),a ld a,(header+2) B_JUMP JForceCmd getScreenContents: ld a,(appData) cp 3 jr z,$F B_CALL SendScreenContents jr exitSilentLinkHook $$: ld hl,ioData ld (hl),00h inc hl ld (hl),03h inc hl ld (hl),12h ld hl,ioData ld de,3 ld a,06h ld (sndRecState),a ;needs to not be 08h B_CALL SendRAMCmd B_CALL Get4BytesNC B_CALL SendAck ld hl,savesscreen ld bc,768 B_CALL MemClear ld hl,savesscreen ld de,768 ld a,15h B_CALL SendRAMCmd jr exitSilentLinkHook receiveVarAndRun: set executeAfter,(iy+linkmanFlags) jr $F receiveVar: receiveVarNormal: receiveRAMVar: res executeAfter,(iy+linkmanFlags) $$: B_CALL GetSmallPacket ld a,(appData) cp 3 jr z,receiveVarStealth ld hl,ioData+2 ld de,varNameBackup ld bc,9 ldir xor a ld (de),a ld a,15h ld (sndRecState),a B_CALL ReceiveVar bit executeAfter,(iy+linkmanFlags) jr z,exitSilentLinkHook B_CALL CloseEditEqu ld hl,varNameBackup rst 20h ld hl,$F call APP_PUSH_ERRORH B_CALL ParseInp call APP_POP_ERRORH call APP_POP_ERRORH B_JUMP JForceCmdNoChar $$: B_CALL ExecutePrgm call APP_POP_ERRORH B_JUMP JForceCmdNoChar receiveVarStealth: ld h,09h B_CALL Send4BytePacket ld de,0000h xor a ld (arcInfo),a B_CALL GetDataPacket B_CALL Get4BytesNC ld a,(header+1) cp 92h jr nz,receiveVar B_CALL SendAck jr exitSilentLinkHook sendVar: B_CALL GetSmallPacket B_CALL ZeroOP1 ld hl,ioData+2 rst 20h ld a,0Ah ld (sndRecState),a B_CALL SendVariable ld h,92h B_CALL Send4BytePacket jr exitSilentLinkHook getCalcID: B_CALL SendAck B_CALL GetCalcSerial ld hl,ioData ld bc,9 B_CALL MemClear ld hl,OP4 ld de,ioData ld bc,5 ldir ld a,15h ld hl,ioData ld de,9 B_CALL SendRAMCmd jr exitSilentLinkHook testguard2Packet: B_CALL GetSmallPacket ld h,09h B_CALL Send4BytePacket B_CALL Get4BytesNC ld a,(header+1) cp 92h jr nz,testguard2Packet B_CALL SendAck call APP_POP_ERRORH ld hl,(curRow) push hl call displayResetAndPause ld hl,0 ld (curRow),hl ld hl,textShadow ld b,128 $$: ld a,(hl) inc hl B_CALL PutC djnz $B pop hl ld (curRow),hl B_JUMP JForceCmdNoChar displayResetAndPause: B_CALL ClrLCDFull B_CALL CursorOff ld hl,sTransferComplete B_CALL SStringLength ld a,96 sub b srl a ld (penCol),a ld a,8 ld (penRow),a ld hl,sTransferComplete+1 call VPutSApp ld hl,2800h ld (penCol),hl ld hl,sConfirmationCode call VPutSApp ld hl,0C05h ld (curRow),hl ld hl,ioData res appTextSave,(iy+appFlags) call PutSApp B_CALL RunIndicOff res indicOnly,(iy+indicFlags) B_CALL GetKeyRetOff ret unknown47h: ld hl,86B7h ld (iMathPtr5),hl ld hl,(header+2) ld de,32 B_CALL cphlde jr nz,throwError B_CALL GetVariableData jr exitSilentLinkHook unknown74h: ld a,47h ld hl,86B7h ld de,32 B_CALL SendRAMCmd jr exitSilentLinkHook deleteVar: B_CALL GetSmallPacket ld a,(appData) cp 3 jr z,varDeleted ld hl,ioData+2 rst 20h ld a,(OP1) cp 14h jr z,$F B_CALL ChkFindSym jr c,exitSilentLinkHook B_CALL DelVarArc B_CALL SendAck jr exitSilentLinkHook $$: B_CALL FindApp jr c,exitSilentLinkHook B_CALL DeleteApp varDeleted: B_CALL SendAck jr exitSilentLinkHook memoryDump: B_CALL GetSmallPacket ld bc,(ioData) ld a,b or a jr nz,throwError ld hl,(pagedCount) push hl ld hl,(pagedGetPtr) push hl ld hl,(pagedPutPtr) push hl ld hl,dumpErrorHandler call APP_PUSH_ERRORH ld bc,(ioData) ld b,c ld de,(ioData+2) B_CALL SetupPagedPtr ld de,(ioData+4) ld (header+2),de ld a,15h ld (header+1),a B_CALL Send4Bytes ld de,0 ld (header+4),de ld de,(header+2) $$: push de ld c,(hl) B_CALL PagedGet ld c,a B_CALL SendDataByte pop de dec de ld a,d or e jr nz,$B call APP_POP_ERRORH pop de pop de pop bc B_CALL SetupPagedPtr ei ld a,(header+4) B_CALL SendAByte ld a,(header+5) B_CALL SendAByte B_CALL Get4BytesNC jr exitSilentLinkHook dumpErrorHandler: pop de pop de pop bc B_CALL SetupPagedPtr jr throwError remoteExecution: B_CALL GetSmallPacket B_CALL SendAck ld a,(appData) cp 3 jr z,exitSilentLinkHook ld hl,ioData+2 rst 20h ld a,(OP1) cp 14h jr z,isFlashApplication ld a,(appData) cp 5 jr nz,$F ld hl,appData+1 rst 20h jr $F executeProgram: call APP_POP_ERRORH $$: ld hl,$F call APP_PUSH_ERRORH set 1,(iy+08h) B_CALL ParseInp call APP_POP_ERRORH B_JUMP JForceCmdNoChar $$: B_CALL ExecutePrgm B_JUMP JForceCmdNoChar isFlashApplication: ld hl,OP1+1 ld de,progToEdit ld bc,8 ldir B_CALL ExecuteApp B_JUMP JForceCmdNoChar ;some apps are dumb and need this throwError: B_JUMP ErrLinkXmit sendDeviceInfo: B_CALL SendAck B_CALL Get4BytesNC cp 09h jr nz,throwError 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 inc 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 linkHandlerTable: DB 68h DW readyPacket DB 2Bh DW enableKeyEcho DB 2Ch DW disableKeyEcho DB 29h DW enableLockdown DB 2Ah DW disableLockdown DB 2Dh DW getDeviceInfo DB 70h DW testguard2Packet DB 47h DW unknown47h DB 74h DW unknown74h DB 87h DW remoteControl DB 6Eh DW getCalcID DB 6Fh DW memoryDump DB 6Dh DW getScreenContents DB 0C9h DW receiveVar DB 0CAh DW receiveVarAndRun DB 0A2h DW sendVar DB 88h DW deleteVar DB 89h DW remoteExecution DB 0B7h DW receiveRAMVar DB 06h DW receiveVarNormal linkHandlerTableEnd: NUMBER_OF_PACKETS EQU (linkHandlerTableEnd-linkHandlerTable)/3 sTransferComplete: DB 17h,"TRANSFER",06h,"COMPLETE",0 sConfirmationCode: DB "CONFIRMATION",06h,"CODE:",0 COMMENT ~ call loadAppVar ld a,(appData) or a jr nz,$F or 1 ret $$: cp 1 jr z,silentLinkHandler ld hl,silentLinkHandler call APP_PUSH_ERRORH res 1,(iy+1Bh) res 2,(iy+1Bh) res 3,(iy+1Bh) res 4,(iy+1Bh) cp 2 jr nz,$F ld e,0 in a,(0) set 0,(iy+3Eh) B_CALL RejectCommand jr abortSilentLink $$: cp 3 jr z,startTransfer cp 5 jr z,startTransfer_1 in a,(0) B_CALL ContinueGetByte runProgramFromAppVar: B_CALL CloseEditEqu ld hl,appData rst 20h ld a,ProgObj ld (OP1),a ; B_CALL ChkFindSym ; jr c,abortSilentLink ; ld a,b ; or a ; jr nz,abortSilentLink ; ex de,hl ; B_CALL ldhlind ; push hl ; B_CALL EnoughMem ; pop hl ; jr c,abortSilentLink ; ld de,userMem ; push hl ; B_CALL InsertMem ; call userMem ; pop de ; ld hl,userMem ; B_CALL DelMem B_JUMP JForceCmdNoChar startTransfer: in a,(0) B_CALL ContinueGetByte startTransfer_1: B_CALL Get3Bytes startTransfer_2: ld a,(header+1) cp 29h jr z,setLockdown cp 2Ah jr z,resetLockdown cp 2Bh jr z,setKeyEcho cp 2Ch jr z,resetKeyEcho cp 92h jr z,sendAckAndEnd cp 6Dh jr z,sendScreenshot cp 87h jr z,forceKeyPress cp 89h jr z,remoteProgramExecution cp 06h jr z,receiveVarHeader cp 68h jr nz,abortSilentLink ackAndGetNextPacket: B_CALL SendAck B_CALL Get4BytesNC jr startTransfer_2 setKeyEcho: set 5,(iy+33h) jr sendAckAndEnd resetKeyEcho: res 5,(iy+33h) jr sendAckAndEnd setLockdown: res 4,(iy+33h) jr sendAckAndEnd resetLockdown: ld a,7Bh call translatePage ld hl,_RejectCommand ld de,OP1 ld bc,3 B_CALL FlashToRam ld hl,(OP1) ld (9B78h),hl ld a,(OP1+2) ld (9B7Ah),a set 3,(iy+33h) set 4,(iy+33h) jr sendAckAndEnd sendScreenshot: B_CALL SendScreenContents jr abortSilentLink FinishReceivingDataPacket: ld bc,(header+2) $$: push bc B_CALL RecAByteIO pop bc dec bc ld a,b or c jr nz,$B B_CALL RecAByteIO B_CALL RecAByteIO ret remoteProgramExecution: B_CALL GetSmallPacket B_CALL SendAck ld a,(appData) cp 5 jr nz,abortSilentLink ;actually, run the program it sent jr runProgramFromAppVar forceKeyPress: ld a,(header+2) B_JUMP JForceCmd receiveVarHeader: B_CALL GetSmallPacket ld h,09h B_CALL Send4BytePacket B_CALL Get4BytesNC call FinishReceivingDataPacket jr ackAndGetNextPacket sendAckAndEnd: B_CALL SendAck abortSilentLink: call APP_POP_ERRORH silentLinkHandler: res indicOnly,(iy+indicFlags) xor a ret ~