M65C02A Forth VM Support
Posted: Tue Aug 26, 2014 5:31 pm
This post will describe some planned enhancements to the M65C02A core. These planned enhancements, beyond those already implemented, have the objective to enable the efficient implementation of a Forth VM on the M65C02A core. The overarching goal is to maintain binary compatibility with 6502/65C02 processors such as the W65C02S, unlike the R65C19/29/39 microprocessors. That is, no fundamental changes to the standard instructions will be considered. I think that it is important to be able to execute any existing code that does not take advantage of, or depend in any way on the behavior, of the unimplemented instructions. All M65C02A enhancements will be implemented using the unimplemented opcodes of the W65C02S microprocessor.
First, I have begun adding the address mode modification prefix instruction, IND, to the core. It is expected to allow the programmer to specify indirect addressing for those instruction not already supporting indirect addressing. For example, instructions such as TSB zp, TRB zp, BIT zp, INC zp, etc., if preceded by the IND prefix instruction would be converted to TSB (zp), TRB (zp), BIT (zp), INC (zp), etc. Application of the IND prefix instruction to the absolute address mode of these instructions would generate TSB (abs), TRB (abs), etc. A fairly simple modification to the microprogram controller (MPC) or microprogram sequencer (MPS) allows the address mode modification feature to be easily added to M65C0A instruction set.
Second, I have also have plans to support a SIZ prefix instruction which would convert an operation from 8-bits to 16-bits. Unlike the IND prefix instruction, supporting both 8-bit and 16-bit operations will require some changes to the registers and the addition of some logic to the ALU which can be used to use an 8-bit ALU to perform cascaded operations when performing 16-bit operations. Rather than extending the width of the ALU, since the external bus width is not changing, the plan is to perform two cascaded 8-bit operations when the SIZ prefix precedes an ALU instruction. At this time, SIZ is expected to be allowed for the following operations: ORA/AND/EOR/ADC/STA/LDA/CMP/SBC/INC/DEC/ASL/ROL/LSR/ROR. I am also thinking about extending X and Y to 16 bits. If that happens, then SIZ would be allowed for the X and Y specific instructions as well.
Third, I am also considering how to change the destination register for some instructions: ORA/AND/EOR/ADC/STA/LDA/CMP/SBC/INC/DEC/ASL/ROL/LSR/ROR. Specifically, I am looking into the possibility of allowing these instructions to be applied directly to X and Y. As part of these ruminations, I am looking at how to implement X and Y as stack pointers so that the stack operations can be performed using S, X, and Y.
I think that I've worked out how to implement a single instruction Next, NXT, that will support a direct threaded Forth. Without implementing any new internal registers, I think that I can implement a DTC Next using the currently available registers in the M65C02A ALU and Address Generator. The Interpretive Pointer (IP) would be specified by any pair of page zero locations.
As I've worked it out, NXT zp, would perform the DTC operation JMP (IP++) in approximately 8 clock cycles. I've looked around, and I have not been able to determine if the cycle count for Next is reasonable. Does anyone have a DTC Next implemented for the 65C02 that they'd be willing to share?
First, I have begun adding the address mode modification prefix instruction, IND, to the core. It is expected to allow the programmer to specify indirect addressing for those instruction not already supporting indirect addressing. For example, instructions such as TSB zp, TRB zp, BIT zp, INC zp, etc., if preceded by the IND prefix instruction would be converted to TSB (zp), TRB (zp), BIT (zp), INC (zp), etc. Application of the IND prefix instruction to the absolute address mode of these instructions would generate TSB (abs), TRB (abs), etc. A fairly simple modification to the microprogram controller (MPC) or microprogram sequencer (MPS) allows the address mode modification feature to be easily added to M65C0A instruction set.
Second, I have also have plans to support a SIZ prefix instruction which would convert an operation from 8-bits to 16-bits. Unlike the IND prefix instruction, supporting both 8-bit and 16-bit operations will require some changes to the registers and the addition of some logic to the ALU which can be used to use an 8-bit ALU to perform cascaded operations when performing 16-bit operations. Rather than extending the width of the ALU, since the external bus width is not changing, the plan is to perform two cascaded 8-bit operations when the SIZ prefix precedes an ALU instruction. At this time, SIZ is expected to be allowed for the following operations: ORA/AND/EOR/ADC/STA/LDA/CMP/SBC/INC/DEC/ASL/ROL/LSR/ROR. I am also thinking about extending X and Y to 16 bits. If that happens, then SIZ would be allowed for the X and Y specific instructions as well.
Third, I am also considering how to change the destination register for some instructions: ORA/AND/EOR/ADC/STA/LDA/CMP/SBC/INC/DEC/ASL/ROL/LSR/ROR. Specifically, I am looking into the possibility of allowing these instructions to be applied directly to X and Y. As part of these ruminations, I am looking at how to implement X and Y as stack pointers so that the stack operations can be performed using S, X, and Y.
I think that I've worked out how to implement a single instruction Next, NXT, that will support a direct threaded Forth. Without implementing any new internal registers, I think that I can implement a DTC Next using the currently available registers in the M65C02A ALU and Address Generator. The Interpretive Pointer (IP) would be specified by any pair of page zero locations.
As I've worked it out, NXT zp, would perform the DTC operation JMP (IP++) in approximately 8 clock cycles. I've looked around, and I have not been able to determine if the cycle count for Next is reasonable. Does anyone have a DTC Next implemented for the 65C02 that they'd be willing to share?