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.

109 lines
2.2KB

  1. ; blockdev
  2. ;
  3. ; A block device is an abstraction over something we can read from, write to.
  4. ;
  5. ; A device that fits this abstraction puts the properly hook into itself, and
  6. ; then the glue code assigns a blockdev ID to that device. It then becomes easy
  7. ; to access arbitrary devices in a convenient manner.
  8. ;
  9. ; This part exposes a new "bsel" command to select the currently active block
  10. ; device.
  11. ; *** DEFINES ***
  12. ; BLOCKDEV_COUNT: The number of devices we manage.
  13. ; *** CONSTS ***
  14. ; *** VARIABLES ***
  15. ; A memory pointer to a device table. A device table is a list of addresses
  16. ; pointing to GetC and PutC routines.
  17. BLOCKDEV_TBL .equ BLOCKDEV_RAMSTART
  18. ; Index of the current blockdev selection
  19. BLOCKDEV_SELIDX .equ BLOCKDEV_TBL+(BLOCKDEV_COUNT*4)
  20. ; Address of the current GetC routine
  21. BLOCKDEV_GETC .equ BLOCKDEV_SELIDX+1
  22. ; Address of the current PutC routine
  23. BLOCKDEV_PUTC .equ BLOCKDEV_GETC+2
  24. BLOCKDEV_RAMEND .equ BLOCKDEV_PUTC+2
  25. ; *** CODE ***
  26. ; set DE to point to the table entry at index A.
  27. blkFind:
  28. ld de, BLOCKDEV_TBL
  29. cp 0
  30. ret z ; index is zero? don't loop
  31. push bc
  32. ld b, a
  33. push af
  34. ld a, 4
  35. .loop:
  36. call addDE
  37. djnz .loop
  38. pop af
  39. pop bc
  40. ret
  41. ; Set the GetC pointer of device id A to the value in HL
  42. blkSetGetC:
  43. call blkFind
  44. call writeHLinDE
  45. ret
  46. ; Set the GetC pointer of device id A to the value in HL
  47. blkSetPutC:
  48. call blkFind
  49. inc de
  50. inc de
  51. call writeHLinDE
  52. ret
  53. ; Select block index specified in A
  54. blkSel:
  55. call blkFind
  56. ld (BLOCKDEV_SELIDX), a
  57. ex hl, de
  58. ; now, HL points to the table entry
  59. ld de, BLOCKDEV_GETC
  60. ldi ; copy (HL) into (BLOCKDEV_GETC)
  61. ldi ; .. and into +1
  62. ld de, BLOCKDEV_PUTC
  63. ldi ; same thing for (BLOCKDEV_PUTC)
  64. ldi
  65. ret
  66. blkBselCmd:
  67. .db "bsel", 0b001, 0, 0
  68. blkBsel:
  69. ret
  70. push af
  71. ld a, (hl) ; argument supplied
  72. cp BLOCKDEV_COUNT
  73. ret nz ; if selection >= device count, don't do anything
  74. ; (will devise a unified cmd error system later)
  75. call blkSel
  76. pop af
  77. ret
  78. ; Reads one character from blockdev ID specified at A and returns its value
  79. ; in A. Always returns a character and waits until read if it has to.
  80. blkGetC:
  81. push ix
  82. push de
  83. ld de, (BLOCKDEV_GETC)
  84. ld ixh, d
  85. ld ixl, e
  86. pop de
  87. call callIX
  88. pop ix
  89. ret
  90. blkPutC:
  91. push ix
  92. push de
  93. ld de, (BLOCKDEV_PUTC)
  94. ld ixh, d
  95. ld ixl, e
  96. pop de
  97. call callIX
  98. pop ix
  99. ret