From 3014d211797f1b8576160c3af9dcf54c2c8d5fde Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Sat, 4 Jul 2020 14:40:19 +0200 Subject: [PATCH] Implemented uaeexe functionality --- Makefile | 1 + VisualGDB/Amiberry/Amiberry.vcxproj | 2 + VisualGDB/Amiberry/Amiberry.vcxproj.filters | 6 + src/devices.cpp | 3 +- src/include/uaeexe.h | 26 ++++ src/uaeexe.cpp | 135 ++++++++++++++++++++ 6 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 src/include/uaeexe.h create mode 100644 src/uaeexe.cpp diff --git a/Makefile b/Makefile index 9740908c..22e9a5f2 100644 --- a/Makefile +++ b/Makefile @@ -331,6 +331,7 @@ OBJS = \ src/scsiemul.o \ src/statusline.o \ src/traps.o \ + src/uaeexe.o \ src/uaelib.o \ src/uaeresource.o \ src/zfile.o \ diff --git a/VisualGDB/Amiberry/Amiberry.vcxproj b/VisualGDB/Amiberry/Amiberry.vcxproj index a5df9294..e1eab64d 100644 --- a/VisualGDB/Amiberry/Amiberry.vcxproj +++ b/VisualGDB/Amiberry/Amiberry.vcxproj @@ -304,6 +304,7 @@ + @@ -432,6 +433,7 @@ + diff --git a/VisualGDB/Amiberry/Amiberry.vcxproj.filters b/VisualGDB/Amiberry/Amiberry.vcxproj.filters index 66974e13..bb3af2a8 100644 --- a/VisualGDB/Amiberry/Amiberry.vcxproj.filters +++ b/VisualGDB/Amiberry/Amiberry.vcxproj.filters @@ -631,6 +631,9 @@ Source files + + Source files + @@ -1035,5 +1038,8 @@ Source files\include + + Source files\include + \ No newline at end of file diff --git a/src/devices.cpp b/src/devices.cpp index f99cc55d..491f9262 100644 --- a/src/devices.cpp +++ b/src/devices.cpp @@ -30,6 +30,7 @@ #include "gui.h" #include "drawing.h" #include "statusline.h" +#include "uaeexe.h" #ifdef JIT #include "jit/compemu.h" #endif @@ -337,7 +338,7 @@ void virtualdevice_init (void) #ifdef AUTOCONFIG expansion_init (); emulib_install (); - //uaeexe_install (); + uaeexe_install (); #endif #ifdef FILESYS filesys_install (); diff --git a/src/include/uaeexe.h b/src/include/uaeexe.h new file mode 100644 index 00000000..7423fec6 --- /dev/null +++ b/src/include/uaeexe.h @@ -0,0 +1,26 @@ +/* + * uaeexe.h - launch executable in UAE + * + * (c) 1997 by Samuel Devulder + */ + +#ifndef UAE_UAEEXE_H +#define UAE_UAEEXE_H + +#include "uae/types.h" + +struct uae_xcmd { + struct uae_xcmd *prev, *next; + TCHAR *cmd; +}; + +#define UAEEXE_ORG 0xF0FF90 /* sam: I hope this slot is free */ + +#define UAEEXE_OK 0 +#define UAEEXE_NOTRUNNING 1 +#define UAEEXE_NOMEM 2 + +extern void uaeexe_install (void); +extern int uaeexe (const TCHAR *cmd); + +#endif /* UAE_UAEEXE_H */ diff --git a/src/uaeexe.cpp b/src/uaeexe.cpp new file mode 100644 index 00000000..58542085 --- /dev/null +++ b/src/uaeexe.cpp @@ -0,0 +1,135 @@ +/* +* uaeexe.c - UAE remote cli +* +* (c) 1997 by Samuel Devulder +*/ + +#include "sysconfig.h" +#include "sysdeps.h" + +#include "options.h" +#include "uae.h" +#include "memory.h" +#include "custom.h" +#include "newcpu.h" +#include "autoconf.h" +#include "traps.h" +#include "uaeexe.h" + +static struct uae_xcmd *first = NULL; +static struct uae_xcmd *last = NULL; +static TCHAR running = 0; +static uae_u32 REGPARAM3 uaeexe_server (TrapContext *context) REGPARAM; + +/* +* Install the server +*/ +void uaeexe_install (void) +{ + uaecptr loop; + + if (!uae_boot_rom_type && !currprefs.uaeboard) + return; + loop = here (); + org (UAEEXE_ORG); + calltrap (deftrapres (uaeexe_server, 0, _T("uaeexe_server"))); + dw (RTS); + org (loop); +} + +/* +* Send command to the remote cli. +* +* To use this, just call uaeexe("command") and the command will be +* executed by the remote cli (provided you've started it in the +* s:user-startup for example). Be sure to add "run" if you want +* to launch the command asynchronously. Please note also that the +* remote cli works better if you've got the fifo-handler installed. +*/ +int uaeexe (const TCHAR *cmd) +{ + struct uae_xcmd *nw; + + if (!running) + goto NORUN; + + nw = xmalloc (struct uae_xcmd, 1); + if (!nw) + goto NOMEM; + nw->cmd = xmalloc (TCHAR, _tcslen (cmd) + 1); + if (!nw->cmd) { + xfree (nw); + goto NOMEM; + } + + _tcscpy (nw->cmd, cmd); + nw->prev = last; + nw->next = NULL; + + if (!first) + first = nw; + if (last) { + last->next = nw; + last = nw; + } else + last = nw; + + return UAEEXE_OK; +NOMEM: + return UAEEXE_NOMEM; +NORUN: + write_log (_T("Remote cli is not running.\n")); + return UAEEXE_NOTRUNNING; +} + +/* +* returns next command to be executed +*/ +static TCHAR *get_cmd (void) +{ + struct uae_xcmd *cmd; + TCHAR *s; + + if (!first) + return NULL; + s = first->cmd; + cmd = first; + first = first->next; + if (!first) + last = NULL; + free (cmd); + return s; +} + +/* +* helper function +*/ +#define ARG(x) (trap_get_long(ctx, trap_get_areg(ctx, 7) + 4 * (x + 1))) +static uae_u32 REGPARAM2 uaeexe_server (TrapContext *ctx) +{ + int len; + TCHAR *cmd; + char *dst, *s; + + if (ARG (0) && !running) { + running = 1; + write_log (_T("Remote CLI started.\n")); + } + + cmd = get_cmd (); + if (!cmd) + return 0; + if (!ARG (0)) { + running = 0; + return 0; + } + + dst = (char*)get_real_address (ARG (0)); + len = ARG (1); + s = ua (cmd); + strncpy (dst, s, len); + write_log (_T("Sending '%s' to remote cli\n"), cmd); + xfree (s); + xfree (cmd); + return ARG (0); +}