1 #include "src/lib/dos_kb.h"
2 #include "src/lib/mapread.c"
\r
3 //#include "16\lib\x\modex.h"
\r
4 #include "src/lib/wtest/wtest.c"
\r
5 #include "src/lib/planar.c"
6 //====#include "src\lib\ems.c"
\r
8 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
\r
30 int tx; //appears to be the top left tile position on the viewable screen map
\r
31 int ty; //appears to be the top left tile position on the viewable screen map
\r
32 word dxThresh; //????
\r
33 word dyThresh; //????
\r
37 int x; //player exact position on the viewable map
\r
38 int y; //player exact position on the viewable map
\r
39 int tx; //player tile position on the viewable map
\r
40 int ty; //player tile position on the viewable map
\r
41 int triggerx; //player's trigger box tile position on the viewable map
\r
42 int triggery; //player's trigger box tile position on the viewable map
\r
43 int setx; //NOT USED YET! player sprite sheet set on the image x
\r
44 int sety; //NOT USED YET! player sprite sheet set on the image y
\r
45 word q; //loop variable
\r
47 bitmap_t data; //supposively the sprite sheet data
\r
48 int hp; //hitpoints of the player
\r
51 map_t allocMap(int w, int h);
\r
52 void initMap(map_t *map);
\r
53 void mapScrollRight(map_view_t *mv, byte offset);
\r
54 void mapScrollLeft(map_view_t *mv, byte offest);
\r
55 void mapScrollUp(map_view_t *mv, byte offset);
\r
56 void mapScrollDown(map_view_t *mv, byte offset);
\r
57 void mapGoTo(map_view_t *mv, int tx, int ty);
\r
58 void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);
\r
59 void mapDrawRow(map_view_t *mv, int tx, int ty, word y);
\r
60 void mapDrawCol(map_view_t *mv, int tx, int ty, word x);
\r
62 void pdump(map_view_t *pee);
\r
63 void animatePlayer(map_view_t *src, map_view_t *dest, /*map_view_t *top, */sword d, short scrolloffsetswitch, int x, int y, int ls, int lp, bitmap_t *bmp);
\r
66 #define QUADWH TILEWH/2
\r
68 //#define LOOPMAX (TILEWH/SPEED)
\r
70 //place holder definitions
\r
77 size_t oldfreemem=GetFreeSize();
\r
82 static word paloffset=0;
\r
83 bitmap_t ptmp;//, npctmp; // player sprite
\r
86 static int persist_aniframe = 0; /* gonna be increased to 1 before being used, so 0 is ok for default */
\r
87 page_t screen, screen2, screen3;
\r
89 map_view_t mv, mv2, mv3;
\r
90 map_view_t *bg, *spri, *mask;//, *tmp;
\r
92 byte *ptr, *mappalptr;
\r
96 // atexit(qclean());
\r
99 printf("Expanded memory is not present\n");
\r
105 printf("Expanded memory manager is not present\n");
\r
109 emsavail = emmavail();
\r
112 printf("Expanded memory manager error\n");
\r
115 printf("There are %ld pages available\n",emsavail);
\r
117 if((emmhandle = emmalloc(emsavail)) < 0)
\r
119 printf("Insufficient pages available\n");
\r
124 //0000 printf("Total used @ before map load: %zu\n", oldfreemem-GetFreeSize());
125 loadmap("data/test.map", &map);
126 //---- map = allocMap(map.width,map.height); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be drawn properly
127 //if(isEMS()) printf("%d tesuto\n", coretotalEMS());
128 //---- initMap(&map);
135 mappalptr = map.tiles->data->palette;
137 //0000 printf("Total used @ before image loading: %zu\n", oldfreemem-GetFreeSize());
138 ptmp = bitmapLoadPcx("data/ptmp.pcx"); // load sprite
139 //npctmp = bitmapLoadPcx("ptmp1.pcx"); // load sprite
141 /* create the planar buffer */
142 //0000 printf("Total used @ before planar buffer creation: %zu\n", oldfreemem-GetFreeSize());
143 p = planar_buf_from_bitmap(&ptmp);
\r
144 //0000 printf("Total used @ after planar buffer creation: %zu\n", oldfreemem-GetFreeSize());
149 mm.length=sizeof(map);
\r
151 mm.sourceOff=(long)↦
\r
152 mm.destH=emmhandle;
\r
155 ist = move_emem(&mm);
\r
156 printf("%d\n", coretotalEMS());
\r
157 if(!ist){ dealloc_emem(emmhandle); exit(5); }
\r
158 //printf("%d\n", emmhandle);
\r
164 mm.length=emmhandle;
\r
166 mm.sourceOff=(long)&ptmp;
\r
167 mm.destH=emmhandle;
\r
170 ist = move_emem(&mm);
\r
171 printf("%d\n", coretotalEMS());
\r
172 if(!ist){ dealloc_emem(emmhandle); exit(5); }
\r
173 //printf("%d\n", emmhandle);
\r
177 /* save the palette */
178 dpal = modexNewPal();
180 modexFadeOff(4, dpal);
184 modexPalBlack(); //reset the palette~
185 // printf("Total used @ before palette initiation: %zu\n", oldfreemem-GetFreeSize());
186 ptmp.offset=(paloffset/3);
187 modexPalUpdate(&ptmp, &paloffset, 0, 0);
188 //printf(" %d\n", sizeof(ptmp.data));
189 //printf("1: %d\n", paloffset);
190 map.tiles->data->offset=(paloffset/3);
191 modexPalUpdate(map.tiles->data, &paloffset, 0, 0);
193 printf("0 paloffset= %d\n", paloffset/3);
195 gpal = modexNewPal();
\r
197 modexSavePalFile("data/g.pal", gpal);
198 modexPalBlack(); //so player will not see loadings~
200 /* setup camera and screen~ */
201 screen = modexDefaultPage();
202 screen.width += (TILEWH*2);
\r
203 screen.height += (TILEWH*2)+QUADWH;
\r
205 screen2 = modexNextPage(mv.page);
\r
206 mv2.page = &screen2;
\r
208 mv3.page = &screen3;
\r
210 /* set up paging */
\r
215 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
\r
217 mapGoTo(spri, 0, 0);
\r
218 //mapGoTo(mask, 0, 0);
\r
220 //TODO: put player in starting position of spot
\r
221 //default player position on the viewable map
\r
222 player.tx = bg->tx + 10;
\r
223 player.ty = bg->ty + 8;
\r
224 player.x = player.tx*TILEWH;
\r
225 player.y = player.ty*TILEWH;
\r
226 player.triggerx = player.tx;
\r
227 player.triggery = player.ty+1;
\r
232 /*npc0.tx = bg->tx + 1;
\r
233 npc0.ty = bg->ty + 1;
\r
234 npc0.x = npc0.tx*TILEWH;
\r
235 npc0.y = npc0.ty*TILEWH;
\r
236 npc0.triggerx = npc0.tx;
\r
237 npc0.triggery = npc0.ty+1;
\r
240 modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 64, 24, 32, &npctmp);*/
\r
241 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
\r
243 //----modexClearRegion(spri->page, player.triggerx*16, player.triggery*16, 16, 16, 1);
\r
244 //----modexClearRegion(bg->page, player.triggerx*16, player.triggery*16, 16, 16, 1);
\r
246 //----modexClearRegion(spri->page, 5*16, 5*16, 16, 16, 255);
\r
247 //----modexClearRegion(bg->page, 5*16, 5*16, 16, 16, 255);
\r
248 modexShowPage(spri->page);
249 // printf("Total used @ before loop: %zu\n", oldfreemem-GetFreeSize());
250 modexFadeOn(4, gpal);
\r
251 while(!keyp(1) && player.hp>0)
\r
253 //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
\r
254 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
\r
255 //when player.tx or player.ty == 0 or player.tx == 20 or player.ty == 15 then stop because that is edge of map and you do not want to walk of the map
\r
256 #define INC_PER_FRAME if(player.q&1) persist_aniframe++; if(persist_aniframe>4) persist_aniframe = 1;
\r
257 /*#define INC_PER_FRAME_NPC if(npc0.q&1) persist_aniframe++; if(persist_aniframe>4) persist_aniframe = 1;
\r
259 if(npc0.d == 0 && npc0.q == 1) npc0.d =rand()%8;
\r
266 if(npc0.tx < map.width && !(npc0.tx+1 == TRIGGX && npc0.ty == TRIGGY) && !(npc0.tx+1 == player.tx && npc0.ty == player.ty))
\r
268 if(npc0.q<=(TILEWH/SPEED))
\r
272 //animatePlayer(bg, spri, mask, 1, 0, npc0.x, npc0.y, persist_aniframe, q, &npctmp);
\r
273 animatePlayer(bg, spri, npc0.d-1, 0, npc0.x, npc0.y, persist_aniframe, npc0.q, &npctmp);
\r
274 modexShowPage(spri->page);
\r
276 } else { npc0.q = 1; npc0.d = 0; npc0.tx++; }
\r
280 modexCopyPageRegion(spri->page, bg->page, npc0.x-4, npc0.y-TILEWH, npc0.x-4, npc0.y-TILEWH, 24, 32);
\r
281 modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 32, 24, 32, &npctmp);
\r
282 modexShowPage(spri->page);
\r
285 npc0.triggerx = npc0.tx+1;
\r
286 npc0.triggery = npc0.ty;
\r
292 if(npc0.tx > 1 && !(npc0.tx-1 == TRIGGX && npc0.ty == TRIGGY) && !(npc0.tx-1 == player.tx && npc0.ty == player.ty))
\r
294 if(npc0.q<=(TILEWH/SPEED))
\r
298 //animatePlayer(bg, spri, mask, 3, 0, npc0.x, npc0.y, persist_aniframe, q, &npctmp);
\r
299 animatePlayer(bg, spri, npc0.d-1, 0, npc0.x, npc0.y, persist_aniframe, npc0.q, &npctmp);
\r
300 modexShowPage(spri->page);
\r
302 } else { npc0.q = 1; npc0.d = 0; npc0.tx--; }
\r
306 modexCopyPageRegion(spri->page, bg->page, npc0.x-4, npc0.y-TILEWH, npc0.x-4, npc0.y-TILEWH, 24, 32);
\r
307 modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 96, 24, 32, &npctmp);
\r
308 modexShowPage(spri->page);
\r
311 npc0.triggerx = npc0.tx-1;
\r
312 npc0.triggery = npc0.ty;
\r
318 if(npc0.ty < map.height && !(npc0.tx == TRIGGX && npc0.ty+1 == TRIGGY) && !(npc0.tx == player.tx && npc0.ty == player.ty+1))
\r
320 if(npc0.q<=(TILEWH/SPEED))
\r
324 //animatePlayer(bg, spri, mask, 2, 0, npc0.x, npc0.y, persist_aniframe, q, &npctmp);
\r
325 animatePlayer(bg, spri, npc0.d-1, 0, npc0.x, npc0.y, persist_aniframe, npc0.q, &npctmp);
\r
326 modexShowPage(spri->page);
\r
328 } else { npc0.q = 1; npc0.d = 0; npc0.ty++; }
\r
332 modexCopyPageRegion(spri->page, bg->page, npc0.x-4, npc0.y-TILEWH, npc0.x-4, npc0.y-TILEWH, 24, 32);
\r
333 modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 64, 24, 32, &npctmp);
\r
334 modexShowPage(spri->page);
\r
337 npc0.triggerx = npc0.tx;
\r
338 npc0.triggery = npc0.ty+1;
\r
344 if(npc0.ty > 1 && !(npc0.tx == TRIGGX && npc0.ty-1 == TRIGGY) && !(npc0.tx+1 == player.tx && npc0.ty == player.ty-1))
\r
346 if(npc0.q<=(TILEWH/SPEED))
\r
350 //animatePlayer(bg, spri, mask, 0, 0, npc0.x, npc0.y, persist_aniframe, q, &npctmp);
\r
351 modexShowPage(spri->page);
\r
352 animatePlayer(bg, spri, npc0.d-1, 0, npc0.x, npc0.y, persist_aniframe, npc0.q, &npctmp);
\r
354 } else { npc0.q = 1; npc0.d = 0; npc0.ty--; }
\r
358 modexCopyPageRegion(spri->page, bg->page, npc0.x-4, npc0.y-TILEWH, npc0.x-4, npc0.y-TILEWH, 24, 32);
\r
359 modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 0, 24, 32, &npctmp);
\r
360 modexShowPage(spri->page);
\r
363 npc0.triggerx = npc0.tx;
\r
364 npc0.triggery = npc0.ty-1;
\r
367 if((npc0.triggery == player.ty && npc0.triggerx == player.tx) || (npc0.ty == player.ty && npc0.tx == player.tx)){ player.hp--; }
\r
371 //TODO: make movement into a function!
\r
373 if((keyp(77) && !keyp(75) && player.d == 0) || player.d == 2)
\r
375 if(player.d == 0){ player.d = 2; }
\r
376 if(bg->tx >= 0 && bg->tx+20 < map.width && player.tx == bg->tx + 10 && !(player.tx+1 == TRIGGX && player.ty == TRIGGY))
\r
378 if(player.q<=(TILEWH/SPEED))
\r
381 //animatePlayer(bg, spri, mask, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);
\r
382 animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
383 mapScrollRight(bg, SPEED);
\r
384 mapScrollRight(spri, SPEED);
\r
385 //mapScrollRight(mask, SPEED);
\r
386 modexShowPage(spri->page);
\r
388 } else { player.q = 1; player.d = 0; player.tx++; }
\r
390 else if(player.tx < map.width && !(player.tx+1 == TRIGGX && player.ty == TRIGGY))
\r
392 if(player.q<=(TILEWH/SPEED))
\r
396 //animatePlayer(bg, spri, mask, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp);
\r
397 animatePlayer(bg, spri, player.d-1, 0, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
398 modexShowPage(spri->page);
\r
400 } else { player.q = 1; player.d = 0; player.tx++; }
\r
404 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
\r
405 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 32, 24, 32, &ptmp);
\r
406 modexShowPage(spri->page);
\r
409 player.triggerx = player.tx+1;
\r
410 player.triggery = player.ty;
\r
414 if((keyp(75) && !keyp(77) && player.d == 0) || player.d == 4)
\r
416 if(player.d == 0){ player.d = 4; }
\r
417 if(bg->tx > 0 && bg->tx+20 <= map.width && player.tx == bg->tx + 10 && !(player.tx-1 == TRIGGX && player.ty == TRIGGY))
\r
419 if(player.q<=(TILEWH/SPEED))
\r
422 //animatePlayer(bg, spri, mask, 3, 1, player.x, player.y, persist_aniframe, q, &ptmp);
\r
423 animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
424 mapScrollLeft(bg, SPEED);
\r
425 mapScrollLeft(spri, SPEED);
\r
426 //mapScrollLeft(mask, SPEED);
\r
427 modexShowPage(spri->page);
\r
429 } else { player.q = 1; player.d = 0; player.tx--; }
\r
431 else if(player.tx > 1 && !(player.tx-1 == TRIGGX && player.ty == TRIGGY))
\r
433 if(player.q<=(TILEWH/SPEED))
\r
437 //animatePlayer(bg, spri, mask, 3, 0, player.x, player.y, persist_aniframe, q, &ptmp);
\r
438 animatePlayer(bg, spri, player.d-1, 0, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
439 modexShowPage(spri->page);
\r
441 } else { player.q = 1; player.d = 0; player.tx--; }
\r
445 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
\r
446 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 96, 24, 32, &ptmp);
\r
447 modexShowPage(spri->page);
\r
450 player.triggerx = player.tx-1;
\r
451 player.triggery = player.ty;
\r
455 if((keyp(80) && !keyp(72) && player.d == 0) || player.d == 3)
\r
457 if(player.d == 0){ player.d = 3; }
\r
458 if(bg->ty >= 0 && bg->ty+15 < map.height && player.ty == bg->ty + 8 && !(player.tx == TRIGGX && player.ty+1 == TRIGGY))
\r
460 if(player.q<=(TILEWH/SPEED))
\r
463 //animatePlayer(bg, spri, mask, 2, 1, player.x, player.y, persist_aniframe, q, &ptmp);
\r
464 animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
465 mapScrollDown(bg, SPEED);
\r
466 mapScrollDown(spri, SPEED);
\r
467 //mapScrollDown(mask, SPEED);
\r
468 modexShowPage(spri->page);
\r
470 } else { player.q = 1; player.d = 0; player.ty++; }
\r
472 else if(player.ty < map.height && !(player.tx == TRIGGX && player.ty+1 == TRIGGY))
\r
474 if(player.q<=(TILEWH/SPEED))
\r
478 //animatePlayer(bg, spri, mask, 2, 0, player.x, player.y, persist_aniframe, q, &ptmp);
\r
479 animatePlayer(bg, spri, player.d-1, 0, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
480 modexShowPage(spri->page);
\r
482 } else { player.q = 1; player.d = 0; player.ty++; }
\r
486 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
\r
487 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
\r
488 modexShowPage(spri->page);
\r
491 player.triggerx = player.tx;
\r
492 player.triggery = player.ty+1;
\r
496 if((keyp(72) && !keyp(80) && player.d == 0) || player.d == 1)
\r
498 if(player.d == 0){ player.d = 1; }
\r
499 if(bg->ty > 0 && bg->ty+15 <= map.height && player.ty == bg->ty + 8 && !(player.tx == TRIGGX && player.ty-1 == TRIGGY))
\r
501 if(player.q<=(TILEWH/SPEED))
\r
504 //animatePlayer(bg, spri, mask, 0, 1, player.x, player.y, persist_aniframe, q, &ptmp);
\r
505 animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
506 mapScrollUp(bg, SPEED);
\r
507 mapScrollUp(spri, SPEED);
\r
508 //mapScrollUp(mask, SPEED);
\r
509 modexShowPage(spri->page);
\r
511 } else { player.q = 1; player.d = 0; player.ty--; }
\r
513 else if(player.ty > 1 && !(player.tx == TRIGGX && player.ty-1 == TRIGGY))
\r
515 if(player.q<=(TILEWH/SPEED))
\r
519 //animatePlayer(bg, spri, mask, 0, 0, player.x, player.y, persist_aniframe, q, &ptmp);
\r
520 modexShowPage(spri->page);
\r
521 animatePlayer(bg, spri, player.d-1, 0, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
523 } else { player.q = 1; player.d = 0; player.ty--; }
\r
527 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
\r
528 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 0, 24, 32, &ptmp);
\r
529 modexShowPage(spri->page);
\r
532 player.triggerx = player.tx;
\r
533 player.triggery = player.ty-1;
\r
535 //modexClearRegion(mask->page, 66, 66, 2, 40, 0);
\r
537 if(((player.triggerx == TRIGGX && player.triggery == TRIGGY) && keyp(0x1C))||(player.tx == 5 && player.ty == 5))
\r
540 for(i=800; i>=400; i--)
\r
546 if(player.q == (TILEWH/SPEED)+1 && player.d > 0 && (player.triggerx == 5 && player.triggery == 5)){ player.hp--; }
\r
547 //if(keyp(0x0E)) while(1){ if(xmsmalloc(24)) break; }
548 if(keyp(25)){ pdump(bg); pdump(spri); }
549 if(keyp(24)){ modexPalUpdate3(gpal); paloffset=0; pdump(bg); pdump(spri); }
551 paloffset=0; modexPalBlack(); modexPalUpdate(&ptmp, &paloffset, 0, 0);
552 printf("1paloffset = %d\n", paloffset/3);
553 modexPalUpdate(map.tiles->data, &paloffset, 0, 0);
554 printf("2paloffset = %d\n", paloffset/3);
555 pdump(bg); pdump(spri); }
569 /* fade back to text mode */
570 /* but 1st lets save the game palette~ */
572 modexSavePalFile("data/g.pal", gpal);
573 modexFadeOff(4, gpal);
\r
576 //system("mem /E /P");
\r
577 printf("Project 16 scroll.exe\n");
\r
578 printf("tx: %d\n", bg->tx);
\r
579 printf("ty: %d\n", bg->ty);
\r
580 printf("player.x: %d", player.x);
\r
581 if(player.hp==0) printf("%d wwww\n", player.y+8);
\r
582 else printf("\nplayer.y: %d\n", player.y);
\r
583 printf("player.tx: %d\n", player.tx);
\r
584 printf("player.ty: %d\n", player.ty);
\r
585 printf("player.triggx: %d\n", player.triggerx);
\r
586 printf("player.triggy: %d\n", player.triggery);
\r
587 printf("player.hp: %d\n", player.hp);
\r
588 printf("player.q: %d\n", player.q);
\r
589 printf("player.d: %d\n", player.d);
590 printf("palette offset: %d\n", paloffset/3);
591 printf("Total used: %zu\n", oldfreemem-GetFreeSize());
592 printf("Total free: %zu\n", GetFreeSize());
593 printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");
\r
594 printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");
\r
601 //emmclose(emmhandle);
\r
602 switch(detectcpu())
\r
604 case 0: cpus = "8086/8088 or 186/88"; break;
\r
605 case 1: cpus = "286"; break;
\r
606 case 2: cpus = "386 or newer"; break;
\r
607 default: cpus = "internal error"; break;
\r
609 printf("detected CPU type: %s\n", cpus);
610 modexFadeOn(4, dpal);
\r
615 allocMap(int w, int h) {
\r
620 result.data = malloc(sizeof(byte) * w * h);
\r
621 //result.data = (byte *)alloc_emem(((int)sizeof(byte) * w * h)/1024);
\r
622 /*if(isEMS() || checkEMS())
\r
625 //emmhandle = mallocEMS(coretotalEMS());//alloc_emem((int)sizeof(map))
\r
626 mm.length=sizeof(result);
\r
628 mm.sourceOff=ptr2long(&result);
\r
629 mm.destH=emmhandle;
\r
631 ist = move_emem(&mm);
\r
632 if(!ist){ dealloc_emem(emmhandle); exit(5); }
\r
633 printf("%d\n", coretotalEMS());
\r
640 initMap(map_t *map) {
\r
641 /* just a place holder to fill out an alternating pattern */
\r
645 //if(!isEMS() || !checkEMS())
\r
646 // map->tiles = malloc(sizeof(tiles_t));
\r
648 // map->tiles = (tiles_t *)alloc_emem(sizeof(tiles_t));
\r
650 /* create the tile set */
\r
651 //if(!isEMS() || !checkEMS())
\r
652 // map->tiles->data = malloc(sizeof(bitmap_t));
\r
654 // map->tiles->data = (bitmap_t *)alloc_emem(sizeof(bitmap_t));
\r
655 // map->tiles->data->width = (TILEWH/**2*/);
\r
656 // map->tiles->data->height= TILEWH;
\r
657 //if(!isEMS() || !checkEMS())
\r
658 // map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
\r
660 // map->tiles->data->data = (byte *)alloc_emem((TILEWH*2)*TILEWH);
\r
661 // map->tiles->tileHeight = TILEWH;
\r
662 // map->tiles->tileWidth =TILEWH;
\r
663 // map->tiles->rows = 1;
\r
664 // map->tiles->cols = 1;//2;
\r
667 //for(y=0; y<map->height; y++) {
\r
668 //for(x=0; x<map->width; x++) {
670 for(yy=0; yy<TILEWH; yy++) {
\r
671 for(xx=0; xx<(TILEWH); xx++) {
\r
673 map->tiles->data->data[i+1] = map->data[q];//28;//0x24;
674 // printf("[%d]", map->tiles->data->data[i]);
\r
676 //map->tiles->data->data[i] = map->data[q];//0;//0x34;
677 //printf("]%d[==[%d]", i, map->tiles->data->data[i]);
683 // printf("[%d]", map->data[q]);
690 for(y=0; y<map->height; y++) {
\r
691 for(x=0; x<map->width; x++) {
692 // map->data[i]=255;
\r
693 printf("[%d]", map->data[i]);
\r
694 //tile = tile ? 0 : 1;
\r
697 //tile = tile ? 0 : 1;
\r
703 mapScrollRight(map_view_t *mv, byte offset) {
\r
704 word x, y; /* coordinate for drawing */
\r
706 /* increment the pixel position and update the page */
\r
707 mv->page->dx += offset;
\r
709 /* check to see if this changes the tile */
\r
710 if(mv->page->dx >= mv->dxThresh ) {
\r
711 /* go forward one tile */
\r
713 /* Snap the origin forward */
\r
714 mv->page->data += 4;
\r
715 mv->page->dx = mv->map->tiles->tileWidth;
\r
718 /* draw the next column */
\r
719 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
720 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
726 mapScrollLeft(map_view_t *mv, byte offset) {
\r
727 word x, y; /* coordinate for drawing */
\r
729 /* increment the pixel position and update the page */
\r
730 mv->page->dx -= offset;
\r
732 /* check to see if this changes the tile */
\r
733 if(mv->page->dx == 0) {
\r
734 /* go backward one tile */
\r
737 /* Snap the origin backward */
\r
738 mv->page->data -= 4;
\r
739 mv->page->dx = mv->map->tiles->tileWidth;
\r
741 /* draw the next column */
\r
742 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
748 mapScrollUp(map_view_t *mv, byte offset) {
\r
749 word x, y; /* coordinate for drawing */
\r
751 /* increment the pixel position and update the page */
\r
752 mv->page->dy -= offset;
\r
754 /* check to see if this changes the tile */
\r
755 if(mv->page->dy == 0 ) {
\r
756 /* go down one tile */
\r
758 /* Snap the origin downward */
\r
759 mv->page->data -= mv->page->width*4;
\r
760 mv->page->dy = mv->map->tiles->tileHeight;
\r
763 /* draw the next row */
\r
765 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
771 mapScrollDown(map_view_t *mv, byte offset) {
\r
772 word x, y; /* coordinate for drawing */
\r
774 /* increment the pixel position and update the page */
\r
775 mv->page->dy += offset;
\r
777 /* check to see if this changes the tile */
\r
778 if(mv->page->dy >= mv->dyThresh ) {
\r
779 /* go down one tile */
\r
781 /* Snap the origin downward */
\r
782 mv->page->data += mv->page->width*4;
\r
783 mv->page->dy = mv->map->tiles->tileHeight;
\r
786 /* draw the next row */
\r
787 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
788 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
795 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
799 /* set up the coordinates */
\r
802 mv->page->dx = mv->map->tiles->tileWidth;
\r
803 mv->page->dy = mv->map->tiles->tileHeight;
\r
805 /* set up the thresholds */
\r
806 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
807 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
809 /* draw the tiles */
\r
810 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
812 i=mv->ty * mv->map->width + mv->tx;
\r
813 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
814 mapDrawRow(mv, tx-1, ty, py);
\r
815 i+=mv->map->width - tx;
\r
821 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
831 rx = (((i-1) % ((t->data->width)/t->tileWidth)) * t->tileWidth);
\r
832 ry = (((i-1) / ((t->data->height)/t->tileHeight)) * t->tileHeight);
833 //mxPutTile(t->data, x, y, t->tileWidth, t->tileHeight);
\r
834 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
840 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
844 /* the position within the map array */
\r
845 i=ty * mv->map->width + tx;
\r
846 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
848 /* we are in the map, so copy! */
849 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
856 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
860 /* location in the map array */
\r
861 i=ty * mv->map->width + tx;
\r
863 /* We'll copy all of the columns in the screen,
\r
864 i + 1 row above and one below */
\r
865 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
867 /* we are in the map, so copy away! */
868 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
870 i += mv->map->width;
\r
880 void pdump(map_view_t *pee)
883 int palq=(mult)*TILEWH;
\r
886 for(paly=0; paly<palq; paly+=mult){
\r
887 for(palx=0; palx<palq; palx+=mult){
888 modexClearRegion(pee->page, palx+TILEWH, paly+TILEWH, mult, mult, palcol);
\r
895 animatePlayer(map_view_t *src, map_view_t *dest, /*map_view_t *top, */sword d, short scrolloffsetswitch, int x, int y, int ls, int lp, bitmap_t *bmp)
\r
897 sword dire=32*d; //direction
\r
898 sword qq; //scroll offset
\r
900 if(scrolloffsetswitch==0) qq = 0;
\r
901 else qq = ((lp)*SPEED);
\r
925 modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
\r
926 if(2>ls && ls>=1) { modexDrawSpriteRegion(dest->page, x, y, 48, dire, 24, 32, bmp); }else
\r
927 if(3>ls && ls>=2) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }else
\r
928 if(4>ls && ls>=3) { modexDrawSpriteRegion(dest->page, x, y, 0, dire, 24, 32, bmp); }else
\r
929 if(5>ls && ls>=4) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }
\r
930 //TODO: mask copy //modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
\r
931 //modexClearRegion(top->page, 66, 66, 2, 40, 0);
\r
932 //modexCopyPageRegion(dest->page, top->page, 66, 66, 66, 66, 2, 40);
\r
933 //turn this off if XT
\r
934 if(detectcpu() > 0) modexWaitBorder();
\r