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)); } }
static WRITE_HANDLER(play1s_data_w) { static UINT8 oldData; static int timer_on; if (data & 0x0f) { if (oldData != data) sndlocals.volume = 100; oldData = data; discrete_sound_w(8, data & 0x01); discrete_sound_w(4, data & 0x02); discrete_sound_w(2, data & 0x04); discrete_sound_w(1, data & 0x08); if (~data & 0x10) { // start fading timer_adjust(sndlocals.timer, 0.02, 0, 0.02); timer_on = 1; } else { // no fading used timer_adjust(sndlocals.timer, TIME_NEVER, 0, 0); timer_on = 0; mixer_set_volume(0, sndlocals.volume); } } else if (!timer_on) { // no fading going on, so stop sound discrete_sound_w(8, 0); discrete_sound_w(4, 0); discrete_sound_w(2, 0); discrete_sound_w(1, 0); } }
static void cpu_vblankcallback(int param) { int cpunum; if (vblank_countdown == 1) vblank = 1; /* loop over CPUs */ for (cpunum = 0; cpunum < cpu_gettotalcpu(); cpunum++) { /* if the interrupt multiplier is valid */ if (cpu[cpunum].vblankint_multiplier != -1) { /* decrement; if we hit zero, generate the interrupt and reset the countdown */ if (!--cpu[cpunum].vblankint_countdown) { /* a param of -1 means don't call any callbacks */ if (param != -1) { /* if the CPU has a VBLANK handler, call it */ if (Machine->drv->cpu[cpunum].vblank_interrupt && cpu_getstatus(cpunum)) { cpuintrf_push_context(cpunum); (*Machine->drv->cpu[cpunum].vblank_interrupt)(); cpuintrf_pop_context(); } /* update the counters */ cpu[cpunum].iloops--; } /* reset the countdown and timer */ cpu[cpunum].vblankint_countdown = cpu[cpunum].vblankint_multiplier; timer_adjust(cpu[cpunum].vblankint_timer, TIME_NEVER, 0, 0); } } /* else reset the VBLANK timer if this is going to be a real VBLANK */ else if (vblank_countdown == 1) timer_adjust(cpu[cpunum].vblankint_timer, TIME_NEVER, 0, 0); } /* is it a real VBLANK? */ if (!--vblank_countdown) { /* do we update the screen now? */ if (!(Machine->drv->video_attributes & VIDEO_UPDATE_AFTER_VBLANK)) time_to_quit = updatescreen(); /* Set the timer to update the screen */ timer_set(TIME_IN_USEC(Machine->drv->vblank_duration), 0, cpu_updatecallback); /* reset the globals */ cpu_vblankreset(); /* reset the counter */ vblank_countdown = vblank_multiplier; } }
static WRITE8_HANDLER( polyplay_start_timer2 ) { if (data == 0x03) timer_adjust(polyplay_timer, TIME_NEVER, 0, 0); if (data == 0xb5) timer_adjust(polyplay_timer, TIME_IN_HZ(40), 0, TIME_IN_HZ(40)); }
static WRITE8_HANDLER( polyplay_start_timer2 ) { if (data == 0x03) timer_adjust(polyplay_timer, attotime_never, 0, attotime_never); if (data == 0xb5) timer_adjust(polyplay_timer, ATTOTIME_IN_HZ(40), 0, ATTOTIME_IN_HZ(40)); }
void h8_itu_reset(void) { // stop all the timers timer_adjust(h8.timer[0], TIME_NEVER, 0, 0); timer_adjust(h8.timer[1], TIME_NEVER, 0, 0); timer_adjust(h8.timer[2], TIME_NEVER, 0, 0); timer_adjust(h8.timer[3], TIME_NEVER, 0, 0); timer_adjust(h8.timer[4], TIME_NEVER, 0, 0); }
static void dma_timer( int n_channel, UINT32 n_scanline ) { if( n_scanline != 0xffffffff ) { timer_adjust( m_p_timer_dma[ n_channel ], cpu_getscanlinetime( n_scanline ), n_channel, 0 ); } else { timer_adjust( m_p_timer_dma[ n_channel ], TIME_NEVER, 0, 0 ); } m_p_n_dma_lastscanline[ n_channel ] = n_scanline; }
static WRITE_HANDLER(play2s_ctrl_w) { if (!sndlocals.enSn && (data & 1)) { // sound on to full volume timer_adjust(sndlocals.timer, TIME_NEVER, 0, 0); if (!mixer_is_sample_playing(sndlocals.channel)) { mixer_play_sample(sndlocals.channel, (signed char *)squareWave, sizeof(squareWave), 2950000.0 / 4 / (sndlocals.freq + 1), 1); } sndlocals.volume = 100; mixer_set_volume(sndlocals.channel, sndlocals.volume); } else if (!(data & 1) && sndlocals.enSn) { // start fading timer_adjust(sndlocals.timer, TIME_IN_HZ(120), 0, TIME_IN_HZ(120)); } sndlocals.enSn = data & 1; }
void cpu_boost_interleave(double timeslice_time, double boost_duration) { /* if you pass 0 for the timeslice_time, it means pick something reasonable */ if (timeslice_time < perfect_interleave) timeslice_time = perfect_interleave; LOG(("cpu_boost_interleave(%.9f, %.9f)\n", timeslice_time, boost_duration)); /* adjust the interleave timer */ timer_adjust(interleave_boost_timer, timeslice_time, 0, timeslice_time); /* adjust the end timer */ timer_adjust(interleave_boost_timer_end, boost_duration, 0, TIME_NEVER); }
static void gpss4_init(struct sndbrdData *brdData) { capTimer = timer_alloc(capTimer_timer); timer_adjust(capTimer, TIME_NEVER, 0, TIME_NEVER); /* MIXER (pins 27,25,26) = 010 */ SN76477_mixer_w(0, 2); /* ENVELOPE is constant: pin1 = hi, pin 28 = lo */ SN76477_envelope_w(0, 1); /* ENVELOPE is constant: pin1 = hi, pin 28 = lo */ SN76477_envelope_w(1, 1); SN76477_vco_w(1, 1); /* MIXER = 0 */ SN76477_mixer_w(2, 0); /* ENVELOPE is constant: pin1 = lo, pin 28 = lo */ SN76477_envelope_w(2, 0); /* MIXER = 0 */ SN76477_mixer_w(3, 0); /* ENVELOPE is constant: pin1 = lo, pin 28 = hi */ SN76477_envelope_w(3, 2); SN76477_vco_w(3, 1); }
static void cpu_updatecallback(int param) { /* update the screen if we didn't before */ if (Machine->drv->video_attributes & VIDEO_UPDATE_AFTER_VBLANK) time_to_quit = updatescreen(); vblank = 0; /* update IPT_VBLANK input ports */ inputport_vblank_end(); /* reset partial updating */ reset_partial_updates(); /* check the watchdog */ if (watchdog_counter > 0) if (--watchdog_counter == 0) { logerror("reset caused by the watchdog\n"); machine_reset(); } /* track total frames */ current_frame++; /* reset the refresh timer */ timer_adjust(refresh_timer, TIME_NEVER, 0, 0); }
void centronics_write_handshake(int nr, int data, int mask) { CENTRONICS *This=cent+nr; int neu=(data&mask)|(This->control&(~mask)); if (neu & CENTRONICS_NO_RESET) { if ( !(This->control&CENTRONICS_STROBE) && (neu&CENTRONICS_STROBE) ) { printer_output(image_from_devtype_and_index(IO_PRINTER, nr), This->data); /* setup timer for data acknowledge */ /* set mask for data that has changed */ This->new_control_mask = CENTRONICS_ACKNOWLEDGE; /* set data that has changed */ This->new_control_data = CENTRONICS_ACKNOWLEDGE; /* setup a new timer */ timer_adjust(This->timer, TIME_IN_USEC(1), nr, 0); } } This->control=neu; }
/*************************************************************************** ticket_dispenser_toggle How I think this works: When a ticket dispenses, there is N milliseconds of status = high, and N milliseconds of status = low (a wait cycle?). ***************************************************************************/ static void ticket_dispenser_toggle(int which) { /* If we still have power, keep toggling ticket states. */ if (dispenser[which].power) { dispenser[which].status ^= active_bit; #ifdef DEBUG_TICKET logerror("Ticket Status Changed to %02X\n", status); #endif timer_adjust(dispenser[which].timer, TIME_IN_MSEC(time_msec), which, 0); } if (dispenser[which].status == ticketdispensed) { set_led_status(2,1); dispensed_tickets++; #ifdef DEBUG_TICKET logerror("Ticket Dispensed\n"); #endif } else { set_led_status(2,0); } }
void sound_update(void) { #if 0 /* forQUASI88 */ int totalsound = 0; profiler_mark(PROFILER_SOUND); while (Machine->drv->sound[totalsound].sound_type != 0 && totalsound < MAX_SOUND) { if (sndintf[Machine->drv->sound[totalsound].sound_type].update) (*sndintf[Machine->drv->sound[totalsound].sound_type].update)(); totalsound++; } #else /* forQUASI88 */ { if (sndintf[ fm_interface.sound_type ].update) (*sndintf[ fm_interface.sound_type ].update)(); if (sndintf[ beep_interface.sound_type ].update) (*sndintf[ beep_interface.sound_type ].update)(); } #endif /* forQUASI88 */ streams_sh_update(); mixer_sh_update(); timer_adjust(sound_update_timer, TIME_NEVER, 0, 0); profiler_mark(PROFILER_END); }
/* Remove the timer handler */ void timer_restore(void) { /* Restore previous timer setting */ timer_adjust(0); /* Remove the interrupt handler */ _go32_dpmi_set_protected_mode_interrupt_vector(TIMER_INT, &old_handler); }
void tmp68301_update_timer( int i ) { UINT16 TCR = tmp68301_regs[(0x200 + i * 0x20)/2]; UINT16 MAX1 = tmp68301_regs[(0x204 + i * 0x20)/2]; UINT16 MAX2 = tmp68301_regs[(0x206 + i * 0x20)/2]; int max = 0; double duration = 0; timer_adjust(tmp68301_timer[i],TIME_NEVER,i,0); /* timers 1&2 only */ switch( (TCR & 0x0030)>>4 ) /* MR2..1 */ { case 1: max = MAX1; break; case 2: max = MAX2; break; } switch ( (TCR & 0xc000)>>14 ) /* CK2..1 */ { case 0: /* System clock (CLK) */ if (max) { int scale = (TCR & 0x3c00)>>10; /* P4..1 */ if (scale > 8) scale = 8; duration = Machine->drv->cpu[0].cpu_clock; duration /= 1 << scale; duration /= max; } break; } /* logerror("CPU #0 PC %06X: TMP68301 Timer %d, duration %lf, max %04X\n",activecpu_get_pc(),i,duration,max); */ if (!(TCR & 0x0002)) /* CS */ { if (duration) timer_adjust(tmp68301_timer[i],TIME_IN_HZ(duration),i,0); else logerror("CPU #0 PC %06X: TMP68301 error, timer %d duration is 0\n",activecpu_get_pc(),i); } }
INLINE void count_states(int states) { if (!micro.timer) { timer_adjust(micro.timer, TIME_NEVER, 0, 0); micro.timer_active = 1; micro.endtime = (double)states * MICRO_STATE_CLOCK_PERIOD; } else if (timer_timeelapsed(micro.timer) > micro.endtime) { timer_adjust(micro.timer, TIME_NEVER, 0, 0); micro.timer_active = 1; micro.endtime = (double)states * MICRO_STATE_CLOCK_PERIOD; } else micro.endtime += (double)states * MICRO_STATE_CLOCK_PERIOD; }
INLINE void schedule_next_irq(int curscanline) { /* IRQ is clocked by /32V, so every 64 scanlines */ curscanline = (curscanline + 64) & 255; /* next one at the start of this scanline */ timer_adjust(irq_timer, video_screen_get_time_until_pos(0, curscanline, 0), curscanline, attotime_zero); }
static void cpu_firstvblankcallback(int param) { /* now that we're synced up, pulse from here on out */ timer_adjust(vblank_timer, vblank_period, param, vblank_period); /* but we need to call the standard routine as well */ cpu_vblankcallback(param); }
void europc_rtc_init(void) { memset(&europc_rtc,0,sizeof(europc_rtc)); europc_rtc.data[0xf]=1; europc_rtc.timer = timer_alloc(europc_rtc_timer); timer_adjust(europc_rtc.timer, 0, 0, 1.0); }
static TIMER_CALLBACK( scanline_callback ) { if (param==interrupt_scanline) { if (out&0x2000) cpunum_set_input_line(0, 1, ASSERT_LINE); timer_adjust(scanline_timer, video_screen_get_time_until_pos(0, param+1, 0), param+1, attotime_zero); interrupt_line_active = 1; } else { if (interrupt_line_active) cpunum_set_input_line(0, 1, CLEAR_LINE); timer_adjust(scanline_timer, video_screen_get_time_until_pos(0, interrupt_scanline, 0), interrupt_scanline, attotime_zero); interrupt_line_active = 0; } }
static void adjust_timer(int offset) { static char s[8]; SPINBlocals.irqfreq += offset; if (SPINBlocals.irqfreq < 1) SPINBlocals.irqfreq = 1; sprintf(s, "IRQ:%4d", SPINBlocals.irqfreq); core_textOut(s, 8, 40, 0, 5); timer_adjust(SPINBlocals.irqtimer, 1.0/(double)SPINBlocals.irqfreq, 0, 1.0/(double)SPINBlocals.irqfreq); }
static WRITE8_HANDLER( sound_nmi_rate_w ) { /* rate is controlled by the value written here */ /* this value is latched into up-counters, which are clocked at the */ /* input clock / 256 */ attotime nmi_rate = attotime_mul(ATTOTIME_IN_HZ(4000000), 4096 * (256 - data)); timer_adjust(sound_nmi_timer, nmi_rate, 0, nmi_rate); }
void z80ctc_trg_w (int which, int trg, int offset, int data) { z80ctc *ctc = ctcs + which; int ch = trg & 3; int mode; data = data ? 1 : 0; mode = ctc->mode[ch]; /* see if the trigger value has changed */ if (data != ctc->extclk[ch]) { ctc->extclk[ch] = data; /* see if this is the active edge of the trigger */ if (((mode & EDGE) == EDGE_RISING && data) || ((mode & EDGE) == EDGE_FALLING && !data)) { /* if we're waiting for a trigger, start the timer */ if ((mode & WAITING_FOR_TRIG) && (mode & MODE) == MODE_TIMER) { double clock = ((mode & PRESCALER) == PRESCALER_16) ? ctc->invclock16 : ctc->invclock256; logerror("CTC clock %f\n",1.0/clock); if (!(ctc->notimer & (1<<ch))) timer_adjust(ctc->timer[ch], clock * (double)ctc->tconst[ch], (which << 2) + ch, clock * (double)ctc->tconst[ch]); else timer_adjust(ctc->timer[ch], TIME_NEVER, 0, 0); } /* we're no longer waiting */ ctc->mode[ch] &= ~WAITING_FOR_TRIG; /* if we're clocking externally, decrement the count */ if ((mode & MODE) == MODE_COUNTER) { ctc->down[ch]--; /* if we hit zero, do the same thing as for a timer interrupt */ if (!ctc->down[ch]) z80ctc_timercallback ((which << 2) + ch); } } } }
static void play2s_timer_callback(int n) { if (sndlocals.volume) { mixer_set_volume(sndlocals.channel, (--sndlocals.volume)); if (!sndlocals.volume) { timer_adjust(sndlocals.timer, TIME_NEVER, 0, 0); mixer_stop_sample(sndlocals.channel); } } }
static WRITE16_HANDLER( fuuki16_vregs_w ) { UINT16 old_data = fuuki16_vregs[offset]; UINT16 new_data = COMBINE_DATA(&fuuki16_vregs[offset]); if ((offset == 0x1c/2) && old_data != new_data) { timer_adjust(raster_interrupt_timer, video_screen_get_time_until_pos(0, new_data, Machine->screen[0].visarea.max_x + 1), 0, video_screen_get_frame_period(0)); } }
static WRITE8_HANDLER( sound_nmi_rate_w ) { /* rate is controlled by the value written here */ /* this value is latched into up-counters, which are clocked at the */ /* input clock / 256 */ double input_clock = TIME_IN_HZ(4000000/16); double nmi_rate = input_clock * 256 * (256 - data); timer_adjust(sound_nmi_timer, nmi_rate, 0, nmi_rate); }
static MACHINE_RESET( pkscramble) { out = 0; interrupt_line_active=0; scanline_timer = timer_alloc(scanline_callback, NULL); timer_adjust(scanline_timer, video_screen_get_time_until_pos(0, interrupt_scanline, 0), interrupt_scanline, attotime_zero); state_save_register_global(out); state_save_register_global(interrupt_line_active); }
void sound_init(running_machine *machine) { attotime update_frequency = SOUND_UPDATE_FREQUENCY; const char *filename; /* handle -nosound */ nosound_mode = !options_get_bool(mame_options(), OPTION_SOUND); if (nosound_mode) Machine->sample_rate = 11025; /* count the speakers */ for (totalspeakers = 0; Machine->drv->speaker[totalspeakers].tag; totalspeakers++) ; VPRINTF(("total speakers = %d\n", totalspeakers)); /* allocate memory for mix buffers */ leftmix = auto_malloc(Machine->sample_rate * sizeof(*leftmix)); rightmix = auto_malloc(Machine->sample_rate * sizeof(*rightmix)); finalmix = auto_malloc(Machine->sample_rate * sizeof(*finalmix)); /* allocate a global timer for sound timing */ sound_update_timer = timer_alloc(sound_update, NULL); timer_adjust(sound_update_timer, update_frequency, 0, update_frequency); /* initialize the streams engine */ VPRINTF(("streams_init\n")); streams_init(machine, update_frequency.attoseconds); /* now start up the sound chips and tag their streams */ VPRINTF(("start_sound_chips\n")); start_sound_chips(); /* then create all the speakers */ VPRINTF(("start_speakers\n")); start_speakers(); /* finally, do all the routing */ VPRINTF(("route_sound\n")); route_sound(); /* open the output WAV file if specified */ filename = options_get_string(mame_options(), OPTION_WAVWRITE); if (filename[0] != 0) wavfile = wav_open(filename, machine->sample_rate, 2); /* enable sound by default */ global_sound_enabled = TRUE; sound_muted = FALSE; sound_set_attenuation(options_get_int(mame_options(), OPTION_VOLUME)); /* register callbacks */ config_register("mixer", sound_load, sound_save); add_pause_callback(machine, sound_pause); add_reset_callback(machine, sound_reset); add_exit_callback(machine, sound_exit); }
static void TimerHandler_3812(int c,double period) { if( period == 0 ) { /* Reset FM Timer */ timer_enable(Timer_3812[c], 0); } else { /* Start FM Timer */ timer_adjust(Timer_3812[c], period, c, 0); } }