Raspberry Pi Pico 6502 emulator
Raspberry Pi Pico 6502 emulator
I recently received a few raspberry pi picos!
My original idea was to use one of them as a VGA output for my 6502 computer, but that did not really work out.
So I took a different tack about what to do with them and decided to run a 6502 emulator. The I/O is very simple and goes through the Pico's USB to serial capability.
For the emulation code, I started out with this and added support for 65C02 instructions to be able to run Taliforth on it. You can also choose to run it in 6502 mode by changing one #define statement.
It passes all of Klaus Dorman's 65C02 test suite.
I then added 6522 support from this repository.
And putting it on a breadboard, we get some blinkenlights !
While running the tests, I get about 3.1 MHz of emulated speed if I overclock the Pico to 280 Mhz. That seems fairly slow, so I've been looking at Daryl's code for an ARM assembly 6502 emulator. I have absolutely no experience in ARM assembly though, so it will be a while before I can try and rewrite the emulator in ARM assembly that is compatible with the RP2040 microcontroller... If we go by Daryl's result (ARM: 900 MHz -> 6502: 97MHz) I should be able get more than 25 MHz 6502 emulated speed out of the Pico!
Here is the github repo if anyone is interested : https://github.com/jfoucher/pico-6502
My original idea was to use one of them as a VGA output for my 6502 computer, but that did not really work out.
So I took a different tack about what to do with them and decided to run a 6502 emulator. The I/O is very simple and goes through the Pico's USB to serial capability.
For the emulation code, I started out with this and added support for 65C02 instructions to be able to run Taliforth on it. You can also choose to run it in 6502 mode by changing one #define statement.
It passes all of Klaus Dorman's 65C02 test suite.
I then added 6522 support from this repository.
And putting it on a breadboard, we get some blinkenlights !
While running the tests, I get about 3.1 MHz of emulated speed if I overclock the Pico to 280 Mhz. That seems fairly slow, so I've been looking at Daryl's code for an ARM assembly 6502 emulator. I have absolutely no experience in ARM assembly though, so it will be a while before I can try and rewrite the emulator in ARM assembly that is compatible with the RP2040 microcontroller... If we go by Daryl's result (ARM: 900 MHz -> 6502: 97MHz) I should be able get more than 25 MHz 6502 emulated speed out of the Pico!
Here is the github repo if anyone is interested : https://github.com/jfoucher/pico-6502
Re: Raspberry Pi Pico 6502 emulator
Bravo! (And thanks for the various links - I do like a well-linkified post.)
Re: Raspberry Pi Pico 6502 emulator
You might like to check out my 6502 core for the BBC tube interface.
https://github.com/dp111/PicoTube
https://github.com/dp111/PicoTube
Re: Raspberry Pi Pico 6502 emulator
Wow, yeah that looks great dp11, will definitely try to integrate your 6502 core. Thanks !
Re: Raspberry Pi Pico 6502 emulator
Thanks Dominic! I note with amusement that there are vestiges in there of my a6502 emulator, written for a different flavour of ARM and based on Chris Baird's work and, IIRC, Ian Piumarta's and Acorn's ideas.
I mention this partly because searching for a6502 here leads to some previous threads where we discuss performance of emulator code, for example:
emulator performance on embedded cpu
which sets an expectation of a 10x ratio.
It's a good thing to experiment with, emulation of 6502 on ARM, as there's lots of solution space to explore.
I mention this partly because searching for a6502 here leads to some previous threads where we discuss performance of emulator code, for example:
emulator performance on embedded cpu
which sets an expectation of a 10x ratio.
It's a good thing to experiment with, emulation of 6502 on ARM, as there's lots of solution space to explore.
Re: Raspberry Pi Pico 6502 emulator
Thank you. What a great reason to buy a pico!
In theory, there is no difference between theory and practice. In practice, there is. ...Jan van de Snepscheut
Re: Raspberry Pi Pico 6502 emulator
Dominic, I am integrating your 6502 core and trying to get it to run the 6502 tests. However I cannot for the life of me get it to pass the full test suite. It hangs while doing the second BRK test. Is the core supposed to pass a test suite ?
If it does, then do I need anything outside of the core itself to handle the BRK instruction ?
Thanks.
If it does, then do I need anything outside of the core itself to handle the BRK instruction ?
Thanks.
Re: Raspberry Pi Pico 6502 emulator
I have changed many things on what I do on the pico, it now runs a simplified VIc-20 emulator using Dominic’s 6502 core. The Vic chip is extremely simplified and most registers don’t do anything. The vias are not emulated. All this in the interest of speed and laziness. ATM it runs at around 3-4 MHz
Also the colors and the screen scaling are all wrong but at least it runs basic!
Also the colors and the screen scaling are all wrong but at least it runs basic!
Last edited by jfoucher on Fri Jul 09, 2021 12:38 pm, edited 1 time in total.
- fredericsegard
- Posts: 47
- Joined: 05 Aug 2020
- Location: Montreal, QC, Canada
- Contact:
Re: Raspberry Pi Pico 6502 emulator
That is a fascinating experiment, jfoucher. 3.1MHz is a decent speed on an emulated microcontroller, I suppose.
Re: Raspberry Pi Pico 6502 emulator
Sorry for the delay. I was pretty sure the core passed the tests. I'll take a look next week.
Re: Raspberry Pi Pico 6502 emulator
dp11 wrote:
Sorry for the delay. I was pretty sure the core passed the tests. I'll take a look next week.
Re: Raspberry Pi Pico 6502 emulator
Just to check I'm see what you are seeing can you let me know the error output ?
Re: Raspberry Pi Pico 6502 emulator
Here are the last few lines of output with TRACE_6502 enabled :
Here is the last line
Hope that helps
Code: Select all
2701 7c f9 02 f2 06 46 ed ff
16ce 08 88 88 f2 06 46 ed ff
16cf 88 88 88 f2 06 46 ed fe
16d0 88 88 28 f2 06 45 6d fe
16d1 88 28 f0 f2 06 44 6d fe
16d2 28 f0 fe f2 06 43 6d fe
16d3 f0 fe 10 f2 06 43 ed ff
16d5 10 fe 90 f2 06 43 ed ff
16d7 90 fe 50 f2 06 43 ed ff
16d9 50 fe c9 f2 06 43 ed ff
16db c9 f2 d0 f2 06 43 ed ff
16dd d0 fe e0 f2 06 43 6f ff
16df e0 06 d0 f2 06 43 6f ff
16e1 d0 fe c0 f2 06 43 6f ff
16e3 c0 43 d0 f2 06 43 6f ff
16e5 d0 fe ba f2 06 43 6f ff
16e7 ba e0 ff f2 06 43 6f ff
16e8 e0 ff d0 f2 ff 43 ed ff
16ea d0 fe a9 f2 ff 43 6f ff
16ec a9 08 8d f2 ff 43 6f ff
16ee 8d 00 03 08 ff 43 6d ff
16f1 a9 17 8d 08 ff 43 6d ff
16f3 8d 01 03 17 ff 43 6d ff
16f6 a9 05 8d 17 ff 43 6d ff
16f8 8d 00 02 05 ff 43 6d ff
16fb a9 17 8d 05 ff 43 6d ff
16fd 8d 01 02 17 ff 43 6d ff
1700 a2 ff 7c 17 ff 43 6d ff
1702 7c 01 02 17 ff 43 ed ff
1708 ad 02 02 17 ff 43 ed ff
170b c9 0a d0 0a ff 43 6d ff
170d d0 fe a9 0a ff 43 6f ff
170f a9 0b 8d 0a ff 43 6f ff
1711 8d 02 02 0b ff 43 6d ff
1714 a9 00 48 0b ff 43 6d ff
1716 48 a9 42 00 ff 43 6f ff
1717 a9 42 a2 00 ff 43 6f fe
1719 a2 52 a0 42 ff 43 6d fe
171b a0 4b 28 42 52 43 6d fe
171d 28 00 88 42 52 4b 6d fe
171e 00 88 08 42 52 4b 20 ff
2724 08 88 88 42 52 4b 24 fc
2725 88 88 88 42 52 4b 24 fb
2726 88 88 c9 42 52 4a 24 fb
2727 88 c9 bd 42 52 49 24 fb
2728 c9 bd f0 42 52 48 24 fb
272a f0 42 c9 42 52 48 a4 fb
272c c9 42 d0 42 52 48 a4 fb
272e d0 fe e0 42 52 48 27 fb
2730 e0 52 d0 42 52 48 27 fb
2732 d0 fe c0 42 52 48 27 fb
2734 c0 48 d0 42 52 48 27 fb
2736 d0 fe 85 42 52 48 27 fb
2738 85 0a 86 42 52 48 27 fb
273a 86 0b ba 42 52 48 27 fb
273c ba bd 02 42 52 48 27 fb
273d bd 02 01 42 fb 48 a5 fb
2740 c9 30 d0 30 fb 48 25 fb
2742 d0 fe 68 30 fb 48 27 fb
2744 68 c9 34 30 fb 48 27 fb
2745 c9 34 d0 34 fb 48 25 fc
2747 d0 fe ba 34 fb 48 27 fc
2749 ba e0 fc 34 fb 48 27 fc
274a e0 fc d0 34 fc 48 a5 fc
274c d0 fe ad 34 fc 48 27 fc
274e ad ff 01 34 fc 48 27 fc
2751 c9 17 d0 17 fc 48 25 fc
2753 d0 fe ad 17 fc 48 27 fc
2755 ad fe 01 17 fc 48 27 fc
2758 c9 20 d0 20 fc 48 25 fc
275a d0 fe a9 20 fc 48 27 fc
275c a9 ff 48 20 fc 48 27 fc
275e 48 a6 0b ff fc 48 a5 fc
275f a6 0b e8 ff fc 48 a5 fb
2761 e8 a5 0a ff 52 48 25 fb
2762 a5 0a 49 ff 53 48 25 fb
2764 49 aa 28 42 53 48 25 fb
2766 28 40 4c e8 53 48 a5 fb
2767 40 4c 68 e8 53 48 ef fc
1720 08 88 88 e8 53 48 20 ff
1721 88 88 88 e8 53 48 20 fe
1722 88 88 c9 e8 53 47 20 fe
1723 88 c9 e8 e8 53 46 20 fe
1724 c9 e8 d0 e8 53 45 20 fe
1726 d0 fe e0 e8 53 45 23 fe
1728 e0 53 d0 e8 53 45 23 fe
172a d0 fe c0 e8 53 45 23 fe
172c c0 45 d0 e8 53 45 23 fe
172e d0 fe 68 e8 53 45 23 fe
1730 68 c9 30 e8 53 45 23 fe
1731 c9 30 d0 30 53 45 21 ff
1733 d0 fe ba 30 53 45 23 ff
1735 ba e0 ff 30 53 45 23 ff
1736 e0 ff d0 30 ff 45 a1 ff
1738 d0 fe a9 30 ff 45 23 ff
173a a9 ff 48 30 ff 45 23 ff
173c 48 a9 bd ff ff 45 a1 ff
173d a9 bd a2 ff ff 45 a1 fe
173f a2 ad a0 bd ff 45 a1 fe
1741 a0 b4 28 bd ad 45 a1 fe
1743 28 00 88 bd ad b4 a1 fe
1744 00 88 08 bd ad b4 ef ff
2724 08 88 88 bd ad b4 a7 fc
2725 88 88 88 bd ad b4 a7 fb
2726 88 88 c9 bd ad b3 a5 fb
2727 88 c9 bd bd ad b2 a5 fb
2728 c9 bd f0 bd ad b1 a5 fb
272a f0 42 c9 bd ad b1 27 fb
276e e0 ad d0 bd ad b1 27 fb
2770 d0 fe c0 bd ad b1 27 fb
2772 c0 b1 d0 bd ad b1 27 fb
2774 d0 fe 85 bd ad b1 27 fb
2776 85 0a 86 bd ad b1 27 fb
2778 86 0b ba bd ad b1 27 fb
277a ba bd 02 bd ad b1 27 fb
277b bd 02 01 bd fb b1 a5 fb
277e c9 ff d0 ff fb b1 a5 fb
2780 d0 fe 68 ff fb b1 27 fb
2782 68 c9 f7 ff fb b1 27 fb
2783 c9 f7 d0 b7 fb b1 a5 fc
2785 d0 fe ba b7 fb b1 a4 fc
2785 d0 fe ba b7 fb b1 a4 fc
.... ForeverHope that helps
Re: Raspberry Pi Pico 6502 emulator
Just a guess from quickly looking at the code, but is the BRK instruction indevertantly clearing the V flag?
I think this line needs to preserve the V Flag (bit 6) in rPbyteLo
https://github.com/dp111/PicoTube/blob/ ... mM0.S#L395
This would also effect IRQ and NMI interrupts.
Dave
I think this line needs to preserve the V Flag (bit 6) in rPbyteLo
https://github.com/dp111/PicoTube/blob/ ... mM0.S#L395
This would also effect IRQ and NMI interrupts.
Dave
Re: Raspberry Pi Pico 6502 emulator
hoglet wrote:
I think this line needs to preserve the V Flag (bit 6) in rPbyteLo