-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathFrodo.mm
executable file
·136 lines (109 loc) · 2.99 KB
/
Frodo.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
Frodo, Commodore 64 emulator for the iPhone
Copyright (C) 1994-1997,2002 Christian Bauer
See gpl.txt for license information.
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 3 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, see <http://www.gnu.org/licenses/>.
*/
/*
* Frodo.cpp
* iFrodo
*
* Created by Stuart Carnie on 5/5/08.
* Copyright 2008 __MyCompanyName__. All rights reserved.
*
*/
#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#include "Frodo.h"
#include "sysdeps.h"
#include "C64.h"
#include "Display.h"
#include "Prefs.h"
#include "Version.h"
#import "cf_typeref.h"
extern int init_graphics(void);
NSString* Frodo::s_path = nil;
Frodo *Frodo::Instance;
bool Frodo::AutoBoot = false;
static uint8 BROM[] = {
#include "BASIC_ROM.i"
};
uint32 BROM_size = sizeof(BROM) / sizeof(BROM[0]);
Frodo::Frodo()
{
TheC64 = NULL;
Instance = this;
}
bool Frodo::load_rom_files(void)
{
NSBundle *mainBundle = [NSBundle mainBundle];
try {
NSString *path;
NSData *data;
// BASIC ROM
memcpy(TheC64->Basic, BROM, BROM_size);
// Load Kernal ROM
path = [mainBundle pathForResource:@"Kernal.ROM" ofType:nil];
data = [NSData dataWithContentsOfFile:path];
if ([data length] != 0x2000){
[data release];
throw "Unable to load 'Kernal ROM'";
}
[data getBytes:TheC64->Kernal];
[data release];
// Load Char ROM
path = [mainBundle pathForResource:@"Char.ROM" ofType:nil];
data = [NSData dataWithContentsOfFile:path];
if ([data length] != 0x1000){
[data release];
throw "Unable to load 'Char ROM'";
}
[data getBytes:TheC64->Char];
[data release];
// Load 1541 ROM
path = [mainBundle pathForResource:@"1541.ROM" ofType:nil];
data = [NSData dataWithContentsOfFile:path];
if ([data length] != 0x4000){
[data release];
throw "Unable to load '1541 ROM'";
}
[data getBytes:TheC64->ROM1541];
[data release];
}
catch (const char * str) {
ShowRequester((char*)str, "Quit");
return false;
}
return true;
}
const char* Frodo::prefs_path() {
if (s_path == nil)
s_path = [[DOCUMENTS_FOLDER stringByAppendingPathComponent:@"frodo.prefs"] retain];
return [s_path cStringUsingEncoding:[NSString defaultCStringEncoding]];
}
void Frodo::ReadyToRun(void)
{
ThePrefs.Load(prefs_path());
// Create and start C64
TheC64 = new C64;
if (load_rom_files()) {
eventInitialized(this);
TheC64->Run(AutoBoot);
}
delete TheC64;
}
Prefs *Frodo::reload_prefs(void)
{
static Prefs newprefs;
newprefs.Load(prefs_path());
return &newprefs;
}