From 0ba7850819572931f67d28ebca0cc7d73d7c6dea Mon Sep 17 00:00:00 2001 From: hackbard Date: Fri, 21 Mar 2003 12:53:15 +0000 Subject: [PATCH] added display support (init by now) (dfb-api) --- Makefile | 4 +- defines.h | 44 ++++++++++++++-------- display.c | 55 +++++++++++++++++++++++++++ main.c | 110 +++++++++++++++++++++++++++++++++++++----------------- random.c | 11 +++--- 5 files changed, 167 insertions(+), 57 deletions(-) create mode 100644 display.c diff --git a/Makefile b/Makefile index 4f1c9c9..8949339 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,10 @@ INCLUDEDIR = /usr/include -CFLAGS = -DDEBUG -O3 -Wall -I/usr/include/directfb +CFLAGS = -DDEBUG -DUSE_DFB_API -O3 -Wall -I/usr/include/directfb LIBS = -L/usr/lib/directfb-0.9.15 -ldirectfb -OBJS = random.o +OBJS = random.o display.o OBJS2 = morpheus morpheus: $(OBJS) diff --git a/defines.h b/defines.h index 58e758d..0be5bc4 100644 --- a/defines.h +++ b/defines.h @@ -5,6 +5,10 @@ * */ +#ifdef USE_DFB_API +#include +#endif + #define DEFAULT_X_SEG 50 #define DEFAULT_Y_SEG 50 #define DEFAULT_Z_SEG 100 @@ -16,29 +20,37 @@ /* program defines, dont touch ;) */ -#ifdef DEBUG - #define DEBUG 1 -#else - #define DEBUG 0 -#endif - #define URAND_MAX 0xffffffff typedef unsigned int u32; typedef long long unsigned int u64; -#define printfd(fmt,args...) if(DEBUG) printf(fmt,##args); +#ifdef DEBUG + #define DEBUG_IT 1 +#else + #define DEBUG_IT 0 +#endif + +#define printfd(fmt,args...) if(DEBUG_IT) printf(fmt,##args); -/* segment struct - * - * not used by now - */ -struct __segment -{ - u32 status; /* C concentration */ -} +/* display stuff */ +typedef struct __display { + u32 max_x,max_y,max_z; /* dimensions */ + u32 *cell_p; /* pointer to cell data */ +#ifdef USE_DFB_API + IDirectFB *dfb; /* pointer to dfb main construct */ + IDirectFBSurface *primary_surface; /* pointer to dfb primary surface */ +#endif + int screen_height,screen_width; /* screen dimensions */ +} display; + +#define DEFAULT_DISPLAY_X 25 +#define DEFAULT_DISPLAY_Y 25 +#define DEFAULT_DISPLAY_Z 50 +#define DEFAULT_DISPLAY_REF_RATE 100 -/* masks for u32 segments */ + +/* masks for u32 cell */ #define AMORPH 0x00000001 #define CRYSTAL 0x00000000 #define C_CONC_MASK 0xfffffffe diff --git a/display.c b/display.c new file mode 100644 index 0000000..f61e7e2 --- /dev/null +++ b/display.c @@ -0,0 +1,55 @@ +/* + * display.c - visualization api + * + */ + +#include +#include + +#include "defines.h" + +#ifdef USE_DFB_API +static IDirectFB *dfb=NULL; +static IDirectFBSurface *primary_surface=NULL; +static int screen_width=0; +static int screen_height=0; +#endif + +int display_init(int x,int y,int z,display *display,u32 *cell,int *argc,char **argv) +{ +#ifdef USE_DFB_API + DFBSurfaceDescription surface_dsc; + // DFBFontDescription font_dsc; +#endif + + /* store dimensions */ + display->max_x=x; + display->max_y=y; + display->max_z=z; + /* store pointer to cells */ + display->cell_p=cell; + + /* the api(s) */ +#ifdef USE_DFB_API + DirectFBInit(argc,&argv); + DirectFBCreate(&dfb); + dfb->SetCooperativeLevel(dfb,DFSCL_FULLSCREEN); + surface_dsc.flags=DSDESC_CAPS; + surface_dsc.caps=DSCAPS_PRIMARY|DSCAPS_FLIPPING; + dfb->CreateSurface(dfb,&surface_dsc,&primary_surface); + primary_surface->GetSize(primary_surface,&screen_width,&screen_height); + display->dfb=dfb; + display->primary_surface=primary_surface; + display->screen_width=screen_width; + display->screen_height=screen_height; +#endif + return 23; +} + +int display_draw(u32 *cell,int x,int y,int z) +{ +#ifdef USE_DFB_API + +#endif + return 23; +} diff --git a/main.c b/main.c index 49be0ef..07f34c9 100644 --- a/main.c +++ b/main.c @@ -20,7 +20,7 @@ #include "defines.h" /* global variables */ -u32 sum_z_segments; +u32 sum_z_cells; int random_fd; /* /dev/urandom file descriptor */ int usage() @@ -29,44 +29,61 @@ int usage() puts("-h: help"); puts("-a \t slope of nuclear energy loss (default 1)"); puts("-c \t nuclear enery loss at depths 0 (default 0)"); - puts("-x \t # x segments (default 50)"); - puts("-y \t # y segments (default 50)"); - puts("-z \t # z segments (default 100)"); - puts("-s \t # steps to calculate (default 5000"); + puts("-x \t # x cells (default 50)"); + puts("-y \t # y cells (default 50)"); + puts("-z \t # z cells (default 100)"); + puts("-s \t # steps to calculate (default 5000)"); + puts("-X \t display area intercept point x (default 25)"); + puts("-Y \t display area intercept point y (default 25)"); + puts("-Z \t display area intercept point z (default 50)"); + puts("-d \t refresh every loops (default 100)"); return -23; } -int make_amorph(u32 *segment) +int make_amorph(u32 *cell) { - *segment=*segment|AMORPH + *cell=*cell|AMORPH; return 23; } -/* look at segment ... */ -int process_segment(u32 *segment) +int make_cryst(u32 *cell) +{ + *cell=*cell&(~AMORPH); + return 23; +} + +/* look at cell ... */ +int process_cell(u32 *cell) { /* tag it ... testing! */ - make_amorph(segment); + make_amorph(cell); return 23; } int main(int argc,char **argv) { - u32 x_seg,y_seg,z_seg; /* amount of segments */ - u32 x,y,z; /* segments */ + u32 x_cell,y_cell,z_cell; /* amount of segments */ + u32 x,y,z; /* cells */ int i; /* for counting */ int slope_nel,start_nel; /* nuclear energy loss: slope, constant */ int steps; /* # steps */ - void *segments_p; + void *cell_p; + struct __display display; + u32 display_x,display_y,display_z; /* intercept point of diplayed areas */ + u32 display_refresh_rate; /* refresh rate for display */ /* default values */ - x_seg=DEFAULT_X_SEG; - y_seg=DEFAULT_Y_SEG; - z_seg=DEFAULT_Z_SEG; + x_cell=DEFAULT_X_SEG; + y_cell=DEFAULT_Y_SEG; + z_cell=DEFAULT_Z_SEG; slope_nel=DEFAULT_SLOPE_NEL; start_nel=DEFAULT_START_NEL; steps=DEFAULT_STEPS; + display_x=DEFAULT_DISPLAY_X-1; + display_y=DEFAULT_DISPLAY_Y-1; + display_z=DEFAULT_DISPLAY_Z-1; + display_refresh_rate=DEFAULT_DISPLAY_REF_RATE; /* parse command args */ for(i=1;i %d\n",sum_z_segments); + /* calculate sum_z_cells one time! */ + sum_z_cells=0; + for(i=1;i<=z_cell;i++) sum_z_cells+=(start_nel+i*slope_nel); + printfd("debug: sum z cells -> %d\n",sum_z_cells); /* testing ... */ - /* allocate segments */ - if((segments_p=malloc(x_seg*y_seg*z_seg*sizeof(u32)))==NULL) + /* allocate cells */ + if((cell_p=malloc(x_cell*y_cell*z_cell*sizeof(u32)))==NULL) { - puts("failed allocating memory for segments\n"); + puts("failed allocating memory for cells\n"); return -23; } - memset(segments_p,0,x_seg*y_seg*z_seg*sizeof(u32)); + memset(cell_p,0,x_cell*y_cell*z_cell*sizeof(u32)); + + /* init display */ + display_init(x_cell,y_cell,z_cell,&display,cell_p,&argc,argv); /* main routine */ for(i=0;i #include #include + #include "defines.h" -/* global & extern variables */ -extern u32 sum_z_segments; +/* global and extern variables */ +extern u32 sum_z_cells; extern int random_fd; /* return random integer between 0 - max */ @@ -21,7 +22,7 @@ u32 rand_get(u32 max) puts("failed reading 4 bytes of random data"); return -23; } - /* segments numbered 0...max-1 */ + /* cells numbered 0...max-1 */ return((u32)(rand_int*(max*1.0/URAND_MAX))); } @@ -29,11 +30,11 @@ u32 rand_get(u32 max) u32 rand_get_lgp(int slope_nel,int start_nel) { int z; u32 i; - z=rand_get(sum_z_segments)+1; /* +1 as rand_get returns values 0...max-1 */ + z=rand_get(sum_z_cells)+1; /* +1 as rand_get returns values 0...max-1 */ for(i=1;;i++) { z-=(start_nel+i*slope_nel); if(z<=0) break; } - return(i-1); /* return values 0...z_seg-1 */ + return(i-1); /* return values 0...z_cell-1 */ } -- 2.20.1