in_sdl: give names to gamepad buttons
[libpicofe.git] / plat.h
... / ...
CommitLineData
1#ifndef LIBPICOFE_PLAT_H
2#define LIBPICOFE_PLAT_H
3
4#include <stdlib.h>
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10// platform dependend color handling
11#if defined(USE_BGR555)
12#define PXMAKE(r,g,b) ((((b)<<7) & 0x7c00)|(((g)<<2) & 0x03e0)|((r)>>3))
13#define PXMASKL(t,c) ((t) & (((1<<(c))-1)*0x04210421))
14#define PXMASKH(t,c) ((t) & ~(((1<<(c))-1)*0x04210421) & 0x7fff)
15#define PXGETR(t) (((t) & 0x001f)<<3)
16#define PXGETG(t) (((t) & 0x03e0)>>2)
17#define PXGETB(t) (((t) & 0x7c00)>>7)
18#elif defined(USE_BGR565)
19#define PXMAKE(r,g,b) ((((b)<<8) & 0xf800)|(((g)<<3) & 0x07e0)|((r)>>3))
20#define PXMASKL(t,c) ((t) & (((1<<(c))-1)*0x08210821))
21#define PXMASKH(t,c) ((t) & ~(((1<<(c))-1)*0x08210821))
22#define PXGETR(t) (((t) & 0x001f)<<3)
23#define PXGETG(t) (((t) & 0x07e0)>>3)
24#define PXGETB(t) (((t) & 0xf800)>>8)
25#else // RGB565
26#define PXMAKE(r,g,b) ((((r)<<8) & 0xf800)|(((g)<<3) & 0x07e0)|((b)>>3))
27#define PXMASKL(t,c) ((t) & (((1<<(c))-1)*0x08210821))
28#define PXMASKH(t,c) ((t) & ~(((1<<(c))-1)*0x08210821))
29#define PXGETR(t) (((t) & 0xf800)>>8)
30#define PXGETG(t) (((t) & 0x07e0)>>3)
31#define PXGETB(t) (((t) & 0x001f)<<3)
32#endif
33
34/* target device, everything is optional */
35struct plat_target {
36 int (*cpu_clock_get)(void);
37 int (*cpu_clock_set)(int clock);
38 int (*bat_capacity_get)(void);
39 int (*hwfilter_set)(int which);
40 int (*lcdrate_set)(int is_pal);
41 int (*gamma_set)(int val, int black_level);
42 int (*step_volume)(int *volume, int diff);
43 int (*switch_layer)(int which, int enable);
44 const char **vout_methods;
45 int vout_method;
46 int vout_fullscreen;
47 const char **hwfilters;
48 int hwfilter;
49 const int *sound_rates;
50 int sound_rate;
51};
52
53extern struct plat_target plat_target;
54int plat_target_init(void);
55void plat_target_finish(void);
56void plat_target_setup_input(void);
57
58/* CPU clock in MHz */
59static __inline int plat_target_cpu_clock_get(void)
60{
61 if (plat_target.cpu_clock_get)
62 return plat_target.cpu_clock_get();
63 return -1;
64}
65
66static __inline int plat_target_cpu_clock_set(int mhz)
67{
68 if (plat_target.cpu_clock_set)
69 return plat_target.cpu_clock_set(mhz);
70 return -1;
71}
72
73/* battery capacity (0-100) */
74static __inline int plat_target_bat_capacity_get(void)
75{
76 if (plat_target.bat_capacity_get)
77 return plat_target.bat_capacity_get();
78 return -1;
79}
80
81/* set some hardware-specific video filter, 0 for none */
82static __inline int plat_target_hwfilter_set(int which)
83{
84 if (plat_target.hwfilter_set)
85 return plat_target.hwfilter_set(which);
86 return -1;
87}
88
89/* set device LCD rate, is_pal 0 for NTSC, 1 for PAL compatible */
90static __inline int plat_target_lcdrate_set(int is_pal)
91{
92 if (plat_target.lcdrate_set)
93 return plat_target.lcdrate_set(is_pal);
94 return -1;
95}
96
97/* set device LCD rate, is_pal 0 for NTSC, 1 for PAL compatible */
98static __inline int plat_target_gamma_set(int val, int black_level)
99{
100 if (plat_target.gamma_set)
101 return plat_target.gamma_set(val, black_level);
102 return -1;
103}
104
105/* step sound volume up or down */
106static __inline int plat_target_step_volume(int *volume, int diff)
107{
108 if (plat_target.step_volume)
109 return plat_target.step_volume(volume, diff);
110 return -1;
111}
112
113/* switch device graphics layers/overlays */
114static __inline int plat_target_switch_layer(int which, int enable)
115{
116 if (plat_target.switch_layer)
117 return plat_target.switch_layer(which, enable);
118 return -1;
119}
120
121/* menu: enter (switch bpp, etc), begin/end drawing */
122void plat_video_menu_update(void);
123void plat_video_menu_enter(int is_rom_loaded);
124void plat_video_menu_begin(void);
125void plat_video_menu_end(void);
126void plat_video_menu_leave(void);
127
128void plat_video_flip(void);
129void plat_video_wait_vsync(void);
130
131/* return the dir/ where configs, saves, bios, etc. are found */
132int plat_get_root_dir(char *dst, int len);
133
134/* return the dir/ where skin files are found */
135int plat_get_skin_dir(char *dst, int len);
136
137/* return the top level dir for image files */
138int plat_get_data_dir(char *dst, int len);
139
140int plat_is_dir(const char *path);
141int plat_wait_event(int *fds_hnds, int count, int timeout_ms);
142void plat_sleep_ms(int ms);
143
144void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed);
145void *plat_mremap(void *ptr, size_t oldsize, size_t newsize);
146void plat_munmap(void *ptr, size_t size);
147int plat_mem_set_exec(void *ptr, size_t size);
148
149/* timers, to be used for time diff and must refer to the same clock */
150unsigned int plat_get_ticks_ms(void);
151unsigned int plat_get_ticks_us(void);
152void plat_wait_till_us(unsigned int us);
153
154void plat_debug_cat(char *str);
155
156#ifdef __cplusplus
157} // extern "C"
158#endif
159
160#endif /* LIBPICOFE_PLAT_H */