⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 emugui.cpp

📁 NES game Emulator in Linux.c and asm codes.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
     UpdateFileWindow(++SelFile,
      FileListPos + 15 <= NumFiles ? 15 : NumFiles - FileListPos,
      FileListPos);
    }
    continue;

   case KEY_ESC:
    return NULL;

   case KEY_ENTER:
    if (DirList[FileListPos + SelFile].Directory)
    {
     char dir[MAXDIR];

     chdir(DirList[FileListPos + SelFile].Name);
     strcpy(current_file_window_dir, getcwd(dir, MAXDIR)); // "remember" last opened dir
     FileListPos = 0;
     SelFile = 0;
     NumFiles = GetDirList("*.*", DirList, FileListPos);
     UpdateFileWindow(SelFile,
      FileListPos + 15 <= NumFiles ? 15 : NumFiles - FileListPos,
      FileListPos);
     continue;
    } else {
     fix_filename_path(filename, DirList[FileListPos + SelFile].Name,
      MAXPATH);

     return filename;
    }
  }
 }
 return NULL;
}
int ScreenWindow()
{
 int CursorAt = SCREEN_MODE;
 int keypress, key_asc, key_scan;
 clear_keybuf();

 for(;;)
 {
  UpdateScreenWindow(CursorAt);
  refresh_gui();

  while (!keypressed());
  keypress = readkey();
  key_asc = keypress & 0xFF;
  key_scan = keypress >> 8;

  switch (key_scan)
  {
   case KEY_UP:
    if(CursorAt) CursorAt--; else CursorAt=NUM_SCREEN_OPTIONS-1;
    break;
   case KEY_DOWN:
    if(CursorAt < NUM_SCREEN_OPTIONS-1) CursorAt++; else CursorAt=0;
    break;
   case KEY_ESC:
    return -1;
   case KEY_ENTER:
   case KEY_ENTER_PAD:
    return CursorAt;
  }
 }
 return -1; // Signify normal exit
}


char *on_off[2]={ "off", "on" };
char *en_dis[2]={ "enabled", "disabled" };

