window-size sdl surfaces instead of snes
[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 static struct {
11         unsigned x;
12         unsigned y;
13         bool pressed;
14 } mouse;
15
16 static void processEvent(const SDL_Event& event)
17 {
18         switch (event.type) 
19         {
20         case SDL_KEYDOWN:
21                 if (Config.action[event.key.keysym.scancode]) 
22                         S9xDoAction(Config.action[event.key.keysym.scancode]);
23                 joypads[0] |= Config.joypad1Mapping[event.key.keysym.scancode];
24                 break;
25         case SDL_KEYUP:
26                 joypads[0] &= ~Config.joypad1Mapping[event.key.keysym.scancode];
27                 break;
28         case SDL_MOUSEBUTTONUP:
29         case SDL_MOUSEBUTTONDOWN:
30                 mouse.x = event.button.x;
31                 mouse.y = event.button.y;
32                 if (Config.xsp) {
33                         mouse.x /= 2;
34                         mouse.y /= 2;
35                 }
36                 mouse.pressed = event.button.state == SDL_PRESSED;
37                 break;
38         case SDL_MOUSEMOTION:
39                 mouse.x = event.motion.x;
40                 mouse.y = event.motion.y;
41                 if (Config.xsp) {
42                         mouse.x /= 2;
43                         mouse.y /= 2;
44                 }
45                 break;
46         case SDL_QUIT:
47                 Config.quitting = true;
48                 break;
49         }
50 }
51
52 uint32 S9xReadJoypad (int which)
53 {
54         if (which < 0 || which > 2) {
55                 return 0;
56         }
57
58         return joypads[which];
59 }
60
61 bool8 S9xReadMousePosition(int which1, int& x, int& y, uint32& buttons)
62 {
63         if (which1 != 0) return FALSE;
64
65         x = mouse.x;
66         y = mouse.y;
67         buttons = mouse.pressed ? 1 : 0;
68
69         return TRUE;
70 }
71
72 bool8 S9xReadSuperScopePosition(int& x, int& y, uint32& buttons)
73 {
74         x = mouse.x;
75         y = mouse.y;
76         buttons = mouse.pressed ? 8 : 0;
77
78         return TRUE;
79 }
80
81 void S9xProcessEvents(bool8_32 block)
82 {
83         SDL_Event event;
84
85         if (block) {
86                 SDL_WaitEvent(&event);
87                 processEvent(event);
88         } else {
89                 while(SDL_PollEvent(&event)) 
90                 {      
91                         processEvent(event);
92                 }
93         }
94 }
95
96 void S9xInitInputDevices()
97 {
98         joypads[0] = 0;
99         joypads[1] = 0;
100
101         switch (Settings.ControllerOption) {
102                 case SNES_JOYPAD:
103                         joypads[0] = 0x80000000UL;
104                         printf("Input: 1 joypad, keyboard only\n");
105                         break;
106                 case SNES_MOUSE:
107                         joypads[0] = 0x80000000UL;
108                         printf("Input: 1 joypad + mouse\n");
109                         break;
110                 case SNES_MOUSE_SWAPPED:
111                         printf("Input: mouse\n");
112                         break;
113                 case SNES_SUPERSCOPE:
114                         joypads[0] = 0x80000000UL;
115                         printf("Input: 1 joypad + superscope\n");
116                         break;
117                 default:
118                         printf("Input: unknown\n");
119                         break;
120         }
121 }
122
123 void S9xDeinitInputDevices()
124 {
125
126 }
127
128 void S9xInputFullscreenChanged()
129 {
130
131 }
132