FreeBASIC  0.91.0
gfx_driver_vesa_lin.c
Go to the documentation of this file.
1 /* linear VESA gfx driver */
2 
3 #include "../fb_gfx.h"
4 #include "fb_gfx_dos.h"
5 #include <pc.h>
6 #include <go32.h>
7 #include <sys/nearptr.h>
8 
9 static int driver_init(char *title, int w, int h, int depth, int refresh_rate, int flags);
10 static void driver_exit(void);
11 static void driver_update(void);
12 static void end_of_driver_update(void);
13 
15 {
16  "VESA linear", /* char *name; */
17  driver_init, /* int (*init)(char *title, int w, int h, int depth, int refresh_rate, int flags); */
18  driver_exit, /* void (*exit)(void); */
19  fb_dos_lock, /* void (*lock)(void); */
20  fb_dos_unlock, /* void (*unlock)(void); */
21  fb_dos_set_palette, /* void (*set_palette)(int index, int r, int g, int b); */
22  fb_dos_vga_wait_vsync, /* void (*wait_vsync)(void); */
23  fb_dos_get_mouse, /* int (*get_mouse)(int *x, int *y, int *z, int *buttons, int *clip); */
24  fb_dos_set_mouse, /* void (*set_mouse)(int x, int y, int cursor, int clip); */
25  fb_dos_set_window_title, /* void (*set_window_title)(char *title); */
26  NULL, /* int (*set_window_pos)(int x, int y); */
27  fb_dos_vesa_fetch_modes, /* int *(*fetch_modes)(int depth, int *size); */
28  NULL, /* void (*flip)(void); */
29  NULL /* void (*poll_events)(void); */
30 };
31 
32 static __dpmi_meminfo mapping = {0};
33 static unsigned char *video;
34 static BLITTER *blitter;
35 static int nearptr_enabled = FALSE;
36 static int data_locked = FALSE;
37 
38 static int driver_init(char *title, int w, int h, int depth_arg, int refresh_rate, int flags)
39 {
40  int depth = MAX(8, depth_arg);
41  int is_rgb, bpp;
42  int red_pos, blue_pos;
43 
44  fb_dos_detect();
46 
47  if (flags & DRIVER_OPENGL)
48  return -1;
49 
50  if (!fb_dos.nearptr_ok)
51  return -1;
52 
53  if (!fb_dos.vesa_ok)
54  return -1;
55 
56  if (fb_dos_vesa_set_mode(w, h, depth, TRUE))
57  return -1;
58 
59  refresh_rate = 60; /* FIXME */
60 
61  fb_dos_lock_data(&video, sizeof(video));
62  fb_dos_lock_data(&blitter, sizeof(blitter));
63  data_locked = TRUE;
64 
65  /* Lin* fields are only required for VBE 3.0 */
67  {
70  }
71  else
72  {
75  }
76 
77  is_rgb = (depth > 8) && (red_pos == 0);
78 
79  if (blue_pos == 10 || red_pos == 10)
80  bpp = 15;
81  else if (blue_pos == 11 || red_pos == 11)
82  bpp = 16;
83  else
85 
87  if (!blitter)
88  return -1;
89 
91  fb_dos.update_len = (unsigned int)end_of_driver_update - (unsigned int)driver_update;
93 
94  __djgpp_nearptr_enable();
96 
98  mapping.size = fb_dos.vesa_info.total_memory << 16;
99  if (__dpmi_physical_address_mapping(&mapping) != 0)
100  return -1;
101 
102  video = (unsigned char *)(mapping.address - __djgpp_base_address);
103 
104  return fb_dos_init(title, w, h, depth, refresh_rate, flags);
105 }
106 
107 static void driver_exit(void)
108 {
109  if (mapping.address != 0)
110  {
111  __dpmi_free_physical_address_mapping(&mapping);
112  mapping.address = 0;
113  }
114 
115  if (nearptr_enabled)
116  {
117  __djgpp_nearptr_disable();
119  }
120 
121  if (data_locked)
122  {
123  fb_dos_unlock_data(&video, sizeof(video));
125  data_locked = FALSE;
126  }
127 
128  fb_dos_exit();
129 }
130 
131 static void driver_update(void)
132 {
134 
135 }
136 static void end_of_driver_update(void) { /* do not remove */ }