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.

49 lines
791B

  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. or a ; reset carry flag
  16. sbc hl, de
  17. jr nc, .outOfBounds ; HL >= DE
  18. add hl, de ; old HL value
  19. ld de, MMAP_START
  20. add hl, de
  21. cp a ; ensure Z
  22. pop de
  23. ret
  24. .outOfBounds:
  25. pop de
  26. jp unsetZ
  27. mmapGetB:
  28. push hl
  29. call _mmapAddr
  30. jr nz, .end
  31. ld a, (hl)
  32. ; Z already set
  33. .end:
  34. pop hl
  35. ret
  36. mmapPutB:
  37. push hl
  38. call _mmapAddr
  39. jr nz, .end
  40. ld (hl), a
  41. ; Z already set
  42. .end:
  43. pop hl
  44. ret