1 #ifndef __VGABIOS_H
2 #define __VGABIOS_H
3 
4 #include "config.h" // CONFIG_VGA_EMULATE_TEXT
5 #include "farptr.h" // GET_FARVAR
6 #include "types.h" // u8
7 
8 // Save/Restore flags
9 #define SR_HARDWARE   0x0001
10 #define SR_BDA        0x0002
11 #define SR_DAC        0x0004
12 #define SR_REGISTERS  0x0008
13 #define SR_SAVE       0x0100
14 #define SR_RESTORE    0x0200
15 
16 // Mode flags
17 #define MF_LEGACY     0x0001
18 #define MF_GRAYSUM    0x0002
19 #define MF_NOPALETTE  0x0008
20 #define MF_CUSTOMCRTC 0x0800
21 #define MF_LINEARFB   0x4000
22 #define MF_NOCLEARMEM 0x8000
23 #define MF_VBEFLAGS   0xfe00
24 
25 // Memory model types
26 #define MM_TEXT            0x00
27 #define MM_CGA             0x01
28 #define MM_HERCULES        0x02
29 #define MM_PLANAR          0x03
30 #define MM_PACKED          0x04
31 #define MM_NON_CHAIN_4_256 0x05
32 #define MM_DIRECT          0x06
33 #define MM_YUV             0x07
34 
35 struct vgamode_s {
36     u8 memmodel;
37     u16 width;
38     u16 height;
39     u8 depth;
40     u8 cwidth;
41     u8 cheight;
42     u16 sstart;
43 };
44 
45 // Custom internal storage in BDA (don't change here without also
46 // updating vgaentry.S)
47 #define VGA_CUSTOM_BDA 0xb9
48 
49 struct vga_bda_s {
50     u8 flags;
51     u16 vbe_mode;
52     u16 vgamode_offset;
53 } PACKED;
54 
55 #define BF_PM_MASK      0x0f
56 #define BF_EMULATE_TEXT 0x10
57 #define BF_SWCURSOR     0x20
58 #define BF_EXTRA_STACK  0x40
59 
60 #define GET_BDA_EXT(var) \
61     GET_FARVAR(SEG_BDA, ((struct vga_bda_s *)VGA_CUSTOM_BDA)->var)
62 #define SET_BDA_EXT(var, val) \
63     SET_FARVAR(SEG_BDA, ((struct vga_bda_s *)VGA_CUSTOM_BDA)->var, (val))
64 #define MASK_BDA_EXT(var, off, on)                                      \
65     SET_BDA_EXT(var, (GET_BDA_EXT(var) & ~(off)) | (on))
66 
vga_emulate_text(void)67 static inline int vga_emulate_text(void) {
68     return CONFIG_VGA_EMULATE_TEXT && GET_BDA_EXT(flags) & BF_EMULATE_TEXT;
69 }
70 
71 // Write to global variables (during "post" phase only)
72 #define SET_VGA(var, val) SET_FARVAR(get_global_seg(), (var), (val))
73 
74 // Debug settings
75 #define DEBUG_VGA_POST 1
76 #define DEBUG_VGA_10 9
77 
78 // vgabios.c
79 int vga_bpp(struct vgamode_s *vmode_g);
80 u16 calc_page_size(u8 memmodel, u16 width, u16 height);
81 u16 get_cursor_shape(void);
82 struct cursorpos get_cursor_pos(u8 page);
83 int bda_save_restore(int cmd, u16 seg, void *data);
84 struct vgamode_s *get_current_mode(void);
85 int vga_set_mode(int mode, int flags);
86 extern struct video_func_static static_functionality;
87 
88 #endif // vgabios.h
89