Fixed indentation and TODOs

This commit is contained in:
Kabuto 2015-09-28 20:53:19 +02:00
parent 1e9564a337
commit f7c15bfd0f
15 changed files with 1136 additions and 1143 deletions

View File

@ -315,7 +315,7 @@ namespace BizHawk.Emulation.Common
case ".T64":
case ".G64":
case ".CRT":
case ".TAP":
case ".TAP":
game.System = "C64";
break;

View File

@ -2932,9 +2932,9 @@ namespace BizHawk.Emulation.Cores.Components.M6502
mi++;
} //ExecuteOne
public bool AtInstructionStart()
{
return Microcode[opcode][mi] >= Uop.End;
}
public bool AtInstructionStart()
{
return Microcode[opcode][mi] >= Uop.End;
}
}
}

View File

@ -51,110 +51,110 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
}
}
public bool CanStep(StepType type)
{
switch (type)
{
case StepType.Into:
case StepType.Over:
case StepType.Out:
return true;
default:
return false;
}
}
public bool CanStep(StepType type)
{
switch (type)
{
case StepType.Into:
case StepType.Over:
case StepType.Out:
return true;
default:
return false;
}
}
public void Step(StepType type)
{
switch (type)
{
case StepType.Into:
StepInto();
break;
case StepType.Out:
StepOut();
break;
case StepType.Over:
StepOver();
break;
}
}
public void Step(StepType type)
{
switch (type)
{
case StepType.Into:
StepInto();
break;
case StepType.Out:
StepOut();
break;
case StepType.Over:
StepOver();
break;
}
}
private void StepInto()
{
while (board.cpu.AtInstructionStart())
{
DoCycle();
}
while (!board.cpu.AtInstructionStart())
{
DoCycle();
}
}
private void StepInto()
{
while (board.cpu.AtInstructionStart())
{
DoCycle();
}
while (!board.cpu.AtInstructionStart())
{
DoCycle();
}
}
private void StepOver()
{
var instruction = board.cpu.Peek(board.cpu.PC);
private void StepOver()
{
var instruction = board.cpu.Peek(board.cpu.PC);
if (instruction == JSR)
{
var destination = board.cpu.PC + JSRSize;
while (board.cpu.PC != destination)
{
StepInto();
}
}
else
{
StepInto();
}
}
if (instruction == JSR)
{
var destination = board.cpu.PC + JSRSize;
while (board.cpu.PC != destination)
{
StepInto();
}
}
else
{
StepInto();
}
}
private void StepOut()
{
var instr = board.cpu.Peek(board.cpu.PC);
private void StepOut()
{
var instr = board.cpu.Peek(board.cpu.PC);
JSRCount = instr == JSR ? 1 : 0;
JSRCount = instr == JSR ? 1 : 0;
var bailOutFrame = Frame + 1;
var bailOutFrame = Frame + 1;
while (true)
{
StepInto();
instr = board.cpu.Peek(board.cpu.PC);
if (instr == JSR)
{
JSRCount++;
}
else if ((instr == RTS || instr == RTI) && JSRCount <= 0)
{
StepInto();
JSRCount = 0;
break;
}
else if (instr == RTS || instr == RTI)
{
JSRCount--;
}
else //Emergency Bailout Logic
{
if (Frame == bailOutFrame)
{
break;
}
}
}
}
while (true)
{
StepInto();
instr = board.cpu.Peek(board.cpu.PC);
if (instr == JSR)
{
JSRCount++;
}
else if ((instr == RTS || instr == RTI) && JSRCount <= 0)
{
StepInto();
JSRCount = 0;
break;
}
else if (instr == RTS || instr == RTI)
{
JSRCount--;
}
else //Emergency Bailout Logic
{
if (Frame == bailOutFrame)
{
break;
}
}
}
}
private int JSRCount = 0;
private int JSRCount = 0;
private const byte JSR = 0x20;
private const byte RTI = 0x40;
private const byte RTS = 0x60;
private const byte JSR = 0x20;
private const byte RTI = 0x40;
private const byte RTS = 0x60;
private const byte JSRSize = 3;
private const byte JSRSize = 3;
public IMemoryCallbackSystem MemoryCallbacks { get; private set; }
}
public IMemoryCallbackSystem MemoryCallbacks { get; private set; }
}
}

View File

