more Pandora porting work
[picodrive.git] / platform / pandora / pandora.c
CommitLineData
3a3947cd 1\r
2#include <stdio.h>\r
3#include <stdlib.h>\r
4#include <stdarg.h>\r
5#include <string.h>\r
6#include <unistd.h>\r
7#include <sys/mman.h>\r
8#include <sys/types.h>\r
9#include <sys/stat.h>\r
10#include <sys/ioctl.h>\r
11#include <sys/soundcard.h>\r
12#include <fcntl.h>\r
13#include <errno.h>\r
14\r
15#include "../gp2x/gp2x.h"\r
16#include "../gp2x/usbjoy.h"\r
17#include "../common/arm_utils.h"\r
18\r
e55f0cbb 19static volatile unsigned int *memregs;\r
3a3947cd 20//static\r
21int memdev = 0;\r
22static int sounddev = -1, mixerdev = -1, touchdev = -1;\r
23static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 };\r
24\r
e55f0cbb 25#define SCREEN_MAP_SIZE (((800*(480+11)*2)+0xfff)&~0xfff)\r
26static void *screen;\r
3a3947cd 27void *gp2x_screen;\r
28\r
3a3947cd 29\r
30/* video stuff */\r
31void gp2x_video_flip(void)\r
32{\r
3a3947cd 33}\r
34\r
35/* doulblebuffered flip */\r
36void gp2x_video_flip2(void)\r
37{\r
3a3947cd 38}\r
39\r
40\r
41void gp2x_video_changemode2(int bpp)\r
42{\r
3a3947cd 43}\r
44\r
45\r
46void gp2x_video_changemode(int bpp)\r
47{\r
3a3947cd 48}\r
49\r
50\r
51void gp2x_video_setpalette(int *pal, int len)\r
52{\r
3a3947cd 53}\r
54\r
55\r
3a3947cd 56void gp2x_video_RGB_setscaling(int ln_offs, int W, int H)\r
57{\r
3a3947cd 58}\r
59\r
60\r
61void gp2x_video_wait_vsync(void)\r
62{\r
3a3947cd 63}\r
64\r
65\r
66void gp2x_video_flush_cache(void)\r
67{\r
e55f0cbb 68// flushcache(gp2x_screen, (char *)gp2x_screen + 320*240*2, 0);\r
3a3947cd 69}\r
70\r
71\r
72void gp2x_memcpy_buffers(int buffers, void *data, int offset, int len)\r
73{\r
3a3947cd 74}\r
75\r
76\r
77void gp2x_memcpy_all_buffers(void *data, int offset, int len)\r
78{\r
3a3947cd 79}\r
80\r
81\r
82void gp2x_memset_all_buffers(int offset, int byte, int len)\r
83{\r
e55f0cbb 84 memset((char *)gp2x_screen + offset, byte, len);\r
3a3947cd 85}\r
86\r
87\r
88void gp2x_pd_clone_buffer2(void)\r
89{\r
3a3947cd 90}\r
91\r
92\r
93unsigned long gp2x_joystick_read(int allow_usb_joy)\r
94{\r
e55f0cbb 95 unsigned long value = 0;\r
3a3947cd 96 int i;\r
3a3947cd 97\r
98 if (allow_usb_joy && num_of_joys > 0) {\r
99 // check the usb joy as well..\r
100 gp2x_usbjoy_update();\r
101 for (i = 0; i < num_of_joys; i++)\r
102 value |= gp2x_usbjoy_check(i);\r
103 }\r
104\r
105 return value;\r
106}\r
107\r
108typedef struct ucb1x00_ts_event\r
109{\r
110 unsigned short pressure;\r
111 unsigned short x;\r
112 unsigned short y;\r
113 unsigned short pad;\r
114 struct timeval stamp;\r
115} UCB1X00_TS_EVENT;\r
116\r
117int gp2x_touchpad_read(int *x, int *y)\r
118{\r
119 UCB1X00_TS_EVENT event;\r
120 static int zero_seen = 0;\r
121 int retval;\r
122\r
123 if (touchdev < 0) return -1;\r
124\r
125 retval = read(touchdev, &event, sizeof(event));\r
126 if (retval <= 0) {\r
127 printf("touch read failed %i %i\n", retval, errno);\r
128 return -1;\r
129 }\r
130 // this is to ignore the messed-up 4.1.x driver\r
131 if (event.pressure == 0) zero_seen = 1;\r
132\r
133 if (x) *x = (event.x * touchcal[0] + touchcal[2]) >> 16;\r
134 if (y) *y = (event.y * touchcal[4] + touchcal[5]) >> 16;\r
135 // printf("read %i %i %i\n", event.pressure, *x, *y);\r
136\r
137 return zero_seen ? event.pressure : 0;\r
138}\r
139\r
140\r
e55f0cbb 141//static int s_oldrate = 0, s_oldbits = 0, s_oldstereo = 0;\r
3a3947cd 142\r
143void gp2x_start_sound(int rate, int bits, int stereo)\r
144{\r
e55f0cbb 145#if 0\r
3a3947cd 146 int frag = 0, bsize, buffers;\r
147\r
148 // if no settings change, we don't need to do anything\r
149 if (rate == s_oldrate && s_oldbits == bits && s_oldstereo == stereo) return;\r
150\r
151 if (sounddev > 0) close(sounddev);\r
152 sounddev = open("/dev/dsp", O_WRONLY|O_ASYNC);\r
153 if (sounddev == -1)\r
154 printf("open(\"/dev/dsp\") failed with %i\n", errno);\r
155\r
156 ioctl(sounddev, SNDCTL_DSP_SETFMT, &bits);\r
157 ioctl(sounddev, SNDCTL_DSP_SPEED, &rate);\r
158 ioctl(sounddev, SNDCTL_DSP_STEREO, &stereo);\r
159 // calculate buffer size\r
160 buffers = 16;\r
161 bsize = rate / 32;\r
162 if (rate > 22050) { bsize*=4; buffers*=2; } // 44k mode seems to be very demanding\r
163 while ((bsize>>=1)) frag++;\r
164 frag |= buffers<<16; // 16 buffers\r
165 ioctl(sounddev, SNDCTL_DSP_SETFRAGMENT, &frag);\r
166 usleep(192*1024);\r
167\r
168 printf("gp2x_set_sound: %i/%ibit/%s, %i buffers of %i bytes\n",\r
169 rate, bits, stereo?"stereo":"mono", frag>>16, 1<<(frag&0xffff));\r
170\r
171 s_oldrate = rate; s_oldbits = bits; s_oldstereo = stereo;\r
e55f0cbb 172#endif\r
3a3947cd 173}\r
174\r
175\r
176void gp2x_sound_write(void *buff, int len)\r
177{\r
e55f0cbb 178// write(sounddev, buff, len);\r
3a3947cd 179}\r
180\r
181void gp2x_sound_sync(void)\r
182{\r
e55f0cbb 183// ioctl(sounddev, SOUND_PCM_SYNC, 0);\r
3a3947cd 184}\r
185\r
186void gp2x_sound_volume(int l, int r)\r
187{\r
e55f0cbb 188#if 0\r
3a3947cd 189 l=l<0?0:l; l=l>255?255:l; r=r<0?0:r; r=r>255?255:r;\r
190 l<<=8; l|=r;\r
191 ioctl(mixerdev, SOUND_MIXER_WRITE_PCM, &l); /*SOUND_MIXER_WRITE_VOLUME*/\r
e55f0cbb 192#endif\r
3a3947cd 193}\r
194\r
195\r
196/* common */\r
197void gp2x_init(void)\r
198{\r
e55f0cbb 199// struct fb_fix_screeninfo fbfix;\r
200 int fbdev;\r
201\r
3a3947cd 202 printf("entering init()\n"); fflush(stdout);\r
203\r
204 memdev = open("/dev/mem", O_RDWR);\r
205 if (memdev == -1)\r
206 {\r
207 printf("open(\"/dev/mem\") failed with %i\n", errno);\r
208 exit(1);\r
209 }\r
210\r
e55f0cbb 211 memregs = mmap(0, 0x01000000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0x48000000);\r
212 if (memregs == MAP_FAILED)\r
3a3947cd 213 {\r
214 printf("mmap(memregs) failed with %i\n", errno);\r
215 exit(1);\r
216 }\r
3a3947cd 217\r
e55f0cbb 218 fbdev = open("/dev/fb0", O_RDWR);\r
219 if (fbdev == -1)\r
3a3947cd 220 {\r
e55f0cbb 221 printf("open(\"/dev/fb0\") failed with %i\n", errno);\r
3a3947cd 222 exit(1);\r
223 }\r
3a3947cd 224\r
e55f0cbb 225/*\r
226 ret = ioctl(fbdev, FBIOGET_FSCREENINFO, &fbfix);\r
227 if (ret == -1)\r
228 {\r
229 printf("ioctl(fbdev) failed with %i\n", errno);\r
230 exit(1);\r
231 }\r
232*/\r
233 screen = mmap(0, SCREEN_MAP_SIZE, PROT_WRITE|PROT_READ, MAP_SHARED, fbdev, 0);\r
234 if (screen == MAP_FAILED)\r
235 {\r
236 printf("mmap(fbptr) failed with %i\n", errno);\r
237 exit(1);\r
238 }\r
239 printf("fbptr %p\n", screen);\r
240 gp2x_screen = (char *)screen + 800*10*2-64;\r
3a3947cd 241\r
3a3947cd 242\r
243 // snd\r
244 mixerdev = open("/dev/mixer", O_RDWR);\r
245 if (mixerdev == -1)\r
246 printf("open(\"/dev/mixer\") failed with %i\n", errno);\r
247\r
248 /* init usb joys -GnoStiC */\r
249 gp2x_usbjoy_init();\r
250\r
251 // touchscreen\r
252 touchdev = open("/dev/touchscreen/wm97xx", O_RDONLY);\r
253 if (touchdev >= 0) {\r
254 FILE *pcf = fopen("/etc/pointercal", "r");\r
255 if (pcf) {\r
256 fscanf(pcf, "%d %d %d %d %d %d %d", &touchcal[0], &touchcal[1],\r
257 &touchcal[2], &touchcal[3], &touchcal[4], &touchcal[5], &touchcal[6]);\r
258 fclose(pcf);\r
259 }\r
260 printf("found touchscreen/wm97xx\n");\r
261 }\r
262\r
3a3947cd 263 printf("exitting init()\n"); fflush(stdout);\r
264}\r
265\r
3a3947cd 266void gp2x_deinit(void)\r
267{\r
e55f0cbb 268 //gp2x_video_changemode(15);\r
3a3947cd 269\r
e55f0cbb 270 munmap(screen, SCREEN_MAP_SIZE);\r
271 munmap((void *)memregs, 0x10000);\r
3a3947cd 272 close(memdev);\r
e55f0cbb 273 if (mixerdev >= 0) close(mixerdev);\r
3a3947cd 274 if (sounddev >= 0) close(sounddev);\r
275 if (touchdev >= 0) close(touchdev);\r
276\r
277 gp2x_usbjoy_deinit();\r
278\r
e55f0cbb 279 printf("all done");\r
3a3947cd 280}\r
281\r
282/* lprintf */\r
283void lprintf(const char *fmt, ...)\r
284{\r
285 va_list vl;\r
286\r
287 va_start(vl, fmt);\r
288 vprintf(fmt, vl);\r
289 va_end(vl);\r
290}\r
291\r
292\r
293/* fake GP2X */\r
294int crashed_940 = 0;\r
295\r
296int readpng(void *dest, const char *fname, int what) { return -1; }\r
297void set_gamma(int g100, int A_SNs_curve) {}\r
298void set_FCLK(unsigned MHZ) {}\r
299void set_LCD_custom_rate(int rate) {}\r
300void unset_LCD_custom_rate(void) {}\r
e55f0cbb 301void Pause940(int yes) {}\r
302void Reset940(int yes, int bank) {}\r
3a3947cd 303\r