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