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