2009-01-13 19:46:42 +01:00
|
|
|
/*
|
|
|
|
* main.cpp - Main program
|
|
|
|
*
|
|
|
|
* Frodo (C) 1994-1997,2002-2005 Christian Bauer
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
2010-02-07 16:14:52 +01:00
|
|
|
#include <SDL.h>
|
|
|
|
#include <SDL_ttf.h>
|
2009-01-13 19:46:42 +01:00
|
|
|
|
|
|
|
#include "sysdeps.h"
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include "C64.h"
|
|
|
|
#include "Display.h"
|
|
|
|
#include "Prefs.h"
|
|
|
|
#include "SAM.h"
|
2010-02-07 16:14:52 +01:00
|
|
|
#include "gui/gui.hh"
|
2010-02-14 10:30:16 +01:00
|
|
|
#include "data_store.hh"
|
2010-02-07 17:15:36 +01:00
|
|
|
#include "utils.hh"
|
2009-01-13 19:46:42 +01:00
|
|
|
|
2010-03-21 13:52:07 +01:00
|
|
|
#if defined(GEKKO)
|
|
|
|
#include "fat.h"
|
|
|
|
#endif
|
|
|
|
|
2009-01-13 19:46:42 +01:00
|
|
|
|
|
|
|
// Global variables
|
2010-02-07 16:14:52 +01:00
|
|
|
extern int init_graphics(void);
|
|
|
|
|
|
|
|
|
|
|
|
// Global variables
|
2009-01-13 19:46:42 +01:00
|
|
|
C64 *TheC64 = NULL; // Global C64 object
|
|
|
|
char AppDirPath[1024]; // Path of application directory
|
|
|
|
|
|
|
|
|
|
|
|
// ROM file names
|
|
|
|
#ifndef DATADIR
|
|
|
|
#define DATADIR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __riscos__
|
|
|
|
#define BASIC_ROM_FILE "FrodoRsrc:Basic_ROM"
|
|
|
|
#define KERNAL_ROM_FILE "FrodoRsrc:Kernal_ROM"
|
|
|
|
#define CHAR_ROM_FILE "FrodoRsrc:Char_ROM"
|
|
|
|
#define DRIVE_ROM_FILE "FrodoRsrc:1541_ROM"
|
|
|
|
#elif GEKKO
|
|
|
|
#define WII_FRODO_BASE_PATH "/apps/frodo/"
|
|
|
|
#define BASIC_ROM_FILE WII_FRODO_BASE_PATH"Basic_ROM"
|
|
|
|
#define KERNAL_ROM_FILE WII_FRODO_BASE_PATH"Kernal_ROM"
|
|
|
|
#define CHAR_ROM_FILE WII_FRODO_BASE_PATH"Char_ROM"
|
|
|
|
#define DRIVE_ROM_FILE WII_FRODO_BASE_PATH"1541_ROM"
|
|
|
|
#else
|
|
|
|
#define BASIC_ROM_FILE DATADIR "Basic ROM"
|
|
|
|
#define KERNAL_ROM_FILE DATADIR "Kernal ROM"
|
|
|
|
#define CHAR_ROM_FILE DATADIR "Char ROM"
|
|
|
|
#define DRIVE_ROM_FILE DATADIR "1541 ROM"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Builtin ROMs
|
|
|
|
#include "Basic_ROM.h"
|
|
|
|
#include "Kernal_ROM.h"
|
|
|
|
#include "Char_ROM.h"
|
|
|
|
#include "1541_ROM.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load C64 ROM files
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Frodo::load_rom(const char *which, const char *path, uint8 *where, size_t size, const uint8 *builtin)
|
|
|
|
{
|
|
|
|
FILE *f = fopen(path, "rb");
|
|
|
|
if (f) {
|
|
|
|
size_t actual = fread(where, 1, size, f);
|
|
|
|
fclose(f);
|
|
|
|
if (actual == size)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use builtin ROM
|
|
|
|
printf("%s ROM file (%s) not readable, using builtin.\n", which, path);
|
|
|
|
memcpy(where, builtin, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Frodo::load_rom_files()
|
|
|
|
{
|
|
|
|
load_rom("Basic", BASIC_ROM_FILE, TheC64->Basic, BASIC_ROM_SIZE, builtin_basic_rom);
|
|
|
|
load_rom("Kernal", KERNAL_ROM_FILE, TheC64->Kernal, KERNAL_ROM_SIZE, builtin_kernal_rom);
|
|
|
|
load_rom("Char", CHAR_ROM_FILE, TheC64->Char, CHAR_ROM_SIZE, builtin_char_rom);
|
|
|
|
load_rom("1541", DRIVE_ROM_FILE, TheC64->ROM1541, DRIVE_ROM_SIZE, builtin_drive_rom);
|
|
|
|
}
|
|
|
|
|
2010-02-07 16:14:52 +01:00
|
|
|
/*
|
|
|
|
* Create application object and start it
|
|
|
|
*/
|
2009-01-13 19:46:42 +01:00
|
|
|
|
2010-02-07 16:14:52 +01:00
|
|
|
extern "C" int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
srand(tv.tv_usec);
|
|
|
|
|
|
|
|
// Init SDL
|
2010-02-23 18:30:57 +01:00
|
|
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) < 0) {
|
2010-02-07 16:14:52 +01:00
|
|
|
fprintf(stderr, "Couldn't initialize SDL (%s)\n", SDL_GetError());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (TTF_Init() < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Unable to init TTF: %s\n", TTF_GetError() );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
Frodo *the_app = new Frodo();
|
|
|
|
the_app->ArgvReceived(argc, argv);
|
|
|
|
the_app->ReadyToRun();
|
|
|
|
delete the_app;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2009-01-13 19:46:42 +01:00
|
|
|
|
|
|
|
|
2010-02-07 16:14:52 +01:00
|
|
|
/*
|
|
|
|
* Constructor: Initialize member variables
|
|
|
|
*/
|
2009-01-13 19:46:42 +01:00
|
|
|
|
2010-02-07 16:14:52 +01:00
|
|
|
Frodo::Frodo()
|
|
|
|
{
|
2010-02-23 19:23:04 +01:00
|
|
|
Prefs p;
|
|
|
|
|
2010-02-07 16:14:52 +01:00
|
|
|
TheC64 = NULL;
|
2010-02-23 19:23:04 +01:00
|
|
|
ThePrefs = p; /* Silly workaround to fix joystick bug */
|
2010-02-24 12:34:56 +01:00
|
|
|
TheDefaultPrefs = p;
|
2010-02-07 16:14:52 +01:00
|
|
|
}
|
2009-01-13 19:46:42 +01:00
|
|
|
|
|
|
|
|
2010-02-07 16:14:52 +01:00
|
|
|
/*
|
|
|
|
* Process command line arguments
|
|
|
|
*/
|
|
|
|
char *network_server_connect = 0;
|
2009-01-13 19:46:42 +01:00
|
|
|
|
2010-02-07 16:14:52 +01:00
|
|
|
void Frodo::ArgvReceived(int argc, char **argv)
|
|
|
|
{
|
|
|
|
if (argc == 2)
|
|
|
|
network_server_connect = argv[1];
|
|
|
|
}
|
|
|
|
|
2010-02-07 17:15:36 +01:00
|
|
|
const char *try_path(const char *path, const char *file)
|
|
|
|
{
|
|
|
|
if (path == NULL || file == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
char *what = (char *)xmalloc(strlen(path) + strlen(file) + 3);
|
|
|
|
struct stat st;
|
|
|
|
const char *out = NULL;
|
|
|
|
|
|
|
|
sprintf(what, "%s/%s", path, file);
|
2010-02-07 18:04:27 +01:00
|
|
|
if (stat(what, &st) == 0)
|
2010-02-07 17:15:36 +01:00
|
|
|
out = what;
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Frodo::LoadFrodorc()
|
|
|
|
{
|
|
|
|
const char *paths[] = {
|
2010-03-16 21:17:52 +01:00
|
|
|
"/frodo", // Wii
|
2010-02-07 18:04:27 +01:00
|
|
|
".",
|
|
|
|
"/apps/frodo", // Wii
|
2010-02-07 17:15:36 +01:00
|
|
|
"frodo",
|
2010-03-16 21:17:52 +01:00
|
|
|
NULL, // Filled in below
|
|
|
|
NULL, // also filled in below
|
2010-02-07 18:04:27 +01:00
|
|
|
"/usr/share/frodo",
|
2010-02-07 17:15:36 +01:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
const char *prefs_path = NULL;
|
|
|
|
const char *prefs_name = NULL;
|
|
|
|
const char *total_name = NULL;
|
|
|
|
char home_1[255];
|
|
|
|
char home_2[255];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (getenv("HOME"))
|
|
|
|
{
|
|
|
|
snprintf(home_1, sizeof(home_1), "%s/.frodo", getenv("HOME"));
|
|
|
|
snprintf(home_2, sizeof(home_2), "%s/frodo", getenv("HOME"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy(home_1, "");
|
|
|
|
strcpy(home_2, "");
|
|
|
|
}
|
2010-03-16 21:17:52 +01:00
|
|
|
paths[4] = home_1;
|
|
|
|
paths[5] = home_2;
|
2010-02-07 17:15:36 +01:00
|
|
|
|
|
|
|
for (i = 0; paths[i]; i++)
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
const char *name = "frodorc";
|
|
|
|
|
|
|
|
p = try_path(paths[i], name);
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
prefs_path = paths[i];
|
|
|
|
prefs_name = name;
|
|
|
|
total_name = p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free((void*)p);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load preferences
|
2010-02-08 18:56:32 +01:00
|
|
|
if (total_name)
|
|
|
|
{
|
|
|
|
ThePrefs.Load(total_name);
|
2010-02-14 10:40:42 +01:00
|
|
|
strncpy(ThePrefs.PrefsPath, total_name, sizeof(ThePrefs.PrefsPath));
|
2010-02-08 18:56:32 +01:00
|
|
|
} else
|
2010-03-01 12:13:49 +01:00
|
|
|
printf("No frodorc, using default\n");
|
2010-02-07 17:15:36 +01:00
|
|
|
|
|
|
|
free((void*)total_name);
|
|
|
|
}
|
2010-02-07 16:14:52 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Arguments processed, run emulation
|
|
|
|
*/
|
2009-01-13 19:46:42 +01:00
|
|
|
|
2010-02-07 16:14:52 +01:00
|
|
|
void Frodo::ReadyToRun(void)
|
|
|
|
{
|
2010-02-07 17:15:36 +01:00
|
|
|
if (getcwd(AppDirPath, 256) == NULL)
|
|
|
|
strcpy(AppDirPath, "");
|
2010-02-07 16:14:52 +01:00
|
|
|
|
2010-02-07 17:15:36 +01:00
|
|
|
this->LoadFrodorc();
|
2010-02-07 16:14:52 +01:00
|
|
|
if (network_server_connect)
|
|
|
|
strncpy(ThePrefs.NetworkServer, network_server_connect,
|
|
|
|
sizeof(ThePrefs.NetworkServer));
|
2010-02-28 15:09:31 +01:00
|
|
|
panic_if (!init_graphics(),
|
|
|
|
"Can't initialize graphics!\n");
|
2010-02-07 16:14:52 +01:00
|
|
|
|
|
|
|
// Create and start C64
|
|
|
|
TheC64 = new C64;
|
2010-02-14 10:30:16 +01:00
|
|
|
DataStore::ds = new DataStore();
|
2010-02-07 16:14:52 +01:00
|
|
|
Gui::init();
|
|
|
|
load_rom_files();
|
|
|
|
TheC64->Run();
|
|
|
|
|
|
|
|
delete TheC64;
|
2010-03-21 13:52:07 +01:00
|
|
|
|
|
|
|
#if defined(GEKKO)
|
|
|
|
fatUnmount("sd:");
|
|
|
|
#endif
|
2010-02-07 16:14:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine whether path name refers to a directory
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool IsDirectory(const char *path)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
return stat(path, &st) == 0 && S_ISDIR(st.st_mode);
|
|
|
|
}
|