1 #include "src/lib/dos_kb.h"
\r
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"
\r
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
123 /* create the map */
\r
124 //0000 printf("Total used @ before map load: %zu\n", oldfreemem-GetFreeSize());
\r
125 loadmap("data/test.map", &map);
\r
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
\r
127 //if(isEMS()) printf("%d tesuto\n", coretotalEMS());
\r
128 //---- initMap(&map);
\r
133 /* draw the tiles */
\r
135 mappalptr = map.tiles->data->palette;
\r
137 //0000 printf("Total used @ before image loading: %zu\n", oldfreemem-GetFreeSize());
\r
138 ptmp = bitmapLoadPcx("data/ptmp.pcx"); // load sprite
\r
139 //npctmp = bitmapLoadPcx("ptmp1.pcx"); // load sprite
\r
141 /* create the planar buffer */
\r
142 //0000 printf("Total used @ before planar buffer creation: %zu\n", oldfreemem-GetFreeSize());
\r
143 p = planar_buf_from_bitmap(&ptmp);
\r
144 //0000 printf("Total used @ after planar buffer creation: %zu\n", oldfreemem-GetFreeSize());
\r
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 */
\r
178 dpal = modexNewPal();
\r
179 modexPalSave(dpal);
\r
180 modexFadeOff(4, dpal);
\r
184 modexPalBlack(); //reset the palette~
\r
185 // printf("Total used @ before palette initiation: %zu\n", oldfreemem-GetFreeSize());
\r
186 ptmp.offset=(paloffset/3);
\r
187 modexPalUpdate(&ptmp, &paloffset, 0, 0);
\r
188 //printf(" %d\n", sizeof(ptmp.data));
\r
189 //printf("1: %d\n", paloffset);
\r
190 map.tiles->data->offset=(paloffset/3);
\r
191 modexPalUpdate(map.tiles->data, &paloffset, 0, 0);
\r
192 printf("\n====\n");
\r
193 printf("0 paloffset= %d\n", paloffset/3);
\r
194 printf("====\n\n");
\r
195 gpal = modexNewPal();
\r
196 modexPalSave(gpal);
\r
197 modexSavePalFile("data/g.pal", gpal);
\r
198 modexPalBlack(); //so player will not see loadings~
\r
200 /* setup camera and screen~ */
\r
201 screen = modexDefaultPage();
\r
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);
\r
249 // printf("Total used @ before loop: %zu\n", oldfreemem-GetFreeSize());
\r
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; }
\r
548 if(keyp(25)){ pdump(bg); pdump(spri); }
\r
549 if(keyp(24)){ modexPalUpdate3(gpal); paloffset=0; pdump(bg); pdump(spri); }
\r
551 paloffset=0; modexPalBlack(); modexPalUpdate(&ptmp, &paloffset, 0, 0);
\r
552 printf("1paloffset = %d\n", paloffset/3);
\r
553 modexPalUpdate(map.tiles->data, &paloffset, 0, 0);
\r
554 printf("2paloffset = %d\n", paloffset/3);
\r
555 pdump(bg); pdump(spri); }
\r
569 /* fade back to text mode */
\r
570 /* but 1st lets save the game palette~ */
\r
571 modexPalSave(gpal);
\r
572 modexSavePalFile("data/g.pal", gpal);
\r
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);
\r
590 printf("palette offset: %d\n", paloffset/3);
\r
591 printf("Total used: %zu\n", oldfreemem-GetFreeSize());
\r
592 printf("Total free: %zu\n", GetFreeSize());
\r
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
595 printf("Screen: %dx", screen.width); printf("%d\n", screen.height);
\r
596 printf("Screen2: %dx", screen2.width); printf("%d\n", screen2.height);
\r
602 //emmclose(emmhandle);
\r
603 switch(detectcpu())
\r
605 case 0: cpus = "8086/8088 or 186/88"; break;
\r
606 case 1: cpus = "286"; break;
\r
607 case 2: cpus = "386 or newer"; break;
\r
608 default: cpus = "internal error"; break;
\r
610 printf("detected CPU type: %s\n", cpus);
\r
611 modexFadeOn(4, dpal);
\r
616 allocMap(int w, int h) {
\r
621 result.data = malloc(sizeof(byte) * w * h);
\r
622 //result.data = (byte *)alloc_emem(((int)sizeof(byte) * w * h)/1024);
\r
623 /*if(isEMS() || checkEMS())
\r
626 //emmhandle = mallocEMS(coretotalEMS());//alloc_emem((int)sizeof(map))
\r
627 mm.length=sizeof(result);
\r
629 mm.sourceOff=ptr2long(&result);
\r
630 mm.destH=emmhandle;
\r
632 ist = move_emem(&mm);
\r
633 if(!ist){ dealloc_emem(emmhandle); exit(5); }
\r
634 printf("%d\n", coretotalEMS());
\r
641 initMap(map_t *map) {
\r
642 /* just a place holder to fill out an alternating pattern */
\r
646 //if(!isEMS() || !checkEMS())
\r
647 // map->tiles = malloc(sizeof(tiles_t));
\r
649 // map->tiles = (tiles_t *)alloc_emem(sizeof(tiles_t));
\r
651 /* create the tile set */
\r
652 //if(!isEMS() || !checkEMS())
\r
653 // map->tiles->data = malloc(sizeof(bitmap_t));
\r
655 // map->tiles->data = (bitmap_t *)alloc_emem(sizeof(bitmap_t));
\r
656 // map->tiles->data->width = (TILEWH/**2*/);
\r
657 // map->tiles->data->height= TILEWH;
\r
658 //if(!isEMS() || !checkEMS())
\r
659 // map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
\r
661 // map->tiles->data->data = (byte *)alloc_emem((TILEWH*2)*TILEWH);
\r
662 // map->tiles->tileHeight = TILEWH;
\r
663 // map->tiles->tileWidth =TILEWH;
\r
664 // map->tiles->rows = 1;
\r
665 // map->tiles->cols = 1;//2;
\r
668 //for(y=0; y<map->height; y++) {
\r
669 //for(x=0; x<map->width; x++) {
\r
671 for(yy=0; yy<TILEWH; yy++) {
\r
672 for(xx=0; xx<(TILEWH); xx++) {
\r
674 map->tiles->data->data[i+1] = map->data[q];//28;//0x24;
\r
675 // printf("[%d]", map->tiles->data->data[i]);
\r
677 //map->tiles->data->data[i] = map->data[q];//0;//0x34;
\r
678 //printf("]%d[==[%d]", i, map->tiles->data->data[i]);
\r
684 // printf("[%d]", map->data[q]);
\r
691 for(y=0; y<map->height; y++) {
\r
692 for(x=0; x<map->width; x++) {
\r
693 // map->data[i]=255;
\r
694 printf("[%d]", map->data[i]);
\r
695 //tile = tile ? 0 : 1;
\r
698 //tile = tile ? 0 : 1;
\r
704 mapScrollRight(map_view_t *mv, byte offset) {
\r
705 word x, y; /* coordinate for drawing */
\r
707 /* increment the pixel position and update the page */
\r
708 mv->page->dx += offset;
\r
710 /* check to see if this changes the tile */
\r
711 if(mv->page->dx >= mv->dxThresh ) {
\r
712 /* go forward one tile */
\r
714 /* Snap the origin forward */
\r
715 mv->page->data += 4;
\r
716 mv->page->dx = mv->map->tiles->tileWidth;
\r
719 /* draw the next column */
\r
720 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
721 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
727 mapScrollLeft(map_view_t *mv, byte offset) {
\r
728 word x, y; /* coordinate for drawing */
\r
730 /* increment the pixel position and update the page */
\r
731 mv->page->dx -= offset;
\r
733 /* check to see if this changes the tile */
\r
734 if(mv->page->dx == 0) {
\r
735 /* go backward one tile */
\r
738 /* Snap the origin backward */
\r
739 mv->page->data -= 4;
\r
740 mv->page->dx = mv->map->tiles->tileWidth;
\r
742 /* draw the next column */
\r
743 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
749 mapScrollUp(map_view_t *mv, byte offset) {
\r
750 word x, y; /* coordinate for drawing */
\r
752 /* increment the pixel position and update the page */
\r
753 mv->page->dy -= offset;
\r
755 /* check to see if this changes the tile */
\r
756 if(mv->page->dy == 0 ) {
\r
757 /* go down one tile */
\r
759 /* Snap the origin downward */
\r
760 mv->page->data -= mv->page->width*4;
\r
761 mv->page->dy = mv->map->tiles->tileHeight;
\r
764 /* draw the next row */
\r
766 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
772 mapScrollDown(map_view_t *mv, byte offset) {
\r
773 word x, y; /* coordinate for drawing */
\r
775 /* increment the pixel position and update the page */
\r
776 mv->page->dy += offset;
\r
778 /* check to see if this changes the tile */
\r
779 if(mv->page->dy >= mv->dyThresh ) {
\r
780 /* go down one tile */
\r
782 /* Snap the origin downward */
\r
783 mv->page->data += mv->page->width*4;
\r
784 mv->page->dy = mv->map->tiles->tileHeight;
\r
787 /* draw the next row */
\r
788 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
789 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
796 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
800 /* set up the coordinates */
\r
803 mv->page->dx = mv->map->tiles->tileWidth;
\r
804 mv->page->dy = mv->map->tiles->tileHeight;
\r
806 /* set up the thresholds */
\r
807 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
808 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
810 /* draw the tiles */
\r
811 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
813 i=mv->ty * mv->map->width + mv->tx;
\r
814 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
815 mapDrawRow(mv, tx-1, ty, py);
\r
816 i+=mv->map->width - tx;
\r
822 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
832 rx = (((i-1) % ((t->data->width)/t->tileWidth)) * t->tileWidth);
\r
833 ry = (((i-1) / ((t->data->height)/t->tileHeight)) * t->tileHeight);
\r
834 //mxPutTile(t->data, x, y, t->tileWidth, t->tileHeight);
\r
835 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
\r
841 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
845 /* the position within the map array */
\r
846 i=ty * mv->map->width + tx;
\r
847 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
849 /* we are in the map, so copy! */
\r
850 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
857 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
861 /* location in the map array */
\r
862 i=ty * mv->map->width + tx;
\r
864 /* We'll copy all of the columns in the screen,
\r
865 i + 1 row above and one below */
\r
866 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
868 /* we are in the map, so copy away! */
\r
869 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
871 i += mv->map->width;
\r
881 void pdump(map_view_t *pee)
\r
884 int palq=(mult)*TILEWH;
\r
887 for(paly=0; paly<palq; paly+=mult){
\r
888 for(palx=0; palx<palq; palx+=mult){
\r
889 modexClearRegion(pee->page, palx+TILEWH, paly+TILEWH, mult, mult, palcol);
\r
896 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
898 sword dire=32*d; //direction
\r
899 sword qq; //scroll offset
\r
901 if(scrolloffsetswitch==0) qq = 0;
\r
902 else qq = ((lp)*SPEED);
\r
926 modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
\r
927 if(2>ls && ls>=1) { modexDrawSpriteRegion(dest->page, x, y, 48, dire, 24, 32, bmp); }else
\r
928 if(3>ls && ls>=2) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }else
\r
929 if(4>ls && ls>=3) { modexDrawSpriteRegion(dest->page, x, y, 0, dire, 24, 32, bmp); }else
\r
930 if(5>ls && ls>=4) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }
\r
931 //TODO: mask copy //modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
\r
932 //modexClearRegion(top->page, 66, 66, 2, 40, 0);
\r
933 //modexCopyPageRegion(dest->page, top->page, 66, 66, 66, 66, 2, 40);
\r
934 //turn this off if XT
\r
935 //if(detectcpu() > 0) modexWaitBorder();
\r