src/mess/machine/ti99_4x.c
| r4596 | r4597 | |
| 221 | 221 | The p-code card (-> UCSD Pascal system) contains 8 GROMs, all in port 16. This port is not |
| 222 | 222 | in the range recognized by the TI ROMs (0-15), and therefore it is used by the p-code DSR ROMs |
| 223 | 223 | as custom data. Additionally, some hackers used the extra ports to implement "GRAM" devices. |
| 224 | |
| 225 | The handling of cartridge GROMs has moved to ti99cart.c. |
| 224 | 226 | */ |
| 225 | | /* GROM_port_t: descriptor for a port of 8 GROMs */ |
| 226 | | typedef struct GROM_port_t |
| 227 | | { |
| 228 | | /* pointer to GROM data */ |
| 229 | | UINT8 *data_ptr; |
| 230 | | /* current address pointer for the active GROM in port (16 bits) */ |
| 231 | | unsigned int addr; |
| 232 | | /* GROM data buffer */ |
| 233 | | UINT8 buf; |
| 234 | | /* internal flip-flops that are set after the first access to the GROM |
| 235 | | address so that next access is mapped to the LSB, and cleared after each |
| 236 | | data access */ |
| 237 | | char raddr_LSB, waddr_LSB; |
| 238 | | } GROM_port_t; |
| 239 | 227 | |
| 240 | 228 | /* descriptor for console GROMs */ |
| 241 | | static GROM_port_t console_GROMs; |
| 229 | GROM_port_t console_GROMs; |
| 242 | 230 | |
| 243 | 231 | /* true if hsgpl is enabled (i.e. has_hsgpl is true and hsgpl cru bit crdena is |
| 244 | 232 | set) */ |
| 245 | 233 | static char hsgpl_crdena; |
| 246 | 234 | |
| 247 | | /* |
| 248 | | Cartridge support |
| 249 | | */ |
| 250 | | /* pointer on two 8kb cartridge pages */ |
| 251 | | static UINT16 *cartridge_pages[2] = {NULL, NULL}; |
| 252 | | static UINT8 *cartridge_pages_8[2] = {NULL, NULL}; |
| 253 | | /* flag: TRUE if the cartridge is minimemory (4kb of battery-backed SRAM in 0x5000-0x5fff) */ |
| 254 | | static char cartridge_minimemory = FALSE; |
| 255 | | /* flag: TRUE if the cartridge is paged */ |
| 256 | | static char cartridge_paged = FALSE; |
| 257 | | /* flag: TRUE if the cartridge is MBX-style */ |
| 258 | | static char cartridge_mbx = FALSE; |
| 259 | | /* flag on the data for the current page (cartridge_pages[0] if cartridge is not paged) */ |
| 260 | | static UINT16 *current_page_ptr; |
| 261 | | static UINT8 *current_page_ptr_8; |
| 262 | | /* keep track of cart file types - required for cleanup... */ |
| 263 | | typedef enum _slot_type_t { SLOT_EMPTY = -1, SLOT_GROM = 0, SLOT_CROM = 1, SLOT_DROM = 2, SLOT_MINIMEM = 3, SLOT_MBX = 4 } slot_type_t; |
| 264 | | static slot_type_t slot_type[3] = { SLOT_EMPTY, SLOT_EMPTY, SLOT_EMPTY}; |
| 265 | | |
| 266 | 235 | /* true if 99/4p rom6 is enabled */ |
| 267 | 236 | static int ti99_4p_internal_rom6_enable; |
| 268 | 237 | /* pointer to the ROM6 data */ |
| 269 | 238 | static UINT16 *ti99_4p_internal_ROM6; |
| 270 | 239 | |
| 240 | /* Pointer to the cartridge system for the 99/8 */ |
| 241 | static const device_config *multicart8; |
| 271 | 242 | |
| 272 | 243 | /* ti99/8 hardware */ |
| 273 | | static UINT8 ti99_8_CRUS; |
| 244 | static UINT8 ti99_8_enable_rom_and_ports; |
| 274 | 245 | |
| 275 | 246 | static UINT32 ti99_8_mapper_regs[16]; |
| 276 | 247 | static UINT8 ti99_8_mapper_status; |
| 277 | | enum |
| 278 | | { |
| 279 | | ms_WPE = 0x80, /* Write-Protect Error */ |
| 280 | | ms_XCE = 0x40, /* eXeCute Error */ |
| 281 | | ms_RPE = 0x20 /* Read-Protect Error */ |
| 282 | | }; |
| 283 | 248 | |
| 284 | 249 | static UINT8 *xRAM_ptr_8; |
| 285 | 250 | static UINT8 *ROM0_ptr_8; |
| r4596 | r4597 | |
| 292 | 257 | /* tms9995_ICount: used to implement memory waitstates (hack) */ |
| 293 | 258 | /* NPW 23-Feb-2004 - externs no longer needed because we now use cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),) */ |
| 294 | 259 | |
| 260 | /* Link to the cartridge system. */ |
| 261 | const device_config *cartslots; |
| 295 | 262 | |
| 296 | | |
| 297 | 263 | /*===========================================================================*/ |
| 298 | 264 | /* |
| 299 | 265 | General purpose code: |
| 300 | 266 | initialization, cart loading, etc. |
| 301 | 267 | */ |
| 302 | 268 | |
| 303 | | DRIVER_INIT( ti99_4 ) |
| 269 | static void create_grom_high2k(int first, int last) |
| 304 | 270 | { |
| 305 | | int i, j; |
| 271 | /* Generate missing chunk of each console GROMs. Although a GROM |
| 272 | occupies 8 KiB of address space, it only has 6 KiB capacity, and |
| 273 | the last 2 KiB mirror previous content as shown above. */ |
| 274 | int base; |
| 275 | for (base=(first&0xe000); base<((last+1)&0xe000); base+=0x2000) |
| 276 | { |
| 277 | int j; |
| 278 | for (j=0; j<0x800; j++) |
| 279 | { |
| 280 | console_GROMs.data_ptr[base+0x1800+j] = |
| 281 | console_GROMs.data_ptr[base+0x0800+j] |
| 282 | | console_GROMs.data_ptr[base+0x1000+j]; |
| 283 | } |
| 284 | } |
| 285 | } |
| 306 | 286 | |
| 287 | int is_99_8() |
| 288 | { |
| 289 | return ti99_model == model_99_8; |
| 290 | } |
| 307 | 291 | |
| 292 | DRIVER_INIT( ti99_4 ) |
| 293 | { |
| 308 | 294 | ti99_model = model_99_4; |
| 309 | 295 | has_evpc = FALSE; |
| 310 | 296 | |
| 311 | 297 | /* set up memory pointers */ |
| 312 | 298 | xRAM_ptr = (UINT16 *) (memory_region(machine, "maincpu") + offset_xram); |
| 313 | 299 | console_GROMs.data_ptr = memory_region(machine, region_grom); |
| 314 | | |
| 315 | | /* Generate missing chunk of each console GROMs */ |
| 316 | | for (i=0; i<2; i++) |
| 317 | | for (j=0; j<0x800; j++) |
| 318 | | { |
| 319 | | console_GROMs.data_ptr[0x2000*i+0x1800+j] = console_GROMs.data_ptr[0x2000*i+0x0800+j] |
| 320 | | | console_GROMs.data_ptr[0x2000*i+0x1000+j]; |
| 321 | | } |
| 300 | create_grom_high2k(0x0000, 0x5fff); |
| 322 | 301 | } |
| 323 | 302 | |
| 324 | 303 | DRIVER_INIT( ti99_4a ) |
| r4596 | r4597 | |
| 329 | 308 | /* set up memory pointers */ |
| 330 | 309 | xRAM_ptr = (UINT16 *) (memory_region(machine, "maincpu") + offset_xram); |
| 331 | 310 | console_GROMs.data_ptr = memory_region(machine, region_grom); |
| 311 | create_grom_high2k(0x0000, 0x5fff); |
| 332 | 312 | } |
| 333 | 313 | |
| 334 | 314 | DRIVER_INIT( ti99_4ev ) |
| r4596 | r4597 | |
| 339 | 319 | |
| 340 | 320 | /* set up memory pointers */ |
| 341 | 321 | xRAM_ptr = (UINT16 *) (mem + offset_xram); |
| 342 | | cartridge_pages[0] = (UINT16 *) (mem+offset_cart); |
| 343 | | cartridge_pages[1] = (UINT16 *) (mem+offset_cart + 0x2000); |
| 344 | 322 | console_GROMs.data_ptr = memory_region(machine, region_grom); |
| 323 | create_grom_high2k(0x0000, 0x5fff); |
| 345 | 324 | } |
| 346 | 325 | |
| 347 | 326 | DRIVER_INIT( ti99_8 ) |
| r4596 | r4597 | |
| 349 | 328 | UINT8 *mem = memory_region(machine, "maincpu"); |
| 350 | 329 | ti99_model = model_99_8; |
| 351 | 330 | has_evpc = FALSE; |
| 352 | | |
| 331 | |
| 353 | 332 | /* set up memory pointers */ |
| 354 | 333 | xRAM_ptr_8 = mem + offset_xram_8; |
| 355 | 334 | ROM0_ptr_8 = mem + offset_rom0_8; |
| r4596 | r4597 | |
| 358 | 337 | ROM3_ptr_8 = ROM2_ptr_8 + 0x2000; |
| 359 | 338 | sRAM_ptr_8 = mem + offset_sram_8; |
| 360 | 339 | |
| 361 | | cartridge_pages_8[0] = mem+offset_cart_8; |
| 362 | | cartridge_pages_8[1] = mem+offset_cart_8 + 0x2000; |
| 340 | /* Pull this one up here. */ |
| 341 | ti99_8_enable_rom_and_ports = 1; |
| 342 | |
| 363 | 343 | console_GROMs.data_ptr = memory_region(machine, region_grom); |
| 344 | create_grom_high2k(0x0000, 0x5fff); |
| 345 | |
| 346 | multicart8 = devtag_get_device(machine, "ti99_multicart"); |
| 347 | assert (multicart8 != NULL); |
| 364 | 348 | } |
| 365 | 349 | |
| 366 | 350 | DRIVER_INIT( ti99_4p ) |
| r4596 | r4597 | |
| 371 | 355 | /* set up memory pointers */ |
| 372 | 356 | xRAM_ptr = (UINT16 *) (memory_region(machine, "maincpu") + offset_xram_4p); |
| 373 | 357 | /*console_GROMs.data_ptr = memory_region(machine, region_grom);*/ |
| 358 | create_grom_high2k(0x0000, 0x5fff); |
| 374 | 359 | } |
| 375 | 360 | |
| 376 | | DEVICE_START( ti99_cart ) |
| 377 | | { |
| 378 | | int id = 0; |
| 379 | | if (strcmp(device->tag,"cart1")==0) { |
| 380 | | id = 0; |
| 381 | | } |
| 382 | | if (strcmp(device->tag,"cart2")==0) { |
| 383 | | id = 1; |
| 384 | | } |
| 385 | | if (strcmp(device->tag,"cart3")==0) { |
| 386 | | id = 2; |
| 387 | | } |
| 388 | | |
| 389 | | cartridge_pages[id] = (UINT16 *) (memory_region(device->machine, "maincpu") + offset_cart + (id * 0x2000)); |
| 390 | | } |
| 391 | | |
| 392 | | /* |
| 393 | | Load ROM. All files are in raw binary format. |
| 394 | | 1st ROM: GROM (up to 40kb) |
| 395 | | 2nd ROM: CPU ROM (8kb) |
| 396 | | 3rd ROM: CPU ROM, 2nd page (8kb) |
| 397 | | |
| 398 | | We don't need to support 99/4p, as it has no cartridge port. |
| 399 | | */ |
| 400 | | DEVICE_IMAGE_LOAD( ti99_cart ) |
| 401 | | { |
| 402 | | /* Trick - we identify file types according to their extension */ |
| 403 | | /* Note that if we do not recognize the extension, we revert to the slot location <-> type |
| 404 | | scheme. I do this because the extension concept is quite unfamiliar to mac people |
| 405 | | (I am dead serious). */ |
| 406 | | /* Original idea by Norberto Bensa */ |
| 407 | | const char *name = image_filename(image); |
| 408 | | const char *ch, *ch2; |
| 409 | | int id = 0; |
| 410 | | int i; |
| 411 | | slot_type_t type; |
| 412 | | |
| 413 | | if (strcmp(image->tag,"cart1")==0) { |
| 414 | | id = 0; |
| 415 | | } |
| 416 | | if (strcmp(image->tag,"cart2")==0) { |
| 417 | | id = 1; |
| 418 | | } |
| 419 | | if (strcmp(image->tag,"cart3")==0) { |
| 420 | | id = 2; |
| 421 | | } |
| 422 | | type = (slot_type_t) id; |
| 423 | | |
| 424 | | /* There is a circuitry in TI99/4(a) that resets the console when a |
| 425 | | cartridge is inserted or removed. We emulate this instead of resetting the |
| 426 | | emulator (which is the default in MESS). */ |
| 427 | | /*cputag_set_input_line(machine, "maincpu", INPUT_LINE_RESET, PULSE_LINE); |
| 428 | | tms9901_reset(0); |
| 429 | | if (! has_evpc) |
| 430 | | TMS9928A_reset(); |
| 431 | | if (has_evpc) |
| 432 | | v9938_reset(0);*/ |
| 433 | | |
| 434 | | ch = strrchr(name, '.'); |
| 435 | | ch2 = (ch-1 >= name) ? ch-1 : ""; |
| 436 | | |
| 437 | | if (ch) |
| 438 | | { |
| 439 | | if ((! mame_stricmp(ch2, "g.bin")) || (! mame_stricmp(ch, ".grom")) || (! mame_stricmp(ch, ".g"))) |
| 440 | | { |
| 441 | | /* grom */ |
| 442 | | type = SLOT_GROM; |
| 443 | | } |
| 444 | | else if ((! mame_stricmp(ch2, "c.bin")) || (! mame_stricmp(ch, ".crom")) || (! mame_stricmp(ch, ".c"))) |
| 445 | | { |
| 446 | | /* rom first page */ |
| 447 | | type = SLOT_CROM; |
| 448 | | } |
| 449 | | else if ((! mame_stricmp(ch2, "d.bin")) || (! mame_stricmp(ch, ".drom")) || (! mame_stricmp(ch, ".d"))) |
| 450 | | { |
| 451 | | /* rom second page */ |
| 452 | | type = SLOT_DROM; |
| 453 | | } |
| 454 | | else if ((! mame_stricmp(ch2, "m.bin")) || (! mame_stricmp(ch, ".mrom")) || (! mame_stricmp(ch, ".m"))) |
| 455 | | { |
| 456 | | /* rom minimemory */ |
| 457 | | type = SLOT_MINIMEM; |
| 458 | | } |
| 459 | | else if ((! mame_stricmp(ch2, "b.bin")) || (! mame_stricmp(ch, ".brom")) || (! mame_stricmp(ch, ".b"))) |
| 460 | | { |
| 461 | | /* rom MBX */ |
| 462 | | type = SLOT_MBX; |
| 463 | | } |
| 464 | | } |
| 465 | | |
| 466 | | slot_type[id] = type; |
| 467 | | |
| 468 | | switch (type) |
| 469 | | { |
| 470 | | case SLOT_EMPTY: |
| 471 | | break; |
| 472 | | |
| 473 | | case SLOT_GROM: |
| 474 | | image_fread(image, memory_region(image->machine, region_grom) + 0x6000, 0xA000); |
| 475 | | break; |
| 476 | | |
| 477 | | case SLOT_MINIMEM: |
| 478 | | cartridge_minimemory = TRUE; |
| 479 | | /* Load the NVRAM. Need to BIG_ENDIANIZE it. |
| 480 | | MiniMemory has only one cartridge page. */ |
| 481 | | image_battery_load(image, cartridge_pages[0]+0x800,0x1000); |
| 482 | | for (i = 0x800; i < 0x1000; i++) |
| 483 | | cartridge_pages[0][i] = BIG_ENDIANIZE_INT16(cartridge_pages[0][i]); |
| 484 | | break; |
| 485 | | case SLOT_MBX: |
| 486 | | cartridge_mbx = TRUE; |
| 487 | | break; |
| 488 | | case SLOT_CROM: |
| 489 | | if (ti99_model == model_99_8) |
| 490 | | { |
| 491 | | if (cartridge_minimemory) |
| 492 | | /* Only load 4K so we don't overwrite the NVRAM. */ |
| 493 | | image_fread(image, cartridge_pages_8[0], 0x1000); |
| 494 | | else |
| 495 | | image_fread(image, cartridge_pages_8[0], 0x2000); |
| 496 | | current_page_ptr_8 = cartridge_pages_8[0]; |
| 497 | | } |
| 498 | | else |
| 499 | | { |
| 500 | | if (cartridge_minimemory) |
| 501 | | { |
| 502 | | /* Only load 4K so we don't overwrite the NVRAM that |
| 503 | | has been loaded already. */ |
| 504 | | image_fread(image, cartridge_pages[0], 0x1000); |
| 505 | | for (i = 0; i < 0x0800; i++) |
| 506 | | cartridge_pages[0][i] = BIG_ENDIANIZE_INT16(cartridge_pages[0][i]); |
| 507 | | } |
| 508 | | else |
| 509 | | { |
| 510 | | image_fread(image, cartridge_pages[0], 0x2000); |
| 511 | | for (i = 0; i < 0x1000; i++) |
| 512 | | cartridge_pages[0][i] = BIG_ENDIANIZE_INT16(cartridge_pages[0][i]); |
| 513 | | } |
| 514 | | current_page_ptr = cartridge_pages[0]; |
| 515 | | } |
| 516 | | break; |
| 517 | | |
| 518 | | case SLOT_DROM: |
| 519 | | cartridge_paged = TRUE; |
| 520 | | if (ti99_model == model_99_8) |
| 521 | | { |
| 522 | | image_fread(image, cartridge_pages_8[1], 0x2000); |
| 523 | | current_page_ptr_8 = cartridge_pages_8[0]; |
| 524 | | } |
| 525 | | else |
| 526 | | { |
| 527 | | image_fread(image, cartridge_pages[1], 0x2000); |
| 528 | | for (i = 0; i < 0x1000; i++) |
| 529 | | cartridge_pages[1][i] = BIG_ENDIANIZE_INT16(cartridge_pages[1][i]); |
| 530 | | current_page_ptr = cartridge_pages[0]; |
| 531 | | } |
| 532 | | break; |
| 533 | | } |
| 534 | | |
| 535 | | return INIT_PASS; |
| 536 | | } |
| 537 | | |
| 538 | | DEVICE_IMAGE_UNLOAD( ti99_cart ) |
| 539 | | { |
| 540 | | int i; |
| 541 | | int id = 0; |
| 542 | | if (strcmp(image->tag,"cart1")==0) { |
| 543 | | id = 0; |
| 544 | | } |
| 545 | | if (strcmp(image->tag,"cart2")==0) { |
| 546 | | id = 1; |
| 547 | | } |
| 548 | | if (strcmp(image->tag,"cart3")==0) { |
| 549 | | id = 2; |
| 550 | | } |
| 551 | | /* There is a circuitry in TI99/4(a) that resets the console when a |
| 552 | | cartridge is inserted or removed. We emulate this instead of resetting the |
| 553 | | emulator (which is the default in MESS). */ |
| 554 | | /*cputag_set_input_line(machine, "maincpu", INPUT_LINE_RESET, PULSE_LINE); |
| 555 | | tms9901_reset(0); |
| 556 | | if (! has_evpc) |
| 557 | | TMS9928A_reset(); |
| 558 | | if (has_evpc) |
| 559 | | v9938_reset(0);*/ |
| 560 | | |
| 561 | | switch (slot_type[id]) |
| 562 | | { |
| 563 | | case SLOT_EMPTY: |
| 564 | | break; |
| 565 | | |
| 566 | | case SLOT_GROM: |
| 567 | | memset(memory_region(image->machine, region_grom) + 0x6000, 0, 0xA000); |
| 568 | | break; |
| 569 | | |
| 570 | | case SLOT_MINIMEM: |
| 571 | | cartridge_minimemory = FALSE; |
| 572 | | if (ti99_model == model_99_8) |
| 573 | | { |
| 574 | | image_battery_save(image, cartridge_pages_8[0] + 0x1000, 0x1000); |
| 575 | | memset(cartridge_pages_8[0] + 0x1000, 0, 0x1000); |
| 576 | | } |
| 577 | | else |
| 578 | | { |
| 579 | | /* We BIG_ENDIANIZE before saving. This is consistent |
| 580 | | with the cartridge save format. */ |
| 581 | | for (i = 0x800; i < 0x1000; i++) |
| 582 | | cartridge_pages[0][i] = BIG_ENDIANIZE_INT16(cartridge_pages[0][i]); |
| 583 | | image_battery_save(image, cartridge_pages[0] + 0x800, 0x1000); |
| 584 | | memset(cartridge_pages[0] + 0x800, 0, 0x1000); |
| 585 | | } |
| 586 | | break; |
| 587 | | case SLOT_MBX: |
| 588 | | if (slot_type[id] == SLOT_MBX) |
| 589 | | cartridge_mbx = FALSE; |
| 590 | | /* maybe we should insert some code to save the memory contents... */ |
| 591 | | break; |
| 592 | | case SLOT_CROM: |
| 593 | | if (ti99_model == model_99_8) |
| 594 | | { |
| 595 | | if (cartridge_minimemory) |
| 596 | | /* Don't wipe the RAM before it is saved. */ |
| 597 | | memset(cartridge_pages_8[0], 0, 0x1000); |
| 598 | | else |
| 599 | | memset(cartridge_pages_8[0], 0, 0x2000); |
| 600 | | } |
| 601 | | else |
| 602 | | { |
| 603 | | if (cartridge_minimemory) |
| 604 | | memset(cartridge_pages[0], 0, 0x1000); |
| 605 | | else |
| 606 | | memset(cartridge_pages[0], 0, 0x2000); |
| 607 | | } |
| 608 | | break; |
| 609 | | |
| 610 | | case SLOT_DROM: |
| 611 | | cartridge_paged = FALSE; |
| 612 | | if (ti99_model == model_99_8) |
| 613 | | { |
| 614 | | current_page_ptr_8 = cartridge_pages_8[0]; |
| 615 | | } |
| 616 | | else |
| 617 | | { |
| 618 | | current_page_ptr = cartridge_pages[0]; |
| 619 | | } |
| 620 | | break; |
| 621 | | } |
| 622 | | |
| 623 | | slot_type[id] = SLOT_EMPTY; |
| 624 | | } |
| 625 | | |
| 626 | 361 | static const TMS9928a_interface tms9918_interface = |
| 627 | 362 | { |
| 628 | 363 | TMS99x8, |
| r4596 | r4597 | |
| 683 | 418 | |
| 684 | 419 | void ti99_common_init(running_machine *machine, const TMS9928a_interface *gfxparm) |
| 685 | 420 | { |
| 686 | | if (gfxparm!=0) TMS9928A_configure(gfxparm); |
| 421 | if (gfxparm != 0) |
| 422 | TMS9928A_configure(gfxparm); |
| 687 | 423 | |
| 688 | 424 | /* Initialize all. Actually, at this point, we don't know |
| 689 | 425 | how the switches are set. Later we use the configuration switches to |
| r4596 | r4597 | |
| 694 | 430 | ti99_rs232_init(machine); |
| 695 | 431 | ti99_hsgpl_init(machine); |
| 696 | 432 | ti99_usbsm_init(machine); |
| 433 | |
| 434 | /* Find the cartslot device and cache it. This is a string search, |
| 435 | and we don't want to repeat it on each memory access. */ |
| 436 | cartslots = devtag_get_device(machine, "ti99_multicart"); |
| 437 | assert(cartslots != NULL); |
| 697 | 438 | } |
| 698 | 439 | |
| 699 | 440 | |
| r4596 | r4597 | |
| 709 | 450 | if (ti99_model == model_99_8) |
| 710 | 451 | { |
| 711 | 452 | /* ... */ |
| 712 | | ti99_8_CRUS = 1; /* ??? maybe there is a pull-up */ |
| 453 | ti99_8_enable_rom_and_ports = 1; /* ??? maybe there is a pull-up */ |
| 454 | /* MZ: already setting this in driver init, otherwise machine locks up */ |
| 713 | 455 | } |
| 714 | 456 | else if (ti99_model == model_99_4p) |
| 715 | 457 | { |
| r4596 | r4597 | |
| 726 | 468 | memory_set_bankptr(machine, 1, memory_region(machine, "maincpu") + offset_sram); |
| 727 | 469 | } |
| 728 | 470 | |
| 729 | | if (ti99_model != model_99_4p) |
| 730 | | { /* reset cartridge mapper */ |
| 471 | /* if (ti99_model != model_99_4p) |
| 472 | { |
| 731 | 473 | if (ti99_model == model_99_8) |
| 732 | 474 | current_page_ptr_8 = cartridge_pages_8[0]; |
| 733 | 475 | else |
| 734 | 476 | current_page_ptr = cartridge_pages[0]; |
| 735 | | } |
| 477 | } */ |
| 736 | 478 | |
| 737 | 479 | if (!has_evpc) TMS9928A_reset(); |
| 738 | 480 | else v9938_reset(0); |
| r4596 | r4597 | |
| 775 | 517 | if (ti99_model == model_99_4p) |
| 776 | 518 | ti99_4p_internal_dsr_reset(machine); |
| 777 | 519 | |
| 778 | | if (has_speech) |
| 520 | if (has_speech) |
| 779 | 521 | { |
| 780 | 522 | static const spchroms_interface speech_intf = { region_speech_rom }; |
| 781 | 523 | |
| r4596 | r4597 | |
| 789 | 531 | } |
| 790 | 532 | else |
| 791 | 533 | { |
| 792 | | if (ti99_model != model_99_8) |
| 793 | | { |
| 794 | | memory_install_read16_handler(space, 0x9000, 0x93ff, 0, 0, ti99_nop_8_r); |
| 795 | | memory_install_write16_handler(space, 0x9400, 0x97ff, 0, 0, ti99_nop_8_w); |
| 796 | | } |
| 534 | /* which is never true for TI-99/8 */ |
| 535 | memory_install_read16_handler(space, 0x9000, 0x93ff, 0, 0, ti99_nop_8_r); |
| 536 | memory_install_write16_handler(space, 0x9400, 0x97ff, 0, 0, ti99_nop_8_w); |
| 797 | 537 | } |
| 538 | /* Check whether we have locked the cartslot. */ |
| 539 | lock_cartridge_slot(cartslots, (input_port_read(machine, "CFG") >> config_cartslot_bit) & config_cartslot_mask); |
| 798 | 540 | |
| 799 | 541 | switch (xRAM_kind) |
| 800 | 542 | { |
| r4596 | r4597 | |
| 953 | 695 | READ16_HANDLER ( ti99_nop_8_r ) |
| 954 | 696 | { |
| 955 | 697 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 698 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 956 | 699 | |
| 957 | 700 | return (0); |
| 958 | 701 | } |
| r4596 | r4597 | |
| 960 | 703 | WRITE16_HANDLER ( ti99_nop_8_w ) |
| 961 | 704 | { |
| 962 | 705 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 706 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 963 | 707 | } |
| 964 | 708 | |
| 965 | 709 | /* |
| 966 | | TI-99 cartridge port: attached to the 8-bit bus. |
| 967 | | |
| 968 | | Cartridges are usually made of ROM, through a few cartridges include some |
| 969 | | RAM as well. Bank switching is common: I know three banking schemes, |
| 970 | | namely TI, MBX and Supercart. The TI scheme writes a dummy value in |
| 971 | | cartridge space, and the write address gives the bank number. The MBX |
| 972 | | scheme has a cartridge bank register at 0x6fff. I think the Supercart |
| 973 | | scheme has a cartridge bank register in CRU space, but I don't what the |
| 974 | | register address is, and it is therefore not emulated. |
| 975 | | |
| 976 | | HSGPL maps here, too, in order to emulate cartridge ROM/RAM. |
| 977 | | */ |
| 978 | | READ16_HANDLER ( ti99_cart_r ) |
| 979 | | { |
| 980 | | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 981 | | |
| 982 | | if (hsgpl_crdena) |
| 983 | | /* hsgpl is enabled */ |
| 984 | | return ti99_hsgpl_rom6_r(space, offset, mem_mask); |
| 985 | | |
| 986 | | if (cartridge_mbx && (offset >= 0x0600) && (offset <= 0x07fe)) |
| 987 | | return (cartridge_pages[0])[offset]; |
| 988 | | |
| 989 | | return current_page_ptr[offset]; |
| 990 | | } |
| 991 | | |
| 992 | | WRITE16_HANDLER ( ti99_cart_w ) |
| 993 | | { |
| 994 | | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 995 | | |
| 996 | | if (hsgpl_crdena) |
| 997 | | /* hsgpl is enabled */ |
| 998 | | ti99_hsgpl_rom6_w(space, offset, data, mem_mask); |
| 999 | | else if (cartridge_minimemory && offset >= 0x800) |
| 1000 | | /* handle minimem RAM */ |
| 1001 | | COMBINE_DATA(current_page_ptr+offset); |
| 1002 | | else if (cartridge_mbx) |
| 1003 | | { /* handle MBX cart */ |
| 1004 | | /* RAM in 0x6c00-0x6ffd (presumably non-paged) */ |
| 1005 | | /* mapper at 0x6ffe */ |
| 1006 | | if ((offset >= 0x0600) && (offset <= 0x07fe)) |
| 1007 | | COMBINE_DATA(cartridge_pages[0]+offset); |
| 1008 | | else if ((offset == 0x07ff) && ACCESSING_BITS_8_15) |
| 1009 | | current_page_ptr = cartridge_pages[cartridge_paged ? ((data >> 8) & 1) : 0]; |
| 1010 | | } |
| 1011 | | else if (cartridge_paged) |
| 1012 | | /* handle pager */ |
| 1013 | | current_page_ptr = cartridge_pages[offset & 1]; |
| 1014 | | } |
| 1015 | | |
| 1016 | | /* |
| 1017 | 710 | 99/4p cartridge space: mapped either to internal ROM6 or to HSGPL. |
| 1018 | 711 | */ |
| 1019 | 712 | READ16_HANDLER ( ti99_4p_cart_r ) |
| r4596 | r4597 | |
| 1022 | 715 | return ti99_4p_internal_ROM6[offset]; |
| 1023 | 716 | |
| 1024 | 717 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 718 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 1025 | 719 | |
| 1026 | 720 | if (hsgpl_crdena) |
| 1027 | 721 | /* hsgpl is enabled */ |
| r4596 | r4597 | |
| 1039 | 733 | } |
| 1040 | 734 | |
| 1041 | 735 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 736 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 1042 | 737 | |
| 1043 | 738 | if (hsgpl_crdena) |
| 1044 | 739 | /* hsgpl is enabled */ |
| r4596 | r4597 | |
| 1081 | 776 | WRITE16_HANDLER ( ti99_wsnd_w ) |
| 1082 | 777 | { |
| 1083 | 778 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 779 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 1084 | 780 | |
| 1085 | 781 | sn76496_w(devtag_get_device(space->machine, "sn76496"), offset, (data >> 8) & 0xff); |
| 1086 | 782 | } |
| r4596 | r4597 | |
| 1091 | 787 | READ16_HANDLER ( ti99_rvdp_r ) |
| 1092 | 788 | { |
| 1093 | 789 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 790 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 1094 | 791 | |
| 1095 | 792 | if (offset & 1) |
| 1096 | 793 | { /* read VDP status */ |
| r4596 | r4597 | |
| 1108 | 805 | WRITE16_HANDLER ( ti99_wvdp_w ) |
| 1109 | 806 | { |
| 1110 | 807 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 808 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 1111 | 809 | |
| 1112 | 810 | if (offset & 1) |
| 1113 | 811 | { /* write VDP address */ |
| r4596 | r4597 | |
| 1125 | 823 | READ16_HANDLER ( ti99_rv38_r ) |
| 1126 | 824 | { |
| 1127 | 825 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 826 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 1128 | 827 | |
| 1129 | 828 | if (offset & 1) |
| 1130 | 829 | { /* read VDP status */ |
| r4596 | r4597 | |
| 1142 | 841 | WRITE16_HANDLER ( ti99_wv38_w ) |
| 1143 | 842 | { |
| 1144 | 843 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 844 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 1145 | 845 | |
| 1146 | 846 | switch (offset & 3) |
| 1147 | 847 | { |
| r4596 | r4597 | |
| 1217 | 917 | tms5220_data_w(devtag_get_device(space->machine, "tms5220"), offset, (data >> 8) & 0xff); |
| 1218 | 918 | } |
| 1219 | 919 | |
| 920 | static UINT8 GROM_dataread(void) |
| 921 | { |
| 922 | UINT8 reply; |
| 923 | if (console_GROMs.addr >= 0x6000) |
| 924 | { |
| 925 | /* Pass the (one and only) program counter for GROMs. The |
| 926 | buffer is set and used in the cartridge chip. */ |
| 927 | reply = cartridge_grom_read(cartslots, console_GROMs.addr-0x6000); |
| 928 | } |
| 929 | else |
| 930 | { |
| 931 | /* GROMs are buffered. Data is retrieved from a buffer, |
| 932 | while the buffer is replaced with the next cell |
| 933 | content. */ |
| 934 | reply = console_GROMs.buf; |
| 935 | |
| 936 | /* Get next value, put it in buffer. Note that the |
| 937 | GROM wraps at 8K boundaries. */ |
| 938 | console_GROMs.buf = console_GROMs.data_ptr[console_GROMs.addr]; |
| 939 | } |
| 940 | |
| 941 | // printf("GROM address = %04x, reply = %02x\n", console_GROMs.addr, reply>>8); |
| 942 | /* The program counter wraps at each GROM chip size (8K), |
| 943 | so 0x5fff + 1 = 0x4000. */ |
| 944 | console_GROMs.addr = ((console_GROMs.addr + 1) & 0x1FFF) | (console_GROMs.addr & 0xE000); |
| 945 | |
| 946 | /* Reset the read and write address flipflops. */ |
| 947 | console_GROMs.raddr_LSB = console_GROMs.waddr_LSB = FALSE; |
| 948 | |
| 949 | return reply; |
| 950 | } |
| 951 | |
| 1220 | 952 | /* |
| 1221 | 953 | GPL read |
| 1222 | 954 | */ |
| 1223 | | READ16_HANDLER ( ti99_rgpl_r ) |
| 955 | READ16_HANDLER ( ti99_grom_r ) |
| 1224 | 956 | { |
| 1225 | | int reply; |
| 957 | UINT16 reply; |
| 1226 | 958 | |
| 1227 | | |
| 1228 | 959 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4 /*20+3*/); /* from 4 to 23? */ |
| 960 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 1229 | 961 | |
| 962 | /* This implementation features a multislot cartridge system which |
| 963 | is based on multiple GROM base addresses. The standard base |
| 964 | is >9800 (slot 0). When we access the port >9804, we switch to |
| 965 | slot 1, >9808 is slot 2, ... >983C is slot 15. Although theoretically |
| 966 | we could address up to 256 banks, the TI operating system does not |
| 967 | check more than 16 banks. |
| 968 | Cartridges may also contain ROMs which need to be banked |
| 969 | simultaneously. We use the cartridge slot number to swap the ROM at |
| 970 | >6000, or RAM if available. I don't know whether this is the way |
| 971 | Texas Instruments envisaged it in the OS, but it is the only |
| 972 | plausible way to allow for GROM+ROM cartridges. |
| 973 | Note that some cartridges may have programming flaws which only |
| 974 | appear when the cartridge is used in a higher-numbered slot. |
| 975 | Parsec is one example which only runs in slot 0 as the |
| 976 | programmers hard-coded an access to GROM port 0. Note: This *may* |
| 977 | be worked around if we make sure that switching only occurs |
| 978 | when the address is set, not when data is read or written. But |
| 979 | it's not clear whether this has unwanted side effects. |
| 980 | */ |
| 981 | |
| 982 | /* Activates a slot in the multi-cartridge extender. */ |
| 983 | cartridge_slot_set(cartslots, (offset & 0x01fe)/2); |
| 984 | |
| 1230 | 985 | if (offset & 1) |
| 1231 | | { /* read GPL address */ |
| 1232 | | /* the console GROMs are always affected */ |
| 1233 | | console_GROMs.waddr_LSB = FALSE; /* right??? */ |
| 986 | { /* Read GROM address |
| 987 | We only have one GROM program counter for the console GROMs |
| 988 | and all cartridge GROMs in all banks(!). Hardware |
| 989 | implementations must take this into account as well. Thus, |
| 990 | we use a structure here in the console, rather than separate |
| 991 | counters in each GROM chip. */ |
| 992 | |
| 993 | /* When reading, reset the hi/lo flag byte for writing. |
| 994 | TODO: Verify this with a real machine. */ |
| 995 | console_GROMs.waddr_LSB = FALSE; |
| 1234 | 996 | |
| 997 | /* Address reading is done in two steps; first, the high byte |
| 998 | is transferred, then the low byte. */ |
| 1235 | 999 | if (console_GROMs.raddr_LSB) |
| 1236 | 1000 | { |
| 1001 | /* second pass */ |
| 1237 | 1002 | reply = (console_GROMs.addr << 8) & 0xff00; |
| 1238 | 1003 | console_GROMs.raddr_LSB = FALSE; |
| 1239 | 1004 | } |
| 1240 | 1005 | else |
| 1241 | 1006 | { |
| 1007 | /* first pass */ |
| 1242 | 1008 | reply = console_GROMs.addr & 0xff00; |
| 1243 | 1009 | console_GROMs.raddr_LSB = TRUE; |
| 1244 | 1010 | } |
| 1245 | 1011 | } |
| 1246 | 1012 | else |
| 1247 | | { /* read GPL data */ |
| 1248 | | /* the console GROMs are always affected */ |
| 1249 | | reply = ((int) console_GROMs.buf) << 8; /* retreive buffer */ |
| 1250 | | |
| 1251 | | /* read ahead */ |
| 1252 | | console_GROMs.buf = console_GROMs.data_ptr[console_GROMs.addr]; |
| 1253 | | console_GROMs.addr = ((console_GROMs.addr + 1) & 0x1FFF) | (console_GROMs.addr & 0xE000); |
| 1254 | | console_GROMs.raddr_LSB = console_GROMs.waddr_LSB = FALSE; |
| 1013 | { |
| 1014 | /* Read GROM data */ |
| 1015 | reply = ((UINT16)GROM_dataread()) << 8; |
| 1255 | 1016 | } |
| 1256 | 1017 | |
| 1257 | 1018 | if (hsgpl_crdena) |
| r4596 | r4597 | |
| 1264 | 1025 | /* |
| 1265 | 1026 | GPL write |
| 1266 | 1027 | */ |
| 1267 | | WRITE16_HANDLER ( ti99_wgpl_w ) |
| 1028 | WRITE16_HANDLER ( ti99_grom_w ) |
| 1268 | 1029 | { |
| 1269 | 1030 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4/*20+3*/); /* from 4 to 23? */ |
| 1031 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 1270 | 1032 | |
| 1033 | /* Activates a slot in the multi-cartridge extender. */ |
| 1034 | cartridge_slot_set(cartslots, (offset & 0x01fe)/2); |
| 1035 | |
| 1036 | // 1001 1wbb bbbb bbr0 |
| 1037 | |
| 1271 | 1038 | if (offset & 1) |
| 1272 | | { /* write GPL address */ |
| 1273 | | /* the console GROMs are always affected */ |
| 1039 | { /* write GROM address */ |
| 1040 | /* see comments above */ |
| 1274 | 1041 | console_GROMs.raddr_LSB = FALSE; |
| 1275 | | |
| 1042 | |
| 1043 | /* Implements the internal flipflop. |
| 1044 | The Editor/Assembler manuals says that the current address |
| 1045 | plus one is returned. This effect is properly emulated |
| 1046 | as we are using a read-ahead buffer. |
| 1047 | */ |
| 1276 | 1048 | if (console_GROMs.waddr_LSB) |
| 1277 | 1049 | { |
| 1050 | /* Accept low byte (2nd write) */ |
| 1278 | 1051 | console_GROMs.addr = (console_GROMs.addr & 0xFF00) | ((data >> 8) & 0xFF); |
| 1279 | | |
| 1280 | | /* read ahead */ |
| 1281 | | console_GROMs.buf = console_GROMs.data_ptr[console_GROMs.addr]; |
| 1282 | | console_GROMs.addr = ((console_GROMs.addr + 1) & 0x1FFF) | (console_GROMs.addr & 0xE000); |
| 1283 | | |
| 1052 | |
| 1053 | /* Setting the address causes a new read, putting the |
| 1054 | value into the buffer. We don't need the value here. */ |
| 1055 | GROM_dataread(); |
| 1284 | 1056 | console_GROMs.waddr_LSB = FALSE; |
| 1285 | 1057 | } |
| 1286 | 1058 | else |
| 1287 | 1059 | { |
| 1060 | /* Accept high byte (1st write) */ |
| 1288 | 1061 | console_GROMs.addr = (data & 0xFF00) | (console_GROMs.addr & 0xFF); |
| 1289 | | |
| 1290 | 1062 | console_GROMs.waddr_LSB = TRUE; |
| 1291 | 1063 | } |
| 1292 | 1064 | |
| 1293 | 1065 | } |
| 1294 | 1066 | else |
| 1295 | | { /* write GPL data */ |
| 1067 | { |
| 1068 | /* write GROM data */ |
| 1296 | 1069 | /* the console GROMs are always affected */ |
| 1297 | | /* BTW, console GROMs are never GRAMs, therefore there is no need to |
| 1298 | | actually write anything */ |
| 1299 | | /* read ahead */ |
| 1300 | | console_GROMs.buf = console_GROMs.data_ptr[console_GROMs.addr]; |
| 1301 | | console_GROMs.addr = ((console_GROMs.addr + 1) & 0x1FFF) | (console_GROMs.addr & 0xE000); |
| 1070 | /* BTW, console GROMs are never GRAMs, therefore there is no |
| 1071 | need to actually write anything, so we just read ahead |
| 1072 | TODO: There could be cartridges with GRAM, so this must be |
| 1073 | fixed. |
| 1074 | */ |
| 1075 | GROM_dataread(); |
| 1302 | 1076 | console_GROMs.raddr_LSB = console_GROMs.waddr_LSB = FALSE; |
| 1303 | | |
| 1304 | 1077 | } |
| 1305 | 1078 | |
| 1306 | 1079 | if (hsgpl_crdena) |
| r4596 | r4597 | |
| 1308 | 1081 | } |
| 1309 | 1082 | |
| 1310 | 1083 | /* |
| 1311 | | GPL read |
| 1084 | GROM read for TI-99/8 |
| 1085 | For comments, see the handler for TI-99/4A |
| 1312 | 1086 | */ |
| 1313 | | READ16_HANDLER ( ti99_4p_rgpl_r ) |
| 1087 | READ8_HANDLER ( ti99_grom_r8 ) |
| 1314 | 1088 | { |
| 1089 | UINT8 reply; |
| 1090 | |
| 1091 | cpu_adjust_icount(space->machine->cpu[0],-4); |
| 1092 | |
| 1093 | /* Activates a slot in the multi-cartridge extender. */ |
| 1094 | // 1001 1wbb bbbb bbr0 |
| 1095 | cartridge_slot_set(cartslots, (offset & 0x03fc)/4); |
| 1096 | |
| 1097 | if (offset & 2) |
| 1098 | { |
| 1099 | console_GROMs.waddr_LSB = FALSE; |
| 1100 | |
| 1101 | if (console_GROMs.raddr_LSB) |
| 1102 | { |
| 1103 | reply = console_GROMs.addr & 0x00ff; |
| 1104 | console_GROMs.raddr_LSB = FALSE; |
| 1105 | } |
| 1106 | else |
| 1107 | { |
| 1108 | reply = (console_GROMs.addr>>8) & 0x00ff; |
| 1109 | console_GROMs.raddr_LSB = TRUE; |
| 1110 | } |
| 1111 | } |
| 1112 | else |
| 1113 | reply = GROM_dataread(); |
| 1114 | |
| 1115 | return reply; |
| 1116 | } |
| 1117 | |
| 1118 | /* |
| 1119 | GROM write for TI-99/8 |
| 1120 | For comments, see the handler for TI-99/4A |
| 1121 | */ |
| 1122 | WRITE8_HANDLER ( ti99_grom_w8 ) |
| 1123 | { |
| 1124 | cpu_adjust_icount(space->machine->cpu[0],-4/*20+3*/); /* from 4 to 23? */ |
| 1125 | |
| 1126 | /* Activates a slot in the multi-cartridge extender. */ |
| 1127 | cartridge_slot_set(cartslots, (offset & 0x03fc)/4); |
| 1128 | |
| 1129 | if (offset & 2) |
| 1130 | { |
| 1131 | console_GROMs.raddr_LSB = FALSE; |
| 1132 | if (console_GROMs.waddr_LSB) |
| 1133 | { |
| 1134 | console_GROMs.addr = (console_GROMs.addr & 0xFF00) | (data & 0xFF); |
| 1135 | |
| 1136 | GROM_dataread(); |
| 1137 | console_GROMs.waddr_LSB = FALSE; |
| 1138 | } |
| 1139 | else |
| 1140 | { |
| 1141 | console_GROMs.addr = ((data<<8) & 0xFF00) | (console_GROMs.addr & 0xFF); |
| 1142 | console_GROMs.waddr_LSB = TRUE; |
| 1143 | } |
| 1144 | |
| 1145 | } |
| 1146 | else |
| 1147 | { |
| 1148 | GROM_dataread(); |
| 1149 | console_GROMs.raddr_LSB = console_GROMs.waddr_LSB = FALSE; |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | |
| 1154 | /* |
| 1155 | GROM read for TI-99/4p |
| 1156 | */ |
| 1157 | READ16_HANDLER ( ti99_4p_grom_r ) |
| 1158 | { |
| 1315 | 1159 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); /* HSGPL is located on 8-bit bus? */ |
| 1160 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 1316 | 1161 | |
| 1317 | 1162 | return /*hsgpl_crdena ?*/ ti99_hsgpl_gpl_r(space, offset, mem_mask) /*: 0*/; |
| 1318 | 1163 | } |
| 1319 | 1164 | |
| 1320 | 1165 | /* |
| 1321 | | GPL write |
| 1166 | GROM write |
| 1322 | 1167 | */ |
| 1323 | | WRITE16_HANDLER ( ti99_4p_wgpl_w ) |
| 1168 | WRITE16_HANDLER ( ti99_4p_grom_w ) |
| 1324 | 1169 | { |
| 1325 | 1170 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); /* HSGPL is located on 8-bit bus? */ |
| 1171 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 1326 | 1172 | |
| 1327 | 1173 | /*if (hsgpl_crdena)*/ |
| 1328 | 1174 | ti99_hsgpl_gpl_w(space, offset, data, mem_mask); |
| r4596 | r4597 | |
| 1334 | 1180 | #pragma mark 99/8 MEMORY HANDLERS |
| 1335 | 1181 | #endif |
| 1336 | 1182 | |
| 1337 | | READ8_HANDLER ( ti99_8_r ) |
| 1183 | READ8_HANDLER( ti99_8_r ) |
| 1338 | 1184 | { |
| 1185 | /* Set the page. Page size is 4 KiB; page number are the high 4 bits. */ |
| 1339 | 1186 | int page = offset >> 12; |
| 1340 | 1187 | UINT32 mapper_reg; |
| 1341 | | int reply = 0; |
| 1188 | UINT8 reply = 0; |
| 1342 | 1189 | |
| 1343 | | /* 03-Apr-2007 - hack because this seems to be called on startup */ |
| 1344 | | if (!xRAM_ptr_8) |
| 1345 | | return 0; |
| 1346 | | |
| 1347 | | if (ti99_8_CRUS) |
| 1190 | if (ti99_8_enable_rom_and_ports) |
| 1348 | 1191 | { |
| 1349 | | /* memory mapped ports enabled */ |
| 1192 | /* This is only important for address access 0000-1fff and |
| 1193 | 8000-9fff. Outside, the mapper mode is used. */ |
| 1350 | 1194 | if ((offset >= 0x0000) && (offset < 0x2000)) |
| 1351 | | /* ROM? */ |
| 1352 | | return ROM0_ptr_8[offset & 0x1fff]; |
| 1195 | { |
| 1196 | /* ROM */ |
| 1197 | reply = ROM0_ptr_8[offset & 0x1fff]; |
| 1198 | return reply; |
| 1199 | } |
| 1353 | 1200 | else if ((offset >= 0x8000) && (offset < 0xa000)) |
| 1354 | 1201 | { |
| 1355 | 1202 | /* ti99 scratch pad and memory-mapped registers */ |
| r4596 | r4597 | |
| 1357 | 1204 | switch ((offset - 0x8000) >> 10) |
| 1358 | 1205 | { |
| 1359 | 1206 | case 0: |
| 1360 | | /* RAM */ |
| 1207 | /* RAM: >8000 - >83ff */ |
| 1361 | 1208 | reply = sRAM_ptr_8[offset & 0x1fff]; |
| 1362 | 1209 | break; |
| 1363 | 1210 | |
| 1364 | 1211 | case 1: |
| 1365 | | /* sound write + RAM */ |
| 1212 | /* >8400 - >840f: sound (cannot read) |
| 1213 | >8410 - >87ff: SRAM */ |
| 1366 | 1214 | if (offset >= 0x8410) |
| 1367 | 1215 | reply = sRAM_ptr_8[offset & 0x1fff]; |
| 1368 | 1216 | break; |
| r4596 | r4597 | |
| 1374 | 1222 | if (! (offset & 1)) |
| 1375 | 1223 | { |
| 1376 | 1224 | if (offset & 2) |
| 1377 | | /* read VDP status */ |
| 1225 | /* read VDP status >8802 */ |
| 1378 | 1226 | reply = TMS9928A_register_r(space, 0); |
| 1379 | 1227 | else |
| 1380 | | /* read VDP RAM */ |
| 1228 | /* read VDP RAM >8800 */ |
| 1381 | 1229 | reply = TMS9928A_vram_r(space, 0); |
| 1382 | 1230 | } |
| 1383 | 1231 | } |
| 1384 | 1232 | else |
| 1385 | 1233 | { |
| 1234 | /* Read mapper >8810 */ |
| 1386 | 1235 | reply = ti99_8_mapper_status; |
| 1387 | | |
| 1388 | 1236 | ti99_8_mapper_status = 0; |
| 1389 | 1237 | } |
| 1390 | 1238 | break; |
| 1391 | 1239 | |
| 1392 | 1240 | case 4: |
| 1393 | | /* speech read */ |
| 1241 | /* speech read: >9000 */ |
| 1394 | 1242 | if (! (offset & 1)) |
| 1395 | 1243 | { |
| 1396 | 1244 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-16*4); /* this is just a minimum, it can be more */ |
| r4596 | r4597 | |
| 1399 | 1247 | break; |
| 1400 | 1248 | |
| 1401 | 1249 | case 6: |
| 1402 | | /* GPL read */ |
| 1250 | /* GROM read: >9800 */ |
| 1403 | 1251 | if (! (offset & 1)) |
| 1404 | | reply = ti99_rgpl_r(space, offset >> 1, 0) >> 8; |
| 1252 | reply = ti99_grom_r8(space, offset); |
| 1405 | 1253 | break; |
| 1406 | 1254 | |
| 1407 | 1255 | default: |
| r4596 | r4597 | |
| 1434 | 1282 | default: |
| 1435 | 1283 | /* should never happen */ |
| 1436 | 1284 | case 0: |
| 1437 | | /* unassigned??? */ |
| 1285 | /* ff0000 - ff1fff: unassigned? */ |
| 1438 | 1286 | case 1: |
| 1439 | | /* ??? */ |
| 1287 | /* ff2000 - ff3fff: ? */ |
| 1440 | 1288 | case 4: |
| 1441 | | /* internal DSR ROM??? (normally enabled with a write to CRU >2700) */ |
| 1289 | /* ff8000 - ff9fff: internal DSR ROM? (normally enabled with a write to CRU >2700) */ |
| 1442 | 1290 | case 7: |
| 1443 | | /* ??? */ |
| 1291 | /* ffe000 - ffffff: ? */ |
| 1444 | 1292 | logerror("unmapped read page=%d offs=%d\n", (int) page, (int) offset); |
| 1445 | 1293 | break; |
| 1446 | 1294 | |
| 1447 | 1295 | case 2: |
| 1448 | | /* DSR space */ |
| 1296 | /* ff4000 - ff5fff: DSR space */ |
| 1449 | 1297 | reply = ti99_8_peb_r(space, offset & 0x1fff); |
| 1450 | 1298 | break; |
| 1451 | 1299 | |
| 1452 | 1300 | case 3: |
| 1453 | | /* cartridge space */ |
| 1301 | /* ff6000 - ff7fff: cartridge ROM space */ |
| 1454 | 1302 | offset &= 0x1fff; |
| 1455 | | #if 0 |
| 1456 | | if (hsgpl_crdena) |
| 1457 | | /* hsgpl is enabled */ |
| 1458 | | reply = ti99_hsgpl_rom6_r(offset, mem_mask); |
| 1459 | | else |
| 1460 | | #endif |
| 1461 | 1303 | |
| 1462 | | if (cartridge_mbx && (offset >= 0x0c00) && (offset <= 0x0ffd)) |
| 1463 | | reply = (cartridge_pages_8[0])[offset]; |
| 1464 | | else |
| 1465 | | reply = current_page_ptr_8[offset]; |
| 1304 | /* We do not support hsgpl here because it is a 16 bit |
| 1305 | system. Just check the cartridges. */ |
| 1306 | reply = ti99_multicart8_r(multicart8, offset); |
| 1466 | 1307 | break; |
| 1467 | 1308 | |
| 1468 | 1309 | case 5: |
| 1469 | | /* >2000 ROM (ROM1) */ |
| 1310 | /* ffa000 - ffbfff: >2000 ROM (ROM1) */ |
| 1470 | 1311 | reply = ROM1_ptr_8[offset & 0x1fff]; |
| 1471 | 1312 | break; |
| 1472 | 1313 | |
| 1473 | 1314 | case 6: |
| 1474 | | /* >6000 ROM */ |
| 1315 | /* ffc000 - ffdfff: >6000 ROM */ |
| 1475 | 1316 | reply = ROM3_ptr_8[offset & 0x1fff]; |
| 1476 | 1317 | break; |
| 1477 | 1318 | } |
| r4596 | r4597 | |
| 1485 | 1326 | int page = offset >> 12; |
| 1486 | 1327 | UINT32 mapper_reg; |
| 1487 | 1328 | |
| 1488 | | if (ti99_8_CRUS) |
| 1329 | if (ti99_8_enable_rom_and_ports) |
| 1489 | 1330 | { |
| 1490 | 1331 | /* memory mapped ports enabled */ |
| 1491 | 1332 | if ((offset >= 0x0000) && (offset < 0x2000)) |
| 1333 | { |
| 1492 | 1334 | /* ROM? */ |
| 1493 | 1335 | return; |
| 1336 | } |
| 1494 | 1337 | else if ((offset >= 0x8000) && (offset < 0xa000)) |
| 1495 | 1338 | { |
| 1496 | 1339 | /* ti99 scratch pad and memory-mapped registers */ |
| r4596 | r4597 | |
| 1583 | 1426 | case 7: |
| 1584 | 1427 | /* GPL write */ |
| 1585 | 1428 | if (! (offset & 1)) |
| 1586 | | ti99_wgpl_w(space, offset >> 1, data << 8, 0); |
| 1429 | ti99_grom_w8(space, offset, data); |
| 1587 | 1430 | break; |
| 1588 | 1431 | |
| 1589 | 1432 | default: |
| r4596 | r4597 | |
| 1595 | 1438 | } |
| 1596 | 1439 | |
| 1597 | 1440 | mapper_reg = ti99_8_mapper_regs[page]; |
| 1441 | |
| 1442 | /* 4 KiB page size */ |
| 1598 | 1443 | offset = (mapper_reg + (offset & 0x0fff)) & 0x00ffffff; |
| 1599 | 1444 | |
| 1600 | 1445 | /* test write protect */ |
| r4596 | r4597 | |
| 1628 | 1473 | |
| 1629 | 1474 | case 3: |
| 1630 | 1475 | /* cartridge space */ |
| 1631 | | offset &= 0x1fff; |
| 1632 | | #if 0 |
| 1633 | | if (hsgpl_crdena) |
| 1634 | | /* hsgpl is enabled */ |
| 1635 | | ti99_hsgpl_rom6_w(offset, data); |
| 1636 | | else |
| 1637 | | #endif |
| 1638 | | if (cartridge_minimemory && (offset >= 0x1000)) |
| 1639 | | /* handle minimem RAM */ |
| 1640 | | current_page_ptr_8[offset] = data; |
| 1641 | | else if (cartridge_mbx) |
| 1642 | | { /* handle MBX cart */ |
| 1643 | | /* RAM in 0x6c00-0x6ffd (presumably non-paged) */ |
| 1644 | | /* mapper at 0x6ffe */ |
| 1645 | | if ((offset >= 0x0c00) && (offset <= 0x0ffd)) |
| 1646 | | (cartridge_pages_8[0])[offset] = data; |
| 1647 | | else if (offset == 0x0ffe) |
| 1648 | | current_page_ptr_8 = cartridge_pages_8[cartridge_paged ? (data & 1) : 0]; |
| 1649 | | } |
| 1650 | | else if (cartridge_paged) |
| 1651 | | /* handle pager */ |
| 1652 | | current_page_ptr_8 = cartridge_pages_8[(offset & 2) >> 1]; |
| 1476 | /* We do not support HSGPL for the 99/8 at this time. */ |
| 1477 | ti99_multicart8_w(multicart8, offset & 0x1fff, data); |
| 1653 | 1478 | break; |
| 1654 | 1479 | |
| 1655 | 1480 | case 5: |
| r4596 | r4597 | |
| 1662 | 1487 | } |
| 1663 | 1488 | } |
| 1664 | 1489 | else |
| 1490 | { |
| 1665 | 1491 | logerror("unmapped write page=%d offs=%d\n", (int) page, (int) offset); |
| 1492 | } |
| 1666 | 1493 | } |
| 1667 | 1494 | |
| 1668 | 1495 | /*===========================================================================*/ |
| r4596 | r4597 | |
| 2393 | 2220 | |
| 2394 | 2221 | static WRITE8_DEVICE_HANDLER( ti99_8_WCRUS ) |
| 2395 | 2222 | { |
| 2396 | | ti99_8_CRUS = data; |
| 2223 | ti99_8_enable_rom_and_ports = data; |
| 2397 | 2224 | } |
| 2398 | 2225 | |
| 2399 | 2226 | static WRITE8_DEVICE_HANDLER( ti99_8_PTGEN ) |
| r4596 | r4597 | |
| 2619 | 2446 | static READ16_HANDLER ( ti99_TIxramlow_r ) |
| 2620 | 2447 | { |
| 2621 | 2448 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 2449 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 2622 | 2450 | |
| 2623 | 2451 | return xRAM_ptr[offset]; |
| 2624 | 2452 | } |
| r4596 | r4597 | |
| 2626 | 2454 | static WRITE16_HANDLER ( ti99_TIxramlow_w ) |
| 2627 | 2455 | { |
| 2628 | 2456 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 2457 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 2629 | 2458 | |
| 2630 | 2459 | COMBINE_DATA(xRAM_ptr + offset); |
| 2631 | 2460 | } |
| r4596 | r4597 | |
| 2634 | 2463 | static READ16_HANDLER ( ti99_TIxramhigh_r ) |
| 2635 | 2464 | { |
| 2636 | 2465 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 2466 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 2637 | 2467 | |
| 2638 | 2468 | return xRAM_ptr[offset+0x1000]; |
| 2639 | 2469 | } |
| r4596 | r4597 | |
| 2641 | 2471 | static WRITE16_HANDLER ( ti99_TIxramhigh_w ) |
| 2642 | 2472 | { |
| 2643 | 2473 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 2474 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 2644 | 2475 | |
| 2645 | 2476 | COMBINE_DATA(xRAM_ptr + offset+0x1000); |
| 2646 | 2477 | } |
| r4596 | r4597 | |
| 2723 | 2554 | static READ16_HANDLER ( ti99_sAMSxramlow_r ) |
| 2724 | 2555 | { |
| 2725 | 2556 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 2557 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 2726 | 2558 | |
| 2727 | 2559 | if (sAMS_mapper_on) |
| 2728 | 2560 | return xRAM_ptr[(offset&0x7ff)+sAMSlookup[(0x1000+offset)>>11]]; |
| r4596 | r4597 | |
| 2733 | 2565 | static WRITE16_HANDLER ( ti99_sAMSxramlow_w ) |
| 2734 | 2566 | { |
| 2735 | 2567 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 2568 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 2736 | 2569 | |
| 2737 | 2570 | if (sAMS_mapper_on) |
| 2738 | 2571 | COMBINE_DATA(xRAM_ptr + (offset&0x7ff)+sAMSlookup[(0x1000+offset)>>11]); |
| r4596 | r4597 | |
| 2744 | 2577 | static READ16_HANDLER ( ti99_sAMSxramhigh_r ) |
| 2745 | 2578 | { |
| 2746 | 2579 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 2580 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 2747 | 2581 | |
| 2748 | 2582 | if (sAMS_mapper_on) |
| 2749 | 2583 | return xRAM_ptr[(offset&0x7ff)+sAMSlookup[(0x5000+offset)>>11]]; |
| r4596 | r4597 | |
| 2754 | 2588 | static WRITE16_HANDLER ( ti99_sAMSxramhigh_w ) |
| 2755 | 2589 | { |
| 2756 | 2590 | cpu_adjust_icount(cputag_get_cpu(space->machine, "maincpu"),-4); |
| 2591 | // cpu_spinuntil_time(space->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 2757 | 2592 | |
| 2758 | 2593 | if (sAMS_mapper_on) |
| 2759 | 2594 | COMBINE_DATA(xRAM_ptr + (offset&0x7ff)+sAMSlookup[(0x5000+offset)>>11]); |
src/mess/devices/ti99cart.c
| r0 | r4597 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | ti99cart.c |
| 4 | |
| 5 | TI99 family cartridge management |
| 6 | |
| 7 | Michael Zapf, 2009 |
| 8 | |
| 9 | *********************************************************************/ |
| 10 | #include "driver.h" |
| 11 | #include "ti99cart.h" |
| 12 | #include "cartslot.h" |
| 13 | #include "machine/ti99_4x.h" |
| 14 | #include "multcart.h" |
| 15 | |
| 16 | typedef int assmfct(const device_config *); |
| 17 | |
| 18 | enum |
| 19 | { |
| 20 | TI99CARTINFO_FCT_6000_R = DEVINFO_FCT_DEVICE_SPECIFIC, /* read16_device_handler */ |
| 21 | TI99CARTINFO_FCT_6000_W, /* write16_device_handler */ |
| 22 | TI99CARTINFO_FCT_6000_R8, /* read8_device_handler */ |
| 23 | TI99CARTINFO_FCT_6000_W8, /* write16_device_handler */ |
| 24 | TI99CARTINFO_FCT_CRU_R, |
| 25 | TI99CARTINFO_FCT_CRU_W, |
| 26 | TI99CART_FCT_ASSM, |
| 27 | TI99CART_FCT_DISASSM |
| 28 | }; |
| 29 | |
| 30 | typedef enum _legacy_cart_t |
| 31 | { |
| 32 | LEG_CART_NONE, |
| 33 | LEG_CART_STD, |
| 34 | LEG_CART_EXB, |
| 35 | LEG_CART_MINI, |
| 36 | LEG_CART_MBX |
| 37 | } legacy_cart_t; |
| 38 | |
| 39 | struct _ti99_multicart_t |
| 40 | { |
| 41 | /* Reserves space for all cartridges. This is also used in the legacy |
| 42 | cartridge system, but only for slot 0. */ |
| 43 | cartridge_t cartridge[NUMBER_OF_CARTRIDGE_SLOTS]; |
| 44 | |
| 45 | /* Determines which slot is currently active. This value is changed when there |
| 46 | are accesses to other GROM base addresses. */ |
| 47 | int active_slot; |
| 48 | |
| 49 | /* Used in order to enforce a special slot. This value is retrieved |
| 50 | from the dipswitch setting. A value of -1 means automatic, that is, |
| 51 | the grom base switch is used. Values 0 .. max refer to the |
| 52 | respective slot. */ |
| 53 | int fixed_slot; |
| 54 | |
| 55 | /* Holds the highest index of a cartridge being plugged in plus one. |
| 56 | If we only have one cartridge inserted, we don't want to get a |
| 57 | selection option, so we just mirror the memory contents. */ |
| 58 | int next_free_slot; |
| 59 | |
| 60 | /* Counts the number of slots which currently contain legacy format |
| 61 | cartridge images. */ |
| 62 | int legacy_slots; |
| 63 | |
| 64 | /* Counts the number of slots which currently contain new format |
| 65 | cartridge images. */ |
| 66 | int multi_slots; |
| 67 | |
| 68 | /* Legacy mode. Stores the slot number where the cartridge part is mounted. |
| 69 | Index is from slotc_type_t. */ |
| 70 | int legacy_slotnumber[5]; |
| 71 | }; |
| 72 | typedef struct _ti99_multicart_t ti99_multicart_t; |
| 73 | |
| 74 | #define AUTO -1 |
| 75 | |
| 76 | typedef enum _slotc_type_t |
| 77 | { |
| 78 | SLOTC_EMPTY = -1, |
| 79 | SLOTC_GROM = 0, |
| 80 | SLOTC_CROM = 1, |
| 81 | SLOTC_DROM = 2, |
| 82 | SLOTC_MINIMEM = 3, |
| 83 | SLOTC_MBX = 4 |
| 84 | } slotc_type_t; |
| 85 | |
| 86 | /* Function declaration; the function itself is in the later part of this file. */ |
| 87 | static UINT8 cartridge_grom_read_legacy(const device_config *cartsys, int cart_offset); |
| 88 | static void unload_legacy(const device_config *image); |
| 89 | static int load_legacy(const device_config *image); |
| 90 | |
| 91 | /* Access to the pcb. Contained in the token of the pcb instance. */ |
| 92 | struct _ti99_pcb_t |
| 93 | { |
| 94 | /* Read function for this cartridge. */ |
| 95 | read16_device_func read; |
| 96 | |
| 97 | /* Write function for this cartridge. */ |
| 98 | write16_device_func write; |
| 99 | |
| 100 | /* Read function for this cartridge, TI-99/8. */ |
| 101 | read8_device_func read8; |
| 102 | |
| 103 | /* Write function for this cartridge, TI-99/8. */ |
| 104 | write8_device_func write8; |
| 105 | |
| 106 | /* Read function for this cartridge, CRU. */ |
| 107 | read8_device_func cruread; |
| 108 | |
| 109 | /* Write function for this cartridge, CRU. */ |
| 110 | write8_device_func cruwrite; |
| 111 | |
| 112 | /* Link up to the cartridge structure which contains this pcb. */ |
| 113 | cartridge_t *cartridge; |
| 114 | |
| 115 | /* Function to assemble this cartridge. */ |
| 116 | assmfct *assemble; |
| 117 | |
| 118 | /* Function to disassemble this cartridge. */ |
| 119 | assmfct *disassemble; |
| 120 | }; |
| 121 | typedef struct _ti99_pcb_t ti99_pcb_t; |
| 122 | |
| 123 | static int in_legacy_mode(const device_config *device) |
| 124 | { |
| 125 | ti99_multicart_t *cartslots = (ti99_multicart_t *)device->token; |
| 126 | if ((cartslots->legacy_slots>0) && (cartslots->multi_slots==0)) |
| 127 | return TRUE; |
| 128 | return FALSE; |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | Activates a slot in the multi-cartridge extender. |
| 133 | Setting the slot is done by accessing the GROM ports using a |
| 134 | specific address: |
| 135 | |
| 136 | slot n: read data (read address, write data, write address) |
| 137 | |
| 138 | slot 0: 0x9800 (0x9802, 0x9c00, 0x9c02) : cartridge1 |
| 139 | slot 1: 0x9804 (0x9806, 0x9c04, 0x9c06) : cartridge2 |
| 140 | ... |
| 141 | slot 15: 0x983c (0x983e, 0x9c3c, 0x9c3e) : cartridge16 |
| 142 | |
| 143 | The following addresses are theoretically available, but the |
| 144 | built-in OS does not use them; i.e. cartridges will not be |
| 145 | included in the selection list, and their features will not be |
| 146 | found by lookup, but they could be accessed directly by user |
| 147 | programs. |
| 148 | slot 16: 0x9840 (0x9842, 0x9c40, 0x9c42) |
| 149 | ... |
| 150 | slot 255: 0x9bfc (0x9bfe, 0x9ffc, 0x9ffe) |
| 151 | |
| 152 | Setting the GROM base should select one cartridge, but the ROMs in the |
| 153 | CPU space must also be switched. As there is no known special mechanism |
| 154 | we assume that by switching the GROM base, the ROM is automatically |
| 155 | switched. |
| 156 | |
| 157 | Caution: This means that cartridges which do not have at least one |
| 158 | GROM cannot be switched with this mechanism. |
| 159 | |
| 160 | We assume that the slot number is already calculated in the caller: |
| 161 | slotnumber>=0 && slotnumber<=255 |
| 162 | |
| 163 | NOTE: The OS will stop searching when it finds slots 1 and 2 empty. |
| 164 | Interestingly, cartridge subroutines are found nevertheless, even when |
| 165 | the cartridge is plugged into a higher slot. |
| 166 | */ |
| 167 | void cartridge_slot_set(const device_config *cartsys, int slotnumber) |
| 168 | { |
| 169 | ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token; |
| 170 | assert(slotnumber>=0 && slotnumber<=255); |
| 171 | // if (cartslots->active_slot != slotnumber) printf("Setting cartslot to %d\n", slotnumber); |
| 172 | if (cartslots->fixed_slot==AUTO) |
| 173 | cartslots->active_slot = slotnumber; |
| 174 | else |
| 175 | cartslots->active_slot = cartslots->fixed_slot; |
| 176 | } |
| 177 | |
| 178 | /* |
| 179 | Allows to manually lock the cartslot system to a specific slot. |
| 180 | Called from the machine driver, taking the dipswitch setting. |
| 181 | We take slot numbers from 0 (automatic mode) to the maximum. |
| 182 | */ |
| 183 | void lock_cartridge_slot(const device_config *cartsys, int slotnumber) |
| 184 | { |
| 185 | ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token; |
| 186 | assert(slotnumber>=0 && slotnumber<=255); |
| 187 | cartslots->fixed_slot = slotnumber-1; /* auto = -1 */ |
| 188 | } |
| 189 | |
| 190 | static int slot_is_empty(const device_config *cartsys, int slotnumber) |
| 191 | { |
| 192 | cartridge_t *cart; |
| 193 | ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token; |
| 194 | |
| 195 | cart = &cartslots->cartridge[slotnumber]; |
| 196 | |
| 197 | if ((cart->rom_size==0) && (cart->ram_size==0) && (cart->grom_size==0)) |
| 198 | return TRUE; |
| 199 | return FALSE; |
| 200 | } |
| 201 | |
| 202 | static void clear_slot(const device_config *cartsys, int slotnumber) |
| 203 | { |
| 204 | cartridge_t *cart; |
| 205 | ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token; |
| 206 | |
| 207 | cart = &cartslots->cartridge[slotnumber]; |
| 208 | |
| 209 | cart->rom_size = cart->ram_size = cart->grom_size = 0; |
| 210 | cart->rom_ptr = NULL; |
| 211 | cart->rom2_ptr = NULL; |
| 212 | cart->ram_ptr = NULL; |
| 213 | cart->grom_ptr = NULL; |
| 214 | } |
| 215 | |
| 216 | /* |
| 217 | GROM access. Accesses the GROMs in the cartridge. GROM memory is |
| 218 | accessed serially via a set of ports. The GRMWA port (bank 0: 0x9c02) |
| 219 | takes two consecutive byte writes which represent the high and low byte |
| 220 | of the memory address in the GROM space. Once set, bytes can be read |
| 221 | by repeated read accesses on the GRMRD port (bank 0: 0x9800). The |
| 222 | address pointer advances on each read. The pointer wraps at the end |
| 223 | of each GROM chip memory space, i.e. every 8KiB. |
| 224 | This function takes the current GROM address minus 0x6000 which is the |
| 225 | lowest address for cartridge GROMs. Lower addresses access GROMs in the |
| 226 | console only, which appear in all banks. |
| 227 | Note that the GROM access mechanism is identical for all cartridge |
| 228 | types. |
| 229 | */ |
| 230 | UINT8 cartridge_grom_read(const device_config *device, int cart_offset) |
| 231 | { |
| 232 | UINT8 value; |
| 233 | int slot; |
| 234 | cartridge_t *cartridge; |
| 235 | ti99_multicart_t *cartslots = (ti99_multicart_t *)device->token; |
| 236 | |
| 237 | /* Handle the legacy mode. */ |
| 238 | if (in_legacy_mode(device)) |
| 239 | return cartridge_grom_read_legacy(device, cart_offset); |
| 240 | |
| 241 | slot = cartslots->active_slot; |
| 242 | /* |
| 243 | This fixes a minor issue: The selection mechanism of the console |
| 244 | concludes that there are multiple cartridges plugged in when it |
| 245 | checks the different GROM bases and finds different data. Empty |
| 246 | slots should return 0 at all addresses, but when we have only |
| 247 | one cartridge, this entails that the second cartridge is |
| 248 | different (all zeros), and so we get a meaningless selection |
| 249 | option between cartridge 1 and 1 and 1 ... |
| 250 | |
| 251 | So if next_free_slot==1, we have one cartridge in slot 0. |
| 252 | In that case we trick the OS to believe that the addressed |
| 253 | cartridge appears at all locations which causes it to assume a |
| 254 | standard single cartslot. |
| 255 | */ |
| 256 | if (cartslots->fixed_slot==AUTO && cartslots->next_free_slot==1) |
| 257 | slot=0; |
| 258 | |
| 259 | if (slot >= NUMBER_OF_CARTRIDGE_SLOTS) |
| 260 | value = 0; |
| 261 | else |
| 262 | { |
| 263 | cartridge = &cartslots->cartridge[slot]; |
| 264 | |
| 265 | if ((cartridge->grom_size>0) && (cartridge->pcb!=NULL)) |
| 266 | { |
| 267 | /* This is the reason why we need the image size: Read |
| 268 | access beyond the image size must be detected. */ |
| 269 | if (cart_offset > cartridge->grom_size) |
| 270 | return 0; |
| 271 | |
| 272 | value = (UINT8)cartridge->grom_buffer; |
| 273 | /* read ahead */ |
| 274 | cartridge->grom_buffer = cartridge->grom_ptr[cart_offset]; |
| 275 | } |
| 276 | else |
| 277 | { |
| 278 | /* We assume that empty sockets return 0 */ |
| 279 | value = 0; |
| 280 | logerror("Empty socket at address G(%d)>%04x\n", slot, 0x6000 + cart_offset); |
| 281 | } |
| 282 | } |
| 283 | // printf("grom access(port = %x, address = %04x) = %02x\n", slot, 0x6000 + cart_offset*2, value); |
| 284 | return value; |
| 285 | } |
| 286 | |
| 287 | /* |
| 288 | Find the index of the cartridge name. We assume the format |
| 289 | <name><number>, i.e. the number is the longest string from the right |
| 290 | which can be interpreted as a number. |
| 291 | */ |
| 292 | static int get_index_from_tagname(const device_config *image) |
| 293 | { |
| 294 | const char *tag = image->tag; |
| 295 | int maxlen = strlen(tag); |
| 296 | int i; |
| 297 | for (i=maxlen-1; i >=0; i--) |
| 298 | if (tag[i] < 48 || tag[i] > 57) break; |
| 299 | |
| 300 | return atoi(tag+i+1); |
| 301 | } |
| 302 | |
| 303 | /* |
| 304 | Common routine to assemble cartridges from resources. |
| 305 | */ |
| 306 | static cartridge_t *assemble_common(const device_config *cartslot) |
| 307 | { |
| 308 | /* Pointer to the cartridge structure. */ |
| 309 | cartridge_t *cartridge; |
| 310 | const device_config *cartsys = cartslot->owner; |
| 311 | ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token; |
| 312 | |
| 313 | void *socketcont; |
| 314 | int reslength; |
| 315 | int i; |
| 316 | |
| 317 | int slotnumber = get_index_from_tagname(cartslot)-1; |
| 318 | assert(slotnumber>=0 && slotnumber<NUMBER_OF_CARTRIDGE_SLOTS); |
| 319 | |
| 320 | /* There is a cartridge in this slot, check the maximum slot number. */ |
| 321 | if (cartslots->next_free_slot <= slotnumber) |
| 322 | { |
| 323 | cartslots->next_free_slot = slotnumber+1; |
| 324 | } |
| 325 | cartridge = &cartslots->cartridge[slotnumber]; |
| 326 | |
| 327 | /* Get the socket which is retrieved by the multicart instance in |
| 328 | the state of the cartslot instance. */ |
| 329 | socketcont = cartslot_get_socket(cartslot, "grom_socket"); |
| 330 | reslength = cartslot_get_resource_length(cartslot, "grom_socket"); |
| 331 | if (socketcont != NULL) |
| 332 | { |
| 333 | cartridge->grom_ptr = (UINT8 *)socketcont; |
| 334 | cartridge->grom_size = reslength; |
| 335 | } |
| 336 | |
| 337 | socketcont = cartslot_get_socket(cartslot, "rom_socket"); |
| 338 | reslength = cartslot_get_resource_length(cartslot, "rom_socket"); |
| 339 | if (socketcont != NULL) |
| 340 | { |
| 341 | cartridge->rom_ptr = socketcont; |
| 342 | cartridge->rom_size = reslength; |
| 343 | if (!is_99_8()) |
| 344 | { |
| 345 | /* Big-endianize it for 16 bit access. */ |
| 346 | UINT16 *cont16b = (UINT16 *)socketcont; |
| 347 | for (i = 0; i < cartridge->rom_size/2; i++) |
| 348 | cont16b[i] = BIG_ENDIANIZE_INT16(cont16b[i]); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | socketcont = cartslot_get_socket(cartslot, "rom2_socket"); |
| 353 | // reslength = cartslot_get_resource_length(cartslot, "rom2_socket"); /* cannot differ from rom_socket */ |
| 354 | if (socketcont != NULL) |
| 355 | { |
| 356 | cartridge->rom2_ptr = (UINT16 *)socketcont; |
| 357 | assert(cartridge->rom2_ptr != NULL); |
| 358 | if (!is_99_8()) |
| 359 | { |
| 360 | /* Big-endianize it for 16 bit access. */ |
| 361 | UINT16 *cont16b = (UINT16 *)socketcont; |
| 362 | for (i = 0; i < cartridge->rom_size/2; i++) |
| 363 | cont16b[i] = BIG_ENDIANIZE_INT16(cont16b[i]); |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | socketcont = cartslot_get_socket(cartslot, "ram_socket"); |
| 368 | reslength = cartslot_get_resource_length(cartslot, "ram_socket"); |
| 369 | if (socketcont != NULL) |
| 370 | { |
| 371 | cartridge->ram_ptr = socketcont; |
| 372 | cartridge->ram_size = reslength; |
| 373 | if (!is_99_8()) |
| 374 | { |
| 375 | /* Big-endianize it for 16 bit access. */ |
| 376 | UINT16 *cont16b = (UINT16 *)socketcont; |
| 377 | for (i = 0; i < cartridge->ram_size/2; i++) |
| 378 | cont16b[i] = BIG_ENDIANIZE_INT16(cont16b[i]); |
| 379 | } |
| 380 | } |
| 381 | return cartridge; |
| 382 | } |
| 383 | |
| 384 | static void set_pointers(const device_config *pcb, int index) |
| 385 | { |
| 386 | const device_config *cartsys = pcb->owner->owner; |
| 387 | ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token; |
| 388 | ti99_pcb_t *pcb_def = (ti99_pcb_t *)pcb->token; |
| 389 | |
| 390 | pcb_def->read = (read16_device_func) device_get_info_fct(pcb, TI99CARTINFO_FCT_6000_R); |
| 391 | pcb_def->write = (write16_device_func) device_get_info_fct(pcb, TI99CARTINFO_FCT_6000_W); |
| 392 | pcb_def->read8 = (read8_device_func) device_get_info_fct(pcb, TI99CARTINFO_FCT_6000_R8); |
| 393 | pcb_def->write8 = (write8_device_func) device_get_info_fct(pcb, TI99CARTINFO_FCT_6000_W8); |
| 394 | pcb_def->cruread = (read8_device_func) device_get_info_fct(pcb, TI99CARTINFO_FCT_CRU_R); |
| 395 | pcb_def->cruwrite = (write8_device_func) device_get_info_fct(pcb, TI99CARTINFO_FCT_CRU_W); |
| 396 | |
| 397 | pcb_def->assemble = (assmfct *)device_get_info_fct(pcb, TI99CART_FCT_ASSM); |
| 398 | pcb_def->disassemble = (assmfct *)device_get_info_fct(pcb, TI99CART_FCT_DISASSM); |
| 399 | |
| 400 | pcb_def->cartridge = &cartslots->cartridge[index]; |
| 401 | pcb_def->cartridge->pcb = pcb; |
| 402 | } |
| 403 | |
| 404 | /***************************************************************************** |
| 405 | Cartridge type: None |
| 406 | This PCB device is just a pseudo device; the legacy mode is handled |
| 407 | by dedicated functions. |
| 408 | ******************************************************************************/ |
| 409 | static DEVICE_START(ti99_pcb_none) |
| 410 | { |
| 411 | /* device is ti99_cartslot:cartridge:pcb */ |
| 412 | // printf("DEVICE_START(ti99_pcb_none), tag of device=%s\n", device->tag); |
| 413 | set_pointers(device, get_index_from_tagname(device->owner)-1); |
| 414 | } |
| 415 | |
| 416 | /***************************************************************************** |
| 417 | Cartridge type: Standard |
| 418 | Most cartridges are built in this type. Every cartridge may contain |
| 419 | GROM between 0 and 40 KiB, and ROM with 8 KiB length, no banking. |
| 420 | ******************************************************************************/ |
| 421 | |
| 422 | static DEVICE_START(ti99_pcb_std) |
| 423 | { |
| 424 | /* device is ti99_cartslot:cartridge:pcb */ |
| 425 | // printf("DEVICE_START(ti99_pcb_std), tag of device=%s\n", device->tag); |
| 426 | set_pointers(device, get_index_from_tagname(device->owner)-1); |
| 427 | } |
| 428 | |
| 429 | /* |
| 430 | Read handler for the CPU address space of the cartridge |
| 431 | Images for this area are found in the rom_sockets. |
| 432 | */ |
| 433 | static READ16_DEVICE_HANDLER( read_cart_std ) |
| 434 | { |
| 435 | /* device is pcb, owner is cartslot */ |
| 436 | UINT16 value; |
| 437 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 438 | cartridge_t *cartridge = pcb->cartridge; |
| 439 | |
| 440 | if (cartridge->rom_ptr==NULL) |
| 441 | { |
| 442 | // printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot); |
| 443 | // printf("Cartridge address = %lx\n", (long)pcb->cartridge); |
| 444 | value = 0; |
| 445 | } |
| 446 | else |
| 447 | { |
| 448 | value = ((UINT16 *)cartridge->rom_ptr)[offset]; |
| 449 | // printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value); |
| 450 | } |
| 451 | // printf("accessed cartridge rom[%02x:%04x] = %04x\n", 0, 0x6000+offset*2, value); |
| 452 | return value; |
| 453 | } |
| 454 | |
| 455 | static WRITE16_DEVICE_HANDLER( write_cart_std ) |
| 456 | { |
| 457 | logerror("Write access to cartridge ROM at address %04x ignored", 0x6000 + 2*offset); |
| 458 | } |
| 459 | |
| 460 | /* |
| 461 | TI-99/8 support: |
| 462 | Read handler for the CPU address space of the cartridge |
| 463 | Images for this area are found in the rom_sockets. |
| 464 | For comments see the READ16 handler. |
| 465 | */ |
| 466 | static READ8_DEVICE_HANDLER( read_cart_std8 ) |
| 467 | { |
| 468 | UINT8 value; |
| 469 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 470 | cartridge_t *cartridge = pcb->cartridge; |
| 471 | |
| 472 | if (cartridge->rom_ptr==NULL) |
| 473 | value = 0; |
| 474 | else |
| 475 | value = ((UINT8 *)cartridge->rom_ptr)[offset]; |
| 476 | return value; |
| 477 | } |
| 478 | |
| 479 | /* |
| 480 | TI-99/8 support: |
| 481 | Write handler. No writes are allowed to standard cartridges. |
| 482 | */ |
| 483 | static WRITE8_DEVICE_HANDLER( write_cart_std8 ) |
| 484 | { |
| 485 | logerror("Write access to cartridge ROM at address %04x ignored", 0x6000 + offset); |
| 486 | } |
| 487 | |
| 488 | /* |
| 489 | The standard cartridge assemble routine. We just call the common |
| 490 | function here. |
| 491 | */ |
| 492 | static int assemble_std(const device_config *image) |
| 493 | { |
| 494 | cartridge_t *cart; |
| 495 | // printf("assemble_std, %s\n", image->tag); |
| 496 | cart = assemble_common(image); |
| 497 | |
| 498 | return INIT_PASS; |
| 499 | } |
| 500 | |
| 501 | /* |
| 502 | Removes pointers and restores the state before plugging in the |
| 503 | cartridge. |
| 504 | The pointer to the location after the last cartridge is adjusted. |
| 505 | As it seems, we can use the same function for the disassembling of all |
| 506 | cartridge types. |
| 507 | */ |
| 508 | static int disassemble_std(const device_config *image) |
| 509 | { |
| 510 | int slotnumber; |
| 511 | int i; |
| 512 | cartridge_t *cart; |
| 513 | const device_config *cartsys = image->owner; |
| 514 | ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token; |
| 515 | |
| 516 | slotnumber = get_index_from_tagname(image)-1; |
| 517 | // printf("Disassemble cartridge %d\n", slotnumber); |
| 518 | |
| 519 | /* Search the highest remaining cartridge. */ |
| 520 | cartslots->next_free_slot = 0; |
| 521 | for (i=NUMBER_OF_CARTRIDGE_SLOTS-1; i >= 0; i--) |
| 522 | { |
| 523 | if (i != slotnumber) |
| 524 | { |
| 525 | if (!slot_is_empty(cartsys, i)) |
| 526 | { |
| 527 | cartslots->next_free_slot = i+1; |
| 528 | // printf("Setting new next_free_slot to %d\n", cartslots->next_free_slot); |
| 529 | break; |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | /* Do we have RAM? If so, swap the bytes (undo the BIG_ENDIANIZE) */ |
| 535 | cart = &cartslots->cartridge[slotnumber]; |
| 536 | if (!is_99_8()) |
| 537 | { |
| 538 | for (i = 0; i < cart->ram_size/2; i++) |
| 539 | ((UINT16 *)cart->ram_ptr)[i] = BIG_ENDIANIZE_INT16(((UINT16 *)cart->ram_ptr)[i]); |
| 540 | } |
| 541 | |
| 542 | clear_slot(cartsys, slotnumber); |
| 543 | |
| 544 | return INIT_PASS; |
| 545 | } |
| 546 | |
| 547 | /***************************************************************************** |
| 548 | Cartridge type: Paged (Extended Basic) |
| 549 | This cartridge consists of GROM memory and 2 pages of standard ROM. |
| 550 | The page is set by writing any value to a location in |
| 551 | the address area, where an even word offset sets the page to 0 and an |
| 552 | odd word offset sets the page to 1 (e.g. 6000 = bank 0, and |
| 553 | 6002 = bank 1). |
| 554 | ******************************************************************************/ |
| 555 | |
| 556 | static DEVICE_START(ti99_pcb_paged) |
| 557 | { |
| 558 | /* device is ti99_cartslot:cartridge:pcb */ |
| 559 | // printf("DEVICE_START(ti99_pcb_paged), tag of device=%s\n", device->tag); |
| 560 | set_pointers(device, get_index_from_tagname(device->owner)-1); |
| 561 | } |
| 562 | |
| 563 | /* |
| 564 | Read handler for the CPU address space of the cartridge |
| 565 | Images for this area are found in the rom_sockets. |
| 566 | */ |
| 567 | static READ16_DEVICE_HANDLER( read_cart_paged ) |
| 568 | { |
| 569 | /* device is pcb, owner is cartslot */ |
| 570 | UINT16 value; |
| 571 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 572 | cartridge_t *cartridge = pcb->cartridge; |
| 573 | UINT16 *rombank; |
| 574 | |
| 575 | if (cartridge->rom_page==0) |
| 576 | rombank = cartridge->rom_ptr; |
| 577 | else |
| 578 | rombank = cartridge->rom2_ptr; |
| 579 | |
| 580 | if (rombank==NULL) |
| 581 | { |
| 582 | // printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot); |
| 583 | // printf("Cartridge address = %lx\n", (long)pcb->cartridge); |
| 584 | /* TODO: Check for consistency with the GROM memory handling. */ |
| 585 | value = 0; |
| 586 | } |
| 587 | else |
| 588 | { |
| 589 | value = rombank[offset]; |
| 590 | // printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value); |
| 591 | } |
| 592 | // printf("accessed cartridge rom[%02x:%04x] = %04x\n", rompage, 0x6000+offset*2, value); |
| 593 | return value; |
| 594 | } |
| 595 | |
| 596 | |
| 597 | /* |
| 598 | Handle paging. Extended Basic switches between ROM banks by |
| 599 | using the value of the LSB of the address where any value |
| 600 | is written to. |
| 601 | */ |
| 602 | static WRITE16_DEVICE_HANDLER( write_cart_paged ) |
| 603 | { |
| 604 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 605 | cartridge_t *cartridge = pcb->cartridge; |
| 606 | cartridge->rom_page = offset & 1; |
| 607 | // printf("setting rompage to %d\n", cartridge->rom_page); |
| 608 | } |
| 609 | |
| 610 | /* |
| 611 | TI-99/8 support: |
| 612 | Read handler for the CPU address space of the cartridge. |
| 613 | Images for this area are found in the rom_sockets. |
| 614 | */ |
| 615 | static READ8_DEVICE_HANDLER( read_cart_paged8 ) |
| 616 | { |
| 617 | UINT8 value; |
| 618 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 619 | cartridge_t *cartridge = pcb->cartridge; |
| 620 | UINT8 *rombank; |
| 621 | |
| 622 | if (cartridge->rom_page==0) |
| 623 | rombank = cartridge->rom_ptr; |
| 624 | else |
| 625 | rombank = cartridge->rom2_ptr; |
| 626 | |
| 627 | if (rombank==NULL) |
| 628 | value = 0; |
| 629 | else |
| 630 | value = rombank[offset]; |
| 631 | |
| 632 | return value; |
| 633 | } |
| 634 | |
| 635 | |
| 636 | /* |
| 637 | TI-99/8 support: |
| 638 | Handle paging. Extended Basic switches between ROM banks by |
| 639 | using the value of the LSB of the address where any value |
| 640 | is written to. This is the TI-99/8 support. |
| 641 | Note that we need to check whether offset/2 is even or odd. |
| 642 | |
| 643 | FIXME: Extended Basic crashes with TI-99/8 when changing the rom page. |
| 644 | This may be an incompatibility of Extended Basic and TI-99/8. |
| 645 | */ |
| 646 | static WRITE8_DEVICE_HANDLER( write_cart_paged8 ) |
| 647 | { |
| 648 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 649 | cartridge_t *cartridge = pcb->cartridge; |
| 650 | // printf("offset = %04x\n", offset); |
| 651 | cartridge->rom_page = (offset>>1) & 1; |
| 652 | } |
| 653 | |
| 654 | /* |
| 655 | We require paged modules to have at least those two rom banks. |
| 656 | */ |
| 657 | static int assemble_paged(const device_config *image) |
| 658 | { |
| 659 | cartridge_t *cart; |
| 660 | |
| 661 | // printf("assemble_paged, %s\n", image->tag); |
| 662 | cart = assemble_common(image); |
| 663 | if (cart->rom_ptr==NULL) |
| 664 | { |
| 665 | logerror("Missing ROM for paged cartridge"); |
| 666 | return INIT_FAIL; |
| 667 | } |
| 668 | if (cart->rom2_ptr==NULL) |
| 669 | { |
| 670 | logerror("Missing second ROM for paged cartridge"); |
| 671 | return INIT_FAIL; |
| 672 | } |
| 673 | |
| 674 | return INIT_PASS; |
| 675 | } |
| 676 | |
| 677 | /***************************************************************************** |
| 678 | Cartridge type: Mini Memory |
| 679 | GROM: 6 KiB (occupies G>6000 to G>7800) |
| 680 | ROM: 4 KiB (romfile is actually 8 K long, half with zeros, 0x6000-0x6fff) |
| 681 | persistent RAM: 4 KiB (0x7000-0x7fff) |
| 682 | ******************************************************************************/ |
| 683 | |
| 684 | static DEVICE_START(ti99_pcb_minimem) |
| 685 | { |
| 686 | // printf("TI99 pcb minimem start\n"); |
| 687 | set_pointers(device, get_index_from_tagname(device->owner)-1); |
| 688 | } |
| 689 | |
| 690 | static READ16_DEVICE_HANDLER( read_cart_minimem ) |
| 691 | { |
| 692 | /* device is pcb, owner is cartslot */ |
| 693 | UINT16 value; |
| 694 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 695 | cartridge_t *cartridge = pcb->cartridge; |
| 696 | |
| 697 | if (offset < 0x800) |
| 698 | { |
| 699 | if (cartridge->rom_ptr==NULL) |
| 700 | { |
| 701 | // printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot); |
| 702 | // printf("Cartridge address = %lx\n", (long)pcb->cartridge); |
| 703 | value = 0; |
| 704 | } |
| 705 | else |
| 706 | { |
| 707 | value = ((UINT16 *)cartridge->rom_ptr)[offset]; |
| 708 | // printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value); |
| 709 | } |
| 710 | // printf("accessed cartridge rom[%02x:%04x] = %04x\n", rompage, 0x6000+offset*2, value); |
| 711 | } |
| 712 | else |
| 713 | { |
| 714 | if (cartridge->ram_ptr==NULL) |
| 715 | { |
| 716 | // printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot); |
| 717 | // printf("Cartridge address = %lx\n", (long)pcb->cartridge); |
| 718 | value = 0; |
| 719 | } |
| 720 | else |
| 721 | { |
| 722 | value = ((UINT16 *)cartridge->ram_ptr)[offset-0x800]; |
| 723 | // printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value); |
| 724 | } |
| 725 | // printf("accessed cartridge rom[%02x:%04x] = %04x\n", rompage, 0x6000+offset*2, value); |
| 726 | } |
| 727 | return value; |
| 728 | } |
| 729 | |
| 730 | /* |
| 731 | Mini Memory cartridge write operation. RAM is located at offset + 4 KiB |
| 732 | */ |
| 733 | static WRITE16_DEVICE_HANDLER( write_cart_minimem ) |
| 734 | { |
| 735 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 736 | cartridge_t *cartridge = pcb->cartridge; |
| 737 | UINT16 *pos; |
| 738 | |
| 739 | if (offset < 0x800) |
| 740 | { |
| 741 | logerror("Write access to cartridge ROM at address %04x ignored", 0x6000 + 2*offset); |
| 742 | } |
| 743 | else |
| 744 | { |
| 745 | if (cartridge->ram_ptr==NULL) |
| 746 | { |
| 747 | logerror("No cartridge RAM at address %04x", 0x6000 + 2*offset); |
| 748 | |
| 749 | // printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot); |
| 750 | // printf("Cartridge address = %lx\n", (long)pcb->cartridge); |
| 751 | /* TODO: Check for consistency with the GROM memory handling. */ |
| 752 | } |
| 753 | else |
| 754 | { |
| 755 | pos = ((UINT16 *)cartridge->ram_ptr) + offset - 0x800; |
| 756 | COMBINE_DATA(pos); |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | /* |
| 762 | Read handler for MiniMemory in TI-99/8. |
| 763 | */ |
| 764 | static READ8_DEVICE_HANDLER( read_cart_minimem8 ) |
| 765 | { |
| 766 | /* device is pcb, owner is cartslot */ |
| 767 | UINT8 value; |
| 768 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 769 | cartridge_t *cartridge = pcb->cartridge; |
| 770 | |
| 771 | if (offset < 0x1000) |
| 772 | { |
| 773 | if (cartridge->rom_ptr==NULL) |
| 774 | { |
| 775 | value = 0; |
| 776 | } |
| 777 | else |
| 778 | { |
| 779 | value = ((UINT8 *)cartridge->rom_ptr)[offset]; |
| 780 | } |
| 781 | } |
| 782 | else |
| 783 | { |
| 784 | if (cartridge->ram_ptr==NULL) |
| 785 | { |
| 786 | value = 0; |
| 787 | } |
| 788 | else |
| 789 | { |
| 790 | value = ((UINT8 *)cartridge->ram_ptr)[offset-0x1000]; |
| 791 | } |
| 792 | } |
| 793 | return value; |
| 794 | } |
| 795 | |
| 796 | /* |
| 797 | Mini Memory cartridge write operation. RAM is located at offset + 4 KiB. |
| 798 | This is the TI-99/8 support. |
| 799 | */ |
| 800 | static WRITE8_DEVICE_HANDLER( write_cart_minimem8 ) |
| 801 | { |
| 802 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 803 | cartridge_t *cartridge = pcb->cartridge; |
| 804 | |
| 805 | if (offset < 0x1000) |
| 806 | { |
| 807 | logerror("Write access to cartridge ROM at address %04x ignored", 0x6000 + offset); |
| 808 | } |
| 809 | else |
| 810 | { |
| 811 | if (cartridge->ram_ptr==NULL) |
| 812 | { |
| 813 | logerror("No cartridge RAM at address %04x", 0x6000 + offset); |
| 814 | |
| 815 | // printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot); |
| 816 | // printf("Cartridge address = %lx\n", (long)pcb->cartridge); |
| 817 | /* TODO: Check for consistency with the GROM memory handling. */ |
| 818 | } |
| 819 | else |
| 820 | { |
| 821 | ((UINT8 *)cartridge->ram_ptr)[offset-0x1000] = data; |
| 822 | } |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | |
| 827 | static int assemble_minimem(const device_config *image) |
| 828 | { |
| 829 | cartridge_t *cart; |
| 830 | |
| 831 | // printf("assemble_minimem, %s\n", image->tag); |
| 832 | cart = assemble_common(image); |
| 833 | if (cart->grom_size==0) |
| 834 | { |
| 835 | logerror("Missing GROM for Mini Memory"); |
| 836 | return INIT_FAIL; |
| 837 | } |
| 838 | if (cart->rom_size==0) |
| 839 | { |
| 840 | logerror("Missing ROM for Mini Memory"); |
| 841 | return INIT_FAIL; |
| 842 | } |
| 843 | if (cart->ram_size==0) |
| 844 | { |
| 845 | logerror("Missing RAM for Mini Memory"); |
| 846 | return INIT_FAIL; |
| 847 | } |
| 848 | |
| 849 | return INIT_PASS; |
| 850 | } |
| 851 | |
| 852 | |
| 853 | /***************************************************************************** |
| 854 | Cartridge type: SuperSpace II |
| 855 | SuperSpace cartridge type. SuperSpace is intended as a user-definable |
| 856 | blank cartridge containing buffered RAM |
| 857 | It has an Editor/Assembler GROM which helps the user to load |
| 858 | the user program into the cartridge. If the user program has a suitable |
| 859 | header, the console recognizes the cartridge as runnable, and |
| 860 | assigns a number in the selection screen. |
| 861 | Switching the RAM banks in this cartridge is achieved by setting |
| 862 | CRU bits (the system serial interface). |
| 863 | |
| 864 | GROM: Editor/Assembler GROM |
| 865 | ROM: none |
| 866 | persistent RAM: 32 KiB (0x6000-0x7fff, 4 banks) |
| 867 | Switching the bank is done via CRU write |
| 868 | ******************************************************************************/ |
| 869 | |
| 870 | static DEVICE_START(ti99_pcb_super) |
| 871 | { |
| 872 | // printf("TI99 pcb super start\n"); |
| 873 | set_pointers(device, get_index_from_tagname(device->owner)-1); |
| 874 | } |
| 875 | |
| 876 | /* |
| 877 | The CRU read handler. The CRU is a serial interface in the console. |
| 878 | Using the CRU we can switch the banks in the SuperSpace cartridge. |
| 879 | */ |
| 880 | static READ8_DEVICE_HANDLER( read_cart_cru ) |
| 881 | { |
| 882 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 883 | cartridge_t *cartridge = pcb->cartridge; |
| 884 | /* offset is the bit number. The CRU base address is already divided |
| 885 | by 2. */ |
| 886 | int reply = 0; |
| 887 | |
| 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 | */ |
| 910 | if ((offset & 1) == 0 || offset > 7) |
| 911 | reply = 0; |
| 912 | |
| 913 | /* CRU addresses are only 1 bit wide. Bytes are transferred from LSB |
| 914 | to MSB. That is, 8 bit are eight consecutive addresses. */ |
| 915 | reply = (cartridge->ram_page == (offset-1)/2); |
| 916 | |
| 917 | return reply; |
| 918 | } |
| 919 | |
| 920 | static WRITE8_DEVICE_HANDLER( write_cart_cru ) |
| 921 | { |
| 922 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 923 | cartridge_t *cartridge = pcb->cartridge; |
| 924 | // data is bit |
| 925 | // offset is address |
| 926 | if (offset < 8) |
| 927 | { |
| 928 | if (data != 0) |
| 929 | cartridge->ram_page = (offset-1)/2; |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | /* |
| 934 | SuperSpace RAM read operation. RAM is located at 0x6000 to 0x7fff |
| 935 | as 4 banks of 8 KiB each |
| 936 | */ |
| 937 | static READ16_DEVICE_HANDLER( read_cart_super ) |
| 938 | { |
| 939 | /* device is pcb, owner is cartslot */ |
| 940 | UINT16 value; |
| 941 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 942 | cartridge_t *cartridge = pcb->cartridge; |
| 943 | offs_t boffset; |
| 944 | |
| 945 | if (cartridge->ram_ptr==NULL) |
| 946 | { |
| 947 | // printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot); |
| 948 | // printf("Cartridge address = %lx\n", (long)pcb->cartridge); |
| 949 | value = 0; |
| 950 | } |
| 951 | else |
| 952 | { |
| 953 | boffset = cartridge->ram_page * 0x1000 + offset; |
| 954 | value = ((UINT16 *)cartridge->ram_ptr)[boffset]; |
| 955 | // printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value); |
| 956 | } |
| 957 | // printf("accessed cartridge ram[%02x:%04x] = %04x\n", cartridge->ram_page, 0x6000+offset*2, value); |
| 958 | return value; |
| 959 | } |
| 960 | |
| 961 | /* |
| 962 | SuperSpace RAM write operation. RAM is located at 0x6000 to 0x7fff |
| 963 | as 4 banks of 8 KiB each |
| 964 | */ |
| 965 | static WRITE16_DEVICE_HANDLER( write_cart_super ) |
| 966 | { |
| 967 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 968 | cartridge_t *cartridge = pcb->cartridge; |
| 969 | UINT16 *pos; |
| 970 | offs_t boffset; |
| 971 | |
| 972 | if (cartridge->ram_ptr==NULL) |
| 973 | { |
| 974 | logerror("No cartridge RAM at address %04x", 0x6000 + 2*offset); |
| 975 | |
| 976 | // printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot); |
| 977 | // printf("Cartridge address = %lx\n", (long)pcb->cartridge); |
| 978 | } |
| 979 | else |
| 980 | { |
| 981 | boffset = cartridge->ram_page * 0x1000 + offset; |
| 982 | pos = ((UINT16 *)cartridge->ram_ptr) + boffset; |
| 983 | COMBINE_DATA(pos); |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | /* |
| 988 | SuperSpace RAM read operation. RAM is located at 0x6000 to 0x7fff |
| 989 | as 4 banks of 8 KiB each. This is the TI-99/8 support. |
| 990 | */ |
| 991 | static READ8_DEVICE_HANDLER( read_cart_super8 ) |
| 992 | { |
| 993 | /* device is pcb, owner is cartslot */ |
| 994 | UINT8 value; |
| 995 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 996 | cartridge_t *cartridge = pcb->cartridge; |
| 997 | offs_t boffset; |
| 998 | |
| 999 | if (cartridge->ram_ptr==NULL) |
| 1000 | { |
| 1001 | // printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot); |
| 1002 | // printf("Cartridge address = %lx\n", (long)pcb->cartridge); |
| 1003 | value = 0; |
| 1004 | } |
| 1005 | else |
| 1006 | { |
| 1007 | boffset = cartridge->ram_page * 0x2000 + offset; |
| 1008 | value = ((UINT8 *)cartridge->ram_ptr)[boffset]; |
| 1009 | // printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value); |
| 1010 | } |
| 1011 | // printf("accessed cartridge ram[%02x:%04x] = %04x\n", cartridge->ram_page, 0x6000+offset*2, value); |
| 1012 | return value; |
| 1013 | } |
| 1014 | |
| 1015 | /* |
| 1016 | SuperSpace RAM write operation. RAM is located at 0x6000 to 0x7fff |
| 1017 | as 4 banks of 8 KiB each. This is the TI-99/8 support. |
| 1018 | */ |
| 1019 | static WRITE8_DEVICE_HANDLER( write_cart_super8 ) |
| 1020 | { |
| 1021 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 1022 | cartridge_t *cartridge = pcb->cartridge; |
| 1023 | offs_t boffset; |
| 1024 | |
| 1025 | if (cartridge->ram_ptr==NULL) |
| 1026 | { |
| 1027 | logerror("No cartridge RAM at address %04x", 0x6000 + offset); |
| 1028 | |
| 1029 | // printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot); |
| 1030 | // printf("Cartridge address = %lx\n", (long)pcb->cartridge); |
| 1031 | } |
| 1032 | else |
| 1033 | { |
| 1034 | boffset = cartridge->ram_page * 0x2000 + offset; |
| 1035 | ((UINT8 *)cartridge->ram_ptr)[boffset] = data; |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | |
| 1040 | static int assemble_super(const device_config *image) |
| 1041 | { |
| 1042 | cartridge_t *cart; |
| 1043 | // printf("assemble_super, %s\n", image->tag); |
| 1044 | |
| 1045 | cart = assemble_common(image); |
| 1046 | if (cart->ram_size==0) |
| 1047 | { |
| 1048 | logerror("Missing RAM for SuperSpace"); |
| 1049 | return INIT_FAIL; |
| 1050 | } |
| 1051 | return INIT_PASS; |
| 1052 | } |
| 1053 | |
| 1054 | /***************************************************************************** |
| 1055 | Cartridge type: MBX |
| 1056 | GROM: up to 40 KiB |
| 1057 | ROM: up to 16 KiB (in up to 2 banks of 8KiB each) |
| 1058 | RAM: 1022 B (0x6c00-0x6ffd, overrides ROM in that area) |
| 1059 | ROM mapper: 6ffe |
| 1060 | ******************************************************************************/ |
| 1061 | |
| 1062 | static DEVICE_START(ti99_pcb_mbx) |
| 1063 | { |
| 1064 | // printf("TI99 pcb mbx start\n"); |
| 1065 | set_pointers(device, get_index_from_tagname(device->owner)-1); |
| 1066 | } |
| 1067 | |
| 1068 | static READ16_DEVICE_HANDLER( read_cart_mbx ) |
| 1069 | { |
| 1070 | /* device is pcb, owner is cartslot */ |
| 1071 | UINT16 value = 0; |
| 1072 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 1073 | cartridge_t *cartridge = pcb->cartridge; |
| 1074 | |
| 1075 | if ((offset >= 0x0600) && (offset <= 0x07fe)) |
| 1076 | { |
| 1077 | /* This is the RAM area which overrides any ROM. There is no |
| 1078 | known banking behavior for the RAM, so we must assume that |
| 1079 | there is only one bank. */ |
| 1080 | if (cartridge->ram_ptr != NULL) |
| 1081 | value = ((UINT16 *)cartridge->ram_ptr)[offset - 0x0600]; |
| 1082 | } |
| 1083 | else |
| 1084 | { |
| 1085 | if (cartridge->rom_ptr != NULL) |
| 1086 | value = ((UINT16 *)cartridge->rom_ptr)[offset + cartridge->rom_page * 0x1000]; |
| 1087 | } |
| 1088 | return value; |
| 1089 | } |
| 1090 | |
| 1091 | /* |
| 1092 | MBX write operation. |
| 1093 | */ |
| 1094 | static WRITE16_DEVICE_HANDLER( write_cart_mbx ) |
| 1095 | { |
| 1096 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 1097 | cartridge_t *cartridge = pcb->cartridge; |
| 1098 | UINT16 *pos; |
| 1099 | |
| 1100 | if ((offset >= 0x0600) && (offset <= 0x07fe)) |
| 1101 | { |
| 1102 | if (cartridge->ram_ptr == NULL) |
| 1103 | return; |
| 1104 | pos = ((UINT16 *)cartridge->ram_ptr) + offset - 0x0600; |
| 1105 | COMBINE_DATA(pos); |
| 1106 | } |
| 1107 | else if ((offset == 0x07ff) && ACCESSING_BITS_8_15) |
| 1108 | { |
| 1109 | if (cartridge->rom_ptr==NULL) |
| 1110 | return; |
| 1111 | cartridge->rom_page = ((data >> 8) & 1); |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | /* |
| 1116 | TI-99/8 support |
| 1117 | */ |
| 1118 | static READ8_DEVICE_HANDLER( read_cart_mbx8 ) |
| 1119 | { |
| 1120 | /* device is pcb, owner is cartslot */ |
| 1121 | UINT8 value = 0; |
| 1122 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 1123 | cartridge_t *cartridge = pcb->cartridge; |
| 1124 | |
| 1125 | if ((offset >= 0x0c00) && (offset <= 0x0ffd)) |
| 1126 | { |
| 1127 | /* This is the RAM area which overrides any ROM. There is no |
| 1128 | known banking behavior for the RAM, so we must assume that |
| 1129 | there is only one bank. */ |
| 1130 | if (cartridge->ram_ptr != NULL) |
| 1131 | value = ((UINT8 *)cartridge->ram_ptr)[offset - 0x0c00]; |
| 1132 | } |
| 1133 | else |
| 1134 | { |
| 1135 | if (cartridge->rom_ptr != NULL) |
| 1136 | value = ((UINT8 *)cartridge->rom_ptr)[offset + cartridge->rom_page * 0x2000]; |
| 1137 | } |
| 1138 | return value; |
| 1139 | } |
| 1140 | |
| 1141 | /* |
| 1142 | MBX write operation (TI-99/8) |
| 1143 | */ |
| 1144 | static WRITE8_DEVICE_HANDLER( write_cart_mbx8 ) |
| 1145 | { |
| 1146 | ti99_pcb_t *pcb = (ti99_pcb_t *)device->token; |
| 1147 | cartridge_t *cartridge = pcb->cartridge; |
| 1148 | |
| 1149 | if ((offset >= 0x0c00) && (offset <= 0x0ffd)) |
| 1150 | { |
| 1151 | if (cartridge->ram_ptr == NULL) |
| 1152 | return; |
| 1153 | ((UINT8 *)cartridge->ram_ptr)[offset - 0x0c00] = data; |
| 1154 | } |
| 1155 | else if (offset == 0x0ffe || offset == 0x0fff) |
| 1156 | { |
| 1157 | if (cartridge->rom_ptr==NULL) |
| 1158 | return; |
| 1159 | cartridge->rom_page = (data & 1); /* TODO: Check */ |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | |
| 1164 | static int assemble_mbx(const device_config *image) |
| 1165 | { |
| 1166 | cartridge_t *cart; |
| 1167 | |
| 1168 | // printf("assemble_mbx, %s\n", image->tag); |
| 1169 | cart = assemble_common(image); |
| 1170 | return INIT_PASS; |
| 1171 | } |
| 1172 | |
| 1173 | |
| 1174 | /***************************************************************************** |
| 1175 | Device metadata |
| 1176 | ******************************************************************************/ |
| 1177 | |
| 1178 | static DEVICE_GET_INFO(ti99_cart_common) |
| 1179 | { |
| 1180 | switch(state) |
| 1181 | { |
| 1182 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1183 | case DEVINFO_INT_TOKEN_BYTES: |
| 1184 | info->i = sizeof(ti99_pcb_t); |
| 1185 | break; |
| 1186 | case DEVINFO_INT_INLINE_CONFIG_BYTES: |
| 1187 | info->i = 0; |
| 1188 | break; |
| 1189 | case DEVINFO_INT_CLASS: |
| 1190 | info->i = DEVICE_CLASS_PERIPHERAL; |
| 1191 | break; |
| 1192 | |
| 1193 | /* --- the following bits of info are returned as pointers to functions --- */ |
| 1194 | case DEVINFO_FCT_SET_INFO: |
| 1195 | /* Nothing */ |
| 1196 | break; |
| 1197 | case DEVINFO_FCT_START: |
| 1198 | info->start = DEVICE_START_NAME(ti99_pcb_std); |
| 1199 | break; |
| 1200 | case DEVINFO_FCT_STOP: |
| 1201 | /* Nothing */ |
| 1202 | break; |
| 1203 | case DEVINFO_FCT_RESET: |
| 1204 | /* Nothing */ |
| 1205 | break; |
| 1206 | case TI99CARTINFO_FCT_6000_R: |
| 1207 | info->f = (genf *) read_cart_std; break; |
| 1208 | |
| 1209 | case TI99CARTINFO_FCT_6000_W: |
| 1210 | info->f = (genf *) write_cart_std; break; |
| 1211 | |
| 1212 | case TI99CARTINFO_FCT_6000_R8: |
| 1213 | info->f = (genf *) read_cart_std8; break; |
| 1214 | |
| 1215 | case TI99CARTINFO_FCT_6000_W8: |
| 1216 | info->f = (genf *) write_cart_std8; break; |
| 1217 | |
| 1218 | case TI99CARTINFO_FCT_CRU_R: |
| 1219 | /* Nothing */ |
| 1220 | break; |
| 1221 | |
| 1222 | case TI99CARTINFO_FCT_CRU_W: |
| 1223 | /* Nothing */ |
| 1224 | break; |
| 1225 | |
| 1226 | case TI99CART_FCT_ASSM: |
| 1227 | info->f = (genf *) assemble_std; |
| 1228 | break; |
| 1229 | |
| 1230 | case TI99CART_FCT_DISASSM: |
| 1231 | info->f = (genf *) disassemble_std; |
| 1232 | break; |
| 1233 | |
| 1234 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1235 | case DEVINFO_STR_NAME: |
| 1236 | strcpy(info->s, "TI99 standard cartridge pcb"); |
| 1237 | break; |
| 1238 | case DEVINFO_STR_FAMILY: |
| 1239 | strcpy(info->s, "TI99 cartridge pcb"); |
| 1240 | break; |
| 1241 | case DEVINFO_STR_VERSION: |
| 1242 | strcpy(info->s, "1.0"); |
| 1243 | break; |
| 1244 | case DEVINFO_STR_SOURCE_FILE: |
| 1245 | strcpy(info->s, __FILE__); |
| 1246 | break; |
| 1247 | case DEVINFO_STR_CREDITS: |
| 1248 | /* Nothing */ |
| 1249 | break; |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | DEVICE_GET_INFO(ti99_cartridge_pcb_none) |
| 1254 | { |
| 1255 | switch(state) |
| 1256 | { |
| 1257 | case DEVINFO_FCT_START: |
| 1258 | info->start = DEVICE_START_NAME(ti99_pcb_none); |
| 1259 | break; |
| 1260 | |
| 1261 | case DEVINFO_STR_NAME: |
| 1262 | strcpy(info->s, "TI99 empty cartridge"); |
| 1263 | break; |
| 1264 | |
| 1265 | default: |
| 1266 | DEVICE_GET_INFO_CALL(ti99_cart_common); |
| 1267 | break; |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | DEVICE_GET_INFO(ti99_cartridge_pcb_std) |
| 1272 | { |
| 1273 | DEVICE_GET_INFO_CALL(ti99_cart_common); |
| 1274 | } |
| 1275 | |
| 1276 | DEVICE_GET_INFO(ti99_cartridge_pcb_paged) |
| 1277 | { |
| 1278 | switch(state) |
| 1279 | { |
| 1280 | case DEVINFO_FCT_START: |
| 1281 | info->start = DEVICE_START_NAME(ti99_pcb_paged); |
| 1282 | break; |
| 1283 | |
| 1284 | case TI99CART_FCT_ASSM: |
| 1285 | info->f = (genf *) assemble_paged; break; |
| 1286 | |
| 1287 | case TI99CARTINFO_FCT_6000_R: |
| 1288 | info->f = (genf *) read_cart_paged; |
| 1289 | break; |
| 1290 | |
| 1291 | case TI99CARTINFO_FCT_6000_W: |
| 1292 | info->f = (genf *) write_cart_paged; |
| 1293 | break; |
| 1294 | |
| 1295 | case TI99CARTINFO_FCT_6000_R8: |
| 1296 | info->f = (genf *) read_cart_paged8; |
| 1297 | break; |
| 1298 | |
| 1299 | case TI99CARTINFO_FCT_6000_W8: |
| 1300 | info->f = (genf *) write_cart_paged8; |
| 1301 | break; |
| 1302 | |
| 1303 | case DEVINFO_STR_NAME: |
| 1304 | strcpy(info->s, "TI99 paged cartridge pcb"); |
| 1305 | break; |
| 1306 | |
| 1307 | default: |
| 1308 | DEVICE_GET_INFO_CALL(ti99_cart_common); |
| 1309 | break; |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | DEVICE_GET_INFO(ti99_cartridge_pcb_minimem) |
| 1314 | { |
| 1315 | switch(state) |
| 1316 | { |
| 1317 | case DEVINFO_FCT_START: |
| 1318 | info->start = DEVICE_START_NAME(ti99_pcb_minimem); |
| 1319 | break; |
| 1320 | |
| 1321 | case TI99CART_FCT_ASSM: |
| 1322 | info->f = (genf *) assemble_minimem; |
| 1323 | break; |
| 1324 | case TI99CARTINFO_FCT_6000_R: |
| 1325 | info->f = (genf *) read_cart_minimem; |
| 1326 | break; |
| 1327 | case TI99CARTINFO_FCT_6000_W: |
| 1328 | info->f = (genf *) write_cart_minimem; |
| 1329 | break; |
| 1330 | case TI99CARTINFO_FCT_6000_R8: |
| 1331 | info->f = (genf *) read_cart_minimem8; |
| 1332 | break; |
| 1333 | case TI99CARTINFO_FCT_6000_W8: |
| 1334 | info->f = (genf *) write_cart_minimem8; |
| 1335 | break; |
| 1336 | |
| 1337 | case DEVINFO_STR_NAME: |
| 1338 | strcpy(info->s, "TI99 MiniMemory cartridge pcb"); |
| 1339 | break; |
| 1340 | |
| 1341 | default: |
| 1342 | DEVICE_GET_INFO_CALL(ti99_cart_common); |
| 1343 | break; |
| 1344 | } |
| 1345 | } |
| 1346 | |
| 1347 | DEVICE_GET_INFO(ti99_cartridge_pcb_super) |
| 1348 | { |
| 1349 | switch(state) |
| 1350 | { |
| 1351 | case DEVINFO_FCT_START: |
| 1352 | info->start = DEVICE_START_NAME(ti99_pcb_super); |
| 1353 | break; |
| 1354 | |
| 1355 | case TI99CART_FCT_ASSM: |
| 1356 | info->f = (genf *) assemble_super; |
| 1357 | break; |
| 1358 | case TI99CARTINFO_FCT_6000_R: |
| 1359 | info->f = (genf *) read_cart_super; |
| 1360 | break; |
| 1361 | case TI99CARTINFO_FCT_6000_W: |
| 1362 | info->f = (genf *) write_cart_super; |
| 1363 | break; |
| 1364 | case TI99CARTINFO_FCT_6000_R8: |
| 1365 | info->f = (genf *) read_cart_super8; |
| 1366 | break; |
| 1367 | case TI99CARTINFO_FCT_6000_W8: |
| 1368 | info->f = (genf *) write_cart_super8; |
| 1369 | break; |
| 1370 | case TI99CARTINFO_FCT_CRU_R: |
| 1371 | info->f = (genf *) read_cart_cru; |
| 1372 | break; |
| 1373 | case TI99CARTINFO_FCT_CRU_W: |
| 1374 | info->f = (genf *) write_cart_cru; |
| 1375 | break; |
| 1376 | |
| 1377 | case DEVINFO_STR_NAME: |
| 1378 | strcpy(info->s, "TI99 SuperSpace cartridge pcb"); |
| 1379 | break; |
| 1380 | |
| 1381 | default: |
| 1382 | DEVICE_GET_INFO_CALL(ti99_cart_common); |
| 1383 | break; |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | DEVICE_GET_INFO(ti99_cartridge_pcb_mbx) |
| 1388 | { |
| 1389 | switch(state) |
| 1390 | { |
| 1391 | case DEVINFO_FCT_START: |
| 1392 | info->start = DEVICE_START_NAME(ti99_pcb_mbx); |
| 1393 | break; |
| 1394 | |
| 1395 | case TI99CART_FCT_ASSM: |
| 1396 | info->f = (genf *) assemble_mbx; |
| 1397 | break; |
| 1398 | case TI99CARTINFO_FCT_6000_R: |
| 1399 | info->f = (genf *) read_cart_mbx; |
| 1400 | break; |
| 1401 | case TI99CARTINFO_FCT_6000_W: |
| 1402 | info->f = (genf *) write_cart_mbx; |
| 1403 | break; |
| 1404 | case TI99CARTINFO_FCT_6000_R8: |
| 1405 | info->f = (genf *) read_cart_mbx8; |
| 1406 | break; |
| 1407 | case TI99CARTINFO_FCT_6000_W8: |
| 1408 | info->f = (genf *) write_cart_mbx8; |
| 1409 | break; |
| 1410 | |
| 1411 | |
| 1412 | case DEVINFO_STR_NAME: |
| 1413 | strcpy(info->s, "TI99 MBX cartridge pcb"); |
| 1414 | break; |
| 1415 | |
| 1416 | default: |
| 1417 | DEVICE_GET_INFO_CALL(ti99_cart_common); |
| 1418 | break; |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | |
| 1423 | /***************************************************************************** |
| 1424 | The cartridge handling of the multi-cartridge system. |
| 1425 | Every cartridge contains a PCB device. The memory handlers delegate the calls |
| 1426 | to the respective handlers of the cartridges. |
| 1427 | ******************************************************************************/ |
| 1428 | /* |
| 1429 | Initialize a cartridge. Each cartridge contains a PCB device. |
| 1430 | */ |
| 1431 | static DEVICE_START( ti99_cartridge ) |
| 1432 | { |
| 1433 | cartslot_t *cart = device->token; |
| 1434 | astring *tempstring = astring_alloc(); |
| 1435 | |
| 1436 | /* find the PCB device */ |
| 1437 | cart->pcb_device = devtag_get_device( |
| 1438 | device->machine, |
| 1439 | device_build_tag(tempstring, device, TAG_PCB)); |
| 1440 | astring_free(tempstring); |
| 1441 | } |
| 1442 | |
| 1443 | /* |
| 1444 | Load the cartridge image files. Apart from reading, we set pointers |
| 1445 | to the image files so that during runtime we do not need search |
| 1446 | operations. |
| 1447 | */ |
| 1448 | static DEVICE_IMAGE_LOAD( ti99_cartridge ) |
| 1449 | { |
| 1450 | const device_config *pcbdev = cartslot_get_pcb(image); |
| 1451 | const device_config *cartsys = image->owner; |
| 1452 | ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token; |
| 1453 | |
| 1454 | int result; |
| 1455 | |
| 1456 | result = load_legacy(image); |
| 1457 | |
| 1458 | if (result != INIT_FAIL) |
| 1459 | cartslots->legacy_slots++; |
| 1460 | else |
| 1461 | { |
| 1462 | if (pcbdev != NULL) |
| 1463 | { |
| 1464 | /* If we are here, we have a multicart. */ |
| 1465 | ti99_pcb_t *pcb = (ti99_pcb_t *)pcbdev->token; |
| 1466 | cartslot_t *cart = (cartslot_t *)image->token; |
| 1467 | |
| 1468 | /* try opening this as a multicart */ |
| 1469 | /* This line requires that cartslot_t be included in cartslot.h, |
| 1470 | otherwise one cannot make use of multicart handling within such a |
| 1471 | custom LOAD function. */ |
| 1472 | multicart_open_error me = multicart_open(image_filename(image), image->machine->gamedrv->name, MULTICART_FLAGS_LOAD_RESOURCES, &cart->mc); |
| 1473 | |
| 1474 | /* Now that we have loaded the image files, let the PCB put them all |
| 1475 | together. This means we put the images in a structure which allows |
| 1476 | for a quick access by the memory handlers. Every PCB defines an |
| 1477 | own assembly method. */ |
| 1478 | if (me == MCERR_NONE) |
| 1479 | result = pcb->assemble(image); |
| 1480 | else |
| 1481 | fatalerror("Error loading multicart: %s\n", mc_error_text(me)); |
| 1482 | |
| 1483 | /* This is for legacy support. If we have no multicart left |
| 1484 | but there are still legacy dumps, we switch to legacy mode. */ |
| 1485 | if (result != INIT_FAIL) |
| 1486 | cartslots->multi_slots++; |
| 1487 | } |
| 1488 | else |
| 1489 | { |
| 1490 | fatalerror("Error loading multicart: no pcb found.\n"); |
| 1491 | } |
| 1492 | } |
| 1493 | return result; |
| 1494 | } |
| 1495 | |
| 1496 | /* |
| 1497 | This is called when the cartridge is unplugged (or the emulator is |
| 1498 | stopped). |
| 1499 | */ |
| 1500 | static DEVICE_IMAGE_UNLOAD( ti99_cartridge ) |
| 1501 | { |
| 1502 | const device_config *pcbdev; |
| 1503 | ti99_multicart_t *cartslots = (ti99_multicart_t *)image->owner->token; |
| 1504 | |
| 1505 | if (image->token == NULL) |
| 1506 | { |
| 1507 | /* This means something went wrong during the pcb |
| 1508 | identification (e.g. one of the cartridge files was not |
| 1509 | found). We do not need to (and cannot) unload |
| 1510 | the cartridge. */ |
| 1511 | return; |
| 1512 | } |
| 1513 | pcbdev = cartslot_get_pcb(image); |
| 1514 | |
| 1515 | if (pcbdev != NULL) |
| 1516 | { |
| 1517 | ti99_pcb_t *pcb = (ti99_pcb_t *)pcbdev->token; |
| 1518 | cartslot_t *cart = (cartslot_t *)image->token; |
| 1519 | |
| 1520 | // printf("unload\n"); |
| 1521 | if (cart->mc != NULL) |
| 1522 | { |
| 1523 | /* Remove pointers and de-big-endianize RAM contents. */ |
| 1524 | pcb->disassemble(image); |
| 1525 | |
| 1526 | /* Close the multicart; all RAM resources will be |
| 1527 | written to disk */ |
| 1528 | multicart_close(cart->mc); |
| 1529 | cart->mc = NULL; |
| 1530 | |
| 1531 | /* See above: Legacy support. */ |
| 1532 | cartslots->multi_slots--; |
| 1533 | } |
| 1534 | // else |
| 1535 | // fatalerror("Lost pointer to multicart in cartridge. Report bug.\n"); |
| 1536 | } |
| 1537 | else |
| 1538 | { |
| 1539 | unload_legacy(image); |
| 1540 | cartslots->legacy_slots--; |
| 1541 | } |
| 1542 | } |
| 1543 | |
| 1544 | /***************************************************************************** |
| 1545 | The legacy cartridge slot system. |
| 1546 | |
| 1547 | This is the system which was used for the TI family until MESS 0.130. |
| 1548 | Here, plain ROM dumps were mounted on the slots, e.g. the GROM on slot 1, |
| 1549 | ROM on slot 2. No multiple cartridges were supported. |
| 1550 | |
| 1551 | This functionality is deprecated. |
| 1552 | |
| 1553 | In order to allow for a smooth transition, this feature is included in this |
| 1554 | version. It is strongly recommmended to create suitable multicart packs. |
| 1555 | |
| 1556 | This implementation tolerates both cartridge systems in the following way: |
| 1557 | - If there are only single ROM dumps, the system switched to legacy mode. |
| 1558 | - If there is at least one multicart pack in any slot, the system switches |
| 1559 | to the multicart mode. All plain dumps become invisible; the slots appear |
| 1560 | empty to the system |
| 1561 | - Both modes may change on plugging and unplugging. |
| 1562 | ******************************************************************************/ |
| 1563 | |
| 1564 | static UINT8 cartridge_grom_read_legacy(const device_config *cartsys, int cart_offset) |
| 1565 | { |
| 1566 | int slot; |
| 1567 | cartridge_t *cartridge; |
| 1568 | ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token; |
| 1569 | |
| 1570 | UINT8 value; |
| 1571 | |
| 1572 | /* Get the GROM slot number. */ |
| 1573 | slot = cartslots->legacy_slotnumber[SLOTC_GROM]; |
| 1574 | if (slot<0) |
| 1575 | /* No GROM available. */ |
| 1576 | return 0; |
| 1577 | |
| 1578 | cartridge = &cartslots->cartridge[slot]; |
| 1579 | |
| 1580 | if (cartridge->grom_size>0) |
| 1581 | { |
| 1582 | /* This is the reason why we need the image size: Read |
| 1583 | access beyond the image size must be detected. */ |
| 1584 | if (cart_offset > cartridge->grom_size) |
| 1585 | return 0; |
| 1586 | |
| 1587 | value = (UINT8)cartridge->grom_buffer; |
| 1588 | /* read ahead */ |
| 1589 | cartridge->grom_buffer = cartridge->grom_ptr[cart_offset]; |
| 1590 | } |
| 1591 | else |
| 1592 | { |
| 1593 | /* We assume that empty sockets return 0 */ |
| 1594 | value = 0; |
| 1595 | logerror("Empty socket at address G(%d)>%04x\n", slot, 0x6000 + cart_offset); |
| 1596 | } |
| 1597 | |
| 1598 | // printf("grom access(port = %x, address = %04x) = %02x\n", slot, 0x6000 + cart_offset*2, value); |
| 1599 | return value; |
| 1600 | } |
| 1601 | |
| 1602 | static READ16_DEVICE_HANDLER( ti99_cart_r_legacy ) |
| 1603 | { |
| 1604 | /* if (hsgpl_crdena) |
| 1605 | return ti99_hsgpl_rom6_r(space, offset, mem_mask); |
| 1606 | */ |
| 1607 | int slotmbx, slotmini, slotebr2, slotrom; |
| 1608 | ti99_multicart_t *cartslots = (ti99_multicart_t *)device->token; |
| 1609 | |
| 1610 | slotmbx = cartslots->legacy_slotnumber[SLOTC_MBX]; |
| 1611 | |
| 1612 | if ((slotmbx != -1) && (offset >= 0x0600) && (offset <= 0x07fe)) |
| 1613 | { |
| 1614 | /* We are in the RAM area of MBX cartridges. */ |
| 1615 | return ((UINT16 *)(cartslots->cartridge[slotmbx].ram_ptr))[offset-0x0600]; |
| 1616 | } |
| 1617 | |
| 1618 | slotmini = cartslots->legacy_slotnumber[SLOTC_MINIMEM]; |
| 1619 | if ((slotmini != -1) && (offset >= 0x0800) && (offset <= 0x0fff)) |
| 1620 | { |
| 1621 | /* We are in the RAM area of the Mini Memory cartridge. */ |
| 1622 | return ((UINT16 *)(cartslots->cartridge[slotmini].ram_ptr))[offset-0x0800]; |
| 1623 | } |
| 1624 | |
| 1625 | /* Standard */ |
| 1626 | slotrom = cartslots->legacy_slotnumber[SLOTC_CROM]; |
| 1627 | if (slotrom < 0) |
| 1628 | return 0; |
| 1629 | |
| 1630 | slotebr2 = cartslots->legacy_slotnumber[SLOTC_DROM]; |
| 1631 | if (slotebr2 < 0) |
| 1632 | return (((UINT16 *)cartslots->cartridge[slotrom].rom_ptr)[offset]); |
| 1633 | else |
| 1634 | { |
| 1635 | /* Extended Basic or other paged cartridge */ |
| 1636 | if (cartslots->cartridge[slotrom].rom_page!=0) |
| 1637 | return (((UINT16 *)cartslots->cartridge[slotebr2].rom2_ptr)[offset]); |
| 1638 | else |
| 1639 | return (((UINT16 *)cartslots->cartridge[slotrom].rom_ptr)[offset]); |
| 1640 | } |
| 1641 | /* Super Space is not supported in legacy mode. */ |
| 1642 | } |
| 1643 | |
| 1644 | static WRITE16_DEVICE_HANDLER( ti99_cart_w_legacy ) |
| 1645 | { |
| 1646 | |
| 1647 | /* if (hsgpl_crdena) |
| 1648 | ti99_hsgpl_rom6_w(space, offset, data, mem_mask); |
| 1649 | return; |
| 1650 | */ |
| 1651 | int slotmbx, slotmini, slotebr2, slotrom; |
| 1652 | ti99_multicart_t *cartslots = (ti99_multicart_t *)device->token; |
| 1653 | |
| 1654 | slotmbx = cartslots->legacy_slotnumber[SLOTC_MBX]; |
| 1655 | slotrom = cartslots->legacy_slotnumber[SLOTC_CROM]; |
| 1656 | slotebr2 = cartslots->legacy_slotnumber[SLOTC_DROM]; |
| 1657 | slotmini = cartslots->legacy_slotnumber[SLOTC_MINIMEM]; |
| 1658 | |
| 1659 | if (slotmbx != -1) |
| 1660 | { |
| 1661 | if ((offset >= 0x0600) && (offset <= 0x07fe)) |
| 1662 | { |
| 1663 | /* We are in the RAM area of MBX cartridges. */ |
| 1664 | /* RAM in 0x6c00-0x6ffd (presumably non-paged) */ |
| 1665 | /* mapper at 0x6ffe */ |
| 1666 | COMBINE_DATA(((UINT16 *)cartslots->cartridge[slotmbx].ram_ptr) + offset - 0x0600); |
| 1667 | } |
| 1668 | else |
| 1669 | { |
| 1670 | if ((offset == 0x07ff) && ACCESSING_BITS_8_15) |
| 1671 | { |
| 1672 | if (slotebr2 < 0 || slotrom < 0) |
| 1673 | return; /* just ignore if the cartridge is not paged. */ |
| 1674 | else |
| 1675 | cartslots->cartridge[slotrom].rom_page = ((data >> 8) & 1); |
| 1676 | } |
| 1677 | } |
| 1678 | return; |
| 1679 | } |
| 1680 | if (slotmini != -1) |
| 1681 | { |
| 1682 | if ((offset >= 0x0800) && (offset <= 0x0fff)) |
| 1683 | /* We are in the RAM area of a MiniMemory cartridge. */ |
| 1684 | COMBINE_DATA(((UINT16 *)cartslots->cartridge[slotmini].ram_ptr) + offset - 0x0800); |
| 1685 | return; |
| 1686 | } |
| 1687 | if (slotebr2 != -1 && slotrom != -1) |
| 1688 | { |
| 1689 | cartslots->cartridge[slotrom].rom_page = (offset & 1); |
| 1690 | } |
| 1691 | } |
| 1692 | |
| 1693 | /* |
| 1694 | TI-99/8 support. |
| 1695 | */ |
| 1696 | static READ8_DEVICE_HANDLER( ti99_cart_r_legacy8 ) |
| 1697 | { |
| 1698 | /* if (hsgpl_crdena) |
| 1699 | return ti99_hsgpl_rom6_r(space, offset, mem_mask); |
| 1700 | */ |
| 1701 | int slotmbx, slotmini, slotebr2, slotrom; |
| 1702 | ti99_multicart_t *cartslots = (ti99_multicart_t *)device->token; |
| 1703 | |
| 1704 | slotmbx = cartslots->legacy_slotnumber[SLOTC_MBX]; |
| 1705 | |
| 1706 | if ((slotmbx != -1) && (offset >= 0x0c00) && (offset <= 0x0ffd)) |
| 1707 | { |
| 1708 | /* We are in the RAM area of MBX cartridges. */ |
| 1709 | return ((UINT8 *)(cartslots->cartridge[slotmbx].ram_ptr))[offset-0x0c00]; |
| 1710 | } |
| 1711 | |
| 1712 | slotmini = cartslots->legacy_slotnumber[SLOTC_MINIMEM]; |
| 1713 | if ((slotmini != -1) && (offset >= 0x1000) && (offset <= 0x1fff)) |
| 1714 | { |
| 1715 | /* We are in the RAM area of the Mini Memory cartridge. */ |
| 1716 | return ((UINT8 *)(cartslots->cartridge[slotmini].ram_ptr))[offset-0x1000]; |
| 1717 | } |
| 1718 | |
| 1719 | /* Standard */ |
| 1720 | slotrom = cartslots->legacy_slotnumber[SLOTC_CROM]; |
| 1721 | if (slotrom < 0) |
| 1722 | return 0; |
| 1723 | |
| 1724 | slotebr2 = cartslots->legacy_slotnumber[SLOTC_DROM]; |
| 1725 | if (slotebr2 < 0) |
| 1726 | return (((UINT8 *)cartslots->cartridge[slotrom].rom_ptr)[offset]); |
| 1727 | else |
| 1728 | { |
| 1729 | /* Extended Basic or other paged cartridge */ |
| 1730 | if (cartslots->cartridge[slotrom].rom_page!=0) |
| 1731 | return (((UINT8 *)cartslots->cartridge[slotebr2].rom2_ptr)[offset]); |
| 1732 | else |
| 1733 | return (((UINT8 *)cartslots->cartridge[slotrom].rom_ptr)[offset]); |
| 1734 | } |
| 1735 | /* Super Space is not supported in legacy mode. */ |
| 1736 | } |
| 1737 | |
| 1738 | /* |
| 1739 | TI-99/8 support. |
| 1740 | */ |
| 1741 | static WRITE8_DEVICE_HANDLER( ti99_cart_w_legacy8 ) |
| 1742 | { |
| 1743 | |
| 1744 | /* if (hsgpl_crdena) |
| 1745 | ti99_hsgpl_rom6_w(space, offset, data, mem_mask); |
| 1746 | return; |
| 1747 | */ |
| 1748 | int slotmbx, slotmini, slotebr2, slotrom; |
| 1749 | ti99_multicart_t *cartslots = (ti99_multicart_t *)device->token; |
| 1750 | |
| 1751 | slotmbx = cartslots->legacy_slotnumber[SLOTC_MBX]; |
| 1752 | slotrom = cartslots->legacy_slotnumber[SLOTC_CROM]; |
| 1753 | slotebr2 = cartslots->legacy_slotnumber[SLOTC_DROM]; |
| 1754 | slotmini = cartslots->legacy_slotnumber[SLOTC_MINIMEM]; |
| 1755 | |
| 1756 | if (slotmbx != -1) |
| 1757 | { |
| 1758 | if ((offset >= 0x0c00) && (offset <= 0x0ffd)) |
| 1759 | { |
| 1760 | /* We are in the RAM area of MBX cartridges. */ |
| 1761 | /* RAM in 0x6c00-0x6ffd (presumably non-paged) */ |
| 1762 | /* mapper at 0x6ffe */ |
| 1763 | ((UINT8 *)cartslots->cartridge[slotmbx].ram_ptr)[offset - 0x0c00] = data; |
| 1764 | } |
| 1765 | else |
| 1766 | { |
| 1767 | if (offset == 0x0ffe || offset == 0x0fff) |
| 1768 | { |
| 1769 | if (slotebr2 < 0 || slotrom < 0) |
| 1770 | return; /* just ignore if the cartridge is not paged. */ |
| 1771 | else |
| 1772 | cartslots->cartridge[slotrom].rom_page = ((data >> 8) & 1); |
| 1773 | } |
| 1774 | } |
| 1775 | return; |
| 1776 | } |
| 1777 | if (slotmini != -1) |
| 1778 | { |
| 1779 | if ((offset >= 0x1000) && (offset <= 0x1fff)) |
| 1780 | /* We are in the RAM area of a MiniMemory cartridge. */ |
| 1781 | ((UINT8 *)cartslots->cartridge[slotmini].ram_ptr)[offset - 0x1000] = data; |
| 1782 | return; |
| 1783 | } |
| 1784 | if (slotebr2 != -1 && slotrom != -1) |
| 1785 | { |
| 1786 | cartslots->cartridge[slotrom].rom_page = (offset & 1); |
| 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | |
| 1791 | static int load_legacy(const device_config *image) |
| 1792 | { |
| 1793 | const device_config *cartsys = image->owner; |
| 1794 | ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token; |
| 1795 | |
| 1796 | /* Some comments originally in machine/ti99_4x.c */ |
| 1797 | |
| 1798 | /* We identify file types according to their extension */ |
| 1799 | /* Note that if we do not recognize the extension, we revert to the slot location <-> type |
| 1800 | scheme. */ |
| 1801 | int id = 0; |
| 1802 | int i; |
| 1803 | int filesize; |
| 1804 | int maxrom = 0x2000; |
| 1805 | slotc_type_t type; |
| 1806 | int savembx; |
| 1807 | |
| 1808 | const char *ch, *ch2; |
| 1809 | const char *name = image_filename(image); |
| 1810 | |
| 1811 | UINT8 *grom = memory_region(image->machine, region_grom) + 0x6000; |
| 1812 | UINT16 *cartrom = (UINT16 *) (memory_region(image->machine, "maincpu") + offset_cart); |
| 1813 | UINT16 *cartrom2 = (UINT16 *) (memory_region(image->machine, "maincpu") + offset_cart + 0x2000); |
| 1814 | UINT8 *cart8rom = memory_region(image->machine, "maincpu") + offset_cart_8; |
| 1815 | UINT8 *cart8rom2 = memory_region(image->machine, "maincpu") + offset_cart_8 + 0x2000; |
| 1816 | |
| 1817 | UINT16 *cartmbx; |
| 1818 | UINT8 *cartmbx8; |
| 1819 | |
| 1820 | type = SLOTC_EMPTY; |
| 1821 | |
| 1822 | /* There is a circuitry in TI99/4(a) that resets the console when a |
| 1823 | cartridge is inserted or removed. We emulate this instead of resetting the |
| 1824 | emulator (which is the default in MESS). */ |
| 1825 | /*cpu_set_input_line(machine->cpu[0], INPUT_LINE_RESET, PULSE_LINE); |
| 1826 | tms9901_reset(0); |
| 1827 | if (! has_evpc) |
| 1828 | TMS9928A_reset(); |
| 1829 | if (has_evpc) |
| 1830 | v9938_reset(0);*/ |
| 1831 | |
| 1832 | ch = strrchr(name, '.'); |
| 1833 | ch2 = (ch-1 >= name) ? ch-1 : ""; |
| 1834 | |
| 1835 | if (ch) |
| 1836 | { |
| 1837 | if (! mame_stricmp(ch2, "g.bin")) |
| 1838 | { |
| 1839 | /* grom */ |
| 1840 | type = SLOTC_GROM; |
| 1841 | } |
| 1842 | else if (! mame_stricmp(ch2, "c.bin")) |
| 1843 | { |
| 1844 | /* rom first page */ |
| 1845 | type = SLOTC_CROM; |
| 1846 | } |
| 1847 | else if (! mame_stricmp(ch2, "d.bin")) |
| 1848 | { |
| 1849 | /* rom second page */ |
| 1850 | type = SLOTC_DROM; |
| 1851 | } |
| 1852 | else if (! mame_stricmp(ch2, "m.bin")) |
| 1853 | { |
| 1854 | /* rom minimemory */ |
| 1855 | type = SLOTC_MINIMEM; |
| 1856 | } |
| 1857 | else if (! mame_stricmp(ch2, "b.bin")) |
| 1858 | { |
| 1859 | /* rom MBX */ |
| 1860 | type = SLOTC_MBX; |
| 1861 | } |
| 1862 | } |
| 1863 | |
| 1864 | if (type == SLOTC_EMPTY) |
| 1865 | { |
| 1866 | return INIT_FAIL; |
| 1867 | } |
| 1868 | |
| 1869 | id = get_index_from_tagname(image)-1; |
| 1870 | |
| 1871 | /* Remember where the cartridge part is plugged in. */ |
| 1872 | cartslots->legacy_slotnumber[type] = id; |
| 1873 | |
| 1874 | savembx = FALSE; |
| 1875 | |
| 1876 | /* We will use the already allocated buffers in the memory regions, |
| 1877 | and the pointers in the cartridge structure will point to them. */ |
| 1878 | switch (type) |
| 1879 | { |
| 1880 | case SLOTC_EMPTY: |
| 1881 | break; |
| 1882 | |
| 1883 | case SLOTC_GROM: |
| 1884 | filesize = image_fread(image, grom, 0xA000); |
| 1885 | cartslots->cartridge[id].grom_ptr = grom; |
| 1886 | cartslots->cartridge[id].grom_size = filesize; |
| 1887 | // printf("loaded GROM, size = %d\n", filesize); |
| 1888 | break; |
| 1889 | |
| 1890 | case SLOTC_CROM: |
| 1891 | maxrom = 0x2000; |
| 1892 | if (cartslots->legacy_slotnumber[SLOTC_MINIMEM] != -1) |
| 1893 | { |
| 1894 | /* This means the NVRAM has already been loaded. So we just |
| 1895 | load 4K of ROM to avoid overwriting the NVRAM. */ |
| 1896 | maxrom = 0x1000; |
| 1897 | } |
| 1898 | |
| 1899 | if (cartslots->legacy_slotnumber[SLOTC_MBX] != -1) |
| 1900 | { |
| 1901 | /* This means the NVRAM has already been loaded. |
| 1902 | We need to temporarily save the RAM contents and |
| 1903 | write them back because the RAM overrides the |
| 1904 | ROM in an intermediate area. */ |
| 1905 | savembx = TRUE; |
| 1906 | } |
| 1907 | |
| 1908 | if (is_99_8()) |
| 1909 | { |
| 1910 | // printf("** is 99/8\n"); |
| 1911 | if (savembx==TRUE) |
| 1912 | { |
| 1913 | cartmbx8 = malloc(0x400); |
| 1914 | memcpy(cartmbx8, cart8rom + 0x0c00, 0x400); |
| 1915 | filesize = image_fread(image, cart8rom, maxrom); |
| 1916 | memcpy(cart8rom + 0xc00, cartmbx8, 0x400); |
| 1917 | free(cartmbx8); |
| 1918 | } |
| 1919 | else |
| 1920 | { |
| 1921 | filesize = image_fread(image, cart8rom, maxrom); |
| 1922 | } |
| 1923 | cartslots->cartridge[id].rom_ptr = cart8rom; |
| 1924 | cartslots->cartridge[id].rom_size = filesize; |
| 1925 | } |
| 1926 | else |
| 1927 | { |
| 1928 | if (savembx==TRUE) |
| 1929 | { |
| 1930 | cartmbx = malloc(0x400); |
| 1931 | memcpy(cartmbx, cartrom + 0x0600, 0x400); |
| 1932 | filesize = image_fread(image, cartrom, maxrom); |
| 1933 | memcpy(cartrom + 0x0600, cartmbx, 0x400); |
| 1934 | free(cartmbx); |
| 1935 | } |
| 1936 | filesize = image_fread(image, cartrom, maxrom); |
| 1937 | for (i = 0; i < maxrom/2; i++) |
| 1938 | ((UINT16 *)cartrom)[i] = BIG_ENDIANIZE_INT16(((UINT16 *)cartrom)[i]); |
| 1939 | cartslots->cartridge[id].rom_ptr = cartrom; |
| 1940 | cartslots->cartridge[id].rom_size = filesize; |
| 1941 | } |
| 1942 | // printf("loaded ROM, size = %d\n", filesize); |
| 1943 | break; |
| 1944 | |
| 1945 | case SLOTC_MINIMEM: |
| 1946 | /* Load the NVRAM. Need to BIG_ENDIANIZE it. |
| 1947 | MiniMemory has only one cartridge page. */ |
| 1948 | if (is_99_8()) |
| 1949 | { |
| 1950 | // printf("** is 99/8\n"); |
| 1951 | image_battery_load(image, cart8rom+0x1000,0x1000); |
| 1952 | cartslots->cartridge[id].ram_ptr = cart8rom + 0x1000; |
| 1953 | } |
| 1954 | else |
| 1955 | { |
| 1956 | image_battery_load(image, cartrom+0x800,0x1000); |
| 1957 | for (i = 0x800; i < 0x1000; i++) |
| 1958 | cartrom[i] = BIG_ENDIANIZE_INT16(cartrom[i]); |
| 1959 | cartslots->cartridge[id].ram_ptr = (UINT16 *)cartrom + 0x800; |
| 1960 | } |
| 1961 | cartslots->cartridge[id].ram_size = 0x1000; |
| 1962 | // printf("loaded NVRAM\n"); |
| 1963 | break; |
| 1964 | |
| 1965 | case SLOTC_MBX: |
| 1966 | /* Load the NVRAM. Need to BIG_ENDIANIZE it. */ |
| 1967 | if (is_99_8()) |
| 1968 | { |
| 1969 | // printf("** is 99/8\n"); |
| 1970 | image_battery_load(image, cart8rom+0x0c00, 0x0400); |
| 1971 | cartslots->cartridge[id].ram_ptr = cart8rom + 0xc00; |
| 1972 | } |
| 1973 | else |
| 1974 | { |
| 1975 | image_battery_load(image, cartrom+0x0600, 0x0400); |
| 1976 | for (i = 0x0600; i < 0x0800; i++) |
| 1977 | cartrom[i] = BIG_ENDIANIZE_INT16(cartrom[i]); |
| 1978 | cartslots->cartridge[id].ram_ptr = (UINT16 *)cartrom + 0x600; |
| 1979 | } |
| 1980 | cartslots->cartridge[id].ram_size = 0x0400; |
| 1981 | // printf("loaded NVRAM\n"); |
| 1982 | break; |
| 1983 | |
| 1984 | case SLOTC_DROM: |
| 1985 | maxrom = 0x2000; |
| 1986 | if (is_99_8()) |
| 1987 | { |
| 1988 | // printf("** is 99/8\n"); |
| 1989 | filesize = image_fread(image, cart8rom2, maxrom); |
| 1990 | cartslots->cartridge[id].rom2_ptr = cart8rom2; |
| 1991 | } |
| 1992 | else |
| 1993 | { |
| 1994 | filesize = image_fread(image, cartrom2, maxrom); |
| 1995 | for (i = 0; i < maxrom/2; i++) |
| 1996 | cartrom2[i] = BIG_ENDIANIZE_INT16(cartrom2[i]); |
| 1997 | cartslots->cartridge[id].rom2_ptr = cartrom2; |
| 1998 | } |
| 1999 | cartslots->cartridge[id].rom_size = filesize; |
| 2000 | // printf("loaded second ROM, size = %d\n", filesize); |
| 2001 | break; |
| 2002 | } |
| 2003 | return INIT_PASS; |
| 2004 | } |
| 2005 | |
| 2006 | static void unload_legacy(const device_config *image) |
| 2007 | { |
| 2008 | int i; |
| 2009 | const device_config *cartsys = image->owner; |
| 2010 | |
| 2011 | ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token; |
| 2012 | |
| 2013 | slotc_type_t type = SLOTC_EMPTY; |
| 2014 | int slot = get_index_from_tagname(image)-1; |
| 2015 | |
| 2016 | // printf("non-rpk unload\n"); |
| 2017 | |
| 2018 | for (i=0; (i < 5) && (type==SLOTC_EMPTY); i++) |
| 2019 | { |
| 2020 | if (cartslots->legacy_slotnumber[i]==slot) |
| 2021 | { |
| 2022 | cartslots->legacy_slotnumber[i] = -1; |
| 2023 | type = (slotc_type_t)i; |
| 2024 | } |
| 2025 | } |
| 2026 | |
| 2027 | switch (type) |
| 2028 | { |
| 2029 | case SLOTC_EMPTY: |
| 2030 | break; |
| 2031 | |
| 2032 | case SLOTC_GROM: |
| 2033 | memset(cartslots->cartridge[slot].grom_ptr, 0, 0xA000); |
| 2034 | break; |
| 2035 | |
| 2036 | case SLOTC_MINIMEM: |
| 2037 | if (is_99_8()) |
| 2038 | { |
| 2039 | // printf("** is 99/8\n"); |
| 2040 | image_battery_save(image, cartslots->cartridge[slot].ram_ptr, 0x1000); |
| 2041 | memset(cartslots->cartridge[slot].ram_ptr, 0, 0x1000); |
| 2042 | } |
| 2043 | else |
| 2044 | { |
| 2045 | /* We BIG_ENDIANIZE before saving. This is consistent |
| 2046 | with the cartridge save format. */ |
| 2047 | UINT16 *ramcont = (UINT16 *)cartslots->cartridge[slot].ram_ptr; |
| 2048 | for (i = 0; i < 0x0800; i++) |
| 2049 | ramcont[i] = BIG_ENDIANIZE_INT16(ramcont[i]); |
| 2050 | image_battery_save(image, ramcont, 0x1000); |
| 2051 | memset(ramcont, 0, 0x1000); |
| 2052 | } |
| 2053 | break; |
| 2054 | case SLOTC_MBX: |
| 2055 | if (is_99_8()) |
| 2056 | { |
| 2057 | // printf("** is 99/8\n"); |
| 2058 | image_battery_save(image, cartslots->cartridge[slot].ram_ptr, 0x0400); |
| 2059 | memset(cartslots->cartridge[slot].ram_ptr, 0, 0x0400); |
| 2060 | } |
| 2061 | else |
| 2062 | { |
| 2063 | /* We BIG_ENDIANIZE before saving. This is consistent |
| 2064 | with the cartridge save format. */ |
| 2065 | UINT16 *ramcont = (UINT16 *)cartslots->cartridge[slot].ram_ptr; |
| 2066 | for (i = 0; i < 0x0200; i++) |
| 2067 | ramcont[i] = BIG_ENDIANIZE_INT16(ramcont[i]); |
| 2068 | image_battery_save(image, ramcont, 0x0400); |
| 2069 | memset(ramcont, 0, 0x0400); |
| 2070 | } |
| 2071 | break; |
| 2072 | case SLOTC_CROM: |
| 2073 | if (cartslots->legacy_slotnumber[SLOTC_MINIMEM]!=-1) |
| 2074 | /* Don't wipe the RAM before it is saved. */ |
| 2075 | memset(cartslots->cartridge[slot].rom_ptr, 0, 0x1000); |
| 2076 | else |
| 2077 | memset(cartslots->cartridge[slot].rom_ptr, 0, 0x2000); |
| 2078 | break; |
| 2079 | |
| 2080 | case SLOTC_DROM: |
| 2081 | cartslots->cartridge[slot].rom_page = 0; |
| 2082 | memset(cartslots->cartridge[slot].rom2_ptr, 0, 0x2000); |
| 2083 | break; |
| 2084 | } |
| 2085 | |
| 2086 | clear_slot(cartsys, slot); |
| 2087 | } |
| 2088 | |
| 2089 | /***************************************************************************** |
| 2090 | The overall multi-cartridge slot system. It contains instances of |
| 2091 | cartridges which contain PCB devices. The memory handlers delegate the calls |
| 2092 | to the respective handlers of the cartridges. |
| 2093 | |
| 2094 | Note that the term "multi-cartridge system" and "multicart" are not the same: |
| 2095 | A "multicart" may contain multiple resources, organized on a PCB. The multi- |
| 2096 | cart system may thus host multiple multicarts. |
| 2097 | |
| 2098 | Actually, the name of the device should be changed (however, the device name |
| 2099 | length is limited) |
| 2100 | ******************************************************************************/ |
| 2101 | /* |
| 2102 | Instantiation of a multicart system for the TI family. |
| 2103 | */ |
| 2104 | static DEVICE_START(ti99_multicart) |
| 2105 | { |
| 2106 | int i; |
| 2107 | // printf("DEVICE_START(ti99_multicart)\n"); |
| 2108 | ti99_multicart_t *cartslots = (ti99_multicart_t *)device->token; |
| 2109 | |
| 2110 | /* Save this in the shortcut; we don't want to look for it each time |
| 2111 | that we have a memory access. And currently we do not plan for |
| 2112 | multiple multicart instances. */ |
| 2113 | cartslots->active_slot = 0; |
| 2114 | cartslots->next_free_slot = 0; |
| 2115 | |
| 2116 | for (i=0; i < NUMBER_OF_CARTRIDGE_SLOTS; i++) |
| 2117 | { |
| 2118 | cartslots->cartridge[i].pcb = NULL; |
| 2119 | } |
| 2120 | |
| 2121 | /* Initialize the legacy system. */ |
| 2122 | cartslots->legacy_slotnumber[SLOTC_GROM] = -1; |
| 2123 | cartslots->legacy_slotnumber[SLOTC_CROM] = -1; |
| 2124 | cartslots->legacy_slotnumber[SLOTC_DROM] = -1; |
| 2125 | cartslots->legacy_slotnumber[SLOTC_MINIMEM] = -1; |
| 2126 | cartslots->legacy_slotnumber[SLOTC_MBX] = -1; |
| 2127 | |
| 2128 | cartslots->legacy_slots = 0; |
| 2129 | cartslots->multi_slots = 0; |
| 2130 | |
| 2131 | /* The cartslot system is initialized now. The cartridges themselves |
| 2132 | need to check whether their parts are available. */ |
| 2133 | } |
| 2134 | |
| 2135 | static DEVICE_STOP(ti99_multicart) |
| 2136 | { |
| 2137 | // printf("DEVICE_STOP(ti99_multicart)\n"); |
| 2138 | } |
| 2139 | /* |
| 2140 | Accesses the ROM regions of the cartridge for reading. |
| 2141 | This is the area from 0x6000 to 0x7fff. Each cartridge is reponsible |
| 2142 | for all kinds of magic which is done inside this area, like swapping |
| 2143 | banks or doing other control actions. These activities beyond simple |
| 2144 | reading are cartridge-specific. Each kind of cartridge requires a |
| 2145 | new type. |
| 2146 | The currently set GROM bank determines which cartridge is actually |
| 2147 | accessed, also for ROM reads. |
| 2148 | */ |
| 2149 | READ16_DEVICE_HANDLER( ti99_multicart_r ) |
| 2150 | { |
| 2151 | ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token; |
| 2152 | cartridge_t *cart = &cartslots->cartridge[cartslots->active_slot]; |
| 2153 | |
| 2154 | /* Idle the CPU */ |
| 2155 | cpu_adjust_icount(cputag_get_cpu(device->machine, "maincpu"),-4); |
| 2156 | |
| 2157 | // Alternatively: |
| 2158 | // cpu_spinuntil_time(device->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 2159 | |
| 2160 | // printf("rpk = %d, bin = %d\n", cartslots->multi_slots,cartslots->legacy_slots); |
| 2161 | |
| 2162 | /* Handle legacy mode. */ |
| 2163 | if (in_legacy_mode(device)) |
| 2164 | { |
| 2165 | return ti99_cart_r_legacy(device, offset, mem_mask); |
| 2166 | } |
| 2167 | |
| 2168 | if (cart->pcb!=NULL) |
| 2169 | { |
| 2170 | // printf("accessing cartridge in slot %d\n", cartslots->active_slot); |
| 2171 | ti99_pcb_t *pcbdef = (ti99_pcb_t *)cart->pcb->token; |
| 2172 | return (*pcbdef->read)(cart->pcb, offset, mem_mask); |
| 2173 | } |
| 2174 | else |
| 2175 | { |
| 2176 | // printf("No cartridge in slot %d\n", cartslots->active_slot); |
| 2177 | return 0; |
| 2178 | } |
| 2179 | } |
| 2180 | |
| 2181 | /* |
| 2182 | Accesses the ROM regions of the cartridge for writing. |
| 2183 | This is the area from 0x6000 to 0x7fff. Each cartridge is reponsible |
| 2184 | for all kinds of magic which is done inside this area. Specifically, |
| 2185 | writing is often used to swap banks for subsequent reads. The actual |
| 2186 | effect of writing (beyond setting values in a RAM chip) are |
| 2187 | cartridge-specific and must be handled within the cartridge pcb. |
| 2188 | The currently set GROM bank determines which cartridge is actually |
| 2189 | accessed, also for ROM reads. |
| 2190 | */ |
| 2191 | WRITE16_DEVICE_HANDLER( ti99_multicart_w ) |
| 2192 | { |
| 2193 | ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token; |
| 2194 | |
| 2195 | cartridge_t *cart = &cartslots->cartridge[cartslots->active_slot]; |
| 2196 | |
| 2197 | /* Idle the CPU */ |
| 2198 | cpu_adjust_icount(cputag_get_cpu(device->machine, "maincpu"),-4); |
| 2199 | // cpu_spinuntil_time(device->machine->cpu[0], ATTOTIME_IN_USEC(6)); |
| 2200 | |
| 2201 | /* Handle legacy mode. */ |
| 2202 | if (in_legacy_mode(device)) |
| 2203 | { |
| 2204 | ti99_cart_w_legacy(device, offset, data, mem_mask); |
| 2205 | } |
| 2206 | else |
| 2207 | { |
| 2208 | if (cart->pcb!=NULL) |
| 2209 | { |
| 2210 | // printf("writing to cartridge in slot %d\n", cartslots->active_slot); |
| 2211 | ti99_pcb_t *pcbdef = (ti99_pcb_t *)cart->pcb->token; |
| 2212 | (*pcbdef->write)(cart->pcb, offset, data, mem_mask); |
| 2213 | } |
| 2214 | } |
| 2215 | } |
| 2216 | |
| 2217 | /* |
| 2218 | CRU interface to cartridges, used only by SuperSpace-style cartridges. |
| 2219 | The SuperSpace has a CRU-based memory mapper. It is accessed via the |
| 2220 | cartridge slot on CRU base >0800. |
| 2221 | */ |
| 2222 | READ8_DEVICE_HANDLER( ti99_multicart_cru_r ) |
| 2223 | { |
| 2224 | ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token; |
| 2225 | cartridge_t *cart = &cartslots->cartridge[cartslots->active_slot]; |
| 2226 | |
| 2227 | if (cart->pcb!=NULL) |
| 2228 | { |
| 2229 | ti99_pcb_t *pcbdef = (ti99_pcb_t *)cart->pcb->token; |
| 2230 | if (pcbdef->cruread != NULL) |
| 2231 | return (*pcbdef->cruread)(cart->pcb, offset); |
| 2232 | } |
| 2233 | return 0; |
| 2234 | } |
| 2235 | |
| 2236 | /* |
| 2237 | Write cartridge mapper CRU interface (SuperSpace) |
| 2238 | */ |
| 2239 | WRITE8_DEVICE_HANDLER( ti99_multicart_cru_w ) |
| 2240 | { |
| 2241 | ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token; |
| 2242 | cartridge_t *cart = &cartslots->cartridge[cartslots->active_slot]; |
| 2243 | |
| 2244 | if (cart->pcb!=NULL) |
| 2245 | { |
| 2246 | ti99_pcb_t *pcbdef = (ti99_pcb_t *)cart->pcb->token; |
| 2247 | if (pcbdef->cruwrite != NULL) |
| 2248 | (*pcbdef->cruwrite)(cart->pcb, offset, data); |
| 2249 | } |
| 2250 | } |
| 2251 | |
| 2252 | /* |
| 2253 | TI-99/8 support. We have only 8 bit memory access, so we adapt all |
| 2254 | functions to this width. |
| 2255 | */ |
| 2256 | READ8_DEVICE_HANDLER(ti99_multicart8_r) |
| 2257 | { |
| 2258 | ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token; |
| 2259 | cartridge_t *cart = &cartslots->cartridge[cartslots->active_slot]; |
| 2260 | |
| 2261 | /* Idle the CPU. TODO: Check whether this is correct for this machine. */ |
| 2262 | cpu_adjust_icount(cputag_get_cpu(device->machine, "maincpu"),-4); |
| 2263 | |
| 2264 | /* Handle legacy mode. */ |
| 2265 | if (in_legacy_mode(device)) |
| 2266 | { |
| 2267 | return ti99_cart_r_legacy8(device, offset); |
| 2268 | } |
| 2269 | |
| 2270 | if (cart->pcb!=NULL) |
| 2271 | { |
| 2272 | // printf("accessing cartridge in slot %d\n", cartslots->active_slot); |
| 2273 | ti99_pcb_t *pcbdef = (ti99_pcb_t *)cart->pcb->token; |
| 2274 | return (*pcbdef->read8)(cart->pcb, offset); |
| 2275 | } |
| 2276 | else |
| 2277 | { |
| 2278 | // printf("No cartridge in slot %d\n", cartslots->active_slot); |
| 2279 | return 0; |
| 2280 | } |
| 2281 | } |
| 2282 | |
| 2283 | WRITE8_DEVICE_HANDLER(ti99_multicart8_w) |
| 2284 | { |
| 2285 | ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token; |
| 2286 | |
| 2287 | cartridge_t *cart = &cartslots->cartridge[cartslots->active_slot]; |
| 2288 | |
| 2289 | /* Idle the CPU. TODO: Check whether this is correct for this machine. */ |
| 2290 | cpu_adjust_icount(cputag_get_cpu(device->machine, "maincpu"),-4); |
| 2291 | |
| 2292 | /* Handle legacy mode. */ |
| 2293 | if (in_legacy_mode(device)) |
| 2294 | { |
| 2295 | ti99_cart_w_legacy8(device, offset, data); |
| 2296 | } |
| 2297 | else |
| 2298 | { |
| 2299 | if (cart->pcb!=NULL) |
| 2300 | { |
| 2301 | ti99_pcb_t *pcbdef = (ti99_pcb_t *)cart->pcb->token; |
| 2302 | (*pcbdef->write8)(cart->pcb, offset, data); |
| 2303 | } |
| 2304 | } |
| 2305 | } |
| 2306 | |
| 2307 | static MACHINE_DRIVER_START(ti99_multicart) |
| 2308 | MDRV_CARTSLOT_ADD("cartridge1") |
| 2309 | MDRV_CARTSLOT_EXTENSION_LIST("rpk,bin") |
| 2310 | MDRV_CARTSLOT_PCBTYPE(0, "none", TI99_CARTRIDGE_PCB_NONE) |
| 2311 | MDRV_CARTSLOT_PCBTYPE(1, "standard", TI99_CARTRIDGE_PCB_STD) |
| 2312 | MDRV_CARTSLOT_PCBTYPE(2, "paged", TI99_CARTRIDGE_PCB_PAGED) |
| 2313 | MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM) |
| 2314 | MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER) |
| 2315 | MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX) |
| 2316 | // MDRV_CARTSLOT_PCBTYPE(6, "gk", TI99_CARTRIDGE_PCB_GK) |
| 2317 | |
| 2318 | MDRV_CARTSLOT_START(ti99_cartridge) |
| 2319 | MDRV_CARTSLOT_LOAD(ti99_cartridge) |
| 2320 | MDRV_CARTSLOT_UNLOAD(ti99_cartridge) |
| 2321 | |
| 2322 | MDRV_CARTSLOT_ADD("cartridge2") |
| 2323 | MDRV_CARTSLOT_EXTENSION_LIST("rpk,bin") |
| 2324 | MDRV_CARTSLOT_PCBTYPE(0, "none", TI99_CARTRIDGE_PCB_NONE) |
| 2325 | MDRV_CARTSLOT_PCBTYPE(1, "standard", TI99_CARTRIDGE_PCB_STD) |
| 2326 | MDRV_CARTSLOT_PCBTYPE(2, "paged", TI99_CARTRIDGE_PCB_PAGED) |
| 2327 | MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM) |
| 2328 | MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER) |
| 2329 | MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX) |
| 2330 | // MDRV_CARTSLOT_PCBTYPE(6, "gk", TI99_CARTRIDGE_PCB_GK) |
| 2331 | MDRV_CARTSLOT_START(ti99_cartridge) |
| 2332 | MDRV_CARTSLOT_LOAD(ti99_cartridge) |
| 2333 | MDRV_CARTSLOT_UNLOAD(ti99_cartridge) |
| 2334 | |
| 2335 | MDRV_CARTSLOT_ADD("cartridge3") |
| 2336 | MDRV_CARTSLOT_EXTENSION_LIST("rpk,bin") |
| 2337 | MDRV_CARTSLOT_PCBTYPE(0, "none", TI99_CARTRIDGE_PCB_NONE) |
| 2338 | MDRV_CARTSLOT_PCBTYPE(1, "standard", TI99_CARTRIDGE_PCB_STD) |
| 2339 | MDRV_CARTSLOT_PCBTYPE(2, "paged", TI99_CARTRIDGE_PCB_PAGED) |
| 2340 | MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM) |
| 2341 | MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER) |
| 2342 | MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX) |
| 2343 | // MDRV_CARTSLOT_PCBTYPE(6, "gk", TI99_CARTRIDGE_PCB_GK) |
| 2344 | MDRV_CARTSLOT_START(ti99_cartridge) |
| 2345 | MDRV_CARTSLOT_LOAD(ti99_cartridge) |
| 2346 | MDRV_CARTSLOT_UNLOAD(ti99_cartridge) |
| 2347 | |
| 2348 | MDRV_CARTSLOT_ADD("cartridge4") |
| 2349 | MDRV_CARTSLOT_EXTENSION_LIST("rpk,bin") |
| 2350 | MDRV_CARTSLOT_PCBTYPE(0, "none", TI99_CARTRIDGE_PCB_NONE) |
| 2351 | MDRV_CARTSLOT_PCBTYPE(1, "standard", TI99_CARTRIDGE_PCB_STD) |
| 2352 | MDRV_CARTSLOT_PCBTYPE(2, "paged", TI99_CARTRIDGE_PCB_PAGED) |
| 2353 | MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM) |
| 2354 | MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER) |
| 2355 | MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX) |
| 2356 | // MDRV_CARTSLOT_PCBTYPE(6, "gk", TI99_CARTRIDGE_PCB_GK) |
| 2357 | MDRV_CARTSLOT_START(ti99_cartridge) |
| 2358 | MDRV_CARTSLOT_LOAD(ti99_cartridge) |
| 2359 | MDRV_CARTSLOT_UNLOAD(ti99_cartridge) |
| 2360 | MACHINE_DRIVER_END |
| 2361 | |
| 2362 | static DEVICE_SET_INFO(ti99_multicart) |
| 2363 | { |
| 2364 | // printf("device_set_info(ti99-cart)"); |
| 2365 | } |
| 2366 | |
| 2367 | |
| 2368 | DEVICE_GET_INFO(ti99_multicart) |
| 2369 | { |
| 2370 | switch (state) |
| 2371 | { |
| 2372 | /* --- the following bits of info are returned as pointers to data --- */ |
| 2373 | case DEVINFO_PTR_MACHINE_CONFIG: |
| 2374 | info->machine_config = MACHINE_DRIVER_NAME(ti99_multicart); break; |
| 2375 | |
| 2376 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 2377 | case DEVINFO_STR_NAME: |
| 2378 | strcpy(info->s, "TI99 Multi-Cartridge Extender"); |
| 2379 | break; |
| 2380 | |
| 2381 | case DEVINFO_INT_TOKEN_BYTES: /* private storage, automatically allocated */ |
| 2382 | info->i = sizeof(ti99_multicart_t); |
| 2383 | break; |
| 2384 | case DEVINFO_INT_CLASS: |
| 2385 | info->i = DEVICE_CLASS_PERIPHERAL; |
| 2386 | break; |
| 2387 | |
| 2388 | case DEVINFO_STR_FAMILY: |
| 2389 | strcpy(info->s, "Multi-cartridge system"); |
| 2390 | break; |
| 2391 | case DEVINFO_STR_VERSION: |
| 2392 | strcpy(info->s, "1.0"); |
| 2393 | break; |
| 2394 | case DEVINFO_STR_SOURCE_FILE: |
| 2395 | strcpy(info->s, __FILE__); |
| 2396 | break; |
| 2397 | /* --- the following bits of info are returned as pointers to functions --- */ |
| 2398 | case DEVINFO_FCT_SET_INFO: |
| 2399 | info->set_info = DEVICE_SET_INFO_NAME(ti99_multicart); |
| 2400 | break; |
| 2401 | case DEVINFO_FCT_START: |
| 2402 | info->start = DEVICE_START_NAME(ti99_multicart); |
| 2403 | break; |
| 2404 | case DEVINFO_FCT_STOP: |
| 2405 | info->stop = DEVICE_STOP_NAME(ti99_multicart); |
| 2406 | break; |
| 2407 | case DEVINFO_FCT_RESET: |
| 2408 | /* Nothing */ |
| 2409 | break; |
| 2410 | } |
| 2411 | } |
| 2412 | |