- add "create image" for hard disk image

- now the megabytes field is a wxStaticText, which makes it clear that
  it cannot be edited.
- add "enter size/compute geometry" button for HD image
- make a few more strings into #defines in wxdialog.h
- disable most of the Edit menu during simulation, reenable it when
  simulation stops
This commit is contained in:
Bryce Denney 2002-08-29 23:18:10 +00:00
parent e7fbe9e04e
commit 2aba2436fa
4 changed files with 151 additions and 47 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////
// $Id: wxdialog.cc,v 1.8 2002-08-29 21:00:27 bdenney Exp $
// $Id: wxdialog.cc,v 1.9 2002-08-29 23:18:10 bdenney Exp $
/////////////////////////////////////////////////////////////////
//
// misc/wxdialog.cc
@ -73,12 +73,12 @@ LogMsgAskDialog::LogMsgAskDialog(
{
for (int i=0; i<N_BUTTONS; i++) enabled[i] = TRUE;
vertSizer = new wxBoxSizer(wxVERTICAL);
context = new wxStaticText (this, -1, "Context: ");
context = new wxStaticText (this, -1, "");
wxFont font = context->GetFont ();
font.SetWeight (wxBOLD);
font.SetPointSize (2 + font.GetPointSize ());
context->SetFont (font);
message = new wxStaticText (this, -1, "Message: ");
message = new wxStaticText (this, -1, "");
message->SetFont (font);
dontAsk = new wxCheckBox (this, -1, LOG_MSG_DONT_ASK_STRING);
btnSizer = new wxBoxSizer(wxHORIZONTAL);
@ -93,13 +93,13 @@ LogMsgAskDialog::LogMsgAskDialog(
void LogMsgAskDialog::SetContext (char *s) {
wxString text;
text.Printf ("Context: %s", s);
text.Printf (LOG_MSG_CONTEXT, s);
ChangeStaticText (vertSizer, context, text);
}
void LogMsgAskDialog::SetMessage (char *s) {
wxString text;
text.Printf ("Message: %s", s);
text.Printf (LOG_MSG_MSG, s);
ChangeStaticText (vertSizer, message, text);
}
@ -146,7 +146,7 @@ void LogMsgAskDialog::OnEvent(wxCommandEvent& event)
void LogMsgAskDialog::ShowHelp ()
{
wxMessageBox("No help is available yet.", "No Help", wxOK | wxICON_ERROR );
wxMessageBox(MSG_NO_HELP, MSG_NO_HELP_CAPTION, wxOK | wxICON_ERROR );
}
//////////////////////////////////////////////////////////////////////
@ -406,7 +406,7 @@ void FloppyConfigDialog::CreateImage ()
void FloppyConfigDialog::ShowHelp ()
{
wxMessageBox("No help is available yet.", "No Help", wxOK | wxICON_ERROR );
wxMessageBox(MSG_NO_HELP, MSG_NO_HELP_CAPTION, wxOK | wxICON_ERROR );
}
//////////////////////////////////////////////////////////////////////
@ -427,8 +427,8 @@ void FloppyConfigDialog::ShowHelp ()
// " sectors/track "
// geom[2] = spt control
// hsizer[2]:
// "Size in MB: "
// megs text control
// megs = "Size in MB: NUMBER"
// compute geometry button
// buttonSizer:
// help
// cancel
@ -448,7 +448,6 @@ HDConfigDialog::HDConfigDialog(
: wxDialog (parent, id, "", wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
computeMegs = TRUE;
static char *geomNames[] = HD_CONFIG_GEOM_NAMES;
vertSizer = new wxBoxSizer (wxVERTICAL);
enable = new wxCheckBox (this, ID_Enable, "Enabled");
@ -480,17 +479,19 @@ HDConfigDialog::HDConfigDialog(
hsizer[1]->Add (geom[i]);
}
// contents of hsizer[2]
text = new wxStaticText (this, ID_Megs, HD_CONTROL_MEGS); // size in megs
hsizer[2]->Add (text);
megs = new wxTextCtrl (this, -1);
megs = new wxStaticText (this, ID_Megs, ""); // size in megs
hsizer[2]->Add (megs);
computeGeom = new wxButton (this, ID_ComputeGeometry, HD_CONFIG_COMPUTE_TEXT);
hsizer[2]->Add (computeGeom, 0, wxLEFT, 20);
// contents of buttonSizer
btn = new wxButton (this, wxHELP, "Help");
btn = new wxButton (this, wxHELP, BTNLABEL_HELP);
buttonSizer->Add (btn, 0, wxALL, 5);
// use wxID_CANCEL because pressing ESC produces this same code
btn = new wxButton (this, wxID_CANCEL, "Cancel");
btn = new wxButton (this, wxID_CANCEL, BTNLABEL_CANCEL);
buttonSizer->Add (btn, 0, wxALL, 5);
btn = new wxButton (this, wxOK, "Ok");
btn = new wxButton (this, ID_Create, BTNLABEL_CREATE_IMG);
buttonSizer->Add (btn, 0, wxALL, 5);
btn = new wxButton (this, wxOK, BTNLABEL_OK);
buttonSizer->Add (btn, 0, wxALL, 5);
// lay it out!
SetAutoLayout(TRUE);
@ -514,18 +515,21 @@ void HDConfigDialog::SetGeom (int n, int value) {
printf ("setting geom[%d] to %d\n", n, value);
geom[n]->SetValue (value);
printf ("now geom[%d] has value %d\n", n, geom[n]->GetValue ());
if (computeMegs) ComputeMegs ();
UpdateMegs ();
}
void HDConfigDialog::ComputeMegs () {
float
HDConfigDialog::UpdateMegs () {
float meg = 512.0
* geom[0]->GetValue ()
* geom[1]->GetValue ()
* geom[2]->GetValue ()
/ (1024.0*1024.0);
wxString text;
text.Printf ("%.1f", meg);
megs->SetValue (text);
text.Printf (HD_CONFIG_MEGS, meg);
ChangeStaticText (hsizer[2], megs, text);
Layout ();
return meg;
}
void HDConfigDialog::Init()
@ -560,18 +564,34 @@ void HDConfigDialog::OnEvent(wxCommandEvent& event)
case ID_Cylinders:
case ID_Heads:
case ID_SPT:
if (computeMegs) ComputeMegs ();
UpdateMegs ();
break;
case ID_ComputeGeometry:
EnterSize ();
break;
case ID_Create:
{
int cyl = geom[0]->GetValue ();
int heads = geom[1]->GetValue ();
int spt = geom[2]->GetValue ();
int sectors = cyl*heads*spt;
char name[1024];
strncpy (name, filename->GetValue ().c_str (), sizeof(name));
CreateImage (1, sectors, name);
wxString msg;
msg.Printf ("Created a %d megabyte disk image called '%s'.",
sectors*512, name);
wxMessageBox(msg, "Image Created", wxOK | wxICON_INFORMATION);
}
break;
case ID_Enable:
{
bool en = enable->GetValue ();
filename->Enable (en);
for (int i=0; i<3; i++) geom[i]->Enable (en);
megs->Enable (en);
computeGeom->Enable (en);
}
break;
case ID_Megs:
break;
case wxOK:
// probably should validate before allowing ok
EndModal (0);
@ -595,9 +615,54 @@ void HDConfigDialog::OnEvent(wxCommandEvent& event)
}
}
void HDConfigDialog::EnterSize ()
{
int initval = (int) (0.5 + UpdateMegs ());
int target_megs = wxGetNumberFromUser (HD_CONFIG_COMPUTE_INSTR, HD_CONFIG_COMPUTE_PROMPT, HD_CONFIG_COMPUTE_CAPTION, initval, 0, 32255);
if (target_megs<0) return;
// this calculate copied from misc/bximage.c
int cyl, heads=16, spt=63;
cyl = (int) (target_megs*1024.0*1024.0/16.0/63.0/512.0);
wxASSERT (cyl < 65536);
geom[0]->SetValue (cyl);
geom[1]->SetValue (heads);
geom[2]->SetValue (spt);
UpdateMegs ();
}
bool
HDConfigDialog::CreateImage (int harddisk, int sectors, const char *filename)
{
if (sectors<1) {
wxMessageBox("The disk size is invalid.", "Invalid Size", wxOK | wxICON_ERROR );
return false;
}
wxLogDebug ("filename = '%s'\n", filename);
if (strlen (filename) < 1) {
wxMessageBox("You must type a file name for the new disk image.", "Bad Filename", wxOK | wxICON_ERROR );
return false;
}
// try first with overwrite flag = 0
int ret = SIM->create_disk_image (filename, sectors, 0);
if (ret == -1) { // already exists
int answer = wxMessageBox ("File exists. Do you want to overwrite it?",
"File exists", wxYES_NO | wxCENTER);
if (answer == wxYES)
ret = SIM->create_disk_image (filename, sectors, 1);
else
return false; // wxNO
}
if (ret == -2) {
wxMessageBox("I could not create the disk image. Check for permission problems or available disk space.", "Failed", wxOK | wxICON_ERROR );
return false;
}
wxASSERT (ret==0);
return true;
}
void HDConfigDialog::ShowHelp ()
{
wxMessageBox("No help is available yet.", "No Help", wxOK | wxICON_ERROR );
wxMessageBox(MSG_NO_HELP, MSG_NO_HELP_CAPTION, wxOK | wxICON_ERROR );
}
/////////////////////////////////////////////////////////////////

View File

@ -1,11 +1,21 @@
////////////////////////////////////////////////////////////////////
// $Id: wxdialog.h,v 1.7 2002-08-29 22:09:55 bdenney Exp $
// $Id: wxdialog.h,v 1.8 2002-08-29 23:18:10 bdenney Exp $
////////////////////////////////////////////////////////////////////
//
// wxWindows dialogs for Bochs
#include "wx/spinctrl.h"
////////////////////////////////////////////////////////////////////
// text messages used in several places
////////////////////////////////////////////////////////////////////
#define MSG_NO_HELP "No help is available yet."
#define MSG_NO_HELP_CAPTION "No help"
#define BTNLABEL_HELP "Help"
#define BTNLABEL_CANCEL "Cancel"
#define BTNLABEL_OK "Ok"
#define BTNLABEL_CREATE_IMG "Create Image"
////////////////////////////////////////////////////////////////////
// LogMsgAskDialog is a modal dialog box that shows the user a
// simulation error message and asks if they want to continue or
@ -38,6 +48,8 @@ public:
{ "Continue", "Die", "Dump Core", "Debugger", "Help" }
#define LOG_MSG_DONT_ASK_STRING \
"Don't ask about future messages like this"
#define LOG_MSG_CONTEXT "Context: %s"
#define LOG_MSG_MSG "Message: %s"
private:
wxStaticText *context, *message;
wxCheckBox *dontAsk;
@ -171,11 +183,12 @@ DECLARE_EVENT_TABLE()
// +-----Configure Hard Disk-------------------------------------------+
// | |
// | [ ] Enable |
// | Disk image: [______________________________] [Browse] |
// | Geometry: cylinders [____] heads [____] sectors/track [____] |
// | Size in Megabytes: _____ |
// | |
// | [ Help ] [ Cancel ] [ Ok ] |
// | Disk image: [______________________________] [Browse] |
// | Geometry: cylinders [____] heads [____] sectors/track [____] |
// | Size in Megabytes: 38.2 [Enter size/Compute Geometry] |
// | |
// | [ Help ] [ Cancel ] [ Create image ] [ Ok ] |
// +-------------------------------------------------------------------+
//
// To use this dialog:
@ -198,12 +211,16 @@ private:
wxCheckBox *enable;
wxTextCtrl *filename;
wxSpinCtrl *geom[3];
wxTextCtrl *megs;
wxStaticText *megs;
wxButton *computeGeom;
enum geomfields_t { CYL, HEADS, SPT };
#define HD_CONFIG_GEOM_NAMES \
{ "Geometry: cylinders", " heads ", " sectors/track " }
#define HD_CONTROL_MEGS "Size in Megabytes: "
bool computeMegs;
#define HD_CONFIG_MEGS "Size in Megabytes: %.1f"
#define HD_CONFIG_COMPUTE_TEXT "<-- Enter Size/Compute Geometry"
#define HD_CONFIG_COMPUTE_INSTR "Enter size of the hard disk image in megabytes. Between 1 and 32255 please!"
#define HD_CONFIG_COMPUTE_PROMPT "Size in megs: "
#define HD_CONFIG_COMPUTE_CAPTION "Choose Disk Size"
public:
HDConfigDialog(wxWindow* parent, wxWindowID id);
void OnEvent (wxCommandEvent& event);
@ -214,8 +231,10 @@ public:
void SetGeom (int n, int value);
int GetGeom (int n) { return geom[n]->GetValue (); }
void SetGeomRange (int n, int min, int max) { geom[n]->SetRange (min, max); }
void ComputeMegs ();
float UpdateMegs ();
void SetEnable (bool val) { enable->SetValue (val); }
bool GetEnable () { return enable->GetValue (); }
void EnterSize ();
bool CreateImage (int harddisk, int sectors, const char *filename);
DECLARE_EVENT_TABLE()
};

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////
// $Id: wxmain.cc,v 1.13 2002-08-29 14:59:37 bdenney Exp $
// $Id: wxmain.cc,v 1.14 2002-08-29 23:18:10 bdenney Exp $
/////////////////////////////////////////////////////////////////
//
// wxmain.cc implements the wxWindows frame, toolbar, menus, and dialogs.
@ -146,8 +146,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_Edit_HD_0, MyFrame::OnOtherEvent)
EVT_MENU(ID_Edit_HD_1, MyFrame::OnOtherEvent)
// toolbar events
EVT_TOOL(ID_Toolbar_FloppyA, MyFrame::OnToolbarClick)
EVT_TOOL(ID_Toolbar_FloppyB, MyFrame::OnToolbarClick)
EVT_TOOL(ID_Edit_FD_0, MyFrame::OnToolbarClick)
EVT_TOOL(ID_Edit_FD_1, MyFrame::OnToolbarClick)
EVT_TOOL(ID_Toolbar_CdromD, MyFrame::OnToolbarClick)
EVT_TOOL(ID_Toolbar_Reset, MyFrame::OnToolbarClick)
EVT_TOOL(ID_Toolbar_Power, MyFrame::OnToolbarClick)
@ -176,8 +176,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
menuConfiguration->Append (ID_Quit, "&Quit");
menuEdit = new wxMenu;
menuEdit->Append( ID_Toolbar_FloppyA, "Floppy Disk &0..." );
menuEdit->Append( ID_Toolbar_FloppyB, "Floppy Disk &1..." );
menuEdit->Append( ID_Edit_FD_0, "Floppy Disk &0..." );
menuEdit->Append( ID_Edit_FD_1, "Floppy Disk &1..." );
menuEdit->Append( ID_Edit_HD_0, "Hard Disk 0..." );
menuEdit->Append( ID_Edit_HD_1, "Hard Disk 1..." );
menuEdit->Append( ID_Edit_Boot, "&Boot..." );
@ -228,8 +228,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
#define BX_ADD_TOOL(id, xpm_name, tooltip) \
do {tb->AddTool(id, wxBitmap(xpm_name), wxNullBitmap, FALSE, currentX, -1, (wxObject *)NULL, tooltip); currentX += 34; } while (0)
BX_ADD_TOOL(ID_Toolbar_FloppyA, floppya_xpm, "Change Floppy A");
BX_ADD_TOOL(ID_Toolbar_FloppyB, floppyb_xpm, "Change Floppy B");
BX_ADD_TOOL(ID_Edit_FD_0, floppya_xpm, "Change Floppy A");
BX_ADD_TOOL(ID_Edit_FD_1, floppyb_xpm, "Change Floppy B");
BX_ADD_TOOL(ID_Toolbar_CdromD, cdromd_xpm, "Change CDROM");
BX_ADD_TOOL(ID_Toolbar_Reset, reset_xpm, "Reset the system");
BX_ADD_TOOL(ID_Toolbar_Power, power_xpm, "Turn power on/off");
@ -285,8 +285,6 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
void MyFrame::simStatusChanged (StatusChange change, Boolean popupNotify) {
switch (change) {
case Start: // running
menuConfiguration->Enable (ID_Config_New, FALSE);
menuConfiguration->Enable (ID_Config_Read, FALSE);
menuSimulate->Enable (ID_Simulate_Start, FALSE);
menuSimulate->Enable (ID_Simulate_PauseResume, TRUE);
menuSimulate->Enable (ID_Simulate_Stop, TRUE);
@ -312,6 +310,26 @@ void MyFrame::simStatusChanged (StatusChange change, Boolean popupNotify) {
menuSimulate->SetLabel (ID_Simulate_PauseResume, "&Pause");
break;
}
bool canConfigure = (change == Stop);
menuConfiguration->Enable (ID_Config_New, canConfigure);
menuConfiguration->Enable (ID_Config_Read, canConfigure);
menuEdit->Enable (ID_Edit_HD_0, canConfigure);
menuEdit->Enable (ID_Edit_HD_1, canConfigure);
menuEdit->Enable( ID_Edit_Boot, canConfigure);
menuEdit->Enable( ID_Edit_Vga, canConfigure);
menuEdit->Enable( ID_Edit_Memory, canConfigure);
menuEdit->Enable( ID_Edit_Sound, canConfigure);
menuEdit->Enable( ID_Edit_Network, canConfigure);
menuEdit->Enable( ID_Edit_Keyboard, canConfigure);
menuEdit->Enable( ID_Edit_Other, canConfigure);
// during simulation, certain menu options like the floppy disk
// can be modified under some circumstances. A floppy drive can
// only be edited if it was enabled at boot time.
bx_param_c *floppy;
floppy = SIM->get_param(BXP_FLOPPYA);
menuEdit->Enable (ID_Edit_FD_0, canConfigure || floppy->get_enabled ());
floppy = SIM->get_param(BXP_FLOPPYB);
menuEdit->Enable (ID_Edit_FD_1, canConfigure || floppy->get_enabled ());
}
void MyFrame::OnStartSim(wxCommandEvent& WXUNUSED(event))
@ -591,7 +609,8 @@ void MyFrame::editFloppyConfig (int drive)
wxLogError ("floppy params have wrong type");
return;
}
dlg.AddRadio ("None/Disabled", "none");
dlg.AddRadio ("Not Present", "none");
dlg.AddRadio ("Ejected", "none");
dlg.AddRadio ("Physical floppy drive /dev/fd0", "/dev/fd0");
dlg.AddRadio ("Physical floppy drive /dev/fd1", "/dev/fd1");
dlg.SetCapacity (disktype->get () - disktype->get_min ());
@ -651,11 +670,11 @@ void MyFrame::OnToolbarClick(wxCommandEvent& event)
switch (id) {
case ID_Toolbar_Power:which = BX_TOOLBAR_POWER; break;
case ID_Toolbar_Reset: which = BX_TOOLBAR_RESET; break;
case ID_Toolbar_FloppyA:
case ID_Edit_FD_0:
// floppy config dialog box
editFloppyConfig (0);
break;
case ID_Toolbar_FloppyB:
case ID_Edit_FD_1:
// floppy config dialog box
editFloppyConfig (1);
break;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////
// $Id: wxmain.h,v 1.9 2002-08-29 20:13:05 bdenney Exp $
// $Id: wxmain.h,v 1.10 2002-08-29 23:18:10 bdenney Exp $
/////////////////////////////////////////////////////////////////
// This file defines variables and classes that the wxWindows .cc files
// share. It should be included only by wx.cc and wxmain.cc.
@ -79,6 +79,7 @@ enum
ID_Heads,
ID_SPT,
ID_Megs,
ID_ComputeGeometry,
};