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.

94 lines
1.3KB

  1. ; io - handle ed's I/O
  2. ; *** Consts ***
  3. ;
  4. ; Max length of a line
  5. .equ IO_MAXLEN 0x7f
  6. ; *** Variables ***
  7. ; Handle of the target file
  8. .equ IO_FILE_HDL IO_RAMSTART
  9. ; block device targeting IO_FILE_HDL
  10. .equ IO_BLK @+FS_HANDLE_SIZE
  11. ; Buffer for lines read from I/O.
  12. .equ IO_LINE @+BLOCKDEV_SIZE
  13. .equ IO_RAMEND @+IO_MAXLEN+1 ; +1 for null
  14. ; *** Code ***
  15. ; Given a file name in (HL), open that file in (IO_FILE_HDL) and open a blkdev
  16. ; on it at (IO_BLK).
  17. ioInit:
  18. call fsFindFN
  19. ret nz
  20. ld ix, IO_FILE_HDL
  21. call fsOpen
  22. ld de, IO_BLK
  23. ld hl, .blkdev
  24. jp blkSet
  25. .fsGetB:
  26. ld ix, IO_FILE_HDL
  27. jp fsGetB
  28. .fsPutB:
  29. ld ix, IO_FILE_HDL
  30. jp fsPutB
  31. .blkdev:
  32. .dw .fsGetB, .fsPutB
  33. ioGetB:
  34. push ix
  35. ld ix, IO_BLK
  36. call _blkGetB
  37. pop ix
  38. ret
  39. ioPutB:
  40. push ix
  41. ld ix, IO_BLK
  42. call _blkPutB
  43. pop ix
  44. ret
  45. ioSeek:
  46. push ix
  47. ld ix, IO_BLK
  48. call _blkSeek
  49. pop ix
  50. ret
  51. ioTell:
  52. push ix
  53. ld ix, IO_BLK
  54. call _blkTell
  55. pop ix
  56. ret
  57. ioSetSize:
  58. push ix
  59. ld ix, IO_FILE_HDL
  60. call fsSetSize
  61. pop ix
  62. ret
  63. ; Write string (HL) in current file. Ends line with LF.
  64. ioPutLine:
  65. push hl
  66. .loop:
  67. ld a, (hl)
  68. or a
  69. jr z, .loopend ; null, we're finished
  70. call ioPutB
  71. jr nz, .error
  72. inc hl
  73. jr .loop
  74. .loopend:
  75. ; Wrote the whole line, write ending LF
  76. ld a, 0x0a
  77. call ioPutB
  78. jr z, .end ; success
  79. ; continue to error
  80. .error:
  81. call unsetZ
  82. .end:
  83. pop hl
  84. ret