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
56 /* create the map */
\r
57 map = allocMap(80,60);
\r
61 /* draw the tiles */
\r
64 screen = modexDefaultPage();
\r
68 modexShowPage(mv.page);
\r
70 /* scroll all the way to the right */
\r
71 for(x=0; x<(map.width*16-SCREEN_WIDTH); x++) {
\r
72 mapScrollRight(&mv, 1);
\r
73 modexShowPage(mv.page);
\r
76 /* scroll all the way to the left */
\r
78 mapScrollLeft(&mv, 1);
\r
79 modexShowPage(mv.page);
\r
82 /* scroll all the way down */
\r
83 for(y=0; y<(map.height*16-SCREEN_HEIGHT); y++) {
\r
84 mapScrollDown(&mv, 1);
\r
85 modexShowPage(mv.page);
\r
88 /* scroll all the way up */
\r
90 mapScrollUp(&mv, 1);
\r
91 modexShowPage(mv.page);
\r
94 /* spin for a time */
\r
95 for(x=0; x<500; x++) {
\r
104 allocMap(int w, int h) {
\r
109 result.data = malloc(sizeof(byte) * w * h);
\r
116 initMap(map_t *map) {
\r
117 /* just a place holder to fill out an alternating pattern */
\r
121 map->tiles = malloc(sizeof(tiles_t));
\r
123 /* create the tile set */
\r
124 map->tiles->data = malloc(sizeof(bitmap_t));
\r
125 map->tiles->data->width = 32;
\r
126 map->tiles->data->height= 16;
\r
127 map->tiles->data->data = malloc(32*16);
\r
128 map->tiles->tileHeight = 16;
\r
129 map->tiles->tileWidth = 16;
\r
130 map->tiles->rows = 1;
\r
131 map->tiles->cols = 2;
\r
134 for(y=0; y<16; y++) {
\r
135 for(x=0; x<32; x++) {
\r
137 map->tiles->data->data[i] = 0x00;
\r
139 map->tiles->data->data[i] = 0x47;
\r
145 for(y=0; y<map->height; y++) {
\r
146 for(x=0; x<map->width; x++) {
\r
147 map->data[i] = tile;
\r
148 tile = tile ? 0 : 1;
\r
151 tile = tile ? 0 : 1;
\r
157 mapScrollRight(map_view_t *mv, byte offset) {
\r
158 word x, y; /* coordinate for drawing */
\r
160 /* increment the pixel position and update the page */
\r
161 mv->page->dx += offset;
\r
163 /* check to see if this changes the tile */
\r
164 if(mv->page->dx >= mv->dxThresh ) {
\r
165 /* go forward one tile */
\r
167 /* Snap the origin forward */
\r
168 mv->page->data += 4;
\r
169 mv->page->dx = mv->map->tiles->tileWidth;
\r
172 /* draw the next column */
\r
173 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
174 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
180 mapScrollLeft(map_view_t *mv, byte offset) {
\r
181 word x, y; /* coordinate for drawing */
\r
183 /* increment the pixel position and update the page */
\r
184 mv->page->dx -= offset;
\r
186 /* check to see if this changes the tile */
\r
187 if(mv->page->dx == 0) {
\r
188 /* go backward one tile */
\r
191 /* Snap the origin backward */
\r
192 mv->page->data -= 4;
\r
193 mv->page->dx = mv->map->tiles->tileWidth;
\r
195 /* draw the next column */
\r
196 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
202 mapScrollUp(map_view_t *mv, byte offset) {
\r
203 word x, y; /* coordinate for drawing */
\r
205 /* increment the pixel position and update the page */
\r
206 mv->page->dy -= offset;
\r
208 /* check to see if this changes the tile */
\r
209 if(mv->page->dy == 0 ) {
\r
210 /* go down one tile */
\r
212 /* Snap the origin downward */
\r
213 mv->page->data -= mv->page->width*4;
\r
214 mv->page->dy = mv->map->tiles->tileHeight;
\r
217 /* draw the next row */
\r
219 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
225 mapScrollDown(map_view_t *mv, byte offset) {
\r
226 word x, y; /* coordinate for drawing */
\r
228 /* increment the pixel position and update the page */
\r
229 mv->page->dy += offset;
\r
231 /* check to see if this changes the tile */
\r
232 if(mv->page->dy >= mv->dyThresh ) {
\r
233 /* go down one tile */
\r
235 /* Snap the origin downward */
\r
236 mv->page->data += mv->page->width*4;
\r
237 mv->page->dy = mv->map->tiles->tileHeight;
\r
240 /* draw the next row */
\r
241 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
242 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
249 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
253 /* set up the coordinates */
\r
256 mv->page->dx = mv->map->tiles->tileWidth;
\r
257 mv->page->dy = mv->map->tiles->tileHeight;
\r
259 /* set up the thresholds */
\r
260 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
261 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
263 /* draw the tiles */
\r
264 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
266 i=mv->ty * mv->map->width + mv->tx;
\r
267 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
268 mapDrawRow(mv, tx-1, ty, py);
\r
269 i+=mv->map->width - tx;
\r
275 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
278 rx = (i % t->cols) * t->tileWidth;
\r
279 ry = (i / t->cols) * t->tileHeight;
\r
280 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r
285 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
289 /* the position within the map array */
\r
290 i=ty * mv->map->width + tx;
\r
291 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
293 /* we are in the map, so copy! */
\r
294 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
302 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
306 /* location in the map array */
\r
307 i=ty * mv->map->width + tx;
\r
309 /* We'll copy all of the columns in the screen,
\r
310 i + 1 row above and one below */
\r
311 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
313 /* we are in the map, so copy away! */
\r
314 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
316 i += mv->map->width;
\r