1 /* Project 16 Source Code~
2 * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669
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/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, screen2, screen3;
37 map_view_t *bg, *spri, *mask;//, *tmp;
42 void main(int argc, char *argv[])
44 // word panswitch=0, panq=1, pand=0;
45 word panpagenum=0; //for panning!
47 //static word paloffset=0;
49 //static int persist_aniframe = 0; /* gonna be increased to 1 before being used, so 0 is ok for default */
51 //map_view_db_t pgid[4];
58 byte *mesg=malloc(sizeof(dword));
61 if(argv[1]) bakapee = atoi(argv[1]);
64 player[0].persist_aniframe=0;
67 printf("starting timer\n");
70 //extern struct inconfig inpu;
75 fprintf(stderr, "testing map load~\n");
76 loadmap("data/test.map", &map);
80 printf("chkmap ok\n");
81 fprintf(stderr, "yay map loaded~~\n");
89 mappalptr = map.tiles->data->palette;
92 player[0].data = bitmapLoadPcx("data/ptmp.pcx"); // load sprite
93 //npctmp = bitmapLoadPcx("ptmp1.pcx"); // load sprite
95 /* create the planar buffer */
96 p = planar_buf_from_bitmap(&player[0].data);
97 //0000 printf("planar buffer ok\n");
101 IN_Default(0,&player,ctrl_Joystick);
103 /* save the palette */
106 dpal = modexNewPal();
108 modexFadeOff(4, dpal);
112 VGAmodeX(bakapee, &gvar);
114 modexPalBlack(); //reset the palette~
117 // printf("Total used @ before palette initiation: %zu\n", oldfreemem-GetFreeSize());
118 //++++ player[0].data.offset=(paloffset/3);
119 //++++ modexPalUpdate(&player[0].data, &paloffset, 0, 0);
120 //printf(" %d\n", sizeof(ptmp->data));
121 //printf("1: %d\n", paloffset);
122 //++++ map.tiles->data->offset=(paloffset/3);
123 //XTmodexPalUpdate(map.tiles->data, &paloffset, 0, 0);
124 // printf("\n====\n");
125 // printf("0 paloffset= %d\n", paloffset/3);
126 // printf("====\n\n");
129 gpal = modexNewPal();
131 modexSavePalFile("data/g.pal", gpal);
132 modexPalBlack(); //so player will not see loadings~
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 = modexNextPageFlexibleSize(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;
152 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
155 //mapGoTo(mask, 0, 0);
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;*/
172 // player[0].persist_aniframe=0;
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;
182 modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 64, 24, 32, &npctmp);*/
185 oldDrawBmp(VGA, player[0].x-4, player[0].y-TILEWH, &player[0].data, 1);
187 modexDrawSpriteRegion(spri->page, player[0].x-4, player[0].y-TILEWH, 24, 64, 24, 32, &player[0].data);
190 modexClearRegion(mv[1].page, player[0].x-4, player[0].y-TILEWH, 24, 32, 15);
193 modexShowPage(spri->page);
194 modexClearRegion(mv[2].page, 0, 0, mv[2].page->width, mv[2].page->height, 1);
197 modexFadeOn(4, gpal);
200 while(!IN_KeyDown(sc_Escape) && player[0].hp>0)
203 IN_ReadControl(0,&player);
204 //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
205 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
206 //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
214 if((IN_KeyDown(77) && !IN_KeyDown(75) && pand == 0) || pand == 2)
216 if(pand == 0){ pand = 2; }
217 if(panq<=(TILEWH/(player[0].speed)))
224 modexShowPage(bg->page);
229 modexShowPage(spri->page);
234 modexShowPage(mask->page);
238 } else { panq = 1; pand = 0; }
241 if((IN_KeyDown(75) && !IN_KeyDown(77) && pand == 0) || pand == 4)
243 if(pand == 0){ pand = 4; }
244 if(panq<=(TILEWH/(player[0].speed)))
251 modexShowPage(bg->page);
256 modexShowPage(spri->page);
261 modexShowPage(mask->page);
265 } else { panq = 1; pand = 0; }
268 if((IN_KeyDown(72) && !IN_KeyDown(80) && pand == 0) || pand == 3)
270 if(pand == 0){ pand = 3; }
271 if(panq<=(TILEWH/(player[0].speed)))
278 modexShowPage(bg->page);
283 modexShowPage(spri->page);
288 modexShowPage(mask->page);
292 } else { panq = 1; pand = 0; }
295 if((IN_KeyDown(80) && !IN_KeyDown(72) && pand == 0) || pand == 1)
297 if(pand == 0){ pand = 1; }
298 if(panq<=(TILEWH/(player[0].speed)))
305 modexShowPage(bg->page);
310 modexShowPage(spri->page);
315 modexShowPage(mask->page);
319 } else { panq = 1; pand = 0; }
324 //the scripting stuf....
326 //if(((player[0].triggerx == TRIGGX && player[0].triggery == TRIGGY) && IN_KeyDown(0x1C))||(player[0].tx == 5 && player[0].ty == 5))
327 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))
330 for(i=800; i>=400; i--)
336 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--; }
338 //if(IN_KeyDown(0x0E)) while(1){ if(xmsmalloc(24)) break; }
339 if(IN_KeyDown(2)){ modexShowPage(bg->page); panpagenum=0; }
340 if(IN_KeyDown(3)){ modexShowPage(spri->page); panpagenum=1; }
341 if(IN_KeyDown(4)){ modexShowPage(mask->page); panpagenum=2; }
342 if(IN_KeyDown(25)){ pdump(bg->page); pdump(spri->page); } //p
345 if(IN_KeyDown(24)){ modexPalUpdate0(gpal); paloffset=0; pdump(bg->page); pdump(spri->page); }
347 paloffset=0; modexPalBlack(); modexPalUpdate(&player[0].data, &paloffset, 0, 0);
348 printf("1paloffset = %d\n", paloffset/3);
349 modexPalUpdate(map.tiles->data, &paloffset, 0, 0);
350 printf("2paloffset = %d\n", paloffset/3);
351 pdump(bg->page); pdump(spri->page); }
355 //if(IN_KeyDown(88)){if(!panswitch) panswitch++; else panswitch--; } //f12
357 if(IN_KeyDown(87)) //f11
367 if(IN_KeyDown(88)) //s
369 switch(gvar.kurokku.fpscap)
372 gvar.kurokku.fpscap=1;
375 gvar.kurokku.fpscap=0;
380 //TODO fmemtest into page
381 if(IN_KeyDown(4+1)) //4
385 _fmemset(((mv[pg].page->data+4)+(16*(mv[pg].page->width/4))), 15, 4);
388 if((player[0].q==1) && !(player[0].x%TILEWH==0 && player[0].y%TILEWH==0)) break; //incase things go out of sync!
391 /* fade back to text mode */
392 /* but 1st lets save the game palette~ */
396 modexSavePalFile("data/g.pal", gpal);
397 modexFadeOff(4, gpal);
402 printf("Project 16 scroll.exe. This is just a test file!\n");
403 printf("version %s\n", VERSION);
404 printf("tx: %d\n", bg->tx);
405 printf("ty: %d\n", bg->ty);
406 printf("player[0].x: %d", player[0].x); printf(" player[0].y: %d\n", player[0].y);
407 //if(player[0].hp==0) printf("%d wwww\n", player[0].y+8);
408 //else printf("\nplayer[0].y: %d\n", player[0].y);
409 printf("player[0].tx: %d", player[0].tx); printf(" player[0].ty: %d\n", player[0].ty);
410 printf("player[0].triggx: %d", player[0].triggerx); printf(" player[0].triggy: %d\n", player[0].triggery);
411 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);
412 printf("tile data value at player trigger position: %d\n", bg->map->data[(player[0].triggerx-1)+(map.width*(player[0].triggery-1))]);
413 // printf("palette offset: %d\n", paloffset/3);
414 //++++ printf("Total used: %zu\n", oldfreemem-GetFreeSize());
415 //++++ printf("Total free: %zu\n", GetFreeSize());
416 //not used now printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");
417 //not used now printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");
418 // printf("Screen: %dx", screen.width); printf("%d\n", screen.height);
419 // printf("Screen2: %dx", screen2.width); printf("%d\n", screen2.height);
420 // printf("map: %dx%d\n", map.width, map.height);
422 // printf("player[0].info.x: %d", player[0].info.xaxis); printf(" player[0].info.y: %d\n", player[0].info.yaxis);
423 // printf("player[0].info.tx: %d", player[0].info.x); printf(" player[0].info.ty: %d\n", player[0].info.y);
424 //printf("map.width=%d map.height=%d map.data[0]=%d\n", bg->map->width, bg->map->height, bg->map->data[0]);
428 case 0: cpus = "8086/8088 or 186/88"; break;
429 case 1: cpus = "286"; break;
430 case 2: cpus = "386 or newer"; break;
431 default: cpus = "internal error"; break;
433 printf("detected CPU type: %s\n", cpus);
436 modexFadeOn(4, dpal);