From f75da270f738fdb49e1789840427fcb42ddc7aa8 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Tue, 2 May 2017 10:56:59 -0400 Subject: [PATCH] gr-sim: make it a library --- gr-sim/Makefile | 12 ++++++---- gr-sim/gr-sim.c | 57 +++++++++++++++++++++++++++++++++--------------- gr-sim/gr-sim.h | 8 +++++++ gr-sim/rainbow.c | 38 ++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 21 deletions(-) create mode 100644 gr-sim/gr-sim.h create mode 100644 gr-sim/rainbow.c diff --git a/gr-sim/Makefile b/gr-sim/Makefile index 91c84c9a..0d30ab55 100644 --- a/gr-sim/Makefile +++ b/gr-sim/Makefile @@ -5,15 +5,19 @@ LFLAGS = SDL_LIBS= `sdl-config --libs` SDL_INCLUDE= `sdl-config --cflags` -all: gr-sim +all: rainbow + +rainbow: rainbow.o gr-sim.o + $(CC) $(LFLAGS) $(SDL_LIBS) -o rainbow rainbow.o gr-sim.o + +rainbow.o: rainbow.c + $(CC) $(CFLAGS) -c rainbow.c -gr-sim: gr-sim.o - $(CC) $(LFLAGS) $(SDL_LIBS) -o gr-sim gr-sim.o gr-sim.o: gr-sim.c $(CC) $(CFLAGS) $(SDL_INCLUDE) -c gr-sim.c clean: - rm -f *~ *.o gr-sim + rm -f *~ *.o gr-sim rainbow diff --git a/gr-sim/gr-sim.c b/gr-sim/gr-sim.c index 33c02c45..1a241871 100644 --- a/gr-sim/gr-sim.c +++ b/gr-sim/gr-sim.c @@ -4,6 +4,8 @@ #include +#include "gr-sim.h" + #define XSIZE 40 #define YSIZE 48 @@ -15,7 +17,13 @@ static int ysize=YSIZE*PIXEL_Y_SCALE; static unsigned char framebuffer[XSIZE][YSIZE]; -static int get_input(void) { +/* 128kB of RAM */ +unsigned char ram[128*1024]; + + +static SDL_Surface *sdl_screen=NULL; + +int grsim_input(void) { SDL_Event event; int keypressed; @@ -71,12 +79,12 @@ static unsigned int color[16]={ 0xffffff, /* 15 white */ }; -static int gr_to_screen(SDL_Surface *screen) { +int grsim_update(void) { int x,y,i,j; unsigned int *t_pointer; - t_pointer=((Uint32 *)screen->pixels); + t_pointer=((Uint32 *)sdl_screen->pixels); for(y=0;y +#include +#include + +#include "gr-sim.h" + +int main(int argc, char **argv) { + + int x,y,ch; + + grsim_init(); + + /* Put rainbow on screen */ + for(y=0;y<40;y++) for(x=0;x<40;x++) { + color_equals(y%16); + plot(x,y); + } + + color_equals(15); + vlin(0,40,20); + + color_equals(0); + hlin(0,40,20); + + + while(1) { + grsim_update(); + + ch=grsim_input(); + + if (ch=='q') break; + + usleep(100000); + + } + + return 0; +}