| 1 | /****************************************************************************\ |
| 2 | * |
| 3 | * Magnetic - Magnetic Scrolls Interpreter. |
| 4 | * |
| 5 | * Written by Niclas Karlsson <[email protected]>, |
| 6 | * David Kinder <[email protected]>, |
| 7 | * Stefan Meier <[email protected]> and |
| 8 | * Paul David Doherty <[email protected]> |
| 9 | * |
| 10 | * Copyright (C) 1997-2008 Niclas Karlsson |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. |
| 25 | * |
| 26 | \****************************************************************************/ |
| 27 | |
| 28 | #ifndef MAGNETIC_DEFS_H |
| 29 | #define MAGNETIC_DEFS_H |
| 30 | |
| 31 | /*****************************************************************************\ |
| 32 | * Type definitions for Magnetic |
| 33 | * |
| 34 | * Note: When running into trouble please ensure that these types have the |
| 35 | * correct number of bits on your system !!! |
| 36 | \*****************************************************************************/ |
| 37 | |
| 38 | #include <stdint.h> |
| 39 | |
| 40 | typedef uint8_t type8; |
| 41 | typedef int8_t type8s; |
| 42 | |
| 43 | typedef uint16_t type16; |
| 44 | typedef int16_t type16s; |
| 45 | |
| 46 | typedef uint32_t type32; |
| 47 | typedef int32_t type32s; |
| 48 | |
| 49 | /****************************************************************************\ |
| 50 | * Compile time switches |
| 51 | \****************************************************************************/ |
| 52 | |
| 53 | /* Switch: SAVEMEM |
| 54 | Purpose: Magnetic loads a complete graphics file into memory by default. |
| 55 | Setting this switch you tell Magnetic to load images on request |
| 56 | (saving memory, wasting load time) |
| 57 | |
| 58 | #define SAVEMEM |
| 59 | */ |
| 60 | |
| 61 | /* Switch: NO_ANIMATION |
| 62 | Purpose: By default Magnetic plays animated graphics. |
| 63 | Setting this switch to ignore animations, Magnetic shows the |
| 64 | static parts of the images anyway! |
| 65 | |
| 66 | #define NO_ANIMATION |
| 67 | */ |
| 68 | |
| 69 | /****************************************************************************\ |
| 70 | * Abstract functions |
| 71 | * |
| 72 | * Note: These functions MUST be implemented by each port of Magnetic! |
| 73 | \****************************************************************************/ |
| 74 | |
| 75 | /****************************************************************************\ |
| 76 | * Function: ms_load_file |
| 77 | * |
| 78 | * Purpose: Load a save game file and restore game |
| 79 | * |
| 80 | * Parameters: type8s* name zero terminated string of filename |
| 81 | * typed by player |
| 82 | * type8* ptr pointer to data to save |
| 83 | * type16 size number of bytes to save |
| 84 | * |
| 85 | * Result: 0 is successful |
| 86 | * |
| 87 | * Note: You probably want to put in a file requester! |
| 88 | \****************************************************************************/ |
| 89 | |
| 90 | type8 ms_load_file(type8s * name, type8 * ptr, type16 size); |
| 91 | |
| 92 | /****************************************************************************\ |
| 93 | * Function: ms_save_file |
| 94 | * |
| 95 | * Purpose: Save the current game to file |
| 96 | * |
| 97 | * Parameters: type8s* name zero terminated string of filename |
| 98 | * typed by player |
| 99 | * type8* ptr pointer to data to save |
| 100 | * type16 size number of bytes to save |
| 101 | * |
| 102 | * Result: 0 is successful |
| 103 | * |
| 104 | * Note: You probably want to put in a file requester! |
| 105 | \****************************************************************************/ |
| 106 | |
| 107 | type8 ms_save_file(type8s * name, type8 * ptr, type16 size); |
| 108 | |
| 109 | /****************************************************************************\ |
| 110 | * Function: ms_statuschar |
| 111 | * |
| 112 | * Purpose: Output a single character to the status bar |
| 113 | * |
| 114 | * Parameters: type8 c character to be printed |
| 115 | * |
| 116 | * Note: All characters are printed as provided except for: |
| 117 | * 0x0A resets the x position to zero |
| 118 | * 0x09 moves the cursor to the right half of the bar, ie 'width-11' |
| 119 | \****************************************************************************/ |
| 120 | |
| 121 | void ms_statuschar(type8 c); |
| 122 | |
| 123 | /****************************************************************************\ |
| 124 | * Function: ms_putchar |
| 125 | * |
| 126 | * Purpose: Output a single character to the game/text windows |
| 127 | * |
| 128 | * Parameters: type8 c character to be printed |
| 129 | * |
| 130 | * Note: It is highly recommended to buffer the output, see also ms_flush() |
| 131 | \****************************************************************************/ |
| 132 | |
| 133 | void ms_putchar(type8 c); |
| 134 | |
| 135 | /****************************************************************************\ |
| 136 | * Function: ms_flush |
| 137 | * |
| 138 | * Purpose: Flush the output buffer (if applicable) |
| 139 | * |
| 140 | * Note: see also ms_putchar |
| 141 | \****************************************************************************/ |
| 142 | |
| 143 | void ms_flush(void); |
| 144 | |
| 145 | /****************************************************************************\ |
| 146 | * Function: ms_getchar |
| 147 | * |
| 148 | * Purpose: Read user input, buffered |
| 149 | * |
| 150 | * Parameters: type8 trans if not 0, translate any #undo |
| 151 | * input to a return code of 0 |
| 152 | * |
| 153 | * Return: One character |
| 154 | * |
| 155 | * Note: The first time it is called a string should be read and then given |
| 156 | * back one byte at a time (ie. one for each call) until a '\n' is |
| 157 | * reached (which will be the last byte sent back before it all restarts) |
| 158 | * Returning a zero means 'undo' and the rest of the line must then be |
| 159 | * ignored. |
| 160 | * Returning 1 means that the opcode should return immediately. This is |
| 161 | * needed to prevent possible corruption of the game's memory in |
| 162 | * interpreters which allow a new game to be loaded without restarting. |
| 163 | \****************************************************************************/ |
| 164 | |
| 165 | type8 ms_getchar(type8 trans); |
| 166 | |
| 167 | /****************************************************************************\ |
| 168 | * Function: ms_showpic |
| 169 | * |
| 170 | * Purpose: Displays or hides a picture |
| 171 | * |
| 172 | * Parameter: type32 c number of image to be displayed |
| 173 | * type8 mode mode == 0 means gfx off, |
| 174 | * mode == 1 gfx on thumbnails, |
| 175 | * mode == 2 gfx on normal. |
| 176 | * |
| 177 | * Note: For retrieving the raw data of a picture call ms_extract (see below) |
| 178 | \****************************************************************************/ |
| 179 | |
| 180 | void ms_showpic(type32 c, type8 mode); |
| 181 | |
| 182 | /****************************************************************************\ |
| 183 | * Function: ms_fatal |
| 184 | * |
| 185 | * Purpose: Handle fatal interpreter error |
| 186 | * |
| 187 | * Parameter: type8s* txt message |
| 188 | \****************************************************************************/ |
| 189 | |
| 190 | void ms_fatal(type8s * txt); |
| 191 | |
| 192 | /****************************************************************************\ |
| 193 | * Magnetic core functions |
| 194 | * |
| 195 | * Note: These functions SHOULD be used somewhere in your port! |
| 196 | \****************************************************************************/ |
| 197 | |
| 198 | /****************************************************************************\ |
| 199 | * Function: ms_extract |
| 200 | * |
| 201 | * Purpose: Extract a picture and return a pointer to a raw bitmap |
| 202 | * |
| 203 | * Parameters: type32 c number of the picture |
| 204 | * type16* w width of picture |
| 205 | * type16* h height pf picture |
| 206 | * type16* pal array for the palette (16 colours) |
| 207 | * type8* is_anim 1 if animated picture, otherwise 0 |
| 208 | * OR null (!) |
| 209 | * |
| 210 | * Return: Pointer to bitmap data if successful, otherwise null (also if gfx |
| 211 | * are disabled!) |
| 212 | * |
| 213 | * Note: All pictures have 16 colours and the palette entries use 3-bit RGB |
| 214 | * encoded as 00000RRR0GGG0BBB, that is, bits 0-2 give the blue |
| 215 | * component, bits 4-6 the green and bits 8-10 the red. The bitmap is |
| 216 | * one byte per pixel, with each byte giving the pixel's index into the |
| 217 | * palette. The data is given starting from the upper left corner. The |
| 218 | * image buffer is reused when the next picture is requested, so take |
| 219 | * care! More information on animated pictures are below! |
| 220 | \****************************************************************************/ |
| 221 | |
| 222 | type8 *ms_extract(type32 c, type16 * w, type16 * h, type16 * pal, type8 * is_anim); |
| 223 | |
| 224 | /****************************************************************************\ |
| 225 | * Magnetic animated pictures support |
| 226 | * |
| 227 | * Note: Some of the pictures for Wonderland and the Collection Volume 1 games |
| 228 | * are animations. To detect these, pass a pointer to a type8 as the is_anim |
| 229 | * argument to ms_extract(). |
| 230 | * |
| 231 | * There are two types of animated images, however almost all images are type1. |
| 232 | * A type1 image consists of four main elements: |
| 233 | * 1) A static picture which is loaded straight at the beginning |
| 234 | * 2) A set of frames with a mask. These frames are just "small pictures", which |
| 235 | * are coded like the normal static pictures. The image mask determines |
| 236 | * how the frame is removed after it has been displayed. A mask is exactly |
| 237 | * 1/8 the size of the image and holds 1 bit per pixel, saying "remove pixel" |
| 238 | * or leave pixel set when frame gets removed. It might be a good idea to check |
| 239 | * your system documentation for masking operations as your system might be |
| 240 | * able to use this mask data directly. |
| 241 | * 3) Positioning tables. These hold animation sequences consisting of commands |
| 242 | * like "Draw frame 12 at (123,456)" |
| 243 | * 4) A playback script, which determines how to use the positioning tables. |
| 244 | * These scripts are handled inside Magnetic, so no need to worry about. |
| 245 | * However, details can be found in the ms_animate() function. |
| 246 | * |
| 247 | * A type2 image is like a type1 image, but it does not have a static |
| 248 | * picture, nor does it have frame masking. It just consists of frames. |
| 249 | * |
| 250 | * How to support animations? |
| 251 | * After getting is_anim == 1 you should call ms_animate() immediately, and at |
| 252 | * regular intervals until ms_animate() returns 0. An appropriate interval |
| 253 | * between calls is about 100 milliseconds. |
| 254 | * Each call to ms_animate() will fill in the arguments with the address |
| 255 | * and size of an array of ms_position structures (see below), each of |
| 256 | * which holds an an animation frame number and x and y co-ordinates. To |
| 257 | * display the animation, decode all the animation frames (discussed below) |
| 258 | * from a single call to ms_animate() and display each one over the main picture. |
| 259 | * If your port does not support animations, define NO_ANIMATION. |
| 260 | \****************************************************************************/ |
| 261 | |
| 262 | struct ms_position |
| 263 | { |
| 264 | type16s x, y; |
| 265 | type16s number; |
| 266 | }; |
| 267 | |
| 268 | /****************************************************************************\ |
| 269 | * Function: ms_animate |
| 270 | * |
| 271 | * Purpose: Generate the next frame of an animation |
| 272 | * |
| 273 | * Parameters: ms_position** positions array of ms_position structs |
| 274 | * type16* count size of array |
| 275 | * |
| 276 | * Return: 1 if animation continues, 0 if animation is finfished |
| 277 | * |
| 278 | * Note: The positions array holds size ms_positions structures. BEFORE calling |
| 279 | * ms_animate again, retrieve the frames for all the ms_positions |
| 280 | * structures with ms_get_anim_frame and display each one on the static |
| 281 | * main picture. |
| 282 | \****************************************************************************/ |
| 283 | |
| 284 | type8 ms_animate(struct ms_position ** positions, type16 * count); |
| 285 | |
| 286 | /****************************************************************************\ |
| 287 | * Function: ms_get_anim_frame |
| 288 | * |
| 289 | * Purpose: Extracts the bitmap data of a single animation frame |
| 290 | * |
| 291 | * Parameters: type16s number number of frame (see ms_position struct) |
| 292 | * type16* width width of frame |
| 293 | * type16* height height of frame |
| 294 | * type8** mask pointer to masking data, might be NULL |
| 295 | * |
| 296 | * Return: 1 if animation continues, 0 if animation is finfished |
| 297 | * |
| 298 | * Note: The format of the frame is identical to the main pictures' returned by |
| 299 | * ms_extract. The mask has one-bit-per-pixel, determing how to handle the |
| 300 | * removal of the frame. |
| 301 | \****************************************************************************/ |
| 302 | |
| 303 | type8 * ms_get_anim_frame(type16s number, type16 * width, type16 * height, type8 ** mask); |
| 304 | |
| 305 | /****************************************************************************\ |
| 306 | * Function: ms_anim_is_repeating |
| 307 | * |
| 308 | * Purpose: Detects whether an animation is repeating |
| 309 | * |
| 310 | * Return: True if repeating |
| 311 | \****************************************************************************/ |
| 312 | |
| 313 | type8 ms_anim_is_repeating(void); |
| 314 | |
| 315 | /****************************************************************************\ |
| 316 | * Magnetic Windows hint support |
| 317 | * |
| 318 | * The windowed Magnetic Scolls games included online hints. To add support |
| 319 | * for the hints to your magnetic port, you should implement the ms_showhints |
| 320 | * function. It retrieves a pointer to an array of ms_hint structs |
| 321 | * The root element is always hints[0]. The elcount determines the number |
| 322 | * of items in this topic. You probably want to display those in some kind |
| 323 | * of list interface. The content pointer points to the actual description of |
| 324 | * the items, separated by '\0' terminators. The nodetype is 1 if the items are |
| 325 | * "folders" and 2 if the items are hints. Hints should be displayed one after |
| 326 | * another. For "folder" items, the links array holds the index of the hint in |
| 327 | * the array which is to be displayed on selection. One hint block has exactly |
| 328 | * one type. The parent element determines the "back" target. |
| 329 | \****************************************************************************/ |
| 330 | #define MAX_HITEMS 25 |
| 331 | |
| 332 | struct ms_hint |
| 333 | { |
| 334 | type16 elcount; |
| 335 | type16 nodetype; |
| 336 | type8 * content; |
| 337 | type16 links[MAX_HITEMS]; |
| 338 | type16 parent; |
| 339 | }; |
| 340 | |
| 341 | /****************************************************************************\ |
| 342 | * Function: ms_showhints |
| 343 | * Purpose: Show the player a hint |
| 344 | * |
| 345 | * Parameters: ms_hint* hints pointer to array of ms_hint structs |
| 346 | * |
| 347 | * Return: 0 on error, 1 on success |
| 348 | \****************************************************************************/ |
| 349 | |
| 350 | type8 ms_showhints(struct ms_hint * hints); |
| 351 | |
| 352 | /****************************************************************************\ |
| 353 | * Magnetic Windows sound support |
| 354 | * |
| 355 | * Wonderland contains music scores that are played when entering specific |
| 356 | * locations in the game. The music data are actually MIDI events and can be |
| 357 | * played through normal MIDI devices. The original game plays the MIDI score |
| 358 | * until the end, even if the location is changed while playing. The playback |
| 359 | * tempo is not included with the MIDI data. The ms_sndextract function |
| 360 | * returns a recommended tempo, however depending on the MIDI implementation |
| 361 | * and operating system, you might need to adapt it. |
| 362 | \****************************************************************************/ |
| 363 | |
| 364 | /****************************************************************************\ |
| 365 | * Function: ms_playmusic |
| 366 | * |
| 367 | * Purpose: Plays (or stops playing) a MIDI music score. |
| 368 | * |
| 369 | * Parameter: type8 * midi_data the MIDI data to play |
| 370 | * type32 length the length of the MIDI data |
| 371 | * type16 tempo the suggested tempo for playing |
| 372 | * |
| 373 | * Note: If midi_data is NULL, all that should happen is that any currently |
| 374 | * playing music is stopped. |
| 375 | * Note: The data returned contain a complete MIDI file header, so if pure |
| 376 | * memory processing is not applicable you can write the data to a |
| 377 | * temporary file and use external players or libraries. |
| 378 | \****************************************************************************/ |
| 379 | |
| 380 | void ms_playmusic(type8 * midi_data, type32 length, type16 tempo); |
| 381 | |
| 382 | /****************************************************************************\ |
| 383 | * Function: ms_init |
| 384 | * |
| 385 | * Purpose: Loads the interpreter with a game |
| 386 | * |
| 387 | * Parameters: type8s* name filename of story file |
| 388 | * type8s* gfxname filename of graphics file (optional) |
| 389 | * type8s* hntname filename of hints file (optional) |
| 390 | * type8s* sndname filename of music file (optional) |
| 391 | * |
| 392 | * Return: 0 = failure |
| 393 | * 1 = success (without graphics or graphics failed) |
| 394 | * 2 = success (with graphics) |
| 395 | * |
| 396 | * Note: You must call this function before starting the ms_rungame loop |
| 397 | \****************************************************************************/ |
| 398 | |
| 399 | type8 ms_init(type8s * name, type8s * gfxname, type8s * hntname, type8s * sndname); |
| 400 | |
| 401 | /****************************************************************************\ |
| 402 | * Function: ms_rungame |
| 403 | * |
| 404 | * Purpose: Executes an interpreter instruction |
| 405 | * |
| 406 | * Return: True if successful |
| 407 | * |
| 408 | * Note: You must call this function in a loop like this: |
| 409 | * while (running) {running=ms_rungame();} |
| 410 | \****************************************************************************/ |
| 411 | |
| 412 | type8 ms_rungame(void); |
| 413 | |
| 414 | /****************************************************************************\ |
| 415 | * Function: ms_freemen |
| 416 | * |
| 417 | * Purpose: Frees all allocated ressources |
| 418 | \****************************************************************************/ |
| 419 | |
| 420 | void ms_freemem(void); |
| 421 | |
| 422 | /****************************************************************************\ |
| 423 | * Function: ms_seed |
| 424 | * |
| 425 | * Purpose: Initializes the interpreter's random number generator with |
| 426 | * the given seed |
| 427 | * |
| 428 | * Parameter: type32 seed seed |
| 429 | \****************************************************************************/ |
| 430 | |
| 431 | void ms_seed(type32 seed); |
| 432 | |
| 433 | /****************************************************************************\ |
| 434 | * Function: ms_is_running |
| 435 | * |
| 436 | * Purpose: Detects if game is running |
| 437 | * |
| 438 | * Return: True, if game is currently running |
| 439 | \****************************************************************************/ |
| 440 | |
| 441 | type8 ms_is_running(void); |
| 442 | |
| 443 | /****************************************************************************\ |
| 444 | * Function: ms_is_magwin |
| 445 | * |
| 446 | * Purpose: Detects Magnetic Windows games (Wonderland, Collection) |
| 447 | * |
| 448 | * Return: True, if Magnetic Windows game |
| 449 | \****************************************************************************/ |
| 450 | |
| 451 | type8 ms_is_magwin(void); |
| 452 | |
| 453 | /****************************************************************************\ |
| 454 | * Function: ms_stop |
| 455 | * |
| 456 | * Purpose: Stops further processing of opcodes |
| 457 | \****************************************************************************/ |
| 458 | |
| 459 | void ms_stop(void); |
| 460 | |
| 461 | /****************************************************************************\ |
| 462 | * Function: ms_status |
| 463 | * |
| 464 | * Purpose: Dumps interperetr state to stderr, ie. registers |
| 465 | \****************************************************************************/ |
| 466 | |
| 467 | void ms_status(void); |
| 468 | |
| 469 | /****************************************************************************\ |
| 470 | * Function: ms_count |
| 471 | * |
| 472 | * Purpose: Returns the number of executed intructions |
| 473 | * |
| 474 | * Return: Instruction count |
| 475 | \****************************************************************************/ |
| 476 | |
| 477 | type32 ms_count(void); |
| 478 | |
| 479 | #endif /* MAGNETIC_DEFS_H */ |
| 480 |