MSXHawk Linux (#3110)

* hack up a makefile for this

* hack up a build for linux, also fuck msvc fuck msvc fuck msvc

* make this work with the so

* thanks line endings

* lol
This commit is contained in:
CasualPokePlayer 2022-01-30 08:42:20 -08:00 committed by GitHub
parent 2d9651fa89
commit dcccb4e2b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 265 additions and 211 deletions

BIN
Assets/dll/libMSXHawk.so Executable file

Binary file not shown.

View File

@ -1,3 +1,6 @@
#ifndef AY38910_H
#define AY38910_H
#include <iostream>
#include <cstdint>
#include <iomanip>
@ -429,4 +432,6 @@ namespace MSXHawk
#pragma endregion
};
}
}
#endif

View File

@ -1,7 +1,11 @@
#ifndef CORE_H
#define CORE_H
#include <iostream>
#include <cstdint>
#include <iomanip>
#include <string>
#include <cstring>
#include "Z80A.h"
#include "AY_3_8910.h"
@ -203,7 +207,7 @@ namespace MSXHawk
uint32_t* src = vdp.FrameBuffer;
uint32_t* dst = dest;
std::memcpy(dst, src, sizeof uint32_t * 256 * 192);
std::memcpy(dst, src, sizeof (uint32_t) * 256 * 192);
}
uint32_t GetAudio(int32_t* dest, int32_t* n_samp)
@ -211,7 +215,7 @@ namespace MSXHawk
int32_t* src = samples;
int32_t* dst = dest;
std::memcpy(dst, src, sizeof int32_t * num_samples * 2);
std::memcpy(dst, src, sizeof (int32_t) * num_samples * 2);
n_samp[0] = num_samples;
return sampleclock;
@ -225,7 +229,7 @@ namespace MSXHawk
// the copy length l must be supplied ahead of time from GetMessageLength
void GetMessage(char* h, int l)
{
memcpy(h, MemMap.Mem_text_1.c_str(), l);
std::memcpy(h, MemMap.Mem_text_1.c_str(), l);
}
#pragma region State Save / Load
@ -305,7 +309,7 @@ namespace MSXHawk
void GetHeader(char* h, int l)
{
memcpy(h, cpu.TraceHeader, l);
std::memcpy(h, cpu.TraceHeader, l);
}
// the copy length l must be supplied ahead of time from GetRegStrngLength
@ -313,11 +317,11 @@ namespace MSXHawk
{
if (t == 0)
{
memcpy(r, cpu.CPURegisterState().c_str(), l);
std::memcpy(r, cpu.CPURegisterState().c_str(), l);
}
else
{
memcpy(r, cpu.No_Reg, l);
std::memcpy(r, cpu.No_Reg, l);
}
}
@ -326,15 +330,15 @@ namespace MSXHawk
{
if (t == 0)
{
memcpy(d, cpu.CPUDisassembly().c_str(), l);
std::memcpy(d, cpu.CPUDisassembly().c_str(), l);
}
else if (t == 1)
{
memcpy(d, cpu.NMI_event, l);
std::memcpy(d, cpu.NMI_event, l);
}
else
{
memcpy(d, cpu.IRQ_event, l);
std::memcpy(d, cpu.IRQ_event, l);
}
}
@ -342,3 +346,4 @@ namespace MSXHawk
};
}
#endif

View File

@ -1,5 +1,10 @@
#ifdef _WIN32
#ifndef MSXHAWK_H
#define MSXHAWK_H
#ifdef _WIN32 // msvc garbage needs this
#define MSXHawk_EXPORT extern "C" __declspec(dllexport)
#elif __linux__
#define MSXHawk_EXPORT extern "C"
#else
#define MSXHawk_EXPORT extern "C" __attribute__((visibility("default")))
#endif
#endif

View File

