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-11-27 05:11:40 +00:00
|
|
|
|
using BizHawk.Emulation.Computers.Commodore64.MOS;
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// emulated chips:
|
|
|
|
|
// U1: 6526 CIA0
|
|
|
|
|
// U2: 6526 CIA1
|
|
|
|
|
// U4: KERNAL & BASIC ROM
|
|
|
|
|
// U5: CHARACTER ROM
|
|
|
|
|
// U6: 6510 CPU
|
|
|
|
|
// U7: VIC 6567 (NTSC) or 6569 (PAL)
|
|
|
|
|
// U8: Memory multiplexer
|
|
|
|
|
// U9: SID 6581 or 8580
|
|
|
|
|
// U10: RAM
|
|
|
|
|
// U11: RAM
|
|
|
|
|
// U19: 2114 color RAM
|
|
|
|
|
|
|
|
|
|
public partial class C64 : IEmulator
|
|
|
|
|
{
|
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
|
|
|
|
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-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-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-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
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void HardReset()
|
|
|
|
|
{
|
2012-12-05 21:07:51 +00:00
|
|
|
|
board.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
|
|
|
|
}
|