diff --git a/src/emu/debug/debugcmd.c b/src/emu/debug/debugcmd.c index 7687caea6f9..56c2404ad18 100644 --- a/src/emu/debug/debugcmd.c +++ b/src/emu/debug/debugcmd.c @@ -41,6 +41,7 @@ struct _global_entry UINT32 size; }; + typedef struct _cheat_map cheat_map; struct _cheat_map { @@ -51,19 +52,31 @@ struct _cheat_map UINT8 undo:7; }; + typedef struct _cheat_system cheat_system; struct _cheat_system { - char cpu; - UINT64 length; - UINT8 width; - cheat_map * cheatmap; - UINT8 undo; - UINT8 signed_cheat; - UINT8 swapped_cheat; + char cpu; + UINT64 length; + UINT8 width; + cheat_map * cheatmap; + UINT8 undo; + UINT8 signed_cheat; + UINT8 swapped_cheat; }; +typedef struct _cheat_region_map cheat_region_map; +struct _cheat_region_map +{ + UINT64 offset; + UINT64 endoffset; + UINT8 share; + UINT8 disabled; +}; + + + /*************************************************************************** GLOBAL VARIABLES ***************************************************************************/ @@ -1708,10 +1721,14 @@ static void execute_dump(running_machine *machine, int ref, int params, const ch static void execute_cheatinit(running_machine *machine, int ref, int params, const char *param[]) { - UINT64 offset, endoffset, length = 0, real_length = 0; + UINT64 offset, length = 0, real_length = 0; const address_space *space; UINT32 active_cheat = 0; UINT64 curaddr; + UINT8 i, region_count = 0; + + address_map_entry *entry; + cheat_region_map cheat_region[100]; /* validate parameters */ if (!debug_command_parameter_cpu_space(machine, (params > 3) ? param[3] : NULL, ADDRESS_SPACE_PROGRAM, &space)) @@ -1719,6 +1736,9 @@ static void execute_cheatinit(running_machine *machine, int ref, int params, con if (ref == 0) { + cheat.width = 1; + cheat.signed_cheat = FALSE; + cheat.swapped_cheat = FALSE; if (params > 0) { char *srtpnt = (char*)param[0]; @@ -1752,35 +1772,51 @@ static void execute_cheatinit(running_machine *machine, int ref, int params, con else cheat.swapped_cheat = FALSE; } - else - { - cheat.width = 1; - cheat.signed_cheat = FALSE; - cheat.swapped_cheat = FALSE; - } } - if (params > 1) + /* initialize entire memory by default */ + if (params <= 1) { + offset = 0; + length = space->bytemask + 1; + for (entry = space->map->entrylist; entry != NULL; entry = entry->next) + { + cheat_region[region_count].offset = memory_address_to_byte(space, entry->addrstart) & space->bytemask; + cheat_region[region_count].endoffset = memory_address_to_byte(space, entry->addrend) & space->bytemask; + cheat_region[region_count].share = entry->share; + cheat_region[region_count].disabled = (entry->write.shandler8 == SMH_RAM) ? FALSE : TRUE; + + /* disable double share regions */ + if (entry->share != 0) + for (i = 0; i < region_count; i++) + if (cheat_region[i].share == entry->share) + cheat_region[region_count].disabled = TRUE; + + region_count++; + } + } + else + { + /* validate parameters */ if (!debug_command_parameter_number(machine, param[(ref == 0) ? 1 : 0], &offset)) return; if (!debug_command_parameter_number(machine, param[(ref == 0) ? 2 : 1], &length)) return; - } - else - { - /* initialize entire memory */ - offset = 0; - length = space->bytemask + 1; + + /* force region to the specified range */ + cheat_region[region_count].offset = memory_address_to_byte(space, offset) & space->bytemask;; + cheat_region[region_count].endoffset = memory_address_to_byte(space, offset + length - 1) & space->bytemask;; + cheat_region[region_count].share = 0; + cheat_region[region_count].disabled = FALSE; + region_count++; } - endoffset = memory_address_to_byte(space, offset + length - 1) & space->bytemask; - offset = memory_address_to_byte(space, offset) & space->bytemask; - - /* counts the writable bytes in the area */ - for (curaddr = offset; curaddr <= endoffset; curaddr += cheat.width) - if (cheat_address_is_valid(space, curaddr)) - real_length++; + /* determine the writable extent of each region in total */ + for (i = 0; i <= region_count; i++) + if (!cheat_region[i].disabled) + for (curaddr = cheat_region[i].offset; curaddr <= cheat_region[i].endoffset; curaddr += cheat.width) + if (cheat_address_is_valid(space, curaddr)) + real_length++; if (real_length == 0) { @@ -1831,16 +1867,18 @@ static void execute_cheatinit(running_machine *machine, int ref, int params, con } /* initialize cheatmap in the selected space */ - for (curaddr = offset; curaddr <= endoffset; curaddr += cheat.width) - if (cheat_address_is_valid(space, curaddr)) - { - cheat.cheatmap[active_cheat].previous_value = cheat_read_extended(&cheat, space, curaddr); - cheat.cheatmap[active_cheat].first_value = cheat.cheatmap[active_cheat].previous_value; - cheat.cheatmap[active_cheat].offset = curaddr; - cheat.cheatmap[active_cheat].state = 1; - cheat.cheatmap[active_cheat].undo = 0; - active_cheat++; - } + for (i = 0; i < region_count; i++) + if (!cheat_region[i].disabled) + for (curaddr = cheat_region[i].offset; curaddr <= cheat_region[i].endoffset; curaddr += cheat.width) + if (cheat_address_is_valid(space, curaddr)) + { + cheat.cheatmap[active_cheat].previous_value = cheat_read_extended(&cheat, space, curaddr); + cheat.cheatmap[active_cheat].first_value = cheat.cheatmap[active_cheat].previous_value; + cheat.cheatmap[active_cheat].offset = curaddr; + cheat.cheatmap[active_cheat].state = 1; + cheat.cheatmap[active_cheat].undo = 0; + active_cheat++; + } debug_console_printf(machine, "%u cheat initialized\n", active_cheat); } @@ -2067,7 +2105,7 @@ static void execute_cheatlist(running_machine *machine, int ref, int params, con active_cheat++; fprintf(f, " \n", active_cheat, core_i64_hex_format(address, space->logaddrchars), core_i64_hex_format(value, cheat.width * 2)); fprintf(f, " \n"); fprintf(f, " \n\n"); }