Merge pull request #14 from MaddTheSane/MacSupp

Mac support changes
This commit is contained in:
sarah-walker-pcem 2021-05-25 20:37:56 +01:00 committed by GitHub
commit 5da96ac8d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 4658 additions and 1975 deletions

View file

@ -1,6 +1,9 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#if defined(__APPLE__) && defined(__aarch64__)
#include <pthread.h>
#endif
#include "ibm.h"
#include "x86.h"
#include "x86_ops.h"
@ -410,6 +413,9 @@ static inline void exec_recompiler(void)
cpu_new_blocks++;
#if defined(__APPLE__) && defined(__aarch64__)
pthread_jit_write_protect_np(0);
#endif
codegen_block_start_recompile(block);
codegen_in_recompile = 1;
@ -481,6 +487,9 @@ static inline void exec_recompiler(void)
codegen_reset();
codegen_in_recompile = 0;
#if defined(__APPLE__) && defined(__aarch64__)
pthread_jit_write_protect_np(1);
#endif
}
else if (!cpu_state.abrt)
{

View file

@ -137,7 +137,7 @@ pcem_LDADD += wx.res
endif
if !HAS_OFF64T
#pcem_CFLAGS += -Doff64_t=off_t -Dfopen64=fopen -Dfseeko64=fseek -Dftello64=ftell
pcem_CFLAGS += -Doff64_t=off_t -Dfopen64=fopen -Dfseeko64=fseeko -Dftello64=ftello
endif
if RELEASE_BUILD

File diff suppressed because it is too large Load diff

View file

@ -30,6 +30,10 @@ void codegen_allocator_init()
#if defined WIN32 || defined _WIN32 || defined _WIN32
mem_block_alloc = VirtualAlloc(NULL, MEM_BLOCK_NR * MEM_BLOCK_SIZE, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
/* TODO: check deployment target: older Intel-based versions of macOS don't play
nice with MAP_JIT. */
#elif defined(__APPLE__) && defined(MAP_JIT)
mem_block_alloc = mmap(0, MEM_BLOCK_NR * MEM_BLOCK_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE|MAP_JIT, 0, 0);
#else
mem_block_alloc = mmap(0, MEM_BLOCK_NR * MEM_BLOCK_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, 0, 0);
#endif

View file

@ -1,6 +1,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#ifdef __APPLE__
#include <string.h>
#include <dispatch/dispatch.h>
#ifdef __aarch64__
#include <pthread.h>
#endif
#endif
#include "ibm.h"
#include "device.h"
@ -307,7 +314,13 @@ void initpc(int argc, char *argv[])
loadbios();
mem_add_bios();
#if defined(__APPLE__) && defined(__aarch64__)
pthread_jit_write_protect_np(0);
#endif
codegen_init();
#if defined(__APPLE__) && defined(__aarch64__)
pthread_jit_write_protect_np(1);
#endif
timer_reset();
sound_reset();
@ -510,6 +523,14 @@ int serial_fifo_read, serial_fifo_write;
int emu_fps = 0;
#ifdef __APPLE__
static void _set_window_title(void *s)
{
set_window_title((const char *)s);
free(s);
}
#endif
void runpc()
{
char s[200];
@ -585,7 +606,12 @@ void runpc()
{
win_title_update=0;
sprintf(s, "PCem v17 - %i%% - %s - %s - %s", fps, model_getname(), models[model].cpu[cpu_manufacturer].cpus[cpu].name, (!mousecapture) ? "Click to capture mouse" : ((mouse_get_type(mouse_type) & MOUSE_TYPE_3BUTTON) ? "Press CTRL-END to release mouse" : "Press CTRL-END or middle button to release mouse"));
#ifdef __APPLE__
// Needed due to modifying the UI on the non-main thread is a big no-no.
dispatch_async_f(dispatch_get_main_queue(), strdup(s), _set_window_title);
#else
set_window_title(s);
#endif
}
done++;
}

View file

@ -80,6 +80,10 @@ typedef char *SLIRPcaddr_t;
# include <stdint.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifndef _MSC_VER
#include <sys/time.h>
#else

View file

@ -769,6 +769,12 @@ int gl3_init(SDL_Window* window, sdl_render_driver requested_render_driver, SDL_
strcpy(current_render_driver_name, requested_render_driver.name);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
#ifdef __APPLE__
// without an explicit request for the core profile 3.0 macOS falls back to default ancient 2.1
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
#endif
context = SDL_GL_CreateContext(window);
@ -1637,12 +1643,21 @@ int gl3_renderer_available(struct sdl_render_driver* driver)
if (available < 0)
{
available = 0;
// GL SetAttribute should be done *before* window creation for the attributes to apply on
// context creation (seems to depend on OpenGL impl. but it souldn't hurt other platforms
// to do it here (earlier than before)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#ifdef __APPLE__
// without an explicit request for the core profile 3.0 macOS falls back to default ancient 2.1
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
#endif
SDL_Window* window = SDL_CreateWindow("GL3 test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1, 1, SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL);
if (window)
{
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GLContext context = SDL_GL_CreateContext(window);
if (context)
{

View file

@ -50,6 +50,8 @@
#include <fcntl.h>
#include <unistd.h>
#undef pause
#include <sys/types.h>
#include <sys/stat.h>
#endif
extern void creatediscimage_open(void *hwnd);
@ -241,6 +243,20 @@ void get_pcem_path(char *s, int size)
#ifdef __linux
wx_get_home_directory(s);
strcat(s, ".pcem/");
#elif defined(__APPLE__)
/*TODO: Use CoreFoundation functions to get proper directory, in case
the Application Support directory is different (I.E., with signing)*/
wx_get_home_directory(s);
strcat(s, "Library/Application Support/PCem/");
struct stat st = {0};
// create ~/Library/Application Support/PCem/
// if it doesn't exist
if (stat(s, &st) == -1)
{
mkdir(s, 0700);
}
#else
char* path = SDL_GetBasePath();
strcpy(s, path);

View file

@ -1,6 +1,9 @@
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#ifdef __APPLE__
#include <sys/time.h>
#endif
#include "thread.h"
#if defined WIN32 || defined _WIN32 || defined _WIN32
#include <windows.h>