diff --git a/unix/menu.cpp b/unix/menu.cpp index a075470..757ad95 100644 --- a/unix/menu.cpp +++ b/unix/menu.cpp @@ -13,9 +13,9 @@ #include "gfx.h" #ifdef PANDORA -#include "blitscale.h" -extern blit_scaler_option_t blit_scalers[]; -extern blit_scaler_e g_scale; + #include "blitscale.h" + extern blit_scaler_option_t blit_scalers[]; + extern blit_scaler_e g_scale; #endif extern Uint16 sfc_key[256]; @@ -41,164 +41,6 @@ bool8_32 highres_current = false; char snapscreen[17120]={}; extern clock_t start; -// -------------------------------------------------------------------------------------- -// Dingoo Stuff -// -------------------------------------------------------------------------------------- -/* -// Define this to the CPU frequency -unsigned CLK_FREQ = 336; //400 // CPU clock: 336 MHz - -#define CFG_EXTAL 12000000 // EXT clock: 12 Mhz - -// SDRAM Timings, unit: ns -#define SDRAM_TRAS 45 // RAS# Active Time -#define SDRAM_RCD 20 // RAS# to CAS# Delay -#define SDRAM_TPC 20 // RAS# Precharge Time -#define SDRAM_TRWL 7 // Write Latency Time -#define SDRAM_TREF 15625 // Refresh period: 4096 refresh cycles/64ms -//#define SDRAM_TREF 7812 // Refresh period: 8192 refresh cycles/64ms - -// Clock Control Register -#define CPM_CPCCR_I2CS (1 << 31) -#define CPM_CPCCR_CLKOEN (1 << 30) -#define CPM_CPCCR_UCS (1 << 29) -#define CPM_CPCCR_UDIV_BIT 23 -#define CPM_CPCCR_UDIV_MASK (0x3f << CPM_CPCCR_UDIV_BIT) -#define CPM_CPCCR_CE (1 << 22) -#define CPM_CPCCR_PCS (1 << 21) -#define CPM_CPCCR_LDIV_BIT 16 -#define CPM_CPCCR_LDIV_MASK (0x1f << CPM_CPCCR_LDIV_BIT) -#define CPM_CPCCR_MDIV_BIT 12 -#define CPM_CPCCR_MDIV_MASK (0x0f << CPM_CPCCR_MDIV_BIT) -#define CPM_CPCCR_PDIV_BIT 8 -#define CPM_CPCCR_PDIV_MASK (0x0f << CPM_CPCCR_PDIV_BIT) -#define CPM_CPCCR_HDIV_BIT 4 -#define CPM_CPCCR_HDIV_MASK (0x0f << CPM_CPCCR_HDIV_BIT) -#define CPM_CPCCR_CDIV_BIT 0 -#define CPM_CPCCR_CDIV_MASK (0x0f << CPM_CPCCR_CDIV_BIT) - -// I2S Clock Divider Register -#define CPM_I2SCDR_I2SDIV_BIT 0 -#define CPM_I2SCDR_I2SDIV_MASK (0x1ff << CPM_I2SCDR_I2SDIV_BIT) - -// PLL Control Register -#define CPM_CPPCR_PLLM_BIT 23 -#define CPM_CPPCR_PLLM_MASK (0x1ff << CPM_CPPCR_PLLM_BIT) -#define CPM_CPPCR_PLLN_BIT 18 -#define CPM_CPPCR_PLLN_MASK (0x1f << CPM_CPPCR_PLLN_BIT) -#define CPM_CPPCR_PLLOD_BIT 16 -#define CPM_CPPCR_PLLOD_MASK (0x03 << CPM_CPPCR_PLLOD_BIT) -#define CPM_CPPCR_PLLS (1 << 10) -#define CPM_CPPCR_PLLBP (1 << 9) -#define CPM_CPPCR_PLLEN (1 << 8) -#define CPM_CPPCR_PLLST_BIT 0 -#define CPM_CPPCR_PLLST_MASK (0xff << CPM_CPPCR_PLLST_BIT) - -static unsigned long jz_dev=0; -static volatile unsigned long *jz_cpmregl; -static volatile unsigned short *jz_emcregs; - -static int sdram_convert(unsigned int pllin,unsigned int *sdram_freq) -{ - register unsigned int ns, tmp; - - ns = 1000000000 / pllin; - // Set refresh registers - tmp = SDRAM_TREF/ns; - tmp = tmp/64 + 1; - if (tmp > 0xff) tmp = 0xff; - *sdram_freq = tmp; - - return 0; -} - -static void pll_init(unsigned int clock) -{ - register unsigned int cfcr, plcr1; - unsigned int sdramclock = 0; - int n2FR[33] = { - 0, 0, 1, 2, 3, 0, 4, 0, 5, 0, 0, 0, 6, 0, 0, 0, - 7, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, - 9 - }; - int div[5] = {1, 3, 3, 3, 3}; // divisors of I:S:P:L:M - int nf, pllout2; - - cfcr = CPM_CPCCR_CLKOEN | - (n2FR[div[0]] << CPM_CPCCR_CDIV_BIT) | - (n2FR[div[1]] << CPM_CPCCR_HDIV_BIT) | - (n2FR[div[2]] << CPM_CPCCR_PDIV_BIT) | - (n2FR[div[3]] << CPM_CPCCR_MDIV_BIT) | - (n2FR[div[4]] << CPM_CPCCR_LDIV_BIT); - - pllout2 = (cfcr & CPM_CPCCR_PCS) ? clock : (clock / 2); - - // Init UHC clock - jz_cpmregl[0x6C>>2] = pllout2 / 48000000 - 1; - - nf = clock * 2 / CFG_EXTAL; - plcr1 = ((nf - 2) << CPM_CPPCR_PLLM_BIT) | // FD - (0 << CPM_CPPCR_PLLN_BIT) | // RD=0, NR=2 - (0 << CPM_CPPCR_PLLOD_BIT) | // OD=0, NO=1/ - (0x20 << CPM_CPPCR_PLLST_BIT) | // PLL stable time - CPM_CPPCR_PLLEN; // enable PLL - - // init PLL - jz_cpmregl[0] = cfcr; - jz_cpmregl[0x10>>2] = plcr1; - - sdram_convert(clock,&sdramclock); - if(sdramclock > 0) - { - jz_emcregs[0x8C>>1] = sdramclock; - jz_emcregs[0x88>>1] = sdramclock; - } - else - { - printf("sdram init fail!\n"); - while(1); - } -} - -void dingoo_set_clock(unsigned int mhz) -{ - if(!jz_dev) jz_dev = open("/dev/mem", O_RDWR); - - volatile unsigned long *jz_emcregl; - - jz_cpmregl=(unsigned long *)mmap(0, 0x80, PROT_READ|PROT_WRITE, MAP_SHARED, jz_dev, 0x10000000); - jz_emcregl=(unsigned long *)mmap(0, 0x90, PROT_READ|PROT_WRITE, MAP_SHARED, jz_dev, 0x13010000); - jz_emcregs=(unsigned short *)jz_emcregl; - - if (mhz > 430) mhz = 430; - if (mhz < 200) mhz = 200; - - pll_init(mhz*1000000); - - munmap((void *)jz_cpmregl, 0x80); - munmap((void *)jz_emcregl, 0x90); - close(jz_dev); -} - -unsigned int dingoo_get_clock(void) -{ - if(!jz_dev) jz_dev = open("/dev/mem", O_RDWR); - - volatile unsigned long *jz=(unsigned long *)mmap(0, 0x80, PROT_READ|PROT_WRITE, MAP_SHARED, jz_dev, 0x10000000); - - unsigned int plcr1=jz[0x10>>2]; - int nf=2+(plcr1 >> CPM_CPPCR_PLLM_BIT); - munmap((void *)jz, 0x80); - close(jz_dev); - - return 2+(nf*6); -} -*/ -// -------------------------------------------------------------------------------------- -// Dingoo Stuff END -// -------------------------------------------------------------------------------------- - - void menu_dispupdate(void){ char temp[256]; char disptxt[20][256]; @@ -210,7 +52,7 @@ void menu_dispupdate(void){ } } - strcpy(disptxt[0],"Snes9x4D (for DINGUX) v20100429"); + strcpy(disptxt[0],"Snes9x4X v20100429"); strcpy(disptxt[1],""); //strcpy(disptxt[2],"Resume Game "); strcpy(disptxt[2],"Reset Game "); @@ -223,7 +65,7 @@ void menu_dispupdate(void){ #else strcpy(disptxt[7],"Full Screen "); #endif - strcpy(disptxt[8],"Frameskip "); // strcpy(disptxt[8],"Clock Speed "); + strcpy(disptxt[8],"Frameskip "); strcpy(disptxt[9],"Sound Volume "); strcpy(disptxt[10],"Credit "); strcpy(disptxt[11],"Exit"); @@ -310,7 +152,6 @@ void menu_dispupdate(void){ S9xDisplayString (disptxt[i], GFX.Screen, 640,i*10+64); } - //show screen shot for snapshot if(SaveSlotNum_old != SaveSlotNum){ strcpy(temp,"Loading..."); @@ -327,8 +168,14 @@ void menu_dispupdate(void){ S9xDeinitUpdate (320, 240); } -void menu_loop(void){ - uint8 *keyssnes=0; +void menu_loop(void) +{ +#ifdef CAANOO + SDL_Joystick* keyssnes = 0; +#else + uint8 *keyssnes = 0; +#endif + bool8_32 exit_loop = false; char fname[256], ext[8]; char snapscreen_tmp[17120]; @@ -354,117 +201,126 @@ void menu_loop(void){ SDL_Event event; - do { + do + { menu_dispupdate(); usleep(100); + +#ifdef CAANOO + keyssnes = SDL_JoystickOpen(0); +#else keyssnes = SDL_GetKeyState(NULL); - while(SDL_PollEvent(&event)==1) { - switch(event.type) { - case SDL_KEYDOWN: - keyssnes = SDL_GetKeyState(NULL); +#endif + + while(SDL_PollEvent(&event)==1) + { + switch(event.type) + { +#ifdef CAANOO + // CAANOO ------------------------------------------------------------- + case SDL_JOYBUTTONDOWN: + keyssnes = SDL_JoystickOpen(0); +#else + //PANDORA & DINGOO ------------------------------------------------------ + case SDL_KEYDOWN: + keyssnes = SDL_GetKeyState(NULL); if(keyssnes[sfc_key[UP_1]] == SDL_PRESSED) cursor--; else if(keyssnes[sfc_key[DOWN_1]] == SDL_PRESSED) cursor++; else if((keyssnes[sfc_key[A_1]] == SDL_PRESSED)|| (keyssnes[sfc_key[RIGHT_1]] == SDL_PRESSED)|| - (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED)){ - switch(cursor){ - case 2: - if ((keyssnes[sfc_key[A_1]] == SDL_PRESSED)){ - S9xReset(); - exit_loop = TRUE; - } - break; - case 3: - if (keyssnes[sfc_key[A_1]] == SDL_PRESSED){ - memcpy(snapscreen,snapscreen_tmp,16050); - show_screenshot(); - strcpy(fname," Saving..."); - S9xDisplayString (fname, GFX.Screen +280, 640,204); - S9xDeinitUpdate (320, 240); - sprintf(ext, ".s0%d", SaveSlotNum); - strcpy(fname, S9xGetFilename (ext)); - save_screenshot(fname); - sprintf(ext, ".00%d", SaveSlotNum); - strcpy(fname, S9xGetFilename (ext)); - S9xFreezeGame (fname); - sync(); - exit_loop = TRUE; - } - break; - case 4: - if (keyssnes[sfc_key[A_1]] == SDL_PRESSED){ - sprintf(ext, ".00%d", SaveSlotNum); - strcpy(fname, S9xGetFilename (ext)); - S9xLoadSnapshot (fname); - exit_loop = TRUE; - } - break; - case 5: - if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED) - SaveSlotNum--; - else SaveSlotNum++; - if(SaveSlotNum>3) - SaveSlotNum =0; - else if(SaveSlotNum<0) - SaveSlotNum=3; - break; - case 6: - Settings.DisplayFrameRate = !Settings.DisplayFrameRate; - break; - case 7: + (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED)) + { + switch(cursor) + { + case 2: + if ((keyssnes[sfc_key[A_1]] == SDL_PRESSED)){ + S9xReset(); + exit_loop = TRUE; + } + break; + case 3: + if (keyssnes[sfc_key[A_1]] == SDL_PRESSED){ + memcpy(snapscreen,snapscreen_tmp,16050); + show_screenshot(); + strcpy(fname," Saving..."); + S9xDisplayString (fname, GFX.Screen +280, 640,204); + S9xDeinitUpdate (320, 240); + sprintf(ext, ".s0%d", SaveSlotNum); + strcpy(fname, S9xGetFilename (ext)); + save_screenshot(fname); + sprintf(ext, ".00%d", SaveSlotNum); + strcpy(fname, S9xGetFilename (ext)); + S9xFreezeGame (fname); + sync(); + exit_loop = TRUE; + } + break; + case 4: + if (keyssnes[sfc_key[A_1]] == SDL_PRESSED){ + sprintf(ext, ".00%d", SaveSlotNum); + strcpy(fname, S9xGetFilename (ext)); + S9xLoadSnapshot (fname); + exit_loop = TRUE; + } + break; + case 5: + if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED) + SaveSlotNum--; + else SaveSlotNum++; + if(SaveSlotNum>3) + SaveSlotNum =0; + else if(SaveSlotNum<0) + SaveSlotNum=3; + break; + case 6: + Settings.DisplayFrameRate = !Settings.DisplayFrameRate; + break; + case 7: #ifdef PANDORA - // rotate through scalers - do { - g_scale = (blit_scaler_e) ( ( g_scale + 1 ) % bs_max ); - } while ( blit_scalers [ g_scale ].valid == bs_invalid ); + // rotate through scalers + do { + g_scale = (blit_scaler_e) ( ( g_scale + 1 ) % bs_max ); + } while ( blit_scalers [ g_scale ].valid == bs_invalid ); #else - Scale_org = !Scale_org; + Scale_org = !Scale_org; #endif - break; - case 8: -/* - if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED) - CLK_FREQ -=8; - else CLK_FREQ +=8; - if(CLK_FREQ>=432) - CLK_FREQ=432; - else if (CLK_FREQ<=200) - CLK_FREQ=200; -*/ - if (Settings.SkipFrames == AUTO_FRAMERATE) - Settings.SkipFrames = 10; - - if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED) - Settings.SkipFrames--; - else - Settings.SkipFrames++; - - if(Settings.SkipFrames>=10) - Settings.SkipFrames = AUTO_FRAMERATE; - else if (Settings.SkipFrames <=1) - Settings.SkipFrames = 1; - break; - case 9: - if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED) - vol -= 10; - else vol += 10; - if(vol>=100) - vol = 100; - else if (vol <=0) - vol = 0; - break; - case 10: - if (keyssnes[sfc_key[A_1]] == SDL_PRESSED) - ShowCredit(); - break; - case 11: - if (keyssnes[sfc_key[A_1]] == SDL_PRESSED) - S9xExit(); - break; + break; + case 8: + if (Settings.SkipFrames == AUTO_FRAMERATE) + Settings.SkipFrames = 10; + + if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED) + Settings.SkipFrames--; + else + Settings.SkipFrames++; + + if(Settings.SkipFrames>=10) + Settings.SkipFrames = AUTO_FRAMERATE; + else if (Settings.SkipFrames <=1) + Settings.SkipFrames = 1; + break; + case 9: + if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED) + vol -= 10; + else vol += 10; + if(vol>=100) + vol = 100; + else if (vol <=0) + vol = 0; + break; + case 10: + if (keyssnes[sfc_key[A_1]] == SDL_PRESSED) + ShowCredit(); + break; + case 11: + if (keyssnes[sfc_key[A_1]] == SDL_PRESSED) + S9xExit(); + break; } } +#endif if(cursor==1) cursor=11; @@ -473,7 +329,13 @@ void menu_loop(void){ break; } } - } while(exit_loop!=TRUE && keyssnes[sfc_key[B_1]] != SDL_PRESSED); + + } +#ifdef CAANOO + while( exit_loop!=TRUE && SDL_JoystickGetButton(keyssnes, sfc_key[QUIT])!=TRUE ); +#else + while( exit_loop!=TRUE && keyssnes[sfc_key[B_1]] != SDL_PRESSED ); +#endif Scale = Scale_org; Settings.SupportHiRes=highres_current; diff --git a/unix/svga.cpp b/unix/svga.cpp index 9e18739..28c50fb 100644 --- a/unix/svga.cpp +++ b/unix/svga.cpp @@ -94,13 +94,6 @@ void S9xTextMode () #endif -#ifdef CAANOO - extern SDL_Joystick* keyssnes; -#else - extern uint8 *keyssnes; -#endif - - void S9xInitDisplay (int /*argc*/, char ** /*argv*/) { #ifdef CAANOO @@ -117,12 +110,6 @@ void S9xInitDisplay (int /*argc*/, char ** /*argv*/) // No more MOUSE-CURSOR SDL_ShowCursor(SDL_DISABLE); -#ifdef CAANOO - keyssnes = SDL_JoystickOpen(0); -#else - keyssnes = SDL_GetKeyState(NULL); -#endif - #ifdef PANDORA //screen = SDL_SetVideoMode(xs * blit_scalers [ g_scale ].scale_x, ys * blit_scalers [ g_scale ].scale_y, 16, // g_fullscreen ? SDL_SWSURFACE|SDL_FULLSCREEN : SDL_SWSURFACE); @@ -153,9 +140,8 @@ void S9xInitDisplay (int /*argc*/, char ** /*argv*/) break; } -#else - //DINGOO / CAANOO - screen = SDL_SetVideoMode(xs, ys, 16, SDL_SWSURFACE); //SDL_HWSURFACE +#else //DINGOO //CAANOO + screen = SDL_SetVideoMode(xs, ys, 16, SDL_SWSURFACE); //do no take SDL_HWSURFACE on Dingoo (bad overlays) and CAANOO (flickers) #endif if (screen == NULL) diff --git a/unix/unix.cpp b/unix/unix.cpp index df1401a..285fb89 100644 --- a/unix/unix.cpp +++ b/unix/unix.cpp @@ -137,7 +137,6 @@ char msg[256]; int vol=50; static int mixerdev = 0; clock_t start; -//extern bool8_32 Scale_disp; int OldSkipFrame; void InitTimer (); @@ -146,7 +145,6 @@ void gp2x_sound_volume(int l, int r); extern void S9xDisplayFrameRate (uint8 *, uint32); extern void S9xDisplayString (const char *string, uint8 *, uint32, int); -//extern SDL_Surface *screen; extern SDL_Surface *screen,*gfxscreen; static uint32 ffc = 0; @@ -306,16 +304,6 @@ int main (int argc, char **argv) S9xSetRenderPixelFormat (RGB565); #endif -// S9xInitInputDevices (); -// S9xInitDisplay (argc, argv); -// if (!S9xGraphicsInit ()) -// { -// OutOfMemory (); -// } -//#ifndef _ZAURUS -// S9xTextMode (); -//#endif - if (rom_filename) { if (!Memory.LoadROM (rom_filename)) @@ -332,21 +320,22 @@ int main (int argc, char **argv) strcpy (fname, S9xGetROMDirectory ()); strcat (fname, SLASH_STR); strcat (fname, name); + if (ext [0]) { - strcat (fname, "."); - strcat (fname, ext); + strcat (fname, "."); + strcat (fname, ext); } _splitpath (fname, drive, dir, name, ext); _makepath (fname, drive, dir, name, ext); + if (!Memory.LoadROM (fname)) { - printf ("Error opening: %s\n", rom_filename); - exit (1); + printf ("Error opening: %s\n", rom_filename); + exit (1); } } Memory.LoadSRAM (S9xGetFilename (".srm")); -// S9xLoadCheatFile (S9xGetFilename (".cht")); } else { @@ -356,8 +345,14 @@ int main (int argc, char **argv) S9xInitDisplay (argc, argv); if (!S9xGraphicsInit ()) + { OutOfMemory (); + } S9xInitInputDevices (); + + // TODO: + //if (!rom_filename) open rom selector!!!!!!!!!!!!!! + // CPU.Flags = saved_flags; @@ -373,7 +368,9 @@ int main (int argc, char **argv) sigemptyset(&sa.sa_mask); sigaction(SIGINT, &sa, NULL); -#ifdef PANDORA +#ifdef CAANOO + sprintf(msg,"Press HOME to Show MENU"); +#elif PANDORA sprintf(msg,"Press SPACEBAR to Show MENU"); #else sprintf(msg,"Press SELECT+B to Show MENU"); @@ -382,11 +379,12 @@ int main (int argc, char **argv) if (snapshot_filename) { - int Flags = CPU.Flags & (DEBUG_MODE_FLAG | TRACE_FLAG); - if (!S9xLoadSnapshot (snapshot_filename)) - exit (1); - CPU.Flags |= Flags; + int Flags = CPU.Flags & (DEBUG_MODE_FLAG | TRACE_FLAG); + if (!S9xLoadSnapshot (snapshot_filename)) + exit (1); + CPU.Flags |= Flags; } + #ifndef _ZAURUS S9xGraphicsMode (); sprintf (String, "\"%s\" %s: %s", Memory.ROMName, TITLE, VERSION); @@ -453,7 +451,7 @@ void S9xExit () S9xSetSoundMute (TRUE); S9xDeinitDisplay (); Memory.SaveSRAM (S9xGetFilename (".srm")); -// S9xSaveCheatFile (S9xGetFilename (".cht")); //SiENcE - needed for what? +// S9xSaveCheatFile (S9xGetFilename (".cht")); // not needed for embedded devices Memory.Deinit (); S9xDeinitAPU (); @@ -463,6 +461,12 @@ void S9xExit () Uint16 sfc_key[256]; void S9xInitInputDevices () { +#ifdef CAANOO + keyssnes = SDL_JoystickOpen(0); +#else + keyssnes = SDL_GetKeyState(NULL); +#endif + memset(sfc_key, 0, 256); #ifdef CAANOO @@ -1147,29 +1151,30 @@ void S9xProcessEvents (bool8_32 block) { switch(event.type) { - // CAANOO ------------------------------------------------------------- #ifdef CAANOO - keyssnes = SDL_JoystickOpen(0); + // CAANOO ------------------------------------------------------------- case SDL_JOYBUTTONDOWN: - //QUIT Emulator - if ( SDL_JoystickGetButton(keyssnes, sfc_key[QUIT]) && SDL_JoystickGetButton(keyssnes, sfc_key[X_1] ) ) - { - S9xExit(); - } - // MAINMENU - else if ( SDL_JoystickGetButton(keyssnes, sfc_key[QUIT]) ) - { - gp2x_sound_volume(0, 0); - menu_loop(); - gp2x_sound_volume(vol, vol); - } - break; + keyssnes = SDL_JoystickOpen(0); + //QUIT Emulator + if ( SDL_JoystickGetButton(keyssnes, sfc_key[QUIT]) && SDL_JoystickGetButton(keyssnes, sfc_key[B_1] ) ) + { + S9xExit(); + } + // MAINMENU + else if ( SDL_JoystickGetButton(keyssnes, sfc_key[QUIT]) ) + { + gp2x_sound_volume(0, 0); + menu_loop(); + gp2x_sound_volume(vol, vol); + } + break; case SDL_JOYBUTTONUP: + keyssnes = SDL_JoystickOpen(0); switch(event.jbutton.button) { } - break; + break; #else //PANDORA & DINGOO ------------------------------------------------------ case SDL_KEYDOWN: