mirror of
https://github.com/hsoft/collapseos.git
synced 2025-04-13 01:28:16 +10:00
Lots of minor optimisations
Removed an unecessary conditional jump in main.asm, saving 7 cycles and 2 bytes. Removed a function called "subDEfromHL" or something like that, and replaced it with `sbc hl, de`, saving 10 bytes total and 61 cycles. I also rewrote enterParens and strlen to use cpir instead of cpi in a loop, saving 14 cycles per character and also 6 bytes (bc needed to be zeroed in enterParens).
This commit is contained in:
parent
c255903323
commit
6c0052578e
@ -739,12 +739,14 @@ getUpcode:
|
|||||||
push de ; Don't let go of this, that's our dest
|
push de ; Don't let go of this, that's our dest
|
||||||
push hl
|
push hl
|
||||||
call zasmGetPC ; --> HL
|
call zasmGetPC ; --> HL
|
||||||
ex de, hl
|
ex de, hl ; zasmGetPC sets carry on add hl, de
|
||||||
|
; Since it's a PC value, a carry would mean we've overflowed memory.
|
||||||
|
; That means we can safely assume the carry is unset.
|
||||||
pop hl
|
pop hl
|
||||||
call intoHL
|
call intoHL
|
||||||
dec hl ; what we write is "e-2"
|
dec hl ; what we write is "e-2"
|
||||||
dec hl
|
dec hl
|
||||||
call subDEFromHL
|
sbc hl, de ; flags don't need preserving, and carry unset
|
||||||
pop de ; Still have it? good
|
pop de ; Still have it? good
|
||||||
; HL contains our number and we'll check its bounds. If It's negative,
|
; HL contains our number and we'll check its bounds. If It's negative,
|
||||||
; H is going to be 0xff and L has to be >= 0x80. If it's positive,
|
; H is going to be 0xff and L has to be >= 0x80. If it's positive,
|
||||||
|
@ -115,8 +115,7 @@ zasmParseFile:
|
|||||||
ret nz ; error
|
ret nz ; error
|
||||||
ld a, b ; TOK_*
|
ld a, b ; TOK_*
|
||||||
cp TOK_EOF
|
cp TOK_EOF
|
||||||
jr z, .eof
|
jr nz, .loop
|
||||||
jr .loop
|
|
||||||
.eof:
|
.eof:
|
||||||
call zasmIsLocalPass
|
call zasmIsLocalPass
|
||||||
jr nz, .end ; EOF and not local pass
|
jr nz, .end ; EOF and not local pass
|
||||||
|
@ -12,18 +12,6 @@ callHL:
|
|||||||
jp (hl)
|
jp (hl)
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; HL - DE -> HL
|
|
||||||
subDEFromHL:
|
|
||||||
push af
|
|
||||||
ld a, l
|
|
||||||
sub e
|
|
||||||
ld l, a
|
|
||||||
ld a, h
|
|
||||||
sbc a, d
|
|
||||||
ld h, a
|
|
||||||
pop af
|
|
||||||
ret
|
|
||||||
|
|
||||||
; make Z the opposite of what it is now
|
; make Z the opposite of what it is now
|
||||||
toggleZ:
|
toggleZ:
|
||||||
jp z, unsetZ
|
jp z, unsetZ
|
||||||
@ -37,17 +25,13 @@ strlen:
|
|||||||
push hl
|
push hl
|
||||||
ld bc, 0
|
ld bc, 0
|
||||||
ld a, 0 ; look for null char
|
ld a, 0 ; look for null char
|
||||||
.loop:
|
cpir
|
||||||
cpi
|
|
||||||
jp z, .found
|
|
||||||
jr .loop
|
|
||||||
.found:
|
.found:
|
||||||
; How many char do we have? the (NEG BC)-1, which started at 0 and
|
; How many char do we have? the (NEG BC)-1, which started at 0 and
|
||||||
; decreased at each CPI call. In this routine, we stay in the 8-bit
|
; decreased at each CPI call. In this routine, we stay in the 8-bit
|
||||||
; realm, so C only.
|
; realm, so C only.
|
||||||
ld a, c
|
ld a, c
|
||||||
neg
|
cpl ; -a = (~a)+1, so (-a)-1 = ~a
|
||||||
dec a
|
|
||||||
pop hl
|
pop hl
|
||||||
pop bc
|
pop bc
|
||||||
ret
|
ret
|
||||||
@ -132,12 +116,10 @@ enterParens:
|
|||||||
cp '('
|
cp '('
|
||||||
ret nz ; nothing to do
|
ret nz ; nothing to do
|
||||||
push hl
|
push hl
|
||||||
ld a, 0 ; look for null char
|
ld bc, 0 ; so we can use cpir
|
||||||
|
ld a, b ; look for null char
|
||||||
; advance until we get null
|
; advance until we get null
|
||||||
.loop:
|
cpir
|
||||||
cpi
|
|
||||||
jp z, .found
|
|
||||||
jr .loop
|
|
||||||
.found:
|
.found:
|
||||||
dec hl ; cpi over-advances. go back to null-char
|
dec hl ; cpi over-advances. go back to null-char
|
||||||
dec hl ; looking at the last char before null
|
dec hl ; looking at the last char before null
|
||||||
|
Loading…
Reference in New Issue
Block a user