FreeBASIC  0.91.0
gfx_driver.c
Go to the documentation of this file.
1 /* xbox fbgfx driver */
2 
3 #include "../fb_gfx.h"
4 #include <hal/xbox.h>
5 #include <hal/video.h>
6 #include <hal/input.h>
7 
8 #define SCREENLIST(w, h) ((h) | (w) << 16)
9 #define JOYPOS(pos, min, max) (((((float)(pos) - (float)(min)) * 2.0) / ((float)(max) - (float)(min) + 1.0)) - 1.0)
10 
11 static BLITTER *blitter;
12 static void *framebuffer;
13 static volatile int quitting;
14 
15 /*:::::*/
16 static void __stdcall /* FIXME */ driver_update(void *param1, void *param2)
17 {
18  while (!quitting) {
19  /* !!!FIXME!!! */
20  if (blitter) {
21  //blitter(framebuffer, __fb_gfx->w);
22  } else {
24  }
25 
26  /* !!!FIXME!!! */
27  XSleep(10);
28  }
29 }
30 
31 /*:::::*/
32 static int driver_init(char *title, int w, int h, int depth_arg, int refresh_rate, int flags)
33 {
34  int depth = MAX(8, depth_arg);
35 
36  if (depth == 8) {
37  depth = 24;
39  } else {
40  blitter = NULL;
41  }
42 
43  if (flags & DRIVER_OPENGL)
44  return -1;
45 
46  if (!XVideoSetMode(w, h, depth == 32 ? 24 : depth, refresh_rate))
47  return -1;
48 
49  framebuffer = XVideoGetFB();
50 
51  quitting = FALSE;
52 
53  //XInput_Init();
54 
55  /* !!!FIXME!!! use rtlib thread creation function */
56  XCreateThread(driver_update, NULL, NULL);
57 
58  return 0;
59 }
60 
61 /*:::::*/
62 static void driver_exit(void)
63 {
64  quitting = TRUE;
65 
66  //XInput_Quit();
67 
68  /* !!!FIXME!!! */
69 }
70 
71 /*:::::*/
72 static void driver_lock(void)
73 {
74  /* !!!WRITEME!!! */
75 }
76 
77 /*:::::*/
78 static void driver_unlock(void)
79 {
80  /* !!!WRITEME!!! */
81 }
82 
83 /*:::::*/
84 static void driver_set_palette(int index, int r, int g, int b)
85 {
86  /* !!!WRITEME!!! */
87 }
88 
89 /*:::::*/
90 static void driver_wait_vsync(void)
91 {
92  /* !!!WRITEME!!! */
93 }
94 
95 /*:::::*/
96 static int driver_get_mouse(int *x, int *y, int *z, int *buttons)
97 {
98  /* !!!WRITEME!!! */
99 }
100 
101 /*:::::*/
102 static void driver_set_mouse(int x, int y, int cursor)
103 {
104  /* !!!WRITEME!!! */
105 }
106 
107 /*:::::*/
108 static int *driver_fetch_modes(int depth, int *size)
109 {
110  VIDEO_MODE vm;
111  void *p = NULL;
112  int num = 0;
113  int *modes = NULL, *new_modes;
114 
115  while (XVideoListModes(&vm, depth, 0, &p)) {
116  ++num;
117  new_modes = realloc(modes, sizeof(int) * num);
118  if (!new_modes) {
119  *size = num - 1;
120  return modes;
121  }
122 
123  modes = new_modes;
124  modes[num - 1] = SCREENLIST(vm.width, vm.height);
125  }
126 
127  *size = num;
128  return modes;
129 }
130 
131 /*:::::*/
132 static void driver_poll_events(void)
133 {
134  /* !!!WRITEME!!! */
135 }
136 
137 
139 {
140  "xbox", /* char *name; */
141  driver_init, /* int (*init)(char *title, int w, int h, int depth, int refresh_rate, int flags); */
142  driver_exit, /* void (*exit)(void); */
143  driver_lock, /* void (*lock)(void); */
144  driver_unlock, /* void (*unlock)(void); */
145  driver_set_palette, /* void (*set_palette)(int index, int r, int g, int b); */
146  driver_wait_vsync, /* void (*wait_vsync)(void); */
147  driver_get_mouse, /* int (*get_mouse)(int *x, int *y, int *z, int *buttons); */
148  driver_set_mouse, /* void (*set_mouse)(int x, int y, int cursor); */
149  NULL, /* void (*set_window_title)(char *title); */
150  NULL, /* int (*set_window_pos)(int x, int y); */
151  driver_fetch_modes, /* int *(*fetch_modes)(int depth, int *size); */
152  NULL, /* void (*flip)(void); */
153  driver_poll_events /* void (*poll_events)(void); */
154 };
155 
158  NULL
159 };
160 
161 /*:::::*/
162 void fb_hScreenInfo(ssize_t *width, ssize_t *height, ssize_t *depth, ssize_t *refresh)
163 {
164  /* !!!FIXME!!! */
165  VIDEO_MODE vm;
166 
167  vm = XVideoGetMode();
168 
169  *width = vm.width;
170  *height = vm.height;
171  *depth = vm.bpp;
172  *refresh = vm.refresh;
173 }
174 
175 /*:::::*/
176 FBCALL int fb_GfxGetJoystick(int id, ssize_t *buttons, float *a1, float *a2, float *a3, float *a4, float *a5, float *a6, float *a7, float *a8)
177 {
178  static int inited = 0;
179 
180  *buttons = -1;
181  *a1 = *a2 = *a3 = *a4 = *a5 = *a6 = *a7 = *a8 = -1000.0;
182 
183  if ((id < 0) || (id >= 4) || (!g_Pads[id].hPresent))
185 
186  if (!inited) {
187  inited = 1;
188  XInput_Init();
189  }
190 
191  XInput_GetEvents();
192 
193  *buttons = !!g_Pads[id].CurrentButtons.ucAnalogButtons[XPAD_A] |
194  (!!g_Pads[id].CurrentButtons.ucAnalogButtons[XPAD_B] << 1) |
195  (!!g_Pads[id].CurrentButtons.ucAnalogButtons[XPAD_X] << 2) |
196  (!!g_Pads[id].CurrentButtons.ucAnalogButtons[XPAD_Y] << 3) |
197  (!!g_Pads[id].CurrentButtons.ucAnalogButtons[XPAD_BLACK] << 4) |
198  (!!g_Pads[id].CurrentButtons.ucAnalogButtons[XPAD_WHITE] << 5) |
199  (!!(g_Pads[id].CurrentButtons.usDigitalButtons & XPAD_START) << 6) |
200  (!!(g_Pads[id].CurrentButtons.usDigitalButtons & XPAD_BACK) << 7) |
201  (!!(g_Pads[id].CurrentButtons.usDigitalButtons & XPAD_LEFT_THUMB) << 8) |
202  (!!(g_Pads[id].CurrentButtons.usDigitalButtons & XPAD_RIGHT_THUMB) << 9);
203 
204  *a1 = JOYPOS(g_Pads[id].sLThumbX, -32768, 32767);
205  *a2 = -JOYPOS(g_Pads[id].sLThumbY, -32768, 32767);
206  *a3 = JOYPOS(g_Pads[id].sRThumbX, -32768, 32767);
207  *a4 = -JOYPOS(g_Pads[id].sRThumbY, -32768, 32767);
208  *a5 = (JOYPOS(g_Pads[id].CurrentButtons.ucAnalogButtons[XPAD_LEFT_TRIGGER], 0, 255) + 1.0) / 2.0;
209  *a6 = (JOYPOS(g_Pads[id].CurrentButtons.ucAnalogButtons[XPAD_RIGHT_TRIGGER], 0, 255) + 1.0) / 2.0;
210 
211  if (g_Pads[id].CurrentButtons.usDigitalButtons & XPAD_DPAD_RIGHT)
212  *a7 = 1.0;
213  else if (g_Pads[id].CurrentButtons.usDigitalButtons & XPAD_DPAD_LEFT)
214  *a7 = -1.0;
215  else
216  *a7 = 0.0;
217 
218  if (g_Pads[id].CurrentButtons.usDigitalButtons & XPAD_DPAD_DOWN)
219  *a8 = 1.0;
220  else if (g_Pads[id].CurrentButtons.usDigitalButtons & XPAD_DPAD_UP)
221  *a8 = -1.0;
222  else
223  *a8 = 0.0;
224 
225  return fb_ErrorSetNum( FB_RTERROR_OK );
226 }