From 21afaa365c97896da6ccbdd6540e20f2d2bb4990 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 27 May 2007 23:04:35 +0000 Subject: [PATCH] fceu options + support code git-svn-id: file:///home/notaz/opt/svn/fceu@140 be3aeb3a-fb24-0410-a615-afba39da0efa --- drivers/gp2x/asmutils.h | 3 +- drivers/gp2x/asmutils.s | 31 ++++++++++++++++- drivers/gp2x/gp2x-video.c | 72 +++++++++++++++++++++------------------ drivers/gp2x/input.c | 2 +- drivers/gp2x/main.c | 43 +++++++++++------------ drivers/gp2x/menu.c | 61 +++++++++++++++++++++++++-------- fce.c | 22 +++++------- nsf.c | 2 +- svga.c | 27 +-------------- 9 files changed, 149 insertions(+), 114 deletions(-) diff --git a/drivers/gp2x/asmutils.h b/drivers/gp2x/asmutils.h index 0ad81b1..7fce5ee 100644 --- a/drivers/gp2x/asmutils.h +++ b/drivers/gp2x/asmutils.h @@ -2,6 +2,7 @@ void flushcache(unsigned int beginning_addr, unsigned int end_addr, unsigned int void block_or(void *src, size_t n, int pat); void block_and(void *src, size_t n, int pat); void block_andor(void *src, size_t n, int andpat, int orpat); +void memset32(int *dest, int c, int count); void spend_cycles(int c); // utility -void soft_scale(void *dst, unsigned short *pal, int offs, int lines); +void soft_scale(void *dst, unsigned short *pal, int line_offs, int lines); diff --git a/drivers/gp2x/asmutils.s b/drivers/gp2x/asmutils.s index 62e0661..a91cfaf 100644 --- a/drivers/gp2x/asmutils.s +++ b/drivers/gp2x/asmutils.s @@ -86,7 +86,36 @@ spend_cycles: bx lr -.global soft_scale @ void *dst, unsigned short *pal, int offs, int lines +.global memset32 @ int *dest, int c, int count + +memset32: + stmfd sp!, {lr} + + mov r3, r1 + subs r2, r2, #4 + bmi mst32_fin + + mov r12,r1 + mov lr, r1 + +mst32_loop: + subs r2, r2, #4 + stmia r0!, {r1,r3,r12,lr} + bpl mst32_loop + +mst32_fin: + tst r2, #1 + strne r1, [r0], #4 + + tst r2, #2 + stmneia r0!, {r1,r3} + + ldmfd sp!, {lr} + bx lr + + + +.global soft_scale @ void *dst, unsigned short *pal, int line_offs, int lines soft_scale: stmfd sp!,{r4-r11,lr} diff --git a/drivers/gp2x/gp2x-video.c b/drivers/gp2x/gp2x-video.c index b1bf165..ef4a4dc 100644 --- a/drivers/gp2x/gp2x-video.c +++ b/drivers/gp2x/gp2x-video.c @@ -35,6 +35,8 @@ unsigned short gp2x_palette16[256]; int paletterefresh; +extern int eoptions; + #define FPS_COLOR 1 @@ -50,14 +52,14 @@ static void gp2x_text(unsigned char *screen, int x, int y, char *text, int color for (l=0;l<8;l++) { - screen[l*320+0]=(fontdata8x8[((text[i])*8)+l]&0x80)?color:screen[l*320+0]; - screen[l*320+1]=(fontdata8x8[((text[i])*8)+l]&0x40)?color:screen[l*320+1]; - screen[l*320+2]=(fontdata8x8[((text[i])*8)+l]&0x20)?color:screen[l*320+2]; - screen[l*320+3]=(fontdata8x8[((text[i])*8)+l]&0x10)?color:screen[l*320+3]; - screen[l*320+4]=(fontdata8x8[((text[i])*8)+l]&0x08)?color:screen[l*320+4]; - screen[l*320+5]=(fontdata8x8[((text[i])*8)+l]&0x04)?color:screen[l*320+5]; - screen[l*320+6]=(fontdata8x8[((text[i])*8)+l]&0x02)?color:screen[l*320+6]; - screen[l*320+7]=(fontdata8x8[((text[i])*8)+l]&0x01)?color:screen[l*320+7]; + screen[l*320+0]=(fontdata8x8[((text[i])*8)+l]&0x80)?color:0; + screen[l*320+1]=(fontdata8x8[((text[i])*8)+l]&0x40)?color:0; + screen[l*320+2]=(fontdata8x8[((text[i])*8)+l]&0x20)?color:0; + screen[l*320+3]=(fontdata8x8[((text[i])*8)+l]&0x10)?color:0; + screen[l*320+4]=(fontdata8x8[((text[i])*8)+l]&0x08)?color:0; + screen[l*320+5]=(fontdata8x8[((text[i])*8)+l]&0x04)?color:0; + screen[l*320+6]=(fontdata8x8[((text[i])*8)+l]&0x02)?color:0; + screen[l*320+7]=(fontdata8x8[((text[i])*8)+l]&0x01)?color:0; } screen+=8; @@ -70,7 +72,7 @@ void CleanSurface(void) int c=4; while (c--) { - memset(gp2x_screen, 0, 320*240); + memset32(gp2x_screen, 0, 320*240*2/4); gp2x_video_flip(); } XBuf = gp2x_screen; @@ -136,38 +138,24 @@ static INLINE void printFps(uint8 *screen) prevsec = tv_now.tv_sec; } + if (!Settings.showfps || !screen) return; + if (Settings.scaling == 0) { if (needfpsflip) { - int y, *destt = (int *) screen; - for (y = 20/*240*/; y; y--) - { - *destt++ = 0; *destt++ = 0; *destt++ = 0; *destt++ = 0; - *destt++ = 0; *destt++ = 0; *destt++ = 0; *destt++ = 0; - destt += 64+8; - - //*destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; - //*destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; - } - if (Settings.showfps) - { - int sep; - for (sep=1; sep < 5; sep++) - if (fps_str[sep] == '/' || fps_str[sep] == 0) break; - fps_str[sep] = 0; - gp2x_text(screen, 0, 0, fps_str, FPS_COLOR, 0); - gp2x_text(screen, 0, 10, fps_str+sep+1, FPS_COLOR, 0); - } + int sep; + for (sep=1; sep < 5; sep++) + if (fps_str[sep] == '/' || fps_str[sep] == 0) break; + fps_str[sep] = 0; + gp2x_text(screen, 0, 0, fps_str, FPS_COLOR, 0); + gp2x_text(screen, 0, 10, fps_str+sep+1, FPS_COLOR, 0); needfpsflip--; } } else { - if (Settings.showfps) - { - gp2x_text(screen+32, 0, 0, fps_str, FPS_COLOR, 0); // TODO: firstline - } + gp2x_text(screen+32, 0, srendline, fps_str, FPS_COLOR, 0); } } @@ -176,14 +164,30 @@ void BlitScreen(uint8 *buf) { framesEmulated++; - if (!buf) return; + if (!buf) { + printFps(0); + return; + } framesRendered++; printFps(gp2x_screen); + if (eoptions & EO_CLIPSIDES) + { + int i, *p = (int *) ((char *)gp2x_screen + 32); + for (i = 240; i; i--, p += 320/4) + { + p[0] = p[1] = p[62] = p[63] = 0; + } + } + if (Settings.scaling == 3) - soft_scale((char *)gp2x_screen + 32, gp2x_palette16, 0, 240); + { + soft_scale((char *)gp2x_screen + 32, gp2x_palette16, srendline, erendline-srendline); + if (srendline) + memset32((int *)((char *)gp2x_screen + 32), 0, srendline*320*2/4); + } gp2x_video_flip(); XBuf = gp2x_screen; diff --git a/drivers/gp2x/input.c b/drivers/gp2x/input.c index 99a0867..daadc34 100644 --- a/drivers/gp2x/input.c +++ b/drivers/gp2x/input.c @@ -117,7 +117,7 @@ static void do_emu_acts(uint32 acts) #define down(b) (keys & GP2X_##b) static void do_fake_mouse(unsigned long keys) { - static int x=0, y=0; + static int x=256/2, y=240/2; int speed = 3; if (down(A)) speed = 1; diff --git a/drivers/gp2x/main.c b/drivers/gp2x/main.c index 4eaf3f6..caea8cc 100644 --- a/drivers/gp2x/main.c +++ b/drivers/gp2x/main.c @@ -38,11 +38,14 @@ #include "../common/unixdsp.h" #include "../common/cheat.h" +#include "../../fce.h" + #include "dface.h" -// just for printing some iNES info for user.. -#include "../../fce.h" -#include "../../ines.h" + +// TODO! broken fs0, sram saves + +void CleanSurface(void); // internals extern char lastLoadedGameName[2048]; @@ -50,12 +53,12 @@ extern uint8 Exit; // exit emu loop flag void CloseGame(void); FCEUGI *fceugi = NULL; -static int ntsccol=0,ntschue=-1,ntsctint=-1; +int ntsccol=0,ntschue=-1,ntsctint=-1; int soundvol=70; int inited=0; -int srendlinev[2]={0,0}; -int erendlinev[2]={239,239}; +int srendlinev[2]={8,0}; +int erendlinev[2]={231,239}; int srendline,erendline; @@ -83,7 +86,6 @@ static void ParseGI(FCEUGI *gi) InputType[1]=gi->input[1]; if(gi->inputfc>=0) InputTypeFC=gi->inputfc; - FCEUI_GetCurrentVidSystem(&srendline,&erendline); } void FCEUD_PrintError(char *s) @@ -130,8 +132,7 @@ void SaveConfig(const char *name) if (name) sprintf(tdir,"%s"PSS"cfg"PSS"%s.cfg",BaseDirectory,name); else sprintf(tdir,"%s"PSS"fceu2.cfg",BaseDirectory); - DriverInterface(DES_GETNTSCTINT,&ntsctint); - DriverInterface(DES_GETNTSCHUE,&ntschue); + FCEUI_GetNTSCTH(&ntsctint, &ntschue); SaveFCEUConfig(tdir,fceuconfig); } @@ -141,9 +142,9 @@ static void LoadConfig(const char *name) if (name) sprintf(tdir,"%s"PSS"cfg"PSS"%s.cfg",BaseDirectory,name); else sprintf(tdir,"%s"PSS"fceu2.cfg",BaseDirectory); + FCEUI_GetNTSCTH(&ntsctint, &ntschue); /* Get default settings for if no config file exists. */ LoadFCEUConfig(tdir,fceuconfig); - if(ntsctint>=0) DriverInterface(DES_SETNTSCTINT,&ntsctint); - if(ntschue>=0) DriverInterface(DES_SETNTSCHUE,&ntschue); + FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue); } static void LoadLLGN(void) @@ -289,13 +290,10 @@ static int DoArgs(int argc, char *argv[]) if(erendlinev[x]239) erendlinev[x]=239; } - printf("main() setrendered lines: %d, %d, %d, %d\n",srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]); - printf("main() clip sides %d\n", eoptions&EO_CLIPSIDES); - srendlinev[0]=0; + printf("FCEUI_SetRenderedLines: %d, %d, %d, %d\n",srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]); + printf("clip sides: %d\n", eoptions&EO_CLIPSIDES); FCEUI_SetRenderedLines(srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]); - FCEUI_SetRenderedLines(0,erendlinev[0],srendlinev[1],erendlinev[1]); FCEUI_SetSoundVolume(soundvol); - DriverInterface(DES_NTSCCOL,&ntsccol); // TODO DoDriverArgs(); if(fcexp) @@ -364,8 +362,9 @@ int CLImain(int argc, char *argv[]) gp2x_opt_setup(); gp2x_cpuclock_gamma_update(); LoadLLGN(); + FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue); if(cpalette) - LoadCPalette(); + LoadCPalette(); // TODO if(InitSound()) inited|=1; @@ -422,13 +421,15 @@ int CLImain(int argc, char *argv[]) } PrepareOtherInput(); + FCEUI_GetCurrentVidSystem(&srendline,&erendline); gp2x_video_changemode(Settings.scaling == 3 ? 15 : 8); switch (Settings.scaling & 3) { - case 0: gp2x_video_RGB_setscaling(0, 320, 240); gp2x_video_set_offs(0); break; - case 1: gp2x_video_RGB_setscaling(0, 256, 240); gp2x_video_set_offs(32); break; - case 2: gp2x_video_RGB_setscaling(0, 256, 240); gp2x_video_set_offs(32); break; // TODO - case 3: gp2x_video_RGB_setscaling(0, 320, 240); gp2x_video_set_offs(32); break; + case 0: gp2x_video_set_offs(0); gp2x_video_RGB_setscaling(0, 320, 240); break; + case 1: gp2x_video_set_offs(32); gp2x_video_RGB_setscaling(0, 256, 240); break; + case 2: gp2x_video_set_offs(32); gp2x_video_RGB_setscaling(srendline, 256, erendline-srendline); break; + case 3: gp2x_video_set_offs(32); gp2x_video_RGB_setscaling(0, 320, 240); break; } + CleanSurface(); gp2x_start_sound(Settings.sound_rate, 16, 0); FCEUI_Emulate(); } diff --git a/drivers/gp2x/menu.c b/drivers/gp2x/menu.c index 68b9bff..1972024 100644 --- a/drivers/gp2x/menu.c +++ b/drivers/gp2x/menu.c @@ -823,6 +823,19 @@ static void kc_sel_loop(void) // --------- FCEU options ---------- +extern int ntsccol,ntschue,ntsctint; +extern int srendlinev[2]; +extern int erendlinev[2]; +extern int eoptions; + + +static void int_incdec(int *p, int inc, int min, int max) +{ + *p += inc; + if (*p < min) *p = min; + else if (*p > max) *p = max; +} + static void draw_fcemenu_options(int menu_sel) { int tl_x = 25, tl_y = 60, y; @@ -830,8 +843,16 @@ static void draw_fcemenu_options(int menu_sel) y = tl_y; gp2x_fceu_copy_bg(); - gp2x_text_out15(tl_x, y, " %s", "OFF"); // 0 - gp2x_text_out15(tl_x, (y+=10), "Done"); + gp2x_text_out15(tl_x, y, "NTSC Color Emulation %s", ntsccol?"ON":"OFF"); // 0 + gp2x_text_out15(tl_x, (y+=10), " Tint (default: 56) %i", ntsctint); + gp2x_text_out15(tl_x, (y+=10), " Hue (default: 72) %i", ntschue); + gp2x_text_out15(tl_x, (y+=10), "First visible line (NTSC) %i", srendlinev[0]); + gp2x_text_out15(tl_x, (y+=10), "Last visible line (NTSC) %i", erendlinev[0]); + gp2x_text_out15(tl_x, (y+=10), "First visible line (PAL) %i", srendlinev[1]); // 5 + gp2x_text_out15(tl_x, (y+=10), "Last visible line (PAL) %i", erendlinev[1]); + gp2x_text_out15(tl_x, (y+=10), "Clip 8 left/right columns %s", (eoptions&EO_CLIPSIDES)?"ON":"OFF"); + gp2x_text_out15(tl_x, (y+=10), "Disable 8 sprite limit %s", "TODO"); + gp2x_text_out15(tl_x, (y+=10), "Done"); // 9 // draw cursor gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">"); @@ -841,9 +862,11 @@ static void draw_fcemenu_options(int menu_sel) static void fcemenu_loop_options(void) { - int menu_sel = 0, menu_sel_max = 1; + int menu_sel = 0, menu_sel_max = 9, i; unsigned long inp = 0; + FCEUI_GetNTSCTH(&ntsctint, &ntschue); + for(;;) { draw_fcemenu_options(menu_sel); @@ -852,15 +875,29 @@ static void fcemenu_loop_options(void) if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options switch (menu_sel) { - case 0: break; - case 1: return; + case 0: ntsccol = !ntsccol; break; + case 7: eoptions^=EO_CLIPSIDES; break; + case 9: return; + } + } + if(inp & (GP2X_X|GP2X_A)) { + for(i=0;i<2;i++) + { + if(srendlinev[i]<0 || srendlinev[i]>239) srendlinev[i]=0; + if(erendlinev[i]239) erendlinev[i]=239; } + FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue); + FCEUI_SetRenderedLines(srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]); + return; } - if(inp & (GP2X_X|GP2X_A)) return; if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise switch (menu_sel) { - case 0: - break; + case 1: int_incdec(&ntsctint, (inp & GP2X_LEFT) ? -1 : 1, 0, 128); break; + case 2: int_incdec(&ntschue, (inp & GP2X_LEFT) ? -1 : 1, 0, 128); break; + case 3: int_incdec(&srendlinev[0], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break; + case 4: int_incdec(&erendlinev[0], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break; + case 5: int_incdec(&srendlinev[1], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break; + case 6: int_incdec(&erendlinev[1], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break; } } } @@ -932,13 +969,6 @@ static int sndrate_prevnext(int rate, int dir) return rates[i]; } -static void int_incdec(int *p, int inc, int min, int max) -{ - *p += inc; - if (*p < min) *p = min; - else if (*p > max) *p = max; -} - static void config_commit(void) { gp2x_cpuclock_gamma_update(); @@ -1161,6 +1191,7 @@ static int menu_loop_root(void) selfname = romsel_loop(curr_path); if (selfname) { printf("selected file: %s\n", selfname); + while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000); return 2; } break; diff --git a/fce.c b/fce.c index becc308..7cc5996 100644 --- a/fce.c +++ b/fce.c @@ -605,7 +605,7 @@ static void LineUpdate(uint8 *target) { uint32 tem; - if(FSkip) + if(FSkip || scanline < FSettings.FirstSLine || scanline > FSettings.LastSLine) { if(PPU_hook) PRefreshLine(); @@ -614,13 +614,7 @@ static void LineUpdate(uint8 *target) { if(ScreenON) { - if(scanline>=FSettings.FirstSLine && scanline<=FSettings.LastSLine) - BGRender(target); - else - { - if(PPU_hook) - PRefreshLine(); - } + BGRender(target); } else { @@ -1235,13 +1229,13 @@ static void DoLine(void) #ifdef FRAMESKIP if(!FSkip) #endif - if(SpriteON && spork) - CopySprites(target); + if(scanline>=FSettings.FirstSLine && scanline<=FSettings.LastSLine) + { + if(SpriteON && spork) + CopySprites(target); -#ifdef FRAMESKIP - if(!FSkip) -#endif - LineUpdateEnd(target); + LineUpdateEnd(target); + } sphitx=0x100; if(ScreenON || SpriteON) diff --git a/nsf.c b/nsf.c index ea77c6a..52da5e5 100644 --- a/nsf.c +++ b/nsf.c @@ -415,7 +415,7 @@ void DrawNSF(uint8 *XBuf) memset(XBuf+SCREEN_OFFS+x*SCREEN_WIDTH,0,256); if(FSettings.SoundVolume) - mul=8192*240/(16384*FSettings.SoundVolume/50)/8; + mul=8192*240/(16384*FSettings.SoundVolume/50); { int16 *Bufpl; diff --git a/svga.c b/svga.c index f345e76..d00a38a 100644 --- a/svga.c +++ b/svga.c @@ -139,12 +139,6 @@ uint8 DIPS=0; uint8 CommandQueue=0; -static int controlselect=0; -static int ntsccol=0; -static int ntsctint=46+10; -static int ntschue=72; -static int controllength=0; - void FCEUI_SetSnapName(int a) { @@ -208,27 +202,12 @@ void DriverInterface(int w, void *d) { switch(w) { - case DES_NTSCCOL:ntsccol=*(int *)d;FCEU_ResetPalette();break; case DES_RESET:if(netplay!=2) CommandQueue=30;break; case DES_POWER:if(netplay!=2) CommandQueue=31;break; - case DES_GETNTSCTINT:*(int*)d=ntsctint;break; - case DES_GETNTSCHUE:*(int*)d=ntschue;break; - case DES_SETNTSCTINT:ntsctint=*(int*)d;if(ntsccol)FCEU_ResetPalette();break; - case DES_SETNTSCHUE:ntschue=*(int*)d;if(ntsccol)FCEU_ResetPalette();break; - - case DES_FDSINSERT:if(netplay!=2) CommandQueue=2;break; - case DES_FDSEJECT:if(netplay!=2) CommandQueue=3;break; - case DES_FDSSELECT:if(netplay!=2) CommandQueue=1;break; -/* - case DES_NSFINC:NSFControl(1);break; - case DES_NSFDEC:NSFControl(2);break; - case DES_NSFRES:NSFControl(0);break; -*/ + case DES_VSUNIDIPSET:CommandQueue=10+(int)d;break; case DES_VSUNITOGGLEDIPVIEW:CommandQueue=10;break; case DES_VSUNICOIN:CommandQueue=19;break; - case DES_NTSCSELHUE:if(ntsccol && FCEUGameInfo.type!=GIT_VSUNI && !PAL && FCEUGameInfo.type!=GIT_NSF){controlselect=1;controllength=360;}break; - case DES_NTSCSELTINT:if(ntsccol && FCEUGameInfo.type!=GIT_VSUNI && !PAL && FCEUGameInfo.type!=GIT_NSF){controlselect=2;controllength=360;}break; #if 0 case DES_NTSCDEC: if(ntsccol && FCEUGameInfo.type!=GIT_VSUNI && !PAL && FCEUGameInfo.type!=GIT_NSF) @@ -280,10 +259,6 @@ void DriverInterface(int w, void *d) #ifdef FRAMESKIP void FCEU_PutImageDummy(void) { - if(FCEUGameInfo.type!=GIT_NSF) - { - if(controllength) controllength--; - } if(howlong) howlong--; /* DrawMessage() */ #ifdef FPS { -- 2.39.5