]> git.sesse.net Git - pistorm/commitdiff
Some more cleanup, improve IRQ checking a little
authorbeeanyew <beeanyew@gmail.com>
Fri, 1 Jan 2021 18:16:18 +0000 (19:16 +0100)
committerbeeanyew <beeanyew@gmail.com>
Fri, 1 Jan 2021 18:16:18 +0000 (19:16 +0100)
emulator.c
gpio/gpio.c
gpio/gpio.h
platforms/amiga/Gayle.c
platforms/amiga/Gayle.h
platforms/amiga/gayle-ide/ide.c
platforms/amiga/gayle-ide/ide.h

index 43ecdb18f217f1f08262162f93f9214f42765326..d3faa741676f6a2fb7da57107bc65a2073fc6e66 100644 (file)
 #include "main.h"
 #include "platforms/platforms.h"
 #include "input/input.h"
-#include "gpio/gpio.h"
 
 #include "platforms/amiga/Gayle.h"
 #include "platforms/amiga/gayle-ide/ide.h"
 #include "platforms/amiga/amiga-registers.h"
+#include "gpio/gpio.h"
 
 int kb_hook_enabled = 0;
 int mouse_hook_enabled = 0;
@@ -31,6 +31,9 @@ int cpu_emulation_running = 1;
 char mouse_dx = 0, mouse_dy = 0;
 char mouse_buttons = 0;
 
+extern volatile unsigned int *gpio;
+extern volatile uint16_t srdata;
+
 #define KICKBASE 0xF80000
 #define KICKSIZE 0x7FFFF
 
@@ -181,15 +184,6 @@ int main(int argc, char *argv[]) {
     m68k_set_reg(M68K_REG_PC, 0x0);
   }
 
-/*
-          pthread_t id;
-          int err;
-          err = pthread_create(&id, NULL, &iplThread, NULL);
-          if (err != 0)
-              printf("\ncan't create IPL thread :[%s]", strerror(err));
-          else
-              printf("\n IPL Thread created successfully\n");
-*/
   char c = 0;
 
   m68k_pulse_reset();
@@ -234,17 +228,9 @@ int main(int argc, char *argv[]) {
         }
       }
     }*/
-/*
-    if (toggle == 1){
-      srdata = read_reg();
-      m68k_set_irq((srdata >> 13) & 0xff);
-    } else {
-         m68k_set_irq(0);
-    };
-    usleep(1);
-*/
-
-    gpio_handle_irq();
+
+    //gpio_handle_irq();
+    GPIO_HANDLE_IRQ;
   }
 
   stop_cpu_emulation:;
index 2f8eae4d948327339a71c7ccab3948b686d7e1e2..1f9c567f16ca1343e54751fe44df33cf969d5477 100644 (file)
@@ -8,8 +8,9 @@
 #include <sys/mman.h>
 #include <sys/ioctl.h>
 #include "../m68k.h"
-#include "gpio.h"
 #include "../platforms/amiga/Gayle.h"
+#include "../platforms/amiga/gayle-ide/ide.h"
+#include "gpio.h"
 
 // I/O access
 volatile unsigned int *gpio;
@@ -325,12 +326,12 @@ void gpio_enable_200mhz() {
   GPIO_SET = 1 << 7;
 }
 
