Implemented timer interrupts, improved debug logging and so on
authorNick Downing <nick@ndcode.org>
Mon, 4 Mar 2019 23:27:08 +0000 (10:27 +1100)
committerNick Downing <nick@ndcode.org>
Mon, 4 Mar 2019 23:27:08 +0000 (10:27 +1100)
debugger.h
emu.h
logmacro.h
machine/z80daisy.h
sim/iosim.cpp
sim/sim0.cpp
sim/simctl.cpp
sim/simglb.cpp
sim/simglb.h

index 04ba4b8..a1a6fd9 100644 (file)
@@ -1,6 +1,10 @@
 #ifndef _DEBUGGER_H
 #define _DEBUGGER_H 1
 
+#if 0 // set to 1 to enable debugging printf
+#define debugger_instruction_hook(addr) fprintf(stderr, "%04x\n", addr);
+#else
 #define debugger_instruction_hook(addr)
+#endif
 
 #endif
diff --git a/emu.h b/emu.h
index c26e4c1..47550c4 100644 (file)
--- a/emu.h
+++ b/emu.h
@@ -42,6 +42,10 @@ public:
     assert(!m_icountptr);
     m_icountptr = &icount;
   }
+  int standard_irq_callback_member(device_t &device, int irqline) {
+    return standard_irq_callback(device, irqline);
+  }
+  virtual int standard_irq_callback(device_t &device, int irqline) = 0;
 };
 
 class machine_config {
@@ -57,23 +61,28 @@ public:
 union PAIR
 {
 //nick#ifdef LSB_FIRST
-       struct { u8 l,h,h2,h3; } b;
-       struct { u16 l,h; } w;
-       struct { s8 l,h,h2,h3; } sb;
-       struct { s16 l,h; } sw;
+  struct { u8 l,h,h2,h3; } b;
+  struct { u16 l,h; } w;
+  struct { s8 l,h,h2,h3; } sb;
+  struct { s16 l,h; } sw;
 //nick#else
-//nick struct { u8 h3,h2,h,l; } b;
-//nick struct { s8 h3,h2,h,l; } sb;
-//nick struct { u16 h,l; } w;
-//nick struct { s16 h,l; } sw;
+//nick  struct { u8 h3,h2,h,l; } b;
+//nick  struct { s8 h3,h2,h,l; } sb;
+//nick  struct { u16 h,l; } w;
+//nick  struct { s16 h,l; } sw;
 //nick#endif
-       u32 d;
-       s32 sd;
+  u32 d;
+  s32 sd;
 };
 
-#define INPUT_LINE_NMI 0
+enum {
+  INPUT_LINE_NMI = -1
+  // device specific input lines start at 0
+};
 
-#define CLEAR_LINE 0
-#define ASSERT_LINE 1
+enum {
+  CLEAR_LINE,
+  ASSERT_LINE
+};
 
 #endif
index 09d6d9d..aa2c6bd 100644 (file)
@@ -2,7 +2,13 @@
 #define _LOGMACRO_H 1
 
 #include <stdio.h>
-#define LOG printf
-#define logerror printf
+
+#if 0 // set to 1 to enable debugging printf
+#define LOG(...) fprintf(stderr, __VA_ARGS__)
+#define logerror(...) fprintf(stderr, __VA_ARGS__)
+#else
+#define LOG(msg, ...)
+#define logerror(msg, ...)
+#endif
 
 #endif
index a054e50..80dcc76 100644 (file)
@@ -21,9 +21,6 @@ public:
   device_z80daisy_interface *daisy_get_irq_device() {
     return NULL;
   }
-  int standard_irq_callback_member(device_t &device, int irqline) {
-    return 0;
-  }
 };
 
 #endif
index e67c39c..6253ab7 100644 (file)
 #include "sim.h"
 #include "simglb.h"
 #include "memory.h"
+#include "../z180/z180.h"
 
 #define BUFSIZE 256            /* max line length of command buffer */
 #define MAX_BUSY_COUNT 10      /* max counter to detect I/O busy waiting
