fixed video mode bugs
[eradicate] / src / dos / gfx.h
1 #ifndef GFX_H_
2 #define GFX_H_
3
4 #include "inttypes.h"
5
6 struct video_mode {
7         uint16_t mode;
8         short xsz, ysz, bpp, pitch;
9         short rbits, gbits, bbits;
10         short rshift, gshift, bshift;
11         uint32_t rmask, gmask, bmask;
12         uint32_t fb_addr;
13         short max_pages;
14 };
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 int init_video(void);
21 void cleanup_video(void);
22
23 struct video_mode *video_modes(void);
24 int num_video_modes(void);
25
26 int match_video_mode(int xsz, int ysz, int bpp);
27 int find_video_mode(int mode);
28
29 /* argument is the mode list index [0, nmodes-1] */
30 void *set_video_mode(int idx, int nbuf);
31 int set_text_mode(void);
32
33 void set_palette(int idx, int r, int g, int b);
34
35 enum {
36         FLIP_NOW,
37         FLIP_VBLANK
38 };
39 /* page flip and return pointer to the start of the display area (front buffer) */
40 void *page_flip(int vsync);
41
42 #ifdef __WATCOMC__
43 void wait_vsync(void);
44 #pragma aux wait_vsync = \
45         "mov dx, 0x3da" \
46         "l1:" \
47         "in al, dx" \
48         "and al, 0x8" \
49         "jnz l1" \
50         "l2:" \
51         "in al, dx" \
52         "and al, 0x8" \
53         "jz l2" \
54         modify[al dx];
55 #endif
56
57 #ifdef __DJGPP__
58 #define wait_vsync()  asm volatile ( \
59         "mov $0x3da, %%dx\n\t" \
60         "0:\n\t" \
61         "in %%dx, %%al\n\t" \
62         "and $8, %%al\n\t" \
63         "jnz 0b\n\t" \
64         "0:\n\t" \
65         "in %%dx, %%al\n\t" \
66         "and $8, %%al\n\t" \
67         "jz 0b\n\t" \
68         :::"%eax","%edx")
69 #endif
70
71
72 #ifdef __cplusplus
73 }
74 #endif
75
76 #endif  /* GFX_H_ */