Advertisement
Eeems

Untitled

Jun 12th, 2011
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; RAM Areas
  2. LCDBuffer       equ 0C000h
  3. clip_mask       equ 0C300h      ; 1 byte
  4. TextX           equ clip_mask+1     ; 1 byte
  5. TextY           equ TextX+1     ; 1 byte
  6. CurrentThreadID     equ TextY+1     ; 1 byte
  7. UserRAM         equ CurrentThreadID+1   ; UserRAM to UserRAMEnd
  8. UserRAMEnd      equ 0FFFFh
  9.  
  10. ; stuff
  11. SwapSector      equ 1Ch ; TI-83+ BE
  12. FATStart        equ 1Bh ; TI-83+ BE
  13. FSTStart        equ 01h ; All models
  14.  
  15. ; FAT
  16. FILE_START      equ 4000h   ; Start of FAT
  17. FILE_NULL       equ 0
  18. FILE_DELETED_F      equ 1
  19. FILE_DELETED_D      equ 2
  20. ;FILE_DELETED_S     equ 3
  21. FILE_FILE       equ 4
  22. FILE_DIRECTORY      equ 5
  23. ;FILE_SYMLINK       equ 6
  24. FILE_END        equ 7
  25.  
  26. ; Thread states
  27. STATE_NONE      equ 0
  28. STATE_ZOMBIE        equ 1
  29. STATE_STOPPED       equ 2
  30. STATE_RUNNING       equ 3
  31. STATE_INTERRUPTABLE equ 4
  32. STATE_UNINTERRUPTABLE   equ 5
  33.  
  34. ; rst
  35. #define rFastCopy   rst 10h
  36.  
  37. ; Error codes
  38. SUCCCESS        equ 0
  39. FIND_FOUND      equ 0
  40. ALLOCATE_SUCCESS    equ 0
  41. ERROR           equ 1
  42. FIND_NOT_IN_DIR     equ 1
  43. ALLOCATE_OUT_OF_MEM equ 1
  44. CORRUPT         equ 2
  45. MEMORY_CORRUPT      equ 2
  46. FIND_MEMORY_CORRUPT equ 2
  47. FIND_BAD_PATH       equ 3
  48. FILE_END_OF_TABLE   equ 4
  49. ; inputs    de = Pointer to path
  50. ; outputs   de = pointer to file
  51. ;       bc = length of file
  52. ;       a  = status code
  53. LoadFileToRAM:
  54.     call GetFilePointer
  55.     ;ld hl,BootMsg
  56.     ld h,d
  57.     ld l,e
  58.     ret
  59. ; returns the pointer to the file from the path in de
  60. ; outputs   de = pointer to file
  61. ;       bc = length of file
  62. ;       a  = status code
  63. ;       h  = flash page
  64.  
  65. GetFilePointer:
  66.  
  67.     ld a, 1 ; Set flash page 1 in bank 2.
  68.  
  69.     out (6), a
  70.     push de
  71.     ld hl,(FILE_START)
  72.     ld de,FILE_START
  73.     or a
  74.     sbc hl,de
  75.         jr z,_ ; if they are the same no corruption
  76.     ; corruption error here
  77.     ld a,FIND_MEMORY_CORRUPT
  78.     pop de
  79.     ret
  80.    
  81. _   pop de ; memory is fine here
  82.     ld hl,FILE_START+2
  83. _DirLoop:
  84.     call ContainsSlash
  85. ;       jr nz, ; Directory in path
  86.         jr nz, _FileSearch ; no directory in path
  87.     ;handle directory searching here
  88.     ld a, (hl)
  89.  
  90.     cp FILE_END ; End of table
  91.  
  92.         jr z,_END_OF_TABLE ; Not found
  93.  
  94.     cp FILE_DIRECTORY ; Directory
  95.  
  96.         jr z, _CheckDirectory
  97.     cp FILE_FILE
  98.         jr nz,_BAD_PATH ; don't handle anything else for now
  99.     call SkipFileEntry
  100.     jr _DirLoop
  101.  
  102. _CheckDirectory:
  103.  
  104.     inc hl
  105.  
  106.     call DirectoryCompare
  107.  
  108.         jr nz, _DirNotFound
  109.  
  110.     ; Directory found :D
  111.  
  112.     ; Move DE past the directory, and move on
  113.  
  114.     inc de
  115.  
  116.     jr _DirLoop
  117. _DirNotFound:
  118.  
  119.     call SkipDirEntry
  120.  
  121.     jr _DirLoop
  122. _FileSearch:
  123.     ld a,(hl)   ;get File type
  124.     cp FILE_END ; End of table
  125.  
  126.         jr z,_END_OF_TABLE ; Not found
  127.     cp FILE_FILE ; File
  128.  
  129.         jr z, _FileCheck
  130.     cp FILE_DIRECTORY
  131.         jr nz,_NOT_IN_DIR ; don't handle other types for now
  132.     call SkipDirEntry
  133.    
  134. ;   push de
  135. ;       push hl
  136. ;           push bc
  137. ;               push af
  138. ;                   call LoadError
  139. ;                   call DrawString
  140. ;                   call FastCopy
  141. ;               pop af
  142. ;           pop bc
  143. ;       pop hl
  144. ;   pop de
  145.    
  146.     jr _FileSearch
  147. _FileCheck:
  148.  
  149.     call CmpStrings
  150.  
  151.         jr z,_
  152.     call SkipFileEntry
  153.     jr _FileSearch
  154. _   call SkipEntryName  ; Found file
  155.     inc hl
  156.  
  157.     ld a, (hl) ; Flash page into A
  158.  
  159.     inc hl
  160.  
  161.     ld e, (hl)
  162.  
  163.     inc hl
  164.  
  165.     ld d, (hl) ; Location in DE
  166.  
  167.     inc hl
  168.  
  169.     ld c, (hl)
  170.  
  171.     inc hl
  172.  
  173.     ld b, (hl) ; Size in BC
  174.  
  175.     out (6), a ; Set flash page
  176.     ld h,a
  177.     ld a,FIND_FOUND ; Give the right Return code
  178.     ret
  179. _NOT_IN_DIR:
  180.     ld a,FIND_NOT_IN_DIR
  181.     ret
  182. _BAD_PATH:
  183.     ld a,FIND_BAD_PATH
  184.     ret
  185. _END_OF_TABLE:
  186.     ld a,FILE_END_OF_TABLE
  187.     ret
  188. ;
  189. SkipDirEntry:
  190.     call SkipEntryName
  191.  
  192.     inc hl \ inc hl ; pass the Dir ID
  193.     ret
  194. ;
  195. SkipFileEntry:
  196.     call SkipEntryName
  197.     push de \ ld de,7 \ add hl,de \ pop de  ; skip the rest of the data
  198.     ret
  199. SkipEntryName:
  200.     ld a, 0
  201.  
  202.     push bc
  203.  
  204.         ld bc, 0FFFFh
  205.  
  206.         cpir    ; Move HL to the end of the name
  207.  
  208.     pop bc
  209.     ret
  210. ; inputs    de = Pointer to path
  211. ; outputs   z  = true
  212. ;       nz = false
  213. ContainsSlash:
  214.     push de
  215.  
  216. _       ld a, (de)
  217.  
  218.         cp '/'
  219.  
  220.         jr z, ++_
  221.  
  222.         or a
  223.  
  224.         jr z, _
  225.  
  226.         inc de
  227.  
  228.         jr -_
  229.  
  230. _   cp 1
  231.  
  232. _   pop de
  233.  
  234.     ret
  235. ; checks to see if the directory exists
  236. DirectoryCompare:
  237.  
  238.         ld a, (de)
  239.  
  240.         cp 0
  241.  
  242.         jr z,_
  243.  
  244.         cp '/'
  245.  
  246.             jr z,_
  247.  
  248.         cp (hl)
  249.  
  250.             ret nz
  251.  
  252.         inc hl
  253.  
  254.         inc de
  255.  
  256.         jr DirectoryCompare
  257.  
  258. _   ld a, (hl)
  259.  
  260.     cp 0
  261.  
  262.         ret z
  263.  
  264.     cp 1
  265.  
  266.     ret
  267.  
  268. FATTable:
  269.     dw FILE_START           ; Type ID = Start of FAT
  270.    
  271.     db FILE_DIRECTORY       ; Type ID = Folder
  272.     db "root",0         ; Folder name
  273.     dw 0                ; Directory ID (word)
  274.  
  275.     db FILE_FILE            ; Type ID = File
  276.     db "boot.txt", 0        ; File name
  277.     db 01h              ; Flash page
  278.     dw BootText         ; Pointer to data (word)
  279.     dw BootTextEnd-BootText     ; Length (word)
  280.     dw 0                ; Directory ID (word)
  281.    
  282.     db FILE_END         ;end of FAT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement