1 /////////////////////////////////////////////////////////////////////////
2 // $Id: vga.h,v 1.62 2008/09/18 20:10:17 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
5 // Copyright (C) 2002 MandrakeSoft S.A.
9 // 75002 Paris - France
10 // http://www.linux-mandrake.com/
11 // http://www.mandrakesoft.com/
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #ifndef BX_IODEV_VGA_H
28 #define BX_IODEV_VGA_H
31 #define MAKE_COLOUR(red, red_shiftfrom, red_shiftto, red_mask, \
32 green, green_shiftfrom, green_shiftto, green_mask, \
33 blue, blue_shiftfrom, blue_shiftto, blue_mask) \
35 ((((red_shiftto) > (red_shiftfrom)) ? \
36 (red) << ((red_shiftto) - (red_shiftfrom)) : \
37 (red) >> ((red_shiftfrom) - (red_shiftto))) & \
39 ((((green_shiftto) > (green_shiftfrom)) ? \
40 (green) << ((green_shiftto) - (green_shiftfrom)) : \
41 (green) >> ((green_shiftfrom) - (green_shiftto))) & \
43 ((((blue_shiftto) > (blue_shiftfrom)) ? \
44 (blue) << ((blue_shiftto) - (blue_shiftfrom)) : \
45 (blue) >> ((blue_shiftfrom) - (blue_shiftto))) & \
50 #define VBE_DISPI_TOTAL_VIDEO_MEMORY_MB 8
51 #define VBE_DISPI_4BPP_PLANE_SHIFT 21
53 #define VBE_DISPI_BANK_ADDRESS 0xA0000
54 #define VBE_DISPI_BANK_SIZE_KB 64
56 #define VBE_DISPI_MAX_XRES 1600
57 #define VBE_DISPI_MAX_YRES 1200
58 #define VBE_DISPI_MAX_BPP 32
60 #define VBE_DISPI_IOPORT_INDEX 0x01CE
61 #define VBE_DISPI_IOPORT_DATA 0x01CF
63 #define VBE_DISPI_IOPORT_INDEX_OLD 0xFF80
64 #define VBE_DISPI_IOPORT_DATA_OLD 0xFF81
66 #define VBE_DISPI_INDEX_ID 0x0
67 #define VBE_DISPI_INDEX_XRES 0x1
68 #define VBE_DISPI_INDEX_YRES 0x2
69 #define VBE_DISPI_INDEX_BPP 0x3
70 #define VBE_DISPI_INDEX_ENABLE 0x4
71 #define VBE_DISPI_INDEX_BANK 0x5
72 #define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
73 #define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
74 #define VBE_DISPI_INDEX_X_OFFSET 0x8
75 #define VBE_DISPI_INDEX_Y_OFFSET 0x9
77 #define VBE_DISPI_ID0 0xB0C0
78 #define VBE_DISPI_ID1 0xB0C1
79 #define VBE_DISPI_ID2 0xB0C2
80 #define VBE_DISPI_ID3 0xB0C3
81 #define VBE_DISPI_ID4 0xB0C4
83 #define VBE_DISPI_BPP_4 0x04
84 #define VBE_DISPI_BPP_8 0x08
85 #define VBE_DISPI_BPP_15 0x0F
86 #define VBE_DISPI_BPP_16 0x10
87 #define VBE_DISPI_BPP_24 0x18
88 #define VBE_DISPI_BPP_32 0x20
90 #define VBE_DISPI_DISABLED 0x00
91 #define VBE_DISPI_ENABLED 0x01
92 #define VBE_DISPI_GETCAPS 0x02
93 #define VBE_DISPI_8BIT_DAC 0x20
94 #define VBE_DISPI_LFB_ENABLED 0x40
95 #define VBE_DISPI_NOCLEARMEM 0x80
97 #define VBE_DISPI_LFB_PHYSICAL_ADDRESS 0xE0000000
99 #define VBE_DISPI_TOTAL_VIDEO_MEMORY_KB (VBE_DISPI_TOTAL_VIDEO_MEMORY_MB * 1024)
100 #define VBE_DISPI_TOTAL_VIDEO_MEMORY_BYTES (VBE_DISPI_TOTAL_VIDEO_MEMORY_KB * 1024)
102 #define BX_MAX_XRES VBE_DISPI_MAX_XRES
103 #define BX_MAX_YRES VBE_DISPI_MAX_YRES
105 #elif BX_SUPPORT_CLGD54XX
107 #define BX_MAX_XRES 1280
108 #define BX_MAX_YRES 1024
112 #define BX_MAX_XRES 800
113 #define BX_MAX_YRES 600
115 #endif // BX_SUPPORT_VBE
117 #define X_TILESIZE 16
118 #define Y_TILESIZE 24
119 #define BX_NUM_X_TILES (BX_MAX_XRES /X_TILESIZE)
120 #define BX_NUM_Y_TILES (BX_MAX_YRES /Y_TILESIZE)
122 // Support varying number of rows of text. This used to
123 // be limited to only 25 lines.
124 #define BX_MAX_TEXT_LINES 100
127 # define BX_VGA_SMF static
128 # define BX_VGA_THIS theVga->
131 # define BX_VGA_THIS this->
134 class bx_vga_c
: public bx_vga_stub_c
{
138 virtual void init(void);
139 virtual void reset(unsigned type
);
140 BX_VGA_SMF bx_bool
mem_read_handler(bx_phy_address addr
, unsigned len
, void *data
, void *param
);
141 BX_VGA_SMF bx_bool
mem_write_handler(bx_phy_address addr
, unsigned len
, void *data
, void *param
);
142 virtual Bit8u
mem_read(bx_phy_address addr
);
143 virtual void mem_write(bx_phy_address addr
, Bit8u value
);
144 virtual void trigger_timer(void *this_ptr
);
145 virtual void dump_status(void);
146 virtual void register_state(void);
147 virtual void after_restore_state(void);
150 BX_VGA_SMF Bit8u
vbe_mem_read(bx_phy_address addr
) BX_CPP_AttrRegparmN(1);
151 BX_VGA_SMF
void vbe_mem_write(bx_phy_address addr
, Bit8u value
) BX_CPP_AttrRegparmN(2);
154 virtual void redraw_area(unsigned x0
, unsigned y0
,
155 unsigned width
, unsigned height
);
157 virtual void get_text_snapshot(Bit8u
**text_snapshot
, unsigned *txHeight
,
159 virtual Bit8u
get_actl_palette_idx(Bit8u index
);
162 void init_iohandlers(bx_read_handler_t f_read
, bx_write_handler_t f_write
);
163 void init_systemtimer(bx_timer_handler_t f_timer
, param_event_handler f_param
);
165 static Bit32u
read_handler(void *this_ptr
, Bit32u address
, unsigned io_len
);
166 static void write_handler(void *this_ptr
, Bit32u address
, Bit32u value
, unsigned io_len
);
168 static void write_handler_no_log(void *this_ptr
, Bit32u address
, Bit32u value
, unsigned io_len
);
172 static Bit32u
vbe_read_handler(void *this_ptr
, Bit32u address
, unsigned io_len
);
173 static void vbe_write_handler(void *this_ptr
, Bit32u address
, Bit32u value
, unsigned io_len
);
178 bx_bool color_emulation
; // 1=color emulation, base address = 3Dx
179 // 0=mono emulation, base address = 3Bx
180 bx_bool enable_ram
; // enable CPU access to video memory if set
181 Bit8u clock_select
; // 0=25Mhz 1=28Mhz
182 bx_bool select_high_bank
; // when in odd/even modes, select
183 // high 64k bank if set
184 bx_bool horiz_sync_pol
; // bit6: negative if set
185 bx_bool vert_sync_pol
; // bit7: negative if set
186 // bit7,bit6 represent number of lines on display:
196 bx_bool write_protect
;
200 bx_bool flip_flop
; /* 0 = address, 1 = data-write */
201 unsigned address
; /* register number */
202 bx_bool video_enabled
;
203 Bit8u palette_reg
[16];
204 Bit8u overscan_color
;
205 Bit8u color_plane_enable
;
206 Bit8u horiz_pel_panning
;
209 bx_bool graphics_alpha
;
210 bx_bool display_type
;
211 bx_bool enable_line_graphics
;
212 bx_bool blink_intensity
;
213 bx_bool pixel_panning_compat
;
214 bx_bool pixel_clock_select
;
215 bx_bool internal_palette_size
;
220 Bit8u write_data_register
;
221 Bit8u write_data_cycle
; /* 0, 1, 2 */
222 Bit8u read_data_register
;
223 Bit8u read_data_cycle
; /* 0, 1, 2 */
236 Bit8u enable_set_reset
;
240 Bit8u read_map_select
;
244 bx_bool chain_odd_even
;
246 bx_bool graphics_alpha
;
247 Bit8u memory_mapping
; /* 0 = use A0000-BFFFF
248 * 1 = use A0000-AFFFF EGA/VGA graphics modes
249 * 2 = use B0000-B7FFF Monochrome modes
250 * 3 = use B8000-BFFFF CGA modes
252 Bit8u color_dont_care
;
263 Bit8u char_map_select
;
264 bx_bool extended_mem
;
270 bx_bool vga_mem_updated
;
273 unsigned line_offset
;
274 unsigned line_compare
;
275 unsigned vertical_display_end
;
276 unsigned blink_counter
;
277 bx_bool vga_tile_updated
[BX_NUM_X_TILES
][BX_NUM_Y_TILES
];
280 Bit8u text_snapshot
[128 * 1024]; // current text snapshot
281 Bit8u tile
[X_TILESIZE
* Y_TILESIZE
* 4]; /**< Currently allocates the tile as large as needed. */
282 Bit16u charmap_address
;
283 bx_bool x_dotclockdiv2
;
284 bx_bool y_doublescan
;
288 Bit16u vbe_cur_dispi
;
298 Bit32u vbe_visible_screen_size
; /**< in bytes */
299 Bit16u vbe_offset_x
; /**< Virtual screen x start (in pixels) */
300 Bit16u vbe_offset_y
; /**< Virtual screen y start (in pixels) */
301 Bit16u vbe_virtual_xres
;
302 Bit16u vbe_virtual_yres
;
303 Bit32u vbe_virtual_start
; /**< For dealing with bpp>8, this is where the virtual screen starts. */
304 Bit8u vbe_bpp_multiplier
; /**< We have to save this b/c sometimes we need to recalculate stuff with it. */
305 bx_bool vbe_lfb_enabled
;
306 bx_bool vbe_get_capabilities
;
307 bx_bool vbe_8bit_dac
;
309 } s
; // state information
312 #if BX_USE_VGA_SMF == 0
313 Bit32u
read(Bit32u address
, unsigned io_len
);
315 void write(Bit32u address
, Bit32u value
, unsigned io_len
, bx_bool no_log
);
319 #if BX_USE_VGA_SMF == 0
320 Bit32u
vbe_read(Bit32u address
, unsigned io_len
);
321 void vbe_write(Bit32u address
, Bit32u value
, unsigned io_len
, bx_bool no_log
);
324 #endif // BX_SUPPORT_VBE
327 bx_bool extension_init
;
328 bx_bool extension_checked
;
331 static void timer_handler(void *);
332 #if BX_USE_VGA_SMF == 0
333 BX_VGA_SMF
void timer(void);
335 static Bit64s
vga_param_handler(bx_param_c
*param
, int set
, Bit64s val
);
338 BX_VGA_SMF
void update(void);
339 BX_VGA_SMF
void determine_screen_dimensions(unsigned *piHeight
, unsigned *piWidth
);
342 #if BX_SUPPORT_CLGD54XX
343 void libvga_set_smf_pointer(bx_vga_c
*theVga_ptr
);
344 #include "iodev/svga_cirrus.h"