OSDN Git Service

I really do not know what is causing it to be so messy... wwww
[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 //#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         //0000printf("starting timer\n");
58 //++++
59         //++++????start_timer(&gvar);
60 //++++  gvar.frames_per_second = 60;
61 //0000  printf("ok\n");
62         //extern struct inconfig inpu;
63
64 //      atexit(qclean());
65
66         /* create the map */
67         //0000printf("Total used @ before map load:                     %zu\n", oldfreemem-GetFreeSize());
68 //0000  printf("Total free @ before map load:                   %zu\n", GetFreeSize());
69 //0000  printf("Total near free @ before map load:                      %zu\n", GetNearFreeSize());
70 //0000  printf("Total far free @ before map load:                       %zu\n", GetFarFreeSize());
71 //      getch();
72 //0000  fprintf(stderr, "testing~\n");
73 //++++  loadmap("data/test.map", &map);
74         map.width=0;
75         map.height=0;
76         chkmap(&map, 1);
77 //0000  printf("chkmap ok\n");
78 //0000  fprintf(stderr, "yay map loaded~~\n");
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("planar buffer ok\n");
95 //0000  printf("Total used @ after planar buffer creation:      %zu\n", oldfreemem-GetFreeSize());
96
97         /*      input!  */
98 //0000  getch();
99         IN_Startup();
100         IN_Default(0,&player,ctrl_Joystick);
101
102         /* save the palette */
103 #ifdef FADE
104         dpal = modexNewPal();
105         modexPalSave(dpal);
106         modexFadeOff(4, dpal);
107 #endif
108
109         textInit();
110         VGAmodeX(1, &gvar);
111 #ifdef FADE
112         modexPalBlack();        //reset the palette~
113 #endif
114 //      printf("Total used @ before palette initiation:         %zu\n", oldfreemem-GetFreeSize());
115 //++++  player[0].data.offset=(paloffset/3);
116 //++++  modexPalUpdate(&player[0].data, &paloffset, 0, 0);
117         //printf("      %d\n", sizeof(ptmp->data));
118         //printf("1:    %d\n", paloffset);
119 //++++  map.tiles->data->offset=(paloffset/3);
120         //XTmodexPalUpdate(map.tiles->data, &paloffset, 0, 0);
121 //      printf("\n====\n");
122 //      printf("0       paloffset=      %d\n", paloffset/3);
123 //      printf("====\n\n");
124 #ifdef FADE
125         gpal = modexNewPal();
126         modexPalSave(gpal);
127         modexSavePalFile("data/g.pal", gpal);
128         modexPalBlack();        //so player will not see loadings~
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 = modexNextPage0(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         modexDrawSpriteRegion(spri->page, player[0].x-4, player[0].y-TILEWH, 24, 64, 24, 32, &player[0].data);
180 #else
181         modexClearRegion(mv[1].page, player[0].x-4, player[0].y-TILEWH, 24, 32, 15);
182 #endif
183
184         modexShowPage(spri->page);
185 //      printf("Total used @ before loop:                       %zu\n", oldfreemem-GetFreeSize());
186         modexClearRegion(mv[2].page, 0, 0, mv[2].page->width, mv[2].page->height, 1);
187 #ifdef FADE
188         modexFadeOn(4, gpal);
189 #endif
190         while(!IN_KeyDown(sc_Escape) && player[0].hp>0)
191         {
192                 sprintf(mesg, "%lu", gvar.tiku);
193 //++++          modexprint(mv[1].page, 16, 16, 1, 15, 0, mesg);
194                 shinku(mv[1].page, &gvar);
195                 IN_ReadControl(0,&player);
196         //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
197         //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
198         //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
199
200         //player movement
201         //if(!panswitch){
202                 walk(mv, player, 0);
203         /*}else{
204 //88 switch!
205         //right movement
206         if((IN_KeyDown(77) && !IN_KeyDown(75) && pand == 0) || pand == 2)
207         {
208                 if(pand == 0){ pand = 2; }
209                         if(panq<=(TILEWH/(player[0].speed)))
210                         {
211                                 switch(panpagenum)
212                                 {
213                                         case 0:
214                                                 //bg
215                                                 bg->page->dx++;
216                                                 modexShowPage(bg->page);
217                                         break;
218                                         case 1:
219                                                 //spri
220                                                 spri->page->dx++;
221                                                 modexShowPage(spri->page);
222                                         break;
223                                         case 2:
224                                                 //fg
225                                                 mask->page->dx++;
226                                                 modexShowPage(mask->page);
227                                         break;
228                                 }
229                                 panq++;
230                         } else { panq = 1; pand = 0; }
231         }
232         //left movement
233         if((IN_KeyDown(75) && !IN_KeyDown(77) && pand == 0) || pand == 4)
234         {
235                 if(pand == 0){ pand = 4; }
236                         if(panq<=(TILEWH/(player[0].speed)))
237                         {
238                                 switch(panpagenum)
239                                 {
240                                         case 0:
241                                                 //bg
242                                                 bg->page->dx--;
243                                                 modexShowPage(bg->page);
244                                         break;
245                                         case 1:
246                                                 //spri
247                                                 spri->page->dx--;
248                                                 modexShowPage(spri->page);
249                                         break;
250                                         case 2:
251                                                 //fg
252                                                 mask->page->dx--;
253                                                 modexShowPage(mask->page);
254                                         break;
255                                 }
256                                 panq++;
257                         } else { panq = 1; pand = 0; }
258         }
259         //down movement
260         if((IN_KeyDown(72) && !IN_KeyDown(80) && pand == 0) || pand == 3)
261         {
262                 if(pand == 0){ pand = 3; }
263                         if(panq<=(TILEWH/(player[0].speed)))
264                         {
265                                 switch(panpagenum)
266                                 {
267                                         case 0:
268                                                 //bg
269                                                 bg->page->dy--;
270                                                 modexShowPage(bg->page);
271                                         break;
272                                         case 1:
273                                                 //spri
274                                                 spri->page->dy--;
275                                                 modexShowPage(spri->page);
276                                         break;
277                                         case 2:
278                                                 //fg
279                                                 mask->page->dy--;
280                                                 modexShowPage(mask->page);
281                                         break;
282                                 }
283                                 panq++;
284                         } else { panq = 1; pand = 0; }
285         }
286         //up movement
287         if((IN_KeyDown(80) && !IN_KeyDown(72) && pand == 0) || pand == 1)
288         {
289                 if(pand == 0){ pand = 1; }
290                         if(panq<=(TILEWH/(player[0].speed)))
291                         {
292                                 switch(panpagenum)
293                                 {
294                                         case 0:
295                                                 //bg
296                                                 bg->page->dy++;
297                                                 modexShowPage(bg->page);
298                                         break;
299                                         case 1:
300                                                 //spri
301                                                 spri->page->dy++;
302                                                 modexShowPage(spri->page);
303                                         break;
304                                         case 2:
305                                                 //fg
306                                                 mask->page->dy++;
307                                                 modexShowPage(mask->page);
308                                         break;
309                                 }
310                                 panq++;
311                         } else { panq = 1; pand = 0; }
312         }
313 }*/
314
315
316         //the scripting stuf....
317
318         //if(((player[0].triggerx == TRIGGX && player[0].triggery == TRIGGY) && IN_KeyDown(0x1C))||(player[0].tx == 5 && player[0].ty == 5))
319         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))
320         {
321                 short i;
322                 for(i=800; i>=400; i--)
323                 {
324                         sound(i);
325                 }
326                 nosound();
327         }
328         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--; }
329         //debugging binds!
330         //if(IN_KeyDown(0x0E)) while(1){ if(xmsmalloc(24)) break; }
331         if(IN_KeyDown(2)){ modexShowPage(bg->page); panpagenum=0; }
332         if(IN_KeyDown(3)){ modexShowPage(spri->page); panpagenum=1; }
333         if(IN_KeyDown(4)){ modexShowPage(mask->page); panpagenum=2; }
334         if(IN_KeyDown(25)){ pdump(bg->page); pdump(spri->page); }       //p
335 #ifdef FADE
336         if(IN_KeyDown(24)){ modexPalUpdate0(gpal); paloffset=0; pdump(bg->page); pdump(spri->page); }
337         if(IN_KeyDown(22)){
338         paloffset=0; modexPalBlack(); modexPalUpdate(&player[0].data, &paloffset, 0, 0);
339         printf("1paloffset      =       %d\n", paloffset/3);
340          modexPalUpdate(map.tiles->data, &paloffset, 0, 0);
341         printf("2paloffset      =       %d\n", paloffset/3);
342          pdump(bg->page); pdump(spri->page); }
343 #endif
344         //pan switch
345         //if(IN_KeyDown(88)){if(!panswitch) panswitch++; else panswitch--; }    //f12
346         //TSR
347         if(IN_KeyDown(87))      //f11
348         {
349                 VGAmodeX(0, &gvar);
350                 IN_Shutdown();
351                 __asm
352                 {
353                         mov ah,31h
354                         int 21h
355                 }
356         }
357
358         if((player[0].q==1) && !(player[0].x%TILEWH==0 && player[0].y%TILEWH==0)) break;        //incase things go out of sync!
359
360         gvar.tiku++;
361         }
362
363         /* fade back to text mode */
364         /* but 1st lets save the game palette~ */
365 #ifdef FADE
366         modexPalSave(gpal);
367         modexSavePalFile("data/g.pal", gpal);
368         modexFadeOff(4, gpal);
369 #endif
370         VGAmodeX(0, &gvar);
371         IN_Shutdown();
372         printf("Project 16 scroll.exe. This is just a test file!\n");
373         printf("version %s\n", VERSION);
374         printf("tx: %d\n", bg->tx);
375         printf("ty: %d\n", bg->ty);
376         printf("player[0].x: %d", player[0].x); printf("                player[0].y: %d\n", player[0].y);
377         //if(player[0].hp==0) printf("%d wwww\n", player[0].y+8);
378         //else printf("\nplayer[0].y: %d\n", player[0].y);
379         printf("player[0].tx: %d", player[0].tx); printf("              player[0].ty: %d\n", player[0].ty);
380         printf("player[0].triggx: %d", player[0].triggerx); printf("    player[0].triggy: %d\n", player[0].triggery);
381         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);
382         printf("tile data value at player trigger position: %d\n", bg->map->data[(player[0].triggerx-1)+(map.width*(player[0].triggery-1))]);
383 //      printf("palette offset: %d\n", paloffset/3);
384 //++++  printf("Total used: %zu\n", oldfreemem-GetFreeSize());
385 //++++  printf("Total free: %zu\n", GetFreeSize());
386 //not used now  printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");
387 //not used now  printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");
388 //      printf("Screen: %dx", screen.width);    printf("%d\n", screen.height);
389 //      printf("Screen2: %dx", screen2.width);  printf("%d\n", screen2.height);
390 //      printf("map: %dx%d\n", map.width, map.height);
391 //      printf("\n");
392 //      printf("player[0].info.x: %d", player[0].info.xaxis); printf("          player[0].info.y: %d\n", player[0].info.yaxis);
393 //      printf("player[0].info.tx: %d", player[0].info.x); printf("             player[0].info.ty: %d\n", player[0].info.y);
394         //printf("map.width=%d  map.height=%d   map.data[0]=%d\n", bg->map->width, bg->map->height, bg->map->data[0]);
395
396         switch(detectcpu())
397         {
398                 case 0: cpus = "8086/8088 or 186/88"; break;
399                 case 1: cpus = "286"; break;
400                 case 2: cpus = "386 or newer"; break;
401                 default: cpus = "internal error"; break;
402         }
403         printf("detected CPU type: %s\n", cpus);
404 #ifdef FADE
405         modexFadeOn(4, dpal);
406 #endif
407 }