vectrex: More 6522 work and CPU bug fixes

This commit is contained in:
alyosha-tas 2019-05-26 17:19:39 -04:00
parent 05770d88ec
commit c822cf401f
6 changed files with 126 additions and 59 deletions

View File

@ -921,7 +921,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809
result = result.Replace("ix16", "???");
break;
case 0xF:
if ((d >> 5) == 0)
if (((d >> 5) & 3) == 0)
{
byte k = reader(addr++);
bytes.Add(k);

View File

@ -304,7 +304,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809
// Illegal
break;
case 0xF:
if ((Regs[ALU] >> 5) == 0)
if (((Regs[ALU] >> 5) & 3) == 0)
{
PopulateCURINSTR(RD_INC, ALU, PC,
RD_INC_OP, ALU2, PC, SET_ADDR, ADDR, ALU, ALU2,

View File

@ -249,7 +249,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809
}
break;
case WR:
Write_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++], cur_instr[instr_pntr++]);
Write_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]);
break;
case WR_DEC_LO:
Write_Dec_Lo_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]);

View File

@ -29,29 +29,10 @@ namespace BizHawk.Emulation.Common.Components.MC6809
Regs[src]++;
}
public void Write_Func(ushort dest_l, ushort dest_h, ushort src)
public void Write_Func(ushort dest, ushort src)
{
ushort addr = (ushort)(Regs[dest_l] | (Regs[dest_h]) << 8);
if (CDLCallback != null) CDLCallback(addr, eCDLogMemFlags.Write | eCDLogMemFlags.Data);
WriteMemory(addr, (byte)Regs[src]);
}
public void NEG_8_Func(ushort src)
{
int Reg16_d = 0;
Reg16_d -= Regs[src];
FlagC = Regs[src] != 0x0;
FlagZ = (Reg16_d & 0xFF) == 0;
FlagV = Regs[src] == 0x80;
FlagN = (Reg16_d & 0xFF) > 127;
ushort ans = (ushort)(Reg16_d & 0xFF);
// redo for half carry flag
Reg16_d = 0;
Reg16_d -= (Regs[src] & 0xF);
FlagH = Reg16_d.Bit(4);
Regs[src] = ans;
if (CDLCallback != null) CDLCallback(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data);
WriteMemory(Regs[dest], (byte)Regs[src]);
}
public void Write_Dec_Lo_Func(ushort dest, ushort src)
@ -81,6 +62,24 @@ namespace BizHawk.Emulation.Common.Components.MC6809
Regs[dest]++;
}
public void NEG_8_Func(ushort src)
{
int Reg16_d = 0;
Reg16_d -= Regs[src];
FlagC = Regs[src] != 0x0;
FlagZ = (Reg16_d & 0xFF) == 0;
FlagV = Regs[src] == 0x80;
FlagN = (Reg16_d & 0xFF) > 127;
ushort ans = (ushort)(Reg16_d & 0xFF);
// redo for half carry flag
Reg16_d = 0;
Reg16_d -= (Regs[src] & 0xF);
FlagH = Reg16_d.Bit(4);
Regs[src] = ans;
}
public void TR_Func(ushort dest, ushort src)
{
Regs[dest] = Regs[src];

View File

@ -20,10 +20,16 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
public byte portB_ret, portA_ret;
public byte t1_low, t1_high;
public int t1_counter;
public bool t1_on, t1_shot_done;
public bool PB7;
public byte t1_low, t1_high;
public int t1_counter, t1_ctrl;
public bool t1_shot_go;
public byte t2_low, t2_high;
public int t2_counter, t2_ctrl;
public bool t2_shot_go;
public bool PB7, PB6;
public bool PB7_prev, PB6_prev;
public byte int_en, int_fl, aux_ctrl;
@ -67,8 +73,13 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
ret = t1_high;
break;
case 0x8:
ret = (byte)(t2_counter & 0xFF);
int_fl &= 0xDF;
update_int_fl();
break;
case 0x9:
ret = (byte)((t2_counter >> 8) & 0xFF);
break;
case 0xA:
int_fl &= 0xFB;
@ -120,10 +131,11 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
break;
case 0x5:
t1_high = value;
t1_counter = (t1_high << 8) | t1_low;
t1_on = true;
t1_shot_done = false;
t1_shot_go = true;
if (aux_ctrl.Bit(7)) { PB7 = true; }
t1_ctrl = aux_ctrl;
int_fl &= 0xBF;
update_int_fl();
@ -138,8 +150,17 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
update_int_fl();
break;
case 0x8:
t2_low = value;
break;
case 0x9:
t2_high = value;
t2_counter = (t2_high << 8) | t2_low;
t2_shot_go = true;
t2_ctrl = aux_ctrl;
int_fl &= 0xDF;
update_int_fl();
break;
case 0xA:
int_fl &= 0xFB;
@ -166,53 +187,74 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
{
int_en &= (byte)((~value) & 0x7F);
}
update_int_fl();
break;
case 0xF:
break;
}
}
public void Register_Reset()
{
}
public void timer_1_tick()
{
if (t1_on)
t1_counter--;
if (t1_counter < 0)
{
t1_counter--;
if (t1_counter == 0)
if (t1_ctrl.Bit(6))
{
if (aux_ctrl.Bit(6))
{
t1_counter = (t1_high << 8) | t1_low;
t1_counter = (t1_high << 8) | t1_low;
int_fl |= 0x40;
update_int_fl();
//if (int_en.Bit(6)) { cpu.IRQPending = true; }
if (t1_ctrl.Bit(7)) { PB7 = !PB7; }
}
else
{
t1_counter = 0xFFFF;
if (t1_shot_go)
{
int_fl |= 0x40;
update_int_fl();
//if (int_en.Bit(6)) { cpu.IRQPending = true; }
if (t1_ctrl.Bit(7)) { PB7 = false; }
if (aux_ctrl.Bit(7)) { PB7 = !PB7; }
}
else
{
t1_counter = 0xFFFF;
if (!t1_shot_done)
{
int_fl |= 0x40;
//if (int_en.Bit(6)) { cpu.IRQPending = true; }
if (aux_ctrl.Bit(7)) { PB7 = false; }
}
t1_shot_done = true;
}
t1_shot_go = false;
}
}
}
}
public void timer_2_tick()
{
t2_counter--;
if (t2_counter < 0)
{
if (t2_ctrl.Bit(5))
{
t2_counter = (t2_high << 8) | t2_low;
int_fl |= 0x20;
update_int_fl();
//if (int_en.Bit(6)) { cpu.IRQPending = true; }
}
else
{
t2_counter = 0xFFFF;
if (t2_shot_go)
{
int_fl |= 0x20;
update_int_fl();
//if (int_en.Bit(6)) { cpu.IRQPending = true; }
t2_shot_go = false;
}
}
}
}
public void update_int_fl()
@ -227,5 +269,24 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
int_fl |= (byte)(test ? 0x80 : 0);
}
public void Register_Reset()
{
dir_dac = dir_ctrl = 0;
portB_ret = portA_ret = 0;
t1_low = t1_high = 0;
t1_counter = t1_ctrl = 0;
t1_shot_go = false;
PB7 = PB7_prev = false;
t2_low = t2_high = 0;
t2_counter = t2_ctrl = 0;
t2_shot_go = false;
PB6 = PB7_prev = false;
int_en = int_fl = aux_ctrl = 0;
}
}
}

View File

@ -66,9 +66,16 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
ser.Sync(nameof(t1_low), ref t1_low);
ser.Sync(nameof(t1_high), ref t1_high);
ser.Sync(nameof(t1_counter), ref t1_counter);
ser.Sync(nameof(t1_on), ref t1_on);
ser.Sync(nameof(t1_shot_done), ref t1_shot_done);
ser.Sync(nameof(t1_shot_go), ref t1_shot_go);
ser.Sync(nameof(PB7), ref PB7);
ser.Sync(nameof(PB7_prev), ref PB7_prev);
ser.Sync(nameof(t2_low), ref t2_low);
ser.Sync(nameof(t2_high), ref t2_high);
ser.Sync(nameof(t2_counter), ref t2_counter);
ser.Sync(nameof(t2_shot_go), ref t2_shot_go);
ser.Sync(nameof(PB6), ref PB6);
ser.Sync(nameof(PB6_prev), ref PB6_prev);
ser.Sync(nameof(int_en), ref int_en);
ser.Sync(nameof(int_fl), ref int_fl);