Add unit test for #282

This commit is contained in:
tomcw 2015-05-03 21:44:24 +01:00
parent 48be79551b
commit 54f2425168
5 changed files with 529 additions and 0 deletions

View File

@ -11,6 +11,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "zlib\zlib-Express9.
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zip_lib", "zip_lib\zip_lib.vcproj", "{709278B8-C583-4BD8-90DE-4E4F35A3BD8B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestCPU6502", "test\TestCPU6502\TestCPU6502.vcproj", "{2CC8CA9F-E37E-41A4-BFAD-77E54EB783A2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@ -29,6 +31,10 @@ Global
{709278B8-C583-4BD8-90DE-4E4F35A3BD8B}.Debug|Win32.Build.0 = Debug|Win32
{709278B8-C583-4BD8-90DE-4E4F35A3BD8B}.Release|Win32.ActiveCfg = Release|Win32
{709278B8-C583-4BD8-90DE-4E4F35A3BD8B}.Release|Win32.Build.0 = Release|Win32
{2CC8CA9F-E37E-41A4-BFAD-77E54EB783A2}.Debug|Win32.ActiveCfg = Debug|Win32
{2CC8CA9F-E37E-41A4-BFAD-77E54EB783A2}.Debug|Win32.Build.0 = Debug|Win32
{2CC8CA9F-E37E-41A4-BFAD-77E54EB783A2}.Release|Win32.ActiveCfg = Release|Win32
{2CC8CA9F-E37E-41A4-BFAD-77E54EB783A2}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,299 @@
#include "stdafx.h"
#include "../../source/Applewin.h"
#include "../../source/CPU.h"
// From Applewin.cpp
eCPU g_ActiveCPU = CPU_6502;
enum AppMode_e g_nAppMode = MODE_RUNNING;
// From Memory.cpp
LPBYTE memwrite[0x100]; // TODO: Init
LPBYTE mem = NULL; // TODO: Init
LPBYTE memdirty = NULL; // TODO: Init
iofunction IORead[256] = {0}; // TODO: Init
iofunction IOWrite[256] = {0}; // TODO: Init
// From Debugger_Types.h
enum AddressingMode_e // ADDRESSING_MODES_e
{
AM_IMPLIED // Note: SetDebugBreakOnInvalid() assumes this order of first 4 entries
, AM_1 // Invalid 1 Byte
, AM_2 // Invalid 2 Bytes
, AM_3 // Invalid 3 Bytes
};
// From CPU.cpp
#define AF_SIGN 0x80
#define AF_OVERFLOW 0x40
#define AF_RESERVED 0x20
#define AF_BREAK 0x10
#define AF_DECIMAL 0x08
#define AF_INTERRUPT 0x04
#define AF_ZERO 0x02
#define AF_CARRY 0x01
regsrec regs;
static const int IRQ_CHECK_TIMEOUT = 128;
static signed int g_nIrqCheckTimeout = IRQ_CHECK_TIMEOUT;
static __forceinline int Fetch(BYTE& iOpcode, ULONG uExecutedCycles)
{
iOpcode = *(mem+regs.pc);
regs.pc++;
return 1;
}
#define INV IsDebugBreakOnInvalid(AM_1);
inline int IsDebugBreakOnInvalid( int iOpcodeType )
{
return 0;
}
static __forceinline void DoIrqProfiling(DWORD uCycles)
{
}
static __forceinline void CheckInterruptSources(ULONG uExecutedCycles)
{
}
static __forceinline void NMI(ULONG& uExecutedCycles, UINT& uExtraCycles, BOOL& flagc, BOOL& flagn, BOOL& flagv, BOOL& flagz)
{
}
static __forceinline void IRQ(ULONG& uExecutedCycles, UINT& uExtraCycles, BOOL& flagc, BOOL& flagn, BOOL& flagv, BOOL& flagz)
{
}
void RequestDebugger()
{
}
// From Debug.h
inline int IsDebugBreakpointHit()
{
return 0;
}
// From Debug.cpp
int g_bDebugBreakpointHit = 0;
// From z80.cpp
DWORD z80_mainloop(ULONG uTotalCycles, ULONG uExecutedCycles)
{
return 0;
}
#include "../../source/cpu/cpu_general.inl"
#include "../../source/cpu/cpu_instructions.inl"
#include "../../source/cpu/cpu6502.h" // MOS 6502
void init(void)
{
//mem = new BYTE[64*1024];
mem = (LPBYTE)VirtualAlloc(NULL,64*1024,MEM_COMMIT,PAGE_READWRITE);
for (UINT i=0; i<256; i++)
memwrite[i] = mem+i*256;
memdirty = new BYTE[256];
}
void reset(void)
{
regs.a = 0;
regs.x = 0;
regs.y = 0;
regs.pc = 0x300;
regs.sp = 0x1FF;
regs.ps = 0;
regs.bJammed = 0;
}
DWORD AXA_ZPY(BYTE a, BYTE x, BYTE y, WORD base)
{
reset();
mem[0xfe] = base&0xff;
mem[0xff] = base>>8;
regs.a = a;
regs.x = x;
regs.y = y;
mem[regs.pc+0] = 0x93;
mem[regs.pc+1] = 0xfe;
return Cpu6502(0);
}
DWORD AXA_ABSY(BYTE a, BYTE x, BYTE y, WORD base)
{
reset();
regs.a = a;
regs.x = x;
regs.y = y;
mem[regs.pc+0] = 0x9f;
mem[regs.pc+1] = base&0xff;
mem[regs.pc+2] = base>>8;
return Cpu6502(0);
}
DWORD SAY_ABSX(BYTE a, BYTE x, BYTE y, WORD base)
{
reset();
regs.a = a;
regs.x = x;
regs.y = y;
mem[regs.pc+0] = 0x9c;
mem[regs.pc+1] = base&0xff;
mem[regs.pc+2] = base>>8;
return Cpu6502(0);
}
DWORD TAS_ABSY(BYTE a, BYTE x, BYTE y, WORD base)
{
reset();
regs.a = a;
regs.x = x;
regs.y = y;
mem[regs.pc+0] = 0x9b;
mem[regs.pc+1] = base&0xff;
mem[regs.pc+2] = base>>8;
return Cpu6502(0);
}
DWORD XAS_ABSY(BYTE a, BYTE x, BYTE y, WORD base)
{
reset();
regs.a = a;
regs.x = x;
regs.y = y;
mem[regs.pc+0] = 0x9e;
mem[regs.pc+1] = base&0xff;
mem[regs.pc+2] = base>>8;
return Cpu6502(0);
}
int test6502_GH282(void)
{
// axa (zp),y
{
WORD base = 0x20ff, addr = 0x20ff;
mem[addr] = 0xcc;
BYTE a = 0xea, x = 0xff, y = 0;
DWORD cycles = AXA_ZPY(a, x, y, base);
if (cycles != 6) return 1;
if (mem[addr] != (a & x & ((base>>8)+1))) return 1;
}
// axa (zp),y (page-cross)
{
WORD base = 0x20ff, addr = 0x2000;
mem[addr] = 0xcc;
BYTE a = 0xea, x = 0xff, y = 1;
DWORD cycles = AXA_ZPY(a, x, y, base);
if (cycles != 6) return 1;
if (mem[addr] != (a & x & ((base>>8)+1))) return 1;
}
//
// axa abs,y
{
WORD base = 0x20ff, addr = 0x20ff;
mem[addr] = 0xcc;
BYTE a = 0xea, x = 0xff, y = 0;
DWORD cycles = AXA_ABSY(a, x, y, base);
if (cycles != 5) return 1;
if (mem[addr] != (a & x & ((base>>8)+1))) return 1;
}
// axa abs,y (page-cross)
{
WORD base = 0x20ff, addr = 0x2000;
mem[addr] = 0xcc;
BYTE a = 0xea, x = 0xff, y = 1;
DWORD cycles = AXA_ABSY(a, x, y, base);
if (cycles != 5) return 1;
if (mem[addr] != (a & x & ((base>>8)+1))) return 1;
}
//
// say abs,x
{
WORD base = 0x20ff, addr = 0x20ff;
mem[addr] = 0xcc;
BYTE a = 0xea, x = 0, y=0x20;
DWORD cycles = SAY_ABSX(a, x, y, base);
if (cycles != 5) return 1;
if (mem[addr] != (y & ((base>>8)+1))) return 1;
}
// say abs,x (page-cross)
{
WORD base = 0x20ff, addr = 0x2000;
mem[addr] = 0xcc;
BYTE a = 0xea, x = 1, y=0x20;
DWORD cycles = SAY_ABSX(a, x, y, base);
if (cycles != 5) return 1;
if (mem[addr] != (y & ((base>>8)+1))) return 1;
}
//
// tas abs,y
{
WORD base = 0x20ff, addr = 0x20ff;
mem[addr] = 0xcc;
BYTE a = 0xea, x = 0xff, y = 0;
DWORD cycles = TAS_ABSY(a, x, y, base);
if (cycles != 5) return 1;
if (mem[addr] != (a & x & ((base>>8)+1))) return 1;
if (regs.sp != (0x100 | (a & x))) return 1;
}
// tas abs,y (page-cross)
{
WORD base = 0x20ff, addr = 0x2000;
mem[addr] = 0xcc;
BYTE a = 0xea, x = 0xff, y = 1;
DWORD cycles = TAS_ABSY(a, x, y, base);
if (cycles != 5) return 1;
if (mem[addr] != (a & x & ((base>>8)+1))) return 1;
if (regs.sp != (0x100 | (a & x))) return 1;
}
//
// xas abs,y
{
WORD base = 0x20ff, addr = 0x20ff;
mem[addr] = 0xcc;
BYTE a = 0xea, x = 0x20, y = 0;
DWORD cycles = XAS_ABSY(a, x, y, base);
if (cycles != 5) return 1;
if (mem[addr] != (x & ((base>>8)+1))) return 1;
}
// xas abs,y (page-cross)
{
WORD base = 0x20ff, addr = 0x2000;
mem[addr] = 0xcc;
BYTE a = 0xea, x = 0x20, y = 1;
DWORD cycles = XAS_ABSY(a, x, y, base);
if (cycles != 5) return 1;
if (mem[addr] != (x & ((base>>8)+1))) return 1;
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
init();
reset();
int res = test6502_GH282();
return res;
}

View File

@ -0,0 +1,205 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="TestCPU6502"
ProjectGUID="{2CC8CA9F-E37E-41A4-BFAD-77E54EB783A2}"
RootNamespace="TestCPU6502"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="2"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="2"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\stdafx.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\stdafx.h"
>
</File>
<File
RelativePath=".\TestCPU6502.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// TestCPU6502.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

11
test/TestCPU6502/stdafx.h Normal file
View File

@ -0,0 +1,11 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include <stdio.h>
#include <tchar.h>
#include <windows.h>