]> 4ch.mooo.com Git - 16.git/blob - 16/dos_gfx.cpp
modified: 16/DOS_GFX.EXE
[16.git] / 16 / dos_gfx.cpp
1 /*\r
2  * LIB.C v1.2a\r
3  *\r
4  * by Robert Schmidt\r
5  * (C)1993 Ztiff Zox Softwear\r
6  *\r
7  * Simple graphics library to accompany the article\r
8  * \r
9  *                                        INTRODUCTION TO MODE X.\r
10  * \r
11  * This library provides the basic functions for initializing and using\r
12  * unchained (planar) 256-color VGA modes.  Currently supported are:\r
13  *\r
14  *        - 320x200\r
15  *        - 320x240\r
16  *\r
17  * Functions are provided for:\r
18  *\r
19  *        - initializing one of the available modes\r
20  *        - setting the start address of the VGA refresh data\r
21  *        - setting active and visible display pages\r
22  *        - writing and reading a single pixel to/from video memory\r
23  *\r
24  * The library is provided as a demonstration only, and is not claimed\r
25  * to be particularly efficient or suited for any purpose.  It has only\r
26  * been tested with Borland C++ 3.1 by the author.  Comments on success\r
27  * or disaster with other compilers are welcome.\r
28  *\r
29  * This file is public domain.  Do with it whatever you'd like, but\r
30  * please don't distribute it without the article.\r
31  *\r
32  * Thanks go out to various helpful netters who spotted the 0xE7 bug\r
33  * in the set320x240x256() function!\r
34  *\r
35  * Modified by sparky4 so it can be compiled in open watcom ^^\r
36  */\r
37 \r
38 \r
39 \r
40 \r
41 /*\r
42  * We 'require' a large data model simply to get rid of explicit 'far'\r
43  * pointers and compiler specific '_fmemset()' functions and the likes.\r
44  */\r
45 #if !defined(__COMPACT__)\r
46 # if !defined(__LARGE__)\r
47 #  if !defined(__HUGE__)\r
48 #   error Large data model required!  Try compiling with 'wcc -0 -ml lib.c'.\r
49 #  endif\r
50 # endif\r
51 #endif\r
52 \r
53 #include <dos.h>\r
54 #include <mem.h>\r
55 #include <conio.h>\r
56 \r
57 //code from old library!\r
58 /*src\lib\*/\r
59 #include "dos_gfx.h"\r
60 \r
61 int old_mode;\r
62 //color \82Ä\82·\82Æ\r
63 int gq = LGQ;\r
64 //\82Ä\82·\82Æ\r
65 int q = 0;\r
66 int bakax = 0, bakay = 0;\r
67 cord xx = rand()&0%320, yy = rand()&0%240, sx = 0, sy = 0;\r
68 byte coor;\r
69 \r
70 /*\r
71  * Comment out the following #define if you don't want the testing main()\r
72  * to be included.\r
73  */\r
74 #define TESTING\r
75 \r
76 /*\r
77  * Define the port addresses of some VGA registers.\r
78  */\r
79 #define CRTC_ADDR          0x3d4   /* Base port of the CRT Controller (color) */\r
80 \r
81 #define SEQU_ADDR          0x3c4   /* Base port of the Sequencer */\r
82 #define GRAC_ADDR          0x3ce   /* Base port of the Graphics Controller */\r
83 #define STATUS_ADDR     0x3DA\r
84 \r
85 \r
86 /*\r
87  * Make a far pointer to the VGA graphics buffer segment.  Your compiler\r
88  * might not have the MK_FP macro, but you'll figure something out.\r
89  */\r
90 byte *vga = (byte *) MK_FP(0xA000, 0);\r
91 \r
92 \r
93 /*\r
94  * width and height should specify the mode dimensions.  widthBytes\r
95  * specify the width of a line in addressable bytes.\r
96  */\r
97 unsigned width, height, widthBytes;\r
98 \r
99 /*\r
100  * actStart specifies the start of the page being accessed by\r
101  * drawing operations.  visStart specifies the contents of the Screen\r
102  * Start register, i.e. the start of the visible page.\r
103  */\r
104 unsigned actStart, visStart;\r
105 \r
106 /*\r
107  * set320x200x256_X()\r
108  *        sets mode 13h, then turns it into an unchained (planar), 4-page\r
109  *        320x200x256 mode.\r
110  */\r
111 void set320x200x256_X(void)\r
112                 {\r
113                 union REGS r;\r
114 \r
115                 /* Set VGA BIOS mode 13h: */\r
116                 r.x.ax = 0x0013;\r
117                 int86(0x10, &r, &r);\r
118 \r
119                 /* Turn off the Chain-4 bit (bit 3 at index 4, port 0x3c4): */\r
120                 outpw(SEQU_ADDR, 0x0604);\r
121 \r
122                 /* Turn off word mode, by setting the Mode Control register\r
123                 of the CRT Controller (index 0x17, port 0x3d4): */\r
124                 outpw(CRTC_ADDR, 0xE317);\r
125 \r
126                 /* Turn off doubleword mode, by setting the Underline Location\r
127                    register (index 0x14, port 0x3d4): */\r
128                 outpw(CRTC_ADDR, 0x0014);\r
129 \r
130                 /* Clear entire video memory, by selecting all four planes, then\r
131                    writing 0 to entire segment. */\r
132                 outpw(SEQU_ADDR, 0x0F02);\r
133                 memset(vga+1, 0, 0xffff); /* stupid size_t exactly 1 too small */\r
134                 vga[0] = 0;\r
135 \r
136                 /* Update the global variables to reflect dimensions of this\r
137                    mode.  This is needed by most future drawing operations. */\r
138                 width              = 320;\r
139                 height  = 200;\r
140 \r
141                 /* Each byte addresses four pixels, so the width of a scan line\r
142                    in *bytes* is one fourth of the number of pixels on a line. */\r
143                 widthBytes = width / 4;\r
144 \r
145                 /* By default we want screen refreshing and drawing operations\r
146                    to be based at offset 0 in the video segment. */\r
147                 actStart = visStart = 0;\r
148 \r
149                 }\r
150 \r
151 /*\r
152  * setActiveStart() tells our graphics operations which address in video\r
153  * memory should be considered the top left corner.\r
154  */\r
155 void setActiveStart(unsigned offset)\r
156                 {\r
157                 actStart = offset;\r
158                 }\r
159 \r
160 /*\r
161  * setVisibleStart() tells the VGA from which byte to fetch the first\r
162  * pixel when starting refresh at the top of the screen.  This version\r
163  * won't look very well in time critical situations (games for\r
164  * instance) as the register outputs are not synchronized with the\r
165  * screen refresh.  This refresh might start when the high byte is\r
166  * set, but before the low byte is set, which produces a bad flicker.\r
167  */\r
168 void setVisibleStart(unsigned offset)\r
169                 {\r
170                 visStart = offset;\r
171                 outpw(CRTC_ADDR, 0x0C);          /* set high byte */\r
172                 outpw(CRTC_ADDR+1, visStart >> 8);\r
173                 outpw(CRTC_ADDR, 0x0D);          /* set low byte */\r
174                 outpw(CRTC_ADDR+1, visStart & 0xff);\r
175                 }\r
176 \r
177 /*\r
178  * setXXXPage() sets the specified page by multiplying the page number\r
179  * with the size of one page at the current resolution, then handing the\r
180  * resulting offset value over to the corresponding setXXXStart()\r
181  * function.  The first page is number 0.\r
182  */\r
183 void setActivePage(int page)\r
184                 {\r
185                 setActiveStart(page * widthBytes * height);\r
186                 }\r
187 \r
188 void setVisiblePage(int page)\r
189                 {\r
190                 setVisibleStart(page * widthBytes * height);\r
191                 }\r
192 \r
193 void putPixel_X(int x, int y, byte color)\r
194                 {\r
195                 /* Each address accesses four neighboring pixels, so set\r
196                    Write Plane Enable according to which pixel we want\r
197                    to modify.  The plane is determined by the two least\r
198                    significant bits of the x-coordinate: */\r
199                 outp(0x3c4, 0x02);\r
200                 outp(0x3c5, 0x01 << (x & 3));\r
201 \r
202                 /* The offset of the pixel into the video segment is\r
203                    offset = (width * y + x) / 4, and write the given\r
204                    color to the plane we selected above.  Heed the active\r
205                    page start selection. */\r
206                 vga[(unsigned)(widthBytes * y) + (x / 4) + actStart] = color;\r
207 \r
208                 }\r
209 \r
210 byte getPixel_X(int x, int y)\r
211                 {\r
212                 /* Select the plane from which we must read the pixel color: */\r
213                 outpw(GRAC_ADDR, 0x04);\r
214                 outpw(GRAC_ADDR+1, x & 3);\r
215 \r
216                 return vga[(unsigned)(widthBytes * y) + (x / 4) + actStart];\r
217 \r
218                 }\r
219 \r
220 void set320x240x256_X(void)\r
221                 {\r
222                 /* Set the unchained version of mode 13h: */\r
223                 set320x200x256_X();\r
224 \r
225                 /* Modify the vertical sync polarity bits in the Misc. Output\r
226                    Register to achieve square aspect ratio: */\r
227                 outp(0x3C2, 0xE3);\r
228 \r
229                 /* Modify the vertical timing registers to reflect the increased\r
230                    vertical resolution, and to center the image as good as\r
231                    possible: */\r
232                 outpw(0x3D4, 0x2C11);              /* turn off write protect */\r
233                 outpw(0x3D4, 0x0D06);              /* vertical total */\r
234                 outpw(0x3D4, 0x3E07);              /* overflow register */\r
235                 outpw(0x3D4, 0xEA10);              /* vertical retrace start */\r
236                 outpw(0x3D4, 0xAC11);              /* vertical retrace end AND wr.prot */\r
237                 outpw(0x3D4, 0xDF12);              /* vertical display enable end */\r
238                 outpw(0x3D4, 0xE715);              /* start vertical blanking */\r
239                 outpw(0x3D4, 0x0616);              /* end vertical blanking */\r
240 \r
241                 /* Update mode info, so future operations are aware of the\r
242                    resolution */\r
243                 height = 240;\r
244 \r
245                 }\r
246 \r
247 \r
248 /*-----------XXXX-------------*/\r
249 \r
250 /////////////////////////////////////////////////////////////////////////////\r
251 //                                                                         //\r
252 // WaitRetrace() - This waits until you are in a Verticle Retrace.         //\r
253 //                                                                         //\r
254 /////////////////////////////////////////////////////////////////////////////\r
255 void wait_for_retrace(void)\r
256 {\r
257     while (!(inp(STATUS_ADDR) & 0x08));\r
258 }\r
259 \r
260 /*tile*/\r
261 //king_crimson's code\r
262 void putColorBox_X(int x, int y, int w, int h, byte color) {\r
263         outp(0x3c4, 0x02);\r
264 \r
265         int curx, cury;\r
266         unsigned drawptr;\r
267         for (curx=x; curx<(x+w); curx++) {\r
268                 outp(0x3c5, 0x01 << (curx & 3));\r
269                 drawptr = (unsigned)(widthBytes * y) + (curx / 4) + actStart;\r
270                 for (cury=0; cury<h; cury++) {\r
271                         vga[drawptr] = color;\r
272                         drawptr += widthBytes;\r
273                 }\r
274         }\r
275 }\r
276 \r
277 void vScroll(int rows)\r
278 {\r
279         // Scrolling = current start + (rows * bytes in a row)\r
280         setVisibleStart(visStart + (rows * width));\r
281 }\r
282 \r
283 void scrolly(int bongy)\r
284 {\r
285         int boingy=0;\r
286         if(bongy<0)\r
287                 boingy=-1;\r
288         else if(bongy>0)\r
289                 boingy=1;\r
290 \r
291         for(int ti=0;ti<TILEWH;ti++)\r
292         {\r
293                 delay(1);\r
294                 vScroll(boingy);\r
295         }\r
296 }\r
297 \r
298 //king_crimson's code\r
299 void hScroll(int Cols) {\r
300         wait_for_retrace();\r
301         outp(0x3C0, 0x13);\r
302         outp(0x3C0, Cols & 3);\r
303         outp(0x3D4, 0x13);\r
304         outp(0x3D5, Cols >> 2);\r
305         outp(0x3D4, Cols);\r
306         //setVisibleStart(visStart + (Cols * height));\r
307         setVisibleStart(visStart + (Cols * width));\r
308 }\r
309 \r
310 /////////////////////////////////////////////////////////////////////////////\r
311 //                                                                         //\r
312 // setvideo() - This function Manages the video modes                                     //\r
313 //                                                                         //\r
314 /////////////////////////////////////////////////////////////////////////////\r
315 void setvideo(/*byte mode, */int vq){\r
316                 union REGS in, out;\r
317 \r
318                 if(!vq){ // deinit the video\r
319                                 // change to the video mode we were in before we switched to mode 13h\r
320                                 //mxSetMode( MX_TEXT );\r
321                                 mxTerm();\r
322                                 in.h.ah = 0x00;\r
323                                 in.h.al = old_mode;\r
324                                 int86(0x10, &in, &out);\r
325 \r
326                 }else if(vq == 1){ // init the video\r
327                                 // get old video mode\r
328                                 in.h.ah = 0xf;\r
329                                 int86(0x10, &in, &out);\r
330                                 old_mode = out.h.al;\r
331 \r
332                                 // enter mode\r
333                                 mxInit();\r
334                                 mxSetMode( MX_320x240 );\r
335                                 width=320;\r
336                                 height=240;\r
337 //                              mxSetVirtualScreen(width+(width/4), height+(height/4));\r
338 //                              mxSetVirtualScreen(width*2, height*2);\r
339                                 //set320x240x256_X();\r
340                                 mxSetVirtualScreen(560,420);\r
341 //                              mxSetVirtualScreen((640-(TILEWH*2)),(480-(TILEWH*2)));\r
342                                 mxSetClip(0);\r
343                                 //mxSetClipRegion(0, 0, width, height);\r
344                 }\r
345 }\r
346 \r
347 /////////////////////////////////////////////////////////////////////////////\r
348 //                                                                                                                                               //\r
349 // cls() - This clears the screen to the specified color, on the VGA or on //\r
350 //               the Virtual screen.                                                                                     //\r
351 //                                                                                                                                               //\r
352 /////////////////////////////////////////////////////////////////////////////\r
353 void cls(byte color, byte *Where){\r
354                 _fmemset(Where, color, width*(height*17));\r
355 }\r
356 \r
357 //color \82Ä\82·\82Æ\r
358 int colortest(){\r
359                 if(gq < NUM_COLORS){\r
360                                 cls(gq, vga);\r
361                                 gq++;\r
362                 }else gq = 0;\r
363                 return gq;\r
364 }\r
365 \r
366 //color \82Ä\82·\82Æ\r
367 int colorz(){\r
368                 if(gq < HGQ){\r
369 //----            cls(gq, vaddr);\r
370                                 cls(gq, vga);\r
371                                 gq++;\r
372                 }else gq = LGQ;\r
373                 return gq;\r
374 }\r
375 \r
376 //slow spectrum down\r
377 void ssd(int svq){\r
378                 if(sy < height+1){\r
379                                 if(sx < width+1){\r
380                                                 //plotpixel(xx, yy, coor, vga);\r
381                                                 //ppf(sx, sy, coor, vga);\r
382                                                 putPixel_X(sx, sy, coor);\r
383                                                 //printf("%d %d %d %d\n", sx, sy, svq, coor);\r
384                                                 sx++;\r
385                                 }else sx = 0;\r
386                                 if(sx == width){\r
387                                                 sy++;\r
388                                                 if(svq == 7) coor++;\r
389                                                 if(sy == height && svq == 8) coor = rand()%NUM_COLORS;\r
390                                 }\r
391                 }else sy = 0;\r
392 }\r
393 \r
394 /*-----------ding-------------*/\r
395 int ding(int q){\r
396 \r
397 /*      if(yy<height){\r
398                 setActivePage(0);\r
399                 setVisiblePage(0);\r
400         }\r
401         if((height)<yy<(height*2)){\r
402                 setActivePage(1);\r
403                 setVisiblePage(1);\r
404         }\r
405         if((height*2)<yy<(height*3)){\r
406                 setActivePage(2);\r
407                 setVisiblePage(2);\r
408         }*/\r
409                 int d3y;\r
410 \r
411 //++++  if(q <= 4 && q!=2 && gq == BONK-1) coor = rand()%HGQ;\r
412                 if((q == 2\r
413                 ||q==4\r
414                 ||q==16\r
415                 ) && gq == BONK){\r
416                                                 if(coor < HGQ && coor < LGQ) coor = LGQ;\r
417                                                 if(coor < HGQ-1){\r
418                                                                 coor++;\r
419                                 }else{ coor = LGQ;\r
420                                                 bakax = rand()%3; bakay = rand()%3;\r
421                                 }\r
422                 }\r
423 \r
424                 if(q==8){ colorz(); return gq; }else\r
425                 if(q==10){ ssd(q); /*printf("%d\n", coor);*/ }else\r
426                 if(q==5){ colortest(); return gq; }else\r
427                 if(q==11){ colorz(); delay(100); return gq; }\r
428                 if(q==6){\r
429                                 coor = rand()%NUM_COLORS;\r
430 //----            cls(coor, vaddr);\r
431                                 cls(coor, vga);\r
432                                 //updatevbuff();\r
433                 }\r
434 \r
435                 if(q==7||q==9){\r
436                                 if(gq < HGQ){\r
437                                                 if(q == 7) ssd(q);\r
438                                                 if(q == 9){ ssd(q); coor++; }\r
439                                                 gq++;\r
440                                 }else gq = LGQ;\r
441                 }\r
442                 if((q<5 && gq<BONK) || (q==16 && gq<BONK)){ // the number variable make the colors more noticable\r
443                                 if(q==1){\r
444                                                 if(xx==width){bakax=0;}\r
445                                                 if(xx==0){bakax=1;}\r
446                                                 if(yy==height){bakay=0;}\r
447                                                 if(yy==0){bakay=1;}\r
448                                 }else if(q==3){\r
449                                                 if(xx!=width||yy!=height){\r
450                                                                 if(xx==0){bakax=1;bakay=-1;d3y=1;}\r
451                                                                 if(yy==0){bakax=1;bakay=0;d3y=1;}\r
452                                                                 if(xx==width){bakax=-1;bakay=-1;d3y=1;}\r
453                                                                 if(yy==height){bakax=1;bakay=0;d3y=1;}\r
454                                                 }else if(xx==width&&yy==height) xx=yy=0;\r
455                                 }\r
456                                 if(q==3){\r
457                                                 if(d3y){\r
458                                                                 if(bakay<0){\r
459                                                                                 yy--;\r
460                                                                                 d3y--;\r
461                                                                 }else\r
462                                                                 if(bakay>0){\r
463                                                                                 yy++;\r
464                                                                                 d3y--;\r
465                                                                 }\r
466                                                 }\r
467                                                 if(bakax<0){\r
468                                                                 xx--;\r
469                                                 }else\r
470                                                 if(bakax>0){\r
471                                                                 xx++;\r
472                                                 }\r
473                                 }else{\r
474                                                 if(q==16)\r
475                                                 {\r
476                                                                 if(!bakax){\r
477                                                                         xx--;\r
478                                                                 }else if(bakax>0){\r
479                                                                         xx++;\r
480                                                                 }\r
481                                                                 if(!bakay){\r
482                                                                         yy--;\r
483                                                                 }else if(bakay>0){\r
484                                                                         yy++;\r
485                                                                 }\r
486                                                 }else{\r
487                                                                 if(!bakax){\r
488 //                                                                      xx-=TILEWH;\r
489                                                                         xx--;\r
490                                                                 }else if(bakax>1){\r
491 //                                                                      xx+=TILEWH;\r
492                                                                         xx++;\r
493                                                                 }\r
494                                                                 if(!bakay){\r
495 //                                                                      yy-=TILEWH;\r
496                                                                         yy--;\r
497                                                                 }else if(bakay>1){\r
498 //                                                                      yy+=TILEWH;\r
499                                                                         yy++;\r
500                                                                 }\r
501                                                 }\r
502                                 }\r
503                                 // fixer\r
504 //                              if(q!=16){\r
505                                                 if(xx<0) xx=(560/*-TILEWH*/);\r
506                                                 if(yy<0) yy=(420/*-TILEWH*/);\r
507                                                 if(xx>(560/*-TILEWH*/)) xx=0;\r
508                                                 if(yy>(420/*-TILEWH*/)) yy=0;\r
509 //                              }\r
510 \r
511 //interesting effects\r
512                                 if(q==16)\r
513                                 {\r
514                                 int tx=0,ty=0;\r
515                                 tx+=xx+16;\r
516                                 ty+=yy+16;\r
517                                 mxPutPixel(tx, ty, coor);\r
518                                 //drawrect(tx, ty, tx+TILEWH, ty+TILEWH, coor);\r
519                                 //printf("%d %d %d %d %d %d\n", xx, yy, tx, ty, TILEWH);\r
520 \r
521                                 // plot the pixel\r
522 //----            ppf(xx, yy, coor, vga);\r
523                                 }else /*if(xx>=0 && xx<width && yy>=0 && yy<(height*3))*/{\r
524 //                                      mxFillBox(xx, yy, TILEWH, TILEWH, coor, 0);\r
525 //++++0000\r
526 //                                      putPixel_X(xx, yy, coor);\r
527                                         mxPutPixel(xx, yy, coor);\r
528                                 } \r
529 \r
530 //----            if(q==2) ppf(rand()%, rand()%height, 0, vga);\r
531 //                              if(q==2) putColorBox_X(rand()%width, rand()%(height*3), TILEWH, TILEWH, 0);\r
532 //++++0000\r
533                                 if(q==2) mxPutPixel(rand()%width, rand()%(height*3), 0);\r
534                                 if(q==16) mxPutPixel(rand()%width, rand()%(height*3), 0);\r
535                                 if(q==2||q==4||q==16){ bakax = rand()%3; bakay = rand()%3; }\r
536                                 gq++;\r
537 //if(xx<0||xx>320||yy<0||yy>(height*3))\r
538 //        printf("%d %d %d %d %d %d\n", xx, yy, coor, bakax, bakay, getPixel_X(xx,yy));\r
539 //        printf("%d\n", getPixel_X(xx,yy));\r
540                 }else gq = LGQ;\r
541                 return gq;\r
542 }\r
543 \r
544 \r
545 /*\r
546  * The library testing routines follows below.\r
547  */\r
548 \r
549 \r
550 #ifdef TESTING\r
551 \r
552 #include <stdio.h>\r
553 #include <conio.h>\r
554 \r
555 void doTest(void)\r
556                 {\r
557                 int p, x, y, pages;\r
558 \r
559                 /* This is the way to calculate the number of pages available. */\r
560                 pages = 65536L/(widthBytes*height); // apparently this takes the A000 address\r
561 //              if(height==240) pages++;\r
562 \r
563 //              printf("%d\n", pages);\r
564 \r
565                 for (p = 0; p <= pages; ++p)\r
566                                 {\r
567                                 setActivePage(p);\r
568 \r
569                                 /* On each page draw a single colored border, and dump the palette\r
570                                    onto a small square about the middle of the page. */\r
571 \r
572                                    //{\r
573                                                 for (x = 0; x <= width; ++x)\r
574                                                                 {\r
575 //                                                              putPixel_X(x, 0, p+1);\r
576                                                                 mxPutPixel(x, 0, p+1);\r
577                                                                 if(p!=pages) mxPutPixel(x, height-1, p+1);\r
578                                                                                 else if(height==240) mxPutPixel(x, 99-1, p+1);\r
579                                                                 }\r
580 \r
581                                                 for (y = 0; y <= height; ++y)\r
582                                                                 {\r
583                                                                 mxPutPixel(0, y, p+1);\r
584                                                                 if(p!=pages) mxPutPixel(width-1, y, p+1);\r
585                                                                                 else if(height==240) mxPutPixel(width-1, y, p+1);\r
586                                                                 }\r
587 \r
588                                                 for (x = 0; x < TILEWH; ++x)\r
589                                                                 for (y = 0; y < TILEWH; ++y)\r
590                                                                                 mxPutPixel(x+(p+2)*16, y+(p+2)*TILEWH, x + y*TILEWH);\r
591                                                 //}\r
592 \r
593                                 }\r
594 \r
595                 /* Each pages will now contain a different image.  Let the user cycle\r
596                    through all the pages by pressing a key. */\r
597                 for (p = 0; p < pages; ++p)\r
598                                 {\r
599                                 setVisiblePage(p);\r
600                                 getch();\r
601                                 }\r
602 \r
603                 }\r
604 \r
605 /*\r
606  * Library test (program) entry point.\r
607  */\r
608 \r
609 int main(void)\r
610                 {\r
611                 int key,d,xpos,ypos,xdir,ydir;\r
612                 //short int temp;\r
613                 // main variables\r
614                 d=1; // switch variable\r
615                 key=4; // default screensaver number\r
616                 xpos=0;\r
617                 ypos=0;
618                 xdir=1;\r
619                 ydir=1;\r
620 //        puts("First, have a look at the 320x200 mode.  I will draw some rubbish");\r
621 //        puts("on all of the four pages, then let you cycle through them by");\r
622 //        puts("hitting a key on each page.");\r
623 //        puts("Press a key when ready...");\r
624 //        getch();\r
625 \r
626 //        doTest();\r
627 \r
628 //        puts("Then, check out Mode X, 320x240 with 3 (and a half) pages.");\r
629 //        puts("Press a key when ready...");\r
630 //        getch();\r
631 \r
632 //++++0000\r
633                 setvideo(1);\r
634 // screen savers\r
635 \r
636 /*while(d!=0){ // on!\r
637                                 if(!kbhit()){ // conditions of screen saver\r
638                                                 ding(key);\r
639                                 }else{\r
640                                                 setvideo(0);\r
641                                                 // user imput switch\r
642                                                 printf("Enter 1, 2, 3, 4, or 6 to run a screensaver, or enter 5 to quit.\n", getch());  // prompt the user\r
643                                                 scanf("%d", &key);\r
644                                                 //if(key==3){xx=yy=0;} // crazy screen saver wwww\r
645                                                 if(key==5) d=0;\r
646                                                 setvideo(1);\r
647                                 }\r
648                 }*/ // else off\r
649                 while(!kbhit()){ // conditions of screen saver\r
650                         ding(key);\r
651                 }\r
652                 //end of screen savers\r
653                 //doTest();\r
654                 for (int x = 0; x < width; ++x)\r
655                         {\r
656                                 mxPutPixel(x, 0, 15);\r
657                                 mxPutPixel(x, height-1, 15);\r
658                         }\r
659                 for (int y = 0; y < height; ++y)\r
660                         {\r
661                                 mxPutPixel(0, y, 15);\r
662                                 mxPutPixel(width-1, y, 15);\r
663                         }\r
664                 getch();\r
665                 while(!kbhit()){\r
666 //                      hScroll(1);\r
667 //                      scrolly(1);\r
668 //                      vScroll(1);\r
669 //                      delay(100);\r
670                         //for(int i=0;i<TILEWH;i++){\r
671                                 ding(key);\r
672                                 mxPan(xpos,ypos);\r
673                                 mxWaitRetrace();\r
674                                 xpos=xpos+xdir;\r
675                                 ypos=ypos+ydir;\r
676                                 if( (xpos>239)  || (xpos<1))xdir=-xdir;\r
677                                 if( (ypos>179) || (ypos<1))ydir=-ydir; // { Hit a boundry, change\r
678                         //    direction! }\r
679                         //}\r
680                 }\r
681                 setvideo(0);\r
682                 printf("wwww\n%dx%d\n", width,height);\r
683                 printf("[%d]\n", mxGetVersion());\r
684                 puts("where to next?  It's your move! wwww");\r
685                 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
686                 return 0;\r
687                 }\r
688 \r
689 #endif\r