src/video/ipod/SDL_ipodvideo.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1545 8d9bb0cf2c2a
child 1668 4da1ee79c9af
     1.1 --- a/src/video/ipod/SDL_ipodvideo.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/src/video/ipod/SDL_ipodvideo.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -45,15 +45,19 @@
     1.4  
     1.5  #define _THIS SDL_VideoDevice *this
     1.6  
     1.7 -static int iPod_VideoInit (_THIS, SDL_PixelFormat *vformat);
     1.8 -static SDL_Rect **iPod_ListModes (_THIS, SDL_PixelFormat *format, Uint32 flags);
     1.9 -static SDL_Surface *iPod_SetVideoMode (_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
    1.10 -static int iPod_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color *colors);
    1.11 -static void iPod_UpdateRects (_THIS, int nrects, SDL_Rect *rects);
    1.12 +static int iPod_VideoInit (_THIS, SDL_PixelFormat * vformat);
    1.13 +static SDL_Rect **iPod_ListModes (_THIS, SDL_PixelFormat * format,
    1.14 +                                  Uint32 flags);
    1.15 +static SDL_Surface *iPod_SetVideoMode (_THIS, SDL_Surface * current,
    1.16 +                                       int width, int height, int bpp,
    1.17 +                                       Uint32 flags);
    1.18 +static int iPod_SetColors (_THIS, int firstcolor, int ncolors,
    1.19 +                           SDL_Color * colors);
    1.20 +static void iPod_UpdateRects (_THIS, int nrects, SDL_Rect * rects);
    1.21  static void iPod_VideoQuit (_THIS);
    1.22  static void iPod_PumpEvents (_THIS);
    1.23  
    1.24 -static long iPod_GetGeneration();
    1.25 +static long iPod_GetGeneration ();
    1.26  
    1.27  static int initd = 0;
    1.28  static int kbfd = -1;
    1.29 @@ -75,57 +79,65 @@
    1.30  
    1.31  static unsigned long lcd_base, lcd_rtc, lcd_width, lcd_height;
    1.32  
    1.33 -static long iPod_GetGeneration() 
    1.34 +static long
    1.35 +iPod_GetGeneration ()
    1.36  {
    1.37      int i;
    1.38      char cpuinfo[256];
    1.39      char *ptr;
    1.40      FILE *file;
    1.41 -    
    1.42 -    if ((file = fopen("/proc/cpuinfo", "r")) != NULL) {
    1.43 -	while (fgets(cpuinfo, sizeof(cpuinfo), file) != NULL)
    1.44 -	    if (SDL_strncmp(cpuinfo, "Revision", 8) == 0)
    1.45 -		break;
    1.46 -	fclose(file);
    1.47 +
    1.48 +    if ((file = fopen ("/proc/cpuinfo", "r")) != NULL) {
    1.49 +        while (fgets (cpuinfo, sizeof (cpuinfo), file) != NULL)
    1.50 +            if (SDL_strncmp (cpuinfo, "Revision", 8) == 0)
    1.51 +                break;
    1.52 +        fclose (file);
    1.53      }
    1.54 -    for (i = 0; !isspace(cpuinfo[i]); i++);
    1.55 -    for (; isspace(cpuinfo[i]); i++);
    1.56 +    for (i = 0; !isspace (cpuinfo[i]); i++);
    1.57 +    for (; isspace (cpuinfo[i]); i++);
    1.58      ptr = cpuinfo + i + 2;
    1.59 -    
    1.60 -    return SDL_strtol(ptr, NULL, 10);
    1.61 +
    1.62 +    return SDL_strtol (ptr, NULL, 10);
    1.63  }
    1.64  
    1.65 -static int iPod_Available() 
    1.66 +static int
    1.67 +iPod_Available ()
    1.68  {
    1.69      return 1;
    1.70  }
    1.71  
    1.72 -static void iPod_DeleteDevice (SDL_VideoDevice *device)
    1.73 +static void
    1.74 +iPod_DeleteDevice (SDL_VideoDevice * device)
    1.75  {
    1.76      free (device->hidden);
    1.77      free (device);
    1.78  }
    1.79  
    1.80 -void iPod_InitOSKeymap (_THIS) {}
    1.81 +void
    1.82 +iPod_InitOSKeymap (_THIS)
    1.83 +{
    1.84 +}
    1.85  
    1.86 -static SDL_VideoDevice *iPod_CreateDevice (int devindex)
    1.87 +static SDL_VideoDevice *
    1.88 +iPod_CreateDevice (int devindex)
    1.89  {
    1.90      SDL_VideoDevice *this;
    1.91 -    
    1.92 -    this = (SDL_VideoDevice *)SDL_malloc (sizeof(SDL_VideoDevice));
    1.93 +
    1.94 +    this = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice));
    1.95      if (this) {
    1.96 -	memset (this, 0, sizeof *this);
    1.97 -	this->hidden = (struct SDL_PrivateVideoData *) SDL_malloc (sizeof(struct SDL_PrivateVideoData));
    1.98 +        memset (this, 0, sizeof *this);
    1.99 +        this->hidden = (struct SDL_PrivateVideoData *)
   1.100 +            SDL_malloc (sizeof (struct SDL_PrivateVideoData));
   1.101      }
   1.102      if (!this || !this->hidden) {
   1.103 -	SDL_OutOfMemory();
   1.104 -	if (this)
   1.105 -	    SDL_free (this);
   1.106 -	return 0;
   1.107 +        SDL_OutOfMemory ();
   1.108 +        if (this)
   1.109 +            SDL_free (this);
   1.110 +        return 0;
   1.111      }
   1.112 -    memset (this->hidden, 0, sizeof(struct SDL_PrivateVideoData));
   1.113 -    
   1.114 -    generation = iPod_GetGeneration();
   1.115 +    memset (this->hidden, 0, sizeof (struct SDL_PrivateVideoData));
   1.116 +
   1.117 +    generation = iPod_GetGeneration ();
   1.118  
   1.119      this->VideoInit = iPod_VideoInit;
   1.120      this->ListModes = iPod_ListModes;
   1.121 @@ -161,168 +173,182 @@
   1.122  
   1.123  //--//
   1.124  
   1.125 -static int iPod_VideoInit (_THIS, SDL_PixelFormat *vformat)
   1.126 +static int
   1.127 +iPod_VideoInit (_THIS, SDL_PixelFormat * vformat)
   1.128  {
   1.129      if (!initd) {
   1.130 -	/*** Code adapted/copied from SDL fbcon driver. ***/
   1.131 +        /*** Code adapted/copied from SDL fbcon driver. ***/
   1.132  
   1.133 -	static const char * const tty0[] = { "/dev/tty0", "/dev/vc/0", 0 };
   1.134 -	static const char * const vcs[] = { "/dev/vc/%d", "/dev/tty%d", 0 };
   1.135 -	int i, tty0_fd;
   1.136 +        static const char *const tty0[] = { "/dev/tty0", "/dev/vc/0", 0 };
   1.137 +        static const char *const vcs[] = { "/dev/vc/%d", "/dev/tty%d", 0 };
   1.138 +        int i, tty0_fd;
   1.139  
   1.140 -	dbgout = fdopen (open ("/etc/sdlpod.log", O_WRONLY | O_SYNC | O_APPEND), "a");
   1.141 -	if (dbgout) {
   1.142 -	    setbuf (dbgout, 0);
   1.143 -	    fprintf (dbgout, "--> Started SDL <--\n");
   1.144 -	}
   1.145 +        dbgout =
   1.146 +            fdopen (open ("/etc/sdlpod.log", O_WRONLY | O_SYNC | O_APPEND),
   1.147 +                    "a");
   1.148 +        if (dbgout) {
   1.149 +            setbuf (dbgout, 0);
   1.150 +            fprintf (dbgout, "--> Started SDL <--\n");
   1.151 +        }
   1.152 +        // Try to query for a free VT
   1.153 +        tty0_fd = -1;
   1.154 +        for (i = 0; tty0[i] && (tty0_fd < 0); ++i) {
   1.155 +            tty0_fd = open (tty0[i], O_WRONLY, 0);
   1.156 +        }
   1.157 +        if (tty0_fd < 0) {
   1.158 +            tty0_fd = dup (0);  /* Maybe stdin is a VT? */
   1.159 +        }
   1.160 +        ioctl (tty0_fd, VT_OPENQRY, &curvt);
   1.161 +        close (tty0_fd);
   1.162  
   1.163 -	// Try to query for a free VT
   1.164 -	tty0_fd = -1;
   1.165 -	for ( i=0; tty0[i] && (tty0_fd < 0); ++i ) {
   1.166 -	    tty0_fd = open(tty0[i], O_WRONLY, 0);
   1.167 -	}
   1.168 -	if ( tty0_fd < 0 ) {
   1.169 -	    tty0_fd = dup(0); /* Maybe stdin is a VT? */
   1.170 -	}
   1.171 -	ioctl(tty0_fd, VT_OPENQRY, &curvt);
   1.172 -	close(tty0_fd);
   1.173 +        tty0_fd = open ("/dev/tty", O_RDWR, 0);
   1.174 +        if (tty0_fd >= 0) {
   1.175 +            ioctl (tty0_fd, TIOCNOTTY, 0);
   1.176 +            close (tty0_fd);
   1.177 +        }
   1.178  
   1.179 -	tty0_fd = open("/dev/tty", O_RDWR, 0);
   1.180 -	if ( tty0_fd >= 0 ) {
   1.181 -	    ioctl(tty0_fd, TIOCNOTTY, 0);
   1.182 -	    close(tty0_fd);
   1.183 -	}
   1.184 +        if ((geteuid () == 0) && (curvt > 0)) {
   1.185 +            for (i = 0; vcs[i] && (kbfd < 0); ++i) {
   1.186 +                char vtpath[12];
   1.187  
   1.188 -	if ( (geteuid() == 0) && (curvt > 0) ) {
   1.189 -	    for ( i=0; vcs[i] && (kbfd < 0); ++i ) {
   1.190 -		char vtpath[12];
   1.191 -		
   1.192 -		SDL_snprintf(vtpath, SDL_arraysize(vtpath), vcs[i], curvt);
   1.193 -		kbfd = open(vtpath, O_RDWR);
   1.194 -	    }
   1.195 -	}
   1.196 -	if ( kbfd < 0 ) {
   1.197 -	    if (dbgout) fprintf (dbgout, "Couldn't open any VC\n");
   1.198 -	    return -1;
   1.199 -	}
   1.200 -	if (dbgout) fprintf (stderr, "Current VT: %d\n", curvt);
   1.201 +                SDL_snprintf (vtpath, SDL_arraysize (vtpath), vcs[i], curvt);
   1.202 +                kbfd = open (vtpath, O_RDWR);
   1.203 +            }
   1.204 +        }
   1.205 +        if (kbfd < 0) {
   1.206 +            if (dbgout)
   1.207 +                fprintf (dbgout, "Couldn't open any VC\n");
   1.208 +            return -1;
   1.209 +        }
   1.210 +        if (dbgout)
   1.211 +            fprintf (stderr, "Current VT: %d\n", curvt);
   1.212  
   1.213 -	if (kbfd >= 0) {
   1.214 -	    /* Switch to the correct virtual terminal */
   1.215 -	    if ( curvt > 0 ) {
   1.216 -		struct vt_stat vtstate;
   1.217 -		
   1.218 -		if ( ioctl(kbfd, VT_GETSTATE, &vtstate) == 0 ) {
   1.219 -		    oldvt = vtstate.v_active;
   1.220 -		}
   1.221 -		if ( ioctl(kbfd, VT_ACTIVATE, curvt) == 0 ) {
   1.222 -		    if (dbgout) fprintf (dbgout, "Waiting for switch to this VT... ");
   1.223 -		    ioctl(kbfd, VT_WAITACTIVE, curvt);
   1.224 -		    if (dbgout) fprintf (dbgout, "done!\n");
   1.225 -		}
   1.226 -	    }
   1.227 +        if (kbfd >= 0) {
   1.228 +            /* Switch to the correct virtual terminal */
   1.229 +            if (curvt > 0) {
   1.230 +                struct vt_stat vtstate;
   1.231  
   1.232 -	    // Set terminal input mode
   1.233 -	    if (tcgetattr (kbfd, &old_termios) < 0) {
   1.234 -		if (dbgout) fprintf (dbgout, "Can't get termios\n");
   1.235 -		return -1;
   1.236 -	    }
   1.237 -	    cur_termios = old_termios;
   1.238 -	    //	    cur_termios.c_iflag &= ~(ICRNL | INPCK | ISTRIP | IXON);
   1.239 -	    //	    cur_termios.c_iflag |= (BRKINT);
   1.240 -	    //	    cur_termios.c_lflag &= ~(ICANON | ECHO | ISIG | IEXTEN);
   1.241 -	    //	    cur_termios.c_oflag &= ~(OPOST);
   1.242 -	    //	    cur_termios.c_oflag |= (ONOCR | ONLRET);
   1.243 -	    cur_termios.c_lflag &= ~(ICANON | ECHO | ISIG);
   1.244 -	    cur_termios.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);
   1.245 -	    cur_termios.c_cc[VMIN] = 0;
   1.246 -	    cur_termios.c_cc[VTIME] = 0;
   1.247 -	    
   1.248 -	    if (tcsetattr (kbfd, TCSAFLUSH, &cur_termios) < 0) {
   1.249 -		if (dbgout) fprintf (dbgout, "Can't set termios\n");
   1.250 -		return -1;
   1.251 -	    }
   1.252 -	    if (ioctl (kbfd, KDSKBMODE, K_MEDIUMRAW) < 0) {
   1.253 -		if (dbgout) fprintf (dbgout, "Can't set medium-raw mode\n");
   1.254 -		return -1;
   1.255 -	    }
   1.256 -	    if (ioctl (kbfd, KDSETMODE, KD_GRAPHICS) < 0) {
   1.257 -		if (dbgout) fprintf (dbgout, "Can't set graphics\n");
   1.258 -		return -1;
   1.259 -	    }
   1.260 -	}
   1.261 +                if (ioctl (kbfd, VT_GETSTATE, &vtstate) == 0) {
   1.262 +                    oldvt = vtstate.v_active;
   1.263 +                }
   1.264 +                if (ioctl (kbfd, VT_ACTIVATE, curvt) == 0) {
   1.265 +                    if (dbgout)
   1.266 +                        fprintf (dbgout, "Waiting for switch to this VT... ");
   1.267 +                    ioctl (kbfd, VT_WAITACTIVE, curvt);
   1.268 +                    if (dbgout)
   1.269 +                        fprintf (dbgout, "done!\n");
   1.270 +                }
   1.271 +            }
   1.272 +            // Set terminal input mode
   1.273 +            if (tcgetattr (kbfd, &old_termios) < 0) {
   1.274 +                if (dbgout)
   1.275 +                    fprintf (dbgout, "Can't get termios\n");
   1.276 +                return -1;
   1.277 +            }
   1.278 +            cur_termios = old_termios;
   1.279 +            //      cur_termios.c_iflag &= ~(ICRNL | INPCK | ISTRIP | IXON);
   1.280 +            //      cur_termios.c_iflag |= (BRKINT);
   1.281 +            //      cur_termios.c_lflag &= ~(ICANON | ECHO | ISIG | IEXTEN);
   1.282 +            //      cur_termios.c_oflag &= ~(OPOST);
   1.283 +            //      cur_termios.c_oflag |= (ONOCR | ONLRET);
   1.284 +            cur_termios.c_lflag &= ~(ICANON | ECHO | ISIG);
   1.285 +            cur_termios.c_iflag &=
   1.286 +                ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);
   1.287 +            cur_termios.c_cc[VMIN] = 0;
   1.288 +            cur_termios.c_cc[VTIME] = 0;
   1.289  
   1.290 -	// Open the framebuffer
   1.291 -	if ((fbfd = open ("/dev/fb0", O_RDWR)) < 0) {
   1.292 -	    if (dbgout) fprintf (dbgout, "Can't open framebuffer\n");
   1.293 -	    return -1;
   1.294 -	} else {
   1.295 -	    struct fb_var_screeninfo vinfo;
   1.296 +            if (tcsetattr (kbfd, TCSAFLUSH, &cur_termios) < 0) {
   1.297 +                if (dbgout)
   1.298 +                    fprintf (dbgout, "Can't set termios\n");
   1.299 +                return -1;
   1.300 +            }
   1.301 +            if (ioctl (kbfd, KDSKBMODE, K_MEDIUMRAW) < 0) {
   1.302 +                if (dbgout)
   1.303 +                    fprintf (dbgout, "Can't set medium-raw mode\n");
   1.304 +                return -1;
   1.305 +            }
   1.306 +            if (ioctl (kbfd, KDSETMODE, KD_GRAPHICS) < 0) {
   1.307 +                if (dbgout)
   1.308 +                    fprintf (dbgout, "Can't set graphics\n");
   1.309 +                return -1;
   1.310 +            }
   1.311 +        }
   1.312 +        // Open the framebuffer
   1.313 +        if ((fbfd = open ("/dev/fb0", O_RDWR)) < 0) {
   1.314 +            if (dbgout)
   1.315 +                fprintf (dbgout, "Can't open framebuffer\n");
   1.316 +            return -1;
   1.317 +        } else {
   1.318 +            struct fb_var_screeninfo vinfo;
   1.319  
   1.320 -	    if (dbgout) fprintf (dbgout, "Generation: %ld\n", generation);
   1.321 +            if (dbgout)
   1.322 +                fprintf (dbgout, "Generation: %ld\n", generation);
   1.323  
   1.324 -	    if (generation >= 40000) {
   1.325 -		lcd_base = IPOD_NEW_LCD_BASE;
   1.326 -	    } else {
   1.327 -		lcd_base = IPOD_OLD_LCD_BASE;
   1.328 -	    }
   1.329 -	    
   1.330 -	    ioctl (fbfd, FBIOGET_VSCREENINFO, &vinfo);
   1.331 -	    close (fbfd);
   1.332 +            if (generation >= 40000) {
   1.333 +                lcd_base = IPOD_NEW_LCD_BASE;
   1.334 +            } else {
   1.335 +                lcd_base = IPOD_OLD_LCD_BASE;
   1.336 +            }
   1.337  
   1.338 -	    if (lcd_base == IPOD_OLD_LCD_BASE)
   1.339 -		lcd_rtc = IPOD_OLD_LCD_RTC;
   1.340 -	    else if (lcd_base == IPOD_NEW_LCD_BASE)
   1.341 -		lcd_rtc = IPOD_NEW_LCD_RTC;
   1.342 -	    else {
   1.343 -		SDL_SetError ("Unknown iPod version");
   1.344 -		return -1;
   1.345 -	    }
   1.346 +            ioctl (fbfd, FBIOGET_VSCREENINFO, &vinfo);
   1.347 +            close (fbfd);
   1.348  
   1.349 -	    lcd_width = vinfo.xres;
   1.350 -	    lcd_height = vinfo.yres;
   1.351 +            if (lcd_base == IPOD_OLD_LCD_BASE)
   1.352 +                lcd_rtc = IPOD_OLD_LCD_RTC;
   1.353 +            else if (lcd_base == IPOD_NEW_LCD_BASE)
   1.354 +                lcd_rtc = IPOD_NEW_LCD_RTC;
   1.355 +            else {
   1.356 +                SDL_SetError ("Unknown iPod version");
   1.357 +                return -1;
   1.358 +            }
   1.359  
   1.360 -	    if (dbgout) fprintf (dbgout, "LCD is %dx%d\n", lcd_width, lcd_height);
   1.361 -	}
   1.362 +            lcd_width = vinfo.xres;
   1.363 +            lcd_height = vinfo.yres;
   1.364  
   1.365 -	fcntl (kbfd, F_SETFL, O_RDWR | O_NONBLOCK);
   1.366 +            if (dbgout)
   1.367 +                fprintf (dbgout, "LCD is %dx%d\n", lcd_width, lcd_height);
   1.368 +        }
   1.369  
   1.370 -	/* Determine the current screen size */
   1.371 -	this->info.current_w = lcd_width;
   1.372 -	this->info.current_h = lcd_height;
   1.373 +        fcntl (kbfd, F_SETFL, O_RDWR | O_NONBLOCK);
   1.374  
   1.375 -	if ((generation >= 60000) && (generation < 70000)) {
   1.376 -	    vformat->BitsPerPixel = 16;
   1.377 -	    vformat->Rmask = 0xF800;
   1.378 -	    vformat->Gmask = 0x07E0;
   1.379 -	    vformat->Bmask = 0x001F;
   1.380 -	} else {
   1.381 -	    vformat->BitsPerPixel = 8;
   1.382 -	    vformat->Rmask = vformat->Gmask = vformat->Bmask = 0;
   1.383 -	}
   1.384 +        /* Determine the current screen size */
   1.385 +        this->info.current_w = lcd_width;
   1.386 +        this->info.current_h = lcd_height;
   1.387  
   1.388 -	initd = 1;
   1.389 -	if (dbgout) fprintf (dbgout, "Initialized.\n\n");
   1.390 +        if ((generation >= 60000) && (generation < 70000)) {
   1.391 +            vformat->BitsPerPixel = 16;
   1.392 +            vformat->Rmask = 0xF800;
   1.393 +            vformat->Gmask = 0x07E0;
   1.394 +            vformat->Bmask = 0x001F;
   1.395 +        } else {
   1.396 +            vformat->BitsPerPixel = 8;
   1.397 +            vformat->Rmask = vformat->Gmask = vformat->Bmask = 0;
   1.398 +        }
   1.399 +
   1.400 +        initd = 1;
   1.401 +        if (dbgout)
   1.402 +            fprintf (dbgout, "Initialized.\n\n");
   1.403      }
   1.404      return 0;
   1.405  }
   1.406  
   1.407 -static SDL_Rect **iPod_ListModes (_THIS, SDL_PixelFormat *format, Uint32 flags)
   1.408 +static SDL_Rect **
   1.409 +iPod_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
   1.410  {
   1.411      int width, height, fd;
   1.412      static SDL_Rect r;
   1.413      static SDL_Rect *rs[2] = { &r, 0 };
   1.414  
   1.415      if ((fd = open ("/dev/fb0", O_RDWR)) < 0) {
   1.416 -	return 0;
   1.417 +        return 0;
   1.418      } else {
   1.419 -	struct fb_var_screeninfo vinfo;
   1.420 -	
   1.421 -	ioctl (fbfd, FBIOGET_VSCREENINFO, &vinfo);
   1.422 -	close (fbfd);
   1.423 -	
   1.424 -	width = vinfo.xres;
   1.425 -	height = vinfo.yres;
   1.426 +        struct fb_var_screeninfo vinfo;
   1.427 +
   1.428 +        ioctl (fbfd, FBIOGET_VSCREENINFO, &vinfo);
   1.429 +        close (fbfd);
   1.430 +
   1.431 +        width = vinfo.xres;
   1.432 +        height = vinfo.yres;
   1.433      }
   1.434      r.x = r.y = 0;
   1.435      r.w = width;
   1.436 @@ -331,43 +357,45 @@
   1.437  }
   1.438  
   1.439  
   1.440 -static SDL_Surface *iPod_SetVideoMode (_THIS, SDL_Surface *current, int width, int height, int bpp,
   1.441 -				       Uint32 flags)
   1.442 +static SDL_Surface *
   1.443 +iPod_SetVideoMode (_THIS, SDL_Surface * current, int width, int height,
   1.444 +                   int bpp, Uint32 flags)
   1.445  {
   1.446      Uint32 Rmask, Gmask, Bmask;
   1.447      if (bpp > 8) {
   1.448 -	Rmask = 0xF800;
   1.449 -	Gmask = 0x07E0;
   1.450 -	Bmask = 0x001F;	
   1.451 +        Rmask = 0xF800;
   1.452 +        Gmask = 0x07E0;
   1.453 +        Bmask = 0x001F;
   1.454      } else {
   1.455 -	Rmask = Gmask = Bmask = 0;
   1.456 +        Rmask = Gmask = Bmask = 0;
   1.457      }
   1.458  
   1.459 -    if (this->hidden->buffer) SDL_free (this->hidden->buffer);
   1.460 +    if (this->hidden->buffer)
   1.461 +        SDL_free (this->hidden->buffer);
   1.462      this->hidden->buffer = SDL_malloc (width * height * (bpp / 8));
   1.463      if (!this->hidden->buffer) {
   1.464 -	SDL_SetError ("Couldn't allocate buffer for requested mode");
   1.465 -	return 0;
   1.466 +        SDL_SetError ("Couldn't allocate buffer for requested mode");
   1.467 +        return 0;
   1.468      }
   1.469  
   1.470      memset (this->hidden->buffer, 0, width * height * (bpp / 8));
   1.471  
   1.472      if (!SDL_ReallocFormat (current, bpp, Rmask, Gmask, Bmask, 0)) {
   1.473 -	SDL_SetError ("Couldn't allocate new pixel format");
   1.474 -	SDL_free (this->hidden->buffer);
   1.475 -	this->hidden->buffer = 0;
   1.476 -	return 0;
   1.477 +        SDL_SetError ("Couldn't allocate new pixel format");
   1.478 +        SDL_free (this->hidden->buffer);
   1.479 +        this->hidden->buffer = 0;
   1.480 +        return 0;
   1.481      }
   1.482  
   1.483      if (bpp <= 8) {
   1.484 -	int i, j;
   1.485 -	for (i = 0; i < 256; i += 4) {
   1.486 -	    for (j = 0; j < 4; j++) {
   1.487 -		current->format->palette->colors[i+j].r = 85 * j;
   1.488 -		current->format->palette->colors[i+j].g = 85 * j;
   1.489 -		current->format->palette->colors[i+j].b = 85 * j;
   1.490 -	    }
   1.491 -	}
   1.492 +        int i, j;
   1.493 +        for (i = 0; i < 256; i += 4) {
   1.494 +            for (j = 0; j < 4; j++) {
   1.495 +                current->format->palette->colors[i + j].r = 85 * j;
   1.496 +                current->format->palette->colors[i + j].g = 85 * j;
   1.497 +                current->format->palette->colors[i + j].b = 85 * j;
   1.498 +            }
   1.499 +        }
   1.500      }
   1.501  
   1.502      current->flags = flags & SDL_FULLSCREEN;
   1.503 @@ -379,69 +407,73 @@
   1.504      return current;
   1.505  }
   1.506  
   1.507 -static int iPod_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color *colors)
   1.508 +static int
   1.509 +iPod_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors)
   1.510  {
   1.511 -    if (SDL_VideoSurface && SDL_VideoSurface->format && SDL_VideoSurface->format->palette) {
   1.512 -	int i, j;
   1.513 -	for (i = 0; i < 256; i += 4) {
   1.514 -	    for (j = 0; j < 4; j++) {
   1.515 -		SDL_VideoSurface->format->palette->colors[i+j].r = 85 * j;
   1.516 -		SDL_VideoSurface->format->palette->colors[i+j].g = 85 * j;
   1.517 -		SDL_VideoSurface->format->palette->colors[i+j].b = 85 * j;
   1.518 -	    }
   1.519 -	}
   1.520 +    if (SDL_VideoSurface && SDL_VideoSurface->format
   1.521 +        && SDL_VideoSurface->format->palette) {
   1.522 +        int i, j;
   1.523 +        for (i = 0; i < 256; i += 4) {
   1.524 +            for (j = 0; j < 4; j++) {
   1.525 +                SDL_VideoSurface->format->palette->colors[i + j].r = 85 * j;
   1.526 +                SDL_VideoSurface->format->palette->colors[i + j].g = 85 * j;
   1.527 +                SDL_VideoSurface->format->palette->colors[i + j].b = 85 * j;
   1.528 +            }
   1.529 +        }
   1.530      }
   1.531      return 0;
   1.532  }
   1.533  
   1.534 -static void iPod_VideoQuit (_THIS)
   1.535 +static void
   1.536 +iPod_VideoQuit (_THIS)
   1.537  {
   1.538      ioctl (kbfd, KDSETMODE, KD_TEXT);
   1.539      tcsetattr (kbfd, TCSAFLUSH, &old_termios);
   1.540      old_kbmode = -1;
   1.541  
   1.542      if (oldvt > 0)
   1.543 -	ioctl (kbfd, VT_ACTIVATE, oldvt);
   1.544 -    
   1.545 +        ioctl (kbfd, VT_ACTIVATE, oldvt);
   1.546 +
   1.547      if (kbfd > 0)
   1.548 -	close (kbfd);
   1.549 +        close (kbfd);
   1.550  
   1.551      if (dbgout) {
   1.552 -	fprintf (dbgout, "<-- Ended SDL -->\n");
   1.553 -	fclose (dbgout);
   1.554 +        fprintf (dbgout, "<-- Ended SDL -->\n");
   1.555 +        fclose (dbgout);
   1.556      }
   1.557 -    
   1.558 +
   1.559      kbfd = -1;
   1.560  }
   1.561  
   1.562  static char iPod_SC_keymap[] = {
   1.563 -    0,				/* 0 - no key */
   1.564 -    '[' - 0x40,			/* ESC (Ctrl+[) */
   1.565 +    0,                          /* 0 - no key */
   1.566 +    '[' - 0x40,                 /* ESC (Ctrl+[) */
   1.567      '1', '2', '3', '4', '5', '6', '7', '8', '9',
   1.568      '-', '=',
   1.569 -    '\b', '\t',			/* Backspace, Tab (Ctrl+H,Ctrl+I) */
   1.570 +    '\b', '\t',                 /* Backspace, Tab (Ctrl+H,Ctrl+I) */
   1.571      'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']',
   1.572 -    '\n', 0,			/* Enter, Left CTRL */
   1.573 +    '\n', 0,                    /* Enter, Left CTRL */
   1.574      'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`',
   1.575 -    0, '\\',			/* left shift, backslash */
   1.576 +    0, '\\',                    /* left shift, backslash */
   1.577      'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/',
   1.578 -    0, '*', 0, ' ', 0,		/* right shift, KP mul, left alt, space, capslock */
   1.579 -    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F1-10 */
   1.580 -    0, 0,			/* numlock, scrollock */
   1.581 -    '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', /* numeric keypad */
   1.582 -    0, 0,			/* padding */
   1.583 -    0, 0, 0,			/* "less" (?), F11, F12 */
   1.584 -    0, 0, 0, 0, 0, 0, 0,	/* padding */
   1.585 -    '\n', 0, '/', 0, 0,	/* KP enter, Rctrl, Ctrl, KP div, PrtSc, RAlt */
   1.586 -    0, 0, 0, 0, 0, 0, 0, 0, 0,	/* Break, Home, Up, PgUp, Left, Right, End, Down, PgDn */
   1.587 -    0, 0,			/* Ins, Del */
   1.588 -    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* padding */
   1.589 -    0, 0,			/* RWin, LWin */
   1.590 -    0				/* no key */
   1.591 +    0, '*', 0, ' ', 0,          /* right shift, KP mul, left alt, space, capslock */
   1.592 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* F1-10 */
   1.593 +    0, 0,                       /* numlock, scrollock */
   1.594 +    '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.',    /* numeric keypad */
   1.595 +    0, 0,                       /* padding */
   1.596 +    0, 0, 0,                    /* "less" (?), F11, F12 */
   1.597 +    0, 0, 0, 0, 0, 0, 0,        /* padding */
   1.598 +    '\n', 0, '/', 0, 0,         /* KP enter, Rctrl, Ctrl, KP div, PrtSc, RAlt */
   1.599 +    0, 0, 0, 0, 0, 0, 0, 0, 0,  /* Break, Home, Up, PgUp, Left, Right, End, Down, PgDn */
   1.600 +    0, 0,                       /* Ins, Del */
   1.601 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      /* padding */
   1.602 +    0, 0,                       /* RWin, LWin */
   1.603 +    0                           /* no key */
   1.604  };
   1.605 -    
   1.606  
   1.607 -static void iPod_keyboard() 
   1.608 +
   1.609 +static void
   1.610 +iPod_keyboard ()
   1.611  {
   1.612      unsigned char keybuf[128];
   1.613      int i, nread;
   1.614 @@ -450,23 +482,26 @@
   1.615  
   1.616      keysym.mod = 0;
   1.617      keysym.scancode = 0xff;
   1.618 -    memset (&ev, 0, sizeof(SDL_Event));
   1.619 +    memset (&ev, 0, sizeof (SDL_Event));
   1.620  
   1.621      nread = read (kbfd, keybuf, 128);
   1.622      for (i = 0; i < nread; i++) {
   1.623 -	char ascii = iPod_SC_keymap[keybuf[i] & 0x7f];
   1.624 +        char ascii = iPod_SC_keymap[keybuf[i] & 0x7f];
   1.625  
   1.626 -	if (dbgout) fprintf (dbgout, "Key! %02x is %c %s", keybuf[i], ascii, (keybuf[i] & 0x80)? "up" : "down");
   1.627 +        if (dbgout)
   1.628 +            fprintf (dbgout, "Key! %02x is %c %s", keybuf[i], ascii,
   1.629 +                     (keybuf[i] & 0x80) ? "up" : "down");
   1.630  
   1.631 -	keysym.sym = keysym.unicode = ascii;
   1.632 -	ev.type = (keybuf[i] & 0x80)? SDL_KEYUP : SDL_KEYDOWN;
   1.633 -	ev.key.state = 0;
   1.634 -	ev.key.keysym = keysym;
   1.635 -	SDL_PushEvent (&ev);
   1.636 +        keysym.sym = keysym.unicode = ascii;
   1.637 +        ev.type = (keybuf[i] & 0x80) ? SDL_KEYUP : SDL_KEYDOWN;
   1.638 +        ev.key.state = 0;
   1.639 +        ev.key.keysym = keysym;
   1.640 +        SDL_PushEvent (&ev);
   1.641      }
   1.642  }
   1.643  
   1.644 -static void iPod_PumpEvents (_THIS) 
   1.645 +static void
   1.646 +iPod_PumpEvents (_THIS)
   1.647  {
   1.648      fd_set fdset;
   1.649      int max_fd = 0;
   1.650 @@ -474,25 +509,29 @@
   1.651      int posted;
   1.652  
   1.653      do {
   1.654 -	posted = 0;
   1.655 +        posted = 0;
   1.656  
   1.657 -	FD_ZERO (&fdset);
   1.658 -	if (kbfd >= 0) {
   1.659 -	    FD_SET (kbfd, &fdset);
   1.660 -	    max_fd = kbfd;
   1.661 -	}
   1.662 -	if (dbgout) fprintf (dbgout, "Selecting");
   1.663 -	if (select (max_fd + 1, &fdset, 0, 0, &zero) > 0) {
   1.664 -	    if (dbgout) fprintf (dbgout, " -> match!\n");
   1.665 -	    iPod_keyboard();
   1.666 -	    posted++;
   1.667 -	}
   1.668 -	if (dbgout) fprintf (dbgout, "\n");
   1.669 -    } while (posted);
   1.670 +        FD_ZERO (&fdset);
   1.671 +        if (kbfd >= 0) {
   1.672 +            FD_SET (kbfd, &fdset);
   1.673 +            max_fd = kbfd;
   1.674 +        }
   1.675 +        if (dbgout)
   1.676 +            fprintf (dbgout, "Selecting");
   1.677 +        if (select (max_fd + 1, &fdset, 0, 0, &zero) > 0) {
   1.678 +            if (dbgout)
   1.679 +                fprintf (dbgout, " -> match!\n");
   1.680 +            iPod_keyboard ();
   1.681 +            posted++;
   1.682 +        }
   1.683 +        if (dbgout)
   1.684 +            fprintf (dbgout, "\n");
   1.685 +    }
   1.686 +    while (posted);
   1.687  }
   1.688  
   1.689  // enough space for 160x128x2
   1.690 -static char ipod_scr[160 * (128/4)];
   1.691 +static char ipod_scr[160 * (128 / 4)];
   1.692  
   1.693  #define outl(datum,addr) (*(volatile unsigned long *)(addr) = (datum))
   1.694  #define inl(addr) (*(volatile unsigned long *)(addr))
   1.695 @@ -501,233 +540,257 @@
   1.696       file arch/armnommu/mach-ipod/fb.c. A few modifications have been made. ***/
   1.697  
   1.698  /* get current usec counter */
   1.699 -static int M_timer_get_current(void)
   1.700 +static int
   1.701 +M_timer_get_current (void)
   1.702  {
   1.703 -	return inl(lcd_rtc);
   1.704 +    return inl (lcd_rtc);
   1.705  }
   1.706  
   1.707  /* check if number of useconds has past */
   1.708 -static int M_timer_check(int clock_start, int usecs)
   1.709 +static int
   1.710 +M_timer_check (int clock_start, int usecs)
   1.711  {
   1.712 -	unsigned long clock;
   1.713 -	clock = inl(lcd_rtc);
   1.714 -	
   1.715 -	if ( (clock - clock_start) >= usecs ) {
   1.716 -		return 1;
   1.717 -	} else {
   1.718 -		return 0;
   1.719 -	}
   1.720 +    unsigned long clock;
   1.721 +    clock = inl (lcd_rtc);
   1.722 +
   1.723 +    if ((clock - clock_start) >= usecs) {
   1.724 +        return 1;
   1.725 +    } else {
   1.726 +        return 0;
   1.727 +    }
   1.728  }
   1.729  
   1.730  /* wait for LCD with timeout */
   1.731 -static void M_lcd_wait_write(void)
   1.732 +static void
   1.733 +M_lcd_wait_write (void)
   1.734  {
   1.735 -	if ( (inl(lcd_base) & 0x8000) != 0 ) {
   1.736 -		int start = M_timer_get_current();
   1.737 -			
   1.738 -		do {
   1.739 -			if ( (inl(lcd_base) & (unsigned int)0x8000) == 0 ) 
   1.740 -				break;
   1.741 -		} while ( M_timer_check(start, 1000) == 0 );
   1.742 -	}
   1.743 +    if ((inl (lcd_base) & 0x8000) != 0) {
   1.744 +        int start = M_timer_get_current ();
   1.745 +
   1.746 +        do {
   1.747 +            if ((inl (lcd_base) & (unsigned int) 0x8000) == 0)
   1.748 +                break;
   1.749 +        }
   1.750 +        while (M_timer_check (start, 1000) == 0);
   1.751 +    }
   1.752  }
   1.753  
   1.754  
   1.755  /* send LCD data */
   1.756 -static void M_lcd_send_data(int data_lo, int data_hi)
   1.757 +static void
   1.758 +M_lcd_send_data (int data_lo, int data_hi)
   1.759  {
   1.760 -	M_lcd_wait_write();
   1.761 -	
   1.762 -	outl(data_lo, lcd_base + LCD_DATA);
   1.763 -		
   1.764 -	M_lcd_wait_write();
   1.765 -	
   1.766 -	outl(data_hi, lcd_base + LCD_DATA);
   1.767 +    M_lcd_wait_write ();
   1.768 +
   1.769 +    outl (data_lo, lcd_base + LCD_DATA);
   1.770 +
   1.771 +    M_lcd_wait_write ();
   1.772 +
   1.773 +    outl (data_hi, lcd_base + LCD_DATA);
   1.774  
   1.775  }
   1.776  
   1.777  /* send LCD command */
   1.778  static void
   1.779 -M_lcd_prepare_cmd(int cmd)
   1.780 +M_lcd_prepare_cmd (int cmd)
   1.781  {
   1.782 -	M_lcd_wait_write();
   1.783 +    M_lcd_wait_write ();
   1.784  
   1.785 -	outl(0x0, lcd_base + LCD_CMD);
   1.786 +    outl (0x0, lcd_base + LCD_CMD);
   1.787  
   1.788 -	M_lcd_wait_write();
   1.789 -	
   1.790 -	outl(cmd, lcd_base + LCD_CMD);
   1.791 -	
   1.792 +    M_lcd_wait_write ();
   1.793 +
   1.794 +    outl (cmd, lcd_base + LCD_CMD);
   1.795 +
   1.796  }
   1.797  
   1.798  /* send LCD command and data */
   1.799 -static void M_lcd_cmd_and_data(int cmd, int data_lo, int data_hi)
   1.800 +static void
   1.801 +M_lcd_cmd_and_data (int cmd, int data_lo, int data_hi)
   1.802  {
   1.803 -	M_lcd_prepare_cmd(cmd);
   1.804 +    M_lcd_prepare_cmd (cmd);
   1.805  
   1.806 -	M_lcd_send_data(data_lo, data_hi);
   1.807 +    M_lcd_send_data (data_lo, data_hi);
   1.808  }
   1.809  
   1.810  // Copied from uW
   1.811 -static void M_update_display(int sx, int sy, int mx, int my)
   1.812 +static void
   1.813 +M_update_display (int sx, int sy, int mx, int my)
   1.814  {
   1.815 -	int y;
   1.816 -	unsigned short cursor_pos;
   1.817 +    int y;
   1.818 +    unsigned short cursor_pos;
   1.819  
   1.820 -	sx >>= 3;
   1.821 -	mx >>= 3;
   1.822 +    sx >>= 3;
   1.823 +    mx >>= 3;
   1.824  
   1.825 -	cursor_pos = sx + (sy << 5);
   1.826 +    cursor_pos = sx + (sy << 5);
   1.827  
   1.828 -	for ( y = sy; y <= my; y++ ) {
   1.829 -		unsigned char *img_data;
   1.830 -		int x;
   1.831 +    for (y = sy; y <= my; y++) {
   1.832 +        unsigned char *img_data;
   1.833 +        int x;
   1.834  
   1.835 -		/* move the cursor */
   1.836 -		M_lcd_cmd_and_data(0x11, cursor_pos >> 8, cursor_pos & 0xff);
   1.837 +        /* move the cursor */
   1.838 +        M_lcd_cmd_and_data (0x11, cursor_pos >> 8, cursor_pos & 0xff);
   1.839  
   1.840 -		/* setup for printing */
   1.841 -		M_lcd_prepare_cmd(0x12);
   1.842 +        /* setup for printing */
   1.843 +        M_lcd_prepare_cmd (0x12);
   1.844  
   1.845 -		img_data = ipod_scr + (sx << 1) + (y * (lcd_width/4));
   1.846 +        img_data = ipod_scr + (sx << 1) + (y * (lcd_width / 4));
   1.847  
   1.848 -		/* loops up to 160 times */
   1.849 -		for ( x = sx; x <= mx; x++ ) {
   1.850 -		        /* display eight pixels */
   1.851 -			M_lcd_send_data(*(img_data + 1), *img_data);
   1.852 +        /* loops up to 160 times */
   1.853 +        for (x = sx; x <= mx; x++) {
   1.854 +            /* display eight pixels */
   1.855 +            M_lcd_send_data (*(img_data + 1), *img_data);
   1.856  
   1.857 -			img_data += 2;
   1.858 -		}
   1.859 +            img_data += 2;
   1.860 +        }
   1.861  
   1.862 -		/* update cursor pos counter */
   1.863 -		cursor_pos += 0x20;
   1.864 -	}
   1.865 +        /* update cursor pos counter */
   1.866 +        cursor_pos += 0x20;
   1.867 +    }
   1.868  }
   1.869  
   1.870  /* get current usec counter */
   1.871 -static int C_timer_get_current(void)
   1.872 +static int
   1.873 +C_timer_get_current (void)
   1.874  {
   1.875 -	return inl(0x60005010);
   1.876 +    return inl (0x60005010);
   1.877  }
   1.878  
   1.879  /* check if number of useconds has past */
   1.880 -static int C_timer_check(int clock_start, int usecs)
   1.881 +static int
   1.882 +C_timer_check (int clock_start, int usecs)
   1.883  {
   1.884 -	unsigned long clock;
   1.885 -	clock = inl(0x60005010);
   1.886 -	
   1.887 -	if ( (clock - clock_start) >= usecs ) {
   1.888 -		return 1;
   1.889 -	} else {
   1.890 -		return 0;
   1.891 -	}
   1.892 +    unsigned long clock;
   1.893 +    clock = inl (0x60005010);
   1.894 +
   1.895 +    if ((clock - clock_start) >= usecs) {
   1.896 +        return 1;
   1.897 +    } else {
   1.898 +        return 0;
   1.899 +    }
   1.900  }
   1.901  
   1.902  /* wait for LCD with timeout */
   1.903 -static void C_lcd_wait_write(void)
   1.904 +static void
   1.905 +C_lcd_wait_write (void)
   1.906  {
   1.907 -	if ((inl(0x70008A0C) & 0x80000000) != 0) {
   1.908 -		int start = C_timer_get_current();
   1.909 -			
   1.910 -		do {
   1.911 -			if ((inl(0x70008A0C) & 0x80000000) == 0) 
   1.912 -				break;
   1.913 -		} while (C_timer_check(start, 1000) == 0);
   1.914 -	}
   1.915 +    if ((inl (0x70008A0C) & 0x80000000) != 0) {
   1.916 +        int start = C_timer_get_current ();
   1.917 +
   1.918 +        do {
   1.919 +            if ((inl (0x70008A0C) & 0x80000000) == 0)
   1.920 +                break;
   1.921 +        }
   1.922 +        while (C_timer_check (start, 1000) == 0);
   1.923 +    }
   1.924  }
   1.925 -static void C_lcd_cmd_data(int cmd, int data)
   1.926 +static void
   1.927 +C_lcd_cmd_data (int cmd, int data)
   1.928  {
   1.929 -	C_lcd_wait_write();
   1.930 -	outl(cmd | 0x80000000, 0x70008A0C);
   1.931 +    C_lcd_wait_write ();
   1.932 +    outl (cmd | 0x80000000, 0x70008A0C);
   1.933  
   1.934 -	C_lcd_wait_write();
   1.935 -	outl(data | 0x80000000, 0x70008A0C);
   1.936 +    C_lcd_wait_write ();
   1.937 +    outl (data | 0x80000000, 0x70008A0C);
   1.938  }
   1.939  
   1.940 -static void C_update_display(int sx, int sy, int mx, int my)
   1.941 +static void
   1.942 +C_update_display (int sx, int sy, int mx, int my)
   1.943  {
   1.944 -	int height = (my - sy) + 1;
   1.945 -	int width = (mx - sx) + 1;
   1.946 +    int height = (my - sy) + 1;
   1.947 +    int width = (mx - sx) + 1;
   1.948  
   1.949 -	char *addr = SDL_VideoSurface->pixels;
   1.950 +    char *addr = SDL_VideoSurface->pixels;
   1.951  
   1.952 -	if (width & 1) width++;
   1.953 +    if (width & 1)
   1.954 +        width++;
   1.955  
   1.956 -	/* start X and Y */
   1.957 -	C_lcd_cmd_data(0x12, (sy & 0xff));
   1.958 -	C_lcd_cmd_data(0x13, (((SDL_VideoSurface->w - 1) - sx) & 0xff));
   1.959 +    /* start X and Y */
   1.960 +    C_lcd_cmd_data (0x12, (sy & 0xff));
   1.961 +    C_lcd_cmd_data (0x13, (((SDL_VideoSurface->w - 1) - sx) & 0xff));
   1.962  
   1.963 -	/* max X and Y */
   1.964 -	C_lcd_cmd_data(0x15, (((sy + height) - 1) & 0xff));
   1.965 -	C_lcd_cmd_data(0x16, (((((SDL_VideoSurface->w - 1) - sx) - width) + 1) & 0xff));
   1.966 +    /* max X and Y */
   1.967 +    C_lcd_cmd_data (0x15, (((sy + height) - 1) & 0xff));
   1.968 +    C_lcd_cmd_data (0x16,
   1.969 +                    (((((SDL_VideoSurface->w - 1) - sx) - width) +
   1.970 +                      1) & 0xff));
   1.971  
   1.972 -	addr += sx + sy * SDL_VideoSurface->pitch;
   1.973 +    addr += sx + sy * SDL_VideoSurface->pitch;
   1.974  
   1.975 -	while (height > 0) {
   1.976 -		int h, x, y, pixels_to_write;
   1.977 +    while (height > 0) {
   1.978 +        int h, x, y, pixels_to_write;
   1.979  
   1.980 -		pixels_to_write = (width * height) * 2;
   1.981 +        pixels_to_write = (width * height) * 2;
   1.982  
   1.983 -		/* calculate how much we can do in one go */
   1.984 -		h = height;
   1.985 -		if (pixels_to_write > 64000) {
   1.986 -			h = (64000/2) / width;
   1.987 -			pixels_to_write = (width * h) * 2;
   1.988 -		}
   1.989 +        /* calculate how much we can do in one go */
   1.990 +        h = height;
   1.991 +        if (pixels_to_write > 64000) {
   1.992 +            h = (64000 / 2) / width;
   1.993 +            pixels_to_write = (width * h) * 2;
   1.994 +        }
   1.995  
   1.996 -		outl(0x10000080, 0x70008A20);
   1.997 -		outl((pixels_to_write - 1) | 0xC0010000, 0x70008A24);
   1.998 -		outl(0x34000000, 0x70008A20);
   1.999 +        outl (0x10000080, 0x70008A20);
  1.1000 +        outl ((pixels_to_write - 1) | 0xC0010000, 0x70008A24);
  1.1001 +        outl (0x34000000, 0x70008A20);
  1.1002  
  1.1003 -		/* for each row */
  1.1004 -		for (x = 0; x < h; x++)
  1.1005 -		{
  1.1006 -			/* for each column */
  1.1007 -			for (y = 0; y < width; y += 2) {
  1.1008 -				unsigned two_pixels;
  1.1009 +        /* for each row */
  1.1010 +        for (x = 0; x < h; x++) {
  1.1011 +            /* for each column */
  1.1012 +            for (y = 0; y < width; y += 2) {
  1.1013 +                unsigned two_pixels;
  1.1014  
  1.1015 -				two_pixels = addr[0] | (addr[1] << 16);
  1.1016 -				addr += 2;
  1.1017 +                two_pixels = addr[0] | (addr[1] << 16);
  1.1018 +                addr += 2;
  1.1019  
  1.1020 -				while ((inl(0x70008A20) & 0x1000000) == 0);
  1.1021 +                while ((inl (0x70008A20) & 0x1000000) == 0);
  1.1022  
  1.1023 -				/* output 2 pixels */
  1.1024 -				outl(two_pixels, 0x70008B00);
  1.1025 -			}
  1.1026 +                /* output 2 pixels */
  1.1027 +                outl (two_pixels, 0x70008B00);
  1.1028 +            }
  1.1029  
  1.1030 -			addr += SDL_VideoSurface->w - width;
  1.1031 -		}
  1.1032 +            addr += SDL_VideoSurface->w - width;
  1.1033 +        }
  1.1034  
  1.1035 -		while ((inl(0x70008A20) & 0x4000000) == 0);
  1.1036 +        while ((inl (0x70008A20) & 0x4000000) == 0);
  1.1037  
  1.1038 -		outl(0x0, 0x70008A24);
  1.1039 +        outl (0x0, 0x70008A24);
  1.1040  
  1.1041 -		height = height - h;
  1.1042 -	}
  1.1043 +        height = height - h;
  1.1044 +    }
  1.1045  }
  1.1046  
  1.1047  // Should work with photo. However, I don't have one, so I'm not sure.
  1.1048 -static void iPod_UpdateRects (_THIS, int nrects, SDL_Rect *rects) 
  1.1049 +static void
  1.1050 +iPod_UpdateRects (_THIS, int nrects, SDL_Rect * rects)
  1.1051  {
  1.1052      if (SDL_VideoSurface->format->BitsPerPixel == 16) {
  1.1053 -	C_update_display (0, 0, lcd_width, lcd_height);
  1.1054 +        C_update_display (0, 0, lcd_width, lcd_height);
  1.1055      } else {
  1.1056 -	int i, y, x;
  1.1057 -	for (i = 0; i < nrects; i++) {
  1.1058 -	    SDL_Rect *r = rects + i;
  1.1059 -	    if (!r) {
  1.1060 -		continue;
  1.1061 -	    }
  1.1062 -	    
  1.1063 -	    for (y = r->y; (y < r->y + r->h) && y < lcd_height; y++) {
  1.1064 -		for (x = r->x; (x < r->x + r->w) && x < lcd_width; x++) {
  1.1065 -		    ipod_scr[y*(lcd_width/4) + x/4] &= ~(3 << (2 * (x%4)));
  1.1066 -		    ipod_scr[y*(lcd_width/4) + x/4] |=
  1.1067 -			(((Uint8*)(SDL_VideoSurface->pixels))[ y*SDL_VideoSurface->pitch + x ] & 3) << (2 * (x%4));
  1.1068 -		}
  1.1069 -	    }
  1.1070 -	}
  1.1071 -	
  1.1072 -	M_update_display (0, 0, lcd_width, lcd_height);
  1.1073 +        int i, y, x;
  1.1074 +        for (i = 0; i < nrects; i++) {
  1.1075 +            SDL_Rect *r = rects + i;
  1.1076 +            if (!r) {
  1.1077 +                continue;
  1.1078 +            }
  1.1079 +
  1.1080 +            for (y = r->y; (y < r->y + r->h) && y < lcd_height; y++) {
  1.1081 +                for (x = r->x; (x < r->x + r->w) && x < lcd_width; x++) {
  1.1082 +                    ipod_scr[y * (lcd_width / 4) + x / 4] &=
  1.1083 +                        ~(3 << (2 * (x % 4)));
  1.1084 +                    ipod_scr[y * (lcd_width / 4) + x / 4] |=
  1.1085 +                        (((Uint8 *) (SDL_VideoSurface->pixels))[y *
  1.1086 +                                                                SDL_VideoSurface->
  1.1087 +                                                                pitch
  1.1088 +                                                                +
  1.1089 +                                                                x] &
  1.1090 +                         3) << (2 * (x % 4));
  1.1091 +                }
  1.1092 +            }
  1.1093 +        }
  1.1094 +
  1.1095 +        M_update_display (0, 0, lcd_width, lcd_height);
  1.1096      }
  1.1097  }
  1.1098 +
  1.1099 +/* vi: set ts=4 sw=4 expandtab: */