3 Copyright (C) 1989-1995 Alan R. Baldwin
4 721 Berkeley St., Kent, Ohio 44240
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
31 #define CARTSIZE ((unsigned long)4*16UL*1024UL)
33 #define SEGSIZE (CARTSIZE/NBSEG)
35 unsigned char *cart[NBSEG];
37 #define ROMSIZE 0x10000UL
38 #define BANKSIZE 0x4000UL
49 for(i = 0; i < NBSEG; i++) {
50 if((cart[i] = malloc(SEGSIZE)) == NULL) {
51 fprintf(stderr, "ERROR: can't allocate %dth segment of memory (%d bytes)\n", i, (int)SEGSIZE);
54 memset(cart[i], 0, SEGSIZE);
61 pos = rtval[0] | (rtval[1]<<8);
63 pos = rtval[1] | (rtval[0]<<8);
65 /* Perform some validity checks */
67 fprintf(stderr, "ERROR: address overflow (addr %lx >= %lx)\n", pos, ROMSIZE);
70 if(current_rom_bank > 1)
71 pos += (current_rom_bank-1)*BANKSIZE;
72 for(i = 2; i < rtcnt; i++) {
75 if(cart[pos/SEGSIZE][pos%SEGSIZE] != 0)
76 fprintf(stderr, "WARNING: wrote twice at addr %lx (%02X->%02X)\n", pos, rtval[i], cart[pos/SEGSIZE][pos%SEGSIZE]);
77 cart[pos/SEGSIZE][pos%SEGSIZE] = rtval[i];
79 fprintf(stderr, "ERROR: cartridge size overflow (addr %lx >= %lx)\n", pos, CARTSIZE);
88 /* Patch before calculating the checksum */
89 for(i = 0; i < NBSEG; i++)
90 fwrite(cart[i], 1, SEGSIZE, ofp);