+/* Project 16 Source Code~\r
+ * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
+ *\r
+ * This file is part of Project 16.\r
+ *\r
+ * Project 16 is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * Project 16 is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>, or\r
+ * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
+ * Fifth Floor, Boston, MA 02110-1301 USA.\r
+ *\r
+ */\r
+\r
+#include "src/lib/16_scr.h"\r
+#include "src/lib/16_timer.h"\r
+#include "src/lib/wcpu/wcpu.h"\r
+#include "src/lib/16render.h"\r
+#include "src/lib/16_dbg.h"\r
+\r
+#define MODEXZ\r
+\r
+//TODO: known issues the array dependent mv stuff and player arrays\r
+static map_t map;\r
+player_t player[MaxPlayers];\r
+map_view_t mv[4];\r
+float t;\r
+sword bakapee;\r
+pan_t pan;\r
+//debugswitches\r
+boolean panswitch=0,baka=0;\r
+//extern boolean pageflipflop=1;\r
+unsigned int i;\r
+const char *cpus;\r
+//static int persist_aniframe = 0; /* gonna be increased to 1 before being used, so 0 is ok for default */\r
+\r
+//map_view_db_t pgid[4];\r
+word pg;\r
+#ifdef FADE\r
+static word paloffset=0;\r
+byte *dpal;\r
+#endif\r
+byte *gpal;\r
+byte *ptr;\r
+memptr pal;\r
+\r
+void main(int argc, char *argv[])\r
+{\r
+ static global_game_variables_t gvar;\r
+ if(argv[1]) bakapee = atoi(argv[1]);\r
+ else bakapee = 1;\r
+\r
+ Startup16(&gvar);\r
+\r
+ pan.pn=0;\r
+ // OK, this one takes hellova time and needs to be done in farmalloc or MM_...\r
+ //IN CA i think you use CAL_SetupGrFile but i do think we should work together on this part --sparky4\r
+ player[0].ent = malloc(sizeof(entity_t));\r
+ player[0].ent->spri = malloc(sizeof(struct sprite));\r
+ player[0].ent->spri->spritesheet = malloc(sizeof(struct vrs_container));\r
+\r
+ // create the map\r
+ fprintf(stderr, "testing map load~ ");\r
+ loadmap("data/test.map", &map);\r
+ chkmap(&map, 0);\r
+ printf("chkmap ok ");\r
+ fprintf(stderr, "yay map loaded~~\n");\r
+\r
+ // data\r
+ read_vrs(&gvar, "data/spri/chikyuu.vrs", player[0].ent->spri->spritesheet);\r
+\r
+ // input!\r
+ IN_Default(0, &player,ctrl_Keyboard1);\r
+\r
+ // save the palette\r
+#ifdef FADE\r
+ dpal = modexNewPal();\r
+ modexPalSave(dpal);\r
+ modexFadeOff(4, dpal);\r
+#endif\r
+ textInit();\r
+ VGAmodeX(bakapee, 1, &gvar);\r
+#ifdef MODEXZ\r
+#ifdef FADE\r
+ modexPalBlack(); //reset the palette~\r
+ CA_LoadFile("data/spri/chikyuu.pal", &pal, &gvar);\r
+ modexPalUpdate1(pal);\r
+ gpal = modexNewPal();\r
+ modexPalSave(gpal);\r
+ modexSavePalFile("data/g.pal", gpal);\r
+ modexPalBlack(); //so player will not see loadings~\r
+#endif\r
+\r
+ // setup camera and screen~\r
+ modexHiganbanaPageSetup(&gvar.video);\r
+ for(i=0;i<gvar.video.num_of_pages;i++)\r
+ {\r
+ mv[i].page = &gvar.video.page[i];\r
+ mv[i].map = ↦\r
+ mv[i].video = &gvar.video;\r
+ mv[i].pan = &pan;\r
+ }\r
+ player[0].ent->spri->x = player[0].ent->spri->y = 20;\r
+\r
+ // set up paging\r
+ //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen\r
+ mapGoTo(mv, 0, 0);\r
+#endif\r
+\r
+ //TODO: put player in starting position of spot\r
+ //default player position on the viewable map\r
+ player[0].tx = mv[0].tx + mv[0].page->tilemidposscreenx;\r
+ player[0].ty = mv[0].ty + mv[0].page->tilemidposscreeny;\r
+ IN_initplayer(&player, 0);\r
+\r
+ i = set_anim_by_id(player[0].ent->spri, 11);\r
+ print_anim_ids(player[0].ent->spri);\r
+ if (i == -1)\r
+ {\r
+#ifdef FADE\r
+ modexFadeOff(4, gpal);\r
+#endif\r
+ Quit(&gvar, "Wrong");\r
+#ifdef FADE\r
+ modexFadeOn(4, dpal);\r
+#endif\r
+ exit(-4);\r
+ }\r
+ //++++animate_spri(&(player[0].ent->spri));\r
+\r
+ modexShowPage(mv[0].page);//!(gvar.video.p)\r
+ shinku_fps_indicator_page = 0; // we're on page 1 now, shinku(). follow along please or it will not be visible.\r
+#ifdef FADE\r
+ modexFadeOn(4, gpal);\r
+#endif\r
+ strcpy(global_temp_status_text, "press enter for the loop of zcroll\nescape to quit");\r
+ modexprint(&gvar.video.page[0], 144, 72, 1, 7, 0, global_temp_status_text);\r
+ while(!IN_KeyDown(sc_Enter)){ if(IN_KeyDown(sc_Escape)) goto quit; } IN_UserInput(1,1); //wwww\r
+ while(!IN_KeyDown(sc_Escape))// && player[0].hp>0)\r
+ {\r
+ shinku(&gvar);\r
+ //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square\r
+ //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction\r
+ //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
+\r
+ //player movement\r
+ IN_ReadControl(0, &player);\r
+ if(!panswitch){\r
+ ZC_walk(player[0].ent, mv);\r
+ //walk(mv, &player, 0);\r
+ }\r
+\r
+ //the scripting stuff....\r
+/* 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
+ {\r
+ short i;\r
+ for(i=800; i>=400; i--)\r
+ {\r
+ sound(i);\r
+ }\r
+ nosound();\r
+ }\r
+ 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
+*/ //debugging binds!\r
+ if(IN_KeyDown(2)){ modexShowPage(mv[0].page); pan.pn=0; }\r
+ if(IN_KeyDown(25)){ modexpdump(mv[0].page);\r
+ IN_UserInput(1,1);\r
+ } //p\r
+#ifdef FADE\r
+ if(IN_KeyDown(24)){ modexPalUpdate0(gpal); paloffset=0; modexpdump(mv[0].page); IN_UserInput(1,1); }\r
+ if(IN_KeyDown(22)){\r
+ printf("2paloffset = %d\n", paloffset/3);\r
+ IN_UserInput(1,1);\r
+ }\r
+#endif\r
+\r
+ //pan switch\r
+ if(IN_KeyDown(88)){panswitch=!panswitch; IN_UserInput(1,1);} //f12\r
+ if(IN_KeyDown(87)) //f11\r
+ {\r
+ pageflipflop=!pageflipflop;\r
+ IN_UserInput(1,1);\r
+ }\r
+ if(IN_KeyDown(68)) //f10\r
+ {\r
+ gvar.kurokku.fpscap=!gvar.kurokku.fpscap;\r
+ IN_UserInput(1,1);\r
+ }\r
+ if(IN_KeyDown(67)) //f9\r
+ {\r
+ modexClearRegion(mv[0].page, 0, 0, mv[0].page->width, mv[0].page->height, 2);\r
+ }\r
+ if(IN_KeyDown(66)) //f8\r
+ {\r
+ // modexDrawSprite(mv[0].page, 16, 16, p);\r
+ modexDrawSprite(mv[0].page, 32+48, 16, (player[0].data));\r
+ }\r
+ //TODO fmemtest into page\r
+ /*if(IN_KeyDown(4+1)) //4\r
+ {\r
+ pg=1;\r
+ SELECT_ALL_PLANES();\r
+ _fmemset(((mv[pg].page->data+4)+(16*(mv[pg].page->width/4))), 15, 4);\r
+ }*/\r
+\r
+ //9\r
+#ifdef FADE\r
+ if(IN_KeyDown(10)){ modexPalOverscan(rand()%56); modexPalUpdate1(dpal); IN_UserInput(1,1); }\r
+ //if(IN_KeyDown(11)){ modexPalOverscan(15); }\r
+#endif\r
+ if((player[0].q==1) && !(player[0].x%TILEWH==0 && player[0].y%TILEWH==0)) break; //incase things go out of sync!\r
+ player[0].hp = 0;\r
+ }\r
+\r
+ /* fade back to text mode */\r
+ /* but 1st lets save the game palette~ */\r
+ quit:\r
+#ifdef FADE\r
+ modexPalSave(gpal);\r
+ modexSavePalFile("data/g.pal", gpal);\r
+ modexFadeOff(4, gpal);\r
+#endif\r
+ VGAmodeX(0, 1, &gvar);\r
+ Shutdown16(&gvar);\r
+ printf("\nProject 16 zcroll.exe. This is just a test file!\n");\r
+ printf("version %s\n", VERSION);\r
+ SCROLLEXITMESG;\r
+ switch(detectcpu())\r
+ {\r
+ case 0: cpus = "8086/8088 or 186/88"; break;\r
+ case 1: cpus = "286"; break;\r
+ case 2: cpus = "386 or newer"; break;\r
+ default: cpus = "internal error"; break;\r
+ }\r
+ printf("detected CPU type: %s\n", cpus);\r
+#ifdef FADE\r
+ modexFadeOn(4, dpal);\r
+#endif\r
+}\r