5 word far *clock= (word far*) 0x046C; /* 18.2hz clock */
\r
34 map_t allocMap(int w, int h);
\r
35 void initMap(map_t *map);
\r
36 void mapScrollRight(map_view_t *mv, byte offset);
\r
37 void mapScrollLeft(map_view_t *mv, byte offest);
\r
38 void mapScrollUp(map_view_t *mv, byte offset);
\r
39 void mapScrollDown(map_view_t *mv, byte offset);
\r
40 void mapGoTo(map_view_t *mv, byte tx, byte ty);
\r
41 void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);
\r
52 /* create the map */
\r
53 map = allocMap(80,60);
\r
57 /* draw the tiles */
\r
60 screen = modexDefaultPage();
\r
65 /* scroll all the way to the right */
\r
66 for(x=0; x<(80*16-SCREEN_WIDTH); x++) {
\r
67 mapScrollRight(&mv, 1);
\r
68 modexShowPage(mv.page);
\r
72 /* spin for a time */
\r
73 for(x=0; x<500; x++) {
\r
82 allocMap(int w, int h) {
\r
87 result.data = malloc(sizeof(byte) * w * h);
\r
94 initMap(map_t *map) {
\r
95 /* just a place holder to fill out an alternating pattern */
\r
99 map->tiles = malloc(sizeof(tiles_t));
\r
101 /* create the tile set */
\r
102 map->tiles->data = malloc(sizeof(bitmap_t));
\r
103 map->tiles->data->width = 32;
\r
104 map->tiles->data->height= 16;
\r
105 map->tiles->data->data = malloc(32*16);
\r
106 map->tiles->tileHeight = 16;
\r
107 map->tiles->tileWidth = 16;
\r
108 map->tiles->rows = 1;
\r
109 map->tiles->cols = 2;
\r
112 for(y=0; y<16; y++) {
\r
113 for(x=0; x<32; x++) {
\r
115 map->tiles->data->data[i] = 0x00;
\r
117 map->tiles->data->data[i] = 0x47;
\r
123 for(y=0; y<map->height; y++) {
\r
124 for(x=0; x<map->width; x++) {
\r
125 map->data[i] = tile;
\r
126 tile = tile ? 0 : 1;
\r
129 tile = tile ? 0 : 1;
\r
135 mapScrollRight(map_view_t *mv, byte offset) {
\r
136 word x, y; /* coordinate for drawing */
\r
139 /* increment the pixel position and update the page */
\r
140 mv->page->dx += offset;
\r
142 /* check to see if this changes the tile */
\r
143 if(mv->page->dx >= 16) {
\r
144 /* go forward one tile */
\r
146 /* Snap the origin forward */
\r
147 mv->page->data += 4;
\r
151 /* draw the next column */
\r
153 i= mv->ty * mv->map->width + mv->tx + 20;
\r
154 for(y=0; y<240; y+=16) {
\r
155 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, (int)mv->page->dx + x, (int)mv->page->dy+y);
\r
156 i += mv->map->width;
\r
163 mapScrollLeft(map_view_t *mv, byte offest) {
\r
168 mapScrollUp(map_view_t *mv, byte offset) {
\r
173 mapScrollDown(map_view_t *mv, byte offset) {
\r
178 mapGoTo(map_view_t *mv, byte tx, byte ty) {
\r
182 /* set up the coordinates */
\r
188 /* draw the tiles */
\r
189 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
191 i=mv->ty * mv->map->width + mv->tx;
\r
192 for(ty=mv->ty; py < SCREEN_HEIGHT && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
194 for(tx=mv->tx; px < SCREEN_WIDTH+16 && tx < mv->map->width+1; tx++, px+=mv->map->tiles->tileWidth) {
\r
195 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, px, py);
\r
198 i+=mv->map->width - tx;
\r
204 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
207 rx = (i % t->cols) * t->tileWidth;
\r
208 ry = (i / t->cols) * t->tileHeight;
\r
209 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r