improve 64bit portability
[picodrive.git] / pico / memory.c
index b49956e..a31a08e 100644 (file)
@@ -389,7 +389,7 @@ static int get_scanline(int is_from_z80);
 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
+  if ((d & 0x90) == 0x90 && Pico.snd.psg_line < Pico.m.scanline)\r
     PsndDoPSG(Pico.m.scanline);\r
 \r
   SN76496Write(d);\r
@@ -399,7 +399,7 @@ static void psg_write_z80(u32 d)
 {\r
   if ((d & 0x90) == 0x90) {\r
     int scanline = get_scanline(1);\r
-    if (PsndPsgLine < scanline)\r
+    if (Pico.snd.psg_line < scanline)\r
       PsndDoPSG(scanline);\r
   }\r
 \r
@@ -832,10 +832,10 @@ PICO_INTERNAL void PicoMemSetup(void)
     int i;\r
     // by default, point everything to first 64k of ROM\r
     for (i = 0; i < M68K_FETCHBANK1 * 0xe0 / 0x100; i++)\r
-      PicoCpuFM68k.Fetch[i] = (unsigned long)Pico.rom - (i<<(24-FAMEC_FETCHBITS));\r
+      PicoCpuFM68k.Fetch[i] = (uptr)Pico.rom - (i<<(24-FAMEC_FETCHBITS));\r
     // now real ROM\r
     for (i = 0; i < M68K_FETCHBANK1 && (i<<(24-FAMEC_FETCHBITS)) < Pico.romsize; i++)\r
-      PicoCpuFM68k.Fetch[i] = (unsigned long)Pico.rom;\r
+      PicoCpuFM68k.Fetch[i] = (uptr)Pico.rom;\r
     // RAM already set\r
   }\r
 #endif\r
@@ -895,41 +895,41 @@ void ym2612_sync_timers(int z80_cycles, int mode_old, int mode_new)
   int xcycles = z80_cycles << 8;\r
 \r
   /* check for overflows */\r
-  if ((mode_old & 4) && xcycles > timer_a_next_oflow)\r
+  if ((mode_old & 4) && xcycles > Pico.t.timer_a_next_oflow)\r
     ym2612.OPN.ST.status |= 1;\r
 \r
-  if ((mode_old & 8) && xcycles > timer_b_next_oflow)\r
+  if ((mode_old & 8) && xcycles > Pico.t.timer_b_next_oflow)\r
     ym2612.OPN.ST.status |= 2;\r
 \r
   /* update timer a */\r
   if (mode_old & 1)\r
-    while (xcycles > timer_a_next_oflow)\r
-      timer_a_next_oflow += timer_a_step;\r
+    while (xcycles > Pico.t.timer_a_next_oflow)\r
+      Pico.t.timer_a_next_oflow += Pico.t.timer_a_step;\r
 \r
   if ((mode_old ^ mode_new) & 1) // turning on/off\r
   {\r
     if (mode_old & 1)\r
-      timer_a_next_oflow = TIMER_NO_OFLOW;\r
+      Pico.t.timer_a_next_oflow = TIMER_NO_OFLOW;\r
     else\r
-      timer_a_next_oflow = xcycles + timer_a_step;\r
+      Pico.t.timer_a_next_oflow = xcycles + Pico.t.timer_a_step;\r
   }\r
   if (mode_new & 1)\r
-    elprintf(EL_YMTIMER, "timer a upd to %i @ %i", timer_a_next_oflow>>8, z80_cycles);\r
+    elprintf(EL_YMTIMER, "timer a upd to %i @ %i", Pico.t.timer_a_next_oflow>>8, z80_cycles);\r
 \r
   /* update timer b */\r
   if (mode_old & 2)\r
-    while (xcycles > timer_b_next_oflow)\r
-      timer_b_next_oflow += timer_b_step;\r
+    while (xcycles > Pico.t.timer_b_next_oflow)\r
+      Pico.t.timer_b_next_oflow += Pico.t.timer_b_step;\r
 \r
   if ((mode_old ^ mode_new) & 2)\r
   {\r
     if (mode_old & 2)\r
-      timer_b_next_oflow = TIMER_NO_OFLOW;\r
+      Pico.t.timer_b_next_oflow = TIMER_NO_OFLOW;\r
     else\r
-      timer_b_next_oflow = xcycles + timer_b_step;\r
+      Pico.t.timer_b_next_oflow = xcycles + Pico.t.timer_b_step;\r
   }\r
   if (mode_new & 2)\r
-    elprintf(EL_YMTIMER, "timer b upd to %i @ %i", timer_b_next_oflow>>8, z80_cycles);\r
+    elprintf(EL_YMTIMER, "timer b upd to %i @ %i", Pico.t.timer_b_next_oflow>>8, z80_cycles);\r
 }\r
 \r
 // ym2612 DAC and timer I/O handlers for z80\r
