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