hatari-mapper.c 18.7 KB
Newer Older
R-type's avatar
R-type committed
1
2
3
4
5
#include "libretro.h"
#include "libretro-hatari.h"
#include "graph.h"
#include "vkbd.h"
#include "joy.h"
James D. Smith's avatar
James D. Smith committed
6
7
#include "screen.h"
#include "video.h"	/* FIXME: video.h is dependent on HBL_PALETTE_LINES from screen.h */
R-type's avatar
R-type committed
8
9
10
11
12
13

//CORE VAR
extern const char *retro_save_directory;
extern const char *retro_system_directory;
extern const char *retro_content_directory;
char RETRO_DIR[512];
DamsRoxxx's avatar
DamsRoxxx committed
14
char RETRO_TOS[512];
R-type's avatar
R-type committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

//HATARI PROTOTYPES
#include "configuration.h"
#include "file.h"
extern bool Dialog_DoProperty(void);
extern void Screen_SetFullUpdate(void);
extern void Main_HandleMouseMotion(void);
extern void Main_UnInit(void);
extern int  hmain(int argc, char *argv[]);
extern int Reset_Cold(void);

//TIME
#ifdef __CELLOS_LV2__
#include "sys/sys_time.h"
#include "sys/timer.h"
#define usleep  sys_timer_usleep
#else
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#endif

long frame=0;
markwkidd's avatar
markwkidd committed
38
static unsigned long Ktime=0, LastFPSTime=0;
R-type's avatar
R-type committed
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

//VIDEO
extern SDL_Surface *sdlscrn; 
unsigned short int bmp[1024*1024];
unsigned char savbkg[1024*1024* 2];

//SOUND
short signed int SNDBUF[1024*2];
int snd_sampler = 44100 / 50;

//PATH
char RPATH[512];

//EMU FLAGS
int NPAGE=-1, KCOL=1, BKGCOLOR=0, MAXPAS=6;
int SHIFTON=-1,MOUSEMODE=-1,NUMJOY=0,SHOWKEY=-1,PAS=4,STATUTON=-1;
int SND; //SOUND ON/OFF
static int firstps=0;
int pauseg=0; //enter_gui

//JOY
int al[2];//left analog1
int ar[2];//right analog1
unsigned char MXjoy0; // joy
int NUMjoy=1;

//MOUSE
int touch=-1; // gui mouse btn
int fmousex,fmousey; // emu mouse
extern int gmx,gmy; //gui mouse

//KEYBOARD
char Key_Sate[512];
char Key_Sate2[512];

