]> 4ch.mooo.com Git - 16.git/blob - src/bakapi.c
intro screen stuff added from wolf 3d. i am far too busy to code again. there is...
[16.git] / src / bakapi.c
1 /* Project 16 Source Code~\r
2  * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
3  *\r
4  * This file is part of Project 16.\r
5  *\r
6  * Project 16 is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * Project 16 is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You screen.heightould have received a copy of the GNU General Public License\r
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
19  * Fifth Floor, Boston, MA 02110-1301 USA.\r
20  *\r
21  */\r
22 \r
23 #include "src/bakapi.h"\r
24 \r
25 /*\r
26  * BAKAPEE!\r
27  */\r
28 static bakapee_t bakapee;\r
29 word key,d,xpos,ypos,xdir,ydir;\r
30 sword vgamodex_mode = 1; //     1 = 320x240 with buffer\r
31 void TL_VidInit(global_game_variables_t *gvar){}\r
32 //int ch=0x0;\r
33 \r
34 \r
35 void\r
36 main(int argc, char *argvar[])\r
37 {\r
38         static global_game_variables_t gvar;\r
39         struct glob_game_vars   *ggvv;\r
40         char *a;\r
41         int i,c;\r
42         word panq=1, pand=0,showding=0;\r
43         boolean panswitch=0,bptest=1,runding=1;\r
44 \r
45         ggvv=&gvar;\r
46 \r
47         // allow changing default mode from command line\r
48         for (i=1;i < argc;) {\r
49                 a = argvar[i++];\r
50 \r
51                 if (*a == '-') {\r
52                         do { a++; } while (*a == '-');\r
53 \r
54                         if (!strcmp(a,"mx")) {\r
55                                 // (based on src/lib/modex16.c)\r
56                                 // 1 = 320x240\r
57                                 // 2 = 160x120\r
58                                 // 3 = 320x200\r
59                                 // 4 = 192x144\r
60                                 // 5 = 256x192\r
61                                 vgamodex_mode = (sword)strtoul(argvar[i++],NULL,0);\r
62                         }\r
63                         else {\r
64                                 fprintf(stderr,"Unknown switch %s\n",a);\r
65                                 return;\r
66                         }\r
67                 }\r
68                 else {\r
69                         fprintf(stderr,"Unknown command arg %s\n",a);\r
70                         return;\r
71                 }\r
72         }\r
73 \r
74         // initiate doslib //\r
75         TL_DosLibStartup(&gvar);\r
76 \r
77         // main variables values\r
78         d=4; // switch variable\r
79         key=2; // default screensaver number\r
80         xpos=TILEWHD; ypos=TILEWHD; xdir=1; ydir=1;\r
81 \r
82         VGAmodeX(vgamodex_mode, 0, &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.\r
83                 // this code is written around modex16 which so far is a better fit than using DOSLIB vga directly, so leave MXLIB code in.\r
84                 // we'll integrate DOSLIB vga into that part of the code instead for less disruption. -- J.C.\r
85         bakapee.xx = rand()&0%gvar.video.page[0].width; bakapee.yy = rand()&0%gvar.video.page[0].height;\r
86         bakapee.gq = 0; bakapee.sx=bakapee.sy=0; bakapee.bakax=bakapee.bakay=0; bakapee.coor=0;\r
87         //once where #defines\r
88         bakapee.tile=0; bakapee.bonk=400; bakapee.lgq=32; bakapee.hgq=55;\r
89 \r
90         switch(WCPU_detectcpu())\r
91         {\r
92                 case 0:\r
93                         bakapee.tile=1;\r
94                 break;\r
95                 default:\r
96                         bakapee.tile=0;\r
97                 break;\r
98         }\r
99 \r
100         // setup camera and screen~ //\r
101         SETUPPAGEBAKAPI\r
102 \r
103         VL_ShowPage(&gvar.video.page[0], 1, 0);\r
104         BAKAPIINITFIZZTEST\r
105 \r
106         while (bptest)\r
107         {\r
108 /*              if (key > 0)\r
109                 {*/\r
110                 while (!kbhit() && runding)\r
111                         {\r
112                                 //{ word w; for(w=0;w<(gvar.video.page[0].width*gvar.video.page[0].height);w++) {}}\r
113                                 ding(&gvar.video.page[showding], &bakapee, 4);\r
114                         }\r
115                 if (kbhit())\r
116 //                      {\r
117                         getch(); // eat keyboard input\r
118 //                              break;\r
119 //                      }\r
120 //              }*/\r
121 \r
122                 {\r
123 \r
124                         c = getch();\r
125                         switch (c)\r
126                         {\r
127                                 case 27: // Escape key //\r
128                                 case '0':\r
129                                 default:\r
130                                         bptest = false;\r
131                                 break;\r
132                                 case 'b': // test tile change //\r
133                                         switch (bakapee.tile)\r
134                                         {\r
135                                                 case 0:\r
136                                                         bakapee.tile=1;\r
137                                                 break;\r
138                                                 case 1:\r
139                                                         bakapee.tile=0;\r
140                                                 break;\r
141                                         }\r
142                                 break;\r
143                                 case 'r':\r
144                                         runding = false;\r
145                                         BAKAPIINITFIZZTEST\r
146                                 break;\r
147                                 case 'e':\r
148                                         runding = 1;\r
149                                 break;\r
150                                 case 'z':\r
151                                         runding = false;\r
152                                         FIZZFADEFUN\r
153 //                                      runding = true;\r
154                                 break;\r
155                                 case '3':\r
156                                 case '4':\r
157                                         runding = 1;\r
158                                         showding = c - '0' - 3;\r
159                                 break;\r
160                                 case '1':\r
161                                 case '2':\r
162         //                      case '5':\r
163         //                      case '6':\r
164         //                      case '9':\r
165                                         key = c - '0' - 1;\r
166                                         VL_ShowPage(&gvar.video.page[key], 1, 0);\r
167                                 break;\r
168                         }\r
169                 }\r
170         }\r
171 \r
172 \r
173 //while(!kbhit()){}\r
174 \r
175 // screen savers\r
176 //#ifdef BOINK\r
177         while(d>0)      // on!\r
178         {\r
179                 /* run screensaver routine until keyboard input */\r
180                 while (key > 0) {\r
181                         if (kbhit()) {\r
182                                 if(!panswitch)\r
183                                 {\r
184                                         getch(); // eat keyboard input\r
185                                         break;\r
186                                 }else c=getch();\r
187                         }\r
188 \r
189                         if(!panswitch){\r
190                                 if(key==9)\r
191                                 {\r
192                                         ding(&gvar.video.page[1], &bakapee, 4);\r
193                                         ding(&gvar.video.page[0], &bakapee, 4);\r
194                                         FIZZFADEFUN\r
195                                 }else ding(&gvar.video.page[0], &bakapee, key); }\r
196                         else                    ding(&gvar.video.page[0], &bakapee, 2);\r
197                         if(panswitch!=0)\r
198                         {\r
199                                 //right movement\r
200                                 if((c==0x4d && pand == 0) || pand == 2)\r
201                                 {\r
202                                         if(pand == 0){ pand = 2; }\r
203                                         if(panq<=(TILEWH/(4)))\r
204                                         {\r
205                                                 gvar.video.page[0].dx++;\r
206                                                 VL_ShowPage(&gvar.video.page[0], 0, 0);\r
207                                                 panq++;\r
208                                         } else { panq = 1; pand = 0; }\r
209                                 }\r
210                                 //left movement\r
211                                 if((c==0x4b && pand == 0) || pand == 4)\r
212                                 {\r
213                                         if(pand == 0){ pand = 4; }\r
214                                         if(panq<=(TILEWH/(4)))\r
215                                         {\r
216                                                 gvar.video.page[0].dx--;\r
217                                                 VL_ShowPage(&gvar.video.page[0], 0, 0);\r
218                                                 panq++;\r
219                                         } else { panq = 1; pand = 0; }\r
220                                 }\r
221                                 //down movement\r
222                                 if((c==0x50 && pand == 0) || pand == 3)\r
223                                 {\r
224                                         if(pand == 0){ pand = 3; }\r
225                                         if(panq<=(TILEWH/(4)))\r
226                                         {\r
227                                                 gvar.video.page[0].dy++;\r
228                                                 VL_ShowPage(&gvar.video.page[0], 0, 0);\r
229                                                 panq++;\r
230                                         } else { panq = 1; pand = 0; }\r
231                                 }\r
232                                 //up movement\r
233                                 if((c==0x48 && pand == 0) || pand == 1)\r
234                                 {\r
235                                         if(pand == 0){ pand = 1; }\r
236                                         if(panq<=(TILEWH/(4)))\r
237                                         {\r
238                                                 gvar.video.page[0].dy--;\r
239                                                 VL_ShowPage(&gvar.video.page[0], 0, 0);\r
240                                                 panq++;\r
241                                         } else { panq = 1; pand = 0; }\r
242                                 }\r
243                                 if((c==0x4d && pand == 0) || pand == 2)\r
244                                 {\r
245                                         if(pand == 0){ pand = 2; }\r
246                                         if(panq<=(TILEWH/(4)))\r
247                                         {\r
248                                                 gvar.video.page[0].dx++;\r
249                                                 VL_ShowPage(&gvar.video.page[0], 0, 0);\r
250                                                 panq++;\r
251                                         } else { panq = 1; pand = 0; }\r
252                                 }\r
253                                 if(c==0x01+1)\r
254                                 {\r
255                                         VL_ShowPage(&gvar.video.page[0], 0, 0);\r
256                                 }\r
257                                 if(c==0x02+1)\r
258                                 {\r
259                                         VL_ShowPage(&gvar.video.page[1], 0, 0);\r
260                                 }\r
261                                 if(c==0x71 || c==0xb1 || c=='p')\r
262                                 {\r
263                                         //getch(); // eat keyboard input\r
264                                         panswitch=0;\r
265                                         break; // 'q' or 'ESC' or 'p'\r
266                                 }\r
267                         }\r
268                 }\r
269 \r
270                 {\r
271 \r
272                 // this code is written around modex16 which so far is a better fit than using DOSLIB vga directly, so leave MXLIB code in.\r
273                 // we'll integrate DOSLIB vga into that part of the code instead for less disruption. -- J.C.\r
274                         VGAmodeX(0, 0, &gvar);\r
275                         clrscr();       //added to clear screen wwww\r
276                         // user imput switch\r
277                         //fprintf(stderr, "xx=%d        yy=%d   tile=%d\n", bakapee.xx, bakapee.yy, bakapee.tile);\r
278                         //fprintf(stderr, "dx=%d        dy=%d   ", gvar.video.page[0].dx, gvar.video.page[0].dy);\r
279                         printf("Tiled mode is ");\r
280                         switch (bakapee.tile)\r
281                         {\r
282                                 case 0:\r
283                                         printf("off.    ");\r
284                                 break;\r
285                                 case 1:\r
286                                         printf("on.     ");\r
287                                 break;\r
288                         }\r
289                         printf("Pan mode is ");\r
290                         switch (panswitch)\r
291                         {\r
292                                 case 0:\r
293                                         printf("off.");\r
294                                 break;\r
295                                 case 1:\r
296                                         printf("on.");\r
297                                 break;\r
298                         }\r
299                         printf("\n");\r
300                         printf("Incrementation of color happens at every %uth plot.\n", bakapee.bonk);\r
301                         printf("Enter 1, 2, 3, 4, 5, 6, 8, or 9 to run a screensaver, or enter 0 to quit.\n");\r
302 pee:\r
303                         c = getch();\r
304                         switch (c) {\r
305                                 case 27: /* Escape key */\r
306                                 case '0':\r
307                                         d=0;\r
308                                         break;\r
309                                 case 'p': // test pan\r
310                                         switch (panswitch)\r
311                                         {\r
312                                                 case 0:\r
313                                                         panswitch=1;\r
314                                                 break;\r
315                                                 case 1:\r
316                                                         panswitch=0;\r
317                                                 break;\r
318                                         }\r
319                                         key=0;\r
320                                         goto pee;\r
321                                 break;\r
322                                 case 'b': // test tile change\r
323                                         switch (bakapee.tile)\r
324                                         {\r
325                                                 case 0:\r
326                                                         bakapee.tile=1;\r
327                                                 break;\r
328                                                 case 1:\r
329                                                         bakapee.tile=0;\r
330                                                 break;\r
331                                         }\r
332                                         key=0;\r
333                                 break;\r
334                                 case '8':\r
335                                         c+=8;\r
336                                 case '1':\r
337                                 case '2':\r
338                                 case '3':\r
339                                 case '4':\r
340                                 case '5':\r
341                                 case '6':\r
342                                 case '9':\r
343                                         key = c - '0';\r
344                                         VGAmodeX(vgamodex_mode, 0, &gvar);\r
345                                         SETUPPAGEBAKAPI\r
346                 // this code is written around modex16 which so far is a better fit than using DOSLIB vga directly, so leave MXLIB code in.\r
347                 // we'll integrate DOSLIB vga into that part of the code instead for less disruption. -- J.C.\r
348                                         VL_ShowPage(&gvar.video.page[0], 0, 0);\r
349                                 break;\r
350                                 case '-':\r
351                                         if(bakapee.bonk>0)\r
352                                                 bakapee.bonk-=100;\r
353                                 break;\r
354                                 case '=':\r
355                                 case '+':\r
356                                         if(bakapee.bonk<1000)\r
357                                                 bakapee.bonk+=100;\r
358                                 break;\r
359                                 default:\r
360                                         key=0;\r
361                                 break;\r
362                         }\r
363                 }\r
364         }\r
365         clrscr();       //added to clear screen wwww\r
366 #if 0\r
367 //#else // !defined(BOINK)\r
368 // FIXME: Does not compile. Do you want to remove this?\r
369 // INFO: This is a testing section for textrendering and panning for project 16 --sparky4\r
370         while(1)\r
371         { // conditions of screen saver\r
372 //              while(!kbhit())\r
373 //              {\r
374 //                      ding(&gvar.video.page[0], &bakapee, key);\r
375 //              }\r
376                 //end of screen savers\r
377                 //pdump(&gvar.video.page[0]);\r
378 \r
379 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-48, "========================================");\r
380 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-40, "|    |Chikyuu:$line1");\r
381 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-32, "|    |$line2");\r
382 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-24, "|    |$line3");\r
383 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-16, "|    |$line4");\r
384 //              mxOutText(xpos+1, ypos+gvar.video.page[0].height-8,  "========================================");\r
385 \r
386         ding(&gvar.video.page[0], &bakapee, key);\r
387         modexPanPage(&gvar.video.page[0], xpos, ypos);\r
388         c = getch();\r
389 \r
390 //      xpos+=xdir;\r
391 //      ypos+=ydir;\r
392 //      if( (xpos>(gvar.video.page[0].sw-gvar.video.page[0].width-1))  || (xpos<1)){xdir=-xdir;}\r
393 //      if( (ypos>(gvar.video.page[0].sh-gvar.video.page[0].height-1)) || (ypos<1)){ydir=-ydir;}\r
394 //      ch=getch();\r
395         if(ch==0x71)break; // 'q'\r
396         if(ch==0x1b)break; // 'ESC'\r
397         }\r
398         VGAmodeX(0, 1, &gvar);\r
399 #endif // defined(BOINK)\r
400 //      printf("page.width=%u   ", gvar.video.page[0].width); printf("page.height=%u\n", gvar.video.page[0].height);\r
401         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");\r
402         printf("compiled on 2016/04/04\n");\r
403 //      printf("[%u]%dx%d       [%dx%d] %u %u %u\n[%u   %u      %u]", key, bakapee.bakax, bakapee.bakay, bakapee.xx, bakapee.yy,\r
404 //bakapee.coor, bakapee.tile, bakapee.gq, bakapee.bonk, bakapee.lgq, bakapee.hgq);\r
405 }\r
406 //pee!\r