The video output is a 80x25 text terminal (ADM-31 emulation by default) on VGA; the keyboard is a PS/2 keyboard.
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.
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.
The settings are saved in NVS.
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):
Close any serial monitor before running the scripts.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40#include "esp_system.h"
41#include <string>
42
43
45
46
47
50
51#include "src/machine.h"
52
53
54
55
56#define FORMAT_ON_FAIL true
57#define SPIFFS_MOUNT_PATH "/flash"
58#define SDCARD_MOUNT_PATH "/SD"
59
60
61
62#define USE_TEXTUAL_DISPLAYCONTROLLER
63
64
66
67
68
69
70#include "disks/CPM22/cpm22_dsk.h"
71#include "disks/CPM22/games_dsk.h"
72#include "disks/CPM22/turbopascal3_dsk.h"
73#include "disks/CPM22/wordstar3_dsk.h"
74#include "disks/CPM22/wordstar4_dsk.h"
75#include "disks/CPM22/multiplan_dsk.h"
76#include "disks/CPM22/dbaseii_dsk.h"
77#include "disks/CPM22/BDSC_dsk.h"
78#include "disks/CPM22/langs_dsk.h"
79
80
81#include "disks/CPM14/cpm141_dsk.h"
82
83
84#include "disks/CPM3/cpm3_disk1_dsk.h"
85#include "disks/CPM3/cpm3_disk2_dsk.h"
86#include "disks/CPM3/cpm3_build_dsk.h"
87
88
89
90
91
92
93
94#include "disks/AltairDOS/DOS_1_dsk.h"
95#include "disks/AltairDOS/DOS_2_dsk.h"
96
97
98
99
100
101
102
103#include "disks/basic/basic5_dsk.h"
104
106
107
108
110
111
112
113
114#include "minidisks/CPM22/cpm22_disk1_minidsk.h"
115#include "minidisks/CPM22/cpm22_disk2_minidsk.h"
116
117
118
119
120
121
122
123#include "minidisks/basic/basic300_5F_minidisk.h"
124
126
127
128
130
131
132
133#define DISKFORMAT Disk_338K
134
135
136
137
138
139#define DRIVE_A cpm22_dsk
140#define DRIVE_B games_dsk
141#define DRIVE_C "diskC.dsk"
142#define DRIVE_D "diskD.dsk"
143
145
146
147
148
149
150constexpr int DefaultCPU = 1;
151
152constexpr int DefaultTermIndex = 2;
153constexpr int MaxTermIndex = 7;
154
155constexpr int DefaultKbdLayIndex = 2;
156
157constexpr int DefaultRowsCount = 0;
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;
163constexpr int MaxColorsIndex = 5;
164
165
166
167
168#ifdef USE_TEXTUAL_DISPLAYCONTROLLER
170#else
172#endif
175
176Machine altair;
177Mits88Disk diskDrive(&altair, DISKFORMAT);
178SIO SIO0(&altair, 0x00);
179SIO SIO1(&altair, 0x10);
180SIO SIO2(&altair, 0x12);
182
183
184
185char const * basepath = nullptr;
186
187
188using std::string;
189
190
192{
193 return (
TermType) preferences.getInt(
"termEmu", DefaultTermIndex);
194}
195
196
197void setupTerminalEmu()
198{
200}
201
202
203
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");
215 else
216 Terminal.printf("\e[1;%dr", 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
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();
268}
269
270
271
272void emulator_menu()
273{
274 bool resetRequired = false;
275 bool changedRowsCount = false;
276
277 for (bool loop = true; loop; ) {
278
279 diskDrive.flush();
280
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");
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());
303 Terminal.
write(
"\n\r");
304 switch (ch) {
305
306
307
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
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...");
330 resetRequired = true;
331 }
332 break;
333
334
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
342 case 'P':
343 preferences.putBool("realSpeed", !getRealCPUSpeed());
344 setupRealCPUSpeed();
345 break;
346
347
348 case 'G':
349 preferences.putBool("emuCRT", !getEmuCRT());
350 resetRequired = true;
351 break;
352
353
354 case 'U':
355 preferences.putInt("CPU", getCPU() ^ 1);
356 resetRequired = true;
357 break;
358
359
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
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
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
391 case 'L':
392 {
393 int rows = getRowsCount() + 1;
394 if (rows < 24)
395 rows = 24;
396 if (rows > 25)
397 rows = 0;
398 preferences.putInt("rowsCount", rows);
399 changedRowsCount = true;
400 break;
401 }
402
403
404 case 'O':
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
425
426 if (changedRowsCount) {
427 setupRowsCount();
429 Terminal.
write(
"Clear screen required. Settings applied.\r\n\e\n");
430 }
431
432 setupTerminalColors();
433 setupTerminalEmu();
434}
435
436
437void setup()
438{
440
441 preferences.
begin(
"altair8800",
false);
442
443
444
445 PS2Controller.
begin(PS2Preset::KeyboardPort0);
446
447
448 DisplayController.
begin();
449
450 if (getEmuCRT())
452 else
454
455 Terminal.
begin(&DisplayController);
457
461
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
472
473 if (dskimage[0] >= 0x80) {
474
476
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
485 diskDrive.attachReadOnlyBuffer(drive, dskimage);
486 }
487 } else {
488 if ((uint8_t)filename[0] < 0x80) {
489
490 Terminal.printf("\r\nAttaching disk %c to %s...", 'A' + drive, filename);
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{
504 basepath = SDCARD_MOUNT_PATH;
506 basepath = SPIFFS_MOUNT_PATH;
507
508
509
510 attachDisk(0, DRIVE_A);
511 attachDisk(1, DRIVE_B);
512 attachDisk(2, DRIVE_C);
513 attachDisk(3, DRIVE_D);
514
515
516
517
518 SIO0.attachStream(&Terminal);
519
520
521 SIO1.attachStream(&Terminal);
522
523
524 SIO2.attachStream(&Console);
525
526
527 altair.attachRAM(65536);
528
529
530 altair.load(Altair88DiskBootROMAddr, Altair88DiskBootROM, sizeof(Altair88DiskBootROM));
531
532
533 altair.setMenuCallback(emulator_menu);
534
535 setupTerminalColors();
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;
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
563
564
565 setupKbdLayout();
566
567
568 setupTerminalEmu();
569
570
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).
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).
void setLayout(KeyboardLayout const *layout)
Sets the keyboard layout.
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.
void connectLocally()
Allows the terminal to be used locally.
int getRows()
Returns the number of lines.
void clear(bool moveCursor=true)
Clears the screen.
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.
void setColorForAttribute(CharStyle attribute, Color color, bool maintainStyle)
Selects a color for the specified attribute.
void setTerminalType(TermType value)
Sets the terminal type to emulate.
void setBackgroundColor(Color color, bool setAsDefault=true)
Sets the background color.
bool begin(BaseDisplayController *displayController, int maxColumns=-1, int maxRows=-1, Keyboard *keyboard=nullptr)
Initializes the terminal.
void flush(bool waitVSync)
Waits until all codes sent to the display have been processed.
void setForegroundColor(Color color, bool setAsDefault=true)
Sets the foreground color.
An ANSI-VT100 compatible display terminal.
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.
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.
Single include file of the FabGL library.
#define VGA_640x200_70HzRetro
This file contains utility classes and functions.