1 #include "src/lib/dos_kb.h"
\r
2 #include "src/lib/mapread.h"
\r
3 #include "src/lib/wtest/wtest.c"
\r
4 #include "src/lib/planar.c"
\r
5 //====#include "src\lib\ems.c"
\r
7 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
\r
14 int tx; //appears to be the top left tile position on the viewable screen map
15 int ty; //appears to be the top left tile position on the viewable screen map
21 int x; //player exact position on the viewable map
22 int y; //player exact position on the viewable map
23 int tx; //player tile position on the viewable map
24 int ty; //player tile position on the viewable map
25 int triggerx; //player's trigger box tile position on the viewable map
26 int triggery; //player's trigger box tile position on the viewable map
27 int setx; //NOT USED YET! player sprite sheet set on the image x
28 int sety; //NOT USED YET! player sprite sheet set on the image y
29 word q; //loop variable
31 bitmap_t data; //supposively the sprite sheet data
32 int hp; //hitpoints of the player
35 map_t allocMap(int w, int h);
36 void initMap(map_t *map);
37 void mapScrollRight(map_view_t *mv, byte offset);
38 void mapScrollLeft(map_view_t *mv, byte offest);
39 void mapScrollUp(map_view_t *mv, byte offset);
40 void mapScrollDown(map_view_t *mv, byte offset);
41 void mapGoTo(map_view_t *mv, int tx, int ty);
42 void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);
43 void mapDrawRow(map_view_t *mv, int tx, int ty, word y);
44 void mapDrawCol(map_view_t *mv, int tx, int ty, word x);
46 void pdump(map_view_t *pee);
47 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);
50 #define QUADWH TILEWH/2
52 //#define LOOPMAX (TILEWH/SPEED)
54 //place holder definitions
61 size_t oldfreemem=GetFreeSize();
65 word panswitch=0, panq=1, pand=0, panpagenum=0; //for panning!
67 static word paloffset=0;
68 bitmap_t ptmp;//, npctmp; // player sprite
71 static int persist_aniframe = 0; /* gonna be increased to 1 before being used, so 0 is ok for default */
72 page_t screen, screen2, screen3;
74 map_view_t mv, mv2, mv3;
75 map_view_t *bg, *spri, *mask;//, *tmp;
86 printf("Expanded memory is not present\n");
92 printf("Expanded memory manager is not present\n");
96 emsavail = emmavail();
99 printf("Expanded memory manager error\n");
102 printf("There are %ld pages available\n",emsavail);
104 if((emmhandle = emmalloc(emsavail)) < 0)
106 printf("Insufficient pages available\n");
111 //0000 printf("Total used @ before map load: %zu\n", oldfreemem-GetFreeSize());
112 //0000 fprintf(stderr, "testing~\n");
113 loadmap("data/test.map", &map);
114 //0000 fprintf(stderr, "yay map loaded~~\n");
115 //---- 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
116 //if(isEMS()) printf("%d tesuto\n", coretotalEMS());
117 //---- initMap(&map);
124 mappalptr = map.tiles->data->palette;
126 //0000 printf("Total used @ before image loading: %zu\n", oldfreemem-GetFreeSize());
127 ptmp = bitmapLoadPcx("data/ptmp.pcx"); // load sprite
128 // font = bitmapLoadPcx("data/font.pcx");
129 //npctmp = bitmapLoadPcx("ptmp1.pcx"); // load sprite
131 /* create the planar buffer */
132 //0000 printf("Total used @ before planar buffer creation: %zu\n", oldfreemem-GetFreeSize());
133 p = planar_buf_from_bitmap(&ptmp);
134 //0000 printf("Total used @ after planar buffer creation: %zu\n", oldfreemem-GetFreeSize());
139 mm.length=sizeof(map);
141 mm.sourceOff=(long)↦
145 ist = move_emem(&mm);
146 printf("%d\n", coretotalEMS());
147 if(!ist){ dealloc_emem(emmhandle); exit(5); }
148 //printf("%d\n", emmhandle);
156 mm.sourceOff=(long)&ptmp;
160 ist = move_emem(&mm);
161 printf("%d\n", coretotalEMS());
162 if(!ist){ dealloc_emem(emmhandle); exit(5); }
163 //printf("%d\n", emmhandle);
167 /* save the palette */
168 dpal = modexNewPal();
170 modexFadeOff(4, dpal);
174 modexPalBlack(); //reset the palette~
175 // printf("Total used @ before palette initiation: %zu\n", oldfreemem-GetFreeSize());
176 ptmp.offset=(paloffset/3);
177 modexPalUpdate(&ptmp, &paloffset, 0, 0);
178 //printf(" %d\n", sizeof(ptmp.data));
179 //printf("1: %d\n", paloffset);
180 map.tiles->data->offset=(paloffset/3);
181 modexPalUpdate(map.tiles->data, &paloffset, 0, 0);
183 printf("0 paloffset= %d\n", paloffset/3);
185 gpal = modexNewPal();
187 modexSavePalFile("data/g.pal", gpal);
188 modexPalBlack(); //so player will not see loadings~
190 /* setup camera and screen~ */
191 screen = modexDefaultPage();
192 screen.width += (TILEWH*2);
193 screen.height += (TILEWH*2)+QUADWH;
195 screen2 = modexNextPage(mv.page);
197 screen3 = modexNextPage0(mv2.page, 352, 176); //(352*176)+1024 is the remaining amount of memory left wwww
198 //screen3 = modexNextPage0(mv2.page, 320, 192); //(352*176)+1024 is the remaining amount of memory left wwww
206 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
209 //mapGoTo(mask, 0, 0);
211 //TODO: put player in starting position of spot
212 //default player position on the viewable map
213 player.tx = bg->tx + 10;
214 player.ty = bg->ty + 8;
215 player.x = player.tx*TILEWH;
216 player.y = player.ty*TILEWH;
217 player.triggerx = player.tx;
218 player.triggery = player.ty+1;
223 /*npc0.tx = bg->tx + 1;
224 npc0.ty = bg->ty + 1;
225 npc0.x = npc0.tx*TILEWH;
226 npc0.y = npc0.ty*TILEWH;
227 npc0.triggerx = npc0.tx;
228 npc0.triggery = npc0.ty+1;
231 modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 64, 24, 32, &npctmp);*/
232 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
234 modexShowPage(spri->page);
235 // printf("Total used @ before loop: %zu\n", oldfreemem-GetFreeSize());
236 modexFadeOn(4, gpal);
237 while(!keyp(1) && player.hp>0)
239 //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
240 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
241 //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
242 #define INC_PER_FRAME if(player.q&1) persist_aniframe++; if(persist_aniframe>4) persist_aniframe = 1;
244 //modexClearRegion(bg->page, player.x, player.y, 16, 16, 4); //currently the over scan color!
245 /*#define INC_PER_FRAME_NPC if(npc0.q&1) persist_aniframe++; if(persist_aniframe>4) persist_aniframe = 1;
247 if(npc0.d == 0 && npc0.q == 1) npc0.d =rand()%8;
254 if(npc0.tx < map.width && !(npc0.tx+1 == TRIGGX && npc0.ty == TRIGGY) && !(npc0.tx+1 == player.tx && npc0.ty == player.ty))
256 if(npc0.q<=(TILEWH/SPEED))
260 //animatePlayer(bg, spri, mask, 1, 0, npc0.x, npc0.y, persist_aniframe, q, &npctmp);
261 animatePlayer(bg, spri, npc0.d-1, 0, npc0.x, npc0.y, persist_aniframe, npc0.q, &npctmp);
262 modexShowPage(spri->page);
264 } else { npc0.q = 1; npc0.d = 0; npc0.tx++; }
268 modexCopyPageRegion(spri->page, bg->page, npc0.x-4, npc0.y-TILEWH, npc0.x-4, npc0.y-TILEWH, 24, 32);
269 modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 32, 24, 32, &npctmp);
270 modexShowPage(spri->page);
273 npc0.triggerx = npc0.tx+1;
274 npc0.triggery = npc0.ty;
280 if(npc0.tx > 1 && !(npc0.tx-1 == TRIGGX && npc0.ty == TRIGGY) && !(npc0.tx-1 == player.tx && npc0.ty == player.ty))
282 if(npc0.q<=(TILEWH/SPEED))
286 //animatePlayer(bg, spri, mask, 3, 0, npc0.x, npc0.y, persist_aniframe, q, &npctmp);
287 animatePlayer(bg, spri, npc0.d-1, 0, npc0.x, npc0.y, persist_aniframe, npc0.q, &npctmp);
288 modexShowPage(spri->page);
290 } else { npc0.q = 1; npc0.d = 0; npc0.tx--; }
294 modexCopyPageRegion(spri->page, bg->page, npc0.x-4, npc0.y-TILEWH, npc0.x-4, npc0.y-TILEWH, 24, 32);
295 modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 96, 24, 32, &npctmp);
296 modexShowPage(spri->page);
299 npc0.triggerx = npc0.tx-1;
300 npc0.triggery = npc0.ty;
306 if(npc0.ty < map.height && !(npc0.tx == TRIGGX && npc0.ty+1 == TRIGGY) && !(npc0.tx == player.tx && npc0.ty == player.ty+1))
308 if(npc0.q<=(TILEWH/SPEED))
312 //animatePlayer(bg, spri, mask, 2, 0, npc0.x, npc0.y, persist_aniframe, q, &npctmp);
313 animatePlayer(bg, spri, npc0.d-1, 0, npc0.x, npc0.y, persist_aniframe, npc0.q, &npctmp);
314 modexShowPage(spri->page);
316 } else { npc0.q = 1; npc0.d = 0; npc0.ty++; }
320 modexCopyPageRegion(spri->page, bg->page, npc0.x-4, npc0.y-TILEWH, npc0.x-4, npc0.y-TILEWH, 24, 32);
321 modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 64, 24, 32, &npctmp);
322 modexShowPage(spri->page);
325 npc0.triggerx = npc0.tx;
326 npc0.triggery = npc0.ty+1;
332 if(npc0.ty > 1 && !(npc0.tx == TRIGGX && npc0.ty-1 == TRIGGY) && !(npc0.tx+1 == player.tx && npc0.ty == player.ty-1))
334 if(npc0.q<=(TILEWH/SPEED))
338 //animatePlayer(bg, spri, mask, 0, 0, npc0.x, npc0.y, persist_aniframe, q, &npctmp);
339 modexShowPage(spri->page);
340 animatePlayer(bg, spri, npc0.d-1, 0, npc0.x, npc0.y, persist_aniframe, npc0.q, &npctmp);
342 } else { npc0.q = 1; npc0.d = 0; npc0.ty--; }
346 modexCopyPageRegion(spri->page, bg->page, npc0.x-4, npc0.y-TILEWH, npc0.x-4, npc0.y-TILEWH, 24, 32);
347 modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 0, 24, 32, &npctmp);
348 modexShowPage(spri->page);
351 npc0.triggerx = npc0.tx;
352 npc0.triggery = npc0.ty-1;
355 if((npc0.triggery == player.ty && npc0.triggerx == player.tx) || (npc0.ty == player.ty && npc0.tx == player.tx)){ player.hp--; }
359 //TODO: make movement into a function!
362 if((keyp(77) && !keyp(75) && player.d == 0) || player.d == 2)
364 if(player.d == 0){ player.d = 2; }
365 if(bg->tx >= 0 && bg->tx+20 < map.width && player.tx == bg->tx + 10 &&
366 !(bg->map->data[(player.tx)+(map.width*(player.ty-1))] == 0))//!(player.tx+1 == TRIGGX && player.ty == TRIGGY)) //collision detection!
368 if(player.q<=(TILEWH/SPEED))
371 //animatePlayer(bg, spri, mask, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);
372 animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
373 mapScrollRight(bg, SPEED);
374 mapScrollRight(spri, SPEED);
375 //mapScrollRight(mask, SPEED);
376 modexShowPage(spri->page);
378 } else { player.q = 1; player.d = 0; player.tx++; }
380 else if(player.tx < map.width && !(bg->map->data[(player.tx)+(map.width*(player.ty-1))] == 0))//!(player.tx+1 == TRIGGX && player.ty == TRIGGY))
382 if(player.q<=(TILEWH/SPEED))
386 //animatePlayer(bg, spri, mask, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp);
387 animatePlayer(bg, spri, player.d-1, 0, player.x, player.y, persist_aniframe, player.q, &ptmp);
388 modexShowPage(spri->page);
390 } else { player.q = 1; player.d = 0; player.tx++; }
394 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
395 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 32, 24, 32, &ptmp);
396 modexShowPage(spri->page);
399 player.triggerx = player.tx+1;
400 player.triggery = player.ty;
404 if((keyp(75) && !keyp(77) && player.d == 0) || player.d == 4)
406 if(player.d == 0){ player.d = 4; }
407 if(bg->tx > 0 && bg->tx+20 <= map.width && player.tx == bg->tx + 10 &&
408 !(bg->map->data[(player.tx-2)+(map.width*(player.ty-1))] == 0))//!(player.tx-1 == TRIGGX && player.ty == TRIGGY)) //collision detection!
410 if(player.q<=(TILEWH/SPEED))
413 //animatePlayer(bg, spri, mask, 3, 1, player.x, player.y, persist_aniframe, q, &ptmp);
414 animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
415 mapScrollLeft(bg, SPEED);
416 mapScrollLeft(spri, SPEED);
417 //mapScrollLeft(mask, SPEED);
418 modexShowPage(spri->page);
420 } else { player.q = 1; player.d = 0; player.tx--; }
422 else if(player.tx > 1 && !(bg->map->data[(player.tx-2)+(map.width*(player.ty-1))] == 0))//!(player.tx-1 == TRIGGX && player.ty == TRIGGY))
424 if(player.q<=(TILEWH/SPEED))
428 //animatePlayer(bg, spri, mask, 3, 0, player.x, player.y, persist_aniframe, q, &ptmp);
429 animatePlayer(bg, spri, player.d-1, 0, player.x, player.y, persist_aniframe, player.q, &ptmp);
430 modexShowPage(spri->page);
432 } else { player.q = 1; player.d = 0; player.tx--; }
436 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
437 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 96, 24, 32, &ptmp);
438 modexShowPage(spri->page);
441 player.triggerx = player.tx-1;
442 player.triggery = player.ty;
446 if((keyp(80) && !keyp(72) && player.d == 0) || player.d == 3)
448 if(player.d == 0){ player.d = 3; }
449 if(bg->ty >= 0 && bg->ty+15 < map.height && player.ty == bg->ty + 8 &&
450 !(bg->map->data[(player.tx-1)+(map.width*(player.ty))] == 0))//!(player.tx == TRIGGX && player.ty+1 == TRIGGY)) //collision detection!
452 if(player.q<=(TILEWH/SPEED))
455 //animatePlayer(bg, spri, mask, 2, 1, player.x, player.y, persist_aniframe, q, &ptmp);
456 animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
457 mapScrollDown(bg, SPEED);
458 mapScrollDown(spri, SPEED);
459 //mapScrollDown(mask, SPEED);
460 modexShowPage(spri->page);
462 } else { player.q = 1; player.d = 0; player.ty++; }
464 else if(player.ty < map.height && !(bg->map->data[(player.tx-1)+(map.width*(player.ty))] == 0))//!(player.tx == TRIGGX && player.ty+1 == TRIGGY))
466 if(player.q<=(TILEWH/SPEED))
470 //animatePlayer(bg, spri, mask, 2, 0, player.x, player.y, persist_aniframe, q, &ptmp);
471 animatePlayer(bg, spri, player.d-1, 0, player.x, player.y, persist_aniframe, player.q, &ptmp);
472 modexShowPage(spri->page);
474 } else { player.q = 1; player.d = 0; player.ty++; }
478 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
479 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
480 modexShowPage(spri->page);
483 player.triggerx = player.tx;
484 player.triggery = player.ty+1;
488 if((keyp(72) && !keyp(80) && player.d == 0) || player.d == 1)
490 if(player.d == 0){ player.d = 1; }
491 if(bg->ty > 0 && bg->ty+15 <= map.height && player.ty == bg->ty + 8 &&
492 !(bg->map->data[(player.tx-1)+(map.width*(player.ty-2))] == 0))//!(player.tx == TRIGGX && player.ty-1 == TRIGGY)) //collision detection!
494 if(player.q<=(TILEWH/SPEED))
497 //animatePlayer(bg, spri, mask, 0, 1, player.x, player.y, persist_aniframe, q, &ptmp);
498 animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
499 mapScrollUp(bg, SPEED);
500 mapScrollUp(spri, SPEED);
501 //mapScrollUp(mask, SPEED);
502 modexShowPage(spri->page);
504 } else { player.q = 1; player.d = 0; player.ty--; }
506 else if(player.ty > 1 && !(bg->map->data[(player.tx-1)+(map.width*(player.ty-2))] == 0))//!(player.tx == TRIGGX && player.ty-1 == TRIGGY))
508 if(player.q<=(TILEWH/SPEED))
512 //animatePlayer(bg, spri, mask, 0, 0, player.x, player.y, persist_aniframe, q, &ptmp);
513 modexShowPage(spri->page);
514 animatePlayer(bg, spri, player.d-1, 0, player.x, player.y, persist_aniframe, player.q, &ptmp);
516 } else { player.q = 1; player.d = 0; player.ty--; }
520 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
521 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 0, 24, 32, &ptmp);
522 modexShowPage(spri->page);
525 player.triggerx = player.tx;
526 player.triggery = player.ty-1;
531 if((keyp(77) && !keyp(75) && pand == 0) || pand == 2)
533 if(pand == 0){ pand = 2; }
534 if(panq<=(TILEWH/SPEED))
541 modexShowPage(bg->page);
546 modexShowPage(spri->page);
551 modexShowPage(mask->page);
555 } else { panq = 1; pand = 0; }
558 if((keyp(75) && !keyp(77) && pand == 0) || pand == 4)
560 if(pand == 0){ pand = 4; }
561 if(panq<=(TILEWH/SPEED))
568 modexShowPage(bg->page);
573 modexShowPage(spri->page);
578 modexShowPage(mask->page);
582 } else { panq = 1; pand = 0; }
585 if((keyp(72) && !keyp(80) && pand == 0) || pand == 3)
587 if(pand == 0){ pand = 3; }
588 if(panq<=(TILEWH/SPEED))
595 modexShowPage(bg->page);
600 modexShowPage(spri->page);
605 modexShowPage(mask->page);
609 } else { panq = 1; pand = 0; }
612 if((keyp(80) && !keyp(72) && pand == 0) || pand == 1)
614 if(pand == 0){ pand = 1; }
615 if(panq<=(TILEWH/SPEED))
622 modexShowPage(bg->page);
627 modexShowPage(spri->page);
632 modexShowPage(mask->page);
636 } else { panq = 1; pand = 0; }
640 //the scripting stuf....
642 //if(((player.triggerx == TRIGGX && player.triggery == TRIGGY) && keyp(0x1C))||(player.tx == 5 && player.ty == 5))
643 if(((bg->map->data[(player.triggerx-1)+(map.width*(player.triggery-1))] == 0) && keyp(0x1C))||(player.tx == 5 && player.ty == 5))
646 for(i=800; i>=400; i--)
652 if(player.q == (TILEWH/SPEED)+1 && player.d > 0 && (player.triggerx == 5 && player.triggery == 5)){ player.hp--; }
654 //if(keyp(0x0E)) while(1){ if(xmsmalloc(24)) break; }
655 if(keyp(2)){ modexShowPage(bg->page); panpagenum=0; }
656 if(keyp(3)){ modexShowPage(spri->page); panpagenum=1; }
657 if(keyp(4)){ modexShowPage(mask->page); panpagenum=2; }
658 if(keyp(0x44)){ bputs(spri->page, player.x+(TILEWH*2), player.y+(TILEWH*2), "wwww"); } //f10
659 if(keyp(25)){ pdump(bg); pdump(spri); } //p
660 if(keyp(24)){ modexPalUpdate0(gpal); paloffset=0; pdump(bg); pdump(spri); }
662 paloffset=0; modexPalBlack(); modexPalUpdate(&ptmp, &paloffset, 0, 0);
663 printf("1paloffset = %d\n", paloffset/3);
664 modexPalUpdate(map.tiles->data, &paloffset, 0, 0);
665 printf("2paloffset = %d\n", paloffset/3);
666 pdump(bg); pdump(spri); }
668 if(keyp(88)){if(!panswitch) panswitch++; else panswitch--; } //f12
681 if((player.q==1) && !(player.x%TILEWH==0 && player.y%TILEWH==0)) break; //incase things go out of sync!
685 /* fade back to text mode */
686 /* but 1st lets save the game palette~ */
688 modexSavePalFile("data/g.pal", gpal);
689 modexFadeOff(4, gpal);
692 printf("Project 16 scroll.exe\n");
693 printf("tx: %d\n", bg->tx);
694 printf("ty: %d\n", bg->ty);
695 printf("player.x: %d", player.x); printf(" player.y: %d\n", player.y);
696 //if(player.hp==0) printf("%d wwww\n", player.y+8);
697 //else printf("\nplayer.y: %d\n", player.y);
698 printf("player.tx: %d", player.tx); printf(" player.ty: %d\n", player.ty);
699 printf("player.triggx: %d", player.triggerx); printf(" player.triggy: %d\n", player.triggery);
700 printf("player.hp: %d", player.hp); printf(" player.q: %d", player.q); printf(" player.d: %d\n", player.d);
701 printf("tile data value at player trigger position: %d\n", bg->map->data[(player.triggerx-1)+(map.width*(player.triggery-1))]);
702 printf("palette offset: %d\n", paloffset/3);
703 printf("Total used: %zu\n", oldfreemem-GetFreeSize());
704 printf("Total free: %zu\n", GetFreeSize());
705 printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");
706 printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");
707 printf("Screen: %dx", screen.width); printf("%d\n", screen.height);
708 printf("Screen2: %dx", screen2.width); printf("%d\n", screen2.height);
709 //printf("map.width=%d map.height=%d map.data[0]=%d\n", bg->map->width, bg->map->height, bg->map->data[0]);
715 //emmclose(emmhandle);
716 printf("%Fp\n", bios_8x8_font());
717 //printf("%c\n", *bios_8x8_font());
720 case 0: cpus = "8086/8088 or 186/88"; break;
721 case 1: cpus = "286"; break;
722 case 2: cpus = "386 or newer"; break;
723 default: cpus = "internal error"; break;
725 printf("detected CPU type: %s\n", cpus);
726 modexFadeOn(4, dpal);
731 allocMap(int w, int h) {
736 result.data = malloc(sizeof(byte) * w * h);
737 //result.data = (byte *)alloc_emem(((int)sizeof(byte) * w * h)/1024);
738 /*if(isEMS() || checkEMS())
741 //emmhandle = mallocEMS(coretotalEMS());//alloc_emem((int)sizeof(map))
742 mm.length=sizeof(result);
744 mm.sourceOff=ptr2long(&result);
747 ist = move_emem(&mm);
748 if(!ist){ dealloc_emem(emmhandle); exit(5); }
749 printf("%d\n", coretotalEMS());
756 initMap(map_t *map) {
757 /* just a place holder to fill out an alternating pattern */
761 //if(!isEMS() || !checkEMS())
762 // map->tiles = malloc(sizeof(tiles_t));
764 // map->tiles = (tiles_t *)alloc_emem(sizeof(tiles_t));
766 /* create the tile set */
767 //if(!isEMS() || !checkEMS())
768 // map->tiles->data = malloc(sizeof(bitmap_t));
770 // map->tiles->data = (bitmap_t *)alloc_emem(sizeof(bitmap_t));
771 // map->tiles->data->width = (TILEWH/**2*/);
772 // map->tiles->data->height= TILEWH;
773 //if(!isEMS() || !checkEMS())
774 // map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
776 // map->tiles->data->data = (byte *)alloc_emem((TILEWH*2)*TILEWH);
777 // map->tiles->tileHeight = TILEWH;
778 // map->tiles->tileWidth =TILEWH;
779 // map->tiles->rows = 1;
780 // map->tiles->cols = 1;//2;
783 //for(y=0; y<map->height; y++) {
784 //for(x=0; x<map->width; x++) {
786 for(yy=0; yy<TILEWH; yy++) {
787 for(xx=0; xx<(TILEWH); xx++) {
789 map->tiles->data->data[i+1] = map->data[q];//28;//0x24;
790 // printf("[%d]", map->tiles->data->data[i]);
792 //map->tiles->data->data[i] = map->data[q];//0;//0x34;
793 //printf("]%d[==[%d]", i, map->tiles->data->data[i]);
799 // printf("[%d]", map->data[q]);
806 for(y=0; y<map->height; y++) {
807 for(x=0; x<map->width; x++) {
809 printf("[%d]", map->data[i]);
810 //tile = tile ? 0 : 1;
813 //tile = tile ? 0 : 1;
819 mapScrollRight(map_view_t *mv, byte offset) {
820 word x, y; /* coordinate for drawing */
822 /* increment the pixel position and update the page */
823 mv->page->dx += offset;
825 /* check to see if this changes the tile */
826 if(mv->page->dx >= mv->dxThresh ) {
827 /* go forward one tile */
829 /* Snap the origin forward */
831 mv->page->dx = mv->map->tiles->tileWidth;
834 /* draw the next column */
835 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
836 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
842 mapScrollLeft(map_view_t *mv, byte offset) {
843 word x, y; /* coordinate for drawing */
845 /* increment the pixel position and update the page */
846 mv->page->dx -= offset;
848 /* check to see if this changes the tile */
849 if(mv->page->dx == 0) {
850 /* go backward one tile */
853 /* Snap the origin backward */
855 mv->page->dx = mv->map->tiles->tileWidth;
857 /* draw the next column */
858 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
864 mapScrollUp(map_view_t *mv, byte offset) {
865 word x, y; /* coordinate for drawing */
867 /* increment the pixel position and update the page */
868 mv->page->dy -= offset;
870 /* check to see if this changes the tile */
871 if(mv->page->dy == 0 ) {
872 /* go down one tile */
874 /* Snap the origin downward */
875 mv->page->data -= mv->page->width*4;
876 mv->page->dy = mv->map->tiles->tileHeight;
879 /* draw the next row */
881 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
887 mapScrollDown(map_view_t *mv, byte offset) {
888 word x, y; /* coordinate for drawing */
890 /* increment the pixel position and update the page */
891 mv->page->dy += offset;
893 /* check to see if this changes the tile */
894 if(mv->page->dy >= mv->dyThresh ) {
895 /* go down one tile */
897 /* Snap the origin downward */
898 mv->page->data += mv->page->width*4;
899 mv->page->dy = mv->map->tiles->tileHeight;
902 /* draw the next row */
903 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
904 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
911 mapGoTo(map_view_t *mv, int tx, int ty) {
915 /* set up the coordinates */
918 mv->page->dx = mv->map->tiles->tileWidth;
919 mv->page->dy = mv->map->tiles->tileHeight;
921 /* set up the thresholds */
922 mv->dxThresh = mv->map->tiles->tileWidth * 2;
923 mv->dyThresh = mv->map->tiles->tileHeight * 2;
926 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
928 i=mv->ty * mv->map->width + mv->tx;
929 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
930 mapDrawRow(mv, tx-1, ty, py);
931 i+=mv->map->width - tx;
937 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
944 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 0); //currently the over scan color!
948 rx = (((i-1) % ((t->data->width)/t->tileWidth)) * t->tileWidth);
949 ry = (((i-1) / ((t->data->height)/t->tileHeight)) * t->tileHeight);
950 ////0000 printf("i=%d\n", i);
951 //mxPutTile(t->data, x, y, t->tileWidth, t->tileHeight);
952 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
958 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
962 /* the position within the map array */
963 i=ty * mv->map->width + tx;
964 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
966 /* we are in the map, so copy! */
967 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
974 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
978 /* location in the map array */
979 i=ty * mv->map->width + tx;
981 /* We'll copy all of the columns in the screen,
982 i + 1 row above and one below */
983 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
985 /* we are in the map, so copy away! */
986 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
998 void pdump(map_view_t *pee)
1001 int palq=(mult)*TILEWH;
1004 for(paly=0; paly<palq; paly+=mult){
1005 for(palx=0; palx<palq; palx+=mult){
1006 modexClearRegion(pee->page, palx+TILEWH, paly+TILEWH, mult, mult, palcol);
1013 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)
1015 sword dire=32*d; //direction
1016 sword qq; //scroll offset
1018 if(scrolloffsetswitch==0) qq = 0;
1019 else qq = ((lp)*SPEED);
1043 modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
1044 if(2>ls && ls>=1) { modexDrawSpriteRegion(dest->page, x, y, 48, dire, 24, 32, bmp); }else
1045 if(3>ls && ls>=2) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }else
1046 if(4>ls && ls>=3) { modexDrawSpriteRegion(dest->page, x, y, 0, dire, 24, 32, bmp); }else
1047 if(5>ls && ls>=4) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }
1048 //TODO: mask copy //modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
1049 //modexClearRegion(top->page, 66, 66, 2, 40, 0);
1050 //modexCopyPageRegion(dest->page, top->page, 66, 66, 66, 66, 2, 40);
1051 //turn this off if XT
1052 if(detectcpu() > 0) modexWaitBorder();