From 6009e14996f36679d0e1ea52465c4e21600ad4cd Mon Sep 17 00:00:00 2001 From: Bryce Denney Date: Mon, 2 Sep 2002 20:13:52 +0000 Subject: [PATCH] - add MemoryConfigDialog that sets the ROM BIOS and VGA BIOS options, and also the optional rom settings. I think it all works except that the Browse buttons aren't hooked up yet. - modified Files: gui/wxdialog.cc gui/wxdialog.h gui/wxmain.cc gui/wxmain.h --- bochs/gui/wxdialog.cc | 228 +++++++++++++++++++++++++++++++++++++++--- bochs/gui/wxdialog.h | 113 ++++++++++++++++----- bochs/gui/wxmain.cc | 59 ++++++++++- bochs/gui/wxmain.h | 6 +- 4 files changed, 365 insertions(+), 41 deletions(-) diff --git a/bochs/gui/wxdialog.cc b/bochs/gui/wxdialog.cc index 33ca796d6..e5e3d57b0 100644 --- a/bochs/gui/wxdialog.cc +++ b/bochs/gui/wxdialog.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////// -// $Id: wxdialog.cc,v 1.17 2002-09-02 17:03:07 bdenney Exp $ +// $Id: wxdialog.cc,v 1.18 2002-09-02 20:13:43 bdenney Exp $ ///////////////////////////////////////////////////////////////// // // misc/wxdialog.cc @@ -36,9 +36,6 @@ enum { ID_MY_LAST_ID }; -void ChangeStaticText (wxSizer *sizer, wxStaticText *win, wxString newtext); -bool CreateImage (int harddisk, int sectors, const char *filename); - ////////////////////////////////////////////////////////////////////// // LogMsgAskDialog implementation ////////////////////////////////////////////////////////////////////// @@ -262,7 +259,7 @@ void FloppyConfigDialog::Init() // add contents of diskImageSizer diskImageSizer->Add (diskImageRadioBtn); diskImageSizer->Add (filename, 1, wxGROW); - wxButton *btn = new wxButton (this, ID_Browse, "<--Browse"); + wxButton *btn = new wxButton (this, ID_Browse, BTNLABEL_BROWSE); diskImageSizer->Add (btn, 0, wxALL, 5); radioSizer->Add (diskImageSizer); @@ -440,7 +437,7 @@ HDConfigDialog::HDConfigDialog( filename = new wxTextCtrl (this, ID_FilenameText); filename->SetSize (300, filename->GetSize ().GetHeight ()); hsizer[0]->Add (filename, 1); - wxButton *btn = new wxButton (this, ID_Browse, "<--Browse"); + wxButton *btn = new wxButton (this, ID_Browse, BTNLABEL_BROWSE); hsizer[0]->Add (btn); // contents of hsizer[1] for (int i=0; i<3; i++) { @@ -655,7 +652,7 @@ CdromConfigDialog::CdromConfigDialog( filename = new wxTextCtrl (this, ID_FilenameText); filename->SetSize (300, filename->GetSize ().GetHeight ()); fileSizer->Add (filename, 1, wxLEFT, 5); - wxButton *btn = new wxButton (this, ID_Browse, "<--Browse"); + wxButton *btn = new wxButton (this, ID_Browse, BTNLABEL_BROWSE); fileSizer->Add (btn, 0, wxALL, 5); // create buttonSizer & contents but don't add yet btn = new wxButton (this, wxHELP, BTNLABEL_HELP); @@ -909,18 +906,12 @@ int NetConfigDialog::GetIO () { strncpy (buf, string, sizeof(buf)); int n = strtol (string, NULL, 0); if (n<0 || n>0xffff) { - wxMessageBox("I/O address out of range. Try 0x200-0x400.", "Bad I/O address", wxOK | wxICON_ERROR ); + wxMessageBox("I/O address out of range. Try 0 - 0xffff.", "Bad I/O address", wxOK | wxICON_ERROR ); return -1; } return n; } -void NetConfigDialog::SetIO (int addr) { - wxString text; - text.Printf ("0x%03x", addr); - io->SetValue (text); -} - void NetConfigDialog::SetMac (unsigned char addr[6]) { wxString text; text.Printf ("%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); @@ -1163,6 +1154,191 @@ void LogOptionsDialog::ShowHelp () wxMessageBox(MSG_NO_HELP, MSG_NO_HELP_CAPTION, wxOK | wxICON_ERROR ); } +////////////////////////////////////////////////////////////////////// +// ConfigMemoryDialog implementation +////////////////////////////////////////////////////////////////////// +// Structure: +// mainSizer: +// box1 = static box "Standard Options" +// box1sizer: +// box1gridSizer, 3 columns: +// "memsize" +// megs = textfield +// spacer +// "biosimg" +// biosImage = textfield +// browse button +// "biosaddr" +// biosAddr = textfield +// spacer +// "vgabiosimg" +// vgabios = textfield +// browse button +// "vgabiosaddr" +// "0xc0000" +// box2 = static box "Optional ROM images" +// box2sizer: +// box2gridSizer, 3 columns: +// "opt rom 1" +// romImage[0] = textfield +// browse button +// "opt rom 2" +// romImage[1] = textfield +// browse button +// "opt rom 3" +// romImage[2] = textfield +// browse button +// "opt rom 4" +// romImage[3] = textfield +// browse button +// buttonSizer: +// help +// cancel +// ok +// + +// all events go to OnEvent method +BEGIN_EVENT_TABLE(ConfigMemoryDialog, wxDialog) + EVT_BUTTON(-1, ConfigMemoryDialog::OnEvent) + EVT_CHECKBOX(-1, ConfigMemoryDialog::OnEvent) + EVT_TEXT(-1, ConfigMemoryDialog::OnEvent) +END_EVENT_TABLE() + + +ConfigMemoryDialog::ConfigMemoryDialog( + wxWindow* parent, + wxWindowID id) + : wxDialog (parent, id, "", wxDefaultPosition, wxDefaultSize, + wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) +{ + static char *box1_label[] = CONFIG_MEMORY_BOX1_LABELS; + static char *box2_label[] = CONFIG_MEMORY_BOX2_LABELS; + int n_browse = 0; + int insideStaticBoxMargin = 15; + SetTitle (CONFIG_MEMORY_TITLE); + mainSizer = new wxBoxSizer (wxVERTICAL); + wxStaticBox *box1 = new wxStaticBox (this, -1, CONFIG_MEMORY_BOX1_TITLE); + box1sizer = new wxStaticBoxSizer (box1, wxVERTICAL); + mainSizer->Add (box1sizer, 0, wxALL|wxGROW, 10); + wxStaticBox *box2 = new wxStaticBox (this, -1, CONFIG_MEMORY_BOX2_TITLE); + box2sizer = new wxStaticBoxSizer (box2, wxVERTICAL); + mainSizer->Add (box2sizer, 0, wxALL|wxGROW, 10); + buttonSizer = new wxBoxSizer (wxHORIZONTAL); + mainSizer->Add (buttonSizer, 0, wxALIGN_RIGHT); + + // box1 contents + wxSize textCtrlSize (300, -1); // width=300, height=default + box1gridSizer = new wxFlexGridSizer (3); + box1sizer->Add (box1gridSizer, 0, wxALL, insideStaticBoxMargin); +#define add(x) box1gridSizer->Add (x, 0, wxALL, 2) +#define addrt(x) box1gridSizer->Add (x, 0, wxALL|wxALIGN_RIGHT, 2) +#define newlabel(x) new wxStaticText (this, -1, x) +#define spacer() box1gridSizer->Add (1, 1); +#define newbrowse() (browseBtn[n_browse++] = new wxButton (this, ID_Browse, BTNLABEL_BROWSE)) +#define newlongtext() (new wxTextCtrl (this, -1, "", wxDefaultPosition, textCtrlSize)) + addrt (newlabel (box1_label[0])); + add (megs = new wxSpinCtrl (this, -1)); + spacer(); + addrt (newlabel (box1_label[1])); + add (biosImage = newlongtext ()); + add (newbrowse ()); + addrt (newlabel (box1_label[2])); + add (biosAddr = new wxTextCtrl (this, -1)); + spacer(); + addrt (newlabel (box1_label[3])); + add (vgabiosImage = newlongtext ()); + add (newbrowse ()); + addrt (newlabel (box1_label[4])); + add (newlabel (box1_label[5])); +#undef add(x) +#undef addrt(x) +#undef newlabel(x) +#undef spacer() + biosImage->SetSizeHints (300, biosImage->GetSize().GetHeight ()); + vgabiosImage->SetSizeHints (300, biosImage->GetSize().GetHeight ()); + + // box2 contents + box2gridSizer = new wxFlexGridSizer (3); + box2sizer->Add (box2gridSizer, 0, wxALL, insideStaticBoxMargin); +#define add(x) box2gridSizer->Add (x, 0, wxALL, 2) +#define addrt(x) box2gridSizer->Add (x, 0, wxALL|wxALIGN_RIGHT, 2) +#define newlabel(x) new wxStaticText (this, -1, x) +#define spacer() box2gridSizer->Add (1, 1); + for (int i=0; iSetSizeHints (300, rom[i]->GetSize().GetHeight ()); + add (newbrowse ()); + addrt (newlabel (box2_label[2*i + 1])); + add (romAddr[i] = new wxTextCtrl (this, -1)); + spacer(); + } +#undef add(x) +#undef addrt(x) +#undef newlabel(x) +#undef spacer() +#undef newbrowse() +#undef newlongtext() + + // buttonSizer contents + wxButton *btn; + 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, BTNLABEL_CANCEL); + buttonSizer->Add (btn, 0, wxALL, 5); + btn = new wxButton (this, wxOK, BTNLABEL_OK); + buttonSizer->Add (btn, 0, wxALL, 5); +} + +void ConfigMemoryDialog::Init() +{ + // lay it out! + SetAutoLayout(TRUE); + SetSizer(mainSizer); + mainSizer->Fit (this); + wxSize size = mainSizer->GetMinSize (); + printf ("minsize is %d,%d\n", size.GetWidth(), size.GetHeight ()); + int margin = 5; + SetSizeHints (size.GetWidth () + margin, size.GetHeight () + margin); + Center (); +} + +void ConfigMemoryDialog::OnEvent(wxCommandEvent& event) +{ + int id = event.GetId (); + printf ("you pressed button id=%d\n", id); + switch (id) { + case wxOK: + { + // test validity of the integer fields + bool valid; + GetTextCtrlInt (biosAddr, "0x%x", true, &valid); + if (!valid) return; + for (int rom=0; romSetValue (tmp); +} + +int GetTextCtrlInt (wxTextCtrl *ctrl, const char *format, bool complain, bool *valid) { + wxString tmp (ctrl->GetValue ()); + char buf[1024]; + strncpy (buf, tmp.c_str(), sizeof(buf)); + int n; + if (sscanf (buf, format, &n) == 1) { + if (valid) *valid = true; + return n; + } + if (valid) *valid = false; + if (complain) { + wxMessageBox("Invalid integer!", "Invalid", wxOK | wxICON_ERROR ); + ctrl->SetFocus (); + } + return -1; +} + + #ifdef TEST_DIALOG ////////////////////////////////////////////////////////////////////// diff --git a/bochs/gui/wxdialog.h b/bochs/gui/wxdialog.h index 7be0af929..c417a3124 100644 --- a/bochs/gui/wxdialog.h +++ b/bochs/gui/wxdialog.h @@ -1,5 +1,5 @@ //////////////////////////////////////////////////////////////////// -// $Id: wxdialog.h,v 1.17 2002-09-02 17:03:11 bdenney Exp $ +// $Id: wxdialog.h,v 1.18 2002-09-02 20:13:49 bdenney Exp $ //////////////////////////////////////////////////////////////////// // // wxWindows dialogs for Bochs @@ -17,6 +17,13 @@ #define BTNLABEL_OK "Ok" #define BTNLABEL_CREATE_IMG "Create Image" #define BTNLABEL_ADVANCED "Advanced" +#define BTNLABEL_BROWSE "<--Browse" + +// utility function prototype +void ChangeStaticText (wxSizer *sizer, wxStaticText *win, wxString newtext); +bool CreateImage (int harddisk, int sectors, const char *filename); +void SetTextCtrl (wxTextCtrl *text, const char *format, int val); +int GetTextCtrlInt (wxTextCtrl *text, const char *format, bool complain=false, bool *valid = NULL); //////////////////////////////////////////////////////////////////// // LogMsgAskDialog is a modal dialog box that shows the user a @@ -373,7 +380,7 @@ public: int ShowModal() { Init(); return wxDialog::ShowModal(); } void SetEnable (bool en) { enable->SetValue (en); EnableChanged (); } bool GetEnable () { return enable->GetValue (); } - void SetIO (int addr); + void SetIO (int addr) { SetTextCtrl (io, "0x%03x", addr); } int GetIO (); void SetIrq (int addr) { irq->SetValue (addr); } int GetIrq () { return irq->GetValue (); } @@ -409,40 +416,75 @@ DECLARE_EVENT_TABLE() // | +--- Optional ROM images ---------------------------------------+ | // | | | | // | | Optional ROM image #1: [________________] [Browse] | | -// | | address: [______] | | +// | | Address: [______] | | // | | | | // | | Optional ROM image #2: [________________] [Browse] | | -// | | address: [______] | | +// | | Address: [______] | | // | | | | // | | Optional ROM image #3: [________________] [Browse] | | -// | | address: [______] | | +// | | Address: [______] | | // | | | | // | | Optional ROM image #4: [________________] [Browse] | | -// | | address: [______] | | +// | | Address: [______] | | // | | | | // | +---------------------------------------------------------------+ | // | [ Help ] [ Cancel ] [ Ok ] | // +-------------------------------------------------------------------+ +// +// To use this dialog: +// After constructor, use SetSize(), SetBios(), SetBiosAddr(), SetVgaBios(), +// SetRom(), SetRomAddr() to set the initial values. Then call ShowModal() +// which will return wxOK or wxCANCEL. Use the Get* equivalent methods +// to find out the value from each field. +class ConfigMemoryDialog: public wxDialog +{ +private: +#define CONFIG_MEMORY_TITLE "Configure Memory" +#define CONFIG_MEMORY_BOX1_TITLE "Standard Options" +#define CONFIG_MEMORY_BOX2_TITLE "Optional ROM Images" +#define CONFIG_MEMORY_BOX1_LABELS { \ + "Memory size (megabytes):", \ + "ROM BIOS image:", \ + "ROM BIOS address:", \ + "VGA BIOS image:", \ + "VGA BIOS address:", \ + "0xC0000" } +#define CONFIG_MEMORY_BOX2_LABELS { \ + "Optional ROM image #1:", "Address:", \ + "Optional ROM image #2:", "Address:", \ + "Optional ROM image #3:", "Address:", \ + "Optional ROM image #4:", "Address:" \ + } +#define CONFIG_MEMORY_N_ROMS 4 + void Init (); // called automatically by ShowModal() + void ShowHelp (); + wxBoxSizer *mainSizer, *buttonSizer; + wxStaticBoxSizer *box1sizer, *box2sizer; + wxFlexGridSizer *box1gridSizer, *box2gridSizer; + wxSpinCtrl *megs; + wxTextCtrl *biosImage, *biosAddr, *vgabiosImage; + wxTextCtrl *rom[CONFIG_MEMORY_N_ROMS], *romAddr[CONFIG_MEMORY_N_ROMS]; +#define CONFIG_MEMORY_N_BROWSES 6 + wxButton *browseBtn[CONFIG_MEMORY_N_BROWSES]; +public: + ConfigMemoryDialog(wxWindow* parent, wxWindowID id); + void OnEvent (wxCommandEvent& event); + int ShowModal() { Init(); return wxDialog::ShowModal(); } + void SetSize (int val) { megs->SetValue (val); } + void SetBios (wxString filename) { biosImage->SetValue (filename); } + void SetVgaBios (wxString filename) { vgabiosImage->SetValue (filename); } + void SetRom (int n, wxString filename) { rom[n]->SetValue (filename); } + void SetBiosAddr (int addr) { SetTextCtrl (biosAddr, "0x%05x", addr); } + void SetRomAddr (int n, int addr) { SetTextCtrl (romAddr[n], "0x%05x", addr); } + int GetSize () { return megs->GetValue (); } + wxString GetBios () { return biosImage->GetValue (); } + wxString GetVgaBios () { return vgabiosImage->GetValue (); } + wxString GetRom (int n) { return rom[n]->GetValue (); } + int GetBiosAddr () { return GetTextCtrlInt (biosAddr, "0x%x"); } + int GetRomAddr (int n) { return GetTextCtrlInt (romAddr[n], "0x%x"); } -//////////////////////////////////////////////////////////////////////////// -// ConfigSoundDialog -//////////////////////////////////////////////////////////////////////////// -// -// +--- Configure Sound -------------------------------------------+ -// | | -// | Bochs can emulate a Sound Blaster 16. Would you like | -// | to enable it? | -// | | -// | Enable [X] | -// | | -// | DMA timer: [_________] | -// | | -// | Midi mode [ 1 ] Output file [_________________] [Browse] | -// | Wave mode [ 1 ] Output file [_________________] [Browse] | -// | Log mode [ 1 ] Output file [_________________] [Browse] | -// | | -// | [ Help ] [ Cancel ] [ Ok ] | -// +---------------------------------------------------------------+ +DECLARE_EVENT_TABLE() +}; //////////////////////////////////////////////////////////////////////////// // LogOptionsDialog @@ -511,6 +553,27 @@ DECLARE_EVENT_TABLE() }; +//////////////////////////////////////////////////////////////////////////// +// ConfigSoundDialog +//////////////////////////////////////////////////////////////////////////// +// +// +--- Configure Sound -------------------------------------------+ +// | | +// | Bochs can emulate a Sound Blaster 16. Would you like | +// | to enable it? | +// | | +// | Enable [X] | +// | | +// | DMA timer: [_________] | +// | | +// | Midi mode [ 1 ] Output file [_________________] [Browse] | +// | Wave mode [ 1 ] Output file [_________________] [Browse] | +// | Log mode [ 1 ] Output file [_________________] [Browse] | +// | | +// | [ Help ] [ Cancel ] [ Ok ] | +// +---------------------------------------------------------------+ + + /************************************************************************** Everything else in here is a comment! diff --git a/bochs/gui/wxmain.cc b/bochs/gui/wxmain.cc index 10396c775..f84dbae46 100644 --- a/bochs/gui/wxmain.cc +++ b/bochs/gui/wxmain.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////// -// $Id: wxmain.cc,v 1.23 2002-09-02 17:03:13 bdenney Exp $ +// $Id: wxmain.cc,v 1.24 2002-09-02 20:13:51 bdenney Exp $ ///////////////////////////////////////////////////////////////// // // wxmain.cc implements the wxWindows frame, toolbar, menus, and dialogs. @@ -148,6 +148,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(ID_Edit_HD_1, MyFrame::OnOtherEvent) EVT_MENU(ID_Edit_Cdrom, MyFrame::OnOtherEvent) EVT_MENU(ID_Edit_Boot, MyFrame::OnEditBoot) + EVT_MENU(ID_Edit_Memory, MyFrame::OnEditMemory) EVT_MENU(ID_Edit_Network, MyFrame::OnEditNet) EVT_MENU(ID_Log_Prefs, MyFrame::OnLogPrefs) // toolbar events @@ -369,6 +370,53 @@ void MyFrame::OnEditBoot(wxCommandEvent& WXUNUSED(event)) bootdevice->set (which); } +void MyFrame::OnEditMemory(wxCommandEvent& WXUNUSED(event)) +{ + ConfigMemoryDialog dlg (this, -1); + bx_param_num_c *megs = (bx_param_num_c*) SIM->get_param(BXP_MEM_SIZE); + bx_param_string_c *bios = (bx_param_string_c *) SIM->get_param (BXP_ROM_PATH); + bx_param_num_c *biosaddr = (bx_param_num_c*) SIM->get_param(BXP_ROM_ADDRESS); + bx_param_string_c *vgabios = (bx_param_string_c *) SIM->get_param (BXP_VGA_ROM_PATH); + static bx_id optRomPathParams[] = { + BXP_OPTROM1_PATH, BXP_OPTROM2_PATH, BXP_OPTROM3_PATH, BXP_OPTROM4_PATH + }; + static bx_id optRomAddrParams[] = { + BXP_OPTROM1_ADDRESS, BXP_OPTROM2_ADDRESS, BXP_OPTROM3_ADDRESS, BXP_OPTROM4_ADDRESS + }; + bx_param_string_c *optromPath[CONFIG_MEMORY_N_ROMS]; + bx_param_num_c *optromAddr[CONFIG_MEMORY_N_ROMS]; + int rom; + for (rom=0; romget_param (optRomPathParams[rom]); + optromAddr[rom] = (bx_param_num_c *) + SIM->get_param (optRomAddrParams[rom]); + } + dlg.SetSize (megs->get ()); + dlg.SetBios (wxString (bios->getptr ())); + dlg.SetBiosAddr (biosaddr->get ()); + dlg.SetVgaBios (wxString (vgabios->getptr ())); + for (rom=0; romgetptr ())); + dlg.SetRomAddr (rom, optromAddr[rom]->get ()); + } + int n = dlg.ShowModal (); + if (n == wxOK) { + char buf[1024]; + megs->set (dlg.GetSize ()); + safeWxStrcpy (buf, dlg.GetBios (), sizeof (buf)); + bios->set (buf); + biosaddr->set (dlg.GetBiosAddr ()); + safeWxStrcpy (buf, dlg.GetVgaBios (), sizeof (buf)); + vgabios->set (buf); + for (rom=0; romset (buf); + optromAddr[rom]->set (dlg.GetRomAddr (rom)); + } + } +} + void MyFrame::OnEditNet(wxCommandEvent& WXUNUSED(event)) { NetConfigDialog dlg (this, -1); @@ -1125,3 +1173,12 @@ SimThread::GetSyncResponse () return event; } +/////////////////////////////////////////////////////////////////// +// utility +/////////////////////////////////////////////////////////////////// +void +safeWxStrcpy (char *dest, wxString src, int destlen) +{ + wxString tmp (src); + strncpy (dest, tmp.c_str (), destlen); +} diff --git a/bochs/gui/wxmain.h b/bochs/gui/wxmain.h index 6e8478f9f..83e683ee9 100644 --- a/bochs/gui/wxmain.h +++ b/bochs/gui/wxmain.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////// -// $Id: wxmain.h,v 1.15 2002-09-02 17:03:14 bdenney Exp $ +// $Id: wxmain.h,v 1.16 2002-09-02 20:13:52 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. @@ -95,6 +95,9 @@ enum //#define IFDBG_KEY(x) x +// defined in wxmain.cc +void safeWxStrcpy (char *dest, wxString src, int destlen); + /// the MyPanel methods are defined in wx.cc class MyPanel: public wxPanel { @@ -133,6 +136,7 @@ public: void OnKillSim(wxCommandEvent& event); void OnSim2CIEvent(wxCommandEvent& event); void OnEditBoot(wxCommandEvent& event); + void OnEditMemory(wxCommandEvent& event); void OnEditNet(wxCommandEvent& event); void OnLogPrefs(wxCommandEvent& event); void OnOtherEvent(wxCommandEvent& event);