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.

131 lines
2.0KB

  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. .inc "err.h"
  10. .inc "ascii.h"
  11. .inc "blkdev.h"
  12. .inc "fs.h"
  13. jp init ; 3 bytes
  14. ; *** JUMP TABLE ***
  15. jp strncmp
  16. jp upcase
  17. jp findchar
  18. jp blkSel
  19. jp blkSet
  20. jp fsFindFN
  21. jp fsOpen
  22. jp fsGetB
  23. jp _blkGetB
  24. jp _blkPutB
  25. jp _blkSeek
  26. jp _blkTell
  27. jp printstr
  28. .inc "core.asm"
  29. .inc "str.asm"
  30. .equ BLOCKDEV_RAMSTART RAMSTART
  31. .equ BLOCKDEV_COUNT 3
  32. .inc "blockdev.asm"
  33. ; List of devices
  34. .dw emulGetB, unsetZ
  35. .dw unsetZ, emulPutB
  36. .dw fsdevGetB, fsdevPutB
  37. .equ STDIO_RAMSTART BLOCKDEV_RAMEND
  38. .equ STDIO_GETC noop
  39. .equ STDIO_PUTC stderrPutC
  40. .inc "stdio.asm"
  41. .equ FS_RAMSTART STDIO_RAMEND
  42. .equ FS_HANDLE_COUNT 0
  43. .inc "fs.asm"
  44. init:
  45. di
  46. ld hl, 0xffff
  47. ld sp, hl
  48. ld a, 2 ; select fsdev
  49. ld de, BLOCKDEV_SEL
  50. call blkSel
  51. call fsOn
  52. ; There's a special understanding between zasm.c and this unit: The
  53. ; addresses 0xff00 and 0xff01 contain the two ascii chars to send to
  54. ; zasm as the 3rd argument.
  55. ld a, (0xff00)
  56. ld (.zasmArgs+4), a
  57. ld a, (0xff01)
  58. ld (.zasmArgs+5), a
  59. ld hl, .zasmArgs
  60. call USER_CODE
  61. ; signal the emulator we're done
  62. halt
  63. .zasmArgs:
  64. .db "0 1 XX", 0
  65. ; *** I/O ***
  66. emulGetB:
  67. ; the STDIN_SEEK port works by poking it twice. First poke is for high
  68. ; byte, second poke is for low one.
  69. ld a, h
  70. out (STDIN_SEEK), a
  71. ld a, l
  72. out (STDIN_SEEK), a
  73. in a, (STDIO_PORT)
  74. or a ; cp 0
  75. jr z, .eof
  76. cp a ; ensure z
  77. ret
  78. .eof:
  79. jp unsetZ
  80. emulPutB:
  81. out (STDIO_PORT), a
  82. cp a ; ensure Z
  83. ret
  84. stderrPutC:
  85. out (STDERR_PORT), a
  86. cp a ; ensure Z
  87. ret
  88. fsdevGetB:
  89. ld a, e
  90. out (FS_SEEK_PORT), a
  91. ld a, h
  92. out (FS_SEEK_PORT), a
  93. ld a, l
  94. out (FS_SEEK_PORT), a
  95. in a, (FS_SEEK_PORT)
  96. or a
  97. ret nz
  98. in a, (FS_DATA_PORT)
  99. cp a ; ensure Z
  100. ret
  101. fsdevPutB:
  102. push af
  103. ld a, e
  104. out (FS_SEEK_PORT), a
  105. ld a, h
  106. out (FS_SEEK_PORT), a
  107. ld a, l
  108. out (FS_SEEK_PORT), a
  109. in a, (FS_SEEK_PORT)
  110. or a
  111. jr nz, .error
  112. pop af
  113. out (FS_DATA_PORT), a
  114. cp a ; ensure Z
  115. ret
  116. .error:
  117. pop af
  118. jp unsetZ ; returns