]> 4ch.mooo.com Git - 16.git/blob - 16/xlib/demo8.c
more
[16.git] / 16 / xlib / demo8.c
1 /*************************************************************************\r
2 \r
3 DEMO 2\r
4 \r
5 Demonstrates the speed difference between compiled bitmap,  conventional\r
6 masked planar bitmap, and video bitmap blits.\r
7 \r
8 **************************************************************************/\r
9 \r
10 \r
11 \r
12 #include <stdio.h>\r
13 #include <stdlib.h>\r
14 #include <conio.h>\r
15 #include <ctype.h>\r
16 #include <malloc.h>\r
17 #include <dos.h>\r
18 #include <dir.h>\r
19 #include <string.h>\r
20 \r
21 #include "xlib.h"\r
22 #include  "xtext.h"\r
23 #include  "xrect.h"\r
24 \r
25 /* Macro to make pointer parameters model independent */\r
26 #define FARPTR(x) (MK_FP(FP_SEG(x),FP_OFF(x)))\r
27 \r
28 char *swidth[10]={"0","1","2","3","4","5","6","7","8","9"};\r
29 char far *fonts[20];\r
30 char names[20][20];\r
31 int i,fcount=0;\r
32     char c;\r
33 \r
34 typedef struct {\r
35   int  dummy;\r
36   char height;\r
37   char width;\r
38 } header;\r
39 \r
40 void load_user_fonts(){\r
41   FILE *f;\r
42   long len;\r
43   struct ffblk ffblock;\r
44 \r
45   if(findfirst("*.fnt",&ffblock,0)!=0){\r
46     printf("No Fonts found in current directory!\n");\r
47     exit(0);\r
48   };\r
49   do {\r
50     printf("Loading font \"%s\"...\n",ffblock.ff_name);\r
51     strncpy(names[fcount],ffblock.ff_name,14);\r
52 \r
53     f=fopen(ffblock.ff_name,"rb");\r
54 \r
55     fseek(f,0,SEEK_END);\r
56     len=ftell(f);\r
57     fseek(f,0,SEEK_SET);\r
58 \r
59     fonts[fcount] = farmalloc(len);\r
60     if (!fonts[fcount]){\r
61       printf("Out of memory");\r
62       if (fcount!=0){\r
63         printf("- No more fonts can be loaded\n");\r
64         fclose(f);\r
65         goto NoMoreFonts;\r
66       } else printf("\n");\r
67 \r
68       exit(0);\r
69     };\r
70 \r
71     for (i=0;i<len;i++){\r
72       fread(&c,1,1,f);\r
73       *(fonts[fcount]+i)=c;\r
74     }\r
75 \r
76     fclose(f);\r
77     fcount++;\r
78 \r
79   } while (!findnext(&ffblock));\r
80 \r
81 NoMoreFonts:\r
82   printf("\n Press 'v' to view, any other key to quit\n");\r
83   c=getch();\r
84   if (c!='V' && c!='v'){\r
85     x_text_mode();\r
86     exit(0);\r
87   }\r
88 \r
89   x_text_init();\r
90   x_set_mode(X_MODE_320x240,0);\r
91   x_register_userfont(fonts[0]);\r
92   x_set_font(2);\r
93 }\r
94 \r
95                  //......................................//\r
96 char *text[30] = {"EXTRACT: Stephen King's \"SALEM'S LOT\" ",\r
97                   "",\r
98                   "The memory rose up in almost total    ",\r
99                   "sensory reference, and for the moment ",\r
100                   "of its totality he was paralyzed. He  ",\r
101                   "could even smell the plaster and the  ",\r
102                   "wild odour of nesting animals. It     ",\r
103                   "seemed to him that the plain varnished",\r
104                   "door of Matt Burke's guest room stood ",\r
105                   "between him and all the secrets of    ",\r
106                   "Hell. Then he twisted the knob and    ",\r
107                   "pushed the door handle inwards...     ",\r
108                   "",\r
109                   "ABCDEFGHIJKLMNOPQRSTUVWXYZ            ",\r
110                   "abcdefghijklmnopqrstuvwxyz 0123456789 ",\r
111                   "~!@#$%^&*()_+|`-=\\{}[]:\";'<>?,./    ",\r
112                   NULL};\r
113 \r
114 \r
115 \r
116 \r
117 \r
118 void main(){\r
119     int textline;\r
120     int strindex;\r
121     int height;\r
122     load_user_fonts();\r
123 \r
124 \r
125 \r
126     for (i=0;i<fcount;i++){\r
127       x_set_font(FONT_8x8);\r
128       x_rect_fill(0, 0, 319, 239, 0, 0);\r
129       x_line(0,9,319,9,14,0);\r
130       x_line(0,ScrnPhysicalHeight-10,319,ScrnPhysicalHeight-10,14,0);\r
131 \r
132       x_bgprintf(0,0,0,14,0,"Font \"%s\" H=%d,W=%s",names[i],\r
133                (int)*(fonts[i]+2),\r
134                (*(fonts[i]+3)==0)?"Variable":swidth[*(fonts[i]+3)]);\r
135       x_bgprintf(0,ScrnPhysicalHeight-8,0,14,0,\r
136           "Press a key for next font...");\r
137 \r
138       x_register_userfont(fonts[i]);\r
139       x_set_font(FONT_USER);\r
140 \r
141       height=(int)*(fonts[i]+2)+1;\r
142       textline=12;\r
143       strindex=0;\r
144       while(text[strindex]){\r
145        x_printf(0,textline,0,14,text[strindex++]);\r
146        textline+=height;\r
147       }\r
148 \r
149       getch();\r
150     }\r
151 \r
152     x_text_mode();\r
153 }\r
154 \r