src/mess/video/ibm_vga.c
| r14611 | r14612 | |
| 1 | | /*************************************************************************** |
| 2 | | |
| 3 | | Video Graphics Adapter (VGA) section |
| 4 | | |
| 5 | | ***************************************************************************/ |
| 6 | | |
| 7 | | #include "emu.h" |
| 8 | | #include "ibm_vga.h" |
| 9 | | #include "video/mc6845.h" |
| 10 | | |
| 11 | | #define VGA_SCREEN_NAME "vga_screen" |
| 12 | | #define VGA_MC6845_NAME "vga_mc6845" |
| 13 | | |
| 14 | | #define LOG_ACCESSES (1) |
| 15 | | |
| 16 | | #define CRTC_PORT_ADDR ((m_misc_out_reg & 1) ? 0x3d0 : 0x3b0 ) |
| 17 | | |
| 18 | | READ8_MEMBER(ibm_vga_device::vga_crtc_r) |
| 19 | | { |
| 20 | | int data = 0xff; |
| 21 | | switch( offset ) |
| 22 | | { |
| 23 | | case 4: |
| 24 | | /* return last written mc6845 address value here? */ |
| 25 | | break; |
| 26 | | case 5: |
| 27 | | data = m_crtc->register_r( space, offset ); |
| 28 | | break; |
| 29 | | } |
| 30 | | return data; |
| 31 | | |
| 32 | | } |
| 33 | | |
| 34 | | WRITE8_MEMBER(ibm_vga_device::vga_crtc_w) |
| 35 | | { |
| 36 | | switch(offset) |
| 37 | | { |
| 38 | | case 4: |
| 39 | | m_crtc->address_w( space, offset, data ); |
| 40 | | break; |
| 41 | | case 5: |
| 42 | | m_crtc->register_w( space, offset, data ); |
| 43 | | break; |
| 44 | | } |
| 45 | | } |
| 46 | | |
| 47 | | READ8_MEMBER(ibm_vga_device::vga_port_03b0_r) |
| 48 | | { |
| 49 | | UINT8 retVal = 0xff; |
| 50 | | if (CRTC_PORT_ADDR == 0x3b0) |
| 51 | | retVal = vga_crtc_r(space, offset); |
| 52 | | //if (LOG_ACCESSES) |
| 53 | | //logerror("vga_port_03b0_r(): port=0x%04x data=0x%02x\n", offset + 0x3b0, retVal); |
| 54 | | return retVal; |
| 55 | | } |
| 56 | | |
| 57 | | WRITE8_MEMBER( ibm_vga_device::vga_port_03b0_w ) |
| 58 | | { |
| 59 | | //if (LOG_ACCESSES) |
| 60 | | //logerror("vga_port_03b0_w(): port=0x%04x data=0x%02x\n", offset + 0x3b0, data); |
| 61 | | if (CRTC_PORT_ADDR == 0x3b0) |
| 62 | | vga_crtc_w(space, offset, data); |
| 63 | | } |
| 64 | | |
| 65 | | READ8_MEMBER( ibm_vga_device::vga_port_03c0_r) |
| 66 | | { |
| 67 | | UINT8 retVal = 0xff; |
| 68 | | |
| 69 | | switch(offset) { |
| 70 | | case 0x01: // Attribute controller |
| 71 | | if (m_attr_state==0) |
| 72 | | { |
| 73 | | retVal = m_attr_idx; |
| 74 | | } |
| 75 | | else |
| 76 | | { |
| 77 | | retVal = m_attr_data[m_attr_idx & 0x1f]; |
| 78 | | } |
| 79 | | break; |
| 80 | | case 0x04 : // Sequencer Index Register |
| 81 | | retVal = m_seq_idx; |
| 82 | | break; |
| 83 | | case 0x05 : // Sequencer Data Register |
| 84 | | retVal = m_seq_data[m_seq_idx & 0x1f]; |
| 85 | | break; |
| 86 | | case 0x06 : // Video DAC Pel Mask Register |
| 87 | | retVal = m_dac_mask; |
| 88 | | break; |
| 89 | | case 0x07 : // Video DAC Index (CLUT Reads) |
| 90 | | if (m_dac_read) |
| 91 | | retVal = 0; |
| 92 | | else |
| 93 | | retVal = 3; |
| 94 | | break; |
| 95 | | case 0x08 : // Video DAC Index (CLUT Writes) |
| 96 | | retVal = m_dac_write_idx; |
| 97 | | break; |
| 98 | | case 0x09 : // Video DAC Data Register |
| 99 | | if (m_dac_read) |
| 100 | | { |
| 101 | | retVal = m_dac_color[m_dac_state++][m_dac_read_idx]; |
| 102 | | if (m_dac_state==3) |
| 103 | | { |
| 104 | | m_dac_state = 0; |
| 105 | | m_dac_read_idx++; |
| 106 | | } |
| 107 | | } |
| 108 | | break; |
| 109 | | case 0x0a : // |
| 110 | | retVal = m_feature_ctrl; |
| 111 | | break; |
| 112 | | case 0x0c : // Miscellaneous Output Register |
| 113 | | retVal = m_misc_out_reg; |
| 114 | | break; |
| 115 | | case 0x0e : // Graphics Index Register |
| 116 | | retVal = m_gc_idx; |
| 117 | | break; |
| 118 | | case 0x0f : // Graphics Data Register |
| 119 | | retVal = m_gc_data[m_gc_idx & 0x1f]; |
| 120 | | break; |
| 121 | | } |
| 122 | | |
| 123 | | if (LOG_ACCESSES) |
| 124 | | logerror("vga_port_03c0_r(): port=0x%04x data=0x%02x\n", offset + 0x3c0, retVal); |
| 125 | | return retVal; |
| 126 | | } |
| 127 | | |
| 128 | | WRITE8_MEMBER( ibm_vga_device::vga_port_03c0_w ) |
| 129 | | { |
| 130 | | if (LOG_ACCESSES) |
| 131 | | logerror("vga_port_03c0_w(): port=0x%04x data=0x%02x\n", offset + 0x3c0, data); |
| 132 | | |
| 133 | | switch(offset) { |
| 134 | | case 0x00: // Attribute Controller |
| 135 | | if (m_attr_state==0) |
| 136 | | { |
| 137 | | m_attr_idx = data; |
| 138 | | } |
| 139 | | else |
| 140 | | { |
| 141 | | m_attr_data[m_attr_idx & 0x1f] = data; |
| 142 | | } |
| 143 | | m_attr_state=!m_attr_state; |
| 144 | | break; |
| 145 | | case 0x02 : // Miscellaneous Output Register |
| 146 | | m_misc_out_reg = data; |
| 147 | | break; |
| 148 | | case 0x04 : // Sequencer Index Register |
| 149 | | m_seq_idx = data; |
| 150 | | break; |
| 151 | | case 0x05 : // Sequencer Data Register |
| 152 | | m_seq_data[m_seq_idx & 0x1f] = data; |
| 153 | | break; |
| 154 | | case 0x06 : // Video DAC Pel Mask Register |
| 155 | | m_dac_mask = data; |
| 156 | | break; |
| 157 | | case 0x07 : // Video DAC Index (CLUT Reads) |
| 158 | | m_dac_read_idx = data; |
| 159 | | m_dac_state = 0; |
| 160 | | m_dac_read = 1; |
| 161 | | break; |
| 162 | | case 0x08 : // Video DAC Index (CLUT Writes) |
| 163 | | m_dac_write_idx = data; |
| 164 | | m_dac_state = 0; |
| 165 | | m_dac_read = 0; |
| 166 | | break; |
| 167 | | case 0x09 : // Video DAC Data Register |
| 168 | | if (!m_dac_read) |
| 169 | | { |
| 170 | | m_dac_color[m_dac_state++][m_dac_write_idx] = data; |
| 171 | | if (m_dac_state==3) { |
| 172 | | m_dac_state=0; |
| 173 | | m_dac_write_idx++; |
| 174 | | } |
| 175 | | } |
| 176 | | break; |
| 177 | | case 0x0e : // Graphics Index Register |
| 178 | | m_gc_idx = data; |
| 179 | | break; |
| 180 | | case 0x0f : // Graphics Data Register |
| 181 | | m_gc_data[m_gc_idx & 0x1f] = data; |
| 182 | | break; |
| 183 | | } |
| 184 | | } |
| 185 | | |
| 186 | | READ8_MEMBER( ibm_vga_device::vga_port_03d0_r) |
| 187 | | { |
| 188 | | UINT8 retVal = 0xff; |
| 189 | | if (CRTC_PORT_ADDR == 0x3d0) |
| 190 | | retVal = vga_crtc_r(space, offset); |
| 191 | | //if (LOG_ACCESSES) |
| 192 | | // logerror("vga_port_03d0_r(): port=0x%04x data=0x%02x\n", offset + 0x3d0, retVal); |
| 193 | | return retVal; |
| 194 | | } |
| 195 | | |
| 196 | | WRITE8_MEMBER( ibm_vga_device::vga_port_03d0_w ) |
| 197 | | { |
| 198 | | // if (LOG_ACCESSES) |
| 199 | | //logerror("vga_port_03d0_w(): port=0x%04x data=0x%02x\n", offset + 0x3d0, data); |
| 200 | | if (CRTC_PORT_ADDR == 0x3d0) |
| 201 | | vga_crtc_w(space, offset, data); |
| 202 | | } |
| 203 | | |
| 204 | | |
| 205 | | static MC6845_UPDATE_ROW( vga_update_row ) |
| 206 | | { |
| 207 | | } |
| 208 | | |
| 209 | | static const mc6845_interface mc6845_vga_intf = |
| 210 | | { |
| 211 | | VGA_SCREEN_NAME, /* screen number */ |
| 212 | | 8, /* numbers of pixels per video memory address */ |
| 213 | | NULL, /* begin_update */ |
| 214 | | vga_update_row, /* update_row */ |
| 215 | | NULL, /* end_update */ |
| 216 | | DEVCB_NULL, /* on_de_changed */ |
| 217 | | DEVCB_NULL, /* on_cur_changed */ |
| 218 | | DEVCB_NULL, /* on_hsync_changed */ |
| 219 | | DEVCB_NULL, /* on_vsync_changed */ |
| 220 | | NULL |
| 221 | | }; |
| 222 | | |
| 223 | | //************************************************************************** |
| 224 | | // GLOBAL VARIABLES |
| 225 | | //************************************************************************** |
| 226 | | |
| 227 | | const device_type IBM_VGA = &device_creator<ibm_vga_device>; |
| 228 | | |
| 229 | | static MACHINE_CONFIG_FRAGMENT( ibm_vga ) |
| 230 | | MCFG_SCREEN_ADD(VGA_SCREEN_NAME, RASTER) |
| 231 | | MCFG_SCREEN_RAW_PARAMS(XTAL_14_31818MHz,912,0,640,262,0,200) |
| 232 | | MCFG_SCREEN_UPDATE_DEVICE( VGA_MC6845_NAME, mc6845_device, screen_update ) |
| 233 | | |
| 234 | | MCFG_MC6845_ADD(VGA_MC6845_NAME, MC6845, XTAL_14_31818MHz/8, mc6845_vga_intf) |
| 235 | | MACHINE_CONFIG_END |
| 236 | | |
| 237 | | ROM_START( ibm_vga ) |
| 238 | | ROM_REGION(0x10000, "vga", 0) |
| 239 | | ROM_LOAD("8222554.bin", 0x00000, 0x6000, CRC(6c12d745) SHA1(c0156607100e377c6c9563f23967409dab3ab92b)) |
| 240 | | ROM_END |
| 241 | | |
| 242 | | |
| 243 | | //------------------------------------------------- |
| 244 | | // rom_region - return a pointer to the device's |
| 245 | | // internal ROM region |
| 246 | | //------------------------------------------------- |
| 247 | | |
| 248 | | const rom_entry *ibm_vga_device::device_rom_region() const |
| 249 | | { |
| 250 | | return ROM_NAME(ibm_vga); |
| 251 | | } |
| 252 | | |
| 253 | | //------------------------------------------------- |
| 254 | | // machine_config_additions - return a pointer to |
| 255 | | // the device's machine fragment |
| 256 | | //------------------------------------------------- |
| 257 | | |
| 258 | | machine_config_constructor ibm_vga_device::device_mconfig_additions() const |
| 259 | | { |
| 260 | | return MACHINE_CONFIG_NAME(ibm_vga); |
| 261 | | } |
| 262 | | |
| 263 | | //************************************************************************** |
| 264 | | // LIVE DEVICE |
| 265 | | //************************************************************************** |
| 266 | | |
| 267 | | //------------------------------------------------- |
| 268 | | // ibm_vga_device - constructor |
| 269 | | //------------------------------------------------- |
| 270 | | |
| 271 | | ibm_vga_device::ibm_vga_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 272 | | : device_t(mconfig, IBM_VGA, "IBM VGA", tag, owner, clock), |
| 273 | | m_crtc(*this, VGA_MC6845_NAME) |
| 274 | | { |
| 275 | | m_shortname = "ibm_vga"; |
| 276 | | } |
| 277 | | |
| 278 | | /*------------------------------------------------- |
| 279 | | device_start - device-specific startup |
| 280 | | -------------------------------------------------*/ |
| 281 | | |
| 282 | | void ibm_vga_device::device_start() |
| 283 | | { |
| 284 | | int buswidth; |
| 285 | | astring tempstring; |
| 286 | | address_space *spaceio = machine().firstcpu->memory().space(AS_IO); |
| 287 | | address_space *space = machine().firstcpu->memory().space(AS_PROGRAM); |
| 288 | | space->install_rom(0xc0000, 0xc5fff, machine().region(subtag(tempstring, "vga"))->base()); |
| 289 | | buswidth = machine().firstcpu->memory().space_config(AS_PROGRAM)->m_databus_width; |
| 290 | | switch(buswidth) |
| 291 | | { |
| 292 | | case 8: |
| 293 | | spaceio->install_readwrite_handler(0x3b0, 0x3bf, read8_delegate(FUNC(ibm_vga_device::vga_port_03b0_r), this), write8_delegate(FUNC(ibm_vga_device::vga_port_03b0_w), this)); |
| 294 | | spaceio->install_readwrite_handler(0x3c0, 0x3cf, read8_delegate(FUNC(ibm_vga_device::vga_port_03c0_r), this), write8_delegate(FUNC(ibm_vga_device::vga_port_03c0_w), this)); |
| 295 | | spaceio->install_readwrite_handler(0x3d0, 0x3df, read8_delegate(FUNC(ibm_vga_device::vga_port_03d0_r), this), write8_delegate(FUNC(ibm_vga_device::vga_port_03d0_w), this)); |
| 296 | | break; |
| 297 | | |
| 298 | | case 16: |
| 299 | | spaceio->install_readwrite_handler(0x3b0, 0x3bf, read8_delegate(FUNC(ibm_vga_device::vga_port_03b0_r), this), write8_delegate(FUNC(ibm_vga_device::vga_port_03b0_w), this), 0xffff); |
| 300 | | spaceio->install_readwrite_handler(0x3c0, 0x3cf, read8_delegate(FUNC(ibm_vga_device::vga_port_03c0_r), this), write8_delegate(FUNC(ibm_vga_device::vga_port_03c0_w), this), 0xffff); |
| 301 | | spaceio->install_readwrite_handler(0x3d0, 0x3df, read8_delegate(FUNC(ibm_vga_device::vga_port_03d0_r), this), write8_delegate(FUNC(ibm_vga_device::vga_port_03d0_w), this), 0xffff); |
| 302 | | break; |
| 303 | | |
| 304 | | case 32: |
| 305 | | break; |
| 306 | | |
| 307 | | case 64: |
| 308 | | break; |
| 309 | | |
| 310 | | default: |
| 311 | | fatalerror("VGA: Bus width %d not supported", buswidth); |
| 312 | | break; |
| 313 | | } |
| 314 | | m_videoram = auto_alloc_array(machine(), UINT8, 0x40000); |
| 315 | | space->install_readwrite_bank(0xa0000, 0xbffff, "vga_bank" ); |
| 316 | | memory_set_bankptr(machine(),"vga_bank", m_videoram); |
| 317 | | } |
| 318 | | |
| 319 | | /*------------------------------------------------- |
| 320 | | device_reset - device-specific reset |
| 321 | | -------------------------------------------------*/ |
| 322 | | |
| 323 | | void ibm_vga_device::device_reset() |
| 324 | | { |
| 325 | | m_misc_out_reg = 0; |
| 326 | | m_feature_ctrl = 0; |
| 327 | | |
| 328 | | m_seq_idx = 0; |
| 329 | | memset(m_seq_data,0xff,0x1f); |
| 330 | | |
| 331 | | m_attr_idx = 0; |
| 332 | | memset(m_attr_data,0xff,0x1f); |
| 333 | | m_attr_state = 0; |
| 334 | | |
| 335 | | m_gc_idx = 0; |
| 336 | | memset(m_gc_data,0xff,0x1f); |
| 337 | | |
| 338 | | m_dac_mask = 0; |
| 339 | | m_dac_write_idx = 0; |
| 340 | | m_dac_read_idx = 0; |
| 341 | | m_dac_read = 0; |
| 342 | | m_dac_state = 0; |
| 343 | | memset(m_dac_color,0,sizeof(m_dac_color)); |
| 344 | | |
| 345 | | for (int i = 0; i < 0x100; i++) |
| 346 | | palette_set_color_rgb(machine(), i, 0, 0, 0); |
| 347 | | } |