direct.cpp

来自「DGen源码最后版本」· C++ 代码 · 共 1,821 行 · 第 1/4 页

CPP
1,821
字号
  //  HMENU hm=LoadMenu(main_inst,"DGENMENU");
  //  EnableMenuItem(,0x100,MF_CHANGE | MF_CHECKED);
  //EnableMenuItem(GetSubMenu(GetMenu(hWnd), 0), 0x101, MF_CHECKED);
  //CheckMenuItem(GetSubMenu(GetMenu(hWnd), 1), 0x0111, MF_CHECKED);
  return 0;
}

// parses the config file
static int load_config(char *name)
{
  int done=0;
  FILE *hand;
  int i;
  int no_config_file=0;

  hand=fopen(name,"rt");
  if (hand==NULL)
  {
    no_config_file=1;
  }
  else
  {
    no_config_file=0;
    done=0;
    while (!done)
    {
      static char buf[256]="";
      if (fgets(buf,255,hand)==NULL) done=1;
      else
      {
        char *check_for=NULL;
        int slen=strlen(buf);

        // Knock off linefeeds, because they will mess up strings
        if (buf[slen-1]==10) {buf[slen-1]=0; slen--;}

#define IT_IS (strncmp(buf,check_for,strlen(check_for))==0)
#define VALUE (buf+strlen(check_for))
        // Graphics
        check_for="fullscreen";
        if (IT_IS) fullscreen=atoi(VALUE);
        check_for="width";
        if (IT_IS) width=atoi(VALUE);
        check_for="height";
        if (IT_IS) height=atoi(VALUE);
        check_for="depth";
        if (IT_IS) depth=atoi(VALUE);
        check_for="force_depth";
        if (IT_IS) force_depth=atoi(VALUE);
        check_for="brightness";
        if (IT_IS) brightness=atof(VALUE);
        check_for="contrast";
        if (IT_IS) contrast=atof(VALUE);
        check_for="umul";
        if (IT_IS) umul=atof(VALUE);
        check_for="vmul";
        if (IT_IS) vmul=atof(VALUE);
        check_for="crap_tv";
        if (IT_IS) crap_tv=atoi(VALUE);

        // Sound
        check_for="no_sound";
        if (IT_IS) no_sound=atoi(VALUE);
        check_for="snd_rate";
        if (IT_IS) snd_rate=atoi(VALUE);
        check_for="snd_segs";
        if (IT_IS) snd_segs=atoi(VALUE);
        check_for="snd_distort";
        if (IT_IS) snd_distort=atof(VALUE);
        check_for="stereo16";
        if (IT_IS) stereo16=atoi(VALUE);

        // Input
        check_for="pad_code[";
        if (IT_IS)
        {
          char *next_bit;
          int p=strtol(VALUE,&next_bit,10);
          if (next_bit!=NULL)
          {
            if (next_bit[0]==']')
            {
              if (next_bit[1]==' ')
              {
                int val=strtol(next_bit+2,NULL,0);
                pad_code[p&31]=val;
              }
            }
          }
        }

        // Paths
        check_for="rom_path";
        if (IT_IS) if (*VALUE)
            strncpy(rom_path,VALUE+1,0x7ff);
        check_for="state_path";
        if (IT_IS) if (*VALUE)
        strncpy(state_path,VALUE+1,0x7ff);

        // Misc
        check_for="virtual_fps";
        if (IT_IS) virtual_fps=atoi(VALUE);
        check_for="any_size";
        if (IT_IS) any_size=atoi(VALUE);
        check_for="split_screen";
        if (IT_IS) split_screen=atoi(VALUE);
        check_for="country_ver";
        if (IT_IS) megad.country_ver=strtol(VALUE,NULL,0);
        check_for="cpu_emu";
        if (IT_IS) megad.change_cpu_emu(atoi(VALUE));
        check_for="auto_saveload";
        if (IT_IS) auto_saveload=atoi(VALUE);
        check_for="sram_saveload";
        if (IT_IS) sram_saveload=atoi(VALUE);
      }
    }
  
    fclose(hand);
  }

  return no_config_file;
}

