]> 4ch.mooo.com Git - 16.git/blob - src/lib/_croll16.c
2dc6f5aa088258665dcebda37c6610007a39d171
[16.git] / src / lib / _croll16.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         scroll16 library~
24 */
25 #include "src/lib/scroll16.h"
26 #include "src/lib/16_sprite.h"
27
28 void walk(map_view_t *pip, player_t *player, word pn)
29 {
30         #define INC_PER_FRAME if(player[pn].q&1) player[pn].persist_aniframe++; if(player[pn].persist_aniframe>4) player[pn].persist_aniframe = 1;
31         //printf("player[%d].d=%d\n", pn, player[pn].d);
32         switch(player[pn].d)
33         {
34                 //no direction
35                 case 2:
36                         //0000pip[0].video->startclk = (*clockw);
37                 break;
38                 //right movement
39                 case 3:
40                         //printf("pip[0].page->tilesw=%d        ", pip[0].page->tilesw); printf("pip[0].page->tw=%d\n", pip[0].page->tw);
41                         if(pip[0].tx >= 0 && pip[0].tx+pip[0].page->tw < pip[0].map->width && player[pn].tx == pip[0].tx+pip[0].page->tilemidposscreenx &&
42                         !(pip[0].map->data[(player[pn].tx)+(pip[0].map->width*(player[pn].ty-1))] == 0))//!(player[pn].tx+1 == TRIGGX && player[pn].ty == TRIGGY))      //collision detection!
43                         {
44                                 if(player[pn].q<=player[pn].spt)
45                                 {
46                                         INC_PER_FRAME;
47                                         animatePlayer(pip, player, pn, 1);
48                                         ScrollRight(pip, player, 3, pn);
49                                         ScrollRight(pip, player, 2, pn);
50                                         mapScrollRight(pip, player, !(pip[0].video->p), pn);
51                                         mapScrollRight(pip, player, (pip[0].video->p), pn);
52                                         if(!pageflipflop) modexShowPage(pip[1].page);
53                                         player[pn].q++;
54                                         //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
55                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
56                         }
57                         else if(player[pn].tx < pip[0].map->width && !(pip[0].map->data[(player[pn].tx)+(pip[0].map->width*(player[pn].ty-1))] == 0))//!(player[pn].tx+1 == TRIGGX && player[pn].ty == TRIGGY))
58                         {
59                                 if(player[pn].q<=player[pn].spt)
60                                 {
61                                         INC_PER_FRAME;
62                                         player[pn].x+=(player[pn].speed);
63                                         animatePlayer(pip, player, pn, 0);
64                                         if(!pageflipflop) modexShowPage(pip[1].page);
65                                         player[pn].q++;
66                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
67                         }
68                         else
69                         {
70                                 if(!pageflipflop) modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x, player[pn].y-TILEWH, player[pn].x, player[pn].y-TILEWH, 16, 32);
71 #ifdef SPRITE
72                                 //PBUFSFUN(pip[0].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 16, 32, PLAYERBMPDATA);
73                                 animate_spri(player[pn].spri);
74 #else
75                                 modexClearRegion(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 14);
76 #endif
77                                 if(!pageflipflop) modexShowPage(pip[1].page);
78                                 player[pn].d = 2;
79                         }
80                         player[pn].triggerx = player[pn].tx+1;
81                         player[pn].triggery = player[pn].ty;
82                 break;
83
84                 //left movement
85                 case 1:
86                         if(pip[0].tx > 0 && pip[0].tx+pip[0].page->tw <= pip[0].map->width && player[pn].tx == pip[0].tx+pip[0].page->tilemidposscreenx &&
87                         !(pip[0].map->data[(player[pn].tx-2)+(pip[0].map->width*(player[pn].ty-1))] == 0))//!(player[pn].tx-1 == TRIGGX && player[pn].ty == TRIGGY))    //collision detection!
88                         {
89                                 if(player[pn].q<=player[pn].spt)
90                                 {
91                                         INC_PER_FRAME;
92                                         animatePlayer(pip, player, pn, 1);
93                                         ScrollLeft(pip, player, 3, pn);
94                                         ScrollLeft(pip, player, 2, pn);
95                                         mapScrollLeft(pip, player, !(pip[0].video->p), pn);
96                                         mapScrollLeft(pip, player, (pip[0].video->p), pn);
97                                         if(!pageflipflop) modexShowPage(pip[1].page);
98                                         player[pn].q++;
99                                         //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
100                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
101                         }
102                         else if(player[pn].tx > 1 && !(pip[0].map->data[(player[pn].tx-2)+(pip[0].map->width*(player[pn].ty-1))] == 0))//!(player[pn].tx-1 == TRIGGX && player[pn].ty == TRIGGY))
103                         {
104                                 if(player[pn].q<=player[pn].spt)
105                                 {
106                                         INC_PER_FRAME;
107                                         player[pn].x-=(player[pn].speed);
108                                         animatePlayer(pip, player, pn, 0);
109                                         if(!pageflipflop) modexShowPage(pip[1].page);
110                                         player[pn].q++;
111                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
112                         }
113                         else
114                         {
115                                 if(!pageflipflop) modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x, player[pn].y-TILEWH, player[pn].x, player[pn].y-TILEWH, 16, 32);
116 #ifdef SPRITE
117                                 //PBUFSFUN(pip[0].page, player[pn].x, player[pn].y-TILEWH, 16, 96, 16, 32, PLAYERBMPDATA);
118                                 animate_spri(player[pn].spri);
119 #else
120                                 modexClearRegion(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 10);
121 #endif
122                                 if(!pageflipflop) modexShowPage(pip[1].page);
123                                 player[pn].d = 2;
124                         }
125                         player[pn].triggerx = player[pn].tx-1;
126                         player[pn].triggery = player[pn].ty;
127                 break;
128
129                 //down movement
130                 case 4:
131                         if(pip[0].ty >= 0 && pip[0].ty+pip[0].page->th < pip[0].map->height && player[pn].ty == pip[0].ty+pip[0].page->tilemidposscreeny &&
132                         !(pip[0].map->data[(player[pn].tx-1)+(pip[0].map->width*(player[pn].ty))] == 0))//!(player[pn].tx == TRIGGX && player[pn].ty+1 == TRIGGY))      //collision detection!
133                         {
134                                 if(player[pn].q<=player[pn].spt)
135                                 {
136                                         INC_PER_FRAME;
137                                         animatePlayer(pip, player, pn, 1);
138                                         ScrollDown(pip, player, 3, pn);
139                                         ScrollDown(pip, player, 2, pn);
140                                         mapScrollDown(pip, player, !(pip[0].video->p), pn);
141                                         mapScrollDown(pip, player, (pip[0].video->p), pn);
142                                         if(!pageflipflop) modexShowPage(pip[1].page);
143                                         player[pn].q++;
144                                         //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
145                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
146                         }
147                         else if(player[pn].ty < pip[0].map->height && !(pip[0].map->data[(player[pn].tx-1)+(pip[0].map->width*(player[pn].ty))] == 0))//!(player[pn].tx == TRIGGX && player[pn].ty+1 == TRIGGY))
148                         {
149                                 if(player[pn].q<=player[pn].spt)
150                                 {
151                                         INC_PER_FRAME;
152                                         player[pn].y+=(player[pn].speed);
153                                         animatePlayer(pip, player, pn, 0);
154                                         if(!pageflipflop) modexShowPage(pip[1].page);
155                                         player[pn].q++;
156                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
157                         }
158                         else
159                         {
160                                 if(!pageflipflop) modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x, player[pn].y-TILEWH, player[pn].x, player[pn].y-TILEWH, 16, 32);
161 #ifdef SPRITE
162                                 //PBUFSFUN(pip[0].page, player[pn].x, player[pn].y-TILEWH, 16, 64, 16, 32, PLAYERBMPDATA);
163                                 animate_spri(player[pn].spri);
164 #else
165                                 modexClearRegion(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 9);
166 #endif
167                                 if(!pageflipflop) modexShowPage(pip[1].page);
168                                 player[pn].d = 2;
169                         }
170                         player[pn].triggerx = player[pn].tx;
171                         player[pn].triggery = player[pn].ty+1;
172                 break;
173
174                 //up movement
175                 case 0:
176                         if(pip[0].ty > 0 && pip[0].ty+pip[0].page->th <= pip[0].map->height && player[pn].ty == pip[0].ty+pip[0].page->tilemidposscreeny &&
177                         !(pip[0].map->data[(player[pn].tx-1)+(pip[0].map->width*(player[pn].ty-2))] == 0))//!(player[pn].tx == TRIGGX && player[pn].ty-1 == TRIGGY))    //collision detection!
178                         {
179                                 if(player[pn].q<=player[pn].spt)
180                                 {
181                                         INC_PER_FRAME;
182                                         animatePlayer(pip, player, pn, 1);
183                                         ScrollUp(pip, player, 3, pn);
184                                         ScrollUp(pip, player, 2, pn);
185                                         mapScrollUp(pip, player, !(pip[0].video->p), pn);
186                                         mapScrollUp(pip, player, (pip[0].video->p), pn);
187                                         if(!pageflipflop) modexShowPage(pip[1].page);
188                                         player[pn].q++;
189                                         //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
190                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
191                         }
192                         else if(player[pn].ty > 1 && !(pip[0].map->data[(player[pn].tx-1)+(pip[0].map->width*(player[pn].ty-2))] == 0))//!(player[pn].tx == TRIGGX &&  player[pn].ty-1 == TRIGGY))
193                         {
194                                 if(player[pn].q<=player[pn].spt)
195                                 {
196                                         INC_PER_FRAME;
197                                         player[pn].y-=(player[pn].speed);
198                                         animatePlayer(pip, player, 0, pn);
199                                         if(!pageflipflop) modexShowPage(pip[1].page);
200                                         player[pn].q++;
201                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
202                         }
203                         else
204                         {
205                                 if(!pageflipflop) modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x, player[pn].y-TILEWH, player[pn].x, player[pn].y-TILEWH, 16, 32);
206 #ifdef SPRITE
207                                 //PBUFSFUN(pip[0].page, player[pn].x, player[pn].y-TILEWH, 16, 0, 16, 32, PLAYERBMPDATA);
208                                 animate_spri(player[pn].spri);
209 #else
210                                 modexClearRegion(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 12);
211 #endif
212                                 if(!pageflipflop) modexShowPage(pip[1].page);
213                                 player[pn].d = 2;
214                         }
215                         player[pn].triggerx = player[pn].tx;
216                         player[pn].triggery = player[pn].ty-1;
217                 break;
218         }
219 }
220
221 //panning page
222 void panpagemanual(map_view_t *pip, player_t *player, word pn)
223 {
224         switch(player[pn].d)
225         {
226                 //right movement
227                 case 3:
228                         if(pip[pip[0].pan->pn].tx >= 0 && pip[pip[0].pan->pn].tx+pip[pip[0].pan->pn].page->tw < pip[pip[0].pan->pn].page->tilesw)
229                         {
230                                 if(player[pn].q<=player[pn].spt)
231                                 {
232                                         pip[pip[0].pan->pn].page->dx+=4;
233                                         modexShowPage(pip[pip[0].pan->pn].page);
234                                         player[pn].q++;
235                                 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].tx++; }
236                         }
237                 break;
238
239                 //left movement
240                 case 1:
241                         if(pip[pip[0].pan->pn].tx > 0 && pip[pip[0].pan->pn].tx+pip[pip[0].pan->pn].page->tw <= pip[pip[0].pan->pn].page->tilesw)
242                         {
243                                 if(player[pn].q<=player[pn].spt)
244                                 {
245                                         pip[pip[0].pan->pn].page->dx-=4;
246                                         modexShowPage(pip[pip[0].pan->pn].page);
247                                         player[pn].q++;
248                                 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].tx--; }
249                         }
250                 break;
251
252                 //down movement
253                 case 4:
254                         if(pip[pip[0].pan->pn].ty >= 0 && pip[pip[0].pan->pn].ty+pip[pip[0].pan->pn].page->th < pip[pip[0].pan->pn].page->tilesh)
255                         {
256                                 if(player[pn].q<=player[pn].spt)
257                                 {
258                                         pip[pip[0].pan->pn].page->dy+=4;
259                                         modexShowPage(pip[pip[0].pan->pn].page);
260                                         player[pn].q++;
261                                 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].ty++; }
262                         }
263                 break;
264
265                 //up movement
266                 case 0:
267                         if(pip[pip[0].pan->pn].ty > 0 && pip[pip[0].pan->pn].ty+pip[pip[0].pan->pn].page->th <= pip[pip[0].pan->pn].page->tilesh)
268                         {
269                                 if(player[pn].q<=player[pn].spt)
270                                 {
271                                         pip[pip[0].pan->pn].page->dy-=4;
272                                         modexShowPage(pip[pip[0].pan->pn].page);
273                                         player[pn].q++;
274                                 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].ty--; }
275                         }
276                         break;
277         }
278         //if (player[pn].d!=2) printf("player[%u].d=%u player[%u].q=%u\n", pn, player[pn].d, pn, player[pn].q);
279 }
280
281 /*map_t
282 allocMap(int w, int h) {
283         map_t result;
284
285         result.width =w;
286         result.height=h;
287         result.data = malloc(sizeof(byte) * w * h);
288         //result.data = (byte *)alloc_emem(((int)sizeof(byte) * w * h)/1024);
289         if(isEMS() || checkEMS())
290         {
291                 XMOVE mm;
292                 //emmhandle = mallocEMS(coretotalEMS());//alloc_emem((int)sizeof(map))
293                 mm.length=sizeof(result);
294                 mm.sourceH=0;
295                 mm.sourceOff=ptr2long(&result);
296                 mm.destH=emmhandle;
297                 mm.destOff=0;
298                 ist = move_emem(&mm);
299                 if(!ist){ dealloc_emem(emmhandle); exit(5); }
300                 printf("%d\n", coretotalEMS());
301         }
302
303         return result;
304 }*/
305
306 /*void
307 initMap(map_t *map) {
308         // just a place holder to fill out an alternating pattern
309         int x, y, xx, yy;
310         int i, q;
311 //      int tile = 1;
312         //if(!isEMS() || !checkEMS())
313 //              map->tiles = malloc(sizeof(tiles_t));
314         //else
315         //      map->tiles = (tiles_t *)alloc_emem(sizeof(tiles_t));
316
317          //create the tile set
318         //if(!isEMS() || !checkEMS())
319 //              map->tiles->data = malloc(sizeof(bitmap_t));
320         //else
321         //      map->tiles->data = (bitmap_t *)alloc_emem(sizeof(bitmap_t));
322 //      map->tiles->data->width = (TILEWH);
323 //      map->tiles->data->height= TILEWH;
324         //if(!isEMS() || !checkEMS())
325 //              map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
326         //else
327         //      map->tiles->data->data = (byte *)alloc_emem((TILEWH*2)*TILEWH);
328 //      map->tiles->tileHeight = TILEWH;
329 //      map->tiles->tileWidth =TILEWH;
330 //      map->tiles->rows = 1;
331 //      map->tiles->cols = 1;//2;
332
333         q=0;
334         //for(y=0; y<map->height; y++) {
335         //for(x=0; x<map->width; x++) {
336         i=0;
337         for(yy=0; yy<TILEWH; yy++) {
338         for(xx=0; xx<(TILEWH); xx++) {
339                 //if(x<TILEWH){
340                   map->tiles->data->data[i+1] = map->data[q];//28;//0x24;
341 //                printf("[%d]", map->tiles->data->data[i]);
342                 //}else{
343                   //map->tiles->data->data[i] = map->data[q];//0;//0x34;
344                   //printf("]%d[==[%d]", i, map->tiles->data->data[i]);
345                 //}
346                 i++;
347         }
348 //      printf("\n");
349         }
350 //      printf("[%d]", map->data[q]);
351         q++;
352 //      }
353         //printf("\n\n");
354 //      }
355
356         i=0;
357         for(y=0; y<map->height; y++) {
358                 for(x=0; x<map->width; x++) {
359 //                      map->data[i]=255;
360                         printf("[%d]", map->data[i]);
361                         //tile = tile ? 0 : 1;
362                         i++;
363                 }
364                 //tile = tile ? 0 : 1;
365         }
366 }*/
367
368 void near mapScrollRight(map_view_t *mv, player_t *player, word id, word plid)
369 {
370         word x, y;  /* coordinate for drawing */
371
372         /* increment the pixel position and update the page */
373         mv[id].page->dx += player[plid].speed;
374
375         /* check to see if this changes the tile */
376         if(mv[id].page->dx >= mv[id].dxThresh )
377         {
378         /* go forward one tile */
379         mv[id].tx++;
380         /* Snap the origin forward */
381         mv[id].page->data += 4;
382
383         mv[id].page->dx = mv[id].map->tiles->tileWidth;
384         }
385
386         /* draw the next column */
387         x= mv[0].page->sw + mv[id].map->tiles->tileWidth;
388         if(player[plid].q%4)
389                 if(id==0)
390                         mapDrawCol(&mv[0], mv[0].tx + mv[0].page->tw, mv[0].ty-1, x, player, mv->page->dx);
391                 else
392                         if(!pageflipflop && !pageploop)
393                                 modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*(mv[0].page->th+2));
394         mv[0].video->r=1;
395 }
396
397
398 void near mapScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
399 {
400         word x, y;  /* coordinate for drawing */
401
402         /* decrement the pixel position and update the page */
403         mv[id].page->dx -= player[plid].speed;
404
405         /* check to see if this changes the tile */
406         if(mv[id].page->dx == 0)
407         {
408         /* go backward one tile */
409         mv[id].tx--;
410         /* Snap the origin backward */
411         mv[id].page->data -= 4;
412
413         mv[id].page->dx = mv[id].map->tiles->tileWidth;
414         }
415
416         /* draw the next column */
417         x= 0;
418         if(player[plid].q%4)
419                 if(id==0)
420                         mapDrawCol(&mv[0], mv[0].tx - 1, mv[0].ty-1, x, player, mv->page->dx);
421                 else
422                         if(!pageflipflop && !pageploop)
423                                 modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*(mv[0].page->th+2));
424         mv[0].video->r=1;
425 }
426
427
428 void near mapScrollUp(map_view_t *mv, player_t *player, word id, word plid)
429 {
430         word x, y;  /* coordinate for drawing */
431
432         /* decrement the pixel position and update the page */
433         mv[id].page->dy -= player[plid].speed;
434
435         /* check to see if this changes the tile */
436         if(mv[id].page->dy == 0 )
437         {
438         /* go down one tile */
439         mv[id].ty--;
440         /* Snap the origin downward */
441         mv[id].page->data -= mv[id].page->pi;
442
443         mv[id].page->dy = mv[id].map->tiles->tileHeight;
444         }
445
446         /* draw the next row */
447         y= 0;
448         if(player[plid].q%3)
449                 if(id==0)
450                         mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty-1, y, player, mv->page->dy);
451                 else
452                         if(!pageflipflop && !pageploop)
453                                 modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*(mv[0].page->tw+2), mv[id].map->tiles->tileHeight);
454         mv[0].video->r=1;
455 }
456
457 void near mapScrollDown(map_view_t *mv, player_t *player, word id, word plid)
458 {
459         word x, y;  /* coordinate for drawing */
460
461         /* increment the pixel position and update the page */
462         mv[id].page->dy += player[plid].speed;
463
464         /* check to see if this changes the tile */
465         if(mv[id].page->dy >= mv[id].dyThresh )
466         {
467         /* go down one tile */
468         mv[id].ty++;
469         /* Snap the origin downward */
470         mv[id].page->data += mv[id].page->pi;
471
472         mv[id].page->dy = mv[id].map->tiles->tileHeight;
473         }
474
475         /* draw the next row */
476         y= mv[0].page->sh + mv[id].map->tiles->tileHeight;
477         if(player[plid].q%3)
478                 if(id==0)
479                         mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty+mv[0].page->th, y, player, mv->page->dy);
480                 else
481                         if(!pageflipflop && !pageploop)
482                                 modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*(mv[0].page->tw+2), mv[id].map->tiles->tileHeight);
483         mv[0].video->r=1;
484 }
485
486
487 //TODO finish this wwww
488 void near ScrollRight(map_view_t *mv, player_t *player, word id, word plid)
489 {
490         /* increment the pixel position and update the page */
491         mv[id].page->dx += player[plid].speed;
492
493         /* check to see if this changes the tile */
494         if(mv[id].page->dx >= mv[0].dxThresh )
495         {
496 //              vga_setup_wm1_block_copy();
497 //              _fmemmove(mv[id].page->data+4, mv[id].page->data, mv[id].page->pagesize);
498 //              vga_restore_rm0wm0();
499                 /* Snap the origin forward */
500                 mv[id].page->data += 4;
501                 mv[id].page->dx = mv[0].map->tiles->tileWidth;
502         }
503 }
504
505 void near ScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
506 {
507         /* decrement the pixel position and update the page */
508         mv[id].page->dx -= player[plid].speed;
509
510         /* check to see if this changes the tile */
511         if(mv[id].page->dx == 0)
512         {
513 //              vga_setup_wm1_block_copy();
514 //              _fmemmove(mv[id].page->data-4, mv[id].page->data, mv[id].page->pagesize);
515 //              vga_restore_rm0wm0();
516                 /* Snap the origin backward */
517                 mv[id].page->data -= 4;
518                 mv[id].page->dx = mv[0].map->tiles->tileWidth;
519         }
520 }
521
522 void near ScrollUp(map_view_t *mv, player_t *player, word id, word plid)
523 {
524         /* decrement the pixel position and update the page */
525         mv[id].page->dy -= player[plid].speed;
526
527         /* check to see if this changes the tile */
528         if(mv[id].page->dy == 0)
529         {
530 //              vga_setup_wm1_block_copy();
531 //              _fmemmove(mv[id].page->data-mv[id].page->pi, mv[id].page->data, mv[id].page->pagesize);
532 //              vga_restore_rm0wm0();
533                 /* Snap the origin backward */
534                 mv[id].page->data -= mv[id].page->pi;
535                 mv[id].page->dy = mv[0].map->tiles->tileWidth;
536         }
537 }
538
539 void near ScrollDown(map_view_t *mv, player_t *player, word id, word plid)
540 {
541         /* increment the pixel position and update the page */
542         mv[id].page->dy += player[plid].speed;
543
544         /* check to see if this changes the tile */
545         if(mv[id].page->dy >= mv[0].dxThresh )
546         {
547 //              vga_setup_wm1_block_copy();
548 //              _fmemmove(mv[id].page->data+mv[id].page->pi, mv[id].page->data, mv[id].page->pagesize);
549 //              vga_restore_rm0wm0();
550                 /* Snap the origin forward */
551                 mv[id].page->data += mv[id].page->pi;
552                 mv[id].page->dy = mv[0].map->tiles->tileWidth;
553         }
554 }
555
556 sword chkmap(map_t *map, word q)
557 {
558 //      bitmap_t bp;
559         static byte x[(MAPW*MAPH)+1] =
560 { 1, 2, 3, 4, 0, 3, 3, 3, 3, 3, 3, 3, 3, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 6, 7, 8, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10 };
561 /*1,    2,      3,      4,      0,      3,      3,      3,      3,      3,      3,      3,      3,      4,      1,      1,      1,      1,      1,      1,      \
562 5,      6,      7,      8,      0,      1,      0,      1,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
563 9,      10,     11,     12,     4,      1,      0,      1,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
564 13,     14,     15,     16,     0,      1,      1,      1,      5,      8,      1,      11,     11,     1,      1,      1,      1,      1,      1,      1,      \
565 0,      0,      4,      0,      0,      0,      0,      0,      8,      8,      1,      11,     11,     3,      1,      1,      1,      1,      1,      1,      \
566 1,      1,      1,      1,      0,      0,      0,      0,      8,      8,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
567 1,      1,      1,      1,      0,      0,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
568 1,      1,      1,      1,      0,      0,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      3,      1,      1,      1,      \
569 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
570 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
571 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      3,      1,      1,      1,      \
572 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
573 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      3,      1,      1,      1,      \
574 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
575 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      3,      3,      3,      3,      1,      2,      3,      4 };*/
576         //check for failed to load map
577         if((map->width == map->height == 0) && (q>0))
578         {
579                 //initiate a null map!
580                 map->width=MAPW;///2;
581                 map->height=MAPH;///2;
582 //              map->data = malloc(((map->width*map->height)+1)*sizeof(byte));
583                 map->data = &x;
584                 map->tiles = malloc(sizeof(tiles_t));
585                 //fix this to be far~
586 //              bp = bitmapLoadPcx("data/ed.pcx");
587 //              map->tiles->data = &bp;
588                 map->tiles->debug_data = map->data;
589                 map->tiles->tileHeight = 16;
590                 map->tiles->tileWidth = 16;
591                 map->tiles->rows = 1;
592                 map->tiles->cols = 1;
593                 map->tiles->debug_text = true;
594         }
595         else map->tiles->debug_text = false;
596         return 0;
597 }
598
599 //TODO: player position here
600 void mapGoTo(map_view_t *mv, int tx, int ty)
601 {
602         int px, py;
603         unsigned int i;
604
605         /* set up the coordinates */
606         mv[0].tx = mv[1].tx = tx;
607         mv[0].ty = mv[1].ty = ty;
608         mv[0].page->dx = mv[1].page->dx = mv[2].page->dx = mv[3].page->dx = mv->map->tiles->tileWidth;
609         mv[0].page->dy = mv[1].page->dy = mv[2].page->dy = mv[3].page->dy = mv->map->tiles->tileHeight;
610
611         /* set up the thresholds */
612         mv[0].dxThresh = mv[1].dxThresh = mv[2].dxThresh = mv[3].dxThresh = mv->map->tiles->tileWidth * 2;
613         mv[0].dyThresh = mv[1].dyThresh = mv[2].dxThresh = mv[3].dxThresh = mv->map->tiles->tileHeight * 2;
614
615         /* draw the tiles */
616         modexClearRegion(mv[0].page, 0, 0, mv[0].page->width, mv[0].page->height, 0);
617         py=0;
618         i=mv[0].ty * mv[0].map->width + mv[0].tx;
619         for(ty=mv[0].ty-1; py < mv[0].page->sh+mv->dyThresh && ty < mv[0].map->height; ty++, py+=mv[0].map->tiles->tileHeight) {
620                 mapDrawWRow(&mv[0], tx-1, ty, py);
621         i+=mv->map->width - tx;
622         }
623         if(!pageploop) modexCopyPageRegion(mv[1].page, mv[0].page, 0, 0, 0, 0, mv[0].page->width, mv[0].page->height);
624 //      {
625 //              unsigned int k,j,o;
626 //              /* fill screen with a distinctive pattern */
627 //              for (k=0;k < vga_state.vga_width;k++) {
628 //                      o = k >> 2;
629 //                      vga_write_sequencer(0x02/*map mask*/,1 << (k&3));
630 //                              for (j=0;j < (mv[0].page->height)+(mv[1].page->height)+(mv[2].page->height)+(mv[3].page->height);j++,o += vga_state.vga_stride)
631 //                                      vga_state.vga_graphics_ram[o] = (k^j)&15; // VRL samples put all colors in first 15!
632 //              }
633 //      }
634         modexCopyPageRegion(mv[3].page, mv[0].page, 0/**/, 0/**/, 0, 0, 16, 32);
635 }
636
637 void near
638 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y)
639 {
640         word rx;
641         word ry;
642         word textx=0;
643         word texty=0;
644         //if(i==0) i=2;
645         if(i==0)
646         {
647                 //wwww
648                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 0); //currently the over scan color!
649         }
650         else
651         {
652                 rx = (((i-1) % ((t->data->width)/t->tileWidth)) * t->tileWidth);
653                 ry = (((i-1) / ((t->data->height)/t->tileHeight)) * t->tileHeight);
654 ////0000printf("i=%d\n", i);
655                 switch(t->debug_text)
656                 {
657                         case 0:
658 #ifndef TILERENDER
659                                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, ((t->debug_data[i])+1));
660                                 //modexprint(page, x, y, 1, 15, 0, (char const *)(t->debug_data[i]));
661 #else
662                                 PBUFBFUN                (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
663                                 /* then the sprite. note modding ram ptr means we just draw to (x&3,0) */
664                                 //draw_vrl1_vgax_modex(x-rx,y-ry,vrl_header,vrl_lineoffs,buffer+sizeof(*vrl_header),bufsz-sizeof(*vrl_header));
665                                 //modexDrawBmpRegion    (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
666 #endif
667                         break;
668                         case 1:
669                                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, (t->debug_data[i])+1);
670                                 //modexprintbig(page, x, y, 1, 15, 0, (t->debug_data));
671                                 /*for(texty=0; texty<2; texty++)
672                                 {
673                                         for(textx=0; textx<2; textx++)
674                                         {*/
675 //                                              modexprint(page, x+(textx*8), y+(texty*8), 1, (word)(t->debug_data), 0, (t->debug_data));
676 /*                                      }
677                                 }*/
678                         break;
679                 }
680         }
681 }
682
683 void near mapDrawRow(map_view_t *mv, int tx, int ty, word y, player_t *p, word poopoffset)
684 {
685         word x;
686         int i;
687         poopoffset%=p[0].speed;
688 //printf("y: %d\n", poopoffset);
689         /* the position within the map array */
690         i=ty * mv->map->width + tx;
691         for(x=poopoffset; x<(mv->page->sw+mv->dxThresh)/(poopoffset+1) && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
692         if(i>=0) {
693                 /* we are in the map, so copy! */
694                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
695         }
696         i++; /* next! */
697         }
698 }
699
700 void near mapDrawCol(map_view_t *mv, int tx, int ty, word x, player_t *p, word poopoffset)
701 {
702         int y;
703         int i;
704         poopoffset%=p[0].speed;
705 //printf("x: %d\n", poopoffset);
706         /* location in the map array */
707         i=ty * mv->map->width + tx;
708
709         /* We'll copy all of the columns in the screen,
710            i + 1 row above and one below */
711         for(y=poopoffset; y<(mv->page->sh+mv->dyThresh)/(poopoffset+1) && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
712         if(i>=0) {
713                 /* we are in the map, so copy away! */
714                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
715         }
716         i += mv->map->width;
717         }
718 }
719
720 void mapDrawWRow(map_view_t *mv, int tx, int ty, word y)
721 {
722         word x;
723         int i;
724
725         /* the position within the map array */
726         i=ty * mv->map->width + tx;
727         for(x=0; x<mv->page->sw+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
728         if(i>=0) {
729                 /* we are in the map, so copy! */
730                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
731         }
732         i++; /* next! */
733         }
734 }
735
736 void mapDrawWCol(map_view_t *mv, int tx, int ty, word x)
737 {
738         int y;
739         int i;
740
741         /* location in the map array */
742         i=ty * mv->map->width + tx;
743
744         /* We'll copy all of the columns in the screen,
745            i + 1 row above and one below */
746         for(y=0; y<mv->page->sh+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
747         if(i>=0) {
748                 /* we are in the map, so copy away! */
749                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
750         }
751         i += mv->map->width;
752         }
753 }
754
755 /*void qclean()
756 {
757         //setkb(0);
758 }*/
759
760 unsigned char shinku_fps_indicator_page = 2;
761 boolean pageflipflop = 1;
762 boolean pageploop = 1;
763
764 /*      sync    */
765 void shinku(global_game_variables_t *gv)
766 {
767         word x = (0) + gv->video.page[/*!*/(gv->video.p)].dx; // follow the screen
768         word y = (0) + gv->video.page[/*!*/(gv->video.p)].dy; // follow the screen
769         word w = 64, h = 8, col = 7, bgcol = 0, type = 1;
770         byte o,o2,i;
771         //modexCopyPageRegion(pip[1].page, pip[2].page, 16, 16, 16, 16, (14*8)+4, 8+4);
772         /* block copy to visible RAM from offscreen */
773 //      vga_setup_wm1_block_copy();
774 //      modexCopyPageRegion(&(gv->video.page[shinku_fps_indicator_page]), &(gv->video.page[!shinku_fps_indicator_page]), x, y, x+w, 0, w, h);
775 //      o =     *(gv->video.page[2].data); // source offscreen
776 //      o2 =    *(gv->video.page[shinku_fps_indicator_page].data)+(y * vga_state.vga_stride) + (x >> 2); // dest visible (original stride)
777 //      for (i=0;i < h;i++,o += vga_state.vga_draw_stride,o2 += vga_state.vga_stride) vga_wm1_mem_block_copy(o2,o,w >> 2);
778         /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
779 //      vga_restore_rm0wm0();
780         if(elapsed_timer(gv) >= (1.0 / gv->kurokku.frames_per_second))
781         {
782                 sprintf(gv->pee, "%.0f fps", (double)gv->kurokku.tiku/ticktock(gv));
783                 //modexClearRegion(&(gv->video.page[shinku_fps_indicator_page]), x, y, w, h, 45);
784                 modexprint(&(gv->video.page[/*!*/(gv->video.p)]), x, y, type, col, bgcol, gv->pee);
785                 gv->kurokku.tiku=0;
786                 /* block copy to visible RAM from offscreen */
787 //              vga_setup_wm1_block_copy();
788 //              o =     *(gv->video.page[shinku_fps_indicator_page].data); // source offscreen
789 //              o2 =    *(gv->video.page[2].data)+(y * vga_state.vga_stride) + (x >> 2); // dest visible (original stride)
790 //              for (i=0;i < h;i++,o += vga_state.vga_draw_stride,o2 += vga_state.vga_stride) vga_wm1_mem_block_copy(o2,o,w >> 2);
791 //              modexCopyPageRegion(&(gv->video.page[shinku_fps_indicator_page]), &(gv->video.page[!shinku_fps_indicator_page]), x, y, x, 0, w, h);
792                 /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
793 //              vga_restore_rm0wm0();
794         }else //copy dat sheet
795         gv->kurokku.tiku++;
796
797         switch(gv->kurokku.fpscap)
798         {
799                 case 0:
800                         //modexprint(&(gv->video.page[shinku_fps_indicator_page]), x, y+8, type, col, bgcol, "sanic!");
801                         gv->kurokku.frames_per_second=1;
802                 break;
803                 case 1:
804                         //turn this off if XT
805                         //modexWaitBorder();
806                         vga_wait_for_vsync();
807                         gv->kurokku.frames_per_second=60;
808                 break;
809         }
810         if(pageflipflop){
811         if(gv->video.r){
812                 //vga_setup_wm1_block_copy();
813                 //_fmemcpy((gv->video.page[(gv->video.p)]).data, (gv->video.page[(!gv->video.p)]).data, gv->video.page[(!gv->video.p)].pagesize);
814                 //vga_restore_rm0wm0();
815                 if(!pageploop) modexCopyPageRegion(&(gv->video.page[(gv->video.p)]), &(gv->video.page[(!gv->video.p)]), 0, 0, 0, 0, gv->video.page[gv->video.p].width, gv->video.page[!gv->video.p].height);
816                 modexShowPage(&(gv->video.page[gv->video.p]));
817                 if(!pageploop) gv->video.p=!gv->video.p;
818                 gv->video.r=!gv->video.r;
819                 //0000gv->video.tickclk = ((*clockw)-gv->video.startclk)/18.2;
820         }
821         }
822 }
823
824 void near animatePlayer(map_view_t *pip, player_t *player, word pn, sword scrollswitch)
825 {
826         sword x = player[pn].x;
827         sword y = player[pn].y;
828         sword bx = x+16;        //buffer's x
829         sword by = y+16;        //buffer's y
830         word dire=32; //direction
831         sword qq; //scroll offset
832         word ls = player[pn].persist_aniframe;
833
834         switch(scrollswitch)
835         {
836                 case 0:
837                         qq = 0;
838                 break;
839                 default:
840                         qq = ((player[pn].q)*(player[pn].speed));
841                 break;
842         }
843         //x-=4;
844         y-=pip[0].map->tiles->tileHeight;
845         switch (player[pn].d)
846         {
847                 case 0:
848                         //up
849                         dire*=player[pn].d;
850                         y-=qq;
851                         by-=4;
852                 break;
853                 case 3:
854                         // right
855                         dire*=(player[pn].d-2);
856                         x+=qq;
857                         bx+=4;
858                 break;
859                 case 2:
860                 break;
861                 case 4:
862                         //down
863                         dire*=(player[pn].d-2);
864                         y+=qq;
865                         by+=4;
866                 break;
867                 case 1:
868                         //left
869                         dire*=(player[pn].d+2);
870                         x-=qq;
871                         bx-=4;
872                 break;
873         }
874
875 #ifdef SPRITE
876 //#define FRAME1 PBUFSFUN(pip[/*!*/(pip->video->p)].page, x, y, 32, dire, 16, 32,       PLAYERBMPDATA);
877 //#define FRAME2 PBUFSFUN(pip[/*!*/(pip->video->p)].page, x, y, 16, dire, 16, 32,       PLAYERBMPDATA);
878 //#define FRAME3 PBUFSFUN(pip[/*!*/(pip->video->p)].page, x, y, 0, dire, 16, 32,        PLAYERBMPDATA);
879 //#define FRAME4 PBUFSFUN(pip[/*!*/(pip->video->p)].page, x, y, 16, dire, 16, 32,       PLAYERBMPDATA);
880 #define FRAME1 animate_spri(player[pn].spri);
881 #define FRAME2 animate_spri(player[pn].spri);
882 #define FRAME3 animate_spri(player[pn].spri);
883 #define FRAME4 animate_spri(player[pn].spri);
884 #else
885 #define FRAME1 modexClearRegion(pip[/*!*/(pip->video->p)].page, x, y, 16, 32, 2+dire);
886 #define FRAME2 modexClearRegion(pip[/*!*/(pip->video->p)].page, x, y, 16, 32, 1+dire);
887 #define FRAME3 modexClearRegion(pip[/*!*/(pip->video->p)].page, x, y, 16, 32, dire);
888 #define FRAME4 modexClearRegion(pip[/*!*/(pip->video->p)].page, x, y, 16, 32, 1+dire);
889 #endif
890         if(!pageflipflop)
891                 modexCopyPageRegion(pip[1].page, pip[0].page, x-4, y-4, x-4, y-4, 28, 36);
892         else{
893                 //copy old bg to page0
894                 //modexCopyPageRegion(pip[3].page, pip[0].page, bx, by, 0, 0,   20, 36);
895                 //update buffer
896                 //modexCopyPageRegion(pip[0].page, pip[3].page, 0, 0,   x, y,   20, 36);
897         }
898 //modexCopyPageRegion(page_t *dest, page_t *src, word sx, word sy, word dx, word dy, word width, word height);
899         //modexCopyPageRegion(pip[3].page, pip[!(pip->video->p)].page, x-4, y-4, 0, 128, 28, 36);
900         /*modexCopyPageRegion(pip[pip->video->p].page,
901  pip[!(pip->video->p)].page, x-4, y-4, x-4, y-4, 28, 36);*/
902 //      else modexCopyPageRegion(pip[1].page, pip[0].page, x-4, y-4, x-4, y-4, 28, 40);
903         switch(ls)
904         {
905                 case 1:
906                         FRAME1
907                 break;
908                 case 2:
909                         FRAME2
910                 break;
911                 case 3:
912                         FRAME3
913                 break;
914                 case 4:
915                         FRAME4
916                 break;
917         }
918 //      if(2>ls && ls>=1) { FRAME1 }else
919 //      if(3>ls && ls>=2) { FRAME2 }else
920 //      if(4>ls && ls>=3) { FRAME3 }else
921 //      if(5>ls && ls>=4) { FRAME4 }
922         //modexCopyPageRegion(pip[0].page, pip[3].page, 0, 0, x, y, 16, 32);
923         //printf("x=%d  y=%d    bx=%d           by=%d\n", x, y, bx, by);
924         pip->video->r=1;
925 }