src/mess/formats/timex_dck.c
| r8371 | r8372 | |
| 38 | 38 | |
| 39 | 39 | DEVICE_IMAGE_LOAD( timex_cart ) |
| 40 | 40 | { |
| 41 | | // int file_size; |
| 42 | | // UINT8 * file_data; |
| 43 | | // |
| 44 | | // int chunks_in_file = 0; |
| 45 | | // |
| 46 | | // int i; |
| 47 | | // |
| 48 | | // logerror ("Trying to load cart\n"); |
| 49 | | // |
| 50 | | // file_size = image_length(image); |
| 51 | | // |
| 52 | | // if (file_size < 0x09) |
| 53 | | // { |
| 54 | | // logerror ("Bad file size\n"); |
| 55 | | // return IMAGE_INIT_FAIL; |
| 56 | | // } |
| 57 | | // |
| 58 | | // file_data = (UINT8 *)malloc(file_size); |
| 59 | | // if (file_data == NULL) |
| 60 | | // { |
| 61 | | // logerror ("Memory allocating error\n"); |
| 62 | | // return IMAGE_INIT_FAIL; |
| 63 | | // } |
| 64 | | // |
| 65 | | // image_fread(image, file_data, file_size); |
| 66 | | // |
| 67 | | // for (i=0; i<8; i++) |
| 68 | | // if(file_data[i+1]&0x02) chunks_in_file++; |
| 69 | | // |
| 70 | | // if (chunks_in_file*0x2000+0x09 != file_size) |
| 71 | | // { |
| 72 | | // free (file_data); |
| 73 | | // logerror ("File corrupted\n"); |
| 74 | | // return IMAGE_INIT_FAIL; |
| 75 | | // } |
| 76 | | // |
| 77 | | // switch (file_data[0x00]) |
| 78 | | // { |
| 79 | | // case 0x00: logerror ("DOCK cart\n"); |
| 80 | | // timex_cart_type = TIMEX_CART_DOCK; |
| 81 | | // timex_cart_data = (UINT8*) malloc (0x10000); |
| 82 | | // if (!timex_cart_data) |
| 83 | | // { |
| 84 | | // free (file_data); |
| 85 | | // logerror ("Memory allocate error\n"); |
| 86 | | // return IMAGE_INIT_FAIL; |
| 87 | | // } |
| 88 | | // chunks_in_file = 0; |
| 89 | | // for (i=0; i<8; i++) |
| 90 | | // { |
| 91 | | // timex_cart_chunks = timex_cart_chunks | ((file_data[i+1]&0x01)<<i); |
| 92 | | // if (file_data[i+1]&0x02) |
| 93 | | // { |
| 94 | | // memcpy (timex_cart_data+i*0x2000, file_data+0x09+chunks_in_file*0x2000, 0x2000); |
| 95 | | // chunks_in_file++; |
| 96 | | // } |
| 97 | | // else |
| 98 | | // { |
| 99 | | // if (file_data[i+1]&0x01) |
| 100 | | // memset (timex_cart_data+i*0x2000, 0x00, 0x2000); |
| 101 | | // else |
| 102 | | // memset (timex_cart_data+i*0x2000, 0xff, 0x2000); |
| 103 | | // } |
| 104 | | // } |
| 105 | | // free (file_data); |
| 106 | | // break; |
| 107 | | // |
| 108 | | // default: logerror ("Cart type not supported\n"); |
| 109 | | // free (file_data); |
| 110 | | // timex_cart_type = TIMEX_CART_NONE; |
| 111 | | // return IMAGE_INIT_FAIL; |
| 112 | | // } |
| 113 | | // |
| 114 | | // logerror ("Cart loaded\n"); |
| 115 | | // logerror ("Chunks %02x\n", timex_cart_chunks); |
| 41 | int file_size; |
| 42 | UINT8 * file_data; |
| 43 | |
| 44 | int chunks_in_file = 0; |
| 45 | |
| 46 | int i; |
| 47 | |
| 48 | logerror ("Trying to load cart\n"); |
| 49 | |
| 50 | file_size = image.length(); |
| 51 | |
| 52 | if (file_size < 0x09) |
| 53 | { |
| 54 | logerror ("Bad file size\n"); |
| 55 | return IMAGE_INIT_FAIL; |
| 56 | } |
| 57 | |
| 58 | file_data = (UINT8 *)malloc(file_size); |
| 59 | if (file_data == NULL) |
| 60 | { |
| 61 | logerror ("Memory allocating error\n"); |
| 62 | return IMAGE_INIT_FAIL; |
| 63 | } |
| 64 | |
| 65 | image.fread(file_data, file_size); |
| 66 | |
| 67 | for (i=0; i<8; i++) |
| 68 | if(file_data[i+1]&0x02) chunks_in_file++; |
| 69 | |
| 70 | if (chunks_in_file*0x2000+0x09 != file_size) |
| 71 | { |
| 72 | free (file_data); |
| 73 | logerror ("File corrupted\n"); |
| 74 | return IMAGE_INIT_FAIL; |
| 75 | } |
| 76 | |
| 77 | switch (file_data[0x00]) |
| 78 | { |
| 79 | case 0x00: logerror ("DOCK cart\n"); |
| 80 | timex_cart_type = TIMEX_CART_DOCK; |
| 81 | timex_cart_data = (UINT8*) malloc (0x10000); |
| 82 | if (!timex_cart_data) |
| 83 | { |
| 84 | free (file_data); |
| 85 | logerror ("Memory allocate error\n"); |
| 86 | return IMAGE_INIT_FAIL; |
| 87 | } |
| 88 | chunks_in_file = 0; |
| 89 | for (i=0; i<8; i++) |
| 90 | { |
| 91 | timex_cart_chunks = timex_cart_chunks | ((file_data[i+1]&0x01)<<i); |
| 92 | if (file_data[i+1]&0x02) |
| 93 | { |
| 94 | memcpy (timex_cart_data+i*0x2000, file_data+0x09+chunks_in_file*0x2000, 0x2000); |
| 95 | chunks_in_file++; |
| 96 | } |
| 97 | else |
| 98 | { |
| 99 | if (file_data[i+1]&0x01) |
| 100 | memset (timex_cart_data+i*0x2000, 0x00, 0x2000); |
| 101 | else |
| 102 | memset (timex_cart_data+i*0x2000, 0xff, 0x2000); |
| 103 | } |
| 104 | } |
| 105 | free (file_data); |
| 106 | break; |
| 107 | |
| 108 | default: logerror ("Cart type not supported\n"); |
| 109 | free (file_data); |
| 110 | timex_cart_type = TIMEX_CART_NONE; |
| 111 | return IMAGE_INIT_FAIL; |
| 112 | } |
| 113 | |
| 114 | logerror ("Cart loaded\n"); |
| 115 | logerror ("Chunks %02x\n", timex_cart_chunks); |
| 116 | 116 | return IMAGE_INIT_PASS; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | DEVICE_IMAGE_UNLOAD( timex_cart ) |
| 120 | 120 | { |
| 121 | | // if (timex_cart_data) |
| 122 | | // { |
| 123 | | // free (timex_cart_data); |
| 124 | | // timex_cart_data = NULL; |
| 125 | | // } |
| 126 | | // timex_cart_type = TIMEX_CART_NONE; |
| 127 | | // timex_cart_chunks = 0x00; |
| 121 | if (timex_cart_data) |
| 122 | { |
| 123 | free (timex_cart_data); |
| 124 | timex_cart_data = NULL; |
| 125 | } |
| 126 | timex_cart_type = TIMEX_CART_NONE; |
| 127 | timex_cart_chunks = 0x00; |
| 128 | 128 | } |