diff --git a/BizHawk.Emulation/CPUs/MOS 6502/Execute.cs b/BizHawk.Emulation/CPUs/MOS 6502/Execute.cs
index 8cfa2d8912..704b1b43c4 100644
--- a/BizHawk.Emulation/CPUs/MOS 6502/Execute.cs
+++ b/BizHawk.Emulation/CPUs/MOS 6502/Execute.cs
@@ -61,6 +61,7 @@ TriggerException(ExceptionType.BRK);
PendingCycles -= 5; TotalExecutedCycles += 5;
break;
case 0x08: // PHP
+ //FlagB = true; //why would it do this?? how weird
WriteMemory((ushort)(S-- + 0x100), P);
PendingCycles -= 3; TotalExecutedCycles += 3;
break;
@@ -1204,8 +1205,10 @@ FlagT = true;// this seems wrong
P = (byte)((P & 0x7D) | TableNZ[value8]);
PendingCycles -= 7; TotalExecutedCycles += 7;
break;
- default:
- throw new Exception(String.Format("Unhandled opcode: {0:X2}", opcode));
+ default:
+ if(throw_unhandled)
+ throw new Exception(String.Format("Unhandled opcode: {0:X2}", opcode));
+ break;
}
}
}
diff --git a/BizHawk.Emulation/CPUs/MOS 6502/MOS6502.cs b/BizHawk.Emulation/CPUs/MOS 6502/MOS6502.cs
index b21b9faf07..d0df5d6a32 100644
--- a/BizHawk.Emulation/CPUs/MOS 6502/MOS6502.cs
+++ b/BizHawk.Emulation/CPUs/MOS 6502/MOS6502.cs
@@ -26,6 +26,7 @@ namespace BizHawk.Emulation.CPUs.M6502
}*/
public bool debug;
+ public bool throw_unhandled;
public void Reset()
{
@@ -39,11 +40,6 @@ namespace BizHawk.Emulation.CPUs.M6502
TotalExecutedCycles = 0;
}
- public void ResetPC()
- {
- PC = ReadWord(0xFFFE);
- }
-
public string State()
{
int notused;
@@ -61,10 +57,10 @@ namespace BizHawk.Emulation.CPUs.M6502
return val;
}
- private const ushort NMIVector = 0xFFFA;
- private const ushort ResetVector = 0xFFFC;
- private const ushort BRKVector = 0xFFFE;
- private const ushort IRQVector = 0xFFFE;
+ public const ushort NMIVector = 0xFFFA;
+ public const ushort ResetVector = 0xFFFC;
+ public const ushort BRKVector = 0xFFFE;
+ public const ushort IRQVector = 0xFFFE;
enum ExceptionType
{
@@ -73,13 +69,12 @@ namespace BizHawk.Emulation.CPUs.M6502
void TriggerException(ExceptionType type)
{
+ if (type == ExceptionType.BRK)
+ PC++;
WriteMemory((ushort)(S-- + 0x100), (byte)(PC >> 8));
WriteMemory((ushort)(S-- + 0x100), (byte)PC);
- byte oldP = P;
- FlagB = false;
- FlagT = true;
+ FlagB = type == ExceptionType.BRK;
WriteMemory((ushort)(S-- + 0x100), P);
- P = oldP;
FlagI = true;
switch (type)
{
@@ -174,7 +169,7 @@ namespace BizHawk.Emulation.CPUs.M6502
}
/// Interrupt Disable Flag
- private bool FlagI
+ public bool FlagI
{
get { return (P & 0x04) != 0; }
set { P = (byte)((P & ~0x04) | (value ? 0x04 : 0x00)); }
@@ -227,7 +222,7 @@ namespace BizHawk.Emulation.CPUs.M6502
WriteMemory = null;
}
- private ushort ReadWord(ushort address)
+ public ushort ReadWord(ushort address)
{
byte l = ReadMemory(address);
byte h = ReadMemory(++address);
diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs
index ba9a618d31..8b446f949c 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs
@@ -12,7 +12,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
public interface INESBoard
{
void Create(NES nes);
- bool Configure();
+ bool Configure(NES.EDetectionOrigin origin);
byte ReadPRG(int addr);
byte ReadPPU(int addr); byte PeekPPU(int addr);
byte ReadPRAM(int addr);
@@ -38,7 +38,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
{
this.NES = nes;
}
- public abstract bool Configure();
+ public abstract bool Configure(NES.EDetectionOrigin origin);
public CartInfo Cart { get { return NES.cart; } }
public NES NES { get; set; }
@@ -118,6 +118,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo
{
if (addr < 0x2000)
{
+ if (VRAM != null)
+ VRAM[addr] = value;
}
else
{
@@ -131,7 +133,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo
{
if (addr < 0x2000)
{
- return VROM[addr];
+ if (VROM != null)
+ return VROM[addr];
+ else return VRAM[addr];
}
else
{
@@ -222,7 +226,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
///
/// finds a board class which can handle the provided cart
///
- static Type FindBoard(CartInfo cart)
+ static Type FindBoard(CartInfo cart, EDetectionOrigin origin)
{
NES nes = new NES();
nes.cart = cart;
@@ -230,7 +234,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
{
INESBoard board = (INESBoard)Activator.CreateInstance(type);
board.Create(nes);
- if (board.Configure())
+ if (board.Configure(origin))
return type;
}
return null;
diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/AxROM.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/AxROM.cs
index 4740142be9..8fd8de04a1 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/AxROM.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/AxROM.cs
@@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
//state
int prg;
- public override bool Configure()
+ public override bool Configure(NES.EDetectionOrigin origin)
{
//configure
switch (Cart.board_type)
diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/CPROM.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/CPROM.cs
index d2a9a2c982..e51e2c8213 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/CPROM.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/CPROM.cs
@@ -12,7 +12,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
//state
int chr;
- public override bool Configure()
+ public override bool Configure(NES.EDetectionOrigin origin)
{
//configure
switch (Cart.board_type)
diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/CxROM.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/CxROM.cs
index ea66b7739e..0100f00018 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/CxROM.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/CxROM.cs
@@ -21,7 +21,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
//state
int chr;
- public override bool Configure()
+ public override bool Configure(NES.EDetectionOrigin origin)
{
//configure
switch (Cart.board_type)
diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/GxROM.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/GxROM.cs
index f530aec274..d190d77aef 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/GxROM.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/GxROM.cs
@@ -22,7 +22,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
//state
int prg, chr;
- public override bool Configure()
+ public override bool Configure(NES.EDetectionOrigin origin)
{
//configure
switch (Cart.board_type)
diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/IC_74x377.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/IC_74x377.cs
index 9ba71a2059..3ce7a28397 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/IC_74x377.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/IC_74x377.cs
@@ -18,7 +18,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
//state
int prg, chr;
- public override bool Configure()
+ public override bool Configure(NES.EDetectionOrigin origin)
{
switch (Cart.board_type)
{
diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/NROM.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/NROM.cs
index b03f5690e5..0b232703fb 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/NROM.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/NROM.cs
@@ -11,14 +11,15 @@ namespace BizHawk.Emulation.Consoles.Nintendo
//state
//(none)
- public override bool Configure()
+ public override bool Configure(NES.EDetectionOrigin origin)
{
- //configure
+ //configure.
+ //contrary to expectations, some NROM games may have WRAM if theyve been identified through iNES. lame.
switch (Cart.board_type)
{
case "HVC-NROM-256": //super mario bros.
case "NES-NROM-256": //10 yard fight
- AssertPrg(32); AssertChr(8); AssertVram(0); AssertWram(0);
+ AssertPrg(32); AssertChr(8); AssertVram(0); AssertWram(0,8);
break;
case "HVC-RROM": //balloon fight
@@ -27,12 +28,17 @@ namespace BizHawk.Emulation.Consoles.Nintendo
case "KONAMI-NROM-128":
case "NES-NROM-128":
case "NAMCOT-3301":
- AssertPrg(16); AssertChr(8); AssertVram(0); AssertWram(0);
+ AssertPrg(16); AssertChr(8); AssertVram(0); AssertWram(0,8);
+ break;
+
+ case "NROM-HOMEBREW":
+ //whatever. who knows.
break;
default:
return false;
}
+ if (origin != NES.EDetectionOrigin.INES) AssertWram(0);
prg_byte_mask = (Cart.prg_size*1024) - 1;
SetMirrorType(Cart.pad_h, Cart.pad_v);
diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/SxROM.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/SxROM.cs
index 9259e94819..eb6930cc73 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/SxROM.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/SxROM.cs
@@ -256,7 +256,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
}
- public override bool Configure()
+ public override bool Configure(NES.EDetectionOrigin origin)
{
//analyze board type
switch (Cart.board_type)
diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/UxROM.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/UxROM.cs
index 9fd18d0de2..326918791d 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/UxROM.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/UxROM.cs
@@ -23,7 +23,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
//state
int prg;
- public override bool Configure()
+ public override bool Configure(NES.EDetectionOrigin origin)
{
//configure
switch (Cart.board_type)
diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs
index c590ad85ea..34b1996d9c 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs
@@ -56,18 +56,31 @@ namespace BizHawk.Emulation.Consoles.Nintendo
//in this emulator, reset takes place instantaneously
cpu.PC = (ushort)(ReadMemory(0xFFFC) | (ReadMemory(0xFFFD) << 8));
+ cpu.P = 0x34;
+ cpu.S = 0xFD;
//cpu.debug = true;
}
+ bool resetSignal;
public void FrameAdvance(bool render)
{
Controller.UpdateControls(Frame++);
+ if (resetSignal)
+ Controller.UnpressButton("Reset");
+ resetSignal = Controller["Reset"];
ppu.FrameAdvance();
}
protected void RunCpu(int ppu_cycles)
{
+ if (resetSignal)
+ {
+ cpu.PC = cpu.ReadWord(MOS6502.ResetVector);
+ apu.WriteReg(0x4015, 0);
+ cpu.FlagI = true;
+ }
+
int cycles = ppu_cycles;
if (ppu.PAL)
cycles *= 15;
@@ -233,6 +246,10 @@ namespace BizHawk.Emulation.Consoles.Nintendo
public void WriteMemory(ushort addr, byte value)
{
+ if (addr >= 0x6000 && addr < 0x6fff)
+ {
+ int zzz = 9;
+ }
if (addr < 0x0800) ram[addr] = value;
else if (addr < 0x1000) ram[addr - 0x0800] = value;
else if (addr < 0x1800) ram[addr - 0x1000] = value;
diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs
index dc858604b9..f23eccdc6e 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs
@@ -13,7 +13,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
public partial class NES : IEmulator
{
- static readonly bool USE_DATABASE = true;
+ static readonly bool USE_DATABASE = false;
//Game issues:
//3-D World Runner - UNROM - weird lines in gameplay (scanlines off?)
@@ -188,6 +188,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
value <<= 1;
value |= nes.Controller.IsPressed(str) ? 1 : 0;
}
+ //Console.WriteLine("STROBE");
}
public override void Write(int value)
{
@@ -373,7 +374,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
public string GameName { get { return game_name; } }
- enum EDetectionOrigin
+ public enum EDetectionOrigin
{
None, BootGodDB, GameDB, INES
}
@@ -447,27 +448,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
//find a INESBoard to handle this
Type boardType = null;
- bool iNES_tryAgain = false;
- try
- {
- boardType = FindBoard(choice);
- if (boardType == null)
- iNES_tryAgain = true;
- }
- catch(Exception)
- {
- if (origin == EDetectionOrigin.INES)
- iNES_tryAgain = true;
- else throw;
- }
- if (iNES_tryAgain)
- {
- //try again with a different wram size.. because iNES sucks that way
- choice.wram_size = 8;
- Console.WriteLine("Trying classification again with iNES wram adjustment. new parameters:");
- Console.WriteLine(choice);
- boardType = FindBoard(choice);
- }
+ boardType = FindBoard(choice,EDetectionOrigin.INES);
if (boardType == null)
throw new Exception("No class implements the necessary board type: " + choice.board_type);
@@ -475,7 +456,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
cart = choice;
board.Create(this);
- board.Configure();
+ board.Configure(origin);
//create the board's rom and vrom
board.ROM = new byte[choice.prg_size * 1024];
diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/iNES.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/iNES.cs
index d1f0278bf7..f8d8ac93c5 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/NES/iNES.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/NES/iNES.cs
@@ -49,20 +49,24 @@ namespace BizHawk.Emulation.Consoles.Nintendo
//MAP PRG CHR WRAM VRAM BOARD
static string ClassifyTable = @"
-0 16 8 0 0 NES-NROM-128; balloon fight, but its broken right now
-0 32 8 0 0 NES-NROM-256; super mario bros
-1 32 32 0 0 NES-SEROM; lolo
+0 16 0 8 8 NROM-HOMEBREW; some of blargg's test (sprite tests)
+0 16 8 8 0 NES-NROM-128; balloon fight, but its broken right now
+0 32 8 8 0 NES-NROM-256; super mario bros
+1 32 32 8 0 NES-SEROM; lolo
1 128 0 8 0 NES-SNROM; zelda
-2 128 0 0 0 NES-UNROM; mega man
-2 256 0 0 0 NES-UOROM; paperboy 2
-3 32 32 0 0 NES-CNROM; adventure island
-7 128 0 0 0 NES-ANROM; marble madness
-7 256 0 0 8 NES-AOROM; battletoads
-11 32 16 0 0 Discrete_74x377
-11 16 32 0 0 Discrete_74x377
-13 32 0 0 16 NES-CPROM; videomation
-66 64 16 0 0 NES-MHROM; super mario bros / duck hunt
-66 128 32 0 0 NES-GNROM; gumshoe
+1 128 128 8 0 NES-SKROM; zelda 2
+1 128 0 8 8 NES-SNROM; some of blargg's tests (apu)
+1 256 0 8 8 NES-SNROM; some of blargg's test (cpu tests)
+2 128 0 8 0 NES-UNROM; mega man
+2 256 0 8 0 NES-UOROM; paperboy 2
+3 32 32 8 0 NES-CNROM; adventure island
+7 128 0 8 0 NES-ANROM; marble madness
+7 256 0 8 8 NES-AOROM; battletoads
+11 32 16 8 0 Discrete_74x377
+11 16 32 8 0 Discrete_74x377
+13 32 0 8 16 NES-CPROM; videomation
+66 64 16 8 0 NES-MHROM; super mario bros / duck hunt
+66 128 32 8 0 NES-GNROM; gumshoe
";
}
@@ -73,7 +77,10 @@ static string ClassifyTable = @"
public byte VROM_size;
public byte ROM_type;
public byte ROM_type2;
- public fixed byte reserve[8];
+ public byte wram_size;
+ public byte flags9, flags10;
+ public byte zero11, zero12, zero13, zero14, zero15;
+
public bool CheckID()
{
@@ -123,9 +130,17 @@ static string ClassifyTable = @"
ret.chr_size = (short)(VROM_size * 8);
ret.wram_battery = (ROM_type & 2) != 0;
- fixed (iNES_HEADER* self = &this) ret.wram_size = (short)(self->reserve[0] * 8);
- //0 is supposed to mean 1 (for compatibility, as this is an extension to original iNES format)
- //but we'll try using 8 later if it doesn't work with 0
+ if(wram_size != 0 || flags9 != 0 || flags10 != 0 || zero11 != 0 || zero12 != 0 || zero13 != 0 || zero14 != 0 || zero15 != 0)
+ {
+ Console.WriteLine("Looks like you have an iNES 2.0 header, or some other kind of weird garbage.");
+ Console.WriteLine("We haven't bothered to support iNES 2.0.");
+ Console.WriteLine("We might, if we can find anyone who uses it. Let us know.");
+ }
+
+ ret.wram_size = (short)(wram_size * 8);
+ //0 is supposed to mean 8KB (for compatibility, as this is an extension to original iNES format)
+ if (ret.wram_size == 0)
+ ret.wram_size = 8;
//iNES wants us to assume that no chr -> 8KB vram
if (ret.chr_size == 0) ret.vram_size = 8;
diff --git a/BizHawk.MultiClient/BizHawk.MultiClient.csproj b/BizHawk.MultiClient/BizHawk.MultiClient.csproj
index 907939a341..3fa48abf7c 100644
--- a/BizHawk.MultiClient/BizHawk.MultiClient.csproj
+++ b/BizHawk.MultiClient/BizHawk.MultiClient.csproj
@@ -3,7 +3,7 @@
Debug
AnyCPU
- 9.0.21022
+ 9.0.30729
2.0
{DD448B37-BA3F-4544-9754-5406E8094723}
Exe
@@ -399,6 +399,7 @@
+