/* VERY QUICK AND ULTRA-DIRTY DEMO USING XLIB */ /* Simple Demo of MODE X Split screen and panning */ /* Compile using Turbo C and Tasm */ #include #include #include #include #include #include #include "Xlib_all.h" #define MAX_OBJECTS 10 static char *texttest[6] = {"This is a demonstration of the fonts ", "available in XLIB. Notice fixed and ", "variabe spaced fonts are supported but", "are limited to a maximum of 8 pixels in", "width. Height of the characters is ", "ofcourse unlimited..."}; typedef struct { int X,Y,Width,Height,XDir,YDir,XOtherPage,YOtherPage; char far * Image; char far * bg; char far * bgOtherPage; } AnimatedObject; AnimatedObject objects[MAX_OBJECTS]; int object_count=0; static char bm[] = {4,12, /* plane 0 */ 2,2,2,2,2,1,1,1,2,1,1,1,2,3,3,1, 2,0,0,3,2,0,0,3,2,0,0,3,2,0,0,3, 2,3,3,1,2,1,1,1,2,1,1,1,2,2,2,2, /* plane 1 */ 2,2,2,2,1,1,1,1,1,1,1,1,1,3,3,1, 1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1, 1,3,3,1,1,1,1,1,1,1,1,1,2,2,2,2, /* plane 2 */ 2,2,2,2,1,1,1,1,1,1,1,1,1,3,3,1, 1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1, 1,3,3,1,1,1,1,1,1,1,1,1,2,2,2,2, /* plane 3 */ 2,2,2,2,1,1,1,2,1,1,1,2,1,3,3,2, 3,0,0,2,3,0,0,2,3,0,0,2,3,0,0,2, 1,3,3,2,1,1,1,2,1,1,1,2,2,2,2,2}; static char bm2[] = {4,12, /* plane 0 */ 2,2,2,2,2,4,4,4,2,4,4,4,2,2,2,4, 2,0,0,2,2,0,0,2,2,0,0,2,2,0,0,2, 2,2,2,4,2,4,4,4,2,4,4,4,2,2,2,2, /* plane 1 */ 2,2,2,2,4,4,4,4,4,4,4,4,4,2,2,4, 4,0,0,4,4,0,0,4,4,0,0,4,4,0,0,4, 4,2,2,4,4,4,4,4,4,4,4,4,2,2,2,2, /* plane 2 */ 2,2,2,2,4,4,4,4,4,4,4,4,4,2,2,4, 4,0,0,4,4,0,0,4,4,0,0,4,4,0,0,4, 4,2,2,4,4,4,4,4,4,4,4,4,2,2,2,2, /* plane 2 */ 2,2,2,2,4,4,4,2,4,4,4,2,4,2,2,2, 2,0,0,2,2,0,0,2,2,0,0,2,2,0,0,2, 4,2,2,2,4,4,4,2,4,4,4,2,2,2,2,2}; int textwindow_x=0,textwindow_y=0; char far * pal,far * pal2; char palscrolldir=1; char far * userfnt1; void drawtext(int height){ int i; for (i=0;i<6;i++) x_printf(textwindow_x+5,50+i*(height+2),VisiblePageOffs,9,texttest[i]); } /* initialize a new object */ void init_object(int x,int y,int width, int height, int xdir, int ydir, char far * image){ int i; objects[object_count].X = objects[object_count].XOtherPage = x; objects[object_count].Y = objects[object_count].YOtherPage = y; objects[object_count].Width = width; objects[object_count].Height = height; objects[object_count].XDir = xdir; objects[object_count].YDir = ydir; objects[object_count].Image = image; objects[object_count].bg = (char far *) farmalloc(4*width*height+20); objects[object_count].bgOtherPage = (char far *) farmalloc(4*width*height+20); x_get_pbm(x,y,(unsigned)width,height,VisiblePageOffs, objects[object_count].bg); x_get_pbm(x,y,(unsigned)width,height,HiddenPageOffs, objects[object_count].bgOtherPage); object_count++; } /* Move the specified object, bouncing at the edges of the screen and remembering where the object was before the move for erasing next time */ void MoveObject(AnimatedObject * ObjectToMove) { int X, Y; char far *cptr; X = ObjectToMove->X + ObjectToMove->XDir; Y = ObjectToMove->Y + ObjectToMove->YDir; if ((X < 0) || (X > (ScrnLogicalPixelWidth-((ObjectToMove->Width)<<2)))) { ObjectToMove->XDir = -ObjectToMove->XDir; X = ObjectToMove->X + ObjectToMove->XDir; } if ((Y < 0) || (Y > (ScrnLogicalHeight-ObjectToMove->Height))) { ObjectToMove->YDir = -ObjectToMove->YDir; Y = ObjectToMove->Y + ObjectToMove->YDir; } /* Remember previous location for erasing purposes */ ObjectToMove->XOtherPage = ObjectToMove->X; ObjectToMove->YOtherPage = ObjectToMove->Y; ObjectToMove->X = X; /* set new location */ ObjectToMove->Y = Y; cptr = ObjectToMove->bg; ObjectToMove->bg = ObjectToMove->bgOtherPage; ObjectToMove->bgOtherPage = cptr; } void animate(void){ int i; for(i=object_count-1;i>=0;i--){ x_put_pbm(objects[i].XOtherPage,objects[i].YOtherPage, HiddenPageOffs,objects[i].bgOtherPage); } for(i=0;i=0;i--){ x_put_pbm(objects[i].XOtherPage,objects[i].YOtherPage, HiddenPageOffs,objects[i].bgOtherPage); } } void textwindow(int Margin){ int x0=0+Margin; int y0=0+Margin; int x1=ScrnPhysicalPixelWidth-Margin; int y1=ScrnPhysicalHeight-Margin; x_rect_fill(x0, y0, x1,y1,VisiblePageOffs,1); x_line(x0,y0,x1,y0,2,VisiblePageOffs); x_line(x0,y1,x1,y1,2,VisiblePageOffs); x_line(x0,y0,x0,y1,2,VisiblePageOffs); x_line(x1,y0,x1,y1,2,VisiblePageOffs); x_line(x0+2,y0+2,x1-2,y0+2,2,VisiblePageOffs); x_line(x0+2,y1-2,x1-2,y1-2,2,VisiblePageOffs); x_line(x0+2,y0+2,x0+2,y1-2,2,VisiblePageOffs); x_line(x1-2,y0+2,x1-2,y1-2,2,VisiblePageOffs); textwindow_x=x0; textwindow_y=y0; } void wait_for_keypress(void){ x_show_mouse(); while(kbhit()) getch(); palscrolldir^=1; do { x_rot_pal_struc(pal,palscrolldir); MouseFrozen=1; x_put_pal_struc(pal); x_update_mouse(); } while (!kbhit() && !(MouseButtonStatus==LEFT_PRESSED)); while(MouseButtonStatus==LEFT_PRESSED); while(kbhit()) getch(); } void exitfunc(void){ x_mouse_remove(); x_remove_vsync_handler(); x_text_mode(); printf("Thanks to everyone who assisted in the development of XLIB.\n"); printf("\nSpecial thanks to Matthew Mackenzie for contributing \n"); printf("lots of code, documentation and ideas.\n\n"); printf("If you make any money using this code and you're the generous\n"); printf("type please send us some, or at least a copy of your program!\n"); } int terminate(void){ exit(0); } void intro_1(void){ x_set_rgb(1,40,40,40); /* BG Gray */ x_set_rgb(2,63,63,0); /* Bright Yellow */ x_set_rgb(3,63,0,0); /* Bright Red */ x_set_rgb(4,0,63,0); /* Bright Green */ x_set_rgb(5,0,0,63); /* Bright Blue */ x_set_rgb(6,0,0,28); /* Dark Blue */ x_set_rgb(7,0,28,0); /* Dark Green */ x_set_rgb(8,28,0,0); /* Dark red */ x_set_rgb(9,0,0,38); /* Med Blue */ textwindow(20); x_set_font(1); x_printf(textwindow_x+54,textwindow_y+4,VisiblePageOffs,6," XLIB Version 6.0"); x_printf(textwindow_x+53,textwindow_y+3,VisiblePageOffs,2," XLIB Version 6.0"); x_set_font(0); x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6," Not the Unix version"); x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,2," Not the Unix version"); x_printf(textwindow_x+24,168,VisiblePageOffs,6," Press any key to continue"); x_printf(textwindow_x+23,167,VisiblePageOffs,2," Press any key to continue"); } void subsequent_page(void){ x_hide_mouse(); textwindow(20); x_set_font(1); x_printf(textwindow_x+54,textwindow_y+4,VisiblePageOffs,6," XLIB Version 6.0"); x_printf(textwindow_x+53,textwindow_y+3,VisiblePageOffs,2," XLIB Version 6.0"); x_set_font(0); x_printf(textwindow_x+24,168,VisiblePageOffs,6," Press any key to continue"); x_printf(textwindow_x+23,167,VisiblePageOffs,2," Press any key to continue"); } void load_user_fonts(void){ FILE *f; f=fopen("var6x8.fnt","rb"); /* read char by char as fread wont read to far pointers in small model */ { int i; char c; for (i=0;i<256*8+4;i++){ fread(&c,1,1,f); *(userfnt1+i)=c; } } fclose(f); x_register_userfont(userfnt1); } void main(){ int i, j, xinc, yinc, Margin; char ch; WORD curr_x=0, curr_y=0; pal = (char far *) farmalloc(256*3); pal2 = (char far *) farmalloc(256*3); userfnt1 = (char far *) farmalloc(256*16+4); /* INITIALIZE XLIB */ /* we set up Mode X 360x200x256 with a logical width of ~ 500 */ /* pixels; we actually get 496 due to the fact that the width */ /* must be divisible by 8 */ x_text_mode(); /* make sure VGA is in color mode, if possible */ x_set_mode(X_MODE_360x200,500); /* actually is set to 496 */ x_install_vsync_handler(2); x_set_splitscreen(ScrnPhysicalHeight-60); /* split screen 60 pixels high */ x_set_doublebuffer(220); x_text_init(); x_hide_splitscreen(); x_mouse_init(); MouseColor=2; atexit(exitfunc); /* DRAW BACKGROUND LINES */ for(j=0;jScrnPhysicalHeight-60;i--){ x_adjust_splitscreen(i); } x_printf(10,25,SplitScrnOffs,2, " Even better for scrolling games etc."); x_cp_vid_rect(0,0,ScrnLogicalPixelWidth,ScrnLogicalHeight,0,0, VisiblePageOffs,HiddenPageOffs, ScrnLogicalPixelWidth,ScrnLogicalPixelWidth); x_show_mouse(); wait_for_keypress(); curr_x=curr_y=0; init_object(60,90,4, 12, -1, 1, MK_FP(FP_SEG(bm2),FP_OFF(bm2))); init_object(30,30,4, 12, 1, 1, MK_FP(FP_SEG(bm),FP_OFF(bm))); init_object(80,120,4, 12, 2, 1, MK_FP(FP_SEG(bm),FP_OFF(bm))); init_object(300,200,4, 12, 1, -2, MK_FP(FP_SEG(bm),FP_OFF(bm))); init_object(360,30,4, 12, -1, -1, MK_FP(FP_SEG(bm),FP_OFF(bm))); init_object(360,10,4, 12, -2, 2, MK_FP(FP_SEG(bm),FP_OFF(bm))); x_hide_mouse(); while (!kbhit()&& !(MouseButtonStatus==LEFT_PRESSED)){ animate(); if (objects[0].X>=curr_x+ScrnPhysicalPixelWidth-32 && curr_x < MaxScrollX) curr_x++; else if (objects[0].X < curr_x+16 && curr_x > 0) curr_x--; if (objects[0].Y>=curr_y+ScrnPhysicalHeight-92 && curr_y < MaxScrollY) curr_y++; else if (objects[0].Y < curr_y+16 && curr_y > 0) curr_y--; x_page_flip(curr_x,curr_y); while(StartAddressFlag); } while(MouseButtonStatus==LEFT_PRESSED); while(kbhit()) getch(); clear_objects(); x_page_flip(curr_x,curr_y); while(StartAddressFlag); x_set_start_addr(0,0); for (j=0;j<4;j++){ x_hide_splitscreen(); delay(100); x_show_splitscreen(); delay(100); } for (i=ScrnPhysicalHeight-60;i<=ScrnPhysicalHeight;i++){ x_adjust_splitscreen(i); } x_hide_mouse(); subsequent_page(); x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6," Palette functions."); x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3," Palette functions."); x_set_font(2); x_printf(textwindow_x+5,50 ,VisiblePageOffs,9, " A number of palette manipulation functions"); x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " are provided. You have already seen some of"); x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " them in action. Another common operation is"); x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " palette fading. "); i=0; ch=255; while (x_cpcontrast_pal_struc(pal, pal2,ch-=2)){ x_put_pal_struc(pal2); x_rot_pal_struc(pal,palscrolldir); i++; }; for (j=0;j