[queued] Teensy 4.1 Atari ST emulation with MIDI & VGA

Great work!! Earlier this year I was attempting to use my Macbook to emulate Atari ST MIDI Librarians/Editors for my Ensoniq ESQ-1, but I wasn't able to get MIDI to work... might have to try this out.
Hi Jean-Marc,

Wanting to try the Atari emulator on my recently-acquired Teensy 4.1, I downloaded the repository (2b18321) today, and noted the instructions:

# Compilation/flashing (Teensy)
- open the respective ino file with Arduino SDK
- select DISPLAY MODULE in platform_config.h (ST7789 or ILI9341)!!!!
- select VGA or not in platform_config.h (T4.1 using vgat4 lib, T3.6 using uvga lib)
- double check iopins.h for pins configuration!!!!
- compile and install from there.

Just to clarify, in platform_config.h, do I select ST7789/ILI9341/VGA by setting only one of the following?
#define ST7789         1
#define ILI9341        1
#define HAS_T4_VGA     1

Finally, though I did eventually figure this out after searching these forums for "vga_t4", maybe mention in the Readme that we need to install the VGA_t4 library. Without it, I wasn't able to compile, even if setting #define HAS_T4_VGA 0. For example,

Arduino: 1.8.13 (Mac OS X), TD: 1.53, Board: "Teensy 4.1, Serial, 600 MHz, Faster, US English"

In file included from /Teensy/Teensy MCUME/MCUME-2b18321/MCUME_teensy41/teensycastaway41/teensycastaway41.ino:38:0:
/var/folders/xk/0yb20rbd6pv_0y6jp6vcbr1w0000gn/T/arduino_build_990766/sketch/vga_t_dma.h:9:20: fatal error: VGA_t4.h: No such file or directory
compilation terminated.
Error compiling for board Teensy 4.1.

At any rate, after installing the library I was able to compile fine! But I'll have to wait until I can connect a VGA port, resistors, USB port, etc. to my new T4.1. Can't wait. :D
Dont forget you need the PSRAM chip soldered under the Teensy4.1 board, else it will not work!

Best is indeed to use the VGA output.
You should only select one of the supported display (comment out the others, e.g.):
//#define ST7789 1
//#define ILI9341 1
#define HAS_T4_VGA 1

It used to work with ILI9341 but then you only have 320X200 resolution.
I did not try with latest code to be honest but it used to work.

Also joystick + 3 buttons have to be connected else it might read out floating input.
It is a bit of wiring but ok...
Once you did it you can try all emulators including the amiga one too ... ;-)
Hello Jean Marc :)

I just have a question about pin-out when i want to use a SPI TFT LCD.
As i see , the 2 user keys are in conflict with TFT_RST and TFT_CD , the I2S audio data pin is in conflict with TFT_DC.
Some NES console use up to 4 buttons , can you tell me what pin was planned for this ?


I have not used I2S with the TFT display.
TFT_RST is not mandatory AFAIK. I used ILI and ST display. As I recall at least for the ST display it is not. I think same for ILI.

TFT_CD/ you mean DC. As I said I was not using I2S at same time.
I used MSQL audio only with the TFT display. MISO is not used for the TFT (only MOSI). I had a trick to avoid that the SPI library initializing the PIN configuration modifying the code.

NES 4 buttons was never really supported. With the I2C keyboard I mapped most keys. There is a BUT key USER1,2,3.
USER3 is supported in the code but you can map it to a pin in IOPINS.h. It was there on the T3.6 support. if you define it should be added.

Just try and tell me
Hi , thanks for all this information's :)
I use the ILI9341 , so i will then not connect the MISO , TFT_RST will then be connected to VCC.
For the user button that is conflicting with TFT_CS i will chose another pin , and will do same for other user pins in iopins.h ;)

Hi ,
i have do like you said and everything is working up to the joybut and the 3 user keys.(they work on a test sketch i have do just for testing the analog joy and the buttons).
The Emulators don't react to the joybut and the user keys , i don't have made the i2c kb because i have made a minimalistic box (like a handled console) so it stay very compact :)
I tested with teensy5200 , teensygen , teensygnuboy , teensyvectrex .
All emulators start and i can select a game (rom) , and that's it :) ... the game start and i can't do anything because the non reaction to the switch.
Was those emulators only working with your i2c KB ??
The case i printed is like that.
teesy console A.jpg
teesy console B.jpg

This problem is familiar to me. I will try again this w.e on my handled version.
Normally no need for the I2C keyboard.
You edited the option file and selected the proper options there I guess.

The menu does not use the DMA mode for the display.
As soon you start the emulator by launching the game, it switches to DMA. You see the game graphical updates but no control correct?

