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=TILEWHD;
94         ypos=TILEWHD;
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         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                 int c;
127                 /* run screensaver routine until keyboard input */
128                 while (key > 0) {
129                         if (kbhit()) {
130                                 if(!panswitch)
131                                 {
132                                         getch(); // eat keyboard input
133                                         break;
134                                 }else c=getch();
135                         }
136
137                         if(!panswitch)  ding(&gvar.video.page[0], &bakapee, key);
138                         else                    ding(&gvar.video.page[0], &bakapee, 2);
139                         if(panswitch!=0)
140                         {
141                                 //right movement
142                                 if((c==0x4d && pand == 0) || pand == 2)
143                                 {
144                                         if(pand == 0){ pand = 2; }
145                                         if(panq<=(TILEWH/(4)))
146                                         {
147                                                 gvar.video.page[0].dx++;
148                                                 modexShowPage(&gvar.video.page[0]);
149                                                 panq++;
150                                         } else { panq = 1; pand = 0; }
151                                 }
152                                 //left movement
153                                 if((c==0x4b && pand == 0) || pand == 4)
154                                 {
155                                         if(pand == 0){ pand = 4; }
156                                         if(panq<=(TILEWH/(4)))
157                                         {
158                                                 gvar.video.page[0].dx--;
159                                                 modexShowPage(&gvar.video.page[0]);
160                                                 panq++;
161                                         } else { panq = 1; pand = 0; }
162                                 }
163                                 //down movement
164                                 if((c==0x50 && pand == 0) || pand == 3)
165                                 {
166                                         if(pand == 0){ pand = 3; }
167                                         if(panq<=(TILEWH/(4)))
168                                         {
169                                                 gvar.video.page[0].dy++;
170                                                 modexShowPage(&gvar.video.page[0]);
171                                                 panq++;
172                                         } else { panq = 1; pand = 0; }
173                                 }
174                                 //up movement
175                                 if((c==0x48 && pand == 0) || pand == 1)
176                                 {
177                                         if(pand == 0){ pand = 1; }
178                                         if(panq<=(TILEWH/(4)))
179                                         {
180                                                 gvar.video.page[0].dy--;
181                                                 modexShowPage(&gvar.video.page[0]);
182                                                 panq++;
183                                         } else { panq = 1; pand = 0; }
184                                 }
185                                 if(c==0x71 || c==0xb1 || c=='p')
186                                 {
187                                         //getch(); // eat keyboard input
188                                         panswitch=0;
189                                         break; // 'q' or 'ESC' or 'p'
190                                 }
191                         }
192                 }
193
194                 {
195
196                 // this code is written around modex16 which so far is a better fit than using DOSLIB vga directly, so leave MXLIB code in.
197                 // we'll integrate DOSLIB vga into that part of the code instead for less disruption. -- J.C.
198                         VGAmodeX(0, 0, &gvar);
199                         // user imput switch
200                         //fprintf(stderr, "xx=%d        yy=%d   tile=%d\n", bakapee.xx, bakapee.yy, bakapee.tile);
201                         //fprintf(stderr, "dx=%d        dy=%d   ", gvar.video.page[0].dx, gvar.video.page[0].dy);
202                         printf("Tiled mode is ");
203                         switch (bakapee.tile)
204                         {
205                                 case 0:
206                                         printf("off.    ");
207                                 break;
208                                 case 1:
209                                         printf("on.     ");
210                                 break;
211                         }
212                         //printf("\n");
213                         printf("Pan mode is ");
214                         switch (panswitch)
215                         {
216                                 case 0:
217                                         printf("off.\n");
218                                 break;
219                                 case 1:
220                                         printf("on.\n");
221                                 break;
222                         }
223                         printf("Enter 1, 2, 3, 4, 5, 6, 8, or 9 to run a screensaver, or enter 0 to quit.\n");
224 pee:
225                         c = getch();
226                         switch (c) {
227                                 case 27: /* Escape key */
228                                 case '0':
229                                         d=0;
230                                         break;
231                                 case 'p': // test pan
232                                 switch (panswitch)
233                                 {
234                                         case 0:
235                                                 panswitch=1;
236                                         break;
237                                         case 1:
238                                                 panswitch=0;
239                                         break;
240                                 }
241                                 goto pee;
242                                 break;
243                                 case 'b': // test tile change
244                                         switch (bakapee.tile)
245                                         {
246                                                 case 0:
247                                                         bakapee.tile=1;
248                                                 break;
249                                                 case 1:
250                                                         bakapee.tile=0;
251                                                 break;
252                                         }
253                                         key=0;
254                                         break;
255                                 case '8':
256                                         c+=8;
257                                 case '1':
258                                 case '2':
259                                 case '3':
260                                 case '4':
261                                 case '5':
262                                 case '6':
263                                 case '9':
264                                         key = c - '0';
265                                         VGAmodeX(vgamodex_mode, 0, &gvar);
266                                         gvar.video.page[0] = modexDefaultPage(&gvar.video.page[0]);
267                 // this code is written around modex16 which so far is a better fit than using DOSLIB vga directly, so leave MXLIB code in.
268                 // we'll integrate DOSLIB vga into that part of the code instead for less disruption. -- J.C.
269                                         modexShowPage(&gvar.video.page[0]);
270                                         break;
271                                 default:
272                                         key=0;
273                                         break;
274                         }
275                 }
276         }
277 #else // !defined(BOINK)
278 // FIXME: Does not compile. Do you want to remove this?
279 // TODO: This is a testing sextion for textrendering and panning for project 16 --sparky4
280         while(1)
281         { // conditions of screen saver
282 //              while(!kbhit())
283 //              {
284 //                      ding(&gvar.video.page[0], &bakapee, key);
285 //              }
286                 //end of screen savers
287                 //pdump(&gvar.video.page[0]);
288
289 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-48, "========================================");
290 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-40, "|    |Chikyuu:$line1");
291 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-32, "|    |$line2");
292 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-24, "|    |$line3");
293 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-16, "|    |$line4");
294 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-8,  "========================================");
295
296         ding(&gvar.video.page[0], &bakapee, key);
297         modexPanPage(&gvar.video.page[0], xpos, ypos);
298         c = getch();
299
300 //      xpos+=xdir;
301 //      ypos+=ydir;
302 //      if( (xpos>(gvar.video.page[0].sw-gvar.video.page[0].width-1))  || (xpos<1)){xdir=-xdir;}
303 //      if( (ypos>(gvar.video.page[0].sh-gvar.video.page[0].height-1)) || (ypos<1)){ydir=-ydir;}
304 //      ch=getch();
305         if(ch==0x71)break; // 'q'
306         if(ch==0x1b)break; // 'ESC'
307         }
308         VGAmodeX(0, 1, &gvar);
309 #endif // defined(BOINK)
310 //      printf("page.width=%u   ", gvar.video.page[0].width); printf("page.height=%u\n", gvar.video.page[0].height);
311         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");
312         printf("compiled on 2016/04/04\n");
313 }
314 //pee!