Simulating Retro or Experimental CPUs on the Teensy 4.x

Back in April, the Teensy 4.0 and 4.1 were launched by PJRC.

The Teensy is a small format, breadboard friendly development board, and the fourth generation boards bring the power of a 600MHz ARM Cortex M7 microcontroller.

The Teensy 4.0 is the smallest pcb - just 35x18mm. Think of it as a similar size to a 28 pin x 0.6" DIP. As well as the 600MHz CPU, there is 2Mbytes of program memory (Flash) and 1 Mbyte of RAM - of which 512KB is tight coupled.

For more details of the specification please see the manufacturer’s webpage - which gives a comparative set of benchmarks between the Teensy 4.0 and previous generations of Arduino compatible boards.

The Teensy 4.1 is a slightly larger foot print which accomodates a uSD card socket and additional headers for USB Host and 10/100 Ethernet. There are also additional bare footprints on the underside of the board that allows the RAM to be extended to a maximum of 16 Mbyte using a pair of PSRAM chips costing about $1.50 each.

The Teensy 4.1 best resembles a 48 pin x 0.6" DIP package.

The small form factor of these boards, breadboard or protoboard compatible DIP pinouts and relatively low cost makes them very attractive to build into retrocomputing projects - to provide the processing power and memory to simulate whichever cpu you are interested.

The Teensy does not come with an operating system, though various have been ported. Additionally both MicroPython and CircuitPython have been ported to the Teensy 4.x

Teensy 4.x can be programmed using either the Arduino or the PlatformIO IDEs.

My first quick tests were done using Arduino IDE where I am using it to simulate an experimental 16-bit processor which I call Suite-16. It appears to be executing simulated instructions at approximately 20 million per second.

Teensy 4.x can be overclocked to as much as 1.018GHz if the cpu is fitted with a suitable heatsink. At 600MHz - the microcontroller consumes a mere 100mA.

This is a phenomenal amount of processing power and memory resources in a low power, low cost and easy to prototype package. Reading the power consumption figures reminds me of the story of when they (Sophie Wilson and Steve Furber) first powered up the first ARM prototype - but that was only at 8MHz - not 600MHz !

My appetite has also been whetted, by a video that was presented at Virtual VCF West. It was using a Teensy to create a generic bus and memory system for implementing retrocomputing platforms. Whilst the presenter used a Teensy 3.5, The Teensy 4.1 provides a pin compatible footprint, and considerable extra speed and resources.

It could easily be used as an entire video subsystem to complement a Z80 or 6502 project. 3.3V to 5V bus buffers are required when interfacing to 5V systems - but as the video shows - these are provided on an interface board. The video can be seen here:

The attraction of these new Teensy parts is their small format, low cost (about $20 and $30 respectively) and the easy of programming with Arduino, PlatformIO or one of the Python tools.

There is no operating system to get in the way, so you have essentially a blank canvas to work with.

See the manufacturers website for more information and a list of the Worldwide Distributors.


Do you know if this is written up anywhere?

The presenter in the video gave his website as where most of his work has been documented


Nice find Ken!

Here’s Erturk Kocalar’s presentation isolated - with the benefit of a transcript. Here’s the board which puts a Teensy into an Arduino Mega footprint, with the retro CPU hanging off the side:

(The Teensy 3.5 is somewhat outgunned by later developments, but has the retro advantage of 5V tolerance. As noted, otherwise you need level shifters. But in this case, level shifters are included anyway, because some micros apparently needed higher logic voltages.)

If anyone is interested, Erturk Kocalar is selling all of his RetroShield cpu boards on Tindie - as a set of solder it yourself kits.


1 Like

Ok, yea, well, this is interesting, but not what I was looking for.

This is a bit of a showstopper for what I’m looking at:

  • Microprocessor runs at about 110~170kHz.

Nice demo, but not usable for my purposes.

The CPU is a device driven by the Arduino. The Arduino controls the clock and control lines of the CPU.

Right, with the Arduino in charge you don’t reach 1MHz. But with the Teensy 3.5, you do. Presumably even better with the Teensy 4.

Very interesting! Especially the RTC (real time clock), which is missing on many other small board computers, may be interesting for any emulation projects. (However, the specs state merely, “RTC for date/time”, so not sure about the resolution.)

I have revisited a 6502 simulator written for Arduino. It comes complete with ehBASIC coded into the ROM space.

The code can be downloaded from this link

This was loaded onto the Teensy 4.0 using the Arduino IDE and outputs to a serial terminal at 921600 baud.

This might appear an unconventional route to running an old-school BASIC interpreter, on a simulated 6502, coded in C++, via an Arduino compatible ARM board - but having located the source code files, it was up and running within a few minutes.

There are probably a lot of “real” programmers who detest the limitations of the Arduino IDE, but to take C++ code that was originally written for a ATmega328 and have it run without modification on a 600MHz ARM Cortex M7 has to be the ultimate in code portability.

I used the following trig function calculator as a benchmark

