| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#ifndef DOSBOX_VGA_H |
| 22 |
#define DOSBOX_VGA_H |
| 23 |
|
| 24 |
#ifndef DOSBOX_DOSBOX_H |
| 25 |
#include "dosbox.h" |
| 26 |
#endif |
| 27 |
|
| 28 |
|
| 29 |
#define VGA_LFB_MAPPED |
| 30 |
|
| 31 |
#define VGA_CHANGE_SHIFT 9 |
| 32 |
|
| 33 |
class PageHandler; |
| 34 |
|
| 35 |
|
| 36 |
enum VGAModes { |
| 37 |
M_CGA2, M_CGA4, |
| 38 |
M_EGA, M_VGA, |
| 39 |
M_LIN4, M_LIN8, M_LIN15, M_LIN16, M_LIN32, |
| 40 |
M_TEXT, |
| 41 |
M_HERC_GFX, M_HERC_TEXT, |
| 42 |
M_CGA16, M_TANDY2, M_TANDY4, M_TANDY16, M_TANDY_TEXT, |
| 43 |
M_ERROR |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
#define CLK_25 25175 |
| 48 |
#define CLK_28 28322 |
| 49 |
|
| 50 |
#define MIN_VCO 180000 |
| 51 |
#define MAX_VCO 360000 |
| 52 |
|
| 53 |
#define S3_CLOCK_REF 14318 |
| 54 |
#define S3_CLOCK(_M,_N,_R) ((S3_CLOCK_REF * ((_M) + 2)) / (((_N) + 2) * (1 << (_R)))) |
| 55 |
#define S3_MAX_CLOCK 150000 |
| 56 |
|
| 57 |
#define S3_XGA_1024 0x00 |
| 58 |
#define S3_XGA_1152 0x01 |
| 59 |
#define S3_XGA_640 0x40 |
| 60 |
#define S3_XGA_800 0x80 |
| 61 |
#define S3_XGA_1280 0xc0 |
| 62 |
#define S3_XGA_WMASK (S3_XGA_640|S3_XGA_800|S3_XGA_1024|S3_XGA_1152|S3_XGA_1280) |
| 63 |
|
| 64 |
#define S3_XGA_8BPP 0x00 |
| 65 |
#define S3_XGA_16BPP 0x10 |
| 66 |
#define S3_XGA_32BPP 0x30 |
| 67 |
#define S3_XGA_CMASK (S3_XGA_8BPP|S3_XGA_16BPP|S3_XGA_32BPP) |
| 68 |
|
| 69 |
typedef struct { |
| 70 |
bool attrindex; |
| 71 |
} VGA_Internal; |
| 72 |
|
| 73 |
typedef struct { |
| 74 |
|
| 75 |
Bitu mh_mask; |
| 76 |
|
| 77 |
|
| 78 |
Bitu display_start; |
| 79 |
Bitu real_start; |
| 80 |
bool retrace; |
| 81 |
Bitu scan_len; |
| 82 |
Bitu cursor_start; |
| 83 |
|
| 84 |
|
| 85 |
Bitu line_compare; |
| 86 |
bool chained; |
| 87 |
bool compatible_chain4; |
| 88 |
|
| 89 |
|
| 90 |
Bit8u pel_panning; |
| 91 |
Bit8u hlines_skip; |
| 92 |
Bit8u bytes_skip; |
| 93 |
Bit8u addr_shift; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
Bit8u read_mode; |
| 98 |
Bit8u write_mode; |
| 99 |
Bit8u read_map_select; |
| 100 |
Bit8u color_dont_care; |
| 101 |
Bit8u color_compare; |
| 102 |
Bit8u data_rotate; |
| 103 |
Bit8u raster_op; |
| 104 |
|
| 105 |
Bit32u full_bit_mask; |
| 106 |
Bit32u full_map_mask; |
| 107 |
Bit32u full_not_map_mask; |
| 108 |
Bit32u full_set_reset; |
| 109 |
Bit32u full_not_enable_set_reset; |
| 110 |
Bit32u full_enable_set_reset; |
| 111 |
Bit32u full_enable_and_set_reset; |
| 112 |
} VGA_Config; |
| 113 |
|
| 114 |
typedef enum { |
| 115 |
PART, |
| 116 |
DRAWLINE, |
| 117 |
|
| 118 |
} Drawmode; |
| 119 |
|
| 120 |
typedef struct { |
| 121 |
bool resizing; |
| 122 |
Bitu width; |
| 123 |
Bitu height; |
| 124 |
Bitu blocks; |
| 125 |
Bitu address; |
| 126 |
Bitu panning; |
| 127 |
Bitu bytes_skip; |
| 128 |
Bit8u *linear_base; |
| 129 |
Bitu linear_mask; |
| 130 |
Bitu address_add; |
| 131 |
Bitu line_length; |
| 132 |
Bitu address_line_total; |
| 133 |
Bitu address_line; |
| 134 |
Bitu lines_total; |
| 135 |
Bitu vblank_skip; |
| 136 |
Bitu lines_done; |
| 137 |
Bitu lines_scaled; |
| 138 |
Bitu split_line; |
| 139 |
Bitu parts_total; |
| 140 |
Bitu parts_lines; |
| 141 |
Bitu parts_left; |
| 142 |
Bitu byte_panning_shift; |
| 143 |
struct { |
| 144 |
double framestart; |
| 145 |
double vrstart, vrend; |
| 146 |
double hrstart, hrend; |
| 147 |
double hblkstart, hblkend; |
| 148 |
double vblkstart, vblkend; |
| 149 |
double vdend, vtotal; |
| 150 |
double hdend, htotal; |
| 151 |
double parts; |
| 152 |
} delay; |
| 153 |
Bitu bpp; |
| 154 |
double aspect_ratio; |
| 155 |
bool double_scan; |
| 156 |
bool doublewidth,doubleheight; |
| 157 |
Bit8u font[64*1024]; |
| 158 |
Bit8u * font_tables[2]; |
| 159 |
Bitu blinking; |
| 160 |
struct { |
| 161 |
Bitu address; |
| 162 |
Bit8u sline,eline; |
| 163 |
Bit8u count,delay; |
| 164 |
Bit8u enabled; |
| 165 |
} cursor; |
| 166 |
Drawmode mode; |
| 167 |
bool vret_triggered; |
| 168 |
} VGA_Draw; |
| 169 |
|
| 170 |
typedef struct { |
| 171 |
Bit8u curmode; |
| 172 |
Bit16u originx, originy; |
| 173 |
Bit8u fstackpos, bstackpos; |
| 174 |
Bit8u forestack[4]; |
| 175 |
Bit8u backstack[4]; |
| 176 |
Bit16u startaddr; |
| 177 |
Bit8u posx, posy; |
| 178 |
Bit8u mc[64][64]; |
| 179 |
} VGA_HWCURSOR; |
| 180 |
|
| 181 |
typedef struct { |
| 182 |
Bit8u reg_lock1; |
| 183 |
Bit8u reg_lock2; |
| 184 |
Bit8u reg_31; |
| 185 |
Bit8u reg_35; |
| 186 |
Bit8u reg_36; |
| 187 |
Bit8u reg_3a; |
| 188 |
Bit8u reg_40; |
| 189 |
Bit8u reg_41; |
| 190 |
Bit8u reg_43; |
| 191 |
Bit8u reg_45; |
| 192 |
Bit8u reg_50; |
| 193 |
Bit8u reg_51; |
| 194 |
Bit8u reg_52; |
| 195 |
Bit8u reg_55; |
| 196 |
Bit8u reg_58; |
| 197 |
Bit8u reg_6b; |
| 198 |
Bit8u ex_hor_overflow; |
| 199 |
Bit8u ex_ver_overflow; |
| 200 |
Bit16u la_window; |
| 201 |
Bit8u misc_control_2; |
| 202 |
Bit8u ext_mem_ctrl; |
| 203 |
Bitu xga_screen_width; |
| 204 |
VGAModes xga_color_mode; |
| 205 |
struct { |
| 206 |
Bit8u r; |
| 207 |
Bit8u n; |
| 208 |
Bit8u m; |
| 209 |
} clk[4],mclk; |
| 210 |
struct { |
| 211 |
Bit8u lock; |
| 212 |
Bit8u cmd; |
| 213 |
} pll; |
| 214 |
VGA_HWCURSOR hgc; |
| 215 |
} VGA_S3; |
| 216 |
|
| 217 |
typedef struct { |
| 218 |
Bit8u mode_control; |
| 219 |
Bit8u enable_bits; |
| 220 |
} VGA_HERC; |
| 221 |
|
| 222 |
typedef struct { |
| 223 |
Bit8u index; |
| 224 |
Bit8u htotal; |
| 225 |
Bit8u hdend; |
| 226 |
Bit8u hsyncp; |
| 227 |
Bit8u hsyncw; |
| 228 |
Bit8u vtotal; |
| 229 |
Bit8u vdend; |
| 230 |
Bit8u vadjust; |
| 231 |
Bit8u vsyncp; |
| 232 |
Bit8u vsyncw; |
| 233 |
Bit8u max_scanline; |
| 234 |
Bit16u lightpen; |
| 235 |
bool lightpen_triggered; |
| 236 |
Bit8u cursor_start; |
| 237 |
Bit8u cursor_end; |
| 238 |
} VGA_OTHER; |
| 239 |
|
| 240 |
typedef struct { |
| 241 |
Bit8u pcjr_flipflop; |
| 242 |
Bit8u mode_control; |
| 243 |
Bit8u color_select; |
| 244 |
Bit8u disp_bank; |
| 245 |
Bit8u reg_index; |
| 246 |
Bit8u gfx_control; |
| 247 |
Bit8u palette_mask; |
| 248 |
Bit8u extended_ram; |
| 249 |
Bit8u border_color; |
| 250 |
Bit8u line_mask, line_shift; |
| 251 |
Bit8u draw_bank, mem_bank; |
| 252 |
Bit8u *draw_base, *mem_base; |
| 253 |
Bitu addr_mask; |
| 254 |
} VGA_TANDY; |
| 255 |
|
| 256 |
typedef struct { |
| 257 |
Bit8u index; |
| 258 |
Bit8u reset; |
| 259 |
Bit8u clocking_mode; |
| 260 |
Bit8u map_mask; |
| 261 |
Bit8u character_map_select; |
| 262 |
Bit8u memory_mode; |
| 263 |
} VGA_Seq; |
| 264 |
|
| 265 |
typedef struct { |
| 266 |
Bit8u palette[16]; |
| 267 |
Bit8u mode_control; |
| 268 |
Bit8u horizontal_pel_panning; |
| 269 |
Bit8u overscan_color; |
| 270 |
Bit8u color_plane_enable; |
| 271 |
Bit8u color_select; |
| 272 |
Bit8u index; |
| 273 |
Bit8u disabled; |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
} VGA_Attr; |
| 280 |
|
| 281 |
typedef struct { |
| 282 |
Bit8u horizontal_total; |
| 283 |
Bit8u horizontal_display_end; |
| 284 |
Bit8u start_horizontal_blanking; |
| 285 |
Bit8u end_horizontal_blanking; |
| 286 |
Bit8u start_horizontal_retrace; |
| 287 |
Bit8u end_horizontal_retrace; |
| 288 |
Bit8u vertical_total; |
| 289 |
Bit8u overflow; |
| 290 |
Bit8u preset_row_scan; |
| 291 |
Bit8u maximum_scan_line; |
| 292 |
Bit8u cursor_start; |
| 293 |
Bit8u cursor_end; |
| 294 |
Bit8u start_address_high; |
| 295 |
Bit8u start_address_low; |
| 296 |
Bit8u cursor_location_high; |
| 297 |
Bit8u cursor_location_low; |
| 298 |
Bit8u vertical_retrace_start; |
| 299 |
Bit8u vertical_retrace_end; |
| 300 |
Bit8u vertical_display_end; |
| 301 |
Bit8u offset; |
| 302 |
Bit8u underline_location; |
| 303 |
Bit8u start_vertical_blanking; |
| 304 |
Bit8u end_vertical_blanking; |
| 305 |
Bit8u mode_control; |
| 306 |
Bit8u line_compare; |
| 307 |
|
| 308 |
Bit8u index; |
| 309 |
bool read_only; |
| 310 |
} VGA_Crtc; |
| 311 |
|
| 312 |
typedef struct { |
| 313 |
Bit8u index; |
| 314 |
Bit8u set_reset; |
| 315 |
Bit8u enable_set_reset; |
| 316 |
Bit8u color_compare; |
| 317 |
Bit8u data_rotate; |
| 318 |
Bit8u read_map_select; |
| 319 |
Bit8u mode; |
| 320 |
Bit8u miscellaneous; |
| 321 |
Bit8u color_dont_care; |
| 322 |
Bit8u bit_mask; |
| 323 |
} VGA_Gfx; |
| 324 |
|
| 325 |
typedef struct { |
| 326 |
Bit8u red; |
| 327 |
Bit8u green; |
| 328 |
Bit8u blue; |
| 329 |
} RGBEntry; |
| 330 |
|
| 331 |
typedef struct { |
| 332 |
Bit8u bits; |
| 333 |
Bit8u pel_mask; |
| 334 |
Bit8u pel_index; |
| 335 |
Bit8u state; |
| 336 |
Bit8u write_index; |
| 337 |
Bit8u read_index; |
| 338 |
Bitu first_changed; |
| 339 |
Bit8u combine[16]; |
| 340 |
RGBEntry rgb[0x100]; |
| 341 |
Bit16u xlat16[256]; |
| 342 |
} VGA_Dac; |
| 343 |
|
| 344 |
typedef struct { |
| 345 |
Bitu readStart, writeStart; |
| 346 |
Bitu bankMask; |
| 347 |
Bitu bank_read_full; |
| 348 |
Bitu bank_write_full; |
| 349 |
Bit8u bank_read; |
| 350 |
Bit8u bank_write; |
| 351 |
Bitu bank_size; |
| 352 |
} VGA_SVGA; |
| 353 |
|
| 354 |
typedef union { |
| 355 |
Bit32u d; |
| 356 |
Bit8u b[4]; |
| 357 |
} VGA_Latch; |
| 358 |
|
| 359 |
typedef struct { |
| 360 |
Bit8u* linear; |
| 361 |
Bit8u* linear_orgptr; |
| 362 |
} VGA_Memory; |
| 363 |
|
| 364 |
typedef struct { |
| 365 |
|
| 366 |
Bit8u* map; |
| 367 |
Bit8u checkMask, frame, writeMask; |
| 368 |
bool active; |
| 369 |
Bit32u clearMask; |
| 370 |
Bit32u start, last; |
| 371 |
Bit32u lastAddress; |
| 372 |
} VGA_Changes; |
| 373 |
|
| 374 |
typedef struct { |
| 375 |
Bit32u page; |
| 376 |
Bit32u addr; |
| 377 |
Bit32u mask; |
| 378 |
PageHandler *handler; |
| 379 |
} VGA_LFB; |
| 380 |
|
| 381 |
typedef struct { |
| 382 |
VGAModes mode; |
| 383 |
Bit8u misc_output; |
| 384 |
VGA_Draw draw; |
| 385 |
VGA_Config config; |
| 386 |
VGA_Internal internal; |
| 387 |
|
| 388 |
VGA_Seq seq; |
| 389 |
VGA_Attr attr; |
| 390 |
VGA_Crtc crtc; |
| 391 |
VGA_Gfx gfx; |
| 392 |
VGA_Dac dac; |
| 393 |
VGA_Latch latch; |
| 394 |
VGA_S3 s3; |
| 395 |
VGA_SVGA svga; |
| 396 |
VGA_HERC herc; |
| 397 |
VGA_TANDY tandy; |
| 398 |
VGA_OTHER other; |
| 399 |
VGA_Memory mem; |
| 400 |
Bit32u vmemwrap; |
| 401 |
Bit8u* fastmem; |
| 402 |
Bit8u* fastmem_orgptr; |
| 403 |
Bit32u vmemsize; |
| 404 |
#ifdef VGA_KEEP_CHANGES |
| 405 |
VGA_Changes changes; |
| 406 |
#endif |
| 407 |
VGA_LFB lfb; |
| 408 |
} VGA_Type; |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
void Herc_Palette(void); |
| 413 |
|
| 414 |
|
| 415 |
void VGA_SetMode(VGAModes mode); |
| 416 |
void VGA_DetermineMode(void); |
| 417 |
void VGA_SetupHandlers(void); |
| 418 |
void VGA_StartResize(Bitu delay=50); |
| 419 |
void VGA_SetupDrawing(Bitu val); |
| 420 |
void VGA_CheckScanLength(void); |
| 421 |
void VGA_ChangedBank(void); |
| 422 |
|
| 423 |
|
| 424 |
void VGA_DAC_CombineColor(Bit8u attr,Bit8u pal); |
| 425 |
void VGA_DAC_SetEntry(Bitu entry,Bit8u red,Bit8u green,Bit8u blue); |
| 426 |
void VGA_ATTR_SetPalette(Bit8u index,Bit8u val); |
| 427 |
|
| 428 |
|
| 429 |
void VGA_SetupAttr(void); |
| 430 |
void VGA_SetupMemory(Section* sec); |
| 431 |
void VGA_SetupDAC(void); |
| 432 |
void VGA_SetupCRTC(void); |
| 433 |
void VGA_SetupMisc(void); |
| 434 |
void VGA_SetupGFX(void); |
| 435 |
void VGA_SetupSEQ(void); |
| 436 |
void VGA_SetupOther(void); |
| 437 |
void VGA_SetupXGA(void); |
| 438 |
|
| 439 |
|
| 440 |
void VGA_SetClock(Bitu which,Bitu target); |
| 441 |
void VGA_DACSetEntirePalette(void); |
| 442 |
void VGA_StartRetrace(void); |
| 443 |
void VGA_StartUpdateLFB(void); |
| 444 |
void VGA_SetBlinking(Bitu enabled); |
| 445 |
void VGA_SetCGA2Table(Bit8u val0,Bit8u val1); |
| 446 |
void VGA_SetCGA4Table(Bit8u val0,Bit8u val1,Bit8u val2,Bit8u val3); |
| 447 |
void VGA_ActivateHardwareCursor(void); |
| 448 |
void VGA_KillDrawing(void); |
| 449 |
|
| 450 |
extern VGA_Type vga; |
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
typedef struct { |
| 464 |
Bit8u ver_overflow; |
| 465 |
Bit8u hor_overflow; |
| 466 |
Bitu offset; |
| 467 |
Bitu modeNo; |
| 468 |
Bitu htotal; |
| 469 |
Bitu vtotal; |
| 470 |
} VGA_ModeExtraData; |
| 471 |
|
| 472 |
|
| 473 |
typedef void (*tWritePort)(Bitu reg,Bitu val,Bitu iolen); |
| 474 |
typedef Bitu (*tReadPort)(Bitu reg,Bitu iolen); |
| 475 |
typedef void (*tFinishSetMode)(Bitu crtc_base, VGA_ModeExtraData* modeData); |
| 476 |
typedef void (*tDetermineMode)(); |
| 477 |
typedef void (*tSetClock)(Bitu which,Bitu target); |
| 478 |
typedef Bitu (*tGetClock)(); |
| 479 |
typedef bool (*tHWCursorActive)(); |
| 480 |
typedef bool (*tAcceptsMode)(Bitu modeNo); |
| 481 |
|
| 482 |
struct SVGA_Driver { |
| 483 |
tWritePort write_p3d5; |
| 484 |
tReadPort read_p3d5; |
| 485 |
tWritePort write_p3c5; |
| 486 |
tReadPort read_p3c5; |
| 487 |
tWritePort write_p3c0; |
| 488 |
tReadPort read_p3c1; |
| 489 |
tWritePort write_p3cf; |
| 490 |
tReadPort read_p3cf; |
| 491 |
|
| 492 |
tFinishSetMode set_video_mode; |
| 493 |
tDetermineMode determine_mode; |
| 494 |
tSetClock set_clock; |
| 495 |
tGetClock get_clock; |
| 496 |
tHWCursorActive hardware_cursor_active; |
| 497 |
tAcceptsMode accepts_mode; |
| 498 |
}; |
| 499 |
|
| 500 |
extern SVGA_Driver svga; |
| 501 |
|
| 502 |
void SVGA_Setup_S3Trio(void); |
| 503 |
void SVGA_Setup_TsengET4K(void); |
| 504 |
void SVGA_Setup_TsengET3K(void); |
| 505 |
void SVGA_Setup_ParadisePVGA1A(void); |
| 506 |
void SVGA_Setup_Driver(void); |
| 507 |
|
| 508 |
|
| 509 |
Bitu VideoModeMemSize(Bitu mode); |
| 510 |
|
| 511 |
extern Bit32u ExpandTable[256]; |
| 512 |
extern Bit32u FillTable[16]; |
| 513 |
extern Bit32u CGA_2_Table[16]; |
| 514 |
extern Bit32u CGA_4_Table[256]; |
| 515 |
extern Bit32u CGA_4_HiRes_Table[256]; |
| 516 |
extern Bit32u CGA_16_Table[256]; |
| 517 |
extern Bit32u TXT_Font_Table[16]; |
| 518 |
extern Bit32u TXT_FG_Table[16]; |
| 519 |
extern Bit32u TXT_BG_Table[16]; |
| 520 |
extern Bit32u Expand16Table[4][16]; |
| 521 |
extern Bit32u Expand16BigTable[0x10000]; |
| 522 |
|
| 523 |
|
| 524 |
#endif |