OSDN Git Service

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