static int unload_config(char *name)
{
  int i;
  FILE *hand=fopen(name,"wt");

  if (hand==NULL) return 1;

  fprintf(hand,"// Dave's DGEN v%s (DirectX) config file\n\n",VER);
  fprintf(hand,"// Note, 0=off, 1=on\n");

  fprintf(hand,"\n// Graphics\n");
  fprintf(hand,"fullscreen %d\n",fullscreen);
  fprintf(hand,"width %d\n",width);
  fprintf(hand,"height %d\n",height);
  fprintf(hand,"depth %d\n",depth);
  fprintf(hand,"force_depth %d\n",force_depth);
  fprintf(hand,"brightness %.2f\n",brightness);
  fprintf(hand,"contrast %.2f\n",contrast);
  fprintf(hand,"umul %.2f\n",umul);
  fprintf(hand,"vmul %.2f\n",vmul);
  fprintf(hand,"crap_tv %d\n",crap_tv);

  fprintf(hand,"\n\n// Sound (halve rate or increase segs if you have trouble)\n");
  fprintf(hand,"no_sound %d\n",no_sound);
  fprintf(hand,"snd_rate %d\n",snd_rate);
  fprintf(hand,"snd_segs %d\n",snd_segs);
  fprintf(hand,"snd_distort %.2f\n",snd_distort);
  fprintf(hand,"stereo16 %d\n",stereo16);

  fprintf(hand,"\n\n// Input\n");
  for (i=0;i<32;i++)
    fprintf(hand,"pad_code[%.2d] 0x%.5x\n",i,pad_code[i]);

  fprintf(hand,"\n\n// Paths\n");
  fprintf(hand,"rom_path %s\n",rom_path);
  fprintf(hand,"state_path %s\n",state_path);

  fprintf(hand,"\n\n// Misc.\n");
  fprintf(hand,"virtual_fps %d\n",virtual_fps);
  fprintf(hand,"any_size %d\n",any_size);
  fprintf(hand,"split_screen %d\n",split_screen);
  fprintf(hand,"country_ver 0x%.2x\n",megad.country_ver);
  fprintf(hand,"cpu_emu %d\n",megad.cpu_emu);
  fprintf(hand,"auto_saveload %d\n",auto_saveload);
  fprintf(hand,"sram_saveload %d\n",sram_saveload);

  fprintf(hand,"\n");
  fclose(hand);
  return 0;
}

BOOL get_rom_name()
{
	OPENFILENAME	open;
  char  Filter[]=
    "Genesis Roms (*.bin;*.smd;*.zip)\0"
    "*.bin;*.smd;*.zip\0"
    "Zipped Roms (*.zip)\0"
    "*.zip\0"
    "All Files\0"
    "*.*\0";
	memset(&open, 0, sizeof(OPENFILENAME));

	open.lStructSize=sizeof(OPENFILENAME);
  open.lpstrInitialDir=rom_path;
	open.lpstrFilter=&Filter[0];
  rom_name[0]=0;
  open.lpstrFile=rom_name;
  open.nMaxFile=0x7ff;
  open.lpstrTitle="Load Rom Image";
  open.Flags=OFN_HIDEREADONLY;
  if (GetOpenFileName(&open)==0) return 1;

  int i; i=strlen(rom_name);
  for (;i>=0;i--) if (rom_name[i]=='\\') break;
  if (i>0x7ff) i=0x7ff;
  memcpy(rom_path,rom_name,i);
  rom_path[i]=0;

  return 0;
}

