2009-01-13 19:46:42 +01:00
|
|
|
/*
|
|
|
|
* C64_x.i - Put the pieces together, X specific stuff
|
|
|
|
*
|
|
|
|
* Frodo (C) 1994-1997,2002 Christian Bauer
|
|
|
|
* Unix stuff by Bernd Schmidt/Lutz Vieweg
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
|
|
|
|
#if defined(GEKKO)
|
|
|
|
#include <wiiuse/wpad.h>
|
|
|
|
#include <ogc/lwp_watchdog.h>
|
|
|
|
#define SAVES_PATH "/apps/frodo/saves"
|
|
|
|
#define IMAGE_PATH "/apps/frodo/images"
|
|
|
|
#define TMP_PATH "/apps/frodo/tmp"
|
|
|
|
#else
|
|
|
|
#define SAVES_PATH "saves"
|
|
|
|
#define IMAGE_PATH "images"
|
|
|
|
#define TMP_PATH "tmp"
|
|
|
|
#endif
|
|
|
|
|
2009-10-27 17:59:05 +01:00
|
|
|
#define C64_NETWORK_BROKER "c64-network.game-host.org"
|
|
|
|
|
2009-04-18 08:14:52 +02:00
|
|
|
#include "menutexts.h"
|
|
|
|
|
2009-01-24 21:57:23 +01:00
|
|
|
/* TODO: */
|
2009-03-01 15:27:17 +01:00
|
|
|
extern char *fixme_tmp_network_server;
|
2009-01-24 21:57:23 +01:00
|
|
|
|
|
|
|
|
2009-01-13 19:46:42 +01:00
|
|
|
static struct timeval tv_start;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Constructor, system-dependent things
|
|
|
|
*/
|
|
|
|
void C64::c64_ctor1(void)
|
|
|
|
{
|
|
|
|
// Initialize joystick variables
|
|
|
|
#ifdef HAVE_LINUX_JOYSTICK_H
|
|
|
|
joyfd[0] = joyfd[1] = -1;
|
|
|
|
joy_minx = joy_miny = 32767;
|
|
|
|
joy_maxx = joy_maxy = -32768;
|
|
|
|
#endif
|
2009-11-07 11:12:49 +01:00
|
|
|
this->linecnt = 0;
|
2009-01-13 19:46:42 +01:00
|
|
|
|
|
|
|
this->fake_key_sequence = false;
|
|
|
|
this->fake_key_index = 0;
|
2009-01-24 08:30:06 +01:00
|
|
|
this->fake_key_keytime = 4;
|
2009-01-14 20:59:14 +01:00
|
|
|
this->fake_key_str = "\nLOAD \"*\",8,1\nRUN\n";
|
2009-01-13 19:46:42 +01:00
|
|
|
|
|
|
|
this->prefs_changed = false;
|
|
|
|
memset(this->save_game_name, 0, sizeof(this->save_game_name));
|
|
|
|
strcpy(this->save_game_name, "unknown");
|
|
|
|
|
2009-01-22 21:34:33 +01:00
|
|
|
this->virtual_keyboard = new VirtualKeyboard(real_screen, this->menu_font);
|
2009-04-13 10:57:31 +02:00
|
|
|
virtual_keyboard = this->virtual_keyboard;
|
2009-01-24 16:48:43 +01:00
|
|
|
|
2009-10-27 17:59:05 +01:00
|
|
|
strncpy(this->server_hostname, C64_NETWORK_BROKER,
|
2009-01-24 16:48:43 +01:00
|
|
|
sizeof(this->server_hostname));
|
2009-02-28 19:45:26 +01:00
|
|
|
this->server_port = 46214;
|
2009-02-01 20:47:21 +01:00
|
|
|
this->network_connection_type = NONE;
|
2009-02-08 12:27:56 +01:00
|
|
|
this->peer = NULL;
|
2009-01-24 21:57:23 +01:00
|
|
|
|
2009-02-01 20:47:21 +01:00
|
|
|
if (fixme_tmp_network_server) {
|
2009-11-01 09:44:34 +01:00
|
|
|
printf("Connecting to %s\n", fixme_tmp_network_server);
|
2009-03-01 15:27:17 +01:00
|
|
|
strcpy(this->server_hostname, fixme_tmp_network_server);
|
2009-10-28 19:04:30 +01:00
|
|
|
this->peer = new Network(this->server_hostname, this->server_port);
|
2009-11-01 09:44:34 +01:00
|
|
|
this->network_connection_type = CONNECT;
|
2009-02-01 20:47:21 +01:00
|
|
|
}
|
2009-01-13 19:46:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void C64::c64_ctor2(void)
|
|
|
|
{
|
|
|
|
gettimeofday(&tv_start, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Destructor, system-dependent things
|
|
|
|
*/
|
|
|
|
|
|
|
|
void C64::c64_dtor(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-04-19 14:57:29 +02:00
|
|
|
void C64::select_disc(Prefs *np, bool start)
|
2009-01-13 19:46:42 +01:00
|
|
|
{
|
2009-04-19 14:57:29 +02:00
|
|
|
const char *name;
|
|
|
|
const char *d64_name = NULL;
|
|
|
|
|
|
|
|
if (!start)
|
|
|
|
name = menu_select_file(IMAGE_PATH);
|
|
|
|
else
|
|
|
|
name = menu_select_file_start(IMAGE_PATH, &d64_name);
|
2009-01-13 19:46:42 +01:00
|
|
|
|
2009-04-18 12:15:08 +02:00
|
|
|
if (name== NULL)
|
2009-01-13 19:46:42 +01:00
|
|
|
return;
|
|
|
|
|
2009-04-18 12:15:08 +02:00
|
|
|
if (strcmp(name, "None") == 0)
|
|
|
|
{
|
|
|
|
strcpy(np->DrivePath[0], "\0");
|
|
|
|
strcpy(this->save_game_name, "unknown");
|
|
|
|
}
|
|
|
|
else
|
2009-01-13 19:46:42 +01:00
|
|
|
{
|
2009-04-19 16:12:54 +02:00
|
|
|
const char *save_game = strrchr(name, '/');
|
|
|
|
|
|
|
|
if (!save_game)
|
|
|
|
save_game = name;
|
|
|
|
else
|
|
|
|
save_game = save_game + 1; /* Skip '/' */
|
2009-04-18 13:21:40 +02:00
|
|
|
strncpy(np->DrivePath[0], name, 255);
|
2009-04-19 16:12:54 +02:00
|
|
|
strncpy(this->save_game_name, save_game, 255);
|
2009-04-18 12:15:08 +02:00
|
|
|
if (strstr(name, ".prg") || strstr(name, ".PRG") ||
|
|
|
|
strstr(name, ".p00") || strstr(name, ".P00") ||
|
|
|
|
strstr(name, ".s00") || strstr(name, ".S00")) {
|
|
|
|
FILE *src, *dst;
|
|
|
|
|
|
|
|
/* Clean temp dir first (we only want one file) */
|
|
|
|
unlink(TMP_PATH"/a");
|
|
|
|
|
|
|
|
src = fopen(np->DrivePath[0], "r");
|
|
|
|
if (src != NULL)
|
|
|
|
{
|
|
|
|
snprintf(np->DrivePath[0], 255, "%s", TMP_PATH);
|
2009-01-13 19:46:42 +01:00
|
|
|
|
2009-04-18 12:15:08 +02:00
|
|
|
/* Special handling of .prg: Copy to TMP_PATH and
|
|
|
|
* load that as a dir */
|
|
|
|
dst = fopen(TMP_PATH"/a", "w");
|
|
|
|
if (dst)
|
2009-01-13 19:46:42 +01:00
|
|
|
{
|
2009-04-18 12:15:08 +02:00
|
|
|
Uint8 buf[1024];
|
|
|
|
size_t v;
|
|
|
|
|
|
|
|
do {
|
|
|
|
v = fread(buf, 1, 1024, src);
|
|
|
|
fwrite(buf, 1, v, dst);
|
|
|
|
} while (v > 0);
|
|
|
|
fclose(dst);
|
2009-01-13 19:46:42 +01:00
|
|
|
}
|
2009-04-18 12:15:08 +02:00
|
|
|
fclose(src);
|
2009-01-13 19:46:42 +01:00
|
|
|
}
|
|
|
|
}
|
2009-04-18 12:15:08 +02:00
|
|
|
|
|
|
|
NewPrefs(np);
|
|
|
|
ThePrefs = *np;
|
2009-01-13 19:46:42 +01:00
|
|
|
}
|
2009-04-18 12:15:08 +02:00
|
|
|
this->prefs_changed = true;
|
2009-01-13 19:46:42 +01:00
|
|
|
|
2009-04-18 12:15:08 +02:00
|
|
|
/* Cleanup*/
|
|
|
|
free((void*)name);
|
2009-04-19 14:57:29 +02:00
|
|
|
|
|
|
|
/* And maybe start the game */
|
|
|
|
if (d64_name)
|
|
|
|
{
|
|
|
|
static char buf[255];
|
|
|
|
|
|
|
|
snprintf(buf, 255, "\nLOAD \"%s\",8,1\nRUN\n", d64_name);
|
|
|
|
this->start_fake_key_sequence((const char*)buf);
|
|
|
|
free((void*)d64_name);
|
|
|
|
}
|
|
|
|
else if (start)
|
|
|
|
this->start_fake_key_sequence("\nLOAD \"*\",8,1\nRUN\n");
|
2009-01-13 19:46:42 +01:00
|
|
|
}
|
|
|
|
|
2009-01-14 18:31:30 +01:00
|
|
|
|
|
|
|
char *C64::bind_one_key(Prefs *np, int which)
|
|
|
|
{
|
2009-02-21 10:01:33 +01:00
|
|
|
static const char *which_to_button_name[N_WIIMOTE_BINDINGS] = {
|
|
|
|
"up", "down", "left", "right",
|
2009-02-21 10:49:20 +01:00
|
|
|
"2", "1", "A", "B", "+", "-",
|
2009-02-21 10:01:33 +01:00
|
|
|
"classic up", "classic down", "classic left", "classic right", "classic a",
|
2009-02-21 10:49:20 +01:00
|
|
|
"classic b", "classic X", "classic Y", "classic L",
|
2009-01-14 18:31:30 +01:00
|
|
|
"classic R", "classic ZR", "classic ZL" };
|
|
|
|
static char strs[N_WIIMOTE_BINDINGS][255];
|
|
|
|
char *out = strs[which];
|
|
|
|
int cur = np->JoystickKeyBinding[which];
|
|
|
|
|
|
|
|
snprintf(out, 255, "Bind to %s (now %s)", which_to_button_name[which],
|
2009-01-22 22:05:04 +01:00
|
|
|
this->virtual_keyboard->keycode_to_string(cur));
|
2009-01-14 18:31:30 +01:00
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void C64::bind_keys(Prefs *np)
|
2009-01-13 19:46:42 +01:00
|
|
|
{
|
2009-01-14 18:31:30 +01:00
|
|
|
const char *bind_key_messages[N_WIIMOTE_BINDINGS + 1];
|
2009-01-13 19:46:42 +01:00
|
|
|
bool has_classic_controller = false;
|
|
|
|
|
|
|
|
#if defined(GEKKO)
|
|
|
|
WPADData *wpad, *wpad_other;
|
|
|
|
|
|
|
|
wpad = WPAD_Data(0);
|
|
|
|
wpad_other = WPAD_Data(1);
|
|
|
|
|
|
|
|
if (wpad->exp.type == WPAD_EXP_CLASSIC ||
|
|
|
|
wpad_other->exp.type == WPAD_EXP_CLASSIC)
|
|
|
|
has_classic_controller = true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
memset(bind_key_messages, 0, sizeof(const char*) * (N_WIIMOTE_BINDINGS + 1));
|
|
|
|
|
2009-03-09 19:54:43 +01:00
|
|
|
for (int i = 0; i < (has_classic_controller ? N_WIIMOTE_BINDINGS : CLASSIC_UP); i++)
|
2009-01-14 18:31:30 +01:00
|
|
|
bind_key_messages[i] = this->bind_one_key(np, i);
|
2009-01-13 19:46:42 +01:00
|
|
|
|
2009-02-13 08:58:33 +01:00
|
|
|
int opt = menu_select(bind_key_messages, NULL);
|
2009-01-13 19:46:42 +01:00
|
|
|
if (opt >= 0)
|
|
|
|
{
|
2009-01-22 21:34:33 +01:00
|
|
|
int key;
|
|
|
|
bool shifted;
|
2009-01-13 19:46:42 +01:00
|
|
|
|
2009-01-23 19:29:09 +01:00
|
|
|
key = this->virtual_keyboard->get_key();
|
2009-01-23 21:49:00 +01:00
|
|
|
/* -2 means abort */
|
|
|
|
if (key != np->JoystickKeyBinding[opt] && key != -2)
|
2009-01-22 21:34:33 +01:00
|
|
|
{
|
|
|
|
this->prefs_changed = true;
|
|
|
|
np->JoystickKeyBinding[opt] = key;
|
|
|
|
}
|
2009-01-13 19:46:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-24 16:48:43 +01:00
|
|
|
void C64::networking_menu(Prefs *np)
|
|
|
|
{
|
|
|
|
int opt;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2009-03-01 09:27:53 +01:00
|
|
|
char buf[3][255];
|
2009-01-24 16:48:43 +01:00
|
|
|
const char *network_client_messages[] = {
|
2009-03-01 09:27:53 +01:00
|
|
|
buf[0], /* 0 */
|
|
|
|
buf[1], /* 1 */
|
|
|
|
buf[2], /* 2 */
|
2009-10-28 19:04:30 +01:00
|
|
|
"#2 ", /* 3 */
|
|
|
|
"Connect to the C64 network!", /* 4 */
|
2009-01-24 16:48:43 +01:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2009-03-01 09:27:53 +01:00
|
|
|
snprintf(buf[0], 255, "Set username (%s)",
|
|
|
|
np->NetworkName);
|
|
|
|
snprintf(buf[1], 255, "Server hostname (%s)",
|
2009-01-24 16:48:43 +01:00
|
|
|
this->server_hostname);
|
2009-03-01 09:27:53 +01:00
|
|
|
snprintf(buf[2], 255, "Port (%d)",
|
2009-01-24 16:48:43 +01:00
|
|
|
this->server_port);
|
2009-04-19 15:24:27 +02:00
|
|
|
opt = menu_select("Networking", network_client_messages, NULL);
|
2009-01-24 16:48:43 +01:00
|
|
|
|
2009-03-01 09:27:53 +01:00
|
|
|
if (opt >= 0 && opt <= 2)
|
2009-01-24 16:48:43 +01:00
|
|
|
{
|
|
|
|
const char *m = this->virtual_keyboard->get_string();
|
|
|
|
|
2009-03-01 09:27:53 +01:00
|
|
|
if (m)
|
|
|
|
{
|
|
|
|
if (opt == 0)
|
|
|
|
{
|
|
|
|
memset(np->NetworkName, 0,
|
|
|
|
sizeof(np->NetworkName));
|
|
|
|
strncpy(np->NetworkName, m,
|
|
|
|
sizeof(np->NetworkName));
|
|
|
|
} else if (opt == 1)
|
|
|
|
strncpy(this->server_hostname, m,
|
|
|
|
sizeof(this->server_hostname));
|
|
|
|
if (opt == 2)
|
|
|
|
this->server_port = atoi(m);
|
|
|
|
}
|
2009-01-24 16:48:43 +01:00
|
|
|
}
|
2009-10-28 19:04:30 +01:00
|
|
|
else if (opt == 4) {
|
|
|
|
if (strncmp(np->NetworkName, "Unset", 5) == 0)
|
2009-03-01 12:04:47 +01:00
|
|
|
{
|
2009-10-28 19:04:30 +01:00
|
|
|
char *msg = "Select name first";
|
|
|
|
|
|
|
|
msgYesNo(msg, false, 160, 160);
|
|
|
|
continue;
|
2009-03-01 12:04:47 +01:00
|
|
|
}
|
2009-10-28 19:04:30 +01:00
|
|
|
|
|
|
|
this->peer = new Network(this->server_hostname, this->server_port);
|
|
|
|
this->network_connection_type = CONNECT;
|
2009-01-24 16:48:43 +01:00
|
|
|
}
|
2009-10-28 19:04:30 +01:00
|
|
|
} while (opt >= 0 && opt <= 2);
|
2009-01-24 16:48:43 +01:00
|
|
|
|
|
|
|
this->prefs_changed = true;
|
|
|
|
}
|
|
|
|
|
2009-04-19 14:57:29 +02:00
|
|
|
void C64::advanced_options(Prefs *np)
|
2009-01-13 19:46:42 +01:00
|
|
|
{
|
2009-04-19 14:57:29 +02:00
|
|
|
int submenus[4] = { np->DisplayOption, 0,
|
|
|
|
np->SpriteCollisions, 0 };
|
2009-01-13 19:46:42 +01:00
|
|
|
|
2009-02-21 14:05:29 +01:00
|
|
|
#define SPEED_95 30
|
|
|
|
#define SPEED_100 20
|
2009-04-14 20:17:46 +02:00
|
|
|
#define SPEED_110 18
|
2009-01-13 19:46:42 +01:00
|
|
|
|
2009-01-24 16:48:43 +01:00
|
|
|
switch (np->MsPerFrame)
|
|
|
|
{
|
|
|
|
case SPEED_95:
|
|
|
|
submenus[1] = 0; break;
|
|
|
|
case SPEED_110:
|
|
|
|
submenus[1] = 2; break;
|
|
|
|
default:
|
|
|
|
/* If it has some other value... */
|
|
|
|
submenus[1] = 1; break;
|
|
|
|
}
|
2009-04-19 14:57:29 +02:00
|
|
|
|
2009-04-19 15:24:27 +02:00
|
|
|
int opt = menu_select("Advanced options",
|
|
|
|
new_advanced_options_menu_messages,
|
2009-04-19 14:57:29 +02:00
|
|
|
submenus);
|
2009-01-13 19:46:42 +01:00
|
|
|
if (opt >= 0)
|
|
|
|
{
|
|
|
|
np->DisplayOption = submenus[0];
|
2009-04-19 14:57:29 +02:00
|
|
|
np->SpriteCollisions = submenus[2];
|
2009-01-14 07:39:48 +01:00
|
|
|
|
2009-01-13 19:46:42 +01:00
|
|
|
switch(submenus[1])
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
np->MsPerFrame = SPEED_95; break;
|
|
|
|
case 1:
|
|
|
|
np->MsPerFrame = SPEED_100; break;
|
|
|
|
case 2:
|
|
|
|
default:
|
|
|
|
np->MsPerFrame = SPEED_110; break;
|
|
|
|
}
|
2009-01-24 16:48:43 +01:00
|
|
|
|
2009-04-19 14:57:29 +02:00
|
|
|
this->prefs_changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void C64::other_options(Prefs *np)
|
|
|
|
{
|
2009-04-20 20:39:46 +02:00
|
|
|
int old_swap = np->JoystickSwap == true ? 1 : 0;
|
2009-04-19 14:57:29 +02:00
|
|
|
int submenus[3] = { old_swap, !np->Emul1541Proc, 0 };
|
|
|
|
|
2009-04-19 15:24:27 +02:00
|
|
|
int opt = menu_select("Options", new_options_menu_messages,
|
2009-04-19 14:57:29 +02:00
|
|
|
submenus);
|
|
|
|
if (opt >= 0)
|
|
|
|
{
|
|
|
|
np->Emul1541Proc = submenus[1] == 0 ? true : false;
|
2009-04-20 20:39:46 +02:00
|
|
|
np->JoystickSwap = submenus[0] == 0 ? false : true;
|
2009-01-24 16:48:43 +01:00
|
|
|
|
2009-01-13 19:46:42 +01:00
|
|
|
this->prefs_changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-24 09:36:47 +01:00
|
|
|
/* From dreamcast port but heavily modified */
|
|
|
|
void C64::run_fake_key_sequence()
|
|
|
|
{
|
|
|
|
int kc = this->virtual_keyboard->char_to_keycode(this->fake_key_str[this->fake_key_index]);
|
|
|
|
|
|
|
|
TheDisplay->FakeKeyPress(kc, TheCIA1->KeyMatrix, TheCIA1->RevMatrix);
|
|
|
|
|
|
|
|
this->fake_key_keytime --;
|
|
|
|
if (this->fake_key_keytime == 0)
|
|
|
|
{
|
|
|
|
this->fake_key_keytime = 4;
|
|
|
|
this->fake_key_index ++;
|
2009-01-24 10:21:45 +01:00
|
|
|
TheDisplay->FakeKeyPress(-1, TheCIA1->KeyMatrix, TheCIA1->RevMatrix);
|
2009-01-24 09:36:47 +01:00
|
|
|
|
|
|
|
if (this->fake_key_str[this->fake_key_index] == '\0')
|
|
|
|
{
|
|
|
|
this->fake_key_sequence = false;
|
|
|
|
this->fake_key_index = 0;
|
|
|
|
this->fake_key_keytime = 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void C64::start_fake_key_sequence(const char *str)
|
|
|
|
{
|
|
|
|
this->fake_key_str = str;
|
|
|
|
this->fake_key_sequence = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void C64::select_fake_key_sequence(Prefs *np)
|
2009-01-14 20:59:14 +01:00
|
|
|
{
|
|
|
|
static const char *fake_key_sequences[] = {
|
|
|
|
"\nLOAD \"*\",8,1\nRUN\n",
|
2009-01-24 10:21:45 +01:00
|
|
|
"\nLOAD \"$\",8\n",
|
2009-01-14 20:59:14 +01:00
|
|
|
"\nLIST\n",
|
|
|
|
NULL};
|
|
|
|
const char *fake_key_messages[] = {
|
|
|
|
"LOAD \"*\",8,1 and RUN",
|
2009-01-24 10:21:45 +01:00
|
|
|
"LOAD \"$\",8",
|
2009-01-14 20:59:14 +01:00
|
|
|
"LIST",
|
|
|
|
NULL};
|
|
|
|
int opt;
|
|
|
|
|
2009-04-19 15:24:27 +02:00
|
|
|
opt = menu_select("Keyboard macros", fake_key_messages, NULL);
|
2009-01-14 20:59:14 +01:00
|
|
|
if (opt < 0)
|
|
|
|
return;
|
|
|
|
|
2009-04-19 14:57:29 +02:00
|
|
|
this->start_fake_key_sequence(fake_key_sequences[opt]);
|
2009-01-14 20:59:14 +01:00
|
|
|
}
|
|
|
|
|
2009-04-19 14:57:29 +02:00
|
|
|
void C64::save_load_state(Prefs *np, int opt)
|
2009-01-13 19:46:42 +01:00
|
|
|
{
|
|
|
|
switch(opt)
|
|
|
|
{
|
|
|
|
case 1: /* save */
|
|
|
|
{
|
2009-01-14 18:48:04 +01:00
|
|
|
char save_buf[255];
|
|
|
|
char prefs_buf[255];
|
2009-01-13 19:46:42 +01:00
|
|
|
|
2009-04-19 16:12:54 +02:00
|
|
|
snprintf(save_buf, 255, "%s/%s.sav", SAVES_PATH,
|
2009-01-13 19:46:42 +01:00
|
|
|
this->save_game_name);
|
2009-01-14 18:48:04 +01:00
|
|
|
snprintf(prefs_buf, 255, "%s.prefs", save_buf);
|
2009-01-13 19:46:42 +01:00
|
|
|
|
2009-01-14 18:48:04 +01:00
|
|
|
this->SaveSnapshot(save_buf);
|
|
|
|
np->Save(prefs_buf);
|
2009-01-13 19:46:42 +01:00
|
|
|
} break;
|
|
|
|
case 0: /* load/delete */
|
|
|
|
case 2:
|
|
|
|
{
|
2009-04-18 12:15:08 +02:00
|
|
|
const char *name = menu_select_file(SAVES_PATH);
|
|
|
|
char save_buf[255];
|
|
|
|
char prefs_buf[255];
|
2009-01-13 19:46:42 +01:00
|
|
|
|
2009-04-18 12:15:08 +02:00
|
|
|
if (name == NULL)
|
2009-01-13 19:46:42 +01:00
|
|
|
break;
|
|
|
|
|
2009-04-18 13:21:40 +02:00
|
|
|
snprintf(save_buf, 255, "%s", name);
|
2009-04-18 12:15:08 +02:00
|
|
|
snprintf(prefs_buf, 255, "%s.prefs", save_buf);
|
|
|
|
if (opt == 2)
|
|
|
|
{
|
|
|
|
unlink(save_buf);
|
|
|
|
unlink(prefs_buf);
|
|
|
|
}
|
|
|
|
else /* Load the snapshot */
|
|
|
|
{
|
|
|
|
this->LoadSnapshot(save_buf);
|
|
|
|
np->Load(prefs_buf);
|
|
|
|
this->prefs_changed = true;
|
2009-01-13 19:46:42 +01:00
|
|
|
}
|
|
|
|
|
2009-04-18 12:15:08 +02:00
|
|
|
free((void*)name);
|
2009-01-13 19:46:42 +01:00
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start main emulation thread
|
|
|
|
*/
|
|
|
|
|
|
|
|
void C64::Run(void)
|
|
|
|
{
|
|
|
|
// Reset chips
|
|
|
|
TheCPU->Reset();
|
|
|
|
TheSID->Reset();
|
|
|
|
TheCIA1->Reset();
|
|
|
|
TheCIA2->Reset();
|
|
|
|
TheCPU1541->Reset();
|
|
|
|
|
|
|
|
// Patch kernal IEC routines
|
|
|
|
orig_kernal_1d84 = Kernal[0x1d84];
|
|
|
|
orig_kernal_1d85 = Kernal[0x1d85];
|
|
|
|
PatchKernal(ThePrefs.FastReset, ThePrefs.Emul1541Proc);
|
|
|
|
|
|
|
|
quit_thyself = false;
|
|
|
|
thread_func();
|
|
|
|
}
|
|
|
|
|
2009-01-29 21:26:40 +01:00
|
|
|
void C64::network_vblank()
|
2009-01-29 19:04:31 +01:00
|
|
|
{
|
2009-01-30 18:49:47 +01:00
|
|
|
static uint32_t last_time_update;
|
2009-01-29 19:04:31 +01:00
|
|
|
#if defined(GEKKO)
|
|
|
|
Uint32 now = ticks_to_millisecs(gettime());
|
|
|
|
#else
|
|
|
|
Uint32 now = SDL_GetTicks();
|
|
|
|
#endif
|
|
|
|
|
2009-02-08 12:27:56 +01:00
|
|
|
if (this->peer) {
|
2009-02-01 20:47:21 +01:00
|
|
|
Uint8 *master = this->TheDisplay->BitmapBase();
|
2009-02-08 12:27:56 +01:00
|
|
|
Network *remote = this->peer;
|
2009-02-01 20:47:21 +01:00
|
|
|
uint8 *js;
|
|
|
|
static bool has_throttled;
|
2009-01-29 19:04:31 +01:00
|
|
|
|
2009-02-01 20:47:21 +01:00
|
|
|
if (this->quit_thyself)
|
2009-01-29 19:04:31 +01:00
|
|
|
{
|
2009-10-28 19:04:30 +01:00
|
|
|
if (this->network_connection_type != CONNECT)
|
2009-04-04 10:23:51 +02:00
|
|
|
remote->Disconnect();
|
2009-02-08 12:27:56 +01:00
|
|
|
delete remote;
|
|
|
|
this->peer = NULL;
|
|
|
|
return;
|
2009-01-29 19:04:31 +01:00
|
|
|
}
|
2009-01-29 22:11:04 +01:00
|
|
|
|
2009-02-01 20:47:21 +01:00
|
|
|
remote->Tick( now - last_time_update );
|
|
|
|
if (this->network_connection_type == MASTER) {
|
|
|
|
if (ThePrefs.JoystickSwap)
|
|
|
|
js = &TheCIA1->Joystick1;
|
|
|
|
else
|
|
|
|
js = &TheCIA1->Joystick2;
|
2009-10-28 19:04:30 +01:00
|
|
|
} else if (this->network_connection_type == CONNECT) {
|
2009-04-04 10:23:51 +02:00
|
|
|
network_connection_error_t err = this->peer->ConnectFSM();
|
|
|
|
|
|
|
|
TheDisplay->display_status_string("WAITING FOR CONNECTION...", 1);
|
|
|
|
|
|
|
|
if (err == OK) {
|
2009-11-04 17:43:47 +01:00
|
|
|
if (this->peer->is_master)
|
2009-10-28 19:04:30 +01:00
|
|
|
this->network_connection_type = MASTER;
|
|
|
|
else
|
|
|
|
this->network_connection_type = CLIENT;
|
|
|
|
TheDisplay->display_status_string("CONNECTED!", 1);
|
2009-04-04 10:23:51 +02:00
|
|
|
}
|
|
|
|
else if (err != AGAIN_ERROR)
|
|
|
|
{
|
2009-10-28 19:04:30 +01:00
|
|
|
if (err == VERSION_ERROR) {
|
|
|
|
TheDisplay->display_status_string("YOUR FRODO IS TOO OLD, DOWNLOAD NEW AT HTTP://FRODO-WII.GOOGLECODE.COM", 5);
|
|
|
|
}
|
2009-04-04 10:23:51 +02:00
|
|
|
delete remote;
|
|
|
|
this->peer = NULL;
|
|
|
|
}
|
|
|
|
return;
|
2009-02-01 20:47:21 +01:00
|
|
|
} else {
|
|
|
|
if (ThePrefs.JoystickSwap)
|
|
|
|
js = &TheCIA1->Joystick2;
|
|
|
|
else
|
|
|
|
js = &TheCIA1->Joystick1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Has the peer sent any data? */
|
|
|
|
if (remote->ReceiveUpdate() == true)
|
|
|
|
{
|
2009-04-13 08:31:12 +02:00
|
|
|
if (remote->DecodeUpdate(this->TheDisplay,
|
2009-04-09 15:42:49 +02:00
|
|
|
js, this->TheSID) == false)
|
2009-02-01 20:47:21 +01:00
|
|
|
{
|
|
|
|
/* Disconnect or sending crap, remove this guy! */
|
2009-02-08 12:27:56 +01:00
|
|
|
delete remote;
|
|
|
|
this->peer = NULL;
|
|
|
|
return;
|
2009-02-01 20:47:21 +01:00
|
|
|
}
|
|
|
|
if (this->network_connection_type == CLIENT)
|
|
|
|
this->TheDisplay->Update(remote->GetScreen());
|
|
|
|
}
|
|
|
|
remote->ResetNetworkUpdate();
|
|
|
|
|
2009-04-10 13:39:46 +02:00
|
|
|
/* Encode and send updates to the other side (what is determined by
|
|
|
|
* if this is the master or not) */
|
|
|
|
if (this->network_connection_type == MASTER)
|
|
|
|
{
|
|
|
|
/* Skip this frame if the data rate is too high */
|
|
|
|
if (remote->ThrottleTraffic())
|
|
|
|
has_throttled = true;
|
2009-11-07 13:33:09 +01:00
|
|
|
else {
|
2009-04-10 13:39:46 +02:00
|
|
|
remote->EncodeDisplay(master, remote->GetScreen());
|
2009-11-07 13:33:09 +01:00
|
|
|
remote->FlushSound();
|
|
|
|
}
|
2009-02-01 20:47:21 +01:00
|
|
|
}
|
|
|
|
|
2009-04-13 10:57:31 +02:00
|
|
|
char *msg = TheDisplay->GetTextMessage();
|
|
|
|
if (msg)
|
|
|
|
remote->EncodeTextMessage(msg);
|
|
|
|
|
2009-02-02 19:36:51 +01:00
|
|
|
remote->EncodeJoystickUpdate(*js);
|
|
|
|
|
2009-02-01 20:47:21 +01:00
|
|
|
if (remote->SendUpdate() == false)
|
|
|
|
{
|
|
|
|
/* Disconnect or broken data */
|
|
|
|
printf("Could not send update\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
remote->ResetNetworkUpdate();
|
2009-01-29 22:11:04 +01:00
|
|
|
|
2009-02-01 20:47:21 +01:00
|
|
|
if (1)
|
|
|
|
{
|
|
|
|
static uint32_t last_traffic_update;
|
|
|
|
|
|
|
|
if (last_time_update - last_traffic_update > 300)
|
|
|
|
{
|
|
|
|
TheDisplay->NetworkTrafficMeter(remote->GetKbps() / (8 * 1024.0),
|
|
|
|
has_throttled);
|
|
|
|
last_traffic_update = now;
|
|
|
|
has_throttled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
last_time_update = now;
|
2009-01-29 19:04:31 +01:00
|
|
|
}
|
|
|
|
|
2009-01-13 19:46:42 +01:00
|
|
|
/*
|
|
|
|
* Vertical blank: Poll keyboard and joysticks, update window
|
|
|
|
*/
|
|
|
|
|
|
|
|
void C64::VBlank(bool draw_frame)
|
|
|
|
{
|
2009-01-24 21:57:23 +01:00
|
|
|
/* From Acorn port */
|
2009-01-30 18:49:47 +01:00
|
|
|
static uint32_t lastFrame;
|
|
|
|
uint32_t now;
|
2009-01-29 22:11:04 +01:00
|
|
|
uint8 j1, j2;
|
2009-01-24 21:57:23 +01:00
|
|
|
|
2009-01-13 19:46:42 +01:00
|
|
|
#if defined(GEKKO)
|
|
|
|
WPAD_ScanPads();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Poll joysticks
|
2009-01-29 22:11:04 +01:00
|
|
|
j1 = poll_joystick(0);
|
|
|
|
j2 = poll_joystick(1);
|
2009-01-13 19:46:42 +01:00
|
|
|
|
|
|
|
// Poll keyboard
|
|
|
|
TheDisplay->PollKeyboard(TheCIA1->KeyMatrix, TheCIA1->RevMatrix, &joykey);
|
|
|
|
if (TheDisplay->quit_requested)
|
|
|
|
quit_thyself = true;
|
|
|
|
|
|
|
|
if (this->fake_key_sequence)
|
2009-01-24 09:36:47 +01:00
|
|
|
this->run_fake_key_sequence();
|
2009-01-13 19:46:42 +01:00
|
|
|
#ifndef GEKKO
|
|
|
|
// Joystick keyboard emulation
|
|
|
|
if (TheDisplay->NumLock())
|
2009-01-29 22:11:04 +01:00
|
|
|
j1 &= joykey;
|
2009-01-13 19:46:42 +01:00
|
|
|
else
|
2009-01-29 22:11:04 +01:00
|
|
|
j2 &= joykey;
|
2009-01-13 19:46:42 +01:00
|
|
|
#endif
|
|
|
|
|
2009-02-01 20:47:21 +01:00
|
|
|
if (this->network_connection_type == MASTER)
|
2009-01-29 22:11:04 +01:00
|
|
|
{
|
|
|
|
/* Only poll one joystick for network servers */
|
|
|
|
if (ThePrefs.JoystickSwap)
|
|
|
|
TheCIA1->Joystick2 = j2;
|
|
|
|
else
|
|
|
|
TheCIA1->Joystick1 = j2;
|
|
|
|
}
|
2009-04-04 12:21:35 +02:00
|
|
|
else if (this->network_connection_type == CLIENT)
|
|
|
|
{
|
|
|
|
Uint8 which = j2;
|
|
|
|
|
|
|
|
/* Set both joysticks to the updated value */
|
|
|
|
if (j2 != 0xff)
|
|
|
|
which = j2;
|
|
|
|
TheCIA1->Joystick1 = which;
|
|
|
|
TheCIA1->Joystick2 = which;
|
|
|
|
}
|
2009-01-29 22:11:04 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
TheCIA1->Joystick1 = j1;
|
|
|
|
TheCIA1->Joystick2 = j2;
|
|
|
|
}
|
|
|
|
|
2009-01-13 19:46:42 +01:00
|
|
|
// Count TOD clocks
|
|
|
|
TheCIA1->CountTOD();
|
|
|
|
TheCIA2->CountTOD();
|
|
|
|
|
|
|
|
// Update window if needed
|
2009-02-01 20:47:21 +01:00
|
|
|
if (draw_frame && this->network_connection_type != CLIENT) {
|
2009-01-13 19:46:42 +01:00
|
|
|
TheDisplay->Update();
|
|
|
|
}
|
2009-01-24 21:57:23 +01:00
|
|
|
|
2009-01-13 19:46:42 +01:00
|
|
|
if (this->have_a_break) {
|
2009-04-19 14:57:29 +02:00
|
|
|
int submenus[3] = {1, 0, 0};
|
2009-01-13 19:46:42 +01:00
|
|
|
int opt;
|
|
|
|
|
|
|
|
Prefs np = ThePrefs;
|
|
|
|
this->prefs_changed = false;
|
|
|
|
|
|
|
|
TheSID->PauseSound();
|
2009-04-19 15:24:27 +02:00
|
|
|
opt = menu_select("Main menu", new_main_menu_messages, submenus);
|
2009-01-13 19:46:42 +01:00
|
|
|
|
|
|
|
switch(opt)
|
|
|
|
{
|
2009-04-19 15:24:27 +02:00
|
|
|
case 0: /* Insert disc/tape */
|
2009-04-19 14:57:29 +02:00
|
|
|
this->select_disc(&np, submenus[0] == 1);
|
2009-01-13 19:46:42 +01:00
|
|
|
break;
|
2009-04-19 15:24:27 +02:00
|
|
|
case 2: /* Save / load game */
|
2009-04-19 14:57:29 +02:00
|
|
|
this->save_load_state(&np, submenus[1]);
|
2009-01-13 19:46:42 +01:00
|
|
|
break;
|
2009-04-19 15:24:27 +02:00
|
|
|
case 4: /* Bind keys to joystick */
|
2009-04-19 14:57:29 +02:00
|
|
|
switch (submenus[2])
|
|
|
|
{
|
|
|
|
case 0: /* type */
|
|
|
|
{
|
|
|
|
const char *seq = this->virtual_keyboard->get_string();
|
|
|
|
|
|
|
|
if (seq != NULL)
|
|
|
|
this->start_fake_key_sequence(seq);
|
|
|
|
} break;
|
|
|
|
case 1: /* Macro */
|
|
|
|
this->select_fake_key_sequence(&np); break;
|
|
|
|
default:
|
|
|
|
case 2: /* Bind to controller */
|
|
|
|
this->bind_keys(&np); break;
|
|
|
|
}
|
2009-01-13 19:46:42 +01:00
|
|
|
break;
|
2009-04-19 15:24:27 +02:00
|
|
|
case 7: /* Reset the C64 */
|
2009-04-19 14:57:29 +02:00
|
|
|
Reset();
|
2009-01-13 19:46:42 +01:00
|
|
|
break;
|
2009-04-19 15:24:27 +02:00
|
|
|
case 8: /* Networking */
|
2009-04-13 12:46:30 +02:00
|
|
|
this->networking_menu(&np);
|
|
|
|
break;
|
2009-04-19 15:24:27 +02:00
|
|
|
case 9: /* Other options */
|
2009-04-19 14:57:29 +02:00
|
|
|
this->other_options(&np);
|
2009-01-13 19:46:42 +01:00
|
|
|
break;
|
2009-04-19 15:24:27 +02:00
|
|
|
case 10: /* Advanced options */
|
2009-04-19 14:57:29 +02:00
|
|
|
this->advanced_options(&np);
|
2009-01-13 19:46:42 +01:00
|
|
|
break;
|
2009-04-19 15:24:27 +02:00
|
|
|
case 11:
|
2009-04-19 14:57:29 +02:00
|
|
|
{
|
2009-04-19 15:24:27 +02:00
|
|
|
menu_select("Frodo help", welcome, NULL);
|
2009-04-19 14:57:29 +02:00
|
|
|
} break;
|
2009-04-19 15:24:27 +02:00
|
|
|
case 12: /* Quit */
|
2009-01-13 19:46:42 +01:00
|
|
|
quit_thyself = true;
|
|
|
|
break;
|
|
|
|
case -1:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->prefs_changed)
|
|
|
|
{
|
|
|
|
this->NewPrefs(&np);
|
|
|
|
ThePrefs = np;
|
|
|
|
}
|
2009-01-24 08:30:06 +01:00
|
|
|
TheDisplay->FakeKeyPress(-1, TheCIA1->KeyMatrix,
|
2009-01-13 19:46:42 +01:00
|
|
|
TheCIA1->RevMatrix);
|
|
|
|
|
|
|
|
this->have_a_break = false;
|
|
|
|
if (this->quit_thyself)
|
2009-04-19 14:57:29 +02:00
|
|
|
ThePrefs.Save((const char*)PREFS_PATH);
|
2009-01-13 19:46:42 +01:00
|
|
|
}
|
2009-01-29 21:26:40 +01:00
|
|
|
this->network_vblank();
|
2009-02-01 20:47:21 +01:00
|
|
|
|
2009-01-13 19:46:42 +01:00
|
|
|
#if defined(GEKKO)
|
2009-04-26 08:02:57 +02:00
|
|
|
if (this->quit_thyself && Network::networking_started == true)
|
2009-03-28 10:34:31 +01:00
|
|
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
2009-01-24 21:57:23 +01:00
|
|
|
now = ticks_to_millisecs(gettime());
|
2009-01-13 19:46:42 +01:00
|
|
|
#else
|
2009-01-24 21:57:23 +01:00
|
|
|
now = SDL_GetTicks();
|
2009-01-13 19:46:42 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( (now - lastFrame) < ThePrefs.MsPerFrame) {
|
|
|
|
usleep( (ThePrefs.MsPerFrame - (now - lastFrame)) * 1000);
|
|
|
|
}
|
|
|
|
lastFrame = now;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The emulation's main loop
|
|
|
|
*/
|
|
|
|
|
|
|
|
void C64::thread_func(void)
|
|
|
|
{
|
|
|
|
int linecnt = 0;
|
|
|
|
|
|
|
|
#ifdef FRODO_SC
|
|
|
|
while (!quit_thyself) {
|
|
|
|
|
|
|
|
// The order of calls is important here
|
|
|
|
if (TheVIC->EmulateCycle())
|
|
|
|
TheSID->EmulateLine();
|
|
|
|
TheCIA1->CheckIRQs();
|
|
|
|
TheCIA2->CheckIRQs();
|
|
|
|
TheCIA1->EmulateCycle();
|
|
|
|
TheCIA2->EmulateCycle();
|
|
|
|
TheCPU->EmulateCycle();
|
|
|
|
|
|
|
|
if (ThePrefs.Emul1541Proc) {
|
|
|
|
TheCPU1541->CountVIATimers(1);
|
|
|
|
if (!TheCPU1541->Idle)
|
|
|
|
TheCPU1541->EmulateCycle();
|
|
|
|
}
|
|
|
|
CycleCounter++;
|
|
|
|
#else
|
|
|
|
while (!quit_thyself) {
|
|
|
|
|
|
|
|
// The order of calls is important here
|
|
|
|
int cycles = TheVIC->EmulateLine();
|
|
|
|
TheSID->EmulateLine();
|
|
|
|
#if !PRECISE_CIA_CYCLES
|
|
|
|
TheCIA1->EmulateLine(ThePrefs.CIACycles);
|
|
|
|
TheCIA2->EmulateLine(ThePrefs.CIACycles);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ThePrefs.Emul1541Proc) {
|
|
|
|
int cycles_1541 = ThePrefs.FloppyCycles;
|
|
|
|
TheCPU1541->CountVIATimers(cycles_1541);
|
|
|
|
|
|
|
|
if (!TheCPU1541->Idle) {
|
|
|
|
// 1541 processor active, alternately execute
|
|
|
|
// 6502 and 6510 instructions until both have
|
|
|
|
// used up their cycles
|
|
|
|
while (cycles >= 0 || cycles_1541 >= 0)
|
|
|
|
if (cycles > cycles_1541)
|
|
|
|
cycles -= TheCPU->EmulateLine(1);
|
|
|
|
else
|
|
|
|
cycles_1541 -= TheCPU1541->EmulateLine(1);
|
|
|
|
} else
|
|
|
|
TheCPU->EmulateLine(cycles);
|
|
|
|
} else
|
|
|
|
// 1541 processor disabled, only emulate 6510
|
|
|
|
TheCPU->EmulateLine(cycles);
|
|
|
|
#endif
|
|
|
|
linecnt++;
|
|
|
|
}
|
|
|
|
}
|