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