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