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.

98 lines
1.7KB

  1. ; *** SHELL COMMANDS ***
  2. fsOnCmd:
  3. .db "fson", 0, 0, 0
  4. jp fsOn
  5. ; Lists filenames in currently active FS
  6. flsCmd:
  7. .db "fls", 0, 0, 0, 0
  8. call fsIsOn
  9. jr nz, .error
  10. call fsBegin
  11. jr nz, .error
  12. .loop:
  13. call fsIsDeleted
  14. jr z, .skip
  15. ld hl, FS_META+FS_META_FNAME_OFFSET
  16. call printstr
  17. call printcrlf
  18. .skip:
  19. call fsNext
  20. jr z, .loop ; Z set? fsNext was successful
  21. xor a
  22. jr .end
  23. .error:
  24. ld a, FS_ERR_NO_FS
  25. .end:
  26. ret
  27. ; Takes one byte block number to allocate as well we one string arg filename
  28. ; and allocates a new file in the current fs.
  29. fnewCmd:
  30. .db "fnew", 0b001, 0b1001, 0b001
  31. push hl
  32. ld a, (hl)
  33. inc hl
  34. call intoHL
  35. call fsAlloc
  36. pop hl
  37. xor a
  38. ret
  39. ; Deletes filename with specified name
  40. fdelCmd:
  41. .db "fdel", 0b1001, 0b001, 0
  42. push hl
  43. push de
  44. call intoHL ; HL now holds the string we look for
  45. call fsFindFN
  46. jr nz, .notfound
  47. ; Found! delete
  48. xor a
  49. ; Set filename to zero to flag it as deleted
  50. ld (FS_META+FS_META_FNAME_OFFSET), a
  51. call fsWriteMeta
  52. ; a already to 0, our result.
  53. jr .end
  54. .notfound:
  55. ld a, FS_ERR_NOT_FOUND
  56. .end:
  57. pop de
  58. pop hl
  59. ret
  60. ; Opens specified filename in specified file handle.
  61. ; First argument is file handle, second one is file name.
  62. ; Example: fopn 0 foo.txt
  63. fopnCmd:
  64. .db "fopn", 0b001, 0b1001, 0b001
  65. push hl
  66. push de
  67. ld a, (hl) ; file handle index
  68. ld de, FS_HANDLES
  69. or a ; cp 0
  70. jr z, .noInc ; DE already point to correct handle
  71. ld b, a
  72. .loop:
  73. ld a, FS_HANDLE_SIZE
  74. call addDE
  75. djnz .loop
  76. .noInc:
  77. ; DE now stores pointer to file handle
  78. inc hl
  79. call intoHL ; HL now holds the string we look for
  80. call fsFindFN
  81. jr nz, .notfound
  82. ; Found!
  83. ; FS_PTR points to the file we want to open
  84. push de \ pop ix ; IX now points to the file handle.
  85. call fsOpen
  86. jr .end
  87. .notfound:
  88. ld a, FS_ERR_NOT_FOUND
  89. .end:
  90. pop de
  91. pop hl
  92. ret