#include <SDL/SDL.h>
#include <SDL/SDL_thread.h>

#include <unistd.h>   
#include <sys/types.h>                                                          
#include <sys/stat.h>                                                           
#include <fcntl.h>                                                              
#include <string.h>                                                             
#include <sys/time.h>                                                           
#include <dirent.h>                                                             
#include <limits.h>  
#include <errno.h> 
#include <stdlib.h>
#include <stdio.h>
#include <linux/soundcard.h>

SDL_Surface * screen, * surf;                                                            
SDL_Color colors[256];  
SDL_Thread *thredd;
char keypress;



void gl_fillbox(int whx, int why, int wid, int hei, int col){
  SDL_Rect rect;
  Uint32 pix;
  rect.w=wid;rect.h=hei;rect.x=whx;rect.y=why;
  pix=	SDL_MapRGB (screen->format, 0,col,0);

      SDL_FillRect (screen, &rect, pix);
}

int main(int argc, char **argv) {

  // init sdl argv[1] argv[2] as x and y

  int bpp,i; char xx; int x,y;
  int width=atoi(argv[1]);int height=atoi(argv[2]);     
 
 if (SDL_Init (SDL_INIT_VIDEO) < 0) {
    fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());         
    exit (1);                                                                    
 }
  SDL_ShowCursor (SDL_DISABLE);                                                 
                                                                                              
  atexit (SDL_Quit);           

  bpp =                                                                         
    SDL_VideoModeOK (width, height, 8, SDL_HWSURFACE | SDL_HWPALETTE);
                                                                
  screen =                                                                      
    SDL_SetVideoMode (width, height, bpp,SDL_HWSURFACE | SDL_HWPALETTE);
          
                                                                      
                                /* deal with colours */                                                         
  for (i=0;i<256;i++){                                                            
    colors[i].r=i;                                                                  
    colors[i].g=i;                                                                  
    colors[i].b=i;                                                                  
  }                      
            
  SDL_SetColors(screen, colors, 0, 256);           

  // read stdin

  while(1){

      for (y=0;y<height;y++){

    for (x=0;x<width;x++){



    xx=getchar();

    gl_fillbox(x,y,1,1, xx);
      }
    }

SDL_UpdateRect(screen,0,0,width,height);

  }
}
