work on 'vblank on line start' problem, var changes, mask defines
[picodrive.git] / platform / gizmondo / emu.c
index 440a8de..ebc15a2 100644 (file)
@@ -31,7 +31,6 @@ int engineState;
 unsigned char *PicoDraw2FB = gfx_buffer;  // temporary buffer for alt renderer ( (8+320)*(8+240+8) )
 int reset_timing = 0;
 
-static int combo_keys = 0, combo_acts = 0; // keys and actions which need button combos
 static DWORD noticeMsgTime = 0;
 static short *snd_cbuff = NULL;
 static int snd_cbuf_samples = 0, snd_all_samples = 0;
@@ -104,24 +103,13 @@ void emu_Init(void)
 void emu_Deinit(void)
 {
        // save SRAM
-       if((currentConfig.EmuOpt & 1) && SRam.changed) {
+       if ((currentConfig.EmuOpt & 1) && SRam.changed) {
                emu_SaveLoadGame(0, 1);
                SRam.changed = 0;
        }
 
-       if (!(currentConfig.EmuOpt & 0x20)) {
-               FILE *f = fopen(PicoConfigFile, "r+b");
-               if (!f) emu_WriteConfig(0);
-               else {
-                       // if we already have config, reload it, except last ROM
-                       fseek(f, sizeof(currentConfig.lastRomFile), SEEK_SET);
-                       fread(&currentConfig.EmuOpt, 1, sizeof(currentConfig) - sizeof(currentConfig.lastRomFile), f);
-                       fseek(f, 0, SEEK_SET);
-                       fwrite(&currentConfig, 1, sizeof(currentConfig), f);
-                       fflush(f);
-                       fclose(f);
-               }
-       }
+       if (!(currentConfig.EmuOpt & 0x20))
+               config_writelrom(PicoConfigFile);
 
        PicoExit();
 }
@@ -155,10 +143,10 @@ void emu_setDefaultConfig(void)
 }
 
 
-static int EmuScan16(unsigned int num, void *sdata)
+static int EmuScanBegin16(unsigned int num)
 {
        if (!(Pico.video.reg[1]&8)) num += 8;
-       DrawLineDest = (unsigned short *) giz_screen + 321*(num+1);
+       DrawLineDest = (unsigned short *) giz_screen + 321 * num;
 
        if ((currentConfig.EmuOpt&0x4000) && (num&1) == 0) // (Pico.m.frame_count&1))
                return 1; // skip next line
@@ -166,11 +154,11 @@ static int EmuScan16(unsigned int num, void *sdata)
        return 0;
 }
 
-static int EmuScan8(unsigned int num, void *sdata)
+static int EmuScanBegin8(unsigned int num)
 {
        // draw like the fast renderer
        if (!(Pico.video.reg[1]&8)) num += 8;
-       HighCol = gfx_buffer + 328*(num+1);
+       HighCol = gfx_buffer + 328 * num;
 
        return 0;
 }
@@ -265,7 +253,7 @@ static void blit(const char *fps, const char *notice)
                if (emu_opt & 2) osd_text(OSD_FPS_X, h, fps);
        }
 
-       if ((emu_opt & 0x400) && (PicoMCD & 1))
+       if ((emu_opt & 0x400) && (PicoAHW & PAHW_MCD))
                cd_leds();
 }
 
