diff --git a/Assets/dll/libMSXHawk.so b/Assets/dll/libMSXHawk.so new file mode 100755 index 0000000000..a6d59e33c1 Binary files /dev/null and b/Assets/dll/libMSXHawk.so differ diff --git a/libHawk/MSXHawk/MSXHawk/AY_3_8910.h b/libHawk/MSXHawk/MSXHawk/AY_3_8910.h index 20e5293987..accfa0820c 100644 --- a/libHawk/MSXHawk/MSXHawk/AY_3_8910.h +++ b/libHawk/MSXHawk/MSXHawk/AY_3_8910.h @@ -1,3 +1,6 @@ +#ifndef AY38910_H +#define AY38910_H + #include #include #include @@ -429,4 +432,6 @@ namespace MSXHawk #pragma endregion }; -} \ No newline at end of file +} + +#endif diff --git a/libHawk/MSXHawk/MSXHawk/Core.h b/libHawk/MSXHawk/MSXHawk/Core.h index 4b7c0648da..566caee026 100644 --- a/libHawk/MSXHawk/MSXHawk/Core.h +++ b/libHawk/MSXHawk/MSXHawk/Core.h @@ -1,7 +1,11 @@ +#ifndef CORE_H +#define CORE_H + #include #include #include #include +#include #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 diff --git a/libHawk/MSXHawk/MSXHawk/MSXHawk.h b/libHawk/MSXHawk/MSXHawk/MSXHawk.h index 37cb5e0c27..1f8f65ca05 100644 --- a/libHawk/MSXHawk/MSXHawk/MSXHawk.h +++ b/libHawk/MSXHawk/MSXHawk/MSXHawk.h @@ -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 diff --git a/libHawk/MSXHawk/MSXHawk/Memory.h b/libHawk/MSXHawk/MSXHawk/Memory.h index bcd18ef9c7..aa21d4d873 100644 --- a/libHawk/MSXHawk/MSXHawk/Memory.h +++ b/libHawk/MSXHawk/MSXHawk/Memory.h @@ -1,7 +1,11 @@ +#ifndef MEMORY_H +#define MEMORY_H + #include #include #include #include +#include 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 }; -} \ No newline at end of file +} + +#endif diff --git a/libHawk/MSXHawk/MSXHawk/SCC.h b/libHawk/MSXHawk/MSXHawk/SCC.h index 019f074907..7eaa8e9997 100644 --- a/libHawk/MSXHawk/MSXHawk/SCC.h +++ b/libHawk/MSXHawk/MSXHawk/SCC.h @@ -1,7 +1,11 @@ +#ifndef SCC_H +#define SCC_H + #include #include #include #include +#include using namespace std; @@ -325,3 +329,5 @@ namespace MSXHawk #pragma endregion }; } + +#endif diff --git a/libHawk/MSXHawk/MSXHawk/TMS9918A.h b/libHawk/MSXHawk/MSXHawk/TMS9918A.h index c31b76be4a..0a65065d4d 100644 --- a/libHawk/MSXHawk/MSXHawk/TMS9918A.h +++ b/libHawk/MSXHawk/MSXHawk/TMS9918A.h @@ -2,6 +2,7 @@ #include #include #include +#include using namespace std; diff --git a/libHawk/MSXHawk/MSXHawk/Z80A.h b/libHawk/MSXHawk/MSXHawk/Z80A.h index 798c0694e1..9c5bed2ff6 100644 --- a/libHawk/MSXHawk/MSXHawk/Z80A.h +++ b/libHawk/MSXHawk/MSXHawk/Z80A.h @@ -1,7 +1,15 @@ +#ifndef Z80A_H +#define Z80A_H + #include #include #include #include +#include + +#ifndef _WIN32 +#define sprintf_s snprintf +#endif using namespace std; @@ -5585,3 +5593,5 @@ namespace MSXHawk #pragma endregion }; } + +#endif diff --git a/libHawk/MSXHawk/MSXHawk/pch.cpp b/libHawk/MSXHawk/MSXHawk/pch.cpp index 64b7eef6d6..70396b4dfd 100644 --- a/libHawk/MSXHawk/MSXHawk/pch.cpp +++ b/libHawk/MSXHawk/MSXHawk/pch.cpp @@ -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. diff --git a/libHawk/MSXHawk/Makefile b/libHawk/MSXHawk/Makefile new file mode 100644 index 0000000000..4f5d5d1548 --- /dev/null +++ b/libHawk/MSXHawk/Makefile @@ -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) diff --git a/src/BizHawk.Emulation.Cores/Computers/MSX/LibMSX.cs b/src/BizHawk.Emulation.Cores/Computers/MSX/LibMSX.cs index 76aa01f1cf..43681cc205 100644 --- a/src/BizHawk.Emulation.Cores/Computers/MSX/LibMSX.cs +++ b/src/BizHawk.Emulation.Cores/Computers/MSX/LibMSX.cs @@ -1,193 +1,196 @@ -using System; -using System.Runtime.InteropServices; -using System.Text; - -namespace BizHawk.Emulation.Cores.Computers.MSX -{ - /// - /// static bindings into MSXHawk.dll - /// - public static class LibMSX - { - /// opaque state pointer - [DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr MSX_create(); - - /// opaque state pointer - [DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern void MSX_destroy(IntPtr core); - - /// - /// Load BIOS and BASIC image. each must be 16K in size - /// - /// opaque state pointer - /// the rom data, can be disposed of once this function returns - /// length of romdata in bytes - /// 0 on success, negative value on failure. - [DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern int MSX_load_bios(IntPtr core, byte[] bios, byte[] basic); - - /// - /// Load ROM image. - /// - /// opaque state pointer - /// the rom data, can be disposed of once this function returns - /// length of romdata in bytes - /// Mapper number to load core with - /// the rom data, can be disposed of once this function returns - /// length of romdata in bytes - /// Mapper number to load core with - /// 0 on success, negative value on failure. - [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); - - /// - /// Advance a frame and send controller data. - /// - /// opaque state pointer - /// controller data for player 1 - /// controller data for player 2 - /// length of romdata in bytes - /// Mapper number to load core with - /// 0 on success, negative value on failure. - [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); - - /// - /// Get Video data - /// - /// opaque state pointer - /// where to send video to - [DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern void MSX_get_video(IntPtr core, int[] videobuf); - - /// - /// Get Video data - /// - /// opaque state pointer - /// where to send left audio to - /// number of left samples - [DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern uint MSX_get_audio(IntPtr core, int[] aud_buf, ref uint n_samp); - - /// - /// get messages length - /// - /// opaque state pointer - [DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern int MSX_getmessagelength(IntPtr core); - - /// - /// get messages from the core - /// - /// opaque state pointer - /// pointer to const char * - /// length of message to fetch - [DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern void MSX_getmessage(IntPtr core, StringBuilder h, int l); - - /// - /// Save State - /// - /// opaque state pointer - /// save buffer - [DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern void MSX_save_state(IntPtr core, byte[] saver); - - /// - /// Load State - /// - /// opaque state pointer - /// load buffer - [DllImport("MSXHAWK.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern void MSX_load_state(IntPtr core, byte[] loader); - - /// - /// Read the system bus - /// - /// opaque state pointer - /// system bus address - [DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern byte MSX_getsysbus(IntPtr core, int addr); - - /// - /// Read the VRAM - /// - /// opaque state pointer - /// vram address - [DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern byte MSX_getvram(IntPtr core, int addr); - - /// - /// Read the RAM - /// - /// opaque state pointer - /// ram address - [DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern byte MSX_getram(IntPtr core, int addr); - - /// - /// type of the cpu trace callback - /// - /// type of event - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void TraceCallback(int t); - - /// - /// set a callback for trace logging - /// - /// opaque state pointer - /// null to clear - [DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern void MSX_settracecallback(IntPtr core, TraceCallback callback); - - /// - /// get the trace logger header length - /// - /// opaque state pointer - [DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern int MSX_getheaderlength(IntPtr core); - - /// - /// get the trace logger disassembly length, a constant - /// - /// opaque state pointer - [DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern int MSX_getdisasmlength(IntPtr core); - - /// - /// get the trace logger register string length, a constant - /// - /// opaque state pointer - [DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern int MSX_getregstringlength(IntPtr core); - - /// - /// get the trace logger header - /// - /// opaque state pointer - /// pointer to const char * - [DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern void MSX_getheader(IntPtr core, StringBuilder h, int l); - - /// - /// get the register state from the cpu - /// - /// opaque state pointer - /// pointer to const char * - /// call type - /// copy length, must be obtained from appropriate get legnth function - [DllImport("MSXHawk.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern void MSX_getregisterstate(IntPtr core, StringBuilder h, int t, int l); - - /// - /// get the register state from the cpu - /// - /// opaque state pointer - /// pointer to const char * - /// call type - /// copy length, must be obtained from appropriate get legnth function - [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 +{ + /// + /// static bindings into MSXHawk.dll + /// + public static class LibMSX + { + private const string lib = "MSXHawk"; + private const CallingConvention cc = CallingConvention.Cdecl; + + /// opaque state pointer + [DllImport(lib, CallingConvention = cc)] + public static extern IntPtr MSX_create(); + + /// opaque state pointer + [DllImport(lib, CallingConvention = cc)] + public static extern void MSX_destroy(IntPtr core); + + /// + /// Load BIOS and BASIC image. each must be 16K in size + /// + /// opaque state pointer + /// the rom data, can be disposed of once this function returns + /// length of romdata in bytes + /// 0 on success, negative value on failure. + [DllImport(lib, CallingConvention = cc)] + public static extern int MSX_load_bios(IntPtr core, byte[] bios, byte[] basic); + + /// + /// Load ROM image. + /// + /// opaque state pointer + /// the rom data, can be disposed of once this function returns + /// length of romdata in bytes + /// Mapper number to load core with + /// the rom data, can be disposed of once this function returns + /// length of romdata in bytes + /// Mapper number to load core with + /// 0 on success, negative value on failure. + [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); + + /// + /// Advance a frame and send controller data. + /// + /// opaque state pointer + /// controller data for player 1 + /// controller data for player 2 + /// length of romdata in bytes + /// Mapper number to load core with + /// 0 on success, negative value on failure. + [DllImport(lib, CallingConvention = cc)] + public static extern bool MSX_frame_advance(IntPtr core, byte ctrl1, byte ctrl2, byte[] kbrows, bool render, bool sound); + + /// + /// Get Video data + /// + /// opaque state pointer + /// where to send video to + [DllImport(lib, CallingConvention = cc)] + public static extern void MSX_get_video(IntPtr core, int[] videobuf); + + /// + /// Get Video data + /// + /// opaque state pointer + /// where to send left audio to + /// number of left samples + [DllImport(lib, CallingConvention = cc)] + public static extern uint MSX_get_audio(IntPtr core, int[] aud_buf, ref uint n_samp); + + /// + /// get messages length + /// + /// opaque state pointer + [DllImport(lib, CallingConvention = cc)] + public static extern int MSX_getmessagelength(IntPtr core); + + /// + /// get messages from the core + /// + /// opaque state pointer + /// pointer to const char * + /// length of message to fetch + [DllImport(lib, CallingConvention = cc)] + public static extern void MSX_getmessage(IntPtr core, StringBuilder h, int l); + + /// + /// Save State + /// + /// opaque state pointer + /// save buffer + [DllImport(lib, CallingConvention = cc)] + public static extern void MSX_save_state(IntPtr core, byte[] saver); + + /// + /// Load State + /// + /// opaque state pointer + /// load buffer + [DllImport(lib, CallingConvention = cc)] + public static extern void MSX_load_state(IntPtr core, byte[] loader); + + /// + /// Read the system bus + /// + /// opaque state pointer + /// system bus address + [DllImport(lib, CallingConvention = cc)] + public static extern byte MSX_getsysbus(IntPtr core, int addr); + + /// + /// Read the VRAM + /// + /// opaque state pointer + /// vram address + [DllImport(lib, CallingConvention = cc)] + public static extern byte MSX_getvram(IntPtr core, int addr); + + /// + /// Read the RAM + /// + /// opaque state pointer + /// ram address + [DllImport(lib, CallingConvention = cc)] + public static extern byte MSX_getram(IntPtr core, int addr); + + /// + /// type of the cpu trace callback + /// + /// type of event + [UnmanagedFunctionPointer(cc)] + public delegate void TraceCallback(int t); + + /// + /// set a callback for trace logging + /// + /// opaque state pointer + /// null to clear + [DllImport(lib, CallingConvention = cc)] + public static extern void MSX_settracecallback(IntPtr core, TraceCallback callback); + + /// + /// get the trace logger header length + /// + /// opaque state pointer + [DllImport(lib, CallingConvention = cc)] + public static extern int MSX_getheaderlength(IntPtr core); + + /// + /// get the trace logger disassembly length, a constant + /// + /// opaque state pointer + [DllImport(lib, CallingConvention = cc)] + public static extern int MSX_getdisasmlength(IntPtr core); + + /// + /// get the trace logger register string length, a constant + /// + /// opaque state pointer + [DllImport(lib, CallingConvention = cc)] + public static extern int MSX_getregstringlength(IntPtr core); + + /// + /// get the trace logger header + /// + /// opaque state pointer + /// pointer to const char * + [DllImport(lib, CallingConvention = cc)] + public static extern void MSX_getheader(IntPtr core, StringBuilder h, int l); + + /// + /// get the register state from the cpu + /// + /// opaque state pointer + /// pointer to const char * + /// call type + /// copy length, must be obtained from appropriate get legnth function + [DllImport(lib, CallingConvention = cc)] + public static extern void MSX_getregisterstate(IntPtr core, StringBuilder h, int t, int l); + + /// + /// get the register state from the cpu + /// + /// opaque state pointer + /// pointer to const char * + /// call type + /// copy length, must be obtained from appropriate get legnth function + [DllImport(lib, CallingConvention = cc)] + public static extern void MSX_getdisassembly(IntPtr core, StringBuilder h, int t, int l); + } +}