;OS-receiving code include "settings.inc" include "ti83plus.inc" include "equates.inc" SEGMENT Main GLOBALS ON EXTERN PutSApp,IGetKey,keyLoop,StartApp,DispHexA,ReceiveByte,SendByte,DispHexArray,myPage,tempByte EXTERN currentPage,currentOffset,DispHexHL,Abackup,DEbackup,HLbackup,BCbackup,myDispHexA EXTERN sRemoteLinkError,sendDeviceInfo ReceiveOS: B_CALL ClrLCDFull B_CALL HomeUp ld hl,sWarning call PutSApp recvKeyLoop: B_CALL GetKey cp kQuit jr z,StartApp cp kClear jr z,StartApp cp kMode jr z,StartApp cp kEnter jr nz,recvKeyLoop B_CALL ClrLCDFull B_CALL HomeUp ld hl,sReceiving call PutSApp ld hl,sRemoteLinkError call APP_PUSH_ERRORH beginTransfer: B_CALL Get4BytesNC cp 2Dh jr z,sendInfoPacket cp 68h jr nz,pastReady ld h,56h call Send4Bytes jr beginTransfer sendInfoPacket: call sendDeviceInfo jr StartApp pastReady: cp 06h jr z,$F B_JUMP ErrLinkXmit $$: B_CALL GetSmallPacket call DispHexArray ld hl,1 ld (curRow),hl ld hl,sUnlocking call PutSApp ld hl,6 ld (curRow),hl ld hl,sWriting call PutSApp ld hl,sUnlockName rst 20h B_CALL ChkFindSym jr c,errUndefined ld a,b or a jr z,$F errUndefined: B_JUMP ErrUndefined $$: ex de,hl ld c,(hl) inc hl ld b,(hl) inc hl inc hl inc hl dec bc dec bc ld de,userMem di ;This WILL destroy RAM and the OS, no turning back now ldir di ; ld a,07h ; ld hl,45ADh ; ld de,0C000h ; ld bc,1000h ; B_CALL FlashToRam ; call userMem ld a,1 ld (appInfo+2),a rst 28h DW 50CBh ; ld hl,unlockFlash ; ld de,appBackUpScreen ; ld bc,unlockFlashEnd-unlockFlash ; ldir ; call appBackUpScreen ;Set up BCALL replacement ld hl,doBankedCallIX ld de,appBackUpScreen ld bc,doBankedCallIXEnd-doBankedCallIX ldir ;Erase all relevant Flash sectors xor a ld ix,_EraseFlashPage call appBackUpScreen ld a,4 ld ix,_EraseFlashPage call appBackUpScreen ld a,70h ld ix,_EraseFlashPage call appBackUpScreen ld a,74h ld ix,_EraseFlashPage call appBackUpScreen ld a,78h ld ix,_EraseFlashPage call appBackUpScreen ld a,7Ch ld ix,_EraseFlashPage call appBackUpScreen ld h,9 call Send4Bytes ;continue call get4Bytes ;acknowledge ;Some sort of header call get4Bytes ;machine ID, command, size word ld bc,(header+2) headerLoop: push bc call ReceiveByte ;data byte pop bc dec bc ld a,b or c jr nz,headerLoop call ReceiveByte ;checksum call ReceiveByte ld h,56h call Send4Bytes ;acknowledge di receiveOSLoop: ;Header packet with page/offset call get4Bytes ;machine ID, command, size word ld a,(header+1) cp 92h jr z,receiveOSDone ;EOT 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 ;checksum bytes call ReceiveByte ld h,56h call Send4Bytes ;acknowledge ld h,9 call Send4Bytes ;continue call get4Bytes ;acknowledge ld hl,(appData+6) ld (currentOffset),hl ld a,(appData+8) cp 8 jr c,$F push af in a,(2) and 80h pop bc ld a,b jr z,$F set 5,a push af in a,(21h) and 3 pop bc ld a,b jr z,$F set 6,a $$: ld (currentPage),a ;These don't work because PutC no longer exists ; ld hl,7 ; ld (curRow),hl ; ld a,(currentPage) ; call myDispHexA ; ld a,(currentOffset+1) ; call myDispHexA ; ld a,(currentOffset) ; call myDispHexA ;Data packet of 256 bytes to go to page/offset call get4Bytes ;machine ID, command, size word 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 ;checksum bytes call ReceiveByte ld de,(currentOffset) ld a,(currentPage) ld hl,appData ld bc,256 ld ix,_WriteFlash call appBackUpScreen ld h,56h call Send4Bytes ;acknowledge jr receiveOSLoop receiveOSDone: ld h,56h call Send4Bytes ;acknowledge ; res indicOnly,(iy+indicFlags) jp 0000h ; ld hl,7 ; ld (curRow),hl ; B_CALL DispDone ;if receiving anything not TI-OS compatible, this is bad ;$$: B_CALL GetCSC ; or a ; jr z,$B ; jr StartApp doBankedCallIX: ld (Abackup),a ld (DEbackup),de ld (HLbackup),hl ld (BCbackup),bc in a,(6) push af ld a,7Fh call translatePage out (6),a push ix pop hl res 7,h set 6,h ld e,(hl) inc hl ld d,(hl) push de pop ix ld de,returnPoint-doBankedCallIX+appBackUpScreen push de ld a,(Abackup) ld de,(DEbackup) ld hl,(HLbackup) ld bc,(BCbackup) jp (ix) returnPoint: pop af out (6),a ret doBankedCallIXEnd: translatePage: push af in a,(2) and 80h pop bc ld a,b jr z,_83pPage push af in a,(21h) and 3 pop bc ld a,b ret nz and 3Fh ret _83pPage: and 1Fh ret 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 jr SendByte sWarning: DB "!!!!WARNING!!!!!" DB " " DB "Make sure that " DB "prgmUNLOCK is " DB "correct and then" DB "press ",LlBrack,"ENTER] to" DB "continue.",0 sUnlocking: DB "Unlocking",0CEh,0 sReceiving: DB "Receiving",0CEh,0 sWriting: DB "DO NOT INTERRUPT",0 sUnlockName: DB ProtProgObj,"UNLOCK",0 ;myPutC: ; push af ; push hl ; call sub_5950 ; res 0,(iy+8) ; ld hl,curCol ; inc (hl) ; pop hl ; pop af ; ret ;sub_5950: ; di ; push af ; push bc ; push de ; push hl ; push ix ; res 2,(iy+2) ; bit 1,(iy+0Dh) ; jr z,$F ; call sub_600C ; ld (hl),a ;$$: ld l,a ; ld h,0 ; add hl,hl ; add hl,hl ; add hl,hl ; call unk_39CD ; push hl ; pop ix ; ld a,(curRow) ; call sub_670D ; ld (8451h),a ; ld a,(curCol) ; and 1Fh ; add a,20h ; ld b,a ; xor a ; call LCD_delay ; out (10h),a ; ld a,(8451h) ; call sub_5941 ; call some_output ; ld a,b ; call LCD_delay ; out (10h),a ; ld b,8 ;loc_59A2: ; xor a ; dec b ; jr z,loc_59AB ; ld a,(ix+0) ; inc ix ;loc_59AB: ; inc b ; sla a ; bit 3,(iy+5) ; jr z,loc_59E9 ; xor 3Eh ;loc_59B6: ; push af ; ld a,(curCol) ; and 1Fh ; jr z,loc_59E6 ; add a,1Fh ; call LCD_delay ; out (10h),a ; call sub_5928 ; or 1 ; bit 0,(iy+8) ; jr z,loc_59D2 ; and 3Eh ;loc_59D2: ; call LCD_delay ; out (11h),a ; ld a,(curCol) ; and 1Fh ; add a,20h ; call LCD_delay ; out (10h),a ; call sub_5932 ;loc_59E6: ; pop af ; jr loc_59EF ;loc_59E9: ; bit 0,(iy+8) ; jr nz,loc_59B6 ;loc_59EF: ; call LCD_delay ; out (11h),a ; djnz loc_59A2 ; ld a,1 ; call LCD_delay ; out (10h),a ;loc_59FD: ; pop ix ;loc_59FF: ; pop hl ; pop de ; pop bc ; pop af ; ret ;sub_600C: ; push af ; push bc ; push de ; ld hl,(curRow) ; ld a,l ; call Atimes16 ; add a,h ; ld l,a ; ld h,0 ; ld de,8508h ; add hl,de ; pop de ; pop bc ; pop af ; ret ;sub_670D: ; add a,a ; add a,a ; add a,a ; add a,80h ; ret ;sub_5941: ; call some_output2 ; cp 80h ; ret c ; cp 0C0h ; ret nc ; call LCD_delay ; out (10h),a ; ret ;sub_5928: ; call LCD_delay ; in a,(11h) ; call LCD_delay ; in a,(11h) ;sub_5932: ; push af ; ld a,(8451h) ; add a,8 ; sub b ;loc_5939: ; call sub_5941 ; call some_output ; pop af ; ret ;Atimes16: ; add a,a ; add a,a ; add a,a ; add a,a ; ret ;unk_39CD: ; ld de,0C000h ; add hl,de ; ld de,845Ah ; push af ; push bc ; ld b,8 ;$$: ld a,(hl) ; ld (de),a ; inc hl ; inc de ; djnz $B ; pop bc ; pop af ; ld hl,845Ah ; ret ;some_output2: ; push af ; ld a,7 ; call LCD_delay ; out (10h),a ; pop af ; ret ;some_output: ; push af ; ld a,5 ; call LCD_delay ; out (10h),a ; pop af ; ret ;LCD_delay: ; push af ;$$: in a,(2) ; and 2 ; jr z,$B ; bit 3,(iy+41h) ; call nz,small_delay ; call nz,small_delay ; call nz,small_delay ; pop af ; ret ;small_delay: ; push af ; inc hl ; dec hl ; pop af ; ret ;unlockFlash: ; in a,(6) ; push af ; ld a,7Ch ; out (6),a ; ld hl,mystupidpoint-unlockFlash+appBackUpScreen ; push hl ; push af ; ld a,1 ; jp 669Dh ;mystupidpoint: ; pop af ; out (6),a ; ret ;unlockFlashEnd: