]> 4ch.mooo.com Git - 16.git/blob - 16/modex16/scroll.c
deleted: 16/modex16/ED.PCX
[16.git] / 16 / modex16 / scroll.c
1 #include "modex16.h"\r
2 #include <stdio.h>\r
3 #include <stdlib.h>\r
4 \r
5 word far *clock= (word far*) 0x046C; /* 18.2hz clock */\r
6 \r
7 typedef struct {\r
8     bitmap_t *data;\r
9     word tileHeight;\r
10     word tileWidth;\r
11     word rows;\r
12     word cols;\r
13 } tiles_t;\r
14 \r
15 \r
16 typedef struct {\r
17     byte    *data;\r
18     tiles_t *tiles;\r
19     word width;\r
20     word height;\r
21 } map_t;\r
22 \r
23 \r
24 typedef struct {\r
25     map_t *map;\r
26     page_t *page;\r
27     word tx;\r
28     word ty;\r
29 } map_view_t;\r
30 \r
31 \r
32 \r
33 \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
42 \r
43 void main() {\r
44     int show1=1;\r
45     int tx, ty;\r
46     int x, y;\r
47     page_t screen;\r
48     map_t map;\r
49     map_view_t mv;\r
50     byte *ptr;\r
51     \r
52     /* create the map */\r
53     map = allocMap(80,60);\r
54     initMap(&map);\r
55     mv.map = &map;\r
56 \r
57     /* draw the tiles */\r
58     ptr = map.data;\r
59     modexEnter();\r
60     screen = modexDefaultPage();\r
61     screen.width = 352;\r
62     mv.page = &screen;\r
63     mapGoTo(&mv, 0, 0);\r
64 \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
69     }
70 \r
71     for(x=0; x<((80+0.50625)*16-SCREEN_WIDTH); x++) {\r
72         mapScrollLeft(&mv, 1);\r
73         modexShowPage(mv.page);\r
74     }*/
75
76     for(x=0; x<((20)*16-SCREEN_WIDTH); x++) {\r
77         mapScrollRight(&mv, 1);\r
78         modexShowPage(mv.page);\r
79     }\r
80     for(x=0; x<((40/*+0.50625*/)*16-SCREEN_WIDTH); x++) {\r
81         mapScrollLeft(&mv, 1);\r
82         modexShowPage(mv.page);\r
83     }
84 \r
85     /* spin for a time */\r
86     for(x=0; x<500; x++) {\r
87         modexWaitBorder();\r
88     }\r
89 \r
90     modexLeave();\r
91 }\r
92 \r
93 \r
94 map_t\r
95 allocMap(int w, int h) {\r
96     map_t result;\r
97     \r
98     result.width =w;\r
99     result.height=h;\r
100     result.data = malloc(sizeof(byte) * w * h);\r
101 \r
102     return result;\r
103 }\r
104 \r
105 \r
106 void\r
107 initMap(map_t *map) {\r
108     /* just a place holder to fill out an alternating pattern */\r
109     int x, y;\r
110     int i;\r
111     int tile = 1;\r
112     map->tiles = malloc(sizeof(tiles_t));\r
113 \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
123 \r
124     i=0;\r
125     for(y=0; y<16; y++) {\r
126         for(x=0; x<32; x++) {\r
127             if(x<16)\r
128               map->tiles->data->data[i] = 0x00;\r
129             else\r
130               map->tiles->data->data[i] = 0x47;\r
131             i++;\r
132         }\r
133     }\r
134 \r
135     i=0;\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
140             i++;\r
141         }\r
142         tile = tile ? 0 : 1;\r
143     }\r
144 }\r
145 \r
146 \r
147 void\r
148 mapScrollRight(map_view_t *mv, byte offset) {\r
149     word x, y;  /* coordinate for drawing */\r
150     unsigned int i;\r
151 \r
152     /* increment the pixel position and update the page */\r
153     mv->page->dx += offset;\r
154 \r
155     /* check to see if this changes the tile */\r
156     if(mv->page->dx >= 16) {\r
157         /* go forward one tile */\r
158         mv->tx++;\r
159         /* Snap the origin forward */\r
160         mv->page->data += 4;\r
161         mv->page->dx =0;\r
162 \r
163 \r
164         /* draw the next column */\r
165         x= SCREEN_WIDTH;\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
170         }\r
171     }\r
172 }\r
173 \r
174 \r
175 void\r
176 mapScrollLeft(map_view_t *mv, byte offset) {
177         word x, y;  /* coordinate for drawing */\r
178     unsigned int i;\r
179 \r
180     /* increment the pixel position and update the page */\r
181     mv->page->dx -= offset;\r
182 \r
183     /* check to see if this changes the tile */\r
184     if(mv->page->dx >= 16) {\r
185         /* go forward one tile */\r
186         mv->tx++;\r
187         /* Snap the origin forward */\r
188         mv->page->data -= 4;\r
189         mv->page->dx =16;\r
190 \r
191 \r
192         /* draw the next column */\r
193         x= SCREEN_WIDTH;\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
198         }
199 }\r
200 }\r
201 \r
202 \r
203 void\r
204 mapScrollUp(map_view_t *mv, byte offset) {\r
205 }\r
206 \r
207 \r
208 void\r
209 mapScrollDown(map_view_t *mv, byte offset) {\r
210 }\r
211 \r
212 \r
213 void\r
214 mapGoTo(map_view_t *mv, byte tx, byte ty) {\r
215     int px, py;\r
216     unsigned int i;\r
217 \r
218     /* set up the coordinates */\r
219     mv->tx = tx;\r
220     mv->ty = ty;\r
221     mv->page->dx = 0;\r
222     mv->page->dy = 0;\r
223 \r
224     /* draw the tiles */\r
225     modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);\r
226     py=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
229         px=0;\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
232             i++;\r
233         }\r
234         i+=mv->map->width - tx;\r
235     }\r
236 }\r
237 \r
238 \r
239 void\r
240 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {\r
241     word rx;\r
242     word ry;\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
246 }\r