BOOL get_save_name(int save,int sram)
{
	OPENFILENAME	open;
  char      gsx_filt[]="*.gs*\0*.gs*\0All Files\0*.*\0";
  char      srm_filt[]="*.sr*\0*.sr*\0All Files\0*.*\0";
  char *Filter;
  if (sram) Filter=srm_filt; else Filter=gsx_filt;

  memset(&open, 0, sizeof(OPENFILENAME));

	open.lStructSize=sizeof(OPENFILENAME);
  open.lpstrInitialDir=state_path;
	open.lpstrFilter=&Filter[0];

  if (megad.romfilename[0]==0)
    save_name[0]=0;
  else
    sprintf (save_name,"%.8s.%s%c",gst_name(megad.romfilename),
      sram?"sr":"gs", save?(sram?'m':'x'):'*');
  open.lpstrFile=save_name;

  open.nMaxFile=0x7ff;
  if (sram)
  {
    open.lpstrTitle=save?"Save State to...":"Load State from...";
  }
  else
  {
    open.lpstrTitle=save?"Save SRAM to...":"Load SRAM from...";
  }

  open.Flags=OFN_HIDEREADONLY;
  if (save)
  {
    if (GetSaveFileName(&open)==0) return 1;
  }
  else
  {
    if (GetOpenFileName(&open)==0) return 1;
  }

  int i; i=strlen(save_name);
  for (;i>=0;i--) if (save_name[i]=='\\') break;
  if (i>0x7ff) i=0x7ff;
  memcpy(state_path,save_name,i);
  state_path[i]=0;

  return 0;
}

static int manual_defining_keys=0;
static int upto=0,waiting_to_release=-1;
HWND rwin;
static HFONT hnewsfont;   // handle of new fixed font

long int  PASCAL  man_def_keys_proc(HWND rwin, UINT message,WPARAM wParam, LPARAM lParam)
{
  static char kname[12][32]={"Up","Down","Left","Right","A","B","C","Start","X","Y","Z","Mode"};
  switch (message)
  {

    case WM_PAINT:
    {
      PAINTSTRUCT ps;
      HDC  hdc = BeginPaint(rwin, &ps);

      // Establish fixed font in display context.
      SelectObject(hdc, hnewsfont);

      SetTextAlign (hdc, TA_BASELINE /* | TA_CENTER */);

      sprintf (temp,"Manual Define keys for pad %c",manual_defining_keys==1?'A':'B');
      TextOut(hdc, 16, 20, temp, strlen(temp));

      if (upto<=-1)
      {
        sprintf (temp,"(Waiting for 0x%.5x to be released) <===",waiting_to_release);
        TextOut(hdc, 16, 50-1*16, temp, strlen(temp));
      }

      if (upto>=12)
      {
        sprintf (temp,"(Done - Press any key to exit.) <===");
        TextOut(hdc, 16, 50+13*16, temp, strlen(temp));
      }

      int i;
      for (i=0;i<12;i++)
      {
        sprintf (temp,"0x%.5x = %s %s",
          pad_code[(manual_defining_keys==1)?(0+i):(16+i)],kname[i],
            (upto==i)?"<=== (press a button / escape to skip)":"");
        TextOut(hdc, 16, 50+i*16, temp, strlen(temp));
      }
      EndPaint(rwin,&ps);
    }
    break;

    case WM_QUIT:
    case WM_DESTROY:  // message: window being destroyed
      manual_defining_keys=0;
    break;

    default:      // Passes it on if unproccessed
      return (DefWindowProc(rwin, message, wParam, lParam));
  }
  return 0L;
}

