Previous 15994 Revisions Next

r8401 Tuesday 6th July, 2010 at 03:08:29 UTC by Miodrag Milanović
Moved cheat related code to emu, since it is image related (already in MAME tree for a time)
[src/emu]cheat.c
[src/mess]cheatms.c cheatms.h messcore.mak

src/emu/cheat.c
r8400r8401
8484
8585#include <ctype.h>
8686
87#ifdef MESS
88#include "cheatms.h"
89#endif
9087
9188
9289
r8400r8401
412409
413410   /* load the cheat file, MESS will load a crc32.xml ( eg. 01234567.xml )
414411       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))
416414   {
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      }
421425   }
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   }
425430
426431   /* temporary: save the file back out as output.xml for comparison */
427432   if (cheatinfo->cheatlist != NULL)
src/mess/cheatms.c
r8400r8401
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
20static UINT32 *device_crc_list = NULL;
21static INT32 device_crc_list_length = 0;
22UINT32 this_game_crc = 0;
23
24
25
26/***************************************************************************
27    CODE
28***************************************************************************/
29
30static 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
78void 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
89void 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
100int 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
src/mess/cheatms.h
r8400r8401
1/*********************************************************************
2
3    cheatms.h
4
5    MESS specific cheat code
6
7*********************************************************************/
8
9#pragma once
10
11#ifndef __CHEATMS_H__
12#define __CHEATMS_H__
13
14extern UINT32 this_game_crc;
15
16void cheat_mess_init(running_machine *machine);
17void cheat_mess_exit(void);
18int cheat_mess_matches_crc_table(UINT32 crc);
19
20#endif /* __CHEATMS_H__ */
src/mess/messcore.mak
r8400r8401
7474EMUOBJS += \
7575   $(MESSOBJ)/mess.o      \
7676   $(MESSOBJ)/uimess.o      \
77   $(MESSOBJ)/cheatms.o   \
7877
7978$(LIBEMU): $(EMUOBJS)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team