[skip ci] Moved Experimental Code into plugins.

This commit is contained in:
Michael J. Manley
2022-01-27 14:31:05 -08:00
parent 8ef51f6af1
commit 061582ab35
18 changed files with 152 additions and 141 deletions

View File

@@ -103,11 +103,9 @@ if(USE_PCAP_NETWORKING)
include_directories(${PCAP_INCLUDE_DIR}) include_directories(${PCAP_INCLUDE_DIR})
endif() endif()
if(USE_EXPERIMENTAL_PRINTER)
find_package(Freetype REQUIRED)
include_directories(${FREETYPE_INCLUDE_DIRS})
endif()
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
if(USE_EXPERIMENTAL)
add_subdirectory(experimental)
endif()
add_subdirectory(src) add_subdirectory(src)

View File

@@ -0,0 +1,3 @@
if(USE_EXPERIMENTAL_PRINTER)
add_subdirectory(printer_epsonlx810)
endif()

View File

@@ -0,0 +1,16 @@
find_package(Freetype REQUIRED)
include_directories(${FREETYPE_INCLUDE_DIRS})
set(EPSON_LX810_HEADER
${CMAKE_SOURCE_DIR}/includes/private/lpt/lpt_epsonlx810.h
)
set(EPSON_LX810_SRC
wx-imagesave.cc
lpt_epsonlx810.c
plugin.c
)
add_library(printer_epsonlx810 SHARED ${EPSON_LX810_SRC} ${EPSON_LX810_HEADER})
target_link_libraries(printer_epsonlx810 Freetype::Freetype)
set_target_properties(printer_epsonlx810 PROPERTIES SUFFIX ".pcem")

View File

@@ -81,8 +81,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "SDL.h"
#include <ft2build.h> #include <ft2build.h>
#include FT_FREETYPE_H #include FT_FREETYPE_H
@@ -92,16 +90,14 @@
#endif #endif
#include <math.h> #include <math.h>
#include "config.h"
#include "ibm.h"
#include "lpt.h"
#include "lpt_epsonlx810.h" #include "lpt_epsonlx810.h"
#include "paths.h" //#include "paths.h"
#include "wx-utils.h"
#include <pcem/devices.h> #include <pcem/devices.h>
#include <pcem/unsafe/devices.h> #include <pcem/unsafe/devices.h>
#include <pcem/unsafe/config.h>
#include <pcem/logging.h>
#include <SDL.h>
#define STYLE_CONDENSED 0x02 #define STYLE_CONDENSED 0x02
#define STYLE_BOLD 0x04 #define STYLE_BOLD 0x04
@@ -2252,6 +2248,7 @@ static void *epsonprinter_init()
} }
int emulatepins = device_get_config_int("bitmaps_emulate_pins"); int emulatepins = device_get_config_int("bitmaps_emulate_pins");
char s[512];
strlcpy(lpt_epsonprinter->fontpath, printer_path, MAX_PATH_STRING - 2); strlcpy(lpt_epsonprinter->fontpath, printer_path, MAX_PATH_STRING - 2);
put_backslash(lpt_epsonprinter->fontpath); put_backslash(lpt_epsonprinter->fontpath);

View File

@@ -0,0 +1,42 @@
#include <pcem/plugin.h>
#include <pcem/unsafe/config.h>
#include <string.h>
#include "lpt_epsonlx810.h"
char pcem_path[512];
char base_path[512];
LPT_DEVICE l_epsonlx810 = { "Epson LX-810 Printer", "lpt_epsonlx810", &lpt_epsonprinter_device };
#define safe_strncpy(a,b,n) do { strncpy((a),(b),(n)-1); (a)[(n)-1] = 0; } while (0)
char printer_path[512];
void set_printer_path(char *s)
{
safe_strncpy(printer_path, s, 512);
append_slash(printer_path, 512);
}
PLUGIN_INIT(printer_epsonlx810)
{
char *cfg_printer_path = config_get_string(CFG_GLOBAL, "Paths", "printer_path", 0);
if(cfg_printer_path)
{
safe_strncpy(printer_path, cfg_printer_path, 512);
}
else
{
char s[512];
#ifdef linux
append_filename(s, pcem_path, "printer/", 512);
#else
append_filename(s, base_path, "printer/", 512);
#endif
set_printer_path(s);
config_set_string(CFG_GLOBAL, "Paths", "printer_path", printer_path);
}
pcem_add_lpt(&l_epsonlx810);
}

View File

