Mercurial > sdl-ios-xcode
comparison src/video/ipod/SDL_ipodvideo.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
43 #include "SDL_sysevents.h" | 43 #include "SDL_sysevents.h" |
44 #include "SDL_ipodvideo.h" | 44 #include "SDL_ipodvideo.h" |
45 | 45 |
46 #define _THIS SDL_VideoDevice *this | 46 #define _THIS SDL_VideoDevice *this |
47 | 47 |
48 static int iPod_VideoInit (_THIS, SDL_PixelFormat * vformat); | 48 static int iPod_VideoInit(_THIS, SDL_PixelFormat * vformat); |
49 static SDL_Rect **iPod_ListModes (_THIS, SDL_PixelFormat * format, | 49 static SDL_Rect **iPod_ListModes(_THIS, SDL_PixelFormat * format, |
50 Uint32 flags); | 50 Uint32 flags); |
51 static SDL_Surface *iPod_SetVideoMode (_THIS, SDL_Surface * current, | 51 static SDL_Surface *iPod_SetVideoMode(_THIS, SDL_Surface * current, |
52 int width, int height, int bpp, | 52 int width, int height, int bpp, |
53 Uint32 flags); | 53 Uint32 flags); |
54 static int iPod_SetColors (_THIS, int firstcolor, int ncolors, | 54 static int iPod_SetColors(_THIS, int firstcolor, int ncolors, |
55 SDL_Color * colors); | 55 SDL_Color * colors); |
56 static void iPod_UpdateRects (_THIS, int nrects, SDL_Rect * rects); | 56 static void iPod_UpdateRects(_THIS, int nrects, SDL_Rect * rects); |
57 static void iPod_VideoQuit (_THIS); | 57 static void iPod_VideoQuit(_THIS); |
58 static void iPod_PumpEvents (_THIS); | 58 static void iPod_PumpEvents(_THIS); |
59 | 59 |
60 static long iPod_GetGeneration (); | 60 static long iPod_GetGeneration(); |
61 | 61 |
62 static int initd = 0; | 62 static int initd = 0; |
63 static int kbfd = -1; | 63 static int kbfd = -1; |
64 static int fbfd = -1; | 64 static int fbfd = -1; |
65 static int oldvt = -1; | 65 static int oldvt = -1; |
78 #define IPOD_NEW_LCD_RTC 0x60005010 | 78 #define IPOD_NEW_LCD_RTC 0x60005010 |
79 | 79 |
80 static unsigned long lcd_base, lcd_rtc, lcd_width, lcd_height; | 80 static unsigned long lcd_base, lcd_rtc, lcd_width, lcd_height; |
81 | 81 |
82 static long | 82 static long |
83 iPod_GetGeneration () | 83 iPod_GetGeneration() |
84 { | 84 { |
85 int i; | 85 int i; |
86 char cpuinfo[256]; | 86 char cpuinfo[256]; |
87 char *ptr; | 87 char *ptr; |
88 FILE *file; | 88 FILE *file; |
89 | 89 |
90 if ((file = fopen ("/proc/cpuinfo", "r")) != NULL) { | 90 if ((file = fopen("/proc/cpuinfo", "r")) != NULL) { |
91 while (fgets (cpuinfo, sizeof (cpuinfo), file) != NULL) | 91 while (fgets(cpuinfo, sizeof(cpuinfo), file) != NULL) |
92 if (SDL_strncmp (cpuinfo, "Revision", 8) == 0) | 92 if (SDL_strncmp(cpuinfo, "Revision", 8) == 0) |
93 break; | 93 break; |
94 fclose (file); | 94 fclose(file); |
95 } | 95 } |
96 for (i = 0; !isspace (cpuinfo[i]); i++); | 96 for (i = 0; !isspace(cpuinfo[i]); i++); |
97 for (; isspace (cpuinfo[i]); i++); | 97 for (; isspace(cpuinfo[i]); i++); |
98 ptr = cpuinfo + i + 2; | 98 ptr = cpuinfo + i + 2; |
99 | 99 |
100 return SDL_strtol (ptr, NULL, 10); | 100 return SDL_strtol(ptr, NULL, 10); |
101 } | 101 } |
102 | 102 |
103 static int | 103 static int |
104 iPod_Available () | 104 iPod_Available() |
105 { | 105 { |
106 return 1; | 106 return 1; |
107 } | 107 } |
108 | 108 |
109 static void | 109 static void |
110 iPod_DeleteDevice (SDL_VideoDevice * device) | 110 iPod_DeleteDevice(SDL_VideoDevice * device) |
111 { | 111 { |
112 free (device->hidden); | 112 free(device->hidden); |
113 free (device); | 113 free(device); |
114 } | 114 } |
115 | 115 |
116 void | 116 void |
117 iPod_InitOSKeymap (_THIS) | 117 iPod_InitOSKeymap(_THIS) |
118 { | 118 { |
119 } | 119 } |
120 | 120 |
121 static SDL_VideoDevice * | 121 static SDL_VideoDevice * |
122 iPod_CreateDevice (int devindex) | 122 iPod_CreateDevice(int devindex) |
123 { | 123 { |
124 SDL_VideoDevice *this; | 124 SDL_VideoDevice *this; |
125 | 125 |
126 this = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); | 126 this = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice)); |
127 if (this) { | 127 if (this) { |
128 memset (this, 0, sizeof *this); | 128 memset(this, 0, sizeof *this); |
129 this->hidden = (struct SDL_PrivateVideoData *) | 129 this->hidden = (struct SDL_PrivateVideoData *) |
130 SDL_malloc (sizeof (struct SDL_PrivateVideoData)); | 130 SDL_malloc(sizeof(struct SDL_PrivateVideoData)); |
131 } | 131 } |
132 if (!this || !this->hidden) { | 132 if (!this || !this->hidden) { |
133 SDL_OutOfMemory (); | 133 SDL_OutOfMemory(); |
134 if (this) | 134 if (this) |
135 SDL_free (this); | 135 SDL_free(this); |
136 return 0; | 136 return 0; |
137 } | 137 } |
138 memset (this->hidden, 0, sizeof (struct SDL_PrivateVideoData)); | 138 memset(this->hidden, 0, sizeof(struct SDL_PrivateVideoData)); |
139 | 139 |
140 generation = iPod_GetGeneration (); | 140 generation = iPod_GetGeneration(); |
141 | 141 |
142 this->VideoInit = iPod_VideoInit; | 142 this->VideoInit = iPod_VideoInit; |
143 this->ListModes = iPod_ListModes; | 143 this->ListModes = iPod_ListModes; |
144 this->SetVideoMode = iPod_SetVideoMode; | 144 this->SetVideoMode = iPod_SetVideoMode; |
145 this->SetColors = iPod_SetColors; | 145 this->SetColors = iPod_SetColors; |
172 }; | 172 }; |
173 | 173 |
174 //--// | 174 //--// |
175 | 175 |
176 static int | 176 static int |
177 iPod_VideoInit (_THIS, SDL_PixelFormat * vformat) | 177 iPod_VideoInit(_THIS, SDL_PixelFormat * vformat) |
178 { | 178 { |
179 if (!initd) { | 179 if (!initd) { |
180 /*** Code adapted/copied from SDL fbcon driver. ***/ | 180 /*** Code adapted/copied from SDL fbcon driver. ***/ |
181 | 181 |
182 static const char *const tty0[] = { "/dev/tty0", "/dev/vc/0", 0 }; | 182 static const char *const tty0[] = { "/dev/tty0", "/dev/vc/0", 0 }; |
183 static const char *const vcs[] = { "/dev/vc/%d", "/dev/tty%d", 0 }; | 183 static const char *const vcs[] = { "/dev/vc/%d", "/dev/tty%d", 0 }; |
184 int i, tty0_fd; | 184 int i, tty0_fd; |
185 | 185 |
186 dbgout = | 186 dbgout = |
187 fdopen (open ("/etc/sdlpod.log", O_WRONLY | O_SYNC | O_APPEND), | 187 fdopen(open("/etc/sdlpod.log", O_WRONLY | O_SYNC | O_APPEND), |
188 "a"); | 188 "a"); |
189 if (dbgout) { | 189 if (dbgout) { |
190 setbuf (dbgout, 0); | 190 setbuf(dbgout, 0); |
191 fprintf (dbgout, "--> Started SDL <--\n"); | 191 fprintf(dbgout, "--> Started SDL <--\n"); |
192 } | 192 } |
193 // Try to query for a free VT | 193 // Try to query for a free VT |
194 tty0_fd = -1; | 194 tty0_fd = -1; |
195 for (i = 0; tty0[i] && (tty0_fd < 0); ++i) { | 195 for (i = 0; tty0[i] && (tty0_fd < 0); ++i) { |
196 tty0_fd = open (tty0[i], O_WRONLY, 0); | 196 tty0_fd = open(tty0[i], O_WRONLY, 0); |
197 } | 197 } |
198 if (tty0_fd < 0) { | 198 if (tty0_fd < 0) { |
199 tty0_fd = dup (0); /* Maybe stdin is a VT? */ | 199 tty0_fd = dup(0); /* Maybe stdin is a VT? */ |
200 } | 200 } |
201 ioctl (tty0_fd, VT_OPENQRY, &curvt); | 201 ioctl(tty0_fd, VT_OPENQRY, &curvt); |
202 close (tty0_fd); | 202 close(tty0_fd); |
203 | 203 |
204 tty0_fd = open ("/dev/tty", O_RDWR, 0); | 204 tty0_fd = open("/dev/tty", O_RDWR, 0); |
205 if (tty0_fd >= 0) { | 205 if (tty0_fd >= 0) { |
206 ioctl (tty0_fd, TIOCNOTTY, 0); | 206 ioctl(tty0_fd, TIOCNOTTY, 0); |
207 close (tty0_fd); | 207 close(tty0_fd); |
208 } | 208 } |
209 | 209 |
210 if ((geteuid () == 0) && (curvt > 0)) { | 210 if ((geteuid() == 0) && (curvt > 0)) { |
211 for (i = 0; vcs[i] && (kbfd < 0); ++i) { | 211 for (i = 0; vcs[i] && (kbfd < 0); ++i) { |
212 char vtpath[12]; | 212 char vtpath[12]; |
213 | 213 |
214 SDL_snprintf (vtpath, SDL_arraysize (vtpath), vcs[i], curvt); | 214 SDL_snprintf(vtpath, SDL_arraysize(vtpath), vcs[i], curvt); |
215 kbfd = open (vtpath, O_RDWR); | 215 kbfd = open(vtpath, O_RDWR); |
216 } | 216 } |
217 } | 217 } |
218 if (kbfd < 0) { | 218 if (kbfd < 0) { |
219 if (dbgout) | 219 if (dbgout) |
220 fprintf (dbgout, "Couldn't open any VC\n"); | 220 fprintf(dbgout, "Couldn't open any VC\n"); |
221 return -1; | 221 return -1; |
222 } | 222 } |
223 if (dbgout) | 223 if (dbgout) |
224 fprintf (stderr, "Current VT: %d\n", curvt); | 224 fprintf(stderr, "Current VT: %d\n", curvt); |
225 | 225 |
226 if (kbfd >= 0) { | 226 if (kbfd >= 0) { |
227 /* Switch to the correct virtual terminal */ | 227 /* Switch to the correct virtual terminal */ |
228 if (curvt > 0) { | 228 if (curvt > 0) { |
229 struct vt_stat vtstate; | 229 struct vt_stat vtstate; |
230 | 230 |
231 if (ioctl (kbfd, VT_GETSTATE, &vtstate) == 0) { | 231 if (ioctl(kbfd, VT_GETSTATE, &vtstate) == 0) { |
232 oldvt = vtstate.v_active; | 232 oldvt = vtstate.v_active; |
233 } | 233 } |
234 if (ioctl (kbfd, VT_ACTIVATE, curvt) == 0) { | 234 if (ioctl(kbfd, VT_ACTIVATE, curvt) == 0) { |
235 if (dbgout) | 235 if (dbgout) |
236 fprintf (dbgout, "Waiting for switch to this VT... "); | 236 fprintf(dbgout, "Waiting for switch to this VT... "); |
237 ioctl (kbfd, VT_WAITACTIVE, curvt); | 237 ioctl(kbfd, VT_WAITACTIVE, curvt); |
238 if (dbgout) | 238 if (dbgout) |
239 fprintf (dbgout, "done!\n"); | 239 fprintf(dbgout, "done!\n"); |
240 } | 240 } |
241 } | 241 } |
242 // Set terminal input mode | 242 // Set terminal input mode |
243 if (tcgetattr (kbfd, &old_termios) < 0) { | 243 if (tcgetattr(kbfd, &old_termios) < 0) { |
244 if (dbgout) | 244 if (dbgout) |
245 fprintf (dbgout, "Can't get termios\n"); | 245 fprintf(dbgout, "Can't get termios\n"); |
246 return -1; | 246 return -1; |
247 } | 247 } |
248 cur_termios = old_termios; | 248 cur_termios = old_termios; |
249 // cur_termios.c_iflag &= ~(ICRNL | INPCK | ISTRIP | IXON); | 249 // cur_termios.c_iflag &= ~(ICRNL | INPCK | ISTRIP | IXON); |
250 // cur_termios.c_iflag |= (BRKINT); | 250 // cur_termios.c_iflag |= (BRKINT); |
255 cur_termios.c_iflag &= | 255 cur_termios.c_iflag &= |
256 ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON); | 256 ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON); |
257 cur_termios.c_cc[VMIN] = 0; | 257 cur_termios.c_cc[VMIN] = 0; |
258 cur_termios.c_cc[VTIME] = 0; | 258 cur_termios.c_cc[VTIME] = 0; |
259 | 259 |
260 if (tcsetattr (kbfd, TCSAFLUSH, &cur_termios) < 0) { | 260 if (tcsetattr(kbfd, TCSAFLUSH, &cur_termios) < 0) { |
261 if (dbgout) | 261 if (dbgout) |
262 fprintf (dbgout, "Can't set termios\n"); | 262 fprintf(dbgout, "Can't set termios\n"); |
263 return -1; | 263 return -1; |
264 } | 264 } |
265 if (ioctl (kbfd, KDSKBMODE, K_MEDIUMRAW) < 0) { | 265 if (ioctl(kbfd, KDSKBMODE, K_MEDIUMRAW) < 0) { |
266 if (dbgout) | 266 if (dbgout) |
267 fprintf (dbgout, "Can't set medium-raw mode\n"); | 267 fprintf(dbgout, "Can't set medium-raw mode\n"); |
268 return -1; | 268 return -1; |
269 } | 269 } |
270 if (ioctl (kbfd, KDSETMODE, KD_GRAPHICS) < 0) { | 270 if (ioctl(kbfd, KDSETMODE, KD_GRAPHICS) < 0) { |
271 if (dbgout) | 271 if (dbgout) |
272 fprintf (dbgout, "Can't set graphics\n"); | 272 fprintf(dbgout, "Can't set graphics\n"); |
273 return -1; | 273 return -1; |
274 } | 274 } |
275 } | 275 } |
276 // Open the framebuffer | 276 // Open the framebuffer |
277 if ((fbfd = open ("/dev/fb0", O_RDWR)) < 0) { | 277 if ((fbfd = open("/dev/fb0", O_RDWR)) < 0) { |
278 if (dbgout) | 278 if (dbgout) |
279 fprintf (dbgout, "Can't open framebuffer\n"); | 279 fprintf(dbgout, "Can't open framebuffer\n"); |
280 return -1; | 280 return -1; |
281 } else { | 281 } else { |
282 struct fb_var_screeninfo vinfo; | 282 struct fb_var_screeninfo vinfo; |
283 | 283 |
284 if (dbgout) | 284 if (dbgout) |
285 fprintf (dbgout, "Generation: %ld\n", generation); | 285 fprintf(dbgout, "Generation: %ld\n", generation); |
286 | 286 |
287 if (generation >= 40000) { | 287 if (generation >= 40000) { |
288 lcd_base = IPOD_NEW_LCD_BASE; | 288 lcd_base = IPOD_NEW_LCD_BASE; |
289 } else { | 289 } else { |
290 lcd_base = IPOD_OLD_LCD_BASE; | 290 lcd_base = IPOD_OLD_LCD_BASE; |
291 } | 291 } |
292 | 292 |
293 ioctl (fbfd, FBIOGET_VSCREENINFO, &vinfo); | 293 ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo); |
294 close (fbfd); | 294 close(fbfd); |
295 | 295 |
296 if (lcd_base == IPOD_OLD_LCD_BASE) | 296 if (lcd_base == IPOD_OLD_LCD_BASE) |
297 lcd_rtc = IPOD_OLD_LCD_RTC; | 297 lcd_rtc = IPOD_OLD_LCD_RTC; |
298 else if (lcd_base == IPOD_NEW_LCD_BASE) | 298 else if (lcd_base == IPOD_NEW_LCD_BASE) |
299 lcd_rtc = IPOD_NEW_LCD_RTC; | 299 lcd_rtc = IPOD_NEW_LCD_RTC; |
300 else { | 300 else { |
301 SDL_SetError ("Unknown iPod version"); | 301 SDL_SetError("Unknown iPod version"); |
302 return -1; | 302 return -1; |
303 } | 303 } |
304 | 304 |
305 lcd_width = vinfo.xres; | 305 lcd_width = vinfo.xres; |
306 lcd_height = vinfo.yres; | 306 lcd_height = vinfo.yres; |
307 | 307 |
308 if (dbgout) | 308 if (dbgout) |
309 fprintf (dbgout, "LCD is %dx%d\n", lcd_width, lcd_height); | 309 fprintf(dbgout, "LCD is %dx%d\n", lcd_width, lcd_height); |
310 } | 310 } |
311 | 311 |
312 fcntl (kbfd, F_SETFL, O_RDWR | O_NONBLOCK); | 312 fcntl(kbfd, F_SETFL, O_RDWR | O_NONBLOCK); |
313 | 313 |
314 /* Determine the current screen size */ | 314 /* Determine the current screen size */ |
315 this->info.current_w = lcd_width; | 315 this->info.current_w = lcd_width; |
316 this->info.current_h = lcd_height; | 316 this->info.current_h = lcd_height; |
317 | 317 |
325 vformat->Rmask = vformat->Gmask = vformat->Bmask = 0; | 325 vformat->Rmask = vformat->Gmask = vformat->Bmask = 0; |
326 } | 326 } |
327 | 327 |
328 initd = 1; | 328 initd = 1; |
329 if (dbgout) | 329 if (dbgout) |
330 fprintf (dbgout, "Initialized.\n\n"); | 330 fprintf(dbgout, "Initialized.\n\n"); |
331 } | 331 } |
332 return 0; | 332 return 0; |
333 } | 333 } |
334 | 334 |
335 static SDL_Rect ** | 335 static SDL_Rect ** |
336 iPod_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) | 336 iPod_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags) |
337 { | 337 { |
338 int width, height, fd; | 338 int width, height, fd; |
339 static SDL_Rect r; | 339 static SDL_Rect r; |
340 static SDL_Rect *rs[2] = { &r, 0 }; | 340 static SDL_Rect *rs[2] = { &r, 0 }; |
341 | 341 |
342 if ((fd = open ("/dev/fb0", O_RDWR)) < 0) { | 342 if ((fd = open("/dev/fb0", O_RDWR)) < 0) { |
343 return 0; | 343 return 0; |
344 } else { | 344 } else { |
345 struct fb_var_screeninfo vinfo; | 345 struct fb_var_screeninfo vinfo; |
346 | 346 |
347 ioctl (fbfd, FBIOGET_VSCREENINFO, &vinfo); | 347 ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo); |
348 close (fbfd); | 348 close(fbfd); |
349 | 349 |
350 width = vinfo.xres; | 350 width = vinfo.xres; |
351 height = vinfo.yres; | 351 height = vinfo.yres; |
352 } | 352 } |
353 r.x = r.y = 0; | 353 r.x = r.y = 0; |
356 return rs; | 356 return rs; |
357 } | 357 } |
358 | 358 |
359 | 359 |
360 static SDL_Surface * | 360 static SDL_Surface * |
361 iPod_SetVideoMode (_THIS, SDL_Surface * current, int width, int height, | 361 iPod_SetVideoMode(_THIS, SDL_Surface * current, int width, int height, |
362 int bpp, Uint32 flags) | 362 int bpp, Uint32 flags) |
363 { | 363 { |
364 Uint32 Rmask, Gmask, Bmask; | 364 Uint32 Rmask, Gmask, Bmask; |
365 if (bpp > 8) { | 365 if (bpp > 8) { |
366 Rmask = 0xF800; | 366 Rmask = 0xF800; |
367 Gmask = 0x07E0; | 367 Gmask = 0x07E0; |
369 } else { | 369 } else { |
370 Rmask = Gmask = Bmask = 0; | 370 Rmask = Gmask = Bmask = 0; |
371 } | 371 } |
372 | 372 |
373 if (this->hidden->buffer) | 373 if (this->hidden->buffer) |
374 SDL_free (this->hidden->buffer); | 374 SDL_free(this->hidden->buffer); |
375 this->hidden->buffer = SDL_malloc (width * height * (bpp / 8)); | 375 this->hidden->buffer = SDL_malloc(width * height * (bpp / 8)); |
376 if (!this->hidden->buffer) { | 376 if (!this->hidden->buffer) { |
377 SDL_SetError ("Couldn't allocate buffer for requested mode"); | 377 SDL_SetError("Couldn't allocate buffer for requested mode"); |
378 return 0; | 378 return 0; |
379 } | 379 } |
380 | 380 |
381 memset (this->hidden->buffer, 0, width * height * (bpp / 8)); | 381 memset(this->hidden->buffer, 0, width * height * (bpp / 8)); |
382 | 382 |
383 if (!SDL_ReallocFormat (current, bpp, Rmask, Gmask, Bmask, 0)) { | 383 if (!SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0)) { |
384 SDL_SetError ("Couldn't allocate new pixel format"); | 384 SDL_SetError("Couldn't allocate new pixel format"); |
385 SDL_free (this->hidden->buffer); | 385 SDL_free(this->hidden->buffer); |
386 this->hidden->buffer = 0; | 386 this->hidden->buffer = 0; |
387 return 0; | 387 return 0; |
388 } | 388 } |
389 | 389 |
390 if (bpp <= 8) { | 390 if (bpp <= 8) { |
406 | 406 |
407 return current; | 407 return current; |
408 } | 408 } |
409 | 409 |
410 static int | 410 static int |
411 iPod_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) | 411 iPod_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors) |
412 { | 412 { |
413 if (SDL_VideoSurface && SDL_VideoSurface->format | 413 if (SDL_VideoSurface && SDL_VideoSurface->format |
414 && SDL_VideoSurface->format->palette) { | 414 && SDL_VideoSurface->format->palette) { |
415 int i, j; | 415 int i, j; |
416 for (i = 0; i < 256; i += 4) { | 416 for (i = 0; i < 256; i += 4) { |
423 } | 423 } |
424 return 0; | 424 return 0; |
425 } | 425 } |
426 | 426 |
427 static void | 427 static void |
428 iPod_VideoQuit (_THIS) | 428 iPod_VideoQuit(_THIS) |
429 { | 429 { |
430 ioctl (kbfd, KDSETMODE, KD_TEXT); | 430 ioctl(kbfd, KDSETMODE, KD_TEXT); |
431 tcsetattr (kbfd, TCSAFLUSH, &old_termios); | 431 tcsetattr(kbfd, TCSAFLUSH, &old_termios); |
432 old_kbmode = -1; | 432 old_kbmode = -1; |
433 | 433 |
434 if (oldvt > 0) | 434 if (oldvt > 0) |
435 ioctl (kbfd, VT_ACTIVATE, oldvt); | 435 ioctl(kbfd, VT_ACTIVATE, oldvt); |
436 | 436 |
437 if (kbfd > 0) | 437 if (kbfd > 0) |
438 close (kbfd); | 438 close(kbfd); |
439 | 439 |
440 if (dbgout) { | 440 if (dbgout) { |
441 fprintf (dbgout, "<-- Ended SDL -->\n"); | 441 fprintf(dbgout, "<-- Ended SDL -->\n"); |
442 fclose (dbgout); | 442 fclose(dbgout); |
443 } | 443 } |
444 | 444 |
445 kbfd = -1; | 445 kbfd = -1; |
446 } | 446 } |
447 | 447 |
471 0 /* no key */ | 471 0 /* no key */ |
472 }; | 472 }; |
473 | 473 |
474 | 474 |
475 static void | 475 static void |
476 iPod_keyboard () | 476 iPod_keyboard() |
477 { | 477 { |
478 unsigned char keybuf[128]; | 478 unsigned char keybuf[128]; |
479 int i, nread; | 479 int i, nread; |
480 SDL_keysym keysym; | 480 SDL_keysym keysym; |
481 SDL_Event ev; | 481 SDL_Event ev; |
482 | 482 |
483 keysym.mod = 0; | 483 keysym.mod = 0; |
484 keysym.scancode = 0xff; | 484 keysym.scancode = 0xff; |
485 memset (&ev, 0, sizeof (SDL_Event)); | 485 memset(&ev, 0, sizeof(SDL_Event)); |
486 | 486 |
487 nread = read (kbfd, keybuf, 128); | 487 nread = read(kbfd, keybuf, 128); |
488 for (i = 0; i < nread; i++) { | 488 for (i = 0; i < nread; i++) { |
489 char ascii = iPod_SC_keymap[keybuf[i] & 0x7f]; | 489 char ascii = iPod_SC_keymap[keybuf[i] & 0x7f]; |
490 | 490 |
491 if (dbgout) | 491 if (dbgout) |
492 fprintf (dbgout, "Key! %02x is %c %s", keybuf[i], ascii, | 492 fprintf(dbgout, "Key! %02x is %c %s", keybuf[i], ascii, |
493 (keybuf[i] & 0x80) ? "up" : "down"); | 493 (keybuf[i] & 0x80) ? "up" : "down"); |
494 | 494 |
495 keysym.sym = keysym.unicode = ascii; | 495 keysym.sym = keysym.unicode = ascii; |
496 ev.type = (keybuf[i] & 0x80) ? SDL_KEYUP : SDL_KEYDOWN; | 496 ev.type = (keybuf[i] & 0x80) ? SDL_KEYUP : SDL_KEYDOWN; |
497 ev.key.state = 0; | 497 ev.key.state = 0; |
498 ev.key.keysym = keysym; | 498 ev.key.keysym = keysym; |
499 SDL_PushEvent (&ev); | 499 SDL_PushEvent(&ev); |
500 } | 500 } |
501 } | 501 } |
502 | 502 |
503 static void | 503 static void |
504 iPod_PumpEvents (_THIS) | 504 iPod_PumpEvents(_THIS) |
505 { | 505 { |
506 fd_set fdset; | 506 fd_set fdset; |
507 int max_fd = 0; | 507 int max_fd = 0; |
508 static struct timeval zero; | 508 static struct timeval zero; |
509 int posted; | 509 int posted; |
510 | 510 |
511 do { | 511 do { |
512 posted = 0; | 512 posted = 0; |
513 | 513 |
514 FD_ZERO (&fdset); | 514 FD_ZERO(&fdset); |
515 if (kbfd >= 0) { | 515 if (kbfd >= 0) { |
516 FD_SET (kbfd, &fdset); | 516 FD_SET(kbfd, &fdset); |
517 max_fd = kbfd; | 517 max_fd = kbfd; |
518 } | 518 } |
519 if (dbgout) | 519 if (dbgout) |
520 fprintf (dbgout, "Selecting"); | 520 fprintf(dbgout, "Selecting"); |
521 if (select (max_fd + 1, &fdset, 0, 0, &zero) > 0) { | 521 if (select(max_fd + 1, &fdset, 0, 0, &zero) > 0) { |
522 if (dbgout) | 522 if (dbgout) |
523 fprintf (dbgout, " -> match!\n"); | 523 fprintf(dbgout, " -> match!\n"); |
524 iPod_keyboard (); | 524 iPod_keyboard(); |
525 posted++; | 525 posted++; |
526 } | 526 } |
527 if (dbgout) | 527 if (dbgout) |
528 fprintf (dbgout, "\n"); | 528 fprintf(dbgout, "\n"); |
529 } | 529 } |
530 while (posted); | 530 while (posted); |
531 } | 531 } |
532 | 532 |
533 // enough space for 160x128x2 | 533 // enough space for 160x128x2 |
539 /*** The following LCD code is taken from Linux kernel uclinux-2.4.24-uc0-ipod2, | 539 /*** The following LCD code is taken from Linux kernel uclinux-2.4.24-uc0-ipod2, |
540 file arch/armnommu/mach-ipod/fb.c. A few modifications have been made. ***/ | 540 file arch/armnommu/mach-ipod/fb.c. A few modifications have been made. ***/ |
541 | 541 |
542 /* get current usec counter */ | 542 /* get current usec counter */ |
543 static int | 543 static int |
544 M_timer_get_current (void) | 544 M_timer_get_current(void) |
545 { | 545 { |
546 return inl (lcd_rtc); | 546 return inl(lcd_rtc); |
547 } | 547 } |
548 | 548 |
549 /* check if number of useconds has past */ | 549 /* check if number of useconds has past */ |
550 static int | 550 static int |
551 M_timer_check (int clock_start, int usecs) | 551 M_timer_check(int clock_start, int usecs) |
552 { | 552 { |
553 unsigned long clock; | 553 unsigned long clock; |
554 clock = inl (lcd_rtc); | 554 clock = inl(lcd_rtc); |
555 | 555 |
556 if ((clock - clock_start) >= usecs) { | 556 if ((clock - clock_start) >= usecs) { |
557 return 1; | 557 return 1; |
558 } else { | 558 } else { |
559 return 0; | 559 return 0; |
560 } | 560 } |
561 } | 561 } |
562 | 562 |
563 /* wait for LCD with timeout */ | 563 /* wait for LCD with timeout */ |
564 static void | 564 static void |
565 M_lcd_wait_write (void) | 565 M_lcd_wait_write(void) |
566 { | 566 { |
567 if ((inl (lcd_base) & 0x8000) != 0) { | 567 if ((inl(lcd_base) & 0x8000) != 0) { |
568 int start = M_timer_get_current (); | 568 int start = M_timer_get_current(); |
569 | 569 |
570 do { | 570 do { |
571 if ((inl (lcd_base) & (unsigned int) 0x8000) == 0) | 571 if ((inl(lcd_base) & (unsigned int) 0x8000) == 0) |
572 break; | 572 break; |
573 } | 573 } |
574 while (M_timer_check (start, 1000) == 0); | 574 while (M_timer_check(start, 1000) == 0); |
575 } | 575 } |
576 } | 576 } |
577 | 577 |
578 | 578 |
579 /* send LCD data */ | 579 /* send LCD data */ |
580 static void | 580 static void |
581 M_lcd_send_data (int data_lo, int data_hi) | 581 M_lcd_send_data(int data_lo, int data_hi) |
582 { | 582 { |
583 M_lcd_wait_write (); | 583 M_lcd_wait_write(); |
584 | 584 |
585 outl (data_lo, lcd_base + LCD_DATA); | 585 outl(data_lo, lcd_base + LCD_DATA); |
586 | 586 |
587 M_lcd_wait_write (); | 587 M_lcd_wait_write(); |
588 | 588 |
589 outl (data_hi, lcd_base + LCD_DATA); | 589 outl(data_hi, lcd_base + LCD_DATA); |
590 | 590 |
591 } | 591 } |
592 | 592 |
593 /* send LCD command */ | 593 /* send LCD command */ |
594 static void | 594 static void |
595 M_lcd_prepare_cmd (int cmd) | 595 M_lcd_prepare_cmd(int cmd) |
596 { | 596 { |
597 M_lcd_wait_write (); | 597 M_lcd_wait_write(); |
598 | 598 |
599 outl (0x0, lcd_base + LCD_CMD); | 599 outl(0x0, lcd_base + LCD_CMD); |
600 | 600 |
601 M_lcd_wait_write (); | 601 M_lcd_wait_write(); |
602 | 602 |
603 outl (cmd, lcd_base + LCD_CMD); | 603 outl(cmd, lcd_base + LCD_CMD); |
604 | 604 |
605 } | 605 } |
606 | 606 |
607 /* send LCD command and data */ | 607 /* send LCD command and data */ |
608 static void | 608 static void |
609 M_lcd_cmd_and_data (int cmd, int data_lo, int data_hi) | 609 M_lcd_cmd_and_data(int cmd, int data_lo, int data_hi) |
610 { | 610 { |
611 M_lcd_prepare_cmd (cmd); | 611 M_lcd_prepare_cmd(cmd); |
612 | 612 |
613 M_lcd_send_data (data_lo, data_hi); | 613 M_lcd_send_data(data_lo, data_hi); |
614 } | 614 } |
615 | 615 |
616 // Copied from uW | 616 // Copied from uW |
617 static void | 617 static void |
618 M_update_display (int sx, int sy, int mx, int my) | 618 M_update_display(int sx, int sy, int mx, int my) |
619 { | 619 { |
620 int y; | 620 int y; |
621 unsigned short cursor_pos; | 621 unsigned short cursor_pos; |
622 | 622 |
623 sx >>= 3; | 623 sx >>= 3; |
628 for (y = sy; y <= my; y++) { | 628 for (y = sy; y <= my; y++) { |
629 unsigned char *img_data; | 629 unsigned char *img_data; |
630 int x; | 630 int x; |
631 | 631 |
632 /* move the cursor */ | 632 /* move the cursor */ |
633 M_lcd_cmd_and_data (0x11, cursor_pos >> 8, cursor_pos & 0xff); | 633 M_lcd_cmd_and_data(0x11, cursor_pos >> 8, cursor_pos & 0xff); |
634 | 634 |
635 /* setup for printing */ | 635 /* setup for printing */ |
636 M_lcd_prepare_cmd (0x12); | 636 M_lcd_prepare_cmd(0x12); |
637 | 637 |
638 img_data = ipod_scr + (sx << 1) + (y * (lcd_width / 4)); | 638 img_data = ipod_scr + (sx << 1) + (y * (lcd_width / 4)); |
639 | 639 |
640 /* loops up to 160 times */ | 640 /* loops up to 160 times */ |
641 for (x = sx; x <= mx; x++) { | 641 for (x = sx; x <= mx; x++) { |
642 /* display eight pixels */ | 642 /* display eight pixels */ |
643 M_lcd_send_data (*(img_data + 1), *img_data); | 643 M_lcd_send_data(*(img_data + 1), *img_data); |
644 | 644 |
645 img_data += 2; | 645 img_data += 2; |
646 } | 646 } |
647 | 647 |
648 /* update cursor pos counter */ | 648 /* update cursor pos counter */ |
650 } | 650 } |
651 } | 651 } |
652 | 652 |
653 /* get current usec counter */ | 653 /* get current usec counter */ |
654 static int | 654 static int |
655 C_timer_get_current (void) | 655 C_timer_get_current(void) |
656 { | 656 { |
657 return inl (0x60005010); | 657 return inl(0x60005010); |
658 } | 658 } |
659 | 659 |
660 /* check if number of useconds has past */ | 660 /* check if number of useconds has past */ |
661 static int | 661 static int |
662 C_timer_check (int clock_start, int usecs) | 662 C_timer_check(int clock_start, int usecs) |
663 { | 663 { |
664 unsigned long clock; | 664 unsigned long clock; |
665 clock = inl (0x60005010); | 665 clock = inl(0x60005010); |
666 | 666 |
667 if ((clock - clock_start) >= usecs) { | 667 if ((clock - clock_start) >= usecs) { |
668 return 1; | 668 return 1; |
669 } else { | 669 } else { |
670 return 0; | 670 return 0; |
671 } | 671 } |
672 } | 672 } |
673 | 673 |
674 /* wait for LCD with timeout */ | 674 /* wait for LCD with timeout */ |
675 static void | 675 static void |
676 C_lcd_wait_write (void) | 676 C_lcd_wait_write(void) |
677 { | 677 { |
678 if ((inl (0x70008A0C) & 0x80000000) != 0) { | 678 if ((inl(0x70008A0C) & 0x80000000) != 0) { |
679 int start = C_timer_get_current (); | 679 int start = C_timer_get_current(); |
680 | 680 |
681 do { | 681 do { |
682 if ((inl (0x70008A0C) & 0x80000000) == 0) | 682 if ((inl(0x70008A0C) & 0x80000000) == 0) |
683 break; | 683 break; |
684 } | 684 } |
685 while (C_timer_check (start, 1000) == 0); | 685 while (C_timer_check(start, 1000) == 0); |
686 } | 686 } |
687 } | 687 } |
688 static void | 688 static void |
689 C_lcd_cmd_data (int cmd, int data) | 689 C_lcd_cmd_data(int cmd, int data) |
690 { | 690 { |
691 C_lcd_wait_write (); | 691 C_lcd_wait_write(); |
692 outl (cmd | 0x80000000, 0x70008A0C); | 692 outl(cmd | 0x80000000, 0x70008A0C); |
693 | 693 |
694 C_lcd_wait_write (); | 694 C_lcd_wait_write(); |
695 outl (data | 0x80000000, 0x70008A0C); | 695 outl(data | 0x80000000, 0x70008A0C); |
696 } | 696 } |
697 | 697 |
698 static void | 698 static void |
699 C_update_display (int sx, int sy, int mx, int my) | 699 C_update_display(int sx, int sy, int mx, int my) |
700 { | 700 { |
701 int height = (my - sy) + 1; | 701 int height = (my - sy) + 1; |
702 int width = (mx - sx) + 1; | 702 int width = (mx - sx) + 1; |
703 | 703 |
704 char *addr = SDL_VideoSurface->pixels; | 704 char *addr = SDL_VideoSurface->pixels; |
705 | 705 |
706 if (width & 1) | 706 if (width & 1) |
707 width++; | 707 width++; |
708 | 708 |
709 /* start X and Y */ | 709 /* start X and Y */ |
710 C_lcd_cmd_data (0x12, (sy & 0xff)); | 710 C_lcd_cmd_data(0x12, (sy & 0xff)); |
711 C_lcd_cmd_data (0x13, (((SDL_VideoSurface->w - 1) - sx) & 0xff)); | 711 C_lcd_cmd_data(0x13, (((SDL_VideoSurface->w - 1) - sx) & 0xff)); |
712 | 712 |
713 /* max X and Y */ | 713 /* max X and Y */ |
714 C_lcd_cmd_data (0x15, (((sy + height) - 1) & 0xff)); | 714 C_lcd_cmd_data(0x15, (((sy + height) - 1) & 0xff)); |
715 C_lcd_cmd_data (0x16, | 715 C_lcd_cmd_data(0x16, |
716 (((((SDL_VideoSurface->w - 1) - sx) - width) + | 716 (((((SDL_VideoSurface->w - 1) - sx) - width) + 1) & 0xff)); |
717 1) & 0xff)); | |
718 | 717 |
719 addr += sx + sy * SDL_VideoSurface->pitch; | 718 addr += sx + sy * SDL_VideoSurface->pitch; |
720 | 719 |
721 while (height > 0) { | 720 while (height > 0) { |
722 int h, x, y, pixels_to_write; | 721 int h, x, y, pixels_to_write; |
728 if (pixels_to_write > 64000) { | 727 if (pixels_to_write > 64000) { |
729 h = (64000 / 2) / width; | 728 h = (64000 / 2) / width; |
730 pixels_to_write = (width * h) * 2; | 729 pixels_to_write = (width * h) * 2; |
731 } | 730 } |
732 | 731 |
733 outl (0x10000080, 0x70008A20); | 732 outl(0x10000080, 0x70008A20); |
734 outl ((pixels_to_write - 1) | 0xC0010000, 0x70008A24); | 733 outl((pixels_to_write - 1) | 0xC0010000, 0x70008A24); |
735 outl (0x34000000, 0x70008A20); | 734 outl(0x34000000, 0x70008A20); |
736 | 735 |
737 /* for each row */ | 736 /* for each row */ |
738 for (x = 0; x < h; x++) { | 737 for (x = 0; x < h; x++) { |
739 /* for each column */ | 738 /* for each column */ |
740 for (y = 0; y < width; y += 2) { | 739 for (y = 0; y < width; y += 2) { |
741 unsigned two_pixels; | 740 unsigned two_pixels; |
742 | 741 |
743 two_pixels = addr[0] | (addr[1] << 16); | 742 two_pixels = addr[0] | (addr[1] << 16); |
744 addr += 2; | 743 addr += 2; |
745 | 744 |
746 while ((inl (0x70008A20) & 0x1000000) == 0); | 745 while ((inl(0x70008A20) & 0x1000000) == 0); |
747 | 746 |
748 /* output 2 pixels */ | 747 /* output 2 pixels */ |
749 outl (two_pixels, 0x70008B00); | 748 outl(two_pixels, 0x70008B00); |
750 } | 749 } |
751 | 750 |
752 addr += SDL_VideoSurface->w - width; | 751 addr += SDL_VideoSurface->w - width; |
753 } | 752 } |
754 | 753 |
755 while ((inl (0x70008A20) & 0x4000000) == 0); | 754 while ((inl(0x70008A20) & 0x4000000) == 0); |
756 | 755 |
757 outl (0x0, 0x70008A24); | 756 outl(0x0, 0x70008A24); |
758 | 757 |
759 height = height - h; | 758 height = height - h; |
760 } | 759 } |
761 } | 760 } |
762 | 761 |
763 // Should work with photo. However, I don't have one, so I'm not sure. | 762 // Should work with photo. However, I don't have one, so I'm not sure. |
764 static void | 763 static void |
765 iPod_UpdateRects (_THIS, int nrects, SDL_Rect * rects) | 764 iPod_UpdateRects(_THIS, int nrects, SDL_Rect * rects) |
766 { | 765 { |
767 if (SDL_VideoSurface->format->BitsPerPixel == 16) { | 766 if (SDL_VideoSurface->format->BitsPerPixel == 16) { |
768 C_update_display (0, 0, lcd_width, lcd_height); | 767 C_update_display(0, 0, lcd_width, lcd_height); |
769 } else { | 768 } else { |
770 int i, y, x; | 769 int i, y, x; |
771 for (i = 0; i < nrects; i++) { | 770 for (i = 0; i < nrects; i++) { |
772 SDL_Rect *r = rects + i; | 771 SDL_Rect *r = rects + i; |
773 if (!r) { | 772 if (!r) { |
787 3) << (2 * (x % 4)); | 786 3) << (2 * (x % 4)); |
788 } | 787 } |
789 } | 788 } |
790 } | 789 } |
791 | 790 |
792 M_update_display (0, 0, lcd_width, lcd_height); | 791 M_update_display(0, 0, lcd_width, lcd_height); |
793 } | 792 } |
794 } | 793 } |
795 | 794 |
796 /* vi: set ts=4 sw=4 expandtab: */ | 795 /* vi: set ts=4 sw=4 expandtab: */ |