OSDN Git Service

wwww
[proj16/16.git] / src / lib / scroll.c
1 #include "src\lib\modex16.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "src\lib\dos_kb.h"
5 #include "src\lib\wtest\wtest.c"
6
7 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
8
9 typedef struct {
10         bitmap_t *data;
11         word tileHeight;
12         word tileWidth;
13         unsigned int rows;
14         unsigned int cols;
15 } tiles_t;
16
17
18 typedef struct {
19         byte    *data;
20         tiles_t *tiles;
21         int width;
22         int height;
23 } map_t;
24
25
26 typedef struct {
27         map_t *map;
28         page_t *page;
29         int tx; //appears to be the top left tile position on the viewable screen map
30         int ty; //appears to be the top left tile position on the viewable screen map
31         word dxThresh; //????
32         word dyThresh; //????
33 } map_view_t;
34
35 //TODO: make this into actor_t
36 struct {
37         int x; //player exact position on the viewable map
38         int y; //player exact position on the viewable map
39         int tx; //player tile position on the viewable map
40         int ty; //player tile position on the viewable map
41         int triggerx; //player's trigger box tile position on the viewable map
42         int triggery; //player's trigger box tile position on the viewable map
43         int hp; //hitpoints of the player
44 } player;
45
46
47 map_t allocMap(int w, int h);
48 void initMap(map_t *map);
49 void mapScrollRight(map_view_t *mv, byte offset, short lp);
50 void mapScrollLeft(map_view_t *mv, byte offest, short lp);
51 void mapScrollUp(map_view_t *mv, byte offset, short lp);
52 void mapScrollDown(map_view_t *mv, byte offset, short lp);
53 void mapGoTo(map_view_t *mv, int tx, int ty);
54 void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);
55 void mapDrawRow(map_view_t *mv, int tx, int ty, word y, word poopoffset);
56 void mapDrawCol(map_view_t *mv, int tx, int ty, word x, word poopoffset);
57 void mapDrawWRow(map_view_t *mv, int tx, int ty, word y);
58 void mapDrawWCol(map_view_t *mv, int tx, int ty, word x);
59 void animatePlayer(map_view_t *src, map_view_t *dest, short d1, short d2, int x, int y, int ls, int lp, bitmap_t *bmp);
60
61 #define TILEWH 16
62 #define QUADWH (TILEWH/4)
63 #define SPEED 4
64
65 //place holder definitions
66 #define MAPX 200
67 #define MAPY 150
68 #define TRIGGX 10
69 #define TRIGGY 9
70 //#define SWAP(a, b) tmp=a; a=b; b=tmp;
71 void main() {
72         bitmap_t ptmp; // player sprite
73         word q=1;
74         const char *cpus;
75         //static int persist_aniframe = 0;    /* gonna be increased to 1 before being used, so 0 is ok for default */
76         page_t screen, screen2, screen3;
77         map_t map;
78         map_view_t mv, mv2, mv3;
79         map_view_t *bg, *spri, *mask;//, *tmp;
80         byte *ptr;
81
82         /* create the map */
83         map = allocMap(MAPX,MAPY); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be drawn properly
84         initMap(&map);
85         mv.map = &map;
86         mv2.map = &map;
87         mv3.map = &map;
88
89         /* draw the tiles */
90         ptr = map.data;
91         /*data\\*/
92         ptmp = bitmapLoadPcx("ptmp.pcx"); // load sprite
93         setkb(1);
94         modexEnter();
95         modexPalUpdate(ptmp.palette);
96         screen = modexDefaultPage();
97         screen.width += (TILEWH*2);
98         screen.height += (TILEWH*2)+QUADWH;
99         mv.page = &screen;
100         screen2 = modexNextPage(mv.page);
101         mv2.page = &screen2;
102         screen3 = screen2;
103         mv3.page = &screen3;
104
105         /* set up paging */
106         bg = &mv;
107         spri = &mv2;
108         mask = &mv3;
109
110 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
111         mapGoTo(bg, 0, 0);
112         mapGoTo(spri, 0, 0);
113         //mapGoTo(mask, 0, 0);
114
115         //TODO: put player in starting position of spot
116         //default player position on the viewable map
117         player.tx = bg->tx + 10;
118         player.ty = bg->ty + 8;
119         player.x = player.tx*TILEWH;
120         player.y = player.ty*TILEWH;
121         player.triggerx = player.tx;
122         player.triggery = player.ty+1;
123         //TODO: erase player initial draw
124         modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
125         //temp draw trigger box
126         modexClearRegion(spri->page, player.triggerx*16, player.triggery*16, 16, 16, 1);
127         modexClearRegion(bg->page, player.triggerx*16, player.triggery*16, 16, 16, 1);
128         modexShowPage(spri->page);
129         while(!keyp(1))//!keyp(1))
130         {
131         //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
132         //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
133         //when player.tx or player.ty == 0 or player.tx == 20 or player.ty == 15 then stop because that is edge of map and you do not want to walk of the map
134
135         #define INC_PER_FRAME if(q&1) persist_aniframe++; if(persist_aniframe>4) persist_aniframe = 1;
136
137         //temp testing
138                 /*if(bg->tx >= 0 && bg->tx+20 < MAPX && player.tx == bg->tx + 10)
139                 {
140                         for(q=1; q<=(TILEWH/SPEED); q++)
141                         {
142                                 //INC_PER_FRAME;
143                                 //animatePlayer(bg, spri, mask, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);
144                                 //animatePlayer(bg, spri, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);
145                                 mapScrollRight(bg, SPEED);
146                                 //mapScrollRight(spri, SPEED);
147                                 //mapScrollRight(mask, SPEED);
148                                 modexShowPage(bg->page);
149                         }
150                         player.tx++;
151                 }
152                 else if(player.tx < MAPX)
153                 {
154                         for(q=1; q<=(TILEWH/SPEED); q++)
155                         {
156                                 INC_PER_FRAME;
157                                 player.x+=SPEED;
158                                 //animatePlayer(bg, spri, mask, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp);
159                                 animatePlayer(bg, spri, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp);
160                                 modexShowPage(spri->page);
161                         }
162                         player.tx++;
163                 }
164                 else
165                 {
166 break;
167                 }*/
168         if(keyp(77) && !keyp(75))
169         {
170                 if(bg->tx >= 0 && bg->tx+20 < MAPX && player.tx == bg->tx + 10 && !(player.tx+1 == TRIGGX && player.ty == TRIGGY))
171                 {
172                         for(q=1; q<=(TILEWH/SPEED); q++)
173                         {
174                                 INC_PER_FRAME;
175                                 //animatePlayer(bg, spri, mask, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);
176                                 animatePlayer(bg, spri, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);
177                                 mapScrollRight(bg, SPEED, q);
178                                 mapScrollRight(spri, SPEED, q);
179                                 //mapScrollRight(mask, SPEED);
180                                 modexShowPage(spri->page);
181                         }
182                         player.tx++;
183                 }
184                 else if(player.tx < MAPX && !(player.tx+1 == TRIGGX && player.ty == TRIGGY))
185                 {
186                         for(q=1; q<=(TILEWH/SPEED); q++)
187                         {
188                                 INC_PER_FRAME;
189                                 player.x+=SPEED;
190                                 //animatePlayer(bg, spri, mask, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp);
191                                 animatePlayer(bg, spri, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp);
192                                 modexShowPage(spri->page);
193                         }
194                         player.tx++;
195                 }
196                 else
197                 {
198                         modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
199                         modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 32, 24, 32, &ptmp);
200                         modexShowPage(spri->page);
201                 }
202                 player.triggerx = player.tx+1;
203                 player.triggery = player.ty;
204         }
205
206         if(keyp(75) && !keyp(77))
207         {
208                 if(bg->tx > 0 && bg->tx+20 <= MAPX && player.tx == bg->tx + 10 && !(player.tx-1 == TRIGGX && player.ty == TRIGGY))
209                 {
210                         for(q=1; q<=(TILEWH/SPEED); q++)
211                         {
212                                 INC_PER_FRAME;
213                                 //animatePlayer(bg, spri, mask, 3, 1, player.x, player.y, persist_aniframe, q, &ptmp);
214                                 animatePlayer(bg, spri, 3, 1, player.x, player.y, persist_aniframe, q, &ptmp);
215                                 mapScrollLeft(bg, SPEED, q);
216                                 mapScrollLeft(spri, SPEED, q);
217                                 //mapScrollLeft(mask, SPEED);
218                                 modexShowPage(spri->page);
219                         }
220                         player.tx--;
221                 }
222                 else if(player.tx > 1 && !(player.tx-1 == TRIGGX && player.ty == TRIGGY))
223                 {
224                         for(q=1; q<=(TILEWH/SPEED); q++)
225                         {
226                                 INC_PER_FRAME;
227                                 player.x-=SPEED;
228                                 //animatePlayer(bg, spri, mask, 3, 0, player.x, player.y, persist_aniframe, q, &ptmp);
229                                 animatePlayer(bg, spri, 3, 0, player.x, player.y, persist_aniframe, q, &ptmp);
230                                 modexShowPage(spri->page);
231                         }
232                         player.tx--;
233                 }
234                 else
235                 {
236                         modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
237                         modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 96, 24, 32, &ptmp);
238                         modexShowPage(spri->page);
239                 }
240                 player.triggerx = player.tx-1;
241                 player.triggery = player.ty;
242         }
243
244         if(keyp(80) && !keyp(72))
245         {
246                 if(bg->ty >= 0 && bg->ty+15 < MAPY && player.ty == bg->ty + 8 && !(player.tx == TRIGGX && player.ty+1 == TRIGGY))
247                 {
248                         for(q=1; q<=(TILEWH/SPEED); q++)
249                         {
250                                 INC_PER_FRAME;
251                                 //animatePlayer(bg, spri, mask, 2, 1, player.x, player.y, persist_aniframe, q, &ptmp);
252                                 animatePlayer(bg, spri, 2, 1, player.x, player.y, persist_aniframe, q, &ptmp);
253                                 mapScrollDown(bg, SPEED, q);
254                                 mapScrollDown(spri, SPEED, q);
255                                 //mapScrollDown(mask, SPEED);
256                                 modexShowPage(spri->page);
257                         }
258                         player.ty++;
259                 }
260                 else if(player.ty < MAPY && !(player.tx == TRIGGX && player.ty+1 == TRIGGY))
261                 {
262                         for(q=1; q<=(TILEWH/SPEED); q++)
263                         {
264                                 INC_PER_FRAME;
265                                 player.y+=SPEED;
266                                 //animatePlayer(bg, spri, mask, 2, 0, player.x, player.y, persist_aniframe, q, &ptmp);
267                                 animatePlayer(bg, spri, 2, 0, player.x, player.y, persist_aniframe, q, &ptmp);
268                                 modexShowPage(spri->page);
269                         }
270                         player.ty++;
271                 }
272                 else
273                 {
274                         modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
275                         modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
276                         modexShowPage(spri->page);
277                 }
278                 player.triggerx = player.tx;
279                 player.triggery = player.ty+1;
280         }
281
282         if(keyp(72) && !keyp(80))
283         {
284                 if(bg->ty > 0 && bg->ty+15 <= MAPY && player.ty == bg->ty + 8 && !(player.tx == TRIGGX && player.ty-1 == TRIGGY))
285                 {
286                         for(q=1; q<=(TILEWH/SPEED); q++)
287                         {
288                                 INC_PER_FRAME;
289                                 //animatePlayer(bg, spri, mask, 0, 1, player.x, player.y, persist_aniframe, q, &ptmp);
290                                 animatePlayer(bg, spri, 0, 1, player.x, player.y, persist_aniframe, q, &ptmp);
291                                 mapScrollUp(bg, SPEED, q);
292                                 mapScrollUp(spri, SPEED, q);
293                                 //mapScrollUp(mask, SPEED);
294                                 modexShowPage(spri->page);
295                         }
296                         player.ty--;
297                 }
298                 else if(player.ty > 1 && !(player.tx == TRIGGX &&  player.ty-1 == TRIGGY))
299                 {
300                         for(q=1; q<=(TILEWH/SPEED); q++)
301                         {
302                                 INC_PER_FRAME;
303                                 player.y-=SPEED;
304                                 //animatePlayer(bg, spri, mask, 0, 0, player.x, player.y, persist_aniframe, q, &ptmp);
305                                 modexShowPage(spri->page);
306                                 animatePlayer(bg, spri, 0, 0, player.x, player.y, persist_aniframe, q, &ptmp);
307                         }
308                         player.ty--;
309                 }
310                 else
311                 {
312                         modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
313                         modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 0, 24, 32, &ptmp);
314                         modexShowPage(spri->page);
315                 }
316                 player.triggerx = player.tx;
317                 player.triggery = player.ty-1;
318         }
319         //modexClearRegion(mask->page, 66, 66, 2, 40, 0);
320
321         if((player.triggerx == TRIGGX && player.triggery == TRIGGY) && keyp(KEY_ENTER))
322         {
323                 short i;
324                 for(i=600; i>=400; i--)
325                 {
326                         sound(i);
327                 }
328                 nosound();
329         }
330         }
331
332         modexLeave();
333         setkb(0);
334         printf("Project 16 scroll.exe\n");
335         printf("tx: %d\n", bg->tx);
336         printf("ty: %d\n", bg->ty);
337         printf("player.x: %d\n", player.x);
338         printf("player.y: %d\n", player.y);
339         printf("player.tx: %d\n", player.tx);
340         printf("player.ty: %d\n", player.ty);
341         printf("player.triggx: %d\n", player.triggerx);
342         printf("player.triggy: %d\n", player.triggery);
343         printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");
344         printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");
345         printf("\n");
346         switch(detectcpu())
347         {
348                 case 0: cpus = "8086/8088 or 186/88"; break;
349                 case 1: cpus = "286"; break;
350                 case 2: cpus = "386 or newer"; break;
351                 default: cpus = "internal error"; break;
352         }
353         printf("detected CPU type: %s\n", cpus);
354 }
355
356
357 map_t
358 allocMap(int w, int h) {
359         map_t result;
360
361         result.width =w;
362         result.height=h;
363         result.data = malloc(sizeof(byte) * w * h);
364
365         return result;
366 }
367
368
369 void
370 initMap(map_t *map) {
371         /* just a place holder to fill out an alternating pattern */
372         int x, y;
373         int i;
374         int tile = 1;
375         map->tiles = malloc(sizeof(tiles_t));
376
377         /* create the tile set */
378         map->tiles->data = malloc(sizeof(bitmap_t));
379         map->tiles->data->width = (TILEWH*2);
380         map->tiles->data->height= TILEWH;
381         map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
382         map->tiles->tileHeight = TILEWH;
383         map->tiles->tileWidth =TILEWH;
384         map->tiles->rows = 1;
385         map->tiles->cols = 2;
386
387         i=0;
388         for(y=0; y<TILEWH; y++) {
389         for(x=0; x<(TILEWH*2); x++) {
390                 if(x<TILEWH)
391                   map->tiles->data->data[i] = 28;//0x24;
392                 else
393                   map->tiles->data->data[i] = 0;//0x34;
394                 i++;
395         }
396         }
397
398         i=0;
399         for(y=0; y<map->height; y++) {
400                 for(x=0; x<map->width; x++) {
401                         map->data[i] = tile;
402                         tile = tile ? 0 : 1;
403                         i++;
404                 }
405                 tile = tile ? 0 : 1;
406         }
407 }
408
409
410 void
411 mapScrollRight(map_view_t *mv, byte offset, short lp) {
412         word x, y;  /* coordinate for drawing */
413
414         /* increment the pixel position and update the page */
415         mv->page->dx += offset;
416
417         /* check to see if this changes the tile */
418         if(mv->page->dx >= mv->dxThresh ) {
419         /* go forward one tile */
420         mv->tx++;
421         /* Snap the origin forward */
422         mv->page->data += 4;
423         mv->page->dx = mv->map->tiles->tileWidth;
424         //}
425
426         /* draw the next column */
427         x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
428         //if(lp%4)
429                 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x, mv->page->dx);
430         }
431 }
432
433
434 void
435 mapScrollLeft(map_view_t *mv, byte offset, short lp) {
436         word x, y;  /* coordinate for drawing */
437
438         /* increment the pixel position and update the page */
439         mv->page->dx -= offset;
440
441         /* check to see if this changes the tile */
442         if(mv->page->dx == 0) {
443         /* go backward one tile */
444         mv->tx--;
445
446         /* Snap the origin backward */
447         mv->page->data -= 4;
448         mv->page->dx = mv->map->tiles->tileWidth;
449         //}
450         /* draw the next column */
451         //if(lp%4)
452                 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0, mv->page->dx);
453         }
454 }
455
456
457 void
458 mapScrollUp(map_view_t *mv, byte offset, short lp) {
459         word x, y;  /* coordinate for drawing */
460
461         /* increment the pixel position and update the page */
462         mv->page->dy -= offset;
463
464         /* check to see if this changes the tile */
465         if(mv->page->dy == 0 ) {
466         /* go down one tile */
467         mv->ty--;
468         /* Snap the origin downward */
469         mv->page->data -= mv->page->width*4;
470         mv->page->dy = mv->map->tiles->tileHeight;
471         //}
472
473         /* draw the next row */
474         y= 0;
475         //if(lp%3)
476                 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y, mv->page->dy);
477         }
478 }
479
480
481 void
482 mapScrollDown(map_view_t *mv, byte offset, short lp) {
483         word x, y;  /* coordinate for drawing */
484
485         /* increment the pixel position and update the page */
486         mv->page->dy += offset;
487
488         /* check to see if this changes the tile */
489         if(mv->page->dy >= mv->dyThresh ) {
490         /* go down one tile */
491         mv->ty++;
492         /* Snap the origin downward */
493         mv->page->data += mv->page->width*4;
494         mv->page->dy = mv->map->tiles->tileHeight;
495         //}
496
497         /* draw the next row */
498         y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
499         //if(lp%3)
500                 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y, mv->page->dy);
501         }
502
503 }
504
505
506 void
507 mapGoTo(map_view_t *mv, int tx, int ty) {
508         int px, py;
509         unsigned int i;
510
511         /* set up the coordinates */
512         mv->tx = tx;
513         mv->ty = ty;
514         mv->page->dx = mv->map->tiles->tileWidth;
515         mv->page->dy = mv->map->tiles->tileHeight;
516
517         /* set up the thresholds */
518         mv->dxThresh = mv->map->tiles->tileWidth * 2;
519         mv->dyThresh = mv->map->tiles->tileHeight * 2;
520
521         /* draw the tiles */
522         modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
523         py=0;
524         i=mv->ty * mv->map->width + mv->tx;
525         for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
526                 mapDrawWRow(mv, tx-1, ty, py);
527         i+=mv->map->width - tx;
528         }
529 }
530
531
532 void
533 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
534         word rx;
535         word ry;
536         rx = (i % t->cols) * t->tileWidth;
537         ry = (i / t->cols) * t->tileHeight;
538         modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
539 }
540
541
542 void
543 mapDrawRow(map_view_t *mv, int tx, int ty, word y, word poopoffset) {
544         word x;
545         int i;
546         poopoffset%=SPEED;
547 //printf("y: %d\n", poopoffset);
548         /* the position within the map array */
549         i=ty * mv->map->width + tx;
550         for(x=poopoffset; x<(SCREEN_WIDTH+mv->dxThresh)/(poopoffset+1) && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
551         if(i>=0) {
552                 /* we are in the map, so copy! */
553                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
554         }
555         i++; /* next! */
556         }
557 }
558
559
560 void
561 mapDrawCol(map_view_t *mv, int tx, int ty, word x, word poopoffset) {
562         int y;
563         int i;
564         poopoffset%=SPEED;
565 //printf("x: %d\n", poopoffset);
566         /* location in the map array */
567         i=ty * mv->map->width + tx;
568
569         /* We'll copy all of the columns in the screen,
570            i + 1 row above and one below */
571         for(y=poopoffset; y<(SCREEN_HEIGHT+mv->dyThresh)/(poopoffset+1) && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
572         if(i>=0) {
573                 /* we are in the map, so copy away! */
574                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
575         }
576         i += mv->map->width;
577         }
578 }
579
580 void
581 mapDrawWRow(map_view_t *mv, int tx, int ty, word y) {
582         word x;
583         int i;
584
585         /* the position within the map array */
586         i=ty * mv->map->width + tx;
587         for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
588         if(i>=0) {
589                 /* we are in the map, so copy! */
590                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
591         }
592         i++; /* next! */
593         }
594 }
595
596 void
597 mapDrawWCol(map_view_t *mv, int tx, int ty, word x) {
598         int y;
599         int i;
600
601         /* location in the map array */
602         i=ty * mv->map->width + tx;
603
604         /* We'll copy all of the columns in the screen,
605            i + 1 row above and one below */
606         for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
607         if(i>=0) {
608                 /* we are in the map, so copy away! */
609                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
610         }
611         i += mv->map->width;
612         }
613 }
614
615 //              animatePlayer(map_view_t *src, map_view_t *dest, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);
616 //              animatePlayer(bg, spri, 0, 1, player.x, player.y, persist_aniframe, q, &ptmp);
617 //              animatePlayer(bg, spri, 0, 0, player.x, player.y, persist_aniframe, q, &ptmp);
618 //              animatePlayer(map_view_t *src, map_view_t *dest, player_t *player, word playnum, sword scrolloffsetswitch, int ls, bitmap_t *bmp)
619 void    animatePlayer(map_view_t *src, map_view_t *dest, short d1, short d2, int x, int y, int ls, int lp, bitmap_t *bmp)
620 {
621         short dire=32*d1; //direction
622         short qq; //scroll offset
623
624         if(d2==0) qq = 0;
625         else qq = ((lp)*SPEED);
626         switch (d1)
627         {
628                 case 0:
629                         //up
630                         x=x-4;
631                         y=y-qq-TILEWH;
632                 break;
633                 case 1:
634                         // right
635                         x=x+qq-4;
636                         y=y-TILEWH;
637                 break;
638                 case 2:
639                         //down
640                         x=x-4;
641                         y=y+qq-TILEWH;
642                 break;
643                 case 3:
644                         //left
645                         x=x-qq-4;
646                         y=y-TILEWH;
647                 break;
648         }
649         modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
650         if(2>ls && ls>=1) { modexDrawSpriteRegion(dest->page, x, y, 48, dire, 24, 32, bmp); }else
651         if(3>ls && ls>=2) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }else
652         if(4>ls && ls>=3) { modexDrawSpriteRegion(dest->page, x, y, 0, dire, 24, 32, bmp); }else
653         if(5>ls && ls>=4) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }
654         //TODO: mask copy //modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
655         //modexClearRegion(top->page, 66, 66, 2, 40, 0);
656         //modexCopyPageRegion(dest->page, top->page, 66, 66, 66, 66, 2, 40);
657         //turn this off if XT
658         if(detectcpu() > 0) modexWaitBorder();
659 }