From e5f12da441801c7b78a837c8f6bbeea6272c9c22 Mon Sep 17 00:00:00 2001 From: ugetab Date: Fri, 21 May 2010 20:36:24 +0000 Subject: [PATCH] After much effort, added NTSC 2x scaler option to both Windows and SDL. Includes new config option NTSCwinspecial. --- changelog.txt | 1 + src/drivers/common/vidblit.cpp | 140 +- src/drivers/common/vidblit.h | 2 +- src/drivers/sdl/gui.cpp | 3090 ++++++++++++++++---------------- src/drivers/sdl/sdl-opengl.cpp | 4 +- src/drivers/sdl/sdl-video.cpp | 14 +- src/drivers/sdl/sdl.cpp | 3 +- src/drivers/win/config.cpp | 1 + src/drivers/win/video.cpp | 42 +- src/drivers/win/video.h | 1 + src/drivers/win/window.cpp | 3 +- vc/vc10_fceux.vcxproj | 4 + vc/vc10_fceux.vcxproj.filters | 12 + vc/vc9_fceux.vcproj | 16 + 14 files changed, 1732 insertions(+), 1601 deletions(-) diff --git a/changelog.txt b/changelog.txt index a9a9bd52..a21c81dc 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,4 @@ +20-may-2010 - ugetab - Added NTSC 2x scalar option with some CFG config options of it's own 20-may-2010 - Cah4e3 - Win32 - CDLogger - fixed bug preventing correct interrupt vectors from logging 19-may-2010 - ugetab/adelikat - Win32 - Added single-instance mode, which makes starting a second copy of FCEUX load the file into the first, then exit.Mode off by default, togglable under Config -> GUI 18-may-2010 - adelikat - Movie + loadstate errors are handled more gracefully now, more informative error messages and the movie doesn't have to stop diff --git a/src/drivers/common/vidblit.cpp b/src/drivers/common/vidblit.cpp index 064aa491..07f655e2 100644 --- a/src/drivers/common/vidblit.cpp +++ b/src/drivers/common/vidblit.cpp @@ -25,6 +25,11 @@ #include "../../types.h" +#include "nes_ntsc.h" + +nes_ntsc_t* nes_ntsc; +uint8 burst_phase = 0; + static uint32 CBM[3]; static uint32 *palettetranslate=0; @@ -36,7 +41,7 @@ static int backBpp, backshiftr[3], backshiftl[3]; //static uint32 backmask[3]; static uint8 *specbuf8bpp = NULL; // For 2xscale, 3xscale. - +uint8 *ntscblit = NULL; // For nes_ntsc static int silt; @@ -75,16 +80,51 @@ static void CalculateShift(uint32 *CBM, int *cshiftr, int *cshiftl) } -int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask, int efx, int specfilt) +int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask, int efx, int specfilt, int specfilteropt) { - if(specfilt == 2 || specfilt == 4) // scale2x and scale3x + + // -Video Modes Tag- + if(specfilt == 3) // NTSC 2x + { + int multi = (2 * 2); + + //nes_ntsc variables + nes_ntsc_setup_t ntsc_setup = nes_ntsc_composite; + + switch (specfilteropt) + { + //case 0: // Composite + //ntsc_setup = nes_ntsc_composite; + //break; + case 1: //S-Video + ntsc_setup = nes_ntsc_svideo; + break; + case 2: //RGB + ntsc_setup = nes_ntsc_rgb; + break; + case 3: //Monochrome + ntsc_setup = nes_ntsc_monochrome; + break; + + } + + nes_ntsc = (nes_ntsc_t*) malloc( sizeof (nes_ntsc_t) ); + + if ( nes_ntsc ) { + nes_ntsc_init( nes_ntsc, &ntsc_setup, b, 2 ); + + ntscblit = (uint8*)malloc(256*257*b*multi); //Need to add multiplier for larger sizes + } + + } // -Video Modes Tag- + else if(specfilt == 2 || specfilt == 5) // scale2x and scale3x { int multi = ((specfilt == 2) ? 2 * 2 : 3 * 3); specbuf8bpp = (uint8*)malloc(256*240*multi); //mbg merge 7/17/06 added cast - } - else if(specfilt == 1 || specfilt == 3) // hq2x and hq3x + } // -Video Modes Tag- + else if(specfilt == 1 || specfilt == 4) // hq2x and hq3x { if(b == 1) return(0); @@ -116,8 +156,9 @@ int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask, int efx, int // backshiftr[x] -= backshiftl[x]; // End iffy code } + // -Video Modes Tag- if(specfilt == 1) specbuf32bpp = (uint32*)malloc(256*240*4*sizeof(uint32)); //mbg merge 7/17/06 added cast - else if(specfilt == 3) specbuf32bpp = (uint32*)malloc(256*240*9*sizeof(uint32)); //mbg merge 7/17/06 added cast + else if(specfilt == 4) specbuf32bpp = (uint32*)malloc(256*240*9*sizeof(uint32)); //mbg merge 7/17/06 added cast } efx=0; @@ -126,7 +167,8 @@ int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask, int efx, int gmask=0x3F<<5; bmask=0x1F; - if(specfilt == 3) + // -Video Modes Tag- + if(specfilt == 4) hq3x_InitLUTs(); else hq2x_InitLUTs(); @@ -188,12 +230,21 @@ void KillBlitToHigh(void) } if(specbuf) { - if(silt == 3) + // -Video Modes Tag- + if(silt == 4) hq3x_Kill(); else hq2x_Kill(); specbuf=NULL; } + if (nes_ntsc) { + free(nes_ntsc); + nes_ntsc = NULL; + } + if (ntscblit) { + free(ntscblit); + ntscblit = NULL; + } } @@ -348,6 +399,11 @@ void Blit8To8(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale, in int x,y; int pinc; + // -Video Modes Tag- + if(special==3) //NTSC 2x + return; //Incompatible with 8-bit output. This is here for SDL. + + // -Video Modes Tag- if(special==2) { if(xscale!=2 || yscale!=2) return; @@ -356,7 +412,8 @@ void Blit8To8(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale, in return; } - if(special==4) + // -Video Modes Tag- + if(special==5) { if(xscale!=3 || yscale!=3) return; scale(3,dest,pitch,src,256,1,xr,yr); @@ -442,6 +499,7 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int mult; int base; + // -Video Modes Tag- if(silt == 2) mult = 2; else mult = 3; @@ -673,31 +731,43 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, switch(Bpp) { case 4: - pinc=pitch-((xr*xscale)<<2); - for(y=yr;y;y--,src+=256-xr) - { - int doo=yscale; - - if(highefx& FVB_SCANLINES) - doo-=yscale>>1; - do + if ( nes_ntsc ) { + burst_phase ^= 1; + nes_ntsc_blit( nes_ntsc, (unsigned char*)src, xr, burst_phase, + xr, yr, ntscblit, xr * Bpp * xscale ); + + //Multiply 4 by the multiplier on output, because it's 4 bpp + //Top 2 lines = line 3, due to distracting flicker + //memcpy(dest,ntscblit+(Bpp * xscale)+(Bpp * xr * xscale),(Bpp * xr * xscale)); + //memcpy(dest+(Bpp * xr * xscale),ntscblit+(Bpp * xscale)+(Bpp * xr * xscale * 2),(Bpp * xr * xscale)); + memcpy(dest+(Bpp * xr * xscale),ntscblit+(Bpp * xscale),(xr*yr*Bpp*xscale*yscale)); + } else { + pinc=pitch-((xr*xscale)<<2); + for(y=yr;y;y--,src+=256-xr) { - for(x=xr;x;x--,src++) + int doo=yscale; + + if(highefx& FVB_SCANLINES) + doo-=yscale>>1; + do { - int too=xscale; - do + for(x=xr;x;x--,src++) { - *(uint32 *)dest=palettetranslate[*src]; - dest+=4; - } while(--too); - } - src-=xr; - dest+=pinc; - } while(--doo); - src+=xr; - if(highefx&FVB_SCANLINES) - dest+=pitch*(yscale>>1); - } + int too=xscale; + do + { + *(uint32 *)dest=palettetranslate[*src]; + dest+=4; + } while(--too); + } + src-=xr; + dest+=pinc; + } while(--doo); + src+=xr; + if(highefx&FVB_SCANLINES) + dest+=pitch*(yscale>>1); + } + } break; case 3: @@ -817,9 +887,10 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, { if(specbuf32bpp) { - int mult = (silt == 3)?3:2; + // -Video Modes Tag- + int mult = (silt == 4)?3:2; - if(silt == 3) + if(silt == 4) hq3x_32((uint8 *)specbuf,(uint8*)specbuf32bpp,xr,yr,xr*3*sizeof(uint32)); else hq2x_32((uint8 *)specbuf,(uint8*)specbuf32bpp,xr,yr,xr*2*sizeof(uint32)); @@ -831,7 +902,8 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, } else { - if(silt == 3) + // -Video Modes Tag- + if(silt == 4) hq3x_32((uint8 *)specbuf,destbackup,xr,yr,pitchbackup); else hq2x_32((uint8 *)specbuf,destbackup,xr,yr,pitchbackup); diff --git a/src/drivers/common/vidblit.h b/src/drivers/common/vidblit.h index cf957e32..5a3927f8 100644 --- a/src/drivers/common/vidblit.h +++ b/src/drivers/common/vidblit.h @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask, int eefx, int specfilt); +int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask, int eefx, int specfilt, int specfilteropt); void SetPaletteBlitToHigh(uint8 *src); void KillBlitToHigh(void); void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale, int yscale); diff --git a/src/drivers/sdl/gui.cpp b/src/drivers/sdl/gui.cpp index c6c31576..59fccdc3 100644 --- a/src/drivers/sdl/gui.cpp +++ b/src/drivers/sdl/gui.cpp @@ -1,1544 +1,1546 @@ -#include -#include - -#include - -#include -#include -#include - -#include "../../types.h" -#include "../../fceu.h" -#include "../../driver.h" -#include "../../version.h" -#include "../../movie.h" -#include "../../palette.h" -#include "../../fds.h" - - -#include "../common/configSys.h" -#include "sdl.h" -#include "gui.h" -#include "dface.h" -#include "input.h" -#include "config.h" - -#ifdef _S9XLUA_H -#include "../../fceulua.h" -#endif - -void toggleSound(GtkWidget* check, gpointer data); -void loadGame (); - -extern Config *g_config; - -GtkWidget* MainWindow = NULL; -GtkWidget* padNoCombo; - -// This function configures a single button on a gamepad -int configGamepadButton(GtkButton* button, gpointer p) -{ - int x = GPOINTER_TO_INT(p); - int padNo = 0; - char* padStr = gtk_combo_box_get_active_text(GTK_COMBO_BOX(padNoCombo)); - - if(!strcmp(padStr, "1")) - padNo = 0; - if(!strcmp(padStr, "2")) - padNo = 1; - if(!strcmp(padStr, "3")) - padNo = 2; - if(!strcmp(padStr, "4")) - padNo = 3; - - char buf[256]; - std::string prefix; - - ButtonConfigBegin(); - - snprintf(buf, 256, "SDL.Input.GamePad.%d", padNo); - prefix = buf; - ConfigButton((char*)GamePadNames[x], &GamePadConfig[padNo][x]); - - g_config->setOption(prefix + GamePadNames[x], GamePadConfig[padNo][x].ButtonNum[0]); - - if(GamePadConfig[padNo][x].ButtType[0] == BUTTC_KEYBOARD) - { - g_config->setOption(prefix + "DeviceType", "Keyboard"); - } else if(GamePadConfig[padNo][x].ButtType[0] == BUTTC_JOYSTICK) { - g_config->setOption(prefix + "DeviceType", "Joystick"); - } else { - g_config->setOption(prefix + "DeviceType", "Unknown"); - } - g_config->setOption(prefix + "DeviceNum", GamePadConfig[padNo][0].DeviceNum[0]); - - ButtonConfigEnd(); - - return 0; -} - -void toggleLowPass(GtkWidget* w, gpointer p) -{ - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) - { - g_config->setOption("SDL.Sound.LowPass", 1); - FCEUI_SetLowPass(1); - } - else - { - g_config->setOption("SDL.Sound.LowPass", 0); - FCEUI_SetLowPass(0); - } - g_config->save(); - -} - -// Wrapper for pushing GTK options into the config file -// p : pointer to the string that names the config option -// w : toggle widget -void toggleOption(GtkWidget* w, gpointer p) -{ - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) - g_config->setOption((char*)p, 1); - else - g_config->setOption((char*)p, 0); - g_config->save(); -} - -int setTint(GtkWidget* w, gpointer p) -{ - int v = gtk_range_get_value(GTK_RANGE(w)); - g_config->setOption("SDL.Tint", v); - g_config->save(); - int c, h; - g_config->getOption("SDL.NTSCpalette", &c); - g_config->getOption("SDL.Hue", &h); - FCEUI_SetNTSCTH(c, v, h); - - return 0; -} -int setHue(GtkWidget* w, gpointer p) -{ - int v = gtk_range_get_value(GTK_RANGE(w)); - g_config->setOption("SDL.Hue", v); - g_config->save(); - int c, t; - g_config->getOption("SDL.Tint", &t); - g_config->getOption("SDL.SDL.NTSCpalette", &c); - FCEUI_SetNTSCTH(c, t, v); - - return 0; -} -void loadPalette (GtkWidget* w, gpointer p) -{ - GtkWidget* fileChooser; - - fileChooser = gtk_file_chooser_dialog_new ("Open NES Palette", GTK_WINDOW(MainWindow), - GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); - - if (gtk_dialog_run (GTK_DIALOG (fileChooser)) ==GTK_RESPONSE_ACCEPT) - { - char* filename; - - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); - g_config->setOption("SDL.Palette", filename); - g_config->setOption("SDL.SDL.NTSCpalette", 0); - if(LoadCPalette(filename) == 0) - { - GtkWidget* msgbox; - msgbox = gtk_message_dialog_new(GTK_WINDOW(MainWindow), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - "Failed to load the palette."); - - gtk_dialog_run(GTK_DIALOG(msgbox)); - gtk_widget_hide_all(msgbox); - } - - gtk_entry_set_text(GTK_ENTRY(p), filename); - - } - gtk_widget_destroy (fileChooser); -} - -void clearPalette(GtkWidget* w, gpointer p) -{ - g_config->setOption("SDL.Palette", 0); - gtk_entry_set_text(GTK_ENTRY(p), ""); -} - -void openPaletteConfig() -{ - GtkWidget* win; - GtkWidget* vbox; - GtkWidget* paletteFrame; - GtkWidget* paletteHbox; - GtkWidget* paletteButton; - GtkWidget* paletteEntry; - GtkWidget* clearButton; - GtkWidget* ntscColorChk; - GtkWidget* slidersFrame; - GtkWidget* slidersVbox; - GtkWidget* tintFrame; - GtkWidget* tintHscale; - GtkWidget* hueFrame; - GtkWidget* hueHscale; - - win = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(win),"Palette Options"); - vbox = gtk_vbox_new(FALSE, 5); - gtk_container_add(GTK_CONTAINER(win), vbox); - - gtk_widget_set_size_request(win, 460, 275); - - paletteFrame = gtk_frame_new("Custom palette: "); - paletteHbox = gtk_hbox_new(FALSE, 5); - gtk_container_set_border_width(GTK_CONTAINER(paletteHbox), 5); - gtk_container_add(GTK_CONTAINER(paletteFrame), paletteHbox); - paletteButton = gtk_button_new_from_stock(GTK_STOCK_OPEN); - gtk_button_set_label(GTK_BUTTON(paletteButton), "Open palette"); - paletteEntry = gtk_entry_new(); - gtk_entry_set_editable(GTK_ENTRY(paletteEntry), FALSE); - - clearButton = gtk_button_new_from_stock(GTK_STOCK_CLEAR); - - gtk_box_pack_start(GTK_BOX(paletteHbox), paletteButton, FALSE, FALSE, 2); - gtk_box_pack_start(GTK_BOX(paletteHbox), paletteEntry, TRUE, TRUE, 5); - gtk_box_pack_start(GTK_BOX(paletteHbox), clearButton, FALSE, FALSE, 0); - - g_signal_connect(paletteButton, "clicked", G_CALLBACK(loadPalette), paletteEntry); - g_signal_connect(clearButton, "clicked", G_CALLBACK(clearPalette), paletteEntry); - - - - // sync with config - std::string fn; - g_config->getOption("SDL.Palette", &fn); - gtk_entry_set_text(GTK_ENTRY(paletteEntry), fn.c_str()); - - // ntsc color check - - ntscColorChk = gtk_check_button_new_with_label("Use NTSC palette"); - - g_signal_connect(ntscColorChk, "clicked", G_CALLBACK(toggleOption), (gpointer)"SDL.NTSCpalette"); - - int b; - // sync with config - g_config->getOption("SDL.NTSCpalette", &b); - if(b) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ntscColorChk), 1); - else - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ntscColorChk), 0); - - - // color / tint / hue sliders - slidersFrame = gtk_frame_new("NTSC palette controls"); - slidersVbox = gtk_vbox_new(FALSE, 2); - tintFrame = gtk_frame_new("Tint"); - tintHscale = gtk_hscale_new_with_range(0, 128, 1); - gtk_container_add(GTK_CONTAINER(tintFrame), tintHscale); - hueFrame = gtk_frame_new("Hue"); - hueHscale = gtk_hscale_new_with_range(0, 128, 1); - gtk_container_add(GTK_CONTAINER(hueFrame), hueHscale); - - g_signal_connect(tintHscale, "button-release-event", G_CALLBACK(setTint), NULL); - g_signal_connect(hueHscale, "button-release-event", G_CALLBACK(setHue), NULL); - - // sync with config - int h, t; - g_config->getOption("SDL.Hue", &h); - g_config->getOption("SDL.Tint", &t); - - gtk_range_set_value(GTK_RANGE(hueHscale), h); - gtk_range_set_value(GTK_RANGE(tintHscale), t); - - gtk_container_add(GTK_CONTAINER(slidersFrame), slidersVbox); - gtk_box_pack_start(GTK_BOX(slidersVbox), ntscColorChk, FALSE, FALSE, 5); - gtk_box_pack_start(GTK_BOX(slidersVbox), tintFrame, FALSE, TRUE, 5); - gtk_box_pack_start(GTK_BOX(slidersVbox), hueFrame, FALSE, TRUE, 5); - - gtk_box_pack_start(GTK_BOX(vbox), paletteFrame, FALSE, TRUE, 5); - - gtk_box_pack_start(GTK_BOX(vbox), slidersFrame, FALSE, TRUE, 5); - - gtk_widget_show_all(win); - - return; -} - -GtkWidget* ipEntry; -GtkWidget* portSpin; -GtkWidget* pwEntry; - -void launchNet(GtkWidget* w, gpointer p) -{ - char* ip = (char*)gtk_entry_get_text(GTK_ENTRY(ipEntry)); - char* pw = (char*)gtk_entry_get_text(GTK_ENTRY(pwEntry)); - int port = (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(portSpin)); - - g_config->setOption("SDL.NetworkIP", ip); - g_config->setOption("SDL.NetworkPassword", pw); - g_config->setOption("SDL.NetworkPort", port); - - gtk_widget_destroy(GTK_WIDGET(p)); - - loadGame(); -} -void closeNet(GtkWidget* w, gpointer p) -{ - gtk_widget_destroy(GTK_WIDGET(p)); -} - -void setUsername(GtkWidget* w, gpointer p) -{ - char* s = (char*)gtk_entry_get_text(GTK_ENTRY(w)); - g_config->setOption("SDL.NetworkUsername", s); -} - -void openNetworkConfig() -{ - GtkWidget* win; - GtkWidget* box; - GtkWidget* userBox; - GtkWidget* userEntry; - GtkWidget* userLbl; - GtkWidget* frame; - GtkWidget* vbox; - GtkWidget* ipBox; - GtkWidget* ipLbl; - - GtkWidget* portBox; - GtkWidget* portLbl; - - //GtkWidget* localPlayersCbo; - GtkWidget* pwBox; - GtkWidget* pwLbl; - - GtkWidget* bb; - GtkWidget* conBtn; - GtkWidget* closeBtn; - - win = gtk_window_new(GTK_WINDOW_TOPLEVEL); - box = gtk_vbox_new(FALSE, 3); - - userBox = gtk_hbox_new(FALSE, 3); - userLbl = gtk_label_new("Username:"); - userEntry = gtk_entry_new(); - std::string s; - g_config->getOption("SDL.NetworkUsername", &s); - gtk_entry_set_text(GTK_ENTRY(userEntry), s.c_str()); - - g_signal_connect(userEntry, "changed", G_CALLBACK(setUsername), NULL); - - - frame = gtk_frame_new("Network options"); - vbox = gtk_vbox_new(FALSE, 5); - ipBox = gtk_hbox_new(FALSE, 5); - ipLbl = gtk_label_new("Server IP:"); - ipEntry = gtk_entry_new(); - portBox = gtk_hbox_new(FALSE, 5); - portLbl = gtk_label_new("Server port:"); - portSpin = gtk_spin_button_new_with_range(0, 999999, 1); - //localPlayersCbo = gtk_combo_box_new_text(); - pwBox = gtk_hbox_new(FALSE, 3); - pwLbl = gtk_label_new("Server password:"); - pwEntry = gtk_entry_new(); - bb = gtk_hbox_new(FALSE, 5); - conBtn = gtk_button_new_from_stock(GTK_STOCK_CONNECT); - closeBtn = gtk_button_new_from_stock(GTK_STOCK_CLOSE); - - gtk_spin_button_set_value(GTK_SPIN_BUTTON(portSpin), 4046); - - gtk_box_pack_start(GTK_BOX(userBox), userLbl, FALSE, FALSE, 3); - gtk_box_pack_start(GTK_BOX(userBox), userEntry, TRUE , TRUE, 3); - - gtk_box_pack_start(GTK_BOX(portBox), portLbl, FALSE, FALSE, 3); - gtk_box_pack_start(GTK_BOX(portBox), portSpin, FALSE , FALSE, 3); - - gtk_box_pack_start(GTK_BOX(ipBox), ipLbl, FALSE, FALSE, 3); - gtk_box_pack_start(GTK_BOX(ipBox), ipEntry, TRUE , TRUE, 3); - - gtk_box_pack_start(GTK_BOX(pwBox), pwLbl, FALSE, FALSE, 3); - gtk_box_pack_start(GTK_BOX(pwBox), pwEntry, TRUE , TRUE, 3); - - gtk_box_pack_start_defaults(GTK_BOX(vbox), ipBox); - gtk_box_pack_start_defaults(GTK_BOX(vbox), portBox); - //gtk_box_pack_start_defaults(GTK_BOX(vbox), localPlayersCbo); - gtk_box_pack_start_defaults(GTK_BOX(vbox), pwBox); - - gtk_container_add(GTK_CONTAINER(frame), vbox); - - gtk_box_pack_start_defaults(GTK_BOX(box), userBox); - gtk_box_pack_start_defaults(GTK_BOX(box), frame); - gtk_box_pack_start(GTK_BOX(bb), closeBtn, FALSE, FALSE, 5); - gtk_box_pack_start(GTK_BOX(bb), conBtn, FALSE, FALSE, 5); - - gtk_box_pack_start_defaults(GTK_BOX(box), bb); - gtk_container_add(GTK_CONTAINER(win), box); - - gtk_widget_show_all(win); - - g_signal_connect(closeBtn, "clicked", G_CALLBACK(closeNet), win); - g_signal_connect(conBtn, "clicked", G_CALLBACK(launchNet), win); -} - -// creates and opens hotkey config window -/*void openHotkeyConfig() -{ - std::string prefix = "SDL.Hotkeys."; - GtkWidget* win = gtk_window_new(GTK_WINDOW_TOPLEVEL); - enum - { - COMMAND_COLUMN, - KEY_COLUMN, - N_COLUMNS - }; - GtkListStore* store = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING); - GtkTreeIter iter; - - gtk_list_store_append(store, &iter); // aquire iter - - - int buf; - for(int i=0; igetOption(prefix + HotkeyStrings[i], &buf); - gtk_list_store_set(store, &iter, - COMMAND_COLUMN, prefix + HotkeyStrings[i], - KEY_COLUMN, "TODO", -1); - } - GtkWidget* tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - - renderer = gtk_cell_renderer_text_new(); - column = gtk_tree_view_column_new_with_attributes("Command", renderer, "text", 0, NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); - - gtk_container_add(GTK_CONTAINER(win),tree); - gtk_widget_show_all(win); -}*/ -GtkWidget* typeCombo; - -// TODO: finish this -int setInputDevice(GtkWidget* w, gpointer p) -{ - std::string s = "SDL.Input."; - s = s + (char*)p; - printf("%s", s.c_str()); - g_config->setOption(s, gtk_combo_box_get_active_text(GTK_COMBO_BOX(typeCombo))); - g_config->save(); - - return 1; -} - -// creates and opens the gamepad config window -void openGamepadConfig() -{ - GtkWidget* win; - GtkWidget* vbox; - GtkWidget* hboxPadNo; - GtkWidget* padNoLabel; - GtkWidget* fourScoreChk; - - GtkWidget* buttons[10]; - - win = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(win), "Gamepad Config"); - gtk_widget_set_size_request(win, 250, 500); - vbox = gtk_vbox_new(TRUE, 4); - hboxPadNo = gtk_hbox_new(FALSE, 5); - padNoLabel = gtk_label_new("Gamepad Number:"); - fourScoreChk = gtk_check_button_new_with_label("Enable four score"); - - typeCombo = gtk_combo_box_new_text(); - gtk_combo_box_append_text(GTK_COMBO_BOX(typeCombo), "gamepad"); - gtk_combo_box_append_text(GTK_COMBO_BOX(typeCombo), "zapper"); - gtk_combo_box_append_text(GTK_COMBO_BOX(typeCombo), "powerpad.0"); - gtk_combo_box_append_text(GTK_COMBO_BOX(typeCombo), "powerpad.1"); - gtk_combo_box_append_text(GTK_COMBO_BOX(typeCombo), "arkanoid"); - - gtk_combo_box_set_active(GTK_COMBO_BOX(typeCombo), 0); - - - padNoCombo = gtk_combo_box_new_text(); - gtk_combo_box_append_text(GTK_COMBO_BOX(padNoCombo), "1"); - gtk_combo_box_append_text(GTK_COMBO_BOX(padNoCombo), "2"); - gtk_combo_box_append_text(GTK_COMBO_BOX(padNoCombo), "3"); - gtk_combo_box_append_text(GTK_COMBO_BOX(padNoCombo), "4"); - - gtk_combo_box_set_active(GTK_COMBO_BOX(padNoCombo), 0); - - g_signal_connect(GTK_OBJECT(typeCombo), "changed", G_CALLBACK(setInputDevice), - gtk_combo_box_get_active_text(GTK_COMBO_BOX(typeCombo))); - - // sync with config - int buf = 0; - g_config->getOption("SDL.FourScore", &buf); - if(buf) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fourScoreChk), 1); - else - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fourScoreChk), 0); - - g_signal_connect(GTK_OBJECT(fourScoreChk), "clicked", G_CALLBACK(toggleOption), (gpointer)"SDL.FourScore"); - - gtk_box_pack_start(GTK_BOX(hboxPadNo), padNoLabel, TRUE, TRUE, 5); - gtk_box_pack_start(GTK_BOX(hboxPadNo), padNoCombo, TRUE, FALSE, 5); - gtk_box_pack_start(GTK_BOX(vbox), hboxPadNo, TRUE, TRUE, 5); - //gtk_box_pack_start_defaults(GTK_BOX(vbox), typeCombo); - - gtk_box_pack_start(GTK_BOX(vbox), fourScoreChk, TRUE, TRUE, 5); - // create gamepad buttons - for(int i=0; i<10; i++) - { - buttons[i] = gtk_button_new_with_label(GamePadNames[i]); - gtk_box_pack_start(GTK_BOX(vbox), buttons[i], TRUE, TRUE, 3); - gtk_signal_connect(GTK_OBJECT(buttons[i]), "clicked", G_CALLBACK(configGamepadButton), GINT_TO_POINTER(i)); - } - - gtk_container_add(GTK_CONTAINER(win), vbox); - - gtk_widget_show_all(win); - - return; -} - -int setBufSize(GtkWidget* w, gpointer p) -{ - int x = gtk_range_get_value(GTK_RANGE(w)); - g_config->setOption("SDL.Sound.BufSize", x); - // reset sound subsystem for changes to take effect - KillSound(); - InitSound(); - g_config->save(); - return false; -} - -void setRate(GtkWidget* w, gpointer p) -{ - char* str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(w)); - g_config->setOption("SDL.Sound.Rate", atoi(str)); - // reset sound subsystem for changes to take effect - KillSound(); - InitSound(); - g_config->save(); - return; -} - -void setQuality(GtkWidget* w, gpointer p) -{ - char* str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(w)); - if(!strcmp(str, "Very High")) - g_config->setOption("SDL.Sound.Quality", 2); - if(!strcmp(str, "High")) - g_config->setOption("SDL.Sound.Quality", 1); - if(!strcmp(str, "Low")) - g_config->setOption("SDL.Sound.Quality", 0); - // reset sound subsystem for changes to take effect - KillSound(); - InitSound(); - g_config->save(); - return; -} - -void setScaler(GtkWidget* w, gpointer p) -{ - int x = gtk_combo_box_get_active(GTK_COMBO_BOX(w)); - g_config->setOption("SDL.SpecialFilter", x); - g_config->save(); -} - - -int setXscale(GtkWidget* w, gpointer p) -{ - double v = gtk_spin_button_get_value(GTK_SPIN_BUTTON(w)); - g_config->setOption("SDL.XScale", v); - g_config->save(); - return 0; -} - -int setYscale(GtkWidget* w, gpointer p) -{ - double v = gtk_spin_button_get_value(GTK_SPIN_BUTTON(w)); - g_config->setOption("SDL.YScale", v); - g_config->save(); - return 0; -} - -void setGl(GtkWidget* w, gpointer p) -{ - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) - g_config->setOption("SDL.OpenGL", 1); - else - g_config->setOption("SDL.OpenGL", 0); - g_config->save(); -} - - -void openVideoConfig() -{ - GtkWidget* win; - GtkWidget* vbox; - GtkWidget* lbl; - GtkWidget* hbox1; - GtkWidget* scalerLbl; - GtkWidget* scalerCombo; - GtkWidget* glChk; - GtkWidget* palChk; - GtkWidget* ppuChk; - GtkWidget* xscaleSpin; - GtkWidget* yscaleSpin; - GtkWidget* xscaleLbl; - GtkWidget* yscaleLbl; - GtkWidget* xscaleHbox; - GtkWidget* yscaleHbox; - - - win = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(win), "Video Preferences"); - //gtk_widget_set_size_request(win, 250, 250); - - vbox = gtk_vbox_new(FALSE, 5); - - lbl = gtk_label_new("Video options will not take\neffect until the emulator is restarted."); - - // scalar widgets - hbox1 = gtk_hbox_new(FALSE, 3); - scalerLbl = gtk_label_new("Special Scaler: "); - scalerCombo = gtk_combo_box_new_text(); - gtk_combo_box_append_text(GTK_COMBO_BOX(scalerCombo), "none"); - gtk_combo_box_append_text(GTK_COMBO_BOX(scalerCombo), "hq2x"); - gtk_combo_box_append_text(GTK_COMBO_BOX(scalerCombo), "scale2x"); - gtk_combo_box_append_text(GTK_COMBO_BOX(scalerCombo), "hq3x"); - gtk_combo_box_append_text(GTK_COMBO_BOX(scalerCombo), "scale3x"); - - // sync with cfg - int buf; - g_config->getOption("SDL.SpecialFilter", &buf); - gtk_combo_box_set_active(GTK_COMBO_BOX(scalerCombo), buf); - - g_signal_connect(GTK_OBJECT(scalerCombo), "changed", G_CALLBACK(setScaler), NULL); - gtk_box_pack_start(GTK_BOX(hbox1), scalerLbl, FALSE, FALSE, 5); - gtk_box_pack_start(GTK_BOX(hbox1), scalerCombo, FALSE, FALSE, 5); - - // openGL check - glChk = gtk_check_button_new_with_label("Enable OpenGL"); - g_signal_connect(GTK_OBJECT(glChk), "clicked", G_CALLBACK(setGl), (gpointer)scalerCombo); - - // sync with config - g_config->getOption("SDL.OpenGL", &buf); - if(buf) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glChk), 1); - else - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glChk), 0); - - // PAL check - palChk = gtk_check_button_new_with_label("Enable PAL mode"); - g_signal_connect(GTK_OBJECT(palChk), "clicked", G_CALLBACK(toggleOption), (gpointer)"SDL.PAL"); - - // sync with config - g_config->getOption("SDL.PAL", &buf); - if(buf) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(palChk), 1); - else - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(palChk), 0); - - // New PPU check - ppuChk = gtk_check_button_new_with_label("Enable new PPU"); - g_signal_connect(GTK_OBJECT(ppuChk), "clicked", G_CALLBACK(toggleOption), (gpointer)"SDL.NewPPU"); - - // sync with config - buf = 0; - g_config->getOption("SDL.NewPPU", &buf); - if(buf) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ppuChk), 1); - else - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ppuChk), 0); - - // xscale / yscale - xscaleHbox = gtk_hbox_new(FALSE, 5); - xscaleLbl = gtk_label_new("X scaling factor"); - xscaleSpin = gtk_spin_button_new_with_range(1.0, 10.0, .1); - yscaleHbox = gtk_hbox_new(FALSE, 5); - yscaleLbl = gtk_label_new("Y scaling factor"); - yscaleSpin = gtk_spin_button_new_with_range(1.0, 10.0, .1); - - gtk_box_pack_start(GTK_BOX(xscaleHbox), xscaleLbl, FALSE, FALSE, 2); - gtk_box_pack_start(GTK_BOX(xscaleHbox), xscaleSpin, FALSE, FALSE, 2); - gtk_box_pack_start(GTK_BOX(yscaleHbox), yscaleLbl, FALSE, FALSE, 2); - gtk_box_pack_start(GTK_BOX(yscaleHbox), yscaleSpin, FALSE, FALSE, 2); - - g_signal_connect(xscaleSpin, "button-release-event", G_CALLBACK(setXscale), NULL); - g_signal_connect(yscaleSpin, "button-release-event", G_CALLBACK(setYscale), NULL); - - double f; - // sync with config - g_config->getOption("SDL.XScale", &f); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(xscaleSpin), f); - g_config->getOption("SDL.YScale", &f); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(yscaleSpin), f); - - - - gtk_box_pack_start(GTK_BOX(vbox), lbl, FALSE, FALSE, 5); - gtk_box_pack_start(GTK_BOX(vbox), hbox1, FALSE, FALSE, 5); - gtk_box_pack_start(GTK_BOX(vbox), glChk, FALSE, FALSE, 5); - gtk_box_pack_start(GTK_BOX(vbox), palChk, FALSE, FALSE,5); - gtk_box_pack_start(GTK_BOX(vbox), ppuChk, FALSE, FALSE, 5); - gtk_box_pack_start(GTK_BOX(vbox), xscaleHbox, FALSE, FALSE, 5); - gtk_box_pack_start(GTK_BOX(vbox), yscaleHbox, FALSE, FALSE, 5); - - - gtk_container_add(GTK_CONTAINER(win), vbox); - gtk_widget_show_all(win); - - return; -} -const char* mixerStrings[6] = {"Volume", "Triangle", "Square1", "Square2", "Noise", "PCM"}; - -int mixerChanged(GtkWidget* w, gpointer p) -{ - int v = gtk_range_get_value(GTK_RANGE(w)); - GtkWidget* parent = gtk_widget_get_parent(w); - char* lbl = (char*)gtk_frame_get_label(GTK_FRAME(parent)); - if(strcmp(lbl, "Volume") == 0) - { - g_config->setOption("SDL.Sound.Volume", v); - FCEUI_SetSoundVolume(v); - } - if(strcmp(lbl, "Triangle") == 0) - { - g_config->setOption("SDL.Sound.TriangleVolume", v); - FCEUI_SetTriangleVolume(v); - } - if(strcmp(lbl, "Square1") == 0) - { - g_config->setOption("SDL.Sound.Square1Volume", v); - FCEUI_SetSquare1Volume(v); - } - if(strcmp(lbl, "Square2") == 0) - { - g_config->setOption("SDL.Sound.Square2Volume", v); - FCEUI_SetSquare2Volume(v); - } - if(strcmp(lbl, "Noise") == 0) - { - g_config->setOption("SDL.Sound.NoiseVolume", v); - FCEUI_SetNoiseVolume(v); - } - if(strcmp(lbl, "PCM") == 0) - { - g_config->setOption("SDL.Sound.PCMVolume", v); - FCEUI_SetPCMVolume(v); - } - - return 0; -} - - -void openSoundConfig() -{ - GtkWidget* win; - GtkWidget* main_hbox; - GtkWidget* vbox; - GtkWidget* soundChk; - GtkWidget* lowpassChk; - GtkWidget* hbox1; - GtkWidget* qualityCombo; - GtkWidget* qualityLbl; - GtkWidget* hbox2; - GtkWidget* rateCombo; - GtkWidget* rateLbl; - GtkWidget* hbox3; - GtkWidget* bufferLbl; - GtkWidget* bufferHscale; - GtkWidget* mixerFrame; - GtkWidget* mixerHbox; - GtkWidget* mixers[6]; - GtkWidget* mixerFrames[6]; - - - win = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(win), "Sound Preferences"); - main_hbox = gtk_hbox_new(FALSE, 15); - vbox = gtk_vbox_new(False, 5); - //gtk_widget_set_size_request(win, 300, 200); - - - // sound enable check - soundChk = gtk_check_button_new_with_label("Enable sound"); - - // sync with cfg - int cfgBuf; - g_config->getOption("SDL.Sound", &cfgBuf); - if(cfgBuf) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(soundChk), TRUE); - else - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(soundChk), FALSE); - - gtk_signal_connect(GTK_OBJECT(soundChk), "clicked", - G_CALLBACK(toggleSound), NULL); - - - // low pass filter check - lowpassChk = gtk_check_button_new_with_label("Enable low pass filter"); - - // sync with cfg - g_config->getOption("SDL.Sound.LowPass", &cfgBuf); - if(cfgBuf) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lowpassChk), TRUE); - else - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lowpassChk), FALSE); - - gtk_signal_connect(GTK_OBJECT(lowpassChk), "clicked", G_CALLBACK(toggleLowPass), NULL); - - // sound quality combo box - hbox1 = gtk_hbox_new(FALSE, 3); - qualityCombo = gtk_combo_box_new_text(); - gtk_combo_box_append_text(GTK_COMBO_BOX(qualityCombo), "Low"); - gtk_combo_box_append_text(GTK_COMBO_BOX(qualityCombo), "High"); - gtk_combo_box_append_text(GTK_COMBO_BOX(qualityCombo), "Very High"); - - // sync widget with cfg - g_config->getOption("SDL.Sound.Quality", &cfgBuf); - if(cfgBuf == 2) - gtk_combo_box_set_active(GTK_COMBO_BOX(qualityCombo), 2); - else if(cfgBuf == 1) - gtk_combo_box_set_active(GTK_COMBO_BOX(qualityCombo), 1); - else - gtk_combo_box_set_active(GTK_COMBO_BOX(qualityCombo), 0); - - g_signal_connect(qualityCombo, "changed", G_CALLBACK(setQuality), NULL); - - qualityLbl = gtk_label_new("Quality: "); - - gtk_box_pack_start(GTK_BOX(hbox1), qualityLbl, FALSE, FALSE, 5); - gtk_box_pack_start(GTK_BOX(hbox1), qualityCombo, FALSE, FALSE, 5); - - // sound rate widgets - hbox2 = gtk_hbox_new(FALSE, 3); - rateCombo = gtk_combo_box_new_text(); - - const int rates[5] = {11025, 22050, 44100, 48000, 96000}; - - char buf[8]; - for(int i=0; i<5;i++) - { - sprintf(buf, "%d", rates[i]); - gtk_combo_box_append_text(GTK_COMBO_BOX(rateCombo), buf); - } - - // sync widget with cfg - g_config->getOption("SDL.Sound.Rate", &cfgBuf); - for(int i=0; i<5; i++) - if(cfgBuf == rates[i]) - gtk_combo_box_set_active(GTK_COMBO_BOX(rateCombo), i); - - g_signal_connect(rateCombo, "changed", G_CALLBACK(setRate), NULL); - - - // sound rate widgets - rateLbl = gtk_label_new("Rate (Hz): "); - - gtk_box_pack_start(GTK_BOX(hbox2), rateLbl, FALSE, FALSE, 5); - gtk_box_pack_start(GTK_BOX(hbox2), rateCombo, FALSE, FALSE, 5); - - hbox3 = gtk_hbox_new(FALSE, 2); - bufferHscale = gtk_hscale_new_with_range(15, 200, 2); - bufferLbl = gtk_label_new("Buffer size (in ms)"); - - // sync widget with cfg - g_config->getOption("SDL.Sound.BufSize", &cfgBuf); - gtk_range_set_value(GTK_RANGE(bufferHscale), cfgBuf); - - g_signal_connect(bufferHscale, "button-release-event", G_CALLBACK(setBufSize), NULL); - - - // mixer - mixerFrame = gtk_frame_new("Mixer:"); - mixerHbox = gtk_hbox_new(TRUE, 5); - for(int i=0; i<6; i++) - { - mixers[i] = gtk_vscale_new_with_range(0, 256, 1); - gtk_range_set_inverted(GTK_RANGE(mixers[i]), TRUE); - mixerFrames[i] = gtk_frame_new(mixerStrings[i]); - gtk_container_add(GTK_CONTAINER(mixerFrames[i]), mixers[i]); - gtk_box_pack_start(GTK_BOX(mixerHbox), mixerFrames[i], FALSE, TRUE, 5); - g_signal_connect(mixers[i], "button-release-event", G_CALLBACK(mixerChanged), (gpointer)i); - } - - // sync with cfg - int v; - g_config->getOption("SDL.Sound.Volume", &v); - gtk_range_set_value(GTK_RANGE(mixers[0]), v); - g_config->getOption("SDL.Sound.TriangleVolume", &v); - gtk_range_set_value(GTK_RANGE(mixers[1]), v); - g_config->getOption("SDL.Sound.Square1Volume", &v); - gtk_range_set_value(GTK_RANGE(mixers[2]), v); - g_config->getOption("SDL.Sound.Square2Volume", &v); - gtk_range_set_value(GTK_RANGE(mixers[3]), v); - g_config->getOption("SDL.Sound.NoiseVolume", &v); - gtk_range_set_value(GTK_RANGE(mixers[4]), v); - g_config->getOption("SDL.Sound.PCMVolume", &v); - gtk_range_set_value(GTK_RANGE(mixers[5]), v); - - - // packing some boxes - - gtk_box_pack_start(GTK_BOX(main_hbox), vbox, FALSE, TRUE, 5); - gtk_box_pack_start(GTK_BOX(vbox), soundChk, FALSE, FALSE, 5); - gtk_box_pack_start(GTK_BOX(vbox), lowpassChk, FALSE, FALSE, 5); - gtk_box_pack_start(GTK_BOX(vbox), hbox1, FALSE, FALSE, 5); - gtk_box_pack_start(GTK_BOX(vbox), hbox2, FALSE, FALSE, 5); - gtk_box_pack_start(GTK_BOX(vbox), bufferLbl, FALSE, FALSE, 5); - gtk_box_pack_start(GTK_BOX(vbox), bufferHscale, FALSE, TRUE, 5); - gtk_box_pack_start(GTK_BOX(main_hbox), mixerFrame, TRUE, TRUE, 5); - gtk_container_add(GTK_CONTAINER(mixerFrame), mixerHbox); - - gtk_container_add(GTK_CONTAINER(win), main_hbox); - - gtk_widget_show_all(win); - - return; -} - -void quit () -{ - FCEUI_Kill(); - SDL_Quit(); - gtk_main_quit(); - exit(0); -} - -void showAbout () -{ - GtkWidget* aboutDialog; - - aboutDialog = gtk_about_dialog_new (); - gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(aboutDialog), "About fceuX"); - gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(aboutDialog), "fceuX"); - gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(aboutDialog), FCEU_VERSION_STRING); - gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(aboutDialog), "GPL-2; See COPYING"); - gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(aboutDialog), "http://fceux.com"); - - - gtk_dialog_run(GTK_DIALOG(aboutDialog)); - gtk_widget_hide_all(aboutDialog); - -} - -void toggleSound(GtkWidget* check, gpointer data) -{ - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check))) - { - g_config->setOption("SDL.Sound", 1); - InitSound(); - } - else - { - g_config->setOption("SDL.Sound", 0); - KillSound(); - } -} - -void emuReset () -{ - if(isloaded) - ResetNES(); -} - -void emuPause () -{ - if(isloaded) - FCEUI_SetEmulationPaused(1); -} -void emuResume () -{ - if(isloaded) - FCEUI_SetEmulationPaused(0); -} - -void enableFullscreen () -{ - if(isloaded) - ToggleFS(); -} -void recordMovie() -{ - char* movie_fname = const_cast(FCEU_MakeFName(FCEUMKF_MOVIE, 0, 0).c_str()); - FCEUI_printf("Recording movie to %s\n", movie_fname); - FCEUI_SaveMovie(movie_fname, MOVIE_FLAG_NONE, L""); - - return; -} -void recordMovieAs () -{ - GtkWidget* fileChooser; - - GtkFileFilter* filterFm2; - GtkFileFilter* filterAll; - - filterFm2 = gtk_file_filter_new(); - gtk_file_filter_add_pattern(filterFm2, "*.fm2"); - gtk_file_filter_set_name(filterFm2, "FM2 Movies"); - - filterAll = gtk_file_filter_new(); - gtk_file_filter_add_pattern(filterAll, "*"); - gtk_file_filter_set_name(filterAll, "All Files"); - - fileChooser = gtk_file_chooser_dialog_new ("Save FM2 movie for recording", GTK_WINDOW(MainWindow), - GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); - gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(fileChooser), ".fm2"); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterFm2); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterAll); - - if (gtk_dialog_run (GTK_DIALOG (fileChooser)) ==GTK_RESPONSE_ACCEPT) - { - std::string fname; - - fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); - if (!fname.size()) - return; // no filename selected, quit the whole thing - - std::string s = GetUserText("Author name"); - std::wstring author(s.begin(), s.end()); - - - FCEUI_SaveMovie(fname.c_str(), MOVIE_FLAG_FROM_POWERON, author); - } - gtk_widget_destroy (fileChooser); -} - -void loadMovie () -{ - GtkWidget* fileChooser; - - GtkFileFilter* filterFm2; - GtkFileFilter* filterAll; - - filterFm2 = gtk_file_filter_new(); - gtk_file_filter_add_pattern(filterFm2, "*.fm2"); - gtk_file_filter_add_pattern(filterFm2, "*.FM2f"); - gtk_file_filter_set_name(filterFm2, "FM2 Movies"); - - filterAll = gtk_file_filter_new(); - gtk_file_filter_add_pattern(filterAll, "*"); - gtk_file_filter_set_name(filterAll, "All Files"); - - fileChooser = gtk_file_chooser_dialog_new ("Open FM2 Movie", GTK_WINDOW(MainWindow), - GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); - - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterFm2); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterAll); - - if (gtk_dialog_run (GTK_DIALOG (fileChooser)) ==GTK_RESPONSE_ACCEPT) - { - char* fname; - - fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); - static int pauseframe; - g_config->getOption("SDL.PauseFrame", &pauseframe); - g_config->setOption("SDL.PauseFrame", 0); - FCEUI_printf("Playing back movie located at %s\n", fname); - if(FCEUI_LoadMovie(fname, false, false, pauseframe ? pauseframe : false) == FALSE) - { - GtkWidget* d; - d = gtk_message_dialog_new(GTK_WINDOW(MainWindow), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, - "Could not open the selected FM2 file."); - gtk_dialog_run(GTK_DIALOG(d)); - gtk_widget_destroy(d); - } - } - gtk_widget_destroy (fileChooser); -} - -#ifdef _S9XLUA_H -void loadLua () -{ - GtkWidget* fileChooser; - GtkFileFilter* filterLua; - GtkFileFilter* filterAll; - - filterLua = gtk_file_filter_new(); - gtk_file_filter_add_pattern(filterLua, "*.lua"); - gtk_file_filter_add_pattern(filterLua, "*.LUA"); - gtk_file_filter_set_name(filterLua, "Lua scripts"); - - filterAll = gtk_file_filter_new(); - gtk_file_filter_add_pattern(filterAll, "*"); - gtk_file_filter_set_name(filterAll, "All Files"); - - fileChooser = gtk_file_chooser_dialog_new ("Open LUA Script", GTK_WINDOW(MainWindow), - GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); - - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterLua); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterAll); - - if (gtk_dialog_run (GTK_DIALOG (fileChooser)) ==GTK_RESPONSE_ACCEPT) - { - char* filename; - - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); - gtk_widget_destroy(fileChooser); - if(FCEU_LoadLuaCode(filename) == 0) - { - GtkWidget* d; - d = gtk_message_dialog_new(GTK_WINDOW(MainWindow), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, - "Could not open the selected lua script."); - gtk_dialog_run(GTK_DIALOG(d)); - gtk_widget_destroy(d); - } - g_free(filename); - } - else - gtk_widget_destroy (fileChooser); -} -#endif - - -void loadFdsBios () -{ - GtkWidget* fileChooser; - GtkFileFilter* filterDiskSys; - GtkFileFilter* filterRom; - GtkFileFilter* filterAll; - - - filterDiskSys = gtk_file_filter_new(); - gtk_file_filter_add_pattern(filterDiskSys, "disksys.rom"); - gtk_file_filter_set_name(filterDiskSys, "FDS BIOS"); - - filterRom = gtk_file_filter_new(); - gtk_file_filter_add_pattern(filterRom, "*.rom"); - gtk_file_filter_set_name(filterRom, "*.rom"); - - filterAll = gtk_file_filter_new(); - gtk_file_filter_add_pattern(filterAll, "*"); - gtk_file_filter_set_name(filterAll, "All Files"); - - - fileChooser = gtk_file_chooser_dialog_new ("Load FDS BIOS (disksys.rom)", GTK_WINDOW(MainWindow), - GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterDiskSys); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterRom); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterAll); - - if (gtk_dialog_run (GTK_DIALOG (fileChooser)) ==GTK_RESPONSE_ACCEPT) - { - char* filename; - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); - // copy BIOS file to proper place (~/.fceux/disksys.rom) - std::ifstream f1 (filename,std::fstream::binary); - std::string fn_out = FCEU_MakeFName(FCEUMKF_FDSROM, 0, ""); - std::ofstream f2 (fn_out.c_str(),std::fstream::trunc|std::fstream::binary); - gtk_widget_destroy (fileChooser); - GtkWidget* d; - d = gtk_message_dialog_new(GTK_WINDOW(MainWindow), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, - "Famicom Disk System BIOS loaded. If you are you having issues, make sure your BIOS file is 8KB in size."); - gtk_dialog_run(GTK_DIALOG(d)); - gtk_widget_destroy(d); - - f2<width, event->height, 0, 0); - - return TRUE; -} - -void saveStateAs() -{ - GtkWidget* fileChooser; - GtkFileFilter* filterSav; - GtkFileFilter* filterAll; - - filterSav = gtk_file_filter_new(); - gtk_file_filter_add_pattern(filterSav, "*.sav"); - gtk_file_filter_add_pattern(filterSav, "*.SAV"); - gtk_file_filter_set_name(filterSav, "SAV files"); - - filterAll = gtk_file_filter_new(); - gtk_file_filter_add_pattern(filterAll, "*"); - gtk_file_filter_set_name(filterAll, "All Files"); - - fileChooser = gtk_file_chooser_dialog_new ("Save State As", GTK_WINDOW(MainWindow), - GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); - gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(fileChooser), ".sav"); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterSav); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterAll); - - if (gtk_dialog_run (GTK_DIALOG (fileChooser)) ==GTK_RESPONSE_ACCEPT) - { - char* filename; - - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); - FCEUI_SaveState(filename); - g_free(filename); - } - gtk_widget_destroy (fileChooser); - - -} - -void loadStateFrom() -{ - GtkWidget* fileChooser; - GtkFileFilter* filterSav; - GtkFileFilter* filterAll; - - filterSav = gtk_file_filter_new(); - gtk_file_filter_add_pattern(filterSav, "*.sav"); - gtk_file_filter_add_pattern(filterSav, "*.SAV"); - gtk_file_filter_set_name(filterSav, "SAV files"); - - filterAll = gtk_file_filter_new(); - gtk_file_filter_add_pattern(filterAll, "*"); - gtk_file_filter_set_name(filterAll, "All Files"); - - fileChooser = gtk_file_chooser_dialog_new ("Load State From", GTK_WINDOW(MainWindow), - GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterSav); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterAll); - - if (gtk_dialog_run (GTK_DIALOG (fileChooser)) ==GTK_RESPONSE_ACCEPT) - { - char* filename; - - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); - FCEUI_LoadState(filename); - g_free(filename); - } - gtk_widget_destroy (fileChooser); - - -} - - -/* Our menu, an array of GtkItemFactoryEntry structures that defines each menu item */ -static GtkItemFactoryEntry menu_items[] = { - { "/_File", NULL, NULL, 0, "" }, - //{ "/File/_New", "N", NULL, 0, "", GTK_STOCK_NEW }, - { "/File/_Open ROM", "O", loadGame, 0, "", GTK_STOCK_OPEN }, - { "/File/_Close ROM", "C", closeGame, 0, "", GTK_STOCK_CLOSE }, - // { "/File/Save _As", NULL, NULL, 0, "" }, - { "/File/sep1", NULL, NULL, 0, "" }, - { "/File/_Play NSF", "N", loadNSF, 0, "", GTK_STOCK_OPEN }, - { "/File/sep2", NULL, NULL, 0, "" }, - { "/File/Savestate", NULL, NULL, 0, "" }, - { "/File/Savestate/Load State _From", NULL, loadStateFrom, 0, ""}, - { "/File/Savestate/Save State _As", NULL, saveStateAs, 0, ""}, -#ifdef _S9XLUA_H - { "/File/Load _Lua Script", NULL, loadLua, 0, ""}, -#endif - { "/File/sep3", NULL, NULL, 0, "" }, - { "/File/_Screenshot", "F12", FCEUI_SaveSnapshot, 0, ""}, - { "/File/sep2", NULL, NULL, 0, "" }, - { "/File/_Quit", "Q", quit, 0, "", GTK_STOCK_QUIT }, - { "/_Options", NULL, NULL, 0, "" }, - { "/_Emulator", NULL, NULL, 0, "" }, - { "/Emulator/P_ower", NULL, FCEUI_PowerNES, 0, ""}, - { "/Emulator/_Reset", NULL, emuReset, 0, ""}, - { "/Emulator/_Pause", NULL, emuPause, 0, ""}, - { "/Emulator/R_esume", NULL, emuResume, 0, ""}, - { "/Emulator/_FDS", NULL, NULL, 0, ""}, - { "/Emulator/_FDS/_Switch Disk", NULL, FCEU_FDSSelect, 0, ""}, - { "/Emulator/_FDS/_Eject Disk", NULL, FCEU_FDSInsert, 0, ""}, - { "/Emulator/_FDS/Load _BIOS File", NULL, loadFdsBios, 0, ""}, - { "/Emulator/_Insert coin", NULL, FCEUI_VSUniCoin, 0, ""}, - //{ "/Emulator/GTKterm (DEV)", NULL, openGTKterm, 0, ""}, - { "/_Movie", NULL, NULL, 0, "" }, - { "/Movie/_Open", NULL, loadMovie, 0, ""}, - { "/Movie/S_top", NULL, FCEUI_StopMovie, 0, ""}, - { "/Movie/_Pause", NULL, emuPause, 0, ""}, - { "/Movie/R_esume", NULL, emuResume, 0, ""}, - { "/Movie/sep2", NULL, NULL, 0, "" }, - { "/Movie/_Record", NULL, recordMovie, 0, ""}, - { "/Movie/Record _as", NULL, recordMovieAs, 0, ""}, - { "/Options/_Gamepad Config", NULL , openGamepadConfig, 0, "", GTK_STOCK_PREFERENCES }, - { "/Options/_Sound Config", NULL , openSoundConfig, 0, "" }, - { "/Options/_Video Config", NULL , openVideoConfig, 0, "" }, - { "/Options/_Palette Config", NULL , openPaletteConfig, 0, "" }, - { "/Options/_Network Config", NULL , openNetworkConfig, 0, "" }, - //{ "/Options/Map _Hotkeys", NULL , openHotkeyConfig, 0, "" }, - { "/Options/sep1", NULL, NULL, 0, "" }, - { "/Options/_Fullscreen", NULL, enableFullscreen, 0, "" }, - { "/_Help", NULL, NULL, 0, "" }, - { "/Help/About", NULL, showAbout, 0, "" }, -}; - -static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]); - -static GtkWidget* CreateMenubar( GtkWidget* window) -{ - GtkItemFactory *item_factory; - GtkAccelGroup *accel_group; - - /* Make an accelerator group (shortcut keys) */ - accel_group = gtk_accel_group_new (); - - /* Make an ItemFactory (that makes a menubar) */ - item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "
", accel_group); - - /* This function generates the menu items. Pass the item factory, - the number of items in the array, the array itself, and any - callback data for the the menu items. */ - gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL); - - /* Attach the new accelerator group to the window. */ - gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); - - /* Finally, return the actual menu bar created by the item factory. */ - return gtk_item_factory_get_widget (item_factory, "
"); -} -//GtkTextBuffer* gtkConsoleBuf; -//GtkWidget* consoleOutput; -//GtkTextIter iter; -char* buf; -//GtkWidget* term; - -void pushOutputToGTK(const char* str) -{ - - //printf(str); - //gtk_text_buffer_insert(GTK_TEXT_BUFFER(gtkConsoleBuf), &iter, str, -1); - //gtk_text_buffer_set_text(gtkConsoleBuf, str, -1); - - //vte_terminal_feed_child(VTE_TERMINAL(term), str, -1); - return; -} - -void showGui(bool b) -{ - if(b) - gtk_widget_show_all(MainWindow); - else - gtk_widget_hide_all(MainWindow); -} - -int InitGTKSubsystem(int argc, char** argv) -{ - GtkWidget* Menubar; - GtkWidget* vbox; - - MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(MainWindow), FCEU_NAME_AND_VERSION); - gtk_window_set_default_size(GTK_WINDOW(MainWindow), 359, 200); - - vbox = gtk_vbox_new(FALSE, 3); - gtk_container_add(GTK_CONTAINER(MainWindow), vbox); - - Menubar = CreateMenubar(MainWindow); - - //consoleOutput = gtk_text_view_new_with_buffer(gtkConsoleBuf); - //gtk_text_view_set_editable(GTK_TEXT_VIEW(consoleOutput), FALSE); - - //gtkConsoleBuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(consoleOutput)); - //gtk_text_buffer_get_iter_at_offset(gtkConsoleBuf, &iter, 0); - //gtk_text_buffer_insert(gtkConsoleBuf, &iter, "FceuX GUI Started.\n", -1); - // = vte_terminal_new(); - //vte_terminal_feed(VTE_TERMINAL(term), "FceuX GUI Started", -1); - - - - - //gtk_container_add(GTK_CONTAINER(vbox), Menubar); - gtk_box_pack_start (GTK_BOX(vbox), Menubar, FALSE, TRUE, 0); - //gtk_box_pack_start (GTK_BOX(vbox), term, TRUE, TRUE, 0); - - - - - // broken SDL embedding code - //gtk_widget_set_usize(MainWindow, xres, yres); - //gtk_widget_realize(MainWindow); - - // event handlers - //gtk_widget_add_events(MainWindow, GDK_BUTTON_PRESS_MASK); - //gtk_signal_connect(GTK_OBJECT(MainWindow), "configure_event", - // GTK_SIGNAL_FUNC(configureEvent), 0); - - - // PRG: this code here is the the windowID "hack" to render SDL - // in a GTK window. however, I can't get it to work right now - // so i'm commenting it out and haivng a seperate GTK2 window with - // controls - // 12/21/09 - /* - GtkWidget* socket = gtk_socket_new(); - gtk_widget_show (socket) ; - gtk_container_add (GTK_CONTAINER(MainWindow), socket); - - gtk_widget_realize (socket); - - char SDL_windowhack[24]; - sprintf(SDL_windowhack, "SDL_WINDOWID=%ld", (long int)gtk_socket_get_id (GTK_SOCKET(socket))); - putenv(SDL_windowhack); - - - // init SDL - if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) - { - fprintf(stderr, "Couldn't init SDL: %s\n", SDL_GetError()); - gtk_main_quit(); - } - - - - // test rendering - //screen = SDL_SetVideoMode(xres, yres, 0, 0); - //hello = SDL_LoadBMP( "hello.bmp" ); - */ - g_signal_connect(MainWindow, "destroy-event", quit, NULL); - - //gtk_idle_add(mainLoop, MainWindow); - // signal handlers - g_signal_connect(MainWindow, "delete-event", quit, NULL); - - - gtk_widget_show_all(MainWindow); - - return 0; -} - +#include +#include + +#include + +#include +#include +#include + +#include "../../types.h" +#include "../../fceu.h" +#include "../../driver.h" +#include "../../version.h" +#include "../../movie.h" +#include "../../palette.h" +#include "../../fds.h" + + +#include "../common/configSys.h" +#include "sdl.h" +#include "gui.h" +#include "dface.h" +#include "input.h" +#include "config.h" + +#ifdef _S9XLUA_H +#include "../../fceulua.h" +#endif + +void toggleSound(GtkWidget* check, gpointer data); +void loadGame (); + +extern Config *g_config; + +GtkWidget* MainWindow = NULL; +GtkWidget* padNoCombo; + +// This function configures a single button on a gamepad +int configGamepadButton(GtkButton* button, gpointer p) +{ + int x = GPOINTER_TO_INT(p); + int padNo = 0; + char* padStr = gtk_combo_box_get_active_text(GTK_COMBO_BOX(padNoCombo)); + + if(!strcmp(padStr, "1")) + padNo = 0; + if(!strcmp(padStr, "2")) + padNo = 1; + if(!strcmp(padStr, "3")) + padNo = 2; + if(!strcmp(padStr, "4")) + padNo = 3; + + char buf[256]; + std::string prefix; + + ButtonConfigBegin(); + + snprintf(buf, 256, "SDL.Input.GamePad.%d", padNo); + prefix = buf; + ConfigButton((char*)GamePadNames[x], &GamePadConfig[padNo][x]); + + g_config->setOption(prefix + GamePadNames[x], GamePadConfig[padNo][x].ButtonNum[0]); + + if(GamePadConfig[padNo][x].ButtType[0] == BUTTC_KEYBOARD) + { + g_config->setOption(prefix + "DeviceType", "Keyboard"); + } else if(GamePadConfig[padNo][x].ButtType[0] == BUTTC_JOYSTICK) { + g_config->setOption(prefix + "DeviceType", "Joystick"); + } else { + g_config->setOption(prefix + "DeviceType", "Unknown"); + } + g_config->setOption(prefix + "DeviceNum", GamePadConfig[padNo][0].DeviceNum[0]); + + ButtonConfigEnd(); + + return 0; +} + +void toggleLowPass(GtkWidget* w, gpointer p) +{ + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) + { + g_config->setOption("SDL.Sound.LowPass", 1); + FCEUI_SetLowPass(1); + } + else + { + g_config->setOption("SDL.Sound.LowPass", 0); + FCEUI_SetLowPass(0); + } + g_config->save(); + +} + +// Wrapper for pushing GTK options into the config file +// p : pointer to the string that names the config option +// w : toggle widget +void toggleOption(GtkWidget* w, gpointer p) +{ + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) + g_config->setOption((char*)p, 1); + else + g_config->setOption((char*)p, 0); + g_config->save(); +} + +int setTint(GtkWidget* w, gpointer p) +{ + int v = gtk_range_get_value(GTK_RANGE(w)); + g_config->setOption("SDL.Tint", v); + g_config->save(); + int c, h; + g_config->getOption("SDL.NTSCpalette", &c); + g_config->getOption("SDL.Hue", &h); + FCEUI_SetNTSCTH(c, v, h); + + return 0; +} +int setHue(GtkWidget* w, gpointer p) +{ + int v = gtk_range_get_value(GTK_RANGE(w)); + g_config->setOption("SDL.Hue", v); + g_config->save(); + int c, t; + g_config->getOption("SDL.Tint", &t); + g_config->getOption("SDL.SDL.NTSCpalette", &c); + FCEUI_SetNTSCTH(c, t, v); + + return 0; +} +void loadPalette (GtkWidget* w, gpointer p) +{ + GtkWidget* fileChooser; + + fileChooser = gtk_file_chooser_dialog_new ("Open NES Palette", GTK_WINDOW(MainWindow), + GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); + + if (gtk_dialog_run (GTK_DIALOG (fileChooser)) ==GTK_RESPONSE_ACCEPT) + { + char* filename; + + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); + g_config->setOption("SDL.Palette", filename); + g_config->setOption("SDL.SDL.NTSCpalette", 0); + if(LoadCPalette(filename) == 0) + { + GtkWidget* msgbox; + msgbox = gtk_message_dialog_new(GTK_WINDOW(MainWindow), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, + "Failed to load the palette."); + + gtk_dialog_run(GTK_DIALOG(msgbox)); + gtk_widget_hide_all(msgbox); + } + + gtk_entry_set_text(GTK_ENTRY(p), filename); + + } + gtk_widget_destroy (fileChooser); +} + +void clearPalette(GtkWidget* w, gpointer p) +{ + g_config->setOption("SDL.Palette", 0); + gtk_entry_set_text(GTK_ENTRY(p), ""); +} + +void openPaletteConfig() +{ + GtkWidget* win; + GtkWidget* vbox; + GtkWidget* paletteFrame; + GtkWidget* paletteHbox; + GtkWidget* paletteButton; + GtkWidget* paletteEntry; + GtkWidget* clearButton; + GtkWidget* ntscColorChk; + GtkWidget* slidersFrame; + GtkWidget* slidersVbox; + GtkWidget* tintFrame; + GtkWidget* tintHscale; + GtkWidget* hueFrame; + GtkWidget* hueHscale; + + win = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(win),"Palette Options"); + vbox = gtk_vbox_new(FALSE, 5); + gtk_container_add(GTK_CONTAINER(win), vbox); + + gtk_widget_set_size_request(win, 460, 275); + + paletteFrame = gtk_frame_new("Custom palette: "); + paletteHbox = gtk_hbox_new(FALSE, 5); + gtk_container_set_border_width(GTK_CONTAINER(paletteHbox), 5); + gtk_container_add(GTK_CONTAINER(paletteFrame), paletteHbox); + paletteButton = gtk_button_new_from_stock(GTK_STOCK_OPEN); + gtk_button_set_label(GTK_BUTTON(paletteButton), "Open palette"); + paletteEntry = gtk_entry_new(); + gtk_entry_set_editable(GTK_ENTRY(paletteEntry), FALSE); + + clearButton = gtk_button_new_from_stock(GTK_STOCK_CLEAR); + + gtk_box_pack_start(GTK_BOX(paletteHbox), paletteButton, FALSE, FALSE, 2); + gtk_box_pack_start(GTK_BOX(paletteHbox), paletteEntry, TRUE, TRUE, 5); + gtk_box_pack_start(GTK_BOX(paletteHbox), clearButton, FALSE, FALSE, 0); + + g_signal_connect(paletteButton, "clicked", G_CALLBACK(loadPalette), paletteEntry); + g_signal_connect(clearButton, "clicked", G_CALLBACK(clearPalette), paletteEntry); + + + + // sync with config + std::string fn; + g_config->getOption("SDL.Palette", &fn); + gtk_entry_set_text(GTK_ENTRY(paletteEntry), fn.c_str()); + + // ntsc color check + + ntscColorChk = gtk_check_button_new_with_label("Use NTSC palette"); + + g_signal_connect(ntscColorChk, "clicked", G_CALLBACK(toggleOption), (gpointer)"SDL.NTSCpalette"); + + int b; + // sync with config + g_config->getOption("SDL.NTSCpalette", &b); + if(b) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ntscColorChk), 1); + else + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ntscColorChk), 0); + + + // color / tint / hue sliders + slidersFrame = gtk_frame_new("NTSC palette controls"); + slidersVbox = gtk_vbox_new(FALSE, 2); + tintFrame = gtk_frame_new("Tint"); + tintHscale = gtk_hscale_new_with_range(0, 128, 1); + gtk_container_add(GTK_CONTAINER(tintFrame), tintHscale); + hueFrame = gtk_frame_new("Hue"); + hueHscale = gtk_hscale_new_with_range(0, 128, 1); + gtk_container_add(GTK_CONTAINER(hueFrame), hueHscale); + + g_signal_connect(tintHscale, "button-release-event", G_CALLBACK(setTint), NULL); + g_signal_connect(hueHscale, "button-release-event", G_CALLBACK(setHue), NULL); + + // sync with config + int h, t; + g_config->getOption("SDL.Hue", &h); + g_config->getOption("SDL.Tint", &t); + + gtk_range_set_value(GTK_RANGE(hueHscale), h); + gtk_range_set_value(GTK_RANGE(tintHscale), t); + + gtk_container_add(GTK_CONTAINER(slidersFrame), slidersVbox); + gtk_box_pack_start(GTK_BOX(slidersVbox), ntscColorChk, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(slidersVbox), tintFrame, FALSE, TRUE, 5); + gtk_box_pack_start(GTK_BOX(slidersVbox), hueFrame, FALSE, TRUE, 5); + + gtk_box_pack_start(GTK_BOX(vbox), paletteFrame, FALSE, TRUE, 5); + + gtk_box_pack_start(GTK_BOX(vbox), slidersFrame, FALSE, TRUE, 5); + + gtk_widget_show_all(win); + + return; +} + +GtkWidget* ipEntry; +GtkWidget* portSpin; +GtkWidget* pwEntry; + +void launchNet(GtkWidget* w, gpointer p) +{ + char* ip = (char*)gtk_entry_get_text(GTK_ENTRY(ipEntry)); + char* pw = (char*)gtk_entry_get_text(GTK_ENTRY(pwEntry)); + int port = (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(portSpin)); + + g_config->setOption("SDL.NetworkIP", ip); + g_config->setOption("SDL.NetworkPassword", pw); + g_config->setOption("SDL.NetworkPort", port); + + gtk_widget_destroy(GTK_WIDGET(p)); + + loadGame(); +} +void closeNet(GtkWidget* w, gpointer p) +{ + gtk_widget_destroy(GTK_WIDGET(p)); +} + +void setUsername(GtkWidget* w, gpointer p) +{ + char* s = (char*)gtk_entry_get_text(GTK_ENTRY(w)); + g_config->setOption("SDL.NetworkUsername", s); +} + +void openNetworkConfig() +{ + GtkWidget* win; + GtkWidget* box; + GtkWidget* userBox; + GtkWidget* userEntry; + GtkWidget* userLbl; + GtkWidget* frame; + GtkWidget* vbox; + GtkWidget* ipBox; + GtkWidget* ipLbl; + + GtkWidget* portBox; + GtkWidget* portLbl; + + //GtkWidget* localPlayersCbo; + GtkWidget* pwBox; + GtkWidget* pwLbl; + + GtkWidget* bb; + GtkWidget* conBtn; + GtkWidget* closeBtn; + + win = gtk_window_new(GTK_WINDOW_TOPLEVEL); + box = gtk_vbox_new(FALSE, 3); + + userBox = gtk_hbox_new(FALSE, 3); + userLbl = gtk_label_new("Username:"); + userEntry = gtk_entry_new(); + std::string s; + g_config->getOption("SDL.NetworkUsername", &s); + gtk_entry_set_text(GTK_ENTRY(userEntry), s.c_str()); + + g_signal_connect(userEntry, "changed", G_CALLBACK(setUsername), NULL); + + + frame = gtk_frame_new("Network options"); + vbox = gtk_vbox_new(FALSE, 5); + ipBox = gtk_hbox_new(FALSE, 5); + ipLbl = gtk_label_new("Server IP:"); + ipEntry = gtk_entry_new(); + portBox = gtk_hbox_new(FALSE, 5); + portLbl = gtk_label_new("Server port:"); + portSpin = gtk_spin_button_new_with_range(0, 999999, 1); + //localPlayersCbo = gtk_combo_box_new_text(); + pwBox = gtk_hbox_new(FALSE, 3); + pwLbl = gtk_label_new("Server password:"); + pwEntry = gtk_entry_new(); + bb = gtk_hbox_new(FALSE, 5); + conBtn = gtk_button_new_from_stock(GTK_STOCK_CONNECT); + closeBtn = gtk_button_new_from_stock(GTK_STOCK_CLOSE); + + gtk_spin_button_set_value(GTK_SPIN_BUTTON(portSpin), 4046); + + gtk_box_pack_start(GTK_BOX(userBox), userLbl, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(userBox), userEntry, TRUE , TRUE, 3); + + gtk_box_pack_start(GTK_BOX(portBox), portLbl, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(portBox), portSpin, FALSE , FALSE, 3); + + gtk_box_pack_start(GTK_BOX(ipBox), ipLbl, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(ipBox), ipEntry, TRUE , TRUE, 3); + + gtk_box_pack_start(GTK_BOX(pwBox), pwLbl, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(pwBox), pwEntry, TRUE , TRUE, 3); + + gtk_box_pack_start_defaults(GTK_BOX(vbox), ipBox); + gtk_box_pack_start_defaults(GTK_BOX(vbox), portBox); + //gtk_box_pack_start_defaults(GTK_BOX(vbox), localPlayersCbo); + gtk_box_pack_start_defaults(GTK_BOX(vbox), pwBox); + + gtk_container_add(GTK_CONTAINER(frame), vbox); + + gtk_box_pack_start_defaults(GTK_BOX(box), userBox); + gtk_box_pack_start_defaults(GTK_BOX(box), frame); + gtk_box_pack_start(GTK_BOX(bb), closeBtn, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(bb), conBtn, FALSE, FALSE, 5); + + gtk_box_pack_start_defaults(GTK_BOX(box), bb); + gtk_container_add(GTK_CONTAINER(win), box); + + gtk_widget_show_all(win); + + g_signal_connect(closeBtn, "clicked", G_CALLBACK(closeNet), win); + g_signal_connect(conBtn, "clicked", G_CALLBACK(launchNet), win); +} + +// creates and opens hotkey config window +/*void openHotkeyConfig() +{ + std::string prefix = "SDL.Hotkeys."; + GtkWidget* win = gtk_window_new(GTK_WINDOW_TOPLEVEL); + enum + { + COMMAND_COLUMN, + KEY_COLUMN, + N_COLUMNS + }; + GtkListStore* store = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING); + GtkTreeIter iter; + + gtk_list_store_append(store, &iter); // aquire iter + + + int buf; + for(int i=0; igetOption(prefix + HotkeyStrings[i], &buf); + gtk_list_store_set(store, &iter, + COMMAND_COLUMN, prefix + HotkeyStrings[i], + KEY_COLUMN, "TODO", -1); + } + GtkWidget* tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Command", renderer, "text", 0, NULL); + gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); + + gtk_container_add(GTK_CONTAINER(win),tree); + gtk_widget_show_all(win); +}*/ +GtkWidget* typeCombo; + +// TODO: finish this +int setInputDevice(GtkWidget* w, gpointer p) +{ + std::string s = "SDL.Input."; + s = s + (char*)p; + printf("%s", s.c_str()); + g_config->setOption(s, gtk_combo_box_get_active_text(GTK_COMBO_BOX(typeCombo))); + g_config->save(); + + return 1; +} + +// creates and opens the gamepad config window +void openGamepadConfig() +{ + GtkWidget* win; + GtkWidget* vbox; + GtkWidget* hboxPadNo; + GtkWidget* padNoLabel; + GtkWidget* fourScoreChk; + + GtkWidget* buttons[10]; + + win = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(win), "Gamepad Config"); + gtk_widget_set_size_request(win, 250, 500); + vbox = gtk_vbox_new(TRUE, 4); + hboxPadNo = gtk_hbox_new(FALSE, 5); + padNoLabel = gtk_label_new("Gamepad Number:"); + fourScoreChk = gtk_check_button_new_with_label("Enable four score"); + + typeCombo = gtk_combo_box_new_text(); + gtk_combo_box_append_text(GTK_COMBO_BOX(typeCombo), "gamepad"); + gtk_combo_box_append_text(GTK_COMBO_BOX(typeCombo), "zapper"); + gtk_combo_box_append_text(GTK_COMBO_BOX(typeCombo), "powerpad.0"); + gtk_combo_box_append_text(GTK_COMBO_BOX(typeCombo), "powerpad.1"); + gtk_combo_box_append_text(GTK_COMBO_BOX(typeCombo), "arkanoid"); + + gtk_combo_box_set_active(GTK_COMBO_BOX(typeCombo), 0); + + + padNoCombo = gtk_combo_box_new_text(); + gtk_combo_box_append_text(GTK_COMBO_BOX(padNoCombo), "1"); + gtk_combo_box_append_text(GTK_COMBO_BOX(padNoCombo), "2"); + gtk_combo_box_append_text(GTK_COMBO_BOX(padNoCombo), "3"); + gtk_combo_box_append_text(GTK_COMBO_BOX(padNoCombo), "4"); + + gtk_combo_box_set_active(GTK_COMBO_BOX(padNoCombo), 0); + + g_signal_connect(GTK_OBJECT(typeCombo), "changed", G_CALLBACK(setInputDevice), + gtk_combo_box_get_active_text(GTK_COMBO_BOX(typeCombo))); + + // sync with config + int buf = 0; + g_config->getOption("SDL.FourScore", &buf); + if(buf) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fourScoreChk), 1); + else + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fourScoreChk), 0); + + g_signal_connect(GTK_OBJECT(fourScoreChk), "clicked", G_CALLBACK(toggleOption), (gpointer)"SDL.FourScore"); + + gtk_box_pack_start(GTK_BOX(hboxPadNo), padNoLabel, TRUE, TRUE, 5); + gtk_box_pack_start(GTK_BOX(hboxPadNo), padNoCombo, TRUE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(vbox), hboxPadNo, TRUE, TRUE, 5); + //gtk_box_pack_start_defaults(GTK_BOX(vbox), typeCombo); + + gtk_box_pack_start(GTK_BOX(vbox), fourScoreChk, TRUE, TRUE, 5); + // create gamepad buttons + for(int i=0; i<10; i++) + { + buttons[i] = gtk_button_new_with_label(GamePadNames[i]); + gtk_box_pack_start(GTK_BOX(vbox), buttons[i], TRUE, TRUE, 3); + gtk_signal_connect(GTK_OBJECT(buttons[i]), "clicked", G_CALLBACK(configGamepadButton), GINT_TO_POINTER(i)); + } + + gtk_container_add(GTK_CONTAINER(win), vbox); + + gtk_widget_show_all(win); + + return; +} + +int setBufSize(GtkWidget* w, gpointer p) +{ + int x = gtk_range_get_value(GTK_RANGE(w)); + g_config->setOption("SDL.Sound.BufSize", x); + // reset sound subsystem for changes to take effect + KillSound(); + InitSound(); + g_config->save(); + return false; +} + +void setRate(GtkWidget* w, gpointer p) +{ + char* str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(w)); + g_config->setOption("SDL.Sound.Rate", atoi(str)); + // reset sound subsystem for changes to take effect + KillSound(); + InitSound(); + g_config->save(); + return; +} + +void setQuality(GtkWidget* w, gpointer p) +{ + char* str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(w)); + if(!strcmp(str, "Very High")) + g_config->setOption("SDL.Sound.Quality", 2); + if(!strcmp(str, "High")) + g_config->setOption("SDL.Sound.Quality", 1); + if(!strcmp(str, "Low")) + g_config->setOption("SDL.Sound.Quality", 0); + // reset sound subsystem for changes to take effect + KillSound(); + InitSound(); + g_config->save(); + return; +} + +void setScaler(GtkWidget* w, gpointer p) +{ + int x = gtk_combo_box_get_active(GTK_COMBO_BOX(w)); + g_config->setOption("SDL.SpecialFilter", x); + g_config->save(); +} + + +int setXscale(GtkWidget* w, gpointer p) +{ + double v = gtk_spin_button_get_value(GTK_SPIN_BUTTON(w)); + g_config->setOption("SDL.XScale", v); + g_config->save(); + return 0; +} + +int setYscale(GtkWidget* w, gpointer p) +{ + double v = gtk_spin_button_get_value(GTK_SPIN_BUTTON(w)); + g_config->setOption("SDL.YScale", v); + g_config->save(); + return 0; +} + +void setGl(GtkWidget* w, gpointer p) +{ + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) + g_config->setOption("SDL.OpenGL", 1); + else + g_config->setOption("SDL.OpenGL", 0); + g_config->save(); +} + + +void openVideoConfig() +{ + GtkWidget* win; + GtkWidget* vbox; + GtkWidget* lbl; + GtkWidget* hbox1; + GtkWidget* scalerLbl; + GtkWidget* scalerCombo; + GtkWidget* glChk; + GtkWidget* palChk; + GtkWidget* ppuChk; + GtkWidget* xscaleSpin; + GtkWidget* yscaleSpin; + GtkWidget* xscaleLbl; + GtkWidget* yscaleLbl; + GtkWidget* xscaleHbox; + GtkWidget* yscaleHbox; + + + win = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(win), "Video Preferences"); + //gtk_widget_set_size_request(win, 250, 250); + + vbox = gtk_vbox_new(FALSE, 5); + + lbl = gtk_label_new("Video options will not take\neffect until the emulator is restarted."); + + // scalar widgets + hbox1 = gtk_hbox_new(FALSE, 3); + scalerLbl = gtk_label_new("Special Scaler: "); + scalerCombo = gtk_combo_box_new_text(); + // -Video Modes Tag- + gtk_combo_box_append_text(GTK_COMBO_BOX(scalerCombo), "none"); + gtk_combo_box_append_text(GTK_COMBO_BOX(scalerCombo), "hq2x"); + gtk_combo_box_append_text(GTK_COMBO_BOX(scalerCombo), "scale2x"); + gtk_combo_box_append_text(GTK_COMBO_BOX(scalerCombo), "NTSC 2x"); + gtk_combo_box_append_text(GTK_COMBO_BOX(scalerCombo), "hq3x"); + gtk_combo_box_append_text(GTK_COMBO_BOX(scalerCombo), "scale3x"); + + // sync with cfg + int buf; + g_config->getOption("SDL.SpecialFilter", &buf); + gtk_combo_box_set_active(GTK_COMBO_BOX(scalerCombo), buf); + + g_signal_connect(GTK_OBJECT(scalerCombo), "changed", G_CALLBACK(setScaler), NULL); + gtk_box_pack_start(GTK_BOX(hbox1), scalerLbl, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(hbox1), scalerCombo, FALSE, FALSE, 5); + + // openGL check + glChk = gtk_check_button_new_with_label("Enable OpenGL"); + g_signal_connect(GTK_OBJECT(glChk), "clicked", G_CALLBACK(setGl), (gpointer)scalerCombo); + + // sync with config + g_config->getOption("SDL.OpenGL", &buf); + if(buf) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glChk), 1); + else + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glChk), 0); + + // PAL check + palChk = gtk_check_button_new_with_label("Enable PAL mode"); + g_signal_connect(GTK_OBJECT(palChk), "clicked", G_CALLBACK(toggleOption), (gpointer)"SDL.PAL"); + + // sync with config + g_config->getOption("SDL.PAL", &buf); + if(buf) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(palChk), 1); + else + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(palChk), 0); + + // New PPU check + ppuChk = gtk_check_button_new_with_label("Enable new PPU"); + g_signal_connect(GTK_OBJECT(ppuChk), "clicked", G_CALLBACK(toggleOption), (gpointer)"SDL.NewPPU"); + + // sync with config + buf = 0; + g_config->getOption("SDL.NewPPU", &buf); + if(buf) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ppuChk), 1); + else + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ppuChk), 0); + + // xscale / yscale + xscaleHbox = gtk_hbox_new(FALSE, 5); + xscaleLbl = gtk_label_new("X scaling factor"); + xscaleSpin = gtk_spin_button_new_with_range(1.0, 10.0, .1); + yscaleHbox = gtk_hbox_new(FALSE, 5); + yscaleLbl = gtk_label_new("Y scaling factor"); + yscaleSpin = gtk_spin_button_new_with_range(1.0, 10.0, .1); + + gtk_box_pack_start(GTK_BOX(xscaleHbox), xscaleLbl, FALSE, FALSE, 2); + gtk_box_pack_start(GTK_BOX(xscaleHbox), xscaleSpin, FALSE, FALSE, 2); + gtk_box_pack_start(GTK_BOX(yscaleHbox), yscaleLbl, FALSE, FALSE, 2); + gtk_box_pack_start(GTK_BOX(yscaleHbox), yscaleSpin, FALSE, FALSE, 2); + + g_signal_connect(xscaleSpin, "button-release-event", G_CALLBACK(setXscale), NULL); + g_signal_connect(yscaleSpin, "button-release-event", G_CALLBACK(setYscale), NULL); + + double f; + // sync with config + g_config->getOption("SDL.XScale", &f); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(xscaleSpin), f); + g_config->getOption("SDL.YScale", &f); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(yscaleSpin), f); + + + + gtk_box_pack_start(GTK_BOX(vbox), lbl, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(vbox), hbox1, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(vbox), glChk, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(vbox), palChk, FALSE, FALSE,5); + gtk_box_pack_start(GTK_BOX(vbox), ppuChk, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(vbox), xscaleHbox, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(vbox), yscaleHbox, FALSE, FALSE, 5); + + + gtk_container_add(GTK_CONTAINER(win), vbox); + gtk_widget_show_all(win); + + return; +} +const char* mixerStrings[6] = {"Volume", "Triangle", "Square1", "Square2", "Noise", "PCM"}; + +int mixerChanged(GtkWidget* w, gpointer p) +{ + int v = gtk_range_get_value(GTK_RANGE(w)); + GtkWidget* parent = gtk_widget_get_parent(w); + char* lbl = (char*)gtk_frame_get_label(GTK_FRAME(parent)); + if(strcmp(lbl, "Volume") == 0) + { + g_config->setOption("SDL.Sound.Volume", v); + FCEUI_SetSoundVolume(v); + } + if(strcmp(lbl, "Triangle") == 0) + { + g_config->setOption("SDL.Sound.TriangleVolume", v); + FCEUI_SetTriangleVolume(v); + } + if(strcmp(lbl, "Square1") == 0) + { + g_config->setOption("SDL.Sound.Square1Volume", v); + FCEUI_SetSquare1Volume(v); + } + if(strcmp(lbl, "Square2") == 0) + { + g_config->setOption("SDL.Sound.Square2Volume", v); + FCEUI_SetSquare2Volume(v); + } + if(strcmp(lbl, "Noise") == 0) + { + g_config->setOption("SDL.Sound.NoiseVolume", v); + FCEUI_SetNoiseVolume(v); + } + if(strcmp(lbl, "PCM") == 0) + { + g_config->setOption("SDL.Sound.PCMVolume", v); + FCEUI_SetPCMVolume(v); + } + + return 0; +} + + +void openSoundConfig() +{ + GtkWidget* win; + GtkWidget* main_hbox; + GtkWidget* vbox; + GtkWidget* soundChk; + GtkWidget* lowpassChk; + GtkWidget* hbox1; + GtkWidget* qualityCombo; + GtkWidget* qualityLbl; + GtkWidget* hbox2; + GtkWidget* rateCombo; + GtkWidget* rateLbl; + GtkWidget* hbox3; + GtkWidget* bufferLbl; + GtkWidget* bufferHscale; + GtkWidget* mixerFrame; + GtkWidget* mixerHbox; + GtkWidget* mixers[6]; + GtkWidget* mixerFrames[6]; + + + win = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(win), "Sound Preferences"); + main_hbox = gtk_hbox_new(FALSE, 15); + vbox = gtk_vbox_new(False, 5); + //gtk_widget_set_size_request(win, 300, 200); + + + // sound enable check + soundChk = gtk_check_button_new_with_label("Enable sound"); + + // sync with cfg + int cfgBuf; + g_config->getOption("SDL.Sound", &cfgBuf); + if(cfgBuf) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(soundChk), TRUE); + else + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(soundChk), FALSE); + + gtk_signal_connect(GTK_OBJECT(soundChk), "clicked", + G_CALLBACK(toggleSound), NULL); + + + // low pass filter check + lowpassChk = gtk_check_button_new_with_label("Enable low pass filter"); + + // sync with cfg + g_config->getOption("SDL.Sound.LowPass", &cfgBuf); + if(cfgBuf) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lowpassChk), TRUE); + else + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lowpassChk), FALSE); + + gtk_signal_connect(GTK_OBJECT(lowpassChk), "clicked", G_CALLBACK(toggleLowPass), NULL); + + // sound quality combo box + hbox1 = gtk_hbox_new(FALSE, 3); + qualityCombo = gtk_combo_box_new_text(); + gtk_combo_box_append_text(GTK_COMBO_BOX(qualityCombo), "Low"); + gtk_combo_box_append_text(GTK_COMBO_BOX(qualityCombo), "High"); + gtk_combo_box_append_text(GTK_COMBO_BOX(qualityCombo), "Very High"); + + // sync widget with cfg + g_config->getOption("SDL.Sound.Quality", &cfgBuf); + if(cfgBuf == 2) + gtk_combo_box_set_active(GTK_COMBO_BOX(qualityCombo), 2); + else if(cfgBuf == 1) + gtk_combo_box_set_active(GTK_COMBO_BOX(qualityCombo), 1); + else + gtk_combo_box_set_active(GTK_COMBO_BOX(qualityCombo), 0); + + g_signal_connect(qualityCombo, "changed", G_CALLBACK(setQuality), NULL); + + qualityLbl = gtk_label_new("Quality: "); + + gtk_box_pack_start(GTK_BOX(hbox1), qualityLbl, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(hbox1), qualityCombo, FALSE, FALSE, 5); + + // sound rate widgets + hbox2 = gtk_hbox_new(FALSE, 3); + rateCombo = gtk_combo_box_new_text(); + + const int rates[5] = {11025, 22050, 44100, 48000, 96000}; + + char buf[8]; + for(int i=0; i<5;i++) + { + sprintf(buf, "%d", rates[i]); + gtk_combo_box_append_text(GTK_COMBO_BOX(rateCombo), buf); + } + + // sync widget with cfg + g_config->getOption("SDL.Sound.Rate", &cfgBuf); + for(int i=0; i<5; i++) + if(cfgBuf == rates[i]) + gtk_combo_box_set_active(GTK_COMBO_BOX(rateCombo), i); + + g_signal_connect(rateCombo, "changed", G_CALLBACK(setRate), NULL); + + + // sound rate widgets + rateLbl = gtk_label_new("Rate (Hz): "); + + gtk_box_pack_start(GTK_BOX(hbox2), rateLbl, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(hbox2), rateCombo, FALSE, FALSE, 5); + + hbox3 = gtk_hbox_new(FALSE, 2); + bufferHscale = gtk_hscale_new_with_range(15, 200, 2); + bufferLbl = gtk_label_new("Buffer size (in ms)"); + + // sync widget with cfg + g_config->getOption("SDL.Sound.BufSize", &cfgBuf); + gtk_range_set_value(GTK_RANGE(bufferHscale), cfgBuf); + + g_signal_connect(bufferHscale, "button-release-event", G_CALLBACK(setBufSize), NULL); + + + // mixer + mixerFrame = gtk_frame_new("Mixer:"); + mixerHbox = gtk_hbox_new(TRUE, 5); + for(int i=0; i<6; i++) + { + mixers[i] = gtk_vscale_new_with_range(0, 256, 1); + gtk_range_set_inverted(GTK_RANGE(mixers[i]), TRUE); + mixerFrames[i] = gtk_frame_new(mixerStrings[i]); + gtk_container_add(GTK_CONTAINER(mixerFrames[i]), mixers[i]); + gtk_box_pack_start(GTK_BOX(mixerHbox), mixerFrames[i], FALSE, TRUE, 5); + g_signal_connect(mixers[i], "button-release-event", G_CALLBACK(mixerChanged), (gpointer)i); + } + + // sync with cfg + int v; + g_config->getOption("SDL.Sound.Volume", &v); + gtk_range_set_value(GTK_RANGE(mixers[0]), v); + g_config->getOption("SDL.Sound.TriangleVolume", &v); + gtk_range_set_value(GTK_RANGE(mixers[1]), v); + g_config->getOption("SDL.Sound.Square1Volume", &v); + gtk_range_set_value(GTK_RANGE(mixers[2]), v); + g_config->getOption("SDL.Sound.Square2Volume", &v); + gtk_range_set_value(GTK_RANGE(mixers[3]), v); + g_config->getOption("SDL.Sound.NoiseVolume", &v); + gtk_range_set_value(GTK_RANGE(mixers[4]), v); + g_config->getOption("SDL.Sound.PCMVolume", &v); + gtk_range_set_value(GTK_RANGE(mixers[5]), v); + + + // packing some boxes + + gtk_box_pack_start(GTK_BOX(main_hbox), vbox, FALSE, TRUE, 5); + gtk_box_pack_start(GTK_BOX(vbox), soundChk, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(vbox), lowpassChk, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(vbox), hbox1, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(vbox), hbox2, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(vbox), bufferLbl, FALSE, FALSE, 5); + gtk_box_pack_start(GTK_BOX(vbox), bufferHscale, FALSE, TRUE, 5); + gtk_box_pack_start(GTK_BOX(main_hbox), mixerFrame, TRUE, TRUE, 5); + gtk_container_add(GTK_CONTAINER(mixerFrame), mixerHbox); + + gtk_container_add(GTK_CONTAINER(win), main_hbox); + + gtk_widget_show_all(win); + + return; +} + +void quit () +{ + FCEUI_Kill(); + SDL_Quit(); + gtk_main_quit(); + exit(0); +} + +void showAbout () +{ + GtkWidget* aboutDialog; + + aboutDialog = gtk_about_dialog_new (); + gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(aboutDialog), "About fceuX"); + gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(aboutDialog), "fceuX"); + gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(aboutDialog), FCEU_VERSION_STRING); + gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(aboutDialog), "GPL-2; See COPYING"); + gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(aboutDialog), "http://fceux.com"); + + + gtk_dialog_run(GTK_DIALOG(aboutDialog)); + gtk_widget_hide_all(aboutDialog); + +} + +void toggleSound(GtkWidget* check, gpointer data) +{ + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check))) + { + g_config->setOption("SDL.Sound", 1); + InitSound(); + } + else + { + g_config->setOption("SDL.Sound", 0); + KillSound(); + } +} + +void emuReset () +{ + if(isloaded) + ResetNES(); +} + +void emuPause () +{ + if(isloaded) + FCEUI_SetEmulationPaused(1); +} +void emuResume () +{ + if(isloaded) + FCEUI_SetEmulationPaused(0); +} + +void enableFullscreen () +{ + if(isloaded) + ToggleFS(); +} +void recordMovie() +{ + char* movie_fname = const_cast(FCEU_MakeFName(FCEUMKF_MOVIE, 0, 0).c_str()); + FCEUI_printf("Recording movie to %s\n", movie_fname); + FCEUI_SaveMovie(movie_fname, MOVIE_FLAG_NONE, L""); + + return; +} +void recordMovieAs () +{ + GtkWidget* fileChooser; + + GtkFileFilter* filterFm2; + GtkFileFilter* filterAll; + + filterFm2 = gtk_file_filter_new(); + gtk_file_filter_add_pattern(filterFm2, "*.fm2"); + gtk_file_filter_set_name(filterFm2, "FM2 Movies"); + + filterAll = gtk_file_filter_new(); + gtk_file_filter_add_pattern(filterAll, "*"); + gtk_file_filter_set_name(filterAll, "All Files"); + + fileChooser = gtk_file_chooser_dialog_new ("Save FM2 movie for recording", GTK_WINDOW(MainWindow), + GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); + gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(fileChooser), ".fm2"); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterFm2); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterAll); + + if (gtk_dialog_run (GTK_DIALOG (fileChooser)) ==GTK_RESPONSE_ACCEPT) + { + std::string fname; + + fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); + if (!fname.size()) + return; // no filename selected, quit the whole thing + + std::string s = GetUserText("Author name"); + std::wstring author(s.begin(), s.end()); + + + FCEUI_SaveMovie(fname.c_str(), MOVIE_FLAG_FROM_POWERON, author); + } + gtk_widget_destroy (fileChooser); +} + +void loadMovie () +{ + GtkWidget* fileChooser; + + GtkFileFilter* filterFm2; + GtkFileFilter* filterAll; + + filterFm2 = gtk_file_filter_new(); + gtk_file_filter_add_pattern(filterFm2, "*.fm2"); + gtk_file_filter_add_pattern(filterFm2, "*.FM2f"); + gtk_file_filter_set_name(filterFm2, "FM2 Movies"); + + filterAll = gtk_file_filter_new(); + gtk_file_filter_add_pattern(filterAll, "*"); + gtk_file_filter_set_name(filterAll, "All Files"); + + fileChooser = gtk_file_chooser_dialog_new ("Open FM2 Movie", GTK_WINDOW(MainWindow), + GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); + + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterFm2); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterAll); + + if (gtk_dialog_run (GTK_DIALOG (fileChooser)) ==GTK_RESPONSE_ACCEPT) + { + char* fname; + + fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); + static int pauseframe; + g_config->getOption("SDL.PauseFrame", &pauseframe); + g_config->setOption("SDL.PauseFrame", 0); + FCEUI_printf("Playing back movie located at %s\n", fname); + if(FCEUI_LoadMovie(fname, false, false, pauseframe ? pauseframe : false) == FALSE) + { + GtkWidget* d; + d = gtk_message_dialog_new(GTK_WINDOW(MainWindow), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, + "Could not open the selected FM2 file."); + gtk_dialog_run(GTK_DIALOG(d)); + gtk_widget_destroy(d); + } + } + gtk_widget_destroy (fileChooser); +} + +#ifdef _S9XLUA_H +void loadLua () +{ + GtkWidget* fileChooser; + GtkFileFilter* filterLua; + GtkFileFilter* filterAll; + + filterLua = gtk_file_filter_new(); + gtk_file_filter_add_pattern(filterLua, "*.lua"); + gtk_file_filter_add_pattern(filterLua, "*.LUA"); + gtk_file_filter_set_name(filterLua, "Lua scripts"); + + filterAll = gtk_file_filter_new(); + gtk_file_filter_add_pattern(filterAll, "*"); + gtk_file_filter_set_name(filterAll, "All Files"); + + fileChooser = gtk_file_chooser_dialog_new ("Open LUA Script", GTK_WINDOW(MainWindow), + GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); + + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterLua); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterAll); + + if (gtk_dialog_run (GTK_DIALOG (fileChooser)) ==GTK_RESPONSE_ACCEPT) + { + char* filename; + + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); + gtk_widget_destroy(fileChooser); + if(FCEU_LoadLuaCode(filename) == 0) + { + GtkWidget* d; + d = gtk_message_dialog_new(GTK_WINDOW(MainWindow), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, + "Could not open the selected lua script."); + gtk_dialog_run(GTK_DIALOG(d)); + gtk_widget_destroy(d); + } + g_free(filename); + } + else + gtk_widget_destroy (fileChooser); +} +#endif + + +void loadFdsBios () +{ + GtkWidget* fileChooser; + GtkFileFilter* filterDiskSys; + GtkFileFilter* filterRom; + GtkFileFilter* filterAll; + + + filterDiskSys = gtk_file_filter_new(); + gtk_file_filter_add_pattern(filterDiskSys, "disksys.rom"); + gtk_file_filter_set_name(filterDiskSys, "FDS BIOS"); + + filterRom = gtk_file_filter_new(); + gtk_file_filter_add_pattern(filterRom, "*.rom"); + gtk_file_filter_set_name(filterRom, "*.rom"); + + filterAll = gtk_file_filter_new(); + gtk_file_filter_add_pattern(filterAll, "*"); + gtk_file_filter_set_name(filterAll, "All Files"); + + + fileChooser = gtk_file_chooser_dialog_new ("Load FDS BIOS (disksys.rom)", GTK_WINDOW(MainWindow), + GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterDiskSys); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterRom); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterAll); + + if (gtk_dialog_run (GTK_DIALOG (fileChooser)) ==GTK_RESPONSE_ACCEPT) + { + char* filename; + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); + // copy BIOS file to proper place (~/.fceux/disksys.rom) + std::ifstream f1 (filename,std::fstream::binary); + std::string fn_out = FCEU_MakeFName(FCEUMKF_FDSROM, 0, ""); + std::ofstream f2 (fn_out.c_str(),std::fstream::trunc|std::fstream::binary); + gtk_widget_destroy (fileChooser); + GtkWidget* d; + d = gtk_message_dialog_new(GTK_WINDOW(MainWindow), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, + "Famicom Disk System BIOS loaded. If you are you having issues, make sure your BIOS file is 8KB in size."); + gtk_dialog_run(GTK_DIALOG(d)); + gtk_widget_destroy(d); + + f2<width, event->height, 0, 0); + + return TRUE; +} + +void saveStateAs() +{ + GtkWidget* fileChooser; + GtkFileFilter* filterSav; + GtkFileFilter* filterAll; + + filterSav = gtk_file_filter_new(); + gtk_file_filter_add_pattern(filterSav, "*.sav"); + gtk_file_filter_add_pattern(filterSav, "*.SAV"); + gtk_file_filter_set_name(filterSav, "SAV files"); + + filterAll = gtk_file_filter_new(); + gtk_file_filter_add_pattern(filterAll, "*"); + gtk_file_filter_set_name(filterAll, "All Files"); + + fileChooser = gtk_file_chooser_dialog_new ("Save State As", GTK_WINDOW(MainWindow), + GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); + gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(fileChooser), ".sav"); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterSav); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterAll); + + if (gtk_dialog_run (GTK_DIALOG (fileChooser)) ==GTK_RESPONSE_ACCEPT) + { + char* filename; + + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); + FCEUI_SaveState(filename); + g_free(filename); + } + gtk_widget_destroy (fileChooser); + + +} + +void loadStateFrom() +{ + GtkWidget* fileChooser; + GtkFileFilter* filterSav; + GtkFileFilter* filterAll; + + filterSav = gtk_file_filter_new(); + gtk_file_filter_add_pattern(filterSav, "*.sav"); + gtk_file_filter_add_pattern(filterSav, "*.SAV"); + gtk_file_filter_set_name(filterSav, "SAV files"); + + filterAll = gtk_file_filter_new(); + gtk_file_filter_add_pattern(filterAll, "*"); + gtk_file_filter_set_name(filterAll, "All Files"); + + fileChooser = gtk_file_chooser_dialog_new ("Load State From", GTK_WINDOW(MainWindow), + GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterSav); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterAll); + + if (gtk_dialog_run (GTK_DIALOG (fileChooser)) ==GTK_RESPONSE_ACCEPT) + { + char* filename; + + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); + FCEUI_LoadState(filename); + g_free(filename); + } + gtk_widget_destroy (fileChooser); + + +} + + +/* Our menu, an array of GtkItemFactoryEntry structures that defines each menu item */ +static GtkItemFactoryEntry menu_items[] = { + { "/_File", NULL, NULL, 0, "" }, + //{ "/File/_New", "N", NULL, 0, "", GTK_STOCK_NEW }, + { "/File/_Open ROM", "O", loadGame, 0, "", GTK_STOCK_OPEN }, + { "/File/_Close ROM", "C", closeGame, 0, "", GTK_STOCK_CLOSE }, + // { "/File/Save _As", NULL, NULL, 0, "" }, + { "/File/sep1", NULL, NULL, 0, "" }, + { "/File/_Play NSF", "N", loadNSF, 0, "", GTK_STOCK_OPEN }, + { "/File/sep2", NULL, NULL, 0, "" }, + { "/File/Savestate", NULL, NULL, 0, "" }, + { "/File/Savestate/Load State _From", NULL, loadStateFrom, 0, ""}, + { "/File/Savestate/Save State _As", NULL, saveStateAs, 0, ""}, +#ifdef _S9XLUA_H + { "/File/Load _Lua Script", NULL, loadLua, 0, ""}, +#endif + { "/File/sep3", NULL, NULL, 0, "" }, + { "/File/_Screenshot", "F12", FCEUI_SaveSnapshot, 0, ""}, + { "/File/sep2", NULL, NULL, 0, "" }, + { "/File/_Quit", "Q", quit, 0, "", GTK_STOCK_QUIT }, + { "/_Options", NULL, NULL, 0, "" }, + { "/_Emulator", NULL, NULL, 0, "" }, + { "/Emulator/P_ower", NULL, FCEUI_PowerNES, 0, ""}, + { "/Emulator/_Reset", NULL, emuReset, 0, ""}, + { "/Emulator/_Pause", NULL, emuPause, 0, ""}, + { "/Emulator/R_esume", NULL, emuResume, 0, ""}, + { "/Emulator/_FDS", NULL, NULL, 0, ""}, + { "/Emulator/_FDS/_Switch Disk", NULL, FCEU_FDSSelect, 0, ""}, + { "/Emulator/_FDS/_Eject Disk", NULL, FCEU_FDSInsert, 0, ""}, + { "/Emulator/_FDS/Load _BIOS File", NULL, loadFdsBios, 0, ""}, + { "/Emulator/_Insert coin", NULL, FCEUI_VSUniCoin, 0, ""}, + //{ "/Emulator/GTKterm (DEV)", NULL, openGTKterm, 0, ""}, + { "/_Movie", NULL, NULL, 0, "" }, + { "/Movie/_Open", NULL, loadMovie, 0, ""}, + { "/Movie/S_top", NULL, FCEUI_StopMovie, 0, ""}, + { "/Movie/_Pause", NULL, emuPause, 0, ""}, + { "/Movie/R_esume", NULL, emuResume, 0, ""}, + { "/Movie/sep2", NULL, NULL, 0, "" }, + { "/Movie/_Record", NULL, recordMovie, 0, ""}, + { "/Movie/Record _as", NULL, recordMovieAs, 0, ""}, + { "/Options/_Gamepad Config", NULL , openGamepadConfig, 0, "", GTK_STOCK_PREFERENCES }, + { "/Options/_Sound Config", NULL , openSoundConfig, 0, "" }, + { "/Options/_Video Config", NULL , openVideoConfig, 0, "" }, + { "/Options/_Palette Config", NULL , openPaletteConfig, 0, "" }, + { "/Options/_Network Config", NULL , openNetworkConfig, 0, "" }, + //{ "/Options/Map _Hotkeys", NULL , openHotkeyConfig, 0, "" }, + { "/Options/sep1", NULL, NULL, 0, "" }, + { "/Options/_Fullscreen", NULL, enableFullscreen, 0, "" }, + { "/_Help", NULL, NULL, 0, "" }, + { "/Help/About", NULL, showAbout, 0, "" }, +}; + +static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]); + +static GtkWidget* CreateMenubar( GtkWidget* window) +{ + GtkItemFactory *item_factory; + GtkAccelGroup *accel_group; + + /* Make an accelerator group (shortcut keys) */ + accel_group = gtk_accel_group_new (); + + /* Make an ItemFactory (that makes a menubar) */ + item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "
", accel_group); + + /* This function generates the menu items. Pass the item factory, + the number of items in the array, the array itself, and any + callback data for the the menu items. */ + gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL); + + /* Attach the new accelerator group to the window. */ + gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); + + /* Finally, return the actual menu bar created by the item factory. */ + return gtk_item_factory_get_widget (item_factory, "
"); +} +//GtkTextBuffer* gtkConsoleBuf; +//GtkWidget* consoleOutput; +//GtkTextIter iter; +char* buf; +//GtkWidget* term; + +void pushOutputToGTK(const char* str) +{ + + //printf(str); + //gtk_text_buffer_insert(GTK_TEXT_BUFFER(gtkConsoleBuf), &iter, str, -1); + //gtk_text_buffer_set_text(gtkConsoleBuf, str, -1); + + //vte_terminal_feed_child(VTE_TERMINAL(term), str, -1); + return; +} + +void showGui(bool b) +{ + if(b) + gtk_widget_show_all(MainWindow); + else + gtk_widget_hide_all(MainWindow); +} + +int InitGTKSubsystem(int argc, char** argv) +{ + GtkWidget* Menubar; + GtkWidget* vbox; + + MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(MainWindow), FCEU_NAME_AND_VERSION); + gtk_window_set_default_size(GTK_WINDOW(MainWindow), 359, 200); + + vbox = gtk_vbox_new(FALSE, 3); + gtk_container_add(GTK_CONTAINER(MainWindow), vbox); + + Menubar = CreateMenubar(MainWindow); + + //consoleOutput = gtk_text_view_new_with_buffer(gtkConsoleBuf); + //gtk_text_view_set_editable(GTK_TEXT_VIEW(consoleOutput), FALSE); + + //gtkConsoleBuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(consoleOutput)); + //gtk_text_buffer_get_iter_at_offset(gtkConsoleBuf, &iter, 0); + //gtk_text_buffer_insert(gtkConsoleBuf, &iter, "FceuX GUI Started.\n", -1); + // = vte_terminal_new(); + //vte_terminal_feed(VTE_TERMINAL(term), "FceuX GUI Started", -1); + + + + + //gtk_container_add(GTK_CONTAINER(vbox), Menubar); + gtk_box_pack_start (GTK_BOX(vbox), Menubar, FALSE, TRUE, 0); + //gtk_box_pack_start (GTK_BOX(vbox), term, TRUE, TRUE, 0); + + + + + // broken SDL embedding code + //gtk_widget_set_usize(MainWindow, xres, yres); + //gtk_widget_realize(MainWindow); + + // event handlers + //gtk_widget_add_events(MainWindow, GDK_BUTTON_PRESS_MASK); + //gtk_signal_connect(GTK_OBJECT(MainWindow), "configure_event", + // GTK_SIGNAL_FUNC(configureEvent), 0); + + + // PRG: this code here is the the windowID "hack" to render SDL + // in a GTK window. however, I can't get it to work right now + // so i'm commenting it out and haivng a seperate GTK2 window with + // controls + // 12/21/09 + /* + GtkWidget* socket = gtk_socket_new(); + gtk_widget_show (socket) ; + gtk_container_add (GTK_CONTAINER(MainWindow), socket); + + gtk_widget_realize (socket); + + char SDL_windowhack[24]; + sprintf(SDL_windowhack, "SDL_WINDOWID=%ld", (long int)gtk_socket_get_id (GTK_SOCKET(socket))); + putenv(SDL_windowhack); + + + // init SDL + if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) + { + fprintf(stderr, "Couldn't init SDL: %s\n", SDL_GetError()); + gtk_main_quit(); + } + + + + // test rendering + //screen = SDL_SetVideoMode(xres, yres, 0, 0); + //hello = SDL_LoadBMP( "hello.bmp" ); + */ + g_signal_connect(MainWindow, "destroy-event", quit, NULL); + + //gtk_idle_add(mainLoop, MainWindow); + // signal handlers + g_signal_connect(MainWindow, "delete-event", quit, NULL); + + + gtk_widget_show_all(MainWindow); + + return 0; +} + diff --git a/src/drivers/sdl/sdl-opengl.cpp b/src/drivers/sdl/sdl-opengl.cpp index c2c7cbf3..7f700d16 100644 --- a/src/drivers/sdl/sdl-opengl.cpp +++ b/src/drivers/sdl/sdl-opengl.cpp @@ -216,9 +216,9 @@ InitOpenGL(int l, HiBuffer=malloc(4*256*256); memset(HiBuffer,0x00,4*256*256); #ifndef LSB_FIRST - InitBlitToHigh(4,0xFF000000,0xFF0000,0xFF00,efx&2,0); + InitBlitToHigh(4,0xFF000000,0xFF0000,0xFF00,efx&2,0,0); #else - InitBlitToHigh(4,0xFF,0xFF00,0xFF0000,efx&2,0); + InitBlitToHigh(4,0xFF,0xFF00,0xFF0000,efx&2,0,0); #endif } diff --git a/src/drivers/sdl/sdl-video.cpp b/src/drivers/sdl/sdl-video.cpp index 9c3d84e7..3126ad86 100644 --- a/src/drivers/sdl/sdl-video.cpp +++ b/src/drivers/sdl/sdl-video.cpp @@ -279,15 +279,16 @@ InitVideo(FCEUGI *gi) } else { desbpp = 0; } - + + // -Video Modes Tag- if(s_sponge) { - if(s_sponge == 3 || s_sponge == 4) { + if(s_sponge == 4 || s_sponge == 5) { s_exs = s_eys = 3; } else { s_exs = s_eys = 2; } s_eefx = 0; - if(s_sponge == 1 || s_sponge == 3) { + if(s_sponge == 1 || s_sponge == 4) { desbpp = 32; } } @@ -322,9 +323,10 @@ InitVideo(FCEUGI *gi) g_config->getOption("SDL.XScale", &s_exs); g_config->getOption("SDL.YScale", &s_eys); g_config->getOption("SDL.SpecialFX", &s_eefx); - + + // -Video Modes Tag- if(s_sponge) { - if(s_sponge >= 3) { + if(s_sponge >= 4) { s_exs = s_eys = 3; } else { s_exs = s_eys = 2; @@ -416,7 +418,7 @@ InitVideo(FCEUGI *gi) s_screen->format->Rmask, s_screen->format->Gmask, s_screen->format->Bmask, - s_eefx, s_sponge); + s_eefx, s_sponge, 0); #ifdef OPENGL if(s_useOpenGL) { diff --git a/src/drivers/sdl/sdl.cpp b/src/drivers/sdl/sdl.cpp index 8225700b..53f999c6 100644 --- a/src/drivers/sdl/sdl.cpp +++ b/src/drivers/sdl/sdl.cpp @@ -71,6 +71,7 @@ int mutecapture; #endif static int noconfig; +// -Video Modes Tag- : See --special char *DriverUsage="\ Option Value Description\n\ --pal {0|1} Use PAL timing.\n\ @@ -90,7 +91,7 @@ Option Value Description\n\ --fullscreen {0|1} Enable full screen mode.\n\ --noframe {0|1} Hide title bar and window decorations.\n\ --special {1-4} Use special video scaling filters\n\ - (1 = hq2x 2 = Scale2x 3 = hq3x 4 = Scale3x)\n\ + (1 = hq2x 2 = Scale2x 3 = NTSC 2x 4 = hq3x 5 = Scale3x)\n\ --palette f Load custom global palette from file f.\n\ --sound {0|1} Enable sound.\n\ --soundrate x Set sound playback rate to x Hz.\n\ diff --git a/src/drivers/win/config.cpp b/src/drivers/win/config.cpp index 6fc66aa5..8c650f64 100644 --- a/src/drivers/win/config.cpp +++ b/src/drivers/win/config.cpp @@ -168,6 +168,7 @@ static CFGSTRUCT fceuconfig[] = { NACS("odbase",directory_names[13]), AC(winspecial), + AC(NTSCwinspecial), AC(winsizemulx), AC(winsizemuly), NAC("saspectw987",saspectw), diff --git a/src/drivers/win/video.cpp b/src/drivers/win/video.cpp index 274d95f7..212e7331 100644 --- a/src/drivers/win/video.cpp +++ b/src/drivers/win/video.cpp @@ -42,6 +42,7 @@ int fssync=0; int winsync=0; int winspecial = 0; +int NTSCwinspecial = 0; int vmod = 0; vmdef vmodes[11]={ @@ -197,9 +198,18 @@ static int GetBPP(void) static int InitBPPStuff(int fs) { + + int specfilteropt = 0; + switch (winspecial) + { + case 3: + specfilteropt = NTSCwinspecial; + break; + } + if(bpp >= 16) { - InitBlitToHigh(bpp >> 3, CBM[0], CBM[1], CBM[2], 0, fs?vmodes[vmod].special:winspecial); + InitBlitToHigh(bpp >> 3, CBM[0], CBM[1], CBM[2], 0, fs?vmodes[vmod].special:winspecial,specfilteropt); } else if(bpp==8) { @@ -241,9 +251,10 @@ int SetVideoMode(int fs) if(!fs) { - if(winspecial == 2 || winspecial == 1) + // -Video Modes Tag- + if(winspecial <= 3 && winspecial >= 1) specmul = 2; - else if(winspecial == 3 || winspecial == 4) + else if(winspecial >= 4 && winspecial <= 5) specmul = 3; else specmul = 1; @@ -334,9 +345,10 @@ int SetVideoMode(int fs) { if(vmod == 0) { - if(vmodes[0].special == 2 || vmodes[0].special == 1) + // -Video Modes Tag- + if(vmodes[0].special <= 3 && vmodes[0].special >= 1) specmul = 2; - else if(vmodes[0].special == 3 || vmodes[0].special == 4) + else if(vmodes[0].special >= 4 && vmodes[0].special <= 5) specmul = 3; else specmul = 1; @@ -483,9 +495,10 @@ static void BlitScreenWindow(unsigned char *XBuf) if (!lpDDSBack) return; - if(winspecial == 2 || winspecial == 1) + // -Video Modes Tag- + if(winspecial <= 3 && winspecial >= 1) specialmul = 2; - else if(winspecial == 4 || winspecial == 3) + else if(winspecial >= 4 && winspecial <= 5) specialmul = 3; else specialmul = 1; @@ -544,9 +557,10 @@ static void BlitScreenFull(uint8 *XBuf) RECT srect,drect; LPDIRECTDRAWSURFACE7 lpDDSVPrimary; int specmul; // Special scaler size multiplier - if(vmodes[0].special == 2 || vmodes[0].special == 1) + // -Video Modes Tag- + if(vmodes[0].special <= 3 && vmodes[0].special >= 1) specmul = 2; - else if(vmodes[0].special == 3 || vmodes[0].special == 4) + else if(vmodes[0].special >= 4 && vmodes[0].special <= 5) specmul = 3; else specmul = 1; @@ -739,6 +753,7 @@ static void BlitScreenFull(uint8 *XBuf) { if(!(vmodes[vmod].flags&VMDF_DXBLT)) { + // -Video Modes Tag- if(vmodes[vmod].special) ScreenLoc += (vmodes[vmod].drect.left*(bpp>>3)) + ((vmodes[vmod].drect.top)*pitch); else @@ -752,6 +767,7 @@ static void BlitScreenFull(uint8 *XBuf) else { XBuf+=FSettings.FirstSLine*256+VNSCLIP; + // -Video Modes Tag- if(vmodes[vmod].special) Blit8To8(XBuf,(uint8*)ScreenLoc, VNSWID, FSettings.TotalScanlines(), pitch,vmodes[vmod].xscale,vmodes[vmod].yscale,0,vmodes[vmod].special); //mbg merge 7/17/06 added cast else @@ -887,7 +903,8 @@ static int RecalcCustom(void) cmode->drect.right=cmode->drect.left+VNSWID*cmode->xscale; } - if((cmode->special == 1 || cmode->special == 3) && cmode->bpp == 8) + // -Video Modes Tag- + if((cmode->special == 1 || cmode->special == 4) && cmode->bpp == 8) { cmode->bpp = 32; //FCEUD_PrintError("HQ2x/HQ3x requires 16bpp or 32bpp(best)."); @@ -963,9 +980,10 @@ BOOL CALLBACK VideoConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara CheckRadioButton(hwndDlg,IDC_RADIO_SCALE,IDC_RADIO_STRETCH,(vmodes[0].flags&VMDF_STRFS)?IDC_RADIO_STRETCH:IDC_RADIO_SCALE); { - char *str[]={"","hq2x","Scale2x","hq3x","Scale3x"}; + // -Video Modes Tag- + char *str[]={"","hq2x","Scale2x","NTSC 2x","hq3x","Scale3x"}; int x; - for(x=0;x<5;x++) + for(x=0;x<6;x++) { SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SCALER_FS,CB_ADDSTRING,0,(LPARAM)(LPSTR)str[x]); SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SCALER_WIN,CB_ADDSTRING,0,(LPARAM)(LPSTR)str[x]); diff --git a/src/drivers/win/video.h b/src/drivers/win/video.h index 16c161f0..1ecf4f06 100644 --- a/src/drivers/win/video.h +++ b/src/drivers/win/video.h @@ -40,6 +40,7 @@ typedef struct { // left, top, right, bottom extern vmdef vmodes[11]; extern int winspecial; +extern int NTSCwinspecial; extern int disvaccel; extern int fssync; diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index 41549741..1b8e8431 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -2269,8 +2269,9 @@ void FixWXY(int pref) } if(winspecial) { + // -Video Modes Tag- int mult; - if(winspecial == 1 || winspecial == 2) mult = 2; + if(winspecial >= 1 && winspecial <= 3) mult = 2; else mult = 3; if(winsizemulx < mult) { diff --git a/vc/vc10_fceux.vcxproj b/vc/vc10_fceux.vcxproj index f5371b27..3df43321 100644 --- a/vc/vc10_fceux.vcxproj +++ b/vc/vc10_fceux.vcxproj @@ -323,6 +323,7 @@ + @@ -686,6 +687,9 @@ + + + diff --git a/vc/vc10_fceux.vcxproj.filters b/vc/vc10_fceux.vcxproj.filters index f896968f..9e085126 100644 --- a/vc/vc10_fceux.vcxproj.filters +++ b/vc/vc10_fceux.vcxproj.filters @@ -907,6 +907,9 @@ + + drivers\common + @@ -1342,6 +1345,15 @@ drivers\win\lua + + drivers\common + + + drivers\common + + + drivers\common + diff --git a/vc/vc9_fceux.vcproj b/vc/vc9_fceux.vcproj index e0ea68e0..45b56204 100644 --- a/vc/vc9_fceux.vcproj +++ b/vc/vc9_fceux.vcproj @@ -798,6 +798,22 @@ RelativePath="..\src\drivers\common\hq3x.h" > + + + + + + + +