📄 demo1.c
字号:
/* VERY QUICK AND ULTRA-DIRTY DEMO USING XLIB */
/* Simple Demo of MODE X Split screen and panning */
/* Compile using Turbo C and Tasm */
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <alloc.h>
#include <dos.h>
#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<object_count;i++){
MoveObject(&objects[i]);
x_get_pbm(objects[i].X,objects[i].Y,
(unsigned)objects[i].Width,objects[i].Height,HiddenPageOffs,
objects[i].bg);
x_put_masked_pbm(objects[i].X,objects[i].Y,HiddenPageOffs,
objects[i].Image);
}
}
void clear_objects(void){
int i;
for(i=object_count-1;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 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -