Skip to content

Commit d53ffcb

Browse files
committed
igs/igs011_video.cpp, igs/igs012.cpp: Make IGS011 and IGS012 as device, Update related drivers
igs/igs011.cpp: - Move IGS011 (including decryption, protection, and video), IGS012 into separated device - Fix relocate protection area function - Fix naming for per-game protection functions - Fix logging - Fix post load function - Add notes for dbc title screen - Fix typename values igs/pgmprot*.cpp: - Add include guard - Fix spacings - Fix save state support igs/pgmprot_igs025_igs012.cpp: - Add notes for IGS012, Add IGS012 placeholder igs/igs025.cpp: - Fix spacing, Suppress side effect for debugger reads
1 parent 1b607b9 commit d53ffcb

14 files changed

Lines changed: 1261 additions & 1009 deletions

src/mame/igs/igs011.cpp

Lines changed: 294 additions & 941 deletions
Large diffs are not rendered by default.

src/mame/igs/igs011_video.cpp

Lines changed: 538 additions & 0 deletions
Large diffs are not rendered by default.

src/mame/igs/igs011_video.h

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// license:BSD-3-Clause
2+
// copyright-holders:Luca Elia, Olivier Galibert
3+
#ifndef MAME_IGS_IGS011_VIDEO_H
4+
#define MAME_IGS_IGS011_VIDEO_H
5+
6+
#pragma once
7+
8+
class igs011_device : public device_t, public device_gfx_interface
9+
{
10+
public:
11+
igs011_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);
12+
13+
// configurations
14+
template <typename T> void set_host_space(T &&tag, int index) { m_host_space.set_tag(std::forward<T>(tag), index); }
15+
auto restore_space_callback() { return m_restore_space_cb.bind(); }
16+
17+
u32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
18+
19+
void blitter_pen_hi_w(u8 data);
20+
void priority_w(offs_t offset, u16 data, u16 mem_mask = ~0);
21+
u8 layers_r(offs_t offset);
22+
void layers_w(offs_t offset, u8 data);
23+
u16 priority_ram_r(offs_t offset);
24+
void priority_ram_w(offs_t offset, u16 data, u16 mem_mask = ~0);
25+
26+
void prot_w(offs_t offset, u8 data);
27+
u16 prot_r();
28+
void prot_addr_w(u16 data);
29+
30+
void map(address_map &map) ATTR_COLD;
31+
32+
void lhb2_gfx_decrypt() ATTR_COLD;
33+
void drgnwrld_gfx_decrypt() ATTR_COLD;
34+
void vbowl_gfx_unpack() ATTR_COLD;
35+
36+
protected:
37+
virtual void device_start() override ATTR_COLD;
38+
virtual void device_post_load() override ATTR_COLD;
39+
40+
private:
41+
void blit_x_w(offs_t offset, u16 data, u16 mem_mask = ~0);
42+
void blit_y_w(offs_t offset, u16 data, u16 mem_mask = ~0);
43+
void blit_gfx_lo_w(offs_t offset, u16 data, u16 mem_mask = ~0);
44+
void blit_gfx_hi_w(offs_t offset, u16 data, u16 mem_mask = ~0);
45+
void blit_w_w(offs_t offset, u16 data, u16 mem_mask = ~0);
46+
void blit_h_w(offs_t offset, u16 data, u16 mem_mask = ~0);
47+
void blit_depth_w(offs_t offset, u16 data, u16 mem_mask = ~0);
48+
void blit_pen_w(offs_t offset, u16 data, u16 mem_mask = ~0);
49+
void blit_flags_w(offs_t offset, u16 data, u16 mem_mask = ~0);
50+
51+
void prot_addr_change_w(s32 data);
52+
void prot_mem_range_set();
53+
54+
// blitter
55+
struct blitter_t
56+
{
57+
blitter_t()
58+
: x(0), y(0), w(0), h(0)
59+
, gfx_lo(0), gfx_hi(0)
60+
, depth(0)
61+
, pen(0)
62+
, flags(0)
63+
{
64+
}
65+
66+
u16 x, y, w, h;
67+
u16 gfx_lo, gfx_hi;
68+
u16 depth;
69+
u16 pen;
70+
u16 flags;
71+
};
72+
73+
blitter_t m_blitter;
74+
75+
u16 m_priority;
76+
u8 m_blitter_pen_hi;
77+
78+
// protection
79+
u8 m_prot;
80+
u8 m_prot_swap;
81+
u32 m_prot_addr;
82+
s32 m_prev_prot_addr;
83+
84+
memory_share_array_creator<u8, 4> m_layer_ram;
85+
memory_share_creator<u16> m_priority_ram;
86+
87+
required_region_ptr<u8> m_gfx;
88+
optional_region_ptr<u8> m_gfx_hi;
89+
90+
required_address_space m_host_space;
91+
92+
devcb_write32 m_restore_space_cb;
93+
};
94+
95+
DECLARE_DEVICE_TYPE(IGS011, igs011_device)
96+
97+
#endif // MAME_IGS_IGS011_VIDEO_H