int SoundWindow()
{
 switch (sound_enabled)
 {
  case 0:
   Sound_Options[SOUND_ENABLE_SOUND] = "Sound Disabled";
   break;
  case 1:
   Sound_Options[SOUND_ENABLE_SOUND] = "Sound Enabled (mono)";
   break;
  default:
   Sound_Options[SOUND_ENABLE_SOUND] = "Sound Enabled (stereo)";
 }


 sprintf(sample_size_str, "Sample size: %2d-bit", sound_bits);


 Sound_Options[SOUND_ENABLE_ECHO] = sound_echo_enabled ?
  "Echo/FIR filter: on" : "Echo/FIR filter: off";


 Sound_Options[SOUND_ENABLE_GAUSS] = sound_gauss_enabled ?
  "Gaussian filter: on" : "Gaussian filter: off";


 Sound_Options[SOUND_ENABLE_ENVX] = ENVX_ENABLED ?
  "ENVX reading: on" : "ENVX reading: off";



 int CursorAt=0;
 int keypress, key_asc, key_scan;
 clear_keybuf();

 for(;;)
 {
  UpdateSoundWindow(CursorAt);
  refresh_gui();

  while (!keypressed());
  keypress = readkey();
  key_asc = keypress & 0xFF;
  key_scan = keypress >> 8;

  switch (key_scan)
  {
   case KEY_UP:
    CursorAt--;
    if(CursorAt == -1) // so it wraps
     CursorAt = SOUND_NUM_OPTIONS-1;
    break;
   case KEY_DOWN:
    CursorAt++;
    if(CursorAt == SOUND_NUM_OPTIONS) // so it wraps
    CursorAt=0;
    break;

   case KEY_ESC:
    return -1;

   case KEY_ENTER:
   case KEY_ENTER_PAD:
    if (CursorAt == SOUND_ENABLE_SOUND)
    {
     switch(sound_enabled)
     {
      case 0:
       if (Install_Sound(0))
       {
        Sound_Options[SOUND_ENABLE_SOUND] = "Sound Enabled (mono)";
       }
       break;
      case 1:
       Remove_Sound();
       if (Install_Sound(1))
       {
        Sound_Options[SOUND_ENABLE_SOUND] = "Sound Enabled (stereo)";
       }
       else
       {
        Sound_Options[SOUND_ENABLE_SOUND] = "Sound Disabled";
       }
       break;
      case 2:
       Remove_Sound();
       Sound_Options[SOUND_ENABLE_SOUND] = "Sound Disabled";
     }
    }

    if (CursorAt == SOUND_SAMPLE_SIZE)
    {
     sound_bits = sound_bits == 16 ? 8 : 16;
     sprintf(sample_size_str, "Sample size: %2d-bit", sound_bits);

     switch(sound_enabled)
     {
      case 0:
       Sound_Options[SOUND_ENABLE_SOUND] = "Sound Disabled";
       break;

      case 1:
       Remove_Sound();
       if (Install_Sound(0))
       {
        Sound_Options[SOUND_ENABLE_SOUND] = "Sound Enabled (mono)";
       }
       else
       {
        Sound_Options[SOUND_ENABLE_SOUND] = "Sound Disabled";
       }
       break;

      case 2:
       Remove_Sound();
       if (Install_Sound(1))
       {
        Sound_Options[SOUND_ENABLE_SOUND] = "Sound Enabled (stereo)";
       }
       else
       {
        Sound_Options[SOUND_ENABLE_SOUND] = "Sound Disabled";
       }
     }

    }


    if (CursorAt == SOUND_ENABLE_ECHO)
    {
     Sound_Options[SOUND_ENABLE_ECHO] =
      (sound_echo_enabled = !sound_echo_enabled) ?
      "Echo/FIR filter: on" : "Echo/FIR filter: off";
    }


    if (CursorAt == SOUND_ENABLE_GAUSS)
    {
     Sound_Options[SOUND_ENABLE_GAUSS] =
      (sound_gauss_enabled = !sound_gauss_enabled) ?
      "Gaussian filter: on" : "Gaussian filter: off";
    }


    if (CursorAt == SOUND_ENABLE_ENVX)
    {
     Sound_Options[SOUND_ENABLE_ENVX] = (ENVX_ENABLED = !ENVX_ENABLED) ?
      "ENVX reading: on" : "ENVX reading: off";
    }

  }
 }
 return 1;          // Signify normal exit
}

#if 0
const int joydriver_id[] =
{
 JOY_TYPE_NONE,
 JOY_TYPE_STANDARD,
 JOY_TYPE_2PADS,
 JOY_TYPE_4BUTTON,
 JOY_TYPE_6BUTTON,
 JOY_TYPE_8BUTTON,
 JOY_TYPE_FSPRO,
 JOY_TYPE_WINGEX,
 JOY_TYPE_SIDEWINDER,
 JOY_TYPE_SIDEWINDER_AG,
 JOY_TYPE_GAMEPAD_PRO,
 JOY_TYPE_GRIP,
 JOY_TYPE_SNESPAD_LPT1,
 JOY_TYPE_SNESPAD_LPT2,
 JOY_TYPE_SNESPAD_LPT3,
 JOY_TYPE_PSXPAD_LPT1,
 JOY_TYPE_PSXPAD_LPT2,
 JOY_TYPE_PSXPAD_LPT3,
 JOY_TYPE_N64PAD_LPT1,
 JOY_TYPE_N64PAD_LPT2,
 JOY_TYPE_N64PAD_LPT3,
 JOY_TYPE_DB9_LPT1,
 JOY_TYPE_DB9_LPT2,
 JOY_TYPE_DB9_LPT3,
 JOY_TYPE_TURBOGRAFIX_LPT1,
 JOY_TYPE_TURBOGRAFIX_LPT2,
 JOY_TYPE_TURBOGRAFIX_LPT3,
 JOY_TYPE_WINGWARRIOR,
 JOY_TYPE_IFSEGA_ISA,
 JOY_TYPE_IFSEGA_PCI,
 JOY_TYPE_IFSEGA_PCI_FAST,
 JOY_TYPE_AUTODETECT
};


const int joydriver_count = sizeof(joydriver_id) / sizeof(int);