@ -5,32 +5,26 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Computers.Commodore64
{
public partial class C64 : IDisassemblable
{
public string Cpu
{
get
{
return "6510";
}
set
{
}
}
public partial class C64 : IDisassemblable
{
public string Cpu
{
get { return "6510"; }
}
public string PCRegisterName
{
get { return "PC"; }
}
public string PCRegisterName
{
get { return "PC"; }
}
public IEnumerable<string> AvailableCpus
{
get { yield return "6510"; }
}
public IEnumerable<string> AvailableCpus
{
get { yield return "6510"; }
}
public string Disassemble(MemoryDomain m, uint addr, out int length)
{
return Components.M6502.MOS6502X.Disassemble((ushort)addr, out length, (a) => m.PeekByte(a));
}
}
public string Disassemble(MemoryDomain m, uint addr, out int length)
{
return Components.M6502.MOS6502X.Disassemble((ushort)addr, out length, (a) => m.PeekByte(a));
}
}
}

View File

@ -42,7 +42,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
private C64 _c64;
public Motherboard(C64 c64, Region initRegion)
public Motherboard(C64 c64, DisplayType initRegion)
{
// note: roms need to be added on their own externally
_c64 = c64;
@ -59,8 +59,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
sid = MOS6581.Create(44100, initRegion);
switch (initRegion)
{
case Region.NTSC: vic = MOS6567.Create(); break;
case Region.PAL: vic = MOS6569.Create(); break;
case DisplayType.NTSC: vic = MOS6567.Create(); break;
case DisplayType.PAL: vic = MOS6569.Create(); break;
}
userPort = new UserPortDevice();
}
@ -102,7 +102,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
sid.HardReset();
vic.HardReset();
userPort.HardReset();
cassPort.HardReset();
cassPort.HardReset();
// because of how mapping works, the cpu needs to be hard reset twice
cpu.HardReset();

View File