@@ -0,0 +1,55 @@
#include "lpt_epsonlx810.h"
#include <wx/xrc/xmlres.h>
#include <wx/wfstream.h>
#include <wx/log.h>
int wx_image_save_fullpath(const char* fullpath, const char* format, unsigned char* rgba, int width, int height, int alpha)
{
int x, y;
wxLogNull logNull;
wxImage image(width, height);
if (alpha)
{
// these will be automatically freed
unsigned char* rgb = (unsigned char*)malloc(width*height*3);
unsigned char* a = (unsigned char*)malloc(width*height);
for (x = 0; x < width; ++x)
{
for (y = 0; y < height; ++y)
{
rgb[(y*width+x)*3+0] = rgba[(y*width+x)*4+0];
rgb[(y*width+x)*3+1] = rgba[(y*width+x)*4+1];
rgb[(y*width+x)*3+2] = rgba[(y*width+x)*4+2];
a[y*width+x] = rgba[(y*width+x)*4+3];
}
}
image.SetData(rgb);
image.SetAlpha(a);
}
else
image.SetData(rgba, true);
wxImageHandler* h;
if (!strcmp(format, IMAGE_TIFF))
h = new wxTIFFHandler();
else if (!strcmp(format, IMAGE_BMP))
h = new wxBMPHandler();
else if (!strcmp(format, IMAGE_JPG))
h = new wxJPEGHandler();
else
h = new wxPNGHandler();
int res = 0;
if (h)
{
wxString p(fullpath);
wxFileOutputStream stream(p);
res = h->SaveFile(&image, stream, false);
delete h;
}
return res;
}

View File

@@ -1,5 +1,22 @@
#ifndef __LPT_EPSONLX810_H__ #ifndef __LPT_EPSONLX810_H__
#define __LPT_EPSONLX810_H__ #define __LPT_EPSONLX810_H__
#include <pcem/devices.h>
extern lpt_device_t lpt_epsonprinter_device; extern lpt_device_t lpt_epsonprinter_device;
extern char printer_path[512];
#ifdef __cplusplus
extern "C" {
#endif
int wx_image_save_fullpath(const char* fullpath, const char* format, unsigned char* rgba, int width, int height, int alpha);
#ifdef __cplusplus
}
#endif
#define IMAGE_JPG "jpg"
#define IMAGE_PNG "png"
#define IMAGE_BMP "bmp"
#define IMAGE_TIFF "tiff"
#endif /* __LPT_EPSONLX810_H__ */ #endif /* __LPT_EPSONLX810_H__ */

View File

@@ -9,10 +9,6 @@ extern char screenshots_path[512];
extern char nvr_default_path[512]; extern char nvr_default_path[512];
extern char plugins_default_path[512]; extern char plugins_default_path[512];
extern char base_path[512]; extern char base_path[512];
#ifdef USE_EXPERIMENTAL_PRINTER
extern char default_printer_path[512];
extern char printer_path[512];
#endif
void get_pcem_path(char *s, int size); void get_pcem_path(char *s, int size);
void get_pcem_base_path(char *s, int size); void get_pcem_base_path(char *s, int size);
@@ -29,9 +25,6 @@ void set_default_logs_path(char *s);
void set_default_configs_path(char *s); void set_default_configs_path(char *s);
void set_default_screenshots_path(char *s); void set_default_screenshots_path(char *s);
void set_default_nvr_default_path(char *s); void set_default_nvr_default_path(char *s);
#ifdef USE_EXPERIMENTAL_PRINTER
void set_default_printer_path(char *s);
#endif
/* set the paths temporarily for this session */ /* set the paths temporarily for this session */
void set_roms_paths(char* path); void set_roms_paths(char* path);
@@ -40,8 +33,5 @@ void set_logs_path(char *s);
void set_configs_path(char *s); void set_configs_path(char *s);
void set_screenshots_path(char *s); void set_screenshots_path(char *s);
void set_plugins_path(char *s); void set_plugins_path(char *s);
#ifdef USE_EXPERIMENTAL_PRINTER
void set_printer_path(char *s);
#endif
#endif /* _PATHS_H_ */ #endif /* _PATHS_H_ */

View File

