1 /* Project 16 Source Code~
2 * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
4 * This file is part of Project 16.
6 * Project 16 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * Project 16 is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
19 * Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "src/lib/scroll16.h"
26 #include "src/lib/16_sprite.h"
28 void walk(map_view_t *pip, player_t *player, word pn)
30 #define INC_PER_FRAME if(player[pn].q&1) player[pn].persist_aniframe++; if(player[pn].persist_aniframe>4) player[pn].persist_aniframe = 1;
31 //printf("player[%d].d=%d\n", pn, player[pn].d);
36 //0000pip[0].video->startclk = (*clockw);
40 //printf("pip[0].page->tilesw=%d ", pip[0].page->tilesw); printf("pip[0].page->tw=%d\n", pip[0].page->tw);
41 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 &&
42 !(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!
44 if(player[pn].q<=player[pn].spt)
47 animatePlayer(pip, player, pn, 1);
48 ScrollRight(pip, player, 3, pn);
49 ScrollRight(pip, player, 2, pn);
50 mapScrollRight(pip, player, !(pip[0].video->p), pn);
51 mapScrollRight(pip, player, (pip[0].video->p), pn);
52 if(!pageflipflop) modexShowPage(pip[1].page);
54 //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
55 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
57 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))
59 if(player[pn].q<=player[pn].spt)
62 player[pn].x+=(player[pn].speed);
63 animatePlayer(pip, player, pn, 0);
64 if(!pageflipflop) modexShowPage(pip[1].page);
66 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
70 if(!pageflipflop) modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x, player[pn].y-TILEWH, player[pn].x, player[pn].y-TILEWH, 16, 32);
72 //PBUFSFUN(pip[0].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 16, 32, PLAYERBMPDATA);
73 animate_spri(player[pn].spri);
75 modexClearRegion(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 14);
77 if(!pageflipflop) modexShowPage(pip[1].page);
80 player[pn].triggerx = player[pn].tx+1;
81 player[pn].triggery = player[pn].ty;
86 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 &&
87 !(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!
89 if(player[pn].q<=player[pn].spt)
92 animatePlayer(pip, player, pn, 1);
93 ScrollLeft(pip, player, 3, pn);
94 ScrollLeft(pip, player, 2, pn);
95 mapScrollLeft(pip, player, !(pip[0].video->p), pn);
96 mapScrollLeft(pip, player, (pip[0].video->p), pn);
97 if(!pageflipflop) modexShowPage(pip[1].page);
99 //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
100 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
102 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))
104 if(player[pn].q<=player[pn].spt)
107 player[pn].x-=(player[pn].speed);
108 animatePlayer(pip, player, pn, 0);
109 if(!pageflipflop) modexShowPage(pip[1].page);
111 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
115 if(!pageflipflop) modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x, player[pn].y-TILEWH, player[pn].x, player[pn].y-TILEWH, 16, 32);
117 //PBUFSFUN(pip[0].page, player[pn].x, player[pn].y-TILEWH, 16, 96, 16, 32, PLAYERBMPDATA);
118 animate_spri(player[pn].spri);
120 modexClearRegion(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 10);
122 if(!pageflipflop) modexShowPage(pip[1].page);
125 player[pn].triggerx = player[pn].tx-1;
126 player[pn].triggery = player[pn].ty;
131 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 &&
132 !(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!
134 if(player[pn].q<=player[pn].spt)
137 animatePlayer(pip, player, pn, 1);
138 ScrollDown(pip, player, 3, pn);
139 ScrollDown(pip, player, 2, pn);
140 mapScrollDown(pip, player, !(pip[0].video->p), pn);
141 mapScrollDown(pip, player, (pip[0].video->p), pn);
142 if(!pageflipflop) modexShowPage(pip[1].page);
144 //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
145 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
147 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))
149 if(player[pn].q<=player[pn].spt)
152 player[pn].y+=(player[pn].speed);
153 animatePlayer(pip, player, pn, 0);
154 if(!pageflipflop) modexShowPage(pip[1].page);
156 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
160 if(!pageflipflop) modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x, player[pn].y-TILEWH, player[pn].x, player[pn].y-TILEWH, 16, 32);
162 //PBUFSFUN(pip[0].page, player[pn].x, player[pn].y-TILEWH, 16, 64, 16, 32, PLAYERBMPDATA);
163 animate_spri(player[pn].spri);
165 modexClearRegion(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 9);
167 if(!pageflipflop) modexShowPage(pip[1].page);
170 player[pn].triggerx = player[pn].tx;
171 player[pn].triggery = player[pn].ty+1;
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 &&
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!
179 if(player[pn].q<=player[pn].spt)
182 animatePlayer(pip, player, pn, 1);
183 ScrollUp(pip, player, 3, pn);
184 ScrollUp(pip, player, 2, pn);
185 mapScrollUp(pip, player, !(pip[0].video->p), pn);
186 mapScrollUp(pip, player, (pip[0].video->p), pn);
187 if(!pageflipflop) modexShowPage(pip[1].page);
189 //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
190 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
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))
194 if(player[pn].q<=player[pn].spt)
197 player[pn].y-=(player[pn].speed);
198 animatePlayer(pip, player, 0, pn);
199 if(!pageflipflop) modexShowPage(pip[1].page);
201 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
205 if(!pageflipflop) modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x, player[pn].y-TILEWH, player[pn].x, player[pn].y-TILEWH, 16, 32);
207 //PBUFSFUN(pip[0].page, player[pn].x, player[pn].y-TILEWH, 16, 0, 16, 32, PLAYERBMPDATA);
208 animate_spri(player[pn].spri);
210 modexClearRegion(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 12);
212 if(!pageflipflop) modexShowPage(pip[1].page);
215 player[pn].triggerx = player[pn].tx;
216 player[pn].triggery = player[pn].ty-1;
222 void panpagemanual(map_view_t *pip, player_t *player, word pn)
228 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)
230 if(player[pn].q<=player[pn].spt)
232 pip[pip[0].pan->pn].page->dx+=4;
233 modexShowPage(pip[pip[0].pan->pn].page);
235 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].tx++; }
241 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)
243 if(player[pn].q<=player[pn].spt)
245 pip[pip[0].pan->pn].page->dx-=4;
246 modexShowPage(pip[pip[0].pan->pn].page);
248 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].tx--; }
254 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)
256 if(player[pn].q<=player[pn].spt)
258 pip[pip[0].pan->pn].page->dy+=4;
259 modexShowPage(pip[pip[0].pan->pn].page);
261 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].ty++; }
267 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)
269 if(player[pn].q<=player[pn].spt)
271 pip[pip[0].pan->pn].page->dy-=4;
272 modexShowPage(pip[pip[0].pan->pn].page);
274 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].ty--; }
278 //if (player[pn].d!=2) printf("player[%u].d=%u player[%u].q=%u\n", pn, player[pn].d, pn, player[pn].q);
282 allocMap(int w, int h) {
287 result.data = malloc(sizeof(byte) * w * h);
288 //result.data = (byte *)alloc_emem(((int)sizeof(byte) * w * h)/1024);
289 if(isEMS() || checkEMS())
292 //emmhandle = mallocEMS(coretotalEMS());//alloc_emem((int)sizeof(map))
293 mm.length=sizeof(result);
295 mm.sourceOff=ptr2long(&result);
298 ist = move_emem(&mm);
299 if(!ist){ dealloc_emem(emmhandle); exit(5); }
300 printf("%d\n", coretotalEMS());
307 initMap(map_t *map) {
308 // just a place holder to fill out an alternating pattern
312 //if(!isEMS() || !checkEMS())
313 // map->tiles = malloc(sizeof(tiles_t));
315 // map->tiles = (tiles_t *)alloc_emem(sizeof(tiles_t));
317 //create the tile set
318 //if(!isEMS() || !checkEMS())
319 // map->tiles->data = malloc(sizeof(bitmap_t));
321 // map->tiles->data = (bitmap_t *)alloc_emem(sizeof(bitmap_t));
322 // map->tiles->data->width = (TILEWH);
323 // map->tiles->data->height= TILEWH;
324 //if(!isEMS() || !checkEMS())
325 // map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
327 // map->tiles->data->data = (byte *)alloc_emem((TILEWH*2)*TILEWH);
328 // map->tiles->tileHeight = TILEWH;
329 // map->tiles->tileWidth =TILEWH;
330 // map->tiles->rows = 1;
331 // map->tiles->cols = 1;//2;
334 //for(y=0; y<map->height; y++) {
335 //for(x=0; x<map->width; x++) {
337 for(yy=0; yy<TILEWH; yy++) {
338 for(xx=0; xx<(TILEWH); xx++) {
340 map->tiles->data->data[i+1] = map->data[q];//28;//0x24;
341 // printf("[%d]", map->tiles->data->data[i]);
343 //map->tiles->data->data[i] = map->data[q];//0;//0x34;
344 //printf("]%d[==[%d]", i, map->tiles->data->data[i]);
350 // printf("[%d]", map->data[q]);
357 for(y=0; y<map->height; y++) {
358 for(x=0; x<map->width; x++) {
360 printf("[%d]", map->data[i]);
361 //tile = tile ? 0 : 1;
364 //tile = tile ? 0 : 1;
368 void near mapScrollRight(map_view_t *mv, player_t *player, word id, word plid)
370 word x, y; /* coordinate for drawing */
372 /* increment the pixel position and update the page */
373 mv[id].page->dx += player[plid].speed;
375 /* check to see if this changes the tile */
376 if(mv[id].page->dx >= mv[id].dxThresh )
378 /* go forward one tile */
380 /* Snap the origin forward */
381 mv[id].page->data += 4;
383 mv[id].page->dx = mv[id].map->tiles->tileWidth;
386 /* draw the next column */
387 x= mv[0].page->sw + mv[id].map->tiles->tileWidth;
390 mapDrawCol(&mv[0], mv[0].tx + mv[0].page->tw, mv[0].ty-1, x, player, mv->page->dx);
392 if(!pageflipflop && !pageploop)
393 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));
398 void near mapScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
400 word x, y; /* coordinate for drawing */
402 /* decrement the pixel position and update the page */
403 mv[id].page->dx -= player[plid].speed;
405 /* check to see if this changes the tile */
406 if(mv[id].page->dx == 0)
408 /* go backward one tile */
410 /* Snap the origin backward */
411 mv[id].page->data -= 4;
413 mv[id].page->dx = mv[id].map->tiles->tileWidth;
416 /* draw the next column */
420 mapDrawCol(&mv[0], mv[0].tx - 1, mv[0].ty-1, x, player, mv->page->dx);
422 if(!pageflipflop && !pageploop)
423 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));
428 void near mapScrollUp(map_view_t *mv, player_t *player, word id, word plid)
430 word x, y; /* coordinate for drawing */
432 /* decrement the pixel position and update the page */
433 mv[id].page->dy -= player[plid].speed;
435 /* check to see if this changes the tile */
436 if(mv[id].page->dy == 0 )
438 /* go down one tile */
440 /* Snap the origin downward */
441 mv[id].page->data -= mv[id].page->pi;
443 mv[id].page->dy = mv[id].map->tiles->tileHeight;
446 /* draw the next row */
450 mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty-1, y, player, mv->page->dy);
452 if(!pageflipflop && !pageploop)
453 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);
457 void near mapScrollDown(map_view_t *mv, player_t *player, word id, word plid)
459 word x, y; /* coordinate for drawing */
461 /* increment the pixel position and update the page */
462 mv[id].page->dy += player[plid].speed;
464 /* check to see if this changes the tile */
465 if(mv[id].page->dy >= mv[id].dyThresh )
467 /* go down one tile */
469 /* Snap the origin downward */
470 mv[id].page->data += mv[id].page->pi;
472 mv[id].page->dy = mv[id].map->tiles->tileHeight;
475 /* draw the next row */
476 y= mv[0].page->sh + mv[id].map->tiles->tileHeight;
479 mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty+mv[0].page->th, y, player, mv->page->dy);
481 if(!pageflipflop && !pageploop)
482 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);
487 //TODO finish this wwww
488 void near ScrollRight(map_view_t *mv, player_t *player, word id, word plid)
490 /* increment the pixel position and update the page */
491 mv[id].page->dx += player[plid].speed;
493 /* check to see if this changes the tile */
494 if(mv[id].page->dx >= mv[0].dxThresh )
496 // vga_setup_wm1_block_copy();
497 // _fmemmove(mv[id].page->data+4, mv[id].page->data, mv[id].page->pagesize);
498 // vga_restore_rm0wm0();
499 /* Snap the origin forward */
500 mv[id].page->data += 4;
501 mv[id].page->dx = mv[0].map->tiles->tileWidth;
505 void near ScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
507 /* decrement the pixel position and update the page */
508 mv[id].page->dx -= player[plid].speed;
510 /* check to see if this changes the tile */
511 if(mv[id].page->dx == 0)
513 // vga_setup_wm1_block_copy();
514 // _fmemmove(mv[id].page->data-4, mv[id].page->data, mv[id].page->pagesize);
515 // vga_restore_rm0wm0();
516 /* Snap the origin backward */
517 mv[id].page->data -= 4;
518 mv[id].page->dx = mv[0].map->tiles->tileWidth;
522 void near ScrollUp(map_view_t *mv, player_t *player, word id, word plid)
524 /* decrement the pixel position and update the page */
525 mv[id].page->dy -= player[plid].speed;
527 /* check to see if this changes the tile */
528 if(mv[id].page->dy == 0)
530 // vga_setup_wm1_block_copy();
531 // _fmemmove(mv[id].page->data-mv[id].page->pi, mv[id].page->data, mv[id].page->pagesize);
532 // vga_restore_rm0wm0();
533 /* Snap the origin backward */
534 mv[id].page->data -= mv[id].page->pi;
535 mv[id].page->dy = mv[0].map->tiles->tileWidth;
539 void near ScrollDown(map_view_t *mv, player_t *player, word id, word plid)
541 /* increment the pixel position and update the page */
542 mv[id].page->dy += player[plid].speed;
544 /* check to see if this changes the tile */
545 if(mv[id].page->dy >= mv[0].dxThresh )
547 // vga_setup_wm1_block_copy();
548 // _fmemmove(mv[id].page->data+mv[id].page->pi, mv[id].page->data, mv[id].page->pagesize);
549 // vga_restore_rm0wm0();
550 /* Snap the origin forward */
551 mv[id].page->data += mv[id].page->pi;
552 mv[id].page->dy = mv[0].map->tiles->tileWidth;
556 sword chkmap(map_t *map, word q)
559 static byte x[(MAPW*MAPH)+1] =
560 { 1, 2, 3, 4, 0, 3, 3, 3, 3, 3, 3, 3, 3, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 6, 7, 8, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 10, 11, 12, 4, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
575 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 1, 2, 3, 4 };*/
576 //check for failed to load map
577 if((map->width == map->height == 0) && (q>0))
579 //initiate a null map!
580 map->width=MAPW;///2;
581 map->height=MAPH;///2;
582 // map->data = malloc(((map->width*map->height)+1)*sizeof(byte));
584 map->tiles = malloc(sizeof(tiles_t));
585 //fix this to be far~
586 // bp = bitmapLoadPcx("data/ed.pcx");
587 // map->tiles->data = &bp;
588 map->tiles->debug_data = map->data;
589 map->tiles->tileHeight = 16;
590 map->tiles->tileWidth = 16;
591 map->tiles->rows = 1;
592 map->tiles->cols = 1;
593 map->tiles->debug_text = true;
595 else map->tiles->debug_text = false;
599 //TODO: player position here
600 void mapGoTo(map_view_t *mv, int tx, int ty)
605 /* set up the coordinates */
606 mv[0].tx = mv[1].tx = tx;
607 mv[0].ty = mv[1].ty = ty;
608 mv[0].page->dx = mv[1].page->dx = mv[2].page->dx = mv[3].page->dx = mv->map->tiles->tileWidth;
609 mv[0].page->dy = mv[1].page->dy = mv[2].page->dy = mv[3].page->dy = mv->map->tiles->tileHeight;
611 /* set up the thresholds */
612 mv[0].dxThresh = mv[1].dxThresh = mv[2].dxThresh = mv[3].dxThresh = mv->map->tiles->tileWidth * 2;
613 mv[0].dyThresh = mv[1].dyThresh = mv[2].dxThresh = mv[3].dxThresh = mv->map->tiles->tileHeight * 2;
616 modexClearRegion(mv[0].page, 0, 0, mv[0].page->width, mv[0].page->height, 0);
618 i=mv[0].ty * mv[0].map->width + mv[0].tx;
619 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) {
620 mapDrawWRow(&mv[0], tx-1, ty, py);
621 i+=mv->map->width - tx;
623 if(!pageploop) modexCopyPageRegion(mv[1].page, mv[0].page, 0, 0, 0, 0, mv[0].page->width, mv[0].page->height);
625 // unsigned int k,j,o;
626 // /* fill screen with a distinctive pattern */
627 // for (k=0;k < vga_state.vga_width;k++) {
629 // vga_write_sequencer(0x02/*map mask*/,1 << (k&3));
630 // 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)
631 // vga_state.vga_graphics_ram[o] = (k^j)&15; // VRL samples put all colors in first 15!
634 modexCopyPageRegion(mv[3].page, mv[0].page, 0/**/, 0/**/, 0, 0, 16, 32);
638 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y)
648 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 0); //currently the over scan color!
652 rx = (((i-1) % ((t->data->width)/t->tileWidth)) * t->tileWidth);
653 ry = (((i-1) / ((t->data->height)/t->tileHeight)) * t->tileHeight);
654 ////0000printf("i=%d\n", i);
655 switch(t->debug_text)
659 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, ((t->debug_data[i])+1));
660 //modexprint(page, x, y, 1, 15, 0, (char const *)(t->debug_data[i]));
662 PBUFBFUN (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
663 /* then the sprite. note modding ram ptr means we just draw to (x&3,0) */
664 //draw_vrl1_vgax_modex(x-rx,y-ry,vrl_header,vrl_lineoffs,buffer+sizeof(*vrl_header),bufsz-sizeof(*vrl_header));
665 //modexDrawBmpRegion (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
669 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, (t->debug_data[i])+1);
670 //modexprintbig(page, x, y, 1, 15, 0, (t->debug_data));
671 /*for(texty=0; texty<2; texty++)
673 for(textx=0; textx<2; textx++)
675 // modexprint(page, x+(textx*8), y+(texty*8), 1, (word)(t->debug_data), 0, (t->debug_data));
683 void near mapDrawRow(map_view_t *mv, int tx, int ty, word y, player_t *p, word poopoffset)
687 poopoffset%=p[0].speed;
688 //printf("y: %d\n", poopoffset);
689 /* the position within the map array */
690 i=ty * mv->map->width + tx;
691 for(x=poopoffset; x<(mv->page->sw+mv->dxThresh)/(poopoffset+1) && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
693 /* we are in the map, so copy! */
694 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
700 void near mapDrawCol(map_view_t *mv, int tx, int ty, word x, player_t *p, word poopoffset)
704 poopoffset%=p[0].speed;
705 //printf("x: %d\n", poopoffset);
706 /* location in the map array */
707 i=ty * mv->map->width + tx;
709 /* We'll copy all of the columns in the screen,
710 i + 1 row above and one below */
711 for(y=poopoffset; y<(mv->page->sh+mv->dyThresh)/(poopoffset+1) && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
713 /* we are in the map, so copy away! */
714 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
720 void mapDrawWRow(map_view_t *mv, int tx, int ty, word y)
725 /* the position within the map array */
726 i=ty * mv->map->width + tx;
727 for(x=0; x<mv->page->sw+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
729 /* we are in the map, so copy! */
730 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
736 void mapDrawWCol(map_view_t *mv, int tx, int ty, word x)
741 /* location in the map array */
742 i=ty * mv->map->width + tx;
744 /* We'll copy all of the columns in the screen,
745 i + 1 row above and one below */
746 for(y=0; y<mv->page->sh+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
748 /* we are in the map, so copy away! */
749 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
760 unsigned char shinku_fps_indicator_page = 2;
761 boolean pageflipflop = 1;
762 boolean pageploop = 1;
765 void shinku(global_game_variables_t *gv)
767 word x = (0) + gv->video.page[/*!*/(gv->video.p)].dx; // follow the screen
768 word y = (0) + gv->video.page[/*!*/(gv->video.p)].dy; // follow the screen
769 word w = 64, h = 8, col = 7, bgcol = 0, type = 1;
771 //modexCopyPageRegion(pip[1].page, pip[2].page, 16, 16, 16, 16, (14*8)+4, 8+4);
772 /* block copy to visible RAM from offscreen */
773 // vga_setup_wm1_block_copy();
774 // modexCopyPageRegion(&(gv->video.page[shinku_fps_indicator_page]), &(gv->video.page[!shinku_fps_indicator_page]), x, y, x+w, 0, w, h);
775 // o = *(gv->video.page[2].data); // source offscreen
776 // o2 = *(gv->video.page[shinku_fps_indicator_page].data)+(y * vga_state.vga_stride) + (x >> 2); // dest visible (original stride)
777 // 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);
778 /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
779 // vga_restore_rm0wm0();
780 if(elapsed_timer(gv) >= (1.0 / gv->kurokku.frames_per_second))
782 sprintf(gv->pee, "%.0f fps", (double)gv->kurokku.tiku/ticktock(gv));
783 //modexClearRegion(&(gv->video.page[shinku_fps_indicator_page]), x, y, w, h, 45);
784 modexprint(&(gv->video.page[/*!*/(gv->video.p)]), x, y, type, col, bgcol, gv->pee);
786 /* block copy to visible RAM from offscreen */
787 // vga_setup_wm1_block_copy();
788 // o = *(gv->video.page[shinku_fps_indicator_page].data); // source offscreen
789 // o2 = *(gv->video.page[2].data)+(y * vga_state.vga_stride) + (x >> 2); // dest visible (original stride)
790 // 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);
791 // modexCopyPageRegion(&(gv->video.page[shinku_fps_indicator_page]), &(gv->video.page[!shinku_fps_indicator_page]), x, y, x, 0, w, h);
792 /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
793 // vga_restore_rm0wm0();
794 }else //copy dat sheet
797 switch(gv->kurokku.fpscap)
800 //modexprint(&(gv->video.page[shinku_fps_indicator_page]), x, y+8, type, col, bgcol, "sanic!");
801 gv->kurokku.frames_per_second=1;
804 //turn this off if XT
806 vga_wait_for_vsync();
807 gv->kurokku.frames_per_second=60;
812 //vga_setup_wm1_block_copy();
813 //_fmemcpy((gv->video.page[(gv->video.p)]).data, (gv->video.page[(!gv->video.p)]).data, gv->video.page[(!gv->video.p)].pagesize);
814 //vga_restore_rm0wm0();
815 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);
816 modexShowPage(&(gv->video.page[gv->video.p]));
817 if(!pageploop) gv->video.p=!gv->video.p;
818 gv->video.r=!gv->video.r;
819 //0000gv->video.tickclk = ((*clockw)-gv->video.startclk)/18.2;
824 void near animatePlayer(map_view_t *pip, player_t *player, word pn, sword scrollswitch)
826 sword x = player[pn].x;
827 sword y = player[pn].y;
828 sword bx = x+16; //buffer's x
829 sword by = y+16; //buffer's y
830 word dire=32; //direction
831 sword qq; //scroll offset
832 word ls = player[pn].persist_aniframe;
840 qq = ((player[pn].q)*(player[pn].speed));
844 y-=pip[0].map->tiles->tileHeight;
845 switch (player[pn].d)
855 dire*=(player[pn].d-2);
863 dire*=(player[pn].d-2);
869 dire*=(player[pn].d+2);
876 //#define FRAME1 PBUFSFUN(pip[/*!*/(pip->video->p)].page, x, y, 32, dire, 16, 32, PLAYERBMPDATA);
877 //#define FRAME2 PBUFSFUN(pip[/*!*/(pip->video->p)].page, x, y, 16, dire, 16, 32, PLAYERBMPDATA);
878 //#define FRAME3 PBUFSFUN(pip[/*!*/(pip->video->p)].page, x, y, 0, dire, 16, 32, PLAYERBMPDATA);
879 //#define FRAME4 PBUFSFUN(pip[/*!*/(pip->video->p)].page, x, y, 16, dire, 16, 32, PLAYERBMPDATA);
880 #define FRAME1 animate_spri(player[pn].spri);
881 #define FRAME2 animate_spri(player[pn].spri);
882 #define FRAME3 animate_spri(player[pn].spri);
883 #define FRAME4 animate_spri(player[pn].spri);
885 #define FRAME1 modexClearRegion(pip[/*!*/(pip->video->p)].page, x, y, 16, 32, 2+dire);
886 #define FRAME2 modexClearRegion(pip[/*!*/(pip->video->p)].page, x, y, 16, 32, 1+dire);
887 #define FRAME3 modexClearRegion(pip[/*!*/(pip->video->p)].page, x, y, 16, 32, dire);
888 #define FRAME4 modexClearRegion(pip[/*!*/(pip->video->p)].page, x, y, 16, 32, 1+dire);
891 modexCopyPageRegion(pip[1].page, pip[0].page, x-4, y-4, x-4, y-4, 28, 36);
893 //copy old bg to page0
894 //modexCopyPageRegion(pip[3].page, pip[0].page, bx, by, 0, 0, 20, 36);
896 //modexCopyPageRegion(pip[0].page, pip[3].page, 0, 0, x, y, 20, 36);
898 //modexCopyPageRegion(page_t *dest, page_t *src, word sx, word sy, word dx, word dy, word width, word height);
899 //modexCopyPageRegion(pip[3].page, pip[!(pip->video->p)].page, x-4, y-4, 0, 128, 28, 36);
900 /*modexCopyPageRegion(pip[pip->video->p].page,
901 pip[!(pip->video->p)].page, x-4, y-4, x-4, y-4, 28, 36);*/
902 // else modexCopyPageRegion(pip[1].page, pip[0].page, x-4, y-4, x-4, y-4, 28, 40);
918 // if(2>ls && ls>=1) { FRAME1 }else
919 // if(3>ls && ls>=2) { FRAME2 }else
920 // if(4>ls && ls>=3) { FRAME3 }else
921 // if(5>ls && ls>=4) { FRAME4 }
922 //modexCopyPageRegion(pip[0].page, pip[3].page, 0, 0, x, y, 16, 32);
923 //printf("x=%d y=%d bx=%d by=%d\n", x, y, bx, by);