16 * define the command functions for the controller pad.
19 #define CMD_PAD(b, B) \
20 static int (cmd_ ## b)(int c, char **v) \
21 { pad_set((PAD_ ## B), v[0][0] == '+'); return 0; } \
22 static int (cmd_ ## b)(int c, char **v)
27 CMD_PAD(right
, RIGHT
);
30 CMD_PAD(start
, START
);
31 CMD_PAD(select
, SELECT
);
35 * the set command is used to set rc-exported variables.
38 static int cmd_set(int argc
, char **argv
)
42 return rc_setvar(argv
[1], argc
-2, argv
+2);
46 * the toggle command is used to switch rc-exported bool variables.
49 static int cmd_toggle(int argc
, char **argv
)
51 static const char* bools
[] = {"0", "1", 0};
54 return rc_setvar(argv
[1], 1, rc_getint(argv
[1])?(void*)bools
:(void*)(bools
+1));
59 * the following commands allow keys to be bound to perform rc commands.
62 static int cmd_bind(int argc
, char **argv
)
66 return rc_bindkey(argv
[1], argv
[2]);
69 static int cmd_unbind(int argc
, char **argv
)
73 return rc_unbindkey(argv
[1]);
76 static int cmd_unbindall()
82 static int cmd_source(int argc
, char **argv
)
86 return rc_sourcefile(argv
[1]);
95 static int cmd_reset()
101 static int cmd_savestate(int argc
, char **argv
)
103 state_save(argc
> 1 ? atoi(argv
[1]) : -1);
107 static int cmd_loadstate(int argc
, char **argv
)
109 state_load(argc
> 1 ? atoi(argv
[1]) : -1);
113 static int cmd_menu(int argc
, char **argv
)
115 /* some of the actions we perform from the menu require us
116 to break out of the emu_run main loop, so we just signal
117 it to return and then let main() enter the menu instead. */
124 * table of command names and the corresponding functions to be called
130 RCC("toggle", cmd_toggle
),
131 RCC("bind", cmd_bind
),
132 RCC("unbind", cmd_unbind
),
133 RCC("unbindall", cmd_unbindall
),
134 RCC("source", cmd_source
),
135 RCC("reset", cmd_reset
),
136 RCC("quit", cmd_quit
),
137 RCC("menu", cmd_menu
),
138 RCC("savestate", cmd_savestate
),
139 RCC("loadstate", cmd_loadstate
),
143 RCC("+down", cmd_down
),
144 RCC("-down", cmd_down
),
145 RCC("+left", cmd_left
),
146 RCC("-left", cmd_left
),
147 RCC("+right", cmd_right
),
148 RCC("-right", cmd_right
),
153 RCC("+start", cmd_start
),
154 RCC("-start", cmd_start
),
155 RCC("+select", cmd_select
),
156 RCC("-select", cmd_select
),
165 int rc_command(char *line
)
168 char *argv
[128], *linecopy
;
170 linecopy
= malloc(strlen(line
)+1);
171 strcpy(linecopy
, line
);
173 argc
= splitline(argv
, (sizeof argv
)/(sizeof argv
[0]), linecopy
);
180 for (i
= 0; rccmds
[i
].name
; i
++)
182 if (!strcmp(argv
[0], rccmds
[i
].name
))
184 ret
= rccmds
[i
].func(argc
, argv
);
190 /* printf("unknown command: %s\n", argv[0]); */