Previous 15994 Revisions Next

r5235 Tuesday 14th July, 2009 at 15:57:25 UTC by Fabio Priuli
A "just in case I got hit by a bus" commit (carts go currently nowhere, but it's good to have backup).
[src/mess/machine]c64.c

src/mess/machine/c64.c
r5234r5235
4343      } \
4444   } while (0)
4545
46#define log_cart 0
4647
4748/* expansion port lines input */
4849int c64_pal = 0;
r5234r5235
6768static int c64_cia1_on = 1;
6869static int c64_io_enabled = 0;
6970static int is_sx64 = 0;   // temporary workaround until we implement full vc1541 emulation for every c64 set
71static UINT8 c64_cart_loaded = 0;
7072
7173static UINT8 serial_clock, serial_data, serial_atn;
7274static UINT8 vicirq = 0;
r5234r5235
883885      c64_bankswitch(machine, 1);
884886}
885887
886MACHINE_RESET( c64 )
887{
888}
889
890888INTERRUPT_GEN( c64_frame_interrupt )
891889{
892890   c64_nmi(device->machine);
r5234r5235
977975
978976*/
979977
980static CBM_ROM c64_cbm_cart[0x20] = { {0} };
978
979#define C64_MAX_ROMBANK 64 //?
980
981static CBM_ROM c64_cbm_cart[C64_MAX_ROMBANK] = { {0} };
981982static INT8 cbm_c64_game;
982983static INT8 cbm_c64_exrom;
983984
984985static DEVICE_IMAGE_UNLOAD(c64_cart)
985986{
986   int index = 0;
987   if (strcmp(image->tag,"cart1")==0) {
988      index = 0;
987   int i;
988
989   for (i = 0; i < C64_MAX_ROMBANK; i++)
990   {
991      c64_cbm_cart[i].size = 0;
992      c64_cbm_cart[i].addr = 0;
993      c64_cbm_cart[i].chip = 0;
989994   }
990   if (strcmp(image->tag,"cart2")==0) {
991      index = 1;
992   }
993   c64_cbm_cart[index].size = 0;
994   c64_cbm_cart[index].chip = 0;
995995}
996996
997
997998static DEVICE_START(c64_cart)
998999{
9991000   int index = 0;
1000   if (strcmp(device->tag,"cart1")==0) {
1001
1002   if (strcmp(device->tag, "cart1") == 0)
10011003      index = 0;
1002   }
1003   if (strcmp(device->tag,"cart2")==0) {
1004
1005   if (strcmp(device->tag, "cart2") == 0)
10041006      index = 1;
1005   }
1007
1008
1009   /* In the first slot we can load a .crt file. In this case we want
1010      to use game & exrom values from the header, not the default ones. */
10061011   if (index == 0)
10071012   {
10081013      cbm_c64_game = -1;
r5234r5235
10621067   *****************************************/
10631068};
10641069
1070static UINT8 c64_mapper = GENERIC_CRT;
1071
10651072static DEVICE_IMAGE_LOAD(c64_cart)
10661073{
1067   int size = image_length(image), test, i;
1074   int size = image_length(image), test, i = 0;
10681075   const char *filetype;
1069   int address = 0;
1076   int address = 0, lbank_end_addr = 0, hbank_end_addr = 0, new_start = 0;
1077   UINT8 *cart = memory_region(image->machine, "cart");
10701078
10711079   filetype = image_filetype(image);
10721080
r5234r5235
10741082   if (!mame_stricmp (filetype, "crt"))
10751083   {
10761084      int j;
1077      unsigned short cart_type;
1085      unsigned short c64_cart_type;
10781086
1079      for (i=0; (i<sizeof(c64_cbm_cart) / sizeof(c64_cbm_cart[0])) && (c64_cbm_cart[i].size!=0); i++)
1087      for (i = 0; (i < sizeof(c64_cbm_cart) / sizeof(c64_cbm_cart[0])) && (c64_cbm_cart[i].size != 0); i++)
10801088      ;
10811089
10821090      if (i >= sizeof(c64_cbm_cart) / sizeof(c64_cbm_cart[0]))
r5234r5235
10851093      /* Start to parse the .crt header */
10861094      /* 0x16-0x17 is Hardware type */
10871095      image_fseek(image, 0x16, SEEK_SET);
1088      image_fread(image, &cart_type, 2);
1089      cart_type = BIG_ENDIANIZE_INT16(cart_type);
1096      image_fread(image, &c64_cart_type, 2);
1097      c64_cart_type = BIG_ENDIANIZE_INT16(c64_cart_type);
1098      c64_mapper = c64_cart_type;
10901099
10911100      /* If it is unsupported cart type, warn the user */
1092      switch (cart_type)
1101      switch (c64_cart_type)
10931102      {
10941103         case GENERIC_CRT:
10951104            break;
10961105
10971106         default:
1098            logerror("Currently unsupported cart type (Type %d)\n", cart_type);
1107            logerror("Currently unsupported cart type (Type %d)\n", c64_cart_type);
10991108            break;
11001109      }
11011110
r5234r5235
11111120      j = 0x40;
11121121
11131122      logerror("Loading cart %s size:%.4x\n", image_filename(image), size);
1114      logerror("Header info: EXROM %d, GAME %d, Cart Type %d \n", cbm_c64_exrom, cbm_c64_game, cart_type);
1123      logerror("Header info: EXROM %d, GAME %d, Cart Type %d \n", cbm_c64_exrom, cbm_c64_game, c64_cart_type);
11151124
11161125
11171126      /* Data in a .crt image are organized in blocks called 'CHIP':
r5234r5235
11351144         image_fread(image, buffer + 6, 2);
11361145
11371146         /* 0x0a-0x0b is the bank number of the CHIP block */
1138         /* We currently don't use this, but it is needed to support more cart types. */
11391147         image_fread(image, &chip_bank_index, 2);
11401148         chip_bank_index = BIG_ENDIANIZE_INT16(chip_bank_index);
11411149
r5234r5235
11611169
11621170         /* Store data, address & size of the CHIP block */
11631171         c64_cbm_cart[i].addr = address;
1172         c64_cbm_cart[i].index = chip_bank_index;
11641173         c64_cbm_cart[i].size = chip_data_size;
1174         c64_cbm_cart[i].start = new_start;
1175
11651176         test = image_fread(image, c64_cbm_cart[i].chip, chip_data_size);
11661177
1178         memcpy(&cart[new_start], c64_cbm_cart[i].chip, c64_cbm_cart[i].size);
1179         new_start += c64_cbm_cart[i].size;
1180
11671181         if (test != chip_data_size)
11681182            return INIT_FAIL;
11691183
r5234r5235
11961210      /* Store data, address & size */
11971211      c64_cbm_cart[0].addr = address;
11981212      c64_cbm_cart[0].size = size;
1199      test = image_fread(image, c64_cbm_cart[0].chip, c64_cbm_cart[0].size);
1213      c64_cbm_cart[0].start = new_start;
12001214
1215      test = image_fread(image, c64_cbm_cart[0].chip, size);
1216
1217      memcpy(&cart[new_start], c64_cbm_cart[0].chip, c64_cbm_cart[0].size);
1218      new_start += c64_cbm_cart[0].size;
1219
12011220      if (test != c64_cbm_cart[0].size)
12021221         return INIT_FAIL;
12031222   }
r5234r5235
12091228      c64_game  = cbm_c64_game;
12101229   }
12111230
1231
12121232   /* Finally load the cart */
12131233   roml = c64_roml;
12141234   romh = c64_romh;
12151235
1216   memset(roml, 0, 0x2000);
1236   memset(roml, 0, 0x4000);
12171237   memset(romh, 0, 0x2000);
12181238
1219   for (i=0; (i < sizeof(c64_cbm_cart) / sizeof(c64_cbm_cart[0])) && (c64_cbm_cart[i].size != 0); i++)
1239   /* a bit hacky, until we have fixed the bankswitch part... it will be improved afterwards! */
1240   /* previously we only loaded cart here because we had at most two banks to be loaded sequentially and never switched */
1241   /* now we have bankswitch handlers for some cart types, but we keep loading first 1 or 2 banks here, for carts without bankswitch */
1242   /* to be sure we only load the first pieces, we check that cart.addr is larger than the previous and that no more than 2 CHIPs are loaded */
1243   for (i = 0; (i < sizeof(c64_cbm_cart) / sizeof(c64_cbm_cart[0])) && (c64_cbm_cart[i].size != 0); i++)
12201244   {
1221      if (c64_cbm_cart[i].addr < 0xc000)
1222         memcpy(roml + c64_cbm_cart[i].addr - 0x8000, c64_cbm_cart[i].chip, c64_cbm_cart[i].size);
1223
1224      else
1225         memcpy(romh + c64_cbm_cart[i].addr - 0xe000, c64_cbm_cart[i].chip, c64_cbm_cart[i].size);
1245      /* load the bank only if the space is free */
1246      if ((c64_cbm_cart[i].addr < 0xc000) && (c64_cbm_cart[i].addr >= lbank_end_addr + 0x8000) && (i < 2))
1247      {
1248         memcpy(roml + c64_cbm_cart[i].addr - 0x8000, cart + c64_cbm_cart[i].start, c64_cbm_cart[i].size);
1249         lbank_end_addr += c64_cbm_cart[i].addr - 0x8000 + c64_cbm_cart[i].size;
1250      }
1251      else if ((c64_cbm_cart[i].addr >= 0xe000) && (c64_cbm_cart[i].addr >= hbank_end_addr + 0xe000))
1252      {
1253         memcpy(romh + c64_cbm_cart[i].addr - 0xe000, cart + c64_cbm_cart[i].start, c64_cbm_cart[i].size);
1254         hbank_end_addr += c64_cbm_cart[i].addr - 0xe000 + c64_cbm_cart[i].size;
1255      }
12261256   }
12271257
1258   c64_cart_loaded = 1; // this is needed so that we only set mappers if a cart is present!
12281259   return INIT_PASS;
12291260}
12301261
12311262
1263static WRITE8_HANDLER( fc3_bank_w )
1264{
1265   UINT8 bank = data - 0x40;
1266   UINT8 *mem = memory_region(space->machine, "maincpu");
1267   UINT8 *cart = memory_region(space->machine, "cart");
1268
1269   if (bank > 3)
1270      logerror("Warning: This cart type should have at most 4 banks and the cart looked for bank %d... Something strange is going on!\n", bank);
1271
1272   memcpy(mem + c64_cbm_cart[bank].addr, cart + c64_cbm_cart[bank].start, c64_cbm_cart[bank].size);
1273
1274   if (log_cart)
1275   {
1276      logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1277      if (c64_cbm_cart[bank].index != bank)
1278         logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank);
1279   }
1280}
1281
1282static WRITE8_HANDLER( ocean1_bank_w )
1283{
1284   UINT8 bank = data & 0x3f;
1285   UINT8 *mem = memory_region(space->machine, "maincpu");
1286   UINT8 *cart = memory_region(space->machine, "cart");
1287
1288   memcpy(mem + c64_cbm_cart[bank].addr, cart + c64_cbm_cart[bank].start, c64_cbm_cart[bank].size);
1289
1290   if (log_cart)
1291   {
1292      logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1293      if (c64_cbm_cart[bank].index != bank)
1294         logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank);
1295   }
1296}
1297
1298static WRITE8_HANDLER( funplay_bank_w )
1299{
1300   UINT8 bank = data & 0x39, real_bank = 0;
1301   UINT8 *mem = memory_region(space->machine, "maincpu");
1302   UINT8 *cart = memory_region(space->machine, "cart");
1303
1304   /* This should be written after the bankswitch has happened. We log it to see if it is really working */
1305   if (data == 0x86 )
1306      logerror("Reserved value written\n");
1307   else
1308   {
1309      /* bank number is not the value written, but c64_cbm_cart[bank].index IS the value written! */
1310      real_bank = ((bank & 0x01) << 3) + ((bank & 0x38) >> 3);
1311
1312      memcpy(mem + c64_cbm_cart[bank].addr, cart + c64_cbm_cart[bank].start, c64_cbm_cart[bank].size);
1313
1314      if (log_cart)
1315      {
1316         logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1317         if (c64_cbm_cart[bank].index != bank)
1318            logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank);
1319      }
1320   }
1321}
1322
1323static WRITE8_HANDLER( c64gs_bank_w )
1324{
1325   UINT8 bank = offset & 0xff;
1326   UINT8 *mem = memory_region(space->machine, "maincpu");
1327   UINT8 *cart = memory_region(space->machine, "cart");
1328
1329   if (bank > 0x3f)
1330      logerror("Warning: This cart type should have at most 64 banks and the cart looked for bank %d... Something strange is going on!\n", bank);
1331
1332   memcpy(mem + c64_cbm_cart[bank].addr, cart + c64_cbm_cart[bank].start, c64_cbm_cart[bank].size);
1333
1334   if (log_cart)
1335   {
1336      logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1337      if (c64_cbm_cart[bank].index != bank)
1338         logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank);
1339   }
1340}
1341
1342static READ8_HANDLER( dinamic_bank_r )
1343{
1344   UINT8 bank = offset & 0xff;
1345   UINT8 *mem = memory_region(space->machine, "maincpu");
1346   UINT8 *cart = memory_region(space->machine, "cart");
1347
1348   if (bank > 0xf)
1349      logerror("Warning: This cart type should have 16 banks and the cart looked for bank %d... Something strange is going on!\n", bank);
1350
1351   memcpy(mem + c64_cbm_cart[bank].addr, cart + c64_cbm_cart[bank].start, c64_cbm_cart[bank].size);
1352
1353   if (log_cart)
1354   {
1355      logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1356      if (c64_cbm_cart[bank].index != bank)
1357         logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank);
1358   }
1359
1360   return 0;
1361}
1362
1363static WRITE8_HANDLER( comal80_bank_w )
1364{
1365   UINT8 bank = offset & 0x83;
1366   UINT8 *mem = memory_region(space->machine, "maincpu");
1367   UINT8 *cart = memory_region(space->machine, "cart");
1368
1369   /* only valid values 0x80, 0x81, 0x82, 0x83 */
1370   if (!(bank & 0x80))
1371      logerror("Warning: we are writing an invalid bank value %d\n", bank);
1372   else
1373   {
1374      bank &= 0x03;
1375      memcpy(mem + c64_cbm_cart[bank].addr, cart + c64_cbm_cart[bank].start, c64_cbm_cart[bank].size);
1376
1377      if (log_cart)
1378      {
1379         logerror("bank %d of size %d successfully loaded at %d!\n", bank, c64_cbm_cart[bank].size, c64_cbm_cart[bank].addr);
1380         if (c64_cbm_cart[bank].index != bank)
1381            logerror("Warning: According to the CHIP info this should be bank %d, but we are loading it as bank %d!\n", c64_cbm_cart[bank].index, bank);
1382      }
1383   
1384   }
1385}
1386
1387static void setup_c64_custom_mappers(running_machine *machine)
1388{
1389   const address_space *space = cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM );
1390
1391   switch( c64_mapper )
1392   {
1393      case FINAL_CART_III:    /* 4 16k banks, loaded at 0x8000, banks chosen by writing to 0xdfff */
1394         memory_install_write8_handler( space, 0xdfff, 0xdfff, 0, 0, fc3_bank_w );
1395         break;
1396      case OCEAN_1:           /* up to 64 8k banks, loaded at 0x8000 or 0xa000, banks chosen by writing to 0xde00 */
1397         memory_install_write8_handler( space, 0xde00, 0xde00, 0, 0, ocean1_bank_w );
1398         break;
1399      case FUN_PLAY:          /* 16 8k banks, loaded at 0x8000, banks chosen by writing to 0xde00 */
1400         memory_install_write8_handler( space, 0xde00, 0xde00, 0, 0, funplay_bank_w );
1401         break;
1402      case C64GS:             /* up to 64 8k banks, loaded at 0x8000, banks chosen by writing to 0xde00+bank# */
1403         memory_install_write8_handler( space, 0xde00, 0xdeff, 0, 0, c64gs_bank_w );
1404         break;
1405      case DINAMIC:           /* 16 8k banks, loaded at 0x8000, banks chosen by reading to 0xde00+bank# */
1406         memory_install_read8_handler( space, 0xde00, 0xdeff, 0, 0, dinamic_bank_r );
1407         break;
1408      case COMAL_80:          /* 4 16k banks, loaded at 0x8000, banks chosen by writing(?) to 0xde00 */
1409         memory_install_write8_handler( space, 0xde00, 0xdeff, 0, 0, comal80_bank_w );
1410         break;
1411      case GENERIC_CRT:       /* single bank, no bankswitch, loaded at start with correct size and place */
1412      default:
1413         break;
1414   }
1415}
1416
1417
1418MACHINE_RESET( c64 )
1419{
1420   if(c64_cart_loaded)
1421      setup_c64_custom_mappers(machine);
1422}
1423
1424
12321425MACHINE_DRIVER_START(c64_cartslot)
12331426   MDRV_CARTSLOT_ADD("cart1")
12341427   MDRV_CARTSLOT_EXTENSION_LIST("crt,80")

Previous 15994 Revisions Next


© 1998-2018 The MESS Team