From 52f0f50dee1c9c246560e35ad77278bc01d7cdd3 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 3 Dec 2022 15:47:51 +0200 Subject: [PATCH] rpprinter --- od-win32/cloanto/RetroPlatformIPC.h | 41 +++++++++++++-------- od-win32/parser.cpp | 55 ++++++++++++++++++++++------- od-win32/rp.cpp | 32 +++++++++++++++++ od-win32/rp.h | 4 +++ od-win32/win32.cpp | 5 +++ 5 files changed, 111 insertions(+), 26 deletions(-) diff --git a/od-win32/cloanto/RetroPlatformIPC.h b/od-win32/cloanto/RetroPlatformIPC.h index 5bd76a2e..a4cbb70d 100644 --- a/od-win32/cloanto/RetroPlatformIPC.h +++ b/od-win32/cloanto/RetroPlatformIPC.h @@ -2,14 +2,14 @@ Name : RetroPlatformIPC.h Project : RetroPlatform Player Support : http://www.retroplatform.com - Legal : Copyright 2007-2021 Cloanto Corporation - All rights reserved. This + Legal : Copyright 2007-2022 Cloanto Corporation - All rights reserved. This : file is multi-licensed under the terms of the Mozilla Public License : version 2.0 as published by Mozilla Corporation and the GNU General : Public License, version 2 or later, as published by the Free : Software Foundation. Authors : os, m Created : 2007-08-27 13:55:49 - Updated : 2021-10-17 10:43:32 + Updated : 2022-12-03 11:27:12 Comment : RetroPlatform Player interprocess communication include file *****************************************************************************/ @@ -18,9 +18,9 @@ #include -#define RETROPLATFORM_API_VER "10.0" +#define RETROPLATFORM_API_VER "10.1" #define RETROPLATFORM_API_VER_MAJOR 10 -#define RETROPLATFORM_API_VER_MINOR 0 +#define RETROPLATFORM_API_VER_MINOR 1 #define RPIPC_HostWndClass "RetroPlatformHost%s" #define RPIPC_GuestWndClass "RetroPlatformGuest%d" @@ -72,6 +72,12 @@ #define RP_IPC_TO_HOST_TEXT_CURSOR_INFO (WM_APP + 42) // introduced in RetroPlatform API 7.9 #define RP_IPC_TO_HOST_SET_MOUSE_CURSOR (WM_APP + 43) // introduced in RetroPlatform API 7.10 #define RP_IPC_TO_HOST_EXECUTE_RESULT (WM_APP + 44) // introduced in RetroPlatform API 10.0 +#define RP_IPC_TO_HOST_DEVICEOPEN (WM_APP + 45) // introduced in RetroPlatform API 10.0 +#define RP_IPC_TO_HOST_DEVICECLOSE (WM_APP + 46) // introduced in RetroPlatform API 10.0 +#define RP_IPC_TO_HOST_DEVICEREADBYTE (WM_APP + 47) // introduced in RetroPlatform API 10.0 +#define RP_IPC_TO_HOST_DEVICEWRITEBYTE (WM_APP + 48) // introduced in RetroPlatform API 10.0 +#define RP_IPC_TO_HOST_PRIVATE_CANTYPECLIPB (WM_APP + 49) // introduced in RetroPlatform API 10.0 +#define RP_IPC_TO_HOST_DEVICEWRITEBYTES (WM_APP + 50) // introduced in RetroPlatform API 10.1 // **************************************************************************** // Host-to-Guest Messages @@ -322,16 +328,18 @@ typedef struct RPDeviceContent // Device Categories -#define RP_DEVICECATEGORY_FLOPPY 0 // floppy disk drive -#define RP_DEVICECATEGORY_HD 1 // hard disk drive -#define RP_DEVICECATEGORY_CD 2 // CD/DVD drive -#define RP_DEVICECATEGORY_NET 3 // network card -#define RP_DEVICECATEGORY_TAPE 4 // cassette tape drive -#define RP_DEVICECATEGORY_CARTRIDGE 5 // expansion cartridge -#define RP_DEVICECATEGORY_INPUTPORT 6 // input port (hosts an INPUTDEVICE: mouse, joystick, etc.) -#define RP_DEVICECATEGORY_KEYBOARD 7 // keyboard -#define RP_DEVICECATEGORY_MULTITAPPORT 8 // multitap port (e.g. input port on Amiga parallel port joystick adapter) -#define RP_DEVICECATEGORY_COUNT 9 // total number of device categories +#define RP_DEVICECATEGORY_FLOPPY 0 // floppy disk drive +#define RP_DEVICECATEGORY_HD 1 // hard disk drive +#define RP_DEVICECATEGORY_CD 2 // CD/DVD drive +#define RP_DEVICECATEGORY_NET 3 // network card +#define RP_DEVICECATEGORY_TAPE 4 // cassette tape drive +#define RP_DEVICECATEGORY_CARTRIDGE 5 // expansion cartridge +#define RP_DEVICECATEGORY_INPUTPORT 6 // input port (hosts an INPUTDEVICE: mouse, joystick, etc.) +#define RP_DEVICECATEGORY_KEYBOARD 7 // keyboard +#define RP_DEVICECATEGORY_MULTITAPPORT 8 // multitap port (e.g. input port on Amiga parallel port joystick adapter) +#define RP_DEVICECATEGORY_MODEM 9 // virtual modem +#define RP_DEVICECATEGORY_PRINTER 10 // printer +#define RP_DEVICECATEGORY_COUNT 11 // total number of device categories #define RP_ALL_DEVICES 32 // constant for the RP_IPC_TO_HOST_DEVICEACTIVITY message (to turn on/off all LEDs for a device category) @@ -633,6 +641,11 @@ typedef struct RPExecuteResult } RPEXECUTERESULT; +// RP_IPC_TO_HOST_DEVICEREADBYTE returned flag +#define RP_READBYTE_OK 0x80000000 // a byte was read from the specified device +#define RP_READBYTE_BYTEMASK 0x000000FF // byte mask + + // Legacy Compatibility #ifndef RP_NO_LEGACY // Changed in 7.0 diff --git a/od-win32/parser.cpp b/od-win32/parser.cpp index 0dcbad8e..8ba42148 100644 --- a/od-win32/parser.cpp +++ b/od-win32/parser.cpp @@ -56,6 +56,9 @@ #include "uaeipc.h" #include "xwin.h" #include "drawing.h" +#ifdef RETROPLATFORM +#include "rp.h" +#endif #define GSDLLEXPORT __declspec(dllimport) @@ -224,9 +227,9 @@ static void prt_thread (void *p) prt_running--; } -static int doflushprinter (void) +static int doflushprinter(int open) { - if (prtopen == 0 && prtbufbytes < MIN_PRTBYTES) { + if (open == 0 && prtbufbytes < MIN_PRTBYTES) { if (prtbufbytes > 0) write_log (_T("PRINTER: %d bytes received, less than %d bytes, not printing.\n"), prtbufbytes, MIN_PRTBYTES); prtbufbytes = 0; @@ -267,7 +270,7 @@ static void flushprtbuf (void) if (currprefs.parallel_matrix_emulation >= PARALLEL_MATRIX_EPSON) { int i; if (!prtopen) { - if (!doflushprinter ()) + if (!doflushprinter(prtopen)) return; if (epson_init (currprefs.prtname, currprefs.parallel_matrix_emulation)) prtopen = 1; @@ -275,8 +278,20 @@ static void flushprtbuf (void) for (i = 0; i < prtbufbytes; i++) epson_printchar (prtbuf[i]); } else { +#ifdef RETROPLATFORM + if (rp_isprinter()) { + bool open = rp_isprinteropen(); + if (!open) { + if (!doflushprinter(open)) + return; + } + rp_writeprinter(prtbuf, prtbufbytes); + prtbufbytes = 0; + return; + } +#endif if (hPrt == INVALID_HANDLE_VALUE) { - if (!doflushprinter ()) + if (!doflushprinter(prtopen)) return; openprinter (); } @@ -358,18 +373,23 @@ static void DoSomeWeirdPrintingStuff (uae_char val) } } -int isprinter (void) +int isprinter(void) { +#ifdef RETROPLATFORM + if (rp_isprinter()) { + return 1; + } +#endif if (!currprefs.prtname[0]) return 0; - if (!_tcsncmp (currprefs.prtname, _T("LPT"), 3)) { - paraport_open (currprefs.prtname); + if (!_tcsncmp(currprefs.prtname, _T("LPT"), 3)) { + paraport_open(currprefs.prtname); return -1; } return 1; } -int isprinteropen (void) +int isprinteropen(void) { if (prtopen || prtbufbytes > 0) return 1; @@ -507,12 +527,23 @@ static void openprinter (void) } } -void flushprinter (void) +void flushprinter(void) { - if (!doflushprinter ()) +#ifdef RETROPLATFORM + if (rp_isprinter()) { + if (!doflushprinter(rp_isprinteropen())) { + return; + } + flushprtbuf(); + rp_writeprinter(NULL, 0); + closeprinter(); return; - flushprtbuf (); - closeprinter (); + } +#endif + if (!doflushprinter(prtopen)) + return; + flushprtbuf(); + closeprinter(); } void closeprinter (void) diff --git a/od-win32/rp.cpp b/od-win32/rp.cpp index a6ca53f5..66d98f55 100644 --- a/od-win32/rp.cpp +++ b/od-win32/rp.cpp @@ -47,8 +47,10 @@ int rp_rpescapekey = 0x01; int rp_rpescapeholdtime = 600; int rp_screenmode = 0; int rp_inputmode = 0; +int rp_printer = 0; int log_rp = 2; static int rp_revision, rp_version, rp_build; +static int rp_printeropen = 0; static int max_horiz_dbl = RES_HIRES; static int max_vert_dbl = VRES_DOUBLE; @@ -2377,6 +2379,36 @@ void rp_reset(void) device_add_vsync_pre(rp_vsync); } + +bool rp_isprinter(void) +{ + return rp_printer != 0; +} +bool rp_isprinteropen(void) +{ + return rp_printer != 0 && rp_printeropen != 0; +} +void rp_writeprinter(uae_char *b, int len) +{ + if (!initialized) + return; + WPARAM unit = MAKEWORD(RP_DEVICECATEGORY_PRINTER, 0); + if (!b) { + if (rp_printeropen) { + write_log(_T("RP: printer close\n")); + RPSendMessagex(RP_IPC_TO_HOST_DEVICECLOSE, unit, 0, NULL, 0, &guestinfo, NULL); + } + rp_printeropen = 0; + return; + } + if (!rp_printeropen) { + write_log(_T("RP: printer open\n")); + RPSendMessagex(RP_IPC_TO_HOST_DEVICEOPEN, unit, 0, NULL, 0, &guestinfo, NULL); + rp_printeropen = 1; + } + RPSendMessagex(RP_IPC_TO_HOST_DEVICEWRITEBYTES, unit, 0, b, len, &guestinfo, NULL); +} + void rp_test(void) { #if 0 diff --git a/od-win32/rp.h b/od-win32/rp.h index a8bb950a..efff0177 100644 --- a/od-win32/rp.h +++ b/od-win32/rp.h @@ -24,12 +24,16 @@ extern bool rp_mouseevent(int x, int y, int buttons, int buttonmask); extern bool rp_ismouseevent(void); extern void rp_reset(void); extern void rp_test(void); +extern bool rp_isprinter(void); +extern bool rp_isprinteropen(void); +extern void rp_writeprinter(uae_char*, int); extern TCHAR *rp_param; extern int rp_rpescapekey; extern int rp_rpescapeholdtime; extern int rp_screenmode; extern int rp_inputmode; +extern int rp_printer; extern int log_rp; extern void rp_input_change (int num); diff --git a/od-win32/win32.cpp b/od-win32/win32.cpp index 92406e86..8307de5c 100644 --- a/od-win32/win32.cpp +++ b/od-win32/win32.cpp @@ -6654,6 +6654,11 @@ static int parseargs(const TCHAR *argx, const TCHAR *np, const TCHAR *np2) nocrashdump = 1; return 1; } + if (!_tcscmp(arg, _T("rpprinter"))) { + rp_printer = 1; + return 1; + } + if (!np) return 0; -- 2.47.3