src/mame/igs/igs012.cpp

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
// license:BSD-3-Clause
2+
// copyright-holders:Luca Elia, Olivier Galibert
3+
/*
4+
5+
IGS012 protection device
6+
7+
implementation based from igs/igs011.cpp, by Luca Elia/Olivier Galibert.
8+
9+
Used by:
10+
- igs/igs011.cpp
11+
- igs/pgmprot_igs025_igs012.cpp used this chip, but not (or incorrectly) implemented
12+
*/
13+
14+
#include "emu.h"
15+
#include "igs012.h"
16+
17+
void igs012_device::map(address_map &map)
18+
{
19+
map(0x00, 0x0f).w(FUNC(igs012_device::prot_swap_w)); // swap (a5 / 55)
20+
map(0x10, 0x1f).r(FUNC(igs012_device::prot_r)); // read (mode 0)
21+
map(0x20, 0x2f).w(FUNC(igs012_device::prot_dec_inc_w)); // dec (aa), inc (fa)
22+
map(0x30, 0x3f).w(FUNC(igs012_device::prot_inc_w)); // inc (ff)
23+
map(0x40, 0x4f).w(FUNC(igs012_device::prot_copy_w)); // copy (22)
24+
map(0x50, 0x5f).w(FUNC(igs012_device::prot_dec_copy_w)); // dec (5a), copy (33)
25+
map(0x60, 0x6f).r(FUNC(igs012_device::prot_r)); // read (mode 1)
26+
map(0x70, 0x7f).w(FUNC(igs012_device::prot_mode_w)); // mode (cc / dd)
27+
}
28+
29+
DEFINE_DEVICE_TYPE(IGS012, igs012_device, "igs012", "IGS012 Protection Device")
30+
31+
igs012_device::igs012_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
32+
: device_t(mconfig, IGS012, tag, owner, clock)
33+
, m_prot(0)
34+
, m_prot_swap(0)
35+
, m_prot_mode(0)
36+
{
37+
}
38+
39+
void igs012_device::device_start()
40+
{
41+
save_item(NAME(m_prot));
42+
save_item(NAME(m_prot_swap));
43+
save_item(NAME(m_prot_mode));
44+
}
45+
46+
/***************************************************************************
47+
48+
IGS012 Protection ("ASIC12 CHECK PORT ERROR")
49+
50+
The chip holds an internal value, a buffered value and a mode.
51+
These are manipulated by issuing commands, where each command is assigned
52+
a specific address range, and is triggered by writing a specific byte value
53+
to that range. Possible commands:
54+
55+
- INC: increment value
56+
- DEC: decrement value
57+
- SWAP: write bitswap1(value) to buffer
58+
- COPY: copy buffer to value
59+
- MODE: toggle mode (toggles address ranges to write/read and byte values to write)
60+
- RESET: value = 0, mode = 0
61+
62+
The protection value is read from an additional address range:
63+
- READ: read bitswap2(value). Only 2 bits are checked.
64+
65+
***************************************************************************/
66+
67+
68+
void igs012_device::prot_reset_w(u16 data)
69+
{
70+
m_prot = 0x00;
71+
m_prot_swap = 0x00;
72+
73+
m_prot_mode = 0;
74+
}
75+
/*
76+
u16 igs012_device::prot_fake_r(offs_t offset)
77+
{
78+
switch (offset)
79+
{
80+
case 0: return m_prot;
81+
case 1: return m_prot_swap;
82+
case 2: return m_prot_mode;
83+
}
84+
return 0;
85+
}
86+
*/
87+
88+
// Macro that checks whether the current mode and data byte written match the arguments
89+
#define MODE_AND_DATA(_MODE,_DATA) (m_prot_mode == (_MODE) && ((data & 0xff) == (_DATA)) )
90+
91+
void igs012_device::prot_mode_w(offs_t offset, u8 data)
92+
{
93+
if (MODE_AND_DATA(0, 0xcc) || MODE_AND_DATA(1, 0xcc) || MODE_AND_DATA(0, 0xdd) || MODE_AND_DATA(1, 0xdd))
94+
{
95+
m_prot_mode = m_prot_mode ^ 1;
96+
}
97+
else
98+
logerror("%s: warning, unknown prot_mode_w( %04x, %04x ), mode %x\n", machine().describe_context(), offset, data, m_prot_mode);
99+
}
100+
101+
void igs012_device::prot_inc_w(offs_t offset, u8 data)
102+
{
103+
if (MODE_AND_DATA(0, 0xff))
104+
{
105+
m_prot = (m_prot + 1) & 0x1f;
106+
}
107+
else
108+
logerror("%s: warning, unknown prot_inc_w( %04x, %04x ), mode %x\n", machine().describe_context(), offset, data, m_prot_mode);
109+
}
110+
111+
void igs012_device::prot_dec_inc_w(offs_t offset, u8 data)
112+
{
113+
if (MODE_AND_DATA(0, 0xaa))
114+
{
115+
m_prot = (m_prot - 1) & 0x1f;
116+
}
117+
else if (MODE_AND_DATA(1, 0xfa))
118+
{
119+
m_prot = (m_prot + 1) & 0x1f;
120+
}
121+
else
122+
logerror("%s: warning, unknown prot_dec_inc_w( %04x, %04x ), mode %x\n", machine().describe_context(), offset, data, m_prot_mode);
123+
}
124+
125+
void igs012_device::prot_dec_copy_w(offs_t offset, u8 data)
126+
{
127+
if (MODE_AND_DATA(0, 0x33))
128+
{
129+
m_prot = m_prot_swap;
130+
}
131+
else if (MODE_AND_DATA(1, 0x5a))
132+
{
133+
m_prot = (m_prot - 1) & 0x1f;
134+
}
135+
else
136+
logerror("%s: warning, unknown prot_dec_copy_w( %04x, %04x ), mode %x\n", machine().describe_context(), offset, data, m_prot_mode);
137+
}
138+
139+
void igs012_device::prot_copy_w(offs_t offset, u8 data)
140+
{
141+
if (MODE_AND_DATA(1, 0x22))
142+
{
143+
m_prot = m_prot_swap;
144+
}
145+
else
146+
logerror("%s: warning, unknown prot_copy_w( %04x, %04x ), mode %x\n", machine().describe_context(), offset, data, m_prot_mode);
147+
}
148+
149+
void igs012_device::prot_swap_w(offs_t offset, u8 data)
150+
{
151+
if (MODE_AND_DATA(0, 0x55) || MODE_AND_DATA(1, 0xa5))
152+
{
153+
// !(3 | 1)..(2 & 1)..(3 ^ 0)..(!2)
154+
u8 const x = m_prot;
155+
m_prot_swap = (((BIT(x,3)|BIT(x,1))^1)<<3) | ((BIT(x,2)&BIT(x,1))<<2) | ((BIT(x,3)^BIT(x,0))<<1) | (BIT(x,2)^1);
156+
}
157+
else
158+
logerror("%s: warning, unknown prot_swap_w( %04x, %04x ), mode %x\n", machine().describe_context(), offset, data, m_prot_mode);
159+
}
160+
161+
u16 igs012_device::prot_r()
162+
{
163+
// FIXME: mode 0 and mode 1 are mapped to different memory ranges
164+
u8 const x = m_prot;
165+
166+
u8 const b1 = (BIT(x, 3) | BIT(x, 1)) ^ 1;
167+
u8 const b0 = BIT(x, 3) ^ BIT(x, 0);
168+
169+
return (b1 << 1) | (b0 << 0);
170+
}

