Add a way to pretend displaying while actualy not displayint

to go around some weirdness with Valgrind that crashwhen using OpenGL.
This commit is contained in:
Godzil 2021-04-06 23:11:30 +01:00
parent da26704390
commit ac3779e640
2 changed files with 79 additions and 13 deletions

View File

@ -1,10 +1,16 @@
set(SOURCES audio.c emulate.c gpu.c io.c log.c memory.c rom.c ws.c)
set(HEADERS audio.h emulate.h gpu.h io.h log.h memory.h rom.h ws.h)
option(FAKE_DISPLAY "Disable OpenGL and fake displaying" OFF)
add_library(wswan ${SOURCES} ${HEADERS})
if (FAKE_DISPLAY)
target_compile_options(wswan PRIVATE -DPRETENT_DISPLAY)
endif()
target_link_libraries(wswan nec_v30 glfw ${OPENGL_glu_LIBRARY} ${OPENGL_gl_LIBRARY})
target_include_directories(wswan PUBLIC .)
target_include_directories(wswan PUBLIC . nec/)
add_subdirectory(nec)

View File

@ -26,6 +26,7 @@
#include <sys/mman.h>
#include <sys/time.h>
#ifndef PRETENT_DISPLAY
#define GLFW_INCLUDE_GLEXT
#define GL_SILENCE_DEPRECATION
@ -34,6 +35,7 @@
#ifndef GL_TEXTURE_RECTANGLE
#define GL_TEXTURE_RECTANGLE GL_TEXTURE_RECTANGLE_EXT
#endif
#endif /* PRETENT_DISPLAY */
#include "log.h"
#include "io.h"
@ -50,6 +52,7 @@ int app_terminate = 0;
int ws_key_esc = 0;
#ifndef PRETENT_DISPLAY
/* Open GL stuffs */
typedef struct GLWindow_t GLWindow;
struct KeyArray
@ -236,18 +239,6 @@ static void updateScreen(GLWindow *g)
glfwPollEvents();
}
uint64_t getTicks()
{
struct timeval curTime;
uint64_t ticks;
/* Get datetime */
gettimeofday(&curTime, NULL);
ticks = (curTime.tv_sec * 1000) + curTime.tv_usec / 1000;
return ticks;
}
static inline int getKeyState(int key)
{
return mainWindow.keyArray[key].curState;
@ -348,6 +339,75 @@ static void read_keys()
ws_cyclesByLine -= 10;
}
}
#else
typedef struct PseudoWindow_t
{
uint8_t *videoMemory;
int WIDTH;
int HEIGHT;
} PseudoWindow_t;
static PseudoWindow_t mainWindow;
static void GLWindowInitEx(PseudoWindow_t *g, int w, int h)
{
g->WIDTH = w;
g->HEIGHT = h;
}
static void initDisplay(PseudoWindow_t *g)
{
int w = g->WIDTH;
int h = g->HEIGHT;
g->videoMemory = (uint8_t *)malloc(w * h * sizeof(uint16_t));
memset(g->videoMemory, 0, w * h * sizeof(uint16_t));
}
static void clearScreen(PseudoWindow_t *g)
{
memset(g->videoMemory, 0, sizeof(uint16_t) * g->WIDTH * g->HEIGHT);
}
static void updateScreen(PseudoWindow_t *g)
{
}
static void read_keys()
{
static uint32_t i = 0;
ws_key_start = 0;
ws_key_x4 = 0;
ws_key_x2 = 0;
ws_key_x1 = 0;
ws_key_x3 = 0;
ws_key_y4 = 0;
ws_key_y2 = 0;
ws_key_y1 = 0;
ws_key_y3 = 0;
ws_key_button_a = 0;
ws_key_button_b = 0;
if (i > 1024)
{
ws_key_esc = 1;
}
i++;
}
#endif /* PRETENT_DISPLAY */
uint64_t getTicks()
{
struct timeval curTime;
uint64_t ticks;
/* Get datetime */
gettimeofday(&curTime, NULL);
ticks = (curTime.tv_sec * 1000) + curTime.tv_usec / 1000;
return ticks;
}
////////////////////////////////////////////////////////////////////////////////
//