diff --git a/BizHawk.Emulation/BizHawk.Emulation.csproj b/BizHawk.Emulation/BizHawk.Emulation.csproj
index 087c3764ef..60eb77075a 100644
--- a/BizHawk.Emulation/BizHawk.Emulation.csproj
+++ b/BizHawk.Emulation/BizHawk.Emulation.csproj
@@ -84,6 +84,8 @@
+
+
diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.core.cs b/BizHawk.Emulation/Computers/Commodore64/C64.core.cs
index 7718dde930..7b0147d6da 100644
--- a/BizHawk.Emulation/Computers/Commodore64/C64.core.cs
+++ b/BizHawk.Emulation/Computers/Commodore64/C64.core.cs
@@ -11,9 +11,9 @@ namespace BizHawk.Emulation.Computers.Commodore64
{
// source
public Cartridge cart;
- public bool cartInserted;
public string extension;
public byte[] inputFile;
+ public List mediaAttached = new List();
// chipset
public Cia cia0;
@@ -59,18 +59,12 @@ namespace BizHawk.Emulation.Computers.Commodore64
{
case @".PRG":
if (inputFile.Length > 2)
- {
- mem.ApplyMemory(inputFile);
- // idle vector
- cpu.PC = (ushort)2064;
- }
+ mediaAttached.Add(new PRGFile(inputFile, mem, cpu));
break;
case @".CRT":
Cartridge cart = new Cartridge(inputFile);
if (cart.valid)
- {
- mem.ApplyCartridge(cart);
- }
+ mediaAttached.Add(cart);
break;
}
diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.cs b/BizHawk.Emulation/Computers/Commodore64/C64.cs
index 38a3b36eca..6be347e354 100644
--- a/BizHawk.Emulation/Computers/Commodore64/C64.cs
+++ b/BizHawk.Emulation/Computers/Commodore64/C64.cs
@@ -89,6 +89,14 @@ namespace BizHawk.Emulation.Computers.Commodore64
int cyclesPerSecond = (14318181 / 14 / 60);
+ foreach (IMedia media in mediaAttached)
+ {
+ if (!media.Loaded() && media.Ready())
+ {
+ media.Apply(mem);
+ }
+ }
+
for (int i = 0; i < cyclesPerSecond; i++)
{
cpu.IRQ = signal.CpuIRQ;
diff --git a/BizHawk.Emulation/Computers/Commodore64/Cartridge.cs b/BizHawk.Emulation/Computers/Commodore64/Cartridge.cs
index 881649a091..092b078b11 100644
--- a/BizHawk.Emulation/Computers/Commodore64/Cartridge.cs
+++ b/BizHawk.Emulation/Computers/Commodore64/Cartridge.cs
@@ -15,7 +15,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
public int type;
}
- public class Cartridge
+ public class Cartridge : IMedia
{
public List chips;
public bool exRomPin;
@@ -24,6 +24,8 @@ namespace BizHawk.Emulation.Computers.Commodore64
public bool valid;
public int version;
+ private bool loaded;
+
public Cartridge(byte[] rom)
{
chips = new List();
@@ -135,12 +137,31 @@ namespace BizHawk.Emulation.Computers.Commodore64
}
}
+ public void Apply(Memory mem)
+ {
+ mem.cart = this;
+ mem.exRomPin = exRomPin;
+ mem.gamePin = gamePin;
+ mem.UpdateLayout();
+ loaded = true;
+ }
+
+ public bool Loaded()
+ {
+ return loaded;
+ }
+
public byte Read(ushort addr)
{
CartridgeChip currentChip = chips[0];
return currentChip.data[addr & currentChip.romMask];
}
+ public bool Ready()
+ {
+ return true;
+ }
+
public void Write(ushort addr, byte val)
{
// can't write to rom but we can process DE00/DF00 here
diff --git a/BizHawk.Emulation/Computers/Commodore64/IMedia.cs b/BizHawk.Emulation/Computers/Commodore64/IMedia.cs
new file mode 100644
index 0000000000..4e9420e929
--- /dev/null
+++ b/BizHawk.Emulation/Computers/Commodore64/IMedia.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace BizHawk.Emulation.Computers.Commodore64
+{
+ public interface IMedia
+ {
+ void Apply(Memory mem);
+ bool Loaded();
+ bool Ready();
+ }
+}
diff --git a/BizHawk.Emulation/Computers/Commodore64/MemBus.cs b/BizHawk.Emulation/Computers/Commodore64/MemBus.cs
index 8e342a302d..e900f5ed11 100644
--- a/BizHawk.Emulation/Computers/Commodore64/MemBus.cs
+++ b/BizHawk.Emulation/Computers/Commodore64/MemBus.cs
@@ -45,7 +45,6 @@ namespace BizHawk.Emulation.Computers.Commodore64
// storage
public Cartridge cart;
- public bool cartInserted = false;
// roms
public byte[] basicRom;
@@ -107,27 +106,15 @@ namespace BizHawk.Emulation.Computers.Commodore64
HardReset();
}
- public void ApplyCartridge(Cartridge newCart)
+ public byte this[ushort index]
{
- cart = newCart;
- cartInserted = true;
- exRomPin = cart.exRomPin;
- gamePin = cart.gamePin;
- UpdateLayout();
- }
-
- public void ApplyMemory(byte[] newMemory)
- {
- int address = newMemory[1];
- address <<= 8;
- address |= newMemory[0];
-
- int count = newMemory.Length;
-
- for (int i = 2; i < count; i++)
+ get
{
- Write((ushort)(address & 0xFFFF), newMemory[i]);
- address++;
+ return ram[index];
+ }
+ set
+ {
+ ram[index] = value;
}
}
diff --git a/BizHawk.Emulation/Computers/Commodore64/PRGFile.cs b/BizHawk.Emulation/Computers/Commodore64/PRGFile.cs
new file mode 100644
index 0000000000..326254d7e8
--- /dev/null
+++ b/BizHawk.Emulation/Computers/Commodore64/PRGFile.cs
@@ -0,0 +1,79 @@
+using BizHawk.Emulation.CPUs.M6502;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace BizHawk.Emulation.Computers.Commodore64
+{
+ public class PRGFile : IMedia
+ {
+ private MOS6502X cpu;
+ private byte[] data;
+ private bool loaded;
+ private Memory mem;
+
+ public PRGFile(byte[] file, Memory checkMem, MOS6502X targetCpu)
+ {
+ cpu = targetCpu;
+ mem = checkMem;
+ data = file;
+ }
+
+ public void Apply(Memory mem)
+ {
+ int address = data[1];
+ address <<= 8;
+ address |= data[0];
+
+ int count = data.Length;
+
+ for (int i = 2; i < count; i++)
+ {
+ mem.Write((ushort)(address & 0xFFFF), data[i]);
+ address++;
+ }
+
+ //// "RUN"
+ //mem[0x04F0] = 0x12;
+ //mem[0x04F1] = 0x15;
+ //mem[0x04F2] = 0x0E;
+
+ //// set cursor to be right after run (3, 6)
+ //mem[0x00C9] = 0x06;
+ //mem[0x00CA] = 0x03;
+ //mem[0x00D3] = 0x03;
+ //mem[0x00D6] = 0x06;
+
+ //// set keyboard buffer
+ //mem[0x00C5] = 0x0D;
+ //mem[0x00C6] = 0x02;
+ //mem[0x00CB] = 0x0D;
+ //mem[0x0277] = 0x0D;
+ //mem[0x0278] = 0x0D;
+
+ cpu.PC = 2064;
+
+ loaded = true;
+ }
+
+ public bool Loaded()
+ {
+ return loaded;
+ }
+
+ public bool Ready()
+ {
+ // wait for READY. to be on display
+ return (
+ mem[0x04C8] == 0x12 &&
+ mem[0x04C9] == 0x05 &&
+ mem[0x04CA] == 0x01 &&
+ mem[0x04CB] == 0x04 &&
+ mem[0x04CC] == 0x19 &&
+ mem[0x04CD] == 0x2E &&
+ mem[0x04CE] == 0x20
+ );
+ }
+ }
+}