1 /************************************************************************/
2 /*									*/
3 /*				QUASI88					*/
4 /*									*/
5 /************************************************************************/
6 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <sys/types.h>
10 #include <unistd.h>	/* setuid, getuid */
11 
12 #include "quasi88.h"
13 #include "device.h"
14 
15 #include "getconf.h"	/* config_init */
16 #include "suspend.h"	/* stateload_system */
17 #include "menu.h"	/* menu_about_osd_msg */
18 
19 #include "snapshot.h"	/* snapshot_cmd_enable */
20 
21 
22 /***********************************************************************
23  * ���ץ����
24  ************************************************************************/
25 static	int	invalid_arg;
26 static	const	T_CONFIG_TABLE x11_options[] =
27 {
28   /* 300��349: �����ƥ��¸���ץ���� */
29 
30   /*  -- GRAPHIC -- */
31   { 300, "cmap",         X_INT,  &colormap_type,   0, 2,                    0, 0        },
32 #ifdef MITSHM
33   { 301, "shm",          X_FIX,  &use_SHM,         TRUE,                  0,0, 0        },
34   { 301, "noshm",        X_FIX,  &use_SHM,         FALSE,                 0,0, 0        },
35 #else
36   {   0, "shm",          X_INV,                                       0,0,0,0, 0        },
37   {   0, "noshm",        X_INV,                                       0,0,0,0, 0        },
38 #endif
39 #ifdef USE_XV
40   { 302, "xv",           X_FIX,  &use_xv,          TRUE,                  0,0, 0        },
41   { 302, "noxv",         X_FIX,  &use_xv,          FALSE,                 0,0, 0        },
42 #else
43   {   0, "xv",           X_INV,                                       0,0,0,0, 0        },
44   {   0, "noxv",         X_INV,                                       0,0,0,0, 0        },
45 #endif
46   { 303, "xdnd",         X_FIX,  &use_xdnd,        TRUE,                  0,0, 0        },
47   { 303, "noxdnd",       X_FIX,  &use_xdnd,        FALSE,                 0,0, 0        },
48   { 304, "xsync",        X_FIX,  &use_xsync,       TRUE,                  0,0, 0        },
49   { 304, "noxsync",      X_FIX,  &use_xsync,       FALSE,                 0,0, 0        },
50 
51   /*  -- INPUT -- */
52   { 311, "use_joy",      X_FIX,  &use_joydevice,   TRUE,                  0,0, 0        },
53   { 311, "nouse_joy",    X_FIX,  &use_joydevice,   FALSE,                 0,0, 0        },
54   { 312, "keyboard",     X_INT,  &keyboard_type,   0, 2,                    0, 0        },
55   { 313, "keyconf",      X_STR,  &file_keyboard,                        0,0,0, 0        },
56 
57   /*  -- SYSTEM -- */
58   { 321, "sleepparm",    X_INT,  &wait_sleep_min_us, 0, 1000000,            0, 0        },
59   { 322, "show_fps",     X_FIX,  &show_fps,        TRUE,                  0,0, 0        },
60   { 322, "hide_fps",     X_FIX,  &show_fps,        FALSE,                 0,0, 0        },
61 
62 
63   /*  -- ̵�� -- (¾�����ƥ�ΰ����Ĥ����ץ����) */
64   {   0, "videodrv",     X_INV,  &invalid_arg,                          0,0,0, 0        },
65   {   0, "audiodrv",     X_INV,  &invalid_arg,                          0,0,0, 0        },
66 
67   {   0, "sdlbufsize",   X_INV,  &invalid_arg,                          0,0,0, 0        },
68   {   0, "sdlbufnum",    X_INV,  &invalid_arg,                          0,0,0, 0        },
69 
70 
71   /* ��ü */
72   {   0, NULL,           X_INV,                                       0,0,0,0, 0        },
73 };
74 
help_msg_x11(void)75 static	void	help_msg_x11(void)
76 {
77   fprintf
78   (
79    stdout,
80    "  ** GRAPHIC (X11 depend) **\n"
81    "    -cmap <0/1/2>           Colormap type 0(shared)/1(private)/2(static)\n"
82 #ifdef	MITSHM
83    "    -shm/-noshm             Use/Not use MIT SHM extensions [-shm]\n"
84 #endif
85 #ifdef	USE_DGA
86    "    -dga/-nodga             Use/Not use XFree86-DGA (-fullscreen) [-nodga]\n"
87 #endif
88 #ifdef	USE_XV
89    "    -xv/-noxv               Use/Not use XV Extension [-noxv]\n"
90 #endif
91    "    -xdnd/-noxdnd           Enable/Disable X-Drag-And-Drop Protcol [-xdnd]\n"
92    "    -xsync/-noxsync         Use/Not use XSync as screen refresh [-xsync]\n"
93    "  ** INPUT (X11 depend) **\n"
94    "    -use_joy/-nouse_joy     Enable/Disabel system joystick [-use_joy]\n"
95    "    -keyboard <0|1|2>       Set keyboard type (0:config/1:106key/2:101key) [1]\n"
96    "    -keyconf <filename>     Specify keyboard configuration file <filename>\n"
97    "  ** SYSTEM (X11 depend) **\n"
98    "    -show_fps/-hide_fps     Show/Hide FPS (experimentral)\n"
99    );
100 }
101 
102 
103 
104 /***********************************************************************
105  * �ᥤ�����
106  ************************************************************************/
107 static	void	finish(void);
108 
main(int argc,char * argv[])109 int	main(int argc, char *argv[])
110 {
111     int x = 1;
112 
113 	/* root���¤�ɬ�פʽ��� (X11��Ϣ) ������˹Ԥ� */
114 
115     x11_init();	/* �����ǥ��顼���ФƤ⥪�ץ������Ϥ���Τ���˿ʤ� */
116 
117 
118 	/* �ǡ����줬�����С� root ���¤������ */
119 
120     if (setuid( getuid() ) != 0) {
121 	fprintf(stderr, "%s : setuid error\n", argv[0]);
122 	x11_exit();
123 	return -1;
124     }
125 
126 	/* root �� exec() �Ǥ���Τϴ��ʤΤǡ����Ȥ� */
127 
128     if (getuid() == 0) snapshot_cmd_enable = FALSE;
129 
130 
131 	/* ����ǥ�����ͥ������å� */
132 
133 #ifdef LSB_FIRST
134     if (*(char *)&x != 1) {
135 	fprintf(stderr,
136 		"%s CAN'T EXCUTE !\n"
137 		"This machine is Big-Endian.\n"
138 		"Compile again comment-out 'LSB_FIRST = 1' in Makefile.\n",
139 		argv[0]);
140 	x11_exit();
141 	return -1;
142     }
143 #else
144     if (*(char *)&x == 1) {
145 	fprintf(stderr,
146 		"%s CAN'T EXCUTE !\n"
147 		"This machine is Little-Endian.\n"
148 		"Compile again comment-in 'LSB_FIRST = 1' in Makefile.\n",
149 		argv[0]);
150 	x11_exit();
151 	return -1;
152     }
153 #endif
154 
155 
156     if (config_init(argc, argv,		/* �Ķ������ & �������� */
157 		    x11_options,
158 		    help_msg_x11)) {
159 
160 	quasi88_atexit(finish);		/* quasi88() �¹���˶�����λ�����ݤ�
161 					   ������Хå��ؿ�����Ͽ���� */
162 	quasi88();			/* PC-8801 ���ߥ�졼����� */
163 
164 	config_exit();			/* ������������� */
165     }
166 
167     x11_exit();				/* X11��Ϣ����� */
168 
169     return 0;
170 }
171 
172 
173 
174 /*
175  * ������λ���Υ�����Хå��ؿ� (quasi88_exit()�ƽл��ˡ����������)
176  */
finish(void)177 static	void	finish(void)
178 {
179     config_exit();			/* ������������� */
180     x11_exit();				/* X11��Ϣ����� */
181 }
182 
183 
184 
185 /***********************************************************************
186  * ���ơ��ȥ��ɡ����ơ��ȥ�����
187  ************************************************************************/
188 
189 /*	¾�ξ����٤Ƥ����� or �����֤��줿��˸ƤӽФ���롣
190  *	ɬ�פ˱����ơ������ƥ��ͭ�ξ�����ղä��Ƥ⤤�����ȡ�
191  */
192 
stateload_system(void)193 int	stateload_system( void )
194 {
195   return TRUE;
196 }
statesave_system(void)197 int	statesave_system( void )
198 {
199   return TRUE;
200 }
201 
202 
203 
204 /***********************************************************************
205  * ��˥塼���̤�ɽ�����롢�����ƥ��ͭ��å�����
206  ************************************************************************/
207 
menu_about_osd_msg(int req_japanese,int * result_code,const char * message[])208 int	menu_about_osd_msg(int        req_japanese,
209 			   int        *result_code,
210 			   const char *message[])
211 {
212     static const char *about_en =
213     {
214 #ifdef	MITSHM
215 	"MIT-SHM ... Supported\n"
216 #endif
217 
218 #ifdef	USE_DGA
219 	"XFree86-DGA ... Supported\n"
220 #endif
221 
222 #ifdef	USE_XV
223 	"XVideo ... Supported\n"
224 #endif
225 
226 #if	defined (JOY_SDL)
227 	"JOYSTICK (SDL) ... Supported\n"
228 #elif	defined (JOY_LINUX_USB)
229 	"JOYSTICK (Linux USB-joystick) ... Supported\n"
230 #elif	defined (JOY_BSD_USB)
231 	"JOYSTICK (BSD USB-joystick) ... Supported\n"
232 #else
233 	"JOYSTICK ... Not supported\n"
234 #endif
235     };
236 
237     static const char *about_jp =
238     {
239 #ifdef	MITSHM
240 	"MIT-SHM �����ݡ��Ȥ���Ƥ��ޤ�\n"
241 #endif
242 
243 #ifdef	USE_DGA
244 	"XFree86-DGA �����ݡ��Ȥ���Ƥ��ޤ�\n"
245 #endif
246 
247 #ifdef	USE_XV
248 	"XVideo �����ݡ��Ȥ���Ƥ��ޤ�\n"
249 #endif
250 
251 #if	defined (JOY_SDL)
252 	"���祤���ƥ��å� (SDL) �����ݡ��Ȥ���Ƥ��ޤ�\n"
253 #elif	defined (JOY_LINUX_USB)
254 	"���祤���ƥ��å� (Linux USB-joystick) �����ݡ��Ȥ���Ƥ��ޤ�\n"
255 #elif	defined (JOY_BSD_USB)
256 	"���祤���ƥ��å� (BSD USB-joystick) �����ݡ��Ȥ���Ƥ��ޤ�\n"
257 #else
258 	"���祤���ƥ��å� �ϥ��ݡ��Ȥ���Ƥ��ޤ���\n"
259 #endif
260     };
261 
262 
263     *result_code = -1;				/* ʸ�������ɻ���ʤ� */
264 
265     if (req_japanese == FALSE) {
266 	*message = about_en;
267     } else {
268 	*message = about_jp;
269     }
270 
271     return TRUE;
272 }
273