]> 4ch.mooo.com Git - 16.git/blob - src/scroll.c
panning updated and stuff wwww
[16.git] / src / scroll.c
1 /* Project 16 Source Code~
2  * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123
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/16_timer.h"
25 #include "src/lib/wcpu/wcpu.h"
26
27 //#define FADE
28 #define MODEX   //this is for mode x initiating
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, gvar.video.page[1], gvar.video.page[2];
36 map_view_t mv[3];
37 bitmap_t p;
38 word pn=0;
39 static planar_buf_t huge *pp;
40 float t;
41 sword bakapee;
42 pan_t pan;
43 boolean panswitch=1;
44         unsigned int i;
45         const char *cpus;
46         //static int persist_aniframe = 0;    /* gonna be increased to 1 before being used, so 0 is ok for default */
47
48         //map_view_db_t pgid[4];
49         word pg;
50 //#ifdef FADE
51         static word paloffset=0;
52         byte *dpal, *default_pal;
53 //#endif
54         byte *gpal;
55         byte *ptr;
56         byte *mappalptr;
57
58 void main(int argc, char *argv[])
59 {
60         byte *mesg=malloc(sizeof(dword));
61
62         if(argv[1]) bakapee = atoi(argv[1]);
63         else bakapee = 1;
64
65         // DOSLIB: check our environment
66         probe_dos();
67
68         // DOSLIB: what CPU are we using?
69         // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.
70         //      So this code by itself shouldn't care too much what CPU it's running on. Except that other
71         //      parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for
72         //      the CPU to carry out tasks. --J.C.
73         cpu_probe();
74
75         // DOSLIB: check for VGA
76         if (!probe_vga()) {
77                 printf("VGA probe failed\n");
78                 return;
79         }
80         // hardware must be VGA or higher!
81         if (!(vga_state.vga_flags & VGA_IS_VGA)) {
82                 printf("This program requires VGA or higher graphics hardware\n");
83                 return;
84         }
85
86         pan.pn=0;
87         //player[0].data = &pp;
88
89         printf("starting timer  ");
90         start_timer(&gvar);
91         printf("ok\n");
92
93 //      atexit(qclean());
94
95         /* create the map */
96         fprintf(stderr, "testing map load~      ");
97         loadmap("data/test.map", &map);
98         chkmap(&map, 0);
99         printf("chkmap ok       ");
100         fprintf(stderr, "yay map loaded~~\n");
101
102         /* draw the tiles */
103 #ifdef MODEX
104         ptr = map.data;
105         //mappalptr = map.tiles->btdata->palette;
106
107         /* data */
108         //++++p = bitmapLoadPcx("data/ptmp.pcx"); // load sprite
109         //npctmp = bitmapLoadPcx("ptmp1.pcx"); // load sprite
110
111         /* create the planar buffer */
112 ////++++        (player[0].data) = *planar_buf_from_bitmap(&p);
113         /*++++printf("load pee!!        ");
114         pp = planar_buf_from_bitmap(&p);
115         printf("done!\n");*/
116
117 #endif
118         /*      input!  */
119         IN_Startup();
120         IN_Default(0,&player,ctrl_Joystick);
121         IN_Default(1,&player,ctrl_Joystick);
122
123         /* save the palette */
124 #ifdef MODEX
125 #ifdef FADE
126         dpal = modexNewPal();
127         default_pal = modexNewPal();
128         *default_pal = *dpal;
129         modexPalSave(dpal);
130         modexFadeOff(4, dpal);
131 #endif
132
133         textInit();
134         VGAmodeX(bakapee, 1, &gvar);
135 //      printf("%dx%d\n", gvar.video.page[0].sw, gvar.video.page[0].sh);
136 #ifdef FADE
137         modexPalBlack();        //reset the palette~
138 #endif
139 #endif
140 //      printf("Total used @ before palette initiation:         %zu\n", oldfreemem-GetFreeSize());
141 //++++  player[0].data.offset=(paloffset/3);
142 //++++  modexPalUpdate1(&player[0].data, &paloffset, 0, 0);
143                 //modexPalUpdate1(p.palette);
144 //++++0000              modexPalUpdate1(map.tiles->btdata->palette);
145         //printf("      %d\n", sizeof(ptmp->data));
146         //printf("1:    %d\n", paloffset);
147 //++++  map.tiles->data->offset=(paloffset/3);
148         //XTmodexPalUpdate(map.tiles->data, &paloffset, 0, 0);
149 //      printf("\n====\n");
150 //      printf("0       paloffset=      %d\n", paloffset/3);
151 //      printf("====\n\n");
152 #ifdef MODEX
153 #ifdef FADE
154         gpal = modexNewPal();
155         modexPalSave(gpal);
156         modexSavePalFile("data/g.pal", gpal);
157         modexPalBlack();        //so player will not see loadings~
158 #endif
159 #endif
160
161         /* setup camera and screen~ */
162         modexHiganbanaPageSetup(&gvar.video);
163         for(i=0;i<gvar.video.num_of_pages-3;i++)
164         {
165                 mv[i].page = &gvar.video.page[i];
166                 mv[i].map = &map;
167                 mv[i].video = &gvar.video;
168                 mv[i].pan       = &pan;
169                 /* set up paging */
170 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
171                 mapGoTo(&mv[i], -1, -1);
172 //TODO: put player in starting position of spot
173         }
174
175         //default player position on the viewable map
176         player[panswitch].tx = mv[0].tx + mv[0].page->tilemidposscreenx;
177         player[panswitch].ty = mv[0].ty + mv[0].page->tilemidposscreeny;
178         IN_initplayer(&player, 0);
179         IN_initplayer(&player, 1);
180
181 //      modexCopyPageRegion(mv[1].page, mv[0].page, 0, 0, 0, 0, mv[0].page->width, mv[0].page->height);
182 #ifndef SPRITE
183 //      modexClearRegion(mv[1].page, player[panswitch].x-4, player[panswitch].y-TILEWH, 24, 32, 15);
184 #else
185         //PBUFSFUN(mv[1].page, player[panswitch].x-4, player[panswitch].y-TILEWH, 24, 64, 24, 32,       PLAYERBMPDATA);
186 //      PBUFSFUN(mv[1].page, player[panswitch].x-4, player[panswitch].y-TILEWH, 24, 64, 24, 32, &pp);
187 #endif
188
189         modexShowPage(mv[pan.pn].page);
190         shinku_fps_indicator_page = 0; // we're on page 1 now, shinku(). follow along please or it will not be visible.
191         //modexClearRegion(mv[2].page, 0, 0, mv[2].page->width, mv[2].page->height, 1);
192 #ifdef MODEX
193 #ifdef FADE
194         modexFadeOn(4, gpal);
195 #endif
196 #endif
197         while(!IN_KeyDown(sc_Escape) && player[panswitch].hp>0)
198         {
199                 shinku(&gvar);
200         //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
201         //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
202         //when player[panswitch].tx or player[panswitch].ty == 0 or player[panswitch].tx == 20 or player[panswitch].ty == 15 then stop because that is edge of map and you do not want to walk of the map
203
204         //player movement
205                 IN_ReadControl(panswitch,&player);
206         if(!panswitch){
207                 walk(mv, player, panswitch);
208         }else{
209                 panpagemanual(mv, player, panswitch);
210                 //printf("      player[panswitch].q: %d", player[panswitch].q); printf("        player[panswitch].d: %d\n", player[panswitch].d);
211         }
212
213
214         //the scripting stuff....
215         //if(((player[panswitch].triggerx == TRIGGX && player[panswitch].triggery == TRIGGY) && IN_KeyDown(0x1C))||(player[panswitch].tx == 5 && player[panswitch].ty == 5))
216         if(((mv[panswitch].map->data[(player[panswitch].triggerx-1)+(map.width*(player[panswitch].triggery-1))] == 0) && IN_KeyDown(0x1C))||(player[panswitch].tx == 5 && player[panswitch].ty == 5))
217         {
218                 short i;
219                 for(i=800; i>=400; i--)
220                 {
221                         sound(i);
222                 }
223                 nosound();
224         }
225         if(player[panswitch].q == (TILEWH/(player[panswitch].speed))+1 && player[panswitch].info.dir != 2 && (player[panswitch].triggerx == 5 && player[panswitch].triggery == 5)){ player[panswitch].hp--; }
226         //debugging binds!
227         //if(IN_KeyDown(0x0E)) while(1){ if(xmsmalloc(24)) break; }
228         if(IN_KeyDown(2)){ modexShowPage(mv[0].page); pan.pn=0; }
229         if(IN_KeyDown(3)){ modexShowPage(mv[1].page); pan.pn=1; }
230         //if(IN_KeyDown(4)){ modexShowPage(mv[2].page); pan.pn=2; }
231         //if(IN_KeyDown(4+1)){ modexShowPage(mv[3].page); pan.pn=3; }
232         if(IN_KeyDown(25)){ modexpdump(mv[0].page); modexpdump(mv[1].page);
233                 //IN_Ack();
234         }       //p
235 #ifdef MODEX
236 #ifdef FADE
237         if(IN_KeyDown(24)){ modexPalUpdate0(gpal); paloffset=0; modexpdump(mv[0].page); modexpdump(mv[1].page); }
238         if(IN_KeyDown(22)){
239         paloffset=0; modexPalBlack(); modexPalUpdate(&player[panswitch].data, &paloffset, 0, 0);
240         printf("1paloffset      =       %d\n", paloffset/3);
241          modexPalUpdate(map.tiles->data, &paloffset, 0, 0);
242         printf("2paloffset      =       %d\n", paloffset/3);
243          modexpdump(mv[0].page); modexpdump(mv[1].page); }
244 #endif
245 #endif
246         //pan switch
247         if(IN_KeyDown(88)){panswitch=!panswitch;}       //f12
248         //TSR
249         if(IN_KeyDown(87))      //f11
250         {
251                 pageflipflop=!pageflipflop;
252                 //IN_Ack();
253 //              VGAmodeX(0, 0, &gvar);
254 //              IN_Shutdown();
255 //              __asm
256 //              {
257 //                      mov ah,31h
258 //                      int 21h
259 //              }
260         }
261         if(IN_KeyDown(68))      //s
262         {
263                 gvar.kurokku.fpscap=!gvar.kurokku.fpscap;
264                 //IN_Ack();
265         }
266         //TODO fmemtest into page
267         /*if(IN_KeyDown(4+1))   //4
268         {
269                 pg=1;
270                 SELECT_ALL_PLANES();
271                 _fmemset(((mv[pg].page->data+4)+(16*(mv[pg].page->width/4))), 15, 4);
272         }*/
273
274         //9
275         if(IN_KeyDown(10)){ modexPalOverscan(default_pal, rand()%56); modexPalUpdate1(default_pal); }
276         //if(IN_KeyDown(11)){ modexPalOverscan(default_pal, 15); }
277         if((player[panswitch].q==1) && !(player[panswitch].x%TILEWH==0 && player[panswitch].y%TILEWH==0)) break;        //incase things go out of sync!
278         }
279
280         /* fade back to text mode */
281         /* but 1st lets save the game palette~ */
282 #ifdef MODEX
283 #ifdef FADE
284         modexPalSave(gpal);
285         modexSavePalFile("data/g.pal", gpal);
286         modexFadeOff(4, gpal);
287 #endif
288         VGAmodeX(0, 1, &gvar);
289 #endif
290         IN_Shutdown();
291         printf("Project 16 scroll.exe. This is just a test file!\n");
292         printf("version %s\n", VERSION);
293         printf("tx: %d\n", mv[0].tx);
294         printf("ty: %d\n", mv[0].ty);
295         printf("player.x: %d", player[panswitch].x); printf("           player.y: %d\n", player[panswitch].y);
296         //if(player[0].hp==0) printf("%d wwww\n", player[0].y+8);
297         //else printf("\nplayer[0].y: %d\n", player[0].y);
298         printf("player.tx: %d", player[panswitch].tx); printf("         player.ty: %d\n", player[panswitch].ty);
299         printf("player.triggx: %d", player[panswitch].triggerx); printf("       player.triggy: %d\n", player[panswitch].triggery);
300         printf("player.hp: %d", (player[panswitch].hp));        printf("        player.q: %d", player[panswitch].q);    printf("        player.info.dir: %d", player[panswitch].info.dir);      printf("        player.d: %d ", player[panswitch].d);
301                 printf("pdir=%d\n", player[panswitch].pdir);
302         printf("tile data value at player trigger position: %d\n", mv[0].map->data[(player[panswitch].triggerx-1)+(map.width*(player[panswitch].triggery-1))]);
303 //      printf("palette offset: %d\n", paloffset/3);
304 //++++  printf("Total used: %zu\n", oldfreemem-GetFreeSize());
305 //++++  printf("Total free: %zu\n", GetFreeSize());
306 //not used now  printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");
307 //not used now  printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");
308         printf("Virtual Screen: %dx", gvar.video.page[0].width);        printf("%d\n", gvar.video.page[0].height);
309         printf("Screen: %dx", gvar.video.page[0].sw);   printf("%d\n", gvar.video.page[0].sh);
310         printf("virtual tile resolution: %dx", gvar.video.page[0].tilesw);      printf("%d\n", gvar.video.page[0].tilesh);
311         printf("tile resolution: %dx", gvar.video.page[0].tw);  printf("%d \n", gvar.video.page[0].th);
312         printf("middle tile position: %dx", gvar.video.page[0].tilemidposscreenx);      printf("%d\n", gvar.video.page[0].tilemidposscreeny);
313         printf("video memory remaining: %ld\n", gvar.video.vmem_remain);
314         printf("page ");
315         for(i=0; i<gvar.video.num_of_pages;i++)
316         {
317                 printf("        [%u]=", i);
318                 printf("(%Fp)\n", (gvar.video.page[i].data));
319         }
320         printf("mv[%u].tx: %d", pan.pn, mv[pan.pn].tx); printf("        mv[%u].ty: %d\n", pan.pn, mv[pan.pn].ty);
321         //printf("player[1].q: %d", player[1].q);       printf("        player[1].d: %d\n", player[1].d);
322         printf("\n");
323 //      printf("Screen2: %dx", gvar.video.page[1].width);       printf("%d\n", gvar.video.page[1].height);
324 //      printf("map: %dx%d\n", map.width, map.height);
325 //      printf("\n");
326 //      printf("player[0].info.x: %d", player[0].info.xaxis); printf("          player[0].info.y: %d\n", player[0].info.yaxis);
327 //      printf("player[0].info.tx: %d", player[0].info.x); printf("             player[0].info.ty: %d\n", player[0].info.y);
328         //printf("map.width=%d  map.height=%d   map.data[0]=%d\n", mv[0].map->width, mv[0].map->height, mv[0].map->data[0]);
329
330         printf("\n");
331         switch(detectcpu())
332         {
333                 case 0: cpus = "8086/8088 or 186/88"; break;
334                 case 1: cpus = "286"; break;
335                 case 2: cpus = "386 or newer"; break;
336                 default: cpus = "internal error"; break;
337         }
338         printf("detected CPU type: %s\n", cpus);
339 #ifdef MODEX
340 #ifdef FADE
341         modexFadeOn(4, dpal);
342 #endif
343 #endif
344 }