OSDN Git Service

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