1 /* Project 16 Source Code~
\r
2 * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
\r
4 * This file is part of Project 16.
\r
6 * Project 16 is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Project 16 is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
\r
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
\r
19 * Fifth Floor, Boston, MA 02110-1301 USA.
\r
23 #include "src/lib/scroll16.h"
\r
24 #include "src/lib/16_timer.h"
\r
25 #include "src/lib/wcpu/wcpu.h"
\r
28 #define MODEX //this is for mode x initiating
\r
30 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
\r
32 global_game_variables_t gvar;
\r
34 player_t player[MaxPlayers];
\r
36 //word pn=0; //i forgot ww
\r
41 boolean panswitch=0;
\r
42 //extern boolean pageflipflop=1;
\r
45 //static int persist_aniframe = 0; /* gonna be increased to 1 before being used, so 0 is ok for default */
\r
47 //map_view_db_t pgid[4];
\r
50 static word paloffset=0;
\r
57 void main(int argc, char *argv[])
\r
59 byte *mesg=malloc(sizeof(dword));
\r
61 if(argv[1]) bakapee = atoi(argv[1]);
\r
64 // DOSLIB: check our environment
\r
67 // DOSLIB: what CPU are we using?
\r
68 // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.
\r
69 // So this code by itself shouldn't care too much what CPU it's running on. Except that other
\r
70 // parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for
\r
71 // the CPU to carry out tasks. --J.C.
\r
74 // DOSLIB: check for VGA
\r
76 printf("VGA probe failed\n");
\r
79 // hardware must be VGA or higher!
\r
80 if (!(vga_state.vga_flags & VGA_IS_VGA)) {
\r
81 printf("This program requires VGA or higher graphics hardware\n");
\r
85 if (_DEBUG_INIT() == 0) {
\r
87 printf("WARNING: Failed to initialize DEBUG output\n");
\r
90 _DEBUG("Serial debug output started\n"); // NTS: All serial output must end messages with newline, or DOSBox-X will not emit text to log
\r
91 _DEBUGF("Serial debug output printf test %u %u %u\n",1U,2U,3U);
\r
97 /* create the map */
\r
98 fprintf(stderr, "testing map load~ ");
\r
99 loadmap("data/test.map", &map);
\r
101 printf("chkmap ok ");
\r
102 fprintf(stderr, "yay map loaded~~\n");
\r
104 /* draw the tiles */
\r
107 //mappalptr = map.tiles->btdata->palette;
\r
110 player[0].data = malloc(48*128); //TODO use exmm
\r
111 *player[0].data = bitmapLoadPcx("data/chikyuu.pcx"); // load sprite
\r
113 /* create the planar buffer */
\r
114 ////++++ (player[0].data) = *planar_buf_from_bitmap(&p);
\r
115 /*++++printf("load pee!! ");
\r
116 pp = planar_buf_from_bitmap(&p);
\r
117 printf("done!\n");*/
\r
122 IN_Default(0,&player,ctrl_Joystick);
\r
123 //IN_Default(1,&player,ctrl_Joystick);
\r
125 /* save the palette */
\r
128 dpal = modexNewPal();
\r
129 modexPalSave(dpal);
\r
130 modexFadeOff(4, dpal);
\r
134 VGAmodeX(bakapee, 1, &gvar);
\r
135 // printf("%dx%d\n", gvar.video.page[0].sw, gvar.video.page[0].sh);
\r
137 modexPalBlack(); //reset the palette~
\r
140 // printf("Total used @ before palette initiation: %zu\n", oldfreemem-GetFreeSize());
\r
141 //++++ player[0].data.offset=(paloffset/3);
\r
142 //++++ modexPalUpdate1(&player[0].data, &paloffset, 0, 0);
\r
143 modexPalUpdate1(player[0].data->palette);
\r
144 //++++0000 modexPalUpdate1(map.tiles->btdata->palette);
\r
145 //printf(" %d\n", sizeof(ptmp->data));
\r
146 //printf("1: %d\n", paloffset);
\r
147 //++++ map.tiles->data->offset=(paloffset/3);
\r
148 //XTmodexPalUpdate(map.tiles->data, &paloffset, 0, 0);
\r
149 // printf("\n====\n");
\r
150 // printf("0 paloffset= %d\n", paloffset/3);
\r
151 // printf("====\n\n");
\r
154 gpal = modexNewPal();
\r
155 modexPalSave(gpal);
\r
156 modexSavePalFile("data/g.pal", gpal);
\r
157 modexPalBlack(); //so player will not see loadings~
\r
161 /* setup camera and screen~ */
\r
162 modexHiganbanaPageSetup(&gvar.video);
\r
163 for(i=0;i<gvar.video.num_of_pages;i++)
\r
165 mv[i].page = &gvar.video.page[i];
\r
167 mv[i].video = &gvar.video;
\r
171 /* set up paging */
\r
172 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
\r
174 //_fmemcpy(mv[1].page->data, mv[0].page->data, mv[0].page->pagesize);
\r
176 //TODO: put player in starting position of spot
\r
177 //default player position on the viewable map
\r
178 player[0].tx = mv[0].tx + mv[0].page->tilemidposscreenx;
\r
179 player[0].ty = mv[0].ty + mv[0].page->tilemidposscreeny;
\r
180 IN_initplayer(&player, 0);
\r
181 //IN_initplayer(&player, 1);
\r
184 modexClearRegion(mv[0].page, player[0].x, player[0].y-TILEWH, 16, 32, 15);
\r
185 //modexClearRegion(mv[1].page, player[0].x, player[0].y-TILEWH, 16, 32, 15);
\r
187 //PBUFSFUN(mv[1].page, player[0].x, player[0].y-TILEWH, 16, 64, 24, 32, PLAYERBMPDATA);
\r
188 PBUFSFUN(mv[0].page, player[0].x, player[0].y-TILEWH, 16, 64, 16, 32, player[0].data);
\r
191 if(!pageflipflop) modexShowPage(mv[1].page);
\r
192 else modexShowPage(mv[0].page);//!(gvar.video.p)
\r
193 shinku_fps_indicator_page = 0; // we're on page 1 now, shinku(). follow along please or it will not be visible.
\r
196 // modexClearRegion(mv[2].page, 0, 0, mv[2].page->width, mv[2].page->height, 47);
\r
197 // modexClearRegion(mv[3].page, 0, 0, mv[3].page->width, mv[3].page->height, 45);
\r
199 // unsigned int k,j,o;
\r
200 // /* fill screen with a distinctive pattern */
\r
201 // for (k=0;k < vga_state.vga_width;k++) {
\r
203 // vga_write_sequencer(0x02/*map mask*/,1 << (k&3));
\r
204 // for (j=0;j < vga_state.vga_height;j++,o += vga_state.vga_stride)
\r
205 // vga_state.vga_graphics_ram[o] = (k^j)&15; // VRL samples put all colors in first 15!
\r
208 modexClearRegion(mv[3].page, 0, 128, 24, 36, 15);
\r
212 modexFadeOn(4, gpal);
\r
215 while(!IN_KeyDown(sc_Escape) && player[0].hp>0)
\r
218 //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
\r
219 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
\r
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
\r
223 IN_ReadControl(0,&player);
\r
225 walk(mv, player, 0);
\r
227 panpagemanual(mv, player, 0);
\r
228 //printf(" player[0].q: %d", player[0].q); printf(" player[0].d: %d\n", player[0].d);
\r
231 //the scripting stuff....
\r
232 //if(((player[0].triggerx == TRIGGX && player[0].triggery == TRIGGY) && IN_KeyDown(0x1C))||(player[0].tx == 5 && player[0].ty == 5))
\r
233 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))
\r
236 for(i=800; i>=400; i--)
\r
242 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--; }
\r
244 if(IN_KeyDown(2)){ modexShowPage(mv[0].page); pan.pn=0; }
\r
245 if(IN_KeyDown(3)){ modexShowPage(mv[1].page); pan.pn=1; }
\r
246 if(IN_KeyDown(4)){ modexShowPage(mv[2].page); pan.pn=2; }
\r
247 if(IN_KeyDown(4+1)){ modexShowPage(mv[3].page); pan.pn=3; }
\r
248 if(IN_KeyDown(25)){ modexpdump(mv[0].page); modexpdump(mv[1].page);
\r
253 if(IN_KeyDown(24)){ modexPalUpdate0(gpal); paloffset=0; modexpdump(mv[0].page); modexpdump(mv[1].page); IN_UserInput(1,1); }
\r
254 if(IN_KeyDown(22)){
\r
255 paloffset=0; modexPalBlack(); modexPalUpdate(player[0].data, &paloffset, 0, 0);
\r
256 printf("1paloffset = %d\n", paloffset/3);
\r
257 modexPalUpdate(map.tiles->data, &paloffset, 0, 0);
\r
258 printf("2paloffset = %d\n", paloffset/3);
\r
259 modexpdump(mv[0].page); modexpdump(mv[1].page);
\r
265 if(IN_KeyDown(88)){panswitch=!panswitch; IN_UserInput(1,1);} //f12
\r
266 if(IN_KeyDown(87)) //f11
\r
268 pageflipflop=!pageflipflop;
\r
270 // VGAmodeX(0, 0, &gvar);
\r
278 if(IN_KeyDown(68)) //f10
\r
280 gvar.kurokku.fpscap=!gvar.kurokku.fpscap;
\r
283 if(IN_KeyDown(67)) //f9
\r
285 modexClearRegion(mv[1].page, 0, 0, mv[1].page->width, mv[1].page->height, 2);
\r
286 modexClearRegion(mv[2].page, 0, 0, mv[2].page->width, mv[2].page->height, 3);
\r
287 modexClearRegion(mv[3].page, 0, 0, mv[3].page->width, mv[3].page->height, 4);
\r
288 modexClearRegion(mv[3].page, 0, 0, 20, 36, 15);
\r
289 //IN_UserInput(1,1);
\r
291 if(IN_KeyDown(66)) //f8
\r
293 // modexDrawSprite(mv[0].page, 16, 16, p);
\r
294 modexDrawSprite(mv[0].page, 32+48, 16, (player[0].data));
\r
296 //TODO fmemtest into page
\r
297 /*if(IN_KeyDown(4+1)) //4
\r
300 SELECT_ALL_PLANES();
\r
301 _fmemset(((mv[pg].page->data+4)+(16*(mv[pg].page->width/4))), 15, 4);
\r
305 if(IN_KeyDown(10)){ modexPalOverscan(rand()%56); modexPalUpdate1(dpal); IN_UserInput(1,1); }
\r
306 //if(IN_KeyDown(11)){ modexPalOverscan(15); }
\r
307 if((player[0].q==1) && !(player[0].x%TILEWH==0 && player[0].y%TILEWH==0)) break; //incase things go out of sync!
\r
310 /* fade back to text mode */
\r
311 /* but 1st lets save the game palette~ */
\r
314 modexPalSave(gpal);
\r
315 modexSavePalFile("data/g.pal", gpal);
\r
316 modexFadeOff(4, gpal);
\r
318 VGAmodeX(0, 1, &gvar);
\r
321 printf("\nProject 16 scroll.exe. This is just a test file!\n");
\r
322 printf("version %s\n", VERSION);
\r
323 printf("tx: %d ", mv[0].tx);
\r
324 printf("ty: %d\n", mv[0].ty);
\r
326 printf("player vars:\n");
\r
327 printf(" x: %d", player[0].x); printf(" y: %d\n", player[0].y);
\r
328 //if(player[0].hp==0) printf("%d wwww\n", player[0].y+8);
\r
329 //else printf("\nplayer[0].y: %d\n", player[0].y);
\r
330 printf(" tx: %d", player[0].tx); printf(" ty: %d\n", player[0].ty);
\r
331 printf(" triggx: %d", player[0].triggerx); printf(" triggy: %d\n", player[0].triggery);
\r
332 printf(" hp: %d", (player[0].hp)); printf(" q: %d", player[0].q); printf(" player.info.dir: %d", player[0].info.dir); printf(" player.d: %d ", player[0].d);
\r
333 printf(" pdir=%d\n", player[0].pdir);
\r
334 printf(" tile data value at player trigger position: %d\n\n", mv[0].map->data[(player[0].triggerx-1)+(map.width*(player[0].triggery-1))]);
\r
335 // printf("palette offset: %d\n", paloffset/3);
\r
336 //++++ printf("Total used: %zu\n", oldfreemem-GetFreeSize());
\r
337 //++++ printf("Total free: %zu\n", GetFreeSize());
\r
338 //not used now printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");
\r
339 //not used now printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");
\r
340 printf("Virtual Screen: %dx", gvar.video.page[0].width); printf("%d ", gvar.video.page[0].height);
\r
341 printf("Screen: %dx", gvar.video.page[0].sw); printf("%d\n", gvar.video.page[0].sh);
\r
342 printf("virtual tile resolution: %dx", gvar.video.page[0].tilesw); printf("%d ", gvar.video.page[0].tilesh);
\r
343 printf("tile resolution: %dx", gvar.video.page[0].tw); printf("%d\n", gvar.video.page[0].th);
\r
344 printf("middle tile position: %dx", gvar.video.page[0].tilemidposscreenx); printf("%d\n", gvar.video.page[0].tilemidposscreeny);
\r
345 modexprintmeminfo(&gvar.video);
\r
346 //printf("mv[%u].tx: %d", pan.pn, mv[pan.pn].tx); printf(" mv[%u].ty: %d ", pan.pn, mv[pan.pn].ty);
\r
347 printf("gvar.video.p=%u ", gvar.video.p); printf("gvar.video.r=%u ", gvar.video.r);
\r
348 printf("pageflipflop=%u\n", pageflipflop);
\r
349 //0000printf("\ngvar.video.tickclk=%f\n", gvar.video.tickclk);
\r
350 //0000printf("gvar.video.clk=%f", gvar.video.clk);
\r
352 //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]);
\r
355 switch(detectcpu())
\r
357 case 0: cpus = "8086/8088 or 186/88"; break;
\r
358 case 1: cpus = "286"; break;
\r
359 case 2: cpus = "386 or newer"; break;
\r
360 default: cpus = "internal error"; break;
\r
362 printf("detected CPU type: %s\n", cpus);
\r
365 modexFadeOn(4, dpal);
\r