@@ -292,10 +280,10 @@ static void vidResetMode(void)
        if (PicoOpt&0x10) {
        } else if (currentConfig.EmuOpt&0x80) {
                PicoDrawSetColorFormat(1);
-               PicoScan = EmuScan16;
+               PicoScanBegin = EmuScanBegin16;
        } else {
                PicoDrawSetColorFormat(-1);
-               PicoScan = EmuScan8;
+               PicoScanBegin = EmuScanBegin8;
        }
        if ((PicoOpt&0x10) || !(currentConfig.EmuOpt&0x80)) {
                // setup pal for 8-bit modes
@@ -368,8 +356,7 @@ void emu_forcedFrame(void)
                giz_screen = Framework2D_LockBuffer(1);
 
        PicoDrawSetColorFormat(1);
-       PicoScan = EmuScan16;
-       PicoScan((unsigned) -1, NULL);
+       PicoScanBegin = EmuScanBegin16;
        Pico.m.dirtyPal = 1;
        PicoFrameDrawOnly();
 
@@ -468,20 +455,21 @@ static void updateKeys(void)
                        int pl, acts = currentConfig.KeyBinds[i];
                        if (!acts) continue;
                        pl = (acts >> 16) & 1;
-                       if (combo_keys & (1 << i))
+                       if (kb_combo_keys & (1 << i))
                        {
-                               int u = i+1, acts_c = acts & combo_acts;
+                               int u = i+1, acts_c = acts & kb_combo_acts;
                                // let's try to find the other one
-                               if (acts_c)
+                               if (acts_c) {
                                        for (; u < 32; u++)
-                                               if ( (currentConfig.KeyBinds[u] & acts_c) && (keys & (1 << u)) ) {
-                                                       allActions[pl] |= acts_c;
+                                               if ( (keys & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) {
+                                                       allActions[pl] |= acts_c & currentConfig.KeyBinds[u];
                                                        keys &= ~((1 << i) | (1 << u));
                                                        break;
                                                }
+                               }
                                // add non-combo actions if combo ones were not found
                                if (!acts_c || u == 32)
-                                       allActions[pl] |= acts & ~combo_acts;
+                                       allActions[pl] |= acts & ~kb_combo_acts;
                        } else {
                                allActions[pl] |= acts;
                        }
@@ -515,34 +503,6 @@ static void updateKeys(void)
        prevEvents = (allActions[0] | allActions[1]) >> 16;
 }
 
-static void find_combos(void)
-{
-       int act, u;
-
-       // find out which keys and actions are combos
-       combo_keys = combo_acts = 0;
-       for (act = 0; act < 32; act++)
-       {
-               int keyc = 0;
-               if (act == 16 || act == 17) continue; // player2 flag
-               for (u = 0; u < 32; u++)
-               {
-                       if (currentConfig.KeyBinds[u] & (1 << act)) keyc++;
-               }
-               if (keyc > 1)
-               {
-                       // loop again and mark those keys and actions as combo
-                       for (u = 0; u < 32; u++)
-                       {
-                               if (currentConfig.KeyBinds[u] & (1 << act)) {
-                                       combo_keys |= 1 << u;
-                                       combo_acts |= 1 << act;
-                               }
-                       }
-               }
-       }
-}
-
 
 static void simpleWait(DWORD until)
 {
@@ -577,7 +537,7 @@ void emu_Loop(void)
        else PicoOpt&=~0x4000;
        Pico.m.dirtyPal = 1;
        oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc;
-       find_combos();
+       emu_findKeyBindCombos();
 
        // pal/ntsc might have changed, reset related stuff
        target_fps = Pico.m.pal ? 50 : 60;
@@ -585,7 +545,7 @@ void emu_Loop(void)
        reset_timing = 1;
 
        // prepare CD buffer
-       if (PicoMCD & 1) PicoCDBufferInit();
+       if (PicoAHW & PAHW_MCD) PicoCDBufferInit();
 
        // prepare sound stuff
        PsndOut = NULL;
@@ -593,7 +553,7 @@ void emu_Loop(void)
        {
                int ret, snd_excess_add, stereo;
                if (PsndRate != PsndRate_old || (PicoOpt&0x0b) != (PicoOpt_old&0x0b) || Pico.m.pal != pal_old) {
-                       sound_rerate(Pico.m.frame_count ? 1 : 0);
+                       PsndRerate(Pico.m.frame_count ? 1 : 0);
                }
                stereo=(PicoOpt&8)>>3;
                snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;
@@ -755,9 +715,6 @@ void emu_Loop(void)
                        /* be sure correct framebuffer is locked */
                        giz_screen = Framework2D_LockBuffer((currentConfig.EmuOpt&0x8000) ? 0 : 1);
 
-               if (!(PicoOpt&0x10))
-                       PicoScan((unsigned) -1, NULL);
-
                PicoFrame();
 
                if (giz_screen == NULL)
@@ -796,7 +753,7 @@ void emu_Loop(void)
        }
 
 
-       if (PicoMCD & 1) PicoCDBufferFree();
+       if (PicoAHW & PAHW_MCD) PicoCDBufferFree();
 
        if (PsndOut != NULL) {
                PsndOut = snd_cbuff = NULL;
@@ -814,7 +771,7 @@ void emu_Loop(void)
 
 void emu_ResetGame(void)
 {
-       PicoReset(0);
+       PicoReset();
        reset_timing = 1;
 }