void main(void) { int i, r, g, b; x_set_mode(X_MODE_360x480, 360); for (b = 0; b < 6; b++) for (g = 0; g < 6; g++) for (r = 0; r < 6; r++) x_set_rgb(b + 6 * g + 36 * r, 12 * b + 3, 12 * g + 3, 12 * r + 3); for (i = 216; i < 256; i++) x_set_rgb(i, i - 193, i - 193, 279 - i); for (i = 0; i <= 1080; i++) { x_bezier(i, 240, 90, i, 270, 479-i, 359 - i, 240, 6, i ,0); } for (i = 720; i >= 0; i--) { x_bezier(360 - i, i/3, 360 - i, i, i, i, i, i/3, 4, i ,0); x_bezier(360 - i, 479-i/3, 360 - i, 479-i, i, 479-i, i, 479-i/3, 4, i ,0); } getch(); x_text_mode(); }
void main(void) { int i; x_set_mode(1, 320); for (i = 0; i < 120; i++) { x_circle(0, 0, i, 121 - i, 0); x_circle(319 - i, 0, i, i - 20, 0); x_circle(0, 239 - i, i, i - 20, 0); x_circle(319 - i, 239 - i, i, 121 - i, 0); x_filled_circle(40 + i, i, 241 - (i << 1), i+1, 0); } getch(); x_text_mode(); }
void main(){ int i,j,handle,size,comp_size; char far * tempbuff,far * diskbuff; pbm = farmalloc(20 * 30 + 2); x_bm_to_pbm( MK_FP(FP_SEG(turtle),FP_OFF(turtle)), pbm); x_set_mode(X_MODE_360x240,360); load_user_fonts(); x_bgprintf(0,0,0,14,0, "This is a demo of RLE compression of 360x240 video screen to "); x_bgprintf(0,8,0,14,0, "disk. Uncompressed, this screen requires a file of size "); x_bgprintf(0,16,0,14,0,"86400 (360x240) bytes."); x_bgprintf(0,48,0,14,0, "Press a key to draw the image and save it to screen:"); getch(); x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0); for (j=0;j<(ScrnPhysicalHeight/30);j++) for (i=0;i<(ScrnPhysicalPixelWidth/20);i++) x_put_masked_pbm(i*20, j*30, 0, pbm); x_set_start_addr(0,240); x_bgprintf(0,0,240*90,14,0, "Now compressing and writing to file 'screen.dat'."); x_bgprintf(0,8,240*90,14,0,"Please wait... "); if((handle=f_open("screen.dat",F_WRONLY))==FILE_ERR) error("Unable to open 'screen.dat' for writing."); size=0; tempbuff=farmalloc(90*240); diskbuff=farmalloc(90*240); buffsize=(int far *)farmalloc(2); for (i=0;i<4;i++){ x_select_default_plane(i); if (!(j=x_buff_RLEncode(MK_FP(0xA000,0),tempbuff,90*240))) error("Error buff compressing"); *buffsize=j; f_writefar(handle,(char far *)buffsize,2); f_writefar(handle,tempbuff,j); size+=j; } comp_size=size; f_close(handle); if((handle=f_open("screen.raw",F_WRONLY))==FILE_ERR) error("Unable to open 'screen.dat' for writing."); for (i=0;i<4;i++){ x_select_default_plane(i); f_writefar(handle,MK_FP(0xA000,0),90*240); } f_close(handle); x_bgprintf(0,8,240*90,14,0,"Done. Press a key to restore."); getch(); x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0); x_set_start_addr(0,0); if((handle=f_open("screen.dat",F_RDONLY))==FILE_ERR) error("Unable to open 'screen.dat' for reading."); size=0; for (i=0;i<4;i++){ x_select_default_plane(i); f_readfar(handle,(char far *)buffsize,2); f_readfar(handle,diskbuff,*buffsize); j=x_buff_RLDecode(diskbuff,MK_FP(0xA000,0)); size+=j; } f_close(handle); getch(); x_text_mode(); printf("screen size = 86400 compressed = %u",comp_size); }
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;j<ScrnPhysicalHeight;j++){ x_line(0,j,ScrnLogicalPixelWidth,j,16+(j%239),VisiblePageOffs); } ctrlbrk(terminate); x_get_pal_struc(pal, 240,16); load_user_fonts(); intro_1(); x_set_font(2); x_hide_mouse(); x_printf(textwindow_x+5,50 ,VisiblePageOffs,9, " Hi, folks. This is yet another FREEWARE Mode X"); x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " graphics library. It is by no means complete,"); x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " but I believe it contains a rich enough set of"); x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " functions to achieve its design goal - to be"); x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " a game development oriented library for"); x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " Borland TC/BC/BC++ and TASM programmers."); x_printf(textwindow_x+5,50+48,VisiblePageOffs,9, " This library comes with TASM and C sources."); x_printf(textwindow_x+5,50+56,VisiblePageOffs,9, " It was inspired by the DDJ Graphics column and"); x_printf(textwindow_x+5,50+64,VisiblePageOffs,9, " many INTERNET and USENET authors who, unlike the"); x_printf(textwindow_x+5,50+72,VisiblePageOffs,9, " majority of programmers (you know who you are!),"); x_printf(textwindow_x+5,50+80,VisiblePageOffs,9, " willingly share their code and ideas with others."); x_printf(textwindow_x+5,50+88,VisiblePageOffs,9, " I can't afford, nor do I want, to copyright"); x_printf(textwindow_x+5,50+96,VisiblePageOffs,9, " this code - but if you use it, some credit would "); x_printf(textwindow_x+5,50+104,VisiblePageOffs,9," be appreciated. "); wait_for_keypress(); subsequent_page(); x_set_font(0); x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"Supported 256 colour resolutions."); x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"Supported 256 colour resolutions."); x_set_font(2); x_printf(textwindow_x+5,50 ,VisiblePageOffs,9, " 320x200 Standard for games ~ 4 pages"); x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " 320x240 DDJ Mode X square pixels ~ 3.5 pages"); x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " 360x200 My favourite for games ~ 3 pages "); x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " 360x240 ~ 2.8 pages"); x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " 320x400 ~ 2 pages "); x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " 320x480 All subsequent modes support"); x_printf(textwindow_x+5,50+48,VisiblePageOffs,9, " 360x400 less than two pages."); x_printf(textwindow_x+5,50+56,VisiblePageOffs,9, " 360x480"); x_printf(textwindow_x+5,50+64,VisiblePageOffs,9, " 376x282,360x360,376x308,376x564,256x200,256x240"); x_printf(textwindow_x+5,50+72,VisiblePageOffs,9, " Phew! and they'll run on all VGA cards and "); x_printf(textwindow_x+5,50+80,VisiblePageOffs,9, " monitors (some of the weird ones are best suited"); x_printf(textwindow_x+5,50+88,VisiblePageOffs,9, " to monitors with both vert & horiz adjustments)"); x_printf(textwindow_x+5,50+98,VisiblePageOffs,2, " "); x_printf(textwindow_x+5,50+106,VisiblePageOffs,2," Overkill? Maybe!! "); wait_for_keypress(); subsequent_page(); x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6," Text display functions."); x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3," Text display functions."); x_set_font(2); x_printf(textwindow_x+5,50 ,VisiblePageOffs,9, " Several text printing functions are provided."); x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " They support the VGA ROM 8x14 and 8x8 fonts as"); x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " well as user-defined fonts (like this 6x8 font)."); x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " Furthermore, a function similar to printf is"); x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " included which provides formatted text output."); x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " User defined fonts may be proportionally spaced"); x_printf(textwindow_x+5,50+58,VisiblePageOffs,9, " but have a maximum width of 8 pixels."); wait_for_keypress(); subsequent_page(); x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6," Advanced screen functions."); x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3," Advanced screen functions."); x_set_font(2); x_printf(textwindow_x+5,50 ,VisiblePageOffs,9, " The library supports virtual screens larger"); x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " than the physical screen, panning of such"); x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " screens, and a split screen option."); x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " These functions can be used together or"); x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " in isolation, and in the lower resolutions"); x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " double buffering can also be accomplished."); x_rect_fill(0, 0, ScrnPhysicalPixelWidth,60,SplitScrnOffs,5); x_line(0,0,ScrnPhysicalPixelWidth,0,2,SplitScrnOffs); x_set_font(1); x_printf(10,10,SplitScrnOffs,2, " This is a split screen, tops for scores."); x_set_font(0); for (i=ScrnPhysicalHeight;i>ScrnPhysicalHeight-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<i;j++){ x_cpcontrast_pal_struc(pal, pal2,ch+=2); x_put_pal_struc(pal2); x_rot_pal_struc(pal,palscrolldir); }; wait_for_keypress(); subsequent_page(); x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6," NEW Version 3.0 Functions!"); x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3," NEW Version 3.0 Functions!"); x_set_font(2); x_printf(textwindow_x+5,50 ,VisiblePageOffs,9, " NEW functions not demonstrated here include:"); x_printf(textwindow_x+5,50+10,VisiblePageOffs,9, " - RLE data compression"); x_printf(textwindow_x+5,50+20,VisiblePageOffs,9, " - FAST compiled masked bitmaps"); x_printf(textwindow_x+5,50+30,VisiblePageOffs,9, " - Hardware detection"); x_show_mouse(); wait_for_keypress(); x_hide_mouse(); for (i = 0; i < 150; i++) { x_circle(0, 0, i, 181 - i, VisiblePageOffs); x_circle(360 - i, 0, i, i + 30, VisiblePageOffs); x_circle(0, 200 - i, i, i + 30, VisiblePageOffs); x_circle(360 - i, 200 - i, i, 181 - i, VisiblePageOffs); } for (i = 0; i < 100; i++) x_filled_circle(80 + i, i, 201 - (i << 1), 30+i, VisiblePageOffs); x_show_mouse(); wait_for_keypress(); subsequent_page(); x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6," NEW Version 4.0 Functions!"); x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3," NEW Version 4.0 Functions!"); x_set_font(2); x_printf(textwindow_x+5,50 ,VisiblePageOffs,9, " NEW functions not demonstrated here include:"); x_printf(textwindow_x+5,50+10,VisiblePageOffs,9, " - FAST VRAM-based masked bitmaps, including"); x_printf(textwindow_x+5,50+18,VisiblePageOffs,9, " support for clipping regions"); x_printf(textwindow_x+5,50+28,VisiblePageOffs,9, " - Faster, smaller compiled bitmaps"); x_printf(textwindow_x+5,50+38,VisiblePageOffs,9, " - Improved planar bitmap performance and"); x_printf(textwindow_x+5,50+46,VisiblePageOffs,9, " additional support for clipping"); x_printf(textwindow_x+5,50+56,VisiblePageOffs,9, " - mouse module"); x_printf(textwindow_x+5,50+66,VisiblePageOffs,9, " - Detection of math co-processor and mouse"); x_printf(textwindow_x+5,50+76,VisiblePageOffs,9, " - Bezier curve module"); x_printf(textwindow_x+5,50+86,VisiblePageOffs,9, " - Four new resolutions, including one with"); x_printf(textwindow_x+5,50+94,VisiblePageOffs,9, " square pixels (376x282)"); x_printf(textwindow_x+5,50+104,VisiblePageOffs,9, " - More bug fixes"); wait_for_keypress(); subsequent_page(); x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6," NEW Version 5.0 Functions!"); x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3," NEW Version 5.0 Functions!"); x_set_font(2); x_printf(textwindow_x+5,50 ,VisiblePageOffs,9, " - *FAST* filled and clipped triangles ideal for"); x_printf(textwindow_x+5,50+10,VisiblePageOffs,9, " 3D work. Thanks to S. Dollins for the code."); x_printf(textwindow_x+5,50+20,VisiblePageOffs,9, " - Filled and clipped polygons, C++ Compatible"); x_printf(textwindow_x+5,50+30,VisiblePageOffs,9, " - header files, and of course bug fixes!"); x_show_mouse(); wait_for_keypress(); subsequent_page(); x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6," NEW Version 6.0 Functions!"); x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3," NEW Version 6.0 Functions!"); x_set_font(2); x_printf(textwindow_x+5,50 ,VisiblePageOffs,9, " - Fast flood filling functions "); x_printf(textwindow_x+5,50+10,VisiblePageOffs,9, " - New pbm flipping put functions."); x_printf(textwindow_x+5,50+20,VisiblePageOffs,9, " - Timer synchronized vertical retrace"); x_printf(textwindow_x+5,50+30,VisiblePageOffs,9, " - Tripple buffering extensions"); x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " Checkout demo 9 and 10 for previews"); x_show_mouse(); wait_for_keypress(); randomize(); x_hide_mouse(); while(kbhit()) getch(); palscrolldir^=1; do { int x0,x1,x2,y0,y1,y2,i; i=random(256); x0=random(ScrnLogicalPixelWidth); x1=random(ScrnLogicalPixelWidth); x2=random(ScrnLogicalPixelWidth); y0=random(ScrnPhysicalHeight); y1=random(ScrnPhysicalHeight); y2=random(ScrnPhysicalHeight); x_triangle(x0,y0,x1,y1,x2,y2,i,VisiblePageOffs); } while (!kbhit() && !(MouseButtonStatus==LEFT_PRESSED)); while(MouseButtonStatus==LEFT_PRESSED); while(kbhit()) getch(); x_show_mouse(); subsequent_page(); x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6," PLEASE..."); x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3," PLEASE..."); x_set_font(2); x_printf(textwindow_x+5,50 ,VisiblePageOffs,9, " Please mention my name in programs that use XLIB"); x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " just to make me feel it was worth the effort."); x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " If you have any bug to report please feel free to"); x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " mail me a message. Any hints, suggestions and"); x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " contributions are welcome and encouraged."); x_printf(textwindow_x+5,50+52,VisiblePageOffs,9, " I have contributed this code to the public domain."); x_printf(textwindow_x+5,50+60,VisiblePageOffs,9, " Please respect my wishes and leave it there."); x_printf(textwindow_x+5,50+80,VisiblePageOffs,9, " Finally, I hope you all find this stuff useful,"); x_printf(textwindow_x+5,50+96,VisiblePageOffs,9, " Themie Gouthas - [email protected]"); wait_for_keypress(); x_hide_mouse(); x_shift_rect (27, 27, 360-27, 177, 27, 23, VisiblePageOffs); x_rect_fill(25, 173, 335, 176, VisiblePageOffs, 1); for (i = 0; i < 50; i++) { x_shift_rect (27, 26, 360-27, 177 - (i * 3), 27, 23, VisiblePageOffs); } }
void main ( void ) { WORD x, y; x_set_mode( X_MODE_320x240, 640 ); for( y=0; y<240; y++ ) for( x=0; x<640; x++ ) { //x_put_pix( x, y, 0, (x*4)/5 ); if ( y<118 ) x_put_pix( x, y, 0, (x*y&63) ); else x_put_pix( x, y, 160, (x*y&63) ); } getch(); _disable(); OldTimer=_dos_getvect( 0x8 ); _dos_setvect( 0x8, SplitIRQ ); outp( 0x43, 0x30 ); outp( 0x40, 0 ); outp( 0x40, 0 ); _enable(); x=0; while( !kbhit() ) { SplitPos = x; outpw( 0x3d4, 0xc | (SplitPos & 0xff00) ); outpw( 0x3d4, 0xd | (SplitPos << 8) ); SplitVal = ( ( 40*3 - 1 - SplitPos ) << 8 ) | 0x13; //_border(1); sync(); nsync(); nhsync(); //outp( 0x43, 0x30 ); outp( 0x40, DIVISOR & 0x00ff ); outp( 0x40, DIVISOR >> 8 ); x++; if( x == 80 ) x=0; } _disable(); outp( 0x43, 0x36 ); outp( 0x40, 0 ); outp( 0x40, 0 ); _dos_setvect( 0x8, OldTimer ); _enable(); getch(); x_text_mode(); }