@ -8,22 +8,15 @@ using System.Windows.Forms;
namespace BizHawk.Emulation.Cores.Computers.Commodore64
{
// TODO: use the EMulation.Common Region enum
public enum Region
{
NTSC,
PAL
}
[CoreAttributes(
"C64Hawk",
"SaxxonPIke",
isPorted: false,
isReleased: false
)]
[ServiceNotApplicable(typeof(IRegionable), typeof(ISettable<,>))]
sealed public partial class C64 : IEmulator, IStatable, IInputPollable, IDriveLight, IDebuggable, IDisassemblable
{
[ServiceNotApplicable(typeof(ISettable<,>))]
sealed public partial class C64 : IEmulator, IStatable, IInputPollable, IDriveLight, IDebuggable, IDisassemblable, IRegionable
{
// framework
public C64(CoreComm comm, GameInfo game, byte[] rom, string romextension)
{
@ -34,37 +27,37 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
inputFileInfo.Data = rom;
inputFileInfo.Extension = romextension;
CoreComm = comm;
Nullable<Region> region = queryUserForRegion();
if (region == null)
{
throw new Exception("Can't construct new C64 because you didn't choose anything");
}
Init(region.Value);
Region = queryUserForRegion();
Init(Region);
cyclesPerFrame = board.vic.CyclesPerFrame;
SetupMemoryDomains();
MemoryCallbacks = new MemoryCallbackSystem();
HardReset();
MemoryCallbacks = new MemoryCallbackSystem();
HardReset();
(ServiceProvider as BasicServiceProvider).Register<IVideoProvider>(board.vic);
}
}
private Nullable<Region> queryUserForRegion()
{
Form prompt = new Form() { Width = 160, Height = 120, FormBorderStyle = FormBorderStyle.FixedDialog, Text = "Region selector", StartPosition = FormStartPosition.CenterScreen };
Label textLabel = new Label() { Left = 10, Top = 10, Width = 260, Text = "Please choose a region:" };
RadioButton palButton = new RadioButton() { Left = 10, Top = 30, Width = 70, Text = "PAL", Checked = true };
RadioButton ntscButton = new RadioButton() { Left = 80, Top = 30, Width = 70, Text = "NTSC" };
Button confirmation = new Button() { Text = "Ok", Left = 40, Width = 80, Top = 60, DialogResult = DialogResult.OK };
confirmation.Click += (sender, e) => { prompt.Close(); };
prompt.Controls.Add(textLabel);
prompt.Controls.Add(palButton);
prompt.Controls.Add(ntscButton);
prompt.Controls.Add(confirmation);
prompt.AcceptButton = confirmation;
private DisplayType queryUserForRegion()
{
Form prompt = new Form() { Width = 160, Height = 120, FormBorderStyle = FormBorderStyle.FixedDialog, Text = "Region selector", StartPosition = FormStartPosition.CenterScreen };
Label textLabel = new Label() { Left = 10, Top = 10, Width = 260, Text = "Please choose a region:" };
RadioButton palButton = new RadioButton() { Left = 10, Top = 30, Width = 70, Text = "PAL", Checked = true };
RadioButton ntscButton = new RadioButton() { Left = 80, Top = 30, Width = 70, Text = "NTSC" };
Button confirmation = new Button() { Text = "Ok", Left = 40, Width = 80, Top = 60, DialogResult = DialogResult.OK };
confirmation.Click += (sender, e) => { prompt.Close(); };
prompt.Controls.Add(textLabel);
prompt.Controls.Add(palButton);
prompt.Controls.Add(ntscButton);
prompt.Controls.Add(confirmation);
prompt.AcceptButton = confirmation;
return prompt.ShowDialog() == DialogResult.OK ? palButton.Checked ? new Nullable<Region>(Region.PAL) : ntscButton.Checked ? new Nullable<Region>(Region.NTSC) : null : null;
}
if (prompt.ShowDialog() != DialogResult.OK || !palButton.Checked && !ntscButton.Checked)
{
throw new Exception("Can't construct new C64 because you didn't choose anything");
}
return palButton.Checked ? DisplayType.PAL : DisplayType.NTSC;
}
// internal variables
private int _frame = 0;
@ -88,8 +81,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
_frame = 0;
_lagcount = 0;
_islag = false;
frameCycles = 0;
}
frameCycles = 0;
}
// audio/video
public void EndAsyncSound() { } //TODO
@ -118,6 +111,12 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
public IEmulatorServiceProvider ServiceProvider { get; private set; }
public DisplayType Region
{
get;
private set;
}
public void Dispose()
{
if (board.sid != null)
@ -127,69 +126,69 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
}
}
int frameCycles;
int frameCycles;
private void DoCycle()
{
if (frameCycles == 0) {
board.inputRead = false;
board.PollInput();
board.cpu.LagCycles = 0;
}
//disk.Execute();
board.Execute();
frameCycles++;
// load PRG file if needed
if (loadPrg)
{
// check to see if cpu PC is at the BASIC warm start vector
if (board.cpu.PC == ((board.ram.Peek(0x0303) << 8) | board.ram.Peek(0x0302)))
{
//board.ram.Poke(0x0302, 0xAE);
//board.ram.Poke(0x0303, 0xA7);
////board.ram.Poke(0x0302, board.ram.Peek(0x0308));
////board.ram.Poke(0x0303, board.ram.Peek(0x0309));
//if (inputFileInfo.Data.Length >= 6)
//{
// board.ram.Poke(0x0039, inputFileInfo.Data[4]);
// board.ram.Poke(0x003A, inputFileInfo.Data[5]);
//}
PRG.Load(board.pla, inputFileInfo.Data);
loadPrg = false;
}
}
if (frameCycles == cyclesPerFrame)
{
board.Flush();
_islag = !board.inputRead;
if (_islag)
_lagcount++;
frameCycles -= cyclesPerFrame;
_frame++;
//Console.WriteLine("CPUPC: " + C64Util.ToHex(board.cpu.PC, 4) + " 1541PC: " + C64Util.ToHex(disk.PC, 4));
int test = board.cpu.LagCycles;
DriveLightOn = DriveLED;
}
}
// process frame
public void FrameAdvance(bool render, bool rendersound)
// process frame
public void FrameAdvance(bool render, bool rendersound)
{
do
{
DoCycle();
}
while (frameCycles != 0);
}
do
{
DoCycle();
}
while (frameCycles != 0);
}
private void HandleFirmwareError(string file)
private void DoCycle()
{
if (frameCycles == 0) {
board.inputRead = false;
board.PollInput();
board.cpu.LagCycles = 0;
}
//disk.Execute();
board.Execute();
frameCycles++;
// load PRG file if needed
if (loadPrg)
{
// check to see if cpu PC is at the BASIC warm start vector
if (board.cpu.PC == ((board.ram.Peek(0x0303) << 8) | board.ram.Peek(0x0302)))
{
//board.ram.Poke(0x0302, 0xAE);
//board.ram.Poke(0x0303, 0xA7);
////board.ram.Poke(0x0302, board.ram.Peek(0x0308));
////board.ram.Poke(0x0303, board.ram.Peek(0x0309));
//if (inputFileInfo.Data.Length >= 6)
//{
// board.ram.Poke(0x0039, inputFileInfo.Data[4]);
// board.ram.Poke(0x003A, inputFileInfo.Data[5]);
//}
PRG.Load(board.pla, inputFileInfo.Data);
loadPrg = false;
}
}
if (frameCycles == cyclesPerFrame)
{
board.Flush();
_islag = !board.inputRead;
if (_islag)
_lagcount++;
frameCycles -= cyclesPerFrame;
_frame++;
//Console.WriteLine("CPUPC: " + C64Util.ToHex(board.cpu.PC, 4) + " 1541PC: " + C64Util.ToHex(disk.PC, 4));
int test = board.cpu.LagCycles;
DriveLightOn = DriveLED;
}
}
private void HandleFirmwareError(string file)
{
System.Windows.Forms.MessageBox.Show("the C64 core is referencing a firmware file which could not be found. Please make sure it's in your configured C64 firmwares folder. The referenced filename is: " + file);
throw new FileNotFoundException();
@ -206,7 +205,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
return result;
}
private void Init(Region initRegion)
private void Init(DisplayType initRegion)
{
board = new Motherboard(this, initRegion);
InitRoms();
@ -228,13 +227,13 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{
board.cartPort.Connect(cart);
}
break;
case @".TAP":
CassettePort.Tape tape = CassettePort.Tape.Load(inputFileInfo.Data);
if (tape != null)
{
board.cassPort.Connect(tape);
}
break;
case @".TAP":
CassettePort.Tape tape = CassettePort.Tape.Load(inputFileInfo.Data);
if (tape != null)
{
board.cassPort.Connect(tape);
}
break;
case @".PRG":
if (inputFileInfo.Data.Length > 2)
@ -261,5 +260,5 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
board.HardReset();
//disk.HardReset();
}
}
}
}

