Optimize sign extension to AY

This commit is contained in:
Natt Akuma 2022-02-04 00:59:44 +07:00
parent 69b9dfa468
commit 73dfb5f443
2 changed files with 7 additions and 15 deletions

View File

@ -1707,7 +1707,13 @@ $repeatLabel lda $counterVar
// sign extend signed byte in A to full word in AY
when(valueDt) {
DataType.UBYTE -> out(" ldy #0")
DataType.BYTE -> out(" jsr prog8_lib.sign_extend_AY_byte")
DataType.BYTE -> out("""
ldy #0
cmp #$80
bcc +
dey
+
""")
else -> throw AssemblyError("need byte type")
}
}

View File

@ -1158,20 +1158,6 @@ sign_extend_stack_byte .proc
rts
.pend
sign_extend_AY_byte .proc
; -- sign extend the (signed) byte in AY to full 16 bits
pha
and #$80
beq +
ldy #$ff
pla
rts
+ ldy #0
pla
rts
.pend
strlen .proc
; -- returns the number of bytes in the string in AY, in Y.
sta P8ZP_SCRATCH_W1