~ubuntu-branches/ubuntu/dapper/vice/dapper

« back to all changes in this revision

Viewing changes to src/cbm2/cbm2rom.c

  • Committer: Bazaar Package Importer
  • Author(s): Zed Pobre
  • Date: 2004-08-26 13:35:51 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040826133551-gcje8j31q5cqgdq2
Tags: 1.14-3
Apply patch from Spiro Trikaliotis <vice@trikaliotis.net> to fix a
problem that some users were experiencing with a floating point
exception on startup related to the fullscreen option being enabled
during compile.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * cbm2rom.c 
 
3
 *
 
4
 * Written by
 
5
 *  Andreas Boose <viceteam@t-online.de>
 
6
 *  Andr� Fachat <fachat@physik.tu-chemnitz.de>
 
7
 *
 
8
 * This file is part of VICE, the Versatile Commodore Emulator.
 
9
 * See README for copyright notice.
 
10
 *
 
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.
 
15
 *
 
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.
 
20
 *
 
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
 
24
 *  02111-1307  USA.
 
25
 *
 
26
 */
 
27
 
 
28
#include "vice.h"
 
29
 
 
30
#include <stdio.h>
 
31
#include <string.h>
 
32
 
 
33
#include "autostart.h"
 
34
#include "cbm2.h"
 
35
#include "cbm2mem.h"
 
36
#include "cbm2rom.h"
 
37
#include "crtc.h"
 
38
#include "kbdbuf.h"
 
39
#include "log.h"
 
40
#include "resources.h"
 
41
#include "sysfile.h"
 
42
#include "tape.h"
 
43
#include "types.h"
 
44
#include "util.h"
 
45
 
 
46
 
 
47
static log_t cbm2rom_log = LOG_ERR;
 
48
 
 
49
/* Flag: nonzero if the ROM has been loaded. */
 
50
static int rom_loaded = 0;
 
51
 
 
52
static tape_init_t tapeinit = {
 
53
    0,
 
54
    0,
 
55
    0,
 
56
    0,
 
57
    0,
 
58
    0,
 
59
    0,
 
60
    0,
 
61
    0,
 
62
    NULL,
 
63
    36 * 8,
 
64
    54 * 8,
 
65
    55 * 8,
 
66
    73 * 8,
 
67
    74 * 8,
 
68
    100 * 8
 
69
};
 
70
 
 
71
 
 
72
int cbm2rom_load_chargen(const char *rom_name)
 
73
{
 
74
    int i;
 
75
 
 
76
    if (!rom_loaded)
 
77
        return 0;  /* init not far enough */
 
78
 
 
79
    /* Load chargen ROM
 
80
     * we load 4k of 16-byte-per-char Charrom.
 
81
     * Then we generate the inverted chars */
 
82
 
 
83
    if (!util_check_null_string(rom_name)) {
 
84
        memset(mem_chargen_rom, 0, CBM2_CHARGEN_ROM_SIZE);
 
85
 
 
86
        if (sysfile_load(rom_name, mem_chargen_rom, 4096, 4096) < 0) {
 
87
            log_error(cbm2rom_log, "Couldn't load character ROM '%s'.",
 
88
                      rom_name);
 
89
            return -1;
 
90
        }
 
91
 
 
92
        if (!cbm2_isC500) {
 
93
            memmove(mem_chargen_rom + 4096, mem_chargen_rom + 2048, 2048);
 
94
 
 
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;
 
99
            }
 
100
        }
 
101
    }
 
102
 
 
103
    if (cbm2_isC500) {
 
104
        /* VIC-II config */
 
105
    } else {
 
106
        crtc_set_chargen_addr(mem_chargen_rom, CBM2_CHARGEN_ROM_SIZE >> 4);
 
107
    }
 
108
 
 
109
    return 0;
 
110
}
 
111
 
 
112
int cbm2rom_checksum(void)
 
113
{
 
114
    int i;
 
115
    WORD sum;
 
116
 
 
117
    /* Checksum over top 8 kByte kernal.  */
 
118
    for (i = 0xe000, sum = 0; i < 0x10000; i++)
 
119
        sum += mem_rom[i];
 
120
 
 
121
    log_message(cbm2rom_log, "Kernal checksum is %d ($%04X).",
 
122
                sum, sum);
 
123
    return 0;
 
124
}
 
125
 
 
126
int cbm2rom_load_kernal(const char *rom_name)
 
127
{
 
128
    if (!rom_loaded)
 
129
        return 0;  /* init not far enough */
 
130
 
 
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);
 
136
 
 
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);
 
141
            return -1;
 
142
        }
 
143
    }
 
144
 
 
145
    return cbm2rom_checksum();
 
146
}
 
147
 
 
148
int cbm2rom_load_basic(const char *rom_name)
 
