From 1d88369ae0f1026e588fa64f6af79009e74c748f Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Tue, 16 Jan 2024 20:55:27 -0800 Subject: [PATCH] Call bytecode routines whithin VM16 to avoid stack conversion --- src/makefile | 4 +- src/vmsrc/apple/cmd.pla | 2 +- src/vmsrc/apple/cmdjit.pla | 2 +- src/vmsrc/apple/plvm802.s | 150 ++++++++++++++++++++++++++-------- src/vmsrc/apple/soscmd.pla | 4 +- src/vmsrc/apple/soscmdjit.pla | 4 +- 6 files changed, 125 insertions(+), 41 deletions(-) diff --git a/src/makefile b/src/makefile index 73206e5..d05ebde 100755 --- a/src/makefile +++ b/src/makefile @@ -175,13 +175,13 @@ $(PLVMZP_APL): FORCE -mkdir -p rel -mkdir -p rel/apple -rm -f vmsrc/plvmzp.inc - -ln -s apple/plvmzp.inc vmsrc/plvmzp.inc + -cp vmsrc/apple/plvmzp.inc vmsrc/plvmzp.inc $(PLVMZP_C64): FORCE -mkdir -p rel -mkdir -p rel/c64 -rm -f vmsrc/plvmzp.inc - -ln -s c64/plvmzp.inc vmsrc/plvmzp.inc + -cp vmsrc/c64/plvmzp.inc vmsrc/plvmzp.inc FORCE: diff --git a/src/vmsrc/apple/cmd.pla b/src/vmsrc/apple/cmd.pla index 673d532..9f8e4e2 100755 --- a/src/vmsrc/apple/cmd.pla +++ b/src/vmsrc/apple/cmd.pla @@ -1393,7 +1393,7 @@ loop // // Set system path // -strcat(strcpy(@sysmods, $300), "SYS/")) // This is the path to CMD +strcat(strcpy(@sysmods, $300), "SYS/") // This is the path to CMD syspath = @sysmods // Update external interface table syscmdln = @cmdln // diff --git a/src/vmsrc/apple/cmdjit.pla b/src/vmsrc/apple/cmdjit.pla index 63ac8b9..ffdc997 100755 --- a/src/vmsrc/apple/cmdjit.pla +++ b/src/vmsrc/apple/cmdjit.pla @@ -1468,7 +1468,7 @@ loop // // Set system path // -strcat(strcpy(@sysmods, $300), "SYS/")) // This is the path to CMD +strcat(strcpy(@sysmods, $300), "SYS/") // This is the path to CMD syspath = @sysmods // Update external interface table syscmdln = @cmdln // diff --git a/src/vmsrc/apple/plvm802.s b/src/vmsrc/apple/plvm802.s index bc36435..f6a6078 100644 --- a/src/vmsrc/apple/plvm802.s +++ b/src/vmsrc/apple/plvm802.s @@ -51,6 +51,9 @@ ALTWRON = $C005 !SOURCE "vmsrc/plvmzp.inc" PSR = TMP+2 HWSP = PSR+1 +VM16SP = HWSP+1 +VM16RETX = VM16SP+1 +VM16RETIP= VM16RETX+1 DROP = $EF NEXTOP = DROP+1 FETCHOP = NEXTOP+1 @@ -378,17 +381,24 @@ CMDENTRY = * ; ; INIT VM ENVIRONMENT STACK POINTERS ; -; LDA #$00 - STA $01FF ; CLEAR CMDLINE BUFF - STA PPL ; INIT FRAME POINTER - STA IFPL + STZ $01FF ; CLEAR CMDLINE BUFF + STZ PPL ; INIT FRAME POINTER + STZ IFPL LDA #$AF ; FRAME POINTER AT $AF00, BELOW JIT BUFFER STA PPH STA IFPH LDX #$FE ; INIT STACK POINTER (YES, $FE. SEE GETS) TXS + INX + STX VM16SP ; INIT VM16 RETURN STACK POINTER LDX #ESTKSZ/2 ; INIT EVAL STACK INDEX ; +; CLEAR VM16 RETURN IP +; + STZ VM16RETX + STZ VM16RETIP + STZ VM16RETIP+1 +; ; CHANGE CMD STRING TO SYSPATH STRING ; LDA STRBUF @@ -531,7 +541,7 @@ JITINTRPX PHP STA ESTKH,X JSR JMPTMP !AS ; RETURN IN EMULATION MODE - PLA + PLA STA TMPL PLA STA TMPH @@ -611,31 +621,6 @@ _MULSLP ASL BNE _MULSLP STA NOS,S ; PROD JMP DROP -;MUL LDX #$04 -; LDA NOS,S -; EOR #$FFFF -; STA TMP -; LDA #$0000 -;_MULLP ASL -; ASL TMP ; MULTPLR -; BCS + -; ADC TOS,S ; MULTPLD -;+ ASL -; ASL TMP ; MULTPLR -; BCS + -; ADC TOS,S ; MULTPLD -;+ ASL -; ASL TMP ; MULTPLR -; BCS + -; ADC TOS,S ; MULTPLD -;+ ASL -; ASL TMP ; MULTPLR -; BCS + -; ADC TOS,S ; MULTPLD -;+ DEX -; BNE _MULLP -; STA NOS,S ; PROD -; JMP DROP ;* ;* INTERNAL DIVIDE ALGORITHM ;* @@ -1582,6 +1567,19 @@ EMUSTK STA TMP SEC ADC IP STA IP + LDA (TMP) ; CHECK IF FIRST OPCODE IS JSR TO $XXDX + AND #$F3FF + CMP #$D020 + BNE + + LDY #$01 ; VERIFY JSR ADDRESS AS VM ENTRYPOINT + LDA (TMP),Y + CMP #$03D0 + BEQ CALL16 + CMP #$03DC + BEQ XCALL16 ++ JSR PUSHVM16 ; SAVE CURRENT VM16 RETURN ADDRESS + STZ VM16RETX ; CLEAR RETURN ADDRESS + STZ VM16RETIP SEC ; SWITCH TO EMULATION MODE XCE !AS @@ -1629,11 +1627,43 @@ EMUSTK STA TMP PHY CPX ESP BNE - -+ LDX #>OPTBL ; MAKE SURE WE'RE INDEXING THE RIGHT TABLE ++ JSR POPVM16 ; RESTORE VM16 RETURN ADDRESS + LDX #>OPTBL ; MAKE SURE WE'RE INDEXING THE RIGHT TABLE STX OPPAGE LDY #$00 JMP FETCHOP ;* +;* QUICK CALL TO VM16 FUNCTION +;* +CALL16 JSR PUSHVM16 + LDX OPPAGE + STX VM16RETX + LDA IP + STA VM16RETIP + LDA TMP ; BYTECODE DIRECTLY FOLLOWS JSR DINTERP + CLC + ADC #$0003 + STA IP + LDX #>OPTBL ; MAKE SURE WE'RE INDEXING THE RIGHT TABLE + STX OPPAGE + STX ALTRDOFF + LDY #$00 + JMP FETCHOP +XCALL16 JSR PUSHVM16 + LDX OPPAGE + STX VM16RETX + LDA IP + STA VM16RETIP + STX ALTRDOFF + LDY #$03 + LDA (TMP),Y ; BYTECODE ADDRESS FOLLOWS JSR IINTERP IN DEF STRUCTURE + STA IP + LDX #>OPXTBL ; MAKE SURE WE'RE INDEXING THE RIGHT TABLE + STX OPPAGE + STX ALTRDON + LDY #$00 + JMP FETCHOP +;* ;* INDIRECT CALL TO ADDRESS (NATIVE CODE) ;* ICALX PLA @@ -1649,6 +1679,19 @@ EMUSTKX STA TMP SEC ADC IP STA IP + LDA (TMP) ; CHECK IF FIRST OPCODE IS JSR TO $XXDX + AND #$F0FF + CMP #$D020 + BNE + + LDY #$01 ; VERIFY JSR ADDRESS AS VM ENTRYPOINT + LDA (TMP),Y + CMP #$03D0 + BEQ CALL16 + CMP #$03DC + BEQ XCALL16 ++ JSR PUSHVM16 ; SAVE CURRENT VM16 RETURN ADDRESS + STZ VM16RETX ; CLEAR RETURN ADDRESS + STZ VM16RETIP SEC ; SWITCH TO EMULATION MODE XCE !AS @@ -1697,7 +1740,8 @@ EMUSTKX STA TMP PHY CPX ESP BNE - -+ STX ALTRDON ++ JSR POPVM16 ; RESTORE VM16 RETURN ADDRESS + STX ALTRDON LDX #>OPXTBL ; MAKE SURE WE'RE INDEXING THE RIGHT TABLE STX OPPAGE LDY #$00 @@ -1749,7 +1793,18 @@ LEAVE INY ;+INC_IP LDA (IFP),Y ; RESTORE PREVIOUS FRAME STA IFP RET STX ALTRDOFF - SEC ; SWITCH TO EMULATION MODE + LDA VM16RETIP + BEQ ++ + STA IP + LDX VM16RETX + STX OPPAGE + CPX #>OPXTBL ; CHECK IF AUXMEM NEEDS READ ENABLING + BNE + + STX ALTRDON ++ JSR POPVM16 ; RESTORE VM16 RETURN ADDRESS FOR CALLING FUNCTION + LDY #$00 + JMP FETCHOP +++ SEC ; SWITCH TO EMULATION MODE XCE !AS TSC ; MOVE HW EVAL STACK TO ZP EVAL STACK @@ -1797,5 +1852,34 @@ JUMP INY STA IP LDY #$00 JMP FETCHOP +;* +;* RETURN ADDRESS STACK FOR 16 BIT VM CALL/RETURN +;* +PUSHVM16 LDX VM16SP + DEX + DEX + DEX + LDY LCRWEN+LCBNK2 ; MAKE SURE LANGUAGE CARD IS WRITEABLE + LDY LCRWEN+LCBNK2 + LDA VM16RETX ; CAREFUL, PUSHING 8 BIT VALUE AS 16, BUT MSB OVERWRITTEN NEXT + STA VM16STACK+1,X + LDA VM16RETIP + STA VM16STACK+2,X + STX VM16SP + RTS +POPVM16 LDX VM16SP + LDY VM16STACK+1,X + STY VM16RETX + LDA VM16STACK+2,X + STA VM16RETIP + INX + INX + INX + STX VM16SP + RTS +VM16STACK = * +;* +;* SPACE FOR STACK FOLLOWS +;* VMEND = * } diff --git a/src/vmsrc/apple/soscmd.pla b/src/vmsrc/apple/soscmd.pla index 46f805c..869fd17 100755 --- a/src/vmsrc/apple/soscmd.pla +++ b/src/vmsrc/apple/soscmd.pla @@ -181,7 +181,7 @@ def shell#1 // // Handle commands. // - getpfx(@prefix)) + getpfx(@prefix) repeat if ^cmdptr when toupper(parsecmd(cmdptr)) @@ -206,7 +206,7 @@ def shell#1 break is 'S' setpfx(cmdptr) - strcat(getpfx(cmdsys:syspath), "SYS/")) + strcat(getpfx(cmdsys:syspath), "SYS/") break is 'V' volumes diff --git a/src/vmsrc/apple/soscmdjit.pla b/src/vmsrc/apple/soscmdjit.pla index 41d1d16..1ad0e56 100755 --- a/src/vmsrc/apple/soscmdjit.pla +++ b/src/vmsrc/apple/soscmdjit.pla @@ -256,7 +256,7 @@ def shell#1 // // Handle commands. // - getpfx(@prefix)) + getpfx(@prefix) repeat if ^cmdptr when toupper(parsecmd(cmdptr)) @@ -281,7 +281,7 @@ def shell#1 break is 'S' setpfx(cmdptr) - strcat(getpfx(cmdsys:syspath), "SYS/")) + strcat(getpfx(cmdsys:syspath), "SYS/") break is 'V' volumes