void z80dart_device::device_start() { // resolve callbacks devcb_resolve_write_line(&m_out_int_func, &m_config.m_out_int_func, this); m_channel[Z80DART_CH_A].start(this, Z80DART_CH_A, m_config.m_in_rxda_func, m_config.m_out_txda_func, m_config.m_out_dtra_func, m_config.m_out_rtsa_func, m_config.m_out_wrdya_func); m_channel[Z80DART_CH_B].start(this, Z80DART_CH_B, m_config.m_in_rxdb_func, m_config.m_out_txdb_func, m_config.m_out_dtrb_func, m_config.m_out_rtsb_func, m_config.m_out_wrdyb_func); if (m_config.m_rx_clock_a != 0) { // allocate channel A receive timer m_rxca_timer = timer_alloc(&m_machine, dart_channel::static_rxca_tick, (void *)&m_channel[Z80DART_CH_A]); timer_adjust_periodic(m_rxca_timer, attotime_zero, 0, ATTOTIME_IN_HZ(m_config.m_rx_clock_a)); } if (m_config.m_tx_clock_a != 0) { // allocate channel A transmit timer m_txca_timer = timer_alloc(&m_machine, dart_channel::static_txca_tick, (void *)&m_channel[Z80DART_CH_A]); timer_adjust_periodic(m_txca_timer, attotime_zero, 0, ATTOTIME_IN_HZ(m_config.m_tx_clock_a)); } if (m_config.m_rx_tx_clock_b != 0) { // allocate channel B receive/transmit timer m_rxtxcb_timer = timer_alloc(&m_machine, dart_channel::static_rxtxcb_tick, (void *)&m_channel[Z80DART_CH_B]); timer_adjust_periodic(m_rxtxcb_timer, attotime_zero, 0, ATTOTIME_IN_HZ(m_config.m_rx_tx_clock_b)); } state_save_register_device_item_array(this, 0, m_int_state); }
void timer_device::device_reset() { // type based configuration switch (m_config.m_type) { case timer_device_config::TIMER_TYPE_GENERIC: case timer_device_config::TIMER_TYPE_PERIODIC: { // convert the period into attotime attotime period = attotime_never; if (m_config.m_period > 0) { period = UINT64_ATTOTIME_TO_ATTOTIME(m_config.m_period); // convert the start_delay into attotime attotime start_delay = attotime_zero; if (m_config.m_start_delay > 0) start_delay = UINT64_ATTOTIME_TO_ATTOTIME(m_config.m_start_delay); // allocate and start the backing timer timer_adjust_periodic(m_timer, start_delay, m_config.m_param, period); } break; } case timer_device_config::TIMER_TYPE_SCANLINE: if (m_screen == NULL) fatalerror("timer '%s': unable to find screen '%s'\n", tag(), m_config.m_screen); // set the timer to to fire immediately m_first_time = true; timer_adjust_oneshot(m_timer, attotime_zero, m_config.m_param); break; } }
static void dma8257_update_status(const device_config *device) { dma8257_t *dma8257 = get_safe_token(device); UINT16 pending_transfer; attotime next; /* no transfer is active right now; is there a transfer pending right now? */ pending_transfer = dma8257->drq & (dma8257->mode & 0x0F); if (pending_transfer) { next = ATTOTIME_IN_HZ(device->clock / 4 ); timer_adjust_periodic(dma8257->timer, attotime_zero, 0, /* 1 byte transferred in 4 clock cycles */ next); } else { /* no transfers active right now */ timer_reset(dma8257->timer, attotime_never); } /* set the halt line */ if (dma8257->intf && dma8257->intf->cputag != NULL) { cputag_set_input_line(device->machine, dma8257->intf->cputag, INPUT_LINE_HALT, pending_transfer ? ASSERT_LINE : CLEAR_LINE); } }
static void msm5205_playmode(msm5205_state *voice,int select) { 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); voice->prescaler = prescaler; /* timer set */ if( prescaler ) { attotime period = attotime_mul(ATTOTIME_IN_HZ(voice->clock), prescaler); timer_adjust_periodic(voice->timer, period, 0, period); } else timer_adjust_oneshot(voice->timer, attotime_never, 0); } if( voice->bitwidth != bitwidth ) { stream_update(voice->stream); voice->bitwidth = bitwidth; } }
static DEVICE_START( cdp1852 ) { cdp1852_t *cdp1852 = get_safe_token(device); const cdp1852_interface *intf = get_interface(device); /* resolve callbacks */ devcb_resolve_read8(&cdp1852->in_data_func, &intf->in_data_func, device); devcb_resolve_write8(&cdp1852->out_data_func, &intf->out_data_func, device); devcb_resolve_write_line(&cdp1852->out_sr_func, &intf->out_sr_func, device); /* set initial values */ cdp1852->mode = (cdp1852_mode)intf->mode; if (device->clock > 0) { /* create the scan timer */ cdp1852->scan_timer = timer_alloc(device->machine, cdp1852_scan_tick, (void *)device); timer_adjust_periodic(cdp1852->scan_timer, attotime_zero, 0, ATTOTIME_IN_HZ(device->clock)); } /* register for state saving */ state_save_register_device_item(device, 0, cdp1852->new_data); state_save_register_device_item(device, 0, cdp1852->data); state_save_register_device_item(device, 0, cdp1852->next_data); state_save_register_device_item(device, 0, cdp1852->sr); state_save_register_device_item(device, 0, cdp1852->next_sr); }
void z80dma_device::update_status() { UINT16 pending_transfer; attotime next; // no transfer is active right now; is there a transfer pending right now? pending_transfer = is_ready() & m_dma_enabled; if (pending_transfer) { m_is_read = true; m_cur_cycle = (PORTA_IS_SOURCE ? PORTA_CYCLE_LEN : PORTB_CYCLE_LEN); next = ATTOTIME_IN_HZ(clock()); timer_adjust_periodic(m_timer, attotime_zero, 0, // 1 byte transferred in 4 clock cycles next); } else { if (m_is_read) { // no transfers active right now timer_reset(m_timer, attotime_never); } } // set the busreq line devcb_call_write_line(&m_out_busreq_func, pending_transfer ? ASSERT_LINE : CLEAR_LINE); }
void microtouch_init(running_machine *machine, microtouch_tx_func tx_cb, microtouch_touch_func touch_cb) { memset(µtouch, 0, sizeof(microtouch)); microtouch.last_touch_state = -1; microtouch.tx_callback = tx_cb; microtouch.touch_callback = touch_cb; microtouch.timer = timer_alloc(machine, microtouch_timer_callback, NULL); timer_adjust_periodic(microtouch.timer, ATTOTIME_IN_HZ(167*5), 0, ATTOTIME_IN_HZ(167*5)); state_save_register_item(machine, "microtouch", NULL, 0, microtouch.reset_done); state_save_register_item(machine, "microtouch", NULL, 0, microtouch.format_tablet); state_save_register_item(machine, "microtouch", NULL, 0, microtouch.mode_inactive); state_save_register_item(machine, "microtouch", NULL, 0, microtouch.mode_stream); state_save_register_item(machine, "microtouch", NULL, 0, microtouch.last_touch_state); state_save_register_item(machine, "microtouch", NULL, 0, microtouch.last_x); state_save_register_item(machine, "microtouch", NULL, 0, microtouch.last_y); state_save_register_item_array(machine, "microtouch", NULL, 0, microtouch.rx_buffer); state_save_register_item(machine, "microtouch", NULL, 0, microtouch.rx_buffer_ptr); state_save_register_item_array(machine, "microtouch", NULL, 0, microtouch.tx_buffer); state_save_register_item(machine, "microtouch", NULL, 0, microtouch.tx_buffer_num); state_save_register_item(machine, "microtouch", NULL, 0, microtouch.tx_buffer_ptr); };
void DS2404_init(running_machine *machine, int ref_year, int ref_month, int ref_day) { struct tm ref_tm; time_t ref_time; time_t current_time; emu_timer *timer; memset( &ref_tm, 0, sizeof( ref_tm ) ); ref_tm.tm_year = ref_year - 1900; ref_tm.tm_mon = ref_month - 1; ref_tm.tm_mday = ref_day; ref_time = mktime( &ref_tm ); time( ¤t_time ); current_time -= ref_time; ds2404.rtc[ 0 ] = 0x0; ds2404.rtc[ 1 ] = ( current_time >> 0 ) & 0xff; ds2404.rtc[ 2 ] = ( current_time >> 8 ) & 0xff; ds2404.rtc[ 3 ] = ( current_time >> 16 ) & 0xff; ds2404.rtc[ 4 ] = ( current_time >> 24 ) & 0xff; timer = timer_alloc( machine, DS2404_tick , NULL); timer_adjust_periodic( timer, ATTOTIME_IN_HZ( 256 ), 0, ATTOTIME_IN_HZ( 256 ) ); }
void timer_device_reset(running_device *timer) { timer_state *state = get_safe_token(timer); #ifdef MAME_DEBUG timer_config *config = (timer_config *)timer->baseconfig().inline_config; /* doesn't make sense for scanline timers */ assert(config->type != TIMER_TYPE_SCANLINE); #endif timer_adjust_periodic(state->timer, state->start_delay, 0, state->period); }
static WRITE16_HANDLER( fuuki16_vregs_w ) { fuuki16_state *state = (fuuki16_state *)space->machine->driver_data; UINT16 old_data = state->vregs[offset]; UINT16 new_data = COMBINE_DATA(&state->vregs[offset]); if ((offset == 0x1c/2) && old_data != new_data) { const rectangle *visarea = video_screen_get_visible_area(space->machine->primary_screen); attotime period = video_screen_get_frame_period(space->machine->primary_screen); timer_adjust_periodic(state->raster_interrupt_timer, video_screen_get_time_until_pos(space->machine->primary_screen, new_data, visarea->max_x + 1), 0, period); } }
void timer_device_reset(const device_config *timer) { timer_state *state = get_safe_token(timer); #ifndef NDEBUG timer_config *config = timer->inline_config; /* only makes sense for periodic timers */ assert(config->type == TIMER_TYPE_PERIODIC); #endif timer_adjust_periodic(state->timer, state->start_delay, 0, state->period); }
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 */ VPRINTF(("total speakers = %d\n", speaker_output_count(machine->config))); /* 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_periodic(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(); /* 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 DEVICE_START(timekeeper) { timekeeper_state *c = get_safe_token(device); emu_timer *timer; attotime duration; mame_system_time systime; /* validate some basic stuff */ assert(device != NULL); // assert(device->static_config != NULL); assert(device->inline_config == NULL); assert(device->machine != NULL); assert(device->machine->config != NULL); mame_get_base_datetime(device->machine, &systime); c->device = device; c->control = 0; c->seconds = make_bcd( systime.local_time.second ); c->minutes = make_bcd( systime.local_time.minute ); c->hours = make_bcd( systime.local_time.hour ); c->day = make_bcd( systime.local_time.weekday + 1 ); c->date = make_bcd( systime.local_time.mday ); c->month = make_bcd( systime.local_time.month + 1 ); c->year = make_bcd( systime.local_time.year % 100 ); c->century = make_bcd( systime.local_time.year / 100 ); c->data = auto_alloc_array( device->machine, UINT8, c->size ); c->default_data = device->region; if (c->default_data != NULL) { assert( device->regionbytes == c->size ); } state_save_register_device_item( device, 0, c->control ); state_save_register_device_item( device, 0, c->seconds ); state_save_register_device_item( device, 0, c->minutes ); state_save_register_device_item( device, 0, c->hours ); state_save_register_device_item( device, 0, c->day ); state_save_register_device_item( device, 0, c->date ); state_save_register_device_item( device, 0, c->month ); state_save_register_device_item( device, 0, c->year ); state_save_register_device_item( device, 0, c->century ); state_save_register_device_item_pointer( device, 0, c->data, c->size ); timer = timer_alloc( device->machine, timekeeper_tick, c ); duration = ATTOTIME_IN_SEC(1); timer_adjust_periodic( timer, duration, 0, duration ); }
void timer_device_adjust_periodic(running_device *timer, attotime start_delay, INT32 param, attotime period) { timer_state *state = get_safe_token(timer); #ifdef MAME_DEBUG timer_config *config = (timer_config *)timer->baseconfig().inline_config; /* doesn't make sense for scanline timers */ assert(config->type != TIMER_TYPE_SCANLINE); #endif state->start_delay = start_delay; state->period = period; state->param = param; /* adjust the timer */ timer_adjust_periodic(state->timer, state->start_delay, 0, state->period); }
void timer_device_adjust_periodic(const device_config *timer, attotime start_delay, INT32 param, attotime period) { timer_state *state = get_safe_token(timer); #ifndef NDEBUG timer_config *config = timer->inline_config; /* only makes sense for periodic timers */ assert(config->type == TIMER_TYPE_PERIODIC); #endif state->start_delay = start_delay; state->period = period; state->param = param; /* adjust the timer */ timer_adjust_periodic(state->timer, state->start_delay, 0, state->period); }
AM_RANGE(0x00, 0x3f) AM_RAM ADDRESS_MAP_END /**************************************************************************** * Initialize emulation ****************************************************************************/ static void cop410_init(int index, int clock, const void *config, int (*irqcallback)(int)) { int i; memset(&R, 0, sizeof(R)); R.G_mask = 0x0F; R.D_mask = 0x0F; cop410_serial_timer = timer_alloc(cop410_serial_tick, NULL); timer_adjust_periodic(cop410_serial_timer, attotime_zero, index, ATTOTIME_IN_HZ(clock)); for (i=0; i<256; i++) InstLen[i]=1; InstLen[0x60] = InstLen[0x61] = InstLen[0x68] = InstLen[0x69] = InstLen[0x33] = InstLen[0x23] = 2; for (i=0; i<256; i++) LBIops[i] = 0; for (i=0x08; i<0x10; i++) LBIops[i] = 1; for (i=0x18; i<0x20; i++) LBIops[i] = 1; for (i=0x28; i<0x30; i++) LBIops[i] = 1; for (i=0x38; i<0x40; i++) LBIops[i] = 1; state_save_register_item("cop410", index, PC); state_save_register_item("cop410", index, R.PREVPC); state_save_register_item("cop410", index, A); state_save_register_item("cop410", index, B); state_save_register_item("cop410", index, C); state_save_register_item("cop410", index, EN); state_save_register_item("cop410", index, G); state_save_register_item("cop410", index, Q); state_save_register_item("cop410", index, SA); state_save_register_item("cop410", index, SB); state_save_register_item("cop410", index, SIO); state_save_register_item("cop410", index, SKL); state_save_register_item("cop410", index, skip); state_save_register_item("cop410", index, skipLBI); state_save_register_item("cop410", index, R.G_mask); state_save_register_item("cop410", index, R.D_mask); state_save_register_item("cop410", index, R.last_si); }
void sound_init(running_machine *machine) { sound_private *global; const char *filename; machine->sound_data = global = auto_alloc_clear(machine, sound_private); /* handle -nosound */ global->nosound_mode = !options_get_bool(machine->options(), OPTION_SOUND); if (global->nosound_mode) machine->sample_rate = 11025; /* count the speakers */ VPRINTF(("total speakers = %d\n", speaker_output_count(machine->config))); /* allocate memory for mix buffers */ global->leftmix = auto_alloc_array(machine, INT32, machine->sample_rate); global->rightmix = auto_alloc_array(machine, INT32, machine->sample_rate); global->finalmix = auto_alloc_array(machine, INT16, machine->sample_rate); /* allocate a global timer for sound timing */ global->update_timer = timer_alloc(machine, sound_update, NULL); timer_adjust_periodic(global->update_timer, STREAMS_UPDATE_ATTOTIME, 0, STREAMS_UPDATE_ATTOTIME); /* finally, do all the routing */ VPRINTF(("route_sound\n")); route_sound(machine); /* open the output WAV file if specified */ filename = options_get_string(machine->options(), OPTION_WAVWRITE); if (filename[0] != 0) global->wavfile = wav_open(filename, machine->sample_rate, 2); /* enable sound by default */ global->enabled = TRUE; global->muted = FALSE; sound_set_attenuation(machine, options_get_int(machine->options(), OPTION_VOLUME)); /* register callbacks */ config_register(machine, "mixer", sound_load, sound_save); machine->add_notifier(MACHINE_NOTIFY_PAUSE, sound_pause); machine->add_notifier(MACHINE_NOTIFY_RESUME, sound_resume); machine->add_notifier(MACHINE_NOTIFY_RESET, sound_reset); machine->add_notifier(MACHINE_NOTIFY_EXIT, sound_exit); }
static void sslam_play(const device_config *device, int track, int data) { int status = okim6295_r(device,0); if (data < 0x80) { if (track) { if (sslam_track != data) { sslam_track = data; sslam_bar = 1; if (status & 0x08) okim6295_w(device,0,0x40); okim6295_w(device,0,(0x80 | data)); okim6295_w(device,0,0x81); timer_adjust_periodic(music_timer, ATTOTIME_IN_MSEC(4), 0, ATTOTIME_IN_HZ(250)); /* 250Hz for smooth sequencing */ } } else { if ((status & 0x01) == 0) { okim6295_w(device,0,(0x80 | data)); okim6295_w(device,0,0x11); } else if ((status & 0x02) == 0) { okim6295_w(device,0,(0x80 | data)); okim6295_w(device,0,0x21); } else if ((status & 0x04) == 0) { okim6295_w(device,0,(0x80 | data)); okim6295_w(device,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_w(device,0,data); } }
static READ8_HANDLER ( combasc_YM2203_status_port_0_r ) { static int boost = 1; int status = YM2203_status_port_0_r(machine,0); if (activecpu_get_pc() == 0x334) { if (boost) { boost = 0; timer_adjust_periodic(combasc_interleave_timer, attotime_zero, 0, ATTOTIME_IN_CYCLES(80,1)); } else if (status & 2) { boost = 1; timer_adjust_oneshot(combasc_interleave_timer, attotime_zero, 0); } } return(status); }
static DEVICE_START( timer ) { timer_state *state = get_safe_token(device); char unique_tag[50]; timer_config *config; void *param; /* validate some basic stuff */ assert(device != NULL); assert(device->static_config == NULL); assert(device->inline_config != NULL); assert(device->machine != NULL); assert(device->machine->config != NULL); /* get and validate the configuration */ config = device->inline_config; assert((config->type == TIMER_TYPE_PERIODIC) || (config->type == TIMER_TYPE_SCANLINE)); assert(config->callback != NULL); /* copy the pointer parameter */ state->ptr = config->ptr; /* create the name for save states */ assert(strlen(device->tag) < 30); state_save_combine_module_and_tag(unique_tag, "timer_device", device->tag); /* type based configuration */ switch (config->type) { case TIMER_TYPE_PERIODIC: /* make sure that only the applicable parameters are filled in */ assert(config->screen == NULL); assert(config->first_vpos == 0); assert(config->increment == 0); /* validate that we have at least a start_delay or period */ assert(config->period > 0); /* copy the optional integer parameter */ state->param = config->param; /* convert the start_delay and period into attotime */ state->period = UINT64_ATTOTIME_TO_ATTOTIME(config->period); if (config->start_delay > 0) state->start_delay = UINT64_ATTOTIME_TO_ATTOTIME(config->start_delay); else state->start_delay = attotime_zero; /* register for state saves */ state_save_register_item(unique_tag, 0, state->start_delay.seconds); state_save_register_item(unique_tag, 0, state->start_delay.attoseconds); state_save_register_item(unique_tag, 0, state->period.seconds); state_save_register_item(unique_tag, 0, state->period.attoseconds); state_save_register_item(unique_tag, 0, state->param); /* allocate the backing timer */ param = (void *)device; state->timer = timer_alloc(periodic_timer_device_timer_callback, param); /* finally, start the timer */ timer_adjust_periodic(state->timer, state->start_delay, 0, state->period); break; case TIMER_TYPE_SCANLINE: /* make sure that only the applicable parameters are filled in */ assert(config->start_delay == 0); assert(config->period == 0); assert(config->param == 0); assert(config->first_vpos >= 0); assert(config->increment >= 0); /* allocate the backing timer */ param = (void *)device; state->timer = timer_alloc(scanline_timer_device_timer_callback, param); /* indicate that this will be the first call */ state->first_time = TRUE; /* register for state saves */ state_save_register_item(unique_tag, 0, state->first_time); /* fire it as soon as the emulation starts */ timer_adjust_oneshot(state->timer, attotime_zero, 0); break; default: /* we will never get here */ fatalerror("Unknown timer device type"); break; } }
void timer_reset(emu_timer *which, attotime duration) { timer_adjust_periodic(which, duration, which->param, which->period); }
void _timer_pulse_internal(attotime period, void *ptr, INT32 param, timer_fired_func callback, const char *file, int line, const char *func) { emu_timer *timer = _timer_alloc_common(callback, ptr, file, line, func, FALSE); timer_adjust_periodic(timer, period, param, period); }
void timer_adjust_oneshot(emu_timer *which, attotime duration, INT32 param) { timer_adjust_periodic(which, duration, param, attotime_never); }