From ba2c6d9008d931cd2fcf83d4e01fa3f2c2972f7b Mon Sep 17 00:00:00 2001 From: IrgendwerA8 Date: Tue, 22 May 2018 15:59:05 +0200 Subject: [PATCH] Further optimizations in common/conio. --- libsrc/common/ltoa.s | 92 +++++++++++++++++++---------------------- libsrc/common/strcspn.s | 19 ++++----- libsrc/common/strlen.s | 12 +++--- libsrc/common/strspn.s | 19 ++++----- libsrc/conio/scrsize.s | 27 ++++++------ 5 files changed, 81 insertions(+), 88 deletions(-) diff --git a/libsrc/common/ltoa.s b/libsrc/common/ltoa.s index 5dc215bd1..54b693ecc 100644 --- a/libsrc/common/ltoa.s +++ b/libsrc/common/ltoa.s @@ -6,11 +6,11 @@ ; .export _ltoa, _ultoa - .import popax + .import popax, popptr1, negeax .import __hextab, __longminstr .importzp sreg, ptr1, ptr2, ptr3, tmp1 - + .macpack cpu .code @@ -19,17 +19,15 @@ ; dopop: sta tmp1 ; will loose high byte - jsr popax ; get s - sta ptr1 - stx ptr1+1 - sta sreg ; save for return - stx sreg+1 - jsr popax ; get low word of value + jsr popax ; get s to ptr2 sta ptr2 stx ptr2+1 - jsr popax ; get high word of value - sta ptr3 + sta ptr3 ; save for return stx ptr3+1 + jsr popptr1 ; get low word of value to ptr1 + jsr popax ; get high word of value to sreg + sta sreg + stx sreg+1 rts ; @@ -41,20 +39,20 @@ _ltoa: jsr dopop ; pop the arguments ; We must handle $80000000 in a special way, since it is the only negative ; number that has no positive 32-bit counterpart - ldx ptr3+1 ; get high byte + ldx sreg+1 ; get high byte ldy tmp1 ; get radix cpy #10 bne ultoa - lda ptr3 - ora ptr2+1 - ora ptr2 + lda sreg + ora ptr1+1 + ora ptr1 bne L2 cpx #$80 bne L2 ldy #11 L1: lda __longminstr,y ; copy -2147483648 - sta (ptr1),y + sta (ptr2),y dey bpl L1 jmp L10 @@ -65,29 +63,25 @@ L1: lda __longminstr,y ; copy -2147483648 L2: txa ; get high byte bpl ultoa lda #'-' - ldy #0 - sta (ptr1),y ; store sign - inc ptr1 - bne L3 - inc ptr1+1 -L3: lda ptr2 ; negate val - eor #$FF - clc - adc #$01 - sta ptr2 - lda ptr2+1 - eor #$FF - adc #$00 - sta ptr2+1 - lda ptr3 - eor #$FF - adc #$00 - sta ptr3 - lda ptr3+1 - eor #$FF - adc #$00 - sta ptr3+1 +.if (.cpu .bitand CPU_ISET_65SC02) + sta (ptr2) +.else + ldy #0 + sta (ptr2),y ; store sign +.endif + + inc ptr2 + bne L3 + inc ptr2+1 + +L3: lda ptr1 ; negate val + ldx ptr1+1 + + jsr negeax + + sta ptr1 + stx ptr1+1 jmp ultoa ; @@ -105,15 +99,15 @@ ultoa: lda #$00 L5: ldy #32 ; 32 bit lda #0 ; remainder -L6: asl ptr2 - rol ptr2+1 - rol ptr3 - rol ptr3+1 +L6: asl ptr1 + rol ptr1+1 + rol sreg + rol sreg+1 rol a cmp tmp1 bcc L7 sbc tmp1 - inc ptr2 + inc ptr1 L7: dey bne L6 @@ -121,25 +115,25 @@ L7: dey lda __hextab,y ; get hex character pha ; save char value on stack - lda ptr2 - ora ptr2+1 - ora ptr3 - ora ptr3+1 + lda ptr1 + ora ptr1+1 + ora sreg + ora sreg+1 bne L5 ; Get the characters from the stack into the string ldy #0 L9: pla - sta (ptr1),y + sta (ptr2),y beq L10 ; jump if sentinel iny bne L9 ; jump always ; Done! Return the target string -L10: lda sreg - ldx sreg+1 +L10: lda ptr3 + ldx ptr3+1 rts diff --git a/libsrc/common/strcspn.s b/libsrc/common/strcspn.s index c9122dc90..9cf159218 100644 --- a/libsrc/common/strcspn.s +++ b/libsrc/common/strcspn.s @@ -6,40 +6,39 @@ ; .export _strcspn - .import popax, _strlen + .import popptr1, _strlen .importzp ptr1, ptr2, tmp1, tmp2 _strcspn: - jsr _strlen ; get length in a/x and transfer s2 to ptr1 + jsr _strlen ; get length in a/x and transfer s2 to ptr2 ; Note: It does not make sense to ; have more than 255 test chars, so - ; we don't support a high byte here! (ptr1+1 is + ; we don't support a high byte here! (ptr2+1 is ; also unchanged in strlen then (important!)) ; -> the original implementation also ; ignored this case sta tmp1 ; tmp1 = strlen of test chars - jsr popax ; get and save s1 - sta ptr2 ; to ptr2 - stx ptr2+1 + jsr popptr1 ; get and save s1 to ptr1 + ldx #0 ; low counter byte stx tmp2 ; high counter byte loadChar: ldy #0 - lda (ptr2),y ; get next char from s1 + lda (ptr1),y ; get next char from s1 beq leave ; handly byte of s1 advance: - inc ptr2 ; advance string position to test + inc ptr1 ; advance string position to test bne check - inc ptr2+1 + inc ptr1+1 dey ; correct next iny (faster/shorter than bne...) checkNext: iny check: cpy tmp1 ; compare with length of test character string beq endOfTestChars - cmp (ptr1),y ; found matching char? + cmp (ptr2),y ; found matching char? bne checkNext leave: txa ; restore position of finding diff --git a/libsrc/common/strlen.s b/libsrc/common/strlen.s index 1a51edb11..e89039179 100644 --- a/libsrc/common/strlen.s +++ b/libsrc/common/strlen.s @@ -2,26 +2,26 @@ ; Ullrich von Bassewitz, 31.05.1998 ; ; Note: strspn & strcspn call internally this function and rely on -; the usage of only ptr1 here! Keep in mind when appling changes +; the usage of only ptr2 here! Keep in mind when appling changes ; and check the other implementations too! ; ; int strlen (const char* s); ; .export _strlen - .importzp ptr1 + .importzp ptr2 _strlen: - sta ptr1 ; Save s - stx ptr1+1 + sta ptr2 ; Save s + stx ptr2+1 ldx #0 ; YX used as counter ldy #0 -L1: lda (ptr1),y +L1: lda (ptr2),y beq L9 iny bne L1 - inc ptr1+1 + inc ptr2+1 inx bne L1 diff --git a/libsrc/common/strspn.s b/libsrc/common/strspn.s index 079b935ee..6fda716be 100644 --- a/libsrc/common/strspn.s +++ b/libsrc/common/strspn.s @@ -6,40 +6,39 @@ ; .export _strspn - .import popax, _strlen + .import popptr1, _strlen .importzp ptr1, ptr2, tmp1, tmp2 _strspn: - jsr _strlen ; get length in a/x and transfer s2 to ptr1 + jsr _strlen ; get length in a/x and transfer s2 to ptr2 ; Note: It does not make sense to ; have more than 255 test chars, so - ; we don't support a high byte here! (ptr1+1 is + ; we don't support a high byte here! (ptr2+1 is ; also unchanged in strlen then (important!)) ; -> the original implementation also ; ignored this case sta tmp1 ; tmp1 = strlen of test chars - jsr popax ; get and save s1 - sta ptr2 ; to ptr2 - stx ptr2+1 + jsr popptr1 ; get and save s1 to ptr1 + ldx #0 ; low counter byte stx tmp2 ; high counter byte loadChar: ldy #0 - lda (ptr2),y ; get next char from s1 + lda (ptr1),y ; get next char from s1 beq leave ; handly byte of s1 advance: - inc ptr2 ; advance string position to test + inc ptr1 ; advance string position to test bne check - inc ptr2+1 + inc ptr1+1 dey ; correct next iny (faster/shorter than bne...) checkNext: iny check: cpy tmp1 ; compare with length of test character string beq leave - cmp (ptr1),y ; found matching char? + cmp (ptr2),y ; found matching char? bne checkNext foundTestChar: diff --git a/libsrc/conio/scrsize.s b/libsrc/conio/scrsize.s index 6582568d7..014b6f08b 100644 --- a/libsrc/conio/scrsize.s +++ b/libsrc/conio/scrsize.s @@ -6,29 +6,30 @@ .export _screensize - .import popsreg + .import popptr1 .import screensize - .importzp ptr1, sreg + .importzp ptr1, ptr2 + + .macpack cpu .proc _screensize - sta ptr1 ; Store the y pointer - stx ptr1+1 - jsr popsreg ; Get the x pointer into sreg + sta ptr2 ; Store the y pointer + stx ptr2+1 + jsr popptr1 ; Get the x pointer into ptr1 jsr screensize ; Get screensize into X/Y tya ; Get Y size into A -.IFP02 - ldy #0 - sta (ptr1),y +.if (.cpu .bitand ::CPU_ISET_65SC02) + sta (ptr2) txa - sta (sreg),y -.ELSE sta (ptr1) +.else + ldy #0 + sta (ptr2),y txa - sta (sreg) -.ENDIF - + sta (ptr1),y +.endif rts .endproc