src/mame/igs/igs012.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// license:BSD-3-Clause
2+
// copyright-holders:Luca Elia, Olivier Galibert
3+
4+
#ifndef MAME_IGS_IGS012_H
5+
#define MAME_IGS_IGS012_H
6+
7+
#pragma once
8+
9+
class igs012_device : public device_t
10+
{
11+
public:
12+
igs012_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
13+
14+
void prot_reset_w(u16 data);
15+
16+
void map(address_map &map) ATTR_COLD;
17+
18+
protected:
19+
virtual void device_start() override ATTR_COLD;
20+
21+
private:
22+
void prot_mode_w(offs_t offset, u8 data);
23+
void prot_inc_w(offs_t offset, u8 data);
24+
void prot_dec_inc_w(offs_t offset, u8 data);
25+
void prot_dec_copy_w(offs_t offset, u8 data);
26+
void prot_copy_w(offs_t offset, u8 data);
27+
void prot_swap_w(offs_t offset, u8 data);
28+
u16 prot_r();
29+
30+
u8 m_prot = 0;
31+
u8 m_prot_swap = 0;
32+
u8 m_prot_mode = 0;
33+
};
34+
35+
36+
DECLARE_DEVICE_TYPE(IGS012, igs012_device)
37+
38+
#endif // MAME_IGS_IGS012_H

