forked from Cpasjuste/uae4all2
-
Notifications
You must be signed in to change notification settings - Fork 10
/
sdlgfx.cpp
executable file
·934 lines (865 loc) · 23 KB
/
sdlgfx.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
/*
* UAE - The Un*x Amiga Emulator
*
* SDL interface
*
* Copyright 2001 Bernd Lachner (EMail: dev@lachner-net.de)
*
* Partialy based on the UAE X interface (xwin.c)
*
* Copyright 1995, 1996 Bernd Schmidt
* Copyright 1996 Ed Hanway, Andre Beck, Samuel Devulder, Bruno Coste
* Copyright 1998 Marcus Sundberg
* DGA support by Kai Kollmorgen
* X11/DGA merge, hotkeys and grabmouse by Marcus Sundberg
*/
#include "sysconfig.h"
#include "sysdeps.h"
#include <unistd.h>
#include <signal.h>
#include <SDL.h>
#include <SDL_endian.h>
#include "config.h"
#include "uae.h"
#include "options.h"
#include "memory-uae.h"
#include "xwin.h"
#include "custom.h"
#include "drawing.h"
#include "m68k/m68k_intrf.h"
#include "keyboard.h"
#include "keybuf.h"
#include "gui.h"
#include "debug.h"
#ifdef USE_UAE4ALL_VKBD
#include "vkbd.h"
#endif
#include "gp2x.h"
#include "gp2xutil.h"
#include "inputmode.h"
#include "menu_config.h"
#include "menu.h"
#include "savestate.h"
#include "rpt.h"
#include "events.h"
#if defined(__PSP2__) || defined(__SWITCH__)
#define SDL_PollEvent PSP2_PollEvent
#endif
#ifdef __PSP2__ // NOT __SWITCH__
#include "psp2/psp2_touch.h"
#endif
#ifdef __SWITCH__
#include "switch/switch_touch.h"
#endif
bool mouse_state = true;
#if defined(__PSP2__) || defined(__SWITCH__)
extern bool slow_mouse;
extern bool fast_mouse;
#else
bool slow_mouse = false;
#endif
extern int moved_x;
extern int moved_y;
extern int stylusClickOverride;
int mouseMoving = 0;
int justClicked = 0;
int fcounter = 0;
extern int stylusAdjustX;
extern int stylusAdjustY;
int doStylusRightClick = 0;
extern int gp2xMouseEmuOn;
extern int gp2xButtonRemappingOn;
#ifndef PANDORA
extern int hasGp2xButtonRemapping;
#endif
int show_inputmode = 0;
int show_volumecontrol;
extern int soundVolume;
extern int drawfinished;
int prefs_gfx_framerate, changed_gfx_framerate;
uae_u16 *prSDLScreenPixels;
char *gfx_mem=NULL;
unsigned gfx_rowbytes=0;
Uint32 uae4all_numframes=0;
#define VIDEO_FLAGS_INIT SDL_SWSURFACE|SDL_FULLSCREEN
#ifdef ANDROIDSDL
#define VIDEO_FLAGS VIDEO_FLAGS_INIT
#else
#define VIDEO_FLAGS VIDEO_FLAGS_INIT | SDL_DOUBLEBUF
#endif
/* Uncomment for debugging output */
/* #define DEBUG */
/* SDL variable for output surface */
SDL_Surface *prSDLScreen = NULL;
static int red_bits, green_bits, blue_bits;
static int red_shift, green_shift, blue_shift;
static SDL_Color arSDLColors[256];
static int ncolors = 0;
/* Keyboard and mouse */
int uae4all_keystate[256];
static int shiftWasPressed = 0;
#ifdef PANDORA
#define SIMULATE_SHIFT 0x200
#define SIMULATE_RELEASED_SHIFT 0x400
#endif
static unsigned long previous_synctime = 0;
static unsigned long next_synctime = 0;
void flush_block ()
{
#if !defined(__PSP2__) //no need to unlock screen on Vita unless we have to
SDL_UnlockSurface(prSDLScreen);
#endif
#ifdef USE_UAE4ALL_VKBD //draw vkbd and process user input
#if defined(__PSP2__) //even on Vita, vkbd blitting requires unlock/lock
if (vkbd_mode)
{
SDL_UnlockSurface(prSDLScreen);
vkbd_key=vkbd_process();
SDL_LockSurface(prSDLScreen);
}
#else
if (vkbd_mode)
vkbd_key=vkbd_process();
#endif
#endif
if (show_inputmode)
inputmode_redraw();
if (drawfinished)
{
drawfinished=0;
if (savestate_state == STATE_DOSAVE)
{
#if defined(__PSP2__)
SDL_UnlockSurface(prSDLScreen);
CreateScreenshot(SCREENSHOT);
SDL_LockSurface(prSDLScreen);
#else
CreateScreenshot(SCREENSHOT);
#endif
}
unsigned long start = read_processor_time();
if(start < next_synctime && next_synctime - start > time_per_frame - 1000)
#if defined(__PSP2__)
SDL_Delay(((next_synctime - start) - 1000) / 1000);
#else
usleep((next_synctime - start) - 1000);
#endif
SDL_Flip(prSDLScreen);
last_synctime = read_processor_time();
if(last_synctime - next_synctime > time_per_frame - 1000)
adjust_idletime(0);
else
adjust_idletime(next_synctime - start);
if(last_synctime - next_synctime > time_per_frame - 5000)
next_synctime = last_synctime + time_per_frame * (1 + prefs_gfx_framerate);
else
next_synctime = next_synctime + time_per_frame * (1 + prefs_gfx_framerate);
}
#if defined(__SWITCH__)
SDL_LockSurface (prSDLScreen);
#endif
#if !defined(__PSP2__) && !defined(__SWITCH__)
SDL_LockSurface (prSDLScreen);
if(stylusClickOverride)
{
justClicked = 0;
mouseMoving = 0;
}
else
{
if(justClicked)
{
buttonstate[0] = 0;
buttonstate[2] = 0;
justClicked = 0;
}
if(mouseMoving)
{
if(fcounter >= mainMenu_tapDelay)
{
if(doStylusRightClick)
{
buttonstate[2] = 1;
}
else
{
buttonstate[0] = 1;
mouseMoving = 0;
justClicked = 1;
fcounter = 0;
}
}
fcounter++;
}
}
#endif // __PSP2__
init_row_map();
}
void black_screen_now(void)
{
SDL_FillRect(prSDLScreen,NULL,0);
SDL_Flip(prSDLScreen);
}
static __inline__ int bitsInMask (unsigned long mask)
{
/* count bits in mask */
int n = 0;
while (mask)
{
n += mask & 1;
mask >>= 1;
}
return n;
}
static __inline__ int maskShift (unsigned long mask)
{
/* determine how far mask is shifted */
int n = 0;
while (!(mask & 1))
{
n++;
mask >>= 1;
}
return n;
}
static int get_color (int r, int g, int b, xcolnr *cnp)
{
*cnp = SDL_MapRGB(prSDLScreen->format, r, g, b);
arSDLColors[ncolors].r = r;
arSDLColors[ncolors].g = g;
arSDLColors[ncolors].b = b;
ncolors++;
return 1;
}
static int init_colors (void)
{
int i;
/* Truecolor: */
red_bits = bitsInMask(prSDLScreen->format->Rmask);
green_bits = bitsInMask(prSDLScreen->format->Gmask);
blue_bits = bitsInMask(prSDLScreen->format->Bmask);
red_shift = maskShift(prSDLScreen->format->Rmask);
green_shift = maskShift(prSDLScreen->format->Gmask);
blue_shift = maskShift(prSDLScreen->format->Bmask);
alloc_colors64k (red_bits, green_bits, blue_bits, red_shift, green_shift, blue_shift);
for (i = 0; i < 4096; i++)
xcolors[i] = xcolors[i] * 0x00010001;
return 1;
}
int graphics_setup (void)
{
/* Initialize the SDL library */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
return 0;
}
return 1;
}
static void graphics_subinit (void)
{
if (prSDLScreen == NULL)
{
fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError());
return;
}
else
{
prSDLScreenPixels=(uae_u16 *)prSDLScreen->pixels;
SDL_LockSurface(prSDLScreen);
SDL_UnlockSurface(prSDLScreen);
SDL_Flip(prSDLScreen);
SDL_ShowCursor(SDL_DISABLE);
/* Initialize structure for Amiga video modes */
gfx_mem = (char *)prSDLScreen->pixels;
gfx_rowbytes = prSDLScreen->pitch;
}
lastmx = lastmy = 0;
newmousecounters = 0;
}
int graphics_init (void)
{
int i,j;
// this will hold the state of the mouse emulation toggle. The start button
// will enable mouse emulation, which will allow the joystick to move the
// mouse point (probably badly, but there you go).
gp2xButtonRemappingOn = 0;
show_volumecontrol = 0;
graphics_subinit ();
check_all_prefs();
if (!init_colors ())
return 0;
buttonstate[0] = buttonstate[1] = buttonstate[2] = 0;
for (i = 256; i--;)
uae4all_keystate[i] = 0;
shiftWasPressed = 0;
return 1;
}
static void graphics_subshutdown (void)
{
#ifndef AROS
SDL_FreeSurface(prSDLScreen);
#endif
}
void graphics_leave (void)
{
graphics_subshutdown ();
SDL_VideoQuit();
dumpcustom ();
}
/* Decode KeySyms. This function knows about all keys that are common
* between different keyboard languages. */
static int kc_decode (SDL_keysym *prKeySym)
{
#ifdef PANDORA
// Special handling of Pandora keyboard:
// Some keys requires shift on Amiga, so we simulate shift...
switch (prKeySym->sym)
{
case SDLK_COLON:
return SIMULATE_SHIFT | AK_SEMICOLON;
case SDLK_QUESTION:
return SIMULATE_SHIFT | AK_SLASH;
case SDLK_HASH:
return SIMULATE_SHIFT | AK_3;
case SDLK_DOLLAR:
return SIMULATE_SHIFT | AK_4;
case SDLK_QUOTEDBL:
return SIMULATE_SHIFT | AK_QUOTE;
case SDLK_PLUS:
return SIMULATE_SHIFT | AK_EQUAL;
case SDLK_AT:
return SIMULATE_SHIFT | AK_2;
case SDLK_LEFTPAREN:
return SIMULATE_SHIFT | AK_9;
case SDLK_RIGHTPAREN:
return SIMULATE_SHIFT | AK_0;
case SDLK_EXCLAIM:
return SIMULATE_SHIFT | AK_1;
case SDLK_UNDERSCORE:
return SIMULATE_SHIFT | AK_MINUS;
case SDLK_2:
if(prKeySym->mod == KMOD_LSHIFT)
return SIMULATE_SHIFT | AK_LBRACKET;
break;
case SDLK_3:
if(prKeySym->mod == KMOD_LSHIFT)
return SIMULATE_SHIFT | AK_RBRACKET;
break;
case SDLK_4:
if(prKeySym->mod == KMOD_LSHIFT)
return SIMULATE_SHIFT | AK_BACKQUOTE;
break;
case SDLK_9:
if(prKeySym->mod == KMOD_LSHIFT)
return SIMULATE_RELEASED_SHIFT | AK_LBRACKET;
break;
case SDLK_0:
if(prKeySym->mod == KMOD_LSHIFT)
return SIMULATE_RELEASED_SHIFT | AK_RBRACKET;
break;
case 124: // code for '|'
return SIMULATE_SHIFT | AK_BACKSLASH;
}
#endif
switch (prKeySym->sym)
{
case SDLK_b: return AK_B;
case SDLK_c: return AK_C;
case SDLK_d: return AK_D;
case SDLK_e: return AK_E;
case SDLK_f: return AK_F;
case SDLK_g: return AK_G;
case SDLK_h: return AK_H;
case SDLK_i: return AK_I;
case SDLK_j: return AK_J;
case SDLK_k: return AK_K;
case SDLK_l: return AK_L;
case SDLK_n: return AK_N;
case SDLK_o: return AK_O;
case SDLK_p: return AK_P;
case SDLK_r: return AK_R;
case SDLK_s: return AK_S;
case SDLK_t: return AK_T;
case SDLK_u: return AK_U;
case SDLK_v: return AK_V;
case SDLK_x: return AK_X;
case SDLK_0: return AK_0;
case SDLK_1: return AK_1;
case SDLK_2: return AK_2;
case SDLK_3: return AK_3;
case SDLK_4: return AK_4;
case SDLK_5: return AK_5;
case SDLK_6: return AK_6;
case SDLK_7: return AK_7;
case SDLK_8: return AK_8;
case SDLK_9: return AK_9;
case SDLK_KP0: return AK_NP0;
case SDLK_KP1: return AK_NP1;
case SDLK_KP2: return AK_NP2;
case SDLK_KP3: return AK_NP3;
case SDLK_KP4: return AK_NP4;
case SDLK_KP5: return AK_NP5;
case SDLK_KP6: return AK_NP6;
case SDLK_KP7: return AK_NP7;
case SDLK_KP8: return AK_NP8;
case SDLK_KP9: return AK_NP9;
case SDLK_KP_DIVIDE: return AK_NPDIV;
case SDLK_KP_MULTIPLY: return AK_NPMUL;
case SDLK_KP_MINUS: return AK_NPSUB;
case SDLK_KP_PLUS: return AK_NPADD;
case SDLK_KP_PERIOD: return AK_NPDEL;
case SDLK_KP_ENTER: return AK_ENT;
case SDLK_F1: return AK_F1;
case SDLK_F2: return AK_F2;
case SDLK_F3: return AK_F3;
case SDLK_F4: return AK_F4;
case SDLK_F5: return AK_F5;
case SDLK_F6: return AK_F6;
case SDLK_F7: return AK_F7;
case SDLK_F8: return AK_F8;
case SDLK_F9: return AK_F9;
case SDLK_F10: return AK_F10;
case SDLK_BACKSPACE: return AK_BS;
case SDLK_DELETE: return AK_DEL;
case SDLK_LCTRL: return AK_CTRL;
case SDLK_RCTRL: return AK_RCTRL;
case SDLK_TAB: return AK_TAB;
case SDLK_LALT: return AK_LALT;
case SDLK_RALT: return AK_RALT;
case SDLK_LMETA: return AK_LAMI;
case SDLK_RMETA: return AK_RAMI;
case SDLK_RETURN: return AK_RET;
case SDLK_SPACE: return AK_SPC;
case SDLK_LSHIFT: return AK_LSH;
case SDLK_RSHIFT: return AK_RSH;
case SDLK_ESCAPE: return AK_ESC;
case SDLK_INSERT: return AK_HELP;
case SDLK_HOME: return AK_NPLPAREN;
case SDLK_END: return AK_NPRPAREN;
case SDLK_CAPSLOCK: return AK_CAPSLOCK;
case SDLK_UP: return AK_UP;
case SDLK_DOWN: return AK_DN;
case SDLK_LEFT: return AK_LF;
case SDLK_RIGHT: return AK_RT;
case SDLK_PAGEDOWN: return AK_LAMI; /* PgDn mapped to left amiga */
case SDLK_PAGEUP: return AK_RAMI; /* PgUp mapped to right amiga */
default: return -1;
}
}
static int decode_us (SDL_keysym *prKeySym)
{
switch(prKeySym->sym)
{
/* US specific */
case SDLK_a: return AK_A;
case SDLK_m: return AK_M;
case SDLK_q: return AK_Q;
case SDLK_y: return AK_Y;
case SDLK_w: return AK_W;
case SDLK_z: return AK_Z;
case SDLK_LEFTBRACKET: return AK_LBRACKET;
case SDLK_RIGHTBRACKET: return AK_RBRACKET;
case SDLK_COMMA: return AK_COMMA;
case SDLK_PERIOD: return AK_PERIOD;
case SDLK_SLASH: return AK_SLASH;
case SDLK_SEMICOLON: return AK_SEMICOLON;
case SDLK_MINUS: return AK_MINUS;
case SDLK_EQUALS: return AK_EQUAL;
/* this doesn't work: */
case SDLK_BACKQUOTE: return AK_QUOTE;
case SDLK_QUOTE: return AK_BACKQUOTE;
case SDLK_BACKSLASH: return AK_BACKSLASH;
default: return -1;
}
}
int keycode2amiga(SDL_keysym *prKeySym)
{
int iAmigaKeycode = kc_decode(prKeySym);
if (iAmigaKeycode == -1)
return decode_us(prKeySym);
return iAmigaKeycode;
}
static int refresh_necessary = 0;
void handle_events (void)
{
SDL_Event rEvent;
int iAmigaKeyCode;
int i, j;
int iIsHotKey = 0;
/* Handle GUI events */
gui_handle_events ();
#if defined(__PSP2__) || defined(__SWITCH__)
/* SDL events on PSP2 with all keyboard/mouse inputs for BT keyboard and mouse, and touch */
#ifdef __PSP2__ // NOT __SWITCH__
if (mainMenu_touchControls) {
psp2PollTouch();
}
#endif
#ifdef __SWITCH__
// need to call this once per frame
if (mainMenu_touchControls)
SWITCH_FinishSimulatedMouseClicks();
#endif
while (SDL_PollEvent(&rEvent))
{
#ifdef __SWITCH__
if (mainMenu_touchControls)
SWITCH_HandleTouch(&rEvent);
#endif
switch (rEvent.type)
{
case SDL_QUIT:
uae_quit();
break;
case SDL_KEYDOWN:
iAmigaKeyCode = keycode2amiga(&(rEvent.key.keysym));
if (iAmigaKeyCode >= 0)
{
if (!uae4all_keystate[iAmigaKeyCode])
{
uae4all_keystate[iAmigaKeyCode] = 1;
record_key(iAmigaKeyCode << 1);
}
}
break;
case SDL_KEYUP:
{
iAmigaKeyCode = keycode2amiga(&(rEvent.key.keysym));
if (iAmigaKeyCode >= 0)
{
uae4all_keystate[iAmigaKeyCode] = 0;
record_key((iAmigaKeyCode << 1) | 1);
}
}
break;
case SDL_MOUSEBUTTONDOWN:
buttonstate[(rEvent.button.button-1)%3] = 1;
break;
case SDL_MOUSEBUTTONUP:
buttonstate[(rEvent.button.button-1)%3] = 0;
break;
case SDL_MOUSEMOTION:
mouse_state = true;
int mouseScale = mainMenu_mouseMultiplier * 16;
mouseScale /= 100;
if (fast_mouse) mouseScale *= 3;
if (slow_mouse) mouseScale /= 8;
lastmx += rEvent.motion.xrel * mouseScale;
lastmy += rEvent.motion.yrel * mouseScale;
if(rEvent.motion.x == 0)
lastmx -= mouseScale * 4;
if(rEvent.motion.y == 0)
lastmy -= mouseScale * 4;
if(rEvent.motion.x == visibleAreaWidth-1)
lastmx += mouseScale * 4;
if(rEvent.motion.y == mainMenu_displayedLines-1)
lastmy += mouseScale * 4;
newmousecounters = 1;
break;
}
}
#else
/* Event handling on non-PSP2 systems involves special hooks for certain keys */
while (SDL_PollEvent(&rEvent))
{
switch (rEvent.type)
{
case SDL_QUIT:
uae_quit();
break;
case SDL_KEYDOWN:
if(rEvent.key.keysym.sym==SDLK_PAGEUP)
slow_mouse=true;
if(gp2xMouseEmuOn)
{
if(rEvent.key.keysym.sym==SDLK_RSHIFT)
{
uae4all_keystate[AK_LALT] = 1;
record_key(AK_LALT << 1);
}
if(rEvent.key.keysym.sym==SDLK_RCTRL || rEvent.key.keysym.sym==SDLK_END || rEvent.key.keysym.sym==SDLK_HOME)
{
uae4all_keystate[AK_RALT] = 1;
record_key(AK_RALT << 1);
}
if(rEvent.key.keysym.sym==SDLK_PAGEDOWN)
{
uae4all_keystate[AK_DN] = 1;
record_key(AK_DN << 1);
}
}
#ifdef ANDROIDSDL
if (rEvent.key.keysym.sym==SDLK_F11)
#else
if (rEvent.key.keysym.sym==SDLK_LALT)
#endif
{
#ifdef USE_UAE4ALL_VKBD
if (!vkbd_mode)
#endif
{
// only do this if the virtual keyboard isn't visible
// state moves thus:
// joystick mode (with virt keyboard on L and R)
// mouse mode (with mouse buttons on L and R)
// if specified:
// remapping mode (with whatever's been supplied)
// back to start of state
#ifndef PANDORA
if (!hasGp2xButtonRemapping)
{
// skip the remapping state
gp2xMouseEmuOn = !gp2xMouseEmuOn;
}
else
{
#endif
// start condition is gp2xMouseEmuOn = 0, gp2xButtonRemappingOn = 0
if (!gp2xButtonRemappingOn && !gp2xMouseEmuOn)
{
// move to mouse emu mode
gp2xMouseEmuOn = 1;
gp2xButtonRemappingOn = 0;
}
else if (gp2xMouseEmuOn && !gp2xButtonRemappingOn)
{
// move to button remapping mode
gp2xMouseEmuOn = 0;
gp2xButtonRemappingOn = 1;
}
else if (!gp2xMouseEmuOn && gp2xButtonRemappingOn)
{
gp2xMouseEmuOn = 0;
gp2xButtonRemappingOn = 0;
}
if (!gp2xMouseEmuOn)
togglemouse();
#ifndef PANDORA
}
#endif
show_inputmode = 1;
}
}
#ifdef USE_UAE4ALL_VKBD
else if ((!gp2xMouseEmuOn) && (!gp2xButtonRemappingOn) && (!vkbd_mode) && (vkbd_button2!=(SDLKey)0))
{
if (vkbd_button2) // button2 keyboard was a planned feature, not yet implemented
rEvent.key.keysym.sym=vkbd_button2;
else
break;
}
#endif //UAE_UAE4ALL_VKBD
#ifndef PANDORA
if (gp2xButtonRemappingOn)
#endif
{
if (rEvent.key.keysym.sym==SDLK_RSHIFT || rEvent.key.keysym.sym==SDLK_RCTRL)
doStylusRightClick = 1;
}
if (rEvent.key.keysym.sym!=SDLK_UP && rEvent.key.keysym.sym!=SDLK_DOWN && rEvent.key.keysym.sym!=SDLK_LEFT &&
rEvent.key.keysym.sym!=SDLK_RIGHT && rEvent.key.keysym.sym!=SDLK_PAGEUP && rEvent.key.keysym.sym!=SDLK_PAGEDOWN &&
#ifdef ANDROIDSDL
rEvent.key.keysym.sym!=SDLK_HOME && rEvent.key.keysym.sym!=SDLK_END && rEvent.key.keysym.sym!=SDLK_F11 &&
rEvent.key.keysym.sym!=SDLK_F12 && rEvent.key.keysym.sym!=SDLK_F13 && rEvent.key.keysym.sym!=SDLK_RCTRL)
#else
rEvent.key.keysym.sym!=SDLK_HOME && rEvent.key.keysym.sym!=SDLK_END && rEvent.key.keysym.sym!=SDLK_LALT &&
rEvent.key.keysym.sym!=SDLK_LCTRL && rEvent.key.keysym.sym!=SDLK_RSHIFT && rEvent.key.keysym.sym!=SDLK_RCTRL)
#endif
{
iAmigaKeyCode = keycode2amiga(&(rEvent.key.keysym));
if (iAmigaKeyCode >= 0)
{
#ifdef PANDORA
if(iAmigaKeyCode & SIMULATE_SHIFT)
{
// We need to simulate shift
iAmigaKeyCode = iAmigaKeyCode & 0x1ff;
shiftWasPressed = uae4all_keystate[AK_LSH];
if(!shiftWasPressed)
{
uae4all_keystate[AK_LSH] = 1;
record_key(AK_LSH << 1);
}
}
if(iAmigaKeyCode & SIMULATE_RELEASED_SHIFT)
{
// We need to simulate released shift
iAmigaKeyCode = iAmigaKeyCode & 0x1ff;
shiftWasPressed = uae4all_keystate[AK_LSH];
if(shiftWasPressed)
{
uae4all_keystate[AK_LSH] = 0;
record_key((AK_LSH << 1) | 1);
}
}
#endif
if (!uae4all_keystate[iAmigaKeyCode])
{
uae4all_keystate[iAmigaKeyCode] = 1;
record_key(iAmigaKeyCode << 1);
}
}
}
break;
case SDL_KEYUP:
if(rEvent.key.keysym.sym==SDLK_PAGEUP)
slow_mouse = false;
if(gp2xMouseEmuOn)
{
if(rEvent.key.keysym.sym==SDLK_RSHIFT)
{
uae4all_keystate[AK_LALT] = 0;
record_key((AK_LALT << 1) | 1);
}
if(rEvent.key.keysym.sym==SDLK_RCTRL || rEvent.key.keysym.sym==SDLK_END || rEvent.key.keysym.sym==SDLK_HOME)
{
uae4all_keystate[AK_RALT] = 0;
record_key((AK_RALT << 1) | 1);
}
if(rEvent.key.keysym.sym==SDLK_PAGEDOWN)
{
uae4all_keystate[AK_DN] = 0;
record_key((AK_DN << 1) | 1);
}
}
#ifndef PANDORA
if (gp2xButtonRemappingOn)
#endif
{
if (rEvent.key.keysym.sym==SDLK_RSHIFT || rEvent.key.keysym.sym==SDLK_RCTRL)
{
doStylusRightClick = 0;
mouseMoving = 0;
justClicked = 0;
fcounter = 0;
buttonstate[2] = 0;
}
}
#ifdef ANDROIDSDL
if (rEvent.key.keysym.sym==SDLK_F11)
#else
if (rEvent.key.keysym.sym==SDLK_LALT)
#endif
{
show_inputmode = 0;
}
if (rEvent.key.keysym.sym!=SDLK_UP && rEvent.key.keysym.sym!=SDLK_DOWN && rEvent.key.keysym.sym!=SDLK_LEFT &&
rEvent.key.keysym.sym!=SDLK_RIGHT && rEvent.key.keysym.sym!=SDLK_PAGEUP && rEvent.key.keysym.sym!=SDLK_PAGEDOWN &&
#ifdef ANDROIDSDL
rEvent.key.keysym.sym!=SDLK_HOME && rEvent.key.keysym.sym!=SDLK_END && rEvent.key.keysym.sym!=SDLK_F11 &&
rEvent.key.keysym.sym!=SDLK_F12 && rEvent.key.keysym.sym!=SDLK_F13 && rEvent.key.keysym.sym!=SDLK_RCTRL)
#else
rEvent.key.keysym.sym!=SDLK_HOME && rEvent.key.keysym.sym!=SDLK_END && rEvent.key.keysym.sym!=SDLK_LALT &&
rEvent.key.keysym.sym!=SDLK_LCTRL && rEvent.key.keysym.sym!=SDLK_RSHIFT && rEvent.key.keysym.sym!=SDLK_RCTRL)
#endif
{
iAmigaKeyCode = keycode2amiga(&(rEvent.key.keysym));
if (iAmigaKeyCode >= 0)
{
#ifdef PANDORA
if(iAmigaKeyCode & SIMULATE_SHIFT)
{
// We needed to simulate shift
iAmigaKeyCode = iAmigaKeyCode & 0x1ff;
if(!shiftWasPressed)
{
uae4all_keystate[AK_LSH] = 0;
record_key((AK_LSH << 1) | 1);
shiftWasPressed = 0;
}
}
if(iAmigaKeyCode & SIMULATE_RELEASED_SHIFT)
{
// We needed to simulate released shift
iAmigaKeyCode = iAmigaKeyCode & 0x1ff;
if(shiftWasPressed)
{
uae4all_keystate[AK_LSH] = 1;
record_key(AK_LSH << 1);
shiftWasPressed = 0;
}
}
#endif
uae4all_keystate[iAmigaKeyCode] = 0;
record_key((iAmigaKeyCode << 1) | 1);
}
}
break;
case SDL_MOUSEBUTTONDOWN:
if (!gp2xButtonRemappingOn)
buttonstate[(rEvent.button.button-1)%3] = 1;
break;
case SDL_MOUSEBUTTONUP:
if (!gp2xButtonRemappingOn)
buttonstate[(rEvent.button.button-1)%3] = 0;
break;
case SDL_MOUSEMOTION:
mouse_state = true;
if(gp2xButtonRemappingOn)
{
lastmx = 16 * (rEvent.motion.x*2 - mainMenu_stylusOffset + moved_x + stylusAdjustX >> 1);
lastmy = 16 * (rEvent.motion.y*2 - mainMenu_stylusOffset + moved_y + stylusAdjustY >> 1);
//mouseMoving = 1;
}
else if(slow_mouse)
{
lastmx += 16 * rEvent.motion.xrel;
lastmy += 16 * rEvent.motion.yrel;
if(rEvent.motion.x == 0)
lastmx -= 2*16;
if(rEvent.motion.y == 0)
lastmy -= 2*16;
if(rEvent.motion.x == visibleAreaWidth-1)
lastmx += 2*16;
if(rEvent.motion.y == mainMenu_displayedLines-1)
lastmy += 2*16;
}
else
{
int mouseScale = mainMenu_mouseMultiplier * 4 * 16;
mouseScale /= 100;
lastmx += rEvent.motion.xrel * mouseScale;
lastmy += rEvent.motion.yrel * mouseScale;
if(rEvent.motion.x == 0)
lastmx -= mouseScale * 4;
if(rEvent.motion.y == 0)
lastmy -= mouseScale * 4;
if(rEvent.motion.x == visibleAreaWidth-1)
lastmx += mouseScale * 4;
if(rEvent.motion.y == mainMenu_displayedLines-1)
lastmy += mouseScale * 4;
}
newmousecounters = 1;
break;
}
}
#endif // __PSP2__
if (mouse_state==false)
{
mouse_x = 0;
mouse_y = 0;
newmousecounters = 1;
}
}
int needmousehack (void)
{
return 1;
}
int lockscr (void)
{
SDL_LockSurface(prSDLScreen);
return 1;
}
void unlockscr (void)
{
SDL_UnlockSurface(prSDLScreen);
}
void gui_purge_events(void)
{
SDL_Event event;
SDL_Delay(150);
while(SDL_PollEvent(&event))
SDL_Delay(10);
keybuf_init();
}