Mirror of CollapseOS
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

118 Zeilen
2.0KB

  1. ; *** REQUIREMENTS ***
  2. ; blockdev
  3. ; stdio
  4. blkBselCmd:
  5. .db "bsel", 0b001, 0, 0
  6. ld a, (hl) ; argument supplied
  7. cp BLOCKDEV_COUNT
  8. jr nc, .error ; if selection >= device count, error
  9. push de
  10. ld de, BLOCKDEV_SEL
  11. call blkSel
  12. pop de
  13. xor a
  14. ret
  15. .error:
  16. ld a, BLOCKDEV_ERR_OUT_OF_BOUNDS
  17. ret
  18. blkSeekCmd:
  19. .db "seek", 0b001, 0b011, 0b001
  20. ; First, the mode
  21. ld a, (hl)
  22. inc hl
  23. push af ; save mode for later
  24. ; HL points to two bytes that contain out address. Seek expects HL
  25. ; to directly contain that address.
  26. ld a, (hl)
  27. ex af, af'
  28. inc hl
  29. ld a, (hl)
  30. ld l, a
  31. ex af, af'
  32. ld h, a
  33. pop af ; bring mode back
  34. ld de, 0 ; DE is used for seek > 64K which we don't support
  35. call blkSeek
  36. call blkTell
  37. ld a, h
  38. call printHex
  39. ld a, l
  40. call printHex
  41. call printcrlf
  42. xor a
  43. ret
  44. ; Load the specified number of bytes (max 0x100, 0 means 0x100) from IO and
  45. ; write them in the current memory pointer (which doesn't change). If the
  46. ; blkdev hits end of stream before we reach our specified number of bytes, we
  47. ; stop loading.
  48. ;
  49. ; Returns a SHELL_ERR_IO_ERROR only if we couldn't read any byte (if the first
  50. ; call to GetC failed)
  51. ;
  52. ; Example: load 42
  53. blkLoadCmd:
  54. .db "load", 0b001, 0, 0
  55. blkLoad:
  56. push bc
  57. push hl
  58. ld a, (hl)
  59. ld b, a
  60. ld hl, (SHELL_MEM_PTR)
  61. call blkGetC
  62. jr nz, .ioError
  63. jr .intoLoop ; we'v already called blkGetC. don't call it
  64. ; again.
  65. .loop:
  66. call blkGetC
  67. .intoLoop:
  68. ld (hl), a
  69. inc hl
  70. jr nz, .loopend
  71. djnz .loop
  72. .loopend:
  73. ; success
  74. xor a
  75. jr .end
  76. .ioError:
  77. ld a, SHELL_ERR_IO_ERROR
  78. .end:
  79. pop hl
  80. pop bc
  81. ret
  82. ; Load the specified number of bytes (max 0x100, 0 means 0x100) from the current
  83. ; memory pointer and write them to I/O. Memory pointer doesn't move. This puts
  84. ; chars to blkPutC. Raises error if not all bytes could be written.
  85. ;
  86. ; Example: save 42
  87. blkSaveCmd:
  88. .db "save", 0b001, 0, 0
  89. blkSave:
  90. push bc
  91. push hl
  92. ld a, (hl)
  93. ld b, a
  94. ld hl, (SHELL_MEM_PTR)
  95. .loop:
  96. ld a, (hl)
  97. inc hl
  98. call blkPutC
  99. jr nz, .ioError
  100. djnz .loop
  101. .loopend:
  102. ; success
  103. xor a
  104. jr .end
  105. .ioError:
  106. ld a, SHELL_ERR_IO_ERROR
  107. .end:
  108. pop hl
  109. pop bc
  110. ret