📄 emugui.cpp
字号:
/*
SNEeSe, an Open Source Super NES emulator.
Copyright (c) 1998-2004 Charles Bilyue'.
Portions Copyright (c) 2003-2004 Daniel Horchner.
This is free software. See 'LICENSE' for details.
You must read and accept the license prior to use.
*/
/*
EmuGUI.cc
Contains emulator specific GUI code
Some stuff from helper.c will be moved here!
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "wrapaleg.h"
#include "guicore.h"
/* ------------------------- GUI STUFF ------------------------- */
#include "types.h"
#include "font.h"
#include "input.h"
#include "cpu/cpu.h"
#include "apu/spc.h"
#include "apu/sound.h"
#include "romload.h"
#include "debug.h"
#include "snes.h"
extern PALETTE sneesepal;
extern BITMAP *sneese;
extern BITMAP *joypad;
extern SCREEN screenmodes[];
// Used to configure the screen and set internal variables for rendering!
BITMAP *SetGUIScreen(int ScreenMode)
{
if (Allegro_Bitmap) // If bitmap exists destroy it
{
destroy_bitmap(Allegro_Bitmap);
Allegro_Bitmap = NULL;
}
if (screenmodes[SCREEN_MODE = ScreenMode].set())
{
switch(ScreenMode)
{
case 0:
case 2:
case 3:
return (BITMAP *) 0;
break;
default:
if (screenmodes[SCREEN_MODE = 0].set()) return (BITMAP *) 0;
}
}
ScreenX = screenmodes[SCREEN_MODE].w;
ScreenY = screenmodes[SCREEN_MODE].h;
Allegro_Bitmap = create_bitmap(ScreenX, ScreenY);
if (!Allegro_Bitmap) return (BITMAP *) 0;
clear(Allegro_Bitmap);
#ifndef NO_LOGO
// We reload to convert to correct bit depth
{
char logo_name[MAXPATH];
if (sneese) destroy_bitmap(sneese);
strcpy(logo_name, dat_name);
strcat(logo_name, "#sneese");
sneese = load_bmp(logo_name, sneesepal);
}
#endif
return Allegro_Bitmap;
}
void fill_backdrop(BITMAP *gui_screen)
{
#ifndef NO_LOGO
if (sneese)
{ // Prevent a crash if file not found!
stretch_blit(sneese, gui_screen, 0, 0,
GUI_ScreenWidth, GUI_ScreenHeight, 0, 0, SCREEN_W, SCREEN_H);
}
else
#endif
{
clear_to_color(Allegro_Bitmap, 240);
}
}
void refresh_gui(void)
{
fill_backdrop(Allegro_Bitmap);
draw_sprite(Allegro_Bitmap, GUI_Bitmap, 0, 0);
vsync();
CopyGUIScreen();
}
const char *GUI_init()
{
char *errormsg;
char joypad_name[MAXPATH];
errormsg = GUI_core_init();
if (errormsg) return errormsg;
set_color_conversion(COLORCONV_NONE);
if (!joypad)
{
strcpy(joypad_name, dat_name);
strcat(joypad_name, "#joypad");
joypad = load_pcx(joypad_name, NULL);
}
set_color_conversion(COLORCONV_TOTAL);
return 0;
}
WINDOW *GUI_window=0;
WINDOW *File_window=0;
WINDOW *Main_window=0;
enum {
MAIN_RESUME_EMULATION,
MAIN_RESET_EMULATION,
MAIN_LOAD_ROM,
MAIN_CONFIGURE,
MAIN_ROM_INFO,
MAIN_HW_STATUS,
MAIN_DMA_STATUS,
MAIN_APU_STATUS,
MAIN_BGWIN_STATUS,
MAIN_EXIT,
MAIN_NUM_OPTIONS
};
char *Main_Options[MAIN_NUM_OPTIONS]={
"Resume emulation",
"Reset emulation",
"Load ROM",
"Configure",
"ROM information",
"HW status",
"(H)DMA status",
"Voice status",
"BG window status",
"Exit SNEeSe :("};
WINDOW *Config_window=0;
enum {
CONFIG_SCREEN_MODE,
CONFIG_CONTROLLERS,
CONFIG_SOUND,
CONFIG_ENABLE_SPC,
CONFIG_STRETCH_H,
CONFIG_STRETCH_V,
CONFIG_FRAMESKIP_MIN,
CONFIG_FRAMESKIP_MAX,
CONFIG_ENABLE_FPS_COUNTER,
CONFIG_NUM_OPTIONS
};
char min_frameskip_str[] = "Min Frameskip: ???????";
char max_frameskip_str[] = "Max Frameskip: ???????";
char fps_counter_str[] = "FPS counter: off";
char stretch_h_str[] = "H stretch: full";
char stretch_v_str[] = "V stretch: full";
const char *Config_Options[CONFIG_NUM_OPTIONS]={
0, // screen mode
"Configure controllers", // controller configuration menu
"Configure sound",
0, // SPC enable setting
stretch_h_str, // screen stretch settings
stretch_v_str,
min_frameskip_str,
max_frameskip_str,
fps_counter_str
};
WINDOW *Sound_window=0;
enum {
SOUND_ENABLE_SOUND,
SOUND_SAMPLE_SIZE,
SOUND_ENABLE_ECHO,
SOUND_ENABLE_GAUSS,
SOUND_ENABLE_ENVX,
SOUND_NUM_OPTIONS
};
char sample_size_str[] = "Sample size: xx-bit";
const char *Sound_Options[SOUND_NUM_OPTIONS]={
0, // Sound enable setting
sample_size_str, // Sound sample size
0, // Sound echo/FIR filter enable
0, // Sound gauss filter enable
0 // Sound ENVX reading enable
};
WINDOW *Controls_window=0;
enum {
#if 0
#ifdef ALLEGRO_DOS
CONTROLS_JOYSTICK_DRIVER,
#endif
#endif
CONTROLS_CONTROLLER_1,
CONTROLS_CONTROLLER_2,
CONTROLS_MAP_1,
CONTROLS_MAP_2,
CONTROLS_NUM_OPTIONS
};
const char *Controls_Options[CONTROLS_NUM_OPTIONS]=
{
#if 0
#ifdef ALLEGRO_DOS
"Joystick: **************", // joystick driver
#endif
#endif
"-------- on player 1", // controls: first player
"-------- on player 2", // controls: second player
"Define keys for player 1",
"Define keys for player 2"
};
WINDOW *Screen_window=0;
#if defined(ALLEGRO_DOS)
#define NUM_SCREEN_OPTIONS 7
char *Screen_Options[NUM_SCREEN_OPTIONS]={
"320x200x256 VGA",
"320x240x256 VESA2",
"320x240x256 MODE-X",
"256x239x256 VGA",
"320x200x16b VESA2",
"320x240x16b VESA2",
"640x480x16b VESA2"
};
#elif defined(ALLEGRO_WINDOWS) || defined(ALLEGRO_UNIX) || defined(ALLEGRO_BEOS)
#define NUM_SCREEN_OPTIONS 8
char *Screen_Options[NUM_SCREEN_OPTIONS]={
"320x200x256 WIN",
"320x240x256 WIN",
"320x240x256 FS",
"256x239x256 WIN",
"320x200x16b WIN",
"320x240x16b WIN",
"640x480x16b WIN",
"640x480x16b FS"
};
#else
#error Unsupported platform.
#endif
void UpdateGUI()
{
GUI_window->refresh();
}
void UpdateMainWindow(int Selected)
{
static int last = 0;
if (Selected < 0) Selected = last;
else last = Selected;
UpdateGUI();
Main_window->refresh();
for(int a=0;a<MAIN_NUM_OPTIONS;a++)
if(a!=Selected) PlotMenuItem(Main_window,default_font,Main_Options[a],0,default_font->get_heightspace()*a,16);
else PlotSelectedMenuItem(Main_window,default_font,Main_Options[a],0,default_font->get_heightspace()*a,16);
}
void UpdateFileWindow(int SelFile, int NumFiles, int FirstFile)
{
char TempString[MAXPATH + 2];
UpdateMainWindow(-1);
File_window->refresh();
for (int a = 0; a < NumFiles; a++){
int CurFile = FirstFile + a;
if (DirList[CurFile].Directory)
sprintf(TempString, "[%s]", DirList[CurFile].Name);
if (a == SelFile)
PlotSelectedMenuItem(File_window, default_font,
DirList[CurFile].Directory ? TempString : DirList[CurFile].Name,
0, default_font->get_heightspace() * a, 38);
else
PlotMenuItem(File_window, default_font,
DirList[CurFile].Directory ? TempString : DirList[CurFile].Name,
0, default_font->get_heightspace() * a, 38);
}
refresh_gui();
}
void UpdateConfigWindow(int Selected)
{
static int last = 0;
if (Selected < 0) Selected = last;
else last = Selected;
UpdateMainWindow(-1);
Config_window->refresh();
for(int a=0;a<CONFIG_NUM_OPTIONS;a++)
if(a!=Selected) PlotMenuItem(Config_window,default_font,Config_Options[a],0,default_font->get_heightspace()*a,24);
else PlotSelectedMenuItem(Config_window,default_font,Config_Options[a],0,default_font->get_heightspace()*a,24);
}
void UpdateScreenWindow(int Selected)
{
static int last = 0;
if (Selected < 0) Selected = last;
else last = Selected;
UpdateConfigWindow(-1);
Screen_window->refresh();
for(int a=0;a<NUM_SCREEN_OPTIONS;a++)
if(a!=Selected) PlotMenuItem(Screen_window,default_font,Screen_Options[a],0,default_font->get_heightspace()*a,20);
else PlotSelectedMenuItem(Screen_window,default_font,Screen_Options[a],0,default_font->get_heightspace()*a,20);
}
void UpdateSoundWindow(int Selected)
{
static int last = 0;
if (Selected < 0) Selected = last;
else last = Selected;
UpdateConfigWindow(-1);
Sound_window->refresh();
for(int a=0;a<SOUND_NUM_OPTIONS;a++)
if(a!=Selected) PlotMenuItem(Sound_window,default_font,Sound_Options[a],0,default_font->get_heightspace()*a,24);
else PlotSelectedMenuItem(Sound_window,default_font,Sound_Options[a],0,default_font->get_heightspace()*a,24);
}
void UpdateControlsWindow(int Selected)
{
static int last = 0;
if (Selected < 0) Selected = last;
else last = Selected;
UpdateConfigWindow(-1);
Controls_window->refresh();
for(int a=0;a<CONTROLS_NUM_OPTIONS;a++)
if(a!=Selected) PlotMenuItem(Controls_window,default_font,Controls_Options[a],0,default_font->get_heightspace()*a,24);
else PlotSelectedMenuItem(Controls_window,default_font,Controls_Options[a],0,default_font->get_heightspace()*a,24);
}
const char *FileWindow()
{
clear_keybuf();
static int FileListPos = 0;
static int SelFile = 0;
int NumFiles;
int keypress, key_asc, key_scan;
static char current_file_window_dir[MAXPATH] = ".";
static char filename[MAXPATH];
chdir(current_file_window_dir);
NumFiles = GetDirList("*.*", DirList, FileListPos);
UpdateFileWindow(SelFile,
FileListPos + 15 <= NumFiles ? 15 : NumFiles - FileListPos,
FileListPos);
for(;;)
{
while (!keypressed());
keypress = readkey();
key_asc = keypress & 0xFF;
key_scan = keypress >> 8;
switch (key_scan)
{
case KEY_HOME:
FileListPos = 0;
SelFile = 0;
UpdateFileWindow(SelFile,
FileListPos + 15 <= NumFiles ? 15 : NumFiles - FileListPos,
FileListPos);
continue;
case KEY_END:
// Jump to end of files, then to end of drives
if (FileListPos + 15 + 26 < NumFiles) FileListPos = NumFiles - 15 - 26;
else FileListPos = NumFiles - 15;
if (FileListPos < 0) FileListPos = 0;
SelFile = (FileListPos + 15 <= NumFiles ? 15 : NumFiles - FileListPos) - 1;
UpdateFileWindow(SelFile,
FileListPos + 15 <= NumFiles ? 15 : NumFiles - FileListPos,
FileListPos);
continue;
case KEY_PGUP:
if (FileListPos != 0)
{
FileListPos -= 15;
if (FileListPos < 0) FileListPos = 0;
} else SelFile = 0;
UpdateFileWindow(SelFile,
FileListPos + 15 <= NumFiles ? 15 : NumFiles - FileListPos,
FileListPos);
continue;
case KEY_PGDN:
if (FileListPos + 15 < NumFiles)
{
FileListPos += 15;
if (FileListPos + 15 >= NumFiles) FileListPos = NumFiles - 15;
} else SelFile =
(FileListPos + 15 <= NumFiles ? 15 : NumFiles - FileListPos) - 1;
UpdateFileWindow(SelFile,
FileListPos + 15 <= NumFiles ? 15 : NumFiles - FileListPos,
FileListPos);
continue;
case KEY_UP:
if (SelFile == 0 && FileListPos > 0)
{
FileListPos--;
UpdateFileWindow(SelFile,
FileListPos + 15 <= NumFiles ? 15 : NumFiles - FileListPos,
FileListPos);
} else if (SelFile > 0)
{
UpdateFileWindow(--SelFile,
FileListPos + 15 <= NumFiles ? 15 : NumFiles - FileListPos,
FileListPos);
}
continue;
case KEY_DOWN:
if(SelFile == 14 && FileListPos < NumFiles - 15)
{
FileListPos++;
UpdateFileWindow(SelFile,
FileListPos + 15 <= NumFiles ? 15 : NumFiles - FileListPos,
FileListPos);
} else if (SelFile
< (FileListPos + 15 <= NumFiles ? 15 : NumFiles - FileListPos) - 1)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -