Add new TestDebugger project with some simple unit-tests for _6502_GetTargets() (#445)

This commit is contained in:
tomcw 2017-08-15 21:02:54 +01:00
parent fb963148c2
commit dada9e6af0
7 changed files with 466 additions and 6 deletions

View File

@ -1,12 +1,13 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AppleWin", "AppleWinExpress2008.vcproj", "{1DA0C491-B5F4-4EC8-B1D2-CF6BE635DADC}"
# Visual C++ Express 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Applewin", "AppleWinExpress2008.vcproj", "{1DA0C491-B5F4-4EC8-B1D2-CF6BE635DADC}"
ProjectSection(ProjectDependencies) = postProject
{5CE8051A-3F0C-4C39-B1C0-3338E48BA60F} = {5CE8051A-3F0C-4C39-B1C0-3338E48BA60F}
{7935B998-C713-42AE-8F6D-9FF9080A1B1B} = {7935B998-C713-42AE-8F6D-9FF9080A1B1B}
{2CC8CA9F-E37E-41A4-BFAD-77E54EB783A2} = {2CC8CA9F-E37E-41A4-BFAD-77E54EB783A2}
{709278B8-C583-4BD8-90DE-4E4F35A3BD8B} = {709278B8-C583-4BD8-90DE-4E4F35A3BD8B}
{0AE28CF0-15B0-4DDF-B6D2-4562D8E456BB} = {0AE28CF0-15B0-4DDF-B6D2-4562D8E456BB}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "zlib\zlib-Express2008.vcproj", "{7935B998-C713-42AE-8F6D-9FF9080A1B1B}"
@ -17,6 +18,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestCPU6502", "test\TestCPU
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "yaml", "libyaml\win32\yaml2008.vcproj", "{5CE8051A-3F0C-4C39-B1C0-3338E48BA60F}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestDebugger", "test\TestDebugger\TestDebugger.vcproj", "{0AE28CF0-15B0-4DDF-B6D2-4562D8E456BB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@ -43,6 +46,10 @@ Global
{5CE8051A-3F0C-4C39-B1C0-3338E48BA60F}.Debug|Win32.Build.0 = Debug|Win32
{5CE8051A-3F0C-4C39-B1C0-3338E48BA60F}.Release|Win32.ActiveCfg = Release|Win32
{5CE8051A-3F0C-4C39-B1C0-3338E48BA60F}.Release|Win32.Build.0 = Release|Win32
{0AE28CF0-15B0-4DDF-B6D2-4562D8E456BB}.Debug|Win32.ActiveCfg = Debug|Win32
{0AE28CF0-15B0-4DDF-B6D2-4562D8E456BB}.Debug|Win32.Build.0 = Debug|Win32
{0AE28CF0-15B0-4DDF-B6D2-4562D8E456BB}.Release|Win32.ActiveCfg = Release|Win32
{0AE28CF0-15B0-4DDF-B6D2-4562D8E456BB}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -26,8 +26,8 @@
>
<Tool
Name="VCPreBuildEventTool"
Description="Performing unit-test: TestCPU6502"
CommandLine=".\Release\TestCPU6502.exe"
Description=""
CommandLine=".\test\UnitTests.bat Release"
/>
<Tool
Name="VCCustomBuildTool"
@ -132,8 +132,8 @@
>
<Tool
Name="VCPreBuildEventTool"
Description="Performing unit-test: TestCPU6502"
CommandLine=".\Debug\TestCPU6502.exe"
Description=""
CommandLine=".\test\UnitTests.bat Debug"
/>
<Tool
Name="VCCustomBuildTool"

View File

@ -0,0 +1,195 @@
#include "stdafx.h"
#include "../../source/Applewin.h"
#include "../../source/CPU.h"
#include "../../source/Debugger/Debugger_Types.h"
#include "../../source/Debugger/Debugger_Assembler.h" // Pull in default args for _6502_GetTargets()
// NB. DebugDefs.h must come after Debugger_Types.h which declares these as extern
#include "../../source/Debugger/DebugDefs.h"
// From CPU.cpp
regsrec regs;
// From Frame.cpp
HWND g_hFrameWindow = (HWND)0;
// From Memory.cpp
LPBYTE mem = NULL; // TODO: Init
LPBYTE memdirty = NULL; // TODO: Init
//-------------------------------------
// From Debugger_Console.cpp
char g_aConsolePrompt[] = ">!"; // input, assembler // NUM_PROMPTS
char g_sConsolePrompt[] = ">"; // No, NOT Integer Basic! The nostalgic '*' "Monitor" doesn't look as good, IMHO. :-(
Update_t ConsoleUpdate ()
{
return 0;
}
bool ConsoleBufferPush ( const char * pText )
{
return false;
}
bool ConsoleBufferPushVa ( char* buf, size_t bufsz, const char * pFormat, va_list va )
{
return false;
}
// From Debugger_DisassemblerData.cpp
DisasmData_t* Disassembly_IsDataAddress ( WORD nAddress )
{
return NULL;
}
// From Debugger_Parser.cpp
int g_nArgRaw;
Arg_t g_aArgRaw[ MAX_ARGS ]; // pre-processing
Arg_t g_aArgs [ MAX_ARGS ]; // post-processing (cooked)
bool ArgsGetValue ( Arg_t *pArg, WORD * pAddressValue_, const int nBase )
{
return false;
}
// From Debugger_Symbols.cpp
bool FindAddressFromSymbol ( const char* pSymbol, WORD * pAddress_, int * iTable_ )
{
return false;
}
//-------------------------------------
void init(void)
{
mem = (LPBYTE)VirtualAlloc(NULL,64*1024,MEM_COMMIT,PAGE_READWRITE);
}
void reset(void)
{
regs.a = 0;
regs.x = 0;
regs.y = 0;
regs.pc = 0x300;
regs.sp = 0x1FF;
regs.ps = 0;
regs.bJammed = 0;
}
//-------------------------------------
int GH445_test_sub_PHn(BYTE op)
{
bool bRes;
int TargetAddr[3];
int TargetBytes;
mem[regs.pc] = op;
regs.sp = 0x1FE;
bRes = _6502_GetTargets(regs.pc, &TargetAddr[0], &TargetAddr[1], &TargetAddr[2], &TargetBytes);
if (!bRes || TargetAddr[2] != regs.sp) return 1;
regs.sp = 0x1FF;
bRes = _6502_GetTargets(regs.pc, &TargetAddr[0], &TargetAddr[1], &TargetAddr[2], &TargetBytes);
if (!bRes || TargetAddr[2] != regs.sp) return 1;
regs.sp = 0x100;
bRes = _6502_GetTargets(regs.pc, &TargetAddr[0], &TargetAddr[1], &TargetAddr[2], &TargetBytes);
if (!bRes || TargetAddr[2] != regs.sp) return 1;
return 0;
}
int GH445_test_sub_PLn(BYTE op)
{
bool bRes;
int TargetAddr[3];
int TargetBytes;
mem[regs.pc] = op;
regs.sp = 0x1FE;
bRes = _6502_GetTargets(regs.pc, &TargetAddr[0], &TargetAddr[1], &TargetAddr[2], &TargetBytes);
if (!bRes || TargetAddr[2] != (regs.sp+1)) return 1;
regs.sp = 0x1FF;
bRes = _6502_GetTargets(regs.pc, &TargetAddr[0], &TargetAddr[1], &TargetAddr[2], &TargetBytes);
if (!bRes || TargetAddr[2] != 0x100) return 1;
regs.sp = 0x100;
bRes = _6502_GetTargets(regs.pc, &TargetAddr[0], &TargetAddr[1], &TargetAddr[2], &TargetBytes);
if (!bRes || TargetAddr[2] != (regs.sp+1)) return 1;
return 0;
}
int GH445_test_sub(bool bIs65C02)
{
int res;
regs.pc = 0x300;
res = GH445_test_sub_PHn(0x08); // PHP
if (res) return res;
res = GH445_test_sub_PHn(0x48); // PHA
if (res) return res;
if (bIs65C02)
{
res = GH445_test_sub_PHn(0x5A); // PHY
if (res) return res;
res = GH445_test_sub_PHn(0xDA); // PHX
if (res) return res;
}
//
res = GH445_test_sub_PLn(0x28); // PLP
if (res) return res;
res = GH445_test_sub_PLn(0x68); // PLA
if (res) return res;
if (bIs65C02)
{
res = GH445_test_sub_PLn(0x7A); // PLY
if (res) return res;
res = GH445_test_sub_PLn(0xFA); // PLX
if (res) return res;
}
return 0;
}
int GH445_test(void)
{
int res;
g_aOpcodes = g_aOpcodes65C02;
res = GH445_test_sub(true);
if (res) return res;
g_aOpcodes = g_aOpcodes6502;
res = GH445_test_sub(false);
return res;
}
//-------------------------------------
int _tmain(int argc, _TCHAR* argv[])
{
int res = 1;
init();
reset();
res = GH445_test();
if (res) return res;
return 0;
}

View File

@ -0,0 +1,213 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="TestDebugger"
ProjectGUID="{0AE28CF0-15B0-4DDF-B6D2-4562D8E456BB}"
RootNamespace="TestDebugger"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\source\Debugger"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="2"
WarningLevel="3"
DebugInformationFormat="4"
DisableSpecificWarnings="4819;4996"
/>
<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="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="..\..\source\Debugger"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="2"
WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4819;4996"
/>
<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="..\..\source\Debugger\Debugger_Assembler.cpp"
>
</File>
<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=".\TestDebugger.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// TestDebugger.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

View File

@ -0,0 +1,16 @@
// 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>
#include <ddraw.h>
#include <algorithm>
#include <map>
#include <vector>

21
test/UnitTests.bat Normal file
View File

@ -0,0 +1,21 @@
@REM %1 = <Debug|Release>
@IF "%~1" == "" GOTO help
@ECHO Performing unit-test: TestCPU6502
.\%1\TestCPU6502.exe
@IF errorlevel 1 GOTO failed
@ECHO Performing unit-test: TestDebugger
.\%1\TestDebugger.exe
@if errorlevel 1 GOTO failed
@GOTO end
:failed
@ECHO Unit-test failed
EXIT /B 1
:help
@ECHO %0 "<Debug|Release>"
:end