Previous 199869 Revisions Next

r21061 Thursday 14th February, 2013 at 12:13:54 UTC by Miodrag Milanović
pgm modernization (nw)
[src/mame/drivers]pgm.c
[src/mame/includes]pgm.h
[src/mame/machine]pgmprot.c pgmprot1.c pgmprot2.c pgmprot3.c pgmprot4.c pgmprot5.c pgmprot6.c
[src/mame/video]pgm.c

trunk/src/mame/drivers/pgm.c
r21060r21061
37003700/* This function expands the 32x32 5-bit data into a format which is easier to
37013701   decode in MAME */
37023702
3703static void expand_32x32x5bpp(running_machine &machine)
3703void pgm_state::expand_32x32x5bpp()
37043704{
3705   UINT8 *src = machine.root_device().memregion( "tiles" )->base();
3705   UINT8 *src = memregion( "tiles" )->base();
37063706   gfx_layout glcopy;
37073707   glcopy = *(&pgm32_charlayout);
37083708
3709   size_t  srcsize = machine.root_device().memregion( "tiles" )->bytes();
3709   size_t  srcsize = memregion( "tiles" )->bytes();
37103710   int cnt, pix;
37113711   size_t gfx2_size_needed = ((srcsize/5)*8)+0x1000;
3712   UINT8 *dst = auto_alloc_array(machine, UINT8, gfx2_size_needed);
3712   UINT8 *dst = auto_alloc_array(machine(), UINT8, gfx2_size_needed);
37133713
37143714
37153715   for (cnt = 0; cnt < srcsize/5 ; cnt ++)
r21060r21061
37343734
37353735   glcopy.total = (gfx2_size_needed / glcopy.charincrement)*8;
37363736
3737   machine.gfx[1] = auto_alloc(machine, gfx_element(machine, glcopy, (UINT8 *)dst, 32, 0x400));
3737   machine().gfx[1] = auto_alloc(machine(), gfx_element(machine(), glcopy, (UINT8 *)dst, 32, 0x400));
37383738
37393739
37403740}
r21060r21061
37423742/* This function expands the sprite colour data (in the A Roms) from 3 pixels
37433743   in each word to a byte per pixel making it easier to use */
37443744
3745static void expand_colourdata( running_machine &machine )
3745void pgm_state::expand_colourdata(  )
37463746{
3747   pgm_state *state = machine.driver_data<pgm_state>();
3748   UINT8 *src = state->memregion( "sprcol" )->base();
3749   size_t srcsize = state->memregion( "sprcol" )->bytes();
3747   UINT8 *src = memregion( "sprcol" )->base();
3748   size_t srcsize = memregion( "sprcol" )->bytes();
37503749   int cnt;
37513750   size_t needed = srcsize / 2 * 3;
37523751
37533752   /* work out how much ram we need to allocate to expand the sprites into
37543753      and be able to mask the offset */
3755   state->m_sprite_a_region_size = 1;
3756   while (state->m_sprite_a_region_size < needed)
3757      state->m_sprite_a_region_size <<= 1;
3754   m_sprite_a_region_size = 1;
3755   while (m_sprite_a_region_size < needed)
3756      m_sprite_a_region_size <<= 1;
37583757
3759   state->m_sprite_a_region = auto_alloc_array(machine, UINT8, state->m_sprite_a_region_size);
3758   m_sprite_a_region = auto_alloc_array(machine(), UINT8, m_sprite_a_region_size);
37603759
37613760   for (cnt = 0 ; cnt < srcsize / 2 ; cnt++)
37623761   {
37633762      UINT16 colpack;
37643763
37653764      colpack = ((src[cnt * 2]) | (src[cnt * 2 + 1] << 8));
3766      state->m_sprite_a_region[cnt * 3 + 0] = (colpack >> 0 ) & 0x1f;
3767      state->m_sprite_a_region[cnt * 3 + 1] = (colpack >> 5 ) & 0x1f;
3768      state->m_sprite_a_region[cnt * 3 + 2] = (colpack >> 10) & 0x1f;
3765      m_sprite_a_region[cnt * 3 + 0] = (colpack >> 0 ) & 0x1f;
3766      m_sprite_a_region[cnt * 3 + 1] = (colpack >> 5 ) & 0x1f;
3767      m_sprite_a_region[cnt * 3 + 2] = (colpack >> 10) & 0x1f;
37693768   }
37703769}
37713770
3772void pgm_basic_init( running_machine &machine, bool set_bank)
3771void pgm_state::pgm_basic_init( bool set_bank)
37733772{
3774   pgm_state *state = machine.driver_data<pgm_state>();
3773   UINT8 *ROM = memregion("maincpu")->base();
3774   if (set_bank) membank("bank1")->set_base(&ROM[0x100000]);
37753775
3776   UINT8 *ROM = state->memregion("maincpu")->base();
3777   if (set_bank) state->membank("bank1")->set_base(&ROM[0x100000]);
3776   expand_32x32x5bpp();
3777   expand_colourdata();
37783778
3779   expand_32x32x5bpp(machine);
3780   expand_colourdata(machine);
3781
3782   state->m_bg_videoram = &state->m_videoram[0];
3783   state->m_tx_videoram = &state->m_videoram[0x4000/2];
3784   state->m_rowscrollram = &state->m_videoram[0x7000/2];
3779   m_bg_videoram = &m_videoram[0];
3780   m_tx_videoram = &m_videoram[0x4000/2];
3781   m_rowscrollram = &m_videoram[0x7000/2];
37853782}
37863783
37873784DRIVER_INIT_MEMBER(pgm_state,pgm)
37883785{
3789   pgm_basic_init(machine());
3786   pgm_basic_init();
37903787}
37913788
37923789
trunk/src/mame/machine/pgmprot1.c
r21060r21061
5656/**************************** EMULATION *******************************/
5757/* used by photoy2k, kovsh */
5858
59static READ32_HANDLER( pgm_arm7_type1_protlatch_r )
59READ32_MEMBER(pgm_arm_type1_state::pgm_arm7_type1_protlatch_r )
6060{
61   pgm_arm_type1_state *state = space.machine().driver_data<pgm_arm_type1_state>();
61   machine().scheduler().synchronize(); // force resync
6262
63   space.machine().scheduler().synchronize(); // force resync
64
65   return (state->m_pgm_arm_type1_highlatch_68k_w << 16) | (state->m_pgm_arm_type1_lowlatch_68k_w);
63   return (m_pgm_arm_type1_highlatch_68k_w << 16) | (m_pgm_arm_type1_lowlatch_68k_w);
6664}
6765
68static WRITE32_HANDLER( pgm_arm7_type1_protlatch_w )
69{
70   pgm_arm_type1_state *state = space.machine().driver_data<pgm_arm_type1_state>();
66WRITE32_MEMBER(pgm_arm_type1_state::pgm_arm7_type1_protlatch_w )
67{   
68   machine().scheduler().synchronize(); // force resync
7169
72   space.machine().scheduler().synchronize(); // force resync
73
7470   if (ACCESSING_BITS_16_31)
7571   {
76      state->m_pgm_arm_type1_highlatch_arm_w = data >> 16;
77      state->m_pgm_arm_type1_highlatch_68k_w = 0;
72      m_pgm_arm_type1_highlatch_arm_w = data >> 16;
73      m_pgm_arm_type1_highlatch_68k_w = 0;
7874   }
7975   if (ACCESSING_BITS_0_15)
8076   {
81      state->m_pgm_arm_type1_lowlatch_arm_w = data;
82      state->m_pgm_arm_type1_lowlatch_68k_w = 0;
77      m_pgm_arm_type1_lowlatch_arm_w = data;
78      m_pgm_arm_type1_lowlatch_68k_w = 0;
8379   }
8480}
8581
86static READ16_HANDLER( pgm_arm7_type1_68k_protlatch_r )
87{
88   pgm_arm_type1_state *state = space.machine().driver_data<pgm_arm_type1_state>();
82READ16_MEMBER(pgm_arm_type1_state::pgm_arm7_type1_68k_protlatch_r )
83{   
84   machine().scheduler().synchronize(); // force resync
8985
90   space.machine().scheduler().synchronize(); // force resync
91
9286   switch (offset)
9387   {
94      case 1: return state->m_pgm_arm_type1_highlatch_arm_w;
95      case 0: return state->m_pgm_arm_type1_lowlatch_arm_w;
88      case 1: return m_pgm_arm_type1_highlatch_arm_w;
89      case 0: return m_pgm_arm_type1_lowlatch_arm_w;
9690   }
9791   return -1;
9892}
9993
100static WRITE16_HANDLER( pgm_arm7_type1_68k_protlatch_w )
94WRITE16_MEMBER(pgm_arm_type1_state::pgm_arm7_type1_68k_protlatch_w )
10195{
102   pgm_arm_type1_state *state = space.machine().driver_data<pgm_arm_type1_state>();
96   machine().scheduler().synchronize(); // force resync
10397
104   space.machine().scheduler().synchronize(); // force resync
105
10698   switch (offset)
10799   {
108100      case 1:
109         state->m_pgm_arm_type1_highlatch_68k_w = data;
101         m_pgm_arm_type1_highlatch_68k_w = data;
110102         break;
111103
112104      case 0:
113         state->m_pgm_arm_type1_lowlatch_68k_w = data;
105         m_pgm_arm_type1_lowlatch_68k_w = data;
114106         break;
115107   }
116108}
117109
118static READ16_HANDLER( pgm_arm7_type1_ram_r )
110READ16_MEMBER(pgm_arm_type1_state::pgm_arm7_type1_ram_r )
119111{
120   pgm_arm_type1_state *state = space.machine().driver_data<pgm_arm_type1_state>();
121   UINT16 *share16 = reinterpret_cast<UINT16 *>(state->m_arm7_shareram.target());
112   UINT16 *share16 = reinterpret_cast<UINT16 *>(m_arm7_shareram.target());
122113
123114   if (PGMARM7LOGERROR)
124115      logerror("M68K: ARM7 Shared RAM Read: %04x = %04x (%08x) (%06x)\n", BYTE_XOR_LE(offset), share16[BYTE_XOR_LE(offset)], mem_mask, space.device().safe_pc());
125116   return share16[BYTE_XOR_LE(offset << 1)];
126117}
127118
128static WRITE16_HANDLER( pgm_arm7_type1_ram_w )
119WRITE16_MEMBER(pgm_arm_type1_state::pgm_arm7_type1_ram_w )
129120{
130   pgm_arm_type1_state *state = space.machine().driver_data<pgm_arm_type1_state>();
131   UINT16 *share16 = reinterpret_cast<UINT16 *>(state->m_arm7_shareram.target());
121   UINT16 *share16 = reinterpret_cast<UINT16 *>(m_arm7_shareram.target());
132122
133123   if (PGMARM7LOGERROR)
134124      logerror("M68K: ARM7 Shared RAM Write: %04x = %04x (%04x) (%06x)\n", BYTE_XOR_LE(offset), data, mem_mask, space.device().safe_pc());
r21060r21061
138128
139129
140130
141static READ32_HANDLER( pgm_arm7_type1_unk_r )
131READ32_MEMBER(pgm_arm_type1_state::pgm_arm7_type1_unk_r )
142132{
143   pgm_arm_type1_state *state = space.machine().driver_data<pgm_arm_type1_state>();
144   return state->m_pgm_arm_type1_counter++;
133   return m_pgm_arm_type1_counter++;
145134}
146135
147static READ32_HANDLER( pgm_arm7_type1_exrom_r )
136READ32_MEMBER(pgm_arm_type1_state::pgm_arm7_type1_exrom_r )
148137{
149138   return 0x00000000;
150139}
151140
152static READ32_HANDLER( pgm_arm7_type1_shareram_r )
141READ32_MEMBER(pgm_arm_type1_state::pgm_arm7_type1_shareram_r )
153142{
154   pgm_arm_type1_state *state = space.machine().driver_data<pgm_arm_type1_state>();
155
156143   if (PGMARM7LOGERROR)
157      logerror("ARM7: ARM7 Shared RAM Read: %04x = %08x (%08x) (%06x)\n", offset << 2, state->m_arm7_shareram[offset], mem_mask, space.device().safe_pc());
158   return state->m_arm7_shareram[offset];
144      logerror("ARM7: ARM7 Shared RAM Read: %04x = %08x (%08x) (%06x)\n", offset << 2, m_arm7_shareram[offset], mem_mask, space.device().safe_pc());
145   return m_arm7_shareram[offset];
159146}
160147
161static WRITE32_HANDLER( pgm_arm7_type1_shareram_w )
148WRITE32_MEMBER(pgm_arm_type1_state::pgm_arm7_type1_shareram_w )
162149{
163   pgm_arm_type1_state *state = space.machine().driver_data<pgm_arm_type1_state>();
164
165150   if (PGMARM7LOGERROR)
166151      logerror("ARM7: ARM7 Shared RAM Write: %04x = %08x (%08x) (%06x)\n", offset << 2, data, mem_mask, space.device().safe_pc());
167   COMBINE_DATA(&state->m_arm7_shareram[offset]);
152   COMBINE_DATA(&m_arm7_shareram[offset]);
168153}
169154
170155/* 55857E? */
r21060r21061
173158static ADDRESS_MAP_START( kov_map, AS_PROGRAM, 16, pgm_arm_type1_state )
174159   AM_IMPORT_FROM(pgm_mem)
175160   AM_RANGE(0x100000, 0x4effff) AM_ROMBANK("bank1") /* Game ROM */
176   AM_RANGE(0x4f0000, 0x4f003f) AM_READWRITE_LEGACY(pgm_arm7_type1_ram_r, pgm_arm7_type1_ram_w) /* ARM7 Shared RAM */
177   AM_RANGE(0x500000, 0x500005) AM_READWRITE_LEGACY(pgm_arm7_type1_68k_protlatch_r, pgm_arm7_type1_68k_protlatch_w) /* ARM7 Latch */
161   AM_RANGE(0x4f0000, 0x4f003f) AM_READWRITE(pgm_arm7_type1_ram_r, pgm_arm7_type1_ram_w) /* ARM7 Shared RAM */
162   AM_RANGE(0x500000, 0x500005) AM_READWRITE(pgm_arm7_type1_68k_protlatch_r, pgm_arm7_type1_68k_protlatch_w) /* ARM7 Latch */
178163ADDRESS_MAP_END
179164
180165static ADDRESS_MAP_START( 55857E_arm7_map, AS_PROGRAM, 32, pgm_arm_type1_state )
181166   AM_RANGE(0x00000000, 0x00003fff) AM_ROM
182   AM_RANGE(0x08100000, 0x083fffff) AM_READ_LEGACY(pgm_arm7_type1_exrom_r) // unpopulated, returns 0 to keep checksum happy
167   AM_RANGE(0x08100000, 0x083fffff) AM_READ(pgm_arm7_type1_exrom_r) // unpopulated, returns 0 to keep checksum happy
183168   AM_RANGE(0x10000000, 0x100003ff) AM_RAM // internal ram for asic
184   AM_RANGE(0x40000000, 0x40000003) AM_READWRITE_LEGACY(pgm_arm7_type1_protlatch_r, pgm_arm7_type1_protlatch_w)
169   AM_RANGE(0x40000000, 0x40000003) AM_READWRITE(pgm_arm7_type1_protlatch_r, pgm_arm7_type1_protlatch_w)
185170   AM_RANGE(0x40000008, 0x4000000b) AM_WRITENOP // ?
186   AM_RANGE(0x4000000c, 0x4000000f) AM_READ_LEGACY(pgm_arm7_type1_unk_r)
187   AM_RANGE(0x50800000, 0x5080003f) AM_READWRITE_LEGACY(pgm_arm7_type1_shareram_r, pgm_arm7_type1_shareram_w) AM_SHARE("arm7_shareram")
171   AM_RANGE(0x4000000c, 0x4000000f) AM_READ(pgm_arm7_type1_unk_r)
172   AM_RANGE(0x50800000, 0x5080003f) AM_READWRITE(pgm_arm7_type1_shareram_r, pgm_arm7_type1_shareram_w) AM_SHARE("arm7_shareram")
188173   AM_RANGE(0x50000000, 0x500003ff) AM_RAM // uploads xor table to decrypt 68k rom here
189174ADDRESS_MAP_END
190175
r21060r21061
252237   MCFG_CPU_PROGRAM_MAP(55857E_arm7_map)
253238MACHINE_CONFIG_END
254239
255void pgm_arm7_type1_latch_init( running_machine &machine )
240void pgm_arm_type1_state::pgm_arm7_type1_latch_init()
256241{
257   pgm_arm_type1_state *state = machine.driver_data<pgm_arm_type1_state>();
242   m_pgm_arm_type1_highlatch_arm_w = 0;
243   m_pgm_arm_type1_lowlatch_arm_w = 0;
244   m_pgm_arm_type1_highlatch_68k_w = 0;
245   m_pgm_arm_type1_lowlatch_68k_w = 0;
246   m_pgm_arm_type1_counter = 1;
258247
259   state->m_pgm_arm_type1_highlatch_arm_w = 0;
260   state->m_pgm_arm_type1_lowlatch_arm_w = 0;
261   state->m_pgm_arm_type1_highlatch_68k_w = 0;
262   state->m_pgm_arm_type1_lowlatch_68k_w = 0;
263   state->m_pgm_arm_type1_counter = 1;
264
265   state->save_item(NAME(state->m_pgm_arm_type1_highlatch_arm_w));
266   state->save_item(NAME(state->m_pgm_arm_type1_lowlatch_arm_w));
267   state->save_item(NAME(state->m_pgm_arm_type1_highlatch_68k_w));
268   state->save_item(NAME(state->m_pgm_arm_type1_lowlatch_68k_w));
269   state->save_item(NAME(state->m_pgm_arm_type1_counter));
248   save_item(NAME(m_pgm_arm_type1_highlatch_arm_w));
249   save_item(NAME(m_pgm_arm_type1_lowlatch_arm_w));
250   save_item(NAME(m_pgm_arm_type1_highlatch_68k_w));
251   save_item(NAME(m_pgm_arm_type1_lowlatch_68k_w));
252   save_item(NAME(m_pgm_arm_type1_counter));
270253}
271254
272static READ16_HANDLER( kovsh_fake_region_r )
255READ16_MEMBER(pgm_arm_type1_state::kovsh_fake_region_r )
273256{
274   pgm_arm_type1_state *state = space.machine().driver_data<pgm_arm_type1_state>();
275   int regionhack = state->ioport("RegionHack")->read();
257   int regionhack = ioport("RegionHack")->read();
276258   if (regionhack != 0xff) return regionhack;
277259
278260   offset = 0x4;
279   UINT16 *share16 = reinterpret_cast<UINT16 *>(state->m_arm7_shareram.target());
261   UINT16 *share16 = reinterpret_cast<UINT16 *>(m_arm7_shareram.target());
280262   return share16[BYTE_XOR_LE(offset << 1)];
281263}
282264
283265DRIVER_INIT_MEMBER(pgm_arm_type1_state,photoy2k)
284266{
285   pgm_basic_init(machine());
267   pgm_basic_init();
286268   pgm_photoy2k_decrypt(machine());
287   pgm_arm7_type1_latch_init(machine());
269   pgm_arm7_type1_latch_init();
288270   /* we only have a china internal ROM dumped for now.. allow region to be changed for debugging (to ensure all alt titles / regions can be seen) */
289   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x4f0008, 0x4f0009, FUNC(kovsh_fake_region_r));
271   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x4f0008, 0x4f0009, read16_delegate(FUNC(pgm_arm_type1_state::kovsh_fake_region_r),this));
290272}
291273
292274DRIVER_INIT_MEMBER(pgm_arm_type1_state,kovsh)
293275{
294   pgm_basic_init(machine());
276   pgm_basic_init();
295277   pgm_kovsh_decrypt(machine());
296   pgm_arm7_type1_latch_init(machine());
278   pgm_arm7_type1_latch_init();
297279   /* we only have a china internal ROM dumped for now.. allow region to be changed for debugging (to ensure all alt titles / regions can be seen) */
298   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x4f0008, 0x4f0009, FUNC(kovsh_fake_region_r));
280   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x4f0008, 0x4f0009, read16_delegate(FUNC(pgm_arm_type1_state::kovsh_fake_region_r),this));
299281}
300282
301283/* Fake remapping of ASIC commands to the ones used by KOVSH due to the lack of the real ARM rom for this set */
302WRITE16_HANDLER( kovshp_asic27a_write_word )
284WRITE16_MEMBER(pgm_arm_type1_state::kovshp_asic27a_write_word )
303285{
304   pgm_arm_type1_state *state = space.machine().driver_data<pgm_arm_type1_state>();
305
306286   switch (offset)
307287   {
308288      case 0:
309         state->m_pgm_arm_type1_lowlatch_68k_w = data;
289         m_pgm_arm_type1_lowlatch_68k_w = data;
310290      return;
311291
312292      case 1:
r21060r21061
353333            case 0xf8: asic_cmd = 0xf3; break;
354334         }
355335
356         state->m_pgm_arm_type1_highlatch_68k_w = asic_cmd ^ (asic_key | (asic_key << 8));
336         m_pgm_arm_type1_highlatch_68k_w = asic_cmd ^ (asic_key | (asic_key << 8));
357337      }
358338      return;
359339   }
r21060r21061
362342
363343DRIVER_INIT_MEMBER(pgm_arm_type1_state,kovshp)
364344{
365   pgm_basic_init(machine());
345   pgm_basic_init();
366346   pgm_kovshp_decrypt(machine());
367   pgm_arm7_type1_latch_init(machine());
368   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x4f0008, 0x4f0009, FUNC(kovsh_fake_region_r));
369   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_write_handler(0x500000, 0x500005, FUNC(kovshp_asic27a_write_word));
347   pgm_arm7_type1_latch_init();
348   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x4f0008, 0x4f0009, read16_delegate(FUNC(pgm_arm_type1_state::kovsh_fake_region_r),this));
349   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x500000, 0x500005, write16_delegate(FUNC(pgm_arm_type1_state::kovshp_asic27a_write_word),this));
370350}
371351
372352
r21060r21061
375355
376356DRIVER_INIT_MEMBER(pgm_arm_type1_state,kovshxas)
377357{
378   pgm_basic_init(machine());
358   pgm_basic_init();
379359//  pgm_kovshp_decrypt(machine());
380   pgm_arm7_type1_latch_init(machine());
381   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x4f0008, 0x4f0009, FUNC(kovsh_fake_region_r));
382   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_write_handler(0x500000, 0x500005, FUNC(kovshp_asic27a_write_word));
360   pgm_arm7_type1_latch_init();
361   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x4f0008, 0x4f0009, read16_delegate(FUNC(pgm_arm_type1_state::kovsh_fake_region_r),this));
362   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x500000, 0x500005, write16_delegate(FUNC(pgm_arm_type1_state::kovshp_asic27a_write_word),this));
383363}
384364
385static void pgm_decode_kovlsqh2_tiles( running_machine &machine )
365void pgm_arm_type1_state::pgm_decode_kovlsqh2_tiles()
386366{
387367   int i, j;
388   UINT16 *src = (UINT16 *)(machine.root_device().memregion("tiles")->base() + 0x180000);
389   UINT16 *dst = auto_alloc_array(machine, UINT16, 0x800000);
368   UINT16 *src = (UINT16 *)(memregion("tiles")->base() + 0x180000);
369   UINT16 *dst = auto_alloc_array(machine(), UINT16, 0x800000);
390370
391371   for (i = 0; i < 0x800000 / 2; i++)
392372   {
r21060r21061
397377
398378   memcpy( src, dst, 0x800000 );
399379
400   auto_free( machine, dst );
380   auto_free( machine(), dst );
401381}
402382
403static void pgm_decode_kovlsqh2_sprites( running_machine &machine, UINT8 *src )
383void pgm_arm_type1_state::pgm_decode_kovlsqh2_sprites( UINT8 *src )
404384{
405385   int i, j;
406   UINT8 *dst = auto_alloc_array(machine, UINT8, 0x800000);
386   UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x800000);
407387
408388   for (i = 0; i < 0x800000; i++)
409389   {
r21060r21061
414394
415395   memcpy( src, dst, 0x800000 );
416396
417   auto_free( machine, dst );
397   auto_free( machine(), dst );
418398}
419399
420static void pgm_decode_kovlsqh2_samples( running_machine &machine )
400void pgm_arm_type1_state::pgm_decode_kovlsqh2_samples()
421401{
422402   int i;
423   UINT8 *src = (UINT8 *)(machine.root_device().memregion("ics")->base() + 0x400000);
403   UINT8 *src = (UINT8 *)(memregion("ics")->base() + 0x400000);
424404
425405   for (i = 0; i < 0x400000; i+=2) {
426406      src[i + 0x000001] = src[i + 0x400001];
r21060r21061
429409   memcpy( src + 0x400000, src, 0x400000 );
430410}
431411
432static void pgm_decode_kovqhsgs_program( running_machine &machine )
412void pgm_arm_type1_state::pgm_decode_kovqhsgs_program()
433413{
434414   int i;
435   UINT16 *src = (UINT16 *)(machine.root_device().memregion("maincpu")->base() + 0x100000);
436   UINT16 *dst = auto_alloc_array(machine, UINT16, 0x400000);
415   UINT16 *src = (UINT16 *)(memregion("maincpu")->base() + 0x100000);
416   UINT16 *dst = auto_alloc_array(machine(), UINT16, 0x400000);
437417
438418   for (i = 0; i < 0x400000 / 2; i++)
439419   {
r21060r21061
444424
445425   memcpy( src, dst, 0x400000 );
446426
447   auto_free( machine, dst );
427   auto_free( machine(), dst );
448428}
449429
450static void pgm_decode_kovqhsgs2_program( running_machine &machine )
430void pgm_arm_type1_state::pgm_decode_kovqhsgs2_program()
451431{
452432   int i;
453   UINT16 *src = (UINT16 *)(machine.root_device().memregion("maincpu")->base() + 0x100000);
454   UINT16 *dst = auto_alloc_array(machine, UINT16, 0x400000);
433   UINT16 *src = (UINT16 *)(memregion("maincpu")->base() + 0x100000);
434   UINT16 *dst = auto_alloc_array(machine(), UINT16, 0x400000);
455435
456436   for (i = 0; i < 0x400000 / 2; i++)
457437   {
r21060r21061
462442
463443   memcpy( src, dst, 0x400000 );
464444
465   auto_free( machine, dst );
445   auto_free( machine(), dst );
466446}
467447
468448
469449DRIVER_INIT_MEMBER(pgm_arm_type1_state,kovlsqh2)
470450{
471   pgm_decode_kovqhsgs2_program(machine());
472   pgm_decode_kovlsqh2_tiles(machine());
451   pgm_decode_kovqhsgs2_program();
452   pgm_decode_kovlsqh2_tiles();
473453
474   pgm_decode_kovlsqh2_sprites(machine(), machine().root_device().memregion("sprcol")->base() + 0x0000000);
475   pgm_decode_kovlsqh2_sprites(machine(), machine().root_device().memregion("sprcol")->base() + 0x0800000);
476   pgm_decode_kovlsqh2_sprites(machine(), machine().root_device().memregion("sprcol")->base() + 0x1000000);
477   pgm_decode_kovlsqh2_sprites(machine(), machine().root_device().memregion("sprcol")->base() + 0x1800000);
478   pgm_decode_kovlsqh2_sprites(machine(), machine().root_device().memregion("sprcol")->base() + 0x2000000);
479   pgm_decode_kovlsqh2_sprites(machine(), machine().root_device().memregion("sprcol")->base() + 0x2800000);
480   pgm_decode_kovlsqh2_sprites(machine(), machine().root_device().memregion("sprmask")->base() + 0x0000000);
481   pgm_decode_kovlsqh2_sprites(machine(), machine().root_device().memregion("sprmask")->base() + 0x0800000);
454   pgm_decode_kovlsqh2_sprites(memregion("sprcol")->base() + 0x0000000);
455   pgm_decode_kovlsqh2_sprites(memregion("sprcol")->base() + 0x0800000);
456   pgm_decode_kovlsqh2_sprites(memregion("sprcol")->base() + 0x1000000);
457   pgm_decode_kovlsqh2_sprites(memregion("sprcol")->base() + 0x1800000);
458   pgm_decode_kovlsqh2_sprites(memregion("sprcol")->base() + 0x2000000);
459   pgm_decode_kovlsqh2_sprites(memregion("sprcol")->base() + 0x2800000);
460   pgm_decode_kovlsqh2_sprites(memregion("sprmask")->base() + 0x0000000);
461   pgm_decode_kovlsqh2_sprites(memregion("sprmask")->base() + 0x0800000);
482462
483   pgm_decode_kovlsqh2_samples(machine());
484   pgm_basic_init(machine());
485   pgm_arm7_type1_latch_init(machine());
486   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x4f0008, 0x4f0009, FUNC(kovsh_fake_region_r));
487   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_write_handler(0x500000, 0x500005, FUNC(kovshp_asic27a_write_word));
463   pgm_decode_kovlsqh2_samples();
464   pgm_basic_init();
465   pgm_arm7_type1_latch_init();
466   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x4f0008, 0x4f0009, read16_delegate(FUNC(pgm_arm_type1_state::kovsh_fake_region_r),this));
467   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x500000, 0x500005, write16_delegate(FUNC(pgm_arm_type1_state::kovshp_asic27a_write_word),this));
488468}
489469
490470DRIVER_INIT_MEMBER(pgm_arm_type1_state,kovqhsgs)
491471{
492   pgm_decode_kovqhsgs_program(machine());
493   pgm_decode_kovlsqh2_tiles(machine());
472   pgm_decode_kovqhsgs_program();
473   pgm_decode_kovlsqh2_tiles();
494474
495   pgm_decode_kovlsqh2_sprites(machine(), machine().root_device().memregion("sprcol")->base() + 0x0000000);
496   pgm_decode_kovlsqh2_sprites(machine(), machine().root_device().memregion("sprcol")->base() + 0x0800000);
497   pgm_decode_kovlsqh2_sprites(machine(), machine().root_device().memregion("sprcol")->base() + 0x1000000);
498   pgm_decode_kovlsqh2_sprites(machine(), machine().root_device().memregion("sprcol")->base() + 0x1800000);
499   pgm_decode_kovlsqh2_sprites(machine(), machine().root_device().memregion("sprcol")->base() + 0x2000000);
500   pgm_decode_kovlsqh2_sprites(machine(), machine().root_device().memregion("sprcol")->base() + 0x2800000);
501   pgm_decode_kovlsqh2_sprites(machine(), machine().root_device().memregion("sprmask")->base() + 0x0000000);
502   pgm_decode_kovlsqh2_sprites(machine(), machine().root_device().memregion("sprmask")->base() + 0x0800000);
475   pgm_decode_kovlsqh2_sprites(memregion("sprcol")->base() + 0x0000000);
476   pgm_decode_kovlsqh2_sprites(memregion("sprcol")->base() + 0x0800000);
477   pgm_decode_kovlsqh2_sprites(memregion("sprcol")->base() + 0x1000000);
478   pgm_decode_kovlsqh2_sprites(memregion("sprcol")->base() + 0x1800000);
479   pgm_decode_kovlsqh2_sprites(memregion("sprcol")->base() + 0x2000000);
480   pgm_decode_kovlsqh2_sprites(memregion("sprcol")->base() + 0x2800000);
481   pgm_decode_kovlsqh2_sprites(memregion("sprmask")->base() + 0x0000000);
482   pgm_decode_kovlsqh2_sprites(memregion("sprmask")->base() + 0x0800000);
503483
504   pgm_decode_kovlsqh2_samples(machine());
505   pgm_basic_init(machine());
506   pgm_arm7_type1_latch_init(machine());
484   pgm_decode_kovlsqh2_samples();
485   pgm_basic_init();
486   pgm_arm7_type1_latch_init();
507487   /* we only have a china internal ROM dumped for now.. allow region to be changed for debugging (to ensure all alt titles / regions can be seen) */
508   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x4f0008, 0x4f0009, FUNC(kovsh_fake_region_r));
488   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x4f0008, 0x4f0009, read16_delegate(FUNC(pgm_arm_type1_state::kovsh_fake_region_r),this));
509489}
510490
511491/*
r21060r21061
517497 bp A71A0,1,{d0=0x12;g}
518498*/
519499
520static READ16_HANDLER( pgm_arm7_type1_sim_r )
500READ16_MEMBER(pgm_arm_type1_state::pgm_arm7_type1_sim_r )
521501{
522   pgm_arm_type1_state *state = space.machine().driver_data<pgm_arm_type1_state>();
523
524502   if (offset == 0)
525503   {
526      UINT16 d = state->m_valueresponse & 0xffff;
527      UINT16 realkey = state->m_valuekey >> 8;
528      realkey |= state->m_valuekey;
504      UINT16 d = m_valueresponse & 0xffff;
505      UINT16 realkey = m_valuekey >> 8;
506      realkey |= m_valuekey;
529507      d ^= realkey;
530508
531509      return d;
r21060r21061
533511   }
534512   else if (offset == 1)
535513   {
536      UINT16 d = state->m_valueresponse >> 16;
537      UINT16 realkey = state->m_valuekey >> 8;
538      realkey |= state->m_valuekey;
514      UINT16 d = m_valueresponse >> 16;
515      UINT16 realkey = m_valuekey >> 8;
516      realkey |= m_valuekey;
539517      d ^= realkey;
540518      return d;
541519
r21060r21061
544522}
545523
546524/* working */
547void command_handler_ddp3(pgm_arm_type1_state *state, int pc)
525void pgm_arm_type1_state::command_handler_ddp3(int pc)
548526{
549   switch (state->m_ddp3lastcommand)
527   switch (m_ddp3lastcommand)
550528   {
551529      default:
552         printf("%06x command %02x | %04x\n", pc, state->m_ddp3lastcommand, state->m_value0);
553         state->m_valueresponse = 0x880000;
530         printf("%06x command %02x | %04x\n", pc, m_ddp3lastcommand, m_value0);
531         m_valueresponse = 0x880000;
554532         break;
555533
556534      case 0x40:
557         state->m_valueresponse = 0x880000;
558         state->m_slots[(state->m_value0>>10)&0x1F]=
559            (state->m_slots[(state->m_value0>>5)&0x1F]+
560               state->m_slots[(state->m_value0>>0)&0x1F])&0xffffff;
535         m_valueresponse = 0x880000;
536         m_slots[(m_value0>>10)&0x1F]=
537            (m_slots[(m_value0>>5)&0x1F]+
538               m_slots[(m_value0>>0)&0x1F])&0xffffff;
561539         break;
562540
563541      case 0x67: // set high bits
564   //      printf("%06x command %02x | %04x\n", space.device().safe_pc(), state->m_ddp3lastcommand, state->m_value0);
565         state->m_valueresponse = 0x880000;
566         state->m_curslots = (state->m_value0 & 0xff00)>>8;
567         state->m_slots[state->m_curslots] = (state->m_value0 & 0x00ff) << 16;
542   //      printf("%06x command %02x | %04x\n", space.device().safe_pc(), m_ddp3lastcommand, m_value0);
543         m_valueresponse = 0x880000;
544         m_curslots = (m_value0 & 0xff00)>>8;
545         m_slots[m_curslots] = (m_value0 & 0x00ff) << 16;
568546         break;
569547
570548      case 0xe5: // set low bits for operation?
571      //  printf("%06x command %02x | %04x\n", space.device().safe_pc(), state->m_ddp3lastcommand, state->m_value0);
572         state->m_valueresponse = 0x880000;
573         state->m_slots[state->m_curslots] |= (state->m_value0 & 0xffff);
549      //  printf("%06x command %02x | %04x\n", space.device().safe_pc(), m_ddp3lastcommand, m_value0);
550         m_valueresponse = 0x880000;
551         m_slots[m_curslots] |= (m_value0 & 0xffff);
574552         break;
575553
576554
577555      case 0x8e: // read back result of operations
578   //      printf("%06x command %02x | %04x\n", space.device().safe_pc(), state->m_ddp3lastcommand, state->m_value0);
579         state->m_valueresponse = state->m_slots[state->m_value0&0xff];
556   //      printf("%06x command %02x | %04x\n", space.device().safe_pc(), m_ddp3lastcommand, m_value0);
557         m_valueresponse = m_slots[m_value0&0xff];
580558         break;
581559
582560
583561      case 0x99: // reset?
584         state->m_valuekey = 0x100;
585         state->m_valueresponse = 0x00880000;
562         m_valuekey = 0x100;
563         m_valueresponse = 0x00880000;
586564         break;
587565
588566   }
r21060r21061
590568
591569/* preliminary */
592570
593void command_handler_puzzli2(pgm_arm_type1_state *state, int pc)
571void pgm_arm_type1_state::command_handler_puzzli2(int pc)
594572{
595   printf("%08x: %02x %04x\n",pc, state->m_ddp3lastcommand, state->m_value0);
573   printf("%08x: %02x %04x\n",pc, m_ddp3lastcommand, m_value0);
596574
597   switch (state->m_ddp3lastcommand)
575   switch (m_ddp3lastcommand)
598576   {
599577      case 0x13: // ASIC status?
600         state->m_valueresponse = 0x74<<16; // 2d or 74! (based on?)
578         m_valueresponse = 0x74<<16; // 2d or 74! (based on?)
601579      break;
602580
603581      case 0x31:
r21060r21061
605583         // how is this selected? command 54?
606584
607585         // just a wild guess
608         if (state->m_puzzli_54_trigger) {
586         if (m_puzzli_54_trigger) {
609587            // pc == 1387de
610            state->m_valueresponse = 0x63<<16; // ?
588            m_valueresponse = 0x63<<16; // ?
611589         } else {
612590            // pc == 14cf58
613            state->m_valueresponse = 0xd2<<16;
591            m_valueresponse = 0xd2<<16;
614592         }
615593
616         state->m_puzzli_54_trigger = 0;
594         m_puzzli_54_trigger = 0;
617595      }
618596      break;
619597
620598      case 0x38: // Reset
621         state->m_valueresponse = 0x78<<16;
622         state->m_valuekey = 0x100;
623         state->m_puzzli_54_trigger = 0;
599         m_valueresponse = 0x78<<16;
600         m_valuekey = 0x100;
601         m_puzzli_54_trigger = 0;
624602      break;
625603
626604      case 0x41: // ASIC status?
627         state->m_valueresponse = 0x74<<16;
605         m_valueresponse = 0x74<<16;
628606      break;
629607
630608      case 0x47: // ASIC status?
631         state->m_valueresponse = 0x74<<16;
609         m_valueresponse = 0x74<<16;
632610      break;
633611
634612      case 0x52: // ASIC status?
635613      {
636614         // how is this selected?
637615
638         //if (state->m_value0 == 6) {
639            state->m_valueresponse = (0x74<<16)|1; // |1?
616         //if (m_value0 == 6) {
617            m_valueresponse = (0x74<<16)|1; // |1?
640618         //} else {
641         //  state->m_valueresponse = 0x74<<16;
619         //  m_valueresponse = 0x74<<16;
642620         //}
643621      }
644622      break;
645623
646624      case 0x54: // ??
647         state->m_puzzli_54_trigger = 1;
648         state->m_valueresponse = 0x36<<16;
625         m_puzzli_54_trigger = 1;
626         m_valueresponse = 0x36<<16;
649627      break;
650628
651629      case 0x61: // ??
652         state->m_valueresponse = 0x36<<16;
630         m_valueresponse = 0x36<<16;
653631      break;
654632
655633      case 0x63: // used as a read address by the 68k code (related to previous uploaded values like cave?) should point at a table of ~0x80 in size? seems to use values as further pointers?
656         state->m_valueresponse = 0x00600000;
634         m_valueresponse = 0x00600000;
657635      break;
658636
659637      case 0x67: // used as a read address by the 68k code (related to previous uploaded values like cave?) directly reads ~0xDBE from the address..
660         state->m_valueresponse = 0x00400000;
638         m_valueresponse = 0x00400000;
661639      break;
662640
663641      default:
664         state->m_valueresponse = 0x74<<16;
642         m_valueresponse = 0x74<<16;
665643      break;
666644   }
667645}
668646
669647/* preliminary */
670void command_handler_py2k2(pgm_arm_type1_state *state, int pc)
648void pgm_arm_type1_state::command_handler_py2k2(int pc)
671649{
672   switch (state->m_ddp3lastcommand)
650   switch (m_ddp3lastcommand)
673651   {
674652      default:
675         printf("%06x command %02x | %04x\n", pc, state->m_ddp3lastcommand, state->m_value0);
676         state->m_valueresponse = 0x880000;
653         printf("%06x command %02x | %04x\n", pc, m_ddp3lastcommand, m_value0);
654         m_valueresponse = 0x880000;
677655         break;
678656
679657      case 0xc0:
680         printf("%06x command %02x | %04x\n", pc, state->m_ddp3lastcommand, state->m_value0);
681         state->m_valueresponse = 0x880000;
658         printf("%06x command %02x | %04x\n", pc, m_ddp3lastcommand, m_value0);
659         m_valueresponse = 0x880000;
682660         break;
683661
684662      case 0xcb: // Background layer 'x' select (pgm3in1, same as kov)
685         state->m_valueresponse = 0x880000;
686         state->m_kov_cb_value = state->m_value0;
663         m_valueresponse = 0x880000;
664         m_kov_cb_value = m_value0;
687665      break;
688666
689667      case 0xcc: // Background layer offset (pgm3in1, same as kov)
690668      {
691         int y = state->m_value0;
669         int y = m_value0;
692670         if (y & 0x400) y = -(0x400 - (y & 0x3ff));
693         state->m_valueresponse = 0x900000 + ((state->m_kov_cb_value + (y * 0x40)) * 4);
671         m_valueresponse = 0x900000 + ((m_kov_cb_value + (y * 0x40)) * 4);
694672      }
695673      break;
696674
697675      case 0x99: // reset?
698         state->m_valuekey = 0x100;
699         state->m_valueresponse = 0x00880000;
676         m_valuekey = 0x100;
677         m_valueresponse = 0x00880000;
700678         break;
701679   }
702680}
r21060r21061
799777   0x00,0x00,0x00
800778};
801779
802void command_handler_pstars(pgm_arm_type1_state *state, int pc)
780void pgm_arm_type1_state::command_handler_pstars(int pc)
803781{
804   switch (state->m_ddp3lastcommand)
782   switch (m_ddp3lastcommand)
805783   {
806784      case 0x99:
807         state->m_valuekey = 0x100;
808         state->m_valueresponse = 0x880000;
785         m_valuekey = 0x100;
786         m_valueresponse = 0x880000;
809787         break;
810788
811789      case 0xe0:
812         state->m_valueresponse = 0xa00000 + (state->m_value0 << 6);
790         m_valueresponse = 0xa00000 + (m_value0 << 6);
813791         break;
814792
815793      case 0xdc:
816         state->m_valueresponse = 0xa00800 + (state->m_value0 << 6);
794         m_valueresponse = 0xa00800 + (m_value0 << 6);
817795         break;
818796
819797      case 0xd0:
820         state->m_valueresponse = 0xa01000 + (state->m_value0 << 5);
798         m_valueresponse = 0xa01000 + (m_value0 << 5);
821799         break;
822800
823801      case 0xb1:
824         state->m_pstar_b1_value = state->m_value0;
825         state->m_valueresponse = 0x890000;
802         m_pstar_b1_value = m_value0;
803         m_valueresponse = 0x890000;
826804         break;
827805
828806      case 0xbf:
829         state->m_valueresponse = state->m_pstar_b1_value * state->m_value0;
807         m_valueresponse = m_pstar_b1_value * m_value0;
830808         break;
831809
832810      case 0xc1: //TODO:TIMER  0,1,2,FIX TO 0 should be OK?
833         state->m_valueresponse = 0;
811         m_valueresponse = 0;
834812         break;
835813
836814      case 0xce: //TODO:TIMER  0,1,2
837         state->m_pstar_ce_value = state->m_value0;
838         state->m_valueresponse=0x890000;
815         m_pstar_ce_value = m_value0;
816         m_valueresponse=0x890000;
839817         break;
840818
841819      case 0xcf: //TODO:TIMER  0,1,2
842         state->m_extra_ram[state->m_pstar_ce_value] = state->m_value0;
843         state->m_valueresponse = 0x890000;
820         m_extra_ram[m_pstar_ce_value] = m_value0;
821         m_valueresponse = 0x890000;
844822         break;
845823
846824      case 0xe7:
847         state->m_pstar_e7_value = (state->m_value0 >> 12) & 0xf;
848         state->m_slots[state->m_pstar_e7_value] &= 0xffff;
849         state->m_slots[state->m_pstar_e7_value] |= (state->m_value0 & 0xff) << 16;
850         state->m_valueresponse = 0x890000;
825         m_pstar_e7_value = (m_value0 >> 12) & 0xf;
826         m_slots[m_pstar_e7_value] &= 0xffff;
827         m_slots[m_pstar_e7_value] |= (m_value0 & 0xff) << 16;
828         m_valueresponse = 0x890000;
851829         break;
852830
853831      case 0xe5:
854         state->m_slots[state->m_pstar_e7_value] &= 0xff0000;
855         state->m_slots[state->m_pstar_e7_value] |= state->m_value0;
856         state->m_valueresponse = 0x890000;
832         m_slots[m_pstar_e7_value] &= 0xff0000;
833         m_slots[m_pstar_e7_value] |= m_value0;
834         m_valueresponse = 0x890000;
857835         break;
858836
859837      case 0xf8: //@73C
860         state->m_valueresponse = state->m_slots[state->m_value0 & 0xf] & 0xffffff;
838         m_valueresponse = m_slots[m_value0 & 0xf] & 0xffffff;
861839         break;
862840
863841      case 0xba:
864         state->m_valueresponse = pstar_ba[state->m_value0];
842         m_valueresponse = pstar_ba[m_value0];
865843         break;
866844
867845      case 0xb0:
868         state->m_valueresponse = pstar_b0[state->m_value0];
846         m_valueresponse = pstar_b0[m_value0];
869847         break;
870848
871849      case 0xae:
872         state->m_valueresponse = pstar_ae[state->m_value0];
850         m_valueresponse = pstar_ae[m_value0];
873851         break;
874852
875853      case 0xa0:
876         state->m_valueresponse = pstar_a0[state->m_value0];
854         m_valueresponse = pstar_a0[m_value0];
877855         break;
878856
879857      case 0x9d:
880         state->m_valueresponse = pstar_9d[state->m_value0];
858         m_valueresponse = pstar_9d[m_value0];
881859         break;
882860
883861      case 0x90:
884         state->m_valueresponse = pstar_90[state->m_value0];
862         m_valueresponse = pstar_90[m_value0];
885863         break;
886864
887865      case 0x8c:
888         state->m_valueresponse = pstar_8c[state->m_value0];
866         m_valueresponse = pstar_8c[m_value0];
889867         break;
890868
891869      case 0x80:
892         state->m_valueresponse = pstar_80[state->m_value0];
870         m_valueresponse = pstar_80[m_value0];
893871         break;
894872
895873      default:
896         state->m_valueresponse = 0x890000;
897         logerror("PSTARS PC(%06x) UNKNOWN %4X %4X\n", pc, state->m_value1, state->m_value0);
874         m_valueresponse = 0x890000;
875         logerror("PSTARS PC(%06x) UNKNOWN %4X %4X\n", pc, m_value1, m_value0);
898876   }
899877}
900878
r21060r21061
909887static const UINT8 kov_B0TABLE[16] = { 2, 0, 1, 4, 3 }; // Maps char portraits to tables
910888
911889
912void command_handler_kov(pgm_arm_type1_state *state, int pc)
890void pgm_arm_type1_state::command_handler_kov(int pc)
913891{
914   switch (state->m_ddp3lastcommand)
892   switch (m_ddp3lastcommand)
915893   {
916894      case 0x67: // unknown or status check?
917895      case 0x8e:
r21060r21061
919897      case 0x33: // kovsgqyz (a3)
920898      case 0x3a: // kovplus
921899      case 0xc5: // kovplus
922         state->m_valueresponse = 0x880000;
900         m_valueresponse = 0x880000;
923901      break;
924902
925903      case 0x99: // Reset
926         state->m_valueresponse = 0x880000;
927         state->m_valuekey = 0x100;
904         m_valueresponse = 0x880000;
905         m_valuekey = 0x100;
928906      break;
929907
930908      case 0x9d: // Sprite palette offset
931         state->m_valueresponse = 0xa00000 + ((state->m_value0 & 0x1f) * 0x40);
909         m_valueresponse = 0xa00000 + ((m_value0 & 0x1f) * 0x40);
932910      break;
933911
934912      case 0xb0: // Read from data table
935         state->m_valueresponse = kov_B0TABLE[state->m_value0 & 0x0f];
913         m_valueresponse = kov_B0TABLE[m_value0 & 0x0f];
936914      break;
937915
938916      case 0xb4: // Copy slot 'a' to slot 'b'
939917      case 0xb7: // kovsgqyz (b4)
940918      {
941         state->m_valueresponse = 0x880000;
919         m_valueresponse = 0x880000;
942920
943         if (state->m_value0 == 0x0102) state->m_value0 = 0x0100; // why?
921         if (m_value0 == 0x0102) m_value0 = 0x0100; // why?
944922
945         state->m_slots[(state->m_value0 >> 8) & 0x0f] = state->m_slots[(state->m_value0 >> 0) & 0x0f];
923         m_slots[(m_value0 >> 8) & 0x0f] = m_slots[(m_value0 >> 0) & 0x0f];
946924      }
947925      break;
948926
949927      case 0xba: // Read from data table
950         state->m_valueresponse = kov_BATABLE[state->m_value0 & 0x3f];
928         m_valueresponse = kov_BATABLE[m_value0 & 0x3f];
951929      break;
952930
953931      case 0xc0: // Text layer 'x' select
954         state->m_valueresponse = 0x880000;
955         state->m_kov_c0_value = state->m_value0;
932         m_valueresponse = 0x880000;
933         m_kov_c0_value = m_value0;
956934      break;
957935
958936      case 0xc3: // Text layer offset
959         state->m_valueresponse = 0x904000 + ((state->m_kov_c0_value + (state->m_value0 * 0x40)) * 4);
937         m_valueresponse = 0x904000 + ((m_kov_c0_value + (m_value0 * 0x40)) * 4);
960938      break;
961939
962940      case 0xcb: // Background layer 'x' select
963         state->m_valueresponse = 0x880000;
964         state->m_kov_cb_value = state->m_value0;
941         m_valueresponse = 0x880000;
942         m_kov_cb_value = m_value0;
965943      break;
966944
967945      case 0xcc: // Background layer offset
968946      {
969         int y = state->m_value0;
947         int y = m_value0;
970948         if (y & 0x400) y = -(0x400 - (y & 0x3ff));
971         state->m_valueresponse = 0x900000 + ((state->m_kov_cb_value + (y * 0x40)) * 4);
949         m_valueresponse = 0x900000 + ((m_kov_cb_value + (y * 0x40)) * 4);
972950      }
973951      break;
974952
975953      case 0xd0: // Text palette offset
976954      case 0xcd: // kovsgqyz (d0)
977         state->m_valueresponse = 0xa01000 + (state->m_value0 * 0x20);
955         m_valueresponse = 0xa01000 + (m_value0 * 0x20);
978956      break;
979957
980958      case 0xd6: // Copy slot to slot 0
981         state->m_valueresponse = 0x880000;
982         state->m_slots[0] = state->m_slots[state->m_value0 & 0x0f];
959         m_valueresponse = 0x880000;
960         m_slots[0] = m_slots[m_value0 & 0x0f];
983961      break;
984962
985963      case 0xdc: // Background palette offset
986964      case 0x11: // kovsgqyz (dc)
987         state->m_valueresponse = 0xa00800 + (state->m_value0 * 0x40);
965         m_valueresponse = 0xa00800 + (m_value0 * 0x40);
988966      break;
989967
990968      case 0xe0: // Sprite palette offset
991969      case 0x9e: // kovsgqyz (e0)
992         state->m_valueresponse = 0xa00000 + ((state->m_value0 & 0x1f) * 0x40);
970         m_valueresponse = 0xa00000 + ((m_value0 & 0x1f) * 0x40);
993971      break;
994972
995973      case 0xe5: // Write slot (low)
996974      {
997         state->m_valueresponse = 0x880000;
975         m_valueresponse = 0x880000;
998976
999         INT32 sel = (state->m_curslots >> 12) & 0x0f;
1000         state->m_slots[sel] = (state->m_slots[sel] & 0x00ff0000) | ((state->m_value0 & 0xffff) <<  0);
977         INT32 sel = (m_curslots >> 12) & 0x0f;
978         m_slots[sel] = (m_slots[sel] & 0x00ff0000) | ((m_value0 & 0xffff) <<  0);
1001979      }
1002980      break;
1003981
1004982      case 0xe7: // Write slot (and slot select) (high)
1005983      {
1006         state->m_valueresponse = 0x880000;
1007         state->m_curslots = state->m_value0;
984         m_valueresponse = 0x880000;
985         m_curslots = m_value0;
1008986
1009         INT32 sel = (state->m_curslots >> 12) & 0x0f;
1010         state->m_slots[sel] = (state->m_slots[sel] & 0x0000ffff) | ((state->m_value0 & 0x00ff) << 16);
987         INT32 sel = (m_curslots >> 12) & 0x0f;
988         m_slots[sel] = (m_slots[sel] & 0x0000ffff) | ((m_value0 & 0x00ff) << 16);
1011989      }
1012990      break;
1013991
1014992      case 0xf0: // Some sort of status read?
1015         state->m_valueresponse = 0x00c000;
993         m_valueresponse = 0x00c000;
1016994      break;
1017995
1018996      case 0xf8: // Read slot
1019997      case 0xab: // kovsgqyz (f8)
1020         state->m_valueresponse = state->m_slots[state->m_value0 & 0x0f] & 0x00ffffff;
998         m_valueresponse = m_slots[m_value0 & 0x0f] & 0x00ffffff;
1021999      break;
10221000
10231001      case 0xfc: // Adjust damage level to char experience level
1024         state->m_valueresponse = (state->m_value0 * state->m_kov_fe_value) >> 6;
1002         m_valueresponse = (m_value0 * m_kov_fe_value) >> 6;
10251003      break;
10261004
10271005      case 0xfe: // Damage level adjust
1028         state->m_valueresponse = 0x880000;
1029         state->m_kov_fe_value = state->m_value0;
1006         m_valueresponse = 0x880000;
1007         m_kov_fe_value = m_value0;
10301008      break;
10311009
10321010      default:
1033         state->m_valueresponse = 0x880000;
1034//                  logerror("Unknown ASIC27 command: %2.2x data: %4.4x\n", (data ^ state->m_valuekey) & 0xff, state->m_value0);
1011         m_valueresponse = 0x880000;
1012//                  logerror("Unknown ASIC27 command: %2.2x data: %4.4x\n", (data ^ m_valuekey) & 0xff, m_value0);
10351013      break;
10361014   }
10371015}
r21060r21061
11921170};
11931171
11941172
1195void command_handler_oldsplus(pgm_arm_type1_state *state, int pc)
1173void pgm_arm_type1_state::command_handler_oldsplus(int pc)
11961174{
1197   switch (state->m_ddp3lastcommand)
1175   switch (m_ddp3lastcommand)
11981176   {
11991177      case 0x88:
1200         state->m_valuekey = 0x100;
1201         state->m_valueresponse = 0x990000;
1178         m_valuekey = 0x100;
1179         m_valueresponse = 0x990000;
12021180         break;
12031181
12041182      case 0xd0:
1205         state->m_valueresponse = 0xa01000 + (state->m_value0 << 5);
1183         m_valueresponse = 0xa01000 + (m_value0 << 5);
12061184         break;
12071185
12081186      case 0xc0:
1209         state->m_valueresponse = 0xa00000 + (state->m_value0 << 6);
1187         m_valueresponse = 0xa00000 + (m_value0 << 6);
12101188         break;
12111189
12121190      case 0xc3:
1213         state->m_valueresponse = 0xa00800 + (state->m_value0 << 6);
1191         m_valueresponse = 0xa00800 + (m_value0 << 6);
12141192         break;
12151193
12161194      case 0x36:
1217         state->m_extra_ram[0x36] = state->m_value0;
1218         state->m_valueresponse = 0x990000;
1195         m_extra_ram[0x36] = m_value0;
1196         m_valueresponse = 0x990000;
12191197         break;
12201198
12211199      case 0x33:
1222         state->m_extra_ram[0x33] = state->m_value0;
1223         state->m_valueresponse = 0x990000;
1200         m_extra_ram[0x33] = m_value0;
1201         m_valueresponse = 0x990000;
12241202         break;
12251203
12261204      case 0x35:
1227         state->m_extra_ram[0x36] += state->m_value0;
1228         state->m_valueresponse = 0x990000;
1205         m_extra_ram[0x36] += m_value0;
1206         m_valueresponse = 0x990000;
12291207         break;
12301208
12311209      case 0x37:
1232         state->m_extra_ram[0x33] += state->m_value0;
1233         state->m_valueresponse = 0x990000;
1210         m_extra_ram[0x33] += m_value0;
1211         m_valueresponse = 0x990000;
12341212         break;
12351213
12361214      case 0x34:
1237         state->m_valueresponse = state->m_extra_ram[0x36];
1215         m_valueresponse = m_extra_ram[0x36];
12381216         break;
12391217
12401218      case 0x38:
1241         state->m_valueresponse = state->m_extra_ram[0x33];
1219         m_valueresponse = m_extra_ram[0x33];
12421220         break;
12431221
12441222      case 0x80:
1245         state->m_valueresponse = oldsplus_80[state->m_value0];
1223         m_valueresponse = oldsplus_80[m_value0];
12461224         break;
12471225
12481226      case 0xe7:
1249         state->m_extra_ram[0xe7] = state->m_value0;
1250         state->m_valueresponse = 0x990000;
1227         m_extra_ram[0xe7] = m_value0;
1228         m_valueresponse = 0x990000;
12511229         break;
12521230
12531231      case 0xe5:
1254         switch (state->m_extra_ram[0xe7])
1232         switch (m_extra_ram[0xe7])
12551233         {
12561234            case 0xb000:
1257               state->m_slots[0xb] = state->m_value0;
1258               state->m_slots[0xc] = 0;
1235               m_slots[0xb] = m_value0;
1236               m_slots[0xc] = 0;
12591237               break;
12601238
12611239            case 0xc000:
1262               state->m_slots[0xc] = state->m_value0;
1240               m_slots[0xc] = m_value0;
12631241               break;
12641242
12651243            case 0xd000:
1266               state->m_slots[0xd] = state->m_value0;
1244               m_slots[0xd] = m_value0;
12671245               break;
12681246
12691247            case 0xf000:
1270               state->m_slots[0xf] = state->m_value0;
1248               m_slots[0xf] = m_value0;
12711249               break;
12721250         }
1273         state->m_valueresponse = 0x990000;
1251         m_valueresponse = 0x990000;
12741252         break;
12751253
12761254      case 0xf8:
1277         state->m_valueresponse = state->m_slots[state->m_value0];
1255         m_valueresponse = m_slots[m_value0];
12781256         break;
12791257
12801258      case 0xfc:
1281         state->m_valueresponse = oldsplus_fc[state->m_value0];
1259         m_valueresponse = oldsplus_fc[m_value0];
12821260         break;
12831261
12841262      case 0xc5:
1285         state->m_slots[0xd] --;
1286         state->m_valueresponse = 0x990000;
1263         m_slots[0xd] --;
1264         m_valueresponse = 0x990000;
12871265         break;
12881266
12891267      case 0xd6:
1290         state->m_slots[0xb] ++;
1291         state->m_valueresponse = 0x990000;
1268         m_slots[0xb] ++;
1269         m_valueresponse = 0x990000;
12921270         break;
12931271
12941272      case 0x3a:
1295         state->m_slots[0xf] = 0;
1296         state->m_valueresponse = 0x990000;
1273         m_slots[0xf] = 0;
1274         m_valueresponse = 0x990000;
12971275         break;
12981276
12991277      case 0xf0:
1300         state->m_extra_ram[0xf0] = state->m_value0;
1301         state->m_valueresponse = 0x990000;
1278         m_extra_ram[0xf0] = m_value0;
1279         m_valueresponse = 0x990000;
13021280         break;
13031281
13041282      case 0xed:
1305         state->m_valueresponse = state->m_value0 << 0x6;
1306         state->m_valueresponse += state->m_extra_ram[0xf0];
1307         state->m_valueresponse = state->m_valueresponse << 0x2;
1308         state->m_valueresponse += 0x900000;
1283         m_valueresponse = m_value0 << 0x6;
1284         m_valueresponse += m_extra_ram[0xf0];
1285         m_valueresponse = m_valueresponse << 0x2;
1286         m_valueresponse += 0x900000;
13091287         break;
13101288
13111289      case 0xe0:
1312         state->m_extra_ram[0xe0] = state->m_value0;
1313         state->m_valueresponse = 0x990000;
1290         m_extra_ram[0xe0] = m_value0;
1291         m_valueresponse = 0x990000;
13141292         break;
13151293
13161294      case 0xdc:
1317         state->m_valueresponse = state->m_value0 << 0x6;
1318         state->m_valueresponse += state->m_extra_ram[0xe0];
1319         state->m_valueresponse = state->m_valueresponse << 0x2;
1320         state->m_valueresponse += 0x904000;
1295         m_valueresponse = m_value0 << 0x6;
1296         m_valueresponse += m_extra_ram[0xe0];
1297         m_valueresponse = m_valueresponse << 0x2;
1298         m_valueresponse += 0x904000;
13211299         break;
13221300
13231301      case 0xcb:
1324         state->m_valueresponse =  0xc000;
1302         m_valueresponse =  0xc000;
13251303         break;
13261304
13271305      case 0xa0:
1328         state->m_valueresponse = oldsplus_a0[state->m_value0];
1306         m_valueresponse = oldsplus_a0[m_value0];
13291307         break;
13301308
13311309      case 0xba:
1332         state->m_valueresponse = oldsplus_ba[state->m_value0];
1310         m_valueresponse = oldsplus_ba[m_value0];
13331311         break;
13341312
13351313      case 0x5e:
1336         state->m_valueresponse = oldsplus_5e[state->m_value0];
1314         m_valueresponse = oldsplus_5e[m_value0];
13371315         break;
13381316
13391317      case 0xb0:
1340         state->m_valueresponse = oldsplus_b0[state->m_value0];
1318         m_valueresponse = oldsplus_b0[m_value0];
13411319         break;
13421320
13431321      case 0xae:
1344         state->m_valueresponse = oldsplus_ae[state->m_value0];
1322         m_valueresponse = oldsplus_ae[m_value0];
13451323         break;
13461324
13471325      case 0x9d:
1348         state->m_valueresponse = oldsplus_9d[state->m_value0];
1326         m_valueresponse = oldsplus_9d[m_value0];
13491327         break;
13501328
13511329      case 0x90:
1352         state->m_valueresponse = oldsplus_90[state->m_value0];
1330         m_valueresponse = oldsplus_90[m_value0];
13531331         break;
13541332
13551333      case 0x8c:
1356         state->m_valueresponse = oldsplus_8c[state->m_value0];
1334         m_valueresponse = oldsplus_8c[m_value0];
13571335         break;
13581336
13591337      default:
1360         state->m_valueresponse = 0x990000;
1361         printf("%06X: oldsplus_UNKNOWN W CMD %X  VAL %X\n", pc,state->m_value1,state->m_value0);
1338         m_valueresponse = 0x990000;
1339         printf("%06X: oldsplus_UNKNOWN W CMD %X  VAL %X\n", pc,m_value1,m_value0);
13621340         break;
13631341   }
13641342}
13651343
1366static WRITE16_HANDLER( pgm_arm7_type1_sim_w )
1367{
1368   pgm_arm_type1_state *state = space.machine().driver_data<pgm_arm_type1_state>();
1344WRITE16_MEMBER(pgm_arm_type1_state::pgm_arm7_type1_sim_w )
1345{   
13691346   int pc = space.device().safe_pc();
13701347
13711348   if (offset == 0)
13721349   {
1373      state->m_value0 = data;
1350      m_value0 = data;
13741351      return;
13751352   }
13761353   else if (offset == 1)
13771354   {
13781355      UINT16 realkey;
13791356      if ((data >> 8) == 0xff)
1380         state->m_valuekey = 0xff00;
1381      realkey = state->m_valuekey >> 8;
1382      realkey |= state->m_valuekey;
1357         m_valuekey = 0xff00;
1358      realkey = m_valuekey >> 8;
1359      realkey |= m_valuekey;
13831360      {
1384         state->m_valuekey += 0x0100;
1385         state->m_valuekey &= 0xff00;
1386         if (state->m_valuekey == 0xff00)
1387            state->m_valuekey =  0x0100;
1361         m_valuekey += 0x0100;
1362         m_valuekey &= 0xff00;
1363         if (m_valuekey == 0xff00)
1364            m_valuekey =  0x0100;
13881365      }
13891366      data ^= realkey;
1390      state->m_value1 = data;
1391      state->m_value0 ^= realkey;
1367      m_value1 = data;
1368      m_value0 ^= realkey;
13921369
1393      state->m_ddp3lastcommand = state->m_value1 & 0xff;
1370      m_ddp3lastcommand = m_value1 & 0xff;
13941371
1395      state->arm_sim_handler(state, pc);
1372      (this->*arm_sim_handler)(pc);
13961373   }
13971374   else if (offset==2)
13981375   {
13991376   }
14001377}
14011378
1402static READ16_HANDLER( pgm_arm7_type1_sim_protram_r )
1379READ16_MEMBER(pgm_arm_type1_state::pgm_arm7_type1_sim_protram_r )
14031380{
14041381   if (offset == 4)
1405      return space.machine().root_device().ioport("Region")->read();
1382      return ioport("Region")->read();
14061383
14071384   return 0x0000;
14081385}
14091386
1410static READ16_HANDLER( pstars_arm7_type1_sim_protram_r )
1387READ16_MEMBER(pgm_arm_type1_state::pstars_arm7_type1_sim_protram_r )
14111388{
1412   pgm_arm_type1_state *state = space.machine().driver_data<pgm_arm_type1_state>();
1413
14141389   if (offset == 4)        //region
1415      return state->ioport("Region")->read();
1390      return ioport("Region")->read();
14161391   else if (offset >= 0x10)  //timer
14171392   {
1418      logerror("PSTARS ACCESS COUNTER %6X\n", state->m_extra_ram[offset - 0x10]);
1419      return state->m_extra_ram[offset - 0x10]--;
1393      logerror("PSTARS ACCESS COUNTER %6X\n", m_extra_ram[offset - 0x10]);
1394      return m_extra_ram[offset - 0x10]--;
14201395   }
14211396   return 0x0000;
14221397}
r21060r21061
14241399
14251400DRIVER_INIT_MEMBER(pgm_arm_type1_state,ddp3)
14261401{
1427   pgm_basic_init(machine(), false);
1402   pgm_basic_init(false);
14281403   pgm_py2k2_decrypt(machine()); // yes, it's the same as photo y2k2
1429   arm_sim_handler = command_handler_ddp3;
1430   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x500000, 0x500005, FUNC(pgm_arm7_type1_sim_r), FUNC(pgm_arm7_type1_sim_w));
1404   arm_sim_handler = &pgm_arm_type1_state::command_handler_ddp3;
1405   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x500000, 0x500005, read16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_r),this), write16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_w),this));
14311406}
14321407
14331408DRIVER_INIT_MEMBER(pgm_arm_type1_state,ket)
14341409{
1435   pgm_basic_init(machine(), false);
1410   pgm_basic_init(false);
14361411   pgm_ket_decrypt(machine());
1437   arm_sim_handler = command_handler_ddp3;
1438   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x400000, 0x400005, FUNC(pgm_arm7_type1_sim_r), FUNC(pgm_arm7_type1_sim_w));
1412   arm_sim_handler = &pgm_arm_type1_state::command_handler_ddp3;
1413   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x400000, 0x400005, read16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_r),this), write16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_w),this));
14391414}
14401415
14411416DRIVER_INIT_MEMBER(pgm_arm_type1_state,espgal)
14421417{
1443   pgm_basic_init(machine(), false);
1418   pgm_basic_init(false);
14441419   pgm_espgal_decrypt(machine());
1445   arm_sim_handler = command_handler_ddp3;
1446   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x400000, 0x400005, FUNC(pgm_arm7_type1_sim_r), FUNC(pgm_arm7_type1_sim_w));
1420   arm_sim_handler = &pgm_arm_type1_state::command_handler_ddp3;
1421   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x400000, 0x400005, read16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_r),this), write16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_w),this));
14471422}
14481423
14491424DRIVER_INIT_MEMBER(pgm_arm_type1_state,puzzli2)
14501425{
1451   pgm_basic_init(machine());
1426   pgm_basic_init();
14521427   pgm_puzzli2_decrypt(machine());
1453   arm_sim_handler = command_handler_puzzli2;
1454   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x500000, 0x500005, FUNC(pgm_arm7_type1_sim_r), FUNC(pgm_arm7_type1_sim_w));
1455   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x4f0000, 0x4f003f, FUNC(pgm_arm7_type1_sim_protram_r));
1428   arm_sim_handler = &pgm_arm_type1_state::command_handler_puzzli2;
1429   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x500000, 0x500005, read16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_r),this), write16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_w),this));
1430   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x4f0000, 0x4f003f, read16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_protram_r),this));
14561431   m_irq4_disabled = 1; // // doesn't like this irq??
14571432}
14581433
14591434DRIVER_INIT_MEMBER(pgm_arm_type1_state,py2k2)
14601435{
1461   pgm_basic_init(machine());
1436   pgm_basic_init();
14621437   pgm_py2k2_decrypt(machine());
1463   arm_sim_handler = command_handler_py2k2;
1464   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x500000, 0x500005, FUNC(pgm_arm7_type1_sim_r), FUNC(pgm_arm7_type1_sim_w));
1465   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x4f0000, 0x4f003f, FUNC(pgm_arm7_type1_sim_protram_r));
1438   arm_sim_handler = &pgm_arm_type1_state::command_handler_py2k2;
1439   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x500000, 0x500005, read16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_r),this), write16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_w),this));
1440   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x4f0000, 0x4f003f, read16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_protram_r),this));
14661441}
14671442
14681443DRIVER_INIT_MEMBER(pgm_arm_type1_state,pgm3in1)
14691444{
1470   pgm_basic_init(machine());
1445   pgm_basic_init();
14711446   pgm_decrypt_pgm3in1(machine());
1472   arm_sim_handler = command_handler_py2k2;
1473   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x500000, 0x500005, FUNC(pgm_arm7_type1_sim_r), FUNC(pgm_arm7_type1_sim_w));
1474   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x4f0000, 0x4f003f, FUNC(pgm_arm7_type1_sim_protram_r));
1447   arm_sim_handler = &pgm_arm_type1_state::command_handler_py2k2;
1448   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x500000, 0x500005,read16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_r),this), write16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_w),this));
1449   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x4f0000, 0x4f003f, read16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_protram_r),this));
14751450   m_irq4_disabled = 1; // // doesn't like this irq??
14761451}
14771452
14781453DRIVER_INIT_MEMBER(pgm_arm_type1_state,pstar)
14791454{
1480   pgm_basic_init(machine());
1455   pgm_basic_init();
14811456   pgm_pstar_decrypt(machine());
1482   pgm_arm7_type1_latch_init(machine());
1457   pgm_arm7_type1_latch_init();
14831458
14841459   m_pstar_e7_value = 0;
14851460   m_pstar_b1_value = 0;
r21060r21061
14891464   m_extra_ram[2] = 0;
14901465   memset(m_slots, 0, 16 * sizeof(UINT32));
14911466
1492   arm_sim_handler = command_handler_pstars;
1493   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x500000, 0x500005, FUNC(pgm_arm7_type1_sim_r), FUNC(pgm_arm7_type1_sim_w));
1494   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x4f0000, 0x4f003f, FUNC(pstars_arm7_type1_sim_protram_r));
1467   arm_sim_handler = &pgm_arm_type1_state::command_handler_pstars;
1468   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x500000, 0x500005, read16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_r),this), write16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_w),this));
1469   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x4f0000, 0x4f003f, read16_delegate(FUNC(pgm_arm_type1_state::pstars_arm7_type1_sim_protram_r),this));
14951470
14961471   save_item(NAME(m_pstar_e7_value));
14971472   save_item(NAME(m_pstar_b1_value));
r21060r21061
15011476
15021477DRIVER_INIT_MEMBER(pgm_arm_type1_state,kov)
15031478{
1504   pgm_basic_init(machine());
1479   pgm_basic_init();
15051480   pgm_kov_decrypt(machine());
1506   pgm_arm7_type1_latch_init(machine());
1481   pgm_arm7_type1_latch_init();
15071482   m_curslots = 0;
15081483   m_kov_c0_value = 0;
15091484   m_kov_cb_value = 0;
15101485   m_kov_fe_value = 0;
1511   arm_sim_handler = command_handler_kov;
1512   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x500000, 0x500005, FUNC(pgm_arm7_type1_sim_r), FUNC(pgm_arm7_type1_sim_w));
1513   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x4f0000, 0x4f003f, FUNC(pgm_arm7_type1_sim_protram_r));
1486   arm_sim_handler = &pgm_arm_type1_state::command_handler_kov;
1487   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x500000, 0x500005, read16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_r),this), write16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_w),this));
1488   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x4f0000, 0x4f003f, read16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_protram_r),this));
15141489}
15151490
15161491DRIVER_INIT_MEMBER(pgm_arm_type1_state,kovboot)
15171492{
1518   pgm_basic_init(machine());
1493   pgm_basic_init();
15191494//  pgm_kov_decrypt(machine());
1520   pgm_arm7_type1_latch_init(machine());
1495   pgm_arm7_type1_latch_init();
15211496   m_curslots = 0;
15221497   m_kov_c0_value = 0;
15231498   m_kov_cb_value = 0;
15241499   m_kov_fe_value = 0;
1525   arm_sim_handler = command_handler_kov;
1526   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x500000, 0x500005, FUNC(pgm_arm7_type1_sim_r), FUNC(pgm_arm7_type1_sim_w));
1527   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x4f0000, 0x4f003f, FUNC(pgm_arm7_type1_sim_protram_r));
1500   arm_sim_handler = &pgm_arm_type1_state::command_handler_kov;
1501   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x500000, 0x500005, read16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_r),this), write16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_w),this));
1502   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x4f0000, 0x4f003f, read16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_protram_r),this));
15281503
15291504}
15301505
15311506DRIVER_INIT_MEMBER(pgm_arm_type1_state,oldsplus)
15321507{
1533   pgm_basic_init(machine());
1508   pgm_basic_init();
15341509   pgm_oldsplus_decrypt(machine());
1535   pgm_arm7_type1_latch_init(machine());
1510   pgm_arm7_type1_latch_init();
15361511   memset(m_extra_ram, 0, 0x100 * sizeof(UINT16));
15371512   memset(m_slots, 0, 0x100 * sizeof(UINT32));
1538   arm_sim_handler = command_handler_oldsplus;
1539   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x500000, 0x500005, FUNC(pgm_arm7_type1_sim_r), FUNC(pgm_arm7_type1_sim_w));
1540   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x4f0000, 0x4f003f, FUNC(pgm_arm7_type1_sim_protram_r));
1513   arm_sim_handler = &pgm_arm_type1_state::command_handler_oldsplus;
1514   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x500000, 0x500005, read16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_r),this), write16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_w),this));
1515   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x4f0000, 0x4f003f, read16_delegate(FUNC(pgm_arm_type1_state::pgm_arm7_type1_sim_protram_r),this));
15411516   state_save_register_global_array(machine(), m_extra_ram);
15421517   state_save_register_global_array(machine(), m_slots);
15431518}
trunk/src/mame/machine/pgmprot2.c
r21060r21061
3333#include "includes/pgm.h"
3434
3535
36static READ32_HANDLER( arm7_latch_arm_r )
36READ32_MEMBER(pgm_arm_type2_state::arm7_latch_arm_r )
3737{
38   pgm_arm_type2_state *state = space.machine().driver_data<pgm_arm_type2_state>();
38   m_prot->set_input_line(ARM7_FIRQ_LINE, CLEAR_LINE ); // guess
3939
40   state->m_prot->set_input_line(ARM7_FIRQ_LINE, CLEAR_LINE ); // guess
41
4240   if (PGMARM7LOGERROR)
43      logerror("ARM7: Latch read: %08x (%08x) (%06x)\n", state->m_kov2_latchdata_68k_w, mem_mask, space.device().safe_pc());
44   return state->m_kov2_latchdata_68k_w;
41      logerror("ARM7: Latch read: %08x (%08x) (%06x)\n", m_kov2_latchdata_68k_w, mem_mask, space.device().safe_pc());
42   return m_kov2_latchdata_68k_w;
4543}
4644
47static WRITE32_HANDLER( arm7_latch_arm_w )
45WRITE32_MEMBER(pgm_arm_type2_state::arm7_latch_arm_w )
4846{
49   pgm_arm_type2_state *state = space.machine().driver_data<pgm_arm_type2_state>();
50
5147   if (PGMARM7LOGERROR)
5248      logerror("ARM7: Latch write: %08x (%08x) (%06x)\n", data, mem_mask, space.device().safe_pc());
5349
54   COMBINE_DATA(&state->m_kov2_latchdata_arm_w);
50   COMBINE_DATA(&m_kov2_latchdata_arm_w);
5551}
5652
57static READ32_HANDLER( arm7_shareram_r )
53READ32_MEMBER(pgm_arm_type2_state::arm7_shareram_r )
5854{
59   pgm_arm_type2_state *state = space.machine().driver_data<pgm_arm_type2_state>();
60
6155   if (PGMARM7LOGERROR)
62      logerror("ARM7: ARM7 Shared RAM Read: %04x = %08x (%08x) (%06x)\n", offset << 2, state->m_arm7_shareram[offset], mem_mask, space.device().safe_pc());
63   return state->m_arm7_shareram[offset];
56      logerror("ARM7: ARM7 Shared RAM Read: %04x = %08x (%08x) (%06x)\n", offset << 2, m_arm7_shareram[offset], mem_mask, space.device().safe_pc());
57   return m_arm7_shareram[offset];
6458}
6559
66static WRITE32_HANDLER( arm7_shareram_w )
60WRITE32_MEMBER(pgm_arm_type2_state::arm7_shareram_w )
6761{
68   pgm_arm_type2_state *state = space.machine().driver_data<pgm_arm_type2_state>();
69
7062   if (PGMARM7LOGERROR)
7163      logerror("ARM7: ARM7 Shared RAM Write: %04x = %08x (%08x) (%06x)\n", offset << 2, data, mem_mask, space.device().safe_pc());
72   COMBINE_DATA(&state->m_arm7_shareram[offset]);
64   COMBINE_DATA(&m_arm7_shareram[offset]);
7365}
7466
75static READ16_HANDLER( arm7_latch_68k_r )
67READ16_MEMBER(pgm_arm_type2_state::arm7_latch_68k_r )
7668{
77   pgm_arm_type2_state *state = space.machine().driver_data<pgm_arm_type2_state>();
78
7969   if (PGMARM7LOGERROR)
80      logerror("M68K: Latch read: %04x (%04x) (%06x)\n", state->m_kov2_latchdata_arm_w & 0x0000ffff, mem_mask, space.device().safe_pc());
81   return state->m_kov2_latchdata_arm_w;
70      logerror("M68K: Latch read: %04x (%04x) (%06x)\n", m_kov2_latchdata_arm_w & 0x0000ffff, mem_mask, space.device().safe_pc());
71   return m_kov2_latchdata_arm_w;
8272}
8373
84static WRITE16_HANDLER( arm7_latch_68k_w )
74WRITE16_MEMBER(pgm_arm_type2_state::arm7_latch_68k_w )
8575{
86   pgm_arm_type2_state *state = space.machine().driver_data<pgm_arm_type2_state>();
87
8876   if (PGMARM7LOGERROR)
8977      logerror("M68K: Latch write: %04x (%04x) (%06x)\n", data & 0x0000ffff, mem_mask, space.device().safe_pc());
90   COMBINE_DATA(&state->m_kov2_latchdata_68k_w);
78   COMBINE_DATA(&m_kov2_latchdata_68k_w);
9179
92   state->m_prot->set_input_line(ARM7_FIRQ_LINE, ASSERT_LINE ); // guess
80   m_prot->set_input_line(ARM7_FIRQ_LINE, ASSERT_LINE ); // guess
9381}
9482
95static READ16_HANDLER( arm7_ram_r )
83READ16_MEMBER(pgm_arm_type2_state::arm7_ram_r )
9684{
97   pgm_arm_type2_state *state = space.machine().driver_data<pgm_arm_type2_state>();
98   UINT16 *share16 = reinterpret_cast<UINT16 *>(state->m_arm7_shareram.target());
85   UINT16 *share16 = reinterpret_cast<UINT16 *>(m_arm7_shareram.target());
9986
10087   if (PGMARM7LOGERROR)
10188      logerror("M68K: ARM7 Shared RAM Read: %04x = %04x (%08x) (%06x)\n", BYTE_XOR_LE(offset), share16[BYTE_XOR_LE(offset)], mem_mask, space.device().safe_pc());
10289   return share16[BYTE_XOR_LE(offset)];
10390}
10491
105static WRITE16_HANDLER( arm7_ram_w )
92WRITE16_MEMBER(pgm_arm_type2_state::arm7_ram_w )
10693{
107   pgm_arm_type2_state *state = space.machine().driver_data<pgm_arm_type2_state>();
108   UINT16 *share16 = reinterpret_cast<UINT16 *>(state->m_arm7_shareram.target());
94   UINT16 *share16 = reinterpret_cast<UINT16 *>(m_arm7_shareram.target());
10995
11096   if (PGMARM7LOGERROR)
11197      logerror("M68K: ARM7 Shared RAM Write: %04x = %04x (%04x) (%06x)\n", BYTE_XOR_LE(offset), data, mem_mask, space.device().safe_pc());
r21060r21061
118104static ADDRESS_MAP_START( kov2_mem, AS_PROGRAM, 16, pgm_arm_type2_state )
119105   AM_IMPORT_FROM(pgm_mem)
120106   AM_RANGE(0x100000, 0x5fffff) AM_ROMBANK("bank1") /* Game ROM */
121   AM_RANGE(0xd00000, 0xd0ffff) AM_READWRITE_LEGACY(arm7_ram_r, arm7_ram_w) /* ARM7 Shared RAM */
122   AM_RANGE(0xd10000, 0xd10001) AM_READWRITE_LEGACY(arm7_latch_68k_r, arm7_latch_68k_w) /* ARM7 Latch */
107   AM_RANGE(0xd00000, 0xd0ffff) AM_READWRITE(arm7_ram_r, arm7_ram_w) /* ARM7 Shared RAM */
108   AM_RANGE(0xd10000, 0xd10001) AM_READWRITE(arm7_latch_68k_r, arm7_latch_68k_w) /* ARM7 Latch */
123109ADDRESS_MAP_END
124110
125111
r21060r21061
128114   AM_RANGE(0x08000000, 0x083fffff) AM_ROM AM_REGION("user1", 0)
129115   AM_RANGE(0x10000000, 0x100003ff) AM_RAM
130116   AM_RANGE(0x18000000, 0x1800ffff) AM_RAM AM_SHARE("arm_ram")
131   AM_RANGE(0x38000000, 0x38000003) AM_READWRITE_LEGACY(arm7_latch_arm_r, arm7_latch_arm_w) /* 68k Latch */
132   AM_RANGE(0x48000000, 0x4800ffff) AM_READWRITE_LEGACY(arm7_shareram_r, arm7_shareram_w) AM_SHARE("arm7_shareram")
117   AM_RANGE(0x38000000, 0x38000003) AM_READWRITE(arm7_latch_arm_r, arm7_latch_arm_w) /* 68k Latch */
118   AM_RANGE(0x48000000, 0x4800ffff) AM_READWRITE(arm7_shareram_r, arm7_shareram_w) AM_SHARE("arm7_shareram")
133119   AM_RANGE(0x50000000, 0x500003ff) AM_RAM
134120ADDRESS_MAP_END
135121
r21060r21061
161147
162148
163149
164static void kov2_latch_init( running_machine &machine )
150void pgm_arm_type2_state::kov2_latch_init()
165151{
166   pgm_arm_type2_state *state = machine.driver_data<pgm_arm_type2_state>();
152   m_kov2_latchdata_68k_w = 0;
153   m_kov2_latchdata_arm_w = 0;
167154
168   state->m_kov2_latchdata_68k_w = 0;
169   state->m_kov2_latchdata_arm_w = 0;
170
171   state->save_item(NAME(state->m_kov2_latchdata_68k_w));
172   state->save_item(NAME(state->m_kov2_latchdata_arm_w));
155   save_item(NAME(m_kov2_latchdata_68k_w));
156   save_item(NAME(m_kov2_latchdata_arm_w));
173157}
174158
175static WRITE32_HANDLER( kov2_arm_region_w )
159WRITE32_MEMBER(pgm_arm_type2_state::kov2_arm_region_w )
176160{
177   pgm_arm_type2_state *state = space.machine().driver_data<pgm_arm_type2_state>();
178161   int pc = space.device().safe_pc();
179   int regionhack = state->ioport("RegionHack")->read();
162   int regionhack = ioport("RegionHack")->read();
180163   if (pc==0x190 && regionhack != 0xff) data = (data & 0xffff0000) | (regionhack << 0);
181   COMBINE_DATA(&state->m_arm7_shareram[0x138/4]);
164   COMBINE_DATA(&m_arm7_shareram[0x138/4]);
182165}
183166
184167DRIVER_INIT_MEMBER(pgm_arm_type2_state,kov2)
185168{
186   pgm_basic_init(machine());
169   pgm_basic_init();
187170   pgm_kov2_decrypt(machine());
188   kov2_latch_init(machine());
171   kov2_latch_init();
189172
190173   // we only have a HK internal ROM dumped for now, allow us to override that for debugging purposes.
191   machine().device("prot")->memory().space(AS_PROGRAM).install_legacy_write_handler(0x48000138, 0x4800013b, FUNC(kov2_arm_region_w));
174   machine().device("prot")->memory().space(AS_PROGRAM).install_write_handler(0x48000138, 0x4800013b, write32_delegate(FUNC(pgm_arm_type2_state::kov2_arm_region_w),this));
192175}
193176
194177
r21060r21061
197180   // this hacks the identification of the kov2 rom to return the string required for kov2p
198181   // this isn't guaranteed to work properly (and definitely wouldn't on real hardware due to the internal
199182   // ROM uploading the encryption table)  The internal ROM should be dumped properly.
200   pgm_basic_init(machine());
183   pgm_basic_init();
201184   pgm_kov2p_decrypt(machine());
202   kov2_latch_init(machine());
185   kov2_latch_init();
203186
204   UINT8 *mem8 = (UINT8 *)machine().root_device().memregion("user1")->base();
187   UINT8 *mem8 = (UINT8 *)memregion("user1")->base();
205188   mem8[0xDE] = 0xC0;
206189   mem8[0xDF] = 0x46;
207190   mem8[0x4ED8] = 0xA8;// B0
r21060r21061
222205   mem8[0x1FFFFD] = 0x99;
223206
224207   // we only have a HK internal ROM dumped for now, allow us to override that for debugging purposes.
225   machine().device("prot")->memory().space(AS_PROGRAM).install_legacy_write_handler(0x48000138, 0x4800013b, FUNC(kov2_arm_region_w));
208   machine().device("prot")->memory().space(AS_PROGRAM).install_write_handler(0x48000138, 0x4800013b, write32_delegate(FUNC(pgm_arm_type2_state::kov2_arm_region_w),this));
226209}
227210
228static WRITE32_HANDLER( martmast_arm_region_w )
211WRITE32_MEMBER(pgm_arm_type2_state::martmast_arm_region_w )
229212{
230   pgm_arm_type2_state *state = space.machine().driver_data<pgm_arm_type2_state>();
231213   int pc = space.device().safe_pc();
232   int regionhack = state->ioport("RegionHack")->read();
214   int regionhack = ioport("RegionHack")->read();
233215   if (pc==0x170 && regionhack != 0xff) data = (data & 0xffff0000) | (regionhack << 0);
234   COMBINE_DATA(&state->m_arm7_shareram[0x138/4]);
216   COMBINE_DATA(&m_arm7_shareram[0x138/4]);
235217}
236218
237219
238220DRIVER_INIT_MEMBER(pgm_arm_type2_state,martmast)
239221{
240   pgm_basic_init(machine());
222   pgm_basic_init();
241223   pgm_mm_decrypt(machine());
242   kov2_latch_init(machine());
224   kov2_latch_init();
243225
244226   // we only have a USA / CHINA internal ROMs dumped for now, allow us to override that for debugging purposes.
245   machine().device("prot")->memory().space(AS_PROGRAM).install_legacy_write_handler(0x48000138, 0x4800013b, FUNC(martmast_arm_region_w));
227   machine().device("prot")->memory().space(AS_PROGRAM).install_write_handler(0x48000138, 0x4800013b, write32_delegate(FUNC(pgm_arm_type2_state::martmast_arm_region_w),this));
246228}
247229
248230
249static WRITE32_HANDLER( ddp2_arm_region_w )
231WRITE32_MEMBER(pgm_arm_type2_state::ddp2_arm_region_w )
250232{
251   pgm_arm_type2_state *state = space.machine().driver_data<pgm_arm_type2_state>();
252233   int pc = space.device().safe_pc();
253   int regionhack = state->ioport("RegionHack")->read();
234   int regionhack = ioport("RegionHack")->read();
254235   if (pc==0x0174 && regionhack != 0xff) data = (data & 0x0000ffff) | (regionhack << 16);
255   COMBINE_DATA(&state->m_arm7_shareram[0x0]);
236   COMBINE_DATA(&m_arm7_shareram[0x0]);
256237}
257238
258static READ32_HANDLER( ddp2_speedup_r )
239READ32_MEMBER(pgm_arm_type2_state::ddp2_speedup_r )
259240{
260   pgm_arm_type2_state *state = space.machine().driver_data<pgm_arm_type2_state>();
261241   int pc = space.device().safe_pc();
262   UINT32 data = state->m_arm_ram[0x300c/4];
242   UINT32 data = m_arm_ram[0x300c/4];
263243
264244   if (pc==0x080109b4)
265245   {
r21060r21061
269249
270250      if (r4==0x18002f9e)
271251      {
272         UINT32 data2 =  state->m_arm_ram[0x2F9C/4]&0xffff0000;
252         UINT32 data2 =  m_arm_ram[0x2F9C/4]&0xffff0000;
273253         if ((data==0x00000000) && (data2==0x00000000)) space.device().execute().spin_until_interrupt();
274254      }
275255   }
r21060r21061
277257   return data;
278258}
279259
280static READ16_HANDLER( ddp2_main_speedup_r )
260READ16_MEMBER(pgm_arm_type2_state::ddp2_main_speedup_r )
281261{
282   pgm_state *state = space.machine().driver_data<pgm_state>();
283   UINT16 data = state->m_mainram[0x0ee54/2];
262   UINT16 data = m_mainram[0x0ee54/2];
284263   int pc = space.device().safe_pc();
285264
286265   if (pc == 0x149dce) space.device().execute().spin_until_interrupt();
r21060r21061
292271
293272DRIVER_INIT_MEMBER(pgm_arm_type2_state,ddp2)
294273{
295   pgm_basic_init(machine());
274   pgm_basic_init();
296275   pgm_ddp2_decrypt(machine());
297   kov2_latch_init(machine());
276   kov2_latch_init();
298277
299278   // we only have a Japan internal ROM dumped for now, allow us to override that for debugging purposes.
300   machine().device("prot")->memory().space(AS_PROGRAM).install_legacy_write_handler(0x48000000, 0x48000003, FUNC(ddp2_arm_region_w));
279   machine().device("prot")->memory().space(AS_PROGRAM).install_write_handler(0x48000000, 0x48000003, write32_delegate(FUNC(pgm_arm_type2_state::ddp2_arm_region_w),this));
301280
302   machine().device("prot")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x1800300c, 0x1800300f, FUNC(ddp2_speedup_r));
303   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x80ee54, 0x80ee55, FUNC(ddp2_main_speedup_r));
281   machine().device("prot")->memory().space(AS_PROGRAM).install_read_handler(0x1800300c, 0x1800300f, read32_delegate(FUNC(pgm_arm_type2_state::ddp2_speedup_r),this));
282   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x80ee54, 0x80ee55, read16_delegate(FUNC(pgm_arm_type2_state::ddp2_main_speedup_r),this));
304283}
305284
306285
307286DRIVER_INIT_MEMBER(pgm_arm_type2_state,dw2001)
308287{
309   pgm_basic_init(machine());
310   kov2_latch_init(machine());
288   pgm_basic_init();
289   kov2_latch_init();
311290   pgm_mm_decrypt(machine()); // encryption is the same as martial masters
312291}
313292
314293DRIVER_INIT_MEMBER(pgm_arm_type2_state,dwpc)
315294{
316   pgm_basic_init(machine());
317   kov2_latch_init(machine());
295   pgm_basic_init();
296   kov2_latch_init();
318297   pgm_mm_decrypt(machine()); // encryption is the same as martial masters
319298}
320299
trunk/src/mame/machine/pgmprot.c
r21060r21061
1515
1616/*** ASIC 3 (oriental legends protection) ****************************************/
1717
18static void asic3_compute_hold(running_machine &machine)
18void pgm_asic3_state::asic3_compute_hold()
1919{
20   pgm_asic3_state *state = machine.driver_data<pgm_asic3_state>();
21
2220   // The mode is dependent on the region
2321   static const int modes[4] = { 1, 1, 3, 2 };
24   int mode = modes[machine.root_device().ioport("Region")->read() & 3];
22   int mode = modes[ioport("Region")->read() & 3];
2523
2624   switch (mode)
2725   {
2826   case 1:
29      state->m_asic3_hold =
30         (state->m_asic3_hold << 1)
27      m_asic3_hold =
28         (m_asic3_hold << 1)
3129            ^ 0x2bad
32            ^ BIT(state->m_asic3_hold, 15) ^ BIT(state->m_asic3_hold, 10) ^ BIT(state->m_asic3_hold, 8) ^ BIT(state->m_asic3_hold, 5)
33            ^ BIT(state->m_asic3_z, state->m_asic3_y)
34            ^ (BIT(state->m_asic3_x, 0) << 1) ^ (BIT(state->m_asic3_x, 1) << 6) ^ (BIT(state->m_asic3_x, 2) << 10) ^ (BIT(state->m_asic3_x, 3) << 14);
30            ^ BIT(m_asic3_hold, 15) ^ BIT(m_asic3_hold, 10) ^ BIT(m_asic3_hold, 8) ^ BIT(m_asic3_hold, 5)
31            ^ BIT(m_asic3_z, m_asic3_y)
32            ^ (BIT(m_asic3_x, 0) << 1) ^ (BIT(m_asic3_x, 1) << 6) ^ (BIT(m_asic3_x, 2) << 10) ^ (BIT(m_asic3_x, 3) << 14);
3533      break;
3634   case 2:
37      state->m_asic3_hold =
38         (state->m_asic3_hold << 1)
35      m_asic3_hold =
36         (m_asic3_hold << 1)
3937            ^ 0x2bad
40            ^ BIT(state->m_asic3_hold, 15) ^ BIT(state->m_asic3_hold, 7) ^ BIT(state->m_asic3_hold, 6) ^ BIT(state->m_asic3_hold, 5)
41            ^ BIT(state->m_asic3_z, state->m_asic3_y)
42            ^ (BIT(state->m_asic3_x, 0) << 4) ^ (BIT(state->m_asic3_x, 1) << 6) ^ (BIT(state->m_asic3_x, 2) << 10) ^ (BIT(state->m_asic3_x, 3) << 12);
38            ^ BIT(m_asic3_hold, 15) ^ BIT(m_asic3_hold, 7) ^ BIT(m_asic3_hold, 6) ^ BIT(m_asic3_hold, 5)
39            ^ BIT(m_asic3_z, m_asic3_y)
40            ^ (BIT(m_asic3_x, 0) << 4) ^ (BIT(m_asic3_x, 1) << 6) ^ (BIT(m_asic3_x, 2) << 10) ^ (BIT(m_asic3_x, 3) << 12);
4341      break;
4442   case 3:
45      state->m_asic3_hold =
46         (state->m_asic3_hold << 1)
43      m_asic3_hold =
44         (m_asic3_hold << 1)
4745            ^ 0x2bad
48            ^ BIT(state->m_asic3_hold, 15) ^ BIT(state->m_asic3_hold, 10) ^ BIT(state->m_asic3_hold, 8) ^ BIT(state->m_asic3_hold, 5)
49            ^ BIT(state->m_asic3_z, state->m_asic3_y)
50            ^ (BIT(state->m_asic3_x, 0) << 4) ^ (BIT(state->m_asic3_x, 1) << 6) ^ (BIT(state->m_asic3_x, 2) << 10) ^ (BIT(state->m_asic3_x, 3) << 12);
46            ^ BIT(m_asic3_hold, 15) ^ BIT(m_asic3_hold, 10) ^ BIT(m_asic3_hold, 8) ^ BIT(m_asic3_hold, 5)
47            ^ BIT(m_asic3_z, m_asic3_y)
48            ^ (BIT(m_asic3_x, 0) << 4) ^ (BIT(m_asic3_x, 1) << 6) ^ (BIT(m_asic3_x, 2) << 10) ^ (BIT(m_asic3_x, 3) << 12);
5149      break;
5250   }
5351}
5452
55READ16_HANDLER( pgm_asic3_r )
53READ16_MEMBER(pgm_asic3_state::pgm_asic3_r )
5654{
57   pgm_asic3_state *state = space.machine().driver_data<pgm_asic3_state>();
5855   UINT8 res = 0;
5956   /* region is supplied by the protection device */
6057
61   switch (state->m_asic3_reg)
58   switch (m_asic3_reg)
6259   {
63   case 0x00: res = (state->m_asic3_latch[0] & 0xf7) | ((state->ioport("Region")->read() << 3) & 0x08); break;
64   case 0x01: res = state->m_asic3_latch[1]; break;
65   case 0x02: res = (state->m_asic3_latch[2] & 0x7f) | ((state->ioport("Region")->read() << 6) & 0x80); break;
60   case 0x00: res = (m_asic3_latch[0] & 0xf7) | ((ioport("Region")->read() << 3) & 0x08); break;
61   case 0x01: res = m_asic3_latch[1]; break;
62   case 0x02: res = (m_asic3_latch[2] & 0x7f) | ((ioport("Region")->read() << 6) & 0x80); break;
6663   case 0x03:
67      res = (BIT(state->m_asic3_hold, 15) << 0)
68         | (BIT(state->m_asic3_hold, 12) << 1)
69         | (BIT(state->m_asic3_hold, 13) << 2)
70         | (BIT(state->m_asic3_hold, 10) << 3)
71         | (BIT(state->m_asic3_hold, 7) << 4)
72         | (BIT(state->m_asic3_hold, 9) << 5)
73         | (BIT(state->m_asic3_hold, 2) << 6)
74         | (BIT(state->m_asic3_hold, 5) << 7);
64      res = (BIT(m_asic3_hold, 15) << 0)
65         | (BIT(m_asic3_hold, 12) << 1)
66         | (BIT(m_asic3_hold, 13) << 2)
67         | (BIT(m_asic3_hold, 10) << 3)
68         | (BIT(m_asic3_hold, 7) << 4)
69         | (BIT(m_asic3_hold, 9) << 5)
70         | (BIT(m_asic3_hold, 2) << 6)
71         | (BIT(m_asic3_hold, 5) << 7);
7572      break;
7673   case 0x20: res = 0x49; break;
7774   case 0x21: res = 0x47; break;
r21060r21061
9693   return res;
9794}
9895
99WRITE16_HANDLER( pgm_asic3_w )
96WRITE16_MEMBER(pgm_asic3_state::pgm_asic3_w )
10097{
101   pgm_asic3_state *state = space.machine().driver_data<pgm_asic3_state>();
102
10398   if(ACCESSING_BITS_0_7)
10499   {
105      if (state->m_asic3_reg < 3)
106         state->m_asic3_latch[state->m_asic3_reg] = data << 1;
107      else if (state->m_asic3_reg == 0xa0)
108         state->m_asic3_hold = 0;
109      else if (state->m_asic3_reg == 0x40)
100      if (m_asic3_reg < 3)
101         m_asic3_latch[m_asic3_reg] = data << 1;
102      else if (m_asic3_reg == 0xa0)
103         m_asic3_hold = 0;
104      else if (m_asic3_reg == 0x40)
110105      {
111         state->m_asic3_h2 = state->m_asic3_h1;
112         state->m_asic3_h1 = data;
106         m_asic3_h2 = m_asic3_h1;
107         m_asic3_h1 = data;
113108      }
114      else if (state->m_asic3_reg == 0x48)
109      else if (m_asic3_reg == 0x48)
115110      {
116         state->m_asic3_x = 0;
117         if (!(state->m_asic3_h2 & 0x0a))
118            state->m_asic3_x |= 8;
119         if (!(state->m_asic3_h2 & 0x90))
120            state->m_asic3_x |= 4;
121         if (!(state->m_asic3_h1 & 0x06))
122            state->m_asic3_x |= 2;
123         if (!(state->m_asic3_h1 & 0x90))
124            state->m_asic3_x |= 1;
111         m_asic3_x = 0;
112         if (!(m_asic3_h2 & 0x0a))
113            m_asic3_x |= 8;
114         if (!(m_asic3_h2 & 0x90))
115            m_asic3_x |= 4;
116         if (!(m_asic3_h1 & 0x06))
117            m_asic3_x |= 2;
118         if (!(m_asic3_h1 & 0x90))
119            m_asic3_x |= 1;
125120      }
126      else if(state->m_asic3_reg >= 0x80 && state->m_asic3_reg <= 0x87)
121      else if(m_asic3_reg >= 0x80 && m_asic3_reg <= 0x87)
127122      {
128         state->m_asic3_y = state->m_asic3_reg & 7;
129         state->m_asic3_z = data;
130         asic3_compute_hold(space.machine());
123         m_asic3_y = m_asic3_reg & 7;
124         m_asic3_z = data;
125         asic3_compute_hold();
131126      }
132127   }
133128}
134129
135WRITE16_HANDLER( pgm_asic3_reg_w )
130WRITE16_MEMBER(pgm_asic3_state::pgm_asic3_reg_w )
136131{
137   pgm_asic3_state *state = space.machine().driver_data<pgm_asic3_state>();
138
139132   if(ACCESSING_BITS_0_7)
140      state->m_asic3_reg = data & 0xff;
133      m_asic3_reg = data & 0xff;
141134}
142135
143136
r21060r21061
148141
149142DRIVER_INIT_MEMBER(pgm_asic3_state,orlegend)
150143{
151   pgm_basic_init(machine());
144   pgm_basic_init();
152145
153   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0xC0400e, 0xC0400f, FUNC(pgm_asic3_r), FUNC(pgm_asic3_w));
154   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_write_handler(0xC04000, 0xC04001, FUNC(pgm_asic3_reg_w));
146   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0xC0400e, 0xC0400f, read16_delegate(FUNC(pgm_asic3_state::pgm_asic3_r),this), write16_delegate(FUNC(pgm_asic3_state::pgm_asic3_w),this));
147   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0xC04000, 0xC04001, write16_delegate(FUNC(pgm_asic3_state::pgm_asic3_reg_w),this));
155148
156149   m_asic3_reg = 0;
157150   m_asic3_latch[0] = 0;
trunk/src/mame/machine/pgmprot3.c
r21060r21061
4040#include "emu.h"
4141#include "includes/pgm.h"
4242
43static WRITE32_HANDLER( svg_arm7_ram_sel_w )
43WRITE32_MEMBER(pgm_arm_type3_state::svg_arm7_ram_sel_w )
4444{
4545//  printf("svg_arm7_ram_sel_w %08x\n", data);
46   space.machine().scheduler().synchronize(); // force resync
47
48   pgm_arm_type3_state *state = space.machine().driver_data<pgm_arm_type3_state>();
49   state->m_svg_ram_sel = data & 1;
46   machine().scheduler().synchronize(); // force resync   
47   m_svg_ram_sel = data & 1;
5048}
5149
52static READ32_HANDLER( svg_arm7_shareram_r )
50READ32_MEMBER(pgm_arm_type3_state::svg_arm7_shareram_r )
5351{
54   pgm_arm_type3_state *state = space.machine().driver_data<pgm_arm_type3_state>();
55   return state->m_svg_shareram[state->m_svg_ram_sel & 1][offset];
52   return m_svg_shareram[m_svg_ram_sel & 1][offset];
5653}
5754
58static WRITE32_HANDLER( svg_arm7_shareram_w )
55WRITE32_MEMBER(pgm_arm_type3_state::svg_arm7_shareram_w )
5956{
60   pgm_arm_type3_state *state = space.machine().driver_data<pgm_arm_type3_state>();
61   COMBINE_DATA(&state->m_svg_shareram[state->m_svg_ram_sel & 1][offset]);
57   COMBINE_DATA(&m_svg_shareram[m_svg_ram_sel & 1][offset]);
6258}
6359
64static READ16_HANDLER( svg_m68k_ram_r )
60READ16_MEMBER(pgm_arm_type3_state::svg_m68k_ram_r )
6561{
66   pgm_arm_type3_state *state = space.machine().driver_data<pgm_arm_type3_state>();
67   int ram_sel = (state->m_svg_ram_sel & 1) ^ 1;
68   UINT16 *share16 = (UINT16 *)(state->m_svg_shareram[ram_sel & 1]);
62   int ram_sel = (m_svg_ram_sel & 1) ^ 1;
63   UINT16 *share16 = (UINT16 *)(m_svg_shareram[ram_sel & 1]);
6964
7065   return share16[BYTE_XOR_LE(offset)];
7166}
7267
73static WRITE16_HANDLER( svg_m68k_ram_w )
68WRITE16_MEMBER(pgm_arm_type3_state::svg_m68k_ram_w )
7469{
75   pgm_arm_type3_state *state = space.machine().driver_data<pgm_arm_type3_state>();
76   int ram_sel = (state->m_svg_ram_sel & 1) ^ 1;
77   UINT16 *share16 = (UINT16 *)(state->m_svg_shareram[ram_sel & 1]);
70   int ram_sel = (m_svg_ram_sel & 1) ^ 1;
71   UINT16 *share16 = (UINT16 *)(m_svg_shareram[ram_sel & 1]);
7872
7973   COMBINE_DATA(&share16[BYTE_XOR_LE(offset)]);
8074}
8175
82static READ16_HANDLER( svg_68k_nmi_r )
76READ16_MEMBER(pgm_arm_type3_state::svg_68k_nmi_r )
8377{
8478   return 0;
8579}
8680
87static WRITE16_HANDLER( svg_68k_nmi_w )
81WRITE16_MEMBER(pgm_arm_type3_state::svg_68k_nmi_w )
8882{
89   pgm_arm_type3_state *state = space.machine().driver_data<pgm_arm_type3_state>();
90   generic_pulse_irq_line(state->m_prot, ARM7_FIRQ_LINE, 1);
83   generic_pulse_irq_line(*m_prot, ARM7_FIRQ_LINE, 1);
9184}
9285
93static WRITE16_HANDLER( svg_latch_68k_w )
86WRITE16_MEMBER(pgm_arm_type3_state::svg_latch_68k_w )
9487{
95   pgm_arm_type3_state *state = space.machine().driver_data<pgm_arm_type3_state>();
9688   if (PGMARM7LOGERROR)
9789      logerror("M68K: Latch write: %04x (%04x) (%06x)\n", data & 0x0000ffff, mem_mask, space.device().safe_pc());
98   COMBINE_DATA(&state->m_svg_latchdata_68k_w);
90   COMBINE_DATA(&m_svg_latchdata_68k_w);
9991}
10092
10193
102static READ16_HANDLER( svg_latch_68k_r )
94READ16_MEMBER(pgm_arm_type3_state::svg_latch_68k_r )
10395{
104   pgm_arm_type3_state *state = space.machine().driver_data<pgm_arm_type3_state>();
105
10696   if (PGMARM7LOGERROR)
107      logerror("M68K: Latch read: %04x (%04x) (%06x)\n", state->m_svg_latchdata_arm_w & 0x0000ffff, mem_mask, space.device().safe_pc());
108   return state->m_svg_latchdata_arm_w;
97      logerror("M68K: Latch read: %04x (%04x) (%06x)\n", m_svg_latchdata_arm_w & 0x0000ffff, mem_mask, space.device().safe_pc());
98   return m_svg_latchdata_arm_w;
10999}
110100
111101
112102
113static READ32_HANDLER( svg_latch_arm_r )
103READ32_MEMBER(pgm_arm_type3_state::svg_latch_arm_r )
114104{
115   pgm_arm_type3_state *state = space.machine().driver_data<pgm_arm_type3_state>();
116
117105   if (PGMARM7LOGERROR)
118      logerror("ARM7: Latch read: %08x (%08x) (%06x)\n", state->m_svg_latchdata_68k_w, mem_mask, space.device().safe_pc());
119   return state->m_svg_latchdata_68k_w;
106      logerror("ARM7: Latch read: %08x (%08x) (%06x)\n", m_svg_latchdata_68k_w, mem_mask, space.device().safe_pc());
107   return m_svg_latchdata_68k_w;
120108}
121109
122static WRITE32_HANDLER( svg_latch_arm_w )
110WRITE32_MEMBER(pgm_arm_type3_state::svg_latch_arm_w )
123111{
124   pgm_arm_type3_state *state = space.machine().driver_data<pgm_arm_type3_state>();
125
126112   if (PGMARM7LOGERROR)
127113      logerror("ARM7: Latch write: %08x (%08x) (%06x)\n", data, mem_mask, space.device().safe_pc());
128114
129   COMBINE_DATA(&state->m_svg_latchdata_arm_w);
115   COMBINE_DATA(&m_svg_latchdata_arm_w);
130116}
131117
132118/* 55857G? */
r21060r21061
136122   AM_IMPORT_FROM(pgm_mem)
137123   AM_RANGE(0x100000, 0x1fffff) AM_ROMBANK("bank1")  /* Game ROM */
138124
139   AM_RANGE(0x500000, 0x51ffff) AM_READWRITE_LEGACY(svg_m68k_ram_r, svg_m68k_ram_w)    /* ARM7 Shared RAM */
140   AM_RANGE(0x5c0000, 0x5c0001) AM_READWRITE_LEGACY(svg_68k_nmi_r, svg_68k_nmi_w)      /* ARM7 FIQ */
141   AM_RANGE(0x5c0300, 0x5c0301) AM_READWRITE_LEGACY(svg_latch_68k_r, svg_latch_68k_w) /* ARM7 Latch */
125   AM_RANGE(0x500000, 0x51ffff) AM_READWRITE(svg_m68k_ram_r, svg_m68k_ram_w)    /* ARM7 Shared RAM */
126   AM_RANGE(0x5c0000, 0x5c0001) AM_READWRITE(svg_68k_nmi_r, svg_68k_nmi_w)      /* ARM7 FIQ */
127   AM_RANGE(0x5c0300, 0x5c0301) AM_READWRITE(svg_latch_68k_r, svg_latch_68k_w) /* ARM7 Latch */
142128ADDRESS_MAP_END
143129
144130
r21060r21061
147133   AM_RANGE(0x08000000, 0x087fffff) AM_ROM AM_REGION("user1", 0)
148134   AM_RANGE(0x10000000, 0x100003ff) AM_RAM
149135   AM_RANGE(0x18000000, 0x1803ffff) AM_RAM AM_SHARE("arm_ram")
150   AM_RANGE(0x38000000, 0x3801ffff) AM_READWRITE_LEGACY(svg_arm7_shareram_r, svg_arm7_shareram_w)
151   AM_RANGE(0x48000000, 0x48000003) AM_READWRITE_LEGACY(svg_latch_arm_r, svg_latch_arm_w) /* 68k Latch */
152   AM_RANGE(0x40000018, 0x4000001b) AM_WRITE_LEGACY(svg_arm7_ram_sel_w) /* RAM SEL */
136   AM_RANGE(0x38000000, 0x3801ffff) AM_READWRITE(svg_arm7_shareram_r, svg_arm7_shareram_w)
137   AM_RANGE(0x48000000, 0x48000003) AM_READWRITE(svg_latch_arm_r, svg_latch_arm_w) /* 68k Latch */
138   AM_RANGE(0x40000018, 0x4000001b) AM_WRITE(svg_arm7_ram_sel_w) /* RAM SEL */
153139   AM_RANGE(0x50000000, 0x500003ff) AM_RAM
154140ADDRESS_MAP_END
155141
r21060r21061
182168
183169
184170
185static void svg_basic_init(running_machine &machine)
171void pgm_arm_type3_state::svg_basic_init()
186172{
187   pgm_arm_type3_state *state = machine.driver_data<pgm_arm_type3_state>();
173   pgm_basic_init();
174   m_svg_shareram[0] = auto_alloc_array(machine(), UINT32, 0x10000 / 4);
175   m_svg_shareram[1] = auto_alloc_array(machine(), UINT32, 0x10000 / 4);
176   m_svg_ram_sel = 0;
188177
189   pgm_basic_init(machine);
190   state->m_svg_shareram[0] = auto_alloc_array(machine, UINT32, 0x10000 / 4);
191   state->m_svg_shareram[1] = auto_alloc_array(machine, UINT32, 0x10000 / 4);
192   state->m_svg_ram_sel = 0;
193
194   state->save_pointer(NAME(state->m_svg_shareram[0]), 0x10000 / 4);
195   state->save_pointer(NAME(state->m_svg_shareram[1]), 0x10000 / 4);
196   state->save_item(NAME(state->m_svg_ram_sel));
178   save_pointer(NAME(m_svg_shareram[0]), 0x10000 / 4);
179   save_pointer(NAME(m_svg_shareram[1]), 0x10000 / 4);
180   save_item(NAME(m_svg_ram_sel));
197181}
198182
199static void pgm_create_dummy_internal_arm_region(running_machine &machine)
183void pgm_arm_type3_state::pgm_create_dummy_internal_arm_region()
200184{
201   UINT16 *temp16 = (UINT16 *)machine.root_device().memregion("prot")->base();
185   UINT16 *temp16 = (UINT16 *)memregion("prot")->base();
202186
203187   // fill with RX 14
204188   int i;
r21060r21061
222206
223207
224208
225static void svg_latch_init( running_machine &machine )
209void pgm_arm_type3_state::svg_latch_init()
226210{
227   pgm_arm_type3_state *state = machine.driver_data<pgm_arm_type3_state>();
211   m_svg_latchdata_68k_w = 0;
212   m_svg_latchdata_arm_w = 0;
228213
229   state->m_svg_latchdata_68k_w = 0;
230   state->m_svg_latchdata_arm_w = 0;
231
232   state->save_item(NAME(state->m_svg_latchdata_68k_w));
233   state->save_item(NAME(state->m_svg_latchdata_arm_w));
214   save_item(NAME(m_svg_latchdata_68k_w));
215   save_item(NAME(m_svg_latchdata_arm_w));
234216}
235217
236218
237219DRIVER_INIT_MEMBER(pgm_arm_type3_state,theglad)
238220{
239   svg_basic_init(machine());
221   svg_basic_init();
240222   pgm_theglad_decrypt(machine());
241   svg_latch_init(machine());
242   pgm_create_dummy_internal_arm_region(machine());
223   svg_latch_init();
224   pgm_create_dummy_internal_arm_region();
243225}
244226
245227DRIVER_INIT_MEMBER(pgm_arm_type3_state,svg)
246228{
247   svg_basic_init(machine());
229   svg_basic_init();
248230   pgm_svg_decrypt(machine());
249   svg_latch_init(machine());
250   pgm_create_dummy_internal_arm_region(machine());
231   svg_latch_init();
232   pgm_create_dummy_internal_arm_region();
251233}
252234
253235DRIVER_INIT_MEMBER(pgm_arm_type3_state,svgpcb)
254236{
255   svg_basic_init(machine());
237   svg_basic_init();
256238   pgm_svgpcb_decrypt(machine());
257   svg_latch_init(machine());
258   pgm_create_dummy_internal_arm_region(machine());
239   svg_latch_init();
240   pgm_create_dummy_internal_arm_region();
259241}
260242
261243DRIVER_INIT_MEMBER(pgm_arm_type3_state,killbldp)
262244{
263   svg_basic_init(machine());
245   svg_basic_init();
264246   pgm_killbldp_decrypt(machine());
265   svg_latch_init(machine());
247   svg_latch_init();
266248}
267249
268static READ32_HANDLER( dmnfrnt_speedup_r )
269{
270   pgm_arm_type3_state *state = space.machine().driver_data<pgm_arm_type3_state>();
250READ32_MEMBER(pgm_arm_type3_state::dmnfrnt_speedup_r )
251{   
271252   int pc = space.device().safe_pc();
272253   if (pc == 0x8000fea) space.device().execute().eat_cycles(500);
273254//  else printf("dmn_speedup_r %08x\n", pc);
274   return state->m_arm_ram[0x000444/4];
255   return m_arm_ram[0x000444/4];
275256}
276257
277static READ16_HANDLER( dmnfrnt_main_speedup_r )
278{
279   pgm_state *state = space.machine().driver_data<pgm_state>();
280   UINT16 data = state->m_mainram[0xa03c/2];
258READ16_MEMBER(pgm_arm_type3_state::dmnfrnt_main_speedup_r )
259{   
260   UINT16 data = m_mainram[0xa03c/2];
281261   int pc = space.device().safe_pc();
282262   if (pc == 0x10193a) space.device().execute().spin_until_interrupt();
283263   else if (pc == 0x1019a4) space.device().execute().spin_until_interrupt();
r21060r21061
286266
287267DRIVER_INIT_MEMBER(pgm_arm_type3_state,dmnfrnt)
288268{
289   svg_basic_init(machine());
269   svg_basic_init();
290270   pgm_dfront_decrypt(machine());
291   svg_latch_init(machine());
271   svg_latch_init();
292272
293273   /* put some fake code for the ARM here ... */
294   pgm_create_dummy_internal_arm_region(machine());
274   pgm_create_dummy_internal_arm_region();
295275
296   machine().device("prot")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x18000444, 0x18000447, FUNC(dmnfrnt_speedup_r));
297   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x80a03c, 0x80a03d, FUNC(dmnfrnt_main_speedup_r));
276   machine().device("prot")->memory().space(AS_PROGRAM).install_read_handler(0x18000444, 0x18000447, read32_delegate(FUNC(pgm_arm_type3_state::dmnfrnt_speedup_r),this));
277   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x80a03c, 0x80a03d, read16_delegate(FUNC(pgm_arm_type3_state::dmnfrnt_main_speedup_r),this));
298278
299279   m_svg_ram_sel = 1;
300280
r21060r21061
310290
311291DRIVER_INIT_MEMBER(pgm_arm_type3_state,happy6)
312292{
313   svg_basic_init(machine());
293   svg_basic_init();
314294   pgm_happy6_decrypt(machine());
315   svg_latch_init(machine());
316   pgm_create_dummy_internal_arm_region(machine());
295   svg_latch_init();
296   pgm_create_dummy_internal_arm_region();
317297}
trunk/src/mame/machine/pgmprot4.c
r21060r21061
3333*/
3434
3535
36void pgm_dw3_decrypt(running_machine &machine)
36void pgm_022_025_state::pgm_dw3_decrypt()
3737{
3838//  int i;
3939//  UINT16 *src=(UINT16 *) (OP_ROM+0x100000);
4040
4141   int i;
42   UINT16 *src = (UINT16 *) (machine.root_device().memregion("maincpu")->base()+0x100000);
42   UINT16 *src = (UINT16 *) (memregion("maincpu")->base()+0x100000);
4343
4444   int rom_size = 0x100000;
4545
r21060r21061
6464   }
6565}
6666
67void pgm_killbld_decrypt(running_machine &machine)
67void pgm_022_025_state::pgm_killbld_decrypt()
6868{
6969//  int i;
7070//  UINT16 *src=(UINT16 *) (OP_ROM+0x100000);
7171
7272   int i;
73   UINT16 *src = (UINT16 *) (machine.root_device().memregion("maincpu")->base()+0x100000);
73   UINT16 *src = (UINT16 *) (memregion("maincpu")->base()+0x100000);
7474
7575   int rom_size = 0x200000;
7676
r21060r21061
8888
8989
9090
91static void IGS022_do_dma(running_machine& machine, UINT16 src, UINT16 dst, UINT16 size, UINT16 mode)
91void pgm_022_025_state::IGS022_do_dma(UINT16 src, UINT16 dst, UINT16 size, UINT16 mode)
9292{
93   pgm_022_025_state *state = machine.driver_data<pgm_022_025_state>();
9493   UINT16 param;
9594   /*
9695   P_SRC =0x300290 (offset from prot rom base)
r21060r21061
162161      };
163162      */
164163      int x;
165      UINT16 *PROTROM = (UINT16*)machine.root_device().memregion("igs022data")->base();
164      UINT16 *PROTROM = (UINT16*)memregion("igs022data")->base();
166165
167166      for (x = 0; x < size; x++)
168167      {
169         //UINT16 *RAMDUMP = (UINT16*)space.machine().root_device().memregion("user2")->base();
168         //UINT16 *RAMDUMP = (UINT16*)memregion("user2")->base();
170169         //UINT16 dat = RAMDUMP[dst + x];
171170
172171         UINT16 dat2 = PROTROM[src + x];
173172
174173         UINT8 extraoffset = param&0xfe; // the lowest bit changed the table addressing in tests, see 'rawDataOdd' table instead.. it's still related to the main one, not identical
175         UINT8* dectable = (UINT8*)machine.root_device().memregion("igs022data")->base();//rawDataEven; // the basic decryption table is at the start of the mcu data rom! at least in killbld
174         UINT8* dectable = (UINT8*)memregion("igs022data")->base();//rawDataEven; // the basic decryption table is at the start of the mcu data rom! at least in killbld
176175         UINT16 extraxor = ((dectable[((x*2)+0+extraoffset)&0xff]) << 8) | (dectable[((x*2)+1+extraoffset)&0xff] << 0);
177176
178177         dat2 = ((dat2 & 0x00ff)<<8) | ((dat2 & 0xff00)>>8);
r21060r21061
185184         //if (dat!=dat2)
186185         //  printf("Mode %04x Param %04x Mismatch %04x %04x\n", mode, param, dat, dat2);
187186
188         state->m_sharedprotram[dst + x] = dat2;
187         m_sharedprotram[dst + x] = dat2;
189188      }
190189
191190      /* Killing Blade: hack, patches out some additional security checks... we need to emulate them instead! */
192191      // different region IGS025 devices supply different sequences - we currently only have the china sequence for Killing Blade
193      //if ((mode==3) && (param==0x54) && (src*2==0x2120) && (dst*2==0x2600)) state->m_sharedprotram[0x2600 / 2] = 0x4e75;
192      //if ((mode==3) && (param==0x54) && (src*2==0x2120) && (dst*2==0x2600)) m_sharedprotram[0x2600 / 2] = 0x4e75;
194193
195194   }
196195   if (mode == 4)
r21060r21061
203202   {
204203      /* mode 5 seems to be a straight copy */
205204      int x;
206      UINT16 *PROTROM = (UINT16*)machine.root_device().memregion("igs022data")->base();
205      UINT16 *PROTROM = (UINT16*)memregion("igs022data")->base();
207206      for (x = 0; x < size; x++)
208207      {
209208         UINT16 dat = PROTROM[src + x];
210209
211210
212         state->m_sharedprotram[dst + x] = dat;
211         m_sharedprotram[dst + x] = dat;
213212      }
214213   }
215214   else if (mode == 6)
216215   {
217216      /* mode 6 seems to swap bytes and nibbles */
218217      int x;
219      UINT16 *PROTROM = (UINT16*)machine.root_device().memregion("igs022data")->base();
218      UINT16 *PROTROM = (UINT16*)memregion("igs022data")->base();
220219      for (x = 0; x < size; x++)
221220      {
222221         UINT16 dat = PROTROM[src + x];
r21060r21061
226225               ((dat & 0x00f0) << 4)|
227226               ((dat & 0x000f) << 12);
228227
229         state->m_sharedprotram[dst + x] = dat;
228         m_sharedprotram[dst + x] = dat;
230229      }
231230   }
232231   else if (mode == 7)
r21060r21061
246245
247246// the internal MCU boot code automatically does this DMA
248247// and puts the version # of the data rom in ram
249static void IGS022_reset(running_machine& machine)
248void pgm_022_025_state::IGS022_reset()
250249{
251250   int i;
252   UINT16 *PROTROM = (UINT16*)machine.root_device().memregion("igs022data")->base();
253   pgm_022_025_state *state = machine.driver_data<pgm_022_025_state>();
251   UINT16 *PROTROM = (UINT16*)memregion("igs022data")->base();
254252   UINT16 tmp;
255253
256254   // fill ram with A5 patern
257255   for (i = 0; i < 0x4000/2; i++)
258      state->m_sharedprotram[i] = 0xa55a;
256      m_sharedprotram[i] = 0xa55a;
259257
260258   // the auto-dma
261259   UINT16 src = PROTROM[0x100 / 2];
r21060r21061
272270
273271   printf("Auto-DMA %04x %04x %04x %04x\n",src,dst,size,mode);
274272
275   IGS022_do_dma(machine,src,dst,size,mode);
273   IGS022_do_dma(src,dst,size,mode);
276274
277275   // there is also a version ID? (or is it some kind of checksum) that is stored in the data rom, and gets copied..
278276   // Dragon World 3 checks it
279277   tmp = PROTROM[0x114/2];
280278   tmp = ((tmp & 0xff00) >> 8) | ((tmp & 0x00ff) << 8);
281   state->m_sharedprotram[0x2a2/2] = tmp;
279   m_sharedprotram[0x2a2/2] = tmp;
282280}
283281
284static void IGS022_handle_command(running_machine& machine)
282void pgm_022_025_state::IGS022_handle_command()
285283{
286   pgm_022_025_state *state = machine.driver_data<pgm_022_025_state>();
287   UINT16 cmd = state->m_sharedprotram[0x200/2];
284   UINT16 cmd = m_sharedprotram[0x200/2];
288285   //mame_printf_debug("command %04x\n", cmd);
289286   if (cmd == 0x6d)    //Store values to asic ram
290287   {
291      UINT32 p1 = (state->m_sharedprotram[0x298/2] << 16) | state->m_sharedprotram[0x29a/2];
292      UINT32 p2 = (state->m_sharedprotram[0x29c/2] << 16) | state->m_sharedprotram[0x29e/2];
288      UINT32 p1 = (m_sharedprotram[0x298/2] << 16) | m_sharedprotram[0x29a/2];
289      UINT32 p2 = (m_sharedprotram[0x29c/2] << 16) | m_sharedprotram[0x29e/2];
293290
294291      if ((p2 & 0xffff) == 0x9)   //Set value
295292      {
296293         int reg = (p2 >> 16) & 0xffff;
297294         if (reg & 0x200)
298            state->m_kb_regs[reg & 0xff] = p1;
295            m_kb_regs[reg & 0xff] = p1;
299296      }
300297      if ((p2 & 0xffff) == 0x6)   //Add value
301298      {
302299         int src1 = (p1 >> 16) & 0xff;
303300         int src2 = (p1 >> 0) & 0xff;
304301         int dst = (p2 >> 16) & 0xff;
305         state->m_kb_regs[dst] = state->m_kb_regs[src2] - state->m_kb_regs[src1];
302         m_kb_regs[dst] = m_kb_regs[src2] - m_kb_regs[src1];
306303      }
307304      if ((p2 & 0xffff) == 0x1)   //Add Imm?
308305      {
309306         int reg = (p2 >> 16) & 0xff;
310307         int imm = (p1 >> 0) & 0xffff;
311         state->m_kb_regs[reg] += imm;
308         m_kb_regs[reg] += imm;
312309      }
313310      if ((p2 & 0xffff) == 0xa)   //Get value
314311      {
315312         int reg = (p1 >> 16) & 0xFF;
316         state->m_sharedprotram[0x29c/2] = (state->m_kb_regs[reg] >> 16) & 0xffff;
317         state->m_sharedprotram[0x29e/2] = state->m_kb_regs[reg] & 0xffff;
313         m_sharedprotram[0x29c/2] = (m_kb_regs[reg] >> 16) & 0xffff;
314         m_sharedprotram[0x29e/2] = m_kb_regs[reg] & 0xffff;
318315      }
319316   }
320317   if(cmd == 0x4f) //memcpy with encryption / scrambling
321318   {
322      UINT16 src = state->m_sharedprotram[0x290 / 2] >> 1; // ?
323      UINT32 dst = state->m_sharedprotram[0x292 / 2];
324      UINT16 size = state->m_sharedprotram[0x294 / 2];
325      UINT16 mode = state->m_sharedprotram[0x296 / 2];
319      UINT16 src = m_sharedprotram[0x290 / 2] >> 1; // ?
320      UINT32 dst = m_sharedprotram[0x292 / 2];
321      UINT16 size = m_sharedprotram[0x294 / 2];
322      UINT16 mode = m_sharedprotram[0x296 / 2];
326323
327      IGS022_do_dma(machine, src,dst,size,mode);
324      IGS022_do_dma(src,dst,size,mode);
328325   }
329326
330327}
331328
332329
333static WRITE16_HANDLER( killbld_igs025_prot_w )
330WRITE16_MEMBER(pgm_022_025_state::killbld_igs025_prot_w )
334331{
335332//  mame_printf_debug("killbrd prot r\n");
336//  return 0;
337   pgm_022_025_state *state = space.machine().driver_data<pgm_022_025_state>();
333//  return 0;   
338334   offset &= 0xf;
339335
340336   if (offset == 0)
341      state->m_kb_cmd = data;
337      m_kb_cmd = data;
342338   else //offset==2
343339   {
344      logerror("%06X: ASIC25 W CMD %X  VAL %X\n", space.device().safe_pc(), state->m_kb_cmd, data);
345      if (state->m_kb_cmd == 0)
346         state->m_kb_reg = data;
347      else if (state->m_kb_cmd == 2)
340      logerror("%06X: ASIC25 W CMD %X  VAL %X\n", space.device().safe_pc(), m_kb_cmd, data);
341      if (m_kb_cmd == 0)
342         m_kb_reg = data;
343      else if (m_kb_cmd == 2)
348344      {
349345         if (data == 1)  //Execute cmd
350346         {
351            IGS022_handle_command(space.machine());
352            state->m_kb_reg++;
347            IGS022_handle_command();
348            m_kb_reg++;
353349         }
354350      }
355      else if (state->m_kb_cmd == 4)
356         state->m_kb_ptr = data;
357      else if (state->m_kb_cmd == 0x20)
358         state->m_kb_ptr++;
351      else if (m_kb_cmd == 4)
352         m_kb_ptr = data;
353      else if (m_kb_cmd == 0x20)
354         m_kb_ptr++;
359355   }
360356}
361357
362static READ16_HANDLER( killbld_igs025_prot_r )
358READ16_MEMBER(pgm_022_025_state::killbld_igs025_prot_r )
363359{
364360//  mame_printf_debug("killbld prot w\n");
365   pgm_022_025_state *state = space.machine().driver_data<pgm_022_025_state>();
366361   UINT16 res ;
367362
368363   offset &= 0xf;
r21060r21061
370365
371366   if (offset == 1)
372367   {
373      if (state->m_kb_cmd == 1)
368      if (m_kb_cmd == 1)
374369      {
375         res = state->m_kb_reg & 0x7f;
370         res = m_kb_reg & 0x7f;
376371      }
377      else if (state->m_kb_cmd == 5)
372      else if (m_kb_cmd == 5)
378373      {
379374         UINT8 kb_region_sequence[11] = {0x17, 0x14, 0x91, 0x89, 0x21, 0xD5, 0x7C, 0x65, 0x8F, 0x8E, 0xE1};
380375         UINT8 ret;
381376
382377         // this isn't properly understood.. should be some kind of bitswap / xor / shift..based on values written to 0x22/0x23 etc.?
383378         // return hardcoded china sequence results for now, avoids rom patch
384         if (state->m_kb_region_sequence_position < 11)
379         if (m_kb_region_sequence_position < 11)
385380         {
386            ret = kb_region_sequence[state->m_kb_region_sequence_position];
387            state->m_kb_region_sequence_position++;
381            ret = kb_region_sequence[m_kb_region_sequence_position];
382            m_kb_region_sequence_position++;
388383         }
389384         else
390385         {
391            UINT32 protvalue = 0x89911400 | space.machine().root_device().ioport("Region")->read();
392            ret = (protvalue >> (8 * (state->m_kb_ptr - 1))) & 0xff;
386            UINT32 protvalue = 0x89911400 | ioport("Region")->read();
387            ret = (protvalue >> (8 * (m_kb_ptr - 1))) & 0xff;
393388         }
394389
395390         res = 0x3f00 | ret;  // always 0x3fxx in logged behavior...
396391
397392      }
398393   }
399   logerror("%06X: ASIC25 R CMD %X  VAL %X\n", space.device().safe_pc(), state->m_kb_cmd, res);
394   logerror("%06X: ASIC25 R CMD %X  VAL %X\n", space.device().safe_pc(), m_kb_cmd, res);
400395   return res;
401396}
402397
r21060r21061
407402{
408403   MACHINE_RESET_CALL_MEMBER(pgm);
409404   /* fill the protection ram with a5 + auto dma */
410   IGS022_reset(machine());
405   IGS022_reset();
411406
412407   // Reset IGS025 stuff
413408   m_kb_cmd = 0;
r21060r21061
423418
424419DRIVER_INIT_MEMBER(pgm_022_025_state,killbld)
425420{
426   pgm_basic_init(machine());
427   pgm_killbld_decrypt(machine());
421   pgm_basic_init();
422   pgm_killbld_decrypt();
428423
429   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0xd40000, 0xd40003, FUNC(killbld_igs025_prot_r), FUNC(killbld_igs025_prot_w));
424   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0xd40000, 0xd40003, read16_delegate(FUNC(pgm_022_025_state::killbld_igs025_prot_r),this), write16_delegate(FUNC(pgm_022_025_state::killbld_igs025_prot_w),this));
430425
431426   m_kb_cmd = 0;
432427   m_kb_reg = 0;
r21060r21061
445440{
446441   MACHINE_RESET_CALL_MEMBER(pgm);
447442   /* fill the protection ram with a5 + auto dma */
448   IGS022_reset(machine());
443   IGS022_reset();
449444
450445   /* game won't boot unless various values are in protection RAM
451446    - these should almost certainly end up there as the result of executing the protection
r21060r21061
495490
496491
497492
498static int reg;
499static int ptr=0;
500
501493#define DW3BITSWAP(s,d,bs,bd)  d=((d&(~(1<<bd)))|(((s>>bs)&1)<<bd))
502static UINT8 dw3_swap;
503static WRITE16_HANDLER( drgw3_igs025_prot_w )
504{
505   pgm_022_025_state *state = space.machine().driver_data<pgm_022_025_state>();
506494
495WRITE16_MEMBER(pgm_022_025_state::drgw3_igs025_prot_w )
496{
507497   offset&=0xf;
508498
509499   if(offset==0)
510      state->m_kb_cmd=data;
500      m_kb_cmd=data;
511501   else //offset==2
512502   {
513      printf("%06X: ASIC25 W CMD %X  VAL %X\n",space.device().safe_pc(),state->m_kb_cmd,data);
514      if(state->m_kb_cmd==0)
503      printf("%06X: ASIC25 W CMD %X  VAL %X\n",space.device().safe_pc(),m_kb_cmd,data);
504      if(m_kb_cmd==0)
515505         reg=data;
516      else if(state->m_kb_cmd==3) //??????????
506      else if(m_kb_cmd==3) //??????????
517507      {
518508         dw3_swap = data;
519509
r21060r21061
521511      }
522512      //else if(kb_cmd==4)
523513      //  ptr=data;
524      else if(state->m_kb_cmd==0x20)
514      else if(m_kb_cmd==0x20)
525515         ptr++;
526516   }
527517}
528518
529static READ16_HANDLER( drgw3_igs025_prot_r )
519READ16_MEMBER(pgm_022_025_state::drgw3_igs025_prot_r )
530520{
531//  mame_printf_debug("killbld prot w\n");
532   pgm_022_025_state *state = space.machine().driver_data<pgm_022_025_state>();
533
521//  mame_printf_debug("killbld prot w\n");   
534522   UINT16 res ;
535523
536524   offset&=0xf;
r21060r21061
538526
539527   if(offset==1)
540528   {
541      if(state->m_kb_cmd==0)  //swap
529      if(m_kb_cmd==0)  //swap
542530      {
543531            UINT8 v1=(dw3_swap+1)&0x7F;
544532            UINT8 v2=0;
r21060r21061
554542            res=v2;
555543
556544      }
557      else if(state->m_kb_cmd==1)
545      else if(m_kb_cmd==1)
558546      {
559547         res=reg&0x7f;
560548      }
561      else if(state->m_kb_cmd==5)
549      else if(m_kb_cmd==5)
562550      {
563551         UINT32 protvalue;
564         protvalue = 0x60000|space.machine().root_device().ioport("Region")->read();
552         protvalue = 0x60000|ioport("Region")->read();
565553         res=(protvalue>>(8*(ptr-1)))&0xff;
566554
567555
568556      }
569557   }
570   logerror("%06X: ASIC25 R CMD %X  VAL %X\n",space.device().safe_pc(),state->m_kb_cmd,res);
558   logerror("%06X: ASIC25 R CMD %X  VAL %X\n",space.device().safe_pc(),m_kb_cmd,res);
571559   return res;
572560}
573561
574562
575563DRIVER_INIT_MEMBER(pgm_022_025_state,drgw3)
576564{
577   pgm_basic_init(machine());
578
565   pgm_basic_init();
566   ptr = 0;
579567/*
580568    {
581569        int x;
r21060r21061
587575        }
588576    }
589577*/
590   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0xDA5610, 0xDA5613, FUNC(drgw3_igs025_prot_r), FUNC(drgw3_igs025_prot_w));
578   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0xDA5610, 0xDA5613, read16_delegate(FUNC(pgm_022_025_state::drgw3_igs025_prot_r),this), write16_delegate(FUNC(pgm_022_025_state::drgw3_igs025_prot_w),this));
591579
592   pgm_dw3_decrypt(machine());
580   pgm_dw3_decrypt();
593581}
594582
595583
trunk/src/mame/machine/pgmprot5.c
r21060r21061
2626
2727/* Dragon World 2 */
2828
29static int protection_address;
30
31static UINT16 dw2_asic_reg[2];
32static UINT8 dw2_asic_z;
33static UINT8 dw2_asic_y;
34static UINT16 dw2_asic_hold;
35
36READ16_HANDLER( dw2_d80000_r )
29READ16_MEMBER(pgm_state::dw2_d80000_r )
3730{
38//  pgm_state *state = space.machine().driver_data<pgm_state>();
3931   UINT16 ret;
4032/*  UINT16 test;
4133
r21060r21061
5446            logerror("%06x: warning, reading with igs003_reg = %02x\n", space.device().safe_pc(), dw2_asic_reg[0]);
5547    }
5648
57    test = BITSWAP16(state->m_mainram[protection_address], 14,11,8,6,4,3,1,0, 5,2,9,7,10,13,12,15) & 0xff; // original hack
49    test = BITSWAP16(m_mainram[protection_address], 14,11,8,6,4,3,1,0, 5,2,9,7,10,13,12,15) & 0xff; // original hack
5850*/
5951   // This bitswap seems to also be common to a few IGS protection devices (igs011.c, Oriental Legend)
6052   ret = BITSWAP16(dw2_asic_hold, 14,11,8,6,4,3,1,0, 5,2,9,7,10,13,12,15) & 0xff;
6153/*
62    if ((ret != test) || (dw2_asic_hold != state->m_mainram[protection_address])) {
63        logerror ("Protection calculation error: SIMRET: %2.2x, HACKRET: %2.2x, SIMHOLD: %4.4x, REALHOLD: %4.4x\n", ret, test, dw2_asic_hold, state->m_mainram[protection_address]);
54    if ((ret != test) || (dw2_asic_hold != m_mainram[protection_address])) {
55        logerror ("Protection calculation error: SIMRET: %2.2x, HACKRET: %2.2x, SIMHOLD: %4.4x, REALHOLD: %4.4x\n", ret, test, dw2_asic_hold, m_mainram[protection_address]);
6456    }
6557*/
6658   return ret;
6759}
6860
69WRITE16_HANDLER( dw2_d80000_w )
61WRITE16_MEMBER(pgm_state::dw2_d80000_w )
7062{
71   pgm_state *state = space.machine().driver_data<pgm_state>();
72
7363   COMBINE_DATA(&dw2_asic_reg[offset]);
7464
7565   if (offset == 0)
r21060r21061
8272         // initialized. Ok to use as reset??
8373         // The last "hold" value used is stored in NVRAM. Otherwise we either
8474         // need to set the "hold" value as non-volatile or wipe NVRAM.
85         dw2_asic_hold = state->m_mainram[protection_address]; // hack
75         dw2_asic_hold = m_mainram[protection_address]; // hack
8676      break;
8777
8878      case 0x09: // Used only on init...
r21060r21061
155145}
156146
157147// What purpose to writes to this region serve? Written, but never read back? Must be related to the protection device?
158WRITE16_HANDLER(dw2_unk_w)
148WRITE16_MEMBER(pgm_state::dw2_unk_w)
159149{
160150//  logerror("%06x: warning, writing to address %6.6x = %4.4x\n", space.device().safe_pc(), 0xd00000+(offset*2), data);
161151}
162152
163static void pgm_dw2_decrypt(running_machine &machine)
153void pgm_state::pgm_dw2_decrypt()
164154{
165155   int i;
166   UINT16 *src = (UINT16 *) (machine.root_device().memregion("maincpu")->base()+0x100000);
156   UINT16 *src = (UINT16 *) (memregion("maincpu")->base()+0x100000);
167157
168158   int rom_size = 0x80000;
169159
r21060r21061
180170   }
181171}
182172
183static void drgwld2_common_init(running_machine &machine)
173void pgm_state::drgwld2_common_init()
184174{
185   pgm_basic_init(machine);
186   pgm_dw2_decrypt(machine);
175   pgm_basic_init();
176   pgm_dw2_decrypt();
187177
188   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0xd80000, 0xd80003, FUNC(dw2_d80000_r));
189   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_write_handler(0xd80000, 0xd80003, FUNC(dw2_d80000_w));
190   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_write_handler(0xd00000, 0xd00fff, FUNC(dw2_unk_w));
178   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0xd80000, 0xd80003, read16_delegate(FUNC(pgm_state::dw2_d80000_r),this));
179   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0xd80000, 0xd80003, write16_delegate(FUNC(pgm_state::dw2_d80000_w),this));
180   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0xd00000, 0xd00fff, write16_delegate(FUNC(pgm_state::dw2_unk_w),this));
191181}
192182
193183DRIVER_INIT_MEMBER(pgm_state,drgw2)
194184{
195185   /* incomplete? */
196   UINT16 *mem16 = (UINT16 *)machine().root_device().memregion("maincpu")->base();
186   UINT16 *mem16 = (UINT16 *)memregion("maincpu")->base();
197187
198   drgwld2_common_init(machine());
188   drgwld2_common_init();
199189
200190   protection_address = 0xcb7e/2; // $80cb7e;
201191
r21060r21061
209199
210200DRIVER_INIT_MEMBER(pgm_state,dw2v100x)
211201{
212   UINT16 *mem16 = (UINT16 *)machine().root_device().memregion("maincpu")->base();
202   UINT16 *mem16 = (UINT16 *)memregion("maincpu")->base();
213203
214   drgwld2_common_init(machine());
204   drgwld2_common_init();
215205
216206   protection_address = 0xcb7e/2; // $80cb7e;
217207
r21060r21061
225215
226216DRIVER_INIT_MEMBER(pgm_state,drgw2c)
227217{
228   UINT16 *mem16 = (UINT16 *)machine().root_device().memregion("maincpu")->base();
218   UINT16 *mem16 = (UINT16 *)memregion("maincpu")->base();
229219
230   drgwld2_common_init(machine());
220   drgwld2_common_init();
231221
232222   protection_address = 0xeece/2; // $80eece;
233223
r21060r21061
241231
242232DRIVER_INIT_MEMBER(pgm_state,drgw2j)
243233{
244   UINT16 *mem16 = (UINT16 *)machine().root_device().memregion("maincpu")->base();
234   UINT16 *mem16 = (UINT16 *)memregion("maincpu")->base();
245235
246   drgwld2_common_init(machine());
236   drgwld2_common_init();
247237
248238   protection_address = 0x91cc/2; // $8091cc;
249239
trunk/src/mame/machine/pgmprot6.c
r21060r21061
2020#include "emu.h"
2121#include "includes/pgm.h"
2222
23static UINT32 olds_prot_addr( UINT16 addr )
23UINT32 pgm_028_025_state::olds_prot_addr( UINT16 addr )
2424{
2525   UINT32 mode = addr & 0xff;
2626   UINT32 offset = addr >> 8;
r21060r21061
6969   return realaddr;
7070}
7171
72static UINT32 olds_read_reg( running_machine &machine, UINT16 addr )
72UINT32 pgm_028_025_state::olds_read_reg(UINT16 addr )
7373{
74   pgm_028_025_state *state = machine.driver_data<pgm_028_025_state>();
7574   UINT32 protaddr = (olds_prot_addr(addr) - 0x400000) / 2;
76   return state->m_sharedprotram[protaddr] << 16 | state->m_sharedprotram[protaddr + 1];
75   return m_sharedprotram[protaddr] << 16 | m_sharedprotram[protaddr + 1];
7776}
7877
79static void olds_write_reg( running_machine &machine, UINT16 addr, UINT32 val )
78void pgm_028_025_state::olds_write_reg( UINT16 addr, UINT32 val )
8079{
81   pgm_028_025_state *state = machine.driver_data<pgm_028_025_state>();
82   state->m_sharedprotram[(olds_prot_addr(addr) - 0x400000) / 2]     = val >> 16;
83   state->m_sharedprotram[(olds_prot_addr(addr) - 0x400000) / 2 + 1] = val & 0xffff;
80   m_sharedprotram[(olds_prot_addr(addr) - 0x400000) / 2]     = val >> 16;
81   m_sharedprotram[(olds_prot_addr(addr) - 0x400000) / 2 + 1] = val & 0xffff;
8482}
8583
8684MACHINE_RESET_MEMBER(pgm_028_025_state,olds)
r21060r21061
104102   }
105103}
106104
107static READ16_HANDLER( olds_r )
105READ16_MEMBER(pgm_028_025_state::olds_r )
108106{
109   pgm_028_025_state *state = space.machine().driver_data<pgm_028_025_state>();
110107   UINT16 res = 0;
111108
112109   if (offset == 1)
113110   {
114      if (state->m_kb_cmd == 1)
115         res = state->m_kb_reg & 0x7f;
116      if (state->m_kb_cmd == 2)
117         res = state->m_olds_bs | 0x80;
118      if (state->m_kb_cmd == 3)
119         res = state->m_olds_cmd3;
120      else if (state->m_kb_cmd == 5)
111      if (m_kb_cmd == 1)
112         res = m_kb_reg & 0x7f;
113      if (m_kb_cmd == 2)
114         res = m_olds_bs | 0x80;
115      if (m_kb_cmd == 3)
116         res = m_olds_cmd3;
117      else if (m_kb_cmd == 5)
121118      {
122         UINT32 protvalue = 0x900000 | state->ioport("Region")->read(); // region from protection device.
123         res = (protvalue >> (8 * (state->m_kb_ptr - 1))) & 0xff; // includes region 1 = taiwan , 2 = china, 3 = japan (title = orlegend special), 4 = korea, 5 = hongkong, 6 = world
119         UINT32 protvalue = 0x900000 | ioport("Region")->read(); // region from protection device.
120         res = (protvalue >> (8 * (m_kb_ptr - 1))) & 0xff; // includes region 1 = taiwan , 2 = china, 3 = japan (title = orlegend special), 4 = korea, 5 = hongkong, 6 = world
124121
125122      }
126123   }
127   logerror("%06X: ASIC25 R CMD %X  VAL %X\n", space.device().safe_pc(), state->m_kb_cmd, res);
124   logerror("%06X: ASIC25 R CMD %X  VAL %X\n", space.device().safe_pc(), m_kb_cmd, res);
128125   return res;
129126}
130127
131static WRITE16_HANDLER( olds_w )
128WRITE16_MEMBER(pgm_028_025_state::olds_w )
132129{
133   pgm_028_025_state *state = space.machine().driver_data<pgm_028_025_state>();
134130   if (offset == 0)
135      state->m_kb_cmd = data;
131      m_kb_cmd = data;
136132   else //offset==2
137133   {
138      logerror("%06X: ASIC25 W CMD %X  VAL %X\n",space.device().safe_pc(), state->m_kb_cmd, data);
139      if (state->m_kb_cmd == 0)
140         state->m_kb_reg = data;
141      else if(state->m_kb_cmd == 2)   //a bitswap=
134      logerror("%06X: ASIC25 W CMD %X  VAL %X\n",space.device().safe_pc(), m_kb_cmd, data);
135      if (m_kb_cmd == 0)
136         m_kb_reg = data;
137      else if(m_kb_cmd == 2)   //a bitswap=
142138      {
143139         int reg = 0;
144140         if (data & 0x01)
r21060r21061
149145            reg |= 0x20;
150146         if (data & 0x08)
151147            reg |= 0x10;
152         state->m_olds_bs = reg;
148         m_olds_bs = reg;
153149      }
154      else if (state->m_kb_cmd == 3)
150      else if (m_kb_cmd == 3)
155151      {
156         UINT16 cmd = state->m_sharedprotram[0x3026 / 2];
152         UINT16 cmd = m_sharedprotram[0x3026 / 2];
157153         switch (cmd)
158154         {
159155            case 0x11:
r21060r21061
161157                  break;
162158            case 0x64:
163159               {
164                  UINT16 cmd0 = state->m_sharedprotram[0x3082 / 2];
165                  UINT16 val0 = state->m_sharedprotram[0x3050 / 2];   //CMD_FORMAT
160                  UINT16 cmd0 = m_sharedprotram[0x3082 / 2];
161                  UINT16 val0 = m_sharedprotram[0x3050 / 2];   //CMD_FORMAT
166162                  {
167163                     if ((cmd0 & 0xff) == 0x2)
168                        olds_write_reg(space.machine(), val0, olds_read_reg(space.machine(), val0) + 0x10000);
164                        olds_write_reg(val0, olds_read_reg(val0) + 0x10000);
169165                  }
170166                  break;
171167               }
r21060r21061
173169            default:
174170                  break;
175171         }
176         state->m_olds_cmd3 = ((data >> 4) + 1) & 0x3;
172         m_olds_cmd3 = ((data >> 4) + 1) & 0x3;
177173      }
178      else if (state->m_kb_cmd == 4)
179         state->m_kb_ptr = data;
180      else if(state->m_kb_cmd == 0x20)
181         state->m_kb_ptr++;
174      else if (m_kb_cmd == 4)
175         m_kb_ptr = data;
176      else if(m_kb_cmd == 0x20)
177         m_kb_ptr++;
182178   }
183179}
184180
185static READ16_HANDLER( olds_prot_swap_r )
181READ16_MEMBER(pgm_028_025_state::olds_prot_swap_r )
186182{
187   pgm_state *state = space.machine().driver_data<pgm_state>();
188183   if (space.device().safe_pc() < 0x100000)        //bios
189      return state->m_mainram[0x178f4 / 2];
184      return m_mainram[0x178f4 / 2];
190185   else                        //game
191      return state->m_mainram[0x178d8 / 2];
186      return m_mainram[0x178d8 / 2];
192187
193188}
194189
195190DRIVER_INIT_MEMBER(pgm_028_025_state,olds)
196191{
197   pgm_basic_init(machine());
192   pgm_basic_init();
198193
199   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0xdcb400, 0xdcb403, FUNC(olds_r), FUNC(olds_w));
200   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x8178f4, 0x8178f5, FUNC(olds_prot_swap_r));
194   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0xdcb400, 0xdcb403, read16_delegate(FUNC(pgm_028_025_state::olds_r),this), write16_delegate(FUNC(pgm_028_025_state::olds_w),this));
195   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x8178f4, 0x8178f5, read16_delegate(FUNC(pgm_028_025_state::olds_prot_swap_r),this));
201196
202197   m_kb_cmd = 0;
203198   m_kb_reg = 0;
trunk/src/mame/includes/pgm.h
r21060r21061
119119   UINT32 screen_update_pgm(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
120120   void screen_eof_pgm(screen_device &screen, bool state);
121121   TIMER_DEVICE_CALLBACK_MEMBER(pgm_interrupt);
122   
123   // from pgmprot5.c
124   int protection_address;
125
126   UINT16 dw2_asic_reg[2];
127   UINT8 dw2_asic_z;
128   UINT8 dw2_asic_y;
129   UINT16 dw2_asic_hold;
130   
131   DECLARE_READ16_MEMBER( dw2_d80000_r );
132   DECLARE_WRITE16_MEMBER( dw2_d80000_w );
133   DECLARE_WRITE16_MEMBER(dw2_unk_w);
134   void pgm_dw2_decrypt();
135   void drgwld2_common_init();   
136   inline void pgm_draw_pix( int xdrawpos, int pri, UINT16* dest, UINT8* destpri, UINT16 srcdat);
137   inline void pgm_draw_pix_nopri( int xdrawpos, UINT16* dest, UINT8* destpri, UINT16 srcdat);
138   inline void pgm_draw_pix_pri( int xdrawpos, UINT16* dest, UINT8* destpri, UINT16 srcdat);
139   void draw_sprite_line( int wide, UINT16* dest, UINT8* destpri, int xzoom, int xgrow, int flip, int xpos, int pri, int realxsize, int palt, int draw );
140   void draw_sprite_new_zoomed( int wide, int high, int xpos, int ypos, int palt, int flip, bitmap_ind16 &bitmap, bitmap_ind8 &priority_bitmap, UINT32 xzoom, int xgrow, UINT32 yzoom, int ygrow, int pri );
141   void draw_sprite_line_basic( int wide, UINT16* dest, UINT8* destpri, int flip, int xpos, int pri, int realxsize, int palt, int draw );
142   void draw_sprite_new_basic( int wide, int high, int xpos, int ypos, int palt, int flip, bitmap_ind16 &bitmap, bitmap_ind8 &priority_bitmap, int pri );
143   void draw_sprites( bitmap_ind16& spritebitmap, UINT16 *sprite_source, bitmap_ind8& priority_bitmap );
144   void expand_32x32x5bpp();
145   void expand_colourdata(  );
146   void pgm_basic_init( bool set_bank = true);
122147};
123148
124149
r21060r21061
141166   UINT16        m_asic3_hold;
142167
143168   DECLARE_DRIVER_INIT(orlegend);
169   void asic3_compute_hold();
170   DECLARE_READ16_MEMBER( pgm_asic3_r );
171   DECLARE_WRITE16_MEMBER( pgm_asic3_w );
172   DECLARE_WRITE16_MEMBER( pgm_asic3_reg_w );   
144173};
145174
146175
r21060r21061
175204   // puzzli2
176205   INT32 m_puzzli_54_trigger;
177206
178   typedef void (*pgm_arm_sim_command_handler)(pgm_arm_type1_state *state, int pc);
207   typedef void (pgm_arm_type1_state::*pgm_arm_sim_command_handler)(int pc);
179208
180209   pgm_arm_sim_command_handler arm_sim_handler;
181210
r21060r21061
206235   DECLARE_DRIVER_INIT(kovboot);
207236   DECLARE_DRIVER_INIT(oldsplus);
208237   DECLARE_MACHINE_START(pgm_arm_type1);
238   
239   DECLARE_READ32_MEMBER( pgm_arm7_type1_protlatch_r );
240   DECLARE_WRITE32_MEMBER( pgm_arm7_type1_protlatch_w );
241   DECLARE_READ16_MEMBER( pgm_arm7_type1_68k_protlatch_r );
242   DECLARE_WRITE16_MEMBER( pgm_arm7_type1_68k_protlatch_w );
243   DECLARE_READ16_MEMBER( pgm_arm7_type1_ram_r );
244   DECLARE_WRITE16_MEMBER( pgm_arm7_type1_ram_w );
245   DECLARE_READ32_MEMBER( pgm_arm7_type1_unk_r );
246   DECLARE_READ32_MEMBER( pgm_arm7_type1_exrom_r );
247   DECLARE_READ32_MEMBER( pgm_arm7_type1_shareram_r );
248   DECLARE_WRITE32_MEMBER( pgm_arm7_type1_shareram_w );
249   void pgm_arm7_type1_latch_init();
250   DECLARE_READ16_MEMBER( kovsh_fake_region_r );
251   DECLARE_WRITE16_MEMBER( kovshp_asic27a_write_word );
252   void pgm_decode_kovlsqh2_tiles();
253   void pgm_decode_kovlsqh2_sprites(UINT8 *src );
254   void pgm_decode_kovlsqh2_samples();
255   void pgm_decode_kovqhsgs_program();
256   void pgm_decode_kovqhsgs2_program();
257   DECLARE_READ16_MEMBER( pgm_arm7_type1_sim_r );
258   void command_handler_ddp3(int pc);
259   void command_handler_puzzli2(int pc);
260   void command_handler_py2k2(int pc);
261   void command_handler_pstars(int pc);
262   void command_handler_kov(int pc);
263   void command_handler_oldsplus(int pc);
264   DECLARE_WRITE16_MEMBER( pgm_arm7_type1_sim_w );
265   DECLARE_READ16_MEMBER( pgm_arm7_type1_sim_protram_r );
266   DECLARE_READ16_MEMBER( pstars_arm7_type1_sim_protram_r );   
209267};
210268
211269/* for machine/pgmprot2.c type games */
r21060r21061
233291   DECLARE_DRIVER_INIT(dw2001);
234292   DECLARE_DRIVER_INIT(dwpc);
235293   DECLARE_MACHINE_START(pgm_arm_type2);
294   DECLARE_READ32_MEMBER( arm7_latch_arm_r );
295   DECLARE_WRITE32_MEMBER( arm7_latch_arm_w );
296   DECLARE_READ32_MEMBER( arm7_shareram_r );
297   DECLARE_WRITE32_MEMBER( arm7_shareram_w );
298   DECLARE_READ16_MEMBER( arm7_latch_68k_r );
299   DECLARE_WRITE16_MEMBER( arm7_latch_68k_w );
300   DECLARE_READ16_MEMBER( arm7_ram_r );
301   DECLARE_WRITE16_MEMBER( arm7_ram_w );
302   void kov2_latch_init();
303   DECLARE_WRITE32_MEMBER( martmast_arm_region_w );
304   DECLARE_WRITE32_MEMBER( kov2_arm_region_w );
305   DECLARE_WRITE32_MEMBER( ddp2_arm_region_w );
306   DECLARE_READ32_MEMBER( ddp2_speedup_r );
307   DECLARE_READ16_MEMBER( ddp2_main_speedup_r );
236308};
237309
238310
r21060r21061
262334   DECLARE_DRIVER_INIT(dmnfrnt);
263335   DECLARE_DRIVER_INIT(happy6);
264336   DECLARE_MACHINE_START(pgm_arm_type3);
337   DECLARE_WRITE32_MEMBER( svg_arm7_ram_sel_w );
338   DECLARE_READ32_MEMBER( svg_arm7_shareram_r );
339   DECLARE_WRITE32_MEMBER( svg_arm7_shareram_w );
340   DECLARE_READ16_MEMBER( svg_m68k_ram_r );
341   DECLARE_WRITE16_MEMBER( svg_m68k_ram_w );
342   DECLARE_READ16_MEMBER( svg_68k_nmi_r );
343   DECLARE_WRITE16_MEMBER( svg_68k_nmi_w );
344   DECLARE_WRITE16_MEMBER( svg_latch_68k_w );
345   DECLARE_READ16_MEMBER( svg_latch_68k_r );
346   DECLARE_READ32_MEMBER( svg_latch_arm_r );
347   DECLARE_WRITE32_MEMBER( svg_latch_arm_w );
348   void svg_basic_init();
349   void pgm_create_dummy_internal_arm_region();
350   void svg_latch_init();
351   DECLARE_READ32_MEMBER( dmnfrnt_speedup_r );
352   DECLARE_READ16_MEMBER( dmnfrnt_main_speedup_r );
265353};
266354
267355
r21060r21061
278366   int           m_kb_ptr;
279367   int           m_kb_region_sequence_position;
280368   UINT32        m_kb_regs[0x10];
369   int         reg;
370   int         ptr;
371   UINT8         dw3_swap;
281372   required_shared_ptr<UINT16> m_sharedprotram;
282373
283374   DECLARE_DRIVER_INIT(killbld);
284375   DECLARE_DRIVER_INIT(drgw3);
285376   DECLARE_MACHINE_RESET(killbld);
286377   DECLARE_MACHINE_RESET(dw3);
378   void pgm_dw3_decrypt();
379   void pgm_killbld_decrypt();
380   void IGS022_do_dma(UINT16 src, UINT16 dst, UINT16 size, UINT16 mode);
381   void IGS022_reset();
382   void IGS022_handle_command();
383   DECLARE_WRITE16_MEMBER( killbld_igs025_prot_w );
384   DECLARE_READ16_MEMBER( killbld_igs025_prot_r );
385   DECLARE_WRITE16_MEMBER( drgw3_igs025_prot_w );
386   DECLARE_READ16_MEMBER( drgw3_igs025_prot_r );
287387};
288388
289389/* for machine/pgmprot6.c type games */
r21060r21061
304404
305405   DECLARE_DRIVER_INIT(olds);
306406   DECLARE_MACHINE_RESET(olds);
407   
408   UINT32 olds_prot_addr( UINT16 addr );
409   UINT32 olds_read_reg( UINT16 addr );
410   void olds_write_reg( UINT16 addr, UINT32 val );
411   DECLARE_READ16_MEMBER( olds_r );
412   DECLARE_WRITE16_MEMBER( olds_w );
413   DECLARE_READ16_MEMBER( olds_prot_swap_r );
307414};
308415
309416
r21060r21061
311418
312419/*----------- defined in drivers/pgm.c -----------*/
313420
314void pgm_basic_init( running_machine &machine, bool set_bank  = true );
315
316421INPUT_PORTS_EXTERN( pgm );
317422
318423GFXDECODE_EXTERN( pgm );
trunk/src/mame/video/pgm.c
r21060r21061
1616// bg pri is 2
1717// sprite already here is 1 / 3
1818
19INLINE void pgm_draw_pix( int xdrawpos, int pri, UINT16* dest, UINT8* destpri, UINT16 srcdat)
19inline void pgm_state::pgm_draw_pix( int xdrawpos, int pri, UINT16* dest, UINT8* destpri, UINT16 srcdat)
2020{
2121   if ((xdrawpos >= 0) && (xdrawpos < 448))
2222   {
r21060r21061
3939   }
4040}
4141
42INLINE void pgm_draw_pix_nopri( int xdrawpos, UINT16* dest, UINT8* destpri, UINT16 srcdat)
42inline void pgm_state::pgm_draw_pix_nopri( int xdrawpos, UINT16* dest, UINT8* destpri, UINT16 srcdat)
4343{
4444   if ((xdrawpos >= 0) && (xdrawpos < 448))
4545   {
r21060r21061
5151   }
5252}
5353
54INLINE void pgm_draw_pix_pri( int xdrawpos, UINT16* dest, UINT8* destpri, UINT16 srcdat)
54inline void pgm_state::pgm_draw_pix_pri( int xdrawpos, UINT16* dest, UINT8* destpri, UINT16 srcdat)
5555{
5656   if ((xdrawpos >= 0) && (xdrawpos < 448))
5757   {
r21060r21061
7171  for complex zoomed cases
7272*************************************************************************/
7373
74static void draw_sprite_line( running_machine &machine, int wide, UINT16* dest, UINT8* destpri, int xzoom, int xgrow, int flip, int xpos, int pri, int realxsize, int palt, int draw )
74void pgm_state::draw_sprite_line( int wide, UINT16* dest, UINT8* destpri, int xzoom, int xgrow, int flip, int xpos, int pri, int realxsize, int palt, int draw )
7575{
76   pgm_state *state = machine.driver_data<pgm_state>();
7776   int xcnt,xcntdraw;
7877   int xzoombit;
7978   int xoffset = 0;
8079   int xdrawpos = 0;
8180
82   UINT8 *adata = state->m_sprite_a_region;
83   size_t  adatasize = state->m_sprite_a_region_size - 1;
81   UINT8 *adata = m_sprite_a_region;
82   size_t  adatasize = m_sprite_a_region_size - 1;
8483
8584   UINT16 msk;
8685   UINT16 srcdat;
r21060r21061
9291   {
9392      int x;
9493
95      msk = ((state->m_bdata[(state->m_boffset + 1) & state->m_bdatasize] << 8) |( state->m_bdata[(state->m_boffset + 0) & state->m_bdatasize] << 0));
94      msk = ((m_bdata[(m_boffset + 1) & m_bdatasize] << 8) |( m_bdata[(m_boffset + 0) & m_bdatasize] << 0));
9695
9796      for (x = 0; x < 16; x++)
9897      {
9998         if (!(msk & 0x0001))
10099         {
101            srcdat = adata[state->m_aoffset & adatasize] + palt * 32;
102            state->m_aoffset++;
100            srcdat = adata[m_aoffset & adatasize] + palt * 32;
101            m_aoffset++;
103102
104103            if (draw)
105104            {
r21060r21061
159158
160159      }
161160
162      state->m_boffset += 2;
161      m_boffset += 2;
163162   }
164163}
165164
166static void draw_sprite_new_zoomed( pgm_state *state, running_machine &machine, int wide, int high, int xpos, int ypos, int palt, int flip, bitmap_ind16 &bitmap, bitmap_ind8 &priority_bitmap, UINT32 xzoom, int xgrow, UINT32 yzoom, int ygrow, int pri )
165void pgm_state::draw_sprite_new_zoomed( int wide, int high, int xpos, int ypos, int palt, int flip, bitmap_ind16 &bitmap, bitmap_ind8 &priority_bitmap, UINT32 xzoom, int xgrow, UINT32 yzoom, int ygrow, int pri )
167166{
168167   int ycnt;
169168   int ydrawpos;
r21060r21061
175174   int xcnt = 0;
176175
177176
178   state->m_aoffset = (state->m_bdata[(state->m_boffset + 3) & state->m_bdatasize] << 24) | (state->m_bdata[(state->m_boffset + 2) & state->m_bdatasize] << 16) |
179            (state->m_bdata[(state->m_boffset + 1) & state->m_bdatasize] << 8) | (state->m_bdata[(state->m_boffset + 0) & state->m_bdatasize] << 0);
180   state->m_aoffset = state->m_aoffset >> 2; state->m_aoffset *= 3;
177   m_aoffset = (m_bdata[(m_boffset + 3) & m_bdatasize] << 24) | (m_bdata[(m_boffset + 2) & m_bdatasize] << 16) |
178            (m_bdata[(m_boffset + 1) & m_bdatasize] << 8) | (m_bdata[(m_boffset + 0) & m_bdatasize] << 0);
179   m_aoffset = m_aoffset >> 2; m_aoffset *= 3;
181180
182   state->m_boffset+=4;
181   m_boffset+=4;
183182
184183   /* precalculate where drawing will end, for flipped zoomed cases. */
185184   /* if we're to avoid pre-decoding the data for each sprite each time we draw then we have to draw the sprite data
r21060r21061
224223
225224      if (yzoombit == 1 && ygrow == 1) // double this line
226225      {
227         int temp_aoffset = state->m_aoffset;
228         int temp_boffset = state->m_boffset;
226         int temp_aoffset = m_aoffset;
227         int temp_boffset = m_boffset;
229228
230229         if (!(flip & 0x02))
231230            ydrawpos = ypos + ycntdraw;
r21060r21061
236235         {
237236            dest = &bitmap.pix16(ydrawpos);
238237            destpri = &priority_bitmap.pix8(ydrawpos);
239            draw_sprite_line(machine, wide, dest, destpri, xzoom, xgrow, flip, xpos, pri, realxsize, palt, 1);
238            draw_sprite_line(wide, dest, destpri, xzoom, xgrow, flip, xpos, pri, realxsize, palt, 1);
240239         }
241240         else
242241         {
243            draw_sprite_line(machine, wide, NULL, NULL, xzoom, xgrow, flip, xpos, pri, realxsize, palt, 0);
242            draw_sprite_line(wide, NULL, NULL, xzoom, xgrow, flip, xpos, pri, realxsize, palt, 0);
244243         }
245244
246245         ycntdraw++;
247246
248247         // we need to draw this line again, so restore our pointers to previous values
249         state->m_aoffset = temp_aoffset;
250         state->m_boffset = temp_boffset;
248         m_aoffset = temp_aoffset;
249         m_boffset = temp_boffset;
251250
252251         if (!(flip & 0x02))
253252            ydrawpos = ypos + ycntdraw;
r21060r21061
258257         {
259258            dest = &bitmap.pix16(ydrawpos);
260259            destpri = &priority_bitmap.pix8(ydrawpos);
261            draw_sprite_line(machine, wide, dest, destpri, xzoom, xgrow, flip, xpos, pri, realxsize, palt, 1);
260            draw_sprite_line(wide, dest, destpri, xzoom, xgrow, flip, xpos, pri, realxsize, palt, 1);
262261         }
263262         else
264263         {
265            draw_sprite_line(machine, wide, NULL, NULL, xzoom, xgrow, flip, xpos, pri, realxsize, palt, 0);
264            draw_sprite_line(wide, NULL, NULL, xzoom, xgrow, flip, xpos, pri, realxsize, palt, 0);
266265
267266            if (!(flip & 0x02))
268267            {
r21060r21061
282281      else if (yzoombit == 1 && ygrow == 0)
283282      {
284283         /* skip this line */
285         draw_sprite_line(machine, wide, NULL, NULL, xzoom, xgrow, flip, xpos, pri, realxsize, palt, 0);
284         draw_sprite_line(wide, NULL, NULL, xzoom, xgrow, flip, xpos, pri, realxsize, palt, 0);
286285      }
287286      else /* normal line */
288287      {
r21060r21061
295294         {
296295            dest = &bitmap.pix16(ydrawpos);
297296            destpri = &priority_bitmap.pix8(ydrawpos);
298            draw_sprite_line(machine, wide, dest, destpri, xzoom, xgrow, flip, xpos, pri, realxsize, palt, 1);
297            draw_sprite_line(wide, dest, destpri, xzoom, xgrow, flip, xpos, pri, realxsize, palt, 1);
299298         }
300299         else
301300         {
302            draw_sprite_line(machine, wide, NULL, NULL, xzoom, xgrow, flip, xpos, pri, realxsize, palt, 0);
301            draw_sprite_line(wide, NULL, NULL, xzoom, xgrow, flip, xpos, pri, realxsize, palt, 0);
303302
304303            if (!(flip & 0x02))
305304            {
r21060r21061
322321}
323322
324323
325static void draw_sprite_line_basic( running_machine &machine, int wide, UINT16* dest, UINT8* destpri, int flip, int xpos, int pri, int realxsize, int palt, int draw )
324void pgm_state::draw_sprite_line_basic( int wide, UINT16* dest, UINT8* destpri, int flip, int xpos, int pri, int realxsize, int palt, int draw )
326325{
327   pgm_state *state = machine.driver_data<pgm_state>();
328326   int xcnt,xcntdraw;
329327   int xoffset = 0;
330328   int xdrawpos = 0;
331   UINT8 *adata = state->m_sprite_a_region;
332   size_t  adatasize = state->m_sprite_a_region_size - 1;
329   UINT8 *adata = m_sprite_a_region;
330   size_t  adatasize = m_sprite_a_region_size - 1;
333331
334332   UINT16 msk;
335333   UINT16 srcdat;
r21060r21061
343341      {
344342         int x;
345343
346         msk = ((state->m_bdata[(state->m_boffset + 1) & state->m_bdatasize] << 8) |( state->m_bdata[(state->m_boffset + 0) & state->m_bdatasize] << 0));
344         msk = ((m_bdata[(m_boffset + 1) & m_bdatasize] << 8) |( m_bdata[(m_boffset + 0) & m_bdatasize] << 0));
347345
348346         for (x = 0; x < 16; x++)
349347         {
350348            if (!(msk & 0x0001))
351349            {
352               srcdat = adata[state->m_aoffset & adatasize] + palt * 32;
353               state->m_aoffset++;
350               srcdat = adata[m_aoffset & adatasize] + palt * 32;
351               m_aoffset++;
354352
355353               if (draw)
356354               {
r21060r21061
376374            msk >>= 1;
377375         }
378376
379         state->m_boffset += 2;
377         m_boffset += 2;
380378      }
381379   }
382380   else
r21060r21061
385383      {
386384         int x;
387385
388         msk = ((state->m_bdata[(state->m_boffset + 1) & state->m_bdatasize] << 8) |( state->m_bdata[(state->m_boffset + 0) & state->m_bdatasize] << 0));
386         msk = ((m_bdata[(m_boffset + 1) & m_bdatasize] << 8) |( m_bdata[(m_boffset + 0) & m_bdatasize] << 0));
389387
390388         for (x = 0; x < 16; x++)
391389         {
392390            if (!(msk & 0x0001))
393391            {
394               srcdat = adata[state->m_aoffset & adatasize] + palt * 32;
395               state->m_aoffset++;
392               srcdat = adata[m_aoffset & adatasize] + palt * 32;
393               m_aoffset++;
396394
397395               if (draw)
398396               {
r21060r21061
418416            msk >>= 1;
419417         }
420418
421         state->m_boffset += 2;
419         m_boffset += 2;
422420      }
423421   }
424422}
r21060r21061
428426  simplified version for non-zoomed cases, a bit faster
429427*************************************************************************/
430428
431static void draw_sprite_new_basic( pgm_state *state, running_machine &machine, int wide, int high, int xpos, int ypos, int palt, int flip, bitmap_ind16 &bitmap, bitmap_ind8 &priority_bitmap, int pri )
429void pgm_state::draw_sprite_new_basic( int wide, int high, int xpos, int ypos, int palt, int flip, bitmap_ind16 &bitmap, bitmap_ind8 &priority_bitmap, int pri )
432430{
433431   int ycnt;
434432   int ydrawpos;
r21060r21061
436434   UINT8* destpri;
437435   int ycntdraw;
438436
439   state->m_aoffset = (state->m_bdata[(state->m_boffset + 3) & state->m_bdatasize] << 24) | (state->m_bdata[(state->m_boffset + 2) & state->m_bdatasize] << 16) |
440            (state->m_bdata[(state->m_boffset + 1) & state->m_bdatasize] << 8) | (state->m_bdata[(state->m_boffset + 0) & state->m_bdatasize] << 0);
441   state->m_aoffset = state->m_aoffset >> 2; state->m_aoffset *= 3;
437   m_aoffset = (m_bdata[(m_boffset + 3) & m_bdatasize] << 24) | (m_bdata[(m_boffset + 2) & m_bdatasize] << 16) |
438            (m_bdata[(m_boffset + 1) & m_bdatasize] << 8) | (m_bdata[(m_boffset + 0) & m_bdatasize] << 0);
439   m_aoffset = m_aoffset >> 2; m_aoffset *= 3;
442440
443   state->m_boffset+=4;
441   m_boffset+=4;
444442
445443   int realysize = high-1;
446444   int realxsize = (wide * 16)-1;
r21060r21061
460458      {
461459         dest = &bitmap.pix16(ydrawpos);
462460         destpri = &priority_bitmap.pix8(ydrawpos);
463         draw_sprite_line_basic(machine, wide, dest, destpri, flip, xpos, pri, realxsize, palt, 1);
461         draw_sprite_line_basic(wide, dest, destpri, flip, xpos, pri, realxsize, palt, 1);
464462      }
465463      else
466464      {
467         draw_sprite_line_basic(machine, wide, NULL, NULL, flip, xpos, pri, realxsize, palt, 0);
465         draw_sprite_line_basic(wide, NULL, NULL, flip, xpos, pri, realxsize, palt, 0);
468466
469467         if (!(flip & 0x02))
470468         {
r21060r21061
484482}
485483
486484
487static void draw_sprites( pgm_state *state, running_machine &machine, bitmap_ind16& spritebitmap, UINT16 *sprite_source, bitmap_ind8& priority_bitmap )
485void pgm_state::draw_sprites( bitmap_ind16& spritebitmap, UINT16 *sprite_source, bitmap_ind8& priority_bitmap )
488486{
489487   /* ZZZZ Zxxx xxxx xxxx
490488      zzzz z-yy yyyy yyyy
r21060r21061
493491      wwww wwwh hhhh hhhh
494492   */
495493
496   const UINT16 *finish = state->m_spritebufferram + (0xa00 / 2);
494   const UINT16 *finish = m_spritebufferram + (0xa00 / 2);
497495
498496   UINT16* start = sprite_source;
499497
r21060r21061
521519
522520      UINT32 xzoom, yzoom;
523521
524      UINT16* sprite_zoomtable = &state->m_videoregs[0x1000 / 2];
522      UINT16* sprite_zoomtable = &m_videoregs[0x1000 / 2];
525523
526524      if (xgrow)
527525      {
r21060r21061
544542
545543      //if ((priority == 1) && (pri == 0)) break;
546544
547      state->m_boffset = boff;
548      if ((!xzoom) && (!yzoom)) draw_sprite_new_basic(state, machine, wide, high, xpos, ypos, palt, flip, spritebitmap, priority_bitmap, pri );
549      else draw_sprite_new_zoomed(state, machine, wide, high, xpos, ypos, palt, flip, spritebitmap, priority_bitmap, xzoom, xgrow, yzoom, ygrow, pri );
545      m_boffset = boff;
546      if ((!xzoom) && (!yzoom)) draw_sprite_new_basic(wide, high, xpos, ypos, palt, flip, spritebitmap, priority_bitmap, pri );
547      else draw_sprite_new_zoomed(wide, high, xpos, ypos, palt, flip, spritebitmap, priority_bitmap, xzoom, xgrow, yzoom, ygrow, pri );
550548
551549      sprite_source -= 5;
552550   }
r21060r21061
650648
651649   m_bg_tilemap->draw(bitmap, cliprect, 0, 2);
652650
653   draw_sprites(this, machine(), bitmap, m_spritebufferram, machine().priority_bitmap);
651   draw_sprites(bitmap, m_spritebufferram, machine().priority_bitmap);
654652
655653   m_tx_tilemap->set_scrolly(0, m_videoregs[0x5000/2]);
656654   m_tx_tilemap->set_scrollx(0, m_videoregs[0x6000/2]); // Check

Previous 199869 Revisions Next


© 1997-2024 The MAME Team