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