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.

141 lines
2.5KB

  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 parseDecimalC
  44. jr nz, .notANumber
  45. call rdSep
  46. call bufAdd
  47. pop hl ; <-- lvl 1
  48. ret nz
  49. ld de, SCRATCHPAD
  50. jr .loop
  51. .notANumber:
  52. pop hl ; <-- lvl 1
  53. ld de, SCRATCHPAD
  54. jr .loop
  55. .loopend:
  56. cp a
  57. ret
  58. basFOPEN:
  59. call rdExpr ; file handle index
  60. ret nz
  61. push ix \ pop de
  62. ld a, e
  63. call fsHandle
  64. ; DE now points to file handle
  65. call rdSep
  66. ; HL now holds the string we look for
  67. call fsFindFN
  68. ret nz ; not found
  69. ; Found!
  70. ; FS_PTR points to the file we want to open
  71. push de \ pop ix ; IX now points to the file handle.
  72. jp fsOpen
  73. ; Takes one byte block number to allocate as well we one string arg filename
  74. ; and allocates a new file in the current fs.
  75. basFNEW:
  76. call rdExpr ; file block count
  77. ret nz
  78. call rdSep ; HL now points to filename
  79. push ix \ pop de
  80. ld a, e
  81. jp fsAlloc
  82. ; Deletes filename with specified name
  83. basFDEL:
  84. call fsFindFN
  85. ret nz
  86. ; Found! delete
  87. jp fsDel
  88. basPgmHook:
  89. ; Cmd to find is in (DE)
  90. ex de, hl
  91. ; (HL) is suitable for a direct fsFindFN call
  92. call fsFindFN
  93. ret nz
  94. ; We have a file! Let's load it in memory
  95. ld ix, BFS_FILE_HDL
  96. call fsOpen
  97. ld hl, 0 ; addr that we read in file handle
  98. ld de, USER_CODE ; addr in mem we write to
  99. .loop:
  100. call fsGetB ; we use Z at end of loop
  101. ld (de), a ; Z preserved
  102. inc hl ; Z preserved in 16-bit
  103. inc de ; Z preserved in 16-bit
  104. jr z, .loop
  105. ; Ready to jump. Return .call in IX and basCallCmd will take care
  106. ; of setting (HL) to the arg string. .call then takes care of wrapping
  107. ; the USER_CODE call.
  108. ld ix, .call
  109. cp a ; ensure Z
  110. ret
  111. .call:
  112. ld iy, USER_CODE
  113. call callIY
  114. call basR2Var
  115. or a ; Z set only if A is zero
  116. ret
  117. basFSCmds:
  118. .db "fls", 0
  119. .dw basFLS
  120. .db "ldbas", 0
  121. .dw basLDBAS
  122. .db "fopen", 0
  123. .dw basFOPEN
  124. .db "fnew", 0
  125. .dw basFNEW
  126. .db "fdel", 0
  127. .dw basFDEL
  128. .db "fson", 0
  129. .dw fsOn
  130. .db 0xff ; end of table