Vectrex: Hook up audio and fix more bugs

This commit is contained in:
alyosha-tas 2019-06-15 18:39:00 -04:00
parent 6f5d2cf24b
commit c063319816
7 changed files with 89 additions and 30 deletions

View File

@ -139,7 +139,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809
private void INDEX_OP_EX4_ST()
{
PopulateCURINSTR(IDLE,
WR, ALU, IDX_EA, indexed_op_reg);
WR, IDX_EA, indexed_op_reg);
IRQS = 2;
}

View File

@ -259,7 +259,9 @@ namespace BizHawk.Emulation.Common.Components.MC6809
case LEA:
LEA_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]);
break;
case ANDCC:
Regs[CC] &= Regs[instr_pntr++];
break;
}
break;
case WR:

View File

@ -482,7 +482,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809
{
PopulateCURINSTR(RD_INC, ALU, PC,
IDLE,
DEC16, SP,
DEC16, src,
PSH_n, src);
IRQS = -1;

View File

@ -12,12 +12,11 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
{
public VectrexHawk Core { get; set; }
private BlipBuffer _blip_L = new BlipBuffer(15000);
private BlipBuffer _blip_R = new BlipBuffer(15000);
private BlipBuffer _blip = new BlipBuffer(15000);
public uint master_audio_clock;
private short current_sample;
private short current_sample, old_sample;
public byte[] Register = new byte[16];
@ -71,7 +70,11 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
ser.Sync(nameof(noise), ref noise);
ser.Sync(nameof(env_E), ref env_E);
ser.Sync(nameof(E_up_down), ref E_up_down);
ser.Sync(nameof(port_sel), ref port_sel);
ser.Sync(nameof(current_sample), ref current_sample);
ser.Sync(nameof(old_sample), ref old_sample);
ser.Sync(nameof(master_audio_clock), ref master_audio_clock);
sync_psg_state();
@ -145,6 +148,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
public void WriteReg(int addr, byte value)
{
//Console.WriteLine("PORT: " + port_sel + " value: " + value + " cpu: " + Core.cpu.TotalExecutedCycles);
value &= 0xFF;
Register[port_sel] = value;
@ -176,8 +181,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
bool sound_out_C;
psg_clock++;
master_audio_clock++;
if (psg_clock == 8)
if (psg_clock == 1)
{
psg_clock = 0;
@ -294,6 +300,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
}
current_sample = (short)v;
if (current_sample != old_sample)
{
_blip.AddDelta(master_audio_clock, current_sample - old_sample);
old_sample = current_sample;
}
}
}
@ -302,6 +314,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
clock_A = clock_B = clock_C = 0x1000;
noise_clock = 0x20;
port_sel = 0;
current_sample = old_sample = 0;
master_audio_clock = 0;
for (int i = 0; i < 16; i++)
{
@ -309,8 +323,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
}
sync_psg_state();
_blip_L.SetRates(4194304, 44100);
_blip_R.SetRates(4194304, 44100);
_blip.SetRates(1500000, 44100);
}
#region audio
@ -329,19 +342,13 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
public void GetSamplesSync(out short[] samples, out int nsamp)
{
_blip_L.EndFrame(master_audio_clock);
_blip_R.EndFrame(master_audio_clock);
_blip.EndFrame(master_audio_clock);
nsamp = _blip_L.SamplesAvailable();
// only for running without errors, remove this line once you get audio
nsamp = 1;
nsamp = _blip.SamplesAvailable();
samples = new short[nsamp * 2];
// uncomment these once you have audio to play
//_blip_L.ReadSamplesLeft(samples, nsamp);
//_blip_R.ReadSamplesRight(samples, nsamp);
_blip.ReadSamples(samples, nsamp, true);
master_audio_clock = 0;
}
@ -353,8 +360,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
public void DiscardSamples()
{
_blip_L.Clear();
_blip_R.Clear();
_blip.Clear();
master_audio_clock = 0;
}
@ -365,12 +371,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
public void DisposeSound()
{
_blip_L.Clear();
_blip_R.Clear();
_blip_L.Dispose();
_blip_R.Dispose();
_blip_L = null;
_blip_R = null;
_blip.Clear();
_blip.Dispose();
_blip = null;
}
#endregion