@@ -941,7 +941,7 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80)
   if (a == 1 && ym2612.OPN.ST.address == 0x2a) /* DAC data */\r
   {\r
     int scanline = get_scanline(is_from_z80);\r
-    //elprintf(EL_STATUS, "%03i -> %03i dac w %08x z80 %i", PsndDacLine, scanline, d, is_from_z80);\r
+    //elprintf(EL_STATUS, "%03i -> %03i dac w %08x z80 %i", Pico.snd.dac_line, scanline, d, is_from_z80);\r
     ym2612.dacout = ((int)d - 0x80) << 6;\r
     if (ym2612.dacen)\r
       PsndDoDAC(scanline);\r
@@ -977,13 +977,13 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80)
             ym2612.OPN.ST.TA = TAnew;\r
             //ym2612.OPN.ST.TAC = (1024-TAnew)*18;\r
             //ym2612.OPN.ST.TAT = 0;\r
-            timer_a_step = TIMER_A_TICK_ZCYCLES * (1024 - TAnew);\r
+            Pico.t.timer_a_step = TIMER_A_TICK_ZCYCLES * (1024 - TAnew);\r
             if (ym2612.OPN.ST.mode & 1) {\r
               // this is not right, should really be done on overflow only\r
               int cycles = is_from_z80 ? z80_cyclesDone() : z80_cycles_from_68k();\r
-              timer_a_next_oflow = (cycles << 8) + timer_a_step;\r
+              Pico.t.timer_a_next_oflow = (cycles << 8) + Pico.t.timer_a_step;\r
             }\r
-            elprintf(EL_YMTIMER, "timer a set to %i, %i", 1024 - TAnew, timer_a_next_oflow>>8);\r
+            elprintf(EL_YMTIMER, "timer a set to %i, %i", 1024 - TAnew, Pico.t.timer_a_next_oflow>>8);\r
           }\r
           return 0;\r
         }\r
@@ -993,12 +993,12 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80)
             ym2612.OPN.ST.TB = d;\r
             //ym2612.OPN.ST.TBC = (256-d) * 288;\r
             //ym2612.OPN.ST.TBT  = 0;\r
-            timer_b_step = TIMER_B_TICK_ZCYCLES * (256 - d); // 262800\r
+            Pico.t.timer_b_step = TIMER_B_TICK_ZCYCLES * (256 - d); // 262800\r
             if (ym2612.OPN.ST.mode & 2) {\r
               int cycles = is_from_z80 ? z80_cyclesDone() : z80_cycles_from_68k();\r
-              timer_b_next_oflow = (cycles << 8) + timer_b_step;\r
+              Pico.t.timer_b_next_oflow = (cycles << 8) + Pico.t.timer_b_step;\r
             }\r
-            elprintf(EL_YMTIMER, "timer b set to %i, %i", 256 - d, timer_b_next_oflow>>8);\r
+            elprintf(EL_YMTIMER, "timer b set to %i, %i", 256 - d, Pico.t.timer_b_next_oflow>>8);\r
           }\r
           return 0;\r
         case 0x27: { /* mode, timer control */\r
@@ -1029,7 +1029,7 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80)
           int scanline = get_scanline(is_from_z80);\r
           if (ym2612.dacen != (d & 0x80)) {\r
             ym2612.dacen = d & 0x80;\r
-            PsndDacLine = scanline;\r
+            Pico.snd.dac_line = scanline;\r
           }\r
 #ifdef __GP2X__\r
           if (PicoIn.opt & POPT_EXT_FM) YM2612Write_940(a, d, scanline);\r
@@ -1065,9 +1065,9 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80)
 \r
 \r
 #define ym2612_read_local() \\r
-  if (xcycles >= timer_a_next_oflow) \\r
+  if (xcycles >= Pico.t.timer_a_next_oflow) \\r
     ym2612.OPN.ST.status |= (ym2612.OPN.ST.mode >> 2) & 1; \\r
-  if (xcycles >= timer_b_next_oflow) \\r
+  if (xcycles >= Pico.t.timer_b_next_oflow) \\r
     ym2612.OPN.ST.status |= (ym2612.OPN.ST.mode >> 2) & 2\r
 \r
 static u32 ym2612_read_local_z80(void)\r
@@ -1076,8 +1076,9 @@ static u32 ym2612_read_local_z80(void)
 \r
   ym2612_read_local();\r
 \r
