deckle studioOpen in the editor

ESP32: x86 PC with FreeDOS (FabGL)

An 8086 PC on the ESP32: FreeDOS, VGA, PS/2 keyboard.

Open in the simulatorNo account needed: press Simulate and it runs.

How it works

An ESP32-DevKitC with a WROVER module (8 MB PSRAM) runs FabGL's IBM PC/XT emulator: an 8086 with BIOS, timer, keyboard controller and CGA, its 1 MB of RAM in PSRAM. It boots FreeDOS from a floppy image in flash to the A:\> prompt. The picture goes out of I2S by DMA through the resistor DAC to the VGA monitor; the PS/2 keyboard is your keyboard while it runs, its protocol handled by the ESP32's ULP coprocessor. Hard disk C: is the file HD.IMG on the microSD card (SPI), with the FreeDOS tools EDIT, MEM, XCOPY, TREE, MORE and FIND; what you write there is kept while it runs. An emulator in an emulator: give it some 15 s of simulated time to boot (a few minutes), then type DIR C: or VER.

Wiring

Each line is one connection (net) and the pins it joins.

NetPins
GNDA1 GNDC1 2J1 GNDJ2 VSSKB1 GND
3V3A1 3V3C1 1J2 VDDKB1 VCCR7 1R8 1R9 1R10 1R11 1R12 1R13 1R14 1R15 1
VSYNCA1 GPIO15J1 VSYNC
B0A1 GPIO4R6 1
B1A1 GPIO5R5 1
BLUEJ1 BLUER5 2R6 2
G0A1 GPIO18R4 1
G1A1 GPIO19R3 1
GREENJ1 GREENR3 2R4 2
HSYNCA1 GPIO23J1 HSYNC
KCLKA1 GPIO33KB1 CLKR7 2
KDATA1 GPIO32KB1 DATAR8 2
MCLKA1 GPIO26R9 2
MDATA1 GPIO27R10 2
R0A1 GPIO21R2 1
R1A1 GPIO22R1 1
REDJ1 REDR1 2R2 2
SDCLKA1 GPIO2J2 CLK
SDCSA1 GPIO25J2 DAT3/CSR13 2
SDD1J2 DAT1R15 2
SDD2J2 DAT2R14 2
SDDIA1 GPIO13J2 CMD/DIR12 2
SDDOA1 GPIO34J2 DAT0/DOR11 2

Parts

Firmware

sketch.ino · 53 lines

// ESP32 x86 PC: FabGL's IBM PC/XT emulator (8086, CGA, PS/2 keyboard) boots FreeDOS from a floppy
// image in flash (its sectors unpacked into PSRAM). Needs an ESP32 with PSRAM (WROVER): the PC's 1 MB of RAM and the floppy live there.
// VGA on the FabGL pins (R 22/21, G 19/18, B 5/4, HSYNC 23, VSYNC 15), PS/2 keyboard CLK 33, DATA 32.
// Hard disk C: is the file HD.IMG on a microSD card (SPI: CLK 2, MISO 34, MOSI 13, CS 25); without
// a card the PC runs from A: alone.
#include "fabgl.h"
#include "pcemulator.h"
#include "esp_psram.h"
#include <SPI.h>
#include <SD.h>

// the microSD card's SPI bus and its chip select: VSPI on pins of their own, because FabGL's PC
// claims HSPI with GPIO14 / 35 / 12 for its MCP23S17 port expander when it starts
const int SD_CLK = 2, SD_MISO = 34, SD_MOSI = 13, SD_CS = 25;
static SPIClass sdSpi(VSPI);
// where C: lives in PSRAM (above the floppy) and how large it may be
const size_t HD_OFFSET = 0x200000, HD_MAX = 0x500000;

static Machine * machine;

void setup() {
  Serial.begin(115200);
  if (esp_psram_init() != ESP_OK) {
    Serial.println("This PC needs an ESP32 with PSRAM (WROVER module)");
    return;
  }
  // the floppy into PSRAM above the PC's 1 MB of RAM, writable
  uint8_t * disk = (uint8_t *) SOC_EXTRAM_DATA_LOW + PCEMU_DISK_OFFSET;
  size_t size = freedosFloppyTo(disk);
  Serial.printf("FreeDOS floppy: %u bytes\n", (unsigned) size);
  machine = new Machine;
  machine->setDriveMemory(0, disk, size);
  // C: from the card, if there is one with HD.IMG: copied into PSRAM above the floppy (the PC then
  // reads and writes it there, for this run; the card is not touched while the PC runs)
  sdSpi.begin(SD_CLK, SD_MISO, SD_MOSI, SD_CS);
  File hd;
  if (SD.begin(SD_CS, sdSpi, 20000000, "/sd") && (hd = SD.open("/HD.IMG")) && hd.size() <= HD_MAX) {
    uint8_t * c = disk + HD_OFFSET;
    size_t n = 0, got;
    while ((got = hd.read(c + n, 4096)) > 0) n += got;
    hd.close();
    machine->setDriveMemory(2, c, n);
    Serial.printf("C: = HD.IMG from the microSD card, %u bytes\n", (unsigned) n);
  } else {
    Serial.println("no microSD card with HD.IMG: no drive C:");
  }
  machine->setBootDrive(0);
  machine->run();
}

void loop() {
  vTaskDelay(1000);
}
Open in the simulator

More examples: Microcontrollers