unit frmProfileSettingsUnt;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, Profile, ExtCtrls, ComCtrls, ToolWin;

type
  TfrmProfileSettings = class(TForm)
    lblFilename: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    edtTitle: TEdit;
    GroupBox1: TGroupBox;
    rbStandard: TRadioButton;
    rbECS: TRadioButton;
    btnOK: TBitBtn;
    btnCancel: TBitBtn;
    Label8: TLabel;
    edtManufacturer: TEdit;
    Label9: TLabel;
    edtYear: TEdit;
    rbKBDC: TRadioButton;
    rbImagic4800: TRadioButton;
    Label3: TLabel;
    tbMemory: TToolBar;
    btn0: TToolButton;
    btn1: TToolButton;
    btn2: TToolButton;
    btn3: TToolButton;
    btn4: TToolButton;
    btn5: TToolButton;
    btn6: TToolButton;
    btn7: TToolButton;
    btn8: TToolButton;
    btn9: TToolButton;
    btnA: TToolButton;
    btnB: TToolButton;
    btnC: TToolButton;
    btnD: TToolButton;
    btnE: TToolButton;
    btnF: TToolButton;
    procedure FormShow(Sender: TObject);
    procedure btnOKClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmProfileSettings: TfrmProfileSettings;

implementation

{$R *.DFM}

Uses Base, frmMenuunt, frmMainunt;

procedure TfrmProfileSettings.FormShow(Sender: TObject);
begin
  lblFileName.Caption := ExtractFileName(MenuInfo.FileName);
  If MenuInfo.ProfileRec <> Nil Then
  Begin
    edtTitle.Text        := MenuInfo.ProfileRec.RealName;
    edtManufacturer.Text := MenuInfo.ProfileRec.Manufacturer;
    If MenuInfo.ProfileRec.Year <> 0
     Then edtYear.Text := IntToStr(MenuInfo.ProfileRec.Year)
     Else edtYear.Text := '';
    Case MenuInfo.ProfileRec.Cart Of
 ctStandard: rbStandard.Checked   := True;
     ct4800: rbImagic4800.Checked := True;
      ctECS: rbECS.Checked        := True;
     ct6502: rbKBDC.Checked       := True;
    Else
      rbStandard.Checked := True;
    End; // Case
    btn0.Down := (Pos('0',MenuInfo.ProfileRec.MemStr) <> 0);
    btn1.Down := (Pos('1',MenuInfo.ProfileRec.MemStr) <> 0);
    btn2.Down := (Pos('2',MenuInfo.ProfileRec.MemStr) <> 0);
    btn3.Down := (Pos('3',MenuInfo.ProfileRec.MemStr) <> 0);
    btn4.Down := (Pos('4',MenuInfo.ProfileRec.MemStr) <> 0);
    btn5.Down := (Pos('5',MenuInfo.ProfileRec.MemStr) <> 0);
    btn6.Down := (Pos('6',MenuInfo.ProfileRec.MemStr) <> 0);
    btn7.Down := (Pos('7',MenuInfo.ProfileRec.MemStr) <> 0);
    btn8.Down := (Pos('8',MenuInfo.ProfileRec.MemStr) <> 0);
    btn9.Down := (Pos('9',MenuInfo.ProfileRec.MemStr) <> 0);
    btnA.Down := (Pos('A',MenuInfo.ProfileRec.MemStr) <> 0);
    btnB.Down := (Pos('B',MenuInfo.ProfileRec.MemStr) <> 0);
    btnC.Down := (Pos('C',MenuInfo.ProfileRec.MemStr) <> 0);
    btnD.Down := (Pos('D',MenuInfo.ProfileRec.MemStr) <> 0);
    btnE.Down := (Pos('E',MenuInfo.ProfileRec.MemStr) <> 0);
    btnF.Down := (Pos('F',MenuInfo.ProfileRec.MemStr) <> 0);
  End
  Else
  Begin
    btn0.Down            := False;
    btn1.Down            := False;
    btn2.Down            := False;
    btn3.Down            := False;
    btn4.Down            := False;
    btn5.Down            := False;
    btn6.Down            := False;
    btn7.Down            := False;
    btn8.Down            := False;
    btn9.Down            := False;
    btnA.Down            := False;
    btnB.Down            := False;
    btnC.Down            := False;
    btnD.Down            := False;
    btnE.Down            := False;
    btnF.Down            := False;
    edtTitle.Text        := '';
    rbStandard.Checked   := True;
    edtManufacturer.Text := '';
    edtYear.Text         := '';
  End;
end;

procedure TfrmProfileSettings.btnOKClick(Sender: TObject);
Var
  RealName     : String;
  Path         : String;
  Dir          : String;
  Name         : String;
  I            : Integer;
  Manufacturer : String;
  Year         : Integer;
  MemStr       : String;

  Function GetNum(St: String): Integer;
  Var I,J: Integer;
  Begin
    St := Trim(St);
    If St <> '' Then
    Begin
      Val(St,I,J);
      If J = 0 Then GetNum := I Else GetNum := 0;
    End
    Else GetNum := 0;
  End; // GetYear

begin
  If rbStandard.Checked
   Then Cart := ctStandard
   Else If rbECS.Checked Then Cart := ctECS
   Else If rbImagic4800.Checked Then Cart := ct4800
   Else Cart := ct6502;
  RealName     := Trim(edtTitle.Text);
  Manufacturer := Trim(edtManufacturer.Text);
  Year         := GetNum(edtYear.Text);
  MemStr       := '';
  If btn0.Down Then MemStr := MemStr + '0';
  If btn1.Down Then MemStr := MemStr + '1';
  If btn2.Down Then MemStr := MemStr + '2';
  If btn3.Down Then MemStr := MemStr + '3';
  If btn4.Down Then MemStr := MemStr + '4';
  If btn5.Down Then MemStr := MemStr + '5';
  If btn6.Down Then MemStr := MemStr + '6';
  If btn7.Down Then MemStr := MemStr + '7';
  If btn8.Down Then MemStr := MemStr + '8';
  If btn9.Down Then MemStr := MemStr + '9';
  If btnA.Down Then MemStr := MemStr + 'A';
  If btnB.Down Then MemStr := MemStr + 'B';
  If btnC.Down Then MemStr := MemStr + 'C';
  If btnD.Down Then MemStr := MemStr + 'D';
  If btnE.Down Then MemStr := MemStr + 'E';
  If btnF.Down Then MemStr := MemStr + 'F';

  // Remove double quotes from title (switch to single quotes)

  For I := 1 To Length(RealName) Do If RealName[I] = '"' Then RealName[I] := '''';

  // Save profile information

  If MenuInfo.ProfileRec <> Nil Then
  Begin
    MenuInfo.ProfileRec.Cart         := Cart;
    MenuInfo.ProfileRec.RealName     := RealName;
    MenuInfo.ProfileRec.Manufacturer := Manufacturer;
    MenuInfo.ProfileRec.Year         := Year;
    MenuInfo.ProfileRec.MemStr       := MemStr;
  End
  Else
  Begin
    Path := ExpandFileName(UpperCase(MenuInfo.FileName));
    Name := ExtractFileName(Path);
    Dir  := ExtractFilePath(Path);
    AddToProfile(Name,RealName,Cart,Manufacturer,Year,MemStr);
  End;
  MakeProfile(ExtractFilePath(Application.ExeName));
end;

end.

// ----------------------------------------------------------------------
// IntvWin - Mattel Intellivision Emulator
// Copyright (C) 2000 John Dullea
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// ----------------------------------------------------------------------
