]> 4ch.mooo.com Git - 16.git/blob - src/lib/scroll.c
new file: 16.c
[16.git] / src / lib / scroll.c
1 #include "src\scroll.h"
2 #include "src\lib\modex16.h"
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include "src\lib\dos_kb.h"
6 #include "src\lib\wtest\wtest.c"
7
8 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
9
10 map_t
11 allocMap(int w, int h) {
12         map_t result;
13
14         result.width =w;
15         result.height=h;
16         result.data = malloc(sizeof(byte) * w * h);
17
18         return result;
19 }
20
21
22 void
23 initMap(map_t *map) {
24         /* just a place holder to fill out an alternating pattern */
25         int x, y;
26         int i;
27         int tile = 1;
28         map->tiles = malloc(sizeof(tiles_t));
29
30         /* create the tile set */
31         map->tiles->data = malloc(sizeof(bitmap_t));
32         map->tiles->data->width = (TILEWH*2);
33         map->tiles->data->height= TILEWH;
34         map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
35         map->tiles->tileHeight = TILEWH;
36         map->tiles->tileWidth =TILEWH;
37         map->tiles->rows = 1;
38         map->tiles->cols = 2;
39
40         i=0;
41         for(y=0; y<TILEWH; y++) {
42         for(x=0; x<(TILEWH*2); x++) {
43                 if(x<TILEWH)
44                   map->tiles->data->data[i] = 28;//0x24;
45                 else
46                   map->tiles->data->data[i] = 0;//0x34;
47                 i++;
48         }
49         }
50
51         i=0;
52         for(y=0; y<map->height; y++) {
53                 for(x=0; x<map->width; x++) {
54                         map->data[i] = tile;
55                         tile = tile ? 0 : 1;
56                         i++;
57                 }
58                 tile = tile ? 0 : 1;
59         }
60 }
61
62
63 void
64 mapScrollRight(map_view_t *mv, byte offset, short lp) {
65         word x, y;  /* coordinate for drawing */
66
67         /* increment the pixel position and update the page */
68         mv->page->dx += offset;
69
70         /* check to see if this changes the tile */
71         if(mv->page->dx >= mv->dxThresh ) {
72         /* go forward one tile */
73         mv->tx++;
74         /* Snap the origin forward */
75         mv->page->data += 4;
76         mv->page->dx = mv->map->tiles->tileWidth;
77         //}
78
79         /* draw the next column */
80         x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
81         //if(lp%4)
82                 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x, mv->page->dx);
83         }
84 }
85
86
87 void
88 mapScrollLeft(map_view_t *mv, byte offset, short lp) {
89         word x, y;  /* coordinate for drawing */
90
91         /* increment the pixel position and update the page */
92         mv->page->dx -= offset;
93
94         /* check to see if this changes the tile */
95         if(mv->page->dx == 0) {
96         /* go backward one tile */
97         mv->tx--;
98                 
99         /* Snap the origin backward */
100         mv->page->data -= 4;
101         mv->page->dx = mv->map->tiles->tileWidth;
102         //}
103         /* draw the next column */
104         //if(lp%4)
105                 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0, mv->page->dx);
106         }
107 }
108
109
110 void
111 mapScrollUp(map_view_t *mv, byte offset, short lp) {
112         word x, y;  /* coordinate for drawing */
113
114         /* increment the pixel position and update the page */
115         mv->page->dy -= offset;
116
117         /* check to see if this changes the tile */
118         if(mv->page->dy == 0 ) {
119         /* go down one tile */
120         mv->ty--;
121         /* Snap the origin downward */
122         mv->page->data -= mv->page->width*4;
123         mv->page->dy = mv->map->tiles->tileHeight;
124         //}
125
126         /* draw the next row */
127         y= 0;
128         //if(lp%3)
129                 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y, mv->page->dy);
130         }
131 }
132
133
134 void
135 mapScrollDown(map_view_t *mv, byte offset, short lp) {
136         word x, y;  /* coordinate for drawing */
137
138         /* increment the pixel position and update the page */
139         mv->page->dy += offset;
140
141         /* check to see if this changes the tile */
142         if(mv->page->dy >= mv->dyThresh ) {
143         /* go down one tile */
144         mv->ty++;
145         /* Snap the origin downward */
146         mv->page->data += mv->page->width*4;
147         mv->page->dy = mv->map->tiles->tileHeight;
148         //}
149
150         /* draw the next row */
151         y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
152         //if(lp%3)
153                 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y, mv->page->dy);
154         }
155
156 }
157
158
159 void
160 mapGoTo(map_view_t *mv, int tx, int ty) {
161         int px, py;
162         unsigned int i;
163
164         /* set up the coordinates */
165         mv->tx = tx;
166         mv->ty = ty;
167         mv->page->dx = mv->map->tiles->tileWidth;
168         mv->page->dy = mv->map->tiles->tileHeight;
169
170         /* set up the thresholds */
171         mv->dxThresh = mv->map->tiles->tileWidth * 2;
172         mv->dyThresh = mv->map->tiles->tileHeight * 2;
173
174         /* draw the tiles */
175         modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
176         py=0;
177         i=mv->ty * mv->map->width + mv->tx;
178         for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
179                 mapDrawWRow(mv, tx-1, ty, py);
180         i+=mv->map->width - tx;
181         }
182 }
183
184
185 void
186 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
187         word rx;
188         word ry;
189         rx = (i % t->cols) * t->tileWidth;
190         ry = (i / t->cols) * t->tileHeight;
191         modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
192 }
193
194
195 void 
196 mapDrawRow(map_view_t *mv, int tx, int ty, word y, word poopoffset) {
197         word x;
198         int i;
199         poopoffset%=SPEED;
200 //printf("y: %d\n", poopoffset);
201         /* the position within the map array */
202         i=ty * mv->map->width + tx;
203         for(x=poopoffset; x<(SCREEN_WIDTH+mv->dxThresh)/(poopoffset+1) && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
204         if(i>=0) {
205                 /* we are in the map, so copy! */
206                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
207         }
208         i++; /* next! */
209         }
210 }
211
212
213 void 
214 mapDrawCol(map_view_t *mv, int tx, int ty, word x, word poopoffset) {
215         int y;
216         int i;
217         poopoffset%=SPEED;
218 //printf("x: %d\n", poopoffset);
219         /* location in the map array */
220         i=ty * mv->map->width + tx;
221
222         /* We'll copy all of the columns in the screen, 
223            i + 1 row above and one below */
224         for(y=poopoffset; y<(SCREEN_HEIGHT+mv->dyThresh)/(poopoffset+1) && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
225         if(i>=0) {
226                 /* we are in the map, so copy away! */
227                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
228         }
229         i += mv->map->width;
230         }
231 }
232
233 void 
234 mapDrawWRow(map_view_t *mv, int tx, int ty, word y) {
235         word x;
236         int i;
237
238         /* the position within the map array */
239         i=ty * mv->map->width + tx;
240         for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
241         if(i>=0) {
242                 /* we are in the map, so copy! */
243                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
244         }
245         i++; /* next! */
246         }
247 }
248
249 void 
250 mapDrawWCol(map_view_t *mv, int tx, int ty, word x) {
251         int y;
252         int i;
253
254         /* location in the map array */
255         i=ty * mv->map->width + tx;
256
257         /* We'll copy all of the columns in the screen, 
258            i + 1 row above and one below */
259         for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
260         if(i>=0) {
261                 /* we are in the map, so copy away! */
262                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
263         }
264         i += mv->map->width;
265         }
266 }
267
268 void
269 animatePlayer(map_view_t *src, map_view_t *dest, /*map_view_t *top, */short d1, short d2, int x, int y, int ls, int lp, bitmap_t *bmp)
270 {
271         short dire=32*d1; //direction
272         short qq; //scroll offset
273
274         if(d2==0) qq = 0;
275         else qq = ((lp)*SPEED);
276         switch (d1)
277         {
278                 case 0:
279                         //up
280                         x=x-4;
281                         y=y-qq-TILEWH;
282                 break;
283                 case 1:
284                         // right
285                         x=x+qq-4;
286                         y=y-TILEWH;
287                 break;
288                 case 2:
289                         //down
290                         x=x-4;
291                         y=y+qq-TILEWH;
292                 break;
293                 case 3:
294                         //left
295                         x=x-qq-4;
296                         y=y-TILEWH;
297                 break;
298         }
299         modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
300         if(2>ls && ls>=1) { modexDrawSpriteRegion(dest->page, x, y, 48, dire, 24, 32, bmp); }else
301         if(3>ls && ls>=2) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }else
302         if(4>ls && ls>=3) { modexDrawSpriteRegion(dest->page, x, y, 0, dire, 24, 32, bmp); }else
303         if(5>ls && ls>=4) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }
304         //TODO: mask copy //modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
305         //modexClearRegion(top->page, 66, 66, 2, 40, 0);
306         //modexCopyPageRegion(dest->page, top->page, 66, 66, 66, 66, 2, 40);
307         //turn this off if XT
308         if(detectcpu() > 0) modexWaitBorder();
309 }