2019-04-16 22:36:26 +10:00
|
|
|
; mmap
|
|
|
|
;
|
|
|
|
; Block device that maps to memory.
|
|
|
|
;
|
|
|
|
; *** DEFINES ***
|
|
|
|
; MMAP_START: Memory address where the mmap begins
|
2019-07-24 13:00:32 +10:00
|
|
|
; Memory address where the mmap stops, exclusively (we aren't allowed to access
|
|
|
|
; that address).
|
|
|
|
.equ MMAP_LEN 0xffff-MMAP_START
|
2019-04-16 22:36:26 +10:00
|
|
|
|
2019-07-24 13:00:32 +10:00
|
|
|
; Returns absolute addr of memory pointer in HL if HL is within bounds.
|
|
|
|
; Sets Z on success, unset when out of bounds.
|
2019-04-16 22:36:26 +10:00
|
|
|
_mmapAddr:
|
|
|
|
push de
|
2019-07-24 13:00:32 +10:00
|
|
|
ld de, MMAP_LEN
|
|
|
|
call cpHLDE
|
|
|
|
jr nc, .outOfBounds ; HL >= DE
|
2019-04-16 22:36:26 +10:00
|
|
|
ld de, MMAP_START
|
|
|
|
add hl, de
|
2019-07-24 13:00:32 +10:00
|
|
|
cp a ; ensure Z
|
2019-04-16 22:36:26 +10:00
|
|
|
pop de
|
|
|
|
ret
|
2019-07-24 13:00:32 +10:00
|
|
|
.outOfBounds:
|
|
|
|
pop de
|
|
|
|
jp unsetZ
|
2019-04-16 22:36:26 +10:00
|
|
|
|
|
|
|
mmapGetC:
|
|
|
|
push hl
|
|
|
|
call _mmapAddr
|
2019-07-24 13:00:32 +10:00
|
|
|
jr nz, .end
|
2019-04-16 22:36:26 +10:00
|
|
|
ld a, (hl)
|
2019-07-24 13:00:32 +10:00
|
|
|
; Z already set
|
|
|
|
.end:
|
2019-04-16 22:36:26 +10:00
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2019-07-24 13:00:32 +10:00
|
|
|
|
2019-04-16 22:36:26 +10:00
|
|
|
mmapPutC:
|
|
|
|
push hl
|
|
|
|
call _mmapAddr
|
2019-07-24 13:00:32 +10:00
|
|
|
jr nz, .end
|
2019-04-16 22:36:26 +10:00
|
|
|
ld (hl), a
|
2019-07-24 13:00:32 +10:00
|
|
|
; Z already set
|
|
|
|
.end:
|
2019-04-16 22:36:26 +10:00
|
|
|
pop hl
|
|
|
|
ret
|