trunk/src/mess/video/nubus_m2video.c
| r0 | r18570 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | Apple Macintosh II Video Card (630-0153) emulation |
| 4 | |
| 5 | Video ASIC is "TFB" 344-0001 |
| 6 | RAMDAC is Bt453: control at Fs09001C, data at Fs090018 |
| 7 | Fs08000x is general framebuffer control (video mode at 0) |
| 8 | Fs0D0000 bit 0 is VBL status |
| 9 | |
| 10 | ***************************************************************************/ |
| 11 | |
| 12 | #include "emu.h" |
| 13 | #include "video/nubus_m2video.h" |
| 14 | |
| 15 | #define M2VIDEO_SCREEN_NAME "m2video_screen" |
| 16 | #define M2VIDEO_ROM_REGION "m2video_rom" |
| 17 | |
| 18 | #define VRAM_SIZE (0x80000) // 512k max |
| 19 | |
| 20 | MACHINE_CONFIG_FRAGMENT( m2video ) |
| 21 | MCFG_SCREEN_ADD( M2VIDEO_SCREEN_NAME, RASTER) |
| 22 | MCFG_SCREEN_UPDATE_DEVICE(DEVICE_SELF, nubus_m2video_device, screen_update) |
| 23 | MCFG_SCREEN_RAW_PARAMS(25175000, 800, 0, 640, 525, 0, 480) |
| 24 | MCFG_SCREEN_SIZE(1024,768) |
| 25 | MCFG_SCREEN_VISIBLE_AREA(0, 640-1, 0, 480-1) |
| 26 | MACHINE_CONFIG_END |
| 27 | |
| 28 | ROM_START( m2video ) |
| 29 | ROM_REGION(0x1000, M2VIDEO_ROM_REGION, 0) |
| 30 | ROM_LOAD( "342-0008-a.bin", 0x000000, 0x001000, CRC(bf50850d) SHA1(abe85d8a882bb2b8187a28bd6707fc2f5d77eedd) ) |
| 31 | ROM_END |
| 32 | |
| 33 | //************************************************************************** |
| 34 | // GLOBAL VARIABLES |
| 35 | //************************************************************************** |
| 36 | |
| 37 | const device_type NUBUS_M2VIDEO = &device_creator<nubus_m2video_device>; |
| 38 | |
| 39 | |
| 40 | //------------------------------------------------- |
| 41 | // machine_config_additions - device-specific |
| 42 | // machine configurations |
| 43 | //------------------------------------------------- |
| 44 | |
| 45 | machine_config_constructor nubus_m2video_device::device_mconfig_additions() const |
| 46 | { |
| 47 | return MACHINE_CONFIG_NAME( m2video ); |
| 48 | } |
| 49 | |
| 50 | //------------------------------------------------- |
| 51 | // rom_region - device-specific ROM region |
| 52 | //------------------------------------------------- |
| 53 | |
| 54 | const rom_entry *nubus_m2video_device::device_rom_region() const |
| 55 | { |
| 56 | return ROM_NAME( m2video ); |
| 57 | } |
| 58 | |
| 59 | //************************************************************************** |
| 60 | // LIVE DEVICE |
| 61 | //************************************************************************** |
| 62 | |
| 63 | //------------------------------------------------- |
| 64 | // nubus_m2video_device - constructor |
| 65 | //------------------------------------------------- |
| 66 | |
| 67 | nubus_m2video_device::nubus_m2video_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 68 | device_t(mconfig, NUBUS_M2VIDEO, "Macintosh II Video Card", tag, owner, clock), |
| 69 | device_nubus_card_interface(mconfig, *this) |
| 70 | { |
| 71 | m_shortname = "nb_m2vc"; |
| 72 | } |
| 73 | |
| 74 | nubus_m2video_device::nubus_m2video_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock) : |
| 75 | device_t(mconfig, type, name, tag, owner, clock), |
| 76 | device_nubus_card_interface(mconfig, *this) |
| 77 | { |
| 78 | m_shortname = "nb_m2vc"; |
| 79 | } |
| 80 | |
| 81 | //------------------------------------------------- |
| 82 | // device_start - device-specific startup |
| 83 | //------------------------------------------------- |
| 84 | |
| 85 | void nubus_m2video_device::device_start() |
| 86 | { |
| 87 | UINT32 slotspace; |
| 88 | |
| 89 | // set_nubus_device makes m_slot valid |
| 90 | set_nubus_device(); |
| 91 | install_declaration_rom(this, M2VIDEO_ROM_REGION, true, true); |
| 92 | |
| 93 | slotspace = get_slotspace(); |
| 94 | |
| 95 | // printf("[m2video %p] slotspace = %x\n", this, slotspace); |
| 96 | |
| 97 | m_vram = auto_alloc_array(machine(), UINT8, VRAM_SIZE); |
| 98 | m_vram32 = (UINT32 *)m_vram; |
| 99 | |
| 100 | m_nubus->install_device(slotspace, slotspace+VRAM_SIZE-1, read32_delegate(FUNC(nubus_m2video_device::vram_r), this), write32_delegate(FUNC(nubus_m2video_device::vram_w), this)); |
| 101 | m_nubus->install_device(slotspace+0x900000, slotspace+VRAM_SIZE-1+0x900000, read32_delegate(FUNC(nubus_m2video_device::vram_r), this), write32_delegate(FUNC(nubus_m2video_device::vram_w), this)); |
| 102 | m_nubus->install_device(slotspace+0x80000, slotspace+0xeffff, read32_delegate(FUNC(nubus_m2video_device::m2video_r), this), write32_delegate(FUNC(nubus_m2video_device::m2video_w), this)); |
| 103 | |
| 104 | m_timer = timer_alloc(0, NULL); |
| 105 | m_screen = NULL; // can we look this up now? |
| 106 | } |
| 107 | |
| 108 | //------------------------------------------------- |
| 109 | // device_reset - device-specific reset |
| 110 | //------------------------------------------------- |
| 111 | |
| 112 | void nubus_m2video_device::device_reset() |
| 113 | { |
| 114 | m_count = 0; |
| 115 | m_clutoffs = 0; |
| 116 | m_vbl_disable = 1; |
| 117 | m_mode = 0; |
| 118 | memset(m_vram, 0, VRAM_SIZE); |
| 119 | memset(m_palette, 0, sizeof(m_palette)); |
| 120 | |
| 121 | m_palette[0] = MAKE_RGB(255, 255, 255); |
| 122 | m_palette[0x80] = MAKE_RGB(0, 0, 0); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | void nubus_m2video_device::device_timer(emu_timer &timer, device_timer_id tid, int param, void *ptr) |
| 127 | { |
| 128 | if (!m_vbl_disable) |
| 129 | { |
| 130 | raise_slot_irq(); |
| 131 | } |
| 132 | |
| 133 | m_timer->adjust(m_screen->time_until_pos(479, 0), 0); |
| 134 | } |
| 135 | |
| 136 | /*************************************************************************** |
| 137 | |
| 138 | "TFB" section |
| 139 | |
| 140 | ***************************************************************************/ |
| 141 | |
| 142 | UINT32 nubus_m2video_device::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) |
| 143 | { |
| 144 | UINT32 *scanline; |
| 145 | int x, y; |
| 146 | UINT8 pixels, *vram; |
| 147 | |
| 148 | // first time? kick off the VBL timer |
| 149 | if (!m_screen) |
| 150 | { |
| 151 | m_screen = &screen; |
| 152 | m_timer->adjust(m_screen->time_until_pos(479, 0), 0); |
| 153 | } |
| 154 | |
| 155 | vram = m_vram + 0x20; |
| 156 | |
| 157 | switch (m_mode) |
| 158 | { |
| 159 | case 0: // 1 bpp? |
| 160 | for (y = 0; y < 480; y++) |
| 161 | { |
| 162 | scanline = &bitmap.pix32(y); |
| 163 | for (x = 0; x < 640/8; x++) |
| 164 | { |
| 165 | pixels = vram[(y * 128) + (BYTE4_XOR_BE(x))]; |
| 166 | |
| 167 | *scanline++ = m_palette[(pixels&0x80)]; |
| 168 | *scanline++ = m_palette[((pixels<<1)&0x80)]; |
| 169 | *scanline++ = m_palette[((pixels<<2)&0x80)]; |
| 170 | *scanline++ = m_palette[((pixels<<3)&0x80)]; |
| 171 | *scanline++ = m_palette[((pixels<<4)&0x80)]; |
| 172 | *scanline++ = m_palette[((pixels<<5)&0x80)]; |
| 173 | *scanline++ = m_palette[((pixels<<6)&0x80)]; |
| 174 | *scanline++ = m_palette[((pixels<<7)&0x80)]; |
| 175 | } |
| 176 | } |
| 177 | break; |
| 178 | |
| 179 | case 1: // 2 bpp |
| 180 | for (y = 0; y < 480; y++) |
| 181 | { |
| 182 | scanline = &bitmap.pix32(y); |
| 183 | for (x = 0; x < 640/4; x++) |
| 184 | { |
| 185 | pixels = vram[(y * 256) + (BYTE4_XOR_BE(x))]; |
| 186 | |
| 187 | *scanline++ = m_palette[(pixels&0xc0)]; |
| 188 | *scanline++ = m_palette[((pixels<<2)&0xc0)]; |
| 189 | *scanline++ = m_palette[((pixels<<4)&0xc0)]; |
| 190 | *scanline++ = m_palette[((pixels<<6)&0xc0)]; |
| 191 | } |
| 192 | } |
| 193 | break; |
| 194 | |
| 195 | case 2: // 4 bpp |
| 196 | for (y = 0; y < 480; y++) |
| 197 | { |
| 198 | scanline = &bitmap.pix32(y); |
| 199 | |
| 200 | for (x = 0; x < 640/2; x++) |
| 201 | { |
| 202 | pixels = vram[(y * 512) + (BYTE4_XOR_BE(x))]; |
| 203 | |
| 204 | *scanline++ = m_palette[(pixels&0xf0)]; |
| 205 | *scanline++ = m_palette[((pixels&0x0f)<<4)]; |
| 206 | } |
| 207 | } |
| 208 | break; |
| 209 | |
| 210 | case 3: // 8 bpp |
| 211 | for (y = 0; y < 480; y++) |
| 212 | { |
| 213 | scanline = &bitmap.pix32(y); |
| 214 | |
| 215 | for (x = 0; x < 640; x++) |
| 216 | { |
| 217 | pixels = vram[(y * 1024) + (BYTE4_XOR_BE(x))]; |
| 218 | *scanline++ = m_palette[pixels]; |
| 219 | } |
| 220 | } |
| 221 | break; |
| 222 | |
| 223 | default: |
| 224 | fatalerror("m2video: unknown video mode %d\n", m_mode); |
| 225 | break; |
| 226 | } |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | WRITE32_MEMBER( nubus_m2video_device::m2video_w ) |
| 231 | { |
| 232 | data ^= 0xffffffff; |
| 233 | switch (offset) |
| 234 | { |
| 235 | case 0: // mode |
| 236 | switch (data & 0xff000000) |
| 237 | { |
| 238 | case 0x20000000: |
| 239 | m_mode = 0; |
| 240 | break; |
| 241 | |
| 242 | case 0x40000000: |
| 243 | m_mode = 1; |
| 244 | break; |
| 245 | |
| 246 | case 0x80000000: |
| 247 | m_mode = 2; |
| 248 | break; |
| 249 | |
| 250 | case 0x00000000: |
| 251 | m_mode = 3; |
| 252 | break; |
| 253 | } |
| 254 | break; |
| 255 | |
| 256 | case 0x4007: // DAC control |
| 257 | // printf("%08x to DAC control (PC=%x)\n", data, space.device().safe_pc()); |
| 258 | m_clutoffs = (data>>24)&0xff; |
| 259 | break; |
| 260 | |
| 261 | case 0x4006: // DAC data |
| 262 | m_colors[m_count++] = (data>>24) & 0xff; |
| 263 | |
| 264 | if (m_count == 3) |
| 265 | { |
| 266 | printf("RAMDAC: color %02x = %02x %02x %02x (PC=%x)\n", m_clutoffs, m_colors[0], m_colors[1], m_colors[2], space.device().safe_pc() ); |
| 267 | m_palette[m_clutoffs] = MAKE_RGB(m_colors[0], m_colors[1], m_colors[2]); |
| 268 | m_clutoffs++; |
| 269 | if (m_clutoffs > 255) |
| 270 | { |
| 271 | m_clutoffs = 0; |
| 272 | } |
| 273 | m_count = 0; |
| 274 | } |
| 275 | break; |
| 276 | |
| 277 | case 0x8000: // enable and ack VBL |
| 278 | m_vbl_disable = 0; |
| 279 | lower_slot_irq(); |
| 280 | break; |
| 281 | |
| 282 | case 0x8001: // disable VBL |
| 283 | m_vbl_disable = 1; |
| 284 | break; |
| 285 | |
| 286 | default: |
| 287 | printf("m2video_w: %08x @ %x, mask %08x (PC=%x)\n", data, offset, mem_mask, space.device().safe_pc()); |
| 288 | break; |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | READ32_MEMBER( nubus_m2video_device::m2video_r ) |
| 293 | { |
| 294 | if (offset == 0x50000/4) // bit 0 is VBL status |
| 295 | { |
| 296 | m_toggle ^= 1; |
| 297 | return m_toggle; |
| 298 | } |
| 299 | else |
| 300 | { |
| 301 | printf("m2video_r: @ %x, mask %08x (PC=%x)\n", offset, mem_mask, space.device().safe_pc()); |
| 302 | } |
| 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | WRITE32_MEMBER( nubus_m2video_device::vram_w ) |
| 308 | { |
| 309 | data ^= 0xffffffff; |
| 310 | COMBINE_DATA(&m_vram32[offset]); |
| 311 | } |
| 312 | |
| 313 | READ32_MEMBER( nubus_m2video_device::vram_r ) |
| 314 | { |
| 315 | return m_vram32[offset] ^ 0xffffffff; |
| 316 | } |
trunk/src/mess/video/nubus_m2video.h
| r0 | r18570 | |
| 1 | #pragma once |
| 2 | |
| 3 | #ifndef __NUBUS_M2VIDEO_H__ |
| 4 | #define __NUBUS_M2VIDEO_H__ |
| 5 | |
| 6 | #include "emu.h" |
| 7 | #include "machine/nubus.h" |
| 8 | |
| 9 | //************************************************************************** |
| 10 | // TYPE DEFINITIONS |
| 11 | //************************************************************************** |
| 12 | |
| 13 | // ======================> nubus_m2video_device |
| 14 | |
| 15 | class nubus_m2video_device : |
| 16 | public device_t, |
| 17 | public device_nubus_card_interface |
| 18 | { |
| 19 | public: |
| 20 | // construction/destruction |
| 21 | nubus_m2video_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 22 | nubus_m2video_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock); |
| 23 | |
| 24 | // optional information overrides |
| 25 | virtual machine_config_constructor device_mconfig_additions() const; |
| 26 | virtual const rom_entry *device_rom_region() const; |
| 27 | |
| 28 | UINT32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); |
| 29 | protected: |
| 30 | // device-level overrides |
| 31 | virtual void device_start(); |
| 32 | virtual void device_reset(); |
| 33 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 34 | |
| 35 | DECLARE_READ32_MEMBER(m2video_r); |
| 36 | DECLARE_WRITE32_MEMBER(m2video_w); |
| 37 | DECLARE_READ32_MEMBER(vram_r); |
| 38 | DECLARE_WRITE32_MEMBER(vram_w); |
| 39 | |
| 40 | public: |
| 41 | UINT8 *m_vram; |
| 42 | UINT32 *m_vram32; |
| 43 | UINT32 m_mode, m_vbl_disable, m_toggle; |
| 44 | UINT32 m_palette[256], m_colors[3], m_count, m_clutoffs; |
| 45 | screen_device *m_screen; |
| 46 | emu_timer *m_timer; |
| 47 | }; |
| 48 | |
| 49 | |
| 50 | // device type definition |
| 51 | extern const device_type NUBUS_M2VIDEO; |
| 52 | |
| 53 | #endif /* __NUBUS_M2VIDEO_H__ */ |