1 /////////////////////////////////////////////////////////////////////////////
\r
3 // TUTPROG4.CPP - VGA Trainer Program 4 (in Turbo C++ 3.0) //
\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
11 // Program Notes : This program implements virtual screens, a great way //
\r
12 // to update your screen. //
\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
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
22 // Author : Grant Smith (Denthor) - denthor@beastie.cs.und.ac.za //
\r
23 // Translator : Christopher G. Mann - r3cgm@dax.cc.uakron.edu //
\r
25 // Last Modified : December 23, 1994 //
\r
27 /////////////////////////////////////////////////////////////////////////////
\r
28 #include "src\lib\dos_gfx.h"
\r
30 // declare a pointer to the offset of the Virtual Screen
\r
32 // declare a pointer to the offset of the VGA memory
\r
33 byte *vga = (byte *) MK_FP(VMEM, 0);
\r
39 int bakax = 0, bakay = 0;
\r
40 int xx = 0, yy = 0, sx = 0, sy = 0;
\r
43 /////////////////////////////////////////////////////////////////////////////
\r
45 // setvideo() - This function Manages the video modes //
\r
47 /////////////////////////////////////////////////////////////////////////////
\r
48 void setvideo(byte mode, int vq){
\r
51 if(!vq){ // deinit the video
\r
52 // change to the video mode we were in before we switched to mode 13h
\r
55 int86(0x10, &in, &out);
\r
56 }else if(vq == 1){ // init the video
\r
57 // get old video mode
\r
59 int86(0x10, &in, &out);
\r
60 old_mode = out.h.al;
\r
68 int86(0x10, &in, &out);
\r
72 /////////////////////////////////////////////////////////////////////////////
\r
74 // setvbuff() - This manages the memory needed for the virtual screen. //
\r
76 /////////////////////////////////////////////////////////////////////////////
\r
77 // manages the buffer/virtual screen
\r
78 void setvbuff(int vq){
\r
82 vaddr = (byte *) calloc(SW*SH, 1);
\r
86 cout << "Not enough video memory available, exiting program....";
\r
92 /////////////////////////////////////////////////////////////////////////////
\r
94 // updatevbuff() - This flips the virtual screen to the VGA screen. //
\r
96 /////////////////////////////////////////////////////////////////////////////
\r
97 // updates the buffer/virtual screen
\r
99 /* // wait for vertical re-trace
\r
100 while(inportb(INPUT_STATUS_0) & 8);
\r
101 while(!(inportb(INPUT_STATUS_0) & 8));*/
\r
103 // copy everything to video memory
\r
104 _fmemcpy(vga, vaddr, SW*SH);
\r
107 /////////////////////////////////////////////////////////////////////////////
\r
109 // cls() - This clears the screen to the specified color, on the VGA or on //
\r
110 // the Virtual screen. //
\r
112 /////////////////////////////////////////////////////////////////////////////
\r
113 void cls(byte color, byte *Where){
\r
114 _fmemset(Where, color, SW*SH);
\r
117 // clears the entire video output
\r
123 /////////////////////////////////////////////////////////////////////////////
\r
125 // plotpixel() - This puts a pixel at X,Y using color Col, on VGA or the //
\r
126 // Virtual Screen; //
\r
128 /////////////////////////////////////////////////////////////////////////////
\r
129 void plotpixel(int x, int y, byte color, byte *Where){
\r
130 memset(Where+(x+(y*SW)),color,1);
\r
133 // king_crimson's code
\r
134 void plotpixelfast(int x, int y, byte color, byte *Where) {
\r
136 vidptr = (byte far *)(Where + y*SW + x);
\r
140 /////////////////////////////////////////////////////////////////////////////
\r
142 // BlockMove() - This tests various ways of moving a block around the //
\r
145 /////////////////////////////////////////////////////////////////////////////
\r
148 int loop1, loop2, loop3;
\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
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
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
178 void etesuto(int x = 160, int y = 100){
\r
179 memset(vaddr+(x+(y*SW)),gq-1,1);
\r
183 void qtesuto(int x = 160, int y = 100, int color = 0){
\r
184 memset(vaddr+(x+(y*SW)),color,1);
\r
190 if(gq < NUM_COLORS){
\r
208 //slow spectrum down
\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
219 if(svq == 7) coor++;
\r
220 if(sy == SH && svq == 8) coor = rand()%NUM_COLORS;
\r
225 /*-----------ding-------------*/
\r
229 if(q <= 4 && gq == BONK-1) coor = rand()%NUM_COLORS;
\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
236 coor = rand()%NUM_COLORS;
\r
241 if(q == 7 || q== 9){
\r
244 if(q == 9){ ssd(q); coor++; }
\r
248 if(q<5 && gq<BONK){ // the number variable make the colors more noticable
\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
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
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
296 // printf("%d %d %d %d\n", xx, yy, gq, coor);
\r