puts("[display] initializing display ...");
- /* init stuff next .. */
+ /* dimensions */
display->max_x=atoi(getenv("COLUMNS"));
display->max_y=atoi(getenv("LINES"));
+ /* allocating 'screen' buffer */
+ if((display->screen=(unsigned char *)malloc(display->max_x*display->max_y))
+ ==NULL) {
+ perror("[display] malloc call");
+ return D_ERROR;
+ }
+ /* space as display pixel default */
+ memset(display->screen,0x20,display->max_x*display->max_y);
+
return D_SUCCESS;
}
-int display_refresh(t_display *display) {
+int display_draw(t_display *display) {
- display->max_x=atoi(getenv("COLUMNS"));
- display->max_y=atoi(getenv("LINES"));
+ int x,y;
+
+ for(y=0;y<display->max_y;y++) {
+ for(x=0;x<display->max_x;x++)
+ printf("%c",display->screen+y*display->max_x+x);
+ printf("\n");
+ }
+
+ return D_SUCCESS;
+}
+
+int display_draw_until_line(t_display *display,int line) {
+
+ int x,y;
+
+ for(x=0;x<display->max_x;x++) {
+ for(y=0;y<line;y++) printf("%c",display->screen+y*display->max_x+x);
+ printf("\n");
+ }
+
+ return D_SUCCESS;
+}
+
+int display_clear_screen(t_display *display) {
+
+ memcpy(display->screen,0x20,display->max_x*display->max_y);
return D_SUCCESS;
}
int display_shutdown(t_display *display) {
+ free(display->screen);
+
puts("[display] shutdown");
return D_SUCCESS;
}
-int display_term_line(t_display *display,char sym) {
+int display_line(t_display *display,int X,int Y,int X_,int Y_,char sym) {
- int i;
+ double m;
+ int x,y;
- for(i=0;i<display->max_x;i++) printf("%c",sym);
- printf("\n");
+ m=(Y_-Y)/(X_-X);
+
+ for(y=0;y<display->max_y;y++)
+ for(x=0;x<display->max_x;x++)
+ if((int)((x-X)*m+Y)==y) display->screen+y*display->max_x+x=sym;
return D_SUCCESS;
}
-int display_term_string(t_display *display,char *string) {
+int display_string(t_display *display,int x,int y,char *string,int len) {
+
+ if(len>display->max_x-x) return D_INV_STRING_LEN;
- /* to be continued ... */
+ memcpy(display->screen+y*display->max_x+x,string,len);
return D_SUCCESS;
}
+int display_string_vert(t_display *display,int x,int y,char *string,int len) {
+
+ if(len>display->max_y-y) return D_INV_STRING_LEN;
+
+ for(i=y*display->max_x+x;i<(y+len)*display->max_x+x;i+=display->max_x)
+ *(display->screen+i)=*(string++);
+
+ return D_SUCCESS;
+}
/* defines */
#define D_SUCCESS 1
#define D_ERROR -1
+#define D_INV_STRING_LEN -2
#define MAX_TERM_STRING 64
typedef struct s_display {
int max_x;
int max_y;
- int x;
- int y;
+ unsigned char *screen;
} t_display;
/* function prototypes */
int display_init(t_display *display);
-int display_refresh(t_display *display);
+int display_draw(t_display *display);
+int int display_draw_until_line(t_display *display,int line);
+int display_clear_screen(t_display *display);
int display_shutdown(t_display *display);
-int display_term_line(t_display *display,char sym);
-int display_term_string(t_display *display,char *string);
+int display_line(t_display *display,int X,int Y,int X_,int Y_,char sym);
+int display_string(t_display *display,int x,int y,char *string,int len);
+int display_string_vert(t_display *display,int x,int y,char *string,int len);
int ivac_display_head(t_ivac *ivac) {
-#ifndef XXX_GUI
- display_term_line(&(ivac->display),'#');
- puts("##### ivac - - Copyright (C) 2004 Frank Zirkelbach #####");
- puts("#########################################################");
-#endif
+ display_line(&(ivac->display),0,ivac->display.max_x,0,0,'#');
+ display_string(&(ivac->display),(display->max_x-strlen(PROG_NAME))/2,2,
+ PROG_NAME,strlen(PROG_NAME));
+ display_line(&(ivac->display),0,ivac->display.max_x,2,2,'#');
return SUCCESS;
}
+GO ON HERE !!! display stuff
+
int ivac_display_box(t_ivac *ivac) {
#ifndef XXX_GUI