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.

https://www.pjrc.com/store/teensy40.html

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.

https://www.pjrc.com/store/index.html

3 Likes

Do you know if this is written up anywhere?

The presenter in the video gave his website as http://8bitforce.com/ where most of his work has been documented

2 Likes

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.

Ken

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 https://forum.arduino.cc/index.php?topic=193216.0

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 withing 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

5  REM TRIGONOMETRIC FUNCTIONS TEST 1..89 DEGREE
10 PH = 3.141592653/2.0
15 REM DEFINE ARCSIN AND ARCCOS
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))
35 REM TR, TD - TO RAD, TO DEG
40 TR = 3.141592653 / 180.0
50 TD = 180.0 / 3.141592653
55 REM INPUT IN DEGREE (1..89)
60 FOR D = 1 TO 89
70 R = D * TR
80 S = FN ASN(FN ACS(ATN(TAN(COS(SIN(R))))))
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.

2 Likes

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:

LIST

 5 REM TRIGONOMETRIC FUNCTIONS TEST 1DEF
ENDSPC(89 DEGREE

whereas the imported source text is

5 REM TRIGONOMETRIC FUNCTIONS TEST 1{226}{128}{166}89 DEGREE

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:
5 REM TRIGONOMETRIC FUNCTIONS TEST 1…89 DEGREE
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 “?”.