src/emu/video.c
| r9718 | r9719 | |
| 39 | 39 | |
| 40 | 40 | #include "emu.h" |
| 41 | 41 | #include "emuopts.h" |
| 42 | | #include "profiler.h" |
| 43 | 42 | #include "png.h" |
| 44 | 43 | #include "debugger.h" |
| 45 | 44 | #include "debugint/debugint.h" |
| 46 | | #include "rendutil.h" |
| 47 | 45 | #include "ui.h" |
| 48 | 46 | #include "aviio.h" |
| 49 | 47 | #include "crsshair.h" |
| r9718 | r9719 | |
| 52 | 50 | |
| 53 | 51 | |
| 54 | 52 | |
| 55 | | /*************************************************************************** |
| 56 | | DEBUGGING |
| 57 | | ***************************************************************************/ |
| 53 | //************************************************************************** |
| 54 | // DEBUGGING |
| 55 | //************************************************************************** |
| 58 | 56 | |
| 59 | 57 | #define LOG_THROTTLE (0) |
| 60 | | #define VERBOSE (0) |
| 61 | | #define LOG_PARTIAL_UPDATES(x) do { if (VERBOSE) logerror x; } while (0) |
| 62 | 58 | |
| 63 | 59 | |
| 64 | 60 | |
| 65 | | /*************************************************************************** |
| 66 | | CONSTANTS |
| 67 | | ***************************************************************************/ |
| 61 | //************************************************************************** |
| 62 | // GLOBAL VARIABLES |
| 63 | //************************************************************************** |
| 68 | 64 | |
| 69 | | #define SUBSECONDS_PER_SPEED_UPDATE (ATTOSECONDS_PER_SECOND / 4) |
| 70 | | #define PAUSED_REFRESH_RATE (30) |
| 71 | | |
| 72 | | |
| 73 | | |
| 74 | | /*************************************************************************** |
| 75 | | DEVICE DEFINITIONS |
| 76 | | ***************************************************************************/ |
| 77 | | |
| 78 | | const device_type SCREEN = screen_device_config::static_alloc_device_config; |
| 79 | | |
| 80 | | |
| 81 | | |
| 82 | | /*************************************************************************** |
| 83 | | TYPE DEFINITIONS |
| 84 | | ***************************************************************************/ |
| 85 | | |
| 86 | | typedef struct _video_global video_global; |
| 87 | | struct _video_global |
| 65 | // frameskipping tables |
| 66 | const UINT8 video_manager::s_skiptable[FRAMESKIP_LEVELS][FRAMESKIP_LEVELS] = |
| 88 | 67 | { |
| 89 | | /* screenless systems */ |
| 90 | | emu_timer * screenless_frame_timer; /* timer to signal VBLANK start */ |
| 91 | | |
| 92 | | /* throttling calculations */ |
| 93 | | osd_ticks_t throttle_last_ticks; /* osd_ticks the last call to throttle */ |
| 94 | | attotime throttle_realtime; /* real time the last call to throttle */ |
| 95 | | attotime throttle_emutime; /* emulated time the last call to throttle */ |
| 96 | | UINT32 throttle_history; /* history of frames where we were fast enough */ |
| 97 | | |
| 98 | | /* dynamic speed computation */ |
| 99 | | osd_ticks_t speed_last_realtime; /* real time at the last speed calculation */ |
| 100 | | attotime speed_last_emutime; /* emulated time at the last speed calculation */ |
| 101 | | double speed_percent; /* most recent speed percentage */ |
| 102 | | UINT32 partial_updates_this_frame;/* partial update counter this frame */ |
| 103 | | |
| 104 | | /* overall speed computation */ |
| 105 | | UINT32 overall_real_seconds; /* accumulated real seconds at normal speed */ |
| 106 | | osd_ticks_t overall_real_ticks; /* accumulated real ticks at normal speed */ |
| 107 | | attotime overall_emutime; /* accumulated emulated time at normal speed */ |
| 108 | | UINT32 overall_valid_counter; /* number of consecutive valid time periods */ |
| 109 | | |
| 110 | | /* configuration */ |
| 111 | | UINT8 throttle; /* flag: TRUE if we're currently throttled */ |
| 112 | | UINT8 fastforward; /* flag: TRUE if we're currently fast-forwarding */ |
| 113 | | UINT32 seconds_to_run; /* number of seconds to run before quitting */ |
| 114 | | UINT8 auto_frameskip; /* flag: TRUE if we're automatically frameskipping */ |
| 115 | | UINT32 speed; /* overall speed (*100) */ |
| 116 | | |
| 117 | | /* frameskipping */ |
| 118 | | UINT8 empty_skip_count; /* number of empty frames we have skipped */ |
| 119 | | UINT8 frameskip_level; /* current frameskip level */ |
| 120 | | UINT8 frameskip_counter; /* counter that counts through the frameskip steps */ |
| 121 | | INT8 frameskip_adjust; |
| 122 | | UINT8 skipping_this_frame; /* flag: TRUE if we are skipping the current frame */ |
| 123 | | osd_ticks_t average_oversleep; /* average number of ticks the OSD oversleeps */ |
| 124 | | |
| 125 | | /* snapshot stuff */ |
| 126 | | render_target * snap_target; /* screen shapshot target */ |
| 127 | | bitmap_t * snap_bitmap; /* screen snapshot bitmap */ |
| 128 | | UINT8 snap_native; /* are we using native per-screen layouts? */ |
| 129 | | INT32 snap_width; /* width of snapshots (0 == auto) */ |
| 130 | | INT32 snap_height; /* height of snapshots (0 == auto) */ |
| 131 | | |
| 132 | | /* movie recording */ |
| 133 | | mame_file * mngfile; /* handle to the open movie file */ |
| 134 | | avi_file * avifile; /* handle to the open movie file */ |
| 135 | | attotime movie_frame_period; /* period of a single movie frame */ |
| 136 | | attotime movie_next_frame_time; /* time of next frame */ |
| 137 | | UINT32 movie_frame; /* current movie frame number */ |
| 138 | | }; |
| 139 | | |
| 140 | | |
| 141 | | |
| 142 | | /*************************************************************************** |
| 143 | | GLOBAL VARIABLES |
| 144 | | ***************************************************************************/ |
| 145 | | |
| 146 | | /* global state */ |
| 147 | | static video_global global; |
| 148 | | |
| 149 | | /* frameskipping tables */ |
| 150 | | static const UINT8 skiptable[FRAMESKIP_LEVELS][FRAMESKIP_LEVELS] = |
| 151 | | { |
| 152 | 68 | { 0,0,0,0,0,0,0,0,0,0,0,0 }, |
| 153 | 69 | { 0,0,0,0,0,0,0,0,0,0,0,1 }, |
| 154 | 70 | { 0,0,0,0,0,1,0,0,0,0,0,1 }, |
| r9718 | r9719 | |
| 165 | 81 | |
| 166 | 82 | |
| 167 | 83 | |
| 168 | | /*************************************************************************** |
| 169 | | FUNCTION PROTOTYPES |
| 170 | | ***************************************************************************/ |
| 84 | //************************************************************************** |
| 85 | // FUNCTION PROTOTYPES |
| 86 | //************************************************************************** |
| 171 | 87 | |
| 172 | | /* core implementation */ |
| 173 | | static void video_exit(running_machine &machine); |
| 174 | | static void init_buffered_spriteram(running_machine *machine); |
| 88 | // software rendering |
| 89 | static void rgb888_draw_primitives(const render_primitive_list &primlist, void *dstdata, UINT32 width, UINT32 height, UINT32 pitch); |
| 175 | 90 | |
| 176 | | /* global rendering */ |
| 177 | | static int finish_screen_updates(running_machine *machine); |
| 178 | | static TIMER_CALLBACK( screenless_update_callback ); |
| 179 | 91 | |
| 180 | | /* throttling/frameskipping/performance */ |
| 181 | | static void update_throttle(running_machine *machine, attotime emutime); |
| 182 | | static osd_ticks_t throttle_until_ticks(running_machine *machine, osd_ticks_t target_ticks); |
| 183 | | static void update_frameskip(running_machine *machine); |
| 184 | | static void recompute_speed(running_machine *machine, attotime emutime); |
| 185 | | static void update_refresh_speed(running_machine *machine); |
| 186 | 92 | |
| 187 | | /* screen snapshots */ |
| 188 | | static void create_snapshot_bitmap(device_t *screen); |
| 189 | | static file_error mame_fopen_next(running_machine *machine, const char *pathoption, const char *extension, mame_file **file); |
| 93 | //************************************************************************** |
| 94 | // VIDEO MANAGER |
| 95 | //************************************************************************** |
| 190 | 96 | |
| 191 | | /* movie recording */ |
| 192 | | static void video_mng_record_frame(running_machine *machine); |
| 193 | | static void video_avi_record_frame(running_machine *machine); |
| 97 | //------------------------------------------------- |
| 98 | // video_manager - constructor |
| 99 | //------------------------------------------------- |
| 194 | 100 | |
| 195 | | /* software rendering */ |
| 196 | | static void rgb888_draw_primitives(const render_primitive_list &primlist, void *dstdata, UINT32 width, UINT32 height, UINT32 pitch); |
| 101 | video_manager::video_manager(running_machine &machine) |
| 102 | : m_machine(machine), |
| 103 | m_screenless_frame_timer(NULL), |
| 104 | m_throttle_last_ticks(0), |
| 105 | m_throttle_realtime(attotime_zero), |
| 106 | m_throttle_emutime(attotime_zero), |
| 107 | m_throttle_history(0), |
| 108 | m_speed_last_realtime(0), |
| 109 | m_speed_last_emutime(attotime_zero), |
| 110 | m_speed_percent(1.0), |
| 111 | m_overall_real_seconds(0), |
| 112 | m_overall_real_ticks(0), |
| 113 | m_overall_emutime(attotime_zero), |
| 114 | m_overall_valid_counter(0), |
| 115 | m_throttle(options_get_bool(machine.options(), OPTION_THROTTLE)), |
| 116 | m_fastforward(false), |
| 117 | m_seconds_to_run(options_get_int(machine.options(), OPTION_SECONDS_TO_RUN)), |
| 118 | m_auto_frameskip(options_get_bool(machine.options(), OPTION_AUTOFRAMESKIP)), |
| 119 | m_speed(original_speed_setting()), |
| 120 | m_empty_skip_count(0), |
| 121 | m_frameskip_level(options_get_int(machine.options(), OPTION_FRAMESKIP)), |
| 122 | m_frameskip_counter(0), |
| 123 | m_frameskip_adjust(0), |
| 124 | m_skipping_this_frame(false), |
| 125 | m_average_oversleep(0), |
| 126 | m_snap_target(NULL), |
| 127 | m_snap_bitmap(NULL), |
| 128 | m_snap_native(true), |
| 129 | m_snap_width(0), |
| 130 | m_snap_height(0), |
| 131 | m_mngfile(NULL), |
| 132 | m_avifile(NULL), |
| 133 | m_movie_frame_period(attotime_zero), |
| 134 | m_movie_next_frame_time(attotime_zero), |
| 135 | m_movie_frame(0) |
| 136 | { |
| 137 | // request a callback upon exiting |
| 138 | machine.add_notifier(MACHINE_NOTIFY_EXIT, exit_static); |
| 139 | state_save_register_postload(&machine, state_postload_stub<video_manager, &video_manager::postload>, this); |
| 197 | 140 | |
| 141 | // extract initial execution state from global configuration settings |
| 142 | update_refresh_speed(); |
| 198 | 143 | |
| 144 | // create spriteram buffers if necessary |
| 145 | if (machine.config->m_video_attributes & VIDEO_BUFFERS_SPRITERAM) |
| 146 | init_buffered_spriteram(); |
| 199 | 147 | |
| 200 | | /*************************************************************************** |
| 201 | | INLINE FUNCTIONS |
| 202 | | ***************************************************************************/ |
| 148 | // create a render target for snapshots |
| 149 | const char *viewname = options_get_string(machine.options(), OPTION_SNAPVIEW); |
| 150 | m_snap_native = (machine.primary_screen != NULL && (viewname[0] == 0 || strcmp(viewname, "native") == 0)); |
| 203 | 151 | |
| 204 | | /*------------------------------------------------- |
| 205 | | effective_autoframeskip - return the effective |
| 206 | | autoframeskip value, accounting for fast |
| 207 | | forward |
| 208 | | -------------------------------------------------*/ |
| 152 | // the native target is hard-coded to our internal layout and has all options disabled |
| 153 | if (m_snap_native) |
| 154 | { |
| 155 | m_snap_target = machine.render().target_alloc(layout_snap, RENDER_CREATE_SINGLE_FILE | RENDER_CREATE_HIDDEN); |
| 156 | m_snap_target->set_backdrops_enabled(false); |
| 157 | m_snap_target->set_overlays_enabled(false); |
| 158 | m_snap_target->set_bezels_enabled(false); |
| 159 | m_snap_target->set_screen_overlay_enabled(false); |
| 160 | m_snap_target->set_zoom_to_screen(false); |
| 161 | } |
| 209 | 162 | |
| 210 | | INLINE int effective_autoframeskip(running_machine *machine) |
| 211 | | { |
| 212 | | /* if we're fast forwarding or paused, autoframeskip is disabled */ |
| 213 | | if (global.fastforward || machine->paused()) |
| 214 | | return FALSE; |
| 163 | // other targets select the specified view and turn off effects |
| 164 | else |
| 165 | { |
| 166 | m_snap_target = machine.render().target_alloc(NULL, RENDER_CREATE_HIDDEN); |
| 167 | m_snap_target->set_view(m_snap_target->configured_view(viewname, 0, 1)); |
| 168 | m_snap_target->set_screen_overlay_enabled(false); |
| 169 | } |
| 215 | 170 | |
| 216 | | /* otherwise, it's up to the user */ |
| 217 | | return global.auto_frameskip; |
| 218 | | } |
| 171 | // extract snap resolution if present |
| 172 | if (sscanf(options_get_string(machine.options(), OPTION_SNAPSIZE), "%dx%d", &m_snap_width, &m_snap_height) != 2) |
| 173 | m_snap_width = m_snap_height = 0; |
| 219 | 174 | |
| 175 | // start recording movie if specified |
| 176 | const char *filename = options_get_string(machine.options(), OPTION_MNGWRITE); |
| 177 | if (filename[0] != 0) |
| 178 | begin_recording(filename, MF_MNG); |
| 220 | 179 | |
| 221 | | /*------------------------------------------------- |
| 222 | | effective_frameskip - return the effective |
| 223 | | frameskip value, accounting for fast |
| 224 | | forward |
| 225 | | -------------------------------------------------*/ |
| 180 | filename = options_get_string(machine.options(), OPTION_AVIWRITE); |
| 181 | if (filename[0] != 0) |
| 182 | begin_recording(filename, MF_AVI); |
| 226 | 183 | |
| 227 | | INLINE int effective_frameskip(void) |
| 228 | | { |
| 229 | | /* if we're fast forwarding, use the maximum frameskip */ |
| 230 | | if (global.fastforward) |
| 231 | | return FRAMESKIP_LEVELS - 1; |
| 232 | | |
| 233 | | /* otherwise, it's up to the user */ |
| 234 | | return global.frameskip_level; |
| 184 | // if no screens, create a periodic timer to drive updates |
| 185 | if (machine.primary_screen == NULL) |
| 186 | { |
| 187 | m_screenless_frame_timer = timer_alloc(&machine, &screenless_update_callback, this); |
| 188 | timer_adjust_periodic(m_screenless_frame_timer, screen_device::DEFAULT_FRAME_PERIOD, 0, screen_device::DEFAULT_FRAME_PERIOD); |
| 189 | } |
| 235 | 190 | } |
| 236 | 191 | |
| 237 | 192 | |
| 238 | | /*------------------------------------------------- |
| 239 | | effective_throttle - return the effective |
| 240 | | throttle value, accounting for fast |
| 241 | | forward and user interface |
| 242 | | -------------------------------------------------*/ |
| 193 | //------------------------------------------------- |
| 194 | // set_frameskip - set the current actual |
| 195 | // frameskip (-1 means autoframeskip) |
| 196 | //------------------------------------------------- |
| 243 | 197 | |
| 244 | | INLINE int effective_throttle(running_machine *machine) |
| 198 | void video_manager::set_frameskip(int frameskip) |
| 245 | 199 | { |
| 246 | | /* if we're paused, or if the UI is active, we always throttle */ |
| 247 | | if (machine->paused() || ui_is_menu_active()) |
| 248 | | return TRUE; |
| 200 | // -1 means autoframeskip |
| 201 | if (frameskip == -1) |
| 202 | { |
| 203 | m_auto_frameskip = true; |
| 204 | m_frameskip_level = 0; |
| 205 | } |
| 249 | 206 | |
| 250 | | /* if we're fast forwarding, we don't throttle */ |
| 251 | | if (global.fastforward) |
| 252 | | return FALSE; |
| 253 | | |
| 254 | | /* otherwise, it's up to the user */ |
| 255 | | return global.throttle; |
| 207 | // any other level is a direct control |
| 208 | else if (frameskip >= 0 && frameskip <= MAX_FRAMESKIP) |
| 209 | { |
| 210 | m_auto_frameskip = false; |
| 211 | m_frameskip_level = frameskip; |
| 212 | } |
| 256 | 213 | } |
| 257 | 214 | |
| 258 | 215 | |
| 259 | | /*------------------------------------------------- |
| 260 | | original_speed_setting - return the original |
| 261 | | speed setting |
| 262 | | -------------------------------------------------*/ |
| 216 | //------------------------------------------------- |
| 217 | // frame_update - handle frameskipping and UI, |
| 218 | // plus updating the screen during normal |
| 219 | // operations |
| 220 | //------------------------------------------------- |
| 263 | 221 | |
| 264 | | INLINE int original_speed_setting(void) |
| 222 | void video_manager::frame_update(bool debug) |
| 265 | 223 | { |
| 266 | | return options_get_float(mame_options(), OPTION_SPEED) * 100.0 + 0.5; |
| 267 | | } |
| 224 | // only render sound and video if we're in the running phase |
| 225 | int phase = m_machine.phase(); |
| 226 | bool skipped_it = m_skipping_this_frame; |
| 227 | if (phase == MACHINE_PHASE_RUNNING && (!m_machine.paused() || options_get_bool(m_machine.options(), OPTION_UPDATEINPAUSE))) |
| 228 | { |
| 229 | bool anything_changed = finish_screen_updates(); |
| 268 | 230 | |
| 231 | // if none of the screens changed and we haven't skipped too many frames in a row, |
| 232 | // mark this frame as skipped to prevent throttling; this helps for games that |
| 233 | // don't update their screen at the monitor refresh rate |
| 234 | if (!anything_changed && !m_auto_frameskip && m_frameskip_level == 0 && m_empty_skip_count++ < 3) |
| 235 | skipped_it = true; |
| 236 | else |
| 237 | m_empty_skip_count = 0; |
| 238 | } |
| 269 | 239 | |
| 240 | // draw the user interface |
| 241 | ui_update_and_render(&m_machine, &m_machine.render().ui_container()); |
| 270 | 242 | |
| 271 | | /*************************************************************************** |
| 272 | | CORE IMPLEMENTATION |
| 273 | | ***************************************************************************/ |
| 243 | // update the internal render debugger |
| 244 | debugint_update_during_game(&m_machine); |
| 274 | 245 | |
| 275 | | /*------------------------------------------------- |
| 276 | | video_init - start up the video system |
| 277 | | -------------------------------------------------*/ |
| 246 | // if we're throttling, synchronize before rendering |
| 247 | attotime current_time = timer_get_time(&m_machine); |
| 248 | if (!debug && !skipped_it && effective_throttle()) |
| 249 | update_throttle(current_time); |
| 278 | 250 | |
| 279 | | void video_init(running_machine *machine) |
| 280 | | { |
| 281 | | const char *filename; |
| 282 | | const char *viewname; |
| 251 | // ask the OSD to update |
| 252 | g_profiler.start(PROFILER_BLIT); |
| 253 | m_machine.osd().update(!debug && skipped_it); |
| 254 | g_profiler.stop(); |
| 283 | 255 | |
| 284 | | /* validate */ |
| 285 | | assert(machine != NULL); |
| 286 | | assert(machine->config != NULL); |
| 256 | // perform tasks for this frame |
| 257 | if (!debug) |
| 258 | m_machine.call_notifiers(MACHINE_NOTIFY_FRAME); |
| 287 | 259 | |
| 288 | | /* request a callback upon exiting */ |
| 289 | | machine->add_notifier(MACHINE_NOTIFY_EXIT, video_exit); |
| 260 | // update frameskipping |
| 261 | if (!debug) |
| 262 | update_frameskip(); |
| 290 | 263 | |
| 291 | | /* reset our global state */ |
| 292 | | memset(&global, 0, sizeof(global)); |
| 293 | | global.speed_percent = 1.0; |
| 264 | // update speed computations |
| 265 | if (!debug && !skipped_it) |
| 266 | recompute_speed(current_time); |
| 294 | 267 | |
| 295 | | /* extract initial execution state from global configuration settings */ |
| 296 | | global.speed = original_speed_setting(); |
| 297 | | update_refresh_speed(machine); |
| 298 | | global.throttle = options_get_bool(machine->options(), OPTION_THROTTLE); |
| 299 | | global.auto_frameskip = options_get_bool(machine->options(), OPTION_AUTOFRAMESKIP); |
| 300 | | global.frameskip_level = options_get_int(machine->options(), OPTION_FRAMESKIP); |
| 301 | | global.seconds_to_run = options_get_int(machine->options(), OPTION_SECONDS_TO_RUN); |
| 302 | | |
| 303 | | /* create spriteram buffers if necessary */ |
| 304 | | if (machine->config->m_video_attributes & VIDEO_BUFFERS_SPRITERAM) |
| 305 | | init_buffered_spriteram(machine); |
| 306 | | |
| 307 | | /* create a render target for snapshots */ |
| 308 | | viewname = options_get_string(machine->options(), OPTION_SNAPVIEW); |
| 309 | | global.snap_native = (machine->primary_screen != NULL && (viewname[0] == 0 || strcmp(viewname, "native") == 0)); |
| 310 | | |
| 311 | | /* the native target is hard-coded to our internal layout and has all options disabled */ |
| 312 | | if (global.snap_native) |
| 268 | // call the end-of-frame callback |
| 269 | if (phase == MACHINE_PHASE_RUNNING) |
| 313 | 270 | { |
| 314 | | global.snap_target = machine->render().target_alloc(layout_snap, RENDER_CREATE_SINGLE_FILE | RENDER_CREATE_HIDDEN); |
| 315 | | global.snap_target->set_backdrops_enabled(false); |
| 316 | | global.snap_target->set_overlays_enabled(false); |
| 317 | | global.snap_target->set_bezels_enabled(false); |
| 318 | | global.snap_target->set_screen_overlay_enabled(false); |
| 319 | | global.snap_target->set_zoom_to_screen(false); |
| 320 | | } |
| 271 | // reset partial updates if we're paused or if the debugger is active |
| 272 | if (m_machine.primary_screen != NULL && (m_machine.paused() || debug || debugger_within_instruction_hook(&m_machine))) |
| 273 | m_machine.primary_screen->scanline0_callback(); |
| 321 | 274 | |
| 322 | | /* other targets select the specified view and turn off effects */ |
| 323 | | else |
| 324 | | { |
| 325 | | global.snap_target = machine->render().target_alloc(NULL, RENDER_CREATE_HIDDEN); |
| 326 | | global.snap_target->set_view(video_get_view_for_target(machine, global.snap_target, viewname, 0, 1)); |
| 327 | | global.snap_target->set_screen_overlay_enabled(false); |
| 275 | // otherwise, call the video EOF callback |
| 276 | else |
| 277 | { |
| 278 | g_profiler.start(PROFILER_VIDEO); |
| 279 | m_machine.driver_data<driver_device>()->video_eof(); |
| 280 | g_profiler.stop(); |
| 281 | } |
| 328 | 282 | } |
| 283 | } |
| 329 | 284 | |
| 330 | | /* extract snap resolution if present */ |
| 331 | | if (sscanf(options_get_string(machine->options(), OPTION_SNAPSIZE), "%dx%d", &global.snap_width, &global.snap_height) != 2) |
| 332 | | global.snap_width = global.snap_height = 0; |
| 333 | 285 | |
| 334 | | /* start recording movie if specified */ |
| 335 | | filename = options_get_string(machine->options(), OPTION_MNGWRITE); |
| 336 | | if (filename[0] != 0) |
| 337 | | video_mng_begin_recording(machine, filename); |
| 286 | //------------------------------------------------- |
| 287 | // speed_text - print the text to be displayed |
| 288 | // into a string buffer |
| 289 | //------------------------------------------------- |
| 338 | 290 | |
| 339 | | filename = options_get_string(machine->options(), OPTION_AVIWRITE); |
| 340 | | if (filename[0] != 0) |
| 341 | | video_avi_begin_recording(machine, filename); |
| 291 | astring &video_manager::speed_text(astring &string) |
| 292 | { |
| 293 | string.reset(); |
| 342 | 294 | |
| 343 | | /* if no screens, create a periodic timer to drive updates */ |
| 344 | | if (machine->primary_screen == NULL) |
| 345 | | { |
| 346 | | global.screenless_frame_timer = timer_alloc(machine, screenless_update_callback, NULL); |
| 347 | | timer_adjust_periodic(global.screenless_frame_timer, screen_device::k_default_frame_period, 0, screen_device::k_default_frame_period); |
| 348 | | } |
| 349 | | } |
| 295 | // if we're paused, just display Paused |
| 296 | bool paused = m_machine.paused(); |
| 297 | if (paused) |
| 298 | string.cat("paused"); |
| 350 | 299 | |
| 300 | // if we're fast forwarding, just display Fast-forward |
| 301 | else if (m_fastforward) |
| 302 | string.cat("fast "); |
| 351 | 303 | |
| 352 | | /*------------------------------------------------- |
| 353 | | video_exit - close down the video system |
| 354 | | -------------------------------------------------*/ |
| 304 | // if we're auto frameskipping, display that plus the level |
| 305 | else if (effective_autoframeskip()) |
| 306 | string.catprintf("auto%2d/%d", effective_frameskip(), MAX_FRAMESKIP); |
| 355 | 307 | |
| 356 | | static void video_exit(running_machine &machine) |
| 357 | | { |
| 358 | | int i; |
| 308 | // otherwise, just display the frameskip plus the level |
| 309 | else |
| 310 | string.catprintf("skip %d/%d", effective_frameskip(), MAX_FRAMESKIP); |
| 359 | 311 | |
| 360 | | /* stop recording any movie */ |
| 361 | | video_mng_end_recording(&machine); |
| 362 | | video_avi_end_recording(&machine); |
| 312 | // append the speed for all cases except paused |
| 313 | if (!paused) |
| 314 | string.catprintf("%4d%%", (int)(100 * m_speed_percent + 0.5)); |
| 363 | 315 | |
| 364 | | /* free all the graphics elements */ |
| 365 | | for (i = 0; i < MAX_GFX_ELEMENTS; i++) |
| 366 | | gfx_element_free(machine.gfx[i]); |
| 316 | // display the number of partial updates as well |
| 317 | int partials = 0; |
| 318 | for (screen_device *screen = m_machine.first_screen(); screen != NULL; screen = screen->next_screen()) |
| 319 | partials += screen->partial_updates(); |
| 320 | if (partials > 1) |
| 321 | string.catprintf("\n%d partial updates", partials); |
| 367 | 322 | |
| 368 | | /* free the snapshot target */ |
| 369 | | machine.render().target_free(global.snap_target); |
| 370 | | if (global.snap_bitmap != NULL) |
| 371 | | global_free(global.snap_bitmap); |
| 372 | | |
| 373 | | /* print a final result if we have at least 5 seconds' worth of data */ |
| 374 | | if (global.overall_emutime.seconds >= 5) |
| 375 | | { |
| 376 | | osd_ticks_t tps = osd_ticks_per_second(); |
| 377 | | double final_real_time = (double)global.overall_real_seconds + (double)global.overall_real_ticks / (double)tps; |
| 378 | | double final_emu_time = attotime_to_double(global.overall_emutime); |
| 379 | | mame_printf_info("Average speed: %.2f%% (%d seconds)\n", 100 * final_emu_time / final_real_time, attotime_add_attoseconds(global.overall_emutime, ATTOSECONDS_PER_SECOND / 2).seconds); |
| 380 | | } |
| 323 | return string; |
| 381 | 324 | } |
| 382 | 325 | |
| 383 | 326 | |
| 384 | | /*------------------------------------------------- |
| 385 | | init_buffered_spriteram - initialize the |
| 386 | | double-buffered spriteram |
| 387 | | -------------------------------------------------*/ |
| 327 | //------------------------------------------------- |
| 328 | // save_snapshot - save a snapshot to the given |
| 329 | // file handle |
| 330 | //------------------------------------------------- |
| 388 | 331 | |
| 389 | | static void init_buffered_spriteram(running_machine *machine) |
| 332 | void video_manager::save_snapshot(screen_device *screen, mame_file &fp) |
| 390 | 333 | { |
| 391 | | assert_always(machine->generic.spriteram_size != 0, "Video buffers spriteram but spriteram size is 0"); |
| 334 | // validate |
| 335 | assert(!m_snap_native || screen != NULL); |
| 392 | 336 | |
| 393 | | /* allocate memory for the back buffer */ |
| 394 | | machine->generic.buffered_spriteram.u8 = auto_alloc_array(machine, UINT8, machine->generic.spriteram_size); |
| 337 | // create the bitmap to pass in |
| 338 | create_snapshot_bitmap(screen); |
| 395 | 339 | |
| 396 | | /* register for saving it */ |
| 397 | | state_save_register_global_pointer(machine, machine->generic.buffered_spriteram.u8, machine->generic.spriteram_size); |
| 340 | // add two text entries describing the image |
| 341 | astring text1(APPNAME, " ", build_version); |
| 342 | astring text2(m_machine.m_game.manufacturer, " ", m_machine.m_game.description); |
| 343 | png_info pnginfo = { 0 }; |
| 344 | png_add_text(&pnginfo, "Software", text1); |
| 345 | png_add_text(&pnginfo, "System", text2); |
| 398 | 346 | |
| 399 | | /* do the same for the second back buffer, if present */ |
| 400 | | if (machine->generic.spriteram2_size) |
| 401 | | { |
| 402 | | /* allocate memory */ |
| 403 | | machine->generic.buffered_spriteram2.u8 = auto_alloc_array(machine, UINT8, machine->generic.spriteram2_size); |
| 347 | // now do the actual work |
| 348 | const rgb_t *palette = (m_machine.palette != NULL) ? palette_entry_list_adjusted(m_machine.palette) : NULL; |
| 349 | png_error error = png_write_bitmap(mame_core_file(&fp), &pnginfo, m_snap_bitmap, m_machine.total_colors(), palette); |
| 350 | if (error != PNGERR_NONE) |
| 351 | mame_printf_error("Error generating PNG for snapshot: png_error = %d\n", error); |
| 404 | 352 | |
| 405 | | /* register for saving it */ |
| 406 | | state_save_register_global_pointer(machine, machine->generic.buffered_spriteram2.u8, machine->generic.spriteram2_size); |
| 407 | | } |
| 353 | // free any data allocated |
| 354 | png_free(&pnginfo); |
| 408 | 355 | } |
| 409 | 356 | |
| 410 | 357 | |
| 358 | //------------------------------------------------- |
| 359 | // save_active_screen_snapshots - save a |
| 360 | // snapshot of all active screens |
| 361 | //------------------------------------------------- |
| 411 | 362 | |
| 412 | | /*************************************************************************** |
| 413 | | SCREEN MANAGEMENT |
| 414 | | ***************************************************************************/ |
| 415 | | |
| 416 | | /*------------------------------------------------- |
| 417 | | screenless_update_callback - update generator |
| 418 | | when there are no screens to drive it |
| 419 | | -------------------------------------------------*/ |
| 420 | | |
| 421 | | static TIMER_CALLBACK( screenless_update_callback ) |
| 363 | void video_manager::save_active_screen_snapshots() |
| 422 | 364 | { |
| 423 | | /* force an update */ |
| 424 | | video_frame_update(machine, false); |
| 365 | // if we're native, then write one snapshot per visible screen |
| 366 | if (m_snap_native) |
| 367 | { |
| 368 | // write one snapshot per visible screen |
| 369 | for (screen_device *screen = m_machine.first_screen(); screen != NULL; screen = screen->next_screen()) |
| 370 | if (m_machine.render().is_live(*screen)) |
| 371 | { |
| 372 | mame_file *fp; |
| 373 | file_error filerr = mame_fopen_next(SEARCHPATH_SCREENSHOT, "png", fp); |
| 374 | if (filerr == FILERR_NONE) |
| 375 | { |
| 376 | save_snapshot(screen, *fp); |
| 377 | mame_fclose(fp); |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | // otherwise, just write a single snapshot |
| 383 | else |
| 384 | { |
| 385 | mame_file *fp; |
| 386 | file_error filerr = mame_fopen_next(SEARCHPATH_SCREENSHOT, "png", fp); |
| 387 | if (filerr == FILERR_NONE) |
| 388 | { |
| 389 | save_snapshot(NULL, *fp); |
| 390 | mame_fclose(fp); |
| 391 | } |
| 392 | } |
| 425 | 393 | } |
| 426 | 394 | |
| 427 | 395 | |
| 428 | | /*------------------------------------------------- |
| 429 | | video_frame_update - handle frameskipping and |
| 430 | | UI, plus updating the screen during normal |
| 431 | | operations |
| 432 | | -------------------------------------------------*/ |
| 396 | //------------------------------------------------- |
| 397 | // begin_recording - begin recording of a movie |
| 398 | //------------------------------------------------- |
| 433 | 399 | |
| 434 | | void video_frame_update(running_machine *machine, int debug) |
| 400 | void video_manager::begin_recording(const char *name, movie_format format) |
| 435 | 401 | { |
| 436 | | attotime current_time = timer_get_time(machine); |
| 437 | | int skipped_it = global.skipping_this_frame; |
| 438 | | int phase = machine->phase(); |
| 402 | // stop any existign recording |
| 403 | end_recording(); |
| 439 | 404 | |
| 440 | | /* validate */ |
| 441 | | assert(machine != NULL); |
| 442 | | assert(machine->config != NULL); |
| 405 | // create a snapshot bitmap so we know what the target size is |
| 406 | create_snapshot_bitmap(NULL); |
| 443 | 407 | |
| 444 | | /* only render sound and video if we're in the running phase */ |
| 445 | | if (phase == MACHINE_PHASE_RUNNING && (!machine->paused() || options_get_bool(machine->options(), OPTION_UPDATEINPAUSE))) |
| 408 | // reset the state |
| 409 | m_movie_frame = 0; |
| 410 | m_movie_next_frame_time = timer_get_time(&m_machine); |
| 411 | |
| 412 | // start up an AVI recording |
| 413 | if (format == MF_AVI) |
| 446 | 414 | { |
| 447 | | int anything_changed = finish_screen_updates(machine); |
| 415 | // build up information about this new movie |
| 416 | avi_movie_info info; |
| 417 | info.video_format = 0; |
| 418 | info.video_timescale = 1000 * ((m_machine.primary_screen != NULL) ? ATTOSECONDS_TO_HZ(m_machine.primary_screen->frame_period().attoseconds) : screen_device::DEFAULT_FRAME_RATE); |
| 419 | info.video_sampletime = 1000; |
| 420 | info.video_numsamples = 0; |
| 421 | info.video_width = m_snap_bitmap->width; |
| 422 | info.video_height = m_snap_bitmap->height; |
| 423 | info.video_depth = 24; |
| 448 | 424 | |
| 449 | | /* if none of the screens changed and we haven't skipped too many frames in a row, |
| 450 | | mark this frame as skipped to prevent throttling; this helps for games that |
| 451 | | don't update their screen at the monitor refresh rate */ |
| 452 | | if (!anything_changed && !global.auto_frameskip && global.frameskip_level == 0 && global.empty_skip_count++ < 3) |
| 453 | | skipped_it = TRUE; |
| 425 | info.audio_format = 0; |
| 426 | info.audio_timescale = m_machine.sample_rate; |
| 427 | info.audio_sampletime = 1; |
| 428 | info.audio_numsamples = 0; |
| 429 | info.audio_channels = 2; |
| 430 | info.audio_samplebits = 16; |
| 431 | info.audio_samplerate = m_machine.sample_rate; |
| 432 | |
| 433 | // create a new temporary movie file |
| 434 | mame_file *tempfile; |
| 435 | file_error filerr; |
| 436 | if (name != NULL) |
| 437 | filerr = mame_fopen(SEARCHPATH_MOVIE, name, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &tempfile); |
| 454 | 438 | else |
| 455 | | global.empty_skip_count = 0; |
| 456 | | } |
| 439 | filerr = mame_fopen_next(SEARCHPATH_MOVIE, "avi", tempfile); |
| 457 | 440 | |
| 458 | | /* draw the user interface */ |
| 459 | | ui_update_and_render(machine, &machine->render().ui_container()); |
| 441 | // compute the frame time |
| 442 | m_movie_frame_period = attotime_div(ATTOTIME_IN_SEC(1000), info.video_timescale); |
| 460 | 443 | |
| 461 | | /* update the internal render debugger */ |
| 462 | | debugint_update_during_game(machine); |
| 444 | // if we succeeded, make a copy of the name and create the real file over top |
| 445 | if (filerr == FILERR_NONE) |
| 446 | { |
| 447 | astring fullname(mame_file_full_name(tempfile)); |
| 448 | mame_fclose(tempfile); |
| 463 | 449 | |
| 464 | | /* if we're throttling, synchronize before rendering */ |
| 465 | | if (!debug && !skipped_it && effective_throttle(machine)) |
| 466 | | update_throttle(machine, current_time); |
| 450 | // create the file and free the string |
| 451 | avi_error avierr = avi_create(fullname, &info, &m_avifile); |
| 452 | if (avierr != AVIERR_NONE) |
| 453 | mame_printf_error("Error creating AVI: %s\n", avi_error_string(avierr)); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | // start up a MNG recording |
| 458 | else if (format == MF_MNG) |
| 459 | { |
| 460 | // create a new movie file and start recording |
| 461 | file_error filerr; |
| 462 | if (name != NULL) |
| 463 | filerr = mame_fopen(SEARCHPATH_MOVIE, name, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &m_mngfile); |
| 464 | else |
| 465 | filerr = mame_fopen_next(SEARCHPATH_MOVIE, "mng", m_mngfile); |
| 467 | 466 | |
| 468 | | /* ask the OSD to update */ |
| 469 | | g_profiler.start(PROFILER_BLIT); |
| 470 | | machine->osd().update(!debug && skipped_it); |
| 471 | | g_profiler.stop(); |
| 467 | // start the capture |
| 468 | int rate = (m_machine.primary_screen != NULL) ? ATTOSECONDS_TO_HZ(m_machine.primary_screen->frame_period().attoseconds) : screen_device::DEFAULT_FRAME_RATE; |
| 469 | png_error pngerr = mng_capture_start(mame_core_file(m_mngfile), m_snap_bitmap, rate); |
| 470 | if (pngerr != PNGERR_NONE) |
| 471 | return end_recording(); |
| 472 | 472 | |
| 473 | | /* perform tasks for this frame */ |
| 474 | | if (!debug) |
| 475 | | machine->call_notifiers(MACHINE_NOTIFY_FRAME); |
| 473 | // compute the frame time |
| 474 | m_movie_frame_period = ATTOTIME_IN_HZ(rate); |
| 475 | } |
| 476 | } |
| 476 | 477 | |
| 477 | | /* update frameskipping */ |
| 478 | | if (!debug) |
| 479 | | update_frameskip(machine); |
| 480 | 478 | |
| 481 | | /* update speed computations */ |
| 482 | | if (!debug && !skipped_it) |
| 483 | | recompute_speed(machine, current_time); |
| 479 | //------------------------------------------------- |
| 480 | // end_recording - stop recording of a movie |
| 481 | //------------------------------------------------- |
| 484 | 482 | |
| 485 | | /* call the end-of-frame callback */ |
| 486 | | if (phase == MACHINE_PHASE_RUNNING) |
| 483 | void video_manager::end_recording() |
| 484 | { |
| 485 | // close the file if it exists |
| 486 | if (m_avifile != NULL) |
| 487 | 487 | { |
| 488 | | /* reset partial updates if we're paused or if the debugger is active */ |
| 489 | | if (machine->primary_screen != NULL && (machine->paused() || debug || debugger_within_instruction_hook(machine))) |
| 490 | | machine->primary_screen->scanline0_callback(); |
| 488 | avi_close(m_avifile); |
| 489 | m_avifile = NULL; |
| 490 | } |
| 491 | 491 | |
| 492 | | /* otherwise, call the video EOF callback */ |
| 493 | | else |
| 494 | | { |
| 495 | | g_profiler.start(PROFILER_VIDEO); |
| 496 | | machine->driver_data<driver_device>()->video_eof(); |
| 497 | | g_profiler.stop(); |
| 498 | | } |
| 492 | // close the file if it exists |
| 493 | if (m_mngfile != NULL) |
| 494 | { |
| 495 | mng_capture_stop(mame_core_file(m_mngfile)); |
| 496 | mame_fclose(m_mngfile); |
| 497 | m_mngfile = NULL; |
| 499 | 498 | } |
| 499 | |
| 500 | // reset the state |
| 501 | m_movie_frame = 0; |
| 500 | 502 | } |
| 501 | 503 | |
| 502 | 504 | |
| 503 | | /*------------------------------------------------- |
| 504 | | finish_screen_updates - finish updating all |
| 505 | | the screens |
| 506 | | -------------------------------------------------*/ |
| 505 | //------------------------------------------------- |
| 506 | // add_sound_to_recording - add sound to a movie |
| 507 | // recording |
| 508 | //------------------------------------------------- |
| 507 | 509 | |
| 508 | | static int finish_screen_updates(running_machine *machine) |
| 510 | void video_manager::add_sound_to_recording(const INT16 *sound, int numsamples) |
| 509 | 511 | { |
| 510 | | bool anything_changed = false; |
| 511 | | |
| 512 | | /* finish updating the screens */ |
| 513 | | for (screen_device *screen = screen_first(*machine); screen != NULL; screen = screen_next(screen)) |
| 514 | | screen->update_partial(screen->visible_area().max_y); |
| 515 | | |
| 516 | | /* now add the quads for all the screens */ |
| 517 | | for (screen_device *screen = screen_first(*machine); screen != NULL; screen = screen_next(screen)) |
| 518 | | if (screen->update_quads()) |
| 519 | | anything_changed = true; |
| 520 | | |
| 521 | | /* update our movie recording and burn-in state */ |
| 522 | | if (!machine->paused()) |
| 512 | // only record if we have a file |
| 513 | if (m_avifile != NULL) |
| 523 | 514 | { |
| 524 | | video_mng_record_frame(machine); |
| 525 | | video_avi_record_frame(machine); |
| 515 | g_profiler.start(PROFILER_MOVIE_REC); |
| 526 | 516 | |
| 527 | | /* iterate over screens and update the burnin for the ones that care */ |
| 528 | | for (screen_device *screen = screen_first(*machine); screen != NULL; screen = screen_next(screen)) |
| 529 | | screen->update_burnin(); |
| 530 | | } |
| 517 | // write the next frame |
| 518 | avi_error avierr = avi_append_sound_samples(m_avifile, 0, sound + 0, numsamples, 1); |
| 519 | if (avierr == AVIERR_NONE) |
| 520 | avierr = avi_append_sound_samples(m_avifile, 1, sound + 1, numsamples, 1); |
| 521 | if (avierr != AVIERR_NONE) |
| 522 | end_recording(); |
| 531 | 523 | |
| 532 | | /* draw any crosshairs */ |
| 533 | | for (screen_device *screen = screen_first(*machine); screen != NULL; screen = screen_next(screen)) |
| 534 | | crosshair_render(*screen); |
| 535 | | |
| 536 | | return anything_changed; |
| 524 | g_profiler.stop(); |
| 525 | } |
| 537 | 526 | } |
| 538 | 527 | |
| 539 | 528 | |
| 540 | 529 | |
| 541 | | /*************************************************************************** |
| 542 | | THROTTLING/FRAMESKIPPING/PERFORMANCE |
| 543 | | ***************************************************************************/ |
| 530 | //------------------------------------------------- |
| 531 | // init_buffered_spriteram - initialize the |
| 532 | // double-buffered spriteram |
| 533 | //------------------------------------------------- |
| 544 | 534 | |
| 545 | | /*------------------------------------------------- |
| 546 | | video_skip_this_frame - accessor to determine |
| 547 | | if this frame is being skipped |
| 548 | | -------------------------------------------------*/ |
| 549 | | |
| 550 | | int video_skip_this_frame(void) |
| 535 | void video_manager::init_buffered_spriteram() |
| 551 | 536 | { |
| 552 | | return global.skipping_this_frame; |
| 553 | | } |
| 537 | assert_always(m_machine.generic.spriteram_size != 0, "Video buffers spriteram but spriteram size is 0"); |
| 554 | 538 | |
| 539 | // allocate memory for the back buffer |
| 540 | m_machine.generic.buffered_spriteram.u8 = auto_alloc_array(&m_machine, UINT8, m_machine.generic.spriteram_size); |
| 555 | 541 | |
| 556 | | /*------------------------------------------------- |
| 557 | | video_get_speed_factor - return the speed |
| 558 | | factor as an integer * 100 |
| 559 | | -------------------------------------------------*/ |
| 542 | // register for saving it |
| 543 | state_save_register_global_pointer(&m_machine, m_machine.generic.buffered_spriteram.u8, m_machine.generic.spriteram_size); |
| 560 | 544 | |
| 561 | | int video_get_speed_factor(void) |
| 562 | | { |
| 563 | | return global.speed; |
| 545 | // do the same for the second back buffer, if present |
| 546 | if (m_machine.generic.spriteram2_size) |
| 547 | { |
| 548 | // allocate memory |
| 549 | m_machine.generic.buffered_spriteram2.u8 = auto_alloc_array(&m_machine, UINT8, m_machine.generic.spriteram2_size); |
| 550 | |
| 551 | // register for saving it |
| 552 | state_save_register_global_pointer(&m_machine, m_machine.generic.buffered_spriteram2.u8, m_machine.generic.spriteram2_size); |
| 553 | } |
| 564 | 554 | } |
| 565 | 555 | |
| 566 | 556 | |
| 567 | | /*------------------------------------------------- |
| 568 | | video_set_speed_factor - sets the speed |
| 569 | | factor as an integer * 100 |
| 570 | | -------------------------------------------------*/ |
| 557 | //------------------------------------------------- |
| 558 | // video_exit - close down the video system |
| 559 | //------------------------------------------------- |
| 571 | 560 | |
| 572 | | void video_set_speed_factor(int speed) |
| 561 | void video_manager::exit_static(running_machine &machine) |
| 573 | 562 | { |
| 574 | | global.speed = speed; |
| 563 | machine.video().exit(); |
| 575 | 564 | } |
| 576 | 565 | |
| 577 | | |
| 578 | | /*------------------------------------------------- |
| 579 | | video_get_speed_text - print the text to |
| 580 | | be displayed in the upper-right corner |
| 581 | | -------------------------------------------------*/ |
| 582 | | |
| 583 | | const char *video_get_speed_text(running_machine *machine) |
| 566 | void video_manager::exit() |
| 584 | 567 | { |
| 585 | | bool paused = machine->paused(); |
| 586 | | static char buffer[1024]; |
| 587 | | char *dest = buffer; |
| 568 | // stop recording any movie |
| 569 | end_recording(); |
| 588 | 570 | |
| 589 | | /* validate */ |
| 590 | | assert(machine != NULL); |
| 571 | // free all the graphics elements |
| 572 | for (int i = 0; i < MAX_GFX_ELEMENTS; i++) |
| 573 | gfx_element_free(m_machine.gfx[i]); |
| 591 | 574 | |
| 592 | | /* if we're paused, just display Paused */ |
| 593 | | if (paused) |
| 594 | | dest += sprintf(dest, "paused"); |
| 575 | // free the snapshot target |
| 576 | m_machine.render().target_free(m_snap_target); |
| 577 | if (m_snap_bitmap != NULL) |
| 578 | global_free(m_snap_bitmap); |
| 595 | 579 | |
| 596 | | /* if we're fast forwarding, just display Fast-forward */ |
| 597 | | else if (global.fastforward) |
| 598 | | dest += sprintf(dest, "fast "); |
| 580 | // print a final result if we have at least 5 seconds' worth of data |
| 581 | if (m_overall_emutime.seconds >= 5) |
| 582 | { |
| 583 | osd_ticks_t tps = osd_ticks_per_second(); |
| 584 | double final_real_time = (double)m_overall_real_seconds + (double)m_overall_real_ticks / (double)tps; |
| 585 | double final_emu_time = attotime_to_double(m_overall_emutime); |
| 586 | mame_printf_info("Average speed: %.2f%% (%d seconds)\n", 100 * final_emu_time / final_real_time, attotime_add_attoseconds(m_overall_emutime, ATTOSECONDS_PER_SECOND / 2).seconds); |
| 587 | } |
| 588 | } |
| 599 | 589 | |
| 600 | | /* if we're auto frameskipping, display that plus the level */ |
| 601 | | else if (effective_autoframeskip(machine)) |
| 602 | | dest += sprintf(dest, "auto%2d/%d", effective_frameskip(), MAX_FRAMESKIP); |
| 603 | 590 | |
| 604 | | /* otherwise, just display the frameskip plus the level */ |
| 605 | | else |
| 606 | | dest += sprintf(dest, "skip %d/%d", effective_frameskip(), MAX_FRAMESKIP); |
| 591 | //------------------------------------------------- |
| 592 | // screenless_update_callback - update generator |
| 593 | // when there are no screens to drive it |
| 594 | //------------------------------------------------- |
| 607 | 595 | |
| 608 | | /* append the speed for all cases except paused */ |
| 609 | | if (!paused) |
| 610 | | dest += sprintf(dest, "%4d%%", (int)(100 * global.speed_percent + 0.5)); |
| 611 | | |
| 612 | | /* display the number of partial updates as well */ |
| 613 | | if (global.partial_updates_this_frame > 1) |
| 614 | | dest += sprintf(dest, "\n%d partial updates", global.partial_updates_this_frame); |
| 615 | | |
| 616 | | /* return a pointer to the static buffer */ |
| 617 | | return buffer; |
| 596 | TIMER_CALLBACK( video_manager::screenless_update_callback ) |
| 597 | { |
| 598 | // force an update |
| 599 | reinterpret_cast<video_manager *>(ptr)->frame_update(false); |
| 618 | 600 | } |
| 619 | 601 | |
| 620 | 602 | |
| 621 | | /*------------------------------------------------- |
| 622 | | video_get_speed_percent - return the current |
| 623 | | effective speed percentage |
| 624 | | -------------------------------------------------*/ |
| 603 | //------------------------------------------------- |
| 604 | // postload - callback for resetting things after |
| 605 | // state has been loaded |
| 606 | //------------------------------------------------- |
| 625 | 607 | |
| 626 | | double video_get_speed_percent(running_machine *machine) |
| 608 | void video_manager::postload() |
| 627 | 609 | { |
| 628 | | return global.speed_percent; |
| 610 | m_movie_next_frame_time = timer_get_time(&m_machine); |
| 629 | 611 | } |
| 630 | 612 | |
| 631 | 613 | |
| 632 | | /*------------------------------------------------- |
| 633 | | video_get_frameskip - return the current |
| 634 | | actual frameskip (-1 means autoframeskip) |
| 635 | | -------------------------------------------------*/ |
| 614 | //------------------------------------------------- |
| 615 | // effective_autoframeskip - return the effective |
| 616 | // autoframeskip value, accounting for fast |
| 617 | // forward |
| 618 | //------------------------------------------------- |
| 636 | 619 | |
| 637 | | int video_get_frameskip(void) |
| 620 | inline int video_manager::effective_autoframeskip() const |
| 638 | 621 | { |
| 639 | | /* if autoframeskip is on, return -1 */ |
| 640 | | if (global.auto_frameskip) |
| 641 | | return -1; |
| 622 | // if we're fast forwarding or paused, autoframeskip is disabled |
| 623 | if (m_fastforward || m_machine.paused()) |
| 624 | return false; |
| 642 | 625 | |
| 643 | | /* otherwise, return the direct level */ |
| 644 | | else |
| 645 | | return global.frameskip_level; |
| 626 | // otherwise, it's up to the user |
| 627 | return m_auto_frameskip; |
| 646 | 628 | } |
| 647 | 629 | |
| 648 | 630 | |
| 649 | | /*------------------------------------------------- |
| 650 | | video_set_frameskip - set the current |
| 651 | | actual frameskip (-1 means autoframeskip) |
| 652 | | -------------------------------------------------*/ |
| 631 | //------------------------------------------------- |
| 632 | // effective_frameskip - return the effective |
| 633 | // frameskip value, accounting for fast |
| 634 | // forward |
| 635 | //------------------------------------------------- |
| 653 | 636 | |
| 654 | | void video_set_frameskip(int frameskip) |
| 637 | inline int video_manager::effective_frameskip() const |
| 655 | 638 | { |
| 656 | | /* -1 means autoframeskip */ |
| 657 | | if (frameskip == -1) |
| 658 | | { |
| 659 | | global.auto_frameskip = TRUE; |
| 660 | | global.frameskip_level = 0; |
| 661 | | } |
| 639 | // if we're fast forwarding, use the maximum frameskip |
| 640 | if (m_fastforward) |
| 641 | return FRAMESKIP_LEVELS - 1; |
| 662 | 642 | |
| 663 | | /* any other level is a direct control */ |
| 664 | | else if (frameskip >= 0 && frameskip <= MAX_FRAMESKIP) |
| 665 | | { |
| 666 | | global.auto_frameskip = FALSE; |
| 667 | | global.frameskip_level = frameskip; |
| 668 | | } |
| 643 | // otherwise, it's up to the user |
| 644 | return m_frameskip_level; |
| 669 | 645 | } |
| 670 | 646 | |
| 671 | 647 | |
| 672 | | /*------------------------------------------------- |
| 673 | | video_get_throttle - return the current |
| 674 | | actual throttle |
| 675 | | -------------------------------------------------*/ |
| 648 | //------------------------------------------------- |
| 649 | // effective_throttle - return the effective |
| 650 | // throttle value, accounting for fast |
| 651 | // forward and user interface |
| 652 | //------------------------------------------------- |
| 676 | 653 | |
| 677 | | int video_get_throttle(void) |
| 654 | inline bool video_manager::effective_throttle() const |
| 678 | 655 | { |
| 679 | | return global.throttle; |
| 656 | // if we're paused, or if the UI is active, we always throttle |
| 657 | if (m_machine.paused() || ui_is_menu_active()) |
| 658 | return true; |
| 659 | |
| 660 | // if we're fast forwarding, we don't throttle |
| 661 | if (m_fastforward) |
| 662 | return false; |
| 663 | |
| 664 | // otherwise, it's up to the user |
| 665 | return m_throttle; |
| 680 | 666 | } |
| 681 | 667 | |
| 682 | 668 | |
| 683 | | /*------------------------------------------------- |
| 684 | | video_set_throttle - set the current |
| 685 | | actual throttle |
| 686 | | -------------------------------------------------*/ |
| 669 | //------------------------------------------------- |
| 670 | // original_speed_setting - return the original |
| 671 | // speed setting |
| 672 | //------------------------------------------------- |
| 687 | 673 | |
| 688 | | void video_set_throttle(int throttle) |
| 674 | inline int video_manager::original_speed_setting() const |
| 689 | 675 | { |
| 690 | | global.throttle = throttle; |
| 676 | return options_get_float(mame_options(), OPTION_SPEED) * 100.0 + 0.5; |
| 691 | 677 | } |
| 692 | 678 | |
| 693 | 679 | |
| 694 | | /*------------------------------------------------- |
| 695 | | video_get_fastforward - return the current |
| 696 | | fastforward value |
| 697 | | -------------------------------------------------*/ |
| 680 | //------------------------------------------------- |
| 681 | // finish_screen_updates - finish updating all |
| 682 | // the screens |
| 683 | //------------------------------------------------- |
| 698 | 684 | |
| 699 | | int video_get_fastforward(void) |
| 685 | bool video_manager::finish_screen_updates() |
| 700 | 686 | { |
| 701 | | return global.fastforward; |
| 702 | | } |
| 687 | // finish updating the screens |
| 688 | for (screen_device *screen = m_machine.first_screen(); screen != NULL; screen = screen->next_screen()) |
| 689 | screen->update_partial(screen->visible_area().max_y); |
| 703 | 690 | |
| 691 | // now add the quads for all the screens |
| 692 | bool anything_changed = false; |
| 693 | for (screen_device *screen = m_machine.first_screen(); screen != NULL; screen = screen->next_screen()) |
| 694 | if (screen->update_quads()) |
| 695 | anything_changed = true; |
| 704 | 696 | |
| 705 | | /*------------------------------------------------- |
| 706 | | video_set_fastforward - set the current |
| 707 | | fastforward value |
| 708 | | -------------------------------------------------*/ |
| 697 | // update our movie recording and burn-in state |
| 698 | if (!m_machine.paused()) |
| 699 | { |
| 700 | record_frame(); |
| 709 | 701 | |
| 710 | | void video_set_fastforward(int _fastforward) |
| 711 | | { |
| 712 | | global.fastforward = _fastforward; |
| 702 | // iterate over screens and update the burnin for the ones that care |
| 703 | for (screen_device *screen = m_machine.first_screen(); screen != NULL; screen = screen->next_screen()) |
| 704 | screen->update_burnin(); |
| 705 | } |
| 706 | |
| 707 | // draw any crosshairs |
| 708 | for (screen_device *screen = m_machine.first_screen(); screen != NULL; screen = screen->next_screen()) |
| 709 | crosshair_render(*screen); |
| 710 | |
| 711 | return anything_changed; |
| 713 | 712 | } |
| 714 | 713 | |
| 715 | 714 | |
| 716 | | /*------------------------------------------------- |
| 717 | | update_throttle - throttle to the game's |
| 718 | | natural speed |
| 719 | | -------------------------------------------------*/ |
| 720 | 715 | |
| 721 | | static void update_throttle(running_machine *machine, attotime emutime) |
| 716 | //------------------------------------------------- |
| 717 | // update_throttle - throttle to the game's |
| 718 | // natural speed |
| 719 | //------------------------------------------------- |
| 720 | |
| 721 | void video_manager::update_throttle(attotime emutime) |
| 722 | 722 | { |
| 723 | 723 | /* |
| 724 | 724 | |
| r9718 | r9719 | |
| 764 | 764 | 2,3,3,4,3,4,4,5, 3,4,4,5,4,5,5,6, 3,4,4,5,4,5,5,6, 4,5,5,6,5,6,6,7, |
| 765 | 765 | 3,4,4,5,4,5,5,6, 4,5,5,6,5,6,6,7, 4,5,5,6,5,6,6,7, 5,6,6,7,6,7,7,8 |
| 766 | 766 | }; |
| 767 | | attoseconds_t real_delta_attoseconds; |
| 768 | | attoseconds_t emu_delta_attoseconds; |
| 769 | | attoseconds_t real_is_ahead_attoseconds; |
| 770 | | attoseconds_t attoseconds_per_tick; |
| 771 | | osd_ticks_t ticks_per_second; |
| 772 | | osd_ticks_t target_ticks; |
| 773 | | osd_ticks_t diff_ticks; |
| 774 | 767 | |
| 775 | | /* apply speed factor to emu time */ |
| 776 | | if (global.speed != 0 && global.speed != 100) |
| 768 | // outer scope so we can break out in case of a resync |
| 769 | while (1) |
| 777 | 770 | { |
| 778 | | /* multiply emutime by 100, then divide by the global speed factor */ |
| 779 | | emutime = attotime_div(attotime_mul(emutime, 100), global.speed); |
| 780 | | } |
| 771 | // apply speed factor to emu time |
| 772 | if (m_speed != 0 && m_speed != 100) |
| 773 | { |
| 774 | // multiply emutime by 100, then divide by the global speed factor |
| 775 | emutime = attotime_div(attotime_mul(emutime, 100), m_speed); |
| 776 | } |
| 781 | 777 | |
| 782 | | /* compute conversion factors up front */ |
| 783 | | ticks_per_second = osd_ticks_per_second(); |
| 784 | | attoseconds_per_tick = ATTOSECONDS_PER_SECOND / ticks_per_second; |
| 778 | // compute conversion factors up front |
| 779 | osd_ticks_t ticks_per_second = osd_ticks_per_second(); |
| 780 | attoseconds_t attoseconds_per_tick = ATTOSECONDS_PER_SECOND / ticks_per_second; |
| 785 | 781 | |
| 786 | | /* if we're paused, emutime will not advance; instead, we subtract a fixed |
| 787 | | amount of time (1/60th of a second) from the emulated time that was passed in, |
| 788 | | and explicitly reset our tracked real and emulated timers to that value ... |
| 789 | | this means we pretend that the last update was exactly 1/60th of a second |
| 790 | | ago, and was in sync in both real and emulated time */ |
| 791 | | if (machine->paused()) |
| 792 | | { |
| 793 | | global.throttle_emutime = attotime_sub_attoseconds(emutime, ATTOSECONDS_PER_SECOND / PAUSED_REFRESH_RATE); |
| 794 | | global.throttle_realtime = global.throttle_emutime; |
| 795 | | } |
| 782 | // if we're paused, emutime will not advance; instead, we subtract a fixed |
| 783 | // amount of time (1/60th of a second) from the emulated time that was passed in, |
| 784 | // and explicitly reset our tracked real and emulated timers to that value ... |
| 785 | // this means we pretend that the last update was exactly 1/60th of a second |
| 786 | // ago, and was in sync in both real and emulated time |
| 787 | if (m_machine.paused()) |
| 788 | { |
| 789 | m_throttle_emutime = attotime_sub_attoseconds(emutime, ATTOSECONDS_PER_SECOND / PAUSED_REFRESH_RATE); |
| 790 | m_throttle_realtime = m_throttle_emutime; |
| 791 | } |
| 796 | 792 | |
| 797 | | /* attempt to detect anomalies in the emulated time by subtracting the previously |
| 798 | | reported value from our current value; this should be a small value somewhere |
| 799 | | between 0 and 1/10th of a second ... anything outside of this range is obviously |
| 800 | | wrong and requires a resync */ |
| 801 | | emu_delta_attoseconds = attotime_to_attoseconds(attotime_sub(emutime, global.throttle_emutime)); |
| 802 | | if (emu_delta_attoseconds < 0 || emu_delta_attoseconds > ATTOSECONDS_PER_SECOND / 10) |
| 803 | | { |
| 804 | | if (LOG_THROTTLE) |
| 805 | | logerror("Resync due to weird emutime delta: %s\n", attotime_string(attotime_make(0, emu_delta_attoseconds), 18)); |
| 806 | | goto resync; |
| 807 | | } |
| 793 | // attempt to detect anomalies in the emulated time by subtracting the previously |
| 794 | // reported value from our current value; this should be a small value somewhere |
| 795 | // between 0 and 1/10th of a second ... anything outside of this range is obviously |
| 796 | // wrong and requires a resync |
| 797 | attoseconds_t emu_delta_attoseconds = attotime_to_attoseconds(attotime_sub(emutime, m_throttle_emutime)); |
| 798 | if (emu_delta_attoseconds < 0 || emu_delta_attoseconds > ATTOSECONDS_PER_SECOND / 10) |
| 799 | { |
| 800 | if (LOG_THROTTLE) |
| 801 | logerror("Resync due to weird emutime delta: %s\n", attotime_string(attotime_make(0, emu_delta_attoseconds), 18)); |
| 802 | break; |
| 803 | } |
| 808 | 804 | |
| 809 | | /* now determine the current real time in OSD-specified ticks; we have to be careful |
| 810 | | here because counters can wrap, so we only use the difference between the last |
| 811 | | read value and the current value in our computations */ |
| 812 | | diff_ticks = osd_ticks() - global.throttle_last_ticks; |
| 813 | | global.throttle_last_ticks += diff_ticks; |
| 805 | // now determine the current real time in OSD-specified ticks; we have to be careful |
| 806 | // here because counters can wrap, so we only use the difference between the last |
| 807 | // read value and the current value in our computations |
| 808 | osd_ticks_t diff_ticks = osd_ticks() - m_throttle_last_ticks; |
| 809 | m_throttle_last_ticks += diff_ticks; |
| 814 | 810 | |
| 815 | | /* if it has been more than a full second of real time since the last call to this |
| 816 | | function, we just need to resynchronize */ |
| 817 | | if (diff_ticks >= ticks_per_second) |
| 818 | | { |
| 819 | | if (LOG_THROTTLE) |
| 820 | | logerror("Resync due to real time advancing by more than 1 second\n"); |
| 821 | | goto resync; |
| 822 | | } |
| 811 | // if it has been more than a full second of real time since the last call to this |
| 812 | // function, we just need to resynchronize |
| 813 | if (diff_ticks >= ticks_per_second) |
| 814 | { |
| 815 | if (LOG_THROTTLE) |
| 816 | logerror("Resync due to real time advancing by more than 1 second\n"); |
| 817 | break; |
| 818 | } |
| 823 | 819 | |
| 824 | | /* convert this value into attoseconds for easier comparison */ |
| 825 | | real_delta_attoseconds = diff_ticks * attoseconds_per_tick; |
| 820 | // convert this value into attoseconds for easier comparison |
| 821 | attoseconds_t real_delta_attoseconds = diff_ticks * attoseconds_per_tick; |
| 826 | 822 | |
| 827 | | /* now update our real and emulated timers with the current values */ |
| 828 | | global.throttle_emutime = emutime; |
| 829 | | global.throttle_realtime = attotime_add_attoseconds(global.throttle_realtime, real_delta_attoseconds); |
| 823 | // now update our real and emulated timers with the current values |
| 824 | m_throttle_emutime = emutime; |
| 825 | m_throttle_realtime = attotime_add_attoseconds(m_throttle_realtime, real_delta_attoseconds); |
| 830 | 826 | |
| 831 | | /* keep a history of whether or not emulated time beat real time over the last few |
| 832 | | updates; this can be used for future heuristics */ |
| 833 | | global.throttle_history = (global.throttle_history << 1) | (emu_delta_attoseconds > real_delta_attoseconds); |
| 827 | // keep a history of whether or not emulated time beat real time over the last few |
| 828 | // updates; this can be used for future heuristics |
| 829 | m_throttle_history = (m_throttle_history << 1) | (emu_delta_attoseconds > real_delta_attoseconds); |
| 834 | 830 | |
| 835 | | /* determine how far ahead real time is versus emulated time; note that we use the |
| 836 | | accumulated times for this instead of the deltas for the current update because |
| 837 | | we want to track time over a longer duration than a single update */ |
| 838 | | real_is_ahead_attoseconds = attotime_to_attoseconds(attotime_sub(global.throttle_emutime, global.throttle_realtime)); |
| 831 | // determine how far ahead real time is versus emulated time; note that we use the |
| 832 | // accumulated times for this instead of the deltas for the current update because |
| 833 | // we want to track time over a longer duration than a single update |
| 834 | attoseconds_t real_is_ahead_attoseconds = attotime_to_attoseconds(attotime_sub(m_throttle_emutime, m_throttle_realtime)); |
| 839 | 835 | |
| 840 | | /* if we're more than 1/10th of a second out, or if we are behind at all and emulation |
| 841 | | is taking longer than the real frame, we just need to resync */ |
| 842 | | if (real_is_ahead_attoseconds < -ATTOSECONDS_PER_SECOND / 10 || |
| 843 | | (real_is_ahead_attoseconds < 0 && popcount[global.throttle_history & 0xff] < 6)) |
| 844 | | { |
| 845 | | if (LOG_THROTTLE) |
| 846 | | logerror("Resync due to being behind: %s (history=%08X)\n", attotime_string(attotime_make(0, -real_is_ahead_attoseconds), 18), global.throttle_history); |
| 847 | | goto resync; |
| 848 | | } |
| 836 | // if we're more than 1/10th of a second out, or if we are behind at all and emulation |
| 837 | // is taking longer than the real frame, we just need to resync |
| 838 | if (real_is_ahead_attoseconds < -ATTOSECONDS_PER_SECOND / 10 || |
| 839 | (real_is_ahead_attoseconds < 0 && popcount[m_throttle_history & 0xff] < 6)) |
| 840 | { |
| 841 | if (LOG_THROTTLE) |
| 842 | logerror("Resync due to being behind: %s (history=%08X)\n", attotime_string(attotime_make(0, -real_is_ahead_attoseconds), 18), m_throttle_history); |
| 843 | break; |
| 844 | } |
| 849 | 845 | |
| 850 | | /* if we're behind, it's time to just get out */ |
| 851 | | if (real_is_ahead_attoseconds < 0) |
| 852 | | return; |
| 846 | // if we're behind, it's time to just get out |
| 847 | if (real_is_ahead_attoseconds < 0) |
| 848 | return; |
| 853 | 849 | |
| 854 | | /* compute the target real time, in ticks, where we want to be */ |
| 855 | | target_ticks = global.throttle_last_ticks + real_is_ahead_attoseconds / attoseconds_per_tick; |
| 850 | // compute the target real time, in ticks, where we want to be |
| 851 | osd_ticks_t target_ticks = m_throttle_last_ticks + real_is_ahead_attoseconds / attoseconds_per_tick; |
| 856 | 852 | |
| 857 | | /* throttle until we read the target, and update real time to match the final time */ |
| 858 | | diff_ticks = throttle_until_ticks(machine, target_ticks) - global.throttle_last_ticks; |
| 859 | | global.throttle_last_ticks += diff_ticks; |
| 860 | | global.throttle_realtime = attotime_add_attoseconds(global.throttle_realtime, diff_ticks * attoseconds_per_tick); |
| 861 | | return; |
| 853 | // throttle until we read the target, and update real time to match the final time |
| 854 | diff_ticks = throttle_until_ticks(target_ticks) - m_throttle_last_ticks; |
| 855 | m_throttle_last_ticks += diff_ticks; |
| 856 | m_throttle_realtime = attotime_add_attoseconds(m_throttle_realtime, diff_ticks * attoseconds_per_tick); |
| 857 | return; |
| 858 | } |
| 862 | 859 | |
| 863 | | resync: |
| 864 | | /* reset realtime and emutime to the same value */ |
| 865 | | global.throttle_realtime = global.throttle_emutime = emutime; |
| 860 | // reset realtime and emutime to the same value |
| 861 | m_throttle_realtime = m_throttle_emutime = emutime; |
| 866 | 862 | } |
| 867 | 863 | |
| 868 | 864 | |
| 869 | | /*------------------------------------------------- |
| 870 | | throttle_until_ticks - spin until the |
| 871 | | specified target time, calling the OSD code |
| 872 | | to sleep if possible |
| 873 | | -------------------------------------------------*/ |
| 865 | //------------------------------------------------- |
| 866 | // throttle_until_ticks - spin until the |
| 867 | // specified target time, calling the OSD code |
| 868 | // to sleep if possible |
| 869 | //------------------------------------------------- |
| 874 | 870 | |
| 875 | | static osd_ticks_t throttle_until_ticks(running_machine *machine, osd_ticks_t target_ticks) |
| 871 | osd_ticks_t video_manager::throttle_until_ticks(osd_ticks_t target_ticks) |
| 876 | 872 | { |
| 877 | | osd_ticks_t minimum_sleep = osd_ticks_per_second() / 1000; |
| 878 | | osd_ticks_t current_ticks = osd_ticks(); |
| 879 | | osd_ticks_t new_ticks; |
| 880 | | int allowed_to_sleep = FALSE; |
| 873 | // we're allowed to sleep via the OSD code only if we're configured to do so |
| 874 | // and we're not frameskipping due to autoframeskip, or if we're paused |
| 875 | bool allowed_to_sleep = false; |
| 876 | if (options_get_bool(m_machine.options(), OPTION_SLEEP) && (!effective_autoframeskip() || effective_frameskip() == 0)) |
| 877 | allowed_to_sleep = true; |
| 878 | if (m_machine.paused()) |
| 879 | allowed_to_sleep = true; |
| 881 | 880 | |
| 882 | | /* we're allowed to sleep via the OSD code only if we're configured to do so |
| 883 | | and we're not frameskipping due to autoframeskip, or if we're paused */ |
| 884 | | if (options_get_bool(machine->options(), OPTION_SLEEP) && (!effective_autoframeskip(machine) || effective_frameskip() == 0)) |
| 885 | | allowed_to_sleep = TRUE; |
| 886 | | if (machine->paused()) |
| 887 | | allowed_to_sleep = TRUE; |
| 888 | | |
| 889 | | /* loop until we reach our target */ |
| 881 | // loop until we reach our target |
| 890 | 882 | g_profiler.start(PROFILER_IDLE); |
| 883 | osd_ticks_t minimum_sleep = osd_ticks_per_second() / 1000; |
| 884 | osd_ticks_t current_ticks = osd_ticks(); |
| 891 | 885 | while (current_ticks < target_ticks) |
| 892 | 886 | { |
| 893 | | osd_ticks_t delta; |
| 894 | | int slept = FALSE; |
| 887 | // compute how much time to sleep for, taking into account the average oversleep |
| 888 | osd_ticks_t delta = (target_ticks - current_ticks) * 1000 / (1000 + m_average_oversleep); |
| 895 | 889 | |
| 896 | | /* compute how much time to sleep for, taking into account the average oversleep */ |
| 897 | | delta = (target_ticks - current_ticks) * 1000 / (1000 + global.average_oversleep); |
| 898 | | |
| 899 | | /* see if we can sleep */ |
| 890 | // see if we can sleep |
| 891 | bool slept = false; |
| 900 | 892 | if (allowed_to_sleep && delta >= minimum_sleep) |
| 901 | 893 | { |
| 902 | 894 | osd_sleep(delta); |
| 903 | | slept = TRUE; |
| 895 | slept = true; |
| 904 | 896 | } |
| 905 | 897 | |
| 906 | | /* read the new value */ |
| 907 | | new_ticks = osd_ticks(); |
| 898 | // read the new value |
| 899 | osd_ticks_t new_ticks = osd_ticks(); |
| 908 | 900 | |
| 909 | | /* keep some metrics on the sleeping patterns of the OSD layer */ |
| 901 | // keep some metrics on the sleeping patterns of the OSD layer |
| 910 | 902 | if (slept) |
| 911 | 903 | { |
| 904 | // if we overslept, keep an average of the amount |
| 912 | 905 | osd_ticks_t actual_ticks = new_ticks - current_ticks; |
| 913 | | |
| 914 | | /* if we overslept, keep an average of the amount */ |
| 915 | 906 | if (actual_ticks > delta) |
| 916 | 907 | { |
| 908 | // take 90% of the previous average plus 10% of the new value |
| 917 | 909 | osd_ticks_t oversleep_milliticks = 1000 * (actual_ticks - delta) / delta; |
| 910 | m_average_oversleep = (m_average_oversleep * 99 + oversleep_milliticks) / 100; |
| 918 | 911 | |
| 919 | | /* take 90% of the previous average plus 10% of the new value */ |
| 920 | | global.average_oversleep = (global.average_oversleep * 99 + oversleep_milliticks) / 100; |
| 921 | | |
| 922 | 912 | if (LOG_THROTTLE) |
| 923 | | logerror("Slept for %d ticks, got %d ticks, avgover = %d\n", (int)delta, (int)actual_ticks, (int)global.average_oversleep); |
| 913 | logerror("Slept for %d ticks, got %d ticks, avgover = %d\n", (int)delta, (int)actual_ticks, (int)m_average_oversleep); |
| 924 | 914 | } |
| 925 | 915 | } |
| 926 | 916 | current_ticks = new_ticks; |
| r9718 | r9719 | |
| 931 | 921 | } |
| 932 | 922 | |
| 933 | 923 | |
| 934 | | /*------------------------------------------------- |
| 935 | | update_frameskip - update frameskipping |
| 936 | | counters and periodically update autoframeskip |
| 937 | | -------------------------------------------------*/ |
| 924 | //------------------------------------------------- |
| 925 | // update_frameskip - update frameskipping |
| 926 | // counters and periodically update autoframeskip |
| 927 | //------------------------------------------------- |
| 938 | 928 | |
| 939 | | static void update_frameskip(running_machine *machine) |
| 929 | void video_manager::update_frameskip() |
| 940 | 930 | { |
| 941 | | /* if we're throttling and autoframeskip is on, adjust */ |
| 942 | | if (effective_throttle(machine) && effective_autoframeskip(machine) && global.frameskip_counter == 0) |
| 931 | // if we're throttling and autoframeskip is on, adjust |
| 932 | if (effective_throttle() && effective_autoframeskip() && m_frameskip_counter == 0) |
| 943 | 933 | { |
| 944 | | double speed = global.speed * 0.01; |
| 945 | | |
| 946 | | /* if we're too fast, attempt to increase the frameskip */ |
| 947 | | if (global.speed_percent >= 0.995 * speed) |
| 934 | // if we're too fast, attempt to increase the frameskip |
| 935 | double speed = m_speed * 0.01; |
| 936 | if (m_speed_percent >= 0.995 * speed) |
| 948 | 937 | { |
| 949 | | /* but only after 3 consecutive frames where we are too fast */ |
| 950 | | if (++global.frameskip_adjust >= 3) |
| 938 | // but only after 3 consecutive frames where we are too fast |
| 939 | if (++m_frameskip_adjust >= 3) |
| 951 | 940 | { |
| 952 | | global.frameskip_adjust = 0; |
| 953 | | if (global.frameskip_level > 0) |
| 954 | | global.frameskip_level--; |
| 941 | m_frameskip_adjust = 0; |
| 942 | if (m_frameskip_level > 0) |
| 943 | m_frameskip_level--; |
| 955 | 944 | } |
| 956 | 945 | } |
| 957 | 946 | |
| 958 | | /* if we're too slow, attempt to increase the frameskip */ |
| 947 | // if we're too slow, attempt to increase the frameskip |
| 959 | 948 | else |
| 960 | 949 | { |
| 961 | | /* if below 80% speed, be more aggressive */ |
| 962 | | if (global.speed_percent < 0.80 * speed) |
| 963 | | global.frameskip_adjust -= (0.90 * speed - global.speed_percent) / 0.05; |
| 950 | // if below 80% speed, be more aggressive |
| 951 | if (m_speed_percent < 0.80 * speed) |
| 952 | m_frameskip_adjust -= (0.90 * speed - m_speed_percent) / 0.05; |
| 964 | 953 | |
| 965 | | /* if we're close, only force it up to frameskip 8 */ |
| 966 | | else if (global.frameskip_level < 8) |
| 967 | | global.frameskip_adjust--; |
| 954 | // if we're close, only force it up to frameskip 8 |
| 955 | else if (m_frameskip_level < 8) |
| 956 | m_frameskip_adjust--; |
| 968 | 957 | |
| 969 | | /* perform the adjustment */ |
| 970 | | while (global.frameskip_adjust <= -2) |
| 958 | // perform the adjustment |
| 959 | while (m_frameskip_adjust <= -2) |
| 971 | 960 | { |
| 972 | | global.frameskip_adjust += 2; |
| 973 | | if (global.frameskip_level < MAX_FRAMESKIP) |
| 974 | | global.frameskip_level++; |
| 961 | m_frameskip_adjust += 2; |
| 962 | if (m_frameskip_level < MAX_FRAMESKIP) |
| 963 | m_frameskip_level++; |
| 975 | 964 | } |
| 976 | 965 | } |
| 977 | 966 | } |
| 978 | 967 | |
| 979 | | /* increment the frameskip counter and determine if we will skip the next frame */ |
| 980 | | global.frameskip_counter = (global.frameskip_counter + 1) % FRAMESKIP_LEVELS; |
| 981 | | global.skipping_this_frame = skiptable[effective_frameskip()][global.frameskip_counter]; |
| 968 | // increment the frameskip counter and determine if we will skip the next frame |
| 969 | m_frameskip_counter = (m_frameskip_counter + 1) % FRAMESKIP_LEVELS; |
| 970 | m_skipping_this_frame = s_skiptable[effective_frameskip()][m_frameskip_counter]; |
| 982 | 971 | } |
| 983 | 972 | |
| 984 | 973 | |
| 985 | | /*------------------------------------------------- |
| 986 | | update_refresh_speed - update the global.speed |
| 987 | | based on the maximum refresh rate supported |
| 988 | | -------------------------------------------------*/ |
| 974 | //------------------------------------------------- |
| 975 | // update_refresh_speed - update the m_speed |
| 976 | // based on the maximum refresh rate supported |
| 977 | //------------------------------------------------- |
| 989 | 978 | |
| 990 | | static void update_refresh_speed(running_machine *machine) |
| 979 | void video_manager::update_refresh_speed() |
| 991 | 980 | { |
| 992 | | /* only do this if the refreshspeed option is used */ |
| 993 | | if (options_get_bool(machine->options(), OPTION_REFRESHSPEED)) |
| 981 | // only do this if the refreshspeed option is used |
| 982 | if (options_get_bool(m_machine.options(), OPTION_REFRESHSPEED)) |
| 994 | 983 | { |
| 995 | | float minrefresh = machine->render().max_update_rate(); |
| 984 | float minrefresh = m_machine.render().max_update_rate(); |
| 996 | 985 | if (minrefresh != 0) |
| 997 | 986 | { |
| 987 | // find the screen with the shortest frame period (max refresh rate) |
| 988 | // note that we first check the token since this can get called before all screens are created |
| 998 | 989 | attoseconds_t min_frame_period = ATTOSECONDS_PER_SECOND; |
| 999 | | UINT32 original_speed = original_speed_setting(); |
| 1000 | | UINT32 target_speed; |
| 1001 | | |
| 1002 | | /* find the screen with the shortest frame period (max refresh rate) */ |
| 1003 | | /* note that we first check the token since this can get called before all screens are created */ |
| 1004 | | for (screen_device *screen = screen_first(*machine); screen != NULL; screen = screen_next(screen)) |
| 990 | for (screen_device *screen = m_machine.first_screen(); screen != NULL; screen = screen->next_screen()) |
| 1005 | 991 | { |
| 1006 | 992 | attoseconds_t period = screen->frame_period().attoseconds; |
| 1007 | 993 | if (period != 0) |
| 1008 | 994 | min_frame_period = MIN(min_frame_period, period); |
| 1009 | 995 | } |
| 1010 | 996 | |
| 1011 | | /* compute a target speed as an integral percentage */ |
| 1012 | | /* note that we lop 0.25Hz off of the minrefresh when doing the computation to allow for |
| 1013 | | the fact that most refresh rates are not accurate to 10 digits... */ |
| 1014 | | target_speed = floor((minrefresh - 0.25f) * 100.0 / ATTOSECONDS_TO_HZ(min_frame_period)); |
| 997 | // compute a target speed as an integral percentage |
| 998 | // note that we lop 0.25Hz off of the minrefresh when doing the computation to allow for |
| 999 | // the fact that most refresh rates are not accurate to 10 digits... |
| 1000 | UINT32 target_speed = floor((minrefresh - 0.25f) * 100.0 / ATTOSECONDS_TO_HZ(min_frame_period)); |
| 1001 | UINT32 original_speed = original_speed_setting(); |
| 1015 | 1002 | target_speed = MIN(target_speed, original_speed); |
| 1016 | 1003 | |
| 1017 | | /* if we changed, log that verbosely */ |
| 1018 | | if (target_speed != global.speed) |
| 1004 | // if we changed, log that verbosely |
| 1005 | if (target_speed != m_speed) |
| 1019 | 1006 | { |
| 1020 | 1007 | mame_printf_verbose("Adjusting target speed to %d%% (hw=%.2fHz, game=%.2fHz, adjusted=%.2fHz)\n", target_speed, minrefresh, ATTOSECONDS_TO_HZ(min_frame_period), ATTOSECONDS_TO_HZ(min_frame_period * 100 / target_speed)); |
| 1021 | | global.speed = target_speed; |
| 1008 | m_speed = target_speed; |
| 1022 | 1009 | } |
| 1023 | 1010 | } |
| 1024 | 1011 | } |
| 1025 | 1012 | } |
| 1026 | 1013 | |
| 1027 | 1014 | |
| 1028 | | /*------------------------------------------------- |
| 1029 | | recompute_speed - recompute the current |
| 1030 | | overall speed; we assume this is called only |
| 1031 | | if we did not skip a frame |
| 1032 | | -------------------------------------------------*/ |
| 1015 | //------------------------------------------------- |
| 1016 | // recompute_speed - recompute the current |
| 1017 | // overall speed; we assume this is called only |
| 1018 | // if we did not skip a frame |
| 1019 | //------------------------------------------------- |
| 1033 | 1020 | |
| 1034 | | static void recompute_speed(running_machine *machine, attotime emutime) |
| 1021 | void video_manager::recompute_speed(attotime emutime) |
| 1035 | 1022 | { |
| 1036 | | attoseconds_t delta_emutime; |
| 1037 | | |
| 1038 | | /* if we don't have a starting time yet, or if we're paused, reset our starting point */ |
| 1039 | | if (global.speed_last_realtime == 0 || machine->paused()) |
| 1023 | // if we don't have a starting time yet, or if we're paused, reset our starting point |
| 1024 | if (m_speed_last_realtime == 0 || m_machine.paused()) |
| 1040 | 1025 | { |
| 1041 | | global.speed_last_realtime = osd_ticks(); |
| 1042 | | global.speed_last_emutime = emutime; |
| 1026 | m_speed_last_realtime = osd_ticks(); |
| 1027 | m_speed_last_emutime = emutime; |
| 1043 | 1028 | } |
| 1044 | 1029 | |
| 1045 | | /* if it has been more than the update interval, update the time */ |
| 1046 | | delta_emutime = attotime_to_attoseconds(attotime_sub(emutime, global.speed_last_emutime)); |
| 1030 | // if it has been more than the update interval, update the time |
| 1031 | attoseconds_t delta_emutime = attotime_to_attoseconds(attotime_sub(emutime, m_speed_last_emutime)); |
| 1047 | 1032 | if (delta_emutime > SUBSECONDS_PER_SPEED_UPDATE) |
| 1048 | 1033 | { |
| 1034 | // convert from ticks to attoseconds |
| 1049 | 1035 | osd_ticks_t realtime = osd_ticks(); |
| 1050 | | osd_ticks_t delta_realtime = realtime - global.speed_last_realtime; |
| 1036 | osd_ticks_t delta_realtime = realtime - m_speed_last_realtime; |
| 1051 | 1037 | osd_ticks_t tps = osd_ticks_per_second(); |
| 1038 | m_speed_percent = (double)delta_emutime * (double)tps / ((double)delta_realtime * (double)ATTOSECONDS_PER_SECOND); |
| 1052 | 1039 | |
| 1053 | | /* convert from ticks to attoseconds */ |
| 1054 | | global.speed_percent = (double)delta_emutime * (double)tps / ((double)delta_realtime * (double)ATTOSECONDS_PER_SECOND); |
| 1040 | // remember the last times |
| 1041 | m_speed_last_realtime = realtime; |
| 1042 | m_speed_last_emutime = emutime; |
| 1055 | 1043 | |
| 1056 | | /* remember the last times */ |
| 1057 | | global.speed_last_realtime = realtime; |
| 1058 | | global.speed_last_emutime = emutime; |
| 1059 | | |
| 1060 | | /* if we're throttled, this time period counts for overall speed; otherwise, we reset the counter */ |
| 1061 | | if (!global.fastforward) |
| 1062 | | global.overall_valid_counter++; |
| 1044 | // if we're throttled, this time period counts for overall speed; otherwise, we reset the counter |
| 1045 | if (!m_fastforward) |
| 1046 | m_overall_valid_counter++; |
| 1063 | 1047 | else |
| 1064 | | global.overall_valid_counter = 0; |
| 1048 | m_overall_valid_counter = 0; |
| 1065 | 1049 | |
| 1066 | | /* if we've had at least 4 consecutive valid periods, accumulate stats */ |
| 1067 | | if (global.overall_valid_counter >= 4) |
| 1050 | // if we've had at least 4 consecutive valid periods, accumulate stats |
| 1051 | if (m_overall_valid_counter >= 4) |
| 1068 | 1052 | { |
| 1069 | | global.overall_real_ticks += delta_realtime; |
| 1070 | | while (global.overall_real_ticks >= tps) |
| 1053 | m_overall_real_ticks += delta_realtime; |
| 1054 | while (m_overall_real_ticks >= tps) |
| 1071 | 1055 | { |
| 1072 | | global.overall_real_ticks -= tps; |
| 1073 | | global.overall_real_seconds++; |
| 1056 | m_overall_real_ticks -= tps; |
| 1057 | m_overall_real_seconds++; |
| 1074 | 1058 | } |
| 1075 | | global.overall_emutime = attotime_add_attoseconds(global.overall_emutime, delta_emutime); |
| 1059 | m_overall_emutime = attotime_add_attoseconds(m_overall_emutime, delta_emutime); |
| 1076 | 1060 | } |
| 1077 | 1061 | } |
| 1078 | 1062 | |
| 1079 | | /* if we're past the "time-to-execute" requested, signal an exit */ |
| 1080 | | if (global.seconds_to_run != 0 && emutime.seconds >= global.seconds_to_run) |
| 1063 | // if we're past the "time-to-execute" requested, signal an exit |
| 1064 | if (m_seconds_to_run != 0 && emutime.seconds >= m_seconds_to_run) |
| 1081 | 1065 | { |
| 1082 | | if (machine->primary_screen != NULL) |
| 1066 | if (m_machine.primary_screen != NULL) |
| 1083 | 1067 | { |
| 1084 | | astring fname(machine->basename(), PATH_SEPARATOR "final.png"); |
| 1085 | | file_error filerr; |
| 1086 | | mame_file *file; |
| 1068 | astring fname(m_machine.basename(), PATH_SEPARATOR "final.png"); |
| 1087 | 1069 | |
| 1088 | | /* create a final screenshot */ |
| 1089 | | filerr = mame_fopen(SEARCHPATH_SCREENSHOT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file); |
| 1070 | // create a final screenshot |
| 1071 | mame_file *file; |
| 1072 | file_error filerr = mame_fopen(SEARCHPATH_SCREENSHOT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file); |
| 1090 | 1073 | if (filerr == FILERR_NONE) |
| 1091 | 1074 | { |
| 1092 | | screen_save_snapshot(machine, machine->primary_screen, file); |
| 1075 | save_snapshot(m_machine.primary_screen, *file); |
| 1093 | 1076 | mame_fclose(file); |
| 1094 | 1077 | } |
| 1095 | 1078 | } |
| 1096 | 1079 | |
| 1097 | | /* schedule our demise */ |
| 1098 | | machine->schedule_exit(); |
| 1080 | // schedule our demise |
| 1081 | m_machine.schedule_exit(); |
| 1099 | 1082 | } |
| 1100 | 1083 | } |
| 1101 | 1084 | |
| 1102 | 1085 | |
| 1086 | //------------------------------------------------- |
| 1087 | // create_snapshot_bitmap - creates a |
| 1088 | // bitmap containing the screenshot for the |
| 1089 | // given screen |
| 1090 | //------------------------------------------------- |
| 1103 | 1091 | |
| 1104 | | /*************************************************************************** |
| 1105 | | SCREEN SNAPSHOTS |
| 1106 | | ***************************************************************************/ |
| 1107 | | |
| 1108 | | /*------------------------------------------------- |
| 1109 | | screen_save_snapshot - save a snapshot |
| 1110 | | to the given file handle |
| 1111 | | -------------------------------------------------*/ |
| 1112 | | |
| 1113 | | void screen_save_snapshot(running_machine *machine, device_t *screen, mame_file *fp) |
| 1092 | void video_manager::create_snapshot_bitmap(device_t *screen) |
| 1114 | 1093 | { |
| 1115 | | png_info pnginfo = { 0 }; |
| 1116 | | const rgb_t *palette; |
| 1117 | | png_error error; |
| 1118 | | char text[256]; |
| 1119 | | |
| 1120 | | /* validate */ |
| 1121 | | assert(!global.snap_native || screen != NULL); |
| 1122 | | assert(fp != NULL); |
| 1123 | | |
| 1124 | | /* create the bitmap to pass in */ |
| 1125 | | create_snapshot_bitmap(screen); |
| 1126 | | |
| 1127 | | /* add two text entries describing the image */ |
| 1128 | | sprintf(text, APPNAME " %s", build_version); |
| 1129 | | png_add_text(&pnginfo, "Software", text); |
| 1130 | | sprintf(text, "%s %s", machine->gamedrv->manufacturer, machine->gamedrv->description); |
| 1131 | | png_add_text(&pnginfo, "System", text); |
| 1132 | | |
| 1133 | | /* now do the actual work */ |
| 1134 | | palette = (machine->palette != NULL) ? palette_entry_list_adjusted(machine->palette) : NULL; |
| 1135 | | error = png_write_bitmap(mame_core_file(fp), &pnginfo, global.snap_bitmap, machine->total_colors(), palette); |
| 1136 | | |
| 1137 | | /* free any data allocated */ |
| 1138 | | png_free(&pnginfo); |
| 1139 | | } |
| 1140 | | |
| 1141 | | |
| 1142 | | /*------------------------------------------------- |
| 1143 | | video_save_active_screen_snapshots - save a |
| 1144 | | snapshot of all active screens |
| 1145 | | -------------------------------------------------*/ |
| 1146 | | |
| 1147 | | void video_save_active_screen_snapshots(running_machine *machine) |
| 1148 | | { |
| 1149 | | mame_file *fp; |
| 1150 | | |
| 1151 | | /* validate */ |
| 1152 | | assert(machine != NULL); |
| 1153 | | assert(machine->config != NULL); |
| 1154 | | |
| 1155 | | /* if we're native, then write one snapshot per visible screen */ |
| 1156 | | if (global.snap_native) |
| 1094 | // select the appropriate view in our dummy target |
| 1095 | if (m_snap_native && screen != NULL) |
| 1157 | 1096 | { |
| 1158 | | /* write one snapshot per visible screen */ |
| 1159 | | for (screen_device *screen = screen_first(*machine); screen != NULL; screen = screen_next(screen)) |
| 1160 | | if (machine->render().is_live(*screen)) |
| 1161 | | { |
| 1162 | | file_error filerr = mame_fopen_next(machine, SEARCHPATH_SCREENSHOT, "png", &fp); |
| 1163 | | if (filerr == FILERR_NONE) |
| 1164 | | { |
| 1165 | | screen_save_snapshot(machine, screen, fp); |
| 1166 | | mame_fclose(fp); |
| 1167 | | } |
| 1168 | | } |
| 1169 | | } |
| 1170 | | |
| 1171 | | /* otherwise, just write a single snapshot */ |
| 1172 | | else |
| 1173 | | { |
| 1174 | | file_error filerr = mame_fopen_next(machine, SEARCHPATH_SCREENSHOT, "png", &fp); |
| 1175 | | if (filerr == FILERR_NONE) |
| 1176 | | { |
| 1177 | | screen_save_snapshot(machine, NULL, fp); |
| 1178 | | mame_fclose(fp); |
| 1179 | | } |
| 1180 | | } |
| 1181 | | } |
| 1182 | | |
| 1183 | | |
| 1184 | | /*------------------------------------------------- |
| 1185 | | creare_snapshot_bitmap - creates a |
| 1186 | | bitmap containing the screenshot for the |
| 1187 | | given screen |
| 1188 | | -------------------------------------------------*/ |
| 1189 | | |
| 1190 | | static void create_snapshot_bitmap(device_t *screen) |
| 1191 | | { |
| 1192 | | INT32 width, height; |
| 1193 | | int view_index; |
| 1194 | | |
| 1195 | | /* select the appropriate view in our dummy target */ |
| 1196 | | if (global.snap_native && screen != NULL) |
| 1197 | | { |
| 1198 | | view_index = screen->machine->m_devicelist.index(SCREEN, screen->tag()); |
| 1097 | int view_index = m_machine.m_devicelist.index(SCREEN, screen->tag()); |
| 1199 | 1098 | assert(view_index != -1); |
| 1200 | | global.snap_target->set_view(view_index); |
| 1099 | m_snap_target->set_view(view_index); |
| 1201 | 1100 | } |
| 1202 | 1101 | |
| 1203 | | /* get the minimum width/height and set it on the target */ |
| 1204 | | width = global.snap_width; |
| 1205 | | height = global.snap_height; |
| 1102 | // get the minimum width/height and set it on the target |
| 1103 | INT32 width = m_snap_width; |
| 1104 | INT32 height = m_snap_height; |
| 1206 | 1105 | if (width == 0 || height == 0) |
| 1207 | | global.snap_target->compute_minimum_size(width, height); |
| 1208 | | global.snap_target->set_bounds(width, height); |
| 1106 | m_snap_target->compute_minimum_size(width, height); |
| 1107 | m_snap_target->set_bounds(width, height); |
| 1209 | 1108 | |
| 1210 | | /* if we don't have a bitmap, or if it's not the right size, allocate a new one */ |
| 1211 | | if (global.snap_bitmap == NULL || width != global.snap_bitmap->width || height != global.snap_bitmap->height) |
| 1109 | // if we don't have a bitmap, or if it's not the right size, allocate a new one |
| 1110 | if (m_snap_bitmap == NULL || width != m_snap_bitmap->width || height != m_snap_bitmap->height) |
| 1212 | 1111 | { |
| 1213 | | if (global.snap_bitmap != NULL) |
| 1214 | | global_free(global.snap_bitmap); |
| 1215 | | global.snap_bitmap = global_alloc(bitmap_t(width, height, BITMAP_FORMAT_RGB32)); |
| 1216 | | assert(global.snap_bitmap != NULL); |
| 1112 | if (m_snap_bitmap != NULL) |
| 1113 | auto_free(&m_machine, m_snap_bitmap); |
| 1114 | m_snap_bitmap = auto_alloc(&m_machine, bitmap_t(width, height, BITMAP_FORMAT_RGB32)); |
| 1217 | 1115 | } |
| 1218 | 1116 | |
| 1219 | | /* render the screen there */ |
| 1220 | | render_primitive_list &primlist = global.snap_target->get_primitives(); |
| 1117 | // render the screen there |
| 1118 | render_primitive_list &primlist = m_snap_target->get_primitives(); |
| 1221 | 1119 | primlist.acquire_lock(); |
| 1222 | | rgb888_draw_primitives(primlist, global.snap_bitmap->base, width, height, global.snap_bitmap->rowpixels); |
| 1120 | rgb888_draw_primitives(primlist, m_snap_bitmap->base, width, height, m_snap_bitmap->rowpixels); |
| 1223 | 1121 | primlist.release_lock(); |
| 1224 | 1122 | } |
| 1225 | 1123 | |
| 1226 | 1124 | |
| 1227 | | /*------------------------------------------------- |
| 1228 | | mame_fopen_next - open the next non-existing |
| 1229 | | file of type filetype according to our |
| 1230 | | numbering scheme |
| 1231 | | -------------------------------------------------*/ |
| 1125 | //------------------------------------------------- |
| 1126 | // mame_fopen_next - open the next non-existing |
| 1127 | // file of type filetype according to our |
| 1128 | // numbering scheme |
| 1129 | //------------------------------------------------- |
| 1232 | 1130 | |
| 1233 | | static file_error mame_fopen_next(running_machine *machine, const char *pathoption, const char *extension, mame_file **file) |
| 1131 | file_error video_manager::mame_fopen_next(const char *pathoption, const char *extension, mame_file *&file) |
| 1234 | 1132 | { |
| 1235 | | const char *snapname = options_get_string(machine->options(), OPTION_SNAPNAME); |
| 1236 | | file_error filerr; |
| 1237 | | astring snapstr; |
| 1238 | | astring fname; |
| 1239 | | int index; |
| 1240 | | |
| 1241 | | /* handle defaults */ |
| 1133 | // handle defaults |
| 1134 | const char *snapname = options_get_string(m_machine.options(), OPTION_SNAPNAME); |
| 1242 | 1135 | if (snapname == NULL || snapname[0] == 0) |
| 1243 | 1136 | snapname = "%g/%i"; |
| 1244 | | snapstr.cpy(snapname); |
| 1137 | astring snapstr(snapname); |
| 1245 | 1138 | |
| 1246 | | /* strip any extension in the provided name and add our own */ |
| 1247 | | index = snapstr.rchr(0, '.'); |
| 1139 | // strip any extension in the provided name and add our own |
| 1140 | int index = snapstr.rchr(0, '.'); |
| 1248 | 1141 | if (index != -1) |
| 1249 | 1142 | snapstr.substr(0, index); |
| 1250 | 1143 | snapstr.cat(".").cat(extension); |
| 1251 | 1144 | |
| 1252 | | /* substitute path and gamename up front */ |
| 1145 | // substitute path and gamename up front |
| 1253 | 1146 | snapstr.replace(0, "/", PATH_SEPARATOR); |
| 1254 | | snapstr.replace(0, "%g", machine->basename()); |
| 1147 | snapstr.replace(0, "%g", m_machine.basename()); |
| 1255 | 1148 | |
| 1256 | | /* determine if the template has an index; if not, we always use the same name */ |
| 1149 | // determine if the template has an index; if not, we always use the same name |
| 1150 | astring fname; |
| 1257 | 1151 | if (snapstr.find(0, "%i") == -1) |
| 1258 | 1152 | fname.cpy(snapstr); |
| 1259 | 1153 | |
| 1260 | | /* otherwise, we scan for the next available filename */ |
| 1154 | // otherwise, we scan for the next available filename |
| 1261 | 1155 | else |
| 1262 | 1156 | { |
| 1263 | | int seq; |
| 1264 | | |
| 1265 | | /* try until we succeed */ |
| 1266 | | for (seq = 0; ; seq++) |
| 1157 | // try until we succeed |
| 1158 | astring seqtext; |
| 1159 | for (int seq = 0; ; seq++) |
| 1267 | 1160 | { |
| 1268 | | char seqtext[10]; |
| 1161 | // build up the filename |
| 1162 | fname.cpy(snapstr).replace(0, "%i", seqtext.format("%04d", seq).cstr()); |
| 1269 | 1163 | |
| 1270 | | /* make text for the sequence number */ |
| 1271 | | sprintf(seqtext, "%04d", seq); |
| 1272 | | |
| 1273 | | /* build up the filename */ |
| 1274 | | fname.cpy(snapstr).replace(0, "%i", seqtext); |
| 1275 | | |
| 1276 | | /* try to open the file; stop when we fail */ |
| 1277 | | filerr = mame_fopen(pathoption, fname, OPEN_FLAG_READ, file); |
| 1164 | // try to open the file; stop when we fail |
| 1165 | file_error filerr = mame_fopen(pathoption, fname, OPEN_FLAG_READ, &file); |
| 1278 | 1166 | if (filerr != FILERR_NONE) |
| 1279 | 1167 | break; |
| 1280 | | mame_fclose(*file); |
| 1168 | mame_fclose(file); |
| 1281 | 1169 | } |
| 1282 | 1170 | } |
| 1283 | 1171 | |
| 1284 | | /* create the final file */ |
| 1285 | | return mame_fopen(pathoption, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, file); |
| 1172 | // create the final file |
| 1173 | return mame_fopen(pathoption, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file); |
| 1286 | 1174 | } |
| 1287 | 1175 | |
| 1288 | 1176 | |
| 1289 | 1177 | |
| 1290 | | /*************************************************************************** |
| 1291 | | MNG MOVIE RECORDING |
| 1292 | | ***************************************************************************/ |
| 1178 | //------------------------------------------------- |
| 1179 | // record_frame - record a frame of a movie |
| 1180 | //------------------------------------------------- |
| 1293 | 1181 | |
| 1294 | | /*------------------------------------------------- |
| 1295 | | video_mng_is_movie_active - return true if a |
| 1296 | | MNG movie is currently being recorded |
| 1297 | | -------------------------------------------------*/ |
| 1298 | | |
| 1299 | | int video_mng_is_movie_active(running_machine *machine) |
| 1182 | void video_manager::record_frame() |
| 1300 | 1183 | { |
| 1301 | | return (global.mngfile != NULL); |
| 1302 | | } |
| 1303 | | |
| 1304 | | |
| 1305 | | /*------------------------------------------------- |
| 1306 | | video_mng_begin_recording - begin recording |
| 1307 | | of a MNG movie |
| 1308 | | -------------------------------------------------*/ |
| 1309 | | |
| 1310 | | void video_mng_begin_recording(running_machine *machine, const char *name) |
| 1311 | | { |
| 1312 | | file_error filerr; |
| 1313 | | png_error pngerr; |
| 1314 | | int rate; |
| 1315 | | |
| 1316 | | /* close any existing movie file */ |
| 1317 | | if (global.mngfile != NULL) |
| 1318 | | video_mng_end_recording(machine); |
| 1319 | | |
| 1320 | | /* create a snapshot bitmap so we know what the target size is */ |
| 1321 | | create_snapshot_bitmap(NULL); |
| 1322 | | |
| 1323 | | /* create a new movie file and start recording */ |
| 1324 | | if (name != NULL) |
| 1325 | | filerr = mame_fopen(SEARCHPATH_MOVIE, name, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &global.mngfile); |
| 1326 | | else |
| 1327 | | filerr = mame_fopen_next(machine, SEARCHPATH_MOVIE, "mng", &global.mngfile); |
| 1328 | | |
| 1329 | | /* start the capture */ |
| 1330 | | rate = (machine->primary_screen != NULL) ? ATTOSECONDS_TO_HZ(machine->primary_screen->frame_period().attoseconds) : screen_device::k_default_frame_rate; |
| 1331 | | pngerr = mng_capture_start(mame_core_file(global.mngfile), global.snap_bitmap, rate); |
| 1332 | | if (pngerr != PNGERR_NONE) |
| 1333 | | { |
| 1334 | | video_mng_end_recording(machine); |
| 1184 | // ignore if nothing to do |
| 1185 | if (m_mngfile == NULL && m_avifile == NULL) |
| 1335 | 1186 | return; |
| 1336 | | } |
| 1337 | 1187 | |
| 1338 | | /* compute the frame time */ |
| 1339 | | global.movie_next_frame_time = timer_get_time(machine); |
| 1340 | | global.movie_frame_period = ATTOTIME_IN_HZ(rate); |
| 1341 | | global.movie_frame = 0; |
| 1342 | | } |
| 1188 | // start the profiler and get the current time |
| 1189 | g_profiler.start(PROFILER_MOVIE_REC); |
| 1190 | attotime curtime = timer_get_time(&m_machine); |
| 1343 | 1191 | |
| 1344 | | |
| 1345 | | /*------------------------------------------------- |
| 1346 | | video_mng_end_recording - stop recording of |
| 1347 | | a MNG movie |
| 1348 | | -------------------------------------------------*/ |
| 1349 | | |
| 1350 | | void video_mng_end_recording(running_machine *machine) |
| 1351 | | { |
| 1352 | | /* close the file if it exists */ |
| 1353 | | if (global.mngfile != NULL) |
| 1354 | | { |
| 1355 | | mng_capture_stop(mame_core_file(global.mngfile)); |
| 1356 | | mame_fclose(global.mngfile); |
| 1357 | | global.mngfile = NULL; |
| 1358 | | global.movie_frame = 0; |
| 1359 | | } |
| 1360 | | } |
| 1361 | | |
| 1362 | | |
| 1363 | | /*------------------------------------------------- |
| 1364 | | video_mng_record_frame - record a frame of a |
| 1365 | | movie |
| 1366 | | -------------------------------------------------*/ |
| 1367 | | |
| 1368 | | static void video_mng_record_frame(running_machine *machine) |
| 1369 | | { |
| 1370 | | /* only record if we have a file */ |
| 1371 | | if (global.mngfile != NULL) |
| 1372 | | { |
| 1373 | | attotime curtime = timer_get_time(machine); |
| 1374 | | png_info pnginfo = { 0 }; |
| 1375 | | png_error error; |
| 1376 | | |
| 1377 | | g_profiler.start(PROFILER_MOVIE_REC); |
| 1378 | | |
| 1379 | | /* create the bitmap */ |
| 1380 | | create_snapshot_bitmap(NULL); |
| 1381 | | |
| 1382 | | /* loop until we hit the right time */ |
| 1383 | | while (attotime_compare(global.movie_next_frame_time, curtime) <= 0) |
| 1384 | | { |
| 1385 | | const rgb_t *palette; |
| 1386 | | |
| 1387 | | /* set up the text fields in the movie info */ |
| 1388 | | if (global.movie_frame == 0) |
| 1389 | | { |
| 1390 | | char text[256]; |
| 1391 | | |
| 1392 | | sprintf(text, APPNAME " %s", build_version); |
| 1393 | | png_add_text(&pnginfo, "Software", text); |
| 1394 | | sprintf(text, "%s %s", machine->gamedrv->manufacturer, machine->gamedrv->description); |
| 1395 | | png_add_text(&pnginfo, "System", text); |
| 1396 | | } |
| 1397 | | |
| 1398 | | /* write the next frame */ |
| 1399 | | palette = (machine->palette != NULL) ? palette_entry_list_adjusted(machine->palette) : NULL; |
| 1400 | | error = mng_capture_frame(mame_core_file(global.mngfile), &pnginfo, global.snap_bitmap, machine->total_colors(), palette); |
| 1401 | | png_free(&pnginfo); |
| 1402 | | if (error != PNGERR_NONE) |
| 1403 | | { |
| 1404 | | video_mng_end_recording(machine); |
| 1405 | | break; |
| 1406 | | } |
| 1407 | | |
| 1408 | | /* advance time */ |
| 1409 | | global.movie_next_frame_time = attotime_add(global.movie_next_frame_time, global.movie_frame_period); |
| 1410 | | global.movie_frame++; |
| 1411 | | } |
| 1412 | | |
| 1413 | | g_profiler.stop(); |
| 1414 | | } |
| 1415 | | } |
| 1416 | | |
| 1417 | | |
| 1418 | | |
| 1419 | | /*************************************************************************** |
| 1420 | | AVI MOVIE RECORDING |
| 1421 | | ***************************************************************************/ |
| 1422 | | |
| 1423 | | /*------------------------------------------------- |
| 1424 | | video_avi_begin_recording - begin recording |
| 1425 | | of an AVI movie |
| 1426 | | -------------------------------------------------*/ |
| 1427 | | |
| 1428 | | void video_avi_begin_recording(running_machine *machine, const char *name) |
| 1429 | | { |
| 1430 | | avi_movie_info info; |
| 1431 | | mame_file *tempfile; |
| 1432 | | file_error filerr; |
| 1433 | | avi_error avierr; |
| 1434 | | |
| 1435 | | /* close any existing movie file */ |
| 1436 | | if (global.avifile != NULL) |
| 1437 | | video_avi_end_recording(machine); |
| 1438 | | |
| 1439 | | /* create a snapshot bitmap so we know what the target size is */ |
| 1192 | // create the bitmap |
| 1440 | 1193 | create_snapshot_bitmap(NULL); |
| 1441 | 1194 | |
| 1442 | | /* build up information about this new movie */ |
| 1443 | | info.video_format = 0; |
| 1444 | | info.video_timescale = 1000 * ((machine->primary_screen != NULL) ? ATTOSECONDS_TO_HZ(machine->primary_screen->frame_period().attoseconds) : screen_device::k_default_frame_rate); |
| 1445 | | info.video_sampletime = 1000; |
| 1446 | | info.video_numsamples = 0; |
| 1447 | | info.video_width = global.snap_bitmap->width; |
| 1448 | | info.video_height = global.snap_bitmap->height; |
| 1449 | | info.video_depth = 24; |
| 1450 | | |
| 1451 | | info.audio_format = 0; |
| 1452 | | info.audio_timescale = machine->sample_rate; |
| 1453 | | info.audio_sampletime = 1; |
| 1454 | | info.audio_numsamples = 0; |
| 1455 | | info.audio_channels = 2; |
| 1456 | | info.audio_samplebits = 16; |
| 1457 | | info.audio_samplerate = machine->sample_rate; |
| 1458 | | |
| 1459 | | /* create a new temporary movie file */ |
| 1460 | | if (name != NULL) |
| 1461 | | filerr = mame_fopen(SEARCHPATH_MOVIE, name, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &tempfile); |
| 1462 | | else |
| 1463 | | filerr = mame_fopen_next(machine, SEARCHPATH_MOVIE, "avi", &tempfile); |
| 1464 | | |
| 1465 | | /* reset our tracking */ |
| 1466 | | global.movie_frame = 0; |
| 1467 | | global.movie_next_frame_time = timer_get_time(machine); |
| 1468 | | global.movie_frame_period = attotime_div(ATTOTIME_IN_SEC(1000), info.video_timescale); |
| 1469 | | |
| 1470 | | /* if we succeeded, make a copy of the name and create the real file over top */ |
| 1471 | | if (filerr == FILERR_NONE) |
| 1195 | // loop until we hit the right time |
| 1196 | while (attotime_compare(m_movie_next_frame_time, curtime) <= 0) |
| 1472 | 1197 | { |
| 1473 | | astring fullname(mame_file_full_name(tempfile)); |
| 1474 | | mame_fclose(tempfile); |
| 1475 | | |
| 1476 | | /* create the file and free the string */ |
| 1477 | | avierr = avi_create(fullname, &info, &global.avifile); |
| 1478 | | } |
| 1479 | | } |
| 1480 | | |
| 1481 | | |
| 1482 | | /*------------------------------------------------- |
| 1483 | | video_avi_end_recording - stop recording of |
| 1484 | | a avi movie |
| 1485 | | -------------------------------------------------*/ |
| 1486 | | |
| 1487 | | void video_avi_end_recording(running_machine *machine) |
| 1488 | | { |
| 1489 | | /* close the file if it exists */ |
| 1490 | | if (global.avifile != NULL) |
| 1491 | | { |
| 1492 | | avi_close(global.avifile); |
| 1493 | | global.avifile = NULL; |
| 1494 | | global.movie_frame = 0; |
| 1495 | | } |
| 1496 | | } |
| 1497 | | |
| 1498 | | |
| 1499 | | /*------------------------------------------------- |
| 1500 | | video_avi_record_frame - record a frame of a |
| 1501 | | movie |
| 1502 | | -------------------------------------------------*/ |
| 1503 | | |
| 1504 | | static void video_avi_record_frame(running_machine *machine) |
| 1505 | | { |
| 1506 | | /* only record if we have a file */ |
| 1507 | | if (global.avifile != NULL) |
| 1508 | | { |
| 1509 | | attotime curtime = timer_get_time(machine); |
| 1510 | | avi_error avierr; |
| 1511 | | |
| 1512 | | g_profiler.start(PROFILER_MOVIE_REC); |
| 1513 | | |
| 1514 | | /* create the bitmap */ |
| 1515 | | create_snapshot_bitmap(NULL); |
| 1516 | | |
| 1517 | | /* loop until we hit the right time */ |
| 1518 | | while (attotime_compare(global.movie_next_frame_time, curtime) <= 0) |
| 1198 | // handle an AVI recording |
| 1199 | if (m_avifile != NULL) |
| 1519 | 1200 | { |
| 1520 | | /* write the next frame */ |
| 1521 | | avierr = avi_append_video_frame_rgb32(global.avifile, global.snap_bitmap); |
| 1201 | // write the next frame |
| 1202 | avi_error avierr = avi_append_video_frame_rgb32(m_avifile, m_snap_bitmap); |
| 1522 | 1203 | if (avierr != AVIERR_NONE) |
| 1523 | 1204 | { |
| 1524 | | video_avi_end_recording(machine); |
| 1525 | | break; |
| 1205 | g_profiler.stop(); |
| 1206 | return end_recording(); |
| 1526 | 1207 | } |
| 1527 | | |
| 1528 | | /* advance time */ |
| 1529 | | global.movie_next_frame_time = attotime_add(global.movie_next_frame_time, global.movie_frame_period); |
| 1530 | | global.movie_frame++; |
| 1531 | 1208 | } |
| 1532 | 1209 | |
| 1533 | | g_profiler.stop(); |
| 1534 | | } |
| 1535 | | } |
| 1536 | | |
| 1537 | | |
| 1538 | | /*------------------------------------------------- |
| 1539 | | video_avi_add_sound - add sound to an AVI |
| 1540 | | recording |
| 1541 | | -------------------------------------------------*/ |
| 1542 | | |
| 1543 | | void video_avi_add_sound(running_machine *machine, const INT16 *sound, int numsamples) |
| 1544 | | { |
| 1545 | | /* only record if we have a file */ |
| 1546 | | if (global.avifile != NULL) |
| 1547 | | { |
| 1548 | | avi_error avierr; |
| 1549 | | |
| 1550 | | g_profiler.start(PROFILER_MOVIE_REC); |
| 1551 | | |
| 1552 | | /* write the next frame */ |
| 1553 | | avierr = avi_append_sound_samples(global.avifile, 0, sound + 0, numsamples, 1); |
| 1554 | | if (avierr == AVIERR_NONE) |
| 1555 | | avierr = avi_append_sound_samples(global.avifile, 1, sound + 1, numsamples, 1); |
| 1556 | | if (avierr != AVIERR_NONE) |
| 1557 | | video_avi_end_recording(machine); |
| 1558 | | |
| 1559 | | g_profiler.stop(); |
| 1560 | | } |
| 1561 | | } |
| 1562 | | |
| 1563 | | |
| 1564 | | |
| 1565 | | /*************************************************************************** |
| 1566 | | BURN-IN GENERATION |
| 1567 | | ***************************************************************************/ |
| 1568 | | |
| 1569 | | |
| 1570 | | /*************************************************************************** |
| 1571 | | CONFIGURATION HELPERS |
| 1572 | | ***************************************************************************/ |
| 1573 | | |
| 1574 | | /*------------------------------------------------- |
| 1575 | | video_get_view_for_target - select a view |
| 1576 | | for a given target |
| 1577 | | -------------------------------------------------*/ |
| 1578 | | |
| 1579 | | int video_get_view_for_target(running_machine *machine, render_target *target, const char *viewname, int targetindex, int numtargets) |
| 1580 | | { |
| 1581 | | int viewindex = -1; |
| 1582 | | |
| 1583 | | /* auto view just selects the nth view */ |
| 1584 | | if (strcmp(viewname, "auto") != 0) |
| 1585 | | { |
| 1586 | | /* scan for a matching view name */ |
| 1587 | | for (viewindex = 0; ; viewindex++) |
| 1210 | // handle a MNG recording |
| 1211 | if (m_mngfile != NULL) |
| 1588 | 1212 | { |
| 1589 | | const char *name = target->view_name(viewindex); |
| 1590 | | |
| 1591 | | /* stop scanning when we hit NULL */ |
| 1592 | | if (name == NULL) |
| 1213 | // set up the text fields in the movie info |
| 1214 | png_info pnginfo = { 0 }; |
| 1215 | if (m_movie_frame == 0) |
| 1593 | 1216 | { |
| 1594 | | viewindex = -1; |
| 1595 | | break; |
| 1217 | astring text1(APPNAME, " ", build_version); |
| 1218 | astring text2(m_machine.m_game.manufacturer, " ", m_machine.m_game.description); |
| 1219 | png_add_text(&pnginfo, "Software", text1); |
| 1220 | png_add_text(&pnginfo, "System", text2); |
| 1596 | 1221 | } |
| 1597 | | if (mame_strnicmp(name, viewname, strlen(viewname)) == 0) |
| 1598 | | break; |
| 1599 | | } |
| 1600 | | } |
| 1601 | 1222 | |
| 1602 | | /* if we don't have a match, default to the nth view */ |
| 1603 | | int scrcount = screen_count(*machine->config); |
| 1604 | | if (viewindex == -1 && scrcount > 0) |
| 1605 | | { |
| 1606 | | /* if we have enough targets to be one per screen, assign in order */ |
| 1607 | | if (numtargets >= scrcount) |
| 1608 | | { |
| 1609 | | int index = target->index() % scrcount; |
| 1610 | | screen_device *screen; |
| 1611 | | for (screen = screen_first(*machine); screen != NULL; screen = screen_next(screen)) |
| 1612 | | if (index-- == 0) |
| 1613 | | break; |
| 1614 | | |
| 1615 | | /* find the first view with this screen and this screen only */ |
| 1616 | | for (viewindex = 0; ; viewindex++) |
| 1223 | // write the next frame |
| 1224 | const rgb_t *palette = (m_machine.palette != NULL) ? palette_entry_list_adjusted(m_machine.palette) : NULL; |
| 1225 | png_error error = mng_capture_frame(mame_core_file(m_mngfile), &pnginfo, m_snap_bitmap, m_machine.total_colors(), palette); |
| 1226 | png_free(&pnginfo); |
| 1227 | if (error != PNGERR_NONE) |
| 1617 | 1228 | { |
| 1618 | | const render_screen_list &viewscreens = target->view_screens(viewindex); |
| 1619 | | if (viewscreens.count() == 1 && viewscreens.contains(*screen)) |
| 1620 | | break; |
| 1621 | | if (viewscreens.count() == 0) |
| 1622 | | { |
| 1623 | | viewindex = -1; |
| 1624 | | break; |
| 1625 | | } |
| 1229 | g_profiler.stop(); |
| 1230 | return end_recording(); |
| 1626 | 1231 | } |
| 1627 | 1232 | } |
| 1628 | 1233 | |
| 1629 | | /* otherwise, find the first view that has all the screens */ |
| 1630 | | if (viewindex == -1) |
| 1631 | | { |
| 1632 | | for (viewindex = 0; ; viewindex++) |
| 1633 | | { |
| 1634 | | const render_screen_list &viewscreens = target->view_screens(viewindex); |
| 1635 | | if (viewscreens.count() == 0) |
| 1636 | | break; |
| 1637 | | if (viewscreens.count() >= scrcount) |
| 1638 | | { |
| 1639 | | screen_device *screen; |
| 1640 | | for (screen = screen_first(*machine); screen != NULL; screen = screen_next(screen)) |
| 1641 | | if (!viewscreens.contains(*screen)) |
| 1642 | | break; |
| 1643 | | if (screen == NULL) |
| 1644 | | break; |
| 1645 | | } |
| 1646 | | } |
| 1647 | | } |
| 1234 | // advance time |
| 1235 | m_movie_next_frame_time = attotime_add(m_movie_next_frame_time, m_movie_frame_period); |
| 1236 | m_movie_frame++; |
| 1648 | 1237 | } |
| 1649 | | |
| 1650 | | /* make sure it's a valid view */ |
| 1651 | | if (target->view_name(viewindex) == NULL) |
| 1652 | | viewindex = 0; |
| 1653 | | |
| 1654 | | return viewindex; |
| 1238 | g_profiler.stop(); |
| 1655 | 1239 | } |
| 1656 | 1240 | |
| 1657 | 1241 | |
| 1658 | 1242 | |
| 1659 | | /*************************************************************************** |
| 1660 | | DEBUGGING HELPERS |
| 1661 | | ***************************************************************************/ |
| 1662 | | |
| 1663 | 1243 | /*------------------------------------------------- |
| 1664 | 1244 | video_assert_out_of_range_pixels - assert if |
| 1665 | 1245 | any pixels in the given bitmap contain an |
| r9718 | r9719 | |
| 1672 | 1252 | int maxindex = palette_get_max_index(machine->palette); |
| 1673 | 1253 | int x, y; |
| 1674 | 1254 | |
| 1675 | | /* this only applies to indexed16 bitmaps */ |
| 1255 | // this only applies to indexed16 bitmaps |
| 1676 | 1256 | if (bitmap->format != BITMAP_FORMAT_INDEXED16) |
| 1677 | 1257 | return; |
| 1678 | 1258 | |
| 1679 | | /* iterate over rows */ |
| 1259 | // iterate over rows |
| 1680 | 1260 | for (y = 0; y < bitmap->height; y++) |
| 1681 | 1261 | { |
| 1682 | 1262 | UINT16 *rowbase = BITMAP_ADDR16(bitmap, y, 0); |
| r9718 | r9719 | |
| 1689 | 1269 | |
| 1690 | 1270 | |
| 1691 | 1271 | //************************************************************************** |
| 1692 | | // VIDEO SCREEN DEVICE CONFIGURATION |
| 1693 | | //************************************************************************** |
| 1694 | | |
| 1695 | | const attotime screen_device::k_default_frame_period = STATIC_ATTOTIME_IN_HZ(k_default_frame_rate); |
| 1696 | | |
| 1697 | | |
| 1698 | | //------------------------------------------------- |
| 1699 | | // screen_device_config - constructor |
| 1700 | | //------------------------------------------------- |
| 1701 | | |
| 1702 | | screen_device_config::screen_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 1703 | | : device_config(mconfig, static_alloc_device_config, "Video Screen", tag, owner, clock), |
| 1704 | | m_type(SCREEN_TYPE_RASTER), |
| 1705 | | m_width(0), |
| 1706 | | m_height(0), |
| 1707 | | m_oldstyle_vblank_supplied(false), |
| 1708 | | m_refresh(0), |
| 1709 | | m_vblank(0), |
| 1710 | | m_format(BITMAP_FORMAT_INVALID), |
| 1711 | | m_xoffset(0.0f), |
| 1712 | | m_yoffset(0.0f), |
| 1713 | | m_xscale(1.0f), |
| 1714 | | m_yscale(1.0f) |
| 1715 | | { |
| 1716 | | } |
| 1717 | | |
| 1718 | | |
| 1719 | | //------------------------------------------------- |
| 1720 | | // static_alloc_device_config - allocate a new |
| 1721 | | // configuration object |
| 1722 | | //------------------------------------------------- |
| 1723 | | |
| 1724 | | device_config *screen_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 1725 | | { |
| 1726 | | return global_alloc(screen_device_config(mconfig, tag, owner, clock)); |
| 1727 | | } |
| 1728 | | |
| 1729 | | |
| 1730 | | //------------------------------------------------- |
| 1731 | | // alloc_device - allocate a new device object |
| 1732 | | //------------------------------------------------- |
| 1733 | | |
| 1734 | | device_t *screen_device_config::alloc_device(running_machine &machine) const |
| 1735 | | { |
| 1736 | | return auto_alloc(&machine, screen_device(machine, *this)); |
| 1737 | | } |
| 1738 | | |
| 1739 | | |
| 1740 | | //------------------------------------------------- |
| 1741 | | // static_set_format - configuration helper |
| 1742 | | // to set the bitmap format |
| 1743 | | //------------------------------------------------- |
| 1744 | | |
| 1745 | | void screen_device_config::static_set_format(device_config *device, bitmap_format format) |
| 1746 | | { |
| 1747 | | screen_device_config *screen = downcast<screen_device_config *>(device); |
| 1748 | | screen->m_format = format; |
| 1749 | | } |
| 1750 | | |
| 1751 | | |
| 1752 | | //------------------------------------------------- |
| 1753 | | // static_set_type - configuration helper |
| 1754 | | // to set the screen type |
| 1755 | | //------------------------------------------------- |
| 1756 | | |
| 1757 | | void screen_device_config::static_set_type(device_config *device, screen_type_enum type) |
| 1758 | | { |
| 1759 | | screen_device_config *screen = downcast<screen_device_config *>(device); |
| 1760 | | screen->m_type = type; |
| 1761 | | } |
| 1762 | | |
| 1763 | | |
| 1764 | | //------------------------------------------------- |
| 1765 | | // static_set_raw - configuration helper |
| 1766 | | // to set the raw screen parameters |
| 1767 | | //------------------------------------------------- |
| 1768 | | |
| 1769 | | void screen_device_config::static_set_raw(device_config *device, UINT32 pixclock, UINT16 htotal, UINT16 hbend, UINT16 hbstart, UINT16 vtotal, UINT16 vbend, UINT16 vbstart) |
| 1770 | | { |
| 1771 | | screen_device_config *screen = downcast<screen_device_config *>(device); |
| 1772 | | screen->m_refresh = HZ_TO_ATTOSECONDS(pixclock) * htotal * vtotal; |
| 1773 | | screen->m_vblank = screen->m_refresh / vtotal * (vtotal - (vbstart - vbend)); |
| 1774 | | screen->m_width = htotal; |
| 1775 | | screen->m_height = vtotal; |
| 1776 | | screen->m_visarea.min_x = hbend; |
| 1777 | | screen->m_visarea.max_x = hbstart - 1; |
| 1778 | | screen->m_visarea.min_y = vbend; |
| 1779 | | screen->m_visarea.max_y = vbstart - 1; |
| 1780 | | } |
| 1781 | | |
| 1782 | | |
| 1783 | | //------------------------------------------------- |
| 1784 | | // static_set_refresh - configuration helper |
| 1785 | | // to set the refresh rate |
| 1786 | | //------------------------------------------------- |
| 1787 | | |
| 1788 | | void screen_device_config::static_set_refresh(device_config *device, attoseconds_t rate) |
| 1789 | | { |
| 1790 | | screen_device_config *screen = downcast<screen_device_config *>(device); |
| 1791 | | screen->m_refresh = rate; |
| 1792 | | } |
| 1793 | | |
| 1794 | | |
| 1795 | | //------------------------------------------------- |
| 1796 | | // static_set_vblank_time - configuration helper |
| 1797 | | // to set the VBLANK duration |
| 1798 | | //------------------------------------------------- |
| 1799 | | |
| 1800 | | void screen_device_config::static_set_vblank_time(device_config *device, attoseconds_t time) |
| 1801 | | { |
| 1802 | | screen_device_config *screen = downcast<screen_device_config *>(device); |
| 1803 | | screen->m_vblank = time; |
| 1804 | | screen->m_oldstyle_vblank_supplied = true; |
| 1805 | | } |
| 1806 | | |
| 1807 | | |
| 1808 | | //------------------------------------------------- |
| 1809 | | // static_set_size - configuration helper to set |
| 1810 | | // the width/height of the screen |
| 1811 | | //------------------------------------------------- |
| 1812 | | |
| 1813 | | void screen_device_config::static_set_size(device_config *device, UINT16 width, UINT16 height) |
| 1814 | | { |
| 1815 | | screen_device_config *screen = downcast<screen_device_config *>(device); |
| 1816 | | screen->m_width = width; |
| 1817 | | screen->m_height = height; |
| 1818 | | } |
| 1819 | | |
| 1820 | | |
| 1821 | | //------------------------------------------------- |
| 1822 | | // static_set_visarea - configuration helper to |
| 1823 | | // set the visible area of the screen |
| 1824 | | //------------------------------------------------- |
| 1825 | | |
| 1826 | | void screen_device_config::static_set_visarea(device_config *device, INT16 minx, INT16 maxx, INT16 miny, INT16 maxy) |
| 1827 | | { |
| 1828 | | screen_device_config *screen = downcast<screen_device_config *>(device); |
| 1829 | | screen->m_visarea.min_x = minx; |
| 1830 | | screen->m_visarea.max_x = maxx; |
| 1831 | | screen->m_visarea.min_y = miny; |
| 1832 | | screen->m_visarea.max_y = maxy; |
| 1833 | | } |
| 1834 | | |
| 1835 | | |
| 1836 | | //------------------------------------------------- |
| 1837 | | // static_set_default_position - configuration |
| 1838 | | // helper to set the default position and scale |
| 1839 | | // factors for the screen |
| 1840 | | //------------------------------------------------- |
| 1841 | | |
| 1842 | | void screen_device_config::static_set_default_position(device_config *device, double xscale, double xoffs, double yscale, double yoffs) |
| 1843 | | { |
| 1844 | | screen_device_config *screen = downcast<screen_device_config *>(device); |
| 1845 | | screen->m_xscale = xscale; |
| 1846 | | screen->m_xoffset = xoffs; |
| 1847 | | screen->m_yscale = yscale; |
| 1848 | | screen->m_yoffset = yoffs; |
| 1849 | | } |
| 1850 | | |
| 1851 | | |
| 1852 | | //------------------------------------------------- |
| 1853 | | // device_validity_check - verify device |
| 1854 | | // configuration |
| 1855 | | //------------------------------------------------- |
| 1856 | | |
| 1857 | | bool screen_device_config::device_validity_check(const game_driver &driver) const |
| 1858 | | { |
| 1859 | | bool error = false; |
| 1860 | | |
| 1861 | | // sanity check dimensions |
| 1862 | | if (m_width <= 0 || m_height <= 0) |
| 1863 | | { |
| 1864 | | mame_printf_error("%s: %s screen '%s' has invalid display dimensions\n", driver.source_file, driver.name, tag()); |
| 1865 | | error = true; |
| 1866 | | } |
| 1867 | | |
| 1868 | | // sanity check display area |
| 1869 | | if (m_type != SCREEN_TYPE_VECTOR) |
| 1870 | | { |
| 1871 | | if ((m_visarea.max_x < m_visarea.min_x) || |
| 1872 | | (m_visarea.max_y < m_visarea.min_y) || |
| 1873 | | (m_visarea.max_x >= m_width) || |
| 1874 | | (m_visarea.max_y >= m_height)) |
| 1875 | | { |
| 1876 | | mame_printf_error("%s: %s screen '%s' has an invalid display area\n", driver.source_file, driver.name, tag()); |
| 1877 | | error = true; |
| 1878 | | } |
| 1879 | | |
| 1880 | | // sanity check screen formats |
| 1881 | | if (m_format != BITMAP_FORMAT_INDEXED16 && |
| 1882 | | m_format != BITMAP_FORMAT_RGB15 && |
| 1883 | | m_format != BITMAP_FORMAT_RGB32) |
| 1884 | | { |
| 1885 | | mame_printf_error("%s: %s screen '%s' has unsupported format\n", driver.source_file, driver.name, tag()); |
| 1886 | | error = true; |
| 1887 | | } |
| 1888 | | } |
| 1889 | | |
| 1890 | | // check for zero frame rate |
| 1891 | | if (m_refresh == 0) |
| 1892 | | { |
| 1893 | | mame_printf_error("%s: %s screen '%s' has a zero refresh rate\n", driver.source_file, driver.name, tag()); |
| 1894 | | error = true; |
| 1895 | | } |
| 1896 | | return error; |
| 1897 | | } |
| 1898 | | |
| 1899 | | |
| 1900 | | |
| 1901 | | //************************************************************************** |
| 1902 | | // LIVE VIDEO SCREEN DEVICE |
| 1903 | | //************************************************************************** |
| 1904 | | |
| 1905 | | //------------------------------------------------- |
| 1906 | | // screen_device - constructor |
| 1907 | | //------------------------------------------------- |
| 1908 | | |
| 1909 | | screen_device::screen_device(running_machine &_machine, const screen_device_config &config) |
| 1910 | | : device_t(_machine, config), |
| 1911 | | m_config(config), |
| 1912 | | m_container(NULL), |
| 1913 | | m_width(m_config.m_width), |
| 1914 | | m_height(m_config.m_height), |
| 1915 | | m_visarea(m_config.m_visarea), |
| 1916 | | m_burnin(NULL), |
| 1917 | | m_curbitmap(0), |
| 1918 | | m_curtexture(0), |
| 1919 | | m_texture_format(0), |
| 1920 | | m_changed(true), |
| 1921 | | m_last_partial_scan(0), |
| 1922 | | m_screen_overlay_bitmap(NULL), |
| 1923 | | m_frame_period(m_config.m_refresh), |
| 1924 | | m_scantime(1), |
| 1925 | | m_pixeltime(1), |
| 1926 | | m_vblank_period(0), |
| 1927 | | m_vblank_start_time(attotime_zero), |
| 1928 | | m_vblank_end_time(attotime_zero), |
| 1929 | | m_vblank_begin_timer(NULL), |
| 1930 | | m_vblank_end_timer(NULL), |
| 1931 | | m_scanline0_timer(NULL), |
| 1932 | | m_scanline_timer(NULL), |
| 1933 | | m_frame_number(0), |
| 1934 | | m_callback_list(NULL) |
| 1935 | | { |
| 1936 | | memset(m_texture, 0, sizeof(m_texture)); |
| 1937 | | memset(m_bitmap, 0, sizeof(m_bitmap)); |
| 1938 | | } |
| 1939 | | |
| 1940 | | |
| 1941 | | //------------------------------------------------- |
| 1942 | | // ~screen_device - destructor |
| 1943 | | //------------------------------------------------- |
| 1944 | | |
| 1945 | | screen_device::~screen_device() |
| 1946 | | { |
| 1947 | | m_machine.render().texture_free(m_texture[0]); |
| 1948 | | m_machine.render().texture_free(m_texture[1]); |
| 1949 | | if (m_burnin != NULL) |
| 1950 | | finalize_burnin(); |
| 1951 | | global_free(m_screen_overlay_bitmap); |
| 1952 | | } |
| 1953 | | |
| 1954 | | |
| 1955 | | //------------------------------------------------- |
| 1956 | | // device_start - device-specific startup |
| 1957 | | //------------------------------------------------- |
| 1958 | | |
| 1959 | | void screen_device::device_start() |
| 1960 | | { |
| 1961 | | // configure the default cliparea |
| 1962 | | render_container::user_settings settings; |
| 1963 | | m_container->get_user_settings(settings); |
| 1964 | | settings.m_xoffset = m_config.m_xoffset; |
| 1965 | | settings.m_yoffset = m_config.m_yoffset; |
| 1966 | | settings.m_xscale = m_config.m_xscale; |
| 1967 | | settings.m_yscale = m_config.m_yscale; |
| 1968 | | m_container->set_user_settings(settings); |
| 1969 | | |
| 1970 | | // allocate the VBLANK timers |
| 1971 | | m_vblank_begin_timer = timer_alloc(machine, static_vblank_begin_callback, (void *)this); |
| 1972 | | m_vblank_end_timer = timer_alloc(machine, static_vblank_end_callback, (void *)this); |
| 1973 | | |
| 1974 | | // allocate a timer to reset partial updates |
| 1975 | | m_scanline0_timer = timer_alloc(machine, static_scanline0_callback, (void *)this); |
| 1976 | | |
| 1977 | | // allocate a timer to generate per-scanline updates |
| 1978 | | if ((machine->config->m_video_attributes & VIDEO_UPDATE_SCANLINE) != 0) |
| 1979 | | m_scanline_timer = timer_alloc(machine, static_scanline_update_callback, (void *)this); |
| 1980 | | |
| 1981 | | // configure the screen with the default parameters |
| 1982 | | configure(m_config.m_width, m_config.m_height, m_config.m_visarea, m_config.m_refresh); |
| 1983 | | |
| 1984 | | // reset VBLANK timing */ |
| 1985 | | m_vblank_start_time = attotime_zero; |
| 1986 | | m_vblank_end_time = attotime_make(0, m_vblank_period); |
| 1987 | | |
| 1988 | | // start the timer to generate per-scanline updates |
| 1989 | | if ((machine->config->m_video_attributes & VIDEO_UPDATE_SCANLINE) != 0) |
| 1990 | | timer_adjust_oneshot(m_scanline_timer, time_until_pos(0), 0); |
| 1991 | | |
| 1992 | | // create burn-in bitmap |
| 1993 | | if (options_get_int(machine->options(), OPTION_BURNIN) > 0) |
| 1994 | | { |
| 1995 | | int width, height; |
| 1996 | | if (sscanf(options_get_string(machine->options(), OPTION_SNAPSIZE), "%dx%d", &width, &height) != 2 || width == 0 || height == 0) |
| 1997 | | width = height = 300; |
| 1998 | | m_burnin = auto_alloc(machine, bitmap_t(width, height, BITMAP_FORMAT_INDEXED64)); |
| 1999 | | if (m_burnin == NULL) |
| 2000 | | fatalerror("Error allocating burn-in bitmap for screen at (%dx%d)\n", width, height); |
| 2001 | | bitmap_fill(m_burnin, NULL, 0); |
| 2002 | | } |
| 2003 | | |
| 2004 | | // load the effect overlay |
| 2005 | | const char *overname = options_get_string(machine->options(), OPTION_EFFECT); |
| 2006 | | if (overname != NULL && strcmp(overname, "none") != 0) |
| 2007 | | load_effect_overlay(overname); |
| 2008 | | |
| 2009 | | state_save_register_device_item(this, 0, m_width); |
| 2010 | | state_save_register_device_item(this, 0, m_height); |
| 2011 | | state_save_register_device_item(this, 0, m_visarea.min_x); |
| 2012 | | state_save_register_device_item(this, 0, m_visarea.min_y); |
| 2013 | | state_save_register_device_item(this, 0, m_visarea.max_x); |
| 2014 | | state_save_register_device_item(this, 0, m_visarea.max_y); |
| 2015 | | state_save_register_device_item(this, 0, m_last_partial_scan); |
| 2016 | | state_save_register_device_item(this, 0, m_frame_period); |
| 2017 | | state_save_register_device_item(this, 0, m_scantime); |
| 2018 | | state_save_register_device_item(this, 0, m_pixeltime); |
| 2019 | | state_save_register_device_item(this, 0, m_vblank_period); |
| 2020 | | state_save_register_device_item(this, 0, m_vblank_start_time.seconds); |
| 2021 | | state_save_register_device_item(this, 0, m_vblank_start_time.attoseconds); |
| 2022 | | state_save_register_device_item(this, 0, m_vblank_end_time.seconds); |
| 2023 | | state_save_register_device_item(this, 0, m_vblank_end_time.attoseconds); |
| 2024 | | state_save_register_device_item(this, 0, m_frame_number); |
| 2025 | | } |
| 2026 | | |
| 2027 | | |
| 2028 | | //------------------------------------------------- |
| 2029 | | // device_post_load - device-specific update |
| 2030 | | // after a save state is loaded |
| 2031 | | //------------------------------------------------- |
| 2032 | | |
| 2033 | | void screen_device::device_post_load() |
| 2034 | | { |
| 2035 | | realloc_screen_bitmaps(); |
| 2036 | | global.movie_next_frame_time = timer_get_time(machine); |
| 2037 | | } |
| 2038 | | |
| 2039 | | |
| 2040 | | //------------------------------------------------- |
| 2041 | | // configure - configure screen parameters |
| 2042 | | //------------------------------------------------- |
| 2043 | | |
| 2044 | | void screen_device::configure(int width, int height, const rectangle &visarea, attoseconds_t frame_period) |
| 2045 | | { |
| 2046 | | // validate arguments |
| 2047 | | assert(width > 0); |
| 2048 | | assert(height > 0); |
| 2049 | | assert(visarea.min_x >= 0); |
| 2050 | | assert(visarea.min_y >= 0); |
| 2051 | | assert(m_config.m_type == SCREEN_TYPE_VECTOR || visarea.min_x < width); |
| 2052 | | assert(m_config.m_type == SCREEN_TYPE_VECTOR || visarea.min_y < height); |
| 2053 | | assert(frame_period > 0); |
| 2054 | | |
| 2055 | | // fill in the new parameters |
| 2056 | | m_width = width; |
| 2057 | | m_height = height; |
| 2058 | | m_visarea = visarea; |
| 2059 | | |
| 2060 | | // reallocate bitmap if necessary |
| 2061 | | realloc_screen_bitmaps(); |
| 2062 | | |
| 2063 | | // compute timing parameters |
| 2064 | | m_frame_period = frame_period; |
| 2065 | | m_scantime = frame_period / height; |
| 2066 | | m_pixeltime = frame_period / (height * width); |
| 2067 | | |
| 2068 | | // if there has been no VBLANK time specified in the MACHINE_DRIVER, compute it now |
| 2069 | | // from the visible area, otherwise just used the supplied value |
| 2070 | | if (m_config.m_vblank == 0 && !m_config.m_oldstyle_vblank_supplied) |
| 2071 | | m_vblank_period = m_scantime * (height - (visarea.max_y + 1 - visarea.min_y)); |
| 2072 | | else |
| 2073 | | m_vblank_period = m_config.m_vblank; |
| 2074 | | |
| 2075 | | // if we are on scanline 0 already, reset the update timer immediately |
| 2076 | | // otherwise, defer until the next scanline 0 |
| 2077 | | if (vpos() == 0) |
| 2078 | | timer_adjust_oneshot(m_scanline0_timer, attotime_zero, 0); |
| 2079 | | else |
| 2080 | | timer_adjust_oneshot(m_scanline0_timer, time_until_pos(0), 0); |
| 2081 | | |
| 2082 | | // start the VBLANK timer |
| 2083 | | timer_adjust_oneshot(m_vblank_begin_timer, time_until_vblank_start(), 0); |
| 2084 | | |
| 2085 | | // adjust speed if necessary |
| 2086 | | update_refresh_speed(machine); |
| 2087 | | } |
| 2088 | | |
| 2089 | | |
| 2090 | | //------------------------------------------------- |
| 2091 | | // reset_origin - reset the timing such that the |
| 2092 | | // given (x,y) occurs at the current time |
| 2093 | | //------------------------------------------------- |
| 2094 | | |
| 2095 | | void screen_device::reset_origin(int beamy, int beamx) |
| 2096 | | { |
| 2097 | | // compute the effective VBLANK start/end times |
| 2098 | | attotime curtime = timer_get_time(machine); |
| 2099 | | m_vblank_end_time = attotime_sub_attoseconds(curtime, beamy * m_scantime + beamx * m_pixeltime); |
| 2100 | | m_vblank_start_time = attotime_sub_attoseconds(m_vblank_end_time, m_vblank_period); |
| 2101 | | |
| 2102 | | // if we are resetting relative to (0,0) == VBLANK end, call the |
| 2103 | | // scanline 0 timer by hand now; otherwise, adjust it for the future |
| 2104 | | if (beamy == 0 && beamx == 0) |
| 2105 | | scanline0_callback(); |
| 2106 | | else |
| 2107 | | timer_adjust_oneshot(m_scanline0_timer, time_until_pos(0), 0); |
| 2108 | | |
| 2109 | | // if we are resetting relative to (visarea.max_y + 1, 0) == VBLANK start, |
| 2110 | | // call the VBLANK start timer now; otherwise, adjust it for the future |
| 2111 | | if (beamy == m_visarea.max_y + 1 && beamx == 0) |
| 2112 | | vblank_begin_callback(); |
| 2113 | | else |
| 2114 | | timer_adjust_oneshot(m_vblank_begin_timer, time_until_vblank_start(), 0); |
| 2115 | | } |
| 2116 | | |
| 2117 | | |
| 2118 | | //------------------------------------------------- |
| 2119 | | // realloc_screen_bitmaps - reallocate bitmaps |
| 2120 | | // and textures as necessary |
| 2121 | | //------------------------------------------------- |
| 2122 | | |
| 2123 | | void screen_device::realloc_screen_bitmaps() |
| 2124 | | { |
| 2125 | | if (m_config.m_type == SCREEN_TYPE_VECTOR) |
| 2126 | | return; |
| 2127 | | |
| 2128 | | int curwidth = 0, curheight = 0; |
| 2129 | | |
| 2130 | | // extract the current width/height from the bitmap |
| 2131 | | if (m_bitmap[0] != NULL) |
| 2132 | | { |
| 2133 | | curwidth = m_bitmap[0]->width; |
| 2134 | | curheight = m_bitmap[0]->height; |
| 2135 | | } |
| 2136 | | |
| 2137 | | // if we're too small to contain this width/height, reallocate our bitmaps and textures |
| 2138 | | if (m_width > curwidth || m_height > curheight) |
| 2139 | | { |
| 2140 | | // free what we have currently |
| 2141 | | m_machine.render().texture_free(m_texture[0]); |
| 2142 | | m_machine.render().texture_free(m_texture[1]); |
| 2143 | | auto_free(machine, m_bitmap[0]); |
| 2144 | | auto_free(machine, m_bitmap[1]); |
| 2145 | | |
| 2146 | | // compute new width/height |
| 2147 | | curwidth = MAX(m_width, curwidth); |
| 2148 | | curheight = MAX(m_height, curheight); |
| 2149 | | |
| 2150 | | // choose the texture format - convert the screen format to a texture format |
| 2151 | | palette_t *palette = NULL; |
| 2152 | | switch (m_config.m_format) |
| 2153 | | { |
| 2154 | | case BITMAP_FORMAT_INDEXED16: m_texture_format = TEXFORMAT_PALETTE16; palette = machine->palette; break; |
| 2155 | | case BITMAP_FORMAT_RGB15: m_texture_format = TEXFORMAT_RGB15; palette = NULL; break; |
| 2156 | | case BITMAP_FORMAT_RGB32: m_texture_format = TEXFORMAT_RGB32; palette = NULL; break; |
| 2157 | | default: fatalerror("Invalid bitmap format!"); break; |
| 2158 | | } |
| 2159 | | |
| 2160 | | // allocate bitmaps |
| 2161 | | m_bitmap[0] = auto_alloc(machine, bitmap_t(curwidth, curheight, m_config.m_format)); |
| 2162 | | bitmap_set_palette(m_bitmap[0], machine->palette); |
| 2163 | | m_bitmap[1] = auto_alloc(machine, bitmap_t(curwidth, curheight, m_config.m_format)); |
| 2164 | | bitmap_set_palette(m_bitmap[1], machine->palette); |
| 2165 | | |
| 2166 | | // allocate textures |
| 2167 | | m_texture[0] = m_machine.render().texture_alloc(); |
| 2168 | | m_texture[0]->set_bitmap(m_bitmap[0], &m_visarea, m_texture_format, palette); |
| 2169 | | m_texture[1] = m_machine.render().texture_alloc(); |
| 2170 | | m_texture[1]->set_bitmap(m_bitmap[1], &m_visarea, m_texture_format, palette); |
| 2171 | | } |
| 2172 | | } |
| 2173 | | |
| 2174 | | |
| 2175 | | //------------------------------------------------- |
| 2176 | | // set_visible_area - just set the visible area |
| 2177 | | //------------------------------------------------- |
| 2178 | | |
| 2179 | | void screen_device::set_visible_area(int min_x, int max_x, int min_y, int max_y) |
| 2180 | | { |
| 2181 | | // validate arguments |
| 2182 | | assert(min_x >= 0); |
| 2183 | | assert(min_y >= 0); |
| 2184 | | assert(min_x < max_x); |
| 2185 | | assert(min_y < max_y); |
| 2186 | | |
| 2187 | | rectangle visarea; |
| 2188 | | visarea.min_x = min_x; |
| 2189 | | visarea.max_x = max_x; |
| 2190 | | visarea.min_y = min_y; |
| 2191 | | visarea.max_y = max_y; |
| 2192 | | |
| 2193 | | configure(m_width, m_height, visarea, m_frame_period); |
| 2194 | | } |
| 2195 | | |
| 2196 | | |
| 2197 | | //------------------------------------------------- |
| 2198 | | // update_partial - perform a partial update from |
| 2199 | | // the last scanline up to and including the |
| 2200 | | // specified scanline |
| 2201 | | //-----------------------------------------------*/ |
| 2202 | | |
| 2203 | | bool screen_device::update_partial(int scanline) |
| 2204 | | { |
| 2205 | | // validate arguments |
| 2206 | | assert(scanline >= 0); |
| 2207 | | |
| 2208 | | LOG_PARTIAL_UPDATES(("Partial: update_partial(%s, %d): ", tag(), scanline)); |
| 2209 | | |
| 2210 | | // these two checks only apply if we're allowed to skip frames |
| 2211 | | if (!(machine->config->m_video_attributes & VIDEO_ALWAYS_UPDATE)) |
| 2212 | | { |
| 2213 | | // if skipping this frame, bail |
| 2214 | | if (global.skipping_this_frame) |
| 2215 | | { |
| 2216 | | LOG_PARTIAL_UPDATES(("skipped due to frameskipping\n")); |
| 2217 | | return FALSE; |
| 2218 | | } |
| 2219 | | |
| 2220 | | // skip if this screen is not visible anywhere |
| 2221 | | if (!m_machine.render().is_live(*this)) |
| 2222 | | { |
| 2223 | | LOG_PARTIAL_UPDATES(("skipped because screen not live\n")); |
| 2224 | | return FALSE; |
| 2225 | | } |
| 2226 | | } |
| 2227 | | |
| 2228 | | // skip if less than the lowest so far |
| 2229 | | if (scanline < m_last_partial_scan) |
| 2230 | | { |
| 2231 | | LOG_PARTIAL_UPDATES(("skipped because less than previous\n")); |
| 2232 | | return FALSE; |
| 2233 | | } |
| 2234 | | |
| 2235 | | // set the start/end scanlines |
| 2236 | | rectangle clip = m_visarea; |
| 2237 | | if (m_last_partial_scan > clip.min_y) |
| 2238 | | clip.min_y = m_last_partial_scan; |
| 2239 | | if (scanline < clip.max_y) |
| 2240 | | clip.max_y = scanline; |
| 2241 | | |
| 2242 | | // render if necessary |
| 2243 | | bool result = false; |
| 2244 | | if (clip.min_y <= clip.max_y) |
| 2245 | | { |
| 2246 | | UINT32 flags = UPDATE_HAS_NOT_CHANGED; |
| 2247 | | |
| 2248 | | g_profiler.start(PROFILER_VIDEO); |
| 2249 | | LOG_PARTIAL_UPDATES(("updating %d-%d\n", clip.min_y, clip.max_y)); |
| 2250 | | |
| 2251 | | flags = machine->driver_data<driver_device>()->video_update(*this, *m_bitmap[m_curbitmap], clip); |
| 2252 | | global.partial_updates_this_frame++; |
| 2253 | | g_profiler.stop(); |
| 2254 | | |
| 2255 | | // if we modified the bitmap, we have to commit |
| 2256 | | m_changed |= ~flags & UPDATE_HAS_NOT_CHANGED; |
| 2257 | | result = true; |
| 2258 | | } |
| 2259 | | |
| 2260 | | // remember where we left off |
| 2261 | | m_last_partial_scan = scanline + 1; |
| 2262 | | return result; |
| 2263 | | } |
| 2264 | | |
| 2265 | | |
| 2266 | | //------------------------------------------------- |
| 2267 | | // update_now - perform an update from the last |
| 2268 | | // beam position up to the current beam position |
| 2269 | | //------------------------------------------------- |
| 2270 | | |
| 2271 | | void screen_device::update_now() |
| 2272 | | { |
| 2273 | | int current_vpos = vpos(); |
| 2274 | | int current_hpos = hpos(); |
| 2275 | | |
| 2276 | | // since we can currently update only at the scanline |
| 2277 | | // level, we are trying to do the right thing by |
| 2278 | | // updating including the current scanline, only if the |
| 2279 | | // beam is past the halfway point horizontally. |
| 2280 | | // If the beam is in the first half of the scanline, |
| 2281 | | // we only update up to the previous scanline. |
| 2282 | | // This minimizes the number of pixels that might be drawn |
| 2283 | | // incorrectly until we support a pixel level granularity |
| 2284 | | if (current_hpos < (m_width / 2) && current_vpos > 0) |
| 2285 | | current_vpos = current_vpos - 1; |
| 2286 | | |
| 2287 | | update_partial(current_vpos); |
| 2288 | | } |
| 2289 | | |
| 2290 | | |
| 2291 | | //------------------------------------------------- |
| 2292 | | // vpos - returns the current vertical position |
| 2293 | | // of the beam |
| 2294 | | //------------------------------------------------- |
| 2295 | | |
| 2296 | | int screen_device::vpos() const |
| 2297 | | { |
| 2298 | | attoseconds_t delta = attotime_to_attoseconds(attotime_sub(timer_get_time(machine), m_vblank_start_time)); |
| 2299 | | int vpos; |
| 2300 | | |
| 2301 | | // round to the nearest pixel |
| 2302 | | delta += m_pixeltime / 2; |
| 2303 | | |
| 2304 | | // compute the v position relative to the start of VBLANK |
| 2305 | | vpos = delta / m_scantime; |
| 2306 | | |
| 2307 | | // adjust for the fact that VBLANK starts at the bottom of the visible area |
| 2308 | | return (m_visarea.max_y + 1 + vpos) % m_height; |
| 2309 | | } |
| 2310 | | |
| 2311 | | |
| 2312 | | //------------------------------------------------- |
| 2313 | | // hpos - returns the current horizontal position |
| 2314 | | // of the beam |
| 2315 | | //------------------------------------------------- |
| 2316 | | |
| 2317 | | int screen_device::hpos() const |
| 2318 | | { |
| 2319 | | attoseconds_t delta = attotime_to_attoseconds(attotime_sub(timer_get_time(machine), m_vblank_start_time)); |
| 2320 | | |
| 2321 | | // round to the nearest pixel |
| 2322 | | delta += m_pixeltime / 2; |
| 2323 | | |
| 2324 | | // compute the v position relative to the start of VBLANK |
| 2325 | | int vpos = delta / m_scantime; |
| 2326 | | |
| 2327 | | // subtract that from the total time |
| 2328 | | delta -= vpos * m_scantime; |
| 2329 | | |
| 2330 | | // return the pixel offset from the start of this scanline |
| 2331 | | return delta / m_pixeltime; |
| 2332 | | } |
| 2333 | | |
| 2334 | | |
| 2335 | | //------------------------------------------------- |
| 2336 | | // time_until_pos - returns the amount of time |
| 2337 | | // remaining until the beam is at the given |
| 2338 | | // hpos,vpos |
| 2339 | | //------------------------------------------------- |
| 2340 | | |
| 2341 | | attotime screen_device::time_until_pos(int vpos, int hpos) const |
| 2342 | | { |
| 2343 | | // validate arguments |
| 2344 | | assert(vpos >= 0); |
| 2345 | | assert(hpos >= 0); |
| 2346 | | |
| 2347 | | // since we measure time relative to VBLANK, compute the scanline offset from VBLANK |
| 2348 | | vpos += m_height - (m_visarea.max_y + 1); |
| 2349 | | vpos %= m_height; |
| 2350 | | |
| 2351 | | // compute the delta for the given X,Y position |
| 2352 | | attoseconds_t targetdelta = (attoseconds_t)vpos * m_scantime + (attoseconds_t)hpos * m_pixeltime; |
| 2353 | | |
| 2354 | | // if we're past that time (within 1/2 of a pixel), head to the next frame |
| 2355 | | attoseconds_t curdelta = attotime_to_attoseconds(attotime_sub(timer_get_time(machine), m_vblank_start_time)); |
| 2356 | | if (targetdelta <= curdelta + m_pixeltime / 2) |
| 2357 | | targetdelta += m_frame_period; |
| 2358 | | while (targetdelta <= curdelta) |
| 2359 | | targetdelta += m_frame_period; |
| 2360 | | |
| 2361 | | // return the difference |
| 2362 | | return attotime_make(0, targetdelta - curdelta); |
| 2363 | | } |
| 2364 | | |
| 2365 | | |
| 2366 | | //------------------------------------------------- |
| 2367 | | // time_until_vblank_end - returns the amount of |
| 2368 | | // time remaining until the end of the current |
| 2369 | | // VBLANK (if in progress) or the end of the next |
| 2370 | | // VBLANK |
| 2371 | | //------------------------------------------------- |
| 2372 | | |
| 2373 | | attotime screen_device::time_until_vblank_end() const |
| 2374 | | { |
| 2375 | | // if we are in the VBLANK region, compute the time until the end of the current VBLANK period |
| 2376 | | attotime target_time = m_vblank_end_time; |
| 2377 | | if (!vblank()) |
| 2378 | | target_time = attotime_add_attoseconds(target_time, m_frame_period); |
| 2379 | | return attotime_sub(target_time, timer_get_time(machine)); |
| 2380 | | } |
| 2381 | | |
| 2382 | | |
| 2383 | | //------------------------------------------------- |
| 2384 | | // register_vblank_callback - registers a VBLANK |
| 2385 | | // callback |
| 2386 | | //------------------------------------------------- |
| 2387 | | |
| 2388 | | void screen_device::register_vblank_callback(vblank_state_changed_func vblank_callback, void *param) |
| 2389 | | { |
| 2390 | | // validate arguments |
| 2391 | | assert(vblank_callback != NULL); |
| 2392 | | |
| 2393 | | // check if we already have this callback registered |
| 2394 | | callback_item **itemptr; |
| 2395 | | for (itemptr = &m_callback_list; *itemptr != NULL; itemptr = &(*itemptr)->m_next) |
| 2396 | | if ((*itemptr)->m_callback == vblank_callback) |
| 2397 | | break; |
| 2398 | | |
| 2399 | | // if not found, register |
| 2400 | | if (*itemptr == NULL) |
| 2401 | | { |
| 2402 | | *itemptr = auto_alloc(machine, callback_item); |
| 2403 | | (*itemptr)->m_next = NULL; |
| 2404 | | (*itemptr)->m_callback = vblank_callback; |
| 2405 | | (*itemptr)->m_param = param; |
| 2406 | | } |
| 2407 | | } |
| 2408 | | |
| 2409 | | |
| 2410 | | //------------------------------------------------- |
| 2411 | | // vblank_begin_callback - call any external |
| 2412 | | // callbacks to signal the VBLANK period has begun |
| 2413 | | //------------------------------------------------- |
| 2414 | | |
| 2415 | | void screen_device::vblank_begin_callback() |
| 2416 | | { |
| 2417 | | // reset the starting VBLANK time |
| 2418 | | m_vblank_start_time = timer_get_time(machine); |
| 2419 | | m_vblank_end_time = attotime_add_attoseconds(m_vblank_start_time, m_vblank_period); |
| 2420 | | |
| 2421 | | // call the screen specific callbacks |
| 2422 | | for (callback_item *item = m_callback_list; item != NULL; item = item->m_next) |
| 2423 | | (*item->m_callback)(*this, item->m_param, true); |
| 2424 | | |
| 2425 | | // if this is the primary screen and we need to update now |
| 2426 | | if (this == machine->primary_screen && !(machine->config->m_video_attributes & VIDEO_UPDATE_AFTER_VBLANK)) |
| 2427 | | video_frame_update(machine, FALSE); |
| 2428 | | |
| 2429 | | // reset the VBLANK start timer for the next frame |
| 2430 | | timer_adjust_oneshot(m_vblank_begin_timer, time_until_vblank_start(), 0); |
| 2431 | | |
| 2432 | | // if no VBLANK period, call the VBLANK end callback immedietely, otherwise reset the timer |
| 2433 | | if (m_vblank_period == 0) |
| 2434 | | vblank_end_callback(); |
| 2435 | | else |
| 2436 | | timer_adjust_oneshot(m_vblank_end_timer, time_until_vblank_end(), 0); |
| 2437 | | } |
| 2438 | | |
| 2439 | | |
| 2440 | | //------------------------------------------------- |
| 2441 | | // vblank_end_callback - call any external |
| 2442 | | // callbacks to signal the VBLANK period has ended |
| 2443 | | //------------------------------------------------- |
| 2444 | | |
| 2445 | | void screen_device::vblank_end_callback() |
| 2446 | | { |
| 2447 | | // call the screen specific callbacks |
| 2448 | | for (callback_item *item = m_callback_list; item != NULL; item = item->m_next) |
| 2449 | | (*item->m_callback)(*this, item->m_param, false); |
| 2450 | | |
| 2451 | | // if this is the primary screen and we need to update now |
| 2452 | | if (this == machine->primary_screen && (machine->config->m_video_attributes & VIDEO_UPDATE_AFTER_VBLANK)) |
| 2453 | | video_frame_update(machine, FALSE); |
| 2454 | | |
| 2455 | | // increment the frame number counter |
| 2456 | | m_frame_number++; |
| 2457 | | } |
| 2458 | | |
| 2459 | | |
| 2460 | | //------------------------------------------------- |
| 2461 | | // scanline0_callback - reset partial updates |
| 2462 | | // for a screen |
| 2463 | | //------------------------------------------------- |
| 2464 | | |
| 2465 | | void screen_device::scanline0_callback() |
| 2466 | | { |
| 2467 | | // reset partial updates |
| 2468 | | m_last_partial_scan = 0; |
| 2469 | | global.partial_updates_this_frame = 0; |
| 2470 | | |
| 2471 | | timer_adjust_oneshot(m_scanline0_timer, time_until_pos(0), 0); |
| 2472 | | } |
| 2473 | | |
| 2474 | | |
| 2475 | | //------------------------------------------------- |
| 2476 | | // scanline_update_callback - perform partial |
| 2477 | | // updates on each scanline |
| 2478 | | //------------------------------------------------- |
| 2479 | | |
| 2480 | | void screen_device::scanline_update_callback(int scanline) |
| 2481 | | { |
| 2482 | | // force a partial update to the current scanline |
| 2483 | | update_partial(scanline); |
| 2484 | | |
| 2485 | | // compute the next visible scanline |
| 2486 | | scanline++; |
| 2487 | | if (scanline > m_visarea.max_y) |
| 2488 | | scanline = m_visarea.min_y; |
| 2489 | | timer_adjust_oneshot(m_scanline_timer, time_until_pos(scanline), scanline); |
| 2490 | | } |
| 2491 | | |
| 2492 | | |
| 2493 | | //------------------------------------------------- |
| 2494 | | // update_quads - set up the quads for this |
| 2495 | | // screen |
| 2496 | | //------------------------------------------------- |
| 2497 | | |
| 2498 | | bool screen_device::update_quads() |
| 2499 | | { |
| 2500 | | // only update if live |
| 2501 | | if (m_machine.render().is_live(*this)) |
| 2502 | | { |
| 2503 | | // only update if empty and not a vector game; otherwise assume the driver did it directly |
| 2504 | | if (m_config.m_type != SCREEN_TYPE_VECTOR && (machine->config->m_video_attributes & VIDEO_SELF_RENDER) == 0) |
| 2505 | | { |
| 2506 | | // if we're not skipping the frame and if the screen actually changed, then update the texture |
| 2507 | | if (!global.skipping_this_frame && m_changed) |
| 2508 | | { |
| 2509 | | rectangle fixedvis = m_visarea; |
| 2510 | | fixedvis.max_x++; |
| 2511 | | fixedvis.max_y++; |
| 2512 | | |
| 2513 | | palette_t *palette = (m_texture_format == TEXFORMAT_PALETTE16) ? machine->palette : NULL; |
| 2514 | | m_texture[m_curbitmap]->set_bitmap(m_bitmap[m_curbitmap], &fixedvis, m_texture_format, palette); |
| 2515 | | |
| 2516 | | m_curtexture = m_curbitmap; |
| 2517 | | m_curbitmap = 1 - m_curbitmap; |
| 2518 | | } |
| 2519 | | |
| 2520 | | // create an empty container with a single quad |
| 2521 | | m_container->empty(); |
| 2522 | | m_container->add_quad(0.0f, 0.0f, 1.0f, 1.0f, MAKE_ARGB(0xff,0xff,0xff,0xff), m_texture[m_curtexture], PRIMFLAG_BLENDMODE(BLENDMODE_NONE) | PRIMFLAG_SCREENTEX(1)); |
| 2523 | | } |
| 2524 | | } |
| 2525 | | |
| 2526 | | // reset the screen changed flags |
| 2527 | | bool result = m_changed; |
| 2528 | | m_changed = false; |
| 2529 | | return result; |
| 2530 | | } |
| 2531 | | |
| 2532 | | |
| 2533 | | //------------------------------------------------- |
| 2534 | | // update_burnin - update the burnin bitmap |
| 2535 | | //------------------------------------------------- |
| 2536 | | |
| 2537 | | void screen_device::update_burnin() |
| 2538 | | { |
| 2539 | | #undef rand |
| 2540 | | if (m_burnin == NULL) |
| 2541 | | return; |
| 2542 | | |
| 2543 | | bitmap_t *srcbitmap = m_bitmap[m_curtexture]; |
| 2544 | | if (srcbitmap == NULL) |
| 2545 | | return; |
| 2546 | | |
| 2547 | | int srcwidth = srcbitmap->width; |
| 2548 | | int srcheight = srcbitmap->height; |
| 2549 | | int dstwidth = m_burnin->width; |
| 2550 | | int dstheight = m_burnin->height; |
| 2551 | | int xstep = (srcwidth << 16) / dstwidth; |
| 2552 | | int ystep = (srcheight << 16) / dstheight; |
| 2553 | | int xstart = ((UINT32)rand() % 32767) * xstep / 32767; |
| 2554 | | int ystart = ((UINT32)rand() % 32767) * ystep / 32767; |
| 2555 | | int srcx, srcy; |
| 2556 | | int x, y; |
| 2557 | | |
| 2558 | | // iterate over rows in the destination |
| 2559 | | for (y = 0, srcy = ystart; y < dstheight; y++, srcy += ystep) |
| 2560 | | { |
| 2561 | | UINT64 *dst = BITMAP_ADDR64(m_burnin, y, 0); |
| 2562 | | |
| 2563 | | // handle the 16-bit palettized case |
| 2564 | | if (srcbitmap->format == BITMAP_FORMAT_INDEXED16) |
| 2565 | | { |
| 2566 | | const UINT16 *src = BITMAP_ADDR16(srcbitmap, srcy >> 16, 0); |
| 2567 | | const rgb_t *palette = palette_entry_list_adjusted(machine->palette); |
| 2568 | | for (x = 0, srcx = xstart; x < dstwidth; x++, srcx += xstep) |
| 2569 | | { |
| 2570 | | rgb_t pixel = palette[src[srcx >> 16]]; |
| 2571 | | dst[x] += RGB_GREEN(pixel) + RGB_RED(pixel) + RGB_BLUE(pixel); |
| 2572 | | } |
| 2573 | | } |
| 2574 | | |
| 2575 | | // handle the 15-bit RGB case |
| 2576 | | else if (srcbitmap->format == BITMAP_FORMAT_RGB15) |
| 2577 | | { |
| 2578 | | const UINT16 *src = BITMAP_ADDR16(srcbitmap, srcy >> 16, 0); |
| 2579 | | for (x = 0, srcx = xstart; x < dstwidth; x++, srcx += xstep) |
| 2580 | | { |
| 2581 | | rgb15_t pixel = src[srcx >> 16]; |
| 2582 | | dst[x] += ((pixel >> 10) & 0x1f) + ((pixel >> 5) & 0x1f) + ((pixel >> 0) & 0x1f); |
| 2583 | | } |
| 2584 | | } |
| 2585 | | |
| 2586 | | // handle the 32-bit RGB case |
| 2587 | | else if (srcbitmap->format == BITMAP_FORMAT_RGB32) |
| 2588 | | { |
| 2589 | | const UINT32 *src = BITMAP_ADDR32(srcbitmap, srcy >> 16, 0); |
| 2590 | | for (x = 0, srcx = xstart; x < dstwidth; x++, srcx += xstep) |
| 2591 | | { |
| 2592 | | rgb_t pixel = src[srcx >> 16]; |
| 2593 | | dst[x] += RGB_GREEN(pixel) + RGB_RED(pixel) + RGB_BLUE(pixel); |
| 2594 | | } |
| 2595 | | } |
| 2596 | | } |
| 2597 | | } |
| 2598 | | |
| 2599 | | |
| 2600 | | //------------------------------------------------- |
| 2601 | | // finalize_burnin - finalize the burnin bitmap |
| 2602 | | //------------------------------------------------- |
| 2603 | | |
| 2604 | | void screen_device::finalize_burnin() |
| 2605 | | { |
| 2606 | | if (m_burnin == NULL) |
| 2607 | | return; |
| 2608 | | |
| 2609 | | // compute the scaled visible region |
| 2610 | | rectangle scaledvis; |
| 2611 | | scaledvis.min_x = m_visarea.min_x * m_burnin->width / m_width; |
| 2612 | | scaledvis.max_x = m_visarea.max_x * m_burnin->width / m_width; |
| 2613 | | scaledvis.min_y = m_visarea.min_y * m_burnin->height / m_height; |
| 2614 | | scaledvis.max_y = m_visarea.max_y * m_burnin->height / m_height; |
| 2615 | | |
| 2616 | | // wrap a bitmap around the subregion we care about |
| 2617 | | bitmap_t *finalmap = auto_alloc(machine, bitmap_t(scaledvis.max_x + 1 - scaledvis.min_x, |
| 2618 | | scaledvis.max_y + 1 - scaledvis.min_y, |
| 2619 | | BITMAP_FORMAT_ARGB32)); |
| 2620 | | |
| 2621 | | int srcwidth = m_burnin->width; |
| 2622 | | int srcheight = m_burnin->height; |
| 2623 | | int dstwidth = finalmap->width; |
| 2624 | | int dstheight = finalmap->height; |
| 2625 | | int xstep = (srcwidth << 16) / dstwidth; |
| 2626 | | int ystep = (srcheight << 16) / dstheight; |
| 2627 | | |
| 2628 | | // find the maximum value |
| 2629 | | UINT64 minval = ~(UINT64)0; |
| 2630 | | UINT64 maxval = 0; |
| 2631 | | for (int y = 0; y < srcheight; y++) |
| 2632 | | { |
| 2633 | | UINT64 *src = BITMAP_ADDR64(m_burnin, y, 0); |
| 2634 | | for (int x = 0; x < srcwidth; x++) |
| 2635 | | { |
| 2636 | | minval = MIN(minval, src[x]); |
| 2637 | | maxval = MAX(maxval, src[x]); |
| 2638 | | } |
| 2639 | | } |
| 2640 | | |
| 2641 | | if (minval == maxval) |
| 2642 | | return; |
| 2643 | | |
| 2644 | | // now normalize and convert to RGB |
| 2645 | | for (int y = 0, srcy = 0; y < dstheight; y++, srcy += ystep) |
| 2646 | | { |
| 2647 | | UINT64 *src = BITMAP_ADDR64(m_burnin, srcy >> 16, 0); |
| 2648 | | UINT32 *dst = BITMAP_ADDR32(finalmap, y, 0); |
| 2649 | | for (int x = 0, srcx = 0; x < dstwidth; x++, srcx += xstep) |
| 2650 | | { |
| 2651 | | int brightness = (UINT64)(maxval - src[srcx >> 16]) * 255 / (maxval - minval); |
| 2652 | | dst[x] = MAKE_ARGB(0xff, brightness, brightness, brightness); |
| 2653 | | } |
| 2654 | | } |
| 2655 | | |
| 2656 | | // write the final PNG |
| 2657 | | |
| 2658 | | // compute the name and create the file |
| 2659 | | astring fname; |
| 2660 | | fname.printf("%s" PATH_SEPARATOR "burnin-%s.png", machine->basename(), tag()); |
| 2661 | | mame_file *file; |
| 2662 | | file_error filerr = mame_fopen(SEARCHPATH_SCREENSHOT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file); |
| 2663 | | if (filerr == FILERR_NONE) |
| 2664 | | { |
| 2665 | | png_info pnginfo = { 0 }; |
| 2666 | | png_error pngerr; |
| 2667 | | char text[256]; |
| 2668 | | |
| 2669 | | // add two text entries describing the image |
| 2670 | | sprintf(text, APPNAME " %s", build_version); |
| 2671 | | png_add_text(&pnginfo, "Software", text); |
| 2672 | | sprintf(text, "%s %s", machine->gamedrv->manufacturer, machine->gamedrv->description); |
| 2673 | | png_add_text(&pnginfo, "System", text); |
| 2674 | | |
| 2675 | | // now do the actual work |
| 2676 | | pngerr = png_write_bitmap(mame_core_file(file), &pnginfo, finalmap, 0, NULL); |
| 2677 | | |
| 2678 | | // free any data allocated |
| 2679 | | png_free(&pnginfo); |
| 2680 | | mame_fclose(file); |
| 2681 | | } |
| 2682 | | } |
| 2683 | | |
| 2684 | | |
| 2685 | | //------------------------------------------------- |
| 2686 | | // finalize_burnin - finalize the burnin bitmap |
| 2687 | | //------------------------------------------------- |
| 2688 | | |
| 2689 | | void screen_device::load_effect_overlay(const char *filename) |
| 2690 | | { |
| 2691 | | // ensure that there is a .png extension |
| 2692 | | astring fullname(filename); |
| 2693 | | int extension = fullname.rchr(0, '.'); |
| 2694 | | if (extension != -1) |
| 2695 | | fullname.del(extension, -1); |
| 2696 | | fullname.cat(".png"); |
| 2697 | | |
| 2698 | | // load the file |
| 2699 | | m_screen_overlay_bitmap = render_load_png(OPTION_ARTPATH, NULL, fullname, NULL, NULL); |
| 2700 | | if (m_screen_overlay_bitmap != NULL) |
| 2701 | | m_container->set_overlay(m_screen_overlay_bitmap); |
| 2702 | | else |
| 2703 | | mame_printf_warning("Unable to load effect PNG file '%s'\n", fullname.cstr()); |
| 2704 | | } |
| 2705 | | |
| 2706 | | |
| 2707 | | |
| 2708 | | //************************************************************************** |
| 2709 | 1272 | // SOFTWARE RENDERING |
| 2710 | 1273 | //************************************************************************** |
| 2711 | 1274 | |
src/emu/screen.c
| r0 | r9719 | |
| 1 | /***************************************************************************
|
| 2 | |
| 3 | screen.c
|
| 4 | |
| 5 | Core MAME screen device.
|
| 6 | |
| 7 | ****************************************************************************
|
| 8 | |
| 9 | Copyright Aaron Giles
|
| 10 | All rights reserved.
|
| 11 | |
| 12 | Redistribution and use in source and binary forms, with or without
|
| 13 | modification, are permitted provided that the following conditions are
|
| 14 | met:
|
| 15 | |
| 16 | * Redistributions of source code must retain the above copyright
|
| 17 | notice, this list of conditions and the following disclaimer.
|
| 18 | * Redistributions in binary form must reproduce the above copyright
|
| 19 | notice, this list of conditions and the following disclaimer in
|
| 20 | the documentation and/or other materials provided with the
|
| 21 | distribution.
|
| 22 | * Neither the name 'MAME' nor the names of its contributors may be
|
| 23 | used to endorse or promote products derived from this software
|
| 24 | without specific prior written permission.
|
| 25 | |
| 26 | THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
|
| 27 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 28 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 29 | DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
|
| 30 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 31 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 32 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 33 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
| 34 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
| 35 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 36 | POSSIBILITY OF SUCH DAMAGE.
|
| 37 | |
| 38 | ***************************************************************************/
|
| 39 | |
| 40 | #include "emu.h"
|
| 41 | #include "emuopts.h"
|
| 42 | #include "png.h"
|
| 43 | #include "rendutil.h"
|
| 44 | |
| 45 | |
| 46 | |
| 47 | //**************************************************************************
|
| 48 | // DEBUGGING
|
| 49 | //**************************************************************************
|
| 50 | |
| 51 | #define VERBOSE (0)
|
| 52 | #define LOG_PARTIAL_UPDATES(x) do { if (VERBOSE) logerror x; } while (0)
|
| 53 | |
| 54 | |
| 55 | |
| 56 | //**************************************************************************
|
| 57 | // GLOBAL VARIABLES
|
| 58 | //**************************************************************************
|
| 59 | |
| 60 | const device_type SCREEN = screen_device_config::static_alloc_device_config;
|
| 61 | |
| 62 | const attotime screen_device::DEFAULT_FRAME_PERIOD = STATIC_ATTOTIME_IN_HZ(DEFAULT_FRAME_RATE);
|
| 63 | |
| 64 | |
| 65 | |
| 66 | //**************************************************************************
|
| 67 | // SCREEN DEVICE CONFIGURATION
|
| 68 | //**************************************************************************
|
| 69 | |
| 70 | //-------------------------------------------------
|
| 71 | // screen_device_config - constructor
|
| 72 | //-------------------------------------------------
|
| 73 | |
| 74 | screen_device_config::screen_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
|
| 75 | : device_config(mconfig, static_alloc_device_config, "Video Screen", tag, owner, clock),
|
| 76 | m_type(SCREEN_TYPE_RASTER),
|
| 77 | m_width(0),
|
| 78 | m_height(0),
|
| 79 | m_oldstyle_vblank_supplied(false),
|
| 80 | m_refresh(0),
|
| 81 | m_vblank(0),
|
| 82 | m_format(BITMAP_FORMAT_INVALID),
|
| 83 | m_xoffset(0.0f),
|
| 84 | m_yoffset(0.0f),
|
| 85 | m_xscale(1.0f),
|
| 86 | m_yscale(1.0f)
|
| 87 | {
|
| 88 | }
|
| 89 | |
| 90 | |
| 91 | //-------------------------------------------------
|
| 92 | // static_alloc_device_config - allocate a new
|
| 93 | // configuration object
|
| 94 | //-------------------------------------------------
|
| 95 | |
| 96 | device_config *screen_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
|
| 97 | {
|
| 98 | return global_alloc(screen_device_config(mconfig, tag, owner, clock));
|
| 99 | }
|
| 100 | |
| 101 | |
| 102 | //-------------------------------------------------
|
| 103 | // alloc_device - allocate a new device object
|
| 104 | //-------------------------------------------------
|
| 105 | |
| 106 | device_t *screen_device_config::alloc_device(running_machine &machine) const
|
| 107 | {
|
| 108 | return auto_alloc(&machine, screen_device(machine, *this));
|
| 109 | }
|
| 110 | |
| 111 | |
| 112 | //-------------------------------------------------
|
| 113 | // static_set_format - configuration helper
|
| 114 | // to set the bitmap format
|
| 115 | //-------------------------------------------------
|
| 116 | |
| 117 | void screen_device_config::static_set_format(device_config *device, bitmap_format format)
|
| 118 | {
|
| 119 | screen_device_config *screen = downcast<screen_device_config *>(device);
|
| 120 | screen->m_format = format;
|
| 121 | }
|
| 122 | |
| 123 | |
| 124 | //-------------------------------------------------
|
| 125 | // static_set_type - configuration helper
|
| 126 | // to set the screen type
|
| 127 | //-------------------------------------------------
|
| 128 | |
| 129 | void screen_device_config::static_set_type(device_config *device, screen_type_enum type)
|
| 130 | {
|
| 131 | screen_device_config *screen = downcast<screen_device_config *>(device);
|
| 132 | screen->m_type = type;
|
| 133 | }
|
| 134 | |
| 135 | |
| 136 | //-------------------------------------------------
|
| 137 | // static_set_raw - configuration helper
|
| 138 | // to set the raw screen parameters
|
| 139 | //-------------------------------------------------
|
| 140 | |
| 141 | void screen_device_config::static_set_raw(device_config *device, UINT32 pixclock, UINT16 htotal, UINT16 hbend, UINT16 hbstart, UINT16 vtotal, UINT16 vbend, UINT16 vbstart)
|
| 142 | {
|
| 143 | screen_device_config *screen = downcast<screen_device_config *>(device);
|
| 144 | screen->m_refresh = HZ_TO_ATTOSECONDS(pixclock) * htotal * vtotal;
|
| 145 | screen->m_vblank = screen->m_refresh / vtotal * (vtotal - (vbstart - vbend));
|
| 146 | screen->m_width = htotal;
|
| 147 | screen->m_height = vtotal;
|
| 148 | screen->m_visarea.min_x = hbend;
|
| 149 | screen->m_visarea.max_x = hbstart - 1;
|
| 150 | screen->m_visarea.min_y = vbend;
|
| 151 | screen->m_visarea.max_y = vbstart - 1;
|
| 152 | }
|
| 153 | |
| 154 | |
| 155 | //-------------------------------------------------
|
| 156 | // static_set_refresh - configuration helper
|
| 157 | // to set the refresh rate
|
| 158 | //-------------------------------------------------
|
| 159 | |
| 160 | void screen_device_config::static_set_refresh(device_config *device, attoseconds_t rate)
|
| 161 | {
|
| 162 | screen_device_config *screen = downcast<screen_device_config *>(device);
|
| 163 | screen->m_refresh = rate;
|
| 164 | }
|
| 165 | |
| 166 | |
| 167 | //-------------------------------------------------
|
| 168 | // static_set_vblank_time - configuration helper
|
| 169 | // to set the VBLANK duration
|
| 170 | //-------------------------------------------------
|
| 171 | |
| 172 | void screen_device_config::static_set_vblank_time(device_config *device, attoseconds_t time)
|
| 173 | {
|
| 174 | screen_device_config *screen = downcast<screen_device_config *>(device);
|
| 175 | screen->m_vblank = time;
|
| 176 | screen->m_oldstyle_vblank_supplied = true;
|
| 177 | }
|
| 178 | |
| 179 | |
| 180 | //-------------------------------------------------
|
| 181 | // static_set_size - configuration helper to set
|
| 182 | // the width/height of the screen
|
| 183 | //-------------------------------------------------
|
| 184 | |
| 185 | void screen_device_config::static_set_size(device_config *device, UINT16 width, UINT16 height)
|
| 186 | {
|
| 187 | screen_device_config *screen = downcast<screen_device_config *>(device);
|
| 188 | screen->m_width = width;
|
| 189 | screen->m_height = height;
|
| 190 | }
|
| 191 | |
| 192 | |
| 193 | //-------------------------------------------------
|
| 194 | // static_set_visarea - configuration helper to
|
| 195 | // set the visible area of the screen
|
| 196 | //-------------------------------------------------
|
| 197 | |
| 198 | void screen_device_config::static_set_visarea(device_config *device, INT16 minx, INT16 maxx, INT16 miny, INT16 maxy)
|
| 199 | {
|
| 200 | screen_device_config *screen = downcast<screen_device_config *>(device);
|
| 201 | screen->m_visarea.min_x = minx;
|
| 202 | screen->m_visarea.max_x = maxx;
|
| 203 | screen->m_visarea.min_y = miny;
|
| 204 | screen->m_visarea.max_y = maxy;
|
| 205 | }
|
| 206 | |
| 207 | |
| 208 | //-------------------------------------------------
|
| 209 | // static_set_default_position - configuration
|
| 210 | // helper to set the default position and scale
|
| 211 | // factors for the screen
|
| 212 | //-------------------------------------------------
|
| 213 | |
| 214 | void screen_device_config::static_set_default_position(device_config *device, double xscale, double xoffs, double yscale, double yoffs)
|
| 215 | {
|
| 216 | screen_device_config *screen = downcast<screen_device_config *>(device);
|
| 217 | screen->m_xscale = xscale;
|
| 218 | screen->m_xoffset = xoffs;
|
| 219 | screen->m_yscale = yscale;
|
| 220 | screen->m_yoffset = yoffs;
|
| 221 | }
|
| 222 | |
| 223 | |
| 224 | //-------------------------------------------------
|
| 225 | // device_validity_check - verify device
|
| 226 | // configuration
|
| 227 | //-------------------------------------------------
|
| 228 | |
| 229 | bool screen_device_config::device_validity_check(const game_driver &driver) const
|
| 230 | {
|
| 231 | bool error = false;
|
| 232 | |
| 233 | // sanity check dimensions
|
| 234 | if (m_width <= 0 || m_height <= 0)
|
| 235 | {
|
| 236 | mame_printf_error("%s: %s screen '%s' has invalid display dimensions\n", driver.source_file, driver.name, tag());
|
| 237 | error = true;
|
| 238 | }
|
| 239 | |
| 240 | // sanity check display area
|
| 241 | if (m_type != SCREEN_TYPE_VECTOR)
|
| 242 | {
|
| 243 | if ((m_visarea.max_x < m_visarea.min_x) ||
|
| 244 | (m_visarea.max_y < m_visarea.min_y) ||
|
| 245 | (m_visarea.max_x >= m_width) ||
|
| 246 | (m_visarea.max_y >= m_height))
|
| 247 | {
|
| 248 | mame_printf_error("%s: %s screen '%s' has an invalid display area\n", driver.source_file, driver.name, tag());
|
| 249 | error = true;
|
| 250 | }
|
| 251 | |
| 252 | // sanity check screen formats
|
| 253 | if (m_format != BITMAP_FORMAT_INDEXED16 &&
|
| 254 | m_format != BITMAP_FORMAT_RGB15 &&
|
| 255 | m_format != BITMAP_FORMAT_RGB32)
|
| 256 | {
|
| 257 | mame_printf_error("%s: %s screen '%s' has unsupported format\n", driver.source_file, driver.name, tag());
|
| 258 | error = true;
|
| 259 | }
|
| 260 | }
|
| 261 | |
| 262 | // check for zero frame rate
|
| 263 | if (m_refresh == 0)
|
| 264 | {
|
| 265 | mame_printf_error("%s: %s screen '%s' has a zero refresh rate\n", driver.source_file, driver.name, tag());
|
| 266 | error = true;
|
| 267 | }
|
| 268 | return error;
|
| 269 | }
|
| 270 | |
| 271 | |
| 272 | |
| 273 | //**************************************************************************
|
| 274 | // SCREEN DEVICE
|
| 275 | //**************************************************************************
|
| 276 | |
| 277 | //-------------------------------------------------
|
| 278 | // screen_device - constructor
|
| 279 | //-------------------------------------------------
|
| 280 | |
| 281 | screen_device::screen_device(running_machine &_machine, const screen_device_config &config)
|
| 282 | : device_t(_machine, config),
|
| 283 | m_config(config),
|
| 284 | m_container(NULL),
|
| 285 | m_width(m_config.m_width),
|
| 286 | m_height(m_config.m_height),
|
| 287 | m_visarea(m_config.m_visarea),
|
| 288 | m_burnin(NULL),
|
| 289 | m_curbitmap(0),
|
| 290 | m_curtexture(0),
|
| 291 | m_texture_format(0),
|
| 292 | m_changed(true),
|
| 293 | m_last_partial_scan(0),
|
| 294 | m_screen_overlay_bitmap(NULL),
|
| 295 | m_frame_period(m_config.m_refresh),
|
| 296 | m_scantime(1),
|
| 297 | m_pixeltime(1),
|
| 298 | m_vblank_period(0),
|
| 299 | m_vblank_start_time(attotime_zero),
|
| 300 | m_vblank_end_time(attotime_zero),
|
| 301 | m_vblank_begin_timer(NULL),
|
| 302 | m_vblank_end_timer(NULL),
|
| 303 | m_scanline0_timer(NULL),
|
| 304 | m_scanline_timer(NULL),
|
| 305 | m_frame_number(0),
|
| 306 | m_partial_updates_this_frame(0),
|
| 307 | m_callback_list(NULL)
|
| 308 | {
|
| 309 | memset(m_texture, 0, sizeof(m_texture));
|
| 310 | memset(m_bitmap, 0, sizeof(m_bitmap));
|
| 311 | }
|
| 312 | |
| 313 | |
| 314 | //-------------------------------------------------
|
| 315 | // ~screen_device - destructor
|
| 316 | //-------------------------------------------------
|
| 317 | |
| 318 | screen_device::~screen_device()
|
| 319 | {
|
| 320 | m_machine.render().texture_free(m_texture[0]);
|
| 321 | m_machine.render().texture_free(m_texture[1]);
|
| 322 | if (m_burnin != NULL)
|
| 323 | finalize_burnin();
|
| 324 | global_free(m_screen_overlay_bitmap);
|
| 325 | }
|
| 326 | |
| 327 | |
| 328 | //-------------------------------------------------
|
| 329 | // device_start - device-specific startup
|
| 330 | //-------------------------------------------------
|
| 331 | |
| 332 | void screen_device::device_start()
|
| 333 | {
|
| 334 | // configure the default cliparea
|
| 335 | render_container::user_settings settings;
|
| 336 | m_container->get_user_settings(settings);
|
| 337 | settings.m_xoffset = m_config.m_xoffset;
|
| 338 | settings.m_yoffset = m_config.m_yoffset;
|
| 339 | settings.m_xscale = m_config.m_xscale;
|
| 340 | settings.m_yscale = m_config.m_yscale;
|
| 341 | m_container->set_user_settings(settings);
|
| 342 | |
| 343 | // allocate the VBLANK timers
|
| 344 | m_vblank_begin_timer = timer_alloc(machine, static_vblank_begin_callback, (void *)this);
|
| 345 | m_vblank_end_timer = timer_alloc(machine, static_vblank_end_callback, (void *)this);
|
| 346 | |
| 347 | // allocate a timer to reset partial updates
|
| 348 | m_scanline0_timer = timer_alloc(machine, static_scanline0_callback, (void *)this);
|
| 349 | |
| 350 | // allocate a timer to generate per-scanline updates
|
| 351 | if ((machine->config->m_video_attributes & VIDEO_UPDATE_SCANLINE) != 0)
|
| 352 | m_scanline_timer = timer_alloc(machine, static_scanline_update_callback, (void *)this);
|
| 353 | |
| 354 | // configure the screen with the default parameters
|
| 355 | configure(m_config.m_width, m_config.m_height, m_config.m_visarea, m_config.m_refresh);
|
| 356 | |
| 357 | // reset VBLANK timing
|
| 358 | m_vblank_start_time = attotime_zero;
|
| 359 | m_vblank_end_time = attotime_make(0, m_vblank_period);
|
| 360 | |
| 361 | // start the timer to generate per-scanline updates
|
| 362 | if ((machine->config->m_video_attributes & VIDEO_UPDATE_SCANLINE) != 0)
|
| 363 | timer_adjust_oneshot(m_scanline_timer, time_until_pos(0), 0);
|
| 364 | |
| 365 | // create burn-in bitmap
|
| 366 | if (options_get_int(machine->options(), OPTION_BURNIN) > 0)
|
| 367 | {
|
| 368 | int width, height;
|
| 369 | if (sscanf(options_get_string(machine->options(), OPTION_SNAPSIZE), "%dx%d", &width, &height) != 2 || width == 0 || height == 0)
|
| 370 | width = height = 300;
|
| 371 | m_burnin = auto_alloc(machine, bitmap_t(width, height, BITMAP_FORMAT_INDEXED64));
|
| 372 | if (m_burnin == NULL)
|
| 373 | fatalerror("Error allocating burn-in bitmap for screen at (%dx%d)\n", width, height);
|
| 374 | bitmap_fill(m_burnin, NULL, 0);
|
| 375 | }
|
| 376 | |
| 377 | // load the effect overlay
|
| 378 | const char *overname = options_get_string(machine->options(), OPTION_EFFECT);
|
| 379 | if (overname != NULL && strcmp(overname, "none") != 0)
|
| 380 | load_effect_overlay(overname);
|
| 381 | |
| 382 | state_save_register_device_item(this, 0, m_width);
|
| 383 | state_save_register_device_item(this, 0, m_height);
|
| 384 | state_save_register_device_item(this, 0, m_visarea.min_x);
|
| 385 | state_save_register_device_item(this, 0, m_visarea.min_y);
|
| 386 | state_save_register_device_item(this, 0, m_visarea.max_x);
|
| 387 | state_save_register_device_item(this, 0, m_visarea.max_y);
|
| 388 | state_save_register_device_item(this, 0, m_last_partial_scan);
|
| 389 | state_save_register_device_item(this, 0, m_frame_period);
|
| 390 | state_save_register_device_item(this, 0, m_scantime);
|
| 391 | state_save_register_device_item(this, 0, m_pixeltime);
|
| 392 | state_save_register_device_item(this, 0, m_vblank_period);
|
| 393 | state_save_register_device_item(this, 0, m_vblank_start_time.seconds);
|
| 394 | state_save_register_device_item(this, 0, m_vblank_start_time.attoseconds);
|
| 395 | state_save_register_device_item(this, 0, m_vblank_end_time.seconds);
|
| 396 | state_save_register_device_item(this, 0, m_vblank_end_time.attoseconds);
|
| 397 | state_save_register_device_item(this, 0, m_frame_number);
|
| 398 | }
|
| 399 | |
| 400 | |
| 401 | //-------------------------------------------------
|
| 402 | // device_post_load - device-specific update
|
| 403 | // after a save state is loaded
|
| 404 | //-------------------------------------------------
|
| 405 | |
| 406 | void screen_device::device_post_load()
|
| 407 | {
|
| 408 | realloc_screen_bitmaps();
|
| 409 | }
|
| 410 | |
| 411 | |
| 412 | //-------------------------------------------------
|
| 413 | // configure - configure screen parameters
|
| 414 | //-------------------------------------------------
|
| 415 | |
| 416 | void screen_device::configure(int width, int height, const rectangle &visarea, attoseconds_t frame_period)
|
| 417 | {
|
| 418 | // validate arguments
|
| 419 | assert(width > 0);
|
| 420 | assert(height > 0);
|
| 421 | assert(visarea.min_x >= 0);
|
| 422 | assert(visarea.min_y >= 0);
|
| 423 | assert(m_config.m_type == SCREEN_TYPE_VECTOR || visarea.min_x < width);
|
| 424 | assert(m_config.m_type == SCREEN_TYPE_VECTOR || visarea.min_y < height);
|
| 425 | assert(frame_period > 0);
|
| 426 | |
| 427 | // fill in the new parameters
|
| 428 | m_width = width;
|
| 429 | m_height = height;
|
| 430 | m_visarea = visarea;
|
| 431 | |
| 432 | // reallocate bitmap if necessary
|
| 433 | realloc_screen_bitmaps();
|
| 434 | |
| 435 | // compute timing parameters
|
| 436 | m_frame_period = frame_period;
|
| 437 | m_scantime = frame_period / height;
|
| 438 | m_pixeltime = frame_period / (height * width);
|
| 439 | |
| 440 | // if there has been no VBLANK time specified in the MACHINE_DRIVER, compute it now
|
| 441 | // from the visible area, otherwise just used the supplied value
|
| 442 | if (m_config.m_vblank == 0 && !m_config.m_oldstyle_vblank_supplied)
|
| 443 | m_vblank_period = m_scantime * (height - (visarea.max_y + 1 - visarea.min_y));
|
| 444 | else
|
| 445 | m_vblank_period = m_config.m_vblank;
|
| 446 | |
| 447 | // if we are on scanline 0 already, reset the update timer immediately
|
| 448 | // otherwise, defer until the next scanline 0
|
| 449 | if (vpos() == 0)
|
| 450 | timer_adjust_oneshot(m_scanline0_timer, attotime_zero, 0);
|
| 451 | else
|
| 452 | timer_adjust_oneshot(m_scanline0_timer, time_until_pos(0), 0);
|
| 453 | |
| 454 | // start the VBLANK timer
|
| 455 | timer_adjust_oneshot(m_vblank_begin_timer, time_until_vblank_start(), 0);
|
| 456 | |
| 457 | // adjust speed if necessary
|
| 458 | m_machine.video().update_refresh_speed();
|
| 459 | }
|
| 460 | |
| 461 | |
| 462 | //-------------------------------------------------
|
| 463 | // reset_origin - reset the timing such that the
|
| 464 | // given (x,y) occurs at the current time
|
| 465 | //-------------------------------------------------
|
| 466 | |
| 467 | void screen_device::reset_origin(int beamy, int beamx)
|
| 468 | {
|
| 469 | // compute the effective VBLANK start/end times
|
| 470 | attotime curtime = timer_get_time(machine);
|
| 471 | m_vblank_end_time = attotime_sub_attoseconds(curtime, beamy * m_scantime + beamx * m_pixeltime);
|
| 472 | m_vblank_start_time = attotime_sub_attoseconds(m_vblank_end_time, m_vblank_period);
|
| 473 | |
| 474 | // if we are resetting relative to (0,0) == VBLANK end, call the
|
| 475 | // scanline 0 timer by hand now; otherwise, adjust it for the future
|
| 476 | if (beamy == 0 && beamx == 0)
|
| 477 | scanline0_callback();
|
| 478 | else
|
| 479 | timer_adjust_oneshot(m_scanline0_timer, time_until_pos(0), 0);
|
| 480 | |
| 481 | // if we are resetting relative to (visarea.max_y + 1, 0) == VBLANK start,
|
| 482 | // call the VBLANK start timer now; otherwise, adjust it for the future
|
| 483 | if (beamy == m_visarea.max_y + 1 && beamx == 0)
|
| 484 | vblank_begin_callback();
|
| 485 | else
|
| 486 | timer_adjust_oneshot(m_vblank_begin_timer, time_until_vblank_start(), 0);
|
| 487 | }
|
| 488 | |
| 489 | |
| 490 | //-------------------------------------------------
|
| 491 | // realloc_screen_bitmaps - reallocate bitmaps
|
| 492 | // and textures as necessary
|
| 493 | //-------------------------------------------------
|
| 494 | |
| 495 | void screen_device::realloc_screen_bitmaps()
|
| 496 | {
|
| 497 | if (m_config.m_type == SCREEN_TYPE_VECTOR)
|
| 498 | return;
|
| 499 | |
| 500 | int curwidth = 0, curheight = 0;
|
| 501 | |
| 502 | // extract the current width/height from the bitmap
|
| 503 | if (m_bitmap[0] != NULL)
|
| 504 | {
|
| 505 | curwidth = m_bitmap[0]->width;
|
| 506 | curheight = m_bitmap[0]->height;
|
| 507 | }
|
| 508 | |
| 509 | // if we're too small to contain this width/height, reallocate our bitmaps and textures
|
| 510 | if (m_width > curwidth || m_height > curheight)
|
| 511 | {
|
| 512 | // free what we have currently
|
| 513 | m_machine.render().texture_free(m_texture[0]);
|
| 514 | m_machine.render().texture_free(m_texture[1]);
|
| 515 | auto_free(machine, m_bitmap[0]);
|
| 516 | auto_free(machine, m_bitmap[1]);
|
| 517 | |
| 518 | // compute new width/height
|
| 519 | curwidth = MAX(m_width, curwidth);
|
| 520 | curheight = MAX(m_height, curheight);
|
| 521 | |
| 522 | // choose the texture format - convert the screen format to a texture format
|
| 523 | palette_t *palette = NULL;
|
| 524 | switch (m_config.m_format)
|
| 525 | {
|
| 526 | case BITMAP_FORMAT_INDEXED16: m_texture_format = TEXFORMAT_PALETTE16; palette = machine->palette; break;
|
| 527 | case BITMAP_FORMAT_RGB15: m_texture_format = TEXFORMAT_RGB15; palette = NULL; break;
|
| 528 | case BITMAP_FORMAT_RGB32: m_texture_format = TEXFORMAT_RGB32; palette = NULL; break;
|
| 529 | default: fatalerror("Invalid bitmap format!"); break;
|
| 530 | }
|
| 531 | |
| 532 | // allocate bitmaps
|
| 533 | m_bitmap[0] = auto_alloc(machine, bitmap_t(curwidth, curheight, m_config.m_format));
|
| 534 | bitmap_set_palette(m_bitmap[0], machine->palette);
|
| 535 | m_bitmap[1] = auto_alloc(machine, bitmap_t(curwidth, curheight, m_config.m_format));
|
| 536 | bitmap_set_palette(m_bitmap[1], machine->palette);
|
| 537 | |
| 538 | // allocate textures
|
| 539 | m_texture[0] = m_machine.render().texture_alloc();
|
| 540 | m_texture[0]->set_bitmap(m_bitmap[0], &m_visarea, m_texture_format, palette);
|
| 541 | m_texture[1] = m_machine.render().texture_alloc();
|
| 542 | m_texture[1]->set_bitmap(m_bitmap[1], &m_visarea, m_texture_format, palette);
|
| 543 | }
|
| 544 | }
|
| 545 | |
| 546 | |
| 547 | //-------------------------------------------------
|
| 548 | // set_visible_area - just set the visible area
|
| 549 | //-------------------------------------------------
|
| 550 | |
| 551 | void screen_device::set_visible_area(int min_x, int max_x, int min_y, int max_y)
|
| 552 | {
|
| 553 | // validate arguments
|
| 554 | assert(min_x >= 0);
|
| 555 | assert(min_y >= 0);
|
| 556 | assert(min_x < max_x);
|
| 557 | assert(min_y < max_y);
|
| 558 | |
| 559 | rectangle visarea;
|
| 560 | visarea.min_x = min_x;
|
| 561 | visarea.max_x = max_x;
|
| 562 | visarea.min_y = min_y;
|
| 563 | visarea.max_y = max_y;
|
| 564 | |
| 565 | configure(m_width, m_height, visarea, m_frame_period);
|
| 566 | }
|
| 567 | |
| 568 | |
| 569 | //-------------------------------------------------
|
| 570 | // update_partial - perform a partial update from
|
| 571 | // the last scanline up to and including the
|
| 572 | // specified scanline
|
| 573 | //-----------------------------------------------*/
|
| 574 | |
| 575 | bool screen_device::update_partial(int scanline)
|
| 576 | {
|
| 577 | // validate arguments
|
| 578 | assert(scanline >= 0);
|
| 579 | |
| 580 | LOG_PARTIAL_UPDATES(("Partial: update_partial(%s, %d): ", tag(), scanline));
|
| 581 | |
| 582 | // these two checks only apply if we're allowed to skip frames
|
| 583 | if (!(machine->config->m_video_attributes & VIDEO_ALWAYS_UPDATE))
|
| 584 | {
|
| 585 | // if skipping this frame, bail
|
| 586 | if (m_machine.video().skip_this_frame())
|
| 587 | {
|
| 588 | LOG_PARTIAL_UPDATES(("skipped due to frameskipping\n"));
|
| 589 | return FALSE;
|
| 590 | }
|
| 591 | |
| 592 | // skip if this screen is not visible anywhere
|
| 593 | if (!m_machine.render().is_live(*this))
|
| 594 | {
|
| 595 | LOG_PARTIAL_UPDATES(("skipped because screen not live\n"));
|
| 596 | return FALSE;
|
| 597 | }
|
| 598 | }
|
| 599 | |
| 600 | // skip if less than the lowest so far
|
| 601 | if (scanline < m_last_partial_scan)
|
| 602 | {
|
| 603 | LOG_PARTIAL_UPDATES(("skipped because less than previous\n"));
|
| 604 | return FALSE;
|
| 605 | }
|
| 606 | |
| 607 | // set the start/end scanlines
|
| 608 | rectangle clip = m_visarea;
|
| 609 | if (m_last_partial_scan > clip.min_y)
|
| 610 | clip.min_y = m_last_partial_scan;
|
| 611 | if (scanline < clip.max_y)
|
| 612 | clip.max_y = scanline;
|
| 613 | |
| 614 | // render if necessary
|
| 615 | bool result = false;
|
| 616 | if (clip.min_y <= clip.max_y)
|
| 617 | {
|
| 618 | UINT32 flags = UPDATE_HAS_NOT_CHANGED;
|
| 619 | |
| 620 | g_profiler.start(PROFILER_VIDEO);
|
| 621 | LOG_PARTIAL_UPDATES(("updating %d-%d\n", clip.min_y, clip.max_y));
|
| 622 | |
| 623 | flags = machine->driver_data<driver_device>()->video_update(*this, *m_bitmap[m_curbitmap], clip);
|
| 624 | m_partial_updates_this_frame++;
|
| 625 | g_profiler.stop();
|
| 626 | |
| 627 | // if we modified the bitmap, we have to commit
|
| 628 | m_changed |= ~flags & UPDATE_HAS_NOT_CHANGED;
|
| 629 | result = true;
|
| 630 | }
|
| 631 | |
| 632 | // remember where we left off
|
| 633 | m_last_partial_scan = scanline + 1;
|
| 634 | return result;
|
| 635 | }
|
| 636 | |
| 637 | |
| 638 | //-------------------------------------------------
|
| 639 | // update_now - perform an update from the last
|
| 640 | // beam position up to the current beam position
|
| 641 | //-------------------------------------------------
|
| 642 | |
| 643 | void screen_device::update_now()
|
| 644 | {
|
| 645 | int current_vpos = vpos();
|
| 646 | int current_hpos = hpos();
|
| 647 | |
| 648 | // since we can currently update only at the scanline
|
| 649 | // level, we are trying to do the right thing by
|
| 650 | // updating including the current scanline, only if the
|
| 651 | // beam is past the halfway point horizontally.
|
| 652 | // If the beam is in the first half of the scanline,
|
| 653 | // we only update up to the previous scanline.
|
| 654 | // This minimizes the number of pixels that might be drawn
|
| 655 | // incorrectly until we support a pixel level granularity
|
| 656 | if (current_hpos < (m_width / 2) && current_vpos > 0)
|
| 657 | current_vpos = current_vpos - 1;
|
| 658 | |
| 659 | update_partial(current_vpos);
|
| 660 | }
|
| 661 | |
| 662 | |
| 663 | //-------------------------------------------------
|
| 664 | // vpos - returns the current vertical position
|
| 665 | // of the beam
|
| 666 | //-------------------------------------------------
|
| 667 | |
| 668 | int screen_device::vpos() const
|
| 669 | {
|
| 670 | attoseconds_t delta = attotime_to_attoseconds(attotime_sub(timer_get_time(machine), m_vblank_start_time));
|
| 671 | int vpos;
|
| 672 | |
| 673 | // round to the nearest pixel
|
| 674 | delta += m_pixeltime / 2;
|
| 675 | |
| 676 | // compute the v position relative to the start of VBLANK
|
| 677 | vpos = delta / m_scantime;
|
| 678 | |
| 679 | // adjust for the fact that VBLANK starts at the bottom of the visible area
|
| 680 | return (m_visarea.max_y + 1 + vpos) % m_height;
|
| 681 | }
|
| 682 | |
| 683 | |
| 684 | //-------------------------------------------------
|
| 685 | // hpos - returns the current horizontal position
|
| 686 | // of the beam
|
| 687 | //-------------------------------------------------
|
| 688 | |
| 689 | int screen_device::hpos() const
|
| 690 | {
|
| 691 | attoseconds_t delta = attotime_to_attoseconds(attotime_sub(timer_get_time(machine), m_vblank_start_time));
|
| 692 | |
| 693 | // round to the nearest pixel
|
| 694 | delta += m_pixeltime / 2;
|
| 695 | |
| 696 | // compute the v position relative to the start of VBLANK
|
| 697 | int vpos = delta / m_scantime;
|
| 698 | |
| 699 | // subtract that from the total time
|
| 700 | delta -= vpos * m_scantime;
|
| 701 | |
| 702 | // return the pixel offset from the start of this scanline
|
| 703 | return delta / m_pixeltime;
|
| 704 | }
|
| 705 | |
| 706 | |
| 707 | //-------------------------------------------------
|
| 708 | // time_until_pos - returns the amount of time
|
| 709 | // remaining until the beam is at the given
|
| 710 | // hpos,vpos
|
| 711 | //-------------------------------------------------
|
| 712 | |
| 713 | attotime screen_device::time_until_pos(int vpos, int hpos) const
|
| 714 | {
|
| 715 | // validate arguments
|
| 716 | assert(vpos >= 0);
|
| 717 | assert(hpos >= 0);
|
| 718 | |
| 719 | // since we measure time relative to VBLANK, compute the scanline offset from VBLANK
|
| 720 | vpos += m_height - (m_visarea.max_y + 1);
|
| 721 | vpos %= m_height;
|
| 722 | |
| 723 | // compute the delta for the given X,Y position
|
| 724 | attoseconds_t targetdelta = (attoseconds_t)vpos * m_scantime + (attoseconds_t)hpos * m_pixeltime;
|
| 725 | |
| 726 | // if we're past that time (within 1/2 of a pixel), head to the next frame
|
| 727 | attoseconds_t curdelta = attotime_to_attoseconds(attotime_sub(timer_get_time(machine), m_vblank_start_time));
|
| 728 | if (targetdelta <= curdelta + m_pixeltime / 2)
|
| 729 | targetdelta += m_frame_period;
|
| 730 | while (targetdelta <= curdelta)
|
| 731 | targetdelta += m_frame_period;
|
| 732 | |
| 733 | // return the difference
|
| 734 | return attotime_make(0, targetdelta - curdelta);
|
| 735 | }
|
| 736 | |
| 737 | |
| 738 | //-------------------------------------------------
|
| 739 | // time_until_vblank_end - returns the amount of
|
| 740 | // time remaining until the end of the current
|
| 741 | // VBLANK (if in progress) or the end of the next
|
| 742 | // VBLANK
|
| 743 | //-------------------------------------------------
|
| 744 | |
| 745 | attotime screen_device::time_until_vblank_end() const
|
| 746 | {
|
| 747 | // if we are in the VBLANK region, compute the time until the end of the current VBLANK period
|
| 748 | attotime target_time = m_vblank_end_time;
|
| 749 | if (!vblank())
|
| 750 | target_time = attotime_add_attoseconds(target_time, m_frame_period);
|
| 751 | return attotime_sub(target_time, timer_get_time(machine));
|
| 752 | }
|
| 753 | |
| 754 | |
| 755 | //-------------------------------------------------
|
| 756 | // register_vblank_callback - registers a VBLANK
|
| 757 | // callback
|
| 758 | //-------------------------------------------------
|
| 759 | |
| 760 | void screen_device::register_vblank_callback(vblank_state_changed_func vblank_callback, void *param)
|
| 761 | {
|
| 762 | // validate arguments
|
| 763 | assert(vblank_callback != NULL);
|
| 764 | |
| 765 | // check if we already have this callback registered
|
| 766 | callback_item **itemptr;
|
| 767 | for (itemptr = &m_callback_list; *itemptr != NULL; itemptr = &(*itemptr)->m_next)
|
| 768 | if ((*itemptr)->m_callback == vblank_callback)
|
| 769 | break;
|
| 770 | |
| 771 | // if not found, register
|
| 772 | if (*itemptr == NULL)
|
| 773 | {
|
| 774 | *itemptr = auto_alloc(machine, callback_item);
|
| 775 | (*itemptr)->m_next = NULL;
|
| 776 | (*itemptr)->m_callback = vblank_callback;
|
| 777 | (*itemptr)->m_param = param;
|
| 778 | }
|
| 779 | }
|
| 780 | |
| 781 | |
| 782 | //-------------------------------------------------
|
| 783 | // vblank_begin_callback - call any external
|
| 784 | // callbacks to signal the VBLANK period has begun
|
| 785 | //-------------------------------------------------
|
| 786 | |
| 787 | void screen_device::vblank_begin_callback()
|
| 788 | {
|
| 789 | // reset the starting VBLANK time
|
| 790 | m_vblank_start_time = timer_get_time(machine);
|
| 791 | m_vblank_end_time = attotime_add_attoseconds(m_vblank_start_time, m_vblank_period);
|
| 792 | |
| 793 | // call the screen specific callbacks
|
| 794 | for (callback_item *item = m_callback_list; item != NULL; item = item->m_next)
|
| 795 | (*item->m_callback)(*this, item->m_param, true);
|
| 796 | |
| 797 | // if this is the primary screen and we need to update now
|
| 798 | if (this == machine->primary_screen && !(machine->config->m_video_attributes & VIDEO_UPDATE_AFTER_VBLANK))
|
| 799 | machine->video().frame_update();
|
| 800 | |
| 801 | // reset the VBLANK start timer for the next frame
|
| 802 | timer_adjust_oneshot(m_vblank_begin_timer, time_until_vblank_start(), 0);
|
| 803 | |
| 804 | // if no VBLANK period, call the VBLANK end callback immedietely, otherwise reset the timer
|
| 805 | if (m_vblank_period == 0)
|
| 806 | vblank_end_callback();
|
| 807 | else
|
| 808 | timer_adjust_oneshot(m_vblank_end_timer, time_until_vblank_end(), 0);
|
| 809 | }
|
| 810 | |
| 811 | |
| 812 | //-------------------------------------------------
|
| 813 | // vblank_end_callback - call any external
|
| 814 | // callbacks to signal the VBLANK period has ended
|
| 815 | //-------------------------------------------------
|
| 816 | |
| 817 | void screen_device::vblank_end_callback()
|
| 818 | {
|
| 819 | // call the screen specific callbacks
|
| 820 | for (callback_item *item = m_callback_list; item != NULL; item = item->m_next)
|
| 821 | (*item->m_callback)(*this, item->m_param, false);
|
| 822 | |
| 823 | // if this is the primary screen and we need to update now
|
| 824 | if (this == machine->primary_screen && (machine->config->m_video_attributes & VIDEO_UPDATE_AFTER_VBLANK))
|
| 825 | machine->video().frame_update();
|
| 826 | |
| 827 | // increment the frame number counter
|
| 828 | m_frame_number++;
|
| 829 | }
|
| 830 | |
| 831 | |
| 832 | //-------------------------------------------------
|
| 833 | // scanline0_callback - reset partial updates
|
| 834 | // for a screen
|
| 835 | //-------------------------------------------------
|
| 836 | |
| 837 | void screen_device::scanline0_callback()
|
| 838 | {
|
| 839 | // reset partial updates
|
| 840 | m_last_partial_scan = 0;
|
| 841 | m_partial_updates_this_frame = 0;
|
| 842 | |
| 843 | timer_adjust_oneshot(m_scanline0_timer, time_until_pos(0), 0);
|
| 844 | }
|
| 845 | |
| 846 | |
| 847 | //-------------------------------------------------
|
| 848 | // scanline_update_callback - perform partial
|
| 849 | // updates on each scanline
|
| 850 | //-------------------------------------------------
|
| 851 | |
| 852 | void screen_device::scanline_update_callback(int scanline)
|
| 853 | {
|
| 854 | // force a partial update to the current scanline
|
| 855 | update_partial(scanline);
|
| 856 | |
| 857 | // compute the next visible scanline
|
| 858 | scanline++;
|
| 859 | if (scanline > m_visarea.max_y)
|
| 860 | scanline = m_visarea.min_y;
|
| 861 | timer_adjust_oneshot(m_scanline_timer, time_until_pos(scanline), scanline);
|
| 862 | }
|
| 863 | |
| 864 | |
| 865 | //-------------------------------------------------
|
| 866 | // update_quads - set up the quads for this
|
| 867 | // screen
|
| 868 | //-------------------------------------------------
|
| 869 | |
| 870 | bool screen_device::update_quads()
|
| 871 | {
|
| 872 | // only update if live
|
| 873 | if (m_machine.render().is_live(*this))
|
| 874 | {
|
| 875 | // only update if empty and not a vector game; otherwise assume the driver did it directly
|
| 876 | if (m_config.m_type != SCREEN_TYPE_VECTOR && (machine->config->m_video_attributes & VIDEO_SELF_RENDER) == 0)
|
| 877 | {
|
| 878 | // if we're not skipping the frame and if the screen actually changed, then update the texture
|
| 879 | if (!m_machine.video().skip_this_frame() && m_changed)
|
| 880 | {
|
| 881 | rectangle fixedvis = m_visarea;
|
| 882 | fixedvis.max_x++;
|
| 883 | fixedvis.max_y++;
|
| 884 | |
| 885 | palette_t *palette = (m_texture_format == TEXFORMAT_PALETTE16) ? machine->palette : NULL;
|
| 886 | m_texture[m_curbitmap]->set_bitmap(m_bitmap[m_curbitmap], &fixedvis, m_texture_format, palette);
|
| 887 | |
| 888 | m_curtexture = m_curbitmap;
|
| 889 | m_curbitmap = 1 - m_curbitmap;
|
| 890 | }
|
| 891 | |
| 892 | // create an empty container with a single quad
|
| 893 | m_container->empty();
|
| 894 | m_container->add_quad(0.0f, 0.0f, 1.0f, 1.0f, MAKE_ARGB(0xff,0xff,0xff,0xff), m_texture[m_curtexture], PRIMFLAG_BLENDMODE(BLENDMODE_NONE) | PRIMFLAG_SCREENTEX(1));
|
| 895 | }
|
| 896 | }
|
| 897 | |
| 898 | // reset the screen changed flags
|
| 899 | bool result = m_changed;
|
| 900 | m_changed = false;
|
| 901 | return result;
|
| 902 | }
|
| 903 | |
| 904 | |
| 905 | //-------------------------------------------------
|
| 906 | // update_burnin - update the burnin bitmap
|
| 907 | //-------------------------------------------------
|
| 908 | |
| 909 | void screen_device::update_burnin()
|
| 910 | {
|
| 911 | #undef rand
|
| 912 | if (m_burnin == NULL)
|
| 913 | return;
|
| 914 | |
| 915 | bitmap_t *srcbitmap = m_bitmap[m_curtexture];
|
| 916 | if (srcbitmap == NULL)
|
| 917 | return;
|
| 918 | |
| 919 | int srcwidth = srcbitmap->width;
|
| 920 | int srcheight = srcbitmap->height;
|
| 921 | int dstwidth = m_burnin->width;
|
| 922 | int dstheight = m_burnin->height;
|
| 923 | int xstep = (srcwidth << 16) / dstwidth;
|
| 924 | int ystep = (srcheight << 16) / dstheight;
|
| 925 | int xstart = ((UINT32)rand() % 32767) * xstep / 32767;
|
| 926 | int ystart = ((UINT32)rand() % 32767) * ystep / 32767;
|
| 927 | int srcx, srcy;
|
| 928 | int x, y;
|
| 929 | |
| 930 | // iterate over rows in the destination
|
| 931 | for (y = 0, srcy = ystart; y < dstheight; y++, srcy += ystep)
|
| 932 | {
|
| 933 | UINT64 *dst = BITMAP_ADDR64(m_burnin, y, 0);
|
| 934 | |
| 935 | // handle the 16-bit palettized case
|
| 936 | if (srcbitmap->format == BITMAP_FORMAT_INDEXED16)
|
| 937 | {
|
| 938 | const UINT16 *src = BITMAP_ADDR16(srcbitmap, srcy >> 16, 0);
|
| 939 | const rgb_t *palette = palette_entry_list_adjusted(machine->palette);
|
| 940 | for (x = 0, srcx = xstart; x < dstwidth; x++, srcx += xstep)
|
| 941 | {
|
| 942 | rgb_t pixel = palette[src[srcx >> 16]];
|
| 943 | dst[x] += RGB_GREEN(pixel) + RGB_RED(pixel) + RGB_BLUE(pixel);
|
| 944 | }
|
| 945 | }
|
| 946 | |
| 947 | // handle the 15-bit RGB case
|
| 948 | else if (srcbitmap->format == BITMAP_FORMAT_RGB15)
|
| 949 | {
|
| 950 | const UINT16 *src = BITMAP_ADDR16(srcbitmap, srcy >> 16, 0);
|
| 951 | for (x = 0, srcx = xstart; x < dstwidth; x++, srcx += xstep)
|
| 952 | {
|
| 953 | rgb15_t pixel = src[srcx >> 16];
|
| 954 | dst[x] += ((pixel >> 10) & 0x1f) + ((pixel >> 5) & 0x1f) + ((pixel >> 0) & 0x1f);
|
| 955 | }
|
| 956 | }
|
| 957 | |
| 958 | // handle the 32-bit RGB case
|
| 959 | else if (srcbitmap->format == BITMAP_FORMAT_RGB32)
|
| 960 | {
|
| 961 | const UINT32 *src = BITMAP_ADDR32(srcbitmap, srcy >> 16, 0);
|
| 962 | for (x = 0, srcx = xstart; x < dstwidth; x++, srcx += xstep)
|
| 963 | {
|
| 964 | rgb_t pixel = src[srcx >> 16];
|
| 965 | dst[x] += RGB_GREEN(pixel) + RGB_RED(pixel) + RGB_BLUE(pixel);
|
| 966 | }
|
| 967 | }
|
| 968 | }
|
| 969 | }
|
| 970 | |
| 971 | |
| 972 | //-------------------------------------------------
|
| 973 | // finalize_burnin - finalize the burnin bitmap
|
| 974 | //-------------------------------------------------
|
| 975 | |
| 976 | void screen_device::finalize_burnin()
|
| 977 | {
|
| 978 | if (m_burnin == NULL)
|
| 979 | return;
|
| 980 | |
| 981 | // compute the scaled visible region
|
| 982 | rectangle scaledvis;
|
| 983 | scaledvis.min_x = m_visarea.min_x * m_burnin->width / m_width;
|
| 984 | scaledvis.max_x = m_visarea.max_x * m_burnin->width / m_width;
|
| 985 | scaledvis.min_y = m_visarea.min_y * m_burnin->height / m_height;
|
| 986 | scaledvis.max_y = m_visarea.max_y * m_burnin->height / m_height;
|
| 987 | |
| 988 | // wrap a bitmap around the subregion we care about
|
| 989 | bitmap_t *finalmap = auto_alloc(machine, bitmap_t(scaledvis.max_x + 1 - scaledvis.min_x,
|
| 990 | scaledvis.max_y + 1 - scaledvis.min_y,
|
| 991 | BITMAP_FORMAT_ARGB32));
|
| 992 | |
| 993 | int srcwidth = m_burnin->width;
|
| 994 | int srcheight = m_burnin->height;
|
| 995 | int dstwidth = finalmap->width;
|
| 996 | int dstheight = finalmap->height;
|
| 997 | int xstep = (srcwidth << 16) / dstwidth;
|
| 998 | int ystep = (srcheight << 16) / dstheight;
|
| 999 | |
| 1000 | // find the maximum value
|
| 1001 | UINT64 minval = ~(UINT64)0;
|
| 1002 | UINT64 maxval = 0;
|
| 1003 | for (int y = 0; y < srcheight; y++)
|
| 1004 | {
|
| 1005 | UINT64 *src = BITMAP_ADDR64(m_burnin, y, 0);
|
| 1006 | for (int x = 0; x < srcwidth; x++)
|
| 1007 | {
|
| 1008 | minval = MIN(minval, src[x]);
|
| 1009 | maxval = MAX(maxval, src[x]);
|
| 1010 | }
|
| 1011 | }
|
| 1012 | |
| 1013 | if (minval == maxval)
|
| 1014 | return;
|
| 1015 | |
| 1016 | // now normalize and convert to RGB
|
| 1017 | for (int y = 0, srcy = 0; y < dstheight; y++, srcy += ystep)
|
| 1018 | {
|
| 1019 | UINT64 *src = BITMAP_ADDR64(m_burnin, srcy >> 16, 0);
|
| 1020 | UINT32 *dst = BITMAP_ADDR32(finalmap, y, 0);
|
| 1021 | for (int x = 0, srcx = 0; x < dstwidth; x++, srcx += xstep)
|
| 1022 | {
|
| 1023 | int brightness = (UINT64)(maxval - src[srcx >> 16]) * 255 / (maxval - minval);
|
| 1024 | dst[x] = MAKE_ARGB(0xff, brightness, brightness, brightness);
|
| 1025 | }
|
| 1026 | }
|
| 1027 | |
| 1028 | // write the final PNG
|
| 1029 | |
| 1030 | // compute the name and create the file
|
| 1031 | astring fname;
|
| 1032 | fname.printf("%s" PATH_SEPARATOR "burnin-%s.png", machine->basename(), tag());
|
| 1033 | mame_file *file;
|
| 1034 | file_error filerr = mame_fopen(SEARCHPATH_SCREENSHOT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
|
| 1035 | if (filerr == FILERR_NONE)
|
| 1036 | {
|
| 1037 | png_info pnginfo = { 0 };
|
| 1038 | png_error pngerr;
|
| 1039 | char text[256];
|
| 1040 | |
| 1041 | // add two text entries describing the image
|
| 1042 | sprintf(text, APPNAME " %s", build_version);
|
| 1043 | png_add_text(&pnginfo, "Software", text);
|
| 1044 | sprintf(text, "%s %s", machine->m_game.manufacturer, machine->m_game.description);
|
| 1045 | png_add_text(&pnginfo, "System", text);
|
| 1046 | |
| 1047 | // now do the actual work
|
| 1048 | pngerr = png_write_bitmap(mame_core_file(file), &pnginfo, finalmap, 0, NULL);
|
| 1049 | |
| 1050 | // free any data allocated
|
| 1051 | png_free(&pnginfo);
|
| 1052 | mame_fclose(file);
|
| 1053 | }
|
| 1054 | }
|
| 1055 | |
| 1056 | |
| 1057 | //-------------------------------------------------
|
| 1058 | // finalize_burnin - finalize the burnin bitmap
|
| 1059 | //-------------------------------------------------
|
| 1060 | |
| 1061 | void screen_device::load_effect_overlay(const char *filename)
|
| 1062 | {
|
| 1063 | // ensure that there is a .png extension
|
| 1064 | astring fullname(filename);
|
| 1065 | int extension = fullname.rchr(0, '.');
|
| 1066 | if (extension != -1)
|
| 1067 | fullname.del(extension, -1);
|
| 1068 | fullname.cat(".png");
|
| 1069 | |
| 1070 | // load the file
|
| 1071 | m_screen_overlay_bitmap = render_load_png(OPTION_ARTPATH, NULL, fullname, NULL, NULL);
|
| 1072 | if (m_screen_overlay_bitmap != NULL)
|
| 1073 | m_container->set_overlay(m_screen_overlay_bitmap);
|
| 1074 | else
|
| 1075 | mame_printf_warning("Unable to load effect PNG file '%s'\n", fullname.cstr());
|
| 1076 | }
|