cpu_8080.o: cpu_8080.h
-emu_8080_alt: emu_8080_alt.o 8080_cpu.o
+emu_8080_alt: emu_8080_alt.o i8080.o
${CC} ${CFLAGS} -o $@ $^
-emu_8080_alt.o: emu_8080.c intel-8080/cpu.h
+emu_8080_alt.o: emu_8080.c 8080/i8080.h
${CC} ${CFLAGS} ${ALT_8080_CFLAGS} -o $@ -c $<
-8080_cpu.o: intel-8080/cpu.c intel-8080/cpu.h
- ${CC} ${CFLAGS} ${ALT_8080_CFLAGS} -o $@ -c $<
+i8080.o: 8080/i8080.c 8080/i8080.h
+ ${CC} ${CFLAGS} ${ALT_8080_CFLAGS} -c $<
mbasic.ihx: cpm_compilers/Microsoft\ BASIC-80\ v521/MBASIC.COM
${BIN2HEX} --offset=0x100 "$<" __temp__.ihx
#include <stdlib.h>
#include <string.h>
#if ALT_BACKEND
-#include "intel-8080/cpu.h"
+#include "8080/i8080.h"
#else
#include "cpu_8080.h"
#endif
return a;
}
-#if ALT_BACKEND
-uint8_t read_byte(uint16_t addr)
-#else
-int read_byte(void *context, int addr)
-#endif
-{
+int read_byte(void *context, int addr) {
#if MEM_TRACE
int data = mem[addr];
fprintf(stderr, "addr=%04x rd=%02x\n", addr, data);
#endif
}
-#if ALT_BACKEND
-void write_byte(uint16_t addr, uint8_t data)
-#else
-void write_byte(void *context, int addr, int data)
-#endif
-{
+void write_byte(void *context, int addr, int data) {
#if MEM_TRACE
fprintf(stderr, "addr=%04x wr=%02x\n", addr, data);
#endif
io_write[addr] = data;
}
+#if ALT_BACKEND
+uint8_t rb(void *userdata, uint16_t addr) {
+ return read_byte(NULL, addr);
+}
+
+void wb(void *userdata, uint16_t addr, uint8_t val) {
+ write_byte(NULL, addr, val);
+}
+
+uint8_t in(void *userdata, uint8_t port) {
+ return in_byte(NULL, port);
+}
+
+void out(void *userdata, uint8_t port, uint8_t val) {
+ out_byte(NULL, port, val);
+}
+#endif
+
int main(int argc, char **argv) {
if (argc < 2) {
printf("usage: %s image.ihx\n", argv[0]);
mem[BIOS_SECTRAN] = 0xc9; // ret
#if ALT_BACKEND
- regs.pc = entry_point;
- regs.sp = BDOS - 2; // assume word at BDOS - 2 is initialized to 0
+ i8080 cpu;
+ i8080_init(&cpu);
+ cpu.read_byte = rb;
+ cpu.write_byte = wb;
+ cpu.port_in = in;
+ cpu.port_out = out;
+ cpu.pc = entry_point;
+ cpu.sp = BDOS - 2; // assume word at BDOS - 2 is initialized to 0
while (true) {
#if REG_TRACE
fprintf(
stderr,
"pc=%04x psw=%04x bc=%04x de=%04x hl=%04x sp=%04x cf=%d pf=%d acf=%d zf=%d sf=%d\n",
- regs.pc,
- regs.cf |
+ cpu.pc,
+ cpu.cf |
2 |
- (regs.pf << 2) |
- (regs.acf << 4) |
- (regs.zf << 6) |
- (regs.sf << 7) |
- (regs.a << 8),
- regs.c | (regs.b << 8),
- regs.e | (regs.d << 8),
- regs.l | (regs.h << 8),
- regs.sp,
- regs.cf,
- regs.pf,
- regs.acf,
- regs.zf,
- regs.sf
+ (cpu.pf << 2) |
+ (cpu.hf << 4) |
+ (cpu.zf << 6) |
+ (cpu.sf << 7) |
+ (cpu.a << 8),
+ cpu.c | (cpu.b << 8),
+ cpu.e | (cpu.d << 8),
+ cpu.l | (cpu.h << 8),
+ cpu.sp,
+ cpu.cf,
+ cpu.pf,
+ cpu.hf,
+ cpu.zf,
+ cpu.sf
);
#endif
- if (regs.pc == BDOS) {
- int de = regs.e | (regs.d << 8);
- uint16_t hl = regs.l | (regs.h << 8);
- regs.a = bdos(regs.a, regs.c, de, &hl);
- regs.l = (uint8_t)hl;
- regs.h = (uint8_t)(hl >> 8);
+ if (cpu.pc == BDOS) {
+ int de = cpu.e | (cpu.d << 8);
+ uint16_t hl = cpu.l | (cpu.h << 8);
+ cpu.a = bdos(cpu.a, cpu.c, de, &hl);
+ cpu.l = (uint8_t)hl;
+ cpu.h = (uint8_t)(hl >> 8);
}
- else if (regs.pc >= BIOS_BOOT)
- regs.a = bios(regs.pc, regs.a, regs.c);
+ else if (cpu.pc >= BIOS_BOOT)
+ cpu.a = bios(cpu.pc, cpu.a, cpu.c);
- instruction(read_next_byte()); // should check return code (HLT, RST)
+ i8080_step(&cpu);
}
#else
struct cpu_8080 cpu;