Change from /emu8051 submodule to /cpu8051 submodule, based on https://github.com... master
authorNick Downing <nick@ndcode.org>
Wed, 6 May 2026 01:44:29 +0000 (11:44 +1000)
committerNick Downing <nick@ndcode.org>
Wed, 6 May 2026 04:33:12 +0000 (14:33 +1000)
.gitmodules
Makefile
cpu8051 [new submodule]
emu8051 [deleted submodule]
emu_8051.c

index 718e830..b44451f 100644 (file)
@@ -55,6 +55,6 @@
 [submodule "udis"]
        path = udis
        url = https://github.com/nickd4/udis.git
-[submodule "emu8051"]
-       path = emu8051
-       url = https://github.com/nickd4/emu8051.git
+[submodule "cpu8051"]
+       path = cpu8051
+       url = https://github.com/nickd4/cpu8051.git
index 297962f..7dbee64 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -327,41 +327,16 @@ mbasic.ihx: cpm_compilers/Microsoft\ BASIC-80\ v521/MBASIC.COM
        rm __temp__.ihx
 
 # 8051
-emu_8051_alt: \
-emu_8051_alt.o \
-cpu8051.o \
-instructions_8051.o \
-memory.o \
-operations.o \
-psw.o \
-sfr.o
+emu_8051_alt: emu_8051_alt.o execute.o inst.o
        ${CC} ${CFLAGS} -o $@ $^
 
-emu_8051_alt.o: \
-emu_8051.c \
-emu8051/src/common/cpu8051.h \
-emu8051/src/common/memory.h \
-emu8051/src/common/reg8051.h
+emu_8051_alt.o: emu_8051.c
        ${CC} ${CFLAGS} ${ALT_8051_CFLAGS} -o $@ -c $<
 
-cpu8051.o: emu8051/src/common/cpu8051.c emu8051/src/common/cpu8051.h
+execute.o: cpu8051/src/execute.c
        ${CC} ${CFLAGS} ${ALT_8051_CFLAGS} -o $@ -c $<
 
-instructions_8051.o: \
-emu8051/src/common/instructions_8051.c \
-emu8051/src/common/instructions_8051.h
-       ${CC} ${CFLAGS} ${ALT_8051_CFLAGS} -o $@ -c $<
-
-memory.o: emu8051/src/common/memory.c emu8051/src/common/memory.h
-       ${CC} ${CFLAGS} ${ALT_8051_CFLAGS} -o $@ -c $<
-
-operations.o: emu8051/src/common/operations.c emu8051/src/common/operations.h
-       ${CC} ${CFLAGS} ${ALT_8051_CFLAGS} -o $@ -c $<
-
-psw.o: emu8051/src/common/psw.c emu8051/src/common/psw.h
-       ${CC} ${CFLAGS} ${ALT_8051_CFLAGS} -o $@ -c $<
-
-sfr.o: emu8051/src/common/sfr.c emu8051/src/common/sfr.h
+inst.o: cpu8051/src/inst.c
        ${CC} ${CFLAGS} ${ALT_8051_CFLAGS} -o $@ -c $<
 
 basic-52.ihx:
diff --git a/cpu8051 b/cpu8051
new file mode 160000 (submodule)
index 0000000..41d15f6
--- /dev/null
+++ b/cpu8051
@@ -0,0 +1 @@
+Subproject commit 41d15f682d911351b073a849bc68249d46ebc639
diff --git a/emu8051 b/emu8051
deleted file mode 160000 (submodule)
index 32aeb9b..0000000
--- a/emu8051
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 32aeb9be8b67793a887a8a2bf841fba4c9738086
index 90ced63..221ecfc 100644 (file)
@@ -4,9 +4,7 @@
 #include <stdlib.h>
 #include <string.h>
 #if ALT_BACKEND
-#include "emu8051/src/common/cpu8051.h"
-#include "emu8051/src/common/memory.h"
-#include "emu8051/src/common/reg8051.h"
+#include "cpu8051/src/8051.h"
 #else
 #include "cpu_8051.h"
 #endif
@@ -43,6 +41,7 @@
 
 #define P3_RXD 0
 
+#if !ALT_BACKEND // also defined in 8051.h
 #define PSW_P 0
 #define PSW_UD 1
 #define PSW_OV 2
@@ -51,6 +50,7 @@
 #define PSW_F0 5
 #define PSW_AC 6
 #define PSW_CY 7
+#endif
 
 // 0x00000..0x0ffff: code
 // 0x10000..0x1ffff: xram
