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:
#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
#define P3_RXD 0
+#if !ALT_BACKEND // also defined in 8051.h
#define PSW_P 0
#define PSW_UD 1
#define PSW_OV 2
#define PSW_F0 5
#define PSW_AC 6
#define PSW_CY 7
+#endif
// 0x00000..0x0ffff: code
// 0x10000..0x1ffff: xram
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:
}
}
-#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]);
}
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],
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:
mem[MEM_SBUF] = (uint8_t)c;
mem[MEM_SCON] |= 1 << SCON_RI;
}
- cpu8051_exec();
+ Decode_t d;
+ execute(&d);
}
#else
struct cpu_8051 cpu;