]> git.sesse.net Git - pistorm/commitdiff
Merge pull request #5 from borb/0.x-borb
authorbeeanyew <beeanyew@gmail.com>
Mon, 8 Mar 2021 17:16:15 +0000 (18:16 +0100)
committerGitHub <noreply@github.com>
Mon, 8 Mar 2021 17:16:15 +0000 (18:16 +0100)
Work in progress updates

32 files changed:
.gitignore
68new.cfg
Makefile
buptest.c
config_file/config_file.c
config_file/config_file.h
emulator.c
emulator.h [moved from main.h with 75% similarity]
gpio/gpio_old.c
gpio/ps_protocol.c
input/input.c
input/input.h
m68kconf.h
platforms/amiga/Gayle.c
platforms/amiga/amiga-autoconf.c
platforms/amiga/amiga-autoconf.h
platforms/amiga/amiga-platform.c
platforms/amiga/amiga-registers.c
platforms/amiga/amiga-registers.h
platforms/amiga/cdtv-dmac.c
platforms/amiga/gayle-ide/ide.c
platforms/amiga/hunk-reloc.h
platforms/amiga/net/net_driver_amiga/pi-net-amiga.c
platforms/amiga/net/pi-net.c
platforms/amiga/piscsi/piscsi.c
platforms/amiga/piscsi/piscsi.h
platforms/amiga/rtg/rtg-gfx.c
platforms/amiga/rtg/rtg-output.c
platforms/amiga/rtg/rtg.c
platforms/dummy/dummy-platform.c
platforms/platforms.h
softfloat/softfloat.c

index 8e3ac16796957a585b970c612e38f1959deeac18..5b7f6eb8dafb1f2f5198f622d2cad3865c7205f7 100644 (file)
@@ -11,3 +11,4 @@
 /m68kmake.exe
 /m68kops.c
 /m68kops.h
+/emulator
index a09ffb509ba119981e72c76b6003b009d7dc0227..4ea3c2e71d2f965a8b88f4120b01661665f94be9 100644 (file)
--- a/68new.cfg
+++ b/68new.cfg
@@ -1,27 +1,22 @@
 # this supports ECP5 Evaluation Board
 
 reset_config none
-interface bcm2835gpio
-
-
+adapter driver bcm2835gpio
 
 #bcm2835gpio_peripheral_base 0x20000000
 bcm2835gpio_peripheral_base 0x3F000000
 
-
 # Transition delay calculation: SPEED_COEFF/khz - SPEED_OFFSET
 # These depend on system clock, calibrated for stock 700MHz
 # bcm2835gpio_speed SPEED_COEFF SPEED_OFFSET
 #bcm2835gpio_speed_coeffs 146203 36
 bcm2835gpio_speed_coeffs 194938 48
 
-
-
 #bcm2835gpio_peripheral_base 0x3F000000
 #bcm2835gpio_speed_coeffs 194938 48
 
 reset_config none
-adapter_khz 100
+adapter speed 100
 
 # JTAG                tck tms tdi tdo
 bcm2835gpio_jtag_nums 26 24   27  25
@@ -31,7 +26,7 @@ bcm2835gpio_srst_num 5
 reset_config srst_only srst_open_drain
 
 transport select jtag
-jtag newtap max2 tap -irlen 11 -expected-id 0x020a20dd 
+jtag newtap max2 tap -irlen 11 -expected-id 0x020a20dd
 init
 svf ./rtl/bitstream.svf -quiet
 sleep 200
index fedac27587156ea70bcba581496371e414661a5b..1ccd7e86f735f789f38d61f43d6218a2bb03962e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -37,7 +37,7 @@ EXEPATH = ./
 
 CC        = gcc
 WARNINGS  = -Wall -Wextra -pedantic
-CFLAGS    = $(WARNINGS) -march=armv8-a -mfloat-abi=hard -mfpu=neon-fp-armv8 -O3 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
+CFLAGS    = $(WARNINGS) -I. -march=armv8-a -mfloat-abi=hard -mfpu=neon-fp-armv8 -O3 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
 LFLAGS    = $(WARNINGS) `sdl2-config --libs`
 
 TARGET = $(EXENAME)$(EXE)
index bbba2ed7693a47caa34eb750a36f1e3d635fa94a..6538736beda9f3dc922190aef8fbccc5c07ed3ac 100644 (file)
--- a/buptest.c
+++ b/buptest.c
@@ -15,7 +15,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
-#include "main.h"
+#include "emulator.h"
 #include "gpio/gpio.h"
 #include "platforms/amiga/gayle-ide/ide.h"
 
index 772c6ba39699d5800035b8c1b885f773f09887f7..7dbd238afbdb4122566deaf2e66e801eb2db2c15 100644 (file)
@@ -1,4 +1,4 @@
-#include "../platforms/platforms.h"
+#include "platforms/platforms.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -228,7 +228,6 @@ void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int ad
     case MAPTYPE_REGISTER:
     default:
       break;
-      break;
   }
 
   printf("[MAP %d] Added %s mapping for range %.8lX-%.8lX ID: %s\n", index, map_type_names[type], cfg->map_offset[index], cfg->map_high[index] - 1, cfg->map_id[index] ? cfg->map_id[index] : "None");
