5 word far *clock= (word far*) 0x046C; /* 18.2hz clock */
\r
36 map_t allocMap(int w, int h);
\r
37 void initMap(map_t *map);
\r
38 void mapScrollRight(map_view_t *mv, byte offset);
\r
39 void mapScrollLeft(map_view_t *mv, byte offest);
\r
40 void mapScrollUp(map_view_t *mv, byte offset);
\r
41 void mapScrollDown(map_view_t *mv, byte offset);
\r
42 void mapGoTo(map_view_t *mv, int tx, int ty);
\r
43 void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);
\r
44 void mapDrawRow(map_view_t *mv, int tx, int ty, word y);
\r
45 void mapDrawCol(map_view_t *mv, int tx, int ty, word x);
\r
47 #define SWAP(a, b) tmp=a; a=b; b=tmp;
\r
52 page_t screen,screen2;
\r
55 map_view_t *draw, *show, *tmp;
\r
58 /* create the map */
\r
59 map = allocMap(80,60);
\r
64 /* draw the tiles */
\r
67 screen = modexDefaultPage();
\r
70 screen2=modexNextPage(mv.page);
\r
71 mv2.page = &screen2;
\r
73 mapGoTo(&mv2, 0, 0);
\r
74 modexShowPage(mv.page);
\r
79 /* scroll all the way to the right */
\r
80 for(x=0; x<(map.width*16-SCREEN_WIDTH); x++) {
\r
81 mapScrollRight(draw, 1);
\r
82 modexShowPage(draw->page);
\r
83 mapScrollRight(show, 1);
\r
87 /* scroll all the way to the left */
\r
89 mapScrollLeft(&mv, 1);
\r
90 modexShowPage(mv.page);
\r
93 /* scroll all the way down */
\r
94 for(y=0; y<(map.height*16-SCREEN_HEIGHT); y++) {
\r
95 mapScrollDown(&mv, 1);
\r
96 modexShowPage(mv.page);
\r
99 /* scroll all the way up */
\r
101 mapScrollUp(&mv, 1);
\r
102 modexShowPage(mv.page);
\r
105 /* spin for a time */
\r
106 for(x=0; x<500; x++) {
\r
115 allocMap(int w, int h) {
\r
120 result.data = malloc(sizeof(byte) * w * h);
\r
127 initMap(map_t *map) {
\r
128 /* just a place holder to fill out an alternating pattern */
\r
132 map->tiles = malloc(sizeof(tiles_t));
\r
134 /* create the tile set */
\r
135 map->tiles->data = malloc(sizeof(bitmap_t));
\r
136 map->tiles->data->width = 32;
\r
137 map->tiles->data->height= 16;
\r
138 map->tiles->data->data = malloc(32*16);
\r
139 map->tiles->tileHeight = 16;
\r
140 map->tiles->tileWidth = 16;
\r
141 map->tiles->rows = 1;
\r
142 map->tiles->cols = 2;
\r
145 for(y=0; y<16; y++) {
\r
146 for(x=0; x<32; x++) {
\r
148 map->tiles->data->data[i] = 0x00;
\r
150 map->tiles->data->data[i] = 0x47;
\r
156 for(y=0; y<map->height; y++) {
\r
157 for(x=0; x<map->width; x++) {
\r
158 map->data[i] = tile;
\r
159 tile = tile ? 0 : 1;
\r
162 tile = tile ? 0 : 1;
\r
168 mapScrollRight(map_view_t *mv, byte offset) {
\r
169 word x, y; /* coordinate for drawing */
\r
171 /* increment the pixel position and update the page */
\r
172 mv->page->dx += offset;
\r
174 /* check to see if this changes the tile */
\r
175 if(mv->page->dx >= mv->dxThresh ) {
\r
176 /* go forward one tile */
\r
178 /* Snap the origin forward */
\r
179 mv->page->data += 4;
\r
180 mv->page->dx = mv->map->tiles->tileWidth;
\r
183 /* draw the next column */
\r
184 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
185 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
191 mapScrollLeft(map_view_t *mv, byte offset) {
\r
192 word x, y; /* coordinate for drawing */
\r
194 /* increment the pixel position and update the page */
\r
195 mv->page->dx -= offset;
\r
197 /* check to see if this changes the tile */
\r
198 if(mv->page->dx == 0) {
\r
199 /* go backward one tile */
\r
202 /* Snap the origin backward */
\r
203 mv->page->data -= 4;
\r
204 mv->page->dx = mv->map->tiles->tileWidth;
\r
206 /* draw the next column */
\r
207 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
213 mapScrollUp(map_view_t *mv, byte offset) {
\r
214 word x, y; /* coordinate for drawing */
\r
216 /* increment the pixel position and update the page */
\r
217 mv->page->dy -= offset;
\r
219 /* check to see if this changes the tile */
\r
220 if(mv->page->dy == 0 ) {
\r
221 /* go down one tile */
\r
223 /* Snap the origin downward */
\r
224 mv->page->data -= mv->page->width*4;
\r
225 mv->page->dy = mv->map->tiles->tileHeight;
\r
228 /* draw the next row */
\r
230 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
236 mapScrollDown(map_view_t *mv, byte offset) {
\r
237 word x, y; /* coordinate for drawing */
\r
239 /* increment the pixel position and update the page */
\r
240 mv->page->dy += offset;
\r
242 /* check to see if this changes the tile */
\r
243 if(mv->page->dy >= mv->dyThresh ) {
\r
244 /* go down one tile */
\r
246 /* Snap the origin downward */
\r
247 mv->page->data += mv->page->width*4;
\r
248 mv->page->dy = mv->map->tiles->tileHeight;
\r
251 /* draw the next row */
\r
252 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
253 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
260 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
264 /* set up the coordinates */
\r
267 mv->page->dx = mv->map->tiles->tileWidth;
\r
268 mv->page->dy = mv->map->tiles->tileHeight;
\r
270 /* set up the thresholds */
\r
271 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
272 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
274 /* draw the tiles */
\r
275 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
277 i=mv->ty * mv->map->width + mv->tx;
\r
278 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
279 mapDrawRow(mv, tx-1, ty, py);
\r
280 i+=mv->map->width - tx;
\r
286 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
289 rx = (i % t->cols) * t->tileWidth;
\r
290 ry = (i / t->cols) * t->tileHeight;
\r
291 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r
296 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
300 /* the position within the map array */
\r
301 i=ty * mv->map->width + tx;
\r
302 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
304 /* we are in the map, so copy! */
\r
305 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
313 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
317 /* location in the map array */
\r
318 i=ty * mv->map->width + tx;
\r
320 /* We'll copy all of the columns in the screen,
\r
321 i + 1 row above and one below */
\r
322 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
324 /* we are in the map, so copy away! */
\r
325 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
327 i += mv->map->width;
\r