@@ -179,9 +179,9 @@ int read_byte(void *context, int addr) {
   static int rxd_count;
   switch (addr) {
   case MEM_P3:
-    // make RXD input toggle after each 2 reads
+    // make RXD input toggle after each read
     // necessary to pass the auto-baud code in basic-52.ihx
-    data = ((rxd_count >> 1) & (1 << P3_RXD)) | (mem[MEM_P3] & ~(1 << P3_RXD));
+    data = (rxd_count & (1 << P3_RXD)) | (mem[MEM_P3] & ~(1 << P3_RXD));
     ++rxd_count;
     break;
   default:
@@ -249,39 +249,6 @@ void write_byte(void *context, int addr, int data) {
   }
 }
 
-#if ALT_BACKEND
-void mem_write8(enum mem_id_t id, unsigned long address, uint8_t value) {
-  switch (id) {
-  case INT_MEM_ID:
-    write_byte(NULL, 0x20000 + (address & 0xff) + (address & 0x80), value);
-    break;
-  case EXT_MEM_ID:
-    write_byte(NULL, 0x20080 + (address & 0x7f), value);
-    break;
-  case XRAM_MEM_ID:
-    write_byte(NULL, 0x10000 + (address & 0xffff), value);
-    break;
-  default:
-    abort();
-  }
-}
-
-uint8_t mem_read8(enum mem_id_t id, unsigned long address) {
-  switch (id) {
-  case PGM_MEM_ID:
-    return read_byte(NULL, address & 0xffff);
-  case INT_MEM_ID:
-    return read_byte(NULL, 0x20000 + (address & 0xff) + (address & 0x80));
-  case EXT_MEM_ID:
-    return read_byte(NULL, 0x20080 + (address & 0x7f));
-  case XRAM_MEM_ID:
-    return read_byte(NULL, 0x10000 + (address & 0xffff));
-  default:
-    abort();
-  }
-}
-#endif
-
 int main(int argc, char **argv) {
   if (argc < 2) {
     printf("usage: %s image.ihx\n", argv[0]);
@@ -289,19 +256,23 @@ int main(int argc, char **argv) {
   }
   int entry_point = load_ihx(argv[1]);
 
+  write_byte(NULL, MEM_P0, 0xff);
+  write_byte(NULL, MEM_P1, 0xff);
+  write_byte(NULL, MEM_P2, 0xff);
+  write_byte(NULL, MEM_P3, 0xff);
+
 #if ALT_BACKEND
-  cpu8051_init();
-  cpu8051_reset();
-  cpu8051.pc = entry_point;
+  reset_cpu();
+  pc = entry_point;
 
   while (true) {
 #if REG_TRACE
     fprintf(
       stderr,
       "pc=%04x a=%02x b=%02x r0=%02x r1=%02x r2=%02x r3=%02x r4=%02x r5=%02x r6=%02x r7=%02x sp=%02x dptr=%04x p=%d ud=%d ov=%d rs=%d f0=%d ac=%d cy=%d\n",
-      cpu8051.pc,
-      mem[MEM_ACC],
-      mem[MEM_B],
+      pc,
+      acc,
+      b,
       mem[0x20000],
       mem[0x20001],
       mem[0x20002],
@@ -310,19 +281,19 @@ int main(int argc, char **argv) {
       mem[0x20005],
       mem[0x20006],
       mem[0x20007],
-      mem[MEM_SP],
-      mem[MEM_DPL] | (mem[MEM_DPH] << 8),
-      (mem[MEM_PSW] >> PSW_P) & 1,
-      (mem[MEM_PSW] >> PSW_UD) & 1,
-      (mem[MEM_PSW] >> PSW_OV) & 1,
-      (mem[MEM_PSW] >> PSW_RS0) & 3,
-      (mem[MEM_PSW] >> PSW_F0) & 1,
-      (mem[MEM_PSW] >> PSW_AC) & 1,
-      (mem[MEM_PSW] >> PSW_CY) & 1
+      sp,
+      dptr,
+      (psw >> PSW_P) & 1,
+      (psw >> PSW_UD) & 1,
+      (psw >> PSW_OV) & 1,
+      (psw >> PSW_RS0) & 3,
+      (psw >> PSW_F0) & 1,
+      (psw >> PSW_AC) & 1,
+      (psw >> PSW_CY) & 1
     );
 #endif
 
-    if (cpu8051.pc == 0x79b && (mem[MEM_SCON] & (1 << SCON_RI)) == 0) {
+    if (pc == 0x79b && (mem[MEM_SCON] & (1 << SCON_RI)) == 0) {
       int c = getchar();
       switch (c) {
       case EOF:
@@ -334,7 +305,8 @@ int main(int argc, char **argv) {
       mem[MEM_SBUF] = (uint8_t)c;
       mem[MEM_SCON] |= 1 << SCON_RI;
     }
-    cpu8051_exec();
+    Decode_t d;
+    execute(&d);
   }
 #else
   struct cpu_8051 cpu;