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
56 page_t screen,screen2;
\r
59 map_view_t *draw, *show, *tmp;
\r
64 /* create the map */
\r
65 map = allocMap(40,30); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be drawn properly
\r
70 /* draw the tiles */
\r
73 screen = modexDefaultPage();
\r
77 screen2=modexNextPage(mv.page);
\r
78 mv2.page = &screen2;
\r
79 mapGoTo(&mv2, 0, 0);
\r
80 modexShowPage(mv.page);
\r
88 for(q=0; q<16; q++) {
\r
89 mapScrollRight(draw, 1);
\r
90 modexShowPage(draw->page);
\r
91 // mapScrollRight(draw, 1);
\r
92 // SWAP(draw, show);
\r
97 for(q=0; q<16; q++) {
\r
98 mapScrollLeft(draw, 1);
\r
99 modexShowPage(draw->page);
\r
100 // mapScrollLeft(show, 1);
\r
101 // SWAP(draw, show);
\r
106 for(q=0; q<16; q++) {
\r
107 mapScrollDown(draw, 1);
\r
108 modexShowPage(draw->page);
\r
109 // mapScrollDown(show, 1);
\r
110 // SWAP(draw, show);
\r
115 for(q=0; q<16; q++) {
\r
116 mapScrollUp(draw, 1);
\r
117 modexShowPage(draw->page);
\r
118 // mapScrollUp(show, 1);
\r
119 // SWAP(draw, show);
\r
133 allocMap(int w, int h) {
\r
138 result.data = malloc(sizeof(byte) * w * h);
\r
145 initMap(map_t *map) {
\r
146 /* just a place holder to fill out an alternating pattern */
\r
150 map->tiles = malloc(sizeof(tiles_t));
\r
152 /* create the tile set */
\r
153 map->tiles->data = malloc(sizeof(bitmap_t));
\r
154 map->tiles->data->width = 32;
\r
155 map->tiles->data->height= 16;
\r
156 map->tiles->data->data = malloc(32*16);
\r
157 map->tiles->tileHeight = 16;
\r
158 map->tiles->tileWidth = 16;
\r
159 map->tiles->rows = 1;
\r
160 map->tiles->cols = 2;
\r
163 for(y=0; y<16; y++) {
\r
164 for(x=0; x<32; x++) {
\r
166 map->tiles->data->data[i] = 0x24;
\r
168 map->tiles->data->data[i] = 0x34;
\r
174 for(y=0; y<map->height; y++) {
\r
175 for(x=0; x<map->width; x++) {
\r
176 map->data[i] = tile;
\r
177 tile = tile ? 0 : 1;
\r
180 tile = tile ? 0 : 1;
\r
186 mapScrollRight(map_view_t *mv, byte offset) {
\r
187 word x, y; /* coordinate for drawing */
\r
189 /* increment the pixel position and update the page */
\r
190 mv->page->dx += offset;
\r
192 /* check to see if this changes the tile */
\r
193 if(mv->page->dx >= mv->dxThresh ) {
\r
194 /* go forward one tile */
\r
196 /* Snap the origin forward */
\r
197 mv->page->data += 4;
\r
198 mv->page->dx = mv->map->tiles->tileWidth;
\r
201 /* draw the next column */
\r
202 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
203 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
209 mapScrollLeft(map_view_t *mv, byte offset) {
\r
210 word x, y; /* coordinate for drawing */
\r
212 /* increment the pixel position and update the page */
\r
213 mv->page->dx -= offset;
\r
215 /* check to see if this changes the tile */
\r
216 if(mv->page->dx == 0) {
\r
217 /* go backward one tile */
\r
220 /* Snap the origin backward */
\r
221 mv->page->data -= 4;
\r
222 mv->page->dx = mv->map->tiles->tileWidth;
\r
224 /* draw the next column */
\r
225 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
231 mapScrollUp(map_view_t *mv, byte offset) {
\r
232 word x, y; /* coordinate for drawing */
\r
234 /* increment the pixel position and update the page */
\r
235 mv->page->dy -= offset;
\r
237 /* check to see if this changes the tile */
\r
238 if(mv->page->dy == 0 ) {
\r
239 /* go down one tile */
\r
241 /* Snap the origin downward */
\r
242 mv->page->data -= mv->page->width*4;
\r
243 mv->page->dy = mv->map->tiles->tileHeight;
\r
246 /* draw the next row */
\r
248 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
254 mapScrollDown(map_view_t *mv, byte offset) {
\r
255 word x, y; /* coordinate for drawing */
\r
257 /* increment the pixel position and update the page */
\r
258 mv->page->dy += offset;
\r
260 /* check to see if this changes the tile */
\r
261 if(mv->page->dy >= mv->dyThresh ) {
\r
262 /* go down one tile */
\r
264 /* Snap the origin downward */
\r
265 mv->page->data += mv->page->width*4;
\r
266 mv->page->dy = mv->map->tiles->tileHeight;
\r
269 /* draw the next row */
\r
270 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
271 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
278 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
282 /* set up the coordinates */
\r
285 mv->page->dx = mv->map->tiles->tileWidth;
\r
286 mv->page->dy = mv->map->tiles->tileHeight;
\r
288 /* set up the thresholds */
\r
289 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
290 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
292 /* draw the tiles */
\r
293 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
295 i=mv->ty * mv->map->width + mv->tx;
\r
296 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
297 mapDrawRow(mv, tx-1, ty, py);
\r
298 i+=mv->map->width - tx;
\r
304 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
307 rx = (i % t->cols) * t->tileWidth;
\r
308 ry = (i / t->cols) * t->tileHeight;
\r
309 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r
314 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
318 /* the position within the map array */
\r
319 i=ty * mv->map->width + tx;
\r
320 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
322 /* we are in the map, so copy! */
\r
323 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
331 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
335 /* location in the map array */
\r
336 i=ty * mv->map->width + tx;
\r
338 /* We'll copy all of the columns in the screen,
\r
339 i + 1 row above and one below */
\r
340 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
342 /* we are in the map, so copy away! */
\r
343 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
345 i += mv->map->width;
\r