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