static int mbt[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

//STATS GUI
extern int LEDA,LEDB,LEDC;
int BOXDEC= 32+2;
int STAT_BASEY;

static retro_input_state_t input_state_cb;
static retro_input_poll_t input_poll_cb;

void retro_set_input_state(retro_input_state_t cb)
{
   input_state_cb = cb;
}

void retro_set_input_poll(retro_input_poll_t cb)
{
   input_poll_cb = cb;
}

long GetTicks(void)
{ // in MSec
#ifndef _ANDROID_

#ifdef __CELLOS_LV2__

   //#warning "GetTick PS3\n"

   unsigned long	ticks_micro;
   uint64_t secs;
   uint64_t nsecs;

   sys_time_get_current_time(&secs, &nsecs);
   ticks_micro =  secs * 1000000UL + (nsecs / 1000);

   return ticks_micro/1000;
#else
   struct timeval tv;
   gettimeofday (&tv, NULL);
   return (tv.tv_sec*1000000 + tv.tv_usec)/1000;
#endif

#else

   struct timespec now;
   clock_gettime(CLOCK_MONOTONIC, &now);
   return (now.tv_sec*1000000 + now.tv_nsec/1000)/1000;
#endif

} 

Not6's avatar
Not6 committed
125
#ifdef WIIU
126
#include <os/time.h>
Not6's avatar
Not6 committed
127
128
retro_time_t current_tus=0,last_tus=0;
#endif
129
130
int slowdown=0;

R-type's avatar
R-type committed
131
132
133
//NO SURE FIND BETTER WAY TO COME BACK IN MAIN THREAD IN HATARI GUI
void gui_poll_events(void)
{
Not6's avatar
Not6 committed
134
#ifdef WIIU
135
  current_tus=OSGetSystemTime();
Not6's avatar
Not6 committed
136
137
138
139
140
141
142
143
144
145
  current_tus/=1000;

   if(current_tus - last_tus >= 1000/50)
   { 
      slowdown=0;
      frame++; 
      last_tus = current_tus;		
      co_switch(mainThread);
   }
#else
R-type's avatar
R-type committed
146
147
148
   Ktime = GetTicks();

   if(Ktime - LastFPSTime >= 1000/50)
149
150
   { 
	  slowdown=0;
R-type's avatar
R-type committed
151
152
153
154
      frame++; 
      LastFPSTime = Ktime;		
      co_switch(mainThread);
   }
Not6's avatar
Not6 committed
155
#endif
R-type's avatar
R-type committed
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
}

//save bkg for screenshot
void save_bkg(void)
{
   int i, j, k;	
   unsigned char *ptr;

   k = 0;
   ptr = (unsigned char*)sdlscrn->pixels;

   for(j=0;j<retroh;j++)
   {
      for(i=0;i<retrow*2;i++)
      {
         savbkg[k]=*ptr;
         ptr++;
         k++;
      }
   }
}

void retro_fillrect(SDL_Surface * surf,SDL_Rect *rect,unsigned int col)
{
   DrawFBoxBmp(bmp,rect->x,rect->y,rect->w ,rect->h,col); 
}

int  GuiGetMouseState( int * x,int * y)
{
   *x=gmx;
   *y=gmy;
   return 0;
}

void texture_uninit(void)
{
192
193
194
195
196
197
198
   if(sdlscrn)
   {
      if(sdlscrn->format)
         free(sdlscrn->format);

      free(sdlscrn);
   }
R-type's avatar
R-type committed
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
}

SDL_Surface *prepare_texture(int w,int h,int b)
{
   SDL_Surface *bitmp;

   if(sdlscrn)
      texture_uninit();

   bitmp = (SDL_Surface *) calloc(1, sizeof(*bitmp));
   if (bitmp == NULL)
   {
      printf("tex surface failed");
      return NULL;
   }

   bitmp->format = calloc(1,sizeof(*bitmp->format));
   if (bitmp->format == NULL)
   {
      printf("tex format failed");
      return NULL;
   }

   bitmp->format->BitsPerPixel = 16;
   bitmp->format->BytesPerPixel = 2;
   bitmp->format->Rloss=3;
   bitmp->format->Gloss=3;
   bitmp->format->Bloss=3;
   bitmp->format->Aloss=0;
   bitmp->format->Rshift=11;
   bitmp->format->Gshift=6;
   bitmp->format->Bshift=0;
   bitmp->format->Ashift=0;
   bitmp->format->Rmask=0x0000F800;
   bitmp->format->Gmask=0x000007E0;
   bitmp->format->Bmask=0x0000001F;
   bitmp->format->Amask=0x00000000;
   bitmp->format->colorkey=0;
   bitmp->format->alpha=0;
   bitmp->format->palette = NULL;

   bitmp->flags=0;
   bitmp->w=w;
   bitmp->h=h;
   bitmp->pitch=retrow*2;
   bitmp->pixels=(unsigned char *)&bmp[0];
   bitmp->clip_rect.x=0;
   bitmp->clip_rect.y=0;
   bitmp->clip_rect.w=w;
   bitmp->clip_rect.h=h;

   //printf("fin prepare tex:%dx%dx%d\n",bitmp->w,bitmp->h,bitmp->format->BytesPerPixel);
   return bitmp;
}      

void texture_init(void)
{
   memset(bmp, 0, sizeof(bmp));

   gmx=(retrow/2)-1;
   gmy=(retroh/2)-1;
}

void enter_gui(void)
{
   save_bkg();

   Dialog_DoProperty();
   pauseg=0;
}

void pause_select(void)
{
   if(pauseg==1 && firstps==0)
   {
      firstps=1;
      enter_gui();
      firstps=0;
   }
}

void Print_Statut(void)
{
   STAT_BASEY=CROP_HEIGHT;

   DrawFBoxBmp(bmp,0,CROP_HEIGHT,CROP_WIDTH,STAT_YSZ,RGB565(0,0,0));

   if(MOUSEMODE==-1)
      Draw_text(bmp,STAT_DECX,STAT_BASEY,0xffff,0x8080,1,2,40,"Joy  ");
   else
      Draw_text(bmp,STAT_DECX,STAT_BASEY,0xffff,0x8080,1,2,40,"Mouse");

   Draw_text(bmp,STAT_DECX+40 ,STAT_BASEY,0xffff,0x8080,1,2,40,(SHIFTON>0?"SHFT":""));
   Draw_text(bmp,STAT_DECX+80 ,STAT_BASEY,0xffff,0x8080,1,2,40,"MS:%d",PAS);
   Draw_text(bmp,STAT_DECX+120,STAT_BASEY,0xffff,0x8080,1,2,40,"Joy:%d",NUMjoy);

Libretro-Admin's avatar
Libretro-Admin committed
295
296
   if(LEDA)
   {
R-type's avatar
R-type committed
297
298
299
      DrawFBoxBmp(bmp,CROP_WIDTH-6*BOXDEC-6-16,CROP_HEIGHT-0,16,16,RGB565(0,7,0));//led A drive
      Draw_text(bmp,CROP_WIDTH-6*BOXDEC-6-16,CROP_HEIGHT-0,0xffff,0x0,1,2,40," A");
   }	
Libretro-Admin's avatar
Libretro-Admin committed
300
301
302

   if(LEDB)
   {
R-type's avatar
R-type committed
303
304
305
      DrawFBoxBmp(bmp,CROP_WIDTH-7*BOXDEC-6-16,CROP_HEIGHT-0,16,16,RGB565(0,7,0));//led B drive
      Draw_text(bmp,CROP_WIDTH-7*BOXDEC-6-16,CROP_HEIGHT-0,0xffff,0x0,1,2,40," B");
   }
Libretro-Admin's avatar
Libretro-Admin committed
306
307
308

   if(LEDC)
   {
R-type's avatar
R-type committed
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
      DrawFBoxBmp(bmp,CROP_WIDTH-8*BOXDEC-6-16,CROP_HEIGHT-0,16,16,RGB565(0,7,0));//led C drive
      Draw_text(bmp,CROP_WIDTH-8*BOXDEC-6-16,CROP_HEIGHT-0,0xffff,0x0,1,2,40," C");
      LEDC=0;
   }

}

void retro_key_down(unsigned char retrok)
{
   IKBD_PressSTKey(retrok,1); 
}

void retro_key_up(unsigned char retrok)
{
   IKBD_PressSTKey(retrok,0);
}

void Process_key(void)
{
   int i;
   for(i=0;i<320;i++)
   {
      Key_Sate[i]=input_state_cb(0, RETRO_DEVICE_KEYBOARD, 0,i) ? 0x80: 0;

      if(SDLKeyToSTScanCode[i]==0x2a )
      {  //SHIFT CASE

         if( Key_Sate[i] && Key_Sate2[i]==0 )
         {
            if(SHIFTON == 1)
               retro_key_up(	SDLKeyToSTScanCode[i] );					
            else if(SHIFTON == -1) 
               retro_key_down(SDLKeyToSTScanCode[i] );

            SHIFTON=-SHIFTON;

            Key_Sate2[i]=1;

         }
         else if ( !Key_Sate[i] && Key_Sate2[i]==1 )Key_Sate2[i]=0;

      }
      else
      {
         if(Key_Sate[i] && SDLKeyToSTScanCode[i]!=-1  && Key_Sate2[i]==0)
         {
            retro_key_down(	SDLKeyToSTScanCode[i] );
            Key_Sate2[i]=1;
         }
         else if ( !Key_Sate[i] && SDLKeyToSTScanCode[i]!=-1 && Key_Sate2[i]==1 )
         {
            retro_key_up( SDLKeyToSTScanCode[i] );
            Key_Sate2[i]=0;

         }

      }
   }

}


/*
   L2  show/hide Statut
   R2  swap kbd pages
   L   show/hide vkbd
   R   MOUSE SPEED(gui/emu)
   SEL toggle mouse/joy mode
   STR toggle num joy 
   A   fire/mousea/valid key in vkbd
   B   mouseb
   X   switch Shift ON/OFF
   Y   Emu Gui
   */

void update_input(void)
{
   int i;
   //   RETRO        B    Y    SLT  STA  UP   DWN  LEFT RGT  A    X    L    R    L2   R2   L3   R3
   //   INDEX        0    1    2    3    4    5    6    7    8    9    10   11   12   13   14   15
   static int vbt[16]={0x1C,0x39,0x01,0x3B,0x01,0x02,0x04,0x08,0x80,0x6D,0x15,0x31,0x24,0x1F,0x6E,0x6F};
   static int oldi=-1;
   static int vkx=0,vky=0;

   MXjoy0=0;
Libretro-Admin's avatar
Libretro-Admin committed
394
395
396
397
398
   if(oldi!=-1)
   {
      IKBD_PressSTKey(oldi,0);
      oldi=-1;
   }
R-type's avatar
R-type committed
399
400
401
402
403

   input_poll_cb();

   Process_key();

Libretro-Admin's avatar
Libretro-Admin committed
404
   if (Key_Sate[RETROK_F11] || input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y) )
R-type's avatar
R-type committed
405
406
407
408
409
      pauseg=1;

   i=10;//show vkey toggle
   if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 )
      mbt[i]=1;
