]> git.sesse.net Git - pistorm/commitdiff
Merge branch 'wip-crap' of https://github.com/beeanyew/pistorm into wip-crap
authorjust nine <nine@aphlor.org>
Tue, 3 Mar 2020 07:16:02 +0000 (07:16 +0000)
committerjust nine <nine@aphlor.org>
Tue, 3 Mar 2020 07:16:02 +0000 (07:16 +0000)
.gitignore
68new.cfg
emulator.c
input/input.c
input/input.h
platforms/amiga/registers.h [new file with mode: 0644]

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 b1ac4bcc07bdfaece9805f4d1c8d5629078fe15c..290b6c051a3f2dd195c981c1f590359ff9d6da5e 100644 (file)
@@ -43,8 +43,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;
@@ -251,10 +252,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");
     }
   }
 
@@ -322,7 +339,7 @@ int main(int argc, char *argv[]) {
   m68k_pulse_reset();
   while (42) {
     if (mouse_hook_enabled) {
-      get_mouse_status(&mouse_dx, &mouse_dy, &mouse_buttons);
+      get_mouse_status(&mouse_dx, &mouse_dy, &mouse_buttons, &mouse_extra);
     }
 
     if (realtime_disassembly && (do_disasm || cpu_emulation_running)) {
@@ -400,11 +417,18 @@ int main(int argc, char *argv[]) {
         }
       }
 
+      // pause pressed; trigger nmi (int level 7)
+      if (c == 0x01 && c_type) {
+        printf("[INT] Sending NMI\n");
+        last_irq = 7;
+        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 = 0;
+          mouse_dx = mouse_dy = mouse_buttons = mouse_extra = 0;
         }
         if (c == 'r') {
           cpu_emulation_running ^= 1;
@@ -445,6 +469,23 @@ int main(int argc, char *argv[]) {
         }
       }
     }
+
+    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;
+    }
   }
 
   stop_cpu_emulation:;
@@ -545,10 +586,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 +652,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 +765,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)) {
index 7da63eab3e43e973f63fd80e08bbd434ab85bddd..cee65e72a7705feb45dc2e58ca56bd7e9a7c849d 100644 (file)
@@ -13,6 +13,7 @@ static int lshift = 0, rshift = 0, lctrl = 0, rctrl = 0, lalt = 0, altgr = 0;
 extern int mouse_fd;
 extern int keyboard_fd;
 
+// 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, \
@@ -22,7 +23,7 @@ char keymap_amiga[256] = { \
 /*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, \
+/*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, \
@@ -30,7 +31,7 @@ char keymap_amiga[256] = { \
 /*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 }; \
+/*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 +66,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 +111,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 +137,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 +180,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();
diff --git a/platforms/amiga/registers.h b/platforms/amiga/registers.h
new file mode 100644 (file)
index 0000000..ec7b825
--- /dev/null
@@ -0,0 +1,52 @@
+/**
+ * amiga custom chip registers
+ *
+ * transcribed from adcd 2.1 amigaguide. likely omits aa chipset registers, and gayle.
+ *
+ * just nine <nine@aphlor.org>
+ */
+
+#ifndef _AMIGA_REGISTERS_H
+#define _AMIGA_REGISTERS_H
+
+/**
+ * three discernable banks which cover all amiga systems.
+ *
+ * bfd000-bfdf00 for the even cia
+ * bfe001-bfef01 for the odd cia
+ * dff000-dfffff for custom chip registers
+ *
+ * we will concern ourselves with the custom chip registers here; the cia is for additional i/o ops
+ */
+
+#define CREG_BASE   0xdff000
+#define CREG_END    0xdfffff
+
+#define BLTDDAT     CREG_BASE + 0x000   // agnus, blitter destination early read address (dummy)
+#define DMACONR     CREG_BASE + 0x002   // agnus, paula dma control + blitter status read
+#define VPOSR       CREG_BASE + 0x004   // ecs agnus, read vertical msb + frame flop
+#define VHPOSR      CREG_BASE + 0x006   // agnus, vertical + horizonal position of beam
+#define DSKDATR     CREG_BASE + 0x008   // paula, disk data early read address (dummy)
+#define JOY0DAT     CREG_BASE + 0x00a   // denise, input port 0 data
+#define JOY1DAT     CREG_BASE + 0x00c   // denise, input port 1 data
+// clxdat
+// adkconr
+// pot0dat
+// pot1dat
+// potgor
+#define SERDATR     CREG_BASE + 0x018   // paula, serial port data and status, read
+// dskbytr
+// internar
+// intreqr
+// dskpth
+// dskptl
+// dsklen
+// refptr
+// vposw
+// vhposw
+// copcon
+#define SERDAT      CREG_BASE + 0x030   // paula, serial port data and stop bits, write
+#define SERPER      CREG_BASE + 0x032   // paula, serial port speed and control
+// @todo: the rest?!
+
+#endif