1  /*
2   * E-UAE - The portable Amiga emulator.
3   *
4   * BeOS UI - or the beginnings of one
5   *
6   * Copyright 2004-2007 Richard Drummond
7   */
8 
9 extern "C" {
10 #include "sysconfig.h"
11 #include "sysdeps.h"
12 
13 #include "options.h"
14 #include "gui.h"
15 #include "xwin.h"
16 #include "disk.h"
17 #include "gensound.h"
18 }
19 
20 #include <AppKit.h>
21 #include <InterfaceKit.h>
22 #include <storage/FilePanel.h>
23 #include <storage/Path.h>
24 #include <kernel/OS.h>
25 
26 /*
27  * Dialog for inserting floppy images
28  */
29 class floppyFilePanel: public BFilePanel, public BHandler {
30     public:
31 	floppyFilePanel (int drive);
32 	void MessageReceived (BMessage *msg);
33 	void run ();
34     private:
35 	sem_id done_sem;
36 	static const uint32 MSG_FLOPPY_PANEL_DRIVE0 = 'flp0';
37 	static const uint32 MSG_FLOPPY_PANEL_DRIVE1 = 'flp1';
38 	static const uint32 MSG_FLOPPY_PANEL_DRIVE2 = 'flp2';
39 	static const uint32 MSG_FLOPPY_PANEL_DRIVE3 = 'flp3';
40 };
41 
floppyFilePanel(int drive)42 floppyFilePanel::floppyFilePanel (int drive):
43 	BFilePanel (B_OPEN_PANEL, NULL, NULL, 0, false, NULL, 0, true, true)
44 {
45     char title[80];
46     BEntry dir      = BEntry (currprefs.df[drive]);
47     BMessage   msg  = BMessage (MSG_FLOPPY_PANEL_DRIVE0 + drive);
48 
49     dir.GetParent (&dir);
50     sprintf (title, "UAE: Select image to insert in drive DF%d:", drive);
51 
52     done_sem = create_sem (0, NULL);
53 
54     be_app->Lock ();
55     be_app->AddHandler (this);
56     be_app->Unlock ();
57 
58     this->SetTarget (BMessenger (this));
59     this->SetMessage (&msg);
60     this->SetPanelDirectory (&dir);
61     this->Window ()->SetTitle (title);
62 }
63 
MessageReceived(BMessage * msg)64 void floppyFilePanel::MessageReceived (BMessage *msg) {
65     switch (msg->what) {
66 	case MSG_FLOPPY_PANEL_DRIVE0:
67 	case MSG_FLOPPY_PANEL_DRIVE1:
68 	case MSG_FLOPPY_PANEL_DRIVE2:
69 	case MSG_FLOPPY_PANEL_DRIVE3: {
70 	    int drive = msg->what - MSG_FLOPPY_PANEL_DRIVE0;
71 	    entry_ref ref;
72 	    BEntry entry;
73 	    if (msg->FindRef ("refs", &ref) == B_NO_ERROR)
74 	        if (entry.SetTo (&ref) == B_NO_ERROR) {
75 		    BPath path;
76 		    entry.GetPath (&path);
77 //		    disk_insert (drive, path.Path ());
78 //		    disk_insert() doesn't work for some reason . . .
79 		    strcpy (changed_prefs.df[drive], path.Path ());
80 		    release_sem (done_sem);
81 	        }
82 		break;
83 	    }
84 	case B_CANCEL:
85 	    release_sem (done_sem);
86 	    /* fall through */
87 	default:
88 	    BHandler::MessageReceived (msg);
89     }
90 }
91 
run()92 void floppyFilePanel::run ()
93 {
94     this->Window ()->Show ();
95     acquire_sem (done_sem);
96 }
97 
98 
99 /*
100  * The UAE GUI callbacks
101  */
102 
gui_init(void)103 int gui_init (void)
104 {
105 }
106 
gui_exit(void)107 void gui_exit (void)
108 {
109 }
110 
gui_update(void)111 int gui_update (void)
112 {
113     return 0;
114 }
115 
gui_filename(int num,const char * name)116 void gui_filename (int num, const char *name)
117 {
118 }
119 
gui_handle_events(void)120 void gui_handle_events (void)
121 {
122 }
123 
gui_fps(int fps,int idle)124 void gui_fps (int fps, int idle)
125 {
126     gui_data.fps  = fps;
127     gui_data.idle = idle;
128 }
129 
gui_flicker_led(int led,int unitnum,int status)130 void gui_flicker_led (int led, int unitnum, int status)
131 {
132 }
133 
gui_led(int led,int on)134 void gui_led (int led, int on)
135 {
136 }
137 
gui_display(int shortcut)138 void gui_display (int shortcut)
139 {
140     pause_sound ();
141 
142     if (shortcut >=0 && shortcut < 4) {
143 	/* If we're running full-screen, we must toggle
144 	 * to windowed mode before opening the dialog */
145 	int was_fullscreen;
146 
147 	if (was_fullscreen = is_fullscreen ()) {
148 	    toggle_fullscreen (0);
149 	    if (is_fullscreen ()) {
150 		resume_sound ();
151 		return;
152 	    }
153 	}
154 
155 	(new floppyFilePanel (shortcut))->run ();
156 
157 	if (was_fullscreen)
158 	    toggle_fullscreen (0);
159     }
160     resume_sound ();
161 }
162 
gui_message(const char * format,...)163 void gui_message (const char *format,...)
164 {
165     char msg[2048];
166     va_list parms;
167     BAlert *alert;
168 
169     va_start (parms,format);
170     vsprintf (msg, format, parms);
171     va_end (parms);
172 
173     write_log (msg);
174 
175     alert = new BAlert ("UAE Information", msg, "Okay", NULL, NULL,
176 			B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT);
177     alert->Go();
178 }
179 
180 static int guijoybutton[MAX_JPORTS];
181 static int guijoyaxis[MAX_JPORTS][4];
182 static bool guijoychange;
183 
gui_gameport_button_change(int port,int button,int onoff)184 void gui_gameport_button_change (int port, int button, int onoff)
185 {
186         //write_log ("%d %d %d\n", port, button, onoff);
187 #ifdef RETROPLATFORM
188         int mask = 0;
189         if (button == JOYBUTTON_CD32_PLAY)
190                 mask = RP_JOYSTICK_BUTTON5;
191         if (button == JOYBUTTON_CD32_RWD)
192                 mask = RP_JOYSTICK_BUTTON6;
193         if (button == JOYBUTTON_CD32_FFW)
194                 mask = RP_JOYSTICK_BUTTON7;
195         if (button == JOYBUTTON_CD32_GREEN)
196                 mask = RP_JOYSTICK_BUTTON4;
197         if (button == JOYBUTTON_3 || button == JOYBUTTON_CD32_YELLOW)
198                 mask = RP_JOYSTICK_BUTTON3;
199         if (button == JOYBUTTON_1 || button == JOYBUTTON_CD32_RED)
200                 mask = RP_JOYSTICK_BUTTON1;
201         if (button == JOYBUTTON_2 || button == JOYBUTTON_CD32_BLUE)
202                 mask = RP_JOYSTICK_BUTTON2;
203         rp_update_gameport (port, mask, onoff);
204 #endif
205         if (onoff)
206                 guijoybutton[port] |= 1 << button;
207         else
208                 guijoybutton[port] &= ~(1 << button);
209         guijoychange = true;
210 }
211 
gui_gameport_axis_change(int port,int axis,int state,int max)212 void gui_gameport_axis_change (int port, int axis, int state, int max)
213 {
214         int onoff = state ? 100 : 0;
215         if (axis < 0 || axis > 3)
216                 return;
217         if (max < 0) {
218                 if (guijoyaxis[port][axis] == 0)
219                         return;
220                 if (guijoyaxis[port][axis] > 0)
221                         guijoyaxis[port][axis]--;
222         } else {
223                 if (state > max)
224                         state = max;
225                 if (state < 0)
226                         state = 0;
227                 guijoyaxis[port][axis] = max ? state * 127 / max : onoff;
228 #ifdef RETROPLATFORM
229                 if (axis == DIR_LEFT_BIT)
230                         rp_update_gameport (port, RP_JOYSTICK_LEFT, onoff);
231                 if (axis == DIR_RIGHT_BIT)
232                         rp_update_gameport (port, DIR_RIGHT_BIT, onoff);
233                 if (axis == DIR_UP_BIT)
234                         rp_update_gameport (port, DIR_UP_BIT, onoff);
235                 if (axis == DIR_DOWN_BIT)
236                         rp_update_gameport (port, DIR_DOWN_BIT, onoff);
237 #endif
238         }
239         guijoychange = true;
240 }
241 
242