Libretro-Admin's avatar
Libretro-Admin committed
410
411
   else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
   {
R-type's avatar
R-type committed
412
413
414
415
416
417
418
419
      mbt[i]=0;
      SHOWKEY=-SHOWKEY;
      Screen_SetFullUpdate();
   }

   i=2;//mouse/joy toggle
   if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 )
      mbt[i]=1;
Libretro-Admin's avatar
Libretro-Admin committed
420
421
   else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
   {
R-type's avatar
R-type committed
422
423
424
425
426
427
428
      mbt[i]=0;
      MOUSEMODE=-MOUSEMODE;
   }

   i=3;//num joy toggle
   if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 )
      mbt[i]=1;
Libretro-Admin's avatar
Libretro-Admin committed
429
430
   else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
   {
R-type's avatar
R-type committed
431
432
433
434
435
436
437
438
      mbt[i]=0;
      NUMJOY++;if(NUMJOY>1)NUMJOY=0;
      NUMjoy=-NUMjoy;
   }

   i=11;//mouse gui speed
   if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 )
      mbt[i]=1;
Libretro-Admin's avatar
Libretro-Admin committed
439
440
   else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
   {
R-type's avatar
R-type committed
441
442
443
444
445
446
447
      mbt[i]=0;
      PAS++;if(PAS>MAXPAS)PAS=1;
   }

   i=9;//switch shift On/Off 
   if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 )
      mbt[i]=1;