You did not selected external SD, you use the SD card of the teensy 4.1, not of the display.
I found why it was not working correctly :)
It was here ...

#ifdef HAS_T4_VGA
#define PIN_JOY2_A1X    A3
#define PIN_JOY2_A2Y    A2
#define PIN_JOY2_BTN    14
#define PIN_KEY_USER1   22
#define PIN_KEY_USER2   23
#define PIN_KEY_USER3   35

// Second joystick
#define PIN_JOY1_BTN     34
#define PIN_JOY1_1       35 // UP
#define PIN_JOY1_2       36 // DOWN
#define PIN_JOY1_3       38 // RIGHT
#define PIN_JOY1_4       37 // LEFT

#define PIN_JOY2_A1X    A3               <-----
#define PIN_JOY2_A2Y    A2               <-----
#define PIN_JOY2_BTN    14               <-----
#define PIN_KEY_USER1   22 //34          <-----
#define PIN_KEY_USER2   23 //35          <-----
#define PIN_KEY_USER3   35               <-----
Its just because i just have this define : #define HAS_T41 1
So after the #else i don't have set the correct pins :)
For answer your questions , i don't use external SD , just the one present on the t41 board , and here everything is perfect.

The next i have to do is add audio , have you a schematic for this if you don't use pcm5102 ?
Last edited:
the new pinout was introduced for T4.1 VGA because I needed more pins and because of the flexio usage.

With my original ILI PCB, in lopins.h, it should end up in the else and I use those pins.

Because the code was working with a T4.0, HAS_T41 don't need to be defined. If I recall well, HAS_T41 was defined if PSRAM is defined or needed by the emulator. With T4.0 I used my own PSRAM driver and for T4.1 it is just supported by the library.

Happy it is working for you now (I hope at least)

I will solder header pins on a new T4. and try again, to avoid swapping it from one board to the other and destroy it.

If you want to use the I2S together with the ILI, you better use the other SPI bus for the T4.1 (pin 26 and 27)

#ifdef HAS_T4_VGA
#define PIN_JOY2_A1X A3
#define PIN_JOY2_A2Y A2
#define PIN_JOY2_BTN 14
#define PIN_KEY_USER1 22
#define PIN_KEY_USER2 23

// Second joystick
#define PIN_JOY1_BTN 34
#define PIN_JOY1_1 35 // UP
#define PIN_JOY1_2 36 // DOWN
#define PIN_JOY1_3 38 // RIGHT
#define PIN_JOY1_4 37 // LEFT

#define PIN_JOY2_A1X A1
#define PIN_JOY2_A2Y A2
#define PIN_JOY2_BTN 17
#define PIN_KEY_USER1 3 //34
#define PIN_KEY_USER2 4 //35

// Second joystick
#define PIN_JOY1_BTN 2
#define PIN_JOY1_1 14 // UP
#define PIN_JOY1_2 7 // DOWN
#define PIN_JOY1_3 6 // RIGHT
#define PIN_JOY1_4 5 // LEFT
Hi ,
i tested some of the emulators , they are working up to one (.... problem.....) ,
It seems that all emulators are slower than normal , can it be that the T41 is not set at 600Mhz ?
In the Arduino IDE it's check for 600Mhz but i don't know if you change something in the emulators :)
I tried to compile from Fastest to Smallest code but the speed stay the same ...
teensy tetris.jpg
few possibilities,
- screen refresh too slow because of the SPI display (you can try go above the clock, normally it uses 60000000MHz in the DMA driver)
- it does sync on timer interrupt (myTimer.begin(vblCount, 20000); in the sketch, you can lower the value)
- for some there is a fixed delay sometimes in the sketch
- play with frame skip in emuapi.h VID_FRAME_SKIP 0x0

The teensy is fast enough for those emulator.
Try for e.g. colecovision. It is a simple one and you should be able to make it running 5 times faster.
That's it :)
on gameboy emulator :
myTimer.begin(vblCount, 40000); <--- i set it to 20000 and it's more like the expected speed :)
VID_FRAME_SKIP 0x1 give a little boost too ....
To test the result speed i have test with Sonic game on the sms emulator , it have a second counter in-game , was easy to compare the video i have do with a real clock :)
I forget to ask you about audio :)
On github i read that you use MSQ for audio.
Do you use MSQR , MSQL or both ?
If i understand correctly , all i have to do is to connect a little audio amplifier on this pins (10 & 12) to get sound .... correct me if i'm wrong :)
Hi Jean Marc ,
I just fond out for audio , i activated the commented MQS in your code.
But it was allot of noise , so i made a filter and now everything goes well ;)