@ -1,7 +1,11 @@
#ifndef MEMORY_H
#define MEMORY_H
#include <iostream>
#include <cstdint>
#include <iomanip>
#include <string>
#include <cstring>
using namespace std;
@ -85,8 +89,8 @@ namespace MSXHawk
bios_rom = new uint8_t[0x4000];
basic_rom = new uint8_t[0x4000];
memcpy(bios_rom, bios, 0x4000);
memcpy(basic_rom, basic, 0x4000);
std::memcpy(bios_rom, bios, 0x4000);
std::memcpy(basic_rom, basic, 0x4000);
}
void Load_ROM(uint8_t* ext_rom_1, uint32_t ext_rom_size_1, uint32_t ext_rom_mapper_1, uint8_t* ext_rom_2, uint32_t ext_rom_size_2, uint32_t ext_rom_mapper_2)
@ -94,8 +98,8 @@ namespace MSXHawk
rom_1 = new uint8_t[ext_rom_size_1];
rom_2 = new uint8_t[ext_rom_size_2];
memcpy(rom_1, ext_rom_1, ext_rom_size_1);
memcpy(rom_2, ext_rom_2, ext_rom_size_2);
std::memcpy(rom_1, ext_rom_1, ext_rom_size_1);
std::memcpy(rom_2, ext_rom_2, ext_rom_size_2);
rom_mapper_1 = ext_rom_mapper_1;
rom_mapper_2 = ext_rom_mapper_2;
@ -236,4 +240,6 @@ namespace MSXHawk
#pragma endregion
};
}
}
#endif

View File

@ -1,7 +1,11 @@
#ifndef SCC_H
#define SCC_H
#include <iostream>
#include <cstdint>
#include <iomanip>
#include <string>
#include <cstring>
using namespace std;
@ -325,3 +329,5 @@ namespace MSXHawk
#pragma endregion
};
}
#endif

View File

@ -2,6 +2,7 @@
#include <cstdint>
#include <iomanip>
#include <string>
#include <cstring>
using namespace std;

View File

@ -1,7 +1,15 @@
#ifndef Z80A_H
#define Z80A_H
#include <iostream>
#include <cstdint>
#include <iomanip>
#include <string>
#include <cstring>
#ifndef _WIN32
#define sprintf_s snprintf
#endif
using namespace std;
@ -5585,3 +5593,5 @@ namespace MSXHawk
#pragma endregion
};
}
#endif

View File

@ -1,5 +1,7 @@
// pch.cpp: source file corresponding to the pre-compiled header
#ifdef _WIN32
#include "pch.h"
#endif
// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.

11
libHawk/MSXHawk/Makefile Normal file
View File

