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

📄 debugoptions.pas

📁 一个不出名的GBA模拟器
💻 PAS
字号:
//////////////////////////////////////////////////////////////////////
//                                                                  //
// DebugOptions.pas: Debug Options Dialog                           //
//                                                                  //
// The contents of this file are subject to the Bottled Light       //
// Public License Version 1.0 (the "License"); you may not use this //
// file except in compliance with the License. You may obtain a     //
// copy of the License at http://www.bottledlight.com/BLPL/         //
//                                                                  //
// Software distributed under the License is distributed on an      //
// "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or   //
// implied. See the License for the specific language governing     //
// rights and limitations under the License.                        //
//                                                                  //
// The Original Code is the Mappy VM User Interface, released       //
// April 1st, 2003. The Initial Developer of the Original Code is   //
// Bottled Light, Inc. Portions created by Bottled Light, Inc. are  //
// Copyright (C) 2001-2003 Bottled Light, Inc. All Rights Reserved. //
//                                                                  //
// Author(s):                                                       //
//   Michael Noland (joat), michael@bottledlight.com                //
//                                                                  //
// Changelog:                                                       //
//   1.0: First public release (April 1st, 2003)                    //
//                                                                  //
// Notes:                                                           //
//   None at present.                                               //
//                                                                  //
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
unit DebugOptions; ///////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
interface ////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IniFiles, CheckLst, Math, CpuObservers, nexus,
  console, romUtils, AddressSpace;

//////////////////////////////////////////////////////////////////////

type
  TDebugOptionsDialog = class(TCpuObserver)
    loggingGroup: TGroupBox;
    loggingOptions: TCheckListBox;
    biosGroup: TGroupBox;
    eBiosLocation: TEdit;
    biosBrowse: TButton;
    cAutopatchHeader: TCheckBox;
    cUseFastLoader: TCheckBox;
    cInternalBIOS: TCheckBox;
    bReload: TButton;
    openDialog: TOpenDialog;
    bClearConsole: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure changeLoggingOptions(Sender: TObject);
    procedure clearTheConsole(Sender: TObject);
    procedure ChooseNewBIOS(Sender: TObject);
    procedure ToggleInternalBIOS(Sender: TObject);
    procedure ReloadBIOS(Sender: TObject);
    procedure ChangeOptions(Sender: TObject);
  public
    procedure UpdateObserver; override;
    class function OCaption: string; override;
  end;

//////////////////////////////////////////////////////////////////////

var
  DebugOptionsDialog: TDebugOptionsDialog;

  // BIOS options
  autopatchLogo: boolean;
  useFastLoader: boolean;
  biosFilename: string;

//////////////////////////////////////////////////////////////////////

procedure LoadDebugOptions(ini: TIniFile);
procedure SaveDebugOptions(ini: TIniFile);

//////////////////////////////////////////////////////////////////////
implementation ///////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

{$R *.DFM}
{$R bios.res}

//////////////////////////////////////////////////////////////////////

var
  logInvalidStates: boolean;
  logDMAtransfers: boolean;
  logBIOScalls: boolean;
  logIOwrites: boolean;

//////////////////////////////////////////////////////////////////////

procedure SetDebuggingFlags;
begin
  vmSetOption(PChar('logInvalidStates'), logInvalidStates);
  vmSetOption(PChar('logDMAtransfers'), logDMAtransfers);
  vmSetOption(PChar('logBIOScalls'), logBIOScalls);
  vmSetOption(PChar('logIOwrites'), logIOwrites);
end;

//////////////////////////////////////////////////////////////////////
// BIOS Searching / Loading //////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

function VerifyBIOSFilename(filename: string): string;
var
  f: TSearchRec;
begin
  Result := filename;
  if (Result <> '%internal%') and not FileExists(Result) then begin
    Result := '';

    if FindFirst(ExtractFilePath(ParamStr(0)) + 'gba.rom', faAnyFile, f) = 0 then Result := f.Name;
    FindClose(f);

    if Result = '' then begin
      if FindFirst(ExtractFilePath(ParamStr(0)) + 'v5.bios', faAnyFile, f) = 0 then Result := f.Name;
      FindClose(f);
    end;

    if Result = '' then begin
      if FindFirst(ExtractFilePath(ParamStr(0)) + '*.bios', faAnyFile, f) = 0 then Result := f.Name;
      FindClose(f);
    end;

    if Result = '' then begin
      if FindFirst(ExtractFilePath(ParamStr(0)) + '*.rom', faAnyFile, f) = 0 then Result := f.Name;
      FindClose(f);
    end;

    if Result = '' then
      Result := '%internal%'
    else
      Result := ExtractFilePath(ParamStr(0)) + Result;
  end;
end;

//////////////////////////////////////////////////////////////////////

procedure LoadBIOS;
var
  stream: TFileStream;
  systemROM: array[0..16383] of byte;
  i: integer;
  banks: TvmMemoryLock1;