@@ -278,7 +277,7 @@ struct emulator_config *load_config_file(char *filename) {
       goto skip_line;
 
     trim_whitespace(parse_line);
-    
+
     get_next_string(parse_line, cur_cmd, &str_pos, ' ');
 
     switch (get_config_item_type(cur_cmd)) {
@@ -391,7 +390,7 @@ struct emulator_config *load_config_file(char *filename) {
         printf("Unknown config item %s on line %d.\n", cur_cmd, cur_line);
         break;
     }
-    
+
     skip_line:;
     cur_line++;
   }
index b19d80972f8227c52514cc4d30a7e50a9310d5d4..6880f0fcada497f7912ca1f9c3b62ee06dc2013a 100644 (file)
@@ -1,4 +1,9 @@
-#include "../m68k.h"
+#ifndef _CONFIG_FILE_H
+#define _CONFIG_FILE_H
+
+#include "m68k.h"
+
+#include <unistd.h>
 
 #define MAX_NUM_MAPPED_ITEMS 8
 #define SIZE_KILO 1024
@@ -93,3 +98,5 @@ int handle_mapped_write(struct emulator_config *cfg, unsigned int addr, unsigned
 int get_named_mapped_item(struct emulator_config *cfg, char *name);
 int get_mapped_item_by_address(struct emulator_config *cfg, uint32_t address);
 unsigned int get_int(char *str);
+
+#endif /* _CONFIG_FILE_H */
index b1ac4bcc07bdfaece9805f4d1c8d5629078fe15c..9ef71b21c337be5aa3e302ec45f96f96f81f7a48 100644 (file)
@@ -1,7 +1,24 @@
+#include "m68k.h"
+#include "emulator.h"
+#include "platforms/platforms.h"
+#include "input/input.h"
+
+#include "platforms/amiga/Gayle.h"
+#include "platforms/amiga/gayle-ide/ide.h"
+#include "platforms/amiga/amiga-registers.h"
+#include "platforms/amiga/rtg/rtg.h"
+#include "platforms/amiga/hunk-reloc.h"
+#include "platforms/amiga/piscsi/piscsi.h"
+#include "platforms/amiga/piscsi/piscsi-enums.h"
+#include "platforms/amiga/net/pi-net.h"
+#include "platforms/amiga/net/pi-net-enums.h"
+#include "gpio/ps_protocol.h"
+
 #include <assert.h>
 #include <dirent.h>
 #include <endian.h>
 #include <fcntl.h>
+#include <poll.h>
 #include <pthread.h>
 #include <sched.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include <sys/ioctl.h>
-#include "m68k.h"
-#include "main.h"
-#include "platforms/platforms.h"
-#include "input/input.h"
 
-#include "platforms/amiga/Gayle.h"
-#include "platforms/amiga/gayle-ide/ide.h"
-#include "platforms/amiga/amiga-registers.h"
-#include "platforms/amiga/rtg/rtg.h"
-#include "platforms/amiga/hunk-reloc.h"
-#include "platforms/amiga/piscsi/piscsi.h"
-#include "platforms/amiga/piscsi/piscsi-enums.h"
-#include "platforms/amiga/net/pi-net.h"
-#include "platforms/amiga/net/pi-net-enums.h"
-#include "gpio/ps_protocol.h"
+#define KEY_POLL_INTERVAL_MSEC 5000
 
 unsigned char read_ranges;
 unsigned int read_addr[8];
@@ -43,8 +47,9 @@ 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;
+uint8_t mouse_dx = 0, mouse_dy = 0;
+uint8_t mouse_buttons = 0;
+uint8_t mouse_extra = 0;
 
 extern uint8_t gayle_int;
 extern uint8_t gayle_ide_enabled;
@@ -55,6 +60,8 @@ extern volatile uint16_t srdata;
 extern uint8_t realtime_graphics_debug;
 uint8_t realtime_disassembly, int2_enabled = 0;
 uint32_t do_disasm = 0, old_level;
+char c = 0, c_code = 0, c_type = 0; // @todo temporary main/cpu_task scope workaround until input moved to a thread
+uint32_t last_irq = 0, last_last_irq = 0;
 
 char disasm_buf[4096];
 
@@ -103,7 +110,7 @@ char keyboard_file[256] = "/dev/input/event1";
 uint64_t trig_irq = 0, serv_irq = 0;
 uint16_t irq_delay = 0;
 
-void *iplThread(void *args) {
+void *ipl_task(void *args) {
   printf("IPL thread running\n");
   uint16_t old_irq = 0;
   uint32_t value;
@@ -150,6 +157,178 @@ void *iplThread(void *args) {
   return args;
 }
 
+void *cpu_task() {
+  m68k_pulse_reset();
+
+cpu_loop:
+  if (mouse_hook_enabled) {
+    get_mouse_status(&mouse_dx, &mouse_dy, &mouse_buttons, &mouse_extra);
+  }
+
+  if (realtime_disassembly && (do_disasm || cpu_emulation_running)) {
+    m68k_disassemble(disasm_buf, m68k_get_reg(NULL, M68K_REG_PC), cpu_type);
+    printf("REGA: 0:$%.8X 1:$%.8X 2:$%.8X 3:$%.8X 4:$%.8X 5:$%.8X 6:$%.8X 7:$%.8X\n", m68k_get_reg(NULL, M68K_REG_A0), m68k_get_reg(NULL, M68K_REG_A1), m68k_get_reg(NULL, M68K_REG_A2), m68k_get_reg(NULL, M68K_REG_A3), \
+            m68k_get_reg(NULL, M68K_REG_A4), m68k_get_reg(NULL, M68K_REG_A5), m68k_get_reg(NULL, M68K_REG_A6), m68k_get_reg(NULL, M68K_REG_A7));
+    printf("REGD: 0:$%.8X 1:$%.8X 2:$%.8X 3:$%.8X 4:$%.8X 5:$%.8X 6:$%.8X 7:$%.8X\n", m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_D1), m68k_get_reg(NULL, M68K_REG_D2), m68k_get_reg(NULL, M68K_REG_D3), \
+            m68k_get_reg(NULL, M68K_REG_D4), m68k_get_reg(NULL, M68K_REG_D5), m68k_get_reg(NULL, M68K_REG_D6), m68k_get_reg(NULL, M68K_REG_D7));
+    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);
+  }
+  else {
+    if (cpu_emulation_running)
+      m68k_execute(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);
+    }
+    M68K_SET_IRQ(0);
+    last_last_irq = 0;
+  }
+  /*else {
+    if (last_irq != 0) {
+      M68K_SET_IRQ(0);
+      last_last_irq = last_irq;
+      last_irq = 0;
+    }
+  }*/
+
+  if (mouse_hook_enabled && (mouse_extra != 0x00)) {
+    // mouse wheel events have occurred; unlike l/m/r buttons, these are queued as keypresses, so add to end of buffer
+    switch (mouse_extra) {
+      case 0xff:
+        // wheel up
+        queue_keypress(0xfe, KEYPRESS_PRESS, PLATFORM_AMIGA);
+        break;
+      case 0x01:
+        // wheel down
+        queue_keypress(0xff, KEYPRESS_PRESS, PLATFORM_AMIGA);
+        break;
+    }
+
+    // dampen the scroll wheel until next while loop iteration
+    mouse_extra = 0x00;
+  }
+  goto cpu_loop;
+
+stop_cpu_emulation:
+  printf("[CPU] End of CPU thread\n");
+}
+
+void *keyboard_task() {
+  struct pollfd kbdfd[1];
+  int kpoll;
+
+  printf("[KBD] Keyboard thread started\n");
+
+  kbdfd[0].fd = keyboard_fd;
+  kbdfd[0].events = POLLIN;
+
+key_loop:
+  kpoll = poll(kbdfd, 1, KEY_POLL_INTERVAL_MSEC);
+  if ((kpoll > 0) && (kbdfd[0].revents & POLLHUP)) {
+    // in the event that a keyboard is unplugged, keyboard_task will whiz up to 100% utilisation
+    // this is undesired, so if the keyboard HUPs, end the thread without ending the emulation
+    printf("[KBD] Keyboard node returned HUP (unplugged?)\n");
+    goto key_end;
+  }
+
+  // if kpoll > 0 then it contains number of events to pull, also check if POLLIN is set in revents
+  if ((kpoll <= 0) || !(kbdfd[0].revents & POLLIN)) {
+    goto key_loop;
+  }
+
+  while (get_key_char(&c, &c_code, &c_type)) {
+    if (c && c == cfg->keyboard_toggle_key && !kb_hook_enabled) {
+      kb_hook_enabled = 1;
+      printf("Keyboard hook enabled.\n");
+    }
+    else if (kb_hook_enabled) {
+      if (c == 0x1B && c_type) {
+        kb_hook_enabled = 0;
+        printf("Keyboard hook disabled.\n");
+      }
+      else {
+        if (queue_keypress(c_code, c_type, cfg->platform->id) && int2_enabled && last_irq != 2) {
+          //last_irq = 0;
+          //M68K_SET_IRQ(2);
+        }
+      }
+    }
+
+    // pause pressed; trigger nmi (int level 7)
+    if (c == 0x01 && c_type) {
+      printf("[INT] Sending NMI\n");
+      M68K_SET_IRQ(7);
+    }
+
+    if (!kb_hook_enabled && c_type) {
+      if (c && c == cfg->mouse_toggle_key) {
+        mouse_hook_enabled ^= 1;
+        printf("Mouse hook %s.\n", mouse_hook_enabled ? "enabled" : "disabled");
+        mouse_dx = mouse_dy = mouse_buttons = mouse_extra = 0;
+      }
+      if (c == 'r') {
+        cpu_emulation_running ^= 1;
+        printf("CPU emulation is now %s\n", cpu_emulation_running ? "running" : "stopped");
+      }
+      if (c == 'g') {
+        realtime_graphics_debug ^= 1;
+        printf("Real time graphics debug is now %s\n", realtime_graphics_debug ? "on" : "off");
+      }
+      if (c == 'R') {
+        cpu_pulse_reset();
+        //m68k_pulse_reset();
+        printf("CPU emulation reset.\n");
+      }
+      // @todo work out how to signal the main process that we want to quit
+      // if (c == 'q') {
+      //   printf("Quitting and exiting emulator.\n");
+      //   goto stop_cpu_emulation;
+      // }
+      if (c == 'd') {
+        realtime_disassembly ^= 1;
+        do_disasm = 1;
+        printf("Real time disassembly is now %s\n", realtime_disassembly ? "on" : "off");
+      }
+      if (c == 'D') {
+        int r = get_mapped_item_by_address(cfg, 0x08000000);
+        if (r != -1) {
+          printf("Dumping first 16MB of mapped range %d.\n", r);
+          FILE *dmp = fopen("./memdmp.bin", "wb+");
+          fwrite(cfg->map_data[r], 16 * SIZE_MEGA, 1, dmp);
+          fclose(dmp);
+        }
+      }
+      if (c == 's' && realtime_disassembly) {
+        do_disasm = 1;
+      }
+      if (c == 'S' && realtime_disassembly) {
+        do_disasm = 128;
+      }
+    }
+  }
+
+  goto key_loop;
+
+key_end:
+  printf("[KBD] Keyboard thread ending\n");
+}
+
 void stop_cpu_emulation(uint8_t disasm_cur) {
   M68K_END_TIMESLICE;
   if (disasm_cur) {
@@ -251,10 +430,26 @@ int main(int argc, char *argv[]) {
   }
 
   if (cfg->mouse_enabled) {
-    mouse_fd = open(cfg->mouse_file, O_RDONLY | O_NONBLOCK);
+    mouse_fd = open(cfg->mouse_file, O_RDWR | O_NONBLOCK);
     if (mouse_fd == -1) {
       printf("Failed to open %s, can't enable mouse hook.\n", cfg->mouse_file);
       cfg->mouse_enabled = 0;
+    } else {
+      /**
+       * *-*-*-* magic numbers! *-*-*-*
+       * great, so waaaay back in the history of the pc, the ps/2 protocol set the standard for mice
+       * and in the process, the mouse sample rate was defined as a way of putting mice into vendor-specific modes.
+       * as the ancient gpm command explains, almost everything except incredibly old mice talk the IntelliMouse
+       * protocol, which reports four bytes. by default, every mouse starts in 3-byte mode (don't report wheel or
+       * additional buttons) until imps2 magic is sent. so, command $f3 is "set sample rate", followed by a byte.
+       */
+      uint8_t mouse_init[] = { 0xf4, 0xf3, 0x64 }; // enable, then set sample rate 100
+      uint8_t imps2_init[] = { 0xf3, 0xc8, 0xf3, 0x64, 0xf3, 0x50 }; // magic sequence; set sample 200, 100, 80
+      if (write(mouse_fd, mouse_init, sizeof(mouse_init)) != -1) {
+        if (write(mouse_fd, imps2_init, sizeof(imps2_init)) == -1)
+          printf("[MOUSE] Couldn't enable scroll wheel events; is this mouse from the 1980s?\n");
+      } else
+        printf("[MOUSE] Mouse didn't respond to normal PS/2 init; have you plugged a brick in by mistake?\n");
     }
   }
 
@@ -308,146 +503,37 @@ int main(int argc, char *argv[]) {
   m68k_set_cpu_type(cpu_type);
   cpu_pulse_reset();
 
-  char c = 0, c_code = 0, c_type = 0;
-  uint32_t last_irq = 0, last_last_irq = 0;
-
-  pthread_t id;
+  pthread_t ipl_tid, cpu_tid, kbd_tid;
   int err;
-  err = pthread_create(&id, NULL, &iplThread, NULL);
+  err = pthread_create(&ipl_tid, NULL, &ipl_task, NULL);
   if (err != 0)
-    printf("can't create IPL thread :[%s]", strerror(err));
-  else
-    printf("IPL Thread created successfully\n");
-
-  m68k_pulse_reset();
-  while (42) {
-    if (mouse_hook_enabled) {
-      get_mouse_status(&mouse_dx, &mouse_dy, &mouse_buttons);
-    }
-
-    if (realtime_disassembly && (do_disasm || cpu_emulation_running)) {
-      m68k_disassemble(disasm_buf, m68k_get_reg(NULL, M68K_REG_PC), cpu_type);
-      printf("REGA: 0:$%.8X 1:$%.8X 2:$%.8X 3:$%.8X 4:$%.8X 5:$%.8X 6:$%.8X 7:$%.8X\n", m68k_get_reg(NULL, M68K_REG_A0), m68k_get_reg(NULL, M68K_REG_A1), m68k_get_reg(NULL, M68K_REG_A2), m68k_get_reg(NULL, M68K_REG_A3), \
-              m68k_get_reg(NULL, M68K_REG_A4), m68k_get_reg(NULL, M68K_REG_A5), m68k_get_reg(NULL, M68K_REG_A6), m68k_get_reg(NULL, M68K_REG_A7));
-      printf("REGD: 0:$%.8X 1:$%.8X 2:$%.8X 3:$%.8X 4:$%.8X 5:$%.8X 6:$%.8X 7:$%.8X\n", m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_D1), m68k_get_reg(NULL, M68K_REG_D2), m68k_get_reg(NULL, M68K_REG_D3), \
-              m68k_get_reg(NULL, M68K_REG_D4), m68k_get_reg(NULL, M68K_REG_D5), m68k_get_reg(NULL, M68K_REG_D6), m68k_get_reg(NULL, M68K_REG_D7));
-      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);
-    }
-    else {
-      if (cpu_emulation_running)
-        m68k_execute(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);
-      }
-      M68K_SET_IRQ(0);
-      last_last_irq = 0;
-    }
-    /*else {
-      if (last_irq != 0) {
-        M68K_SET_IRQ(0);
-        last_last_irq = last_irq;
-        last_irq = 0;
-      }
-    }*/
+    printf("[ERROR] Cannot create IPL thread: [%s]", strerror(err));
+  else {
+    pthread_setname_np(ipl_tid, "pistorm: ipl");
+    printf("IPL thread created successfully\n");
+  }
 
-    while (get_key_char(&c, &c_code, &c_type)) {
-      if (c && c == cfg->keyboard_toggle_key && !kb_hook_enabled) {
-        kb_hook_enabled = 1;
-        printf("Keyboard hook enabled.\n");
-      }
-      else if (kb_hook_enabled) {
-        if (c == 0x1B && c_type) {
-          kb_hook_enabled = 0;
-          printf("Keyboard hook disabled.\n");
-        }
-        else {
-          /*printf("Key code: %.2X - ", c_code);
-          switch (c_type) {
-            case 0:
-              printf("released.\n");
-              break;
-            case 1:
-              printf("pressed.\n");
-              break;
-            case 2:
-              printf("repeat.\n");
-              break;
-            default:
-              printf("unknown.\n");
-              break;
-          }*/
-          if (queue_keypress(c_code, c_type, cfg->platform->id) && int2_enabled && last_irq != 2) {
-            //last_irq = 0;
-            //M68K_SET_IRQ(2);
-          }
-        }
-      }
+  // create keyboard task
+  err = pthread_create(&kbd_tid, NULL, &keyboard_task, NULL);
+  if (err != 0)
+    printf("[ERROR] Cannot create keyboard thread: [%s]", strerror(err));
+  else {
+    pthread_setname_np(kbd_tid, "pistorm: kbd");
+    printf("[MAIN] Keyboard thread created successfully\n");
+  }
 
-      if (!kb_hook_enabled && c_type) {
-        if (c && c == cfg->mouse_toggle_key) {
-          mouse_hook_enabled ^= 1;
-          printf("Mouse hook %s.\n", mouse_hook_enabled ? "enabled" : "disabled");
-          mouse_dx = mouse_dy = mouse_buttons = 0;
-        }
-        if (c == 'r') {
-          cpu_emulation_running ^= 1;
-          printf("CPU emulation is now %s\n", cpu_emulation_running ? "running" : "stopped");
-        }
-        if (c == 'g') {
-          realtime_graphics_debug ^= 1;
-          printf("Real time graphics debug is now %s\n", realtime_graphics_debug ? "on" : "off");
-        }
-        if (c == 'R') {
-          cpu_pulse_reset();
-          //m68k_pulse_reset();
-          printf("CPU emulation reset.\n");
-        }
-        if (c == 'q') {
-          printf("Quitting and exiting emulator.\n");
-          goto stop_cpu_emulation;
-        }
-        if (c == 'd') {
-          realtime_disassembly ^= 1;
-          do_disasm = 1;
-          printf("Real time disassembly is now %s\n", realtime_disassembly ? "on" : "off");
-        }
-        if (c == 'D') {
-          int r = get_mapped_item_by_address(cfg, 0x08000000);
-          if (r != -1) {
-            printf("Dumping first 16MB of mapped range %d.\n", r);
-            FILE *dmp = fopen("./memdmp.bin", "wb+");
-            fwrite(cfg->map_data[r], 16 * SIZE_MEGA, 1, dmp);
-            fclose(dmp);
-          }
-        }
-        if (c == 's' && realtime_disassembly) {
-          do_disasm = 1;
-        }
-        if (c == 'S' && realtime_disassembly) {
-          do_disasm = 128;
-        }
-      }
-    }
+  // create cpu task
+  err = pthread_create(&cpu_tid, NULL, &cpu_task, NULL);
+  if (err != 0)
+    printf("[ERROR] Cannot create CPU thread: [%s]", strerror(err));
+  else {
+    pthread_setname_np(cpu_tid, "pistorm: cpu");
+    printf("[MAIN] CPU thread created successfully\n");
   }
 
-  stop_cpu_emulation:;
+  // wait for cpu task to end before closing up and finishing
+  pthread_join(cpu_tid, NULL);
+  printf("[MAIN] All threads appear to have concluded; ending process\n");
 
   if (mouse_fd != -1)
     close(mouse_fd);
@@ -467,7 +553,6 @@ void cpu_pulse_reset(void) {
   if (cfg->platform->handle_reset)
     cfg->platform->handle_reset(cfg);
 
-  
   m68k_write_memory_16(INTENA, 0x7FFF);
   ovl = 1;
   m68k_write_memory_8(0xbfe201, 0x0001);  // AMIGA OVL
@@ -545,10 +630,11 @@ unsigned int m68k_read_memory_8(unsigned int address) {
         //mouse_buttons -= 1;
         return (unsigned int)(result ^ 0x40);
       }
-      else
-          return (unsigned int)result;
+
+      return (unsigned int)result;
     }
   }
+
   if (kb_hook_enabled) {
     if (address == CIAAICR) {
       if (get_num_kb_queued() && (!send_keypress || send_keypress == 1)) {
@@ -610,11 +696,12 @@ unsigned int m68k_read_memory_16(unsigned int address) {
     }*/
     if (address == POTGOR) {
       unsigned short result = (unsigned int)read16((uint32_t)address);
-      if (mouse_buttons & 0x02) {
-        return (unsigned int)(result ^ (0x2 << 9));
+      // bit 1 rmb, bit 2 mmb
+      if (mouse_buttons & 0x06) {
+        return (unsigned int)((result ^ ((mouse_buttons & 0x02) << 9))   // move rmb to bit 10
+                            & (result ^ ((mouse_buttons & 0x04) << 6))); // move mmb to bit 8
       }
-      else
-          return (unsigned int)(result & 0xFFFD);
+      return (unsigned int)(result & 0xfffd);
     }
   }
 
@@ -722,8 +809,10 @@ void m68k_write_memory_16(unsigned int address, unsigned int value) {
   }*/
 
   if (address == 0xDFF030) {
-    char *beb = (char *)&value;
-    printf("%c%c", beb[1], beb[0]);
+    char *serdat = (char *)&value;
+    // 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]);
   }
   if (address == 0xDFF09A) {
     if (!(value & 0x8000)) {
similarity index 75%
rename from main.h
rename to emulator.h
index 49944b00b57f9cec258dca9606698ab412670f50..f2849b1c62b61975871b83c9b351a633397958ec 100644 (file)
--- a/main.h
@@ -1,17 +1,16 @@
-//
-// BCM283x SMI interface 
-// Derived from Documentation
-// GVL 15-Oct-2014 
-//
-#ifndef MAIN__HEADER
-#define MAIN__HEADER
+/**
+ * pistorm
+ * emulator function declarations
+ */
 
+#ifndef _EMULATOR_H
+#define _EMULATOR_H
+
+// see feature_set_macros(7)
+#define _GNU_SOURCE
 
 #include <stdint.h>
 
-void setup_io();
-void restore_io();
-int set_pio_timing(int p);
 /*
 void write16(uint32_t address,uint16_t data);
 uint16_t read16(uint32_t address);
@@ -19,7 +18,6 @@ void write8(uint32_t address,uint16_t data);
 uint16_t read8(uint32_t address);
 */
 
-
 void cpu_pulse_reset(void);
 void m68ki_int_ack(uint8_t int_level);
 int cpu_irq_ack(int level);
@@ -30,7 +28,4 @@ void m68k_write_memory_8(unsigned int address, unsigned int value);
 void m68k_write_memory_16(unsigned int address, unsigned int value);
 void m68k_write_memory_32(unsigned int address, unsigned int value);
 
-
-
-#endif /* MAIN__HEADER */
-
+#endif /* _EMULATOR_H */
index 9ea5ef35ca35ea28daf026c66c33ef1976c9b17e..6d78f53e3a57f762a674f4a6708ca09739a97286 100644 (file)
@@ -7,9 +7,9 @@
 #include <fcntl.h>
 #include <sys/mman.h>
 #include <sys/ioctl.h>
-#include "../m68k.h"
-#include "../platforms/amiga/Gayle.h"
-#include "../platforms/amiga/gayle-ide/ide.h"
+#include "m68k.h"
+#include "platforms/amiga/Gayle.h"
+#include "platforms/amiga/gayle-ide/ide.h"
 #include "gpio_old.h"
 
 // I/O access
index 2e8364ee42aaef0040023a8b9542b918289238d1..92ec2ffcfdf041466e5dd3f78ad32c425820d1d4 100644 (file)
@@ -1,6 +1,6 @@
 /*
   Original Copyright 2020 Claude Schwarz
-  Code reorganized and rewritten by 
+  Code reorganized and rewritten by
   Niklas Ekström 2021 (https://github.com/niklasekstrom)
 */
 
@@ -13,7 +13,9 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+
 #include "ps_protocol.h"
+#include "m68k.h"
 
 volatile unsigned int *gpio;
 volatile unsigned int *gpclk;
index 7da63eab3e43e973f63fd80e08bbd434ab85bddd..bb5a725c30da38993613ec3ad812232895947e4e 100644 (file)
@@ -1,10 +1,12 @@
-#include <termios.h>
-#include <unistd.h>
+#include <linux/input.h>
+#include <pthread.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
-#include <linux/input.h>
-#include "../platforms/platforms.h"
+#include <termios.h>
+#include <unistd.h>
+
+#include "platforms/platforms.h"
 #include "input.h"
 
 #define NONE 0x80
@@ -13,24 +15,26 @@ static int lshift = 0, rshift = 0, lctrl = 0, rctrl = 0, lalt = 0, altgr = 0;
 extern int mouse_fd;
 extern int keyboard_fd;
 
-char keymap_amiga[256] = { \
-/*      00    01    02    03    04    05    06    07    08    09    0A    0B    0C    0D    0E    0F */ \
-/*00*/ 0x80, 0x45, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x41, 0x42, \
-/*10*/ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x44, 0x63, 0x20, 0x21, \
-/*20*/ 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x00, 0x60, 0x2B, 0x31, 0x32, 0x33, 0x34, \
-/*30*/ 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x61, 0x5D, 0x64, 0x40, NONE, 0x50, 0x51, 0x52, 0x53, 0x54, \
-/*40*/ 0x55, 0x56, 0x57, 0x58, 0x69, 0x5B, NONE, 0x3D, 0x3E, 0x3F, 0x4A, 0x2D, 0x2E, 0x2F, 0x4E, 0x1D, \
-/*50*/ 0x1E, 0x1F, 0x0F, 0x3C, NONE, NONE, 0x30, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, \
-/*60*/ 0x43, NONE, 0x5C, NONE, NONE, NONE, 0x5F, 0x4C, 0x5A, 0x4F, 0x4E, NONE, 0x4D, NONE, 0x0D, 0x46, \
-/*70*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, 0x66, 0x67, NONE, \
-/*80*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, \
-/*90*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, \
-/*A0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, \
-/*B0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, \
-/*C0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, \
-/*D0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, \
-/*E0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, \
-/*F0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE }; \
+// n.b. $fe and $ff are mapped to newmouse standard wheel up/down keycodes, nonexistant on amiga keyboards
+char keymap_amiga[256] = {
+/*      00    01    02    03    04    05    06    07    08    09    0A    0B    0C    0D    0E    0F */
+/*00*/ 0x80, 0x45, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x41, 0x42,
+/*10*/ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x44, 0x63, 0x20, 0x21,
+/*20*/ 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x00, 0x60, 0x2B, 0x31, 0x32, 0x33, 0x34,
+/*30*/ 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x61, 0x5D, 0x64, 0x40, NONE, 0x50, 0x51, 0x52, 0x53, 0x54,
+/*40*/ 0x55, 0x56, 0x57, 0x58, 0x69, 0x5B, NONE, 0x3D, 0x3E, 0x3F, 0x4A, 0x2D, 0x2E, 0x2F, 0x4E, 0x1D,
+/*50*/ 0x1E, 0x1F, 0x0F, 0x3C, NONE, NONE, 0x30, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+/*60*/ 0x43, NONE, 0x5C, NONE, NONE, NONE, 0x5F, 0x4C, 0x5A, 0x4F, 0x4E, NONE, 0x4D, NONE, 0x0D, 0x46,
+/*70*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, 0x66, 0x67, 0x67,
+/*80*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+/*90*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+/*A0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+/*B0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+/*C0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+/*D0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+/*E0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+/*F0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, 0x7A, 0x7B,
+};
 
 int handle_modifier(struct input_event *ev) {
   int *target_modifier = NULL;
@@ -65,6 +69,12 @@ int handle_modifier(struct input_event *ev) {
 
 #define KEYCASE(a, b, c)case a: return (lshift || rshift) ? c : b;
 
+/**
+ * translates keycodes back into a simpler enumerable value for handling emulator command events
+ *
+ * @param *struct/input_event  ev  pointer to input layer event structure
+ * @return char
+ */
 char char_from_input_event(struct input_event *ev) {
   switch(ev->code) {
     KEYCASE(KEY_A, 'a', 'A');
@@ -104,6 +114,7 @@ char char_from_input_event(struct input_event *ev) {
     KEYCASE(KEY_9, '9', '(');
     KEYCASE(KEY_0, '0', ')');
     KEYCASE(KEY_F12, 0x1B, 0x1B);
+    KEYCASE(KEY_PAUSE, 0x01, 0x01);
     default:
       return 0;
   }
@@ -129,16 +140,18 @@ int get_key_char(char *c, char *code, char *event_type)
   return 0;
 }
 
-uint16_t mouse_x = 0, mouse_y = 0, mouse_b = 0;
+uint8_t mouse_x = 0, mouse_y = 0;
 
-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];
-    mouse_x += ((char *)&ie)[1];
+int get_mouse_status(uint8_t *x, uint8_t *y, uint8_t *b, uint8_t *e) {
+  uint8_t mouse_ev[4];
+  if (read(mouse_fd, &mouse_ev, 4) != -1) {
+    *b = ((uint8_t *)&mouse_ev)[0];
+    *e = ((uint8_t *)&mouse_ev)[3];
+
+    mouse_x += ((uint8_t *)&mouse_ev)[1];
     *x = mouse_x;
-    mouse_y += (-((char *)&ie)[2]);
-    *y = mouse_y; //-((char *)&ie)[2];
+    mouse_y += (-((uint8_t *)&mouse_ev)[2]);
+    *y = mouse_y;
     return 1;
   }
 
@@ -170,7 +183,7 @@ int queue_keypress(uint8_t keycode, uint8_t event_type, uint8_t platform) {
   if (keymap != NULL) {
     if (keymap[keycode] != NONE) {
       if (queued_keypresses < 255) {
-        //printf("Keypress queued, matched %.2X to host key code %.2X\n", keycode, keymap[keycode]);
+        // printf("Keypress queued, matched %.2X to host key code %.2X\n", keycode, keymap[keycode]);
         queued_keys[queue_output_pos] = keymap[keycode];
         queued_events[queue_output_pos] = event_type;
         queue_output_pos++;
index d4810ecdd4bb1e29acf873174e341cc8af25987f..a7855342cb6a6c5eb78f2e9d12263a749dddc294 100644 (file)
@@ -1,10 +1,12 @@
+#include <stdint.h>
+
 enum keypress_type {
   KEYPRESS_RELEASE,
   KEYPRESS_PRESS,
   KEYPRESS_REPEAT,
 };
 
-int get_mouse_status(char *x, char *y, char *b);
+int get_mouse_status(uint8_t *x, uint8_t *y, uint8_t *b, uint8_t *e);
 int get_key_char(char *c, char *code, char *event_type);
 int queue_keypress(uint8_t keycode, uint8_t event_type, uint8_t platform);
 int get_num_kb_queued();
index 26ee063e9b08821558e7b05097e7bee07f1d11f4..a18195a26cd8f3953bb60d155ac7543cde293d52 100644 (file)
 #define M68K_USE_64_BIT  OPT_ON
 
 
-#include "main.h"
+#include "emulator.h"
 
 
 //#define m68k_read_memory_8(A)  read16(A)
index 3ecf4d2f9fe939832f78651827898886da6bc493..55da51ad6407b1297fd8692edbdfe5639fad57e2 100644 (file)
@@ -19,8 +19,8 @@
 #include <time.h>
 #include <endian.h>
 
-#include "../shared/rtc.h"
-#include "../../config_file/config_file.h"
+#include "platforms/shared/rtc.h"
+#include "config_file/config_file.h"
 
 #include "gayle-ide/ide.h"
 #include "amiga-registers.h"
@@ -109,7 +109,7 @@ void InitGayle(void) {
   }
   if (ide0)
     ide_reset_begin(ide0);
-  
+
   if (num_ide_drives == 0) {
     // No IDE drives mounted, disable IDE component of Gayle
     printf("No IDE drives mounted, disabling Gayle IDE component.\n");
index 054cfdb27c94b212e5cd141970168912059fc2d7..9fb849d44864090ae1a4c187ce3649a7f537c9f4 100644 (file)
@@ -1,4 +1,4 @@
-#include "../platforms.h"
+#include "platforms/platforms.h"
 #include "amiga-autoconf.h"
 #include <stdio.h>
 #include <stdlib.h>
@@ -263,7 +263,7 @@ unsigned int autoconfig_read_memory_8(struct emulator_config *cfg, unsigned int
       break;
   }
 
-  
+
   if ((address & 1) == 0 && (address / 2) < (int)sizeof(ac_fast_ram_rom)) {
     if (ac_z2_type[ac_z2_current_pic] == ACTYPE_MAPFAST_Z2 && address / 2 == 1) {
       val = get_autoconf_size(cfg->map_size[ac_z2_index[ac_z2_current_pic]]);
@@ -277,7 +277,7 @@ unsigned int autoconfig_read_memory_8(struct emulator_config *cfg, unsigned int
   val <<= 4;
   if (address != 0 && address != 2 && address != 0x40 && address != 0x42)
     val ^= 0xff;
-  
+
   return (unsigned int)val;
 }
 
index e5032a6364af2e9805c9c40ca6c7f819605ae028..554b6c67431aa3a2cb36f647127b5e3c84b044d0 100644 (file)
@@ -1,3 +1,5 @@
+#include "config_file/config_file.h"
+
 #define AC_Z2_BASE 0xE80000
 #define AC_Z3_BASE 0xFF000000
 #define AC_SIZE (64 * 1024)
index b284789d51b247848ad1d509b8eeba9007df95c1..5668bb8bdc2bfe016a5318002c5fe4aaebb2ec9b 100644 (file)
@@ -2,15 +2,15 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
-#include "../platforms.h"
 #include "amiga-autoconf.h"
 #include "amiga-registers.h"
-#include "../shared/rtc.h"
 #include "hunk-reloc.h"
-#include "piscsi/piscsi.h"
-#include "piscsi/piscsi-enums.h"
-#include "net/pi-net.h"
 #include "net/pi-net-enums.h"
+#include "net/pi-net.h"
+#include "piscsi/piscsi-enums.h"
+#include "piscsi/piscsi.h"
+#include "platforms/platforms.h"
+#include "platforms/shared/rtc.h"
 #include "rtg/rtg.h"
 
 int handle_register_read_amiga(unsigned int addr, unsigned char type, unsigned int *val);
@@ -249,7 +249,7 @@ int setup_platform_amiga(struct emulator_config *cfg) {
     index = get_named_mapped_item(cfg, z2_autoconf_id);
     if (index != -1)
         goto more_z2_fast;
-    
+
     for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i ++) {
         // Restore any "zapped" autoconf items so they can be reinitialized if needed.
         if (cfg->map_id[i] && strcmp(cfg->map_id[i], z2_autoconf_zap_id) == 0) {
@@ -292,7 +292,7 @@ int setup_platform_amiga(struct emulator_config *cfg) {
             fclose(in);
         }
     }
-    
+
     return 0;
 }
 
index 88314a424aaa7f2c92816a32bfdc69ead068727c..2d74fd6fe4f945e2f50db72d026fe1a4805378d4 100644 (file)
@@ -1,5 +1,5 @@
 #include "Gayle.h"
-#include "../../config_file/config_file.h"
+#include "config_file/config_file.h"
 #include "amiga-registers.h"
 
 uint8_t rtc_emulation_enabled = 1;
index 8da0bc2550f509b97bc5309b41323f4dc77e5187..a9868661e08567660a9f6d3ed566c6263f51d4c5 100644 (file)
@@ -32,6 +32,8 @@ void adjust_gayle_1200();
 #define CIAAPRA 0xBFE001
 #define CIAADAT 0xBFEC01
 #define CIAAICR 0xBFED01
+#define CIAACRA 0xBFEE01
+#define CIAACRB 0xBFEF01
 #define POTGOR  0xDFF016
 
 /* RAMSEY ADDRESSES */
@@ -39,4 +41,4 @@ void adjust_gayle_1200();
 #define RAMSEY_ID 0xDE0043  /* Either 0x0D or 0x0F (most recent version) */
 /* RAMSEY TYPES */
 #define RAMSEY_REV4 0x0D
-#define RAMSEY_REV7 0x0F
\ No newline at end of file
+#define RAMSEY_REV7 0x0F
index cfe25cd8295b29133c0af3412ef0cf460dffb5bc..f41adf1ebc29b7c4dcd72c4203c09938e8af4459 100644 (file)
@@ -1,7 +1,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
-#include "../../config_file/config_file.h"
+#include "config_file/config_file.h"
 
 uint8_t dmac_reg_idx = 0;
 uint8_t dmac_reg_values[0xFFFF];
index 64ddf4481a81c4686301e625ac1f7d9a66256417..9263201bbeead2d9bbd11e11f48fcb5f0c4f06f7 100644 (file)
 #include <errno.h>
 #include <time.h>
 #include <arpa/inet.h>
-#include "../../../config_file/config_file.h"
 
+#include "config_file/config_file.h"
 #include "ide.h"
 
 #define IDE_IDLE       0
 #define IDE_CMD                1
 #define IDE_DATA_IN    2
 #define IDE_DATA_OUT   3
+
 #define DCR_NIEN       2
 #define DCR_SRST       4
 
@@ -141,7 +141,7 @@ static off_t xlate_block(struct ide_taskfile *t)
   uint16_t cyl;
 
   if (d->controller->lba4 & DEVH_LBA) {
-/*    fprintf(stderr, "XLATE LBA %02X:%02X:%02X:%02X\n", 
+/*    fprintf(stderr, "XLATE LBA %02X:%02X:%02X:%02X\n",
       t->lba4, t->lba3, t->lba2, t->lba1);*/
     if (d->lba)
       return ((d->header_present) ? 2 : 0) + (((t->drive->controller->lba4 & DEVH_HEAD) << 24) | (t->drive->controller->lba3 << 16) | (t->drive->controller->lba2 << 8) | t->drive->controller->lba1);
@@ -261,7 +261,7 @@ static void ide_srst_begin(struct ide_controller *c)
     c->drive[0].taskfile.status |= ST_BSY;
   if (c->drive[1].present)
     c->drive[1].taskfile.status |= ST_BSY;
-}  
+}
 
 static void ide_srst_end(struct ide_controller *c)
 {
@@ -539,7 +539,7 @@ static void ide_data_out(struct ide_drive *d, uint16_t v, int len)
     if (d->dptr == d->data + 512) {
       if (ide_write_sector(d) < 0) {
         ide_set_error(d);
-        return;        
+        return;
       }
       d->length--;
       d->intrq = 1;
@@ -558,7 +558,7 @@ static void ide_issue_command(struct ide_taskfile *t)
   t->status |= ST_BSY;
   t->error = 0;
   t->drive->state = IDE_CMD;
-  
+
   /* We could complete with delays but don't do so yet */
   switch(t->command) {
     case IDE_CMD_EDD:  /* 0x90 */
@@ -675,7 +675,7 @@ void ide_write8(struct ide_controller *c, uint8_t r, uint8_t v)
       c->lba4 = v & (DEVH_HEAD|/*DEVH_DEV|*/DEVH_LBA);
       break;
     case ide_command_w:
-      t->command = v; 
+      t->command = v;
       ide_issue_command(t);
       break;
     case ide_devctrl_w:
@@ -831,7 +831,7 @@ void ide_detach(struct ide_drive *d)
 
 /*
  *     Free up and release and IDE controller
- */  
+ */
 void ide_free(struct ide_controller *c)
 {
   if (c->drive[0].present)
@@ -869,7 +869,7 @@ void ide_write_latched(struct ide_controller *c, uint8_t reg, uint8_t v)
   }
   if (reg == ide_data)
     d |=  (c->data_latch << 8);
-  ide_write16(c, reg, d);  
+  ide_write16(c, reg, d);
 }
 
 static void make_ascii(uint16_t *p, const char *t, int len)
@@ -883,7 +883,7 @@ static void make_ascii(uint16_t *p, const char *t, int len)
     *d = d[1];
     d[1] = c;
     d += 2;
-  }  
+  }
 }
 
 static void make_serial(uint16_t *p)
@@ -937,7 +937,7 @@ int ide_make_drive(uint8_t type, int fd)
 
   if (type < 1 || type > MAX_DRIVE_TYPE)
     return -2;
-  
+
   memset(ident, 0, 512);
   memcpy(ident, ide_magic, 8);
   if (write(fd, ident, 512) != 512)
@@ -949,7 +949,7 @@ int ide_make_drive(uint8_t type, int fd)
   ident[47] = 0; /* no read multi for now */
   ident[51] = le16(240 /* PIO2 */ << 8);       /* PIO cycle time */
   ident[53] = le16(1);         /* Geometry words are valid */
-  
+
   switch(type) {
     case ACME_ROADRUNNER:
       /* 504MB drive with LBA support */
@@ -959,7 +959,7 @@ int ide_make_drive(uint8_t type, int fd)
       make_ascii(ident + 23, "A001.001", 8);
       make_ascii(ident + 27, "ACME ROADRUNNER v0.1", 40);
       ident[49] = le16(1 << 9); /* LBA */
-      break;  
+      break;
     case ACME_ULTRASONICUS:
       /* 40MB drive with LBA support */
       c = 977;
@@ -985,7 +985,7 @@ int ide_make_drive(uint8_t type, int fd)
       s = 16;
       make_ascii(ident + 23, "A001.001", 8);
       make_ascii(ident + 27, "ACME COYOTE v0.1", 40);
-      break;  
+      break;
     case ACME_ACCELLERATTI:
       c = 1024;
       h = 16;
@@ -1016,10 +1016,10 @@ int ide_make_drive(uint8_t type, int fd)
   ident[61] = ident[58];
   if (write(fd, ident, 512) != 512)
     return -1;
-  
+
   memset(ident, 0xE5, 512);
   while(sectors--)
     if (write(fd, ident, 512) != 512)
-      return -1;  
+      return -1;
   return 0;
 }
index c153ac6c69fd47373f030eee1dc9dda68f447dd6..ef64444c75a9252d95eadb48e49f7d9bea38264e 100644 (file)
@@ -1,3 +1,6 @@
+#ifndef _HUNK_RELOC_H
+#define _HUNK_RELOC_H
+
 struct hunk_reloc {
     uint32_t src_hunk;
     uint32_t target_hunk;
@@ -32,3 +35,5 @@ int load_lseg(int fd, uint8_t **buf_p, struct hunk_info *i, struct hunk_reloc *r
 void reloc_hunk(struct hunk_reloc *h, uint8_t *buf, struct hunk_info *i);
 void process_hunks(FILE *in, struct hunk_info *h_info, struct hunk_reloc *r, uint32_t offset);
 void reloc_hunks(struct hunk_reloc *r, uint8_t *buf, struct hunk_info *h_info);
+
+#endif /* _HUNK_RELOC_H */
index 68923f5f6cc92eb084f7cdda2af275cee8f0d0cc..b7517a2c23f608732b4f9f8763c5a390265c2253 100644 (file)
@@ -128,7 +128,7 @@ uint32_t __UserDevOpen(struct IORequest *io, uint32_t num, uint32_t flags) {
 
             NewList(&dev_base->read_list);
             InitSemaphore(&dev_base->read_list_sem);
-            
+
             ret = 0;
             ok = 1;
         //}
@@ -162,7 +162,7 @@ uint32_t pinet_read_frame(struct IOSana2Req *ioreq) {
     uint32_t sz   = ((uint32_t)frm[0] << 8) | ((uint32_t)frm[1]);
     uint32_t ser  = ((uint32_t)frm[2] << 8) | ((uint32_t)frm[3]);
     uint16_t tp   = ((uint16_t)frm[16] << 8) | ((uint16_t)frm[17]);
-    
+
     if (req->ios2_Req.io_Flags & SANA2IOF_RAW) {
         frame_ptr = frm + 4;
         datasize = sz;
@@ -193,10 +193,10 @@ uint32_t pinet_read_frame(struct IOSana2Req *ioreq) {
         req->ios2_Req.io_Error = req->ios2_WireError = 0;
         err = 0;
     }
-    
+
     memcpy(req->ios2_SrcAddr, frame+4+6, HW_ADDRFIELDSIZE);
     memcpy(req->ios2_DstAddr, frame+4, HW_ADDRFIELDSIZE);
-    
+
     //D(("RXSZ %ld\n",(LONG)sz));
     //D(("RXPT %ld\n",(LONG)tp));
 
@@ -215,14 +215,14 @@ uint32_t pinet_read_frame(struct IOSana2Req *ioreq) {
     if (broadcast) {
         req->ios2_Req.io_Flags |= SANA2IOF_BCAST;
     }
-    
+
     req->ios2_PacketType = tp;*/
 
     return err;
 }
 
 void pinet_write_frame(struct IOSana2Req *ioreq) {
-    
+
 }
 
 void exit(int status) { }
@@ -333,7 +333,7 @@ void __AbortIO(struct IORequest* ioreq) {
 ADDTABL_1(__TermIO,a1);
 void __TermIO(struct IORequest *ioreq) {
     struct IOSana2Req* ios2 = (struct IOSana2Req*)ioreq;
-    
+
     if (!(ios2->ios2_Req.io_Flags & SANA2IOF_QUICK)) {
         ReplyMsg((struct Message *)ioreq);
     } else {
@@ -359,7 +359,7 @@ ULONG read_frame(struct IOSana2Req *req, volatile UBYTE *frame)
   ULONG sz   = ((ULONG)frm[0]<<8)|((ULONG)frm[1]);
   ULONG ser  = ((ULONG)frm[2]<<8)|((ULONG)frm[3]);
   USHORT tp  = ((USHORT)frm[16]<<8)|((USHORT)frm[17]);
-  
+
   if (req->ios2_Req.io_Flags & SANA2IOF_RAW) {
     frame_ptr = frm+4;
     datasize = sz;
@@ -390,10 +390,10 @@ ULONG read_frame(struct IOSana2Req *req, volatile UBYTE *frame)
     req->ios2_Req.io_Error = req->ios2_WireError = 0;
     err = 0;
   }
-  
+
   memcpy(req->ios2_SrcAddr, frame+4+6, HW_ADDRFIELDSIZE);
   memcpy(req->ios2_DstAddr, frame+4, HW_ADDRFIELDSIZE);
-  
+
   //D(("RXSZ %ld\n",(LONG)sz));
   //D(("RXPT %ld\n",(LONG)tp));
 
@@ -412,7 +412,7 @@ ULONG read_frame(struct IOSana2Req *req, volatile UBYTE *frame)
   if (broadcast) {
     req->ios2_Req.io_Flags |= SANA2IOF_BCAST;
   }
-  
+
   req->ios2_PacketType = tp;
 
   return err;
@@ -423,7 +423,7 @@ ULONG write_frame(struct IOSana2Req *req, UBYTE *frame)
    ULONG rc=0;
    struct BufferManagement *bm;
    USHORT sz=0;
-   
+
    if (req->ios2_Req.io_Flags & SANA2IOF_RAW) {
       sz = req->ios2_DataLength;
    } else {
index 857bc2c928af53ee576cca5ed78361cd946e7543..f19bae1db61c9a153de523f56588d3d9ebf5d140 100644 (file)
@@ -5,8 +5,8 @@
 #include <endian.h>
 #include "pi-net.h"
 #include "pi-net-enums.h"
-#include "../../../config_file/config_file.h"
-#include "../../../gpio/ps_protocol.h"
+#include "config_file/config_file.h"
+#include "gpio/ps_protocol.h"
 
 uint32_t pinet_u32[4];
 static const char *op_type_names[4] = {
index 3f354dd387ff9430ee8d71d3dae54f62927c69e0..cf9c696d006ad250d524d8a3e4585c3fb892ba4d 100644 (file)
@@ -5,11 +5,12 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <endian.h>
-#include "../hunk-reloc.h"
-#include "piscsi.h"
+
+#include "config_file/config_file.h"
+#include "gpio/ps_protocol.h"
 #include "piscsi-enums.h"
-#include "../../../config_file/config_file.h"
-#include "../../../gpio/ps_protocol.h"
+#include "piscsi.h"
+#include "platforms/amiga/hunk-reloc.h"
 
 #define BE(val) be32toh(val)
 #define BE16(val) be16toh(val)
@@ -213,16 +214,16 @@ void piscsi_refresh_drives() {
 void piscsi_find_filesystems(struct piscsi_dev *d) {
     if (!d->num_partitions)
         return;
-    
+
     uint8_t fs_found = 0;
-    
+
     uint8_t *fhb_block = malloc(512);
 
     lseek64(d->fd, d->fshd_offs, SEEK_SET);
 
     struct FileSysHeaderBlock *fhb = (struct FileSysHeaderBlock *)fhb_block;
     read(d->fd, fhb_block, 512);
-    
+
     while (BE(fhb->fhb_ID) == FS_IDENTIFIER) {
         char *dosID = (char *)&fhb->fhb_DosType;
 #ifdef PISCSI_DEBUG
@@ -245,7 +246,7 @@ void piscsi_find_filesystems(struct piscsi_dev *d) {
                 DEBUG("[FSHD] File system %c%c%c/%d already loaded. Skipping.\n", dosID[0], dosID[1], dosID[2], dosID[3]);
                 if (BE(fhb->fhb_Next) == 0xFFFFFFFF)
                     goto fs_done;
-                
+
                 goto skip_fs_load_lseg;
             }
         }
@@ -615,7 +616,7 @@ void handle_piscsi_write(uint32_t addr, uint32_t val, uint8_t type) {
                 memcpy(dst_data + addr, piscsi_rom_ptr + PISCSI_DRIVER_OFFSET, 0x4000 - PISCSI_DRIVER_OFFSET);
 
                 piscsi_hinfo.base_offset = val;
-                
+
                 reloc_hunks(piscsi_hreloc, dst_data + addr, &piscsi_hinfo);
 
                 #define PUTNODELONG(val) *(uint32_t *)&dst_data[p_offs] = htobe32(val); p_offs += 4;
@@ -685,7 +686,7 @@ void handle_piscsi_write(uint32_t addr, uint32_t val, uint8_t type) {
 skip_disk:;
                 }
             }
-           
+
             break;
         }
         case PISCSI_CMD_NEXTPART:
@@ -780,7 +781,7 @@ uint32_t handle_piscsi_read(uint32_t addr, uint8_t type) {
         }
         return 0;
     }
-    
+
     switch (addr & 0xFFFF) {
         case PISCSI_CMD_ADDR1: case PISCSI_CMD_ADDR2: case PISCSI_CMD_ADDR3: case PISCSI_CMD_ADDR4: {
             int i = ((addr & 0xFFFF) - PISCSI_CMD_ADDR1) / 4;
index 5ed0078320c3c711916b3a705bfd85b7896f27af..7c008d45b3e0e10186df7c73227c55779b83ec73 100644 (file)
@@ -1,3 +1,7 @@
+#include <stdint.h>
+
+#include "platforms/amiga/hunk-reloc.h"
+
 #define        TDF_EXTCOM (1<<15)
 
 #define CMD_INVALID    0
index 95b77983991e48fa00e59ce6621745439637c7de..8cd177fa3845a392b0ef61c61099204f36a0c5eb 100644 (file)
@@ -2,9 +2,9 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
-#include "../../../config_file/config_file.h"
+#include "config_file/config_file.h"
 #ifndef FAKESTORM
-#include "../../../gpio/ps_protocol.h"
+#include "gpio/ps_protocol.h"
 #endif
 #include "rtg.h"
 
@@ -344,7 +344,7 @@ void rtg_blittemplate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t s
                         else {
                             SET_RTG_PIXELS2_COND_MASK(&dptr[xs << format], fg_color[format], bg_color[format], format);
                         }
-                        
+
                         xs += 7;
                     }
                     else {
@@ -484,7 +484,7 @@ void rtg_blitpattern(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t sr
                         else {
                             SET_RTG_PIXELS2_COND_MASK(&dptr[xs << format], fg_color[format], bg_color[format], format);
                         }
-                        
+
                         xs += 7;
                     }
                     else {
index 5423671ba76fd42e97cb413d0f8309cb4baaa111..6f218cc797d7f7e17ca336b6b2459daaeed73f91 100644 (file)
@@ -1,11 +1,13 @@
+#include "emulator.h"
+#include "rtg.h"
+
+#include <pthread.h>
 #include <SDL2/SDL.h>
-#include <stdio.h>
 #include <stdint.h>
+#include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
-#include <pthread.h>
 #include <string.h>
-#include "rtg.h"
+#include <unistd.h>
 
 #define RTG_INIT_ERR(a) { printf(a); *data->running = 0; }
 
@@ -201,7 +203,7 @@ shutdown_sdl:;
 
     if (reinit)
         goto reinit_sdl;
-    
+
     if (indexed_buf)
         free(indexed_buf);
 
@@ -227,6 +229,7 @@ void rtg_init_display() {
         }
         else {
             rtg_initialized = 1;
+            pthread_setname_np(thread_id, "pistorm: rtg");
             printf("RTG Thread created successfully\n");
         }
     }
index c4b7f561111dbbf7305adcc9273725c868d2dc29..a4be06952d528bd5aa9392ca16ac390ae247b5bc 100644 (file)
@@ -5,7 +5,7 @@
 #include <string.h>
 #include <time.h>
 #include "rtg.h"
-#include "../../../config_file/config_file.h"
+#include "config_file/config_file.h"
 
 uint8_t rtg_u8[4];
 uint16_t rtg_x[8], rtg_y[8];
index 7e431e0d5286ec5484f2c262f66d9d6b3a1e3b25..0a4e177d3f01998395ec0d0b9d4d4ae2e18fe2ae 100644 (file)
@@ -1,7 +1,8 @@
-#include "../platforms.h"
 #include <stdlib.h>
 #include <string.h>
 
+#include "platforms/platforms.h"
+
 int handle_register_read_dummy(unsigned int addr, unsigned char type, unsigned int *val);
 int handle_register_write_dummy(unsigned int addr, unsigned int value, unsigned char type);
 
index 82a286811e9687afef9d645450be90b56f5438ac..e9d2cdb1e4a3b07636693807c422d4938cef942d 100644 (file)
@@ -1,4 +1,4 @@
-#include "../config_file/config_file.h"
+#include "config_file/config_file.h"
 
 enum base_platforms {
     PLATFORM_NONE,
index 400fd593fdca4c299c935caaabaf54e5b0049b2e..d561daa36481ba0349f980e4a4a18afbf2bdbf75 100644 (file)
@@ -30,7 +30,7 @@ these four paragraphs for those parts of this code that are retained.
 
 =============================================================================*/
 
-#include "../m68kcpu.h" // which includes softfloat.h after defining the basic types
+#include "m68kcpu.h" // which includes softfloat.h after defining the basic types
 
 /*----------------------------------------------------------------------------
 | Floating-point rounding mode, extended double-precision rounding precision,