FabGL2 2.0.0
ESP32 Display Controller and Graphics Library for ESP-IDF
Loading...
Searching...
No Matches
Altair8800

Emulator of the MITS Altair 8800 computer with Intel 8080 or Zilog Z80 CPU, 64 KB of RAM, up to four 88-DCDD 8" floppy disk drives and serial I/O boards. It boots CP/M (1.4, 2.2, 3), Altair Disk BASIC or Altair DOS from the disk images included in the firmware. Watch it on YouTube.

The video output is a 80x25 text terminal (ADM-31 emulation by default) on VGA; the keyboard is a PS/2 keyboard.

Getting started

Flash the example and wait for the A> prompt: drive A contains CP/M 2.2, drive B contains games.

A>DIR
A>B:
B>DIR
B>LADDER

Some programs to try:

Disk Programs
A: CP/M 2.2 (cpm22_dsk) MBASIC, ASM, MAC, M80/L80, DDT, ED, PIP, STAT, SUBMIT, DUMP, SURVEY, FORMAT, PCGET/PCPUT
B: Games (games_dsk) LADDER, CATCHUM, ALIENS, OTHELLO, DUMPSTAR, and in MBASIC: STARTRK, LUNAR, CHASE, TICTAK (MBASIC STARTRK)

If a game draws garbage, configure it for the terminal: LADCONF (Ladder) and CATCONF (Catchum) select the terminal type, or change the emulated terminal from the emulator menu.

Disk drives

Drive Default content Writable
A: CP/M 2.2 system disk (image in flash) With an SD card: yes (copied to diskA.dsk on the card). Without: read only
B: Games disk (image in flash) Same as A: (diskB.dsk)
C: diskC.dsk on SD card or SPIFFS Yes. Format it first with FORMAT C:
D: diskD.dsk on SD card or SPIFFS Yes. Format it first with FORMAT D:

The emulator uses the SD card if present, otherwise the internal SPIFFS partition (formatted automatically on first use). Files on drives C: and D: survive a reboot.

Changing the disk images

The included images are selected at compile time with the DRIVE_A ... DRIVE_D defines at the top of main/Altair8800.cpp:

#define DISKFORMAT Disk_338K
#define DRIVE_A cpm22_dsk // image in flash
#define DRIVE_B games_dsk // image in flash
#define DRIVE_C "diskC.dsk" // file on SD card / SPIFFS
#define DRIVE_D "diskD.dsk"

Available 8" images (DISKFORMAT Disk_338K, folder main/disks):

Image Content Use as
cpm22_dsk CP/M 2.2 system A
games_dsk Games B
turbopascal3_dsk Turbo Pascal 3 B
wordstar3_dsk, wordstar4_dsk WordStar 3 / 4 B
multiplan_dsk Multiplan (+ WordStar) B
dbaseii_dsk dBase II (+ WordStar) B
BDSC_dsk BDS C compiler B
langs_dsk Languages: BBC BASIC, Forth 83, DX-Forth, XLISP, ... B
cpm141_dsk CP/M 1.4 system A
cpm3_disk1_dsk CP/M 3 system (requires the Z80 CPU) A
cpm3_disk2_dsk, cpm3_build_dsk CP/M 3 utilities and system build files B
DOS_1_dsk, DOS_2_dsk Altair DOS A
basic5_dsk Altair Disk BASIC 5 A

