Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; RAM Areas
- LCDBuffer equ 0C000h
- clip_mask equ 0C300h ; 1 byte
- TextX equ clip_mask+1 ; 1 byte
- TextY equ TextX+1 ; 1 byte
- CurrentThreadID equ TextY+1 ; 1 byte
- UserRAM equ CurrentThreadID+1 ; UserRAM to UserRAMEnd
- UserRAMEnd equ 0FFFFh
- ; stuff
- SwapSector equ 1Ch ; TI-83+ BE
- FATStart equ 1Bh ; TI-83+ BE
- FSTStart equ 01h ; All models
- ; FAT
- FILE_START equ 4000h ; Start of FAT
- FILE_NULL equ 0
- FILE_DELETED_F equ 1
- FILE_DELETED_D equ 2
- ;FILE_DELETED_S equ 3
- FILE_FILE equ 4
- FILE_DIRECTORY equ 5
- ;FILE_SYMLINK equ 6
- FILE_END equ 7
- ; Thread states
- STATE_NONE equ 0
- STATE_ZOMBIE equ 1
- STATE_STOPPED equ 2
- STATE_RUNNING equ 3
- STATE_INTERRUPTABLE equ 4
- STATE_UNINTERRUPTABLE equ 5
- ; rst
- #define rFastCopy rst 10h
- ; Error codes
- SUCCCESS equ 0
- FIND_FOUND equ 0
- ALLOCATE_SUCCESS equ 0
- ERROR equ 1
- FIND_NOT_IN_DIR equ 1
- ALLOCATE_OUT_OF_MEM equ 1
- CORRUPT equ 2
- MEMORY_CORRUPT equ 2
- FIND_MEMORY_CORRUPT equ 2
- FIND_BAD_PATH equ 3
- FILE_END_OF_TABLE equ 4
- ; inputs de = Pointer to path
- ; outputs de = pointer to file
- ; bc = length of file
- ; a = status code
- LoadFileToRAM:
- call GetFilePointer
- ;ld hl,BootMsg
- ld h,d
- ld l,e
- ret
- ; returns the pointer to the file from the path in de
- ; outputs de = pointer to file
- ; bc = length of file
- ; a = status code
- ; h = flash page
- GetFilePointer:
- ld a, 1 ; Set flash page 1 in bank 2.
- out (6), a
- push de
- ld hl,(FILE_START)
- ld de,FILE_START
- or a
- sbc hl,de
- jr z,_ ; if they are the same no corruption
- ; corruption error here
- ld a,FIND_MEMORY_CORRUPT
- pop de
- ret
- _ pop de ; memory is fine here
- ld hl,FILE_START+2
- _DirLoop:
- call ContainsSlash
- ; jr nz, ; Directory in path
- jr nz, _FileSearch ; no directory in path
- ;handle directory searching here
- ld a, (hl)
- cp FILE_END ; End of table
- jr z,_END_OF_TABLE ; Not found
- cp FILE_DIRECTORY ; Directory
- jr z, _CheckDirectory
- cp FILE_FILE
- jr nz,_BAD_PATH ; don't handle anything else for now
- call SkipFileEntry
- jr _DirLoop
- _CheckDirectory:
- inc hl
- call DirectoryCompare
- jr nz, _DirNotFound
- ; Directory found :D
- ; Move DE past the directory, and move on
- inc de
- jr _DirLoop
- _DirNotFound:
- call SkipDirEntry
- jr _DirLoop
- _FileSearch:
- ld a,(hl) ;get File type
- cp FILE_END ; End of table
- jr z,_END_OF_TABLE ; Not found
- cp FILE_FILE ; File
- jr z, _FileCheck
- cp FILE_DIRECTORY
- jr nz,_NOT_IN_DIR ; don't handle other types for now
- call SkipDirEntry
- ; push de
- ; push hl
- ; push bc
- ; push af
- ; call LoadError
- ; call DrawString
- ; call FastCopy
- ; pop af
- ; pop bc
- ; pop hl
- ; pop de
- jr _FileSearch
- _FileCheck:
- call CmpStrings
- jr z,_
- call SkipFileEntry
- jr _FileSearch
- _ call SkipEntryName ; Found file
- inc hl
- ld a, (hl) ; Flash page into A
- inc hl
- ld e, (hl)
- inc hl
- ld d, (hl) ; Location in DE
- inc hl
- ld c, (hl)
- inc hl
- ld b, (hl) ; Size in BC
- out (6), a ; Set flash page
- ld h,a
- ld a,FIND_FOUND ; Give the right Return code
- ret
- _NOT_IN_DIR:
- ld a,FIND_NOT_IN_DIR
- ret
- _BAD_PATH:
- ld a,FIND_BAD_PATH
- ret
- _END_OF_TABLE:
- ld a,FILE_END_OF_TABLE
- ret
- ;
- SkipDirEntry:
- call SkipEntryName
- inc hl \ inc hl ; pass the Dir ID
- ret
- ;
- SkipFileEntry:
- call SkipEntryName
- push de \ ld de,7 \ add hl,de \ pop de ; skip the rest of the data
- ret
- SkipEntryName:
- ld a, 0
- push bc
- ld bc, 0FFFFh
- cpir ; Move HL to the end of the name
- pop bc
- ret
- ; inputs de = Pointer to path
- ; outputs z = true
- ; nz = false
- ContainsSlash:
- push de
- _ ld a, (de)
- cp '/'
- jr z, ++_
- or a
- jr z, _
- inc de
- jr -_
- _ cp 1
- _ pop de
- ret
- ; checks to see if the directory exists
- DirectoryCompare:
- ld a, (de)
- cp 0
- jr z,_
- cp '/'
- jr z,_
- cp (hl)
- ret nz
- inc hl
- inc de
- jr DirectoryCompare
- _ ld a, (hl)
- cp 0
- ret z
- cp 1
- ret
- FATTable:
- dw FILE_START ; Type ID = Start of FAT
- db FILE_DIRECTORY ; Type ID = Folder
- db "root",0 ; Folder name
- dw 0 ; Directory ID (word)
- db FILE_FILE ; Type ID = File
- db "boot.txt", 0 ; File name
- db 01h ; Flash page
- dw BootText ; Pointer to data (word)
- dw BootTextEnd-BootText ; Length (word)
- dw 0 ; Directory ID (word)
- db FILE_END ;end of FAT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement