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