[{"data":1,"prerenderedAt":215},["ShallowReactive",2],{"example-page-esp32-pc":3},{"id":4,"info":5,"parts":6,"wired":21,"refs":22,"nets":23,"moreNets":209,"code":210},"esp32-pc","An ESP32-DevKitC with a WROVER module (8 MB PSRAM) runs FabGL's IBM PC\u002FXT 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\u002F2 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.",[7,10,13,15,17,19],[8,9],"resistor",15,[11,12],"capacitor",1,[14,12],"esp32_devkitc",[16,12],"microsd_card",[18,12],"ps2_keyboard",[20,12],"vga_monitor",false,{"A1":14,"C1":11,"J1":20,"J2":16,"KB1":18,"R7":8,"R8":8,"R9":8,"R10":8,"R11":8,"R12":8,"R13":8,"R14":8,"R15":8,"R6":8,"R5":8,"R4":8,"R3":8,"R2":8,"R1":8},[24,40,68,74,81,88,94,101,108,114,120,128,136,142,148,155,161,167,173,181,187,193,201],{"name":25,"pins":26},"0",[27,30,33,35,38],[28,29],"A1","GND",[31,32],"C1","2",[34,29],"J1",[36,37],"J2","VSS",[39,29],"KB1",{"name":41,"pins":42},"3V3",[43,44,46,48,50,52,54,56,58,60,62,64,66],[28,41],[31,45],"1",[36,47],"VDD",[39,49],"VCC",[51,45],"R7",[53,45],"R8",[55,45],"R9",[57,45],"R10",[59,45],"R11",[61,45],"R12",[63,45],"R13",[65,45],"R14",[67,45],"R15",{"name":69,"pins":70},"VSYNC",[71,73],[28,72],"GPIO15",[34,69],{"name":75,"pins":76},"B0",[77,79],[28,78],"GPIO4",[80,45],"R6",{"name":82,"pins":83},"B1",[84,86],[28,85],"GPIO5",[87,45],"R5",{"name":89,"pins":90},"BLUE",[91,92,93],[34,89],[87,32],[80,32],{"name":95,"pins":96},"G0",[97,99],[28,98],"GPIO18",[100,45],"R4",{"name":102,"pins":103},"G1",[104,106],[28,105],"GPIO19",[107,45],"R3",{"name":109,"pins":110},"GREEN",[111,112,113],[34,109],[107,32],[100,32],{"name":115,"pins":116},"HSYNC",[117,119],[28,118],"GPIO23",[34,115],{"name":121,"pins":122},"KCLK",[123,125,127],[28,124],"GPIO33",[39,126],"CLK",[51,32],{"name":129,"pins":130},"KDAT",[131,133,135],[28,132],"GPIO32",[39,134],"DATA",[53,32],{"name":137,"pins":138},"MCLK",[139,141],[28,140],"GPIO26",[55,32],{"name":143,"pins":144},"MDAT",[145,147],[28,146],"GPIO27",[57,32],{"name":149,"pins":150},"R0",[151,153],[28,152],"GPIO21",[154,45],"R2",{"name":156,"pins":157},"R1",[158,160],[28,159],"GPIO22",[156,45],{"name":162,"pins":163},"RED",[164,165,166],[34,162],[156,32],[154,32],{"name":168,"pins":169},"SDCLK",[170,172],[28,171],"GPIO2",[36,126],{"name":174,"pins":175},"SDCS",[176,178,180],[28,177],"GPIO25",[36,179],"DAT3\u002FCS",[63,32],{"name":182,"pins":183},"SDD1",[184,186],[36,185],"DAT1",[67,32],{"name":188,"pins":189},"SDD2",[190,192],[36,191],"DAT2",[65,32],{"name":194,"pins":195},"SDDI",[196,198,200],[28,197],"GPIO13",[36,199],"CMD\u002FDI",[61,32],{"name":202,"pins":203},"SDDO",[204,206,208],[28,205],"GPIO34",[36,207],"DAT0\u002FDO",[59,32],0,{"file":211,"lang":212,"text":213,"lines":214,"more":21},"sketch.ino","cpp","\u002F\u002F ESP32 x86 PC: FabGL's IBM PC\u002FXT emulator (8086, CGA, PS\u002F2 keyboard) boots FreeDOS from a floppy\n\u002F\u002F 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.\n\u002F\u002F VGA on the FabGL pins (R 22\u002F21, G 19\u002F18, B 5\u002F4, HSYNC 23, VSYNC 15), PS\u002F2 keyboard CLK 33, DATA 32.\n\u002F\u002F Hard disk C: is the file HD.IMG on a microSD card (SPI: CLK 2, MISO 34, MOSI 13, CS 25); without\n\u002F\u002F a card the PC runs from A: alone.\n#include \"fabgl.h\"\n#include \"pcemulator.h\"\n#include \"esp_psram.h\"\n#include \u003CSPI.h>\n#include \u003CSD.h>\n\n\u002F\u002F the microSD card's SPI bus and its chip select: VSPI on pins of their own, because FabGL's PC\n\u002F\u002F claims HSPI with GPIO14 \u002F 35 \u002F 12 for its MCP23S17 port expander when it starts\nconst int SD_CLK = 2, SD_MISO = 34, SD_MOSI = 13, SD_CS = 25;\nstatic SPIClass sdSpi(VSPI);\n\u002F\u002F where C: lives in PSRAM (above the floppy) and how large it may be\nconst size_t HD_OFFSET = 0x200000, HD_MAX = 0x500000;\n\nstatic Machine * machine;\n\nvoid setup() {\n  Serial.begin(115200);\n  if (esp_psram_init() != ESP_OK) {\n    Serial.println(\"This PC needs an ESP32 with PSRAM (WROVER module)\");\n    return;\n  }\n  \u002F\u002F the floppy into PSRAM above the PC's 1 MB of RAM, writable\n  uint8_t * disk = (uint8_t *) SOC_EXTRAM_DATA_LOW + PCEMU_DISK_OFFSET;\n  size_t size = freedosFloppyTo(disk);\n  Serial.printf(\"FreeDOS floppy: %u bytes\\n\", (unsigned) size);\n  machine = new Machine;\n  machine->setDriveMemory(0, disk, size);\n  \u002F\u002F C: from the card, if there is one with HD.IMG: copied into PSRAM above the floppy (the PC then\n  \u002F\u002F reads and writes it there, for this run; the card is not touched while the PC runs)\n  sdSpi.begin(SD_CLK, SD_MISO, SD_MOSI, SD_CS);\n  File hd;\n  if (SD.begin(SD_CS, sdSpi, 20000000, \"\u002Fsd\") && (hd = SD.open(\"\u002FHD.IMG\")) && hd.size() \u003C= HD_MAX) {\n    uint8_t * c = disk + HD_OFFSET;\n    size_t n = 0, got;\n    while ((got = hd.read(c + n, 4096)) > 0) n += got;\n    hd.close();\n    machine->setDriveMemory(2, c, n);\n    Serial.printf(\"C: = HD.IMG from the microSD card, %u bytes\\n\", (unsigned) n);\n  } else {\n    Serial.println(\"no microSD card with HD.IMG: no drive C:\");\n  }\n  machine->setBootDrive(0);\n  machine->run();\n}\n\nvoid loop() {\n  vTaskDelay(1000);\n}",53,1796304409829]