15 #define CARTSIZE ((unsigned long)4*16UL*1024UL)
17 #define SEGSIZE (CARTSIZE/NBSEG)
19 unsigned char *cart[NBSEG];
21 #define ROMSIZE 0x10000UL
22 #define BANKSIZE 0x4000UL
33 for(i = 0; i < NBSEG; i++) {
34 if((cart[i] = malloc(SEGSIZE)) == NULL) {
35 fprintf(stderr, "ERROR: can't allocate %dth segment of memory (%d bytes)\n", i, (int)SEGSIZE);
38 memset(cart[i], 0, SEGSIZE);
45 pos = rtval[0] | (rtval[1]<<8);
47 pos = rtval[1] | (rtval[0]<<8);
49 /* Perform some validity checks */
51 fprintf(stderr, "ERROR: address overflow (addr %lx >= %lx)\n", pos, ROMSIZE);
54 if(current_rom_bank > 1)
55 pos += (current_rom_bank-1)*BANKSIZE;
56 for(i = 2; i < rtcnt; i++) {
59 if(cart[pos/SEGSIZE][pos%SEGSIZE] != 0)
60 fprintf(stderr, "WARNING: wrote twice at addr %lx (%02X->%02X)\n", pos, rtval[i], cart[pos/SEGSIZE][pos%SEGSIZE]);
61 cart[pos/SEGSIZE][pos%SEGSIZE] = rtval[i];
63 fprintf(stderr, "ERROR: cartridge size overflow (addr %lx >= %lx)\n", pos, CARTSIZE);
72 /* Patch before calculating the checksum */
73 for(i = 0; i < NBSEG; i++)
74 fwrite(cart[i], 1, SEGSIZE, ofp);