-
Notifications
You must be signed in to change notification settings - Fork 0
/
uaeexe.c
executable file
·131 lines (114 loc) · 2.4 KB
/
uaeexe.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* 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 char running = 0;
static uae_u32 uaeexe_server (TrapContext *context) REGPARAM;
/*
* Install the server
*/
void uaeexe_install (void)
{
uaecptr loop;
loop = here ();
org (UAEEXE_ORG);
calltrap (deftrap (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 char *cmd)
{
struct uae_xcmd *nw;
if (!running)
goto NORUN;
nw = (struct uae_xcmd *) malloc (sizeof *nw);
if (!nw)
goto NOMEM;
nw->cmd = (char *) malloc (strlen (cmd) + 1);
if (!nw->cmd) {
free (nw);
goto NOMEM;
}
strcpy (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 ("Remote cli is not running.\n");
return UAEEXE_NOTRUNNING;
}
/*
* returns next command to be executed
*/
static char *get_cmd (void)
{
struct uae_xcmd *cmd;
char *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) (get_long (m68k_areg (&context->regs, 7) + 4*(x+1)))
static uae_u32 REGPARAM2 uaeexe_server (TrapContext *context)
{
int len;
char *cmd;
char *dst;
if (ARG(0) && !running) {
running = 1;
write_log ("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);
strncpy (dst, cmd, len);
write_log ("Sending '%s' to remote cli\n", cmd);
free (cmd);
return ARG (0);
}