1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-12-24 14:28:06 +11:00

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 ***
; 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:
push de
ld de, MMAP_LEN
call cpHLDE
jr nc, .outOfBounds ; HL >= DE
ld de, MMAP_START
add hl, de
jr nc, .end
; we have carry? out of bounds, set to maximum
ld hl, 0xffff
.end:
cp a ; ensure Z
pop de
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:
push hl
call _mmapAddr
jr nz, .end
ld a, (hl)
cp a ; ensure Z
; Z already set
.end:
pop hl
ret
mmapPutC:
push hl
call _mmapAddr
jr nz, .end
ld (hl), a
cp a ; ensure Z
; Z already set
.end:
pop hl
ret