2012-11-27 05:11:40 +00:00
|
|
|
|
using BizHawk.Emulation.CPUs.M6502;
|
2012-12-06 06:25:30 +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;
|
2012-12-06 06:53:55 +00:00
|
|
|
|
using BizHawk.Emulation.Computers.Commodore64.Tape;
|
2012-11-27 05:11:40 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.Emulation.Computers.Commodore64
|
|
|
|
|
{
|
|
|
|
|
public enum Region
|
|
|
|
|
{
|
|
|
|
|
NTSC,
|
|
|
|
|
PAL
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public partial class C64 : IEmulator
|
|
|
|
|
{
|
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
2012-12-05 21:07:51 +00:00
|
|
|
|
private Motherboard board;
|
2012-12-06 06:53:55 +00:00
|
|
|
|
private VIC1541 disk;
|
|
|
|
|
private VIC1530 tape;
|
2012-11-28 17:49:42 +00:00
|
|
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
|
|
|
|
private bool loadPrg;
|
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-12-06 06:53:55 +00:00
|
|
|
|
InitDisk(initRegion);
|
2012-11-28 03:30:59 +00:00
|
|
|
|
InitMedia();
|
2012-11-27 05:11:40 +00:00
|
|
|
|
|
|
|
|
|
// configure video
|
2012-12-05 21:07:51 +00:00
|
|
|
|
CoreOutputComm.VsyncDen = board.vic.CyclesPerFrame;
|
|
|
|
|
CoreOutputComm.VsyncNum = board.vic.CyclesPerSecond;
|
2012-11-27 05:11:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-06 06:53:55 +00:00
|
|
|
|
private void InitDisk(Region initRegion)
|
|
|
|
|
{
|
|
|
|
|
string sourceFolder = CoreInputComm.C64_FirmwaresPath;
|
|
|
|
|
if (sourceFolder == null)
|
|
|
|
|
sourceFolder = @".\C64\Firmwares";
|
|
|
|
|
string diskFile = "dos1541";
|
|
|
|
|
string diskPath = Path.Combine(sourceFolder, diskFile);
|
|
|
|
|
if (!File.Exists(diskPath)) HandleFirmwareError(diskFile);
|
|
|
|
|
byte[] diskRom = File.ReadAllBytes(diskPath);
|
|
|
|
|
|
|
|
|
|
disk = new VIC1541(initRegion, diskRom);
|
2012-12-07 17:06:07 +00:00
|
|
|
|
disk.Connect(board.serPort);
|
2012-12-06 06:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-28 03:30:59 +00:00
|
|
|
|
private void InitMedia()
|
|
|
|
|
{
|
|
|
|
|
switch (extension.ToUpper())
|
|
|
|
|
{
|
|
|
|
|
case @".CRT":
|
2012-12-06 06:25:30 +00:00
|
|
|
|
Cart cart = Cart.Load(inputFile);
|
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":
|
|
|
|
|
if (inputFile.Length > 2)
|
|
|
|
|
loadPrg = true;
|
|
|
|
|
break;
|
2012-11-28 03:30:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-27 05:11:40 +00:00
|
|
|
|
private void InitRoms()
|
|
|
|
|
{
|
|
|
|
|
string sourceFolder = CoreInputComm.C64_FirmwaresPath;
|
|
|
|
|
if (sourceFolder == null)
|
|
|
|
|
sourceFolder = @".\C64\Firmwares";
|
|
|
|
|
|
|
|
|
|
string basicFile = "basic";
|
|
|
|
|
string charFile = "chargen";
|
|
|
|
|
string kernalFile = "kernal";
|
|
|
|
|
|
|
|
|
|
string basicPath = Path.Combine(sourceFolder, basicFile);
|
|
|
|
|
string charPath = Path.Combine(sourceFolder, charFile);
|
|
|
|
|
string kernalPath = Path.Combine(sourceFolder, kernalFile);
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(basicPath)) HandleFirmwareError(basicFile);
|
|
|
|
|
if (!File.Exists(charPath)) HandleFirmwareError(charFile);
|
|
|
|
|
if (!File.Exists(kernalPath)) HandleFirmwareError(kernalFile);
|
|
|
|
|
|
|
|
|
|
byte[] basicRom = File.ReadAllBytes(basicPath);
|
|
|
|
|
byte[] charRom = File.ReadAllBytes(charPath);
|
|
|
|
|
byte[] kernalRom = File.ReadAllBytes(kernalPath);
|
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
|
|
|
|
|
{
|
2012-12-07 17:06:07 +00:00
|
|
|
|
return (disk.PeekVia1(0x00) & 0x08) != 0;
|
2012-11-27 05:11:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void HardReset()
|
|
|
|
|
{
|
2012-12-05 21:07:51 +00:00
|
|
|
|
board.HardReset();
|
2012-12-07 05:24:00 +00:00
|
|
|
|
disk.HardReset();
|
2012-11-27 05:11:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-30 21:12:23 +00:00
|
|
|
|
static public class C64Util
|
|
|
|
|
{
|
|
|
|
|
static public string ToBinary(uint n, uint 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(uint n, uint charsmin)
|
|
|
|
|
{
|
|
|
|
|
string result = "";
|
|
|
|
|
|
|
|
|
|
while (n > 0 || charsmin > 0)
|
|
|
|
|
{
|
|
|
|
|
result = "0123456789ABCDEF".Substring((int)(n & 0xF), 1) + result;
|
|
|
|
|
n >>= 4;
|
|
|
|
|
if (charsmin > 0)
|
|
|
|
|
charsmin--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-11-27 05:11:40 +00:00
|
|
|
|
}
|