00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #define MODELIST_SIZE 256
00029 #define FG_LINEAR 1
00030 #define CAPABLE_LINEAR 16
00031
00032 #ifdef FG_NAMESPACE
00033 namespace fgl {
00034 #endif
00035
00039 class FGScreen : public FGDrawBuffer
00040 {
00041 public:
00042 FGScreen() : FGDrawBuffer(0, 0, FGFRAMEBUFFER)
00043 {
00044 assert(image==0);
00045 }
00046 void Resize(int xx, int yy)
00047 {
00048 wwrk = w = xx;
00049 hwrk = h = yy;
00050 X_width = w;
00051 Y_width = h;
00052 fgl::set_clip_rect(w, h, 0, 0);
00053 set_font(FONT0816);
00054 set_colors(0, CWHITE);
00055 set_ppop(_GSET);
00056 image = videobase;
00057 }
00058 };
00059
00060 union gii_event;
00064 class FGDriver
00065 {
00066 friend class FGDGADriver;
00067 friend void _giiEvQueueAdd(gii_event *ev);
00068 friend class FGApp;
00069 friend int graph_set_mode(int mode);
00070
00071 static int sort(const void *a, const void *b)
00072 {
00073 int val1 = ((vmode *)a)->w;
00074 int val2 = ((vmode *)b)->w;
00075 int rc = val2 - val1;
00076 if (rc==0)
00077 rc = ((vmode *)b)->h - ((vmode *)a)->h;
00078 if (rc==0)
00079 rc = ((vmode *)b)->refresh - ((vmode *)a)->refresh;
00080 return rc;
00081 }
00082 FGDrawBuffer *back_store;
00083 protected:
00087 struct vmode
00088 {
00089 short w,h,mode;
00090 char flag, refresh;
00091 };
00092
00093 char *name, *subname;
00094 int accel_hint;
00095 int total_modes;
00096 bool ismouse, iskeyboard, isgraph,
00097 islinear, mapped, verbose, ps2_mouse;
00098 int w,h,
00099 virt_w, virt_h,
00100 x_offset, y_offset;
00101 int req_w, req_h,
00102 pitch,
00103 mode_num,
00104 bpp;
00105 unsigned long synch;
00106 int current_buffer,
00107 bufnum;
00108 void *linear_base,
00109 *mmio_base;
00110 unsigned long linear_size,
00111 mmio_size;
00112 unsigned char *mmio;
00113 int driver;
00114 FGPixel *videobase;
00115 FGPixel *buffer[4];
00116 vmode modelist[MODELIST_SIZE];
00117 char *accel_name;
00118 unsigned ops;
00119 int root;
00120 int msefd;
00121 int oldx, oldy;
00122 int mousex, mousey, but;
00123 char *mouse_string;
00124 static bool is_ctrl, is_alt, is_shift;
00125
00126 void vram_line(int x, int y, int w, int h, FGPixel ink, unsigned ppop);
00127 virtual int find(int& ww, int& hh);
00128 int postinit();
00129 int detect(void);
00130 int preinit(void);
00131 virtual int text_mode(void)
00132 {
00133 isgraph = 0;
00134 return true;
00135 }
00136 virtual int set_mouse(void)
00137 {
00138 if (verbose) printf("DRIVER %s: set_mouse() called\n", name);
00139 ismouse = 1;
00140 return true;
00141 }
00142 virtual void reset_mouse(void)
00143 {
00144 if (verbose) printf("DRIVER %s: reset_mouse() called\n", name);
00145 ismouse = 0;
00146 }
00147 virtual int set_keyboard(void)
00148 {
00149 if (verbose) printf("DRIVER %s: set_keyboard() called\n", name);
00150 iskeyboard = 1;
00151 return true;
00152 }
00153 virtual void reset_keyboard(void)
00154 {
00155 if (verbose) printf("DRIVER %s: reset_keyboard() called\n", name);
00156 iskeyboard = 0;
00157 }
00158 virtual void get_all_modes(vmode *)
00159 {
00160 }
00161 int build_modelist(void)
00162 {
00163 total_modes = 0;
00164 get_all_modes(modelist);
00165 if ( total_modes == 0 )
00166 {
00167 printf("No video modes available for %d BPP\n", FASTGL_BPP);
00168 return 0;
00169 }
00170
00171 if (total_modes>1) qsort(modelist, total_modes, sizeof(vmode), sort);
00172 if (verbose)
00173 {
00174 printf("\nVideo modes:\n");
00175 for(int i=0; i<total_modes; i++)
00176 {
00177 if (modelist[i].w) printf("\tmode \"%dx%d-%d@%d\" available as %s\n", modelist[i].w, modelist[i].h, bpp*8, modelist[i].refresh ,modelist[i].flag&FG_LINEAR?"linear":"banked");
00178 }
00179 }
00180 return total_modes;
00181 }
00182 virtual int available(void)
00183 {
00184 if (verbose) printf("DRIVER %s: available() called\n", name);
00185 return false;
00186 }
00187 virtual int link(void)
00188 {
00189 if (verbose) printf("DRIVER %s: link() called\n", name);
00190 return false;
00191 }
00192 public:
00193 int offset;
00194 FGDriver(char *nm);
00195 virtual ~FGDriver()
00196 {
00197 if (verbose) printf("DRIVER %s: unload() called\n", name);
00198 }
00199 int launch(int ww, int hh, int syn, int verb);
00200 void message(void);
00201 virtual int get_event(int& , int& , int& , int& , int& )
00202 {
00203 return false;
00204 }
00205 virtual int set_mode(int w, int h)
00206 {
00207 if (isgraph)
00208 {
00209 back_store = new FGDrawBuffer(w, h);
00210 get_block(0,0, w, h, back_store->GetArray());
00211 }
00212 return true;
00213 }
00214 virtual void change_mouse(void)
00215 {
00216 if (verbose) printf("DRIVER %s: change_mouse() called\n", name);
00217 }
00218 virtual void shutdown(void)
00219 {
00220 if (ismouse) reset_mouse();
00221 if (iskeyboard) reset_keyboard();
00222 text_mode();
00223 }
00224 void SetVerbose(int v) { verbose = !!v; }
00225 void SetFrequency(int v) { synch = v; }
00226
00227 virtual void SetCaption(char *)
00228 {
00229 }
00230
00231 virtual int EnableBuffering(int mode);
00232 virtual void DisableBuffering(void)
00233 {
00234 set_page(current_buffer=0);
00235 fgl::videobase = videobase = buffer[0];
00236 offset = 0;
00237 }
00238
00239 virtual int set_page(int)
00240 {
00241 return 0;
00242 }
00243 virtual int Flip(void);
00244 virtual int set_virtual_size(int , int )
00245 {
00246 return 0;
00247 }
00248 virtual int set_virtual_pos(int , int )
00249 {
00250 return 0;
00251 }
00252 int GetBuffersNum(void)
00253 {
00254 return bufnum;
00255 }
00256 #ifdef INDEX_COLORS
00257 void ReservedColors(void);
00258 #endif
00259 int GetW(void) const { return w; }
00260 int GetH(void) const { return h; }
00261 virtual void UpdateRect(int x, int y, int xm, int ym, int w, int h) { }
00262 int GetPriv(void) const { return root; }
00263
00264 static void SetShiftState(bool pressed) { is_shift = pressed; }
00265 static void SetControlState(bool pressed) { is_ctrl = pressed; }
00266 static void SetAltState(bool pressed) { is_alt = pressed; }
00267 };
00268
00269 #ifdef FG_NAMESPACE
00270 }
00271 #endif
00272