Debian Codegraph @

src/gp2xwiz/wiz_system.c

raw
1 /* ______ ___ ___
2 * /\ _ \ /\_ \ /\_ \
3 * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
4 * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
5 * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
6 * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
7 * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
8 * /\____/
9 * \_/__/
10 *
11 * GP2X Wiz system driver
12 *
13 * By Trent Gamblin.
14 *
15 */
16
17 #include <sys/time.h>
18
19 #include "allegro5/allegro.h"
20 #include "allegro5/platform/aintunix.h"
21 #include "allegro5/internal/aintern_gp2xwiz.h"
22 #include "allegro5/platform/aintwiz.h"
23
24 static ALLEGRO_SYSTEM_INTERFACE *gp2xwiz_vt;
25
26 static ALLEGRO_SYSTEM *gp2xwiz_initialize(int flags)
27 {
28 ALLEGRO_SYSTEM_GP2XWIZ *s;
29
30 (void)flags;
31
32 _al_unix_init_time();
33
34 s = al_calloc(1, sizeof *s);
35
36 _al_vector_init(&s->system.displays, sizeof (ALLEGRO_DISPLAY *));
37
38 s->system.vt = gp2xwiz_vt;
39
40 return &s->system;
41 }
42
43 static void gp2xwiz_shutdown_system(void)
44 {
45 /* Close all open displays. */
46 ALLEGRO_SYSTEM *s = al_get_system_driver();
47 ALLEGRO_SYSTEM_GP2XWIZ *sx = (void *)s;
48
49 while (_al_vector_size(&s->displays) > 0) {
50 ALLEGRO_DISPLAY **dptr = _al_vector_ref(&s->displays, 0);
51 ALLEGRO_DISPLAY *d = *dptr;
52 al_destroy_display(d);
53 }
54 _al_vector_free(&s->displays);
55
56 al_free(sx);
57
58 lc_exit();
59
60 }
61
62 static ALLEGRO_DISPLAY_INTERFACE *gp2xwiz_get_display_driver(void)
63 {
64 if (al_get_new_display_flags() & ALLEGRO_OPENGL)
65 return _al_display_gp2xwiz_opengl_driver();
66 else
67 return _al_display_gp2xwiz_framebuffer_driver();
68 }
69
70 static ALLEGRO_KEYBOARD_DRIVER *gp2xwiz_get_keyboard_driver(void)
71 {
72 //return _al_gp2xwiz_keyboard_driver;
73 return NULL;
74 }
75
76 static ALLEGRO_MOUSE_DRIVER *gp2xwiz_get_mouse_driver(void)
77 {
78 //return _al_gp2xwiz_mouse_driver;
79 return NULL;
80 }
81
82 static ALLEGRO_JOYSTICK_DRIVER *gp2xwiz_get_joystick_driver(void)
83 {
84 return _al_joystick_driver_list[0].driver;
85 }
86
87 static int gp2xwiz_get_num_video_adapters(void)
88 {
89 return 1;
90 }
91
92 static bool gp2xwiz_get_monitor_info(int adapter, ALLEGRO_MONITOR_INFO *info)
93 {
94 (void)adapter;
95 info->x1 = 0;
96 info->y1 = 0;
97 info->x2 = 320;
98 info->y2 = 240;
99 return true;
100 }
101
102 // FIXME
103 static bool gp2xwiz_get_cursor_position(int *ret_x, int *ret_y)
104 {
105 *ret_x = 0;
106 *ret_y = 0;
107 return true;
108 }
109
110 static bool gp2xwiz_inhibit_screensaver(bool inhibit)
111 {
112 (void)inhibit;
113 return false;
114 }
115
116
117 static int gp2xwiz_get_num_display_modes(void)
118 {
119 return 1;
120 }
121
122
123 static ALLEGRO_DISPLAY_MODE *gp2xwiz_get_display_mode(int index,
124 ALLEGRO_DISPLAY_MODE *mode)
125 {
126 (void)index;
127 ASSERT(index == 0);
128 mode->width = 320;
129 mode->height = 240;
130 mode->format = ALLEGRO_PIXEL_FORMAT_RGB_565;
131 mode->refresh_rate = 60;
132 return mode;
133 }
134
135
136 /* Internal function to get a reference to this driver. */
137 ALLEGRO_SYSTEM_INTERFACE *_al_system_gp2xwiz_driver(void)
138 {
139 if (gp2xwiz_vt)
140 return gp2xwiz_vt;
141
142 gp2xwiz_vt = al_calloc(1, sizeof *gp2xwiz_vt);
143
144 gp2xwiz_vt->id = ALLEGRO_SYSTEM_ID_GP2XWIZ;
145 gp2xwiz_vt->initialize = gp2xwiz_initialize;
146 gp2xwiz_vt->get_display_driver = gp2xwiz_get_display_driver;
147 gp2xwiz_vt->get_keyboard_driver = gp2xwiz_get_keyboard_driver;
148 gp2xwiz_vt->get_mouse_driver = gp2xwiz_get_mouse_driver;
149 gp2xwiz_vt->get_joystick_driver = gp2xwiz_get_joystick_driver;
150 gp2xwiz_vt->get_num_display_modes = gp2xwiz_get_num_display_modes;
151 gp2xwiz_vt->get_display_mode = gp2xwiz_get_display_mode;
152 gp2xwiz_vt->shutdown_system = gp2xwiz_shutdown_system;
153 gp2xwiz_vt->get_num_video_adapters = gp2xwiz_get_num_video_adapters;
154 gp2xwiz_vt->get_monitor_info = gp2xwiz_get_monitor_info;
155 gp2xwiz_vt->get_cursor_position = gp2xwiz_get_cursor_position;
156 gp2xwiz_vt->get_path = _al_unix_get_path;
157 gp2xwiz_vt->inhibit_screensaver = gp2xwiz_inhibit_screensaver;
158 gp2xwiz_vt->get_num_display_formats = gp2xwiz_get_num_display_formats;
159 gp2xwiz_vt->get_time = _al_unix_get_time;
160 gp2xwiz_vt->rest = _al_unix_rest;
161 gp2xwiz_vt->init_timeout = _al_unix_init_timeout;
162
163 return gp2xwiz_vt;
164 }
165
166 /* This is a function each platform must define to register all available
167 * system drivers.
168 */
169 void _al_register_system_interfaces(void)
170 {
171 ALLEGRO_SYSTEM_INTERFACE **add;
172
173 add = _al_vector_alloc_back(&_al_system_interfaces);
174 *add = _al_system_gp2xwiz_driver();
175 }
176
177 /* vim: set sts=3 sw=3 et: */