;Ndless install code include "settings.inc" include "ti83plus.inc" include "equates.inc" include "usb8x.inc" SEGMENT Main GLOBALS ON EXTERN ExitApp,ProcessNavNetEvents,NavNetRequestDeviceInfo,NavNetCopyFile,strcpy,StartApp,NavNetGetErrors,DispHexA,NavNetKill EXTERN USBDriverCall,USBDriverBuf,NavNetInit,NavNetGetScreenshot,NavNetEchoData,NavNetGetFileFolderInfo,NavNetPutFile EXTERN NavNetCreateDirectory,NavNetDeleteFile,IPutS,IGetKey,BHL_plus_DE,myLoadCIndPaged,DispHexHL,NavNetInstallOS,tempWord DoNdlessInstall: U_CALL StopLog set appAutoScroll,(iy+appFlags) B_CALL ClrLCDFull B_CALL HomeUp ;Make sure loader.tns, hook.tns, and copier.tno exist oncalc and abort if not ld hl,sLoaderTNS rst 20h call VerifyTNSAppVarExists jr c,requiredFilesNotFound ld hl,sHookTNS rst 20h call VerifyTNSAppVarExists jr c,requiredFilesNotFound ld hl,sCopierTNO rst 20h call VerifyTNOAppVarExists jr c,requiredFilesNotFound ;Initialize NavNet driver call InitializeNavNetDriver jr c,NdlessError ld hl,sRequiredFilesFound call NdlessPutS call NdlessNewLine ;See if "ndless-installation" folder exists ld hl,sSearchingForInstallFolder call NdlessPutS call NdlessNewLine ld hl,sInstallDir ld de,appBackUpScreen+256 push de call strcpy pop hl ld de,asm_ram call NavNetGetFileFolderInfo jr c,NdlessError jr z,$F ;It doesn't, so create it ld hl,sNotFoundCreating call NdlessPutS call NdlessNewLine ld hl,appBackUpScreen+256 call NavNetCreateDirectory jr c,NdlessError $$: ld hl,sBackingUpFiles call NdlessPutS call NdlessNewLine ;Back up string resource file ld hl,sStringResPath ld de,appBackUpScreen push de call strcpy ld hl,sStringResBackupPath ld de,appBackUpScreen+256 push de call strcpy pop de pop hl call NavNetCopyFile jr c,NdlessError ;Send loader.tns file to install folder ld hl,sSendingLoader call NdlessPutS call NdlessNewLine ld hl,sLoaderDestinationPath ld de,appBackUpScreen+256 push de call strcpy ld hl,sLoaderTNS rst 20h call GetDataPointers pop de call NavNetPutFile jr c,NdlessError ;Send hook.tns file to install folder ld hl,sSendingHook call NdlessPutS call NdlessNewLine ld hl,sHookDestinationPath ld de,appBackUpScreen+256 push de call strcpy ld hl,sHookTNS rst 20h call GetDataPointers pop de call NavNetPutFile jr c,NdlessError ;Delete "/../phoenix/syst/locales/copysamples" ld hl,sDeletingSamples call NdlessPutS call NdlessNewLine ld hl,sSamplesPath ld de,appBackUpScreen+256 push de call strcpy pop hl call NavNetDeleteFile jr c,NdlessError ;Send OS file copier.tno ld hl,sSendingCopier call NdlessPutS call NdlessNewLine ld hl,sCopierTNO rst 20h call GetDataPointers push de ;Set pointers to BHL ex de,hl B_CALL SetupPagedPtr pop hl ld de,0 ld bc,callbackCopierTNO call NavNetInstallOS jr c,NdlessError ;See if the copier transferred successfully ;This isn't really necessary, it's old testing code from trying to implement NavNetInstallOS COMMENT ~ ld hl,sSamplesPath ld de,appBackUpScreen push de call strcpy ld hl,sCopierBackupPath ld de,appBackUpScreen+256 push de call strcpy pop de pop hl call NavNetCopyFile jr c,NdlessError ~ ;TODO: Maybe verify transfer by: ; Copying "/../phoenix/syst/locales/copysamples" to "/ndless-installation/copier.tns" ; Getting file "/ndless-installation/copier.tns" ; Deleting file "/ndless-installation/copier.tns" ; Comparing copier.tns file we received and our copier.tno file, and aborting if unequal ;I've never seen this transfer fail, but the PC Ndless did this at one point, so I don't know. ;Delete file "/../phoenix/syst/settings/initialized" ld hl,sDeletingInitFile call NdlessPutS call NdlessNewLine ld hl,sInitializedPath ld de,appBackUpScreen+256 push de call strcpy pop hl call NavNetDeleteFile jr c,NdlessError ;Reboot and wait for device to start back up xor a call RebootDevice ;Tell the user to confirm setup dialogs (SELECT ENGLISH AS LANGUAGE) with [HOME], [6] ld hl,sConfirmDialogs call NdlessPutS call IGetKey call NdlessNewLine ;TODO: Check for initialization: ; For twenty seconds: ; Every two seconds: ; Try copying file "/../phoenix/syst/settings/initialized" to "/ndless-installation/initialized.tns" ; If successful, we're initialized ;This isn't really necessary, if the user didn't follow instructions and confirm the setup dialogs, NO EXPLOIT FOR YOU ;Reboot but don't wait for device to start back up or 1 call RebootDevice ;Wait for the user to acknowledge and then quit ld hl,sInstallationSuccessful call NdlessPutS call IGetKey jr StartApp NdlessError: ld hl,sNdlessError call NdlessPutS U_CALL GetErrorCode push bc pop hl call DispHexHL call NavNetGetErrors ld b,3 $$: ld a,(hl) inc hl call DispHexA djnz $B call NdlessNewLine ld hl,sOnToContinue call IPutS $$: in a,(4) bit 3,a jr nz,$B jr StartApp sNdlessError: DB "ERROR ",0 sOnToContinue: DB "Press ",LlBrack,"ON] to " DB "continue",0CEh,0 NdlessPutS: ld a,(hl) inc hl or a ret z B_CALL PutMap ld a,(hl) or a ret z ld a,(curCol) inc a ld (curCol),a cp 16 call z,NdlessNewLine jr NdlessPutS NdlessNewLine: push hl xor a ld (curCol),a B_CALL NewLine pop hl ret InitializeNavNetDriver: ld hl,USBDriverCall ld de,saveSScreen ld bc,USBDriverBuf jr NavNetInit RebootDevice: ;Inputs: A=0 to wait for device to start back up, otherwise return immediately ;TODO: List "/" directory? I don't think we would ever need to do this. push af ld hl,8000h ld (tempWord),hl ld hl,sRebootNow call NdlessPutS call NdlessNewLine ;Install zeroed-out 500,000 byte OS file xor a ld (9C0Ch),a B_CALL InitTimer ld a,b ld de,933*5 ld c,0 B_CALL StartTimer ;In the callback, abort when at 250,000 mark (or after 5 seconds from start of transfer) ld de,0007h ld hl,0A120h ld bc,callbackEmptyOS call NavNetInstallOS B_CALL KillTimer ;Enumerate device or some other USB activity to make it reboot (try getting class information or kill/re-init it) ld hl,appData U_CALL GetClass ;don't care whether this fails or not call NavNetKill pop af or a ; ret nz ;TODO: Wait for shutdown -- keep trying communication for next 10 seconds until it stops responding ;TODO: Wait for startup -- keep trying communication for next 20 seconds until it starts responding ld hl,sRebooted call NdlessPutS call NdlessNewLine call IGetKey call NdlessNewLine call InitializeNavNetDriver jr c,NdlessError ret sRequiredFilesFound: DB "Required files " DB " found",0CEh,0 sSearchingForInstallFolder: DB "Searching for " DB " install folder",0CEh,0 sNotFoundCreating: DB "Not found, " DB " creating",0CEh,0 sBackingUpFiles: DB "Backing up",0CEh,0 sSendingLoader: DB "Sending loader",0CEh,0 sSendingHook: DB "Sending hook",0CEh,0 sDeletingSamples: DB "Deleting " DB " samples",0CEh,0 sSendingCopier: DB "Sending copier",0CEh,0 sDeletingInitFile: DB "Deleting init " DB " file",0CEh,0 sRebootNow: DB "Rebooting",0CEh,0 sStringResPath: DB "/../phoenix/syst/locales/en/strings.res",0 sStringResBackupPath: DB "/ndless/strbackup.tns",0 sInstallDir: DB "/ndless",0 sSamplesPath: DB "/../phoenix/syst/locales/copysamples",0 sCopierBackupPath: DB "/ndless/copier.tns",0 sInitializedPath: DB "/../phoenix/syst/settings/initialized",0 sLoaderTNS: DB AppVarObj,"LOADER",0 sLoaderDestinationPath: DB "/ndless/loader.tns",0 sHookTNS: DB AppVarObj,"HOOK",0 sHookDestinationPath: DB "/ndless/hook.tns",0 sCopierTNO: DB AppVarObj,"COPIER",0 sConfirmDialogs: DB "Confirm setup " DB "dialogs and " DB "press ",LlBrack,"6] to go " DB "to My Documents." DB "Then press any " DB "key",0CEh,0 sRebooted: DB "Reboot has been " DB "attempted. If " DB "unsuccessful, " DB "manually reboot," DB "wait for startup" DB "and press any " DB "key to continue",0CEh,0 sInstallationSuccessful: DB "Installation was" DB " successful!",0 requiredFilesNotFound: B_CALL ClrLCDFull B_CALL HomeUp ld hl,sRequiredFilesNotFound call IPutS call IGetKey jr StartApp sRequiredFilesNotFound: DB "Required files " DB "for Ndless " DB "installation not" DB "found. Verify " DB "files exist and " DB "try again.",0 VerifyTNSAppVarExists: ld de,3532h jr $F VerifyTNOAppVarExists: ld de,3432h $$: push de B_CALL ChkFindSym pop hl ret c push hl ;This AppVar exists, now see if it's a valid TNS/TNO file ex de,hl ld a,b or a jr z,$F ld de,9 call BHL_plus_DE call myLoadCIndPaged ld d,0 ld e,c call BHL_plus_DE $$: ;BHL points to the size bytes call myLoadCIndPaged push bc call myLoadCIndPaged pop de ld d,c ;DE is the data size ;If this is less than two, this can't possibly be valid push hl ld hl,2-1 or a sbc hl,de pop hl jr c,$F ;we should definitely carry if subtracting this from 1 pop hl scf ret $$: call myLoadCIndPaged ;AppVar ID bytes push bc call myLoadCIndPaged pop hl ld h,c pop de or a sbc hl,de scf ret nz xor a ret GetDataPointers: B_CALL ChkFindSym ret c ex de,hl ld a,b or a jr z,$F ld de,9 call BHL_plus_DE call myLoadCIndPaged ld d,0 ld e,c call BHL_plus_DE $$: ;BHL points to the size bytes call myLoadCIndPaged push bc call myLoadCIndPaged pop de ld d,c ;DE is the data size call myLoadCIndPaged ;AppVar ID bytes call myLoadCIndPaged ;BHL now points to file data dec de dec de push de pop ix ;IX now has file data size xor a ret callbackCopierTNO: ;Buffer BC bytes to HL $$: push bc push hl B_CALL PagedGet pop hl ld (hl),a inc hl pop bc dec bc ld a,b or c jr nz,$B xor a ret callbackEmptyOS: ;Zero out the buffer B_CALL MemClear ld a,(9C0Ch) bit 2,a jr nz,$F xor a ret $$: or 1 ret