Libretro-Admin's avatar
Libretro-Admin committed
448
449
   else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
   {
R-type's avatar
R-type committed
450
451
452
453
454
455
456
457
      mbt[i]=0;
      SHIFTON=-SHIFTON;
      Screen_SetFullUpdate();
   }

   i=12;//show/hide statut
   if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 )
      mbt[i]=1;
Libretro-Admin's avatar
Libretro-Admin committed
458
459
   else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
   {
R-type's avatar
R-type committed
460
461
462
463
464
465
466
467
      mbt[i]=0;
      STATUTON=-STATUTON;
      Screen_SetFullUpdate();
   }

   i=13;//swap kbd pages
   if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 )
      mbt[i]=1;
Libretro-Admin's avatar
Libretro-Admin committed
468
469
   else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
   {
R-type's avatar
R-type committed
470
      mbt[i]=0;
Libretro-Admin's avatar
Libretro-Admin committed
471
472
      if(SHOWKEY==1)
      {
R-type's avatar
R-type committed
473
474
475
476
477
         NPAGE=-NPAGE;
         Screen_SetFullUpdate();
      }
   }

Libretro-Admin's avatar
Libretro-Admin committed
478
479
   if(SHOWKEY==1)
   {
R-type's avatar
R-type committed
480
481
482
483
      static int vkflag[5]={0,0,0,0,0};		

      if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP) && vkflag[0]==0 )
         vkflag[0]=1;
