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/mapread.h"
25 #include "src/lib/wcpu/wcpu.h"
26 //====#include "src\lib\ems.c"
28 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
32 // word panswitch=0, panq=1, pand=0;
33 word panpagenum=0; //for panning!
35 static word paloffset=0;
38 //static int persist_aniframe = 0; /* gonna be increased to 1 before being used, so 0 is ok for default */
39 page_t screen, screen2, screen3;
42 map_view_t *bg, *spri, *mask;//, *tmp;
43 //map_view_db_t pgid[4];
47 player_t player[MaxPlayers];
49 player[0].persist_aniframe=0;
51 //extern struct inconfig inpu;
58 printf("Expanded memory is not present\n");
64 printf("Expanded memory manager is not present\n");
68 emsavail = emmavail();
71 printf("Expanded memory manager error\n");
74 printf("There are %ld pages available\n",emsavail);
76 if((emmhandle = emmalloc(emsavail)) < 0)
78 printf("Insufficient pages available\n");
83 //printf("Total used @ before map load: %zu\n", oldfreemem-GetFreeSize());
84 printf("Total free @ before map load: %zu\n", GetFreeSize());
85 printf("Total far free @ before map load: %zu\n", GetFarFreeSize());
87 //0000 fprintf(stderr, "testing~\n");
88 // loadmap("data/test.map", &map);
89 //0000 fprintf(stderr, "yay map loaded~~\n");
90 //---- map = allocMap(map.width,map.height); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be drawn properly
91 //if(isEMS()) printf("%d tesuto\n", coretotalEMS());
99 mappalptr = map.tiles->data->palette;
101 //0000 printf("Total used @ before image loading: %zu\n", oldfreemem-GetFreeSize());
102 player[0].data = bitmapLoadPcx("data/ptmp.pcx"); // load sprite
103 //npctmp = bitmapLoadPcx("ptmp1.pcx"); // load sprite
105 /* create the planar buffer */
106 //0000 printf("Total used @ before planar buffer creation: %zu\n", oldfreemem-GetFreeSize());
107 p = planar_buf_from_bitmap(&player[0].data);
108 //0000 printf("Total used @ after planar buffer creation: %zu\n", oldfreemem-GetFreeSize());
113 mm.length=sizeof(map);
115 mm.sourceOff=(long)↦
119 ist = move_emem(&mm);
120 printf("%d\n", coretotalEMS());
121 if(!ist){ dealloc_emem(emmhandle); exit(5); }
122 //printf("%d\n", emmhandle);
130 mm.sourceOff=(long)&ptmp;
134 ist = move_emem(&mm);
135 printf("%d\n", coretotalEMS());
136 if(!ist){ dealloc_emem(emmhandle); exit(5); }
137 //printf("%d\n", emmhandle);
143 IN_Default(0,&player,ctrl_Joystick);
145 /* save the palette */
146 dpal = modexNewPal();
148 modexFadeOff(4, dpal);
151 modexPalBlack(); //reset the palette~
152 // printf("Total used @ before palette initiation: %zu\n", oldfreemem-GetFreeSize());
153 player[0].data.offset=(paloffset/3);
154 modexPalUpdate(&player[0].data, &paloffset, 0, 0);
155 //printf(" %d\n", sizeof(ptmp->data));
156 //printf("1: %d\n", paloffset);
157 map.tiles->data->offset=(paloffset/3);
158 //XTmodexPalUpdate(map.tiles->data, &paloffset, 0, 0);
160 printf("0 paloffset= %d\n", paloffset/3);
162 gpal = modexNewPal();
164 modexSavePalFile("data/g.pal", gpal);
165 modexPalBlack(); //so player will not see loadings~
167 /* setup camera and screen~ */
168 screen = modexDefaultPage();
169 screen.width += (TILEWH*2);
170 screen.height += (TILEWH*2);//+QUADWH;
171 mv[0].page = &screen;
172 screen2 = modexNextPage(mv[0].page);
173 mv[1].page = &screen2;
174 screen3 = modexNextPage0(mv[1].page, 320, 240); //(352*176)+1024 is the remaining amount of memory left wwww
175 //screen3 = modexNextPage0(mv2.page, 320, 192); //(352*176)+1024 is the remaining amount of memory left wwww
176 mv[2].page = &screen3;
183 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
186 //mapGoTo(mask, 0, 0);
188 //TODO: put player in starting position of spot
189 //default player position on the viewable map
190 player[0].tx = bg->tx + 10;
191 player[0].ty = bg->ty + 8;
192 player[0].x = player[0].tx*TILEWH;
193 player[0].y = player[0].ty*TILEWH;
194 player[0].triggerx = player[0].tx;
195 player[0].triggery = player[0].ty+1;
197 player[0].info.dir=2;
200 /*npc0.tx = bg->tx + 1;
201 npc0.ty = bg->ty + 1;
202 npc0.x = npc0.tx*TILEWH;
203 npc0.y = npc0.ty*TILEWH;
204 npc0.triggerx = npc0.tx;
205 npc0.triggery = npc0.ty+1;
208 modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 64, 24, 32, &npctmp);*/
209 modexDrawSpriteRegion(spri->page, player[0].x-4, player[0].y-TILEWH, 24, 64, 24, 32, &player[0].data);
211 modexShowPage(spri->page);
212 // printf("Total used @ before loop: %zu\n", oldfreemem-GetFreeSize());
213 modexClearRegion(mv[2].page, 0, 0, mv[2].page->width, mv[2].page->height, 1);
214 modexFadeOn(4, gpal);
215 while(!IN_KeyDown(sc_Escape) && player[0].hp>0)
\r
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(bg->page);
243 modexShowPage(spri->page);
248 modexShowPage(mask->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(bg->page);
270 modexShowPage(spri->page);
275 modexShowPage(mask->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(bg->page);
297 modexShowPage(spri->page);
302 modexShowPage(mask->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(bg->page);
324 modexShowPage(spri->page);
329 modexShowPage(mask->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(((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))
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(bg->page); panpagenum=0; }
354 if(IN_KeyDown(3)){ modexShowPage(spri->page); panpagenum=1; }
355 if(IN_KeyDown(4)){ modexShowPage(mask->page); panpagenum=2; }
356 if(IN_KeyDown(25)){ pdump(bg->page); pdump(spri->page); } //p
357 if(IN_KeyDown(24)){ modexPalUpdate0(gpal); paloffset=0; pdump(bg->page); pdump(spri->page); }
359 paloffset=0; modexPalBlack(); modexPalUpdate(&player[0].data, &paloffset, 0, 0);
360 printf("1paloffset = %d\n", paloffset/3);
361 modexPalUpdate(map.tiles->data, &paloffset, 0, 0);
362 printf("2paloffset = %d\n", paloffset/3);
363 pdump(bg->page); pdump(spri->page); }
365 //if(IN_KeyDown(88)){if(!panswitch) panswitch++; else panswitch--; } //f12
367 if(IN_KeyDown(87)) //f11
378 if((player[0].q==1) && !(player[0].x%TILEWH==0 && player[0].y%TILEWH==0)) break; //incase things go out of sync!
382 /* fade back to text mode */
383 /* but 1st lets save the game palette~ */
385 modexSavePalFile("data/g.pal", gpal);
386 modexFadeOff(4, gpal);
389 printf("Project 16 scroll.exe\n");
390 printf("tx: %d\n", bg->tx);
391 printf("ty: %d\n", bg->ty);
392 printf("player[0].x: %d", player[0].x); printf(" player[0].y: %d\n", player[0].y);
393 //if(player[0].hp==0) printf("%d wwww\n", player[0].y+8);
394 //else printf("\nplayer[0].y: %d\n", player[0].y);
395 printf("player[0].tx: %d", player[0].tx); printf(" player[0].ty: %d\n", player[0].ty);
396 printf("player[0].triggx: %d", player[0].triggerx); printf(" player[0].triggy: %d\n", player[0].triggery);
397 printf("player[0].hp: %d", (player[0].hp)); printf(" player[0].q: %d", player[0].q); printf(" player[0].info.dir: %d\n", player[0].info.dir);
398 printf("tile data value at player trigger position: %d\n", bg->map->data[(player[0].triggerx-1)+(map.width*(player[0].triggery-1))]);
399 printf("palette offset: %d\n", paloffset/3);
400 //++++ printf("Total used: %zu\n", oldfreemem-GetFreeSize());
401 //++++ printf("Total free: %zu\n", GetFreeSize());
402 printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");
403 printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");
404 printf("Screen: %dx", screen.width); printf("%d\n", screen.height);
405 printf("Screen2: %dx", screen2.width); printf("%d\n", screen2.height);
406 printf("map: %dx%d\n", map.width, map.height);
407 //printf("map.width=%d map.height=%d map.data[0]=%d\n", bg->map->width, bg->map->height, bg->map->data[0]);
413 //emmclose(emmhandle);
416 case 0: cpus = "8086/8088 or 186/88"; break;
417 case 1: cpus = "286"; break;
418 case 2: cpus = "386 or newer"; break;
419 default: cpus = "internal error"; break;
421 printf("detected CPU type: %s\n", cpus);
422 modexFadeOn(4, dpal);