@@ -2620,6 +2621,7 @@ static int get_date(struct tm *t)
  */
 static void time_out(BYTE data)
 {
+#if 1 // set to 0 to disable timer interrupts
        static struct itimerval tim;
        static struct sigaction newact;
 
@@ -2644,6 +2646,7 @@ static void time_out(BYTE data)
                tim.it_value.tv_usec = 0;
                setitimer(ITIMER_REAL, &tim, NULL);
        }
+#endif
 }
 
 /*
@@ -2755,10 +2758,13 @@ static void int_timer(int sig)
 {
        sig = sig;      /* to avoid compiler warning */
 
-#if 0
+#if 1
+ cpu_dev->execute_set_input(Z180_INPUT_LINE_IRQ0, ASSERT_LINE);
+ //fputc('!', stderr);
+#else
        int_int = 1;
-       int_data = 0xff;        /* RST 38H for IM 0, 0FFH for IM 2 */
 #endif
+       int_data = 0xff;        /* RST 38H for IM 0, 0FFH for IM 2 */
 }
 
 #if defined(NETWORKING) && defined(TCPASYNC)
index a3af822..d651fed 100644 (file)
@@ -326,11 +326,18 @@ puts(" #####    ###     #####    ###            #####    ###   #     #");
 static void init_cpu(void)
 {
 #if 1
- z180_device *z180_dev = new z180_device();
+ class sim_z180_device : public z180_device {
+  virtual int standard_irq_callback(device_t &device, int irqline) override {
+   assert(irqline == Z180_INPUT_LINE_IRQ0);
+   execute_set_input(Z180_INPUT_LINE_IRQ0, CLEAR_LINE);
+   return int_data;
+  }
+ };
+ z180_device *z180_dev = new sim_z180_device();
  z180_dev->device_start();
  *z180_dev->m_icountptr = 0;
 
- class memory_address_space : public address_space {
+ class sim_memory_address_space : public address_space {
   virtual u8 read_byte(offs_t address) override {
    return memrdr((WORD)address);
   }
@@ -338,11 +345,11 @@ static void init_cpu(void)
    memwrt((WORD)address, (BYTE)data);
   }
  };
- z180_dev->m_program = new memory_address_space();
+ z180_dev->m_program = new sim_memory_address_space();
 
  BYTE io_in(BYTE addrl, BYTE addrh);
  void io_out(BYTE addrl, BYTE addrh, BYTE data);
- class io_address_space : public address_space {
+ class sim_io_address_space : public address_space {
   virtual u8 read_byte(offs_t address) override {
    return io_in((BYTE)address, (BYTE)(address >> 8));
   }
@@ -350,7 +357,7 @@ static void init_cpu(void)
    io_out((BYTE)address, (BYTE)(address >> 8), (BYTE)data);
   }
  };
- z180_dev->m_iospace = new io_address_space();
+ z180_dev->m_iospace = new sim_io_address_space();
 
  z180_dev->device_reset();
  cpu_dev = z180_dev;
index 3d5d303..fc0eb64 100644 (file)
@@ -87,6 +87,9 @@ void mon(void)
  while (true) {
   *cpu_dev->m_icountptr += 1000;
   cpu_dev->execute_run();
+  // we require at least one console poll per 1000 t-states to detect busy
+  if (busy_loop_cnt[0] > 0)
+   --busy_loop_cnt[0];
   //fputc('.', stderr);
  }
 #else
index 0dc1847..13bac38 100644 (file)
@@ -95,7 +95,9 @@ int cpu_error;                        /* error status of CPU emulation */
 int int_mode;                  /* CPU interrupt mode (IM 0, IM 1, IM 2) */
 int int_nmi;                   /* non maskable interrupt request */
 int int_int;                   /* interrupt request */
+#endif
 int int_data = -1;             /* data from interrupting device on data bus */
+#if 1
 int int_protection;            /* to delay interrupts after EI */
 BYTE bus_request;              /* request address/data bus from CPU */
 #endif
index 53b8706..8910426 100644 (file)
@@ -66,8 +66,8 @@ extern int    m1_step;
 #endif
 
 extern BYTE    cpu_state, bus_request;
-extern int     int_data;
 #endif
+extern int     int_data;
 
 extern int     s_flag, l_flag, m_flag, x_flag, i_flag, f_flag;
 #if 0