| 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: vga_misc.cpp,v 1.39 2009-01-25 12:00:49 c2woody Exp $ */ |
| 20 |
|
| 21 |
#include "dosbox.h" |
| 22 |
#include "inout.h" |
| 23 |
#include "pic.h" |
| 24 |
#include "vga.h" |
| 25 |
#include <math.h> |
| 26 |
|
| 27 |
|
| 28 |
void vga_write_p3d4(Bitu port,Bitu val,Bitu iolen); |
| 29 |
Bitu vga_read_p3d4(Bitu port,Bitu iolen); |
| 30 |
void vga_write_p3d5(Bitu port,Bitu val,Bitu iolen); |
| 31 |
Bitu vga_read_p3d5(Bitu port,Bitu iolen); |
| 32 |
|
| 33 |
Bitu vga_read_p3da(Bitu port,Bitu iolen) { |
| 34 |
Bit8u retval=0; |
| 35 |
double timeInFrame = PIC_FullIndex()-vga.draw.delay.framestart; |
| 36 |
|
| 37 |
vga.internal.attrindex=false; |
| 38 |
vga.tandy.pcjr_flipflop=false; |
| 39 |
|
| 40 |
// 3DAh (R): Status Register |
| 41 |
// bit 0 Horizontal or Vertical blanking |
| 42 |
// 3 Vertical sync |
| 43 |
|
| 44 |
if (timeInFrame >= vga.draw.delay.vrstart && |
| 45 |
timeInFrame <= vga.draw.delay.vrend) |
| 46 |
retval |= 8; |
| 47 |
if (timeInFrame >= vga.draw.delay.vdend) { |
| 48 |
retval |= 1; |
| 49 |
} else { |
| 50 |
double timeInLine=fmod(timeInFrame,vga.draw.delay.htotal); |
| 51 |
if (timeInLine >= vga.draw.delay.hblkstart && |
| 52 |
timeInLine <= vga.draw.delay.hblkend) { |
| 53 |
retval |= 1; |
| 54 |
} |
| 55 |
} |
| 56 |
return retval; |
| 57 |
} |
| 58 |
|
| 59 |
static void write_p3c2(Bitu port,Bitu val,Bitu iolen) { |
| 60 |
vga.misc_output=val; |
| 61 |
if (val & 0x1) { |
| 62 |
IO_RegisterWriteHandler(0x3d4,vga_write_p3d4,IO_MB); |
| 63 |
IO_RegisterReadHandler(0x3d4,vga_read_p3d4,IO_MB); |
| 64 |
IO_RegisterReadHandler(0x3da,vga_read_p3da,IO_MB); |
| 65 |
|
| 66 |
IO_RegisterWriteHandler(0x3d5,vga_write_p3d5,IO_MB); |
| 67 |
IO_RegisterReadHandler(0x3d5,vga_read_p3d5,IO_MB); |
| 68 |
|
| 69 |
IO_FreeWriteHandler(0x3b4,IO_MB); |
| 70 |
IO_FreeReadHandler(0x3b4,IO_MB); |
| 71 |
IO_FreeWriteHandler(0x3b5,IO_MB); |
| 72 |
IO_FreeReadHandler(0x3b5,IO_MB); |
| 73 |
IO_FreeReadHandler(0x3ba,IO_MB); |
| 74 |
} else { |
| 75 |
IO_RegisterWriteHandler(0x3b4,vga_write_p3d4,IO_MB); |
| 76 |
IO_RegisterReadHandler(0x3b4,vga_read_p3d4,IO_MB); |
| 77 |
IO_RegisterReadHandler(0x3ba,vga_read_p3da,IO_MB); |
| 78 |
|
| 79 |
IO_RegisterWriteHandler(0x3b5,vga_write_p3d5,IO_MB); |
| 80 |
IO_RegisterReadHandler(0x3b5,vga_read_p3d5,IO_MB); |
| 81 |
|
| 82 |
|
| 83 |
IO_FreeWriteHandler(0x3d4,IO_MB); |
| 84 |
IO_FreeReadHandler(0x3d4,IO_MB); |
| 85 |
IO_FreeWriteHandler(0x3d5,IO_MB); |
| 86 |
IO_FreeReadHandler(0x3d5,IO_MB); |
| 87 |
IO_FreeReadHandler(0x3da,IO_MB); |
| 88 |
} |
| 89 |
/* |
| 90 |
0 If set Color Emulation. Base Address=3Dxh else Mono Emulation. Base Address=3Bxh. |
| 91 |
2-3 Clock Select. 0: 25MHz, 1: 28MHz |
| 92 |
5 When in Odd/Even modes Select High 64k bank if set |
| 93 |
6 Horizontal Sync Polarity. Negative if set |
| 94 |
7 Vertical Sync Polarity. Negative if set |
| 95 |
Bit 6-7 indicates the number of lines on the display: |
| 96 |
1: 400, 2: 350, 3: 480 |
| 97 |
Note: Set to all zero on a hardware reset. |
| 98 |
Note: This register can be read from port 3CCh. |
| 99 |
*/ |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
static Bitu read_p3cc(Bitu port,Bitu iolen) { |
| 104 |
return vga.misc_output; |
| 105 |
} |
| 106 |
|
| 107 |
// VGA feature control register |
| 108 |
static Bitu read_p3ca(Bitu port,Bitu iolen) { |
| 109 |
return 0; |
| 110 |
} |
| 111 |
|
| 112 |
static Bitu read_p3c8(Bitu port,Bitu iolen) { |
| 113 |
return 0x10; |
| 114 |
} |
| 115 |
|
| 116 |
static Bitu read_p3c2(Bitu port,Bitu iolen) { |
| 117 |
Bit8u retval=0; |
| 118 |
|
| 119 |
if (machine==MCH_EGA) retval = 0x0F; |
| 120 |
else if (IS_VGA_ARCH) retval = 0x60; |
| 121 |
if ((machine==MCH_VGA) || (((vga.misc_output>>2)&3)==0) || (((vga.misc_output>>2)&3)==3)) { |
| 122 |
retval |= 0x10; |
| 123 |
} |
| 124 |
|
| 125 |
if (vga.draw.vret_triggered) retval |= 0x80; |
| 126 |
return retval; |
| 127 |
/* |
| 128 |
0-3 0xF on EGA, 0x0 on VGA |
| 129 |
4 Status of the switch selected by the Miscellaneous Output |
| 130 |
Register 3C2h bit 2-3. Switch high if set. |
| 131 |
(apparently always 1 on VGA) |
| 132 |
5 (EGA) Pin 19 of the Feature Connector (FEAT0) is high if set |
| 133 |
6 (EGA) Pin 17 of the Feature Connector (FEAT1) is high if set |
| 134 |
(default differs by card, ET4000 sets them both) |
| 135 |
7 If set IRQ 2 has happened due to Vertical Retrace. |
| 136 |
Should be cleared by IRQ 2 interrupt routine by clearing port 3d4h |
| 137 |
index 11h bit 4. |
| 138 |
*/ |
| 139 |
} |
| 140 |
|
| 141 |
void VGA_SetupMisc(void) { |
| 142 |
if (IS_EGAVGA_ARCH) { |
| 143 |
vga.draw.vret_triggered=false; |
| 144 |
IO_RegisterReadHandler(0x3c2,read_p3c2,IO_MB); |
| 145 |
IO_RegisterWriteHandler(0x3c2,write_p3c2,IO_MB); |
| 146 |
if (IS_VGA_ARCH) { |
| 147 |
IO_RegisterReadHandler(0x3ca,read_p3ca,IO_MB); |
| 148 |
IO_RegisterReadHandler(0x3cc,read_p3cc,IO_MB); |
| 149 |
} else { |
| 150 |
IO_RegisterReadHandler(0x3c8,read_p3c8,IO_MB); |
| 151 |
} |
| 152 |
} else if (machine==MCH_CGA || IS_TANDY_ARCH) { |
| 153 |
IO_RegisterReadHandler(0x3da,vga_read_p3da,IO_MB); |
| 154 |
} |
| 155 |
} |