DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/ints/int10.h
00001 /*
00002  *  Copyright (C) 2002-2020  The DOSBox Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License along
00015  *  with this program; if not, write to the Free Software Foundation, Inc.,
00016  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 
00020 #include "vga.h"
00021 
00022 extern uint32_t S3_LFB_BASE;
00023 
00024 #define BIOSMEM_SEG             0x40u
00025 
00026 #define BIOSMEM_INITIAL_MODE  0x10u
00027 #define BIOSMEM_CURRENT_MODE  0x49u
00028 #define BIOSMEM_NB_COLS       0x4Au
00029 #define BIOSMEM_PAGE_SIZE     0x4Cu
00030 #define BIOSMEM_CURRENT_START 0x4Eu
00031 #define BIOSMEM_CURSOR_POS    0x50u
00032 #define BIOSMEM_CURSOR_TYPE   0x60u
00033 #define BIOSMEM_CURRENT_PAGE  0x62u
00034 #define BIOSMEM_CRTC_ADDRESS  0x63u
00035 #define BIOSMEM_CURRENT_MSR   0x65u
00036 #define BIOSMEM_CURRENT_PAL   0x66u
00037 #define BIOSMEM_NB_ROWS       0x84u
00038 #define BIOSMEM_CHAR_HEIGHT   0x85u
00039 #define BIOSMEM_VIDEO_CTL     0x87u
00040 #define BIOSMEM_SWITCHES      0x88u
00041 #define BIOSMEM_MODESET_CTL   0x89u
00042 #define BIOSMEM_DCC_INDEX     0x8Au
00043 #define BIOSMEM_CRTCPU_PAGE   0x8Au
00044 #define BIOSMEM_VS_POINTER    0xA8u
00045 
00046 
00047 /*
00048  *
00049  * VGA registers
00050  *
00051  */
00052 #define VGAREG_ACTL_ADDRESS            0x3c0u
00053 #define VGAREG_ACTL_WRITE_DATA         0x3c0u
00054 #define VGAREG_ACTL_READ_DATA          0x3c1u
00055 
00056 #define VGAREG_INPUT_STATUS            0x3c2u
00057 #define VGAREG_WRITE_MISC_OUTPUT       0x3c2u
00058 #define VGAREG_VIDEO_ENABLE            0x3c3u
00059 #define VGAREG_SEQU_ADDRESS            0x3c4u
00060 #define VGAREG_SEQU_DATA               0x3c5u
00061 
00062 #define VGAREG_PEL_MASK                0x3c6u
00063 #define VGAREG_DAC_STATE               0x3c7u
00064 #define VGAREG_DAC_READ_ADDRESS        0x3c7u
00065 #define VGAREG_DAC_WRITE_ADDRESS       0x3c8u
00066 #define VGAREG_DAC_DATA                0x3c9u
00067 
00068 #define VGAREG_READ_FEATURE_CTL        0x3cau
00069 #define VGAREG_READ_MISC_OUTPUT        0x3ccu
00070 
00071 #define VGAREG_GRDC_ADDRESS            0x3ceu
00072 #define VGAREG_GRDC_DATA               0x3cfu
00073 
00074 #define VGAREG_MDA_CRTC_ADDRESS        0x3b4u
00075 #define VGAREG_MDA_CRTC_DATA           0x3b5u
00076 #define VGAREG_VGA_CRTC_ADDRESS        0x3d4u
00077 #define VGAREG_VGA_CRTC_DATA           0x3d5u
00078 
00079 #define VGAREG_MDA_WRITE_FEATURE_CTL   0x3bau
00080 #define VGAREG_VGA_WRITE_FEATURE_CTL   0x3dau
00081 #define VGAREG_ACTL_RESET              0x3dau
00082 #define VGAREG_TDY_RESET               0x3dau
00083 #define VGAREG_TDY_ADDRESS             0x3dau
00084 #define VGAREG_TDY_DATA                0x3deu
00085 #define VGAREG_PCJR_DATA               0x3dau
00086 
00087 #define VGAREG_MDA_MODECTL             0x3b8u
00088 #define VGAREG_CGA_MODECTL             0x3d8u
00089 #define VGAREG_CGA_PALETTE             0x3d9u
00090 
00091 /* Video memory */
00092 #define VGAMEM_GRAPH 0xA000u
00093 #define VGAMEM_CTEXT 0xB800u
00094 #define VGAMEM_MTEXT 0xB000u
00095 
00096 /* FIXME: Wait, what?? What the hell kind of preprocessor macro is this??? Kill these macros! --J.C. */
00097 #define BIOS_NCOLS Bit16u ncols=IS_PC98_ARCH ? 80 : real_readw(BIOSMEM_SEG,BIOSMEM_NB_COLS);
00098 #define BIOS_NROWS Bit16u nrows=IS_PC98_ARCH ? (Bit16u)(real_readb(0x60,0x112)+1u) : (Bit16u)real_readb(BIOSMEM_SEG,BIOSMEM_NB_ROWS)+1u;
00099 
00100 extern Bit8u int10_font_08[256 * 8];
00101 extern Bit8u int10_font_14[256 * 14];
00102 extern Bit8u int10_font_16[256 * 16];
00103 extern Bit8u int10_font_14_alternate[20 * 15 + 1];
00104 extern Bit8u int10_font_16_alternate[19 * 17 + 1];
00105 
00106 struct VideoModeBlock {
00107         Bit16u  mode;
00108         VGAModes        type;
00109         Bitu    swidth, sheight;
00110         Bitu    twidth, theight;
00111         Bitu    cwidth, cheight;
00112         Bitu    ptotal,pstart,plength;
00113 
00114         Bitu    htotal,vtotal;
00115         Bitu    hdispend,vdispend;
00116         Bitu    special;
00117         
00118 };
00119 extern VideoModeBlock ModeList_VGA[];
00120 extern VideoModeBlock * CurMode;
00121 
00122 typedef struct {
00123         struct {
00124                 RealPt font_8_first;
00125                 RealPt font_8_second;
00126                 RealPt font_14;
00127                 RealPt font_16;
00128                 RealPt font_14_alternate;
00129                 RealPt font_16_alternate;
00130                 RealPt static_state;
00131                 RealPt video_save_pointers;
00132         RealPt video_dynamic_save_area;
00133                 RealPt video_parameter_table;
00134                 RealPt video_save_pointer_table;
00135                 RealPt video_dcc_table;
00136                 RealPt oemstring;
00137                 RealPt vesa_modes;
00138                 RealPt wait_retrace;
00139                 RealPt set_window;
00140                 RealPt pmode_interface;
00141                 Bit16u pmode_interface_size;
00142                 Bit16u pmode_interface_start;
00143                 Bit16u pmode_interface_window;
00144                 Bit16u pmode_interface_palette;
00145         Bit16u vesa_alloc_modes;
00146                 Bit16u used;
00147         } rom;
00148         Bit16u vesa_setmode;
00149         bool vesa_nolfb;
00150         bool vesa_oldvbe;
00151 } Int10Data;
00152 
00153 #define _EGA_HALF_CLOCK                 0x0001
00154 #define _DOUBLESCAN                         0x0002  /* CGA/EGA on VGA doublescan (bit 7 of max scanline) */
00155 #define _VGA_PIXEL_DOUBLE               0x0004
00156 #define _S3_PIXEL_DOUBLE                0x0008
00157 #define _REPEAT1                            0x0010  /* VGA doublescan (bit 0 of max scanline) */
00158 #define _CGA_SYNCDOUBLE                 0x0020
00159 #define _HIGH_DEFINITION        0x0040
00160 #define _UNUSUAL_MODE           0x0080
00161 #define _USER_DISABLED          0x4000  /* disabled (cannot set mode) but still listed in modelist */
00162 #define _USER_MODIFIED          0x8000  /* user modified (through VESAMOED) */
00163 
00164 extern Int10Data int10;
00165 
00166 static inline Bit8u CURSOR_POS_COL(Bit8u page) {
00167     if (IS_PC98_ARCH)
00168         return real_readb(0x60,0x11C); /* MS-DOS kernel location */
00169     else
00170         return real_readb(BIOSMEM_SEG,BIOSMEM_CURSOR_POS+page*2u);
00171 }
00172 
00173 static inline Bit8u CURSOR_POS_ROW(Bit8u page) {
00174     if (IS_PC98_ARCH)
00175         return real_readb(0x60,0x110); /* MS-DOS kernel location */
00176     else
00177         return real_readb(BIOSMEM_SEG,BIOSMEM_CURSOR_POS+page*2u+1u);
00178 }
00179 
00181 bool INT10_GetInsertState();
00182 
00183 bool INT10_SetVideoMode(Bit16u mode);
00184 
00185 void INT10_ScrollWindow(Bit8u rul,Bit8u cul,Bit8u rlr,Bit8u clr,Bit8s nlines,Bit8u attr,Bit8u page);
00186 
00187 void INT10_SetActivePage(Bit8u page);
00188 bool INT10_SetCurMode(void);
00189 void INT10_DisplayCombinationCode(Bit16u * dcc,bool set);
00190 void INT10_GetFuncStateInformation(PhysPt save);
00191 
00192 void INT10_SetCursorShape(Bit8u first,Bit8u last);
00193 void INT10_GetScreenColumns(Bit16u* cols);
00194 void INT10_GetCursorPos(Bit8u *row, Bit8u *col, Bit8u page);
00195 void INT10_SetCursorPos(Bit8u row,Bit8u col,Bit8u page);
00196 void INT10_TeletypeOutput(Bit8u chr,Bit8u attr);
00197 void INT10_TeletypeOutputAttr(Bit8u chr,Bit8u attr,bool useattr);
00198 void INT10_ReadCharAttr(Bit16u * result,Bit8u page);
00199 void INT10_WriteChar(Bit16u chr,Bit8u attr,Bit8u page,Bit16u count,bool showattr);
00200 void INT10_WriteString(Bit8u row,Bit8u col,Bit8u flag,Bit8u attr,PhysPt string,Bit16u count,Bit8u page);
00201 
00202 /* Graphics Stuff */
00203 void INT10_PutPixel(Bit16u x,Bit16u y,Bit8u page,Bit8u color);
00204 void INT10_GetPixel(Bit16u x,Bit16u y,Bit8u page,Bit8u * color);
00205 
00206 /* Font Stuff */
00207 void INT10_LoadFont(PhysPt font,bool reload,Bit16u count,Bitu offset,Bitu map,Bit8u height);
00208 void INT10_ReloadFont(void);
00209 
00210 /* Palette Group */
00211 void INT10_SetBackgroundBorder(Bit8u val);
00212 void INT10_SetColorSelect(Bit8u val);
00213 void INT10_SetSinglePaletteRegister(Bit8u reg,Bit8u val);
00214 void INT10_SetOverscanBorderColor(Bit8u val);
00215 void INT10_SetAllPaletteRegisters(PhysPt data);
00216 void INT10_ToggleBlinkingBit(Bit8u state);
00217 void INT10_GetSinglePaletteRegister(Bit8u reg,Bit8u * val);
00218 void INT10_GetOverscanBorderColor(Bit8u * val);
00219 void INT10_GetAllPaletteRegisters(PhysPt data);
00220 void INT10_SetSingleDACRegister(Bit8u index,Bit8u red,Bit8u green,Bit8u blue);
00221 void INT10_GetSingleDACRegister(Bit8u index,Bit8u * red,Bit8u * green,Bit8u * blue);
00222 void INT10_SetDACBlock(Bit16u index,Bit16u count,PhysPt data);
00223 void INT10_GetDACBlock(Bit16u index,Bit16u count,PhysPt data);
00224 void INT10_SelectDACPage(Bit8u function,Bit8u mode);
00225 void INT10_GetDACPage(Bit8u* mode,Bit8u* page);
00226 void INT10_SetPelMask(Bit8u mask);
00227 void INT10_GetPelMask(Bit8u & mask);
00228 void INT10_PerformGrayScaleSumming(Bit16u start_reg,Bit16u count);
00229 
00230 
00231 /* Vesa Group */
00232 Bit8u VESA_GetSVGAInformation(Bit16u seg,Bit16u off);
00233 Bit8u VESA_GetSVGAModeInformation(Bit16u mode,Bit16u seg,Bit16u off);
00234 Bit8u VESA_SetSVGAMode(Bit16u mode);
00235 Bit8u VESA_GetSVGAMode(Bit16u & mode);
00236 Bit8u VESA_SetCPUWindow(Bit8u window,Bit8u address);
00237 Bit8u VESA_GetCPUWindow(Bit8u window,Bit16u & address);
00238 Bit8u VESA_ScanLineLength(Bit8u subcall, Bit16u val, Bit16u & bytes,Bit16u & pixels,Bit16u & lines);
00239 Bit8u VESA_SetDisplayStart(Bit16u x,Bit16u y,bool wait);
00240 Bit8u VESA_GetDisplayStart(Bit16u & x,Bit16u & y);
00241 Bit8u VESA_SetPalette(PhysPt data,Bitu index,Bitu count,bool wait);
00242 Bit8u VESA_GetPalette(PhysPt data,Bitu index,Bitu count);
00243 
00244 /* Sub Groups */
00245 void INT10_SetupRomMemory(void);
00246 void INT10_SetupRomMemoryChecksum(void);
00247 void INT10_SetupVESA(void);
00248 
00249 /* EGA RIL */
00250 RealPt INT10_EGA_RIL_GetVersionPt(void);
00251 void INT10_EGA_RIL_ReadRegister(Bit8u & bl, Bit16u dx);
00252 void INT10_EGA_RIL_WriteRegister(Bit8u & bl, Bit8u bh, Bit16u dx);
00253 void INT10_EGA_RIL_ReadRegisterRange(Bit8u ch, Bit8u cl, Bit16u dx, PhysPt dst);
00254 void INT10_EGA_RIL_WriteRegisterRange(Bit8u ch, Bit8u cl, Bit16u dx, PhysPt src);
00255 void INT10_EGA_RIL_ReadRegisterSet(Bit16u cx, PhysPt tbl);
00256 void INT10_EGA_RIL_WriteRegisterSet(Bit16u cx, PhysPt tbl);
00257 
00258 /* Video State */
00259 Bitu INT10_VideoState_GetSize(Bitu state);
00260 bool INT10_VideoState_Save(Bitu state,RealPt buffer);
00261 bool INT10_VideoState_Restore(Bitu state,RealPt buffer);
00262 
00263 /* Video Parameter Tables */
00264 Bit16u INT10_SetupVideoParameterTable(PhysPt basepos);
00265 void INT10_SetupBasicVideoParameterTable(void);