]> git.sesse.net Git - pistorm/commitdiff
Cleanup, move mouse/keyboard input code out of emulator.c
authorbeeanyew <Bjorn Astrom>
Fri, 4 Dec 2020 07:11:29 +0000 (08:11 +0100)
committerbeeanyew <Bjorn Astrom>
Fri, 4 Dec 2020 07:11:29 +0000 (08:11 +0100)
Makefile
config_file/config_file.c
config_file/config_file.h
emulator.c
input/input.c [new file with mode: 0644]
input/input.h [new file with mode: 0644]

index 8792bff6b3745f0508c76146dc8565731a861855..9060f95b774dd77e2f74c45d66952bb22f781b14 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 EXENAME          = emulator
 
-MAINFILES        = emulator.c Gayle.c ide.c memory_mapped.c config_file/config_file.c registers/registers_amiga.c
+MAINFILES        = emulator.c Gayle.c ide.c memory_mapped.c config_file/config_file.c registers/registers_amiga.c input/input.c
 MUSASHIFILES     = m68kcpu.c softfloat/softfloat.c 
 MUSASHIGENCFILES = m68kops.c
 MUSASHIGENHFILES = m68kops.h
index c7fcccc0668ce63a3a0d008a60d0a26691d00a49..b7eff98a05b8e9d75ca2ff3781b90239c7c68c64 100644 (file)
@@ -226,7 +226,7 @@ void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int ad
       break;
   }
 
-  printf("[MAP %d] Added %s mapping for range %.8lX-%.8lX (%.8lX)\n", index, map_type_names[type], cfg->map_offset[index], cfg->map_offset[index] + cfg->map_size[index] - 1, (uint64_t)cfg->map_data[index]);
+  printf("[MAP %d] Added %s mapping for range %.8lX-%.8lX (%lX)\n", index, map_type_names[type], cfg->map_offset[index], cfg->map_offset[index] + cfg->map_size[index] - 1, (uint64_t)cfg->map_data[index]);
 
   return;
 
index e193eb189c759a0542722a3328a424790173bc9d..6c56a687028d640bde35c8f7976bfa3a3a04c855 100644 (file)
@@ -68,5 +68,3 @@ int handle_mapped_read(struct emulator_config *cfg, unsigned int addr, unsigned
 int handle_mapped_write(struct emulator_config *cfg, unsigned int addr, unsigned int value, unsigned char type, unsigned char mirror);
 int handle_register_read(unsigned int addr, unsigned char type, unsigned int *val);
 int handle_register_write(unsigned int addr, unsigned int value, unsigned char type);
-
-int get_mouse_status(char *x, char *y, char *b);
index 49aa883da97655b85c19c0be34a57eba647e496f..c65876e7d040d9b1dc23750e856312065630608d 100644 (file)
 #include <sys/types.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
-#include <termios.h>
-#include <linux/input.h>
 #include "Gayle.h"
 #include "ide.h"
 #include "m68k.h"
 #include "main.h"
 #include "config_file/config_file.h"
-
-int kbhit()
-{
-  struct termios term;
-  tcgetattr(0, &term);
-
-  struct termios term2 = term;
-  term2.c_lflag &= ~ICANON;
-  tcsetattr(0, TCSANOW, &term2);
-
-  int byteswaiting;
-  ioctl(0, FIONREAD, &byteswaiting);
-
-  tcsetattr(0, TCSANOW, &term);
-
-  return byteswaiting > 0;
-}
+#include "input/input.h"
 
 //#define BCM2708_PERI_BASE        0x20000000  //pi0-1
 //#define BCM2708_PERI_BASE    0xFE000000     //pi4
@@ -99,6 +81,7 @@ int kbhit()
 
 int kb_hook_enabled = 0;
 int mouse_hook_enabled = 0;
+int cpu_emulation_running = 1;
 
 char mouse_dx = 0, mouse_dy = 0;
 char mouse_buttons = 0;
@@ -233,7 +216,8 @@ int main(int argc, char *argv[]) {
       memset(cfg, 0x00, sizeof(struct emulator_config));
     }
   }
