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