149
{
 
150
    if (!rom_loaded)
 
151
        return 0;  /* init not far enough */
 
152
 
 
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'.",
 
157
                      rom_name);
 
158
            return -1;
 
159
        }
 
160
    } else {
 
161
        log_warning(cbm2rom_log, "Disabling BASIC by unloading ROM!");
 
162
        memset(mem_rom + 0x8000, 0xff, 0x4000);
 
163
    }
 
164
    return 0;
 
165
}
 
166
 
 
167
int cbm2rom_load_cart_1(const char *rom_name)
 
168
{
 
169
    if (!rom_loaded)
 
170
        return 0;  /* init not far enough */
 
171
 
 
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'.",
 
175
                      rom_name);
 
176
        }
 
177
    } else {
 
178
        memset(mem_rom + 0x1000, 0xff, 0x1000);
 
179
    }
 
180
    return 0;
 
181
}
 
182
 
 
183
int cbm2rom_load_cart_2(const char *rom_name)
 
184
{
 
185
    if (!rom_loaded)
 
186
        return 0;  /* init not far enough */
 
187
 
 
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'.",
 
191
                      rom_name);
 
192
        }
 
193
    } else {
 
194
        memset(mem_rom + 0x2000, 0xff, 0x2000);
 
195
    }
 
196
    return 0;
 
197
}
 
198
 
 
199
int cbm2rom_load_cart_4(const char *rom_name)
 
200
{
 
201
    if (!rom_loaded)
 
202
        return 0;  /* init not far enough */
 
203
 
 
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'.",
 
207
                      rom_name);
 
208
        }
 
209
    } else {
 
210
        memset(mem_rom + 0x4000, 0xff, 0x2000);
 
211
    }
 
212
    return 0;
 
213
}
 
214
 
 
215
int cbm2rom_load_cart_6(const char *rom_name)
 
216
{
 
217
    if (!rom_loaded)
 
218
        return 0;  /* init not far enough */
 
219
 
 
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'.",
 
223
                      rom_name);
 
224
        }
 
225
    } else {
 
226
        memset(mem_rom + 0x6000, 0xff, 0x2000);
 
227
    }
 
228
    return 0;
 
229
}
 
230
 
 
231
/* Load memory image files. */
 
232
int mem_load(void)
 
233
{
 
234
    int i;
 
235
    char *rom_name = NULL;
 
236
 
 
237
    if (cbm2rom_log == LOG_ERR)
 
238
        cbm2rom_log = log_open("CBM2MEM");
 
239
 
 
240
    rom_loaded = 1;
 
241
 
 
242
    if (resources_get_value("ChargenName", (void *)&rom_name) < 0)
 
243
        return -1;
 
244
    if (cbm2rom_load_chargen(rom_name) < 0)
 
245
        return -1;
 
246
 
 
247
    /* Init Disk/Cartridge ROM with 'unused address' values.  */
 
248
    for (i = 0x800; i < 0x8000; i++) {
 
249
        mem_rom[i] = 0xff;
 
250
    }
 
251
 
 
252
    if (resources_get_value("KernalName", (void *)&rom_name) < 0)
 
253
        return -1;
 
254
    if (cbm2rom_load_kernal(rom_name) < 0)
 
255
        return -1;
 
256
 
 
257
    if (resources_get_value("BasicName", (void *)&rom_name) < 0)
 
258
        return -1;
 
259
    if (cbm2rom_load_basic(rom_name) < 0)
 
260
        return -1;
 
261
 
 
262
    /* Load extension ROMs.  */
 
263
    if (resources_get_value("Cart1Name", (void *)&rom_name) < 0)
 
264
        return -1;
 
265
    if (cbm2rom_load_cart_1(rom_name) < 0)
 
266
        return -1;
 
267
 
 
268
    if (resources_get_value("Cart2Name", (void *)&rom_name) < 0)
 
269
        return -1;
 
270
    if (cbm2rom_load_cart_2(rom_name) < 0)
 
271
        return -1;
 
272
 
 
273
    if (resources_get_value("Cart4Name", (void *)&rom_name) < 0)
 
274
        return -1;
 
275
    if (cbm2rom_load_cart_4(rom_name) < 0)
 
276
        return -1;
 
277
 
 
278
    if (resources_get_value("Cart6Name", (void *)&rom_name) < 0)
 
279
        return -1;
 
280
    if (cbm2rom_load_cart_6(rom_name) < 0)
 
281
        return -1;
 
282
 
 
283
    if (cbm2_isC500) {
 
284
        /* VIC-II config */
 
285
    } else {
 
286
        crtc_set_screen_addr(mem_rom + 0xd000);
 
287
    }
 
288
 
 
289
    return 0;
 
290
}
 
291