From b258ed441ac28f60afed0e287654a91b3b0c5607 Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Sat, 2 Sep 2023 11:30:15 -0700 Subject: [PATCH 1/4] decompress faster --- Platform/Apple/virtual/src/core/decomp.s | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Platform/Apple/virtual/src/core/decomp.s b/Platform/Apple/virtual/src/core/decomp.s index a83ef764..468c15fb 100644 --- a/Platform/Apple/virtual/src/core/decomp.s +++ b/Platform/Apple/virtual/src/core/decomp.s @@ -33,8 +33,9 @@ DEBUG = 0 decomp !zone { jsr .chkdst ldy #0 ; In lit loop Y must be zero + sec .fill1A jsr .getbt2 - jmp .fill1B + bne .fill1B ; always taken .incdst inc pDst+1 .chkdst ldx pDst+1 @@ -174,19 +175,19 @@ decomp !zone { bne .gshift ; always taken ; Get another 8 bits into our bit buffer. Destroys X. Preserves A. Requires Y=0. +; Carry is always set on entry, Z always clear on exit ; Alternately, use .getbt2 to preserve X and destroy A .getbts tax .getbt2 lda (pSrc),y - inc pSrc - beq .src3A -.src3B sec rol sta bits txa + inc pSrc + beq .src3A rts .src3A inc pSrc+1 - bne .src3B ; always taken + rts } ; end of zone From 3f359cf3ffc987048b3236303340582b30856ddd Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Sun, 3 Sep 2023 14:41:10 -0700 Subject: [PATCH 2/4] fix a couple of bugs, compare a bit faster --- .../Apple/virtual/src/plasma/gameloop.pla | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/Platform/Apple/virtual/src/plasma/gameloop.pla b/Platform/Apple/virtual/src/plasma/gameloop.pla index d4860ecc..5330a517 100644 --- a/Platform/Apple/virtual/src/plasma/gameloop.pla +++ b/Platform/Apple/virtual/src/plasma/gameloop.pla @@ -363,7 +363,7 @@ export asm memcpy(pSrc, pDst, len, auxWr)#0 inc pTmp+1 bne .pglup ; always taken .part: - cpx #0 + txa beq .done - lda (tmp),y sta (pTmp),y @@ -419,10 +419,10 @@ export asm readAuxByte(ptr)#1 sta $10-1,y dey bne - - jmp $10 -.rdauxb sei ; prevent interrupts while in aux mem sta setAuxRd + jmp $10 +.rdauxb lda (pTmp),y sta clrAuxRd cli @@ -461,19 +461,19 @@ end export asm finishString(isPlural)#1 !zone { +asmPlasmRet 1 + ldy prevCSWL+ABS_OFFSET ; put the cout vector back to default + sty cswl + ldy prevCSWL+1+ABS_OFFSET ; put the cout vector back to default + sty cswh + ldy #0 ; dest offset in Y (will be incremented before store) + cpy inbuf + beq .done1 ; failsafe: handle zero-length string tax ; test for isPlural == 0 beq + lda #$40 ; for setting V later + sta tmp ; save isPlural flag - lda prevCSWL+ABS_OFFSET ; put the cout vector back to default - sta cswl - lda prevCSWL+1+ABS_OFFSET ; put the cout vector back to default - sta cswh clv ; V flag for prev-is-alpha - ldy #0 ; dest offset in Y (will be incremented before store) ldx #0 ; source offset in X (will be incremented before load) - cpx inbuf - beq .done ; failsafe: handle zero-length string .fetch inx lda inbuf,x ; get next input char @@ -487,7 +487,7 @@ export asm finishString(isPlural)#1 dey ; undo copy of the paren stx tmp+1 ; save position in input - dex ; needed for failsafe operation + bcs .done ; failsafe: handle missing end-paren bit tmp ; set copy flag (V) initially to same as isPlural flag .findsl ; see if there's a slash within the parens inx @@ -502,11 +502,8 @@ export asm finishString(isPlural)#1 pha plp + cmp #")" ; scan until ending paren - beq + - cpx inbuf - bcc .findsl ; loop to scan next char - bcs .done ; failsafe: handle missing end-paren (always taken) -+ ldx tmp+1 ; get back to start of parens + bne .findsl ; loop to scan next char + ldx tmp+1 ; get back to start of parens ; copy mode flag is now in V: if slash present, single=copy, plural=nocopy ; if no slash: single=nocopy, plural=copy .plup @@ -540,6 +537,7 @@ export asm finishString(isPlural)#1 .done sty inbuf ; save new length +.done1 lda #inbuf rts @@ -574,8 +572,8 @@ export asm blit(isAux, srcData, dstScreenPtr, nLines, lineSize)#0 lsr ; to carry bit bcc + ldy #15 ; put aux copy routine in zero page -- lda .cpaux + ABS_OFFSET,y - sta $10,y +- ldx .cpaux + ABS_OFFSET,y + stx $10,y dey bpl - + pla ; get line count @@ -693,8 +691,9 @@ export asm puts(str)#0 sta pTmp lda #'!' ldx #1 - sty pTmp+1 + tya beq + ; safety: print '!' instead of null string + sty pTmp+1 ldy #0 lda (pTmp),y tax @@ -912,9 +911,8 @@ export asm rawDisplayStr(pStr)#0 lda (pTmp),y sta tmp - cpy tmp - bcc + - rts -+ iny + bcs ++ + iny lda (pTmp),y ora #$80 cmp #"^" @@ -928,7 +926,8 @@ export asm rawDisplayStr(pStr)#0 + sty tmp+1 jsr DisplayChar ldy tmp+1 - bne - + bne - ; always taken +++rts end /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1006,18 +1005,17 @@ export asm streqi(a, b)#1 cmp #('z'&$7F)+1 ; convert to upper case bcs + cmp #'a'&$7F - bcc + + bcc ++ sbc #$20 -+ sta ysav - lda (pTmp),y - cmp #('z'&$7F)+1 ; convert to upper case - bcs + - cmp #'a'&$7F - bcc + - sbc #$20 -+ cmp ysav - bne .noteqi ; abort on inequality - dex + !byte $C9 ; CMP imm - to skip next opcode ++ clc ; clear carry if not alpha + ; CMP will set carry +++eor (pTmp),y + beq + ; matched + bcc .noteqi ; abort on non-alpha inequality + eor #$20 ; check for case bit + bne .noteqi ; abort on alpha inequality ++ dex bne - lda #1 ldy #0 ; okay, they're equal. Return 1 (not just any char; so that PLASMA when...is can work) From c54052737045df94ea947493949fc24c6e9a6bc7 Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Sun, 3 Sep 2023 14:42:51 -0700 Subject: [PATCH 3/4] another fix --- Platform/Apple/virtual/src/plasma/gameloop.pla | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Platform/Apple/virtual/src/plasma/gameloop.pla b/Platform/Apple/virtual/src/plasma/gameloop.pla index 5330a517..7ab40c1a 100644 --- a/Platform/Apple/virtual/src/plasma/gameloop.pla +++ b/Platform/Apple/virtual/src/plasma/gameloop.pla @@ -389,8 +389,8 @@ export asm memset(pDst, val, len)#0 lda evalStkL,x ; len lo pha lda evalStkH,x ; len hi - tax beq + + tax lda tmp - sta (pTmp),y iny @@ -487,11 +487,11 @@ export asm finishString(isPlural)#1 dey ; undo copy of the paren stx tmp+1 ; save position in input - bcs .done ; failsafe: handle missing end-paren bit tmp ; set copy flag (V) initially to same as isPlural flag .findsl ; see if there's a slash within the parens inx cpx inbuf + bcs .done ; failsafe: handle missing end-paren lda inbuf,x ora #$80 ; normalize hi-bit for comparisons below cmp #"/" @@ -989,8 +989,8 @@ export asm streqi(a, b)#1 lda evalStkL+1,x sta pTmp lda evalStkH+1,x - sta pTmp+1 beq .null + sta pTmp+1 ldy #0 lda (tmp),y cmp (pTmp),y From d4d3c59b8cf813251c30ebe4d4ed042e73b5d8b4 Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Sun, 3 Sep 2023 15:08:16 -0700 Subject: [PATCH 4/4] defer case check to be faster --- Platform/Apple/virtual/src/plasma/gameloop.pla | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Platform/Apple/virtual/src/plasma/gameloop.pla b/Platform/Apple/virtual/src/plasma/gameloop.pla index 7ab40c1a..5860693d 100644 --- a/Platform/Apple/virtual/src/plasma/gameloop.pla +++ b/Platform/Apple/virtual/src/plasma/gameloop.pla @@ -1002,19 +1002,15 @@ export asm streqi(a, b)#1 + tax ; count up to (verified same) length of the strings - iny lda (tmp),y - cmp #('z'&$7F)+1 ; convert to upper case - bcs + - cmp #'a'&$7F - bcc ++ - sbc #$20 - !byte $C9 ; CMP imm - to skip next opcode -+ clc ; clear carry if not alpha - ; CMP will set carry -++eor (pTmp),y + eor (pTmp),y beq + ; matched - bcc .noteqi ; abort on non-alpha inequality - eor #$20 ; check for case bit + cmp #$20 ; check for case bit bne .noteqi ; abort on alpha inequality + ora (tmp),y ; convert to lower case + cmp #('z'&$7F)+1 + bcs .noteqi ; abort on inequality + cmp #'a'&$7F + bcc .noteqi ; abort on inequality + dex bne - lda #1