trunk/src/mess/drivers/timex.c
| r21567 | r21568 | |
| 174 | 174 | |
| 175 | 175 | static timex_cart_t timex_cart; |
| 176 | 176 | |
| 177 | | |
| 178 | | DEVICE_IMAGE_LOAD_LEGACY( timex_cart ) |
| 179 | | { |
| 180 | | int file_size; |
| 181 | | UINT8 * file_data; |
| 182 | | |
| 183 | | int chunks_in_file = 0; |
| 184 | | |
| 185 | | int i; |
| 186 | | |
| 187 | | logerror ("Trying to load cart\n"); |
| 188 | | |
| 189 | | file_size = image.length(); |
| 190 | | |
| 191 | | if (file_size < 0x09) |
| 192 | | { |
| 193 | | logerror ("Bad file size\n"); |
| 194 | | return IMAGE_INIT_FAIL; |
| 195 | | } |
| 196 | | |
| 197 | | file_data = (UINT8 *)malloc(file_size); |
| 198 | | if (file_data == NULL) |
| 199 | | { |
| 200 | | logerror ("Memory allocating error\n"); |
| 201 | | return IMAGE_INIT_FAIL; |
| 202 | | } |
| 203 | | |
| 204 | | image.fread(file_data, file_size); |
| 205 | | |
| 206 | | for (i=0; i<8; i++) |
| 207 | | if(file_data[i+1]&0x02) chunks_in_file++; |
| 208 | | |
| 209 | | if (chunks_in_file*0x2000+0x09 != file_size) |
| 210 | | { |
| 211 | | free (file_data); |
| 212 | | logerror ("File corrupted\n"); |
| 213 | | return IMAGE_INIT_FAIL; |
| 214 | | } |
| 215 | | |
| 216 | | switch (file_data[0x00]) |
| 217 | | { |
| 218 | | case 0x00: logerror ("DOCK cart\n"); |
| 219 | | timex_cart.type = TIMEX_CART_DOCK; |
| 220 | | timex_cart.data = (UINT8*) malloc (0x10000); |
| 221 | | if (!timex_cart.data) |
| 222 | | { |
| 223 | | free (file_data); |
| 224 | | logerror ("Memory allocate error\n"); |
| 225 | | return IMAGE_INIT_FAIL; |
| 226 | | } |
| 227 | | chunks_in_file = 0; |
| 228 | | for (i=0; i<8; i++) |
| 229 | | { |
| 230 | | timex_cart.chunks = timex_cart.chunks | ((file_data[i+1]&0x01)<<i); |
| 231 | | if (file_data[i+1]&0x02) |
| 232 | | { |
| 233 | | memcpy (timex_cart.data+i*0x2000, file_data+0x09+chunks_in_file*0x2000, 0x2000); |
| 234 | | chunks_in_file++; |
| 235 | | } |
| 236 | | else |
| 237 | | { |
| 238 | | if (file_data[i+1]&0x01) |
| 239 | | memset (timex_cart.data+i*0x2000, 0x00, 0x2000); |
| 240 | | else |
| 241 | | memset (timex_cart.data+i*0x2000, 0xff, 0x2000); |
| 242 | | } |
| 243 | | } |
| 244 | | free (file_data); |
| 245 | | break; |
| 246 | | |
| 247 | | default: logerror ("Cart type not supported\n"); |
| 248 | | free (file_data); |
| 249 | | timex_cart.type = TIMEX_CART_NONE; |
| 250 | | return IMAGE_INIT_FAIL; |
| 251 | | } |
| 252 | | |
| 253 | | logerror ("Cart loaded\n"); |
| 254 | | logerror ("Chunks %02x\n", timex_cart.chunks); |
| 255 | | return IMAGE_INIT_PASS; |
| 256 | | } |
| 257 | | |
| 258 | | DEVICE_IMAGE_UNLOAD_LEGACY( timex_cart ) |
| 259 | | { |
| 260 | | if (timex_cart.data) |
| 261 | | { |
| 262 | | free (timex_cart.data); |
| 263 | | timex_cart.data = NULL; |
| 264 | | } |
| 265 | | timex_cart.type = TIMEX_CART_NONE; |
| 266 | | timex_cart.chunks = 0x00; |
| 267 | | } |
| 268 | | |
| 269 | 177 | const timex_cart_t *timex_cart_data(void) |
| 270 | 178 | { |
| 271 | 179 | return &timex_cart; |
| r21567 | r21568 | |
| 712 | 620 | |
| 713 | 621 | DEVICE_IMAGE_LOAD_MEMBER( spectrum_state, timex_cart ) |
| 714 | 622 | { |
| 715 | | return device_load_timex_cart( image ); |
| 623 | int file_size; |
| 624 | UINT8 * file_data; |
| 625 | |
| 626 | int chunks_in_file = 0; |
| 627 | |
| 628 | int i; |
| 629 | |
| 630 | logerror ("Trying to load cart\n"); |
| 631 | |
| 632 | file_size = image.length(); |
| 633 | |
| 634 | if (file_size < 0x09) |
| 635 | { |
| 636 | logerror ("Bad file size\n"); |
| 637 | return IMAGE_INIT_FAIL; |
| 638 | } |
| 639 | |
| 640 | file_data = (UINT8 *)malloc(file_size); |
| 641 | if (file_data == NULL) |
| 642 | { |
| 643 | logerror ("Memory allocating error\n"); |
| 644 | return IMAGE_INIT_FAIL; |
| 645 | } |
| 646 | |
| 647 | image.fread(file_data, file_size); |
| 648 | |
| 649 | for (i=0; i<8; i++) |
| 650 | if(file_data[i+1]&0x02) chunks_in_file++; |
| 651 | |
| 652 | if (chunks_in_file*0x2000+0x09 != file_size) |
| 653 | { |
| 654 | free (file_data); |
| 655 | logerror ("File corrupted\n"); |
| 656 | return IMAGE_INIT_FAIL; |
| 657 | } |
| 658 | |
| 659 | switch (file_data[0x00]) |
| 660 | { |
| 661 | case 0x00: logerror ("DOCK cart\n"); |
| 662 | timex_cart.type = TIMEX_CART_DOCK; |
| 663 | timex_cart.data = (UINT8*) malloc (0x10000); |
| 664 | if (!timex_cart.data) |
| 665 | { |
| 666 | free (file_data); |
| 667 | logerror ("Memory allocate error\n"); |
| 668 | return IMAGE_INIT_FAIL; |
| 669 | } |
| 670 | chunks_in_file = 0; |
| 671 | for (i=0; i<8; i++) |
| 672 | { |
| 673 | timex_cart.chunks = timex_cart.chunks | ((file_data[i+1]&0x01)<<i); |
| 674 | if (file_data[i+1]&0x02) |
| 675 | { |
| 676 | memcpy (timex_cart.data+i*0x2000, file_data+0x09+chunks_in_file*0x2000, 0x2000); |
| 677 | chunks_in_file++; |
| 678 | } |
| 679 | else |
| 680 | { |
| 681 | if (file_data[i+1]&0x01) |
| 682 | memset (timex_cart.data+i*0x2000, 0x00, 0x2000); |
| 683 | else |
| 684 | memset (timex_cart.data+i*0x2000, 0xff, 0x2000); |
| 685 | } |
| 686 | } |
| 687 | free (file_data); |
| 688 | break; |
| 689 | |
| 690 | default: logerror ("Cart type not supported\n"); |
| 691 | free (file_data); |
| 692 | timex_cart.type = TIMEX_CART_NONE; |
| 693 | return IMAGE_INIT_FAIL; |
| 694 | } |
| 695 | |
| 696 | logerror ("Cart loaded\n"); |
| 697 | logerror ("Chunks %02x\n", timex_cart.chunks); |
| 698 | return IMAGE_INIT_PASS; |
| 716 | 699 | } |
| 717 | 700 | |
| 718 | 701 | |
| 719 | 702 | DEVICE_IMAGE_UNLOAD_MEMBER( spectrum_state, timex_cart ) |
| 720 | 703 | { |
| 721 | | device_unload_timex_cart( image ); |
| 704 | if (timex_cart.data) |
| 705 | { |
| 706 | free (timex_cart.data); |
| 707 | timex_cart.data = NULL; |
| 708 | } |
| 709 | timex_cart.type = TIMEX_CART_NONE; |
| 710 | timex_cart.chunks = 0x00; |
| 722 | 711 | } |
| 723 | 712 | |
| 724 | 713 | |
trunk/src/mess/drivers/studio2.c
| r21567 | r21568 | |
| 234 | 234 | ***************************************************************************/ |
| 235 | 235 | |
| 236 | 236 | /*------------------------------------------------- |
| 237 | | DEVICE_IMAGE_LOAD( st2_cartslot_load ) |
| 237 | DEVICE_IMAGE_LOAD_MEMBER( studio2_state, st2_cartslot_load ) |
| 238 | 238 | -------------------------------------------------*/ |
| 239 | 239 | |
| 240 | | DEVICE_IMAGE_LOAD_LEGACY( st2_cartslot_load ) |
| 240 | DEVICE_IMAGE_LOAD_MEMBER( studio2_state, st2_cartslot_load ) |
| 241 | 241 | { |
| 242 | 242 | st2_header header; |
| 243 | 243 | |
| r21567 | r21568 | |
| 512 | 512 | DEVICE_IMAGE_LOAD_MEMBER( studio2_state, studio2_cart_load ) |
| 513 | 513 | { |
| 514 | 514 | if (image.software_entry() == NULL) |
| 515 | | return device_load_st2_cartslot_load(image); |
| 515 | return DEVICE_IMAGE_LOAD_MEMBER_NAME(st2_cartslot_load)(image); |
| 516 | 516 | else |
| 517 | 517 | { |
| 518 | 518 | // WARNING: list code currently assume that cart mapping starts at 0x400. |