View File

@ -32,6 +32,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
public bool PB7, PB6;
public bool PB7_prev, PB6_prev;
// Port B controls
public bool sw, sel0, sel1, bc1, bdir, compare, ramp;
public byte int_en, int_fl, aux_ctrl;
public byte Read_Registers(int addr)
@ -47,7 +50,14 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
update_int_fl();
break;
case 0x1:
if (!bdir && bc1)
{
ret = audio.ReadReg(0);
}
else
{
ret = portA_ret;
}
int_fl &= 0xFC;
update_int_fl();
@ -98,6 +108,10 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
ret = int_en;
break;
case 0xF:
ret = portA_ret;
int_fl &= 0xFC;
update_int_fl();
break;
}
return ret;
@ -114,6 +128,22 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
portB_ret = (byte)(wrt_val | (reg_B & ~(dir_ctrl)));
if (dir_ctrl.Bit(0)) { sw = value.Bit(0); }
if (dir_ctrl.Bit(1)) { sel0 = value.Bit(1); }
if (dir_ctrl.Bit(2)) { sel1 = value.Bit(2); }
if (dir_ctrl.Bit(3)) { bc1 = value.Bit(3); }
if (dir_ctrl.Bit(4)) { bdir = value.Bit(4); }
if (dir_ctrl.Bit(5)) { /*compare = value.Bit(5);*/ }
if (dir_ctrl.Bit(6)) { /* cart bank switch */ }
if (dir_ctrl.Bit(7)) { ramp = !value.Bit(7); }
// writing to sound reg
if (bdir)
{
if (bc1) { audio.port_sel = (byte)(portA_ret & 0xF); }
else { audio.WriteReg(0, portA_ret); }
}
int_fl &= 0xE7;
update_int_fl();
break;
@ -122,16 +152,21 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
portA_ret = (byte)(wrt_val | (reg_A & ~(dir_dac)));
// writing to sound reg
if (bdir)
{
if (bc1) { audio.port_sel = (byte)(portA_ret & 0xf); }
else { audio.WriteReg(0, portA_ret); }
}
int_fl &= 0xFC;
update_int_fl();
break;
case 0x2:
dir_ctrl = value;
Console.WriteLine("dir_ctrl: " + value);
break;
case 0x3:
dir_dac = value;
Console.WriteLine("dir_dac: " + value);
break;
case 0x4:
t1_low = value;
@ -197,6 +232,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
update_int_fl();
break;
case 0xF:
wrt_val = (byte)(value & dir_dac);
portA_ret = (byte)(wrt_val | (reg_A & ~(dir_dac)));
int_fl &= 0xFC;
update_int_fl();
break;
}
}

View File

@ -44,10 +44,11 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
public void do_frame()
{
for (int i = 0; i < 45000; i++)
for (int i = 0; i < 25000; i++)
{
timer_1_tick();
timer_2_tick();
audio.tick();
cpu.ExecuteOne();
}
}

View File

@ -62,6 +62,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
ser.Sync(nameof(portB_ret), ref portB_ret);
ser.Sync(nameof(portA_ret), ref portA_ret);
ser.Sync(nameof(reg_A), ref reg_A);
ser.Sync(nameof(reg_B), ref reg_B);
ser.Sync(nameof(t1_low), ref t1_low);
ser.Sync(nameof(t1_high), ref t1_high);
@ -81,10 +83,20 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
ser.Sync(nameof(int_fl), ref int_fl);
ser.Sync(nameof(aux_ctrl), ref aux_ctrl);
ser.Sync(nameof(sw), ref sw);
ser.Sync(nameof(sel0), ref sel0);
ser.Sync(nameof(sel1), ref sel1);
ser.Sync(nameof(bc1), ref bc1);
ser.Sync(nameof(bdir), ref bdir);
ser.Sync(nameof(compare), ref compare);
ser.Sync(nameof(ramp), ref ramp);
ser.Sync(nameof(_frame), ref _frame);
ser.Sync(nameof(_lagcount), ref _lagcount);
ser.Sync(nameof(_islag), ref _islag);
// probably a better way to do this
if (cart_RAM != null)
{