View File

@ -9,33 +9,33 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.CassettePort
{
public class CassettePortDevice
{
public Func<bool> ReadDataOutput;
public Func<bool> ReadMotor;
Commodore64.CassettePort.Tape tape;
public Func<bool> ReadDataOutput;
public Func<bool> ReadMotor;
Commodore64.CassettePort.Tape tape;
public void HardReset()
{
if (tape != null) tape.rewind();
}
public void HardReset()
{
if (tape != null) tape.rewind();
}
virtual public bool ReadDataInputBuffer()
{
return tape != null && !ReadMotor() ? tape.read() : true;
}
virtual public bool ReadDataInputBuffer()
{
return tape != null && !ReadMotor() ? tape.read() : true;
}
virtual public bool ReadSenseBuffer()
{
return tape == null; // Just assume that "play" is constantly pressed as long as a tape is inserted
}
virtual public bool ReadSenseBuffer()
{
return tape == null; // Just assume that "play" is constantly pressed as long as a tape is inserted
}
public void SyncState(Serializer ser)
{
SaveState.SyncObject(ser, this);
}
public void SyncState(Serializer ser)
{
SaveState.SyncObject(ser, this);
}
internal void Connect(Tape tape)
{
this.tape = tape;
}
}
internal void Connect(Tape tape)
{
this.tape = tape;
}
}
}

View File

