Previous 199869 Revisions Next

r21156 Monday 18th February, 2013 at 07:13:31 UTC by Miodrag Milanović
neogeo modernize (nw)
[src/mame/drivers]neodrvr.c neogeo.c
[src/mame/includes]neogeo.h
[src/mame/machine]neoboot.c neocrypt.c neoprot.c
[src/mess/drivers]ng_aes.c

trunk/src/mess/drivers/ng_aes.c
r21155r21156
11751175
11761176   m_maincpu->reset();
11771177
1178   neogeo_reset_rng(machine());
1178   neogeo_reset_rng();
11791179
11801180   start_interrupt_timers();
11811181
trunk/src/mame/drivers/neodrvr.c
r21155r21156
92899289DRIVER_INIT_MEMBER(neogeo_state,fatfury2)
92909290{
92919291   DRIVER_INIT_CALL(neogeo);
9292   fatfury2_install_protection(machine());
9292   fatfury2_install_protection();
92939293}
92949294
92959295DRIVER_INIT_MEMBER(neogeo_state,zupapa)
92969296{
92979297   DRIVER_INIT_CALL(neogeo);
92989298   m_fixed_layer_bank_type = 1;
9299   kof99_neogeo_gfx_decrypt(machine(), 0xbd);
9299   kof99_neogeo_gfx_decrypt(0xbd);
93009300}
93019301
93029302DRIVER_INIT_MEMBER(neogeo_state,kof98)
93039303{
93049304   DRIVER_INIT_CALL(neogeo);
9305   kof98_decrypt_68k(machine());
9306   install_kof98_protection(machine());
9305   kof98_decrypt_68k();
9306   install_kof98_protection();
93079307}
93089308
93099309DRIVER_INIT_MEMBER(neogeo_state,mslugx)
93109310{
93119311   DRIVER_INIT_CALL(neogeo);
9312   mslugx_install_protection(machine());
9312   mslugx_install_protection();
93139313}
93149314
93159315DRIVER_INIT_MEMBER(neogeo_state,kof99)
93169316{
93179317   DRIVER_INIT_CALL(neogeo);
9318   kof99_decrypt_68k(machine());
9318   kof99_decrypt_68k();
93199319   m_fixed_layer_bank_type = 1;
9320   kof99_neogeo_gfx_decrypt(machine(), 0x00);
9321   kof99_install_protection(machine());
9320   kof99_neogeo_gfx_decrypt(0x00);
9321   kof99_install_protection();
93229322}
93239323
93249324DRIVER_INIT_MEMBER(neogeo_state,kof99k)
93259325{
93269326   DRIVER_INIT_CALL(neogeo);
93279327   m_fixed_layer_bank_type = 1;
9328   kof99_neogeo_gfx_decrypt(machine(), 0x00);
9328   kof99_neogeo_gfx_decrypt(0x00);
93299329}
93309330
93319331DRIVER_INIT_MEMBER(neogeo_state,garou)
93329332{
93339333   DRIVER_INIT_CALL(neogeo);
9334   garou_decrypt_68k(machine());
9334   garou_decrypt_68k();
93359335   m_fixed_layer_bank_type = 1;
9336   kof99_neogeo_gfx_decrypt(machine(), 0x06);
9337   garou_install_protection(machine());
9336   kof99_neogeo_gfx_decrypt(0x06);
9337   garou_install_protection();
93389338}
93399339
93409340DRIVER_INIT_MEMBER(neogeo_state,garouh)
93419341{
93429342   DRIVER_INIT_CALL(neogeo);
9343   garouh_decrypt_68k(machine());
9343   garouh_decrypt_68k();
93449344   m_fixed_layer_bank_type = 1;
9345   kof99_neogeo_gfx_decrypt(machine(), 0x06);
9346   garouh_install_protection(machine());
9345   kof99_neogeo_gfx_decrypt(0x06);
9346   garouh_install_protection();
93479347}
93489348
93499349DRIVER_INIT_MEMBER(neogeo_state,garoubl)
93509350{
93519351   DRIVER_INIT_CALL(neogeo);
9352   neogeo_bootleg_sx_decrypt(machine(), 2);
9353   neogeo_bootleg_cx_decrypt(machine());
9352   neogeo_bootleg_sx_decrypt(2);
9353   neogeo_bootleg_cx_decrypt();
93549354}
93559355
93569356DRIVER_INIT_MEMBER(neogeo_state,mslug3)
93579357{
93589358   DRIVER_INIT_CALL(neogeo);
9359   mslug3_decrypt_68k(machine());
9359   mslug3_decrypt_68k();
93609360   m_fixed_layer_bank_type = 1;
9361   kof99_neogeo_gfx_decrypt(machine(), 0xad);
9362   mslug3_install_protection(machine());
9361   kof99_neogeo_gfx_decrypt(0xad);
9362   mslug3_install_protection();
93639363}
93649364
93659365DRIVER_INIT_MEMBER(neogeo_state,mslug3h)
93669366{
93679367   DRIVER_INIT_CALL(neogeo);
93689368   m_fixed_layer_bank_type = 1;
9369   kof99_neogeo_gfx_decrypt(machine(), 0xad);
9369   kof99_neogeo_gfx_decrypt(0xad);
93709370}
93719371
93729372DRIVER_INIT_MEMBER(neogeo_state,mslug3b6)
93739373{
93749374   DRIVER_INIT_CALL(neogeo);
9375   neogeo_bootleg_sx_decrypt(machine(), 2);
9376   cmc42_neogeo_gfx_decrypt(machine(), 0xad);
9375   neogeo_bootleg_sx_decrypt(2);
9376   cmc42_neogeo_gfx_decrypt(0xad);
93779377}
93789378
93799379DRIVER_INIT_MEMBER(neogeo_state,kof2000)
93809380{
93819381   DRIVER_INIT_CALL(neogeo);
9382   kof2000_decrypt_68k(machine());
9382   kof2000_decrypt_68k();
93839383   m_fixed_layer_bank_type = 2;
9384   neogeo_cmc50_m1_decrypt(machine());
9385   kof2000_neogeo_gfx_decrypt(machine(), 0x00);
9386   kof2000_install_protection(machine());
9384   neogeo_cmc50_m1_decrypt();
9385   kof2000_neogeo_gfx_decrypt(0x00);
9386   kof2000_install_protection();
93879387}
93889388
93899389DRIVER_INIT_MEMBER(neogeo_state,kof2000n)
93909390{
93919391   DRIVER_INIT_CALL(neogeo);
93929392   m_fixed_layer_bank_type = 2;
9393   neogeo_cmc50_m1_decrypt(machine());
9394   kof2000_neogeo_gfx_decrypt(machine(), 0x00);
9393   neogeo_cmc50_m1_decrypt();
9394   kof2000_neogeo_gfx_decrypt(0x00);
93959395}
93969396
93979397DRIVER_INIT_MEMBER(neogeo_state,kof2001)
93989398{
93999399   DRIVER_INIT_CALL(neogeo);
94009400   m_fixed_layer_bank_type = 1;
9401   kof2000_neogeo_gfx_decrypt(machine(), 0x1e);
9402   neogeo_cmc50_m1_decrypt(machine());
9401   kof2000_neogeo_gfx_decrypt(0x1e);
9402   neogeo_cmc50_m1_decrypt();
94039403}
94049404
94059405DRIVER_INIT_MEMBER(neogeo_state,cthd2003)
94069406{
94079407   DRIVER_INIT_CALL(neogeo);
9408   decrypt_cthd2003(machine());
9409   patch_cthd2003(machine());
9408   decrypt_cthd2003();
9409   patch_cthd2003();
94109410}
94119411
94129412DRIVER_INIT_MEMBER(neogeo_state,ct2k3sp)
94139413{
94149414   DRIVER_INIT_CALL(neogeo);
9415   decrypt_ct2k3sp(machine());
9416   patch_cthd2003(machine());
9415   decrypt_ct2k3sp();
9416   patch_cthd2003();
94179417}
94189418
94199419DRIVER_INIT_MEMBER(neogeo_state,ct2k3sa)
94209420{
94219421   DRIVER_INIT_CALL(neogeo);
9422   decrypt_ct2k3sa(machine());
9423   patch_ct2k3sa(machine());
9422   decrypt_ct2k3sa();
9423   patch_ct2k3sa();
94249424}
94259425
94269426DRIVER_INIT_MEMBER(neogeo_state,mslug4)
94279427{
94289428   DRIVER_INIT_CALL(neogeo);
94299429   m_fixed_layer_bank_type = 1; /* USA violent content screen is wrong -- not a bug, confirmed on real hardware! */
9430   neogeo_cmc50_m1_decrypt(machine());
9431   kof2000_neogeo_gfx_decrypt(machine(), 0x31);
9432   neo_pcm2_snk_1999(machine(), 8);
9430   neogeo_cmc50_m1_decrypt();
9431   kof2000_neogeo_gfx_decrypt(0x31);
9432   neo_pcm2_snk_1999(8);
94339433}
94349434
94359435DRIVER_INIT_MEMBER(neogeo_state,ms4plus)
94369436{
94379437   DRIVER_INIT_CALL(neogeo);
9438   cmc50_neogeo_gfx_decrypt(machine(), 0x31);
9439   neo_pcm2_snk_1999(machine(), 8);
9440   neogeo_cmc50_m1_decrypt(machine());
9438   cmc50_neogeo_gfx_decrypt(0x31);
9439   neo_pcm2_snk_1999(8);
9440   neogeo_cmc50_m1_decrypt();
94419441}
94429442
94439443DRIVER_INIT_MEMBER(neogeo_state,ganryu)
94449444{
94459445   DRIVER_INIT_CALL(neogeo);
94469446   m_fixed_layer_bank_type = 1;
9447   kof99_neogeo_gfx_decrypt(machine(), 0x07);
9447   kof99_neogeo_gfx_decrypt(0x07);
94489448}
94499449
94509450DRIVER_INIT_MEMBER(neogeo_state,s1945p)
94519451{
94529452   DRIVER_INIT_CALL(neogeo);
94539453   m_fixed_layer_bank_type = 1;
9454   kof99_neogeo_gfx_decrypt(machine(), 0x05);
9454   kof99_neogeo_gfx_decrypt(0x05);
94559455}
94569456
94579457DRIVER_INIT_MEMBER(neogeo_state,preisle2)
94589458{
94599459   DRIVER_INIT_CALL(neogeo);
94609460   m_fixed_layer_bank_type = 1;
9461   kof99_neogeo_gfx_decrypt(machine(), 0x9f);
9461   kof99_neogeo_gfx_decrypt(0x9f);
94629462}
94639463
94649464DRIVER_INIT_MEMBER(neogeo_state,bangbead)
94659465{
94669466   DRIVER_INIT_CALL(neogeo);
94679467   m_fixed_layer_bank_type = 1;
9468   kof99_neogeo_gfx_decrypt(machine(), 0xf8);
9468   kof99_neogeo_gfx_decrypt(0xf8);
94699469}
94709470
94719471DRIVER_INIT_MEMBER(neogeo_state,nitd)
94729472{
94739473   DRIVER_INIT_CALL(neogeo);
94749474   m_fixed_layer_bank_type = 1;
9475   kof99_neogeo_gfx_decrypt(machine(), 0xff);
9475   kof99_neogeo_gfx_decrypt(0xff);
94769476}
94779477
94789478DRIVER_INIT_MEMBER(neogeo_state,sengoku3)
94799479{
94809480   DRIVER_INIT_CALL(neogeo);
94819481   m_fixed_layer_bank_type = 1;
9482   kof99_neogeo_gfx_decrypt(machine(), 0xfe);
9482   kof99_neogeo_gfx_decrypt(0xfe);
94839483}
94849484
94859485DRIVER_INIT_MEMBER(neogeo_state,rotd)
94869486{
94879487   DRIVER_INIT_CALL(neogeo);
9488   neo_pcm2_snk_1999(machine(), 16);
9488   neo_pcm2_snk_1999(16);
94899489   m_fixed_layer_bank_type = 1;
9490   neogeo_cmc50_m1_decrypt(machine());
9491   kof2000_neogeo_gfx_decrypt(machine(), 0x3f);
9490   neogeo_cmc50_m1_decrypt();
9491   kof2000_neogeo_gfx_decrypt(0x3f);
94929492}
94939493
94949494DRIVER_INIT_MEMBER(neogeo_state,kof2002)
94959495{
94969496   DRIVER_INIT_CALL(neogeo);
9497   kof2002_decrypt_68k(machine());
9498   neo_pcm2_swap(machine(), 0);
9499   neogeo_cmc50_m1_decrypt(machine());
9500   kof2000_neogeo_gfx_decrypt(machine(), 0xec);
9497   kof2002_decrypt_68k();
9498   neo_pcm2_swap(0);
9499   neogeo_cmc50_m1_decrypt();
9500   kof2000_neogeo_gfx_decrypt(0xec);
95019501}
95029502
95039503DRIVER_INIT_MEMBER(neogeo_state,kof2002b)
95049504{
95059505   DRIVER_INIT_CALL(neogeo);
9506   kof2002_decrypt_68k(machine());
9507   neo_pcm2_swap(machine(), 0);
9508   neogeo_cmc50_m1_decrypt(machine());
9509   kof2002b_gfx_decrypt(machine(), memregion("sprites")->base(),0x4000000);
9510   kof2002b_gfx_decrypt(machine(), memregion("fixed")->base(),0x20000);
9506   kof2002_decrypt_68k();
9507   neo_pcm2_swap(0);
9508   neogeo_cmc50_m1_decrypt();
9509   kof2002b_gfx_decrypt(memregion("sprites")->base(),0x4000000);
9510   kof2002b_gfx_decrypt(memregion("fixed")->base(),0x20000);
95119511}
95129512
95139513DRIVER_INIT_MEMBER(neogeo_state,kf2k2pls)
95149514{
95159515   DRIVER_INIT_CALL(neogeo);
9516   kof2002_decrypt_68k(machine());
9517   neo_pcm2_swap(machine(), 0);
9518   neogeo_cmc50_m1_decrypt(machine());
9519   cmc50_neogeo_gfx_decrypt(machine(), 0xec);
9516   kof2002_decrypt_68k();
9517   neo_pcm2_swap(0);
9518   neogeo_cmc50_m1_decrypt();
9519   cmc50_neogeo_gfx_decrypt(0xec);
95209520}
95219521
95229522DRIVER_INIT_MEMBER(neogeo_state,kf2k2mp)
95239523{
95249524   DRIVER_INIT_CALL(neogeo);
9525   kf2k2mp_decrypt(machine());
9526   neo_pcm2_swap(machine(), 0);
9527   neogeo_cmc50_m1_decrypt(machine());
9528   neogeo_bootleg_sx_decrypt(machine(), 2);
9529   cmc50_neogeo_gfx_decrypt(machine(), 0xec);
9525   kf2k2mp_decrypt();
9526   neo_pcm2_swap(0);
9527   neogeo_cmc50_m1_decrypt();
9528   neogeo_bootleg_sx_decrypt(2);
9529   cmc50_neogeo_gfx_decrypt(0xec);
95309530}
95319531
95329532DRIVER_INIT_MEMBER(neogeo_state,kf2k2mp2)
95339533{
95349534   DRIVER_INIT_CALL(neogeo);
9535   kf2k2mp2_px_decrypt(machine());
9536   neo_pcm2_swap(machine(), 0);
9537   neogeo_cmc50_m1_decrypt(machine());
9538   neogeo_bootleg_sx_decrypt(machine(), 1);
9539   cmc50_neogeo_gfx_decrypt(machine(), 0xec);
9535   kf2k2mp2_px_decrypt();
9536   neo_pcm2_swap(0);
9537   neogeo_cmc50_m1_decrypt();
9538   neogeo_bootleg_sx_decrypt(1);
9539   cmc50_neogeo_gfx_decrypt(0xec);
95409540}
95419541
95429542DRIVER_INIT_MEMBER(neogeo_state,kof10th)
95439543{
95449544   DRIVER_INIT_CALL(neogeo);
9545   decrypt_kof10th(machine());
9546   install_kof10th_protection(machine());
9545   decrypt_kof10th();
9546   install_kof10th_protection();
95479547}
95489548
95499549DRIVER_INIT_MEMBER(neogeo_state,kf10thep)
95509550{
95519551   DRIVER_INIT_CALL(neogeo);
9552   decrypt_kf10thep(machine());
9552   decrypt_kf10thep();
95539553}
95549554
95559555DRIVER_INIT_MEMBER(neogeo_state,kf2k5uni)
95569556{
95579557   DRIVER_INIT_CALL(neogeo);
9558   decrypt_kf2k5uni(machine());
9558   decrypt_kf2k5uni();
95599559}
95609560
95619561DRIVER_INIT_MEMBER(neogeo_state,kof2k4se)
95629562{
95639563   DRIVER_INIT_CALL(neogeo);
9564   decrypt_kof2k4se_68k(machine());
9564   decrypt_kof2k4se_68k();
95659565}
95669566
95679567DRIVER_INIT_MEMBER(neogeo_state,matrim)
95689568{
95699569   DRIVER_INIT_CALL(neogeo);
9570   matrim_decrypt_68k(machine());
9571   neo_pcm2_swap(machine(), 1);
9570   matrim_decrypt_68k();
9571   neo_pcm2_swap(1);
95729572   m_fixed_layer_bank_type = 2;
9573   neogeo_cmc50_m1_decrypt(machine());
9574   kof2000_neogeo_gfx_decrypt(machine(), 0x6a);
9573   neogeo_cmc50_m1_decrypt();
9574   kof2000_neogeo_gfx_decrypt(0x6a);
95759575}
95769576
95779577DRIVER_INIT_MEMBER(neogeo_state,matrimbl)
95789578{
95799579   DRIVER_INIT_CALL(neogeo);
9580   matrim_decrypt_68k(machine());
9580   matrim_decrypt_68k();
95819581   m_fixed_layer_bank_type = 2;
9582   matrimbl_decrypt(machine());
9583   neogeo_sfix_decrypt(machine()); /* required for text layer */
9582   matrimbl_decrypt();
9583   neogeo_sfix_decrypt(); /* required for text layer */
95849584}
95859585
95869586DRIVER_INIT_MEMBER(neogeo_state,pnyaa)
95879587{
95889588   DRIVER_INIT_CALL(neogeo);
9589   neo_pcm2_snk_1999(machine(), 4);
9589   neo_pcm2_snk_1999(4);
95909590   m_fixed_layer_bank_type = 1;
9591   neogeo_cmc50_m1_decrypt(machine());
9592   kof2000_neogeo_gfx_decrypt(machine(), 0x2e);
9591   neogeo_cmc50_m1_decrypt();
9592   kof2000_neogeo_gfx_decrypt(0x2e);
95939593}
95949594
95959595DRIVER_INIT_MEMBER(neogeo_state,mslug5)
95969596{
95979597   DRIVER_INIT_CALL(neogeo);
9598   mslug5_decrypt_68k(machine());
9599   neo_pcm2_swap(machine(), 2);
9598   mslug5_decrypt_68k();
9599   neo_pcm2_swap(2);
96009600   m_fixed_layer_bank_type = 1;
9601   neogeo_cmc50_m1_decrypt(machine());
9602   kof2000_neogeo_gfx_decrypt(machine(), 0x19);
9603   install_pvc_protection(machine());
9601   neogeo_cmc50_m1_decrypt();
9602   kof2000_neogeo_gfx_decrypt(0x19);
9603   install_pvc_protection();
96049604}
96059605
9606static TIMER_CALLBACK( ms5pcb_bios_timer_callback )
9606TIMER_CALLBACK_MEMBER(neogeo_state::ms5pcb_bios_timer_callback)
96079607{
9608   int harddip3 = machine.root_device().ioport("HARDDIP")->read() & 1;
9609   machine.root_device().membank(NEOGEO_BANK_BIOS)->set_base(machine.root_device().memregion("mainbios")->base() + 0x20000 + harddip3 * 0x20000);
9608   int harddip3 = ioport("HARDDIP")->read() & 1;
9609   membank(NEOGEO_BANK_BIOS)->set_base(memregion("mainbios")->base() + 0x20000 + harddip3 * 0x20000);
96109610}
96119611
96129612DRIVER_INIT_MEMBER(neogeo_state,ms5pcb)
r21155r21156
96149614   DRIVER_INIT_CALL(neogeo);
96159615
96169616   /* start a timer that will check the BIOS select DIP every second */
9617   machine().scheduler().timer_set(attotime::zero, FUNC(ms5pcb_bios_timer_callback));
9618   machine().scheduler().timer_pulse(attotime::from_msec(1000), FUNC(ms5pcb_bios_timer_callback));
9617   machine().scheduler().timer_set(attotime::zero, timer_expired_delegate(FUNC(neogeo_state::ms5pcb_bios_timer_callback),this));
9618   machine().scheduler().timer_pulse(attotime::from_msec(1000), timer_expired_delegate(FUNC(neogeo_state::ms5pcb_bios_timer_callback),this));
96199619
9620   mslug5_decrypt_68k(machine());
9621   svcpcb_gfx_decrypt(machine());
9622   neogeo_cmc50_m1_decrypt(machine());
9623   kof2000_neogeo_gfx_decrypt(machine(), 0x19);
9620   mslug5_decrypt_68k();
9621   svcpcb_gfx_decrypt();
9622   neogeo_cmc50_m1_decrypt();
9623   kof2000_neogeo_gfx_decrypt(0x19);
96249624   m_fixed_layer_bank_type = 2;
9625   svcpcb_s1data_decrypt(machine());
9626   neo_pcm2_swap(machine(), 2);
9627   install_pvc_protection(machine());
9625   svcpcb_s1data_decrypt();
9626   neo_pcm2_swap(2);
9627   install_pvc_protection();
96289628}
96299629
96309630DRIVER_INIT_MEMBER(neogeo_state,ms5plus)
96319631{
96329632   DRIVER_INIT_CALL(neogeo);
9633   cmc50_neogeo_gfx_decrypt(machine(), 0x19);
9634   neo_pcm2_swap(machine(), 2);
9635   neogeo_bootleg_sx_decrypt(machine(), 1);
9633   cmc50_neogeo_gfx_decrypt(0x19);
9634   neo_pcm2_swap(2);
9635   neogeo_bootleg_sx_decrypt(1);
96369636   m_fixed_layer_bank_type = 1;
9637   neogeo_cmc50_m1_decrypt(machine());
9638   install_ms5plus_protection(machine());
9637   neogeo_cmc50_m1_decrypt();
9638   install_ms5plus_protection();
96399639}
96409640
9641static TIMER_CALLBACK( svcpcb_bios_timer_callback )
9641TIMER_CALLBACK_MEMBER(neogeo_state::svcpcb_bios_timer_callback)
96429642{
9643   int harddip3 = machine.root_device().ioport("HARDDIP")->read() & 1;
9644   machine.root_device().membank(NEOGEO_BANK_BIOS)->set_base(machine.root_device().memregion("mainbios")->base() + 0x20000 + harddip3 * 0x20000);
9643   int harddip3 = ioport("HARDDIP")->read() & 1;
9644   membank(NEOGEO_BANK_BIOS)->set_base(memregion("mainbios")->base() + 0x20000 + harddip3 * 0x20000);
96459645}
96469646
96479647DRIVER_INIT_MEMBER(neogeo_state,svcpcb)
r21155r21156
96499649   DRIVER_INIT_CALL(neogeo);
96509650
96519651   /* start a timer that will check the BIOS select DIP every second */
9652   machine().scheduler().timer_set(attotime::zero, FUNC(svcpcb_bios_timer_callback));
9653   machine().scheduler().timer_pulse(attotime::from_msec(1000), FUNC(svcpcb_bios_timer_callback));
9652   machine().scheduler().timer_set(attotime::zero, timer_expired_delegate(FUNC(neogeo_state::svcpcb_bios_timer_callback),this));
9653   machine().scheduler().timer_pulse(attotime::from_msec(1000), timer_expired_delegate(FUNC(neogeo_state::svcpcb_bios_timer_callback),this));
96549654
9655   svc_px_decrypt(machine());
9656   svcpcb_gfx_decrypt(machine());
9657   neogeo_cmc50_m1_decrypt(machine());
9658   kof2000_neogeo_gfx_decrypt(machine(), 0x57);
9659   svcpcb_s1data_decrypt(machine());
9660   neo_pcm2_swap(machine(), 3);
9655   svc_px_decrypt();
9656   svcpcb_gfx_decrypt();
9657   neogeo_cmc50_m1_decrypt();
9658   kof2000_neogeo_gfx_decrypt(0x57);
9659   svcpcb_s1data_decrypt();
9660   neo_pcm2_swap(3);
96619661   m_fixed_layer_bank_type = 2;
9662   install_pvc_protection(machine());
9662   install_pvc_protection();
96639663}
96649664
96659665DRIVER_INIT_MEMBER(neogeo_state,svc)
96669666{
96679667   DRIVER_INIT_CALL(neogeo);
9668   svc_px_decrypt(machine());
9669   neo_pcm2_swap(machine(), 3);
9668   svc_px_decrypt();
9669   neo_pcm2_swap(3);
96709670   m_fixed_layer_bank_type = 2;
9671   neogeo_cmc50_m1_decrypt(machine());
9672   kof2000_neogeo_gfx_decrypt(machine(), 0x57);
9673   install_pvc_protection(machine());
9671   neogeo_cmc50_m1_decrypt();
9672   kof2000_neogeo_gfx_decrypt(0x57);
9673   install_pvc_protection();
96749674}
96759675
96769676DRIVER_INIT_MEMBER(neogeo_state,svcboot)
96779677{
96789678   DRIVER_INIT_CALL(neogeo);
9679   svcboot_px_decrypt(machine());
9680   svcboot_cx_decrypt(machine());
9681   install_pvc_protection(machine());
9679   svcboot_px_decrypt();
9680   svcboot_cx_decrypt();
9681   install_pvc_protection();
96829682}
96839683
96849684DRIVER_INIT_MEMBER(neogeo_state,svcplus)
96859685{
96869686   DRIVER_INIT_CALL(neogeo);
9687   svcplus_px_decrypt(machine());
9688   svcboot_cx_decrypt(machine());
9689   neogeo_bootleg_sx_decrypt(machine(), 1);
9690   svcplus_px_hack(machine());
9687   svcplus_px_decrypt();
9688   svcboot_cx_decrypt();
9689   neogeo_bootleg_sx_decrypt( 1);
9690   svcplus_px_hack();
96919691}
96929692
96939693DRIVER_INIT_MEMBER(neogeo_state,svcplusa)
96949694{
96959695   DRIVER_INIT_CALL(neogeo);
9696   svcplusa_px_decrypt(machine());
9697   svcboot_cx_decrypt(machine());
9698   svcplus_px_hack(machine());
9696   svcplusa_px_decrypt();
9697   svcboot_cx_decrypt();
9698   svcplus_px_hack();
96999699}
97009700
97019701DRIVER_INIT_MEMBER(neogeo_state,svcsplus)
97029702{
97039703   DRIVER_INIT_CALL(neogeo);
9704   svcsplus_px_decrypt(machine());
9705   neogeo_bootleg_sx_decrypt(machine(), 2);
9706   svcboot_cx_decrypt(machine());
9707   svcsplus_px_hack(machine());
9708   install_pvc_protection(machine());
9704   svcsplus_px_decrypt();
9705   neogeo_bootleg_sx_decrypt(2);
9706   svcboot_cx_decrypt();
9707   svcsplus_px_hack();
9708   install_pvc_protection();
97099709}
97109710
97119711DRIVER_INIT_MEMBER(neogeo_state,samsho5)
97129712{
97139713   DRIVER_INIT_CALL(neogeo);
9714   samsho5_decrypt_68k(machine());
9715   neo_pcm2_swap(machine(), 4);
9714   samsho5_decrypt_68k();
9715   neo_pcm2_swap(4);
97169716   m_fixed_layer_bank_type = 1;
9717   neogeo_cmc50_m1_decrypt(machine());
9718   kof2000_neogeo_gfx_decrypt(machine(), 0x0f);
9717   neogeo_cmc50_m1_decrypt();
9718   kof2000_neogeo_gfx_decrypt(0x0f);
97199719}
97209720
97219721DRIVER_INIT_MEMBER(neogeo_state,samsho5b)
97229722{
97239723   DRIVER_INIT_CALL(neogeo);
9724   samsho5b_px_decrypt(machine());
9725   samsho5b_vx_decrypt(machine());
9726   neogeo_bootleg_sx_decrypt(machine(), 1);
9727   neogeo_bootleg_cx_decrypt(machine());
9724   samsho5b_px_decrypt();
9725   samsho5b_vx_decrypt();
9726   neogeo_bootleg_sx_decrypt(1);
9727   neogeo_bootleg_cx_decrypt();
97289728}
97299729
97309730DRIVER_INIT_MEMBER(neogeo_state,kf2k3pcb)
97319731{
97329732   DRIVER_INIT_CALL(neogeo);
9733   kf2k3pcb_decrypt_68k(machine());
9734   kf2k3pcb_gfx_decrypt(machine());
9735   kof2003biosdecode(machine());
9736   neogeo_cmc50_m1_decrypt(machine());
9733   kf2k3pcb_decrypt_68k();
9734   kf2k3pcb_gfx_decrypt();
9735   kof2003biosdecode();
9736   neogeo_cmc50_m1_decrypt();
97379737
97389738   /* extra little swap on the m1 - this must be performed AFTER the m1 decrypt
97399739      or the m1 checksum (used to generate the key) for decrypting the m1 is
r21155r21156
97479747      }
97489748   }
97499749
9750   kof2000_neogeo_gfx_decrypt(machine(), 0x9d);
9751   kf2k3pcb_decrypt_s1data(machine());
9752   neo_pcm2_swap(machine(), 5);
9750   kof2000_neogeo_gfx_decrypt(0x9d);
9751   kf2k3pcb_decrypt_s1data();
9752   neo_pcm2_swap(5);
97539753   m_fixed_layer_bank_type = 2;
9754   install_pvc_protection(machine());
9754   install_pvc_protection();
97559755   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0xc00000, 0xc7ffff, "bios" );  // 512k bios
97569756}
97579757
97589758DRIVER_INIT_MEMBER(neogeo_state,kof2003)
97599759{
97609760   DRIVER_INIT_CALL(neogeo);
9761   kof2003_decrypt_68k(machine());
9762   neo_pcm2_swap(machine(), 5);
9761   kof2003_decrypt_68k();
9762   neo_pcm2_swap(5);
97639763   m_fixed_layer_bank_type = 2;
9764   neogeo_cmc50_m1_decrypt(machine());
9765   kof2000_neogeo_gfx_decrypt(machine(), 0x9d);
9766   install_pvc_protection(machine());
9764   neogeo_cmc50_m1_decrypt();
9765   kof2000_neogeo_gfx_decrypt(0x9d);
9766   install_pvc_protection();
97679767}
97689768
97699769DRIVER_INIT_MEMBER(neogeo_state,kof2003h)
97709770{
97719771   DRIVER_INIT_CALL(neogeo);
9772   kof2003h_decrypt_68k(machine());
9773   neo_pcm2_swap(machine(), 5);
9772   kof2003h_decrypt_68k();
9773   neo_pcm2_swap(5);
97749774   m_fixed_layer_bank_type = 2;
9775   neogeo_cmc50_m1_decrypt(machine());
9776   kof2000_neogeo_gfx_decrypt(machine(), 0x9d);
9777   install_pvc_protection(machine());
9775   neogeo_cmc50_m1_decrypt();
9776   kof2000_neogeo_gfx_decrypt(0x9d);
9777   install_pvc_protection();
97789778}
97799779
97809780DRIVER_INIT_MEMBER(neogeo_state,kf2k3bl)
97819781{
97829782   DRIVER_INIT_CALL(neogeo);
9783   cmc50_neogeo_gfx_decrypt(machine(), 0x9d);
9784   neo_pcm2_swap(machine(), 5);
9785   neogeo_bootleg_sx_decrypt(machine(), 1);
9786   kf2k3bl_install_protection(machine());
9783   cmc50_neogeo_gfx_decrypt(0x9d);
9784   neo_pcm2_swap(5);
9785   neogeo_bootleg_sx_decrypt(1);
9786   kf2k3bl_install_protection();
97879787}
97889788
97899789DRIVER_INIT_MEMBER(neogeo_state,kf2k3pl)
97909790{
97919791   DRIVER_INIT_CALL(neogeo);
9792   cmc50_neogeo_gfx_decrypt(machine(), 0x9d);
9793   neo_pcm2_swap(machine(), 5);
9794   kf2k3pl_px_decrypt(machine());
9795   neogeo_bootleg_sx_decrypt(machine(), 1);
9796   kf2k3pl_install_protection(machine());
9792   cmc50_neogeo_gfx_decrypt(0x9d);
9793   neo_pcm2_swap(5);
9794   kf2k3pl_px_decrypt();
9795   neogeo_bootleg_sx_decrypt(1);
9796   kf2k3pl_install_protection();
97979797}
97989798
97999799DRIVER_INIT_MEMBER(neogeo_state,kf2k3upl)
98009800{
98019801   DRIVER_INIT_CALL(neogeo);
9802   cmc50_neogeo_gfx_decrypt(machine(), 0x9d);
9803   neo_pcm2_swap(machine(), 5);
9804   kf2k3upl_px_decrypt(machine());
9805   neogeo_bootleg_sx_decrypt(machine(), 2);
9806   kf2k3upl_install_protection(machine());
9802   cmc50_neogeo_gfx_decrypt(0x9d);
9803   neo_pcm2_swap(5);
9804   kf2k3upl_px_decrypt();
9805   neogeo_bootleg_sx_decrypt(2);
9806   kf2k3upl_install_protection();
98079807}
98089808
98099809DRIVER_INIT_MEMBER(neogeo_state,samsh5sp)
98109810{
98119811   DRIVER_INIT_CALL(neogeo);
9812   samsh5sp_decrypt_68k(machine());
9813   neo_pcm2_swap(machine(), 6);
9812   samsh5sp_decrypt_68k();
9813   neo_pcm2_swap(6);
98149814   m_fixed_layer_bank_type = 1;
9815   neogeo_cmc50_m1_decrypt(machine());
9816   kof2000_neogeo_gfx_decrypt(machine(), 0x0d);
9815   neogeo_cmc50_m1_decrypt();
9816   kof2000_neogeo_gfx_decrypt(0x0d);
98179817}
98189818
98199819DRIVER_INIT_MEMBER(neogeo_state,jockeygp)
98209820{
98219821   DRIVER_INIT_CALL(neogeo);
98229822   m_fixed_layer_bank_type = 1;
9823   neogeo_cmc50_m1_decrypt(machine());
9824   kof2000_neogeo_gfx_decrypt(machine(), 0xac);
9823   neogeo_cmc50_m1_decrypt();
9824   kof2000_neogeo_gfx_decrypt(0xac);
98259825
98269826   /* install some extra RAM */
98279827   machine().device("maincpu")->memory().space(AS_PROGRAM).install_ram(0x200000, 0x201fff);
r21155r21156
98429842
98439843DRIVER_INIT_MEMBER(neogeo_state,kof97oro)
98449844{
9845   kof97oro_px_decode(machine());
9846   neogeo_bootleg_sx_decrypt(machine(), 1);
9847   neogeo_bootleg_cx_decrypt(machine());
9845   kof97oro_px_decode();
9846   neogeo_bootleg_sx_decrypt(1);
9847   neogeo_bootleg_cx_decrypt();
98489848   DRIVER_INIT_CALL(neogeo);
98499849}
98509850
r21155r21156
98539853   /* overlay cartridge ROM */
98549854   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_port(0x0ffffe, 0x0fffff, "JUMPER");
98559855
9856   kog_px_decrypt(machine());
9857   neogeo_bootleg_sx_decrypt(machine(), 1);
9858   neogeo_bootleg_cx_decrypt(machine());
9856   kog_px_decrypt();
9857   neogeo_bootleg_sx_decrypt(1);
9858   neogeo_bootleg_cx_decrypt();
98599859   DRIVER_INIT_CALL(neogeo);
98609860}
98619861
98629862DRIVER_INIT_MEMBER(neogeo_state,lans2004)
98639863{
9864   lans2004_decrypt_68k(machine());
9865   lans2004_vx_decrypt(machine());
9866   neogeo_bootleg_sx_decrypt(machine(), 1);
9867   neogeo_bootleg_cx_decrypt(machine());
9864   lans2004_decrypt_68k();
9865   lans2004_vx_decrypt();
9866   neogeo_bootleg_sx_decrypt(1);
9867   neogeo_bootleg_cx_decrypt();
98689868   DRIVER_INIT_CALL(neogeo);
98699869}
98709870
9871static READ16_HANDLER( sbp_lowerrom_r )
9871READ16_MEMBER( neogeo_state::sbp_lowerrom_r )
98729872{
9873   UINT16* rom = (UINT16*)space.machine().root_device().memregion("maincpu")->base();
9873   UINT16* rom = (UINT16*)memregion("maincpu")->base();
98749874   UINT16 origdata = rom[(offset+(0x200/2))];
98759875   UINT16 data =  BITSWAP16(origdata, 11,10,9,8,15,14,13,12,3,2,1,0,7,6,5,4);
98769876   int realoffset = 0x200+(offset*2);
r21155r21156
98829882   return data;
98839883}
98849884
9885static WRITE16_HANDLER( sbp_lowerrom_w )
9885WRITE16_MEMBER( neogeo_state::sbp_lowerrom_w )
98869886{
98879887   int realoffset = 0x200+(offset*2);
98889888
r21155r21156
99119911   // there are also writes to 0x1080..
99129912   //
99139913   // other stuff going on as well tho, the main overlay is still missing, and p1 inputs don't work
9914   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x00200, 0x001fff, FUNC(sbp_lowerrom_r));
9915   machine().device("maincpu")->memory().space(AS_PROGRAM).install_legacy_write_handler(0x00200, 0x001fff, FUNC(sbp_lowerrom_w));
9914   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x00200, 0x001fff, read16_delegate(FUNC(neogeo_state::sbp_lowerrom_r),this));
9915   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x00200, 0x001fff, write16_delegate(FUNC(neogeo_state::sbp_lowerrom_w),this));
99169916
99179917   /* the game code clears the text overlay used ingame immediately after writing it.. why? protection? sloppy code that the hw ignores? imperfect emulation? */
99189918   {
trunk/src/mame/drivers/neogeo.c
r21155r21156
10511051
10521052   m_maincpu->reset();
10531053
1054   neogeo_reset_rng(machine());
1054   neogeo_reset_rng();
10551055
10561056   start_interrupt_timers();
10571057
trunk/src/mame/machine/neocrypt.c
r21155r21156
108108
109109***************************************************************************/
110110
111static const UINT8 *type0_t03;
112static const UINT8 *type0_t12;
113static const UINT8 *type1_t03;
114static const UINT8 *type1_t12;
115static const UINT8 *address_8_15_xor1;
116static const UINT8 *address_8_15_xor2;
117static const UINT8 *address_16_23_xor1;
118static const UINT8 *address_16_23_xor2;
119static const UINT8 *address_0_7_xor;
120
121
122111static const UINT8 kof99_type0_t03[256] =
123112{
124113   0xfb, 0x86, 0x9d, 0xf1, 0xbf, 0x80, 0xd5, 0x43, 0xab, 0xb3, 0x9f, 0x6a, 0x33, 0xd9, 0xdb, 0xb6,
r21155r21156
501490
502491
503492
504static void decrypt(UINT8 *r0, UINT8 *r1,
493void neogeo_state::decrypt(UINT8 *r0, UINT8 *r1,
505494               UINT8 c0,  UINT8 c1,
506495               const UINT8 *table0hi,
507496               const UINT8 *table0lo,
r21155r21156
528517}
529518
530519
531static void neogeo_gfx_decrypt(running_machine &machine, int extra_xor)
520void neogeo_state::neogeo_gfx_decrypt(int extra_xor)
532521{
533522   int rom_size;
534523   UINT8 *buf;
535524   UINT8 *rom;
536525   int rpos;
537526
538   rom_size = machine.root_device().memregion("sprites")->bytes();
527   rom_size = memregion("sprites")->bytes();
539528
540   buf = auto_alloc_array(machine, UINT8, rom_size);
529   buf = auto_alloc_array(machine(), UINT8, rom_size);
541530
542   rom = machine.root_device().memregion("sprites")->base();
531   rom = memregion("sprites")->base();
543532
544533   // Data xor
545534   for (rpos = 0;rpos < rom_size/4;rpos++)
r21155r21156
587576      rom[4*rpos+3] = buf[4*baser+3];
588577   }
589578
590   auto_free(machine, buf);
579   auto_free(machine(), buf);
591580}
592581
593582
594583/* the S data comes from the end of the C data */
595void neogeo_sfix_decrypt(running_machine &machine)
584void neogeo_state::neogeo_sfix_decrypt()
596585{
597586   int i;
598   int rom_size = machine.root_device().memregion("sprites")->bytes();
599   int tx_size = machine.root_device().memregion("fixed")->bytes();
600   UINT8 *src = machine.root_device().memregion("sprites")->base()+rom_size-tx_size;
601   UINT8 *dst = machine.root_device().memregion("fixed")->base();
587   int rom_size = memregion("sprites")->bytes();
588   int tx_size = memregion("fixed")->bytes();
589   UINT8 *src = memregion("sprites")->base()+rom_size-tx_size;
590   UINT8 *dst = memregion("fixed")->base();
602591
603592   for (i = 0;i < tx_size;i++)
604593      dst[i] = src[(i & ~0x1f) + ((i & 7) << 2) + ((~i & 8) >> 2) + ((i & 0x10) >> 4)];
r21155r21156
606595
607596
608597/* CMC42 protection chip */
609void kof99_neogeo_gfx_decrypt(running_machine &machine, int extra_xor)
598void neogeo_state::kof99_neogeo_gfx_decrypt(int extra_xor)
610599{
611600   type0_t03 =          kof99_type0_t03;
612601   type0_t12 =          kof99_type0_t12;
r21155r21156
617606   address_16_23_xor1 = kof99_address_16_23_xor1;
618607   address_16_23_xor2 = kof99_address_16_23_xor2;
619608   address_0_7_xor =    kof99_address_0_7_xor;
620   neogeo_gfx_decrypt(machine, extra_xor);
621   neogeo_sfix_decrypt(machine);
609   neogeo_gfx_decrypt(extra_xor);
610   neogeo_sfix_decrypt();
622611}
623612
624613
625614/* CMC50 protection chip */
626void kof2000_neogeo_gfx_decrypt(running_machine &machine, int extra_xor)
615void neogeo_state::kof2000_neogeo_gfx_decrypt(int extra_xor)
627616{
628617   type0_t03 =          kof2000_type0_t03;
629618   type0_t12 =          kof2000_type0_t12;
r21155r21156
634623   address_16_23_xor1 = kof2000_address_16_23_xor1;
635624   address_16_23_xor2 = kof2000_address_16_23_xor2;
636625   address_0_7_xor =    kof2000_address_0_7_xor;
637   neogeo_gfx_decrypt(machine, extra_xor);
638   neogeo_sfix_decrypt(machine);
626   neogeo_gfx_decrypt(extra_xor);
627   neogeo_sfix_decrypt();
639628}
640629
641630
642631/* CMC42 protection chip */
643void cmc42_neogeo_gfx_decrypt(running_machine &machine, int extra_xor)
632void neogeo_state::cmc42_neogeo_gfx_decrypt(int extra_xor)
644633{
645634   type0_t03 =          kof99_type0_t03;
646635   type0_t12 =          kof99_type0_t12;
r21155r21156
651640   address_16_23_xor1 = kof99_address_16_23_xor1;
652641   address_16_23_xor2 = kof99_address_16_23_xor2;
653642   address_0_7_xor =    kof99_address_0_7_xor;
654   neogeo_gfx_decrypt(machine, extra_xor);
643   neogeo_gfx_decrypt(extra_xor);
655644}
656645
657646
658647/* CMC50 protection chip */
659void cmc50_neogeo_gfx_decrypt(running_machine &machine, int extra_xor)
648void neogeo_state::cmc50_neogeo_gfx_decrypt(int extra_xor)
660649{
661650   type0_t03 =          kof2000_type0_t03;
662651   type0_t12 =          kof2000_type0_t12;
r21155r21156
667656   address_16_23_xor1 = kof2000_address_16_23_xor1;
668657   address_16_23_xor2 = kof2000_address_16_23_xor2;
669658   address_0_7_xor =    kof2000_address_0_7_xor;
670   neogeo_gfx_decrypt(machine, extra_xor);
659   neogeo_gfx_decrypt(extra_xor);
671660}
672661
673662
674663/* ms5pcb and svcpcb have an additional scramble on top of the standard CMC scrambling */
675void svcpcb_gfx_decrypt(running_machine &machine)
664void neogeo_state::svcpcb_gfx_decrypt()
676665{
677666   static const UINT8 xorval[ 4 ] = { 0x34, 0x21, 0xc4, 0xe9 };
678667   int i;
679668   int ofst;
680   int rom_size = machine.root_device().memregion( "sprites" )->bytes();
681   UINT8 *rom = machine.root_device().memregion( "sprites" )->base();
682   UINT8 *buf = auto_alloc_array(machine, UINT8,  rom_size );
669   int rom_size = memregion( "sprites" )->bytes();
670   UINT8 *rom = memregion( "sprites" )->base();
671   UINT8 *buf = auto_alloc_array(machine(), UINT8,  rom_size );
683672
684673   for( i = 0; i < rom_size; i++ )
685674   {
r21155r21156
702691      ofst += (i & 0xffe00000);
703692      memcpy( &rom[ i * 4 ], &buf[ ofst * 4 ], 0x04 );
704693   }
705   auto_free( machine, buf );
694   auto_free( machine(), buf );
706695}
707696
708697
709698/* and a further swap on the s1 data */
710void svcpcb_s1data_decrypt(running_machine &machine)
699void neogeo_state::svcpcb_s1data_decrypt()
711700{
712701   int i;
713   UINT8 *s1 = machine.root_device().memregion( "fixed" )->base();
714   size_t s1_size = machine.root_device().memregion( "fixed" )->bytes();
702   UINT8 *s1 = memregion( "fixed" )->base();
703   size_t s1_size = memregion( "fixed" )->bytes();
715704
716705   for( i = 0; i < s1_size; i++ ) // Decrypt S
717706   {
r21155r21156
722711
723712/* kf2k3pcb has an additional scramble on top of the standard CMC scrambling */
724713/* Thanks to Razoola & Halrin for the info */
725void kf2k3pcb_gfx_decrypt(running_machine &machine)
714void neogeo_state::kf2k3pcb_gfx_decrypt()
726715{
727716   static const UINT8 xorval[ 4 ] = { 0x34, 0x21, 0xc4, 0xe9 };
728717   int i;
729718   int ofst;
730   int rom_size = machine.root_device().memregion( "sprites" )->bytes();
731   UINT8 *rom = machine.root_device().memregion( "sprites" )->base();
732   UINT8 *buf = auto_alloc_array(machine, UINT8,  rom_size );
719   int rom_size = memregion( "sprites" )->bytes();
720   UINT8 *rom = memregion( "sprites" )->base();
721   UINT8 *buf = auto_alloc_array(machine(), UINT8,  rom_size );
733722
734723   for ( i = 0; i < rom_size; i++ )
735724   {
r21155r21156
748737      ofst += (i & 0xff800000);
749738      memcpy( &rom[ ofst ], &buf[ i ], 0x04 );
750739   }
751   auto_free( machine, buf );
740   auto_free( machine(), buf );
752741}
753742
754743
755744/* and a further swap on the s1 data */
756void kf2k3pcb_decrypt_s1data(running_machine &machine)
745void neogeo_state::kf2k3pcb_decrypt_s1data()
757746{
758747   UINT8 *src;
759748   UINT8 *dst;
760749   int i;
761   int tx_size = machine.root_device().memregion( "fixed" )->bytes();
762   int srom_size = machine.root_device().memregion( "sprites" )->bytes();
750   int tx_size = memregion( "fixed" )->bytes();
751   int srom_size = memregion( "sprites" )->bytes();
763752
764   src = machine.root_device().memregion( "sprites" )->base() + srom_size - 0x1000000 - 0x80000; // Decrypt S
765   dst = machine.root_device().memregion( "fixed" )->base();
753   src = memregion( "sprites" )->base() + srom_size - 0x1000000 - 0x80000; // Decrypt S
754   dst = memregion( "fixed" )->base();
766755
767756   for( i = 0; i < tx_size / 2; i++ )
768757   {
769758      dst[ i ] = src[ (i & ~0x1f) + ((i & 7) << 2) + ((~i & 8) >> 2) + ((i & 0x10) >> 4) ];
770759   }
771760
772   src = machine.root_device().memregion( "sprites" )->base() + srom_size - 0x80000;
773   dst = machine.root_device().memregion( "fixed" )->base() + 0x80000;
761   src = memregion( "sprites" )->base() + srom_size - 0x80000;
762   dst = memregion( "fixed" )->base() + 0x80000;
774763
775764   for( i = 0; i < tx_size / 2; i++ )
776765   {
777766      dst[ i ] = src[ (i & ~0x1f) + ((i & 7) << 2) + ((~i & 8) >> 2) + ((i & 0x10) >> 4) ];
778767   }
779768
780   dst = machine.root_device().memregion( "fixed" )->base();
769   dst = memregion( "fixed" )->base();
781770
782771   for( i = 0; i < tx_size; i++ )
783772   {
r21155r21156
839828   ,and uses this checksum as the basis of the key with which to decrypt
840829   the rom */
841830
842static UINT16 generate_cs16(UINT8 *rom, int size)
831UINT16 neogeo_state::generate_cs16(UINT8 *rom, int size)
843832{
844833   UINT16 cs16;
845834   int i;
r21155r21156
852841}
853842
854843
855static int m1_address_scramble(int address, UINT16 key)
844int neogeo_state::m1_address_scramble(int address, UINT16 key)
856845{
857846   int block;
858847   int aux;
r21155r21156
885874}
886875
887876
888void neogeo_cmc50_m1_decrypt(running_machine &machine)
877void neogeo_state::neogeo_cmc50_m1_decrypt()
889878{
890   UINT8* rom = machine.root_device().memregion("audiocrypt")->base();
879   UINT8* rom = memregion("audiocrypt")->base();
891880   size_t rom_size = 0x80000;
892   UINT8* rom2 = machine.root_device().memregion("audiocpu")->base();
881   UINT8* rom2 = memregion("audiocpu")->base();
893882
894   UINT8* buffer = auto_alloc_array(machine, UINT8, rom_size);
883   UINT8* buffer = auto_alloc_array(machine(), UINT8, rom_size);
895884
896885   UINT32 i;
897886
r21155r21156
912901   #if 0
913902   {
914903      FILE *fp;
915      const char *gamename = machine.system().name;
904      const char *gamename = machine().system().name;
916905      char filename[256];
917906      sprintf(filename, "%s_m1.dump", gamename);
918907
r21155r21156
929918   #if 0
930919   {
931920      FILE *fp;
932      const char *gamename = machine.system().name;
921      const char *gamename = machine().system().name;
933922      char filename[256];
934923      sprintf(filename, "%s_m1extra.dump", gamename);
935924
r21155r21156
942931   }
943932   #endif
944933
945   auto_free( machine, buffer );
934   auto_free( machine(), buffer );
946935}
947936
948937
r21155r21156
954943
955944
956945/* Kof98 uses an early encryption, quite different from the others */
957void kof98_decrypt_68k(running_machine &machine)
946void neogeo_state::kof98_decrypt_68k()
958947{
959   UINT8 *src = machine.root_device().memregion("maincpu")->base();
960   UINT8 *dst = auto_alloc_array(machine, UINT8, 0x200000);
948   UINT8 *src = memregion("maincpu")->base();
949   UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x200000);
961950   int i, j, k;
962951   static const UINT32 sec[]={0x000000,0x100000,0x000004,0x100004,0x10000a,0x00000a,0x10000e,0x00000e};
963952   static const UINT32 pos[]={0x000,0x004,0x00a,0x00e};
r21155r21156
996985   }
997986   memmove( &src[0x100000], &src[0x200000], 0x400000 );
998987
999   auto_free(machine, dst);
988   auto_free(machine(), dst);
1000989}
1001990
1002991
1003992/* kof99, garou, garouh, mslug3 and kof2000 have and SMA chip which contains program code and decrypts the 68k roms */
1004void kof99_decrypt_68k(running_machine &machine)
993void neogeo_state::kof99_decrypt_68k()
1005994{
1006995   UINT16 *rom;
1007996   int i,j;
1008997
1009   rom = (UINT16 *)(machine.root_device().memregion("maincpu")->base() + 0x100000);
998   rom = (UINT16 *)(memregion("maincpu")->base() + 0x100000);
1010999   /* swap data lines on the whole ROMs */
10111000   for (i = 0;i < 0x800000/2;i++)
10121001   {
r21155r21156
10251014   }
10261015
10271016   /* swap address lines & relocate fixed part */
1028   rom = (UINT16 *)machine.root_device().memregion("maincpu")->base();
1017   rom = (UINT16 *)memregion("maincpu")->base();
10291018   for (i = 0;i < 0x0c0000/2;i++)
10301019   {
10311020      rom[i] = rom[0x700000/2 + BITSWAP24(i,23,22,21,20,19,18,11,6,14,17,16,5,8,10,12,0,4,3,2,7,9,15,13,1)];
r21155r21156
10331022}
10341023
10351024
1036void garou_decrypt_68k(running_machine &machine)
1025void neogeo_state::garou_decrypt_68k()
10371026{
10381027   UINT16 *rom;
10391028   int i,j;
10401029
10411030   /* thanks to Razoola and Mr K for the info */
1042   rom = (UINT16 *)(machine.root_device().memregion("maincpu")->base() + 0x100000);
1031   rom = (UINT16 *)(memregion("maincpu")->base() + 0x100000);
10431032   /* swap data lines on the whole ROMs */
10441033   for (i = 0;i < 0x800000/2;i++)
10451034   {
r21155r21156
10471036   }
10481037
10491038   /* swap address lines & relocate fixed part */
1050   rom = (UINT16 *)machine.root_device().memregion("maincpu")->base();
1039   rom = (UINT16 *)memregion("maincpu")->base();
10511040   for (i = 0;i < 0x0c0000/2;i++)
10521041   {
10531042      rom[i] = rom[0x710000/2 + BITSWAP24(i,23,22,21,20,19,18,4,5,16,14,7,9,6,13,17,15,3,1,2,12,11,8,10,0)];
10541043   }
10551044
10561045   /* swap address lines for the banked part */
1057   rom = (UINT16 *)(machine.root_device().memregion("maincpu")->base() + 0x100000);
1046   rom = (UINT16 *)(memregion("maincpu")->base() + 0x100000);
10581047   for (i = 0;i < 0x800000/2;i+=0x8000/2)
10591048   {
10601049      UINT16 buffer[0x8000/2];
r21155r21156
10671056}
10681057
10691058
1070void garouh_decrypt_68k(running_machine &machine)
1059void neogeo_state::garouh_decrypt_68k()
10711060{
10721061   UINT16 *rom;
10731062   int i,j;
10741063
10751064   /* thanks to Razoola and Mr K for the info */
1076   rom = (UINT16 *)(machine.root_device().memregion("maincpu")->base() + 0x100000);
1065   rom = (UINT16 *)(memregion("maincpu")->base() + 0x100000);
10771066   /* swap data lines on the whole ROMs */
10781067   for (i = 0;i < 0x800000/2;i++)
10791068   {
r21155r21156
10811070   }
10821071
10831072   /* swap address lines & relocate fixed part */
1084   rom = (UINT16 *)machine.root_device().memregion("maincpu")->base();
1073   rom = (UINT16 *)memregion("maincpu")->base();
10851074   for (i = 0;i < 0x0c0000/2;i++)
10861075   {
10871076      rom[i] = rom[0x7f8000/2 + BITSWAP24(i,23,22,21,20,19,18,5,16,11,2,6,7,17,3,12,8,14,4,0,9,1,10,15,13)];
10881077   }
10891078
10901079   /* swap address lines for the banked part */
1091   rom = (UINT16 *)(machine.root_device().memregion("maincpu")->base() + 0x100000);
1080   rom = (UINT16 *)(memregion("maincpu")->base() + 0x100000);
10921081   for (i = 0;i < 0x800000/2;i+=0x8000/2)
10931082   {
10941083      UINT16 buffer[0x8000/2];
r21155r21156
11011090}
11021091
11031092
1104void mslug3_decrypt_68k(running_machine &machine)
1093void neogeo_state::mslug3_decrypt_68k()
11051094{
11061095   UINT16 *rom;
11071096   int i,j;
11081097
11091098   /* thanks to Razoola and Mr K for the info */
1110   rom = (UINT16 *)(machine.root_device().memregion("maincpu")->base() + 0x100000);
1099   rom = (UINT16 *)(memregion("maincpu")->base() + 0x100000);
11111100   /* swap data lines on the whole ROMs */
11121101   for (i = 0;i < 0x800000/2;i++)
11131102   {
r21155r21156
11151104   }
11161105
11171106   /* swap address lines & relocate fixed part */
1118   rom = (UINT16 *)machine.root_device().memregion("maincpu")->base();
1107   rom = (UINT16 *)memregion("maincpu")->base();
11191108   for (i = 0;i < 0x0c0000/2;i++)
11201109   {
11211110      rom[i] = rom[0x5d0000/2 + BITSWAP24(i,23,22,21,20,19,18,15,2,1,13,3,0,9,6,16,4,11,5,7,12,17,14,10,8)];
11221111   }
11231112
11241113   /* swap address lines for the banked part */
1125   rom = (UINT16 *)(machine.root_device().memregion("maincpu")->base() + 0x100000);
1114   rom = (UINT16 *)(memregion("maincpu")->base() + 0x100000);
11261115   for (i = 0;i < 0x800000/2;i+=0x10000/2)
11271116   {
11281117      UINT16 buffer[0x10000/2];
r21155r21156
11351124}
11361125
11371126
1138void kof2000_decrypt_68k(running_machine &machine)
1127void neogeo_state::kof2000_decrypt_68k()
11391128{
11401129   UINT16 *rom;
11411130   int i,j;
11421131
11431132   /* thanks to Razoola and Mr K for the info */
1144   rom = (UINT16 *)(machine.root_device().memregion("maincpu")->base() + 0x100000);
1133   rom = (UINT16 *)(memregion("maincpu")->base() + 0x100000);
11451134   /* swap data lines on the whole ROMs */
11461135   for (i = 0;i < 0x800000/2;i++)
11471136   {
r21155r21156
11601149   }
11611150
11621151   /* swap address lines & relocate fixed part */
1163   rom = (UINT16 *)machine.root_device().memregion("maincpu")->base();
1152   rom = (UINT16 *)memregion("maincpu")->base();
11641153   for (i = 0;i < 0x0c0000/2;i++)
11651154   {
11661155      rom[i] = rom[0x73a000/2 + BITSWAP24(i,23,22,21,20,19,18,8,4,15,13,3,14,16,2,6,17,7,12,10,0,5,11,1,9)];
r21155r21156
11691158
11701159
11711160/* kof2002, matrim, samsho5, samsh5sp have some simple block swapping */
1172void kof2002_decrypt_68k(running_machine &machine)
1161void neogeo_state::kof2002_decrypt_68k()
11731162{
11741163   int i;
11751164   static const int sec[]={0x100000,0x280000,0x300000,0x180000,0x000000,0x380000,0x200000,0x080000};
1176   UINT8 *src = machine.root_device().memregion("maincpu")->base()+0x100000;
1177   UINT8 *dst = auto_alloc_array(machine, UINT8, 0x400000);
1165   UINT8 *src = memregion("maincpu")->base()+0x100000;
1166   UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x400000);
11781167   memcpy( dst, src, 0x400000 );
11791168   for( i=0; i<8; ++i )
11801169   {
11811170      memcpy( src+i*0x80000, dst+sec[i], 0x80000 );
11821171   }
1183   auto_free(machine, dst);
1172   auto_free(machine(), dst);
11841173}
11851174
11861175
1187void matrim_decrypt_68k(running_machine &machine)
1176void neogeo_state::matrim_decrypt_68k()
11881177{
11891178   int i;
11901179   static const int sec[]={0x100000,0x280000,0x300000,0x180000,0x000000,0x380000,0x200000,0x080000};
1191   UINT8 *src = machine.root_device().memregion("maincpu")->base()+0x100000;
1192   UINT8 *dst = auto_alloc_array(machine, UINT8, 0x400000);
1180   UINT8 *src = memregion("maincpu")->base()+0x100000;
1181   UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x400000);
11931182   memcpy( dst, src, 0x400000);
11941183   for( i=0; i<8; ++i )
11951184   {
11961185      memcpy( src+i*0x80000, dst+sec[i], 0x80000 );
11971186   }
1198   auto_free(machine, dst);
1187   auto_free(machine(), dst);
11991188}
12001189
12011190
1202void samsho5_decrypt_68k(running_machine &machine)
1191void neogeo_state::samsho5_decrypt_68k()
12031192{
12041193   int i;
12051194   static const int sec[]={0x000000,0x080000,0x700000,0x680000,0x500000,0x180000,0x200000,0x480000,0x300000,0x780000,0x600000,0x280000,0x100000,0x580000,0x400000,0x380000};
1206   UINT8 *src = machine.root_device().memregion("maincpu")->base();
1207   UINT8 *dst = auto_alloc_array(machine, UINT8, 0x800000);
1195   UINT8 *src = memregion("maincpu")->base();
1196   UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x800000);
12081197
12091198   memcpy( dst, src, 0x800000 );
12101199   for( i=0; i<16; ++i )
12111200   {
12121201      memcpy( src+i*0x80000, dst+sec[i], 0x80000 );
12131202   }
1214   auto_free(machine, dst);
1203   auto_free(machine(), dst);
12151204}
12161205
12171206
1218void samsh5sp_decrypt_68k(running_machine &machine)
1207void neogeo_state::samsh5sp_decrypt_68k()
12191208{
12201209   int i;
12211210   static const int sec[]={0x000000,0x080000,0x500000,0x480000,0x600000,0x580000,0x700000,0x280000,0x100000,0x680000,0x400000,0x780000,0x200000,0x380000,0x300000,0x180000};
1222   UINT8 *src = machine.root_device().memregion("maincpu")->base();
1223   UINT8 *dst = auto_alloc_array(machine, UINT8, 0x800000);
1211   UINT8 *src = memregion("maincpu")->base();
1212   UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x800000);
12241213
12251214   memcpy( dst, src, 0x800000 );
12261215   for( i=0; i<16; ++i )
12271216   {
12281217      memcpy( src+i*0x80000, dst+sec[i], 0x80000 );
12291218   }
1230   auto_free(machine, dst);
1219   auto_free(machine(), dst);
12311220}
12321221
12331222
12341223/* kf2k3pcb, kof2003, kof2003h, mslug5 and svc have updated P rom scramble */
1235void mslug5_decrypt_68k(running_machine &machine)
1224void neogeo_state::mslug5_decrypt_68k()
12361225{
12371226   static const UINT8 xor1[ 0x20 ] = { 0xc2, 0x4b, 0x74, 0xfd, 0x0b, 0x34, 0xeb, 0xd7, 0x10, 0x6d, 0xf9, 0xce, 0x5d, 0xd5, 0x61, 0x29, 0xf5, 0xbe, 0x0d, 0x82, 0x72, 0x45, 0x0f, 0x24, 0xb3, 0x34, 0x1b, 0x99, 0xea, 0x09, 0xf3, 0x03 };
12381227   static const UINT8 xor2[ 0x20 ] = { 0x36, 0x09, 0xb0, 0x64, 0x95, 0x0f, 0x90, 0x42, 0x6e, 0x0f, 0x30, 0xf6, 0xe5, 0x08, 0x30, 0x64, 0x08, 0x04, 0x00, 0x2f, 0x72, 0x09, 0xa0, 0x13, 0xc9, 0x0b, 0xa0, 0x3e, 0xc2, 0x00, 0x40, 0x2b };
12391228   int i;
12401229   int ofst;
12411230   int rom_size = 0x800000;
1242   UINT8 *rom = machine.root_device().memregion( "maincpu" )->base();
1243   UINT8 *buf = auto_alloc_array(machine, UINT8,  rom_size );
1231   UINT8 *rom = memregion( "maincpu" )->base();
1232   UINT8 *buf = auto_alloc_array(machine(), UINT8,  rom_size );
12441233
12451234   for( i = 0; i < 0x100000; i++ )
12461235   {
r21155r21156
12731262   memcpy( buf, rom, rom_size );
12741263   memcpy( &rom[ 0x100000 ], &buf[ 0x700000 ], 0x100000 );
12751264   memcpy( &rom[ 0x200000 ], &buf[ 0x100000 ], 0x600000 );
1276   auto_free( machine, buf );
1265   auto_free( machine(), buf );
12771266}
12781267
12791268
1280void svc_px_decrypt(running_machine &machine)
1269void neogeo_state::svc_px_decrypt()
12811270{
12821271   static const UINT8 xor1[ 0x20 ] = { 0x3b, 0x6a, 0xf7, 0xb7, 0xe8, 0xa9, 0x20, 0x99, 0x9f, 0x39, 0x34, 0x0c, 0xc3, 0x9a, 0xa5, 0xc8, 0xb8, 0x18, 0xce, 0x56, 0x94, 0x44, 0xe3, 0x7a, 0xf7, 0xdd, 0x42, 0xf0, 0x18, 0x60, 0x92, 0x9f };
12831272   static const UINT8 xor2[ 0x20 ] = { 0x69, 0x0b, 0x60, 0xd6, 0x4f, 0x01, 0x40, 0x1a, 0x9f, 0x0b, 0xf0, 0x75, 0x58, 0x0e, 0x60, 0xb4, 0x14, 0x04, 0x20, 0xe4, 0xb9, 0x0d, 0x10, 0x89, 0xeb, 0x07, 0x30, 0x90, 0x50, 0x0e, 0x20, 0x26 };
12841273   int i;
12851274   int ofst;
12861275   int rom_size = 0x800000;
1287   UINT8 *rom = machine.root_device().memregion( "maincpu" )->base();
1288   UINT8 *buf = auto_alloc_array(machine, UINT8,  rom_size );
1276   UINT8 *rom = memregion( "maincpu" )->base();
1277   UINT8 *buf = auto_alloc_array(machine(), UINT8,  rom_size );
12891278
12901279   for( i = 0; i < 0x100000; i++ )
12911280   {
r21155r21156
13181307   memcpy( buf, rom, rom_size );
13191308   memcpy( &rom[ 0x100000 ], &buf[ 0x700000 ], 0x100000 );
13201309   memcpy( &rom[ 0x200000 ], &buf[ 0x100000 ], 0x600000 );
1321   auto_free( machine, buf );
1310   auto_free( machine(), buf );
13221311}
13231312
13241313
1325void kf2k3pcb_decrypt_68k(running_machine &machine)
1314void neogeo_state::kf2k3pcb_decrypt_68k()
13261315{
13271316   static const UINT8 xor2[ 0x20 ] = { 0xb4, 0x0f, 0x40, 0x6c, 0x38, 0x07, 0xd0, 0x3f, 0x53, 0x08, 0x80, 0xaa, 0xbe, 0x07, 0xc0, 0xfa, 0xd0, 0x08, 0x10, 0xd2, 0xf1, 0x03, 0x70, 0x7e, 0x87, 0x0b, 0x40, 0xf6, 0x2a, 0x0a, 0xe0, 0xf9 };
13281317   int i;
13291318   int ofst;
13301319   int rom_size = 0x900000;
1331   UINT8 *rom = machine.root_device().memregion( "maincpu" )->base();
1332   UINT8 *buf = auto_alloc_array(machine, UINT8,  rom_size );
1320   UINT8 *rom = memregion( "maincpu" )->base();
1321   UINT8 *buf = auto_alloc_array(machine(), UINT8,  rom_size );
13331322
13341323   for (i = 0; i < 0x100000; i++)
13351324   {
r21155r21156
13601349   memcpy (&rom[0x000000], &buf[0x000000], 0x100000);
13611350   memcpy (&rom[0x100000], &buf[0x800000], 0x100000);
13621351   memcpy (&rom[0x200000], &buf[0x100000], 0x700000);
1363   auto_free( machine, buf );
1352   auto_free( machine(), buf );
13641353}
13651354
13661355
1367void kof2003_decrypt_68k(running_machine &machine)
1356void neogeo_state::kof2003_decrypt_68k()
13681357{
13691358   static const UINT8 xor1[0x20] = { 0x3b, 0x6a, 0xf7, 0xb7, 0xe8, 0xa9, 0x20, 0x99, 0x9f, 0x39, 0x34, 0x0c, 0xc3, 0x9a, 0xa5, 0xc8, 0xb8, 0x18, 0xce, 0x56, 0x94, 0x44, 0xe3, 0x7a, 0xf7, 0xdd, 0x42, 0xf0, 0x18, 0x60, 0x92, 0x9f };
13701359   static const UINT8 xor2[0x20] = { 0x2f, 0x02, 0x60, 0xbb, 0x77, 0x01, 0x30, 0x08, 0xd8, 0x01, 0xa0, 0xdf, 0x37, 0x0a, 0xf0, 0x65, 0x28, 0x03, 0xd0, 0x23, 0xd3, 0x03, 0x70, 0x42, 0xbb, 0x06, 0xf0, 0x28, 0xba, 0x0f, 0xf0, 0x7a };
13711360   int i;
13721361   int ofst;
13731362   int rom_size = 0x900000;
1374   UINT8 *rom = machine.root_device().memregion( "maincpu" )->base();
1375   UINT8 *buf = auto_alloc_array(machine, UINT8,  rom_size );
1363   UINT8 *rom = memregion( "maincpu" )->base();
1364   UINT8 *buf = auto_alloc_array(machine(), UINT8,  rom_size );
13761365
13771366   for (i = 0; i < 0x100000; i++)
13781367   {
r21155r21156
14071396   memcpy (&rom[0x000000], &buf[0x000000], 0x100000);
14081397   memcpy (&rom[0x100000], &buf[0x800000], 0x100000);
14091398   memcpy (&rom[0x200000], &buf[0x100000], 0x700000);
1410   auto_free( machine, buf );
1399   auto_free( machine(), buf );
14111400}
14121401
14131402
14141403// Thanks to IQ_132 for the info
1415void kof2003h_decrypt_68k(running_machine &machine)
1404void neogeo_state::kof2003h_decrypt_68k()
14161405{
14171406   static const UINT8 xor1[0x20] = { 0xc2, 0x4b, 0x74, 0xfd, 0x0b, 0x34, 0xeb, 0xd7, 0x10, 0x6d, 0xf9, 0xce, 0x5d, 0xd5, 0x61, 0x29, 0xf5, 0xbe, 0x0d, 0x82, 0x72, 0x45, 0x0f, 0x24, 0xb3, 0x34, 0x1b, 0x99, 0xea, 0x09, 0xf3, 0x03 };
14181407   static const UINT8 xor2[0x20] = { 0x2b, 0x09, 0xd0, 0x7f, 0x51, 0x0b, 0x10, 0x4c, 0x5b, 0x07, 0x70, 0x9d, 0x3e, 0x0b, 0xb0, 0xb6, 0x54, 0x09, 0xe0, 0xcc, 0x3d, 0x0d, 0x80, 0x99, 0x87, 0x03, 0x90, 0x82, 0xfe, 0x04, 0x20, 0x18 };
14191408   int i;
14201409   int ofst;
14211410   int rom_size = 0x900000;
1422   UINT8 *rom = machine.root_device().memregion( "maincpu" )->base();
1423   UINT8 *buf = auto_alloc_array(machine, UINT8,  rom_size );
1411   UINT8 *rom = memregion( "maincpu" )->base();
1412   UINT8 *buf = auto_alloc_array(machine(), UINT8,  rom_size );
14241413
14251414   for (i = 0; i < 0x100000; i++)
14261415   {
r21155r21156
14551444   memcpy (&rom[0x000000], &buf[0x000000], 0x100000);
14561445   memcpy (&rom[0x100000], &buf[0x800000], 0x100000);
14571446   memcpy (&rom[0x200000], &buf[0x100000], 0x700000);
1458   auto_free( machine, buf );
1447   auto_free( machine(), buf );
14591448}
14601449
14611450
r21155r21156
14671456***************************************************************************/
14681457
14691458/* Neo-Pcm2 Drivers for Encrypted V Roms */
1470void neo_pcm2_snk_1999(running_machine &machine, int value)
1459void neogeo_state::neo_pcm2_snk_1999(int value)
14711460{   /* thanks to Elsemi for the NEO-PCM2 info */
1472   UINT16 *rom = (UINT16 *)machine.root_device().memregion("ymsnd")->base();
1473   int size = machine.root_device().memregion("ymsnd")->bytes();
1461   UINT16 *rom = (UINT16 *)memregion("ymsnd")->base();
1462   int size = memregion("ymsnd")->bytes();
14741463   int i, j;
14751464
14761465   if( rom != NULL )
14771466   {   /* swap address lines on the whole ROMs */
1478      UINT16 *buffer = auto_alloc_array(machine, UINT16, value / 2);
1467      UINT16 *buffer = auto_alloc_array(machine(), UINT16, value / 2);
14791468
14801469      for( i = 0; i < size / 2; i += ( value / 2 ) )
14811470      {
r21155r21156
14851474            rom[ i + j ] = buffer[ j ^ (value/4) ];
14861475         }
14871476      }
1488      auto_free(machine, buffer);
1477      auto_free(machine(), buffer);
14891478   }
14901479}
14911480
14921481
14931482/* the later PCM2 games have additional scrambling */
1494void neo_pcm2_swap(running_machine &machine, int value)
1483void neogeo_state::neo_pcm2_swap(int value)
14951484{
14961485   static const UINT32 addrs[7][2]={
14971486      {0x000000,0xa5000},
r21155r21156
15091498      {0xcb,0x29,0x7d,0x43,0xd2,0x3a,0xc2,0xb4},
15101499      {0x4b,0xa4,0x63,0x46,0xf0,0x91,0xea,0x62},
15111500      {0x4b,0xa4,0x63,0x46,0xf0,0x91,0xea,0x62}};
1512   UINT8 *src = machine.root_device().memregion("ymsnd")->base();
1513   UINT8 *buf = auto_alloc_array(machine, UINT8, 0x1000000);
1501   UINT8 *src = memregion("ymsnd")->base();
1502   UINT8 *buf = auto_alloc_array(machine(), UINT8, 0x1000000);
15141503   int i, j, d;
15151504
15161505   memcpy(buf,src,0x1000000);
r21155r21156
15211510      d=((i+addrs[value][0])&0xffffff);
15221511      src[j]=buf[d]^xordata[value][j&0x7];
15231512   }
1524   auto_free(machine, buf);
1513   auto_free(machine(), buf);
15251514}
15261515
15271516
r21155r21156
15331522
15341523
15351524/* only found on kf2k3pcb */
1536void kof2003biosdecode(running_machine &machine)
1525void neogeo_state::kof2003biosdecode()
15371526{
15381527   static const UINT8 address[0x80]={
15391528      0xb9,0xb8,0x36,0x37,0x3d,0x3c,0xb2,0xb3,
r21155r21156
15531542      0xd3,0xd2,0x5c,0x5d,0x57,0x56,0xd8,0xd9,
15541543      0xd3,0xd2,0x5c,0x5d,0x57,0x56,0xd8,0xd9,
15551544   };
1556   UINT16*src= (UINT16*)machine.root_device().memregion( "mainbios" )->base();
1557   UINT16*buf= auto_alloc_array(machine, UINT16, 0x80000/2);
1545   UINT16*src= (UINT16*)memregion( "mainbios" )->base();
1546   UINT16*buf= auto_alloc_array(machine(), UINT16, 0x80000/2);
15581547   int a,addr;
15591548
15601549   for (a=0;a<0x80000/2;a++)
r21155r21156
15741563      buf[addr]=src[a];
15751564   }
15761565   memcpy(src,buf,0x80000);
1577   auto_free(machine, buf);
1566   auto_free(machine(), buf);
15781567}
trunk/src/mame/machine/neoboot.c
r21155r21156
1919/* General Bootleg Functions - used by more than 1 game */
2020
2121
22void neogeo_bootleg_cx_decrypt( running_machine &machine )
22void neogeo_state::neogeo_bootleg_cx_decrypt()
2323{
2424   int i;
25   int cx_size = machine.root_device().memregion( "sprites" )->bytes();
26   UINT8 *rom = machine.root_device().memregion( "sprites" )->base();
27   UINT8 *buf = auto_alloc_array(machine, UINT8, cx_size );
25   int cx_size = memregion( "sprites" )->bytes();
26   UINT8 *rom = memregion( "sprites" )->base();
27   UINT8 *buf = auto_alloc_array(machine(), UINT8, cx_size );
2828
2929   memcpy( buf, rom, cx_size );
3030
r21155r21156
3232      memcpy( &rom[ i * 0x40 ], &buf[ (i ^ 1) * 0x40 ], 0x40 );
3333   }
3434
35   auto_free( machine, buf );
35   auto_free( machine(), buf );
3636}
3737
3838
39void neogeo_bootleg_sx_decrypt( running_machine &machine, int value )
39void neogeo_state::neogeo_bootleg_sx_decrypt(int value )
4040{
41   int sx_size = machine.root_device().memregion( "fixed" )->bytes();
42   UINT8 *rom = machine.root_device().memregion( "fixed" )->base();
41   int sx_size = memregion( "fixed" )->bytes();
42   UINT8 *rom = memregion( "fixed" )->base();
4343   int i;
4444
4545   if (value == 1)
4646   {
47      UINT8 *buf = auto_alloc_array(machine, UINT8, sx_size );
47      UINT8 *buf = auto_alloc_array(machine(), UINT8, sx_size );
4848      memcpy( buf, rom, sx_size );
4949
5050      for( i = 0; i < sx_size; i += 0x10 )
r21155r21156
5252         memcpy( &rom[ i ], &buf[ i + 8 ], 8 );
5353         memcpy( &rom[ i + 8 ], &buf[ i ], 8 );
5454      }
55      auto_free( machine, buf );
55      auto_free( machine(), buf );
5656   }
5757   else if (value == 2)
5858   {
r21155r21156
6868/* The protection patching here may be incomplete
6969   Thanks to Razoola for the info */
7070
71void kog_px_decrypt( running_machine &machine )
71void neogeo_state::kog_px_decrypt()
7272{
7373   /* the protection chip does some *very* strange things to the rom */
74   UINT8 *src = machine.root_device().memregion("maincpu")->base();
75   UINT8 *dst = auto_alloc_array(machine, UINT8, 0x600000 );
76   UINT16 *rom = (UINT16 *)machine.root_device().memregion("maincpu")->base();
74   UINT8 *src = memregion("maincpu")->base();
75   UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x600000 );
76   UINT16 *rom = (UINT16 *)memregion("maincpu")->base();
7777   int i;
7878   static const int sec[] = { 0x3, 0x8, 0x7, 0xC, 0x1, 0xA, 0x6, 0xD };
7979
r21155r21156
8787   memcpy (dst + 0x090000, src + 0x040000, 0x004000);
8888   memcpy (dst + 0x100000, src + 0x200000, 0x400000);
8989   memcpy (src, dst, 0x600000);
90   auto_free (machine, dst);
90   auto_free (machine(), dst);
9191
9292   for (i = 0x90000/2; i < 0x94000/2; i++){
9393      if (((rom[i]&0xFFBF) == 0x4EB9 || rom[i] == 0x43F9) && !rom[i + 1])
r21155r21156
132132
133133/* The King of Fighters '97 Oroshi Plus 2003 (bootleg) */
134134
135void kof97oro_px_decode( running_machine &machine )
135void neogeo_state::kof97oro_px_decode()
136136{
137137   int i;
138   UINT16 *tmp = auto_alloc_array(machine, UINT16, 0x500000 );
139   UINT16 *src = (UINT16*)machine.root_device().memregion("maincpu")->base();
138   UINT16 *tmp = auto_alloc_array(machine(), UINT16, 0x500000 );
139   UINT16 *src = (UINT16*)memregion("maincpu")->base();
140140
141141   for (i = 0; i < 0x500000/2; i++) {
142142      tmp[i] = src[i ^ 0x7ffef];
r21155r21156
144144
145145   memcpy (src, tmp, 0x500000);
146146
147   auto_free (machine, tmp);
147   auto_free (machine(), tmp);
148148}
149149
150150
r21155r21156
155155  is incomplete, at the moment the S data is copied from the program rom on
156156  start-up instead */
157157
158static UINT16 kof10thExtraRAMB[0x01000];
159
160static void kof10thBankswitch(address_space &space, UINT16 nBank)
158void neogeo_state::kof10thBankswitch(address_space &space, UINT16 nBank)
161159{
162160   UINT32 bank = 0x100000 + ((nBank & 7) << 20);
163161   if (bank >= 0x700000)
164162      bank = 0x100000;
165   space.machine().driver_data<neogeo_state>()->neogeo_set_main_cpu_bank_address(bank);
163   neogeo_set_main_cpu_bank_address(bank);
166164}
167165
168static READ16_HANDLER( kof10th_RAMB_r )
166READ16_MEMBER( neogeo_state::kof10th_RAMB_r )
169167{
170168   return kof10thExtraRAMB[offset];
171169}
172170
173static WRITE16_HANDLER( kof10th_custom_w )
171WRITE16_MEMBER( neogeo_state::kof10th_custom_w )
174172{
175173   if (!kof10thExtraRAMB[0xFFE]) { // Write to RAM bank A
176      UINT16 *prom = (UINT16*)space.machine().root_device().memregion( "maincpu" )->base();
174      UINT16 *prom = (UINT16*)memregion( "maincpu" )->base();
177175      COMBINE_DATA(&prom[(0xE0000/2) + (offset & 0xFFFF)]);
178176   } else { // Write S data on-the-fly
179      UINT8 *srom = space.machine().root_device().memregion( "fixed" )->base();
177      UINT8 *srom = memregion( "fixed" )->base();
180178      srom[offset] = BITSWAP8(data,7,6,0,4,3,2,1,5);
181179   }
182180}
183181
184static WRITE16_HANDLER( kof10th_bankswitch_w )
182WRITE16_MEMBER( neogeo_state::kof10th_bankswitch_w )
185183{
186184   if (offset >= 0x5F000) {
187185      if (offset == 0x5FFF8) { // Standard bankswitch
188186         kof10thBankswitch(space, data);
189187      } else if (offset == 0x5FFFC && kof10thExtraRAMB[0xFFC] != data) { // Special bankswitch
190         UINT8 *src = space.machine().root_device().memregion( "maincpu" )->base();
188         UINT8 *src = memregion( "maincpu" )->base();
191189         memcpy (src + 0x10000,  src + ((data & 1) ? 0x810000 : 0x710000), 0xcffff);
192190      }
193191      COMBINE_DATA(&kof10thExtraRAMB[offset & 0xFFF]);
194192   }
195193}
196194
197void install_kof10th_protection ( running_machine &machine )
195void neogeo_state::install_kof10th_protection ()
198196{
199   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x2fe000, 0x2fffff, FUNC(kof10th_RAMB_r));
200   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_write_handler(0x200000, 0x23ffff, FUNC(kof10th_custom_w));
201   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_write_handler(0x240000, 0x2fffff, FUNC(kof10th_bankswitch_w));
197   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x2fe000, 0x2fffff, read16_delegate(FUNC(neogeo_state::kof10th_RAMB_r),this));
198   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x200000, 0x23ffff, write16_delegate(FUNC(neogeo_state::kof10th_custom_w),this));
199   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x240000, 0x2fffff, write16_delegate(FUNC(neogeo_state::kof10th_bankswitch_w),this));
202200}
203201
204void decrypt_kof10th(running_machine &machine)
202void neogeo_state::decrypt_kof10th()
205203{
206204   int i, j;
207   UINT8 *dst = auto_alloc_array(machine, UINT8, 0x900000);
208   UINT8 *src = machine.root_device().memregion( "maincpu" )->base();
205   UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x900000);
206   UINT8 *src = memregion( "maincpu" )->base();
209207
210208   memcpy(dst + 0x000000, src + 0x700000, 0x100000); // Correct (Verified in Uni-bios)
211209   memcpy(dst + 0x100000, src + 0x000000, 0x800000);
r21155r21156
215213      src[j] = dst[i];
216214   }
217215
218   auto_free(machine, dst);
216   auto_free(machine(), dst);
219217
220218   // Altera protection chip patches these over P ROM
221219   ((UINT16*)src)[0x0124/2] = 0x000d; // Enables XOR for RAM moves, forces SoftDIPs, and USA region
r21155r21156
230228/* The King of Fighters 10th Anniversary Extra Plus (The King of Fighters 2002 bootleg) */
231229
232230
233void decrypt_kf10thep(running_machine &machine)
231void neogeo_state::decrypt_kf10thep()
234232{
235233   int i;
236   UINT16 *rom = (UINT16*)machine.root_device().memregion("maincpu")->base();
237   UINT8  *src = machine.root_device().memregion("maincpu")->base();
238   UINT16 *buf = (UINT16*)machine.root_device().memregion("audiocrypt")->base();
239   UINT8 *srom = (UINT8*)machine.root_device().memregion("fixed")->base();
240   UINT8 *sbuf = auto_alloc_array(machine, UINT8, 0x20000);
234   UINT16 *rom = (UINT16*)memregion("maincpu")->base();
235   UINT8  *src = memregion("maincpu")->base();
236   UINT16 *buf = (UINT16*)memregion("audiocrypt")->base();
237   UINT8 *srom = (UINT8*)memregion("fixed")->base();
238   UINT8 *sbuf = auto_alloc_array(machine(), UINT8, 0x20000);
241239
242   UINT8 *dst = auto_alloc_array(machine, UINT8, 0x200000);
240   UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x200000);
243241
244242   memcpy(dst,buf,0x200000);
245243   memcpy(src+0x000000,dst+0x060000,0x20000);
r21155r21156
258256      if (rom[i+0] == 0x4ef9 && rom[i+1] == 0x0000) rom[i+1] = 0x000F; // correct JMP in moved code
259257   }
260258   rom[0x00342/2] = 0x000f;
261   auto_free(machine, dst);
259   auto_free(machine(), dst);
262260
263261   for (i=0;i<0x20000;i++)
264262      sbuf[i]=srom[i^0x8];
265263
266264   memcpy(srom,sbuf,0x20000);
267   auto_free(machine, sbuf);
265   auto_free(machine(), sbuf);
268266}
269267
270268
271269/* The King of Fighters 10th Anniversary 2005 Unique (The King of Fighters 2002 bootleg) */
272270
273271
274static void kf2k5uni_px_decrypt( running_machine &machine )
272void neogeo_state::kf2k5uni_px_decrypt()
275273{
276274   int i, j, ofst;
277   UINT8 *src = machine.root_device().memregion( "maincpu" )->base();
278   UINT8 *dst = auto_alloc_array(machine, UINT8, 0x80);
275   UINT8 *src = memregion( "maincpu" )->base();
276   UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x80);
279277
280278   for (i = 0; i < 0x800000; i+=0x80)
281279   {
r21155r21156
286284      }
287285      memcpy(src + i, dst, 0x80);
288286   }
289   auto_free(machine, dst);
287   auto_free(machine(), dst);
290288
291289   memcpy(src, src + 0x600000, 0x100000); // Seems to be the same as kof10th
292290}
293291
294static void kf2k5uni_sx_decrypt( running_machine &machine )
292void neogeo_state::kf2k5uni_sx_decrypt()
295293{
296294   int i;
297   UINT8 *srom = machine.root_device().memregion( "fixed" )->base();
295   UINT8 *srom = memregion( "fixed" )->base();
298296
299297   for (i = 0; i < 0x20000; i++)
300298      srom[i] = BITSWAP8(srom[i], 4, 5, 6, 7, 0, 1, 2, 3);
301299}
302300
303static void kf2k5uni_mx_decrypt( running_machine &machine )
301void neogeo_state::kf2k5uni_mx_decrypt()
304302{
305303   int i;
306   UINT8 *mrom = machine.root_device().memregion( "audiocpu" )->base();
304   UINT8 *mrom = memregion( "audiocpu" )->base();
307305
308306   for (i = 0; i < 0x30000; i++)
309307      mrom[i] = BITSWAP8(mrom[i], 4, 5, 6, 7, 0, 1, 2, 3);
310308}
311309
312void decrypt_kf2k5uni( running_machine &machine )
310void neogeo_state::decrypt_kf2k5uni()
313311{
314   kf2k5uni_px_decrypt(machine);
315   kf2k5uni_sx_decrypt(machine);
316   kf2k5uni_mx_decrypt(machine);
312   kf2k5uni_px_decrypt();
313   kf2k5uni_sx_decrypt();
314   kf2k5uni_mx_decrypt();
317315}
318316
319317
r21155r21156
321319
322320
323321// Thanks to IQ_132 for the info
324void kof2002b_gfx_decrypt(running_machine &machine, UINT8 *src, int size)
322void neogeo_state::kof2002b_gfx_decrypt(UINT8 *src, int size)
325323{
326324   int i, j;
327325   int t[ 8 ][ 10 ] =
r21155r21156
336334      { 8, 0, 7, 3, 4, 5, 6, 2, 1 },
337335   };
338336
339   UINT8 *dst = auto_alloc_array(machine, UINT8,  0x10000 );
337   UINT8 *dst = auto_alloc_array(machine(), UINT8,  0x10000 );
340338
341339   for ( i = 0; i < size; i+=0x10000 )
342340   {
r21155r21156
350348         memcpy( src+i+ofst*128, dst+j*128, 128 );
351349      }
352350   }
353   auto_free( machine, dst );
351   auto_free( machine(), dst );
354352}
355353
356354
357355/* The King of Fighters 2002 Magic Plus (bootleg) */
358356
359357
360void kf2k2mp_decrypt( running_machine &machine )
358void neogeo_state::kf2k2mp_decrypt()
361359{
362360   int i,j;
363361
364   UINT8 *src = machine.root_device().memregion("maincpu")->base();
365   UINT8 *dst = auto_alloc_array(machine, UINT8, 0x80);
362   UINT8 *src = memregion("maincpu")->base();
363   UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x80);
366364
367365   memmove(src, src + 0x300000, 0x500000);
368366
r21155r21156
375373      }
376374      memcpy(src + i, dst, 0x80);
377375   }
378   auto_free(machine, dst);
376   auto_free(machine(), dst);
379377}
380378
381379
382380/* The King of Fighters 2002 Magic Plus II (bootleg) */
383381
384382
385void kf2k2mp2_px_decrypt( running_machine &machine )
383void neogeo_state::kf2k2mp2_px_decrypt()
386384{
387   UINT8 *src = machine.root_device().memregion("maincpu")->base();
388   UINT8 *dst = auto_alloc_array(machine, UINT8, 0x600000);
385   UINT8 *src = memregion("maincpu")->base();
386   UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x600000);
389387
390388   memcpy (dst + 0x000000, src + 0x1C0000, 0x040000);
391389   memcpy (dst + 0x040000, src + 0x140000, 0x080000);
392390   memcpy (dst + 0x0C0000, src + 0x100000, 0x040000);
393391   memcpy (dst + 0x100000, src + 0x200000, 0x400000);
394392   memcpy (src + 0x000000, dst + 0x000000, 0x600000);
395   auto_free (machine, dst);
393   auto_free (machine(), dst);
396394}
397395
398396
r21155r21156
400398
401399
402400/* descrambling information from razoola */
403static void cthd2003_neogeo_gfx_address_fix_do(running_machine &machine, int start, int end, int bit3shift, int bit2shift, int bit1shift, int bit0shift)
401void neogeo_state::cthd2003_neogeo_gfx_address_fix_do(int start, int end, int bit3shift, int bit2shift, int bit1shift, int bit0shift)
404402{
405403   int i,j;
406404   int tilesize=128;
407405
408   UINT8* rom = auto_alloc_array(machine, UINT8, 16*tilesize); // 16 tiles buffer
409   UINT8* realrom = machine.root_device().memregion("sprites")->base() + start*tilesize;
406   UINT8* rom = auto_alloc_array(machine(), UINT8, 16*tilesize); // 16 tiles buffer
407   UINT8* realrom = memregion("sprites")->base() + start*tilesize;
410408
411409   for (i = 0; i < (end-start)/16; i++) {
412410      for (j = 0; j < 16; j++) {
r21155r21156
420418      memcpy(realrom,rom,tilesize*16);
421419      realrom+=16*tilesize;
422420   }
423   auto_free(machine, rom);
421   auto_free(machine(), rom);
424422}
425423
426static void cthd2003_neogeo_gfx_address_fix(running_machine &machine, int start, int end)
424void neogeo_state::cthd2003_neogeo_gfx_address_fix(int start, int end)
427425{
428   cthd2003_neogeo_gfx_address_fix_do(machine, start+512*0, end+512*0, 0,3,2,1);
429   cthd2003_neogeo_gfx_address_fix_do(machine, start+512*1, end+512*1, 1,0,3,2);
430   cthd2003_neogeo_gfx_address_fix_do(machine, start+512*2, end+512*2, 2,1,0,3);
426   cthd2003_neogeo_gfx_address_fix_do(start+512*0, end+512*0, 0,3,2,1);
427   cthd2003_neogeo_gfx_address_fix_do(start+512*1, end+512*1, 1,0,3,2);
428   cthd2003_neogeo_gfx_address_fix_do(start+512*2, end+512*2, 2,1,0,3);
431429   // skip 3 & 4
432   cthd2003_neogeo_gfx_address_fix_do(machine, start+512*5, end+512*5, 0,1,2,3);
433   cthd2003_neogeo_gfx_address_fix_do(machine, start+512*6, end+512*6, 0,1,2,3);
434   cthd2003_neogeo_gfx_address_fix_do(machine, start+512*7, end+512*7, 0,2,3,1);
430   cthd2003_neogeo_gfx_address_fix_do(start+512*5, end+512*5, 0,1,2,3);
431   cthd2003_neogeo_gfx_address_fix_do(start+512*6, end+512*6, 0,1,2,3);
432   cthd2003_neogeo_gfx_address_fix_do(start+512*7, end+512*7, 0,2,3,1);
435433}
436434
437static void cthd2003_c(running_machine &machine, int pow)
435void neogeo_state::cthd2003_c(int pow)
438436{
439437   int i;
440438
441439   for (i=0; i<=192; i+=8)
442      cthd2003_neogeo_gfx_address_fix(machine, i*512,i*512+512);
440      cthd2003_neogeo_gfx_address_fix(i*512,i*512+512);
443441
444442   for (i=200; i<=392; i+=8)
445      cthd2003_neogeo_gfx_address_fix(machine, i*512,i*512+512);
443      cthd2003_neogeo_gfx_address_fix(i*512,i*512+512);
446444
447445   for (i=400; i<=592; i+=8)
448      cthd2003_neogeo_gfx_address_fix(machine, i*512,i*512+512);
446      cthd2003_neogeo_gfx_address_fix(i*512,i*512+512);
449447
450448   for (i=600; i<=792; i+=8)
451      cthd2003_neogeo_gfx_address_fix(machine, i*512,i*512+512);
449      cthd2003_neogeo_gfx_address_fix(i*512,i*512+512);
452450
453451   for (i=800; i<=992; i+=8)
454      cthd2003_neogeo_gfx_address_fix(machine, i*512,i*512+512);
452      cthd2003_neogeo_gfx_address_fix(i*512,i*512+512);
455453
456454   for (i=1000; i<=1016; i+=8)
457      cthd2003_neogeo_gfx_address_fix(machine, i*512,i*512+512);
455      cthd2003_neogeo_gfx_address_fix(i*512,i*512+512);
458456}
459457
460void decrypt_cthd2003( running_machine &machine )
458void neogeo_state::decrypt_cthd2003()
461459{
462   UINT8 *romdata = machine.root_device().memregion("fixed")->base();
463   UINT8 *tmp = auto_alloc_array(machine, UINT8, 8*128*128);
460   UINT8 *romdata = memregion("fixed")->base();
461   UINT8 *tmp = auto_alloc_array(machine(), UINT8, 8*128*128);
464462
465463   memcpy(tmp+8*0*128, romdata+8*0*128, 8*32*128);
466464   memcpy(tmp+8*32*128, romdata+8*64*128, 8*32*128);
r21155r21156
468466   memcpy(tmp+8*96*128, romdata+8*96*128, 8*32*128);
469467   memcpy(romdata, tmp, 8*128*128);
470468
471   romdata = machine.root_device().memregion("audiocpu")->base()+0x10000;
469   romdata = memregion("audiocpu")->base()+0x10000;
472470   memcpy(tmp+8*0*128, romdata+8*0*128, 8*32*128);
473471   memcpy(tmp+8*32*128, romdata+8*64*128, 8*32*128);
474472   memcpy(tmp+8*64*128, romdata+8*32*128, 8*32*128);
475473   memcpy(tmp+8*96*128, romdata+8*96*128, 8*32*128);
476474   memcpy(romdata, tmp, 8*128*128);
477475
478   auto_free(machine, tmp);
476   auto_free(machine(), tmp);
479477
480478   memcpy(romdata-0x10000,romdata,0x10000);
481479
482   cthd2003_c(machine, 0);
480   cthd2003_c(0);
483481}
484482
485static WRITE16_HANDLER ( cthd2003_bankswitch_w )
483WRITE16_MEMBER( neogeo_state::cthd2003_bankswitch_w )
486484{
487485   int bankaddress;
488486   static const int cthd2003_banks[8] =
r21155r21156
492490   if (offset == 0)
493491   {
494492      bankaddress = 0x100000 + cthd2003_banks[data&7]*0x100000;
495      space.machine().driver_data<neogeo_state>()->neogeo_set_main_cpu_bank_address(bankaddress);
493      neogeo_set_main_cpu_bank_address(bankaddress);
496494   }
497495}
498496
499void patch_cthd2003( running_machine &machine )
497void neogeo_state::patch_cthd2003()
500498{
501499   /* patches thanks to razoola */
502500   int i;
503   UINT16 *mem16 = (UINT16 *)machine.root_device().memregion("maincpu")->base();
501   UINT16 *mem16 = (UINT16 *)memregion("maincpu")->base();
504502
505503   /* special ROM banking handler */
506   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_write_handler(0x2ffff0, 0x2fffff, FUNC(cthd2003_bankswitch_w));
504   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x2ffff0, 0x2fffff, write16_delegate(FUNC(neogeo_state::cthd2003_bankswitch_w),this));
507505
508506   // theres still a problem on the character select screen but it seems to be related to cpu core timing issues,
509507   // overclocking the 68k prevents it.
r21155r21156
541539/* Crouching Tiger Hidden Dragon 2003 Super Plus (bootleg of King of Fighters 2001) */
542540
543541
544static void ct2k3sp_sx_decrypt( running_machine &machine )
542void neogeo_state::ct2k3sp_sx_decrypt()
545543{
546   int rom_size = machine.root_device().memregion( "fixed" )->bytes();
547   UINT8 *rom = machine.root_device().memregion( "fixed" )->base();
548   UINT8 *buf = auto_alloc_array(machine, UINT8,  rom_size );
544   int rom_size = memregion( "fixed" )->bytes();
545   UINT8 *rom = memregion( "fixed" )->base();
546   UINT8 *buf = auto_alloc_array(machine(), UINT8,  rom_size );
549547   int i;
550548   int ofst;
551549
r21155r21156
568566   memcpy( &rom[ 0x28000 ], &buf[ 0x30000 ], 0x8000 );
569567   memcpy( &rom[ 0x30000 ], &buf[ 0x28000 ], 0x8000 );
570568
571   auto_free( machine, buf );
569   auto_free( machine(), buf );
572570}
573571
574void decrypt_ct2k3sp( running_machine &machine )
572void neogeo_state::decrypt_ct2k3sp()
575573{
576   UINT8 *romdata = machine.root_device().memregion("audiocpu")->base()+0x10000;
577   UINT8*tmp = auto_alloc_array(machine, UINT8, 8*128*128);
574   UINT8 *romdata = memregion("audiocpu")->base()+0x10000;
575   UINT8*tmp = auto_alloc_array(machine(), UINT8, 8*128*128);
578576   memcpy(tmp+8*0*128, romdata+8*0*128, 8*32*128);
579577   memcpy(tmp+8*32*128, romdata+8*64*128, 8*32*128);
580578   memcpy(tmp+8*64*128, romdata+8*32*128, 8*32*128);
581579   memcpy(tmp+8*96*128, romdata+8*96*128, 8*32*128);
582580   memcpy(romdata, tmp, 8*128*128);
583581
584   auto_free(machine, tmp);
582   auto_free(machine(), tmp);
585583   memcpy(romdata-0x10000,romdata,0x10000);
586   ct2k3sp_sx_decrypt(machine);
587   cthd2003_c(machine, 0);
584   ct2k3sp_sx_decrypt();
585   cthd2003_c(0);
588586}
589587
590588
591589/* Crouching Tiger Hidden Dragon 2003 Super Plus alternate (bootleg of King of Fighters 2001) */
592590
593591
594void decrypt_ct2k3sa( running_machine &machine )
592void neogeo_state::decrypt_ct2k3sa()
595593{
596   UINT8 *romdata = machine.root_device().memregion("audiocpu")->base()+0x10000;
597   UINT8*tmp = auto_alloc_array(machine, UINT8, 8*128*128);
594   UINT8 *romdata = memregion("audiocpu")->base()+0x10000;
595   UINT8*tmp = auto_alloc_array(machine(), UINT8, 8*128*128);
598596   memcpy(tmp+8*0*128, romdata+8*0*128, 8*32*128);
599597   memcpy(tmp+8*32*128, romdata+8*64*128, 8*32*128);
600598   memcpy(tmp+8*64*128, romdata+8*32*128, 8*32*128);
601599   memcpy(tmp+8*96*128, romdata+8*96*128, 8*32*128);
602600   memcpy(romdata, tmp, 8*128*128);
603601
604   auto_free(machine, tmp);
602   auto_free(machine(), tmp);
605603   memcpy(romdata-0x10000,romdata,0x10000);
606   cthd2003_c(machine, 0);
604   cthd2003_c(0);
607605}
608606
609void patch_ct2k3sa( running_machine &machine )
607void neogeo_state::patch_ct2k3sa()
610608{
611609   /* patches thanks to razoola - same as for cthd2003*/
612610   int i;
613   UINT16 *mem16 = (UINT16 *)machine.root_device().memregion("maincpu")->base();
611   UINT16 *mem16 = (UINT16 *)memregion("maincpu")->base();
614612
615613   // theres still a problem on the character select screen but it seems to be related to cpu core timing issues,
616614   // overclocking the 68k prevents it.
r21155r21156
649647/* King of Fighters Special Edition 2004 (bootleg of King of Fighters 2002) */
650648
651649
652void decrypt_kof2k4se_68k( running_machine &machine )
650void neogeo_state::decrypt_kof2k4se_68k()
653651{
654   UINT8 *src = machine.root_device().memregion("maincpu")->base()+0x100000;
655   UINT8 *dst = auto_alloc_array(machine, UINT8, 0x400000);
652   UINT8 *src = memregion("maincpu")->base()+0x100000;
653   UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x400000);
656654   int i;
657655   static const int sec[] = {0x300000,0x200000,0x100000,0x000000};
658656   memcpy(dst,src,0x400000);
r21155r21156
661659   {
662660      memcpy(src+i*0x100000,dst+sec[i],0x100000);
663661   }
664   auto_free(machine, dst);
662   auto_free(machine(), dst);
665663}
666664
667665
668666/* Lansquenet 2004 (Shock Troopers - 2nd Squad bootleg) */
669667
670668
671void lans2004_vx_decrypt( running_machine &machine )
669void neogeo_state::lans2004_vx_decrypt()
672670{
673671   int i;
674   UINT8 *rom = machine.root_device().memregion( "ymsnd" )->base();
672   UINT8 *rom = memregion( "ymsnd" )->base();
675673   for (i = 0; i < 0xA00000; i++)
676674      rom[i] = BITSWAP8(rom[i], 0, 1, 5, 4, 3, 2, 6, 7);
677675}
678676
679void lans2004_decrypt_68k( running_machine &machine )
677void neogeo_state::lans2004_decrypt_68k()
680678{
681679   /* Descrambling P ROMs - Thanks to Razoola for the info */
682680   int i;
683   UINT8 *src = machine.root_device().memregion( "maincpu" )->base();
684   UINT16 *rom = (UINT16*)machine.root_device().memregion( "maincpu" )->base();
685   UINT8 *dst = auto_alloc_array(machine, UINT8, 0x600000);
681   UINT8 *src = memregion( "maincpu" )->base();
682   UINT16 *rom = (UINT16*)memregion( "maincpu" )->base();
683   UINT8 *dst = auto_alloc_array(machine(), UINT8, 0x600000);
686684
687685   {
688686      static const int sec[] = { 0x3, 0x8, 0x7, 0xC, 0x1, 0xA, 0x6, 0xD };
r21155r21156
694692      memcpy (dst + 0x02FFF0, src + 0x1A92BE, 0x000010);
695693      memcpy (dst + 0x100000, src + 0x200000, 0x400000);
696694      memcpy (src, dst, 0x600000);
697      auto_free (machine, dst);
695      auto_free (machine(), dst);
698696   }
699697
700698   for (i = 0xBBB00/2; i < 0xBE000/2; i++) {
r21155r21156
718716/* Metal Slug 5 Plus (bootleg) */
719717
720718
721static READ16_HANDLER( mslug5_prot_r )
719READ16_MEMBER( neogeo_state::mslug5_prot_r )
722720{
723721   logerror("PC %06x: access protected\n",space.device().safe_pc());
724722   return 0xa0;
725723}
726724
727static WRITE16_HANDLER ( ms5plus_bankswitch_w )
725WRITE16_MEMBER( neogeo_state::ms5plus_bankswitch_w )
728726{
729727   int bankaddress;
730728   logerror("offset: %06x PC %06x: set banking %04x\n",offset,space.device().safe_pc(),data);
731729   if ((offset == 0)&&(data == 0xa0))
732730   {
733731      bankaddress=0xa0;
734      space.machine().driver_data<neogeo_state>()->neogeo_set_main_cpu_bank_address(bankaddress);
732      neogeo_set_main_cpu_bank_address(bankaddress);
735733      logerror("offset: %06x PC %06x: set banking %04x\n\n",offset,space.device().safe_pc(),bankaddress);
736734   }
737735   else if(offset == 2)
r21155r21156
739737      data=data>>4;
740738      //data=data&7;
741739      bankaddress=data*0x100000;
742      space.machine().driver_data<neogeo_state>()->neogeo_set_main_cpu_bank_address(bankaddress);
740      neogeo_set_main_cpu_bank_address(bankaddress);
743741      logerror("offset: %06x PC %06x: set banking %04x\n\n",offset,space.device().safe_pc(),bankaddress);
744742   }
745743}
746744
747void install_ms5plus_protection(running_machine &machine)
745void neogeo_state::install_ms5plus_protection()
748746{
749747   // special ROM banking handler / additional protection
750   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x2ffff0, 0x2fffff,FUNC(mslug5_prot_r), FUNC(ms5plus_bankswitch_w));
748   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x2ffff0, 0x2fffff,read16_delegate(FUNC(neogeo_state::mslug5_prot_r),this), write16_delegate(FUNC(neogeo_state::ms5plus_bankswitch_w),this));
751749}
752750
753751
754752/* SNK vs. CAPCOM SVC CHAOS (bootleg) */
755753
756754
757void svcboot_px_decrypt( running_machine &machine )
755void neogeo_state::svcboot_px_decrypt()
758756{
759757   static const UINT8 sec[] = {
760758      0x06, 0x07, 0x01, 0x02, 0x03, 0x04, 0x05, 0x00
761759   };
762760   int i;
763   int size = machine.root_device().memregion( "maincpu" )->bytes();
764   UINT8 *src = machine.root_device().memregion( "maincpu" )->base();
765   UINT8 *dst = auto_alloc_array(machine, UINT8,  size );
761   int size = memregion( "maincpu" )->bytes();
762   UINT8 *src = memregion( "maincpu" )->base();
763   UINT8 *dst = auto_alloc_array(machine(), UINT8,  size );
766764   int ofst;
767765   for( i = 0; i < size / 0x100000; i++ ){
768766      memcpy( &dst[ i * 0x100000 ], &src[ sec[ i ] * 0x100000 ], 0x100000 );
r21155r21156
772770      ofst += (i & 0xffff00);
773771      memcpy( &src[ i * 2 ], &dst[ ofst * 2 ], 0x02 );
774772   }
775   auto_free( machine, dst );
773   auto_free( machine(), dst );
776774}
777775
778void svcboot_cx_decrypt( running_machine &machine )
776void neogeo_state::svcboot_cx_decrypt()
779777{
780778   static const UINT8 idx_tbl[ 0x10 ] = {
781779      0, 1, 0, 1, 2, 3, 2, 3, 3, 4, 3, 4, 4, 5, 4, 5,
r21155r21156
789787      { 3, 0, 2, 1 },
790788   };
791789   int i;
792   int size = machine.root_device().memregion( "sprites" )->bytes();
793   UINT8 *src = machine.root_device().memregion( "sprites" )->base();
794   UINT8 *dst = auto_alloc_array(machine, UINT8,  size );
790   int size = memregion( "sprites" )->bytes();
791   UINT8 *src = memregion( "sprites" )->base();
792   UINT8 *dst = auto_alloc_array(machine(), UINT8,  size );
795793   int ofst;
796794   memcpy( dst, src, size );
797795   for( i = 0; i < size / 0x80; i++ ){
r21155r21156
804802      ofst += (i & 0xfffff00);
805803      memcpy( &src[ i * 0x80 ], &dst[ ofst * 0x80 ], 0x80 );
806804   }
807   auto_free( machine, dst );
805   auto_free( machine(), dst );
808806}
809807
810808
811809/* SNK vs. CAPCOM SVC CHAOS Plus (bootleg set 1) */
812810
813811
814void svcplus_px_decrypt( running_machine &machine )
812void neogeo_state::svcplus_px_decrypt()
815813{
816814   static const int sec[] = {
817815      0x00, 0x03, 0x02, 0x05, 0x04, 0x01
818816   };
819   int size = machine.root_device().memregion( "maincpu" )->bytes();
820   UINT8 *src = machine.root_device().memregion( "maincpu" )->base();
821   UINT8 *dst = auto_alloc_array(machine, UINT8,  size );
817   int size = memregion( "maincpu" )->bytes();
818   UINT8 *src = memregion( "maincpu" )->base();
819   UINT8 *dst = auto_alloc_array(machine(), UINT8,  size );
822820   int i;
823821   int ofst;
824822   memcpy( dst, src, size );
r21155r21156
834832   for( i = 0; i < 6; i++ ){
835833      memcpy( &src[ i * 0x100000 ], &dst[ sec[ i ] * 0x100000 ], 0x100000 );
836834   }
837   auto_free( machine, dst );
835   auto_free( machine(), dst );
838836}
839837
840void svcplus_px_hack( running_machine &machine )
838void neogeo_state::svcplus_px_hack()
841839{
842840   /* patched by the protection chip? */
843   UINT8 *src = machine.root_device().memregion( "maincpu" )->base();
841   UINT8 *src = memregion( "maincpu" )->base();
844842   src[ 0x0f8010 ] = 0x40;
845843   src[ 0x0f8011 ] = 0x04;
846844   src[ 0x0f8012 ] = 0x00;
r21155r21156
855853/* SNK vs. CAPCOM SVC CHAOS Plus (bootleg set 2) */
856854
857855
858void svcplusa_px_decrypt( running_machine &machine )
856void neogeo_state::svcplusa_px_decrypt()
859857{
860858   int i;
861859   static const int sec[] = {
862860      0x01, 0x02, 0x03, 0x04, 0x05, 0x00
863861   };
864   int size = machine.root_device().memregion( "maincpu" )->bytes();
865   UINT8 *src = machine.root_device().memregion( "maincpu" )->base();
866   UINT8 *dst = auto_alloc_array(machine, UINT8,  size );
862   int size = memregion( "maincpu" )->bytes();
863   UINT8 *src = memregion( "maincpu" )->base();
864   UINT8 *dst = auto_alloc_array(machine(), UINT8,  size );
867865   memcpy( dst, src, size );
868866   for( i = 0; i < 6; i++ ){
869867      memcpy( &src[ i * 0x100000 ], &dst[ sec[ i ] * 0x100000 ], 0x100000 );
870868   }
871   auto_free( machine, dst );
869   auto_free( machine(), dst );
872870}
873871
874872
875873/* SNK vs. CAPCOM SVC CHAOS Super Plus (bootleg) */
876874
877875
878void svcsplus_px_decrypt( running_machine &machine )
876void neogeo_state::svcsplus_px_decrypt()
879877{
880878   static const int sec[] = {
881879      0x06, 0x07, 0x01, 0x02, 0x03, 0x04, 0x05, 0x00
882880   };
883   int size = machine.root_device().memregion( "maincpu" )->bytes();
884   UINT8 *src = machine.root_device().memregion( "maincpu" )->base();
885   UINT8 *dst = auto_alloc_array(machine, UINT8,  size );
881   int size = memregion( "maincpu" )->bytes();
882   UINT8 *src = memregion( "maincpu" )->base();
883   UINT8 *dst = auto_alloc_array(machine(), UINT8,  size );
886884   int i;
887885   int ofst;
888886   memcpy( dst, src, size );
r21155r21156
894892      ofst += sec[ (i & 0xf80000) >> 19 ] << 19;
895893      memcpy( &src[ i * 2 ], &dst[ ofst * 2 ], 0x02 );
896894   }
897   auto_free( machine, dst );
895   auto_free( machine(), dst );
898896}
899897
900void svcsplus_px_hack( running_machine &machine )
898void neogeo_state::svcsplus_px_hack()
901899{
902900   /* patched by the protection chip? */
903   UINT16 *mem16 = (UINT16 *)machine.root_device().memregion("maincpu")->base();
901   UINT16 *mem16 = (UINT16 *)memregion("maincpu")->base();
904902   mem16[0x9e90/2] = 0x000f;
905903   mem16[0x9e92/2] = 0xc9c0;
906904   mem16[0xa10c/2] = 0x4eb9;
r21155r21156
909907}
910908
911909#ifdef UNUSED_FUNCTION
912static UINT16 mv0_bank_ram[ 0x10/2 ];
910UINT16 mv0_bank_ram[ 0x10/2 ];
913911
914static READ16_HANDLER( mv0_bankswitch_r )
912READ16_MEMBER( neogeo_state::mv0_bankswitch_r )
915913{
916914   return mv0_bank_ram[ offset ];
917915}
918916
919static WRITE16_HANDLER( mv0_bankswitch_w )
917WRITE16_MEMBER( neogeo_state::mv0_bankswitch_w )
920918{
921919   UINT32 bankaddress = (mv0_bank_ram[ 0 ] >> 8) + (mv0_bank_ram[ 1 ] << 8) + 0x100000;
922920   COMBINE_DATA( &mv0_bank_ram[ offset ] );
923   space.machine().driver_data<neogeo_state>()->neogeo_set_main_cpu_bank_address( bankaddress );
921   neogeo_set_main_cpu_bank_address( bankaddress );
924922}
925923#endif
926924
r21155r21156
928926/* The King of Fighters 2003 (bootleg set 1) */
929927
930928
931static UINT16 kof2003_tbl[4096];
932
933static READ16_HANDLER( kof2003_r)
929READ16_MEMBER( neogeo_state::kof2003_r)
934930{
935931   return kof2003_tbl[offset];
936932}
937933
938static WRITE16_HANDLER( kof2003_w )
934WRITE16_MEMBER( neogeo_state::kof2003_w )
939935{
940936   data = COMBINE_DATA(&kof2003_tbl[offset]);
941937   if (offset == 0x1ff0/2 || offset == 0x1ff2/2) {
942938      UINT8* cr = (UINT8 *)kof2003_tbl;
943939      UINT32 address = (cr[BYTE_XOR_LE(0x1ff3)]<<16)|(cr[BYTE_XOR_LE(0x1ff2)]<<8)|cr[BYTE_XOR_LE(0x1ff1)];
944940      UINT8 prt = cr[BYTE_XOR_LE(0x1ff2)];
945      UINT8* mem = (UINT8 *)space.machine().root_device().memregion("maincpu")->base();
941      UINT8* mem = (UINT8 *)memregion("maincpu")->base();
946942
947943      cr[BYTE_XOR_LE(0x1ff0)] =  0xa0;
948944      cr[BYTE_XOR_LE(0x1ff1)] &= 0xfe;
949945      cr[BYTE_XOR_LE(0x1ff3)] &= 0x7f;
950      space.machine().driver_data<neogeo_state>()->neogeo_set_main_cpu_bank_address(address+0x100000);
946      neogeo_set_main_cpu_bank_address(address+0x100000);
951947
952948      mem[BYTE_XOR_LE(0x58196)] = prt;
953949   }
954950}
955951
956static WRITE16_HANDLER( kof2003p_w )
952WRITE16_MEMBER( neogeo_state::kof2003p_w )
957953{
958954   data = COMBINE_DATA(&kof2003_tbl[offset]);
959955   if (offset == 0x1ff0/2 || offset == 0x1ff2/2) {
960956      UINT8* cr = (UINT8 *)kof2003_tbl;
961957      UINT32 address = (cr[BYTE_XOR_LE(0x1ff3)]<<16)|(cr[BYTE_XOR_LE(0x1ff2)]<<8)|cr[BYTE_XOR_LE(0x1ff0)];
962958      UINT8 prt = cr[BYTE_XOR_LE(0x1ff2)];
963      UINT8* mem = (UINT8 *)space.machine().root_device().memregion("maincpu")->base();
959      UINT8* mem = (UINT8 *)memregion("maincpu")->base();
964960
965961      cr[BYTE_XOR_LE(0x1ff0)] &= 0xfe;
966962      cr[BYTE_XOR_LE(0x1ff3)] &= 0x7f;
967      space.machine().driver_data<neogeo_state>()->neogeo_set_main_cpu_bank_address(address+0x100000);
963      neogeo_set_main_cpu_bank_address(address+0x100000);
968964
969965      mem[BYTE_XOR_LE(0x58196)] = prt;
970966   }
971967}
972968
973void kf2k3bl_px_decrypt( running_machine &machine )
969void neogeo_state::kf2k3bl_px_decrypt()
974970{
975971   int i;
976972   static const UINT8 sec[] = {
r21155r21156
978974   };
979975
980976   int rom_size = 0x800000;
981   UINT8 *rom = machine.root_device().memregion( "maincpu" )->base();
982   UINT8 *buf = auto_alloc_array(machine, UINT8,  rom_size );
977   UINT8 *rom = memregion( "maincpu" )->base();
978   UINT8 *buf = auto_alloc_array(machine(), UINT8,  rom_size );
983979   memcpy( buf, rom, rom_size );
984980
985981   for( i = 0; i < rom_size / 0x100000; i++ ){
986982      memcpy( &rom[ i * 0x100000 ], &buf[ sec[ i ] * 0x100000 ], 0x100000 );
987983   }
988   auto_free( machine, buf );
984   auto_free( machine(), buf );
989985}
990986
991void kf2k3bl_install_protection(running_machine &machine)
987void neogeo_state::kf2k3bl_install_protection()
992988{
993   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x2fe000, 0x2fffff, FUNC(kof2003_r), FUNC(kof2003_w) );
989   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x2fe000, 0x2fffff, read16_delegate(FUNC(neogeo_state::kof2003_r),this), write16_delegate(FUNC(neogeo_state::kof2003_w),this) );
994990}
995991
996992
997993/* The King of Fighters 2004 Plus / Hero (The King of Fighters 2003 bootleg) */
998994
999995
1000void kf2k3pl_px_decrypt( running_machine &machine )
996void neogeo_state::kf2k3pl_px_decrypt()
1001997{
1002   UINT16*tmp = auto_alloc_array(machine, UINT16, 0x100000/2);
1003   UINT16*rom = (UINT16*)machine.root_device().memregion( "maincpu" )->base();
998   UINT16*tmp = auto_alloc_array(machine(), UINT16, 0x100000/2);
999   UINT16*rom = (UINT16*)memregion( "maincpu" )->base();
10041000   int j;
10051001   int i;
10061002
r21155r21156
10101006      for (j = 0;j < 0x100000/2;j++)
10111007         rom[i+j] = tmp[BITSWAP24(j,23,22,21,20,19,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18)];
10121008   }
1013   auto_free(machine, tmp);
1009   auto_free(machine(), tmp);
10141010
10151011   /* patched by Altera protection chip on PCB */
10161012   rom[0xf38ac/2] = 0x4e75;
10171013}
10181014
1019void kf2k3pl_install_protection(running_machine &machine)
1015void neogeo_state::kf2k3pl_install_protection()
10201016{
1021   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x2fe000, 0x2fffff, FUNC(kof2003_r), FUNC(kof2003p_w) );
1017   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x2fe000, 0x2fffff, read16_delegate(FUNC(neogeo_state::kof2003_r),this), write16_delegate(FUNC(neogeo_state::kof2003p_w),this) );
10221018}
10231019
10241020
10251021/* The King of Fighters 2004 Ultra Plus (The King of Fighters 2003 bootleg) */
10261022
10271023
1028void kf2k3upl_px_decrypt( running_machine &machine )
1024void neogeo_state::kf2k3upl_px_decrypt()
10291025{
10301026   {
1031      UINT8 *src = machine.root_device().memregion("maincpu")->base();
1027      UINT8 *src = memregion("maincpu")->base();
10321028      memmove(src+0x100000, src, 0x600000);
10331029      memmove(src, src+0x700000, 0x100000);
10341030   }
r21155r21156
10361032   {
10371033      int ofst;
10381034      int i;
1039      UINT8 *rom = machine.root_device().memregion( "maincpu" )->base() + 0xfe000;
1040      UINT8 *buf = machine.root_device().memregion( "maincpu" )->base() + 0xd0610;
1035      UINT8 *rom = memregion( "maincpu" )->base() + 0xfe000;
1036      UINT8 *buf = memregion( "maincpu" )->base() + 0xd0610;
10411037
10421038      for( i = 0; i < 0x2000 / 2; i++ ){
10431039         ofst = (i & 0xff00) + BITSWAP8( (i & 0x00ff), 7, 6, 0, 4, 3, 2, 1, 5 );
r21155r21156
10461042   }
10471043}
10481044
1049void kf2k3upl_install_protection(running_machine &machine)
1045void neogeo_state::kf2k3upl_install_protection()
10501046{
1051   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x2fe000, 0x2fffff, FUNC(kof2003_r), FUNC(kof2003_w) );
1047   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x2fe000, 0x2fffff, read16_delegate(FUNC(neogeo_state::kof2003_r),this), write16_delegate(FUNC(neogeo_state::kof2003_w),this) );
10521048}
10531049
10541050
10551051/* Samurai Shodown V / Samurai Spirits Zero (bootleg) */
10561052
10571053
1058void samsho5b_px_decrypt( running_machine &machine )
1054void neogeo_state::samsho5b_px_decrypt()
10591055{
1060   int px_size = machine.root_device().memregion( "maincpu" )->bytes();
1061   UINT8 *rom = machine.root_device().memregion( "maincpu" )->base();
1062   UINT8 *buf = auto_alloc_array(machine, UINT8,  px_size );
1056   int px_size = memregion( "maincpu" )->bytes();
1057   UINT8 *rom = memregion( "maincpu" )->base();
1058   UINT8 *buf = auto_alloc_array(machine(), UINT8,  px_size );
10631059   int ofst;
10641060   int i;
10651061
r21155r21156
10781074   memcpy( &rom[ 0x000000 ], &buf[ 0x700000 ], 0x100000 );
10791075   memcpy( &rom[ 0x100000 ], &buf[ 0x000000 ], 0x700000 );
10801076
1081   auto_free( machine, buf );
1077   auto_free( machine(), buf );
10821078}
10831079
10841080
1085void samsho5b_vx_decrypt( running_machine &machine )
1081void neogeo_state::samsho5b_vx_decrypt()
10861082{
1087   int vx_size = machine.root_device().memregion( "ymsnd" )->bytes();
1088   UINT8 *rom = machine.root_device().memregion( "ymsnd" )->base();
1083   int vx_size = memregion( "ymsnd" )->bytes();
1084   UINT8 *rom = memregion( "ymsnd" )->base();
10891085   int i;
10901086
10911087   for( i = 0; i < vx_size; i++ )
r21155r21156
10981094
10991095#define MATRIMBLZ80( i ) ( i^(BITSWAP8(i&0x3,4,3,1,2,0,7,6,5)<<8) )
11001096
1101void matrimbl_decrypt( running_machine &machine )
1097void neogeo_state::matrimbl_decrypt()
11021098{
11031099   /* decrypt Z80 */
1104   UINT8 *rom = machine.root_device().memregion( "audiocpu" )->base()+0x10000;
1105   UINT8 *buf = auto_alloc_array(machine, UINT8,  0x20000 );
1100   UINT8 *rom = memregion( "audiocpu" )->base()+0x10000;
1101   UINT8 *buf = auto_alloc_array(machine(), UINT8,  0x20000 );
11061102   int i, j=0;
11071103   memcpy( buf, rom, 0x20000 );
11081104   for( i=0x00000; i<0x20000; i++ )
r21155r21156
11331129      }
11341130      rom[ j ]=buf[ i ];
11351131   }
1136   auto_free( machine, buf );
1132   auto_free( machine(), buf );
11371133   memcpy( rom-0x10000, rom, 0x10000 );
11381134
11391135   /* decrypt gfx */
1140   cthd2003_c( machine, 0 );
1136   cthd2003_c( 0 );
11411137}
trunk/src/mame/machine/neoprot.c
r21155r21156
2222
2323/************************ Fatal Fury 2 *************************/
2424
25static READ16_HANDLER( fatfury2_protection_16_r )
26{
27   neogeo_state *state = space.machine().driver_data<neogeo_state>();
28   UINT16 res = state->m_fatfury2_prot_data >> 24;
25READ16_MEMBER( neogeo_state::fatfury2_protection_16_r )
26{   
27   UINT16 res = m_fatfury2_prot_data >> 24;
2928
3029   switch (offset)
3130   {
r21155r21156
4847}
4948
5049
51static WRITE16_HANDLER( fatfury2_protection_16_w )
50WRITE16_MEMBER( neogeo_state::fatfury2_protection_16_w )
5251{
53   neogeo_state *state = space.machine().driver_data<neogeo_state>();
54
5552   switch (offset)
5653   {
5754      case 0x11112/2: /* data == 0x1111; expects 0xff000000 back */
58         state->m_fatfury2_prot_data = 0xff000000;
55         m_fatfury2_prot_data = 0xff000000;
5956         break;
6057
6158      case 0x33332/2: /* data == 0x3333; expects 0x0000ffff back */
62         state->m_fatfury2_prot_data = 0x0000ffff;
59         m_fatfury2_prot_data = 0x0000ffff;
6360         break;
6461
6562      case 0x44442/2: /* data == 0x4444; expects 0x00ff0000 back */
66         state->m_fatfury2_prot_data = 0x00ff0000;
63         m_fatfury2_prot_data = 0x00ff0000;
6764         break;
6865
6966      case 0x55552/2: /* data == 0x5555; read back from 55550, ffff0, 00000, ff000 */
70         state->m_fatfury2_prot_data = 0xff00ff00;
67         m_fatfury2_prot_data = 0xff00ff00;
7168         break;
7269
7370      case 0x56782/2: /* data == 0x1234; read back from 36000 *or* 36004 */
74         state->m_fatfury2_prot_data = 0xf05a3601;
71         m_fatfury2_prot_data = 0xf05a3601;
7572         break;
7673
7774      case 0x42812/2: /* data == 0x1824; read back from 36008 *or* 3600c */
78         state->m_fatfury2_prot_data = 0x81422418;
75         m_fatfury2_prot_data = 0x81422418;
7976         break;
8077
8178      case 0x55550/2:
r21155r21156
8582      case 0x36004/2:
8683      case 0x36008/2:
8784      case 0x3600c/2:
88         state->m_fatfury2_prot_data <<= 8;
85         m_fatfury2_prot_data <<= 8;
8986         break;
9087
9188      default:
r21155r21156
9592}
9693
9794
98void fatfury2_install_protection( running_machine &machine )
99{
100   neogeo_state *state = machine.driver_data<neogeo_state>();
101
95void neogeo_state::fatfury2_install_protection()
96{   
10297   /* the protection involves reading and writing addresses in the */
10398   /* 0x2xxxxx range. There are several checks all around the code. */
104   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x200000, 0x2fffff, FUNC(fatfury2_protection_16_r), FUNC(fatfury2_protection_16_w));
99   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x200000, 0x2fffff, read16_delegate(FUNC(neogeo_state::fatfury2_protection_16_r),this), write16_delegate(FUNC(neogeo_state::fatfury2_protection_16_w),this));
105100
106   state->m_fatfury2_prot_data = 0;
101   m_fatfury2_prot_data = 0;
107102
108   state->save_item(NAME(state->m_fatfury2_prot_data));
103   save_item(NAME(m_fatfury2_prot_data));
109104}
110105
111106
r21155r21156
116111  The board has a ALTERA (EPM7128SQC100-15) chip which is tied to 242-P1
117112***************************************************************/
118113
119static WRITE16_HANDLER ( kof98_prot_w )
114WRITE16_MEMBER( neogeo_state::kof98_prot_w )
120115{
121116   /* info from razoola */
122   UINT16* mem16 = (UINT16*)space.machine().root_device().memregion("maincpu")->base();
117   UINT16* mem16 = (UINT16*)memregion("maincpu")->base();
123118
124119   switch (data)
125120   {
r21155r21156
142137}
143138
144139
145void install_kof98_protection( running_machine &machine )
140void neogeo_state::install_kof98_protection()
146141{
147142   /* when 0x20aaaa contains 0x0090 (word) then 0x100 (normally the neogeo header) should return 0x00c200fd worked out using real hw */
148143
149   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_write_handler(0x20aaaa, 0x20aaab, FUNC(kof98_prot_w));
144   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x20aaaa, 0x20aaab, write16_delegate(FUNC(neogeo_state::kof98_prot_w),this));
150145}
151146
152147
r21155r21156
156151  Also found on this special board is a QFP144 labeled with 0103
157152***************************************************************/
158153
159static WRITE16_HANDLER( mslugx_protection_16_w )
154WRITE16_MEMBER( neogeo_state::mslugx_protection_16_w )
160155{
161   neogeo_state *state = space.machine().driver_data<neogeo_state>();
162
163156   switch (offset)
164157   {
165158      case 0x0/2: // start new read?
166         state->m_mslugx_command = 0;
159         m_mslugx_command = 0;
167160      break;
168161
169162      case 0x2/2: // command? These are pulsed with data and then 0
170163      case 0x4/2:
171         state->m_mslugx_command |= data;
164         m_mslugx_command |= data;
172165      break;
173166
174167      case 0x6/2: // finished?
175168      break;
176169
177170      case 0xa/2: // init?
178         state->m_mslugx_counter = 0;
179         state->m_mslugx_command = 0;
171         m_mslugx_counter = 0;
172         m_mslugx_command = 0;
180173      break;
181174
182175      default:
r21155r21156
186179}
187180
188181
189static READ16_HANDLER( mslugx_protection_16_r )
182READ16_MEMBER( neogeo_state::mslugx_protection_16_r )
190183{
191   neogeo_state *state = space.machine().driver_data<neogeo_state>();
192
193184   UINT16 res = 0;
194185
195   switch (state->m_mslugx_command)
186   switch (m_mslugx_command)
196187   {
197188      case 0x0001: { // $3bdc(?) and $3c30 (Register D7)
198         res = (space.read_byte(0xdedd2 + ((state->m_mslugx_counter >> 3) & 0xfff)) >> (~state->m_mslugx_counter & 0x07)) & 1;
199         state->m_mslugx_counter++;
189         res = (space.read_byte(0xdedd2 + ((m_mslugx_counter >> 3) & 0xfff)) >> (~m_mslugx_counter & 0x07)) & 1;
190         m_mslugx_counter++;
200191      }
201192      break;
202193
r21155r21156
215206}
216207
217208
218void mslugx_install_protection( running_machine &machine )
209void neogeo_state::mslugx_install_protection()
219210{
220   neogeo_state *state = machine.driver_data<neogeo_state>();
211   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x2fffe0, 0x2fffef, read16_delegate(FUNC(neogeo_state::mslugx_protection_16_r),this), write16_delegate(FUNC(neogeo_state::mslugx_protection_16_w),this));
221212
222   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x2fffe0, 0x2fffef, FUNC(mslugx_protection_16_r), FUNC(mslugx_protection_16_w));
223
224   state->save_item(NAME(state->m_mslugx_command));
225   state->save_item(NAME(state->m_mslugx_counter));
213   save_item(NAME(m_mslugx_command));
214   save_item(NAME(m_mslugx_counter));
226215}
227216
228217
r21155r21156
230219  thanks to Razoola
231220***************************************************************/
232221
233static WRITE16_HANDLER( kof99_bankswitch_w )
222WRITE16_MEMBER( neogeo_state::kof99_bankswitch_w )
234223{
235224   int bankaddress;
236225   static const int bankoffset[64] =
r21155r21156
257246
258247   bankaddress = 0x100000 + bankoffset[data];
259248
260   space.machine().driver_data<neogeo_state>()->neogeo_set_main_cpu_bank_address(bankaddress);
249   neogeo_set_main_cpu_bank_address(bankaddress);
261250}
262251
263252
264static WRITE16_HANDLER( garou_bankswitch_w )
253WRITE16_MEMBER( neogeo_state::garou_bankswitch_w )
265254{
266255   /* thanks to Razoola and Mr K for the info */
267256   int bankaddress;
r21155r21156
294283
295284   bankaddress = 0x100000 + bankoffset[data];
296285
297   space.machine().driver_data<neogeo_state>()->neogeo_set_main_cpu_bank_address(bankaddress);
286   neogeo_set_main_cpu_bank_address(bankaddress);
298287}
299288
300289
301static WRITE16_HANDLER( garouh_bankswitch_w )
290WRITE16_MEMBER( neogeo_state::garouh_bankswitch_w )
302291{
303292   /* thanks to Razoola and Mr K for the info */
304293   int bankaddress;
r21155r21156
333322
334323   bankaddress = 0x100000 + bankoffset[data];
335324
336   space.machine().driver_data<neogeo_state>()->neogeo_set_main_cpu_bank_address(bankaddress);
325   neogeo_set_main_cpu_bank_address(bankaddress);
337326}
338327
339328
340static WRITE16_HANDLER( mslug3_bankswitch_w )
329WRITE16_MEMBER( neogeo_state::mslug3_bankswitch_w )
341330{
342331   /* thanks to Razoola and Mr K for the info */
343332   int bankaddress;
r21155r21156
369358
370359   bankaddress = 0x100000 + bankoffset[data];
371360
372   space.machine().driver_data<neogeo_state>()->neogeo_set_main_cpu_bank_address(bankaddress);
361   neogeo_set_main_cpu_bank_address(bankaddress);
373362}
374363
375364
376static WRITE16_HANDLER( kof2000_bankswitch_w )
365WRITE16_MEMBER( neogeo_state::kof2000_bankswitch_w )
377366{
378367   /* thanks to Razoola and Mr K for the info */
379368   int bankaddress;
r21155r21156
401390
402391   bankaddress = 0x100000 + bankoffset[data];
403392
404   space.machine().driver_data<neogeo_state>()->neogeo_set_main_cpu_bank_address(bankaddress);
393   neogeo_set_main_cpu_bank_address(bankaddress);
405394}
406395
407396
408static READ16_HANDLER( prot_9a37_r )
397READ16_MEMBER( neogeo_state::prot_9a37_r )
409398{
410399   return 0x9a37;
411400}
r21155r21156
414403/* information about the sma random number generator provided by razoola */
415404/* this RNG is correct for KOF99, other games might be different */
416405
417static READ16_HANDLER( sma_random_r )
406READ16_MEMBER( neogeo_state::sma_random_r )
418407{
419   neogeo_state *state = space.machine().driver_data<neogeo_state>();
420   UINT16 old = state->m_neogeo_rng;
408   UINT16 old = m_neogeo_rng;
421409
422   UINT16 newbit = ((state->m_neogeo_rng >> 2) ^
423                  (state->m_neogeo_rng >> 3) ^
424                  (state->m_neogeo_rng >> 5) ^
425                  (state->m_neogeo_rng >> 6) ^
426                  (state->m_neogeo_rng >> 7) ^
427                  (state->m_neogeo_rng >>11) ^
428                  (state->m_neogeo_rng >>12) ^
429                  (state->m_neogeo_rng >>15)) & 1;
410   UINT16 newbit = ((m_neogeo_rng >> 2) ^
411                  (m_neogeo_rng >> 3) ^
412                  (m_neogeo_rng >> 5) ^
413                  (m_neogeo_rng >> 6) ^
414                  (m_neogeo_rng >> 7) ^
415                  (m_neogeo_rng >>11) ^
416                  (m_neogeo_rng >>12) ^
417                  (m_neogeo_rng >>15)) & 1;
430418
431   state->m_neogeo_rng = (state->m_neogeo_rng << 1) | newbit;
419   m_neogeo_rng = (m_neogeo_rng << 1) | newbit;
432420
433421   return old;
434422}
435423
436424
437void neogeo_reset_rng( running_machine &machine )
425void neogeo_state::neogeo_reset_rng()
438426{
439   neogeo_state *state = machine.driver_data<neogeo_state>();
440   state->m_neogeo_rng = 0x2345;
427   m_neogeo_rng = 0x2345;
441428}
442429
443430
444static void sma_install_random_read_handler( running_machine &machine, int addr1, int addr2 )
431void neogeo_state::sma_install_random_read_handler(int addr1, int addr2 )
445432{
446   neogeo_state *state = machine.driver_data<neogeo_state>();
447   state->save_item(NAME(state->m_neogeo_rng));
433   save_item(NAME(m_neogeo_rng));
448434
449   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(addr1, addr1 + 1, FUNC(sma_random_r));
450   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(addr2, addr2 + 1, FUNC(sma_random_r));
435   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(addr1, addr1 + 1, read16_delegate(FUNC(neogeo_state::sma_random_r),this));
436   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(addr2, addr2 + 1, read16_delegate(FUNC(neogeo_state::sma_random_r),this));
451437}
452438
453439
454void kof99_install_protection( running_machine &machine )
440void neogeo_state::kof99_install_protection()
455441{
456   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_write_handler(0x2ffff0, 0x2ffff1, FUNC(kof99_bankswitch_w));
457   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x2fe446, 0x2fe447, FUNC(prot_9a37_r));
442   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x2ffff0, 0x2ffff1, write16_delegate(FUNC(neogeo_state::kof99_bankswitch_w),this));
443   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x2fe446, 0x2fe447, read16_delegate(FUNC(neogeo_state::prot_9a37_r),this));
458444
459   sma_install_random_read_handler(machine, 0x2ffff8, 0x2ffffa);
445   sma_install_random_read_handler(0x2ffff8, 0x2ffffa);
460446}
461447
462448
463void garou_install_protection( running_machine &machine )
449void neogeo_state::garou_install_protection()
464450{
465   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_write_handler(0x2fffc0, 0x2fffc1, FUNC(garou_bankswitch_w));
466   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x2fe446, 0x2fe447, FUNC(prot_9a37_r));
451   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x2fffc0, 0x2fffc1, write16_delegate(FUNC(neogeo_state::garou_bankswitch_w),this));
452   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x2fe446, 0x2fe447, read16_delegate(FUNC(neogeo_state::prot_9a37_r),this));
467453
468   sma_install_random_read_handler(machine, 0x2fffcc, 0x2ffff0);
454   sma_install_random_read_handler(0x2fffcc, 0x2ffff0);
469455}
470456
471457
472void garouh_install_protection( running_machine &machine )
458void neogeo_state::garouh_install_protection()
473459{
474   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_write_handler(0x2fffc0, 0x2fffc1, FUNC(garouh_bankswitch_w));
475   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x2fe446, 0x2fe447, FUNC(prot_9a37_r));
460   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x2fffc0, 0x2fffc1, write16_delegate(FUNC(neogeo_state::garouh_bankswitch_w),this));
461   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x2fe446, 0x2fe447, read16_delegate(FUNC(neogeo_state::prot_9a37_r),this));
476462
477   sma_install_random_read_handler(machine, 0x2fffcc, 0x2ffff0);
463   sma_install_random_read_handler(0x2fffcc, 0x2ffff0);
478464}
479465
480466
481void mslug3_install_protection( running_machine &machine )
467void neogeo_state::mslug3_install_protection()
482468{
483   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_write_handler(0x2fffe4, 0x2fffe5, FUNC(mslug3_bankswitch_w));
484   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x2fe446, 0x2fe447, FUNC(prot_9a37_r));
469   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x2fffe4, 0x2fffe5, write16_delegate(FUNC(neogeo_state::mslug3_bankswitch_w),this));
470   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x2fe446, 0x2fe447, read16_delegate(FUNC(neogeo_state::prot_9a37_r),this));
485471
486//  sma_install_random_read_handler(machine, 0x2ffff8, 0x2ffffa);
472//  sma_install_random_read_handler(0x2ffff8, 0x2ffffa);
487473}
488474
489475
490void kof2000_install_protection( running_machine &machine )
476void neogeo_state::kof2000_install_protection()
491477{
492   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_write_handler(0x2fffec, 0x2fffed, FUNC(kof2000_bankswitch_w));
493   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_read_handler(0x2fe446, 0x2fe447, FUNC(prot_9a37_r));
478   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x2fffec, 0x2fffed, write16_delegate(FUNC(neogeo_state::kof2000_bankswitch_w),this));
479   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x2fe446, 0x2fe447, read16_delegate(FUNC(neogeo_state::prot_9a37_r),this));
494480
495   sma_install_random_read_handler(machine, 0x2fffd8, 0x2fffda);
481   sma_install_random_read_handler(0x2fffd8, 0x2fffda);
496482}
497483
498484
r21155r21156
501487  mslug5, svcchaos, kof2003
502488***************************************************************/
503489
504static void pvc_w8( running_machine &machine, offs_t offset, UINT8 data )
490void neogeo_state::pvc_w8(offs_t offset, UINT8 data )
505491{
506   neogeo_state *state = machine.driver_data<neogeo_state>();
507   *(((UINT8*)state->m_pvc_cartridge_ram) + BYTE_XOR_LE(offset)) = data;
492   *(((UINT8*)m_pvc_cartridge_ram) + BYTE_XOR_LE(offset)) = data;
508493}
509494
510495
511static UINT8 pvc_r8( running_machine &machine, offs_t offset )
496UINT8 neogeo_state::pvc_r8(offs_t offset )
512497{
513   neogeo_state *state = machine.driver_data<neogeo_state>();
514   return *(((UINT8*)state->m_pvc_cartridge_ram) + BYTE_XOR_LE(offset));
498   return *(((UINT8*)m_pvc_cartridge_ram) + BYTE_XOR_LE(offset));
515499}
516500
517501
518static void pvc_prot1( running_machine &machine )
502void neogeo_state::pvc_prot1()
519503{
520504   UINT8 b1, b2;
521505
522   b1 = pvc_r8(machine, 0x1fe1);
523   b2 = pvc_r8(machine, 0x1fe0);
524   pvc_w8(machine, 0x1fe2, (((b2 >> 0) & 0xf) << 1) | ((b1 >> 4) & 1));
525   pvc_w8(machine, 0x1fe3, (((b2 >> 4) & 0xf) << 1) | ((b1 >> 5) & 1));
526   pvc_w8(machine, 0x1fe4, (((b1 >> 0) & 0xf) << 1) | ((b1 >> 6) & 1));
527   pvc_w8(machine, 0x1fe5, (b1 >> 7));
506   b1 = pvc_r8(0x1fe1);
507   b2 = pvc_r8(0x1fe0);
508   pvc_w8(0x1fe2, (((b2 >> 0) & 0xf) << 1) | ((b1 >> 4) & 1));
509   pvc_w8(0x1fe3, (((b2 >> 4) & 0xf) << 1) | ((b1 >> 5) & 1));
510   pvc_w8(0x1fe4, (((b1 >> 0) & 0xf) << 1) | ((b1 >> 6) & 1));
511   pvc_w8(0x1fe5, (b1 >> 7));
528512}
529513
530514
531static void pvc_prot2( running_machine &machine ) // on writes to e8/e9/ea/eb
515void neogeo_state::pvc_prot2() // on writes to e8/e9/ea/eb
532516{
533517   UINT8 b1, b2, b3, b4;
534518
535   b1 = pvc_r8(machine, 0x1fe9);
536   b2 = pvc_r8(machine, 0x1fe8);
537   b3 = pvc_r8(machine, 0x1feb);
538   b4 = pvc_r8(machine, 0x1fea);
539   pvc_w8(machine, 0x1fec, (b2 >> 1) | ((b1 >> 1) << 4));
540   pvc_w8(machine, 0x1fed, (b4 >> 1) | ((b2 & 1) << 4) | ((b1 & 1) << 5) | ((b4 & 1) << 6) | ((b3 & 1) << 7));
519   b1 = pvc_r8(0x1fe9);
520   b2 = pvc_r8(0x1fe8);
521   b3 = pvc_r8(0x1feb);
522   b4 = pvc_r8(0x1fea);
523   pvc_w8(0x1fec, (b2 >> 1) | ((b1 >> 1) << 4));
524   pvc_w8(0x1fed, (b4 >> 1) | ((b2 & 1) << 4) | ((b1 & 1) << 5) | ((b4 & 1) << 6) | ((b3 & 1) << 7));
541525}
542526
543527
544static void pvc_write_bankswitch( address_space &space )
528void neogeo_state::pvc_write_bankswitch( address_space &space )
545529{
546   neogeo_state *state = space.machine().driver_data<neogeo_state>();
547530   UINT32 bankaddress;
548531
549   bankaddress = ((state->m_pvc_cartridge_ram[0xff8] >> 8)|(state->m_pvc_cartridge_ram[0xff9] << 8));
550   *(((UINT8 *)state->m_pvc_cartridge_ram) + BYTE_XOR_LE(0x1ff0)) = 0xa0;
551   *(((UINT8 *)state->m_pvc_cartridge_ram) + BYTE_XOR_LE(0x1ff1)) &= 0xfe;
552   *(((UINT8 *)state->m_pvc_cartridge_ram) + BYTE_XOR_LE(0x1ff3)) &= 0x7f;
553   state->neogeo_set_main_cpu_bank_address(bankaddress + 0x100000);
532   bankaddress = ((m_pvc_cartridge_ram[0xff8] >> 8)|(m_pvc_cartridge_ram[0xff9] << 8));
533   *(((UINT8 *)m_pvc_cartridge_ram) + BYTE_XOR_LE(0x1ff0)) = 0xa0;
534   *(((UINT8 *)m_pvc_cartridge_ram) + BYTE_XOR_LE(0x1ff1)) &= 0xfe;
535   *(((UINT8 *)m_pvc_cartridge_ram) + BYTE_XOR_LE(0x1ff3)) &= 0x7f;
536   neogeo_set_main_cpu_bank_address(bankaddress + 0x100000);
554537}
555538
556539
557static READ16_HANDLER( pvc_prot_r )
540READ16_MEMBER( neogeo_state::pvc_prot_r )
558541{
559   neogeo_state *state = space.machine().driver_data<neogeo_state>();
560   return state->m_pvc_cartridge_ram[offset];
542   return m_pvc_cartridge_ram[offset];
561543}
562544
563545
564static WRITE16_HANDLER( pvc_prot_w )
546WRITE16_MEMBER( neogeo_state::pvc_prot_w )
565547{
566   neogeo_state *state = space.machine().driver_data<neogeo_state>();
567
568   COMBINE_DATA(&state->m_pvc_cartridge_ram[offset] );
548   COMBINE_DATA(&m_pvc_cartridge_ram[offset] );
569549   if (offset == 0xff0)
570      pvc_prot1(space.machine());
550      pvc_prot1();
571551   else if(offset >= 0xff4 && offset <= 0xff5)
572      pvc_prot2(space.machine());
552      pvc_prot2();
573553   else if(offset >= 0xff8)
574554      pvc_write_bankswitch(space);
575555}
576556
577557
578void install_pvc_protection( running_machine &machine )
558void neogeo_state::install_pvc_protection()
579559{
580   neogeo_state *state = machine.driver_data<neogeo_state>();
581   state->m_pvc_cartridge_ram = auto_alloc_array(machine, UINT16, 0x2000 / 2);
582   state->save_pointer(NAME(state->m_pvc_cartridge_ram), 0x2000 / 2);
560   m_pvc_cartridge_ram = auto_alloc_array(machine(), UINT16, 0x2000 / 2);
561   save_pointer(NAME(m_pvc_cartridge_ram), 0x2000 / 2);
583562
584   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x2fe000, 0x2fffff, FUNC(pvc_prot_r), FUNC(pvc_prot_w));
563   machine().device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x2fe000, 0x2fffff, read16_delegate(FUNC(neogeo_state::pvc_prot_r),this), write16_delegate(FUNC(neogeo_state::pvc_prot_w),this));
585564}
trunk/src/mame/includes/neogeo.h
r21155r21156
263263
264264   void neogeo_set_main_cpu_bank_address( UINT32 bank_address );
265265
266   // protection data
267   UINT16 kof2003_tbl[4096];
268   UINT16 kof10thExtraRAMB[0x01000];
269   const UINT8 *type0_t03;
270   const UINT8 *type0_t12;
271   const UINT8 *type1_t03;
272   const UINT8 *type1_t12;
273   const UINT8 *address_8_15_xor1;
274   const UINT8 *address_8_15_xor2;
275   const UINT8 *address_16_23_xor1;
276   const UINT8 *address_16_23_xor2;
277   const UINT8 *address_0_7_xor;
278
266279protected:
267280   required_memory_region m_region_maincpu;
268281   required_memory_region m_region_sprites;
r21155r21156
319332   void set_outputs(  );
320333   void set_output_latch( UINT8 data );
321334   void set_output_data( UINT8 data );
335   TIMER_CALLBACK_MEMBER( ms5pcb_bios_timer_callback );
336   TIMER_CALLBACK_MEMBER( svcpcb_bios_timer_callback );
337   
338   // protections implementation
339   DECLARE_READ16_MEMBER( sbp_lowerrom_r );
340   DECLARE_WRITE16_MEMBER( sbp_lowerrom_w );
341   DECLARE_READ16_MEMBER( fatfury2_protection_16_r );
342   DECLARE_WRITE16_MEMBER( fatfury2_protection_16_w );
343   void fatfury2_install_protection();
344   DECLARE_WRITE16_MEMBER ( kof98_prot_w );
345   void install_kof98_protection();
346   DECLARE_WRITE16_MEMBER( mslugx_protection_16_w );
347   DECLARE_READ16_MEMBER( mslugx_protection_16_r );
348   void mslugx_install_protection();
349   DECLARE_WRITE16_MEMBER( kof99_bankswitch_w );
350   DECLARE_WRITE16_MEMBER( garou_bankswitch_w );
351   DECLARE_WRITE16_MEMBER( garouh_bankswitch_w );
352   DECLARE_WRITE16_MEMBER( mslug3_bankswitch_w );
353   DECLARE_WRITE16_MEMBER( kof2000_bankswitch_w );
354   DECLARE_READ16_MEMBER( prot_9a37_r );
355   DECLARE_READ16_MEMBER( sma_random_r );
356   void neogeo_reset_rng();
357   void sma_install_random_read_handler( int addr1, int addr2 );
358   void kof99_install_protection();
359   void garou_install_protection();
360   void garouh_install_protection();
361   void mslug3_install_protection();
362   void kof2000_install_protection();
363   void pvc_w8( offs_t offset, UINT8 data );
364   UINT8 pvc_r8( offs_t offset );
365   void pvc_prot1();
366   void pvc_prot2(); // on writes to e8/e9/ea/eb
367   void pvc_write_bankswitch( address_space &space );
368   DECLARE_READ16_MEMBER( pvc_prot_r );
369   DECLARE_WRITE16_MEMBER( pvc_prot_w );
370   void install_pvc_protection();
371   void neogeo_bootleg_cx_decrypt();
372   void neogeo_bootleg_sx_decrypt(int value );
373   void kog_px_decrypt();
374   void kof97oro_px_decode();
375   void kof10thBankswitch(address_space &space, UINT16 nBank);
376   DECLARE_READ16_MEMBER( kof10th_RAMB_r );
377   DECLARE_WRITE16_MEMBER( kof10th_custom_w );
378   DECLARE_WRITE16_MEMBER( kof10th_bankswitch_w );
379   void install_kof10th_protection ();
380   void decrypt_kof10th();
381   void decrypt_kf10thep();
382   void kf2k5uni_px_decrypt();
383   void kf2k5uni_sx_decrypt();
384   void kf2k5uni_mx_decrypt();
385   void decrypt_kf2k5uni();
386   void kof2002b_gfx_decrypt(UINT8 *src, int size);
387   void kf2k2mp_decrypt();
388   void kf2k2mp2_px_decrypt();
389   void cthd2003_neogeo_gfx_address_fix_do(int start, int end, int bit3shift, int bit2shift, int bit1shift, int bit0shift);
390   void cthd2003_neogeo_gfx_address_fix(int start, int end);
391   void cthd2003_c(int pow);
392   void decrypt_cthd2003();
393   DECLARE_WRITE16_MEMBER ( cthd2003_bankswitch_w );
394   void patch_cthd2003();
395   void ct2k3sp_sx_decrypt();
396   void decrypt_ct2k3sp();
397   void decrypt_ct2k3sa();
398   void patch_ct2k3sa();
399   void decrypt_kof2k4se_68k();
400   void lans2004_vx_decrypt();
401   void lans2004_decrypt_68k();
402   DECLARE_READ16_MEMBER( mslug5_prot_r );
403   DECLARE_WRITE16_MEMBER ( ms5plus_bankswitch_w );
404   void install_ms5plus_protection();
405   void svcboot_px_decrypt();
406   void svcboot_cx_decrypt();
407   void svcplus_px_decrypt();
408   void svcplus_px_hack();
409   void svcplusa_px_decrypt();
410   void svcsplus_px_decrypt();
411   void svcsplus_px_hack();
412   DECLARE_READ16_MEMBER( kof2003_r);
413   DECLARE_WRITE16_MEMBER( kof2003_w );
414   DECLARE_WRITE16_MEMBER( kof2003p_w );
415   void kf2k3bl_px_decrypt();
416   void kf2k3bl_install_protection();
417   void kf2k3pl_px_decrypt();
418   void kf2k3pl_install_protection();
419   void kf2k3upl_px_decrypt();
420   void kf2k3upl_install_protection();
421   void samsho5b_px_decrypt();
422   void samsho5b_vx_decrypt();
423   void matrimbl_decrypt();
424   void decrypt(UINT8 *r0, UINT8 *r1,UINT8 c0,  UINT8 c1,const UINT8 *table0hi,const UINT8 *table0lo,const UINT8 *table1,int base,int invert);
425   void neogeo_gfx_decrypt(int extra_xor);
426   void neogeo_sfix_decrypt();
427   void kof99_neogeo_gfx_decrypt(int extra_xor);
428   void kof2000_neogeo_gfx_decrypt(int extra_xor);
429   void cmc42_neogeo_gfx_decrypt(int extra_xor);
430   void cmc50_neogeo_gfx_decrypt(int extra_xor);
431   void svcpcb_gfx_decrypt();
432   void svcpcb_s1data_decrypt();
433   void kf2k3pcb_gfx_decrypt();
434   void kf2k3pcb_decrypt_s1data();
435   UINT16 generate_cs16(UINT8 *rom, int size);
436   int m1_address_scramble(int address, UINT16 key);
437   void neogeo_cmc50_m1_decrypt();
438   void kof98_decrypt_68k();
439   void kof99_decrypt_68k();
440   void garou_decrypt_68k();
441   void garouh_decrypt_68k();
442   void mslug3_decrypt_68k();
443   void kof2000_decrypt_68k();
444   void kof2002_decrypt_68k();
445   void matrim_decrypt_68k();
446   void samsho5_decrypt_68k();
447   void samsh5sp_decrypt_68k();
448   void mslug5_decrypt_68k();
449   void svc_px_decrypt();
450   void kf2k3pcb_decrypt_68k();
451   void kof2003_decrypt_68k();
452   void kof2003h_decrypt_68k();
453   void neo_pcm2_snk_1999(int value);
454   void neo_pcm2_swap(int value);
455   void kof2003biosdecode();
322456};
323457
324458
325459/*----------- defined in drivers/neogeo.c -----------*/
326460
327461MACHINE_CONFIG_EXTERN( neogeo_base );
328
329/*----------- defined in machine/neocrypt.c -----------*/
330
331void kof99_neogeo_gfx_decrypt(running_machine &machine, int extra_xor);
332void kof2000_neogeo_gfx_decrypt(running_machine &machine, int extra_xor);
333void cmc42_neogeo_gfx_decrypt(running_machine &machine, int extra_xor);
334void cmc50_neogeo_gfx_decrypt(running_machine &machine, int extra_xor);
335void neogeo_cmc50_m1_decrypt(running_machine &machine);
336void neo_pcm2_snk_1999(running_machine &machine, int value);
337void neo_pcm2_swap(running_machine &machine, int value);
338void neogeo_sfix_decrypt(running_machine &machine);
339void kof99_decrypt_68k(running_machine &machine);
340void garou_decrypt_68k(running_machine &machine);
341void garouh_decrypt_68k(running_machine &machine);
342void mslug3_decrypt_68k(running_machine &machine);
343void kof2000_decrypt_68k(running_machine &machine);
344void kof98_decrypt_68k(running_machine &machine);
345void kof2002_decrypt_68k(running_machine &machine);
346void matrim_decrypt_68k(running_machine &machine);
347void mslug5_decrypt_68k(running_machine &machine);
348void svc_px_decrypt(running_machine &machine);
349void svcpcb_gfx_decrypt(running_machine &machine);
350void svcpcb_s1data_decrypt(running_machine &machine);
351void samsho5_decrypt_68k(running_machine &machine);
352void kf2k3pcb_gfx_decrypt(running_machine &machine);
353void kf2k3pcb_decrypt_68k(running_machine &machine);
354void kf2k3pcb_decrypt_s1data(running_machine &machine);
355void kof2003_decrypt_68k(running_machine &machine);
356void kof2003h_decrypt_68k(running_machine &machine);
357void kof2003biosdecode(running_machine &machine);
358void samsh5sp_decrypt_68k(running_machine &machine);
359
360
361/*----------- defined in machine/neoprot.c -----------*/
362
363void neogeo_reset_rng(running_machine &machine);
364void fatfury2_install_protection(running_machine &machine);
365void mslugx_install_protection(running_machine &machine);
366void kof99_install_protection(running_machine &machine);
367void garou_install_protection(running_machine &machine);
368void garouh_install_protection(running_machine &machine);
369void mslug3_install_protection(running_machine &machine);
370void kof2000_install_protection(running_machine &machine);
371void install_kof98_protection(running_machine &machine);
372void install_pvc_protection(running_machine &machine);
373
374
375/*----------- defined in machine/neoboot.c -----------*/
376
377void kog_px_decrypt(running_machine &machine);
378void kof97oro_px_decode( running_machine &machine );
379void neogeo_bootleg_cx_decrypt(running_machine &machine);
380void install_kof10th_protection(running_machine &machine);
381void decrypt_kof10th(running_machine &machine);
382void decrypt_kf10thep(running_machine &machine);
383void decrypt_kf2k5uni(running_machine &machine);
384void neogeo_bootleg_sx_decrypt(running_machine &machine, int value);
385void kof2002b_gfx_decrypt(running_machine &machine, UINT8 *src, int size);
386void kf2k2mp_decrypt(running_machine &machine);
387void kf2k2mp2_px_decrypt(running_machine &machine);
388void decrypt_cthd2003(running_machine &machine);
389void patch_cthd2003(running_machine &machine);
390void decrypt_ct2k3sp(running_machine &machine);
391void decrypt_ct2k3sa(running_machine &machine);
392void patch_ct2k3sa(running_machine &machine);
393void decrypt_kof2k4se_68k(running_machine &machine);
394void lans2004_decrypt_68k(running_machine &machine);
395void lans2004_vx_decrypt(running_machine &machine);
396void install_ms5plus_protection(running_machine &machine);
397void svcboot_px_decrypt(running_machine &machine);
398void svcboot_cx_decrypt(running_machine &machine);
399void svcplus_px_decrypt(running_machine &machine);
400void svcplus_px_hack(running_machine &machine);
401void svcplusa_px_decrypt(running_machine &machine);
402void svcsplus_px_decrypt(running_machine &machine);
403void svcsplus_px_hack(running_machine &machine);
404void kf2k3bl_px_decrypt(running_machine &machine);
405void kf2k3bl_install_protection(running_machine &machine);
406void kf2k3pl_px_decrypt(running_machine &machine);
407void kf2k3upl_px_decrypt(running_machine &machine);
408void kf2k3upl_install_protection(running_machine &machine);
409void kf2k3pl_install_protection(running_machine &machine);
410void samsho5b_px_decrypt(running_machine &machine);
411void samsho5b_vx_decrypt(running_machine &machine);
412void matrimbl_decrypt(running_machine &machine);
413

Previous 199869 Revisions Next


© 1997-2024 The MAME Team