@@ -100,7 +100,6 @@ extern "C" {
int wx_config_get_bool(void* config, const char* name, int* dst, int defVal); int wx_config_get_bool(void* config, const char* name, int* dst, int defVal);
int wx_config_has_entry(void* config, const char* name); int wx_config_has_entry(void* config, const char* name);
void wx_config_free(void* config); void wx_config_free(void* config);
int wx_image_save_fullpath(const char* fullpath, const char* format, unsigned char* rgba, int width, int height, int alpha);
int confirm(); int confirm();

View File

@@ -1,6 +1,8 @@
#ifndef _PCEM_CPU_H_ #ifndef _PCEM_CPU_H_
#define _PCEM_CPU_H_ #define _PCEM_CPU_H_
#include <stdint.h>
typedef struct FPU typedef struct FPU
{ {
const char *name; const char *name;

View File

@@ -11,7 +11,6 @@ set(PCEM_PRIVATE_API ${PCEM_PRIVATE_API}
set(PCEM_SRC ${PCEM_SRC} set(PCEM_SRC ${PCEM_SRC}
devices/cassette.c devices/cassette.c
devices/device.c
devices/esdi_at.c devices/esdi_at.c
devices/f82c710_upc.c devices/f82c710_upc.c
devices/nvr.c devices/nvr.c

View File

@@ -23,10 +23,6 @@ LPT_DEVICE l_dss = { "Disney Sound Source", "dss", &dss_device };
LPT_DEVICE l_lpt_dac = { "LPT DAC / Covox Speech Thing", "lpt_dac", &lpt_dac_device }; LPT_DEVICE l_lpt_dac = { "LPT DAC / Covox Speech Thing", "lpt_dac", &lpt_dac_device };
LPT_DEVICE l_lpt_dac_stereo = { "Stereo LPT DAC", "lpt_dac_stereo", &lpt_dac_stereo_device }; LPT_DEVICE l_lpt_dac_stereo = { "Stereo LPT DAC", "lpt_dac_stereo", &lpt_dac_stereo_device };
#ifdef USE_EXPERIMENTAL_PRINTER
LPT_DEVICE l_epsonlx810 = { "Epson LX-810 Printer", "lpt_epsonlx810", &lpt_epsonprinter_device };
#endif
char* lpt_device_get_name(int id) char* lpt_device_get_name(int id)
{ {
if (lpt_devices[id] == NULL || strlen(lpt_devices[id]->name) == 0) if (lpt_devices[id] == NULL || strlen(lpt_devices[id]->name) == 0)
@@ -199,7 +195,4 @@ void lpt_init_builtin()
pcem_add_lpt(&l_dss); pcem_add_lpt(&l_dss);
pcem_add_lpt(&l_lpt_dac); pcem_add_lpt(&l_lpt_dac);
pcem_add_lpt(&l_lpt_dac_stereo); pcem_add_lpt(&l_lpt_dac_stereo);
#ifdef USE_EXPERIMENTAL_PRINTER
pcem_add_lpt(&l_epsonlx810);
#endif
} }

View File

@@ -1,7 +1,6 @@
set(PCEM_PRIVATE_API ${PCEM_PRIVATE_API} set(PCEM_PRIVATE_API ${PCEM_PRIVATE_API}
${CMAKE_SOURCE_DIR}/includes/private/lpt/lpt_dac.h ${CMAKE_SOURCE_DIR}/includes/private/lpt/lpt_dac.h
${CMAKE_SOURCE_DIR}/includes/private/lpt/lpt_dss.h ${CMAKE_SOURCE_DIR}/includes/private/lpt/lpt_dss.h
${CMAKE_SOURCE_DIR}/includes/private/lpt/lpt_epsonlx810.h
${CMAKE_SOURCE_DIR}/includes/private/lpt/lpt.h ${CMAKE_SOURCE_DIR}/includes/private/lpt/lpt.h
) )
@@ -10,11 +9,3 @@ set(PCEM_SRC ${PCEM_SRC}
lpt/lpt_dac.c lpt/lpt_dac.c
lpt/lpt_dss.c lpt/lpt_dss.c
) )
if(USE_EXPERIMENTAL AND USE_EXPERIMENTAL_PRINTER)
set(PCEM_DEFINES ${PCEM_DEFINES} USE_EXPERIMENTAL_PRINTER)
set(PCEM_SRC ${PCEM_SRC}
lpt/lpt_epsonlx810.c
)
set(PCEM_ADDITIONAL_LIBS ${PCEM_ADDITIONAL_LIBS} Freetype::Freetype)
endif()

View File

@@ -1,17 +1,17 @@
#include "ibm.h"
#include "config.h"
#include "cpu.h"
#include "device.h"
#include "model.h"
#include "sound.h"
#include <pcem/defines.h> #include <pcem/defines.h>
#include <pcem/devices.h>
#include <string.h>
#include <pcem/unsafe/config.h>
extern void *device_priv[256]; extern void *device_priv[256];
extern device_t *devices[DEV_MAX]; extern device_t *devices[DEV_MAX];
extern device_t *current_device; extern device_t *current_device;
extern char *current_device_name; extern char *current_device_name;
extern struct device_t *model_getdevice(int model);
extern int model;
extern void sound_speed_changed();
void device_init() void device_init()
{ {
memset(devices, 0, sizeof(devices)); memset(devices, 0, sizeof(devices));

View File

@@ -12,9 +12,6 @@ char default_nvr_path[512];
char default_configs_path[512]; char default_configs_path[512];
char default_logs_path[512]; char default_logs_path[512];
char default_screenshots_path[512]; char default_screenshots_path[512];
#ifdef USE_EXPERIMENTAL_PRINTER
char default_printer_path[512];
#endif
/* the number of roms paths */ /* the number of roms paths */
int num_roms_paths; int num_roms_paths;
@@ -27,10 +24,6 @@ char nvr_path[512];
char configs_path[512]; char configs_path[512];
/* this is where log-files as stored */ /* this is where log-files as stored */
char logs_path[512]; char logs_path[512];
#ifdef USE_EXPERIMENTAL_PRINTER
/* this is where printer data is stored */
char printer_path[512];
#endif
/* this is where screenshots as stored */ /* this is where screenshots as stored */
char screenshots_path[512]; char screenshots_path[512];
/* this is where plugins are stored */ /* this is where plugins are stored */
@@ -185,9 +178,6 @@ void paths_loadconfig()
char *cfg_nvr_path = config_get_string(CFG_GLOBAL, "Paths", "nvr_path", 0); char *cfg_nvr_path = config_get_string(CFG_GLOBAL, "Paths", "nvr_path", 0);
char *cfg_configs_path = config_get_string(CFG_GLOBAL, "Paths", "configs_path", 0); char *cfg_configs_path = config_get_string(CFG_GLOBAL, "Paths", "configs_path", 0);
char *cfg_logs_path = config_get_string(CFG_GLOBAL, "Paths", "logs_path", 0); char *cfg_logs_path = config_get_string(CFG_GLOBAL, "Paths", "logs_path", 0);
#ifdef USE_EXPERIMENTAL_PRINTER
char *cfg_printer_path = config_get_string(CFG_GLOBAL, "Paths", "printer_path", 0);
#endif
char *cfg_screenshots_path = config_get_string(CFG_GLOBAL, "Paths", "screenshots_path", 0); char *cfg_screenshots_path = config_get_string(CFG_GLOBAL, "Paths", "screenshots_path", 0);
if (cfg_roms_paths) if (cfg_roms_paths)
@@ -198,10 +188,6 @@ void paths_loadconfig()
safe_strncpy(default_configs_path, cfg_configs_path, 512); safe_strncpy(default_configs_path, cfg_configs_path, 512);
if (cfg_logs_path) if (cfg_logs_path)
safe_strncpy(default_logs_path, cfg_logs_path, 512); safe_strncpy(default_logs_path, cfg_logs_path, 512);
#ifdef USE_EXPERIMENTAL_PRINTER
if (cfg_printer_path)
safe_strncpy(default_printer_path, cfg_printer_path, 512);
#endif
if (cfg_screenshots_path) if (cfg_screenshots_path)
safe_strncpy(default_screenshots_path, cfg_screenshots_path, 512); safe_strncpy(default_screenshots_path, cfg_screenshots_path, 512);
} }
@@ -212,9 +198,6 @@ void paths_saveconfig()
config_set_string(CFG_GLOBAL, "Paths", "nvr_path", default_nvr_path); config_set_string(CFG_GLOBAL, "Paths", "nvr_path", default_nvr_path);
config_set_string(CFG_GLOBAL, "Paths", "configs_path", default_configs_path); config_set_string(CFG_GLOBAL, "Paths", "configs_path", default_configs_path);
config_set_string(CFG_GLOBAL, "Paths", "logs_path", default_logs_path); config_set_string(CFG_GLOBAL, "Paths", "logs_path", default_logs_path);
#ifdef USE_EXPERIMENTAL_PRINTER
config_set_string(CFG_GLOBAL, "Paths", "printer_path", default_printer_path);
#endif
config_set_string(CFG_GLOBAL, "Paths", "screenshots_path", default_screenshots_path); config_set_string(CFG_GLOBAL, "Paths", "screenshots_path", default_screenshots_path);
} }
@@ -232,11 +215,6 @@ void paths_onconfigloaded()
if (strlen(default_logs_path) > 0) if (strlen(default_logs_path) > 0)
set_logs_path(default_logs_path); set_logs_path(default_logs_path);
#ifdef USE_EXPERIMENTAL_PRINTER
if (strlen(default_printer_path) > 0)
set_printer_path(default_printer_path);
#endif
if (strlen(default_screenshots_path) > 0) if (strlen(default_screenshots_path) > 0)
set_screenshots_path(default_screenshots_path); set_screenshots_path(default_screenshots_path);
@@ -268,10 +246,7 @@ void paths_init()
set_screenshots_path(s); set_screenshots_path(s);
append_filename(s, base_path, "logs/", 512); append_filename(s, base_path, "logs/", 512);
set_logs_path(s); set_logs_path(s);
#ifdef USE_EXPERIMENTAL_PRINTER
append_filename(s, base_path, "printer/", 512);
set_printer_path(s);
#endif
append_filename(s, base_path, "nvr/default/", 512); append_filename(s, base_path, "nvr/default/", 512);
set_default_nvr_default_path(s); set_default_nvr_default_path(s);
append_filename(s, base_path, "plugins/", 512); append_filename(s, base_path, "plugins/", 512);
@@ -312,16 +287,3 @@ void get_pcem_path(char* s, int size)
#endif #endif
} }
#ifdef USE_EXPERIMENTAL_PRINTER
void set_printer_path(char *s)
{
safe_strncpy(printer_path, s, 512);
append_slash(printer_path, 512);
}
void set_default_printer_path(char *s)
{
safe_strncpy(default_printer_path, s, 512);
set_printer_path(s);
}
#endif

View File

@@ -20,6 +20,7 @@ set(PCEM_SRC_PLUGINAPI
plugin-api/config.c plugin-api/config.c
plugin-api/paths.c plugin-api/paths.c
plugin-api/logging.c plugin-api/logging.c
plugin-api/device.c
plugin-api/devices.c plugin-api/devices.c
plugin-api/plugin.c plugin-api/plugin.c
) )

