Skip to content

Commit

Permalink
[CPCHawk] Trying a new z80 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Asnivor committed Oct 6, 2024
1 parent 9e0cfb1 commit c644ed1
Show file tree
Hide file tree
Showing 19 changed files with 6,084 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ UpgradeLog.htm
/packages

launchSettings.json
/ExternalProjects/FlooohZ80/x64
Binary file added Assets/dll/FlooohZ80.dll
Binary file not shown.
174 changes: 174 additions & 0 deletions ExternalProjects/FlooohZ80/FlooohZ80.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#define CHIPS_IMPL
#include "FlooohZ80.h"
#include <stdlib.h> // Include for malloc and free

LibFz80::LibFz80() {
z80Instance = new z80_t();
z80_init(z80Instance);
}

LibFz80::~LibFz80() {
delete z80Instance;
}

uint64_t LibFz80::Initialize() {
return z80_init(z80Instance);
}

uint64_t LibFz80::Reset() {
return z80_reset(z80Instance);
}

uint64_t LibFz80::Tick(uint64_t pins) {
return z80_tick(z80Instance, pins);
}

uint64_t LibFz80::Prefetch(uint16_t new_pc) {
return z80_prefetch(z80Instance, new_pc);
}

bool LibFz80::InstructionDone() {
return z80_opdone(z80Instance);
}

// Getter methods for z80_t members
uint16_t LibFz80::GET_step() { return z80Instance->step; }
uint16_t LibFz80::GET_addr() { return z80Instance->addr; }
uint8_t LibFz80::GET_dlatch() { return z80Instance->dlatch; }
uint8_t LibFz80::GET_opcode() { return z80Instance->opcode; }
uint8_t LibFz80::GET_hlx_idx() { return z80Instance->hlx_idx; }
bool LibFz80::GET_prefix_active() { return z80Instance->prefix_active; }
uint64_t LibFz80::GET_pins() { return z80Instance->pins; }
uint64_t LibFz80::GET_int_bits() { return z80Instance->int_bits; }
uint16_t LibFz80::GET_pc() { return z80Instance->pc; }
uint16_t LibFz80::GET_af() { return z80Instance->af; }
uint16_t LibFz80::GET_bc() { return z80Instance->bc; }
uint16_t LibFz80::GET_de() { return z80Instance->de; }
uint16_t LibFz80::GET_hl() { return z80Instance->hl; }
uint16_t LibFz80::GET_ix() { return z80Instance->ix; }
uint16_t LibFz80::GET_iy() { return z80Instance->iy; }
uint16_t LibFz80::GET_wz() { return z80Instance->wz; }
uint16_t LibFz80::GET_sp() { return z80Instance->sp; }
uint16_t LibFz80::GET_ir() { return z80Instance->ir; }
uint16_t LibFz80::GET_af2() { return z80Instance->af2; }
uint16_t LibFz80::GET_bc2() { return z80Instance->bc2; }
uint16_t LibFz80::GET_de2() { return z80Instance->de2; }
uint16_t LibFz80::GET_hl2() { return z80Instance->hl2; }
uint8_t LibFz80::GET_im() { return z80Instance->im; }
bool LibFz80::GET_iff1() { return z80Instance->iff1; }
bool LibFz80::GET_iff2() { return z80Instance->iff2; }

// Setter methods for z80_t members
void LibFz80::SET_step(uint16_t value) { z80Instance->step = value; }
void LibFz80::SET_addr(uint16_t value) { z80Instance->addr = value; }
void LibFz80::SET_dlatch(uint8_t value) { z80Instance->dlatch = value; }
void LibFz80::SET_opcode(uint8_t value) { z80Instance->opcode = value; }
void LibFz80::SET_hlx_idx(uint8_t value) { z80Instance->hlx_idx = value; }
void LibFz80::SET_prefix_active(bool value) { z80Instance->prefix_active = value; }
void LibFz80::SET_pins(uint64_t value) { z80Instance->pins = value; }
void LibFz80::SET_int_bits(uint64_t value) { z80Instance->int_bits = value; }
void LibFz80::SET_pc(uint16_t value) { z80Instance->pc = value; }
void LibFz80::SET_af(uint16_t value) { z80Instance->af = value; }
void LibFz80::SET_bc(uint16_t value) { z80Instance->bc = value; }
void LibFz80::SET_de(uint16_t value) { z80Instance->de = value; }
void LibFz80::SET_hl(uint16_t value) { z80Instance->hl = value; }
void LibFz80::SET_ix(uint16_t value) { z80Instance->ix = value; }
void LibFz80::SET_iy(uint16_t value) { z80Instance->iy = value; }
void LibFz80::SET_wz(uint16_t value) { z80Instance->wz = value; }
void LibFz80::SET_sp(uint16_t value) { z80Instance->sp = value; }
void LibFz80::SET_ir(uint16_t value) { z80Instance->ir = value; }
void LibFz80::SET_af2(uint16_t value) { z80Instance->af2 = value; }
void LibFz80::SET_bc2(uint16_t value) { z80Instance->bc2 = value; }
void LibFz80::SET_de2(uint16_t value) { z80Instance->de2 = value; }
void LibFz80::SET_hl2(uint16_t value) { z80Instance->hl2 = value; }
void LibFz80::SET_im(uint8_t value) { z80Instance->im = value; }
void LibFz80::SET_iff1(bool value) { z80Instance->iff1 = value; }
void LibFz80::SET_iff2(bool value) { z80Instance->iff2 = value; }


