1 /* Project 16 Source Code~
2 * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123
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"
27 void walk(map_view_t *pip, player_t *player, word pn)
29 #define INC_PER_FRAME if(player[pn].q&1) player[pn].persist_aniframe++; if(player[pn].persist_aniframe>4) player[pn].persist_aniframe = 1;
30 //printf("player[%d].d=%d\n", pn, player[pn].d);
35 //0000pip[0].video->startclk = (*clockw);
39 //printf("pip[0].page->tilesw=%d ", pip[0].page->tilesw); printf("pip[0].page->tw=%d\n", pip[0].page->tw);
40 if(pip[0].tx >= 0 && pip[0].tx+pip[0].page->tw < pip[0].map->width && player[pn].tx == pip[0].tx+pip[0].page->tilemidposscreenx &&
41 !(pip[0].map->data[(player[pn].tx)+(pip[0].map->width*(player[pn].ty-1))] == 0))//!(player[pn].tx+1 == TRIGGX && player[pn].ty == TRIGGY)) //collision detection!
43 if(player[pn].q<=player[pn].spt)
46 animatePlayer(pip, player, pn, 1);
47 ScrollRight(pip, player, 3, pn);
48 ScrollRight(pip, player, 2, pn);
49 mapScrollRight(pip, player, !(pip[0].video->p), pn);
50 mapScrollRight(pip, player, (pip[0].video->p), pn);
51 if(!pageflipflop) modexShowPage(pip[1].page);
53 //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
54 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
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))
58 if(player[pn].q<=player[pn].spt)
61 player[pn].x+=(player[pn].speed);
62 animatePlayer(pip, player, pn, 0);
63 if(!pageflipflop) modexShowPage(pip[1].page);
65 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
69 if(!pageflipflop) modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x, player[pn].y-TILEWH, player[pn].x, player[pn].y-TILEWH, 16, 32);
71 PBUFSFUN(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 16, 32, PLAYERBMPDATA);
73 modexClearRegion(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 14);
75 if(!pageflipflop) modexShowPage(pip[1].page);
78 player[pn].triggerx = player[pn].tx+1;
79 player[pn].triggery = player[pn].ty;
84 if(pip[0].tx > 0 && pip[0].tx+pip[0].page->tw <= pip[0].map->width && player[pn].tx == pip[0].tx+pip[0].page->tilemidposscreenx &&
85 !(pip[0].map->data[(player[pn].tx-2)+(pip[0].map->width*(player[pn].ty-1))] == 0))//!(player[pn].tx-1 == TRIGGX && player[pn].ty == TRIGGY)) //collision detection!
87 if(player[pn].q<=player[pn].spt)
90 animatePlayer(pip, player, pn, 1);
91 ScrollLeft(pip, player, 3, pn);
92 ScrollLeft(pip, player, 2, pn);
93 mapScrollLeft(pip, player, !(pip[0].video->p), pn);
94 mapScrollLeft(pip, player, (pip[0].video->p), pn);
95 if(!pageflipflop) modexShowPage(pip[1].page);
97 //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
98 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
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))
102 if(player[pn].q<=player[pn].spt)
105 player[pn].x-=(player[pn].speed);
106 animatePlayer(pip, player, pn, 0);
107 if(!pageflipflop) modexShowPage(pip[1].page);
109 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
113 if(!pageflipflop) modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x, player[pn].y-TILEWH, player[pn].x, player[pn].y-TILEWH, 16, 32);
115 PBUFSFUN(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 96, 16, 32, PLAYERBMPDATA);
117 modexClearRegion(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 10);
119 if(!pageflipflop) modexShowPage(pip[1].page);
122 player[pn].triggerx = player[pn].tx-1;
123 player[pn].triggery = player[pn].ty;
128 if(pip[0].ty >= 0 && pip[0].ty+pip[0].page->th < pip[0].map->height && player[pn].ty == pip[0].ty+pip[0].page->tilemidposscreeny &&
129 !(pip[0].map->data[(player[pn].tx-1)+(pip[0].map->width*(player[pn].ty))] == 0))//!(player[pn].tx == TRIGGX && player[pn].ty+1 == TRIGGY)) //collision detection!
131 if(player[pn].q<=player[pn].spt)
134 animatePlayer(pip, player, pn, 1);
135 ScrollDown(pip, player, 3, pn);
136 ScrollDown(pip, player, 2, pn);
137 mapScrollDown(pip, player, !(pip[0].video->p), pn);
138 mapScrollDown(pip, player, (pip[0].video->p), pn);
139 if(!pageflipflop) modexShowPage(pip[1].page);
141 //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
142 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
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))
146 if(player[pn].q<=player[pn].spt)
149 player[pn].y+=(player[pn].speed);
150 animatePlayer(pip, player, pn, 0);
151 if(!pageflipflop) modexShowPage(pip[1].page);
153 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
157 if(!pageflipflop) modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x, player[pn].y-TILEWH, player[pn].x, player[pn].y-TILEWH, 16, 32);
159 PBUFSFUN(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 64, 16, 32, PLAYERBMPDATA);
161 modexClearRegion(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 9);
163 if(!pageflipflop) modexShowPage(pip[1].page);
166 player[pn].triggerx = player[pn].tx;
167 player[pn].triggery = player[pn].ty+1;
172 if(pip[0].ty > 0 && pip[0].ty+pip[0].page->th <= pip[0].map->height && player[pn].ty == pip[0].ty+pip[0].page->tilemidposscreeny &&
173 !(pip[0].map->data[(player[pn].tx-1)+(pip[0].map->width*(player[pn].ty-2))] == 0))//!(player[pn].tx == TRIGGX && player[pn].ty-1 == TRIGGY)) //collision detection!
175 if(player[pn].q<=player[pn].spt)
178 animatePlayer(pip, player, pn, 1);
179 ScrollUp(pip, player, 3, pn);
180 ScrollUp(pip, player, 2, pn);
181 mapScrollUp(pip, player, !(pip[0].video->p), pn);
182 mapScrollUp(pip, player, (pip[0].video->p), pn);
183 if(!pageflipflop) modexShowPage(pip[1].page);
185 //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
186 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
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))
190 if(player[pn].q<=player[pn].spt)
193 player[pn].y-=(player[pn].speed);
194 animatePlayer(pip, player, 0, pn);
195 if(!pageflipflop) modexShowPage(pip[1].page);
197 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
201 if(!pageflipflop) modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x, player[pn].y-TILEWH, player[pn].x, player[pn].y-TILEWH, 16, 32);
203 PBUFSFUN(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 0, 16, 32, PLAYERBMPDATA);
205 modexClearRegion(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 12);
207 if(!pageflipflop) modexShowPage(pip[1].page);
210 player[pn].triggerx = player[pn].tx;
211 player[pn].triggery = player[pn].ty-1;
217 void panpagemanual(map_view_t *pip, player_t *player, word pn)
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)
225 if(player[pn].q<=player[pn].spt)
227 pip[pip[0].pan->pn].page->dx+=4;
228 modexShowPage(pip[pip[0].pan->pn].page);
230 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].tx++; }
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)
238 if(player[pn].q<=player[pn].spt)
240 pip[pip[0].pan->pn].page->dx-=4;
241 modexShowPage(pip[pip[0].pan->pn].page);
243 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].tx--; }
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)
251 if(player[pn].q<=player[pn].spt)
253 pip[pip[0].pan->pn].page->dy+=4;
254 modexShowPage(pip[pip[0].pan->pn].page);
256 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].ty++; }
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)
264 if(player[pn].q<=player[pn].spt)
266 pip[pip[0].pan->pn].page->dy-=4;
267 modexShowPage(pip[pip[0].pan->pn].page);
269 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].ty--; }
273 //if (player[pn].d!=2) printf("player[%u].d=%u player[%u].q=%u\n", pn, player[pn].d, pn, player[pn].q);
277 allocMap(int w, int h) {
282 result.data = malloc(sizeof(byte) * w * h);
283 //result.data = (byte *)alloc_emem(((int)sizeof(byte) * w * h)/1024);
284 if(isEMS() || checkEMS())
287 //emmhandle = mallocEMS(coretotalEMS());//alloc_emem((int)sizeof(map))
288 mm.length=sizeof(result);
290 mm.sourceOff=ptr2long(&result);
293 ist = move_emem(&mm);
294 if(!ist){ dealloc_emem(emmhandle); exit(5); }
295 printf("%d\n", coretotalEMS());
302 initMap(map_t *map) {
303 // just a place holder to fill out an alternating pattern
307 //if(!isEMS() || !checkEMS())
308 // map->tiles = malloc(sizeof(tiles_t));
310 // map->tiles = (tiles_t *)alloc_emem(sizeof(tiles_t));
312 //create the tile set
313 //if(!isEMS() || !checkEMS())
314 // map->tiles->data = malloc(sizeof(bitmap_t));
316 // map->tiles->data = (bitmap_t *)alloc_emem(sizeof(bitmap_t));
317 // map->tiles->data->width = (TILEWH);
318 // map->tiles->data->height= TILEWH;
319 //if(!isEMS() || !checkEMS())
320 // map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
322 // map->tiles->data->data = (byte *)alloc_emem((TILEWH*2)*TILEWH);
323 // map->tiles->tileHeight = TILEWH;
324 // map->tiles->tileWidth =TILEWH;
325 // map->tiles->rows = 1;
326 // map->tiles->cols = 1;//2;
329 //for(y=0; y<map->height; y++) {
330 //for(x=0; x<map->width; x++) {
332 for(yy=0; yy<TILEWH; yy++) {
333 for(xx=0; xx<(TILEWH); xx++) {
335 map->tiles->data->data[i+1] = map->data[q];//28;//0x24;
336 // printf("[%d]", map->tiles->data->data[i]);
338 //map->tiles->data->data[i] = map->data[q];//0;//0x34;
339 //printf("]%d[==[%d]", i, map->tiles->data->data[i]);
345 // printf("[%d]", map->data[q]);
352 for(y=0; y<map->height; y++) {
353 for(x=0; x<map->width; x++) {
355 printf("[%d]", map->data[i]);
356 //tile = tile ? 0 : 1;
359 //tile = tile ? 0 : 1;
363 void near mapScrollRight(map_view_t *mv, player_t *player, word id, word plid)
365 word x, y; /* coordinate for drawing */
367 /* increment the pixel position and update the page */
368 mv[id].page->dx += player[plid].speed;
370 /* check to see if this changes the tile */
371 if(mv[id].page->dx >= mv[id].dxThresh )
373 /* go forward one tile */
375 /* Snap the origin forward */
376 mv[id].page->data += 4;
377 mv[id].page->dx = mv[id].map->tiles->tileWidth;
380 /* draw the next column */
381 x= mv[0].page->sw + mv[id].map->tiles->tileWidth;
385 mapDrawCol(&mv[0], mv[0].tx + mv[0].page->tw, mv[0].ty-1, x, player, mv->page->dx);
387 modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*(mv[0].page->th+2));
388 }else mapDrawCol(&mv[(!mv[0].video->p)], mv[0].tx + mv[0].page->tw, mv[0].ty-1, x, player, mv->page->dx);
392 void near mapScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
394 word x, y; /* coordinate for drawing */
396 /* decrement the pixel position and update the page */
397 mv[id].page->dx -= player[plid].speed;
399 /* check to see if this changes the tile */
400 if(mv[id].page->dx == 0)
402 /* go backward one tile */
405 /* Snap the origin backward */
406 mv[id].page->data -= 4;
407 mv[id].page->dx = mv[id].map->tiles->tileWidth;
410 /* draw the next column */
415 mapDrawCol(&mv[0], mv[0].tx - 1, mv[0].ty-1, x, player, mv->page->dx);
417 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));
418 }else mapDrawCol(&mv[(!mv[0].video->p)], mv[0].tx - 1, mv[0].ty-1, x, player, mv->page->dx);
422 void near mapScrollUp(map_view_t *mv, player_t *player, word id, word plid)
424 word x, y; /* coordinate for drawing */
426 /* decrement the pixel position and update the page */
427 mv[id].page->dy -= player[plid].speed;
429 /* check to see if this changes the tile */
430 if(mv[id].page->dy == 0 )
432 /* go down one tile */
434 /* Snap the origin downward */
435 mv[id].page->data -= mv[id].page->width*4;
436 mv[id].page->dy = mv[id].map->tiles->tileHeight;
439 /* draw the next row */
444 mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty-1, y, player, mv->page->dy);
446 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);
447 }else mapDrawRow(&mv[(!mv[0].video->p)], mv[0].tx - 1, mv[0].ty-1, y, player, mv->page->dy);
450 void near mapScrollDown(map_view_t *mv, player_t *player, word id, word plid)
452 word x, y; /* coordinate for drawing */
454 /* increment the pixel position and update the page */
455 mv[id].page->dy += player[plid].speed;
457 /* check to see if this changes the tile */
458 if(mv[id].page->dy >= mv[id].dyThresh )
460 /* go down one tile */
462 /* Snap the origin downward */
463 mv[id].page->data += mv[id].page->width*4;
464 mv[id].page->dy = mv[id].map->tiles->tileHeight;
467 /* draw the next row */
468 y= mv[0].page->sh + mv[id].map->tiles->tileHeight;
472 mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty+mv[0].page->th, y, player, mv->page->dy);
474 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);
475 }else mapDrawRow(&mv[(!mv[0].video->p)], mv[0].tx - 1, mv[0].ty+mv[0].page->th, y, player, mv->page->dy);
479 //TODO finish this wwww
480 void near ScrollRight(map_view_t *mv, player_t *player, word id, word plid)
482 /* increment the pixel position and update the page */
483 mv[0].video->page[id].dx += player[plid].speed;
485 /* check to see if this changes the tile */
486 if(mv[0].video->page[id].dx >= mv[0].dxThresh )
488 /* block copy pattern to where we will draw the sprite */
489 vga_setup_wm1_block_copy();
493 // o2 = *mv[0].video->page[id].data+4;
494 // o = *mv[0].video->page[id].data;
495 // for (i=0;i < mv[0].video->page[id].height;i++,o += mv[0].video->page[id].width+vga_state.vga_stride,o2 += (*mv[0].video->page[id].data >> 2)) vga_wm1_mem_block_copy(o2,o,*mv[0].video->page[id].data >> 2);
497 _fmemmove(mv[0].video->page[id].data+4, mv[0].video->page[id].data, mv[0].video->page[id].pagesize);
498 /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
499 vga_restore_rm0wm0();
500 /* Snap the origin forward */
501 mv[0].video->page[id].data += 4;
502 mv[0].video->page[id].dx = mv[0].map->tiles->tileWidth;
506 void near ScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
508 /* decrement the pixel position and update the page */
509 mv[0].video->page[id].dx -= player[plid].speed;
511 /* check to see if this changes the tile */
512 if(mv[0].video->page[id].dx == 0)
514 /* block copy pattern to where we will draw the sprite */
515 vga_setup_wm1_block_copy();
519 // o2 = *mv[0].video->page[id].data-4;
520 // o = *mv[0].video->page[id].data;
521 // for (i=0;i < mv[0].video->page[id].height;i++,o += mv[0].video->page[id].width+vga_state.vga_stride,o2 += (*mv[0].video->page[id].data >> 2)) vga_wm1_mem_block_copy(o2,o,*mv[0].video->page[id].data >> 2);
523 _fmemmove(mv[0].video->page[id].data-4, mv[0].video->page[id].data, mv[0].video->page[id].pagesize);
524 /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
525 vga_restore_rm0wm0();
526 /* Snap the origin backward */
527 mv[0].video->page[id].data -= 4;
528 mv[0].video->page[id].dx = mv[0].map->tiles->tileWidth;
532 void near ScrollUp(map_view_t *mv, player_t *player, word id, word plid)
534 /* decrement the pixel position and update the page */
535 mv[0].video->page[id].dy -= player[plid].speed;
537 /* check to see if this changes the tile */
538 if(mv[0].video->page[id].dy == 0)
540 /* block copy pattern to where we will draw the sprite */
541 vga_setup_wm1_block_copy();
545 // o2 = *mv[0].video->page[id].data-mv[0].video->page[id].pi;
546 // o = *mv[0].video->page[id].data;
547 // for (i=0;i < mv[0].video->page[id].height;i++,o += mv[0].video->page[id].width+vga_state.vga_stride,o2 += (*mv[0].video->page[id].data >> 2)) vga_wm1_mem_block_copy(o2,o,*mv[0].video->page[id].data >> 2);
549 _fmemmove(mv[0].video->page[id].data-mv[0].video->page[id].pi, mv[0].video->page[id].data, mv[0].video->page[id].pagesize);
550 /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
551 vga_restore_rm0wm0();
552 /* Snap the origin backward */
553 mv[0].video->page[id].data -= mv[0].video->page[id].pi;
554 mv[0].video->page[id].dy = mv[0].map->tiles->tileWidth;
558 void near ScrollDown(map_view_t *mv, player_t *player, word id, word plid)
560 /* increment the pixel position and update the page */
561 mv[0].video->page[id].dy += player[plid].speed;
563 /* check to see if this changes the tile */
564 if(mv[0].video->page[id].dy >= mv[0].dxThresh )
566 /* block copy pattern to where we will draw the sprite */
567 vga_setup_wm1_block_copy();
571 // o2 = *mv[0].video->page[id].data+mv[0].video->page[id].pi;
572 // o = *mv[0].video->page[id].data;
573 // for (i=0;i < mv[0].video->page[id].height;i++,o += mv[0].video->page[id].width+vga_state.vga_stride,o2 += (*mv[0].video->page[id].data >> 2)) vga_wm1_mem_block_copy(o2,o,*mv[0].video->page[id].data >> 2);
575 _fmemmove(mv[0].video->page[id].data+mv[0].video->page[id].pi, mv[0].video->page[id].data, mv[0].video->page[id].pagesize);
576 /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
577 vga_restore_rm0wm0();
578 /* Snap the origin forward */
579 mv[0].video->page[id].data += mv[0].video->page[id].pi;
580 mv[0].video->page[id].dy = mv[0].map->tiles->tileWidth;
584 sword chkmap(map_t *map, word q)
587 static byte x[(MAPW*MAPH)+1] =
588 { 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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1, 1, \
601 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, \
602 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
603 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 1, 2, 3, 4 };*/
604 //check for failed to load map
605 if((map->width == map->height == 0) && (q>0))
607 //initiate a null map!
608 map->width=MAPW;///2;
609 map->height=MAPH;///2;
610 // map->data = malloc(((map->width*map->height)+1)*sizeof(byte));
612 map->tiles = malloc(sizeof(tiles_t));
613 //fix this to be far~
614 // bp = bitmapLoadPcx("data/ed.pcx");
615 // map->tiles->data = &bp;
616 map->tiles->debug_data = map->data;
617 map->tiles->tileHeight = 16;
618 map->tiles->tileWidth = 16;
619 map->tiles->rows = 1;
620 map->tiles->cols = 1;
621 map->tiles->debug_text = true;
623 else map->tiles->debug_text = false;
627 //TODO: player position here
628 void mapGoTo(map_view_t *mv, int tx, int ty)
633 /* set up the coordinates */
634 mv[0].tx = mv[1].tx = tx;
635 mv[0].ty = mv[1].ty = ty;
636 mv[0].page->dx = mv[1].page->dx = mv[2].page->dx = mv[3].page->dx = mv->map->tiles->tileWidth;
637 mv[0].page->dy = mv[1].page->dy = mv[2].page->dy = mv[3].page->dy = mv->map->tiles->tileHeight;
639 /* set up the thresholds */
640 mv[0].dxThresh = mv[1].dxThresh = mv[2].dxThresh = mv[3].dxThresh = mv->map->tiles->tileWidth * 2;
641 mv[0].dyThresh = mv[1].dyThresh = mv[2].dxThresh = mv[3].dxThresh = mv->map->tiles->tileHeight * 2;
644 modexClearRegion(mv[0].page, 0, 0, mv[0].page->width, mv[0].page->height, 0);
646 i=mv[0].ty * mv[0].map->width + mv[0].tx;
647 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) {
648 mapDrawWRow(&mv[0], tx-1, ty, py);
649 i+=mv->map->width - tx;
651 modexCopyPageRegion(mv[1].page, mv[0].page, 0, 0, 0, 0, mv[0].page->width, mv[0].page->height);
654 /* fill screen with a distinctive pattern */
655 for (k=0;k < vga_state.vga_width;k++) {
657 vga_write_sequencer(0x02/*map mask*/,1 << (k&3));
658 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)
659 vga_state.vga_graphics_ram[o] = (k^j)&15; // VRL samples put all colors in first 15!
662 modexCopyPageRegion(mv[3].page, mv[!(mv->video->p)].page, 0/**/, 0/**/, 0, 128, 20, 36);
667 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y)
677 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 0); //currently the over scan color!
681 rx = (((i-1) % ((t->data->width)/t->tileWidth)) * t->tileWidth);
682 ry = (((i-1) / ((t->data->height)/t->tileHeight)) * t->tileHeight);
683 ////0000printf("i=%d\n", i);
684 switch(t->debug_text)
688 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, ((t->debug_data[i])+1));
689 //modexprint(page, x, y, 1, 15, 0, (char const *)(t->debug_data[i]));
691 PBUFBFUN (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
692 /* then the sprite. note modding ram ptr means we just draw to (x&3,0) */
693 //draw_vrl1_vgax_modex(x-rx,y-ry,vrl_header,vrl_lineoffs,buffer+sizeof(*vrl_header),bufsz-sizeof(*vrl_header));
694 //modexDrawBmpRegion (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
698 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, (t->debug_data[i]+1));
699 //modexprintbig(page, x, y, 1, 15, 0, (t->debug_data));
700 /*for(texty=0; texty<2; texty++)
702 for(textx=0; textx<2; textx++)
704 // modexprint(page, x+(textx*8), y+(texty*8), 1, (word)(t->debug_data), 0, (t->debug_data));
712 void near mapDrawRow(map_view_t *mv, int tx, int ty, word y, player_t *p, word poopoffset)
716 poopoffset%=p[0].speed;
717 //printf("y: %d\n", poopoffset);
718 /* the position within the map array */
719 i=ty * mv->map->width + tx;
720 for(x=poopoffset; x<(mv->page->sw+mv->dxThresh)/(poopoffset+1) && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
722 /* we are in the map, so copy! */
723 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
729 void near mapDrawCol(map_view_t *mv, int tx, int ty, word x, player_t *p, word poopoffset)
733 poopoffset%=p[0].speed;
734 //printf("x: %d\n", poopoffset);
735 /* location in the map array */
736 i=ty * mv->map->width + tx;
738 /* We'll copy all of the columns in the screen,
739 i + 1 row above and one below */
740 for(y=poopoffset; y<(mv->page->sh+mv->dyThresh)/(poopoffset+1) && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
742 /* we are in the map, so copy away! */
743 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
749 void mapDrawWRow(map_view_t *mv, int tx, int ty, word y)
754 /* the position within the map array */
755 i=ty * mv->map->width + tx;
756 for(x=0; x<mv->page->sw+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
758 /* we are in the map, so copy! */
759 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
765 void mapDrawWCol(map_view_t *mv, int tx, int ty, word x)
770 /* location in the map array */
771 i=ty * mv->map->width + tx;
773 /* We'll copy all of the columns in the screen,
774 i + 1 row above and one below */
775 for(y=0; y<mv->page->sh+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
777 /* we are in the map, so copy away! */
778 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
789 unsigned char shinku_fps_indicator_page = 2;
790 boolean pageflipflop;
794 void shinku(global_game_variables_t *gv)
796 word x = (0) + gv->video.page[!(gv->video.p)].dx; // follow the screen
797 word y = (0) + gv->video.page[!(gv->video.p)].dy; // follow the screen
804 //modexClearRegion(&gv->video.page[2], 0, 0, gv->video.page[2].sw, gv->video.page[2].sh, 47);
805 //modexClearRegion(&gv->video.page[3], 0, 0, gv->video.page[3].sw, gv->video.page[3].sh, 45);
806 //modexCopyPageRegion(pip[1].page, pip[2].page, 16, 16, 16, 16, (14*8)+4, 8+4);
807 /* block copy to visible RAM from offscreen */
808 // vga_setup_wm1_block_copy();
809 // modexCopyPageRegion(&(gv->video.page[shinku_fps_indicator_page]), &(gv->video.page[!shinku_fps_indicator_page]), x, y, x+w, 0, w, h);
810 // o = *(gv->video.page[2].data); // source offscreen
811 // o2 = *(gv->video.page[shinku_fps_indicator_page].data)+(y * vga_state.vga_stride) + (x >> 2); // dest visible (original stride)
812 // 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);
813 /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
814 // vga_restore_rm0wm0();
815 if(elapsed_timer(gv) >= (1.0 / gv->kurokku.frames_per_second))
817 sprintf(gv->pee, "%.0f fps", (double)gv->kurokku.tiku/ticktock(gv));
818 //modexClearRegion(&(gv->video.page[shinku_fps_indicator_page]), x, y, w, h, 45);
819 modexprint(&(gv->video.page[!(gv->video.p)]), x, y, type, col, bgcol, gv->pee);
821 /* block copy to visible RAM from offscreen */
822 // vga_setup_wm1_block_copy();
823 // o = *(gv->video.page[shinku_fps_indicator_page].data); // source offscreen
824 // o2 = *(gv->video.page[2].data)+(y * vga_state.vga_stride) + (x >> 2); // dest visible (original stride)
825 // 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);
826 // modexCopyPageRegion(&(gv->video.page[shinku_fps_indicator_page]), &(gv->video.page[!shinku_fps_indicator_page]), x, y, x, 0, w, h);
827 /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
828 // vga_restore_rm0wm0();
829 }else //copy dat sheet
832 switch(gv->kurokku.fpscap)
835 //modexprint(&(gv->video.page[shinku_fps_indicator_page]), x, y+8, type, col, bgcol, "sanic!");
836 gv->kurokku.frames_per_second=1;
839 //turn this off if XT
841 //vga_wait_for_vsync();
842 gv->kurokku.frames_per_second=60;
847 //vga_setup_wm1_block_copy();
848 //_fmemcpy((gv->video.page[(gv->video.p)]).data, (gv->video.page[(!gv->video.p)]).data, gv->video.page[(!gv->video.p)].pagesize);
849 //vga_restore_rm0wm0();
850 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);
851 modexShowPage(&(gv->video.page[gv->video.p]));
852 gv->video.p=!gv->video.p;
853 gv->video.r=!gv->video.r;
854 //0000gv->video.tickclk = ((*clockw)-gv->video.startclk)/18.2;
859 void near animatePlayer(map_view_t *pip, player_t *player, word pn, sword scrollswitch)
861 sword x = player[pn].x;
862 sword y = player[pn].y;
863 word dire=32; //direction
864 sword qq; //scroll offset
865 word ls = player[pn].persist_aniframe;
867 if(scrollswitch==0) qq = 0;
868 else qq = ((player[pn].q)*(player[pn].speed));
871 switch (player[pn].d)
880 dire*=(player[pn].d-2);
887 dire*=(player[pn].d-2);
892 dire*=(player[pn].d+2);
896 //modexCopyPageRegion(pip[!(pip->video->p)].page, pip[3].page, 0, 128, x-4, y-4, 28, 36);
898 // #define FRAME1 PBUFSFUN(pip[1].page, x, y, 32, dire, 16, 32, PLAYERBMPDATA);
899 // #define FRAME2 PBUFSFUN(pip[1].page, x, y, 16, dire, 16, 32, PLAYERBMPDATA);
900 // #define FRAME3 PBUFSFUN(pip[1].page, x, y, 0, dire, 16, 32, PLAYERBMPDATA);
901 // #define FRAME4 PBUFSFUN(pip[1].page, x, y, 16, dire, 16, 32, PLAYERBMPDATA);
902 #define FRAME1 PBUFSFUN(pip[!(pip->video->p)].page, x, y, 32, dire, 16, 32, PLAYERBMPDATA);
903 #define FRAME2 PBUFSFUN(pip[!(pip->video->p)].page, x, y, 16, dire, 16, 32, PLAYERBMPDATA);
904 #define FRAME3 PBUFSFUN(pip[!(pip->video->p)].page, x, y, 0, dire, 16, 32, PLAYERBMPDATA);
905 #define FRAME4 PBUFSFUN(pip[!(pip->video->p)].page, x, y, 16, dire, 16, 32, PLAYERBMPDATA);
907 #define FRAME1 modexClearRegion(pip[!(pip->video->p)].page, x, y, 16, 32, 2+dire);
908 #define FRAME2 modexClearRegion(pip[!(pip->video->p)].page, x, y, 16, 32, 1+dire);
909 #define FRAME3 modexClearRegion(pip[!(pip->video->p)].page, x, y, 16, 32, dire);
910 #define FRAME4 modexClearRegion(pip[!(pip->video->p)].page, x, y, 16, 32, 1+dire);
913 modexCopyPageRegion(pip[1].page, pip[0].page, x-4, y-4, x-4, y-4, 28, 36);
914 //modexCopyPageRegion(page_t *dest, page_t *src, word sx, word sy, word dx, word dy, word width, word height);
915 //modexCopyPageRegion(pip[3].page, pip[!(pip->video->p)].page, x-4, y-4, 0, 128, 28, 36);
916 /*modexCopyPageRegion(pip[pip->video->p].page,
917 pip[!(pip->video->p)].page, x-4, y-4, x-4, y-4, 28, 36);*/
918 // else modexCopyPageRegion(pip[1].page, pip[0].page, x-4, y-4, x-4, y-4, 28, 40);
934 // if(2>ls && ls>=1) { FRAME1 }else
935 // if(3>ls && ls>=2) { FRAME2 }else
936 // if(4>ls && ls>=3) { FRAME3 }else
937 // if(5>ls && ls>=4) { FRAME4 }
939 //TODO: mask copy //modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
940 //modexClearRegion(top->page, 66, 66, 2, 40, 0);
941 //modexCopyPageRegion(dest->page, top->page, 66, 66, 66, 66, 2, 40);