begin
  biosFilename := VerifyBIOSFilename(biosFilename);

  if coreLoaded then begin
    // Load a BIOS
    FillChar(systemROM, 16384, 0);
    if FileExists(biosFilename) then begin
      logWriteLn('Loading external BIOS "' + biosFilename + '"');
      stream := TFileStream.Create(biosFilename, fmOpenRead);
      stream.Read(systemROM, Min(16384, stream.Size));
      stream.Free;
    end else begin
      logWriteLn('Loading internal BIOS');
      biosFilename := '%internal%';
      LoadResourceFile('bios.BIOS', systemROM, 16384);
    end;

    vmLockMemory(banks);
    Move(systemROM, banks.bios^, 16384);
    vmUnlockMemory(banks);

    // Search for the logo in the BIOS
    headerIndex := -1;
    for i := $0 to $3F64 do
      if crc32(0, @(systemROM[i]), $9C) = $D0BEB55E then begin
        headerIndex := i;
        Break;
      end;
  end;
end;

//////////////////////////////////////////////////////////////////////
// TDebugOptionsDialog ///////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

procedure TDebugOptionsDialog.FormCreate(Sender: TObject);
begin
  HelpContext := LinkHelp('debug_options.html');
end;

//////////////////////////////////////////////////////////////////////

procedure TDebugOptionsDialog.FormShow(Sender: TObject);
begin
  // Logging options
  loggingOptions.Checked[0] := logInvalidStates;
  loggingOptions.Checked[1] := logDMAtransfers;
  loggingOptions.Checked[2] := logBIOScalls;
  loggingOptions.Checked[3] := logIOwrites;

  // BIOS Options
  cInternalBIOS.Checked := biosFilename = '%internal%';
  eBiosLocation.Text := biosFilename;

  // Load the translation
  LoadTranslation(self, translation);
end;

//////////////////////////////////////////////////////////////////////

procedure TDebugOptionsDialog.changeLoggingOptions(Sender: TObject);
begin
  logInvalidStates := loggingOptions.Checked[0];
  logDMAtransfers := loggingOptions.Checked[1];
  logBIOScalls := loggingOptions.Checked[2];
  logIOwrites := loggingOptions.Checked[3];
  SetDebuggingFlags;
end;

//////////////////////////////////////////////////////////////////////

procedure TDebugOptionsDialog.clearTheConsole(Sender: TObject);
begin
  logProcessCommand('clear');
end;

//////////////////////////////////////////////////////////////////////

procedure TDebugOptionsDialog.ChooseNewBIOS(Sender: TObject);
begin
  openDialog.InitialDir := ExtractFilePath(biosFilename);
  if openDialog.Execute then begin
    cInternalBIOS.Checked := false;
    eBiosLocation.Text := openDialog.FileName;
  end;
end;

//////////////////////////////////////////////////////////////////////

procedure TDebugOptionsDialog.ToggleInternalBIOS(Sender: TObject);
begin
  if cInternalBIOS.Checked then
    eBiosLocation.Text := '%internal%'
  else
    eBiosLocation.Text := VerifyBIOSFilename('');
end;
//////////////////////////////////////////////////////////////////////

procedure TDebugOptionsDialog.ReloadBIOS(Sender: TObject);
begin
  biosFilename := eBiosLocation.Text;
  LoadBIOS;
end;

//////////////////////////////////////////////////////////////////////

procedure TDebugOptionsDialog.ChangeOptions(Sender: TObject);
begin
  autopatchLogo := cAutopatchHeader.Checked;
  useFastLoader := cUseFastLoader.Checked;
end;

//////////////////////////////////////////////////////////////////////
// Debugging Preferences /////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

procedure LoadDebugOptions(ini: TIniFile);
begin
  // Read logging settings
  logInvalidStates := ini.ReadBool('Core', 'InvalidStates', false);
  logDMAtransfers := ini.ReadBool('Core', 'DMAtransfers', false);
  logBIOScalls := ini.ReadBool('Core', 'BIOScalls', false);
  logIOwrites := ini.ReadBool('Core', 'IOwrites', false);

  // Read BIOS settings
  biosFilename := ini.ReadString('BIOS', 'Filename', '');
  autopatchLogo := ini.ReadBool('BIOS', 'PatchHeader', true);
  useFastLoader := ini.ReadBool('BIOS', 'BypassBoot', false);

  // Apply settings
  LoadBIOS;
end;

//////////////////////////////////////////////////////////////////////

procedure SaveDebugOptions(ini: TIniFile);
begin
  // Write logging settings
  ini.WriteBool('Core', 'InvalidStates', logInvalidStates);
  ini.WriteBool('Core', 'DMAtransfers', logDMAtransfers);
  ini.WriteBool('Core', 'BIOScalls', logBIOScalls);
  ini.WriteBool('Core', 'IOwrites', logIOwrites);

  // Write BIOS settings
  ini.WriteString('BIOS', 'Filename', biosFilename);
  ini.WriteBool('BIOS', 'PatchHeader', autopatchLogo);
  ini.WriteBool('BIOS', 'BypassBoot', useFastLoader);
end;

//////////////////////////////////////////////////////////////////////

class function TDebugOptionsDialog.OCaption: string;
begin
  Result := 'Core Options';
end;

//////////////////////////////////////////////////////////////////////

procedure TDebugOptionsDialog.UpdateObserver;
begin
//
end;

//////////////////////////////////////////////////////////////////////

initialization
  RegisterDialog(TDebugOptionsDialog);
end.

//////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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