From 7a08cb1075f0d98626a7c6995b791a6b3de818c8 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 14 Sep 2013 19:34:14 +0000 Subject: [PATCH] Fix some annoying warnings and some misc code cleanup --- BizHawk.Emulation/Consoles/Calculator/TI83.cs | 1752 ++++++++--------- .../Consoles/Nintendo/NES/Core.cs | 2 +- BizHawk.Emulation/DiscSystem/Disc.cs | 3 +- .../GENtools/GenGameGenie.Designer.cs | 18 +- BizHawk.MultiClient/GENtools/GenGameGenie.cs | 6 +- BizHawk.MultiClient/Program.cs | 2 +- BizHawk.MultiClient/config/RewindConfig.cs | 57 +- BizHawk.MultiClient/tools/Watch/Watch.cs | 6 +- BizHawk_2012.sln | 16 - 9 files changed, 919 insertions(+), 943 deletions(-) diff --git a/BizHawk.Emulation/Consoles/Calculator/TI83.cs b/BizHawk.Emulation/Consoles/Calculator/TI83.cs index f4a7bb07b1..ab311e398a 100644 --- a/BizHawk.Emulation/Consoles/Calculator/TI83.cs +++ b/BizHawk.Emulation/Consoles/Calculator/TI83.cs @@ -8,430 +8,428 @@ using BizHawk.Emulation.CPUs.Z80; namespace BizHawk.Emulation.Consoles.Calculator { - public class TI83 : IEmulator - { - //hardware - private readonly Z80A cpu = new Z80A(); - private readonly byte[] rom; - private byte[] ram; - private int romPageLow3Bits; - private int romPageHighBit; - private byte maskOn; - private bool onPressed; - private int keyboardMask; + public class TI83 : IEmulator + { + //hardware + private readonly Z80A cpu = new Z80A(); + private readonly byte[] rom; + private byte[] ram; + private int romPageLow3Bits; + private int romPageHighBit; + private byte maskOn; + private bool onPressed; + private int keyboardMask; - private int disp_mode; - private int disp_move; - private uint disp_x, disp_y; - private int m_LinkOutput, m_LinkInput; + private int disp_mode; + private int disp_move; + private uint disp_x, disp_y; + private int m_LinkOutput, m_LinkInput; - private int m_LinkState - { - get - { - return (m_LinkOutput | m_LinkInput) ^ 3; - } - } + private int m_LinkState + { + get + { + return (m_LinkOutput | m_LinkInput) ^ 3; + } + } - private bool LinkActive; - private bool m_CursorMoved; + private bool LinkActive; + private bool m_CursorMoved; - //------- + //------- - public byte ReadMemory(ushort addr) - { - byte ret; - int romPage = romPageLow3Bits | (romPageHighBit << 3); - //Console.WriteLine("read memory: {0:X4}", addr); - if (addr < 0x4000) - ret = rom[addr]; //ROM zero-page - else if (addr < 0x8000) - ret = rom[romPage * 0x4000 + addr - 0x4000]; //other rom page - else ret = ram[addr - 0x8000]; + public byte ReadMemory(ushort addr) + { + byte ret; + int romPage = romPageLow3Bits | (romPageHighBit << 3); + //Console.WriteLine("read memory: {0:X4}", addr); + if (addr < 0x4000) + ret = rom[addr]; //ROM zero-page + else if (addr < 0x8000) + ret = rom[romPage * 0x4000 + addr - 0x4000]; //other rom page + else ret = ram[addr - 0x8000]; - if (CoreComm.MemoryCallbackSystem.HasRead) - { - CoreComm.MemoryCallbackSystem.TriggerRead(addr); - } + if (CoreComm.MemoryCallbackSystem.HasRead) + { + CoreComm.MemoryCallbackSystem.TriggerRead(addr); + } - return ret; - } + return ret; + } - public void WriteMemory(ushort addr, byte value) - { - if (addr < 0x4000) - return; //ROM zero-page - else if (addr < 0x8000) - return; //other rom page - else ram[addr - 0x8000] = value; + public void WriteMemory(ushort addr, byte value) + { + if (addr < 0x4000) + return; //ROM zero-page + else if (addr < 0x8000) + return; //other rom page + else ram[addr - 0x8000] = value; - if (CoreComm.MemoryCallbackSystem.HasWrite) - { - CoreComm.MemoryCallbackSystem.TriggerWrite(addr); - } - } + if (CoreComm.MemoryCallbackSystem.HasWrite) + { + CoreComm.MemoryCallbackSystem.TriggerWrite(addr); + } + } - public void WriteHardware(ushort addr, byte value) - { - switch (addr) - { - case 0: //PORT_LINK - romPageHighBit = (value >> 4) & 1; - m_LinkOutput = value & 3; + public void WriteHardware(ushort addr, byte value) + { + switch (addr) + { + case 0: //PORT_LINK + romPageHighBit = (value >> 4) & 1; + m_LinkOutput = value & 3; - if (LinkActive) - { - //Prevent rom calls from disturbing link port activity - if (LinkActive && cpu.RegisterPC < 0x4000) - return; + if (LinkActive) + { + //Prevent rom calls from disturbing link port activity + if (LinkActive && cpu.RegisterPC < 0x4000) + return; - LinkPort.Update(); - } - break; - case 1: //PORT_KEYBOARD: - lagged = false; - keyboardMask = value; - //Console.WriteLine("write PORT_KEYBOARD {0:X2}",value); - break; - case 2: //PORT_ROMPAGE - romPageLow3Bits = value & 0x7; - break; - case 3: //PORT_STATUS - maskOn = (byte)(value & 1); - break; - case 16: //PORT_DISPCTRL - //Console.WriteLine("write PORT_DISPCTRL {0}",value); - WriteDispCtrl(value); - break; - case 17: //PORT_DISPDATA - //Console.WriteLine("write PORT_DISPDATA {0}",value); - WriteDispData(value); - break; - } - } + LinkPort.Update(); + } + break; + case 1: //PORT_KEYBOARD: + lagged = false; + keyboardMask = value; + //Console.WriteLine("write PORT_KEYBOARD {0:X2}",value); + break; + case 2: //PORT_ROMPAGE + romPageLow3Bits = value & 0x7; + break; + case 3: //PORT_STATUS + maskOn = (byte)(value & 1); + break; + case 16: //PORT_DISPCTRL + //Console.WriteLine("write PORT_DISPCTRL {0}",value); + WriteDispCtrl(value); + break; + case 17: //PORT_DISPDATA + //Console.WriteLine("write PORT_DISPDATA {0}",value); + WriteDispData(value); + break; + } + } - public byte ReadHardware(ushort addr) - { - switch (addr) - { - case 0: //PORT_LINK - LinkPort.Update(); - return (byte)((romPageHighBit << 4) | (m_LinkState << 2) | m_LinkOutput); - case 1: //PORT_KEYBOARD: - //Console.WriteLine("read PORT_KEYBOARD"); - return ReadKeyboard(); - case 2: //PORT_ROMPAGE - return (byte)romPageLow3Bits; - case 3: //PORT_STATUS - { - //Console.WriteLine("read PORT_STATUS"); - byte ret = 0; - // Bits: - // 0 - Set if ON key is down and ON key is trapped - // 1 - Update things (keyboard etc) - // 2 - Unknown, but used - // 3 - Set if ON key is up - // 4-7 - Unknown - //if (onPressed && maskOn) ret |= 1; - //if (!onPressed) ret |= 0x8; - ret = (byte)((Controller.IsPressed("ON") ? maskOn : 8) | (LinkActive ? 0 : 2)); - return ret; - } + public byte ReadHardware(ushort addr) + { + switch (addr) + { + case 0: //PORT_LINK + LinkPort.Update(); + return (byte)((romPageHighBit << 4) | (m_LinkState << 2) | m_LinkOutput); + case 1: //PORT_KEYBOARD: + //Console.WriteLine("read PORT_KEYBOARD"); + return ReadKeyboard(); + case 2: //PORT_ROMPAGE + return (byte)romPageLow3Bits; + case 3: //PORT_STATUS + { + //Console.WriteLine("read PORT_STATUS"); + // Bits: + // 0 - Set if ON key is down and ON key is trapped + // 1 - Update things (keyboard etc) + // 2 - Unknown, but used + // 3 - Set if ON key is up + // 4-7 - Unknown + //if (onPressed && maskOn) ret |= 1; + //if (!onPressed) ret |= 0x8; + return (byte)((Controller.IsPressed("ON") ? maskOn : 8) | (LinkActive ? 0 : 2)); + } - case 4: //PORT_INTCTRL - //Console.WriteLine("read PORT_INTCTRL"); - return 0xFF; + case 4: //PORT_INTCTRL + //Console.WriteLine("read PORT_INTCTRL"); + return 0xFF; - case 16: //PORT_DISPCTRL - //Console.WriteLine("read DISPCTRL"); - break; + case 16: //PORT_DISPCTRL + //Console.WriteLine("read DISPCTRL"); + break; - case 17: //PORT_DISPDATA - return ReadDispData(); - } - return 0xFF; - } + case 17: //PORT_DISPDATA + return ReadDispData(); + } + return 0xFF; + } - byte ReadKeyboard() - { - if (CoreComm.InputCallback != null) CoreComm.InputCallback(); - //ref TI-9X + byte ReadKeyboard() + { + if (CoreComm.InputCallback != null) CoreComm.InputCallback(); + //ref TI-9X - int ret = 0xFF; - //Console.WriteLine("keyboardMask: {0:X2}",keyboardMask); - if ((keyboardMask & 1) == 0) - { - if (Controller.IsPressed("DOWN")) ret ^= 1; - if (Controller.IsPressed("LEFT")) ret ^= 2; - if (Controller.IsPressed("RIGHT")) ret ^= 4; - if (Controller.IsPressed("UP")) ret ^= 8; - } - if ((keyboardMask & 2) == 0) - { - if (Controller.IsPressed("ENTER")) ret ^= 1; - if (Controller.IsPressed("PLUS")) ret ^= 2; - if (Controller.IsPressed("MINUS")) ret ^= 4; - if (Controller.IsPressed("MULTIPLY")) ret ^= 8; - if (Controller.IsPressed("DIVIDE")) ret ^= 16; - if (Controller.IsPressed("EXP")) ret ^= 32; - if (Controller.IsPressed("CLEAR")) ret ^= 64; - } - if ((keyboardMask & 4) == 0) - { - if (Controller.IsPressed("DASH")) ret ^= 1; - if (Controller.IsPressed("3")) ret ^= 2; - if (Controller.IsPressed("6")) ret ^= 4; - if (Controller.IsPressed("9")) ret ^= 8; - if (Controller.IsPressed("PARACLOSE")) ret ^= 16; - if (Controller.IsPressed("TAN")) ret ^= 32; - if (Controller.IsPressed("VARS")) ret ^= 64; - } - if ((keyboardMask & 8) == 0) - { - if (Controller.IsPressed("DOT")) ret ^= 1; - if (Controller.IsPressed("2")) ret ^= 2; - if (Controller.IsPressed("5")) ret ^= 4; - if (Controller.IsPressed("8")) ret ^= 8; - if (Controller.IsPressed("PARAOPEN")) ret ^= 16; - if (Controller.IsPressed("COS")) ret ^= 32; - if (Controller.IsPressed("PRGM")) ret ^= 64; - if (Controller.IsPressed("STAT")) ret ^= 128; - } - if ((keyboardMask & 16) == 0) - { - if (Controller.IsPressed("0")) ret ^= 1; - if (Controller.IsPressed("1")) ret ^= 2; - if (Controller.IsPressed("4")) ret ^= 4; - if (Controller.IsPressed("7")) ret ^= 8; - if (Controller.IsPressed("COMMA")) ret ^= 16; - if (Controller.IsPressed("SIN")) ret ^= 32; - if (Controller.IsPressed("MATRIX")) ret ^= 64; - if (Controller.IsPressed("X")) ret ^= 128; - } + int ret = 0xFF; + //Console.WriteLine("keyboardMask: {0:X2}",keyboardMask); + if ((keyboardMask & 1) == 0) + { + if (Controller.IsPressed("DOWN")) ret ^= 1; + if (Controller.IsPressed("LEFT")) ret ^= 2; + if (Controller.IsPressed("RIGHT")) ret ^= 4; + if (Controller.IsPressed("UP")) ret ^= 8; + } + if ((keyboardMask & 2) == 0) + { + if (Controller.IsPressed("ENTER")) ret ^= 1; + if (Controller.IsPressed("PLUS")) ret ^= 2; + if (Controller.IsPressed("MINUS")) ret ^= 4; + if (Controller.IsPressed("MULTIPLY")) ret ^= 8; + if (Controller.IsPressed("DIVIDE")) ret ^= 16; + if (Controller.IsPressed("EXP")) ret ^= 32; + if (Controller.IsPressed("CLEAR")) ret ^= 64; + } + if ((keyboardMask & 4) == 0) + { + if (Controller.IsPressed("DASH")) ret ^= 1; + if (Controller.IsPressed("3")) ret ^= 2; + if (Controller.IsPressed("6")) ret ^= 4; + if (Controller.IsPressed("9")) ret ^= 8; + if (Controller.IsPressed("PARACLOSE")) ret ^= 16; + if (Controller.IsPressed("TAN")) ret ^= 32; + if (Controller.IsPressed("VARS")) ret ^= 64; + } + if ((keyboardMask & 8) == 0) + { + if (Controller.IsPressed("DOT")) ret ^= 1; + if (Controller.IsPressed("2")) ret ^= 2; + if (Controller.IsPressed("5")) ret ^= 4; + if (Controller.IsPressed("8")) ret ^= 8; + if (Controller.IsPressed("PARAOPEN")) ret ^= 16; + if (Controller.IsPressed("COS")) ret ^= 32; + if (Controller.IsPressed("PRGM")) ret ^= 64; + if (Controller.IsPressed("STAT")) ret ^= 128; + } + if ((keyboardMask & 16) == 0) + { + if (Controller.IsPressed("0")) ret ^= 1; + if (Controller.IsPressed("1")) ret ^= 2; + if (Controller.IsPressed("4")) ret ^= 4; + if (Controller.IsPressed("7")) ret ^= 8; + if (Controller.IsPressed("COMMA")) ret ^= 16; + if (Controller.IsPressed("SIN")) ret ^= 32; + if (Controller.IsPressed("MATRIX")) ret ^= 64; + if (Controller.IsPressed("X")) ret ^= 128; + } - if ((keyboardMask & 32) == 0) - { - if (Controller.IsPressed("STO")) ret ^= 2; - if (Controller.IsPressed("LN")) ret ^= 4; - if (Controller.IsPressed("LOG")) ret ^= 8; - if (Controller.IsPressed("SQUARED")) ret ^= 16; - if (Controller.IsPressed("NEG1")) ret ^= 32; - if (Controller.IsPressed("MATH")) - ret ^= 64; - if (Controller.IsPressed("ALPHA")) ret ^= 128; - } + if ((keyboardMask & 32) == 0) + { + if (Controller.IsPressed("STO")) ret ^= 2; + if (Controller.IsPressed("LN")) ret ^= 4; + if (Controller.IsPressed("LOG")) ret ^= 8; + if (Controller.IsPressed("SQUARED")) ret ^= 16; + if (Controller.IsPressed("NEG1")) ret ^= 32; + if (Controller.IsPressed("MATH")) + ret ^= 64; + if (Controller.IsPressed("ALPHA")) ret ^= 128; + } - if ((keyboardMask & 64) == 0) - { - if (Controller.IsPressed("GRAPH")) ret ^= 1; - if (Controller.IsPressed("TRACE")) ret ^= 2; - if (Controller.IsPressed("ZOOM")) ret ^= 4; - if (Controller.IsPressed("WINDOW")) ret ^= 8; - if (Controller.IsPressed("Y")) ret ^= 16; - if (Controller.IsPressed("2ND")) ret ^= 32; - if (Controller.IsPressed("MODE")) ret ^= 64; - if (Controller.IsPressed("DEL")) ret ^= 128; - } + if ((keyboardMask & 64) == 0) + { + if (Controller.IsPressed("GRAPH")) ret ^= 1; + if (Controller.IsPressed("TRACE")) ret ^= 2; + if (Controller.IsPressed("ZOOM")) ret ^= 4; + if (Controller.IsPressed("WINDOW")) ret ^= 8; + if (Controller.IsPressed("Y")) ret ^= 16; + if (Controller.IsPressed("2ND")) ret ^= 32; + if (Controller.IsPressed("MODE")) ret ^= 64; + if (Controller.IsPressed("DEL")) ret ^= 128; + } - return (byte)ret; + return (byte)ret; - } + } - byte ReadDispData() - { - if (m_CursorMoved) - { - m_CursorMoved = false; - return 0x00; //not accurate this should be stale data or something - } + byte ReadDispData() + { + if (m_CursorMoved) + { + m_CursorMoved = false; + return 0x00; //not accurate this should be stale data or something + } - byte ret; - if (disp_mode == 1) - { - ret = vram[disp_y * 12 + disp_x]; - } - else - { - int column = 6 * (int)disp_x; - int offset = (int)disp_y * 12 + (column >> 3); - int shift = 10 - (column & 7); - ret = (byte)(((vram[offset] << 8) | vram[offset + 1]) >> shift); - } + byte ret; + if (disp_mode == 1) + { + ret = vram[disp_y * 12 + disp_x]; + } + else + { + int column = 6 * (int)disp_x; + int offset = (int)disp_y * 12 + (column >> 3); + int shift = 10 - (column & 7); + ret = (byte)(((vram[offset] << 8) | vram[offset + 1]) >> shift); + } - doDispMove(); - return ret; - } + doDispMove(); + return ret; + } - void WriteDispData(byte value) - { - int offset; - if (disp_mode == 1) - { - offset = (int)disp_y * 12 + (int)disp_x; - vram[offset] = value; - } - else - { - int column = 6 * (int)disp_x; - offset = (int)disp_y * 12 + (column >> 3); - if (offset < 0x300) - { - int shift = column & 7; - int mask = ~(252 >> shift); - int Data = value << 2; - vram[offset] = (byte)(vram[offset] & mask | (Data >> shift)); - if (shift > 2 && offset < 0x2ff) - { - offset++; + void WriteDispData(byte value) + { + int offset; + if (disp_mode == 1) + { + offset = (int)disp_y * 12 + (int)disp_x; + vram[offset] = value; + } + else + { + int column = 6 * (int)disp_x; + offset = (int)disp_y * 12 + (column >> 3); + if (offset < 0x300) + { + int shift = column & 7; + int mask = ~(252 >> shift); + int Data = value << 2; + vram[offset] = (byte)(vram[offset] & mask | (Data >> shift)); + if (shift > 2 && offset < 0x2ff) + { + offset++; - shift = 8 - shift; + shift = 8 - shift; - mask = ~(252 << shift); - vram[offset] = (byte)(vram[offset] & mask | (Data << shift)); - } - } - } + mask = ~(252 << shift); + vram[offset] = (byte)(vram[offset] & mask | (Data << shift)); + } + } + } - doDispMove(); - } + doDispMove(); + } - void doDispMove() - { - switch (disp_move) - { - case 0: disp_y--; break; - case 1: disp_y++; break; - case 2: disp_x--; break; - case 3: disp_x++; break; - } + void doDispMove() + { + switch (disp_move) + { + case 0: disp_y--; break; + case 1: disp_y++; break; + case 2: disp_x--; break; + case 3: disp_x++; break; + } - disp_x &= 0xF; //0xF or 0x1F? dunno - disp_y &= 0x3F; - } + disp_x &= 0xF; //0xF or 0x1F? dunno + disp_y &= 0x3F; + } - void WriteDispCtrl(byte value) - { - if (value <= 1) - disp_mode = value; - else if (value >= 4 && value <= 7) - disp_move = value - 4; - else if ((value & 0xC0) == 0x40) - { - //hardware scroll - } - else if ((value & 0xE0) == 0x20) - { - disp_x = (uint)(value & 0x1F); - m_CursorMoved = true; - } - else if ((value & 0xC0) == 0x80) - { - disp_y = (uint)(value & 0x3F); - m_CursorMoved = true; - } - else if ((value & 0xC0) == 0xC0) - { - //contrast - } - else if (value == 2) - { - } - else if (value == 3) - { - } - else - { - } - } + void WriteDispCtrl(byte value) + { + if (value <= 1) + disp_mode = value; + else if (value >= 4 && value <= 7) + disp_move = value - 4; + else if ((value & 0xC0) == 0x40) + { + //hardware scroll + } + else if ((value & 0xE0) == 0x20) + { + disp_x = (uint)(value & 0x1F); + m_CursorMoved = true; + } + else if ((value & 0xC0) == 0x80) + { + disp_y = (uint)(value & 0x3F); + m_CursorMoved = true; + } + else if ((value & 0xC0) == 0xC0) + { + //contrast + } + else if (value == 2) + { + } + else if (value == 3) + { + } + else + { + } + } - public TI83(CoreComm comm, GameInfo game, byte[] rom) - { - CoreComm = comm; - cpu.ReadMemory = ReadMemory; - cpu.WriteMemory = WriteMemory; - cpu.ReadHardware = ReadHardware; - cpu.WriteHardware = WriteHardware; - cpu.IRQCallback = IRQCallback; - cpu.NMICallback = NMICallback; + public TI83(CoreComm comm, GameInfo game, byte[] rom) + { + CoreComm = comm; + cpu.ReadMemory = ReadMemory; + cpu.WriteMemory = WriteMemory; + cpu.ReadHardware = ReadHardware; + cpu.WriteHardware = WriteHardware; + cpu.IRQCallback = IRQCallback; + cpu.NMICallback = NMICallback; - this.rom = rom; - this.LinkPort = new Link(this); + this.rom = rom; + LinkPort = new Link(this); - //different calculators (different revisions?) have different initPC. we track this in the game database by rom hash - //if( *(unsigned long *)(m_pRom + 0x6ce) == 0x04D3163E ) m_Regs.PC.W = 0x6ce; //KNOWN - //else if( *(unsigned long *)(m_pRom + 0x6f6) == 0x04D3163E ) m_Regs.PC.W = 0x6f6; //UNKNOWN + //different calculators (different revisions?) have different initPC. we track this in the game database by rom hash + //if( *(unsigned long *)(m_pRom + 0x6ce) == 0x04D3163E ) m_Regs.PC.W = 0x6ce; //KNOWN + //else if( *(unsigned long *)(m_pRom + 0x6f6) == 0x04D3163E ) m_Regs.PC.W = 0x6f6; //UNKNOWN - if (game["initPC"]) - startPC = ushort.Parse(game.OptionValue("initPC"), NumberStyles.HexNumber); + if (game["initPC"]) + startPC = ushort.Parse(game.OptionValue("initPC"), NumberStyles.HexNumber); - HardReset(); - SetupMemoryDomains(); - } + HardReset(); + SetupMemoryDomains(); + } - void IRQCallback() - { - //Console.WriteLine("IRQ with vec {0} and cpu.InterruptMode {1}", cpu.RegisterI, cpu.InterruptMode); - cpu.Interrupt = false; - } + void IRQCallback() + { + //Console.WriteLine("IRQ with vec {0} and cpu.InterruptMode {1}", cpu.RegisterI, cpu.InterruptMode); + cpu.Interrupt = false; + } - void NMICallback() - { - Console.WriteLine("NMI"); - cpu.NonMaskableInterrupt = false; - } + void NMICallback() + { + Console.WriteLine("NMI"); + cpu.NonMaskableInterrupt = false; + } - public CoreComm CoreComm { get; private set; } + public CoreComm CoreComm { get; private set; } - protected byte[] vram = new byte[0x300]; - class MyVideoProvider : IVideoProvider - { - private readonly TI83 emu; - public MyVideoProvider(TI83 emu) - { - this.emu = emu; - } + protected byte[] vram = new byte[0x300]; + class MyVideoProvider : IVideoProvider + { + private readonly TI83 emu; + public MyVideoProvider(TI83 emu) + { + this.emu = emu; + } - public int[] GetVideoBuffer() - { - //unflatten bit buffer - int[] pixels = new int[96 * 64]; - int i = 0; - for (int y = 0; y < 64; y++) - for (int x = 0; x < 96; x++) - { - int offset = y * 96 + x; - int bufbyte = offset >> 3; - int bufbit = offset & 7; - int bit = ((emu.vram[bufbyte] >> (7 - bufbit)) & 1); - if (bit == 0) - unchecked { pixels[i++] = (int)0xFFFFFFFF; } - else - pixels[i++] = 0; + public int[] GetVideoBuffer() + { + //unflatten bit buffer + int[] pixels = new int[96 * 64]; + int i = 0; + for (int y = 0; y < 64; y++) + for (int x = 0; x < 96; x++) + { + int offset = y * 96 + x; + int bufbyte = offset >> 3; + int bufbit = offset & 7; + int bit = ((emu.vram[bufbyte] >> (7 - bufbit)) & 1); + if (bit == 0) + unchecked { pixels[i++] = (int)0xFFFFFFFF; } + else + pixels[i++] = 0; - } - return pixels; - } - public int VirtualWidth { get { return 96; } } - public int BufferWidth { get { return 96; } } - public int BufferHeight { get { return 64; } } - public int BackgroundColor { get { return 0; } } - } - public IVideoProvider VideoProvider - { - get { return new MyVideoProvider(this); } - } + } + return pixels; + } + public int VirtualWidth { get { return 96; } } + public int BufferWidth { get { return 96; } } + public int BufferHeight { get { return 64; } } + public int BackgroundColor { get { return 0; } } + } + public IVideoProvider VideoProvider + { + get { return new MyVideoProvider(this); } + } - public ISoundProvider SoundProvider { get { return NullSound.SilenceProvider; } } - public ISyncSoundProvider SyncSoundProvider { get { return new FakeSyncSound(NullSound.SilenceProvider, 735); } } - public bool StartAsyncSound() { return true; } - public void EndAsyncSound() { } + public ISoundProvider SoundProvider { get { return NullSound.SilenceProvider; } } + public ISyncSoundProvider SyncSoundProvider { get { return new FakeSyncSound(NullSound.SilenceProvider, 735); } } + public bool StartAsyncSound() { return true; } + public void EndAsyncSound() { } - public static readonly ControllerDefinition TI83Controller = - new ControllerDefinition - { - Name = "TI83 Controller", - BoolButtons = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9","DOT", + public static readonly ControllerDefinition TI83Controller = + new ControllerDefinition + { + Name = "TI83 Controller", + BoolButtons = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9","DOT", "ON","ENTER", "DOWN","LEFT","UP","RIGHT", "PLUS","MINUS","MULTIPLY","DIVIDE", @@ -440,505 +438,501 @@ namespace BizHawk.Emulation.Consoles.Calculator "STO", "LN", "LOG", "SQUARED", "NEG1", "MATH", "ALPHA", "GRAPH", "TRACE", "ZOOM", "WINDOW", "Y", "2ND", "MODE", "DEL" } - }; - - public ControllerDefinition ControllerDefinition { get { return TI83Controller; } } - - IController controller; - public IController Controller - { - get { return controller; } - set { controller = value; } - } - //configuration - ushort startPC; - - public void FrameAdvance(bool render, bool rendersound) - { - lagged = true; - //I eyeballed this speed - for (int i = 0; i < 5; i++) - { - onPressed = Controller.IsPressed("ON"); - //and this was derived from other emus - cpu.ExecuteCycles(10000); - cpu.Interrupt = true; - } - Controller.UpdateControls(Frame++); - if (lagged) - { - _lagcount++; - islag = true; - } - else - islag = false; - } - - public void HardReset() - { - cpu.Reset(); - ram = new byte[0x8000]; - for (int i = 0; i < 0x8000; i++) - ram[i] = 0xFF; - cpu.RegisterPC = startPC; - - cpu.IFF1 = false; - cpu.IFF2 = false; - cpu.InterruptMode = 2; - - maskOn = 1; - romPageHighBit = 0; - romPageLow3Bits = 0; - keyboardMask = 0; - - disp_mode = 0; - disp_move = 0; - disp_x = disp_y = 0; - } - - private int _lagcount = 0; - private bool lagged = true; - private bool islag = false; - public int Frame { get; set; } - - public void ResetFrameCounter() - { - Frame = 0; - _lagcount = 0; - islag = false; - } - - public int LagCount { get { return _lagcount; } set { _lagcount = value; } } - public bool IsLagFrame { get { return islag; } } - - public bool DeterministicEmulation { get { return true; } } - - public byte[] ReadSaveRam() { return null; } - public void StoreSaveRam(byte[] data) { } - public void ClearSaveRam() { } - public bool SaveRamModified - { - get { return false; } - set { } - } - - public void SaveStateText(TextWriter writer) - { - writer.WriteLine("[TI83]\n"); - writer.WriteLine("Frame {0}", Frame); - cpu.SaveStateText(writer); - writer.Write("RAM "); - ram.SaveAsHex(writer); - writer.WriteLine("romPageLow3Bits {0}", romPageLow3Bits); - writer.WriteLine("romPageHighBit {0}", romPageHighBit); - writer.WriteLine("disp_mode {0}", disp_mode); - writer.WriteLine("disp_move {0}", disp_move); - writer.WriteLine("disp_x {0}", disp_x); - writer.WriteLine("disp_y {0}", disp_y); - writer.WriteLine("m_CursorMoved {0}", m_CursorMoved); - writer.WriteLine("maskOn {0}", maskOn); - writer.WriteLine("onPressed {0}", onPressed); - writer.WriteLine("keyboardMask {0}", keyboardMask); - writer.WriteLine("m_LinkOutput {0}", m_LinkOutput); - writer.WriteLine("m_LinkInput {0}", m_LinkInput); - writer.WriteLine("lag {0}", _lagcount); - writer.WriteLine("islag {0}", islag); - writer.WriteLine("vram {0}", Util.BytesToHexString(vram)); - writer.WriteLine("[/TI83]"); - } - - public void LoadStateText(TextReader reader) - { - while (true) - { - string[] args = reader.ReadLine().Split(' '); - if (args[0].Trim() == "") continue; - if (args[0] == "[TI83]") continue; - if (args[0] == "[/TI83]") break; - if (args[0] == "Frame") - Frame = int.Parse(args[1]); - else if (args[0] == "[Z80]") - cpu.LoadStateText(reader); - else if (args[0] == "RAM") - ram.ReadFromHex(args[1]); - else if (args[0] == "romPageLow3Bits") - romPageLow3Bits = int.Parse(args[1]); - else if (args[0] == "romPageHighBit") - romPageHighBit = int.Parse(args[1]); - else if (args[0] == "disp_mode") - disp_mode = int.Parse(args[1]); - else if (args[0] == "disp_move") - disp_move = int.Parse(args[1]); - else if (args[0] == "disp_x") - disp_x = uint.Parse(args[1]); - else if (args[0] == "disp_y") - disp_y = uint.Parse(args[1]); - else if (args[0] == "m_CursorMoved") - m_CursorMoved = bool.Parse(args[1]); - else if (args[0] == "maskOn") - maskOn = byte.Parse(args[1]); - else if (args[0] == "onPressed") - onPressed = bool.Parse(args[1]); - else if (args[0] == "keyboardMask") - keyboardMask = int.Parse(args[1]); - else if (args[0] == "m_LinkOutput") - m_LinkOutput = int.Parse(args[1]); - else if (args[0] == "m_LinkInput") - m_LinkInput = int.Parse(args[1]); - else if (args[0] == "lag") - _lagcount = int.Parse(args[1]); - else if (args[0] == "islag") - islag = bool.Parse(args[1]); - else if (args[0] == "vram") - vram = Util.HexStringToBytes(args[1]); - else - Console.WriteLine("Skipping unrecognized identifier " + args[0]); - } - } - - public void SaveStateBinary(BinaryWriter writer) - { - } - - public void LoadStateBinary(BinaryReader reader) - { - } - - public byte[] SaveStateBinary() - { - return new byte[0]; - } - - public bool BinarySaveStatesPreferred { get { return false; } } - - public string SystemId { get { return "TI83"; } } - - public string BoardName { get { return null; } } - - private IList memoryDomains; - private const ushort RamSizeMask = 0x7FFF; - - private void SetupMemoryDomains() - { - var domains = new List(); - var MainMemoryDomain = new MemoryDomain("Main RAM", ram.Length, Endian.Little, - addr => ram[addr & RamSizeMask], - (addr, value) => ram[addr & RamSizeMask] = value); - domains.Add(MainMemoryDomain); - memoryDomains = domains.AsReadOnly(); - } - - public IList MemoryDomains { get { return memoryDomains; } } - public MemoryDomain MainMemory { get { return memoryDomains[0]; } } - - public void Dispose() { } - - public Link LinkPort; - public class Link - { - byte[] FileData; - TI83 Parent; - - private Action NextStep; - private Queue CurrentData = new Queue(); - private ushort BytesToSend; - private byte BitsLeft; - private byte CurrentByte; - private byte StepsLeft; - - private Status CurrentStatus = Status.Inactive; - - private enum Status - { - Inactive, - PrepareReceive, - PrepareSend, - Receive, - Send - } - - public Link(TI83 Parent) - { - this.Parent = Parent; - } - - public void Update() - { - if (CurrentStatus == Status.PrepareReceive) - { - //Get the first byte, and start sending it. - CurrentByte = CurrentData.Dequeue(); - CurrentStatus = Status.Receive; - BitsLeft = 8; - StepsLeft = 5; - } - - if (CurrentStatus == Status.PrepareSend && Parent.m_LinkState != 3) - { - CurrentStatus = Status.Send; - BitsLeft = 8; - StepsLeft = 5; - CurrentByte = 0; - } - - if (CurrentStatus == Status.Receive) - { - switch (StepsLeft) - { - case 5: - //Receive step 1: Lower the other device's line. - Parent.m_LinkInput = ((CurrentByte & 1) == 1) ? 2 : 1; - CurrentByte >>= 1; - StepsLeft--; - break; - - case 4: - //Receive step 2: Wait for the calc to lower the other line. - if ((Parent.m_LinkState & 3) == 0) - StepsLeft--; - break; - - case 3: - //Receive step 3: Raise the other device's line back up. - Parent.m_LinkInput = 0; - StepsLeft--; - break; - - case 2: - //Receive step 4: Wait for the calc to raise its line back up. - if ((Parent.m_LinkState & 3) == 3) - StepsLeft--; - break; - - case 1: - //Receive step 5: Finish. - BitsLeft--; - - if (BitsLeft == 0) - { - if (CurrentData.Count > 0) - CurrentStatus = Status.PrepareReceive; - else - { - CurrentStatus = Status.Inactive; - if (NextStep != null) - NextStep(); - } - } - else - //next bit in the current byte. - StepsLeft = 5; - break; - } - } - else if (CurrentStatus == Status.Send) - { - switch (StepsLeft) - { - case 5: - //Send step 1: Calc lowers a line. - if (Parent.m_LinkState != 3) - { - int Bit = Parent.m_LinkState & 1; - int Shift = 8 - BitsLeft; - CurrentByte |= (byte)(Bit << Shift); - StepsLeft--; - } - break; - - case 4: - //send step 2: Lower our line. - Parent.m_LinkInput = Parent.m_LinkOutput ^ 3; - StepsLeft--; - break; - - case 3: - //Send step 3: wait for the calc to raise its line. - if ((Parent.m_LinkOutput & 3) == 0) - StepsLeft--; - break; - - case 2: - //Send step 4: raise the other devices lines. - Parent.m_LinkInput = 0; - StepsLeft--; - break; - - case 1: - //Send step 5: Finish - BitsLeft--; - - if (BitsLeft == 0) - { - BytesToSend--; - CurrentData.Enqueue(CurrentByte); - - if (BytesToSend > 0) - CurrentStatus = Status.PrepareSend; - else - { - CurrentStatus = Status.Inactive; - if (NextStep != null) - NextStep(); - } - } - else - { - //next bit in the current byte. - StepsLeft = 5; - } - break; - } - } - } - - public void SendFileToCalc(FileStream FS) - { - FS.Seek(53, SeekOrigin.Begin); - int Size = FS.ReadByte() + FS.ReadByte() * 256; - - if (FS.Length != Size + 57) - throw new FormatException("Invalid calculator file."); - - byte[] Header = new byte[13]; - FS.Read(Header, 0, 13); - - FileData = new byte[Size - 13]; - FS.Read(FileData, 0, Size - 13); - - //Request to send the file. - CurrentData.Clear(); - - CurrentData.Enqueue(0x03); - CurrentData.Enqueue(0xC9); - - foreach (byte B in Header) - CurrentData.Enqueue(B); - - //Calculate the checksum for the command. - ushort Checksum = 0; - for (int n = 2; n < Header.Length; n++) - Checksum += Header[n]; - - CurrentData.Enqueue((byte)(Checksum % 256)); - CurrentData.Enqueue((byte)(Checksum / 256)); - - //Finalize the command. - CurrentStatus = Status.PrepareReceive; - NextStep = new Action(ReceiveReqAck); - Parent.LinkActive = true; - } - - private void ReceiveReqAck() - { - Parent.LinkActive = false; - CurrentData.Clear(); - - //Prepare to receive the Aknowledgement response from the calculator. - BytesToSend = 8; - CurrentStatus = Status.PrepareSend; - NextStep = new Action(SendVariableData); - } - - private void SendVariableData() - { - //Check to see if out of memory first. - CurrentData.Dequeue(); - CurrentData.Dequeue(); - CurrentData.Dequeue(); - CurrentData.Dequeue(); - CurrentData.Dequeue(); - - if (CurrentData.Dequeue() == 0x36) - OutOfMemory(); - else - { - CurrentData.Clear(); - - CurrentData.Enqueue(0x03); - CurrentData.Enqueue(0x56); - CurrentData.Enqueue(0x00); - CurrentData.Enqueue(0x00); - - CurrentData.Enqueue(0x03); - CurrentData.Enqueue(0x15); - - //Add variable data. - foreach (byte B in FileData) - CurrentData.Enqueue(B); - - //Calculate the checksum. - ushort Checksum = 0; - for (int n = 2; n < FileData.Length; n++) - Checksum += FileData[n]; - - CurrentData.Enqueue((byte)(Checksum % 256)); - CurrentData.Enqueue((byte)(Checksum / 256)); - - CurrentStatus = Status.PrepareReceive; - NextStep = new Action(ReceiveDataAck); - Parent.LinkActive = true; - } - } - - private void ReceiveDataAck() - { - Parent.LinkActive = false; - CurrentData.Clear(); - - //Prepare to receive the Aknowledgement response from the calculator. - BytesToSend = 4; - CurrentStatus = Status.PrepareSend; - NextStep = new Action(EndTransmission); - } - - private void EndTransmission() - { - CurrentData.Clear(); - - //Send the end transmission command. - CurrentData.Enqueue(0x03); - CurrentData.Enqueue(0x92); - CurrentData.Enqueue(0x00); - CurrentData.Enqueue(0x00); - - CurrentStatus = Status.PrepareReceive; - NextStep = new Action(Finalize); - Parent.LinkActive = true; - } - - private void OutOfMemory() - { - Parent.LinkActive = false; - CurrentData.Clear(); - - //Prepare to receive the Aknowledgement response from the calculator. - BytesToSend = 3; - CurrentStatus = Status.PrepareSend; - NextStep = new Action(EndOutOfMemory); - } - - private void EndOutOfMemory() - { - CurrentData.Clear(); - - //Send the end transmission command. - CurrentData.Enqueue(0x03); - CurrentData.Enqueue(0x56); - CurrentData.Enqueue(0x01); - CurrentData.Enqueue(0x00); - - CurrentStatus = Status.PrepareReceive; - NextStep = new Action(Finalize); - Parent.LinkActive = true; - } - - private void Finalize() - { - CurrentData.Clear(); - Parent.LinkActive = false; - NextStep = null; - } - } - } + }; + + public ControllerDefinition ControllerDefinition { get { return TI83Controller; } } + + public IController Controller { get; set; } + + //configuration + ushort startPC; + + public void FrameAdvance(bool render, bool rendersound) + { + lagged = true; + //I eyeballed this speed + for (int i = 0; i < 5; i++) + { + onPressed = Controller.IsPressed("ON"); + //and this was derived from other emus + cpu.ExecuteCycles(10000); + cpu.Interrupt = true; + } + Controller.UpdateControls(Frame++); + if (lagged) + { + _lagcount++; + islag = true; + } + else + islag = false; + } + + public void HardReset() + { + cpu.Reset(); + ram = new byte[0x8000]; + for (int i = 0; i < 0x8000; i++) + ram[i] = 0xFF; + cpu.RegisterPC = startPC; + + cpu.IFF1 = false; + cpu.IFF2 = false; + cpu.InterruptMode = 2; + + maskOn = 1; + romPageHighBit = 0; + romPageLow3Bits = 0; + keyboardMask = 0; + + disp_mode = 0; + disp_move = 0; + disp_x = disp_y = 0; + } + + private int _lagcount = 0; + private bool lagged = true; + private bool islag = false; + public int Frame { get; set; } + + public void ResetFrameCounter() + { + Frame = 0; + _lagcount = 0; + islag = false; + } + + public int LagCount { get { return _lagcount; } set { _lagcount = value; } } + public bool IsLagFrame { get { return islag; } } + + public bool DeterministicEmulation { get { return true; } } + + public byte[] ReadSaveRam() { return null; } + public void StoreSaveRam(byte[] data) { } + public void ClearSaveRam() { } + public bool SaveRamModified + { + get { return false; } + set { } + } + + public void SaveStateText(TextWriter writer) + { + writer.WriteLine("[TI83]\n"); + writer.WriteLine("Frame {0}", Frame); + cpu.SaveStateText(writer); + writer.Write("RAM "); + ram.SaveAsHex(writer); + writer.WriteLine("romPageLow3Bits {0}", romPageLow3Bits); + writer.WriteLine("romPageHighBit {0}", romPageHighBit); + writer.WriteLine("disp_mode {0}", disp_mode); + writer.WriteLine("disp_move {0}", disp_move); + writer.WriteLine("disp_x {0}", disp_x); + writer.WriteLine("disp_y {0}", disp_y); + writer.WriteLine("m_CursorMoved {0}", m_CursorMoved); + writer.WriteLine("maskOn {0}", maskOn); + writer.WriteLine("onPressed {0}", onPressed); + writer.WriteLine("keyboardMask {0}", keyboardMask); + writer.WriteLine("m_LinkOutput {0}", m_LinkOutput); + writer.WriteLine("m_LinkInput {0}", m_LinkInput); + writer.WriteLine("lag {0}", _lagcount); + writer.WriteLine("islag {0}", islag); + writer.WriteLine("vram {0}", Util.BytesToHexString(vram)); + writer.WriteLine("[/TI83]"); + } + + public void LoadStateText(TextReader reader) + { + while (true) + { + string[] args = reader.ReadLine().Split(' '); + if (args[0].Trim() == "") continue; + if (args[0] == "[TI83]") continue; + if (args[0] == "[/TI83]") break; + if (args[0] == "Frame") + Frame = int.Parse(args[1]); + else if (args[0] == "[Z80]") + cpu.LoadStateText(reader); + else if (args[0] == "RAM") + ram.ReadFromHex(args[1]); + else if (args[0] == "romPageLow3Bits") + romPageLow3Bits = int.Parse(args[1]); + else if (args[0] == "romPageHighBit") + romPageHighBit = int.Parse(args[1]); + else if (args[0] == "disp_mode") + disp_mode = int.Parse(args[1]); + else if (args[0] == "disp_move") + disp_move = int.Parse(args[1]); + else if (args[0] == "disp_x") + disp_x = uint.Parse(args[1]); + else if (args[0] == "disp_y") + disp_y = uint.Parse(args[1]); + else if (args[0] == "m_CursorMoved") + m_CursorMoved = bool.Parse(args[1]); + else if (args[0] == "maskOn") + maskOn = byte.Parse(args[1]); + else if (args[0] == "onPressed") + onPressed = bool.Parse(args[1]); + else if (args[0] == "keyboardMask") + keyboardMask = int.Parse(args[1]); + else if (args[0] == "m_LinkOutput") + m_LinkOutput = int.Parse(args[1]); + else if (args[0] == "m_LinkInput") + m_LinkInput = int.Parse(args[1]); + else if (args[0] == "lag") + _lagcount = int.Parse(args[1]); + else if (args[0] == "islag") + islag = bool.Parse(args[1]); + else if (args[0] == "vram") + vram = Util.HexStringToBytes(args[1]); + else + Console.WriteLine("Skipping unrecognized identifier " + args[0]); + } + } + + public void SaveStateBinary(BinaryWriter writer) + { + } + + public void LoadStateBinary(BinaryReader reader) + { + } + + public byte[] SaveStateBinary() + { + return new byte[0]; + } + + public bool BinarySaveStatesPreferred { get { return false; } } + + public string SystemId { get { return "TI83"; } } + + public string BoardName { get { return null; } } + + private IList memoryDomains; + private const ushort RamSizeMask = 0x7FFF; + + private void SetupMemoryDomains() + { + var domains = new List(); + var MainMemoryDomain = new MemoryDomain("Main RAM", ram.Length, Endian.Little, + addr => ram[addr & RamSizeMask], + (addr, value) => ram[addr & RamSizeMask] = value); + domains.Add(MainMemoryDomain); + memoryDomains = domains.AsReadOnly(); + } + + public IList MemoryDomains { get { return memoryDomains; } } + public MemoryDomain MainMemory { get { return memoryDomains[0]; } } + + public void Dispose() { } + + public Link LinkPort; + public class Link + { + byte[] FileData; + readonly TI83 Parent; + + private Action NextStep; + private Queue CurrentData = new Queue(); + private ushort BytesToSend; + private byte BitsLeft; + private byte CurrentByte; + private byte StepsLeft; + + private Status CurrentStatus = Status.Inactive; + + private enum Status + { + Inactive, + PrepareReceive, + PrepareSend, + Receive, + Send + } + + public Link(TI83 Parent) + { + this.Parent = Parent; + } + + public void Update() + { + if (CurrentStatus == Status.PrepareReceive) + { + //Get the first byte, and start sending it. + CurrentByte = CurrentData.Dequeue(); + CurrentStatus = Status.Receive; + BitsLeft = 8; + StepsLeft = 5; + } + + if (CurrentStatus == Status.PrepareSend && Parent.m_LinkState != 3) + { + CurrentStatus = Status.Send; + BitsLeft = 8; + StepsLeft = 5; + CurrentByte = 0; + } + + if (CurrentStatus == Status.Receive) + { + switch (StepsLeft) + { + case 5: + //Receive step 1: Lower the other device's line. + Parent.m_LinkInput = ((CurrentByte & 1) == 1) ? 2 : 1; + CurrentByte >>= 1; + StepsLeft--; + break; + + case 4: + //Receive step 2: Wait for the calc to lower the other line. + if ((Parent.m_LinkState & 3) == 0) + StepsLeft--; + break; + + case 3: + //Receive step 3: Raise the other device's line back up. + Parent.m_LinkInput = 0; + StepsLeft--; + break; + + case 2: + //Receive step 4: Wait for the calc to raise its line back up. + if ((Parent.m_LinkState & 3) == 3) + StepsLeft--; + break; + + case 1: + //Receive step 5: Finish. + BitsLeft--; + + if (BitsLeft == 0) + { + if (CurrentData.Count > 0) + CurrentStatus = Status.PrepareReceive; + else + { + CurrentStatus = Status.Inactive; + if (NextStep != null) + NextStep(); + } + } + else + //next bit in the current byte. + StepsLeft = 5; + break; + } + } + else if (CurrentStatus == Status.Send) + { + switch (StepsLeft) + { + case 5: + //Send step 1: Calc lowers a line. + if (Parent.m_LinkState != 3) + { + int Bit = Parent.m_LinkState & 1; + int Shift = 8 - BitsLeft; + CurrentByte |= (byte)(Bit << Shift); + StepsLeft--; + } + break; + + case 4: + //send step 2: Lower our line. + Parent.m_LinkInput = Parent.m_LinkOutput ^ 3; + StepsLeft--; + break; + + case 3: + //Send step 3: wait for the calc to raise its line. + if ((Parent.m_LinkOutput & 3) == 0) + StepsLeft--; + break; + + case 2: + //Send step 4: raise the other devices lines. + Parent.m_LinkInput = 0; + StepsLeft--; + break; + + case 1: + //Send step 5: Finish + BitsLeft--; + + if (BitsLeft == 0) + { + BytesToSend--; + CurrentData.Enqueue(CurrentByte); + + if (BytesToSend > 0) + CurrentStatus = Status.PrepareSend; + else + { + CurrentStatus = Status.Inactive; + if (NextStep != null) + NextStep(); + } + } + else + { + //next bit in the current byte. + StepsLeft = 5; + } + break; + } + } + } + + public void SendFileToCalc(FileStream FS) + { + FS.Seek(53, SeekOrigin.Begin); + int Size = FS.ReadByte() + FS.ReadByte() * 256; + + if (FS.Length != Size + 57) + throw new FormatException("Invalid calculator file."); + + byte[] Header = new byte[13]; + FS.Read(Header, 0, 13); + + FileData = new byte[Size - 13]; + FS.Read(FileData, 0, Size - 13); + + //Request to send the file. + CurrentData.Clear(); + + CurrentData.Enqueue(0x03); + CurrentData.Enqueue(0xC9); + + foreach (byte B in Header) + CurrentData.Enqueue(B); + + //Calculate the checksum for the command. + ushort Checksum = 0; + for (int n = 2; n < Header.Length; n++) + Checksum += Header[n]; + + CurrentData.Enqueue((byte)(Checksum % 256)); + CurrentData.Enqueue((byte)(Checksum / 256)); + + //Finalize the command. + CurrentStatus = Status.PrepareReceive; + NextStep = ReceiveReqAck; + Parent.LinkActive = true; + } + + private void ReceiveReqAck() + { + Parent.LinkActive = false; + CurrentData.Clear(); + + //Prepare to receive the Aknowledgement response from the calculator. + BytesToSend = 8; + CurrentStatus = Status.PrepareSend; + NextStep = SendVariableData; + } + + private void SendVariableData() + { + //Check to see if out of memory first. + CurrentData.Dequeue(); + CurrentData.Dequeue(); + CurrentData.Dequeue(); + CurrentData.Dequeue(); + CurrentData.Dequeue(); + + if (CurrentData.Dequeue() == 0x36) + OutOfMemory(); + else + { + CurrentData.Clear(); + + CurrentData.Enqueue(0x03); + CurrentData.Enqueue(0x56); + CurrentData.Enqueue(0x00); + CurrentData.Enqueue(0x00); + + CurrentData.Enqueue(0x03); + CurrentData.Enqueue(0x15); + + //Add variable data. + foreach (byte B in FileData) + CurrentData.Enqueue(B); + + //Calculate the checksum. + ushort Checksum = 0; + for (int n = 2; n < FileData.Length; n++) + Checksum += FileData[n]; + + CurrentData.Enqueue((byte)(Checksum % 256)); + CurrentData.Enqueue((byte)(Checksum / 256)); + + CurrentStatus = Status.PrepareReceive; + NextStep = ReceiveDataAck; + Parent.LinkActive = true; + } + } + + private void ReceiveDataAck() + { + Parent.LinkActive = false; + CurrentData.Clear(); + + //Prepare to receive the Aknowledgement response from the calculator. + BytesToSend = 4; + CurrentStatus = Status.PrepareSend; + NextStep = EndTransmission; + } + + private void EndTransmission() + { + CurrentData.Clear(); + + //Send the end transmission command. + CurrentData.Enqueue(0x03); + CurrentData.Enqueue(0x92); + CurrentData.Enqueue(0x00); + CurrentData.Enqueue(0x00); + + CurrentStatus = Status.PrepareReceive; + NextStep = Finalize; + Parent.LinkActive = true; + } + + private void OutOfMemory() + { + Parent.LinkActive = false; + CurrentData.Clear(); + + //Prepare to receive the Aknowledgement response from the calculator. + BytesToSend = 3; + CurrentStatus = Status.PrepareSend; + NextStep = EndOutOfMemory; + } + + private void EndOutOfMemory() + { + CurrentData.Clear(); + + //Send the end transmission command. + CurrentData.Enqueue(0x03); + CurrentData.Enqueue(0x56); + CurrentData.Enqueue(0x01); + CurrentData.Enqueue(0x00); + + CurrentStatus = Status.PrepareReceive; + NextStep = Finalize; + Parent.LinkActive = true; + } + + private void Finalize() + { + CurrentData.Clear(); + Parent.LinkActive = false; + NextStep = null; + } + } + } } \ No newline at end of file diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs index 2397c8ddbe..7621b29c99 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs @@ -280,7 +280,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo #if VS2012 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - protected void RunCpuOne() + private void RunCpuOne() { cpu_stepcounter++; if (cpu_stepcounter == cpu_sequence[cpu_step]) diff --git a/BizHawk.Emulation/DiscSystem/Disc.cs b/BizHawk.Emulation/DiscSystem/Disc.cs index f5d713c9ca..95ee451138 100644 --- a/BizHawk.Emulation/DiscSystem/Disc.cs +++ b/BizHawk.Emulation/DiscSystem/Disc.cs @@ -111,7 +111,7 @@ namespace BizHawk.DiscSystem throw new NotImplementedException("Blob_ZeroPadAdapter hasnt been tested yet! please report this!"); //something about this seems unnecessarily complex, but... i dunno. - + /* //figure out how much remains until the zero-padding begins long remain = byte_pos - padFrom; int todo; @@ -144,6 +144,7 @@ namespace BizHawk.DiscSystem totalRead += todo; return totalRead; + */ } public void Dispose() diff --git a/BizHawk.MultiClient/GENtools/GenGameGenie.Designer.cs b/BizHawk.MultiClient/GENtools/GenGameGenie.Designer.cs index eaa3095a38..ec4bf8b261 100644 --- a/BizHawk.MultiClient/GENtools/GenGameGenie.Designer.cs +++ b/BizHawk.MultiClient/GENtools/GenGameGenie.Designer.cs @@ -55,11 +55,12 @@ // // menuStrip1 // + this.menuStrip1.ClickThrough = true; this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.optionsToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(302, 24); + this.menuStrip1.Size = new System.Drawing.Size(292, 24); this.menuStrip1.TabIndex = 8; this.menuStrip1.Text = "menuStrip1"; // @@ -104,7 +105,7 @@ // GGCodeMaskBox // this.GGCodeMaskBox.Location = new System.Drawing.Point(18, 30); - this.GGCodeMaskBox.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.GGCodeMaskBox.Margin = new System.Windows.Forms.Padding(2); this.GGCodeMaskBox.Mask = ">AAAA-AAAA"; this.GGCodeMaskBox.Name = "GGCodeMaskBox"; this.GGCodeMaskBox.Size = new System.Drawing.Size(76, 20); @@ -118,7 +119,7 @@ // this.addcheatbt.Enabled = false; this.addcheatbt.Location = new System.Drawing.Point(156, 117); - this.addcheatbt.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.addcheatbt.Margin = new System.Windows.Forms.Padding(2); this.addcheatbt.Name = "addcheatbt"; this.addcheatbt.Size = new System.Drawing.Size(72, 26); this.addcheatbt.TabIndex = 10; @@ -223,7 +224,7 @@ // ClearBT // this.ClearBT.Location = new System.Drawing.Point(66, 117); - this.ClearBT.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.ClearBT.Margin = new System.Windows.Forms.Padding(2); this.ClearBT.Name = "ClearBT"; this.ClearBT.Size = new System.Drawing.Size(68, 26); this.ClearBT.TabIndex = 13; @@ -235,9 +236,9 @@ // this.groupBox2.Controls.Add(this.cheatname); this.groupBox2.Location = new System.Drawing.Point(20, 154); - this.groupBox2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.groupBox2.Margin = new System.Windows.Forms.Padding(2); this.groupBox2.Name = "groupBox2"; - this.groupBox2.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.groupBox2.Padding = new System.Windows.Forms.Padding(2); this.groupBox2.Size = new System.Drawing.Size(266, 50); this.groupBox2.TabIndex = 14; this.groupBox2.TabStop = false; @@ -246,7 +247,7 @@ // cheatname // this.cheatname.Location = new System.Drawing.Point(18, 24); - this.cheatname.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.cheatname.Margin = new System.Windows.Forms.Padding(2); this.cheatname.Name = "cheatname"; this.cheatname.Size = new System.Drawing.Size(228, 20); this.cheatname.TabIndex = 0; @@ -255,7 +256,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(302, 217); + this.ClientSize = new System.Drawing.Size(292, 217); this.Controls.Add(this.groupBox2); this.Controls.Add(this.ClearBT); this.Controls.Add(this.groupBox1); @@ -272,6 +273,7 @@ this.Name = "GenGameGenie"; this.ShowIcon = false; this.Text = "Genesis Game Genie Encoder / Decoder"; + this.Load += new System.EventHandler(this.GENGameGenie_Load); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.GameGenieCodeBox.ResumeLayout(false); diff --git a/BizHawk.MultiClient/GENtools/GenGameGenie.cs b/BizHawk.MultiClient/GENtools/GenGameGenie.cs index 6720a6421b..de670fdc3c 100644 --- a/BizHawk.MultiClient/GENtools/GenGameGenie.cs +++ b/BizHawk.MultiClient/GENtools/GenGameGenie.cs @@ -6,6 +6,8 @@ using System.Globalization; using System.Text.RegularExpressions; using BizHawk.Emulation.Consoles.Sega; +#pragma warning disable 675 //TOOD: fix the potential problem this is masking + namespace BizHawk.MultiClient { public partial class GenGameGenie : Form @@ -295,9 +297,11 @@ namespace BizHawk.MultiClient private void GENGameGenie_Load(object sender, EventArgs e) { - + if (Global.Config.GENGGSaveWindowPosition && Global.Config.GENGGWndx >= 0 && Global.Config.GENGGWndy >= 0) + { Location = new Point(Global.Config.GENGGWndx, Global.Config.GENGGWndy); + } } private void SaveConfigSettings() diff --git a/BizHawk.MultiClient/Program.cs b/BizHawk.MultiClient/Program.cs index 6f9d2b8420..96d2a38ae0 100644 --- a/BizHawk.MultiClient/Program.cs +++ b/BizHawk.MultiClient/Program.cs @@ -91,7 +91,7 @@ namespace BizHawk.MultiClient { new SingleInstanceController(args).Run(args); } - catch (ObjectDisposedException ex) + catch (ObjectDisposedException) { /*Eat it, MainForm disposed itself and Run attempts to dispose of itself. Eventually we would want to figure out a way to prevent that, but in the meantime it is harmless, so just eat the error*/ } diff --git a/BizHawk.MultiClient/config/RewindConfig.cs b/BizHawk.MultiClient/config/RewindConfig.cs index 39e90bae60..e208676578 100644 --- a/BizHawk.MultiClient/config/RewindConfig.cs +++ b/BizHawk.MultiClient/config/RewindConfig.cs @@ -28,47 +28,38 @@ namespace BizHawk.MultiClient RewindFramesUsedLabel.Text = "N/A"; } - try - { - DiskBufferCheckbox.Checked = Global.Config.Rewind_OnDisk; - RewindIsThreadedCheckbox.Checked = Global.Config.Rewind_IsThreaded; - StateSize = Global.Emulator.SaveStateBinary().Length; - BufferSizeUpDown.Value = Global.Config.Rewind_BufferSize; + + DiskBufferCheckbox.Checked = Global.Config.Rewind_OnDisk; + RewindIsThreadedCheckbox.Checked = Global.Config.Rewind_IsThreaded; + StateSize = Global.Emulator.SaveStateBinary().Length; + BufferSizeUpDown.Value = Global.Config.Rewind_BufferSize; - MediumStateSize = Global.Config.Rewind_MediumStateSize; - LargeStateSize = Global.Config.Rewind_LargeStateSize; + MediumStateSize = Global.Config.Rewind_MediumStateSize; + LargeStateSize = Global.Config.Rewind_LargeStateSize; - UseDeltaCompression.Checked = Global.Config.Rewind_UseDelta; + UseDeltaCompression.Checked = Global.Config.Rewind_UseDelta; - SmallSavestateNumeric.Value = Global.Config.RewindFrequencySmall; - MediumSavestateNumeric.Value = Global.Config.RewindFrequencyMedium; - LargeSavestateNumeric.Value = Global.Config.RewindFrequencyLarge; + SmallSavestateNumeric.Value = Global.Config.RewindFrequencySmall; + MediumSavestateNumeric.Value = Global.Config.RewindFrequencyMedium; + LargeSavestateNumeric.Value = Global.Config.RewindFrequencyLarge; - SmallStateEnabledBox.Checked = Global.Config.RewindEnabledSmall; - MediumStateEnabledBox.Checked = Global.Config.RewindEnabledMedium; - LargeStateEnabledBox.Checked = Global.Config.RewindEnabledLarge; + SmallStateEnabledBox.Checked = Global.Config.RewindEnabledSmall; + MediumStateEnabledBox.Checked = Global.Config.RewindEnabledMedium; + LargeStateEnabledBox.Checked = Global.Config.RewindEnabledLarge; - SetSmallEnabled(); - SetMediumEnabled(); - SetLargeEnabled(); + SetSmallEnabled(); + SetMediumEnabled(); + SetLargeEnabled(); - SetStateSize(); + SetStateSize(); - int medium_state_size_kb = Global.Config.Rewind_MediumStateSize / 1024; - int large_state_size_kb = Global.Config.Rewind_LargeStateSize / 1024; + int medium_state_size_kb = Global.Config.Rewind_MediumStateSize / 1024; + int large_state_size_kb = Global.Config.Rewind_LargeStateSize / 1024; - MediumStateTrackbar.Value = medium_state_size_kb; - MediumStateUpDown.Value = (decimal)medium_state_size_kb; - LargeStateTrackbar.Value = large_state_size_kb; - LargeStateUpDown.Value = (decimal)large_state_size_kb; - } - catch (Exception ex) - { - int x = 0; - x++; - int y = x; - y++; - } + MediumStateTrackbar.Value = medium_state_size_kb; + MediumStateUpDown.Value = (decimal)medium_state_size_kb; + LargeStateTrackbar.Value = large_state_size_kb; + LargeStateUpDown.Value = (decimal)large_state_size_kb; } private void SetStateSize() diff --git a/BizHawk.MultiClient/tools/Watch/Watch.cs b/BizHawk.MultiClient/tools/Watch/Watch.cs index 6b72c257a2..c69be35794 100644 --- a/BizHawk.MultiClient/tools/Watch/Watch.cs +++ b/BizHawk.MultiClient/tools/Watch/Watch.cs @@ -276,14 +276,14 @@ namespace BizHawk.MultiClient /// public static Watch ConvertLegacyWatch(Watch_Legacy watch) { - Watch w = Watch.GenerateWatch( + Watch w = GenerateWatch( watch.Domain, watch.Address, - Watch.SizeFromChar(watch.TypeChar), + SizeFromChar(watch.TypeChar), !String.IsNullOrWhiteSpace(watch.Notes) ); - w.Type = Watch.DisplayTypeFromChar(watch.SignedChar); + w.Type = DisplayTypeFromChar(watch.SignedChar); if (!String.IsNullOrWhiteSpace(watch.Notes)) { diff --git a/BizHawk_2012.sln b/BizHawk_2012.sln index 89fe43c294..96a7eac34d 100644 --- a/BizHawk_2012.sln +++ b/BizHawk_2012.sln @@ -9,8 +9,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.MultiClient_v4.5", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiscoHawk_4.5", "DiscoHawk\DiscoHawk_4.5.csproj", "{C4366030-6D03-424B-AE53-F4F43BB217C3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.PCE_Debugger", "BizHawk.PCE_Debugger\BizHawk.PCE_Debugger.csproj", "{2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -79,20 +77,6 @@ Global {C4366030-6D03-424B-AE53-F4F43BB217C3}.Release|Win32.ActiveCfg = Release|Any CPU {C4366030-6D03-424B-AE53-F4F43BB217C3}.Release|Win32.Build.0 = Release|Any CPU {C4366030-6D03-424B-AE53-F4F43BB217C3}.Release|x86.ActiveCfg = Release|Any CPU - {2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}.Debug|Any CPU.ActiveCfg = Debug|x86 - {2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}.Debug|Mixed Platforms.Build.0 = Debug|x86 - {2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}.Debug|Win32.ActiveCfg = Debug|x86 - {2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}.Debug|Win32.Build.0 = Debug|x86 - {2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}.Debug|x86.ActiveCfg = Debug|x86 - {2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}.Debug|x86.Build.0 = Debug|x86 - {2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}.Release|Any CPU.ActiveCfg = Release|x86 - {2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}.Release|Mixed Platforms.Build.0 = Release|x86 - {2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}.Release|Win32.ActiveCfg = Release|x86 - {2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}.Release|Win32.Build.0 = Release|x86 - {2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}.Release|x86.ActiveCfg = Release|x86 - {2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE