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
62 /* create the map */
\r
63 map = allocMap(40,30);
\r
67 /* draw the tiles */
\r
70 screen = modexDefaultPage();
\r
74 modexShowPage(mv.page);
\r
78 // scroll all the way to the right
\r
79 //for(x=0; x<(map.width*16-SCREEN_WIDTH); x++) {
82 for(q=0; q<16; q++) {
\r
83 mapScrollRight(&mv, 1);
\r
84 modexShowPage(mv.page);
88 // scroll all the way to the left
\r
92 for(q=0; q<16; q++) {
\r
93 mapScrollLeft(&mv, 1);
\r
94 modexShowPage(mv.page);
98 // scroll all the way down
\r
99 //for(y=0; y<(map.height*16-SCREEN_HEIGHT); y++) {
102 for(q=0; q<16; q++) {
\r
103 mapScrollDown(&mv, 1);
\r
104 modexShowPage(mv.page);
108 // scroll all the way up
\r
112 for(q=0; q<16; q++) {
\r
113 mapScrollUp(&mv, 1);
\r
114 modexShowPage(mv.page);
118 // spin for a time
\r
119 /*for(x=0; x<500; x++) {
\r
124 //printf("0x%02x\n", ch);
126 // if(ch==0x71)break; // 'q'
\r
127 // if(ch==0x1b)break; // 'ESC'
\r
135 allocMap(int w, int h) {
\r
140 result.data = malloc(sizeof(byte) * w * h);
\r
147 initMap(map_t *map) {
\r
148 /* just a place holder to fill out an alternating pattern */
\r
152 map->tiles = malloc(sizeof(tiles_t));
\r
154 /* create the tile set */
\r
155 map->tiles->data = malloc(sizeof(bitmap_t));
\r
156 map->tiles->data->width = 32;
\r
157 map->tiles->data->height= 16;
\r
158 map->tiles->data->data = malloc(32*16);
\r
159 map->tiles->tileHeight = 16;
\r
160 map->tiles->tileWidth = 16;
\r
161 map->tiles->rows = 1;
\r
162 map->tiles->cols = 2;
\r
165 for(y=0; y<16; y++) {
\r
166 for(x=0; x<32; x++) {
\r
168 map->tiles->data->data[i] = 0x00;
\r
170 map->tiles->data->data[i] = 0x47;
\r
176 for(y=0; y<map->height; y++) {
\r
177 for(x=0; x<map->width; x++) {
\r
178 map->data[i] = tile;
\r
179 tile = tile ? 0 : 1;
\r
182 tile = tile ? 0 : 1;
\r
188 mapScrollRight(map_view_t *mv, byte offset) {
\r
189 word x, y; /* coordinate for drawing */
\r
191 /* increment the pixel position and update the page */
\r
192 mv->page->dx += offset;
\r
194 /* check to see if this changes the tile */
\r
195 if(mv->page->dx >= mv->dxThresh ) {
\r
196 /* go forward one tile */
\r
198 /* Snap the origin forward */
\r
199 mv->page->data += 4;
\r
200 mv->page->dx = mv->map->tiles->tileWidth;
\r
203 /* draw the next column */
\r
204 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
205 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
211 mapScrollLeft(map_view_t *mv, byte offset) {
\r
212 word x, y; /* coordinate for drawing */
\r
214 /* increment the pixel position and update the page */
\r
215 mv->page->dx -= offset;
\r
217 /* check to see if this changes the tile */
\r
218 if(mv->page->dx == 0) {
\r
219 /* go backward one tile */
\r
222 /* Snap the origin backward */
\r
223 mv->page->data -= 4;
\r
224 mv->page->dx = mv->map->tiles->tileWidth;
\r
226 /* draw the next column */
\r
227 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
233 mapScrollUp(map_view_t *mv, byte offset) {
\r
234 word x, y; /* coordinate for drawing */
\r
236 /* increment the pixel position and update the page */
\r
237 mv->page->dy -= offset;
\r
239 /* check to see if this changes the tile */
\r
240 if(mv->page->dy == 0 ) {
\r
241 /* go down one tile */
\r
243 /* Snap the origin downward */
\r
244 mv->page->data -= mv->page->width*4;
\r
245 mv->page->dy = mv->map->tiles->tileHeight;
\r
248 /* draw the next row */
\r
250 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
256 mapScrollDown(map_view_t *mv, byte offset) {
\r
257 word x, y; /* coordinate for drawing */
\r
259 /* increment the pixel position and update the page */
\r
260 mv->page->dy += offset;
\r
262 /* check to see if this changes the tile */
\r
263 if(mv->page->dy >= mv->dyThresh ) {
\r
264 /* go down one tile */
\r
266 /* Snap the origin downward */
\r
267 mv->page->data += mv->page->width*4;
\r
268 mv->page->dy = mv->map->tiles->tileHeight;
\r
271 /* draw the next row */
\r
272 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
273 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
280 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
284 /* set up the coordinates */
\r
287 mv->page->dx = mv->map->tiles->tileWidth;
\r
288 mv->page->dy = mv->map->tiles->tileHeight;
\r
290 /* set up the thresholds */
\r
291 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
292 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
294 /* draw the tiles */
\r
295 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
297 i=mv->ty * mv->map->width + mv->tx;
\r
298 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
299 mapDrawRow(mv, tx-1, ty, py);
\r
300 i+=mv->map->width - tx;
\r
306 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
309 rx = (i % t->cols) * t->tileWidth;
\r
310 ry = (i / t->cols) * t->tileHeight;
\r
311 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r
316 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
320 /* the position within the map array */
\r
321 i=ty * mv->map->width + tx;
\r
322 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
324 /* we are in the map, so copy! */
\r
325 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
333 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
337 /* location in the map array */
\r
338 i=ty * mv->map->width + tx;
\r
340 /* We'll copy all of the columns in the screen,
\r
341 i + 1 row above and one below */
\r
342 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
344 /* we are in the map, so copy away! */
\r
345 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
347 i += mv->map->width;
\r