public static void timer_list_insert(emu_timer timer1) { int i; int i1 = -1; if (timer1.func == "latch_callback") { int i2 = 1; } if (timer1.func == "cpunum_empty_event_queue") { foreach (emu_timer et in lt) { if (et.func == timer1.func && Attotime.attotime_compare(et.expire, global_basetime) <= 0) { i1 = lt.IndexOf(et); break; } } } if (i1 == -1) { Atime expire = timer1.enabled ? timer1.expire : Attotime.ATTOTIME_NEVER; for (i = 0; i < lt.Count; i++) { if (Attotime.attotime_compare(lt[i].expire, expire) > 0) { break; } } lt.Insert(i, timer1); } }
public static void timer_list_remove(emu_timer timer1) { if (timer1.func == "cpunum_empty_event_queue") { List <emu_timer> lt1 = new List <emu_timer>(); foreach (emu_timer et in lt) { if (et.func == timer1.func && Attotime.attotime_compare(et.expire, timer1.expire) == 0) { lt1.Add(et); } } foreach (emu_timer et1 in lt1) { lt.Remove(et1); } } else { foreach (emu_timer et in lt) { if (et.func == timer1.func) { lt.Remove(et); break; } } } }
public static void timer_adjust_periodic(emu_timer which, Atime start_delay, Atime period) { Atime time = get_current_time(); if (which == callback_timer) { callback_timer_modified = true; } which.enabled = true; if (start_delay.seconds < 0) { start_delay = Attotime.ATTOTIME_ZERO; } which.start = time; which.expire = Attotime.attotime_add(time, start_delay); if (which.expire.attoseconds == 0x003be7e176706f58) { int i1 = 1; } which.period = period; timer_list_remove(which); timer_list_insert(which); if (lt.IndexOf(which) == 0) { if (Cpuexec.activecpu >= 0 && Cpuexec.activecpu < Cpuexec.ncpu) { Cpuexec.activecpu_abort_timeslice(Cpuexec.activecpu); } } }
private static void recompute_speed(Atime emutime) { long delta_emutime; if (speed_last_realtime == 0 || Mame.mame_is_paused()) { speed_last_realtime = Wintime.osd_ticks(); speed_last_emutime = emutime; } delta_emutime = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(emutime, speed_last_emutime)); if (delta_emutime > Attotime.ATTOSECONDS_PER_SECOND / 4) { long realtime = Wintime.osd_ticks(); long delta_realtime = realtime - speed_last_realtime; long tps = Wintime.ticks_per_second; speed_percent = (double)delta_emutime * (double)tps / ((double)delta_realtime * (double)Attotime.ATTOSECONDS_PER_SECOND); speed_last_realtime = realtime; speed_last_emutime = emutime; overall_valid_counter++; if (overall_valid_counter >= 4) { overall_real_ticks += delta_realtime; while (overall_real_ticks >= tps) { overall_real_ticks -= tps; overall_real_seconds++; } overall_emutime = Attotime.attotime_add_attoseconds(overall_emutime, delta_emutime); } } }
public static void replay_portC2() { if (Inptport.bReplayRead) { try { Video.screenstate.frame_number = Mame.brRecord.ReadInt64(); short0_old = Mame.brRecord.ReadInt16(); short1_old = Mame.brRecord.ReadInt16(); short2_old = Mame.brRecord.ReadInt16(); } catch { Mame.playState = Mame.PlayState.PLAY_REPLAYEND; //Mame.mame_pause(true); } Inptport.bReplayRead = false; } if (Attotime.attotime_compare(Timer.global_basetime, Timer.global_basetime_obj) == 0) { short0 = short0_old; short1 = short1_old; short2 = short2_old; Inptport.bReplayRead = true; } else { Inptport.bReplayRead = false; } }
private static void adjust_display_position_interrupt_timer() { if ((display_counter + 1) != 0) { Atime period = Attotime.attotime_mul(new Atime(0, Attotime.ATTOSECONDS_PER_SECOND / 6000000), display_counter + 1); Timer.timer_adjust_periodic(display_position_interrupt_timer, period, Attotime.ATTOTIME_NEVER); } }
public static int video_screen_get_vpos() { long delta = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(Timer.get_current_time(), screenstate.vblank_start_time)); int vpos; delta += screenstate.pixeltime / 2; vpos = (int)(delta / screenstate.scantime); return((screenstate.visarea.max_y + 1 + vpos) % screenstate.height); }
private static void TimerHandler_3812(int c, Atime period) { if (Attotime.attotime_compare(period, Attotime.ATTOTIME_ZERO) == 0) { Timer.timer_enable(timer[c], false); } else { Timer.timer_adjust_periodic(timer[c], period, Attotime.ATTOTIME_NEVER); } }
public static uint input_port_read_direct(analog_field_state analog) { uint result; int value; long nsec_since_last; nsec_since_last = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(Timer.get_current_time(), portdata.last_frame_time)) / Attotime.ATTOSECONDS_PER_NANOSECOND; value = (int)(analog.previous + ((long)(analog.accum - analog.previous) * nsec_since_last / portdata.last_delta_nsec)); result = (uint)apply_analog_settings(value); return(result); }
public static Atime cpunum_get_localtime(int cpunum) { Atime result; result = cpu[cpunum].localtime; int cycles; cycles = cpu[cpunum].cycles_running - cpu[cpunum].PendingCycles; result = Attotime.attotime_add(result, new Atime(cycles / cpu[cpunum].cycles_per_second, cycles * cpu[cpunum].attoseconds_per_cycle)); return(result); }
public static void cpu_boost_interleave(Atime timeslice_time, Atime boost_duration) { if (Attotime.attotime_compare(timeslice_time, perfect_interleave) < 0) { timeslice_time = perfect_interleave; } Timer.timer_adjust_periodic(interleave_boost_timer, timeslice_time, timeslice_time); if (!Timer.timer_enabled(interleave_boost_timer_end) || Attotime.attotime_compare(Timer.timer_timeleft(interleave_boost_timer_end), boost_duration) < 0) { Timer.timer_adjust_periodic(interleave_boost_timer_end, boost_duration, Attotime.ATTOTIME_NEVER); } }
private static void update_throttle(Atime emutime) { long real_delta_attoseconds; long emu_delta_attoseconds; long real_is_ahead_attoseconds; long attoseconds_per_tick; long ticks_per_second; long target_ticks; long diff_ticks; ticks_per_second = Wintime.ticks_per_second; attoseconds_per_tick = Attotime.ATTOSECONDS_PER_SECOND / ticks_per_second; if (Mame.mame_is_paused()) { throttle_emutime = Attotime.attotime_sub_attoseconds(emutime, Attotime.ATTOSECONDS_PER_SECOND / PAUSED_REFRESH_RATE); throttle_realtime = throttle_emutime; } emu_delta_attoseconds = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(emutime, throttle_emutime)); if (emu_delta_attoseconds < 0 || emu_delta_attoseconds > Attotime.ATTOSECONDS_PER_SECOND / 10) { goto resync; } diff_ticks = Wintime.osd_ticks() - throttle_last_ticks; throttle_last_ticks += diff_ticks; if (diff_ticks >= ticks_per_second) { goto resync; } real_delta_attoseconds = diff_ticks * attoseconds_per_tick; throttle_emutime = emutime; throttle_realtime = Attotime.attotime_add_attoseconds(throttle_realtime, real_delta_attoseconds); throttle_history = (throttle_history << 1) | Convert.ToUInt32(emu_delta_attoseconds > real_delta_attoseconds); real_is_ahead_attoseconds = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(throttle_emutime, throttle_realtime)); if ((real_is_ahead_attoseconds < -Attotime.ATTOSECONDS_PER_SECOND / 10) || (real_is_ahead_attoseconds < 0 && popcount[throttle_history & 0xff] < 6)) { goto resync; } if (real_is_ahead_attoseconds < 0) { return; } target_ticks = throttle_last_ticks + real_is_ahead_attoseconds / attoseconds_per_tick; diff_ticks = throttle_until_ticks(target_ticks) - throttle_last_ticks; throttle_last_ticks += diff_ticks; throttle_realtime = Attotime.attotime_add_attoseconds(throttle_realtime, diff_ticks * attoseconds_per_tick); return; resync: throttle_realtime = throttle_emutime = emutime; }
public static void watchdog_reset() { if (!watchdog_enabled) { Timer.timer_adjust_periodic(watchdog_timer, Attotime.ATTOTIME_NEVER, Attotime.ATTOTIME_NEVER); } else if (Attotime.attotime_compare(watchdog_time, Attotime.ATTOTIME_ZERO) != 0) { Timer.timer_adjust_periodic(watchdog_timer, watchdog_time, Attotime.ATTOTIME_NEVER); } else { Timer.timer_adjust_periodic(watchdog_timer, new Atime(3, 0), Attotime.ATTOTIME_NEVER); } }
public static void timer_handler1(int count) { if (count == 0) { /* Reset FM Timer */ Timer.timer_enable(timer1, false); } else { /* Start FM Timer */ Atime period = Attotime.attotime_mul(new Atime(0, Attotime.ATTOSECONDS_PER_SECOND / 8000000), (uint)count); if (!Timer.timer_enable(timer1, true)) { Timer.timer_adjust_periodic(timer1, period, Attotime.ATTOTIME_NEVER); } } }
private static void OPL_initalize() { int i; OPL.freqbase = (OPL.rate != 0) ? ((double)OPL.clock / 72.0) / OPL.rate : 0; OPL.TimerBase = Attotime.attotime_mul(Attotime.ATTOTIME_IN_HZ((int)OPL.clock),72); for (i = 0; i < 1024; i++) { OPL.fn_tab[i] = (uint)((double)i * 64 * OPL.freqbase * (1 << (16 - 10))); } OPL.lfo_am_inc = (uint)(0x40000 * OPL.freqbase); OPL.lfo_pm_inc = (uint)(0x4000 * OPL.freqbase); OPL.noise_f = (uint)(0x10000 * OPL.freqbase); OPL.eg_timer_add = (uint)(0x10000 * OPL.freqbase); OPL.eg_timer_overflow = 0x10000; }
/*public static bool video_screen_update_partial(int scanline) * { * new_clip = screenstate.visarea; * bool result = false; * if (screenstate.last_partial_scan > new_clip.min_y) * { * new_clip.min_y = screenstate.last_partial_scan; * } * if (scanline < new_clip.max_y) * { * new_clip.max_y = scanline; * } * if (new_clip.min_y <= new_clip.max_y) * { * video_update_callback(); * result = true; * } * screenstate.last_partial_scan = scanline + 1; * return result; * }*/ /*public static int video_screen_get_vpos() * { * long delta = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(Timer.get_current_time(), screenstate.vblank_start_time)); * int vpos; * delta += screenstate.pixeltime / 2; * vpos = (int)(delta / screenstate.scantime); * return (screenstate.visarea.max_y + 1 + vpos) % screenstate.height; * }*/ public static Atime video_screen_get_time_until_pos(int vpos, int hpos) { long curdelta = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(Timer.get_current_time(), screenstate.vblank_start_time)); long targetdelta; //vpos += screenstate.height - (screenstate.visarea.max_y + 1); vpos %= screenstate.height; targetdelta = vpos * screenstate.scantime + hpos * screenstate.pixeltime; if (targetdelta <= curdelta + screenstate.pixeltime / 2) { targetdelta += screenstate.frame_period; } while (targetdelta <= curdelta) { targetdelta += screenstate.frame_period; } return(new Atime(0, targetdelta - curdelta)); }
public static void recalc_timer(int i) { long period = (long)(1000000000 * timer[i].scale * timer[i].preset / 33868800); if (period != 0) { period = (long)(1000000000 / 62.8206); } if (timer[i].period != period) { timer[i].period = period; if (period != 0) { Timer.timer_adjust_periodic(timer[i].timer, Attotime.ATTOTIME_IN_NSEC(period), Attotime.ATTOTIME_IN_NSEC(period)); } else { Timer.timer_adjust_periodic(timer[i].timer, Attotime.ATTOTIME_NEVER, Attotime.ATTOTIME_NEVER); } } }
private static void frame_update() { Atime curtime = Timer.get_current_time(); portdata.last_delta_nsec = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(curtime, portdata.last_frame_time)) / Attotime.ATTOSECONDS_PER_NANOSECOND; portdata.last_frame_time = curtime; if (Mame.playState != Mame.PlayState.PLAY_REPLAYRUNNING) { if (Mame.is_foreground) { loop_inputports_callback(); } /*int i1 = (int)(Video.screenstate.frame_number % 4); * if (i1 == 0) * { * CPS.short1 = unchecked((short)0xfffb); * } * else if (i1 == 1) * { * CPS.short1 = unchecked((short)0xffce); * } * else if (i1 == 2) * { * CPS.short1 = unchecked((short)0xfff7); * } * else if (i1 == 3) * { * CPS.short1 = unchecked((short)0xffcd); * }*/ } if (Mame.playState == Mame.PlayState.PLAY_RECORDRUNNING) { record_port_callback(); } else if (Mame.playState == Mame.PlayState.PLAY_REPLAYRUNNING) { replay_port_callback(); } }
public static void m92_spritecontrol_w(int offset, byte data) { m92_spritecontrol[offset] = (byte)data; if (offset * 2 == 2) { if ((data & 0xff) == 8) { m92_sprite_list = (((0x100 - m92_spritecontrol[0]) & 0xff) * 4); } else { m92_sprite_list = 0x400; } } if (offset * 2 == 4) { Generic.buffer_spriteram16_w(); m92_sprite_buffer_busy = 0; Timer.emu_timer timer = Timer.timer_alloc_common(spritebuffer_callback, "spritebuffer_callback", true); Timer.timer_adjust_periodic(timer, Attotime.attotime_mul(new Atime(0, (long)(1e18 / 26666000)), 0x400), Attotime.ATTOTIME_NEVER); } }
private static void frame_update() { Atime curtime = Timer.get_current_time(); portdata.last_delta_nsec = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(curtime, portdata.last_frame_time)) / Attotime.ATTOSECONDS_PER_NANOSECOND; portdata.last_frame_time = curtime; if (Mame.playState != Mame.PlayState.PLAY_REPLAYRUNNING) { if (Mame.is_foreground) { loop_inputports_callback(); } } if (Mame.playState == Mame.PlayState.PLAY_RECORDRUNNING) { record_port_callback(); } else if (Mame.playState == Mame.PlayState.PLAY_REPLAYRUNNING) { replay_port_callback(); } }
public static void timer_set_global_time(Atime newbase) { emu_timer timer; global_basetime = newbase; while (Attotime.attotime_compare(lt[0].expire, global_basetime) <= 0) { bool was_enabled = lt[0].enabled; timer = lt[0]; if (Attotime.attotime_compare(timer.period, Attotime.ATTOTIME_ZERO) == 0 || Attotime.attotime_compare(timer.period, Attotime.ATTOTIME_NEVER) == 0) { timer.enabled = false; } callback_timer_modified = false; callback_timer = timer; callback_timer_expire_time = timer.expire; if (was_enabled && (timer.action != null && timer.action != Cpuexec.null_callback)) { timer.action(); } callback_timer = null; if (callback_timer_modified == false) { if (timer.temporary) { timer_list_remove(timer); } else { timer.start = timer.expire; timer.expire = Attotime.attotime_add(timer.expire, timer.period); timer_list_remove(timer); timer_list_insert(timer); } } } }
public static void cpuexec_timeslice() { StreamWriter sw2 = null; Atime target = Timer.lt[0].expire; Atime tbase = Timer.global_basetime; int ran; Atime at; for (icpu = 0; icpu < ncpu; icpu++) { cpu[icpu].suspend = cpu[icpu].nextsuspend; cpu[icpu].eatcycles = cpu[icpu].nexteatcycles; } for (icpu = 0; icpu < ncpu; icpu++) { if (cpu[icpu].suspend == 0) { at = Attotime.attotime_sub(target, cpu[icpu].localtime); cpu[icpu].cycles_running = (int)(at.seconds * cpu[icpu].cycles_per_second + at.attoseconds / cpu[icpu].attoseconds_per_cycle); if (cpu[icpu].cycles_running > 0) { cpu[icpu].cycles_stolen = 0; activecpu = icpu; ran = cpu[icpu].ExecuteCycles(cpu[icpu].cycles_running); activecpu = -1; ran -= cpu[icpu].cycles_stolen; cpu[icpu].totalcycles += (ulong)ran; cpu[icpu].localtime = Attotime.attotime_add(cpu[icpu].localtime, new Atime(ran / cpu[icpu].cycles_per_second, ran * cpu[icpu].attoseconds_per_cycle)); if (Attotime.attotime_compare(cpu[icpu].localtime, target) < 0) { if (Attotime.attotime_compare(cpu[icpu].localtime, tbase) > 0) { target = cpu[icpu].localtime; } else { target = tbase; } } } } } for (icpu = 0; icpu < ncpu; icpu++) { if (cpu[icpu].suspend != 0 && cpu[icpu].eatcycles != 0 && Attotime.attotime_compare(cpu[icpu].localtime, target) < 0) { at = Attotime.attotime_sub(target, cpu[icpu].localtime); cpu[icpu].cycles_running = (int)(at.seconds * cpu[icpu].cycles_per_second + at.attoseconds / cpu[icpu].attoseconds_per_cycle); cpu[icpu].totalcycles += (ulong)cpu[icpu].cycles_running; cpu[icpu].localtime = Attotime.attotime_add(cpu[icpu].localtime, new Atime(cpu[icpu].cycles_running / cpu[icpu].cycles_per_second, cpu[icpu].cycles_running * cpu[icpu].attoseconds_per_cycle)); } cpu[icpu].suspend = cpu[icpu].nextsuspend; cpu[icpu].eatcycles = cpu[icpu].nexteatcycles; } Timer.timer_set_global_time(target); /* if (Timer.global_basetime.attoseconds == 0 && Machine.FORM.cheatform.lockState == cheatForm.LockState.LOCK_SECOND) * { * Machine.FORM.cheatform.ApplyCheat(); * }*/ }
public static Atime timer_timeleft(emu_timer which) { return(Attotime.attotime_sub(which.expire, get_current_time())); }
public static void cpunum_empty_event_queue() { List <irq> lsirq = new List <irq>(); foreach (irq irq1 in lirq) { if (Attotime.attotime_compare(irq1.time, Timer.global_basetime) <= 0) { if (irq1.line == (int)LineState.INPUT_LINE_RESET) { if (irq1.state == LineState.ASSERT_LINE) { Cpuexec.cpunum_suspend(irq1.cpunum, Cpuexec.SUSPEND_REASON_RESET, 1); } else { if ((irq1.state == LineState.CLEAR_LINE && Cpuexec.cpunum_is_suspended(irq1.cpunum, Cpuexec.SUSPEND_REASON_RESET)) || irq1.state == LineState.PULSE_LINE) { Cpuexec.cpu[irq1.cpunum].Reset(); } Cpuexec.cpunum_resume(irq1.cpunum, Cpuexec.SUSPEND_REASON_RESET); } } else if (irq1.line == (int)LineState.INPUT_LINE_HALT) { if (irq1.state == LineState.ASSERT_LINE) { Cpuexec.cpunum_suspend(irq1.cpunum, Cpuexec.SUSPEND_REASON_HALT, 1); } else if (irq1.state == LineState.CLEAR_LINE) { Cpuexec.cpunum_resume(irq1.cpunum, Cpuexec.SUSPEND_REASON_HALT); } } else { switch (irq1.state) { case LineState.PULSE_LINE: Cpuexec.cpu[irq1.cpunum].set_irq_line(irq1.line, LineState.ASSERT_LINE); Cpuexec.cpu[irq1.cpunum].set_irq_line(irq1.line, LineState.CLEAR_LINE); break; case LineState.HOLD_LINE: case LineState.ASSERT_LINE: Cpuexec.cpu[irq1.cpunum].set_irq_line(irq1.line, LineState.ASSERT_LINE); break; case LineState.CLEAR_LINE: Cpuexec.cpu[irq1.cpunum].set_irq_line(irq1.line, LineState.CLEAR_LINE); break; } } lsirq.Add(irq1); } } foreach (irq irq1 in lsirq) { lirq.Remove(irq1); } }
private static int NEOGEO_VBLANK_RELOAD_HPOS = 0x11f; //287 public static void video_init() { Wintime.wintime_init(); global_throttle = true; //UI.ui_handler_callback = UI.handler_ingame; sDrawText = ""; popup_text_end = 0; popcount = new int[256] { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 }; switch (Machine.sBoard) { case "CPS-1": //case "CPS-1(QSound)": screenstate.width = 0x200; screenstate.height = 0x100; //screenstate.visarea.min_x = 0; //screenstate.visarea.max_x = 0x1ff; //screenstate.visarea.min_y = 0; //screenstate.visarea.max_y = 0x1ff; fullwidth = 0x200; fullheight = 0x200; frame_update_time = new Atime(0, (long)(1e18 / 59.61));//59.61Hz screenstate.vblank_period = 0; // bitmapGDI = new Bitmap(Video.fullwidth, Video.fullheight); // UI.ui_update_callback = UI.ui_updateC; bitmapbase = new ushort[2][]; bitmapbase[0] = new ushort[0x200 * 0x200]; bitmapbase[1] = new ushort[0x200 * 0x200]; // bbmp = new Bitmap[3]; // bbmp[0] = new Bitmap(512, 512); // bbmp[1] = new Bitmap(512, 256); // bbmp[2] = new Bitmap(384, 224); video_update_callback = CPS.video_update_cps1; video_eof_callback = CPS.video_eof_cps1; break; /*case "CPS2": * screenstate.width = 0x200; * screenstate.height = 0x100; * screenstate.visarea.min_x = 0; * screenstate.visarea.max_x = 0x1ff; * screenstate.visarea.min_y = 0; * screenstate.visarea.max_y = 0x1ff; * fullwidth = 0x200; * fullheight = 0x200; * frame_update_time = new Atime(0, (long)(1e18 / 8000000) * 512 * 262);//59.637404580152669Hz * screenstate.vblank_period = 0; * bitmapGDI = new Bitmap(Video.fullwidth, Video.fullheight); * UI.ui_update_callback = UI.ui_updateC; * bitmapbase = new ushort[2][]; * bitmapbase[0] = new ushort[0x200 * 0x200]; * bitmapbase[1] = new ushort[0x200 * 0x200]; * bbmp = new Bitmap[3]; * bbmp[0] = new Bitmap(512, 512); * bbmp[1] = new Bitmap(512, 256); * bbmp[2] = new Bitmap(384, 224); * video_update_callback = CPS.video_update_cps1; * video_eof_callback = CPS.video_eof_cps1; * break; * case "Neo Geo": * screenstate.width = 384; * screenstate.height = 264; * screenstate.visarea.min_x = NEOGEO_HBEND;//30 * screenstate.visarea.max_x = NEOGEO_HBSTART - 1;//349 * screenstate.visarea.min_y = NEOGEO_VBEND;//16 * screenstate.visarea.max_y = NEOGEO_VBSTART - 1;//239 * fullwidth = 384; * fullheight = 264; * frame_update_time = new Atime(0, (long)(1e18 / 6000000) * screenstate.width * screenstate.height);//59.1856060608428Hz * screenstate.vblank_period = (long)(1e18 / 6000000) * 384 * (264 - 224); * UI.ui_update_callback = UI.ui_updateN; * bitmapbaseN = new int[2][]; * bitmapbaseN[0] = new int[384 * 264]; * bitmapbaseN[1] = new int[384 * 264]; * bbmp = new Bitmap[1]; * bbmp[0] = new Bitmap(320, 224); * video_update_callback = Neogeo.video_update_neogeo; * video_eof_callback = Neogeo.video_eof_neogeo; * break; * case "Namco System 1": * screenstate.width = 0x200; * screenstate.height = 0x200; * screenstate.visarea.min_x = 0; * screenstate.visarea.max_x = 0x1ff; * screenstate.visarea.min_y = 0; * screenstate.visarea.max_y = 0x1ff; * fullwidth = 0x200; * fullheight = 0x200; * frame_update_time = new Atime(0, (long)(1e18 / 60.606060)); * screenstate.vblank_period = 0; * UI.ui_update_callback = UI.ui_updateNa; * bitmapGDI = new Bitmap(Video.fullwidth, Video.fullheight); * bitmapbase = new ushort[2][]; * bitmapbase[0] = new ushort[0x200 * 0x200]; * bitmapbase[1] = new ushort[0x200 * 0x200]; * bbmp = new Bitmap[2]; * bbmp[0] = new Bitmap(512, 512); * bbmp[1] = new Bitmap(288, 224); * video_update_callback = Namcos1.video_update_namcos1; * video_eof_callback = Namcos1.video_eof_namcos1; * break; * case "IGS011": * screenstate.width = 0x200; * screenstate.height = 0x100; * screenstate.visarea.min_x = 0; * screenstate.visarea.max_x = 0x1ff; * screenstate.visarea.min_y = 0; * screenstate.visarea.max_y = 0xff; * fullwidth = 0x200; * fullheight = 0x200; * frame_update_time = new Atime(0, (long)(1e18 / 60)); * screenstate.vblank_period = 0; * UI.ui_update_callback = UI.ui_updateIGS011; * bitmapGDI = new Bitmap(Video.fullwidth, Video.fullheight); * bitmapbase = new ushort[2][]; * bitmapbase[0] = new ushort[0x200 * 0x200]; * bitmapbase[1] = new ushort[0x200 * 0x200]; * bbmp = new Bitmap[1]; * bbmp[0] = new Bitmap(512, 240); * video_update_callback = IGS011.video_update_igs011; * video_eof_callback = IGS011.video_eof_igs011; * break; * case "PGM": * screenstate.width = 0x200; * screenstate.height = 0x200; * screenstate.visarea.min_x = 0; * screenstate.visarea.max_x = 0x1bf; * screenstate.visarea.min_y = 0; * screenstate.visarea.max_y = 0xdf; * fullwidth = 0x200; * fullheight = 0x200; * frame_update_time = new Atime(0, (long)(1e18 / 60)); * screenstate.vblank_period = 0; * UI.ui_update_callback = UI.ui_updatePGM; * bitmapGDI = new Bitmap(Video.fullwidth, Video.fullheight); * bitmapbase = new ushort[2][]; * bitmapbase[0] = new ushort[0x200 * 0x200]; * bitmapbase[1] = new ushort[0x200 * 0x200]; * bbmp = new Bitmap[1]; * bbmp[0] = new Bitmap(448, 224); * video_update_callback = PGM.video_update_pgm; * video_eof_callback = PGM.video_eof_pgm; * break; * case "M72": * screenstate.width = 0x200; * screenstate.height = 0x11c; * screenstate.visarea.min_x = 0x40; * screenstate.visarea.max_x = 0x1bf; * screenstate.visarea.min_y = 0; * screenstate.visarea.max_y = 0xff; * fullwidth = 0x200; * fullheight = 0x200; * frame_update_time = new Atime(0, (long)(1e18 / 8000000) * screenstate.width * screenstate.height); * screenstate.vblank_period = (long)(1e18 / 8000000) * 512 * (284 - 256); * UI.ui_update_callback = UI.ui_updatePGM; * bitmapbase = new ushort[2][]; * bitmapbase[0] = new ushort[0x200 * 0x200];//0x11c * bitmapbase[1] = new ushort[0x200 * 0x200];//0x11c * bbmp = new Bitmap[1]; * bbmp[0] = new Bitmap(512, 284); * video_update_callback = M72.video_update_m72; * video_eof_callback = M72.video_eof_m72; * break; * case "M92": * screenstate.width = 0x200; * screenstate.height = 0x100; * screenstate.visarea.min_x = 0x50; * screenstate.visarea.max_x = 0x18f; * screenstate.visarea.min_y = 0x8; * screenstate.visarea.max_y = 0xf7; * fullwidth = 0x200; * fullheight = 0x200; * frame_update_time = new Atime(0, (long)(1e18 / 60)); * screenstate.vblank_period = 0; * UI.ui_update_callback = UI.ui_updatePGM; * bitmapbase = new ushort[2][]; * bitmapbase[0] = new ushort[0x200 * 0x200]; * bitmapbase[1] = new ushort[0x200 * 0x200]; * bbmp = new Bitmap[1]; * bbmp[0] = new Bitmap(0x200, 0x100); * video_update_callback = M92.video_update_m92; * video_eof_callback = M92.video_eof_m92; * break;*/ } screenstate.frame_period = frame_update_time.attoseconds; screenstate.scantime = screenstate.frame_period / screenstate.height; screenstate.pixeltime = screenstate.frame_period / (screenstate.height * screenstate.width); screenstate.frame_number = 0; // bitmapGDI = new Bitmap(Video.fullwidth, Video.fullheight); bitmapcolor = new int[Video.fullwidth * Video.fullheight]; vblank_begin_timer = Timer.timer_alloc_common(vblank_begin_callback, "vblank_begin_callback", false); Timer.timer_adjust_periodic(vblank_begin_timer, frame_update_time, Attotime.ATTOTIME_NEVER); scanline0_timer = Timer.timer_alloc_common(scanline0_callback, "scanline0_callback", false); Timer.timer_adjust_periodic(scanline0_timer, video_screen_get_time_until_pos(0, 0), Attotime.ATTOTIME_NEVER); switch (Machine.sBoard) { case "CPS-1": case "CPS-1(QSound)": case "Namco System 1": break; case "CPS2": Cpuexec.cpu[0].partial_frame_period = Attotime.attotime_div(Video.frame_update_time, 262); Cpuexec.cpu[0].partial_frame_timer = Timer.timer_alloc_common(Cpuexec.trigger_partial_frame_interrupt, "trigger_partial_frame_interrupt", false); break; case "Neo Geo": break; case "IGS011": Cpuexec.cpu[0].partial_frame_period = Attotime.attotime_div(Video.frame_update_time, 5); Cpuexec.cpu[0].partial_frame_timer = Timer.timer_alloc_common(Cpuexec.trigger_partial_frame_interrupt, "trigger_partial_frame_interrupt", false); break; case "M72": Cpuexec.cpu[1].partial_frame_period = Attotime.attotime_div(Video.frame_update_time, 128); Cpuexec.cpu[1].partial_frame_timer = Timer.timer_alloc_common(Cpuexec.trigger_partial_frame_interrupt, "trigger_partial_frame_interrupt", false); break; } screenstate.vblank_start_time = Attotime.ATTOTIME_ZERO; }
static void OPLWriteReg(int r,int v) { int slot; int block_fnum; r &= 0xff; v &= 0xff; switch (r & 0xe0) { case 0x00: switch (r & 0x1f) { case 0x01: if ((OPL.type & 0x01) != 0) { OPL.wavesel = (byte)(v & 0x20); } break; case 0x02: OPL.T[0] = (uint)((256 - v) * 4); break; case 0x03: OPL.T[1] = (uint)((256 - v) * 16); break; case 0x04: if ((v & 0x80) != 0) { OPL_STATUS_RESET(0x7f - 0x08); } else { byte st1 = (byte)(v & 1); byte st2 = (byte)((v >> 1) & 1); OPL_STATUS_RESET(v & (0x78 - 0x08)); OPL_STATUSMASK_SET((~v) & 0x78); if (OPL.st[1] != st2) { Atime period = st2 != 0 ? Attotime.attotime_mul(OPL.TimerBase,OPL.T[1]) : Attotime.ATTOTIME_ZERO; OPL.st[1] = st2; if (OPL.timer_handler != null) { //(OPL.timer_handler)(OPL.TimerParam,1,period); } } if (OPL.st[0] != st1) { Atime period = st1 != 0 ? Attotime.attotime_mul(OPL.TimerBase,OPL.T[0]) : Attotime.ATTOTIME_ZERO; OPL.st[0] = st1; if (OPL.timer_handler != null) { //(OPL.timer_handler)(OPL.TimerParam,0,period); } } } break; case 0x08: OPL.mode = (byte)v; break; default: break; } break; case 0x20: slot = slot_array[r & 0x1f]; if (slot < 0) { return; } set_mul(slot,v); break; case 0x40: slot = slot_array[r & 0x1f]; if (slot < 0) { return; } set_ksl_tl(slot,v); break; case 0x60: slot = slot_array[r & 0x1f]; if (slot < 0) { return; } set_ar_dr(slot,v); break; case 0x80: slot = slot_array[r & 0x1f]; if (slot < 0) { return; } set_sl_rr(slot,v); break; case 0xa0: if (r == 0xbd) { OPL.lfo_am_depth = (byte)(v & 0x80); OPL.lfo_pm_depth_range = (byte)((v & 0x40) != 0 ? 8 : 0); OPL.rhythm = (byte)(v & 0x3f); if ((OPL.rhythm & 0x20) != 0) { if ((v & 0x10) != 0) { FM_KEYON(6,0,2); FM_KEYON(6,0,2); } else { FM_KEYOFF(6,0,unchecked((uint)(~2))); FM_KEYOFF(6,0,unchecked((uint)(~2))); } if ((v & 0x01) != 0) { FM_KEYON(7,0,2); } else { FM_KEYOFF(7,0,unchecked((uint)(~2))); } if ((v & 0x08) != 0) { FM_KEYON(7,1,2); } else { FM_KEYOFF(7,1,unchecked((uint)(~2))); } if ((v & 0x04) != 0) { FM_KEYON(8,0,2); } else { FM_KEYOFF(8,0,unchecked((uint)(~2))); } if ((v & 0x02) != 0) { FM_KEYON(8,1,2); } else { FM_KEYOFF(8,1,unchecked((uint)(~2))); } } else { FM_KEYOFF(6,0,unchecked((uint)(~2))); FM_KEYOFF(6,1,unchecked((uint)(~2))); FM_KEYOFF(7,0,unchecked((uint)(~2))); FM_KEYOFF(7,1,unchecked((uint)(~2))); FM_KEYOFF(8,0,unchecked((uint)(~2))); FM_KEYOFF(8,1,unchecked((uint)(~2))); } return; } if ((r & 0x0f) > 8) { return; } if ((r & 0x10) == 0) { block_fnum = (int)((OPL.P_CH[r & 0x0f].block_fnum & 0x1f00) | (uint)v); } else { block_fnum = (int)((uint)((v & 0x1f) << 8) | (OPL.P_CH[r & 0x0f].block_fnum & 0xff)); if ((v & 0x20) != 0) { FM_KEYON(r & 0x0f,0,1); FM_KEYON(r & 0x0f,1,1); } else { FM_KEYOFF(r & 0x0f,0,unchecked((uint)(~1))); FM_KEYOFF(r & 0x0f,1,unchecked((uint)(~1))); } } if (OPL.P_CH[r & 0x0f].block_fnum != block_fnum) { byte block = (byte)(block_fnum >> 10); OPL.P_CH[r & 0x0f].block_fnum = (uint)block_fnum; OPL.P_CH[r & 0x0f].ksl_base = ksl_tab[block_fnum >> 6]; OPL.P_CH[r & 0x0f].fc = OPL.fn_tab[block_fnum & 0x03ff] >> (7 - block); OPL.P_CH[r & 0x0f].kcode = (byte)((OPL.P_CH[r & 0x0f].block_fnum & 0x1c00) >> 9); if ((OPL.mode & 0x40) != 0) { OPL.P_CH[r & 0x0f].kcode |= (byte)((OPL.P_CH[r & 0x0f].block_fnum & 0x100) >> 8); } else { OPL.P_CH[r & 0x0f].kcode |= (byte)((OPL.P_CH[r & 0x0f].block_fnum & 0x200) >> 9); } OPL.P_CH[r & 0x0f].SLOT[0].TLL = (int)(OPL.P_CH[r & 0x0f].SLOT[0].TL + (OPL.P_CH[r & 0x0f].ksl_base >> OPL.P_CH[r & 0x0f].SLOT[0].ksl)); OPL.P_CH[r & 0x0f].SLOT[1].TLL = (int)(OPL.P_CH[r & 0x0f].SLOT[1].TL + (OPL.P_CH[r & 0x0f].ksl_base >> OPL.P_CH[r & 0x0f].SLOT[1].ksl)); CALC_FCSLOT(r & 0x0f,0); CALC_FCSLOT(r & 0x0f,1); } break; case 0xc0: if ((r & 0x0f) > 8) { return; } OPL.P_CH[r & 0x0f].SLOT[0].FB = (byte)(((v >> 1) & 7) != 0 ? ((v >> 1) & 7) + 7 : 0); OPL.P_CH[r & 0x0f].SLOT[0].CON = (byte)(v & 1); OPL.P_CH[r & 0x0f].SLOT[0].iconnect = OPL.P_CH[r & 0x0f].SLOT[0].CON != 0 ? 1 : 2; break; case 0xe0: if (OPL.wavesel != 0) { slot = slot_array[r & 0x1f]; if (slot < 0) { return; } OPL.P_CH[slot / 2].SLOT[slot & 1].wavetable = (ushort)((v & 0x03) * 0x400); } break; } }
private static int NEOGEO_VBLANK_RELOAD_HPOS = 0x11f; //287 public static void video_init() { Wintime.wintime_init(); global_throttle = true; UI.ui_handler_callback = UI.handler_ingame; sDrawText = ""; popup_text_end = 0; popcount = new int[256] { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 }; switch (Machine.sBoard) { case "CPS-1": case "CPS-1(QSound)": screenstate.visarea.min_x = 0; screenstate.visarea.max_x = 0x1ff; screenstate.visarea.min_y = 0; screenstate.visarea.max_y = 0x1ff; fullwidth = 0x200; fullheight = 0x200; frame_update_time = new Atime(0, (long)(1e18 / 59.61));//59.61Hz bitmapGDI = new Bitmap(Video.fullwidth, Video.fullheight); UI.ui_update_callback = UI.ui_updateC; bitmapbaseC = new ushort[2][]; bitmapbaseC[0] = new ushort[0x200 * 0x200]; bitmapbaseC[1] = new ushort[0x200 * 0x200]; bbmp = new Bitmap[3]; bbmp[0] = new Bitmap(512, 512); bbmp[1] = new Bitmap(512, 256); bbmp[2] = new Bitmap(384, 224); video_update_callback = CPS.video_update_cps1; video_eof_callback = CPS.video_eof_cps1; break; case "CPS2": fullwidth = 0x200; fullheight = 0x200; frame_update_time = new Atime(0, (long)(1e18 / 8000000) * 512 * 262);//59.637404580152669Hz bitmapGDI = new Bitmap(Video.fullwidth, Video.fullheight); UI.ui_update_callback = UI.ui_updateC; bitmapbaseC = new ushort[2][]; bitmapbaseC[0] = new ushort[0x200 * 0x200]; bitmapbaseC[1] = new ushort[0x200 * 0x200]; bbmp = new Bitmap[3]; bbmp[0] = new Bitmap(512, 512); bbmp[1] = new Bitmap(512, 256); bbmp[2] = new Bitmap(384, 224); video_update_callback = CPS.video_update_cps1; video_eof_callback = CPS.video_eof_cps1; break; case "Neo Geo": screenstate.width = 384; screenstate.height = 264; screenstate.visarea.min_x = NEOGEO_HBEND; //30 screenstate.visarea.max_x = NEOGEO_HBSTART - 1; //349 screenstate.visarea.min_y = NEOGEO_VBEND; //16 screenstate.visarea.max_y = NEOGEO_VBSTART - 1; //239 fullwidth = 384; fullheight = 264; screenstate.frame_period = (long)(1e18 / 6000000) * screenstate.width * screenstate.height; screenstate.scantime = (long)(1e18 / 6000000) * screenstate.width; screenstate.pixeltime = (long)(1e18 / 6000000); frame_update_time = new Atime(0, (long)(1e18 / 6000000) * 384 * 264);//59.1856060608428Hz UI.ui_update_callback = UI.ui_updateN; bitmapbaseN = new int[2][]; bitmapbaseN[0] = new int[384 * 264]; bitmapbaseN[1] = new int[384 * 264]; bbmp = new Bitmap[1]; bbmp[0] = new Bitmap(320, 224); video_update_callback = Neogeo.video_update_neogeo; video_eof_callback = Neogeo.video_eof_neogeo; break; case "Namco System 1": screenstate.visarea.min_x = 0; screenstate.visarea.max_x = 0x1ff; screenstate.visarea.min_y = 0; screenstate.visarea.max_y = 0x1ff; fullwidth = 0x200; fullheight = 0x200; frame_update_time = new Atime(0, (long)(1e18 / 60.606060)); UI.ui_update_callback = UI.ui_updateNa; bitmapGDI = new Bitmap(Video.fullwidth, Video.fullheight); bitmapbaseNa = new ushort[2][]; bitmapbaseNa[0] = new ushort[0x200 * 0x200]; bitmapbaseNa[1] = new ushort[0x200 * 0x200]; bbmp = new Bitmap[2]; bbmp[0] = new Bitmap(512, 512); bbmp[1] = new Bitmap(288, 224); video_update_callback = Namcos1.video_update_namcos1; video_eof_callback = Namcos1.video_eof_namcos1; break; case "IGS011": screenstate.visarea.min_x = 0; screenstate.visarea.max_x = 0x1ff; screenstate.visarea.min_y = 0; screenstate.visarea.max_y = 0xff; fullwidth = 0x200; fullheight = 0x200; frame_update_time = new Atime(0, (long)(1e18 / 60)); UI.ui_update_callback = UI.ui_updateIGS011; bitmapGDI = new Bitmap(Video.fullwidth, Video.fullheight); bitmapbaseIGS011 = new ushort[2][]; bitmapbaseIGS011[0] = new ushort[0x200 * 0x200]; bitmapbaseIGS011[1] = new ushort[0x200 * 0x200]; bbmp = new Bitmap[1]; bbmp[0] = new Bitmap(512, 240); video_update_callback = IGS011.video_update_igs011; video_eof_callback = IGS011.video_eof_igs011; break; case "PGM": fullwidth = 0x200; fullheight = 0x200; frame_update_time = new Atime(0, (long)(1e18 / 60)); UI.ui_update_callback = UI.ui_updatePGM; bitmapGDI = new Bitmap(Video.fullwidth, Video.fullheight); bitmapbasePGM = new ushort[2][]; bitmapbasePGM[0] = new ushort[0x200 * 0x200]; bitmapbasePGM[1] = new ushort[0x200 * 0x200]; bbmp = new Bitmap[1]; bbmp[0] = new Bitmap(448, 224); video_update_callback = PGM.video_update_pgm; video_eof_callback = PGM.video_eof_pgm; break; } screenstate.frame_number = 0; bitmapGDI = new Bitmap(Video.fullwidth, Video.fullheight); bitmapcolor = new int[Video.fullwidth * Video.fullheight]; vblank_begin_timer = Timer.timer_alloc_common(vblank_begin_callback, "vblank_begin_callback", false); Timer.timer_adjust_periodic(vblank_begin_timer, frame_update_time, Attotime.ATTOTIME_NEVER); switch (Machine.sBoard) { case "CPS-1": case "CPS-1(QSound)": case "Namco System 1": break; case "CPS2": partial_frame_period = Attotime.attotime_div(Video.frame_update_time, 262); Cpuexec.partial_frame_timer = Timer.timer_alloc_common(Cpuexec.trigger_partial_frame_interrupt, "trigger_partial_frame_interrupt", false); break; case "Neo Geo": Timer.timer_adjust_periodic(vblank_begin_timer, video_screen_get_time_until_pos(screenstate.visarea.max_y + 1, 0), Attotime.ATTOTIME_NEVER); break; case "IGS011": partial_frame_period = Attotime.attotime_div(Video.frame_update_time, 5); Cpuexec.partial_frame_timer = Timer.timer_alloc_common(Cpuexec.trigger_partial_frame_interrupt, "trigger_partial_frame_interrupt", false); break; case "PGM": partial_frame_period = Attotime.attotime_div(Video.frame_update_time, 2); Cpuexec.partial_frame_timer = Timer.timer_alloc_common(Cpuexec.trigger_partial_frame_interrupt, "trigger_partial_frame_interrupt", false); break; } screenstate.vblank_start_time = Attotime.ATTOTIME_ZERO; }