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.

68 lines
955B

  1. ; mmap
  2. ;
  3. ; Block device that maps to memory.
  4. ;
  5. ; *** DEFINES ***
  6. ; MMAP_START: Memory address where the mmap begins
  7. ; *** VARIABLES ***
  8. .equ MMAP_PTR MMAP_RAMSTART
  9. .equ MMAP_RAMEND MMAP_PTR+2
  10. ; *** CODE ***
  11. mmapInit:
  12. xor a
  13. ld (MMAP_PTR), a
  14. ld (MMAP_PTR+1), a
  15. ret
  16. ; Increase mem pointer by one
  17. _mmapForward:
  18. ld hl, (MMAP_PTR)
  19. inc hl
  20. ld (MMAP_PTR), hl
  21. ret
  22. ; Returns absolute addr of memory pointer in HL.
  23. _mmapAddr:
  24. push de
  25. ld hl, (MMAP_PTR)
  26. ld de, MMAP_START
  27. add hl, de
  28. jr nc, .end
  29. ; we have carry? out of bounds, set to maximum
  30. ld hl, 0xffff
  31. .end:
  32. pop de
  33. ret
  34. ; if out of bounds, will continually return the last char
  35. ; TODO: add bounds check and return Z accordingly.
  36. mmapGetC:
  37. push hl
  38. call _mmapAddr
  39. ld a, (hl)
  40. call _mmapForward
  41. cp a ; ensure Z
  42. pop hl
  43. ret
  44. mmapPutC:
  45. push hl
  46. call _mmapAddr
  47. ld (hl), a
  48. call _mmapForward
  49. cp a ; ensure Z
  50. pop hl
  51. ret
  52. mmapSeek:
  53. ld (MMAP_PTR), hl
  54. ret
  55. mmapTell:
  56. ld hl, (MMAP_PTR)
  57. ret