From 46b74e279924809679ba7ceb3a61db3bf7095879 Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Wed, 16 Sep 2015 14:43:34 -0700 Subject: [PATCH] faster, smaller code, and a bugfix conio: faster grcolor, branchless smaller grplot, smaller a3textmode etherip: bugfix: add missing '+' to avoid stack corruption hgr1test: faster smaller draw_scan rod: faster grcolor, branchless smaller grplot a1cmd: faster call, memset, lookuptbl, branchless uword_isge, uword_isle, smaller toupper, lookuptbl cmd: faster memset, prstr, lookuptbl, branchless uword_isge, uword_isle, smaller modtosym, lookuptbl cmdstub: smaller vminit plvm01: smaller vminit plvm02: smaller interp init soscmd: faster memset, lookuptbl, branchless uword_isge, uword_isle, smaller modtosym, lookuptbl --- src/libsrc/conio.pla | 28 +++++++------- src/libsrc/etherip.pla | 2 +- src/samplesrc/hgr1test.pla | 5 +-- src/samplesrc/rod.pla | 25 ++++++------- src/vmsrc/a1cmd.pla | 56 ++++++++++++++-------------- src/vmsrc/cmd.pla | 76 ++++++++++++++++++++------------------ src/vmsrc/cmdstub.s | 9 ++--- src/vmsrc/plvm01.s | 11 +++--- src/vmsrc/plvm02.s | 6 +-- src/vmsrc/soscmd.pla | 48 +++++++++++++----------- 10 files changed, 134 insertions(+), 132 deletions(-) diff --git a/src/libsrc/conio.pla b/src/libsrc/conio.pla index 558040f..f733ea4 100644 --- a/src/libsrc/conio.pla +++ b/src/libsrc/conio.pla @@ -102,12 +102,12 @@ asm grcolor GRCLR = $30 LDA #$0F AND ESTKL,X - STA ESTKL,X + STA GRCLR ASL ASL ASL ASL - ORA ESTKL,X + ORA GRCLR STA GRCLR RTS end @@ -119,23 +119,22 @@ asm grplot LDA ESTKL,X AND #$FE TAY - LDA (GRSCRN),Y + LDA (GRSCRN),Y STA DSTL INY LDA (GRSCRN),Y STA DSTH - LDY ESTKL+1,X - LDA GRCLR + LDA #$FF LSR ESTKL,X - BCS + - AND #$0F + ADC #$00 + EOR #$F0 + TAY + AND GRCLR STA TMPL - LDA #$F0 - BCC ++ -+ AND #$F0 - STA TMPL - LDA #$0F -++ AND (DST),Y + TYA + EOR #$FF + LDY ESTKL+1,X + AND (DST),Y ORA TMPL STA (DST),Y LDY IPY @@ -277,11 +276,10 @@ end def a3texttype(type) end def a3textmode(columns) + puts(@textbwmode) if columns > 40 - puts(@textbwmode) a3viewport(0, 0, 80, 24) else - puts(@textbwmode) a3viewport(0, 0, 40, 24) fin return putc(28) diff --git a/src/libsrc/etherip.pla b/src/libsrc/etherip.pla index f6309b3..87b7cb5 100644 --- a/src/libsrc/etherip.pla +++ b/src/libsrc/etherip.pla @@ -226,7 +226,7 @@ asm sum1 STA ESTKL,X BEQ + INC ESTKH,X - BCC CHKLP ++ BCC CHKLP INC ESTKH,X CLC CHKLP LDA (SRC),Y diff --git a/src/samplesrc/hgr1test.pla b/src/samplesrc/hgr1test.pla index ed707c6..b8fa643 100644 --- a/src/samplesrc/hgr1test.pla +++ b/src/samplesrc/hgr1test.pla @@ -92,13 +92,12 @@ PIX = $83 STA (TMP),Y + ASL PIX BPL + - LDA #$01 - STA PIX + SEC + ROL PIX INY CPY #36 BEQ ++ + LDA ESTKL+1,X - CLC ADC WFIXL STA WFIXL LDA ESTKH+1,X diff --git a/src/samplesrc/rod.pla b/src/samplesrc/rod.pla index 23edd46..1b6b0bc 100644 --- a/src/samplesrc/rod.pla +++ b/src/samplesrc/rod.pla @@ -88,12 +88,12 @@ asm grcolor GRCLR = $30 LDA #$0F AND ESTKL,X - STA ESTKL,X + STA GRCLR ASL ASL ASL ASL - ORA ESTKL,X + ORA GRCLR STA GRCLR RTS end @@ -105,23 +105,22 @@ asm grplot LDA ESTKL,X AND #$FE TAY - LDA (GRSCRN),Y + LDA (GRSCRN),Y STA DSTL INY LDA (GRSCRN),Y STA DSTH - LDY ESTKL+1,X - LDA GRCLR + LDA #$FF LSR ESTKL,X - BCS + - AND #$0F + ADC #$00 + EOR #$F0 + TAY + AND GRCLR STA TMPL - LDA #$F0 - BCC ++ -+ AND #$F0 - STA TMPL - LDA #$0F -++ AND (DST),Y + TYA + EOR #$FF + LDY ESTKL+1,X + AND (DST),Y ORA TMPL STA (DST),Y LDY IPY diff --git a/src/vmsrc/a1cmd.pla b/src/vmsrc/a1cmd.pla index fd1b8f9..63977c8 100644 --- a/src/vmsrc/a1cmd.pla +++ b/src/vmsrc/a1cmd.pla @@ -143,8 +143,7 @@ REGVALS = SRC LDA ESTKL,X PHA INX - LDA ESTKL,X - TAY + LDY ESTKL,X INX LDA ESTKL+1,X PHA @@ -187,25 +186,26 @@ asm memset LDA ESTKH+2,X STA DSTH LDY ESTKL,X - BEQ + + BEQ + INC ESTKH,X LDY #$00 -+ LDA ESTKH,X - BEQ SETMEX ++ LDA ESTKH,X + BEQ SETMEX SETMLPL CLC LDA ESTKL+1,X SETMLPH STA (DST),Y DEC ESTKL,X - BNE + - DEC ESTKH,X - BEQ SETMEX -+ INY - BNE + - INC DSTH -+ BCS SETMLPL + BEQ ++ +- INY + BEQ + +-- BCS SETMLPL SEC LDA ESTKH+1,X - BCS SETMLPH + BCS SETMLPH ++ INC DSTH + BNE -- +++ DEC ESTKH,X + BNE - SETMEX INX INX RTS @@ -291,15 +291,15 @@ end // Unsigned word comparisons. // asm uword_isge - LDY #$00 LDA ESTKL+1,X CMP ESTKL,X LDA ESTKH+1,X SBC ESTKH,X - BCC + - DEY -+ STY ESTKL+1,X - STY ESTKH+1,X + LDA #$FF + ADC #$00 + EOR #$FF + STA ESTKL+1,X + STA ESTKH+1,X INX RTS end @@ -309,9 +309,10 @@ asm uword_isle CMP ESTKL+1,X LDA ESTKH,X SBC ESTKH+1,X - BCC + - DEY -+ STY ESTKL+1,X + LDA #$FF + ADC #$00 + EOR #$FF + STY ESTKL+1,X STY ESTKH+1,X INX RTS @@ -436,7 +437,7 @@ asm stodci end asm toupper LDA ESTKL,X -TOUPR AND #$7F +TOUPR AND #$7F CMP #'a' BCC + CMP #'z'+1 @@ -476,7 +477,7 @@ asm modtosym LDY #$00 LDA #'#'+$80 - STA (DST),Y - CMP #$80 + ASL LDA (SRC),Y INY BCS - @@ -517,7 +518,7 @@ asm lookuptbl CMP (SRC),Y BNE ++ INY - CMP #$80 + ASL BCS - LDA (DST),Y PHA @@ -532,9 +533,8 @@ asm lookuptbl ++ LDY #$00 -- LDA (DST),Y INC DSTL - BNE ++ - INC DSTH -++ CMP #$80 + BEQ + +--- ASL BCS -- LDA #$02 ADC DSTL @@ -542,6 +542,8 @@ asm lookuptbl BCC - INC DSTH BCS - ++ INC DSTH + BNE --- end // // CONSOLE I/O diff --git a/src/vmsrc/cmd.pla b/src/vmsrc/cmd.pla index 73a31c2..6ab3d88 100644 --- a/src/vmsrc/cmd.pla +++ b/src/vmsrc/cmd.pla @@ -201,25 +201,26 @@ asm memset LDA ESTKH+2,X STA DSTH LDY ESTKL,X - BEQ + + BEQ + INC ESTKH,X LDY #$00 -+ LDA ESTKH,X - BEQ SETMEX ++ LDA ESTKH,X + BEQ SETMEX SETMLPL CLC LDA ESTKL+1,X SETMLPH STA (DST),Y DEC ESTKL,X - BNE + - DEC ESTKH,X - BEQ SETMEX -+ INY - BNE + - INC DSTH -+ BCS SETMLPL + BEQ ++ +- INY + BEQ + +-- BCS SETMLPL SEC LDA ESTKH+1,X - BCS SETMLPH + BCS SETMLPH ++ INC DSTH + BNE -- +++ DEC ESTKH,X + BNE - SETMEX INX INX RTS @@ -325,7 +326,7 @@ asm memxcpy SEC JSR $C311 BIT LCRDEN+LCBNK2 - LDX ESP + LDX ESP INX INX RTS @@ -372,13 +373,13 @@ end // asm prstr LDY #$00 - LDA ESTKL,X - STA SRCL - LDA ESTKH,X - STA SRCH - LDA (SRC),Y - STA TMP - BEQ ++ + LDA ESTKL,X + STA SRCL + LDA ESTKH,X + STA SRCH + LDA (SRC),Y + BEQ ++ + STA TMP BIT ROMEN - INY LDA (SRC),Y @@ -427,20 +428,20 @@ asm rdstr LDA ESTKL,X STA $33 STX ESP - BIT ROMEN + BIT ROMEN JSR $FD6A STX $01FF -- LDA $01FF,X - AND #$7F - STA $01FF,X +- LDA $01FF,X + AND #$7F + STA $01FF,X DEX - BPL - + BPL - TXA LDX ESP STA ESTKL,X LDA #$01 STA ESTKH,X - BIT LCRDEN+LCBNK2 + BIT LCRDEN+LCBNK2 RTS end asm uword_isge @@ -449,9 +450,10 @@ asm uword_isge CMP ESTKL,X LDA ESTKH+1,X SBC ESTKH,X - BCC + - DEY -+ STY ESTKL+1,X + LDA #$FF + ADC #$00 + EOR #$FF + STY ESTKL+1,X STY ESTKH+1,X INX RTS @@ -462,9 +464,10 @@ asm uword_isle CMP ESTKL+1,X LDA ESTKH,X SBC ESTKH+1,X - BCC + - DEY -+ STY ESTKL+1,X + LDA #$FF + ADC #$00 + EOR #$FF + STY ESTKL+1,X STY ESTKH+1,X INX RTS @@ -620,7 +623,7 @@ asm modtosym LDY #$00 LDA #'#'+$80 - STA (DST),Y - CMP #$80 + ASL LDA (SRC),Y INY BCS - @@ -661,7 +664,7 @@ asm lookuptbl CMP (SRC),Y BNE ++ INY - CMP #$80 + ASL BCS - LDA (DST),Y PHA @@ -676,9 +679,8 @@ asm lookuptbl ++ LDY #$00 -- LDA (DST),Y INC DSTL - BNE ++ - INC DSTH -++ CMP #$80 + BEQ + +--- ASL BCS -- LDA #$02 ADC DSTL @@ -686,6 +688,8 @@ asm lookuptbl BCC - INC DSTH BCS - ++ INC DSTH + BNE --- end // // ProDOS routines diff --git a/src/vmsrc/cmdstub.s b/src/vmsrc/cmdstub.s index fea3adf..09928ea 100644 --- a/src/vmsrc/cmdstub.s +++ b/src/vmsrc/cmdstub.s @@ -1,7 +1,7 @@ INTERP = $03D0 LCRDEN = $C080 LCWTEN = $C081 -ROMEN = $C082 +ROMEN = $C082 LCRWEN = $C083 LCBNK2 = $00 LCBNK1 = $08 @@ -33,15 +33,14 @@ LCBNK1 = $08 ; ; INIT VM ENVIRONMENT STACK POINTERS ; - LDA #$00 ; INIT FRAME POINTER - STA PPL - STA IFPL + STY PPL + STY IFPL ; INIT FRAME POINTER LDA #$BF STA PPH STA IFPH LDX #$FE ; INIT STACK POINTER (YES, $FE. SEE GETS) TXS - LDX #ESTKSZ/2 ; INIT EVAL STACK INDEX + LDX #ESTKSZ/2 ; INIT EVAL STACK INDEX JMP $1000 _CMDBEGIN = * !PSEUDOPC $1000 { diff --git a/src/vmsrc/plvm01.s b/src/vmsrc/plvm01.s index c36c438..6736daf 100644 --- a/src/vmsrc/plvm01.s +++ b/src/vmsrc/plvm01.s @@ -884,13 +884,12 @@ LIFPH INC IFPH RET RTS A1CMD !SOURCE "vmsrc/a1cmd.a" SEGEND = * -VMINIT LDY #$0F ; INSTALL PAGE 0 FETCHOP ROUTINE -- LDA PAGE0,Y - STA DROP,Y +VMINIT LDY #$10 ; INSTALL PAGE 0 FETCHOP ROUTINE +- LDA PAGE0-1,Y + STA DROP-1,Y DEY - BPL - - LDA #$00 ; INIT FRAME POINTER - STA IFPL + BNE - + STY IFPL ; INIT FRAME POINTER LDA #$80 STA IFPH LDA #VMCORE STA SRCH - LDA #$00 - STA DSTL + LDY #$00 + STY DSTL LDA #$D0 STA DSTH - LDY #$00 - LDA (SRC),Y ; COPY VM+CMD INTO LANGUAGE CARD STA (DST),Y INY @@ -118,7 +117,6 @@ RAMDONE CLI ;* ;* MOVE FIRST PAGE OF 'BYE' INTO PLACE ;* - LDY #$00 STY SRCL LDA #$D1 STA SRCH diff --git a/src/vmsrc/soscmd.pla b/src/vmsrc/soscmd.pla index adfd94b..9c1184e 100644 --- a/src/vmsrc/soscmd.pla +++ b/src/vmsrc/soscmd.pla @@ -188,25 +188,26 @@ asm memset LDA ESTKH+2,X STA DSTH LDY ESTKL,X - BEQ + + BEQ + INC ESTKH,X LDY #$00 -+ LDA ESTKH,X - BEQ SETMEX ++ LDA ESTKH,X + BEQ SETMEX SETMLPL CLC LDA ESTKL+1,X SETMLPH STA (DST),Y DEC ESTKL,X - BNE + - DEC ESTKH,X - BEQ SETMEX -+ INY - BNE + - INC DSTH -+ BCS SETMLPL + BEQ ++ +- INY + BEQ + +-- BCS SETMLPL SEC LDA ESTKH+1,X - BCS SETMLPH + BCS SETMLPH ++ INC DSTH + BNE -- +++ DEC ESTKH,X + BNE - SETMEX INX INX RTS @@ -361,9 +362,10 @@ asm uword_isge CMP ESTKL,X LDA ESTKH+1,X SBC ESTKH,X - BCC + - DEY -+ STY ESTKL+1,X + LDA #$FF + ADC #$00 + EOR #$FF + STY ESTKL+1,X STY ESTKH+1,X INX RTS @@ -374,9 +376,10 @@ asm uword_isle CMP ESTKL+1,X LDA ESTKH,X SBC ESTKH+1,X - BCC + - DEY -+ STY ESTKL+1,X + LDA #$FF + ADC #$00 + EOR #$FF + STY ESTKL+1,X STY ESTKH+1,X INX RTS @@ -541,7 +544,7 @@ asm modtosym LDY #$00 LDA #'#'+$80 - STA (DST),Y - CMP #$80 + ASL LDA (SRC),Y INY BCS - @@ -587,7 +590,7 @@ asm lookuptbl CMP (SRC),Y BNE ++ INY - CMP #$80 + ASL BCS - LDA (DST),Y PHA @@ -604,9 +607,8 @@ asm lookuptbl ++ LDY #$00 -- LDA (DST),Y INC DSTL - BNE + - INC DSTH -+ CMP #$80 + BEQ + +--- ASL BCS -- LDA #$02 ADC DSTL @@ -614,6 +616,8 @@ asm lookuptbl BCC - INC DSTH BCS - ++ INC DSTH + BNE --- end // // SOS routines