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