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 <iostream>
#include <cstdint> #include <cstdint>
#include <iomanip> #include <iomanip>
@ -429,4 +432,6 @@ namespace MSXHawk
#pragma endregion #pragma endregion
}; };
} }
#endif

View File

@ -1,7 +1,11 @@
#ifndef CORE_H
#define CORE_H
#include <iostream> #include <iostream>
#include <cstdint> #include <cstdint>
#include <iomanip> #include <iomanip>
#include <string> #include <string>
#include <cstring>
#include "Z80A.h" #include "Z80A.h"
#include "AY_3_8910.h" #include "AY_3_8910.h"
@ -203,7 +207,7 @@ namespace MSXHawk
uint32_t* src = vdp.FrameBuffer; uint32_t* src = vdp.FrameBuffer;
uint32_t* dst = dest; 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) uint32_t GetAudio(int32_t* dest, int32_t* n_samp)
@ -211,7 +215,7 @@ namespace MSXHawk
int32_t* src = samples; int32_t* src = samples;
int32_t* dst = dest; 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; n_samp[0] = num_samples;
return sampleclock; return sampleclock;
@ -225,7 +229,7 @@ namespace MSXHawk
// the copy length l must be supplied ahead of time from GetMessageLength // the copy length l must be supplied ahead of time from GetMessageLength
void GetMessage(char* h, int l) 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 #pragma region State Save / Load
@ -305,7 +309,7 @@ namespace MSXHawk
void GetHeader(char* h, int l) 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 // the copy length l must be supplied ahead of time from GetRegStrngLength
@ -313,11 +317,11 @@ namespace MSXHawk
{ {
if (t == 0) if (t == 0)
{ {
memcpy(r, cpu.CPURegisterState().c_str(), l); std::memcpy(r, cpu.CPURegisterState().c_str(), l);
} }
else else
{ {
memcpy(r, cpu.No_Reg, l); std::memcpy(r, cpu.No_Reg, l);
} }
} }
@ -326,15 +330,15 @@ namespace MSXHawk
{ {
if (t == 0) if (t == 0)
{ {
memcpy(d, cpu.CPUDisassembly().c_str(), l); std::memcpy(d, cpu.CPUDisassembly().c_str(), l);
} }
else if (t == 1) else if (t == 1)
{ {
memcpy(d, cpu.NMI_event, l); std::memcpy(d, cpu.NMI_event, l);
} }
else 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) #define MSXHawk_EXPORT extern "C" __declspec(dllexport)
#elif __linux__ #else
#define MSXHawk_EXPORT extern "C" #define MSXHawk_EXPORT extern "C" __attribute__((visibility("default")))
#endif
#endif #endif

View File

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

View File

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

View File

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

View File

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

View File

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