Browse Source

core, some test code for team player and 4way play

root 2 years ago
parent
commit
9c5ed6de21
2 changed files with 80 additions and 1 deletions
  1. 78 1
      pico/memory.c
  2. 2 0
      pico/pico.h

+ 78 - 1
pico/memory.c

@@ -256,6 +256,65 @@ out:
   return value;
 }
 
+static u32 read_pad_team(int i, u32 out_bits)
+{
+  u32 pad;
+  int phase = Pico.m.padTHPhase[i];
+  u32 value;
+
+  if (phase == 0) {
+    value = 0x03;
+    goto out;
+  }
+  if (phase == 1) {
+    value = 0x0f;
+    goto out;
+  }
+
+  pad = ~PicoIn.padInt[0]; // Get inverse of pad MXYZ SACB RLDU
+  if (phase == 8) {
+    value = pad & 0x0f;                          // ?x?x RLDU
+    goto out;
+  }
+  else if(phase == 9) {
+    value = (pad & 0xf0) >>  4;                  // ?x?x SACB
+    goto out;
+  }
+
+  pad = ~PicoIn.padInt[1]; // Get inverse of pad MXYZ SACB RLDU
+  if (phase == 12) {
+    value = pad & 0x0f;                          // ?x?x RLDU
+    goto out;
+  }
+  else if(phase == 13) {
+    value = (pad & 0xf0) >>  4;                  // ?x?x SACB
+    goto out;
+  }
+
+  if (phase >= 8 && pad < 16) {
+    value = 0x0f;
+    goto out;
+  }
+
+  value = 0;
+
+out:
+  value |= (out_bits & 0x40) | ((out_bits & 0x20)>>1);
+  return value;
+}
+
+static u32 read_pad_4way(int i, u32 out_bits)
+{
+  u32 pad = (PicoMem.ioports[2] & 0x70) >> 4;
+  u32 value = 0;
+
+  if (i == 0 && !(pad & 1))
+    value = read_pad_3btn(pad >> 1, out_bits);
+
+  value |= (out_bits & 0x40);
+  return value;
+}
+
 static u32 read_nothing(int i, u32 out_bits)
 {
   return 0xff;
@@ -307,6 +366,14 @@ void PicoSetInputDevice(int port, enum input_device device)
     func = read_pad_6btn;
     break;
 
+  case PICO_INPUT_PAD_TEAM:
+    func = read_pad_team;
+    break;
+
+  case PICO_INPUT_PAD_4WAY:
+    func = read_pad_4way;
+    break;
+
   default:
     func = read_nothing;
     break;
@@ -337,7 +404,17 @@ NOINLINE void io_ports_write(u32 a, u32 d)
   if (1 <= a && a <= 2)
   {
     Pico.m.padDelay[a - 1] = 0;
-    if (!(PicoMem.ioports[a] & 0x40) && (d & 0x40))
+    if (port_readers[a - 1] == read_pad_team) {
+      if (d & 0x40)
+        Pico.m.padTHPhase[a - 1] = 0;
+      else if ((d^PicoMem.ioports[a]) & 0x60)
+        Pico.m.padTHPhase[a - 1]++;
+    } else if (port_readers[a - 1] == read_pad_4way) {
+      if (a == 2 && ((PicoMem.ioports[a] ^ d) & 0x70))
+        Pico.m.padTHPhase[0] = 0;
+      if (a == 1 && !(PicoMem.ioports[a] & 0x40) && (d & 0x40))
+        Pico.m.padTHPhase[0]++;
+    } else if (!(PicoMem.ioports[a] & 0x40) && (d & 0x40))
       Pico.m.padTHPhase[a - 1]++;
   }
 

+ 2 - 0
pico/pico.h

@@ -308,6 +308,8 @@ enum input_device {
   PICO_INPUT_NOTHING,
   PICO_INPUT_PAD_3BTN,
   PICO_INPUT_PAD_6BTN,
+  PICO_INPUT_PAD_TEAM,
+  PICO_INPUT_PAD_4WAY,
 };
 void PicoSetInputDevice(int port, enum input_device device);