;File browser code include "settings.inc" include "ti83plus.inc" include "equates.inc" include "usb8x.inc" SEGMENT Main GLOBALS ON EXTERN StartApp,ExitApp,USBError,SoftKey,VPutSApp,FillRect,IPutS EXTERN USBDriverCall,USBDriverBuf,DispHexHL,navNetRAM EXTERN NavNetInit,NavNetGetDirectoryListing,PutSApp,NavNetGetFileFolderInfo EXTERN NavNetDeleteFile,NavNetDeleteDirectory,CreateDirectory,GetFileUI,PutFileUI EXTERN currentPath,topItem,selectedItem,NavNetKill,dFileSize directoryEntries EQU appBackUpScreen DoFileBrowser: ld hl,currentPath ld (hl),'/' inc hl ld (hl),0 ;Initialize the NavNet driver ld hl,USBDriverCall ld de,saveSScreen ld bc,USBDriverBuf call NavNetInit jr c,USBError DisplayDirectory: ld hl,0 ld (topItem),hl ld (selectedItem),hl res bufferOnly,(iy+plotFlag3) set plotLoc,(iy+plotFlags) res textWrite,(iy+sGrFlags) B_CALL ClrLCDFull B_CALL GrBufClr ld hl,0 ld de,6*256+95 call FillRect ld hl,0003h ld (pencol),hl ld hl,currentPath set textInverse,(iy+textFlags) call VPutSApp res textInverse,(iy+textFlags) ld hl,softMain call SoftKey ld hl,currentPath ld de,directoryEntries call NavNetGetDirectoryListing jr c,USBError DisplayNames: ld hl,8*256+0 ld (penCol),hl ld bc,(directoryEntries) ld a,b or c jr z,browserKeyLoop ld bc,(topItem) ld d,8 displayNamesLoop: push de push bc call GetNamePointer call VPutSApp $$: ld a,(penCol) cp 95 jr nc,$F ld a,' ' B_CALL VPutMap jr $B $$: xor a ld (penCol),a ld a,(penRow) add a,6 ld (penRow),a pop bc inc bc pop de dec d ld hl,(directoryEntries) or a sbc hl,bc jr z,displayNamesLoopDone ld a,d or a jr nz,displayNamesLoop displayNamesLoopDone: ld hl,(selectedItem) ld de,(topItem) or a sbc hl,de call InvertSelection browserKeyLoop: B_CALL GetKey ld hl,(directoryEntries) ld de,0 B_CALL cphlde jr z,$F cp kUp jr z,moveUp cp kDown jr z,moveDown cp kZoom jr z,getFile cp kTrace jr z,deleteFileDirectory cp kEnter jr z,handleEnter $$: cp kYequ jr z,createDirectory cp kWindow jr z,putFile cp kGraph jr z,goUpDirectory cp kQuit jr z,$F cp kClear jr z,$F jr browserKeyLoop $$: call NavNetKill jr StartApp createDirectory: ld a,(currentPath+1) or a jr nz,browserKeyLoop jr CreateDirectory moveUp: ld hl,(selectedItem) ld a,h or l jr z,browserKeyLoop ld de,(topItem) B_CALL cphlde jr nz,$F ;We're the top item, so we need to scroll ld hl,(selectedItem) dec hl ld (selectedItem),hl ld hl,(topItem) dec hl ld (topItem),hl jr DisplayNames $$: ld de,(topItem) or a sbc hl,de call InvertSelection ld hl,(selectedItem) dec hl ld (selectedItem),hl ld de,(topItem) or a sbc hl,de call InvertSelection jr browserKeyLoop moveDown: ld hl,(directoryEntries) ld bc,(selectedItem) inc bc or a sbc hl,bc jr z,browserKeyLoop ld hl,(topItem) ld bc,7 add hl,bc ld de,(selectedItem) B_CALL cphlde jr nz,$F ;We're the bottom item, so we need to scroll ld hl,(selectedItem) inc hl ld (selectedItem),hl ld hl,(topItem) inc hl ld (topItem),hl jr DisplayNames $$: ld hl,(selectedItem) ld de,(topItem) or a sbc hl,de call InvertSelection ld hl,(selectedItem) inc hl ld (selectedItem),hl ld de,(topItem) or a sbc hl,de call InvertSelection jr browserKeyLoop deleteFileDirectory: ;Build the file path ld de,appBackUpScreen+512 call BuildFilePath ld hl,appBackUpScreen+512 ld de,asm_ram call NavNetGetFileFolderInfo jr c,USBError ld a,(asm_ram+8) or a jr nz,$F ;This is a file, delete it ld hl,appBackUpScreen+512 call NavNetDeleteFile jr c,USBError jr DisplayDirectory $$: ;This is a directory, delete it ld hl,appBackUpScreen+512 call NavNetDeleteDirectory jr c,USBError jr DisplayDirectory goUpDirectory: ld a,(currentPath+1) or a jr z,browserKeyLoop ld hl,currentPath $$: ld a,(hl) inc hl or a jr nz,$B dec hl $$: dec hl ld a,(hl) cp '/' jr nz,$B inc hl ld (hl),0 jr DisplayDirectory handleEnter: ;Build the file path ld de,appBackUpScreen+512 call BuildFilePath ld hl,appBackUpScreen+512 ld de,asm_ram call NavNetGetFileFolderInfo jr c,USBError ld a,(asm_ram+8) or a jr nz,$F ;We're a file, do nothing right now jr browserKeyLoop $$: ;Set the new path and display it ld de,currentPath call BuildFilePath jr DisplayDirectory putFile: ld a,(currentPath+1) or a jr z,browserKeyLoop ;Don't put files in the root jr PutFileUI getFile: ;Build the file path ld de,appBackUpScreen+512 call BuildFilePath ld hl,appBackUpScreen+512 ld de,asm_ram call NavNetGetFileFolderInfo jr c,USBError ld a,(asm_ram+8) or a jr nz,browserKeyLoop ld ix,asm_ram ld d,(ix+0) ld e,(ix+1) ld h,(ix+2) ld l,(ix+3) ld (dFileSize),hl ld (dFileSize+2),de jr GetFileUI BuildFilePath: ;Write current path to DE ld hl,currentPath $$: ld a,(hl) ld (de),a inc hl inc de or a jr nz,$B dec de dec de ;Is the last character /? ld a,(de) cp '/' jr z,$F inc de ;No, so add one ld a,'/' ld (de),a $$: inc de ;Write the current entry to DE push de ld bc,(selectedItem) call GetNamePointer pop de $$: ld a,(hl) ld (de),a inc hl inc de or a jr nz,$B ret GetNamePointer: ;BC is the index push bc ld hl,directoryEntries+2 ld a,b or c jr z,gnpDone $$: push bc xor a ld bc,0FFFFh cpir pop bc dec bc ld a,b or c jr nz,$B gnpDone: pop bc ret InvertSelection: push hl ld a,l add a,a ld b,a add a,a add a,b add a,8 ld h,a add a,5 ld d,a ld l,0 ld e,94 B_CALL InvertRect pop hl ret DisplayWaitScreen: ld hl,0003h ld (curRow),hl ld hl,sPleaseWait call IPutS ret softMain: DB " New ",0 DB " Add ",0 DB " Get ",0 DB " Del ",0 DB " Up",0 sPleaseWait: DB " " DB " Please wait... " DB " ",0