-  else {
+
+  if (cfg) {
     if (cfg->cpu_type) cpu_type = cfg->cpu_type;
     if (cfg->loop_cycles) loop_cycles = cfg->loop_cycles;
   }
@@ -329,27 +313,6 @@ int main(int argc, char *argv[]) {
   write_reg(0x00);
   usleep(100);
 
-  // load kick.rom if present
-  /*maprom = 1;
-  int fd = 0;
-  fd = open("kick.rom", O_RDONLY);
-  if (fd < 1) {
-    printf("Failed loading kick.rom, using motherboard kickstart\n");
-    maprom = 0;
-  } else {
-    int size = (int)lseek(fd, 0, SEEK_END);
-    if (size == 0x40000) {
-      lseek(fd, 0, SEEK_SET);
-      read(fd, &g_kick, size);
-      lseek(fd, 0, SEEK_SET);
-      read(fd, &g_kick[0x40000], size);
-    } else {
-      lseek(fd, 0, SEEK_SET);
-      read(fd, &g_kick, size);
-    }
-    printf("Loaded kick.rom with size %d kib\n", size / 1024);
-  }*/
-
   // reset amiga and statemachine
   skip_everything:;
   cpu_pulse_reset();
@@ -360,6 +323,7 @@ int main(int argc, char *argv[]) {
   usleep(1500);
 
   m68k_init();
+  printf("Setting CPU type to %d.\n", cpu_type);
   m68k_set_cpu_type(cpu_type);
   m68k_pulse_reset();
 
@@ -379,8 +343,6 @@ int main(int argc, char *argv[]) {
               printf("\n IPL Thread created successfully\n");
 */
 
-  int cpu_emulation_running = 1;
-
   m68k_pulse_reset();
   while (42) {
     if (mouse_hook_enabled) {
@@ -477,21 +439,6 @@ unsigned int m68k_read_memory_8(unsigned int address) {
     if (ret != -1)
       return target;
   }
-  /*if (address > FASTBASE && address < FASTBASE + FASTSIZE) {
-    return g_ram[address - FASTBASE];
-  }
-
-  if (maprom == 1) {
-    if (address > KICKBASE && address < KICKBASE + KICKSIZE) {
-      return g_kick[address - KICKBASE];
-    }
-  }
-
-  if (gayle_emulation_enabled) {
-    if (address > GAYLEBASE && address < GAYLEBASE + GAYLESIZE) {
-      return readGayleB(address);
-    }
-  }*/
 
     address &=0xFFFFFF;
 //  if (address < 0xffffff) {
@@ -534,21 +481,6 @@ unsigned int m68k_read_memory_16(unsigned int address) {
           return (unsigned int)result;
     }
   }
-  /*if (address > FASTBASE && address < FASTBASE + FASTSIZE) {
-    return be16toh(*(uint16_t *)&g_ram[address - FASTBASE]);
-  }
-
-  if (maprom == 1) {
-    if (address > KICKBASE && address < KICKBASE + KICKSIZE) {
-      return be16toh(*(uint16_t *)&g_kick[address - KICKBASE]);
-    }
-  }
-
-  if (gayle_emulation_enabled) {
-    if (address > GAYLEBASE && address < GAYLEBASE + GAYLESIZE) {
-      return readGayle(address);
-    }
-  }*/
 
 //  if (address < 0xffffff) {
     address &=0xFFFFFF;
@@ -564,21 +496,6 @@ unsigned int m68k_read_memory_32(unsigned int address) {
     if (ret != -1)
       return target;
   }
-  /*if (address > FASTBASE && address < FASTBASE + FASTSIZE) {
-    return be32toh(*(uint32_t *)&g_ram[address - FASTBASE]);
-  }
-
-  if (maprom == 1) {
-    if (address > KICKBASE && address < KICKBASE + KICKSIZE) {
-      return be32toh(*(uint32_t *)&g_kick[address - KICKBASE]);
-    }
-  }
-
-  if (gayle_emulation_enabled) {
-    if (address > GAYLEBASE && address < GAYLEBASE + GAYLESIZE) {
-      return readGayleL(address);
-    }
-  }*/
 
 //  if (address < 0xffffff) {
     address &=0xFFFFFF;
@@ -596,17 +513,6 @@ void m68k_write_memory_8(unsigned int address, unsigned int value) {
     if (ret != -1)
       return;
   }
-  /*if (address > FASTBASE && address < FASTBASE + FASTSIZE) {
-    g_ram[address - FASTBASE] = value;
-    return;
-  }
-
-  if (gayle_emulation_enabled) {
-    if (address > GAYLEBASE && address < GAYLEBASE + GAYLESIZE) {
-      writeGayleB(address, value);
-      return;
-    }
-  }*/
 
   if (address == 0xbfe001) {
     ovl = (value & (1 << 0));
@@ -628,17 +534,6 @@ void m68k_write_memory_16(unsigned int address, unsigned int value) {
     if (ret != -1)
       return;
   }
-  /*if (address > FASTBASE && address < FASTBASE + FASTSIZE) {
-    *(uint16_t *)&g_ram[address - FASTBASE] = htobe16(value);
-    return;
-  }
-
-  if (gayle_emulation_enabled) {
-    if (address > GAYLEBASE && address < GAYLEBASE + GAYLESIZE) {
-      writeGayle(address, value);
-      return;
-    }
-  }*/
 
 //  if (address < 0xffffff) {
     address &=0xFFFFFF;
@@ -654,16 +549,6 @@ void m68k_write_memory_32(unsigned int address, unsigned int value) {
     if (ret != -1)
       return;
   }
-  /*if (address > FASTBASE && address < FASTBASE + FASTSIZE) {
-    *(uint32_t *)&g_ram[address - FASTBASE] = htobe32(value);
-    return;
-  }
-
-  if (gayle_emulation_enabled) {
-    if (address > GAYLEBASE && address < GAYLEBASE + GAYLESIZE) {
-      writeGayleL(address, value);
-    }
-  }*/
 
 //  if (address < 0xffffff) {
     address &=0xFFFFFF;
@@ -901,15 +786,3 @@ void setup_io() {
   gpclk = ((volatile unsigned *)gpio_map) + GPCLK_ADDR / 4;
 
 }  // setup_io
-
-int get_mouse_status(char *x, char *y, char *b) {
-  struct input_event ie;
-  if (read(mouse_fd, &ie, sizeof(struct input_event)) != -1) {
-    *b = ((char *)&ie)[0];
-    *x = ((char *)&ie)[1];
-    *y = ((char *)&ie)[2];
-    return 1;
-  }
-
-  return 0;
-}
diff --git a/input/input.c b/input/input.c
new file mode 100644 (file)
index 0000000..0a7f53d
--- /dev/null
@@ -0,0 +1,34 @@
+#include <termios.h>
+#include <unistd.h>
+#include <linux/input.h>
+
+int kbhit()
+{
+  struct termios term;
+  tcgetattr(0, &term);
+
+  struct termios term2 = term;
+  term2.c_lflag &= ~ICANON;
+  tcsetattr(0, TCSANOW, &term2);
+
+  int byteswaiting;
+  ioctl(0, FIONREAD, &byteswaiting);
+
+  tcsetattr(0, TCSANOW, &term);
+
+  return byteswaiting > 0;
+}
+
+extern int mouse_fd;
+
+int get_mouse_status(char *x, char *y, char *b) {
+  struct input_event ie;
+  if (read(mouse_fd, &ie, sizeof(struct input_event)) != -1) {
+    *b = ((char *)&ie)[0];
+    *x = ((char *)&ie)[1];
+    *y = ((char *)&ie)[2];
+    return 1;
+  }
+
+  return 0;
+}
diff --git a/input/input.h b/input/input.h
new file mode 100644 (file)
index 0000000..b6565bf
--- /dev/null
@@ -0,0 +1,2 @@
+int get_mouse_status(char *x, char *y, char *b);
+int kbhit();