00001
00002
00003
00004
00005
00006
00007 #include <AppKit.h>
00008 #include <StorageKit.h>
00009 #include <Path.h>
00010 #include <InterfaceKit.h>
00011
00012 #include "Version.h"
00013
00014
00015
00016 bool FromShell;
00017 BEntry AppDirectory;
00018 BBitmap *AboutBitmap;
00019 const BRect AboutFrame = BRect(0, 0, 383, 99);
00020
00021
00022
00023
00024
00025
00026 int main(int argc, char **argv)
00027 {
00028 Frodo *the_app;
00029
00030 srand(real_time_clock());
00031 FromShell = (argc != 0);
00032
00033 the_app = new Frodo();
00034 if (the_app != NULL) {
00035 the_app->Run();
00036 delete the_app;
00037 }
00038 return 0;
00039 }
00040
00041
00042
00043
00044
00045
00046 Frodo::Frodo() : BApplication(APP_SIGNATURE), this_messenger(this)
00047 {
00048 TheC64 = NULL;
00049 AboutBitmap = NULL;
00050 strcpy(prefs_path, "/boot/home/config/settings/Frodo_settings");
00051 prefs_showing = false;
00052
00053
00054 open_panel = new BFilePanel(B_OPEN_PANEL, &this_messenger, NULL, 0, false, new BMessage(MSG_OPEN_SNAPSHOT_RETURNED));
00055 open_panel->Window()->SetTitle("Frodo: Load snapshot");
00056 save_panel = new BFilePanel(B_SAVE_PANEL, &this_messenger, NULL, 0, false, new BMessage(MSG_SAVE_SNAPSHOT_RETURNED));
00057 save_panel->Window()->SetTitle("Frodo: Save snapshot");
00058 }
00059
00060
00061
00062
00063
00064
00065 void Frodo::ArgvReceived(int32 argc, char **argv)
00066 {
00067 if (argc == 2) {
00068 strncpy(prefs_path, argv[1], 1023);
00069 prefs_path[1023] = 0;
00070 }
00071 }
00072
00073
00074
00075
00076
00077
00078 void Frodo::RefsReceived(BMessage *message)
00079 {
00080
00081 if (!prefs_showing && !TheC64) {
00082 entry_ref the_ref;
00083 BEntry the_entry;
00084
00085 if (message->FindRef("refs", &the_ref) == B_NO_ERROR)
00086 if (the_entry.SetTo(&the_ref) == B_NO_ERROR)
00087 if (the_entry.IsFile()) {
00088 BPath the_path;
00089 the_entry.GetPath(&the_path);
00090 strncpy(prefs_path, the_path.Path(), 1023);
00091 prefs_path[1023] = 0;
00092 }
00093 }
00094 }
00095
00096
00097
00098
00099
00100
00101 void Frodo::ReadyToRun(void)
00102 {
00103
00104 app_info the_info;
00105 GetAppInfo(&the_info);
00106 BEntry the_file(&the_info.ref);
00107 the_file.GetParent(&AppDirectory);
00108 BPath the_path;
00109 AppDirectory.GetPath(&the_path);
00110 strncpy(AppDirPath, the_path.Path(), 1023);
00111 AppDirPath[1023] = 0;
00112 chdir(AppDirPath);
00113
00114
00115 AboutBitmap = new BBitmap(AboutFrame, B_COLOR_8_BIT);
00116 FILE *logofile = fopen("Frodo Logo", "rb");
00117 if (logofile != NULL) {
00118 fread(AboutBitmap->Bits(), 384*100, 1, logofile);
00119 fclose(logofile);
00120 }
00121
00122
00123 ThePrefs.Load(prefs_path);
00124
00125
00126 prefs_showing = true;
00127 ThePrefs.ShowEditor(true, prefs_path);
00128 }
00129
00130
00131
00132
00133
00134
00135 void Frodo::MessageReceived(BMessage *msg)
00136 {
00137 switch (msg->what) {
00138 case MSG_STARTUP:
00139
00140
00141 prefs_showing = false;
00142
00143
00144 TheC64 = new C64;
00145
00146
00147 if (!load_rom_files()) {
00148 PostMessage(B_QUIT_REQUESTED);
00149 return;
00150 }
00151
00152
00153 TheC64->Run();
00154 break;
00155
00156 case MSG_PREFS:
00157 if (TheC64 != NULL && !prefs_showing) {
00158 TheC64->Pause();
00159 TheC64->TheDisplay->Pause();
00160
00161 Prefs *prefs = new Prefs(ThePrefs);
00162 prefs_showing = true;
00163 prefs->ShowEditor(false, prefs_path);
00164 }
00165 break;
00166
00167 case MSG_PREFS_DONE:
00168 Prefs *prefs;
00169 msg->FindPointer("prefs", &prefs);
00170 if (!msg->FindBool("canceled")) {
00171 TheC64->NewPrefs(prefs);
00172 ThePrefs = *prefs;
00173 }
00174 delete prefs;
00175 prefs_showing = false;
00176
00177 TheC64->TheDisplay->Resume();
00178 TheC64->Resume();
00179 break;
00180
00181 case MSG_RESET:
00182 if (TheC64 != NULL)
00183 TheC64->Reset();
00184 break;
00185
00186 case MSG_NMI:
00187 if (TheC64 != NULL)
00188 TheC64->NMI();
00189 break;
00190
00191 case MSG_SAM:
00192 if (TheC64 != NULL && !prefs_showing && FromShell) {
00193 TheC64->Pause();
00194 TheC64->TheDisplay->Pause();
00195 SAM(TheC64);
00196 TheC64->TheDisplay->Resume();
00197 TheC64->Resume();
00198 }
00199 break;
00200
00201 case MSG_NEXTDISK:
00202 if (TheC64 != NULL && !prefs_showing && strlen(ThePrefs.DrivePath[0]) > 4) {
00203 char str[256];
00204 strcpy(str, ThePrefs.DrivePath[0]);
00205 char *p = str + strlen(str) - 5;
00206
00207
00208 if (p[1] == '.' && p[3] == '6' && p[4] == '4') {
00209 p[0]++;
00210
00211
00212 FILE *file;
00213 if ((file = fopen(str, "rb")) == NULL) {
00214 if (isdigit(p[0]))
00215 p[0] = '1';
00216 else if (isupper(p[0]))
00217 p[0] = 'A';
00218 else
00219 p[0] = 'a';
00220 } else
00221 fclose(file);
00222
00223
00224 TheC64->Pause();
00225 Prefs *prefs = new Prefs(ThePrefs);
00226 strcpy(prefs->DrivePath[0], str);
00227 TheC64->NewPrefs(prefs);
00228 ThePrefs = *prefs;
00229 delete prefs;
00230 TheC64->Resume();
00231 }
00232 }
00233 break;
00234
00235 case MSG_TOGGLE_1541:
00236 if (TheC64 != NULL && !prefs_showing) {
00237 TheC64->Pause();
00238 Prefs *prefs = new Prefs(ThePrefs);
00239 prefs->Emul1541Proc = !prefs->Emul1541Proc;
00240 TheC64->NewPrefs(prefs);
00241 ThePrefs = *prefs;
00242 delete prefs;
00243 TheC64->Resume();
00244 }
00245 break;
00246
00247 case MSG_OPEN_SNAPSHOT:
00248 if (TheC64 != NULL && !prefs_showing)
00249 open_panel->Show();
00250 break;
00251
00252 case MSG_SAVE_SNAPSHOT:
00253 if (TheC64 != NULL && !prefs_showing)
00254 save_panel->Show();
00255 break;
00256
00257 case MSG_OPEN_SNAPSHOT_RETURNED:
00258 if (TheC64 != NULL && !prefs_showing) {
00259 entry_ref the_ref;
00260 BEntry the_entry;
00261 if (msg->FindRef("refs", &the_ref) == B_NO_ERROR)
00262 if (the_entry.SetTo(&the_ref) == B_NO_ERROR)
00263 if (the_entry.IsFile()) {
00264 char path[1024];
00265 BPath the_path;
00266 the_entry.GetPath(&the_path);
00267 strncpy(path, the_path.Path(), 1023);
00268 path[1023] = 0;
00269 TheC64->Pause();
00270 TheC64->LoadSnapshot(path);
00271 TheC64->Resume();
00272 }
00273 }
00274 break;
00275
00276 case MSG_SAVE_SNAPSHOT_RETURNED:
00277 if (TheC64 != NULL && !prefs_showing) {
00278 entry_ref the_ref;
00279 BEntry the_entry;
00280 if (msg->FindRef("directory", &the_ref) == B_NO_ERROR)
00281 if (the_entry.SetTo(&the_ref) == B_NO_ERROR) {
00282 char path[1024];
00283 BPath the_path;
00284 the_entry.GetPath(&the_path);
00285 strncpy(path, the_path.Path(), 1023);
00286 strncat(path, "/", 1023);
00287 strncat(path, msg->FindString("name"), 1023);
00288 path[1023] = 0;
00289 TheC64->Pause();
00290 TheC64->SaveSnapshot(path);
00291 TheC64->Resume();
00292 }
00293 }
00294 break;
00295
00296 default:
00297 BApplication::MessageReceived(msg);
00298 }
00299 }
00300
00301
00302
00303
00304
00305
00306 bool Frodo::QuitRequested(void)
00307 {
00308
00309 if (TheC64) {
00310 TheC64->Quit();
00311 delete TheC64;
00312 }
00313
00314 delete AboutBitmap;
00315 delete open_panel;
00316 delete save_panel;
00317
00318 return BApplication::QuitRequested();
00319 }
00320
00321
00322
00323
00324
00325
00326 class AboutView : public BView {
00327 public:
00328 AboutView() : BView(AboutFrame, "", B_FOLLOW_NONE, B_WILL_DRAW) {}
00329
00330 virtual void AttachedToWindow(void)
00331 {
00332 SetHighColor(0, 0, 0);
00333 }
00334
00335 virtual void Draw(BRect update)
00336 {
00337 DrawBitmap(AboutBitmap, update, update);
00338
00339 SetFont(be_bold_font);
00340 SetDrawingMode(B_OP_OVER);
00341 MovePenTo(204, 20);
00342 DrawString(VERSION_STRING);
00343
00344 SetFont(be_plain_font);
00345 MovePenTo(204, 40);
00346 DrawString("by Christian Bauer");
00347 MovePenTo(204, 52);
00348 DrawString("<cbauer@iphcip1.physik.uni-mainz.de>");
00349 MovePenTo(204, 75);
00350 DrawString(B_UTF8_COPYRIGHT " Copyright 1994-1997");
00351 MovePenTo(204, 87);
00352 DrawString("Freely distributable.");
00353 }
00354
00355 virtual void MouseDown(BPoint point)
00356 {
00357 Window()->PostMessage(B_QUIT_REQUESTED);
00358 }
00359 };
00360
00361 class AboutWindow : public BWindow {
00362 public:
00363 AboutWindow() : BWindow(AboutFrame, NULL, B_BORDERED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK)
00364 {
00365 Lock();
00366 MoveTo(100, 100);
00367 AboutView *view = new AboutView;
00368 AddChild(view);
00369 view->MakeFocus();
00370 Unlock();
00371 Show();
00372 }
00373 };
00374
00375 void Frodo::AboutRequested(void)
00376 {
00377 new AboutWindow();
00378 }