Mirror of CollapseOS
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

121 satır
4.5KB

  1. # Collapse OS usage guide
  2. If you already know Forth, start here. Otherwise, read primer
  3. first.
  4. We begin with a few oddities in Collapse OS compared to tradi-
  5. tional forths, then cover higher level operations.
  6. # Signed-ness
  7. For simplicity purposes, numbers are generally considered
  8. unsigned. For convenience, decimal parsing and formatting
  9. support the "-" prefix, but under the hood, it's all unsigned.
  10. This leads to some oddities. For example, "-1 0 <" is false.
  11. To compare whether something is negative, use the "0<" word
  12. which is the equivalent to "0x7fff >".
  13. # Branching
  14. Branching in Collapse OS is limited to 8-bit. This represents
  15. 64 word references forward or backward. While this might seem
  16. a bit tight at first, having this limit saves us a non-
  17. negligible amount of resource usage.
  18. The reasoning behind this intentional limit is that huge
  19. branches are generally an indicator that a logic ought to be
  20. simplified. So here's one more constraint for you to help you
  21. towards simplicity.
  22. # Interpreter I/O
  23. The INTERPRET loop, the heart of Collapse OS, feeds itself
  24. from the C< word, which yields a character every time it is
  25. called. If no character is available to interpret, it blocks.
  26. During normal operations, C< is simply a buffered layer over
  27. KEY, which has the same behavior (but unbuffered). Before
  28. yielding any character, the C< routine fetches a whole line
  29. from KEY, puts it in a buffer, then yields the buffered line,
  30. one character at a time.
  31. Both C< and KEY can be overridden by setting an alternate
  32. routine at the proper RAM offset (see impl.txt). For example,
  33. C< overrides are used during LOAD so that input comes from disk
  34. blocks instead of keyboard.
  35. KEY overrides can be used to, for example, temporarily give
  36. prompt control to a RS-232 device instead of the keyboard.
  37. Interpreter output is unbuffered and only has EMIT. This
  38. word can also be overriden, mostly as a companion to the
  39. raison d'etre of your KEY override.
  40. # Addressed devices
  41. A@ and A! are the indirect versions of C@ and C!. Their target
  42. word is controlled through A@* and A!* and by default point to
  43. C@ and C*. There is also a AMOVE word that is the same as MOVE
  44. but using A@ and A!.
  45. # Disk blocks
  46. Disk blocks are Collapse OS' main access to permanent storage.
  47. The system is exceedingly simple: blocks are contiguous
  48. chunks of 1024 bytes each living on some permanent media such
  49. as floppy disks or SD cards. They are mostly used for text,
  50. either informational or source code, which is organized into
  51. 16 lines of 64 characters each.
  52. Blocks are referred to by number, 0-indexed. They are read
  53. through BLK@ and written through BLK!. When a block is read,
  54. its 1024 bytes content is copied to an in-memory buffer
  55. starting at BLK( and ending at BLK). Those read/write
  56. operations are often implicit. For example, LIST calls BLK@.
  57. When a word modifies the buffer, it sets the buffer as dirty
  58. by calling BLK!!. BLK@ checks, before it reads its buffer,
  59. whether the current buffer is dirty and implicitly calls BLK!
  60. when it is.
  61. The index of the block currently in memory is kept in BLK>.
  62. Many blocks contain code. That code can be interpreted through
  63. LOAD. Programs stored in blocks frequently have "loader blocks"
  64. that take care of loading all blocks relevant to the program.
  65. Blocks spanning multiple disks are tricky. If your media isn't
  66. large enough to hold all Collapse OS blocks in one unit, you'll
  67. have to make it span multiple disks. Block reference in
  68. informational texts aren't a problem: When you swap your disk,
  69. you mentally adjust the block number you fetch.
  70. However, absolute LOAD operations in Collapse OS aren't aware
  71. of disk spanning and will not work properly in your spanned
  72. system.
  73. Although the usage of absolute LOAD calls are minimally used
  74. (relative LOADs are preferred), they are sometimes unavoidable.
  75. When you span Collapse OS over multiple disks, don't forget to
  76. adjust those absolute LOADs.
  77. # How blocks are organized
  78. Organization of contiguous blocks is an ongoing challenge and
  79. Collapse OS' blocks are never as tidy as they should, but we
  80. try to strive towards a few goals:
  81. 1. Block 0 contains documentation discovery core keys to the
  82. uninitiated.
  83. 2. B1-B4 are for a master index of blocks.
  84. 3. B5-B199 are for runtime usage utilities
  85. 4. B200-B599 are for bootstrapping
  86. 5. The rest is for recipes.
  87. Blocks are currently not organized neatly. I'm planning the
  88. extraction of recipes into some kind of block "overlays" that
  89. would live in the recipes subfolder so each recipe would build
  90. its own specific blkfs which would contain only its recipe code,
  91. starting at B600.