@ -9,85 +9,85 @@ using BizHawk.Common;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.CassettePort
{
/**
* This class represents a tape. Only TAP-style tapes are supported for now.
*/
class Tape
{
private byte[] tapeData;
private byte version;
private uint pos, cycle, start, end;
/**
* This class represents a tape. Only TAP-style tapes are supported for now.
*/
class Tape
{
private byte[] tapeData;
private byte version;
private uint pos, cycle, start, end;
public Tape(byte version, byte[] tapeData, uint start, uint end)
{
this.version = version;
this.tapeData = tapeData;
this.start = start;
this.end = end;
rewind();
}
public Tape(byte version, byte[] tapeData, uint start, uint end)
{
this.version = version;
this.tapeData = tapeData;
this.start = start;
this.end = end;
rewind();
}
// Rewinds the tape back to start
public void rewind()
{
pos = start;
cycle = 0;
}
// Rewinds the tape back to start
public void rewind()
{
pos = start;
cycle = 0;
}
// Reads from tape, this will tell the caller if the flag pin should be raised
public bool read()
{
if (cycle == 0)
{
Console.WriteLine("Tape @ " + pos.ToString());
if (pos >= end)
{
return true;
}
else
{
cycle = ((uint)tapeData[pos++])*8;
if (cycle == 0)
{
if (version == 0)
{
cycle = 256 * 8; // unspecified overflow condition
}
else
{
cycle = BitConverter.ToUInt32(tapeData, (int)pos-1)>>8;
pos += 3;
if (cycle == 0)
{
throw new Exception("Bad tape data");
}
}
}
}
}
// Reads from tape, this will tell the caller if the flag pin should be raised
public bool read()
{
if (cycle == 0)
{
Console.WriteLine("Tape @ " + pos.ToString());
if (pos >= end)
{
return true;
}
else
{
cycle = ((uint)tapeData[pos++])*8;
if (cycle == 0)
{
if (version == 0)
{
cycle = 256 * 8; // unspecified overflow condition
}
else
{
cycle = BitConverter.ToUInt32(tapeData, (int)pos-1)>>8;
pos += 3;
if (cycle == 0)
{
throw new Exception("Bad tape data");
}
}
}
}
}
// Send a single negative pulse at the end of a cycle
return --cycle != 0;
}
// Send a single negative pulse at the end of a cycle
return --cycle != 0;
}
// Try to construct a tape file from file data. Returns null if not a tape file, throws exceptions for bad tape files.
// (Note that some error conditions aren't caught right here.)
static public Tape Load(byte[] tapeFile)
{
Tape result = null;
// Try to construct a tape file from file data. Returns null if not a tape file, throws exceptions for bad tape files.
// (Note that some error conditions aren't caught right here.)
static public Tape Load(byte[] tapeFile)
{
Tape result = null;
if (System.Text.Encoding.ASCII.GetString(tapeFile, 0, 12) == "C64-TAPE-RAW")
{
byte version = tapeFile[12];
if (version > 1) throw new Exception("This tape has an unsupported version");
uint size = BitConverter.ToUInt32(tapeFile, 16);
if (size + 20 != tapeFile.Length)
{
throw new Exception("Tape file header specifies a length that doesn't match the file size");
}
result = new Tape(version, tapeFile, 20, (uint)tapeFile.Length);
}
return result;
}
}
if (System.Text.Encoding.ASCII.GetString(tapeFile, 0, 12) == "C64-TAPE-RAW")
{
byte version = tapeFile[12];
if (version > 1) throw new Exception("This tape has an unsupported version");
uint size = BitConverter.ToUInt32(tapeFile, 16);
if (size + 20 != tapeFile.Length)
{
throw new Exception("Tape file header specifies a length that doesn't match the file size");
}
result = new Tape(version, tapeFile, 20, (uint)tapeFile.Length);
}
return result;
}
}
}

View File

@ -99,18 +99,18 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
}
set
{
lagCycles = value;
}
}
lagCycles = value;
}
}
internal bool AtInstructionStart()
{
return cpu.AtInstructionStart();
}
internal bool AtInstructionStart()
{
return cpu.AtInstructionStart();
}
// ------------------------------------
// ------------------------------------
public ushort PC
public ushort PC
{
get
{

View File

@ -233,7 +233,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
LatchedPort portA;
LatchedPort portB;
public MOS6526_2(Region region)
public MOS6526_2(Common.DisplayType region)
{
a = new CiaTimer(serialPortA, underFlowA);
b = new CiaTimer(serialPortB, underFlowB);
@ -241,10 +241,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
portB = new LatchedPort();
switch (region)
{
case Region.NTSC:
case Common.DisplayType.NTSC:
tod_period = 14318181 / 140;
break;
case Region.PAL:
case Common.DisplayType.PAL:
tod_period = 17734472 / 180;
break;
}

File diff suppressed because it is too large Load Diff

View File

@ -4119,7 +4119,7 @@
}
};
static public Sid Create(int newSampleRate, Region newRegion)
static public Sid Create(int newSampleRate, Common.DisplayType newRegion)
{
return new Sid(waveTable, newSampleRate, newRegion);
}

View File

@ -42,7 +42,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public Func<byte> ReadPotX;
public Func<byte> ReadPotY;
public Sid(int[][] newWaveformTable, int newSampleRate, Region newRegion)
public Sid(int[][] newWaveformTable, int newSampleRate, Common.DisplayType newRegion)
{
uint cyclesPerSec = 0;
uint cyclesNum;
@ -51,8 +51,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
switch (newRegion)
{
case Region.NTSC: cyclesNum = 14318181; cyclesDen = 14; break;
case Region.PAL: cyclesNum = 17734472; cyclesDen = 18; break;
case Common.DisplayType.NTSC: cyclesNum = 14318181; cyclesDen = 14; break;
case Common.DisplayType.PAL: cyclesNum = 17734472; cyclesDen = 18; break;
default: return;
}

View File

@ -145,8 +145,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
}
else if (parseba == 0x1000)
{
pinBA = !badline;
}
pinBA = !badline;
}
else
{
parsecycleBAsprite0 = (parseba & 0x000F);

View File

@ -74,9 +74,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
lastRasterLine = rasterLine;
}
// display enable compare
if (rasterLine == 0)
badlineEnable = false;
// display enable compare
if (rasterLine == 0)
badlineEnable = false;
if (rasterLine == 0x030)
badlineEnable |= displayEnable;