// Expose the functions for C# interoperability
extern "C" {

__declspec(dllexport) LibFz80* CreateLibFz80() {
return new LibFz80();
}

__declspec(dllexport) void DestroyLibFz80(LibFz80* instance) {
delete instance;
}

__declspec(dllexport) uint64_t LibFz80_Initialize(LibFz80* instance) {
return instance->Initialize();
}

__declspec(dllexport) uint64_t LibFz80_Reset(LibFz80* instance) {
return instance->Reset();
}

__declspec(dllexport) uint64_t LibFz80_Tick(LibFz80* instance, uint64_t pins) {
return instance->Tick(pins);
}

__declspec(dllexport) uint64_t LibFz80_Prefetch(LibFz80* instance, uint16_t new_pc) {
return instance->Prefetch(new_pc);
}

__declspec(dllexport) bool LibFz80_InstructionDone(LibFz80* instance) {
return instance->InstructionDone();
}


// Getter functions
__declspec(dllexport) uint16_t LibFz80_GET_step(LibFz80* instance) { return instance->GET_step(); }
__declspec(dllexport) uint16_t LibFz80_GET_addr(LibFz80* instance) { return instance->GET_addr(); }
__declspec(dllexport) uint8_t LibFz80_GET_dlatch(LibFz80* instance) { return instance->GET_dlatch(); }
__declspec(dllexport) uint8_t LibFz80_GET_opcode(LibFz80* instance) { return instance->GET_opcode(); }
__declspec(dllexport) uint8_t LibFz80_GET_hlx_idx(LibFz80* instance) { return instance->GET_hlx_idx(); }
__declspec(dllexport) bool LibFz80_GET_prefix_active(LibFz80* instance) { return instance->GET_prefix_active(); }
__declspec(dllexport) uint64_t LibFz80_GET_pins(LibFz80* instance) { return instance->GET_pins(); }
__declspec(dllexport) uint64_t LibFz80_GET_int_bits(LibFz80* instance) { return instance->GET_int_bits(); }
__declspec(dllexport) uint16_t LibFz80_GET_pc(LibFz80* instance) { return instance->GET_pc(); }
__declspec(dllexport) uint16_t LibFz80_GET_af(LibFz80* instance) { return instance->GET_af(); }
__declspec(dllexport) uint16_t LibFz80_GET_bc(LibFz80* instance) { return instance->GET_bc(); }
__declspec(dllexport) uint16_t LibFz80_GET_de(LibFz80* instance) { return instance->GET_de(); }
__declspec(dllexport) uint16_t LibFz80_GET_hl(LibFz80* instance) { return instance->GET_hl(); }
__declspec(dllexport) uint16_t LibFz80_GET_ix(LibFz80* instance) { return instance->GET_ix(); }
__declspec(dllexport) uint16_t LibFz80_GET_iy(LibFz80* instance) { return instance->GET_iy(); }
__declspec(dllexport) uint16_t LibFz80_GET_wz(LibFz80* instance) { return instance->GET_wz(); }
__declspec(dllexport) uint16_t LibFz80_GET_sp(LibFz80* instance) { return instance->GET_sp(); }
__declspec(dllexport) uint16_t LibFz80_GET_ir(LibFz80* instance) { return instance->GET_ir(); }
__declspec(dllexport) uint16_t LibFz80_GET_af2(LibFz80* instance) { return instance->GET_af2(); }
__declspec(dllexport) uint16_t LibFz80_GET_bc2(LibFz80* instance) { return instance->GET_bc2(); }
__declspec(dllexport) uint16_t LibFz80_GET_de2(LibFz80* instance) { return instance->GET_de2(); }
__declspec(dllexport) uint16_t LibFz80_GET_hl2(LibFz80* instance) { return instance->GET_hl2(); }
__declspec(dllexport) uint8_t LibFz80_GET_im(LibFz80* instance) { return instance->GET_im(); }
__declspec(dllexport) bool LibFz80_GET_iff1(LibFz80* instance) { return instance->GET_iff1(); }
__declspec(dllexport) bool LibFz80_GET_iff2(LibFz80* instance) { return instance->GET_iff2(); }

// Setter functions
__declspec(dllexport) void LibFz80_SET_step(LibFz80* instance, uint16_t value) { instance->SET_step(value); }
__declspec(dllexport) void LibFz80_SET_addr(LibFz80* instance, uint16_t value) { instance->SET_addr(value); }
__declspec(dllexport) void LibFz80_SET_dlatch(LibFz80* instance, uint8_t value) { instance->SET_dlatch(value); }
__declspec(dllexport) void LibFz80_SET_opcode(LibFz80* instance, uint8_t value) { instance->SET_opcode(value); }
__declspec(dllexport) void LibFz80_SET_hlx_idx(LibFz80* instance, uint8_t value) { instance->SET_hlx_idx(value); }
__declspec(dllexport) void LibFz80_SET_prefix_active(LibFz80* instance, bool value) { instance->SET_prefix_active(value); }
__declspec(dllexport) void LibFz80_SET_pins(LibFz80* instance, uint64_t value) { instance->SET_pins(value); }
__declspec(dllexport) void LibFz80_SET_int_bits(LibFz80* instance, uint64_t value) { instance->SET_int_bits(value); }
__declspec(dllexport) void LibFz80_SET_pc(LibFz80* instance, uint16_t value) { instance->SET_pc(value); }
__declspec(dllexport) void LibFz80_SET_af(LibFz80* instance, uint16_t value) { instance->SET_af(value); }
__declspec(dllexport) void LibFz80_SET_bc(LibFz80* instance, uint16_t value) { instance->SET_bc(value); }
__declspec(dllexport) void LibFz80_SET_de(LibFz80* instance, uint16_t value) { instance->SET_de(value); }
__declspec(dllexport) void LibFz80_SET_hl(LibFz80* instance, uint16_t value) { instance->SET_hl(value); }
__declspec(dllexport) void LibFz80_SET_ix(LibFz80* instance, uint16_t value) { instance->SET_ix(value); }
__declspec(dllexport) void LibFz80_SET_iy(LibFz80* instance, uint16_t value) { instance->SET_iy(value); }
__declspec(dllexport) void LibFz80_SET_wz(LibFz80* instance, uint16_t value) { instance->SET_wz(value); }
__declspec(dllexport) void LibFz80_SET_sp(LibFz80* instance, uint16_t value) { instance->SET_sp(value); }
__declspec(dllexport) void LibFz80_SET_ir(LibFz80* instance, uint16_t value) { instance->SET_ir(value); }
__declspec(dllexport) void LibFz80_SET_af2(LibFz80* instance, uint16_t value) { instance->SET_af2(value); }
__declspec(dllexport) void LibFz80_SET_bc2(LibFz80* instance, uint16_t value) { instance->SET_bc2(value); }
__declspec(dllexport) void LibFz80_SET_de2(LibFz80* instance, uint16_t value) { instance->SET_de2(value); }
__declspec(dllexport) void LibFz80_SET_hl2(LibFz80* instance, uint16_t value) { instance->SET_hl2(value); }
__declspec(dllexport) void LibFz80_SET_im(LibFz80* instance, uint8_t value) { instance->SET_im(value); }
__declspec(dllexport) void LibFz80_SET_iff1(LibFz80* instance, bool value) { instance->SET_iff1(value); }
__declspec(dllexport) void LibFz80_SET_iff2(LibFz80* instance, bool value) { instance->SET_iff2(value); }
}
142 changes: 142 additions & 0 deletions ExternalProjects/FlooohZ80/FlooohZ80.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#ifndef FLOOOHZ80_H
#define FLOOOHZ80_H

