]> 4ch.mooo.com Git - 16.git/blob - src/scroll.c
wwww
[16.git] / src / scroll.c
1 /* Project 16 Source Code~
2  * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669
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 should 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/lib/scroll16.h"
24 #include "src/lib/timer.h"
25 #include "src/lib/wcpu/wcpu.h"
26
27 //#define FADE
28 #define MODEX   //this is for mode x initiating
29
30 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
31
32 global_game_variables_t gvar;
33 static map_t map;
34 player_t player[MaxPlayers];
35 //page_t screen, gvar.video.page[1], gvar.video.page[2];
36 map_view_t mv[3];
37 map_view_t *bg, *spri, *mask;//, *tmp;
38 bitmap_t p;
39 word pn=0;
40 static planar_buf_t huge *pp;
41 float t;
42 sword bakapee;
43
44 //      word panswitch=0, panq=1, pand=0;
45         word panpagenum=0; //for panning!
46         unsigned int i;
47         const char *cpus;
48         //static int persist_aniframe = 0;    /* gonna be increased to 1 before being used, so 0 is ok for default */
49
50         //map_view_db_t pgid[4];
51         word pg;
52 //#ifdef FADE
53         static word paloffset=0;
54         byte *dpal, *default_pal;
55 //#endif
56         byte *gpal;
57         byte *ptr;
58         byte *mappalptr;
59
60 void main(int argc, char *argv[])
61 {
62         byte *mesg=malloc(sizeof(dword));
63
64         if(argv[1]) bakapee = atoi(argv[1]);
65         else bakapee = 1;
66
67         player[0].persist_aniframe=0;
68         player[0].speed=4;
69         //player[0].data = &pp;
70
71         printf("starting timer\n");
72         start_timer(&gvar);
73         printf("ok\n");
74         //extern struct inconfig inpu;
75
76 //      atexit(qclean());
77
78         /* create the map */
79         fprintf(stderr, "testing map load~\n");
80         loadmap("data/test.map", &map);
81         chkmap(&map, 0);
82         printf("chkmap ok\n");
83         fprintf(stderr, "yay map loaded~~\n");
84         mv[0].map = &map;
85         mv[1].map = &map;
86         mv[2].map = &map;
87
88         /* draw the tiles */
89 #ifdef MODEX
90         ptr = map.data;
91         //mappalptr = map.tiles->btdata->palette;
92
93         /* data */
94         p = bitmapLoadPcx("data/ptmp.pcx"); // load sprite
95         //npctmp = bitmapLoadPcx("ptmp1.pcx"); // load sprite
96
97         /* create the planar buffer */
98 ////++++        (player[0].data) = *planar_buf_from_bitmap(&p);
99         printf("load pee!!\n");
100         pp = planar_buf_from_bitmap(&p);
101         printf("done!\n");
102
103 #endif
104         /*      input!  */
105         IN_Startup();
106         IN_Default(0,&player,ctrl_Joystick);
107
108         /* save the palette */
109 #ifdef MODEX
110 #ifdef FADE
111         dpal = modexNewPal();
112         default_pal = modexNewPal();
113         *default_pal = *dpal;
114         modexPalSave(dpal);
115         modexFadeOff(4, dpal);
116 #endif
117
118         textInit();
119         VGAmodeX(bakapee, &gvar);
120 //      printf("%dx%d\n", gvar.video.page[0].sw, gvar.video.page[0].sh);
121 #ifdef FADE
122         modexPalBlack();        //reset the palette~
123 #endif
124 #endif
125 //      printf("Total used @ before palette initiation:         %zu\n", oldfreemem-GetFreeSize());
126 //++++  player[0].data.offset=(paloffset/3);
127 //++++  modexPalUpdate1(&player[0].data, &paloffset, 0, 0);
128                 //modexPalUpdate1(p.palette);
129                 modexPalUpdate1(map.tiles->btdata->palette);
130         //printf("      %d\n", sizeof(ptmp->data));
131         //printf("1:    %d\n", paloffset);
132 //++++  map.tiles->data->offset=(paloffset/3);
133         //XTmodexPalUpdate(map.tiles->data, &paloffset, 0, 0);
134 //      printf("\n====\n");
135 //      printf("0       paloffset=      %d\n", paloffset/3);
136 //      printf("====\n\n");
137 #ifdef MODEX
138 #ifdef FADE
139         gpal = modexNewPal();
140         modexPalSave(gpal);
141         modexSavePalFile("data/g.pal", gpal);
142         modexPalBlack();        //so player will not see loadings~
143 #endif
144 #endif
145
146         /* setup camera and screen~ */
147         gvar.video.page[0] = modexDefaultPage(&gvar.video.page[0]);
148         gvar.video.page[0].width += (TILEWH*2);
149         gvar.video.page[0].height += (TILEWH*2);//+QUADWH;
150         mv[0].page = &gvar.video.page[0];
151         gvar.video.page[1] = modexNextPage(mv[0].page);
152         mv[1].page = &gvar.video.page[1];
153
154         gvar.video.page[2] = modexNextPageFlexibleSize(mv[1].page, gvar.video.page[0].sw, gvar.video.page[0].sh);       //(352*176)+1024 is the remaining amount of memory left wwww
155         //gvar.video.page[2] = modexNextPage0(mv2.page, 320, 192);      //(352*176)+1024 is the remaining amount of memory left wwww
156         mv[2].page = &gvar.video.page[2];
157
158         /* set up paging */
159         bg = &mv[0];
160         spri = &mv[1];
161         mask = &mv[2];
162 //IN_Ack();
163 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
164         mapGoTo(bg, 0, 0);
165         mapGoTo(spri, 0, 0);
166         //mapGoTo(mask, 0, 0);
167 //IN_Ack();
168         //TODO: put player in starting position of spot
169         //default player position on the viewable map
170         player[0].tx = bg->tx + bg->page->tilemidposscreenx;
171         player[0].ty = bg->ty + bg->page->tilemidposscreeny;
172         player[0].x = player[0].tx*TILEWH;
173         player[0].y = player[0].ty*TILEWH;
174         player[0].triggerx = player[0].tx;
175         player[0].triggery = player[0].ty+1;
176 /*      player[0].info.x = player[0].tx;
177         player[0].info.xaxis = player[0].tx*TILEWH;
178         player[0].info.y = player[0].ty;
179         player[0].info.yaxis = player[0].ty*TILEWH;*/
180         player[0].q=1;
181         player[0].d=2;
182         player[0].hp=4;
183 //      player[0].persist_aniframe=0;
184         //npc
185         /*npc0.tx = bg->tx + 1;
186         npc0.ty = bg->ty + 1;
187         npc0.x = npc0.tx*TILEWH;
188         npc0.y = npc0.ty*TILEWH;
189         npc0.triggerx = npc0.tx;
190         npc0.triggery = npc0.ty+1;
191         npc0.q=1;
192         npc0.d=0;
193         modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 64, 24, 32, &npctmp);*/
194
195         modexCopyPageRegion(mv[1].page, mv[0].page, 0, 0, 0, 0, mv[0].page->width, mv[0].page->height);
196 #ifndef SPRITE
197         modexClearRegion(mv[1].page, player[0].x-4, player[0].y-TILEWH, 24, 32, 15);
198 #else
199         //PBUFSFUN(spri->page, player[0].x-4, player[0].y-TILEWH, 24, 64, 24, 32,       PLAYERBMPDATA);
200         PBUFSFUN(spri->page, player[0].x-4, player[0].y-TILEWH, 24, 64, 24, 32, &pp);
201 #endif
202
203         modexShowPage(spri->page);
204         //modexClearRegion(mv[2].page, 0, 0, mv[2].page->width, mv[2].page->height, 1);
205 #ifdef MODEX
206 #ifdef FADE
207         modexFadeOn(4, gpal);
208 #endif
209 #endif
210         while(!IN_KeyDown(sc_Escape) && player[0].hp>0)
211         {
212                 shinku(mv, &gvar);
213                 IN_ReadControl(0,&player);
214         //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
215         //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
216         //when player[0].tx or player[0].ty == 0 or player[0].tx == 20 or player[0].ty == 15 then stop because that is edge of map and you do not want to walk of the map
217
218         //player movement
219         //if(!panswitch){
220                 walk(mv, player, 0);
221         /*}else{
222 //88 switch!
223         //right movement
224         if((IN_KeyDown(77) && !IN_KeyDown(75) && pand == 0) || pand == 2)
225         {
226                 if(pand == 0){ pand = 2; }
227                         if(panq<=(TILEWH/(player[0].speed)))
228                         {
229                                 switch(panpagenum)
230                                 {
231                                         case 0:
232                                                 //bg
233                                                 bg->page->dx++;
234                                                 modexShowPage(bg->page);
235                                         break;
236                                         case 1:
237                                                 //spri
238                                                 spri->page->dx++;
239                                                 modexShowPage(spri->page);
240                                         break;
241                                         case 2:
242                                                 //fg
243                                                 mask->page->dx++;
244                                                 modexShowPage(mask->page);
245                                         break;
246                                 }
247                                 panq++;
248                         } else { panq = 1; pand = 0; }
249         }
250         //left movement
251         if((IN_KeyDown(75) && !IN_KeyDown(77) && pand == 0) || pand == 4)
252         {
253                 if(pand == 0){ pand = 4; }
254                         if(panq<=(TILEWH/(player[0].speed)))
255                         {
256                                 switch(panpagenum)
257                                 {
258                                         case 0:
259                                                 //bg
260                                                 bg->page->dx--;
261                                                 modexShowPage(bg->page);
262                                         break;
263                                         case 1:
264                                                 //spri
265                                                 spri->page->dx--;
266                                                 modexShowPage(spri->page);
267                                         break;
268                                         case 2:
269                                                 //fg
270                                                 mask->page->dx--;
271                                                 modexShowPage(mask->page);
272                                         break;
273                                 }
274                                 panq++;
275                         } else { panq = 1; pand = 0; }
276         }
277         //down movement
278         if((IN_KeyDown(72) && !IN_KeyDown(80) && pand == 0) || pand == 3)
279         {
280                 if(pand == 0){ pand = 3; }
281                         if(panq<=(TILEWH/(player[0].speed)))
282                         {
283                                 switch(panpagenum)
284                                 {
285                                         case 0:
286                                                 //bg
287                                                 bg->page->dy--;
288                                                 modexShowPage(bg->page);
289                                         break;
290                                         case 1:
291                                                 //spri
292                                                 spri->page->dy--;
293                                                 modexShowPage(spri->page);
294                                         break;
295                                         case 2:
296                                                 //fg
297                                                 mask->page->dy--;
298                                                 modexShowPage(mask->page);
299                                         break;
300                                 }
301                                 panq++;
302                         } else { panq = 1; pand = 0; }
303         }
304         //up movement
305         if((IN_KeyDown(80) && !IN_KeyDown(72) && pand == 0) || pand == 1)
306         {
307                 if(pand == 0){ pand = 1; }
308                         if(panq<=(TILEWH/(player[0].speed)))
309                         {
310                                 switch(panpagenum)
311                                 {
312                                         case 0:
313                                                 //bg
314                                                 bg->page->dy++;
315                                                 modexShowPage(bg->page);
316                                         break;
317                                         case 1:
318                                                 //spri
319                                                 spri->page->dy++;
320                                                 modexShowPage(spri->page);
321                                         break;
322                                         case 2:
323                                                 //fg
324                                                 mask->page->dy++;
325                                                 modexShowPage(mask->page);
326                                         break;
327                                 }
328                                 panq++;
329                         } else { panq = 1; pand = 0; }
330         }
331 }*/
332
333
334         //the scripting stuf....
335
336         //if(((player[0].triggerx == TRIGGX && player[0].triggery == TRIGGY) && IN_KeyDown(0x1C))||(player[0].tx == 5 && player[0].ty == 5))
337         if(((bg->map->data[(player[0].triggerx-1)+(map.width*(player[0].triggery-1))] == 0) && IN_KeyDown(0x1C))||(player[0].tx == 5 && player[0].ty == 5))
338         {
339                 short i;
340                 for(i=800; i>=400; i--)
341                 {
342                         sound(i);
343                 }
344                 nosound();
345         }
346         if(player[0].q == (TILEWH/(player[0].speed))+1 && player[0].info.dir != 2 && (player[0].triggerx == 5 && player[0].triggery == 5)){ player[0].hp--; }
347         //debugging binds!
348         //if(IN_KeyDown(0x0E)) while(1){ if(xmsmalloc(24)) break; }
349         if(IN_KeyDown(2)){ modexShowPage(bg->page); panpagenum=0; }
350         if(IN_KeyDown(3)){ modexShowPage(spri->page); panpagenum=1; }
351         if(IN_KeyDown(4)){ modexShowPage(mask->page); panpagenum=2; }
352         if(IN_KeyDown(25)){ pdump(bg->page); pdump(spri->page); }       //p
353 #ifdef MODEX
354 #ifdef FADE
355         if(IN_KeyDown(24)){ modexPalUpdate0(gpal); paloffset=0; pdump(bg->page); pdump(spri->page); }
356         if(IN_KeyDown(22)){
357         paloffset=0; modexPalBlack(); modexPalUpdate(&player[0].data, &paloffset, 0, 0);
358         printf("1paloffset      =       %d\n", paloffset/3);
359          modexPalUpdate(map.tiles->data, &paloffset, 0, 0);
360         printf("2paloffset      =       %d\n", paloffset/3);
361          pdump(bg->page); pdump(spri->page); }
362 #endif
363 #endif
364         //pan switch
365         //if(IN_KeyDown(88)){if(!panswitch) panswitch++; else panswitch--; }    //f12
366         //TSR
367         if(IN_KeyDown(87))      //f11
368         {
369                 VGAmodeX(0, &gvar);
370                 IN_Shutdown();
371                 __asm
372                 {
373                         mov ah,31h
374                         int 21h
375                 }
376         }
377         if(IN_KeyDown(88))      //s
378         {
379                 switch(gvar.kurokku.fpscap)
380                 {
381                         case 0:
382                                 gvar.kurokku.fpscap=1;
383                         break;
384                         case 1:
385                                 gvar.kurokku.fpscap=0;
386                         break;
387                 }
388                 IN_Ack();
389         }
390         //TODO fmemtest into page
391         if(IN_KeyDown(4+1))     //4
392         {
393                 pg=1;
394                 SELECT_ALL_PLANES();
395                 _fmemset(((mv[pg].page->data+4)+(16*(mv[pg].page->width/4))), 15, 4);
396         }
397
398         //9
399         if(IN_KeyDown(10)){ modexPalOverscan(default_pal, rand()%56); modexPalUpdate1(default_pal); }
400         //if(IN_KeyDown(11)){ modexPalOverscan(default_pal, 15); }
401         if((player[0].q==1) && !(player[0].x%TILEWH==0 && player[0].y%TILEWH==0)) break;        //incase things go out of sync!
402         }
403
404         /* fade back to text mode */
405         /* but 1st lets save the game palette~ */
406 #ifdef MODEX
407 #ifdef FADE
408         modexPalSave(gpal);
409         modexSavePalFile("data/g.pal", gpal);
410         modexFadeOff(4, gpal);
411 #endif
412         VGAmodeX(0, &gvar);
413 #endif
414         IN_Shutdown();
415         printf("Project 16 scroll.exe. This is just a test file!\n");
416         printf("version %s\n", VERSION);
417         printf("tx: %d\n", bg->tx);
418         printf("ty: %d\n", bg->ty);
419         printf("player[0].x: %d", player[0].x); printf("                player[0].y: %d\n", player[0].y);
420         //if(player[0].hp==0) printf("%d wwww\n", player[0].y+8);
421         //else printf("\nplayer[0].y: %d\n", player[0].y);
422         printf("player[0].tx: %d", player[0].tx); printf("              player[0].ty: %d\n", player[0].ty);
423         printf("player[0].triggx: %d", player[0].triggerx); printf("    player[0].triggy: %d\n", player[0].triggery);
424         printf("player[0].hp: %d", (player[0].hp));     printf("        player[0].q: %d", player[0].q); printf("        player[0].info.dir: %d", player[0].info.dir);   printf("        player[0].d: %d\n", player[0].d);
425         printf("tile data value at player trigger position: %d\n", bg->map->data[(player[0].triggerx-1)+(map.width*(player[0].triggery-1))]);
426 //      printf("palette offset: %d\n", paloffset/3);
427 //++++  printf("Total used: %zu\n", oldfreemem-GetFreeSize());
428 //++++  printf("Total free: %zu\n", GetFreeSize());
429 //not used now  printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");
430 //not used now  printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");
431         printf("Virtual Screen: %dx", gvar.video.page[0].width);        printf("%d\n", gvar.video.page[0].height);
432         printf("Screen: %dx", gvar.video.page[0].sw);   printf("%d\n", gvar.video.page[0].sh);
433         printf("tile resolution: %dx", gvar.video.page[0].tilesh);      printf("%d\n", gvar.video.page[0].tilesh);
434         printf("middle tile position: %dx", gvar.video.page[0].tilemidposscreenx);      printf("%d\n", gvar.video.page[0].tilemidposscreeny);
435 //      printf("Screen2: %dx", gvar.video.page[1].width);       printf("%d\n", gvar.video.page[1].height);
436 //      printf("map: %dx%d\n", map.width, map.height);
437 //      printf("\n");
438 //      printf("player[0].info.x: %d", player[0].info.xaxis); printf("          player[0].info.y: %d\n", player[0].info.yaxis);
439 //      printf("player[0].info.tx: %d", player[0].info.x); printf("             player[0].info.ty: %d\n", player[0].info.y);
440         //printf("map.width=%d  map.height=%d   map.data[0]=%d\n", bg->map->width, bg->map->height, bg->map->data[0]);
441
442         switch(detectcpu())
443         {
444                 case 0: cpus = "8086/8088 or 186/88"; break;
445                 case 1: cpus = "286"; break;
446                 case 2: cpus = "386 or newer"; break;
447                 default: cpus = "internal error"; break;
448         }
449         printf("detected CPU type: %s\n", cpus);
450 #ifdef MODEX
451 #ifdef FADE
452         modexFadeOn(4, dpal);
453 #endif
454 #endif
455 }