10 PH = 3.141592653/2.0
20 DEF FN ASN(X) = ATN(X/SQR(1.0-X*X))
30 DEF FN ACS(X) = PH-ATN(X/SQR(1.0-X*X))
40 TR = 3.141592653 / 180.0
50 TD = 180.0 / 3.141592653
60 FOR D = 1 TO 89
70 R = D * TR
90 T = S * TD
100 PRINT T; " "; D; " "; T-D; " "; FRE(1)
110 NEXT D
120 END

100 iterations of this program were completed in 92 seconds . I think that is fairly good proof of what the Teensy 4.0 can do by emulating the classic 6502 cpu, and recalculating 8900 trig functions in 92 seconds.

If anyone could suggest how long the above program would take on an original 6502 machine.


Nice work! (Let’s not distract ourselves by supposing what things some people might not like - that’s not a good discussion)

In @NoLand’s PET simulator the program - or a version of it - takes 41 seconds to run. That’s a 1MHz 6502 running an MS Basic.

I think 0.92 compares very well to 41! You must be at about 45MHz.

(It’s more than just all the trig functions: there are a lot of evaluations of defined functions, and square roots, too.)

Ed - thanks for the relative benchmark.

I think that the combined forces of the Teensy 4.x for direct simulation, and Erturk Kocalar’s Retro Shield providing hardware support functionality for the venerable old microprocessors provide a couple of relatively low cost, quick and easy approaches to getting involved with the Retro Computing scene.

Erturk used an interesting phrase at the end of his video presentation - something like “breadboarding in software” I think this sums up a very powerful technique.

1 Like

Oops, I observed a small hick-up in the source text import / tokenizing routine, regarding the REM statement in the first line:



whereas the imported source text is


Now PETSCII 226 (0xE2), 128 (0x80), 166 (0xA0) doesn’t make any obvious sense. Moreover, I seem to have missed something about tokenizing vs quoting of REM statements somewhere in the process, which may require fixing.

What was the original, intended text and what method did you use to generate the link (emulator or any of the external consoles)?

I’d pasted Ken’s program into a txt file and dragged it - but at the time it was rendered as markup (I subsequently put it in a code block) so it probably is a unicode kind of problem:
It seems .. as two characters has been rendered as HORIZONTAL ELLIPSIS

Ah, I see. (I may have to migrate to using a regular TextRenderer supporting Unicode, which is a thing for several years now, and guarding against higher values. At the moment, I’m doing it all low-level, just for the fun of it, BOM and so on, just looking for PI in the respective byte order and ignoring the possibility of any other non-ASCII Unicode characters occurring. Because, what could go possibly wrong? A case of one level of retro too much.)

Update: this issue should be fixed. Common replacements and AutoCorrection™ substitutions (e.g., “a(c)=x” turned into “a©=x”) are undone and remaining Unicode-only characters are replaced by “?”.

Further to my recent experiments in simulating the PDP-8 and 6502 on the Teensy 4.0, I was prompted by the latest RC2014 Newsletter, which describes a new CP/M board for the RC2014, to investigate Z80 simulations, with the possibility of running CP/M.

A CP/M simulator needs minimum hardware, an Arduino (Due) compatible board and an SDcard module. If you want to play with CP/M the $30 Teensy 4.1seems the lowest cost harware solution (or carefully solder a microSD socket to the underside of a $20 Teeny 4.0).

To lower the level of the entry bar, it is desirable to find a simulation that has been written for the Arduino. The Teensy is compatible with Arduino C++, and past experience has shown these simulation programs to “work straight out of the can” or require minimal tweaks to get them to run.

Three Z80 simulations have come to light so far:

CPMDuino was written for the Arduino Due. The Teensy 4.x has 24 times the performance of the Due, plus the advantage of considerably more RAM (tightly coupled).

What other classic microprocessors have Arduino based simulators?

I found this one for the 6800 - which simulates the SWTPC 6800 - introduced in 1975.

I have done a non-exhaustive search for 6809 simulations but as yet nothing has come to light - apart for one broken link in Russian.

Forging ahead, and with discussion this week about the 68000 series, I found this interesting link to Jean Marc Harvengt’s Multicomputer Machine emulation project - MCUME

Here Jean Marc Harvengt simulates 6502, Z80, 68000, 68020 and 8086 on Teensy 4.0 or 4.1 and also on ESP32. Not just the processor itself but integrated into a complete retrocomputer system - with a tiny hardware implemention with keyboard and LCD!

The table below summarises this awesome project

The 8086 and PC-XT simulation was written by Mike Chambers - here he describes a little bit about it

I guess that once you have perfected the techniques of writing one processor simulator, the method can more or less be applied to any target processor - rather in the way that a table driven assembler (eg. TASM) can fairly easily be modified to suit new targets.


That is only true if data sizes and memory tend to be similar.
How about a 36 bit or Decimal machine? I am using a C compiler that supports long long for a 36 bit assembler being written, but a older system may not have it,

I was able to emulate the 6502 including the bus interface on a Teensy 4.1 and try it in a VIC-20 and Apple II+.

Code available on GitHub: Projects/MCL65+ at master · MicroCoreLabs/Projects · GitHub