;Uninstall routines include "settings.inc" include "ti83plus.inc" include "equates.inc" SEGMENT Main GLOBALS ON EXTERN ExitApp,StartApp,PutSApp,DisplayPressAnyKey,DisplayProgress EXTERN InvalidatePatchData,ApplyPatchBlocks,IsInstalled,GetHookInfo EXTERN appEnd UninstallHookMan: B_CALL ClrLCDFull B_CALL HomeUp call IsInstalled jr c,notInstalled ld hl,sUninstalling call PutSApp ld hl,plotSScreen B_CALL SaveDisp ;Uninstall the OS patch call UninstallOSPatch call ClearHookConfiguration ;Display success B_CALL ClrLCDFull B_CALL HomeUp ld hl,sDone call PutSApp $$: call DisplayPressAnyKey B_CALL GetKey jr StartApp notInstalled: ;Okay, the user thinks we're installed (but we're not) and is trying to uninstall ;Possibilities: ; 1. User is an idiot and we're really not installed at all. ; Put up a message saying to install first. ; 2. The user installed the application, then resent the application (so we have no patch data). ; Put up a message saying to resend the OS. ; 3. The user installed the application, then received someone else's application from a different OS version (so we have incorrect patch data). ; Put up a message saying to resend the OS. call InvalidatePatchData ;We aren't installed and don't have valid patch data for this OS, so erase anything we might have ld hl,sNotInstalled call PutSApp jr $B sUninstalling: DB "Uninstalling",0CEh," " DB " " DB "Be patient; this" DB "WILL take a few " DB "moments.",0 sDone: DB "HookMan has been" DB "successfully " DB "uninstalled!",0 sNotInstalled: DB "HookMan does not" DB "appear to be " DB "installed! " DB "Try installing " DB "first, or try to" DB "resend the OS.",0 ClearHookConfiguration: ;Scan all 24 hook blocks and see if it's installed, and if so, see if it's "our" hook, and if so, deactivate it ld b,24 $$: push bc ld a,b call GetHookInfo pop bc and (hl) ld c,a jr z,skipHook ;Okay, we have a hook; is it ours? push hl pop ix ex de,hl ;HL has the hook's RAM block ld e,(hl) inc hl ld d,(hl) inc hl in a,(6) cp (hl) jr nz,skipHook ;not the same page ex de,hl or a sbc hl,bc jr nz,skipHook ;This is our hook, so kill it ld a,c ld (ix+0),a skipHook: djnz $B ret UninstallOSPatch: ;Copy the patch blocks to RAM (these will always be in order). ld a,10 call DisplayProgress ld hl,saveSScreen ld (iMathPtr5),hl ld hl,(appEnd) ld (iMathPtr4),hl ;(iMathPtr5): current position in saveSScreen ;(iMathPtr4): current position in application copyPatchBlocksLoop: ld hl,(iMathPtr4) push hl pop de ld a,(hl) inc a jr z,copyPatchBlocksDone call IsPatchBlock inc hl ld c,(hl) inc hl ld b,(hl) inc hl push af add hl,bc ld (iMathPtr4),hl pop af jr c,copyPatchBlocksLoop ;We found one ex de,hl ;HL points to the start of the patch block inc bc ;compensate for patch ID inc bc ;compensate for block size 1 inc bc ;compensate for block size 2 ;BC is size of the block ld de,(iMathPtr5) ldir ;copy block to RAM ld (iMathPtr5),de jr copyPatchBlocksLoop copyPatchBlocksDone: ;Terminate group ld hl,(iMathPtr5) ld (hl),0FFh ld a,50 call DisplayProgress ;Parse through the group of patch blocks: ; Erase the swap sector. ; Loop: ; Get the sector containing the page for the first patch block. ; For each page in the sector: ; Copy each byte from the page to the corresponding page in the swap sector, until patch block's address is found. ; When patch block's address is found: ; Write the original data for that block instead of whatever is already there. ; Move to the next patch block. ; Erase the original sector, copy the swap sector to it, and erase the swap sector. res isInstalling,(iy+hookManFlags) ;apply the original code from the patch blocks (reusing code is good, if it works) call ApplyPatchBlocks ld a,75 call DisplayProgress ; Invalidate any existing patch blocks in application by changing the ID to 0. jr InvalidatePatchData IsPatchBlock: cp patch1ID+1 ret z cp patch2ID+1 ret z cp patch3ID+1 ret z cp patchAdditional1+1 ret z cp patchAdditional2+1 ret z cp OSCompatibilityID ret z scf ret