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