From 7ff10685c56a6e123336c684e5e96fdb9e8b3674 Mon Sep 17 00:00:00 2001 From: arbee Date: Wed, 13 Dec 2023 13:20:50 -0500 Subject: nubus/nubus_wsportrait.cpp: Updates [R. Belmont] * Modernized types, format, and palette device usage * Use correct raster timing parameters * Added save state support * Fixed 2/4 bpp modes, which never worked --- src/devices/bus/nubus/nubus_wsportrait.cpp | 217 +++++++++++++++-------------- src/devices/bus/nubus/nubus_wsportrait.h | 46 +----- 2 files changed, 110 insertions(+), 153 deletions(-) diff --git a/src/devices/bus/nubus/nubus_wsportrait.cpp b/src/devices/bus/nubus/nubus_wsportrait.cpp index 41d96442987..77b6b43fda8 100644 --- a/src/devices/bus/nubus/nubus_wsportrait.cpp +++ b/src/devices/bus/nubus/nubus_wsportrait.cpp @@ -6,6 +6,11 @@ PCB is marked "Workstation/Portrait Card" 640x870, 1, 2 or 4bpp grayscale + Raster parameters, from an archived copy of Apple's spec sheet: + Horizontal 68.85 kHz + Vertical 75.0 Hz + Dot Clock 57.2832 MHz + Fs0900e0 = DAC control Fs0900e4 = DAC data Fs0A0000 = enable / ack VBL IRQ @@ -14,89 +19,101 @@ ***************************************************************************/ #include "emu.h" + #include "nubus_wsportrait.h" + +#include "emupal.h" #include "screen.h" #include -#define WSPORTRAIT_SCREEN_NAME "wsport_screen" -#define WSPORTRAIT_ROM_REGION "wsport_rom" +namespace { -#define VRAM_SIZE (0x80000) // 512k max +static constexpr u32 VRAM_SIZE = 0x80000; +class nubus_wsportrait_device : public device_t, + public device_video_interface, + public device_nubus_card_interface +{ +public: + // construction/destruction + nubus_wsportrait_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); -ROM_START( wsportrait ) - ROM_REGION(0x1000, WSPORTRAIT_ROM_REGION, 0) - ROM_LOAD( "341-0732.bin", 0x000000, 0x001000, CRC(ddc35b78) SHA1(ce2bf2374bb994c17962dba8f3d11bc1260e2644) ) -ROM_END +protected: + nubus_wsportrait_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock); + + // device-level overrides + virtual void device_start() override; + virtual void device_reset() override; + + // optional information overrides + virtual void device_add_mconfig(machine_config &config) override; + virtual const tiny_rom_entry *device_rom_region() const override; -//************************************************************************** -// GLOBAL VARIABLES -//************************************************************************** + TIMER_CALLBACK_MEMBER(vbl_tick); -DEFINE_DEVICE_TYPE(NUBUS_WSPORTRAIT, nubus_wsportrait_device, "nb_wspt", "Macintosh II Portrait Video Card") +private: + u32 wsportrait_r(offs_t offset, u32 mem_mask = ~0); + void wsportrait_w(offs_t offset, u32 data, u32 mem_mask = ~0); + u32 vram_r(offs_t offset, u32 mem_mask = ~0); + void vram_w(offs_t offset, u32 data, u32 mem_mask = ~0); + u32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); -//------------------------------------------------- -// device_add_mconfig - add device configuration -//------------------------------------------------- + required_device m_screen; + required_device m_palette; + + std::unique_ptr m_vram; + u32 m_mode, m_vbl_disable; + u32 m_colors[3], m_count, m_clutoffs; + emu_timer *m_timer; +}; + +ROM_START( wsportrait ) + ROM_REGION(0x1000, "declrom", 0) + ROM_LOAD( "341-0732.bin", 0x000000, 0x001000, CRC(ddc35b78) SHA1(ce2bf2374bb994c17962dba8f3d11bc1260e2644) ) +ROM_END void nubus_wsportrait_device::device_add_mconfig(machine_config &config) { - screen_device &screen(SCREEN(config, WSPORTRAIT_SCREEN_NAME, SCREEN_TYPE_RASTER)); - screen.set_screen_update(FUNC(nubus_wsportrait_device::screen_update)); - screen.set_size(1024, 960); - screen.set_refresh_hz(75.0); - screen.set_visarea(0, 640-1, 0, 870-1); - screen.set_physical_aspect(3, 4); -} + SCREEN(config, m_screen, SCREEN_TYPE_RASTER); + m_screen->set_screen_update(FUNC(nubus_wsportrait_device::screen_update)); + m_screen->set_raw(57.2832_MHz_XTAL, 832, 0, 640, 918, 0, 832); + m_screen->set_physical_aspect(3, 4); -//------------------------------------------------- -// rom_region - device-specific ROM region -//------------------------------------------------- + PALETTE(config, m_palette).set_entries(256); +} const tiny_rom_entry *nubus_wsportrait_device::device_rom_region() const { return ROM_NAME( wsportrait ); } -//************************************************************************** -// LIVE DEVICE -//************************************************************************** - -//------------------------------------------------- -// nubus_wsportrait_device - constructor -//------------------------------------------------- - -nubus_wsportrait_device::nubus_wsportrait_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : +nubus_wsportrait_device::nubus_wsportrait_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : nubus_wsportrait_device(mconfig, NUBUS_WSPORTRAIT, tag, owner, clock) { } -nubus_wsportrait_device::nubus_wsportrait_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) : +nubus_wsportrait_device::nubus_wsportrait_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock) : device_t(mconfig, type, tag, owner, clock), device_video_interface(mconfig, *this), device_nubus_card_interface(mconfig, *this), - m_mode(0), m_vbl_disable(0), m_toggle(0), m_count(0), m_clutoffs(0), m_timer(nullptr) + m_screen(*this, "screen"), + m_palette(*this, "palette"), + m_mode(0), m_vbl_disable(0), m_count(0), m_clutoffs(0), m_timer(nullptr) { - set_screen(*this, WSPORTRAIT_SCREEN_NAME); + set_screen(*this, "screen"); } -//------------------------------------------------- -// device_start - device-specific startup -//------------------------------------------------- - void nubus_wsportrait_device::device_start() { - uint32_t slotspace; + u32 slotspace; - install_declaration_rom(WSPORTRAIT_ROM_REGION, true); + install_declaration_rom("declrom", true); slotspace = get_slotspace(); -// printf("[wsportrait %p] slotspace = %x\n", (void *)this, slotspace); - - m_vram.resize(VRAM_SIZE / sizeof(uint32_t)); + m_vram = std::make_unique(VRAM_SIZE / sizeof(u32)); nubus().install_device(slotspace, slotspace+VRAM_SIZE-1, read32s_delegate(*this, FUNC(nubus_wsportrait_device::vram_r)), write32s_delegate(*this, FUNC(nubus_wsportrait_device::vram_w))); nubus().install_device(slotspace+0x900000, slotspace+0x900000+VRAM_SIZE-1, read32s_delegate(*this, FUNC(nubus_wsportrait_device::vram_r)), write32s_delegate(*this, FUNC(nubus_wsportrait_device::vram_w))); @@ -104,11 +121,14 @@ void nubus_wsportrait_device::device_start() m_timer = timer_alloc(FUNC(nubus_wsportrait_device::vbl_tick), this); m_timer->adjust(screen().time_until_pos(869, 0), 0); -} -//------------------------------------------------- -// device_reset - device-specific reset -//------------------------------------------------- + save_item(NAME(m_mode)); + save_item(NAME(m_vbl_disable)); + save_item(NAME(m_colors)); + save_item(NAME(m_count)); + save_item(NAME(m_clutoffs)); + save_pointer(NAME(m_vram), VRAM_SIZE / sizeof(u32)); +} void nubus_wsportrait_device::device_reset() { @@ -116,11 +136,9 @@ void nubus_wsportrait_device::device_reset() m_clutoffs = 0; m_vbl_disable = 1; m_mode = 0; - std::fill(m_vram.begin(), m_vram.end(), 0); - memset(m_palette, 0, sizeof(m_palette)); + std::fill_n(&m_vram[0], VRAM_SIZE / sizeof(u32), 0); } - TIMER_CALLBACK_MEMBER(nubus_wsportrait_device::vbl_tick) { if (!m_vbl_disable) @@ -131,65 +149,59 @@ TIMER_CALLBACK_MEMBER(nubus_wsportrait_device::vbl_tick) m_timer->adjust(screen().time_until_pos(869, 0), 0); } -/*************************************************************************** - - Workstation/Portrait emulation - -***************************************************************************/ - -uint32_t nubus_wsportrait_device::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) +u32 nubus_wsportrait_device::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) { - // first time? kick off the VBL timer - auto const vram8 = util::big_endian_cast(&m_vram[0]) + 0x80; + auto const vram8 = util::big_endian_cast(&m_vram[0]) + 0x80; + const pen_t *pens = m_palette->pens(); switch (m_mode) { case 0: // 1 bpp? for (int y = 0; y < 870; y++) { - uint32_t *scanline = &bitmap.pix(y); + u32 *scanline = &bitmap.pix(y); for (int x = 0; x < 640/8; x++) { - uint8_t const pixels = vram8[(y * 128) + x]; - - *scanline++ = m_palette[BIT(pixels, 7)]; - *scanline++ = m_palette[BIT(pixels, 6)]; - *scanline++ = m_palette[BIT(pixels, 5)]; - *scanline++ = m_palette[BIT(pixels, 4)]; - *scanline++ = m_palette[BIT(pixels, 3)]; - *scanline++ = m_palette[BIT(pixels, 2)]; - *scanline++ = m_palette[BIT(pixels, 1)]; - *scanline++ = m_palette[BIT(pixels, 0)]; + u8 const pixels = vram8[(y * 128) + x]; + + *scanline++ = pens[BIT(pixels, 7)]; + *scanline++ = pens[BIT(pixels, 6)]; + *scanline++ = pens[BIT(pixels, 5)]; + *scanline++ = pens[BIT(pixels, 4)]; + *scanline++ = pens[BIT(pixels, 3)]; + *scanline++ = pens[BIT(pixels, 2)]; + *scanline++ = pens[BIT(pixels, 1)]; + *scanline++ = pens[BIT(pixels, 0)]; } } break; case 1: // 2 bpp - for (int y = 0; y < 480; y++) + for (int y = 0; y < 870; y++) { - uint32_t *scanline = &bitmap.pix(y); + u32 *scanline = &bitmap.pix(y); for (int x = 0; x < 640/4; x++) { - uint8_t const pixels = vram8[(y * 256) + x]; + u8 const pixels = vram8[(y * 256) + x]; - *scanline++ = m_palette[((pixels>>6)&3)]; - *scanline++ = m_palette[((pixels>>4)&3)]; - *scanline++ = m_palette[((pixels>>2)&3)]; - *scanline++ = m_palette[(pixels&3)]; + *scanline++ = pens[((pixels>>6)&3)]; + *scanline++ = pens[((pixels>>4)&3)]; + *scanline++ = pens[((pixels>>2)&3)]; + *scanline++ = pens[(pixels&3)]; } } break; case 2: // 4 bpp - for (int y = 0; y < 480; y++) + for (int y = 0; y < 870; y++) { - uint32_t *scanline = &bitmap.pix(y); + u32 *scanline = &bitmap.pix(y); for (int x = 0; x < 640/2; x++) { - uint8_t const pixels = vram8[(y * 512) + x]; + u8 const pixels = vram8[(y * 512) + x]; - *scanline++ = m_palette[((pixels&0xf0)>>4)]; - *scanline++ = m_palette[(pixels&0xf)]; + *scanline++ = pens[((pixels&0xf0)>>4)]; + *scanline++ = pens[(pixels&0xf)]; } } break; @@ -200,7 +212,7 @@ uint32_t nubus_wsportrait_device::screen_update(screen_device &screen, bitmap_rg return 0; } -void nubus_wsportrait_device::wsportrait_w(offs_t offset, uint32_t data, uint32_t mem_mask) +void nubus_wsportrait_device::wsportrait_w(offs_t offset, u32 data, u32 mem_mask) { data ^= 0xffffffff; // if (offset != 0x8000) printf("wsportrait: Write %08x @ %x, mask %08x\n", data, offset, mem_mask); @@ -208,7 +220,6 @@ void nubus_wsportrait_device::wsportrait_w(offs_t offset, uint32_t data, uint32_ switch (offset) { case 1: // mode control -// printf("%08x to mode 1\n", data); switch (data & 0xff000000) { case 0x20000000: @@ -229,6 +240,7 @@ void nubus_wsportrait_device::wsportrait_w(offs_t offset, uint32_t data, uint32_ case 0x4038: // DAC control m_clutoffs = (data>>24)&0xff; + m_count = 0; break; case 0x4039: // DAC data - only 4 bits per component! @@ -238,8 +250,9 @@ void nubus_wsportrait_device::wsportrait_w(offs_t offset, uint32_t data, uint32_ if (m_count == 3) { -// logerror("RAMDAC: color %d = %02x %02x %02x %s\n", m_clutoffs, m_colors[0], m_colors[1], m_colors[2], machine().describe_context()); - m_palette[m_clutoffs] = rgb_t(m_colors[2], m_colors[2], m_colors[2]); + m_palette->set_pen_red_level(m_clutoffs, m_colors[2]); + m_palette->set_pen_green_level(m_clutoffs, m_colors[2]); + m_palette->set_pen_blue_level(m_clutoffs, m_colors[2]); m_clutoffs++; if (m_clutoffs > 255) { @@ -260,39 +273,27 @@ void nubus_wsportrait_device::wsportrait_w(offs_t offset, uint32_t data, uint32_ } } -uint32_t nubus_wsportrait_device::wsportrait_r(offs_t offset, uint32_t mem_mask) +u32 nubus_wsportrait_device::wsportrait_r(offs_t offset, u32 mem_mask) { -// printf("wsportrait: Read @ %x, mask %08x\n", offset, mem_mask); - - /* - monitor types - - 0x0 = invalid - 0x2 = invalid - 0x4 = color: 640x870 1bpp, 640x480 2bpp and 4bpp - 0x6 = 1bpp 640x384? and sets weird mode controls - 0x8 = really odd (bitplaned?) - 0xa = invalid - 0xc = 640x480 grayscale - 0xe = same as 0x6 - */ - switch (offset) { case 0x4004: - m_toggle ^= 0x00010000; - return m_toggle | 0xfffc0000; // bit 0 = vbl status, bits 1-3 = monitor type + return (m_screen->vblank() << 16) | 0xfffc0000; // bit 16 = vbl status, bits 17-20 = monitor type } return 0; } -void nubus_wsportrait_device::vram_w(offs_t offset, uint32_t data, uint32_t mem_mask) +void nubus_wsportrait_device::vram_w(offs_t offset, u32 data, u32 mem_mask) { data ^= 0xffffffff; COMBINE_DATA(&m_vram[offset]); } -uint32_t nubus_wsportrait_device::vram_r(offs_t offset, uint32_t mem_mask) +u32 nubus_wsportrait_device::vram_r(offs_t offset, u32 mem_mask) { return m_vram[offset] ^ 0xffffffff; } + +} // anonymous namespace + +DEFINE_DEVICE_TYPE_PRIVATE(NUBUS_WSPORTRAIT, device_nubus_card_interface, nubus_wsportrait_device, "nb_wspt", "Macintosh II Portrait Video Card") diff --git a/src/devices/bus/nubus/nubus_wsportrait.h b/src/devices/bus/nubus/nubus_wsportrait.h index e25292c792d..3b3546eb721 100644 --- a/src/devices/bus/nubus/nubus_wsportrait.h +++ b/src/devices/bus/nubus/nubus_wsportrait.h @@ -7,50 +7,6 @@ #include "nubus.h" -//************************************************************************** -// TYPE DEFINITIONS -//************************************************************************** - -// ======================> nubus_wsportrait_device - -class nubus_wsportrait_device : - public device_t, - public device_video_interface, - public device_nubus_card_interface -{ -public: - // construction/destruction - nubus_wsportrait_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - -protected: - nubus_wsportrait_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); - - // device-level overrides - virtual void device_start() override; - virtual void device_reset() override; - - // optional information overrides - virtual void device_add_mconfig(machine_config &config) override; - virtual const tiny_rom_entry *device_rom_region() const override; - - TIMER_CALLBACK_MEMBER(vbl_tick); - -private: - uint32_t wsportrait_r(offs_t offset, uint32_t mem_mask = ~0); - void wsportrait_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t vram_r(offs_t offset, uint32_t mem_mask = ~0); - void vram_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - - uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); - - std::vector m_vram; - uint32_t m_mode, m_vbl_disable, m_toggle; - uint32_t m_palette[256], m_colors[3], m_count, m_clutoffs; - emu_timer *m_timer; -}; - - -// device type definition -DECLARE_DEVICE_TYPE(NUBUS_WSPORTRAIT, nubus_wsportrait_device) +DECLARE_DEVICE_TYPE(NUBUS_WSPORTRAIT, device_nubus_card_interface) #endif // MAME_BUS_NUBUS_WSPORTRAIT_H -- cgit v1.2.3