src/mess/devices/ti99cart.c
| r6133 | r6134 | |
| 39 | 39 | struct _ti99_multicart_t |
| 40 | 40 | { |
| 41 | 41 | /* Reserves space for all cartridges. This is also used in the legacy |
| 42 | | cartridge system, but only for slot 0. */ |
| 42 | cartridge system, but only for slot 0. */ |
| 43 | 43 | cartridge_t cartridge[NUMBER_OF_CARTRIDGE_SLOTS]; |
| 44 | 44 | |
| 45 | 45 | /* Determines which slot is currently active. This value is changed when there |
| 46 | | are accesses to other GROM base addresses. */ |
| 46 | are accesses to other GROM base addresses. */ |
| 47 | 47 | int active_slot; |
| 48 | 48 | |
| 49 | 49 | /* Used in order to enforce a special slot. This value is retrieved |
| r6133 | r6134 | |
| 886 | 886 | int reply = 0; |
| 887 | 887 | |
| 888 | 888 | /* ram_page contains the bank number. We have a maximum of |
| 889 | | 4 banks; the Super Space II manual says: |
| 890 | | |
| 891 | | Banks are selected by writing a bit pattern to CRU address >0800: |
| 892 | | |
| 893 | | Bank # Value |
| 894 | | 0 >02 = 0000 0010 |
| 895 | | 1 >08 = 0000 1000 |
| 896 | | 2 >20 = 0010 0000 |
| 897 | | 3 >80 = 1000 0000 |
| 898 | | |
| 899 | | With the bank number (0, 1, 2, or 3) in R0: |
| 900 | | |
| 901 | | BNKSW LI R12,>0800 Set CRU address |
| 902 | | LI R1,2 Load Shift Bit |
| 903 | | SLA R0,1 Align Bank Number |
| 904 | | JEQ BNKS1 Skip shift if Bank 0 |
| 905 | | SLA R1,0 Align Shift Bit |
| 906 | | BNKS1 LDCR R1,0 Switch Banks |
| 907 | | SRL R0,1 Restore Bank Number (optional) |
| 908 | | RT |
| 909 | | */ |
| 889 | 4 banks; the Super Space II manual says: |
| 890 | |
| 891 | Banks are selected by writing a bit pattern to CRU address >0800: |
| 892 | |
| 893 | Bank # Value |
| 894 | 0 >02 = 0000 0010 |
| 895 | 1 >08 = 0000 1000 |
| 896 | 2 >20 = 0010 0000 |
| 897 | 3 >80 = 1000 0000 |
| 898 | |
| 899 | With the bank number (0, 1, 2, or 3) in R0: |
| 900 | |
| 901 | BNKSW LI R12,>0800 Set CRU address |
| 902 | LI R1,2 Load Shift Bit |
| 903 | SLA R0,1 Align Bank Number |
| 904 | JEQ BNKS1 Skip shift if Bank 0 |
| 905 | SLA R1,0 Align Shift Bit |
| 906 | BNKS1 LDCR R1,0 Switch Banks |
| 907 | SRL R0,1 Restore Bank Number (optional) |
| 908 | RT |
| 909 | */ |
| 910 | 910 | if ((offset & 1) == 0 || offset > 7) |
| 911 | 911 | reply = 0; |
| 912 | 912 | |
| 913 | 913 | /* CRU addresses are only 1 bit wide. Bytes are transferred from LSB |
| 914 | | to MSB. That is, 8 bit are eight consecutive addresses. */ |
| 914 | to MSB. That is, 8 bit are eight consecutive addresses. */ |
| 915 | 915 | reply = (cartridge->ram_page == (offset-1)/2); |
| 916 | 916 | |
| 917 | 917 | return reply; |
| r6133 | r6134 | |
| 1170 | 1170 | return INIT_PASS; |
| 1171 | 1171 | } |
| 1172 | 1172 | |
| 1173 | /***************************************************************************** |
| 1174 | Cartridge type: paged379i |
| 1175 | This cartridge consists of one 16 KiB, 32 KiB, or 64 KiB EEPROM which is |
| 1176 | organised in 2, 4, or 8 pages of 8 KiB each. We assume there is only one |
| 1177 | dump file of the respective size. |
| 1178 | The pages are selected by writing a value to some memory locations. Due to |
| 1179 | using the inverted outputs of the LS379 latch, setting the inputs of the |
| 1180 | latch to all 0 selects the highest bank, while setting to all 1 selects the |
| 1181 | lowest.There are some cartridges (16 KiB) which are using this scheme, and |
| 1182 | there are new hardware developments mainly relying on this scheme. |
| 1183 | |
| 1184 | Writing to selects page (16K/32K/64K) |
| 1185 | >6000 1 / 3 / 7 |
| 1186 | >6002 0 / 2 / 6 |
| 1187 | >6004 1 / 1 / 5 |
| 1188 | >6006 0 / 0 / 4 |
| 1189 | >6008 1 / 3 / 3 |
| 1190 | >600A 0 / 2 / 2 |
| 1191 | >600C 1 / 1 / 1 |
| 1192 | >600E 0 / 0 / 0 |
| 1173 | 1193 | |
| 1194 | ******************************************************************************/ |
| 1195 | |
| 1196 | static DEVICE_START(ti99_pcb_paged379i) |
| 1197 | { |
| 1198 | /* device is ti99_cartslot:cartridge:pcb */ |
| 1199 | // printf("DEVICE_START(ti99_pcb_paged379i), tag of device=%s\n", device->tag); |
| 1200 | set_pointers(device, get_index_from_tagname(device->owner)-1); |
| 1201 | } |
| 1202 | |
| 1203 | /* |
| 1204 | Read handler for the CPU address space of the cartridge |
| 1205 | Images for this area are found in the rom_sockets. |
| 1206 | */ |
| 1207 | static READ16_DEVICE_HANDLER( read_cart_paged379i ) |
| 1208 | { |
| 1209 | /* device is pcb, owner is cartslot */ |
| 1210 | UINT16 value; |
| 1211 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 1212 | cartridge_t *cartridge = pcb->cartridge; |
| 1213 | offs_t boffset; |
| 1214 | |
| 1215 | if (cartridge->rom_ptr==NULL) |
| 1216 | { |
| 1217 | // printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot); |
| 1218 | // printf("Cartridge address = %lx\n", (long)pcb->cartridge); |
| 1219 | value = 0; |
| 1220 | } |
| 1221 | else |
| 1222 | { |
| 1223 | // rom_page is the stored latch value |
| 1224 | // 16bit access -> multiply by 0x1000 |
| 1225 | boffset = cartridge->rom_page * 0x1000 + offset; |
| 1226 | value = ((UINT16 *)cartridge->rom_ptr)[boffset]; |
| 1227 | // printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value); |
| 1228 | } |
| 1229 | // printf("accessed cartridge rom[%02x:%04x] = %04x\n", cartridge->rom_page, 0x6000+offset*2, value); |
| 1230 | return value; |
| 1231 | } |
| 1232 | |
| 1233 | static void set_paged379i_bank(cartridge_t *cartridge, int rompage) |
| 1234 | { |
| 1235 | int mask = 0; |
| 1236 | if (cartridge->rom_size > 16384) |
| 1237 | { |
| 1238 | if (cartridge->rom_size > 32768) |
| 1239 | mask = 7; |
| 1240 | else |
| 1241 | mask = 3; |
| 1242 | } |
| 1243 | else |
| 1244 | mask = 1; |
| 1245 | |
| 1246 | cartridge->rom_page = rompage & mask; |
| 1247 | // printf("setting rompage to %d\n", cartridge->rom_page); |
| 1248 | } |
| 1249 | |
| 1250 | /* |
| 1251 | Handle paging. We use a LS379 latch for storing the page number. On this |
| 1252 | PCB, the inverted output of the latch is used, so the order of pages |
| 1253 | is reversed. (No problem as long as the memory dump is kept exactly |
| 1254 | in the way it is stored in the EPROM.) |
| 1255 | The latch can store a value of 4 bits. We adjust the number of |
| 1256 | significant bits by the size of the memory dump (16K, 32K, 64K). |
| 1257 | */ |
| 1258 | static WRITE16_DEVICE_HANDLER( write_cart_paged379i ) |
| 1259 | { |
| 1260 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 1261 | cartridge_t *cartridge = pcb->cartridge; |
| 1262 | /* |
| 1263 | >6000 1 / 3 / 7 |
| 1264 | >6002 0 / 2 / 6 |
| 1265 | >6004 1 / 1 / 5 |
| 1266 | >6006 0 / 0 / 4 |
| 1267 | >6008 1 / 3 / 3 |
| 1268 | >600A 0 / 2 / 2 |
| 1269 | >600C 1 / 1 / 1 |
| 1270 | >600E 0 / 0 / 0 |
| 1271 | |
| 1272 | Bits: 011x xxxx xxxx bbbx |
| 1273 | x = don't care, bbb = bank |
| 1274 | 16bit access -> drop rightmost bit |
| 1275 | */ |
| 1276 | set_paged379i_bank(cartridge, 7 - (offset & 7)); |
| 1277 | } |
| 1278 | |
| 1279 | /* |
| 1280 | TI-99/8 support: |
| 1281 | Read handler for the CPU address space of the cartridge. |
| 1282 | Images for this area are found in the rom_sockets. |
| 1283 | */ |
| 1284 | static READ8_DEVICE_HANDLER( read_cart_paged379i8 ) |
| 1285 | { |
| 1286 | UINT8 value; |
| 1287 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 1288 | cartridge_t *cartridge = pcb->cartridge; |
| 1289 | offs_t boffset; |
| 1290 | |
| 1291 | if (cartridge->rom_ptr==NULL) |
| 1292 | { |
| 1293 | // printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot); |
| 1294 | // printf("Cartridge address = %lx\n", (long)pcb->cartridge); |
| 1295 | value = 0; |
| 1296 | } |
| 1297 | else |
| 1298 | { |
| 1299 | // rom_page is the stored latch value |
| 1300 | // 8bit access -> multiply by 0x2000 |
| 1301 | boffset = cartridge->rom_page * 0x2000 + offset; |
| 1302 | value = ((UINT8 *)cartridge->rom_ptr)[boffset]; |
| 1303 | // printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value); |
| 1304 | } |
| 1305 | // printf("accessed cartridge rom[%02x:%04x] = %04x\n", cartridge->rom_page, 0x6000+offset*2, value); |
| 1306 | return value; |
| 1307 | |
| 1308 | } |
| 1309 | |
| 1310 | /* |
| 1311 | TI-99/8 support: Handle paging. |
| 1312 | */ |
| 1313 | static WRITE8_DEVICE_HANDLER( write_cart_paged379i8 ) |
| 1314 | { |
| 1315 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 1316 | cartridge_t *cartridge = pcb->cartridge; |
| 1317 | /* |
| 1318 | >6000 1 / 3 / 7 |
| 1319 | >6002 0 / 2 / 6 |
| 1320 | >6004 1 / 1 / 5 |
| 1321 | >6006 0 / 0 / 4 |
| 1322 | >6008 1 / 3 / 3 |
| 1323 | >600A 0 / 2 / 2 |
| 1324 | >600C 1 / 1 / 1 |
| 1325 | >600E 0 / 0 / 0 |
| 1326 | |
| 1327 | Bits: 011x xxxx xxxx bbbx |
| 1328 | x = don't care, bbb = bank |
| 1329 | 16bit access -> drop rightmost bit |
| 1330 | */ |
| 1331 | set_paged379i_bank(cartridge, 7 - ((offset>>1) & 7)); |
| 1332 | } |
| 1333 | |
| 1334 | /* |
| 1335 | Paged379i modules have one EPROM dump. |
| 1336 | */ |
| 1337 | static int assemble_paged379i(const device_config *image) |
| 1338 | { |
| 1339 | cartridge_t *cart; |
| 1340 | |
| 1341 | // printf("assemble_paged379i, %s\n", image->tag); |
| 1342 | cart = assemble_common(image); |
| 1343 | if (cart->rom_ptr==NULL) |
| 1344 | { |
| 1345 | logerror("Missing ROM for paged cartridge"); |
| 1346 | return INIT_FAIL; |
| 1347 | } |
| 1348 | set_paged379i_bank(cart, 15); |
| 1349 | return INIT_PASS; |
| 1350 | } |
| 1351 | |
| 1174 | 1352 | /***************************************************************************** |
| 1353 | Cartridge type: pagedcru |
| 1354 | This cartridge consists of one 16 KiB, 32 KiB, or 64 KiB EEPROM which is |
| 1355 | organised in 2, 4, or 8 pages of 8 KiB each. We assume there is only one |
| 1356 | dump file of the respective size. |
| 1357 | The pages are selected by writing a value to the CRU. This scheme is |
| 1358 | similar to the one used for the SuperSpace cartridge, with the exception |
| 1359 | that we are using ROM only, and we can have up to 8 pages. |
| 1360 | |
| 1361 | Bank Value written to CRU>0800 |
| 1362 | 0 >0002 = 0000 0000 0000 0010 |
| 1363 | 1 >0008 = 0000 0000 0000 1000 |
| 1364 | 2 >0020 = 0000 0000 0010 0000 |
| 1365 | 3 >0080 = 0000 0000 1000 0000 |
| 1366 | 4 >0200 = 0000 0010 0000 0000 |
| 1367 | 5 >0800 = 0000 1000 0000 0000 |
| 1368 | 6 >2000 = 0010 0000 0000 0000 |
| 1369 | 7 >8000 = 1000 0000 0000 0000 |
| 1370 | |
| 1371 | ******************************************************************************/ |
| 1372 | |
| 1373 | static DEVICE_START(ti99_pcb_pagedcru) |
| 1374 | { |
| 1375 | /* device is ti99_cartslot:cartridge:pcb */ |
| 1376 | // printf("DEVICE_START(ti99_pcb_paged379i), tag of device=%s\n", device->tag); |
| 1377 | set_pointers(device, get_index_from_tagname(device->owner)-1); |
| 1378 | } |
| 1379 | |
| 1380 | /* |
| 1381 | Read handler for the CPU address space of the cartridge |
| 1382 | Images for this area are found in the rom_sockets. |
| 1383 | */ |
| 1384 | static READ16_DEVICE_HANDLER( read_cart_pagedcru ) |
| 1385 | { |
| 1386 | /* device is pcb, owner is cartslot */ |
| 1387 | UINT16 value; |
| 1388 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 1389 | cartridge_t *cartridge = pcb->cartridge; |
| 1390 | offs_t boffset; |
| 1391 | |
| 1392 | if (cartridge->rom_ptr==NULL) |
| 1393 | { |
| 1394 | // printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot); |
| 1395 | // printf("Cartridge address = %lx\n", (long)pcb->cartridge); |
| 1396 | value = 0; |
| 1397 | } |
| 1398 | else |
| 1399 | { |
| 1400 | // rom_page is the stored latch value |
| 1401 | // 16bit access -> multiply by 0x1000 |
| 1402 | boffset = cartridge->rom_page * 0x1000 + offset; |
| 1403 | value = ((UINT16 *)cartridge->rom_ptr)[boffset]; |
| 1404 | // printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value); |
| 1405 | } |
| 1406 | // printf("accessed cartridge rom[%02x:%04x] = %04x\n", cartridge->rom_page, 0x6000+offset*2, value); |
| 1407 | return value; |
| 1408 | } |
| 1409 | |
| 1410 | /* |
| 1411 | This type of cartridge does not support writing to the EPROM address |
| 1412 | space. |
| 1413 | */ |
| 1414 | static WRITE16_DEVICE_HANDLER( write_cart_pagedcru ) |
| 1415 | { |
| 1416 | return; |
| 1417 | } |
| 1418 | |
| 1419 | /* |
| 1420 | TI-99/8 support: |
| 1421 | Read handler for the CPU address space of the cartridge. |
| 1422 | Images for this area are found in the rom_sockets. |
| 1423 | */ |
| 1424 | static READ8_DEVICE_HANDLER( read_cart_pagedcru8 ) |
| 1425 | { |
| 1426 | UINT8 value; |
| 1427 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 1428 | cartridge_t *cartridge = pcb->cartridge; |
| 1429 | offs_t boffset; |
| 1430 | |
| 1431 | if (cartridge->rom_ptr==NULL) |
| 1432 | { |
| 1433 | // printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot); |
| 1434 | // printf("Cartridge address = %lx\n", (long)pcb->cartridge); |
| 1435 | value = 0; |
| 1436 | } |
| 1437 | else |
| 1438 | { |
| 1439 | // rom_page is the stored latch value |
| 1440 | // 8bit access -> multiply by 0x2000 |
| 1441 | boffset = cartridge->rom_page * 0x2000 + offset; |
| 1442 | value = ((UINT8 *)cartridge->rom_ptr)[boffset]; |
| 1443 | // printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value); |
| 1444 | } |
| 1445 | // printf("accessed cartridge rom[%02x:%04x] = %04x\n", cartridge->rom_page, 0x6000+offset*2, value); |
| 1446 | return value; |
| 1447 | |
| 1448 | } |
| 1449 | |
| 1450 | /* |
| 1451 | TI-99/8 support: This type of cartridge does not support writing to the |
| 1452 | EPROM address space. |
| 1453 | */ |
| 1454 | static WRITE8_DEVICE_HANDLER( write_cart_pagedcru8 ) |
| 1455 | { |
| 1456 | return; |
| 1457 | } |
| 1458 | |
| 1459 | /* |
| 1460 | The CRU read handler. The CRU is a serial interface in the console. |
| 1461 | Using the CRU we can switch the banks in the SuperSpace cartridge. |
| 1462 | For documentation see the corresponding cru function above. Note we are |
| 1463 | using rom_page here. |
| 1464 | */ |
| 1465 | static READ8_DEVICE_HANDLER( read_cart_cru_paged ) |
| 1466 | { |
| 1467 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 1468 | cartridge_t *cartridge = pcb->cartridge; |
| 1469 | int reply = 0; |
| 1470 | |
| 1471 | if ((offset & 1) == 0 || offset > 15) |
| 1472 | reply = 0; |
| 1473 | |
| 1474 | reply = (cartridge->rom_page == (offset-1)/2); |
| 1475 | |
| 1476 | return reply; |
| 1477 | } |
| 1478 | |
| 1479 | static WRITE8_DEVICE_HANDLER( write_cart_cru_paged ) |
| 1480 | { |
| 1481 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 1482 | cartridge_t *cartridge = pcb->cartridge; |
| 1483 | // data is bit |
| 1484 | // offset is address |
| 1485 | /* Note that CRU >0F00 also gets in here ... should check |
| 1486 | whether it is intended to go somewhere else */ |
| 1487 | if (offset < 16) |
| 1488 | { |
| 1489 | if (data != 0) |
| 1490 | { |
| 1491 | cartridge->rom_page = (offset-1)/2; |
| 1492 | printf("Setting bit %4x of CRU base >0800\n", offset); |
| 1493 | } |
| 1494 | } |
| 1495 | // printf("setting rompage to %d\n", cartridge->rom_page); |
| 1496 | } |
| 1497 | |
| 1498 | /* |
| 1499 | Pagedcru modules have one EPROM dump. |
| 1500 | */ |
| 1501 | static int assemble_pagedcru(const device_config *image) |
| 1502 | { |
| 1503 | cartridge_t *cart; |
| 1504 | |
| 1505 | // printf("assemble_paged379i, %s\n", image->tag); |
| 1506 | cart = assemble_common(image); |
| 1507 | if (cart->rom_ptr==NULL) |
| 1508 | { |
| 1509 | logerror("Missing ROM for pagedcru cartridge"); |
| 1510 | return INIT_FAIL; |
| 1511 | } |
| 1512 | cart->rom_page = 0; |
| 1513 | return INIT_PASS; |
| 1514 | } |
| 1515 | |
| 1516 | /***************************************************************************** |
| 1175 | 1517 | Device metadata |
| 1176 | 1518 | ******************************************************************************/ |
| 1177 | 1519 | |
| r6133 | r6134 | |
| 1416 | 1758 | } |
| 1417 | 1759 | } |
| 1418 | 1760 | |
| 1761 | static DEVICE_GET_INFO(ti99_cartridge_pcb_paged379i) |
| 1762 | { |
| 1763 | switch(state) |
| 1764 | { |
| 1765 | case DEVINFO_FCT_START: |
| 1766 | info->start = DEVICE_START_NAME(ti99_pcb_paged379i); |
| 1767 | break; |
| 1419 | 1768 | |
| 1769 | case TI99CART_FCT_ASSM: |
| 1770 | info->f = (genf *) assemble_paged379i; break; |
| 1771 | |
| 1772 | case TI99CARTINFO_FCT_6000_R: |
| 1773 | info->f = (genf *) read_cart_paged379i; |
| 1774 | break; |
| 1775 | |
| 1776 | case TI99CARTINFO_FCT_6000_W: |
| 1777 | info->f = (genf *) write_cart_paged379i; |
| 1778 | break; |
| 1779 | |
| 1780 | case TI99CARTINFO_FCT_6000_R8: |
| 1781 | info->f = (genf *) read_cart_paged379i8; |
| 1782 | break; |
| 1783 | |
| 1784 | case TI99CARTINFO_FCT_6000_W8: |
| 1785 | info->f = (genf *) write_cart_paged379i8; |
| 1786 | break; |
| 1787 | |
| 1788 | case DEVINFO_STR_NAME: |
| 1789 | strcpy(info->s, "TI99 paged379i cartridge pcb"); |
| 1790 | break; |
| 1791 | |
| 1792 | default: |
| 1793 | DEVICE_GET_INFO_CALL(ti99_cart_common); |
| 1794 | break; |
| 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | static DEVICE_GET_INFO(ti99_cartridge_pcb_pagedcru) |
| 1799 | { |
| 1800 | switch(state) |
| 1801 | { |
| 1802 | case DEVINFO_FCT_START: |
| 1803 | info->start = DEVICE_START_NAME(ti99_pcb_pagedcru); |
| 1804 | break; |
| 1805 | |
| 1806 | case TI99CART_FCT_ASSM: |
| 1807 | info->f = (genf *) assemble_pagedcru; |
| 1808 | break; |
| 1809 | |
| 1810 | case TI99CARTINFO_FCT_6000_R: |
| 1811 | info->f = (genf *) read_cart_pagedcru; |
| 1812 | break; |
| 1813 | |
| 1814 | case TI99CARTINFO_FCT_6000_W: |
| 1815 | info->f = (genf *) write_cart_pagedcru; |
| 1816 | break; |
| 1817 | |
| 1818 | case TI99CARTINFO_FCT_6000_R8: |
| 1819 | info->f = (genf *) read_cart_pagedcru8; |
| 1820 | break; |
| 1821 | |
| 1822 | case TI99CARTINFO_FCT_6000_W8: |
| 1823 | info->f = (genf *) write_cart_pagedcru8; |
| 1824 | break; |
| 1825 | |
| 1826 | case TI99CARTINFO_FCT_CRU_R: |
| 1827 | info->f = (genf *) read_cart_cru_paged; |
| 1828 | break; |
| 1829 | case TI99CARTINFO_FCT_CRU_W: |
| 1830 | info->f = (genf *) write_cart_cru_paged; |
| 1831 | break; |
| 1832 | |
| 1833 | case DEVINFO_STR_NAME: |
| 1834 | strcpy(info->s, "TI99 pagedcru cartridge pcb"); |
| 1835 | break; |
| 1836 | |
| 1837 | default: |
| 1838 | DEVICE_GET_INFO_CALL(ti99_cart_common); |
| 1839 | break; |
| 1840 | } |
| 1841 | } |
| 1842 | |
| 1420 | 1843 | /***************************************************************************** |
| 1421 | 1844 | The cartridge handling of the multi-cartridge system. |
| 1422 | 1845 | Every cartridge contains a PCB device. The memory handlers delegate the calls |
| r6133 | r6134 | |
| 1464 | 1887 | |
| 1465 | 1888 | /* try opening this as a multicart */ |
| 1466 | 1889 | /* This line requires that cartslot_t be included in cartslot.h, |
| 1467 | | otherwise one cannot make use of multicart handling within such a |
| 1468 | | custom LOAD function. */ |
| 1890 | otherwise one cannot make use of multicart handling within such a |
| 1891 | custom LOAD function. */ |
| 1469 | 1892 | multicart_open_error me = multicart_open(image_filename(image), image->machine->gamedrv->name, MULTICART_FLAGS_LOAD_RESOURCES, &cart->mc); |
| 1470 | 1893 | |
| 1471 | 1894 | /* Now that we have loaded the image files, let the PCB put them all |
| 1472 | | together. This means we put the images in a structure which allows |
| 1473 | | for a quick access by the memory handlers. Every PCB defines an |
| 1474 | | own assembly method. */ |
| 1895 | together. This means we put the images in a structure which allows |
| 1896 | for a quick access by the memory handlers. Every PCB defines an |
| 1897 | own assembly method. */ |
| 1475 | 1898 | if (me == MCERR_NONE) |
| 1476 | 1899 | result = pcb->assemble(image); |
| 1477 | 1900 | else |
| 1478 | 1901 | fatalerror("Error loading multicart: %s\n", mc_error_text(me)); |
| 1479 | 1902 | |
| 1480 | 1903 | /* This is for legacy support. If we have no multicart left |
| 1481 | | but there are still legacy dumps, we switch to legacy mode. */ |
| 1904 | but there are still legacy dumps, we switch to legacy mode. */ |
| 1482 | 1905 | if (result != INIT_FAIL) |
| 1483 | 1906 | cartslots->multi_slots++; |
| 1484 | 1907 | } |
| r6133 | r6134 | |
| 1502 | 1925 | if (image->token == NULL) |
| 1503 | 1926 | { |
| 1504 | 1927 | /* This means something went wrong during the pcb |
| 1505 | | identification (e.g. one of the cartridge files was not |
| 1506 | | found). We do not need to (and cannot) unload |
| 1507 | | the cartridge. */ |
| 1928 | identification (e.g. one of the cartridge files was not |
| 1929 | found). We do not need to (and cannot) unload the cartridge. */ |
| 1508 | 1930 | return; |
| 1509 | 1931 | } |
| 1510 | 1932 | pcbdev = cartslot_get_pcb(image); |
| r6133 | r6134 | |
| 1521 | 1943 | pcb->disassemble(image); |
| 1522 | 1944 | |
| 1523 | 1945 | /* Close the multicart; all RAM resources will be |
| 1524 | | written to disk */ |
| 1946 | written to disk */ |
| 1525 | 1947 | multicart_close(cart->mc); |
| 1526 | 1948 | cart->mc = NULL; |
| 1527 | 1949 | |
| r6133 | r6134 | |
| 1577 | 1999 | if (cartridge->grom_size>0) |
| 1578 | 2000 | { |
| 1579 | 2001 | /* This is the reason why we need the image size: Read |
| 1580 | | access beyond the image size must be detected. */ |
| 2002 | access beyond the image size must be detected. */ |
| 1581 | 2003 | if (cart_offset > cartridge->grom_size) |
| 1582 | 2004 | return 0; |
| 1583 | 2005 | |
| r6133 | r6134 | |
| 1635 | 2057 | else |
| 1636 | 2058 | return (((UINT16 *)cartslots->cartridge[slotrom].rom_ptr)[offset]); |
| 1637 | 2059 | } |
| 1638 | | /* Super Space is not supported in legacy mode. */ |
| 2060 | /* SuperSpace, paged379i, and pagedcru are not supported in |
| 2061 | legacy mode. */ |
| 1639 | 2062 | } |
| 1640 | 2063 | |
| 1641 | 2064 | static WRITE16_DEVICE_HANDLER( ti99_cart_w_legacy ) |
| r6133 | r6134 | |
| 1729 | 2152 | else |
| 1730 | 2153 | return (((UINT8 *)cartslots->cartridge[slotrom].rom_ptr)[offset]); |
| 1731 | 2154 | } |
| 1732 | | /* Super Space is not supported in legacy mode. */ |
| 2155 | /* Super Space, paged379i, and pagedcru are not supported in |
| 2156 | legacy mode. */ |
| 1733 | 2157 | } |
| 1734 | 2158 | |
| 1735 | 2159 | /* |
| r6133 | r6134 | |
| 1793 | 2217 | /* Some comments originally in machine/ti99_4x.c */ |
| 1794 | 2218 | |
| 1795 | 2219 | /* We identify file types according to their extension */ |
| 1796 | | /* Note that if we do not recognize the extension, we revert to the slot location <-> type |
| 1797 | | scheme. */ |
| 2220 | /* Note that if we do not recognize the extension, we revert to the |
| 2221 | slot location <-> type scheme. */ |
| 1798 | 2222 | int id = 0; |
| 1799 | 2223 | int i; |
| 1800 | 2224 | int filesize; |
| r6133 | r6134 | |
| 1817 | 2241 | type = SLOTC_EMPTY; |
| 1818 | 2242 | |
| 1819 | 2243 | /* There is a circuitry in TI99/4(a) that resets the console when a |
| 1820 | | cartridge is inserted or removed. We emulate this instead of resetting the |
| 1821 | | emulator (which is the default in MESS). */ |
| 2244 | cartridge is inserted or removed. We emulate this instead of resetting |
| 2245 | the emulator (which is the default in MESS). */ |
| 1822 | 2246 | /*cpu_set_input_line(machine->firstcpu, INPUT_LINE_RESET, PULSE_LINE); |
| 1823 | | tms9901_reset(0); |
| 1824 | | if (! has_evpc) |
| 1825 | | TMS9928A_reset(); |
| 1826 | | if (has_evpc) |
| 1827 | | v9938_reset(0);*/ |
| 2247 | tms9901_reset(0); |
| 2248 | if (! has_evpc) |
| 2249 | TMS9928A_reset(); |
| 2250 | if (has_evpc) |
| 2251 | v9938_reset(0);*/ |
| 1828 | 2252 | |
| 1829 | 2253 | ch = strrchr(name, '.'); |
| 1830 | 2254 | ch2 = (ch-1 >= name) ? ch-1 : ""; |
| r6133 | r6134 | |
| 1888 | 2312 | maxrom = 0x2000; |
| 1889 | 2313 | if (cartslots->legacy_slotnumber[SLOTC_MINIMEM] != -1) |
| 1890 | 2314 | { |
| 1891 | | /* This means the NVRAM has already been loaded. So we just |
| 1892 | | load 4K of ROM to avoid overwriting the NVRAM. */ |
| 2315 | /* This means the NVRAM has already been loaded. |
| 2316 | So we just load 4K of ROM to avoid overwriting |
| 2317 | the NVRAM. */ |
| 1893 | 2318 | maxrom = 0x1000; |
| 1894 | 2319 | } |
| 1895 | 2320 | |
| 1896 | 2321 | if (cartslots->legacy_slotnumber[SLOTC_MBX] != -1) |
| 1897 | 2322 | { |
| 1898 | 2323 | /* This means the NVRAM has already been loaded. |
| 1899 | | We need to temporarily save the RAM contents and |
| 1900 | | write them back because the RAM overrides the |
| 1901 | | ROM in an intermediate area. */ |
| 2324 | We need to temporarily save the RAM contents and |
| 2325 | write them back because the RAM overrides the |
| 2326 | ROM in an intermediate area. */ |
| 1902 | 2327 | savembx = TRUE; |
| 1903 | 2328 | } |
| 1904 | 2329 | |
| r6133 | r6134 | |
| 1941 | 2366 | |
| 1942 | 2367 | case SLOTC_MINIMEM: |
| 1943 | 2368 | /* Load the NVRAM. Need to BIG_ENDIANIZE it. |
| 1944 | | MiniMemory has only one cartridge page. */ |
| 2369 | MiniMemory has only one cartridge page. */ |
| 1945 | 2370 | if (is_99_8()) |
| 1946 | 2371 | { |
| 1947 | 2372 | // printf("** is 99/8\n"); |
| r6133 | r6134 | |
| 2039 | 2464 | } |
| 2040 | 2465 | else |
| 2041 | 2466 | { |
| 2042 | | /* We BIG_ENDIANIZE before saving. This is consistent |
| 2043 | | with the cartridge save format. */ |
| 2467 | /* We BIG_ENDIANIZE before saving. This is |
| 2468 | consistent with the cartridge save format. */ |
| 2044 | 2469 | UINT16 *ramcont = (UINT16 *)cartslots->cartridge[slot].ram_ptr; |
| 2045 | 2470 | for (i = 0; i < 0x0800; i++) |
| 2046 | 2471 | ramcont[i] = BIG_ENDIANIZE_INT16(ramcont[i]); |
| r6133 | r6134 | |
| 2057 | 2482 | } |
| 2058 | 2483 | else |
| 2059 | 2484 | { |
| 2060 | | /* We BIG_ENDIANIZE before saving. This is consistent |
| 2061 | | with the cartridge save format. */ |
| 2485 | /* We BIG_ENDIANIZE before saving. This is |
| 2486 | consistent with the cartridge save format. */ |
| 2062 | 2487 | UINT16 *ramcont = (UINT16 *)cartslots->cartridge[slot].ram_ptr; |
| 2063 | 2488 | for (i = 0; i < 0x0200; i++) |
| 2064 | 2489 | ramcont[i] = BIG_ENDIANIZE_INT16(ramcont[i]); |
| r6133 | r6134 | |
| 2104 | 2529 | // printf("DEVICE_START(ti99_multicart)\n"); |
| 2105 | 2530 | ti99_multicart_t *cartslots = (ti99_multicart_t *)device->token; |
| 2106 | 2531 | |
| 2107 | | /* Save this in the shortcut; we don't want to look for it each time |
| 2108 | | that we have a memory access. And currently we do not plan for |
| 2109 | | multiple multicart instances. */ |
| 2110 | 2532 | cartslots->active_slot = 0; |
| 2111 | 2533 | cartslots->next_free_slot = 0; |
| 2112 | 2534 | |
| r6133 | r6134 | |
| 2134 | 2556 | { |
| 2135 | 2557 | // printf("DEVICE_STOP(ti99_multicart)\n"); |
| 2136 | 2558 | } |
| 2559 | |
| 2560 | static DEVICE_RESET(ti99_multicart) |
| 2561 | { |
| 2562 | /* Consider to propagate RESET to cartridges. |
| 2563 | However, schematics do not reveal any pin for resetting a cartridge; |
| 2564 | the reset line is an input used when plugging in a cartridge. */ |
| 2565 | // printf("DEVICE_RESET(ti99_multicart)\n"); |
| 2566 | } |
| 2567 | |
| 2137 | 2568 | /* |
| 2138 | | Accesses the ROM regions of the cartridge for reading. |
| 2139 | | This is the area from 0x6000 to 0x7fff. Each cartridge is reponsible |
| 2140 | | for all kinds of magic which is done inside this area, like swapping |
| 2141 | | banks or doing other control actions. These activities beyond simple |
| 2142 | | reading are cartridge-specific. Each kind of cartridge requires a |
| 2143 | | new type. |
| 2144 | | The currently set GROM bank determines which cartridge is actually |
| 2145 | | accessed, also for ROM reads. |
| 2569 | Accesses the ROM regions of the cartridge for reading. |
| 2570 | This is the area from 0x6000 to 0x7fff. Each cartridge is reponsible |
| 2571 | for all kinds of magic which is done inside this area, like swapping |
| 2572 | banks or doing other control actions. These activities beyond simple |
| 2573 | reading are cartridge-specific. Each kind of cartridge requires a |
| 2574 | new type. |
| 2575 | The currently set GROM bank determines which cartridge is actually |
| 2576 | accessed, also for ROM reads. |
| 2146 | 2577 | */ |
| 2147 | 2578 | READ16_DEVICE_HANDLER( ti99_multicart_r ) |
| 2148 | 2579 | { |
| r6133 | r6134 | |
| 2196 | 2627 | } |
| 2197 | 2628 | |
| 2198 | 2629 | /* |
| 2199 | | Accesses the ROM regions of the cartridge for writing. |
| 2200 | | This is the area from 0x6000 to 0x7fff. Each cartridge is reponsible |
| 2201 | | for all kinds of magic which is done inside this area. Specifically, |
| 2202 | | writing is often used to swap banks for subsequent reads. The actual |
| 2203 | | effect of writing (beyond setting values in a RAM chip) are |
| 2204 | | cartridge-specific and must be handled within the cartridge pcb. |
| 2205 | | The currently set GROM bank determines which cartridge is actually |
| 2206 | | accessed, also for ROM reads. |
| 2630 | Accesses the ROM regions of the cartridge for writing. |
| 2631 | This is the area from 0x6000 to 0x7fff. Each cartridge is reponsible |
| 2632 | for all kinds of magic which is done inside this area. Specifically, |
| 2633 | writing is often used to swap banks for subsequent reads. The actual |
| 2634 | effect of writing (beyond setting values in a RAM chip) are |
| 2635 | cartridge-specific and must be handled within the cartridge pcb. |
| 2636 | The currently set GROM bank determines which cartridge is actually |
| 2637 | accessed, also for ROM reads. |
| 2207 | 2638 | */ |
| 2208 | 2639 | WRITE16_DEVICE_HANDLER( ti99_multicart_w ) |
| 2209 | 2640 | { |
| r6133 | r6134 | |
| 2242 | 2673 | } |
| 2243 | 2674 | |
| 2244 | 2675 | /* |
| 2245 | | CRU interface to cartridges, used only by SuperSpace-style cartridges. |
| 2676 | CRU interface to cartridges, used only by SuperSpace and Pagedcru |
| 2677 | style cartridges. |
| 2246 | 2678 | The SuperSpace has a CRU-based memory mapper. It is accessed via the |
| 2247 | 2679 | cartridge slot on CRU base >0800. |
| 2248 | 2680 | */ |
| r6133 | r6134 | |
| 2273 | 2705 | } |
| 2274 | 2706 | |
| 2275 | 2707 | /* |
| 2276 | | Write cartridge mapper CRU interface (SuperSpace) |
| 2708 | Write cartridge mapper CRU interface (SuperSpace, Pagedcru) |
| 2277 | 2709 | */ |
| 2278 | 2710 | WRITE8_DEVICE_HANDLER( ti99_multicart_cru_w ) |
| 2279 | 2711 | { |
| r6133 | r6134 | |
| 2387 | 2819 | MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM) |
| 2388 | 2820 | MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER) |
| 2389 | 2821 | MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX) |
| 2822 | MDRV_CARTSLOT_PCBTYPE(6, "paged379i", TI99_CARTRIDGE_PCB_PAGED379I) |
| 2823 | MDRV_CARTSLOT_PCBTYPE(7, "pagedcru", TI99_CARTRIDGE_PCB_PAGEDCRU) |
| 2390 | 2824 | |
| 2391 | 2825 | MDRV_CARTSLOT_START(ti99_cartridge) |
| 2392 | 2826 | MDRV_CARTSLOT_LOAD(ti99_cartridge) |
| r6133 | r6134 | |
| 2400 | 2834 | MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM) |
| 2401 | 2835 | MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER) |
| 2402 | 2836 | MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX) |
| 2837 | MDRV_CARTSLOT_PCBTYPE(6, "paged379i", TI99_CARTRIDGE_PCB_PAGED379I) |
| 2838 | MDRV_CARTSLOT_PCBTYPE(7, "pagedcru", TI99_CARTRIDGE_PCB_PAGEDCRU) |
| 2403 | 2839 | |
| 2404 | 2840 | MDRV_CARTSLOT_START(ti99_cartridge) |
| 2405 | 2841 | MDRV_CARTSLOT_LOAD(ti99_cartridge) |
| r6133 | r6134 | |
| 2413 | 2849 | MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM) |
| 2414 | 2850 | MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER) |
| 2415 | 2851 | MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX) |
| 2852 | MDRV_CARTSLOT_PCBTYPE(6, "paged379i", TI99_CARTRIDGE_PCB_PAGED379I) |
| 2853 | MDRV_CARTSLOT_PCBTYPE(7, "pagedcru", TI99_CARTRIDGE_PCB_PAGEDCRU) |
| 2416 | 2854 | |
| 2417 | 2855 | MDRV_CARTSLOT_START(ti99_cartridge) |
| 2418 | 2856 | MDRV_CARTSLOT_LOAD(ti99_cartridge) |
| r6133 | r6134 | |
| 2426 | 2864 | MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM) |
| 2427 | 2865 | MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER) |
| 2428 | 2866 | MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX) |
| 2867 | MDRV_CARTSLOT_PCBTYPE(6, "paged379i", TI99_CARTRIDGE_PCB_PAGED379I) |
| 2868 | MDRV_CARTSLOT_PCBTYPE(7, "pagedcru", TI99_CARTRIDGE_PCB_PAGEDCRU) |
| 2429 | 2869 | |
| 2430 | 2870 | MDRV_CARTSLOT_START(ti99_cartridge) |
| 2431 | 2871 | MDRV_CARTSLOT_LOAD(ti99_cartridge) |
| r6133 | r6134 | |
| 2470 | 2910 | info->stop = DEVICE_STOP_NAME(ti99_multicart); |
| 2471 | 2911 | break; |
| 2472 | 2912 | case DEVINFO_FCT_RESET: |
| 2473 | | /* Nothing */ |
| 2913 | info->reset = DEVICE_RESET_NAME(ti99_multicart); |
| 2474 | 2914 | break; |
| 2475 | 2915 | } |
| 2476 | 2916 | } |