src/emu/cheat.c
| r8400 | r8401 | |
| 84 | 84 | |
| 85 | 85 | #include <ctype.h> |
| 86 | 86 | |
| 87 | | #ifdef MESS |
| 88 | | #include "cheatms.h" |
| 89 | | #endif |
| 90 | 87 | |
| 91 | 88 | |
| 92 | 89 | |
| r8400 | r8401 | |
| 412 | 409 | |
| 413 | 410 | /* load the cheat file, MESS will load a crc32.xml ( eg. 01234567.xml ) |
| 414 | 411 | and MAME will load gamename.xml */ |
| 415 | | #ifdef MESS |
| 412 | device_image_interface *image = NULL; |
| 413 | for (bool gotone = machine->devicelist.first(image); gotone; gotone = image->next(image)) |
| 416 | 414 | { |
| 417 | | char mess_cheat_filename[9]; |
| 418 | | cheat_mess_init(machine); |
| 419 | | sprintf(mess_cheat_filename, "%08X", this_game_crc); |
| 420 | | cheatinfo->cheatlist = cheat_list_load(machine, mess_cheat_filename); |
| 415 | if (image->exists()) |
| 416 | { |
| 417 | char mess_cheat_filename[9]; |
| 418 | UINT32 crc = image->crc(); |
| 419 | sprintf(mess_cheat_filename, "%08X", crc); |
| 420 | if (crc!=0) { |
| 421 | cheatinfo->cheatlist = cheat_list_load(machine, mess_cheat_filename); |
| 422 | break; |
| 423 | } |
| 424 | } |
| 421 | 425 | } |
| 422 | | #else |
| 423 | | cheatinfo->cheatlist = cheat_list_load(machine, machine->basename); |
| 424 | | #endif |
| 426 | if (cheatinfo->cheatlist == NULL) |
| 427 | { |
| 428 | cheatinfo->cheatlist = cheat_list_load(machine, machine->basename); |
| 429 | } |
| 425 | 430 | |
| 426 | 431 | /* temporary: save the file back out as output.xml for comparison */ |
| 427 | 432 | if (cheatinfo->cheatlist != NULL) |
src/mess/cheatms.c
| r8400 | r8401 | |
| 1 | | /**************************************************************************** |
| 2 | | |
| 3 | | cheatms.c |
| 4 | | |
| 5 | | MESS sepcific cheat code |
| 6 | | |
| 7 | | ****************************************************************************/ |
| 8 | | |
| 9 | | |
| 10 | | #include "emu.h" |
| 11 | | #include "mess.h" |
| 12 | | #include "image.h" |
| 13 | | #include "cheatms.h" |
| 14 | | |
| 15 | | |
| 16 | | /*************************************************************************** |
| 17 | | GLOBALS |
| 18 | | ***************************************************************************/ |
| 19 | | |
| 20 | | static UINT32 *device_crc_list = NULL; |
| 21 | | static INT32 device_crc_list_length = 0; |
| 22 | | UINT32 this_game_crc = 0; |
| 23 | | |
| 24 | | |
| 25 | | |
| 26 | | /*************************************************************************** |
| 27 | | CODE |
| 28 | | ***************************************************************************/ |
| 29 | | |
| 30 | | static void build_crc_table(running_machine *machine) |
| 31 | | { |
| 32 | | int listIdx; |
| 33 | | device_image_interface *image = NULL; |
| 34 | | static UINT32 *tmp_list = NULL; |
| 35 | | |
| 36 | | free(device_crc_list); |
| 37 | | |
| 38 | | /* allocate list with single member (0x00000000) */ |
| 39 | | device_crc_list = (UINT32*)malloc(sizeof(UINT32)); |
| 40 | | memset(device_crc_list,0,sizeof(UINT32)); |
| 41 | | device_crc_list_length = 1; |
| 42 | | |
| 43 | | for (bool gotone = machine->devicelist.first(image); gotone; gotone = image->next(image)) |
| 44 | | { |
| 45 | | if (image->exists()) |
| 46 | | { |
| 47 | | UINT32 crc = image->crc(); |
| 48 | | int isUnique = 1; |
| 49 | | |
| 50 | | for(listIdx = 0; listIdx < device_crc_list_length; listIdx++) |
| 51 | | { |
| 52 | | if(device_crc_list[listIdx] == crc) |
| 53 | | { |
| 54 | | isUnique = 0; |
| 55 | | |
| 56 | | break; |
| 57 | | } |
| 58 | | } |
| 59 | | |
| 60 | | if(isUnique) |
| 61 | | { |
| 62 | | if(!this_game_crc) |
| 63 | | this_game_crc = crc; |
| 64 | | |
| 65 | | tmp_list = (UINT32*)malloc((device_crc_list_length + 1) * sizeof(UINT32)); |
| 66 | | memcpy(tmp_list,device_crc_list,device_crc_list_length * sizeof(UINT32)); |
| 67 | | if (device_crc_list) free(device_crc_list); |
| 68 | | device_crc_list = tmp_list; |
| 69 | | |
| 70 | | device_crc_list[device_crc_list_length] = crc; |
| 71 | | device_crc_list_length++; |
| 72 | | } |
| 73 | | } |
| 74 | | } |
| 75 | | } |
| 76 | | |
| 77 | | |
| 78 | | void cheat_mess_init(running_machine *machine) |
| 79 | | { |
| 80 | | device_crc_list = NULL; |
| 81 | | device_crc_list_length = 0; |
| 82 | | this_game_crc = 0; |
| 83 | | |
| 84 | | build_crc_table(machine); |
| 85 | | } |
| 86 | | |
| 87 | | |
| 88 | | |
| 89 | | void cheat_mess_exit(void) |
| 90 | | { |
| 91 | | free(device_crc_list); |
| 92 | | device_crc_list = NULL; |
| 93 | | |
| 94 | | device_crc_list_length = 0; |
| 95 | | this_game_crc = 0; |
| 96 | | } |
| 97 | | |
| 98 | | |
| 99 | | |
| 100 | | int cheat_mess_matches_crc_table(UINT32 crc) |
| 101 | | { |
| 102 | | int i; |
| 103 | | |
| 104 | | for(i = 0; i < device_crc_list_length; i++) |
| 105 | | if(device_crc_list[i] == crc) |
| 106 | | return 1; |
| 107 | | |
| 108 | | return 0; |
| 109 | | } |
| 110 | | |