6 #include <hildon/hildon.h>
10 #include "../frontend/plugin_lib.h"
11 #include "../frontend/main.h"
12 #include "../libpcsxcore/misc.h"
13 #include "../include/psemu_plugin_defs.h"
14 #include "../libpcsxcore/cdrom.h"
15 #include "../libpcsxcore/cdriso.h"
16 #include "../plugins/dfinput/main.h"
17 #include "../frontend/libpicofe/readpng.h"
18 #include "maemo_common.h"
20 #include <dbus/dbus.h>
27 #define CALL_SIGNAL_IF "com.nokia.csd.Call"
28 #define CALL_SIGNAL_PATH "/com/nokia/csd/call"
29 #define CALL_INCOMING_SIG "Coming"
31 #define DBUS_RULE_CALL_INCOMING "type='signal',interface='" CALL_SIGNAL_IF \
32 "',path='" CALL_SIGNAL_PATH \
33 "',member='" CALL_INCOMING_SIG "'"
35 osso_context_t* osso = NULL;
37 extern int bKeepDisplayOn;
38 extern int bAutosaveOnExit;
39 extern int cornerActions[4];
40 extern char keys_config_file[MAXPATHLEN];
41 static pthread_t display_thread = (pthread_t)0;
42 int g_layer_x = (X_RES - D_WIDTH) / 2;
43 int g_layer_y = (Y_RES - D_HEIGHT) / 2;
44 int g_layer_w = D_WIDTH, g_layer_h = D_HEIGHT;
46 static GdkImage *image;
47 static HildonAnimationActor *actor;
48 static GtkWidget *window, *drawing = NULL;
50 static int pl_buf_w, pl_buf_h;
52 int direction_keys[4];
54 // map psx4m compatible keymap to PSX keys
55 static const unsigned char keymap2[14] = {
82 int maemo_x11_update_keys();
83 void show_notification(char* text);
85 void change_slot(int delta)
90 else if (state_slot < 0)
93 sprintf(message,"Savestate slot: %i",state_slot + 1);
94 show_notification(message);
97 void save(int state_slot)
99 emu_save_state(state_slot);
100 char buf[MAXPATHLEN];
101 if (image && image->mem){
102 sprintf (buf,"/opt/maemo/usr/games/screenshots%s.%3.3d",file_name,state_slot);
103 writepng(buf, image->mem, pl_buf_w,pl_buf_h);
106 sprintf(message,"Saved savestate slot: %i",state_slot + 1);
107 show_notification(message);
112 if (bAutosaveOnExit){
113 show_notification("Autosaving");
115 char buf[MAXPATHLEN];
116 if (image && image->mem){
117 sprintf (buf,"/opt/maemo/usr/games/screenshots%s.%3.3d",file_name,99);
118 writepng(buf, image->mem, pl_buf_w,pl_buf_h);
124 int show_confirmbox(char* text)
130 dialog = gtk_message_dialog_new (GTK_WINDOW(window),
131 GTK_DIALOG_DESTROY_WITH_PARENT,
132 GTK_MESSAGE_QUESTION,
135 gint result = gtk_dialog_run (GTK_DIALOG (dialog));
136 gtk_widget_destroy (dialog);
137 if (result == GTK_RESPONSE_YES)
143 window_button_proxy(GtkWidget *widget,
144 GdkEventButton *event,
150 switch (event->type){
151 case GDK_BUTTON_PRESS:
152 //printf("GDK_BUTTON_PRESS: x=%f y=%f\n", event->x, event->y);
156 case GDK_BUTTON_RELEASE:
157 //printf("GDK_BUTTON_RELEASE: x=%f y=%f\n", event->x, event->y);
158 if (press_x < sens && press_y < sens && event->x < sens && event->y < sens)
160 else if (press_x > 800 - sens && press_y < sens && event->x > 800 - sens && event->y < sens)
162 else if (press_x > 800 - sens && press_y > 480 - sens && event->x > 800 - sens && event->y > 480 - sens)
164 else if (press_x < sens && press_y > 480 - sens && event->x < sens && event->y > 480 - sens)
175 switch (cornerActions[corner]){
177 if (show_confirmbox("Save savestate?"))
181 if (show_confirmbox("Load savestate?"))
182 emu_load_state(state_slot);
191 if (show_confirmbox("Quit?"))
198 static void *displayThread(void *arg)
200 DBusConnection* system_bus = (DBusConnection*)osso_get_sys_dbus_connection(osso);
201 DBusMessage* msg = dbus_message_new_method_call("com.nokia.mce",
202 "/com/nokia/mce/request",
203 "com.nokia.mce.request",
204 "req_display_blanking_pause");
205 if (msg && system_bus) {
208 dbus_connection_send(system_bus, msg, NULL);
209 dbus_connection_flush(system_bus);
217 dbus_message_unref(msg);
224 void show_notification(char* text)
227 GtkWidget* banner = hildon_banner_show_information(GTK_WIDGET(window), NULL, text);
228 hildon_banner_set_timeout(HILDON_BANNER(banner), 3000);
230 DBusConnection* session_bus = (DBusConnection*)osso_get_dbus_connection(osso);
231 DBusMessageIter args;
232 DBusMessage*msg = dbus_message_new_method_call("org.freedesktop.Notifications",
233 "/org/freedesktop/Notifications",
234 "org.freedesktop.Notifications",
235 "SystemNoteInfoprint");
237 dbus_message_iter_init_append(msg, &args);
239 if (dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, ¶m)) {
240 dbus_connection_send(session_bus, msg, NULL);
241 dbus_connection_flush(session_bus);
243 dbus_message_unref(msg);
248 void show_messagebox(char* text)
254 dialog = gtk_message_dialog_new (GTK_WINDOW(window),
255 GTK_DIALOG_DESTROY_WITH_PARENT,
259 gtk_dialog_run (GTK_DIALOG (dialog));
260 gtk_widget_destroy (dialog);
263 #include <hildon/hildon-file-chooser-dialog.h>
267 dialog = hildon_file_chooser_dialog_new (GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_OPEN);
268 gtk_window_set_title (GTK_WINDOW (dialog), "Change disc");
270 char currentFile[MAXPATHLEN];
271 strcpy(currentFile, GetIsoFile());
272 if (strlen(currentFile))
273 gtk_file_chooser_set_filename (GTK_FILE_CHOOSER(dialog), currentFile);
275 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog), "/home/user/MyDocs/");
277 GtkFileFilter *filter=gtk_file_filter_new();
278 gtk_file_filter_add_pattern (filter,"*.bin");
279 gtk_file_filter_add_pattern (filter,"*.BIN");
280 gtk_file_filter_add_pattern (filter,"*.iso");
281 gtk_file_filter_add_pattern (filter,"*.ISO");
282 gtk_file_filter_add_pattern (filter,"*.img");
283 gtk_file_filter_add_pattern (filter,"*.IMG");
284 gtk_file_filter_add_pattern (filter,"*.z");
285 gtk_file_filter_add_pattern (filter,"*.Z");
286 gtk_file_filter_add_pattern (filter,"*.znx");
287 gtk_file_filter_add_pattern (filter,"*.ZNX");
288 gtk_file_filter_add_pattern (filter,"*.pbp");
289 gtk_file_filter_add_pattern (filter,"*.PBP");
290 gtk_file_filter_add_pattern (filter,"*.mdf");
291 gtk_file_filter_add_pattern (filter,"*.MDF");
292 gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog),filter);
294 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
295 char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
297 //if (strcmp(filename, currentFile)) {
299 CdromLabel[0] = '\0';
301 set_cd_image(filename);
302 if (ReloadCdromPlugin() < 0)
303 printf("Failed to load cdr plugin\n");
306 printf("Failed to open cdr plugin\n");
308 strcpy(file_name, strrchr(filename,'/'));
310 SetCdOpenCaseTime(time(NULL) + 3);
316 gtk_widget_destroy (dialog);
319 void change_multi_disc()
321 HildonDialog* window = HILDON_DIALOG(hildon_dialog_new());
322 gtk_window_set_title (GTK_WINDOW (window), "Change disc");
323 gtk_window_set_default_size(GTK_WINDOW (window), 480, 300);
325 GtkWidget* sw = hildon_pannable_area_new ();
326 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(window)->vbox), sw, TRUE, TRUE, 0);
328 GtkWidget* tree_view = hildon_gtk_tree_view_new (HILDON_UI_MODE_EDIT);
329 gtk_widget_set_name (tree_view, "fremantle-widget");
331 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE);
334 GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING);
335 for (i = 0; i < cdrIsoMultidiskCount; i++) {
338 str = g_strdup_printf ("Disc %d", i+1);
339 gtk_list_store_insert_with_values (store, NULL, i, 0, str, -1);
342 GtkTreeModel* model = GTK_TREE_MODEL (store);
344 gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), model);
345 g_object_unref (model);
347 GtkTreeSelection* selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
348 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
350 GtkCellRenderer* renderer = gtk_cell_renderer_text_new ();
351 g_object_set (renderer,
353 "weight", PANGO_WEIGHT_NORMAL,
356 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
363 sprintf(current, "%i", cdrIsoMultidiskSelect);
364 GtkTreePath* path = gtk_tree_path_new_from_string(current);
365 gtk_tree_selection_select_path (selection, path);
366 gtk_tree_path_free(path);
368 gtk_widget_set_size_request (tree_view, 480, 800);
369 gtk_container_add (GTK_CONTAINER (sw), tree_view);
371 hildon_dialog_add_button (HILDON_DIALOG(window), GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
373 gtk_widget_show_all (GTK_WIDGET(window));
374 gint result = gtk_dialog_run (GTK_DIALOG (window));
375 if (result == GTK_RESPONSE_ACCEPT) {
378 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
379 if (gtk_tree_selection_get_selected(selection, &model, &iter)){
380 GtkTreePath* path = gtk_tree_model_get_path(model , &iter);
381 int* i = gtk_tree_path_get_indices(path) ;
383 cdrIsoMultidiskSelect = *i;
385 CdromLabel[0] = '\0';
388 if (CDR_open() < 0) {
389 printf("Failed to load cdr plugin\n");
393 SetCdOpenCaseTime(time(NULL) + 3);
397 gtk_widget_destroy(GTK_WIDGET(window));
400 static DBusHandlerResult on_msg_recieved(DBusConnection* connection G_GNUC_UNUSED, DBusMessage* message, void* data)
402 const char* path = dbus_message_get_path(message);
403 if (path && g_str_equal(path, CALL_SIGNAL_PATH)){
404 const char* mbr = dbus_message_get_member(message);
405 if (mbr && g_str_equal(mbr, CALL_INCOMING_SIG))
406 show_messagebox("Paused");
409 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
413 window_key_proxy(GtkWidget *widget,
417 key_press_event(event->hardware_keycode, event->type == GDK_KEY_PRESS ? 1 : (event->type == GDK_KEY_RELEASE ? 2 : 0) );
420 int last_key_pressed = 0;
421 inline void key_press_event(int key2,int type)
423 int psxkey1 = -1, psxkey2 = -1;
424 int key=keymap[key2];
429 if (type == 1 && key2 == last_key_pressed)
431 last_key_pressed = type == 1 ? key2 : 0;
433 //printf("Key: %i %s\n", key2, type == 1 ? "Pressed" : (type == 2 ? "Released" : "Unknown"));
434 if (key < ARRAY_SIZE(keymap2)){
435 psxkey1 = keymap2[key];
446 psxkey2 = DKEY_RIGHT;
454 psxkey2 = DKEY_RIGHT;
462 emu_load_state(state_slot);
474 if (cdrIsoMultidiskCount > 1)
482 if (in_type1 == PSE_PAD_TYPE_GUNCON){
486 in_state_gun |= SACTION_GUN_A;
489 in_state_gun |= SACTION_GUN_B;
492 in_state_gun |= SACTION_GUN_TRIGGER2;
495 in_state_gun |= SACTION_GUN_TRIGGER;
498 }else if (type == 2) {
501 in_state_gun &= ~SACTION_GUN_A;
504 in_state_gun &= ~SACTION_GUN_B;
507 in_state_gun &= ~SACTION_GUN_TRIGGER2;
510 in_state_gun &= ~SACTION_GUN_TRIGGER;
517 in_keystate |= 1 << psxkey1;
519 in_keystate |= 1 << psxkey2;
521 if (in_type1 == PSE_PAD_TYPE_ANALOGPAD){
538 else if (type == 2) {
540 in_keystate &= ~(1 << psxkey1);
542 in_keystate &= ~(1 << psxkey2);
544 if (in_type1 == PSE_PAD_TYPE_ANALOGPAD){
556 emu_set_action(SACTION_NONE);
566 void set_accel_multipliers()
568 accelOptions.xMultiplier = 255.0 / ( (accelOptions.maxValue - accelOptions.sens) * 2.0);
569 accelOptions.yMultiplier = 255.0 / ( (accelOptions.maxValue - accelOptions.sens) * 2.0);
572 #include <gdk/gdkx.h>
573 int maemo_init(int *argc, char ***argv)
575 osso = osso_initialize("pcsxrearmed", PACKAGE_VERSION, FALSE, NULL);
577 DBusConnection* system_bus = (DBusConnection*)osso_get_sys_dbus_connection(osso);
578 dbus_bus_add_match(system_bus, DBUS_RULE_CALL_INCOMING, NULL);
579 dbus_connection_add_filter(system_bus, on_msg_recieved, NULL, NULL);
582 pFile = fopen(keys_config_file, "r");
584 fprintf(stderr, "Error opening keys config file %s\n", keys_config_file);
587 printf("Keys config read from %s\n", keys_config_file);
591 for (i=0;i<65536;i++)
595 fscanf(pFile, "%i",&ch);
598 direction_keys[i] = ch;
604 case PSE_PAD_TYPE_GUNCON:
605 memset(cornerActions, 0, sizeof(cornerActions));
606 printf("Controller set to GUNCON (SLPH-00034)\n");
608 case PSE_PAD_TYPE_STANDARD:
609 printf("Controller set to standard (SCPH-1080)\n");
611 case PSE_PAD_TYPE_ANALOGPAD:
612 printf("Controller set to analog (SCPH-1150)\n");
616 if (in_enable_vibration)
617 printf("Vibration enabled\n");
619 if (!(g_maemo_opts&8)){
620 gtk_init (argc, argv);
622 window = hildon_stackable_window_new ();
623 gtk_widget_realize (window);
624 gtk_window_fullscreen (GTK_WINDOW(window));
626 if (cornerActions[0] + cornerActions[1] + cornerActions[2] + cornerActions[3] > 0){
627 g_signal_connect (G_OBJECT (window), "button_release_event",
628 G_CALLBACK (window_button_proxy), NULL);
629 g_signal_connect (G_OBJECT (window), "button_press_event",
630 G_CALLBACK (window_button_proxy), NULL);
633 g_signal_connect (G_OBJECT (window), "key-press-event",
634 G_CALLBACK (window_key_proxy), NULL);
635 g_signal_connect (G_OBJECT (window), "key-release-event",
636 G_CALLBACK (window_key_proxy), NULL);
637 g_signal_connect (G_OBJECT (window), "delete_event",
638 G_CALLBACK (hildon_quit), NULL);
639 gtk_widget_add_events (window,
640 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
642 actor = HILDON_ANIMATION_ACTOR (hildon_animation_actor_new());
643 if (g_maemo_opts & 2)
644 hildon_animation_actor_set_position (actor, 0, 0 );
646 hildon_animation_actor_set_position (actor, (X_RES - D_WIDTH)/2, (Y_RES - D_HEIGHT)/2 );
647 hildon_animation_actor_set_parent (actor, GTK_WINDOW (window));
649 drawing = gtk_image_new ();
651 gtk_container_add (GTK_CONTAINER (actor), drawing);
653 gtk_widget_show_all (GTK_WIDGET (actor));
654 gtk_widget_show_all (GTK_WIDGET (window));
656 gtk_init (argc, argv);
657 /*GdkScreen* scr = gdk_screen_get_default();
658 window = GTK_WIDGET(gdk_screen_get_root_window(scr));
660 window = GTK_WIDGET(gdk_get_default_root_window());*/
663 set_accel_multipliers();
666 if (pthread_create(&display_thread, NULL, displayThread, NULL))
667 printf("Failed to create display thread.\n");
670 pl_rearmed_cbs.only_16bpp = 1;
676 if (display_thread > 0){
678 pthread_join(display_thread, NULL);
682 osso_deinitialize(osso);
692 void *plat_gvideo_set_mode(int *w_, int *h_, int *bpp_)
694 int w = *w_, h = *h_;
696 if (g_maemo_opts&8) return pl_vout_buf;
697 //printf("Setting video mode %ix%i\n", w, h);
699 if (w <= 0 || h <= 0)
702 if (image) gdk_image_destroy(image);
703 image = gdk_image_new( GDK_IMAGE_FASTEST, gdk_visual_get_system(), w, h );
705 pl_vout_buf = (void *) image->mem;
707 gtk_image_set_from_image (GTK_IMAGE(drawing), image, NULL);
709 gtk_window_resize (GTK_WINDOW (actor), w, h);
710 if (g_maemo_opts & 2)
711 hildon_animation_actor_set_scale (actor,
712 (gdouble)800 / (gdouble)w,
713 (gdouble)480 / (gdouble)h
716 hildon_animation_actor_set_scale (actor,
717 (gdouble)D_WIDTH / (gdouble)w,
718 (gdouble)D_HEIGHT / (gdouble)h
720 pl_buf_w=w;pl_buf_h=h;
724 void *plat_gvideo_flip(void)
726 if (!(g_maemo_opts&8))
727 gtk_widget_queue_draw(drawing);
729 // process accelometer
730 if (g_maemo_opts & 4) {
732 FILE* f = fopen( "/sys/class/i2c-adapter/i2c-3/3-001d/coord", "r" );
733 if( !f ) {printf ("err in accel"); exit(1);}
734 fscanf( f, "%f %f %f", &x, &y, &z );
737 if (in_type1 == PSE_PAD_TYPE_ANALOGPAD){
738 if (x > accelOptions.maxValue) x = accelOptions.maxValue;
739 else if (x < -accelOptions.maxValue) x = -accelOptions.maxValue;
741 const int maxValue = accelOptions.maxValue - accelOptions.sens;
742 if(x > accelOptions.sens){
743 x -= accelOptions.sens;
744 in_a1[0] = (-x + maxValue ) * accelOptions.xMultiplier;
745 }else if (x < -accelOptions.sens){
746 x += accelOptions.sens;
747 in_a1[0] = (-x + maxValue ) * accelOptions.xMultiplier;
748 }else in_a1[0] = 127;
750 y += accelOptions.y_def;
751 if (y > accelOptions.maxValue) y = accelOptions.maxValue;
752 else if (y < -accelOptions.maxValue) y = -accelOptions.maxValue;
754 if(y > accelOptions.sens){
755 y -= accelOptions.sens;
756 in_a1[1] = (-y + maxValue ) * accelOptions.yMultiplier;
757 }else if (y < -accelOptions.sens){
758 y += accelOptions.sens;
759 in_a1[1] = (-y + maxValue ) * accelOptions.yMultiplier;
760 }else in_a1[1] = 127;
762 //printf("x: %i y: %i\n", in_a1[0], in_a1[1]);
764 if( x > accelOptions.sens ) in_keystate |= 1 << DKEY_LEFT;
765 else if( x < -accelOptions.sens ) in_keystate |= 1 << DKEY_RIGHT;
766 else {in_keystate &= ~(1 << DKEY_LEFT);in_keystate &= ~(1 << DKEY_RIGHT);}
768 y += accelOptions.y_def;
769 if( y > accelOptions.sens )in_keystate |= 1 << DKEY_UP;
770 else if( y < -accelOptions.sens ) in_keystate |= 1 << DKEY_DOWN;
771 else {in_keystate &= ~(1 << DKEY_DOWN);in_keystate &= ~(1 << DKEY_UP);}
778 // for frontend/plugin_lib.c
779 void update_input(void)
781 if (g_maemo_opts & 8)
782 maemo_x11_update_keys();
784 /* process GTK+ events */
785 while (gtk_events_pending())
786 gtk_main_iteration();
790 int omap_enable_layer(int enabled)
795 void menu_notify_mode_change(int w, int h, int bpp)
799 void *plat_prepare_screenshot(int *w, int *h, int *bpp)
804 void plat_step_volume(int is_up)
808 void plat_trigger_vibrate(int pad, int low, int high)
810 const int vDuration = 10;
812 DBusConnection* system_bus = (DBusConnection*)osso_get_sys_dbus_connection(osso);
813 DBusMessageIter args;
814 DBusMessage*msg = dbus_message_new_method_call("com.nokia.mce",
815 "/com/nokia/mce/request",
816 "com.nokia.mce.request",
817 "req_start_manual_vibration");
819 dbus_message_iter_init_append(msg, &args);
820 // FIXME: somebody with hardware should tune this
821 int speed = high; // is_strong ? 200 : 150;
822 int duration = vDuration;
823 if (dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &speed)) {
824 if (dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &duration)) {
825 dbus_connection_send(system_bus, msg, NULL);
826 //dbus_connection_flush(system_bus);
829 dbus_message_unref(msg);
833 void plat_minimize(void)
837 void plat_gvideo_close(void)
841 void plat_gvideo_open(int is_pal)