Switch emu_8080_alt to use /8080 submodule by superzazu, remove /intel-8080
authorNick Downing <nick@ndcode.org>
Thu, 4 Dec 2025 03:33:17 +0000 (14:33 +1100)
committerNick Downing <nick@ndcode.org>
Thu, 4 Dec 2025 03:51:55 +0000 (14:51 +1100)
.gitmodules
8080 [new submodule]
Makefile
emu_8080.c

index da21646..193cb75 100644 (file)
@@ -46,9 +46,9 @@
 [submodule "cpm_compilers"]
        path = cpm_compilers
        url = https://github.com/davidly/cpm_compilers.git
-[submodule "intel-8080"]
-       path = intel-8080
-       url = https://github.com/nickd4/intel-8080.git
 [submodule "jefftranter_8080"]
        path = jefftranter_8080
        url = https://github.com/nickd4/jefftranter_8080.git
+[submodule "8080"]
+       path = 8080
+       url = https://github.com/nickd4/8080.git
diff --git a/8080 b/8080
new file mode 160000 (submodule)
index 0000000..1864f69
--- /dev/null
+++ b/8080
@@ -0,0 +1 @@
+Subproject commit 1864f69b79f646269078773bf3c5e47afc3ff580
index d042b92..f8c5409 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -307,14 +307,14 @@ emu_8080.o: cpu_8080.h
 
 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
index ec5c5c3..27c6b50 100644 (file)
@@ -4,7 +4,7 @@
 #include <stdlib.h>
 #include <string.h>
 #if ALT_BACKEND
-#include "intel-8080/cpu.h"
+#include "8080/i8080.h"
 #else
 #include "cpu_8080.h"
 #endif
@@ -294,12 +294,7 @@ int bios(int pc, int a, int c) {
   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);
@@ -309,12 +304,7 @@ int read_byte(void *context, int addr)
 #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
@@ -340,6 +330,24 @@ void out_byte(void *context, int addr, int data) {
   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]);
@@ -444,45 +452,51 @@ int main(int argc, char **argv) {
   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;