I8080_cld — Esp32 Devkit C V4 simulation

An interactive Esp32 Devkit C V4 circuit simulation you can run free in your browser on Velxio, by alireza-cs94.

Sketch code

/*
 * CpmBdos.h - tiny CP/M BDOS emulation, enough to run the classic 8080 test
 * programs (TST8080.COM, 8080PRE.COM, CPUTEST.COM, 8080EXM.COM).
 *
 * How the glue works (see host/test_cpm.cpp and src/main.cpp):
 *   - load the .COM file at address 0x0100 and start with PC = 0x0100
 *   - before every step, if PC == 0x0005 the program is calling BDOS:
 *       call cpm_bdos(C, DE, ...), then do a RET yourself (pop PC from the stack)
 *   - if PC == 0x0000 the program did a warm boot = it has finished
 */
#ifndef CPM_BDOS_H
#define CPM_BDOS_H

#include "I8080_common.h"

typedef void (*cpm_putc_fn)(void *user, char ch);

/*
 * func : value of register C (BDOS function number)
 * de   : value of register pair DE
 * rd   : memory read callback (to fetch the '$'-terminated string)
 * Returns false when the program asked to exit (function 0), true otherwise.
 *
 * Implemented: 0 = system reset, 2 = print char in E, 9 = print '$' string at DE.
 */
static inline bool cpm_bdos(uint8_t func, uint16_t de,
                            i8080_read_fn rd, void *memUser,
                            cpm_putc_fn putc_fn, void *outUser) {
    switch (func) {
        case 0:
            return false;
        case 2:
            putc_fn(outUser, (char)(de & 0xFF));
            break;
        case 9: {
            uint16_t addr = de;
            for (uint32_t i = 0; i < 0x10000; i++) {   /* guard against a missing '$' */
                char ch = (char)rd(memUser, addr);
                addr = (uint16_t)(addr + 1);
                if (ch == '$') break;
                putc_fn(outUser, ch);
            }
            break;
        }
        default:
            break;
    }
    return true;
}

#endif /* CPM_BDOS_H */

More projects by alireza-cs94