Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
2.6KB

  1. ; FS-related basic commands
  2. ; *** Variables ***
  3. ; Handle of the target file
  4. .equ BFS_FILE_HDL BFS_RAMSTART
  5. .equ BFS_RAMEND @+FS_HANDLE_SIZE
  6. ; Lists filenames in currently active FS
  7. basFLS:
  8. ld iy, .iter
  9. jp fsIter
  10. .iter:
  11. ld a, FS_META_FNAME_OFFSET
  12. call addHL
  13. call printstr
  14. jp printcrlf
  15. basLDBAS:
  16. call fsFindFN
  17. ret nz
  18. call bufInit
  19. ld ix, BFS_FILE_HDL
  20. call fsOpen
  21. ld hl, 0
  22. ld de, SCRATCHPAD
  23. .loop:
  24. ld ix, BFS_FILE_HDL
  25. call fsGetB
  26. jr nz, .loopend
  27. inc hl
  28. or a ; null? hum, weird. same as LF
  29. jr z, .lineend
  30. cp LF
  31. jr z, .lineend
  32. ld (de), a
  33. inc de
  34. jr .loop
  35. .lineend:
  36. ; We've just finished reading a line, writing each char in the pad.
  37. ; Null terminate it.
  38. xor a
  39. ld (de), a
  40. ; Ok, line ready
  41. push hl ; --> lvl 1. current file position
  42. ld hl, SCRATCHPAD
  43. call parseDecimal
  44. jr nz, .notANumber
  45. push ix \ pop de
  46. call toSepOrEnd
  47. call rdSep
  48. call bufAdd
  49. pop hl ; <-- lvl 1
  50. ret nz
  51. ld de, SCRATCHPAD
  52. jr .loop
  53. .notANumber:
  54. pop hl ; <-- lvl 1
  55. ld de, SCRATCHPAD
  56. jr .loop
  57. .loopend:
  58. cp a
  59. ret
  60. basFOPEN:
  61. call rdExpr ; file handle index
  62. ret nz
  63. push ix \ pop de
  64. ld a, e
  65. call fsHandle
  66. ; DE now points to file handle
  67. call rdSep
  68. ; HL now holds the string we look for
  69. call fsFindFN
  70. ret nz ; not found
  71. ; Found!
  72. ; FS_PTR points to the file we want to open
  73. push de \ pop ix ; IX now points to the file handle.
  74. jp fsOpen
  75. ; Takes one byte block number to allocate as well we one string arg filename
  76. ; and allocates a new file in the current fs.
  77. basFNEW:
  78. call rdExpr ; file block count
  79. ret nz
  80. call rdSep ; HL now points to filename
  81. push ix \ pop de
  82. ld a, e
  83. jp fsAlloc
  84. ; Deletes filename with specified name
  85. basFDEL:
  86. call fsFindFN
  87. ret nz
  88. ; Found! delete
  89. jp fsDel
  90. basPgmHook:
  91. ; Cmd to find is in (DE)
  92. ex de, hl
  93. ; (HL) is suitable for a direct fsFindFN call
  94. call fsFindFN
  95. ret nz
  96. ; We have a file! Let's load it in memory
  97. ld ix, BFS_FILE_HDL
  98. call fsOpen
  99. ld hl, 0 ; addr that we read in file handle
  100. ld de, USER_CODE ; addr in mem we write to
  101. .loop:
  102. call fsGetB ; we use Z at end of loop
  103. ld (de), a ; Z preserved
  104. inc hl ; Z preserved in 16-bit
  105. inc de ; Z preserved in 16-bit
  106. jr z, .loop
  107. ; Ready to jump. Return .call in IX and basCallCmd will take care
  108. ; of setting (HL) to the arg string. .call then takes care of wrapping
  109. ; the USER_CODE call.
  110. ld ix, .call
  111. cp a ; ensure Z
  112. ret
  113. .call:
  114. ld iy, USER_CODE
  115. call callIY
  116. call basR2Var
  117. or a ; Z set only if A is zero
  118. ret
  119. basFSCmds:
  120. .db "fls", 0
  121. .dw basFLS
  122. .db "ldbas", 0
  123. .dw basLDBAS
  124. .db "fopen", 0
  125. .dw basFOPEN
  126. .db "fnew", 0
  127. .dw basFNEW
  128. .db "fdel", 0
  129. .dw basFDEL
  130. .db "fson", 0
  131. .dw fsOn
  132. .db 0xff ; end of table