| 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_video_state.cpp,v 1.3 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 |
Bitu INT10_VideoState_GetSize(Bitu state) { |
| 27 |
// state: bit0=hardware, bit1=bios data, bit2=color regs/dac state |
| 28 |
if ((state&7)==0) return 0; |
| 29 |
|
| 30 |
Bitu size=0x20; |
| 31 |
if (state&1) size+=0x46; |
| 32 |
if (state&2) size+=0x3a; |
| 33 |
if (state&4) size+=0x303; |
| 34 |
if ((svgaCard==SVGA_S3Trio) && (state&8)) size+=0x43; |
| 35 |
if (size!=0) size=(size-1)/64+1; |
| 36 |
return size; |
| 37 |
} |
| 38 |
|
| 39 |
bool INT10_VideoState_Save(Bitu state,RealPt buffer) { |
| 40 |
Bitu ct; |
| 41 |
if ((state&7)==0) return false; |
| 42 |
|
| 43 |
Bitu base_seg=RealSeg(buffer); |
| 44 |
Bitu base_dest=RealOff(buffer)+0x20; |
| 45 |
|
| 46 |
if (state&1) { |
| 47 |
real_writew(base_seg,RealOff(buffer),base_dest); |
| 48 |
|
| 49 |
Bit16u crt_reg=real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS); |
| 50 |
real_writew(base_seg,base_dest+0x40,crt_reg); |
| 51 |
|
| 52 |
real_writeb(base_seg,base_dest+0x00,IO_ReadB(0x3c4)); |
| 53 |
real_writeb(base_seg,base_dest+0x01,IO_ReadB(0x3d4)); |
| 54 |
real_writeb(base_seg,base_dest+0x02,IO_ReadB(0x3ce)); |
| 55 |
IO_ReadB(crt_reg+6); |
| 56 |
real_writeb(base_seg,base_dest+0x03,IO_ReadB(0x3c0)); |
| 57 |
real_writeb(base_seg,base_dest+0x04,IO_ReadB(0x3ca)); |
| 58 |
|
| 59 |
// sequencer |
| 60 |
for (ct=1; ct<5; ct++) { |
| 61 |
IO_WriteB(0x3c4,ct); |
| 62 |
real_writeb(base_seg,base_dest+0x04+ct,IO_ReadB(0x3c5)); |
| 63 |
} |
| 64 |
|
| 65 |
real_writeb(base_seg,base_dest+0x09,IO_ReadB(0x3cc)); |
| 66 |
|
| 67 |
// crt controller |
| 68 |
for (ct=0; ct<0x19; ct++) { |
| 69 |
IO_WriteB(crt_reg,ct); |
| 70 |
real_writeb(base_seg,base_dest+0x0a+ct,IO_ReadB(crt_reg+1)); |
| 71 |
} |
| 72 |
|
| 73 |
// attr registers |
| 74 |
for (ct=0; ct<4; ct++) { |
| 75 |
IO_ReadB(crt_reg+6); |
| 76 |
IO_WriteB(0x3c0,0x10+ct); |
| 77 |
real_writeb(base_seg,base_dest+0x33+ct,IO_ReadB(0x3c1)); |
| 78 |
} |
| 79 |
|
| 80 |
// graphics registers |
| 81 |
for (ct=0; ct<9; ct++) { |
| 82 |
IO_WriteB(0x3ce,ct); |
| 83 |
real_writeb(base_seg,base_dest+0x37+ct,IO_ReadB(0x3cf)); |
| 84 |
} |
| 85 |
|
| 86 |
// save some registers |
| 87 |
IO_WriteB(0x3c4,2); |
| 88 |
Bit8u crtc_2=IO_ReadB(0x3c5); |
| 89 |
IO_WriteB(0x3c4,4); |
| 90 |
Bit8u crtc_4=IO_ReadB(0x3c5); |
| 91 |
IO_WriteB(0x3ce,6); |
| 92 |
Bit8u gfx_6=IO_ReadB(0x3cf); |
| 93 |
IO_WriteB(0x3ce,5); |
| 94 |
Bit8u gfx_5=IO_ReadB(0x3cf); |
| 95 |
IO_WriteB(0x3ce,4); |
| 96 |
Bit8u gfx_4=IO_ReadB(0x3cf); |
| 97 |
|
| 98 |
// reprogram for full access to plane latches |
| 99 |
IO_WriteW(0x3c4,0x0f02); |
| 100 |
IO_WriteW(0x3c4,0x0704); |
| 101 |
IO_WriteW(0x3ce,0x0406); |
| 102 |
IO_WriteW(0x3ce,0x0105); |
| 103 |
mem_writeb(0xaffff,0); |
| 104 |
|
| 105 |
for (ct=0; ct<4; ct++) { |
| 106 |
IO_WriteW(0x3ce,0x0004+ct*0x100); |
| 107 |
real_writeb(base_seg,base_dest+0x42+ct,mem_readb(0xaffff)); |
| 108 |
} |
| 109 |
|
| 110 |
// restore registers |
| 111 |
IO_WriteW(0x3ce,0x0004|(gfx_4<<8)); |
| 112 |
IO_WriteW(0x3ce,0x0005|(gfx_5<<8)); |
| 113 |
IO_WriteW(0x3ce,0x0006|(gfx_6<<8)); |
| 114 |
IO_WriteW(0x3c4,0x0004|(crtc_4<<8)); |
| 115 |
IO_WriteW(0x3c4,0x0002|(crtc_2<<8)); |
| 116 |
|
| 117 |
for (ct=0; ct<0x10; ct++) { |
| 118 |
IO_ReadB(crt_reg+6); |
| 119 |
IO_WriteB(0x3c0,ct); |
| 120 |
real_writeb(base_seg,base_dest+0x23+ct,IO_ReadB(0x3c1)); |
| 121 |
} |
| 122 |
IO_WriteB(0x3c0,0x20); |
| 123 |
|
| 124 |
base_dest+=0x46; |
| 125 |
} |
| 126 |
|
| 127 |
if (state&2) { |
| 128 |
real_writew(base_seg,RealOff(buffer)+2,base_dest); |
| 129 |
|
| 130 |
real_writeb(base_seg,base_dest+0x00,mem_readb(0x410)&0x30); |
| 131 |
for (ct=0; ct<0x1e; ct++) { |
| 132 |
real_writeb(base_seg,base_dest+0x01+ct,mem_readb(0x449+ct)); |
| 133 |
} |
| 134 |
for (ct=0; ct<0x07; ct++) { |
| 135 |
real_writeb(base_seg,base_dest+0x1f+ct,mem_readb(0x484+ct)); |
| 136 |
} |
| 137 |
real_writed(base_seg,base_dest+0x26,mem_readd(0x48a)); |
| 138 |
real_writed(base_seg,base_dest+0x2a,mem_readd(0x14)); // int 5 |
| 139 |
real_writed(base_seg,base_dest+0x2e,mem_readd(0x74)); // int 1d |
| 140 |
real_writed(base_seg,base_dest+0x32,mem_readd(0x7c)); // int 1f |
| 141 |
real_writed(base_seg,base_dest+0x36,mem_readd(0x10c)); // int 43 |
| 142 |
|
| 143 |
base_dest+=0x3a; |
| 144 |
} |
| 145 |
|
| 146 |
if (state&4) { |
| 147 |
real_writew(base_seg,RealOff(buffer)+4,base_dest); |
| 148 |
|
| 149 |
Bit16u crt_reg=real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS); |
| 150 |
|
| 151 |
IO_ReadB(crt_reg+6); |
| 152 |
IO_WriteB(0x3c0,0x14); |
| 153 |
real_writeb(base_seg,base_dest+0x303,IO_ReadB(0x3c1)); |
| 154 |
|
| 155 |
Bitu dac_state=IO_ReadB(0x3c7)&1; |
| 156 |
Bitu dac_windex=IO_ReadB(0x3c8); |
| 157 |
if (dac_state!=0) dac_windex--; |
| 158 |
real_writeb(base_seg,base_dest+0x000,dac_state); |
| 159 |
real_writeb(base_seg,base_dest+0x001,dac_windex); |
| 160 |
real_writeb(base_seg,base_dest+0x002,IO_ReadB(0x3c6)); |
| 161 |
|
| 162 |
for (ct=0; ct<0x100; ct++) { |
| 163 |
IO_WriteB(0x3c7,ct); |
| 164 |
real_writeb(base_seg,base_dest+0x003+ct*3+0,IO_ReadB(0x3c9)); |
| 165 |
real_writeb(base_seg,base_dest+0x003+ct*3+1,IO_ReadB(0x3c9)); |
| 166 |
real_writeb(base_seg,base_dest+0x003+ct*3+2,IO_ReadB(0x3c9)); |
| 167 |
} |
| 168 |
|
| 169 |
IO_ReadB(crt_reg+6); |
| 170 |
IO_WriteB(0x3c0,0x20); |
| 171 |
|
| 172 |
base_dest+=0x303; |
| 173 |
} |
| 174 |
|
| 175 |
if ((svgaCard==SVGA_S3Trio) && (state&8)) { |
| 176 |
real_writew(base_seg,RealOff(buffer)+6,base_dest); |
| 177 |
|
| 178 |
Bit16u crt_reg=real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS); |
| 179 |
|
| 180 |
IO_WriteB(0x3c4,0x08); |
| 181 |
// Bitu seq_8=IO_ReadB(0x3c5); |
| 182 |
IO_ReadB(0x3c5); |
| 183 |
// real_writeb(base_seg,base_dest+0x00,IO_ReadB(0x3c5)); |
| 184 |
IO_WriteB(0x3c5,0x06); // unlock s3-specific registers |
| 185 |
|
| 186 |
// sequencer |
| 187 |
for (ct=0; ct<0x13; ct++) { |
| 188 |
IO_WriteB(0x3c4,0x09+ct); |
| 189 |
real_writeb(base_seg,base_dest+0x00+ct,IO_ReadB(0x3c5)); |
| 190 |
} |
| 191 |
|
| 192 |
// unlock s3-specific registers |
| 193 |
IO_WriteW(crt_reg,0x4838); |
| 194 |
IO_WriteW(crt_reg,0xa539); |
| 195 |
|
| 196 |
// crt controller |
| 197 |
Bitu ct_dest=0x13; |
| 198 |
for (ct=0; ct<0x40; ct++) { |
| 199 |
if ((ct==0x4a-0x30) || (ct==0x4b-0x30)) { |
| 200 |
IO_WriteB(crt_reg,0x45); |
| 201 |
IO_ReadB(crt_reg+1); |
| 202 |
IO_WriteB(crt_reg,0x30+ct); |
| 203 |
real_writeb(base_seg,base_dest+(ct_dest++),IO_ReadB(crt_reg+1)); |
| 204 |
real_writeb(base_seg,base_dest+(ct_dest++),IO_ReadB(crt_reg+1)); |
| 205 |
real_writeb(base_seg,base_dest+(ct_dest++),IO_ReadB(crt_reg+1)); |
| 206 |
} else { |
| 207 |
IO_WriteB(crt_reg,0x30+ct); |
| 208 |
real_writeb(base_seg,base_dest+(ct_dest++),IO_ReadB(crt_reg+1)); |
| 209 |
} |
| 210 |
} |
| 211 |
} |
| 212 |
return true; |
| 213 |
} |
| 214 |
|
| 215 |
bool INT10_VideoState_Restore(Bitu state,RealPt buffer) { |
| 216 |
Bitu ct; |
| 217 |
if ((state&7)==0) return false; |
| 218 |
|
| 219 |
Bit16u base_seg=RealSeg(buffer); |
| 220 |
Bit16u base_dest; |
| 221 |
|
| 222 |
if (state&1) { |
| 223 |
base_dest=real_readw(base_seg,RealOff(buffer)); |
| 224 |
Bit16u crt_reg=real_readw(base_seg,base_dest+0x40); |
| 225 |
|
| 226 |
// reprogram for full access to plane latches |
| 227 |
IO_WriteW(0x3c4,0x0704); |
| 228 |
IO_WriteW(0x3ce,0x0406); |
| 229 |
IO_WriteW(0x3ce,0x0005); |
| 230 |
|
| 231 |
IO_WriteW(0x3c4,0x0002); |
| 232 |
mem_writeb(0xaffff,real_readb(base_seg,base_dest+0x42)); |
| 233 |
IO_WriteW(0x3c4,0x0102); |
| 234 |
mem_writeb(0xaffff,real_readb(base_seg,base_dest+0x43)); |
| 235 |
IO_WriteW(0x3c4,0x0202); |
| 236 |
mem_writeb(0xaffff,real_readb(base_seg,base_dest+0x44)); |
| 237 |
IO_WriteW(0x3c4,0x0402); |
| 238 |
mem_writeb(0xaffff,real_readb(base_seg,base_dest+0x45)); |
| 239 |
IO_WriteW(0x3c4,0x0f02); |
| 240 |
mem_readb(0xaffff); |
| 241 |
|
| 242 |
IO_WriteW(0x3c4,0x0100); |
| 243 |
|
| 244 |
// sequencer |
| 245 |
for (ct=1; ct<5; ct++) { |
| 246 |
IO_WriteW(0x3c4,ct+(real_readb(base_seg,base_dest+0x04+ct)<<8)); |
| 247 |
} |
| 248 |
|
| 249 |
IO_WriteB(0x3c2,real_readb(base_seg,base_dest+0x09)); |
| 250 |
IO_WriteW(0x3c4,0x0300); |
| 251 |
IO_WriteW(crt_reg,0x0011); |
| 252 |
|
| 253 |
// crt controller |
| 254 |
for (ct=0; ct<0x19; ct++) { |
| 255 |
IO_WriteW(crt_reg,ct+(real_readb(base_seg,base_dest+0x0a+ct)<<8)); |
| 256 |
} |
| 257 |
|
| 258 |
IO_ReadB(crt_reg+6); |
| 259 |
// attr registers |
| 260 |
for (ct=0; ct<4; ct++) { |
| 261 |
IO_WriteB(0x3c0,0x10+ct); |
| 262 |
IO_WriteB(0x3c0,real_readb(base_seg,base_dest+0x33+ct)); |
| 263 |
} |
| 264 |
|
| 265 |
// graphics registers |
| 266 |
for (ct=0; ct<9; ct++) { |
| 267 |
IO_WriteW(0x3ce,ct+(real_readb(base_seg,base_dest+0x37+ct)<<8)); |
| 268 |
} |
| 269 |
|
| 270 |
IO_WriteB(crt_reg+6,real_readb(base_seg,base_dest+0x04)); |
| 271 |
IO_ReadB(crt_reg+6); |
| 272 |
|
| 273 |
// attr registers |
| 274 |
for (ct=0; ct<0x10; ct++) { |
| 275 |
IO_WriteB(0x3c0,ct); |
| 276 |
IO_WriteB(0x3c0,real_readb(base_seg,base_dest+0x23+ct)); |
| 277 |
} |
| 278 |
|
| 279 |
IO_WriteB(0x3c4,real_readb(base_seg,base_dest+0x00)); |
| 280 |
IO_WriteB(0x3d4,real_readb(base_seg,base_dest+0x01)); |
| 281 |
IO_WriteB(0x3ce,real_readb(base_seg,base_dest+0x02)); |
| 282 |
IO_ReadB(crt_reg+6); |
| 283 |
IO_WriteB(0x3c0,real_readb(base_seg,base_dest+0x03)); |
| 284 |
} |
| 285 |
|
| 286 |
if (state&2) { |
| 287 |
base_dest=real_readw(base_seg,RealOff(buffer)+2); |
| 288 |
|
| 289 |
mem_writeb(0x410,(mem_readb(0x410)&0xcf) | real_readb(base_seg,base_dest+0x00)); |
| 290 |
for (ct=0; ct<0x1e; ct++) { |
| 291 |
mem_writeb(0x449+ct,real_readb(base_seg,base_dest+0x01+ct)); |
| 292 |
} |
| 293 |
for (ct=0; ct<0x07; ct++) { |
| 294 |
mem_writeb(0x484+ct,real_readb(base_seg,base_dest+0x1f+ct)); |
| 295 |
} |
| 296 |
mem_writed(0x48a,real_readd(base_seg,base_dest+0x26)); |
| 297 |
mem_writed(0x14,real_readd(base_seg,base_dest+0x2a)); // int 5 |
| 298 |
mem_writed(0x74,real_readd(base_seg,base_dest+0x2e)); // int 1d |
| 299 |
mem_writed(0x7c,real_readd(base_seg,base_dest+0x32)); // int 1f |
| 300 |
mem_writed(0x10c,real_readd(base_seg,base_dest+0x36)); // int 43 |
| 301 |
} |
| 302 |
|
| 303 |
if (state&4) { |
| 304 |
base_dest=real_readw(base_seg,RealOff(buffer)+4); |
| 305 |
|
| 306 |
Bit16u crt_reg=real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS); |
| 307 |
|
| 308 |
IO_WriteB(0x3c6,real_readb(base_seg,base_dest+0x002)); |
| 309 |
|
| 310 |
for (ct=0; ct<0x100; ct++) { |
| 311 |
IO_WriteB(0x3c8,ct); |
| 312 |
IO_WriteB(0x3c9,real_readb(base_seg,base_dest+0x003+ct*3+0)); |
| 313 |
IO_WriteB(0x3c9,real_readb(base_seg,base_dest+0x003+ct*3+1)); |
| 314 |
IO_WriteB(0x3c9,real_readb(base_seg,base_dest+0x003+ct*3+2)); |
| 315 |
} |
| 316 |
|
| 317 |
IO_ReadB(crt_reg+6); |
| 318 |
IO_WriteB(0x3c0,0x14); |
| 319 |
IO_WriteB(0x3c0,real_readb(base_seg,base_dest+0x303)); |
| 320 |
|
| 321 |
Bitu dac_state=real_readb(base_seg,base_dest+0x000); |
| 322 |
if (dac_state==0) { |
| 323 |
IO_WriteB(0x3c8,real_readb(base_seg,base_dest+0x001)); |
| 324 |
} else { |
| 325 |
IO_WriteB(0x3c7,real_readb(base_seg,base_dest+0x001)); |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
if ((svgaCard==SVGA_S3Trio) && (state&8)) { |
| 330 |
base_dest=real_readw(base_seg,RealOff(buffer)+6); |
| 331 |
|
| 332 |
Bit16u crt_reg=real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS); |
| 333 |
|
| 334 |
Bitu seq_idx=IO_ReadB(0x3c4); |
| 335 |
IO_WriteB(0x3c4,0x08); |
| 336 |
// Bitu seq_8=IO_ReadB(0x3c5); |
| 337 |
IO_ReadB(0x3c5); |
| 338 |
// real_writeb(base_seg,base_dest+0x00,IO_ReadB(0x3c5)); |
| 339 |
IO_WriteB(0x3c5,0x06); // unlock s3-specific registers |
| 340 |
|
| 341 |
// sequencer |
| 342 |
for (ct=0; ct<0x13; ct++) { |
| 343 |
IO_WriteW(0x3c4,(0x09+ct)+(real_readb(base_seg,base_dest+0x00+ct)<<8)); |
| 344 |
} |
| 345 |
IO_WriteB(0x3c4,seq_idx); |
| 346 |
|
| 347 |
// Bitu crtc_idx=IO_ReadB(0x3d4); |
| 348 |
|
| 349 |
// unlock s3-specific registers |
| 350 |
IO_WriteW(crt_reg,0x4838); |
| 351 |
IO_WriteW(crt_reg,0xa539); |
| 352 |
|
| 353 |
// crt controller |
| 354 |
Bitu ct_dest=0x13; |
| 355 |
for (ct=0; ct<0x40; ct++) { |
| 356 |
if ((ct==0x4a-0x30) || (ct==0x4b-0x30)) { |
| 357 |
IO_WriteB(crt_reg,0x45); |
| 358 |
IO_ReadB(crt_reg+1); |
| 359 |
IO_WriteB(crt_reg,0x30+ct); |
| 360 |
IO_WriteB(crt_reg,real_readb(base_seg,base_dest+(ct_dest++))); |
| 361 |
} else { |
| 362 |
IO_WriteW(crt_reg,(0x30+ct)+(real_readb(base_seg,base_dest+(ct_dest++))<<8)); |
| 363 |
} |
| 364 |
} |
| 365 |
|
| 366 |
// mmio |
| 367 |
/* IO_WriteB(crt_reg,0x40); |
| 368 |
Bitu sysval1=IO_ReadB(crt_reg+1); |
| 369 |
IO_WriteB(crt_reg+1,sysval|1); |
| 370 |
IO_WriteB(crt_reg,0x53); |
| 371 |
Bitu sysva2=IO_ReadB(crt_reg+1); |
| 372 |
IO_WriteB(crt_reg+1,sysval2|0x10); |
| 373 |
|
| 374 |
real_writew(0xa000,0x8128,0xffff); |
| 375 |
|
| 376 |
IO_WriteB(crt_reg,0x40); |
| 377 |
IO_WriteB(crt_reg,sysval1); |
| 378 |
IO_WriteB(crt_reg,0x53); |
| 379 |
IO_WriteB(crt_reg,sysval2); |
| 380 |
IO_WriteB(crt_reg,crtc_idx); */ |
| 381 |
} |
| 382 |
|
| 383 |
return true; |
| 384 |
} |