]> 4ch.mooo.com Git - 16.git/blob - src/bakapi.c
bakapi modex16 test fun: allow video mode choice from command line.
[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 #ifdef MXLIB
97         VGAmodeX(vgamodex_mode, &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.
98 #else
99 # error REMOVED // 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 #endif
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                 /* run screensaver routine until keyboard input */
129                 while (key > 0) {
130                         if (kbhit()) {
131                                 getch(); // eat keyboard input
132                                 break;
133                         }
134
135                         ding(&gvar.video.page[0], &bakapee, key);
136                 }
137
138                 {
139                         int c;
140
141 # ifndef MXLIB
142 #  error REMOVED // this code is written around modex16 which so far is a better fit than using DOSLIB vga directly, so leave MXLIB code in.
143                 // we'll integrate DOSLIB vga into that part of the code instead for less disruption. -- J.C.
144 # else
145                         VGAmodeX(0, &gvar);
146 # endif
147                         // user imput switch
148                         fprintf(stderr, "xx=%d  yy=%d   tile=%d\n", bakapee.xx, bakapee.yy, bakapee.tile);
149                         printf("Enter 1, 2, 3, 4, or 6 to run a screensaver, or enter 0 to quit.\n");
150
151                         c = getch();
152                         switch (c) {
153                                 case 27: /* Escape key */
154                                 case '0':
155                                         d=0;
156                                         break;
157                                 case 'b': // test tile change
158                                         switch (bakapee.tile)
159                                         {
160                                                 case 0:
161                                                         bakapee.tile=1;
162                                                 break;
163                                                 case 1:
164                                                         bakapee.tile=0;
165                                                 break;
166                                         }
167                                         key=0;
168                                         break;
169                                 case '1':
170                                 case '2':
171                                 case '3':
172                                 case '4':
173                                 case '5':
174                                 case '6':
175                                         key = c - '0';
176 # ifdef MXLIB
177                                         gvar.video.page[0] = modexDefaultPage(&gvar.video.page[0]);
178                                         gvar.video.page[0].width += (TILEWH*2);
179                                         gvar.video.page[0].height += (TILEWH*2);
180                                         VGAmodeX(vgamodex_mode, &gvar);
181 # else
182 #  error REMOVED // this code is written around modex16 which so far is a better fit than using DOSLIB vga directly, so leave MXLIB code in.
183                 // we'll integrate DOSLIB vga into that part of the code instead for less disruption. -- J.C.
184 # endif
185                                         modexShowPage(&gvar.video.page[0]);
186                                         break;
187                                 default:
188                                         key=0;
189                                         break;
190                         }
191                 }
192         }
193 #else // !defined(BOINK)
194 // FIXME: Does not compile. Do you want to remove this?
195         while(1)
196         { // conditions of screen saver
197                 while(!kbhit())
198                 {
199                         ding(&gvar.video.page[0], &bakapee, key);
200                 }
201                 //end of screen savers
202                 /*for(int x = 0; x < gvar.video.page[0].width; ++x)
203                 {
204                         modexputPixel(&page, x, 0, 15);
205                         mxPutPixel(x, gvar.video.page[0].height-1, 15);
206                         }
207                 for (int y = 0; y < VH; ++y)
208                         {
209                                 mxPutPixel(0, y, 15);
210                                 mxPutPixel(gvar.video.page[0].width-1, y, 15);
211                         }
212                 for (int x = 0; x < VW; ++x)
213                         {
214                                 mxPutPixel(x, 0, 15);
215                                 mxPutPixel(x, VH-1, 15);
216                         }
217                 for (int y = 240; y < VH; ++y)
218                         {
219                                 mxPutPixel(0, y, 15);
220                                 mxPutPixel(VW-1, y, 15);
221                         }*/
222                 pdump(&gvar.video.page[0]);
223                 getch();
224                 //text box
225                 /*++++mxBitBlt(xpos, ypos+(TILEWH*12), gvar.video.page[0].width, TILEWH*BUFFMX, 0, BS); //copy background
226                 mxFillBox(xpos, ypos+(TILEWH*12), gvar.video.page[0].width, TILEWH*BUFFMX, 0, OP_SET); // background for text box
227                 //+(QUADWH*6)
228                 mxOutText(xpos+1, ypos+gvar.video.page[0].height-48, "========================================");
229                 mxOutText(xpos+1, ypos+gvar.video.page[0].height-40, "|    |Chikyuu:$line1");
230                 mxOutText(xpos+1, ypos+gvar.video.page[0].height-32, "|    |$line2");
231                 mxOutText(xpos+1, ypos+gvar.video.page[0].height-24, "|    |$line3");
232                 mxOutText(xpos+1, ypos+gvar.video.page[0].height-16, "|    |$line4");
233                 mxOutText(xpos+1, ypos+gvar.video.page[0].height-8,  "========================================");
234                 mxFillBox(xpos+QUADWH, ypos+QUADWH+(TILEWH*12), TILEWH*2, TILEWH*2, 9, OP_SET); //portriat~
235                 getch();
236                 mxBitBlt(0, BS, gvar.video.page[0].width, TILEWH*BUFFMX, xpos, ypos+(TILEWH*12)); //copy background
237                 getch();++++*/
238                 while(!kbhit())
239                 {
240                         //for(int i=0;i<TILEWH;i++){
241                                 ding(&gvar.video.page[0], &bakapee, key);
242                                 modexPanPage(&gvar.video.page[0], xpos, ypos);
243 //++++mxFillBox(384, 304, 384, 304, 10, OP_SET);
244 //mxBitBlt(xpos, ypos, gvar.video.page[0].width, gvar.video.page[0].height, 32, (gvar.video.page[0].height+64+32));
245 //++++mxBitBlt(TILEWH*2, TILEWH*2, gvar.video.page[0].width, gvar.video.page[0].height, 32, (gvar.video.page[0].height+64+32));
246                                 //for(word o = 0; o<TILEWH; o++){
247                                         xpos+=xdir;
248                                         ypos+=ydir;
249                                         //if(ypos==1 || (ypos==(BH-gvar.video.page[0].height-1)))delay(500);
250                                         //if((xpos>(VW-gvar.video.page[0].width-1)) || (xpos<1))delay(500);
251                                         //mxWaitRetrace();
252 //mxBitBlt(32, (gvar.video.page[0].height+32), gvar.video.page[0].width, gvar.video.page[0].height, xpos, ypos);
253 //++++mxBitBlt(TILEWH*2, (gvar.video.page[0].height+64+32), gvar.video.page[0].width, gvar.video.page[0].height, TILEWH*2, TILEWH*2);
254 //xpos=ypos=TILEWH*2;
255                                         //????modexPanPage(&gvar.video.page[0], 32, 32);
256                                 //}
257                                 if( (xpos>(VW-gvar.video.page[0].width-1))  || (xpos<1)){xdir=-xdir;}
258                                 if( (ypos>(BH-gvar.video.page[0].height-1)) || (ypos<1)){ydir=-ydir;} // { Hit a boundry, change
259                         //}//    direction!
260 //mxBitBlt(32, (gvar.video.page[0].height+64+32), gvar.video.page[0].width, gvar.video.page[0].height, xpos, ypos);
261 //mxBitBlt(TILEWH*2, (gvar.video.page[0].height+64+32), gvar.video.page[0].width, gvar.video.page[0].height, TILEWH*2, TILEWH*2);
262                 }
263         ch=getch();
264         if(ch==0x71)break; // 'q'
265         if(ch==0x1b)break; // 'ESC'
266         }
267 //      VGAmodeX(0, &gvar);
268 #endif // defined(BOINK)
269         printf("bakapi ver. 1.04.13.04\nis made by sparky4\81i\81\86\83Ö\81\85\81j feel free to use it ^^\nLicence: GPL v3\n");
270 }
271 //pee!