first round of patches
[drnoksnes] / platform / sdli.cpp
1 #include <SDL.h>
2
3 #include "platform.h"
4 #include "snes9x.h"
5 #include "display.h"
6
7 #define kPollEveryNFrames       3
8
9 static uint32 joypads[2];
10
11 static void processEvent(const SDL_Event& event)
12 {
13         switch (event.type) 
14         {
15         case SDL_KEYDOWN:
16                 if (Config.action[event.key.keysym.scancode]) 
17                         S9xDoAction(Config.action[event.key.keysym.scancode]);
18                 joypads[0] |= Config.joypad1Mapping[event.key.keysym.scancode];
19                 break;
20         case SDL_KEYUP:
21                 joypads[0] &= ~Config.joypad1Mapping[event.key.keysym.scancode];
22                 break;
23         case SDL_QUIT:
24                 Config.quitting = true;
25                 break;
26         }
27 }
28
29 uint32 S9xReadJoypad (int which)
30 {
31         if (which < 0 || which > 2) {
32                 return 0;
33         }
34         
35         return joypads[which];
36 }
37
38 bool8 S9xReadMousePosition (int /* which1 */, int &/* x */, int & /* y */,
39                     uint32 & /* buttons */)
40 {
41         return FALSE;
42 }
43
44 bool8 S9xReadSuperScopePosition (int & /* x */, int & /* y */,
45                          uint32 & /* buttons */)
46 {
47         return FALSE;
48 }
49
50 void S9xProcessEvents(bool8_32 block)
51 {
52         SDL_Event event;
53         
54         if (block) {
55                 SDL_WaitEvent(&event);
56                 processEvent(event);
57         } else {
58                 while(SDL_PollEvent(&event)) 
59                 {      
60                         processEvent(event);
61                 }
62         }
63 }
64
65 void S9xInitInputDevices()
66 {
67         joypads[0] = 0x80000000UL;
68         joypads[1] = 0;
69         
70         printf("Input: 1 joypad, hw keyboard input only\n");
71 }
72