1 /*
2  * xrick/src/scr_imap.c
3  *
4  * Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net). All rights reserved.
5  *
6  * The use and distribution terms for this software are contained in the file
7  * named README, which can be found in the root of this distribution. By
8  * using this software in any fashion, you are agreeing to be bound by the
9  * terms of this license.
10  *
11  * You must not remove this notice, or any other, from this software.
12  */
13 
14 #include <stdio.h>
15 
16 #include "system.h"
17 #include "game.h"
18 #include "screens.h"
19 
20 #include "rects.h"
21 #include "draw.h"
22 #include "control.h"
23 #include "maps.h"
24 
25 /*
26  * local vars
27  */
28 static U16 step;              /* current step */
29 static U16 count;             /* number of loops for current step */
30 static U16 run;               /* 1 = run, 0 = no more step */
31 static U8 flipflop;           /* flipflop for top, bottom, left, right */
32 static U16 spnum;             /* sprite number */
33 static U16 spx, spdx;         /* sprite x position and delta */
34 static U16 spy, spdy;         /* sprite y position and delta */
35 static U16 spbase, spoffs;    /* base, offset for sprite numbers table */
36 static U8 seq = 0;            /* anim sequence */
37 
38 static rect_t anim_rect = { 120, 16, 64, 64, NULL }; /* anim rectangle */
39 
40 /*
41  * prototypes
42  */
43 static void drawtb(void);
44 static void drawlr(void);
45 static void drawsprite(void);
46 static void drawcenter(void);
47 static void nextstep(void);
48 static void anim(void);
49 static void init(void);
50 
51 /*
52  * Map introduction
53  *
54  * ASM: 1948
55  *
56  * return: SCREEN_RUNNING, SCREEN_DONE, SCREEN_EXIT
57  */
58 U8
screen_introMap(void)59 screen_introMap(void)
60 {
61   switch (seq) {
62   case 0:
63     sysvid_clear();
64 
65 #ifdef GFXPC
66     draw_tilesBank = 1;
67     draw_filter = 0xAAAA;
68 #endif
69 #ifdef GFXST
70     draw_tilesBank = 0;
71 #endif
72     draw_tllst = screen_imaptext[game_map];
73     draw_setfb(32, 0);
74     draw_tilesSubList();
75 
76     draw_setfb(32, 96);
77 #ifdef GFXPC
78     draw_filter = 0x5555;
79 #endif
80     draw_tilesList();
81 
82     game_rects = NULL;
83 
84 #ifdef GFXPC
85     draw_filter = 0xFFFF;
86 #endif
87 
88     init();
89     nextstep();
90     drawcenter();
91     drawtb();
92     drawlr();
93     drawsprite();
94     control_last = 0;
95 
96     game_rects = &draw_SCREENRECT;
97 
98 #ifdef ENABLE_SOUND
99 	game_setmusic(map_maps[game_map].tune, 1);
100 #endif
101 
102 	seq = 1;
103     break;
104   case 1:  /* top and bottom borders */
105     drawtb();
106     game_rects = &anim_rect;
107     seq = 2;
108     break;
109   case 2:  /* background and sprite */
110     anim();
111     drawcenter();
112     drawsprite();
113     game_rects = &anim_rect;
114     seq = 3;
115     break;
116   case 3:  /* all borders */
117     drawtb();
118     drawlr();
119     game_rects = &anim_rect;
120     seq = 1;
121     break;
122   case 4:  /* wait for key release */
123     if (!(control_status & CONTROL_FIRE))
124       seq = 5;
125     break;
126   }
127 
128   if (control_status & CONTROL_FIRE) {  /* end as soon as key pressed */
129     seq = 4;
130   }
131 
132   if (control_status & CONTROL_EXIT)  /* check for exit request */
133     return SCREEN_EXIT;
134 
135   if (seq == 5) {  /* end as soon as key pressed */
136     sysvid_clear();
137     seq = 0;
138 	return SCREEN_DONE;
139   }
140   else
141     return SCREEN_RUNNING;
142 }
143 
144 
145 /*
146  * Display top and bottom borders (0x1B1F)
147  *
148  */
149 static void
drawtb(void)150 drawtb(void)
151 {
152   U8 i;
153 
154   flipflop++;
155   if (flipflop & 0x01) {
156     draw_setfb(128, 16);
157     for (i = 0; i < 6; i++)
158       draw_tile(0x40);
159     draw_setfb(128, 72);
160     for (i = 0; i < 6; i++)
161       draw_tile(0x06);
162   }
163   else {
164     draw_setfb(128, 16);
165     for (i = 0; i < 6; i++)
166       draw_tile(0x05);
167     draw_setfb(128, 72);
168     for (i = 0; i < 6; i++)
169       draw_tile(0x40);
170   }
171 }
172 
173 
174 /*
175  * Display left and right borders (0x1B7C)
176  *
177  */
178 static void
drawlr(void)179 drawlr(void)
180 {
181   U8 i;
182 
183   if (flipflop & 0x02) {
184     for (i = 0; i < 8; i++) {
185       draw_setfb(120, 16 + i * 8);
186       draw_tile(0x04);
187       draw_setfb(176, 16 + i * 8);
188       draw_tile(0x04);
189     }
190   }
191   else {
192     for (i = 0; i < 8; i++) {
193       draw_setfb(120, 16 + i * 8);
194       draw_tile(0x2B);
195       draw_setfb(176, 16 + i * 8);
196       draw_tile(0x2B);
197     }
198   }
199 }
200 
201 
202 /*
203  * Draw the sprite (0x19C6)
204  *
205  */
206 static void
drawsprite(void)207 drawsprite(void)
208 {
209   draw_sprite(spnum, 128 + ((spx << 1) & 0x1C), 24 + (spy << 1));
210 }
211 
212 
213 /*
214  * Draw the background (0x1AF1)
215  *
216  */
217 static void
drawcenter(void)218 drawcenter(void)
219 {
220   static U8 tn0[] = { 0x07, 0x5B, 0x7F, 0xA3, 0xC7 };
221   U8 i, j, tn;
222 
223   tn = tn0[game_map];
224   for (i = 0; i < 6; i++) {
225     draw_setfb(128, (24 + 8 * i));
226     for (j = 0; j < 6; j++)
227       draw_tile(tn++);
228   }
229 }
230 
231 
232 /*
233  * Next Step (0x1A74)
234  *
235  */
236 static void
nextstep(void)237 nextstep(void)
238 {
239   if (screen_imapsteps[step].count) {
240     count = screen_imapsteps[step].count;
241     spdx = screen_imapsteps[step].dx;
242     spdy = screen_imapsteps[step].dy;
243     spbase = screen_imapsteps[step].base;
244     spoffs = 0;
245     step++;
246   }
247   else {
248     run = 0;
249   }
250 }
251 
252 
253 /*
254  * Anim (0x1AA8)
255  *
256  */
257 static void
anim(void)258 anim(void)
259 {
260   U16 i;
261 
262   if (run) {
263     i = screen_imapsl[spbase + spoffs];
264     if (i == 0) {
265       spoffs = 0;
266       i = screen_imapsl[spbase];
267     }
268     spnum = i;
269     spoffs++;
270     spx += spdx;
271     spy += spdy;
272     count--;
273     if (count == 0)
274       nextstep();
275   }
276 }
277 
278 
279 /*
280  * Initialize (0x1A43)
281  *
282  */
283 static void
init(void)284 init(void)
285 {
286   run = 0; run--;
287   step = screen_imapsofs[game_map];
288   spx = screen_imapsteps[step].dx;
289   spy = screen_imapsteps[step].dy;
290   step++;
291   spnum = 0; /* NOTE spnum in [8728] is never initialized ? */
292 }
293 
294 /* eof */
295 
296 
297 
298