]> 4ch.mooo.com Git - 16.git/blob - src/bakapi.c
wwww
[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 sword vgamodex_mode = 1; // 320x240 default
32 int ch=0x0;
33
34 void
35 main(int argc, char *argvar[])
36 {
37         char *a;
38         int i;
39
40         // allow changing default mode from command line
41         for (i=1;i < argc;) {
42                 a = argvar[i++];
43
44                 if (*a == '-') {
45                         do { a++; } while (*a == '-');
46
47                         if (!strcmp(a,"mx")) {
48                                 // (based on src/lib/modex16.c)
49                                 // 1 = 320x240
50                                 // 2 = 160x120
51                                 // 3 = 320x200
52                                 // 4 = 192x144
53                                 // 5 = 256x192
54                                 vgamodex_mode = (sword)strtoul(argvar[i++],NULL,0);
55                         }
56                         else {
57                                 fprintf(stderr,"Unknown switch %s\n",a);
58                                 return;
59                         }
60                 }
61                 else {
62                         fprintf(stderr,"Unknown command arg %s\n",a);
63                         return;
64                 }
65         }
66
67         // DOSLIB: check our environment
68         probe_dos();
69
70         // DOSLIB: what CPU are we using?
71         // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.
72         //      So this code by itself shouldn't care too much what CPU it's running on. Except that other
73         //      parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for
74         //      the CPU to carry out tasks. --J.C.
75         cpu_probe();
76
77         // DOSLIB: check for VGA
78         if (!probe_vga()) {
79                 printf("VGA probe failed\n");
80                 return;
81         }
82         // hardware must be VGA or higher!
83         if (!(vga_state.vga_flags & VGA_IS_VGA)) {
84                 printf("This program requires VGA or higher graphics hardware\n");
85                 return;
86         }
87
88         // main variables values
89         d=4; // switch variable
90         key=2; // default screensaver number
91         xpos=TILEWH*2;
92         ypos=TILEWH*2;
93         xdir=1;
94         ydir=1;
95
96         VGAmodeX(vgamodex_mode, 1, &gvar); // TODO: Suggestion: Instead of magic numbers for the first param, might I suggest defining an enum or some #define constants that are easier to remember? --J.C.
97                 // this code is written around modex16 which so far is a better fit than using DOSLIB vga directly, so leave MXLIB code in.
98                 // we'll integrate DOSLIB vga into that part of the code instead for less disruption. -- J.C.
99
100         bakapee.xx = rand()&0%gvar.video.page[0].width;
101         bakapee.yy = rand()&0%gvar.video.page[0].height;
102         bakapee.gq = 0;
103         bakapee.sx=0;
104         bakapee.sy=0;
105         bakapee.bakax=0;
106         bakapee.bakay=0;
107         bakapee.coor=0;
108         bakapee.tile=0;
109
110         /* setup camera and screen~ */
111         gvar.video.page[0] = modexDefaultPage(&gvar.video.page[0]);
112         gvar.video.page[0].width += (TILEWH*2);
113         gvar.video.page[0].height += (TILEWH*2);
114         textInit();
115
116         //modexPalUpdate(bmp.palette); //____
117         //modexDrawBmp(VGA, 0, 0, &bmp, 0); //____
118         //getch(); //____
119
120         modexShowPage(&gvar.video.page[0]);
121
122 // screen savers
123 #ifdef BOINK
124         while(d>0)      // on!
125         {
126                 /* run screensaver routine until keyboard input */
127                 while (key > 0) {
128                         if (kbhit()) {
129                                 getch(); // eat keyboard input
130                                 break;
131                         }
132
133                         ding(&gvar.video.page[0], &bakapee, key);
134                 }
135
136                 {
137                         int c;
138
139                 // this code is written around modex16 which so far is a better fit than using DOSLIB vga directly, so leave MXLIB code in.
140                 // we'll integrate DOSLIB vga into that part of the code instead for less disruption. -- J.C.
141                         VGAmodeX(0, 0, &gvar);
142                         // user imput switch
143                         //fprintf(stderr, "xx=%d        yy=%d   tile=%d\n", bakapee.xx, bakapee.yy, bakapee.tile);
144                         printf("Tiled mode is ");
145                         switch (bakapee.tile)
146                         {
147                                 case 0:
148                                         printf("off.\n");
149                                 break;
150                                 case 1:
151                                         printf("on.\n");
152                                 break;
153                         }
154                         printf("Enter 1, 2, 3, 4, 5, 6, 8, or 9 to run a screensaver, or enter 0 to quit.\n");
155
156                         c = getch();
157                         switch (c) {
158                                 case 27: /* Escape key */
159                                 case '0':
160                                         d=0;
161                                         break;
162                                 case 'b': // test tile change
163                                         switch (bakapee.tile)
164                                         {
165                                                 case 0:
166                                                         bakapee.tile=1;
167                                                 break;
168                                                 case 1:
169                                                         bakapee.tile=0;
170                                                 break;
171                                         }
172                                         key=0;
173                                         break;
174                                 case '8':
175                                         c+=8;
176                                 case '1':
177                                 case '2':
178                                 case '3':
179                                 case '4':
180                                 case '5':
181                                 case '6':
182                                 case '9':
183                                         key = c - '0';
184                                         gvar.video.page[0] = modexDefaultPage(&gvar.video.page[0]);
185                                         gvar.video.page[0].width += (TILEWH*2);
186                                         gvar.video.page[0].height += (TILEWH*2);
187                                         VGAmodeX(vgamodex_mode, 0, &gvar);
188                 // this code is written around modex16 which so far is a better fit than using DOSLIB vga directly, so leave MXLIB code in.
189                 // we'll integrate DOSLIB vga into that part of the code instead for less disruption. -- J.C.
190                                         modexShowPage(&gvar.video.page[0]);
191                                         break;
192                                 default:
193                                         key=0;
194                                         break;
195                         }
196                 }
197         }
198 #else // !defined(BOINK)
199 word panq=1, pand=0;
200 boolean panswitch=0;
201 // FIXME: Does not compile. Do you want to remove this?
202 // TODO: This is a testing sextion for textrendering and panning for project 16 --sparky4
203         while(1)
204         { // conditions of screen saver
205 //              while(!kbhit())
206 //              {
207 //                      ding(&gvar.video.page[0], &bakapee, key);
208 //              }
209                 //end of screen savers
210                 //pdump(&gvar.video.page[0]);
211
212 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-48, "========================================");
213 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-40, "|    |Chikyuu:$line1");
214 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-32, "|    |$line2");
215 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-24, "|    |$line3");
216 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-16, "|    |$line4");
217 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-8,  "========================================");
218
219         ding(&gvar.video.page[0], &bakapee, key);
220         modexPanPage(&gvar.video.page[0], xpos, ypos);
221                 //right movement
222         if((IN_KeyDown(77) && !IN_KeyDown(75) && pand == 0) || pand == 2)
223         {
224                 if(pand == 0){ pand = 2; }
225                         if(panq<=(TILEWH/(4)))
226                         {
227                                 switch(panpagenum)
228                                 {
229                                         case 0:
230                                                 //bg
231                                                 bg->page->dx++;
232                                                 modexShowPage(bg->page);
233                                         break;
234                                         case 1:
235                                                 //spri
236                                                 spri->page->dx++;
237                                                 modexShowPage(spri->page);
238                                         break;
239                                         case 2:
240                                                 //fg
241                                                 mask->page->dx++;
242                                                 modexShowPage(mask->page);
243                                         break;
244                                 }
245                                 panq++;
246                         } else { panq = 1; pand = 0; }
247         }
248         //left movement
249         if((IN_KeyDown(75) && !IN_KeyDown(77) && pand == 0) || pand == 4)
250         {
251                 if(pand == 0){ pand = 4; }
252                         if(panq<=(TILEWH/(4)))
253                         {
254                                 switch(panpagenum)
255                                 {
256                                         case 0:
257                                                 //bg
258                                                 bg->page->dx--;
259                                                 modexShowPage(bg->page);
260                                         break;
261                                         case 1:
262                                                 //spri
263                                                 spri->page->dx--;
264                                                 modexShowPage(spri->page);
265                                         break;
266                                         case 2:
267                                                 //fg
268                                                 mask->page->dx--;
269                                                 modexShowPage(mask->page);
270                                         break;
271                                 }
272                                 panq++;
273                         } else { panq = 1; pand = 0; }
274         }
275         //down movement
276         if((IN_KeyDown(72) && !IN_KeyDown(80) && pand == 0) || pand == 3)
277         {
278                 if(pand == 0){ pand = 3; }
279                         if(panq<=(TILEWH/(4)))
280                         {
281                                 switch(panpagenum)
282                                 {
283                                         case 0:
284                                                 //bg
285                                                 bg->page->dy--;
286                                                 modexShowPage(bg->page);
287                                         break;
288                                         case 1:
289                                                 //spri
290                                                 spri->page->dy--;
291                                                 modexShowPage(spri->page);
292                                         break;
293                                         case 2:
294                                                 //fg
295                                                 mask->page->dy--;
296                                                 modexShowPage(mask->page);
297                                         break;
298                                 }
299                                 panq++;
300                         } else { panq = 1; pand = 0; }
301         }
302         //up movement
303         if((IN_KeyDown(80) && !IN_KeyDown(72) && pand == 0) || pand == 1)
304         {
305                 if(pand == 0){ pand = 1; }
306                         if(panq<=(TILEWH/(4)))
307                         {
308                                 switch(panpagenum)
309                                 {
310                                         case 0:
311                                                 //bg
312                                                 bg->page->dy++;
313                                                 modexShowPage(bg->page);
314                                         break;
315                                         case 1:
316                                                 //spri
317                                                 spri->page->dy++;
318                                                 modexShowPage(spri->page);
319                                         break;
320                                         case 2:
321                                                 //fg
322                                                 mask->page->dy++;
323                                                 modexShowPage(mask->page);
324                                         break;
325                                 }
326                                 panq++;
327                         } else { panq = 1; pand = 0; }
328         }
329 //      xpos+=xdir;
330 //      ypos+=ydir;
331 //      if( (xpos>(VW-gvar.video.page[0].width-1))  || (xpos<1)){xdir=-xdir;}
332 //      if( (ypos>(BH-gvar.video.page[0].height-1)) || (ypos<1)){ydir=-ydir;}
333         ch=getch();
334         if(ch==0x71)break; // 'q'
335         if(ch==0x1b)break; // 'ESC'
336         }
337         VGAmodeX(0, 1, &gvar);
338 #endif // defined(BOINK)
339         printf("bakapi ver. 1.04.16.04\nis made by sparky4\81i\81\86\83Ö\81\85\81j feel free to use it ^^\nLicence: GPL v3\n");
340         printf("compiled on 2016/04/04\n");
341 }
342 //pee!