This commit is contained in:
ASNiVOR 2024-11-02 10:58:35 +00:00
parent de98bf9b2e
commit a04aa8c584
10 changed files with 366 additions and 1 deletions

2
.gitignore vendored
View File

@ -48,4 +48,4 @@ UpgradeLog.htm
/packages
launchSettings.json
/ExternalProjects/vfEmu6502/x64/Debug
/ExternalProjects/vfEmu6502/x64

BIN
Assets/dll/vrEmu6502.dll Normal file

Binary file not shown.

View File

@ -0,0 +1,11 @@
#!/bin/sh
if [ -z "$BIZHAWKBUILD_HOME" ]; then export BIZHAWKBUILD_HOME="$(realpath "$(dirname "$0")/../..")"; fi
if [ -z "$CC" ]; then export CXX="clang"; fi
mkdir -p build
$CC -std=c11 -O3 -fvisibility=hidden -fPIC -shared -s FlooohZ80.c -o build/vrEmu6502.so
cp build/libFlooohZ80.so "$BIZHAWKBUILD_HOME/Assets/dll"
if [ -e "$BIZHAWKBUILD_HOME/output" ]; then
cp build/libFlooohZ80.so "$BIZHAWKBUILD_HOME/output/dll"
fi

View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34616.47
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vfEmu6502", "vfEmu6502.vcxproj", "{2215CCFC-9478-4CA8-8E76-661605A6D60C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2215CCFC-9478-4CA8-8E76-661605A6D60C}.Debug|x64.ActiveCfg = Debug|x64
{2215CCFC-9478-4CA8-8E76-661605A6D60C}.Debug|x64.Build.0 = Debug|x64
{2215CCFC-9478-4CA8-8E76-661605A6D60C}.Debug|x86.ActiveCfg = Debug|Win32
{2215CCFC-9478-4CA8-8E76-661605A6D60C}.Debug|x86.Build.0 = Debug|Win32
{2215CCFC-9478-4CA8-8E76-661605A6D60C}.Release|x64.ActiveCfg = Release|x64
{2215CCFC-9478-4CA8-8E76-661605A6D60C}.Release|x64.Build.0 = Release|x64
{2215CCFC-9478-4CA8-8E76-661605A6D60C}.Release|x86.ActiveCfg = Release|Win32
{2215CCFC-9478-4CA8-8E76-661605A6D60C}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FF38F018-AEDF-406B-9DE7-DE892A6B03C1}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,151 @@
<?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>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{2215ccfc-9478-4ca8-8e76-661605a6d60c}</ProjectGuid>
<RootNamespace>vfEmu6502</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>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</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 Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<TargetName>vfEmu6502</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>..\..\Assets\dll</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<TargetName>vrEmu6502</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<CompileAs>CompileAsC</CompileAs>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<CompileAs>CompileAsC</CompileAs>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="vr6502.c" />
<ClCompile Include="vrEmu6502\src\vrEmu6502.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="vrEmu6502\src\vrEmu6502.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,7 @@
#include "vrEmu6502/src/vrEmu6502.h"
#ifdef _WIN32
#define VR_EMU_6502_DLLEXPORT __declspec(dllexport)
#else
#define VR_EMU_6502_DLLEXPORT __attribute__((visibility("default")))
#endif

View File

@ -0,0 +1 @@
#pragma once

View File

@ -0,0 +1,44 @@
using System.Runtime.InteropServices;
using static BizHawk.Emulation.Cores.Components.vr6502.vr6502;
namespace BizHawk.Emulation.Cores.Components.vr6502
{
public static class VrEmu6502Interop
{
private const string lib = "vrEmu6502";
private const CallingConvention cc = CallingConvention.Cdecl;
/// <summary>
/// Instantiate a new 6502 emulator
/// </summary>
[DllImport(lib, CallingConvention = cc)]
public static extern VrEmu6502State vrEmu6502New(
VrEmu6502Model model,
VrEmu6502MemRead readFn,
VrEmu6502MemWrite writeFn);
/// <summary>
/// Destroy a 6502 emulator
/// </summary>
[DllImport(lib, CallingConvention = cc)]
public static extern void vrEmu6502Destroy(ref VrEmu6502State state);
/// <summary>
/// Reset a 6502 emulator
/// </summary>
[DllImport(lib, CallingConvention = cc)]
public static extern void vrEmu6502Reset(ref VrEmu6502State state);
/// <summary>
/// A single clock tick
/// </summary>
[DllImport(lib, CallingConvention = cc)]
public static extern void vrEmu6502Tick(ref VrEmu6502State state);
/// <summary>
/// A single instruction cycle
/// </summary>
[DllImport(lib, CallingConvention = cc)]
public static extern byte vrEmu6502InstCycle(ref VrEmu6502State state);
}
}

View File

@ -0,0 +1,87 @@
using System.Runtime.InteropServices;
namespace BizHawk.Emulation.Cores.Components.vr6502
{
public partial class vr6502
{
[StructLayout(LayoutKind.Sequential)]
public struct VrEmu6502State
{
public VrEmu6502Model Model;
public IntPtr ReadFn;
public IntPtr WriteFn;
public VrEmu6502Interrupt IntPin;
public VrEmu6502Interrupt NmiPin;
public byte Step;
public byte CurrentOpcode;
public ushort CurrentOpcodeAddr;
public bool Wai;
public bool Stp;
public ushort Pc;
public byte Ac;
public byte Ix;
public byte Iy;
public byte Sp;
public byte Flags;
public ushort ZpBase;
public ushort SpBase;
public ushort TmpAddr;
public IntPtr Opcodes; // Use IntPtr for pointer to array
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public string[] MnemonicNames;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public VrEmu6502AddrMode[] AddrModes;
}
public enum VrEmu6502Model
{
CPU_6502,
CPU_6502U,
CPU_65C02,
CPU_W65C02,
CPU_R65C02,
CPU_6510 = CPU_6502U,
CPU_8500 = CPU_6510,
CPU_8502 = CPU_8500,
CPU_7501 = CPU_6502,
CPU_8501 = CPU_6502
}
public enum VrEmu6502Interrupt
{
IntCleared,
IntRequested,
IntLow = IntRequested,
IntHigh = IntCleared
}
public enum VrEmu6502AddrMode
{
AddrModeAbs,
AddrModeAbsX,
AddrModeAbsY,
AddrModeImm,
AddrModeAbsInd,
AddrModeAbsIndX,
AddrModeIndX,
AddrModeIndY,
AddrModeRel,
AddrModeZP,
AddrModeZPI,
AddrModeZPX,
AddrModeZPY,
AddrModeAcc,
AddrModeImp
}
}
}

View File

@ -0,0 +1,33 @@

namespace BizHawk.Emulation.Cores.Components.vr6502
{
public partial class vr6502
{
private VrEmu6502State _6502s;
private readonly VrEmu6502Model _model;
public vr6502(VrEmu6502Model model, VrEmu6502MemRead readFn, VrEmu6502MemWrite writeFn)
{
_model = model;
_6502s = VrEmu6502Interop.vrEmu6502New(_model, readFn, writeFn);
}
public delegate byte VrEmu6502MemRead(ushort addr, bool isDbg);
public delegate void VrEmu6502MemWrite(ushort addr, byte val);
public void Reset()
{
VrEmu6502Interop.vrEmu6502Reset(ref _6502s);
}
public void ExecuteTick()
{
VrEmu6502Interop.vrEmu6502Tick(ref _6502s);
}
public void ExecuteInstruction()
{
VrEmu6502Interop.vrEmu6502InstCycle(ref _6502s);
}
}
}