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

📄 emugui.cpp

📁 NES game Emulator in Linux.c and asm codes.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
 PlotString(HWStatus_window,default_font,Number,default_font->get_widthspace()*15,default_font->get_heightspace()*7);
 sprintf(Number, "%02X", (unsigned) Win1_Bands_Out[1]);
 PlotString(HWStatus_window,default_font,Number,default_font->get_widthspace()*18,default_font->get_heightspace()*7);
 sprintf(Number, "%02X", (unsigned) Win1_Bands_Out[2]);
 PlotString(HWStatus_window,default_font,Number,default_font->get_widthspace()*21,default_font->get_heightspace()*7);
 sprintf(Number, "%02X", (unsigned) Win1_Bands_Out[3]);
 PlotString(HWStatus_window,default_font,Number,default_font->get_widthspace()*24,default_font->get_heightspace()*7);

 PlotString(HWStatus_window,default_font,"Win2:# ## ## # ## ## ## ##",0,default_font->get_heightspace()*8);
 sprintf(Number, "%1X", (unsigned) Win2_Count_In);
 PlotString(HWStatus_window,default_font,Number,default_font->get_widthspace()*5,default_font->get_heightspace()*8);
 sprintf(Number, "%02X", (unsigned) Win2_Bands_In[0]);
 PlotString(HWStatus_window,default_font,Number,default_font->get_widthspace()*7,default_font->get_heightspace()*8);
 sprintf(Number, "%02X", (unsigned) Win2_Bands_In[1]);
 PlotString(HWStatus_window,default_font,Number,default_font->get_widthspace()*10,default_font->get_heightspace()*8);
 sprintf(Number, "%1X", (unsigned) Win2_Count_Out);
 PlotString(HWStatus_window,default_font,Number,default_font->get_widthspace()*13,default_font->get_heightspace()*8);
 sprintf(Number, "%02X", (unsigned) Win2_Bands_Out[0]);
 PlotString(HWStatus_window,default_font,Number,default_font->get_widthspace()*15,default_font->get_heightspace()*8);
 sprintf(Number, "%02X", (unsigned) Win2_Bands_Out[1]);
 PlotString(HWStatus_window,default_font,Number,default_font->get_widthspace()*18,default_font->get_heightspace()*8);
 sprintf(Number, "%02X", (unsigned) Win2_Bands_Out[2]);
 PlotString(HWStatus_window,default_font,Number,default_font->get_widthspace()*21,default_font->get_heightspace()*8);
 sprintf(Number, "%02X", (unsigned) Win2_Bands_Out[3]);
 PlotString(HWStatus_window,default_font,Number,default_font->get_widthspace()*24,default_font->get_heightspace()*8);

 refresh_gui();

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

extern "C" unsigned char MDMAEN;
extern "C" unsigned char HDMAEN;
extern "C" unsigned char DMAP_0, DMAP_1, DMAP_2, DMAP_3;
extern "C" unsigned char DMAP_4, DMAP_5, DMAP_6, DMAP_7;
extern "C" unsigned char BBAD_0, BBAD_1, BBAD_2, BBAD_3;
extern "C" unsigned char BBAD_4, BBAD_5, BBAD_6, BBAD_7;
extern "C" unsigned char A1TL_0, A1TL_1, A1TL_2, A1TL_3;
extern "C" unsigned char A1TL_4, A1TL_5, A1TL_6, A1TL_7;
extern "C" unsigned char A1TH_0, A1TH_1, A1TH_2, A1TH_3;
extern "C" unsigned char A1TH_4, A1TH_5, A1TH_6, A1TH_7;
extern "C" unsigned char A1B_0, A1B_1, A1B_2, A1B_3;
extern "C" unsigned char A1B_4, A1B_5, A1B_6, A1B_7;
extern "C" unsigned char DASL_0, DASL_1, DASL_2, DASL_3;
extern "C" unsigned char DASL_4, DASL_5, DASL_6, DASL_7;
extern "C" unsigned char DASH_0, DASH_1, DASH_2, DASH_3;
extern "C" unsigned char DASH_4, DASH_5, DASH_6, DASH_7;
extern "C" unsigned char DASB_0, DASB_1, DASB_2, DASB_3;
extern "C" unsigned char DASB_4, DASB_5, DASB_6, DASB_7;
extern "C" unsigned char A2L_0, A2L_1, A2L_2, A2L_3;
extern "C" unsigned char A2L_4, A2L_5, A2L_6, A2L_7;
extern "C" unsigned char A2H_0, A2H_1, A2H_2, A2H_3;
extern "C" unsigned char A2H_4, A2H_5, A2H_6, A2H_7;
extern "C" unsigned char A2B_0, A2B_1, A2B_2, A2B_3;
extern "C" unsigned char A2B_4, A2B_5, A2B_6, A2B_7;

