summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2019-10-19 22:35:04 -0400
committer AJR <ajrhacker@users.noreply.github.com>2019-10-19 22:40:04 -0400
commit270a2736b0770e5be2d9967b399e178500dbe7a5 (patch)
tree4bfe26c9e3f453e73f1c6d27641133c3862323f7 /src/mame/video
parentc08c7d6e53a484570b7f0645f45bb2d529547e48 (diff)
segaic16.cpp: Code cleanup, reorganization and decoupling (nw)
- Move open_bus_r down into the 315-5195 mapper device (not 100% ideal, but the next best place) - Split out 315-5195 mapper device into separate source file and modernize logging - Move remaining portion of sega_16bit_common_base (all to do with palettes) into video/segaic16.cpp segahang.cpp: Split I/O handlers; eliminate probably unnecessary open bus read semantics to decouple from sega_16bit_common_base (nw)
Diffstat (limited to 'src/mame/video')
-rw-r--r--src/mame/video/segaic16.cpp155
-rw-r--r--src/mame/video/segaic16.h37
2 files changed, 189 insertions, 3 deletions
diff --git a/src/mame/video/segaic16.cpp b/src/mame/video/segaic16.cpp
index 622ef9f95a2..eb2a7535c30 100644
--- a/src/mame/video/segaic16.cpp
+++ b/src/mame/video/segaic16.cpp
@@ -373,6 +373,161 @@ Quick review of the system16 hardware:
+//**************************************************************************
+// PALETTE HELPERS
+//**************************************************************************
+
+//-------------------------------------------------
+// sega_16bit_common_base - constructor
+//-------------------------------------------------
+
+sega_16bit_common_base::sega_16bit_common_base(const machine_config &mconfig, device_type type, const char *tag)
+ : driver_device(mconfig, type, tag)
+ , m_paletteram(*this, "paletteram")
+ , m_palette_entries(0)
+ , m_palette(*this, "palette")
+{
+ palette_init();
+}
+
+
+//-------------------------------------------------
+// palette_init - precompute weighted RGB values
+// for each input value 0-31
+//-------------------------------------------------
+
+void sega_16bit_common_base::palette_init()
+{
+ //
+ // Color generation details
+ //
+ // Each color is made up of 5 bits, connected through one or more resistors like so:
+ //
+ // Bit 0 = 1 x 3.9K ohm
+ // Bit 1 = 1 x 2.0K ohm
+ // Bit 2 = 1 x 1.0K ohm
+ // Bit 3 = 2 x 1.0K ohm
+ // Bit 4 = 4 x 1.0K ohm
+ //
+ // Another data bit is connected by a tristate buffer to the color output through a
+ // 470 ohm resistor. The buffer allows the resistor to have no effect (tristate),
+ // halve brightness (pull-down) or double brightness (pull-up). The data bit source
+ // is bit 15 of each color RAM entry.
+ //
+
+ // compute weight table for regular palette entries
+ static const int resistances_normal[6] = { 3900, 2000, 1000, 1000/2, 1000/4, 0 };
+ double weights_normal[6];
+ compute_resistor_weights(0, 255, -1.0,
+ 6, resistances_normal, weights_normal, 0, 0,
+ 0, nullptr, nullptr, 0, 0,
+ 0, nullptr, nullptr, 0, 0);
+
+ // compute weight table for shadow/hilight palette entries
+ static const int resistances_sh[6] = { 3900, 2000, 1000, 1000/2, 1000/4, 470 };
+ double weights_sh[6];
+ compute_resistor_weights(0, 255, -1.0,
+ 6, resistances_sh, weights_sh, 0, 0,
+ 0, nullptr, nullptr, 0, 0,
+ 0, nullptr, nullptr, 0, 0);
+
+ // compute R, G, B for each weight
+ for (int value = 0; value < 32; value++)
+ {
+ const u8 i4 = (value >> 4) & 1;
+ const u8 i3 = (value >> 3) & 1;
+ const u8 i2 = (value >> 2) & 1;
+ const u8 i1 = (value >> 1) & 1;
+ const u8 i0 = (value >> 0) & 1;
+ m_palette_normal[value] = combine_weights(weights_normal, i0, i1, i2, i3, i4, 0);
+ m_palette_shadow[value] = combine_weights(weights_sh, i0, i1, i2, i3, i4, 0);
+ m_palette_hilight[value] = combine_weights(weights_sh, i0, i1, i2, i3, i4, 1);
+ }
+}
+
+
+//-------------------------------------------------
+// paletteram_w - handle writes to palette RAM
+//-------------------------------------------------
+
+WRITE16_MEMBER( sega_16bit_common_base::paletteram_w )
+{
+ // compute the number of entries
+ if (m_palette_entries == 0)
+ m_palette_entries = memshare("paletteram")->bytes() / 2;
+
+ // get the new value
+ u16 newval = m_paletteram[offset];
+ COMBINE_DATA(&newval);
+ m_paletteram[offset] = newval;
+
+ // byte 0 byte 1
+ // sBGR BBBB GGGG RRRR
+ // x000 4321 4321 4321
+ const u8 r = ((newval >> 12) & 0x01) | ((newval << 1) & 0x1e);
+ const u8 g = ((newval >> 13) & 0x01) | ((newval >> 3) & 0x1e);
+ const u8 b = ((newval >> 14) & 0x01) | ((newval >> 7) & 0x1e);
+
+ // shadow / hilight toggle bit in palette RAM
+ rgb_t effects = (newval & 0x8000) ?
+ rgb_t(m_palette_hilight[r], m_palette_hilight[g], m_palette_hilight[b]) :
+ rgb_t(m_palette_shadow[r], m_palette_shadow[g], m_palette_shadow[b]);
+ m_palette->set_pen_color(offset + 0 * m_palette_entries, m_palette_normal[r], m_palette_normal[g], m_palette_normal[b]);
+ m_palette->set_pen_color(offset + 1 * m_palette_entries, effects);
+}
+
+WRITE16_MEMBER( sega_16bit_common_base::hangon_paletteram_w )
+{
+ // compute the number of entries
+ if (m_palette_entries == 0)
+ m_palette_entries = memshare("paletteram")->bytes() / 2;
+
+ // get the new value
+ u16 newval = m_paletteram[offset];
+ COMBINE_DATA(&newval);
+ m_paletteram[offset] = newval;
+
+ // byte 0 byte 1
+ // xBGR BBBB GGGG RRRR
+ // x000 4321 4321 4321
+ const u8 r = ((newval >> 12) & 0x01) | ((newval << 1) & 0x1e);
+ const u8 g = ((newval >> 13) & 0x01) | ((newval >> 3) & 0x1e);
+ const u8 b = ((newval >> 14) & 0x01) | ((newval >> 7) & 0x1e);
+
+ // hangon has external shadow / hilight toggle bit
+ m_palette->set_pen_color(offset + 0 * m_palette_entries, m_palette_normal[r], m_palette_normal[g], m_palette_normal[b]);
+ m_palette->set_pen_color(offset + 1 * m_palette_entries, m_palette_shadow[r], m_palette_shadow[g], m_palette_shadow[b]);
+ m_palette->set_pen_color(offset + 2 * m_palette_entries, m_palette_hilight[r], m_palette_hilight[g], m_palette_hilight[b]);
+}
+
+WRITE16_MEMBER( sega_16bit_common_base::philko_paletteram_w )
+{
+ // compute the number of entries
+ if (m_palette_entries == 0)
+ m_palette_entries = memshare("paletteram")->bytes() / 2;
+
+ // get the new value
+ u16 newval = m_paletteram[offset];
+ COMBINE_DATA(&newval);
+ m_paletteram[offset] = newval;
+
+ // byte 0 byte 1
+ // sRRR RRGG GGGB BBBB
+ // x432 1043 2104 3210
+ const u8 b = (newval >> 0) & 0x1f;
+ const u8 g = (newval >> 5) & 0x1f;
+ const u8 r = (newval >> 10) & 0x1f;
+
+ // shadow / hilight toggle bit in palette RAM
+ rgb_t effects = (newval & 0x8000) ?
+ rgb_t(m_palette_hilight[r], m_palette_hilight[g], m_palette_hilight[b]) :
+ rgb_t(m_palette_shadow[r], m_palette_shadow[g], m_palette_shadow[b]);
+ m_palette->set_pen_color(offset + 0 * m_palette_entries, m_palette_normal[r], m_palette_normal[g], m_palette_normal[b]);
+ m_palette->set_pen_color(offset + 1 * m_palette_entries, effects);
+}
+
+
+
DEFINE_DEVICE_TYPE(SEGAIC16VID, segaic16_video_device, "segaic16_video", "Sega 16-bit Video")
segaic16_video_device::segaic16_video_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
diff --git a/src/mame/video/segaic16.h b/src/mame/video/segaic16.h
index 13fe52179c6..42ffb1539eb 100644
--- a/src/mame/video/segaic16.h
+++ b/src/mame/video/segaic16.h
@@ -10,15 +10,46 @@
#pragma once
+#include "emupal.h"
#include "tilemap.h"
typedef device_delegate<void (int, uint16_t*, uint16_t*, uint16_t*, uint16_t*)> segaic16_video_pagelatch_delegate;
-/***************************************************************************
- FUNCTION PROTOTYPES
-***************************************************************************/
+//**************************************************************************
+// TYPE DEFINITIONS
+//**************************************************************************
+
+
+// ======================> sega_16bit_common_base
+
+class sega_16bit_common_base : public driver_device
+{
+public:
+ // palette helpers
+ DECLARE_WRITE16_MEMBER( paletteram_w );
+ DECLARE_WRITE16_MEMBER( hangon_paletteram_w );
+ DECLARE_WRITE16_MEMBER( philko_paletteram_w );
+protected:
+ // construction/destruction
+ sega_16bit_common_base(const machine_config &mconfig, device_type type, const char *tag);
+
+ // internal helpers
+ void palette_init();
+
+public: // -- stupid system16.cpp
+ // memory pointers
+ required_shared_ptr<u16> m_paletteram;
+protected:
+
+ // internal state
+ u32 m_palette_entries; // number of palette entries
+ u8 m_palette_normal[32]; // RGB translations for normal pixels
+ u8 m_palette_shadow[32]; // RGB translations for shadowed pixels
+ u8 m_palette_hilight[32]; // RGB translations for hilighted pixels
+ required_device<palette_device> m_palette;
+};
class segaic16_video_device : public device_t,