1
0
mirror of https://github.com/jborza/emu6502.git synced 2024-12-18 02:29:32 +00:00

added a 'nestest' vc++ solution for executing the nestest

This commit is contained in:
jborza 2019-05-07 21:10:28 +02:00
parent c4b2b70d96
commit d1a4c35f9a
7 changed files with 218 additions and 4 deletions

1
.gitignore vendored
View File

@ -58,3 +58,4 @@ dkms.conf
/emu6502.vcxproj.filters
/data/.vscode/ipch
/x64/
/nestest.vcxproj.user

View File

@ -89,7 +89,7 @@ byte * read_bin() {
rewind(file);
byte* buffer = malloc(glob_file_size);
int read = fread(buffer, sizeof(byte), glob_file_size, file);
size_t read = fread(buffer, sizeof(byte), glob_file_size, file);
fclose(file);
return buffer;
}
@ -134,7 +134,7 @@ void print_frame() {
}
}
int main2(int argc, char* argv[]) {
int main(int argc, char* argv[]) {
State6502 state;
clear_state(&state);
state.memory = malloc(MEMORY_SIZE);

View File

@ -17,9 +17,10 @@
#define MEMORY_SIZE 0xFFFF
byte* read_nestest() {
FILE* file = fopen("nestest\\nestest.bin", "rb");
FILE* file = fopen("nestest/nestest.bin", "rb");
if (!file) {
int err = errno;
printf("Couldn't load nestest.bin!");
exit(1);
}
static byte buffer[NESTEST_SIZE];

View File

@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "emu6502", "emu6502.vcxproj"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test6502", "test6502.vcxproj", "{259880CE-646B-48DB-8961-32397CE32005}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nestest", "nestest.vcxproj", "{45934D07-B04C-4348-AC1F-8953CFFD5F8F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@ -31,6 +33,14 @@ Global
{259880CE-646B-48DB-8961-32397CE32005}.Release|x64.Build.0 = Release|x64
{259880CE-646B-48DB-8961-32397CE32005}.Release|x86.ActiveCfg = Release|Win32
{259880CE-646B-48DB-8961-32397CE32005}.Release|x86.Build.0 = Release|Win32
{45934D07-B04C-4348-AC1F-8953CFFD5F8F}.Debug|x64.ActiveCfg = Debug|x64
{45934D07-B04C-4348-AC1F-8953CFFD5F8F}.Debug|x64.Build.0 = Debug|x64
{45934D07-B04C-4348-AC1F-8953CFFD5F8F}.Debug|x86.ActiveCfg = Debug|Win32
{45934D07-B04C-4348-AC1F-8953CFFD5F8F}.Debug|x86.Build.0 = Debug|Win32
{45934D07-B04C-4348-AC1F-8953CFFD5F8F}.Release|x64.ActiveCfg = Release|x64
{45934D07-B04C-4348-AC1F-8953CFFD5F8F}.Release|x64.Build.0 = Release|x64
{45934D07-B04C-4348-AC1F-8953CFFD5F8F}.Release|x86.ActiveCfg = Release|Win32
{45934D07-B04C-4348-AC1F-8953CFFD5F8F}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -154,7 +154,6 @@
<ClCompile Include="cpu.c" />
<ClCompile Include="debugger_windows.c" />
<ClCompile Include="disassembler.c" />
<ClCompile Include="emu6502.c" />
<ClCompile Include="memory.c" />
</ItemGroup>
<ItemGroup>

147
nestest.vcxproj Normal file
View File

@ -0,0 +1,147 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{45934D07-B04C-4348-AC1F-8953CFFD5F8F}</ProjectGuid>
<RootNamespace>nestest</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="cpu.c" />
<ClCompile Include="disassembler.c" />
<ClCompile Include="memory.c" />
<ClCompile Include="nestest_main.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="cpu.h" />
<ClInclude Include="disassembler.h" />
<ClInclude Include="flags.h" />
<ClInclude Include="memory.h" />
<ClInclude Include="opcodes.h" />
<ClInclude Include="state.h" />
<ClInclude Include="types.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

56
nestest_main.c Normal file
View File

@ -0,0 +1,56 @@
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include "state.h"
#include "cpu.h"
#include "disassembler.h"
#include "opcodes.h"
#include <direct.h>
#define NESTEST_SIZE 0x4000
#define NESTEST_DST 0xC000
#define MEMORY_SIZE 0xFFFF
byte* read_nestest() {
FILE* file = fopen("nestest/nestest.bin", "rb");
if (!file) {
printf("Couldn't load nestest.bin!");
exit(1);
}
static byte buffer[NESTEST_SIZE];
int read = fread(&buffer, sizeof(byte), NESTEST_SIZE, file);
fclose(file);
return buffer;
}
byte debug_flags_as_byte(State6502* state) {
byte flags_value = 0;
memcpy(&flags_value, &state->flags, sizeof(Flags));
return flags_value;
}
void run_nestest() {
State6502 state;
clear_state(&state);
state.memory = malloc(MEMORY_SIZE);
memset(state.memory, 0, MEMORY_SIZE);
byte* bin = read_nestest();
//const word TARGET = 0xC000;
memcpy(state.memory + NESTEST_DST, bin, NESTEST_SIZE);
memcpy(state.memory + 0x8000, bin, NESTEST_SIZE);
state.pc = NESTEST_DST;
//a little cheat to simulate probably a JSR and SEI at the beginning
state.sp = 0xfd;
state.flags.i = 1;
do {
char* dasm = disassemble_6502_to_string(state.memory, state.pc);
printf("%-50s A:%02X X:%02X Y:%02X P:%02X SP:%02X\n", dasm, state.a, state.x, state.y, debug_flags_as_byte(&state), state.sp);
emulate_6502_op(&state);
} while (state.flags.b != 1);
}
int main()
{
run_nestest();
return 0;
}