View File

@@ -517,10 +517,6 @@ int pc_main(int argc, char** argv)
set_default_screenshots_path(s); set_default_screenshots_path(s);
append_filename(s, pcem_path, "logs/", 511); append_filename(s, pcem_path, "logs/", 511);
set_default_logs_path(s); set_default_logs_path(s);
#ifdef USE_EXPERIMENTAL_PRINTER
append_filename(s, pcem_path, "printer/", 511);
set_default_printer_path(s);
#endif
append_filename(s, pcem_path, "plugins/", 512); append_filename(s, pcem_path, "plugins/", 512);
set_plugins_path(s); set_plugins_path(s);
#endif #endif

View File

@@ -832,53 +832,3 @@ void wx_date_format(char* s, const char* format)
wxString res = wxDateTime::Now().Format(format); wxString res = wxDateTime::Now().Format(format);
strcpy(s, res.mb_str()); strcpy(s, res.mb_str());
} }
int wx_image_save_fullpath(const char* fullpath, const char* format, unsigned char* rgba, int width, int height, int alpha)
{
int x, y;
wxLogNull logNull;
wxImage image(width, height);
if (alpha)
{
// these will be automatically freed
unsigned char* rgb = (unsigned char*)malloc(width*height*3);
unsigned char* a = (unsigned char*)malloc(width*height);
for (x = 0; x < width; ++x)
{
for (y = 0; y < height; ++y)
{
rgb[(y*width+x)*3+0] = rgba[(y*width+x)*4+0];
rgb[(y*width+x)*3+1] = rgba[(y*width+x)*4+1];
rgb[(y*width+x)*3+2] = rgba[(y*width+x)*4+2];
a[y*width+x] = rgba[(y*width+x)*4+3];
}
}
image.SetData(rgb);
image.SetAlpha(a);
}
else
image.SetData(rgba, true);
wxImageHandler* h;
if (!strcmp(format, IMAGE_TIFF))
h = new wxTIFFHandler();
else if (!strcmp(format, IMAGE_BMP))
h = new wxBMPHandler();
else if (!strcmp(format, IMAGE_JPG))
h = new wxJPEGHandler();
else
h = new wxPNGHandler();
int res = 0;
if (h)
{
wxString p(fullpath);
wxFileOutputStream stream(p);
res = h->SaveFile(&image, stream, false);
delete h;
}
return res;
}