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