es40-cfg.cpp

Go to the documentation of this file.
00001 /* ES40 emulator.
00002  * Copyright (C) 2007-2008 by the ES40 Emulator Project
00003  *
00004  * WWW    : http://sourceforge.net/projects/es40
00005  * E-mail : camiel@camicom.com
00006  * 
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00020  *
00021  * Although this is not required, the author would appreciate being notified of, 
00022  * and receiving any modifications you may make to the source code that might serve
00023  * the general public.
00024  */
00025 
00051 #include "StdAfx.h"
00052 
00053 // C++ includes
00054 #include <string>
00055 #include <vector>
00056 #include <iostream>
00057 #include <fstream>
00058 #include <sstream>
00059 #include <algorithm>
00060 
00061 #if defined(HAVE_PCAP)
00062 #include <pcap.h>
00063 #endif
00064 
00065 using namespace std;
00066 
00067 // Question classes
00068 
00069 #include "Question.h"
00070 #include "FreeTextQuestion.h"
00071 #include "NumberQuestion.h"
00072 #include "MultipleChoiceQuestion.h"
00073 #include "ShrinkingChoiceQuestion.h"
00074 
00084 void add_disks(ShrinkingChoiceQuestion * disk_q, ostream * os)
00085 {
00086   /* Loop until there are no more disks to be added.
00087    */
00088   for(;;)
00089   {
00090     /* If disk_q has only one answer left, this is the 
00091      * "none" answer. This controller can contain no
00092      * more disks.
00093      */
00094     if (disk_q->countAnswers() == 1)
00095       break;
00096 
00097     /* If the answer value is "", the answer "none"
00098      * was given. Stop adding disks to this controller.
00099      */
00100     if (disk_q->ask() == "")
00101       break;
00102     
00103     /* Find out if this should be using:
00104      *   - a disk image file
00105      *   - a raw device
00106      *   - a RAM DISK
00107      */
00108     MultipleChoiceQuestion type_q;
00109     type_q.setQuestion("How should " + disk_q->getAnswer() + " be emulated?");
00110     type_q.setDefault("file");
00111     type_q.setExplanation("Disks can be emulated in several ways.");
00112     type_q.addAnswer("file","file","The disk uses a disk image on the host system's disk.");
00113     type_q.addAnswer("device","device","The disk uses one of the host system's raw disks.");
00114     type_q.addAnswer("ramdisk","ramdisk","The disk stores it's data in RAM. Volatile.");
00115 
00116     *os << "    " << disk_q->getAnswer() << " = " << type_q.ask() << "\n";
00117     *os << "    {\n";
00118     
00119     if (type_q.getAnswer() == "file" || type_q.getAnswer() == "device")
00120     {
00121       /* For a file or device, we need to know what
00122        * file or device to use.
00123        */
00124       FreeTextQuestion img_q;
00125       img_q.setQuestion("What " + type_q.getAnswer() + " should " + disk_q->getAnswer() + " use?");
00126       img_q.setExplanation("Enter the path to the " + type_q.getAnswer() + " to use for this disk.");
00127       *os << "      " << type_q.getAnswer() << " = \"" << img_q.ask() << "\";\n";
00128     }
00129 
00130     if (type_q.getAnswer() == "file")
00131     {
00132       /* For a file, we need to know whether to create
00133        * it when it doesn't exist or not.
00134        */
00135       MultipleChoiceQuestion create_q;
00136       create_q.setQuestion("If the file doesn't exist, do you want us to create it?");
00137       create_q.setExplanation("The file will be created the first time the emulator runs.");
00138       create_q.addAnswer("no","no","Don't create this file");
00139       create_q.addAnswer("yes","yes","Create this file");
00140       if (create_q.getAnswer() == "yes")
00141       {
00142         /* If we should create the file, we need to
00143          * know it's size.
00144          */
00145         MultipleChoiceQuestion unit_q;
00146         unit_q.setQuestion("What unit do you want to use to specify the disk size?");
00147         unit_q.setExplanation("This is needed to create the file if it doesn't exist.");
00148         unit_q.addAnswer("KB","K","Kilobytes");
00149         unit_q.addAnswer("MB","M","Megabytes");
00150         unit_q.addAnswer("GB","G","Gigabytes");
00151         unit_q.setDefault("MB");
00152         unit_q.ask();
00153         NumberQuestion size_q;
00154         size_q.setQuestion("How many " + unit_q.getAnswer() + "Bytes should the disk be?");
00155         size_q.setExplanation("This is needed to create the file if it doesn't exist.");
00156         size_q.setRange(1,1024);
00157         size_q.setDefault("10");
00158         size_q.ask();
00159         *os << "      autocreate_size = \"" << size_q.getAnswer() << unit_q.getAnswer() << "\";\n";
00160       }
00161     }
00162 
00163     if (type_q.getAnswer() == "ramdisk")
00164     {
00165       /* For a RAM DISK, we need to know what
00166        * size it should be.
00167        */
00168       MultipleChoiceQuestion unit_q;
00169       unit_q.setQuestion("What unit do you want to use to specify the disk size?");
00170       unit_q.setExplanation("This is needed to create the RAMDISK.");
00171       unit_q.addAnswer("KB","K","Kilobytes");
00172       unit_q.addAnswer("MB","M","Megabytes");
00173       unit_q.addAnswer("GB","G","Gigabytes");
00174       unit_q.setDefault("MB");
00175       unit_q.ask();
00176       NumberQuestion size_q;
00177       size_q.setQuestion("How many " + unit_q.getAnswer() + "Bytes should the disk be?");
00178       size_q.setExplanation("This is needed to create the RAMDISK.");
00179       size_q.setRange(1,1024);
00180       size_q.setDefault("10");
00181       size_q.ask();
00182       *os << "      size = \"" << size_q.getAnswer() << unit_q.getAnswer() << "\";\n";
00183     }
00184 
00185     /* We need to know whether to emulate this as
00186      * a cd-rom, or as a hard-disk.
00187      */
00188     MultipleChoiceQuestion cdrom_q;
00189     cdrom_q.setQuestion("Should " + disk_q->getAnswer() + " be a disk or a cd-rom device?");
00190     cdrom_q.setExplanation("Do you want the OS to see this " + type_q.getAnswer() + " as a hard-disk, or as a cd-rom?");
00191     cdrom_q.addAnswer("disk","false","Hard-disk");
00192     cdrom_q.addAnswer("cd-rom","true","CD-ROM drive");
00193     cdrom_q.setDefault("disk");
00194     *os << "      cdrom = " << cdrom_q.getAnswer() << ";\n";
00195 
00196     /* We also need to know whether this is a
00197      * writeable or a read-only device.
00198      */
00199     MultipleChoiceQuestion ro_q;
00200     ro_q.setQuestion("Should " + disk_q->getAnswer() + " be a read-only disk?");
00201     ro_q.setExplanation("You might want to write-protect this disk.");
00202     ro_q.addAnswer("no","false","writeable");
00203     ro_q.addAnswer("yes","true","read-only");
00204     ro_q.setDefault("no");
00205 
00206     if (cdrom_q.ask() == "true")
00207     {
00208       /* CD-ROMs are always read-only.
00209        */
00210       ro_q.setAnswer("true");
00211     }
00212     else if (type_q.getAnswer() == "ramdisk")
00213     {
00214       /* Read-only RAM DISKs don't make any sense.
00215        */
00216       ro_q.setAnswer("false");
00217     }
00218     else
00219     {
00220       /* Otherwise, ask.
00221        */
00222       ro_q.ask();
00223     }
00224     *os << "      read_only = " << ro_q.getAnswer() << ";\n";
00225 
00226     /* The user can define a custom model
00227      * number for the device.
00228      */
00229     FreeTextQuestion ft_q;
00230     ft_q.setQuestion("Would you like to set a disk model number?");
00231     ft_q.setExplanation("Leave blank to choose the default.");
00232     if (ft_q.ask() != "")
00233       *os << "      model_number = \"" << ft_q.getAnswer() << "\";\n";
00234 
00235     /* The user can define a custom revision
00236      * number for the device.
00237      */
00238     ft_q.setQuestion("Would you like to set a revision number?");
00239     if (ft_q.ask() != "")
00240       *os << "      rev_number = \"" << ft_q.getAnswer() << "\";\n";
00241 
00242     /* The user can define a custom serial
00243      * number for the device.
00244      */
00245     ft_q.setQuestion("Would you like to set a serial number?");
00246     if (ft_q.ask() != "")
00247       *os << "      serial_number = \"" << ft_q.getAnswer() << "\";\n";
00248 
00249     *os << "    }\n\n";
00250   }
00251 }
00252 
00256 int main(int argc, char* argv[])
00257 {
00258   /* Banner
00259    */
00260   printf("\n\n");
00261   printf("   **======================================================================**\n");
00262   printf("   ||                             ES40  emulator                           ||\n");
00263   printf("   ||                              Version " VERSION "                            ||\n");
00264   printf("   ||                                                                      ||\n");
00265   printf("   ||  Copyright (C) 2007-2008 by the ES40 Emulator Project                ||\n");
00266   printf("   ||  Website: http://sourceforge.net/projects/es40                       ||\n");
00267   printf("   ||  E-mail : camiel@camicom.com                                         ||\n");
00268   printf("   ||                                                                      ||\n");
00269   printf("   ||  This program is free software; you can redistribute it and/or       ||\n");
00270   printf("   ||  modify it under the terms of the GNU General Public License         ||\n");
00271   printf("   ||  as published by the Free Software Foundation; either version 2      ||\n");
00272   printf("   ||  of the License, or (at your option) any later version.              ||\n");
00273   printf("   **======================================================================**\n");
00274   printf("\n\n");
00275 
00276   /* Explanation
00277    */
00278   printf("We are now going to set up an initial configuration file for the Emulator.\n");
00279   printf("This file will be saved as es40.cfg in the current directory.\n\n");
00280   printf("For more detailed information to the current question, answer '?'.\n");
00281 
00282   /* Open es40.cfg for writing.
00283    */
00284   filebuf fb;
00285   fb.open("es40.cfg",ios::out);
00286   ostream os(&fb);
00287 
00288   /* **************************** *
00289    * GUI Choice                   *
00290    * **************************** */
00291 
00292   MultipleChoiceQuestion gui_q;
00293 
00294   gui_q.setQuestion("Do you want to have a GUI?");
00295   gui_q.setExplanation("You need a GUI if you want to use an emulated graphics card. You don't need this for most OS'es. If you don't need this, we recomment that you answer 'none' to this question.");
00296   gui_q.setDefault("none");
00297   gui_q.addAnswer("none","","No GUI. Graphics cards are not supported.");
00298 
00299 #if defined(HAVE_SDL)
00300   gui_q.addAnswer("SDL","sdl","Simple Directmedia Layer. Preferred GUI mechanism.");
00301 #endif
00302 #if defined(HAVE_X11)
00303   gui_q.addAnswer("X11","X11","Unix X-Windows GUI support.");
00304 #endif
00305 #if defined(_WIN32)
00306   gui_q.addAnswer("win32","win32","Windows 32 GUI support.");
00307 #endif
00308 
00309   if (gui_q.countAnswers()==1)
00310   {
00311     /* The only valid answer is "none".
00312      */
00313     cout << "\nSorry, the GUI is not available! (no SDL, win32 or X11 support found).\n";
00314     gui_q.setAnswer("");
00315   }
00316   else
00317   {
00318     /* Ask what GUI to use?
00319      */
00320     gui_q.ask();
00321   }
00322 
00323   if (gui_q.getAnswer() != "")
00324   {
00325     /* Yes, we have a GUI.
00326      */
00327     os << "gui = " << gui_q.getAnswer() << "\n";
00328     os << "{\n";
00329     os << "}\n\n";
00330   }
00331 
00332   /* **************************** *
00333    * Memory Size                  *
00334    * **************************** */
00335 
00336   MultipleChoiceQuestion mem_q;
00337   
00338   mem_q.setQuestion("How much RAM memory do you want to emulate?");
00339   mem_q.setExplanation("Your system should have enough free memory to emulate the amount you choose here.");
00340   mem_q.setDefault("256M");
00341 
00342   /* Add memory sizes from 32 MB to 8 GB
00343    * (25 to 34 bits).
00344    */
00345   for (int i = 25;i<34;i++)
00346   {
00347     string a;
00348     int j = i;
00349     if (i<30)
00350     {
00351       /* Megabyte-range.
00352        */
00353       j -=20;
00354       a = "M";
00355     }
00356     else
00357     {
00358       /* Gigabyte range.
00359        */
00360       j -= 30;
00361       a = "G";
00362     }
00363     mem_q.addAnswer(i2s(1<<j) + a, i2s(i), i2s(1<<j) + a + "Bytes of memory.");
00364   }
00365 
00366   os << "sys0 = tsunami\n";
00367   os << "{\n";
00368   os << "  memory.bits = " << mem_q.ask() << ";\n";
00369 
00370   /* **************************** *
00371    * ROM Files                    *
00372    * **************************** */
00373 
00374   FreeTextQuestion rom_q;
00375   rom_q.setQuestion("Where can the SRM ROM image be found?");
00376   rom_q.setExplanation("This file is required.");
00377 #if defined(_WIN32)
00378   rom_q.setDefault("rom\\cl67srmrom.exe");
00379 #elif defined(__VMS)
00380   rom_q.setDefault("[.ROM]CL67SRMROM.EXE");
00381 #else
00382   rom_q.setDefault("rom/cl67srmrom.exe");
00383 #endif
00384 
00385   os << "  rom.srm = \"" << rom_q.ask() << "\";\n";
00386 
00387   rom_q.setQuestion("Where should the decompressed ROM image be saved?");
00388   rom_q.setExplanation("This file will be created the first time the emulator runs.");
00389 #if defined(_WIN32)
00390   rom_q.setDefault("rom\\decompressed.rom");
00391 #elif defined(__VMS)
00392   rom_q.setDefault("[.ROM]DECOMPRESSED.ROM");
00393 #else
00394   rom_q.setDefault("rom/decompressed.rom");
00395 #endif
00396 
00397   os << "  rom.decompressed = \"" << rom_q.ask() << "\";\n";
00398 
00399   rom_q.setQuestion("Where should the Flash ROM image be saved?");
00400 #if defined(_WIN32)
00401   rom_q.setDefault("rom\\flash.rom");
00402 #elif defined(__VMS)
00403   rom_q.setDefault("[.ROM]FLASH.ROM");
00404 #else
00405   rom_q.setDefault("rom/flash.rom");
00406 #endif
00407 
00408   os << "  rom.flash = \"" << rom_q.ask() << "\";\n";
00409 
00410   rom_q.setQuestion("Where should the DPR EEPROM image be saved?");
00411 #if defined(_WIN32)
00412   rom_q.setDefault("rom\\dpr.rom");
00413 #elif defined(__VMS)
00414   rom_q.setDefault("[.ROM]DPR.ROM");
00415 #else
00416   rom_q.setDefault("rom/dpr.rom");
00417 #endif
00418 
00419   os << "  rom.dpr = \"" << rom_q.ask() << "\";\n\n";
00420 
00421   /* **************************** *
00422    * CPU's                        *
00423    * **************************** */
00424 
00425   NumberQuestion cpu_q;
00426 
00427   cpu_q.setQuestion("How many CPU's do you want in the system?");
00428   cpu_q.setRange(1,4);
00429   cpu_q.setDefault("1");
00430   cpu_q.setExplanation("The normal value for the number of CPU's is 1. More CPU's are very experimental, and currently doesn't work.");
00431 
00432   cpu_q.ask();
00433 
00434   MultipleChoiceQuestion icache_q;
00435 
00436   icache_q.setQuestion("Do you want the ICACHE on the CPU's enabled?");
00437   icache_q.setExplanation("The ICACHE makes the CPU emulation more accurate, but also slows down the emulator. Decent operating systems shouldn't depend on this.");
00438   icache_q.setDefault("no");
00439   icache_q.addAnswer("yes","true","ICACHE enabled. Performance hit, but may be necessary for some software.");
00440   icache_q.addAnswer("no","false","ICACHE disabled. Better performance, but may not always work.");
00441 
00442   icache_q.ask();
00443 
00444   NumberQuestion mhz_q;
00445 
00446   mhz_q.setQuestion("What should the reported speed of the CPU's be in MHz?");
00447   mhz_q.setExplanation("This only changes the CPU speed reported to the OS; not the speed of the emulation.");
00448   mhz_q.setRange(10,1250);
00449   mhz_q.setDefault("800");
00450 
00451   mhz_q.ask();
00452 
00453   for (int i=0; i< cpu_q.getNum(); i++)
00454   {
00455     /* Repeat the CPU configuration for each
00456      * CPU. Differing CPU specs are not supported.
00457      */
00458     os << "  cpu" << i << " = ev68cb\n";
00459     os << "  {\n";
00460     os << "    speed = " << mhz_q.getAnswer() << "M;\n";
00461     os << "    icache = " << icache_q.getAnswer() << ";\n";
00462     os << "  }\n\n";
00463   }
00464 
00465   /* **************************** *
00466    * Serial Ports                 *
00467    * **************************** */
00468 
00469   /* There are two serial ports (0 and 1).
00470    */
00471   for (int i = 0; i<2; i++)
00472   {
00473     NumberQuestion port_q;
00474     port_q.setQuestion("What telnet port should serial " + i2s(i) + " listen?");
00475     port_q.setRange(1,65535);
00476     /* The default ports are 21264 and 21265.
00477      */
00478     port_q.setDefault(i2s(21264+i));
00479     port_q.setExplanation("You will telnet to this port to establish a connection with emulated serial port " + i2s(i) + ".");
00480 
00481     port_q.ask();
00482 
00483     FreeTextQuestion exec_q;
00484     exec_q.setQuestion("What program should be started automatically for serial " + i2s(i) + "?");
00485 #if defined(_WIN32)
00486     /* On windows, default to
00487      * C:\Program Files\Putty\Putty.exe
00488      */
00489     exec_q.setDefault("C:\\Program Files\\Putty\\Putty.exe");
00490 #else
00491     /* On other OS'es, default to
00492      * putty
00493      */
00494     exec_q.setDefault("putty");
00495 #endif
00496     exec_q.setExplanation("Enter the path to a program to start this to create an automatic connection with the serial port. Set to 'none' to establish the connection manually.");
00497 
00498     exec_q.ask();
00499     FreeTextQuestion arg_q;
00500 
00501     /* If none was answered, we don't need to
00502      * ask for arguments.
00503      */
00504     if (exec_q.getAnswer() != "none")
00505     {
00506       arg_q.setQuestion("What arguments should the program use to connect to the serial port?");
00507       arg_q.setExplanation("Enter the arguments the program needs.");
00508       /* This is the argument format for PuTTy.
00509        */
00510       arg_q.setDefault("telnet://localhost:" + port_q.getAnswer());
00511 
00512       arg_q.ask();
00513     }
00514 
00515     os << "  serial" << i << " = serial\n";
00516     os << "  {\n";
00517     os << "    port = " << port_q.getAnswer() << ";\n";
00518     if (exec_q.getAnswer() != "none")
00519     {
00520 #if defined(_WIN32)
00521       /* Quote the program path/name in "",
00522        * as it may contain spaces.
00523        */
00524       os << "    action = \"\"\"" << exec_q.getAnswer() << "\"\" " << arg_q.getAnswer() << "\";\n";
00525 #else
00526       os << "    action = \"" << exec_q.getAnswer() << " " << arg_q.getAnswer() << "\";\n";
00527 #endif
00528     }
00529       os << "  }\n\n";
00530   }
00531 
00532   /* **************************** *
00533    * ALi IDE Disks                *
00534    * **************************** */
00535 
00536   /* Use a ShrinkingChoiceQuestion; once
00537    * a disk position has been used, it
00538    * can't be used again.
00539    */
00540   ShrinkingChoiceQuestion ide_q;
00541   ide_q.setQuestion("Do you want to add any disks to the IDE controller?");
00542   ide_q.setDefault("none");
00543   ide_q.setExplanation("The IDE controller is mandatory. You can skip this, and set up a SCSI controller, too.");
00544   ide_q.addAnswer("none","","stop adding disks");
00545   ide_q.addAnswer("0.0","disk0.0","primary master");
00546   ide_q.addAnswer("0.1","disk0.1","primary slave");
00547   ide_q.addAnswer("1.0","disk1.0","secondary master");
00548   ide_q.addAnswer("1.1","disk1.1","secondary slave");
00549 
00550   os << "  pci0.15 = ali_ide\n";
00551   os << "  {\n";
00552   /* Ask what disks to add.
00553    */
00554   add_disks(&ide_q, &os);
00555   os << "  }\n\n";
00556 
00557   /* **************************** *
00558    * VGA Card                     *
00559    * **************************** */
00560 
00561   /* Use a ShrinkingChoiceQuestion. Once a
00562    * card is using a specific PCI slot, it
00563    * can't be used by another card.
00564    */
00565   ShrinkingChoiceQuestion pci_q;
00566 
00567   /* Only add the PCI bus 0 slots, as the
00568    * VGA card is only supported on hose 0.
00569    */
00570   for (int i=1; i<5; i++)
00571   {
00572     pci_q.addAnswer("0." + i2s(i),"pci0." + i2s(i),"Bus 0, Slot " + i2s(i));
00573   }
00574   pci_q.setExplanation("Only free PCI slots are listed.");
00575 
00576   MultipleChoiceQuestion vga_q;
00577 
00578   if (gui_q.getAnswer()!="")
00579   {
00580     vga_q.setQuestion("What (if any) VGA card do you wish to add to the system?");
00581     vga_q.setExplanation("Functionality of the different cards is pretty much the same; some OS'es seem to have a preference, though.");
00582     vga_q.setDefault("Cirrus");
00583     vga_q.addAnswer("none","","No graphics card");
00584     vga_q.addAnswer("Cirrus","cirrus","Cirrus CL-GD something");
00585     vga_q.addAnswer("S3","s3","S3 Trio 64");
00586 #if defined(HAVE_RADEON)
00587     /* Radeon support is optional, and currently
00588      * unreleased, because the specs are only
00589      * available under an NDA with AMD. Once AMD
00590      * has publicly released the Radeon 7500 (RV200)
00591      * specs, the emulated Radeon card will be
00592      * released.
00593      */
00594     vga_q.addAnswer("Radeon","radeon","Radeon 7500");
00595 #endif
00596 
00597     vga_q.ask();
00598   }
00599 
00600   if (vga_q.getAnswer()!="")
00601   {
00602     pci_q.setQuestion("What PCI slot should the " + vga_q.getAnswer() + " card be on?");
00603     pci_q.setDefault("0.1");
00604     
00605     rom_q.setQuestion("Where can the VGA BIOS ROM image be found?");
00606     rom_q.setExplanation("This file is required.");
00607 #if defined(_WIN32)
00608     rom_q.setDefault("rom\\vgabios-0.6a.bin");
00609 #elif defined(__VMS)
00610     rom_q.setDefault("[.ROM]VGABIOS_0_6A.BIN");
00611 #else
00612     rom_q.setDefault("rom/vgabios-0.6a.bin");
00613 #endif
00614     
00615     os << "  " << pci_q.ask() << " = " << vga_q.getAnswer() << "\n";
00616     os << "  {\n";
00617     os << "    rom = \"" << rom_q.ask() << "\";\n";
00618     os << "  }\n\n";
00619   }
00620 
00621   /* **************************** *
00622    * Free Form PCI Cards          *
00623    * **************************** */
00624 
00625   /* Add the PCI bus 1 slots. All non-VGA
00626    * PCI cards can be on either hose 0 or
00627    * hose 1.
00628    */
00629   for (int i=1; i<7; i++)
00630   {
00631     pci_q.addAnswer("1." + i2s(i),"pci1." + i2s(i),"Bus 1, Slot " + i2s(i));
00632   }
00633 
00634   MultipleChoiceQuestion card_q;
00635 
00636   card_q.setQuestion("Would you like to add another PCI card to the system?");
00637   card_q.setDefault("none");
00638   card_q.setExplanation("Choose what PCI card you'd like to add. Choose none if you have no more cards to add.");
00639   card_q.addAnswer("none","","No more cards to add");
00640 #if defined(HAVE_PCAP)
00641   card_q.addAnswer("nic","dec21143","DEC 21143 Network Interface (1 max)");
00642 #endif
00643   card_q.addAnswer("scsi","sym53c810","Symbios 53C810 narrow SCSI controller");
00644   card_q.addAnswer("wide scsi","sym53c895","Symbios 53C895 wide SCSI controller (doesn't work with OpenVMS)");
00645 
00646   /* Loop until there are no more PCI
00647    * cards to add.
00648    */
00649   for (;;)
00650   {
00651     /* If there are no more free PCI slots,
00652      * stop adding PCI cards.
00653      */
00654     if (pci_q.countAnswers() == 0)
00655       break;
00656 
00657     /* Default to the first available free
00658      * PCI slot.
00659      */
00660     pci_q.setDefault(pci_q.getFirstChoice());
00661 
00662     /* If this answer has been answered with
00663      * "none", stop adding PCI cards.
00664      */
00665     if (card_q.ask() == "")
00666       break;
00667 
00668     /* Determine where to put this card.
00669      */
00670     pci_q.setQuestion("In what PCI slot would you like to put the " + card_q.getAnswer() + " card?");
00671     os << "  " << pci_q.ask() << " = " << card_q.getAnswer() << "\n";
00672     os << "  {\n";
00673 
00674     if (card_q.getAnswer() == "dec21143")
00675     {
00676       /* Due to limitations in our network 
00677        * emulation, only one NIC is allowed.
00678        * Remove it from the list of choices.
00679        */
00680       card_q.dropChoice("nic");
00681 
00682 #if defined(HAVE_PCAP)
00683       MultipleChoiceQuestion if_q;
00684       if_q.setQuestion("What host network interface should we connect to (answer ? for a list)?");
00685       if_q.setExplanation("Choose 'list' to get a list at run-time.");
00686       if_q.addAnswer("list","","Get a list at run-time");
00687 
00688       /* Get a list of network interfaces and
00689        * add them to the list.
00690        */
00691       pcap_if_t*  alldevs;
00692       pcap_if_t *d;
00693       char        errbuf[PCAP_ERRBUF_SIZE];
00694 
00695       if(pcap_findalldevs(&alldevs, errbuf) == -1)
00696       {
00697         /* No devices to add.
00698          */
00699         printf("Error in pcap_findalldevs_ex: %s", errbuf);
00700       }
00701       else
00702       {
00703         int i = 1;
00704         for(d = alldevs; d; d = d->next)
00705         {
00706           if_q.addAnswer(i2s(i),d->name, string(d->name) + "(" + string(d->description) + ")");
00707           i++;
00708         }
00709       }
00710 
00711       if (if_q.ask() != "")
00712         os << "    adapter = \"" << if_q.getAnswer() << "\";\n";
00713 
00714       FreeTextQuestion mac_q;
00715       mac_q.setQuestion("What should the NIC's MAC address be?");
00716       mac_q.setExplanation("This should be unique on your network.");
00717       mac_q.setDefault("08-00-2B-E5-40-00");
00718       os << "    mac = \"" << mac_q.ask() << "\";\n";
00719 #endif
00720     }
00721     else if (card_q.getAnswer() == "sym53c810")
00722     {
00723       /* Use a ShrinkingChoiceQuestion; once
00724        * a disk position has been used, it
00725        * can't be used again.
00726        */
00727       ShrinkingChoiceQuestion disk_q;
00728       disk_q.setQuestion("Do you want to add any disks to the Sym53C810 controller?");
00729       disk_q.setDefault("none");
00730       disk_q.setExplanation("Add disks. Select 'none' if you have no more disks to add.");
00731       disk_q.addAnswer("none","","stop adding disks");
00732       /* The narrow SCSI controller supports
00733        * devices at targets 0..6.
00734        */
00735       for (int i = 0; i < 7; i++)
00736       {
00737         disk_q.addAnswer(i2s(i), "disk0." + i2s(i), "Target " + i2s(i));
00738       }
00739       /* Ask what disks to add.
00740        */
00741       add_disks(&disk_q, &os);
00742     }
00743     else if (card_q.getAnswer() == "sym53c895")
00744     {
00745       /* Use a ShrinkingChoiceQuestion; once
00746        * a disk position has been used, it
00747        * can't be used again.
00748        */
00749       ShrinkingChoiceQuestion disk_q;
00750       disk_q.setQuestion("Do you want to add any disks to the Sym53C895 controller?");
00751       disk_q.setDefault("none");
00752       disk_q.setExplanation("Add disks. Select 'none' if you have no more disks to add.");
00753       disk_q.addAnswer("none","","stop adding disks");
00754       /* The wide SCSI controller supports
00755        * devices at targets 0..6 and 8..15.
00756        */
00757       for (int i = 0; i < 16; i++)
00758       {
00759         if (i != 7)
00760           disk_q.addAnswer(i2s(i), "disk0." + i2s(i), "Target " + i2s(i));
00761       }
00762       /* Ask what disks to add.
00763        */
00764       add_disks(&disk_q, &os);
00765     }
00766     os << "  }\n\n";
00767   }
00768 
00769   MultipleChoiceQuestion mouse_q;
00770   mouse_q.setQuestion("Would you like to emulate the mouse?");
00771   mouse_q.setExplanation("The mouse is not really working yet... :-(");
00772   mouse_q.addAnswer("no","false","Disable the mouse");
00773   mouse_q.addAnswer("yes","true","Enable the mouse");
00774   mouse_q.setDefault("no");
00775 
00776   MultipleChoiceQuestion vgacons_q;
00777   vgacons_q.setQuestion("Where would you like console output to go?");
00778   vgacons_q.setExplanation("This is the SRM console option");
00779   vgacons_q.addAnswer("serial","false","Console on serial port 0");
00780   vgacons_q.addAnswer("graphics","true","Console on graphics controller");
00781   vgacons_q.setDefault("graphics");
00782 
00783   if (vga_q.getAnswer() != "")
00784   {
00785     /* If a VGA card is present, ask about
00786      * the mouse and the console.
00787      */
00788     mouse_q.ask();
00789     vgacons_q.ask();
00790   }
00791   else
00792   {
00793     /* No VGA card present, mouse support
00794      * is disabled, and the console goes
00795      * to serial port 0.
00796      */
00797     mouse_q.setAnswer("false");
00798     vgacons_q.setAnswer("false");
00799   }
00800 
00801   FreeTextQuestion lpt_q;
00802   lpt_q.setQuestion("Where would you like printer output to go?");
00803   lpt_q.setExplanation("Output from the printer port will be saved to this file. Leave blank if not wanted.");
00804   lpt_q.ask();
00805 
00806   os << "  pci0.7 = ali\n";
00807   os << "  {\n";
00808   os << "    mouse.enabled = " << mouse_q.getAnswer() << ";\n";
00809   os << "    vga_console = " << vgacons_q.getAnswer() << ";\n";
00810   if (lpt_q.getAnswer() != "")
00811     os << "    lpt.outfile = \"" << lpt_q.getAnswer() << "\"\n";
00812   os << "  }\n\n";
00813 
00814   /* The USB device is a fixed part, and
00815    * currently not configurable.
00816    */
00817   os << "  pci0.19 = ali_usb\n";
00818   os << "  {\n";
00819   os << "  }\n";
00820 
00821   os << "}\n";
00822   
00823   /* Close es40.cfg.
00824    */
00825   fb.close();
00826 
00827   /* All is well.
00828    */
00829   return 0;
00830 }
00831 

SourceForge.net Logo
Project space on SourceForge.net