From 9b2d926bc0b8abcf8c363d5004a517ec6b3a4c7c Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Thu, 4 Jul 2019 20:00:59 -0400 Subject: [PATCH 1/6] Vectrex: working controllers --- .../Consoles/GCE/Vectrex/HW_Registers.cs | 94 +++++++++++++++++-- .../GCE/Vectrex/VectrexHawk.IEmulator.cs | 18 ++++ .../GCE/Vectrex/VectrexHawk.IStatable.cs | 6 ++ .../GCE/Vectrex/VectrexHawkControllers.cs | 6 +- 4 files changed, 116 insertions(+), 8 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/HW_Registers.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/HW_Registers.cs index 60b9de2767..26e4a88211 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/HW_Registers.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/HW_Registers.cs @@ -59,7 +59,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex ret = (byte)((portB_ret & 0x7F) | (PB7 ? 0x80 : 0x0)); } - if (!dir_ctrl.Bit(5)) { ret |= (byte)(compare ? 0x0 : 0x20); } + if (!dir_ctrl.Bit(5)) { ret |= (byte)(!compare ? 0x0 : 0x20); } int_fl &= 0xE7; update_int_fl(); @@ -181,8 +181,16 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex { if (sel0) { - if (sel1) {/* sound samples direct to output */ audio.pcm_sample = (short)(portA_ret << 6); } - else { ppu.vec_scale = portA_ret; if (portA_ret != 0) { Console.WriteLine("scale: " + portA_ret); } } + if (sel1) + { + /* sound samples direct to output */ + audio.pcm_sample = (short)(portA_ret << 6); + } + else + { + ppu.vec_scale = portA_ret; + if (portA_ret != 0) { Console.WriteLine("scale: " + portA_ret); } + } } else { @@ -195,7 +203,39 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex ppu.bright = (byte)(portA_ret & 0x3F); ppu.bright_int_3 = (uint)(0xFF000000 | (ppu.bright << 16) | (ppu.bright << 8) | ppu.bright); } - else { ppu.y_vel = (byte)(portA_ret ^ 0x80); } + else + { + ppu.y_vel = (byte)(portA_ret ^ 0x80); + } + } + } + else + { + if (sel0) + { + if (sel1) + { + if (portA_ret >= joy2_UD) { compare = true; } + else { compare = false; } + } + else + { + if (portA_ret >= joy1_UD) { compare = true; } + else { compare = false; } + } + } + else + { + if (sel1) + { + if (portA_ret >= joy2_LR) { compare = true; } + else { compare = false; } + } + else + { + if (portA_ret >= joy1_LR) { compare = true; } + else { compare = false; } + } } } @@ -220,8 +260,16 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex { if (sel0) { - if (sel1) {/* sound samples direct to output */ audio.pcm_sample = (short)(portA_ret << 6); } - else { ppu.vec_scale = portA_ret; if (portA_ret != 0) { Console.WriteLine("scale: " + portA_ret); } } + if (sel1) + { + /* sound samples direct to output */ + audio.pcm_sample = (short)(portA_ret << 6); + } + else + { + ppu.vec_scale = portA_ret; + if (portA_ret != 0) { Console.WriteLine("scale: " + portA_ret); } + } } else { @@ -234,7 +282,39 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex ppu.bright = (byte)(portA_ret & 0x3F); ppu.bright_int_3 = (uint)(0xFF000000 | (ppu.bright << 16) | (ppu.bright << 8) | ppu.bright); } - else { ppu.y_vel = (byte)(portA_ret ^ 0x80); } + else + { + ppu.y_vel = (byte)(portA_ret ^ 0x80); + } + } + } + else + { + if (sel0) + { + if (sel1) + { + if (portA_ret >= joy2_UD) { compare = true; } + else { compare = false; } + } + else + { + if (portA_ret >= joy1_UD) { compare = true; } + else { compare = false; } + } + } + else + { + if (sel1) + { + if (portA_ret >= joy2_LR) { compare = true; } + else { compare = false; } + } + else + { + if (portA_ret >= joy1_LR) { compare = true; } + else { compare = false; } + } } } diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IEmulator.cs index 4a3d10da24..47536693b3 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IEmulator.cs @@ -12,6 +12,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex public ControllerDefinition ControllerDefinition => _controllerDeck.Definition; + byte joy1_LR, joy2_LR, joy1_UD, joy2_UD; + public bool FrameAdvance(IController controller, bool render, bool rendersound) { if (_tracer.Enabled) @@ -37,7 +39,23 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex audio.Register[14] |= (byte)(_controllerDeck.ReadPort2(controller) << 4); // joystick position is based on pot reading + joy1_LR = (byte)(Math.Floor(controller.GetFloat("P1 Stick X")) + 128); + joy1_UD = (byte)(Math.Floor(controller.GetFloat("P1 Stick Y")) + 128); + joy2_LR = (byte)(Math.Floor(controller.GetFloat("P2 Stick X")) + 128); + joy2_UD = (byte)(Math.Floor(controller.GetFloat("P2 Stick Y")) + 128); + // override stick reading with digital input if supplied + // On vectrex there is no such thing as pressing left + right or up + down + // so convention will be up and right dominate + if (controller.IsPressed("P1 Down")) { joy1_UD = 0xFF; } + if (controller.IsPressed("P1 Up")) { joy1_UD = 0; } + if (controller.IsPressed("P1 Left")) { joy1_LR = 0xFF; } + if (controller.IsPressed("P1 Right")) { joy1_LR = 0; } + + if (controller.IsPressed("P2 Down")) { joy2_UD = 0xFF; } + if (controller.IsPressed("P2 Up")) { joy2_UD = 0; } + if (controller.IsPressed("P2 Left")) { joy2_LR = 0xFF; } + if (controller.IsPressed("P2 Right")) { joy2_LR = 0; } frame_end = false; diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IStatable.cs index a607e3b06a..eb18e92ce3 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IStatable.cs @@ -104,6 +104,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex ser.Sync(nameof(PB7_undriven), ref PB7_undriven); ser.Sync(nameof(pot_val), ref pot_val); + ser.Sync(nameof(joy1_LR), ref joy1_LR); + ser.Sync(nameof(joy1_UD), ref joy1_UD); + ser.Sync(nameof(joy2_LR), ref joy2_LR); + ser.Sync(nameof(joy2_UD), ref joy2_UD); + + // probably a better way to do this if (cart_RAM != null) { diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllers.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllers.cs index 300e8c8dbd..c247f71254 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllers.cs @@ -35,7 +35,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex .Select(b => "P" + PortNum + " " + b) .ToList(), FloatControls = { "P" + PortNum + " Stick X", "P" + PortNum + " Stick Y" }, - FloatRanges = { new[] { -127.0f, 0, 127.0f }, new[] { -127.0f, 0, 127.0f } } + FloatRanges = { new[] { 127.0f, 0, -128.0f }, new[] { -128.0f, 0, 127.0f } } }; } @@ -57,6 +57,10 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex private static readonly string[] BaseDefinition = { + "Up", + "Down", + "Left", + "Right", "Button 1", "Button 2", "Button 3", From 275ccb381a7dcec67291e23067359551ecae70e4 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Thu, 4 Jul 2019 21:26:13 -0400 Subject: [PATCH 2/6] Vectrex: ramp overscan more accurate, fixes numerous display bugs --- .../Consoles/GCE/Vectrex/PPU.cs | 19 ++--- .../GCE/Vectrex/VectrexHawk.IDebuggable.cs | 69 +++++++++++++------ 2 files changed, 60 insertions(+), 28 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/PPU.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/PPU.cs index 089739b7e7..07fad880be 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/PPU.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/PPU.cs @@ -7,7 +7,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex { public VectrexHawk Core { get; set; } - public bool zero_sig, ramp_sig, blank_sig; + public bool zero_sig, ramp_sig, blank_sig, off_screen; public byte vec_scale, x_vel, y_vel, bright; public double x_pos, y_pos; @@ -32,13 +32,15 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex { skip--; } - - if (x_pos > 257) { x_pos = 257; } - if (x_pos < 2) { x_pos = 2; } - if (y_pos > 385) { y_pos = 385; } - if (y_pos < 2) { y_pos = 2; } - + off_screen = false; + + if (x_pos > 257) { off_screen = true; if (x_pos > (257 + 256)) { x_pos = (257 + 256); } } + if (x_pos < 2) { off_screen = true; if (x_pos < (2 - 256)) { x_pos = (2 - 256); } } + if (y_pos > 385) { off_screen = true; if (y_pos > (385 + 256)) { y_pos = (385 + 256); } } + if (y_pos < 2) { off_screen = true; if (y_pos < (2 - 256)) { y_pos = (2 - 256); } } + + } else if (zero_sig) { @@ -46,7 +48,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex y_pos = 192 + 2; } - if (!blank_sig) + if (!blank_sig && !off_screen) { Core._vidbuffer[(int)(Math.Round(x_pos) + 260 * Math.Round(y_pos))] |= (int)(br & bright_int_1); @@ -84,6 +86,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex ser.Sync(nameof(zero_sig), ref zero_sig); ser.Sync(nameof(blank_sig), ref blank_sig); ser.Sync(nameof(ramp_sig), ref ramp_sig); + ser.Sync(nameof(off_screen), ref off_screen); ser.Sync(nameof(vec_scale), ref vec_scale); ser.Sync(nameof(x_vel), ref x_vel); diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IDebuggable.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IDebuggable.cs index c703f77cbc..95405698d6 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IDebuggable.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IDebuggable.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.Components.MC6809; namespace BizHawk.Emulation.Cores.Consoles.Vectrex { @@ -11,21 +12,22 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex { return new Dictionary { - /* - ["A"] = cpu.A, - ["X"] = cpu.X, - ["Y"] = cpu.Y, - ["S"] = cpu.S, - ["PC"] = cpu.PC, - ["Flag C"] = cpu.FlagC, - ["Flag Z"] = cpu.FlagZ, + + ["A"] = cpu.Regs[MC6809.A], + ["B"] = cpu.Regs[MC6809.B], + ["X"] = cpu.Regs[MC6809.X], + ["Y"] = cpu.Regs[MC6809.Y], + ["US"] = cpu.Regs[MC6809.US], + ["SP"] = cpu.Regs[MC6809.SP], + ["PC"] = cpu.Regs[MC6809.PC], + ["Flag E"] = cpu.FlagE, + ["Flag F"] = cpu.FlagF, + ["Flag H"] = cpu.FlagH, ["Flag I"] = cpu.FlagI, - ["Flag D"] = cpu.FlagD, - ["Flag B"] = cpu.FlagB, - ["Flag V"] = cpu.FlagV, ["Flag N"] = cpu.FlagN, - ["Flag T"] = cpu.FlagT - */ + ["Flag Z"] = cpu.FlagZ, + ["Flag V"] = cpu.FlagV, + ["Flag C"] = cpu.FlagC }; } @@ -36,22 +38,49 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex default: throw new InvalidOperationException(); case "A": - //cpu.A = (byte)value; + cpu.Regs[MC6809.A] = (byte)value; + break; + case "B": + cpu.Regs[MC6809.B] = (byte)value; break; case "X": - //cpu.X = (byte)value; + cpu.Regs[MC6809.X] = (byte)value; break; case "Y": - //cpu.Y = (byte)value; + cpu.Regs[MC6809.Y] = (ushort)value; break; - case "S": - //cpu.S = (byte)value; + case "US": + cpu.Regs[MC6809.US] = (ushort)value; + break; + case "SP": + cpu.Regs[MC6809.SP] = (ushort)value; break; case "PC": - //cpu.PC = (ushort)value; + cpu.Regs[MC6809.PC] = (ushort)value; + break; + case "Flag E": + cpu.FlagE = value > 0; + break; + case "Flag F": + cpu.FlagF = value > 0; + break; + case "Flag H": + cpu.FlagH = value > 0; break; case "Flag I": - //cpu.FlagI = value > 0; + cpu.FlagI = value > 0; + break; + case "Flag N": + cpu.FlagN = value > 0; + break; + case "Flag Z": + cpu.FlagZ = value > 0; + break; + case "Flag V": + cpu.FlagV = value > 0; + break; + case "Flag C": + cpu.FlagC = value > 0; break; } } From e9ca6f82bca488d5d0866ece17df07b260b14d42 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Fri, 5 Jul 2019 10:06:00 -0400 Subject: [PATCH 3/6] Trace Logger: Fix exception when scrolling --- BizHawk.Client.EmuHawk/tools/TraceLogger.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/TraceLogger.cs b/BizHawk.Client.EmuHawk/tools/TraceLogger.cs index 5516f31055..d2690cf4cd 100644 --- a/BizHawk.Client.EmuHawk/tools/TraceLogger.cs +++ b/BizHawk.Client.EmuHawk/tools/TraceLogger.cs @@ -133,7 +133,11 @@ namespace BizHawk.Client.EmuHawk { if (ToWindowRadio.Checked) { - TraceView.VirtualListSize = _instructions.Count; + // setting to zero first fixes an exception when scrolling the view + // how or why I don't know + // it's hidden behind an internal class ListViewNativeItemCollection + TraceView.VirtualListSize = 0; + TraceView.VirtualListSize = _instructions.Count; } else { @@ -148,7 +152,7 @@ namespace BizHawk.Client.EmuHawk //connect tracer to sink for next frame if (ToWindowRadio.Checked) { - //update listview with most recentr results + //update listview with most recent results TraceView.BlazingFast = !GlobalWin.MainForm.EmulatorPaused; Tracer.Sink = new CallbackSink() From b0123ea13328624d21b1bf19e625c6bb701403d9 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Fri, 5 Jul 2019 17:16:11 -0400 Subject: [PATCH 4/6] Vectrex: fix control stick in some cases --- .../Consoles/GCE/Vectrex/HW_Registers.cs | 80 +++++++++---------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/HW_Registers.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/HW_Registers.cs index 26e4a88211..04a105aa27 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/HW_Registers.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/HW_Registers.cs @@ -209,33 +209,31 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex } } } + + if (sel0) + { + if (sel1) + { + if (portA_ret >= joy2_UD) { compare = true; } + else { compare = false; } + } + else + { + if (portA_ret >= joy1_UD) { compare = true; } + else { compare = false; } + } + } else { - if (sel0) + if (sel1) { - if (sel1) - { - if (portA_ret >= joy2_UD) { compare = true; } - else { compare = false; } - } - else - { - if (portA_ret >= joy1_UD) { compare = true; } - else { compare = false; } - } + if (portA_ret >= joy2_LR) { compare = true; } + else { compare = false; } } else { - if (sel1) - { - if (portA_ret >= joy2_LR) { compare = true; } - else { compare = false; } - } - else - { - if (portA_ret >= joy1_LR) { compare = true; } - else { compare = false; } - } + if (portA_ret >= joy1_LR) { compare = true; } + else { compare = false; } } } @@ -288,33 +286,31 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex } } } + + if (sel0) + { + if (sel1) + { + if (portA_ret >= joy2_UD) { compare = true; } + else { compare = false; } + } + else + { + if (portA_ret >= joy1_UD) { compare = true; } + else { compare = false; } + } + } else { - if (sel0) + if (sel1) { - if (sel1) - { - if (portA_ret >= joy2_UD) { compare = true; } - else { compare = false; } - } - else - { - if (portA_ret >= joy1_UD) { compare = true; } - else { compare = false; } - } + if (portA_ret >= joy2_LR) { compare = true; } + else { compare = false; } } else { - if (sel1) - { - if (portA_ret >= joy2_LR) { compare = true; } - else { compare = false; } - } - else - { - if (portA_ret >= joy1_LR) { compare = true; } - else { compare = false; } - } + if (portA_ret >= joy1_LR) { compare = true; } + else { compare = false; } } } From 6a5fc8b47ee273349601e5f2f344e607816e5fb4 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Fri, 5 Jul 2019 19:57:55 -0400 Subject: [PATCH 5/6] Vectrex: Implement interrupts, fixes Bedlam --- .../CPUs/MC6809/Disassembler.cs | 2 +- .../CPUs/MC6809/Interrupts.cs | 2 +- BizHawk.Emulation.Cores/CPUs/MC6809/MC6809.cs | 38 ++++++++++++------- .../CPUs/MC6809/Registers.cs | 2 + .../Consoles/GCE/Vectrex/HW_Registers.cs | 11 +++--- .../GCE/Vectrex/VectrexHawk.IEmulator.cs | 4 +- 6 files changed, 36 insertions(+), 23 deletions(-) diff --git a/BizHawk.Emulation.Cores/CPUs/MC6809/Disassembler.cs b/BizHawk.Emulation.Cores/CPUs/MC6809/Disassembler.cs index c2a82aecd7..ee9d543b3d 100644 --- a/BizHawk.Emulation.Cores/CPUs/MC6809/Disassembler.cs +++ b/BizHawk.Emulation.Cores/CPUs/MC6809/Disassembler.cs @@ -68,7 +68,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809 "RTS", // 39 "ABX", // 3a "RTI", // 3b - "CWAI", // 3c + "CWAI i8", // 3c "MUL", // 3d "???", // 3e "SWI1", // 3f diff --git a/BizHawk.Emulation.Cores/CPUs/MC6809/Interrupts.cs b/BizHawk.Emulation.Cores/CPUs/MC6809/Interrupts.cs index d443e83065..1f352e05fd 100644 --- a/BizHawk.Emulation.Cores/CPUs/MC6809/Interrupts.cs +++ b/BizHawk.Emulation.Cores/CPUs/MC6809/Interrupts.cs @@ -22,7 +22,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809 WR_DEC_LO, SP, B, WR_DEC_LO, SP, A, WR, SP, CC, - SET_F_I, + SET_I, RD_INC, ALU, ADDR, RD_INC, ALU2, ADDR, SET_ADDR, PC, ALU, ALU2); diff --git a/BizHawk.Emulation.Cores/CPUs/MC6809/MC6809.cs b/BizHawk.Emulation.Cores/CPUs/MC6809/MC6809.cs index dbb9915a4b..93d91d6279 100644 --- a/BizHawk.Emulation.Cores/CPUs/MC6809/MC6809.cs +++ b/BizHawk.Emulation.Cores/CPUs/MC6809/MC6809.cs @@ -66,17 +66,18 @@ namespace BizHawk.Emulation.Common.Components.MC6809 public const ushort WR_DEC_HI_OP = 55; public const ushort SET_ADDR_PUL = 56; public const ushort SET_F_I = 57; - public const ushort SET_E = 58; - public const ushort ANDCC = 59; - public const ushort CMP8 = 60; - public const ushort SUB16 = 61; - public const ushort ADD16 = 62; - public const ushort CMP16 = 63; - public const ushort CMP16D = 64; - public const ushort WR_HI_INC = 65; - public const ushort LD_8 = 66; - public const ushort LD_16 = 67; - public const ushort LEA = 68; + public const ushort SET_I = 58; + public const ushort SET_E = 59; + public const ushort ANDCC = 60; + public const ushort CMP8 = 61; + public const ushort SUB16 = 62; + public const ushort ADD16 = 63; + public const ushort CMP16 = 64; + public const ushort CMP16D = 65; + public const ushort WR_HI_INC = 66; + public const ushort LD_8 = 67; + public const ushort LD_16 = 68; + public const ushort LEA = 69; public MC6809() { @@ -231,7 +232,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809 Regs[reg_d_ad] = (ushort)((Regs[reg_h_ad] << 8) | Regs[reg_l_ad]); break; case JPE: - if (!FlagE) { instr_pntr = 45; }; + if (!FlagE) { instr_pntr = 44; irq_pntr = 10; }; break; case IDX_DCDE: Index_decode(); @@ -353,6 +354,9 @@ namespace BizHawk.Emulation.Common.Components.MC6809 case SET_F_I: FlagI = true; FlagF = true; break; + case SET_I: + FlagI = true; + break; case SET_E: FlagE = true; break; @@ -449,6 +453,8 @@ namespace BizHawk.Emulation.Common.Components.MC6809 case CWAI: if (NMIPending) { + NMIPending = false; + Regs[ADDR] = 0xFFFC; PopulateCURINSTR(RD_INC, ALU, ADDR, RD_INC, ALU2, ADDR, @@ -460,6 +466,8 @@ namespace BizHawk.Emulation.Common.Components.MC6809 } else if (FIRQPending && !FlagF) { + FIRQPending = false; + Regs[ADDR] = 0xFFF6; PopulateCURINSTR(RD_INC, ALU, ADDR, RD_INC, ALU2, ADDR, @@ -471,6 +479,8 @@ namespace BizHawk.Emulation.Common.Components.MC6809 } else if (IRQPending && !FlagI) { + IRQPending = false; + Regs[ADDR] = 0xFFF8; PopulateCURINSTR(RD_INC, ALU, ADDR, RD_INC, ALU2, ADDR, @@ -542,7 +552,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809 PopulateCURINSTR(IDLE); } } - // then regular IRQ + // then regular IRQ else if (IRQPending && !FlagI) { if (!FlagI) @@ -567,7 +577,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809 instr_pntr = irq_pntr = 0; PopulateCURINSTR(IDLE); } - } + } // otherwise start the next instruction else { diff --git a/BizHawk.Emulation.Cores/CPUs/MC6809/Registers.cs b/BizHawk.Emulation.Cores/CPUs/MC6809/Registers.cs index 78a30cb2f1..0b4341d6ab 100644 --- a/BizHawk.Emulation.Cores/CPUs/MC6809/Registers.cs +++ b/BizHawk.Emulation.Cores/CPUs/MC6809/Registers.cs @@ -82,6 +82,8 @@ namespace BizHawk.Emulation.Common.Components.MC6809 { Regs[i] = 0; } + + FlagI = true; } } } \ No newline at end of file diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/HW_Registers.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/HW_Registers.cs index 04a105aa27..b34bd73b84 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/HW_Registers.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/HW_Registers.cs @@ -417,6 +417,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex { int_en &= (byte)((~value) & 0x7F); } + update_int_fl(); break; case 0xF: @@ -468,7 +469,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex int_fl |= 0x40; update_int_fl(); - //if (int_en.Bit(6)) { cpu.IRQPending = true; } + if (int_en.Bit(6)) { cpu.IRQPending = true; } if (t1_ctrl.Bit(7)) { PB7 = !PB7; ppu.ramp_sig = !PB7; } } @@ -480,7 +481,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex { int_fl |= 0x40; update_int_fl(); - //if (int_en.Bit(6)) { cpu.IRQPending = true; } + if (int_en.Bit(6)) { cpu.IRQPending = true; } if (t1_ctrl.Bit(7)) { PB7 = true; ppu.ramp_sig = false; } t1_shot_go = false; @@ -496,10 +497,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex 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; } + if (int_en.Bit(5)) { cpu.IRQPending = true; } } else { @@ -509,7 +509,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex { int_fl |= 0x20; update_int_fl(); - //if (int_en.Bit(6)) { cpu.IRQPending = true; } + if (int_en.Bit(5)) { cpu.IRQPending = true; } t2_shot_go = false; } @@ -564,6 +564,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex test |= int_en.Bit(i) & int_fl.Bit(i); } + if (!test) { cpu.IRQPending = false; } int_fl |= (byte)(test ? 0x80 : 0); } diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IEmulator.cs index 47536693b3..09f1d1d8a7 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IEmulator.cs @@ -73,8 +73,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex public void do_frame() { _vidbuffer = new int[VirtualWidth * VirtualHeight]; - //PB7_undriven = true; - //for (int i = 0; i < 1000; i++) + + //for (int i = 0; i < 100; i++) while (!frame_end) { internal_state_tick(); From 9cbc78778fdeeb5332064b5676ab01c658e9bdc9 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Fri, 5 Jul 2019 20:25:03 -0400 Subject: [PATCH 6/6] Vectrex: interrupt fixes --- BizHawk.Emulation.Cores/CPUs/MC6809/Interrupts.cs | 6 +++--- BizHawk.Emulation.Cores/CPUs/MC6809/MC6809.cs | 4 ++++ BizHawk.Emulation.Cores/CPUs/MC6809/OP_Tables.cs | 3 +-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/BizHawk.Emulation.Cores/CPUs/MC6809/Interrupts.cs b/BizHawk.Emulation.Cores/CPUs/MC6809/Interrupts.cs index 1f352e05fd..4c9e84a74a 100644 --- a/BizHawk.Emulation.Cores/CPUs/MC6809/Interrupts.cs +++ b/BizHawk.Emulation.Cores/CPUs/MC6809/Interrupts.cs @@ -8,7 +8,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809 { Regs[ADDR] = 0xFFF8; PopulateCURINSTR(IDLE, - IDLE, + SET_E, DEC16, SP, WR_DEC_LO, SP, PC, WR_DEC_HI, SP, PC, @@ -34,7 +34,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809 { Regs[ADDR] = 0xFFF6; PopulateCURINSTR(IDLE, - IDLE, + CLR_E, DEC16, SP, WR_DEC_LO, SP, PC, WR_DEC_HI, SP, PC, @@ -51,7 +51,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809 { Regs[ADDR] = 0xFFFC; PopulateCURINSTR(IDLE, - IDLE, + SET_E, DEC16, SP, WR_DEC_LO, SP, PC, WR_DEC_HI, SP, PC, diff --git a/BizHawk.Emulation.Cores/CPUs/MC6809/MC6809.cs b/BizHawk.Emulation.Cores/CPUs/MC6809/MC6809.cs index 93d91d6279..352c0eded9 100644 --- a/BizHawk.Emulation.Cores/CPUs/MC6809/MC6809.cs +++ b/BizHawk.Emulation.Cores/CPUs/MC6809/MC6809.cs @@ -78,6 +78,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809 public const ushort LD_8 = 67; public const ushort LD_16 = 68; public const ushort LEA = 69; + public const ushort CLR_E = 70; public MC6809() { @@ -360,6 +361,9 @@ namespace BizHawk.Emulation.Common.Components.MC6809 case SET_E: FlagE = true; break; + case CLR_E: + FlagE = false; + break; case ANDCC: Regs[CC] &= Regs[instr_pntr++]; break; diff --git a/BizHawk.Emulation.Cores/CPUs/MC6809/OP_Tables.cs b/BizHawk.Emulation.Cores/CPUs/MC6809/OP_Tables.cs index 45db75e8ab..e5950a074b 100644 --- a/BizHawk.Emulation.Cores/CPUs/MC6809/OP_Tables.cs +++ b/BizHawk.Emulation.Cores/CPUs/MC6809/OP_Tables.cs @@ -472,8 +472,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809 RD_INC, ALU, SP, RD_INC_OP, ALU2, SP, SET_ADDR, US, ALU, ALU2, RD_INC, ALU, SP, - RD_INC_OP, ALU2, SP, - SET_ADDR, PC, ALU, ALU2); + RD_INC_OP, ALU2, SP, SET_ADDR, PC, ALU, ALU2); IRQS = 14; }