Mini disk images (5.25", DISKFORMAT MiniDisk_76K, folder main/minidisks): cpm22_disk1_minidsk, cpm22_disk2_minidsk, basic300_5F_minidisk (requires the i8080 CPU).

Altair DOS and Disk BASIC ask some questions at boot. Suggested answers are in the comments next to their #include lines in Altair8800.cpp (for example Disk BASIC: MEMORY SIZE? Enter, LINEPRINTER? C, then Enter to the remaining questions).

Each 8" image is 337568 bytes (77 tracks x 32 sectors x 137 bytes). To add your own image, convert the raw Altair .dsk file to a C header containing a const uint8_t name[] = { ... }; array (for example with xxd -i), include it and assign it to a drive.

Emulator menu (F12 or Pause)

Press F12 or Pause at any time to open the emulator menu. Press the letter of an option, Enter to go back to the emulated machine.

Key Option
Z Reset the Altair (reboot)
S Send a disk image to the serial port (USB)
R Receive a disk image from the serial port (USB)
F Format the file system (SD card or SPIFFS): deletes all the disk files!
U CPU: Z80 / i8080 (reset required)
P Real CPU speed: emulate the original 2 MHz speed, or run as fast as possible
T Terminal emulation: ANSI, ADM 3A, ADM 31, Hazeltine 1500, Osborne, Kaypro, VT52, ANSI Legacy
K Keyboard layout
C Colors: Green/Black, Yellow/Black, White/Black, Black/White, Yellow/Blue, Black/Yellow
L Rows: 24, 25 or max
G CRT mode (retro scanlines, only with the graphical display controller, see below)
O Reset the configuration to the defaults

The settings are saved in NVS.

Transferring files with a PC

The Altair has three serial boards: SIO at port 00h (TTY) and 10h (CRT) are connected to the screen and keyboard, SIO at port 12h is connected to the USB serial port (115200 baud). The scripts in tools use it (they need Python 3 with pyserial, and xmodem for transfile.py: pip3 install pyserial xmodem):

Single files (XMODEM): run PCGET (receive) or PCPUT (send) on the Altair, then on the PC:

A>PCGET MYFILE.COM (on the Altair)
python3 tools/transfile.py MYFILE.COM to /dev/ttyUSB0 (on the PC)
A>PCPUT MBASIC.COM (on the Altair)
python3 tools/transfile.py MBASIC.COM from /dev/ttyUSB0 (on the PC)

Whole disk images: open the emulator menu and choose R (receive) or S (send) and the drive letter, then on the PC:

python3 tools/transdisk.py mydisk.dsk to /dev/ttyUSB0 (PC -> Altair, after "R")
python3 tools/transdisk.py mydisk.dsk from /dev/ttyUSB0 (Altair -> PC, start this before "S")

Close any serial monitor before running the scripts.

What it demonstrates

Hardware

  • VGA output (default pins)
  • PS/2 keyboard on port 0 (CLK = GPIO33, DATA = GPIO32)
  • Optional SD card (TTGO VGA32 slot: MISO = GPIO16 (2 on PICO-D4), MOSI = GPIO17 (12 on PICO-D4), CLK = GPIO14, CS = GPIO13)

Build

The example ships a partitions.csv (2 MB application + SPIFFS for the writable disks). See Building the examples.

Source code

Main file of the example, main/Altair8800.cpp. The complete project is in the examples/VGA/Altair8800 folder.

1/*
2 Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - <http://www.fabgl.com>
3 Copyright (c) 2019-2026 Fabrizio Di Vittorio.
4 All rights reserved.
5
6
7* Please contact fdivitto2013@gmail.com if you need a commercial license.
8
9
10* This library and related software is available under GPL v3.
11
12 FabGL is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 FabGL is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with FabGL. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26
27
28 /*
29 * Optional SD Card connections:
30 * MISO => GPIO 16 (2 for PICO-D4)
31 * MOSI => GPIO 17 (12 for PICO-D4)
32 * CLK => GPIO 14
33 * CS => GPIO 13
34 *
35 * To change above assignment fill other paramaters of FileBrowser::mountSDCard().
36 */
37
38
39
40#include "esp_system.h"
41#include <string>
42
43
44#include "fabgl.h"
45
46
47// UART0 (console) stream
48fabgl::UARTStream Console;
49#include "fabutils.h"
50
51#include "src/machine.h"
52
53
54
55// Flash and SDCard configuration
56#define FORMAT_ON_FAIL true
57#define SPIFFS_MOUNT_PATH "/flash"
58#define SDCARD_MOUNT_PATH "/SD"
59
60
61// Display controller (textual or bitmapped)
62#define USE_TEXTUAL_DISPLAYCONTROLLER
63
64
66// 8'' disk images (338K)
67// To use these disks you have to enable Disk_338K and disable MiniDisk_76K
68
69// CP/M 2.2
70#include "disks/CPM22/cpm22_dsk.h" // usage: "#define DRIVE_A cpm22_dsk"
71#include "disks/CPM22/games_dsk.h" // usage: "#define DRIVE_B games_dsk"
72#include "disks/CPM22/turbopascal3_dsk.h" // usage: "#define DRIVE_B turbopascal3_dsk"
73#include "disks/CPM22/wordstar3_dsk.h" // usage: "#define DRIVE_B wordstar3_dsk"
74#include "disks/CPM22/wordstar4_dsk.h" // usage: "#define DRIVE_B wordstar4_dsk"
75#include "disks/CPM22/multiplan_dsk.h" // usage: "#define DRIVE_B multiplan_dsk"
76#include "disks/CPM22/dbaseii_dsk.h" // usage: "#define DRIVE_B dbaseii_dsk"
77#include "disks/CPM22/BDSC_dsk.h" // usage: "#define DRIVE_B BDSC_dsk"
78#include "disks/CPM22/langs_dsk.h" // usage: "#define DRIVE_B langs_dsk"
79
80// CP/M 1.4
81#include "disks/CPM14/cpm141_dsk.h" // usage: "#define DRIVE_A cpm141_dsk"
82
83// CP/M 3
84#include "disks/CPM3/cpm3_disk1_dsk.h" // usage: "#define DRIVE_A cpm3_disk1_dsk"
85#include "disks/CPM3/cpm3_disk2_dsk.h" // usage: "#define DRIVE_B cpm3_disk2_dsk"
86#include "disks/CPM3/cpm3_build_dsk.h" // usage: "#define DRIVE_B cpm3_build_dsk"
87
88// Altair DOS
89// MEMORY SIZE? [insert "64"]
90// INTERRUPTS? [press ENTER]
91// HIGHEST DISK NUMBER? [insert "1"]
92// HOW MANY DISK FILES? [insert "4"]
93// HOW MANY RANDOM FILES? [insert "4"]
94#include "disks/AltairDOS/DOS_1_dsk.h" // usage: "#define DRIVE_A DOS_1_dsk"
95#include "disks/AltairDOS/DOS_2_dsk.h" // usage: "#define DRIVE_A DOS_2_dsk"
96
97// Basic
98// MEMORY SIZE? [press ENTER]
99// LINEPRINTER? [insert "C"]
100// HIGHEST DISK NUMBER? [press ENTER]
101// HOW MANY FILES? [press ENTER]
102// HOW MANY RANDOM FILES? [press ENTER]
103#include "disks/basic/basic5_dsk.h" // usage: "#define DRIVE_A basic5_dsk"
104
106
107
108
110// Mini disk images (76K)
111// To use these disks you have to enable MiniDisk_76K and disable Disk_338K
112
113// CP/M 2.2
114#include "minidisks/CPM22/cpm22_disk1_minidsk.h" // usage: "#define DRIVE_A cpm22_disk1_minidsk"
115#include "minidisks/CPM22/cpm22_disk2_minidsk.h" // usage: "#define DRIVE_B cpm22_disk2_minidsk"
116
117// Basic (need i8080 CPU)
118// MEMORY SIZE? [press ENTER]
119// LINEPRINTER? [insert "C"]
120// HIGHEST DISK NUMBER? [insert "0"]
121// HOW MANY FILES? [insert "3"]
122// HOW MANY RANDOM FILES? [insert "2"]
123#include "minidisks/basic/basic300_5F_minidisk.h" // usage: "#define DRIVE_A basic300_5F_minidisk"
124
126
127
128
130// Disks configuration
131
132// Enable this when using 8'' disk images ("disks" folder)
133#define DISKFORMAT Disk_338K
134
135// Enable this when using minidisk images ("minidisk" folder)
136//#define DISKFORMAT MiniDisk_76K
137
138// Specify which disk image or file name assign to drives
139#define DRIVE_A cpm22_dsk // A: read only (or read/write using SD Card)
140#define DRIVE_B games_dsk // B: read only (or read/write using SD Card)
141#define DRIVE_C "diskC.dsk" // C: read/write (remember to FORMAT!!)
142#define DRIVE_D "diskD.dsk" // D: read/write (remember to FORMAT!!)
143
145
146
147
148// consts
149
150constexpr int DefaultCPU = 1; // 0 = i8080, 1 = Z80
151
152constexpr int DefaultTermIndex = 2; // Default: "ADM-31"
153constexpr int MaxTermIndex = 7; // Max: "Legacy ANSI"
154
155constexpr int DefaultKbdLayIndex = 2; // Default: "UK"
156
157constexpr int DefaultRowsCount = 0; // 0 = no limit (34 on the text terminal)
158
159const char * ColorsStr[] = { "Green/Black", "Yellow/Black", "White/Black", "Black/White", "Yellow/Blue", "Black/Yellow" };
160const Color TextColors[] = { Color::BrightGreen, Color::BrightYellow, Color::BrightWhite, Color::Black, Color::BrightYellow, Color::Black };
161const Color BackColors[] = { Color::Black, Color::Black, Color::Black, Color::BrightWhite, Color::Blue, Color::BrightYellow };
162constexpr int DefaultColorsIndex = 0; // Default: Green/Black
163constexpr int MaxColorsIndex = 5;
164
165
166// globals
167
168#ifdef USE_TEXTUAL_DISPLAYCONTROLLER
169fabgl::VGATextController DisplayController;
170#else
171fabgl::VGA16Controller DisplayController;
172#endif
173fabgl::PS2Controller PS2Controller;
174fabgl::Terminal Terminal;
175
176Machine altair;
177Mits88Disk diskDrive(&altair, DISKFORMAT);
178SIO SIO0(&altair, 0x00);
179SIO SIO1(&altair, 0x10);
180SIO SIO2(&altair, 0x12);
181Preferences preferences;
182
183
184// base path (can be SPIFFS_MOUNT_PATH or SDCARD_MOUNT_PATH depending from what was successfully mounted first)
185char const * basepath = nullptr;
186
187
188using std::string;
189
190
191TermType getTerminalEmu()
192{
193 return (TermType) preferences.getInt("termEmu", DefaultTermIndex);
194}
195
196
197void setupTerminalEmu()
198{
199 Terminal.setTerminalType(getTerminalEmu());
200}
201
202
203// 0 = max
204int getRowsCount()
205{
206 return preferences.getInt("rowsCount", DefaultRowsCount);
207}
208
209
210void setupRowsCount()
211{
212 int rows = getRowsCount();
213 if (rows <= 0)
214 Terminal.write("\e[r"); // disable scrolling region
215 else
216 Terminal.printf("\e[1;%dr", rows); // enable scrolling region (1..rows)
217}
218
219
220int getKbdLayoutIndex()
221{
222 return preferences.getInt("kbdLay", DefaultKbdLayIndex);
223}
224
225
226void setupKbdLayout()
227{
228 PS2Controller.keyboard()->setLayout( SupportedLayouts::layouts()[getKbdLayoutIndex()] );
229}
230
231
232bool getRealCPUSpeed()
233{
234 return preferences.getBool("realSpeed", false);
235}
236
237
238void setupRealCPUSpeed()
239{
240 altair.setRealSpeed(getRealCPUSpeed());
241}
242
243
244// 0 = 8080, 1 = Z80
245int getCPU()
246{
247 return preferences.getInt("CPU", DefaultCPU);
248}
249
250
251bool getEmuCRT()
252{
253 return preferences.getBool("emuCRT", false);
254}
255
256
257int getColorsIndex()
258{
259 return preferences.getInt("colors", DefaultColorsIndex);
260}
261
262
263void setupTerminalColors()
264{
265 int colorsIndex = getColorsIndex();
266 Terminal.setForegroundColor(TextColors[colorsIndex]);
267 Terminal.setBackgroundColor(BackColors[colorsIndex]);
268}
269
270
271// shown pressing PAUSE
272void emulator_menu()
273{
274 bool resetRequired = false;
275 bool changedRowsCount = false;
276
277 for (bool loop = true; loop; ) {
278
279 diskDrive.flush();
280
281 Terminal.setTerminalType(TermType::ANSILegacy);
282
283 Terminal.write("\r\n\n\e[97m\e[40m ** Emulator Menu **\e[K\r\n\e[K\n");
284 Terminal.write( "\e[93m Z \e[37m Reset\e[K\n\r");
285 Terminal.write( "\e[93m S \e[37m Send Disk to Serial\e[K\n\r");
286 Terminal.write( "\e[93m R \e[37m Get Disk from Serial\e[K\n\r");
287 Terminal.write( "\e[93m F \e[37m Format FileSystem\e[K\n\r");
288 Terminal.printf("\e[93m U \e[37m CPU: \e[33m%s\e[K\n\r", getCPU() == 1 ? "Z80" : "i8080");
289 Terminal.printf("\e[93m P \e[37m Real CPU Speed: \e[33m%s\e[K\n\r", getRealCPUSpeed() ? "YES" : "NO");
290 Terminal.write("\e[6A"); // cursor UP
291 Terminal.printf("\t\t\t\t\t\e[93m T \e[37m Terminal: \e[33m%s\e[K\n\r", SupportedTerminals::names()[(int)getTerminalEmu()] );
292 Terminal.printf("\t\t\t\t\t\e[93m K \e[37m Keyboard Layout: \e[33m%s\e[K\n\r", SupportedLayouts::names()[getKbdLayoutIndex()] );
293 #ifndef USE_TEXTUAL_DISPLAYCONTROLLER
294 Terminal.printf("\t\t\t\t\t\e[93m G \e[37m CRT Mode: \e[33m%s\e[K\n\r", getEmuCRT() ? "YES" : "NO");
295 #endif
296 Terminal.printf("\t\t\t\t\t\e[93m C \e[37m Colors: \e[33m%s\e[K\n\r", ColorsStr[getColorsIndex()] );
297 Terminal.printf("\t\t\t\t\t\e[93m L \e[37m Rows: \e[33m%d\e[K\n\r", getRowsCount() <= 0 ? Terminal.getRows() : getRowsCount());
298 Terminal.write( "\t\t\t\t\t\e[93m O \e[37m Reset Configuration\e[K\n\r");
299
300 Terminal.write("\n\n\e[97mPlease select an option (ENTER to exit): \e[K\e[92m");
301 int ch = toupper(Terminal.read());
302 Terminal.write(ch);
303 Terminal.write("\n\r");
304 switch (ch) {
305
306 // 1. Send a disk image to serial port (console UART)
307 // 2. Receive a disk image from serial port (console UART)
308 case 'S':
309 case 'R':
310 {
311 Terminal.write("Select a drive (A, B, C, D...): ");
312 char drive = toupper(Terminal.read());
313 if (ch == 'S') {
314 Terminal.printf("\n\rSending drive %c...\n\r", drive);
315 diskDrive.sendDiskImageToStream(drive - 'A', &Console);
316 } else if (ch == 'R') {
317 Terminal.printf("\n\rReceiving drive %c...\n\r", drive);
318 diskDrive.receiveDiskImageFromStream(drive - 'A', &Console);
319 }
320 break;
321 }
322
323 // Format FileSystem
324 case 'F':
325 Terminal.write("\e[91mFormat deletes all disks and files in your SD or SPIFFS!\e[92m\r\nAre you sure? (Y/N)");
326 if (toupper(Terminal.read()) == 'Y') {
327 Terminal.write("\n\rFormatting...");
328 Terminal.flush();
330 resetRequired = true;
331 }
332 break;
333
334 // Reset
335 case 'Z':
336 Terminal.write("Resetting the Altair. Are you sure? (Y/N)");
337 if (toupper(Terminal.read()) == 'Y')
338 esp_restart();
339 break;
340
341 // Real CPU speed
342 case 'P':
343 preferences.putBool("realSpeed", !getRealCPUSpeed());
344 setupRealCPUSpeed();
345 break;
346
347 // Emulate CRT
348 case 'G':
349 preferences.putBool("emuCRT", !getEmuCRT());
350 resetRequired = true;
351 break;
352
353 // CPU
354 case 'U':
355 preferences.putInt("CPU", getCPU() ^ 1);
356 resetRequired = true;
357 break;
358
359 // Terminal emulation
360 case 'T':
361 {
362 int termIndex = (int)getTerminalEmu() + 1;
363 if (termIndex > MaxTermIndex)
364 termIndex = 0;
365 preferences.putInt("termEmu", termIndex);
366 break;
367 }
368
369 // Keyboard layout
370 case 'K':
371 {
372 int kbdLayIndex = getKbdLayoutIndex() + 1;
373 if (kbdLayIndex >= SupportedLayouts::count())
374 kbdLayIndex = 0;
375 preferences.putInt("kbdLay", kbdLayIndex);
376 setupKbdLayout();
377 break;
378 }
379
380 // Colors
381 case 'C':
382 {
383 int colorsIndex = getColorsIndex() + 1;
384 if (colorsIndex > MaxColorsIndex)
385 colorsIndex = 0;
386 preferences.putInt("colors", colorsIndex);
387 break;
388 }
389
390 // Rows
391 case 'L':
392 {
393 int rows = getRowsCount() + 1;
394 if (rows < 24)
395 rows = 24; // min
396 if (rows > 25)
397 rows = 0; // max
398 preferences.putInt("rowsCount", rows);
399 changedRowsCount = true;
400 break;
401 }
402
403 // Reset configuration
404 case 'O':
405 preferences.clear();
406 resetRequired = true;
407 break;
408
409 default:
410 loop = false;
411 break;
412
413 }
414 }
415
416 if (resetRequired) {
417 Terminal.write("Reset required. Reset now? (Y/N)");
418 if (toupper(Terminal.read()) == 'Y') {
419 diskDrive.detachAll();
420 esp_restart();
421 }
422 }
423
424 Terminal.localWrite("\n");
425
426 if (changedRowsCount) {
427 setupRowsCount();
428 Terminal.clear();
429 Terminal.write("Clear screen required. Settings applied.\r\n\e\n");
430 }
431
432 setupTerminalColors();
433 setupTerminalEmu();
434}
435
436
437void setup()
438{
439 Console.begin();
440
441 preferences.begin("altair8800", false);
442
443
444 // setup Keyboard (default configuration)
445 PS2Controller.begin(PS2Preset::KeyboardPort0);
446
447 // setup VGA (default configuration with 64 colors)
448 DisplayController.begin();
449
450 if (getEmuCRT())
451 DisplayController.setResolution(VGA_640x200_70HzRetro);
452 else
453 DisplayController.setResolution(VGA_640x200_70Hz);
454
455 Terminal.begin(&DisplayController);
456 Terminal.connectLocally(); // to use Terminal.read(), available(), etc..
457
458 Terminal.setBackgroundColor(Color::Black);
459 Terminal.setForegroundColor(Color::BrightGreen);
460 Terminal.clear();
461
462 Terminal.enableCursor(true);
463}
464
465
466void attachDisk(int drive, void const * data)
467{
468 auto filename = (char const *)data;
469 auto dskimage = (uint8_t const *) data;
470
471 FileBrowser fb(basepath);
472
473 if (dskimage[0] >= 0x80) {
474 // "data" is a disk image
476 // when storage is SD Card, copy read only disk image into a file, if doesn't already exist
477 char newfilename[10] = { 'd', 'i', 's', 'k', (char)('A' + drive), '.', 'd', 's', 'k' };
478 Terminal.printf("\r\nAttaching disk %c to %s...", 'A' + drive, newfilename);
479 auto sz = fb.getFullPath(newfilename, nullptr, 0);
480 char newfilenamePath[sz];
481 fb.getFullPath(newfilename, newfilenamePath, sz);
482 diskDrive.attachFileFromImage(drive, newfilenamePath, dskimage);
483 } else {
484 // when storage is SPIFFS just mount image as Read Only image
485 diskDrive.attachReadOnlyBuffer(drive, dskimage);
486 }
487 } else {
488 if ((uint8_t)filename[0] < 0x80) {
489 // "data" is a filename
490 Terminal.printf("\r\nAttaching disk %c to %s...", 'A' + drive, filename);
491 Terminal.flush();
492 auto sz = fb.getFullPath(filename, nullptr, 0);
493 char filenamePath[sz];
494 fb.getFullPath(filename, filenamePath, sz);
495 diskDrive.attachFile(drive, filenamePath);
496 }
497 }
498}
499
500
501void loop()
502{
503 if (FileBrowser::mountSDCard(FORMAT_ON_FAIL, SDCARD_MOUNT_PATH))
504 basepath = SDCARD_MOUNT_PATH;
505 else if (FileBrowser::mountSPIFFS(FORMAT_ON_FAIL, SPIFFS_MOUNT_PATH))
506 basepath = SPIFFS_MOUNT_PATH;
507
508 // setup disk drives
509
510 attachDisk(0, DRIVE_A);
511 attachDisk(1, DRIVE_B);
512 attachDisk(2, DRIVE_C);
513 attachDisk(3, DRIVE_D);
514
515 // setup SIOs (Serial I/O)
516
517 // TTY
518 SIO0.attachStream(&Terminal);
519
520 // CRT/Keyboard
521 SIO1.attachStream(&Terminal);
522
523 // Serial (console UART)
524 SIO2.attachStream(&Console);
525
526 // RAM
527 altair.attachRAM(65536);
528
529 // boot ROM
530 altair.load(Altair88DiskBootROMAddr, Altair88DiskBootROM, sizeof(Altair88DiskBootROM));
531
532 // menu callback (pressing PAUSE or F12)
533 altair.setMenuCallback(emulator_menu);
534
535 setupTerminalColors();
536 Terminal.clear();
537
538 setupRowsCount();
539
540 Terminal.write("\e[97m\e[44m");
541 Terminal.write(" /* * * * * * * * * * * * * * * * * * * *\e[K\r\n");
542 Terminal.write(" A L T A I R 8 8 0 0 \e[K\r\n");
543 Terminal.write(" \e[37mby Fabrizio Di Vittorio - www.fabgl.com\e[97m\e[K\r\n");
544 Terminal.write(" * * * * * * * * * * * * * * * * * * * */\e[K\r\n\e[K\n");
545
546 Terminal.printf("\e[33mFree Memory :\e[32m %d bytes\e[K\r\n", heap_caps_get_free_size(MALLOC_CAP_32BIT));
547
548 int64_t total, used;
549 FileBrowser::getFSInfo(FileBrowser::getDriveType(basepath), 0, &total, &used);
550 Terminal.printf("\e[33mFile System :\e[32m %lld KiB used, %lld KiB free\e[K\r\n", used / 1024, (total - used) / 1024);
551
552 Terminal.printf("\e[33mKbd Layout : \e[32m%s\e[K\r\n", SupportedLayouts::names()[getKbdLayoutIndex()] );
553 Terminal.printf("\e[33mCPU : \e[32m%s\e[92m\e[K\r\n\e[K\n", getCPU() == 1 ? "Z80" : "i8080");
554
555 Terminal.printf("Press \e[93m[F12]\e[92m or \e[93m[PAUSE]\e[92m to display emulator menu\e[K\r\n");
556
557 setupTerminalColors();
558
559 Terminal.setColorForAttribute(CharStyle::Bold, Color::BrightYellow, false);
560 Terminal.setColorForAttribute(CharStyle::Italic, Color::BrightRed, false);
561 Terminal.setColorForAttribute(CharStyle::Underline, Color::BrightWhite, false);
562 Terminal.setColorForAttribute(CharStyle::ReducedLuminosity, Color::BrightYellow, false);
563
564 // setup keyboard layout
565 setupKbdLayout();
566
567 // setup terminal emulation
568 setupTerminalEmu();
569
570 // CPU speed
571 setupRealCPUSpeed();
572
573 CPU cpu = (getCPU() == 1 ? CPU::Z80 : CPU::i8080);
574 altair.run(cpu, Altair88DiskBootROMRun);
575}
576
577
578extern "C" void app_main()
579{
580 setup();
581 while (true)
582 loop();
583}
static bool mountSPIFFS(bool formatOnFail, char const *mountPath, size_t maxFiles=4)
Mounts the SPIFFS (Flash) filesystem.
static bool format(DriveType driveType, int drive)
Formats SPIFFS or SD Card.
static bool mountSDCard(bool formatOnFail, char const *mountPath, size_t maxFiles=4, int allocationUnitSize=16 *1024, int MISO=16, int MOSI=17, int CLK=14, int CS=13)
Mounts the filesystem of the SD Card.
static DriveType getDriveType(char const *path)
Returns the drive type of the specified path.
static bool getFSInfo(DriveType driveType, int drive, int64_t *total, int64_t *used)
Gets the total and used space of a filesystem.
FileBrowser provides basic file system operations (directory listing, mkdir, remove and rename).
Definition fabutils.h:698
bool clear()
Removes all keys of the namespace.
bool begin(char const *name, bool readOnly=false)
Opens the specified namespace.
Simple key/value storage in non-volatile flash (NVS).
Definition preferences.h:61
void setLayout(KeyboardLayout const *layout)
Sets the keyboard layout.
Definition keyboard.cpp:224
static Keyboard * keyboard()
Returns the Keyboard object automatically created by PS2Controller.
static void begin(gpio_num_t port0_clkGPIO, gpio_num_t port0_datGPIO, gpio_num_t port1_clkGPIO=GPIO_UNUSED, gpio_num_t port1_datGPIO=GPIO_UNUSED)
Initializes the PS/2 device controller.
PS/2 device controller.
void connectLocally()
Allows the terminal to be used locally.
Definition terminal.cpp:439
int getRows()
Returns the number of lines.
Definition terminal.h:1075
void clear(bool moveCursor=true)
Clears the screen.
Definition terminal.cpp:797
size_t write(const uint8_t *buffer, size_t size)
Sends the specified number of codes to the display.
void localWrite(uint8_t c)
Appends a key to the keyboard queue.
int read()
Reads codes from keyboard.
void enableCursor(bool value)
Enables or disables the cursor.
Definition terminal.cpp:902
void setColorForAttribute(CharStyle attribute, Color color, bool maintainStyle)
Selects a color for the specified attribute.
Definition terminal.cpp:764
void setTerminalType(TermType value)
Sets the terminal type to emulate.
void setBackgroundColor(Color color, bool setAsDefault=true)
Sets the background color.
Definition terminal.cpp:707
bool begin(BaseDisplayController *displayController, int maxColumns=-1, int maxRows=-1, Keyboard *keyboard=nullptr)
Initializes the terminal.
Definition terminal.cpp:307
void flush(bool waitVSync)
Waits until all codes sent to the display have been processed.
Definition terminal.cpp:674
void setForegroundColor(Color color, bool setAsDefault=true)
Sets the foreground color.
Definition terminal.cpp:727
An ANSI-VT100 compatible display terminal.
Definition terminal.h:883
bool begin(int port=0, int baud=0, int rxPin=-1, int txPin=-1, int rxBufferSize=1024, int txBufferSize=0)
Initializes the UART.
A Stream implemented on top of the ESP-IDF UART driver.
Definition uartstream.h:68
VGA bitmapped display controller with 16 colors.
void begin(gpio_num_t redGPIO, gpio_num_t greenGPIO, gpio_num_t blueGPIO, gpio_num_t HSyncGPIO, gpio_num_t VSyncGPIO)
Initializer for 8 colors (5 GPIOs).
void setResolution(char const *modeline=nullptr, int viewPortWidth=-1, int viewPortHeight=-1, bool doubleBuffered=false)
Sets the fixed resolution.
VGA text-only display controller.
TermType
Supported terminals.
Definition terminfo.h:110
Color
Named colors.
Single include file of the FabGL library.
#define VGA_640x200_70HzRetro
Definition fabglconf.h:216
#define VGA_640x200_70Hz
Definition fabglconf.h:213
This file contains utility classes and functions.