void timer_set_global_time(attotime newbase) { emu_timer *timer; /* set the new global offset */ global_basetime = newbase; LOG(("timer_set_global_time: new=%s head->expire=%s\n", attotime_string(newbase, 9), attotime_string(timer_head->expire, 9))); /* now process any timers that are overdue */ while (attotime_compare(timer_head->expire, global_basetime) <= 0) { int was_enabled = timer_head->enabled; /* if this is a one-shot timer, disable it now */ timer = timer_head; if (attotime_compare(timer->period, attotime_zero) == 0 || attotime_compare(timer->period, attotime_never) == 0) timer->enabled = FALSE; /* set the global state of which callback we're in */ callback_timer_modified = FALSE; callback_timer = timer; callback_timer_expire_time = timer->expire; /* call the callback */ if (was_enabled && timer->callback != NULL) { LOG(("Timer %s:%d[%s] fired (expire=%s)\n", timer->file, timer->line, timer->func, attotime_string(timer->expire, 9))); profiler_mark(PROFILER_TIMER_CALLBACK); (*timer->callback)(Machine, timer->ptr, timer->param); profiler_mark(PROFILER_END); } /* clear the callback timer global */ callback_timer = NULL; /* reset or remove the timer, but only if it wasn't modified during the callback */ if (!callback_timer_modified) { /* if the timer is temporary, remove it now */ if (timer->temporary) timer_remove(timer); /* otherwise, reschedule it */ else { timer->start = timer->expire; timer->expire = attotime_add(timer->expire, timer->period); timer_list_remove(timer); timer_list_insert(timer); } } } }
void ttl74123_device::start_pulse() { attotime duration = compute_duration(); if(timer_running()) { /* retriggering, but not if we are called to quickly */ attotime delay_time = attotime_make(0, ATTOSECONDS_PER_SECOND * m_config.m_cap * 220); if(attotime_compare(timer_timeelapsed(m_timer), delay_time) >= 0) { timer_adjust_oneshot(m_timer, duration, 0); if (LOG) logerror("74123 %s: Retriggering pulse. Duration: %f\n", tag(), attotime_to_double(duration)); } else { if (LOG) logerror("74123 %s: Retriggering failed.\n", tag()); } } else { /* starting */ timer_adjust_oneshot(m_timer, duration, 0); set_output(); if (LOG) logerror("74123 %s: Starting pulse. Duration: %f\n", tag(), attotime_to_double(duration)); } }
static void start_pulse(const device_config *device) { ttl74123_t *chip = get_safe_token(device); attotime duration = compute_duration(chip); if (timer_running(chip)) { /* retriggering, but not if we are called to quickly */ attotime delay_time = attotime_make(0, ATTOSECONDS_PER_SECOND * chip->intf->cap * 220); if (attotime_compare(timer_timeelapsed(chip->timer), delay_time) >= 0) { timer_adjust_oneshot(chip->timer, duration, 0); if (LOG) logerror("74123 %s: Retriggering pulse. Duration: %f\n", device->tag, attotime_to_double(duration)); } else { if (LOG) logerror("74123 %s: Retriggering failed.\n", device->tag); } } else { /* starting */ timer_adjust_oneshot(chip->timer, duration, 0); set_output(device); if (LOG) logerror("74123 %s: Starting pulse. Duration: %f\n", device->tag, attotime_to_double(duration)); } }
void osd_update(running_machine *machine, int skip_redraw){ nitroinput_update(); const render_primitive_list *primlist; int minwidth, minheight; // get the minimum width/height for the current layout render_target_get_minimum_size(our_target, &minwidth, &minheight); if(our_target){ // make that the size of our target render_target_set_bounds(our_target, minwidth, minheight, 0); // get the list of primitives for the target at the current size primlist = render_target_get_primitives(our_target); // lock them, and then render them osd_lock_acquire(primlist->lock); // do the drawing here osd_lock_release(primlist->lock); } // after 5 seconds, exit if (attotime_compare(timer_get_time(machine), attotime_make(5, 0)) > 0) mame_schedule_exit(machine); }
static void watchdog_internal_reset(running_machine *machine) { /* set up the watchdog timer; only start off enabled if explicitly configured */ watchdog_enabled = (machine->config->watchdog_vblank_count != 0 || attotime_compare(machine->config->watchdog_time, attotime_zero) != 0); watchdog_reset(machine); watchdog_enabled = TRUE; }
static void start_pulse(TTL74123_state *chip) { attotime duration = compute_duration(chip); if (timer_running(chip)) { /* retriggering, but not if we are called to quickly */ attotime delay_time = attotime_make(0, ATTOSECONDS_PER_SECOND * chip->intf->cap * 220); if (attotime_compare(timer_timeelapsed(chip->timer), delay_time) >= 0) { timer_adjust(chip->timer, duration, 0, attotime_never); if (LOG) logerror("74123 #%d: Retriggering pulse. Duration: %f\n", chip->which, attotime_to_double(duration)); } else { if (LOG) logerror("74123 #%d: Retriggering failed.\n", chip->which); } } else { /* starting */ timer_adjust(chip->timer, duration, 0, attotime_never); set_output(chip); if (LOG) logerror("74123 #%d: Starting pulse. Duration: %f\n", chip->which, attotime_to_double(duration)); } }
INLINE void timer_list_insert(emu_timer *timer) { attotime expire = timer->enabled ? timer->expire : attotime_never; timer_private *global = timer->machine->timer_data; emu_timer *t, *lt = NULL; /* sanity checks for the debug build */ #ifdef MAME_DEBUG { int tnum = 0; /* loop over the timer list */ for (t = global->activelist; t; t = t->next, tnum++) { if (t == timer) fatalerror("This timer is already inserted in the list!"); if (tnum == MAX_TIMERS-1) fatalerror("Timer list is full!"); } } #endif /* loop over the timer list */ for (t = global->activelist; t != NULL; lt = t, t = t->next) { /* if the current list entry expires after us, we should be inserted before it */ if (attotime_compare(t->expire, expire) > 0) { /* link the new guy in before the current list entry */ timer->prev = t->prev; timer->next = t; if (t->prev != NULL) t->prev->next = timer; else { global->activelist = timer; global->exec.nextfire = timer->expire; } t->prev = timer; return; } } /* need to insert after the last one */ if (lt != NULL) lt->next = timer; else { global->activelist = timer; global->exec.nextfire = timer->expire; } timer->prev = lt; timer->next = NULL; }
static TIMER_CALLBACK( senjyo_sh_update ) { /* ctc2 timer single tone generator frequency */ attotime period = z80ctc_getperiod (0, 2); if (attotime_compare(period, attotime_zero) != 0 ) single_rate = ATTOSECONDS_TO_HZ(period.attoseconds); else single_rate = 0; sample_set_freq(0,single_rate); }
/* TimerHandler from fm.c */ static void TimerHandler(void *param,int c,attotime period) { ym3526_state *info = (ym3526_state *)param; if( attotime_compare(period, attotime_zero) == 0 ) { /* Reset FM Timer */ timer_enable(info->timer[c], 0); } else { /* Start FM Timer */ timer_adjust_oneshot(info->timer[c], period, 0); } }
void speaker_level_w(running_device *device, int new_level) { speaker_state *sp = get_safe_token(device); int volume; attotime time; if (new_level == sp->level) return; if (new_level < 0) new_level = 0; else if (new_level >= sp->num_levels) new_level = sp->num_levels - 1; volume = sp->levels[sp->level]; time = timer_get_time(device->machine); if (attotime_compare(time, sp->channel_next_sample_time) < 0) { /* Stream sample is yet unfinished, but we may have one or more interm. samples */ update_interm_samples(sp, time, volume); /* Do not forget to update speaker state before returning! */ sp->level = new_level; return; } /* Reaching here means such time has passed since last stream update * that we can add at least one complete sample to the stream. * The details have to be handled by speaker_sound_update() */ /* Force streams.c to update sound until this point in time now */ stream_update(sp->channel); /* This is redundant because time update has to be done within speaker_sound_update() anyway, * however this ensures synchronization between the speaker and stream timing: */ sp->channel_last_sample_time = stream_get_time(sp->channel); sp->channel_next_sample_time = attotime_add_attoseconds(sp->channel_last_sample_time, sp->channel_sample_period); sp->next_interm_sample_time = attotime_add_attoseconds(sp->channel_last_sample_time, sp->interm_sample_period); sp->last_update_time = sp->channel_last_sample_time; /* Assertion: time - last_update_time < channel_sample_period, i.e. time < channel_next_sample_time */ /* The overshooting fraction of time will make zero, one or more interm. samples: */ update_interm_samples(sp, time, volume); /* Finally update speaker state before returning */ sp->level = new_level; } /* speaker_level_w */
static TIMER_CALLBACK( senjyo_sh_update ) { running_device *samples = machine->device("samples"); /* ctc2 timer single tone generator frequency */ z80ctc_device *ctc = machine->device<z80ctc_device>("z80ctc"); attotime period = ctc->period(2); if (attotime_compare(period, attotime_zero) != 0 ) single_rate = ATTOSECONDS_TO_HZ(period.attoseconds); else single_rate = 0; sample_set_freq(samples, 0,single_rate); }
void timer_add_scheduling_quantum(running_machine *machine, attoseconds_t quantum, attotime duration) { timer_private *global = machine->timer_data; attotime curtime = timer_get_time(machine); attotime expire = attotime_add(curtime, duration); int curr, blank = -1; /* a 0 request (minimum) needs to be non-zero to occupy a slot */ if (quantum == 0) quantum = 1; /* find an equal-duration slot or an empty slot */ for (curr = 1; curr < ARRAY_LENGTH(global->quantum_list); curr++) { quantum_slot *slot = &global->quantum_list[curr]; /* look for a matching quantum and extend it */ if (slot->requested == quantum) { slot->expire = attotime_max(slot->expire, expire); return; } /* remember any empty slots in case of no match */ if (slot->requested == 0) { if (blank == -1) blank = curr; } /* otherwise, expire any expired slots */ else if (attotime_compare(curtime, slot->expire) >= 0) slot->requested = 0; } /* fatal error if no slots left */ assert_always(blank != -1, "Out of scheduling quantum slots!"); /* fill in the item */ global->quantum_list[blank].requested = quantum; global->quantum_list[blank].actual = MAX(global->quantum_list[blank].requested, global->quantum_minimum); global->quantum_list[blank].expire = expire; /* update the minimum */ if (quantum < global->quantum_current->requested) { global->quantum_current = &global->quantum_list[blank]; global->exec.curquantum = global->quantum_current->actual; } }
INLINE void count_states(int states) { attotime state_time = attotime_make(0, attotime_to_attoseconds(MICRO_STATE_CLOCK_PERIOD) * states); if (!micro.timer) { timer_adjust_oneshot(micro.timer, attotime_never, 0); micro.timer_active = 1; micro.endtime = state_time; } else if (attotime_compare(timer_timeelapsed(micro.timer), micro.endtime) > 0) { timer_adjust_oneshot(micro.timer, attotime_never, 0); micro.timer_active = 1; micro.endtime = state_time; } else micro.endtime = attotime_add(micro.endtime, state_time); }
static void update_interm_samples(speaker_state *sp, attotime time, int volume) { double fraction; /* We may have completed zero, one or more interm. samples: */ while (attotime_compare(time, sp->next_interm_sample_time) >= 0) { /* First interm. sample may be composed, subsequent samples will be homogeneous. */ /* Treat all the same general way. */ finalize_interm_sample(sp, volume); init_next_interm_sample(sp); } /* Depending on status above: * a) Add latest fraction to unfinished composed sample * b) The overshooting fraction of time will start a new composed sample */ fraction = make_fraction(time, sp->last_update_time, sp->interm_sample_period_secfrac); sp->composed_volume[sp->composed_sample_index] += volume * fraction; sp->last_update_time = time; }
void mini_osd_interface::update(bool skip_redraw) { // get the minimum width/height for the current layout int minwidth, minheight; our_target->compute_minimum_size(minwidth, minheight); // make that the size of our target our_target->set_bounds(minwidth, minheight); // get the list of primitives for the target at the current size render_primitive_list &primlist = our_target->get_primitives(); // lock them, and then render them primlist.acquire_lock(); // do the drawing here primlist.release_lock(); // after 5 seconds, exit if (attotime_compare(timer_get_time(&machine()), attotime_make(5, 0)) > 0) machine().schedule_exit(); }
void watchdog_reset(running_machine *machine) { /* if we're not enabled, skip it */ if (!watchdog_enabled) timer_adjust_oneshot(watchdog_timer, attotime_never, 0); /* VBLANK-based watchdog? */ else if (machine->config->watchdog_vblank_count != 0) { watchdog_counter = machine->config->watchdog_vblank_count; /* register a VBLANK callback for the primary screen */ if (machine->primary_screen != NULL) video_screen_register_vblank_callback(machine->primary_screen, on_vblank, NULL); } /* timer-based watchdog? */ else if (attotime_compare(machine->config->watchdog_time, attotime_zero) != 0) timer_adjust_oneshot(watchdog_timer, machine->config->watchdog_time, 0); /* default to an obscene amount of time (3 seconds) */ else timer_adjust_oneshot(watchdog_timer, ATTOTIME_IN_SEC(3), 0); }
bool legacy_image_device_base::load_internal(const char *path, bool is_create, int create_format, option_resolution *create_args) { image_error_t err; UINT32 open_plan[4]; int i; bool softload = FALSE; /* first unload the image */ unload(); /* clear any possible error messages */ clear_error(); /* we are now loading */ m_is_loading = TRUE; /* record the filename */ err = set_image_filename(path); if (err) goto done; /* Check if there's a software list defined for this device and use that if we're not creating an image */ softload = load_software_part( this, path, &m_software_info_ptr, &m_software_part_ptr, &m_full_software_name ); if (is_create || (!softload && m_software_info_ptr==NULL)) { /* determine open plan */ determine_open_plan(is_create, open_plan); /* attempt to open the file in various ways */ for (i = 0; !m_file && open_plan[i]; i++) { /* open the file */ err = load_image_by_path(open_plan[i], path); if (err && (err != IMAGE_ERROR_FILENOTFOUND)) goto done; } } /* Copy some image information when we have been loaded through a software list */ if ( m_software_info_ptr ) { m_longname = m_software_info_ptr->longname; m_manufacturer = m_software_info_ptr->publisher; m_year = m_software_info_ptr->year; //m_playable = m_software_info_ptr->supported; } /* did we fail to find the file? */ if (!is_loaded() && !softload) { err = IMAGE_ERROR_FILENOTFOUND; goto done; } /* call device load or create */ m_create_format = create_format; m_create_args = create_args; if (m_init_phase==FALSE) { err = (image_error_t)finish_load(); if (err) goto done; } /* success! */ done: if (m_err) { if (!m_init_phase) { if (machine->phase() == MACHINE_PHASE_RUNNING) popmessage("Error: Unable to %s image '%s': %s\n", is_create ? "create" : "load", path, error()); else mame_printf_error("Error: Unable to %s image '%s': %s", is_create ? "create" : "load", path, error()); } clear(); } else { /* do we need to reset the CPU? only schedule it if load/create is successful */ if ((attotime_compare(timer_get_time(device().machine), attotime_zero) > 0) && m_image_config.is_reset_on_load()) device().machine->schedule_hard_reset(); else { if (!m_init_phase) { if (machine->phase() == MACHINE_PHASE_RUNNING) popmessage("Image '%s' was successfully %s.", path, is_create ? "created" : "loaded"); else mame_printf_info("Image '%s' was successfully %s.\n", path, is_create ? "created" : "loaded"); } } } return err ? IMAGE_INIT_FAIL : IMAGE_INIT_PASS; }
static int timer_running(ttl74123_t *chip) { return (attotime_compare(timer_timeleft(chip->timer), attotime_zero) > 0) && (attotime_compare(timer_timeleft(chip->timer), attotime_never) != 0); }
int ttl74123_device::timer_running() { return (attotime_compare(timer_timeleft(m_timer), attotime_zero) > 0) && (attotime_compare(timer_timeleft(m_timer), attotime_never) != 0); }
void timer_execute_timers(running_machine *machine) { timer_private *global = machine->timer_data; emu_timer *timer; /* if the current quantum has expired, find a new one */ if (attotime_compare(global->exec.basetime, global->quantum_current->expire) >= 0) { int curr; global->quantum_current->requested = 0; global->quantum_current = &global->quantum_list[0]; for (curr = 1; curr < ARRAY_LENGTH(global->quantum_list); curr++) if (global->quantum_list[curr].requested != 0 && global->quantum_list[curr].requested < global->quantum_current->requested) global->quantum_current = &global->quantum_list[curr]; global->exec.curquantum = global->quantum_current->actual; } LOG(("timer_set_global_time: new=%s head->expire=%s\n", attotime_string(global->exec.basetime, 9), attotime_string(global->activelist->expire, 9))); /* now process any timers that are overdue */ while (attotime_compare(global->activelist->expire, global->exec.basetime) <= 0) { int was_enabled = global->activelist->enabled; /* if this is a one-shot timer, disable it now */ timer = global->activelist; if (attotime_compare(timer->period, attotime_zero) == 0 || attotime_compare(timer->period, attotime_never) == 0) timer->enabled = FALSE; /* set the global state of which callback we're in */ global->callback_timer_modified = FALSE; global->callback_timer = timer; global->callback_timer_expire_time = timer->expire; /* call the callback */ if (was_enabled && timer->callback != NULL) { LOG(("Timer %s:%d[%s] fired (expire=%s)\n", timer->file, timer->line, timer->func, attotime_string(timer->expire, 9))); profiler_mark_start(PROFILER_TIMER_CALLBACK); (*timer->callback)(machine, timer->ptr, timer->param); profiler_mark_end(); } /* clear the callback timer global */ global->callback_timer = NULL; /* reset or remove the timer, but only if it wasn't modified during the callback */ if (!global->callback_timer_modified) { /* if the timer is temporary, remove it now */ if (timer->temporary) timer_remove(timer); /* otherwise, reschedule it */ else { timer->start = timer->expire; timer->expire = attotime_add(timer->expire, timer->period); timer_list_remove(timer); timer_list_insert(timer); } } } }