1 |
|
/* |
2 |
|
* main.cpp - Main program |
3 |
|
* |
4 |
< |
* Frodo (C) 1994-1997,2002 Christian Bauer |
4 |
> |
* Frodo (C) 1994-1997,2002-2003 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
32 |
|
|
33 |
|
|
34 |
|
// ROM file names |
35 |
+ |
#ifndef DATADIR |
36 |
+ |
#define DATADIR |
37 |
+ |
#endif |
38 |
+ |
|
39 |
|
#ifdef __riscos__ |
40 |
|
#define BASIC_ROM_FILE "FrodoRsrc:Basic_ROM" |
41 |
|
#define KERNAL_ROM_FILE "FrodoRsrc:Kernal_ROM" |
42 |
|
#define CHAR_ROM_FILE "FrodoRsrc:Char_ROM" |
43 |
< |
#define FLOPPY_ROM_FILE "FrodoRsrc:1541_ROM" |
43 |
> |
#define DRIVE_ROM_FILE "FrodoRsrc:1541_ROM" |
44 |
|
#else |
45 |
< |
#define BASIC_ROM_FILE "Basic ROM" |
46 |
< |
#define KERNAL_ROM_FILE "Kernal ROM" |
47 |
< |
#define CHAR_ROM_FILE "Char ROM" |
48 |
< |
#define FLOPPY_ROM_FILE "1541 ROM" |
45 |
> |
#define BASIC_ROM_FILE DATADIR "Basic ROM" |
46 |
> |
#define KERNAL_ROM_FILE DATADIR "Kernal ROM" |
47 |
> |
#define CHAR_ROM_FILE DATADIR "Char ROM" |
48 |
> |
#define DRIVE_ROM_FILE DATADIR "1541 ROM" |
49 |
|
#endif |
50 |
|
|
51 |
|
|
52 |
+ |
// Builtin ROMs |
53 |
+ |
#include "Basic_ROM.h" |
54 |
+ |
#include "Kernal_ROM.h" |
55 |
+ |
#include "Char_ROM.h" |
56 |
+ |
#include "1541_ROM.h" |
57 |
+ |
|
58 |
+ |
|
59 |
|
/* |
60 |
|
* Load C64 ROM files |
61 |
|
*/ |
62 |
|
|
63 |
< |
bool Frodo::load_rom_files(void) |
63 |
> |
void Frodo::load_rom(const char *which, const char *path, uint8 *where, size_t size, const uint8 *builtin) |
64 |
|
{ |
65 |
< |
FILE *file; |
66 |
< |
|
67 |
< |
// Load Basic ROM |
68 |
< |
if ((file = fopen(BASIC_ROM_FILE, "rb")) != NULL) { |
69 |
< |
if (fread(TheC64->Basic, 1, 0x2000, file) != 0x2000) { |
70 |
< |
ShowRequester("Can't read 'Basic ROM'.", "Quit"); |
60 |
< |
return false; |
61 |
< |
} |
62 |
< |
fclose(file); |
63 |
< |
} else { |
64 |
< |
ShowRequester("Can't find 'Basic ROM'.", "Quit"); |
65 |
< |
return false; |
66 |
< |
} |
67 |
< |
|
68 |
< |
// Load Kernal ROM |
69 |
< |
if ((file = fopen(KERNAL_ROM_FILE, "rb")) != NULL) { |
70 |
< |
if (fread(TheC64->Kernal, 1, 0x2000, file) != 0x2000) { |
71 |
< |
ShowRequester("Can't read 'Kernal ROM'.", "Quit"); |
72 |
< |
return false; |
73 |
< |
} |
74 |
< |
fclose(file); |
75 |
< |
} else { |
76 |
< |
ShowRequester("Can't find 'Kernal ROM'.", "Quit"); |
77 |
< |
return false; |
78 |
< |
} |
79 |
< |
|
80 |
< |
// Load Char ROM |
81 |
< |
if ((file = fopen(CHAR_ROM_FILE, "rb")) != NULL) { |
82 |
< |
if (fread(TheC64->Char, 1, 0x1000, file) != 0x1000) { |
83 |
< |
ShowRequester("Can't read 'Char ROM'.", "Quit"); |
84 |
< |
return false; |
85 |
< |
} |
86 |
< |
fclose(file); |
87 |
< |
} else { |
88 |
< |
ShowRequester("Can't find 'Char ROM'.", "Quit"); |
89 |
< |
return false; |
65 |
> |
FILE *f = fopen(path, "rb"); |
66 |
> |
if (f) { |
67 |
> |
size_t actual = fread(where, 1, size, f); |
68 |
> |
fclose(f); |
69 |
> |
if (actual == size) |
70 |
> |
return; |
71 |
|
} |
72 |
|
|
73 |
< |
// Load 1541 ROM |
74 |
< |
if ((file = fopen(FLOPPY_ROM_FILE, "rb")) != NULL) { |
75 |
< |
if (fread(TheC64->ROM1541, 1, 0x4000, file) != 0x4000) { |
76 |
< |
ShowRequester("Can't read '1541 ROM'.", "Quit"); |
96 |
< |
return false; |
97 |
< |
} |
98 |
< |
fclose(file); |
99 |
< |
} else { |
100 |
< |
ShowRequester("Can't find '1541 ROM'.", "Quit"); |
101 |
< |
return false; |
102 |
< |
} |
73 |
> |
// Use builtin ROM |
74 |
> |
printf("%s ROM file (%s) not readable, using builtin.\n", which, path); |
75 |
> |
memcpy(where, builtin, size); |
76 |
> |
} |
77 |
|
|
78 |
< |
return true; |
78 |
> |
void Frodo::load_rom_files() |
79 |
> |
{ |
80 |
> |
load_rom("Basic", BASIC_ROM_FILE, TheC64->Basic, BASIC_ROM_SIZE, builtin_basic_rom); |
81 |
> |
load_rom("Kernal", KERNAL_ROM_FILE, TheC64->Kernal, KERNAL_ROM_SIZE, builtin_kernal_rom); |
82 |
> |
load_rom("Char", CHAR_ROM_FILE, TheC64->Char, CHAR_ROM_SIZE, builtin_char_rom); |
83 |
> |
load_rom("1541", DRIVE_ROM_FILE, TheC64->ROM1541, DRIVE_ROM_SIZE, builtin_drive_rom); |
84 |
|
} |
85 |
|
|
86 |
|
|