]> 4ch.mooo.com Git - 16.git/blob - src/lib/scroll16.c
damn!! hmmm i think ther eis something wrong with the presistant animation stuff
[16.git] / src / lib / scroll16.c
1 /* Project 16 Source Code~
2  * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669
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         switch(player[pn].d)
31         {
32                 //right movement
33                 case 3:
34                         if(pip[0].tx >= 0 && pip[0].tx+20 < pip[0].map->width && player[pn].tx == pip[0].tx + 10 &&
35                         !(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!
36                         {
37                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
38                                 {
39                                         INC_PER_FRAME;
40                                         animatePlayer(pip, player, pn, 1);
41                                         mapScrollRight(pip, player, 0, pn);
42                                         mapScrollRight(pip, player, 1, pn);
43                                         modexShowPage(pip[1].page);
44                                         player[pn].q++;
45                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
46                         }
47                         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))
48                         {
49                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
50                                 {
51                                         INC_PER_FRAME;
52                                         player[pn].x+=(player[pn].speed);
53                                         animatePlayer(pip, player, pn, 0);
54                                         modexShowPage(pip[1].page);
55                                         player[pn].q++;
56                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
57                         }
58                         else
59                         {
60                                 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);
61 #ifdef SPRITE
62                                 modexDrawSpriteRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 24, 32, &player[pn].data);
63 #else
64                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 14);
65 #endif
66                                 modexShowPage(pip[1].page);
67                                 player[pn].d = 2;
68                         }
69                         player[pn].triggerx = player[pn].tx+1;
70                         player[pn].triggery = player[pn].ty;
71                 break;
72
73                 //left movement
74                 case 1:
75                         if(pip[0].tx > 0 && pip[0].tx+20 <= pip[0].map->width && player[pn].tx == pip[0].tx + 10 &&
76                         !(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!
77                         {
78                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
79                                 {
80                                         INC_PER_FRAME;
81                                         animatePlayer(pip, player, pn, 1);
82                                         mapScrollLeft(pip, player, 0, pn);
83                                         mapScrollLeft(pip, player, 1, pn);
84                                         modexShowPage(pip[1].page);
85                                         player[pn].q++;
86                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
87                         }
88                         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))
89                         {
90                                 modexprint(pip[1].page, 320, (player[pn].q*8), 1, player[pn].q, 0, (byte *)(player[pn].q));
91                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
92                                 {
93                                         INC_PER_FRAME;
94                                         player[pn].x-=(player[pn].speed);
95                                         animatePlayer(pip, player, pn, 0);
96                                         modexShowPage(pip[1].page);
97                                         player[pn].q++;
98                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
99                         }
100                         else
101                         {
102                                 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);
103 #ifdef SPRITE
104                                 modexDrawSpriteRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 96, 24, 32, &player[pn].data);
105 #else
106                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 10);
107 #endif
108                                 modexShowPage(pip[1].page);
109                                 player[pn].d = 2;
110                         }
111                         player[pn].triggerx = player[pn].tx-1;
112                         player[pn].triggery = player[pn].ty;
113                 break;
114
115                 //down movement
116                 case 4:
117                         if(pip[0].ty >= 0 && pip[0].ty+15 < pip[0].map->height && player[pn].ty == pip[0].ty + 8 &&
118                         !(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!
119                         {
120                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
121                                 {
122                                         INC_PER_FRAME;
123                                         animatePlayer(pip, player, pn, 1);
124                                         mapScrollDown(pip, player, 0, pn);
125                                         mapScrollDown(pip, player, 1, pn);
126                                         modexShowPage(pip[1].page);
127                                         player[pn].q++;
128                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
129                         }
130                         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))
131                         {
132                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
133                                 {
134                                         INC_PER_FRAME;
135                                         player[pn].y+=(player[pn].speed);
136                                         animatePlayer(pip, player, pn, 0);
137                                         modexShowPage(pip[1].page);
138                                         player[pn].q++;
139                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
140                         }
141                         else
142                         {
143                                 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);
144 #ifdef SPRITE
145                                 modexDrawSpriteRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 64, 24, 32, &player[pn].data);
146 #else
147                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 9);
148 #endif
149                                 modexShowPage(pip[1].page);
150                                 player[pn].d = 2;
151                         }
152                         player[pn].triggerx = player[pn].tx;
153                         player[pn].triggery = player[pn].ty+1;
154                 break;
155
156                 //up movement
157                 case 0:
158                         if(pip[0].ty > 0 && pip[0].ty+15 <= pip[0].map->height && player[pn].ty == pip[0].ty + 8 &&
159                         !(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!
160                         {
161                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
162                                 {
163                                         INC_PER_FRAME;
164                                         animatePlayer(pip, player, pn, 1);
165                                         mapScrollUp(pip, player, 0, pn);
166                                         mapScrollUp(pip, player, 1, pn);
167                                         modexShowPage(pip[1].page);
168                                         player[pn].q++;
169                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
170                         }
171                         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))
172                         {
173                                 modexprint(pip[1].page, 320, (player[pn].q*8), 1, player[pn].q, 0, (byte *)(player[pn].q));
174                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
175                                 {
176                                         INC_PER_FRAME;
177                                         player[pn].y-=(player[pn].speed);
178                                         animatePlayer(pip, player, 0, pn);
179                                         modexShowPage(pip[1].page);
180                                         player[pn].q++;
181                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
182                         }
183                         else
184                         {
185                                 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);
186 #ifdef SPRITE
187                                 modexDrawSpriteRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 0, 24, 32, &player[pn].data);
188 #else
189                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 12);
190 #endif
191                                 modexShowPage(pip[1].page);
192                                 player[pn].d = 2;
193                         }
194                         player[pn].triggerx = player[pn].tx;
195                         player[pn].triggery = player[pn].ty-1;
196                 break;
197         }
198 }
199
200 /*map_t
201 allocMap(int w, int h) {
202         map_t result;
203
204         result.width =w;
205         result.height=h;
206         result.data = malloc(sizeof(byte) * w * h);
207         //result.data = (byte *)alloc_emem(((int)sizeof(byte) * w * h)/1024);
208         if(isEMS() || checkEMS())
209         {
210                 XMOVE mm;
211                 //emmhandle = mallocEMS(coretotalEMS());//alloc_emem((int)sizeof(map))
212                 mm.length=sizeof(result);
213                 mm.sourceH=0;
214                 mm.sourceOff=ptr2long(&result);
215                 mm.destH=emmhandle;
216                 mm.destOff=0;
217                 ist = move_emem(&mm);
218                 if(!ist){ dealloc_emem(emmhandle); exit(5); }
219                 printf("%d\n", coretotalEMS());
220         }
221
222         return result;
223 }*/
224
225 /*void
226 initMap(map_t *map) {
227         // just a place holder to fill out an alternating pattern
228         int x, y, xx, yy;
229         int i, q;
230 //      int tile = 1;
231         //if(!isEMS() || !checkEMS())
232 //              map->tiles = malloc(sizeof(tiles_t));
233         //else
234         //      map->tiles = (tiles_t *)alloc_emem(sizeof(tiles_t));
235
236          //create the tile set
237         //if(!isEMS() || !checkEMS())
238 //              map->tiles->data = malloc(sizeof(bitmap_t));
239         //else
240         //      map->tiles->data = (bitmap_t *)alloc_emem(sizeof(bitmap_t));
241 //      map->tiles->data->width = (TILEWH);
242 //      map->tiles->data->height= TILEWH;
243         //if(!isEMS() || !checkEMS())
244 //              map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
245         //else
246         //      map->tiles->data->data = (byte *)alloc_emem((TILEWH*2)*TILEWH);
247 //      map->tiles->tileHeight = TILEWH;
248 //      map->tiles->tileWidth =TILEWH;
249 //      map->tiles->rows = 1;
250 //      map->tiles->cols = 1;//2;
251
252         q=0;
253         //for(y=0; y<map->height; y++) {
254         //for(x=0; x<map->width; x++) {
255         i=0;
256         for(yy=0; yy<TILEWH; yy++) {
257         for(xx=0; xx<(TILEWH); xx++) {
258                 //if(x<TILEWH){
259                   map->tiles->data->data[i+1] = map->data[q];//28;//0x24;
260 //                printf("[%d]", map->tiles->data->data[i]);
261                 //}else{
262                   //map->tiles->data->data[i] = map->data[q];//0;//0x34;
263                   //printf("]%d[==[%d]", i, map->tiles->data->data[i]);
264                 //}
265                 i++;
266         }
267 //      printf("\n");
268         }
269 //      printf("[%d]", map->data[q]);
270         q++;
271 //      }
272         //printf("\n\n");
273 //      }
274
275         i=0;
276         for(y=0; y<map->height; y++) {
277                 for(x=0; x<map->width; x++) {
278 //                      map->data[i]=255;
279                         printf("[%d]", map->data[i]);
280                         //tile = tile ? 0 : 1;
281                         i++;
282                 }
283                 //tile = tile ? 0 : 1;
284         }
285 }*/
286
287 void mapScrollRight(map_view_t *mv, player_t *player, word id, word plid)
288 {
289         word x, y;  /* coordinate for drawing */
290
291         /* increment the pixel position and update the page */
292         mv[id].page->dx += player[plid].speed;
293
294         /* check to see if this changes the tile */
295         if(mv[id].page->dx >= mv[id].dxThresh )
296         {
297         /* go forward one tile */
298         mv[id].tx++;
299         /* Snap the origin forward */
300         mv[id].page->data += 4;
301         mv[id].page->dx = mv[id].map->tiles->tileWidth;
302         }
303
304         /* draw the next column */
305         x= SCREEN_WIDTH + mv[id].map->tiles->tileWidth;
306         if(player[plid].q%4)
307                 if(id==0)
308                         mapDrawCol(&mv[0], mv[0].tx + 20 , mv[0].ty-1, x, player, mv->page->dx);
309                 else
310                         modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*17);
311         //}
312 }
313
314
315 void mapScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
316 {
317         word x, y;  /* coordinate for drawing */
318
319         /* increment the pixel position and update the page */
320         mv[id].page->dx -= player[plid].speed;
321
322         /* check to see if this changes the tile */
323         if(mv[id].page->dx == 0)
324         {
325         /* go backward one tile */
326         mv[id].tx--;
327
328         /* Snap the origin backward */
329         mv[id].page->data -= 4;
330         mv[id].page->dx = mv[id].map->tiles->tileWidth;
331         }
332
333         /* draw the next column */
334         x= 0;
335         if(player[plid].q%4)
336                 if(id==0)
337                         mapDrawCol(&mv[0], mv[0].tx - 1, mv[0].ty-1, x, player, mv->page->dx);
338                 else
339                         modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*17);
340         //}
341 }
342
343
344 void mapScrollUp(map_view_t *mv, player_t *player, word id, word plid)
345 {
346         word x, y;  /* coordinate for drawing */
347
348         /* increment the pixel position and update the page */
349         mv[id].page->dy -= player[plid].speed;
350
351         /* check to see if this changes the tile */
352         if(mv[id].page->dy == 0 )
353         {
354         /* go down one tile */
355         mv[id].ty--;
356         /* Snap the origin downward */
357         mv[id].page->data -= mv[id].page->width*4;
358         mv[id].page->dy = mv[id].map->tiles->tileHeight;
359         }
360
361         /* draw the next row */
362         y= 0;
363         if(player[plid].q%3)
364                 if(id==0)
365                         mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty-1, y, player, mv->page->dy);
366                 else
367                         modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*22, mv[id].map->tiles->tileHeight);
368         //}
369 }
370
371 void mapScrollDown(map_view_t *mv, player_t *player, word id, word plid)
372 {
373         word x, y;  /* coordinate for drawing */
374
375         /* increment the pixel position and update the page */
376         mv[id].page->dy += player[plid].speed;
377
378         /* check to see if this changes the tile */
379         if(mv[id].page->dy >= mv[id].dyThresh )
380         {
381         /* go down one tile */
382         mv[id].ty++;
383         /* Snap the origin downward */
384         mv[id].page->data += mv[id].page->width*4;
385         mv[id].page->dy = mv[id].map->tiles->tileHeight;
386         }
387
388         /* draw the next row */
389         y= SCREEN_HEIGHT + mv[id].map->tiles->tileHeight;
390         if(player[plid].q%3)
391                 if(id==0)
392                         mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty+15, y, player, mv->page->dy);
393                 else
394                         modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*22, mv[id].map->tiles->tileHeight);
395         //}
396 }
397
398 sword chkmap(map_t *map, word q)
399 {
400 //      bitmap_t bp;
401         byte x[MAPW*MAPH] = { 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, 1, 9, 10, 11, 12, 4, 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, 1, 13, 14,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 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 };
402         //check for failed to load map
403         if((map->width == map->height == 0) || (q>0))
404         {
405                 //initiate a null map!
406                 map->width=MAPW;
407                 map->height=MAPH;
408                 map->data = malloc((map->width*map->height)*sizeof(byte));
409                 map->data = &x;
410                 map->tiles = malloc(sizeof(tiles_t));
411                 //fix this to be far~
412 //              bp = bitmapLoadPcx("data/ed.pcx");
413 //              map->tiles->data = &bp;
414                 map->tiles->debug_data = map->data;
415                 map->tiles->tileHeight = 16;
416                 map->tiles->tileWidth = 16;
417                 map->tiles->rows = 1;
418                 map->tiles->cols = 1;
419                 map->tiles->debug_text = true;
420         }
421         return 0;
422 }
423
424 void mapGoTo(map_view_t *mv, int tx, int ty)
425 {
426         int px, py;
427         unsigned int i;
428
429         /* set up the coordinates */
430         mv->tx = tx;
431         mv->ty = ty;
432         mv->page->dx = mv->map->tiles->tileWidth;
433         mv->page->dy = mv->map->tiles->tileHeight;
434
435         /* set up the thresholds */
436         mv->dxThresh = mv->map->tiles->tileWidth * 2;
437         mv->dyThresh = mv->map->tiles->tileHeight * 2;
438
439         /* draw the tiles */
440         modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
441         py=0;
442         i=mv->ty * mv->map->width + mv->tx;
443         for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
444                 mapDrawWRow(mv, tx-1, ty, py);
445         i+=mv->map->width - tx;
446         }
447 }
448
449
450 void
451 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y)
452 {
453         word rx;
454         word ry;
455         word textx=0;
456         word texty=0;
457         //if(i==0) i=2;
458         if(i==0)
459         {
460                 //wwww
461                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 0); //currently the over scan color!
462         }
463         else
464         {
465                 rx = (((i-1) % ((t->data->width)/t->tileWidth)) * t->tileWidth);
466                 ry = (((i-1) / ((t->data->height)/t->tileHeight)) * t->tileHeight);
467 ////0000printf("i=%d\n", i);
468                 switch(t->debug_text)
469                 {
470                         case 0:
471                                 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
472                         break;
473                         case 1:
474                                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, (t->debug_data[(x+(t->data->width*y))]));
475                                 //modexprintbig(page, x, y, 1, 15, 0, (t->debug_data));
476                                 /*for(texty=0; texty<2; texty++)
477                                 {
478                                         for(textx=0; textx<2; textx++)
479                                         {*/
480 //                                              modexprint(page, x+(textx*8), y+(texty*8), 1, (word)(t->debug_data), 0, (t->debug_data));
481 /*                                      }
482                                 }*/
483                         break;
484                 }
485         }
486 }
487
488 void mapDrawRow(map_view_t *mv, int tx, int ty, word y, player_t *p, word poopoffset)
489 {
490         word x;
491         int i;
492         poopoffset%=p[0].speed;
493 //printf("y: %d\n", poopoffset);
494         /* the position within the map array */
495         i=ty * mv->map->width + tx;
496         for(x=poopoffset; x<(SCREEN_WIDTH+mv->dxThresh)/(poopoffset+1) && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
497         if(i>=0) {
498                 /* we are in the map, so copy! */
499                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
500         }
501         i++; /* next! */
502         }
503 }
504
505 void mapDrawCol(map_view_t *mv, int tx, int ty, word x, player_t *p, word poopoffset)
506 {
507         int y;
508         int i;
509         poopoffset%=p[0].speed;
510 //printf("x: %d\n", poopoffset);
511         /* location in the map array */
512         i=ty * mv->map->width + tx;
513
514         /* We'll copy all of the columns in the screen,
515            i + 1 row above and one below */
516         for(y=poopoffset; y<(SCREEN_HEIGHT+mv->dyThresh)/(poopoffset+1) && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
517         if(i>=0) {
518                 /* we are in the map, so copy away! */
519                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
520         }
521         i += mv->map->width;
522         }
523 }
524
525 void mapDrawWRow(map_view_t *mv, int tx, int ty, word y)
526 {
527         word x;
528         int i;
529
530         /* the position within the map array */
531         i=ty * mv->map->width + tx;
532         for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
533         if(i>=0) {
534                 /* we are in the map, so copy! */
535                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
536         }
537         i++; /* next! */
538         }
539 }
540
541 void mapDrawWCol(map_view_t *mv, int tx, int ty, word x)
542 {
543         int y;
544         int i;
545
546         /* location in the map array */
547         i=ty * mv->map->width + tx;
548
549         /* We'll copy all of the columns in the screen,
550            i + 1 row above and one below */
551         for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
552         if(i>=0) {
553                 /* we are in the map, so copy away! */
554                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
555         }
556         i += mv->map->width;
557         }
558 }
559
560 void qclean()
561 {
562         modexLeave();
563         //setkb(0);
564 }
565
566 void pdump(page_t *pee)
567 {
568         int mult=(QUADWH);
569         int palq=(mult)*TILEWH;
570         int palcol=0;
571         int palx, paly;
572         for(paly=0; paly<palq; paly+=mult){
573                 for(palx=0; palx<palq; palx+=mult){
574                                 modexClearRegion(pee, palx+TILEWH, paly+TILEWH, mult, mult, palcol);
575                         palcol++;
576                 }
577         }
578 }
579
580 //sync!
581 void shinku(page_t *page, global_game_variables_t *gv)
582 {
583         byte *pee;
584         word x = (16);
585         word y = (8+16);
586         word col = 15;
587         word bgcol = 0;
588         word type = 1;
589         dword far* clockdww= (dword far*) 0x046C; /* 18.2hz clock */
590         if(elapsed_timer(gv) >= (1.0 / gv->frames_per_second))
591         {
592                 pee = malloc(sizeof(double));
593                 sprintf(pee, "%f", ((*clockdww-(gv->t)) /18.2));
594                 modexprint(page, x, y, type, col, bgcol, pee);
595                 sprintf(pee, "%f", elapsed_timer(gv));
596                 modexprint(page, x, y+8, type, col, bgcol, pee);
597         }
598 }
599
600 void animatePlayer(map_view_t *pip, player_t *player, word playnum, sword scrollswitch)
601 {
602         sword x = player[playnum].x;
603         sword y = player[playnum].y;
604         sword dire=32; //direction
605         sword qq; //scroll offset
606         word ls = player[playnum].persist_aniframe;
607
608         if(!scrollswitch) qq = 0;
609         else qq = ((ls)*player[playnum].speed);
610         switch (player[playnum].d)
611         {
612                 case 0:
613                         //up
614                         dire*=player[playnum].d;
615                         x-=4;
616                         y-=(qq-TILEWH);
617                 break;
618                 case 3:
619                         // right
620                         dire*=(player[playnum].d-2);
621                         x+=(qq-4);
622                         y-=TILEWH;
623                 break;
624                 case 2:
625                 break;
626                 case 4:
627                         //down
628                         dire*=(player[playnum].d-2);
629                         x-=4;
630                         y+=(qq-TILEWH);
631                 break;
632                 case 1:
633                         //left
634                         dire*=(player[playnum].d+2);
635                         x-=(qq-4);
636                         y-=TILEWH;
637                 break;
638         }
639 #ifdef SPRITE
640 #define FRAME1 modexDrawSpriteRegion(pip[1].page, x, y, 48, dire, 24, 32, &player[playnum].data);
641 #define FRAME2 modexDrawSpriteRegion(pip[1].page, x, y, 24, dire, 24, 32, &player[playnum].data)
642 #define FRAME3 modexDrawSpriteRegion(pip[1].page, x, y, 0, dire, 24, 32, &player[playnum].data);
643 #define FRAME4 modexDrawSpriteRegion(pip[1].page, x, y, 24, dire, 24, 32, &player[playnum].data);
644 #else
645 #define FRAME1 modexClearRegion(pip[1].page, x, y, 24, 32, 2+dire);
646 #define FRAME2 modexClearRegion(pip[1].page, x, y, 24, 32, 1+dire);
647 #define FRAME3 modexClearRegion(pip[1].page, x, y, 24, 32, dire);
648 #define FRAME4 modexClearRegion(pip[1].page, x, y, 24, 32, 1+dire);
649 #endif
650         modexCopyPageRegion(pip[1].page, pip[0].page, x-4, y-4, x-4, y-4, 28, 40);
651         if(2>ls && ls>=1) { FRAME1 }else
652         if(3>ls && ls>=2) { FRAME2 }else
653         if(4>ls && ls>=3) { FRAME3 }else
654         if(5>ls && ls>=4) { FRAME4 }
655         //TODO: mask copy //modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
656         //modexClearRegion(top->page, 66, 66, 2, 40, 0);
657         //modexCopyPageRegion(dest->page, top->page, 66, 66, 66, 66, 2, 40);
658         //turn this off if XT
659         //XTif(detectcpu() > 0)
660         modexWaitBorder();
661 }