]> 4ch.mooo.com Git - 16.git/blob - src/lib/scroll16.c
textInit() for font. add variable so shinku() knows what page we're on.
[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         switch(player[pn].d)
31         {
32                 //right movement
33                 case 3:
34                         //printf("pip[0].page->tilesw=%d\n", pip[0].page->tilesw);
35                         if(pip[0].tx >= 0 && pip[0].tx+pip[0].page->tilesw < pip[0].map->width && player[pn].tx == pip[0].tx+pip[0].page->tilemidposscreenx &&
36                         !(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!
37                         {
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].d = 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].d = 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 #ifdef SPRITE
63                                 PBUFSFUN(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 24, 32, PLAYERBMPDATA);
64 #else
65                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 14);
66 #endif
67                                 modexShowPage(pip[1].page);
68                                 player[pn].d = 2;
69                         }
70                         player[pn].triggerx = player[pn].tx+1;
71                         player[pn].triggery = player[pn].ty;
72                 break;
73
74                 //left movement
75                 case 1:
76                         if(pip[0].tx > 0 && pip[0].tx+pip[0].page->tilesw <= pip[0].map->width && player[pn].tx == pip[0].tx+pip[0].page->tilemidposscreenx &&
77                         !(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!
78                         {
79                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
80                                 {
81                                         INC_PER_FRAME;
82                                         animatePlayer(pip, player, pn, 1);
83                                         mapScrollLeft(pip, player, 0, pn);
84                                         mapScrollLeft(pip, player, 1, pn);
85                                         modexShowPage(pip[1].page);
86                                         player[pn].q++;
87                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
88                         }
89                         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))
90                         {
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                                 PBUFSFUN(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 96, 24, 32, PLAYERBMPDATA);
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+pip[0].page->tilesh < pip[0].map->height && player[pn].ty == pip[0].ty+pip[0].page->tilemidposscreeny &&
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                                 PBUFSFUN(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 64, 24, 32, PLAYERBMPDATA);
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+pip[0].page->tilesh <= pip[0].map->height && player[pn].ty == pip[0].ty+pip[0].page->tilemidposscreeny &&
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                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
174                                 {
175                                         INC_PER_FRAME;
176                                         player[pn].y-=(player[pn].speed);
177                                         animatePlayer(pip, player, 0, pn);
178                                         modexShowPage(pip[1].page);
179                                         player[pn].q++;
180                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
181                         }
182                         else
183                         {
184                                 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);
185 #ifdef SPRITE
186                                 PBUFSFUN(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 0, 24, 32, PLAYERBMPDATA);
187 #else
188                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 12);
189 #endif
190                                 modexShowPage(pip[1].page);
191                                 player[pn].d = 2;
192                         }
193                         player[pn].triggerx = player[pn].tx;
194                         player[pn].triggery = player[pn].ty-1;
195                 break;
196         }
197 }
198
199 /*map_t
200 allocMap(int w, int h) {
201         map_t result;
202
203         result.width =w;
204         result.height=h;
205         result.data = malloc(sizeof(byte) * w * h);
206         //result.data = (byte *)alloc_emem(((int)sizeof(byte) * w * h)/1024);
207         if(isEMS() || checkEMS())
208         {
209                 XMOVE mm;
210                 //emmhandle = mallocEMS(coretotalEMS());//alloc_emem((int)sizeof(map))
211                 mm.length=sizeof(result);
212                 mm.sourceH=0;
213                 mm.sourceOff=ptr2long(&result);
214                 mm.destH=emmhandle;
215                 mm.destOff=0;
216                 ist = move_emem(&mm);
217                 if(!ist){ dealloc_emem(emmhandle); exit(5); }
218                 printf("%d\n", coretotalEMS());
219         }
220
221         return result;
222 }*/
223
224 /*void
225 initMap(map_t *map) {
226         // just a place holder to fill out an alternating pattern
227         int x, y, xx, yy;
228         int i, q;
229 //      int tile = 1;
230         //if(!isEMS() || !checkEMS())
231 //              map->tiles = malloc(sizeof(tiles_t));
232         //else
233         //      map->tiles = (tiles_t *)alloc_emem(sizeof(tiles_t));
234
235          //create the tile set
236         //if(!isEMS() || !checkEMS())
237 //              map->tiles->data = malloc(sizeof(bitmap_t));
238         //else
239         //      map->tiles->data = (bitmap_t *)alloc_emem(sizeof(bitmap_t));
240 //      map->tiles->data->width = (TILEWH);
241 //      map->tiles->data->height= TILEWH;
242         //if(!isEMS() || !checkEMS())
243 //              map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
244         //else
245         //      map->tiles->data->data = (byte *)alloc_emem((TILEWH*2)*TILEWH);
246 //      map->tiles->tileHeight = TILEWH;
247 //      map->tiles->tileWidth =TILEWH;
248 //      map->tiles->rows = 1;
249 //      map->tiles->cols = 1;//2;
250
251         q=0;
252         //for(y=0; y<map->height; y++) {
253         //for(x=0; x<map->width; x++) {
254         i=0;
255         for(yy=0; yy<TILEWH; yy++) {
256         for(xx=0; xx<(TILEWH); xx++) {
257                 //if(x<TILEWH){
258                   map->tiles->data->data[i+1] = map->data[q];//28;//0x24;
259 //                printf("[%d]", map->tiles->data->data[i]);
260                 //}else{
261                   //map->tiles->data->data[i] = map->data[q];//0;//0x34;
262                   //printf("]%d[==[%d]", i, map->tiles->data->data[i]);
263                 //}
264                 i++;
265         }
266 //      printf("\n");
267         }
268 //      printf("[%d]", map->data[q]);
269         q++;
270 //      }
271         //printf("\n\n");
272 //      }
273
274         i=0;
275         for(y=0; y<map->height; y++) {
276                 for(x=0; x<map->width; x++) {
277 //                      map->data[i]=255;
278                         printf("[%d]", map->data[i]);
279                         //tile = tile ? 0 : 1;
280                         i++;
281                 }
282                 //tile = tile ? 0 : 1;
283         }
284 }*/
285
286 void near mapScrollRight(map_view_t *mv, player_t *player, word id, word plid)
287 {
288         word x, y;  /* coordinate for drawing */
289
290         /* increment the pixel position and update the page */
291         mv[id].page->dx += player[plid].speed;
292
293         /* check to see if this changes the tile */
294         if(mv[id].page->dx >= mv[id].dxThresh )
295         {
296         /* go forward one tile */
297         mv[id].tx++;
298         /* Snap the origin forward */
299         mv[id].page->data += 4;
300         mv[id].page->dx = mv[id].map->tiles->tileWidth;
301         }
302
303         /* draw the next column */
304         x= mv[0].page->sw + mv[id].map->tiles->tileWidth;
305         if(player[plid].q%4)
306                 if(id==0)
307                         mapDrawCol(&mv[0], mv[0].tx + mv[0].page->tilesw, mv[0].ty-1, x, player, mv->page->dx);
308                 else
309                         modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*(mv[0].page->tilesh+2));
310         //}
311 }
312
313
314 void near mapScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
315 {
316         word x, y;  /* coordinate for drawing */
317
318         /* increment the pixel position and update the page */
319         mv[id].page->dx -= player[plid].speed;
320
321         /* check to see if this changes the tile */
322         if(mv[id].page->dx == 0)
323         {
324         /* go backward one tile */
325         mv[id].tx--;
326
327         /* Snap the origin backward */
328         mv[id].page->data -= 4;
329         mv[id].page->dx = mv[id].map->tiles->tileWidth;
330         }
331
332         /* draw the next column */
333         x= 0;
334         if(player[plid].q%4)
335                 if(id==0)
336                         mapDrawCol(&mv[0], mv[0].tx - 1, mv[0].ty-1, x, player, mv->page->dx);
337                 else
338                         modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*(mv[0].page->tilesh+2));
339         //}
340 }
341
342
343 void near mapScrollUp(map_view_t *mv, player_t *player, word id, word plid)
344 {
345         word x, y;  /* coordinate for drawing */
346
347         /* increment the pixel position and update the page */
348         mv[id].page->dy -= player[plid].speed;
349
350         /* check to see if this changes the tile */
351         if(mv[id].page->dy == 0 )
352         {
353         /* go down one tile */
354         mv[id].ty--;
355         /* Snap the origin downward */
356         mv[id].page->data -= mv[id].page->width*4;
357         mv[id].page->dy = mv[id].map->tiles->tileHeight;
358         }
359
360         /* draw the next row */
361         y= 0;
362         if(player[plid].q%3)
363                 if(id==0)
364                         mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty-1, y, player, mv->page->dy);
365                 else
366                         modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*(mv[0].page->tilesw+2), mv[id].map->tiles->tileHeight);
367         //}
368 }
369
370 void near mapScrollDown(map_view_t *mv, player_t *player, word id, word plid)
371 {
372         word x, y;  /* coordinate for drawing */
373
374         /* increment the pixel position and update the page */
375         mv[id].page->dy += player[plid].speed;
376
377         /* check to see if this changes the tile */
378         if(mv[id].page->dy >= mv[id].dyThresh )
379         {
380         /* go down one tile */
381         mv[id].ty++;
382         /* Snap the origin downward */
383         mv[id].page->data += mv[id].page->width*4;
384         mv[id].page->dy = mv[id].map->tiles->tileHeight;
385         }
386
387         /* draw the next row */
388         y= mv[0].page->sh + mv[id].map->tiles->tileHeight;
389         if(player[plid].q%3)
390                 if(id==0)
391                         mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty+mv[0].page->tilesh, y, player, mv->page->dy);
392                 else
393                         modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*(mv[0].page->tilesw+2), mv[id].map->tiles->tileHeight);
394         //}
395 }
396
397 sword chkmap(map_t *map, word q)
398 {
399 //      bitmap_t bp;
400         static byte x[(MAPW*MAPH)+1] =
401 { 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,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 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 };
402 /*1,    2,      3,      4,      0,      3,      3,      3,      3,      3,      3,      3,      3,      4,      1,      1,      1,      1,      1,      1,      \
403 5,      6,      7,      8,      0,      1,      0,      1,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
404 9,      10,     11,     12,     4,      1,      0,      1,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
405 13,     14,     15,     16,     0,      1,      1,      1,      5,      8,      1,      11,     11,     1,      1,      1,      1,      1,      1,      1,      \
406 0,      0,      4,      0,      0,      0,      0,      0,      8,      8,      1,      11,     11,     3,      1,      1,      1,      1,      1,      1,      \
407 1,      1,      1,      1,      0,      0,      0,      0,      8,      8,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
408 1,      1,      1,      1,      0,      0,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
409 1,      1,      1,      1,      0,      0,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      3,      1,      1,      1,      \
410 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
411 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
412 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      3,      1,      1,      1,      \
413 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
414 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      3,      1,      1,      1,      \
415 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
416 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      3,      3,      3,      3,      1,      2,      3,      4 };*/
417         //check for failed to load map
418         if((map->width == map->height == 0) && (q>0))
419         {
420                 //initiate a null map!
421                 map->width=MAPW;///2;
422                 map->height=MAPH;///2;
423 //              map->data = malloc(((map->width*map->height)+1)*sizeof(byte));
424                 map->data = &x;
425                 map->tiles = malloc(sizeof(tiles_t));
426                 //fix this to be far~
427 //              bp = bitmapLoadPcx("data/ed.pcx");
428 //              map->tiles->data = &bp;
429                 map->tiles->debug_data = map->data;
430                 map->tiles->tileHeight = 16;
431                 map->tiles->tileWidth = 16;
432                 map->tiles->rows = 1;
433                 map->tiles->cols = 1;
434                 map->tiles->debug_text = true;
435         }
436         else map->tiles->debug_text = false;
437         return 0;
438 }
439
440 void mapGoTo(map_view_t *mv, int tx, int ty)
441 {
442         int px, py;
443         unsigned int i;
444
445         /* set up the coordinates */
446         mv->tx = tx;
447         mv->ty = ty;
448         mv->page->dx = mv->map->tiles->tileWidth;
449         mv->page->dy = mv->map->tiles->tileHeight;
450
451         /* set up the thresholds */
452         mv->dxThresh = mv->map->tiles->tileWidth * 2;
453         mv->dyThresh = mv->map->tiles->tileHeight * 2;
454
455         /* draw the tiles */
456         modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
457         py=0;
458         i=mv->ty * mv->map->width + mv->tx;
459         for(ty=mv->ty-1; py < mv->page->sh+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
460                 mapDrawWRow(mv, tx-1, ty, py);
461         i+=mv->map->width - tx;
462         }
463 }
464
465
466 void near
467 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y)
468 {
469         word rx;
470         word ry;
471         word textx=0;
472         word texty=0;
473         //if(i==0) i=2;
474         if(i==0)
475         {
476                 //wwww
477                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 0); //currently the over scan color!
478         }
479         else
480         {
481                 rx = (((i-1) % ((t->data->width)/t->tileWidth)) * t->tileWidth);
482                 ry = (((i-1) / ((t->data->height)/t->tileHeight)) * t->tileHeight);
483 ////0000printf("i=%d\n", i);
484                 switch(t->debug_text)
485                 {
486                         case 0:
487 #ifndef TILERENDER
488                                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, ((t->debug_data[i])+1));
489                                 //cannot print number value du to it being slow as bakapee
490 #else
491                                 PBUFBFUN                (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
492                                 /* then the sprite. note modding ram ptr means we just draw to (x&3,0) */
493                                 //draw_vrl1_vgax_modex(x-rx,y-ry,vrl_header,vrl_lineoffs,buffer+sizeof(*vrl_header),bufsz-sizeof(*vrl_header));
494                                 //modexDrawBmpRegion    (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
495 #endif
496                         break;
497                         case 1:
498                                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, (t->debug_data[i]+1));
499                                 //modexprintbig(page, x, y, 1, 15, 0, (t->debug_data));
500                                 /*for(texty=0; texty<2; texty++)
501                                 {
502                                         for(textx=0; textx<2; textx++)
503                                         {*/
504 //                                              modexprint(page, x+(textx*8), y+(texty*8), 1, (word)(t->debug_data), 0, (t->debug_data));
505 /*                                      }
506                                 }*/
507                         break;
508                 }
509         }
510 }
511
512 void near mapDrawRow(map_view_t *mv, int tx, int ty, word y, player_t *p, word poopoffset)
513 {
514         word x;
515         int i;
516         poopoffset%=p[0].speed;
517 //printf("y: %d\n", poopoffset);
518         /* the position within the map array */
519         i=ty * mv->map->width + tx;
520         for(x=poopoffset; x<(mv->page->sw+mv->dxThresh)/(poopoffset+1) && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
521         if(i>=0) {
522                 /* we are in the map, so copy! */
523                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
524         }
525         i++; /* next! */
526         }
527 }
528
529 void near mapDrawCol(map_view_t *mv, int tx, int ty, word x, player_t *p, word poopoffset)
530 {
531         int y;
532         int i;
533         poopoffset%=p[0].speed;
534 //printf("x: %d\n", poopoffset);
535         /* location in the map array */
536         i=ty * mv->map->width + tx;
537
538         /* We'll copy all of the columns in the screen,
539            i + 1 row above and one below */
540         for(y=poopoffset; y<(mv->page->sh+mv->dyThresh)/(poopoffset+1) && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
541         if(i>=0) {
542                 /* we are in the map, so copy away! */
543                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
544         }
545         i += mv->map->width;
546         }
547 }
548
549 void mapDrawWRow(map_view_t *mv, int tx, int ty, word y)
550 {
551         word x;
552         int i;
553
554         /* the position within the map array */
555         i=ty * mv->map->width + tx;
556         for(x=0; x<mv->page->sw+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
557         if(i>=0) {
558                 /* we are in the map, so copy! */
559                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
560         }
561         i++; /* next! */
562         }
563 }
564
565 void mapDrawWCol(map_view_t *mv, int tx, int ty, word x)
566 {
567         int y;
568         int i;
569
570         /* location in the map array */
571         i=ty * mv->map->width + tx;
572
573         /* We'll copy all of the columns in the screen,
574            i + 1 row above and one below */
575         for(y=0; y<mv->page->sh+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
576         if(i>=0) {
577                 /* we are in the map, so copy away! */
578                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
579         }
580         i += mv->map->width;
581         }
582 }
583
584 /*void qclean()
585 {
586         //setkb(0);
587 }*/
588
589 unsigned char shinku_fps_indicator_page = 0;
590
591 /*      sync    */
592 void shinku(global_game_variables_t *gv)
593 {
594         //modexCopyPageRegion(pip[1].page, pip[2].page, 16, 16, 16, 16, (14*8)+4, 8+4);
595         if(elapsed_timer(gv) >= (1.0 / gv->kurokku.frames_per_second))
596         {
597                 word x = (16) + gv->video.page[shinku_fps_indicator_page].dx; // follow the screen
598                 word y = (16) + gv->video.page[shinku_fps_indicator_page].dy; // follow the screen
599                 word col = 7;
600                 word bgcol = 0;
601                 word type = 0;
602
603                 //t=(((*(gv->clock))-gv->clock_start) /18.2);
604                 sprintf(gv->pee, "%f fps", (double)gv->kurokku.tiku/ticktock(gv));
605 //              printf("%s\n", gv->pee);
606                 //FIXME PLEASE!!
607                 modexprint(&(gv->video.page[shinku_fps_indicator_page]), x, y, type, col, bgcol, gv->pee);
608 //++++  modexprint(&(gv->video.page[0]), x, y, type, col, bgcol, gv->pee);
609                 //(gv->clock_start)=*(gv->clock);
610                 gv->kurokku.tiku=0;
611         }
612         //modexprint(page, 16, 16, 1, 15, 0, pee);
613         gv->kurokku.tiku++;
614         switch(gv->kurokku.fpscap)
615         {
616                 case 0:
617                         //modexprint(page, 16, 32, 1, 15, 0, "sanic!");
618                         gv->kurokku.frames_per_second=1;
619                 break;
620                 case 1:
621                         //turn this off if XT
622                         modexWaitBorder();
623                         //vga_wait_for_vsync();
624                         gv->kurokku.frames_per_second=60;
625                 break;
626         }
627 }
628
629 void near animatePlayer(map_view_t *pip, player_t *player, word pn, sword scrollswitch)
630 {
631         sword x = player[pn].x;
632         sword y = player[pn].y;
633 #ifdef SPRITE
634         word dire=32; //direction
635 #else
636         word dire=8; //direction
637 #endif
638         sword qq; //scroll offset
639         word ls = player[pn].persist_aniframe;
640
641         if(scrollswitch==0) qq = 0;
642         else qq = ((player[pn].q)*(player[pn].speed));
643         x-=4;
644         y-=TILEWH;
645         switch (player[pn].d)
646         {
647                 case 0:
648                         //up
649                         dire*=player[pn].d;
650                         y-=qq;
651                 break;
652                 case 3:
653                         // right
654                         dire*=(player[pn].d-2);
655                         x+=qq;
656                 break;
657                 case 2:
658                 break;
659                 case 4:
660                         //down
661                         dire*=(player[pn].d-2);
662                         y+=qq;
663                 break;
664                 case 1:
665                         //left
666                         dire*=(player[pn].d+2);
667                         x-=qq;
668                 break;
669         }
670
671 #ifdef SPRITE
672 // #define FRAME1 PBUFSFUN(pip[1].page, x, y, 48, dire, 24, 32, PLAYERBMPDATA);
673 // #define FRAME2 PBUFSFUN(pip[1].page, x, y, 24, dire, 24, 32, PLAYERBMPDATA);
674 // #define FRAME3 PBUFSFUN(pip[1].page, x, y, 0, dire, 24, 32,  PLAYERBMPDATA);
675 // #define FRAME4 PBUFSFUN(pip[1].page, x, y, 24, dire, 24, 32, PLAYERBMPDATA);
676 #define FRAME1 PBUFSFUN(pip[1].page, x, y, 48, dire, 24, 32,    PLAYERBMPDATA);
677 #define FRAME2 PBUFSFUN(pip[1].page, x, y, 24, dire, 24, 32,    PLAYERBMPDATA);
678 #define FRAME3 PBUFSFUN(pip[1].page, x, y, 0, dire, 24, 32,     PLAYERBMPDATA);
679 #define FRAME4 PBUFSFUN(pip[1].page, x, y, 24, dire, 24, 32,    PLAYERBMPDATA);
680 #else
681 #define FRAME1 modexClearRegion(pip[1].page, x, y, 24, 32, 2+dire);
682 #define FRAME2 modexClearRegion(pip[1].page, x, y, 24, 32, 1+dire);
683 #define FRAME3 modexClearRegion(pip[1].page, x, y, 24, 32, dire);
684 #define FRAME4 modexClearRegion(pip[1].page, x, y, 24, 32, 1+dire);
685 #endif
686         modexCopyPageRegion(pip[1].page, pip[0].page, x-4, y-4, x-4, y-4, 28, 40);
687         //modexCopyPageRegion(pip[2].page, pip[1].page, 16, 16, 16, 16, (14*8)+4, 8+4);
688         if(2>ls && ls>=1) { FRAME1 }else
689         if(3>ls && ls>=2) { FRAME2 }else
690         if(4>ls && ls>=3) { FRAME3 }else
691         if(5>ls && ls>=4) { FRAME4 }
692         //TODO: mask copy //modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
693         //modexClearRegion(top->page, 66, 66, 2, 40, 0);
694         //modexCopyPageRegion(dest->page, top->page, 66, 66, 66, 66, 2, 40);
695 }