eobish

diff src/main.cc @ 2:cdbcae5b3b98

added fblib
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 18 Jan 2015 03:16:37 +0200
parents 465ca72c9657
children
line diff
     1.1 --- a/src/main.cc	Sat Jan 17 18:40:49 2015 +0200
     1.2 +++ b/src/main.cc	Sun Jan 18 03:16:37 2015 +0200
     1.3 @@ -1,81 +1,36 @@
     1.4  #include <stdio.h>
     1.5 -#include <SDL/SDL.h>
     1.6 +#include "fblib.h"
     1.7  
     1.8  static void display();
     1.9 -static bool proc_event(SDL_Event *ev);
    1.10 -static void set_pal_entry(int idx, int r, int g, int b);
    1.11 -
    1.12 -static SDL_Surface *fbsurf;
    1.13  
    1.14  int main(int argc, char **argv)
    1.15  {
    1.16 -	SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
    1.17 -
    1.18 -	if(!(fbsurf = SDL_SetVideoMode(320, 240, 8, SDL_SWSURFACE))) {
    1.19 -		fprintf(stderr, "failed to set video mode\n");
    1.20 +	if(fb_init(320, 240, 8) == -1) {
    1.21  		return 1;
    1.22  	}
    1.23 -	set_pal_entry(1, 255, 0, 0);
    1.24 +	fb_set_palette_entry(1, 255, 0, 0);
    1.25  
    1.26  	for(;;) {
    1.27 -		SDL_Event ev;
    1.28 -		while(SDL_PollEvent(&ev)) {
    1.29 -			if(!proc_event(&ev)) {
    1.30 -				goto done;
    1.31 -			}
    1.32 +		if(fb_process_events() == -1) {
    1.33 +			break;
    1.34  		}
    1.35 -
    1.36  		display();
    1.37  	}
    1.38  
    1.39  done:
    1.40 -	SDL_Quit();
    1.41 +	fb_shutdown();
    1.42  	return 0;
    1.43  }
    1.44  
    1.45  void display()
    1.46  {
    1.47 -	if(SDL_MUSTLOCK(fbsurf)) {
    1.48 -		SDL_LockSurface(fbsurf);
    1.49 -	}
    1.50 +	int width = fb_get_width();
    1.51 +	int height = fb_get_height();
    1.52 +	unsigned char *pixels = (unsigned char*)fb_begin_frame();
    1.53  
    1.54 -	unsigned char *pixels = (unsigned char*)fbsurf->pixels;
    1.55 -	for(int i=0; i<fbsurf->w * fbsurf->h; i++) {
    1.56 +	for(int i=0; i<width * height; i++) {
    1.57  		*pixels++ = 1;
    1.58  	}
    1.59  
    1.60 -	if(SDL_MUSTLOCK(fbsurf)) {
    1.61 -		SDL_UnlockSurface(fbsurf);
    1.62 -	}
    1.63 -
    1.64 -	SDL_Flip(fbsurf);
    1.65 +	fb_end_frame();
    1.66  }
    1.67 -
    1.68 -static bool proc_event(SDL_Event *ev)
    1.69 -{
    1.70 -	switch(ev->type) {
    1.71 -	case SDL_KEYDOWN:
    1.72 -		if(ev->key.keysym.sym == SDLK_ESCAPE) {
    1.73 -			return false;
    1.74 -		}
    1.75 -		break;
    1.76 -
    1.77 -	default:
    1.78 -		break;
    1.79 -	}
    1.80 -	return true;
    1.81 -}
    1.82 -
    1.83 -static void set_pal_entry(int idx, int r, int g, int b)
    1.84 -{
    1.85 -	SDL_Color col;
    1.86 -	col.r = r;
    1.87 -	col.g = g;
    1.88 -	col.b = b;
    1.89 -
    1.90 -	SDL_SetPalette(fbsurf, SDL_LOGPAL | SDL_PHYSPAL, &col, idx, 1);
    1.91 -
    1.92 -	/*palette[idx].r = r;
    1.93 -	palette[idx].g = g;
    1.94 -	palette[idx].b = b;*/
    1.95 -}