Mirror of CollapseOS
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

111 строки
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. BLOCKDEV_ERR_OUT_OF_BOUNDS .equ 0x03
  15. ; *** VARIABLES ***
  16. ; A memory pointer to a device table. A device table is a list of addresses
  17. ; pointing to GetC and PutC routines.
  18. BLOCKDEV_TBL .equ BLOCKDEV_RAMSTART
  19. ; Index of the current blockdev selection
  20. BLOCKDEV_SELIDX .equ BLOCKDEV_TBL+(BLOCKDEV_COUNT*4)
  21. ; Address of the current GetC routine
  22. BLOCKDEV_GETC .equ BLOCKDEV_SELIDX+1
  23. ; Address of the current PutC routine
  24. BLOCKDEV_PUTC .equ BLOCKDEV_GETC+2
  25. BLOCKDEV_RAMEND .equ BLOCKDEV_PUTC+2
  26. ; *** CODE ***
  27. ; set DE to point to the table entry at index A.
  28. blkFind:
  29. ld de, BLOCKDEV_TBL
  30. cp 0
  31. ret z ; index is zero? don't loop
  32. push bc
  33. ld b, a
  34. push af
  35. ld a, 4
  36. .loop:
  37. call addDE
  38. djnz .loop
  39. pop af
  40. pop bc
  41. ret
  42. ; Set the GetC pointer of device id A to the value in HL
  43. blkSetGetC:
  44. call blkFind
  45. call writeHLinDE
  46. ret
  47. ; Set the GetC pointer of device id A to the value in HL
  48. blkSetPutC:
  49. call blkFind
  50. inc de
  51. inc de
  52. call writeHLinDE
  53. ret
  54. ; Select block index specified in A
  55. blkSel:
  56. call blkFind
  57. ld (BLOCKDEV_SELIDX), a
  58. ex hl, de
  59. ; now, HL points to the table entry
  60. ld de, BLOCKDEV_GETC
  61. ldi ; copy (HL) into (BLOCKDEV_GETC)
  62. ldi ; .. and into +1
  63. ld de, BLOCKDEV_PUTC
  64. ldi ; same thing for (BLOCKDEV_PUTC)
  65. ldi
  66. ret
  67. blkBselCmd:
  68. .db "bsel", 0b001, 0, 0
  69. blkBsel:
  70. ld a, (hl) ; argument supplied
  71. cp BLOCKDEV_COUNT
  72. jr nc, .error ; if selection >= device count, error
  73. call blkSel
  74. xor a
  75. ret
  76. .error:
  77. ld a, BLOCKDEV_ERR_OUT_OF_BOUNDS
  78. ret
  79. ; Reads one character from blockdev ID specified at A and returns its value
  80. ; in A. Always returns a character and waits until read if it has to.
  81. blkGetC:
  82. push ix
  83. push de
  84. ld de, (BLOCKDEV_GETC)
  85. ld ixh, d
  86. ld ixl, e
  87. pop de
  88. call callIX
  89. pop ix
  90. ret
  91. blkPutC:
  92. push ix
  93. push de
  94. ld de, (BLOCKDEV_PUTC)
  95. ld ixh, d
  96. ld ixl, e
  97. pop de
  98. call callIX
  99. pop ix
  100. ret