#include <stdint.h>
#include <stdbool.h>
#include "z80.h"

class LibFz80 {
public:
LibFz80();
~LibFz80();

uint64_t Initialize();
uint64_t Reset();
uint64_t Tick(uint64_t pins);
uint64_t Prefetch(uint16_t new_pc);
bool InstructionDone();

// getter methods for the z80_t struct members
uint16_t GET_step();
uint16_t GET_addr();
uint8_t GET_dlatch();
uint8_t GET_opcode();
uint8_t GET_hlx_idx();
bool GET_prefix_active();
uint64_t GET_pins();
uint64_t GET_int_bits();
uint16_t GET_pc();
uint16_t GET_af();
uint16_t GET_bc();
uint16_t GET_de();
uint16_t GET_hl();
uint16_t GET_ix();
uint16_t GET_iy();
uint16_t GET_wz();
uint16_t GET_sp();
uint16_t GET_ir();
uint16_t GET_af2();
uint16_t GET_bc2();
uint16_t GET_de2();
uint16_t GET_hl2();
uint8_t GET_im();
bool GET_iff1();
bool GET_iff2();

// setter methods for the z80_t struct members
void SET_step(uint16_t value);
void SET_addr(uint16_t value);
void SET_dlatch(uint8_t value);
void SET_opcode(uint8_t value);
void SET_hlx_idx(uint8_t value);
void SET_prefix_active(bool value);
void SET_pins(uint64_t value);
void SET_int_bits(uint64_t value);
void SET_pc(uint16_t value);
void SET_af(uint16_t value);
void SET_bc(uint16_t value);
void SET_de(uint16_t value);
void SET_hl(uint16_t value);
void SET_ix(uint16_t value);
void SET_iy(uint16_t value);
void SET_wz(uint16_t value);
void SET_sp(uint16_t value);
void SET_ir(uint16_t value);
void SET_af2(uint16_t value);
void SET_bc2(uint16_t value);
void SET_de2(uint16_t value);
void SET_hl2(uint16_t value);
void SET_im(uint8_t value);
void SET_iff1(bool value);
void SET_iff2(bool value);

private:
z80_t* z80Instance;
};

