diff options
author | 2017-04-16 21:05:01 -0400 | |
---|---|---|
committer | 2017-04-16 21:05:01 -0400 | |
commit | b2e89fd2e1fd4c1f5d487ffc9c79f9ef5b4cc78d (patch) | |
tree | ed66da3c3e8084a0269a06ba6f659755a906f9a3 /src/emu | |
parent | 6d5a0145f5fc87cf71361cd5acfc9f53e6a34ca9 (diff) | |
parent | dfdd5be76cb87aa5c3ff546fb8efc8d92721d795 (diff) |
Merge pull request #2239 from ajrhacker/dipalette_sanity
dipalette: A return to sanity (nw)
Diffstat (limited to 'src/emu')
-rw-r--r-- | src/emu/dipalette.cpp | 53 | ||||
-rw-r--r-- | src/emu/dipalette.h | 15 | ||||
-rw-r--r-- | src/emu/emupal.cpp | 4 | ||||
-rw-r--r-- | src/emu/emupal.h | 12 |
4 files changed, 49 insertions, 35 deletions
diff --git a/src/emu/dipalette.cpp b/src/emu/dipalette.cpp index 125f7b2c53c..d996ccafe4d 100644 --- a/src/emu/dipalette.cpp +++ b/src/emu/dipalette.cpp @@ -37,6 +37,20 @@ device_palette_interface::device_palette_interface(const machine_config &mconfig //------------------------------------------------- +// interface_validity_check - validation for a +// device after the configuration has been +// constructed +//------------------------------------------------- + +void device_palette_interface::interface_validity_check(validity_checker &valid) const +{ + // this info must be available before the device has started + if (palette_entries() == 0) + osd_printf_error("Palette has no entries specified\n"); +} + + +//------------------------------------------------- // interface_pre_start - work to be done prior to // actually starting a device //------------------------------------------------- @@ -48,28 +62,25 @@ void device_palette_interface::interface_pre_start() m_format = (screen != nullptr) ? screen->format() : BITMAP_FORMAT_INVALID; // allocate the palette - int numentries = palette_entries(); - if (numentries > 0) + u32 numentries = palette_entries(); + allocate_palette(numentries); + allocate_color_tables(); + allocate_shadow_tables(); + + // allocate indirection tables + int indirect_colors = palette_indirect_entries(); + if (indirect_colors > 0) { - allocate_palette(numentries); - allocate_color_tables(); - allocate_shadow_tables(); - - // allocate indirection tables - int indirect_colors = palette_indirect_entries(); - if (indirect_colors > 0) + m_indirect_colors.resize(indirect_colors); + for (int color = 0; color < indirect_colors; color++) { - m_indirect_colors.resize(indirect_colors); - for (int color = 0; color < indirect_colors; color++) - { - // alpha = 0 ensures change is detected the first time set_indirect_color() is called - m_indirect_colors[color] = rgb_t::transparent(); - } - - m_indirect_pens.resize(numentries); - for (int pen = 0; pen < numentries; pen++) - m_indirect_pens[pen] = pen % indirect_colors; + // alpha = 0 ensures change is detected the first time set_indirect_color() is called + m_indirect_colors[color] = rgb_t::transparent(); } + + m_indirect_pens.resize(numentries); + for (int pen = 0; pen < numentries; pen++) + m_indirect_pens[pen] = pen % indirect_colors; } } @@ -328,8 +339,10 @@ void device_palette_interface::set_shadow_dRGB32(int mode, int dr, int dg, int d // palette object itself //------------------------------------------------- -void device_palette_interface::allocate_palette(int numentries) +void device_palette_interface::allocate_palette(u32 numentries) { + assert(numentries > 0); + // determine the number of groups we need int numgroups = 1; if (palette_shadows_enabled()) diff --git a/src/emu/dipalette.h b/src/emu/dipalette.h index ed0a6f31a39..fc1f767300d 100644 --- a/src/emu/dipalette.h +++ b/src/emu/dipalette.h @@ -46,8 +46,8 @@ public: device_palette_interface(const machine_config &mconfig, device_t &device); // getters - int entries() const { return (m_palette != nullptr) ? m_palette->num_colors() : 0; } - int indirect_entries() const { return m_indirect_colors.size(); } + u32 entries() const { return palette_entries(); } + u32 indirect_entries() const { return palette_indirect_entries(); } palette_t *palette() const { return m_palette; } const pen_t &pen(int index) const { return m_pens[index]; } const pen_t *pens() const { return m_pens; } @@ -56,8 +56,8 @@ public: double pen_contrast(pen_t pen) const { return m_palette->entry_contrast(pen); } pen_t black_pen() const { return m_black_pen; } pen_t white_pen() const { return m_white_pen; } - bool shadows_enabled() const { return m_shadow_group != 0; } - bool hilights_enabled() const { return m_hilight_group != 0; } + bool shadows_enabled() const { return palette_shadows_enabled(); } + bool hilights_enabled() const { return palette_hilights_enabled(); } // setters void set_pen_color(pen_t pen, rgb_t rgb) { m_palette->entry_set_color(pen, rgb); } @@ -83,6 +83,7 @@ public: protected: // interface-level overrides + virtual void interface_validity_check(validity_checker &valid) const override; virtual void interface_pre_start() override; virtual void interface_post_start() override; virtual void interface_pre_save() override; @@ -90,14 +91,14 @@ protected: virtual void interface_post_stop() override; // configuration-related overrides - virtual int palette_entries() const = 0; - virtual int palette_indirect_entries() const { return 0; } + virtual u32 palette_entries() const = 0; + virtual u32 palette_indirect_entries() const { return 0; } virtual bool palette_shadows_enabled() const { return false; } virtual bool palette_hilights_enabled() const { return false; } private: // internal helpers - void allocate_palette(int numentries); + void allocate_palette(u32 numentries); void allocate_color_tables(); void allocate_shadow_tables(); public: // needed by konamigx diff --git a/src/emu/emupal.cpp b/src/emu/emupal.cpp index a2567d47250..13e4b329e91 100644 --- a/src/emu/emupal.cpp +++ b/src/emu/emupal.cpp @@ -66,13 +66,13 @@ void palette_device::static_set_endianness(device_t &device, endianness_t endian } -void palette_device::static_set_entries(device_t &device, int entries) +void palette_device::static_set_entries(device_t &device, u32 entries) { downcast<palette_device &>(device).m_entries = entries; } -void palette_device::static_set_indirect_entries(device_t &device, int entries) +void palette_device::static_set_indirect_entries(device_t &device, u32 entries) { downcast<palette_device &>(device).m_indirect_entries = entries; } diff --git a/src/emu/emupal.h b/src/emu/emupal.h index 31f6937fb52..fe8a9b084b9 100644 --- a/src/emu/emupal.h +++ b/src/emu/emupal.h @@ -367,8 +367,8 @@ public: static void static_set_format(device_t &device, raw_to_rgb_converter raw_to_rgb); static void static_set_membits(device_t &device, int membits); static void static_set_endianness(device_t &device, endianness_t endianness); - static void static_set_entries(device_t &device, int entries); - static void static_set_indirect_entries(device_t &device, int entries); + static void static_set_entries(device_t &device, u32 entries); + static void static_set_indirect_entries(device_t &device, u32 entries); static void static_enable_shadows(device_t &device); static void static_enable_hilights(device_t &device); @@ -421,8 +421,8 @@ protected: virtual void device_start() override; // device_palette_interface overrides - virtual int palette_entries() const override { return m_entries; } - virtual int palette_indirect_entries() const override { return m_indirect_entries; } + virtual u32 palette_entries() const override { return m_entries; } + virtual u32 palette_indirect_entries() const override { return m_indirect_entries; } virtual bool palette_shadows_enabled() const override { return m_enable_shadows; } virtual bool palette_hilights_enabled() const override { return m_enable_hilights; } @@ -430,8 +430,8 @@ private: void update_for_write(offs_t byte_offset, int bytes_modified, bool indirect = false); // configuration state - int m_entries; // number of entries in the palette - int m_indirect_entries; // number of indirect colors in the palette + u32 m_entries; // number of entries in the palette + u32 m_indirect_entries; // number of indirect colors in the palette bool m_enable_shadows; // are shadows enabled? bool m_enable_hilights; // are hilights enabled? int m_membits; // width of palette RAM, if different from native |