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