]> 4ch.mooo.com Git - 16.git/blob - src/scroll.c
5e561a8323b9a79fce944642af8c5537db46a0be
[16.git] / src / 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, /*map_view_t *top, */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("dxThresh: %d\n", bg->dxThresh);
344         printf("dyThresh: %d\n", bg->dyThresh);
345         printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");
346         printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");
347         printf("\n");
348         switch(detectcpu())
349         {
350                 case 0: cpus = "8086/8088 or 186/88"; break;
351                 case 1: cpus = "286"; break;
352                 case 2: cpus = "386 or newer"; break;
353                 default: cpus = "internal error"; break;
354         }
355         printf("detected CPU type: %s\n", cpus);
356 }
357
358
359 map_t
360 allocMap(int w, int h) {
361         map_t result;
362
363         result.width =w;
364         result.height=h;
365         result.data = malloc(sizeof(byte) * w * h);
366
367         return result;
368 }
369
370
371 void
372 initMap(map_t *map) {
373         /* just a place holder to fill out an alternating pattern */
374         int x, y;
375         int i;
376         int tile = 1;
377         map->tiles = malloc(sizeof(tiles_t));
378
379         /* create the tile set */
380         map->tiles->data = malloc(sizeof(bitmap_t));
381         map->tiles->data->width = (TILEWH*2);
382         map->tiles->data->height= TILEWH;
383         map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
384         map->tiles->tileHeight = TILEWH;
385         map->tiles->tileWidth =TILEWH;
386         map->tiles->rows = 1;
387         map->tiles->cols = 2;
388
389         i=0;
390         for(y=0; y<TILEWH; y++) {
391         for(x=0; x<(TILEWH*2); x++) {
392                 if(x<TILEWH)
393                   map->tiles->data->data[i] = 28;//0x24;
394                 else
395                   map->tiles->data->data[i] = 0;//0x34;
396                 i++;
397         }
398         }
399
400         i=0;
401         for(y=0; y<map->height; y++) {
402                 for(x=0; x<map->width; x++) {
403                         map->data[i] = tile;
404                         tile = tile ? 0 : 1;
405                         i++;
406                 }
407                 tile = tile ? 0 : 1;
408         }
409 }
410
411
412 void
413 mapScrollRight(map_view_t *mv, byte offset, short lp) {
414         word x, y;  /* coordinate for drawing */
415
416         /* increment the pixel position and update the page */
417         mv->page->dx += offset;
418
419         /* check to see if this changes the tile */
420         if(mv->page->dx >= mv->dxThresh ) {
421         /* go forward one tile */
422         mv->tx++;
423         /* Snap the origin forward */
424         mv->page->data += 4;
425         mv->page->dx = mv->map->tiles->tileWidth;
426         }
427
428         /* draw the next column */
429         x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
430         if(lp%2)
431         //mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x, mv->page->dx);
432         mapDrawWCol(mv, mv->tx + 20 , mv->ty-1, x);
433         //}
434 }
435
436
437 void
438 mapScrollLeft(map_view_t *mv, byte offset, short lp) {
439         word x, y;  /* coordinate for drawing */
440
441         /* increment the pixel position and update the page */
442         mv->page->dx -= offset;
443
444         /* check to see if this changes the tile */
445         if(mv->page->dx == 0) {
446         /* go backward one tile */
447         mv->tx--;
448                 
449         /* Snap the origin backward */
450         mv->page->data -= 4;
451         mv->page->dx = mv->map->tiles->tileWidth;
452         }
453         /* draw the next column */
454         if(lp%2)
455         //mapDrawCol(mv, mv->tx-1, mv->ty-1, 0, mv->page->dx);
456         mapDrawWCol(mv, mv->tx-1, mv->ty-1, 0);
457         //}
458 }
459
460
461 void
462 mapScrollUp(map_view_t *mv, byte offset, short lp) {
463         word x, y;  /* coordinate for drawing */
464
465         /* increment the pixel position and update the page */
466         mv->page->dy -= offset;
467
468         /* check to see if this changes the tile */
469         if(mv->page->dy == 0 ) {
470         /* go down one tile */
471         mv->ty--;
472         /* Snap the origin downward */
473         mv->page->data -= mv->page->width*4;
474         mv->page->dy = mv->map->tiles->tileHeight;
475         }
476
477         /* draw the next row */
478         y= 0;
479         if(lp%3)
480         //mapDrawRow(mv, mv->tx-1 , mv->ty-1, y, mv->page->dy);
481         mapDrawWRow(mv, mv->tx-1 , mv->ty-1, y);
482         //}
483 }
484
485
486 void
487 mapScrollDown(map_view_t *mv, byte offset, short lp) {
488         word x, y;  /* coordinate for drawing */
489
490         /* increment the pixel position and update the page */
491         mv->page->dy += offset;
492
493         /* check to see if this changes the tile */
494         if(mv->page->dy >= mv->dyThresh ) {
495         /* go down one tile */
496         mv->ty++;
497         /* Snap the origin downward */
498         mv->page->data += mv->page->width*4;
499         mv->page->dy = mv->map->tiles->tileHeight;
500         }
501
502         /* draw the next row */
503         y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
504         if(lp%3)
505         //mapDrawRow(mv, mv->tx-1 , mv->ty+15, y, mv->page->dy);
506         mapDrawWRow(mv, mv->tx-1 , mv->ty+15, y);
507         //}
508
509 }
510
511
512 void
513 mapGoTo(map_view_t *mv, int tx, int ty) {
514         int px, py;
515         unsigned int i;
516
517         /* set up the coordinates */
518         mv->tx = tx;
519         mv->ty = ty;
520         mv->page->dx = mv->map->tiles->tileWidth;
521         mv->page->dy = mv->map->tiles->tileHeight;
522
523         /* set up the thresholds */
524         mv->dxThresh = mv->map->tiles->tileWidth * 2;
525         mv->dyThresh = mv->map->tiles->tileHeight * 2;
526
527         /* draw the tiles */
528         modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
529         py=0;
530         i=mv->ty * mv->map->width + mv->tx;
531         for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
532                 mapDrawWRow(mv, tx-1, ty, py);
533         i+=mv->map->width - tx;
534         }
535 }
536
537
538 void
539 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
540         word rx;
541         word ry;
542         rx = (i % t->cols) * t->tileWidth;
543         ry = (i / t->cols) * t->tileHeight;
544         modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
545 }
546
547
548 void 
549 mapDrawRow(map_view_t *mv, int tx, int ty, word y, word poopoffset) {
550         word x;
551         int i;
552         poopoffset%=6;
553
554         /* the position within the map array */
555         i=ty * mv->map->width + tx;
556         for(x=poopoffset; x<(SCREEN_WIDTH+mv->dxThresh)/(poopoffset+1) && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
557         if(i>=0) {
558                 /* we are in the map, so copy! */
559                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
560         }
561         i++; /* next! */
562         }
563 }
564
565
566 void 
567 mapDrawCol(map_view_t *mv, int tx, int ty, word x, word poopoffset) {
568         int y;
569         int i;
570         poopoffset%=4;
571
572         /* location in the map array */
573         i=ty * mv->map->width + tx;
574
575         /* We'll copy all of the columns in the screen, 
576            i + 1 row above and one below */
577         for(y=poopoffset; y<(SCREEN_HEIGHT+mv->dyThresh)/(poopoffset+1) && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
578         if(i>=0) {
579                 /* we are in the map, so copy away! */
580                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
581         }
582         i += mv->map->width;
583         }
584 }
585
586 void 
587 mapDrawWRow(map_view_t *mv, int tx, int ty, word y) {
588         word x;
589         int i;
590
591         /* the position within the map array */
592         i=ty * mv->map->width + tx;
593         for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
594         if(i>=0) {
595                 /* we are in the map, so copy! */
596                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
597         }
598         i++; /* next! */
599         }
600 }
601
602 void 
603 mapDrawWCol(map_view_t *mv, int tx, int ty, word x) {
604         int y;
605         int i;
606
607         /* location in the map array */
608         i=ty * mv->map->width + tx;
609
610         /* We'll copy all of the columns in the screen, 
611            i + 1 row above and one below */
612         for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
613         if(i>=0) {
614                 /* we are in the map, so copy away! */
615                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
616         }
617         i += mv->map->width;
618         }
619 }
620
621 void
622 animatePlayer(map_view_t *src, map_view_t *dest, /*map_view_t *top, */short d1, short d2, int x, int y, int ls, int lp, bitmap_t *bmp)
623 {
624         short dire=32*d1; //direction
625         short qq; //scroll offset
626
627         if(d2==0) qq = 0;
628         else qq = ((lp)*SPEED);
629         switch (d1)
630         {
631                 case 0:
632                         //up
633                         x=x-4;
634                         y=y-qq-TILEWH;
635                 break;
636                 case 1:
637                         // right
638                         x=x+qq-4;
639                         y=y-TILEWH;
640                 break;
641                 case 2:
642                         //down
643                         x=x-4;
644                         y=y+qq-TILEWH;
645                 break;
646                 case 3:
647                         //left
648                         x=x-qq-4;
649                         y=y-TILEWH;
650                 break;
651         }
652         modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
653         if(2>ls && ls>=1) { modexDrawSpriteRegion(dest->page, x, y, 48, dire, 24, 32, bmp); }else
654         if(3>ls && ls>=2) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }else
655         if(4>ls && ls>=3) { modexDrawSpriteRegion(dest->page, x, y, 0, dire, 24, 32, bmp); }else
656         if(5>ls && ls>=4) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }
657         //TODO: mask copy //modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
658         //modexClearRegion(top->page, 66, 66, 2, 40, 0);
659         //modexCopyPageRegion(dest->page, top->page, 66, 66, 66, 66, 2, 40);
660         //turn this off if XT
661         if(detectcpu() > 0) modexWaitBorder();
662 }