From 356039638a18b4b96fb3184426acdcb3892aa790 Mon Sep 17 00:00:00 2001 From: Asnivor Date: Fri, 26 Apr 2019 17:51:45 +0100 Subject: [PATCH] F8: more bug hunting --- .../Fairchild/ChannelF/ChannelF.IO.cs | 3 +- .../ChannelF/ChannelF.IVideoProvider.cs | 85 +++++++++++++------ .../Fairchild/ChannelF/F8/F3850.ALU.cs | 5 +- .../Consoles/Fairchild/ChannelF/F8/F3850.cs | 20 +++-- 4 files changed, 74 insertions(+), 39 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.IO.cs b/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.IO.cs index 0df6d3e1a0..7aa343ee03 100644 --- a/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.IO.cs +++ b/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.IO.cs @@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF public byte[] BIOS01 = new byte[1024]; public byte[] BIOS02 = new byte[1024]; - public byte[] FrameBuffer = new byte[2048]; + public byte[] FrameBuffer = new byte[0x2000]; public byte[] Cartridge = new byte[0x2000 - 0x800]; @@ -31,6 +31,7 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF else if (addr < 0x2000) { // Cart + return 0; return Cartridge[addr - 0x800]; } else if (addr < 0x2000 + 2048) diff --git a/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.IVideoProvider.cs b/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.IVideoProvider.cs index a009e491e0..4efe72af28 100644 --- a/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.IVideoProvider.cs +++ b/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.IVideoProvider.cs @@ -1,4 +1,5 @@ using System; +using BizHawk.Common; using BizHawk.Common.BufferExtensions; using BizHawk.Emulation.Common; @@ -6,63 +7,91 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF { public partial class ChannelF : IVideoProvider, IRegionable { + public static readonly int[] FPalette = + { + Colors.ARGB(0x10, 0x10, 0x10), // Black + Colors.ARGB(0xFD, 0xFD, 0xFD), // White + Colors.ARGB(0xFF, 0x31, 0x53), // Red + Colors.ARGB(0x02, 0xCC, 0x5D), // Green + Colors.ARGB(0x4B, 0x3F, 0xF3), // Blue + Colors.ARGB(0xE0, 0xE0, 0xE0), // Gray + Colors.ARGB(0x91, 0xFF, 0xA6), // BGreen + Colors.ARGB(0xCE, 0xD0, 0xFF), // BBlue + }; + + public static readonly int[] CMap = + { + 0, 1, 1, 1, + 7, 4, 2, 3, + 5, 4, 2, 3, + 6, 4, 2, 3, + }; + public int _frameHz = 60; - public int[] _vidbuffer = new int[102 * 58]; + public int[] _vidbuffer = new int[108 * 64]; public int[] GetVideoBuffer() { - int row; - int col; - int color; - int pal; - + int colour; + int a = 0; + int pOff; + // rows + for (int y = 0; y < 64; y++) + { + pOff = ((FrameBuffer[(y * 128) + 125] & 0x3) & 0x02) | ((FrameBuffer[(y * 128) + 126] & 0x3) >> 1) << 2; + for (int x = a; x < a + 128; x++) + { + colour = pOff + (FrameBuffer[x | (y << 7)] & 0x03); + var yM = y * 64; + _vidbuffer[yM + x] = FPalette[CMap[colour]]; + } + } return _vidbuffer; } - public int VirtualWidth => 102 * 2; - public int VirtualHeight => 58 * 2; - public int BufferWidth => 102; - public int BufferHeight => 58; + public int VirtualWidth => BufferWidth * 2; + public int VirtualHeight => BufferHeight * 2; + public int BufferWidth => 108; // 102 + public int BufferHeight => 64; // 58 public int BackgroundColor => unchecked((int)0xFF000000); public int VsyncNumerator => _frameHz; public int VsyncDenominator => 1; - - private int[] colors = { 0x101010, 0xFDFDFD, 0x5331FF, 0x5DCC02, 0xF33F4B, 0xE0E0E0, 0xA6FF91, 0xD0CEFF }; - private int[] palette = {0,1,1,1, 7,2,4,3, 6,2,4,3, 5,2,4,3}; - private int[] buffer = new int[8192]; - - int ARM = 0; - int X = 0; - int Y = 0; - int Color = 2; + private int row = 0; + private int col = 0; + private byte value = 0; public void VID_PortIN(ushort port, byte val) { switch (port) { - case 0: // ARM - val &= 0x60; - if (val == 0x40 && ARM == 0x60) // Strobed + case 0: + + int o; + PortLatch[port] = val; + if ((val & 0x20) != 0) { - // Write to display buffer - buffer[(Y << 7) + X] = Color; + o = (row * 128) + col; + FrameBuffer[o] = value; } - ARM = val; break; case 1: // Set Color (bits 6 and 7) - Color = ((val ^ 0xFF) >> 6) & 3; + PortLatch[port] = val; + value = (byte)(((val ^ 0xFF) >> 6) & 0x03); break; case 4: // X coordinate, inverted (bits 0-6) - X = (val ^ 0xFF) & 0x7F; + PortLatch[2] = val; + col = (val | 0x80) ^ 0xFF; break; case 5: // Y coordinate, inverted (bits 0-5) - Y = (val ^ 0xFF) & 0x3F; + PortLatch[3] = val; + //sound TODO + row = (val | 0xC0) ^ 0xFF; break; } } diff --git a/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/F8/F3850.ALU.cs b/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/F8/F3850.ALU.cs index 002452e1cd..ccc6d9f234 100644 --- a/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/F8/F3850.ALU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/F8/F3850.ALU.cs @@ -107,7 +107,8 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF ALU_ClearFlags(); ALU_ADD8_FLAGSONLY_Func(dest, src); - ALU_SetFlags_SZ(tmp); + Regs[ALU0] = tmp; + ALU_SetFlags_SZ(ALU0); if (c == 0 && ic == 0) { @@ -229,7 +230,7 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF } */ - public void ADDS_Func(ushort dest_l, ushort dest_h, ushort src_l, ushort src_h) + public void ADDS_FuncX(ushort dest_l, ushort dest_h, ushort src_l, ushort src_h) { int Reg16_d = Regs[dest_l]; int Reg16_s = Regs[src_l]; diff --git a/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/F8/F3850.cs b/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/F8/F3850.cs index df96c4aa1c..42d0ac06c2 100644 --- a/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/F8/F3850.cs +++ b/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/F8/F3850.cs @@ -307,9 +307,9 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF // test operand against status register case OP_BT: - instr_pntr = 0; if ((Regs[W] & cur_instr[instr_pntr++]) != 0) { + instr_pntr = 0; PopulateCURINSTR( // L ROMC_01, @@ -326,6 +326,7 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF } else { + instr_pntr = 0; PopulateCURINSTR( // S ROMC_03_S, @@ -342,9 +343,9 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF // Branch based on ISARL case OP_BR7: - instr_pntr = 0; if ((Regs[ISAR] & 7) == 7) { + instr_pntr = 0; PopulateCURINSTR( // S ROMC_03_S, // DB/IO <- ((PC0)); PC0++ @@ -359,6 +360,7 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF } else { + instr_pntr = 0; PopulateCURINSTR( // L ROMC_01, @@ -376,9 +378,9 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF // PC0 <- PC0+n+1 case OP_BF: - instr_pntr = 0; if ((Regs[W] & cur_instr[instr_pntr++]) != 0) { + instr_pntr = 0; PopulateCURINSTR( // S ROMC_03_S, // DB/IO <- ((PC0)); PC0++ @@ -393,6 +395,7 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF } else { + instr_pntr = 0; PopulateCURINSTR( // L ROMC_01, @@ -465,7 +468,7 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF // CYCLE LENGTH: L case ROMC_01: Read_Func(DB, PC0l, PC0h); - ADDS_Func(PC0l, PC0h, DB, ZERO); + RegPC0 += (ushort)((SByte) Regs[DB]); break; // The device whose DC0 address addresses a memory word within the address space of that device must place on the data bus the contents @@ -535,7 +538,7 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF // All devices add the 8-bit value on the data bus, treated as a signed binary number, to the data counter // CYCLE LENGTH: L case ROMC_0A: - ADDS_Func(DC0l, DC0h, DB, ZERO); + RegDC0 += (ushort) ((sbyte) Regs[DB]); break; // The device whose address space includes the value in PC1 must place the low order byte of PC1 on the data bus @@ -689,12 +692,13 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF public TraceInfo State(bool disassemble = true) { int bytes_read = 0; - string disasm = disassemble ? Disassemble(RegPC0, ReadMemory, out bytes_read) : "---"; + ushort pc = (ushort)(RegPC0 - 1); + string disasm = disassemble ? Disassemble(pc, ReadMemory, out bytes_read) : "---"; string byte_code = null; for (ushort i = 0; i < bytes_read; i++) { - byte_code += ReadMemory((ushort)(RegPC0 + i)).ToHexString(2); + byte_code += ReadMemory((ushort)(pc + i)).ToHexString(2); if (i < (bytes_read - 1)) { byte_code += " "; @@ -705,7 +709,7 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF { Disassembly = string.Format( "{0:X4}: {1} {2}", - RegPC0, + pc, byte_code.PadRight(12), disasm.PadRight(26)), RegisterInfo = string.Format(