]> 4ch.mooo.com Git - 16.git/blob - src/lib/dos_gfx.cpp
bb1e4cf27806894fab0c30df431266610f586ce4
[16.git] / src / lib / dos_gfx.cpp
1 /////////////////////////////////////////////////////////////////////////////\r
2 //                                                                         //\r
3 // TUTPROG4.CPP - VGA Trainer Program 4 (in Turbo C++ 3.0)                 //\r
4 //                                                                         //\r
5 // "The VGA Trainer Program" is written by Denthor of Asphyxia. However it //\r
6 // was limited to Pascal only in its first run.  All I have done is taken  //\r
7 // his original release, translated it to C++ and touched up a few things. //\r
8 // I take absolutely no credit for the concepts presented in this code and //\r
9 // am NOT the person to ask for help if you are having trouble.            //\r
10 //                                                                         //\r
11 // Program Notes : This program implements virtual screens, a great way    //\r
12 //                 to update your screen.                                  //\r
13 //                                                                         //\r
14 //                 For this particular program, I have found the compiler  //\r
15 //                 option -mc (Compact memory model) to work better than   //\r
16 //                 -ml (Large memory model).  However, you must use -mc or //\r
17 //                 greater.                                                //\r
18 //                 Also, you might want to go under "Options...Debugger"   //\r
19 //                 and increase your programs Heap size to >64k.  I don't  //\r
20 //                 know if <64k will lock your system, but I had problems. //\r
21 //                                                                         //\r
22 // Author        : Grant Smith (Denthor) - denthor@beastie.cs.und.ac.za    //\r
23 // Translator    : Christopher G. Mann   - r3cgm@dax.cc.uakron.edu         //\r
24 //                                                                         //\r
25 // Last Modified : December 23, 1994                                       //\r
26 //                                                                         //\r
27 /////////////////////////////////////////////////////////////////////////////\r
28 #include "src\lib\dos_gfx.h"\r
29 \r
30 // declare a pointer to the offset of the Virtual Screen\r
31 byte *vaddr = NULL;\r
32 // declare a pointer to the offset of the VGA memory\r
33 byte *vga = (byte *) MK_FP(VMEM, 0);\r
34 int old_mode;\r
35 //color てすと\r
36 int gq = LGQ;\r
37 //てすと\r
38 int q = 0;\r
39 int bakax = 0, bakay = 0;\r
40 int xx = 0, yy = 0, sx = 0, sy = 0;\r
41 byte coor;\r
42 \r
43 /////////////////////////////////////////////////////////////////////////////\r
44 //                                                                         //\r
45 // setvideo() - This function Manages the video modes                      //\r
46 //                                                                         //\r
47 /////////////////////////////////////////////////////////////////////////////\r
48 void setvideo(byte mode, int vq){\r
49         union REGS in, out;\r
50 \r
51         if(!vq){ // deinit the video\r
52                 // change to the video mode we were in before we switched to mode 13h\r
53                 in.h.ah = 0x00;\r
54                 in.h.al = old_mode;\r
55                 int86(0x10, &in, &out);\r
56         }else if(vq == 1){ // init the video\r
57                 // get old video mode\r
58                 in.h.ah = 0xf;\r
59                 int86(0x10, &in, &out);\r
60                 old_mode = out.h.al;\r
61 \r
62                 // enter mode\r
63                 in.h.ah = 0x00;\r
64                 in.h.al = mode;\r
65                 // vesa\r
66                 //in.x.ax = 0x4f02;\r
67                 //in.x.bx = mode;\r
68                 int86(0x10, &in, &out);\r
69         }\r
70 }\r
71 \r
72 /////////////////////////////////////////////////////////////////////////////\r
73 //                                                                         //\r
74 // setvbuff() - This manages the memory needed for the virtual screen.     //\r
75 //                                                                         //\r
76 /////////////////////////////////////////////////////////////////////////////\r
77 // manages the buffer/virtual screen\r
78 void setvbuff(int vq){\r
79         if(!vq){\r
80                 free(vaddr);\r
81         }else if(vq == 1){\r
82                 vaddr = (byte *) calloc(SW*SH, 1);\r
83 \r
84                 if(vaddr == NULL){\r
85                         setvideo(0x03, 1);\r
86                         cout << "Not enough video memory available, exiting program....";\r
87                         exit(1);\r
88                 }\r
89         }\r
90 }\r
91 \r
92 /////////////////////////////////////////////////////////////////////////////\r
93 //                                                                         //\r
94 // updatevbuff() - This flips the virtual screen to the VGA screen.        //\r
95 //                                                                         //\r
96 /////////////////////////////////////////////////////////////////////////////\r
97 // updates the buffer/virtual screen\r
98 void updatevbuff(){\r
99 /*      // wait for vertical re-trace\r
100         while(inportb(INPUT_STATUS_0) & 8);\r
101         while(!(inportb(INPUT_STATUS_0) & 8));*/\r
102 \r
103         // copy everything to video memory\r
104         _fmemcpy(vga, vaddr, SW*SH);\r
105 }\r
106 \r
107 /////////////////////////////////////////////////////////////////////////////\r
108 //                                                                         //\r
109 // cls() - This clears the screen to the specified color, on the VGA or on //\r
110 //         the Virtual screen.                                             //\r
111 //                                                                         //\r
112 /////////////////////////////////////////////////////////////////////////////\r
113 void cls(byte color, byte *Where){\r
114         _fmemset(Where, color, SW*SH);\r
115 }\r
116 \r
117 // clears the entire video output\r
118 void clearscr(){\r
119         cls(0, vga);\r
120         cls(0, vaddr);\r
121 }\r
122 \r
123 /////////////////////////////////////////////////////////////////////////////\r
124 //                                                                         //\r
125 // plotpixel() - This puts a pixel at X,Y using color Col, on VGA or the    //\r
126 //              Virtual Screen;                                            //\r
127 //                                                                         //\r
128 /////////////////////////////////////////////////////////////////////////////\r
129 void plotpixel(int x, int y, byte color, byte *Where){\r
130         memset(Where+(x+(y*SW)),color,1);\r
131 }\r
132 \r
133 // king_crimson's code\r
134 void plotpixelfast(int x, int y, byte color, byte *Where) {\r
135         byte far *vidptr;\r
136         vidptr = (byte far *)(Where + y*SW + x);\r
137         *vidptr = color;\r
138 }\r
139 \r
140 /////////////////////////////////////////////////////////////////////////////\r
141 //                                                                         //\r
142 // BlockMove() - This tests various ways of moving a block around the      //\r
143 //               screen.                                                   //\r
144 //                                                                         //\r
145 /////////////////////////////////////////////////////////////////////////////\r
146 //てすと\r
147 void BlockMove(){\r
148         int loop1, loop2, loop3;\r
149 \r
150         // This draws a block directly to the VGA with no flipping\r
151         for(loop1=1; loop1<271; loop1++){\r
152         for(loop2=1; loop2<51; loop2++)\r
153                 for(loop3=1; loop3<51; loop3++)\r
154                         plotpixel(loop1+loop2,loop3,32, vga);\r
155                 cls(0,vga);\r
156         }\r
157 \r
158         //`\r
159         for(loop1=1; loop1<281; loop1++){\r
160         for(loop2=1; loop2<41; loop2++)\r
161                 for(loop3=1; loop3<41; loop3++)\r
162                         plotpixel(loop1+loop2,loop3,14, vaddr);\r
163                 updatevbuff();\r
164                 cls(0,vaddr);\r
165         }\r
166 \r
167 /*      // This draws to the virtual screen, waits for retrace, then flips to VGA\r
168         for(loop1=1; loop1<51; loop1++){\r
169         for(loop2=1; loop2<51; loop2++)\r
170                 for(loop3=1; loop3<51; loop3++)\r
171                         plotpixel(loop1+loop2,loop3,32, vaddr);\r
172 //              WaitRetrace();\r
173                 updatevbuff();\r
174                 cls(0,vaddr);\r
175         }*/\r
176 }\r
177 \r
178 void etesuto(int x = 160, int y = 100){\r
179         memset(vaddr+(x+(y*SW)),gq-1,1);\r
180         updatevbuff();\r
181 }\r
182 \r
183 void qtesuto(int x = 160, int y = 100, int color = 0){\r
184         memset(vaddr+(x+(y*SW)),color,1);\r
185         updatevbuff();\r
186 }\r
187 \r
188 //color てすと\r
189 int colortest(){\r
190         if(gq < NUM_COLORS){\r
191                 cls(gq, vaddr);\r
192                 updatevbuff();\r
193                 gq++;\r
194         }else gq = 0;\r
195         return gq;\r
196 }\r
197 \r
198 //color てすと\r
199 int colorz(){\r
200         if(gq < HGQ){\r
201                 cls(gq, vaddr);\r
202                 updatevbuff();\r
203                 gq++;\r
204         }else gq = LGQ;\r
205         return gq;\r
206 }\r
207 \r
208 //slow spectrum down\r
209 void ssd(int svq){\r
210         if(sy < SH+1){\r
211                 if(sx < SW+1){\r
212                         //plotpixel(xx, yy, coor, vga);\r
213                         plotpixelfast(sx, sy, coor, vga);\r
214                         //printf("%d %d %d %d\n", sx, sy, svq, coor);\r
215                         sx++;\r
216                 }else sx = 0;\r
217                 if(sx == SW){\r
218                         sy++;\r
219                         if(svq == 7) coor++;\r
220                         if(sy == SH && svq == 8) coor = rand()%NUM_COLORS;\r
221                 }\r
222         }else sy = 0;\r
223 }\r
224 \r
225 /*-----------ding-------------*/\r
226 int ding(int q){\r
227         int d3y;\r
228 \r
229         if(q <= 4 && gq == BONK-1) coor = rand()%NUM_COLORS;\r
230 \r
231         if(q == 5){ colortest(); return gq; }\r
232         if(q == 10){ colorz(); return gq; }\r
233         if(q == 11){ colorz(); delay(100); return gq; }\r
234         if(q == 8){ ssd(q); /*printf("%d\n", coor);*/ }\r
235         if(q == 6){\r
236                 coor = rand()%NUM_COLORS;\r
237                 cls(coor, vaddr);\r
238                 updatevbuff();\r
239         }\r
240 \r
241         if(q == 7 || q== 9){\r
242                 if(gq < HGQ){\r
243                         if(q == 7) ssd(q);\r
244                         if(q == 9){ ssd(q); coor++; }\r
245                         gq++;\r
246                 }else gq = LGQ;\r
247         }\r
248         if(q<5 && gq<BONK){ // the number variable make the colors more noticable\r
249                 if(q==1){\r
250                         if(xx==SW){bakax=0;}\r
251                         if(xx==0){bakax=1;}\r
252                         if(yy==SH){bakay=0;}\r
253                         if(yy==0){bakay=1;}\r
254                 }else if(q==3){\r
255                         if(xx!=SW||yy!=SH){\r
256                                 if(xx==0){bakax=1;bakay=-1;d3y=1;}\r
257                                 if(yy==0){bakax=1;bakay=0;d3y=1;}\r
258                                 if(xx==SW){bakax=-1;bakay=-1;d3y=1;}\r
259                                 if(yy==SH){bakax=1;bakay=0;d3y=1;}\r
260                         }else if(xx==SW&&yy==SH) xx=yy=0;\r
261                 }\r
262                 if(q==3){\r
263                         if(d3y){\r
264                                 if(bakay<0){\r
265                                         yy--;\r
266                                         d3y--;\r
267                                 }else\r
268                                 if(bakay>0){\r
269                                         yy++;\r
270                                         d3y--;\r
271                                 }\r
272                         }\r
273                         if(bakax<0){\r
274                                 xx--;\r
275                         }else\r
276                         if(bakax>0){\r
277                                 xx++;\r
278                         }\r
279                 }else{\r
280                         if(!bakax){\r
281                                 xx--;\r
282                         }else{\r
283                                 xx++;\r
284                         }\r
285                         if(!bakay){\r
286                                 yy--;\r
287                         }else{\r
288                                 yy++;\r
289                         }\r
290                 }\r
291                 // plot the pixel\r
292                 plotpixelfast(xx, yy, coor, vga);\r
293                 if(q==2) plotpixelfast(rand()%SW, rand()%SH, 0, vga);\r
294                 if(q==2||q==4){ bakax = rand()&0x1; bakay = rand()&0x1; }\r
295                 gq++;\r
296 //              printf("%d %d %d %d\n", xx, yy, gq, coor);\r
297         }else gq = LGQ;\r
298         return gq;\r
299 }\r