16 #define CARTSIZE ((unsigned long)4*16UL*1024UL)
18 #define SEGSIZE (CARTSIZE/NBSEG)
20 unsigned char *cart[NBSEG];
22 #define ROMSIZE 0x10000UL
23 #define BANKSIZE 0x4000UL
34 for(i = 0; i < NBSEG; i++) {
35 if((cart[i] = malloc(SEGSIZE)) == NULL) {
36 fprintf(stderr, "ERROR: can't allocate %dth segment of memory (%d bytes)\n", i, (int)SEGSIZE);
39 memset(cart[i], 0, SEGSIZE);
46 pos = rtval[0] | (rtval[1]<<8);
48 pos = rtval[1] | (rtval[0]<<8);
50 /* Perform some validity checks */
52 fprintf(stderr, "ERROR: address overflow (addr %lx >= %lx)\n", pos, ROMSIZE);
55 if(current_rom_bank > 1)
56 pos += (current_rom_bank-1)*BANKSIZE;
57 for(i = 2; i < rtcnt; i++) {
60 if(cart[pos/SEGSIZE][pos%SEGSIZE] != 0)
61 fprintf(stderr, "WARNING: wrote twice at addr %lx (%02X->%02X)\n", pos, rtval[i], cart[pos/SEGSIZE][pos%SEGSIZE]);
62 cart[pos/SEGSIZE][pos%SEGSIZE] = rtval[i];
64 fprintf(stderr, "ERROR: cartridge size overflow (addr %lx >= %lx)\n", pos, CARTSIZE);
73 /* Patch before calculating the checksum */
74 for(i = 0; i < NBSEG; i++)
75 fwrite(cart[i], 1, SEGSIZE, ofp);