WINDOW *DMAStatus_window=0;

void DMAStatus(void)
{
 char Line[34];

 DMAStatus_window->refresh();
 sprintf(Line,"MDMAEN:%02X HDMAEN:%02X",
  (unsigned) MDMAEN, (unsigned) HDMAEN);
 PlotString(DMAStatus_window,default_font,Line,0,0);

 sprintf(Line,"%02X %02X %02X%02X%02X %02X%02X%02X %02X%02X%02X",
 (unsigned) DMAP_0,(unsigned) BBAD_0,
 (unsigned) A1B_0,(unsigned) A1TH_0,(unsigned) A1TL_0,
 (unsigned) A2B_0,(unsigned) A2H_0,(unsigned) A2L_0,
 (unsigned) DASB_0,(unsigned) DASH_0,(unsigned) DASL_0);
 PlotString(DMAStatus_window,default_font,Line,0,default_font->get_heightspace());

 sprintf(Line,"%02X %02X %02X%02X%02X %02X%02X%02X %02X%02X%02X",
 (unsigned) DMAP_1,(unsigned) BBAD_1,
 (unsigned) A1B_1,(unsigned) A1TH_1,(unsigned) A1TL_1,
 (unsigned) A2B_1,(unsigned) A2H_1,(unsigned) A2L_1,
 (unsigned) DASB_1,(unsigned) DASH_1,(unsigned) DASL_1);
 PlotString(DMAStatus_window,default_font,Line,0,default_font->get_heightspace()*2);

 sprintf(Line,"%02X %02X %02X%02X%02X %02X%02X%02X %02X%02X%02X",
 (unsigned) DMAP_2,(unsigned) BBAD_2,
 (unsigned) A1B_2,(unsigned) A1TH_2,(unsigned) A1TL_2,
 (unsigned) A2B_2,(unsigned) A2H_2,(unsigned) A2L_2,
 (unsigned) DASB_2,(unsigned) DASH_2,(unsigned) DASL_2);
 PlotString(DMAStatus_window,default_font,Line,0,default_font->get_heightspace()*3);

 sprintf(Line,"%02X %02X %02X%02X%02X %02X%02X%02X %02X%02X%02X",
 (unsigned) DMAP_3,(unsigned) BBAD_3,
 (unsigned) A1B_3,(unsigned) A1TH_3,(unsigned) A1TL_3,
 (unsigned) A2B_3,(unsigned) A2H_3,(unsigned) A2L_3,
 (unsigned) DASB_3,(unsigned) DASH_3,(unsigned) DASL_3);
 PlotString(DMAStatus_window,default_font,Line,0,default_font->get_heightspace()*4);

 sprintf(Line,"%02X %02X %02X%02X%02X %02X%02X%02X %02X%02X%02X",
 (unsigned) DMAP_4,(unsigned) BBAD_4,
 (unsigned) A1B_4,(unsigned) A1TH_4,(unsigned) A1TL_4,
 (unsigned) A2B_4,(unsigned) A2H_4,(unsigned) A2L_4,
 (unsigned) DASB_4,(unsigned) DASH_4,(unsigned) DASL_4);
 PlotString(DMAStatus_window,default_font,Line,0,default_font->get_heightspace()*5);

 sprintf(Line,"%02X %02X %02X%02X%02X %02X%02X%02X %02X%02X%02X",
 (unsigned) DMAP_5,(unsigned) BBAD_5,
 (unsigned) A1B_5,(unsigned) A1TH_5,(unsigned) A1TL_5,
 (unsigned) A2B_5,(unsigned) A2H_5,(unsigned) A2L_5,
 (unsigned) DASB_5,(unsigned) DASH_5,(unsigned) DASL_5);
 PlotString(DMAStatus_window,default_font,Line,0,default_font->get_heightspace()*6);

 sprintf(Line,"%02X %02X %02X%02X%02X %02X%02X%02X %02X%02X%02X",
 (unsigned) DMAP_6,(unsigned) BBAD_6,
 (unsigned) A1B_6,(unsigned) A1TH_6,(unsigned) A1TL_6,
 (unsigned) A2B_6,(unsigned) A2H_6,(unsigned) A2L_6,
 (unsigned) DASB_6,(unsigned) DASH_6,(unsigned) DASL_6);
 PlotString(DMAStatus_window,default_font,Line,0,default_font->get_heightspace()*7);

 sprintf(Line,"%02X %02X %02X%02X%02X %02X%02X%02X %02X%02X%02X",
 (unsigned) DMAP_7,(unsigned) BBAD_7,
 (unsigned) A1B_7,(unsigned) A1TH_7,(unsigned) A1TL_7,
 (unsigned) A2B_7,(unsigned) A2H_7,(unsigned) A2L_7,
 (unsigned) DASB_7,(unsigned) DASH_7,(unsigned) DASL_7);
 PlotString(DMAStatus_window,default_font,Line,0,default_font->get_heightspace()*8);

 refresh_gui();

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

WINDOW *APUStatus_window=0;

void APUStatus(void)
{
 char Line[34];
 int v,i;

 APUStatus_window->refresh();
 sprintf(Line,"SNDkeys:%02X", (unsigned) SNDkeys);
 PlotString(APUStatus_window,default_font,Line,0,0);

 for (v = 0; v < 8; v++)
 {
  for (i = 0; i < 16; i++)
  {
   sprintf(Line,"%02X", (unsigned) SPC_DSP[i + (v << 4)]);
   PlotString(APUStatus_window,default_font,Line,
   i * 3 * default_font->get_widthspace(),
   (v + 1) * default_font->get_heightspace());
  }
 }

 refresh_gui();

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

extern unsigned char WinBG1_Main_Count, WinBG1_Main_Bands[6];
extern unsigned char WinBG1_Sub_Count, WinBG1_Sub_Bands[6];
extern unsigned char WinBG2_Main_Count, WinBG2_Main_Bands[6];
extern unsigned char WinBG2_Sub_Count, WinBG2_Sub_Bands[6];
extern unsigned char WinBG3_Main_Count, WinBG3_Main_Bands[6];
extern unsigned char WinBG3_Sub_Count, WinBG3_Sub_Bands[6];
extern unsigned char WinBG4_Main_Count, WinBG4_Main_Bands[6];
extern unsigned char WinBG4_Sub_Count, WinBG4_Sub_Bands[6];

WINDOW *BGWinStatus_window=0;

void BGWinStatus(void)
{
 char Line[34];

 BGWinStatus_window->refresh();
 sprintf(Line,"BG1M: %02X: %02X %02X %02X %02X %02X %02X",
  (unsigned) WinBG1_Main_Count,
  (unsigned) WinBG1_Main_Bands[0],
  (unsigned) WinBG1_Main_Bands[1],
  (unsigned) WinBG1_Main_Bands[2],
  (unsigned) WinBG1_Main_Bands[3],
  (unsigned) WinBG1_Main_Bands[4],
  (unsigned) WinBG1_Main_Bands[5]);
 PlotString(BGWinStatus_window,default_font,Line,0,0);

 sprintf(Line,"BG1S: %02X: %02X %02X %02X %02X %02X %02X",
  (unsigned) WinBG1_Sub_Count,
  (unsigned) WinBG1_Sub_Bands[0],
  (unsigned) WinBG1_Sub_Bands[1],
  (unsigned) WinBG1_Sub_Bands[2],
  (unsigned) WinBG1_Sub_Bands[3],
  (unsigned) WinBG1_Sub_Bands[4],
  (unsigned) WinBG1_Sub_Bands[5]);
 PlotString(BGWinStatus_window,default_font,Line,
  0, default_font->get_heightspace());

 sprintf(Line,"BG2M: %02X: %02X %02X %02X %02X %02X %02X",
  (unsigned) WinBG2_Main_Count,
  (unsigned) WinBG2_Main_Bands[0],
  (unsigned) WinBG2_Main_Bands[1],
  (unsigned) WinBG2_Main_Bands[2],
  (unsigned) WinBG2_Main_Bands[3],
  (unsigned) WinBG2_Main_Bands[4],
  (unsigned) WinBG2_Main_Bands[5]);
 PlotString(BGWinStatus_window,default_font,Line,
  0, 2 * default_font->get_heightspace());

 sprintf(Line,"BG2S: %02X: %02X %02X %02X %02X %02X %02X",
  (unsigned) WinBG2_Sub_Count,
  (unsigned) WinBG2_Sub_Bands[0],
  (unsigned) WinBG2_Sub_Bands[1],
  (unsigned) WinBG2_Sub_Bands[2],
  (unsigned) WinBG2_Sub_Bands[3],
  (unsigned) WinBG2_Sub_Bands[4],
  (unsigned) WinBG2_Sub_Bands[5]);
 PlotString(BGWinStatus_window,default_font,Line,
  0, 3 * default_font->get_heightspace());

 sprintf(Line,"BG3M: %02X: %02X %02X %02X %02X %02X %02X",
  (unsigned) WinBG3_Main_Count,
  (unsigned) WinBG3_Main_Bands[0],
  (unsigned) WinBG3_Main_Bands[1],
  (unsigned) WinBG3_Main_Bands[2],
  (unsigned) WinBG3_Main_Bands[3],
  (unsigned) WinBG3_Main_Bands[4],
  (unsigned) WinBG3_Main_Bands[5]);
 PlotString(BGWinStatus_window,default_font,Line,
  0, 4 * default_font->get_heightspace());

 sprintf(Line,"BG3S: %02X: %02X %02X %02X %02X %02X %02X",
  (unsigned) WinBG3_Sub_Count,
  (unsigned) WinBG3_Sub_Bands[0],
  (unsigned) WinBG3_Sub_Bands[1],
  (unsigned) WinBG3_Sub_Bands[2],
  (unsigned) WinBG3_Sub_Bands[3],
  (unsigned) WinBG3_Sub_Bands[4],
  (unsigned) WinBG3_Sub_Bands[5]);
 PlotString(BGWinStatus_window,default_font,Line,
  0, 5 * default_font->get_heightspace());

 sprintf(Line,"BG4M: %02X: %02X %02X %02X %02X %02X %02X",
  (unsigned) WinBG4_Main_Count,
  (unsigned) WinBG4_Main_Bands[0],
  (unsigned) WinBG4_Main_Bands[1],
  (unsigned) WinBG4_Main_Bands[2],
  (unsigned) WinBG4_Main_Bands[3],
  (unsigned) WinBG4_Main_Bands[4],
  (unsigned) WinBG4_Main_Bands[5]);
 PlotString(BGWinStatus_window,default_font,Line,
  0, 6 * default_font->get_heightspace());

 sprintf(Line,"BG4S: %02X: %02X %02X %02X %02X %02X %02X",
  (unsigned) WinBG4_Sub_Count,
  (unsigned) WinBG4_Sub_Bands[0],
  (unsigned) WinBG4_Sub_Bands[1],
  (unsigned) WinBG4_Sub_Bands[2],
  (unsigned) WinBG4_Sub_Bands[3],
  (unsigned) WinBG4_Sub_Bands[4],
  (unsigned) WinBG4_Sub_Bands[5]);
 PlotString(BGWinStatus_window,default_font,Line,
  0, 7 * default_font->get_heightspace());

 refresh_gui();

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

CTL *joypad_bitmap=0;

CTL_CLEAR GUI_clear(0);
CTL_CLEAR Main_clear;
CTL_CLEAR File_clear;
CTL_CLEAR Screen_clear;
CTL_CLEAR Config_clear;
CTL_CLEAR Sound_clear;
CTL_CLEAR ControlSetup_clear;
CTL_CLEAR ROMInfo_clear;
CTL_CLEAR HWStatus_clear;
CTL_CLEAR DMAStatus_clear;
CTL_CLEAR APUStatus_clear;
CTL_CLEAR BGWinStatus_clear;

int allocate_windows()
{
 GUI_window=new WINDOW(0,0,320,240);
 Main_window=new BORDER_WINDOW(0,0,16*default_font->get_widthspace(),MAIN_NUM_OPTIONS*default_font->get_heightspace());
 File_window=new BORDER_WINDOW(20,0,38*default_font->get_widthspace(),15*default_font->get_heightspace());
 Screen_window=new BORDER_WINDOW(100,30,21*default_font->get_widthspace(),NUM_SCREEN_OPTIONS*default_font->get_heightspace());
 Config_window=new BORDER_WINDOW(70,15,24*default_font->get_widthspace(),CONFIG_NUM_OPTIONS*default_font->get_heightspace());
 Controls_window=new BORDER_WINDOW(90,105,24*default_font->get_widthspace(),CONTROLS_NUM_OPTIONS*default_font->get_heightspace());
 Sound_window=new BORDER_WINDOW(90,105,24*default_font->get_widthspace(),SOUND_NUM_OPTIONS*default_font->get_heightspace());
 ControlSetup_window=new BORDER_WINDOW(29,34,168,104);
 ROMInfo_window=new BORDER_WINDOW(10,70,33*default_font->get_widthspace(),7*default_font->get_heightspace());
 HWStatus_window=new BORDER_WINDOW(10,70,33*default_font->get_widthspace(),9*default_font->get_heightspace());
 DMAStatus_window=new BORDER_WINDOW(10,70,33*default_font->get_widthspace(),9*default_font->get_heightspace());
 APUStatus_window=new BORDER_WINDOW(8,70,48*default_font->get_widthspace(),9*default_font->get_heightspace());
 BGWinStatus_window=new BORDER_WINDOW(8,70,48*default_font->get_widthspace(),9*default_font->get_heightspace());
 if(!(GUI_window && Main_window && File_window && Screen_window &&
    Config_window && Controls_window && Sound_window &&
    ControlSetup_window && ROMInfo_window && HWStatus_window &&
    DMAStatus_window && APUStatus_window && BGWinStatus_window))
     return 1;
 *GUI_window+=GUI_clear;
 *Main_window+=Main_clear;
 *File_window+=File_clear;
 *Screen_window+=Screen_clear;
 *Config_window+=Config_clear;
 *Controls_window+=Config_clear;
 *Sound_window+=Sound_clear;
 *ControlSetup_window+=ControlSetup_clear;
 if(joypad)
  joypad_bitmap=new CTL_BITMAP(ControlSetup_window,&joypad,7,12);
 *ROMInfo_window+=ROMInfo_clear;
 *HWStatus_window+=HWStatus_clear;
 *DMAStatus_window+=DMAStatus_clear;
 *APUStatus_window+=APUStatus_clear;
 *BGWinStatus_window+=BGWinStatus_clear;
 return 0;
}

void free_windows()
{
 delete GUI_window;
 delete Main_window;
 delete File_window;
 delete joypad_bitmap;
 delete Screen_window; delete Config_window; delete Sound_window;
 delete ControlSetup_window; delete ROMInfo_window;
 delete HWStatus_window; delete DMAStatus_window;
 delete APUStatus_window; delete BGWinStatus_window;

 GUI_window=0;
 Main_window=0;
 File_window=0;
 joypad_bitmap=0;
 Screen_window=0; Config_window=0; Sound_window=0;
 ControlSetup_window=0; ROMInfo_window=0; HWStatus_window=0;
 DMAStatus_window=0; APUStatus_window=0;
}

extern volatile unsigned Timer_Counter_Throttle;
extern volatile unsigned Timer_Counter_Profile;

GUI_ERROR GUI()
{
 if (allocate_windows()) return GUI_EXIT;

#ifndef NO_LOGO
 if (sneese)
 {  // Prevent a crash if file not found!
  set_palette(sneesepal);
 }
#endif

 set_palette_range(&GUIPal[-240],240,255,1);    // Set the GUI palette up.

 fill_backdrop(Allegro_Bitmap);

 clear_keybuf();

 int CursorAt = 0;

 for (;;)
 {
  int keypress, key_asc, key_scan;

  UpdateMainWindow(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 = MAIN_NUM_OPTIONS-1;
   break;

  case KEY_DOWN:
   CursorAt++;
   if(CursorAt == MAIN_NUM_OPTIONS) // so it wraps
    CursorAt=0;
   break;

  case KEY_ESC:
   if (snes_rom_loaded)
   {
    while (key[KEY_ESC]);
    goto resume_emulation;
   }
   break;

  case KEY_ENTER:
  case KEY_ENTER_PAD:
   if(snes_rom_loaded)
   {

    if (CursorAt == MAIN_RESUME_EMULATION) goto resume_emulation;
    if (CursorAt == MAIN_RESET_EMULATION)
    {
     snes_reset();
     goto resume_emulation;
    }

    if (CursorAt == MAIN_ROM_INFO)
     RomInfo();

    if (CursorAt == MAIN_HW_STATUS)
     HWStatus();

    if (CursorAt == MAIN_DMA_STATUS)
     DMAStatus();

    if (CursorAt == MAIN_APU_STATUS)
     APUStatus();

    if (CursorAt == MAIN_BGWIN_STATUS)
     BGWinStatus();
   }

   if (CursorAt == MAIN_LOAD_ROM)
   {
    const char *filename = FileWindow();

    if (filename)
    {
     // open_rom() needs the full path to the file
     if (!open_rom(filename))
     {
      //printf("Failed to load cartridge ROM.");
     }
     else
     {
      goto resume_emulation;
     }
    }
    break;
   }

   if (CursorAt == MAIN_CONFIGURE)
    ConfigWindow();

   if (CursorAt == MAIN_EXIT)
   {
    free_windows();
    return GUI_EXIT;
   }
  } //switch (key_scan)
 } //for (;;)

resume_emulation:

 acquire_screen();

 clear(screen);

 release_screen();

 clear(Allegro_Bitmap);

 free_windows();
 return GUI_CONTINUE;   // Signify normal exit
}

⌨️ 快捷键说明

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