]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
rpprinter
authorToni Wilen <twilen@winuae.net>
Sat, 3 Dec 2022 13:47:51 +0000 (15:47 +0200)
committerToni Wilen <twilen@winuae.net>
Sat, 3 Dec 2022 13:47:51 +0000 (15:47 +0200)
od-win32/cloanto/RetroPlatformIPC.h
od-win32/parser.cpp
od-win32/rp.cpp
od-win32/rp.h
od-win32/win32.cpp

index 5bd76a2efd771e5f2bf39ed6245c024cf9e5409a..a4cbb70d503d788e809859cb336634fe6d64f64c 100644 (file)
@@ -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 <windows.h>
 
-#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"
 #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
index 0dcbad8e218a0a3b9fb8df42e7adbcb134fb9056..8ba42148985c67b06bbf39a6a0ec60f73c1b7088 100644 (file)
@@ -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)
index a6ca53f50611d570f7a6b0d0dd26c2b6a71c952d..66d98f5502b87923ee3d6e1320b31e4cbb14836c 100644 (file)
@@ -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
index a8bb950a3dce9570745770f3bc97e3e34e29ae9e..efff017748c394851c5384cac599e215127ca0c4 100644 (file)
@@ -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);
index 92406e86749b82fb284db3c980237bf90ac957fe..8307de5c6cc79ed38eee42f1f7111eb66d0bf51a 100644 (file)
@@ -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;