1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-17 06:58:05 +11:00

core: remove cpHLDE

It wasn't used much, so I replaced its use in the kernel with direct code
and moved the routine in apps/ed, the only other place where it was used.
This commit is contained in:
Virgil Dupras 2019-12-12 15:53:14 -05:00
parent c002c69208
commit 4f7a05e3b7
7 changed files with 65 additions and 42 deletions

View File

@ -33,6 +33,7 @@
.inc "core.asm" .inc "core.asm"
.inc "lib/util.asm" .inc "lib/util.asm"
.inc "lib/parse.asm" .inc "lib/parse.asm"
.inc "ed/util.asm"
.equ IO_RAMSTART USER_RAMSTART .equ IO_RAMSTART USER_RAMSTART
.inc "ed/io.asm" .inc "ed/io.asm"
.equ BUF_RAMSTART IO_RAMEND .equ BUF_RAMSTART IO_RAMEND

8
apps/ed/util.asm Normal file
View File

@ -0,0 +1,8 @@
; Compare HL with DE and sets Z and C in the same way as a regular cp X where
; HL is A and DE is X.
cpHLDE:
push hl
or a ;reset carry flag
sbc hl, de ;There is no 'sub hl, de', so we must use sbc
pop hl
ret

View File

@ -57,15 +57,6 @@ intoIX:
pop ix pop ix
ret ret
; Compare HL with DE and sets Z and C in the same way as a regular cp X where
; HL is A and DE is X.
cpHLDE:
push hl
or a ;reset carry flag
sbc hl, de ;There is no 'sub hl, de', so we must use sbc
pop hl
ret
; Write the contents of HL in (DE) ; Write the contents of HL in (DE)
; de and hl are preserved, so no pushing/popping necessary ; de and hl are preserved, so no pushing/popping necessary
writeHLinDE: writeHLinDE:

View File

@ -413,17 +413,17 @@ fsPlaceH:
; Sets Z according to whether HL is within bounds for file handle at (IX), that ; Sets Z according to whether HL is within bounds for file handle at (IX), that
; is, if it is smaller than file size. ; is, if it is smaller than file size.
fsWithinBounds: fsWithinBounds:
push de ld a, h
; file size cp (ix+5)
ld e, (ix+4) jr c, .within ; H < (IX+5)
ld d, (ix+5) jp nz, unsetZ ; H > (IX+5)
call cpHLDE ; H == (IX+5)
pop de ld a, l
jr nc, .outOfBounds ; HL >= DE cp (ix+4)
jp nc, unsetZ ; L >= (IX+4)
.within:
cp a ; ensure Z cp a ; ensure Z
ret ret
.outOfBounds:
jp unsetZ ; returns
; Set size of file handle (IX) to value in HL. ; Set size of file handle (IX) to value in HL.
; This writes directly in handle's metadata. ; This writes directly in handle's metadata.

View File

@ -13,8 +13,10 @@
_mmapAddr: _mmapAddr:
push de push de
ld de, MMAP_LEN ld de, MMAP_LEN
call cpHLDE or a ; reset carry flag
sbc hl, de
jr nc, .outOfBounds ; HL >= DE jr nc, .outOfBounds ; HL >= DE
add hl, de ; old HL value
ld de, MMAP_START ld de, MMAP_START
add hl, de add hl, de
cp a ; ensure Z cp a ; ensure Z

View File

@ -5,8 +5,6 @@
jp test jp test
.inc "core.asm"
dummyLabel: dummyLabel:
testNum: .db 1 testNum: .db 1
@ -48,30 +46,11 @@ test:
; test that "@" is updated by a .org directive ; test that "@" is updated by a .org directive
ld hl, AFTER_ORG ld hl, AFTER_ORG
ld de, 0x1234 ld de, 0x1234
call cpHLDE or a ; clear carry
sbc hl, de
jp nz, fail jp nz, fail
call nexttest call nexttest
; *** cpHLDE ***
ld hl, 0x42
ld de, 0x42
call cpHLDE
jp nz, fail
jp c, fail
call nexttest
ld de, 0x4242
call cpHLDE
jp z, fail
jp nc, fail
call nexttest
ld hl, 0x4243
call cpHLDE
jp z, fail
jp c, fail
call nexttest
; success ; success
xor a xor a
halt halt

View File

@ -0,0 +1,42 @@
jp test
.inc "ed/util.asm"
test:
ld sp, 0xffff
; *** cpHLDE ***
ld hl, 0x42
ld de, 0x42
call cpHLDE
jp nz, fail
jp c, fail
call nexttest
ld de, 0x4242
call cpHLDE
jp z, fail
jp nc, fail
call nexttest
ld hl, 0x4243
call cpHLDE
jp z, fail
jp c, fail
call nexttest
; success
xor a
halt
testNum: .db 1
nexttest:
ld a, (testNum)
inc a
ld (testNum), a
ret
fail:
ld a, (testNum)
halt