Go Down

Topic: Arduino 6502 emulator + BASIC interpreter (Read 85567 times) previous topic - next topic


I have used an Xacto knife before to cut (scrape) the encasement enough to solder a wire to a broken leg.  After ensuring a connection, coat with a drop of fast set epoxy.


I know Ray, been there before. :)

That's why I said I shouldn't be doing things like that?


I'm not the only one! Back when any IC was quite expensive, especially when my only income was mowing lawns, I had to repair IC legs a few times.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - tinyurl.com/q7uqnvn
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts


Hi. Can somone please post the complete code (if without the roms is will still be ok) of the serial version (from pito)?

thx, Peter


Feb 26, 2015, 09:53 pm Last Edit: Mar 01, 2015, 02:22 pm by pito
Enclosed pls find the serial version.

It works with a terminal, ie. Teraterm, 40x25 char. It is an extremely simple emulation of a video output and keyboard input, with no graphics, etc.

Worked here with Fubarino SD (pic32MX) and the newest Majenko's SDZL board (pic32MZ).

It runs the trigonometric demo in 12secs with pic32MZ @200MHz (or 5secs at 921k6 serial).

It may work with atmega1284p (yes it worked) or DUE (etc.), but you have to adjust the ram sizes in both files.

Caps Lock must be ON on your keyboard when writing Basic programs in the emulator.


@pito: thx. I can confirm, it works also with arduino due.

Code: [Select]
arduino_6502_pic_C64_OK.cpp.o: warning: definition of `RAM' overriding common
cpu1.c.o: warning: common is here

Der Sketch verwendet 33.628 Bytes (6%) des Programmspeicherplatzes. Das Maximum sind 524.288 Bytes.
Erase flash
Write 34764 bytes to flash

runs just fine.
On Mega, even with just 4096 bytes ram, 21k on variable space is missing.



Tested on a Stellaris Launchpad using Energia, works great. Just changed the memory size to 16kb for testing, Because the Stellaris has only 32KB of RAM. This blew my mind (now I will no sleep tonight thinking in this hehehe). Anyways, Does anybody think about an Atari 2600 emu based on an Arduino? May be using another chip for audio/video


I have Leonardo set up to write to the keyboard of my laptop, but it will stop working when i have nes emulator running.

Any idea of an easy way to make those keypresses work on nes emulator?


Aug 15, 2015, 08:41 pm Last Edit: Aug 15, 2015, 08:42 pm by NardJ
Did anyone try this on an esp8266? (26-80Mhz, 32kB, $4)

Specs: http://www.esp8266.com/viewtopic.php?f=5&t=3081



Ok, i tried this myself. I had to remove all progmen references because esp8266 doesn't seem to handle this. It still runs on my pro mini, but on an esp8266-01, I get the following error on upload: '.text' will not fit in region íram_0_seq'. I suspect this means that there is not enough memory, but can't understand why, the esp8266-01 should have 512kb. If I reduce the rom table to 2 bytes the error persists. If I reduce the program code the error vanishes.

I have posted an question on the esp8266.com forum for help and am hoping I have to use some specific esp command to load the sketch in the correct memory-part.


The original code (message 1 of this thread) works on esp8266!  :)

All credits go to martinayotte! esp8266 forum - explanation and sourcecode

Code: [Select]
Starting 6502 CPU...

6502 EhBASIC [C]old/[W]arm ?

Memory size ?

34047 Bytes free

Enhanced BASIC 2.22

FOR I=1 TO 10000:NEXT I


I did a speed test using "FOR I=1 TO 10000:NEXT I".The esp8266 finished in 15 seconds on 80 Mhz, and in 8 seconds on 160 Mhz! So this makes the esp8266 emulate an 1,13Mhz 6502. Haven't looked into the code optimization performed after message 1 of this thread, so could become even faster!

Furthermore the internal memory of the esp8266 makes it possible to allocate 32kB in code. (change "#define RAM_SIZE 1536" in cpu.cpp to "#define RAM_SIZE 34816")

This could be the base for a very cheap C64. I found some internet posts which claim that with an esp-12 it should be possible to get some sort of ISP interface. So using this to interface to 2x 32k256 chips (3.3V same as esp8266) we have 64kB. Another pin to input a ps/2 keyboard and a pin to output video commands (to another 8266 to off-load the 6502 emulator ) and we have a <$10 C64!


And I got Pito's code for the Pic32 working on an esp2866-01. Since the rom is bigger, a little bit less memory remains. The speed is still about 112% that of an real C64. See attachement for code.

Code: [Select]

    **** COMMODORE 64 BASIC V2 ****


FOR I=1 TO 10000:NEXT I



Sep 29, 2015, 06:25 pm Last Edit: Sep 29, 2015, 06:30 pm by ahull
Here's a version for the STM32F103 series of microcontrollers. See http://www.stm32duino.com/viewtopic.php?f=19&t=433 for more details.

The zipped version will work on pretty much any STM32F103, if the your variant  has more than the 20K RAM in the sketch, simply adjust where appropriate.


Looking at the 6502 code...I'm having trouble understanding the "exec6502(100)" line.  What does the 100 do?  Does the 100 slow down the code execution speed?  Is exec6502(1) faster?  Can someone please explain


Here's a real c64 emulation on a Teensy:
Youtube: https://www.youtube.com/watch?v=CjijgL0VC6k
(please excuse the quality)

Go Up