6502 wide stack

Topics relating to PALs, CPLDs, FPGAs, and other PLDs used for the support or creation of 65-family processors, both hardware and HDL.
Post Reply
valerio63
Posts: 7
Joined: 29 Nov 2017
Location: Riva del Garda (38066 TN) Italy

6502 wide stack

Post by valerio63 »

Hello

I put a my old VHDL project of a wide (16 bit) stack 6502 CPU, also I added some useful opcodes for fast contest switch, zero page relocation etc.
The CPU has binary/decimal ALU for full compatibility, I tested this CPU on several projects (on Altera Cyclone IV) as intelligent I/O coprocessor for industrial automation projects for my company.
The clock cycles needed for opcodes are almost identical to original 6502 project, some opcode need less clock cycle than original CPU.

Best Regards
Valerio Venturi
Italy
Attachments
6502 wide stack.zip
(31.68 KiB) Downloaded 268 times
User avatar
Dr Jefyll
Posts: 3526
Joined: 11 Dec 2009
Location: Ontario, Canada
Contact:

Re: 6502 wide stack

Post by Dr Jefyll »

Welcome, Valerio :)

This is a nice selection of improvements. For example the exchange instructions appeal to me -- something so simple, but so worthwhile. It's almost like having new address modes. For example, if you want (ind),X mode then just use XYZ -- ie; exchange X with Y -- and follow up by using (ind),Y mode.

Maybe you can tell us more about that I/O coprocessor, please.

-- Jeff

Code: Select all

; new V6502 opcodes macros
phr:                .macro             ;AXY->SP: push A,X,Y to stack (useful for fast context switch) 
                    .byte        $8b
                    .endm
                    
plr:                .macro             ;SP->YXA: pull A,X,Y from stack (useful for fast context switch)
                    .byte        $ab
                    .endm

taz:                .macro             ;A->Z: copy A to zero page register (MSB base address)
                    .byte        $1b
                    .endm
                    
tza:                .macro             ;Z->A: copy zero page register to A
                    .byte        $3b
                    .endm

txy:                .macro             ;X->Y: copy X to Y
                    .byte        $9b
                    .endm
                    
tyx:                .macro             ;Y->X: copy Y to X 
                    .byte        $bb
                    .endm

xyx:                .macro             ;X<->Y: exchange X with Y 
                    .byte        $eb
                    .endm

xax:                .macro             ;A<->X: exchange A with X
                    .byte        $0b
                    .endm

xay:                .macro             ;A<->Y: exchange A with Y
                    .byte        $2b
                    .endm

isp:                .macro             ;X -> S (lsb); A -> S msb: copy X and A to S (16 bit stack pointer)
                    .byte        $4b
                    .endm

tsp:                .macro             ;S lsb -> X; S msb -> A: copy S to X and A 
                    .byte        $5b
                    .endm

                    
jsrx:               .macro       arg1  ;JSR ($XXXX,X) jump vector table indexed by X
                    .byte        $fc
                    .word        arg1
                    .endm
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
valerio63
Posts: 7
Joined: 29 Nov 2017
Location: Riva del Garda (38066 TN) Italy

Re: 6502 wide stack

Post by valerio63 »

Hello Jeff

I am sorry for delay to answer you but I was very busy, I used the V6502 as I/O coprocessor (or slave CPU) to help main CPU (PowerPC MPC5200) to execute several high speed tasks such intelligent DMA controller, several I2C and SPI interfaces, one CAN bus, incremental encoders, and some discrete I/Os, all of these devices was included in a large FPGA project. Also the ROM and SRAM for the V6502 was included in the FPGA and the main CPU could update "on fly" the software via a simple I2C bus. The main board project was a real time controller for robotic systems.
I choosed the 6502 due to his high deterministic architecture, and also for his speed to execute simple tasks, (the CPU clock was 50 MHZ and the preemptive multitasking interrupt ran at 10 KHZ, 100 microseconds per task).
Today the project is almost obsolete and we moved to a new ARM architecture.

-- Valerio
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: 6502 wide stack

Post by barrym95838 »

valerio63 wrote:
Today the project is almost obsolete and we moved to a new ARM architecture.
Thankfully, your robot didn't have an ego, because it would have taken a serious hit.

Mike B.
valerio63
Posts: 7
Joined: 29 Nov 2017
Location: Riva del Garda (38066 TN) Italy

Re: 6502 wide stack

Post by valerio63 »

.....the destiny of everyone (even the robots) is to become obsolete....:)
valerio63
Posts: 7
Joined: 29 Nov 2017
Location: Riva del Garda (38066 TN) Italy

Re: 6502 wide stack

Post by valerio63 »

Hello

i posted an example of multitasking source code for V6502
Attachments
v6502_multitasking.asm
(12.72 KiB) Downloaded 250 times
valerio63
Posts: 7
Joined: 29 Nov 2017
Location: Riva del Garda (38066 TN) Italy

Re: 6502 wide stack

Post by valerio63 »

I added a PDF file that shows the improvements of V6502
Attachments
V6502WS.pdf
(58.19 KiB) Downloaded 261 times
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: 6502 wide stack

Post by BigEd »

Thanks!

As an aside, this note is interesting:
Quote:
Unlike 65C02 the RES input cannot be used as additional interrupt request signal...
We did discuss that here - it seems the early 'C02s did write to stack during reset, but the later 'C02s from WDC do not...

Having RTI pull the Z register could break some existing software, but I see why it's useful. A tradeoff!
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: 6502 wide stack

Post by barrym95838 »

Updated version here:

viewtopic.php?f=10&t=5026

Mike B.
Post Reply