- map->tiles->tileHeight = TILEWH;
- map->tiles->tileWidth =TILEWH;
- map->tiles->rows = 1;
- map->tiles->cols = 2;
-
- i=0;
- for(y=0; y<TILEWH; y++) {
- for(x=0; x<(TILEWH*2); x++) {
- if(x<TILEWH)
- map->tiles->data->data[i] = 28;//0x24;
- else
- map->tiles->data->data[i] = 0;//0x34;
- i++;
- }
- }
-
- i=0;
- for(y=0; y<map->height; y++) {
- for(x=0; x<map->width; x++) {
- map->data[i] = tile;
- tile = tile ? 0 : 1;
- i++;
- }
- tile = tile ? 0 : 1;
- }
-}
-
-
-void
-mapScrollRight(map_view_t *mv, byte offset) {
- word x, y; /* coordinate for drawing */
-
- /* increment the pixel position and update the page */
- mv->page->dx += offset;
-
- /* check to see if this changes the tile */
- if(mv->page->dx >= mv->dxThresh ) {
- /* go forward one tile */
- mv->tx++;
- /* Snap the origin forward */
- mv->page->data += 4;
- mv->page->dx = mv->map->tiles->tileWidth;
- //}
-
- /* draw the next column */
- x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
- mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
- }
-}
-
-
-void
-mapScrollLeft(map_view_t *mv, byte offset) {
- word x, y; /* coordinate for drawing */
-
- /* increment the pixel position and update the page */
- mv->page->dx -= offset;
-
- /* check to see if this changes the tile */
- if(mv->page->dx == 0) {
- /* go backward one tile */
- mv->tx--;
-
- /* Snap the origin backward */
- mv->page->data -= 4;
- mv->page->dx = mv->map->tiles->tileWidth;
- //}
- /* draw the next column */
- mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
- }
-}
-
-
-void
-mapScrollUp(map_view_t *mv, byte offset) {
- word x, y; /* coordinate for drawing */
-
- /* increment the pixel position and update the page */
- mv->page->dy -= offset;
-
- /* check to see if this changes the tile */
- if(mv->page->dy == 0 ) {
- /* go down one tile */
- mv->ty--;
- /* Snap the origin downward */
- mv->page->data -= mv->page->width*4;
- mv->page->dy = mv->map->tiles->tileHeight;
- //}
-
- /* draw the next row */
- y= 0;
- mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
- }
-}
-
-
-void
-mapScrollDown(map_view_t *mv, byte offset) {
- word x, y; /* coordinate for drawing */
-
- /* increment the pixel position and update the page */
- mv->page->dy += offset;
-
- /* check to see if this changes the tile */
- if(mv->page->dy >= mv->dyThresh ) {
- /* go down one tile */
- mv->ty++;
- /* Snap the origin downward */
- mv->page->data += mv->page->width*4;
- mv->page->dy = mv->map->tiles->tileHeight;
- //}
-
- /* draw the next row */
- y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
- mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
- }
-
-}
-
-
-void
-mapGoTo(map_view_t *mv, int tx, int ty) {
- int px, py;
- unsigned int i;
-
- /* set up the coordinates */
- mv->tx = tx;
- mv->ty = ty;
- mv->page->dx = mv->map->tiles->tileWidth;
- mv->page->dy = mv->map->tiles->tileHeight;
-
- /* set up the thresholds */
- mv->dxThresh = mv->map->tiles->tileWidth * 2;
- mv->dyThresh = mv->map->tiles->tileHeight * 2;
-
- /* draw the tiles */
- modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
- py=0;
- i=mv->ty * mv->map->width + mv->tx;
- for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
- mapDrawRow(mv, tx-1, ty, py);
- i+=mv->map->width - tx;
- }
+ else map->tiles->data->data = xmsmalloc((TILEWH*2)*TILEWH);\r
+ map->tiles->tileHeight = TILEWH;\r
+ map->tiles->tileWidth =TILEWH;\r
+ map->tiles->rows = 1;\r
+ map->tiles->cols = 2;\r
+\r
+ i=0;\r
+ for(y=0; y<TILEWH; y++) {\r
+ for(x=0; x<(TILEWH*2); x++) {\r
+ if(x<TILEWH)\r
+ map->tiles->data->data[i] = 28;//0x24;\r
+ else\r
+ map->tiles->data->data[i] = 0;//0x34;\r
+ i++;\r
+ }\r
+ }\r
+\r
+ i=0;\r
+ for(y=0; y<map->height; y++) {\r
+ for(x=0; x<map->width; x++) {\r
+ map->data[i] = tile;\r
+ tile = tile ? 0 : 1;\r
+ i++;\r
+ }\r
+ tile = tile ? 0 : 1;\r
+ }\r
+}\r
+\r
+\r
+void\r
+mapScrollRight(map_view_t *mv, byte offset) {\r
+ word x, y; /* coordinate for drawing */\r
+\r
+ /* increment the pixel position and update the page */\r
+ mv->page->dx += offset;\r
+\r
+ /* check to see if this changes the tile */\r
+ if(mv->page->dx >= mv->dxThresh ) {\r
+ /* go forward one tile */\r
+ mv->tx++;\r
+ /* Snap the origin forward */\r
+ mv->page->data += 4;\r
+ mv->page->dx = mv->map->tiles->tileWidth;\r
+ //}\r
+\r
+ /* draw the next column */\r
+ x= SCREEN_WIDTH + mv->map->tiles->tileWidth;\r
+ mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);\r
+ }\r
+}\r
+\r
+\r
+void\r
+mapScrollLeft(map_view_t *mv, byte offset) {\r
+ word x, y; /* coordinate for drawing */\r
+\r
+ /* increment the pixel position and update the page */\r
+ mv->page->dx -= offset;\r
+\r
+ /* check to see if this changes the tile */\r
+ if(mv->page->dx == 0) {\r
+ /* go backward one tile */\r
+ mv->tx--;\r
+\r
+ /* Snap the origin backward */\r
+ mv->page->data -= 4;\r
+ mv->page->dx = mv->map->tiles->tileWidth;\r
+ //}\r
+ /* draw the next column */\r
+ mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);\r
+ }\r
+}\r
+\r
+\r
+void\r
+mapScrollUp(map_view_t *mv, byte offset) {\r
+ word x, y; /* coordinate for drawing */\r
+\r
+ /* increment the pixel position and update the page */\r
+ mv->page->dy -= offset;\r
+\r
+ /* check to see if this changes the tile */\r
+ if(mv->page->dy == 0 ) {\r
+ /* go down one tile */\r
+ mv->ty--;\r
+ /* Snap the origin downward */\r
+ mv->page->data -= mv->page->width*4;\r
+ mv->page->dy = mv->map->tiles->tileHeight;\r
+ //}\r
+\r
+ /* draw the next row */\r
+ y= 0;\r
+ mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);\r
+ }\r
+}\r
+\r
+\r
+void\r
+mapScrollDown(map_view_t *mv, byte offset) {\r
+ word x, y; /* coordinate for drawing */\r
+\r
+ /* increment the pixel position and update the page */\r
+ mv->page->dy += offset;\r
+\r
+ /* check to see if this changes the tile */\r
+ if(mv->page->dy >= mv->dyThresh ) {\r
+ /* go down one tile */\r
+ mv->ty++;\r
+ /* Snap the origin downward */\r
+ mv->page->data += mv->page->width*4;\r
+ mv->page->dy = mv->map->tiles->tileHeight;\r
+ //}\r
+\r
+ /* draw the next row */\r
+ y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;\r
+ mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);\r
+ }\r
+\r
+}\r
+\r
+\r
+void\r
+mapGoTo(map_view_t *mv, int tx, int ty) {\r
+ int px, py;\r
+ unsigned int i;\r
+\r
+ /* set up the coordinates */\r
+ mv->tx = tx;\r
+ mv->ty = ty;\r
+ mv->page->dx = mv->map->tiles->tileWidth;\r
+ mv->page->dy = mv->map->tiles->tileHeight;\r
+\r
+ /* set up the thresholds */\r
+ mv->dxThresh = mv->map->tiles->tileWidth * 2;\r
+ mv->dyThresh = mv->map->tiles->tileHeight * 2;\r
+\r
+ /* draw the tiles */\r
+ modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);\r
+ py=0;\r
+ i=mv->ty * mv->map->width + mv->tx;\r
+ for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {\r
+ mapDrawRow(mv, tx-1, ty, py);\r
+ i+=mv->map->width - tx;\r
+ }\r
+}\r
+\r
+\r
+void\r
+mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {\r
+ word rx;\r
+ word ry;\r
+ rx = (i % t->cols) * t->tileWidth;\r
+ ry = (i / t->cols) * t->tileHeight;\r
+ modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);\r
+}\r
+\r
+\r
+void \r
+mapDrawRow(map_view_t *mv, int tx, int ty, word y) {\r
+ word x;\r
+ int i;\r
+\r
+ /* the position within the map array */\r
+ i=ty * mv->map->width + tx;\r
+ for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {\r
+ if(i>=0) {\r
+ /* we are in the map, so copy! */\r
+ mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);\r
+ }\r
+ i++; /* next! */\r
+ }\r
+}\r
+\r
+void \r
+mapDrawCol(map_view_t *mv, int tx, int ty, word x) {\r
+ int y;\r
+ int i;\r
+\r
+ /* location in the map array */\r
+ i=ty * mv->map->width + tx;\r
+\r
+ /* We'll copy all of the columns in the screen, \r
+ i + 1 row above and one below */\r
+ for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {\r
+ if(i>=0) {\r
+ /* we are in the map, so copy away! */\r
+ mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);\r
+ }\r
+ i += mv->map->width;\r
+ }\r