]> 4ch.mooo.com Git - 16.git/blob - src/bakapi.c
doslib probe DOS, CPU, and VGA. exit politely if not VGA.
[16.git] / src / bakapi.c
1 /* Project 16 Source Code~
2  * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123
3  *
4  * This file is part of Project 16.
5  *
6  * Project 16 is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Project 16 is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You screen.heightould have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,
19  * Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22
23 #include "src/bakapi.h"
24
25 /*
26  * BAKAPEE!
27  */
28 global_game_variables_t gvar;
29 static bakapee_t bakapee;
30 word key,d,xpos,ypos,xdir,ydir;
31 int ch=0x0;
32
33 void
34 main(int argc, char *argvar[])
35 {
36         // DOSLIB: check our environment
37         probe_dos();
38
39         // DOSLIB: what CPU are we using?
40         // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.
41         //      So this code by itself shouldn't care too much what CPU it's running on. Except that other
42         //      parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for
43         //      the CPU to carry out tasks. --J.C.
44         cpu_probe();
45
46         // DOSLIB: check for VGA
47         if (!probe_vga()) {
48                 printf("VGA probe failed\n");
49                 return;
50         }
51         // hardware must be VGA or higher!
52         if (!(vga_state.vga_flags & VGA_IS_VGA)) {
53                 printf("This program requires VGA or higher graphics hardware\n");
54                 return;
55         }
56
57         // main variables values
58         d=4; // switch variable
59         key=2; // default screensaver number
60         xpos=TILEWH*2;
61         ypos=TILEWH*2;
62         xdir=1;
63         ydir=1;
64
65 #ifdef MXLIB
66         VGAmodeX(1, &gvar);
67 #else
68         int10_setmode(19);
69         update_state_from_vga();
70         vga_enable_256color_modex(); // VGA mode X
71         vga_state.vga_width = 320; // VGA lib currently does not update this
72         vga_state.vga_height = 240; // VGA lib currently does not update this
73
74 //#if 1 // 320x240 test mode: this is how Project 16 is using our code, enable for test case
75         {
76                 struct vga_mode_params cm;
77
78                 vga_read_crtc_mode(&cm);
79
80                 // 320x240 mode 60Hz
81                 cm.vertical_total = 525;
82                 cm.vertical_start_retrace = 0x1EA;
83                 cm.vertical_end_retrace = 0x1EC;
84                 cm.vertical_display_end = 480;
85                 cm.vertical_blank_start = 489;
86                 cm.vertical_blank_end = 517;
87
88                 vga_write_crtc_mode(&cm,0);
89         }
90         vga_state.vga_height = 240; // VGA lib currently does not update this
91 //#endif
92 #endif
93         bakapee.xx = rand()&0%gvar.video.page[0].width;
94         bakapee.yy = rand()&0%gvar.video.page[0].height;
95         bakapee.gq = 0;
96         bakapee.sx=0;
97         bakapee.sy=0;
98         bakapee.bakax=0;
99         bakapee.bakay=0;
100         bakapee.coor=0;
101         bakapee.tile=0;
102
103         /* setup camera and screen~ */
104         gvar.video.page[0] = modexDefaultPage(&gvar.video.page[0]);
105         gvar.video.page[0].width += (TILEWH*2);
106         gvar.video.page[0].height += (TILEWH*2);
107         textInit();
108
109         //modexPalUpdate(bmp.palette); //____
110         //modexDrawBmp(VGA, 0, 0, &bmp, 0); //____
111         //getch(); //____
112
113         modexShowPage(&gvar.video.page[0]);
114
115 // screen savers
116 #ifdef BOINK
117         while(d>0)      // on!
118         {
119                 if(!kbhit())
120                 { // conditions of screen saver
121                         ding(&gvar.video.page[0], &bakapee, key);
122                 }
123                 else
124                 {
125 #ifndef MXLIB
126                         int10_setmode(3);
127 #else
128                         VGAmodeX(0, &gvar);
129 #endif
130                         // user imput switch
131                         fprintf(stderr, "xx=%d  yy=%d   tile=%d\n", bakapee.xx, bakapee.yy, bakapee.tile);
132                         printf("Enter 1, 2, 3, 4, or 6 to run a screensaver, or enter 0 to quit.\n", getch());  // prompt the user
133                         //scanf("%d", &key);
134                         if(scanf("%d", &key) != 1)
135                         {
136                                 printf("%d\n", key);
137                         }
138                         getch();
139                         //if(key==3){xx=yy=0;} // crazy screen saver wwww
140                         switch (key)
141                         {
142                                 case 0:
143                                         d=0;
144                                 break;
145                                 case 65536:
146                                         switch (bakapee.tile)
147                                         {
148                                                 case 0:
149                                                         bakapee.tile=1;
150                                                 break;
151                                                 case 1:
152                                                         bakapee.tile=0;
153                                                 break;
154                                         }
155                                         d=2;
156                                 default:
157 #ifdef MXLIB
158                                         gvar.video.page[0] = modexDefaultPage(&gvar.video.page[0]);
159                                         gvar.video.page[0].width += (TILEWH*2);
160                                         gvar.video.page[0].height += (TILEWH*2);
161                                         VGAmodeX(1, &gvar);
162 #else
163                                                 probe_dos();
164         if (!probe_vga()) {
165                 printf("VGA probe failed\n");
166                 return 1;
167         }
168         int10_setmode(19);
169         update_state_from_vga();
170         vga_enable_256color_modex(); // VGA mode X
171         vga_state.vga_width = 320; // VGA lib currently does not update this
172         vga_state.vga_height = 240; // VGA lib currently does not update this
173
174 //#if 1 // 320x240 test mode: this is how Project 16 is using our code, enable for test case
175         {
176                 struct vga_mode_params cm;
177
178                 vga_read_crtc_mode(&cm);
179
180                 // 320x240 mode 60Hz
181                 cm.vertical_total = 525;
182                 cm.vertical_start_retrace = 0x1EA;
183                 cm.vertical_end_retrace = 0x1EC;
184                 cm.vertical_display_end = 480;
185                 cm.vertical_blank_start = 489;
186                 cm.vertical_blank_end = 517;
187
188                 vga_write_crtc_mode(&cm,0);
189         }
190         vga_state.vga_height = 240; // VGA lib currently does not update this
191 //#endif
192 #endif
193                                         modexShowPage(&gvar.video.page[0]);
194                                 break;
195                         }
196                 }
197         }
198 #else
199         while(1)
200         { // conditions of screen saver
201                 while(!kbhit())
202                 {
203                         ding(&gvar.video.page[0], &bakapee, key);
204                 }
205                 //end of screen savers
206                 /*for(int x = 0; x < gvar.video.page[0].width; ++x)
207                 {
208                         modexputPixel(&page, x, 0, 15);
209                         mxPutPixel(x, gvar.video.page[0].height-1, 15);
210                         }
211                 for (int y = 0; y < VH; ++y)
212                         {
213                                 mxPutPixel(0, y, 15);
214                                 mxPutPixel(gvar.video.page[0].width-1, y, 15);
215                         }
216                 for (int x = 0; x < VW; ++x)
217                         {
218                                 mxPutPixel(x, 0, 15);
219                                 mxPutPixel(x, VH-1, 15);
220                         }
221                 for (int y = 240; y < VH; ++y)
222                         {
223                                 mxPutPixel(0, y, 15);
224                                 mxPutPixel(VW-1, y, 15);
225                         }*/
226                 pdump(&gvar.video.page[0]);
227                 getch();
228                 //text box
229                 /*++++mxBitBlt(xpos, ypos+(TILEWH*12), gvar.video.page[0].width, TILEWH*BUFFMX, 0, BS); //copy background
230                 mxFillBox(xpos, ypos+(TILEWH*12), gvar.video.page[0].width, TILEWH*BUFFMX, 0, OP_SET); // background for text box
231                 //+(QUADWH*6)
232                 mxOutText(xpos+1, ypos+gvar.video.page[0].height-48, "========================================");
233                 mxOutText(xpos+1, ypos+gvar.video.page[0].height-40, "|    |Chikyuu:$line1");
234                 mxOutText(xpos+1, ypos+gvar.video.page[0].height-32, "|    |$line2");
235                 mxOutText(xpos+1, ypos+gvar.video.page[0].height-24, "|    |$line3");
236                 mxOutText(xpos+1, ypos+gvar.video.page[0].height-16, "|    |$line4");
237                 mxOutText(xpos+1, ypos+gvar.video.page[0].height-8,  "========================================");
238                 mxFillBox(xpos+QUADWH, ypos+QUADWH+(TILEWH*12), TILEWH*2, TILEWH*2, 9, OP_SET); //portriat~
239                 getch();
240                 mxBitBlt(0, BS, gvar.video.page[0].width, TILEWH*BUFFMX, xpos, ypos+(TILEWH*12)); //copy background
241                 getch();++++*/
242                 while(!kbhit())
243                 {
244                         //for(int i=0;i<TILEWH;i++){
245                                 ding(&gvar.video.page[0], &bakapee, key);
246                                 modexPanPage(&gvar.video.page[0], xpos, ypos);
247 //++++mxFillBox(384, 304, 384, 304, 10, OP_SET);
248 //mxBitBlt(xpos, ypos, gvar.video.page[0].width, gvar.video.page[0].height, 32, (gvar.video.page[0].height+64+32));
249 //++++mxBitBlt(TILEWH*2, TILEWH*2, gvar.video.page[0].width, gvar.video.page[0].height, 32, (gvar.video.page[0].height+64+32));
250                                 //for(word o = 0; o<TILEWH; o++){
251                                         xpos+=xdir;
252                                         ypos+=ydir;
253                                         //if(ypos==1 || (ypos==(BH-gvar.video.page[0].height-1)))delay(500);
254                                         //if((xpos>(VW-gvar.video.page[0].width-1)) || (xpos<1))delay(500);
255                                         //mxWaitRetrace();
256 //mxBitBlt(32, (gvar.video.page[0].height+32), gvar.video.page[0].width, gvar.video.page[0].height, xpos, ypos);
257 //++++mxBitBlt(TILEWH*2, (gvar.video.page[0].height+64+32), gvar.video.page[0].width, gvar.video.page[0].height, TILEWH*2, TILEWH*2);
258 //xpos=ypos=TILEWH*2;
259                                         //????modexPanPage(&gvar.video.page[0], 32, 32);
260                                 //}
261                                 if( (xpos>(VW-gvar.video.page[0].width-1))  || (xpos<1)){xdir=-xdir;}
262                                 if( (ypos>(BH-gvar.video.page[0].height-1)) || (ypos<1)){ydir=-ydir;} // { Hit a boundry, change
263                         //}//    direction!
264 //mxBitBlt(32, (gvar.video.page[0].height+64+32), gvar.video.page[0].width, gvar.video.page[0].height, xpos, ypos);
265 //mxBitBlt(TILEWH*2, (gvar.video.page[0].height+64+32), gvar.video.page[0].width, gvar.video.page[0].height, TILEWH*2, TILEWH*2);
266                 }
267         ch=getch();
268         if(ch==0x71)break; // 'q'
269         if(ch==0x1b)break; // 'ESC'
270         }
271 //      VGAmodeX(0, &gvar);
272 #endif
273         printf("bakapi ver. 1.04.13.04\nis made by sparky4\81i\81\86\83Ö\81\85\81j feel free to use it ^^\nLicence: GPL v3\n");
274 }
275 //pee!