src/mame/igs/igs025.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -251,27 +251,28 @@ uint16_t igs025_device::killbld_igs025_prot_r(offs_t offset)
251251

252252
case 0x05:
253253
{
254-
switch (m_kb_ptr)
255-
{
256-
case 1:
257-
return 0x3f00 | ((m_kb_game_id >> 0) & 0xff);
254+
switch (m_kb_ptr)
255+
{
256+
case 1:
257+
return 0x3f00 | ((m_kb_game_id >> 0) & 0xff);
258258

259-
case 2:
260-
return 0x3f00 | ((m_kb_game_id >> 8) & 0xff);
259+
case 2:
260+
return 0x3f00 | ((m_kb_game_id >> 8) & 0xff);
261261

262-
case 3:
263-
return 0x3f00 | ((m_kb_game_id >> 16) & 0xff);
262+
case 3:
263+
return 0x3f00 | ((m_kb_game_id >> 16) & 0xff);
264264

265-
case 4:
266-
return 0x3f00 | ((m_kb_game_id >> 24) & 0xff);
265+
case 4:
266+
return 0x3f00 | ((m_kb_game_id >> 24) & 0xff);
267267

268-
default: // >= 5
269-
return 0x3f00 | bitswap<8>(m_kb_prot_hold, 5, 2, 9, 7, 10, 13, 12, 15);
270-
}
268+
default: // >= 5
269+
return 0x3f00 | bitswap<8>(m_kb_prot_hold, 5, 2, 9, 7, 10, 13, 12, 15);
270+
}
271271
}
272272

273273
case 0x40:
274-
killbld_protection_calculate_hilo();
274+
if (!machine().side_effects_disabled())
275+
killbld_protection_calculate_hilo();
275276
return 0; // Read and then discarded
276277

277278
// default:
@@ -298,7 +299,7 @@ uint16_t igs025_device::killbld_igs025_prot_r(offs_t offset)
298299

299300
void igs025_device::killbld_protection_calculate_hold(int y, int z)
300301
{
301-
unsigned short old = m_kb_prot_hold;
302+
uint16_t old = m_kb_prot_hold;
302303

303304
m_kb_prot_hold = ((old << 1) | (old >> 15));
304305

@@ -315,15 +316,13 @@ void igs025_device::killbld_protection_calculate_hold(int y, int z)
315316

316317
void igs025_device::killbld_protection_calculate_hilo()
317318
{
318-
uint8_t source;
319-
320319
m_kb_prot_hilo_select++;
321320

322321
if (m_kb_prot_hilo_select > 0xeb) {
323322
m_kb_prot_hilo_select = 0;
324323
}
325324

326-
source = m_kb_source_data[m_kb_region][m_kb_prot_hilo_select];
325+
uint8_t source = m_kb_source_data[m_kb_region][m_kb_prot_hilo_select];
327326

328327
if (m_kb_prot_hilo_select & 1)
329328
{

0 commit comments

Comments
 (0)