1
0
mirror of https://github.com/livingcomputermuseum/ContrAlto.git synced 2026-01-21 02:07:30 +00:00

183 lines
5.6 KiB
C#

/*
This file is part of ContrAlto.
ContrAlto 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 3 of the License, or
(at your option) any later version.
ContrAlto 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 ContrAlto. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Windows.Forms;
namespace Contralto
{
public partial class AlternateBootOptions : Form
{
public AlternateBootOptions()
{
InitializeComponent();
LoadBootEntries();
if (Configuration.AlternateBootType == AlternateBootType.Disk)
{
DiskBootRadioButton.Checked = true;
}
else
{
EthernetBootRadioButton.Checked = true;
}
SetBootAddress(Configuration.BootAddress);
SelectBootFile(Configuration.BootFile);
}
private void LoadBootEntries()
{
foreach(BootFileEntry e in _bootEntries)
{
BootFileComboBox.Items.Add(e);
}
}
private void SelectBootFile(ushort fileNumber)
{
// Find the matching entry, if any.
bool found = false;
for (int i = 0; i < BootFileComboBox.Items.Count; i++)
{
if (((BootFileEntry)BootFileComboBox.Items[i]).FileNumber == fileNumber)
{
BootFileComboBox.Select(i, 1);
BootFileComboBox.Text = BootFileComboBox.Items[i].ToString();
found = true;
break;
}
}
if (!found)
{
// No matching entry, just fill in the text box with the number.
BootFileComboBox.Text = Conversion.ToOctal(fileNumber);
}
}
private void SetBootAddress(ushort address)
{
DiskBootAddressTextBox.Text = Conversion.ToOctal(address);
}
private void BootFileComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
_selectedBootFile = ((BootFileEntry)BootFileComboBox.SelectedItem).FileNumber;
}
private void OKButton_Click(object sender, EventArgs e)
{
try
{
_selectedBootAddress = Convert.ToUInt16(DiskBootAddressTextBox.Text, 8);
}
catch
{
MessageBox.Show("The disk boot address must be an octal value between 0 and 177777.");
return;
}
if (BootFileComboBox.SelectedItem == null)
{
try
{
_selectedBootFile = Convert.ToUInt16(BootFileComboBox.Text, 8);
}
catch
{
MessageBox.Show("Please select a valid boot entry or type in a valid boot number.", "Invalid selection");
return;
}
}
else
{
_selectedBootFile = ((BootFileEntry)BootFileComboBox.SelectedItem).FileNumber;
}
Configuration.BootAddress = _selectedBootAddress;
Configuration.BootFile = _selectedBootFile;
if (DiskBootRadioButton.Checked)
{
Configuration.AlternateBootType = AlternateBootType.Disk;
}
else
{
Configuration.AlternateBootType = AlternateBootType.Ethernet;
}
this.Close();
}
private void CancelButton_Click(object sender, EventArgs e)
{
this.Close();
}
private BootFileEntry[] _bootEntries = new BootFileEntry[]
{
new BootFileEntry(0, "DMT"),
new BootFileEntry(1, "NewOS"),
new BootFileEntry(2, "FTP"),
new BootFileEntry(3, "Scavenger"),
new BootFileEntry(4, "CopyDisk"),
new BootFileEntry(5, "CRTTest"),
new BootFileEntry(6, "MADTest"),
new BootFileEntry(7, "Chat"),
new BootFileEntry(8, "NetExec"),
new BootFileEntry(9, "PupTest"),
new BootFileEntry(10, "EtherWatch"),
new BootFileEntry(11, "KeyTest"),
new BootFileEntry(13, "DiEx"),
new BootFileEntry(15, "EDP"),
new BootFileEntry(16, "BFSTest"),
new BootFileEntry(17, "GateControl"),
new BootFileEntry(18, "EtherLoad"),
};
private ushort _selectedBootFile;
private ushort _selectedBootAddress;
}
public struct BootFileEntry
{
public BootFileEntry(ushort number, string desc)
{
FileNumber = number;
Description = desc;
}
public override string ToString()
{
return String.Format("{0} - {1}", Conversion.ToOctal(FileNumber), Description);
}
public override bool Equals(object obj)
{
return base.Equals(obj);
}
public ushort FileNumber;
public string Description;
}
}