5
* Andreas Boose <viceteam@t-online.de>
6
* Andr� Fachat <fachat@physik.tu-chemnitz.de>
8
* This file is part of VICE, the Versatile Commodore Emulator.
9
* See README for copyright notice.
11
* This program is free software; you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation; either version 2 of the License, or
14
* (at your option) any later version.
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
21
* You should have received a copy of the GNU General Public License
22
* along with this program; if not, write to the Free Software
23
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
33
#include "autostart.h"
40
#include "resources.h"
47
static log_t cbm2rom_log = LOG_ERR;
49
/* Flag: nonzero if the ROM has been loaded. */
50
static int rom_loaded = 0;
52
static tape_init_t tapeinit = {
72
int cbm2rom_load_chargen(const char *rom_name)
77
return 0; /* init not far enough */
80
* we load 4k of 16-byte-per-char Charrom.
81
* Then we generate the inverted chars */
83
if (!util_check_null_string(rom_name)) {
84
memset(mem_chargen_rom, 0, CBM2_CHARGEN_ROM_SIZE);
86
if (sysfile_load(rom_name, mem_chargen_rom, 4096, 4096) < 0) {
87
log_error(cbm2rom_log, "Couldn't load character ROM '%s'.",
93
memmove(mem_chargen_rom + 4096, mem_chargen_rom + 2048, 2048);
95
/* Inverted chargen into second half. This is a hardware feature.*/
96
for (i = 0; i < 2048; i++) {
97
mem_chargen_rom[i + 2048] = mem_chargen_rom[i] ^ 0xff;
98
mem_chargen_rom[i + 6144] = mem_chargen_rom[i + 4096] ^ 0xff;
106
crtc_set_chargen_addr(mem_chargen_rom, CBM2_CHARGEN_ROM_SIZE >> 4);
112
int cbm2rom_checksum(void)
117
/* Checksum over top 8 kByte kernal. */
118
for (i = 0xe000, sum = 0; i < 0x10000; i++)
121
log_message(cbm2rom_log, "Kernal checksum is %d ($%04X).",
126
int cbm2rom_load_kernal(const char *rom_name)
129
return 0; /* init not far enough */
131
/* De-initialize kbd-buf, autostart and tape stuff here before
132
reloading the ROM the traps are installed in. */
133
kbd_buf_init(0, 0, 0, 0);
134
autostart_init(0, 0, 0, 0, 0, 0);
135
tape_init(&tapeinit);
137
/* Load Kernal ROM. */
138
if (!util_check_null_string(rom_name)) {
139
if (sysfile_load(rom_name, mem_rom + 0xe000, 0x2000, 0x2000) < 0) {
140
log_error(cbm2rom_log, "Couldn't load ROM `%s'.", rom_name);
145
return cbm2rom_checksum();
148
int cbm2rom_load_basic(const char *rom_name)
151
return 0; /* init not far enough */
153
/* Load BASIC ROM. */
154
if (!util_check_null_string(rom_name)) {
155
if ((sysfile_load(rom_name, mem_rom + 0x8000, 0x4000, 0x4000) < 0)) {
156
log_error(cbm2rom_log, "Couldn't load BASIC ROM `%s'.",
161
log_warning(cbm2rom_log, "Disabling BASIC by unloading ROM!");
162
memset(mem_rom + 0x8000, 0xff, 0x4000);
167
int cbm2rom_load_cart_1(const char *rom_name)
170
return 0; /* init not far enough */
172
if (!util_check_null_string(rom_name)) {
173
if ((sysfile_load(rom_name, mem_rom + 0x1000, 0x1000, 0x1000) < 0)) {
174
log_error(cbm2rom_log, "Couldn't load ROM `%s'.",
178
memset(mem_rom + 0x1000, 0xff, 0x1000);
183
int cbm2rom_load_cart_2(const char *rom_name)
186
return 0; /* init not far enough */
188
if (!util_check_null_string(rom_name)) {
189
if ((sysfile_load(rom_name, mem_rom + 0x2000, 0x2000, 0x2000) < 0)) {
190
log_error(cbm2rom_log, "Couldn't load ROM `%s'.",
194
memset(mem_rom + 0x2000, 0xff, 0x2000);
199
int cbm2rom_load_cart_4(const char *rom_name)
202
return 0; /* init not far enough */
204
if (!util_check_null_string(rom_name)) {
205
if ((sysfile_load(rom_name, mem_rom + 0x4000, 0x2000, 0x2000) < 0)) {
206
log_error(cbm2rom_log, "Couldn't load ROM `%s'.",
210
memset(mem_rom + 0x4000, 0xff, 0x2000);
215
int cbm2rom_load_cart_6(const char *rom_name)
218
return 0; /* init not far enough */
220
if (!util_check_null_string(rom_name)) {
221
if ((sysfile_load(rom_name, mem_rom + 0x6000, 0x2000, 0x2000) < 0)) {
222
log_error(cbm2rom_log, "Couldn't load ROM `%s'.",
226
memset(mem_rom + 0x6000, 0xff, 0x2000);
231
/* Load memory image files. */
235
char *rom_name = NULL;
237
if (cbm2rom_log == LOG_ERR)
238
cbm2rom_log = log_open("CBM2MEM");
242
if (resources_get_value("ChargenName", (void *)&rom_name) < 0)
244
if (cbm2rom_load_chargen(rom_name) < 0)
247
/* Init Disk/Cartridge ROM with 'unused address' values. */
248
for (i = 0x800; i < 0x8000; i++) {
252
if (resources_get_value("KernalName", (void *)&rom_name) < 0)
254
if (cbm2rom_load_kernal(rom_name) < 0)
257
if (resources_get_value("BasicName", (void *)&rom_name) < 0)
259
if (cbm2rom_load_basic(rom_name) < 0)
262
/* Load extension ROMs. */
263
if (resources_get_value("Cart1Name", (void *)&rom_name) < 0)
265
if (cbm2rom_load_cart_1(rom_name) < 0)
268
if (resources_get_value("Cart2Name", (void *)&rom_name) < 0)
270
if (cbm2rom_load_cart_2(rom_name) < 0)
273
if (resources_get_value("Cart4Name", (void *)&rom_name) < 0)
275
if (cbm2rom_load_cart_4(rom_name) < 0)
278
if (resources_get_value("Cart6Name", (void *)&rom_name) < 0)
280
if (cbm2rom_load_cart_6(rom_name) < 0)
286
crtc_set_screen_addr(mem_rom + 0xd000);