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
71 for(x=0; x<((80+0.50625)*16-SCREEN_WIDTH); x++) {
\r
72 mapScrollLeft(&mv, 1);
\r
73 modexShowPage(mv.page);
\r
76 for(x=0; x<((20)*16-SCREEN_WIDTH); x++) {
\r
77 mapScrollRight(&mv, 1);
\r
78 modexShowPage(mv.page);
\r
80 for(x=0; x<((40/*+0.50625*/)*16-SCREEN_WIDTH); x++) {
\r
81 mapScrollLeft(&mv, 1);
\r
82 modexShowPage(mv.page);
\r
85 /* spin for a time */
\r
86 for(x=0; x<500; x++) {
\r
95 allocMap(int w, int h) {
\r
100 result.data = malloc(sizeof(byte) * w * h);
\r
107 initMap(map_t *map) {
\r
108 /* just a place holder to fill out an alternating pattern */
\r
112 map->tiles = malloc(sizeof(tiles_t));
\r
114 /* create the tile set */
\r
115 map->tiles->data = malloc(sizeof(bitmap_t));
\r
116 map->tiles->data->width = 32;
\r
117 map->tiles->data->height= 16;
\r
118 map->tiles->data->data = malloc(32*16);
\r
119 map->tiles->tileHeight = 16;
\r
120 map->tiles->tileWidth = 16;
\r
121 map->tiles->rows = 1;
\r
122 map->tiles->cols = 2;
\r
125 for(y=0; y<16; y++) {
\r
126 for(x=0; x<32; x++) {
\r
128 map->tiles->data->data[i] = 0x00;
\r
130 map->tiles->data->data[i] = 0x47;
\r
136 for(y=0; y<map->height; y++) {
\r
137 for(x=0; x<map->width; x++) {
\r
138 map->data[i] = tile;
\r
139 tile = tile ? 0 : 1;
\r
142 tile = tile ? 0 : 1;
\r
148 mapScrollRight(map_view_t *mv, byte offset) {
\r
149 word x, y; /* coordinate for drawing */
\r
152 /* increment the pixel position and update the page */
\r
153 mv->page->dx += offset;
\r
155 /* check to see if this changes the tile */
\r
156 if(mv->page->dx >= 16) {
\r
157 /* go forward one tile */
\r
159 /* Snap the origin forward */
\r
160 mv->page->data += 4;
\r
164 /* draw the next column */
\r
166 i= mv->ty * mv->map->width + mv->tx + 20;
\r
167 for(y=0; y<SCREEN_HEIGHT; y+=16) {
\r
168 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, (int)mv->page->dx + x, (int)mv->page->dy+y);
\r
169 i += mv->map->width;
\r
176 mapScrollLeft(map_view_t *mv, byte offset) {
177 word x, y; /* coordinate for drawing */
\r
180 /* increment the pixel position and update the page */
\r
181 mv->page->dx -= offset;
\r
183 /* check to see if this changes the tile */
\r
184 if(mv->page->dx >= 16) {
\r
185 /* go forward one tile */
\r
187 /* Snap the origin forward */
\r
188 mv->page->data -= 4;
\r
192 /* draw the next column */
\r
194 i= mv->ty * mv->map->width + mv->tx + 20;
\r
195 for(y=0; y<SCREEN_HEIGHT; y+=16) {
\r
196 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, (int)mv->page->dx + x, (int)mv->page->dy+y);
\r
197 i += mv->map->width;
\r
204 mapScrollUp(map_view_t *mv, byte offset) {
\r
209 mapScrollDown(map_view_t *mv, byte offset) {
\r
214 mapGoTo(map_view_t *mv, byte tx, byte ty) {
\r
218 /* set up the coordinates */
\r
224 /* draw the tiles */
\r
225 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
227 i=mv->ty * mv->map->width + mv->tx;
\r
228 for(ty=mv->ty; py < SCREEN_HEIGHT && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
230 for(tx=mv->tx; px < SCREEN_WIDTH+16 && tx < mv->map->width+1; tx++, px+=mv->map->tiles->tileWidth) {
\r
231 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, px, py);
\r
234 i+=mv->map->width - tx;
\r
240 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
243 rx = (i % t->cols) * t->tileWidth;
\r
244 ry = (i / t->cols) * t->tileHeight;
\r
245 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r