OSDN Git Service

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