]> git.sesse.net Git - pistorm/blobdiff - emulator.c
introducing CPU state parameter
[pistorm] / emulator.c
index dc45bfd07e937ceef84be3975ef2a64557e120b0..8ecc8f8c777bc313dd5e917db8371e7e8d836fff 100644 (file)
 
 #define KEY_POLL_INTERVAL_MSEC 5000
 
-unsigned char read_ranges;
-unsigned int read_addr[8];
-unsigned int read_upper[8];
-unsigned char *read_data[8];
-unsigned char write_ranges;
-unsigned int write_addr[8];
-unsigned int write_upper[8];
-unsigned char *write_data[8];
-address_translation_cache code_translation_cache = {0};
-
 int kb_hook_enabled = 0;
 int mouse_hook_enabled = 0;
 int cpu_emulation_running = 1;
@@ -191,7 +181,8 @@ void *ipl_task(void *args) {
 }
 
 void *cpu_task() {
-  m68k_pulse_reset();
+       m68ki_cpu_core *state = &m68ki_cpu;
+       m68k_pulse_reset(state);
 
 cpu_loop:
   if (mouse_hook_enabled) {
@@ -207,39 +198,28 @@ cpu_loop:
     printf("%.8X (%.8X)]] %s\n", m68k_get_reg(NULL, M68K_REG_PC), (m68k_get_reg(NULL, M68K_REG_PC) & 0xFFFFFF), disasm_buf);
     if (do_disasm)
       do_disasm--;
-    m68k_execute(1);
+         m68k_execute(state, 1);
   }
   else {
-    if (cpu_emulation_running)
-      m68k_execute(loop_cycles);
+    if (cpu_emulation_running) {
+               if (irq)
+                       m68k_execute(state, 5);
+               else
+                       m68k_execute(state, loop_cycles);
+    }
   }
 
   if (irq) {
-    while (irq) {
       last_irq = ((read_reg() & 0xe000) >> 13);
       if (last_irq != last_last_irq) {
         last_last_irq = last_irq;
         M68K_SET_IRQ(last_irq);
       }
-      m68k_execute(5);
-    }
-    if (gayleirq && int2_enabled) {
-      write16(0xdff09c, 0x8000 | (1 << 3) && last_irq != 2);
-      last_last_irq = last_irq;
-      last_irq = 2;
-      M68K_SET_IRQ(2);
-    }
+  } else if (!irq && last_last_irq != 0) {
     M68K_SET_IRQ(0);
     last_last_irq = 0;
-    m68k_execute(5);
   }
-  /*else {
-    if (last_irq != 0) {
-      M68K_SET_IRQ(0);
-      last_last_irq = last_irq;
-      last_irq = 0;
-    }
-  }*/
+
   if (do_reset) {
     cpu_pulse_reset();
     do_reset=0;
@@ -647,6 +627,7 @@ switch_config:
 }
 
 void cpu_pulse_reset(void) {
+       m68ki_cpu_core *state = &m68ki_cpu;
   ps_pulse_reset();
   if (cfg->platform->handle_reset)
     cfg->platform->handle_reset(cfg);
@@ -656,7 +637,7 @@ void cpu_pulse_reset(void) {
   //m68k_write_memory_8(0xbfe201, 0x0001);  // AMIGA OVL
   //m68k_write_memory_8(0xbfe001, 0x0001);  // AMIGA OVL high (ROM@0x0)
 
-  m68k_pulse_reset();
+       m68k_pulse_reset(state);
 }
 
 int cpu_irq_ack(int level) {
@@ -697,8 +678,7 @@ static inline void inline_write_16(unsigned int address, unsigned int data) {
   *(gpio + 1) = GPFSEL1_INPUT;
   *(gpio + 2) = GPFSEL2_INPUT;
 
-  while (*(gpio + 13) & (1 << PIN_TXN_IN_PROGRESS))
-    ;
+  while (*(gpio + 13) & (1 << PIN_TXN_IN_PROGRESS)) {}
 }
 
 static inline void inline_write_8(unsigned int address, unsigned int data) {
@@ -730,8 +710,7 @@ static inline void inline_write_8(unsigned int address, unsigned int data) {
   *(gpio + 1) = GPFSEL1_INPUT;
   *(gpio + 2) = GPFSEL2_INPUT;
 
-  while (*(gpio + 13) & (1 << PIN_TXN_IN_PROGRESS))
-    ;
+  while (*(gpio + 13) & (1 << PIN_TXN_IN_PROGRESS)) {}
 }
 
 static inline void inline_write_32(unsigned int address, unsigned int value) {
@@ -761,9 +740,8 @@ static inline unsigned int inline_read_16(unsigned int address) {
   *(gpio + 7) = (REG_DATA << PIN_A0);
   *(gpio + 7) = 1 << PIN_RD;
 
+  while (*(gpio + 13) & (1 << PIN_TXN_IN_PROGRESS)) {}
   unsigned int value = *(gpio + 13);
-  while ((value=*(gpio + 13)) & (1 << PIN_TXN_IN_PROGRESS))
-    ;
 
   *(gpio + 10) = 0xffffec;
 
@@ -792,9 +770,8 @@ static inline unsigned int inline_read_8(unsigned int address) {
   *(gpio + 7) = (REG_DATA << PIN_A0);
   *(gpio + 7) = 1 << PIN_RD;
 
+  while (*(gpio + 13) & (1 << PIN_TXN_IN_PROGRESS)) {}
   unsigned int value = *(gpio + 13);
-  while ((value=*(gpio + 13)) & (1 << PIN_TXN_IN_PROGRESS))
-    ;
 
   *(gpio + 10) = 0xffffec;
 
@@ -826,72 +803,72 @@ static inline uint32_t ps_read(uint8_t type, uint32_t addr) {
 }
 
 static inline int32_t platform_read_check(uint8_t type, uint32_t addr, uint32_t *res) {
-  switch (addr) {
-    case CIAAPRA:
-      if (mouse_hook_enabled && (mouse_buttons & 0x01)) {
-        rres = (uint32_t)ps_read(type, addr);
-        *res = (rres ^ 0x40);
-        return 1;
-      }
-      return 0;
-      break;
-    case CIAAICR:
-      if (kb_hook_enabled) {
-        rres = (uint32_t)ps_read(type, addr);
-        if (get_num_kb_queued() && (!send_keypress || send_keypress == 1)) {
-          rres |= 0x08;
-          if (!send_keypress)
-            send_keypress = 1;
-        }
-        if (send_keypress == 2) {
-          send_keypress = 0;
-        }
-        *res = rres;
-        return 1;
-      }
-      return 0;
-      break;
-    case CIAADAT:
-      if (kb_hook_enabled) {
-        rres = (uint32_t)ps_read(type, addr);
-        uint8_t c = 0, t = 0;
-        pop_queued_key(&c, &t);
-        t ^= 0x01;
-        rres = ((c << 1) | t) ^ 0xFF;
-        send_keypress = 2;
-        *res = rres;
-        return 1;
-      }
-      return 0;
-      break;
-    case JOY0DAT:
-      if (mouse_hook_enabled) {
-        unsigned short result = (mouse_dy << 8) | (mouse_dx);
-        *res = (unsigned int)result;
-        return 1;
-      }
-      return 0;
-      break;
-    case POTGOR:
-      if (mouse_hook_enabled) {
-        unsigned short result = (unsigned short)ps_read(type, addr);
-        // bit 1 rmb, bit 2 mmb
-        if (mouse_buttons & 0x06) {
-          *res = (unsigned int)((result ^ ((mouse_buttons & 0x02) << 9))   // move rmb to bit 10
-                              & (result ^ ((mouse_buttons & 0x04) << 6))); // move mmb to bit 8
-          return 1;
-        }
-        *res = (unsigned int)(result & 0xfffd);
-        return 1;
-      }
-      return 0;
-      break;
-    default:
-      break;
-  }
-
   switch (cfg->platform->id) {
     case PLATFORM_AMIGA:
+      switch (addr) {
+        case CIAAPRA:
+          if (mouse_hook_enabled && (mouse_buttons & 0x01)) {
+            rres = (uint32_t)ps_read(type, addr);
+            *res = (rres ^ 0x40);
+            return 1;
+          }
+          return 0;
+          break;
+        case CIAAICR:
+          if (kb_hook_enabled) {
+            rres = (uint32_t)ps_read(type, addr);
+            if (get_num_kb_queued() && (!send_keypress || send_keypress == 1)) {
+              rres |= 0x08;
+              if (!send_keypress)
+                send_keypress = 1;
+            }
+            if (send_keypress == 2) {
+              send_keypress = 0;
+            }
+            *res = rres;
+            return 1;
+          }
+          return 0;
+          break;
+        case CIAADAT:
+          if (kb_hook_enabled) {
+            rres = (uint32_t)ps_read(type, addr);
+            uint8_t c = 0, t = 0;
+            pop_queued_key(&c, &t);
+            t ^= 0x01;
+            rres = ((c << 1) | t) ^ 0xFF;
+            send_keypress = 2;
+            *res = rres;
+            return 1;
+          }
+          return 0;
+          break;
+        case JOY0DAT:
+          if (mouse_hook_enabled) {
+            unsigned short result = (mouse_dy << 8) | (mouse_dx);
+            *res = (unsigned int)result;
+            return 1;
+          }
+          return 0;
+          break;
+        case POTGOR:
+          if (mouse_hook_enabled) {
+            unsigned short result = (unsigned short)ps_read(type, addr);
+            // bit 1 rmb, bit 2 mmb
+            if (mouse_buttons & 0x06) {
+              *res = (unsigned int)((result ^ ((mouse_buttons & 0x02) << 9))   // move rmb to bit 10
+                                  & (result ^ ((mouse_buttons & 0x04) << 6))); // move mmb to bit 8
+              return 1;
+            }
+            *res = (unsigned int)(result & 0xfffd);
+            return 1;
+          }
+          return 0;
+          break;
+        default:
+          break;
+      }
+
       if (addr >= cfg->custom_low && addr < cfg->custom_high) {
         if (addr >= PISCSI_OFFSET && addr < PISCSI_UPPER) {
           *res = handle_piscsi_read(addr, type);
@@ -970,40 +947,53 @@ unsigned int m68k_read_memory_32(unsigned int address) {
 }
 
 static inline int32_t platform_write_check(uint8_t type, uint32_t addr, uint32_t val) {
-  switch (addr) {
-    case CIAAPRA:
-      if (ovl != (val & (1 << 0))) {
-        ovl = (val & (1 << 0));
-        printf("OVL:%x\n", ovl);
+  switch (cfg->platform->id) {
+    case PLATFORM_MAC:
+      switch (addr) {
+        case 0xEFFFFE: // VIA1?
+          if (val & 0x10 && !ovl) {
+              ovl = 1;
+              printf("[MAC] OVL on.\n");
+          } else if (ovl) {
+            ovl = 0;
+            printf("[MAC] OVL off.\n");
+          }
+          break;
       }
-      return 0;
       break;
-    case SERDAT: {
-      char *serdat = (char *)&val;
-      // SERDAT word. see amiga dev docs appendix a; upper byte is control codes, and bit 0 is always 1.
-      // ignore this upper byte as it's not viewable data, only display lower byte.
-      printf("%c", serdat[0]);
-      return 0;
-      break;
-    }
-    case INTENA:
-      // This code is kind of strange and should probably be reworked/revoked.
-      if (!(val & 0x8000)) {
-        if (val & 0x04) {
-          int2_enabled = 0;
+    case PLATFORM_AMIGA:
+      switch (addr) {
+        case CIAAPRA:
+          if (ovl != (val & (1 << 0))) {
+            ovl = (val & (1 << 0));
+            printf("OVL:%x\n", ovl);
+          }
+          return 0;
+          break;
+        case SERDAT: {
+          char *serdat = (char *)&val;
+          // SERDAT word. see amiga dev docs appendix a; upper byte is control codes, and bit 0 is always 1.
+          // ignore this upper byte as it's not viewable data, only display lower byte.
+          printf("%c", serdat[0]);
+          return 0;
+          break;
         }
+        case INTENA:
+          // This code is kind of strange and should probably be reworked/revoked.
+          if (!(val & 0x8000)) {
+            if (val & 0x04) {
+              int2_enabled = 0;
+            }
+          }
+          else if (val & 0x04) {
+            int2_enabled = 1;
+          }
+          return 0;
+          break;
+        default:
+          break;
       }
-      else if (val & 0x04) {
-        int2_enabled = 1;
-      }
-      return 0;
-      break;
-    default:
-      break;
-  }
 
-  switch (cfg->platform->id) {
-    case PLATFORM_AMIGA:
       if (addr >= cfg->custom_low && addr < cfg->custom_high) {
         if (addr >= PISCSI_OFFSET && addr < PISCSI_UPPER) {
           handle_piscsi_write(addr, val, type);