5 word far *clock= (word far*) 0x046C; /* 18.2hz clock */
\r
34 map_t allocMap(int w, int h);
\r
35 void initMap(map_t *map);
\r
36 void mapScrollRight(map_view_t *mv, byte offset);
\r
37 void mapScrollLeft(map_view_t *mv, byte offest);
\r
38 void mapScrollUp(map_view_t *mv, byte offset);
\r
39 void mapScrollDown(map_view_t *mv, byte offset);
\r
40 void mapGoTo(map_view_t *mv, byte tx, byte ty);
\r
41 void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);
\r
42 void mapDrawRow(map_view_t *mv, int tx, int ty, word y);
\r
43 void mapDrawCol(map_view_t *mv, int tx, int ty, word x);
\r
54 /* create the map */
\r
55 map = allocMap(80,60);
\r
59 /* draw the tiles */
\r
62 screen = modexDefaultPage();
\r
68 /* scroll all the way to the right */
\r
70 for(x=0; x<((20)*16-SCREEN_WIDTH); x++) {
\r
71 mapScrollRight(&mv, 1);
\r
72 modexShowPage(mv.page);
\r
74 for(x=0; x<((40/*+0.50625*/)*16-SCREEN_WIDTH); x++) {
\r
75 mapScrollLeft(&mv, 1);
\r
76 modexShowPage(mv.page);
\r
79 /* spin for a time */
\r
80 for(x=0; x<500; x++) {
\r
89 allocMap(int w, int h) {
\r
94 result.data = malloc(sizeof(byte) * w * h);
\r
101 initMap(map_t *map) {
\r
102 /* just a place holder to fill out an alternating pattern */
\r
106 map->tiles = malloc(sizeof(tiles_t));
\r
108 /* create the tile set */
\r
109 map->tiles->data = malloc(sizeof(bitmap_t));
\r
110 map->tiles->data->width = 32;
\r
111 map->tiles->data->height= 16;
\r
112 map->tiles->data->data = malloc(32*16);
\r
113 map->tiles->tileHeight = 16;
\r
114 map->tiles->tileWidth = 16;
\r
115 map->tiles->rows = 1;
\r
116 map->tiles->cols = 2;
\r
119 for(y=0; y<16; y++) {
\r
120 for(x=0; x<32; x++) {
\r
122 map->tiles->data->data[i] = 0x00;
\r
124 map->tiles->data->data[i] = 0x47;
\r
130 for(y=0; y<map->height; y++) {
\r
131 for(x=0; x<map->width; x++) {
\r
132 map->data[i] = tile;
\r
133 tile = tile ? 0 : 1;
\r
136 tile = tile ? 0 : 1;
\r
142 mapScrollRight(map_view_t *mv, byte offset) {
\r
143 word x, y; /* coordinate for drawing */
\r
146 /* increment the pixel position and update the page */
\r
147 mv->page->dx += offset;
\r
149 /* check to see if this changes the tile */
\r
150 if(mv->page->dx >= 16) {
\r
151 /* go forward one tile */
\r
153 /* Snap the origin forward */
\r
154 mv->page->data += 4;
\r
158 /* draw the next column */
\r
160 i= mv->ty * mv->map->width + mv->tx + 20;
\r
161 for(y=0; y<SCREEN_HEIGHT; y+=16) {
\r
162 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, (int)mv->page->dx + x, (int)mv->page->dy+y);
\r
163 i += mv->map->width;
\r
170 mapScrollLeft(map_view_t *mv, byte offset) {
\r
171 word x, y; /* coordinate for drawing */
\r
174 /* increment the pixel position and update the page */
\r
175 mv->page->dx -= offset;
\r
177 /* check to see if this changes the tile */
\r
178 if(mv->page->dx >= 16) {
\r
179 /* go forward one tile */
\r
181 /* Snap the origin forward */
\r
182 mv->page->data -= 4;
\r
186 /* draw the next column */
\r
188 i= mv->ty * mv->map->width + mv->tx + 20;
\r
189 for(y=0; y<SCREEN_HEIGHT; y+=16) {
\r
190 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, (int)mv->page->dx + x, (int)mv->page->dy+y);
\r
191 i += mv->map->width;
\r
198 mapScrollUp(map_view_t *mv, byte offset) {
\r
203 mapScrollDown(map_view_t *mv, byte offset) {
\r
208 mapGoTo(map_view_t *mv, byte tx, byte ty) {
\r
212 /* set up the coordinates */
\r
218 /* draw the tiles */
\r
219 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
221 i=mv->ty * mv->map->width + mv->tx;
\r
222 for(ty=mv->ty; py < SCREEN_HEIGHT && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
224 for(tx=mv->tx; px < SCREEN_WIDTH+16 && tx < mv->map->width+1; tx++, px+=mv->map->tiles->tileWidth) {
\r
225 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, px, py);
\r
228 i+=mv->map->width - tx;
\r
234 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
237 rx = (i % t->cols) * t->tileWidth;
\r
238 ry = (i / t->cols) * t->tileHeight;
\r
239 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r
244 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
248 /* the position within the map array */
\r
249 i=ty * mv->map->width + tx;
\r
250 for(x=0; x<SCREEN_HEIGHT+2 & tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
252 /* we are in the map, so copy! */
\r
253 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
261 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
265 /* location in the map array */
\r
266 i=ty * mv->map->width + tx;
\r
268 /* We'll copy all of the columns in the screen,
\r
269 i + 1 row above and one below */
\r
270 for(y=0; y<SCREEN_HEIGHT+2 && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
272 /* we are in the map, so copy away! */
\r
273 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
275 i += mv->map->width;
\r