Libretro-Admin's avatar
Libretro-Admin committed
484
485
      else if (vkflag[0]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP) )
      {
R-type's avatar
R-type committed
486
487
488
489
490
491
         vkflag[0]=0;
         vky -= 1; 
      }

      if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN) && vkflag[1]==0 )
         vkflag[1]=1;
Libretro-Admin's avatar
Libretro-Admin committed
492
493
      else if (vkflag[1]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN) )
      {
R-type's avatar
R-type committed
494
495
496
497
498
499
         vkflag[1]=0;
         vky += 1; 
      }

      if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT) && vkflag[2]==0 )
         vkflag[2]=1;
Libretro-Admin's avatar
Libretro-Admin committed
500
501
      else if (vkflag[2]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT) )
      {
R-type's avatar
R-type committed
502
503
504
505
506
507
         vkflag[2]=0;
         vkx -= 1;
      }

      if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT) && vkflag[3]==0 )
         vkflag[3]=1;
Libretro-Admin's avatar
Libretro-Admin committed
508
509
      else if (vkflag[3]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT) )
      {
R-type's avatar
R-type committed
510
511
512
513
514
515
516
517
518
519
520
521
522
523
         vkflag[3]=0;
         vkx += 1;
      }

      if(vkx<0)vkx=9;
      if(vkx>9)vkx=0;
      if(vky<0)vky=4;
      if(vky>4)vky=0;

      virtual_kdb(bmp,vkx,vky);

      i=8;
      if(input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i)  && vkflag[4]==0) 	
         vkflag[4]=1;
Libretro-Admin's avatar
Libretro-Admin committed
524
525
      else if( !input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i)  && vkflag[4]==1)
      {
R-type's avatar
R-type committed
526
527
528
         vkflag[4]=0;
         i=check_vkey2(vkx,vky);

Libretro-Admin's avatar
Libretro-Admin committed
529
530
         if(i==-2)
         {
R-type's avatar
R-type committed
531
532
533
534
535
            NPAGE=-NPAGE;oldi=-1;
            //Clear interface zone					
            Screen_SetFullUpdate();

         }
Libretro-Admin's avatar
Libretro-Admin committed
536
537
538
539
540
         else if(i==-1)
            oldi=-1;
         else if(i==-3)
         {
            //KDB bgcolor
R-type's avatar
R-type committed
541
542
543
544
            Screen_SetFullUpdate();
            KCOL=-KCOL;
            oldi=-1;
         }
Libretro-Admin's avatar
Libretro-Admin committed
545
546
547
         else if(i==-4)
         {
            //VKbd show/hide 			
R-type's avatar
R-type committed
548
549
550
551
            oldi=-1;
            Screen_SetFullUpdate();
            SHOWKEY=-SHOWKEY;
         }
Libretro-Admin's avatar
Libretro-Admin committed
552
553
554
         else if(i==-5)
         {
            //Change Joy number
R-type's avatar
R-type committed
555
556
557
            NUMjoy=-NUMjoy;
            oldi=-1;
         }
Libretro-Admin's avatar
Libretro-Admin committed
558
559
560
561
         else
         {
            if(i==0x2a)
            {
R-type's avatar
R-type committed
562
563
564
565
566
567
568
569
570

               IKBD_PressSTKey(i,(SHIFTON == 1)?0:1);

               SHIFTON=-SHIFTON;

               Screen_SetFullUpdate();

               oldi=-1;
            }
Libretro-Admin's avatar
Libretro-Admin committed
571
572
            else
            {
R-type's avatar
R-type committed
573
574
575
               oldi=i;
               IKBD_PressSTKey(i,1);
            }
Libretro-Admin's avatar
Libretro-Admin committed
576
         }
R-type's avatar
R-type committed
577
578
      }

