Browse Source

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.
pull/85/head
Virgil Dupras 4 years ago
parent
commit
4f7a05e3b7
7 changed files with 65 additions and 42 deletions
  1. +1
    -0
      apps/ed/glue.asm
  2. +8
    -0
      apps/ed/util.asm
  3. +0
    -9
      kernel/core.asm
  4. +9
    -9
      kernel/fs.asm
  5. +3
    -1
      kernel/mmap.asm
  6. +2
    -23
      tools/tests/unit/test_core.asm
  7. +42
    -0
      tools/tests/unit/test_ed_util.asm

+ 1
- 0
apps/ed/glue.asm 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
- 0
apps/ed/util.asm 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

+ 0
- 9
kernel/core.asm 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:


+ 9
- 9
kernel/fs.asm 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
; file size
ld e, (ix+4)
ld d, (ix+5)
call cpHLDE
pop de
jr nc, .outOfBounds ; HL >= DE
ld a, h
cp (ix+5)
jr c, .within ; H < (IX+5)
jp nz, unsetZ ; H > (IX+5)
; H == (IX+5)
ld a, l
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.


+ 3
- 1
kernel/mmap.asm 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


+ 2
- 23
tools/tests/unit/test_core.asm View File

@@ -5,8 +5,6 @@


jp test jp test


.inc "core.asm"

dummyLabel: dummyLabel:
testNum: .db 1 testNum: .db 1


@@ -48,28 +46,9 @@ 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
jp nz, fail
call nexttest

; *** cpHLDE ***
ld hl, 0x42
ld de, 0x42
call cpHLDE
or a ; clear carry
sbc hl, de
jp nz, fail 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 call nexttest


; success ; success


+ 42
- 0
tools/tests/unit/test_ed_util.asm 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

Loading…
Cancel
Save