6 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
\r
37 map_t allocMap(int w, int h);
\r
38 void initMap(map_t *map);
\r
39 void mapScrollRight(map_view_t *mv, byte offset);
\r
40 void mapScrollLeft(map_view_t *mv, byte offest);
\r
41 void mapScrollUp(map_view_t *mv, byte offset);
\r
42 void mapScrollDown(map_view_t *mv, byte offset);
\r
43 void mapGoTo(map_view_t *mv, int tx, int ty);
\r
44 void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);
\r
45 void mapDrawRow(map_view_t *mv, int tx, int ty, word y);
\r
46 void mapDrawCol(map_view_t *mv, int tx, int ty, word x);
\r
48 #define SWAP(a, b) tmp=a; a=b; b=tmp;
\r
57 page_t screen,screen2;
\r
60 map_view_t *draw, *show, *tmp;
\r
63 /* create the map */
\r
64 map = allocMap(40,30);
\r
69 /* draw the tiles */
\r
72 screen = modexDefaultPage();
\r
75 screen2=modexNextPage(mv.page);
\r
76 mv2.page = &screen2;
\r
78 mapGoTo(&mv2, 0, 0);
\r
79 modexShowPage(mv.page);
\r
87 for(q=0; q<16; q++) {
\r
88 mapScrollRight(draw, 1);
\r
89 modexShowPage(draw->page);
\r
95 for(q=0; q<16; q++) {
\r
96 mapScrollLeft(draw, 1);
\r
97 modexShowPage(draw->page);
\r
103 for(q=0; q<16; q++) {
\r
104 mapScrollDown(draw, 1);
\r
105 modexShowPage(draw->page);
\r
112 for(q=0; q<16; q++) {
\r
113 mapScrollUp(draw, 1);
\r
114 modexShowPage(draw->page);
\r
130 allocMap(int w, int h) {
\r
135 result.data = malloc(sizeof(byte) * w * h);
\r
142 initMap(map_t *map) {
\r
143 /* just a place holder to fill out an alternating pattern */
\r
147 map->tiles = malloc(sizeof(tiles_t));
\r
149 /* create the tile set */
\r
150 map->tiles->data = malloc(sizeof(bitmap_t));
\r
151 map->tiles->data->width = 32;
\r
152 map->tiles->data->height= 16;
\r
153 map->tiles->data->data = malloc(32*16);
\r
154 map->tiles->tileHeight = 16;
\r
155 map->tiles->tileWidth = 16;
\r
156 map->tiles->rows = 1;
\r
157 map->tiles->cols = 2;
\r
160 for(y=0; y<16; y++) {
\r
161 for(x=0; x<32; x++) {
\r
163 map->tiles->data->data[i] = 0x00;
\r
165 map->tiles->data->data[i] = 0x47;
\r
171 for(y=0; y<map->height; y++) {
\r
172 for(x=0; x<map->width; x++) {
\r
173 map->data[i] = tile;
\r
174 tile = tile ? 0 : 1;
\r
177 tile = tile ? 0 : 1;
\r
183 mapScrollRight(map_view_t *mv, byte offset) {
\r
184 word x, y; /* coordinate for drawing */
\r
186 /* increment the pixel position and update the page */
\r
187 mv->page->dx += offset;
\r
189 /* check to see if this changes the tile */
\r
190 if(mv->page->dx >= mv->dxThresh ) {
\r
191 /* go forward one tile */
\r
193 /* Snap the origin forward */
\r
194 mv->page->data += 4;
\r
195 mv->page->dx = mv->map->tiles->tileWidth;
\r
198 /* draw the next column */
\r
199 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
200 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
206 mapScrollLeft(map_view_t *mv, byte offset) {
\r
207 word x, y; /* coordinate for drawing */
\r
209 /* increment the pixel position and update the page */
\r
210 mv->page->dx -= offset;
\r
212 /* check to see if this changes the tile */
\r
213 if(mv->page->dx == 0) {
\r
214 /* go backward one tile */
\r
217 /* Snap the origin backward */
\r
218 mv->page->data -= 4;
\r
219 mv->page->dx = mv->map->tiles->tileWidth;
\r
221 /* draw the next column */
\r
222 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
228 mapScrollUp(map_view_t *mv, byte offset) {
\r
229 word x, y; /* coordinate for drawing */
\r
231 /* increment the pixel position and update the page */
\r
232 mv->page->dy -= offset;
\r
234 /* check to see if this changes the tile */
\r
235 if(mv->page->dy == 0 ) {
\r
236 /* go down one tile */
\r
238 /* Snap the origin downward */
\r
239 mv->page->data -= mv->page->width*4;
\r
240 mv->page->dy = mv->map->tiles->tileHeight;
\r
243 /* draw the next row */
\r
245 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
251 mapScrollDown(map_view_t *mv, byte offset) {
\r
252 word x, y; /* coordinate for drawing */
\r
254 /* increment the pixel position and update the page */
\r
255 mv->page->dy += offset;
\r
257 /* check to see if this changes the tile */
\r
258 if(mv->page->dy >= mv->dyThresh ) {
\r
259 /* go down one tile */
\r
261 /* Snap the origin downward */
\r
262 mv->page->data += mv->page->width*4;
\r
263 mv->page->dy = mv->map->tiles->tileHeight;
\r
266 /* draw the next row */
\r
267 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
268 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
275 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
279 /* set up the coordinates */
\r
282 mv->page->dx = mv->map->tiles->tileWidth;
\r
283 mv->page->dy = mv->map->tiles->tileHeight;
\r
285 /* set up the thresholds */
\r
286 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
287 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
289 /* draw the tiles */
\r
290 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
292 i=mv->ty * mv->map->width + mv->tx;
\r
293 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
294 mapDrawRow(mv, tx-1, ty, py);
\r
295 i+=mv->map->width - tx;
\r
301 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
304 rx = (i % t->cols) * t->tileWidth;
\r
305 ry = (i / t->cols) * t->tileHeight;
\r
306 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r
311 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
315 /* the position within the map array */
\r
316 i=ty * mv->map->width + tx;
\r
317 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
319 /* we are in the map, so copy! */
\r
320 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
328 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
332 /* location in the map array */
\r
333 i=ty * mv->map->width + tx;
\r
335 /* We'll copy all of the columns in the screen,
\r
336 i + 1 row above and one below */
\r
337 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
339 /* we are in the map, so copy away! */
\r
340 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
342 i += mv->map->width;
\r