From 6e151b21c1f2e2ac959a616b8c484562c73c8ee6 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Sat, 13 Jul 2024 08:01:48 +1000 Subject: igs/pgmcrypt.cpp: Fixed Endianness issue for 32-bit games. --- src/devices/bus/isa/dectalk.cpp | 4 +-- src/mame/igs/igs_fear.cpp | 64 +++++++++++++++++++++-------------------- src/mame/igs/pgmcrypt.cpp | 9 +++--- 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/src/devices/bus/isa/dectalk.cpp b/src/devices/bus/isa/dectalk.cpp index 1007604dfca..141a7c06c43 100644 --- a/src/devices/bus/isa/dectalk.cpp +++ b/src/devices/bus/isa/dectalk.cpp @@ -155,12 +155,12 @@ const tiny_rom_entry* dectalk_isa_device::device_rom_region() const void dectalk_isa_device::device_add_mconfig(machine_config &config) { - I80186(config, m_cpu, XTAL(20'000'000)); + I80186(config, m_cpu, 20_MHz_XTAL); m_cpu->set_addrmap(AS_PROGRAM, &dectalk_isa_device::dectalk_cpu_map); m_cpu->set_addrmap(AS_IO, &dectalk_isa_device::dectalk_cpu_io); m_cpu->tmrout0_handler().set(FUNC(dectalk_isa_device::clock_w)); - TMS32015(config, m_dsp, XTAL(80'000'000)); // this is wrong, but it works + TMS32015(config, m_dsp, 80'000'000); // the a 20MHz oscillator is present - clock frequency hacked to make it "work" m_dsp->set_addrmap(AS_PROGRAM, &dectalk_isa_device::dectalk_dsp_map); m_dsp->set_addrmap(AS_IO, &dectalk_isa_device::dectalk_dsp_io); m_dsp->bio().set(FUNC(dectalk_isa_device::bio_line_r)); diff --git a/src/mame/igs/igs_fear.cpp b/src/mame/igs/igs_fear.cpp index 017e51c50e3..dc5c12ec9cd 100644 --- a/src/mame/igs/igs_fear.cpp +++ b/src/mame/igs/igs_fear.cpp @@ -9,8 +9,8 @@ #include "cpu/arm7/arm7core.h" #include "cpu/xa/xa.h" #include "machine/nvram.h" -#include "machine/v3021.h" #include "machine/ticket.h" +#include "machine/v3021.h" #include "sound/ics2115.h" #include "emupal.h" @@ -51,9 +51,9 @@ private: void draw_sprite(bitmap_ind16 &bitmap, const rectangle &cliprect, int xpos, int ypos, int height, int width, int palette, int flipx, int romoffset); - uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); + u32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); - uint32_t igs027_gpio_r(offs_t offset); + u32 igs027_gpio_r(offs_t offset); void igs027_gpio_w(offs_t offset, u32 data, u32 mem_mask); TIMER_CALLBACK_MEMBER(igs027_timer0); @@ -61,29 +61,29 @@ private: void igs027_periph_init(void); void igs027_trigger_irq(int num); - uint32_t igs027_periph_r(offs_t offset); + u32 igs027_periph_r(offs_t offset); void igs027_periph_w(offs_t offset, u32 data, u32 mem_mask); - uint32_t xa_r(offs_t offset); + u32 xa_r(offs_t offset); void xa_w(offs_t offset, u32 data, u32 mem_mask); void cpld_w(offs_t offset, u32 data, u32 mem_mask); - uint32_t m_gpio_o; - uint32_t m_irq_enable; - uint32_t m_irq_pending; + u32 m_gpio_o; + u32 m_irq_enable; + u32 m_irq_pending; emu_timer *m_timer0; emu_timer *m_timer1; - uint32_t m_xa_cmd; + u32 m_xa_cmd; int m_trackball_cnt; int m_trackball_axis[2], m_trackball_axis_pre[2], m_trackball_axis_diff[2]; // devices required_device m_maincpu; required_device m_xa; - required_shared_ptr m_videoram; + required_shared_ptr m_videoram; required_device m_palette; - required_region_ptr m_gfxrom; + required_region_ptr m_gfxrom; required_device m_ticket; required_ioport_array<2> m_io_dsw; @@ -101,18 +101,18 @@ void igs_fear_state::draw_sprite(bitmap_ind16 &bitmap, const rectangle &cliprect if ((romoffset != 0) && (romoffset != 0xffffffff)) { //logerror("x=%d, y=%d, w=%d pix, h=%d pix, c=0x%02x, romoffset=0x%08x\n", xpos, ypos, width, height, palette, romoffset << 2); - const uint8_t *gfxrom = &m_gfxrom[romoffset << 2]; + const u8 *gfxrom = &m_gfxrom[romoffset << 2]; const int x_base = flipx ? (xpos + width - 1) : xpos; const int x_inc = flipx ? (-1) : 1; palette = (palette & 0x3f) << 7; for (int y = 0; y < height; y++) { - uint16_t *dest = &bitmap.pix(ypos + y); + u16 *dest = &bitmap.pix(ypos + y); int x_index = x_base; for (int x = 0; x < width; x++) { - uint8_t pix = *gfxrom++; + u8 pix = *gfxrom++; if (pix) { if (cliprect.contains(x_index, ypos + y)) @@ -124,7 +124,7 @@ void igs_fear_state::draw_sprite(bitmap_ind16 &bitmap, const rectangle &cliprect } } -uint32_t igs_fear_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) +u32 igs_fear_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) { bitmap.fill(0x3ff, cliprect); @@ -312,16 +312,18 @@ void igs_fear_state::vblank_irq(int state) m_maincpu->pulse_input_line(ARM7_FIRQ_LINE, m_maincpu->minimum_quantum_time()); } -uint32_t igs_fear_state::igs027_gpio_r(offs_t offset) +u32 igs_fear_state::igs027_gpio_r(offs_t offset) { - uint32_t data = -1; + u32 data = ~u32(0); switch (offset * 4) { case 0xc: - uint8_t ret = 0xff; - if (!BIT(m_gpio_o, 0)) ret &= m_io_dsw[0]->read(); - if (!BIT(m_gpio_o, 1)) ret &= m_io_dsw[1]->read(); - data = 0x2000 | (ret << 3); + { + u8 ret = 0xff; + if (!BIT(m_gpio_o, 0)) ret &= m_io_dsw[0]->read(); + if (!BIT(m_gpio_o, 1)) ret &= m_io_dsw[1]->read(); + data = 0x2000 | (u32(ret) << 3); + } break; } return data; @@ -339,17 +341,17 @@ void igs_fear_state::igs027_gpio_w(offs_t offset, u32 data, u32 mem_mask) void igs_fear_state::igs027_periph_init() { - m_irq_enable = 0xFF; - m_irq_pending = 0xFF; + m_irq_enable = 0xff; + m_irq_pending = 0xff; m_timer0 = timer_alloc(FUNC(igs_fear_state::igs027_timer0), this); m_timer1 = timer_alloc(FUNC(igs_fear_state::igs027_timer1), this); } void igs_fear_state::igs027_trigger_irq(int num) { - if ((m_irq_enable & (1 << num)) == 0) + if (!BIT(m_irq_enable, num)) { - m_irq_pending &= ~(1 << num); + m_irq_pending &= ~(u32(1) << num); m_maincpu->pulse_input_line(ARM7_IRQ_LINE, m_maincpu->minimum_quantum_time()); } } @@ -383,23 +385,23 @@ void igs_fear_state::igs027_periph_w(offs_t offset, u32 data, u32 mem_mask) } } -uint32_t igs_fear_state::igs027_periph_r(offs_t offset) +u32 igs_fear_state::igs027_periph_r(offs_t offset) { - uint32_t data = -1; + u32 data = ~u32(0); switch (offset * 4) { case 0x200: data = m_irq_pending; - m_irq_pending = 0xFF; + m_irq_pending = 0xff; break; } return data; } // TODO: ICS2115 & trackball support in XA -uint32_t igs_fear_state::xa_r(offs_t offset) +u32 igs_fear_state::xa_r(offs_t offset) { - uint32_t data = -1; + u32 data = ~u32(0); switch (offset * 4) { @@ -553,4 +555,4 @@ void igs_fear_state::init_igs_superkds() } // anonymous namespace GAME( 2005, superkds, 0, igs_fear, superkds, igs_fear_state, init_igs_superkds, ROT0, "IGS", "Super Kids (S019CN)", MACHINE_IS_SKELETON ) -GAME( 2006, fearless, 0, igs_fear, fear, igs_fear_state, init_igs_fear, ROT0, "IGS", "Fearless Pinocchio (V101US)", MACHINE_IS_SKELETON ) +GAME( 2006, fearless, 0, igs_fear, fear, igs_fear_state, init_igs_fear, ROT0, "IGS", "Fearless Pinocchio (V101US)", MACHINE_IS_SKELETON ) diff --git a/src/mame/igs/pgmcrypt.cpp b/src/mame/igs/pgmcrypt.cpp index 7247d695765..db9e4293556 100644 --- a/src/mame/igs/pgmcrypt.cpp +++ b/src/mame/igs/pgmcrypt.cpp @@ -19,6 +19,9 @@ #include "emu.h" #include "pgmcrypt.h" +#include "endianness.h" + + // a common set of these are used, selectable in the real scheme by an uploaded bitfield // some may be duplicates simply due to differing ROM sizes @@ -1417,8 +1420,7 @@ static const uint8_t superkds_tab[256] = { void superkds_decrypt(running_machine &machine) { - // FIXME: Endianness bug - casting a 32-bit ROM region to u16 - auto const src = reinterpret_cast(machine.root_device().memregion("user1")->base()); + auto const src = util::little_endian_cast(reinterpret_cast(machine.root_device().memregion("user1")->base())); int const rom_size = 0x80000; @@ -1443,8 +1445,7 @@ void superkds_decrypt(running_machine &machine) void fearless_decrypt(running_machine &machine) { - // FIXME: Endianness bug - casting a 32-bit ROM region to u16 - auto const src = reinterpret_cast(machine.root_device().memregion("user1")->base()); + auto const src = util::little_endian_cast(reinterpret_cast(machine.root_device().memregion("user1")->base())); int const rom_size = 0x80000; -- cgit v1.2.3