From e94e05c3fae3ce6d6c652f707c0ad782d8288fc0 Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Wed, 3 Aug 2016 15:00:53 -0700 Subject: [PATCH 1/7] minor size optimisation --- src/libsrc/dgr.pla | 38 ++++++++++++++++---------------------- src/libsrc/fiber.pla | 5 +---- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/libsrc/dgr.pla b/src/libsrc/dgr.pla index 64086e7..e1b2dd9 100755 --- a/src/libsrc/dgr.pla +++ b/src/libsrc/dgr.pla @@ -112,21 +112,19 @@ export asm dgrHLin(buff, x1, x2, y) STA GBASH LDA ESTKL+2,X ; X1 COORD LSR ESTKL,X - PHP -- PLP - PHP +- PHP SEI LDX GCLR ; COLOR end asm _dgrHLinPix JSR $3000 + PLP LDX ESP INC ESTKL+2,X ; X1 COORD LDA ESTKL+2,X CMP ESTKL+1,X ; X2 COORD BCC - BEQ - - PLP INX INX INX @@ -186,7 +184,6 @@ export asm dgrBLT(buff, x, y, width, height, src) LDA ESTKL+4,X ; X1 COORD CMP #80 BPL ++++ - CLC ADC ESTKL+2,X BMI ++++ STA ESTKH+2,X ; X2 COORD @@ -194,7 +191,6 @@ export asm dgrBLT(buff, x, y, width, height, src) CMP #48 BPL ++++ STA ESTKH+3,X ; Y COORD - CLC ADC ESTKL+1,X BMI ++++ STA ESTKH+1,X ; Y2 COORD @@ -340,7 +336,6 @@ export asm dgrTile(buff, x, y, src) LDA ESTKL+2,X ; X1 COORD CMP #80 BPL ++++ - CLC ADC #$08 BMI ++++ STA ESTKH+2,X ; X2 COORD @@ -348,7 +343,6 @@ export asm dgrTile(buff, x, y, src) CMP #48 BPL ++++ STA TMPL ; Y COORD - CLC ADC #$08 BMI ++++ STA ESTKH+1,X ; Y2 COORD @@ -376,22 +370,23 @@ export asm dgrTile(buff, x, y, src) -- LSR TAY CMP #40 - LDX #$00 - LDA (SRC,X) - INC SRCL + LDX #$01 +- LDA (SRC,X) + PHA + DEX + BPL - + LDX #$01 +- INC SRCL BNE + INC SRCH -+ BCS + - STA $C005 ; WRITE AUX MEM ++ PLA + BCS + + STA $C004,X ; WRITE AUX or MAIN MEM, depending on pass STA (GBASE),Y STA $C004 ; WRITE MAIN MEM -+ LDA (SRC,X) - INC SRCL - BNE + - INC SRCH -+ BCS ++ - STA (GBASE),Y -++ INC TMPH ; X COORD ++ DEX + BPL - + INC TMPH ; X COORD INC TMPH ; X COORD LDX ESP LDA TMPH @@ -496,8 +491,7 @@ asm _dgrFillTile LDA ESTKH+3,X ; RESTORE X COORD STA ESTKL+3,X LDA ESTKL+2,X ; UPDATE Y COORD - CLC - ADC #$08 + ADC #$07 STA ESTKL+2,X CMP #48 ; OFF BOTTOM? BMI - diff --git a/src/libsrc/fiber.pla b/src/libsrc/fiber.pla index e137931..e84a663 100644 --- a/src/libsrc/fiber.pla +++ b/src/libsrc/fiber.pla @@ -69,10 +69,7 @@ asm fbrSwap(saveVM, restoreVM) LDY HWSP - LDA $100,Y STA (DST),Y - INY - BNE - - LDY HWSP -- LDA (SRC),Y + LDA (SRC),Y STA $100,Y INY BNE - From d8c08bcecf0beee245c9f180d71c56fb15ffa93b Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Wed, 3 Aug 2016 16:19:08 -0700 Subject: [PATCH 2/7] minor size optimisation --- src/libsrc/dgr.pla | 62 ++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/src/libsrc/dgr.pla b/src/libsrc/dgr.pla index e1b2dd9..bcec37e 100755 --- a/src/libsrc/dgr.pla +++ b/src/libsrc/dgr.pla @@ -263,53 +263,49 @@ asm _dgrSetPix BCS + end asm _dgrSetEvnEvn + SEC + !byte $90 ; mask CLC +asm _dgrSetOddEvn + CLC ; EVEN PIXEL - LDA $2000,X - AND #$0F +- JSR $0100 ; LDA AUX (DST),Y STA TMP - JSR $0100 ; LDA AUX (DST),Y - AND #$F0 + LDA #$FF + ADC #$00 + EOR #$F0 ; #$F0 if even, #$0F if odd + PHA + AND TMP + STA TMP + PLA + EOR #$FF ; #$0F if even, #$F0 if odd + AND $2000,X ORA TMP STA $C005 ; WRITE AUX MEM STA (GBASE),Y STA $C004 ; WRITE MAIN MEM RTS end -asm _dgrSetEvnOdd - ; ODD PIXEL -+ LDA $1000,X - AND #$0F - STA TMP - LDA (GBASE),Y - AND #$F0 - ORA TMP - STA (GBASE),Y - RTS + ; ODD ROW ++ LSR TAY - BCS +++ -end -asm _dgrSetOddEvn - ; EVEN PIXEL - LDA $2000,X - AND #$F0 - STA TMP - JSR $0100 ; LDA AUX (DST),Y - AND #$0F - ORA TMP - STA $C005 ; WRITE AUX MEM - STA (GBASE),Y - STA $C004 ; WRITE MAIN MEM - RTS -end + BCC - + asm _dgrSetOddOdd + CLC + !byte $B0 ; mask SEC +asm _dgrSetEvnOdd + SEC ; ODD PIXEL -+++ LDA $1000,X - AND #$F0 ++ LDA #$FF + ADC #$00 + EOR #$0F ; #$F0 if odd, #$0F if even + PHA + AND $1000,X STA TMP - LDA (GBASE),Y - AND #$0F + PLA + EOR #$FF ; #$0F if odd, #$F0 if even + AND (GBASE),Y ORA TMP STA (GBASE),Y RTS From 17e74aa6d06fa94d3c146b7400e22929caa585f1 Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Thu, 4 Aug 2016 10:39:50 -0700 Subject: [PATCH 3/7] correct vblank detection incomplete for IIc --- src/libsrc/dgr.pla | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libsrc/dgr.pla b/src/libsrc/dgr.pla index bcec37e..a5abf30 100755 --- a/src/libsrc/dgr.pla +++ b/src/libsrc/dgr.pla @@ -503,10 +503,10 @@ end asm vlbWait DEX - LDA $C019 - BMI - + BPL - ; wait for current one to end - LDA $C019 - BPL - - RTS + BMI - ; wait for next one to start + RTS ; yes, the flag is saying !vblank end // // Set double lores graphics, return draw buffer From 655fa8df4a0931831245166cf8a287c4808f1e6c Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Fri, 5 Aug 2016 09:12:03 -0700 Subject: [PATCH 4/7] make compiler happy --- src/libsrc/dgr.pla | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libsrc/dgr.pla b/src/libsrc/dgr.pla index a5abf30..04c3657 100755 --- a/src/libsrc/dgr.pla +++ b/src/libsrc/dgr.pla @@ -265,6 +265,7 @@ end asm _dgrSetEvnEvn SEC !byte $90 ; mask CLC +end asm _dgrSetOddEvn CLC ; EVEN PIXEL @@ -284,16 +285,17 @@ asm _dgrSetOddEvn STA (GBASE),Y STA $C004 ; WRITE MAIN MEM RTS -end ; ODD ROW ++ LSR TAY BCC - +end asm _dgrSetOddOdd CLC !byte $B0 ; mask SEC +end asm _dgrSetEvnOdd SEC ; ODD PIXEL From f99ea46957f6e2b0ca2198cd14b715e88ac936b9 Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Fri, 5 Aug 2016 10:48:49 -0700 Subject: [PATCH 5/7] must use cached pointer after all --- src/libsrc/fiber.pla | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libsrc/fiber.pla b/src/libsrc/fiber.pla index e84a663..ee95f7a 100644 --- a/src/libsrc/fiber.pla +++ b/src/libsrc/fiber.pla @@ -66,7 +66,8 @@ asm fbrSwap(saveVM, restoreVM) STA ESTK,Y DEY BPL - - LDY HWSP + TXA + TAY - LDA $100,Y STA (DST),Y LDA (SRC),Y From 9435425246467a85eb10f59e08e566cb73d5373c Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Fri, 5 Aug 2016 11:20:38 -0700 Subject: [PATCH 6/7] Revert to working version --- src/libsrc/fiber.pla | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/libsrc/fiber.pla b/src/libsrc/fiber.pla index ee95f7a..ff57168 100644 --- a/src/libsrc/fiber.pla +++ b/src/libsrc/fiber.pla @@ -46,7 +46,7 @@ byte valstr[] = '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' // asm fbrSwap(saveVM, restoreVM) !SOURCE "vmsrc/plvmzp.inc" - HWSP = IPY + HWSP = IPY LDA ESTKL,X STA SRCL LDA ESTKH,X @@ -66,11 +66,14 @@ asm fbrSwap(saveVM, restoreVM) STA ESTK,Y DEY BPL - - TXA ++ TXA TAY - LDA $100,Y STA (DST),Y - LDA (SRC),Y + INY + BNE - + LDY HWSP +- LDA (SRC),Y STA $100,Y INY BNE - @@ -108,7 +111,7 @@ end export def fbrInit(numPool) byte i word pool - + if numPool >= MAX_FIBERS numPool = MAX_FIBERS fin @@ -144,7 +147,7 @@ end // export def fbrStop(fid) byte i - + // // Don't STOP fiber 0 (avoid deadlock) // @@ -179,7 +182,7 @@ end export def fbrStart(defaddr, param) byte i word vmstate - + for i = fbrMax downto 1 if fbrState[i] == FIBER_FREE // @@ -202,7 +205,7 @@ export def fbrStart(defaddr, param) // This allows a fiber to return and it will fall into fbrExit // vmstate->hwsp = $FB - vmstate=>$FE = @fbrExit - 1 + vmstate=>$FE = @fbrExit - 1 vmstate=>$FC = defaddr - 1 // // Link into RUN list @@ -222,7 +225,7 @@ end // export def fbrYield byte prev - + // // Swap to text fiber if this isn't the only fiber RUNning // @@ -237,7 +240,7 @@ end // export def fbrHalt byte i - + // // Cannot HALT fiber 0 (avoid deadlock) // @@ -284,7 +287,7 @@ end def fbrTest(fid, param) byte i - + for i = 1 to param puth(fid); putc($0D) fbrYield From 1ec6333663c3728ac488234ee37afe26c99f6960 Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Fri, 5 Aug 2016 11:23:52 -0700 Subject: [PATCH 7/7] Revert to working version --- src/libsrc/dgr.pla | 116 ++++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 54 deletions(-) diff --git a/src/libsrc/dgr.pla b/src/libsrc/dgr.pla index 04c3657..94aeb88 100755 --- a/src/libsrc/dgr.pla +++ b/src/libsrc/dgr.pla @@ -112,19 +112,21 @@ export asm dgrHLin(buff, x1, x2, y) STA GBASH LDA ESTKL+2,X ; X1 COORD LSR ESTKL,X -- PHP + PHP +- PLP + PHP SEI LDX GCLR ; COLOR end asm _dgrHLinPix JSR $3000 - PLP LDX ESP INC ESTKL+2,X ; X1 COORD LDA ESTKL+2,X CMP ESTKL+1,X ; X2 COORD BCC - BEQ - + PLP INX INX INX @@ -184,6 +186,7 @@ export asm dgrBLT(buff, x, y, width, height, src) LDA ESTKL+4,X ; X1 COORD CMP #80 BPL ++++ + CLC ADC ESTKL+2,X BMI ++++ STA ESTKH+2,X ; X2 COORD @@ -191,6 +194,7 @@ export asm dgrBLT(buff, x, y, width, height, src) CMP #48 BPL ++++ STA ESTKH+3,X ; Y COORD + CLC ADC ESTKL+1,X BMI ++++ STA ESTKH+1,X ; Y2 COORD @@ -263,51 +267,53 @@ asm _dgrSetPix BCS + end asm _dgrSetEvnEvn - SEC - !byte $90 ; mask CLC -end -asm _dgrSetOddEvn - CLC ; EVEN PIXEL -- JSR $0100 ; LDA AUX (DST),Y + LDA $2000,X + AND #$0F STA TMP - LDA #$FF - ADC #$00 - EOR #$F0 ; #$F0 if even, #$0F if odd - PHA - AND TMP - STA TMP - PLA - EOR #$FF ; #$0F if even, #$F0 if odd - AND $2000,X + JSR $0100 ; LDA AUX (DST),Y + AND #$F0 ORA TMP STA $C005 ; WRITE AUX MEM STA (GBASE),Y STA $C004 ; WRITE MAIN MEM RTS - +end +asm _dgrSetEvnOdd + ; ODD PIXEL ++ LDA $1000,X + AND #$0F + STA TMP + LDA (GBASE),Y + AND #$F0 + ORA TMP + STA (GBASE),Y + RTS ; ODD ROW ++ LSR TAY - BCC - + BCS +++ end - -asm _dgrSetOddOdd - CLC - !byte $B0 ; mask SEC -end -asm _dgrSetEvnOdd - SEC - ; ODD PIXEL -+ LDA #$FF - ADC #$00 - EOR #$0F ; #$F0 if odd, #$0F if even - PHA - AND $1000,X +asm _dgrSetOddEvn + ; EVEN PIXEL + LDA $2000,X + AND #$F0 STA TMP - PLA - EOR #$FF ; #$0F if odd, #$F0 if even - AND (GBASE),Y + JSR $0100 ; LDA AUX (DST),Y + AND #$0F + ORA TMP + STA $C005 ; WRITE AUX MEM + STA (GBASE),Y + STA $C004 ; WRITE MAIN MEM + RTS +end +asm _dgrSetOddOdd + ; ODD PIXEL ++++ LDA $1000,X + AND #$F0 + STA TMP + LDA (GBASE),Y + AND #$0F ORA TMP STA (GBASE),Y RTS @@ -334,6 +340,7 @@ export asm dgrTile(buff, x, y, src) LDA ESTKL+2,X ; X1 COORD CMP #80 BPL ++++ + CLC ADC #$08 BMI ++++ STA ESTKH+2,X ; X2 COORD @@ -341,6 +348,7 @@ export asm dgrTile(buff, x, y, src) CMP #48 BPL ++++ STA TMPL ; Y COORD + CLC ADC #$08 BMI ++++ STA ESTKH+1,X ; Y2 COORD @@ -368,23 +376,22 @@ export asm dgrTile(buff, x, y, src) -- LSR TAY CMP #40 - LDX #$01 -- LDA (SRC,X) - PHA - DEX - BPL - - LDX #$01 -- INC SRCL + LDX #$00 + LDA (SRC,X) + INC SRCL BNE + INC SRCH -+ PLA - BCS + - STA $C004,X ; WRITE AUX or MAIN MEM, depending on pass ++ BCS + + STA $C005 ; WRITE AUX MEM STA (GBASE),Y STA $C004 ; WRITE MAIN MEM -+ DEX - BPL - - INC TMPH ; X COORD ++ LDA (SRC,X) + INC SRCL + BNE + + INC SRCH ++ BCS ++ + STA (GBASE),Y +++ INC TMPH ; X COORD INC TMPH ; X COORD LDX ESP LDA TMPH @@ -489,7 +496,8 @@ asm _dgrFillTile LDA ESTKH+3,X ; RESTORE X COORD STA ESTKL+3,X LDA ESTKL+2,X ; UPDATE Y COORD - ADC #$07 + CLC + ADC #$08 STA ESTKL+2,X CMP #48 ; OFF BOTTOM? BMI - @@ -505,10 +513,10 @@ end asm vlbWait DEX - LDA $C019 - BPL - ; wait for current one to end + BMI - - LDA $C019 - BMI - ; wait for next one to start - RTS ; yes, the flag is saying !vblank + BPL - + RTS end // // Set double lores graphics, return draw buffer @@ -556,7 +564,7 @@ end export def dgrLine(buff, x1, y1, x2, y2) byte dx, dy, dx2, dy2, pp word sx, sy, err, dd2 - + if x1 < x2 sx = 1 dx = x2 - x1 @@ -640,7 +648,7 @@ end // export def dgrClear(buff, clr) byte[32] clrtile - + clr = evnclr[clr&$0F] | (oddclr[clr&$0F] << 8) memset(@clrtile, clr, 32) return dgrFill(buff, 0, 0, @clrtile)