// Expose the functions for C# interoperability
extern "C" {
__declspec(dllexport) LibFz80* CreateLibFz80();
__declspec(dllexport) void DestroyLibFz80(LibFz80* instance);
__declspec(dllexport) uint64_t LibFz80_Initialize(LibFz80* instance);
__declspec(dllexport) uint64_t LibFz80_Reset(LibFz80* instance);
__declspec(dllexport) uint64_t LibFz80_Tick(LibFz80* instance, uint64_t pins);
__declspec(dllexport) uint64_t LibFz80_Prefetch(LibFz80* instance, uint16_t new_pc);
__declspec(dllexport) bool LibFz80_InstructionDone(LibFz80* instance);

// expose struct field getters
__declspec(dllexport) uint16_t LibFz80_GET_step(LibFz80* instance);
__declspec(dllexport) uint16_t LibFz80_GET_addr(LibFz80* instance);
__declspec(dllexport) uint8_t LibFz80_GET_dlatch(LibFz80* instance);
__declspec(dllexport) uint8_t LibFz80_GET_opcode(LibFz80* instance);
__declspec(dllexport) uint8_t LibFz80_GET_hlx_idx(LibFz80* instance);
__declspec(dllexport) bool LibFz80_GET_prefix_active(LibFz80* instance);
__declspec(dllexport) uint64_t LibFz80_GET_pins(LibFz80* instance);
__declspec(dllexport) uint64_t LibFz80_GET_int_bits(LibFz80* instance);
__declspec(dllexport) uint16_t LibFz80_GET_pc(LibFz80* instance);
__declspec(dllexport) uint16_t LibFz80_GET_af(LibFz80* instance);
__declspec(dllexport) uint16_t LibFz80_GET_bc(LibFz80* instance);
__declspec(dllexport) uint16_t LibFz80_GET_de(LibFz80* instance);
__declspec(dllexport) uint16_t LibFz80_GET_hl(LibFz80* instance);
__declspec(dllexport) uint16_t LibFz80_GET_ix(LibFz80* instance);
__declspec(dllexport) uint16_t LibFz80_GET_iy(LibFz80* instance);
__declspec(dllexport) uint16_t LibFz80_GET_wz(LibFz80* instance);
__declspec(dllexport) uint16_t LibFz80_GET_sp(LibFz80* instance);
__declspec(dllexport) uint16_t LibFz80_GET_ir(LibFz80* instance);
__declspec(dllexport) uint16_t LibFz80_GET_af2(LibFz80* instance);
__declspec(dllexport) uint16_t LibFz80_GET_bc2(LibFz80* instance);
__declspec(dllexport) uint16_t LibFz80_GET_de2(LibFz80* instance);
__declspec(dllexport) uint16_t LibFz80_GET_hl2(LibFz80* instance);
__declspec(dllexport) uint8_t LibFz80_GET_im(LibFz80* instance);
__declspec(dllexport) bool LibFz80_GET_iff1(LibFz80* instance);
__declspec(dllexport) bool LibFz80_GET_iff2(LibFz80* instance);

// expose struct field setters
__declspec(dllexport) void LibFz80_SET_step(LibFz80* instance, uint16_t value);
__declspec(dllexport) void LibFz80_SET_addr(LibFz80* instance, uint16_t value);
__declspec(dllexport) void LibFz80_SET_dlatch(LibFz80* instance, uint8_t value);
__declspec(dllexport) void LibFz80_SET_opcode(LibFz80* instance, uint8_t value);
__declspec(dllexport) void LibFz80_SET_hlx_idx(LibFz80* instance, uint8_t value);
__declspec(dllexport) void LibFz80_SET_prefix_active(LibFz80* instance, bool value);
__declspec(dllexport) void LibFz80_SET_pins(LibFz80* instance, uint64_t value);
__declspec(dllexport) void LibFz80_SET_int_bits(LibFz80* instance, uint64_t value);
__declspec(dllexport) void LibFz80_SET_pc(LibFz80* instance, uint16_t value);
__declspec(dllexport) void LibFz80_SET_af(LibFz80* instance, uint16_t value);
__declspec(dllexport) void LibFz80_SET_bc(LibFz80* instance, uint16_t value);
__declspec(dllexport) void LibFz80_SET_de(LibFz80* instance, uint16_t value);
__declspec(dllexport) void LibFz80_SET_hl(LibFz80* instance, uint16_t value);
__declspec(dllexport) void LibFz80_SET_ix(LibFz80* instance, uint16_t value);
__declspec(dllexport) void LibFz80_SET_iy(LibFz80* instance, uint16_t value);
__declspec(dllexport) void LibFz80_SET_wz(LibFz80* instance, uint16_t value);
__declspec(dllexport) void LibFz80_SET_sp(LibFz80* instance, uint16_t value);
__declspec(dllexport) void LibFz80_SET_ir(LibFz80* instance, uint16_t value);
__declspec(dllexport) void LibFz80_SET_af2(LibFz80* instance, uint16_t value);
__declspec(dllexport) void LibFz80_SET_bc2(LibFz80* instance, uint16_t value);
__declspec(dllexport) void LibFz80_SET_de2(LibFz80* instance, uint16_t value);
__declspec(dllexport) void LibFz80_SET_hl2(LibFz80* instance, uint16_t value);
__declspec(dllexport) void LibFz80_SET_im(LibFz80* instance, uint8_t value);
__declspec(dllexport) void LibFz80_SET_iff1(LibFz80* instance, bool value);
__declspec(dllexport) void LibFz80_SET_iff2(LibFz80* instance, bool value);
}