const char *get_joydriver_str(int driver)
{
 switch (driver)
 {
 case JOY_TYPE_NONE: return "None";
 case JOY_TYPE_STANDARD: return "2-button";
 case JOY_TYPE_2PADS: return "two 2-button";
 case JOY_TYPE_4BUTTON: return "4-button";
 case JOY_TYPE_6BUTTON: return "6-button";
 case JOY_TYPE_8BUTTON: return "8-button";
 case JOY_TYPE_FSPRO: return "Flightstick";
 case JOY_TYPE_WINGEX: return "WM Extreme";
 case JOY_TYPE_SIDEWINDER: return "Sidewinder";
 case JOY_TYPE_SIDEWINDER_AG: return "Sidewinder Alt";
 case JOY_TYPE_GAMEPAD_PRO: return "Gravis Pro";
 case JOY_TYPE_GRIP: return "Gravis GrIP";
 case JOY_TYPE_SNESPAD_LPT1: return "SNES pad, LPT1";
 case JOY_TYPE_SNESPAD_LPT2: return "SNES pad, LPT2";
 case JOY_TYPE_SNESPAD_LPT3: return "SNES pad, LPT3";
 case JOY_TYPE_PSXPAD_LPT1: return "PSX pad, LPT1";
 case JOY_TYPE_PSXPAD_LPT2: return "PSX pad, LPT2";
 case JOY_TYPE_PSXPAD_LPT3: return "PSX pad, LPT3";
 case JOY_TYPE_N64PAD_LPT1: return "N64 pad, LPT1";
 case JOY_TYPE_N64PAD_LPT2: return "N64 pad, LPT2";
 case JOY_TYPE_N64PAD_LPT3: return "N64 pad, LPT3";
 case JOY_TYPE_DB9_LPT1: return "DB9stick, LPT1";
 case JOY_TYPE_DB9_LPT2: return "DB9stick, LPT2";
 case JOY_TYPE_DB9_LPT3: return "DB9stick, LPT3";
 case JOY_TYPE_TURBOGRAFIX_LPT1: return "TG16 pad, LPT1";
 case JOY_TYPE_TURBOGRAFIX_LPT2: return "TG16 pad, LPT2";
 case JOY_TYPE_TURBOGRAFIX_LPT3: return "TG16 pad, LPT3";
 case JOY_TYPE_WINGWARRIOR: return "WM Warrior";
 case JOY_TYPE_IFSEGA_ISA: return "IF-SEGA ISA";
 case JOY_TYPE_IFSEGA_PCI: return "IF-SEGA PCI";
 case JOY_TYPE_IFSEGA_PCI_FAST: return "IF-SEGA PCI2";
 case JOY_TYPE_AUTODETECT: return "Autodetect";
 }

 return "";
}
#endif

WINDOW *ControlSetup_window=0;



void UpdateControllerScreen(const SNES_CONTROLLER_INPUTS *input)
{
 char tempch[9];

 UpdateControlsWindow(-1);
 ControlSetup_window->refresh();

 scantotext(input->up,tempch);
 PlotStringShadow(ControlSetup_window,default_font,tempch,38,31,15,8);
 scantotext(input->down,tempch);
 PlotStringShadow(ControlSetup_window,default_font,tempch,38,65,15,8);
 scantotext(input->left,tempch);
 PlotStringShadow(ControlSetup_window,default_font,tempch,24,44,15,8);
 scantotext(input->right,tempch);
 PlotStringShadow(ControlSetup_window,default_font,tempch,55,52,15,8);
 scantotext(input->a,tempch);
 PlotStringShadow(ControlSetup_window,default_font,tempch,151,46,15,8);
 scantotext(input->b,tempch);
 PlotStringShadow(ControlSetup_window,default_font,tempch,130,69,15,8);
 scantotext(input->x,tempch);
 PlotStringShadow(ControlSetup_window,default_font,tempch,127,25,15,8);
 scantotext(input->y,tempch);
 PlotStringShadow(ControlSetup_window,default_font,tempch,104,49,15,8);
 scantotext(input->l,tempch);
 PlotStringShadow(ControlSetup_window,default_font,tempch,40,1,15,8);
 scantotext(input->r,tempch);
 PlotStringShadow(ControlSetup_window,default_font,tempch,127,1,15,8);
 scantotext(input->select,tempch);
 PlotStringShadow(ControlSetup_window,default_font,tempch,68,40,15,8);
 scantotext(input->start,tempch);
 PlotStringShadow(ControlSetup_window,default_font,tempch,91,73,15,8);
}

