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.

201 lines
3.4KB

  1. ; RAMSTART is a label at the end of the file
  2. .equ RAMEND 0xcfff
  3. ; Address of the *CL driver. Same as in recv.asm
  4. .equ COM_DRV_ADDR 0x0238
  5. ; in sync with user.h. Last BAS_RAMEND: 0x600b
  6. .equ USER_CODE 0x6100
  7. ; Free memory in TRSDOS starts at 0x3000
  8. .org 0x3000
  9. jp init
  10. ; *** Jump Table ***
  11. jp strncmp
  12. jp upcase
  13. jp findchar
  14. jp printstr
  15. jp printcrlf
  16. jp blkSet
  17. jp blkSel
  18. jp _blkGetB
  19. jp _blkPutB
  20. jp _blkSeek
  21. jp _blkTell
  22. jp fsFindFN
  23. jp fsOpen
  24. jp fsGetB
  25. jp fsPutB
  26. jp fsSetSize
  27. jp stdioPutC
  28. jp stdioReadLine
  29. .inc "err.h"
  30. .inc "blkdev.h"
  31. .inc "fs.h"
  32. .inc "ascii.h"
  33. .inc "core.asm"
  34. .inc "str.asm"
  35. .inc "trs80/kbd.asm"
  36. .inc "trs80/vid.asm"
  37. .equ FLOPPY_RAMSTART RAMSTART
  38. .inc "trs80/floppy.asm"
  39. .equ GRID_RAMSTART FLOPPY_RAMEND
  40. .equ GRID_ROWS TRS80_ROWS
  41. .equ GRID_COLS TRS80_COLS
  42. .equ GRID_SETCELL trs80SetCell
  43. .equ GRID_GETC trs80GetC
  44. .equ gridPushScr fastPushScr
  45. .inc "grid.asm"
  46. .equ BLOCKDEV_RAMSTART GRID_RAMEND
  47. .equ BLOCKDEV_COUNT 3
  48. .inc "blockdev.asm"
  49. ; List of devices
  50. .dw floppyGetB, floppyPutB
  51. .dw blk1GetB, blk1PutB
  52. .dw blk2GetB, blk2PutB
  53. .equ STDIO_RAMSTART BLOCKDEV_RAMEND
  54. .equ STDIO_GETC gridGetC
  55. .equ STDIO_PUTC gridPutC
  56. .equ STDIO_SETCUR gridSetCurH
  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. .inc "basic/floppy.asm"
  82. .equ BAS_RAMSTART BFS_RAMEND
  83. .inc "basic/main.asm"
  84. .out BAS_RAMEND
  85. init:
  86. ld sp, RAMEND
  87. call gridInit
  88. call floppyInit
  89. call fsInit
  90. call basInit
  91. ld hl, basFindCmdExtra
  92. ld (BAS_FINDHOOK), hl
  93. xor a
  94. ld de, BLOCKDEV_SEL
  95. call blkSel
  96. jp basStart
  97. ; Receive a byte from *cl and put it in A.
  98. ; Returns A > 0xff when receiving the last byte
  99. recvCmd:
  100. xor a
  101. ld (VAR_TBL+1), a ; pre-set MSB
  102. ; put a 0xff mask in B, which will become 0x7f if we receive a 0x20
  103. ld b, 0xff
  104. .inner:
  105. ld a, 0x03 ; @GET
  106. ld de, COM_DRV_ADDR
  107. rst 0x28
  108. jr nz, .maybeerror
  109. or a
  110. jr z, .eof ; Sending a straight NULL ends the comm.
  111. ; @PUT that char back
  112. ld c, a
  113. ld a, 0x04 ; @PUT
  114. ld de, COM_DRV_ADDR
  115. rst 0x28
  116. ret nz ; error
  117. ld a, c
  118. cp 0x20
  119. jr z, .escapechar
  120. ; not an escape char, good
  121. and b ; apply mask
  122. ld (VAR_TBL), a
  123. xor a ; ensure Z
  124. ret
  125. .maybeerror:
  126. ; was it an error?
  127. or a
  128. jr z, .inner ; not an error, just loop
  129. ret ; error
  130. .escapechar:
  131. ld b, 0x7f
  132. jr .inner
  133. .eof:
  134. dec a ; A = 0xff
  135. ld (VAR_TBL+1), a
  136. xor a ; ensure Z
  137. ret
  138. basFindCmdExtra:
  139. ld hl, basFloppyCmds
  140. call basFindCmd
  141. ret z
  142. ld hl, basBLKCmds
  143. call basFindCmd
  144. ret z
  145. ld hl, basFSCmds
  146. call basFindCmd
  147. ret z
  148. ld hl, .cmds
  149. call basFindCmd
  150. ret z
  151. jp basPgmHook
  152. .cmds:
  153. .db "recv", 0
  154. .dw recvCmd
  155. .db 0xff ; end of table
  156. fastPushScr:
  157. push hl
  158. ld hl, GRID_BUF
  159. call trs80PushScr
  160. pop hl
  161. ret
  162. ; *** blkdev 1: file handle 0 ***
  163. blk1GetB:
  164. ld ix, FS_HANDLES
  165. jp fsGetB
  166. blk1PutB:
  167. ld ix, FS_HANDLES
  168. jp fsPutB
  169. ; *** blkdev 2: file handle 1 ***
  170. blk2GetB:
  171. ld ix, FS_HANDLES+FS_HANDLE_SIZE
  172. jp fsGetB
  173. blk2PutB:
  174. ld ix, FS_HANDLES+FS_HANDLE_SIZE
  175. jp fsPutB
  176. RAMSTART: