src/mess/video/nubus_m2hires.c
| r0 | r12563 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | Apple Hi-Resolution Video Card emulation |
| 4 | |
| 5 | RAMDAC: control at Fs0940e0, data at Fs0940e4 |
| 6 | Fs090010 bit 16 is vbl status, bit 17 must be "1" for proper operation |
| 7 | Fs08000x are the control registers |
| 8 | |
| 9 | ***************************************************************************/ |
| 10 | |
| 11 | #include "emu.h" |
| 12 | #include "video/nubus_m2hires.h" |
| 13 | |
| 14 | #define M2HIRES_SCREEN_NAME "m2hires_screen" |
| 15 | #define M2HIRES_ROM_REGION "m2hires_rom" |
| 16 | |
| 17 | #define VRAM_SIZE (0x80000) // 512k max |
| 18 | |
| 19 | static SCREEN_UPDATE( m2hires ); |
| 20 | |
| 21 | MACHINE_CONFIG_FRAGMENT( m2hires ) |
| 22 | MCFG_SCREEN_ADD( M2HIRES_SCREEN_NAME, RASTER) |
| 23 | MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32) |
| 24 | MCFG_SCREEN_UPDATE(m2hires) |
| 25 | MCFG_SCREEN_RAW_PARAMS(25175000, 800, 0, 640, 525, 0, 480) |
| 26 | MCFG_SCREEN_SIZE(1024,768) |
| 27 | MCFG_SCREEN_VISIBLE_AREA(0, 640-1, 0, 480-1) |
| 28 | MACHINE_CONFIG_END |
| 29 | |
| 30 | ROM_START( m2hires ) |
| 31 | ROM_REGION(0x2000, M2HIRES_ROM_REGION, 0) |
| 32 | ROM_LOAD( "341-0660.bin", 0x0000, 0x2000, CRC(ea6f7913) SHA1(37c59f38ae34021d0cb86c2e76a598b7e6077c0d) ) |
| 33 | ROM_END |
| 34 | |
| 35 | //************************************************************************** |
| 36 | // GLOBAL VARIABLES |
| 37 | //************************************************************************** |
| 38 | |
| 39 | const device_type NUBUS_M2HIRES = &device_creator<nubus_m2hires_device>; |
| 40 | |
| 41 | |
| 42 | //------------------------------------------------- |
| 43 | // machine_config_additions - device-specific |
| 44 | // machine configurations |
| 45 | //------------------------------------------------- |
| 46 | |
| 47 | machine_config_constructor nubus_m2hires_device::device_mconfig_additions() const |
| 48 | { |
| 49 | return MACHINE_CONFIG_NAME( m2hires ); |
| 50 | } |
| 51 | |
| 52 | //------------------------------------------------- |
| 53 | // rom_region - device-specific ROM region |
| 54 | //------------------------------------------------- |
| 55 | |
| 56 | const rom_entry *nubus_m2hires_device::device_rom_region() const |
| 57 | { |
| 58 | return ROM_NAME( m2hires ); |
| 59 | } |
| 60 | |
| 61 | //************************************************************************** |
| 62 | // LIVE DEVICE |
| 63 | //************************************************************************** |
| 64 | |
| 65 | //------------------------------------------------- |
| 66 | // nubus_m2hires_device - constructor |
| 67 | //------------------------------------------------- |
| 68 | |
| 69 | nubus_m2hires_device::nubus_m2hires_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 70 | device_t(mconfig, NUBUS_M2HIRES, "Macintosh II Hi-Resolution video card", tag, owner, clock), |
| 71 | device_nubus_card_interface(mconfig, *this), |
| 72 | device_slot_card_interface(mconfig, *this) |
| 73 | { |
| 74 | m_shortname = "nb_m2hr"; |
| 75 | } |
| 76 | |
| 77 | nubus_m2hires_device::nubus_m2hires_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock) : |
| 78 | device_t(mconfig, type, name, tag, owner, clock), |
| 79 | device_nubus_card_interface(mconfig, *this), |
| 80 | device_slot_card_interface(mconfig, *this) |
| 81 | { |
| 82 | m_shortname = "nb_m2hr"; |
| 83 | } |
| 84 | |
| 85 | //------------------------------------------------- |
| 86 | // device_start - device-specific startup |
| 87 | //------------------------------------------------- |
| 88 | |
| 89 | void nubus_m2hires_device::device_start() |
| 90 | { |
| 91 | UINT32 slotspace; |
| 92 | |
| 93 | // set_nubus_device makes m_slot valid |
| 94 | set_nubus_device(); |
| 95 | install_declaration_rom(this, M2HIRES_ROM_REGION); |
| 96 | |
| 97 | slotspace = get_slotspace(); |
| 98 | |
| 99 | // printf("[m2hires %p] slotspace = %x\n", this, slotspace); |
| 100 | |
| 101 | m_vram = auto_alloc_array(machine(), UINT8, VRAM_SIZE); |
| 102 | m_vram32 = (UINT32 *)m_vram; |
| 103 | |
| 104 | m_nubus->install_device(slotspace, slotspace+VRAM_SIZE-1, read32_delegate(FUNC(nubus_m2hires_device::vram_r), this), write32_delegate(FUNC(nubus_m2hires_device::vram_w), this)); |
| 105 | m_nubus->install_device(slotspace+0x900000, slotspace+VRAM_SIZE-1+0x900000, read32_delegate(FUNC(nubus_m2hires_device::vram_r), this), write32_delegate(FUNC(nubus_m2hires_device::vram_w), this)); |
| 106 | m_nubus->install_device(slotspace+0x80000, slotspace+0x8fffff, read32_delegate(FUNC(nubus_m2hires_device::m2hires_r), this), write32_delegate(FUNC(nubus_m2hires_device::m2hires_w), this)); |
| 107 | |
| 108 | m_timer = timer_alloc(0, NULL); |
| 109 | m_screen = NULL; // can we look this up now? |
| 110 | } |
| 111 | |
| 112 | //------------------------------------------------- |
| 113 | // device_reset - device-specific reset |
| 114 | //------------------------------------------------- |
| 115 | |
| 116 | void nubus_m2hires_device::device_reset() |
| 117 | { |
| 118 | m_count = 0; |
| 119 | m_clutoffs = 0; |
| 120 | m_vbl_disable = 1; |
| 121 | m_mode = 0; |
| 122 | memset(m_vram, 0, VRAM_SIZE); |
| 123 | memset(m_palette, 0, sizeof(m_palette)); |
| 124 | |
| 125 | m_palette[0] = MAKE_RGB(255, 255, 255); |
| 126 | m_palette[0x80] = MAKE_RGB(0, 0, 0); |
| 127 | } |
| 128 | |
| 129 | |
| 130 | void nubus_m2hires_device::device_timer(emu_timer &timer, device_timer_id tid, int param, void *ptr) |
| 131 | { |
| 132 | if (!m_vbl_disable) |
| 133 | { |
| 134 | m_nubus->set_irq_line(m_slot, ASSERT_LINE); |
| 135 | } |
| 136 | |
| 137 | m_timer->adjust(m_screen->time_until_pos(479, 0), 0); |
| 138 | } |
| 139 | |
| 140 | /*************************************************************************** |
| 141 | |
| 142 | Spectrum 24 PDQ section |
| 143 | |
| 144 | ***************************************************************************/ |
| 145 | |
| 146 | static SCREEN_UPDATE( m2hires ) |
| 147 | { |
| 148 | UINT32 *scanline; |
| 149 | int x, y; |
| 150 | nubus_m2hires_device *card = downcast<nubus_m2hires_device *>(screen->owner()); |
| 151 | UINT8 pixels, *vram; |
| 152 | |
| 153 | // first time? kick off the VBL timer |
| 154 | if (!card->m_screen) |
| 155 | { |
| 156 | card->m_screen = screen; |
| 157 | card->m_timer->adjust(card->m_screen->time_until_pos(479, 0), 0); |
| 158 | } |
| 159 | |
| 160 | vram = card->m_vram + 0x20; |
| 161 | |
| 162 | switch (card->m_mode) |
| 163 | { |
| 164 | case 0: // 1 bpp? |
| 165 | for (y = 0; y < 480; y++) |
| 166 | { |
| 167 | scanline = BITMAP_ADDR32(bitmap, y, 0); |
| 168 | for (x = 0; x < 640/8; x++) |
| 169 | { |
| 170 | pixels = vram[(y * 128) + (BYTE4_XOR_BE(x))]; |
| 171 | |
| 172 | *scanline++ = card->m_palette[((pixels>>7)&0x1)]; |
| 173 | *scanline++ = card->m_palette[((pixels>>6)&0x1)]; |
| 174 | *scanline++ = card->m_palette[((pixels>>5)&0x1)]; |
| 175 | *scanline++ = card->m_palette[((pixels>>4)&0x1)]; |
| 176 | *scanline++ = card->m_palette[((pixels>>3)&0x1)]; |
| 177 | *scanline++ = card->m_palette[((pixels>>2)&0x1)]; |
| 178 | *scanline++ = card->m_palette[((pixels>>1)&0x1)]; |
| 179 | *scanline++ = card->m_palette[(pixels&1)]; |
| 180 | } |
| 181 | } |
| 182 | break; |
| 183 | |
| 184 | case 1: // 2 bpp |
| 185 | for (y = 0; y < 480; y++) |
| 186 | { |
| 187 | scanline = BITMAP_ADDR32(bitmap, y, 0); |
| 188 | for (x = 0; x < 640/4; x++) |
| 189 | { |
| 190 | pixels = vram[(y * 256) + (BYTE4_XOR_BE(x))]; |
| 191 | |
| 192 | *scanline++ = card->m_palette[((pixels>>6)&3)]; |
| 193 | *scanline++ = card->m_palette[((pixels>>4)&3)]; |
| 194 | *scanline++ = card->m_palette[((pixels>>2)&3)]; |
| 195 | *scanline++ = card->m_palette[(pixels&3)]; |
| 196 | } |
| 197 | } |
| 198 | break; |
| 199 | |
| 200 | case 2: // 4 bpp |
| 201 | for (y = 0; y < 480; y++) |
| 202 | { |
| 203 | scanline = BITMAP_ADDR32(bitmap, y, 0); |
| 204 | |
| 205 | for (x = 0; x < 640/2; x++) |
| 206 | { |
| 207 | pixels = vram[(y * 512) + (BYTE4_XOR_BE(x))]; |
| 208 | |
| 209 | *scanline++ = card->m_palette[((pixels&0xf0)>>4)]; |
| 210 | *scanline++ = card->m_palette[(pixels&0xf)]; |
| 211 | } |
| 212 | } |
| 213 | break; |
| 214 | |
| 215 | case 3: // 8 bpp |
| 216 | for (y = 0; y < 480; y++) |
| 217 | { |
| 218 | scanline = BITMAP_ADDR32(bitmap, y, 0); |
| 219 | |
| 220 | for (x = 0; x < 640; x++) |
| 221 | { |
| 222 | pixels = vram[(y * 1024) + (BYTE4_XOR_BE(x))]; |
| 223 | *scanline++ = card->m_palette[pixels]; |
| 224 | } |
| 225 | } |
| 226 | break; |
| 227 | |
| 228 | default: |
| 229 | fatalerror("m2hires: unknown video mode %d", card->m_mode); |
| 230 | break; |
| 231 | |
| 232 | } |
| 233 | return 0; |
| 234 | } |
| 235 | |
| 236 | WRITE32_MEMBER( nubus_m2hires_device::m2hires_w ) |
| 237 | { |
| 238 | data ^= 0xffffffff; |
| 239 | |
| 240 | switch (offset) |
| 241 | { |
| 242 | case 1: // mode |
| 243 | switch (data) |
| 244 | { |
| 245 | case 0x20000000: |
| 246 | m_mode = 0; |
| 247 | break; |
| 248 | |
| 249 | case 0x40000000: |
| 250 | m_mode = 1; |
| 251 | break; |
| 252 | |
| 253 | case 0x80000000: |
| 254 | m_mode = 2; |
| 255 | break; |
| 256 | |
| 257 | case 0x00010000: |
| 258 | m_mode = 3; |
| 259 | break; |
| 260 | } |
| 261 | break; |
| 262 | |
| 263 | case 0x5038: // DAC control |
| 264 | // printf("%08x to DAC control (PC=%x)\n", data, cpu_get_pc(&space.device())); |
| 265 | m_clutoffs = (data>>24)&0xff; |
| 266 | break; |
| 267 | |
| 268 | case 0x5039: // DAC data |
| 269 | m_colors[m_count++] = (data>>24) & 0xff; |
| 270 | |
| 271 | if (m_count == 3) |
| 272 | { |
| 273 | // printf("RAMDAC: color %d = %02x %02x %02x (PC=%x)\n", m_clutoffs, m_colors[0], m_colors[1], m_colors[2], cpu_get_pc(&space.device()) ); |
| 274 | palette_set_color(space.machine(), m_clutoffs, MAKE_RGB(m_colors[0], m_colors[1], m_colors[2])); |
| 275 | m_palette[m_clutoffs] = MAKE_RGB(m_colors[0], m_colors[1], m_colors[2]); |
| 276 | m_clutoffs++; |
| 277 | if (m_clutoffs > 255) |
| 278 | { |
| 279 | m_clutoffs = 0; |
| 280 | } |
| 281 | m_count = 0; |
| 282 | } |
| 283 | break; |
| 284 | |
| 285 | case 0x8000: // enable and ack VBL |
| 286 | m_vbl_disable = 0; |
| 287 | m_nubus->set_irq_line(m_slot, CLEAR_LINE); |
| 288 | break; |
| 289 | |
| 290 | case 0x8001: // disable VBL |
| 291 | m_vbl_disable = 1; |
| 292 | break; |
| 293 | |
| 294 | default: |
| 295 | // printf("m2hires_w: %08x @ %x, mask %08x (PC=%x)\n", data, offset, mem_mask, cpu_get_pc(&space.device())); |
| 296 | break; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | READ32_MEMBER( nubus_m2hires_device::m2hires_r ) |
| 301 | { |
| 302 | if (offset == 0x10010/4) |
| 303 | { |
| 304 | m_toggle ^= (1<<16); |
| 305 | return m_toggle | (1<<17); // bit 17 indicates a 4/8bpp capable ASIC apparently; the firmware won't enter those modes otherwise (although they show in the list) |
| 306 | } |
| 307 | /* else |
| 308 | { |
| 309 | printf("m2hires_r: @ %x, mask %08x (PC=%x)\n", offset, mem_mask, cpu_get_pc(&space.device())); |
| 310 | }*/ |
| 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | WRITE32_MEMBER( nubus_m2hires_device::vram_w ) |
| 316 | { |
| 317 | data ^= 0xffffffff; |
| 318 | COMBINE_DATA(&m_vram32[offset]); |
| 319 | } |
| 320 | |
| 321 | READ32_MEMBER( nubus_m2hires_device::vram_r ) |
| 322 | { |
| 323 | return m_vram32[offset] ^ 0xffffffff; |
| 324 | } |