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.

47 lines
736B

  1. ; mmap
  2. ;
  3. ; Block device that maps to memory.
  4. ;
  5. ; *** DEFINES ***
  6. ; MMAP_START: Memory address where the mmap begins
  7. ; Memory address where the mmap stops, exclusively (we aren't allowed to access
  8. ; that address).
  9. .equ MMAP_LEN 0xffff-MMAP_START
  10. ; Returns absolute addr of memory pointer in HL if HL is within bounds.
  11. ; Sets Z on success, unset when out of bounds.
  12. _mmapAddr:
  13. push de
  14. ld de, MMAP_LEN
  15. call cpHLDE
  16. jr nc, .outOfBounds ; HL >= DE
  17. ld de, MMAP_START
  18. add hl, de
  19. cp a ; ensure Z
  20. pop de
  21. ret
  22. .outOfBounds:
  23. pop de
  24. jp unsetZ
  25. mmapGetB:
  26. push hl
  27. call _mmapAddr
  28. jr nz, .end
  29. ld a, (hl)
  30. ; Z already set
  31. .end:
  32. pop hl
  33. ret
  34. mmapPutB:
  35. push hl
  36. call _mmapAddr
  37. jr nz, .end
  38. ld (hl), a
  39. ; Z already set
  40. .end:
  41. pop hl
  42. ret