]> 4ch.mooo.com Git - 16.git/blob - 16/dos_gfx.cpp
modified: scroll.exe
[16.git] / 16 / dos_gfx.cpp
1 //DOS Graphics thingy by sparky4 licence GPL v2\r
2 //a special thanks to everyone to release source code for mode X\r
3 /*src\lib\*/\r
4 #include "dos_gfx.h"
5 //#include "lib\modex16.h" //____\r
6 \r
7 int old_mode;\r
8 //color \82Ä\82·\82Æ\r
9 short gq = LGQ;\r
10 \r
11 //\82Ä\82·\82Æ\r
12 short bakax = 0, bakay = 0;\r
13 word xx = rand()&0%SW, yy = rand()&0%SH, sx = 0, sy = 0;\r
14 byte coor;\r
15 \r
16 byte *vga = (byte *) MK_FP(0xA000, 0);\r
17 \r
18 /*\r
19  * Comment out the following #define if you don't want the testing main()\r
20  * to be included.\r
21  */\r
22 #define TESTING\r
23 //#define TILE\r
24 \r
25 /////////////////////////////////////////////////////////////////////////////\r
26 //                                                                         //\r
27 // setvideo() - This function Manages the video modes                                     //\r
28 //                                                                         //\r
29 /////////////////////////////////////////////////////////////////////////////\r
30 void setvideo(/*byte mode, */short vq){\r
31                 union REGS in, out;\r
32 \r
33                 if(!vq){ // deinit the video\r
34                                 // change to the video mode we were in before we switched to mode 13h\r
35                                 //mxSetMode( MX_TEXT );\r
36                                 mxTerm();\r
37                                 in.h.ah = 0x00;\r
38                                 in.h.al = old_mode;\r
39                                 int86(0x10, &in, &out);\r
40 \r
41                 }else if(vq==1){ // init the video\r
42                                 // get old video mode\r
43                                 in.h.ah = 0xf;\r
44                                 int86(0x10, &in, &out);\r
45                                 old_mode = out.h.al;\r
46 \r
47                                 // enter mode\r
48                                 mxInit();\r
49                                 mxSetMode( MX_320x240 );\r
50 //                              mxSetVirtualScreen(SW+(SW/4), SH+(SH/4));\r
51 //                              mxSetVirtualScreen(SW*2, SH*2);\r
52                                 mxSetVirtualScreen(VW,BH);\r
53 //                              mxSetVirtualScreen((640-(TILEWH*4)),(480-(TILEWH*4)));\r
54                                 mxSetClip(true);\r
55                                 mxSetClipRegion(0, 0, VW, BH);\r
56                                 mxPan(TILEWH*2,TILEWH*2);\r
57                                 //mxSetClipRegion(0, VH+1, VW, (TILEWH*BUFFMX));\r
58                 }\r
59 }\r
60 \r
61 void pdump(){\r
62         int mult=(QUADWH)/2;\r
63         int palq=(mult)*16;\r
64         int palcol=0;\r
65         for(int paly=0; paly<palq; paly+=mult){\r
66                 for(int palx=0; palx<palq; palx+=mult){\r
67                                 mxFillBox((SW-palq)+palx+32, paly+32, TILEWH, TILEWH, palcol, OP_SET);\r
68                         palcol++;\r
69                 }\r
70         }\r
71 }\r
72 \r
73 /////////////////////////////////////////////////////////////////////////////\r
74 //                                                                                                                                               //\r
75 // cls() - This clears the screen to the specified color, on the VGA or on //\r
76 //               the Virtual screen.                                                                                     //\r
77 //                                                                                                                                               //\r
78 /////////////////////////////////////////////////////////////////////////////\r
79 void cls(byte color, byte *Where){\r
80                 _fmemset(Where, color, VW*(VH*2));\r
81 }\r
82 \r
83 //color \82Ä\82·\82Æ\r
84 short colortest(){\r
85                 if(gq < NUM_COLORS){\r
86                                 cls(gq, vga);\r
87                                 gq++;\r
88                 }else gq = 0;\r
89                 return gq;\r
90 }\r
91 \r
92 //color \82Ä\82·\82Æ\r
93 short colorz(){\r
94                 if(gq <= HGQ){\r
95 //----            cls(gq, vaddr);\r
96                                 cls(gq, vga);\r
97                                 gq++;\r
98                 }else gq = LGQ;\r
99                 return gq;\r
100 }\r
101 \r
102 //slow spectrum down\r
103 void ssd(short svq){\r
104                 if(sy < SH+1){\r
105                                 if(sx < SW+1){\r
106                                                 //plotpixel(xx, yy, coor, vga);\r
107                                                 //ppf(sx, sy, coor, vga);\r
108                                                 mxPutPixel(sx, sy, coor);\r
109                                                 //printf("%d %d %d %d\n", sx, sy, svq, coor);\r
110                                                 sx++;\r
111                                 }else sx = 0;\r
112                                 if(sx == SW){\r
113                                                 sy++;\r
114                                                 if(svq == 7) coor++;\r
115                                                 if(sy == SH && svq == 8) coor = rand()%NUM_COLORS;\r
116                                 }\r
117                 }else sy = 0;\r
118 }\r
119 \r
120 /*-----------ding-------------*/\r
121 short ding(int q){\r
122 \r
123                 short d3y;\r
124 \r
125 //++++  if(q <= 4 && q!=2 && gq == BONK-1) coor = rand()%HGQ;\r
126                 if((q == 2\r
127                 ||q==4\r
128                 ||q==16\r
129                 ) && gq == BONK){\r
130                                                 if(coor < HGQ && coor < LGQ) coor = LGQ;\r
131                                                 if(coor < HGQ){\r
132                                                                 coor++;\r
133                                 }else{ coor = LGQ;\r
134                                                 bakax = rand()%3; bakay = rand()%3;\r
135                                 }\r
136                 }\r
137 \r
138                 if(q==8){ colorz(); return gq; mxOutText(SW/2, SH/2, "bakapi"); }else\r
139                 if(q==10){ ssd(q); /*printf("%d\n", coor);*/ }else\r
140                 if(q==5){ colortest(); return gq; }else\r
141                 if(q==11){ colorz(); delay(100); return gq; }\r
142                 if(q==6){\r
143                                 coor = rand()%NUM_COLORS;\r
144                                 cls(coor, vga);\r
145                                 //updatevbuff();\r
146                 }\r
147 \r
148                 if(q==7||q==9){\r
149                                 if(gq <= HGQ){\r
150                                                 if(q == 7) ssd(q);\r
151                                                 if(q == 9){ ssd(q); coor++; }\r
152                                                 gq++;\r
153                                 }else gq = LGQ;\r
154                 }\r
155                 if((q<5 && gq<BONK) || (q==16 && gq<BONK)){ // the number variable make the colors more noticable\r
156                                 if(q==1){\r
157                                                 if(xx==VW){bakax=0;}\r
158                                                 if(xx==0){bakax=1;}\r
159                                                 if(yy==VH){bakay=0;}\r
160                                                 if(yy==0){bakay=1;}\r
161                                 }else if(q==3){\r
162                                                 if(xx!=VW||yy!=VH){\r
163                                                                 if(xx==0){bakax=1;bakay=-1;d3y=1;}\r
164                                                                 if(yy==0){bakax=1;bakay=0;d3y=1;}\r
165                                                                 if(xx==VW){bakax=-1;bakay=-1;d3y=1;}\r
166                                                                 if(yy==VH){bakax=1;bakay=0;d3y=1;}\r
167                                                 }else if(xx==VW&&yy==VH) xx=yy=0;\r
168                                 }\r
169                                 if(q==3){\r
170                                                 if(d3y){\r
171                                                                 if(bakay<0){\r
172                                                                                 yy--;\r
173                                                                                 d3y--;\r
174                                                                 }else\r
175                                                                 if(bakay>0){\r
176                                                                                 yy++;\r
177                                                                                 d3y--;\r
178                                                                 }\r
179                                                 }\r
180                                                 if(bakax<0){\r
181                                                                 xx--;\r
182                                                 }else\r
183                                                 if(bakax>0){\r
184                                                                 xx++;\r
185                                                 }\r
186                                 }else{\r
187                                                 if(q==16)\r
188                                                 {\r
189                                                                 if(!bakax){\r
190                                                                         xx--;\r
191                                                                 }else if(bakax>0){\r
192                                                                         xx++;\r
193                                                                 }\r
194                                                                 if(!bakay){\r
195                                                                         yy--;\r
196                                                                 }else if(bakay>0){\r
197                                                                         yy++;\r
198                                                                 }\r
199                                                 }else{\r
200                                                                 if(!bakax){\r
201                                                                         #ifdef TILE\r
202                                                                         xx-=TILEWH;\r
203                                                                         #else\r
204                                                                         xx--;\r
205                                                                         #endif\r
206                                                                 }else if(bakax>1){\r
207                                                                         #ifdef TILE\r
208                                                                         xx+=TILEWH;\r
209                                                                         #else\r
210                                                                         xx++;\r
211                                                                         #endif\r
212                                                                 }\r
213                                                                 if(!bakay){\r
214                                                                         #ifdef TILE\r
215                                                                         yy-=TILEWH;\r
216                                                                         #else\r
217                                                                         yy--;\r
218                                                                         #endif\r
219                                                                 }else if(bakay>1){\r
220                                                                         #ifdef TILE\r
221                                                                         yy+=TILEWH;\r
222                                                                         #else\r
223                                                                         yy++;\r
224                                                                         #endif\r
225                                                                 }\r
226                                                 }\r
227                                 }\r
228                                 // fixer\r
229                                 if(q!=16){\r
230                                         #ifdef TILE\r
231                                                 if(xx<0) xx=(VW-TILEWH);\r
232                                                 if(yy<0) yy=(VH-TILEWH);\r
233                                                 if(xx>(VW-TILEWH)) xx=0;\r
234                                                 if(yy>(VH-TILEWH)/*+(TILEWH*BUFFMX)*/) yy=0;\r
235                                         #else\r
236                                                 if(xx<0) xx=VW;\r
237                                                 if(yy<0) yy=VH;\r
238                                                 if(xx>VW) xx=0;\r
239                                                 if(yy>VH) yy=0;\r
240                                         #endif\r
241                                 }\r
242 \r
243 //interesting effects\r
244                                 if(q==16)\r
245                                 {\r
246                                 short tx=0,ty=0;\r
247                                 tx+=xx+16;\r
248                                 ty+=yy+16;\r
249                                 mxPutPixel(tx, ty, coor);\r
250                                 //printf("%d %d %d %d %d %d\n", xx, yy, tx, ty, TILEWH);\r
251 \r
252                                 // plot the pixel\r
253                                 }else{\r
254                                         #ifdef TILE\r
255                                         mxFillBox(xx, yy, TILEWH, TILEWH, coor, OP_SET);\r
256                                         #else\r
257                                         mxPutPixel(xx, yy, coor);\r
258                                         #endif\r
259                                 } \r
260 \r
261                                 if(q==2)\r
262                                 #ifdef TILE\r
263                                         mxFillBox((rand()*TILEWH)%VW, (rand()*TILEWH)%(VH), TILEWH, TILEWH, 0, OP_SET);\r
264                                 #else\r
265                                         mxPutPixel(rand()%VW, rand()%(VH), 0);\r
266                                 #endif\r
267                                 if(q==16) mxPutPixel(rand()%VW, rand()%(VH), 0);\r
268                                 if(q==2||q==4||q==16){ bakax = rand()%3; bakay = rand()%3; }  //random 3 switch\r
269                                 gq++;\r
270 //if(xx<0||xx>320||yy<0||yy>(SH*3))\r
271 //        printf("%d %d %d %d %d\n", xx, yy, coor, bakax, bakay);\r
272                 }else gq = LGQ;\r
273                 return gq;\r
274 }\r
275 \r
276 \r
277 /*\r
278  * The library testing routines follows below.\r
279  */\r
280 \r
281 #ifdef TESTING\r
282 \r
283 /*\r
284  * Library test (program) entry point.\r
285  */\r
286 \r
287 int main(void)\r
288                 {
289                 //bitmap_t bmp; //____
290                 //bmp = modexLoadPcx("chikyuu.pcx"); //____\r
291                 short key,d,xpos,ypos,xdir,ydir;\r
292                 int ch=0x0;\r
293                 // main variables\r
294                 d=4; // switch variable\r
295                 key=2; // default screensaver number\r
296                 xpos=TILEWH*2;\r
297                 ypos=TILEWH*2;\r
298                 xdir=1;\r
299                 ydir=1;\r
300                 setvideo(1);
301                 //modexPalUpdate(bmp.palette); //____
302                 //modexDrawBmp(VGA, 0, 0, &bmp, 0); //____
303                 //getch(); //____\r
304 // screen savers\r
305 \r
306 /*while(d!=0){ // on!\r
307                                 if(!kbhit()){ // conditions of screen saver\r
308                                                 ding(key);\r
309                                 }else{\r
310                                                 setvideo(0);\r
311                                                 // user imput switch\r
312                                                 printf("Enter 1, 2, 3, 4, or 6 to run a screensaver, or enter 5 to quit.\n", getch());  // prompt the user\r
313                                                 scanf("%d", &key);\r
314                                                 //if(key==3){xx=yy=0;} // crazy screen saver wwww\r
315                                                 if(key==5) d=0;\r
316                                                 setvideo(1);\r
317                                 }\r
318                 }*/ // else off\r
319                 //mxFillBox(0, 0, VW, BH, 10, OP_SET);\r
320                 while(1){ // conditions of screen saver\r
321                 while(!kbhit()){\r
322                         ding(key);\r
323                 }\r
324                 //end of screen savers\r
325                 //doTest();\r
326 /*              for (int x = 0; x < VW; ++x)\r
327                         {\r
328                                 mxPutPixel(x, 0, 15);\r
329                                 mxPutPixel(x, SH-1, 15);\r
330                         }\r
331                 for (int y = 0; y < VH; ++y)\r
332                         {\r
333                                 mxPutPixel(0, y, 15);\r
334                                 mxPutPixel(SW-1, y, 15);\r
335                         }\r
336                 for (int x = 0; x < VW; ++x)\r
337                         {\r
338                                 mxPutPixel(x, 0, 15);\r
339                                 mxPutPixel(x, VH-1, 15);\r
340                         }\r
341                 for (int y = 240; y < VH; ++y)\r
342                         {\r
343                                 mxPutPixel(0, y, 15);\r
344                                 mxPutPixel(VW-1, y, 15);\r
345                         }\r
346                         */\r
347                         pdump();\r
348                         getch();\r
349                         //text box\r
350                         mxSetTextColor(10, OP_TRANS); //set font\r
351                         mxBitBlt(xpos, ypos+(TILEWH*12), SW, TILEWH*BUFFMX, 0, BS); //copy background\r
352                         mxFillBox(xpos, ypos+(TILEWH*12), SW, TILEWH*BUFFMX, 0, OP_SET); // background for text box\r
353                         //+(QUADWH*6)\r
354                         mxOutText(xpos+1, ypos+SH-48, "========================================");\r
355                         mxOutText(xpos+1, ypos+SH-40, "|    |Chikyuu:$line1");\r
356                         mxOutText(xpos+1, ypos+SH-32, "|    |$line2");\r
357                         mxOutText(xpos+1, ypos+SH-24, "|    |$line3");\r
358                         mxOutText(xpos+1, ypos+SH-16, "|    |$line4");\r
359                         mxOutText(xpos+1, ypos+SH-8,  "========================================");\r
360                         mxFillBox(xpos+QUADWH, ypos+QUADWH+(TILEWH*12), TILEWH*2, TILEWH*2, 9, OP_SET); //portriat~\r
361                         getch();\r
362                         mxBitBlt(0, BS, SW, TILEWH*BUFFMX, xpos, ypos+(TILEWH*12)); //copy background\r
363                         getch();\r
364                 while(!kbhit()){\r
365                         //for(int i=0;i<TILEWH;i++){\r
366                                 \r
367                                 ding(key);\r
368                                 mxPan(xpos,ypos);\r
369 mxFillBox(384, 304, 384, 304, 10, OP_SET);\r
370 //mxBitBlt(xpos, ypos, SW, SH, 32, (SH+64+32));\r
371 mxBitBlt(TILEWH*2, TILEWH*2, SW, SH, 32, (SH+64+32));\r
372                                 //for(short o = 0; o<TILEWH; o++){\r
373                                         xpos+=xdir;\r
374                                         ypos+=ydir;\r
375                                         //if(ypos==1 || (ypos==(BH-SH-1)))delay(500);\r
376                                         //if((xpos>(VW-SW-1)) || (xpos<1))delay(500);\r
377                                         //mxWaitRetrace();\r
378 //mxBitBlt(32, (SH+32), SW, SH, xpos, ypos);\r
379 mxBitBlt(TILEWH*2, (SH+64+32), SW, SH, TILEWH*2, TILEWH*2);\r
380 //xpos=ypos=TILEWH*2;\r
381 mxPan(32,32);\r
382                                 //}\r
383                                 if( (xpos>(VW-SW-1))  || (xpos<1)){xdir=-xdir;}\r
384                                 if( (ypos>(BH-SH-1)) || (ypos<1)){ydir=-ydir;} // { Hit a boundry, change\r
385                         //    direction! }\r
386 //mxBitBlt(32, (SH+64+32), SW, SH, xpos, ypos);\r
387 //mxBitBlt(TILEWH*2, (SH+64+32), SW, SH, TILEWH*2, TILEWH*2);\r
388                         }\r
389                         ch=getch();\r
390                         if(ch==0x71)break; // 'q'\r
391                         if(ch==0x1b)break; // 'ESC'\r
392                 }\r
393                 setvideo(0);\r
394                 printf("wwww\nFull Buffer Virtual Resolution: %dx%d\n", VW,BH);\r
395                 printf("Virtual Resolution: %dx%d\n", VW,VH);\r
396                 printf("Resolution: %dx%d\n", SW,SH);\r
397                 printf("Mode X Library Version: %d\n", mxGetVersion());\r
398                 printf("bakapi ver. 1.04.09.04\nis made by sparky4\81i\81\86\83Ö\81\85\81j feel free to use it ^^\nLicence: GPL v2\n");\r
399                 return 0;\r
400                 }\r
401 \r
402 #endif\r