1 /*
2  * PUAE - The *nix Amiga Emulator
3  *
4  * QT GUI for PUAE
5  *
6  * Copyright 2010 Mustafa 'GnoStiC' TUFAN
7  *
8  */
9 
10 #include <QtGui/QApplication>
11 #include <QtGui/QMessageBox>
12 #include <QThread>
13 #include "puae_bridge.h"
14 #include "puae_mainwindow.h"
15 //#include "ui_puae_mainwindow.h"
16 
17 extern "C" {
18 #include "puae_registry.h"
19 #include "gui.h"
20 #include "options.h"
21 #include "writelog.h"
22 #include "misc.h"
23 extern struct uae_prefs workprefs;
24 extern struct uae_prefs currprefs;
25 extern void romlist_clear (void);
26 extern int load_keyring (struct uae_prefs *p, const char *path);
27 }
28 
29 static unsigned int gui_available;
30 static int allow_quit;
31 static int restart_requested;
32 static int full_property_sheet = 1;
33 static struct uae_prefs *pguiprefs;
34 static int currentpage;
35 static int qs_request_reset;
36 static int qs_override;
37 int gui_active;
38 
39 static int forceroms;
40 
41 /*
42  *
43  *
44  */
45 /*class MyThread : public QThread {
46 public:
47 	virtual void run();
48 };
49 
50 void MyThread::run()
51 {
52     QApplication a(NULL, NULL);
53     puae_MainWindow w;
54     w.show();
55     a.exec();
56 }
57 */
58 
59 /* This function is called from od-macosx/main.m
60  * WARNING: This gets called *before* real_main(...)!
61  */
cocoa_gui_early_setup(void)62 extern "C" void cocoa_gui_early_setup (void)
63 {
64 }
65 
read_rom_list(void)66 void read_rom_list (void)
67 {
68 	char tmp2[1000];
69 	int idx, idx2;
70 	char tmp[1000];
71 	int size, size2, exists;
72 
73 	romlist_clear ();
74 	exists = regexiststree ("DetectedROMs");
75 	if (!exists || forceroms) {
76 		load_keyring (NULL, NULL);
77 		scan_roms (forceroms ? 0 : 1);
78 	}
79 	forceroms = 0;
80 }
81 
prefs_to_gui(struct uae_prefs * p)82 static void prefs_to_gui (struct uae_prefs *p)
83 {
84 	workprefs = *p;
85 	/* filesys hack */
86 	workprefs.mountitems = currprefs.mountitems;
87 	memcpy (&workprefs.mountconfig, &currprefs.mountconfig, MOUNT_CONFIG_SIZE * sizeof (struct uaedev_config_info));
88 
89 	//updatewinfsmode (&workprefs);
90 }
91 
gui_to_prefs(void)92 static void gui_to_prefs (void)
93 {
94 	/* Always copy our prefs to changed_prefs, ... */
95 	changed_prefs = workprefs;
96 	/* filesys hack */
97 	currprefs.mountitems = changed_prefs.mountitems;
98 	memcpy (&currprefs.mountconfig, &changed_prefs.mountconfig, MOUNT_CONFIG_SIZE * sizeof (struct uaedev_config_info));
99 	fixup_prefs (&changed_prefs);
100 
101 	//updatewinfsmode (&changed_prefs);
102 }
103 
GetSettings(int all_options)104 int GetSettings (int all_options)
105 {
106 	static int init_called = 0;
107 	int first = 0;
108 
109 	gui_active++;
110 
111 	full_property_sheet = all_options;
112 	allow_quit = all_options;
113 	pguiprefs = &currprefs;
114 	memset (&workprefs, 0, sizeof (struct uae_prefs));
115 	default_prefs (&workprefs, 0);
116 
117 	prefs_to_gui (&changed_prefs);
118 
119 	if (!init_called) {
120 		first = 1;
121 		init_called = 1;
122 	}
123 
124 	if (first)
125 		write_log ("Entering GUI idle loop\n");
126 
127 	full_property_sheet = 0;
128 	gui_active--;
129 	return 0;
130 }
131 
gui_init(void)132 int gui_init (void)
133 {
134 //  MyThread *QT_GUI_Thread=new MyThread;
135 //	QT_GUI_Thread->start();
136 	int ret;
137 
138 	read_rom_list ();
139 	inputdevice_updateconfig (&workprefs, &currprefs);
140 
141         for (;;) {
142                 ret = GetSettings (1);
143                 if (!restart_requested)
144                         break;
145                 restart_requested = 0;
146         }
147 #ifdef AVIOUTPUT
148         if (ret > 0) {
149                 AVIOutput_Begin ();
150         }
151 #endif
152         return ret;
153 }
154 
gui_exit(void)155 void gui_exit (void)
156 {
157 
158 }
159 
gui_update(void)160 int gui_update (void)
161 {
162 	return 1;
163 }
164 
gui_display(int shortcut)165 void gui_display (int shortcut)
166 {
167 	int foo;
168 
169 	if (shortcut == -1) {
170 		int local_argc = 0;
171 		char **local_argv = NULL;
172 		QApplication myApp(local_argc, local_argv);
173 		puae_MainWindow w;
174 
175 		w.show();
176 		foo = myApp.exec();
177 	}
178 }
179 
gui_message(const char * format,...)180 extern "C" void gui_message (const char *format,...)
181 {
182 	char msg[2048];
183 	va_list parms;
184 
185 	va_start (parms, format);
186 	vsprintf (msg, format, parms);
187 	va_end (parms);
188 
189 	if (gui_available)
190 		QMessageBox::information(0, "PUAE", msg);
191 
192 //	write_log (msg);
193 }
194 
gui_fps(int fps,int idle,int color)195 void gui_fps (int fps, int idle, int color)
196 {
197         gui_data.fps = fps;
198         gui_data.idle = idle;
199         gui_led (LED_FPS, 0);
200         gui_led (LED_CPU, 0);
201         gui_led (LED_SND, (gui_data.sndbuf_status > 1 || gui_data.sndbuf_status < 0) ? 0 : 1);
202 }
203 
gui_handle_events(void)204 void gui_handle_events (void)
205 {
206 }
207 
gui_led(int led,int on)208 void gui_led (int led, int on)
209 {
210 	int writing = 0, playing = 0, active2 = 0;
211 	int center = 0;
212 
213 	if (led >= LED_DF0 && led <= LED_DF3) {
214 	} else if (led == LED_POWER) {
215 	} else if (led == LED_HD) {
216 		if (on > 1)
217 			writing = 1;
218 	} else if (led == LED_CD) {
219 		if (on & LED_CD_AUDIO)
220 			playing = 1;
221 		else if (on & LED_CD_ACTIVE2)
222 			active2 = 1;
223 		on &= 1;
224 	} else if (led == LED_FPS) {
225 		double fps = (double)gui_data.fps / 10.0;
226 		if (fps > 999.9)
227 			fps = 999.9;
228 	} else if (led == LED_CPU) {
229 	} else if (led == LED_SND && gui_data.drive_disabled[3]) {
230 	} else if (led == LED_MD) {
231 	}
232 
233 }
234 
gui_flicker_led2(int led,int unitnum,int status)235 static void gui_flicker_led2 (int led, int unitnum, int status)
236 {
237         static int resetcounter[LED_MAX];
238         uae_s8 old;
239         uae_s8 *p;
240 
241         if (led == LED_HD)
242                 p = &gui_data.hd;
243         else if (led == LED_CD)
244                 p = &gui_data.cd;
245         else if (led == LED_MD)
246                 p = &gui_data.md;
247         else
248                 return;
249         old = *p;
250         if (status == 0) {
251                 resetcounter[led]--;
252                 if (resetcounter[led] > 0)
253                         return;
254         }
255 #ifdef RETROPLATFORM
256         if (led == LED_HD)
257                 rp_hd_activity (unitnum, status ? 1 : 0, status == 2 ? 1 : 0);
258         else if (led == LED_CD)
259                 rp_cd_activity (unitnum, status);
260 #endif
261         *p = status;
262         resetcounter[led] = 6;
263         if (old != *p)
264                 gui_led (led, *p);
265 }
266 
gui_flicker_led(int led,int unitnum,int status)267 void gui_flicker_led (int led, int unitnum, int status)
268 {
269         if (led < 0) {
270                 gui_flicker_led2 (LED_HD, 0, 0);
271                 gui_flicker_led2 (LED_CD, 0, 0);
272                 gui_flicker_led2 (LED_MD, 0, 0);
273         } else {
274                 gui_flicker_led2 (led, unitnum, status);
275         }
276 }
277 
gui_gameport_axis_change(int port,int axis,int state,int max)278 void gui_gameport_axis_change (int port, int axis, int state, int max)
279 {
280 }
281 
gui_gameport_button_change(int port,int button,int onoff)282 void gui_gameport_button_change (int port, int button, int onoff)
283 {
284 }
285 
gui_disk_image_change(int unitnum,const TCHAR * name,bool writeprotected)286 void gui_disk_image_change (int unitnum, const TCHAR *name, bool writeprotected)
287 {
288 }
289 
gui_filename(int num,const char * name)290 void gui_filename (int num, const char *name)
291 {
292 }
293