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.

179 lines
2.7KB

  1. .inc "blkdev.h"
  2. .inc "fs.h"
  3. .inc "err.h"
  4. .inc "ascii.h"
  5. .equ RAMSTART 0x2000
  6. .equ USER_CODE 0x4200
  7. .equ STDIO_PORT 0x00
  8. .equ FS_DATA_PORT 0x01
  9. .equ FS_ADDR_PORT 0x02
  10. jp init
  11. ; *** JUMP TABLE ***
  12. jp strncmp
  13. jp upcase
  14. jp findchar
  15. jp blkSelPtr
  16. jp blkSel
  17. jp blkSet
  18. jp blkSeek
  19. jp blkTell
  20. jp blkGetB
  21. jp blkPutB
  22. jp fsFindFN
  23. jp fsOpen
  24. jp fsGetB
  25. jp fsPutB
  26. jp fsSetSize
  27. jp fsOn
  28. jp fsIter
  29. jp fsAlloc
  30. jp fsDel
  31. jp fsHandle
  32. jp printstr
  33. jp printnstr
  34. jp _blkGetB
  35. jp _blkPutB
  36. jp _blkSeek
  37. jp _blkTell
  38. jp printcrlf
  39. jp stdioGetC
  40. jp stdioPutC
  41. jp stdioReadLine
  42. .inc "core.asm"
  43. .inc "str.asm"
  44. .equ BLOCKDEV_RAMSTART RAMSTART
  45. .equ BLOCKDEV_COUNT 4
  46. .inc "blockdev.asm"
  47. ; List of devices
  48. .dw fsdevGetB, fsdevPutB
  49. .dw stdoutGetB, stdoutPutB
  50. .dw stdinGetB, stdinPutB
  51. .dw mmapGetB, mmapPutB
  52. .equ MMAP_START 0xe000
  53. .inc "mmap.asm"
  54. .equ STDIO_RAMSTART BLOCKDEV_RAMEND
  55. .equ STDIO_GETC emulGetC
  56. .equ STDIO_PUTC emulPutC
  57. .inc "stdio.asm"
  58. .equ FS_RAMSTART STDIO_RAMEND
  59. .equ FS_HANDLE_COUNT 2
  60. .inc "fs.asm"
  61. ; *** BASIC ***
  62. ; RAM space used in different routines for short term processing.
  63. .equ SCRATCHPAD_SIZE STDIO_BUFSIZE
  64. .equ SCRATCHPAD FS_RAMEND
  65. .inc "lib/util.asm"
  66. .inc "lib/ari.asm"
  67. .inc "lib/parse.asm"
  68. .inc "lib/fmt.asm"
  69. .equ EXPR_PARSE parseLiteralOrVar
  70. .inc "lib/expr.asm"
  71. .inc "basic/util.asm"
  72. .inc "basic/parse.asm"
  73. .inc "basic/tok.asm"
  74. .equ VAR_RAMSTART SCRATCHPAD+SCRATCHPAD_SIZE
  75. .inc "basic/var.asm"
  76. .equ BUF_RAMSTART VAR_RAMEND
  77. .inc "basic/buf.asm"
  78. .equ BFS_RAMSTART BUF_RAMEND
  79. .inc "basic/fs.asm"
  80. .inc "basic/blk.asm"
  81. .equ BAS_RAMSTART BFS_RAMEND
  82. .inc "basic/main.asm"
  83. init:
  84. di
  85. ; setup stack
  86. ld sp, 0xffff
  87. call fsInit
  88. ld a, 0 ; select fsdev
  89. ld de, BLOCKDEV_SEL
  90. call blkSel
  91. call fsOn
  92. call basInit
  93. ld hl, basFindCmdExtra
  94. ld (BAS_FINDHOOK), hl
  95. jp basStart
  96. basFindCmdExtra:
  97. ld hl, basFSCmds
  98. call basFindCmd
  99. ret z
  100. ld hl, basBLKCmds
  101. call basFindCmd
  102. ret z
  103. jp basPgmHook
  104. emulGetC:
  105. ; Blocks until a char is returned
  106. in a, (STDIO_PORT)
  107. cp a ; ensure Z
  108. ret
  109. emulPutC:
  110. out (STDIO_PORT), a
  111. ret
  112. fsdevGetB:
  113. ld a, e
  114. out (FS_ADDR_PORT), a
  115. ld a, h
  116. out (FS_ADDR_PORT), a
  117. ld a, l
  118. out (FS_ADDR_PORT), a
  119. in a, (FS_ADDR_PORT)
  120. or a
  121. ret nz
  122. in a, (FS_DATA_PORT)
  123. cp a ; ensure Z
  124. ret
  125. fsdevPutB:
  126. push af
  127. ld a, e
  128. out (FS_ADDR_PORT), a
  129. ld a, h
  130. out (FS_ADDR_PORT), a
  131. ld a, l
  132. out (FS_ADDR_PORT), a
  133. in a, (FS_ADDR_PORT)
  134. cp 2 ; only A > 1 means error
  135. jr nc, .error ; A >= 2
  136. pop af
  137. out (FS_DATA_PORT), a
  138. cp a ; ensure Z
  139. ret
  140. .error:
  141. pop af
  142. jp unsetZ ; returns
  143. .equ STDOUT_HANDLE FS_HANDLES
  144. stdoutGetB:
  145. ld ix, STDOUT_HANDLE
  146. jp fsGetB
  147. stdoutPutB:
  148. ld ix, STDOUT_HANDLE
  149. jp fsPutB
  150. .equ STDIN_HANDLE FS_HANDLES+FS_HANDLE_SIZE
  151. stdinGetB:
  152. ld ix, STDIN_HANDLE
  153. jp fsGetB
  154. stdinPutB:
  155. ld ix, STDIN_HANDLE
  156. jp fsPutB