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.

163 lines
2.5KB

  1. ; named shell_.asm to avoid infinite include loop.
  2. .equ RAMSTART 0x4000
  3. ; kernel ram is well under 0x100 bytes. We're giving us 0x200 bytes so that we
  4. ; never worry about the stack.
  5. .equ KERNEL_RAMEND 0x4200
  6. .equ USERCODE KERNEL_RAMEND
  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 addDE
  14. jp addHL
  15. jp upcase
  16. jp unsetZ
  17. jp intoDE
  18. jp intoHL
  19. jp writeHLinDE
  20. jp findchar
  21. jp parseHex
  22. jp parseHexPair
  23. jp blkSel
  24. jp blkSet
  25. jp fsFindFN
  26. jp fsOpen
  27. jp fsGetC
  28. jp fsPutC
  29. jp fsSetSize
  30. jp cpHLDE
  31. jp parseArgs
  32. jp printstr
  33. jp _blkGetC
  34. jp _blkPutC
  35. jp _blkSeek
  36. jp _blkTell
  37. jp printcrlf
  38. jp stdioPutC
  39. jp stdioReadLine
  40. .inc "core.asm"
  41. .inc "err.h"
  42. .inc "parse.asm"
  43. .equ BLOCKDEV_RAMSTART RAMSTART
  44. .equ BLOCKDEV_COUNT 4
  45. .inc "blockdev.asm"
  46. ; List of devices
  47. .dw fsdevGetC, fsdevPutC
  48. .dw stdoutGetC, stdoutPutC
  49. .dw stdinGetC, stdinPutC
  50. .dw mmapGetC, mmapPutC
  51. .equ MMAP_START 0xe000
  52. .inc "mmap.asm"
  53. .equ STDIO_RAMSTART BLOCKDEV_RAMEND
  54. .inc "stdio.asm"
  55. .equ FS_RAMSTART STDIO_RAMEND
  56. .equ FS_HANDLE_COUNT 2
  57. .inc "fs.asm"
  58. .equ SHELL_RAMSTART FS_RAMEND
  59. .equ SHELL_EXTRA_CMD_COUNT 9
  60. .inc "shell.asm"
  61. .dw blkBselCmd, blkSeekCmd, blkLoadCmd, blkSaveCmd
  62. .dw fsOnCmd, flsCmd, fnewCmd, fdelCmd, fopnCmd
  63. .inc "blockdev_cmds.asm"
  64. .inc "fs_cmds.asm"
  65. .equ PGM_RAMSTART SHELL_RAMEND
  66. .equ PGM_CODEADDR USERCODE
  67. .inc "pgm.asm"
  68. ;.out PGM_RAMEND
  69. init:
  70. di
  71. ; setup stack
  72. ld hl, KERNEL_RAMEND
  73. ld sp, hl
  74. ld hl, emulGetC
  75. ld de, emulPutC
  76. call stdioInit
  77. call fsInit
  78. ld a, 0 ; select fsdev
  79. ld de, BLOCKDEV_SEL
  80. call blkSel
  81. call fsOn
  82. call shellInit
  83. ld hl, pgmShellHook
  84. ld (SHELL_CMDHOOK), hl
  85. jp shellLoop
  86. emulGetC:
  87. ; Blocks until a char is returned
  88. in a, (STDIO_PORT)
  89. cp a ; ensure Z
  90. ret
  91. emulPutC:
  92. out (STDIO_PORT), a
  93. ret
  94. fsdevGetC:
  95. ld a, e
  96. out (FS_ADDR_PORT), a
  97. ld a, h
  98. out (FS_ADDR_PORT), a
  99. ld a, l
  100. out (FS_ADDR_PORT), a
  101. in a, (FS_ADDR_PORT)
  102. or a
  103. ret nz
  104. in a, (FS_DATA_PORT)
  105. cp a ; ensure Z
  106. ret
  107. fsdevPutC:
  108. push af
  109. ld a, e
  110. out (FS_ADDR_PORT), a
  111. ld a, h
  112. out (FS_ADDR_PORT), a
  113. ld a, l
  114. out (FS_ADDR_PORT), a
  115. in a, (FS_ADDR_PORT)
  116. cp 2 ; only A > 1 means error
  117. jr nc, .error ; A >= 2
  118. pop af
  119. out (FS_DATA_PORT), a
  120. cp a ; ensure Z
  121. ret
  122. .error:
  123. pop af
  124. jp unsetZ ; returns
  125. .equ STDOUT_HANDLE FS_HANDLES
  126. stdoutGetC:
  127. ld ix, STDOUT_HANDLE
  128. jp fsGetC
  129. stdoutPutC:
  130. ld ix, STDOUT_HANDLE
  131. jp fsPutC
  132. .equ STDIN_HANDLE FS_HANDLES+FS_HANDLE_SIZE
  133. stdinGetC:
  134. ld ix, STDIN_HANDLE
  135. jp fsGetC
  136. stdinPutC:
  137. ld ix, STDIN_HANDLE
  138. jp fsPutC