src/mess/machine/cbm.c
| r7954 | r7955 | |
| 1 | 1 | #include "emu.h" |
| 2 | | #include "devices/cartslot.h" |
| 3 | 2 | #include "devices/cassette.h" |
| 4 | 3 | #include "crsshair.h" |
| 5 | 4 | #include "includes/cbm.h" |
| r7954 | r7955 | |
| 326 | 325 | |
| 327 | 326 | /*********************************************** |
| 328 | 327 | |
| 329 | | CBM Quickloads |
| 330 | | |
| 331 | | ***********************************************/ |
| 332 | | |
| 333 | | |
| 334 | | static int general_cbm_loadsnap( running_device *image, const char *file_type, int snapshot_size, |
| 335 | | offs_t offset, void (*cbm_sethiaddress)(running_machine *machine, UINT16 hiaddress) ) |
| 336 | | { |
| 337 | | char buffer[7]; |
| 338 | | UINT8 *data = NULL; |
| 339 | | UINT32 bytesread; |
| 340 | | UINT16 address = 0; |
| 341 | | int i; |
| 342 | | const address_space *space = cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM); |
| 343 | | |
| 344 | | if (!file_type) |
| 345 | | goto error; |
| 346 | | |
| 347 | | if (!mame_stricmp(file_type, "prg")) |
| 348 | | { |
| 349 | | /* prg files */ |
| 350 | | } |
| 351 | | else if (!mame_stricmp(file_type, "p00")) |
| 352 | | { |
| 353 | | /* p00 files */ |
| 354 | | if (image_fread(image, buffer, sizeof(buffer)) != sizeof(buffer)) |
| 355 | | goto error; |
| 356 | | if (memcmp(buffer, "C64File", sizeof(buffer))) |
| 357 | | goto error; |
| 358 | | image_fseek(image, 26, SEEK_SET); |
| 359 | | snapshot_size -= 26; |
| 360 | | } |
| 361 | | else if (!mame_stricmp(file_type, "t64")) |
| 362 | | { |
| 363 | | /* t64 files - for GB64 Single T64s loading to x0801 - header is always the same size */ |
| 364 | | if (image_fread(image, buffer, sizeof(buffer)) != sizeof(buffer)) |
| 365 | | goto error; |
| 366 | | if (memcmp(buffer, "C64 tape image file", sizeof(buffer))) |
| 367 | | goto error; |
| 368 | | image_fseek(image, 94, SEEK_SET); |
| 369 | | snapshot_size -= 94; |
| 370 | | } |
| 371 | | else |
| 372 | | { |
| 373 | | goto error; |
| 374 | | } |
| 375 | | |
| 376 | | image_fread(image, &address, 2); |
| 377 | | address = LITTLE_ENDIANIZE_INT16(address); |
| 378 | | if (!mame_stricmp(file_type, "t64")) |
| 379 | | address = 2049; |
| 380 | | snapshot_size -= 2; |
| 381 | | |
| 382 | | data = (UINT8*)malloc(snapshot_size); |
| 383 | | if (!data) |
| 384 | | goto error; |
| 385 | | |
| 386 | | bytesread = image_fread(image, data, snapshot_size); |
| 387 | | if (bytesread != snapshot_size) |
| 388 | | goto error; |
| 389 | | |
| 390 | | for (i = 0; i < snapshot_size; i++) |
| 391 | | memory_write_byte(space, address + i + offset, data[i]); |
| 392 | | |
| 393 | | cbm_sethiaddress(image->machine, address + snapshot_size); |
| 394 | | free(data); |
| 395 | | return INIT_PASS; |
| 396 | | |
| 397 | | error: |
| 398 | | if (data) |
| 399 | | free(data); |
| 400 | | return INIT_FAIL; |
| 401 | | } |
| 402 | | |
| 403 | | static void cbm_quick_sethiaddress( running_machine *machine, UINT16 hiaddress ) |
| 404 | | { |
| 405 | | const address_space *space = cpu_get_address_space(machine->firstcpu, ADDRESS_SPACE_PROGRAM); |
| 406 | | |
| 407 | | memory_write_byte(space, 0x31, hiaddress & 0xff); |
| 408 | | memory_write_byte(space, 0x2f, hiaddress & 0xff); |
| 409 | | memory_write_byte(space, 0x2d, hiaddress & 0xff); |
| 410 | | memory_write_byte(space, 0x32, hiaddress >> 8); |
| 411 | | memory_write_byte(space, 0x30, hiaddress >> 8); |
| 412 | | memory_write_byte(space, 0x2e, hiaddress >> 8); |
| 413 | | } |
| 414 | | |
| 415 | | QUICKLOAD_LOAD( cbm_c16 ) |
| 416 | | { |
| 417 | | return general_cbm_loadsnap(image, file_type, quickload_size, 0, cbm_quick_sethiaddress); |
| 418 | | } |
| 419 | | |
| 420 | | QUICKLOAD_LOAD( cbm_c64 ) |
| 421 | | { |
| 422 | | return general_cbm_loadsnap(image, file_type, quickload_size, 0, cbm_quick_sethiaddress); |
| 423 | | } |
| 424 | | |
| 425 | | QUICKLOAD_LOAD( cbm_vc20 ) |
| 426 | | { |
| 427 | | return general_cbm_loadsnap(image, file_type, quickload_size, 0, cbm_quick_sethiaddress); |
| 428 | | } |
| 429 | | |
| 430 | | static void cbm_pet_quick_sethiaddress( running_machine *machine, UINT16 hiaddress ) |
| 431 | | { |
| 432 | | const address_space *space = cpu_get_address_space(machine->firstcpu, ADDRESS_SPACE_PROGRAM); |
| 433 | | |
| 434 | | memory_write_byte(space, 0x2e, hiaddress & 0xff); |
| 435 | | memory_write_byte(space, 0x2c, hiaddress & 0xff); |
| 436 | | memory_write_byte(space, 0x2a, hiaddress & 0xff); |
| 437 | | memory_write_byte(space, 0x2f, hiaddress >> 8); |
| 438 | | memory_write_byte(space, 0x2d, hiaddress >> 8); |
| 439 | | memory_write_byte(space, 0x2b, hiaddress >> 8); |
| 440 | | } |
| 441 | | |
| 442 | | QUICKLOAD_LOAD( cbm_pet ) |
| 443 | | { |
| 444 | | return general_cbm_loadsnap(image, file_type, quickload_size, 0, cbm_pet_quick_sethiaddress); |
| 445 | | } |
| 446 | | |
| 447 | | static void cbm_pet1_quick_sethiaddress(running_machine *machine, UINT16 hiaddress) |
| 448 | | { |
| 449 | | const address_space *space = cpu_get_address_space(machine->firstcpu, ADDRESS_SPACE_PROGRAM); |
| 450 | | |
| 451 | | memory_write_byte(space, 0x80, hiaddress & 0xff); |
| 452 | | memory_write_byte(space, 0x7e, hiaddress & 0xff); |
| 453 | | memory_write_byte(space, 0x7c, hiaddress & 0xff); |
| 454 | | memory_write_byte(space, 0x81, hiaddress >> 8); |
| 455 | | memory_write_byte(space, 0x7f, hiaddress >> 8); |
| 456 | | memory_write_byte(space, 0x7d, hiaddress >> 8); |
| 457 | | } |
| 458 | | |
| 459 | | QUICKLOAD_LOAD( cbm_pet1 ) |
| 460 | | { |
| 461 | | return general_cbm_loadsnap(image, file_type, quickload_size, 0, cbm_pet1_quick_sethiaddress); |
| 462 | | } |
| 463 | | |
| 464 | | static void cbmb_quick_sethiaddress(running_machine *machine, UINT16 hiaddress) |
| 465 | | { |
| 466 | | const address_space *space = cpu_get_address_space(machine->firstcpu, ADDRESS_SPACE_PROGRAM); |
| 467 | | |
| 468 | | memory_write_byte(space, 0xf0046, hiaddress & 0xff); |
| 469 | | memory_write_byte(space, 0xf0047, hiaddress >> 8); |
| 470 | | } |
| 471 | | |
| 472 | | QUICKLOAD_LOAD( cbmb ) |
| 473 | | { |
| 474 | | return general_cbm_loadsnap(image, file_type, quickload_size, 0x10000, cbmb_quick_sethiaddress); |
| 475 | | } |
| 476 | | |
| 477 | | QUICKLOAD_LOAD( p500 ) |
| 478 | | { |
| 479 | | return general_cbm_loadsnap(image, file_type, quickload_size, 0, cbmb_quick_sethiaddress); |
| 480 | | } |
| 481 | | |
| 482 | | static void cbm_c65_quick_sethiaddress( running_machine *machine, UINT16 hiaddress ) |
| 483 | | { |
| 484 | | const address_space *space = cpu_get_address_space(machine->firstcpu, ADDRESS_SPACE_PROGRAM); |
| 485 | | |
| 486 | | memory_write_byte(space, 0x82, hiaddress & 0xff); |
| 487 | | memory_write_byte(space, 0x83, hiaddress >> 8); |
| 488 | | } |
| 489 | | |
| 490 | | QUICKLOAD_LOAD( cbm_c65 ) |
| 491 | | { |
| 492 | | return general_cbm_loadsnap(image, file_type, quickload_size, 0, cbm_c65_quick_sethiaddress); |
| 493 | | } |
| 494 | | |
| 495 | | |
| 496 | | /*********************************************** |
| 497 | | |
| 498 | 328 | CBM Cartridges |
| 499 | 329 | |
| 500 | 330 | ***********************************************/ |
src/mess/formats/cbm_snqk.c
| r0 | r7955 | |
| 1 | /*********************************************** |
| 2 | |
| 3 | CBM Quickloads |
| 4 | |
| 5 | ***********************************************/ |
| 6 | |
| 7 | #include "emu.h" |
| 8 | #include "cbm_snqk.h" |
| 9 | |
| 10 | static int general_cbm_loadsnap( running_device *image, const char *file_type, int snapshot_size, |
| 11 | offs_t offset, void (*cbm_sethiaddress)(running_machine *machine, UINT16 hiaddress) ) |
| 12 | { |
| 13 | char buffer[7]; |
| 14 | UINT8 *data = NULL; |
| 15 | UINT32 bytesread; |
| 16 | UINT16 address = 0; |
| 17 | int i; |
| 18 | const address_space *space = cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM); |
| 19 | |
| 20 | if (!file_type) |
| 21 | goto error; |
| 22 | |
| 23 | if (!mame_stricmp(file_type, "prg")) |
| 24 | { |
| 25 | /* prg files */ |
| 26 | } |
| 27 | else if (!mame_stricmp(file_type, "p00")) |
| 28 | { |
| 29 | /* p00 files */ |
| 30 | if (image_fread(image, buffer, sizeof(buffer)) != sizeof(buffer)) |
| 31 | goto error; |
| 32 | if (memcmp(buffer, "C64File", sizeof(buffer))) |
| 33 | goto error; |
| 34 | image_fseek(image, 26, SEEK_SET); |
| 35 | snapshot_size -= 26; |
| 36 | } |
| 37 | else if (!mame_stricmp(file_type, "t64")) |
| 38 | { |
| 39 | /* t64 files - for GB64 Single T64s loading to x0801 - header is always the same size */ |
| 40 | if (image_fread(image, buffer, sizeof(buffer)) != sizeof(buffer)) |
| 41 | goto error; |
| 42 | if (memcmp(buffer, "C64 tape image file", sizeof(buffer))) |
| 43 | goto error; |
| 44 | image_fseek(image, 94, SEEK_SET); |
| 45 | snapshot_size -= 94; |
| 46 | } |
| 47 | else |
| 48 | { |
| 49 | goto error; |
| 50 | } |
| 51 | |
| 52 | image_fread(image, &address, 2); |
| 53 | address = LITTLE_ENDIANIZE_INT16(address); |
| 54 | if (!mame_stricmp(file_type, "t64")) |
| 55 | address = 2049; |
| 56 | snapshot_size -= 2; |
| 57 | |
| 58 | data = (UINT8*)malloc(snapshot_size); |
| 59 | if (!data) |
| 60 | goto error; |
| 61 | |
| 62 | bytesread = image_fread(image, data, snapshot_size); |
| 63 | if (bytesread != snapshot_size) |
| 64 | goto error; |
| 65 | |
| 66 | for (i = 0; i < snapshot_size; i++) |
| 67 | memory_write_byte(space, address + i + offset, data[i]); |
| 68 | |
| 69 | cbm_sethiaddress(image->machine, address + snapshot_size); |
| 70 | free(data); |
| 71 | return INIT_PASS; |
| 72 | |
| 73 | error: |
| 74 | if (data) |
| 75 | free(data); |
| 76 | return INIT_FAIL; |
| 77 | } |
| 78 | |
| 79 | static void cbm_quick_sethiaddress( running_machine *machine, UINT16 hiaddress ) |
| 80 | { |
| 81 | const address_space *space = cpu_get_address_space(machine->firstcpu, ADDRESS_SPACE_PROGRAM); |
| 82 | |
| 83 | memory_write_byte(space, 0x31, hiaddress & 0xff); |
| 84 | memory_write_byte(space, 0x2f, hiaddress & 0xff); |
| 85 | memory_write_byte(space, 0x2d, hiaddress & 0xff); |
| 86 | memory_write_byte(space, 0x32, hiaddress >> 8); |
| 87 | memory_write_byte(space, 0x30, hiaddress >> 8); |
| 88 | memory_write_byte(space, 0x2e, hiaddress >> 8); |
| 89 | } |
| 90 | |
| 91 | QUICKLOAD_LOAD( cbm_c16 ) |
| 92 | { |
| 93 | return general_cbm_loadsnap(image, file_type, quickload_size, 0, cbm_quick_sethiaddress); |
| 94 | } |
| 95 | |
| 96 | QUICKLOAD_LOAD( cbm_c64 ) |
| 97 | { |
| 98 | return general_cbm_loadsnap(image, file_type, quickload_size, 0, cbm_quick_sethiaddress); |
| 99 | } |
| 100 | |
| 101 | QUICKLOAD_LOAD( cbm_vc20 ) |
| 102 | { |
| 103 | return general_cbm_loadsnap(image, file_type, quickload_size, 0, cbm_quick_sethiaddress); |
| 104 | } |
| 105 | |
| 106 | static void cbm_pet_quick_sethiaddress( running_machine *machine, UINT16 hiaddress ) |
| 107 | { |
| 108 | const address_space *space = cpu_get_address_space(machine->firstcpu, ADDRESS_SPACE_PROGRAM); |
| 109 | |
| 110 | memory_write_byte(space, 0x2e, hiaddress & 0xff); |
| 111 | memory_write_byte(space, 0x2c, hiaddress & 0xff); |
| 112 | memory_write_byte(space, 0x2a, hiaddress & 0xff); |
| 113 | memory_write_byte(space, 0x2f, hiaddress >> 8); |
| 114 | memory_write_byte(space, 0x2d, hiaddress >> 8); |
| 115 | memory_write_byte(space, 0x2b, hiaddress >> 8); |
| 116 | } |
| 117 | |
| 118 | QUICKLOAD_LOAD( cbm_pet ) |
| 119 | { |
| 120 | return general_cbm_loadsnap(image, file_type, quickload_size, 0, cbm_pet_quick_sethiaddress); |
| 121 | } |
| 122 | |
| 123 | static void cbm_pet1_quick_sethiaddress(running_machine *machine, UINT16 hiaddress) |
| 124 | { |
| 125 | const address_space *space = cpu_get_address_space(machine->firstcpu, ADDRESS_SPACE_PROGRAM); |
| 126 | |
| 127 | memory_write_byte(space, 0x80, hiaddress & 0xff); |
| 128 | memory_write_byte(space, 0x7e, hiaddress & 0xff); |
| 129 | memory_write_byte(space, 0x7c, hiaddress & 0xff); |
| 130 | memory_write_byte(space, 0x81, hiaddress >> 8); |
| 131 | memory_write_byte(space, 0x7f, hiaddress >> 8); |
| 132 | memory_write_byte(space, 0x7d, hiaddress >> 8); |
| 133 | } |
| 134 | |
| 135 | QUICKLOAD_LOAD( cbm_pet1 ) |
| 136 | { |
| 137 | return general_cbm_loadsnap(image, file_type, quickload_size, 0, cbm_pet1_quick_sethiaddress); |
| 138 | } |
| 139 | |
| 140 | static void cbmb_quick_sethiaddress(running_machine *machine, UINT16 hiaddress) |
| 141 | { |
| 142 | const address_space *space = cpu_get_address_space(machine->firstcpu, ADDRESS_SPACE_PROGRAM); |
| 143 | |
| 144 | memory_write_byte(space, 0xf0046, hiaddress & 0xff); |
| 145 | memory_write_byte(space, 0xf0047, hiaddress >> 8); |
| 146 | } |
| 147 | |
| 148 | QUICKLOAD_LOAD( cbmb ) |
| 149 | { |
| 150 | return general_cbm_loadsnap(image, file_type, quickload_size, 0x10000, cbmb_quick_sethiaddress); |
| 151 | } |
| 152 | |
| 153 | QUICKLOAD_LOAD( p500 ) |
| 154 | { |
| 155 | return general_cbm_loadsnap(image, file_type, quickload_size, 0, cbmb_quick_sethiaddress); |
| 156 | } |
| 157 | |
| 158 | static void cbm_c65_quick_sethiaddress( running_machine *machine, UINT16 hiaddress ) |
| 159 | { |
| 160 | const address_space *space = cpu_get_address_space(machine->firstcpu, ADDRESS_SPACE_PROGRAM); |
| 161 | |
| 162 | memory_write_byte(space, 0x82, hiaddress & 0xff); |
| 163 | memory_write_byte(space, 0x83, hiaddress >> 8); |
| 164 | } |
| 165 | |
| 166 | QUICKLOAD_LOAD( cbm_c65 ) |
| 167 | { |
| 168 | return general_cbm_loadsnap(image, file_type, quickload_size, 0, cbm_c65_quick_sethiaddress); |
| 169 | } |