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