1 /* Project 16 Source Code~
2 * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123
4 * This file is part of Project 16.
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.
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.
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.
23 #include "src/lib/scroll16.h"
24 #include "src/lib/16_timer.h"
25 #include "src/lib/wcpu/wcpu.h"
28 #define MODEX //this is for mode x initiating
30 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
32 global_game_variables_t gvar;
34 player_t player[MaxPlayers];
35 //page_t screen, gvar.video.page[1], gvar.video.page[2];
39 static planar_buf_t huge *pp;
43 // word panswitch=0, panq=1, pand=0;
44 word panpagenum=0; //for panning!
47 //static int persist_aniframe = 0; /* gonna be increased to 1 before being used, so 0 is ok for default */
49 //map_view_db_t pgid[4];
52 static word paloffset=0;
53 byte *dpal, *default_pal;
59 void main(int argc, char *argv[])
61 byte *mesg=malloc(sizeof(dword));
63 if(argv[1]) bakapee = atoi(argv[1]);
66 // DOSLIB: check our environment
69 // DOSLIB: what CPU are we using?
70 // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.
71 // So this code by itself shouldn't care too much what CPU it's running on. Except that other
72 // parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for
73 // the CPU to carry out tasks. --J.C.
76 // DOSLIB: check for VGA
78 printf("VGA probe failed\n");
81 // hardware must be VGA or higher!
82 if (!(vga_state.vga_flags & VGA_IS_VGA)) {
83 printf("This program requires VGA or higher graphics hardware\n");
87 player[0].persist_aniframe=0;
89 //player[0].data = &pp;
91 printf("starting timer ");
98 fprintf(stderr, "testing map load~ ");
99 loadmap("data/test.map", &map);
101 printf("chkmap ok ");
102 fprintf(stderr, "yay map loaded~~\n");
110 //mappalptr = map.tiles->btdata->palette;
113 //++++p = bitmapLoadPcx("data/ptmp.pcx"); // load sprite
114 //npctmp = bitmapLoadPcx("ptmp1.pcx"); // load sprite
116 /* create the planar buffer */
117 ////++++ (player[0].data) = *planar_buf_from_bitmap(&p);
118 /*++++printf("load pee!! ");
119 pp = planar_buf_from_bitmap(&p);
125 IN_Default(0,&player,ctrl_Joystick);
127 /* save the palette */
130 dpal = modexNewPal();
131 default_pal = modexNewPal();
132 *default_pal = *dpal;
134 modexFadeOff(4, dpal);
138 VGAmodeX(bakapee, 1, &gvar);
139 // printf("%dx%d\n", gvar.video.page[0].sw, gvar.video.page[0].sh);
141 modexPalBlack(); //reset the palette~
144 // printf("Total used @ before palette initiation: %zu\n", oldfreemem-GetFreeSize());
145 //++++ player[0].data.offset=(paloffset/3);
146 //++++ modexPalUpdate1(&player[0].data, &paloffset, 0, 0);
147 //modexPalUpdate1(p.palette);
148 modexPalUpdate1(map.tiles->btdata->palette);
149 //printf(" %d\n", sizeof(ptmp->data));
150 //printf("1: %d\n", paloffset);
151 //++++ map.tiles->data->offset=(paloffset/3);
152 //XTmodexPalUpdate(map.tiles->data, &paloffset, 0, 0);
153 // printf("\n====\n");
154 // printf("0 paloffset= %d\n", paloffset/3);
155 // printf("====\n\n");
158 gpal = modexNewPal();
160 modexSavePalFile("data/g.pal", gpal);
161 modexPalBlack(); //so player will not see loadings~
165 /* setup camera and screen~ */
166 gvar.video.page[0] = modexDefaultPage(&gvar.video.page[0]);
167 gvar.video.page[0].width += (TILEWH*2);
168 gvar.video.page[0].height += (TILEWH*2);//+QUADWH;
169 mv[0].page = &gvar.video.page[0];
170 gvar.video.page[1] = modexNextPage(mv[0].page);
171 mv[1].page = &gvar.video.page[1];
173 gvar.video.page[2] = modexNextPageFlexibleSize(mv[1].page, gvar.video.page[0].sw, gvar.video.page[0].sh); //(352*176)+1024 is the remaining amount of memory left wwww
174 //gvar.video.page[2] = modexNextPage0(mv2.page, 320, 192); //(352*176)+1024 is the remaining amount of memory left wwww
175 mv[2].page = &gvar.video.page[2];
178 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
179 mapGoTo(&mv[0], 0, 0);
180 mapGoTo(&mv[1], 0, 0);
181 //mapGoTo(mask, 0, 0);
183 //TODO: put player in starting position of spot
184 //default player position on the viewable map
185 player[0].tx = mv[0].tx + mv[0].page->tilemidposscreenx;
186 player[0].ty = mv[0].ty + mv[0].page->tilemidposscreeny;
187 IN_initplayer(&player, 0);
189 /*npc0.tx = mv[0].tx + 1;
190 npc0.ty = mv[0].ty + 1;
191 npc0.x = npc0.tx*TILEWH;
192 npc0.y = npc0.ty*TILEWH;
193 npc0.triggerx = npc0.tx;
194 npc0.triggery = npc0.ty+1;
197 modexDrawSpriteRegion(mv[1].page, npc0.x-4, npc0.y-TILEWH, 24, 64, 24, 32, &npctmp);*/
199 modexCopyPageRegion(mv[1].page, mv[0].page, 0, 0, 0, 0, mv[0].page->width, mv[0].page->height);
201 modexClearRegion(mv[1].page, player[0].x-4, player[0].y-TILEWH, 24, 32, 15);
203 //PBUFSFUN(mv[1].page, player[0].x-4, player[0].y-TILEWH, 24, 64, 24, 32, PLAYERBMPDATA);
204 PBUFSFUN(mv[1].page, player[0].x-4, player[0].y-TILEWH, 24, 64, 24, 32, &pp);
207 modexShowPage(mv[1].page);
208 //modexClearRegion(mv[2].page, 0, 0, mv[2].page->width, mv[2].page->height, 1);
211 modexFadeOn(4, gpal);
214 while(!IN_KeyDown(sc_Escape) && player[0].hp>0)
217 IN_ReadControl(0,&player);
218 //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
219 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
220 //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
228 if((IN_KeyDown(77) && !IN_KeyDown(75) && pand == 0) || pand == 2)
230 if(pand == 0){ pand = 2; }
231 if(panq<=(TILEWH/(player[0].speed)))
238 modexShowPage(mv[0].page);
243 modexShowPage(mv[1].page);
248 modexShowPage(mv[2].page);
252 } else { panq = 1; pand = 0; }
255 if((IN_KeyDown(75) && !IN_KeyDown(77) && pand == 0) || pand == 4)
257 if(pand == 0){ pand = 4; }
258 if(panq<=(TILEWH/(player[0].speed)))
265 modexShowPage(mv[0].page);
270 modexShowPage(mv[1].page);
275 modexShowPage(mv[2].page);
279 } else { panq = 1; pand = 0; }
282 if((IN_KeyDown(72) && !IN_KeyDown(80) && pand == 0) || pand == 3)
284 if(pand == 0){ pand = 3; }
285 if(panq<=(TILEWH/(player[0].speed)))
292 modexShowPage(mv[0].page);
297 modexShowPage(mv[1].page);
302 modexShowPage(mv[2].page);
306 } else { panq = 1; pand = 0; }
309 if((IN_KeyDown(80) && !IN_KeyDown(72) && pand == 0) || pand == 1)
311 if(pand == 0){ pand = 1; }
312 if(panq<=(TILEWH/(player[0].speed)))
319 modexShowPage(mv[0].page);
324 modexShowPage(mv[1].page);
329 modexShowPage(mv[2].page);
333 } else { panq = 1; pand = 0; }
338 //the scripting stuf....
340 //if(((player[0].triggerx == TRIGGX && player[0].triggery == TRIGGY) && IN_KeyDown(0x1C))||(player[0].tx == 5 && player[0].ty == 5))
341 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))
344 for(i=800; i>=400; i--)
350 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--; }
352 //if(IN_KeyDown(0x0E)) while(1){ if(xmsmalloc(24)) break; }
353 if(IN_KeyDown(2)){ modexShowPage(mv[0].page); panpagenum=0; }
354 if(IN_KeyDown(3)){ modexShowPage(mv[1].page); panpagenum=1; }
355 if(IN_KeyDown(4)){ modexShowPage(mv[2].page); panpagenum=2; }
356 if(IN_KeyDown(25)){ modexpdump(mv[0].page); modexpdump(mv[1].page); } //p
359 if(IN_KeyDown(24)){ modexPalUpdate0(gpal); paloffset=0; modexpdump(mv[0].page); modexpdump(mv[1].page); }
361 paloffset=0; modexPalBlack(); modexPalUpdate(&player[0].data, &paloffset, 0, 0);
362 printf("1paloffset = %d\n", paloffset/3);
363 modexPalUpdate(map.tiles->data, &paloffset, 0, 0);
364 printf("2paloffset = %d\n", paloffset/3);
365 modexpdump(mv[0].page); modexpdump(mv[1].page); }
369 //if(IN_KeyDown(88)){if(!panswitch) panswitch++; else panswitch--; } //f12
371 if(IN_KeyDown(87)) //f11
373 VGAmodeX(0, 0, &gvar);
381 if(IN_KeyDown(88)) //s
383 switch(gvar.kurokku.fpscap)
386 gvar.kurokku.fpscap=1;
389 gvar.kurokku.fpscap=0;
394 //TODO fmemtest into page
395 if(IN_KeyDown(4+1)) //4
399 _fmemset(((mv[pg].page->data+4)+(16*(mv[pg].page->width/4))), 15, 4);
403 if(IN_KeyDown(10)){ modexPalOverscan(default_pal, rand()%56); modexPalUpdate1(default_pal); }
404 //if(IN_KeyDown(11)){ modexPalOverscan(default_pal, 15); }
405 if((player[0].q==1) && !(player[0].x%TILEWH==0 && player[0].y%TILEWH==0)) break; //incase things go out of sync!
408 /* fade back to text mode */
409 /* but 1st lets save the game palette~ */
413 modexSavePalFile("data/g.pal", gpal);
414 modexFadeOff(4, gpal);
416 VGAmodeX(0, 1, &gvar);
419 printf("Project 16 scroll.exe. This is just a test file!\n");
420 printf("version %s\n", VERSION);
421 printf("tx: %d\n", mv[0].tx);
422 printf("ty: %d\n", mv[0].ty);
423 printf("player[0].x: %d", player[0].x); printf(" player[0].y: %d\n", player[0].y);
424 //if(player[0].hp==0) printf("%d wwww\n", player[0].y+8);
425 //else printf("\nplayer[0].y: %d\n", player[0].y);
426 printf("player[0].tx: %d", player[0].tx); printf(" player[0].ty: %d\n", player[0].ty);
427 printf("player[0].triggx: %d", player[0].triggerx); printf(" player[0].triggy: %d\n", player[0].triggery);
428 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);
429 printf("pdir=%d\n", player[0].pdir);
430 printf("tile data value at player trigger position: %d\n", mv[0].map->data[(player[0].triggerx-1)+(map.width*(player[0].triggery-1))]);
431 // printf("palette offset: %d\n", paloffset/3);
432 //++++ printf("Total used: %zu\n", oldfreemem-GetFreeSize());
433 //++++ printf("Total free: %zu\n", GetFreeSize());
434 //not used now printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");
435 //not used now printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");
436 printf("Virtual Screen: %dx", gvar.video.page[0].width); printf("%d\n", gvar.video.page[0].height);
437 printf("Screen: %dx", gvar.video.page[0].sw); printf("%d\n", gvar.video.page[0].sh);
438 printf("tile resolution: %dx", gvar.video.page[0].tilesh); printf("%d\n", gvar.video.page[0].tilesh);
439 printf("middle tile position: %dx", gvar.video.page[0].tilemidposscreenx); printf("%d\n", gvar.video.page[0].tilemidposscreeny);
440 // printf("Screen2: %dx", gvar.video.page[1].width); printf("%d\n", gvar.video.page[1].height);
441 // printf("map: %dx%d\n", map.width, map.height);
443 // printf("player[0].info.x: %d", player[0].info.xaxis); printf(" player[0].info.y: %d\n", player[0].info.yaxis);
444 // printf("player[0].info.tx: %d", player[0].info.x); printf(" player[0].info.ty: %d\n", player[0].info.y);
445 //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]);
449 case 0: cpus = "8086/8088 or 186/88"; break;
450 case 1: cpus = "286"; break;
451 case 2: cpus = "386 or newer"; break;
452 default: cpus = "internal error"; break;
454 printf("detected CPU type: %s\n", cpus);
457 modexFadeOn(4, dpal);