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);
\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
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
116 for(q=0; q<16; q++) {
\r
117 mapScrollUp(draw, 1);
\r
118 modexShowPage(draw->page);
\r
119 //mapScrollUp(show, 1);
\r
120 //SWAP(draw, show);
\r
134 allocMap(int w, int h) {
\r
139 result.data = malloc(sizeof(byte) * w * h);
\r
146 initMap(map_t *map) {
\r
147 /* just a place holder to fill out an alternating pattern */
\r
151 map->tiles = malloc(sizeof(tiles_t));
\r
153 /* create the tile set */
\r
154 map->tiles->data = malloc(sizeof(bitmap_t));
\r
155 map->tiles->data->width = 32;
\r
156 map->tiles->data->height= 16;
\r
157 map->tiles->data->data = malloc(32*16);
\r
158 map->tiles->tileHeight = 16;
\r
159 map->tiles->tileWidth = 16;
\r
160 map->tiles->rows = 1;
\r
161 map->tiles->cols = 2;
\r
164 for(y=0; y<16; y++) {
\r
165 for(x=0; x<32; x++) {
\r
167 map->tiles->data->data[i] = 0x00;
\r
169 map->tiles->data->data[i] = 0x47;
\r
175 for(y=0; y<map->height; y++) {
\r
176 for(x=0; x<map->width; x++) {
\r
177 map->data[i] = tile;
\r
178 tile = tile ? 0 : 1;
\r
181 tile = tile ? 0 : 1;
\r
187 mapScrollRight(map_view_t *mv, byte offset) {
\r
188 word x, y; /* coordinate for drawing */
\r
190 /* increment the pixel position and update the page */
\r
191 mv->page->dx += offset;
\r
193 /* check to see if this changes the tile */
\r
194 if(mv->page->dx >= mv->dxThresh ) {
\r
195 /* go forward one tile */
\r
197 /* Snap the origin forward */
\r
198 mv->page->data += 4;
\r
199 mv->page->dx = mv->map->tiles->tileWidth;
\r
202 /* draw the next column */
\r
203 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
204 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
210 mapScrollLeft(map_view_t *mv, byte offset) {
\r
211 word x, y; /* coordinate for drawing */
\r
213 /* increment the pixel position and update the page */
\r
214 mv->page->dx -= offset;
\r
216 /* check to see if this changes the tile */
\r
217 if(mv->page->dx == 0) {
\r
218 /* go backward one tile */
\r
221 /* Snap the origin backward */
\r
222 mv->page->data -= 4;
\r
223 mv->page->dx = mv->map->tiles->tileWidth;
\r
225 /* draw the next column */
\r
226 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
232 mapScrollUp(map_view_t *mv, byte offset) {
\r
233 word x, y; /* coordinate for drawing */
\r
235 /* increment the pixel position and update the page */
\r
236 mv->page->dy -= offset;
\r
238 /* check to see if this changes the tile */
\r
239 if(mv->page->dy == 0 ) {
\r
240 /* go down one tile */
\r
242 /* Snap the origin downward */
\r
243 mv->page->data -= mv->page->width*4;
\r
244 mv->page->dy = mv->map->tiles->tileHeight;
\r
247 /* draw the next row */
\r
249 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
255 mapScrollDown(map_view_t *mv, byte offset) {
\r
256 word x, y; /* coordinate for drawing */
\r
258 /* increment the pixel position and update the page */
\r
259 mv->page->dy += offset;
\r
261 /* check to see if this changes the tile */
\r
262 if(mv->page->dy >= mv->dyThresh ) {
\r
263 /* go down one tile */
\r
265 /* Snap the origin downward */
\r
266 mv->page->data += mv->page->width*4;
\r
267 mv->page->dy = mv->map->tiles->tileHeight;
\r
270 /* draw the next row */
\r
271 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
272 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
279 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
283 /* set up the coordinates */
\r
286 mv->page->dx = mv->map->tiles->tileWidth;
\r
287 mv->page->dy = mv->map->tiles->tileHeight;
\r
289 /* set up the thresholds */
\r
290 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
291 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
293 /* draw the tiles */
\r
294 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
296 i=mv->ty * mv->map->width + mv->tx;
\r
297 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
298 mapDrawRow(mv, tx-1, ty, py);
\r
299 i+=mv->map->width - tx;
\r
305 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
308 rx = (i % t->cols) * t->tileWidth;
\r
309 ry = (i / t->cols) * t->tileHeight;
\r
310 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r
315 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
319 /* the position within the map array */
\r
320 i=ty * mv->map->width + tx;
\r
321 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
323 /* we are in the map, so copy! */
\r
324 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
332 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
336 /* location in the map array */
\r
337 i=ty * mv->map->width + tx;
\r
339 /* We'll copy all of the columns in the screen,
\r
340 i + 1 row above and one below */
\r
341 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
343 /* we are in the map, so copy away! */
\r
344 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
346 i += mv->map->width;
\r