//word far *clock= (word far*) 0x046C; /* 18.2hz clock */\r
\r
typedef struct {\r
- bitmap_t *data;\r
- word tileHeight;\r
- word tileWidth;\r
- unsigned int rows;\r
- unsigned int cols;\r
+ bitmap_t *data;\r
+ word tileHeight;\r
+ word tileWidth;\r
+ unsigned int rows;\r
+ unsigned int cols;\r
} tiles_t;\r
\r
\r
typedef struct {\r
- byte *data;\r
- tiles_t *tiles;\r
- int width;\r
- int height;\r
+ byte *data;\r
+ tiles_t *tiles;\r
+ int width;\r
+ int height;\r
} map_t;\r
\r
\r
typedef struct {\r
- map_t *map;\r
- page_t *page;\r
- int tx;\r
- int ty;\r
- word dxThresh;\r
- word dyThresh;\r
+ map_t *map;\r
+ page_t *page;\r
+ int tx;\r
+ int ty;\r
+ word dxThresh;\r
+ word dyThresh;\r
} map_view_t;\r
\r
\r
\r
#define SWAP(a, b) tmp=a; a=b; b=tmp;\r
void main() {\r
- int show1=1;\r
- int tx, ty;\r
- int x, y;\r
+ int show1=1;\r
+ int tx, ty;\r
+ int x, y;\r
//int ch=0x0;\r
byte ch;\r
- int q=0;\r
- page_t screen,screen2;\r
- map_t map;\r
- map_view_t mv, mv2;\r
- map_view_t *draw, *show, *tmp;\r
- byte *ptr;\r
- \r
- /* create the map */\r
- map = allocMap(40,30);\r
- initMap(&map);\r
- mv.map = ↦\r
- mv2.map = ↦\r
-\r
- /* draw the tiles */\r
- ptr = map.data;\r
- modexEnter();\r
- screen = modexDefaultPage();\r
- screen.width = 352;\r
- mv.page = &screen;\r
- screen2=modexNextPage(mv.page);\r
- mv2.page = &screen2;\r
- mapGoTo(&mv, 0, 0);\r
- mapGoTo(&mv2, 0, 0);\r
- modexShowPage(mv.page);\r
-\r
- /* set up paging */\r
- show = &mv;\r
- draw = &mv2;\r
-\r
- while(!keyp(1)) {\r
+ int q=0;
+ setkb(1);\r
+ page_t screen,screen2;\r
+ map_t map;\r
+ map_view_t mv, mv2;\r
+ map_view_t *draw, *show, *tmp;\r
+ byte *ptr;\r
+ \r
+ /* create the map */\r
+ map = allocMap(40,30);\r
+ initMap(&map);\r
+ mv.map = ↦\r
+ mv2.map = ↦\r
+\r
+ /* draw the tiles */\r
+ ptr = map.data;\r
+ modexEnter();\r
+ screen = modexDefaultPage();\r
+ screen.width = 352;\r
+ mv.page = &screen;\r
+ screen2=modexNextPage(mv.page);\r
+ mv2.page = &screen2;\r
+ mapGoTo(&mv, 0, 0);\r
+ mapGoTo(&mv2, 0, 0);\r
+ modexShowPage(mv.page);\r
+\r
+ /* set up paging */\r
+ show = &mv;\r
+ draw = &mv2;\r
+\r
+ while(!keyp(1)) {\r
if(keyp(77)){\r
- for(q=0; q<16; q++) {\r
+ for(q=0; q<16; q++) {\r
mapScrollRight(draw, 1);\r
modexShowPage(draw->page);\r
SWAP(draw, show);\r
- }\r
+ }\r
}\r
\r
if(keyp(75)){\r
- for(q=0; q<16; q++) {\r
+ for(q=0; q<16; q++) {\r
mapScrollLeft(draw, 1);\r
modexShowPage(draw->page);\r
SWAP(draw, show);\r
- }\r
+ }\r
}\r
\r
if(keyp(80)){\r
- for(q=0; q<16; q++) {\r
+ for(q=0; q<16; q++) {\r
mapScrollDown(draw, 1);\r
modexShowPage(draw->page);\r
SWAP(draw, show);\r
- }\r
+ }\r
}\r
\r
\r
if(keyp(72)){\r
- for(q=0; q<16; q++) {\r
+ for(q=0; q<16; q++) {\r
mapScrollUp(draw, 1);\r
modexShowPage(draw->page);\r
SWAP(draw, show);\r
\r
- }\r
+ }\r
}\r
\r
- keyp(ch);\r
+ //keyp(ch);\r
\r
- }\r
+ }\r
\r
- modexLeave();\r
- setkb(0);\r
+ modexLeave();\r
+ setkb(0);\r
}\r
\r
\r
map_t\r
allocMap(int w, int h) {\r
- map_t result;\r
+ map_t result;\r
\r
- result.width =w;\r
- result.height=h;\r
- result.data = malloc(sizeof(byte) * w * h);\r
+ result.width =w;\r
+ result.height=h;\r
+ result.data = malloc(sizeof(byte) * w * h);\r
\r
- return result;\r
+ return result;\r
}\r
\r
\r
void\r
initMap(map_t *map) {\r
- /* just a place holder to fill out an alternating pattern */\r
- int x, y;\r
- int i;\r
- int tile = 1;\r
- map->tiles = malloc(sizeof(tiles_t));\r
-\r
- /* create the tile set */\r
- map->tiles->data = malloc(sizeof(bitmap_t));\r
- map->tiles->data->width = 32;\r
- map->tiles->data->height= 16;\r
- map->tiles->data->data = malloc(32*16);\r
- map->tiles->tileHeight = 16;\r
- map->tiles->tileWidth = 16;\r
- map->tiles->rows = 1;\r
- map->tiles->cols = 2;\r
-\r
- i=0;\r
- for(y=0; y<16; y++) {\r
+ /* just a place holder to fill out an alternating pattern */\r
+ int x, y;\r
+ int i;\r
+ int tile = 1;\r
+ map->tiles = malloc(sizeof(tiles_t));\r
+\r
+ /* create the tile set */\r
+ map->tiles->data = malloc(sizeof(bitmap_t));\r
+ map->tiles->data->width = 32;\r
+ map->tiles->data->height= 16;\r
+ map->tiles->data->data = malloc(32*16);\r
+ map->tiles->tileHeight = 16;\r
+ map->tiles->tileWidth = 16;\r
+ map->tiles->rows = 1;\r
+ map->tiles->cols = 2;\r
+\r
+ i=0;\r
+ for(y=0; y<16; y++) {\r
for(x=0; x<32; x++) {\r
- if(x<16)\r
- map->tiles->data->data[i] = 0x00;\r
- else\r
- map->tiles->data->data[i] = 0x47;\r
- i++;\r
+ if(x<16)\r
+ map->tiles->data->data[i] = 0x00;\r
+ else\r
+ map->tiles->data->data[i] = 0x47;\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
- 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
+ word x, y; /* coordinate for drawing */\r
\r
- /* increment the pixel position and update the page */\r
- mv->page->dx += offset;\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
+ /* 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
\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
+ 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
+ word x, y; /* coordinate for drawing */\r
\r
- /* increment the pixel position and update the page */\r
- mv->page->dx -= offset;\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
+ /* check to see if this changes the tile */\r
+ if(mv->page->dx == 0) {\r
/* go backward one tile */\r
mv->tx--;\r
- \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
+ 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
+ word x, y; /* coordinate for drawing */\r
\r
- /* increment the pixel position and update the page */\r
- mv->page->dy -= offset;\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
+ /* 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
\r
/* draw the next row */\r
y= 0;\r
- mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);\r
- }\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
+ word x, y; /* coordinate for drawing */\r
\r
- /* increment the pixel position and update the page */\r
- mv->page->dy += offset;\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
+ /* 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
\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
+ 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
+ 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
\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
+ 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
+ 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
+ /* 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
+ /* 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
\r
\r
void \r
mapDrawCol(map_view_t *mv, int tx, int ty, word x) {\r
- int y;\r
- int i;\r
+ int y;\r
+ int i;\r
\r
- /* location in the map array */\r
- i=ty * mv->map->width + tx;\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
+ /* 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
+ /* 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
+ }\r
}\r