diff options
135 files changed, 2373 insertions, 2382 deletions
diff --git a/.gitattributes b/.gitattributes index e1846c16ad1..4f6180be3d1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -643,6 +643,8 @@ src/emu/layout/snap.lay svneol=native#text/plain src/emu/layout/triphsxs.lay svneol=native#text/plain src/emu/layout/vertical.lay svneol=native#text/plain src/emu/layout/voffff20.lay svneol=native#text/plain +src/emu/machine.c svneol=native#text/plain +src/emu/machine.h svneol=native#text/plain src/emu/machine/53c810.c svneol=native#text/plain src/emu/machine/53c810.h svneol=native#text/plain src/emu/machine/6522via.c svneol=native#text/plain diff --git a/src/emu/audio/generic.c b/src/emu/audio/generic.c index 5c419fcd99f..a1a79a90066 100644 --- a/src/emu/audio/generic.c +++ b/src/emu/audio/generic.c @@ -163,6 +163,6 @@ WRITE8_HANDLER( soundlatch4_clear_w ) { latch_clear(space, 3); } void soundlatch_setclearedvalue(running_machine *machine, int value) { generic_audio_private *state = machine->generic_audio_data; - assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call soundlatch_setclearedvalue at init time!"); + assert_always(machine->phase() == MACHINE_PHASE_INIT, "Can only call soundlatch_setclearedvalue at init time!"); state->latch_clear_value = value; } diff --git a/src/emu/cheat.c b/src/emu/cheat.c index e49f78cb04b..4243f7a8c5e 100644 --- a/src/emu/cheat.c +++ b/src/emu/cheat.c @@ -215,8 +215,8 @@ struct _cheat_private FUNCTION PROTOTYPES ***************************************************************************/ -static void cheat_exit(running_machine *machine); -static void cheat_frame(running_machine *machine); +static void cheat_exit(running_machine &machine); +static void cheat_frame(running_machine &machine); static void cheat_execute_script(cheat_private *cheatinfo, cheat_entry *cheat, script_state state); static cheat_entry *cheat_list_load(running_machine *machine, const char *filename); @@ -377,8 +377,8 @@ void cheat_init(running_machine *machine) cheat_private *cheatinfo; /* request a callback */ - add_frame_callback(machine, cheat_frame); - add_exit_callback(machine, cheat_exit); + machine->add_notifier(MACHINE_NOTIFY_FRAME, cheat_frame); + machine->add_notifier(MACHINE_NOTIFY_EXIT, cheat_exit); /* allocate memory */ cheatinfo = auto_alloc_clear(machine, cheat_private); @@ -404,7 +404,7 @@ void cheat_reload(running_machine *machine) cheat_private *cheatinfo = machine->cheat_data; /* free everything */ - cheat_exit(machine); + cheat_exit(*machine); /* reset our memory */ auto_free(machine, cheatinfo); @@ -420,7 +420,7 @@ void cheat_reload(running_machine *machine) cheatinfo->cheatlist = cheat_list_load(machine, mess_cheat_filename); } #else - cheatinfo->cheatlist = cheat_list_load(machine, machine->basename); + cheatinfo->cheatlist = cheat_list_load(machine, machine->basename()); #endif /* temporary: save the file back out as output.xml for comparison */ @@ -433,13 +433,13 @@ void cheat_reload(running_machine *machine) cheat_exit - clean up on the way out -------------------------------------------------*/ -static void cheat_exit(running_machine *machine) +static void cheat_exit(running_machine &machine) { - cheat_private *cheatinfo = machine->cheat_data; + cheat_private *cheatinfo = machine.cheat_data; /* free the list of cheats */ if (cheatinfo->cheatlist != NULL) - cheat_list_free(machine, cheatinfo->cheatlist); + cheat_list_free(&machine, cheatinfo->cheatlist); } @@ -892,9 +892,9 @@ astring &cheat_get_comment(void *entry) cheat_frame - per-frame callback -------------------------------------------------*/ -static void cheat_frame(running_machine *machine) +static void cheat_frame(running_machine &machine) { - cheat_private *cheatinfo = machine->cheat_data; + cheat_private *cheatinfo = machine.cheat_data; cheat_entry *cheat; int linenum; diff --git a/src/emu/config.c b/src/emu/config.c index e2995c283d9..0d951b6fdbf 100644 --- a/src/emu/config.c +++ b/src/emu/config.c @@ -102,7 +102,7 @@ void config_register(running_machine *machine, const char *nodename, config_call int config_load_settings(running_machine *machine) { - const char *controller = options_get_string(mame_options(), OPTION_CTRLR); + const char *controller = options_get_string(machine->options(), OPTION_CTRLR); file_error filerr; config_type *type; mame_file *file; @@ -137,7 +137,7 @@ int config_load_settings(running_machine *machine) } /* finally, load the game-specific file */ - astring fname(machine->basename, ".cfg"); + astring fname(machine->basename(), ".cfg"); filerr = mame_fopen(SEARCHPATH_CONFIG, fname, OPEN_FLAG_READ, &file); if (filerr == FILERR_NONE) @@ -175,7 +175,7 @@ void config_save_settings(running_machine *machine) } /* finally, save the game-specific file */ - astring fname(machine->basename, ".cfg"); + astring fname(machine->basename(), ".cfg"); filerr = mame_fopen(SEARCHPATH_CONFIG, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file); if (filerr == FILERR_NONE) diff --git a/src/emu/crsshair.c b/src/emu/crsshair.c index 6c674059ee0..2985bd3be2a 100644 --- a/src/emu/crsshair.c +++ b/src/emu/crsshair.c @@ -131,7 +131,7 @@ static const rgb_t crosshair_colors[] = FUNCTION PROTOTYPES ***************************************************************************/ -static void crosshair_exit(running_machine *machine); +static void crosshair_exit(running_machine &machine); static void crosshair_load(running_machine *machine, int config_type, xml_data_node *parentnode); static void crosshair_save(running_machine *machine, int config_type, xml_data_node *parentnode); @@ -212,7 +212,7 @@ void crosshair_init(running_machine *machine) const input_field_config *field; /* request a callback upon exiting */ - add_exit_callback(machine, crosshair_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, crosshair_exit); /* clear all the globals */ memset(&global, 0, sizeof(global)); @@ -221,7 +221,7 @@ void crosshair_init(running_machine *machine) global.auto_time = CROSSHAIR_VISIBILITY_AUTOTIME_DEFAULT; /* determine who needs crosshairs */ - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) for (field = port->fieldlist; field != NULL; field = field->next) if (field->crossaxis != CROSSHAIR_AXIS_NONE) { @@ -256,7 +256,7 @@ void crosshair_init(running_machine *machine) the crosshairs -------------------------------------------------*/ -static void crosshair_exit(running_machine *machine) +static void crosshair_exit(running_machine &machine) { int player; diff --git a/src/emu/debug/debugcmd.c b/src/emu/debug/debugcmd.c index b985502c234..fc756fb7116 100644 --- a/src/emu/debug/debugcmd.c +++ b/src/emu/debug/debugcmd.c @@ -91,7 +91,7 @@ static cheat_system cheat; FUNCTION PROTOTYPES ***************************************************************************/ -static void debug_command_exit(running_machine *machine); +static void debug_command_exit(running_machine &machine); static UINT64 execute_min(void *globalref, void *ref, UINT32 params, const UINT64 *param); static UINT64 execute_max(void *globalref, void *ref, UINT32 params, const UINT64 *param); @@ -368,10 +368,10 @@ void debug_command_init(running_machine *machine) /* ask all the devices if they would like to register functions or symbols */ machine->m_devicelist.debug_setup_all(); - add_exit_callback(machine, debug_command_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, debug_command_exit); /* set up the initial debugscript if specified */ - name = options_get_string(mame_options(), OPTION_DEBUGSCRIPT); + name = options_get_string(machine->options(), OPTION_DEBUGSCRIPT); if (name[0] != 0) debug_cpu_source_script(machine, name); } @@ -381,16 +381,16 @@ void debug_command_init(running_machine *machine) debug_command_exit - exit-time cleanup -------------------------------------------------*/ -static void debug_command_exit(running_machine *machine) +static void debug_command_exit(running_machine &machine) { device_t *cpu; /* turn off all traces */ - for (cpu = machine->firstcpu; cpu != NULL; cpu = cpu_next(cpu)) + for (cpu = machine.firstcpu; cpu != NULL; cpu = cpu_next(cpu)) debug_cpu_trace(cpu, NULL, 0, NULL); if (cheat.length) - auto_free(machine, cheat.cheatmap); + auto_free(&machine, cheat.cheatmap); } @@ -834,7 +834,7 @@ static void execute_tracelog(running_machine *machine, int ref, int params, cons static void execute_quit(running_machine *machine, int ref, int params, const char *param[]) { mame_printf_error("Exited via the debugger\n"); - mame_schedule_exit(machine); + machine->schedule_exit(); } @@ -2670,7 +2670,7 @@ static void execute_symlist(running_machine *machine, int ref, int params, const static void execute_softreset(running_machine *machine, int ref, int params, const char **param) { - mame_schedule_soft_reset(machine); + machine->schedule_soft_reset(); } @@ -2680,5 +2680,5 @@ static void execute_softreset(running_machine *machine, int ref, int params, con static void execute_hardreset(running_machine *machine, int ref, int params, const char **param) { - mame_schedule_hard_reset(machine); + machine->schedule_hard_reset(); } diff --git a/src/emu/debug/debugcmt.c b/src/emu/debug/debugcmt.c index c73b0441c41..f140cf6f451 100644 --- a/src/emu/debug/debugcmt.c +++ b/src/emu/debug/debugcmt.c @@ -78,7 +78,7 @@ struct _debug_cpu_comment_group ***************************************************************************/ static int debug_comment_load_xml(running_machine *machine, mame_file *file); -static void debug_comment_exit(running_machine *machine); +static void debug_comment_exit(running_machine &machine); @@ -104,7 +104,7 @@ int debug_comment_init(running_machine *machine) /* automatically load em up */ debug_comment_load(machine); - add_exit_callback(machine, debug_comment_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, debug_comment_exit); return 1; } @@ -415,7 +415,7 @@ int debug_comment_save(running_machine *machine) file_error filerr; mame_file *fp; - astring fname(machine->basename, ".cmt"); + astring fname(machine->basename(), ".cmt"); filerr = mame_fopen(SEARCHPATH_COMMENT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &fp); if (filerr == FILERR_NONE) @@ -444,7 +444,7 @@ int debug_comment_load(running_machine *machine) file_error filerr; mame_file *fp; - astring fname(machine->basename, ".cmt"); + astring fname(machine->basename(), ".cmt"); filerr = mame_fopen(SEARCHPATH_COMMENT, fname, OPEN_FLAG_READ, &fp); if (filerr != FILERR_NONE) return 0; @@ -524,7 +524,7 @@ error: debug_comment_exit - saves the comments and frees memory -------------------------------------------------------------------------*/ -static void debug_comment_exit(running_machine *machine) +static void debug_comment_exit(running_machine &machine) { - debug_comment_save(machine); + debug_comment_save(&machine); } diff --git a/src/emu/debug/debugcon.c b/src/emu/debug/debugcon.c index 10ed838ce47..3b101ac8cf1 100644 --- a/src/emu/debug/debugcon.c +++ b/src/emu/debug/debugcon.c @@ -68,7 +68,7 @@ static debug_command *commandlist; FUNCTION PROTOTYPES ***************************************************************************/ -static void debug_console_exit(running_machine *machine); +static void debug_console_exit(running_machine &machine); @@ -99,7 +99,7 @@ void debug_console_init(running_machine *machine) debug_console_printf(machine, "Currently targeting %s (%s)\n", machine->gamedrv->name, machine->gamedrv->description); /* request callback upon exiting */ - add_exit_callback(machine, debug_console_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, debug_console_exit); } @@ -108,7 +108,7 @@ void debug_console_init(running_machine *machine) system -------------------------------------------------*/ -static void debug_console_exit(running_machine *machine) +static void debug_console_exit(running_machine &machine) { /* free allocated memory */ if (console_textbuf) @@ -409,7 +409,7 @@ void debug_console_register_command(running_machine *machine, const char *comman { debug_command *cmd; - assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call debug_console_register_command() at init time!"); + assert_always(machine->phase() == MACHINE_PHASE_INIT, "Can only call debug_console_register_command() at init time!"); assert_always((machine->debug_flags & DEBUG_FLAG_ENABLED) != 0, "Cannot call debug_console_register_command() when debugger is not running"); cmd = auto_alloc_clear(machine, debug_command); @@ -541,13 +541,13 @@ text_buffer *debug_console_get_textbuf(void) the errorlog ring buffer -------------------------------------------------*/ -void debug_errorlog_write_line(running_machine *machine, const char *line) +void debug_errorlog_write_line(running_machine &machine, const char *line) { if (errorlog_textbuf) text_buffer_print(errorlog_textbuf, line); /* force an update of any log views */ - machine->m_debug_view->update_all(DVT_LOG); + machine.m_debug_view->update_all(DVT_LOG); } diff --git a/src/emu/debug/debugcon.h b/src/emu/debug/debugcon.h index 4197e108b70..3ff691c9dbd 100644 --- a/src/emu/debug/debugcon.h +++ b/src/emu/debug/debugcon.h @@ -90,7 +90,7 @@ void CLIB_DECL debug_console_printf_wrap(running_machine *machine, int wrapcol, text_buffer * debug_console_get_textbuf(void); /* errorlog management */ -void debug_errorlog_write_line(running_machine *machine, const char *line); +void debug_errorlog_write_line(running_machine &machine, const char *line); text_buffer * debug_errorlog_get_textbuf(void); #endif diff --git a/src/emu/debug/debugcpu.c b/src/emu/debug/debugcpu.c index 7b00434fe39..c9ac5f77f86 100644 --- a/src/emu/debug/debugcpu.c +++ b/src/emu/debug/debugcpu.c @@ -83,7 +83,7 @@ struct _debugcpu_private ***************************************************************************/ /* internal helpers */ -static void debug_cpu_exit(running_machine *machine); +static void debug_cpu_exit(running_machine &machine); static void on_vblank(screen_device &device, void *param, bool vblank_state); static void reset_transient_flags(running_machine *machine); static void compute_debug_flags(device_t *device); @@ -222,7 +222,7 @@ void debug_cpu_init(running_machine *machine) if (machine->primary_screen != NULL) machine->primary_screen->register_vblank_callback(on_vblank, NULL); - add_exit_callback(machine, debug_cpu_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, debug_cpu_exit); } @@ -638,7 +638,7 @@ void debug_cpu_instruction_hook(device_t *device, offs_t curpc) process_source_file(device->machine); /* if an event got scheduled, resume */ - if (mame_is_scheduled_event_pending(device->machine)) + if (device->machine->scheduled_event_pending()) global->execution_state = EXECUTION_STATE_RUNNING; } sound_mute(device->machine, FALSE); @@ -1157,7 +1157,7 @@ void debug_cpu_source_script(running_machine *machine, const char *file) global->source_file = fopen(file, "r"); if (!global->source_file) { - if (mame_get_phase(machine) == MAME_PHASE_RUNNING) + if (machine->phase() == MACHINE_PHASE_RUNNING) debug_console_printf(machine, "Cannot open command file '%s'\n", file); else fatalerror("Cannot open command file '%s'", file); @@ -1868,14 +1868,14 @@ UINT64 debug_read_opcode(const address_space *space, offs_t address, int size, i debug_cpu_exit - free all memory -------------------------------------------------*/ -static void debug_cpu_exit(running_machine *machine) +static void debug_cpu_exit(running_machine &machine) { - debugcpu_private *global = machine->debugcpu_data; + debugcpu_private *global = machine.debugcpu_data; device_t *cpu; int spacenum; /* loop over all watchpoints and breakpoints to free their memory */ - for (cpu = machine->firstcpu; cpu != NULL; cpu = cpu_next(cpu)) + for (cpu = machine.firstcpu; cpu != NULL; cpu = cpu_next(cpu)) { cpu_debug_data *cpudebug = cpu_get_debug_data(cpu); @@ -1883,7 +1883,7 @@ static void debug_cpu_exit(running_machine *machine) if (cpudebug->trace.file != NULL) fclose(cpudebug->trace.file); if (cpudebug->trace.action != NULL) - auto_free(machine, cpudebug->trace.action); + auto_free(&machine, cpudebug->trace.action); /* free the symbol table */ if (cpudebug->symtable != NULL) @@ -1891,14 +1891,14 @@ static void debug_cpu_exit(running_machine *machine) /* free all breakpoints */ while (cpudebug->bplist != NULL) - debug_cpu_breakpoint_clear(machine, cpudebug->bplist->index); + debug_cpu_breakpoint_clear(&machine, cpudebug->bplist->index); /* loop over all address spaces */ for (spacenum = 0; spacenum < ARRAY_LENGTH(cpudebug->wplist); spacenum++) { /* free all watchpoints */ while (cpudebug->wplist[spacenum] != NULL) - debug_cpu_watchpoint_clear(machine, cpudebug->wplist[spacenum]->index); + debug_cpu_watchpoint_clear(&machine, cpudebug->wplist[spacenum]->index); } } @@ -1951,7 +1951,7 @@ static void compute_debug_flags(device_t *device) machine->debug_flags |= DEBUG_FLAG_ENABLED; /* if we are ignoring this CPU, or if events are pending, we're done */ - if ((cpudebug->flags & DEBUG_FLAG_OBSERVING) == 0 || mame_is_scheduled_event_pending(machine) || mame_is_save_or_load_pending(machine)) + if ((cpudebug->flags & DEBUG_FLAG_OBSERVING) == 0 || machine->scheduled_event_pending() || machine->save_or_load_pending()) return; /* many of our states require us to be called on each instruction */ @@ -2525,15 +2525,12 @@ static UINT64 expression_read_program_direct(const address_space *space, int opc static UINT64 expression_read_memory_region(running_machine *machine, const char *rgntag, offs_t address, int size) { - UINT8 *base = memory_region(machine, rgntag); + const region_info *region = machine->region(rgntag); UINT64 result = ~(UINT64)0 >> (64 - 8*size); /* make sure we get a valid base before proceeding */ - if (base != NULL) + if (region != NULL) { - UINT32 length = memory_region_length(machine, rgntag); - UINT32 flags = memory_region_flags(machine, rgntag); - /* call ourself recursively until we are byte-sized */ if (size > 1) { @@ -2545,21 +2542,21 @@ static UINT64 expression_read_memory_region(running_machine *machine, const char r1 = expression_read_memory_region(machine, rgntag, address + halfsize, halfsize); /* assemble based on the target endianness */ - if ((flags & ROMREGION_ENDIANMASK) == ROMREGION_LE) + if (region->endianness() == ENDIANNESS_LITTLE) result = r0 | (r1 << (8 * halfsize)); else result = r1 | (r0 << (8 * halfsize)); } /* only process if we're within range */ - else if (address < length) + else if (address < region->bytes()) { /* lowmask specified which address bits are within the databus width */ - UINT32 lowmask = (1 << ((flags & ROMREGION_WIDTHMASK) >> 8)) - 1; - base += address & ~lowmask; + UINT32 lowmask = region->width() - 1; + UINT8 *base = region->base() + (address & ~lowmask); /* if we have a valid base, return the appropriate byte */ - if ((flags & ROMREGION_ENDIANMASK) == ROMREGION_LE) + if (region->endianness() == ENDIANNESS_LITTLE) result = base[BYTE8_XOR_LE(address) & lowmask]; else result = base[BYTE8_XOR_BE(address) & lowmask]; @@ -2701,14 +2698,11 @@ static void expression_write_program_direct(const address_space *space, int opco static void expression_write_memory_region(running_machine *machine, const char *rgntag, offs_t address, int size, UINT64 data) { debugcpu_private *global = machine->debugcpu_data; - UINT8 *base = memory_region(machine, rgntag); + const region_info *region = machine->region(rgntag); /* make sure we get a valid base before proceeding */ - if (base != NULL) + if (region != NULL) { - UINT32 length = memory_region_length(machine, rgntag); - UINT32 flags = memory_region_flags(machine, rgntag); - /* call ourself recursively until we are byte-sized */ if (size > 1) { @@ -2717,7 +2711,7 @@ static void expression_write_memory_region(running_machine *machine, const char /* break apart based on the target endianness */ halfmask = ~(UINT64)0 >> (64 - 8 * halfsize); - if ((flags & ROMREGION_ENDIANMASK) == ROMREGION_LE) + if (region->endianness() == ENDIANNESS_LITTLE) { r0 = data & halfmask; r1 = (data >> (8 * halfsize)) & halfmask; @@ -2734,14 +2728,14 @@ static void expression_write_memory_region(running_machine *machine, const char } /* only process if we're within range */ - else if (address < length) + else if (address < region->bytes()) { /* lowmask specified which address bits are within the databus width */ - UINT32 lowmask = (1 << ((flags & ROMREGION_WIDTHMASK) >> 8)) - 1; - base += address & ~lowmask; + UINT32 lowmask = region->width() - 1; + UINT8 *base = region->base() + (address & ~lowmask); /* if we have a valid base, set the appropriate byte */ - if ((flags & ROMREGION_ENDIANMASK) == ROMREGION_LE) + if (region->endianness() == ENDIANNESS_LITTLE) base[BYTE8_XOR_LE(address) & lowmask] = data; else base[BYTE8_XOR_BE(address) & lowmask] = data; diff --git a/src/emu/debug/dvmemory.c b/src/emu/debug/dvmemory.c index 840c9c58944..a3c6548d95d 100644 --- a/src/emu/debug/dvmemory.c +++ b/src/emu/debug/dvmemory.c @@ -165,9 +165,9 @@ void debug_view_memory::enumerate_sources() } // then add all the memory regions - for (const region_info *region = m_machine.regionlist.first(); region != NULL; region = region->next()) + for (const region_info *region = m_machine.m_regionlist.first(); region != NULL; region = region->next()) { - name.printf("Region '%s'", region->name.cstr()); + name.printf("Region '%s'", region->name()); m_source_list.append(*auto_alloc(&m_machine, debug_view_memory_source(name, *region))); } diff --git a/src/emu/debugger.c b/src/emu/debugger.c index 12a4b5360fb..f04f20c26aa 100644 --- a/src/emu/debugger.c +++ b/src/emu/debugger.c @@ -48,7 +48,7 @@ static int atexit_registered; FUNCTION PROTOTYPES ***************************************************************************/ -static void debugger_exit(running_machine *machine); +static void debugger_exit(running_machine &machine); @@ -78,7 +78,7 @@ void debugger_init(running_machine *machine) debugint_init(machine); /* allocate a new entry for our global list */ - add_exit_callback(machine, debugger_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, debugger_exit); entry = global_alloc(machine_entry); entry->next = machine_list; entry->machine = machine; @@ -90,7 +90,7 @@ void debugger_init(running_machine *machine) atexit_registered = TRUE; /* listen in on the errorlog */ - add_logerror_callback(machine, debug_errorlog_write_line); + machine->add_logerror_callback(debug_errorlog_write_line); } } @@ -111,13 +111,13 @@ void debugger_refresh_display(running_machine *machine) global list of active machines for cleanup -------------------------------------------------*/ -static void debugger_exit(running_machine *machine) +static void debugger_exit(running_machine &machine) { machine_entry **entryptr; /* remove this machine from the list; it came down cleanly */ for (entryptr = &machine_list; *entryptr != NULL; entryptr = &(*entryptr)->next) - if ((*entryptr)->machine == machine) + if ((*entryptr)->machine == &machine) { machine_entry *deleteme = *entryptr; *entryptr = deleteme->next; diff --git a/src/emu/debugint/debugint.c b/src/emu/debugint/debugint.c index 7eef8787ffc..791849b01fd 100644 --- a/src/emu/debugint/debugint.c +++ b/src/emu/debugint/debugint.c @@ -879,7 +879,7 @@ static void dview_update(debug_view &dw, void *osdprivate) #endif } -static void debugint_exit(running_machine *machine) +static void debugint_exit(running_machine &machine) { for (DView *ndv = list; ndv != NULL; ) { @@ -919,7 +919,7 @@ void debugint_init(running_machine *machine) debug_font_width++; /* FIXME: above does not really work */ debug_font_width = 10; - add_exit_callback(machine, debugint_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, debugint_exit); } #if 0 @@ -1070,18 +1070,18 @@ static void on_step_out_activate(DView *dv, const ui_menu_event *event) static void on_hard_reset_activate(DView *dv, const ui_menu_event *event) { - mame_schedule_hard_reset(dv->machine); + dv->machine->schedule_hard_reset(); } static void on_soft_reset_activate(DView *dv, const ui_menu_event *event) { - mame_schedule_soft_reset(dv->machine); + dv->machine->schedule_soft_reset(); debug_cpu_go(dv->machine, ~0); } static void on_exit_activate(DView *dv, const ui_menu_event *event) { - mame_schedule_exit(dv->machine); + dv->machine->schedule_exit(); } static void on_view_opcodes_activate(DView *dv, const ui_menu_event *event) @@ -1349,7 +1349,7 @@ static void handle_menus(running_machine *machine) const ui_menu_event *event; render_container_empty(render_container_get_ui()); - ui_input_frame_update(machine); + ui_input_frame_update(*machine); if (menu != NULL) { /* process the menu */ @@ -1474,7 +1474,7 @@ void debugint_wait_for_debugger(running_device *device, int firststop) void debugint_update_during_game(running_machine *machine) { - if (!debug_cpu_is_stopped(machine) && mame_get_phase(machine) == MAME_PHASE_RUNNING) + if (!debug_cpu_is_stopped(machine) && machine->phase() == MACHINE_PHASE_RUNNING) { update_views(); } diff --git a/src/emu/devimage.c b/src/emu/devimage.c index dcb4ea41b41..df10c054b4e 100644 --- a/src/emu/devimage.c +++ b/src/emu/devimage.c @@ -365,7 +365,7 @@ done: if (m_err) { if (!m_init_phase) { - if (mame_get_phase(machine) == MAME_PHASE_RUNNING) + if (machine->phase() == MACHINE_PHASE_RUNNING) popmessage("Error: Unable to %s image '%s': %s\n", is_create ? "create" : "load", path, error()); else mame_printf_error("Error: Unable to %s image '%s': %s", is_create ? "create" : "load", path, error()); @@ -375,12 +375,12 @@ done: else { /* do we need to reset the CPU? only schedule it if load/create is successful */ if ((attotime_compare(timer_get_time(device().machine), attotime_zero) > 0) && m_image_config.is_reset_on_load()) - mame_schedule_hard_reset(device().machine); + device().machine->schedule_hard_reset(); else { if (!m_init_phase) { - if (mame_get_phase(machine) == MAME_PHASE_RUNNING) + if (machine->phase() == MACHINE_PHASE_RUNNING) popmessage("Image '%s' was successfully %s.", path, is_create ? "created" : "loaded"); else mame_printf_info("Image '%s' was successfully %s.\n", path, is_create ? "created" : "loaded"); diff --git a/src/emu/devintrf.c b/src/emu/devintrf.c index d3f8c960783..25caae2b1bb 100644 --- a/src/emu/devintrf.c +++ b/src/emu/devintrf.c @@ -80,7 +80,7 @@ resource_pool &machine_get_pool(running_machine &machine) { // temporary to get around include dependencies, until CPUs // get a proper device class - return machine.respool; + return machine.m_respool; } @@ -125,8 +125,8 @@ void device_list::start_all() { // add exit and reset callbacks assert(m_machine != NULL); - add_reset_callback(m_machine, static_reset); - add_exit_callback(m_machine, static_exit); + m_machine->add_notifier(MACHINE_NOTIFY_RESET, static_reset); + m_machine->add_notifier(MACHINE_NOTIFY_EXIT, static_exit); // add pre-save and post-load callbacks state_save_register_presave(m_machine, static_pre_save, this); @@ -185,9 +185,9 @@ void device_list::reset_all() } -void device_list::static_reset(running_machine *machine) +void device_list::static_reset(running_machine &machine) { - machine->m_devicelist.reset_all(); + machine.m_devicelist.reset_all(); } @@ -195,9 +195,9 @@ void device_list::static_reset(running_machine *machine) // static_exit - tear down all the devices //------------------------------------------------- -void device_list::static_exit(running_machine *machine) +void device_list::static_exit(running_machine &machine) { - machine->m_devicelist.reset(); + machine.m_devicelist.reset(); } diff --git a/src/emu/devintrf.h b/src/emu/devintrf.h index 44398b2a784..1e6ff8a3d9e 100644 --- a/src/emu/devintrf.h +++ b/src/emu/devintrf.h @@ -201,8 +201,8 @@ class device_list : public tagged_device_list<device_t> { running_machine *m_machine; - static void static_reset(running_machine *machine); - static void static_exit(running_machine *machine); + static void static_reset(running_machine &machine); + static void static_exit(running_machine &machine); static void static_pre_save(running_machine *machine, void *param); static void static_post_load(running_machine *machine, void *param); diff --git a/src/emu/diexec.c b/src/emu/diexec.c index 16ee47f37c4..0436c7c1155 100644 --- a/src/emu/diexec.c +++ b/src/emu/diexec.c @@ -303,7 +303,7 @@ device_execute_interface::~device_execute_interface() bool device_execute_interface::is_executing() const { - return (this == m_machine.scheduler.currently_executing()); + return (this == m_machine.scheduler().currently_executing()); } @@ -361,7 +361,7 @@ void device_execute_interface::adjust_icount(int delta) void device_execute_interface::abort_timeslice() { // ignore if not the executing device - if (this != m_machine.scheduler.currently_executing()) + if (this != m_machine.scheduler().currently_executing()) return; // swallow the remaining cycles @@ -655,7 +655,7 @@ void device_execute_interface::interface_clock_changed() m_divisor = attos; // re-compute the perfect interleave factor - m_machine.scheduler.compute_perfect_interleave(); + m_machine.scheduler().compute_perfect_interleave(); } diff --git a/src/emu/drawgfx.c b/src/emu/drawgfx.c index be4c858bb4f..9ab2b01c4d5 100644 --- a/src/emu/drawgfx.c +++ b/src/emu/drawgfx.c @@ -92,8 +92,9 @@ void gfx_init(running_machine *machine) for (curgfx = 0; curgfx < MAX_GFX_ELEMENTS && gfxdecodeinfo[curgfx].gfxlayout != NULL; curgfx++) { const gfx_decode_entry *gfxdecode = &gfxdecodeinfo[curgfx]; - UINT32 region_length = (gfxdecode->memory_region != NULL) ? (8 * memory_region_length(machine, gfxdecode->memory_region)) : 0; - const UINT8 *region_base = (gfxdecode->memory_region != NULL) ? memory_region(machine, gfxdecode->memory_region) : NULL; + const region_info *region = (gfxdecode->memory_region != NULL) ? machine->region(gfxdecode->memory_region) : NULL; + UINT32 region_length = (region != NULL) ? (8 * region->bytes()) : 0; + const UINT8 *region_base = (region != NULL) ? region->base() : NULL; UINT32 xscale = (gfxdecode->xscale == 0) ? 1 : gfxdecode->xscale; UINT32 yscale = (gfxdecode->yscale == 0) ? 1 : gfxdecode->yscale; UINT32 *extpoffs, extxoffs[MAX_ABS_GFX_SIZE], extyoffs[MAX_ABS_GFX_SIZE]; diff --git a/src/emu/emu.h b/src/emu/emu.h index 50ab4d3853a..3e0d50be07f 100644 --- a/src/emu/emu.h +++ b/src/emu/emu.h @@ -107,6 +107,7 @@ #include "mess.h" #include "messdrv.h" #endif /* MESS */ +#include "machine.h" #include "mame.h" // video-related diff --git a/src/emu/emu.mak b/src/emu/emu.mak index 99e8c444763..eeaeffc32c2 100644 --- a/src/emu/emu.mak +++ b/src/emu/emu.mak @@ -72,6 +72,7 @@ EMUOBJS = \ $(EMUOBJ)/inptport.o \ $(EMUOBJ)/ioprocs.o \ $(EMUOBJ)/mame.o \ + $(EMUOBJ)/machine.o \ $(EMUOBJ)/mconfig.o \ $(EMUOBJ)/memory.o \ $(EMUOBJ)/output.o \ diff --git a/src/emu/emuopts.c b/src/emu/emuopts.c index 803204f8c22..2d69a3db0cd 100644 --- a/src/emu/emuopts.c +++ b/src/emu/emuopts.c @@ -216,10 +216,10 @@ const char *image_get_device_option(device_image_interface *image) { const char *result = NULL; - if (options_get_bool(mame_options(), OPTION_ADDED_DEVICE_OPTIONS)) + if (options_get_bool(image->device().machine->options(), OPTION_ADDED_DEVICE_OPTIONS)) { /* access the option */ - result = options_get_string(mame_options(), image->image_config().instance_name()); + result = options_get_string(image->device().machine->options(), image->image_config().instance_name()); } return result; } diff --git a/src/emu/emupal.c b/src/emu/emupal.c index a62ccd65f70..5e462e19c84 100644 --- a/src/emu/emupal.c +++ b/src/emu/emupal.c @@ -77,7 +77,7 @@ public: static void palette_presave(running_machine *machine, void *param); static void palette_postload(running_machine *machine, void *param); -static void palette_exit(running_machine *machine); +static void palette_exit(running_machine &machine); static void allocate_palette(running_machine *machine, palette_private *palette); static void allocate_color_tables(running_machine *machine, palette_private *palette); static void allocate_shadow_tables(running_machine *machine, palette_private *palette); @@ -104,7 +104,7 @@ void palette_init(running_machine *machine) /* request cleanup */ machine->palette_data = palette; - add_exit_callback(machine, palette_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, palette_exit); /* reset all our data */ palette->format = format; @@ -564,11 +564,11 @@ static void palette_postload(running_machine *machine, void *param) palette_exit - free any allocated memory -------------------------------------------------*/ -static void palette_exit(running_machine *machine) +static void palette_exit(running_machine &machine) { /* dereference the palette */ - if (machine->palette != NULL) - palette_deref(machine->palette); + if (machine.palette != NULL) + palette_deref(machine.palette); } diff --git a/src/emu/fileio.c b/src/emu/fileio.c index 07debd89215..d81b914db7c 100644 --- a/src/emu/fileio.c +++ b/src/emu/fileio.c @@ -77,7 +77,7 @@ struct _mame_path ***************************************************************************/ /* core functions */ -static void fileio_exit(running_machine *machine); +static void fileio_exit(running_machine &machine); /* file open/close */ static file_error fopen_internal(core_options *opts, path_iterator *iterator, const char *filename, UINT32 crc, UINT32 flags, mame_file **file); @@ -106,7 +106,7 @@ static int zip_header_is_path(const zip_file_header *header); void fileio_init(running_machine *machine) { - add_exit_callback(machine, fileio_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, fileio_exit); } @@ -114,7 +114,7 @@ void fileio_init(running_machine *machine) fileio_exit - clean up behind ourselves -------------------------------------------------*/ -static void fileio_exit(running_machine *machine) +static void fileio_exit(running_machine &machine) { zip_file_cache_clear(); } diff --git a/src/emu/image.c b/src/emu/image.c index 58aaee2599d..8dbff76d1a5 100644 --- a/src/emu/image.c +++ b/src/emu/image.c @@ -159,7 +159,7 @@ done: static void image_options_extract(running_machine *machine) { /* only extract the device options if we've added them */ - if (options_get_bool(mame_options(), OPTION_ADDED_DEVICE_OPTIONS)) { + if (options_get_bool(machine->options(), OPTION_ADDED_DEVICE_OPTIONS)) { int index = 0; device_image_interface *image = NULL; @@ -168,14 +168,14 @@ static void image_options_extract(running_machine *machine) const char *filename = image->filename(); /* and set the option */ - options_set_string(mame_options(), image->image_config().instance_name() , filename ? filename : "", OPTION_PRIORITY_CMDLINE); + options_set_string(machine->options(), image->image_config().instance_name() , filename ? filename : "", OPTION_PRIORITY_CMDLINE); index++; } } /* write the config, if appropriate */ - if (options_get_bool(mame_options(), OPTION_WRITECONFIG)) + if (options_get_bool(machine->options(), OPTION_WRITECONFIG)) write_config(NULL, machine->gamedrv); } @@ -184,14 +184,14 @@ static void image_options_extract(running_machine *machine) extract options -------------------------------------------------*/ -void image_unload_all(running_machine *machine) +void image_unload_all(running_machine &machine) { device_image_interface *image = NULL; // extract the options - image_options_extract(machine); + image_options_extract(&machine); - for (bool gotone = machine->m_devicelist.first(image); gotone; gotone = image->next(image)) + for (bool gotone = machine.m_devicelist.first(image); gotone; gotone = image->next(image)) { // unload this image image->unload(); @@ -229,7 +229,7 @@ void image_device_init(running_machine *machine) const char *image_basename_str = image->basename(); /* unload all images */ - image_unload_all(machine); + image_unload_all(*machine); fatalerror_exitcode(machine, MAMERR_DEVICE, "Device %s load (%s) failed: %s", image->image_config().devconfig().name(), @@ -271,7 +271,7 @@ void image_postdevice_init(running_machine *machine) const char *image_basename_str = image->basename(); /* unload all images */ - image_unload_all(machine); + image_unload_all(*machine); fatalerror_exitcode(machine, MAMERR_DEVICE, "Device %s load (%s) failed: %s", image->image_config().devconfig().name(), @@ -281,7 +281,7 @@ void image_postdevice_init(running_machine *machine) } /* add a callback for when we shut down */ - add_exit_callback(machine, image_unload_all); + machine->add_notifier(MACHINE_NOTIFY_EXIT, image_unload_all); } /*************************************************************************** INITIALIZATION diff --git a/src/emu/inptport.c b/src/emu/inptport.c index ac1975cb35b..eb9c8094dcb 100644 --- a/src/emu/inptport.c +++ b/src/emu/inptport.c @@ -766,7 +766,7 @@ static const struct ***************************************************************************/ /* core system management */ -static void input_port_exit(running_machine *machine); +static void input_port_exit(running_machine &machine); /* port reading */ static INT32 apply_analog_settings(INT32 current, analog_field_state *analog); @@ -779,7 +779,7 @@ static device_field_info *init_field_device_info(const input_field_config *field static analog_field_state *init_field_analog_state(const input_field_config *field); /* once-per-frame updates */ -static void frame_update_callback(running_machine *machine); +static void frame_update_callback(running_machine &machine); static void frame_update(running_machine *machine); static void frame_update_digital_joysticks(running_machine *machine); static void frame_update_analog_field(running_machine *machine, analog_field_state *analog); @@ -888,7 +888,7 @@ INLINE const char *get_port_tag(const input_port_config *port, char *tempbuffer) if (port->tag != NULL) return port->tag; - for (curport = port->machine->portlist.first(); curport != NULL; curport = curport->next()) + for (curport = port->machine->m_portlist.first(); curport != NULL; curport = curport->next()) { if (curport == port) break; @@ -982,8 +982,8 @@ time_t input_port_init(running_machine *machine, const input_port_token *tokens) //portdata = machine->input_port_data; /* add an exit callback and a frame callback */ - add_exit_callback(machine, input_port_exit); - add_frame_callback(machine, frame_update_callback); + machine->add_notifier(MACHINE_NOTIFY_EXIT, input_port_exit); + machine->add_notifier(MACHINE_NOTIFY_FRAME, frame_update_callback); /* initialize the default port info from the OSD */ init_port_types(machine); @@ -991,7 +991,7 @@ time_t input_port_init(running_machine *machine, const input_port_token *tokens) /* if we have a token list, proceed */ if (tokens != NULL) { - input_port_list_init(machine->portlist, tokens, errorbuf, sizeof(errorbuf), TRUE); + input_port_list_init(machine->m_portlist, tokens, errorbuf, sizeof(errorbuf), TRUE); if (errorbuf[0] != 0) mame_printf_error("Input port errors:\n%s", errorbuf); init_port_state(machine); @@ -1013,11 +1013,11 @@ time_t input_port_init(running_machine *machine, const input_port_token *tokens) we clean up and close our files -------------------------------------------------*/ -static void input_port_exit(running_machine *machine) +static void input_port_exit(running_machine &machine) { /* close any playback or recording files */ - playback_end(machine, NULL); - record_end(machine, NULL); + playback_end(&machine, NULL); + record_end(&machine, NULL); } @@ -1597,7 +1597,7 @@ int input_port_get_crosshair_position(running_machine *machine, int player, floa int gotx = FALSE, goty = FALSE; /* read all the lightgun values */ - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) for (field = port->fieldlist; field != NULL; field = field->next) if (field->player == player && field->crossaxis != CROSSHAIR_AXIS_NONE) if (input_condition_true(machine, &field->condition)) @@ -1666,7 +1666,7 @@ void input_port_update_defaults(running_machine *machine) const input_port_config *port; /* loop over all input ports */ - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) { const input_field_config *field; @@ -2010,13 +2010,13 @@ static astring *get_keyboard_key_name(const input_field_config *field) static void init_port_state(running_machine *machine) { - const char *joystick_map_default = options_get_string(mame_options(), OPTION_JOYSTICK_MAP); + const char *joystick_map_default = options_get_string(machine->options(), OPTION_JOYSTICK_MAP); input_port_private *portdata = machine->input_port_data; const input_field_config *field; const input_port_config *port; /* allocate live structures to mirror the configuration */ - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) { analog_field_state **analogstatetail; device_field_info **readdevicetail; @@ -2092,18 +2092,18 @@ static void init_port_state(running_machine *machine) } /* handle autoselection of devices */ - init_autoselect_devices(machine->portlist, IPT_PADDLE, IPT_PADDLE_V, 0, OPTION_PADDLE_DEVICE, "paddle"); - init_autoselect_devices(machine->portlist, IPT_AD_STICK_X, IPT_AD_STICK_Y, IPT_AD_STICK_Z, OPTION_ADSTICK_DEVICE, "analog joystick"); - init_autoselect_devices(machine->portlist, IPT_LIGHTGUN_X, IPT_LIGHTGUN_Y, 0, OPTION_LIGHTGUN_DEVICE, "lightgun"); - init_autoselect_devices(machine->portlist, IPT_PEDAL, IPT_PEDAL2, IPT_PEDAL3, OPTION_PEDAL_DEVICE, "pedal"); - init_autoselect_devices(machine->portlist, IPT_DIAL, IPT_DIAL_V, 0, OPTION_DIAL_DEVICE, "dial"); - init_autoselect_devices(machine->portlist, IPT_TRACKBALL_X, IPT_TRACKBALL_Y, 0, OPTION_TRACKBALL_DEVICE, "trackball"); - init_autoselect_devices(machine->portlist, IPT_POSITIONAL, IPT_POSITIONAL_V, 0, OPTION_POSITIONAL_DEVICE, "positional"); - init_autoselect_devices(machine->portlist, IPT_MOUSE_X, IPT_MOUSE_Y, 0, OPTION_MOUSE_DEVICE, "mouse"); + init_autoselect_devices(machine->m_portlist, IPT_PADDLE, IPT_PADDLE_V, 0, OPTION_PADDLE_DEVICE, "paddle"); + init_autoselect_devices(machine->m_portlist, IPT_AD_STICK_X, IPT_AD_STICK_Y, IPT_AD_STICK_Z, OPTION_ADSTICK_DEVICE, "analog joystick"); + init_autoselect_devices(machine->m_portlist, IPT_LIGHTGUN_X, IPT_LIGHTGUN_Y, 0, OPTION_LIGHTGUN_DEVICE, "lightgun"); + init_autoselect_devices(machine->m_portlist, IPT_PEDAL, IPT_PEDAL2, IPT_PEDAL3, OPTION_PEDAL_DEVICE, "pedal"); + init_autoselect_devices(machine->m_portlist, IPT_DIAL, IPT_DIAL_V, 0, OPTION_DIAL_DEVICE, "dial"); + init_autoselect_devices(machine->m_portlist, IPT_TRACKBALL_X, IPT_TRACKBALL_Y, 0, OPTION_TRACKBALL_DEVICE, "trackball"); + init_autoselect_devices(machine->m_portlist, IPT_POSITIONAL, IPT_POSITIONAL_V, 0, OPTION_POSITIONAL_DEVICE, "positional"); + init_autoselect_devices(machine->m_portlist, IPT_MOUSE_X, IPT_MOUSE_Y, 0, OPTION_MOUSE_DEVICE, "mouse"); /* look for 4-way joysticks and change the default map if we find any */ if (joystick_map_default[0] == 0 || strcmp(joystick_map_default, "auto") == 0) - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) for (field = port->fieldlist; field != NULL; field = field->next) if (field->state->joystick != NULL && field->way == 4) { @@ -2379,14 +2379,14 @@ static analog_field_state *init_field_analog_state(const input_field_config *fie only if we are not paused -------------------------------------------------*/ -static void frame_update_callback(running_machine *machine) +static void frame_update_callback(running_machine &machine) { /* if we're paused, don't do anything */ - if (mame_is_paused(machine)) + if (machine.paused()) return; /* otherwise, use the common code */ - frame_update(machine); + frame_update(&machine); } static key_buffer *get_buffer(running_machine *machine) @@ -2491,11 +2491,11 @@ profiler_mark_start(PROFILER_INPUT); const char *tag = NULL; input_port_value mask; if (render_target_map_point_input(mouse_target, mouse_target_x, mouse_target_y, &tag, &mask, NULL, NULL)) - mouse_field = input_field_by_tag_and_mask(machine->portlist, tag, mask); + mouse_field = input_field_by_tag_and_mask(machine->m_portlist, tag, mask); } /* loop over all input ports */ - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) { const input_field_config *field; device_field_info *device_field; @@ -4068,7 +4068,7 @@ static int load_game_config(running_machine *machine, xml_data_node *portnode, i defvalue = xml_get_attribute_int(portnode, "defvalue", 0); /* find the port we want; if no tag, search them all */ - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) if (tag == NULL || strcmp(get_port_tag(port, tempbuffer), tag) == 0) for (field = port->fieldlist; field != NULL; field = field->next) @@ -4230,7 +4230,7 @@ static void save_game_inputs(running_machine *machine, xml_data_node *parentnode const input_port_config *port; /* iterate over ports */ - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) for (field = port->fieldlist; field != NULL; field = field->next) if (save_this_input_field_type(field->type)) { @@ -4388,7 +4388,7 @@ static UINT64 playback_read_uint64(running_machine *machine) static time_t playback_init(running_machine *machine) { - const char *filename = options_get_string(mame_options(), OPTION_PLAYBACK); + const char *filename = options_get_string(machine->options(), OPTION_PLAYBACK); input_port_private *portdata = machine->input_port_data; UINT8 header[INP_HEADER_SIZE]; file_error filerr; @@ -4586,10 +4586,10 @@ static void record_write_uint64(running_machine *machine, UINT64 data) static void record_init(running_machine *machine) { - const char *filename = options_get_string(mame_options(), OPTION_RECORD); + const char *filename = options_get_string(machine->options(), OPTION_RECORD); input_port_private *portdata = machine->input_port_data; UINT8 header[INP_HEADER_SIZE]; - mame_system_time systime; + system_time systime; file_error filerr; /* if no file, nothing to do */ @@ -4601,7 +4601,7 @@ static void record_init(running_machine *machine) assert_always(filerr == FILERR_NONE, "Failed to open file for recording"); /* get the base time */ - mame_get_base_datetime(machine, &systime); + machine->base_datetime(systime); /* fill in the header */ memset(header, 0, sizeof(header)); @@ -4708,7 +4708,7 @@ int input_machine_has_keyboard(running_machine *machine) #ifdef MESS const input_field_config *field; const input_port_config *port; - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) { for (field = port->fieldlist; field != NULL; field = field->next) { @@ -4910,7 +4910,7 @@ int validate_natural_keyboard_statics(void) CORE IMPLEMENTATION ***************************************************************************/ -static void clear_keybuffer(running_machine *machine) +static void clear_keybuffer(running_machine &machine) { keybuffer = NULL; queue_chars = NULL; @@ -4923,7 +4923,7 @@ static void setup_keybuffer(running_machine *machine) { inputx_timer = timer_alloc(machine, inputx_timerproc, NULL); keybuffer = auto_alloc_clear(machine, key_buffer); - add_exit_callback(machine, clear_keybuffer); + machine->add_notifier(MACHINE_NOTIFY_EXIT, clear_keybuffer); } @@ -4946,7 +4946,7 @@ void inputx_init(running_machine *machine) /* posting keys directly only makes sense for a computer */ if (input_machine_has_keyboard(machine)) { - codes = build_codes(machine, machine->portlist.first()); + codes = build_codes(machine, machine->m_portlist.first()); setup_keybuffer(machine); } } @@ -5408,7 +5408,7 @@ int input_has_input_class(running_machine *machine, int inputclass) const input_port_config *port; const input_field_config *field; - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) { for (field = port->fieldlist; field != NULL; field = field->next) { @@ -5433,7 +5433,7 @@ int input_count_players(running_machine *machine) int joystick_count; joystick_count = 0; - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) { for (field = port->fieldlist; field != NULL; field = field->next) { @@ -5464,7 +5464,7 @@ int input_category_active(running_machine *machine, int category) assert(category >= 1); /* loop through the input ports */ - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) { for (field = port->fieldlist; field != NULL; field = field->next) { diff --git a/src/emu/input.c b/src/emu/input.c index fd4bdef405d..47824850b57 100644 --- a/src/emu/input.c +++ b/src/emu/input.c @@ -420,7 +420,7 @@ const char joystick_map_4way_diagonal[] = "4444s8888..444458888.444555888.ss5. FUNCTION PROTOTYPES ***************************************************************************/ -static void input_frame(running_machine *machine); +static void input_frame(running_machine &machine); static input_device_item *input_code_item(running_machine *machine, input_code code); static INT32 convert_absolute_value(running_machine *machine, input_code code, input_device_item *item); static INT32 convert_relative_value(input_code code, input_device_item *item); @@ -587,28 +587,28 @@ void input_init(running_machine *machine) code_pressed_memory_reset(machine); /* request a per-frame callback for bookkeeping */ - add_frame_callback(machine, input_frame); + machine->add_notifier(MACHINE_NOTIFY_FRAME, input_frame); /* read input enable options */ device_list[DEVICE_CLASS_KEYBOARD].enabled = TRUE; - device_list[DEVICE_CLASS_MOUSE].enabled = options_get_bool(mame_options(), OPTION_MOUSE); - device_list[DEVICE_CLASS_LIGHTGUN].enabled = options_get_bool(mame_options(), OPTION_LIGHTGUN); - device_list[DEVICE_CLASS_JOYSTICK].enabled = options_get_bool(mame_options(), OPTION_JOYSTICK); + device_list[DEVICE_CLASS_MOUSE].enabled = options_get_bool(machine->options(), OPTION_MOUSE); + device_list[DEVICE_CLASS_LIGHTGUN].enabled = options_get_bool(machine->options(), OPTION_LIGHTGUN); + device_list[DEVICE_CLASS_JOYSTICK].enabled = options_get_bool(machine->options(), OPTION_JOYSTICK); /* read input device multi options */ - device_list[DEVICE_CLASS_KEYBOARD].multi = options_get_bool(mame_options(), OPTION_MULTIKEYBOARD); - device_list[DEVICE_CLASS_MOUSE].multi = options_get_bool(mame_options(), OPTION_MULTIMOUSE); + device_list[DEVICE_CLASS_KEYBOARD].multi = options_get_bool(machine->options(), OPTION_MULTIKEYBOARD); + device_list[DEVICE_CLASS_MOUSE].multi = options_get_bool(machine->options(), OPTION_MULTIMOUSE); device_list[DEVICE_CLASS_LIGHTGUN].multi = TRUE; device_list[DEVICE_CLASS_JOYSTICK].multi = TRUE; /* read other input options */ - state->steadykey_enabled = options_get_bool(mame_options(), OPTION_STEADYKEY); - state->lightgun_reload_button = options_get_bool(mame_options(), OPTION_OFFSCREEN_RELOAD); - state->joystick_deadzone = (INT32)(options_get_float(mame_options(), OPTION_JOYSTICK_DEADZONE) * INPUT_ABSOLUTE_MAX); - state->joystick_saturation = (INT32)(options_get_float(mame_options(), OPTION_JOYSTICK_SATURATION) * INPUT_ABSOLUTE_MAX); + state->steadykey_enabled = options_get_bool(machine->options(), OPTION_STEADYKEY); + state->lightgun_reload_button = options_get_bool(machine->options(), OPTION_OFFSCREEN_RELOAD); + state->joystick_deadzone = (INT32)(options_get_float(machine->options(), OPTION_JOYSTICK_DEADZONE) * INPUT_ABSOLUTE_MAX); + state->joystick_saturation = (INT32)(options_get_float(machine->options(), OPTION_JOYSTICK_SATURATION) * INPUT_ABSOLUTE_MAX); /* get the default joystick map */ - state->joystick_map_default = options_get_string(mame_options(), OPTION_JOYSTICK_MAP); + state->joystick_map_default = options_get_string(machine->options(), OPTION_JOYSTICK_MAP); if (state->joystick_map_default[0] == 0 || strcmp(state->joystick_map_default, "auto") == 0) state->joystick_map_default = joystick_map_8way; if (!joystick_map_parse(state->joystick_map_default, &map)) @@ -687,9 +687,9 @@ int input_device_set_joystick_map(running_machine *machine, int devindex, const bookkeeping -------------------------------------------------*/ -static void input_frame(running_machine *machine) +static void input_frame(running_machine &machine) { - input_private *state = machine->input_data; + input_private *state = machine.input_data; /* if steadykey is enabled, do processing here */ if (state->steadykey_enabled) @@ -710,7 +710,7 @@ static void input_frame(running_machine *machine) input_device_item *item = device->item[itemid]; if (item != NULL && item->itemclass == ITEM_CLASS_SWITCH) { - input_item_update_value(machine, item); + input_item_update_value(&machine, item); if ((item->current ^ item->oldkey) & 1) { changed = TRUE; @@ -752,7 +752,7 @@ input_device *input_device_add(running_machine *machine, input_device_class devc input_private *state = machine->input_data; input_device_list *devlist = &state->device_list[devclass]; - assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call input_device_add at init time!"); + assert_always(machine->phase() == MACHINE_PHASE_INIT, "Can only call input_device_add at init time!"); assert(name != NULL); assert(devclass != DEVICE_CLASS_INVALID && devclass < DEVICE_CLASS_MAXIMUM); @@ -794,7 +794,7 @@ void input_device_item_add(input_device *device, const char *name, void *interna input_device_item *item; input_item_id itemid_std = itemid; - assert_always(mame_get_phase(device->machine) == MAME_PHASE_INIT, "Can only call input_device_item_add at init time!"); + assert_always(device->machine->phase() == MACHINE_PHASE_INIT, "Can only call input_device_item_add at init time!"); assert(name != NULL); assert(itemid > ITEM_ID_INVALID && itemid < ITEM_ID_MAXIMUM); assert(getstate != NULL); diff --git a/src/emu/machine.c b/src/emu/machine.c new file mode 100644 index 00000000000..0dcd62d6b99 --- /dev/null +++ b/src/emu/machine.c @@ -0,0 +1,1003 @@ +/*************************************************************************** + + machine.c + + Controls execution of the core MAME system. + +**************************************************************************** + + Copyright Aaron Giles + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name 'MAME' nor the names of its contributors may be + used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +**************************************************************************** + + Since there has been confusion in the past over the order of + initialization and other such things, here it is, all spelled out + as of January, 2008: + + main() + - does platform-specific init + - calls mame_execute() [mame.c] + + mame_execute() [mame.c] + - calls mame_validitychecks() [validity.c] to perform validity checks on all compiled drivers + - begins resource tracking (level 1) + - calls create_machine [mame.c] to initialize the running_machine structure + - calls init_machine() [mame.c] + + init_machine() [mame.c] + - calls fileio_init() [fileio.c] to initialize file I/O info + - calls config_init() [config.c] to initialize configuration system + - calls input_init() [input.c] to initialize the input system + - calls output_init() [output.c] to initialize the output system + - calls state_init() [state.c] to initialize save state system + - calls state_save_allow_registration() [state.c] to allow registrations + - calls palette_init() [palette.c] to initialize palette system + - calls render_init() [render.c] to initialize the rendering system + - calls ui_init() [ui.c] to initialize the user interface + - calls generic_machine_init() [machine/generic.c] to initialize generic machine structures + - calls generic_video_init() [video/generic.c] to initialize generic video structures + - calls generic_sound_init() [audio/generic.c] to initialize generic sound structures + - calls timer_init() [timer.c] to reset the timer system + - calls osd_init() [osdepend.h] to do platform-specific initialization + - calls input_port_init() [inptport.c] to set up the input ports + - calls rom_init() [romload.c] to load the game's ROMs + - calls memory_init() [memory.c] to process the game's memory maps + - calls watchdog_init() [watchdog.c] to initialize the watchdog system + - calls the driver's DRIVER_INIT callback + - calls device_list_start() [devintrf.c] to start any devices + - calls video_init() [video.c] to start the video system + - calls tilemap_init() [tilemap.c] to start the tilemap system + - calls crosshair_init() [crsshair.c] to configure the crosshairs + - calls sound_init() [sound.c] to start the audio system + - calls debugger_init() [debugger.c] to set up the debugger + - calls the driver's MACHINE_START, SOUND_START, and VIDEO_START callbacks + - calls cheat_init() [cheat.c] to initialize the cheat system + - calls image_init() [image.c] to initialize the image system + + - calls config_load_settings() [config.c] to load the configuration file + - calls nvram_load [machine/generic.c] to load NVRAM + - calls ui_display_startup_screens() [ui.c] to display the the startup screens + - begins resource tracking (level 2) + - calls soft_reset() [mame.c] to reset all systems + + -------------------( at this point, we're up and running )---------------------- + + - calls scheduler->timeslice() [schedule.c] over and over until we exit + - ends resource tracking (level 2), freeing all auto_mallocs and timers + - calls the nvram_save() [machine/generic.c] to save NVRAM + - calls config_save_settings() [config.c] to save the game's configuration + - calls all registered exit routines [mame.c] + - ends resource tracking (level 1), freeing all auto_mallocs and timers + + - exits the program + +***************************************************************************/ + +#include "emu.h" +#include "emuopts.h" +#include "osdepend.h" +#include "config.h" +#include "debugger.h" +#include "image.h" +#include "profiler.h" +#include "render.h" +#include "cheat.h" +#include "ui.h" +#include "uimenu.h" +#include "uiinput.h" +#include "streams.h" +#include "crsshair.h" +#include "validity.h" +#include "debug/debugcon.h" + +#include <time.h> + + + +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** + +// a giant string buffer for temporary strings +static char giant_string_buffer[65536] = { 0 }; + + + +//************************************************************************** +// RUNNING MACHINE +//************************************************************************** + +//------------------------------------------------- +// running_machine - constructor +//------------------------------------------------- + +running_machine::running_machine(const game_driver &driver, const machine_config &_config, core_options &options, bool exit_to_game_select) + : m_regionlist(m_respool), + m_devicelist(m_respool), + config(&_config), + m_config(_config), + firstcpu(NULL), + gamedrv(&driver), + m_game(driver), + primary_screen(NULL), + palette(NULL), + pens(NULL), + colortable(NULL), + shadow_table(NULL), + priority_bitmap(NULL), + sample_rate(options_get_int(&options, OPTION_SAMPLERATE)), + debug_flags(0), + ui_active(false), + mame_data(NULL), + timer_data(NULL), + state_data(NULL), + memory_data(NULL), + palette_data(NULL), + tilemap_data(NULL), + streams_data(NULL), + devices_data(NULL), + romload_data(NULL), + sound_data(NULL), + input_data(NULL), + input_port_data(NULL), + ui_input_data(NULL), + cheat_data(NULL), + debugcpu_data(NULL), + generic_machine_data(NULL), + generic_video_data(NULL), + generic_audio_data(NULL), + m_debug_view(NULL), + driver_data(NULL), + m_logerror_list(NULL), + m_scheduler(*this), + m_options(options), + m_basename(driver.name), + m_current_phase(MACHINE_PHASE_PREINIT), + m_paused(false), + m_hard_reset_pending(false), + m_exit_pending(false), + m_exit_to_game_select(exit_to_game_select), + m_new_driver_pending(NULL), + m_soft_reset_timer(NULL), + m_logfile(NULL), + m_saveload_schedule(SLS_NONE), + m_saveload_schedule_time(attotime_zero), + m_saveload_searchpath(NULL), + m_rand_seed(0x9d14abd7) +{ + memset(gfx, 0, sizeof(gfx)); + memset(&generic, 0, sizeof(generic)); + memset(m_notifier_list, 0, sizeof(m_notifier_list)); + memset(&m_base_time, 0, sizeof(m_base_time)); + + // attach this machine to all the devices in the configuration + m_devicelist.import_config_list(m_config.m_devicelist, *this); + + // allocate the driver data (after devices) + if (m_config.m_driver_data_alloc != NULL) + driver_data = (*m_config.m_driver_data_alloc)(*this); + + // find devices + firstcpu = cpu_first(this); + primary_screen = screen_first(*this); + + // fetch core options + if (options_get_bool(&m_options, OPTION_DEBUG)) + debug_flags = (DEBUG_FLAG_ENABLED | DEBUG_FLAG_CALL_HOOK) | (options_get_bool(&m_options, OPTION_DEBUG_INTERNAL) ? 0 : DEBUG_FLAG_OSD_ENABLED); +} + + +//------------------------------------------------- +// ~running_machine - destructor +//------------------------------------------------- + +running_machine::~running_machine() +{ +} + + +//------------------------------------------------- +// describe_context - return a string describing +// which device is currently executing and its +// PC +//------------------------------------------------- + +const char *running_machine::describe_context() +{ + device_execute_interface *executing = m_scheduler.currently_executing(); + if (executing != NULL) + { + cpu_device *cpu = downcast<cpu_device *>(&executing->device()); + if (cpu != NULL) + m_context.printf("'%s' (%s)", cpu->tag(), core_i64_hex_format(cpu_get_pc(cpu), cpu->space(AS_PROGRAM)->logaddrchars)); + else + m_context.printf("'%s'", cpu->tag()); + } + else + m_context.cpy("(no context)"); + + return m_context; +} + + +//------------------------------------------------- +// start - initialize the emulated machine +//------------------------------------------------- + +void running_machine::start() +{ + // initialize basic can't-fail systems here + fileio_init(this); + config_init(this); + input_init(this); + output_init(this); + state_init(this); + state_save_allow_registration(this, true); + palette_init(this); + render_init(this); + ui_init(this); + generic_machine_init(this); + generic_video_init(this); + generic_sound_init(this); + + // initialize the timers and allocate a soft_reset timer + // this must be done before cpu_init so that CPU's can allocate timers + timer_init(this); + m_soft_reset_timer = timer_alloc(this, static_soft_reset, NULL); + + // init the osd layer + osd_init(this); + + // initialize the base time (needed for doing record/playback) + time(&m_base_time); + + // initialize the input system and input ports for the game + // this must be done before memory_init in order to allow specifying + // callbacks based on input port tags + time_t newbase = input_port_init(this, m_game.ipt); + if (newbase != 0) + m_base_time = newbase; + + // intialize UI input + ui_input_init(this); + + // initialize the streams engine before the sound devices start + streams_init(this); + + // first load ROMs, then populate memory, and finally initialize CPUs + // these operations must proceed in this order + rom_init(this); + memory_init(this); + watchdog_init(this); + + // allocate the gfx elements prior to device initialization + gfx_init(this); + + // initialize natural keyboard support + inputx_init(this); + + // initialize image devices + image_init(this); + + // start up the devices + m_devicelist.start_all(); + + // call the game driver's init function + // this is where decryption is done and memory maps are altered + // so this location in the init order is important + ui_set_startup_text(this, "Initializing...", true); + if (m_game.driver_init != NULL) + (*m_game.driver_init)(this); + + // finish image devices init process + image_postdevice_init(this); + + // start the video and audio hardware + video_init(this); + tilemap_init(this); + crosshair_init(this); + + sound_init(this); + + // initialize the debugger + if ((debug_flags & DEBUG_FLAG_ENABLED) != 0) + debugger_init(this); + + // call the driver's _START callbacks + if (m_config.m_machine_start != NULL) + (*m_config.m_machine_start)(this); + if (m_config.m_sound_start != NULL) + (*m_config.m_sound_start)(this); + if (m_config.m_video_start != NULL) + (*m_config.m_video_start)(this); + + // if we're coming in with a savegame request, process it now + const char *savegame = options_get_string(&m_options, OPTION_STATE); + if (savegame[0] != 0) + schedule_load(savegame); + + // if we're in autosave mode, schedule a load + else if (options_get_bool(&m_options, OPTION_AUTOSAVE) && (m_game.flags & GAME_SUPPORTS_SAVE) != 0) + schedule_load("auto"); + + // set up the cheat engine + if (options_get_bool(&m_options, OPTION_CHEAT)) + cheat_init(this); + + // disallow save state registrations starting here + state_save_allow_registration(this, false); +} + + +//------------------------------------------------- +// run - execute the machine +//------------------------------------------------- + +int running_machine::run(bool firstrun) +{ + int error = MAMERR_NONE; + + // use try/catch for deep error recovery + try + { + // move to the init phase + m_current_phase = MACHINE_PHASE_INIT; + + // if we have a logfile, set up the callback + if (options_get_bool(&m_options, OPTION_LOG)) + { + file_error filerr = mame_fopen(SEARCHPATH_DEBUGLOG, "error.log", OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &m_logfile); + assert_always(filerr == FILERR_NONE, "unable to open log file"); + add_logerror_callback(logfile_callback); + } + + // then finish setting up our local machine + start(); + + // load the configuration settings and NVRAM + bool settingsloaded = config_load_settings(this); + nvram_load(this); + sound_mute(this, FALSE); + + // display the startup screens + ui_display_startup_screens(this, firstrun, !settingsloaded); + + // perform a soft reset -- this takes us to the running phase + soft_reset(); + + // run the CPUs until a reset or exit + m_hard_reset_pending = false; + while ((!m_hard_reset_pending && !m_exit_pending) || m_saveload_schedule != SLS_NONE) + { + profiler_mark_start(PROFILER_EXTRA); + + // execute CPUs if not paused + if (!m_paused) + m_scheduler.timeslice(); + + // otherwise, just pump video updates through + else + video_frame_update(this, false); + + // handle save/load + if (m_saveload_schedule != SLS_NONE) + handle_saveload(); + + profiler_mark_end(); + } + + // and out via the exit phase + m_current_phase = MACHINE_PHASE_EXIT; + + // save the NVRAM and configuration + sound_mute(this, true); + nvram_save(this); + config_save_settings(this); + } + catch (emu_fatalerror &fatal) + { + mame_printf_error("%s\n", fatal.string()); + error = MAMERR_FATALERROR; + if (fatal.exitcode() != 0) + error = fatal.exitcode(); + } + catch (emu_exception &) + { + mame_printf_error("Caught unhandled emulator exception\n"); + error = MAMERR_FATALERROR; + } + catch (std::bad_alloc &) + { + mame_printf_error("Out of memory!\n"); + error = MAMERR_FATALERROR; + } + + // call all exit callbacks registered + call_notifiers(MACHINE_NOTIFY_EXIT); + + // close the logfile + if (m_logfile != NULL) + mame_fclose(m_logfile); + return error; +} + + +//------------------------------------------------- +// schedule_exit - schedule a clean exit +//------------------------------------------------- + +void running_machine::schedule_exit() +{ + // if we are in-game but we started with the select game menu, return to that instead + if (m_exit_to_game_select && options_get_string(&m_options, OPTION_GAMENAME)[0] != 0) + { + options_set_string(&m_options, OPTION_GAMENAME, "", OPTION_PRIORITY_CMDLINE); + ui_menu_force_game_select(this, render_container_get_ui()); + } + + // otherwise, exit for real + else + m_exit_pending = true; + + // if we're executing, abort out immediately + m_scheduler.eat_all_cycles(); + + // if we're autosaving on exit, schedule a save as well + if (options_get_bool(&m_options, OPTION_AUTOSAVE) && (m_game.flags & GAME_SUPPORTS_SAVE)) + schedule_save("auto"); +} + + +//------------------------------------------------- +// schedule_hard_reset - schedule a hard-reset of +// the machine +//------------------------------------------------- + +void running_machine::schedule_hard_reset() +{ + m_hard_reset_pending = true; + + // if we're executing, abort out immediately + m_scheduler.eat_all_cycles(); +} + + +//------------------------------------------------- +// schedule_soft_reset - schedule a soft-reset of +// the system +//------------------------------------------------- + +void running_machine::schedule_soft_reset() +{ + timer_adjust_oneshot(m_soft_reset_timer, attotime_zero, 0); + + // we can't be paused since the timer needs to fire + resume(); + + // if we're executing, abort out immediately + m_scheduler.eat_all_cycles(); +} + + +//------------------------------------------------- +// schedule_new_driver - schedule a new game to +// be loaded +//------------------------------------------------- + +void running_machine::schedule_new_driver(const game_driver &driver) +{ + m_hard_reset_pending = true; + m_new_driver_pending = &driver; + + // if we're executing, abort out immediately + m_scheduler.eat_all_cycles(); +} + + +//------------------------------------------------- +// set_saveload_filename - specifies the filename +// for state loading/saving +//------------------------------------------------- + +void running_machine::set_saveload_filename(const char *filename) +{ + // free any existing request and allocate a copy of the requested name + if (osd_is_absolute_path(filename)) + { + m_saveload_searchpath = NULL; + m_saveload_pending_file.cpy(filename); + } + else + { + m_saveload_searchpath = SEARCHPATH_STATE; + m_saveload_pending_file.cpy(basename()).cat(PATH_SEPARATOR).cat(filename).cat(".sta"); + } +} + + +//------------------------------------------------- +// schedule_save - schedule a save to occur as +// soon as possible +//------------------------------------------------- + +void running_machine::schedule_save(const char *filename) +{ + // specify the filename to save or load + set_saveload_filename(filename); + + // note the start time and set a timer for the next timeslice to actually schedule it + m_saveload_schedule = SLS_SAVE; + m_saveload_schedule_time = timer_get_time(this); + + // we can't be paused since we need to clear out anonymous timers + resume(); +} + + +//------------------------------------------------- +// schedule_load - schedule a load to occur as +// soon as possible +//------------------------------------------------- + +void running_machine::schedule_load(const char *filename) +{ + // specify the filename to save or load + set_saveload_filename(filename); + + // note the start time and set a timer for the next timeslice to actually schedule it + m_saveload_schedule = SLS_LOAD; + m_saveload_schedule_time = timer_get_time(this); + + // we can't be paused since we need to clear out anonymous timers + resume(); +} + + +//------------------------------------------------- +// pause - pause the system +//------------------------------------------------- + +void running_machine::pause() +{ + // ignore if nothing has changed + if (m_paused) + return; + m_paused = true; + + // call the callbacks + call_notifiers(MACHINE_NOTIFY_PAUSE); +} + + +//------------------------------------------------- +// resume - resume the system +//------------------------------------------------- + +void running_machine::resume() +{ + // ignore if nothing has changed + if (!m_paused) + return; + m_paused = false; + + // call the callbacks + call_notifiers(MACHINE_NOTIFY_RESUME); +} + + +//------------------------------------------------- +// region_alloc - allocates memory for a region +//------------------------------------------------- + +region_info *running_machine::region_alloc(const char *name, UINT32 length, UINT32 flags) +{ + // make sure we don't have a region of the same name; also find the end of the list + region_info *info = m_regionlist.find(name); + if (info != NULL) + fatalerror("region_alloc called with duplicate region name \"%s\"\n", name); + + // allocate the region + return m_regionlist.append(name, auto_alloc(this, region_info(*this, name, length, flags))); +} + + +//------------------------------------------------- +// region_free - releases memory for a region +//------------------------------------------------- + +void running_machine::region_free(const char *name) +{ + m_regionlist.remove(name); +} + + +//------------------------------------------------- +// add_notifier - add a notifier of the +// given type +//------------------------------------------------- + +void running_machine::add_notifier(machine_notification event, notify_callback callback) +{ + assert_always(m_current_phase == MACHINE_PHASE_INIT, "Can only call add_notifier at init time!"); + + // exit notifiers are added to the head, and executed in reverse order + if (event == MACHINE_NOTIFY_EXIT) + { + notifier_callback_item *notifier = auto_alloc(this, notifier_callback_item(callback)); + notifier->m_next = m_notifier_list[event]; + m_notifier_list[event] = notifier; + } + + // all other notifiers are added to the tail, and executed in the order registered + else + { + notifier_callback_item **tailptr; + for (tailptr = &m_notifier_list[event]; *tailptr != NULL; tailptr = &(*tailptr)->m_next) ; + *tailptr = auto_alloc(this, notifier_callback_item(callback)); + } +} + + +//------------------------------------------------- +// add_logerror_callback - adds a callback to be +// called on logerror() +//------------------------------------------------- + +void running_machine::add_logerror_callback(logerror_callback callback) +{ + assert_always(m_current_phase == MACHINE_PHASE_INIT, "Can only call add_logerror_callback at init time!"); + + logerror_callback_item **tailptr; + for (tailptr = &m_logerror_list; *tailptr != NULL; tailptr = &(*tailptr)->m_next) ; + *tailptr = auto_alloc(this, logerror_callback_item(callback)); +} + + +//------------------------------------------------- +// logerror - printf-style error logging +//------------------------------------------------- + +void CLIB_DECL running_machine::logerror(const char *format, ...) +{ + // process only if there is a target + if (m_logerror_list != NULL) + { + va_list arg; + va_start(arg, format); + vlogerror(format, arg); + va_end(arg); + } +} + + +//------------------------------------------------- +// vlogerror - vprintf-style error logging +//------------------------------------------------- + +void CLIB_DECL running_machine::vlogerror(const char *format, va_list args) +{ + // process only if there is a target + if (m_logerror_list != NULL) + { + profiler_mark_start(PROFILER_LOGERROR); + + // dump to the buffer + vsnprintf(giant_string_buffer, ARRAY_LENGTH(giant_string_buffer), format, args); + + // log to all callbacks + for (logerror_callback_item *cb = m_logerror_list; cb != NULL; cb = cb->m_next) + (*cb->m_func)(*this, giant_string_buffer); + + profiler_mark_end(); + } +} + + +//------------------------------------------------- +// base_datetime - retrieve the time of the host +// system; useful for RTC implementations +//------------------------------------------------- + +void running_machine::base_datetime(system_time &systime) +{ + systime.set(m_base_time); +} + + +//------------------------------------------------- +// current_datetime - retrieve the current time +// (offset by the base); useful for RTC +// implementations +//------------------------------------------------- + +void running_machine::current_datetime(system_time &systime) +{ + systime.set(m_base_time + timer_get_time(this).seconds); +} + + +//------------------------------------------------- +// rand - standardized random numbers +//------------------------------------------------- + +UINT32 running_machine::rand() +{ + m_rand_seed = 1664525 * m_rand_seed + 1013904223; + + // return rotated by 16 bits; the low bits have a short period + // and are frequently used + return (m_rand_seed >> 16) | (m_rand_seed << 16); +} + + +//------------------------------------------------- +// call_notifiers - call notifiers of the given +// type +//------------------------------------------------- + +void running_machine::call_notifiers(machine_notification which) +{ + for (notifier_callback_item *cb = m_notifier_list[which]; cb != NULL; cb = cb->m_next) + (*cb->m_func)(*this); +} + + +//------------------------------------------------- +// handle_saveload - attempt to perform a save +// or load +//------------------------------------------------- + +void running_machine::handle_saveload() +{ + UINT32 openflags = (m_saveload_schedule == SLS_LOAD) ? OPEN_FLAG_READ : (OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); + const char *opnamed = (m_saveload_schedule == SLS_LOAD) ? "loaded" : "saved"; + const char *opname = (m_saveload_schedule == SLS_LOAD) ? "load" : "save"; + file_error filerr = FILERR_NONE; + + // if no name, bail + if (m_saveload_pending_file.len() == 0) + goto cancel; + + // if there are anonymous timers, we can't save just yet, and we can't load yet either + // because the timers might overwrite data we have loaded + if (timer_count_anonymous(this) > 0) + { + // if more than a second has passed, we're probably screwed + if (attotime_sub(timer_get_time(this), m_saveload_schedule_time).seconds > 0) + { + popmessage("Unable to %s due to pending anonymous timers. See error.log for details.", opname); + goto cancel; + } + return; + } + + // open the file + mame_file *file; + filerr = mame_fopen(m_saveload_searchpath, m_saveload_pending_file, openflags, &file); + if (filerr == FILERR_NONE) + { + astring fullname(mame_file_full_name(file)); + + // read/write the save state + state_save_error staterr = (m_saveload_schedule == SLS_LOAD) ? state_save_read_file(this, file) : state_save_write_file(this, file); + + // handle the result + switch (staterr) + { + case STATERR_ILLEGAL_REGISTRATIONS: + popmessage("Error: Unable to %s state due to illegal registrations. See error.log for details.", opname); + break; + + case STATERR_INVALID_HEADER: + popmessage("Error: Unable to %s state due to an invalid header. Make sure the save state is correct for this game.", opname); + break; + + case STATERR_READ_ERROR: + popmessage("Error: Unable to %s state due to a read error (file is likely corrupt).", opname); + break; + + case STATERR_WRITE_ERROR: + popmessage("Error: Unable to %s state due to a write error. Verify there is enough disk space.", opname); + break; + + case STATERR_NONE: + if (!(m_game.flags & GAME_SUPPORTS_SAVE)) + popmessage("State successfully %s.\nWarning: Save states are not officially supported for this game.", opnamed); + else + popmessage("State successfully %s.", opnamed); + break; + + default: + popmessage("Error: Unknown error during state %s.", opnamed); + break; + } + + // close and perhaps delete the file + mame_fclose(file); + if (staterr != STATERR_NONE && m_saveload_schedule == SLS_SAVE) + osd_rmfile(fullname); + } + else + popmessage("Error: Failed to open file for %s operation.", opname); + + // unschedule the operation +cancel: + m_saveload_pending_file.reset(); + m_saveload_searchpath = NULL; + m_saveload_schedule = SLS_NONE; +} + + +//------------------------------------------------- +// soft_reset - actually perform a soft-reset +// of the system +//------------------------------------------------- + +TIMER_CALLBACK( running_machine::static_soft_reset ) { machine->soft_reset(); } + +void running_machine::soft_reset() +{ + logerror("Soft reset\n"); + + // temporarily in the reset phase + m_current_phase = MACHINE_PHASE_RESET; + + // call all registered reset callbacks + call_notifiers(MACHINE_NOTIFY_RESET); + + // run the driver's reset callbacks + if (m_config.m_machine_reset != NULL) + (*m_config.m_machine_reset)(this); + if (m_config.m_sound_reset != NULL) + (*m_config.m_sound_reset)(this); + if (m_config.m_video_reset != NULL) + (*m_config.m_video_reset)(this); + + // now we're running + m_current_phase = MACHINE_PHASE_RUNNING; + + // allow 0-time queued callbacks to run before any CPUs execute + timer_execute_timers(this); +} + + +//------------------------------------------------- +// logfile_callback - callback for logging to +// logfile +//------------------------------------------------- + +void running_machine::logfile_callback(running_machine &machine, const char *buffer) +{ + if (machine.m_logfile != NULL) + mame_fputs(machine.m_logfile, buffer); +} + + + +/*************************************************************************** + MEMORY REGIONS +***************************************************************************/ + +//------------------------------------------------- +// region_info - constructor +//------------------------------------------------- + +region_info::region_info(running_machine &machine, const char *name, UINT32 length, UINT32 flags) + : m_machine(machine), + m_next(NULL), + m_name(name), + m_length(length), + m_flags(flags) +{ + m_base.u8 = auto_alloc_array(&machine, UINT8, length); +} + + +//------------------------------------------------- +// ~region_info - destructor +//------------------------------------------------- + +region_info::~region_info() +{ + auto_free(&m_machine, m_base.v); +} + + + +//************************************************************************** +// CALLBACK ITEMS +//************************************************************************** + +//------------------------------------------------- +// notifier_callback_item - constructor +//------------------------------------------------- + +running_machine::notifier_callback_item::notifier_callback_item(notify_callback func) + : m_next(NULL), + m_func(func) +{ +} + + +//------------------------------------------------- +// logerror_callback_item - constructor +//------------------------------------------------- + +running_machine::logerror_callback_item::logerror_callback_item(logerror_callback func) + : m_next(NULL), + m_func(func) +{ +} + + + +//************************************************************************** +// SYSTEM TIME +//************************************************************************** + +//------------------------------------------------- +// system_time - constructor +//------------------------------------------------- + +system_time::system_time() +{ + set(0); +} + + +//------------------------------------------------- +// set - fills out a system_time structure +//------------------------------------------------- + +void system_time::set(time_t t) +{ + time = t; + local_time.set(*localtime(&t)); + utc_time.set(*gmtime(&t)); +} + + +//------------------------------------------------- +// get_tm_time - converts a tm struction to a +// MAME mame_system_tm structure +//------------------------------------------------- + +void system_time::full_time::set(struct tm &t) +{ + second = t.tm_sec; + minute = t.tm_min; + hour = t.tm_hour; + mday = t.tm_mday; + month = t.tm_mon; + year = t.tm_year + 1900; + weekday = t.tm_wday; + day = t.tm_yday; + is_dst = t.tm_isdst; +} diff --git a/src/emu/machine.h b/src/emu/machine.h new file mode 100644 index 00000000000..8d52474588d --- /dev/null +++ b/src/emu/machine.h @@ -0,0 +1,492 @@ +/*************************************************************************** + + machine.h + + Controls execution of the core MAME system. + +**************************************************************************** + + Copyright Aaron Giles + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name 'MAME' nor the names of its contributors may be + used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +***************************************************************************/ + +#pragma once + +#ifndef __EMU_H__ +#error Dont include this file directly; include emu.h instead. +#endif + +#ifndef __MACHINE_H__ +#define __MACHINE_H__ + +#include <time.h> + + + +//************************************************************************** +// CONSTANTS +//************************************************************************** + +const int MAX_GFX_ELEMENTS = 32; + + +// machine phases +enum machine_phase +{ + MACHINE_PHASE_PREINIT, + MACHINE_PHASE_INIT, + MACHINE_PHASE_RESET, + MACHINE_PHASE_RUNNING, + MACHINE_PHASE_EXIT +}; + + +// notification callback types +enum machine_notification +{ + MACHINE_NOTIFY_FRAME, + MACHINE_NOTIFY_RESET, + MACHINE_NOTIFY_PAUSE, + MACHINE_NOTIFY_RESUME, + MACHINE_NOTIFY_EXIT, + MACHINE_NOTIFY_COUNT +}; + + +// output channels +enum output_channel +{ + OUTPUT_CHANNEL_ERROR, + OUTPUT_CHANNEL_WARNING, + OUTPUT_CHANNEL_INFO, + OUTPUT_CHANNEL_DEBUG, + OUTPUT_CHANNEL_VERBOSE, + OUTPUT_CHANNEL_LOG, + OUTPUT_CHANNEL_COUNT +}; + + +// debug flags +const int DEBUG_FLAG_ENABLED = 0x00000001; // debugging is enabled +const int DEBUG_FLAG_CALL_HOOK = 0x00000002; // CPU cores must call instruction hook +const int DEBUG_FLAG_WPR_PROGRAM = 0x00000010; // watchpoints are enabled for PROGRAM memory reads +const int DEBUG_FLAG_WPR_DATA = 0x00000020; // watchpoints are enabled for DATA memory reads +const int DEBUG_FLAG_WPR_IO = 0x00000040; // watchpoints are enabled for IO memory reads +const int DEBUG_FLAG_WPW_PROGRAM = 0x00000100; // watchpoints are enabled for PROGRAM memory writes +const int DEBUG_FLAG_WPW_DATA = 0x00000200; // watchpoints are enabled for DATA memory writes +const int DEBUG_FLAG_WPW_IO = 0x00000400; // watchpoints are enabled for IO memory writes +const int DEBUG_FLAG_OSD_ENABLED = 0x00001000; // The OSD debugger is enabled + + + +//************************************************************************** +// MACROS +//************************************************************************** + +// global allocation helpers +#define auto_alloc(m, t) pool_alloc(static_cast<running_machine *>(m)->m_respool, t) +#define auto_alloc_clear(m, t) pool_alloc_clear(static_cast<running_machine *>(m)->m_respool, t) +#define auto_alloc_array(m, t, c) pool_alloc_array(static_cast<running_machine *>(m)->m_respool, t, c) +#define auto_alloc_array_clear(m, t, c) pool_alloc_array_clear(static_cast<running_machine *>(m)->m_respool, t, c) +#define auto_free(m, v) pool_free(static_cast<running_machine *>(m)->m_respool, v) + +#define auto_bitmap_alloc(m, w, h, f) auto_alloc(m, bitmap_t(w, h, f)) +#define auto_strdup(m, s) strcpy(auto_alloc_array(m, char, strlen(s) + 1), s) + + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// forward declarations +class gfx_element; +class colortable_t; +class debug_view_manager; + +typedef struct _mame_private mame_private; +typedef struct _cpuexec_private cpuexec_private; +typedef struct _timer_private timer_private; +typedef struct _state_private state_private; +typedef struct _memory_private memory_private; +typedef struct _palette_private palette_private; +typedef struct _tilemap_private tilemap_private; +typedef struct _streams_private streams_private; +typedef struct _devices_private devices_private; +typedef struct _romload_private romload_private; +typedef struct _sound_private sound_private; +typedef struct _input_private input_private; +typedef struct _input_port_private input_port_private; +typedef struct _ui_input_private ui_input_private; +typedef struct _cheat_private cheat_private; +typedef struct _debugcpu_private debugcpu_private; +typedef struct _debugvw_private debugvw_private; +typedef struct _generic_machine_private generic_machine_private; +typedef struct _generic_video_private generic_video_private; +typedef struct _generic_audio_private generic_audio_private; + + +// template specializations +typedef tagged_list<region_info> region_list; + + +// memory region +class region_info +{ + DISABLE_COPYING(region_info); + + friend class running_machine; + template<class T> friend class tagged_list; + friend resource_pool_object<region_info>::~resource_pool_object(); + + // construction/destruction + region_info(running_machine &machine, const char *name, UINT32 length, UINT32 flags); + ~region_info(); + +public: + // getters + region_info *next() const { return m_next; } + UINT8 *base() const { return (this != NULL) ? m_base.u8 : NULL; } + UINT8 *end() const { return (this != NULL) ? m_base.u8 + m_length : NULL; } + UINT32 bytes() const { return (this != NULL) ? m_length : 0; } + const char *name() const { return m_name; } + UINT32 flags() const { return m_flags; } + + // flag expansion + endianness_t endianness() const { return ((m_flags & ROMREGION_ENDIANMASK) == ROMREGION_LE) ? ENDIANNESS_LITTLE : ENDIANNESS_BIG; } + UINT8 width() const { return 1 << ((m_flags & ROMREGION_WIDTHMASK) >> 8); } + bool invert() const { return ((m_flags & ROMREGION_INVERTMASK) != 0); } + + // data access + UINT8 &u8(offs_t offset = 0) const { return m_base.u8[offset]; } + UINT16 &u16(offs_t offset = 0) const { return m_base.u16[offset]; } + UINT32 &u32(offs_t offset = 0) const { return m_base.u32[offset]; } + UINT64 &u64(offs_t offset = 0) const { return m_base.u64[offset]; } + + // allow passing a region for any common pointer + operator void *() const { return (this != NULL) ? m_base.v : NULL; } + operator INT8 *() const { return (this != NULL) ? m_base.i8 : NULL; } + operator UINT8 *() const { return (this != NULL) ? m_base.u8 : NULL; } + operator INT16 *() const { return (this != NULL) ? m_base.i16 : NULL; } + operator UINT16 *() const { return (this != NULL) ? m_base.u16 : NULL; } + operator INT32 *() const { return (this != NULL) ? m_base.i32 : NULL; } + operator UINT32 *() const { return (this != NULL) ? m_base.u32 : NULL; } + operator INT64 *() const { return (this != NULL) ? m_base.i64 : NULL; } + operator UINT64 *() const { return (this != NULL) ? m_base.u64 : NULL; } + +private: + // internal data + running_machine & m_machine; + region_info * m_next; + astring m_name; + generic_ptr m_base; + UINT32 m_length; + UINT32 m_flags; +}; + + +// this structure holds generic pointers that are commonly used +struct generic_pointers +{ + generic_ptr nvram; // generic NVRAM + UINT32 nvram_size; + generic_ptr videoram; // videoram + UINT32 videoram_size; + generic_ptr spriteram; // spriteram + UINT32 spriteram_size; + generic_ptr spriteram2; // secondary spriteram + UINT32 spriteram2_size; + generic_ptr buffered_spriteram; // buffered spriteram + generic_ptr buffered_spriteram2;// secondary buffered spriteram + generic_ptr paletteram; // palette RAM + generic_ptr paletteram2; // secondary palette RAM + bitmap_t * tmpbitmap; // temporary bitmap +}; + + +class system_time +{ +public: + system_time(); + void set(time_t t); + + struct full_time + { + void set(struct tm &t); + + UINT8 second; // seconds (0-59) + UINT8 minute; // minutes (0-59) + UINT8 hour; // hours (0-23) + UINT8 mday; // day of month (1-31) + UINT8 month; // month (0-11) + INT32 year; // year (1=1 AD) + UINT8 weekday; // day of week (0-6) + UINT16 day; // day of year (0-365) + UINT8 is_dst; // is this daylight savings? + }; + + INT64 time; // number of seconds elapsed since midnight, January 1 1970 UTC + full_time local_time; // local time + full_time utc_time; // UTC coordinated time +}; + + +// description of the currently-running machine +class running_machine +{ + DISABLE_COPYING(running_machine); + + typedef void (*notify_callback)(running_machine &machine); + typedef void (*logerror_callback)(running_machine &machine, const char *string); + +public: + // construction/destruction + running_machine(const game_driver &driver, const machine_config &config, core_options &options, bool exit_to_game_select = false); + ~running_machine(); + + // fetch items by name + inline device_t *device(const char *tag); + template<class T> inline T *device(const char *tag) { return downcast<T *>(device(tag)); } + inline const input_port_config *port(const char *tag); + inline const region_info *region(const char *tag); + + // configuration helpers + UINT32 total_colors() const { return m_config.m_total_colors; } + + // getters + const char *basename() const { return m_basename; } + core_options *options() const { return &m_options; } + machine_phase phase() const { return m_current_phase; } + bool paused() const { return m_paused || (m_current_phase != MACHINE_PHASE_RUNNING); } + bool scheduled_event_pending() const { return m_exit_pending || m_hard_reset_pending; } + bool save_or_load_pending() const { return (m_saveload_pending_file.len() != 0); } + bool exit_pending() const { return m_exit_pending; } + bool new_driver_pending() const { return (m_new_driver_pending != NULL); } + const char *new_driver_name() const { return m_new_driver_pending->name; } + device_scheduler &scheduler() { return m_scheduler; } + + // immediate operations + int run(bool firstrun); + void pause(); + void resume(); + void add_notifier(machine_notification event, notify_callback callback); + void call_notifiers(machine_notification which); + void add_logerror_callback(logerror_callback callback); + + // scheduled operations + void schedule_exit(); + void schedule_hard_reset(); + void schedule_soft_reset(); + void schedule_new_driver(const game_driver &driver); + void schedule_save(const char *filename); + void schedule_load(const char *filename); + + // time + void base_datetime(system_time &systime); + void current_datetime(system_time &systime); + + // regions + region_info *region_alloc(const char *name, UINT32 length, UINT32 flags); + void region_free(const char *name); + + // misc + void CLIB_DECL logerror(const char *format, ...); + void CLIB_DECL vlogerror(const char *format, va_list args); + UINT32 rand(); + const char *describe_context(); + + // internals + resource_pool m_respool; // pool of resources for this machine + region_list m_regionlist; // list of memory regions + device_list m_devicelist; // list of running devices + + // configuration data + const machine_config * config; // points to the constructed machine_config + const machine_config & m_config; // points to the constructed machine_config + ioport_list m_portlist; // points to a list of input port configurations + + // CPU information + device_t * firstcpu; // first CPU (allows for quick iteration via typenext) + + // game-related information + const game_driver * gamedrv; // points to the definition of the game machine + const game_driver & m_game; // points to the definition of the game machine + + // video-related information + gfx_element * gfx[MAX_GFX_ELEMENTS];// array of pointers to graphic sets (chars, sprites) + screen_device * primary_screen; // the primary screen device, or NULL if screenless + palette_t * palette; // global palette object + + // palette-related information + const pen_t * pens; // remapped palette pen numbers + colortable_t * colortable; // global colortable for remapping + pen_t * shadow_table; // table for looking up a shadowed pen + bitmap_t * priority_bitmap; // priority bitmap + + // audio-related information + int sample_rate; // the digital audio sample rate + + // debugger-related information + UINT32 debug_flags; // the current debug flags + + // UI-related + bool ui_active; // ui active or not (useful for games / systems with keyboard inputs) + + // generic pointers + generic_pointers generic; // generic pointers + + // internal core information + mame_private * mame_data; // internal data from mame.c + timer_private * timer_data; // internal data from timer.c + state_private * state_data; // internal data from state.c + memory_private * memory_data; // internal data from memory.c + palette_private * palette_data; // internal data from palette.c + tilemap_private * tilemap_data; // internal data from tilemap.c + streams_private * streams_data; // internal data from streams.c + devices_private * devices_data; // internal data from devices.c + romload_private * romload_data; // internal data from romload.c + sound_private * sound_data; // internal data from sound.c + input_private * input_data; // internal data from input.c + input_port_private * input_port_data; // internal data from inptport.c + ui_input_private * ui_input_data; // internal data from uiinput.c + cheat_private * cheat_data; // internal data from cheat.c + debugcpu_private * debugcpu_data; // internal data from debugcpu.c + generic_machine_private *generic_machine_data; // internal data from machine/generic.c + generic_video_private * generic_video_data; // internal data from video/generic.c + generic_audio_private * generic_audio_data; // internal data from audio/generic.c + + debug_view_manager * m_debug_view; // internal data from debugvw.c + + // driver-specific information + void * driver_data; // drivers can hang data off of here instead of using globals + +private: + void start(); + void set_saveload_filename(const char *filename); + void fill_systime(system_time &systime, time_t t); + void handle_saveload(); + + static TIMER_CALLBACK( static_soft_reset ); + void soft_reset(); + + static void logfile_callback(running_machine &machine, const char *buffer); + + // notifier callbacks + struct notifier_callback_item + { + notifier_callback_item(notify_callback func); + notifier_callback_item * m_next; + notify_callback m_func; + }; + notifier_callback_item *m_notifier_list[MACHINE_NOTIFY_COUNT]; + + // logerror callbacks + struct logerror_callback_item + { + logerror_callback_item(logerror_callback func); + logerror_callback_item * m_next; + logerror_callback m_func; + }; + logerror_callback_item *m_logerror_list; + + device_scheduler m_scheduler; // scheduler object + core_options & m_options; + + astring m_context; // context string + astring m_basename; // basename used for game-related paths + + machine_phase m_current_phase; + bool m_paused; + bool m_hard_reset_pending; + bool m_exit_pending; + bool m_exit_to_game_select; + const game_driver * m_new_driver_pending; + emu_timer * m_soft_reset_timer; + mame_file * m_logfile; + + // load/save + enum saveload_schedule + { + SLS_NONE, + SLS_SAVE, + SLS_LOAD + }; + saveload_schedule m_saveload_schedule; + attotime m_saveload_schedule_time; + astring m_saveload_pending_file; + const char * m_saveload_searchpath; + + // random number seed + UINT32 m_rand_seed; + + // base time + time_t m_base_time; +}; + + + +//************************************************************************** +// INLINE FUNCTIONS +//************************************************************************** + +inline device_t *running_machine::device(const char *tag) +{ + return m_devicelist.find(tag); +} + +inline const input_port_config *running_machine::port(const char *tag) +{ + return m_portlist.find(tag); +} + +inline const region_info *running_machine::region(const char *tag) +{ + return m_regionlist.find(tag); +} + +inline UINT32 mame_rand(running_machine *machine) +{ + return machine->rand(); +} + +inline UINT8 *memory_region(running_machine *machine, const char *name) +{ + const region_info *region = machine->region(name); + return (region != NULL) ? region->base() : NULL; +} + +inline UINT32 memory_region_length(running_machine *machine, const char *name) +{ + const region_info *region = machine->region(name); + return (region != NULL) ? region->bytes() : 0; +} + + +#endif /* __MACHINE_H__ */ diff --git a/src/emu/machine/74181.c b/src/emu/machine/74181.c index 18f41703922..03c2478e490 100644 --- a/src/emu/machine/74181.c +++ b/src/emu/machine/74181.c @@ -31,7 +31,7 @@ void TTL74181_config(running_machine *machine, int which, void *intf) { TTL74181_state *c; - assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call at init time!"); + assert_always(machine->phase() == MACHINE_PHASE_INIT, "Can only call at init time!"); assert_always(intf == 0, "Interface must be NULL"); assert_always((which >= 0) && (which < TTL74181_MAX_CHIPS), "Exceeded maximum number of 74181 chips"); diff --git a/src/emu/machine/ds1302.c b/src/emu/machine/ds1302.c index 3ebaab9450c..3f2314d7986 100644 --- a/src/emu/machine/ds1302.c +++ b/src/emu/machine/ds1302.c @@ -91,8 +91,8 @@ WRITE8_DEVICE_HANDLER( ds1302_clk_w ) ds1302->icount++; if(ds1302->icount == 8) //Command start { - mame_system_time systime; - mame_get_base_datetime(device->machine, &systime); + system_time systime; + device->machine->base_datetime(systime); switch(ds1302->shift_in) { diff --git a/src/emu/machine/eeprom.c b/src/emu/machine/eeprom.c index 7605a6581c4..5a0c23f3a68 100644 --- a/src/emu/machine/eeprom.c +++ b/src/emu/machine/eeprom.c @@ -251,18 +251,18 @@ void eeprom_device::nvram_default() /* populate from a memory region if present */ if (m_region != NULL) { - if (m_region->length != eeprom_bytes) + if (m_region->bytes() != eeprom_bytes) fatalerror("eeprom region '%s' wrong size (expected size = 0x%X)", tag(), eeprom_bytes); - if (m_config.m_data_bits == 8 && (m_region->flags & ROMREGION_WIDTHMASK) != ROMREGION_8BIT) + if (m_config.m_data_bits == 8 && m_region->width() != 1) fatalerror("eeprom region '%s' needs to be an 8-bit region", tag()); - if (m_config.m_data_bits == 16 && ((m_region->flags & ROMREGION_WIDTHMASK) != ROMREGION_16BIT || (m_region->flags & ROMREGION_ENDIANMASK) != ROMREGION_BE)) - fatalerror("eeprom region '%s' needs to be a 16-bit big-endian region (flags=%08x)", tag(), m_region->flags); + if (m_config.m_data_bits == 16 && (m_region->width() != 2 || m_region->endianness() != ENDIANNESS_BIG)) + fatalerror("eeprom region '%s' needs to be a 16-bit big-endian region (flags=%08x)", tag(), m_region->flags()); for (offs_t offs = 0; offs < eeprom_length; offs++) if (m_config.m_data_bits == 8) - memory_write_byte(m_addrspace[0], offs, m_region->base.u8[offs]); + memory_write_byte(m_addrspace[0], offs, m_region->u8(offs)); else - memory_write_word(m_addrspace[0], offs * 2, m_region->base.u16[offs]); + memory_write_word(m_addrspace[0], offs * 2, m_region->u16(offs)); } } diff --git a/src/emu/machine/generic.c b/src/emu/machine/generic.c index 21f131d1314..da0729fa065 100644 --- a/src/emu/machine/generic.c +++ b/src/emu/machine/generic.c @@ -21,7 +21,7 @@ static void counters_load(running_machine *machine, int config_type, xml_data_node *parentnode); static void counters_save(running_machine *machine, int config_type, xml_data_node *parentnode); -static void interrupt_reset(running_machine *machine); +static void interrupt_reset(running_machine &machine); @@ -102,7 +102,7 @@ void generic_machine_init(running_machine *machine) state->memcard_inserted = -1; /* register a reset callback and save state for interrupt enable */ - add_reset_callback(machine, interrupt_reset); + machine->add_notifier(MACHINE_NOTIFY_RESET, interrupt_reset); state_save_register_item_array(machine, "cpu", NULL, 0, state->interrupt_enable); /* register for configuration */ @@ -112,7 +112,7 @@ void generic_machine_init(running_machine *machine) if (machine->config->m_memcard_handler != NULL) { state_save_register_global(machine, state->memcard_inserted); - add_exit_callback(machine, memcard_eject); + machine->add_notifier(MACHINE_NOTIFY_EXIT, memcard_eject); } } @@ -314,7 +314,7 @@ mame_file *nvram_fopen(running_machine *machine, UINT32 openflags) file_error filerr; mame_file *file; - astring fname(machine->basename, ".nv"); + astring fname(machine->basename(), ".nv"); filerr = mame_fopen(SEARCHPATH_NVRAM, fname, openflags, &file); return (filerr == FILERR_NONE) ? file : NULL; @@ -398,12 +398,13 @@ void nvram_save(running_machine *machine) NVRAM_HANDLER( generic_0fill ) { + const region_info *region = machine->region("nvram"); if (read_or_write) mame_fwrite(file, machine->generic.nvram.v, machine->generic.nvram_size); else if (file != NULL) mame_fread(file, machine->generic.nvram.v, machine->generic.nvram_size); - else if (memory_region_length(machine, "nvram") == machine->generic.nvram_size) - memcpy(machine->generic.nvram.v, memory_region(machine, "nvram"), machine->generic.nvram_size); + else if (region != NULL && region->bytes() == machine->generic.nvram_size) + memcpy(machine->generic.nvram.v, region->base(), machine->generic.nvram_size); else memset(machine->generic.nvram.v, 0, machine->generic.nvram_size); } @@ -416,12 +417,13 @@ NVRAM_HANDLER( generic_0fill ) NVRAM_HANDLER( generic_1fill ) { + const region_info *region = machine->region("nvram"); if (read_or_write) mame_fwrite(file, machine->generic.nvram.v, machine->generic.nvram_size); else if (file != NULL) mame_fread(file, machine->generic.nvram.v, machine->generic.nvram_size); - else if (memory_region_length(machine, "nvram") == machine->generic.nvram_size) - memcpy(machine->generic.nvram.v, memory_region(machine, "nvram"), machine->generic.nvram_size); + else if (region != NULL && region->bytes() == machine->generic.nvram_size) + memcpy(machine->generic.nvram.v, region->base(), machine->generic.nvram_size); else memset(machine->generic.nvram.v, 0xff, machine->generic.nvram_size); } @@ -434,12 +436,13 @@ NVRAM_HANDLER( generic_1fill ) NVRAM_HANDLER( generic_randfill ) { + const region_info *region = machine->region("nvram"); if (read_or_write) mame_fwrite(file, machine->generic.nvram.v, machine->generic.nvram_size); else if (file != NULL) mame_fread(file, machine->generic.nvram.v, machine->generic.nvram_size); - else if (memory_region_length(machine, "nvram") == machine->generic.nvram_size) - memcpy(machine->generic.nvram.v, memory_region(machine, "nvram"), machine->generic.nvram_size); + else if (region != NULL && region->bytes() == machine->generic.nvram_size) + memcpy(machine->generic.nvram.v, region->base(), machine->generic.nvram_size); else { UINT8 *nvram = (UINT8 *)machine->generic.nvram.v; @@ -481,7 +484,7 @@ int memcard_create(running_machine *machine, int index, int overwrite) memcard_name(index, name); /* if we can't overwrite, fail if the file already exists */ - astring fname(machine->basename, PATH_SEPARATOR, name); + astring fname(machine->basename(), PATH_SEPARATOR, name); if (!overwrite) { filerr = mame_fopen(SEARCHPATH_MEMCARD, fname, OPEN_FLAG_READ, &file); @@ -521,12 +524,12 @@ int memcard_insert(running_machine *machine, int index) /* if a card is already inserted, eject it first */ if (state->memcard_inserted != -1) - memcard_eject(machine); + memcard_eject(*machine); assert(state->memcard_inserted == -1); /* create a name */ memcard_name(index, name); - astring fname(machine->basename, PATH_SEPARATOR, name); + astring fname(machine->basename(), PATH_SEPARATOR, name); /* open the file; if we can't, it's an error */ filerr = mame_fopen(SEARCHPATH_MEMCARD, fname, OPEN_FLAG_READ, &file); @@ -549,9 +552,9 @@ int memcard_insert(running_machine *machine, int index) its contents along the way -------------------------------------------------*/ -void memcard_eject(running_machine *machine) +void memcard_eject(running_machine &machine) { - generic_machine_private *state = machine->generic_machine_data; + generic_machine_private *state = machine.generic_machine_data; file_error filerr; mame_file *file; char name[16]; @@ -562,7 +565,7 @@ void memcard_eject(running_machine *machine) /* create a name */ memcard_name(state->memcard_inserted, name); - astring fname(machine->basename, PATH_SEPARATOR, name); + astring fname(machine.basename(), PATH_SEPARATOR, name); /* open the file; if we can't, it's an error */ filerr = mame_fopen(SEARCHPATH_MEMCARD, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file); @@ -573,8 +576,8 @@ void memcard_eject(running_machine *machine) } /* initialize and then load the card */ - if (machine->config->m_memcard_handler) - (*machine->config->m_memcard_handler)(machine, file, MEMCARD_EJECT); + if (machine.m_config.m_memcard_handler) + (*machine.m_config.m_memcard_handler)(&machine, file, MEMCARD_EJECT); /* close the file */ mame_fclose(file); @@ -619,9 +622,9 @@ void set_led_status(running_machine *machine, int num, int on) states on a reset -------------------------------------------------*/ -static void interrupt_reset(running_machine *machine) +static void interrupt_reset(running_machine &machine) { - generic_machine_private *state = machine->generic_machine_data; + generic_machine_private *state = machine.generic_machine_data; int cpunum; /* on a reset, enable all interrupts */ diff --git a/src/emu/machine/generic.h b/src/emu/machine/generic.h index de1214c9983..cbb27219ef9 100644 --- a/src/emu/machine/generic.h +++ b/src/emu/machine/generic.h @@ -102,7 +102,7 @@ int memcard_create(running_machine *machine, int index, int overwrite); int memcard_insert(running_machine *machine, int index); /* "eject" a memory card and save its data */ -void memcard_eject(running_machine *machine); +void memcard_eject(running_machine &machine); /* returns the index of the current memory card, or -1 if none */ int memcard_present(running_machine *machine); diff --git a/src/emu/machine/mb3773.c b/src/emu/machine/mb3773.c index 74a402ee4c1..287679430a2 100644 --- a/src/emu/machine/mb3773.c +++ b/src/emu/machine/mb3773.c @@ -48,7 +48,7 @@ INLINE mb3773_state *get_safe_token(running_device *device) static TIMER_CALLBACK( watchdog_timeout ) { - mame_schedule_soft_reset(machine); + machine->schedule_soft_reset(); } /*------------------------------------------------- diff --git a/src/emu/machine/mc146818.c b/src/emu/machine/mc146818.c index c2e9761027e..880af65a408 100644 --- a/src/emu/machine/mc146818.c +++ b/src/emu/machine/mc146818.c @@ -238,9 +238,9 @@ static int dec_2_local(int a) static void mc146818_set_base_datetime(running_machine *machine) { - mame_system_time systime; + system_time systime; - mame_get_base_datetime(machine, &systime); + machine->base_datetime(systime); if (HOURS_24 || (systime.local_time.hour < 12)) mc146818->data[4] = dec_2_local(systime.local_time.hour); diff --git a/src/emu/machine/msm6242.c b/src/emu/machine/msm6242.c index 2f84a309729..754a38f5566 100644 --- a/src/emu/machine/msm6242.c +++ b/src/emu/machine/msm6242.c @@ -33,7 +33,7 @@ typedef struct _msm6242_t msm6242_t; struct _msm6242_t { UINT8 reg[3]; - mame_system_time hold_time; + system_time hold_time; }; @@ -49,7 +49,7 @@ INLINE msm6242_t *get_safe_token(running_device *device) READ8_DEVICE_HANDLER( msm6242_r ) { - mame_system_time curtime, *systime = &curtime; + system_time curtime, *systime = &curtime; msm6242_t *msm6242 = get_safe_token(device); if (msm6242->reg[0] & 1) /* if HOLD is set, use the hold time */ @@ -58,7 +58,7 @@ READ8_DEVICE_HANDLER( msm6242_r ) } else /* otherwise, use the current time */ { - mame_get_current_datetime(device->machine, &curtime); + device->machine->current_datetime(curtime); } switch(offset) @@ -120,7 +120,7 @@ WRITE8_DEVICE_HANDLER( msm6242_w ) if (data & 1) /* was Hold set? */ { - mame_get_current_datetime(device->machine, &msm6242->hold_time); + device->machine->current_datetime(msm6242->hold_time); } return; @@ -157,7 +157,7 @@ static DEVICE_START( msm6242 ) msm6242->reg[0] = 0; msm6242->reg[1] = 0; msm6242->reg[2] = 0; - memset(&msm6242->hold_time, 0, sizeof(mame_system_time)); + memset(&msm6242->hold_time, 0, sizeof(system_time)); } diff --git a/src/emu/machine/pd4990a.c b/src/emu/machine/pd4990a.c index 47996a3c0a7..38cdeb381b2 100644 --- a/src/emu/machine/pd4990a.c +++ b/src/emu/machine/pd4990a.c @@ -448,8 +448,8 @@ static DEVICE_START( upd4990a ) { upd4990a_state *upd4990a = get_safe_token(device); - mame_system_time curtime, *systime = &curtime; - mame_get_current_datetime(device->machine, &curtime); + system_time curtime, *systime = &curtime; + device->machine->current_datetime(curtime); #if 0 upd4990a->seconds = 0x00; diff --git a/src/emu/machine/rtc65271.c b/src/emu/machine/rtc65271.c index ea43f512df9..78e21f45823 100644 --- a/src/emu/machine/rtc65271.c +++ b/src/emu/machine/rtc65271.c @@ -233,10 +233,10 @@ static int rtc65271_file_load(running_device *device, mame_file *file) /*state->dirty = FALSE;*/ { - mame_system_time systime; + system_time systime; /* get the current date/time from the core */ - mame_get_current_datetime(device->machine, &systime); + device->machine->current_datetime(systime); /* set clock registers */ state->regs[reg_second] = systime.local_time.second; diff --git a/src/emu/machine/timekpr.c b/src/emu/machine/timekpr.c index 4dfafc7370d..3abb9c5dfd0 100644 --- a/src/emu/machine/timekpr.c +++ b/src/emu/machine/timekpr.c @@ -286,7 +286,7 @@ static DEVICE_START(timekeeper) timekeeper_state *c = get_safe_token(device); emu_timer *timer; attotime duration; - mame_system_time systime; + system_time systime; /* validate some basic stuff */ assert(device != NULL); @@ -295,7 +295,7 @@ static DEVICE_START(timekeeper) assert(device->machine != NULL); assert(device->machine->config != NULL); - mame_get_base_datetime(device->machine, &systime); + device->machine->base_datetime(systime); c->device = device; c->control = 0; diff --git a/src/emu/mame.c b/src/emu/mame.c index 0d61d1c6886..d20b1f83720 100644 --- a/src/emu/mame.c +++ b/src/emu/mame.c @@ -50,7 +50,6 @@ - calls sound_init() [sound.c] to start the audio system - calls debugger_init() [debugger.c] to set up the debugger - calls the driver's MACHINE_START, SOUND_START, and VIDEO_START callbacks - - calls saveload_init() [mame.c] to set up for save/load - calls cheat_init() [cheat.c] to initialize the cheat system - calls image_init() [image.c] to initialize the image system @@ -95,70 +94,16 @@ /*************************************************************************** - TYPE DEFINITIONS -***************************************************************************/ - -typedef struct _callback_item callback_item; -struct _callback_item -{ - callback_item * next; - union - { - void (*exit)(running_machine *); - void (*reset)(running_machine *); - void (*frame)(running_machine *); - void (*pause)(running_machine *, int); - void (*log)(running_machine *, const char *); - } func; -}; - - -/* typedef struct _mame_private mame_private; */ -struct _mame_private -{ - /* system state */ - int current_phase; - UINT8 paused; - UINT8 hard_reset_pending; - UINT8 exit_pending; - const game_driver *new_driver_pending; - astring saveload_pending_file; - const char * saveload_searchpath; - emu_timer * soft_reset_timer; - mame_file * logfile; - - /* callbacks */ - callback_item * frame_callback_list; - callback_item * reset_callback_list; - callback_item * pause_callback_list; - callback_item * exit_callback_list; - callback_item * logerror_callback_list; - - /* load/save */ - void (*saveload_schedule_callback)(running_machine *); - attotime saveload_schedule_time; - - /* random number seed */ - UINT32 rand_seed; - - /* base time */ - time_t base_time; -}; - - - -/*************************************************************************** GLOBAL VARIABLES ***************************************************************************/ -/* the active machine */ -static running_machine *global_machine; - /* the current options */ static core_options *mame_opts; /* started empty? */ -static UINT8 started_empty; +static bool started_empty; + +static running_machine *global_machine; /* output channels */ static output_callback_func output_cb[OUTPUT_CHANNEL_COUNT]; @@ -175,9 +120,6 @@ const char mame_disclaimer[] = "images is a violation of copyright law and should be promptly reported to the\n" "authors so that appropriate legal action can be taken.\n"; -/* a giant string buffer for temporary strings */ -static char giant_string_buffer[65536] = { 0 }; - /*************************************************************************** @@ -186,14 +128,6 @@ static char giant_string_buffer[65536] = { 0 }; static int parse_ini_file(core_options *options, const char *name, int priority); -static TIMER_CALLBACK( soft_reset ); - -static void saveload_init(running_machine *machine); -static void handle_save(running_machine *machine); -static void handle_load(running_machine *machine); - -static void logfile_callback(running_machine *machine, const char *buffer); - /*************************************************************************** @@ -201,170 +135,91 @@ static void logfile_callback(running_machine *machine, const char *buffer); ***************************************************************************/ /*------------------------------------------------- + mame_is_valid_machine - return true if the + given machine is valid +-------------------------------------------------*/ + +int mame_is_valid_machine(running_machine *machine) +{ + return (machine != NULL && machine == global_machine); +} + + +/*------------------------------------------------- mame_execute - run the core emulation -------------------------------------------------*/ int mame_execute(core_options *options) { - int exit_pending = FALSE; - int error = MAMERR_NONE; - int firstgame = TRUE; - int firstrun = TRUE; + bool firstgame = true; + bool firstrun = true; - /* loop across multiple hard resets */ + // loop across multiple hard resets + bool exit_pending = false; + int error = MAMERR_NONE; while (error == MAMERR_NONE && !exit_pending) { - const game_driver *driver; - running_machine *machine; - mame_private *mame; - callback_item *cb; - astring gamename; - - /* specify the mame_options */ + // specify the global mame_options mame_opts = options; - /* convert the specified gamename to a driver */ - core_filename_extract_base(&gamename, options_get_string(mame_options(), OPTION_GAMENAME), TRUE); - driver = driver_get_name(gamename); + // convert the specified gamename to a driver + astring gamename; + core_filename_extract_base(&gamename, options_get_string(options, OPTION_GAMENAME), true); + const game_driver *driver = driver_get_name(gamename); - /* if no driver, use the internal empty driver */ + // if no driver, use the internal empty driver if (driver == NULL) { driver = &GAME_NAME(empty); if (firstgame) - started_empty = TRUE; + started_empty = true; } - /* otherwise, perform validity checks before anything else */ + // otherwise, perform validity checks before anything else else if (mame_validitychecks(driver) != 0) return MAMERR_FAILED_VALIDITY; - firstgame = FALSE; + firstgame = false; - /* parse any INI files as the first thing */ + // parse any INI files as the first thing if (options_get_bool(options, OPTION_READCONFIG)) { - options_revert(mame_options(), OPTION_PRIORITY_INI); - mame_parse_ini_files(mame_options(), driver); + options_revert(options, OPTION_PRIORITY_INI); + mame_parse_ini_files(options, driver); } // create the machine configuration const machine_config *config = global_alloc(machine_config(driver->machine_config)); - /* create the machine structure and driver */ - machine = global_alloc(running_machine(*driver, *config)); - mame = machine->mame_data; + // create the machine structure and driver + running_machine *machine = global_alloc(running_machine(*driver, *config, *options, started_empty)); - /* start in the "pre-init phase" */ - mame->current_phase = MAME_PHASE_PREINIT; - - /* looooong term: remove this */ + // looooong term: remove this global_machine = machine; - - /* use try/catch for deep error recovery */ - try - { - int settingsloaded; - - /* move to the init phase */ - mame->current_phase = MAME_PHASE_INIT; - - /* if we have a logfile, set up the callback */ - mame->logerror_callback_list = NULL; - if (options_get_bool(mame_options(), OPTION_LOG)) - { - file_error filerr = mame_fopen(SEARCHPATH_DEBUGLOG, "error.log", OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &mame->logfile); - assert_always(filerr == FILERR_NONE, "unable to open log file"); - add_logerror_callback(machine, logfile_callback); - } - - /* then finish setting up our local machine */ - machine->start(); - - /* load the configuration settings and NVRAM */ - settingsloaded = config_load_settings(machine); - nvram_load(machine); - sound_mute(machine, FALSE); - - /* display the startup screens */ - ui_display_startup_screens(machine, firstrun, !settingsloaded); - firstrun = FALSE; - - /* perform a soft reset -- this takes us to the running phase */ - soft_reset(machine, NULL, 0); - - /* run the CPUs until a reset or exit */ - mame->hard_reset_pending = FALSE; - while ((!mame->hard_reset_pending && !mame->exit_pending) || mame->saveload_pending_file.len() != 0) - { - profiler_mark_start(PROFILER_EXTRA); - - /* execute CPUs if not paused */ - if (!mame->paused) - machine->scheduler.timeslice(); - - /* otherwise, just pump video updates through */ - else - video_frame_update(machine, FALSE); - - /* handle save/load */ - if (mame->saveload_schedule_callback != NULL) - (*mame->saveload_schedule_callback)(machine); - - profiler_mark_end(); - } - - /* and out via the exit phase */ - mame->current_phase = MAME_PHASE_EXIT; - - /* save the NVRAM and configuration */ - sound_mute(machine, TRUE); - nvram_save(machine); - config_save_settings(machine); - } - catch (emu_fatalerror &fatal) - { - mame_printf_error("%s\n", fatal.string()); - error = MAMERR_FATALERROR; - if (fatal.exitcode() != 0) - error = fatal.exitcode(); - } - catch (emu_exception &) - { - mame_printf_error("Caught unhandled emulator exception\n"); - error = MAMERR_FATALERROR; - } - catch (std::bad_alloc &) - { - mame_printf_error("Out of memory!\n"); - error = MAMERR_FATALERROR; - } - - /* call all exit callbacks registered */ - for (cb = mame->exit_callback_list; cb; cb = cb->next) - (*cb->func.exit)(machine); - - /* close the logfile */ - if (mame->logfile != NULL) - mame_fclose(mame->logfile); - - /* grab data from the MAME structure before it goes away */ - if (mame->new_driver_pending != NULL) + + // run the machine + error = machine->run(firstrun); + firstrun = false; + + // check the state of the machine + if (machine->new_driver_pending()) { - options_set_string(mame_options(), OPTION_GAMENAME, mame->new_driver_pending->name, OPTION_PRIORITY_CMDLINE); - firstrun = TRUE; + options_set_string(options, OPTION_GAMENAME, machine->new_driver_name(), OPTION_PRIORITY_CMDLINE); + firstrun = true; } - exit_pending = mame->exit_pending; + if (machine->exit_pending()) + exit_pending = true; - /* destroy the machine and the config */ + // destroy the machine and the config global_free(machine); global_free(config); + global_machine = NULL; - /* reset the options */ + // reset the options mame_opts = NULL; } - /* return an error */ + // return an error return error; } @@ -382,451 +237,6 @@ core_options *mame_options(void) -/*------------------------------------------------- - mame_get_phase - return the current program - phase --------------------------------------------------*/ - -int mame_get_phase(running_machine *machine) -{ - mame_private *mame = machine->mame_data; - return mame->current_phase; -} - - -/*------------------------------------------------- - add_frame_callback - request a callback on - frame update --------------------------------------------------*/ - -void add_frame_callback(running_machine *machine, void (*callback)(running_machine *)) -{ - mame_private *mame = machine->mame_data; - callback_item *cb, **cur; - - assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_frame_callback at init time!"); - - /* allocate memory */ - cb = auto_alloc(machine, callback_item); - - /* add us to the end of the list */ - cb->func.frame = callback; - cb->next = NULL; - for (cur = &mame->frame_callback_list; *cur; cur = &(*cur)->next) ; - *cur = cb; -} - - -/*------------------------------------------------- - add_reset_callback - request a callback on - reset --------------------------------------------------*/ - -void add_reset_callback(running_machine *machine, void (*callback)(running_machine *)) -{ - mame_private *mame = machine->mame_data; - callback_item *cb, **cur; - - assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_reset_callback at init time!"); - - /* allocate memory */ - cb = auto_alloc(machine, callback_item); - - /* add us to the end of the list */ - cb->func.reset = callback; - cb->next = NULL; - for (cur = &mame->reset_callback_list; *cur; cur = &(*cur)->next) ; - *cur = cb; -} - - -/*------------------------------------------------- - add_pause_callback - request a callback on - pause --------------------------------------------------*/ - -void add_pause_callback(running_machine *machine, void (*callback)(running_machine *, int)) -{ - mame_private *mame = machine->mame_data; - callback_item *cb, **cur; - - assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_pause_callback at init time!"); - - /* allocate memory */ - cb = auto_alloc(machine, callback_item); - - /* add us to the end of the list */ - cb->func.pause = callback; - cb->next = NULL; - for (cur = &mame->pause_callback_list; *cur; cur = &(*cur)->next) ; - *cur = cb; -} - - -/*------------------------------------------------- - add_exit_callback - request a callback on - termination --------------------------------------------------*/ - -void add_exit_callback(running_machine *machine, void (*callback)(running_machine *)) -{ - mame_private *mame = machine->mame_data; - callback_item *cb; - - assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_exit_callback at init time!"); - - /* allocate memory */ - cb = auto_alloc(machine, callback_item); - - /* add us to the head of the list */ - cb->func.exit = callback; - cb->next = mame->exit_callback_list; - mame->exit_callback_list = cb; -} - - -/*------------------------------------------------- - mame_frame_update - handle update tasks for a - frame boundary --------------------------------------------------*/ - -void mame_frame_update(running_machine *machine) -{ - callback_item *cb; - - /* call all registered frame callbacks */ - for (cb = machine->mame_data->frame_callback_list; cb; cb = cb->next) - (*cb->func.frame)(machine); -} - - -/*------------------------------------------------- - mame_is_valid_machine - return true if the - given machine is valid --------------------------------------------------*/ - -int mame_is_valid_machine(running_machine *machine) -{ - return (machine != NULL && machine == global_machine); -} - - - -/*************************************************************************** - GLOBAL SYSTEM STATES -***************************************************************************/ - -/*------------------------------------------------- - mame_schedule_exit - schedule a clean exit --------------------------------------------------*/ - -void mame_schedule_exit(running_machine *machine) -{ - mame_private *mame = machine->mame_data; - - /* if we are in-game but we started with the select game menu, return to that instead */ - if (started_empty && options_get_string(mame_options(), OPTION_GAMENAME)[0] != 0) - { - options_set_string(mame_options(), OPTION_GAMENAME, "", OPTION_PRIORITY_CMDLINE); - ui_menu_force_game_select(machine, render_container_get_ui()); - } - - /* otherwise, exit for real */ - else - mame->exit_pending = TRUE; - - /* if we're executing, abort out immediately */ - machine->scheduler.eat_all_cycles(); - - /* if we're autosaving on exit, schedule a save as well */ - if (options_get_bool(mame_options(), OPTION_AUTOSAVE) && (machine->gamedrv->flags & GAME_SUPPORTS_SAVE)) - mame_schedule_save(machine, "auto"); -} - - -/*------------------------------------------------- - mame_schedule_hard_reset - schedule a hard- - reset of the system --------------------------------------------------*/ - -void mame_schedule_hard_reset(running_machine *machine) -{ - mame_private *mame = machine->mame_data; - mame->hard_reset_pending = TRUE; - - /* if we're executing, abort out immediately */ - machine->scheduler.eat_all_cycles(); -} - - -/*------------------------------------------------- - mame_schedule_soft_reset - schedule a soft- - reset of the system --------------------------------------------------*/ - -void mame_schedule_soft_reset(running_machine *machine) -{ - mame_private *mame = machine->mame_data; - - timer_adjust_oneshot(mame->soft_reset_timer, attotime_zero, 0); - - /* we can't be paused since the timer needs to fire */ - mame_pause(machine, FALSE); - - /* if we're executing, abort out immediately */ - machine->scheduler.eat_all_cycles(); -} - - -/*------------------------------------------------- - mame_schedule_new_driver - schedule a new game - to be loaded --------------------------------------------------*/ - -void mame_schedule_new_driver(running_machine *machine, const game_driver *driver) -{ - mame_private *mame = machine->mame_data; - mame->hard_reset_pending = TRUE; - mame->new_driver_pending = driver; - - /* if we're executing, abort out immediately */ - machine->scheduler.eat_all_cycles(); -} - - -/*------------------------------------------------- - set_saveload_filename - specifies the filename - for state loading/saving --------------------------------------------------*/ - -static void set_saveload_filename(running_machine *machine, const char *filename) -{ - mame_private *mame = machine->mame_data; - - /* free any existing request and allocate a copy of the requested name */ - if (osd_is_absolute_path(filename)) - { - mame->saveload_searchpath = NULL; - mame->saveload_pending_file.cpy(filename); - } - else - { - mame->saveload_searchpath = SEARCHPATH_STATE; - mame->saveload_pending_file.cpy(machine->basename).cat(PATH_SEPARATOR).cat(filename).cat(".sta"); - } -} - - -/*------------------------------------------------- - mame_schedule_save - schedule a save to - occur as soon as possible --------------------------------------------------*/ - -void mame_schedule_save(running_machine *machine, const char *filename) -{ - mame_private *mame = machine->mame_data; - - /* specify the filename to save or load */ - set_saveload_filename(machine, filename); - - /* note the start time and set a timer for the next timeslice to actually schedule it */ - mame->saveload_schedule_callback = handle_save; - mame->saveload_schedule_time = timer_get_time(machine); - - /* we can't be paused since we need to clear out anonymous timers */ - mame_pause(machine, FALSE); -} - - -/*------------------------------------------------- - mame_schedule_load - schedule a load to - occur as soon as possible --------------------------------------------------*/ - -void mame_schedule_load(running_machine *machine, const char *filename) -{ - mame_private *mame = machine->mame_data; - - /* specify the filename to save or load */ - set_saveload_filename(machine, filename); - - /* note the start time and set a timer for the next timeslice to actually schedule it */ - mame->saveload_schedule_callback = handle_load; - mame->saveload_schedule_time = timer_get_time(machine); - - /* we can't be paused since we need to clear out anonymous timers */ - mame_pause(machine, FALSE); -} - - -/*------------------------------------------------- - mame_is_save_or_load_pending - is a save or - load pending? --------------------------------------------------*/ - -int mame_is_save_or_load_pending(running_machine *machine) -{ - /* we can't check for saveload_pending_file here because it will bypass */ - /* required UI screens if a state is queued from the command line */ - mame_private *mame = machine->mame_data; - return (mame->saveload_pending_file.len() != 0); -} - - -/*------------------------------------------------- - mame_is_scheduled_event_pending - is a - scheduled event pending? --------------------------------------------------*/ - -int mame_is_scheduled_event_pending(running_machine *machine) -{ - /* we can't check for saveload_pending_file here because it will bypass */ - /* required UI screens if a state is queued from the command line */ - mame_private *mame = machine->mame_data; - return mame->exit_pending || mame->hard_reset_pending; -} - - -/*------------------------------------------------- - mame_pause - pause or resume the system --------------------------------------------------*/ - -void mame_pause(running_machine *machine, int pause) -{ - mame_private *mame = machine->mame_data; - callback_item *cb; - - /* ignore if nothing has changed */ - if (mame->paused == pause) - return; - mame->paused = pause; - - /* call all registered pause callbacks */ - for (cb = mame->pause_callback_list; cb; cb = cb->next) - (*cb->func.pause)(machine, mame->paused); -} - - -/*------------------------------------------------- - mame_is_paused - the system paused? --------------------------------------------------*/ - -int mame_is_paused(running_machine *machine) -{ - mame_private *mame = machine->mame_data; - return (mame->current_phase != MAME_PHASE_RUNNING) || mame->paused; -} - - - -/*************************************************************************** - MEMORY REGIONS -***************************************************************************/ - -/*------------------------------------------------- - region_info - constructor for a memory region --------------------------------------------------*/ - -region_info::region_info(running_machine *_machine, const char *_name, UINT32 _length, UINT32 _flags) - : machine(_machine), - m_next(NULL), - name(_name), - length(_length), - flags(_flags) -{ - base.u8 = auto_alloc_array(_machine, UINT8, _length); -} - - -/*------------------------------------------------- - ~region_info - memory region destructor --------------------------------------------------*/ - -region_info::~region_info() -{ - auto_free(machine, base.v); -} - - -/*------------------------------------------------- - memory_region_alloc - allocates memory for a - region --------------------------------------------------*/ - -region_info *memory_region_alloc(running_machine *machine, const char *name, UINT32 length, UINT32 flags) -{ - /* make sure we don't have a region of the same name; also find the end of the list */ - region_info *info = machine->regionlist.find(name); - if (info != NULL) - fatalerror("memory_region_alloc called with duplicate region name \"%s\"\n", name); - - /* allocate the region */ - return machine->regionlist.append(name, global_alloc(region_info(machine, name, length, flags))); -} - - -/*------------------------------------------------- - memory_region_free - releases memory for a - region --------------------------------------------------*/ - -void memory_region_free(running_machine *machine, const char *name) -{ - machine->regionlist.remove(name); -} - - -/*------------------------------------------------- - memory_region - returns pointer to a memory - region --------------------------------------------------*/ - -UINT8 *memory_region(running_machine *machine, const char *name) -{ - const region_info *region = machine->region(name); - return (region != NULL) ? region->base.u8 : NULL; -} - - -/*------------------------------------------------- - memory_region_length - returns length of a - memory region --------------------------------------------------*/ - -UINT32 memory_region_length(running_machine *machine, const char *name) -{ - const region_info *region = machine->region(name); - return (region != NULL) ? region->length : 0; -} - - -/*------------------------------------------------- - memory_region_flags - returns flags for a - memory region --------------------------------------------------*/ - -UINT32 memory_region_flags(running_machine *machine, const char *name) -{ - const region_info *region = machine->region(name); - return (region != NULL) ? region->flags : 0; -} - - -/*------------------------------------------------- - memory_region_next - the name of the next - memory region (or the first if name == NULL) --------------------------------------------------*/ - -const char *memory_region_next(running_machine *machine, const char *name) -{ - if (name == NULL) - return (machine->regionlist.first() != NULL) ? machine->regionlist.first()->name.cstr() : NULL; - const region_info *region = machine->region(name); - return (region != NULL && region->next() != NULL) ? region->next()->name.cstr() : NULL; -} - - - /*************************************************************************** OUTPUT MANAGEMENT ***************************************************************************/ @@ -1023,7 +433,6 @@ void mame_printf_log(const char *format, ...) #endif - /*************************************************************************** MISCELLANEOUS ***************************************************************************/ @@ -1034,22 +443,23 @@ void mame_printf_log(const char *format, ...) void CLIB_DECL popmessage(const char *format, ...) { - /* if the format is NULL, it is a signal to clear the popmessage */ + // if the format is NULL, it is a signal to clear the popmessage if (format == NULL) ui_popup_time(0, " "); - /* otherwise, generate the buffer and call the UI to display the message */ + // otherwise, generate the buffer and call the UI to display the message else { + astring temp; va_list arg; - /* dump to the buffer */ + // dump to the buffer va_start(arg, format); - vsnprintf(giant_string_buffer, ARRAY_LENGTH(giant_string_buffer), format, arg); + temp.vprintf(format, arg); va_end(arg); - /* pop it in the UI */ - ui_popup_time((int)strlen(giant_string_buffer) / 40 + 2, "%s", giant_string_buffer); + // pop it in the UI + ui_popup_time(temp.len() / 40 + 2, "%s", temp.cstr()); } } @@ -1061,85 +471,16 @@ void CLIB_DECL popmessage(const char *format, ...) void CLIB_DECL logerror(const char *format, ...) { - running_machine *machine = global_machine; - - /* currently, we need a machine to do this */ - if (machine != NULL) + if (global_machine != NULL) { - mame_private *mame = machine->mame_data; - callback_item *cb; - - /* process only if there is a target */ - if (mame->logerror_callback_list != NULL) - { - va_list arg; - - profiler_mark_start(PROFILER_LOGERROR); - - /* dump to the buffer */ - va_start(arg, format); - vsnprintf(giant_string_buffer, ARRAY_LENGTH(giant_string_buffer), format, arg); - va_end(arg); - - /* log to all callbacks */ - for (cb = mame->logerror_callback_list; cb; cb = cb->next) - (*cb->func.log)(machine, giant_string_buffer); - - profiler_mark_end(); - } + va_list arg; + va_start(arg, format); + global_machine->vlogerror(format, arg); + va_end(arg); } } -/*------------------------------------------------- - add_logerror_callback - adds a callback to be - called on logerror() --------------------------------------------------*/ - -void add_logerror_callback(running_machine *machine, void (*callback)(running_machine *, const char *)) -{ - mame_private *mame = machine->mame_data; - callback_item *cb, **cur; - - assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call add_logerror_callback at init time!"); - - cb = auto_alloc(machine, callback_item); - cb->func.log = callback; - cb->next = NULL; - - for (cur = &mame->logerror_callback_list; *cur; cur = &(*cur)->next) ; - *cur = cb; -} - - -/*------------------------------------------------- - logfile_callback - callback for logging to - logfile --------------------------------------------------*/ - -static void logfile_callback(running_machine *machine, const char *buffer) -{ - mame_private *mame = machine->mame_data; - if (mame->logfile != NULL) - mame_fputs(mame->logfile, buffer); -} - - -/*------------------------------------------------- - mame_rand - standardized random numbers --------------------------------------------------*/ - -UINT32 mame_rand(running_machine *machine) -{ - mame_private *mame = machine->mame_data; - mame->rand_seed = 1664525 * mame->rand_seed + 1013904223; - - /* return rotated by 16 bits; the low bits have a short period - and are frequently used */ - return (mame->rand_seed >> 16) | (mame->rand_seed << 16); -} - - /*************************************************************************** INTERNAL INITIALIZATION LOGIC @@ -1230,506 +571,3 @@ static int parse_ini_file(core_options *options, const char *name, int priority) mame_fclose(file); return TRUE; } - - -/*------------------------------------------------- - running_machine - create the running machine - object and initialize it based on options --------------------------------------------------*/ - -running_machine::running_machine(const game_driver &driver, const machine_config &_config) - : m_devicelist(respool), - scheduler(*this), - config(&_config), - m_config(_config), - firstcpu(NULL), - gamedrv(&driver), - m_game(driver), - basename(NULL), - primary_screen(NULL), - palette(NULL), - pens(NULL), - colortable(NULL), - shadow_table(NULL), - priority_bitmap(NULL), - sample_rate(0), - debug_flags(0), - ui_active(false), - mame_data(NULL), - timer_data(NULL), - state_data(NULL), - memory_data(NULL), - palette_data(NULL), - tilemap_data(NULL), - streams_data(NULL), - devices_data(NULL), - romload_data(NULL), - sound_data(NULL), - input_data(NULL), - input_port_data(NULL), - ui_input_data(NULL), - cheat_data(NULL), - debugcpu_data(NULL), - generic_machine_data(NULL), - generic_video_data(NULL), - generic_audio_data(NULL), - m_debug_view(NULL), - driver_data(NULL) -{ - try - { - memset(gfx, 0, sizeof(gfx)); - memset(&generic, 0, sizeof(generic)); - - /* allocate memory for the internal mame_data */ - mame_data = auto_alloc_clear(this, mame_private); - - /* initialize the driver-related variables in the machine */ - basename = mame_strdup(driver.name); - - /* attach this machine to all the devices in the configuration */ - m_devicelist.import_config_list(m_config.m_devicelist, *this); - - /* allocate the driver data (after devices) */ - if (m_config.m_driver_data_alloc != NULL) - driver_data = (*m_config.m_driver_data_alloc)(*this); - - /* find devices */ - firstcpu = cpu_first(this); - primary_screen = screen_first(*this); - - /* fetch core options */ - sample_rate = options_get_int(mame_options(), OPTION_SAMPLERATE); - if (options_get_bool(mame_options(), OPTION_DEBUG)) - debug_flags = (DEBUG_FLAG_ENABLED | DEBUG_FLAG_CALL_HOOK) | (options_get_bool(mame_options(), OPTION_DEBUG_INTERNAL) ? 0 : DEBUG_FLAG_OSD_ENABLED); - else - debug_flags = 0; - } - catch (std::bad_alloc &) - { - if (driver_data != NULL) - auto_free(this, driver_data); - if (basename != NULL) - osd_free(basename); - if (mame_data != NULL) - auto_free(this, mame_data); - } -} - - -/*------------------------------------------------- - ~running_machine - free the machine data --------------------------------------------------*/ - -running_machine::~running_machine() -{ - assert(this == global_machine); - - if (basename != NULL) - osd_free(basename); - - global_machine = NULL; -} - - -//------------------------------------------------- -// describe_context - return a string describing -// which device is currently executing and its -// PC -//------------------------------------------------- - -const char *running_machine::describe_context() -{ - device_execute_interface *executing = scheduler.currently_executing(); - if (executing != NULL) - { - cpu_device *cpu = downcast<cpu_device *>(&executing->device()); - if (cpu != NULL) - m_context.printf("'%s' (%s)", cpu->tag(), core_i64_hex_format(cpu_get_pc(cpu), cpu->space(AS_PROGRAM)->logaddrchars)); - else - m_context.printf("'%s'", cpu->tag()); - } - else - m_context.cpy("(no context)"); - - return m_context; -} - - - -//------------------------------------------------- -// start - initialize the emulated machine -//------------------------------------------------- - -void running_machine::start() -{ - // initialize basic can't-fail systems here - fileio_init(this); - config_init(this); - input_init(this); - output_init(this); - state_init(this); - state_save_allow_registration(this, true); - palette_init(this); - render_init(this); - ui_init(this); - generic_machine_init(this); - generic_video_init(this); - generic_sound_init(this); - mame_data->rand_seed = 0x9d14abd7; - - // initialize the timers and allocate a soft_reset timer - // this must be done before cpu_init so that CPU's can allocate timers - timer_init(this); - mame_data->soft_reset_timer = timer_alloc(this, soft_reset, NULL); - - // init the osd layer - osd_init(this); - - // initialize the base time (needed for doing record/playback) - time(&mame_data->base_time); - - // initialize the input system and input ports for the game - // this must be done before memory_init in order to allow specifying - // callbacks based on input port tags - time_t newbase = input_port_init(this, m_game.ipt); - if (newbase != 0) - mame_data->base_time = newbase; - - // intialize UI input - ui_input_init(this); - - // initialize the streams engine before the sound devices start - streams_init(this); - - // first load ROMs, then populate memory, and finally initialize CPUs - // these operations must proceed in this order - rom_init(this); - memory_init(this); - watchdog_init(this); - - // allocate the gfx elements prior to device initialization - gfx_init(this); - - // initialize natural keyboard support - inputx_init(this); - - // initialize image devices - image_init(this); - - // start up the devices - m_devicelist.start_all(); - - // call the game driver's init function - // this is where decryption is done and memory maps are altered - // so this location in the init order is important - ui_set_startup_text(this, "Initializing...", true); - if (m_game.driver_init != NULL) - (*m_game.driver_init)(this); - - // finish image devices init process - image_postdevice_init(this); - - // start the video and audio hardware - video_init(this); - tilemap_init(this); - crosshair_init(this); - - sound_init(this); - - // initialize the debugger - if ((debug_flags & DEBUG_FLAG_ENABLED) != 0) - debugger_init(this); - - // call the driver's _START callbacks - if (m_config.m_machine_start != NULL) - (*m_config.m_machine_start)(this); - if (m_config.m_sound_start != NULL) - (*m_config.m_sound_start)(this); - if (m_config.m_video_start != NULL) - (*m_config.m_video_start)(this); - - // initialize miscellaneous systems - saveload_init(this); - if (options_get_bool(mame_options(), OPTION_CHEAT)) - cheat_init(this); - - // disallow save state registrations starting here - state_save_allow_registration(this, false); -} - - -/*------------------------------------------------- - soft_reset - actually perform a soft-reset - of the system --------------------------------------------------*/ - -static TIMER_CALLBACK( soft_reset ) -{ - mame_private *mame = machine->mame_data; - callback_item *cb; - - logerror("Soft reset\n"); - - /* temporarily in the reset phase */ - mame->current_phase = MAME_PHASE_RESET; - - /* call all registered reset callbacks */ - for (cb = machine->mame_data->reset_callback_list; cb; cb = cb->next) - (*cb->func.reset)(machine); - - /* run the driver's reset callbacks */ - if (machine->config->m_machine_reset != NULL) - (*machine->config->m_machine_reset)(machine); - if (machine->config->m_sound_reset != NULL) - (*machine->config->m_sound_reset)(machine); - if (machine->config->m_video_reset != NULL) - (*machine->config->m_video_reset)(machine); - - /* now we're running */ - mame->current_phase = MAME_PHASE_RUNNING; - - /* allow 0-time queued callbacks to run before any CPUs execute */ - timer_execute_timers(machine); -} - - - -/*************************************************************************** - SAVE/RESTORE -***************************************************************************/ - -/*------------------------------------------------- - saveload_init - initialize the save/load logic --------------------------------------------------*/ - -static void saveload_init(running_machine *machine) -{ - const char *savegame = options_get_string(mame_options(), OPTION_STATE); - - /* if we're coming in with a savegame request, process it now */ - if (savegame[0] != 0) - mame_schedule_load(machine, savegame); - - /* if we're in autosave mode, schedule a load */ - else if (options_get_bool(mame_options(), OPTION_AUTOSAVE) && (machine->gamedrv->flags & GAME_SUPPORTS_SAVE)) - mame_schedule_load(machine, "auto"); -} - - -/*------------------------------------------------- - handle_save - attempt to perform a save --------------------------------------------------*/ - -static void handle_save(running_machine *machine) -{ - mame_private *mame = machine->mame_data; - file_error filerr; - mame_file *file; - - /* if no name, bail */ - if (mame->saveload_pending_file.len() == 0) - { - mame->saveload_schedule_callback = NULL; - return; - } - - /* if there are anonymous timers, we can't save just yet */ - if (timer_count_anonymous(machine) > 0) - { - /* if more than a second has passed, we're probably screwed */ - if (attotime_sub(timer_get_time(machine), mame->saveload_schedule_time).seconds > 0) - { - popmessage("Unable to save due to pending anonymous timers. See error.log for details."); - goto cancel; - } - return; - } - - /* open the file */ - filerr = mame_fopen(mame->saveload_searchpath, mame->saveload_pending_file, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file); - if (filerr == FILERR_NONE) - { - astring fullname(mame_file_full_name(file)); - state_save_error staterr; - - /* write the save state */ - staterr = state_save_write_file(machine, file); - - /* handle the result */ - switch (staterr) - { - case STATERR_ILLEGAL_REGISTRATIONS: - popmessage("Error: Unable to save state due to illegal registrations. See error.log for details."); - break; - - case STATERR_WRITE_ERROR: - popmessage("Error: Unable to save state due to a write error. Verify there is enough disk space."); - break; - - case STATERR_NONE: - if (!(machine->gamedrv->flags & GAME_SUPPORTS_SAVE)) - popmessage("State successfully saved.\nWarning: Save states are not officially supported for this game."); - else - popmessage("State successfully saved."); - break; - - default: - popmessage("Error: Unknwon error during state save."); - break; - } - - /* close and perhaps delete the file */ - mame_fclose(file); - if (staterr != STATERR_NONE) - osd_rmfile(fullname); - } - else - popmessage("Error: Failed to create save state file."); - - /* unschedule the save */ -cancel: - mame->saveload_pending_file.reset(); - mame->saveload_searchpath = NULL; - mame->saveload_schedule_callback = NULL; -} - - -/*------------------------------------------------- - handle_load - attempt to perform a load --------------------------------------------------*/ - -static void handle_load(running_machine *machine) -{ - mame_private *mame = machine->mame_data; - file_error filerr; - mame_file *file; - - /* if no name, bail */ - if (mame->saveload_pending_file.len() == 0) - { - mame->saveload_schedule_callback = NULL; - return; - } - - /* if there are anonymous timers, we can't load just yet because the timers might */ - /* overwrite data we have loaded */ - if (timer_count_anonymous(machine) > 0) - { - /* if more than a second has passed, we're probably screwed */ - if (attotime_sub(timer_get_time(machine), mame->saveload_schedule_time).seconds > 0) - { - popmessage("Unable to load due to pending anonymous timers. See error.log for details."); - goto cancel; - } - return; - } - - /* open the file */ - filerr = mame_fopen(mame->saveload_searchpath, mame->saveload_pending_file, OPEN_FLAG_READ, &file); - if (filerr == FILERR_NONE) - { - state_save_error staterr; - - /* write the save state */ - staterr = state_save_read_file(machine, file); - - /* handle the result */ - switch (staterr) - { - case STATERR_ILLEGAL_REGISTRATIONS: - popmessage("Error: Unable to load state due to illegal registrations. See error.log for details."); - break; - - case STATERR_INVALID_HEADER: - popmessage("Error: Unable to load state due to an invalid header. Make sure the save state is correct for this game."); - break; - - case STATERR_READ_ERROR: - popmessage("Error: Unable to load state due to a read error (file is likely corrupt)."); - break; - - case STATERR_NONE: - if (!(machine->gamedrv->flags & GAME_SUPPORTS_SAVE)) - popmessage("State successfully loaded.\nWarning: Save states are not officially supported for this game."); - else - popmessage("State successfully loaded."); - break; - - default: - popmessage("Error: Unknwon error during state load."); - break; - } - - /* close the file */ - mame_fclose(file); - } - else - popmessage("Error: Failed to open save state file."); - - /* unschedule the load */ -cancel: - mame->saveload_pending_file.reset(); - mame->saveload_schedule_callback = NULL; -} - - - -/*************************************************************************** - SYSTEM TIME -***************************************************************************/ - -/*------------------------------------------------- - get_tm_time - converts a MAME --------------------------------------------------*/ - -static void get_tm_time(struct tm *t, mame_system_tm *systm) -{ - systm->second = t->tm_sec; - systm->minute = t->tm_min; - systm->hour = t->tm_hour; - systm->mday = t->tm_mday; - systm->month = t->tm_mon; - systm->year = t->tm_year + 1900; - systm->weekday = t->tm_wday; - systm->day = t->tm_yday; - systm->is_dst = t->tm_isdst; -} - - -/*------------------------------------------------- - fill_systime - fills out a mame_system_time - structure --------------------------------------------------*/ - -static void fill_systime(mame_system_time *systime, time_t t) -{ - systime->time = t; - get_tm_time(localtime(&t), &systime->local_time); - get_tm_time(gmtime(&t), &systime->utc_time); -} - - -/*------------------------------------------------- - mame_get_base_datetime - retrieve the time of - the host system; useful for RTC implementations --------------------------------------------------*/ - -void mame_get_base_datetime(running_machine *machine, mame_system_time *systime) -{ - mame_private *mame = machine->mame_data; - fill_systime(systime, mame->base_time); -} - - -/*------------------------------------------------- - mame_get_current_datetime - retrieve the current - time (offsetted by the baes); useful for RTC - implementations --------------------------------------------------*/ - -void mame_get_current_datetime(running_machine *machine, mame_system_time *systime) -{ - mame_private *mame = machine->mame_data; - fill_systime(systime, mame->base_time + timer_get_time(machine).seconds); -} diff --git a/src/emu/mame.h b/src/emu/mame.h index 0cf319fc03a..e97362cd6a2 100644 --- a/src/emu/mame.h +++ b/src/emu/mame.h @@ -18,15 +18,15 @@ #ifndef __MAME_H__ #define __MAME_H__ +#include <time.h> -/*************************************************************************** - CONSTANTS -***************************************************************************/ -const int MAX_GFX_ELEMENTS = 32; +//************************************************************************** +// CONSTANTS +//************************************************************************** -/* return values from run_game */ +// return values from run_game enum { MAMERR_NONE = 0, /* no error */ @@ -42,30 +42,7 @@ enum }; -/* program phases */ -enum -{ - MAME_PHASE_PREINIT, - MAME_PHASE_INIT, - MAME_PHASE_RESET, - MAME_PHASE_RUNNING, - MAME_PHASE_EXIT -}; - - -/* debug flags */ -#define DEBUG_FLAG_ENABLED 0x00000001 /* debugging is enabled */ -#define DEBUG_FLAG_CALL_HOOK 0x00000002 /* CPU cores must call instruction hook */ -#define DEBUG_FLAG_WPR_PROGRAM 0x00000010 /* watchpoints are enabled for PROGRAM memory reads */ -#define DEBUG_FLAG_WPR_DATA 0x00000020 /* watchpoints are enabled for DATA memory reads */ -#define DEBUG_FLAG_WPR_IO 0x00000040 /* watchpoints are enabled for IO memory reads */ -#define DEBUG_FLAG_WPW_PROGRAM 0x00000100 /* watchpoints are enabled for PROGRAM memory writes */ -#define DEBUG_FLAG_WPW_DATA 0x00000200 /* watchpoints are enabled for DATA memory writes */ -#define DEBUG_FLAG_WPW_IO 0x00000400 /* watchpoints are enabled for IO memory writes */ -#define DEBUG_FLAG_OSD_ENABLED 0x00001000 /* The OSD debugger is enabled */ - - -/* MESS vs. MAME abstractions */ +// MESS vs. MAME abstractions #ifndef MESS #define APPNAME "MAME" #define APPNAME_LOWER "mame" @@ -91,251 +68,19 @@ enum #endif -/* output channels */ -enum _output_channel -{ - OUTPUT_CHANNEL_ERROR, - OUTPUT_CHANNEL_WARNING, - OUTPUT_CHANNEL_INFO, - OUTPUT_CHANNEL_DEBUG, - OUTPUT_CHANNEL_VERBOSE, - OUTPUT_CHANNEL_LOG, - OUTPUT_CHANNEL_COUNT -}; -typedef enum _output_channel output_channel; - - - -/*************************************************************************** - MACROS -***************************************************************************/ - -// global allocation helpers -#define auto_alloc(m, t) pool_alloc(static_cast<running_machine *>(m)->respool, t) -#define auto_alloc_clear(m, t) pool_alloc_clear(static_cast<running_machine *>(m)->respool, t) -#define auto_alloc_array(m, t, c) pool_alloc_array(static_cast<running_machine *>(m)->respool, t, c) -#define auto_alloc_array_clear(m, t, c) pool_alloc_array_clear(static_cast<running_machine *>(m)->respool, t, c) -#define auto_free(m, v) pool_free(static_cast<running_machine *>(m)->respool, v) - -#define auto_bitmap_alloc(m, w, h, f) auto_alloc(m, bitmap_t(w, h, f)) -#define auto_strdup(m, s) strcpy(auto_alloc_array(m, char, strlen(s) + 1), s) +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** - -/*************************************************************************** - TYPE DEFINITIONS -***************************************************************************/ - -// forward declarations -class gfx_element; -class colortable_t; -class debug_view_manager; - -typedef struct _mame_private mame_private; -typedef struct _cpuexec_private cpuexec_private; -typedef struct _timer_private timer_private; -typedef struct _state_private state_private; -typedef struct _memory_private memory_private; -typedef struct _palette_private palette_private; -typedef struct _tilemap_private tilemap_private; -typedef struct _streams_private streams_private; -typedef struct _devices_private devices_private; -typedef struct _romload_private romload_private; -typedef struct _sound_private sound_private; -typedef struct _input_private input_private; -typedef struct _input_port_private input_port_private; -typedef struct _ui_input_private ui_input_private; -typedef struct _cheat_private cheat_private; -typedef struct _debugcpu_private debugcpu_private; -typedef struct _debugvw_private debugvw_private; -typedef struct _generic_machine_private generic_machine_private; -typedef struct _generic_video_private generic_video_private; -typedef struct _generic_audio_private generic_audio_private; - - -// template specializations -typedef tagged_list<region_info> region_list; - - -/* output channel callback */ +// output channel callback typedef void (*output_callback_func)(void *param, const char *format, va_list argptr); -// memory region -class region_info -{ - DISABLE_COPYING(region_info); - - running_machine * machine; - -public: - region_info(running_machine *machine, const char *_name, UINT32 _length, UINT32 _flags); - ~region_info(); - - region_info *next() const { return m_next; } - - operator void *() const { return (this != NULL) ? base.v : NULL; } - operator INT8 *() const { return (this != NULL) ? base.i8 : NULL; } - operator UINT8 *() const { return (this != NULL) ? base.u8 : NULL; } - operator INT16 *() const { return (this != NULL) ? base.i16 : NULL; } - operator UINT16 *() const { return (this != NULL) ? base.u16 : NULL; } - operator INT32 *() const { return (this != NULL) ? base.i32 : NULL; } - operator UINT32 *() const { return (this != NULL) ? base.u32 : NULL; } - operator INT64 *() const { return (this != NULL) ? base.i64 : NULL; } - operator UINT64 *() const { return (this != NULL) ? base.u64 : NULL; } - - UINT32 bytes() const { return (this != NULL) ? length : 0; } - - endianness_t endianness() const { return ((flags & ROMREGION_ENDIANMASK) == ROMREGION_LE) ? ENDIANNESS_LITTLE : ENDIANNESS_BIG; } - UINT8 width() const { return 1 << ((flags & ROMREGION_WIDTHMASK) >> 8); } - - region_info * m_next; - astring name; - generic_ptr base; - UINT32 length; - UINT32 flags; -}; - - -/* this structure holds generic pointers that are commonly used */ -struct generic_pointers -{ - generic_ptr nvram; /* generic NVRAM */ - UINT32 nvram_size; - generic_ptr videoram; /* videoram */ - UINT32 videoram_size; - generic_ptr spriteram; /* spriteram */ - UINT32 spriteram_size; - generic_ptr spriteram2; /* secondary spriteram */ - UINT32 spriteram2_size; - generic_ptr buffered_spriteram; /* buffered spriteram */ - generic_ptr buffered_spriteram2;/* secondary buffered spriteram */ - generic_ptr paletteram; /* palette RAM */ - generic_ptr paletteram2; /* secondary palette RAM */ - bitmap_t * tmpbitmap; /* temporary bitmap */ -}; - - -/* description of the currently-running machine */ -class running_machine -{ - DISABLE_COPYING(running_machine); - -public: - running_machine(const game_driver &driver, const machine_config &config); - ~running_machine(); - - void start(); - - inline device_t *device(const char *tag); - template<class T> inline T *device(const char *tag) { return downcast<T *>(device(tag)); } - inline const input_port_config *port(const char *tag); - inline const region_info *region(const char *tag); - - // configuration helpers - UINT32 total_colors() const { return m_config.m_total_colors; } - - const char *describe_context(); - - resource_pool respool; // pool of resources for this machine - region_list regionlist; // list of memory regions - device_list m_devicelist; // list of running devices - device_scheduler scheduler; // scheduler object - - /* configuration data */ - const machine_config * config; /* points to the constructed machine_config */ - const machine_config & m_config; /* points to the constructed machine_config */ - ioport_list portlist; /* points to a list of input port configurations */ - - /* CPU information */ - device_t * firstcpu; /* first CPU (allows for quick iteration via typenext) */ - - /* game-related information */ - const game_driver * gamedrv; /* points to the definition of the game machine */ - const game_driver & m_game; /* points to the definition of the game machine */ - char * basename; /* basename used for game-related paths */ - - /* video-related information */ - gfx_element * gfx[MAX_GFX_ELEMENTS];/* array of pointers to graphic sets (chars, sprites) */ - screen_device * primary_screen; /* the primary screen device, or NULL if screenless */ - palette_t * palette; /* global palette object */ - - /* palette-related information */ - const pen_t * pens; /* remapped palette pen numbers */ - colortable_t * colortable; /* global colortable for remapping */ - pen_t * shadow_table; /* table for looking up a shadowed pen */ - bitmap_t * priority_bitmap; /* priority bitmap */ - - /* audio-related information */ - int sample_rate; /* the digital audio sample rate */ - - /* debugger-related information */ - UINT32 debug_flags; /* the current debug flags */ - - /* UI-related */ - bool ui_active; /* ui active or not (useful for games / systems with keyboard inputs) */ - - /* generic pointers */ - generic_pointers generic; /* generic pointers */ - - /* internal core information */ - mame_private * mame_data; /* internal data from mame.c */ - timer_private * timer_data; /* internal data from timer.c */ - state_private * state_data; /* internal data from state.c */ - memory_private * memory_data; /* internal data from memory.c */ - palette_private * palette_data; /* internal data from palette.c */ - tilemap_private * tilemap_data; /* internal data from tilemap.c */ - streams_private * streams_data; /* internal data from streams.c */ - devices_private * devices_data; /* internal data from devices.c */ - romload_private * romload_data; /* internal data from romload.c */ - sound_private * sound_data; /* internal data from sound.c */ - input_private * input_data; /* internal data from input.c */ - input_port_private * input_port_data; /* internal data from inptport.c */ - ui_input_private * ui_input_data; /* internal data from uiinput.c */ - cheat_private * cheat_data; /* internal data from cheat.c */ - debugcpu_private * debugcpu_data; /* internal data from debugcpu.c */ - generic_machine_private *generic_machine_data; /* internal data from machine/generic.c */ - generic_video_private * generic_video_data; /* internal data from video/generic.c */ - generic_audio_private * generic_audio_data; /* internal data from audio/generic.c */ - - debug_view_manager * m_debug_view; /* internal data from debugvw.c */ - - /* driver-specific information */ - void * driver_data; /* drivers can hang data off of here instead of using globals */ - -private: - astring m_context; // context string -}; - - -typedef struct _mame_system_tm mame_system_tm; -struct _mame_system_tm -{ - UINT8 second; /* seconds (0-59) */ - UINT8 minute; /* minutes (0-59) */ - UINT8 hour; /* hours (0-23) */ - UINT8 mday; /* day of month (1-31) */ - UINT8 month; /* month (0-11) */ - INT32 year; /* year (1=1 AD) */ - UINT8 weekday; /* day of week (0-6) */ - UINT16 day; /* day of year (0-365) */ - UINT8 is_dst; /* is this daylight savings? */ -}; - - -typedef struct _mame_system_time mame_system_time; -struct _mame_system_time -{ - INT64 time; /* number of seconds elapsed since midnight, January 1 1970 UTC */ - mame_system_tm local_time; /* local time */ - mame_system_tm utc_time; /* UTC coordinated time */ -}; - - -/*************************************************************************** - GLOBAL VARIABLES -***************************************************************************/ +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** extern const char mame_disclaimer[]; @@ -356,85 +101,11 @@ int mame_execute(core_options *options); /* accesses the core_options for the currently running emulation */ core_options *mame_options(void); -/* return the current phase */ -int mame_get_phase(running_machine *machine); - -/* request callback on frame update */ -void add_frame_callback(running_machine *machine, void (*callback)(running_machine *)); - -/* request callback on reset */ -void add_reset_callback(running_machine *machine, void (*callback)(running_machine *)); - -/* request callback on pause */ -void add_pause_callback(running_machine *machine, void (*callback)(running_machine *, int)); - -/* request callback on termination */ -void add_exit_callback(running_machine *machine, void (*callback)(running_machine *)); - -/* handle update tasks for a frame boundary */ -void mame_frame_update(running_machine *machine); - /* return true if the given machine is valid */ int mame_is_valid_machine(running_machine *machine); -/* ----- global system states ----- */ - -/* schedule an exit */ -void mame_schedule_exit(running_machine *machine); - -/* schedule a hard reset */ -void mame_schedule_hard_reset(running_machine *machine); - -/* schedule a soft reset */ -void mame_schedule_soft_reset(running_machine *machine); - -/* schedule a new driver */ -void mame_schedule_new_driver(running_machine *machine, const game_driver *driver); - -/* schedule a save */ -void mame_schedule_save(running_machine *machine, const char *filename); - -/* schedule a load */ -void mame_schedule_load(running_machine *machine, const char *filename); - -/* is a save or load pending? */ -int mame_is_save_or_load_pending(running_machine *machine); - -/* is a scheduled event pending? */ -int mame_is_scheduled_event_pending(running_machine *machine); - -/* pause the system */ -void mame_pause(running_machine *machine, int pause); - -/* get the current pause state */ -int mame_is_paused(running_machine *machine); - - - -/* ----- memory region management ----- */ - -/* allocate a new memory region */ -region_info *memory_region_alloc(running_machine *machine, const char *name, UINT32 length, UINT32 flags); - -/* free an allocated memory region */ -void memory_region_free(running_machine *machine, const char *name); - -/* return a pointer to a specified memory region */ -UINT8 *memory_region(running_machine *machine, const char *name); - -/* return the size (in bytes) of a specified memory region */ -UINT32 memory_region_length(running_machine *machine, const char *name); - -/* return the flags (defined in romload.h) for a specified memory region */ -UINT32 memory_region_flags(running_machine *machine, const char *name); - -/* return the name of the next memory region (or the first if name == NULL) */ -const char *memory_region_next(running_machine *machine, const char *name); - - - /* ----- output management ----- */ /* set the output handler for a channel, returns the current one */ @@ -461,45 +132,15 @@ void mame_printf_debug(const char *format, ...) ATTR_PRINTF(1,2); /* ----- miscellaneous bits & pieces ----- */ -/* pop-up a user visible message */ -void CLIB_DECL popmessage(const char *format,...) ATTR_PRINTF(1,2); - -/* log to the standard error.log file */ -void CLIB_DECL logerror(const char *format,...) ATTR_PRINTF(1,2); - -/* adds a callback to be called on logerror() */ -void add_logerror_callback(running_machine *machine, void (*callback)(running_machine *, const char *)); - /* parse the configured INI files */ void mame_parse_ini_files(core_options *options, const game_driver *driver); -/* standardized random number generator */ -UINT32 mame_rand(running_machine *machine); -/* retrieve the base system time */ -void mame_get_base_datetime(running_machine *machine, mame_system_time *systime); - -/* retrieve the current system time */ -void mame_get_current_datetime(running_machine *machine, mame_system_time *systime); - -/*************************************************************************** - INLINE FUNCTIONS -***************************************************************************/ - -inline device_t *running_machine::device(const char *tag) -{ - return m_devicelist.find(tag); -} - -inline const input_port_config *running_machine::port(const char *tag) -{ - return portlist.find(tag); -} +// pop-up a user visible message +void CLIB_DECL popmessage(const char *format,...) ATTR_PRINTF(1,2); -inline const region_info *running_machine::region(const char *tag) -{ - return regionlist.find(tag); -} +// log to the standard error.log file +void CLIB_DECL logerror(const char *format,...) ATTR_PRINTF(1,2); #endif /* __MAME_H__ */ diff --git a/src/emu/memory.c b/src/emu/memory.c index 18c52db8a4b..796f92a4dc4 100644 --- a/src/emu/memory.c +++ b/src/emu/memory.c @@ -393,7 +393,7 @@ static void memory_init_populate(running_machine *machine); static void memory_init_map_entry(address_space *space, const address_map_entry *entry, read_or_write readorwrite); static void memory_init_allocate(running_machine *machine); static void memory_init_locate(running_machine *machine); -static void memory_exit(running_machine *machine); +static void memory_exit(running_machine &machine); /* address map helpers */ static void map_detokenize(memory_private *memdata, address_map *map, const game_driver *driver, const device_config *devconfig, const addrmap_token *tokens); @@ -793,7 +793,7 @@ void memory_init(running_machine *machine) { memory_private *memdata; - add_exit_callback(machine, memory_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, memory_exit); /* allocate our private data */ memdata = machine->memory_data = auto_alloc_clear(machine, memory_private); @@ -1493,7 +1493,7 @@ void *_memory_install_ram(const address_space *space, offs_t addrstart, offs_t a /* if we still don't have a pointer, and we're past the initialization phase, allocate a new block */ if (memdata->bank_ptr[bankindex] == NULL && memdata->initialized) { - if (mame_get_phase(space->machine) >= MAME_PHASE_RESET) + if (space->machine->phase() >= MACHINE_PHASE_RESET) fatalerror("Attempted to call memory_install_ram() after initialization time without a baseptr!"); memdata->bank_ptr[bankindex] = (UINT8 *)block_allocate(space, memory_address_to_byte(space, addrstart), memory_address_to_byte_end(space, addrend), NULL); } @@ -1517,7 +1517,7 @@ void *_memory_install_ram(const address_space *space, offs_t addrstart, offs_t a /* if we still don't have a pointer, and we're past the initialization phase, allocate a new block */ if (memdata->bank_ptr[bankindex] == NULL && memdata->initialized) { - if (mame_get_phase(space->machine) >= MAME_PHASE_RESET) + if (space->machine->phase() >= MACHINE_PHASE_RESET) fatalerror("Attempted to call memory_install_ram() after initialization time without a baseptr!"); memdata->bank_ptr[bankindex] = (UINT8 *)block_allocate(space, memory_address_to_byte(space, addrstart), memory_address_to_byte_end(space, addrend), NULL); } @@ -1805,7 +1805,8 @@ static void memory_init_preflight(running_machine *machine) /* loop over valid address spaces */ for (space = (address_space *)memdata->spacelist; space != NULL; space = (address_space *)space->next) { - int regionsize = (space->spacenum == ADDRESS_SPACE_0) ? memory_region_length(space->machine, space->cpu->tag()) : 0; + const region_info *devregion = (space->spacenum == ADDRESS_SPACE_0) ? space->machine->region(space->cpu->tag()) : NULL; + int devregionsize = (devregion != NULL) ? devregion->bytes() : 0; address_map_entry *entry; int entrynum; @@ -1834,7 +1835,7 @@ static void memory_init_preflight(running_machine *machine) if (space->spacenum == ADDRESS_SPACE_0 && entry->read.type == AMH_ROM && entry->region == NULL) { /* make sure it fits within the memory region before doing so, however */ - if (entry->byteend < regionsize) + if (entry->byteend < devregionsize) { entry->region = space->cpu->tag(); entry->rgnoffs = entry->bytestart; @@ -1844,19 +1845,18 @@ static void memory_init_preflight(running_machine *machine) /* validate adjusted addresses against implicit regions */ if (entry->region != NULL && entry->share == NULL && entry->baseptr == NULL) { - UINT8 *base = memory_region(machine, entry->region); - offs_t length = memory_region_length(machine, entry->region); - - /* validate the region */ - if (base == NULL) + const region_info *region = machine->region(entry->region); + if (region == NULL) fatalerror("Error: device '%s' %s space memory map entry %X-%X references non-existant region \"%s\"", space->cpu->tag(), space->name, entry->addrstart, entry->addrend, entry->region); - if (entry->rgnoffs + (entry->byteend - entry->bytestart + 1) > length) - fatalerror("Error: device '%s' %s space memory map entry %X-%X extends beyond region \"%s\" size (%X)", space->cpu->tag(), space->name, entry->addrstart, entry->addrend, entry->region, length); + + /* validate the region */ + if (entry->rgnoffs + (entry->byteend - entry->bytestart + 1) > region->bytes()) + fatalerror("Error: device '%s' %s space memory map entry %X-%X extends beyond region \"%s\" size (%X)", space->cpu->tag(), space->name, entry->addrstart, entry->addrend, entry->region, region->bytes()); } /* convert any region-relative entries to their memory pointers */ if (entry->region != NULL) - entry->memory = memory_region(machine, entry->region) + entry->rgnoffs; + entry->memory = machine->region(entry->region)->base() + entry->rgnoffs; } /* now loop over all the handlers and enforce the address mask */ @@ -2171,9 +2171,9 @@ static void memory_init_locate(running_machine *machine) memory_exit - free memory -------------------------------------------------*/ -static void memory_exit(running_machine *machine) +static void memory_exit(running_machine &machine) { - memory_private *memdata = machine->memory_data; + memory_private *memdata = machine.memory_data; address_space *space; /* free all the address spaces and tables */ @@ -2539,8 +2539,9 @@ static int space_needs_backing_store(const address_space *space, const address_m return TRUE; /* if we're reading from RAM or from ROM outside of address space 0 or its region, then yes, we do need backing */ + const region_info *region = space->machine->region(space->cpu->tag()); if (entry->read.type == AMH_RAM || - (entry->read.type == AMH_ROM && (space->spacenum != ADDRESS_SPACE_0 || entry->addrstart >= memory_region_length(space->machine, space->cpu->tag())))) + (entry->read.type == AMH_ROM && (space->spacenum != ADDRESS_SPACE_0 || region == NULL || entry->addrstart >= region->bytes()))) return TRUE; /* all other cases don't need backing */ @@ -3323,7 +3324,7 @@ static void *block_allocate(const address_space *space, offs_t bytestart, offs_t int allocatemem = (memory == NULL); memory_block *block; size_t bytestoalloc; - const char *region; + const region_info *region; VPRINTF(("block_allocate('%s',%s,%08X,%08X,%p)\n", space->cpu->tag(), space->name, bytestart, byteend, memory)); @@ -3338,11 +3339,9 @@ static void *block_allocate(const address_space *space, offs_t bytestart, offs_t memory = block + 1; /* register for saving, but only if we're not part of a memory region */ - for (region = memory_region_next(space->machine, NULL); region != NULL; region = memory_region_next(space->machine, region)) + for (region = space->machine->m_regionlist.first(); region != NULL; region = region->next()) { - UINT8 *region_base = memory_region(space->machine, region); - UINT32 region_length = memory_region_length(space->machine, region); - if (region_base != NULL && region_length != 0 && (UINT8 *)memory >= region_base && ((UINT8 *)memory + (byteend - bytestart + 1)) < region_base + region_length) + if ((UINT8 *)memory >= region->base() && ((UINT8 *)memory + (byteend - bytestart + 1)) < region->end()) { VPRINTF(("skipping save of this memory block as it is covered by a memory region\n")); break; diff --git a/src/emu/output.c b/src/emu/output.c index 56d86388849..b4b05e30a1a 100644 --- a/src/emu/output.c +++ b/src/emu/output.c @@ -62,8 +62,9 @@ static UINT32 uniqueid = 12345; FUNCTION PROTOTYPES ***************************************************************************/ -static void output_pause(running_machine *machine, int pause); -static void output_exit(running_machine *machine); +static void output_pause(running_machine &machine); +static void output_resume(running_machine &machine); +static void output_exit(running_machine &machine); @@ -146,10 +147,11 @@ INLINE output_item *create_new_item(const char *outname, INT32 value) void output_init(running_machine *machine) { /* add pause callback */ - add_pause_callback(machine, output_pause); + machine->add_notifier(MACHINE_NOTIFY_PAUSE, output_pause); + machine->add_notifier(MACHINE_NOTIFY_RESUME, output_resume); /* get a callback when done */ - add_exit_callback(machine, output_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, output_exit); /* reset the lists */ memset(itemtable, 0, sizeof(itemtable)); @@ -161,9 +163,14 @@ void output_init(running_machine *machine) output_pause - send pause message -------------------------------------------------*/ -static void output_pause(running_machine *machine, int pause) +static void output_pause(running_machine &machine) { - output_set_value("pause", pause & 1); + output_set_value("pause", 1); +} + +static void output_resume(running_machine &machine) +{ + output_set_value("pause", 0); } @@ -171,7 +178,7 @@ static void output_pause(running_machine *machine, int pause) output_exit - cleanup on exit -------------------------------------------------*/ -static void output_exit(running_machine *machine) +static void output_exit(running_machine &machine) { output_notify *notify; output_item *item; diff --git a/src/emu/render.c b/src/emu/render.c index c306967b22c..a1a537d5b0a 100644 --- a/src/emu/render.c +++ b/src/emu/render.c @@ -256,7 +256,7 @@ static const int layer_order_alternate[] = { ITEM_LAYER_BACKDROP, ITEM_LAYER_SCR ***************************************************************************/ /* core system */ -static void render_exit(running_machine *machine); +static void render_exit(running_machine &machine); static void render_load(running_machine *machine, int config_type, xml_data_node *parentnode); static void render_save(running_machine *machine, int config_type, xml_data_node *parentnode); @@ -545,7 +545,7 @@ void render_init(running_machine *machine) render_container **current_container_ptr = &screen_container_list; /* make sure we clean up after ourselves */ - add_exit_callback(machine, render_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, render_exit); /* set up the list of render targets */ targetlist = NULL; @@ -570,9 +570,9 @@ void render_init(running_machine *machine) /* set the initial orientation and brightness/contrast/gamma */ render_container_get_user_settings(screen_container, &settings); settings.orientation = machine->gamedrv->flags & ORIENTATION_MASK; - settings.brightness = options_get_float(mame_options(), OPTION_BRIGHTNESS); - settings.contrast = options_get_float(mame_options(), OPTION_CONTRAST); - settings.gamma = options_get_float(mame_options(), OPTION_GAMMA); + settings.brightness = options_get_float(machine->options(), OPTION_BRIGHTNESS); + settings.contrast = options_get_float(machine->options(), OPTION_CONTRAST); + settings.gamma = options_get_float(machine->options(), OPTION_GAMMA); render_container_set_user_settings(screen_container, &settings); screen_container->screen = screendev; @@ -594,7 +594,7 @@ void render_init(running_machine *machine) render_exit - free all rendering data -------------------------------------------------*/ -static void render_exit(running_machine *machine) +static void render_exit(running_machine &machine) { render_texture **texture_ptr; render_container *container; @@ -898,19 +898,19 @@ static void render_save(running_machine *machine, int config_type, xml_data_node xml_set_attribute_int(screennode, "index", scrnum); /* output the color controls */ - if (container->brightness != options_get_float(mame_options(), OPTION_BRIGHTNESS)) + if (container->brightness != options_get_float(machine->options(), OPTION_BRIGHTNESS)) { xml_set_attribute_float(screennode, "brightness", container->brightness); changed = TRUE; } - if (container->contrast != options_get_float(mame_options(), OPTION_CONTRAST)) + if (container->contrast != options_get_float(machine->options(), OPTION_CONTRAST)) { xml_set_attribute_float(screennode, "contrast", container->contrast); changed = TRUE; } - if (container->gamma != options_get_float(mame_options(), OPTION_GAMMA)) + if (container->gamma != options_get_float(machine->options(), OPTION_GAMMA)) { xml_set_attribute_float(screennode, "gamma", container->gamma); changed = TRUE; @@ -1093,26 +1093,26 @@ render_target *render_target_alloc(running_machine *machine, const char *layoutf /* determine the base layer configuration based on options */ target->base_layerconfig = LAYER_CONFIG_DEFAULT; - if (!options_get_bool(mame_options(), OPTION_USE_BACKDROPS)) target->base_layerconfig &= ~LAYER_CONFIG_ENABLE_BACKDROP; - if (!options_get_bool(mame_options(), OPTION_USE_OVERLAYS)) target->base_layerconfig &= ~LAYER_CONFIG_ENABLE_OVERLAY; - if (!options_get_bool(mame_options(), OPTION_USE_BEZELS)) target->base_layerconfig &= ~LAYER_CONFIG_ENABLE_BEZEL; - if (options_get_bool(mame_options(), OPTION_ARTWORK_CROP)) target->base_layerconfig |= LAYER_CONFIG_ZOOM_TO_SCREEN; + if (!options_get_bool(machine->options(), OPTION_USE_BACKDROPS)) target->base_layerconfig &= ~LAYER_CONFIG_ENABLE_BACKDROP; + if (!options_get_bool(machine->options(), OPTION_USE_OVERLAYS)) target->base_layerconfig &= ~LAYER_CONFIG_ENABLE_OVERLAY; + if (!options_get_bool(machine->options(), OPTION_USE_BEZELS)) target->base_layerconfig &= ~LAYER_CONFIG_ENABLE_BEZEL; + if (options_get_bool(machine->options(), OPTION_ARTWORK_CROP)) target->base_layerconfig |= LAYER_CONFIG_ZOOM_TO_SCREEN; /* determine the base orientation based on options */ target->orientation = ROT0; - if (!options_get_bool(mame_options(), OPTION_ROTATE)) + if (!options_get_bool(machine->options(), OPTION_ROTATE)) target->base_orientation = orientation_reverse(machine->gamedrv->flags & ORIENTATION_MASK); /* rotate left/right */ - if (options_get_bool(mame_options(), OPTION_ROR) || (options_get_bool(mame_options(), OPTION_AUTOROR) && (machine->gamedrv->flags & ORIENTATION_SWAP_XY))) + if (options_get_bool(machine->options(), OPTION_ROR) || (options_get_bool(machine->options(), OPTION_AUTOROR) && (machine->gamedrv->flags & ORIENTATION_SWAP_XY))) target->base_orientation = orientation_add(ROT90, target->base_orientation); - if (options_get_bool(mame_options(), OPTION_ROL) || (options_get_bool(mame_options(), OPTION_AUTOROL) && (machine->gamedrv->flags & ORIENTATION_SWAP_XY))) + if (options_get_bool(machine->options(), OPTION_ROL) || (options_get_bool(machine->options(), OPTION_AUTOROL) && (machine->gamedrv->flags & ORIENTATION_SWAP_XY))) target->base_orientation = orientation_add(ROT270, target->base_orientation); /* flip X/Y */ - if (options_get_bool(mame_options(), OPTION_FLIPX)) + if (options_get_bool(machine->options(), OPTION_FLIPX)) target->base_orientation ^= ORIENTATION_FLIP_X; - if (options_get_bool(mame_options(), OPTION_FLIPY)) + if (options_get_bool(machine->options(), OPTION_FLIPY)) target->base_orientation ^= ORIENTATION_FLIP_Y; /* set the orientation and layerconfig equal to the base */ @@ -1559,7 +1559,7 @@ const render_primitive_list *render_target_get_primitives(render_target *target) root_xform.no_center = FALSE; /* iterate over layers back-to-front, but only if we're running */ - if (mame_get_phase(target->machine) >= MAME_PHASE_RESET) + if (target->machine->phase() >= MACHINE_PHASE_RESET) for (layernum = 0; layernum < ITEM_LAYER_MAX; layernum++) { int blendmode; @@ -1601,7 +1601,7 @@ const render_primitive_list *render_target_get_primitives(render_target *target) state = output_get_value(item->output_name); else if (item->input_tag[0] != 0) { - const input_field_config *field = input_field_by_tag_and_mask(target->machine->portlist, item->input_tag, item->input_mask); + const input_field_config *field = input_field_by_tag_and_mask(target->machine->m_portlist, item->input_tag, item->input_mask); if (field != NULL) state = ((input_port_read_safe(target->machine, item->input_tag, 0) ^ field->defvalue) & item->input_mask) ? 1 : 0; } @@ -1801,7 +1801,7 @@ static int load_layout_files(render_target *target, const char *layoutfile, int running_machine *machine = target->machine; const game_driver *gamedrv = machine->gamedrv; const machine_config *config = machine->config; - const char *basename = machine->basename; + const char *basename = machine->basename(); layout_file **nextfile = &target->filelist; const game_driver *cloneof; diff --git a/src/emu/romload.c b/src/emu/romload.c index 3d0db9d4457..ef5f71c6623 100644 --- a/src/emu/romload.c +++ b/src/emu/romload.c @@ -74,7 +74,7 @@ struct _romload_private FUNCTION PROTOTYPES ***************************************************************************/ -static void rom_exit(running_machine *machine); +static void rom_exit(running_machine &machine); @@ -334,7 +334,7 @@ static void CLIB_DECL ATTR_PRINTF(1,2) debugload(const char *string, ...) static void determine_bios_rom(rom_load_data *romdata) { - const char *specbios = options_get_string(mame_options(), OPTION_BIOS); + const char *specbios = options_get_string(romdata->machine->options(), OPTION_BIOS); const char *defaultname = NULL; const rom_entry *rom; int default_no = 1; @@ -582,15 +582,6 @@ static void display_rom_load_results(rom_load_data *romdata) /* if we had errors, they are fatal */ if (romdata->errors != 0) { - const char *rgntag, *nextrgntag; - - /* clean up any regions */ - for (rgntag = memory_region_next(romdata->machine, NULL); rgntag != NULL; rgntag = nextrgntag) - { - nextrgntag = memory_region_next(romdata->machine, rgntag); - memory_region_free(romdata->machine, rgntag); - } - /* create the error message and exit fatally */ mame_printf_error("%s", romdata->errorstring.cstr()); fatalerror_exitcode(romdata->machine, MAMERR_MISSING_FILES, "ERROR: required files are missing, the "GAMENOUN" cannot be run."); @@ -612,29 +603,30 @@ static void display_rom_load_results(rom_load_data *romdata) static void region_post_process(rom_load_data *romdata, const char *rgntag) { - UINT32 regionlength = memory_region_length(romdata->machine, rgntag); - UINT32 regionflags = memory_region_flags(romdata->machine, rgntag); - UINT8 *regionbase = memory_region(romdata->machine, rgntag); - int endianness = ((regionflags & ROMREGION_ENDIANMASK) == ROMREGION_LE) ? ENDIANNESS_LITTLE : ENDIANNESS_BIG; - int datawidth = 1 << ((regionflags & ROMREGION_WIDTHMASK) >> 8); + const region_info *region = romdata->machine->region(rgntag); UINT8 *base; int i, j; - LOG(("+ datawidth=%d little=%d\n", datawidth, endianness == ENDIANNESS_LITTLE)); + // do nothing if no region + if (region == NULL) + return; + + LOG(("+ datawidth=%d little=%d\n", region->width(), region->endianness() == ENDIANNESS_LITTLE)); /* if the region is inverted, do that now */ - if (regionflags & ROMREGION_INVERTMASK) + if (region->invert()) { LOG(("+ Inverting region\n")); - for (i = 0, base = regionbase; i < regionlength; i++) + for (i = 0, base = region->base(); i < region->bytes(); i++) *base++ ^= 0xff; } /* swap the endianness if we need to */ - if (datawidth > 1 && endianness != ENDIANNESS_NATIVE) + if (region->width() > 1 && region->endianness() != ENDIANNESS_NATIVE) { LOG(("+ Byte swapping region\n")); - for (i = 0, base = regionbase; i < regionlength; i += datawidth) + int datawidth = region->width(); + for (i = 0, base = region->base(); i < region->bytes(); i += datawidth) { UINT8 temp[8]; memcpy(temp, base, datawidth); @@ -732,7 +724,7 @@ static int read_rom_data(rom_load_data *romdata, const rom_entry *romp) int skip = ROM_GETSKIPCOUNT(romp); int reversed = ROM_ISREVERSED(romp); int numgroups = (numbytes + groupsize - 1) / groupsize; - UINT8 *base = romdata->region->base.u8 + ROM_GETOFFSET(romp); + UINT8 *base = romdata->region->base() + ROM_GETOFFSET(romp); UINT32 tempbufsize; UINT8 *tempbuf; int i; @@ -744,7 +736,7 @@ static int read_rom_data(rom_load_data *romdata, const rom_entry *romp) fatalerror("Error in RomModule definition: %s length not an even multiple of group size\n", ROM_GETNAME(romp)); /* make sure we only fill within the region space */ - if (ROM_GETOFFSET(romp) + numgroups * groupsize + (numgroups - 1) * skip > romdata->region->length) + if (ROM_GETOFFSET(romp) + numgroups * groupsize + (numgroups - 1) * skip > romdata->region->bytes()) fatalerror("Error in RomModule definition: %s out of memory region space\n", ROM_GETNAME(romp)); /* make sure the length was valid */ @@ -846,10 +838,10 @@ static int read_rom_data(rom_load_data *romdata, const rom_entry *romp) static void fill_rom_data(rom_load_data *romdata, const rom_entry *romp) { UINT32 numbytes = ROM_GETLENGTH(romp); - UINT8 *base = romdata->region->base.u8 + ROM_GETOFFSET(romp); + UINT8 *base = romdata->region->base() + ROM_GETOFFSET(romp); /* make sure we fill within the region space */ - if (ROM_GETOFFSET(romp) + numbytes > romdata->region->length) + if (ROM_GETOFFSET(romp) + numbytes > romdata->region->bytes()) fatalerror("Error in RomModule definition: FILL out of memory region space\n"); /* make sure the length was valid */ @@ -867,14 +859,13 @@ static void fill_rom_data(rom_load_data *romdata, const rom_entry *romp) static void copy_rom_data(rom_load_data *romdata, const rom_entry *romp) { - UINT8 *base = romdata->region->base.u8 + ROM_GETOFFSET(romp); + UINT8 *base = romdata->region->base() + ROM_GETOFFSET(romp); const char *srcrgntag = ROM_GETNAME(romp); UINT32 numbytes = ROM_GETLENGTH(romp); UINT32 srcoffs = (FPTR)ROM_GETHASHDATA(romp); /* srcoffset in place of hashdata */ - UINT8 *srcbase; /* make sure we copy within the region space */ - if (ROM_GETOFFSET(romp) + numbytes > romdata->region->length) + if (ROM_GETOFFSET(romp) + numbytes > romdata->region->bytes()) fatalerror("Error in RomModule definition: COPY out of target memory region space\n"); /* make sure the length was valid */ @@ -882,16 +873,16 @@ static void copy_rom_data(rom_load_data *romdata, const rom_entry *romp) fatalerror("Error in RomModule definition: COPY has an invalid length\n"); /* make sure the source was valid */ - srcbase = memory_region(romdata->machine, srcrgntag); - if (srcbase == NULL) + const region_info *region = romdata->machine->region(srcrgntag); + if (region == NULL) fatalerror("Error in RomModule definition: COPY from an invalid region\n"); /* make sure we find within the region space */ - if (srcoffs + numbytes > memory_region_length(romdata->machine, srcrgntag)) + if (srcoffs + numbytes > region->bytes()) fatalerror("Error in RomModule definition: COPY out of source memory region space\n"); /* fill the data */ - memcpy(base, srcbase + srcoffs, numbytes); + memcpy(base, region->base() + srcoffs, numbytes); } @@ -1275,16 +1266,14 @@ static UINT32 normalize_flags_for_device(running_machine *machine, UINT32 startf void load_software_part_region(running_device *device, char *swlist, char *swname, rom_entry *start_region) { - astring *regiontag = astring_alloc(); - astring *locationtag = astring_alloc(); - const rom_entry *region; + astring locationtag(swlist, PATH_SEPARATOR, swname); rom_load_data *romdata = device->machine->romload_data; + const rom_entry *region; + astring regiontag; /* Make sure we are passed a device */ assert(device!=NULL); - astring_assemble_3( locationtag, swlist, PATH_SEPARATOR, swname ); - romdata->errorstring.reset(); /* loop until we hit the end */ @@ -1293,52 +1282,51 @@ void load_software_part_region(running_device *device, char *swlist, char *swnam UINT32 regionlength = ROMREGION_GETLENGTH(region); UINT32 regionflags = ROMREGION_GETFLAGS(region); - astring_assemble_3( regiontag, device->tag(), ":", ROMREGION_GETTAG(region) ); - LOG(("Processing region \"%s\" (length=%X)\n", astring_c(regiontag), regionlength)); + device->subtag(regiontag, ROMREGION_GETTAG(region)); + LOG(("Processing region \"%s\" (length=%X)\n", regiontag.cstr(), regionlength)); /* the first entry must be a region */ assert(ROMENTRY_ISREGION(region)); /* if this is a device region, override with the device width and endianness */ - if (devtag_get_device(romdata->machine, astring_c(regiontag)) != NULL) - regionflags = normalize_flags_for_device(romdata->machine, regionflags, astring_c(regiontag)); + const region_info *memregion = romdata->machine->region(regiontag); + if (memregion != NULL) + { + regionflags = normalize_flags_for_device(romdata->machine, regionflags, regiontag); - /* clear old region (todo: should be moved to an image unload function) */ - if (memory_region(romdata->machine, astring_c(regiontag)) != NULL) - memory_region_free(romdata->machine, astring_c(regiontag)); + /* clear old region (todo: should be moved to an image unload function) */ + romdata->machine->region_free(memregion->name()); + } /* remember the base and length */ - romdata->region = memory_region_alloc(romdata->machine, astring_c(regiontag), regionlength, regionflags); - LOG(("Allocated %X bytes @ %p\n", romdata->region->length, romdata->region->base.v)); + romdata->region = romdata->machine->region_alloc(regiontag, regionlength, regionflags); + LOG(("Allocated %X bytes @ %p\n", romdata->region->bytes(), romdata->region->base())); /* clear the region if it's requested */ if (ROMREGION_ISERASE(region)) - memset(romdata->region->base.v, ROMREGION_GETERASEVAL(region), romdata->region->length); + memset(romdata->region->base(), ROMREGION_GETERASEVAL(region), romdata->region->bytes()); /* or if it's sufficiently small (<= 4MB) */ - else if (romdata->region->length <= 0x400000) - memset(romdata->region->base.v, 0, romdata->region->length); + else if (romdata->region->bytes() <= 0x400000) + memset(romdata->region->base(), 0, romdata->region->bytes()); #ifdef MAME_DEBUG /* if we're debugging, fill region with random data to catch errors */ else - fill_random(romdata->machine, romdata->region->base.u8, romdata->region->length); + fill_random(romdata->machine, romdata->region->base(), romdata->region->bytes()); #endif /* now process the entries in the region */ if (ROMREGION_ISROMDATA(region)) - process_rom_entries(romdata, astring_c(locationtag), region + 1); + process_rom_entries(romdata, locationtag, region + 1); else if (ROMREGION_ISDISKDATA(region)) - process_disk_entries(romdata, astring_c(locationtag), region + 1); + process_disk_entries(romdata, locationtag, region + 1); } /* now go back and post-process all the regions */ for (region = start_region; region != NULL; region = rom_next_region(region)) region_post_process(romdata, ROMREGION_GETTAG(region)); - astring_free(regiontag); - astring_free(locationtag); - /* display the results and exit */ display_rom_load_results(romdata); } @@ -1374,21 +1362,21 @@ static void process_region_list(rom_load_data *romdata) regionflags = normalize_flags_for_device(romdata->machine, regionflags, regiontag); /* remember the base and length */ - romdata->region = memory_region_alloc(romdata->machine, regiontag, regionlength, regionflags); - LOG(("Allocated %X bytes @ %p\n", romdata->region->length, romdata->region->base.v)); + romdata->region = romdata->machine->region_alloc(regiontag, regionlength, regionflags); + LOG(("Allocated %X bytes @ %p\n", romdata->region->bytes(), romdata->region->base())); /* clear the region if it's requested */ if (ROMREGION_ISERASE(region)) - memset(romdata->region->base.v, ROMREGION_GETERASEVAL(region), romdata->region->length); + memset(romdata->region->base(), ROMREGION_GETERASEVAL(region), romdata->region->bytes()); /* or if it's sufficiently small (<= 4MB) */ - else if (romdata->region->length <= 0x400000) - memset(romdata->region->base.v, 0, romdata->region->length); + else if (romdata->region->bytes() <= 0x400000) + memset(romdata->region->base(), 0, romdata->region->bytes()); #ifdef MAME_DEBUG /* if we're debugging, fill region with random data to catch errors */ else - fill_random(romdata->machine, romdata->region->base.u8, romdata->region->length); + fill_random(romdata->machine, romdata->region->base(), romdata->region->bytes()); #endif /* now process the entries in the region */ @@ -1418,7 +1406,7 @@ void rom_init(running_machine *machine) machine->romload_data = romdata = auto_alloc_clear(machine, romload_private); /* make sure we get called back on the way out */ - add_exit_callback(machine, rom_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, rom_exit); /* reset the romdata struct */ romdata->machine = machine; @@ -1445,20 +1433,12 @@ void rom_init(running_machine *machine) rom_exit - clean up after ourselves -------------------------------------------------*/ -static void rom_exit(running_machine *machine) +static void rom_exit(running_machine &machine) { - const char *rgntag, *nextrgntag; open_chd *curchd; - /* free the memory allocated for various regions */ - for (rgntag = memory_region_next(machine, NULL); rgntag != NULL; rgntag = nextrgntag) - { - nextrgntag = memory_region_next(machine, rgntag); - memory_region_free(machine, rgntag); - } - /* close all hard drives */ - for (curchd = machine->romload_data->chd_list; curchd != NULL; curchd = curchd->next) + for (curchd = machine.romload_data->chd_list; curchd != NULL; curchd = curchd->next) { if (curchd->diffchd != NULL) chd_close(curchd->diffchd); diff --git a/src/emu/schedule.h b/src/emu/schedule.h index 526218f8f93..bfd0f4acc42 100644 --- a/src/emu/schedule.h +++ b/src/emu/schedule.h @@ -53,9 +53,9 @@ // these must be macros because we are included before the running_machine #define cpuexec_describe_context(mach) (mach)->describe_context() -#define cpuexec_boost_interleave(mach, slice, dur) (mach)->scheduler.boost_interleave(slice, dur) -#define cpuexec_trigger(mach, trigid) (mach)->scheduler.trigger(trigid) -#define cpuexec_triggertime(mach, trigid, dur) (mach)->scheduler.trigger(trigid, dur) +#define cpuexec_boost_interleave(mach, slice, dur) (mach)->scheduler().boost_interleave(slice, dur) +#define cpuexec_trigger(mach, trigid) (mach)->scheduler().trigger(trigid) +#define cpuexec_triggertime(mach, trigid, dur) (mach)->scheduler().trigger(trigid, dur) diff --git a/src/emu/softlist.c b/src/emu/softlist.c index 0e6fac0b533..135ec1ef724 100644 --- a/src/emu/softlist.c +++ b/src/emu/softlist.c @@ -1031,7 +1031,7 @@ bool load_software_part(device_image_interface *image, const char *path, softwar software_list_close( software_list_ptr ); } - software_list_ptr = software_list_open( mame_options(), swlist_name, FALSE, NULL ); + software_list_ptr = software_list_open( image->device().machine->options(), swlist_name, FALSE, NULL ); if ( software_list_ptr ) { @@ -1057,7 +1057,7 @@ bool load_software_part(device_image_interface *image, const char *path, softwar software_list_close( software_list_ptr ); } - software_list_ptr = software_list_open( mame_options(), swlist_name, FALSE, NULL ); + software_list_ptr = software_list_open( image->device().machine->options(), swlist_name, FALSE, NULL ); if ( software_list_ptr ) { @@ -1083,7 +1083,7 @@ bool load_software_part(device_image_interface *image, const char *path, softwar software_list_close( software_list_ptr ); } - software_list_ptr = software_list_open( mame_options(), swlist_name, FALSE, NULL ); + software_list_ptr = software_list_open( image->device().machine->options(), swlist_name, FALSE, NULL ); if ( software_list_ptr ) { @@ -1336,7 +1336,7 @@ struct _software_entry_state /* populate a specific list */ static void ui_mess_menu_populate_software_entries(running_machine *machine, ui_menu *menu, char *list_name) { - software_list *list = software_list_open(mame_options(), list_name, FALSE, NULL); + software_list *list = software_list_open(machine->options(), list_name, FALSE, NULL); if (list) { @@ -1407,7 +1407,7 @@ static void ui_mess_menu_populate_software_list(running_machine *machine, ui_men { if (swlist->list_name[i]) { - software_list *list = software_list_open(mame_options(), swlist->list_name[i], FALSE, NULL); + software_list *list = software_list_open(machine->options(), swlist->list_name[i], FALSE, NULL); if (list) { diff --git a/src/emu/sound.c b/src/emu/sound.c index 49d638e5ff9..9faeb4f3814 100644 --- a/src/emu/sound.c +++ b/src/emu/sound.c @@ -66,9 +66,10 @@ struct _sound_private FUNCTION PROTOTYPES ***************************************************************************/ -static void sound_reset(running_machine *machine); -static void sound_exit(running_machine *machine); -static void sound_pause(running_machine *machine, int pause); +static void sound_reset(running_machine &machine); +static void sound_exit(running_machine &machine); +static void sound_pause(running_machine &machine); +static void sound_resume(running_machine &machine); static void sound_load(running_machine *machine, int config_type, xml_data_node *parentnode); static void sound_save(running_machine *machine, int config_type, xml_data_node *parentnode); static TIMER_CALLBACK( sound_update ); @@ -120,7 +121,7 @@ void sound_init(running_machine *machine) machine->sound_data = global = auto_alloc_clear(machine, sound_private); /* handle -nosound */ - global->nosound_mode = !options_get_bool(mame_options(), OPTION_SOUND); + global->nosound_mode = !options_get_bool(machine->options(), OPTION_SOUND); if (global->nosound_mode) machine->sample_rate = 11025; @@ -141,20 +142,21 @@ void sound_init(running_machine *machine) route_sound(machine); /* open the output WAV file if specified */ - filename = options_get_string(mame_options(), OPTION_WAVWRITE); + filename = options_get_string(machine->options(), OPTION_WAVWRITE); if (filename[0] != 0) global->wavfile = wav_open(filename, machine->sample_rate, 2); /* enable sound by default */ global->enabled = TRUE; global->muted = FALSE; - sound_set_attenuation(machine, options_get_int(mame_options(), OPTION_VOLUME)); + sound_set_attenuation(machine, options_get_int(machine->options(), OPTION_VOLUME)); /* register callbacks */ config_register(machine, "mixer", sound_load, sound_save); - add_pause_callback(machine, sound_pause); - add_reset_callback(machine, sound_reset); - add_exit_callback(machine, sound_exit); + machine->add_notifier(MACHINE_NOTIFY_PAUSE, sound_pause); + machine->add_notifier(MACHINE_NOTIFY_RESUME, sound_resume); + machine->add_notifier(MACHINE_NOTIFY_RESET, sound_reset); + machine->add_notifier(MACHINE_NOTIFY_EXIT, sound_exit); } @@ -162,9 +164,9 @@ void sound_init(running_machine *machine) sound_exit - clean up after ourselves -------------------------------------------------*/ -static void sound_exit(running_machine *machine) +static void sound_exit(running_machine &machine) { - sound_private *global = machine->sound_data; + sound_private *global = machine.sound_data; /* close any open WAV file */ if (global->wavfile != NULL) @@ -228,12 +230,12 @@ static void route_sound(running_machine *machine) sound_reset - reset all sound chips -------------------------------------------------*/ -static void sound_reset(running_machine *machine) +static void sound_reset(running_machine &machine) { device_sound_interface *sound = NULL; /* reset all the sound chips */ - for (bool gotone = machine->m_devicelist.first(sound); gotone; gotone = sound->next(sound)) + for (bool gotone = machine.m_devicelist.first(sound); gotone; gotone = sound->next(sound)) sound->device().reset(); } @@ -242,14 +244,17 @@ static void sound_reset(running_machine *machine) sound_pause - pause sound output -------------------------------------------------*/ -static void sound_pause(running_machine *machine, int pause) +static void sound_pause(running_machine &machine) { - sound_private *global = machine->sound_data; + sound_private *global = machine.sound_data; + global->muted |= 0x02; + osd_set_mastervolume(global->muted ? -32 : global->attenuation); +} - if (pause) - global->muted |= 0x02; - else - global->muted &= ~0x02; +static void sound_resume(running_machine &machine) +{ + sound_private *global = machine.sound_data; + global->muted &= ~0x02; osd_set_mastervolume(global->muted ? -32 : global->attenuation); } diff --git a/src/emu/sound/disc_inp.c b/src/emu/sound/disc_inp.c index 0220db13fba..f05ceddf4f7 100644 --- a/src/emu/sound/disc_inp.c +++ b/src/emu/sound/disc_inp.c @@ -172,7 +172,7 @@ static DISCRETE_RESET(dss_adjustment) double min, max; - context->port = node->info->device->machine->portlist.find((const char *)node->custom); + context->port = node->info->device->machine->m_portlist.find((const char *)node->custom); if (context->port == NULL) fatalerror("DISCRETE_ADJUSTMENT - NODE_%d has invalid tag", NODE_BLOCKINDEX(node)); diff --git a/src/emu/sound/okim6295.c b/src/emu/sound/okim6295.c index 655f1248849..4a7df1c41d2 100644 --- a/src/emu/sound/okim6295.c +++ b/src/emu/sound/okim6295.c @@ -266,7 +266,7 @@ void okim6295_device::set_bank_base(offs_t base) if (m_bank_installed) { m_bank_offs = base; - memory_set_bankptr(&m_machine, tag(), m_region->base.u8 + base); + memory_set_bankptr(&m_machine, tag(), m_region->base() + base); } } diff --git a/src/emu/sound/samples.c b/src/emu/sound/samples.c index 0d64b2d4a02..870fda7eabc 100644 --- a/src/emu/sound/samples.c +++ b/src/emu/sound/samples.c @@ -185,7 +185,7 @@ loaded_samples *readsamples(running_machine *machine, const char *const *samplen int i; /* if the user doesn't want to use samples, bail */ - if (!options_get_bool(mame_options(), OPTION_SAMPLES)) + if (!options_get_bool(machine->options(), OPTION_SAMPLES)) return NULL; if (samplenames == 0 || samplenames[0] == 0) return NULL; diff --git a/src/emu/tilemap.c b/src/emu/tilemap.c index a30f84ad096..ed9e95d0036 100644 --- a/src/emu/tilemap.c +++ b/src/emu/tilemap.c @@ -136,7 +136,7 @@ struct _tilemap_private /* system management helpers */ static tilemap_t *tilemap_create_common(running_machine *machine, void *get_info_object, tile_get_info_func tile_get_info, tilemap_mapper_func mapper, int tilewidth, int tileheight, int cols, int rows); -static void tilemap_exit(running_machine *machine); +static void tilemap_exit(running_machine &machine); static STATE_POSTLOAD( tilemap_postload ); static void tilemap_dispose(tilemap_t *tmap); @@ -297,7 +297,7 @@ void tilemap_init(running_machine *machine) if (screen_width != 0 && screen_height != 0) { machine->priority_bitmap = auto_bitmap_alloc(machine, screen_width, screen_height, BITMAP_FORMAT_INDEXED8); - add_exit_callback(machine, tilemap_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, tilemap_exit); } } @@ -1119,9 +1119,9 @@ TILEMAP_MAPPER( tilemap_scan_cols_flip_xy ) tilemap system -------------------------------------------------*/ -static void tilemap_exit(running_machine *machine) +static void tilemap_exit(running_machine &machine) { - tilemap_private *tilemap_data = machine->tilemap_data; + tilemap_private *tilemap_data = machine.tilemap_data; /* free all the tilemaps in the list */ if (tilemap_data != NULL) diff --git a/src/emu/timer.c b/src/emu/timer.c index 21b2999cc00..0faebed1468 100644 --- a/src/emu/timer.c +++ b/src/emu/timer.c @@ -123,7 +123,7 @@ INLINE attotime get_current_time(running_machine *machine) /* if we're executing as a particular CPU, use its local time as a base */ /* otherwise, return the global base time */ - device_execute_interface *execdevice = machine->scheduler.currently_executing(); + device_execute_interface *execdevice = machine->scheduler().currently_executing(); return (execdevice != NULL) ? execdevice->local_time() : global->exec.basetime; } @@ -704,7 +704,7 @@ void timer_adjust_periodic(emu_timer *which, attotime start_delay, INT32 param, /* if this was inserted as the head, abort the current timeslice and resync */ LOG(("timer_adjust_oneshot %s.%s:%d to expire @ %s\n", which->file, which->func, which->line, attotime_string(which->expire, 9))); if (which == global->activelist) - which->machine->scheduler.abort_timeslice(); + which->machine->scheduler().abort_timeslice(); } diff --git a/src/emu/ui.c b/src/emu/ui.c index 799eb540b89..102b2f5445b 100644 --- a/src/emu/ui.c +++ b/src/emu/ui.c @@ -126,7 +126,7 @@ static UINT8 non_char_keys_down[(ARRAY_LENGTH(non_char_keys) + 7) / 8]; FUNCTION PROTOTYPES ***************************************************************************/ -static void ui_exit(running_machine *machine); +static void ui_exit(running_machine &machine); /* text generators */ static astring &disclaimer_string(running_machine *machine, astring &buffer); @@ -237,7 +237,7 @@ INLINE int is_breakable_char(unicode_char ch) int ui_init(running_machine *machine) { /* make sure we clean up after ourselves */ - add_exit_callback(machine, ui_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, ui_exit); /* allocate the font and messagebox string */ ui_font = render_font_alloc("ui.bdf"); @@ -250,7 +250,7 @@ int ui_init(running_machine *machine) single_step = FALSE; ui_set_handler(handler_messagebox, 0); /* retrieve options */ - ui_use_natural_keyboard = options_get_bool(mame_options(), OPTION_NATURAL_KEYBOARD); + ui_use_natural_keyboard = options_get_bool(machine->options(), OPTION_NATURAL_KEYBOARD); return 0; } @@ -260,7 +260,7 @@ int ui_init(running_machine *machine) ui_exit - clean up ourselves on exit -------------------------------------------------*/ -static void ui_exit(running_machine *machine) +static void ui_exit(running_machine &machine) { /* free the font */ if (ui_font != NULL) @@ -277,8 +277,8 @@ static void ui_exit(running_machine *machine) int ui_display_startup_screens(running_machine *machine, int first_time, int show_disclaimer) { const int maxstate = 3; - int str = options_get_int(mame_options(), OPTION_SECONDS_TO_RUN); - int show_gameinfo = !options_get_bool(mame_options(), OPTION_SKIP_GAMEINFO); + int str = options_get_int(machine->options(), OPTION_SECONDS_TO_RUN); + int show_gameinfo = !options_get_bool(machine->options(), OPTION_SKIP_GAMEINFO); int show_warnings = TRUE; int state; @@ -292,7 +292,7 @@ int ui_display_startup_screens(running_machine *machine, int first_time, int sho /* loop over states */ ui_set_handler(handler_ingame, 0); - for (state = 0; state < maxstate && !mame_is_scheduled_event_pending(machine) && !ui_menu_is_force_game_select(); state++) + for (state = 0; state < maxstate && !machine->scheduled_event_pending() && !ui_menu_is_force_game_select(); state++) { /* default to standard colors */ messagebox_backcolor = UI_BACKGROUND_COLOR; @@ -327,7 +327,7 @@ int ui_display_startup_screens(running_machine *machine, int first_time, int sho while (input_code_poll_switches(machine, FALSE) != INPUT_CODE_INVALID) ; /* loop while we have a handler */ - while (ui_handler_callback != handler_ingame && !mame_is_scheduled_event_pending(machine) && !ui_menu_is_force_game_select()) + while (ui_handler_callback != handler_ingame && !machine->scheduled_event_pending() && !ui_menu_is_force_game_select()) video_frame_update(machine, FALSE); /* clear the handler and force an update */ @@ -377,9 +377,9 @@ void ui_update_and_render(running_machine *machine, render_container *container) render_container_empty(container); /* if we're paused, dim the whole screen */ - if (mame_get_phase(machine) >= MAME_PHASE_RESET && (single_step || mame_is_paused(machine))) + if (machine->phase() >= MACHINE_PHASE_RESET && (single_step || machine->paused())) { - int alpha = (1.0f - options_get_float(mame_options(), OPTION_PAUSE_BRIGHTNESS)) * 255.0f; + int alpha = (1.0f - options_get_float(machine->options(), OPTION_PAUSE_BRIGHTNESS)) * 255.0f; if (ui_menu_is_force_game_select()) alpha = 255; if (alpha > 255) @@ -1139,7 +1139,7 @@ static UINT32 handler_messagebox_ok(running_machine *machine, render_container * /* if the user cancels, exit out completely */ else if (ui_input_pressed(machine, IPT_UI_CANCEL)) { - mame_schedule_exit(machine); + machine->schedule_exit(); state = UI_HANDLER_CANCEL; } @@ -1161,7 +1161,7 @@ static UINT32 handler_messagebox_anykey(running_machine *machine, render_contain /* if the user cancels, exit out completely */ if (ui_input_pressed(machine, IPT_UI_CANCEL)) { - mame_schedule_exit(machine); + machine->schedule_exit(); state = UI_HANDLER_CANCEL; } @@ -1270,7 +1270,7 @@ void ui_image_handler_ingame(running_machine *machine) device_image_interface *image = NULL; /* run display routine for devices */ - if (mame_get_phase(machine) == MAME_PHASE_RUNNING) + if (machine->phase() == MACHINE_PHASE_RUNNING) { for (bool gotone = machine->m_devicelist.first(image); gotone; gotone = image->next(image)) { @@ -1287,7 +1287,7 @@ void ui_image_handler_ingame(running_machine *machine) static UINT32 handler_ingame(running_machine *machine, render_container *container, UINT32 state) { - int is_paused = mame_is_paused(machine); + bool is_paused = machine->paused(); /* first draw the FPS counter */ if (showfps || osd_ticks() < showfps_end) @@ -1309,7 +1309,7 @@ static UINT32 handler_ingame(running_machine *machine, render_container *contain /* if we're single-stepping, pause now */ if (single_step) { - mame_pause(machine, TRUE); + machine->pause(); single_step = FALSE; } @@ -1350,7 +1350,7 @@ static UINT32 handler_ingame(running_machine *machine, render_container *contain } /* is the natural keyboard enabled? */ - if (ui_get_use_natural_keyboard(machine) && (mame_get_phase(machine) == MAME_PHASE_RUNNING)) + if (ui_get_use_natural_keyboard(machine) && (machine->phase() == MACHINE_PHASE_RUNNING)) process_natural_keyboard(machine); if (!ui_disabled) @@ -1366,7 +1366,7 @@ static UINT32 handler_ingame(running_machine *machine, render_container *contain /* if the user pressed ESC, stop the emulation (except in MESS with newui, where ESC toggles the menubar) */ if (ui_input_pressed(machine, IPT_UI_CANCEL) && !ui_use_newui()) - mame_schedule_exit(machine); + machine->schedule_exit(); /* turn on menus if requested */ if (ui_input_pressed(machine, IPT_UI_CONFIGURE) && !ui_use_newui()) @@ -1378,29 +1378,29 @@ static UINT32 handler_ingame(running_machine *machine, render_container *contain /* handle a reset request */ if (ui_input_pressed(machine, IPT_UI_RESET_MACHINE)) - mame_schedule_hard_reset(machine); + machine->schedule_hard_reset(); if (ui_input_pressed(machine, IPT_UI_SOFT_RESET)) - mame_schedule_soft_reset(machine); + machine->schedule_soft_reset(); /* handle a request to display graphics/palette */ if (ui_input_pressed(machine, IPT_UI_SHOW_GFX)) { if (!is_paused) - mame_pause(machine, TRUE); + machine->pause(); return ui_set_handler(ui_gfx_ui_handler, is_paused); } /* handle a save state request */ if (ui_input_pressed(machine, IPT_UI_SAVE_STATE)) { - mame_pause(machine, TRUE); + machine->pause(); return ui_set_handler(handler_load_save, LOADSAVE_SAVE); } /* handle a load state request */ if (ui_input_pressed(machine, IPT_UI_LOAD_STATE)) { - mame_pause(machine, TRUE); + machine->pause(); return ui_set_handler(handler_load_save, LOADSAVE_LOAD); } @@ -1415,10 +1415,12 @@ static UINT32 handler_ingame(running_machine *machine, render_container *contain if (is_paused && (input_code_pressed(machine, KEYCODE_LSHIFT) || input_code_pressed(machine, KEYCODE_RSHIFT))) { single_step = TRUE; - mame_pause(machine, FALSE); + machine->resume(); } + else if (machine->paused()) + machine->resume(); else - mame_pause(machine, !mame_is_paused(machine)); + machine->pause(); } /* handle a toggle cheats request */ @@ -1522,7 +1524,7 @@ static UINT32 handler_load_save(running_machine *machine, render_container *cont popmessage("Load cancelled"); /* reset the state */ - mame_pause(machine, FALSE); + machine->resume(); return UI_HANDLER_CANCEL; } @@ -1546,16 +1548,16 @@ static UINT32 handler_load_save(running_machine *machine, render_container *cont if (state == LOADSAVE_SAVE) { popmessage("Save to position %c", file); - mame_schedule_save(machine, filename); + machine->schedule_save(filename); } else { popmessage("Load from position %c", file); - mame_schedule_load(machine, filename); + machine->schedule_load(filename); } /* remove the pause and reset the state */ - mame_pause(machine, FALSE); + machine->resume(); return UI_HANDLER_CANCEL; } @@ -1631,7 +1633,7 @@ static slider_state *slider_init(running_machine *machine) } /* add analog adjusters */ - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) for (field = port->fieldlist; field != NULL; field = field->next) if (field->type == IPT_ADJUSTER) { @@ -1641,7 +1643,7 @@ static slider_state *slider_init(running_machine *machine) } /* add CPU overclocking (cheat only) */ - if (options_get_bool(mame_options(), OPTION_CHEAT)) + if (options_get_bool(machine->options(), OPTION_CHEAT)) { for (device = machine->firstcpu; device != NULL; device = cpu_next(device)) { @@ -1662,7 +1664,7 @@ static slider_state *slider_init(running_machine *machine) void *param = (void *)screen; /* add refresh rate tweaker */ - if (options_get_bool(mame_options(), OPTION_CHEAT)) + if (options_get_bool(machine->options(), OPTION_CHEAT)) { string.printf("%s Refresh Rate", slider_get_screen_desc(*screen)); *tailptr = slider_alloc(machine, string, -10000, 0, 10000, 1000, slider_refresh, param); @@ -1735,7 +1737,7 @@ static slider_state *slider_init(running_machine *machine) #ifdef MAME_DEBUG /* add crosshair adjusters */ - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) for (field = port->fieldlist; field != NULL; field = field->next) if (field->crossaxis != CROSSHAIR_AXIS_NONE && field->player == 0) { @@ -2219,6 +2221,6 @@ int ui_get_use_natural_keyboard(running_machine *machine) void ui_set_use_natural_keyboard(running_machine *machine, int use_natural_keyboard) { ui_use_natural_keyboard = use_natural_keyboard; - options_set_bool(mame_options(), OPTION_NATURAL_KEYBOARD, use_natural_keyboard, OPTION_PRIORITY_CMDLINE); + options_set_bool(machine->options(), OPTION_NATURAL_KEYBOARD, use_natural_keyboard, OPTION_PRIORITY_CMDLINE); } diff --git a/src/emu/uigfx.c b/src/emu/uigfx.c index cb3536a4899..3943d130b19 100644 --- a/src/emu/uigfx.c +++ b/src/emu/uigfx.c @@ -76,7 +76,7 @@ static ui_gfx_state ui_gfx; FUNCTION PROTOTYPES ***************************************************************************/ -static void ui_gfx_exit(running_machine *machine); +static void ui_gfx_exit(running_machine &machine); /* palette handling */ static void palette_handle_keys(running_machine *machine, ui_gfx_state *state); @@ -109,7 +109,7 @@ void ui_gfx_init(running_machine *machine) int gfx; /* make sure we clean up after ourselves */ - add_exit_callback(machine, ui_gfx_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, ui_gfx_exit); /* initialize our global state */ memset(state, 0, sizeof(*state)); @@ -133,7 +133,7 @@ void ui_gfx_init(running_machine *machine) ui_gfx_exit - clean up after ourselves -------------------------------------------------*/ -static void ui_gfx_exit(running_machine *machine) +static void ui_gfx_exit(running_machine &machine) { /* free the texture */ if (ui_gfx.texture != NULL) @@ -159,7 +159,7 @@ UINT32 ui_gfx_ui_handler(running_machine *machine, render_container *container, goto cancel; /* if we're not paused, mark the bitmap dirty */ - if (!mame_is_paused(machine)) + if (!machine->paused()) state->bitmap_dirty = TRUE; /* switch off the state to display something */ @@ -208,7 +208,12 @@ again: } if (ui_input_pressed(machine, IPT_UI_PAUSE)) - mame_pause(machine, !mame_is_paused(machine)); + { + if (machine->paused()) + machine->resume(); + else + machine->pause(); + } if (ui_input_pressed(machine, IPT_UI_CANCEL) || ui_input_pressed(machine, IPT_UI_SHOW_GFX)) goto cancel; @@ -217,7 +222,7 @@ again: cancel: if (!uistate) - mame_pause(machine, FALSE); + machine->resume(); state->bitmap_dirty = TRUE; return UI_HANDLER_CANCEL; } diff --git a/src/emu/uiinput.c b/src/emu/uiinput.c index 22c232c4a16..1d6c1e273cb 100644 --- a/src/emu/uiinput.c +++ b/src/emu/uiinput.c @@ -80,7 +80,7 @@ void ui_input_init(running_machine *machine) machine->ui_input_data->current_mouse_y = -1; /* add a frame callback to poll inputs */ - add_frame_callback(machine, ui_input_frame_update); + machine->add_notifier(MACHINE_NOTIFY_FRAME, ui_input_frame_update); } @@ -95,15 +95,15 @@ void ui_input_init(running_machine *machine) corresponding IPT_UI_* events -------------------------------------------------*/ -void ui_input_frame_update(running_machine *machine) +void ui_input_frame_update(running_machine &machine) { - ui_input_private *uidata = machine->ui_input_data; + ui_input_private *uidata = machine.ui_input_data; int code; /* update the state of all the UI keys */ for (code = __ipt_ui_start; code <= __ipt_ui_end; code++) { - int pressed = input_seq_pressed(machine, input_type_seq(machine, code, 0, SEQ_TYPE_STANDARD)); + int pressed = input_seq_pressed(&machine, input_type_seq(&machine, code, 0, SEQ_TYPE_STANDARD)); if (!pressed || uidata->seqpressed[code] != SEQ_PRESSED_RESET) uidata->seqpressed[code] = pressed; } diff --git a/src/emu/uiinput.h b/src/emu/uiinput.h index e11e106b396..dc0d3382b28 100644 --- a/src/emu/uiinput.h +++ b/src/emu/uiinput.h @@ -61,7 +61,7 @@ void ui_input_init(running_machine *machine); /* ----- event handling ----- */ -void ui_input_frame_update(running_machine *machine); +void ui_input_frame_update(running_machine &machine); /* pushes a single event onto the queue */ int ui_input_push_event(running_machine *machine, ui_event event); diff --git a/src/emu/uimenu.c b/src/emu/uimenu.c index 997c7fc0121..7a6ecf0ac12 100644 --- a/src/emu/uimenu.c +++ b/src/emu/uimenu.c @@ -247,7 +247,7 @@ static const char exittext[] = "Exit"; FUNCTION PROTOTYPES ***************************************************************************/ -static void ui_menu_exit(running_machine *machine); +static void ui_menu_exit(running_machine &machine); /* internal menu processing */ static void ui_menu_draw(running_machine *machine, ui_menu *menu, int customonly); @@ -401,7 +401,7 @@ void ui_menu_init(running_machine *machine) arrow_texture = render_texture_alloc(menu_render_triangle, NULL); /* add an exit callback to free memory */ - add_exit_callback(machine, ui_menu_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, ui_menu_exit); } @@ -409,11 +409,11 @@ void ui_menu_init(running_machine *machine) ui_menu_exit - clean up after ourselves -------------------------------------------------*/ -static void ui_menu_exit(running_machine *machine) +static void ui_menu_exit(running_machine &machine) { /* free menus */ - ui_menu_stack_reset(machine); - ui_menu_clear_free_list(machine); + ui_menu_stack_reset(&machine); + ui_menu_clear_free_list(&machine); /* free textures */ render_texture_free(hilight_texture); @@ -1230,7 +1230,12 @@ static void ui_menu_handle_keys(ui_menu *menu, UINT32 flags) /* pause enables/disables pause */ if (!ignorepause && exclusive_input_pressed(menu, IPT_UI_PAUSE, 0)) - mame_pause(menu->machine, !mame_is_paused(menu->machine)); + { + if (menu->machine->paused()) + menu->machine->resume(); + else + menu->machine->pause(); + } /* handle a toggle cheats request */ if (ui_input_pressed_repeat(menu->machine, IPT_UI_TOGGLE_CHEAT, 0)) @@ -1398,7 +1403,7 @@ UINT32 ui_slider_ui_handler(running_machine *machine, render_container *containe void ui_menu_force_game_select(running_machine *machine, render_container *container) { - char *gamename = (char *)options_get_string(mame_options(), OPTION_GAMENAME); + char *gamename = (char *)options_get_string(machine->options(), OPTION_GAMENAME); /* reset the menu stack */ ui_menu_stack_reset(machine); @@ -1411,7 +1416,7 @@ void ui_menu_force_game_select(running_machine *machine, render_container *conta ui_show_menu(); /* make sure MAME is paused */ - mame_pause(machine, TRUE); + machine->pause(); } @@ -1498,7 +1503,7 @@ static void menu_main_populate(running_machine *machine, ui_menu *menu, void *st int has_dips = FALSE; /* scan the input port array to see what options we need to enable */ - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) for (field = port->fieldlist; field != NULL; field = field->next) { if (field->type == IPT_DIPSWITCH) @@ -1563,7 +1568,7 @@ static void menu_main_populate(running_machine *machine, ui_menu *menu, void *st ui_menu_item_append(menu, "Crosshair Options", NULL, 0, (void *)menu_crosshair); /* add cheat menu */ - if (options_get_bool(mame_options(), OPTION_CHEAT) && cheat_get_next_menu_entry(machine, NULL, NULL, NULL, NULL) != NULL) + if (options_get_bool(machine->options(), OPTION_CHEAT) && cheat_get_next_menu_entry(machine, NULL, NULL, NULL, NULL) != NULL) ui_menu_item_append(menu, "Cheat", NULL, 0, (void *)menu_cheat); /* add memory card menu */ @@ -1712,7 +1717,7 @@ static void menu_input_specific_populate(running_machine *machine, ui_menu *menu suborder[SEQ_TYPE_INCREMENT] = 2; /* iterate over the input ports and add menu items */ - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) for (field = port->fieldlist; field != NULL; field = field->next) { const char *name = input_field_name(field); @@ -2066,7 +2071,7 @@ static void menu_settings_populate(running_machine *machine, ui_menu *menu, sett diplist_tailptr = &menustate->diplist; /* loop over input ports and set up the current values */ - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) for (field = port->fieldlist; field != NULL; field = field->next) if (field->type == type && input_condition_true(machine, &field->condition)) { @@ -2320,7 +2325,7 @@ static void menu_analog_populate(running_machine *machine, ui_menu *menu) astring text; /* loop over input ports and add the items */ - for (port = machine->portlist.first(); port != NULL; port = port->next()) + for (port = machine->m_portlist.first(); port != NULL; port = port->next()) for (field = port->fieldlist; field != NULL; field = field->next) if (input_type_is_analog(field->type)) { @@ -2674,7 +2679,7 @@ static void menu_memory_card(running_machine *machine, ui_menu *menu, void *para /* handle card ejecting */ case MEMCARD_ITEM_EJECT: - memcard_eject(menu->machine); + memcard_eject(*menu->machine); popmessage("Memory card ejected"); break; @@ -3278,7 +3283,7 @@ static void menu_crosshair_populate(running_machine *machine, ui_menu *menu) /* search for crosshair graphics */ /* open a path to the crosshairs */ - path = mame_openpath(mame_options(), OPTION_CROSSHAIRPATH); + path = mame_openpath(machine->options(), OPTION_CROSSHAIRPATH); if (path != NULL) { const osd_directory_entry *dir; @@ -3387,7 +3392,7 @@ static void menu_crosshair_populate(running_machine *machine, ui_menu *menu) static void menu_quit_game(running_machine *machine, ui_menu *menu, void *parameter, void *state) { /* request a reset */ - mame_schedule_exit(machine); + machine->schedule_exit(); /* reset the menu stack */ ui_menu_stack_reset(machine); @@ -3445,7 +3450,7 @@ static void menu_select_game(running_machine *machine, ui_menu *menu, void *para int audit_result; /* audit the game first to see if we're going to work */ - audit_records = audit_images(mame_options(), driver, AUDIT_VALIDATE_FAST, &audit); + audit_records = audit_images(menu->machine->options(), driver, AUDIT_VALIDATE_FAST, &audit); audit_result = audit_summary(driver, audit_records, audit, FALSE); if (audit_records > 0) global_free(audit); @@ -3453,7 +3458,7 @@ static void menu_select_game(running_machine *machine, ui_menu *menu, void *para /* if everything looks good, schedule the new driver */ if (audit_result == CORRECT || audit_result == BEST_AVAILABLE) { - mame_schedule_new_driver(machine, driver); + machine->schedule_new_driver(*driver); ui_menu_stack_reset(machine); } @@ -3598,7 +3603,7 @@ static void menu_select_game_build_driver_list(ui_menu *menu, select_game_state memset(found, 0, (driver_count + 7) / 8); /* open a path to the ROMs and find them in the array */ - path = mame_openpath(mame_options(), OPTION_ROMPATH); + path = mame_openpath(menu->machine->options(), OPTION_ROMPATH); if (path != NULL) { const osd_directory_entry *dir; diff --git a/src/emu/video.c b/src/emu/video.c index 8e38286e809..918db7259e2 100644 --- a/src/emu/video.c +++ b/src/emu/video.c @@ -162,7 +162,7 @@ static const UINT8 skiptable[FRAMESKIP_LEVELS][FRAMESKIP_LEVELS] = ***************************************************************************/ /* core implementation */ -static void video_exit(running_machine *machine); +static void video_exit(running_machine &machine); static void init_buffered_spriteram(running_machine *machine); /* global rendering */ @@ -202,7 +202,7 @@ static void rgb888_draw_primitives(const render_primitive *primlist, void *dstda INLINE int effective_autoframeskip(running_machine *machine) { /* if we're fast forwarding or paused, autoframeskip is disabled */ - if (global.fastforward || mame_is_paused(machine)) + if (global.fastforward || machine->paused()) return FALSE; /* otherwise, it's up to the user */ @@ -236,7 +236,7 @@ INLINE int effective_frameskip(void) INLINE int effective_throttle(running_machine *machine) { /* if we're paused, or if the UI is active, we always throttle */ - if (mame_is_paused(machine) || ui_is_menu_active()) + if (machine->paused() || ui_is_menu_active()) return TRUE; /* if we're fast forwarding, we don't throttle */ @@ -278,7 +278,7 @@ void video_init(running_machine *machine) assert(machine->config != NULL); /* request a callback upon exiting */ - add_exit_callback(machine, video_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, video_exit); /* reset our global state */ memset(&global, 0, sizeof(global)); @@ -287,10 +287,10 @@ void video_init(running_machine *machine) /* extract initial execution state from global configuration settings */ global.speed = original_speed_setting(); update_refresh_speed(machine); - global.throttle = options_get_bool(mame_options(), OPTION_THROTTLE); - global.auto_frameskip = options_get_bool(mame_options(), OPTION_AUTOFRAMESKIP); - global.frameskip_level = options_get_int(mame_options(), OPTION_FRAMESKIP); - global.seconds_to_run = options_get_int(mame_options(), OPTION_SECONDS_TO_RUN); + global.throttle = options_get_bool(machine->options(), OPTION_THROTTLE); + global.auto_frameskip = options_get_bool(machine->options(), OPTION_AUTOFRAMESKIP); + global.frameskip_level = options_get_int(machine->options(), OPTION_FRAMESKIP); + global.seconds_to_run = options_get_int(machine->options(), OPTION_SECONDS_TO_RUN); /* create spriteram buffers if necessary */ if (machine->config->m_video_attributes & VIDEO_BUFFERS_SPRITERAM) @@ -301,7 +301,7 @@ void video_init(running_machine *machine) (*machine->config->m_init_palette)(machine, memory_region(machine, "proms")); /* create a render target for snapshots */ - viewname = options_get_string(mame_options(), OPTION_SNAPVIEW); + viewname = options_get_string(machine->options(), OPTION_SNAPVIEW); global.snap_native = (machine->primary_screen != NULL && (viewname[0] == 0 || strcmp(viewname, "native") == 0)); /* the native target is hard-coded to our internal layout and has all options disabled */ @@ -322,15 +322,15 @@ void video_init(running_machine *machine) } /* extract snap resolution if present */ - if (sscanf(options_get_string(mame_options(), OPTION_SNAPSIZE), "%dx%d", &global.snap_width, &global.snap_height) != 2) + if (sscanf(options_get_string(machine->options(), OPTION_SNAPSIZE), "%dx%d", &global.snap_width, &global.snap_height) != 2) global.snap_width = global.snap_height = 0; /* start recording movie if specified */ - filename = options_get_string(mame_options(), OPTION_MNGWRITE); + filename = options_get_string(machine->options(), OPTION_MNGWRITE); if (filename[0] != 0) video_mng_begin_recording(machine, filename); - filename = options_get_string(mame_options(), OPTION_AVIWRITE); + filename = options_get_string(machine->options(), OPTION_AVIWRITE); if (filename[0] != 0) video_avi_begin_recording(machine, filename); @@ -347,21 +347,17 @@ void video_init(running_machine *machine) video_exit - close down the video system -------------------------------------------------*/ -static void video_exit(running_machine *machine) +static void video_exit(running_machine &machine) { int i; - /* validate */ - assert(machine != NULL); - assert(machine->config != NULL); - /* stop recording any movie */ - video_mng_end_recording(machine); - video_avi_end_recording(machine); + video_mng_end_recording(&machine); + video_avi_end_recording(&machine); /* free all the graphics elements */ for (i = 0; i < MAX_GFX_ELEMENTS; i++) - gfx_element_free(machine->gfx[i]); + gfx_element_free(machine.gfx[i]); /* free the snapshot target */ if (global.snap_target != NULL) @@ -434,14 +430,14 @@ void video_frame_update(running_machine *machine, int debug) { attotime current_time = timer_get_time(machine); int skipped_it = global.skipping_this_frame; - int phase = mame_get_phase(machine); + int phase = machine->phase(); /* validate */ assert(machine != NULL); assert(machine->config != NULL); /* only render sound and video if we're in the running phase */ - if (phase == MAME_PHASE_RUNNING && (!mame_is_paused(machine) || options_get_bool(mame_options(), OPTION_UPDATEINPAUSE))) + if (phase == MACHINE_PHASE_RUNNING && (!machine->paused() || options_get_bool(machine->options(), OPTION_UPDATEINPAUSE))) { int anything_changed = finish_screen_updates(machine); @@ -471,7 +467,7 @@ void video_frame_update(running_machine *machine, int debug) /* perform tasks for this frame */ if (!debug) - mame_frame_update(machine); + machine->call_notifiers(MACHINE_NOTIFY_FRAME); /* update frameskipping */ if (!debug) @@ -482,10 +478,10 @@ void video_frame_update(running_machine *machine, int debug) recompute_speed(machine, current_time); /* call the end-of-frame callback */ - if (phase == MAME_PHASE_RUNNING) + if (phase == MACHINE_PHASE_RUNNING) { /* reset partial updates if we're paused or if the debugger is active */ - if (machine->primary_screen != NULL && (mame_is_paused(machine) || debug || debugger_within_instruction_hook(machine))) + if (machine->primary_screen != NULL && (machine->paused() || debug || debugger_within_instruction_hook(machine))) machine->primary_screen->scanline0_callback(); /* otherwise, call the video EOF callback */ @@ -518,7 +514,7 @@ static int finish_screen_updates(running_machine *machine) anything_changed = true; /* update our movie recording and burn-in state */ - if (!mame_is_paused(machine)) + if (!machine->paused()) { video_mng_record_frame(machine); video_avi_record_frame(machine); @@ -581,7 +577,7 @@ void video_set_speed_factor(int speed) const char *video_get_speed_text(running_machine *machine) { - int paused = mame_is_paused(machine); + bool paused = machine->paused(); static char buffer[1024]; char *dest = buffer; @@ -787,7 +783,7 @@ static void update_throttle(running_machine *machine, attotime emutime) and explicitly reset our tracked real and emulated timers to that value ... this means we pretend that the last update was exactly 1/60th of a second ago, and was in sync in both real and emulated time */ - if (mame_is_paused(machine)) + if (machine->paused()) { global.throttle_emutime = attotime_sub_attoseconds(emutime, ATTOSECONDS_PER_SECOND / PAUSED_REFRESH_RATE); global.throttle_realtime = global.throttle_emutime; @@ -880,9 +876,9 @@ static osd_ticks_t throttle_until_ticks(running_machine *machine, osd_ticks_t ta /* we're allowed to sleep via the OSD code only if we're configured to do so and we're not frameskipping due to autoframeskip, or if we're paused */ - if (options_get_bool(mame_options(), OPTION_SLEEP) && (!effective_autoframeskip(machine) || effective_frameskip() == 0)) + if (options_get_bool(machine->options(), OPTION_SLEEP) && (!effective_autoframeskip(machine) || effective_frameskip() == 0)) allowed_to_sleep = TRUE; - if (mame_is_paused(machine)) + if (machine->paused()) allowed_to_sleep = TRUE; /* loop until we reach our target */ @@ -989,7 +985,7 @@ static void update_frameskip(running_machine *machine) static void update_refresh_speed(running_machine *machine) { /* only do this if the refreshspeed option is used */ - if (options_get_bool(mame_options(), OPTION_REFRESHSPEED)) + if (options_get_bool(machine->options(), OPTION_REFRESHSPEED)) { float minrefresh = render_get_max_update_rate(); if (minrefresh != 0) @@ -1035,7 +1031,7 @@ static void recompute_speed(running_machine *machine, attotime emutime) attoseconds_t delta_emutime; /* if we don't have a starting time yet, or if we're paused, reset our starting point */ - if (global.speed_last_realtime == 0 || mame_is_paused(machine)) + if (global.speed_last_realtime == 0 || machine->paused()) { global.speed_last_realtime = osd_ticks(); global.speed_last_emutime = emutime; @@ -1080,7 +1076,7 @@ static void recompute_speed(running_machine *machine, attotime emutime) { if (machine->primary_screen != NULL) { - astring fname(machine->basename, PATH_SEPARATOR "final.png"); + astring fname(machine->basename(), PATH_SEPARATOR "final.png"); file_error filerr; mame_file *file; @@ -1094,7 +1090,7 @@ static void recompute_speed(running_machine *machine, attotime emutime) } /* schedule our demise */ - mame_schedule_exit(machine); + machine->schedule_exit(); } } @@ -1232,7 +1228,7 @@ static void create_snapshot_bitmap(device_t *screen) static file_error mame_fopen_next(running_machine *machine, const char *pathoption, const char *extension, mame_file **file) { - const char *snapname = options_get_string(mame_options(), OPTION_SNAPNAME); + const char *snapname = options_get_string(machine->options(), OPTION_SNAPNAME); file_error filerr; astring snapstr; astring fname; @@ -1251,7 +1247,7 @@ static file_error mame_fopen_next(running_machine *machine, const char *pathopti /* substitute path and gamename up front */ snapstr.replace(0, "/", PATH_SEPARATOR); - snapstr.replace(0, "%g", machine->basename); + snapstr.replace(0, "%g", machine->basename()); /* determine if the template has an index; if not, we always use the same name */ if (snapstr.find(0, "%i") == -1) @@ -1896,10 +1892,10 @@ void screen_device::device_start() timer_adjust_oneshot(m_scanline_timer, time_until_pos(0), 0); // create burn-in bitmap - if (options_get_int(mame_options(), OPTION_BURNIN) > 0) + if (options_get_int(machine->options(), OPTION_BURNIN) > 0) { int width, height; - if (sscanf(options_get_string(mame_options(), OPTION_SNAPSIZE), "%dx%d", &width, &height) != 2 || width == 0 || height == 0) + if (sscanf(options_get_string(machine->options(), OPTION_SNAPSIZE), "%dx%d", &width, &height) != 2 || width == 0 || height == 0) width = height = 300; m_burnin = auto_alloc(machine, bitmap_t(width, height, BITMAP_FORMAT_INDEXED64)); if (m_burnin == NULL) @@ -2523,7 +2519,7 @@ void screen_device::finalize_burnin() // compute the name and create the file astring fname; - fname.printf("%s" PATH_SEPARATOR "burnin-%s.png", machine->basename, tag()); + fname.printf("%s" PATH_SEPARATOR "burnin-%s.png", machine->basename(), tag()); mame_file *file; file_error filerr = mame_fopen(SEARCHPATH_SCREENSHOT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file); if (filerr == FILERR_NONE) diff --git a/src/emu/video/vector.c b/src/emu/video/vector.c index 1dfcff0c6c0..2a03e3ac59d 100644 --- a/src/emu/video/vector.c +++ b/src/emu/video/vector.c @@ -178,10 +178,10 @@ float vector_get_beam(void) VIDEO_START( vector ) { - beam_width = options_get_float(mame_options(), OPTION_BEAM); + beam_width = options_get_float(machine->options(), OPTION_BEAM); /* Grab the settings for this session */ - vector_set_flicker(options_get_float(mame_options(), OPTION_FLICKER)); + vector_set_flicker(options_get_float(machine->options(), OPTION_FLICKER)); vector_index = 0; @@ -259,7 +259,7 @@ void vector_clear_list (void) VIDEO_UPDATE( vector ) { - UINT32 flags = PRIMFLAG_ANTIALIAS(options_get_bool(mame_options(), OPTION_ANTIALIAS) ? 1 : 0) | PRIMFLAG_BLENDMODE(BLENDMODE_ADD); + UINT32 flags = PRIMFLAG_ANTIALIAS(options_get_bool(screen->machine->options(), OPTION_ANTIALIAS) ? 1 : 0) | PRIMFLAG_BLENDMODE(BLENDMODE_ADD); const rectangle &visarea = screen->visible_area(); float xscale = 1.0f / (65536 * (visarea.max_x - visarea.min_x)); float yscale = 1.0f / (65536 * (visarea.max_y - visarea.min_y)); diff --git a/src/emu/watchdog.c b/src/emu/watchdog.c index e52282cefef..8f8c63d819a 100644 --- a/src/emu/watchdog.c +++ b/src/emu/watchdog.c @@ -27,7 +27,7 @@ static emu_timer *watchdog_timer; FUNCTION PROTOTYPES ***************************************************************************/ -static void watchdog_internal_reset(running_machine *machine); +static void watchdog_internal_reset(running_machine &machine); static TIMER_CALLBACK( watchdog_callback ); @@ -41,7 +41,7 @@ void watchdog_init(running_machine *machine) /* allocate a timer for the watchdog */ watchdog_timer = timer_alloc(machine, watchdog_callback, NULL); - add_reset_callback(machine, watchdog_internal_reset); + machine->add_notifier(MACHINE_NOTIFY_RESET, watchdog_internal_reset); /* save some stuff in the default tag */ state_save_register_item(machine, "watchdog", NULL, 0, watchdog_enabled); @@ -54,11 +54,11 @@ void watchdog_init(running_machine *machine) system -------------------------------------------------*/ -static void watchdog_internal_reset(running_machine *machine) +static void watchdog_internal_reset(running_machine &machine) { /* set up the watchdog timer; only start off enabled if explicitly configured */ - watchdog_enabled = (machine->config->m_watchdog_vblank_count != 0 || attotime_compare(machine->config->m_watchdog_time, attotime_zero) != 0); - watchdog_reset(machine); + watchdog_enabled = (machine.m_config.m_watchdog_vblank_count != 0 || attotime_compare(machine.m_config.m_watchdog_time, attotime_zero) != 0); + watchdog_reset(&machine); watchdog_enabled = TRUE; } @@ -75,7 +75,7 @@ static TIMER_CALLBACK( watchdog_callback ) popmessage("Reset caused by the watchdog!!!\n"); #endif - mame_schedule_soft_reset(machine); + machine->schedule_soft_reset(); } diff --git a/src/ldplayer/ldplayer.c b/src/ldplayer/ldplayer.c index 605544e5866..eebd49f558f 100644 --- a/src/ldplayer/ldplayer.c +++ b/src/ldplayer/ldplayer.c @@ -82,7 +82,7 @@ static void (*execute_command)(running_device *laserdisc, int command); * *************************************/ -static void free_string(running_machine *machine) +static void free_string(running_machine &machine) { } @@ -94,7 +94,7 @@ static chd_file *get_disc(running_device *device) mame_path *path; /* open a path to the ROMs and find the first CHD file */ - path = mame_openpath(mame_options(), OPTION_ROMPATH); + path = mame_openpath(device->machine->options(), OPTION_ROMPATH); if (path != NULL) { const osd_directory_entry *dir; @@ -124,7 +124,7 @@ static chd_file *get_disc(running_device *device) { set_disk_handle(device->machine, "laserdisc", image_file, image_chd); filename.cpy(dir->name); - add_exit_callback(device->machine, free_string); + device->machine->add_notifier(MACHINE_NOTIFY_EXIT, free_string); break; } diff --git a/src/mame/drivers/bfm_sc1.c b/src/mame/drivers/bfm_sc1.c index 8e545a092d5..1b1c8160d69 100644 --- a/src/mame/drivers/bfm_sc1.c +++ b/src/mame/drivers/bfm_sc1.c @@ -169,7 +169,7 @@ static INTERRUPT_GEN( timer_irq ) watchdog_cnt++; if ( watchdog_cnt > 2 ) // this is a hack, i don't know what the watchdog timeout is, 3 IRQ's works fine { // reset board - mame_schedule_soft_reset(device->machine);// reset entire machine. CPU 0 should be enough, but that doesn't seem to work !! + device->machine->schedule_soft_reset();// reset entire machine. CPU 0 should be enough, but that doesn't seem to work !! return; } } diff --git a/src/mame/drivers/bfm_sc2.c b/src/mame/drivers/bfm_sc2.c index 6292fcdce7b..4191fca8cfd 100644 --- a/src/mame/drivers/bfm_sc2.c +++ b/src/mame/drivers/bfm_sc2.c @@ -506,7 +506,7 @@ static INTERRUPT_GEN( timer_irq ) watchdog_cnt++; if ( watchdog_cnt > 2 ) // this is a hack, i don't know what the watchdog timeout is, 3 IRQ's works fine { // reset board - mame_schedule_soft_reset(device->machine); // reset entire machine. CPU 0 should be enough, but that doesn't seem to work !! + device->machine->schedule_soft_reset(); // reset entire machine. CPU 0 should be enough, but that doesn't seem to work !! on_scorpion2_reset(device->machine); return; } diff --git a/src/mame/drivers/champbas.c b/src/mame/drivers/champbas.c index 050093a5089..825839a4c56 100644 --- a/src/mame/drivers/champbas.c +++ b/src/mame/drivers/champbas.c @@ -101,7 +101,7 @@ static VIDEO_EOF( champbas ) state->watchdog_count++; if (state->watchdog_count == 0x10) - mame_schedule_soft_reset(machine); + machine->schedule_soft_reset(); } diff --git a/src/mame/drivers/cinemat.c b/src/mame/drivers/cinemat.c index aaa82fe140a..73b65e8bc6e 100644 --- a/src/mame/drivers/cinemat.c +++ b/src/mame/drivers/cinemat.c @@ -151,7 +151,7 @@ static WRITE8_HANDLER( mux_select_w ) static UINT8 joystick_read(running_device *device) { - if (mame_get_phase(device->machine) != MAME_PHASE_RUNNING) + if (device->machine->phase() != MACHINE_PHASE_RUNNING) return 0; else { diff --git a/src/mame/drivers/cps3.c b/src/mame/drivers/cps3.c index a3669e2dfe2..d763a5aeacd 100644 --- a/src/mame/drivers/cps3.c +++ b/src/mame/drivers/cps3.c @@ -2269,7 +2269,7 @@ static const struct WD33C93interface scsi_intf = NULL /* command completion IRQ */ }; -static void cps3_exit(running_machine *machine) +static void cps3_exit(running_machine &machine) { wd33c93_exit(&scsi_intf); } @@ -2277,7 +2277,7 @@ static void cps3_exit(running_machine *machine) static MACHINE_START( cps3 ) { wd33c93_init(machine, &scsi_intf); - add_exit_callback(machine, cps3_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, cps3_exit); } static MACHINE_RESET( cps3 ) diff --git a/src/mame/drivers/firebeat.c b/src/mame/drivers/firebeat.c index b4119ff0793..e5082206c3e 100644 --- a/src/mame/drivers/firebeat.c +++ b/src/mame/drivers/firebeat.c @@ -864,7 +864,7 @@ static void atapi_clear_irq(running_machine *machine) cputag_set_input_line(machine, "maincpu", INPUT_LINE_IRQ4, CLEAR_LINE); } -static void atapi_exit(running_machine* machine) +static void atapi_exit(running_machine& machine) { SCSIDeleteInstance(atapi_device_data[1]); SCSIDeleteInstance(atapi_device_data[0]); @@ -886,7 +886,7 @@ static void atapi_init(running_machine *machine) SCSIAllocInstance( machine, SCSI_DEVICE_CDROM, &atapi_device_data[0], "scsi0" ); // TODO: the slave drive can be either CD-ROM, DVD-ROM or HDD SCSIAllocInstance( machine, SCSI_DEVICE_CDROM, &atapi_device_data[1], "scsi1" ); - add_exit_callback(machine, atapi_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, atapi_exit); } static void atapi_reset(void) diff --git a/src/mame/drivers/galaxian.c b/src/mame/drivers/galaxian.c index cd7c5070aab..b9855e2386d 100644 --- a/src/mame/drivers/galaxian.c +++ b/src/mame/drivers/galaxian.c @@ -2658,7 +2658,7 @@ static DRIVER_INIT( gmgalax ) memory_configure_bank(machine, "bank1", 0, 2, memory_region(machine, "maincpu") + 0x10000, 0x4000); /* callback when the game select is toggled */ - gmgalax_game_changed(machine->portlist.first()->fieldlist, NULL, 0, 0); + gmgalax_game_changed(machine->m_portlist.first()->fieldlist, NULL, 0, 0); state_save_register_global(machine, gmgalax_selected_game); } diff --git a/src/mame/drivers/harddriv.c b/src/mame/drivers/harddriv.c index 49a8dc6d8a6..4e195df141b 100644 --- a/src/mame/drivers/harddriv.c +++ b/src/mame/drivers/harddriv.c @@ -3715,10 +3715,10 @@ static void init_ds3(running_machine *machine) /* if we have a sound DSP, boot it */ if (state->soundcpu != NULL && cpu_get_type(state->soundcpu) == CPU_ADSP2105) - adsp2105_load_boot_data(state->soundcpu->region()->base.u8 + 0x10000, state->soundcpu->region()->base.u32); + adsp2105_load_boot_data(state->soundcpu->region()->base() + 0x10000, &state->soundcpu->region()->u32()); if (state->sounddsp != NULL && cpu_get_type(state->sounddsp) == CPU_ADSP2105) - adsp2105_load_boot_data(state->sounddsp->region()->base.u8 + 0x10000, state->sounddsp->region()->base.u32); + adsp2105_load_boot_data(state->sounddsp->region()->base() + 0x10000, &state->sounddsp->region()->u32()); /* diff --git a/src/mame/drivers/hng64.c b/src/mame/drivers/hng64.c index a5dc07e8d0f..92747a69bc4 100644 --- a/src/mame/drivers/hng64.c +++ b/src/mame/drivers/hng64.c @@ -552,8 +552,8 @@ static WRITE32_HANDLER( hng64_pal_w ) static READ32_HANDLER( hng64_sysregs_r ) { - mame_system_time systime; - mame_get_base_datetime(space->machine, &systime); + system_time systime; + space->machine->base_datetime(systime); // if((offset*4) != 0x1084) // printf("HNG64 port read (PC=%08x) 0x%08x\n", cpu_get_pc(space->cpu),offset*4); diff --git a/src/mame/drivers/konamigq.c b/src/mame/drivers/konamigq.c index aa4005db5e8..12592137240 100644 --- a/src/mame/drivers/konamigq.c +++ b/src/mame/drivers/konamigq.c @@ -333,7 +333,7 @@ static DRIVER_INIT( konamigq ) m_p_n_pcmram = memory_region( machine, "shared" ) + 0x80000; } -static void konamigq_exit(running_machine *machine) +static void konamigq_exit(running_machine &machine) { am53cf96_exit(&scsi_intf); } @@ -342,7 +342,7 @@ static MACHINE_START( konamigq ) { /* init the scsi controller and hook up it's DMA */ am53cf96_init(machine, &scsi_intf); - add_exit_callback(machine, konamigq_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, konamigq_exit); psx_dma_install_read_handler(5, scsi_dma_read); psx_dma_install_write_handler(5, scsi_dma_write); diff --git a/src/mame/drivers/konamigv.c b/src/mame/drivers/konamigv.c index 808e9bbe01c..c74e7535392 100644 --- a/src/mame/drivers/konamigv.c +++ b/src/mame/drivers/konamigv.c @@ -280,7 +280,7 @@ static const struct AM53CF96interface scsi_intf = &scsi_irq, /* command completion IRQ */ }; -static void konamigv_exit(running_machine *machine) +static void konamigv_exit(running_machine &machine) { am53cf96_exit(&scsi_intf); } @@ -291,7 +291,7 @@ static DRIVER_INIT( konamigv ) /* init the scsi controller and hook up it's DMA */ am53cf96_init(machine, &scsi_intf); - add_exit_callback(machine, konamigv_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, konamigv_exit); psx_dma_install_read_handler(5, scsi_dma_read); psx_dma_install_write_handler(5, scsi_dma_write); } diff --git a/src/mame/drivers/ksys573.c b/src/mame/drivers/ksys573.c index 44e8f24f71f..47447d8975b 100644 --- a/src/mame/drivers/ksys573.c +++ b/src/mame/drivers/ksys573.c @@ -963,13 +963,13 @@ static WRITE32_HANDLER( atapi_w ) } } -static void atapi_exit(running_machine* machine) +static void atapi_exit(running_machine& machine) { int i; for( i = 0; i < 2; i++ ) { - if( get_disk_handle( machine, diskregions[i] ) != NULL ) + if( get_disk_handle( &machine, diskregions[i] ) != NULL ) { SCSIDeleteInstance( available_cdroms[ i ] ); } @@ -1006,7 +1006,7 @@ static void atapi_init(running_machine *machine) available_cdroms[ i ] = NULL; } } - add_exit_callback(machine, atapi_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, atapi_exit); atapi_data = auto_alloc_array(machine, UINT8, ATAPI_DATA_SIZE ); diff --git a/src/mame/drivers/luckgrln.c b/src/mame/drivers/luckgrln.c index 843bb45b685..b90e80aa07c 100644 --- a/src/mame/drivers/luckgrln.c +++ b/src/mame/drivers/luckgrln.c @@ -423,8 +423,8 @@ static WRITE8_HANDLER( palette_w ) // Oki M62X428 is a 4-bit RTC, doesn't seem to be millennium bug proof ... static READ8_HANDLER( rtc_r ) { - mame_system_time systime; - mame_get_base_datetime(space->machine, &systime); + system_time systime; + space->machine->base_datetime(systime); switch(offset) { diff --git a/src/mame/drivers/mediagx.c b/src/mame/drivers/mediagx.c index b00921fa695..a6b8bc9d26f 100644 --- a/src/mame/drivers/mediagx.c +++ b/src/mame/drivers/mediagx.c @@ -1171,7 +1171,7 @@ static const read32_space_func speedup_handlers[] = }; #ifdef MAME_DEBUG -static void report_speedups(running_machine *machine) +static void report_speedups(running_machine &machine) { int i; @@ -1193,7 +1193,7 @@ static void install_speedups(running_machine *machine, const speedup_entry *entr memory_install_read32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), entries[i].offset, entries[i].offset + 3, 0, 0, speedup_handlers[i]); #ifdef MAME_DEBUG - add_exit_callback(machine, report_speedups); + machine->add_notifier(MACHINE_NOTIFY_EXIT, report_speedups); #endif } diff --git a/src/mame/drivers/meritm.c b/src/mame/drivers/meritm.c index da467b353b2..cfc4826e156 100644 --- a/src/mame/drivers/meritm.c +++ b/src/mame/drivers/meritm.c @@ -521,13 +521,13 @@ static UINT8 binary_to_BCD(UINT8 data) static READ8_HANDLER(meritm_ds1644_r) { - mame_system_time systime; + system_time systime; int rambank = (meritm_psd_a15 >> 2) & 0x3; if (rambank == 3) { //logerror( "Reading RTC, reg = %x\n", offset); - mame_get_current_datetime(space->machine, &systime); + space->machine->current_datetime(systime); meritm_ram[0x7ff9] = binary_to_BCD(systime.local_time.second); meritm_ram[0x7ffa] = binary_to_BCD(systime.local_time.minute); meritm_ram[0x7ffb] = binary_to_BCD(systime.local_time.hour); diff --git a/src/mame/drivers/model3.c b/src/mame/drivers/model3.c index ba222431e41..551f379d32b 100644 --- a/src/mame/drivers/model3.c +++ b/src/mame/drivers/model3.c @@ -1195,7 +1195,7 @@ static const struct LSI53C810interface scsi_intf = &scsi_fetch, }; -static void model3_exit(running_machine *machine) +static void model3_exit(running_machine &machine) { lsi53c810_exit(&scsi_intf); } @@ -1212,13 +1212,13 @@ static void configure_fast_ram(running_machine *machine) static MACHINE_START(model3_10) { lsi53c810_init(machine, &scsi_intf); - add_exit_callback(machine, model3_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, model3_exit); configure_fast_ram(machine); } static MACHINE_START(model3_15) { lsi53c810_init(machine, &scsi_intf); - add_exit_callback(machine, model3_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, model3_exit); configure_fast_ram(machine); } static MACHINE_START(model3_20) diff --git a/src/mame/drivers/multfish.c b/src/mame/drivers/multfish.c index 68ca9056f22..6b111f6b97e 100644 --- a/src/mame/drivers/multfish.c +++ b/src/mame/drivers/multfish.c @@ -320,9 +320,9 @@ INLINE UINT8 make_bcd(UINT8 data) static READ8_HANDLER(multfish_rtc_r) { - mame_system_time systime; + system_time systime; - mame_get_current_datetime(space->machine, &systime); + space->machine->current_datetime(systime); switch (offset) { case 0: diff --git a/src/mame/drivers/namcos12.c b/src/mame/drivers/namcos12.c index 5bf1bb2e70b..41b76f2db2d 100644 --- a/src/mame/drivers/namcos12.c +++ b/src/mame/drivers/namcos12.c @@ -1329,10 +1329,10 @@ INLINE UINT8 make_bcd(UINT8 data) static READ8_HANDLER( s12_mcu_rtc_r ) { UINT8 ret = 0; - mame_system_time systime; + system_time systime; static const int weekday[7] = { 7, 1, 2, 3, 4, 5, 6 }; - mame_get_current_datetime(space->machine, &systime); + space->machine->current_datetime(systime); switch (s12_rtcstate) { diff --git a/src/mame/drivers/namcos23.c b/src/mame/drivers/namcos23.c index 77252a46297..ea467b5c17b 100644 --- a/src/mame/drivers/namcos23.c +++ b/src/mame/drivers/namcos23.c @@ -2396,10 +2396,10 @@ INLINE UINT8 make_bcd(UINT8 data) static READ8_HANDLER( s23_mcu_rtc_r ) { UINT8 ret = 0; - mame_system_time systime; + system_time systime; static const int weekday[7] = { 7, 1, 2, 3, 4, 5, 6 }; - mame_get_current_datetime(space->machine, &systime); + space->machine->current_datetime(systime); switch (s23_rtcstate) { diff --git a/src/mame/drivers/othldrby.c b/src/mame/drivers/othldrby.c index c1d7dd5fa24..4d4b29de3df 100644 --- a/src/mame/drivers/othldrby.c +++ b/src/mame/drivers/othldrby.c @@ -55,9 +55,9 @@ static WRITE16_HANDLER( calendar_w ) static READ16_HANDLER( calendar_r ) { - mame_system_time systime; + system_time systime; - mame_get_base_datetime(space->machine, &systime); + space->machine->base_datetime(systime); switch (offset) { diff --git a/src/mame/drivers/pgm.c b/src/mame/drivers/pgm.c index d27292239b5..b11705e2dd6 100644 --- a/src/mame/drivers/pgm.c +++ b/src/mame/drivers/pgm.c @@ -501,7 +501,7 @@ static WRITE16_HANDLER( pgm_calendar_w ) { pgm_state *state = (pgm_state *)space->machine->driver_data; - mame_get_base_datetime(space->machine, &state->systime); + space->machine->base_datetime(state->systime); state->cal_com <<= 1; state->cal_com |= data & 1; @@ -552,7 +552,7 @@ static WRITE16_HANDLER( pgm_calendar_w ) break; case 0xf: //Load Date - mame_get_base_datetime(space->machine, &state->systime); + space->machine->base_datetime(state->systime); break; } } @@ -1342,7 +1342,7 @@ static MACHINE_START( pgm ) { pgm_state *state = (pgm_state *)machine->driver_data; - mame_get_base_datetime(machine, &state->systime); + machine->base_datetime(state->systime); state->soundcpu = devtag_get_device(machine, "soundcpu"); state->prot = devtag_get_device(machine, "prot"); diff --git a/src/mame/drivers/stv.c b/src/mame/drivers/stv.c index fe5c3b9e785..80eea0cfba0 100644 --- a/src/mame/drivers/stv.c +++ b/src/mame/drivers/stv.c @@ -492,9 +492,9 @@ static UINT8 stv_SMPC_r8 (const address_space *space, int offset) static void stv_SMPC_w8 (const address_space *space, int offset, UINT8 data) { - mame_system_time systime; + system_time systime; - mame_get_base_datetime(space->machine, &systime); + space->machine->base_datetime(systime); // if(LOG_SMPC) logerror ("8-bit SMPC Write to Offset %02x with Data %02x\n", offset, data); smpc_ram[offset] = data; @@ -2336,9 +2336,9 @@ static void print_game_info(void); DRIVER_INIT ( stv ) { - mame_system_time systime; + system_time systime; - mame_get_base_datetime(machine, &systime); + machine->base_datetime(systime); /* amount of time to boost interleave for on MINIT / SINIT, needed for communication to work */ minit_boost = 400; @@ -2590,8 +2590,8 @@ static TIMER_CALLBACK(stv_rtc_increment) static MACHINE_START( stv ) { - mame_system_time systime; - mame_get_base_datetime(machine, &systime); + system_time systime; + machine->base_datetime(systime); stv_maincpu = machine->device<cpu_device>("maincpu"); stv_slave = machine->device<cpu_device>("slave"); @@ -2623,7 +2623,7 @@ static MACHINE_START( stv ) stv_register_protection_savestates(machine); // machine/stvprot.c - add_exit_callback(machine, stvcd_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, stvcd_exit); smpc_ram[0x23] = DectoBCD(systime.local_time.year /100); smpc_ram[0x25] = DectoBCD(systime.local_time.year %100); diff --git a/src/mame/drivers/suprnova.c b/src/mame/drivers/suprnova.c index 4d9fdae7437..65477bd961f 100644 --- a/src/mame/drivers/suprnova.c +++ b/src/mame/drivers/suprnova.c @@ -705,10 +705,10 @@ static WRITE32_HANDLER( skns_io_w ) static READ32_HANDLER( skns_msm6242_r ) { - mame_system_time systime; + system_time systime; long value; - mame_get_base_datetime(space->machine, &systime); + space->machine->base_datetime(systime); // The clock is not y2k-compatible, wrap back 10 years, screw the leap years // tm->tm_year -= 10; diff --git a/src/mame/drivers/taitosj.c b/src/mame/drivers/taitosj.c index 50cb1030022..7d99d8cb8df 100644 --- a/src/mame/drivers/taitosj.c +++ b/src/mame/drivers/taitosj.c @@ -2672,7 +2672,7 @@ ROM_START( kikstart ) ROM_LOAD( "pal16l8.28", 0x0000, 0x0104, NO_DUMP ) /* PAL is read protected */ ROM_END -static void reset_common(running_machine *machine) +static void reset_common(running_machine &machine) { sndnmi_disable = 1; input_port_4_f0 = 0; @@ -2691,7 +2691,7 @@ static void init_common(running_machine *machine) state_save_register_global(machine, dac_out); state_save_register_global(machine, dac_vol); - add_reset_callback(machine, reset_common); + machine->add_notifier(MACHINE_NOTIFY_RESET, reset_common); } static DRIVER_INIT( taitosj ) diff --git a/src/mame/drivers/tmaster.c b/src/mame/drivers/tmaster.c index f83dc68928f..b23682f53cc 100644 --- a/src/mame/drivers/tmaster.c +++ b/src/mame/drivers/tmaster.c @@ -184,9 +184,9 @@ static UINT8 binary_to_BCD(UINT8 data) static READ16_HANDLER(rtc_r) { - mame_system_time systime; + system_time systime; - mame_get_current_datetime(space->machine, &systime); + space->machine->current_datetime(systime); rtc_ram[0x1] = binary_to_BCD(systime.local_time.second); rtc_ram[0x2] = binary_to_BCD(systime.local_time.minute); rtc_ram[0x3] = binary_to_BCD(systime.local_time.hour); diff --git a/src/mame/drivers/vegas.c b/src/mame/drivers/vegas.c index f12e4844db4..1c852be54cb 100644 --- a/src/mame/drivers/vegas.c +++ b/src/mame/drivers/vegas.c @@ -636,8 +636,8 @@ static READ32_HANDLER( timekeeper_r ) if ((offset*4) >= 0x7ff0) { /* get the time */ - mame_system_time systime; - mame_get_base_datetime(space->machine, &systime); + system_time systime; + space->machine->base_datetime(systime); /* return portions thereof */ switch (offset*4) diff --git a/src/mame/includes/pgm.h b/src/mame/includes/pgm.h index bff4c264cbe..a0c95045430 100644 --- a/src/mame/includes/pgm.h +++ b/src/mame/includes/pgm.h @@ -63,7 +63,7 @@ public: /* calendar */ UINT8 cal_val, cal_mask, cal_com, cal_cnt; - mame_system_time systime; + system_time systime; /* devices */ running_device *soundcpu; diff --git a/src/mame/machine/amiga.c b/src/mame/machine/amiga.c index a17d5b55a45..00a8599b52e 100644 --- a/src/mame/machine/amiga.c +++ b/src/mame/machine/amiga.c @@ -1575,7 +1575,7 @@ void amiga_add_autoconfig(running_machine *machine, const amiga_autoconfig_devic autoconfig_device *dev, **d; /* validate the data */ - assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call amiga_add_autoconfig at init time!"); + assert_always(machine->phase() == MACHINE_PHASE_INIT, "Can only call amiga_add_autoconfig at init time!"); assert_always((device->size & (device->size - 1)) == 0, "device->size must be power of 2!"); /* allocate memory and link it in at the end of the list */ diff --git a/src/mame/machine/atari.c b/src/mame/machine/atari.c index 9be195b5635..373e107fb29 100644 --- a/src/mame/machine/atari.c +++ b/src/mame/machine/atari.c @@ -22,7 +22,7 @@ static void a600xl_mmu(running_machine *machine, UINT8 new_mmu); -static void pokey_reset(running_machine *machine); +static void pokey_reset(running_machine &machine); void atari_interrupt_cb(running_device *device, int mask) { @@ -306,9 +306,9 @@ void a5200_handle_keypads(running_machine *machine) *************************************/ -static void pokey_reset(running_machine *machine) +static void pokey_reset(running_machine &machine) { - running_device *pokey = devtag_get_device(machine, "pokey"); + running_device *pokey = machine.device("pokey"); pokey_w(pokey,15,0); atari_last = 0xff; } @@ -330,7 +330,7 @@ static void console_write(const address_space *space, UINT8 data) } -static void _antic_reset(running_machine *machine) +static void _antic_reset(running_machine &machine) { antic_reset(); } @@ -349,10 +349,10 @@ void atari_machine_start(running_machine *machine) gtia_init(machine, >ia_intf); /* pokey */ - add_reset_callback(machine, pokey_reset); + machine->add_notifier(MACHINE_NOTIFY_RESET, pokey_reset); /* ANTIC */ - add_reset_callback(machine, _antic_reset); + machine->add_notifier(MACHINE_NOTIFY_RESET, _antic_reset); /* save states */ state_save_register_global_pointer(machine, ((UINT8 *) &antic.r), sizeof(antic.r)); diff --git a/src/mame/machine/cubocd32.c b/src/mame/machine/cubocd32.c index d07e47e818b..e72783b5784 100644 --- a/src/mame/machine/cubocd32.c +++ b/src/mame/machine/cubocd32.c @@ -68,7 +68,7 @@ static struct akiko_def static TIMER_CALLBACK(akiko_dma_proc); static TIMER_CALLBACK(akiko_frame_proc); -static void amiga_akiko_exit(running_machine* machine) +static void amiga_akiko_exit(running_machine& machine) { if( akiko.cdrom ) { cdrom_close(akiko.cdrom); @@ -107,7 +107,7 @@ void amiga_akiko_init(running_machine* machine) akiko.dma_timer = timer_alloc(machine, akiko_dma_proc, NULL); akiko.frame_timer = timer_alloc(machine, akiko_frame_proc, NULL); - add_exit_callback(machine, amiga_akiko_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, amiga_akiko_exit); /* create the TOC table */ if ( akiko.cdrom != NULL && cdrom_get_last_track(akiko.cdrom) ) diff --git a/src/mame/machine/dc.c b/src/mame/machine/dc.c index 7dae918e865..5f8728f2ce5 100644 --- a/src/mame/machine/dc.c +++ b/src/mame/machine/dc.c @@ -1578,8 +1578,8 @@ static void rtc_initial_setup(running_machine *machine) static UINT32 current_time; static int year_count,cur_year,i; static const int month_to_day_conversion[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; - mame_system_time systime; - mame_get_base_datetime(machine, &systime); + system_time systime; + machine->base_datetime(systime); memset(dc_rtcregister, 0, sizeof(dc_rtcregister)); diff --git a/src/mame/machine/midwayic.c b/src/mame/machine/midwayic.c index 2b1d6a309fe..f59282573aa 100644 --- a/src/mame/machine/midwayic.c +++ b/src/mame/machine/midwayic.c @@ -383,8 +383,8 @@ void midway_serial_pic2_w(const address_space *space, UINT8 data) /* if we haven't written a new time recently, use the real live time */ if (!pic.time_just_written) { - mame_system_time systime; - mame_get_base_datetime(machine, &systime); + system_time systime; + machine->base_datetime(systime); pic.buffer[pic.total++] = make_bcd(systime.local_time.second); pic.buffer[pic.total++] = make_bcd(systime.local_time.minute); diff --git a/src/mame/machine/model3.c b/src/mame/machine/model3.c index af3bb365e14..67c198a7d8c 100644 --- a/src/mame/machine/model3.c +++ b/src/mame/machine/model3.c @@ -289,9 +289,9 @@ void model3_machine_init(int step) static UINT8 rtc_get_reg(running_machine *machine, int reg) { - mame_system_time systime; + system_time systime; - mame_get_current_datetime(machine, &systime); + machine->current_datetime(systime); switch(reg) { diff --git a/src/mame/machine/segaic16.c b/src/mame/machine/segaic16.c index 887cb1de2dd..bf6fe2ff3db 100644 --- a/src/mame/machine/segaic16.c +++ b/src/mame/machine/segaic16.c @@ -136,7 +136,7 @@ void segaic16_memory_mapper_config(running_machine *machine, const UINT8 *map_da void segaic16_memory_mapper_set_decrypted(running_machine *machine, UINT8 *decrypted) { struct memory_mapper_chip *chip = &memory_mapper; - offs_t romsize = chip->cpu->region()->length; + offs_t romsize = chip->cpu->region()->bytes(); int rgnum; /* loop over the regions */ @@ -319,7 +319,7 @@ static void update_memory_mapping(running_machine *machine, struct memory_mapper /* ROM areas need extra clamping */ if (rgn->romoffset != ~0) { - offs_t romsize = chip->cpu->region()->length; + offs_t romsize = chip->cpu->region()->bytes(); if (region_start >= romsize) read = NULL; else if (region_start + rgn->length > romsize) @@ -355,7 +355,7 @@ static void update_memory_mapping(running_machine *machine, struct memory_mapper decrypted = (UINT8 *)fd1089_get_decrypted_base(); } - memory_configure_bank(machine, readbank, 0, 1, chip->cpu->region()->base.u8 + region_start, 0); + memory_configure_bank(machine, readbank, 0, 1, chip->cpu->region()->base() + region_start, 0); if (decrypted) memory_configure_bank_decrypted(machine, readbank, 0, 1, decrypted + region_start, 0); diff --git a/src/mame/machine/snes7110.c b/src/mame/machine/snes7110.c index 03f63253442..ca5c757bfa6 100644 --- a/src/mame/machine/snes7110.c +++ b/src/mame/machine/snes7110.c @@ -992,8 +992,8 @@ static void spc7110_set_data_adjust(UINT32 addr) // (and indeed current code fails to pass Tengai Makyou Zero tests) static void spc7110_update_time(running_machine *machine, UINT8 offset) { - mame_system_time curtime, *systime = &curtime; - mame_get_current_datetime(machine, &curtime); + system_time curtime, *systime = &curtime; + machine->current_datetime(curtime); int update = 1; snes_spc7110.rtc_offset += offset; diff --git a/src/mame/machine/snesrtc.c b/src/mame/machine/snesrtc.c index cadc5661ae8..a8c4e147784 100644 --- a/src/mame/machine/snesrtc.c +++ b/src/mame/machine/snesrtc.c @@ -41,8 +41,8 @@ static const UINT8 srtc_months[12] = static void srtc_update_time( running_machine *machine ) { - mame_system_time curtime, *systime = &curtime; - mame_get_current_datetime(machine, &curtime); + system_time curtime, *systime = &curtime; + machine->current_datetime(curtime); rtc_state.ram[0] = systime->local_time.second % 10; rtc_state.ram[1] = systime->local_time.second / 10; rtc_state.ram[2] = systime->local_time.minute % 10; diff --git a/src/mame/machine/steppers.c b/src/mame/machine/steppers.c index 1e07844b678..d1c814ba535 100644 --- a/src/mame/machine/steppers.c +++ b/src/mame/machine/steppers.c @@ -604,7 +604,7 @@ const stepper_interface starpoint_interface_48step = /////////////////////////////////////////////////////////////////////////// void stepper_config(running_machine *machine, int which, const stepper_interface *intf) { - assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call stepper_config at init time!"); + assert_always(machine->phase() == MACHINE_PHASE_INIT, "Can only call stepper_config at init time!"); assert_always((which >= 0) && (which < MAX_STEPPERS), "stepper_config called on an invalid stepper motor!"); assert_always(intf, "stepper_config called with an invalid interface!"); diff --git a/src/mame/machine/stvcd.c b/src/mame/machine/stvcd.c index 44c03c2c424..0f4b1485f9e 100644 --- a/src/mame/machine/stvcd.c +++ b/src/mame/machine/stvcd.c @@ -1538,11 +1538,11 @@ static void make_dir_current(running_machine *machine, UINT32 fad) } } -void stvcd_exit(running_machine* machine) +void stvcd_exit(running_machine& machine) { if (curdir != (direntryT *)NULL) { - auto_free(machine, curdir); + auto_free(&machine, curdir); curdir = (direntryT *)NULL; } diff --git a/src/mame/machine/stvcd.h b/src/mame/machine/stvcd.h index d9a8a2cb87d..e4477ce2c23 100644 --- a/src/mame/machine/stvcd.h +++ b/src/mame/machine/stvcd.h @@ -10,7 +10,7 @@ #define __STVCD_H__ void stvcd_reset(running_machine* machine); -void stvcd_exit(running_machine* machine); +void stvcd_exit(running_machine& machine); TIMER_DEVICE_CALLBACK( stv_sector_cb ); diff --git a/src/mame/machine/tecmosys.c b/src/mame/machine/tecmosys.c index c11b5ebdecf..d88a430bb4b 100644 --- a/src/mame/machine/tecmosys.c +++ b/src/mame/machine/tecmosys.c @@ -109,7 +109,7 @@ static const struct prot_data tkdensha_data = }; -static void tecmosys_prot_reset(running_machine *machine) +static void tecmosys_prot_reset(running_machine &machine) { device_read_ptr = 0; device_status = DS_IDLE; @@ -125,7 +125,7 @@ void tecmosys_prot_init(running_machine *machine, int which) case 2: device_data = &tkdensha_data; break; } - add_reset_callback(machine, tecmosys_prot_reset); + machine->add_notifier(MACHINE_NOTIFY_RESET, tecmosys_prot_reset); } READ16_HANDLER(tecmosys_prot_status_r) diff --git a/src/mame/video/atarisy1.c b/src/mame/video/atarisy1.c index f11921e392a..4921d676988 100644 --- a/src/mame/video/atarisy1.c +++ b/src/mame/video/atarisy1.c @@ -554,8 +554,8 @@ VIDEO_UPDATE( atarisy1 ) static void decode_gfx(running_machine *machine, UINT16 *pflookup, UINT16 *molookup) { atarisy1_state *state = (atarisy1_state *)machine->driver_data; - UINT8 *prom1 = &machine->region("proms")->base.u8[0x000]; - UINT8 *prom2 = &machine->region("proms")->base.u8[0x200]; + UINT8 *prom1 = &machine->region("proms")->u8(0x000); + UINT8 *prom2 = &machine->region("proms")->u8(0x200); int obj, i; /* reset the globals */ @@ -647,7 +647,7 @@ static int get_bank(running_machine *machine, UINT8 prom1, UINT8 prom2, int bpp) /* if the bank is out of range, call it 0 */ const region_info *tiles = machine->region("tiles"); - if (0x80000 * (bank_index - 1) >= tiles->length) + if (0x80000 * (bank_index - 1) >= tiles->bytes()) return 0; /* don't have one? let's make it ... first find any empty slot */ @@ -657,7 +657,7 @@ static int get_bank(running_machine *machine, UINT8 prom1, UINT8 prom2, int bpp) assert(gfx_index != MAX_GFX_ELEMENTS); /* decode the graphics */ - srcdata = &tiles->base.u8[0x80000 * (bank_index - 1)]; + srcdata = &tiles->u8(0x80000 * (bank_index - 1)); switch (bpp) { case 4: diff --git a/src/mame/video/gaelco3d.c b/src/mame/video/gaelco3d.c index a3b284656e8..373b6bb64b8 100644 --- a/src/mame/video/gaelco3d.c +++ b/src/mame/video/gaelco3d.c @@ -65,7 +65,7 @@ static void render_alphablend(void *dest, INT32 scanline, const poly_extent *ext * *************************************/ -static void gaelco3d_exit(running_machine *machine) +static void gaelco3d_exit(running_machine &machine) { poly_free(poly); } @@ -76,7 +76,7 @@ VIDEO_START( gaelco3d ) int width, height; poly = poly_alloc(machine, 2000, sizeof(poly_extra_data), 0); - add_exit_callback(machine, gaelco3d_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, gaelco3d_exit); screenbits = machine->primary_screen->alloc_compatible_bitmap(); diff --git a/src/mame/video/galastrm.c b/src/mame/video/galastrm.c index d8aee464492..f4bc3b29984 100644 --- a/src/mame/video/galastrm.c +++ b/src/mame/video/galastrm.c @@ -36,7 +36,7 @@ struct _polygon /******************************************************************/ -static void galastrm_exit(running_machine *machine) +static void galastrm_exit(running_machine &machine) { poly_free(poly); } @@ -49,7 +49,7 @@ VIDEO_START( galastrm ) polybitmap = machine->primary_screen->alloc_compatible_bitmap(); poly = poly_alloc(machine, 16, sizeof(poly_extra_data), POLYFLAG_ALLOW_QUADS); - add_exit_callback(machine, galastrm_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, galastrm_exit); } /************************************************************ diff --git a/src/mame/video/gtia.c b/src/mame/video/gtia.c index 61aece907f8..6ae4b4af3db 100644 --- a/src/mame/video/gtia.c +++ b/src/mame/video/gtia.c @@ -27,7 +27,7 @@ gtia_struct gtia; #define CHECK_GRACTL 0 #define VERBOSE 0 -static void gtia_reset(running_machine *machine); +static void gtia_reset(running_machine &machine); static void gtia_state(running_machine *machine); static STATE_POSTLOAD( gtia_state_postload ); @@ -68,7 +68,7 @@ void gtia_init(running_machine *machine, const gtia_interface *intf) memset(>ia, 0, sizeof(gtia)); gtia.intf = *intf; - add_reset_callback(machine, gtia_reset); + machine->add_notifier(MACHINE_NOTIFY_RESET, gtia_reset); /* state saves */ gtia_state(machine); @@ -151,16 +151,16 @@ static int is_ntsc(running_machine *machine) -static void gtia_reset(running_machine *machine) +static void gtia_reset(running_machine &machine) { int i; - const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); + const address_space *space = cputag_get_address_space(&machine, "maincpu", ADDRESS_SPACE_PROGRAM); /* reset the GTIA read/write/helper registers */ for (i = 0; i < 32; i++) atari_gtia_w(space,i,0); memset(>ia.r, 0, sizeof(gtia.r)); - if (is_ntsc(machine)) + if (is_ntsc(&machine)) gtia.r.pal = 0xff; else gtia.r.pal = 0xf1; diff --git a/src/mame/video/gticlub.c b/src/mame/video/gticlub.c index 63908ff84ad..2125da4cb9e 100644 --- a/src/mame/video/gticlub.c +++ b/src/mame/video/gticlub.c @@ -189,7 +189,7 @@ static UINT8 *gfxrom; void K001005_swap_buffers(running_machine *machine); -static void K001005_exit(running_machine *machine) +static void K001005_exit(running_machine &machine) { poly_free(poly); } @@ -217,7 +217,7 @@ void K001005_init(running_machine *machine) K001005_3d_fifo = auto_alloc_array(machine, UINT32, 0x10000); poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), POLYFLAG_ALLOW_QUADS); - add_exit_callback(machine, K001005_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, K001005_exit); for (i=0; i < 128; i++) { diff --git a/src/mame/video/hng64.c b/src/mame/video/hng64.c index 751987e4518..82055cd400e 100644 --- a/src/mame/video/hng64.c +++ b/src/mame/video/hng64.c @@ -2211,7 +2211,7 @@ static void recoverPolygonBlock(running_machine* machine, const UINT16* packet, So instead we're looking for a bit that is on for XRally & Buriki, but noone else. */ if (hng64_3dregs[0x00/4] & 0x2000) { - if (strcmp(machine->basename, "roadedge")) + if (strcmp(machine->basename(), "roadedge")) polys[*numPolys].palOffset += 0x800; } diff --git a/src/mame/video/midvunit.c b/src/mame/video/midvunit.c index cec69ac0958..bbfc6f986be 100644 --- a/src/mame/video/midvunit.c +++ b/src/mame/video/midvunit.c @@ -68,7 +68,7 @@ static TIMER_CALLBACK( scanline_timer_cb ) } -static void midvunit_exit(running_machine *machine) +static void midvunit_exit(running_machine &machine) { poly_free(poly); } @@ -78,7 +78,7 @@ VIDEO_START( midvunit ) { scanline_timer = timer_alloc(machine, scanline_timer_cb, NULL); poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), POLYFLAG_ALLOW_QUADS); - add_exit_callback(machine, midvunit_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, midvunit_exit); state_save_register_global_array(machine, video_regs); state_save_register_global_array(machine, dma_data); diff --git a/src/mame/video/midzeus.c b/src/mame/video/midzeus.c index e5b7a2b4818..f151cd602a6 100644 --- a/src/mame/video/midzeus.c +++ b/src/mame/video/midzeus.c @@ -82,7 +82,7 @@ static int texel_width; * *************************************/ -static void exit_handler(running_machine *machine); +static void exit_handler(running_machine &machine); static void zeus_pointer_w(UINT32 which, UINT32 data, int logit); static void zeus_register16_w(running_machine *machine, offs_t offset, UINT16 data, int logit); @@ -259,7 +259,7 @@ VIDEO_START( midzeus ) poly = poly_alloc(machine, 10000, sizeof(poly_extra_data), POLYFLAG_ALLOW_QUADS); /* we need to cleanup on exit */ - add_exit_callback(machine, exit_handler); + machine->add_notifier(MACHINE_NOTIFY_EXIT, exit_handler); yoffs = 0; texel_width = 256; @@ -282,7 +282,7 @@ VIDEO_START( midzeus ) } -static void exit_handler(running_machine *machine) +static void exit_handler(running_machine &machine) { #if DUMP_WAVE_RAM FILE *f = fopen("waveram.dmp", "w"); diff --git a/src/mame/video/midzeus2.c b/src/mame/video/midzeus2.c index 31b7d8ac482..c9dce0d4144 100644 --- a/src/mame/video/midzeus2.c +++ b/src/mame/video/midzeus2.c @@ -102,7 +102,7 @@ static int subregwrite_count[0x100]; * *************************************/ -static void exit_handler(running_machine *machine); +static void exit_handler(running_machine &machine); static void zeus_register32_w(running_machine *machine, offs_t offset, UINT32 data, int logit); static void zeus_register_update(running_machine *machine, offs_t offset, UINT32 oldval, int logit); @@ -273,7 +273,7 @@ VIDEO_START( midzeus2 ) poly = poly_alloc(machine, 10000, sizeof(poly_extra_data), POLYFLAG_ALLOW_QUADS); /* we need to cleanup on exit */ - add_exit_callback(machine, exit_handler); + machine->add_notifier(MACHINE_NOTIFY_EXIT, exit_handler); zbase = 2.0f; yoffs = 0; @@ -297,7 +297,7 @@ VIDEO_START( midzeus2 ) } -static void exit_handler(running_machine *machine) +static void exit_handler(running_machine &machine) { #if DUMP_WAVE_RAM FILE *f = fopen("waveram.dmp", "w"); diff --git a/src/mame/video/model2.c b/src/mame/video/model2.c index fdc49e167b2..5b5b98e7b97 100644 --- a/src/mame/video/model2.c +++ b/src/mame/video/model2.c @@ -2683,7 +2683,7 @@ static void geo_parse( void ) static bitmap_t *sys24_bitmap = NULL; -static void model2_exit(running_machine *machine) +static void model2_exit(running_machine &machine) { poly_free(poly); } @@ -2698,7 +2698,7 @@ VIDEO_START(model2) sys24_bitmap = auto_alloc(machine, bitmap_t(width, height+4, BITMAP_FORMAT_INDEXED16)); poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), 0); - add_exit_callback(machine, model2_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, model2_exit); /* initialize the geometry engine */ geo_init( machine, (UINT32*)memory_region(machine, "user2") ); diff --git a/src/mame/video/model3.c b/src/mame/video/model3.c index 18768082904..89b67b6443a 100644 --- a/src/mame/video/model3.c +++ b/src/mame/video/model3.c @@ -153,10 +153,10 @@ static UINT32 matrix_base_address; #define BYTE_REVERSE16(x) (((x >> 8) & 0xff) | ((x << 8) & 0xff00)) -static void model3_exit(running_machine *machine) +static void model3_exit(running_machine &machine) { - invalidate_texture(machine, 0, 0, 0, 6, 5); - invalidate_texture(machine, 1, 0, 0, 6, 5); + invalidate_texture(&machine, 0, 0, 0, 6, 5); + invalidate_texture(&machine, 1, 0, 0, 6, 5); poly_free(poly); } @@ -165,7 +165,7 @@ VIDEO_START( model3 ) int width, height; poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), 0); - add_exit_callback(machine, model3_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, model3_exit); width = machine->primary_screen->width(); height = machine->primary_screen->height(); diff --git a/src/mame/video/namcos22.c b/src/mame/video/namcos22.c index 49901910e59..e0fc7d979ce 100644 --- a/src/mame/video/namcos22.c +++ b/src/mame/video/namcos22.c @@ -2190,13 +2190,13 @@ WRITE32_HANDLER( namcos22_paletteram_w ) dirtypal[offset&(0x7fff/4)] = 1; } -static void namcos22_reset(running_machine *machine) +static void namcos22_reset(running_machine &machine) { memset(&mSceneRoot, 0, sizeof(mSceneRoot)); mpFreeSceneNode = NULL; } -static void namcos22_exit(running_machine *machine) +static void namcos22_exit(running_machine &machine) { poly_free(poly); } @@ -2225,8 +2225,8 @@ static VIDEO_START( common ) #else poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), 0); #endif - add_reset_callback(machine, namcos22_reset); - add_exit_callback(machine, namcos22_exit); + machine->add_notifier(MACHINE_NOTIFY_RESET, namcos22_reset); + machine->add_notifier(MACHINE_NOTIFY_EXIT, namcos22_exit); gfx_element_set_source(machine->gfx[GFX_CHAR], (UINT8 *)namcos22_cgram); } diff --git a/src/mame/video/stvvdp2.c b/src/mame/video/stvvdp2.c index 941ea562a51..770fd5a53cf 100644 --- a/src/mame/video/stvvdp2.c +++ b/src/mame/video/stvvdp2.c @@ -5422,14 +5422,14 @@ static STATE_POSTLOAD( stv_vdp2_state_save_postload ) refresh_palette_data(machine); } -static void stv_vdp2_exit (running_machine *machine) +static void stv_vdp2_exit (running_machine &machine) { stv_vdp2_roz_bitmap[0] = stv_vdp2_roz_bitmap[1] = NULL; } static int stv_vdp2_start (running_machine *machine) { - add_exit_callback(machine, stv_vdp2_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, stv_vdp2_exit); stv_vdp2_regs = auto_alloc_array_clear(machine, UINT32, 0x040000/4 ); stv_vdp2_vram = auto_alloc_array_clear(machine, UINT32, 0x100000/4 ); // actually we only need half of it since we don't emulate extra 4mbit ram cart. diff --git a/src/mame/video/taitojc.c b/src/mame/video/taitojc.c index 96929c61280..3a0ba743a50 100644 --- a/src/mame/video/taitojc.c +++ b/src/mame/video/taitojc.c @@ -165,9 +165,9 @@ static void draw_object(running_machine *machine, bitmap_t *bitmap, const rectan } } -static void taitojc_exit(running_machine *machine) +static void taitojc_exit(running_machine &machine) { - taitojc_state *state = (taitojc_state *)machine->driver_data; + taitojc_state *state = (taitojc_state *)machine.driver_data; poly_free(state->poly); } @@ -177,7 +177,7 @@ VIDEO_START( taitojc ) int width, height; state->poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), POLYFLAG_ALLOW_QUADS); - add_exit_callback(machine, taitojc_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, taitojc_exit); /* find first empty slot to decode gfx */ for (state->gfx_index = 0; state->gfx_index < MAX_GFX_ELEMENTS; state->gfx_index++) diff --git a/src/mame/video/tia.c b/src/mame/video/tia.c index b5432bee36f..557316d1b1d 100644 --- a/src/mame/video/tia.c +++ b/src/mame/video/tia.c @@ -1924,7 +1924,7 @@ WRITE8_HANDLER( tia_w ) } -static void tia_reset(running_machine *machine) +static void tia_reset(running_machine &machine) { int i; @@ -1981,7 +1981,7 @@ static void tia_reset(running_machine *machine) void tia_init(running_machine *machine, const struct tia_interface* ti) { - assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call tia_init at init time!"); + assert_always(machine->phase() == MACHINE_PHASE_INIT, "Can only call tia_init at init time!"); if ( ti ) { tia_read_input_port = ti->read_input_port; @@ -1993,8 +1993,8 @@ void tia_init(running_machine *machine, const struct tia_interface* ti) tia_vsync_callback = NULL; } - tia_reset( machine ); + tia_reset( *machine ); - add_reset_callback(machine, tia_reset); + machine->add_notifier(MACHINE_NOTIFY_RESET, tia_reset); } diff --git a/src/mame/video/ygv608.c b/src/mame/video/ygv608.c index c85fc418a0c..62d133d2de0 100644 --- a/src/mame/video/ygv608.c +++ b/src/mame/video/ygv608.c @@ -495,7 +495,7 @@ static void ygv608_register_state_save(running_machine *machine) state_save_register_postload(machine, ygv608_postload, NULL); } -static void ygv608_exit(running_machine *machine) +static void ygv608_exit(running_machine &machine) { work_bitmap = NULL; } @@ -531,7 +531,7 @@ VIDEO_START( ygv608 ) tilemap_B = NULL; ygv608_register_state_save(machine); - add_exit_callback(machine, ygv608_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, ygv608_exit); } static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) diff --git a/src/osd/osdepend.h b/src/osd/osdepend.h index ae08f732c3c..7f44a6b4cdb 100644 --- a/src/osd/osdepend.h +++ b/src/osd/osdepend.h @@ -113,7 +113,7 @@ class device_t; Note that there is no corresponding osd_exit(). Rather, like most systems in MAME, you can register an exit callback via the - add_exit_callback() function in mame.c. + add_notifier() function in mame.c. Also note that there is no return value. If you need to report a fatal error, use the fatalerror() function with a friendly message diff --git a/src/osd/osdmini/minimain.c b/src/osd/osdmini/minimain.c index 08b769d2056..c372d829711 100644 --- a/src/osd/osdmini/minimain.c +++ b/src/osd/osdmini/minimain.c @@ -170,7 +170,7 @@ void osd_update(running_machine *machine, int skip_redraw) // after 5 seconds, exit if (attotime_compare(timer_get_time(machine), attotime_make(5, 0)) > 0) - mame_schedule_exit(machine); + machine->schedule_exit(); } diff --git a/src/osd/sdl/debugwin.c b/src/osd/sdl/debugwin.c index 273235c1391..d8e27ac653a 100644 --- a/src/osd/sdl/debugwin.c +++ b/src/osd/sdl/debugwin.c @@ -506,7 +506,7 @@ static void debugmain_destroy(GtkObject *obj, gpointer user_data) { win_i *dmain = get_first_win_i(WIN_TYPE_MAIN); - mame_schedule_exit(dmain->machine); + dmain->machine->schedule_exit(); } @@ -891,18 +891,18 @@ void on_step_out_activate(GtkWidget *win) void on_hard_reset_activate(GtkWidget *win) { - mame_schedule_hard_reset(get_running_machine(win)); + get_running_machine(win)->schedule_hard_reset(); } void on_soft_reset_activate(GtkWidget *win) { - mame_schedule_soft_reset(get_running_machine(win)); + get_running_machine(win)->schedule_soft_reset(); debug_cpu_go(get_running_machine(win), ~0); } void on_exit_activate(GtkWidget *win) { - mame_schedule_exit(get_running_machine(win)); + get_running_machine(win)->schedule_exit(); } void on_chunks_1_activate(GtkWidget *win) diff --git a/src/osd/sdl/drawogl.c b/src/osd/sdl/drawogl.c index 88e6c475123..b4a90cedb67 100644 --- a/src/osd/sdl/drawogl.c +++ b/src/osd/sdl/drawogl.c @@ -1241,7 +1241,7 @@ static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) // we're doing nothing 3d, so the Z-buffer is currently not interesting glDisable(GL_DEPTH_TEST); - if (options_get_bool(mame_options(), OPTION_ANTIALIAS)) + if (options_get_bool(window->machine->options(), OPTION_ANTIALIAS)) { // enable antialiasing for lines glEnable(GL_LINE_SMOOTH); @@ -2957,9 +2957,9 @@ static void texture_shader_update(sdl_window_info *window, texture_info *texture render_container_get_user_settings(container, &settings); //FIXME: Intended behaviour #if 1 - vid_attributes[0] = options_get_float(mame_options(), OPTION_GAMMA); - vid_attributes[1] = options_get_float(mame_options(), OPTION_CONTRAST); - vid_attributes[2] = options_get_float(mame_options(), OPTION_BRIGHTNESS); + vid_attributes[0] = options_get_float(window->machine->options(), OPTION_GAMMA); + vid_attributes[1] = options_get_float(window->machine->options(), OPTION_CONTRAST); + vid_attributes[2] = options_get_float(window->machine->options(), OPTION_BRIGHTNESS); #else vid_attributes[0] = settings.gamma; vid_attributes[1] = settings.contrast; diff --git a/src/osd/sdl/input.c b/src/osd/sdl/input.c index 340dd9ca2e7..8c6ea4a648f 100644 --- a/src/osd/sdl/input.c +++ b/src/osd/sdl/input.c @@ -173,8 +173,9 @@ static int sixaxis_mode; // PROTOTYPES //============================================================ -static void sdlinput_pause(running_machine *machine, int paused); -static void sdlinput_exit(running_machine *machine); +static void sdlinput_pause(running_machine &machine); +static void sdlinput_resume(running_machine &machine); +static void sdlinput_exit(running_machine &machine); // deivce list management static void device_list_reset_devices(device_info *devlist_head); @@ -637,7 +638,7 @@ static void devmap_init(running_machine *machine, device_map_t *devmap, const ch const char *dev_name; sprintf(defname, "%s%d", opt, dev + 1); - dev_name = options_get_string(mame_options(), defname); + dev_name = options_get_string(machine->options(), defname); if (dev_name && *dev_name && strcmp(dev_name,SDLOPTVAL_AUTO)) { devmap->map[dev].name = remove_spaces(machine, dev_name); @@ -794,7 +795,7 @@ static void sdlinput_register_mice(running_machine *machine) { int index, physical_mouse; - mouse_enabled = options_get_bool(mame_options(), OPTION_MOUSE); + mouse_enabled = options_get_bool(machine->options(), OPTION_MOUSE); devmap_init(machine, &mouse_map, SDLOPTION_MOUSEINDEX, 8, "Mouse mapping"); @@ -854,7 +855,7 @@ static void sdlinput_register_mice(running_machine *machine) devinfo = generic_device_alloc(&mouse_list, "System mouse"); devinfo->device = input_device_add(machine, DEVICE_CLASS_MOUSE, devinfo->name, devinfo); - mouse_enabled = options_get_bool(mame_options(), OPTION_MOUSE); + mouse_enabled = options_get_bool(machine->options(), OPTION_MOUSE); // add the axes input_device_item_add(devinfo->device, "X", &devinfo->mouse.lX, ITEM_ID_XAXIS, generic_axis_get_state); @@ -941,10 +942,10 @@ static kt_table * sdlinput_read_keymap(running_machine *machine) char sks[21]; char kns[21]; - if (!options_get_bool(mame_options(), SDLOPTION_KEYMAP)) + if (!options_get_bool(machine->options(), SDLOPTION_KEYMAP)) return sdl_key_trans_table; - keymap_filename = (char *)options_get_string(mame_options(), SDLOPTION_KEYMAP_FILE); + keymap_filename = (char *)options_get_string(machine->options(), SDLOPTION_KEYMAP_FILE); mame_printf_verbose("Keymap: Start reading keymap_file %s\n", keymap_filename); keymap_file = fopen(keymap_filename, "r"); @@ -1103,8 +1104,9 @@ void sdlinput_init(running_machine *machine) app_has_mouse_focus = 1; // we need pause and exit callbacks - add_pause_callback(machine, sdlinput_pause); - add_exit_callback(machine, sdlinput_exit); + machine->add_notifier(MACHINE_NOTIFY_PAUSE, sdlinput_pause); + machine->add_notifier(MACHINE_NOTIFY_RESUME, sdlinput_resume); + machine->add_notifier(MACHINE_NOTIFY_EXIT, sdlinput_exit); // allocate a lock for input synchronizations input_lock = osd_lock_alloc(); @@ -1123,7 +1125,7 @@ void sdlinput_init(running_machine *machine) } // get Sixaxis special mode info - sixaxis_mode = options_get_bool(mame_options(), SDLOPTION_SIXAXIS); + sixaxis_mode = options_get_bool(machine->options(), SDLOPTION_SIXAXIS); // register the joysticks sdlinput_register_joysticks(machine); @@ -1140,10 +1142,16 @@ void sdlinput_init(running_machine *machine) // sdlinput_pause //============================================================ -static void sdlinput_pause(running_machine *machine, int paused) +static void sdlinput_pause(running_machine &machine) { // keep track of the paused state - input_paused = paused; + input_paused = true; +} + +static void sdlinput_resume(running_machine &machine) +{ + // keep track of the paused state + input_paused = false; } @@ -1151,14 +1159,14 @@ static void sdlinput_pause(running_machine *machine, int paused) // sdlinput_exit //============================================================ -static void sdlinput_exit(running_machine *machine) +static void sdlinput_exit(running_machine &machine) { // free the lock osd_lock_free(input_lock); // deregister - sdlinput_deregister_joysticks(machine); + sdlinput_deregister_joysticks(&machine); // free all devices device_list_free_devices(&keyboard_list); @@ -1457,7 +1465,7 @@ void sdlinput_poll(running_machine *machine) } break; case SDL_QUIT: - mame_schedule_exit(machine); + machine->schedule_exit(); break; case SDL_VIDEORESIZE: sdlwindow_resize(sdl_window_list, event.resize.w, event.resize.h); @@ -1485,7 +1493,7 @@ void sdlinput_poll(running_machine *machine) switch (event.window.event) { case SDL_WINDOWEVENT_CLOSE: - mame_schedule_exit(machine); + machine->schedule_exit(); break; case SDL_WINDOWEVENT_LEAVE: ui_input_push_mouse_leave_event(machine, window->target); diff --git a/src/osd/sdl/output.c b/src/osd/sdl/output.c index e28a1713fcd..ead4a52d3b2 100644 --- a/src/osd/sdl/output.c +++ b/src/osd/sdl/output.c @@ -75,7 +75,7 @@ void sdloutput_init(running_machine *machine) { int fildes; - add_exit_callback(machine, sdloutput_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, sdloutput_exit); fildes = open(SDLMAME_OUTPUT, O_RDWR | O_NONBLOCK); @@ -101,11 +101,11 @@ void sdloutput_init(running_machine *machine) // winoutput_exit //============================================================ -static void sdloutput_exit(running_machine *machine) +static void sdloutput_exit(running_machine &machine) { if (output != NULL) { - fprintf(output, "MAME " PID_FMT " STOP %s\n", osd_getpid(), machine->gamedrv->name); + fprintf(output, "MAME " PID_FMT " STOP %s\n", osd_getpid(), machine.m_game.name); fflush(output); fclose(output); output = NULL; diff --git a/src/osd/sdl/sdlmain.c b/src/osd/sdl/sdlmain.c index c611b07d4b3..4ec754c198a 100644 --- a/src/osd/sdl/sdlmain.c +++ b/src/osd/sdl/sdlmain.c @@ -327,7 +327,7 @@ int main(int argc, char *argv[]) // output_oslog //============================================================ -static void output_oslog(running_machine *machine, const char *buffer) +static void output_oslog(running_machine &machine, const char *buffer) { fputs(buffer, stderr); } @@ -338,7 +338,7 @@ static void output_oslog(running_machine *machine, const char *buffer) // osd_exit //============================================================ -static void osd_exit(running_machine *machine) +static void osd_exit(running_machine &machine) { if (!SDLMAME_INIT_IN_WORKER_THREAD) @@ -471,14 +471,14 @@ void osd_init(running_machine *machine) const char *stemp; // Some driver options - must be before audio init! - stemp = options_get_string(mame_options(), SDLOPTION_AUDIODRIVER); + stemp = options_get_string(machine->options(), SDLOPTION_AUDIODRIVER); if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0) { mame_printf_verbose("Setting SDL audiodriver '%s' ...\n", stemp); osd_setenv(SDLENV_AUDIODRIVER, stemp, 1); } - stemp = options_get_string(mame_options(), SDLOPTION_VIDEODRIVER); + stemp = options_get_string(machine->options(), SDLOPTION_VIDEODRIVER); if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0) { mame_printf_verbose("Setting SDL videodriver '%s' ...\n", stemp); @@ -487,7 +487,7 @@ void osd_init(running_machine *machine) if (SDL_VERSION_ATLEAST(1,3,0)) { - stemp = options_get_string(mame_options(), SDLOPTION_RENDERDRIVER); + stemp = options_get_string(machine->options(), SDLOPTION_RENDERDRIVER); if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0) { mame_printf_verbose("Setting SDL renderdriver '%s' ...\n", stemp); @@ -500,7 +500,7 @@ void osd_init(running_machine *machine) */ /* FIXME: move lib loading code from drawogl.c here */ - stemp = options_get_string(mame_options(), SDLOPTION_GL_LIB); + stemp = options_get_string(machine->options(), SDLOPTION_GL_LIB); if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0) { osd_setenv("SDL_VIDEO_GL_DRIVER", stemp, 1); @@ -508,7 +508,7 @@ void osd_init(running_machine *machine) } /* get number of processors */ - stemp = options_get_string(mame_options(), SDLOPTION_NUMPROCESSORS); + stemp = options_get_string(machine->options(), SDLOPTION_NUMPROCESSORS); sdl_num_processors = 0; @@ -537,7 +537,7 @@ void osd_init(running_machine *machine) osd_sdl_info(); } // must be before sdlvideo_init! - add_exit_callback(machine, osd_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, osd_exit); defines_verbose(); @@ -545,13 +545,13 @@ void osd_init(running_machine *machine) if (machine->debug_flags & DEBUG_FLAG_OSD_ENABLED) { mame_printf_error("sdlmame: -debug not supported on X11-less builds\n\n"); - osd_exit(machine); + osd_exit(*machine); exit(-1); } if (sdlvideo_init(machine)) { - osd_exit(machine); + osd_exit(*machine); mame_printf_error("sdlvideo_init: Initialization failed!\n\n\n"); fflush(stderr); fflush(stdout); @@ -564,8 +564,8 @@ void osd_init(running_machine *machine) sdloutput_init(machine); - if (options_get_bool(mame_options(), SDLOPTION_OSLOG)) - add_logerror_callback(machine, output_oslog); + if (options_get_bool(machine->options(), SDLOPTION_OSLOG)) + machine->add_logerror_callback(output_oslog); #if (SDL_VERSION_ATLEAST(1,3,0)) SDL_EventState(SDL_TEXTINPUT, SDL_TRUE); diff --git a/src/osd/sdl/sound.c b/src/osd/sdl/sound.c index 78b3f74274e..3f31992444a 100644 --- a/src/osd/sdl/sound.c +++ b/src/osd/sdl/sound.c @@ -73,7 +73,7 @@ static int sdl_init(running_machine *machine); static void sdl_kill(running_machine *machine); static int sdl_create_buffers(void); static void sdl_destroy_buffers(void); -static void sdl_cleanup_audio(running_machine *machine); +static void sdl_cleanup_audio(running_machine &machine); static void sdl_callback(void *userdata, Uint8 *stream, int len); @@ -93,7 +93,7 @@ void sdlaudio_init(running_machine *machine) if (sdl_init(machine)) return; - add_exit_callback(machine, sdl_cleanup_audio); + machine->add_notifier(MACHINE_NOTIFY_EXIT, sdl_cleanup_audio); // set the startup volume osd_set_mastervolume(attenuation); } @@ -106,14 +106,14 @@ void sdlaudio_init(running_machine *machine) // osd_stop_audio_stream //============================================================ -static void sdl_cleanup_audio(running_machine *machine) +static void sdl_cleanup_audio(running_machine &machine) { // if nothing to do, don't do it - if (machine->sample_rate == 0) + if (machine.sample_rate == 0) return; // kill the buffers and dsound - sdl_kill(machine); + sdl_kill(&machine); sdl_destroy_buffers(); // print out over/underflow stats @@ -428,7 +428,7 @@ static int sdl_init(running_machine *machine) if (initialized_audio) { - sdl_cleanup_audio(machine); + sdl_cleanup_audio(*machine); } mame_printf_verbose("Audio: Start initialization\n"); @@ -464,7 +464,7 @@ static int sdl_init(running_machine *machine) sdl_xfer_samples = obtained.samples; - audio_latency = options_get_int(mame_options(), SDLOPTION_AUDIO_LATENCY); + audio_latency = options_get_int(machine->options(), SDLOPTION_AUDIO_LATENCY); // pin audio latency if (audio_latency > MAX_AUDIO_LATENCY) diff --git a/src/osd/sdl/video.c b/src/osd/sdl/video.c index 017c7f2b20a..deb60f0a51b 100644 --- a/src/osd/sdl/video.c +++ b/src/osd/sdl/video.c @@ -88,7 +88,7 @@ static bitmap_t *effect_bitmap; // PROTOTYPES //============================================================ -static void video_exit(running_machine *machine); +static void video_exit(running_machine &machine); static void init_monitors(void); static sdl_monitor_info *pick_monitor(int index); @@ -113,13 +113,13 @@ int sdlvideo_init(running_machine *machine) extract_video_config(machine); // ensure we get called on the way out - add_exit_callback(machine, video_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, video_exit); // set up monitors first init_monitors(); // we need the beam width in a float, contrary to what the core does. - video_config.beamwidth = options_get_float(mame_options(), OPTION_BEAM); + video_config.beamwidth = options_get_float(machine->options(), OPTION_BEAM); // initialize the window system so we can make windows if (sdlwindow_init(machine)) @@ -150,7 +150,7 @@ error: // video_exit //============================================================ -static void video_exit(running_machine *machine) +static void video_exit(running_machine &machine) { // free the overlay effect global_free(effect_bitmap); @@ -631,22 +631,22 @@ static void extract_video_config(running_machine *machine) { const char *stemp; - video_config.perftest = options_get_bool(mame_options(), SDLOPTION_SDLVIDEOFPS); + video_config.perftest = options_get_bool(machine->options(), SDLOPTION_SDLVIDEOFPS); // global options: extract the data - video_config.windowed = options_get_bool(mame_options(), SDLOPTION_WINDOW); - video_config.keepaspect = options_get_bool(mame_options(), SDLOPTION_KEEPASPECT); - video_config.numscreens = options_get_int(mame_options(), SDLOPTION_NUMSCREENS); - video_config.fullstretch = options_get_bool(mame_options(), SDLOPTION_UNEVENSTRETCH); + video_config.windowed = options_get_bool(machine->options(), SDLOPTION_WINDOW); + video_config.keepaspect = options_get_bool(machine->options(), SDLOPTION_KEEPASPECT); + video_config.numscreens = options_get_int(machine->options(), SDLOPTION_NUMSCREENS); + video_config.fullstretch = options_get_bool(machine->options(), SDLOPTION_UNEVENSTRETCH); #ifdef SDLMAME_X11 - video_config.restrictonemonitor = !options_get_bool(mame_options(), SDLOPTION_USEALLHEADS); + video_config.restrictonemonitor = !options_get_bool(machine->options(), SDLOPTION_USEALLHEADS); #endif if (machine->debug_flags & DEBUG_FLAG_OSD_ENABLED) video_config.windowed = TRUE; - stemp = options_get_string(mame_options(), SDLOPTION_EFFECT); + stemp = options_get_string(machine->options(), SDLOPTION_EFFECT); if (stemp != NULL && strcmp(stemp, "none") != 0) load_effect_overlay(machine, stemp); @@ -654,7 +654,7 @@ static void extract_video_config(running_machine *machine) video_config.novideo = 0; // d3d options: extract the data - stemp = options_get_string(mame_options(), SDLOPTION_VIDEO); + stemp = options_get_string(machine->options(), SDLOPTION_VIDEO); if (strcmp(stemp, SDLOPTVAL_SOFT) == 0) video_config.mode = VIDEO_MODE_SOFT; else if (strcmp(stemp, SDLOPTVAL_NONE) == 0) @@ -662,7 +662,7 @@ static void extract_video_config(running_machine *machine) video_config.mode = VIDEO_MODE_SOFT; video_config.novideo = 1; - if (options_get_int(mame_options(), OPTION_SECONDS_TO_RUN) == 0) + if (options_get_int(machine->options(), OPTION_SECONDS_TO_RUN) == 0) mame_printf_warning("Warning: -video none doesn't make much sense without -seconds_to_run\n"); } else if (USE_OPENGL && (strcmp(stemp, SDLOPTVAL_OPENGL) == 0)) @@ -683,19 +683,19 @@ static void extract_video_config(running_machine *machine) video_config.mode = VIDEO_MODE_SOFT; } - video_config.switchres = options_get_bool(mame_options(), SDLOPTION_SWITCHRES); - video_config.centerh = options_get_bool(mame_options(), SDLOPTION_CENTERH); - video_config.centerv = options_get_bool(mame_options(), SDLOPTION_CENTERV); - video_config.waitvsync = options_get_bool(mame_options(), SDLOPTION_WAITVSYNC); + video_config.switchres = options_get_bool(machine->options(), SDLOPTION_SWITCHRES); + video_config.centerh = options_get_bool(machine->options(), SDLOPTION_CENTERH); + video_config.centerv = options_get_bool(machine->options(), SDLOPTION_CENTERV); + video_config.waitvsync = options_get_bool(machine->options(), SDLOPTION_WAITVSYNC); if (USE_OPENGL || SDL_VERSION_ATLEAST(1,3,0)) { - video_config.filter = options_get_bool(mame_options(), SDLOPTION_FILTER); + video_config.filter = options_get_bool(machine->options(), SDLOPTION_FILTER); } if (USE_OPENGL) { - video_config.prescale = options_get_int(mame_options(), SDLOPTION_PRESCALE); + video_config.prescale = options_get_int(machine->options(), SDLOPTION_PRESCALE); if (video_config.prescale < 1 || video_config.prescale > 3) { mame_printf_warning("Invalid prescale option, reverting to '1'\n"); @@ -703,17 +703,17 @@ static void extract_video_config(running_machine *machine) } // default to working video please video_config.prefer16bpp_tex = 0; - video_config.forcepow2texture = options_get_bool(mame_options(), SDLOPTION_GL_FORCEPOW2TEXTURE)==1; - video_config.allowtexturerect = options_get_bool(mame_options(), SDLOPTION_GL_NOTEXTURERECT)==0; - video_config.vbo = options_get_bool(mame_options(), SDLOPTION_GL_VBO); - video_config.pbo = options_get_bool(mame_options(), SDLOPTION_GL_PBO); - video_config.glsl = options_get_bool(mame_options(), SDLOPTION_GL_GLSL); + video_config.forcepow2texture = options_get_bool(machine->options(), SDLOPTION_GL_FORCEPOW2TEXTURE)==1; + video_config.allowtexturerect = options_get_bool(machine->options(), SDLOPTION_GL_NOTEXTURERECT)==0; + video_config.vbo = options_get_bool(machine->options(), SDLOPTION_GL_VBO); + video_config.pbo = options_get_bool(machine->options(), SDLOPTION_GL_PBO); + video_config.glsl = options_get_bool(machine->options(), SDLOPTION_GL_GLSL); if ( video_config.glsl ) { int i; static char buffer[20]; // gl_glsl_filter[0..9]? - video_config.glsl_filter = options_get_int (mame_options(), SDLOPTION_GLSL_FILTER); + video_config.glsl_filter = options_get_int (machine->options(), SDLOPTION_GLSL_FILTER); video_config.glsl_shader_mamebm_num=0; @@ -721,7 +721,7 @@ static void extract_video_config(running_machine *machine) { snprintf(buffer, 18, SDLOPTION_SHADER_MAME("%d"), i); buffer[17]=0; - stemp = options_get_string(mame_options(), buffer); + stemp = options_get_string(machine->options(), buffer); if (stemp && strcmp(stemp, SDLOPTVAL_NONE) != 0 && strlen(stemp)>0) { video_config.glsl_shader_mamebm[i] = (char *) malloc(strlen(stemp)+1); @@ -738,7 +738,7 @@ static void extract_video_config(running_machine *machine) { snprintf(buffer, 20, SDLOPTION_SHADER_SCREEN("%d"), i); buffer[19]=0; - stemp = options_get_string(mame_options(), buffer); + stemp = options_get_string(machine->options(), buffer); if (stemp && strcmp(stemp, SDLOPTVAL_NONE) != 0 && strlen(stemp)>0) { video_config.glsl_shader_scrn[i] = (char *) malloc(strlen(stemp)+1); @@ -749,13 +749,13 @@ static void extract_video_config(running_machine *machine) } } - video_config.glsl_vid_attributes = options_get_int (mame_options(), SDLOPTION_GL_GLSL_VID_ATTR); + video_config.glsl_vid_attributes = options_get_int (machine->options(), SDLOPTION_GL_GLSL_VID_ATTR); { // Disable feature: glsl_vid_attributes, as long we have the gamma calculation // disabled within the direct shaders .. -> too slow. // IMHO the gamma setting should be done global anyways, and for the whole system, // not just MAME .. - float gamma = options_get_float(mame_options(), OPTION_GAMMA); + float gamma = options_get_float(machine->options(), OPTION_GAMMA); if (gamma != 1.0 && video_config.glsl_vid_attributes && video_config.glsl) { video_config.glsl_vid_attributes = FALSE; @@ -796,7 +796,7 @@ static void extract_video_config(running_machine *machine) } #endif // yuv settings ... - stemp = options_get_string(mame_options(), SDLOPTION_SCALEMODE); + stemp = options_get_string(machine->options(), SDLOPTION_SCALEMODE); video_config.scale_mode = drawsdl_scale_mode(stemp); if (video_config.scale_mode < 0) { diff --git a/src/osd/sdl/window.c b/src/osd/sdl/window.c index 3c8ca17ed40..ded2b3d8b18 100644 --- a/src/osd/sdl/window.c +++ b/src/osd/sdl/window.c @@ -110,7 +110,7 @@ struct _worker_param { // PROTOTYPES //============================================================ -static void sdlwindow_exit(running_machine *machine); +static void sdlwindow_exit(running_machine &machine); static void sdlwindow_video_window_destroy(running_machine *machine, sdl_window_info *window); static OSDWORK_CALLBACK( draw_video_contents_wt ); static OSDWORK_CALLBACK( sdlwindow_video_window_destroy_wt ); @@ -206,13 +206,13 @@ int sdlwindow_init(running_machine *machine) { mame_printf_verbose("Enter sdlwindow_init\n"); // determine if we are using multithreading or not - multithreading_enabled = options_get_bool(mame_options(), SDLOPTION_MULTITHREADING); + multithreading_enabled = options_get_bool(machine->options(), SDLOPTION_MULTITHREADING); // get the main thread ID before anything else main_threadid = SDL_ThreadID(); // ensure we get called on the way out - add_exit_callback(machine, sdlwindow_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, sdlwindow_exit); // if multithreading, create a thread to run the windows if (multithreading_enabled) @@ -292,7 +292,7 @@ static OSDWORK_CALLBACK( sdlwindow_exit_wt ) } -static void sdlwindow_exit(running_machine *machine) +static void sdlwindow_exit(running_machine &machine) { ASSERT_MAIN_THREAD(); @@ -303,7 +303,7 @@ static void sdlwindow_exit(running_machine *machine) { sdl_window_info *temp = sdl_window_list; sdl_window_list = temp->next; - sdlwindow_video_window_destroy(machine, temp); + sdlwindow_video_window_destroy(&machine, temp); } // if we're multithreaded, clean up the window thread @@ -676,7 +676,7 @@ int sdlwindow_video_window_create(running_machine *machine, int index, sdl_monit // set the initial maximized state // FIXME: Does not belong here - window->startmaximized = options_get_bool(mame_options(), SDLOPTION_MAXIMIZE); + window->startmaximized = options_get_bool(machine->options(), SDLOPTION_MAXIMIZE); if (!window->fullscreen) { @@ -704,7 +704,7 @@ int sdlwindow_video_window_create(running_machine *machine, int index, sdl_monit // set the specific view sprintf(option, SDLOPTION_VIEW("%d"), index); - set_starting_view(machine, index, window, options_get_string(mame_options(), option)); + set_starting_view(machine, index, window, options_get_string(machine->options(), option)); // make the window title if (video_config.numscreens == 1) @@ -1013,7 +1013,7 @@ void sdlwindow_video_window_update(running_machine *machine, sdl_window_info *wi static void set_starting_view(running_machine *machine, int index, sdl_window_info *window, const char *view) { - const char *defview = options_get_string(mame_options(), SDLOPTION_VIEW( )); + const char *defview = options_get_string(machine->options(), SDLOPTION_VIEW( )); int viewindex; ASSERT_MAIN_THREAD(); diff --git a/src/osd/windows/debugwin.c b/src/osd/windows/debugwin.c index 4ec70012892..de0482a2532 100644 --- a/src/osd/windows/debugwin.c +++ b/src/osd/windows/debugwin.c @@ -506,7 +506,7 @@ void debugwin_show(int type) void debugwin_update_during_game(running_machine *machine) { // if we're running live, do some checks - if (!winwindow_has_focus() && !debug_cpu_is_stopped(machine) && mame_get_phase(machine) == MAME_PHASE_RUNNING) + if (!winwindow_has_focus() && !debug_cpu_is_stopped(machine) && machine->phase() == MACHINE_PHASE_RUNNING) { // see if the interrupt key is pressed and break if it is if (debugwin_seq_pressed(machine)) @@ -2666,18 +2666,18 @@ static int global_handle_command(debugwin_info *info, WPARAM wparam, LPARAM lpar return 1; case ID_HARD_RESET: - mame_schedule_hard_reset(info->machine); + info->machine->schedule_hard_reset(); return 1; case ID_SOFT_RESET: - mame_schedule_soft_reset(info->machine); + info->machine->schedule_soft_reset(); debug_cpu_go(info->machine, ~0); return 1; case ID_EXIT: if (info->focuswnd != NULL) SetFocus(info->focuswnd); - mame_schedule_exit(info->machine); + info->machine->schedule_exit(); return 1; } diff --git a/src/osd/windows/input.c b/src/osd/windows/input.c index 5448395ac8b..c1c3f7e3dc7 100644 --- a/src/osd/windows/input.c +++ b/src/osd/windows/input.c @@ -250,8 +250,9 @@ static const TCHAR *const default_axis_name[] = // PROTOTYPES //============================================================ -static void wininput_pause(running_machine *machine, int paused); -static void wininput_exit(running_machine *machine); +static void wininput_pause(running_machine &machine); +static void wininput_resume(running_machine &machine); +static void wininput_exit(running_machine &machine); // device list management static void device_list_poll_devices(device_info *devlist_head); @@ -267,13 +268,13 @@ static INT32 generic_axis_get_state(void *device_internal, void *item_internal); // Win32-specific input code static void win32_init(running_machine *machine); -static void win32_exit(running_machine *machine); +static void win32_exit(running_machine &machine); static void win32_keyboard_poll(device_info *devinfo); static void win32_lightgun_poll(device_info *devinfo); // DirectInput-specific code static void dinput_init(running_machine *machine); -static void dinput_exit(running_machine *machine); +static void dinput_exit(running_machine &machine); static HRESULT dinput_set_dword_property(LPDIRECTINPUTDEVICE device, REFGUID property_guid, DWORD object, DWORD how, DWORD value); static device_info *dinput_device_create(running_machine *machine, device_info **devlist_head_ptr, LPCDIDEVICEINSTANCE instance, LPCDIDATAFORMAT format1, LPCDIDATAFORMAT format2, DWORD cooperative_level); static void dinput_device_release(device_info *devinfo); @@ -289,7 +290,7 @@ static INT32 dinput_joystick_pov_get_state(void *device_internal, void *item_int // RawInput-specific code static void rawinput_init(running_machine *machine); -static void rawinput_exit(running_machine *machine); +static void rawinput_exit(running_machine &machine); static device_info *rawinput_device_create(running_machine *machine, device_info **devlist_head_ptr, PRAWINPUTDEVICELIST device); static void rawinput_device_release(device_info *info); static TCHAR *rawinput_device_improve_name(TCHAR *name); @@ -504,15 +505,16 @@ INLINE INT32 normalize_absolute_axis(INT32 raw, INT32 rawmin, INT32 rawmax) void wininput_init(running_machine *machine) { // we need pause and exit callbacks - add_pause_callback(machine, wininput_pause); - add_exit_callback(machine, wininput_exit); + machine->add_notifier(MACHINE_NOTIFY_PAUSE, wininput_pause); + machine->add_notifier(MACHINE_NOTIFY_RESUME, wininput_resume); + machine->add_notifier(MACHINE_NOTIFY_EXIT, wininput_exit); // allocate a lock for input synchronizations, since messages sometimes come from another thread input_lock = osd_lock_alloc(); assert_always(input_lock != NULL, "Failed to allocate input_lock"); // decode the options - lightgun_shared_axis_mode = options_get_bool(mame_options(), WINOPTION_DUAL_LIGHTGUN); + lightgun_shared_axis_mode = options_get_bool(machine->options(), WINOPTION_DUAL_LIGHTGUN); // initialize RawInput and DirectInput (RawInput first so we can fall back) rawinput_init(machine); @@ -529,10 +531,16 @@ void wininput_init(running_machine *machine) // wininput_pause //============================================================ -static void wininput_pause(running_machine *machine, int paused) +static void wininput_pause(running_machine &machine) { // keep track of the paused state - input_paused = paused; + input_paused = true; +} + +static void wininput_resume(running_machine &machine) +{ + // keep track of the paused state + input_paused = false; } @@ -540,7 +548,7 @@ static void wininput_pause(running_machine *machine, int paused) // wininput_exit //============================================================ -static void wininput_exit(running_machine *machine) +static void wininput_exit(running_machine &machine) { // acquire the lock and turn off input (this ensures everyone is done) osd_lock_acquire(input_lock); @@ -958,7 +966,7 @@ static void win32_init(running_machine *machine) return; // we need an exit callback - add_exit_callback(machine, win32_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, win32_exit); // allocate two lightgun devices for (gunnum = 0; gunnum < 2; gunnum++) @@ -998,7 +1006,7 @@ static void win32_init(running_machine *machine) // win32_exit //============================================================ -static void win32_exit(running_machine *machine) +static void win32_exit(running_machine &machine) { // skip if we're in shared axis mode if (!lightgun_shared_axis_mode) @@ -1126,7 +1134,7 @@ static void dinput_init(running_machine *machine) mame_printf_verbose("DirectInput: Using DirectInput %d\n", dinput_version >> 8); // we need an exit callback - add_exit_callback(machine, dinput_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, dinput_exit); // initialize keyboard devices, but only if we don't have any yet if (keyboard_list == NULL) @@ -1157,7 +1165,7 @@ static void dinput_init(running_machine *machine) // dinput_exit //============================================================ -static void dinput_exit(running_machine *machine) +static void dinput_exit(running_machine &machine) { // release all our devices while (joystick_list != NULL && joystick_list->dinput.device != NULL) @@ -1663,7 +1671,7 @@ static void rawinput_init(running_machine *machine) HMODULE user32; // we need pause and exit callbacks - add_exit_callback(machine, rawinput_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, rawinput_exit); // look in user32 for the raw input APIs user32 = LoadLibrary(TEXT("user32.dll")); @@ -1739,7 +1747,7 @@ error: // rawinput_exit //============================================================ -static void rawinput_exit(running_machine *machine) +static void rawinput_exit(running_machine &machine) { // release all our devices while (lightgun_list != NULL && lightgun_list->rawinput.device != NULL) diff --git a/src/osd/windows/output.c b/src/osd/windows/output.c index eb2e1b3635f..fe5ee23ca5e 100644 --- a/src/osd/windows/output.c +++ b/src/osd/windows/output.c @@ -100,7 +100,7 @@ static UINT om_mame_get_id_string; // FUNCTION PROTOTYPES //============================================================ -static void winoutput_exit(running_machine *machine); +static void winoutput_exit(running_machine &machine); static int create_window_class(void); static LRESULT CALLBACK output_window_proc(HWND wnd, UINT message, WPARAM wparam, LPARAM lparam); static LRESULT register_client(HWND hwnd, LPARAM id); @@ -119,7 +119,7 @@ void winoutput_init(running_machine *machine) int result; // ensure we get cleaned up - add_exit_callback(machine, winoutput_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, winoutput_exit); // reset globals clientlist = NULL; @@ -172,7 +172,7 @@ void winoutput_init(running_machine *machine) // winoutput_exit //============================================================ -static void winoutput_exit(running_machine *machine) +static void winoutput_exit(running_machine &machine) { // free all the clients while (clientlist != NULL) diff --git a/src/osd/windows/sound.c b/src/osd/windows/sound.c index 2116f1ddc0e..ad329255159 100644 --- a/src/osd/windows/sound.c +++ b/src/osd/windows/sound.c @@ -100,7 +100,7 @@ static int buffer_overflows; // PROTOTYPES //============================================================ -static void sound_exit(running_machine *machine); +static void sound_exit(running_machine &machine); static HRESULT dsound_init(running_machine *machine); static void dsound_kill(void); static HRESULT dsound_create_buffers(void); @@ -115,11 +115,11 @@ static void dsound_destroy_buffers(void); void winsound_init(running_machine *machine) { // if no sound, don't create anything - if (!options_get_bool(mame_options(), OPTION_SOUND)) + if (!options_get_bool(machine->options(), OPTION_SOUND)) return; // ensure we get called on the way out - add_exit_callback(machine, sound_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, sound_exit); // attempt to initialize directsound // don't make it fatal if we can't -- we'll just run without sound @@ -131,7 +131,7 @@ void winsound_init(running_machine *machine) // sound_exit //============================================================ -static void sound_exit(running_machine *machine) +static void sound_exit(running_machine &machine) { // kill the buffers and dsound dsound_destroy_buffers(); @@ -305,7 +305,7 @@ static HRESULT dsound_init(running_machine *machine) stream_format.nAvgBytesPerSec = stream_format.nSamplesPerSec * stream_format.nBlockAlign; // compute the buffer size based on the output sample rate - stream_buffer_size = stream_format.nSamplesPerSec * stream_format.nBlockAlign * options_get_int(mame_options(), WINOPTION_AUDIO_LATENCY) / 10; + stream_buffer_size = stream_format.nSamplesPerSec * stream_format.nBlockAlign * options_get_int(machine->options(), WINOPTION_AUDIO_LATENCY) / 10; stream_buffer_size = (stream_buffer_size / 1024) * 1024; if (stream_buffer_size < 1024) stream_buffer_size = 1024; diff --git a/src/osd/windows/video.c b/src/osd/windows/video.c index 5f1388d2245..ad3bdf67dc4 100644 --- a/src/osd/windows/video.c +++ b/src/osd/windows/video.c @@ -96,7 +96,7 @@ static bitmap_t *effect_bitmap; // PROTOTYPES //============================================================ -static void winvideo_exit(running_machine *machine); +static void winvideo_exit(running_machine &machine); static void init_monitors(void); static BOOL CALLBACK monitor_enum_callback(HMONITOR handle, HDC dc, LPRECT rect, LPARAM data); static win_monitor_info *pick_monitor(int index); @@ -119,7 +119,7 @@ void winvideo_init(running_machine *machine) int index; // ensure we get called on the way out - add_exit_callback(machine, winvideo_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, winvideo_exit); // extract data from the options extract_video_config(machine); @@ -146,7 +146,7 @@ void winvideo_init(running_machine *machine) // winvideo_exit //============================================================ -static void winvideo_exit(running_machine *machine) +static void winvideo_exit(running_machine &machine) { // free the overlay effect global_free(effect_bitmap); @@ -399,15 +399,15 @@ static void extract_video_config(running_machine *machine) const char *stemp; // global options: extract the data - video_config.windowed = options_get_bool(mame_options(), WINOPTION_WINDOW); - video_config.prescale = options_get_int(mame_options(), WINOPTION_PRESCALE); - video_config.keepaspect = options_get_bool(mame_options(), WINOPTION_KEEPASPECT); - video_config.numscreens = options_get_int(mame_options(), WINOPTION_NUMSCREENS); + video_config.windowed = options_get_bool(machine->options(), WINOPTION_WINDOW); + video_config.prescale = options_get_int(machine->options(), WINOPTION_PRESCALE); + video_config.keepaspect = options_get_bool(machine->options(), WINOPTION_KEEPASPECT); + video_config.numscreens = options_get_int(machine->options(), WINOPTION_NUMSCREENS); // if we are in debug mode, never go full screen if (machine->debug_flags & DEBUG_FLAG_OSD_ENABLED) video_config.windowed = TRUE; - stemp = options_get_string(mame_options(), WINOPTION_EFFECT); + stemp = options_get_string(machine->options(), WINOPTION_EFFECT); if (strcmp(stemp, "none") != 0) load_effect_overlay(machine, stemp); @@ -418,7 +418,7 @@ static void extract_video_config(running_machine *machine) get_resolution(WINOPTION_RESOLUTION3, &video_config.window[3], TRUE); // video options: extract the data - stemp = options_get_string(mame_options(), WINOPTION_VIDEO); + stemp = options_get_string(machine->options(), WINOPTION_VIDEO); if (strcmp(stemp, "d3d") == 0) video_config.mode = VIDEO_MODE_D3D; else if (strcmp(stemp, "ddraw") == 0) @@ -428,7 +428,7 @@ static void extract_video_config(running_machine *machine) else if (strcmp(stemp, "none") == 0) { video_config.mode = VIDEO_MODE_NONE; - if (options_get_int(mame_options(), OPTION_SECONDS_TO_RUN) == 0) + if (options_get_int(machine->options(), OPTION_SECONDS_TO_RUN) == 0) mame_printf_warning("Warning: -video none doesn't make much sense without -seconds_to_run\n"); } else @@ -436,16 +436,16 @@ static void extract_video_config(running_machine *machine) mame_printf_warning("Invalid video value %s; reverting to gdi\n", stemp); video_config.mode = VIDEO_MODE_GDI; } - video_config.waitvsync = options_get_bool(mame_options(), WINOPTION_WAITVSYNC); - video_config.syncrefresh = options_get_bool(mame_options(), WINOPTION_SYNCREFRESH); - video_config.triplebuf = options_get_bool(mame_options(), WINOPTION_TRIPLEBUFFER); - video_config.switchres = options_get_bool(mame_options(), WINOPTION_SWITCHRES); + video_config.waitvsync = options_get_bool(machine->options(), WINOPTION_WAITVSYNC); + video_config.syncrefresh = options_get_bool(machine->options(), WINOPTION_SYNCREFRESH); + video_config.triplebuf = options_get_bool(machine->options(), WINOPTION_TRIPLEBUFFER); + video_config.switchres = options_get_bool(machine->options(), WINOPTION_SWITCHRES); // ddraw options: extract the data - video_config.hwstretch = options_get_bool(mame_options(), WINOPTION_HWSTRETCH); + video_config.hwstretch = options_get_bool(machine->options(), WINOPTION_HWSTRETCH); // d3d options: extract the data - video_config.filter = options_get_bool(mame_options(), WINOPTION_FILTER); + video_config.filter = options_get_bool(machine->options(), WINOPTION_FILTER); if (video_config.prescale == 0) video_config.prescale = 1; @@ -454,11 +454,11 @@ static void extract_video_config(running_machine *machine) // per-window options: sanity check values // d3d options: sanity check values - options_get_int(mame_options(), WINOPTION_D3DVERSION); + options_get_int(machine->options(), WINOPTION_D3DVERSION); - options_get_float(mame_options(), WINOPTION_FULLSCREENBRIGHTNESS); - options_get_float(mame_options(), WINOPTION_FULLLSCREENCONTRAST); - options_get_float(mame_options(), WINOPTION_FULLSCREENGAMMA); + options_get_float(machine->options(), WINOPTION_FULLSCREENBRIGHTNESS); + options_get_float(machine->options(), WINOPTION_FULLLSCREENCONTRAST); + options_get_float(machine->options(), WINOPTION_FULLSCREENGAMMA); } diff --git a/src/osd/windows/window.c b/src/osd/windows/window.c index 61d75e5ec34..3dacac370fe 100644 --- a/src/osd/windows/window.c +++ b/src/osd/windows/window.c @@ -155,7 +155,7 @@ static HANDLE window_thread_ready_event; // PROTOTYPES //============================================================ -static void winwindow_exit(running_machine *machine); +static void winwindow_exit(running_machine &machine); static void winwindow_video_window_destroy(win_window_info *window); static void draw_video_contents(win_window_info *window, HDC dc, int update); @@ -228,13 +228,13 @@ void winwindow_init(running_machine *machine) size_t temp; // determine if we are using multithreading or not - multithreading_enabled = options_get_bool(mame_options(), WINOPTION_MULTITHREADING); + multithreading_enabled = options_get_bool(machine->options(), WINOPTION_MULTITHREADING); // get the main thread ID before anything else main_threadid = GetCurrentThreadId(); // ensure we get called on the way out - add_exit_callback(machine, winwindow_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, winwindow_exit); // set up window class and register it create_window_class(); @@ -296,12 +296,12 @@ void winwindow_init(running_machine *machine) // (main thread) //============================================================ -static void winwindow_exit(running_machine *machine) +static void winwindow_exit(running_machine &machine) { assert(GetCurrentThreadId() == main_threadid); // possibly kill the debug window - if (machine->debug_flags & DEBUG_FLAG_OSD_ENABLED) + if (machine.debug_flags & DEBUG_FLAG_OSD_ENABLED) debugwin_destroy_windows(); // free all the windows @@ -475,7 +475,7 @@ void winwindow_dispatch_message(running_machine *machine, MSG *message) { // special case for quit case WM_QUIT: - mame_schedule_exit(machine); + machine->schedule_exit(); break; // temporary pause from the window thread @@ -565,7 +565,7 @@ void winwindow_update_cursor_state(running_machine *machine) // 2. we also hide the cursor in full screen mode and when the window doesn't have a menu // 3. we also hide the cursor in windowed mode if we're not paused and // the input system requests it - if (winwindow_has_focus() && ((!video_config.windowed && !win_has_menu(win_window_list)) || (!mame_is_paused(machine) && wininput_should_hide_mouse()))) + if (winwindow_has_focus() && ((!video_config.windowed && !win_has_menu(win_window_list)) || (!machine->paused() && wininput_should_hide_mouse()))) { win_window_info *window = win_window_list; RECT bounds; @@ -642,7 +642,7 @@ void winwindow_video_window_create(running_machine *machine, int index, win_moni // set the specific view sprintf(option, "view%d", index); - set_starting_view(index, window, options_get_string(mame_options(), option)); + set_starting_view(index, window, options_get_string(machine->options(), option)); // remember the current values in case they change window->targetview = render_target_get_view(window->target); @@ -656,7 +656,7 @@ void winwindow_video_window_create(running_machine *machine, int index, win_moni sprintf(window->title, APPNAME ": %s [%s] - Screen %d", machine->gamedrv->description, machine->gamedrv->name, index); // set the initial maximized state - window->startmaximized = options_get_bool(mame_options(), WINOPTION_MAXIMIZE); + window->startmaximized = options_get_bool(machine->options(), WINOPTION_MAXIMIZE); // finish the window creation on the window thread if (multithreading_enabled) @@ -896,9 +896,9 @@ void winwindow_ui_pause_from_main_thread(running_machine *machine, int pause) if (ui_temp_pause++ == 0) { // only call mame_pause if we weren't already paused due to some external reason - ui_temp_was_paused = mame_is_paused(machine); + ui_temp_was_paused = machine->paused(); if (!ui_temp_was_paused) - mame_pause(machine, TRUE); + machine->pause(); SetEvent(ui_pause_event); } @@ -912,7 +912,7 @@ void winwindow_ui_pause_from_main_thread(running_machine *machine, int pause) { // but only do it if we were the ones who initiated it if (!ui_temp_was_paused) - mame_pause(machine, FALSE); + machine->resume(); ResetEvent(ui_pause_event); } @@ -980,7 +980,7 @@ void winwindow_ui_exec_on_main_thread(void (*func)(void *), void *param) int winwindow_ui_is_paused(running_machine *machine) { - return mame_is_paused(machine) && ui_temp_was_paused; + return machine->paused() && ui_temp_was_paused; } @@ -1346,7 +1346,7 @@ LRESULT CALLBACK winwindow_video_window_proc(HWND wnd, UINT message, WPARAM wpar if (multithreading_enabled) PostThreadMessage(main_threadid, WM_QUIT, 0, 0); else - mame_schedule_exit(window->machine); + window->machine->schedule_exit(); break; // destroy: clean up all attached rendering bits and NULL out our hwnd diff --git a/src/osd/windows/winmain.c b/src/osd/windows/winmain.c index a92b8b6a132..f3a0964cdfd 100644 --- a/src/osd/windows/winmain.c +++ b/src/osd/windows/winmain.c @@ -159,7 +159,7 @@ static TIMECAPS caps; // PROTOTYPES //============================================================ -static void osd_exit(running_machine *machine); +static void osd_exit(running_machine &machine); static void soft_link_functions(void); static int is_double_click_start(int argc); @@ -323,7 +323,7 @@ int main(int argc, char *argv[]) // output_oslog //============================================================ -static void output_oslog(running_machine *machine, const char *buffer) +static void output_oslog(running_machine &machine, const char *buffer) { win_output_debug_string_utf8(buffer); } @@ -335,18 +335,18 @@ static void output_oslog(running_machine *machine, const char *buffer) void osd_init(running_machine *machine) { - int watchdog = options_get_int(mame_options(), WINOPTION_WATCHDOG); + int watchdog = options_get_int(machine->options(), WINOPTION_WATCHDOG); const char *stemp; // thread priority if (!(machine->debug_flags & DEBUG_FLAG_OSD_ENABLED)) - SetThreadPriority(GetCurrentThread(), options_get_int(mame_options(), WINOPTION_PRIORITY)); + SetThreadPriority(GetCurrentThread(), options_get_int(machine->options(), WINOPTION_PRIORITY)); // ensure we get called on the way out - add_exit_callback(machine, osd_exit); + machine->add_notifier(MACHINE_NOTIFY_EXIT, osd_exit); // get number of processors - stemp = options_get_string(mame_options(), WINOPTION_NUMPROCESSORS); + stemp = options_get_string(machine->options(), WINOPTION_NUMPROCESSORS); osd_num_processors = 0; @@ -367,8 +367,8 @@ void osd_init(running_machine *machine) winoutput_init(machine); // hook up the debugger log - if (options_get_bool(mame_options(), WINOPTION_OSLOG)) - add_logerror_callback(machine, output_oslog); + if (options_get_bool(machine->options(), WINOPTION_OSLOG)) + machine->add_logerror_callback(output_oslog); // crank up the multimedia timer resolution to its max // this gives the system much finer timeslices @@ -399,7 +399,7 @@ void osd_init(running_machine *machine) // osd_exit //============================================================ -static void osd_exit(running_machine *machine) +static void osd_exit(running_machine &machine) { // take down the watchdog thread if it exists if (watchdog_thread != NULL) @@ -425,7 +425,7 @@ static void osd_exit(running_machine *machine) timeEndPeriod(caps.wPeriodMin); // one last pass at events - winwindow_process_events(machine, 0); + winwindow_process_events(&machine, 0); } |