OSDN Git Service

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