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