-void gpio_handle_irq() {
+inline void gpio_handle_irq() {
   if (GET_GPIO(1) == 0) {
     srdata = read_reg();
     m68k_set_irq((srdata >> 13) & 0xff);
   } else {
-    if (CheckIrq() == 1) {
+    if ((gayle_int & 0x80) && get_ide(0)->drive->intrq) {
       write16(0xdff09c, 0x8008);
       m68k_set_irq(2);
     }
index 398aafde0ad09d10ea8afc1ebaf548e9abf6cfd1..8110083dcb3d73eceedd42251f7d1a48d0d204f3 100644 (file)
 #define GPIO_PULL *(gpio + 37)      // Pull up/pull down
 #define GPIO_PULLCLK0 *(gpio + 38)  // Pull up/pull down clock
 
+#define GPIO_HANDLE_IRQ \
+  if (GET_GPIO(1) == 0) { \
+    srdata = read_reg(); \
+    m68k_set_irq((srdata >> 13) & 0xff); \
+  } else { \
+    if ((gayle_int & 0x80) && get_ide(0)->drive->intrq) { \
+      write16(0xdff09c, 0x8008); \
+      m68k_set_irq(2); \
+    } \
+    else \
+        m68k_set_irq(0); \
+  }; \
+
+extern uint8_t gayle_int;
+
 void setup_io();
 void gpio_enable_200mhz();
 void gpio_handle_irq();
index b518ecd0e55d9ca2acbb2540f35653ad2fc5901f..a8d4657b0dbb8e5aed02fe73f905853882e558b8 100644 (file)
 #define GAYLE_INT_BVD_LEV 0x02 /* BVD int level, 0=lev2,1=lev6 */
 #define GAYLE_INT_BSY_LEV 0x01 /* BSY int level, 0=lev2,1=lev6 */
 
-#define GAYLE_MAX_HARDFILES 8
-
 int counter;
-static uint8_t gayle_irq, gayle_int, gayle_cs, gayle_cs_mask, gayle_cfg;
+static uint8_t gayle_irq, gayle_cs, gayle_cs_mask, gayle_cfg;
 static struct ide_controller *ide0;
 int fd;
 
@@ -107,6 +105,13 @@ char *hdd_image_file[GAYLE_MAX_HARDFILES];
 uint8_t cdtv_mode = 0;
 unsigned char cdtv_sram[32 * SIZE_KILO];
 
+uint8_t gayle_int;
+
+struct ide_controller *get_ide(int index) {
+  //if (index) {}
+  return ide0;
+}
+
 void set_hard_drive_image_file_amiga(uint8_t index, char *filename) {
   if (hdd_image_file[index] != NULL)
     free(hdd_image_file[index]);
index 11d08eb092982944205e26be3088418d85b6c498..2bcb9c3cd5a4a6bd5f23366ff1544762179f00e7 100644 (file)
@@ -9,6 +9,8 @@
 #ifndef Gayle_h
 #define Gayle_h
 
+#define GAYLE_MAX_HARDFILES 8
+
 #include <stdio.h>
 #include <stdint.h>
 
@@ -20,4 +22,6 @@ void writeGayleL(unsigned int address, unsigned value);
 uint8_t readGayleB(unsigned int address);
 uint16_t readGayle(unsigned int address);
 uint32_t readGayleL(unsigned int address);
+
+struct ide_controller *get_ide(int index);
 #endif /* Gayle_h */
index 36b7d0a4729678b993170db7bb063dd24e6a7bc3..f82dfb53a1da6b29154bb2de791b5bf047acc55c 100644 (file)
@@ -73,8 +73,8 @@
 #define IDE_CMD_IDENTIFY       0xEC
 #define IDE_CMD_SETFEATURES    0xEF
 
-const uint8_t ide_magic[8] = {
-  '1','D','E','D','1','5','C','0'
+const uint8_t ide_magic[9] = {
+  '1','D','E','D','1','5','C','0',0x00
 };
 
 static char *charmap(uint8_t v)
index 0d6549cad1d598e7a8b5ef7b532943399b5d7e8f..900c3cd1f646066ff85781f04e4a05b29b9ca06e 100644 (file)
@@ -65,7 +65,7 @@ struct ide_controller {
 };
 
 //extern ide_controller idectrl;
-extern const uint8_t ide_magic[8];
+extern const uint8_t ide_magic[9];
 
 void ide_reset_begin(struct ide_controller *c);
 uint8_t ide_read8(struct ide_controller *c, uint8_t r);