1 //from https://github.com/sparky4/16/commit/7872dbf5d0240f01177588bd7966c3e042ced554
\r
2 #include "16/modex16/modex16.h"
\r
5 #include "16/modex16/dos_kb.h"
\r
7 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
\r
15 unsigned int tilex,tiley; // tile position on the map
\r
30 int tx; //???? appears to be the tile position on the viewable screen map
\r
31 int ty; //???? appears to be the tile position on the viewable screen map
\r
32 word dxThresh; //????
\r
33 word dyThresh; //????
\r
37 int tx; //player position on the viewable map
\r
38 int ty; //player position on the viewable map
\r
42 map_t allocMap(int w, int h);
\r
43 void initMap(map_t *map);
\r
44 void mapScrollRight(map_view_t *mv, byte offset);
\r
45 void mapScrollLeft(map_view_t *mv, byte offest);
\r
46 void mapScrollUp(map_view_t *mv, byte offset);
\r
47 void mapScrollDown(map_view_t *mv, byte offset);
\r
48 void mapGoTo(map_view_t *mv, int tx, int ty);
\r
49 void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);
\r
50 void mapDrawRow(map_view_t *mv, int tx, int ty, word y);
\r
51 void mapDrawCol(map_view_t *mv, int tx, int ty, word x);
\r
54 #define QUADWH (TILEWH/4)
\r
55 //#define SWAP(a, b) tmp=a; a=b; b=tmp;
\r
63 page_t screen;//,screen2;
\r
65 map_view_t mv;//, mv2;
\r
66 map_view_t *draw;//, *show, *tmp;
\r
69 //default player position on the viewable map
\r
74 /* create the map */
\r
75 map = allocMap(160,120); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be drawn properly
\r
80 /* draw the tiles */
\r
83 screen = modexDefaultPage();
\r
84 screen.width += (TILEWH*2);
\r
86 mapGoTo(&mv, 16, 16);
\r
87 // screen2=modexNextPage(mv.page);
\r
88 // mv2.page = &screen2;
\r
89 // mapGoTo(&mv2, 16, 16);
\r
90 // modexShowPage(mv.page);
\r
97 //TODO: set player position data here according to the viewable map screen thingy
\r
100 //TODO: top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
\r
101 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
\r
102 //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
104 // for(q=0; q<TILEWH; q++) {
\r
105 mapScrollRight(draw, 1);
\r
106 // modexShowPage(draw->page);
\r
107 // mapScrollRight(draw, 1);
\r
108 // SWAP(draw, show);
\r
113 // for(q=0; q<TILEWH; q++) {
\r
114 mapScrollLeft(draw, 1);
\r
115 // modexShowPage(draw->page);
\r
116 // mapScrollLeft(show, 1);
\r
117 // SWAP(draw, show);
\r
122 // for(q=0; q<TILEWH; q++) {
\r
123 mapScrollDown(draw, 1);
\r
124 // modexShowPage(draw->page);
\r
125 // mapScrollDown(show, 1);
\r
126 // SWAP(draw, show);
\r
131 // for(q=0; q<TILEWH; q++) {
\r
132 mapScrollUp(draw, 1);
\r
133 // modexShowPage(draw->page);
\r
134 // mapScrollUp(show, 1);
\r
135 // SWAP(draw, show);
\r
140 modexShowPage(draw->page);
\r
150 allocMap(int w, int h) {
\r
155 result.data = malloc(sizeof(byte) * w * h);
\r
162 initMap(map_t *map) {
\r
163 /* just a place holder to fill out an alternating pattern */
\r
167 map->tiles = malloc(sizeof(tiles_t));
\r
169 /* create the tile set */
\r
170 map->tiles->data = malloc(sizeof(bitmap_t));
\r
171 map->tiles->data->width = (TILEWH*2);
\r
172 map->tiles->data->height= TILEWH;
\r
173 map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
\r
174 map->tiles->tileHeight = TILEWH;
\r
175 map->tiles->tileWidth =TILEWH;
\r
176 map->tiles->rows = 1;
\r
177 map->tiles->cols = 2;
\r
180 for(y=0; y<TILEWH; y++) {
\r
181 for(x=0; x<(TILEWH*2); x++) {
\r
183 map->tiles->data->data[i] = 0x24;
\r
185 map->tiles->data->data[i] = 0x34;
\r
191 for(y=0; y<map->height; y++) {
\r
192 for(x=0; x<map->width; x++) {
\r
193 map->data[i] = tile;
\r
194 tile = tile ? 0 : 1;
\r
197 tile = tile ? 0 : 1;
\r
203 mapScrollRight(map_view_t *mv, byte offset) {
\r
204 word x, y; /* coordinate for drawing */
\r
206 /* increment the pixel position and update the page */
\r
207 mv->page->dx += offset;
\r
209 /* check to see if this changes the tile */
\r
210 if(mv->page->dx >= mv->dxThresh ) {
\r
211 /* go forward one tile */
\r
213 /* Snap the origin forward */
\r
214 mv->page->data += 4;
\r
215 mv->page->dx = mv->map->tiles->tileWidth;
\r
218 /* draw the next column */
\r
219 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
220 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
226 mapScrollLeft(map_view_t *mv, byte offset) {
\r
227 word x, y; /* coordinate for drawing */
\r
229 /* increment the pixel position and update the page */
\r
230 mv->page->dx -= offset;
\r
232 /* check to see if this changes the tile */
\r
233 if(mv->page->dx == 0) {
\r
234 /* go backward one tile */
\r
237 /* Snap the origin backward */
\r
238 mv->page->data -= 4;
\r
239 mv->page->dx = mv->map->tiles->tileWidth;
\r
241 /* draw the next column */
\r
242 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
248 mapScrollUp(map_view_t *mv, byte offset) {
\r
249 word x, y; /* coordinate for drawing */
\r
251 /* increment the pixel position and update the page */
\r
252 mv->page->dy -= offset;
\r
254 /* check to see if this changes the tile */
\r
255 if(mv->page->dy == 0 ) {
\r
256 /* go down one tile */
\r
258 /* Snap the origin downward */
\r
259 mv->page->data -= mv->page->width*4;
\r
260 mv->page->dy = mv->map->tiles->tileHeight;
\r
263 /* draw the next row */
\r
265 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
271 mapScrollDown(map_view_t *mv, byte offset) {
\r
272 word x, y; /* coordinate for drawing */
\r
274 /* increment the pixel position and update the page */
\r
275 mv->page->dy += offset;
\r
277 /* check to see if this changes the tile */
\r
278 if(mv->page->dy >= mv->dyThresh ) {
\r
279 /* go down one tile */
\r
281 /* Snap the origin downward */
\r
282 mv->page->data += mv->page->width*4;
\r
283 mv->page->dy = mv->map->tiles->tileHeight;
\r
286 /* draw the next row */
\r
287 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
288 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
295 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
299 /* set up the coordinates */
\r
302 mv->page->dx = mv->map->tiles->tileWidth;
\r
303 mv->page->dy = mv->map->tiles->tileHeight;
\r
305 /* set up the thresholds */
\r
306 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
307 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
309 /* draw the tiles */
\r
310 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
312 i=mv->ty * mv->map->width + mv->tx;
\r
313 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
314 mapDrawRow(mv, tx-1, ty, py);
\r
315 i+=mv->map->width - tx;
\r
321 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
324 rx = (i % t->cols) * t->tileWidth;
\r
325 ry = (i / t->cols) * t->tileHeight;
\r
326 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r
331 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
335 /* the position within the map array */
\r
336 i=ty * mv->map->width + tx;
\r
337 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
339 /* we are in the map, so copy! */
\r
340 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
348 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
352 /* location in the map array */
\r
353 i=ty * mv->map->width + tx;
\r
355 /* We'll copy all of the columns in the screen,
\r
356 i + 1 row above and one below */
\r
357 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
359 /* we are in the map, so copy away! */
\r
360 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
362 i += mv->map->width;
\r