1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-30 22:38:09 +11:00
collapseos/kernel/mmap.asm

49 lines
791 B
NASM
Raw Normal View History

; 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-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.
_mmapAddr:
push de
2019-07-24 13:00:32 +10:00
ld de, MMAP_LEN
or a ; reset carry flag
sbc hl, de
2019-07-24 13:00:32 +10:00
jr nc, .outOfBounds ; HL >= DE
add hl, de ; old HL value
ld de, MMAP_START
add hl, de
2019-07-24 13:00:32 +10:00
cp a ; ensure Z
pop de
ret
2019-07-24 13:00:32 +10:00
.outOfBounds:
pop de
jp unsetZ
mmapGetB:
push hl
call _mmapAddr
2019-07-24 13:00:32 +10:00
jr nz, .end
ld a, (hl)
2019-07-24 13:00:32 +10:00
; Z already set
.end:
pop hl
ret
2019-07-24 13:00:32 +10:00
mmapPutB:
push hl
call _mmapAddr
2019-07-24 13:00:32 +10:00
jr nz, .end
ld (hl), a
2019-07-24 13:00:32 +10:00
; Z already set
.end:
pop hl
ret