Libretro-Admin's avatar
Libretro-Admin committed
579
580
      if(STATUTON==1)
         Print_Statut();
R-type's avatar
R-type committed
581
582
583
584
585
586
587
588
589
590

      return;
   }

   static int mbL=0,mbR=0;
   int mouse_l;
   int mouse_r;
   int16_t mouse_x;
   int16_t mouse_y;

Libretro-Admin's avatar
Libretro-Admin committed
591
592
593
   if(MOUSEMODE==-1)
   {
      //Joy mode
R-type's avatar
R-type committed
594
      //emulate Joy0 with joy analog left 
Libretro-Admin's avatar
Libretro-Admin committed
595
      
R-type's avatar
R-type committed
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
      al[0] =(input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X));///2;
      al[1] =(input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y));///2;

      /* Directions */
      if (al[1] <= JOYRANGE_UP_VALUE)
         MXjoy0 |= ATARIJOY_BITMASK_UP;
      else if (al[1] >= JOYRANGE_DOWN_VALUE)
         MXjoy0 |= ATARIJOY_BITMASK_DOWN;

      if (al[0] <= JOYRANGE_LEFT_VALUE)
         MXjoy0 |= ATARIJOY_BITMASK_LEFT;
      else if (al[0] >= JOYRANGE_RIGHT_VALUE)
         MXjoy0 |= ATARIJOY_BITMASK_RIGHT;


      for(i=4;i<9;i++)if( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )MXjoy0 |= vbt[i]; // Joy press	

James D. Smith's avatar
James D. Smith committed
613
614
615
616
617
618
619
620
      // Joy autofire
      if( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B) )
      {
         MXjoy0 |= ATARIJOY_BITMASK_FIRE;
         if ((nVBLs&0x7)<4)
            MXjoy0 &= ~ATARIJOY_BITMASK_FIRE;
      }

R-type's avatar
R-type committed
621
622
623
624
625
626
627
628
629
      mouse_x = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X);
      mouse_y = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y);
      mouse_l    = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT);
      mouse_r    = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT);

      fmousex=mouse_x;
      fmousey=mouse_y;

   }
Libretro-Admin's avatar
Libretro-Admin committed
630
631
   else
   {
Not6's avatar
Not6 committed
632

Libretro-Admin's avatar
Libretro-Admin committed
633
      //Mouse mode
R-type's avatar
R-type committed
634
635
636
637
638
639
      fmousex=fmousey=0;

      //emulate mouse with joy analog right 
      ar[0] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X));
      ar[1] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y));

Not6's avatar
Not6 committed
640
641
642
643
644
645
646
647
648
649
650
#if defined(VITA)
	// fix analog to mouse move up alone
	int analog_deadzone = (15 * 32768 / 100);
        double analog_r_magnitude = sqrt((ar[0]*ar[0]) + (ar[1]*ar[1]));
               if (analog_r_magnitude <= analog_deadzone)
               {
                  ar[0] = 0;
                  ar[1] = 0;
               }
#endif

Libretro-Admin's avatar
Libretro-Admin committed
651
652
653
654
655
656
657
658
      if(ar[0]<=-1024)
         fmousex -=(-ar[0])/1024;
      if(ar[0]>= 1024)
         fmousex +=( ar[0])/1024;
      if(ar[1]<=-1024)
         fmousey -=(-ar[1])/1024;
      if(ar[1]>= 1024)
         fmousey +=( ar[1])/1024;
R-type's avatar
R-type committed
659
660

      //emulate mouse with dpad
Libretro-Admin's avatar
Libretro-Admin committed
661
662
663
664
665
666
667
668
      if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT))
         fmousex += PAS;
      if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT))
         fmousex -= PAS;
      if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN))
         fmousey += PAS;
      if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP))
         fmousey -= PAS;
R-type's avatar
R-type committed
669
670
671
672
673

      mouse_l=input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A);
      mouse_r=input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B);
   }

