handle frequent psg updates
[picodrive.git] / pico / memory.c
index fb5fa9b..0907696 100644 (file)
@@ -385,6 +385,28 @@ void NOINLINE ctl_write_z80reset(u32 d)
   }\r
 }\r
 \r
+static int get_scanline(int is_from_z80);\r
+\r
+static void psg_write_68k(u32 d)\r
+{\r
+  // look for volume write and update if needed\r
+  if ((d & 0x90) == 0x90 && PsndPsgLine < Pico.m.scanline)\r
+    PsndDoPSG(Pico.m.scanline);\r
+\r
+  SN76496Write(d);\r
+}\r
+\r
+static void psg_write_z80(u32 d)\r
+{\r
+  if ((d & 0x90) == 0x90) {\r
+    int scanline = get_scanline(1);\r
+    if (PsndPsgLine < scanline)\r
+      PsndDoPSG(scanline);\r
+  }\r
+\r
+  SN76496Write(d);\r
+}\r
+\r
 // -----------------------------------------------------------------\r
 \r
 #ifndef _ASM_MEMORY_C\r
@@ -528,8 +550,7 @@ static void PicoWrite8_z80(u32 a, u32 d)
   }\r
   // TODO: probably other VDP access too? Maybe more mirrors?\r
   if ((a & 0x7ff9) == 0x7f11) { // PSG Sound\r
-    if (PicoOpt & POPT_EN_PSG)\r
-      SN76496Write(d);\r
+    psg_write_68k(d);\r
     return;\r
   }\r
   if ((a & 0x7f00) == 0x6000) // Z80 BANK register\r
@@ -703,8 +724,7 @@ static u32 PicoRead16_vdp(u32 a)
 static void PicoWrite8_vdp(u32 a, u32 d)\r
 {\r
   if ((a & 0x00f9) == 0x0011) { // PSG Sound\r
-    if (PicoOpt & POPT_EN_PSG)\r
-      SN76496Write(d);\r
+    psg_write_68k(d);\r
     return;\r
   }\r
   if ((a & 0x00e0) == 0x0000) {\r
@@ -718,11 +738,8 @@ static void PicoWrite8_vdp(u32 a, u32 d)
 \r
 static void PicoWrite16_vdp(u32 a, u32 d)\r
 {\r
-  if ((a & 0x00f9) == 0x0010) { // PSG Sound\r
-    if (PicoOpt & POPT_EN_PSG)\r
-      SN76496Write(d);\r
-    return;\r
-  }\r
+  if ((a & 0x00f9) == 0x0010) // PSG Sound\r
+    psg_write_68k(d);\r
   if ((a & 0x00e0) == 0x0000) {\r
     PicoVideoWrite(a, d);\r
     return;\r
@@ -1198,8 +1215,7 @@ static void z80_md_vdp_br_write(unsigned int a, unsigned char data)
 {\r
   if ((a&0xfff9) == 0x7f11) // 7f11 7f13 7f15 7f17\r
   {\r
-    if (PicoOpt & POPT_EN_PSG)\r
-      SN76496Write(data);\r
+    psg_write_z80(data);\r
     return;\r
   }\r
   // at least VDP data writes hang my machine\r