signed char lastkeypress_locked = 0;
void (*lastkeypress_chain)(int scancode);
volatile int last_scancode;
volatile signed char last_scancode_valid;

static void lastkeypress_callback(int scancode)
{
 if (!(scancode & 0x80))
 {
  last_scancode = scancode;
  last_scancode_valid = -1;
 }
 if (lastkeypress_chain) lastkeypress_chain(scancode);
}
END_OF_STATIC_FUNCTION(lastkeypress_callback);

int lastkeypressed()
{
 if (!last_scancode_valid) return update_joystick_vkeys();
 last_scancode_valid = 0;
 return last_scancode;
}

int AskKey(const char *msg, int *whatkey, SNES_CONTROLLER_INPUTS *input)
{
 int tmp;

 if (!lastkeypress_locked)
 {
  LOCK_VARIABLE(lastkeypress_chain);
  LOCK_VARIABLE(last_scancode);
  LOCK_VARIABLE(last_scancode_valid);
  LOCK_FUNCTION((void *)lastkeypress_callback);
  lastkeypress_locked = -1;
 }

 lastkeypress_chain = keyboard_lowlevel_callback;
 keyboard_lowlevel_callback = lastkeypress_callback;


 UpdateControllerScreen(input);

 PlotStringShadow(ControlSetup_window, default_font,
  msg, 84, 96, 15, 8);

 refresh_gui();


 do tmp = lastkeypressed(); while (!tmp);
 if (keypressed()) readkey(); /* throw away the key */

 keyboard_lowlevel_callback = lastkeypress_chain;

 if(tmp==KEY_ESC) return FALSE;

 *whatkey=tmp;

 return TRUE;
}

void AskControllerInputs(SNES_CONTROLLER_INPUTS *input)
{
 clear_keybuf();

 if (AskKey("Press key for UP", &input->up, input))
  if (AskKey("Press key for DOWN", &input->down, input))
  if (AskKey("Press key for LEFT", &input->left, input))
  if (AskKey("Press key for RIGHT", &input->right, input))
  if (AskKey("Press key for A", &input->a, input))
  if (AskKey("Press key for B", &input->b, input))
  if (AskKey("Press key for X", &input->x, input))
  if (AskKey("Press key for Y", &input->y, input))
  if (AskKey("Press key for L", &input->l, input))
  if (AskKey("Press key for R", &input->r, input))
  if (AskKey("Press key for SELECT", &input->select, input))
  if (AskKey("Press key for START", &input->start, input))
 {
  UpdateControllerScreen(input);

  PlotStringShadow(ControlSetup_window,default_font,
   "Press ESC to exit",84,96,15,8);

  refresh_gui();


  for (;;)
  {
   while (!keypressed());
   if ((readkey() >> 8) == KEY_ESC) break;
  }
 }
}

int ControlsWindow()
{
//int temp;

 switch(CONTROLLER_1_TYPE)
 {
  case 1:
   if (mouse_available)
   {
    Controls_Options[CONTROLS_CONTROLLER_1] = "Mouse on player 1";
    break;
   }
  default:
   Controls_Options[CONTROLS_CONTROLLER_1] = "Joypad on player 1";
   CONTROLLER_1_TYPE=0;
 }

 switch(CONTROLLER_2_TYPE)
 {
  case 1:
   if (mouse_available)
   {
    Controls_Options[CONTROLS_CONTROLLER_2] = "Mouse on player 2";
    break;
   }
  default:
   Controls_Options[CONTROLS_CONTROLLER_2] = "Joypad on player 2";
   CONTROLLER_2_TYPE=0;
 }

 int CursorAt=0;
 int keypress, key_asc, key_scan;
 clear_keybuf();

 for(;;)
 {
  UpdateControlsWindow(CursorAt);
  refresh_gui();

  while (!keypressed());
  keypress = readkey();
  key_asc = keypress & 0xFF;
  key_scan = keypress >> 8;

  switch (key_scan)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -