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)); }
void tdr_to_shift(int which) { acia_6850 *acia_p = &acia[which]; int bitrate = acia_p->rx_clock / acia_p->divide; acia_p->tx_shift = acia[which].tdr; acia_p->status &= ~STATUS_TDRE; /* Start the transmit timer */ timer_adjust(acia_p->tx_timer, TIME_IN_HZ(bitrate), which, TIME_IN_HZ(bitrate)); }
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; }
static MACHINE_INIT(taito) { memset(&TAITOlocals, 0, sizeof(TAITOlocals)); TAITOlocals.pDisplayRAM = memory_region(TAITO_MEMREG_CPU) + 0x4080; TAITOlocals.pCommandsDMA = memory_region(TAITO_MEMREG_CPU) + 0x4090; TAITOlocals.timer_irq = timer_alloc(timer_irq); timer_adjust(TAITOlocals.timer_irq, TIME_IN_HZ(TAITO_IRQFREQ), 0, TIME_IN_HZ(TAITO_IRQFREQ)); if (core_gameData->hw.soundBoard) sndbrd_0_init(core_gameData->hw.soundBoard, TAITO_SCPU, memory_region(TAITO_MEMREG_SCPU), NULL, NULL); TAITOlocals.vblankCount = 1; }
static WRITE8_HANDLER( audio_dac_w) { UINT8 *rom = memory_region(REGION_CPU1); int dac_address = ( data & 0xf0 ) << 8; int sel = ( ( (~data) >> 1 ) & 2 ) | ( data & 1 ); if ( cur_dac_address != dac_address ) { cur_dac_address_index = 0; cur_dac_address = dac_address; } else { cur_dac_address_index++; } if ( sel & 1 ) dac_address += 0x10000; if ( sel & 2 ) dac_address += 0x10000; dac_address += 0x10000; DAC_data_w( 0, rom[dac_address+cur_dac_address_index] ); timer_set( TIME_IN_HZ( 16000 ), 0, dac_irq ); }
static int st300_sh_start(const struct MachineSound *msound) { int mixing_levels[3] = {30,30,30}; int i; int s = 0; memset(&st300loc, 0, sizeof(st300loc)); for (i = 0;i < 9;i++) { snddatst300.ax[i] = 0; snddatst300.axb[i] = 0; snddatst300.c0 = 0; } for (i = 0;i < 32000;i++) { s = (s ? 0 : 1); if (s) { sineWaveext[i] = rand(); } else sineWaveext[i] = 0-rand(); } st300loc.channel = mixer_allocate_channels(3, mixing_levels); mixer_set_name (st300loc.channel, "MC6840 #Q2"); // 6840 Output timer 2 (q2) is easy wave + volume from q3 mixer_set_volume(st300loc.channel,0); mixer_set_name (st300loc.channel+1, "MC6840 #Q1"); // 6840 Output timer 1 (q1) is easy wave + volume always 100 mixer_set_volume(st300loc.channel+1,70*ST300_VOL); mixer_set_name (st300loc.channel+2, "EXT TIM"); // External Timer (U10) is Noise geneartor + volume from q3 mixer_set_volume(st300loc.channel+2,0); timer_pulse(TIME_IN_HZ(ST300_INTCLOCK),0x02,st300_pulse); // start internal clock return 0; }
int TMS34061_start(struct TMS34061interface *interface) { intf = interface; /* Initialize registers to their default values from the manual */ regs[REG_HORENDSYNC] = 0x10; regs[REG_HORENDBLNK] = 0x20; regs[REG_HORSTARTBLNK] = 0x1f0; regs[REG_HORTOTAL] = 0x200; regs[REG_VERENDSYNC] = 0x04; regs[REG_VERENDBLNK] = 0x10; regs[REG_VERSTARTBLNK] = 0xf0; regs[REG_VERTOTAL] = 0x100; regs[REG_DISPUPDATE] = 0x00; regs[REG_DISPSTART] = 0x00; regs[REG_VERINT] = 0x00; regs[REG_CONTROL1] = 0x7000; regs[REG_CONTROL2] = 0x600; regs[REG_STATUS] = 0x00; regs[REG_XYOFFSET] = 0x10; regs[REG_XYADDRESS] = 0x00; regs[REG_DISPADDRESS] = 0x00; regs[REG_VERCOUNTER] = 0x00; /* Start vertical interrupt timer. */ timer = timer_pulse(TIME_IN_HZ (Machine->drv->frames_per_second), intf->cpu, TMS34061_intcallback); return !timer; }
void Dave_Init(void) { int i; //logerror("dave init\n"); Dave_reset(); /* temp! */ nick_virq = 0; /* initialise 1khz timer */ dave.int_latch = 0; dave.int_input = 0; dave.int_enable = 0; dave.timer_irq = 0; dave.fifty_hz_state = 0; dave.one_khz_state = 0; dave.fifty_hz_count = DAVE_FIFTY_HZ_COUNTER_RELOAD; dave.one_hz_count = DAVE_ONE_HZ_COUNTER_RELOAD; timer_pulse(TIME_IN_HZ(1000), 0, dave_1khz_callback); for (i=0; i<3; i++) { dave.Period[i] = ((STEP * Machine->sample_rate)/125000); dave.Count[i] = ((STEP * Machine->sample_rate)/125000); dave.level[i] = 0; } }
void MSM5205_playmode_w(int num,int select) { struct MSM5205Voice *voice = sndti_token(SOUND_MSM5205, num); static const int prescaler_table[4] = {96,48,64,0}; int prescaler = prescaler_table[select & 3]; int bitwidth = (select & 4) ? 4 : 3; if( voice->prescaler != prescaler ) { stream_update(voice->stream,0); voice->prescaler = prescaler; /* timer set */ if( prescaler ) { double period = TIME_IN_HZ(voice->clock / prescaler); timer_adjust_ptr(voice->timer, period, period); } else timer_adjust_ptr(voice->timer, TIME_NEVER, 0); } if( voice->bitwidth != bitwidth ) { stream_update(voice->stream,0); voice->bitwidth = bitwidth; } }
static void mcr68_common_init(void) { int i; /* reset the 6840's */ m6840_status = 0x00; m6840_status_read_since_int = 0x00; m6840_msb_buffer = m6840_lsb_buffer = 0; for (i = 0; i < 3; i++) { m6840_state[i].control = 0x00; m6840_state[i].latch = 0xffff; m6840_state[i].count = 0xffff; m6840_state[i].timer = timer_alloc(counter_fired_callback); m6840_state[i].timer_active = 0; m6840_state[i].period = m6840_counter_periods[i]; } /* initialize the clock */ m6840_internal_counter_period = TIME_IN_HZ(Machine->drv->cpu[0].cpu_clock / 10); /* reset cocktail flip */ mcr_cocktail_flip = 0; /* initialize the sound */ pia_unconfig(); mcr_sound_init(); }
void mc146818_init(MC146818_TYPE type) { mc146818 = auto_malloc(sizeof(*mc146818)); memset(mc146818, 0, sizeof(*mc146818)); mc146818->type = type; mc146818->last_refresh = timer_get_time(); timer_pulse(TIME_IN_HZ(1.0), 0, mc146818_timer); }
void blstroid_int1_callback (int param) { /* generate the interrupt */ cpu_cause_interrupt (0, 1); /* set ourselves up to go off next frame */ int1_timer[param] = timer_set (TIME_IN_HZ (Machine->drv->frames_per_second), param, blstroid_int1_callback); }
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); }
double cpu_getscanlinetime(int scanline) { double scantime = timer_starttime(refresh_timer) + (double)scanline * scanline_period; double abstime = timer_get_time(); double result; /* if we're already past the computed time, count it for the next frame */ if (abstime >= scantime) scantime += TIME_IN_HZ(Machine->drv->frames_per_second); /* compute how long from now until that time */ result = scantime - abstime; /* if it's small, just count a whole frame */ if (result < TIME_IN_NSEC(1)) result += TIME_IN_HZ(Machine->drv->frames_per_second); return result; }
void sega_usb_reset(UINT8 t1_clock_mask) { /* halt the USB CPU at reset time */ cpunum_set_input_line(usb.cpunum, INPUT_LINE_RESET, ASSERT_LINE); /* start the clock timer */ timer_pulse(TIME_IN_HZ(USB_2MHZ_CLOCK / 256), 0, increment_t1_clock); usb.t1_clock_mask = t1_clock_mask; }
void cpu_init_refresh_timer(void) { /* allocate an infinite timer to track elapsed time since the last refresh */ refresh_period = TIME_IN_HZ(Machine->drv->frames_per_second); refresh_period_inv = 1.0 / refresh_period; refresh_timer = timer_alloc(NULL); /* while we're at it, compute the scanline times */ cpu_compute_scanline_timing(); }
void timer_reset(void) { memset(&timer, 0, sizeof(timer)); base_time = 0; frame_base = 0; z80_suspended = 0; time_slice = 1000000.0 / FPS; timer_set(QSOUND_INTERRUPT, TIME_IN_HZ(251), 0, qsound_interrupt); }
void timer_reset(void) { memset(&timer, 0, sizeof(timer)); base_time = 0; frame_base = 0; z80_suspended = !option_sound_enable; m68k_cycles = 11800000.0 * option_m68k_clock / 100000000.0; z80_cycles = 8000000.0 * option_z80_clock / 100000000.0; timer_set(QSOUND_INTERRUPT, TIME_IN_HZ(251), 0, qsound_interrupt); }
M1_BOARD_END /* KiKi KaiKai */ static void Kikikai_Init(long foo) { vblank_timer = timer_pulse(TIME_IN_HZ(60), 0, timer_callback); workram[0x1fff] = 0xff; }
/* Write Control Register */ void acia6850_ctrl_w(int which, UINT8 data) { int wordsel; int divide; acia_6850 *acia_p = &acia[which]; acia_p->ctrl = data; /* 1. Counter divide select */ divide = data & CR1_0; if (divide == 3) { acia_p->reset = 1; reset(which); } else { acia_p->reset = 0; acia_p->divide = div_type[divide]; } /* 2. Word type */ wordsel = (data & CR4_2) >> 2; acia_p->bits = wordtype[wordsel][0]; acia_p->parity = wordtype[wordsel][1]; acia_p->stopbits = wordtype[wordsel][2]; /* 3. TX Control (TODO) */ /* After writing the word type, start receive clock */ if(!acia_p->reset) { int bitrate = acia_p->rx_clock / acia_p->divide; /* TODO! */ timer_adjust(acia_p->rx_timer, TIME_IN_HZ(bitrate), which, TIME_IN_HZ(bitrate)); } }
static double cpu_computerate(int value) { /* values equal to zero are zero */ if (value <= 0) return 0.0; /* values above between 0 and 50000 are in Hz */ if (value < 50000) return TIME_IN_HZ(value); /* values greater than 50000 are in nanoseconds */ else return TIME_IN_NSEC(value); }
static void berzerk_sh_start(void) { int i; berzerknoisemulate = 1; for (i = 0;i < 5;i++) { if (sample_loaded(i)) berzerknoisemulate = 0; } timer_pulse(TIME_IN_HZ(Machine->drv->frames_per_second), 0, berzerk_sh_update); }
void *cchasm_sh_start(int clock, const struct CustomSound_interface *config) { sound_flags = 0; output[0] = 0; output[1] = 0; channel[0] = stream_create(0, 1, Machine->sample_rate, (void *)0, tone_update); channel[1] = stream_create(0, 1, Machine->sample_rate, (void *)1, tone_update); ctc_intf.baseclock[0] = Machine->drv->cpu[1].cpu_clock; z80ctc_init (&ctc_intf); timer_pulse(TIME_IN_HZ(Machine->drv->frames_per_second), 0, cchasm_sh_update); return auto_malloc(1); }
INLINE double get_verint_scanline_time(void) { int scanline = tms34061.regs[TMS34061_VERINT] - tms34061.regs[TMS34061_VERENDBLNK]; double result; if (scanline < 0) scanline += tms34061.regs[TMS34061_VERTOTAL]; /* we fire at the HBLANK signal */ result = cpu_getscanlinetime(scanline) + cpu_getscanlineperiod() * 0.9; if (result < cpu_getscanlineperiod() * 10) result += TIME_IN_HZ(Machine->screen[0].refresh); return result; }
int sound_start(void) { int totalsound = 0; int i; /* Verify the order of entries in the sndintf[] array */ for (i = 0;i < SOUND_COUNT;i++) { if (sndintf[i].sound_num != i) { int j; logerror("Sound #%d wrong ID %d: check enum SOUND_... in src/sndintrf.h!\n",i,sndintf[i].sound_num); for (j = 0; j < i; j++) logerror("ID %2d: %s\n", j, sndintf[j].name); return 1; } } /* samples will be read later if needed */ Machine->samples = 0; refresh_period = TIME_IN_HZ(Machine->drv->frames_per_second); refresh_period_inv = 1.0 / refresh_period; sound_update_timer = timer_alloc(NULL); if (mixer_sh_start() != 0) return 1; if (streams_sh_start() != 0) return 1; while (totalsound < MAX_SOUND && Machine->drv->sound[totalsound].sound_type != 0) { if ((*sndintf[Machine->drv->sound[totalsound].sound_type].start)(&Machine->drv->sound[totalsound]) != 0) goto getout; totalsound++; } return 0; getout: /* TODO: should also free the resources allocated before */ return 1; }
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); } }
static WRITE_HANDLER( common_sound_control_w ) { /* Bit 0 enables and starts NMI timer */ if (nmi_timer) { timer_remove(nmi_timer); nmi_timer = 0; } if (data & 0x01) { /* base clock is 250kHz divided by 256 */ double interval = TIME_IN_HZ(250000.0/256/(256-nmi_rate)); nmi_timer = timer_pulse(interval, 0, nmi_callback); } /* Bit 1 controls a LED on the sound board. I'm not emulating it */ }
static void h8_itu_refresh_timer(int tnum) { int ourTCR = 0; UINT16 ourTVAL = 0; double time; static double tscales[4] = { 1.0, 2.0, 4.0, 8.0 }; switch (tnum) { case 0: ourTCR = h8.per_regs[TCR0]; ourTVAL = h8.h8TCNT0; break; case 1: ourTCR = h8.per_regs[TCR1]; ourTVAL = h8.h8TCNT1; break; case 2: ourTCR = h8.per_regs[TCR2]; ourTVAL = h8.h8TCNT2; break; case 3: ourTCR = h8.per_regs[TCR3]; ourTVAL = h8.h8TCNT3; break; case 4: ourTCR = h8.per_regs[TCR4]; ourTVAL = h8.h8TCNT4; break; } time = (double)TIME_TO_CYCLES(h8.cpu_number, 1) / tscales[ourTCR & 3]; time /= ((double)65536.0 - (double)ourTVAL); if (ourTCR & 4) { logerror("H8/3002: Timer %d is using an external clock. Unsupported!\n", tnum); } timer_adjust(h8.timer[tnum], TIME_IN_HZ(time), 0, 0); }
static void sslam_play(int track, int data) { int status = OKIM6295_status_0_r(0); if (data < 0x80) { if (track) { if (sslam_track != data) { sslam_track = data; sslam_bar = 1; if (status & 0x08) OKIM6295_data_0_w(0,0x40); OKIM6295_data_0_w(0,(0x80 | data)); OKIM6295_data_0_w(0,0x81); timer_adjust(music_timer, TIME_IN_MSEC(4), 0, TIME_IN_HZ(250)); /* 250Hz for smooth sequencing */ } } else { if ((status & 0x01) == 0) { OKIM6295_data_0_w(0,(0x80 | data)); OKIM6295_data_0_w(0,0x11); } else if ((status & 0x02) == 0) { OKIM6295_data_0_w(0,(0x80 | data)); OKIM6295_data_0_w(0,0x21); } else if ((status & 0x04) == 0) { OKIM6295_data_0_w(0,(0x80 | data)); OKIM6295_data_0_w(0,0x41); } } } else { /* use above 0x80 to turn off channels */ if (track) { timer_enable(music_timer,0); sslam_track = 0; sslam_melody = 0; sslam_bar = 0; } data &= 0x7f; OKIM6295_data_0_w(0,data); } }
mame_time video_screen_get_time_until_pos(int scrnum, int vpos, int hpos) { mame_time curdelta = sub_mame_times(mame_timer_get_time(), scrinfo[scrnum].vblank_time); subseconds_t targetdelta; assert(curdelta.seconds == 0); /* since we measure time relative to VBLANK, compute the scanline offset from VBLANK */ vpos += Machine->screen[scrnum].height - (Machine->screen[scrnum].visarea.max_y + 1); vpos %= Machine->screen[scrnum].height; /* compute the delta for the given X,Y position */ targetdelta = (subseconds_t)vpos * scrinfo[scrnum].scantime + (subseconds_t)hpos * scrinfo[scrnum].pixeltime; /* if we're past that time, head to the next frame */ if (targetdelta <= curdelta.subseconds) targetdelta += DOUBLE_TO_SUBSECONDS(TIME_IN_HZ(Machine->screen[scrnum].refresh)); /* return the difference */ return make_mame_time(0, targetdelta - curdelta.subseconds); }