Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

main_Amiga.i

Go to the documentation of this file.
00001 /*
00002  *  main_Amiga.i - Main program, AmigaOS specific stuff
00003  *
00004  *  Frodo (C) 1994-1997 Christian Bauer
00005  */
00006 
00007 #include <exec/types.h>
00008 #include <exec/execbase.h>
00009 #include <proto/exec.h>
00010 #include <proto/intuition.h>
00011 
00012 
00013 // Global variables
00014 Frodo *be_app;  // Pointer to Frodo object
00015 
00016 // Library bases
00017 extern ExecBase *SysBase;
00018 struct GfxBase *GfxBase = NULL;
00019 struct IntuitionBase *IntuitionBase = NULL;
00020 struct Library *GadToolsBase = NULL;
00021 struct Library *DiskfontBase = NULL;
00022 struct Library *AslBase = NULL;
00023 
00024 // Prototypes
00025 void error_exit(char *str);
00026 void open_libs(void);
00027 void close_libs(void);
00028 
00029 
00030 /*
00031  *  Create application object and start it
00032  */
00033 
00034 int main(int argc, char **argv)
00035 {
00036         if ((SysBase->AttnFlags & (AFF_68040 | AFF_68881)) != (AFF_68040 | AFF_68881))
00037                 error_exit("68040/68881 or higher required.\n");
00038         open_libs();
00039 
00040         ULONG secs, micros;
00041         CurrentTime(&secs, &micros);
00042         srand(micros);
00043 
00044         be_app = new Frodo();
00045         be_app->ArgvReceived(argc, argv);
00046         be_app->ReadyToRun();
00047         delete be_app;
00048 
00049         close_libs();
00050         return 0;
00051 }
00052 
00053 
00054 /*
00055  *  Low-level failure
00056  */
00057 
00058 void error_exit(char *str)
00059 {
00060         printf(str);
00061         close_libs();
00062         exit(20);
00063 }
00064 
00065 
00066 /*
00067  *  Open libraries
00068  */
00069 
00070 void open_libs(void)
00071 {
00072         if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)))
00073                 error_exit("Couldn't open Gfx V39.\n");
00074         if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)))
00075                 error_exit("Couldn't open Intuition V39.\n");
00076         if (!(GadToolsBase = OpenLibrary("gadtools.library", 39)))
00077                 error_exit("Couldn't open GadTools V39.\n");
00078         if (!(DiskfontBase = OpenLibrary("diskfont.library", 39)))
00079                 error_exit("Couldn't open Diskfont V39.\n");
00080         if (!(AslBase = OpenLibrary("asl.library", 39)))
00081                 error_exit("Couldn't open ASL V39.\n");
00082 }
00083 
00084 
00085 /*
00086  *  Close libraries
00087  */
00088 
00089 void close_libs(void)
00090 {
00091         if (AslBase)
00092                 CloseLibrary(AslBase);
00093         if (DiskfontBase)
00094                 CloseLibrary(DiskfontBase);
00095         if (GadToolsBase)
00096                 CloseLibrary(GadToolsBase);
00097         if (IntuitionBase)
00098                 CloseLibrary((struct Library *)IntuitionBase);
00099         if (GfxBase)
00100                 CloseLibrary((struct Library *)GfxBase);
00101 }
00102 
00103 
00104 /*
00105  *  Constructor: Initialize member variables
00106  */
00107 
00108 Frodo::Frodo()
00109 {
00110         TheC64 = NULL;
00111         prefs_path[0] = 0;
00112 }
00113 
00114 
00115 /*
00116  *  Process command line arguments
00117  */
00118 
00119 void Frodo::ArgvReceived(int argc, char **argv)
00120 {
00121         if (argc == 2)
00122                 strncpy(prefs_path, argv[1], 255);
00123 }
00124 
00125 
00126 /*
00127  *  Arguments processed, run emulation
00128  */
00129 
00130 void Frodo::ReadyToRun(void)
00131 {
00132         getcwd(AppDirPath, 256);
00133 
00134         // Load preferences
00135         if (!prefs_path[0])
00136                 strcpy(prefs_path, "Frodo Prefs");
00137         ThePrefs.Load(prefs_path);
00138 
00139         // Show preferences editor
00140         if (ThePrefs.ShowEditor(TRUE, prefs_path)) {
00141 
00142                 // Create and start C64
00143                 TheC64 = new C64;
00144                 if (load_rom_files())
00145                         TheC64->Run();
00146                 delete TheC64;
00147         }
00148 }
00149 
00150 
00151 /*
00152  *  Run preferences editor
00153  */
00154 
00155 void Frodo::RunPrefsEditor(void)
00156 {
00157         Prefs *prefs = new Prefs(ThePrefs);
00158         if (prefs->ShowEditor(FALSE, prefs_path)) {
00159                 TheC64->NewPrefs(prefs);
00160                 ThePrefs = *prefs;
00161         }
00162         delete prefs;
00163 }

Generated on Tue Feb 8 04:07:58 2005 for E32frodo by doxygen 1.3.3