static int manual_define_keys()
{
  HDC hDC;
  static LOGFONT   cursfont;           // font structure
  static HFONT     holdsfont;   // handle of original font

  upto=-1;
  // Create a window
  rwin = CreateWindow(
   "manual_define",                 // See RegisterClass() call.
   "Manual Define Keys",
	 WS_OVERLAPPEDWINDOW,        // Window style.
   160,120,160+300,120+190,
	 NULL,                  // Overlapped windows have no parent.
	 NULL,                  // Use the window class menu.
   main_inst,              // This instance owns this window.
	 NULL                   // Pointer not needed.
  );

  if (!rwin) return 1;
  // Get the display context.
  hDC = GetDC(rwin);

  // Build fixed screen font.
  cursfont.lfHeight         =  14;
  cursfont.lfWidth          =  9;
  cursfont.lfEscapement     =  0;
  cursfont.lfOrientation    =  0;
  cursfont.lfWeight         =  FW_NORMAL;
  cursfont.lfItalic         =  FALSE;
  cursfont.lfUnderline      =  FALSE;
  cursfont.lfStrikeOut      =  FALSE;
  cursfont.lfCharSet        =  ANSI_CHARSET;
  cursfont.lfOutPrecision   =  OUT_DEFAULT_PRECIS;
  cursfont.lfClipPrecision  =  CLIP_DEFAULT_PRECIS;
  cursfont.lfQuality        =  DEFAULT_QUALITY;
  cursfont.lfPitchAndFamily =  FIXED_PITCH | FF_DONTCARE;
  strcpy((char *)cursfont.lfFaceName, "System");

  hnewsfont = CreateFontIndirect((LPLOGFONT) &cursfont);

  // Install the font in the current display context.
//  holdsfont = SelectObject(hDC, hnewsfont);

  // get text metrics for paint
//  GetTextMetrics(hDC, &tm);
//  xChar = tm.tmAveCharWidth;
//  yChar = tm.tmHeight + tm.tmExternalLeading;
//  yCharnl = tm.tmHeight;

  // Release the display context.
  ReleaseDC(rwin, hDC);

  // Make the window visible; update its client area;

  ShowWindow(rwin, 1); // Show the window
  InvalidateRect(rwin, NULL, TRUE);
  UpdateWindow(rwin);     // Sends WM_PAINT message

  return 0;
}

static int manual_define_update()
{
  int code;

  input_update();

  if (upto>=12)
  {
    if (input_check(-1)!=-1)
      DestroyWindow(rwin);
    return 0;
  }

  if (input_check(0x01) || input_check(0x201)) code=0x01; // just in case
  else code=input_check(-1);

  if (upto<=-1)
  {
    if (code==0x01 || code==-1)
    {
      upto++;
    }
    else
    {
      waiting_to_release=code;
    }
    InvalidateRect(rwin, NULL, TRUE);
    UpdateWindow(rwin);

    return 0;
  }

  if (code!=-1)
  {
    if (code!=0x01)
    {
      pad_code[ ((manual_defining_keys==1)?(0+upto):(16+upto))&31 ]=code;
      update_menu(); // common_code match may have changed
    }
    upto++;

    InvalidateRect(rwin, NULL, TRUE);
    UpdateWindow(rwin);

    int done=0;
    while(!done)
    {
      input_update();
      if (input_check(code)==0) done=1;
      if (code!=0x01) if (input_check(0x01)) done=1;
      if (code!=0x201) if (input_check(0x201)) done=1;
    }
  }

  return 0;
}

/**********************************************************************/
BOOL InitApplication(HINSTANCE hInstance)
{
  WNDCLASS  wc;

  // Fill in window class structure with parameters that describe the
  // main window.

  wc.style = CS_HREDRAW | CS_VREDRAW; // Class style(s).
  wc.lpfnWndProc = MainWndProc; // Function to retrieve messages for
									 // windows of this class.
  wc.cbClsExtra = 0;  // No per-class extra data.
  wc.cbWndExtra = 0;  // No per-window extra data.
  wc.hInstance = hInstance; // Application that owns the class.
  wc.hIcon = LoadIcon(hInstance,"DGENICON"); /*LoadIcon(NULL, 0x3000 IDI_APPLICATION ); */
  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
  wc.lpszMenuName = "DGENMENU";  // Name of menu resource in .RC file.
  wc.lpszClassName = "DGENMAIN"; // Name used in call to CreateWindow.

  /* Register the window class and return success/failure code. */

  RegisterClass(&wc);

⌨️ 快捷键说明

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