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