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.

133 lines
1.9KB

  1. ; Glue code for the emulated environment
  2. .equ RAMSTART 0x4000
  3. .equ USER_CODE 0x4800
  4. .equ STDIO_PORT 0x00
  5. .equ STDIN_SEEK 0x01
  6. .equ FS_DATA_PORT 0x02
  7. .equ FS_SEEK_PORT 0x03
  8. .equ STDERR_PORT 0x04
  9. jp init ; 3 bytes
  10. ; *** JUMP TABLE ***
  11. jp strncmp
  12. jp addDE
  13. jp addHL
  14. jp upcase
  15. jp unsetZ
  16. jp intoDE
  17. jp intoHL
  18. jp writeHLinDE
  19. jp findchar
  20. jp parseHex
  21. jp parseHexPair
  22. jp blkSel
  23. jp blkSet
  24. jp fsFindFN
  25. jp fsOpen
  26. jp fsGetC
  27. jp cpHLDE
  28. jp parseArgs
  29. jp _blkGetC
  30. jp _blkPutC
  31. jp _blkSeek
  32. jp _blkTell
  33. jp printstr
  34. .inc "core.asm"
  35. .inc "err.h"
  36. .inc "parse.asm"
  37. .equ BLOCKDEV_RAMSTART RAMSTART
  38. .equ BLOCKDEV_COUNT 3
  39. .inc "blockdev.asm"
  40. ; List of devices
  41. .dw emulGetC, unsetZ
  42. .dw unsetZ, emulPutC
  43. .dw fsdevGetC, fsdevPutC
  44. .equ STDIO_RAMSTART BLOCKDEV_RAMEND
  45. .inc "stdio.asm"
  46. .equ FS_RAMSTART STDIO_RAMEND
  47. .equ FS_HANDLE_COUNT 0
  48. .inc "fs.asm"
  49. init:
  50. di
  51. ld hl, 0xffff
  52. ld sp, hl
  53. ld hl, unsetZ
  54. ld de, stderrPutC
  55. call stdioInit
  56. ld a, 2 ; select fsdev
  57. ld de, BLOCKDEV_SEL
  58. call blkSel
  59. call fsOn
  60. ld hl, .zasmArgs
  61. call USER_CODE
  62. ; signal the emulator we're done
  63. halt
  64. .zasmArgs:
  65. .db "0 1", 0
  66. ; *** I/O ***
  67. emulGetC:
  68. ; the STDIN_SEEK port works by poking it twice. First poke is for high
  69. ; byte, second poke is for low one.
  70. ld a, h
  71. out (STDIN_SEEK), a
  72. ld a, l
  73. out (STDIN_SEEK), a
  74. in a, (STDIO_PORT)
  75. or a ; cp 0
  76. jr z, .eof
  77. cp a ; ensure z
  78. ret
  79. .eof:
  80. call unsetZ
  81. ret
  82. emulPutC:
  83. out (STDIO_PORT), a
  84. cp a ; ensure Z
  85. ret
  86. stderrPutC:
  87. out (STDERR_PORT), a
  88. cp a ; ensure Z
  89. ret
  90. fsdevGetC:
  91. ld a, e
  92. out (FS_SEEK_PORT), a
  93. ld a, h
  94. out (FS_SEEK_PORT), a
  95. ld a, l
  96. out (FS_SEEK_PORT), a
  97. in a, (FS_SEEK_PORT)
  98. or a
  99. ret nz
  100. in a, (FS_DATA_PORT)
  101. cp a ; ensure Z
  102. ret
  103. fsdevPutC:
  104. push af
  105. ld a, e
  106. out (FS_SEEK_PORT), a
  107. ld a, h
  108. out (FS_SEEK_PORT), a
  109. ld a, l
  110. out (FS_SEEK_PORT), a
  111. in a, (FS_SEEK_PORT)
  112. or a
  113. jr nz, .error
  114. pop af
  115. out (FS_DATA_PORT), a
  116. cp a ; ensure Z
  117. ret
  118. .error:
  119. pop af
  120. jp unsetZ ; returns