Libretro-Admin's avatar
Libretro-Admin committed
674
675
   if(mbL==0 && mouse_l)
   {
R-type's avatar
R-type committed
676
677
678
      mbL=1;
      Keyboard.bLButtonDown |= BUTTON_MOUSE;
   }
Libretro-Admin's avatar
Libretro-Admin committed
679
680
   else if(mbL==1 && !mouse_l)
   {
R-type's avatar
R-type committed
681
682
683
684
      Keyboard.bLButtonDown &= ~BUTTON_MOUSE;
      mbL=0;
   }

Libretro-Admin's avatar
Libretro-Admin committed
685
686
   if(mbR==0 && mouse_r)
   {
R-type's avatar
R-type committed
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
      mbR=1;
      Keyboard.bRButtonDown |= BUTTON_MOUSE;
   }
   else if(mbR==1 && !mouse_r)
   {
      Keyboard.bRButtonDown &= ~BUTTON_MOUSE;
      mbR=0;
   }

   Main_HandleMouseMotion();

   if(STATUTON==1)
      Print_Statut();
}

void input_gui(void)
{
   int SAVPAS=PAS;	

   input_poll_cb();

   int mouse_l;
   int mouse_r;
   int16_t mouse_x,mouse_y;
   mouse_x=mouse_y=0;

   //mouse/joy toggle
   if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, 2) && mbt[2]==0 )
      mbt[2]=1;
Libretro-Admin's avatar
Libretro-Admin committed
716
717
   else if ( mbt[2]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, 2) )
   {
R-type's avatar
R-type committed
718
719
720
721
      mbt[2]=0;
      MOUSEMODE=-MOUSEMODE;
   }

722
723
   if(slowdown>0)return;

Libretro-Admin's avatar
Libretro-Admin committed
724
725
   if(MOUSEMODE==1)
   {
726

Libretro-Admin's avatar
Libretro-Admin committed
727
728
729
730
731
732
733
734
      if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT))
         mouse_x += PAS;
      if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT))
         mouse_x -= PAS;
      if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN))
         mouse_y += PAS;
      if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP))
         mouse_y -= PAS;
R-type's avatar
R-type committed
735
736
737
738
      mouse_l=input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A);
      mouse_r=input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B);

      PAS=SAVPAS;
739
	
R-type's avatar
R-type committed
740
   }
Libretro-Admin's avatar
Libretro-Admin committed
741
742
   else
   {
R-type's avatar
R-type committed
743
744
745
746
747
748
      mouse_x = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X);
      mouse_y = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y);
      mouse_l    = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT);
      mouse_r    = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT);
   }

749
750
   slowdown=1;

Libretro-Admin's avatar
Libretro-Admin committed
751
   static int mmbL = 0, mmbR = 0;
R-type's avatar
R-type committed
752

Libretro-Admin's avatar
Libretro-Admin committed
753
754
   if(mmbL==0 && mouse_l)
   {
R-type's avatar
R-type committed
755
756
757
      mmbL=1;		
      touch=1;
   }
Libretro-Admin's avatar
Libretro-Admin committed
758
759
   else if(mmbL==1 && !mouse_l)
   {
R-type's avatar
R-type committed
760
761
762
763
      mmbL=0;
      touch=-1;
   }

Libretro-Admin's avatar
Libretro-Admin committed
764
   if(mmbR==0 && mouse_r)
R-type's avatar
R-type committed
765
      mmbR=1;		
Libretro-Admin's avatar
Libretro-Admin committed
766
   else if(mmbR==1 && !mouse_r)
R-type's avatar
R-type committed
767
768
769
770
      mmbR=0;

   gmx+=mouse_x;
   gmy+=mouse_y;
Libretro-Admin's avatar
Libretro-Admin committed
771
772
773
774
775
776
777
778
   if (gmx<0)
      gmx=0;
   if (gmx>retrow-1)
      gmx=retrow-1;
   if (gmy<0)
      gmy=0;
   if (gmy>retroh-1)
      gmy=retroh-1;
R-type's avatar
R-type committed
779
780
781

}