diff --git a/src/vmsrc/plvm01.s b/src/vmsrc/plvm01.s index 9023221..0ca40ec 100644 --- a/src/vmsrc/plvm01.s +++ b/src/vmsrc/plvm01.s @@ -5,7 +5,6 @@ ;* SYSTEM ROUTINES AND LOCATIONS ;* ;********************************************************** -SELFMODIFY = 1 ;* ;* VM ZERO PAGE LOCATIONS ;* @@ -20,18 +19,6 @@ IPH = IPL+1 OPIDX = FETCHOP+6 OPPAGE = OPIDX+1 ;* -;* INTERPRETER INSTRUCTION POINTER INCREMENT MACRO -;* - !MACRO INC_IP { - INY - BPL + - INC IPH - TYA - AND #$7F - TAY -+ - } -;* ;* INTERPRETER HEADER+INITIALIZATION ;* *= $0280 @@ -92,21 +79,21 @@ MULLP LSR TMPH ; MULTPLRH BNE MULLP STA ESTKH+1,X ; PRODH LDY IPY - JMP DROP + JMP DROP ;* ;* INCREMENT TOS ;* INCR INC ESTKL,X - BNE INCR1 + BNE + INC ESTKH,X -INCR1 JMP NEXTOP ++ JMP NEXTOP ;* ;* DECREMENT TOS ;* DECR LDA ESTKL,X - BNE DECR1 + BNE + DEC ESTKH,X -DECR1 DEC ESTKL,X ++ DEC ESTKL,X JMP NEXTOP ;* ;* BITWISE COMPLIMENT TOS @@ -121,7 +108,7 @@ COMP LDA #$FF ;* ;* OPCODE TABLE ;* - !ALIGN 255,0 + !ALIGN 255,0 OPTBL !WORD ZERO,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 00 02 04 06 08 0A 0C 0E !WORD NEG,COMP,BAND,IOR,XOR,SHL,SHR,IDXW ; 10 12 14 16 18 1A 1C 1E !WORD LNOT,LOR,LAND,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E @@ -154,10 +141,9 @@ MOD JSR _DIV DIVMOD JSR _DIV LSR DVSIGN ; SIGN(RESULT) = (SIGN(DIVIDEND) + SIGN(DIVISOR)) & 1 BCC + - INX JSR _NEG - DEX -+ LDA TMPL ; REMNDRL ++ DEX + LDA TMPL ; REMNDRL STA ESTKL,X LDA TMPH ; REMNDRH STA ESTKH,X @@ -292,24 +278,24 @@ XOR LDA ESTKL+1,X ;* ;* SHIFT TOS-1 LEFT BY TOS ;* -SHL STY IPY +SHL STY IPY LDA ESTKL,X CMP #$08 - BCC SHL1 + BCC + LDY ESTKL+1,X STY ESTKH+1,X LDY #$00 STY ESTKL+1,X SBC #$08 -SHL1 TAY - BEQ SHL3 ++ TAY + BEQ + LDA ESTKL+1,X -SHL2 ASL +- ASL ROL ESTKH+1,X DEY - BNE SHL2 + BNE - STA ESTKL+1,X -SHL3 LDY IPY ++ LDY IPY JMP DROP ;* ;* SHIFT TOS-1 RIGHT BY TOS @@ -317,51 +303,40 @@ SHL3 LDY IPY SHR STY IPY LDA ESTKL,X CMP #$08 - BCC SHR2 + BCC ++ LDY ESTKH+1,X STY ESTKL+1,X CPY #$80 LDY #$00 - BCC SHR1 + BCC + DEY -SHR1 STY ESTKH+1,X ++ STY ESTKH+1,X SEC SBC #$08 -SHR2 TAY - BEQ SHR4 +++ TAY + BEQ + LDA ESTKH+1,X -SHR3 CMP #$80 +- CMP #$80 ROR ROR ESTKL+1,X DEY - BNE SHR3 + BNE - STA ESTKH+1,X -SHR4 LDY IPY ++ LDY IPY JMP DROP ;* -;* LOGICAL NOT -;* -LNOT LDA ESTKL,X - ORA ESTKH,X - BEQ LNOT1 - LDA #$FF -LNOT1 EOR #$FF - STA ESTKL,X - STA ESTKH,X - JMP NEXTOP -;* ;* LOGICAL AND ;* LAND LDA ESTKL+1,X ORA ESTKH+1,X - BEQ LAND2 + BEQ ++ LDA ESTKL,X ORA ESTKH,X - BEQ LAND1 + BEQ + LDA #$FF -LAND1 STA ESTKL+1,X ++ STA ESTKL+1,X STA ESTKH+1,X -LAND2 JMP DROP +++ JMP DROP ;* ;* LOGICAL OR ;* @@ -369,11 +344,11 @@ LOR LDA ESTKL,X ORA ESTKH,X ORA ESTKL+1,X ORA ESTKH+1,X - BEQ LOR1 + BEQ + LDA #$FF STA ESTKL+1,X STA ESTKH+1,X -LOR1 JMP DROP ++ JMP DROP ;* ;* DUPLICATE TOS ;* @@ -384,10 +359,20 @@ DUP DEX STA ESTKH,X JMP NEXTOP ;* +;* LOGICAL NOT +;* +LNOT LDA ESTKL,X + ORA ESTKH,X + BNE + + LDA #$FF + STA ESTKL,X + STA ESTKH,X + JMP NEXTOP +;* ;* CONSTANT ;* ZERO DEX - LDA #$00 ++ LDA #$00 STA ESTKL,X STA ESTKH,X JMP NEXTOP @@ -396,19 +381,34 @@ CFFB LDA #$FF CB LDA #$00 DEX STA ESTKH,X - +INC_IP + INY ;+INC_IP LDA (IP),Y STA ESTKL,X JMP NEXTOP ;* ;* LOAD ADDRESS & LOAD CONSTANT WORD (SAME THING, WITH OR WITHOUT FIXUP) ;* -LA = * -CW DEX - INY ;+INC_IP +- TYA ; RENORMALIZE IP + CLC + ADC IPL + STA IPL + BCC + + INC IPH ++ LDY #$FF +LA INY ;+INC_IP + BMI - + DEX LDA (IP),Y STA ESTKL,X - +INC_IP + INY + LDA (IP),Y + STA ESTKH,X + JMP NEXTOP +CW DEX + INY ;+INC_IP + LDA (IP),Y + STA ESTKL,X + INY LDA (IP),Y STA ESTKH,X JMP NEXTOP @@ -416,9 +416,9 @@ CW DEX ;* CONSTANT STRING ;* CS DEX - INY ;+INC_IP - TYA ; NORMALIZE IP AND SAVE STRING ADDR ON ESTK - CLC + ;INY ;+INC_IP + TYA ; NORMALIZE IP AND SAVE STRING ADDR ON ESTK + SEC ADC IPL STA IPL STA ESTKL,X @@ -433,46 +433,38 @@ CS DEX ;* ;* LOAD VALUE FROM ADDRESS TAG ;* -!IF SELFMODIFY { LB LDA ESTKL,X - STA LBLDA+1 - LDA ESTKH,X - STA LBLDA+2 -LBLDA LDA $FFFF + STA ESTKH-1,X + LDA (ESTKH-1,X) STA ESTKL,X LDA #$00 STA ESTKH,X JMP NEXTOP -} ELSE { -LB LDA ESTKL,X - STA TMPL - LDA ESTKH,X - STA TMPH - STY IPY - LDY #$00 - LDA (TMP),Y - STA ESTKL,X - STY ESTKH,X - LDY IPY - JMP NEXTOP -} LW LDA ESTKL,X - STA TMPL - LDA ESTKH,X - STA TMPH - STY IPY - LDY #$00 - LDA (TMP),Y + STA ESTKH-1,X + LDA (ESTKH-1,X) STA ESTKL,X - INY - LDA (TMP),Y + INC ESTKH-1,X + BEQ + + LDA (ESTKH-1,X) + STA ESTKH,X + JMP NEXTOP ++ INC ESTKH,X + LDA (ESTKH-1,X) STA ESTKH,X - LDY IPY JMP NEXTOP ;* ;* LOAD ADDRESS OF LOCAL FRAME OFFSET ;* -LLA +INC_IP +- TYA ; RENORMALIZE IP + CLC + ADC IPL + STA IPL + BCC + + INC IPH ++ LDY #$FF +LLA INY ;+INC_IP + BMI - LDA (IP),Y DEX CLC @@ -485,7 +477,7 @@ LLA +INC_IP ;* ;* LOAD VALUE FROM LOCAL FRAME OFFSET ;* -LLB +INC_IP +LLB INY ;+INC_IP LDA (IP),Y STY IPY TAY @@ -496,7 +488,7 @@ LLB +INC_IP STA ESTKH,X LDY IPY JMP NEXTOP -LLW +INC_IP +LLW INY ;+INC_IP LDA (IP),Y STY IPY TAY @@ -511,39 +503,22 @@ LLW +INC_IP ;* ;* LOAD VALUE FROM ABSOLUTE ADDRESS ;* -!IF SELFMODIFY { -LAB INY ;+INC_IP +LAB INY ;+INC_IP LDA (IP),Y - STA LABLDA+1 - +INC_IP + STA ESTKH-2,X + INY ;+INC_IP LDA (IP),Y - STA LABLDA+2 -LABLDA LDA $FFFF + STA ESTKH-1,X + LDA (ESTKH-2,X) DEX STA ESTKL,X LDA #$00 STA ESTKH,X JMP NEXTOP -} ELSE { -LAB INY ;+INC_IP +LAW INY ;+INC_IP LDA (IP),Y STA TMPL - +INC_IP - LDA (IP),Y - STA TMPH - STY IPY - LDY #$00 - LDA (TMP),Y - DEX - STA ESTKL,X - STY ESTKH,X - LDY IPY - JMP NEXTOP -} -LAW INY ;+INC_IP - LDA (IP),Y - STA TMPL - +INC_IP + INY ;+INC_IP LDA (IP),Y STA TMPH STY IPY @@ -559,54 +534,39 @@ LAW INY ;+INC_IP ;* ;* STORE VALUE TO ADDRESS ;* -!IF SELFMODIFY { SB LDA ESTKL,X - STA SBSTA+1 - LDA ESTKH,X - STA SBSTA+2 + STA ESTKH-1,X LDA ESTKL+1,X -SBSTA STA $FFFF + STA (ESTKH-1,X) INX JMP DROP -} ELSE { -SB LDA ESTKL,X - STA TMPL - LDA ESTKH,X - STA TMPH - LDA ESTKL+1,X - STY IPY - LDY #$00 - STA (TMP),Y - LDY IPY - INX - JMP DROP -} SW LDA ESTKL,X - STA TMPL - LDA ESTKH,X - STA TMPH - STY IPY - LDY #$00 + STA ESTKH-1,X LDA ESTKL+1,X - STA (TMP),Y - INY + STA (ESTKH-1,X) LDA ESTKH+1,X - STA (TMP),Y - LDY IPY + INC ESTKH-1,X + BEQ + + STA (ESTKH-1,X) + INX + JMP DROP ++ INC ESTKH,X + STA (ESTKH-1,X) INX JMP DROP ;* ;* STORE VALUE TO LOCAL FRAME OFFSET ;* -SLB +INC_IP +SLB INY ;+INC_IP LDA (IP),Y STY IPY TAY LDA ESTKL,X STA (IFP),Y LDY IPY + BMI FIXDROP JMP DROP -SLW +INC_IP +SLW INY ;+INC_IP LDA (IP),Y STY IPY TAY @@ -616,11 +576,20 @@ SLW +INC_IP LDA ESTKH,X STA (IFP),Y LDY IPY + BMI FIXDROP JMP DROP +FIXDROP TYA + LDY #$00 + CLC + ADC IPL + STA IPL + BCC + + INC IPH ++ JMP DROP ;* ;* STORE VALUE TO LOCAL FRAME OFFSET WITHOUT POPPING STACK ;* -DLB +INC_IP +DLB INY ;+INC_IP LDA (IP),Y STY IPY TAY @@ -628,7 +597,7 @@ DLB +INC_IP STA (IFP),Y LDY IPY JMP NEXTOP -DLW +INC_IP +DLW INY ;+INC_IP LDA (IP),Y STY IPY TAY @@ -642,34 +611,27 @@ DLW +INC_IP ;* ;* STORE VALUE TO ABSOLUTE ADDRESS ;* -!IF SELFMODIFY { -SAB INY ;+INC_IP +- TYA ; RENORMALIZE IP + CLC + ADC IPL + STA IPL + BCC + + INC IPH ++ LDY #$FF +SAB INY ;+INC_IP + BMI - LDA (IP),Y - STA SABSTA+1 - +INC_IP + STA ESTKH-2,X + INY ;+INC_IP LDA (IP),Y - STA SABSTA+2 + STA ESTKH-1,X LDA ESTKL,X -SABSTA STA $FFFF + STA (ESTKH-2,X) JMP DROP -} ELSE { -SAB INY ;+INC_IP +SAW INY ;+INC_IP LDA (IP),Y STA TMPL - +INC_IP - LDA (IP),Y - STA TMPH - LDA ESTKL,X - STY IPY - LDY #$00 - STA (TMP),Y - LDY IPY - JMP DROP -} -SAW INY ;+INC_IP - LDA (IP),Y - STA TMPL - +INC_IP + INY ;+INC_IP LDA (IP),Y STA TMPH STY IPY @@ -680,38 +642,24 @@ SAW INY ;+INC_IP LDA ESTKH,X STA (TMP),Y LDY IPY + BMI FIXDROP JMP DROP ;* ;* STORE VALUE TO ABSOLUTE ADDRESS WITHOUT POPPING STACK ;* -!IF SELFMODIFY { -DAB INY ;+INC_IP +DAB INY ;+INC_IP LDA (IP),Y - STA DABSTA+1 - +INC_IP + STA ESTKH-2,X + INY ;+INC_IP LDA (IP),Y - STA DABSTA+2 + STA ESTKH-1,X LDA ESTKL,X -DABSTA STA $FFFF + STA (ESTKH-2,X) JMP NEXTOP -} ELSE { -DAB INY ;+INC_IP +DAW INY ;+INC_IP LDA (IP),Y STA TMPL - +INC_IP - LDA (IP),Y - STA TMPH - STY IPY - LDY #$00 - LDA ESTKL,X - STA (TMP),Y - LDY IPY - JMP NEXTOP -} -DAW INY ;+INC_IP - LDA (IP),Y - STA TMPL - +INC_IP + INY ;+INC_IP LDA (IP),Y STA TMPH STY IPY @@ -752,37 +700,41 @@ ISGE LDA ESTKL+1,X CMP ESTKL,X LDA ESTKH+1,X SBC ESTKH,X - BVC ISGE1 - EOR #$80 -ISGE1 BPL ISTRU + BVS + + BPL ISTRU BMI ISFLS ++ BPL ISFLS + BMI ISTRU ; ISGT LDA ESTKL,X CMP ESTKL+1,X LDA ESTKH,X SBC ESTKH+1,X - BVC ISGT1 - EOR #$80 -ISGT1 BMI ISTRU + BVS + + BMI ISTRU BPL ISFLS ++ BMI ISFLS + BPL ISTRU ; ISLE LDA ESTKL,X CMP ESTKL+1,X LDA ESTKH,X SBC ESTKH+1,X - BVC ISLE1 - EOR #$80 -ISLE1 BPL ISTRU + BVS + + BPL ISTRU BMI ISFLS ++ BPL ISFLS + BMI ISTRU ; ISLT LDA ESTKL+1,X CMP ESTKL,X LDA ESTKH+1,X SBC ESTKH,X - BVC ISLT1 - EOR #$80 -ISLT1 BMI ISTRU + BVS + + BMI ISTRU BPL ISFLS ++ BMI ISFLS + BPL ISTRU ;* ;* BRANCHES ;* @@ -790,9 +742,18 @@ BRTRU INX LDA ESTKH-1,X ORA ESTKL-1,X BNE BRNCH -NOBRNCH INY ;+INC_IP - +INC_IP +NOBRNCH INY ;+INC_IP + INY ;+INC_IP + BMI FIXNEXT JMP NEXTOP +FIXNEXT TYA + LDY #$00 + CLC + ADC IPL + STA IPL + BCC + + INC IPH ++ JMP NEXTOP BRFLS INX LDA ESTKH-1,X ORA ESTKL-1,X @@ -836,20 +797,34 @@ BRGT INX CMP ESTKL,X LDA ESTKH-1,X SBC ESTKH,X + BVS + BPL NOBRNCH BMI BRNCH ++ BPL BRNCH + BMI NOBRNCH BRLT INX LDA ESTKL,X CMP ESTKL-1,X LDA ESTKH,X SBC ESTKH-1,X + BVS + BPL NOBRNCH BMI BRNCH -IBRNCH LDA IPL ++ BPL BRNCH + BMI NOBRNCH +IBRNCH TYA ; FLATTEN IP CLC + ADC IPL + STA TMPL + LDA #$00 + TAY + ADC IPH + STA TMPH ; ADD BRANCH OFFSET + LDA TMPL + ;CLC ; BETTER NOT CARRY OUT OF IP+Y ADC ESTKL,X STA IPL - LDA IPH + LDA TMPH ADC ESTKH,X STA IPH JMP DROP @@ -857,36 +832,20 @@ IBRNCH LDA IPL ;* INDIRECT CALL TO ADDRESS (NATIVE CODE) ;* ICAL LDA ESTKL,X -!IF SELFMODIFY { - STA CALLADR+1 -} ELSE { STA TMPL -} LDA ESTKH,X -!IF SELFMODIFY { - STA CALLADR+2 -} ELSE { STA TMPH -} INX BNE _CALL ;* ;* CALL INTO ABSOLUTE ADDRESS (NATIVE CODE) ;* -CALL INY ;+INC_IP +CALL INY ;+INC_IP LDA (IP),Y -!IF SELFMODIFY { - STA CALLADR+1 -} ELSE { STA TMPL -} - INY ;+INC_IP + INY ;+INC_IP LDA (IP),Y -!IF SELFMODIFY { - STA CALLADR+2 -} ELSE { STA TMPH -} _CALL TYA CLC ADC IPL @@ -894,11 +853,7 @@ _CALL TYA LDA IPH ADC #$00 PHA -!IF SELFMODIFY { -CALLADR JSR $FFFF -} ELSE { JSR JMPTMP -} PLA STA IPH PLA @@ -938,14 +893,14 @@ ENTER INY ;* ;* LEAVE FUNCTION ;* -LEAVE INY ;+INC_IP +LEAVE INY ;+INC_IP LDA (IP),Y CLC ADC IFPL STA IFPL - BCS LIFPH + BCS + RTS -LIFPH INC IFPH ++ INC IFPH RET RTS A1CMD !SOURCE "vmsrc/a1cmd.a" SEGEND = * @@ -954,6 +909,8 @@ VMINIT LDY #$10 ; INSTALL PAGE 0 FETCHOP ROUTINE STA DROP-1,Y DEY BNE - + LDA #$4C ; SET JMPTMP OPCODE + STA JMPTMP STY IFPL ; INIT FRAME POINTER LDA #$80 STA IFPH @@ -962,7 +919,7 @@ VMINIT LDY #$10 ; INSTALL PAGE 0 FETCHOP ROUTINE LDA #>SEGEND STA SRCH LDX #ESTKSZ/2 ; INIT EVAL STACK INDEX - JMP A1CMD + JMP A1CMD PAGE0 = * !PSEUDOPC DROP { ;* diff --git a/src/vmsrc/plvm02.s b/src/vmsrc/plvm02.s index cf6c6e9..0c8d46f 100755 --- a/src/vmsrc/plvm02.s +++ b/src/vmsrc/plvm02.s @@ -509,7 +509,8 @@ _DIVLP ROL TMPL ; REMNDRL ROL ESTKH+1,X ; DVDNDH DEY BNE _DIVLP -_DIVEX LDY IPY +_DIVEX INX + LDY IPY RTS ;* ;* NEGATE TOS @@ -526,7 +527,6 @@ NEG LDA #$00 ;* DIV TOS-1 BY TOS ;* DIV JSR _DIV - INX LSR DVSIGN ; SIGN(RESULT) = (SIGN(DIVIDEND) + SIGN(DIVISOR)) & 1 BCS NEG JMP NEXTOP @@ -534,7 +534,6 @@ DIV JSR _DIV ;* MOD TOS-1 BY TOS ;* MOD JSR _DIV - INX LDA TMPL ; REMNDRL STA ESTKL,X LDA TMPH ; REMNDRH @@ -548,10 +547,9 @@ MOD JSR _DIV DIVMOD JSR _DIV LSR DVSIGN ; SIGN(RESULT) = (SIGN(DIVIDEND) + SIGN(DIVISOR)) & 1 BCC + - INX JSR _NEG - DEX -+ LDA TMPL ; REMNDRL ++ DEX + LDA TMPL ; REMNDRL STA ESTKL,X LDA TMPH ; REMNDRH STA ESTKH,X @@ -562,18 +560,18 @@ DIVMOD JSR _DIV ;* INCREMENT TOS ;* INCR INC ESTKL,X - BEQ INCR1 + BEQ + JMP NEXTOP -INCR1 INC ESTKH,X ++ INC ESTKH,X JMP NEXTOP ;* ;* DECREMENT TOS ;* DECR LDA ESTKL,X - BEQ DECR1 + BEQ + DEC ESTKL,X JMP NEXTOP -DECR1 DEC ESTKL,X ++ DEC ESTKL,X DEC ESTKH,X JMP NEXTOP ;* @@ -670,14 +668,14 @@ SHR STY IPY ;* LAND LDA ESTKL+1,X ORA ESTKH+1,X - BEQ LAND2 + BEQ ++ LDA ESTKL,X ORA ESTKH,X - BEQ LAND1 + BEQ + LDA #$FF -LAND1 STA ESTKL+1,X ++ STA ESTKL+1,X STA ESTKH+1,X -LAND2 JMP DROP +++ JMP DROP ;* ;* LOGICAL OR ;* @@ -685,11 +683,11 @@ LOR LDA ESTKL,X ORA ESTKH,X ORA ESTKL+1,X ORA ESTKH+1,X - BEQ LOR1 + BEQ + LDA #$FF STA ESTKL+1,X STA ESTKH+1,X -LOR1 JMP DROP ++ JMP DROP ;* ;* DUPLICATE TOS ;* @@ -720,14 +718,14 @@ ZERO DEX CFFB DEX LDA #$FF STA ESTKH,X - INY + INY ;+INC_IP LDA (IP),Y STA ESTKL,X JMP NEXTOP CB DEX LDA #$00 STA ESTKH,X - INY + INY ;+INC_IP LDA (IP),Y STA ESTKL,X JMP NEXTOP @@ -762,9 +760,9 @@ CW DEX ;* CONSTANT STRING ;* CS DEX - INY ;+INC_IP + ;INY ;+INC_IP TYA ; NORMALIZE IP AND SAVE STRING ADDR ON ESTK - CLC + SEC ADC IPL STA IPL STA ESTKL,X @@ -778,9 +776,9 @@ CS DEX JMP NEXTOP ; CSX DEX - INY ;+INC_IP + ;INY ;+INC_IP TYA ; NORMALIZE IP - CLC + SEC ADC IPL STA IPL LDA #$00 @@ -1565,9 +1563,9 @@ CCBEND LDY #(CCSEND-CCS) JSR OPCPY CCS DEX - INY ;+INC_IP + ;INY ;+INC_IP TYA ; NORMALIZE IP AND SAVE STRING ADDR ON ESTK - CLC + SEC ADC IPL STA IPL STA ESTKL,X diff --git a/src/vmsrc/plvm03.s b/src/vmsrc/plvm03.s index ba7650f..8e7ca9a 100755 --- a/src/vmsrc/plvm03.s +++ b/src/vmsrc/plvm03.s @@ -5,7 +5,6 @@ ;* SYSTEM ROUTINES AND LOCATIONS ;* ;********************************************************** -SELFMODIFY = 1 ; ; HARDWARE REGISTERS ; @@ -40,21 +39,9 @@ DSTX = XPAGE+DSTH !WORD .LIST } ;* -;* INTERPRETER INSTRUCTION POINTER INCREMENT MACRO -;* - !MACRO INC_IP { - INY - BPL + - INC IPH - TYA - AND #$7F - TAY -+ - } -;* ;* INTERPRETER HEADER+INITIALIZATION ;* - SEGSTART = $A000 +SEGSTART = $A000 *= SEGSTART-$0E !TEXT "SOS NTRP" !WORD $0000 @@ -131,16 +118,6 @@ INTERP PLA PLA ADC #$00 STA IPH - - LDA IFPH - PHA ; SAVE ON STACK FOR LEAVE/RET - LDA IFPL - PHA ; SAVE ON STACK FOR LEAVE/RET - LDA PPL ; SET FP TO PP - STA IFPL - LDA PPH - STA IFPH - LDY #$00 STY IPX JMP FETCHOP @@ -161,16 +138,6 @@ XINTERP PLA LDA (TMP),Y STA IPL DEY - - LDA IFPH - PHA ; SAVE ON STACK FOR LEAVE/RET - LDA IFPL - PHA ; SAVE ON STACK FOR LEAVE/RET - LDA PPL ; SET FP TO PP - STA IFPL - LDA PPH - STA IFPH - JMP FETCHOP ;* ;* INTERNAL DIVIDE ALGORITHM @@ -267,8 +234,6 @@ MULLP LSR TMPH ; MULTPLRH BNE MULLP STA ESTKH+1,X ; PRODH LDY IPY -; INX -; JMP NEXTOP JMP DROP ;* ;* NEGATE TOS @@ -299,10 +264,9 @@ MOD JSR _DIV DIVMOD JSR _DIV LSR DVSIGN ; SIGN(RESULT) = (SIGN(DIVIDEND) + SIGN(DIVISOR)) & 1 BCC + - INX JSR _NEG - DEX -+ LDA TMPL ; REMNDRL ++ DEX + LDA TMPL ; REMNDRL STA ESTKL,X LDA TMPH ; REMNDRH STA ESTKH,X @@ -319,8 +283,6 @@ ADD LDA ESTKL,X LDA ESTKH,X ADC ESTKH+1,X STA ESTKH+1,X -; INX -; JMP NEXTOP JMP DROP ;* ;* SUB TOS FROM TOS-1 @@ -332,8 +294,6 @@ SUB LDA ESTKL+1,X LDA ESTKH+1,X SBC ESTKH,X STA ESTKH+1,X -; INX -; JMP NEXTOP JMP DROP ; ;* @@ -348,23 +308,21 @@ IDXW LDA ESTKL,X LDA ESTKH,X ADC ESTKH+1,X STA ESTKH+1,X -; INX -; JMP NEXTOP JMP DROP ;* ;* INCREMENT TOS ;* INCR INC ESTKL,X - BNE INCR1 + BNE + INC ESTKH,X -INCR1 JMP NEXTOP ++ JMP NEXTOP ;* ;* DECREMENT TOS ;* DECR LDA ESTKL,X - BNE DECR1 + BNE + DEC ESTKH,X -DECR1 DEC ESTKL,X ++ DEC ESTKL,X JMP NEXTOP ;* ;* BITWISE COMPLIMENT TOS @@ -385,8 +343,6 @@ BAND LDA ESTKL+1,X LDA ESTKH+1,X AND ESTKH,X STA ESTKH+1,X -; INX -; JMP NEXTOP JMP DROP ;* ;* INCLUSIVE OR TOS TO TOS-1 @@ -397,8 +353,6 @@ IOR LDA ESTKL+1,X LDA ESTKH+1,X ORA ESTKH,X STA ESTKH+1,X -; INX -; JMP NEXTOP JMP DROP ;* ;* EXLUSIVE OR TOS TO TOS-1 @@ -409,8 +363,6 @@ XOR LDA ESTKL+1,X LDA ESTKH+1,X EOR ESTKH,X STA ESTKH+1,X -; INX -; JMP NEXTOP JMP DROP ;* ;* SHIFT TOS-1 LEFT BY TOS @@ -418,21 +370,21 @@ XOR LDA ESTKL+1,X SHL STY IPY LDA ESTKL,X CMP #$08 - BCC SHL1 + BCC + LDY ESTKL+1,X STY ESTKH+1,X LDY #$00 STY ESTKL+1,X SBC #$08 -SHL1 TAY - BEQ SHL3 ++ TAY + BEQ + LDA ESTKL+1,X -SHL2 ASL +- ASL ROL ESTKH+1,X DEY - BNE SHL2 + BNE - STA ESTKL+1,X -SHL3 LDY IPY ++ LDY IPY JMP DROP ;* ;* SHIFT TOS-1 RIGHT BY TOS @@ -440,53 +392,40 @@ SHL3 LDY IPY SHR STY IPY LDA ESTKL,X CMP #$08 - BCC SHR2 + BCC ++ LDY ESTKH+1,X STY ESTKL+1,X CPY #$80 LDY #$00 - BCC SHR1 + BCC + DEY -SHR1 STY ESTKH+1,X ++ STY ESTKH+1,X SEC SBC #$08 -SHR2 TAY - BEQ SHR4 +++ TAY + BEQ + LDA ESTKH+1,X -SHR3 CMP #$80 +- CMP #$80 ROR ROR ESTKL+1,X DEY - BNE SHR3 + BNE - STA ESTKH+1,X -SHR4 LDY IPY ++ LDY IPY JMP DROP ;* -;* LOGICAL NOT -;* -LNOT LDA ESTKL,X - ORA ESTKH,X - BEQ LNOT1 - LDA #$FF -LNOT1 EOR #$FF - STA ESTKL,X - STA ESTKH,X - JMP NEXTOP -;* ;* LOGICAL AND ;* LAND LDA ESTKL+1,X ORA ESTKH+1,X - BEQ LAND2 + BEQ ++ LDA ESTKL,X ORA ESTKH,X - BEQ LAND1 + BEQ + LDA #$FF -LAND1 STA ESTKL+1,X ++ STA ESTKL+1,X STA ESTKH+1,X -;LAND2 INX -; JMP NEXTOP -LAND2 JMP DROP +++ JMP DROP ;* ;* LOGICAL OR ;* @@ -494,13 +433,11 @@ LOR LDA ESTKL,X ORA ESTKH,X ORA ESTKL+1,X ORA ESTKH+1,X - BEQ LOR1 + BEQ + LDA #$FF STA ESTKL+1,X STA ESTKH+1,X -;LOR1 INX -; JMP NEXTOP -LOR1 JMP DROP ++ JMP DROP ;* ;* DUPLICATE TOS ;* @@ -511,10 +448,20 @@ DUP DEX STA ESTKH,X JMP NEXTOP ;* +;* LOGICAL NOT +;* +LNOT LDA ESTKL,X + ORA ESTKH,X + BNE + + LDA #$FF + STA ESTKL,X + STA ESTKH,X + JMP NEXTOP +;* ;* CONSTANT ;* ZERO DEX - LDA #$00 ++ LDA #$00 STA ESTKL,X STA ESTKH,X JMP NEXTOP @@ -523,19 +470,34 @@ CFFB LDA #$FF CB LDA #$00 DEX STA ESTKH,X - +INC_IP + INY ;+INC_IP LDA (IP),Y STA ESTKL,X JMP NEXTOP ;* ;* LOAD ADDRESS & LOAD CONSTANT WORD (SAME THING, WITH OR WITHOUT FIXUP) ;* -LA = * -CW DEX - INY ;+INC_IP +- TYA ; RENORMALIZE IP + CLC + ADC IPL + STA IPL + BCC + + INC IPH ++ LDY #$FF +LA INY ;+INC_IP + BMI - + DEX LDA (IP),Y STA ESTKL,X - +INC_IP + INY + LDA (IP),Y + STA ESTKH,X + JMP NEXTOP +CW DEX + INY ;+INC_IP + LDA (IP),Y + STA ESTKL,X + INY LDA (IP),Y STA ESTKH,X JMP NEXTOP @@ -543,9 +505,9 @@ CW DEX ;* CONSTANT STRING ;* CS DEX - INY ;+INC_IP + ;INY ;+INC_IP TYA ; NORMALIZE IP - CLC + SEC ADC IPL STA IPL LDA #$00 @@ -609,46 +571,38 @@ _CEXS LDA (IP),Y ; SKIP TO NEXT OP ADDR AFTER STRING ;* ;* LOAD VALUE FROM ADDRESS TAG ;* -!IF SELFMODIFY { LB LDA ESTKL,X - STA LBLDA+1 - LDA ESTKH,X - STA LBLDA+2 -LBLDA LDA $FFFF + STA ESTKH-1,X + LDA (ESTKH-1,X) STA ESTKL,X LDA #$00 STA ESTKH,X JMP NEXTOP -} ELSE { -LB LDA ESTKL,X - STA TMPL - LDA ESTKH,X - STA TMPH - STY IPY - LDY #$00 - LDA (TMP),Y - STA ESTKL,X - STY ESTKH,X - LDY IPY - JMP NEXTOP -} LW LDA ESTKL,X - STA TMPL - LDA ESTKH,X - STA TMPH - STY IPY - LDY #$00 - LDA (TMP),Y + STA ESTKH-1,X + LDA (ESTKH-1,X) STA ESTKL,X - INY - LDA (TMP),Y + INC ESTKH-1,X + BEQ + + LDA (ESTKH-1,X) + STA ESTKH,X + JMP NEXTOP ++ INC ESTKH,X + LDA (ESTKH-1,X) STA ESTKH,X - LDY IPY JMP NEXTOP ;* ;* LOAD ADDRESS OF LOCAL FRAME OFFSET ;* -LLA +INC_IP +- TYA ; RENORMALIZE IP + CLC + ADC IPL + STA IPL + BCC + + INC IPH ++ LDY #$FF +LLA INY ;+INC_IP + BMI - LDA (IP),Y DEX CLC @@ -661,7 +615,7 @@ LLA +INC_IP ;* ;* LOAD VALUE FROM LOCAL FRAME OFFSET ;* -LLB +INC_IP +LLB INY ;+INC_IP LDA (IP),Y STY IPY TAY @@ -672,7 +626,7 @@ LLB +INC_IP STA ESTKH,X LDY IPY JMP NEXTOP -LLW +INC_IP +LLW INY ;+INC_IP LDA (IP),Y STY IPY TAY @@ -687,39 +641,22 @@ LLW +INC_IP ;* ;* LOAD VALUE FROM ABSOLUTE ADDRESS ;* -!IF SELFMODIFY { -LAB INY ;+INC_IP +LAB INY ;+INC_IP LDA (IP),Y - STA LABLDA+1 - +INC_IP + STA ESTKH-2,X + INY ;+INC_IP LDA (IP),Y - STA LABLDA+2 -LABLDA LDA $FFFF + STA ESTKH-1,X + LDA (ESTKH-2,X) DEX STA ESTKL,X LDA #$00 STA ESTKH,X JMP NEXTOP -} ELSE { -LAB INY ;+INC_IP +LAW INY ;+INC_IP LDA (IP),Y STA TMPL - +INC_IP - LDA (IP),Y - STA TMPH - STY IPY - LDY #$00 - LDA (TMP),Y - DEX - STA ESTKL,X - STY ESTKH,X - LDY IPY - JMP NEXTOP -} -LAW INY ;+INC_IP - LDA (IP),Y - STA TMPL - +INC_IP + INY ;+INC_IP LDA (IP),Y STA TMPH STY IPY @@ -735,56 +672,39 @@ LAW INY ;+INC_IP ;* ;* STORE VALUE TO ADDRESS ;* -!IF SELFMODIFY { SB LDA ESTKL,X - STA SBSTA+1 - LDA ESTKH,X - STA SBSTA+2 + STA ESTKH-1,X LDA ESTKL+1,X -SBSTA STA $FFFF - INX -; INX -; JMP NEXTOP - JMP DROP -} ELSE { -SB LDA ESTKL,X - STA TMPL - LDA ESTKH,X - STA TMPH - LDA ESTKL+1,X - STY IPY - LDY #$00 - STA (TMP),Y - LDY IPY + STA (ESTKH-1,X) INX JMP DROP -} SW LDA ESTKL,X - STA TMPL - LDA ESTKH,X - STA TMPH - STY IPY - LDY #$00 + STA ESTKH-1,X LDA ESTKL+1,X - STA (TMP),Y - INY + STA (ESTKH-1,X) LDA ESTKH+1,X - STA (TMP),Y - LDY IPY + INC ESTKH-1,X + BEQ + + STA (ESTKH-1,X) + INX + JMP DROP ++ INC ESTKH,X + STA (ESTKH-1,X) INX JMP DROP ;* ;* STORE VALUE TO LOCAL FRAME OFFSET ;* -SLB +INC_IP +SLB INY ;+INC_IP LDA (IP),Y STY IPY TAY LDA ESTKL,X STA (IFP),Y LDY IPY + BMI FIXDROP JMP DROP -SLW +INC_IP +SLW INY ;+INC_IP LDA (IP),Y STY IPY TAY @@ -794,11 +714,20 @@ SLW +INC_IP LDA ESTKH,X STA (IFP),Y LDY IPY + BMI FIXDROP JMP DROP +FIXDROP TYA + LDY #$00 + CLC + ADC IPL + STA IPL + BCC + + INC IPH ++ JMP DROP ;* ;* STORE VALUE TO LOCAL FRAME OFFSET WITHOUT POPPING STACK ;* -DLB +INC_IP +DLB INY ;+INC_IP LDA (IP),Y STY IPY TAY @@ -806,7 +735,7 @@ DLB +INC_IP STA (IFP),Y LDY IPY JMP NEXTOP -DLW +INC_IP +DLW INY ;+INC_IP LDA (IP),Y STY IPY TAY @@ -820,34 +749,27 @@ DLW +INC_IP ;* ;* STORE VALUE TO ABSOLUTE ADDRESS ;* -!IF SELFMODIFY { -SAB INY ;+INC_IP +- TYA ; RENORMALIZE IP + CLC + ADC IPL + STA IPL + BCC + + INC IPH ++ LDY #$FF +SAB INY ;+INC_IP + BMI - LDA (IP),Y - STA SABSTA+1 - +INC_IP + STA ESTKH-2,X + INY ;+INC_IP LDA (IP),Y - STA SABSTA+2 + STA ESTKH-1,X LDA ESTKL,X -SABSTA STA $FFFF + STA (ESTKH-2,X) JMP DROP -} ELSE { -SAB INY ;+INC_IP +SAW INY ;+INC_IP LDA (IP),Y STA TMPL - +INC_IP - LDA (IP),Y - STA TMPH - LDA ESTKL,X - STY IPY - LDY #$00 - STA (TMP),Y - LDY IPY - JMP DROP -} -SAW INY ;+INC_IP - LDA (IP),Y - STA TMPL - +INC_IP + INY ;+INC_IP LDA (IP),Y STA TMPH STY IPY @@ -858,38 +780,24 @@ SAW INY ;+INC_IP LDA ESTKH,X STA (TMP),Y LDY IPY + BMI FIXDROP JMP DROP ;* ;* STORE VALUE TO ABSOLUTE ADDRESS WITHOUT POPPING STACK ;* -!IF SELFMODIFY { -DAB INY ;+INC_IP +DAB INY ;+INC_IP LDA (IP),Y - STA DABSTA+1 - +INC_IP + STA ESTKH-2,X + INY ;+INC_IP LDA (IP),Y - STA DABSTA+2 + STA ESTKH-1,X LDA ESTKL,X -DABSTA STA $FFFF + STA (ESTKH-2,X) JMP NEXTOP -} ELSE { -DAB INY ;+INC_IP +DAW INY ;+INC_IP LDA (IP),Y STA TMPL - +INC_IP - LDA (IP),Y - STA TMPH - STY IPY - LDY #$00 - LDA ESTKL,X - STA (TMP),Y - LDY IPY - JMP NEXTOP -} -DAW INY ;+INC_IP - LDA (IP),Y - STA TMPL - +INC_IP + INY ;+INC_IP LDA (IP),Y STA TMPH STY IPY @@ -913,8 +821,6 @@ ISEQ LDA ESTKL,X ISTRU LDA #$FF STA ESTKL+1,X STA ESTKH+1,X -; INX -; JMP NEXTOP JMP DROP ; ISNE LDA ESTKL,X @@ -926,45 +832,47 @@ ISNE LDA ESTKL,X ISFLS LDA #$00 STA ESTKL+1,X STA ESTKH+1,X -; INX -; JMP NEXTOP JMP DROP ; ISGE LDA ESTKL+1,X CMP ESTKL,X LDA ESTKH+1,X SBC ESTKH,X - BVC ISGE1 - EOR #$80 -ISGE1 BPL ISTRU + BVS + + BPL ISTRU BMI ISFLS ++ BPL ISFLS + BMI ISTRU ; ISGT LDA ESTKL,X CMP ESTKL+1,X LDA ESTKH,X SBC ESTKH+1,X - BVC ISGT1 - EOR #$80 -ISGT1 BMI ISTRU + BVS + + BMI ISTRU BPL ISFLS ++ BMI ISFLS + BPL ISTRU ; ISLE LDA ESTKL,X CMP ESTKL+1,X LDA ESTKH,X SBC ESTKH+1,X - BVC ISLE1 - EOR #$80 -ISLE1 BPL ISTRU + BVS + + BPL ISTRU BMI ISFLS ++ BPL ISFLS + BMI ISTRU ; ISLT LDA ESTKL+1,X CMP ESTKL,X LDA ESTKH+1,X SBC ESTKH,X - BVC ISLT1 - EOR #$80 -ISLT1 BMI ISTRU + BVS + + BMI ISTRU BPL ISFLS ++ BMI ISFLS + BPL ISTRU ;* ;* BRANCHES ;* @@ -972,9 +880,18 @@ BRTRU INX LDA ESTKH-1,X ORA ESTKL-1,X BNE BRNCH -NOBRNCH INY ;+INC_IP - +INC_IP +NOBRNCH INY ;+INC_IP + INY ;+INC_IP + BMI FIXNEXT JMP NEXTOP +FIXNEXT TYA + LDY #$00 + CLC + ADC IPL + STA IPL + BCC + + INC IPH ++ JMP NEXTOP BRFLS INX LDA ESTKH-1,X ORA ESTKL-1,X @@ -1018,20 +935,34 @@ BRGT INX CMP ESTKL,X LDA ESTKH-1,X SBC ESTKH,X + BVS + BPL NOBRNCH BMI BRNCH ++ BPL BRNCH + BMI NOBRNCH BRLT INX LDA ESTKL,X CMP ESTKL-1,X LDA ESTKH,X SBC ESTKH-1,X + BVS + BPL NOBRNCH BMI BRNCH -IBRNCH LDA IPL ++ BPL BRNCH + BMI NOBRNCH +IBRNCH TYA ; FLATTEN IP CLC + ADC IPL + STA TMPL + LDA #$00 + TAY + ADC IPH + STA TMPH ; ADD BRANCH OFFSET + LDA TMPL + ;CLC ; BETTER NOT CARRY OUT OF IP+Y ADC ESTKL,X STA IPL - LDA IPH + LDA TMPH ADC ESTKH,X STA IPH JMP DROP @@ -1107,7 +1038,7 @@ ENTER LDA IFPH ;* ;* LEAVE FUNCTION ;* -LEAVE INY ;+INC_IP +LEAVE INY ;+INC_IP LDA (IP),Y CLC ADC IFPL