#endif // FLOOOHZ80_H
31 changes: 31 additions & 0 deletions ExternalProjects/FlooohZ80/FlooohZ80.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35312.102
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FlooohZ80", "FlooohZ80.vcxproj", "{E1CCFFD1-D23B-4507-88EA-0184A6CE99BF}"
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
{E1CCFFD1-D23B-4507-88EA-0184A6CE99BF}.Debug|x64.ActiveCfg = Debug|x64
{E1CCFFD1-D23B-4507-88EA-0184A6CE99BF}.Debug|x64.Build.0 = Debug|x64
{E1CCFFD1-D23B-4507-88EA-0184A6CE99BF}.Debug|x86.ActiveCfg = Debug|Win32
{E1CCFFD1-D23B-4507-88EA-0184A6CE99BF}.Debug|x86.Build.0 = Debug|Win32
{E1CCFFD1-D23B-4507-88EA-0184A6CE99BF}.Release|x64.ActiveCfg = Release|x64
{E1CCFFD1-D23B-4507-88EA-0184A6CE99BF}.Release|x64.Build.0 = Release|x64
{E1CCFFD1-D23B-4507-88EA-0184A6CE99BF}.Release|x86.ActiveCfg = Release|Win32
{E1CCFFD1-D23B-4507-88EA-0184A6CE99BF}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {34D77329-729A-4192-A813-9163DDBEB85A}
EndGlobalSection
EndGlobal
Loading

0 comments on commit c644ed1

Please sign in to comment.