BizHawk/BizHawk.Emulation.Cores/Computers/Commodore64/C64.Core.cs

142 lines
3.4 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Computers.Commodore64
{
public enum Region
{
NTSC,
PAL
}
sealed public partial class C64 : IEmulator
{
private Motherboard board;
private bool loadPrg;
private byte[] GetFirmware(string name, int length)
{
byte[] result = new byte[length];
using (Stream source = CoreComm.CoreFileProvider.OpenFirmware("C64", name))
{
source.Read(result, 0, length);
}
return result;
}
private void Init(Region initRegion)
{
board = new Motherboard(this, initRegion);
InitRoms();
board.Init();
InitMedia();
// configure video
CoreComm.VsyncDen = board.vic.CyclesPerFrame;
CoreComm.VsyncNum = board.vic.CyclesPerSecond;
}
private void InitMedia()
{
switch (inputFileInfo.Extension.ToUpper())
{
case @".CRT":
Cart cart = Cart.Load(inputFileInfo.Data);
if (cart != null)
{
board.cartPort.Connect(cart);
}
break;
case @".PRG":
if (inputFileInfo.Data.Length > 2)
loadPrg = true;
break;
}
}
private void InitRoms()
{
byte[] basicRom = GetFirmware("Basic", 0x2000);
byte[] charRom = GetFirmware("Chargen", 0x1000);
byte[] kernalRom = GetFirmware("Kernal", 0x2000);
board.basicRom = new Chip23XX(Chip23XXmodel.Chip2364, basicRom);
board.kernalRom = new Chip23XX(Chip23XXmodel.Chip2364, kernalRom);
board.charRom = new Chip23XX(Chip23XXmodel.Chip2332, charRom);
}
// ------------------------------------
public bool DriveLED
{
get
{
//return (disk.PeekVia1(0x00) & 0x08) != 0;
return false;
}
}
public void HardReset()
{
board.HardReset();
//disk.HardReset();
}
public List<KeyValuePair<string, int>> GetCpuFlagsAndRegisters()
{
return new List<KeyValuePair<string, int>>
{
new KeyValuePair<string, int>("A", board.cpu.A),
new KeyValuePair<string, int>("X", board.cpu.X),
new KeyValuePair<string, int>("Y", board.cpu.Y),
new KeyValuePair<string, int>("S", board.cpu.S),
new KeyValuePair<string, int>("PC", board.cpu.PC),
new KeyValuePair<string, int>("Flag C", board.cpu.FlagC ? 1 : 0),
new KeyValuePair<string, int>("Flag Z", board.cpu.FlagZ ? 1 : 0),
new KeyValuePair<string, int>("Flag I", board.cpu.FlagI ? 1 : 0),
new KeyValuePair<string, int>("Flag D", board.cpu.FlagD ? 1 : 0),
new KeyValuePair<string, int>("Flag B", board.cpu.FlagB ? 1 : 0),
new KeyValuePair<string, int>("Flag V", board.cpu.FlagV ? 1 : 0),
new KeyValuePair<string, int>("Flag N", board.cpu.FlagN ? 1 : 0),
new KeyValuePair<string, int>("Flag T", board.cpu.FlagT ? 1 : 0)
};
}
}
static public class C64Util
{
static public string ToBinary(int n, int charsmin)
{
string result = "";
while (n > 0 || charsmin > 0)
{
result = (((n & 0x1) != 0) ? "1" : "0") + result;
n >>= 1;
if (charsmin > 0)
charsmin--;
}
return result;
}
static public string ToHex(int n, int charsmin)
{
string result = "";
while (n > 0 || charsmin > 0)
{
result = "0123456789ABCDEF".Substring((n & 0xF), 1) + result;
n >>= 4;
if (charsmin > 0)
charsmin--;
}
return result;
}
}
}