]> 4ch.mooo.com Git - 16.git/blob - src/xcroll.c
xcroll.exe needs through testing on real hardware./wbuild.sh; wmake www./wbuild.sh...
[16.git] / src / xcroll.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 should 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/lib/scroll16.h"\r
24 #include "src/lib/16_timer.h"\r
25 #include "src/lib/16_dbg.h"\r
26 \r
27 //#define FADE\r
28 //#define NOMAPLOAD\r
29 \r
30 //#define VERBOSESCROLL\r
31 \r
32 static map_t map;\r
33 float t;\r
34 \r
35 //debugswitches\r
36 boolean panswitch=0,baka=0;\r
37 //extern boolean pageflipflop=1;\r
38 extern boolean pagenorendermap; //default: 0\r
39 unsigned int i;\r
40 \r
41 #ifdef FADE\r
42 //static word paloffset=0;\r
43 #endif\r
44 byte *ptr;\r
45 //memptr pal;\r
46 boolean spriteswitch=0;\r
47 \r
48 #define FILENAME_1      "data/spri/chikyuu.vrs"\r
49 #define FILENAME_1P     "data/spri/chikyuu.pal"\r
50 #define FILENAME_2      "data/spri/me.vrs"\r
51 #define FILENAME_2P     "data/spri/me.pal"\r
52 //#define FILENAME_3    "data/spri/chistnd.vrl"\r
53 \r
54 void main(int argc, char *argv[])\r
55 {\r
56         static global_game_variables_t gvar;\r
57         struct glob_game_vars *ggvv;\r
58 \r
59 //      static entity_t enti;\r
60 \r
61         char bakapee[64] = FILENAME_1;\r
62         char bakapeep[64] = FILENAME_1P;\r
63 //      char bakapee3[64] = FILENAME_3;\r
64 \r
65         Startup16(&gvar);\r
66 \r
67         ggvv=&gvar;\r
68         // input!\r
69         IN_Default(0, &gvar.player[0],ctrl_Keyboard1, &gvar);\r
70 \r
71         if (argc >= 2) {\r
72                 if(argv[1]){ strcpy(bakapee, argv[1]);\r
73                 if(argv[2]) strcpy(bakapeep, argv[2]); }\r
74         }\r
75 \r
76         // OK, this one takes hellova time and needs to be done in farmalloc or MM_...\r
77         //IN CA i think you use CAL_SetupGrFile but i do think we should work together on this part --sparky4\r
78         //----gvar.player[0].enti.spri.spritesheet = malloc(sizeof(struct vrs_container));\r
79 \r
80         // create the map\r
81                 #ifdef VERBOSESCROLL\r
82         fprintf(stderr, "testing map load~      ");\r
83                 #endif\r
84         CA_loadmap("data/test.map", &map, &gvar);\r
85 #ifndef NOMAPLOAD\r
86         chkmap(&map, 0);\r
87 //      initMap(&map);\r
88 #else\r
89         chkmap(&map, 1);\r
90         //initMap(&map);\r
91 #endif\r
92                 #ifdef VERBOSESCROLL\r
93         fprintf(stderr, "chkmap ok      ");\r
94         fprintf(stderr, "yay map loaded~~\n");\r
95                 #endif\r
96 \r
97                 #ifdef VERBOSESCROLL\r
98         fprintf(stderr, "press a key wwww\n");\r
99         IN_StartAck (&gvar);    while (!IN_CheckAck (&gvar)){}\r
100                 #endif\r
101 \r
102         // data\r
103                 #ifdef VERBOSESCROLL\r
104         fprintf(stderr, "VRS_LoadVRS    ");\r
105                 #endif\r
106         VRS_LoadVRS(bakapee, &gvar.player[0].enti, &gvar);\r
107                 #ifdef VERBOSESCROLL\r
108         fprintf(stderr, "ok~\n");\r
109                 #endif\r
110 \r
111                 #ifdef VERBOSESCROLL\r
112         fprintf(stderr, "press a key wwww\n");\r
113         IN_StartAck (&gvar);    while (!IN_CheckAck (&gvar)){}\r
114                 #endif\r
115 \r
116         // save the palette\r
117 #ifdef FADE\r
118         modexPalSave(&gvar.video.dpal);\r
119         modexFadeOff(4, &gvar.video.dpal);\r
120         modexPalBlack();\r
121 #endif\r
122 \r
123         //--VGAmodeX(1/*bakapee*/, 1, &gvar);\r
124         VL_Startup(&gvar);\r
125 \r
126         /* load color palette */\r
127         /*ptmp.offset=(paloffset/3);\r
128         modexPalUpdate(&ptmp, &paloffset, 0, 0);\r
129         //modexClearRegion(bg->page, 0, 0, 320, 240, 255);\r
130         //printf("      %d\n", sizeof(ptmp.data));\r
131         //printf("1:    %d\n", paloffset);\r
132         map.tiles->data->offset=(paloffset/3);\r
133         modexPalUpdate(map.tiles->data, &paloffset, 0, 0);*/\r
134                 #ifdef VERBOSESCROLL\r
135         fprintf(stderr, "VL_LoadPalFile ");\r
136                 #endif\r
137         VL_LoadPalFile(bakapeep, &gvar.video.palette, &gvar);\r
138         //VL_LoadPalFile("data/default.pal", &gvar.video.palette);\r
139 \r
140 #ifdef FADE\r
141         modexPalSave(&gvar.video.palette);\r
142         modexSavePalFile("data/g.pal", &gvar.video.palette);\r
143         modexPalBlack();        //so player will not see loadings~\r
144 #endif\r
145                 #ifdef VERBOSESCROLL\r
146         fprintf(stderr, "ok\n");\r
147                 #endif\r
148 \r
149         // setup camera and screen~\r
150         modexHiganbanaPageSetup(&gvar);\r
151         ZC_MVSetup(&gvar.mv, &map, &gvar);\r
152 \r
153 #ifdef FADE\r
154         modexFadeOn(4, &gvar.video.palette);\r
155 #endif\r
156 \r
157 //0000  IN_StartAck (&gvar);    MM_ShowMemory(&gvar);   while (!IN_CheckAck (&gvar)){}\r
158 #ifdef FADE\r
159         modexPalBlack();        //so player will not see loadings~\r
160 #endif\r
161 \r
162         // set up paging\r
163         //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen\r
164         mapGoTo(&gvar.mv, 0, 0);\r
165 \r
166         ZC_PlayerXYpos(0, 0, &gvar.player[0], &gvar.mv, 1);\r
167         EN_initPlayer(&gvar.player[0], &gvar.video);\r
168         //print_anim_ids(gvar.player[0].enti.spri);\r
169         if (gvar.video.sprifilei == -1)\r
170         {\r
171 #ifdef FADE\r
172                 modexFadeOff(4, &gvar.video.palette);\r
173 #endif\r
174                 Quit (&gvar, "Wrong ID for sprite");\r
175 #ifdef FADE\r
176                 modexFadeOn(4, &gvar.video.dpal);\r
177 #endif\r
178         }\r
179 \r
180 //      while(!gvar.in.inst->Keyboard[sc_Escape) && !gvar.in.inst->Keyboard[sc_Space) && !gvar.in.inst->Keyboard[sc_Enter]){ FUNCTIONKEYSHOWMV }\r
181         gvar.video.page[0].tlx=gvar.mv[0].tx*TILEWH;\r
182         gvar.video.page[0].tly=gvar.mv[0].ty*TILEWH;\r
183 \r
184         shinku(&gvar);\r
185 //modexpdump(gvar.mv[0].page);\r
186 #ifdef FADE\r
187         modexFadeOn(4, &gvar.video.palette);\r
188 #endif\r
189         while(!gvar.in.inst->Keyboard[sc_Escape] && gvar.player[0].enti.hp>0)\r
190         {\r
191                 gvar.video.page[0].tlx=gvar.mv[0].tx*TILEWH;\r
192                 gvar.video.page[0].tly=gvar.mv[0].ty*TILEWH;\r
193                 shinku(&gvar);\r
194                 //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square\r
195                 //to stop scrolling and have the gvar.player position data move to the edge of the screen with respect to the direction\r
196                 //when gvar.player[0].tx or gvar.player[0].ty == 0 or gvar.player[0].tx == 20 or gvar.player[0].ty == 15 then stop because that is edge of map and you do not want to walk of the map\r
197 \r
198                 //gvar.player movement\r
199                 IN_ReadControl(&gvar.player[0], &gvar);\r
200                 if(!panswitch){\r
201                         //ZC_walk2(gvar.player[0].ent, mv);\r
202                         ZC_walk(&gvar.mv, &gvar.player, 0);\r
203                 }else{\r
204                         TAIL_PANKEYFUNZC;\r
205                         //printf("      gvar.player[0].enti.q: %d", gvar.player[0].enti.q);     printf("        gvar.player[0].d: %d\n", gvar.player[0].d);\r
206                 }\r
207 \r
208                 //the scripting stuff....\r
209                 //if(((gvar.player[0].enti.triggerx == TRIGGX && gvar.player[0].enti.triggery == TRIGGY) && gvar.in.inst->Keyboard[0x1C))||(gvar.player[0].enti.tx == 5 && gvar.player[0].enti.ty == 5))\r
210                 if(((gvar.mv[0].map->layerdata[0].data[(gvar.player[0].enti.triggerx-1)+(map.width*(gvar.player[0].enti.triggery-1))] == 0) && gvar.in.inst->Keyboard[0x1C])||(gvar.player[0].enti.tx == 5 && gvar.player[0].enti.ty == 5))\r
211                 {\r
212                         short i;\r
213                         for(i=800; i>=400; i--)\r
214                         {\r
215                                 sound(i);\r
216                         }\r
217                         nosound();\r
218                 }\r
219                 if(gvar.player[0].enti.q == (TILEWH/(gvar.player[0].enti.speed))+1 && gvar.player[0].info.dir != 2 && (gvar.player[0].enti.triggerx == 5 && gvar.player[0].enti.triggery == 5)){ gvar.player[0].enti.hp--; }\r
220                 //debugging binds!\r
221 //              if(gvar.in.inst->Keyboard[24]){ VL_modexPalScramble(&gvar.video.palette); /*paloffset=0;*/ VL_LoadPalFileCore(&gvar.video.palette, &gvar); modexpdump(gvar.mv[0].page); IN_UserInput(1, &gvar); } //o\r
222                 if(gvar.in.inst->Keyboard[22]){ VL_modexPalScramble(&gvar.video.palette); VL_LoadPalFileCore(&gvar.video.palette, &gvar); } //u\r
223 \r
224                 TAIL_FUNCTIONKEYFUNCTIONS\r
225                 TAIL_FUNCTIONKEYDRAWJUNK\r
226                 if(gvar.in.inst->Keyboard[sc_L]){ modexClearRegion(&gvar.video.page[0], gvar.player[0].enti.x, gvar.player[0].enti.y, 16, 16, 1); }\r
227 \r
228 //===============================================================================\r
229 #if 0\r
230                 if(gvar.in.inst->Keyboard[sc_BackSlash]){\r
231                         VRS_ReadVRL(bakapee3, &gvar.player[0].enti, &gvar);\r
232                         DrawVRL(\r
233                                 gvar.player[0].enti.x,\r
234                                 gvar.player[0].enti.y,\r
235                                 gvar.player[0].enti.spri.sprite_vrl_cont.vrl_header,\r
236                                 gvar.player[0].enti.spri.sprite_vrl_cont.line_offsets,\r
237                                 gvar.player[0].enti.spri.sprite_vrl_cont.buffer + sizeof(struct vrl1_vgax_header),\r
238                                 gvar.player[0].enti.spri.sprite_vrl_cont.data_size\r
239                         );      while (!IN_CheckAck (&gvar)){}\r
240                         VRS_ReadVRS(bakapee, &gvar.player[0].enti, &gvar);\r
241                 IN_UserInput(1, &gvar); }\r
242 #endif\r
243 //===============================================================================\r
244 \r
245                 if(gvar.in.inst->Keyboard[sc_J])// || gvar.in.inst->Keyboard[sc_K])\r
246                 {\r
247                         if(spriteswitch)//gvar.in.inst->Keyboard[sc_J])\r
248                         {\r
249                                 strcpy(bakapee, FILENAME_1);\r
250                                 strcpy(bakapeep, FILENAME_1P);\r
251                                 gvar.player[0].enti.overdraww=0;\r
252                         }\r
253                         else//if(gvar.in.inst->Keyboard[sc_K])\r
254                         {\r
255                                 strcpy(bakapee, FILENAME_2);\r
256                                 strcpy(bakapeep, FILENAME_2P);\r
257                                 gvar.player[0].enti.overdraww=2;\r
258                         }\r
259                         spriteswitch=!spriteswitch;\r
260 \r
261                         //read_vrs(&gvar, bakapee, gvar.player[0].enti.spri->spritesheet);\r
262                         VRS_ReadVRS(bakapee, &gvar.player[0].enti, &gvar);\r
263                         VL_LoadPalFile(bakapeep, &gvar.video.palette, &gvar);\r
264                         ZC_animatePlayer(&gvar.mv, &gvar.player, 0);\r
265                         IN_UserInput(1, &gvar);\r
266                 }//JK\r
267 //#ifdef FADE\r
268 //              if(gvar.in.inst->Keyboard[10]){ modexPalOverscan(rand()%56); modexPalUpdate(gvar.video.dpal); IN_UserInput(1, &gvar); }\r
269 //#endif\r
270                 if(gvar.in.inst->Keyboard[sc_R]){ VL_modexPalOverscan(&gvar.video.palette, rand()%32); } //r\r
271 \r
272 \r
273                 //if((gvar.player[0].enti.q==1) && !(gvar.player[0].enti.x%TILEWH==0 && gvar.player[0].enti.y%TILEWH==0)) Quit (&gvar, "PLAYER OFF THE RAILS!");//break;        //incase things go out of sync!\r
274                 ZC_GirdChk(&gvar, &gvar.player[0]);\r
275         }\r
276 \r
277         /* fade back to text mode */\r
278         /* but 1st lets save the game palette~ */\r
279 #ifdef FADE\r
280         modexPalSave(&gvar.video.palette);\r
281         modexSavePalFile("data/g.pal", &gvar.video.palette);\r
282         modexFadeOff(4, &gvar.video.palette);\r
283 #endif\r
284         Shutdown16(&gvar);\r
285         printf("\nProject 16 xcroll.exe. This is just a test file!\n");\r
286         printf("version %s\n", VERSION);\r
287         SCROLLEXITMESG;\r
288         WCPU_cpufpumesg();\r
289 #ifdef FADE\r
290         modexFadeOn(4, gvar.video.dpal);\r
291 #endif\r
292 }\r