-  elprintf(EL_YMTIMER, "timer z80 read %i, sched %i, %i @ %i|%i", ym2612.OPN.ST.status,\r
-      timer_a_next_oflow>>8, timer_b_next_oflow>>8, xcycles >> 8, (xcycles >> 8) / 228);\r
+  elprintf(EL_YMTIMER, "timer z80 read %i, sched %i, %i @ %i|%i",\r
+    ym2612.OPN.ST.status, Pico.t.timer_a_next_oflow >> 8,\r
+    Pico.t.timer_b_next_oflow >> 8, xcycles >> 8, (xcycles >> 8) / 228);\r
   return ym2612.OPN.ST.status;\r
 }\r
 \r
@@ -1087,8 +1088,9 @@ static u32 ym2612_read_local_68k(void)
 \r
   ym2612_read_local();\r
 \r
-  elprintf(EL_YMTIMER, "timer 68k read %i, sched %i, %i @ %i|%i", ym2612.OPN.ST.status,\r
-      timer_a_next_oflow>>8, timer_b_next_oflow>>8, xcycles >> 8, (xcycles >> 8) / 228);\r
+  elprintf(EL_YMTIMER, "timer 68k read %i, sched %i, %i @ %i|%i",\r
+    ym2612.OPN.ST.status, Pico.t.timer_a_next_oflow >> 8,\r
+    Pico.t.timer_b_next_oflow >> 8, xcycles >> 8, (xcycles >> 8) / 228);\r
   return ym2612.OPN.ST.status;\r
 }\r
 \r
@@ -1098,10 +1100,12 @@ void ym2612_pack_state(void)
   int tac, tat = 0, tbc, tbt = 0;\r
   tac = 1024 - ym2612.OPN.ST.TA;\r
   tbc = 256  - ym2612.OPN.ST.TB;\r
-  if (timer_a_next_oflow != TIMER_NO_OFLOW)\r
-    tat = (int)((double)(timer_a_step - timer_a_next_oflow) / (double)timer_a_step * tac * 65536);\r
-  if (timer_b_next_oflow != TIMER_NO_OFLOW)\r
-    tbt = (int)((double)(timer_b_step - timer_b_next_oflow) / (double)timer_b_step * tbc * 65536);\r
+  if (Pico.t.timer_a_next_oflow != TIMER_NO_OFLOW)\r
+    tat = (int)((double)(Pico.t.timer_a_step - Pico.t.timer_a_next_oflow)\r
+          / (double)Pico.t.timer_a_step * tac * 65536);\r
+  if (Pico.t.timer_b_next_oflow != TIMER_NO_OFLOW)\r
+    tbt = (int)((double)(Pico.t.timer_b_step - Pico.t.timer_b_next_oflow)\r
+          / (double)Pico.t.timer_b_step * tbc * 65536);\r
   elprintf(EL_YMTIMER, "save: timer a %i/%i", tat >> 16, tac);\r
   elprintf(EL_YMTIMER, "save: timer b %i/%i", tbt >> 16, tbc);\r
 \r
@@ -1154,15 +1158,15 @@ void ym2612_unpack_state(void)
   tac = (1024 - ym2612.OPN.ST.TA) << 16;\r
   tbc = (256  - ym2612.OPN.ST.TB) << 16;\r
   if (ym2612.OPN.ST.mode & 1)\r
-    timer_a_next_oflow = (int)((double)(tac - tat) / (double)tac * timer_a_step);\r
+    Pico.t.timer_a_next_oflow = (int)((double)(tac - tat) / (double)tac * Pico.t.timer_a_step);\r
   else\r
-    timer_a_next_oflow = TIMER_NO_OFLOW;\r
+    Pico.t.timer_a_next_oflow = TIMER_NO_OFLOW;\r
   if (ym2612.OPN.ST.mode & 2)\r
-    timer_b_next_oflow = (int)((double)(tbc - tbt) / (double)tbc * timer_b_step);\r
+    Pico.t.timer_b_next_oflow = (int)((double)(tbc - tbt) / (double)tbc * Pico.t.timer_b_step);\r
   else\r
-    timer_b_next_oflow = TIMER_NO_OFLOW;\r
-  elprintf(EL_YMTIMER, "load: %i/%i, timer_a_next_oflow %i", tat>>16, tac>>16, timer_a_next_oflow >> 8);\r
-  elprintf(EL_YMTIMER, "load: %i/%i, timer_b_next_oflow %i", tbt>>16, tbc>>16, timer_b_next_oflow >> 8);\r
+    Pico.t.timer_b_next_oflow = TIMER_NO_OFLOW;\r
+  elprintf(EL_YMTIMER, "load: %i/%i, timer_a_next_oflow %i", tat>>16, tac>>16, Pico.t.timer_a_next_oflow >> 8);\r
+  elprintf(EL_YMTIMER, "load: %i/%i, timer_b_next_oflow %i", tbt>>16, tbc>>16, Pico.t.timer_b_next_oflow >> 8);\r
 }\r
 \r
 #if defined(NO_32X) && defined(_ASM_MEMORY_C)\r