2013-04-14 20:39:19 +00:00
|
|
|
|
using BizHawk.Emulation.Computers.Commodore64.Cartridge;
|
2012-12-06 06:53:55 +00:00
|
|
|
|
using BizHawk.Emulation.Computers.Commodore64.Disk;
|
2012-11-27 05:11:40 +00:00
|
|
|
|
using BizHawk.Emulation.Computers.Commodore64.MOS;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.Emulation.Computers.Commodore64
|
|
|
|
|
{
|
|
|
|
|
public enum Region
|
|
|
|
|
{
|
|
|
|
|
NTSC,
|
|
|
|
|
PAL
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-24 20:13:16 +00:00
|
|
|
|
sealed public partial class C64 : IEmulator
|
2012-11-27 05:11:40 +00:00
|
|
|
|
{
|
2012-12-05 21:07:51 +00:00
|
|
|
|
private Motherboard board;
|
2012-11-28 17:49:42 +00:00
|
|
|
|
private bool loadPrg;
|
2012-11-27 05:11:40 +00:00
|
|
|
|
|
2013-08-11 02:43:18 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-27 05:11:40 +00:00
|
|
|
|
private void Init(Region initRegion)
|
|
|
|
|
{
|
2012-12-05 21:07:51 +00:00
|
|
|
|
board = new Motherboard(initRegion);
|
2012-11-27 05:11:40 +00:00
|
|
|
|
InitRoms();
|
2012-12-05 21:07:51 +00:00
|
|
|
|
board.Init();
|
2012-11-28 03:30:59 +00:00
|
|
|
|
InitMedia();
|
2012-11-27 05:11:40 +00:00
|
|
|
|
|
|
|
|
|
// configure video
|
2012-12-10 00:43:43 +00:00
|
|
|
|
CoreComm.VsyncDen = board.vic.CyclesPerFrame;
|
|
|
|
|
CoreComm.VsyncNum = board.vic.CyclesPerSecond;
|
2012-11-27 05:11:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-28 03:30:59 +00:00
|
|
|
|
private void InitMedia()
|
|
|
|
|
{
|
2013-08-19 03:42:40 +00:00
|
|
|
|
switch (inputFileInfo.Extension.ToUpper())
|
2012-11-28 03:30:59 +00:00
|
|
|
|
{
|
|
|
|
|
case @".CRT":
|
2013-08-19 03:42:40 +00:00
|
|
|
|
Cart cart = Cart.Load(inputFileInfo.Data);
|
2012-11-28 03:30:59 +00:00
|
|
|
|
if (cart != null)
|
|
|
|
|
{
|
2012-12-05 21:07:51 +00:00
|
|
|
|
board.cartPort.Connect(cart);
|
2012-11-28 03:30:59 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2012-11-28 17:49:42 +00:00
|
|
|
|
case @".PRG":
|
2013-08-19 03:42:40 +00:00
|
|
|
|
if (inputFileInfo.Data.Length > 2)
|
2012-11-28 17:49:42 +00:00
|
|
|
|
loadPrg = true;
|
|
|
|
|
break;
|
2012-11-28 03:30:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-27 05:11:40 +00:00
|
|
|
|
private void InitRoms()
|
|
|
|
|
{
|
2013-08-11 02:43:18 +00:00
|
|
|
|
byte[] basicRom = GetFirmware("Basic", 0x2000);
|
|
|
|
|
byte[] charRom = GetFirmware("Chargen", 0x1000);
|
|
|
|
|
byte[] kernalRom = GetFirmware("Kernal", 0x2000);
|
2012-12-06 06:53:55 +00:00
|
|
|
|
|
2012-12-05 21:07:51 +00:00
|
|
|
|
board.basicRom = new Chip23XX(Chip23XXmodel.Chip2364, basicRom);
|
|
|
|
|
board.kernalRom = new Chip23XX(Chip23XXmodel.Chip2364, kernalRom);
|
|
|
|
|
board.charRom = new Chip23XX(Chip23XXmodel.Chip2332, charRom);
|
2012-11-27 05:11:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
|
|
|
|
public bool DriveLED
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2013-08-13 12:23:32 +00:00
|
|
|
|
//return (disk.PeekVia1(0x00) & 0x08) != 0;
|
|
|
|
|
return false;
|
2012-11-27 05:11:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void HardReset()
|
|
|
|
|
{
|
2012-12-05 21:07:51 +00:00
|
|
|
|
board.HardReset();
|
2013-08-13 12:23:32 +00:00
|
|
|
|
//disk.HardReset();
|
2012-11-27 05:11:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-30 21:12:23 +00:00
|
|
|
|
static public class C64Util
|
|
|
|
|
{
|
2013-08-14 05:05:17 +00:00
|
|
|
|
static public string ToBinary(int n, int charsmin)
|
2012-11-30 21:12:23 +00:00
|
|
|
|
{
|
|
|
|
|
string result = "";
|
|
|
|
|
|
|
|
|
|
while (n > 0 || charsmin > 0)
|
|
|
|
|
{
|
|
|
|
|
result = (((n & 0x1) != 0) ? "1" : "0") + result;
|
|
|
|
|
n >>= 1;
|
|
|
|
|
if (charsmin > 0)
|
|
|
|
|
charsmin--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-14 05:05:17 +00:00
|
|
|
|
static public string ToHex(int n, int charsmin)
|
2012-11-30 21:12:23 +00:00
|
|
|
|
{
|
|
|
|
|
string result = "";
|
|
|
|
|
|
|
|
|
|
while (n > 0 || charsmin > 0)
|
|
|
|
|
{
|
2013-08-14 05:05:17 +00:00
|
|
|
|
result = "0123456789ABCDEF".Substring((n & 0xF), 1) + result;
|
2012-11-30 21:12:23 +00:00
|
|
|
|
n >>= 4;
|
|
|
|
|
if (charsmin > 0)
|
|
|
|
|
charsmin--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-11-27 05:11:40 +00:00
|
|
|
|
}
|