| 1 |
/* |
| 2 |
* Copyright (C) 2002-2010 The DOSBox Team |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program; if not, write to the Free Software |
| 16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 |
*/ |
| 18 |
|
| 19 |
/* $Id: int10_misc.cpp,v 1.21 2009-05-27 09:15:42 qbix79 Exp $ */ |
| 20 |
|
| 21 |
#include "dosbox.h" |
| 22 |
#include "mem.h" |
| 23 |
#include "inout.h" |
| 24 |
#include "int10.h" |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#pragma pack(1) |
| 29 |
struct Dynamic_Functionality { |
| 30 |
RealPt static_table; /* 00h DWORD address of static functionality table */ |
| 31 |
Bit8u cur_mode; /* 04h BYTE video mode in effect */ |
| 32 |
Bit16u num_cols; /* 05h WORD number of columns */ |
| 33 |
Bit16u regen_size; /* 07h WORD length of regen buffer in bytes */ |
| 34 |
Bit16u regen_start; /* 09h WORD starting address of regen buffer*/ |
| 35 |
Bit16u cursor_pos[8]; /* 0Bh WORD cursor position for page 0-7 */ |
| 36 |
Bit16u cursor_type; /* 1Bh WORD cursor type */ |
| 37 |
Bit8u active_page; /* 1Dh BYTE active display page */ |
| 38 |
Bit16u crtc_address; /* 1Eh WORD CRTC port address */ |
| 39 |
Bit8u reg_3x8; /* 20h BYTE current setting of register (3?8) */ |
| 40 |
Bit8u reg_3x9; /* 21h BYTE current setting of register (3?9) */ |
| 41 |
Bit8u num_rows; /* 22h BYTE number of rows */ |
| 42 |
Bit16u bytes_per_char; /* 23h WORD bytes/character */ |
| 43 |
Bit8u dcc; /* 25h BYTE display combination code of active display */ |
| 44 |
Bit8u dcc_alternate; /* 26h BYTE DCC of alternate display */ |
| 45 |
Bit16u num_colors; /* 27h WORD number of colors supported in current mode */ |
| 46 |
Bit8u num_pages; /* 29h BYTE number of pages supported in current mode */ |
| 47 |
Bit8u num_scanlines; /* 2Ah BYTE number of scan lines active mode (0,1,2,3) = (200,350,400,480) */ |
| 48 |
Bit8u pri_char_block; /* 2Bh BYTE primary character block */ |
| 49 |
Bit8u sec_char_block; /* 2Ch BYTE secondary character block */ |
| 50 |
Bit8u misc_flags; /* 2Dh BYTE miscellaneous flags |
| 51 |
bit 0 all modes on all displays on |
| 52 |
1 grey summing on |
| 53 |
2 monochrome display attached |
| 54 |
3 default palette loading disabled |
| 55 |
4 cursor emulation enabled |
| 56 |
5 0 = intensity; 1 = blinking |
| 57 |
6 PS/2 P70 plasma display (without 9-dot wide font) active |
| 58 |
7 reserved |
| 59 |
*/ |
| 60 |
Bit8u reserved1[3]; /* 2Eh 3 BYTEs reserved (00h) */ |
| 61 |
Bit8u vid_mem; /* 31h BYTE video memory available 00h = 64K, 01h = 128K, 02h = 192K, 03h = 256K */ |
| 62 |
Bit8u savep_state_flag; /* 32h BYTE save pointer state flags |
| 63 |
bit 0 512 character set active |
| 64 |
1 dynamic save area present |
| 65 |
2 alpha font override active |
| 66 |
3 graphics font override active |
| 67 |
4 palette override active |
| 68 |
5 DCC override active |
| 69 |
6 reserved |
| 70 |
7 reserved |
| 71 |
*/ |
| 72 |
Bit8u reserved2[13]; /* 33h 13 BYTEs reserved (00h) */ |
| 73 |
} GCC_ATTRIBUTE(packed); |
| 74 |
#pragma pack() |
| 75 |
|
| 76 |
void INT10_GetFuncStateInformation(PhysPt save) { |
| 77 |
/* set static state pointer */ |
| 78 |
mem_writed(save,int10.rom.static_state); |
| 79 |
/* Copy BIOS Segment areas */ |
| 80 |
Bit16u i; |
| 81 |
|
| 82 |
/* First area in Bios Seg */ |
| 83 |
for (i=0;i<0x1e;i++) { |
| 84 |
mem_writeb(save+0x4+i,real_readb(BIOSMEM_SEG,BIOSMEM_CURRENT_MODE+i)); |
| 85 |
} |
| 86 |
/* Second area */ |
| 87 |
mem_writeb(save+0x22,real_readb(BIOSMEM_SEG,BIOSMEM_NB_ROWS)+1); |
| 88 |
for (i=1;i<3;i++) { |
| 89 |
mem_writeb(save+0x22+i,real_readb(BIOSMEM_SEG,BIOSMEM_NB_ROWS+i)); |
| 90 |
} |
| 91 |
/* Zero out rest of block */ |
| 92 |
for (i=0x25;i<0x40;i++) mem_writeb(save+i,0); |
| 93 |
/* DCC */ |
| 94 |
// mem_writeb(save+0x25,real_readb(BIOSMEM_SEG,BIOSMEM_DCC_INDEX)); |
| 95 |
Bit8u dccode = 0x00; |
| 96 |
RealPt vsavept=real_readd(BIOSMEM_SEG,BIOSMEM_VS_POINTER); |
| 97 |
RealPt svstable=real_readd(RealSeg(vsavept),RealOff(vsavept)+0x10); |
| 98 |
if (svstable) { |
| 99 |
RealPt dcctable=real_readd(RealSeg(svstable),RealOff(svstable)+0x02); |
| 100 |
Bit8u entries=real_readb(RealSeg(dcctable),RealOff(dcctable)+0x00); |
| 101 |
Bit8u idx=real_readb(BIOSMEM_SEG,BIOSMEM_DCC_INDEX); |
| 102 |
// check if index within range |
| 103 |
if (idx<entries) { |
| 104 |
Bit16u dccentry=real_readw(RealSeg(dcctable),RealOff(dcctable)+0x04+idx*2); |
| 105 |
if ((dccentry&0xff)==0) dccode=(Bit8u)((dccentry>>8)&0xff); |
| 106 |
else dccode=(Bit8u)(dccentry&0xff); |
| 107 |
} |
| 108 |
} |
| 109 |
mem_writeb(save+0x25,dccode); |
| 110 |
|
| 111 |
Bit16u col_count=0; |
| 112 |
switch (CurMode->type) { |
| 113 |
case M_TEXT: |
| 114 |
if (CurMode->mode==0x7) col_count=1; else col_count=16;break; |
| 115 |
case M_CGA2: |
| 116 |
col_count=2;break; |
| 117 |
case M_CGA4: |
| 118 |
col_count=4;break; |
| 119 |
case M_EGA: |
| 120 |
if (CurMode->mode==0x11 || CurMode->mode==0x0f) |
| 121 |
col_count=2; |
| 122 |
else |
| 123 |
col_count=16; |
| 124 |
break; |
| 125 |
case M_VGA: |
| 126 |
col_count=256;break; |
| 127 |
default: |
| 128 |
LOG(LOG_INT10,LOG_ERROR)("Get Func State illegal mode type %d",CurMode->type); |
| 129 |
} |
| 130 |
/* Colour count */ |
| 131 |
mem_writew(save+0x27,col_count); |
| 132 |
/* Page count */ |
| 133 |
mem_writeb(save+0x29,CurMode->ptotal); |
| 134 |
/* scan lines */ |
| 135 |
switch (CurMode->sheight) { |
| 136 |
case 200: |
| 137 |
mem_writeb(save+0x2a,0);break; |
| 138 |
case 350: |
| 139 |
mem_writeb(save+0x2a,1);break; |
| 140 |
case 400: |
| 141 |
mem_writeb(save+0x2a,2);break; |
| 142 |
case 480: |
| 143 |
mem_writeb(save+0x2a,3);break; |
| 144 |
}; |
| 145 |
/* misc flags */ |
| 146 |
if (CurMode->type==M_TEXT) mem_writeb(save+0x2d,0x21); |
| 147 |
else mem_writeb(save+0x2d,0x01); |
| 148 |
/* Video Memory available */ |
| 149 |
mem_writeb(save+0x31,3); |
| 150 |
} |
| 151 |
|
| 152 |
RealPt INT10_EGA_RIL_GetVersionPt(void) { |
| 153 |
/* points to a graphics ROM location at the moment |
| 154 |
as checks test for bx!=0 only */ |
| 155 |
return RealMake(0xc000,0x30); |
| 156 |
} |
| 157 |
|
| 158 |
static void EGA_RIL(Bit16u dx, Bitu& port, Bitu& regs) { |
| 159 |
port = 0; |
| 160 |
regs = 0; //if nul is returned it's a single register port |
| 161 |
switch(dx) { |
| 162 |
case 0x00: /* CRT Controller (25 reg) 3B4h mono modes, 3D4h color modes */ |
| 163 |
port = real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS); |
| 164 |
regs = 25; |
| 165 |
break; |
| 166 |
case 0x08: /* Sequencer (5 registers) 3C4h */ |
| 167 |
port = 0x3C4; |
| 168 |
regs = 5; |
| 169 |
break; |
| 170 |
case 0x10: /* Graphics Controller (9 registers) 3CEh */ |
| 171 |
port = 0x3CE; |
| 172 |
regs = 9; |
| 173 |
break; |
| 174 |
case 0x18: /* Attribute Controller (20 registers) 3C0h */ |
| 175 |
port = 0x3c0; |
| 176 |
regs = 20; |
| 177 |
break; |
| 178 |
case 0x20: /* Miscellaneous Output register 3C2h */ |
| 179 |
port = 0x3C2; |
| 180 |
break; |
| 181 |
case 0x28: /* Feature Control register (3BAh mono modes, 3DAh color modes) */ |
| 182 |
port = real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS) + 6; |
| 183 |
break; |
| 184 |
case 0x30: /* Graphics 1 Position register 3CCh */ |
| 185 |
port = 0x3CC; |
| 186 |
break; |
| 187 |
case 0x38: /* Graphics 2 Position register 3CAh */ |
| 188 |
port = 0x3CA; |
| 189 |
break; |
| 190 |
default: |
| 191 |
LOG(LOG_INT10,LOG_ERROR)("unknown RIL port selection %X",dx); |
| 192 |
break; |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
void INT10_EGA_RIL_ReadRegister(Bit8u & bl, Bit16u dx) { |
| 197 |
Bitu port = 0; |
| 198 |
Bitu regs = 0; |
| 199 |
EGA_RIL(dx,port,regs); |
| 200 |
if(regs == 0) { |
| 201 |
if(port) bl = IO_Read(port); |
| 202 |
} else { |
| 203 |
if(port == 0x3c0) IO_Read(real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS) + 6); |
| 204 |
IO_Write(port,bl); |
| 205 |
bl = IO_Read(port+1); |
| 206 |
if(port == 0x3c0) IO_Read(real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS) + 6); |
| 207 |
LOG(LOG_INT10,LOG_NORMAL)("EGA RIL read used with multi-reg"); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
void INT10_EGA_RIL_WriteRegister(Bit8u & bl, Bit8u bh, Bit16u dx) { |
| 212 |
Bitu port = 0; |
| 213 |
Bitu regs = 0; |
| 214 |
EGA_RIL(dx,port,regs); |
| 215 |
if(regs == 0) { |
| 216 |
if(port) IO_Write(port,bl); |
| 217 |
} else { |
| 218 |
if(port == 0x3c0) { |
| 219 |
IO_Read(real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS) + 6); |
| 220 |
IO_Write(port,bl); |
| 221 |
IO_Write(port,bh); |
| 222 |
} else { |
| 223 |
IO_Write(port,bl); |
| 224 |
IO_Write(port+1,bh); |
| 225 |
} |
| 226 |
bl = bh;//Not sure |
| 227 |
LOG(LOG_INT10,LOG_NORMAL)("EGA RIL write used with multi-reg"); |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
void INT10_EGA_RIL_ReadRegisterRange(Bit8u ch, Bit8u cl, Bit16u dx, PhysPt dst) { |
| 232 |
Bitu port = 0; |
| 233 |
Bitu regs = 0; |
| 234 |
EGA_RIL(dx,port,regs); |
| 235 |
if(regs == 0) { |
| 236 |
LOG(LOG_INT10,LOG_ERROR)("EGA RIL range read with port %x called",port); |
| 237 |
} else { |
| 238 |
if(ch<regs) { |
| 239 |
if ((Bitu)ch+cl>regs) cl=(Bit8u)(regs-ch); |
| 240 |
for (Bitu i=0; i<cl; i++) { |
| 241 |
if(port == 0x3c0) IO_Read(real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS) + 6); |
| 242 |
IO_Write(port,ch+i); |
| 243 |
mem_writeb(dst++,IO_Read(port+1)); |
| 244 |
} |
| 245 |
if(port == 0x3c0) IO_Read(real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS) + 6); |
| 246 |
} else LOG(LOG_INT10,LOG_ERROR)("EGA RIL range read from %x for invalid register %x",port,ch); |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
void INT10_EGA_RIL_WriteRegisterRange(Bit8u ch, Bit8u cl, Bit16u dx, PhysPt src) { |
| 251 |
Bitu port = 0; |
| 252 |
Bitu regs = 0; |
| 253 |
EGA_RIL(dx,port,regs); |
| 254 |
if(regs == 0) { |
| 255 |
LOG(LOG_INT10,LOG_ERROR)("EGA RIL range write called with port %x",port); |
| 256 |
} else { |
| 257 |
if(ch<regs) { |
| 258 |
if ((Bitu)ch+cl>regs) cl=(Bit8u)(regs-ch); |
| 259 |
if(port == 0x3c0) { |
| 260 |
IO_Read(real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS) + 6); |
| 261 |
for (Bitu i=0; i<cl; i++) { |
| 262 |
IO_Write(port,ch+i); |
| 263 |
IO_Write(port,mem_readb(src++)); |
| 264 |
} |
| 265 |
} else { |
| 266 |
for (Bitu i=0; i<cl; i++) { |
| 267 |
IO_Write(port,ch+i); |
| 268 |
IO_Write(port+1,mem_readb(src++)); |
| 269 |
} |
| 270 |
} |
| 271 |
} else LOG(LOG_INT10,LOG_ERROR)("EGA RIL range write to %x with invalid register %x",port,ch); |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
/* register sets are of the form |
| 276 |
offset 0 (word): group index |
| 277 |
offset 2 (byte): register number (0 for single registers, ignored) |
| 278 |
offset 3 (byte): register value (return value when reading) |
| 279 |
*/ |
| 280 |
void INT10_EGA_RIL_ReadRegisterSet(Bit16u cx, PhysPt tbl) { |
| 281 |
/* read cx register sets */ |
| 282 |
for (Bitu i=0; i<cx; i++) { |
| 283 |
Bit8u vl=mem_readb(tbl+2); |
| 284 |
INT10_EGA_RIL_ReadRegister(vl, mem_readw(tbl)); |
| 285 |
mem_writeb(tbl+3, vl); |
| 286 |
tbl+=4; |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
void INT10_EGA_RIL_WriteRegisterSet(Bit16u cx, PhysPt tbl) { |
| 291 |
/* write cx register sets */ |
| 292 |
Bitu port = 0; |
| 293 |
Bitu regs = 0; |
| 294 |
for (Bitu i=0; i<cx; i++) { |
| 295 |
EGA_RIL(mem_readw(tbl),port,regs); |
| 296 |
Bit8u vl=mem_readb(tbl+3); |
| 297 |
if(regs == 0) { |
| 298 |
if(port) IO_Write(port,vl); |
| 299 |
} else { |
| 300 |
Bit8u idx=mem_readb(tbl+2); |
| 301 |
if(port == 0x3c0) { |
| 302 |
IO_Read(real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS) + 6); |
| 303 |
IO_Write(port,idx); |
| 304 |
IO_Write(port,vl); |
| 305 |
} else { |
| 306 |
IO_Write(port,idx); |
| 307 |
IO_Write(port+1,vl); |
| 308 |
} |
| 309 |
} |
| 310 |
tbl+=4; |
| 311 |
} |
| 312 |
} |