int wave_status(int id, int newstatus) { /* wave status has the following bitfields: * * Bit 1: Mute (1=mute 0=nomute) * Bit 0: Motor (1=on 0=off) * * Also, you can pass -1 to have it simply return the status */ struct wave_file *w = &wave[id]; if( !w->file ) return 0; if( newstatus != -1 ) { w->mute = newstatus & 2; newstatus &= 1; if( newstatus && !w->timer ) { w->timer = timer_set(TIME_NEVER, 0, NULL); } else if( !newstatus && w->timer ) { if( w->timer ) w->offset += (((float)timer_timeelapsed(w->timer))/(float)TIME_ONE_SEC) * w->smpfreq; timer_remove(w->timer); w->timer = NULL; bitmap_dirty = 1; } } return (w->timer ? 1 : 0) | (w->mute ? 2 : 0); }
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)); } }
int wave_seek(int id, int offset, int whence) { struct wave_file *w = &wave[id]; UINT32 pos = 0; if( !w->file ) return pos; switch( whence ) { case SEEK_SET: w->offset = offset; break; case SEEK_END: w->offset = w->samples - 1; break; case SEEK_CUR: if( w->timer ) pos = w->offset + ((((float)timer_timeelapsed(w->timer))/(float)TIME_ONE_SEC) * w->smpfreq); w->offset = pos + offset; if( w->offset < 0 ) w->offset = 0; if( w->offset >= w->length ) w->offset = w->length - 1; } w->playpos = w->offset; if( w->timer ) { timer_remove(w->timer); w->timer = timer_set(TIME_NEVER, 0, NULL); } return w->offset; }
int cpu_gethorzbeampos(void) { double elapsed_time = timer_timeelapsed(refresh_timer); int scanline = (int)(elapsed_time * scanline_period_inv); double time_since_scanline = elapsed_time - (double)scanline * scanline_period; return (int)(time_since_scanline * scanline_period_inv * (double)Machine->drv->screen_width); }
int wave_input(int id) { struct wave_file *w = &wave[id]; UINT32 pos = 0; int level = 0; if( !w->file ) return level; if( w->channel != -1 ) stream_update(w->channel, 0); if( w->timer ) { pos = w->offset + ((((float)timer_timeelapsed(w->timer))/(float)TIME_ONE_SEC) * w->smpfreq); if( pos >= w->samples ) pos = w->samples - 1; w->playpos = pos; if( w->resolution == 16 ) level = *((INT16 *)w->data + pos); else level = 256 * *((INT8 *)w->data + pos); } if( w->display ) wave_display(id); return level; }
int wave_input_chunk(int id, void *dst, int count) { struct wave_file *w = &wave[id]; UINT32 pos = 0; if( !w->file ) return 0; if( w->timer ) { pos = w->offset + ((((float)timer_timeelapsed(w->timer))/(float)TIME_ONE_SEC) * w->smpfreq); if( pos >= w->samples ) pos = w->samples - 1; } if( pos + count >= w->samples ) count = w->samples - pos - 1; if( count > 0 ) { if( w->resolution == 16 ) memcpy(dst, (INT16 *)w->data + pos, count * sizeof(INT16)); else memcpy(dst, (INT8 *)w->data + pos, count * sizeof(INT8)); } return count; }
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 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)); } }
int cpu_scalebyfcount(int value) { int result = (int)((double)value * timer_timeelapsed(refresh_timer) * refresh_period_inv); if (value >= 0) return (result < value) ? result : value; else return (result > value) ? result : value; }
int sound_scalebufferpos(int value) { double elapsed = timer_timeelapsed(sound_update_timer); if(elapsed < 0.) elapsed = 0.; int result = (int)((double)value * elapsed * refresh_period_inv); if (value >= 0) return (result < value) ? result : value; else return (result > value) ? result : value; }
int activecpu_geticount(void) { int result; /* remove me - only used by mamedbg, m92 */ VERIFY_EXECUTINGCPU(0, cpu_geticount); result = TIME_TO_CYCLES(activecpu, cpu[activecpu].vblankint_period - timer_timeelapsed(cpu[activecpu].vblankint_timer)); return (result < 0) ? 0 : result; }
int wave_tell(int id) { struct wave_file *w = &wave[id]; UINT32 pos = 0; if( w->timer ) pos = w->offset + ((((float)timer_timeelapsed(w->timer))/(float)TIME_ONE_SEC) * w->smpfreq); if( pos >= w->samples ) pos = w->samples -1; return pos; }
static void h8_itu_sync_timers(int tnum) { int ourTCR = 0; double time, cur; static double tscales[4] = { 1.0, 2.0, 4.0, 8.0 }; switch (tnum) { case 0: ourTCR = h8.per_regs[TCR0]; break; case 1: ourTCR = h8.per_regs[TCR1]; break; case 2: ourTCR = h8.per_regs[TCR2]; break; case 3: ourTCR = h8.per_regs[TCR3]; break; case 4: ourTCR = h8.per_regs[TCR4]; break; } // get the time per unit time = (double)TIME_TO_CYCLES(h8.cpu_number, 1) / tscales[ourTCR & 3]; time = 1.0 / time; cur = timer_timeelapsed(h8.timer[tnum]); cur /= time; switch (tnum) { case 0: h8.h8TCNT0 = (UINT16)cur; break; case 1: h8.h8TCNT1 = (UINT16)cur; break; case 2: h8.h8TCNT2 = (UINT16)cur; break; case 3: h8.h8TCNT3 = (UINT16)cur; break; case 4: h8.h8TCNT4 = (UINT16)cur; break; } }
static void via_t2_timeout (int which) { struct via6522 *v = via + which; if (v->intf->t2_callback) v->intf->t2_callback(timer_timeelapsed(v->t2)); v->t2 = 0; v->time2=timer_get_time(); if (!(v->ifr & INT_T2)) via_set_int (v, INT_T2); }
INLINE void count_states(int states) { if (!micro.timer) { micro.timer = timer_set(TIME_NEVER, 0, NULL); micro.endtime = (timer_tm)states * MICRO_STATE_CLOCK_PERIOD; } else if (timer_timeelapsed(micro.timer) > micro.endtime) { timer_reset(micro.timer, TIME_NEVER); micro.endtime = (timer_tm)states * MICRO_STATE_CLOCK_PERIOD; } else micro.endtime += (timer_tm)states * MICRO_STATE_CLOCK_PERIOD; }
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; }
static WRITE8_HANDLER( vc1541_via1_write_portb ) { static int old=0; if (data!=old) { DBG_LOG(1, "vc1541 drive",("%.2x\n", data)); if ((old&3)!=(data&3)) { switch (old&3) { case 0: if ((data&3)==1) vc1541->track+=0.5; else if ((data&3)==3) vc1541->track-=0.5; break; case 1: if ((data&3)==2) vc1541->track+=0.5; else if ((data&3)==0) vc1541->track-=0.5; break; case 2: if ((data&3)==3) vc1541->track+=0.5; else if ((data&3)==1) vc1541->track-=0.5; break; case 3: if ((data&3)==0) vc1541->track+=0.5; else if ((data&3)==2) vc1541->track-=0.5; break; } if (vc1541->track<1) vc1541->track=1.0; if (vc1541->track>35) vc1541->track=35; } if ( (vc1541->motor!=(data&4))||(vc1541->frequency!=(data&0x60)) ) { double tme; vc1541->motor = data & 4; vc1541->frequency = data & 0x60; tme=vc1541_times[vc1541->frequency>>5]*8*2; if (vc1541->motor) { if (timer_timeelapsed(vc1541->timer) > 1.0e29) timer_reset(vc1541->timer, TIME_NEVER); else timer_adjust(vc1541->timer, 0, 0, tme); } else { timer_reset(vc1541->timer, TIME_NEVER); } }
void wave_output(int id, int data) { struct wave_file *w = &wave[id]; UINT32 pos = 0; if( !w->file ) return; if( !w->mode ) return; if( data == w->record_sample ) return; if( w->channel != -1 ) stream_update(w->channel, 0); if( w->timer ) { pos = w->offset + ((((float)timer_timeelapsed(w->timer))/(float)TIME_ONE_SEC) * w->smpfreq); while( pos >= w->samples ) { /* add one second of data */ w->samples += w->smpfreq; w->length = w->samples * w->resolution / 8; w->data = realloc(w->data, w->length); if( !w->data ) { logerror("WAVE realloc(%d) failed\n", w->length); memset(w, 0, sizeof(struct wave_file)); return; } } while( w->playpos < pos ) { *((INT16 *)w->data + w->playpos) = w->record_sample; w->playpos++; } } if( w->display ) wave_display(id); w->record_sample = data; }
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); }
int wave_output_chunk(int id, void *src, int count) { struct wave_file *w = &wave[id]; UINT32 pos = 0; if( !w->file ) return 0; if( w->timer ) { pos = w->offset + ((((float)timer_timeelapsed(w->timer))/(float)TIME_ONE_SEC) * w->smpfreq); if( pos >= w->length ) pos = w->length - 1; } if( pos + count >= w->length ) { /* add space for new data */ w->samples += count - pos; w->length = w->samples * w->resolution / 8; w->data = realloc(w->data, w->length); if( !w->data ) { logerror("WAVE realloc(%d) failed\n", w->length); memset(w, 0, sizeof(struct wave_file)); return 0; } } if( count > 0 ) { if( w->resolution == 16 ) memcpy((INT16 *)w->data + pos, src, count * sizeof(INT16)); else memcpy((INT8 *)w->data + pos, src, count * sizeof(INT8)); } return count; }
int cpu_getscanline(void) { double result = floor(timer_timeelapsed(refresh_timer) * scanline_period_inv); return (int)result; }
attotime timer_device_timeelapsed(running_device *timer) { timer_state *state = get_safe_token(timer); return timer_timeelapsed(state->timer); }
static UINT32 ide_controller_read(struct ide_state *ide, offs_t offset, int size) { UINT32 result = 0; /* logit */ if (offset != IDE_ADDR_DATA && offset != IDE_ADDR_STATUS_COMMAND && offset != IDE_ADDR_STATUS_CONTROL) LOG(("%08X:IDE read at %03X, size=%d\n", activecpu_get_previouspc(), offset, size)); switch (offset) { /* unknown config register */ case IDE_ADDR_CONFIG_UNK: return ide->config_unknown; /* active config register */ case IDE_ADDR_CONFIG_REGISTER: return ide->config_register_num; /* data from active config register */ case IDE_ADDR_CONFIG_DATA: if (ide->config_register_num < IDE_CONFIG_REGISTERS) return ide->config_register[ide->config_register_num]; return 0; /* read data if there's data to be read */ case IDE_ADDR_DATA: if (ide->status & IDE_STATUS_BUFFER_READY) { /* fetch the correct amount of data */ result = ide->buffer[ide->buffer_offset++]; if (size > 1) result |= ide->buffer[ide->buffer_offset++] << 8; if (size > 2) { result |= ide->buffer[ide->buffer_offset++] << 16; result |= ide->buffer[ide->buffer_offset++] << 24; } /* if we're at the end of the buffer, handle it */ if (ide->buffer_offset >= IDE_DISK_SECTOR_SIZE) continue_read(ide); } break; /* return the current error */ case IDE_ADDR_ERROR: return ide->error; /* return the current sector count */ case IDE_ADDR_SECTOR_COUNT: return ide->sector_count; /* return the current sector */ case IDE_ADDR_SECTOR_NUMBER: return ide->cur_sector; /* return the current cylinder LSB */ case IDE_ADDR_CYLINDER_LSB: return ide->cur_cylinder & 0xff; /* return the current cylinder MSB */ case IDE_ADDR_CYLINDER_MSB: return ide->cur_cylinder >> 8; /* return the current head */ case IDE_ADDR_HEAD_NUMBER: return ide->cur_head_reg; /* return the current status and clear any pending interrupts */ case IDE_ADDR_STATUS_COMMAND: /* return the current status but don't clear interrupts */ case IDE_ADDR_STATUS_CONTROL: result = ide->status; if (timer_timeelapsed(ide->last_status_timer) > TIME_PER_ROTATION) { result |= IDE_STATUS_HIT_INDEX; timer_adjust(ide->last_status_timer, TIME_NEVER, 0, 0); } /* clear interrutps only when reading the real status */ if (offset == IDE_ADDR_STATUS_COMMAND) { if (ide->interrupt_pending) clear_interrupt(ide); } /* take a bit of time to speed up people who poll hard */ activecpu_adjust_icount(-100); break; /* log anything else */ default: logerror("%08X:unknown IDE read at %03X, size=%d\n", activecpu_get_previouspc(), offset, size); break; } /* return the result */ return result; }
attotime timer_device_timeelapsed(const device_config *timer) { timer_state *state = get_safe_token(timer); return timer_timeelapsed(state->timer); }