X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fwin32%2FGenaDrive%2FLoop.cpp;h=ce89616eeadc9e93bef6f2a7a09d48d28efa3519;hb=2cb51c3c621ed60e192e8342fdeb4225def91bd8;hp=54d35197a997c75bd286954eba36f223e6896629;hpb=cc68a136aa179a5f32fe40208371eb9c2b0aadae;p=picodrive.git diff --git a/platform/win32/GenaDrive/Loop.cpp b/platform/win32/GenaDrive/Loop.cpp index 54d3519..ce89616 100644 --- a/platform/win32/GenaDrive/Loop.cpp +++ b/platform/win32/GenaDrive/Loop.cpp @@ -1,27 +1,10 @@ #include "app.h" -#include "FileMenu.h" +//#include "FileMenu.h" -// sram -struct PicoSRAM -{ - unsigned char *data; // actual data - unsigned int start; // start address in 68k address space - unsigned int end; - unsigned char resize; // 1=SRAM size changed and needs to be reallocated on PicoReset - unsigned char reg_back; // copy of Pico.m.sram_reg to set after reset - unsigned char changed; - unsigned char pad; -}; - -extern "C" PicoSRAM SRam; -extern char *romname; -int fastForward=0; -int frameStep=0; - -char LoopQuit=0; +char LoopQuit=0,LoopWait=0,LoopWaiting=0; static FILE *DebugFile=NULL; int LoopMode=0; -static void UpdateSound(); +static void UpdateSound(int len); int LoopInit() { @@ -30,61 +13,32 @@ int LoopInit() // bits LSb->MSb: // enable_ym2612&dac, enable_sn76496, enable_z80, stereo_sound; // alt_renderer, 6button_gamepad, accurate_timing, accurate_sprites - PicoOpt=0x1f; + PicoOpt=0xbccf; PsndRate=44100; - //PsndLen=PsndRate/60; // calculated later by pico itself // Init Direct3D: - ret=DirectInit(); if (ret) return 1; + ret=DirectInit(); if (ret) { error("DirectX video init failed"); return 1; } InputInit(); // Init DirectSound: //DSoundInit(); ret=EmuInit(); if (ret) return 1; - FileMenu.init(); LoopMode=8; PicoWriteSound = UpdateSound; + PicoAutoRgnOrder = 0x184; return 0; } -void preLoopInit() -{ - romname[strlen(romname)-3] = 0; - strcat(romname, "srm"); - int sram_size = SRam.end-SRam.start+1; - if(SRam.reg_back & 4) sram_size=0x2000; - FILE *f = fopen(romname, "rb"); - if(f && SRam.data) - fread(SRam.data, 1, sram_size, f); - if(f) fclose(f); -} - extern "C" char *debugString(); void LoopExit() { dprintf(debugString()); - romname[strlen(romname)-3] = 0; - strcat(romname, "srm"); - int sram_size = SRam.end-SRam.start+1; - if(SRam.reg_back & 4) sram_size=0x2000; - for(; sram_size > 0; sram_size--) - if(SRam.data[sram_size-1]) break; - if(sram_size) { - FILE *f = fopen(romname, "wb"); - if(f) { - fwrite(SRam.data, 1, sram_size, f); - fclose(f); - } - } - - FileMenu.exit(); EmuExit(); - DSoundExit(); PsndLen=0; InputExit(); DirectExit(); @@ -94,96 +48,28 @@ void LoopExit() // ---------------------------------------------------------------- -int emu_frame = 0; - -static int DoGame() +static void UpdateSound(int len) { - if(fastForward) { PicoSkipFrame+=1; PicoSkipFrame&=7; } - else PicoSkipFrame=0; - - if(frameStep==1) return 0; - else if(frameStep==3) frameStep=1; - - EmuFrame(); - emu_frame++; - - if (Inp.held[7]==1) LoopMode=2; // Right thumb = Toggle Menu - - return 0; + while (DSoundUpdate() > 0) { Sleep(1); } + //while (DSoundUpdate()== 0) { } } -// ---------------------------------------------------------------- -static int MenuUpdate() +static void PostProcess() { - int delta=0; - - if (Inp.repeat[0]) delta-=0x100; - if (Inp.repeat[1]) delta+=0x100; - - if (Inp.button[14]>30) delta-=Inp.button[14]-30; - if (Inp.button[15]>30) delta+=Inp.button[15]-30; - - if (delta) FileMenu.scroll(delta); - - if (Inp.held[8]==1 || Inp.held[10]==1 || Inp.held[4]==1) // A, X or Start + static int lock_to_1_1_prev = 0, is_40_prev = 0; + int is_40 = PicoGetStat(PS_40_CELL); + if (lock_to_1_1) { - //RomFree(); - //FileMenu.getFilePath(RomName); - //RomLoad(); - //LoopMode=8; // Go to game + if (is_40 != is_40_prev || !lock_to_1_1_prev) + PostMessage(FrameWnd, WM_COMMAND, 0x20000 | (is_40 ? 1100 : 1101), 0); } - - if (Inp.held[7]==1) LoopMode=8; // Right thumb = Toggle Menu - - return 0; -} - -static int MenuRender() -{ - WCHAR text[80]={0}; - wsprintfW(text,L"%.40S v%x.%.3x",AppName,PicoVer>>12,PicoVer&0xfff); - FontSetColour(0x60c0ff); - FontText(text,64,48); - - FileMenu.render(); - - return 0; -} - -// ---------------------------------------------------------------- - -static int ModeUpdate() -{ - if (Inp.held[14] && Inp.held[15] && Inp.held[12]==1) LoopQuit=1; // L+R+black to quit: - if (Inp.button[4]>30 && Inp.button[5]>30) LoopQuit=1; // Start and back to quit - - if (LoopMode==8) { DoGame(); return 0; } - - if (DSoundNext) memset(DSoundNext,0,PsndLen<<2); - - if (LoopMode==2) { FileMenu.scan(); LoopMode++; return 0; } - if (LoopMode==3) { MenuUpdate(); return 0; } - if (LoopMode==4) { LightCalUpdate(); return 0; } - - LoopMode=2; // Unknown mode, go to rom menu - return 0; -} - - -static int ModeRender() -{ - DirectScreen(); - if (LoopMode==3) MenuRender(); - if (LoopMode==4) LightCalRender(); - - return 0; -} - -static void UpdateSound() -{ - if(fastForward) return; - while (DSoundUpdate()) { Sleep(1); } - while (DSoundUpdate()==0) { } + if (is_40 != is_40_prev) + { + EmuScreenRect.left = is_40 ? 0 : 32; + EmuScreenRect.right = is_40 ? 320 : 256+32; + } + lock_to_1_1_prev = lock_to_1_1; + is_40_prev = is_40; } int LoopCode() @@ -192,20 +78,30 @@ int LoopCode() // Main loop: while (!LoopQuit) { + if (LoopWait) + { + DSoundExit(); + while (!LoopQuit && LoopWait) { LoopWaiting=1; Sleep(100); } + if (LoopQuit) break; + DSoundInit(); + } InputUpdate(); DirectClear(0); - ModeUpdate(); - ModeRender(); + EmuFrame(); + PostProcess(); + DirectScreen(); DirectPresent(); // UpdateSound(); } + DSoundExit(); return 0; } // ------------------------------------------------------------------------------------- +#if 0 extern "C" int dprintf(char *format, ...) { char *name=NULL; @@ -229,8 +125,9 @@ extern "C" int dprintf(char *format, ...) va_end(val); return 0; } +#endif -extern "C" int dprintf2(char *format, ...) +extern "C" int lprintf(char *format, ...) { char str[512]; va_list val=NULL; @@ -242,3 +139,4 @@ extern "C" int dprintf2(char *format, ...) return 0; } +