1 /* ______ ___ ___
2 * /\ _ \ /\_ \ /\_ \
3 * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
4 * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
5 * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
6 * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
7 * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
8 * /\____/
9 * \_/__/
10 * By Shawn Hargreaves,
11 * 1 Salisbury Road,
12 * Market Drayton,
13 * Shropshire,
14 * England, TF9 1AJ.
15 *
16 * Main header file for the Allegro library.
17 * This should be included by everyone and everything.
18 *
19 * See readme.txt for copyright information.
20 */
21
22
23 #ifndef ALLEGRO_H
24 #define ALLEGRO_H
25
26 #ifdef LINUX
27 #error Linux version not finished. Want to help?
28 #endif
29
30 #ifndef DJGPP
31 #error Allegro can only be used with djgpp
32 #endif
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 #define ALLEGRO_VERSION 3
39 #define ALLEGRO_SUB_VERSION 0
40 #define ALLEGRO_VERSION_STR "3.0"
41 #define ALLEGRO_DATE_STR "1997"
42
43 /* remove these if you only want 256 color graphics support */
44 #define ALLEGRO_COLOR16
45 #define ALLEGRO_COLOR24
46 #define ALLEGRO_COLOR32
47
48
49
50 /*******************************************/
51 /************ Some global stuff ************/
52 /*******************************************/
53
54 #include <stdlib.h>
55 #include <stddef.h>
56 #include <errno.h>
57
58 #ifdef DJGPP
59 #include <dpmi.h>
60 #include <pc.h>
61 #endif
62
63 #ifndef TRUE
64 #define TRUE -1
65 #define FALSE 0
66 #endif
67
68 #ifndef MIN
69 #define MIN(x,y) (((x) < (y)) ? (x) : (y))
70 #define MAX(x,y) (((x) > (y)) ? (x) : (y))
71 #define MID(x,y,z) MAX((x), MIN((y), (z)))
72 #endif
73
74 #ifndef ABS
75 #define ABS(x) (((x) >= 0) ? (x) : (-(x)))
76 #endif
77
78 #ifndef SGN
79 #define SGN(x) (((x) >= 0) ? 1 : -1)
80 #endif
81
82 #ifndef __INLINE__
83 #define __INLINE__ extern inline
84 #endif
85
86 typedef long fixed;
87
88 struct RGB;
89 struct BITMAP;
90 struct RLE_SPRITE;
91 struct SAMPLE;
92 struct MIDI;
93
94 extern char allegro_id[];
95 extern char allegro_error[];
96
97 #define OSTYPE_UNKNOWN 0
98 #define OSTYPE_WIN3 1
99 #define OSTYPE_WIN95 2
100 #define OSTYPE_WINNT 3
101 #define OSTYPE_OS2 4
102 #define OSTYPE_WARP 5
103 #define OSTYPE_DOSEMU 6
104 #define OSTYPE_OPENDOS 7
105
106 extern int os_type;
107
108 extern int windows_version, windows_sub_version;
109
110 int allegro_init();
111 void allegro_exit();
112
113 void check_cpu();
114
115 extern char cpu_vendor[];
116 extern int cpu_family;
117 extern int cpu_model;
118 extern int cpu_fpu;
119 extern int cpu_mmx;
120 extern int cpu_cpuid;
121
122 void lock_bitmap(struct BITMAP *bmp);
123 void lock_sample(struct SAMPLE *spl);
124 void lock_midi(struct MIDI *midi);
125
126 #ifdef DJGPP
127
128 /* for djgpp */
129 #define END_OF_FUNCTION(x) void x##_end() { }
130 #define LOCK_VARIABLE(x) _go32_dpmi_lock_data((void *)&x, sizeof(x))
131 #define LOCK_FUNCTION(x) _go32_dpmi_lock_code(x, (long)x##_end - (long)x)
132
133 #else
134
135 /* for linux */
136 #define END_OF_FUNCTION(x)
137 #define LOCK_VARIABLE(x)
138 #define LOCK_FUNCTION(x)
139
140 #endif
141
142
143
144 /************************************************/
145 /************ Configuration routines ************/
146 /************************************************/
147
148 void set_config_file(char *filename);
149 void set_config_data(char *data, int length);
150 void override_config_file(char *filename);
151 void override_config_data(char *data, int length);
152
153 void push_config_state();
154 void pop_config_state();
155
156 char *get_config_string(char *section, char *name, char *def);
157 int get_config_int(char *section, char *name, int def);
158 int get_config_hex(char *section, char *name, int def);
159 float get_config_float(char *section, char *name, float def);
160 char **get_config_argv(char *section, char *name, int *argc);
161
162 void set_config_string(char *section, char *name, char *val);
163 void set_config_int(char *section, char *name, int val);
164 void set_config_hex(char *section, char *name, int val);
165 void set_config_float(char *section, char *name, float val);
166
167
168
169 /****************************************/
170 /************ Mouse routines ************/
171 /****************************************/
172
173 #if !defined alleg_mouse_unused
174
175 int install_mouse();
176 void remove_mouse();
177
178 extern volatile int mouse_x;
179 extern volatile int mouse_y;
180 extern volatile int mouse_b;
181 extern volatile int mouse_pos;
182
183 extern int freeze_mouse_flag;
184
185 #define MOUSE_FLAG_MOVE 1
186 #define MOUSE_FLAG_LEFT_DOWN 2
187 #define MOUSE_FLAG_LEFT_UP 4
188 #define MOUSE_FLAG_RIGHT_DOWN 8
189 #define MOUSE_FLAG_RIGHT_UP 16
190 #define MOUSE_FLAG_MIDDLE_DOWN 32
191 #define MOUSE_FLAG_MIDDLE_UP 64
192
193 extern void (*mouse_callback)(int flags);
194
195 void show_mouse(struct BITMAP *bmp);
196 void position_mouse(int x, int y);
197 void set_mouse_range(int x1, int y1, int x2, int y2);
198 void set_mouse_speed(int xspeed, int yspeed);
199 void set_mouse_sprite(struct BITMAP *sprite);
200 void set_mouse_sprite_focus(int x, int y);
201 void get_mouse_mickeys(int *mickeyx, int *mickeyy);
202
203 #endif
204
205
206
207 /****************************************/
208 /************ Timer routines ************/
209 /****************************************/
210
211 #if !defined alleg_timer_unused
212
213 #define TIMERS_PER_SECOND 1193181L
214 #define SECS_TO_TIMER(x) ((long)(x) * TIMERS_PER_SECOND)
215 #define MSEC_TO_TIMER(x) ((long)(x) * (TIMERS_PER_SECOND / 1000))
216 #define BPS_TO_TIMER(x) (TIMERS_PER_SECOND / (long)(x))
217 #define BPM_TO_TIMER(x) ((60 * TIMERS_PER_SECOND) / (long)(x))
218
219 int install_timer();
220 void remove_timer();
221
222 int install_int_ex(void (*proc)(), long speed);
223 int install_int(void (*proc)(), long speed);
224 void remove_int(void (*proc)());
225
226 extern int i_love_bill;
227
228 extern volatile int retrace_count;
229 extern void (*retrace_proc)();
230
231 void timer_simulate_retrace(int enable);
232
233 void rest(long time);
234 void rest_callback(long time, void (*callback)());
235
236 #endif
237
238
239
240 /*******************************************/
241 /************ Keyboard routines ************/
242 /*******************************************/
243
244 #if !defined alleg_keyboard_unused
245
246 int install_keyboard();
247 void remove_keyboard();
248
249 extern int (*keyboard_callback)(int key);
250
251 void install_keyboard_hooks(int (*keypressed)(), int (*readkey)());
252
253 extern volatile char key[128];
254 extern volatile int key_shifts;
255
256 extern int three_finger_flag;
257 extern int key_led_flag;
258
259 int keypressed();
260 int readkey();
261 void simulate_keypress(int key);
262 void clear_keybuf();
263 void set_leds(int leds);
264
265 extern unsigned char key_ascii_table[128];
266 extern unsigned char key_capslock_table[128];
267 extern unsigned char key_shift_table[128];
268 extern unsigned char key_control_table[128];
269 extern unsigned char key_altgr_table[128];
270 extern unsigned char key_accent1_lower_table[128];
271 extern unsigned char key_accent1_upper_table[128];
272 extern unsigned char key_accent1_shift_lower_table[128];
273 extern unsigned char key_accent1_shift_upper_table[128];
274 extern unsigned char key_accent2_lower_table[128];
275 extern unsigned char key_accent2_upper_table[128];
276 extern unsigned char key_accent2_shift_lower_table[128];
277 extern unsigned char key_accent2_shift_upper_table[128];
278 extern unsigned char key_numlock_table[128];
279 extern unsigned char key_extended_table[128];
280 extern unsigned short key_special_table[128];
281
282 #define SCANCODE_TO_KEY(c) (((c)<<8) + (int)key_ascii_table[c])
283 #define SCANCODE_TO_CAPS(c) (((c)<<8) + (int)key_capslock_table[c])
284 #define SCANCODE_TO_SHIFT(c) (((c)<<8) + (int)key_shift_table[c])
285 #define SCANCODE_TO_CONTROL(c) (((c)<<8) + (int)key_control_table[c])
286 #define SCANCODE_TO_ALTGR(c) (((c)<<8) + (int)key_altgr_table[c])
287 #define SCANCODE_TO_ALT(c) ((c)<<8)
288
289 #define KB_SHIFT_FLAG 0x0001
290 #define KB_CTRL_FLAG 0x0002
291 #define KB_ALT_FLAG 0x0004
292 #define KB_LWIN_FLAG 0x0008
293 #define KB_RWIN_FLAG 0x0010
294 #define KB_MENU_FLAG 0x0020
295 #define KB_SCROLOCK_FLAG 0x0100
296 #define KB_NUMLOCK_FLAG 0x0200
297 #define KB_CAPSLOCK_FLAG 0x0400
298 #define KB_INALTSEQ_FLAG 0x0800
299 #define KB_ACCENT1_FLAG 0x1000
300 #define KB_ACCENT1_S_FLAG 0x2000
301 #define KB_ACCENT2_FLAG 0x4000
302 #define KB_ACCENT2_S_FLAG 0x8000
303
304 #define KB_NORMAL 1
305 #define KB_EXTENDED 2
306
307 #define KEY_ESC 1 /* keyboard scan codes */
308 #define KEY_1 2
309 #define KEY_2 3
310 #define KEY_3 4
311 #define KEY_4 5
312 #define KEY_5 6
313 #define KEY_6 7
314 #define KEY_7 8
315 #define KEY_8 9
316 #define KEY_9 10
317 #define KEY_0 11
318 #define KEY_MINUS 12
319 #define KEY_EQUALS 13
320 #define KEY_BACKSPACE 14
321 #define KEY_TAB 15
322 #define KEY_Q 16
323 #define KEY_W 17
324 #define KEY_E 18
325 #define KEY_R 19
326 #define KEY_T 20
327 #define KEY_Y 21
328 #define KEY_U 22
329 #define KEY_I 23
330 #define KEY_O 24
331 #define KEY_P 25
332 #define KEY_OPENBRACE 26
333 #define KEY_CLOSEBRACE 27
334 #define KEY_ENTER 28
335 #define KEY_CONTROL 29
336 #define KEY_LCONTROL 29
337 #define KEY_A 30
338 #define KEY_S 31
339 #define KEY_D 32
340 #define KEY_F 33
341 #define KEY_G 34
342 #define KEY_H 35
343 #define KEY_J 36
344 #define KEY_K 37
345 #define KEY_L 38
346 #define KEY_COLON 39
347 #define KEY_QUOTE 40
348 #define KEY_TILDE 41
349 #define KEY_LSHIFT 42
350 #define KEY_BACKSLASH 43
351 #define KEY_Z 44
352 #define KEY_X 45
353 #define KEY_C 46
354 #define KEY_V 47
355 #define KEY_B 48
356 #define KEY_N 49
357 #define KEY_M 50
358 #define KEY_COMMA 51
359 #define KEY_STOP 52
360 #define KEY_SLASH 53
361 #define KEY_RSHIFT 54
362 #define KEY_ASTERISK 55
363 #define KEY_ALT 56
364 #define KEY_SPACE 57
365 #define KEY_CAPSLOCK 58
366 #define KEY_F1 59
367 #define KEY_F2 60
368 #define KEY_F3 61
369 #define KEY_F4 62
370 #define KEY_F5 63
371 #define KEY_F6 64
372 #define KEY_F7 65
373 #define KEY_F8 66
374 #define KEY_F9 67
375 #define KEY_F10 68
376 #define KEY_NUMLOCK 69
377 #define KEY_SCRLOCK 70
378 #define KEY_HOME 71
379 #define KEY_UP 72
380 #define KEY_PGUP 73
381 #define KEY_MINUS_PAD 74
382 #define KEY_LEFT 75
383 #define KEY_5_PAD 76
384 #define KEY_RIGHT 77
385 #define KEY_PLUS_PAD 78
386 #define KEY_END 79
387 #define KEY_DOWN 80
388 #define KEY_PGDN 81
389 #define KEY_INSERT 82
390 #define KEY_DEL 83
391 #define KEY_PRTSCR 84
392 #define KEY_F11 87
393 #define KEY_F12 88
394 #define KEY_LWIN 91
395 #define KEY_RWIN 92
396 #define KEY_MENU 93
397 #define KEY_PAD 100
398 #define KEY_RCONTROL 120
399 #define KEY_ALTGR 121
400 #define KEY_SLASH2 122
401 #define KEY_PAUSE 123
402
403 #endif
404
405
406
407 /*******************************************/
408 /************ Joystick routines ************/
409 /*******************************************/
410
411 #if !defined alleg_joystick_unused
412
413 extern int joy_type;
414
415 /* values for joy_type */
416 #define JOY_TYPE_STANDARD 0
417 #define JOY_TYPE_FSPRO 1
418 #define JOY_TYPE_4BUTTON 2
419 #define JOY_TYPE_6BUTTON 3
420 #define JOY_TYPE_2PADS 4
421 #define JOY_TYPE_WINGEX 5
422
423 /* values for joy_hat */
424 #define JOY_HAT_CENTRE 0
425 #define JOY_HAT_LEFT 1
426 #define JOY_HAT_DOWN 2
427 #define JOY_HAT_RIGHT 3
428 #define JOY_HAT_UP 4
429
430 /* aliases for FSPro buttons */
431 #define joy_FSPRO_trigger joy_b1
432 #define joy_FSPRO_butleft joy_b2
433 #define joy_FSPRO_butright joy_b3
434 #define joy_FSPRO_butmiddle joy_b4
435
436 /* aliases for Wingman Extreme buttons */
437 #define joy_WINGEX_trigger joy_b1
438 #define joy_WINGEX_buttop joy_b2
439 #define joy_WINGEX_butthumb joy_b3
440 #define joy_WINGEX_butmiddle joy_b4
441
442 /* some Yankified aliases ;) */
443 #define JOY_HAT_CENTER JOY_HAT_CENTRE
444
445 /* joystick status variables */
446 extern int joy_x, joy_y;
447 extern int joy_left, joy_right, joy_up, joy_down;
448 extern int joy_b1, joy_b2, joy_b3, joy_b4, joy_b5, joy_b6;
449 extern int joy_hat;
450 extern int joy_throttle;
451 extern int joy2_x, joy2_y;
452 extern int joy2_left, joy2_right, joy2_up, joy2_down;
453 extern int joy2_b1, joy2_b2;
454
455 int initialise_joystick();
456 int calibrate_joystick_tl();
457 int calibrate_joystick_br();
458 int calibrate_joystick_throttle_min();
459 int calibrate_joystick_throttle_max();
460 int calibrate_joystick_hat(int direction);
461
462 void poll_joystick();
463
464 int save_joystick_data(char *filename);
465 int load_joystick_data(char *filename);
466
467 #endif
468
469
470
471 /************************************************/
472 /************ Screen/bitmap routines ************/
473 /************************************************/
474
475 #if !defined alleg_gfx_driver_unused || \
476 !defined alleg_graphics_unused || \
477 !defined alleg_vidmem_unused || \
478 !defined alleg_palette_unused
479
480 #define GFX_TEXT -1
481 #define GFX_AUTODETECT 0
482 #define GFX_VGA 1
483 #define GFX_MODEX 2
484
485 #ifdef DJGPP
486
487 /* for djgpp */
488 #define GFX_VESA1 3
489 #define GFX_VESA2B 4
490 #define GFX_VESA2L 5
491 #define GFX_VBEAF 6
492 #define GFX_XTENDED 7
493 #define GFX_ATI 8
494 #define GFX_MACH64 9
495 #define GFX_CIRRUS64 10
496 #define GFX_CIRRUS54 11
497 #define GFX_PARADISE 12
498 #define GFX_S3 13
499 #define GFX_TRIDENT 14
500 #define GFX_ET3000 15
501 #define GFX_ET4000 16
502 #define GFX_VIDEO7 17
503
504 #else
505
506 /* for linux */
507 #define GFX_SVGALIB 3
508
509 #endif
510
511
512 typedef struct GFX_DRIVER /* creates and manages the screen bitmap */
513 {
514 char *name; /* driver name */
515 char *desc; /* description (VESA version, etc) */
516 struct BITMAP *(*init)(int w, int h, int v_w, int v_h, int color_depth);
517 void (*exit)(struct BITMAP *b);
518 int (*scroll)(int x, int y);
519 void (*vsync)();
520 void (*set_pallete)(struct RGB *p, int from, int to, int vsync);
521 int w, h; /* physical (not virtual!) screen size */
522 int linear; /* true if video memory is linear */
523 long bank_size; /* bank size, in bytes */
524 long bank_gran; /* bank granularity, in bytes */
525 long vid_mem; /* video memory size, in bytes */
526 long vid_phys_base; /* physical address of video memory */
527 } GFX_DRIVER;
528
529
530 extern GFX_DRIVER gfx_vga, gfx_modex;
531
532 #ifdef DJGPP
533
534 /* for djgpp */
535 extern GFX_DRIVER gfx_vesa_1, gfx_vesa_2b, gfx_vesa_2l, gfx_vbeaf,
536 gfx_xtended, gfx_ati, gfx_mach64, gfx_cirrus64,
537 gfx_cirrus54, gfx_realtek, gfx_s3, gfx_trident,
538 gfx_et3000, gfx_et4000, gfx_paradise, gfx_video7;
539
540 #else
541
542 /* for linux */
543 extern GFX_DRIVER gfx_svgalib;
544
545 #endif
546
547
548 typedef struct _GFX_DRIVER_INFO /* info about a graphics driver */
549 {
550 int driver_id; /* integer ID */
551 GFX_DRIVER *driver; /* the driver structure */
552 int autodetect; /* set to allow autodetection */
553 } _GFX_DRIVER_INFO;
554
555
556 /* driver table for autodetection */
557 extern _GFX_DRIVER_INFO _gfx_driver_list[];
558
559
560 /* macros for constructing the driver list */
561 #define DECLARE_GFX_DRIVER_LIST(list...) \
562 _GFX_DRIVER_INFO _gfx_driver_list[] = \
563 { \
564 list \
565 { 0, NULL, 0 } \
566 };
567
568 #define GFX_DRIVER_VGA \
569 { GFX_VGA, &gfx_vga, TRUE },
570
571 #define GFX_DRIVER_MODEX \
572 { GFX_MODEX, &gfx_modex, TRUE },
573
574 #define GFX_DRIVER_VBEAF \
575 { GFX_VBEAF, &gfx_vbeaf, FALSE },
576
577 #define GFX_DRIVER_VESA2L \
578 { GFX_VESA2L, &gfx_vesa_2l, TRUE },
579
580 #define GFX_DRIVER_VESA2B \
581 { GFX_VESA2B, &gfx_vesa_2b, TRUE },
582
583 #define GFX_DRIVER_XTENDED \
584 { GFX_XTENDED, &gfx_xtended, FALSE },
585
586 #define GFX_DRIVER_ATI \
587 { GFX_ATI, &gfx_ati, TRUE },
588
589 #define GFX_DRIVER_MACH64 \
590 { GFX_MACH64, &gfx_mach64, TRUE },
591
592 #define GFX_DRIVER_CIRRUS64 \
593 { GFX_CIRRUS64, &gfx_cirrus64, FALSE },
594
595 #define GFX_DRIVER_CIRRUS54 \
596 { GFX_CIRRUS54, &gfx_cirrus54, TRUE },
597
598 #define GFX_DRIVER_PARADISE \
599 { GFX_PARADISE, &gfx_paradise, TRUE },
600
601 #define GFX_DRIVER_S3 \
602 { GFX_S3, &gfx_s3, TRUE },
603
604 #define GFX_DRIVER_TRIDENT \
605 { GFX_TRIDENT, &gfx_trident, TRUE },
606
607 #define GFX_DRIVER_ET3000 \
608 { GFX_ET3000, &gfx_et3000, FALSE },
609
610 #define GFX_DRIVER_ET4000 \
611 { GFX_ET4000, &gfx_et4000, TRUE },
612
613 #define GFX_DRIVER_VIDEO7 \
614 { GFX_VIDEO7, &gfx_video7, TRUE },
615
616 #define GFX_DRIVER_VESA1 \
617 { GFX_VESA1, &gfx_vesa_1, TRUE },
618
619
620 extern GFX_DRIVER *gfx_driver; /* the driver currently in use */
621
622
623 #define BMP_TYPE_LINEAR 1 /* memory bitmaps, mode 13h, SVGA */
624 #define BMP_TYPE_PLANAR 2 /* mode-X bitmaps */
625
626
627 typedef struct GFX_VTABLE /* functions for drawing onto bitmaps */
628 {
629 int bitmap_type;
630 int color_depth;
631 int mask_color;
632
633 int (*getpixel)(struct BITMAP *bmp, int x, int y);
634 void (*putpixel)(struct BITMAP *bmp, int x, int y, int color);
635 void (*vline)(struct BITMAP *bmp, int x, int y1, int y2, int color);
636 void (*hline)(struct BITMAP *bmp, int x1, int y, int x2, int color);
637 void (*line)(struct BITMAP *bmp, int x1, int y1, int x2, int y2, int color);
638 void (*rectfill)(struct BITMAP *bmp, int x1, int y1, int x2, int y2, int color);
639 void (*draw_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y);
640 void (*draw_256_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y);
641 void (*draw_sprite_v_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y);
642 void (*draw_sprite_h_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y);
643 void (*draw_sprite_vh_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y);
644 void (*draw_trans_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y);
645 void (*draw_lit_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color);
646 void (*draw_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y);
647 void (*draw_trans_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y);
648 void (*draw_lit_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color);
649 void (*draw_character)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color);
650 void (*textout_fixed)(struct BITMAP *bmp, void *f, int h, unsigned char *str, int x, int y, int color);
651 void (*blit_from_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height);
652 void (*blit_to_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height);
653 void (*blit_to_self)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height);
654 void (*blit_to_self_forward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height);
655 void (*blit_to_self_backward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height);
656 void (*masked_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height);
657 void (*clear_to_color)(struct BITMAP *bitmap, int color);
658 void (*draw_sprite_end)(void);
659 void (*blit_end)(void);
660 } GFX_VTABLE;
661
662
663 extern GFX_VTABLE __linear_vtable8, __linear_vtable15, __linear_vtable16,
664 __linear_vtable24, __linear_vtable32, __modex_vtable;
665
666
667 typedef struct _VTABLE_INFO
668 {
669 int color_depth;
670 GFX_VTABLE *vtable;
671 } _VTABLE_INFO;
672
673 extern _VTABLE_INFO _vtable_list[];
674
675
676 /* macros for constructing the vtable list */
677 #define DECLARE_COLOR_DEPTH_LIST(list...) \
678 _VTABLE_INFO _vtable_list[] = \
679 { \
680 list \
681 { 0, NULL } \
682 };
683
684 #define COLOR_DEPTH_8 \
685 { 8, &__linear_vtable8 },
686
687 #define COLOR_DEPTH_15 \
688 { 15, &__linear_vtable15 },
689
690 #define COLOR_DEPTH_16 \
691 { 16, &__linear_vtable16 },
692
693 #define COLOR_DEPTH_24 \
694 { 24, &__linear_vtable24 },
695
696 #define COLOR_DEPTH_32 \
697 { 32, &__linear_vtable32 },
698
699
700
701 typedef struct BITMAP /* a bitmap structure */
702 {
703 int w, h; /* width and height in pixels */
704 int clip; /* flag if clipping is turned on */
705 int cl, cr, ct, cb; /* clip left, right, top and bottom values */
706 GFX_VTABLE *vtable; /* drawing functions */
707 void (*write_bank)(); /* write bank selector, see bank.s */
708 void (*read_bank)(); /* read bank selector, see bank.s */
709 void *dat; /* the memory we allocated for the bitmap */
710 int bitmap_id; /* for identifying sub-bitmaps */
711 void *extra; /* points to a structure with more info */
712 int line_ofs; /* line offset (for screen sub-bitmaps) */
713 int seg; /* bitmap segment */
714 unsigned char *line[0]; /* pointers to the start of each line */
715 } BITMAP;
716
717
718 extern BITMAP *screen;
719
720 #define SCREEN_W (gfx_driver ? gfx_driver->w : 0)
721 #define SCREEN_H (gfx_driver ? gfx_driver->h : 0)
722
723 #define VIRTUAL_W (screen ? screen->w : 0)
724 #define VIRTUAL_H (screen ? screen->h : 0)
725
726 #define COLORCONV_EXPAND_256 1 /* 8 -> 15/16/24/32 */
727 #define COLORCONV_REDUCE_TO_256 2 /* 15/16/24/32 -> 8 */
728 #define COLORCONV_EXPAND_15_TO_16 4 /* 15 -> 16 */
729 #define COLORCONV_REDUCE_16_TO_15 8 /* 16 -> 15 */
730 #define COLORCONV_EXPAND_HI_TO_TRUE 16 /* 15/16 -> 24/32 */
731 #define COLORCONV_REDUCE_TRUE_TO_HI 32 /* 24/32 -> 15/16 */
732 #define COLORCONV_24_EQUALS_32 64 /* 24/32 -> 24/32 */
733
734 #define COLORCONV_NONE 0
735 #define COLORCONV_TOTAL 0xFFFF
736
737 #define COLORCONV_PARTIAL (COLORCONV_EXPAND_15_TO_16 | \
738 COLORCONV_REDUCE_16_TO_15 | \
739 COLORCONV_24_EQUALS_32)
740
741 #define COLORCONV_MOST (COLORCONV_EXPAND_15_TO_16 | \
742 COLORCONV_REDUCE_16_TO_15 | \
743 COLORCONV_EXPAND_HI_TO_TRUE | \
744 COLORCONV_REDUCE_TRUE_TO_HI | \
745 COLORCONV_24_EQUALS_32)
746
747 void set_color_depth(int depth);
748 void set_color_conversion(int mode);
749 int set_gfx_mode(int card, int w, int h, int v_w, int v_h);
750 int scroll_screen(int x, int y);
751 void request_modex_scroll(int x, int y);
752 int poll_modex_scroll();
753 void split_modex_screen(int line);
754
755 BITMAP *create_bitmap(int width, int height);
756 BITMAP *create_bitmap_ex(int color_depth, int width, int height);
757 BITMAP *create_sub_bitmap(BITMAP *parent, int x, int y, int width, int height);
758 void destroy_bitmap(BITMAP *bitmap);
759
760
bitmap_color_depth(BITMAP * bmp)761 __INLINE__ int bitmap_color_depth(BITMAP *bmp)
762 {
763 return bmp->vtable->color_depth;
764 }
765
766
bitmap_mask_color(BITMAP * bmp)767 __INLINE__ int bitmap_mask_color(BITMAP *bmp)
768 {
769 return bmp->vtable->mask_color;
770 }
771
772
is_same_bitmap(BITMAP * bmp1,BITMAP * bmp2)773 __INLINE__ int is_same_bitmap(BITMAP *bmp1, BITMAP *bmp2)
774 {
775 return ((bmp1 == bmp2) ||
776 ((bmp1->bitmap_id != 0) && (bmp1->bitmap_id == bmp2->bitmap_id)));
777 }
778
779
is_linear_bitmap(BITMAP * bmp)780 __INLINE__ int is_linear_bitmap(BITMAP *bmp)
781 {
782 return (bmp->vtable->bitmap_type == BMP_TYPE_LINEAR);
783 }
784
785
is_planar_bitmap(BITMAP * bmp)786 __INLINE__ int is_planar_bitmap(BITMAP *bmp)
787 {
788 return (bmp->vtable->bitmap_type == BMP_TYPE_PLANAR);
789 }
790
791
is_memory_bitmap(BITMAP * bmp)792 __INLINE__ int is_memory_bitmap(BITMAP *bmp)
793 {
794 return (bmp->dat != NULL);
795 }
796
797
is_screen_bitmap(BITMAP * bmp)798 __INLINE__ int is_screen_bitmap(BITMAP *bmp)
799 {
800 return is_same_bitmap(bmp, screen);
801 }
802
803
is_sub_bitmap(BITMAP * bmp)804 __INLINE__ int is_sub_bitmap(BITMAP *bmp)
805 {
806 return ((bmp->dat == NULL) && (bmp != screen));
807 }
808
809 #endif
810
811
812
813 /************************************************/
814 /************ Color/Pallete routines ************/
815 /************************************************/
816
817 #if !defined alleg_palette_unused || !defined alleg_flic_unused
818
819 typedef struct RGB
820 {
821 unsigned char r, g, b;
822 unsigned char filler;
823 } RGB;
824
825 #define PAL_SIZE 256
826
827 typedef RGB PALLETE[PAL_SIZE];
828
829 extern RGB black_rgb;
830 extern PALLETE black_pallete, desktop_pallete, _current_pallete;
831
832 typedef struct {
833 unsigned char data[32][32][32];
834 } RGB_MAP;
835
836 typedef struct {
837 unsigned char data[PAL_SIZE][PAL_SIZE];
838 } COLOR_MAP;
839
840 extern RGB_MAP *rgb_map;
841 extern COLOR_MAP *color_map;
842
843 typedef unsigned long (*BLENDER_FUNC)(unsigned long x, unsigned long y);
844
845 typedef struct {
846 BLENDER_FUNC blend[256];
847 } BLENDER_MAP;
848
849 extern int _color_depth;
850
851 extern int _rgb_r_shift_15, _rgb_g_shift_15, _rgb_b_shift_15,
852 _rgb_r_shift_16, _rgb_g_shift_16, _rgb_b_shift_16,
853 _rgb_r_shift_24, _rgb_g_shift_24, _rgb_b_shift_24,
854 _rgb_r_shift_32, _rgb_g_shift_32, _rgb_b_shift_32;
855
856 extern int _rgb_scale_5[32], _rgb_scale_6[64];
857
858 #define MASK_COLOR_8 0
859 #define MASK_COLOR_15 0x7C1F
860 #define MASK_COLOR_16 0xF81F
861 #define MASK_COLOR_24 0xFF00FF
862 #define MASK_COLOR_32 0xFF00FF
863
864 extern int pallete_color[256];
865
866 void set_color(int index, RGB *p);
867 void set_pallete(PALLETE p);
868 void set_pallete_range(PALLETE p, int from, int to, int vsync);
869
870 void get_color(int index, RGB *p);
871 void get_pallete(PALLETE p);
872 void get_pallete_range(PALLETE p, int from, int to);
873
874 void fade_interpolate(PALLETE source, PALLETE dest, PALLETE output, int pos, int from, int to);
875 void fade_from_range(PALLETE source, PALLETE dest, int speed, int from, int to);
876 void fade_in_range(PALLETE p, int speed, int from, int to);
877 void fade_out_range(int speed, int from, int to);
878 void fade_from(PALLETE source, PALLETE dest, int speed);
879 void fade_in(PALLETE p, int speed);
880 void fade_out(int speed);
881
882 void select_pallete(PALLETE p);
883 void unselect_pallete();
884
885 void generate_332_palette(PALLETE pal);
886 int generate_optimized_palette(BITMAP *image, PALLETE pal, char rsvdcols[256]);
887
888 void create_rgb_table(RGB_MAP *table, PALLETE pal, void (*callback)(int pos));
889 void create_light_table(COLOR_MAP *table, PALLETE pal, int r, int g, int b, void (*callback)(int pos));
890 void create_trans_table(COLOR_MAP *table, PALLETE pal, int r, int g, int b, void (*callback)(int pos));
891 void create_color_table(COLOR_MAP *table, PALLETE pal, RGB (*blend)(PALLETE pal, int x, int y), void (*callback)(int pos));
892
893 void set_blender_mode(BLENDER_MAP *b15, BLENDER_MAP *b16, BLENDER_MAP *b24, int r, int g, int b, int a);
894 void set_trans_blender(int r, int g, int b, int a);
895
896 void hsv_to_rgb(float h, float s, float v, int *r, int *g, int *b);
897 void rgb_to_hsv(int r, int g, int b, float *h, float *s, float *v);
898
899 int bestfit_color(PALLETE pal, int r, int g, int b);
900
901 int makecol(int r, int g, int b);
902 int makecol8(int r, int g, int b);
903 int makecol_depth(int color_depth, int r, int g, int b);
904
905 int getr(int c);
906 int getg(int c);
907 int getb(int c);
908
909 int getr_depth(int color_depth, int c);
910 int getg_depth(int color_depth, int c);
911 int getb_depth(int color_depth, int c);
912
913
vsync()914 __INLINE__ void vsync()
915 {
916 gfx_driver->vsync();
917 }
918
919
_set_color(int index,RGB * p)920 __INLINE__ void _set_color(int index, RGB *p)
921 {
922 outportb(0x3C8, index);
923 outportb(0x3C9, p->r);
924 outportb(0x3C9, p->g);
925 outportb(0x3C9, p->b);
926
927 _current_pallete[index] = *p;
928 }
929
930
makecol15(int r,int g,int b)931 __INLINE__ int makecol15(int r, int g, int b)
932 {
933 return (((r >> 3) << _rgb_r_shift_15) |
934 ((g >> 3) << _rgb_g_shift_15) |
935 ((b >> 3) << _rgb_b_shift_15));
936 }
937
938
makecol16(int r,int g,int b)939 __INLINE__ int makecol16(int r, int g, int b)
940 {
941 return (((r >> 3) << _rgb_r_shift_16) |
942 ((g >> 2) << _rgb_g_shift_16) |
943 ((b >> 3) << _rgb_b_shift_16));
944 }
945
946
makecol24(int r,int g,int b)947 __INLINE__ int makecol24(int r, int g, int b)
948 {
949 return ((r << _rgb_r_shift_24) |
950 (g << _rgb_g_shift_24) |
951 (b << _rgb_b_shift_24));
952 }
953
954
makecol32(int r,int g,int b)955 __INLINE__ int makecol32(int r, int g, int b)
956 {
957 return ((r << _rgb_r_shift_32) |
958 (g << _rgb_g_shift_32) |
959 (b << _rgb_b_shift_32));
960 }
961
962
getr8(int c)963 __INLINE__ int getr8(int c)
964 {
965 return _rgb_scale_6[(int)_current_pallete[c].r];
966 }
967
968
getg8(int c)969 __INLINE__ int getg8(int c)
970 {
971 return _rgb_scale_6[(int)_current_pallete[c].g];
972 }
973
974
getb8(int c)975 __INLINE__ int getb8(int c)
976 {
977 return _rgb_scale_6[(int)_current_pallete[c].b];
978 }
979
980
getr15(int c)981 __INLINE__ int getr15(int c)
982 {
983 return _rgb_scale_5[(c >> _rgb_r_shift_15) & 0x1F];
984 }
985
986
getg15(int c)987 __INLINE__ int getg15(int c)
988 {
989 return _rgb_scale_5[(c >> _rgb_g_shift_15) & 0x1F];
990 }
991
992
getb15(int c)993 __INLINE__ int getb15(int c)
994 {
995 return _rgb_scale_5[(c >> _rgb_b_shift_15) & 0x1F];
996 }
997
998
getr16(int c)999 __INLINE__ int getr16(int c)
1000 {
1001 return _rgb_scale_5[(c >> _rgb_r_shift_16) & 0x1F];
1002 }
1003
1004
getg16(int c)1005 __INLINE__ int getg16(int c)
1006 {
1007 return _rgb_scale_6[(c >> _rgb_g_shift_16) & 0x3F];
1008 }
1009
1010
getb16(int c)1011 __INLINE__ int getb16(int c)
1012 {
1013 return _rgb_scale_5[(c >> _rgb_b_shift_16) & 0x1F];
1014 }
1015
1016
getr24(int c)1017 __INLINE__ int getr24(int c)
1018 {
1019 return ((c >> _rgb_r_shift_24) & 0xFF);
1020 }
1021
1022
getg24(int c)1023 __INLINE__ int getg24(int c)
1024 {
1025 return ((c >> _rgb_g_shift_24) & 0xFF);
1026 }
1027
1028
getb24(int c)1029 __INLINE__ int getb24(int c)
1030 {
1031 return ((c >> _rgb_b_shift_24) & 0xFF);
1032 }
1033
1034
getr32(int c)1035 __INLINE__ int getr32(int c)
1036 {
1037 return ((c >> _rgb_r_shift_32) & 0xFF);
1038 }
1039
1040
getg32(int c)1041 __INLINE__ int getg32(int c)
1042 {
1043 return ((c >> _rgb_g_shift_32) & 0xFF);
1044 }
1045
1046
getb32(int c)1047 __INLINE__ int getb32(int c)
1048 {
1049 return ((c >> _rgb_b_shift_32) & 0xFF);
1050 }
1051
1052
1053 /* in case you want to spell 'pallete' as 'palette' */
1054 #define PALETTE PALLETE
1055 #define black_palette black_pallete
1056 #define desktop_palette desktop_pallete
1057 #define set_palette set_pallete
1058 #define get_palette get_pallete
1059 #define set_palette_range set_pallete_range
1060 #define get_palette_range get_pallete_range
1061 #define fli_palette fli_pallete
1062 #define palette_color pallete_color
1063 #define DAT_PALETTE DAT_PALLETE
1064 #define select_palette select_pallete
1065 #define unselect_palette unselect_pallete
1066 #define generate_332_pallete generate_332_palette
1067 #define generate_optimised_pallete generate_optimised_palette
1068
1069 #endif
1070
1071
1072
1073 /******************************************************/
1074 /************ Graphics and sprite routines ************/
1075 /******************************************************/
1076
1077 #if !defined alleg_graphics_unused
1078
1079 void set_clip(BITMAP *bitmap, int x1, int y1, int x2, int y2);
1080
1081 #define DRAW_MODE_SOLID 0 /* flags for drawing_mode() */
1082 #define DRAW_MODE_XOR 1
1083 #define DRAW_MODE_COPY_PATTERN 2
1084 #define DRAW_MODE_SOLID_PATTERN 3
1085 #define DRAW_MODE_MASKED_PATTERN 4
1086 #define DRAW_MODE_TRANS 5
1087
1088 void drawing_mode(int mode, BITMAP *pattern, int x_anchor, int y_anchor);
1089 void xor_mode(int xor);
1090 void solid_mode();
1091
1092
getpixel(BITMAP * bmp,int x,int y)1093 __INLINE__ int getpixel(BITMAP *bmp, int x, int y)
1094 {
1095 return bmp->vtable->getpixel(bmp, x, y);
1096 }
1097
1098
putpixel(BITMAP * bmp,int x,int y,int color)1099 __INLINE__ void putpixel(BITMAP *bmp, int x, int y, int color)
1100 {
1101 bmp->vtable->putpixel(bmp, x, y, color);
1102 }
1103
1104
vline(BITMAP * bmp,int x,int y1,int y2,int color)1105 __INLINE__ void vline(BITMAP *bmp, int x, int y1, int y2, int color)
1106 {
1107 bmp->vtable->vline(bmp, x, y1, y2, color);
1108 }
1109
1110
hline(BITMAP * bmp,int x1,int y,int x2,int color)1111 __INLINE__ void hline(BITMAP *bmp, int x1, int y, int x2, int color)
1112 {
1113 bmp->vtable->hline(bmp, x1, y, x2, color);
1114 }
1115
1116
line(BITMAP * bmp,int x1,int y1,int x2,int y2,int color)1117 __INLINE__ void line(BITMAP *bmp, int x1, int y1, int x2, int y2, int color)
1118 {
1119 bmp->vtable->line(bmp, x1, y1, x2, y2, color);
1120 }
1121
1122
rectfill(BITMAP * bmp,int x1,int y1,int x2,int y2,int color)1123 __INLINE__ void rectfill(BITMAP *bmp, int x1, int y1, int x2, int y2, int color)
1124 {
1125 bmp->vtable->rectfill(bmp, x1, y1, x2, y2, color);
1126 }
1127
1128
draw_sprite(BITMAP * bmp,BITMAP * sprite,int x,int y)1129 __INLINE__ void draw_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y)
1130 {
1131 if (sprite->vtable->color_depth == 8)
1132 bmp->vtable->draw_256_sprite(bmp, sprite, x, y);
1133 else
1134 bmp->vtable->draw_sprite(bmp, sprite, x, y);
1135 }
1136
1137
draw_sprite_v_flip(BITMAP * bmp,BITMAP * sprite,int x,int y)1138 __INLINE__ void draw_sprite_v_flip(BITMAP *bmp, BITMAP *sprite, int x, int y)
1139 {
1140 bmp->vtable->draw_sprite_v_flip(bmp, sprite, x, y);
1141 }
1142
1143
draw_sprite_h_flip(BITMAP * bmp,BITMAP * sprite,int x,int y)1144 __INLINE__ void draw_sprite_h_flip(BITMAP *bmp, BITMAP *sprite, int x, int y)
1145 {
1146 bmp->vtable->draw_sprite_h_flip(bmp, sprite, x, y);
1147 }
1148
1149
draw_sprite_vh_flip(BITMAP * bmp,BITMAP * sprite,int x,int y)1150 __INLINE__ void draw_sprite_vh_flip(BITMAP *bmp, BITMAP *sprite, int x, int y)
1151 {
1152 bmp->vtable->draw_sprite_vh_flip(bmp, sprite, x, y);
1153 }
1154
1155
draw_trans_sprite(BITMAP * bmp,BITMAP * sprite,int x,int y)1156 __INLINE__ void draw_trans_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y)
1157 {
1158 bmp->vtable->draw_trans_sprite(bmp, sprite, x, y);
1159 }
1160
1161
draw_lit_sprite(BITMAP * bmp,BITMAP * sprite,int x,int y,int color)1162 __INLINE__ void draw_lit_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, int color)
1163 {
1164 bmp->vtable->draw_lit_sprite(bmp, sprite, x, y, color);
1165 }
1166
1167
draw_character(BITMAP * bmp,BITMAP * sprite,int x,int y,int color)1168 __INLINE__ void draw_character(BITMAP *bmp, BITMAP *sprite, int x, int y, int color)
1169 {
1170 bmp->vtable->draw_character(bmp, sprite, x, y, color);
1171 }
1172
1173
draw_rle_sprite(BITMAP * bmp,struct RLE_SPRITE * sprite,int x,int y)1174 __INLINE__ void draw_rle_sprite(BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y)
1175 {
1176 bmp->vtable->draw_rle_sprite(bmp, sprite, x, y);
1177 }
1178
1179
draw_trans_rle_sprite(BITMAP * bmp,struct RLE_SPRITE * sprite,int x,int y)1180 __INLINE__ void draw_trans_rle_sprite(BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y)
1181 {
1182 bmp->vtable->draw_trans_rle_sprite(bmp, sprite, x, y);
1183 }
1184
1185
draw_lit_rle_sprite(BITMAP * bmp,struct RLE_SPRITE * sprite,int x,int y,int color)1186 __INLINE__ void draw_lit_rle_sprite(BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color)
1187 {
1188 bmp->vtable->draw_lit_rle_sprite(bmp, sprite, x, y, color);
1189 }
1190
1191
clear_to_color(BITMAP * bitmap,int color)1192 __INLINE__ void clear_to_color(BITMAP *bitmap, int color)
1193 {
1194 bitmap->vtable->clear_to_color(bitmap, color);
1195 }
1196
1197
1198 void do_line(BITMAP *bmp, int x1, int y1, int x2, int y2, int d, void (*proc)(BITMAP *, int, int, int));
1199 void triangle(BITMAP *bmp, int x1, int y1, int x2, int y2, int x3, int y3, int color);
1200 void polygon(BITMAP *bmp, int vertices, int *points, int color);
1201 void rect(BITMAP *bmp, int x1, int y1, int x2, int y2, int color);
1202 void do_circle(BITMAP *bmp, int x, int y, int radius, int d, void (*proc)(BITMAP *, int, int, int));
1203 void circle(BITMAP *bmp, int x, int y, int radius, int color);
1204 void circlefill(BITMAP *bmp, int x, int y, int radius, int color);
1205 void do_ellipse(BITMAP *bmp, int x, int y, int rx, int ry, int d, void (*proc)(BITMAP *, int, int, int));
1206 void ellipse(BITMAP *bmp, int x, int y, int rx, int ry, int color);
1207 void ellipsefill(BITMAP *bmp, int cx, int cy, int rx, int ry, int color);
1208 void calc_spline(int points[8], int npts, int *x, int *y);
1209 void spline(BITMAP *bmp, int points[8], int color);
1210 void floodfill(BITMAP *bmp, int x, int y, int color);
1211 void blit(BITMAP *source, BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height);
1212 void masked_blit(BITMAP *source, BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height);
1213 void stretch_blit(BITMAP *s, BITMAP *d, int s_x, int s_y, int s_w, int s_h, int d_x, int d_y, int d_w, int d_h);
1214 void stretch_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, int w, int h);
1215 void rotate_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle);
1216 void rotate_scaled_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle, fixed scale);
1217 void clear(BITMAP *bitmap);
1218
1219
1220 typedef struct RLE_SPRITE /* a RLE compressed sprite */
1221 {
1222 int w, h; /* width and height in pixels */
1223 int color_depth; /* color depth of the image */
1224 int size; /* size of sprite data in bytes */
1225 signed char dat[0]; /* RLE bitmap data */
1226 } RLE_SPRITE;
1227
1228
1229 RLE_SPRITE *get_rle_sprite(BITMAP *bitmap);
1230 void destroy_rle_sprite(RLE_SPRITE *sprite);
1231
1232
1233 typedef struct COMPILED_SPRITE /* a compiled sprite */
1234 {
1235 short planar; /* set if it's a planar (mode-X) sprite */
1236 short color_depth; /* color depth of the image */
1237 short w, h; /* size of the sprite */
1238 struct {
1239 void *draw; /* routines to draw the image */
1240 int len; /* length of the drawing functions */
1241 } proc[4];
1242 } COMPILED_SPRITE;
1243
1244
1245 COMPILED_SPRITE *get_compiled_sprite(BITMAP *bitmap, int planar);
1246 void destroy_compiled_sprite(COMPILED_SPRITE *sprite);
1247 void draw_compiled_sprite(BITMAP *bmp, COMPILED_SPRITE *sprite, int x, int y);
1248
1249
1250 #define FONT_SIZE 224 /* number of characters in a font */
1251
1252
1253 typedef struct FONT_8x8 /* a simple 8x8 font */
1254 {
1255 unsigned char dat[FONT_SIZE][8];
1256 } FONT_8x8;
1257
1258
1259 typedef struct FONT_8x16 /* a simple 8x16 font */
1260 {
1261 unsigned char dat[FONT_SIZE][16];
1262 } FONT_8x16;
1263
1264
1265 typedef struct FONT_PROP /* a proportional font */
1266 {
1267 BITMAP *dat[FONT_SIZE];
1268 } FONT_PROP;
1269
1270
1271 typedef struct FONT /* can be either */
1272 {
1273 int height;
1274 union {
1275 FONT_8x8 *dat_8x8;
1276 FONT_8x16 *dat_8x16;
1277 FONT_PROP *dat_prop;
1278 } dat;
1279 } FONT;
1280
1281
1282 extern FONT *font;
1283
1284 void text_mode(int mode);
1285 void textout(BITMAP *bmp, FONT *f, unsigned char *str, int x, int y, int color);
1286 void textout_centre(BITMAP *bmp, FONT *f, unsigned char *str, int x, int y, int color);
1287 void textout_justify(BITMAP *bmp, FONT *f, unsigned char *str, int x1, int x2, int y, int diff, int color);
1288 void textprintf(BITMAP *bmp, FONT *f, int x, int y, int color, char *format, ...) __attribute__ ((format (printf, 6, 7)));
1289 void textprintf_centre(BITMAP *bmp, FONT *f, int x, int y, int color, char *format, ...) __attribute__ ((format (printf, 6, 7)));
1290
1291 int text_length(FONT *f, unsigned char *str);
1292 int text_height(FONT *f);
1293 void destroy_font(FONT *f);
1294
1295
1296 #ifdef __cplusplus
1297
1298 } /* end of extern "C" */
1299
1300
textout(BITMAP * bmp,FONT * f,char * str,int x,int y,int color)1301 __INLINE__ void textout(BITMAP *bmp, FONT *f, char *str, int x, int y, int color)
1302 {
1303 textout(bmp, f, (unsigned char *)str, x, y, color);
1304 }
1305
1306
textout_centre(BITMAP * bmp,FONT * f,char * str,int x,int y,int color)1307 __INLINE__ void textout_centre(BITMAP *bmp, FONT *f, char *str, int x, int y, int color)
1308 {
1309 textout_centre(bmp, f, (unsigned char *)str, x, y, color);
1310 }
1311
1312
textout_justify(BITMAP * bmp,FONT * f,char * str,int x1,int x2,int y,int diff,int color)1313 __INLINE__ void textout_justify(BITMAP *bmp, FONT *f, char *str, int x1, int x2, int y, int diff, int color)
1314 {
1315 textout_justify(bmp, f, (unsigned char *)str, x1, x2, diff, y, color);
1316 }
1317
1318
text_length(FONT * f,char * str)1319 __INLINE__ int text_length(FONT *f, char *str)
1320 {
1321 return text_length(f, (unsigned char *)str);
1322 }
1323
1324
1325 extern "C" {
1326
1327 #endif /* ifdef __cplusplus */
1328
1329
1330 typedef struct V3D /* a 3d point (fixed point version) */
1331 {
1332 fixed x, y, z; /* position */
1333 fixed u, v; /* texture map coordinates */
1334 int c; /* color */
1335 } V3D;
1336
1337
1338 typedef struct V3D_f /* a 3d point (floating point version) */
1339 {
1340 float x, y, z; /* position */
1341 float u, v; /* texture map coordinates */
1342 int c; /* color */
1343 } V3D_f;
1344
1345
1346 #define POLYTYPE_FLAT 0
1347 #define POLYTYPE_GCOL 1
1348 #define POLYTYPE_GRGB 2
1349 #define POLYTYPE_ATEX 3
1350 #define POLYTYPE_PTEX 4
1351 #define POLYTYPE_ATEX_MASK 5
1352 #define POLYTYPE_PTEX_MASK 6
1353 #define POLYTYPE_ATEX_LIT 7
1354 #define POLYTYPE_PTEX_LIT 8
1355
1356
1357 void polygon3d(BITMAP *bmp, int type, BITMAP *texture, int vc, V3D *vtx[]);
1358 void polygon3d_f(BITMAP *bmp, int type, BITMAP *texture, int vc, V3D_f *vtx[]);
1359 void triangle3d(BITMAP *bmp, int type, BITMAP *texture, V3D *v1, V3D *v2, V3D *v3);
1360 void triangle3d_f(BITMAP *bmp, int type, BITMAP *texture, V3D_f *v1, V3D_f *v2, V3D_f *v3);
1361 void quad3d(BITMAP *bmp, int type, BITMAP *texture, V3D *v1, V3D *v2, V3D *v3, V3D *v4);
1362 void quad3d_f(BITMAP *bmp, int type, BITMAP *texture, V3D_f *v1, V3D_f *v2, V3D_f *v3, V3D_f *v4);
1363
1364 #endif
1365
1366
1367
1368 /*********************************************/
1369 /************ Video memory access ************/
1370 /*********************************************/
1371
1372 #if !defined alleg_vidmem_unused
1373
bmp_write_line(BITMAP * bmp,int line)1374 __INLINE__ unsigned long bmp_write_line(BITMAP *bmp, int line)
1375 {
1376 unsigned long result;
1377
1378 asm volatile (
1379 " call *%3 "
1380
1381 : "=a" (result) /* result in eax */
1382
1383 : "d" (bmp), /* bitmap in edx */
1384 "0" (line), /* line number in eax */
1385 "r" (bmp->write_bank) /* the bank switch routine */
1386 );
1387
1388 return result;
1389 }
1390
1391
bmp_read_line(BITMAP * bmp,int line)1392 __INLINE__ unsigned long bmp_read_line(BITMAP *bmp, int line)
1393 {
1394 unsigned long result;
1395
1396 asm volatile (
1397 " call *%3 "
1398
1399 : "=a" (result) /* result in eax */
1400
1401 : "d" (bmp), /* bitmap in edx */
1402 "0" (line), /* line number in eax */
1403 "r" (bmp->read_bank) /* the bank switch routine */
1404 );
1405
1406 return result;
1407 }
1408
1409
_putpixel(BITMAP * bmp,int x,int y,unsigned char color)1410 __INLINE__ void _putpixel(BITMAP *bmp, int x, int y, unsigned char color)
1411 {
1412 asm (
1413 " movw %w0, %%fs ; "
1414 " .byte 0x64 ; "
1415 " movb %b3, (%1, %2) "
1416 : /* no outputs */
1417
1418 : "rm" (bmp->seg), /* segment selector in reg or mem */
1419 "r" (bmp_write_line(bmp, y)), /* line pointer in reg */
1420 "r" (x), /* line offset in reg */
1421 "qi" (color) /* the pixel in reg or immediate */
1422 );
1423 }
1424
1425
_getpixel(BITMAP * bmp,int x,int y)1426 __INLINE__ unsigned char _getpixel(BITMAP *bmp, int x, int y)
1427 {
1428 unsigned char result;
1429
1430 asm (
1431 " movw %w1, %%fs ; "
1432 " .byte 0x64 ; "
1433 " movb (%2, %3), %b0"
1434
1435 : "=&q" (result) /* result in al, bl, cl, or dl */
1436
1437 : "rm" (bmp->seg), /* segment selector in reg or mem */
1438 "r" (bmp_read_line(bmp, y)), /* line pointer in reg */
1439 "r" (x) /* line offset in reg */
1440 );
1441
1442 return result;
1443 }
1444
1445 #endif
1446
1447
1448
1449 /******************************************/
1450 /************ FLI/FLC routines ************/
1451 /******************************************/
1452
1453 #if !defined alleg_flic_unused
1454
1455 #define FLI_OK 0 /* FLI player return values */
1456 #define FLI_EOF -1
1457 #define FLI_ERROR -2
1458 #define FLI_NOT_OPEN -3
1459
1460 int play_fli(char *filename, BITMAP *bmp, int loop, int (*callback)());
1461 int play_memory_fli(void *fli_data, BITMAP *bmp, int loop, int (*callback)());
1462
1463 int open_fli(char *filename);
1464 int open_memory_fli(void *fli_data);
1465 void close_fli();
1466 int next_fli_frame(int loop);
1467 void reset_fli_variables();
1468
1469 extern BITMAP *fli_bitmap; /* current frame of the FLI */
1470 extern PALLETE fli_pallete; /* current FLI pallete */
1471
1472 extern int fli_bmp_dirty_from; /* what part of fli_bitmap is dirty */
1473 extern int fli_bmp_dirty_to;
1474 extern int fli_pal_dirty_from; /* what part of fli_pallete is dirty */
1475 extern int fli_pal_dirty_to;
1476
1477 extern int fli_frame; /* current frame number */
1478
1479 extern volatile int fli_timer; /* for timing FLI playback */
1480
1481 #endif
1482
1483
1484
1485 /****************************************/
1486 /************ Sound routines ************/
1487 /****************************************/
1488
1489 #if !defined alleg_sound_unused
1490
1491 #define DIGI_VOICES 32 /* Theoretical maximums: */
1492 #define MIDI_VOICES 32 /* actual drivers may not be */
1493 #define MIDI_TRACKS 32 /* able to handle this many */
1494
1495
1496 typedef struct SAMPLE /* a sample */
1497 {
1498 int bits; /* 8 or 16 */
1499 int freq; /* sample frequency */
1500 int priority; /* 0-255 */
1501 unsigned long len; /* length (in samples) */
1502 unsigned long loop_start; /* loop start position */
1503 unsigned long loop_end; /* loop finish position */
1504 unsigned long param; /* for internal use by the driver */
1505 void *data; /* sample data */
1506 } SAMPLE;
1507
1508
1509 typedef struct MIDI /* a midi file */
1510 {
1511 int divisions; /* number of ticks per quarter note */
1512 struct {
1513 unsigned char *data; /* MIDI message stream */
1514 int len; /* length of the track data */
1515 } track[MIDI_TRACKS];
1516 } MIDI;
1517
1518
1519 typedef struct AUDIOSTREAM
1520 {
1521 int voice; /* the voice we are playing on */
1522 SAMPLE *samp; /* the sample we are using */
1523 void *b1, *b2; /* two audio buffers */
1524 int bufnum; /* which buffer is currently playing */
1525 int len; /* buffer length */
1526 } AUDIOSTREAM;
1527
1528
1529 #define DIGI_AUTODETECT -1 /* for passing to install_sound() */
1530 #define DIGI_NONE 0
1531
1532 #ifdef DJGPP
1533
1534 /* for djgpp */
1535 #define DIGI_SB 1
1536 #define DIGI_SB10 2
1537 #define DIGI_SB15 3
1538 #define DIGI_SB20 4
1539 #define DIGI_SBPRO 5
1540 #define DIGI_SB16 6
1541 #define DIGI_GUS 7
1542
1543 #else
1544
1545 /* for linux */
1546 #define DIGI_LINUX_SOUND_NOT_IMPLEMENTED_YET
1547
1548 #endif
1549
1550 #define MIDI_AUTODETECT -1
1551 #define MIDI_NONE 0
1552
1553 #ifdef DJGPP
1554
1555 /* for djgpp */
1556 #define MIDI_ADLIB 1
1557 #define MIDI_OPL2 2
1558 #define MIDI_2XOPL2 3
1559 #define MIDI_OPL3 4
1560 #define MIDI_SB_OUT 5
1561 #define MIDI_MPU 6
1562 #define MIDI_GUS 7
1563 #define MIDI_DIGMID 8
1564 #define MIDI_AWE32 9
1565
1566 #else
1567
1568 /* for linux */
1569 #define MIDI_LINUX_SOUND_NOT_IMPLEMENTED_YET
1570
1571 #endif
1572
1573
1574 typedef struct DIGI_DRIVER /* driver for playing digital sfx */
1575 {
1576 char *name; /* driver name */
1577 char *desc; /* description string */
1578 int voices; /* available voices */
1579 int basevoice; /* voice number offset */
1580 int max_voices; /* maximum voices we can support */
1581 int def_voices; /* default number of voices to use */
1582
1583 /* setup routines */
1584 int (*detect)();
1585 int (*init)(int voices);
1586 void (*exit)();
1587 int (*mixer_volume)(int volume);
1588
1589 /* voice control functions */
1590 void (*init_voice)(int voice, SAMPLE *sample);
1591 void (*release_voice)(int voice);
1592 void (*start_voice)(int voice);
1593 void (*stop_voice)(int voice);
1594 void (*loop_voice)(int voice, int playmode);
1595
1596 /* position control functions */
1597 int (*get_position)(int voice);
1598 void (*set_position)(int voice, int position);
1599
1600 /* volume control functions */
1601 int (*get_volume)(int voice);
1602 void (*set_volume)(int voice, int volume);
1603 void (*ramp_volume)(int voice, int time, int endvol);
1604 void (*stop_volume_ramp)(int voice);
1605
1606 /* pitch control functions */
1607 int (*get_frequency)(int voice);
1608 void (*set_frequency)(int voice, int frequency);
1609 void (*sweep_frequency)(int voice, int time, int endfreq);
1610 void (*stop_frequency_sweep)(int voice);
1611
1612 /* pan control functions */
1613 int (*get_pan)(int voice);
1614 void (*set_pan)(int voice, int pan);
1615 void (*sweep_pan)(int voice, int time, int endpan);
1616 void (*stop_pan_sweep)(int voice);
1617
1618 /* effect control functions */
1619 void (*set_echo)(int voice, int strength, int delay);
1620 void (*set_tremolo)(int voice, int rate, int depth);
1621 void (*set_vibrato)(int voice, int rate, int depth);
1622 } DIGI_DRIVER;
1623
1624
1625 typedef struct MIDI_DRIVER /* driver for playing midi music */
1626 {
1627 char *name; /* driver name */
1628 char *desc; /* description string */
1629 int voices; /* available voices */
1630 int basevoice; /* voice number offset */
1631 int max_voices; /* maximum voices we can support */
1632 int def_voices; /* default number of voices to use */
1633 int xmin, xmax; /* reserved voice range */
1634
1635 /* setup routines */
1636 int (*detect)();
1637 int (*init)(int voices);
1638 void (*exit)();
1639 int (*mixer_volume)(int volume);
1640
1641 /* raw MIDI output to MPU-401, etc. */
1642 void (*raw_midi)(unsigned char data);
1643
1644 /* dynamic patch loading routines */
1645 int (*load_patches)(char *patches, char *drums);
1646 void (*adjust_patches)(char *patches, char *drums);
1647
1648 /* note control functions */
1649 void (*key_on)(int inst, int note, int bend, int vol, int pan);
1650 void (*key_off)(int voice);
1651 void (*set_volume)(int voice, int vol);
1652 void (*set_pitch)(int voice, int note, int bend);
1653 void (*set_pan)(int voice, int pan);
1654 void (*set_vibrato)(int voice, int amount);
1655 } MIDI_DRIVER;
1656
1657
1658 extern DIGI_DRIVER digi_none;
1659
1660 #ifdef DJGPP
1661 /* for djgpp */
1662 extern DIGI_DRIVER digi_sb, digi_gus;
1663 #else
1664 /* for linux */
1665 extern DIGI_DRIVER digi_linux_sound_not_implemented_yet;
1666 #endif
1667
1668 extern MIDI_DRIVER midi_none;
1669
1670 #ifdef DJGPP
1671 /* for djgpp */
1672 extern MIDI_DRIVER midi_adlib, midi_sb_out, midi_mpu401, midi_gus, midi_digmid, midi_awe32;
1673 #else
1674 /* for linux */
1675 extern MIDI_DRIVER midi_linux_sound_not_implemented_yet;
1676 #endif
1677
1678
1679 typedef struct _DIGI_DRIVER_INFO /* info about a digital driver */
1680 {
1681 int driver_id; /* integer ID */
1682 DIGI_DRIVER *driver; /* the driver structure */
1683 int autodetect; /* set to allow autodetection */
1684 } _DIGI_DRIVER_INFO;
1685
1686
1687 typedef struct _MIDI_DRIVER_INFO /* info about a MIDI driver */
1688 {
1689 int driver_id; /* integer ID */
1690 MIDI_DRIVER *driver; /* the driver structure */
1691 int autodetect; /* set to allow autodetection */
1692 } _MIDI_DRIVER_INFO;
1693
1694
1695 /* driver tables for autodetection */
1696 extern _DIGI_DRIVER_INFO _digi_driver_list[];
1697 extern _MIDI_DRIVER_INFO _midi_driver_list[];
1698
1699
1700 /* macros for constructing the driver lists */
1701 #define DECLARE_DIGI_DRIVER_LIST(list...) \
1702 _DIGI_DRIVER_INFO _digi_driver_list[] = \
1703 { \
1704 list \
1705 { DIGI_NONE, &digi_none, TRUE }, \
1706 { 0, NULL, 0 } \
1707 };
1708
1709 #define DECLARE_MIDI_DRIVER_LIST(list...) \
1710 _MIDI_DRIVER_INFO _midi_driver_list[] = \
1711 { \
1712 list \
1713 { MIDI_NONE, &midi_none, TRUE }, \
1714 { 0, NULL, 0 } \
1715 };
1716
1717 #define DIGI_DRIVER_GUS \
1718 { DIGI_GUS, &digi_gus, TRUE },
1719
1720 #define DIGI_DRIVER_SB \
1721 { DIGI_SB, &digi_sb, TRUE }, \
1722 { DIGI_SB10, &digi_sb, FALSE }, \
1723 { DIGI_SB15, &digi_sb, FALSE }, \
1724 { DIGI_SB20, &digi_sb, FALSE }, \
1725 { DIGI_SBPRO, &digi_sb, FALSE }, \
1726 { DIGI_SB16, &digi_sb, FALSE },
1727
1728 #define MIDI_DRIVER_AWE32 \
1729 { MIDI_AWE32, &midi_awe32, TRUE },
1730
1731 #define MIDI_DRIVER_DIGMID \
1732 { MIDI_DIGMID, &midi_digmid, TRUE },
1733
1734 #define MIDI_DRIVER_ADLIB \
1735 { MIDI_ADLIB, &midi_adlib, TRUE }, \
1736 { MIDI_OPL2, &midi_adlib, FALSE }, \
1737 { MIDI_2XOPL2, &midi_adlib, FALSE }, \
1738 { MIDI_OPL3, &midi_adlib, FALSE },
1739
1740 #define MIDI_DRIVER_SB_OUT \
1741 { MIDI_SB_OUT, &midi_sb_out, FALSE },
1742
1743 #define MIDI_DRIVER_MPU \
1744 { MIDI_MPU, &midi_mpu401, FALSE },
1745
1746
1747 extern DIGI_DRIVER *digi_driver; /* the drivers currently in use */
1748 extern MIDI_DRIVER *midi_driver;
1749
1750 extern int digi_card, midi_card;
1751
1752 extern volatile long midi_pos; /* current position in the midi file */
1753
1754 extern long midi_loop_start; /* where to loop back to at EOF */
1755 extern long midi_loop_end; /* loop when we hit this position */
1756
1757 int detect_digi_driver(int driver_id);
1758 int detect_midi_driver(int driver_id);
1759
1760 void reserve_voices(int digi_voices, int midi_voices);
1761 int install_sound(int digi_card, int midi_card, char *cfg_path);
1762 void remove_sound();
1763 void set_volume(int digi_volume, int midi_volume);
1764
1765 int load_ibk(char *filename, int drums);
1766
1767 SAMPLE *load_sample(char *filename);
1768 SAMPLE *load_wav(char *filename);
1769 SAMPLE *load_voc(char *filename);
1770 void destroy_sample(SAMPLE *spl);
1771
1772 int play_sample(SAMPLE *spl, int vol, int pan, int freq, int loop);
1773 void stop_sample(SAMPLE *spl);
1774 void adjust_sample(SAMPLE *spl, int vol, int pan, int freq, int loop);
1775
1776 int allocate_voice(SAMPLE *spl);
1777 void deallocate_voice(int voice);
1778 void reallocate_voice(int voice, SAMPLE *spl);
1779 void release_voice(int voice);
1780 void voice_start(int voice);
1781 void voice_stop(int voice);
1782 void voice_set_priority(int voice, int priority);
1783 SAMPLE *voice_check(int voice);
1784
1785 #define PLAYMODE_PLAY 0
1786 #define PLAYMODE_LOOP 1
1787 #define PLAYMODE_FORWARD 0
1788 #define PLAYMODE_BACKWARD 2
1789 #define PLAYMODE_BIDIR 4
1790
1791 void voice_set_playmode(int voice, int playmode);
1792
1793 int voice_get_position(int voice);
1794 void voice_set_position(int voice, int position);
1795
1796 int voice_get_volume(int voice);
1797 void voice_set_volume(int voice, int volume);
1798 void voice_ramp_volume(int voice, int time, int endvol);
1799 void voice_stop_volumeramp(int voice);
1800
1801 int voice_get_frequency(int voice);
1802 void voice_set_frequency(int voice, int frequency);
1803 void voice_sweep_frequency(int voice, int time, int endfreq);
1804 void voice_stop_frequency_sweep(int voice);
1805
1806 int voice_get_pan(int voice);
1807 void voice_set_pan(int voice, int pan);
1808 void voice_sweep_pan(int voice, int time, int endpan);
1809 void voice_stop_pan_sweep(int voice);
1810
1811 void voice_set_echo(int voice, int strength, int delay);
1812 void voice_set_tremolo(int voice, int rate, int depth);
1813 void voice_set_vibrato(int voice, int rate, int depth);
1814
1815 MIDI *load_midi(char *filename);
1816 void destroy_midi(MIDI *midi);
1817 int play_midi(MIDI *midi, int loop);
1818 int play_looped_midi(MIDI *midi, int loop_start, int loop_end);
1819 void stop_midi();
1820 void midi_pause();
1821 void midi_resume();
1822 int midi_seek(int target);
1823 void midi_out(unsigned char *data, int length);
1824 int load_midi_patches();
1825
1826 extern void (*midi_msg_callback)(int msg, int byte1, int byte2);
1827 extern void (*midi_meta_callback)(int type, unsigned char *data, int length);
1828 extern void (*midi_sysex_callback)(unsigned char *data, int length);
1829
1830 AUDIOSTREAM *play_audio_stream(int len, int bits, int freq, int vol, int pan);
1831 void stop_audio_stream(AUDIOSTREAM *stream);
1832 void *get_audio_stream_buffer(AUDIOSTREAM *stream);
1833 void free_audio_stream_buffer(AUDIOSTREAM *stream);
1834
1835 #endif
1836
1837
1838
1839 /***********************************************************/
1840 /************ File I/O and compression routines ************/
1841 /***********************************************************/
1842
1843 #if 0
1844 #if !defined alleg_file_unused
1845
1846 char *get_filename(char *path);
1847 char *get_extension(char *filename);
1848 void put_backslash(char *filename);
1849 int file_exists(char *filename, int attrib, int *aret);
1850 int exists(char *filename);
1851 long file_size(char *filename);
1852 long file_time(char *filename);
1853 int delete_file(char *filename);
1854 int for_each_file(char *name, int attrib, void (*callback)(), int param);
1855
1856 #ifndef EOF
1857 #define EOF -1
1858 #endif
1859
1860 #define F_READ "r" /* for use with pack_fopen() */
1861 #define F_WRITE "w"
1862 #define F_READ_PACKED "rp"
1863 #define F_WRITE_PACKED "wp"
1864 #define F_WRITE_NOPACK "w!"
1865
1866 #define F_BUF_SIZE 4096 /* 4K buffer for caching data */
1867 #define F_PACK_MAGIC 0x736C6821L /* magic number for packed files */
1868 #define F_NOPACK_MAGIC 0x736C682EL /* magic number for autodetect */
1869 #define F_EXE_MAGIC 0x736C682BL /* magic number for appended data */
1870
1871 #define PACKFILE_FLAG_WRITE 1 /* the file is being written */
1872 #define PACKFILE_FLAG_PACK 2 /* data is compressed */
1873 #define PACKFILE_FLAG_CHUNK 4 /* file is a sub-chunk */
1874 #define PACKFILE_FLAG_EOF 8 /* reached the end-of-file */
1875 #define PACKFILE_FLAG_ERROR 16 /* an error has occurred */
1876
1877
1878 typedef struct PACKFILE /* our very own FILE structure... */
1879 {
1880 int hndl; /* DOS file handle */
1881 int flags; /* PACKFILE_FLAG_* constants */
1882 unsigned char *buf_pos; /* position in buffer */
1883 int buf_size; /* number of bytes in the buffer */
1884 long todo; /* number of bytes still on the disk */
1885 struct PACKFILE *parent; /* nested, parent file */
1886 void *pack_data; /* for LZSS compression */
1887 char *filename; /* name of the file */
1888 char *password; /* current encryption position */
1889 unsigned char buf[F_BUF_SIZE]; /* the actual data buffer */
1890 } PACKFILE;
1891
1892
1893 void packfile_password(char *password);
1894 PACKFILE *pack_fopen(char *filename, char *mode);
1895 int pack_fclose(PACKFILE *f);
1896 int pack_fseek(PACKFILE *f, int offset);
1897 PACKFILE *pack_fopen_chunk(PACKFILE *f, int pack);
1898 PACKFILE *pack_fclose_chunk(PACKFILE *f);
1899 int pack_igetw(PACKFILE *f);
1900 long pack_igetl(PACKFILE *f);
1901 int pack_iputw(int w, PACKFILE *f);
1902 long pack_iputl(long l, PACKFILE *f);
1903 int pack_mgetw(PACKFILE *f);
1904 long pack_mgetl(PACKFILE *f);
1905 int pack_mputw(int w, PACKFILE *f);
1906 long pack_mputl(long l, PACKFILE *f);
1907 long pack_fread(void *p, long n, PACKFILE *f);
1908 long pack_fwrite(void *p, long n, PACKFILE *f);
1909 char *pack_fgets(char *p, int max, PACKFILE *f);
1910 int pack_fputs(char *p, PACKFILE *f);
1911
1912 int _sort_out_getc(PACKFILE *f);
1913 int _sort_out_putc(int c, PACKFILE *f);
1914
1915 #define pack_feof(f) ((f)->flags & PACKFILE_FLAG_EOF)
1916 #define pack_ferror(f) ((f)->flags & PACKFILE_FLAG_ERROR)
1917
1918
1919 __INLINE__ int pack_getc(PACKFILE *f)
1920 {
1921 f->buf_size--;
1922 if (f->buf_size > 0)
1923 return *(f->buf_pos++);
1924 else
1925 return _sort_out_getc(f);
1926 }
1927
1928
1929 __INLINE__ int pack_putc(int c, PACKFILE *f)
1930 {
1931 f->buf_size++;
1932 if (f->buf_size >= F_BUF_SIZE)
1933 return _sort_out_putc(c, f);
1934 else
1935 return (*(f->buf_pos++) = c);
1936 }
1937 #endif
1938
1939
1940
1941 /*******************************************/
1942 /************ Datafile routines ************/
1943 /*******************************************/
1944
1945 #if !defined alleg_datafile_unused
1946
1947 #define DAT_ID(a,b,c,d) ((a<<24) | (b<<16) | (c<<8) | d)
1948
1949 #define DAT_MAGIC DAT_ID('A','L','L','.')
1950 #define DAT_FILE DAT_ID('F','I','L','E')
1951 #define DAT_DATA DAT_ID('D','A','T','A')
1952 #define DAT_FONT DAT_ID('F','O','N','T')
1953 #define DAT_SAMPLE DAT_ID('S','A','M','P')
1954 #define DAT_MIDI DAT_ID('M','I','D','I')
1955 #define DAT_PATCH DAT_ID('P','A','T',' ')
1956 #define DAT_FLI DAT_ID('F','L','I','C')
1957 #define DAT_BITMAP DAT_ID('B','M','P',' ')
1958 #define DAT_RLE_SPRITE DAT_ID('R','L','E',' ')
1959 #define DAT_C_SPRITE DAT_ID('C','M','P',' ')
1960 #define DAT_XC_SPRITE DAT_ID('X','C','M','P')
1961 #define DAT_PALLETE DAT_ID('P','A','L',' ')
1962 #define DAT_PROPERTY DAT_ID('p','r','o','p')
1963 #define DAT_NAME DAT_ID('N','A','M','E')
1964 #define DAT_END -1
1965
1966
1967 typedef struct DATAFILE_PROPERTY
1968 {
1969 char *dat; /* pointer to the data */
1970 int type; /* property type */
1971 } DATAFILE_PROPERTY;
1972
1973
1974 typedef struct DATAFILE
1975 {
1976 void *dat; /* pointer to the data */
1977 int type; /* object type */
1978 long size; /* size of the object */
1979 DATAFILE_PROPERTY *prop; /* object properties */
1980 } DATAFILE;
1981
1982
1983 DATAFILE *load_datafile(char *filename);
1984 void unload_datafile(DATAFILE *dat);
1985
1986 DATAFILE *load_datafile_object(char *filename, char *objectname);
1987 void unload_datafile_object(DATAFILE *dat);
1988
1989 char *get_datafile_property(DATAFILE *dat, int type);
1990 void register_datafile_object(int id, void *(*load)(PACKFILE *f, long size), void (*destroy)(void *data));
1991
1992 void fixup_datafile(DATAFILE *data);
1993
1994 BITMAP *load_bitmap(char *filename, RGB *pal);
1995 BITMAP *load_bmp(char *filename, RGB *pal);
1996 BITMAP *load_lbm(char *filename, RGB *pal);
1997 BITMAP *load_pcx(char *filename, RGB *pal);
1998 BITMAP *load_tga(char *filename, RGB *pal);
1999
2000 int save_bitmap(char *filename, BITMAP *bmp, RGB *pal);
2001 int save_bmp(char *filename, BITMAP *bmp, RGB *pal);
2002 int save_pcx(char *filename, BITMAP *bmp, RGB *pal);
2003 int save_tga(char *filename, BITMAP *bmp, RGB *pal);
2004
2005 void register_bitmap_file_type(char *ext, BITMAP *(*load)(char *filename, RGB *pal), int (*save)(char *filename, BITMAP *bmp, RGB *pal));
2006
2007 #endif
2008 #endif
2009
2010
2011
2012 /***************************************/
2013 /************ Math routines ************/
2014 /***************************************/
2015
2016 #if !defined alleg_math_unused
2017
itofix(int x)2018 __INLINE__ fixed itofix(int x)
2019 {
2020 return x << 16;
2021 }
2022
2023
fixtoi(fixed x)2024 __INLINE__ int fixtoi(fixed x)
2025 {
2026 return (x >> 16) + ((x & 0x8000) >> 15);
2027 }
2028
2029
ftofix(double x)2030 __INLINE__ fixed ftofix(double x)
2031 {
2032 if (x > 32767.0) {
2033 errno = ERANGE;
2034 return 0x7FFFFFFF;
2035 }
2036
2037 if (x < -32768.0) {
2038 errno = ERANGE;
2039 return -0x80000000;
2040 }
2041
2042 return (long)(x * 65536.0 + (x < 0 ? -0.5 : 0.5));
2043 }
2044
2045
fixtof(fixed x)2046 __INLINE__ double fixtof(fixed x)
2047 {
2048 return (double)x / 65536.0;
2049 }
2050
2051
2052 fixed fsqrt(fixed x);
2053 fixed fatan(fixed x);
2054 fixed fatan2(fixed y, fixed x);
2055
2056 extern fixed _cos_tbl[];
2057 extern fixed _tan_tbl[];
2058 extern fixed _acos_tbl[];
2059
2060
fcos(fixed x)2061 __INLINE__ fixed fcos(fixed x)
2062 {
2063 return _cos_tbl[((x & 0x4000) ? (x >> 15) + 1 : (x >> 15)) & 0x1ff];
2064 }
2065
2066
fsin(fixed x)2067 __INLINE__ fixed fsin(fixed x)
2068 {
2069 return _cos_tbl[(((x & 0x4000) ? (x >> 15) + 1 : (x >> 15)) -128) & 0x1ff];
2070 }
2071
2072
ftan(fixed x)2073 __INLINE__ fixed ftan(fixed x)
2074 {
2075 return _tan_tbl[((x & 0x4000) ? (x >> 15) + 1 : (x >> 15)) & 0xff];
2076 }
2077
2078
facos(fixed x)2079 __INLINE__ fixed facos(fixed x)
2080 {
2081 if ((x < -65536L) || (x > 65536L)) {
2082 errno = EDOM;
2083 return 0L;
2084 }
2085
2086 return _acos_tbl[(x+65536L)>>8];
2087 }
2088
2089
fasin(fixed x)2090 __INLINE__ fixed fasin(fixed x)
2091 {
2092 if ((x < -65536L) || (x > 65536L)) {
2093 errno = EDOM;
2094 return 0L;
2095 }
2096
2097 return 0x00400000L - _acos_tbl[(x+65536L)>>8];
2098 }
2099
2100
fadd(fixed x,fixed y)2101 __INLINE__ fixed fadd(fixed x, fixed y)
2102 {
2103 fixed result;
2104
2105 asm (
2106 " addl %2, %0 ; " /* do the addition */
2107 " jno 0f ; " /* check for overflow */
2108
2109 " movl $2, _errno ; " /* on overflow, set errno */
2110 " movl $0x7fffffff, %0 ; " /* and return MAXINT */
2111 " cmpl $0, %2 ; "
2112 " jg 0f ; "
2113 " negl %0 ; "
2114
2115 " 0: " /* finished */
2116
2117 : "=r" (result) /* result in a register */
2118
2119 : "0" (x), /* x in the output register */
2120 "g" (y) /* y can go anywhere */
2121
2122 : "%cc" /* clobbers flags */
2123 );
2124
2125 return result;
2126 }
2127
2128
fsub(fixed x,fixed y)2129 __INLINE__ fixed fsub(fixed x, fixed y)
2130 {
2131 fixed result;
2132
2133 asm (
2134 " subl %2, %0 ; " /* do the subtraction */
2135 " jno 0f ; " /* check for overflow */
2136
2137 " movl $2, _errno ; " /* on overflow, set errno */
2138 " movl $0x7fffffff, %0 ; " /* and return MAXINT */
2139 " cmpl $0, %2 ; "
2140 " jl 0f ; "
2141 " negl %0 ; "
2142
2143 " 0: " /* finished */
2144
2145 : "=r" (result) /* result in a register */
2146
2147 : "0" (x), /* x in the output register */
2148 "g" (y) /* y can go anywhere */
2149
2150 : "%cc" /* clobbers flags */
2151 );
2152
2153 return result;
2154 }
2155
2156
fmul(fixed x,fixed y)2157 __INLINE__ fixed fmul(fixed x, fixed y)
2158 {
2159 fixed result;
2160
2161 asm (
2162 " movl %1, %0 ; "
2163 " imull %2 ; " /* do the multiply */
2164 " shrdl $16, %%edx, %0 ; "
2165
2166 " shrl $16, %%edx ; " /* check for overflow */
2167 " jz 0f ; "
2168 " cmpw $0xFFFF, %%dx ; "
2169 " je 0f ; "
2170
2171 " movl $2, _errno ; " /* on overflow, set errno */
2172 " movl $0x7fffffff, %0 ; " /* and return MAXINT */
2173 " cmpl $0, %1 ; "
2174 " jge 1f ; "
2175 " negl %0 ; "
2176 " 1: "
2177 " cmpl $0, %2 ; "
2178 " jge 0f ; "
2179 " negl %0 ; "
2180
2181 " 0: " /* finished */
2182
2183 : "=&a" (result) /* the result has to go in eax */
2184
2185 : "mr" (x), /* x and y can be regs or mem */
2186 "mr" (y)
2187
2188 : "%edx", "%cc" /* clobbers edx and flags */
2189 );
2190
2191 return result;
2192 }
2193
2194
fdiv(fixed x,fixed y)2195 __INLINE__ fixed fdiv(fixed x, fixed y)
2196 {
2197 fixed result;
2198
2199 asm (
2200 " movl %2, %%ecx ; "
2201 " xorl %%ebx, %%ebx ; "
2202
2203 " orl %0, %0 ; " /* test sign of x */
2204 " jns 0f ; "
2205
2206 " negl %0 ; "
2207 " incl %%ebx ; "
2208
2209 " 0: "
2210 " orl %%ecx, %%ecx ; " /* test sign of y */
2211 " jns 1f ; "
2212
2213 " negl %%ecx ; "
2214 " incb %%ebx ; "
2215
2216 " 1: "
2217 " movl %0, %%edx ; " /* check the range is ok */
2218 " shrl $16, %%edx ; "
2219 " shll $16, %0 ; "
2220 " cmpl %%ecx, %%edx ; "
2221 " jae 2f ; "
2222
2223 " divl %%ecx ; " /* do the divide */
2224 " orl %0, %0 ; "
2225 " jns 3f ; "
2226
2227 " 2: "
2228 " movl $2, _errno ; " /* on overflow, set errno */
2229 " movl $0x7fffffff, %0 ; " /* and return MAXINT */
2230
2231 " 3: "
2232 " testl $1, %%ebx ; " /* fix up the sign of the result */
2233 " jz 4f ; "
2234
2235 " negl %0 ; "
2236
2237 " 4: " /* finished */
2238
2239 : "=a" (result) /* the result has to go in eax */
2240
2241 : "0" (x), /* x in eax */
2242 "g" (y) /* y can be anywhere */
2243
2244 : "%ebx", "%ecx", "%edx", "%cc" /* clobbers ebx, ecx, edx + flags */
2245 );
2246
2247 return result;
2248 }
2249
2250
2251 #ifdef __cplusplus
2252
2253 } /* end of extern "C" */
2254
2255
2256 class fix /* C++ wrapper for the fixed point routines */
2257 {
2258 public:
2259 fixed v;
2260
fix()2261 fix() { }
fix(const fix & x)2262 fix(const fix &x) { v = x.v; }
fix(const int x)2263 fix(const int x) { v = itofix(x); }
fix(const long x)2264 fix(const long x) { v = itofix(x); }
fix(const unsigned int x)2265 fix(const unsigned int x) { v = itofix(x); }
fix(const unsigned long x)2266 fix(const unsigned long x) { v = itofix(x); }
fix(const float x)2267 fix(const float x) { v = ftofix(x); }
fix(const double x)2268 fix(const double x) { v = ftofix(x); }
2269
2270 operator int() const { return fixtoi(v); }
2271 operator long() const { return fixtoi(v); }
2272 operator unsigned int() const { return fixtoi(v); }
2273 operator unsigned long() const { return fixtoi(v); }
2274 operator float() const { return fixtof(v); }
2275 operator double() const { return fixtof(v); }
2276
2277 fix& operator = (const fix &x) { v = x.v; return *this; }
2278 fix& operator = (const int x) { v = itofix(x); return *this; }
2279 fix& operator = (const long x) { v = itofix(x); return *this; }
2280 fix& operator = (const unsigned int x) { v = itofix(x); return *this; }
2281 fix& operator = (const unsigned long x) { v = itofix(x); return *this; }
2282 fix& operator = (const float x) { v = ftofix(x); return *this; }
2283 fix& operator = (const double x) { v = ftofix(x); return *this; }
2284
2285 fix& operator += (const fix x) { v += x.v; return *this; }
2286 fix& operator -= (const fix x) { v -= x.v; return *this; }
2287 fix& operator *= (const fix x) { v = fmul(v, x.v); return *this; }
2288 fix& operator *= (const int x) { v *= x; return *this; }
2289 fix& operator /= (const fix x) { v = fdiv(v, x.v); return *this; }
2290 fix& operator /= (const int x) { v /= x; return *this; }
2291 fix& operator <<= (const int x) { v <<= x; return *this; }
2292 fix& operator >>= (const int x) { v >>= x; return *this; }
2293
2294 fix& operator ++ () { v += itofix(1); return *this; }
2295 fix& operator -- () { v -= itofix(1); return *this; }
2296
2297 fix operator - () { fix t; t.v = -v; return t; }
2298
2299 inline friend fix operator + (const fix x, const fix y) { fix t; t.v = x.v + y.v; return t; }
2300 inline friend fix operator - (const fix x, const fix y) { fix t; t.v = x.v - y.v; return t; }
2301 inline friend fix operator * (const fix x, const fix y) { fix t; t.v = fmul(x.v, y.v); return t; }
2302 inline friend fix operator * (const fix x, const int y) { fix t; t.v = x.v * y; return t; }
2303 inline friend fix operator * (const int x, const fix y) { fix t; t.v = y.v * x; return t; }
2304 inline friend fix operator / (const fix x, const fix y) { fix t; t.v = fdiv(x.v, y.v); return t; }
2305 inline friend fix operator / (const fix x, const int y) { fix t; t.v = x.v / y; return t; }
2306 inline friend fix operator << (const fix x, const int y) { fix t; t.v = x.v << y; return t; }
2307 inline friend fix operator >> (const fix x, const int y) { fix t; t.v = x.v >> y; return t; }
2308
2309 inline friend int operator == (const fix x, const fix y) { return (x.v == y.v); }
2310 inline friend int operator != (const fix x, const fix y) { return (x.v != y.v); }
2311 inline friend int operator < (const fix x, const fix y) { return (x.v < y.v); }
2312 inline friend int operator > (const fix x, const fix y) { return (x.v > y.v); }
2313 inline friend int operator <= (const fix x, const fix y) { return (x.v <= y.v); }
2314 inline friend int operator >= (const fix x, const fix y) { return (x.v >= y.v); }
2315
sqrt(fix x)2316 inline friend fix sqrt(fix x) { fix t; t.v = fsqrt(x.v); return t; }
cos(fix x)2317 inline friend fix cos(fix x) { fix t; t.v = fcos(x.v); return t; }
sin(fix x)2318 inline friend fix sin(fix x) { fix t; t.v = fsin(x.v); return t; }
tan(fix x)2319 inline friend fix tan(fix x) { fix t; t.v = ftan(x.v); return t; }
acos(fix x)2320 inline friend fix acos(fix x) { fix t; t.v = facos(x.v); return t; }
asin(fix x)2321 inline friend fix asin(fix x) { fix t; t.v = fasin(x.v); return t; }
atan(fix x)2322 inline friend fix atan(fix x) { fix t; t.v = fatan(x.v); return t; }
atan2(fix x,fix y)2323 inline friend fix atan2(fix x, fix y) { fix t; t.v = fatan2(x.v, y.v); return t; }
2324 };
2325
2326
2327 extern "C" {
2328
2329 #endif /* ifdef __cplusplus */
2330
2331
2332 typedef struct MATRIX /* transformation matrix (fixed point) */
2333 {
2334 fixed v[3][3]; /* scaling and rotation */
2335 fixed t[3]; /* translation */
2336 } MATRIX;
2337
2338
2339 typedef struct MATRIX_f /* transformation matrix (floating point) */
2340 {
2341 float v[3][3]; /* scaling and rotation */
2342 float t[3]; /* translation */
2343 } MATRIX_f;
2344
2345
2346 extern MATRIX identity_matrix;
2347 extern MATRIX_f identity_matrix_f;
2348
2349
2350 void get_translation_matrix(MATRIX *m, fixed x, fixed y, fixed z);
2351 void get_translation_matrix_f(MATRIX_f *m, float x, float y, float z);
2352
2353 void get_scaling_matrix(MATRIX *m, fixed x, fixed y, fixed z);
2354 void get_scaling_matrix_f(MATRIX_f *m, float x, float y, float z);
2355
2356 void get_x_rotate_matrix(MATRIX *m, fixed r);
2357 void get_x_rotate_matrix_f(MATRIX_f *m, float r);
2358
2359 void get_y_rotate_matrix(MATRIX *m, fixed r);
2360 void get_y_rotate_matrix_f(MATRIX_f *m, float r);
2361
2362 void get_z_rotate_matrix(MATRIX *m, fixed r);
2363 void get_z_rotate_matrix_f(MATRIX_f *m, float r);
2364
2365 void get_rotation_matrix(MATRIX *m, fixed x, fixed y, fixed z);
2366 void get_rotation_matrix_f(MATRIX_f *m, float x, float y, float z);
2367
2368 void get_align_matrix(MATRIX *m, fixed xfront, fixed yfront, fixed zfront, fixed xup, fixed yup, fixed zup);
2369 void get_align_matrix_f(MATRIX_f *m, float xfront, float yfront, float zfront, float xup, float yup, float zup);
2370
2371 void get_vector_rotation_matrix(MATRIX *m, fixed x, fixed y, fixed z, fixed a);
2372 void get_vector_rotation_matrix_f(MATRIX_f *m, float x, float y, float z, float a);
2373
2374 void get_transformation_matrix(MATRIX *m, fixed scale, fixed xrot, fixed yrot, fixed zrot, fixed x, fixed y, fixed z);
2375 void get_transformation_matrix_f(MATRIX_f *m, float scale, float xrot, float yrot, float zrot, float x, float y, float z);
2376
2377 void get_camera_matrix(MATRIX *m, fixed x, fixed y, fixed z, fixed xfront, fixed yfront, fixed zfront, fixed xup, fixed yup, fixed zup, fixed fov, fixed aspect);
2378 void get_camera_matrix_f(MATRIX_f *m, float x, float y, float z, float xfront, float yfront, float zfront, float xup, float yup, float zup, float fov, float aspect);
2379
2380 void qtranslate_matrix(MATRIX *m, fixed x, fixed y, fixed z);
2381 void qtranslate_matrix_f(MATRIX_f *m, float x, float y, float z);
2382
2383 void qscale_matrix(MATRIX *m, fixed scale);
2384 void qscale_matrix_f(MATRIX_f *m, float scale);
2385
2386 void matrix_mul(MATRIX *m1, MATRIX *m2, MATRIX *out);
2387 void matrix_mul_f(MATRIX_f *m1, MATRIX_f *m2, MATRIX_f *out);
2388
2389 fixed vector_length(fixed x, fixed y, fixed z);
2390 float vector_length_f(float x, float y, float z);
2391
2392 void normalize_vector(fixed *x, fixed *y, fixed *z);
2393 void normalize_vector_f(float *x, float *y, float *z);
2394
2395 void cross_product(fixed x1, fixed y1, fixed z1, fixed x2, fixed y2, fixed z2, fixed *xout, fixed *yout, fixed *zout);
2396 void cross_product_f(float x1, float y1, float z1, float x2, float y2, float z2, float *xout, float *yout, float *zout);
2397
2398 fixed polygon_z_normal(V3D *v1, V3D *v2, V3D *v3);
2399 float polygon_z_normal_f(V3D_f *v1, V3D_f *v2, V3D_f *v3);
2400
2401
dot_product(fixed x1,fixed y1,fixed z1,fixed x2,fixed y2,fixed z2)2402 __INLINE__ fixed dot_product(fixed x1, fixed y1, fixed z1, fixed x2, fixed y2, fixed z2)
2403 {
2404 return fmul(x1, x2) + fmul(y1, y2) + fmul(z1, z2);
2405 }
2406
2407
dot_product_f(float x1,float y1,float z1,float x2,float y2,float z2)2408 __INLINE__ float dot_product_f(float x1, float y1, float z1, float x2, float y2, float z2)
2409 {
2410 return (x1 * x2) + (y1 * y2) + (z1 * z2);
2411 }
2412
2413
apply_matrix(MATRIX * m,fixed x,fixed y,fixed z,fixed * xout,fixed * yout,fixed * zout)2414 __INLINE__ void apply_matrix(MATRIX *m, fixed x, fixed y, fixed z, fixed *xout, fixed *yout, fixed *zout)
2415 {
2416 #define CALC_ROW(n) (fmul(x, m->v[n][0]) + \
2417 fmul(y, m->v[n][1]) + \
2418 fmul(z, m->v[n][2]) + \
2419 m->t[n])
2420
2421 *xout = CALC_ROW(0);
2422 *yout = CALC_ROW(1);
2423 *zout = CALC_ROW(2);
2424
2425 #undef CALC_ROW
2426 }
2427
2428
2429 void apply_matrix_f(MATRIX_f *m, float x, float y, float z, float *xout, float *yout, float *zout);
2430
2431 extern fixed _persp_xscale, _persp_yscale, _persp_xoffset, _persp_yoffset;
2432 extern float _persp_xscale_f, _persp_yscale_f, _persp_xoffset_f, _persp_yoffset_f;
2433
2434 void set_projection_viewport(int x, int y, int w, int h);
2435
2436
persp_project(fixed x,fixed y,fixed z,fixed * xout,fixed * yout)2437 __INLINE__ void persp_project(fixed x, fixed y, fixed z, fixed *xout, fixed *yout)
2438 {
2439 *xout = fmul(fdiv(x, z), _persp_xscale) + _persp_xoffset;
2440 *yout = fmul(fdiv(y, z), _persp_yscale) + _persp_yoffset;
2441 }
2442
2443
persp_project_f(float x,float y,float z,float * xout,float * yout)2444 __INLINE__ void persp_project_f(float x, float y, float z, float *xout, float *yout)
2445 {
2446 float z1 = 1.0 / z;
2447 *xout = ((x * z1) * _persp_xscale_f) + _persp_xoffset_f;
2448 *yout = ((y * z1) * _persp_yscale_f) + _persp_yoffset_f;
2449 }
2450
2451
2452 #ifdef __cplusplus
2453
2454 } /* end of extern "C" */
2455
2456 /* overloaded functions for use with the fix class */
2457
2458
get_translation_matrix(MATRIX * m,fix x,fix y,fix z)2459 __INLINE__ void get_translation_matrix(MATRIX *m, fix x, fix y, fix z)
2460 {
2461 get_translation_matrix(m, x.v, y.v, z.v);
2462 }
2463
2464
get_scaling_matrix(MATRIX * m,fix x,fix y,fix z)2465 __INLINE__ void get_scaling_matrix(MATRIX *m, fix x, fix y, fix z)
2466 {
2467 get_scaling_matrix(m, x.v, y.v, z.v);
2468 }
2469
2470
get_x_rotate_matrix(MATRIX * m,fix r)2471 __INLINE__ void get_x_rotate_matrix(MATRIX *m, fix r)
2472 {
2473 get_x_rotate_matrix(m, r.v);
2474 }
2475
2476
get_y_rotate_matrix(MATRIX * m,fix r)2477 __INLINE__ void get_y_rotate_matrix(MATRIX *m, fix r)
2478 {
2479 get_y_rotate_matrix(m, r.v);
2480 }
2481
2482
get_z_rotate_matrix(MATRIX * m,fix r)2483 __INLINE__ void get_z_rotate_matrix(MATRIX *m, fix r)
2484 {
2485 get_z_rotate_matrix(m, r.v);
2486 }
2487
2488
get_rotation_matrix(MATRIX * m,fix x,fix y,fix z)2489 __INLINE__ void get_rotation_matrix(MATRIX *m, fix x, fix y, fix z)
2490 {
2491 get_rotation_matrix(m, x.v, y.v, z.v);
2492 }
2493
2494
get_align_matrix(MATRIX * m,fix xfront,fix yfront,fix zfront,fix xup,fix yup,fix zup)2495 __INLINE__ void get_align_matrix(MATRIX *m, fix xfront, fix yfront, fix zfront, fix xup, fix yup, fix zup)
2496 {
2497 get_align_matrix(m, xfront.v, yfront.v, zfront.v, xup.v, yup.v, zup.v);
2498 }
2499
2500
get_vector_rotation_matrix(MATRIX * m,fix x,fix y,fix z,fix a)2501 __INLINE__ void get_vector_rotation_matrix(MATRIX *m, fix x, fix y, fix z, fix a)
2502 {
2503 get_vector_rotation_matrix(m, x.v, y.v, z.v, a.v);
2504 }
2505
2506
get_transformation_matrix(MATRIX * m,fix scale,fix xrot,fix yrot,fix zrot,fix x,fix y,fix z)2507 __INLINE__ void get_transformation_matrix(MATRIX *m, fix scale, fix xrot, fix yrot, fix zrot, fix x, fix y, fix z)
2508 {
2509 get_transformation_matrix(m, scale.v, xrot.v, yrot.v, zrot.v, x.v, y.v, z.v);
2510 }
2511
2512
get_camera_matrix(MATRIX * m,fix x,fix y,fix z,fix xfront,fix yfront,fix zfront,fix xup,fix yup,fix zup,fix fov,fix aspect)2513 __INLINE__ void get_camera_matrix(MATRIX *m, fix x, fix y, fix z, fix xfront, fix yfront, fix zfront, fix xup, fix yup, fix zup, fix fov, fix aspect)
2514 {
2515 get_camera_matrix(m, x.v, y.v, z.v, xfront.v, yfront.v, zfront.v, xup.v, yup.v, zup.v, fov.v, aspect.v);
2516 }
2517
2518
qtranslate_matrix(MATRIX * m,fix x,fix y,fix z)2519 __INLINE__ void qtranslate_matrix(MATRIX *m, fix x, fix y, fix z)
2520 {
2521 qtranslate_matrix(m, x.v, y.v, z.v);
2522 }
2523
2524
qscale_matrix(MATRIX * m,fix scale)2525 __INLINE__ void qscale_matrix(MATRIX *m, fix scale)
2526 {
2527 qscale_matrix(m, scale.v);
2528 }
2529
2530
vector_length(fix x,fix y,fix z)2531 __INLINE__ fix vector_length(fix x, fix y, fix z)
2532 {
2533 fix t;
2534 t.v = vector_length(x.v, y.v, z.v);
2535 return t;
2536 }
2537
2538
normalize_vector(fix * x,fix * y,fix * z)2539 __INLINE__ void normalize_vector(fix *x, fix *y, fix *z)
2540 {
2541 normalize_vector(&x->v, &y->v, &z->v);
2542 }
2543
2544
cross_product(fix x1,fix y1,fix z1,fix x2,fix y2,fix z2,fix * xout,fix * yout,fix * zout)2545 __INLINE__ void cross_product(fix x1, fix y1, fix z1, fix x2, fix y2, fix z2, fix *xout, fix *yout, fix *zout)
2546 {
2547 cross_product(x1.v, y1.v, z1.v, x2.v, y2.v, z2.v, &xout->v, &yout->v, &zout->v);
2548 }
2549
2550
dot_product(fix x1,fix y1,fix z1,fix x2,fix y2,fix z2)2551 __INLINE__ fix dot_product(fix x1, fix y1, fix z1, fix x2, fix y2, fix z2)
2552 {
2553 fix t;
2554 t.v = dot_product(x1.v, y1.v, z1.v, x2.v, y2.v, z2.v);
2555 return t;
2556 }
2557
2558
apply_matrix(MATRIX * m,fix x,fix y,fix z,fix * xout,fix * yout,fix * zout)2559 __INLINE__ void apply_matrix(MATRIX *m, fix x, fix y, fix z, fix *xout, fix *yout, fix *zout)
2560 {
2561 apply_matrix(m, x.v, y.v, z.v, &xout->v, &yout->v, &zout->v);
2562 }
2563
2564
persp_project(fix x,fix y,fix z,fix * xout,fix * yout)2565 __INLINE__ void persp_project(fix x, fix y, fix z, fix *xout, fix *yout)
2566 {
2567 persp_project(x.v, y.v, z.v, &xout->v, &yout->v);
2568 }
2569
2570
2571 extern "C" {
2572
2573 #endif /* ifdef __cplusplus */
2574
2575 #endif
2576
2577
2578
2579 /***************************************/
2580 /************ GUI routines ************/
2581 /***************************************/
2582
2583 #if !defined alleg_gui_unused
2584
2585 /* a GUI object */
2586 typedef struct DIALOG
2587 {
2588 int (*proc)(int, struct DIALOG *, int ); /* dialog procedure */
2589 int x, y, w, h; /* position and size of the object */
2590 int fg, bg; /* foreground and background colors */
2591 int key; /* keyboard shortcut (ASCII code) */
2592 int flags; /* flags about the object state */
2593 int d1, d2; /* any data the object might require */
2594 void *dp, *dp2, *dp3; /* pointers to more object data */
2595 } DIALOG;
2596
2597
2598 /* a popup menu */
2599 typedef struct MENU
2600 {
2601 char *text; /* menu item text */
2602 int (*proc)(void); /* callback function */
2603 struct MENU *child; /* to allow nested menus */
2604 int flags; /* flags about the menu state */
2605 void *dp; /* any data the menu might require */
2606 } MENU;
2607
2608
2609 /* stored information about the state of an active GUI dialog */
2610 typedef struct DIALOG_PLAYER
2611 {
2612 int obj;
2613 int res;
2614 int mouse_obj;
2615 int focus_obj;
2616 int joy_on;
2617 int click_wait;
2618 int mouse_visible;
2619 int mouse_ox, mouse_oy;
2620 DIALOG *dialog;
2621 DIALOG *previous_dialog;
2622 } DIALOG_PLAYER;
2623
2624
2625 #define SEND_MESSAGE(d, msg, c) (d)->proc(msg, d, c)
2626
2627 /* bits for the flags field */
2628 #define D_EXIT 1 /* object makes the dialog exit */
2629 #define D_SELECTED 2 /* object is selected */
2630 #define D_GOTFOCUS 4 /* object has the input focus */
2631 #define D_GOTMOUSE 8 /* mouse is on top of object */
2632 #define D_HIDDEN 16 /* object is not visible */
2633 #define D_DISABLED 32 /* object is visible but inactive */
2634 #define D_INTERNAL 64 /* reserved for internal use */
2635 #define D_USER 128 /* from here on is free for your own use */
2636
2637 /* return values for the dialog procedures */
2638 #define D_O_K 0 /* normal exit status */
2639 #define D_CLOSE 1 /* request to close the dialog */
2640 #define D_REDRAW 2 /* request to redraw the dialog */
2641 #define D_WANTFOCUS 4 /* this object wants the input focus */
2642 #define D_USED_CHAR 8 /* object has used the keypress */
2643
2644 /* messages for the dialog procedures */
2645 #define MSG_START 1 /* start the dialog, initialise */
2646 #define MSG_END 2 /* dialog is finished - cleanup */
2647 #define MSG_DRAW 3 /* draw the object */
2648 #define MSG_CLICK 4 /* mouse click on the object */
2649 #define MSG_DCLICK 5 /* double click on the object */
2650 #define MSG_KEY 6 /* keyboard shortcut */
2651 #define MSG_CHAR 7 /* other keyboard input */
2652 #define MSG_XCHAR 8 /* broadcast character to all objects */
2653 #define MSG_WANTFOCUS 9 /* does object want the input focus? */
2654 #define MSG_GOTFOCUS 10 /* got the input focus */
2655 #define MSG_LOSTFOCUS 11 /* lost the input focus */
2656 #define MSG_GOTMOUSE 12 /* mouse on top of object */
2657 #define MSG_LOSTMOUSE 13 /* mouse moved away from object */
2658 #define MSG_IDLE 14 /* update any background stuff */
2659 #define MSG_RADIO 15 /* clear radio buttons */
2660 #define MSG_USER 16 /* from here on are free... */
2661
2662 /* some dialog procedures */
2663 int d_clear_proc(int msg, DIALOG *d, int c);
2664 int d_box_proc(int msg, DIALOG *d, int c);
2665 int d_shadow_box_proc(int msg, DIALOG *d, int c);
2666 int d_bitmap_proc(int msg, DIALOG *d, int c);
2667 int d_text_proc(int msg, DIALOG *d, int c);
2668 int d_ctext_proc(int msg, DIALOG *d, int c);
2669 int d_button_proc(int msg, DIALOG *d, int c);
2670 int d_check_proc(int msg, DIALOG *d, int c);
2671 int d_radio_proc(int msg, DIALOG *d, int c);
2672 int d_icon_proc(int msg, DIALOG *d, int c);
2673 int d_keyboard_proc(int msg, DIALOG *d, int c);
2674 int d_edit_proc(int msg, DIALOG *d, int c);
2675 int d_list_proc(int msg, DIALOG *d, int c);
2676 int d_textbox_proc(int msg, DIALOG *d, int c);
2677 int d_slider_proc(int msg, DIALOG *d, int c);
2678 int d_menu_proc(int msg, DIALOG *d, int c);
2679
2680 extern DIALOG *active_dialog;
2681 extern MENU *active_menu;
2682
2683 extern int gui_mouse_focus;
2684 extern int gui_fg_color, gui_mg_color, gui_bg_color;
2685 extern int gui_font_baseline;
2686
2687 int gui_textout(BITMAP *bmp, unsigned char *s, int x, int y, int color, int centre);
2688 int gui_strlen(unsigned char *s);
2689 void centre_dialog(DIALOG *dialog);
2690 void set_dialog_color(DIALOG *dialog, int fg, int bg);
2691 int find_dialog_focus(DIALOG *dialog);
2692 int dialog_message(DIALOG *dialog, int msg, int c, int *obj);
2693 int broadcast_dialog_message(int msg, int c);
2694 int do_dialog(DIALOG *dialog, int focus_obj);
2695 int popup_dialog(DIALOG *dialog, int focus_obj);
2696 DIALOG_PLAYER *init_dialog(DIALOG *dialog, int focus_obj);
2697 int update_dialog(DIALOG_PLAYER *player);
2698 int shutdown_dialog(DIALOG_PLAYER *player);
2699 int do_menu(MENU *menu, int x, int y);
2700 int alert(char *s1, char *s2, char *s3, char *b1, char *b2, int c1, int c2);
2701 int alert3(char *s1, char *s2, char *s3, char *b1, char *b2, char *b3, int c1, int c2, int c3);
2702 int file_select(char *message, char *path, char *ext);
2703 int gfx_mode_select(int *card, int *w, int *h);
2704 int gfx_mode_select_ex(int *card, int *w, int *h, int *color_depth);
2705
2706 #endif
2707
2708
2709
2710 #ifdef __cplusplus
2711 }
2712 #endif
2713
2714 #endif /* ifndef ALLEGRO_H */
2715
2716
2717