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 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 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); } }
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; } }