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.

blockdev.md 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Using block devices
  2. The `blockdev.asm` part manage what we call "block devices", an abstraction over
  3. something that we can read a byte to, write a byte to, optionally at arbitrary
  4. offsets.
  5. A Collapse OS system can define up to `0xff` devices. Those definitions are made
  6. in the glue code, so they are static.
  7. Definition of block devices happen at include time. It would look like:
  8. [...]
  9. BLOCKDEV_COUNT .equ 1
  10. #include "blockdev.asm"
  11. ; List of devices
  12. .dw sdcGetB, sdcPutB
  13. [...]
  14. That tells `blockdev` that we're going to set up one device, that its GetB and
  15. PutB are the ones defined by `sdc.asm`.
  16. If your block device is read-only or write-only, use dummy routines. `unsetZ`
  17. is a good choice since it will return with the `Z` flag unset, indicating an
  18. error (dummy methods aren't supposed to be called).
  19. Each defined block device, in addition to its routine definition, holds a
  20. seek pointer. This seek pointer is used in shell commands described below.
  21. ## Routine definitions
  22. Parts that implement GetB and PutB do so in a loosely-coupled manner, but
  23. they should try to adhere to the convention, that is:
  24. **GetB**: Get the byte at position specified by `HL`. If it supports 32-bit
  25. addressing, `DE` contains the high-order bytes. Return the result in
  26. `A`. If there's an error (for example, address out of range), unset
  27. `Z`. This routine is not expected to block. We expect the result to be
  28. immediate.
  29. **PutB**: The opposite of GetB. Write the character in `A` at specified
  30. position. `Z` unset on error.
  31. ## Shell usage
  32. `apps/basic/blk.asm` supplies 4 shell commands that you can add to your shell.
  33. See "Optional Modules/blk" in [the shell doc](../apps/basic/README.md).
  34. ### Example
  35. Let's try an example: You glue yourself a Collapse OS with a mmap starting at
  36. `0xe000` as your 4th device (like it is in the shell emulator). Here's what you
  37. could do to copy memory around:
  38. > m=0xe000
  39. > while m<0xe004 getc:poke m a:m=m+1
  40. [enter "abcd"]
  41. > bsel 3
  42. > i=0
  43. > while i<4 getb:puth a:i=i+1
  44. 61626364> bseek 2
  45. > getb:puth a
  46. 63> getb:puth a
  47. 64>