OSDN Git Service

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