From 94db48b24f14d0a288f87bfaf781a9c5993a282d Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Sun, 23 Jun 2019 17:46:30 -0400 Subject: [PATCH] vectrex; more bug fixes --- .../CPUs/MC6809/Disassembler.cs | 4 +- .../Consoles/GCE/Vectrex/HW_Registers.cs | 47 ++++++++++++++----- .../Consoles/GCE/Vectrex/MemoryMap.cs | 2 +- .../Consoles/GCE/Vectrex/PPU.cs | 5 +- .../GCE/Vectrex/VectrexHawk.IEmulator.cs | 15 +++--- .../GCE/Vectrex/VectrexHawk.IStatable.cs | 2 + 6 files changed, 49 insertions(+), 26 deletions(-) diff --git a/BizHawk.Emulation.Cores/CPUs/MC6809/Disassembler.cs b/BizHawk.Emulation.Cores/CPUs/MC6809/Disassembler.cs index 94cf5b9ece..7ec2c39d8c 100644 --- a/BizHawk.Emulation.Cores/CPUs/MC6809/Disassembler.cs +++ b/BizHawk.Emulation.Cores/CPUs/MC6809/Disassembler.cs @@ -182,8 +182,8 @@ namespace BizHawk.Emulation.Common.Components.MC6809 "ADD A,ix16", // ab "CMP X,ix16", // ac "JSR ix16", // ad - "LD X,ex16", // ae - "ST X,ex16", // af + "LD X,ix16", // ae + "ST X,ix16", // af "SUB A,ex16", // b0 "CMP A,ex16", // b1 "SBC A,ex16", // b2 diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/HW_Registers.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/HW_Registers.cs index f8c9fffdc7..92cfdc4bf5 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/HW_Registers.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/HW_Registers.cs @@ -32,11 +32,15 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex public bool PB7, PB6; public bool PB7_prev, PB6_prev; + public bool PB7_last_write; + // Port B controls public bool sw, sel0, sel1, bc1, bdir, compare, shift_start; public byte int_en, int_fl, aux_ctrl, prt_ctrl, shift_reg, shift_reg_wait, shift_count; + public bool frame_end; + public byte Read_Registers(int addr) { byte ret = 0; @@ -44,7 +48,14 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex switch (addr) { case 0x0: - ret = portB_ret; + if (!aux_ctrl.Bit(7)) + { + ret = portB_ret; + } + else + { + ret = (byte)((portB_ret & 0x7F) | (PB7 ? 0x80 : 0x0)); + } int_fl &= 0xE7; update_int_fl(); @@ -132,6 +143,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex if (aux_ctrl.Bit(7)) { + PB7_last_write = wrt_val.Bit(7); wrt_val = (byte)((wrt_val & 0x7F) | (PB7 ? 0x80 : 0x0)); } @@ -167,7 +179,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex } } - ppu.x_vel = (byte)(portA_ret ^ 0x80);; + //ppu.x_vel = ~portA_ret; + ppu.x_vel = (byte)(portA_ret ^ 0x80); + //ppu.x_vel = portA_ret; if (ppu.x_vel >= 128) { ppu.x_vel -= 128; ppu.x_vel = -ppu.x_vel; } int_fl &= 0xE7; update_int_fl(); @@ -180,7 +194,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex // writing to sound reg if (bdir) { - if (bc1) { audio.port_sel = (byte)(portA_ret & 0xf); } + if (bc1) { audio.port_sel = (byte)(portA_ret & 0xF); } else { audio.WriteReg(0, portA_ret); } } @@ -198,7 +212,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex } } + //ppu.x_vel = ~portA_ret; ppu.x_vel = (byte)(portA_ret ^ 0x80); + //ppu.x_vel = portA_ret; if (ppu.x_vel >= 128) { ppu.x_vel -= 128; ppu.x_vel = -ppu.x_vel; } int_fl &= 0xFC; update_int_fl(); @@ -256,7 +272,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex break; case 0xB: aux_ctrl = value; - if (!aux_ctrl.Bit(7)) { ppu.ramp_sig = value.Bit(7); } + t1_ctrl = aux_ctrl; + //if (aux_ctrl.Bit(7)) { ppu.ramp_sig = !PB7; } + //else { ppu.ramp_sig = !PB7_last_write; } break; case 0xC: prt_ctrl = value; @@ -325,8 +343,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex } } - public void timer_1_tick() + public void internal_state_tick() { + // Timer 1 t1_counter--; if (t1_counter < 0) @@ -356,10 +375,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex } } } - } - public void timer_2_tick() - { + // Timer 2 t2_counter--; if (t2_counter < 0) @@ -385,11 +402,10 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex t2_shot_go = false; } } + frame_end = true; } - } - public void shift_reg_tick() - { + // Shift register if (shift_start) { if (shift_reg_wait > 0) @@ -405,15 +421,20 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex { // reset blank signal back to contorl of peripheral controller shift_start = false; - if ((prt_ctrl & 0xE0) == 0xC0) { ppu.blank_sig = true; } - else { ppu.blank_sig = false; } + //if ((prt_ctrl & 0xE0) == 0xC0) { ppu.blank_sig = true; } + //else { ppu.blank_sig = false; } } else { ppu.blank_sig = !shift_reg.Bit(7 - shift_count); shift_count++; + shift_reg_wait = 1; } } + else + { + Console.WriteLine("method 2"); + } // other clocking modes are not used. Maybe some demos use them? } diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/MemoryMap.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/MemoryMap.cs index fbbcac2837..5ff68df6ae 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/MemoryMap.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/MemoryMap.cs @@ -92,7 +92,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex { if (addr < 0x8000) { - return 0xFF; + return mapper.ReadMemory(addr); } else if (addr < 0xC800) { diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/PPU.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/PPU.cs index c5aaeac6bf..ce6415f48d 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/PPU.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/PPU.cs @@ -15,6 +15,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex public void tick() { + //Console.WriteLine(ramp_sig + " " + zero_sig + " " + blank_sig + " " + Core.cpu.TotalExecutedCycles + " " + (x_vel - 128.0) + " " + x_pos + //+ " " + (y_vel - 128.0) + " " + y_pos + " " + Core.t1_counter + " " + vec_scale); + if (ramp_sig && !zero_sig) { x_pos = x_pos + (x_vel - 128.0) / 256.0 * (vec_scale + 2); @@ -25,7 +28,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex if (y_pos > 383) { y_pos = 383; } if (y_pos < 0) { y_pos = 0; } - if (!blank_sig) { Core._vidbuffer[(int)(Math.Floor(x_pos) + 256 * Math.Floor(y_pos))] = (int)br; } + if (!blank_sig) { Core._vidbuffer[(int)(Math.Round(x_pos) + 256 * Math.Round(y_pos))] = (int)br; } } else if (zero_sig) { diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IEmulator.cs index e945259553..d9abaa8d15 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IEmulator.cs @@ -36,6 +36,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex audio.Register[14] = (byte)(_controllerDeck.ReadPort1(controller) & 0xF); audio.Register[14] |= (byte)(_controllerDeck.ReadPort2(controller) << 4); + frame_end = false; + do_frame(); if (_islag) @@ -50,11 +52,10 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex { _vidbuffer = new int[VirtualWidth * VirtualHeight]; - for (int i = 0; i < 25000; i++) + //for (int i = 0; i < 1000; i++) + while (!frame_end) { - timer_1_tick(); - timer_2_tick(); - shift_reg_tick(); + internal_state_tick(); audio.tick(); ppu.tick(); cpu.ExecuteOne(); @@ -83,7 +84,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex #region Video provider - public int _frameHz = 60; + public int _frameHz = 50; public int[] _vidbuffer; @@ -100,10 +101,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex public int VsyncNumerator => _frameHz; public int VsyncDenominator => 1; - public static readonly uint[] color_palette_Gr = { 0xFFA4C505, 0xFF88A905, 0xFF1D551D, 0xFF052505 }; - - public uint[] color_palette = new uint[4]; - #endregion } } diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IStatable.cs index 4b93b6574f..4ab835cf12 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IStatable.cs @@ -100,6 +100,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex ser.Sync(nameof(shift_reg_wait), ref shift_reg_wait); ser.Sync(nameof(shift_count), ref shift_count); + ser.Sync(nameof(frame_end), ref frame_end); + // probably a better way to do this if (cart_RAM != null) {