@ -0,0 +1,11 @@
CXX = g++
CFLAGS = -Wall -Wextra -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-value -Wno-type-limits -O3 -flto -fvisibility=internal
LFLAGS = -shared
SRCS = $(wildcard MSXHawk/*.cpp)
all: libmsxhawk
libmsxhawk: $(SRCS)
$(CXX) $(CFLAGS) $(SRCS) -o ../../Assets/dll/libMSXHawk.so $(LFLAGS)

View File

@ -1,193 +1,196 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace BizHawk.Emulation.Cores.Computers.MSX
{
/// <summary>
/// static bindings into MSXHawk.dll
/// </summary>
public static class LibMSX
{
/// <returns>opaque state pointer</returns>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr MSX_create();
/// <param name="core">opaque state pointer</param>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void MSX_destroy(IntPtr core);
/// <summary>
/// Load BIOS and BASIC image. each must be 16K in size
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="bios">the rom data, can be disposed of once this function returns</param>
/// <param name="basic">length of romdata in bytes</param>
/// <returns>0 on success, negative value on failure.</returns>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int MSX_load_bios(IntPtr core, byte[] bios, byte[] basic);
/// <summary>
/// Load ROM image.
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="romdata_1">the rom data, can be disposed of once this function returns</param>
/// <param name="length_1">length of romdata in bytes</param>
/// <param name="mapper_1">Mapper number to load core with</param>
/// <param name="romdata_2">the rom data, can be disposed of once this function returns</param>
/// <param name="length_2">length of romdata in bytes</param>
/// <param name="mapper_2">Mapper number to load core with</param>
/// <returns>0 on success, negative value on failure.</returns>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int MSX_load(IntPtr core, byte[] romdata_1, uint length_1, int mapper_1, byte[] romdata_2, uint length_2, int mapper_2);
/// <summary>
/// Advance a frame and send controller data.
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="ctrl1">controller data for player 1</param>
/// <param name="ctrl2">controller data for player 2</param>
/// <param name="render">length of romdata in bytes</param>
/// <param name="sound">Mapper number to load core with</param>
/// <returns>0 on success, negative value on failure.</returns>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern bool MSX_frame_advance(IntPtr core, byte ctrl1, byte ctrl2, byte[] kbrows, bool render, bool sound);
/// <summary>
/// Get Video data
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="videobuf">where to send video to</param>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void MSX_get_video(IntPtr core, int[] videobuf);
/// <summary>
/// Get Video data
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="aud_buf">where to send left audio to</param>
/// <param name="n_samp">number of left samples</param>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern uint MSX_get_audio(IntPtr core, int[] aud_buf, ref uint n_samp);
/// <summary>
/// get messages length
/// </summary>
/// <param name="core">opaque state pointer</param>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int MSX_getmessagelength(IntPtr core);
/// <summary>
/// get messages from the core
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="h">pointer to const char *</param>
/// <param name="l">length of message to fetch</param>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void MSX_getmessage(IntPtr core, StringBuilder h, int l);
/// <summary>
/// Save State
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="saver">save buffer</param>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void MSX_save_state(IntPtr core, byte[] saver);
/// <summary>
/// Load State
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="loader">load buffer</param>
[DllImport("MSXHAWK.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void MSX_load_state(IntPtr core, byte[] loader);
/// <summary>
/// Read the system bus
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="addr">system bus address</param>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern byte MSX_getsysbus(IntPtr core, int addr);
/// <summary>
/// Read the VRAM
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="addr">vram address</param>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern byte MSX_getvram(IntPtr core, int addr);
/// <summary>
/// Read the RAM
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="addr">ram address</param>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern byte MSX_getram(IntPtr core, int addr);
/// <summary>
/// type of the cpu trace callback
/// </summary>
/// <param name="t">type of event</param>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void TraceCallback(int t);
/// <summary>
/// set a callback for trace logging
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="callback">null to clear</param>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void MSX_settracecallback(IntPtr core, TraceCallback callback);
/// <summary>
/// get the trace logger header length
/// </summary>
/// <param name="core">opaque state pointer</param>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int MSX_getheaderlength(IntPtr core);
/// <summary>
/// get the trace logger disassembly length, a constant
/// </summary>
/// <param name="core">opaque state pointer</param>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int MSX_getdisasmlength(IntPtr core);
/// <summary>
/// get the trace logger register string length, a constant
/// </summary>
/// <param name="core">opaque state pointer</param>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int MSX_getregstringlength(IntPtr core);
/// <summary>
/// get the trace logger header
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="h">pointer to const char *</param>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void MSX_getheader(IntPtr core, StringBuilder h, int l);
/// <summary>
/// get the register state from the cpu
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="h">pointer to const char *</param>
/// <param name="t">call type</param>
/// <param name="l">copy length, must be obtained from appropriate get legnth function</param>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void MSX_getregisterstate(IntPtr core, StringBuilder h, int t, int l);
/// <summary>
/// get the register state from the cpu
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="h">pointer to const char *</param>
/// <param name="t">call type</param>
/// <param name="l">copy length, must be obtained from appropriate get legnth function</param>
[DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void MSX_getdisassembly(IntPtr core, StringBuilder h, int t, int l);
}
}
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace BizHawk.Emulation.Cores.Computers.MSX
{
/// <summary>
/// static bindings into MSXHawk.dll
/// </summary>
public static class LibMSX
{
private const string lib = "MSXHawk";
private const CallingConvention cc = CallingConvention.Cdecl;
/// <returns>opaque state pointer</returns>
[DllImport(lib, CallingConvention = cc)]
public static extern IntPtr MSX_create();
/// <param name="core">opaque state pointer</param>
[DllImport(lib, CallingConvention = cc)]
public static extern void MSX_destroy(IntPtr core);
/// <summary>
/// Load BIOS and BASIC image. each must be 16K in size
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="bios">the rom data, can be disposed of once this function returns</param>
/// <param name="basic">length of romdata in bytes</param>
/// <returns>0 on success, negative value on failure.</returns>
[DllImport(lib, CallingConvention = cc)]
public static extern int MSX_load_bios(IntPtr core, byte[] bios, byte[] basic);
/// <summary>
/// Load ROM image.
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="romdata_1">the rom data, can be disposed of once this function returns</param>
/// <param name="length_1">length of romdata in bytes</param>
/// <param name="mapper_1">Mapper number to load core with</param>
/// <param name="romdata_2">the rom data, can be disposed of once this function returns</param>
/// <param name="length_2">length of romdata in bytes</param>
/// <param name="mapper_2">Mapper number to load core with</param>
/// <returns>0 on success, negative value on failure.</returns>
[DllImport(lib, CallingConvention = cc)]
public static extern int MSX_load(IntPtr core, byte[] romdata_1, uint length_1, int mapper_1, byte[] romdata_2, uint length_2, int mapper_2);
/// <summary>
/// Advance a frame and send controller data.
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="ctrl1">controller data for player 1</param>
/// <param name="ctrl2">controller data for player 2</param>
/// <param name="render">length of romdata in bytes</param>
/// <param name="sound">Mapper number to load core with</param>
/// <returns>0 on success, negative value on failure.</returns>
[DllImport(lib, CallingConvention = cc)]
public static extern bool MSX_frame_advance(IntPtr core, byte ctrl1, byte ctrl2, byte[] kbrows, bool render, bool sound);
/// <summary>
/// Get Video data
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="videobuf">where to send video to</param>
[DllImport(lib, CallingConvention = cc)]
public static extern void MSX_get_video(IntPtr core, int[] videobuf);
/// <summary>
/// Get Video data
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="aud_buf">where to send left audio to</param>
/// <param name="n_samp">number of left samples</param>
[DllImport(lib, CallingConvention = cc)]
public static extern uint MSX_get_audio(IntPtr core, int[] aud_buf, ref uint n_samp);
/// <summary>
/// get messages length
/// </summary>
/// <param name="core">opaque state pointer</param>
[DllImport(lib, CallingConvention = cc)]
public static extern int MSX_getmessagelength(IntPtr core);
/// <summary>
/// get messages from the core
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="h">pointer to const char *</param>
/// <param name="l">length of message to fetch</param>
[DllImport(lib, CallingConvention = cc)]
public static extern void MSX_getmessage(IntPtr core, StringBuilder h, int l);
/// <summary>
/// Save State
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="saver">save buffer</param>
[DllImport(lib, CallingConvention = cc)]
public static extern void MSX_save_state(IntPtr core, byte[] saver);
/// <summary>
/// Load State
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="loader">load buffer</param>
[DllImport(lib, CallingConvention = cc)]
public static extern void MSX_load_state(IntPtr core, byte[] loader);
/// <summary>
/// Read the system bus
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="addr">system bus address</param>
[DllImport(lib, CallingConvention = cc)]
public static extern byte MSX_getsysbus(IntPtr core, int addr);
/// <summary>
/// Read the VRAM
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="addr">vram address</param>
[DllImport(lib, CallingConvention = cc)]
public static extern byte MSX_getvram(IntPtr core, int addr);
/// <summary>
/// Read the RAM
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="addr">ram address</param>
[DllImport(lib, CallingConvention = cc)]
public static extern byte MSX_getram(IntPtr core, int addr);
/// <summary>
/// type of the cpu trace callback
/// </summary>
/// <param name="t">type of event</param>
[UnmanagedFunctionPointer(cc)]
public delegate void TraceCallback(int t);
/// <summary>
/// set a callback for trace logging
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="callback">null to clear</param>
[DllImport(lib, CallingConvention = cc)]
public static extern void MSX_settracecallback(IntPtr core, TraceCallback callback);
/// <summary>
/// get the trace logger header length
/// </summary>
/// <param name="core">opaque state pointer</param>
[DllImport(lib, CallingConvention = cc)]
public static extern int MSX_getheaderlength(IntPtr core);
/// <summary>
/// get the trace logger disassembly length, a constant
/// </summary>
/// <param name="core">opaque state pointer</param>
[DllImport(lib, CallingConvention = cc)]
public static extern int MSX_getdisasmlength(IntPtr core);
/// <summary>
/// get the trace logger register string length, a constant
/// </summary>
/// <param name="core">opaque state pointer</param>
[DllImport(lib, CallingConvention = cc)]
public static extern int MSX_getregstringlength(IntPtr core);
/// <summary>
/// get the trace logger header
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="h">pointer to const char *</param>
[DllImport(lib, CallingConvention = cc)]
public static extern void MSX_getheader(IntPtr core, StringBuilder h, int l);
/// <summary>
/// get the register state from the cpu
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="h">pointer to const char *</param>
/// <param name="t">call type</param>
/// <param name="l">copy length, must be obtained from appropriate get legnth function</param>
[DllImport(lib, CallingConvention = cc)]
public static extern void MSX_getregisterstate(IntPtr core, StringBuilder h, int t, int l);
/// <summary>
/// get the register state from the cpu
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="h">pointer to const char *</param>
/// <param name="t">call type</param>
/// <param name="l">copy length, must be obtained from appropriate get legnth function</param>
[DllImport(lib, CallingConvention = cc)]
public static extern void MSX_getdisassembly(IntPtr core, StringBuilder h, int t, int l);
}
}