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
|
2019-12-13 07:53:14 +11:00
|
|
|
or a ; reset carry flag
|
|
|
|
sbc hl, de
|
2019-07-24 13:00:32 +10:00
|
|
|
jr nc, .outOfBounds ; HL >= DE
|
2019-12-13 07:53:14 +11:00
|
|
|
add hl, de ; old HL value
|
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
|
|
|
|
2019-10-31 07:59:35 +11:00
|
|
|
mmapGetB:
|
2019-04-16 22:36:26 +10:00
|
|
|
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-10-31 07:59:35 +11:00
|
|
|
mmapPutB:
|
2019-04-16 22:36:26 +10:00
|
|
|
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
|