]> 4ch.mooo.com Git - 16.git/blob - src/_scroll.c
5a16247dc77b08733c6dead71510d6650c4d88d6
[16.git] / src / _scroll.c
1 /* Project 16 Source Code~
2  * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
3  *
4  * This file is part of Project 16.
5  *
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.
10  *
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.
15  *
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.
20  *
21  */
22
23 #include "src/lib/scroll16.h"
24 #include "src/lib/16_timer.h"
25 #include "src/lib/wcpu/wcpu.h"
26 #include "src/lib/16_sprite.h"
27 #include "src/lib/16_ca.h"
28 #include "src/lib/16_mm.h"
29 //#include "src/lib/16_head.h"//included already
30
31 //#define FADE
32 #define MODEX   //this is for mode x initiating
33
34 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
35 //bitmap_t *p;
36 global_game_variables_t gvar;
37 static map_t map;
38 player_t player[MaxPlayers];
39 map_view_t mv[4];
40 byte *ppal;
41 //word pn=0; //i forgot ww
42 float t;
43 sword bakapee;
44 pan_t pan;
45 //debugswitches
46 boolean panswitch=0;
47 //extern boolean pageflipflop=1;
48         unsigned int i;
49         const char *cpus;
50         //static int persist_aniframe = 0;    /* gonna be increased to 1 before being used, so 0 is ok for default */
51
52         //map_view_db_t pgid[4];
53         word pg;
54 //#ifdef FADE
55         static word paloffset=0;
56         byte *dpal;
57 //#endif
58         byte *gpal;
59         byte *ptr;
60         byte *mappalptr;
61
62 void main(int argc, char *argv[])
63 {
64         struct sprite sp;
65         __segment sega;
66         void __based(sega)* bigbuffer;
67
68         byte *mesg=malloc(sizeof(dword));
69         int i;
70
71         if(argv[1]) bakapee = atoi(argv[1]);
72         else bakapee = 1;
73
74         gvar.mm.mmstarted=0;
75         gvar.bigbuffer=bigbuffer;
76
77         MM_Startup(&gvar.mm, &gvar.mmi);
78         CA_Startup(&gvar);
79         // DOSLIB: check our environment
80         probe_dos();
81
82         // DOSLIB: what CPU are we using?
83         // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.
84         //      So this code by itself shouldn't care too much what CPU it's running on. Except that other
85         //      parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for
86         //      the CPU to carry out tasks. --J.C.
87         cpu_probe();
88
89         // DOSLIB: check for VGA
90         if (!probe_vga()) {
91                 printf("VGA probe failed\n");
92                 return;
93         }
94         // hardware must be VGA or higher!
95         if (!(vga_state.vga_flags & VGA_IS_VGA)) {
96                 printf("This program requires VGA or higher graphics hardware\n");
97                 return;
98         }
99
100         if (_DEBUG_INIT() == 0) {
101 #ifdef DEBUGSERIAL
102                 printf("WARNING: Failed to initialize DEBUG output\n");
103 #endif
104         }
105         _DEBUG("Serial debug output started\n"); // NTS: All serial output must end messages with newline, or DOSBox-X will not emit text to log
106         _DEBUGF("Serial debug output printf test %u %u %u\n",1U,2U,3U);
107
108         pan.pn=1;
109
110         start_timer(&gvar);
111
112         /* create the map */
113         fprintf(stderr, "testing map load~      ");
114         loadmap("data/test.map", &map);
115         chkmap(&map, 0);
116         printf("chkmap ok       ");
117         fprintf(stderr, "yay map loaded~~\n");
118
119         /* draw the tiles */
120 #ifdef MODEX
121         ptr = map.data;
122
123         /* data */
124         i = read_vrs(&gvar, "data/spri/chikyuu.vrs", sp.spritesheet);
125         if (i)
126         {
127                 puts("Error! Did not load sprite!");
128                 return;
129         }
130         puts("Sprite should be loaded now");
131         putch('q');
132         print_anim_ids(&sp);
133         putch('r');
134         i = set_anim_by_id(&sp, 10);
135         if (i == -1)
136         {
137                 printf("Anim id not found!");
138                 return;
139         }
140 /*      player[0].spri = malloc(...)
141  *      read_vrs(&gvar, "data/spri/chikyuu.vrs", player[0].spri->spritesheet); // load sprite
142         putch('s');
143         print_anim_ids(player[0].spri);
144         putch('t');
145         i = set_anim_by_id(player[0].spri, 10);
146         if (i == -1)
147         {
148                 printf("Anim id not found!");
149                 return;
150         }*/
151         player[0].spri = &sp;
152
153 #endif
154         /*      input!  */
155         IN_Startup();
156         IN_Default(0,&player,ctrl_Joystick);
157
158         /* save the palette */
159 #ifdef MODEX
160 #ifdef FADE
161         dpal = modexNewPal();
162         modexPalSave(dpal);
163         modexFadeOff(4, dpal);
164 #endif
165
166         textInit();
167         VGAmodeX(bakapee, 1, &gvar);
168 #ifdef FADE
169         modexPalBlack();        //reset the palette~
170 #endif
171 #endif
172         modexLoadPalFile("data/spri/chikyuu.pal", &ppal);
173         modexPalUpdate1(ppal);
174 #ifdef MODEX
175 #ifdef FADE
176         gpal = modexNewPal();
177         modexPalSave(gpal);
178         modexSavePalFile("data/g.pal", gpal);
179         modexPalBlack();        //so player will not see loadings~
180 #endif
181 #endif
182
183         /* setup camera and screen~ */
184         modexHiganbanaPageSetup(&gvar.video);
185         for(i=0;i<gvar.video.num_of_pages;i++)
186         {
187                 mv[i].page = &gvar.video.page[i];
188                 mv[i].map = &map;
189                 mv[i].video = &gvar.video;
190                 mv[i].pan       = &pan;
191         }
192
193         /* set up paging */
194         //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
195         mapGoTo(mv, 0, 0);
196         //_fmemcpy(mv[1].page->data, mv[0].page->data, mv[0].page->pagesize);
197
198         //TODO: put player in starting position of spot
199         //default player position on the viewable map
200         player[0].tx = mv[0].tx + mv[0].page->tilemidposscreenx;
201         player[0].ty = mv[0].ty + mv[0].page->tilemidposscreeny;
202         IN_initplayer(&player, 0);
203         //IN_initplayer(&player, 1);
204
205 #ifndef SPRITE
206         modexClearRegion(mv[0].page, player[0].x, player[0].y-TILEWH, 16, 32, 15);
207         //modexClearRegion(mv[1].page, player[0].x, player[0].y-TILEWH, 16, 32, 15);
208 #else
209         //PBUFSFUN(mv[1].page, player[0].x, player[0].y-TILEWH, 16, 64, 24, 32, PLAYERBMPDATA);
210         //PBUFSFUN(mv[0].page, player[0].x, player[0].y-TILEWH, 16, 64, 16, 32, player[0].data);
211         animate_spri(player[0].spri);
212 #endif
213
214         if(!pageflipflop)       modexShowPage(mv[1].page);
215         else                    modexShowPage(mv[0].page);//!(gvar.video.p)
216                 shinku_fps_indicator_page = 0; // we're on page 1 now, shinku(). follow along please or it will not be visible.
217
218         /* buffer pages */
219 //      modexClearRegion(mv[2].page, 0, 0, mv[2].page->width, mv[2].page->height, 47);
220 //      modexClearRegion(mv[3].page, 0, 0, mv[3].page->width, mv[3].page->height, 45);
221 //      {
222 //              unsigned int k,j,o;
223 //              /* fill screen with a distinctive pattern */
224 //              for (k=0;k < vga_state.vga_width;k++) {
225 //                      o = k >> 2;
226 //                      vga_write_sequencer(0x02/*map mask*/,1 << (k&3));
227 //                              for (j=0;j < vga_state.vga_height;j++,o += vga_state.vga_stride)
228 //                                      vga_state.vga_graphics_ram[o] = (k^j)&15; // VRL samples put all colors in first 15!
229 //              }
230 //      }
231         modexClearRegion(mv[3].page, 0, 128, 24, 36, 15);
232
233 #ifdef MODEX
234 #ifdef FADE
235         modexFadeOn(4, gpal);
236 #endif
237 #endif
238         while(!IN_KeyDown(sc_Escape) && player[0].hp>0)
239         {
240                 shinku(&gvar);
241         //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
242         //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
243         //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
244
245         //player movement
246                 IN_ReadControl(0,&player);
247         if(!panswitch){
248                 walk(mv, player, 0);
249         }else{
250                 panpagemanual(mv, player, 0);
251                 //printf("      player[0].q: %d", player[0].q); printf("        player[0].d: %d\n", player[0].d);
252         }
253
254         //the scripting stuff....
255         //if(((player[0].triggerx == TRIGGX && player[0].triggery == TRIGGY) && IN_KeyDown(0x1C))||(player[0].tx == 5 && player[0].ty == 5))
256         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))
257         {
258                 short i;
259                 for(i=800; i>=400; i--)
260                 {
261                         sound(i);
262                 }
263                 nosound();
264         }
265         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--; }
266         //debugging binds!
267         if(IN_KeyDown(2)){ modexShowPage(mv[0].page); pan.pn=0; }
268         if(IN_KeyDown(3)){ modexShowPage(mv[1].page); pan.pn=1; }
269         if(IN_KeyDown(4)){ modexShowPage(mv[2].page); pan.pn=2; }
270         if(IN_KeyDown(4+1)){ modexShowPage(mv[3].page); pan.pn=3; }
271         if(IN_KeyDown(25)){ modexpdump(mv[0].page); modexpdump(mv[1].page);
272                  IN_UserInput(1,1);
273         }       //p
274 #ifdef MODEX
275 #ifdef FADE
276         if(IN_KeyDown(24)){ modexPalUpdate0(gpal); paloffset=0; modexpdump(mv[0].page); modexpdump(mv[1].page);  IN_UserInput(1,1); }
277         if(IN_KeyDown(22)){
278 //      paloffset=0; modexPalBlack(); modexPalUpdate(player[0].data, &paloffset, 0, 0);
279 //      printf("1paloffset      =       %d\n", paloffset/3);
280 //       modexPalUpdate(map.tiles->data, &paloffset, 0, 0);
281 //      printf("2paloffset      =       %d\n", paloffset/3);
282 //       modexpdump(mv[0].page); modexpdump(mv[1].page);
283                 IN_UserInput(1,1);
284         }
285 #endif
286 #endif
287         //pan switch
288         if(IN_KeyDown(88)){panswitch=!panswitch; IN_UserInput(1,1);}    //f12
289         if(IN_KeyDown(87))      //f11
290         {
291                 pageflipflop=!pageflipflop;
292                 IN_UserInput(1,1);
293 //              VGAmodeX(0, 0, &gvar);
294 //              IN_Shutdown();
295 //              __asm
296 //              {
297 //                      mov ah,31h
298 //                      int 21h
299 //              }
300         }
301         if(IN_KeyDown(68))      //f10
302         {
303                 gvar.kurokku.fpscap=!gvar.kurokku.fpscap;
304                 IN_UserInput(1,1);
305         }
306         if(IN_KeyDown(67))      //f9
307         {
308                 modexClearRegion(mv[1].page, 0, 0, mv[1].page->width, mv[1].page->height, 2);
309                 modexClearRegion(mv[2].page, 0, 0, mv[2].page->width, mv[2].page->height, 3);
310                 modexClearRegion(mv[3].page, 0, 0, mv[3].page->width, mv[3].page->height, 4);
311                 modexClearRegion(mv[3].page, 0, 0, 20, 36, 15);
312                 //IN_UserInput(1,1);
313         }
314         if(IN_KeyDown(66))      //f8
315         {
316 //              modexDrawSprite(mv[0].page, 16, 16, p);
317 //              modexDrawSprite(mv[0].page, 32+48, 16, (player[0].data));
318         }
319         //TODO fmemtest into page
320         /*if(IN_KeyDown(4+1))   //4
321         {
322                 pg=1;
323                 SELECT_ALL_PLANES();
324                 _fmemset(((mv[pg].page->data+4)+(16*(mv[pg].page->width/4))), 15, 4);
325         }*/
326
327         //9
328         if(IN_KeyDown(10)){ modexPalOverscan(rand()%56); modexPalUpdate1(dpal); IN_UserInput(1,1); }
329         //if(IN_KeyDown(11)){ modexPalOverscan(15); }
330         if((player[0].q==1) && !(player[0].x%TILEWH==0 && player[0].y%TILEWH==0)) break;        //incase things go out of sync!
331         }
332
333         /* fade back to text mode */
334         /* but 1st lets save the game palette~ */
335 #ifdef MODEX
336 #ifdef FADE
337         modexPalSave(gpal);
338         modexSavePalFile("data/g.pal", gpal);
339         modexFadeOff(4, gpal);
340 #endif
341         VGAmodeX(0, 1, &gvar);
342 #endif
343         IN_Shutdown();
344         MM_FreePtr(&bigbuffer, &gvar.mm);
345         CA_Shutdown(&gvar);
346         MM_Shutdown(&gvar.mm);
347         printf("\nProject 16 scroll.exe. This is just a test file!\n");
348         printf("version %s\n", VERSION);
349         printf("tx: %d  ", mv[0].tx);
350         printf("ty: %d\n", mv[0].ty);
351         printf("\n");
352         printf("player vars:\n");
353         printf("        x: %d", player[0].x); printf("  y: %d\n", player[0].y);
354         //if(player[0].hp==0) printf("%d wwww\n", player[0].y+8);
355         //else printf("\nplayer[0].y: %d\n", player[0].y);
356         printf("        tx: %d", player[0].tx); printf("        ty: %d\n", player[0].ty);
357         printf("        triggx: %d", player[0].triggerx); printf("      triggy: %d\n", player[0].triggery);
358         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);
359                 printf("        pdir=%d\n", player[0].pdir);
360         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))]);
361 //      printf("palette offset: %d\n", paloffset/3);
362 //++++  printf("Total used: %zu\n", oldfreemem-GetFreeSize());
363 //++++  printf("Total free: %zu\n", GetFreeSize());
364 //not used now  printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");
365 //not used now  printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");
366         printf("Virtual Screen: %dx", gvar.video.page[0].width);        printf("%d      ", gvar.video.page[0].height);
367         printf("Screen: %dx", gvar.video.page[0].sw);   printf("%d\n", gvar.video.page[0].sh);
368         printf("virtual tile resolution: %dx", gvar.video.page[0].tilesw);      printf("%d      ", gvar.video.page[0].tilesh);
369         printf("tile resolution: %dx", gvar.video.page[0].tw);  printf("%d\n", gvar.video.page[0].th);
370         printf("middle tile position: %dx", gvar.video.page[0].tilemidposscreenx);      printf("%d\n", gvar.video.page[0].tilemidposscreeny);
371         modexprintmeminfo(&gvar.video);
372         //printf("mv[%u].tx: %d", pan.pn, mv[pan.pn].tx); printf("      mv[%u].ty: %d   ", pan.pn, mv[pan.pn].ty);
373         printf("gvar.video.p=%u ", gvar.video.p); printf("gvar.video.r=%u ", gvar.video.r);
374         printf("pageflipflop=%u\n", pageflipflop);
375         //0000printf("\ngvar.video.tickclk=%f\n", gvar.video.tickclk);
376         //0000printf("gvar.video.clk=%f", gvar.video.clk);
377         printf("\n");
378         //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]);
379
380         printf("\n");
381         switch(detectcpu())
382         {
383                 case 0: cpus = "8086/8088 or 186/88"; break;
384                 case 1: cpus = "286"; break;
385                 case 2: cpus = "386 or newer"; break;
386                 default: cpus = "internal error"; break;
387         }
388         printf("detected CPU type: %s\n", cpus);
389 #ifdef MODEX
390 #ifdef FADE
391         modexFadeOn(4, dpal);
392 #endif
393 #endif
394 }