From fd51934ea43902082b82a69fcb01bff280514cd7 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Wed, 10 Jul 2019 15:42:01 -0400 Subject: [PATCH] Vectrex: Fix some bugs --- .../CPUs/MC6809/Indexed_Modes.cs | 8 ++-- BizHawk.Emulation.Cores/CPUs/MC6809/MC6809.cs | 40 ++++++++++++------- .../CPUs/MC6809/OP_Tables.cs | 16 ++++---- .../CPUs/MC6809/Operations.cs | 26 ++++++++++++ .../GCE/Vectrex/VectrexHawk.IEmulator.cs | 5 +++ .../GCE/Vectrex/VectrexHawk.IMemoryDomains.cs | 6 --- .../GCE/Vectrex/VectrexHawk.ISaveRam.cs | 14 ++----- .../GCE/Vectrex/VectrexHawk.ISettable.cs | 5 --- .../GCE/Vectrex/VectrexHawk.IStatable.cs | 11 ++--- .../Consoles/GCE/Vectrex/VectrexHawk.cs | 18 +++++++-- .../GCE/Vectrex/VectrexHawkControllerDeck.cs | 3 +- 11 files changed, 93 insertions(+), 59 deletions(-) diff --git a/BizHawk.Emulation.Cores/CPUs/MC6809/Indexed_Modes.cs b/BizHawk.Emulation.Cores/CPUs/MC6809/Indexed_Modes.cs index da62d89628..c1d0160869 100644 --- a/BizHawk.Emulation.Cores/CPUs/MC6809/Indexed_Modes.cs +++ b/BizHawk.Emulation.Cores/CPUs/MC6809/Indexed_Modes.cs @@ -103,7 +103,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809 private void INDEX_OP_ST() { - PopulateCURINSTR(IDLE, + PopulateCURINSTR(ST_16, indexed_op_reg, WR_HI_INC, IDX_EA, indexed_op_reg, WR_DEC_LO, IDX_EA, indexed_op_reg); @@ -121,8 +121,8 @@ namespace BizHawk.Emulation.Common.Components.MC6809 private void INDEX_OP_STD() { - PopulateCURINSTR(SET_ADDR, ADDR, A, A, - WR_HI_INC, IDX_EA, ADDR, + PopulateCURINSTR(ST_16, Dr, + WR_LO_INC, IDX_EA, A, WR_DEC_LO, IDX_EA, B); IRQS = 3; @@ -138,7 +138,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809 private void INDEX_OP_EX4_ST() { - PopulateCURINSTR(IDLE, + PopulateCURINSTR(ST_8, indexed_op_reg, WR, IDX_EA, indexed_op_reg); IRQS = 2; diff --git a/BizHawk.Emulation.Cores/CPUs/MC6809/MC6809.cs b/BizHawk.Emulation.Cores/CPUs/MC6809/MC6809.cs index f386431caa..14dfc124f4 100644 --- a/BizHawk.Emulation.Cores/CPUs/MC6809/MC6809.cs +++ b/BizHawk.Emulation.Cores/CPUs/MC6809/MC6809.cs @@ -62,20 +62,23 @@ namespace BizHawk.Emulation.Common.Components.MC6809 public const ushort WR_DEC_LO_OP = 51; public const ushort WR_DEC_HI_OP = 52; public const ushort WR_HI_INC = 53; - public const ushort SET_ADDR_PUL = 54; - public const ushort SET_F_I = 55; - public const ushort SET_I = 56; - public const ushort SET_E = 57; - public const ushort ANDCC = 58; - public const ushort CMP8 = 59; - public const ushort SUB16 = 60; - public const ushort ADD16 = 61; - public const ushort CMP16 = 62; - public const ushort CMP16D = 63; - public const ushort LD_8 = 64; - public const ushort LD_16 = 65; - public const ushort LEA = 66; - public const ushort CLR_E = 67; + public const ushort WR_LO_INC = 54; + public const ushort SET_ADDR_PUL = 55; + public const ushort SET_F_I = 56; + public const ushort SET_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 LD_8 = 65; + public const ushort LD_16 = 66; + public const ushort ST_8 = 67; + public const ushort ST_16 = 68; + public const ushort LEA = 69; + public const ushort CLR_E = 70; public MC6809() { @@ -296,6 +299,9 @@ namespace BizHawk.Emulation.Common.Components.MC6809 case WR_HI_INC: Write_Hi_Inc_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; + case WR_LO_INC: + Write_Lo_Inc_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); + break; case TR: TR_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; @@ -305,6 +311,12 @@ namespace BizHawk.Emulation.Common.Components.MC6809 case LD_16: LD_16_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; + case ST_8: + ST_8_Func(cur_instr[instr_pntr++]); + break; + case ST_16: + ST_16_Func(cur_instr[instr_pntr++]); + break; case LEA: LEA_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; diff --git a/BizHawk.Emulation.Cores/CPUs/MC6809/OP_Tables.cs b/BizHawk.Emulation.Cores/CPUs/MC6809/OP_Tables.cs index 323a3c6748..495df28f70 100644 --- a/BizHawk.Emulation.Cores/CPUs/MC6809/OP_Tables.cs +++ b/BizHawk.Emulation.Cores/CPUs/MC6809/OP_Tables.cs @@ -52,7 +52,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809 private void DIRECT_ST_4(ushort dest) { PopulateCURINSTR(RD_INC_OP, ALU, PC, SET_ADDR, ADDR, DP, ALU, - IDLE, + ST_8, dest, WR, ADDR, dest); IRQS = 3; @@ -93,7 +93,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809 { PopulateCURINSTR(RD_INC, ALU, PC, RD_INC_OP, ALU2, PC, SET_ADDR, ADDR, ALU, ALU2, - IDLE, + ST_8, dest, WR, ADDR, dest); IRQS = 4; @@ -168,8 +168,8 @@ namespace BizHawk.Emulation.Common.Components.MC6809 private void DIR_OP_ST_16D() { PopulateCURINSTR(RD_INC_OP, ALU, PC, SET_ADDR, ADDR, DP, ALU, - SET_ADDR, ALU, A, A, - WR_HI_INC, ADDR, ALU, + ST_16, Dr, + WR_LO_INC, ADDR, A, WR, ADDR, B); IRQS = 4; @@ -216,7 +216,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809 private void DIR_OP_ST_16(ushort src) { PopulateCURINSTR(RD_INC_OP, ALU, PC, SET_ADDR, ADDR, DP, ALU, - IDLE, + ST_16, src, WR_HI_INC, ADDR, src, WR_DEC_LO, ADDR, src); @@ -238,7 +238,7 @@ namespace BizHawk.Emulation.Common.Components.MC6809 { PopulateCURINSTR(RD_INC, ALU, PC, RD_INC_OP, ALU2, PC, SET_ADDR, ADDR, ALU, ALU2, - IDLE, + ST_16, src, WR_HI_INC, ADDR, src, WR_DEC_LO, ADDR, src); @@ -260,8 +260,8 @@ namespace BizHawk.Emulation.Common.Components.MC6809 { PopulateCURINSTR(RD_INC, ALU, PC, RD_INC_OP, ALU2, PC, SET_ADDR, ADDR, ALU, ALU2, - SET_ADDR, ALU, A, A, - WR_HI_INC, ADDR, ALU, + ST_16, Dr, + WR_LO_INC, ADDR, A, WR, ADDR, B); IRQS = 5; diff --git a/BizHawk.Emulation.Cores/CPUs/MC6809/Operations.cs b/BizHawk.Emulation.Cores/CPUs/MC6809/Operations.cs index 736b400c3d..eb2f1de17a 100644 --- a/BizHawk.Emulation.Cores/CPUs/MC6809/Operations.cs +++ b/BizHawk.Emulation.Cores/CPUs/MC6809/Operations.cs @@ -62,6 +62,13 @@ namespace BizHawk.Emulation.Common.Components.MC6809 Regs[dest]++; } + public void Write_Lo_Inc_Func(ushort dest, ushort src) + { + if (CDLCallback != null) CDLCallback(Regs[dest], eCDLogMemFlags.Write | eCDLogMemFlags.Data); + WriteMemory(Regs[dest], (byte)Regs[src]); + Regs[dest]++; + } + public void NEG_8_Func(ushort src) { int Reg16_d = 0; @@ -94,6 +101,13 @@ namespace BizHawk.Emulation.Common.Components.MC6809 FlagN = (Regs[dest] & 0xFF) > 127; } + public void ST_8_Func(ushort dest) + { + FlagZ = (Regs[dest] & 0xFF) == 0; + FlagV = false; + FlagN = (Regs[dest] & 0xFF) > 127; + } + public void LD_16_Func(ushort dest, ushort src_h, ushort src_l) { Regs[dest] = (ushort)(Regs[src_h] << 8 | Regs[src_l]); @@ -103,6 +117,18 @@ namespace BizHawk.Emulation.Common.Components.MC6809 FlagN = Regs[dest] > 0x7FFF; } + public void ST_16_Func(ushort dest) + { + if (dest == Dr) + { + Regs[dest] = D; + } + + FlagZ = Regs[dest] == 0; + FlagV = false; + FlagN = Regs[dest] > 0x7FFF; + } + // for LEAX/Y, zero flag can be effected, but not for U/S public void LEA_Func(ushort dest, ushort src) { diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IEmulator.cs index 546604e6ce..056e0f91a4 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IEmulator.cs @@ -29,6 +29,11 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex HardReset(); } + if (controller.IsPressed("Reset")) + { + SoftReset(); + } + _islag = true; // button inputs go to port 14 in the audio registers diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IMemoryDomains.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IMemoryDomains.cs index ee19f7d73b..0a0e505aa6 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IMemoryDomains.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IMemoryDomains.cs @@ -36,12 +36,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex 1), }; - if (cart_RAM != null) - { - var CartRam = new MemoryDomainByteArray("Cart RAM", MemoryDomain.Endian.Little, cart_RAM, true, 1); - domains.Add(CartRam); - } - MemoryDomains = new MemoryDomainList(domains); (ServiceProvider as BasicServiceProvider).Register(MemoryDomains); } diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.ISaveRam.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.ISaveRam.cs index 051fe9d6f5..6db3ef9021 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.ISaveRam.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.ISaveRam.cs @@ -7,27 +7,19 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex { public byte[] CloneSaveRam() { - if (cart_RAM != null) - { - return (byte[])cart_RAM.Clone(); - } - else - { - return null; - } + return null; } public void StoreSaveRam(byte[] data) { - Buffer.BlockCopy(data, 0, cart_RAM, 0, data.Length); - Console.WriteLine("loading SRAM here"); + } public bool SaveRamModified { get { - return has_bat & _syncSettings.Use_SRAM; + return false; } } } diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.ISettable.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.ISettable.cs index 84794c82ee..28ec3e426b 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.ISettable.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.ISettable.cs @@ -91,11 +91,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex } } - [DisplayName("Use Existing SaveRAM")] - [Description("When true, existing SaveRAM will be loaded at boot up")] - [DefaultValue(false)] - public bool Use_SRAM { get; set; } - public VectrexSyncSettings Clone() { return (VectrexSyncSettings)MemberwiseClone(); diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IStatable.cs index eb18e92ce3..7b93fb871d 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IStatable.cs @@ -47,6 +47,10 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex ms.Close(); core = ms.ToArray(); } + else + { + _framebuffer = new int[VirtualWidth * VirtualHeight]; + } cpu.SyncState(ser); mapper.SyncState(ser); ppu.SyncState(ser); @@ -109,13 +113,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex 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) - { - ser.Sync(nameof(cart_RAM), ref cart_RAM, false); - } - ser.EndSection(); } } diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.cs index 0ff765f1d4..572afec960 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.cs @@ -20,9 +20,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex public byte[] _bios, minestorm; public readonly byte[] _rom; - - public byte[] cart_RAM; - public bool has_bat; private int _frame = 0; @@ -138,6 +135,21 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex ppu.Reset(); audio.Reset(); serialport.Reset(); + cpu.Reset(); + + RAM = new byte[0x400]; + + _vidbuffer = new int[VirtualWidth * VirtualHeight]; + _framebuffer = new int[VirtualWidth * VirtualHeight]; + } + + public void SoftReset() + { + Register_Reset(); + ppu.Reset(); + audio.Reset(); + serialport.Reset(); + cpu.Reset(); _vidbuffer = new int[VirtualWidth * VirtualHeight]; _framebuffer = new int[VirtualWidth * VirtualHeight]; diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllerDeck.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllerDeck.cs index bf0508410d..fd773ad9a4 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllerDeck.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllerDeck.cs @@ -32,7 +32,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex .Concat(Port2.Definition.BoolButtons) .Concat(new[] { - "Power" + "Power", + "Reset" }) .ToList() };