mmap: add MMAP_LEN parameter

This commit is contained in:
Virgil Dupras 2019-07-23 23:00:32 -04:00
parent 985d56ca5a
commit 4f6c230dc8

View File

@ -4,33 +4,43 @@
; ;
; *** DEFINES *** ; *** DEFINES ***
; MMAP_START: Memory address where the mmap begins ; MMAP_START: Memory address where the mmap begins
; Memory address where the mmap stops, exclusively (we aren't allowed to access
; that address).
.equ MMAP_LEN 0xffff-MMAP_START
; Returns absolute addr of memory pointer in HL. ; Returns absolute addr of memory pointer in HL if HL is within bounds.
; Sets Z on success, unset when out of bounds.
_mmapAddr: _mmapAddr:
push de push de
ld de, MMAP_LEN
call cpHLDE
jr nc, .outOfBounds ; HL >= DE
ld de, MMAP_START ld de, MMAP_START
add hl, de add hl, de
jr nc, .end cp a ; ensure Z
; we have carry? out of bounds, set to maximum
ld hl, 0xffff
.end:
pop de pop de
ret ret
.outOfBounds:
pop de
jp unsetZ
; if out of bounds, will continually return the last char
; TODO: add bounds check and return Z accordingly.
mmapGetC: mmapGetC:
push hl push hl
call _mmapAddr call _mmapAddr
jr nz, .end
ld a, (hl) ld a, (hl)
cp a ; ensure Z ; Z already set
.end:
pop hl pop hl
ret ret
mmapPutC: mmapPutC:
push hl push hl
call _mmapAddr call _mmapAddr
jr nz, .end
ld (hl), a ld (hl), a
cp a ; ensure Z ; Z already set
.end:
pop hl pop hl
ret ret