/
vsnes.cpp
3606 lines (3029 loc) · 161 KB
/
vsnes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// license:BSD-3-Clause
// copyright-holders:Pierpaolo Prazzoli, Brad Oliver, Fabio Priuli
/***************************************************************************
Nintendo VS UniSystem and DualSystem - (c) 1984 Nintendo of America
Portions of this code are heavily based on
Brad Oliver's MESS implementation of the NES.
RC2C03B/RP2C03B:
- Duck Hunt
- Mahjong
- Pinball (Japan)
- Star Luster *
- Stroke & Match Golf (Japan)
- Tennis
RP2C04-0001:
- Atari R.B.I. Baseball *
- Baseball
- Battle City *
- Freedom Force
- Gradius
- Hogan's Alley
- Mach Rider (Japan, Fighting Course)
- Pinball
- Platoon
- Super Skykid *
- Super Xevious *
- Tetris *
RP2C04-0002:
- Castlevania
- Mach Rider (Endurance Course)
- Raid on Bungeling Bay (Japan)
- Slalom
- Soccer (Japan)
- Stroke & Match Golf
- Stroke & Match Golf (Ladies)
- Wrecking Crew
RP2C04-0003:
- Balloon Fight
- Dr. Mario
- Excitebike
- Goonies
- Soccer
- T.K.O. Boxing *
(Manual states this is an RP2C04-0004 - though the palette doesn't agree)
RP2C04-0004:
- Clu Clu Land
- Excitebike (Japan)
- Ice Climber
- Ice Climber Dual (Japan)
- Super Mario Bros.
- Games marked with a star are compatible with multiple PPU types,
but you need to set dipswitches corresponding to the PPU installed
or else the game will display incorrect colors.
Here the games are listed under the PPU type that works with the
PPU selection dipswitches all set to OFF.
RC2C05-01:
- Ninja Jajamaru Kun (Japan)
RC2C05-02:
- Mighty Bomb Jack (Japan)
RC2C05-03:
- Gumshoe
RC2C05-04:
- Top Gun
Graphic hack games:
- Skate Kids (by Two-Bit Score, 1988; hack of Vs. Super Mario Bros.)
Needed roms:
- Babel no Tou (by Namco, 1986)
- Family Boxing (by Namco/Wood Place, 1987; Japan version of TKO Boxing)
- Family Stadium '87 (by Namco, 1987; sequel to RBI Baseball)
- Family Stadium '88 (by Namco, 1988; sequel to RBI Baseball)
- Family Tennis (by Namco, 1987)
- Head to Head Baseball (ever finished/released?, by Nintendo, 1986)
- Lionex (prototype by Sun Electronics, 1986, DRGN-D board, unreleased dump exists)
- The Wings of Madoola (prototype by Sun Electronics, 1987, DRGN-D board, unreleased dump exists)
- Pro Yakyuu Family Stadium (by Namco, 1986; Japan version of RBI Baseball)
- Quest of Ki (by Namco/Game Studio, 1988)
- Super Chinese (by Namco/Culture Brain, 1988)
- Toukaidou 53tsugi (prototype by Sunsoft, 1985)
- Trojan (by Capcom, 1987)
- Urban Champion (1984)
- Volleyball (1986)
- Walkure no Bouken (by Namco, 1986)
- Wild Gunman (1984, light gun game)
BTANB:
- Coin sound clipped when first coin is inserted in VS. Castlevania.
TO DO:
- Merge mapper implementations with playch10, NES, etc
- Check others bits in coin counter
- Check other values in bnglngby irq
- Top Gun: cpu #0 (PC=00008016): unmapped memory byte read from 00007FFF ???
Changes:
27/05/2004 Pierpaolo Prazzoli
- Fixed Vs. Gumshoe (fully working now)
- Changed coin inputs to use bit impulse
16/10/2003 Pierpaolo Prazzoli
- Added
- Vs. Freedom Force
- Vs. Super Xevious
24/12/2002 Pierpaolo Prazzoli
- Added
- Vs. Mighty Bomb Jack (Japan)
- Vs. Ninja Jajamaru Kun (Japan)
- Vs. Raid on Bungeling Bay (Japan)
- Vs. Top Gun
- Vs. Mach Rider (Japan, Fighting Course Version)
- Vs. Ice Climber (Japan)
- Vs. Gumshoe (partially working)
- Vs. Freedom Force (not working)
- Vs. Stroke and Match Golf (Men set 2) (not working)
- Vs. Baseball (Japan set 3) (not working)
- Added coin counter
- Added Extra Ram in vstetris
- Added Demo Sound in vsmahjng
- Fixed vsskykid inputs
- Fixed protection in Vs. Super Xevious
- Corrected or checked dip-switches in Castlevania, Duck Hunt, Excitebike,
Gradius, Hogan's Alley, Ice Climber, R.B.I. Baseball, Slalom, Soccer,
Super Mario Bros., Top Gun, Baseball, Tennis, Stroke and Match Golf
***************************************************************************/
#include "emu.h"
#include "bus/nes_ctrl/zapper_sensor.h"
#include "cpu/m6502/rp2a03.h"
#include "cpu/z80/z80.h"
#include "machine/nvram.h"
#include "machine/watchdog.h"
#include "sound/sn76496.h"
#include "video/ppu2c0x.h"
#include "screen.h"
#include "speaker.h"
#include "layout/generic.h"
namespace {
class vs_base_state : public driver_device
{
protected:
vs_base_state(const machine_config &mconfig, device_type type, const char *tag)
: driver_device(mconfig, type, tag)
, m_maincpu(*this, "maincpu")
, m_subcpu(*this, "sub")
, m_ppu1(*this, "ppu1")
, m_ppu2(*this, "ppu2")
, m_sensor(*this, "sensor")
, m_nvram(*this, "nvram")
, m_watchdog(*this, "watchdog")
, m_gfx1_rom(*this, "gfx1")
, m_prg_banks(*this, "prg%u", 0U)
, m_prg_view(*this, "prg_view")
, m_chr_banks(*this, "chr%u", 0U)
, m_chr_view(*this, "chr_view")
, m_in(*this, "IN%u", 0U)
, m_coins(*this, "COINS%u", 1U)
, m_dsw(*this, "DSW%u", 0U)
, m_gunx(*this, "GUNX")
, m_guny(*this, "GUNY")
{
}
virtual void machine_reset() override;
template <u8 Side> void vsnes_coin_counter_w(offs_t offset, u8 data);
template <u8 Side> u8 vsnes_coin_counter_r(offs_t offset);
template <u8 Side> void vsnes_in0_w(u8 data);
template <u8 Side> u8 vsnes_in0_r();
template <u8 Side> u8 vsnes_in1_r();
void vsnes_cpu1_map(address_map &map);
void vsnes_cpu2_map(address_map &map);
void vsnes_ppu1_map(address_map &map);
void vsnes_ppu2_map(address_map &map);
void init_prg_banking();
void prg32(int bank);
void prg16(int slot, int bank);
void prg8(int slot, int bank);
enum { MAIN = 0, SUB = 1 };
required_device<cpu_device> m_maincpu;
optional_device<cpu_device> m_subcpu;
required_device<ppu2c0x_device> m_ppu1;
optional_device<ppu2c0x_device> m_ppu2;
optional_device<nes_zapper_sensor_device> m_sensor;
optional_device<nvram_device> m_nvram;
optional_device<watchdog_timer_device> m_watchdog;
optional_memory_region m_gfx1_rom;
memory_bank_array_creator<4> m_prg_banks;
memory_view m_prg_view;
int m_prg_chunks = 0;
memory_bank_array_creator<8> m_chr_banks;
memory_view m_chr_view;
int m_chr_chunks = 0;
bool m_has_gun = false;
private:
optional_ioport_array<4> m_in;
optional_ioport_array<2> m_coins;
optional_ioport_array<2> m_dsw;
optional_ioport m_gunx;
optional_ioport m_guny;
int m_coin = 0;
int m_input_latch[4]{};
int m_input_strobe[2]{};
};
class vs_uni_state : public vs_base_state
{
public:
vs_uni_state(const machine_config &mconfig, device_type type, const char *tag)
: vs_base_state(mconfig, type, tag)
{
}
void vsnes(machine_config &config);
void jajamaru(machine_config &config);
void mightybj(machine_config &config);
void topgun(machine_config &config);
void vsgshoe(machine_config &config);
void init_vskonami();
void init_vsvram();
void init_bnglngby();
void init_drmario();
void init_vs108();
void init_vsfdf();
void init_tkoboxng();
void init_vsgun();
void init_supxevs();
void init_vsgshoe();
void init_vsnormal();
void init_platoon();
void init_rbibb();
protected:
virtual void machine_start() override;
private:
void vsnormal_vrom_banking(u8 data);
void vskonami_rom_banking(offs_t offset, u8 data);
void vsgshoe_gun_in0_w(u8 data);
void drmario_rom_banking(offs_t offset, u8 data);
void vsvram_rom_banking(u8 data);
void vs108_rom_banking(offs_t offset, u8 data);
u8 rbibb_prot_r(offs_t offset);
u8 supxevs_prot_1_r();
u8 supxevs_prot_2_r();
u8 supxevs_prot_3_r();
u8 supxevs_prot_4_r();
u8 tkoboxng_prot_r(offs_t offset);
void sunsoft3_rom_banking(offs_t offset, u8 data);
void set_bnglngby_irq_w(u8 data);
u8 set_bnglngby_irq_r();
void v_set_videorom_bank(int start, int count, int vrom_start_bank);
int m_mmc1_shiftreg = 0;
int m_mmc1_shiftcount = 0;
int m_mmc1_prg16k = 0;
int m_mmc1_switchlow = 0;
int m_mmc1_chr4k = 0;
int m_108_reg = 0;
int m_prot_index = 0;
int m_ret = 0;
};
class vs_dual_state : public vs_base_state
{
public:
vs_dual_state(const machine_config &mconfig, device_type type, const char *tag)
: vs_base_state(mconfig, type, tag)
{
}
void vsdual(machine_config &config);
void init_vsdual();
protected:
virtual void machine_start() override;
private:
template <u8 Side> void vsdual_vrom_banking(u8 data);
};
class vs_smbbl_state : public vs_base_state
{
public:
vs_smbbl_state(const machine_config &mconfig, device_type type, const char *tag)
: vs_base_state(mconfig, type, tag)
, m_sn1(*this, "sn1")
, m_sn2(*this, "sn2")
{
}
void vs_smbbl(machine_config &config);
protected:
virtual void machine_start() override;
private:
void smbbl_6502_sn_w(offs_t offset, u8 data);
void smbbl_z80_sn_w(offs_t offset, u8 data);
u8 smbbl_z80_data_r();
u8 smbbl_z80_address_r(offs_t offset);
void smbbl_scanline_cb(int scanline, bool vblank, bool blanked);
u8 smbbl_ppu_data_r();
void smbbl_6502_map(address_map &map);
void smbbl_z80_map(address_map &map);
void smbbl_ppu_map(address_map &map);
required_device<sn76489_device> m_sn1;
required_device<sn76489_device> m_sn2;
u8 m_bootleg_sound_offset = 0;
u8 m_bootleg_sound_data = 0;
int m_bootleg_latched_scanline = 0;
};
//******************************************************************************
template <u8 Side>
void vs_base_state::vsnes_coin_counter_w(offs_t offset, u8 data)
{
machine().bookkeeping().coin_counter_w(Side, data & 0x01);
m_coin = data;
// "bnglngby" and "cluclu", vsbball service mode
if(data & 0xfe)
logerror("vsnes_coin_counter_w: cpu %hhu, pc = 0x%04x - data = 0x%02x\n", Side, (Side == MAIN) ? m_maincpu->pc() : m_subcpu->pc(), data);
}
template <u8 Side>
u8 vs_base_state::vsnes_coin_counter_r(offs_t offset)
{
// reads effectively write MSB of address (via open bus) to coin counter
machine().bookkeeping().coin_counter_w(Side, BIT(offset, 8));
// only for platoon
return m_coin;
}
template <u8 Side>
void vs_base_state::vsnes_in0_w(u8 data)
{
// Toggling bit 0 high then low resets both controllers
if (m_input_strobe[Side] & ~data & 1)
{
// load up the latches
int p1 = 2 * Side;
int p2 = p1 + 1;
m_input_latch[p1] = m_in[p1]->read();
m_input_latch[p2] = m_in[p2]->read();
if (m_has_gun && m_sensor->detect_light(m_gunx->read(), m_guny->read()))
m_input_latch[p1] |= 0x40;
}
m_input_strobe[Side] = data;
}
template <u8 Side>
u8 vs_base_state::vsnes_in0_r()
{
int p1 = 2 * Side;
if (m_input_strobe[Side] & 1)
{
m_input_latch[p1] = m_in[p1]->read();
if (m_has_gun && m_sensor->detect_light(m_gunx->read(), m_guny->read()))
m_input_latch[p1] |= 0x40;
}
int ret = m_input_latch[p1] & 1;
m_input_latch[p1] >>= 1;
// FIXME: UniSystem's wiring harness connects S Coin 2 to S Coin 1 edge hardness
// This should mean games that don't check Coin 2 inputs respond on UniSys, but on DualSys they'd miss the Coin 2 inserts as all 4 inputs are separate?
ret |= m_coins[Side]->read(); // merge coins, etc
ret |= (m_dsw[Side]->read() & 3) << 3; // merge 2 dipswitches
ret |= Side << 7; // CPU indicator bit
return ret;
}
template <u8 Side>
u8 vs_base_state::vsnes_in1_r()
{
// Only the Sub side CPU can kick the watchdog, which it must do by periodically reading $4017.
// This is one reason UniSystem games too must be installed on the Sub side.
if (m_watchdog && Side == SUB)
m_watchdog->watchdog_reset();
int p2 = 2 * Side + 1;
if (m_input_strobe[Side] & 1)
m_input_latch[p2] = m_in[p2]->read();
int ret = m_input_latch[p2] & 1;
m_input_latch[p2] >>= 1;
ret |= m_dsw[Side]->read() & ~3; // merge the rest of the dipswitches
return ret;
}
/*************************************
*
* Init machine
*
*************************************/
void vs_base_state::machine_reset()
{
m_input_latch[0] = m_input_latch[1] = 0;
m_input_latch[2] = m_input_latch[3] = 0;
m_input_strobe[0] = m_input_strobe[1] = 0;
}
/*************************************
*
* Machine start functions
*
*************************************/
void vs_base_state::init_prg_banking()
{
u8 *base = memregion("prg")->base();
m_prg_chunks = memregion("prg")->bytes() / 0x2000;
for (int i = 0; i < 4; i++)
{
m_prg_banks[i]->configure_entries(0, m_prg_chunks, base, 0x2000);
m_prg_banks[i]->set_entry(m_prg_chunks - 4 + i);
}
m_prg_view.select(0);
}
// safe banking helpers (only work when PRG size is a power of 2, i.e. not Gumshoe)
void vs_base_state::prg32(int bank)
{
bank = (bank << 2) & (m_prg_chunks - 1);
for (int i = 0; i < 4; i++)
m_prg_banks[i]->set_entry(bank + i);
}
void vs_base_state::prg16(int slot, int bank)
{
bank = (bank << 1) & (m_prg_chunks - 1);
slot = (slot & 1) << 1;
for (int i = 0; i < 2; i++)
m_prg_banks[slot + i]->set_entry(bank + i);
}
void vs_base_state::prg8(int slot, int bank)
{
m_prg_banks[slot & 0x03]->set_entry(bank & (m_prg_chunks - 1));
}
void vs_uni_state::v_set_videorom_bank(int start, int count, int vrom_start_bank)
{
assert(start + count <= 8);
vrom_start_bank &= m_chr_chunks - 1;
assert(vrom_start_bank + count <= m_chr_chunks);
// count determines the size of the area mapped
for (int i = 0; i < count; i++)
m_chr_banks[i + start]->set_entry(vrom_start_bank + i);
}
void vs_uni_state::machine_start()
{
// establish chr banks
// DRIVER_INIT is called first - means we can handle this different for VRAM games!
if (m_gfx1_rom != nullptr)
{
u8 *base = m_gfx1_rom->base();
m_chr_chunks = m_gfx1_rom->bytes() / 0x400;
for (int i = 0; i < 8; i++)
{
m_ppu1->space(AS_PROGRAM).install_read_bank(0x0400 * i, 0x0400 * i + 0x03ff, m_chr_banks[i]);
m_chr_banks[i]->configure_entries(0, m_chr_chunks, base, 0x400);
}
v_set_videorom_bank(0, 8, 0);
}
else
m_chr_view.select(0);
}
void vs_dual_state::machine_start()
{
for (int i = 0; i < 2; i++)
{
const char *region = i ? "gfx2" : "gfx1";
u8 *base = memregion(region)->base();
int entries = memregion(region)->bytes() / 0x2000;
m_chr_banks[i]->configure_entries(0, entries, base, 0x2000);
m_chr_banks[i]->set_entry(0);
}
}
void vs_smbbl_state::machine_start()
{
m_ppu1->set_scanline_callback(*this, FUNC(vs_smbbl_state::smbbl_scanline_cb));
u8 *base = m_gfx1_rom->base();
int entries = m_gfx1_rom->bytes() / 0x2000;
m_chr_banks[0]->configure_entries(0, entries, base, 0x2000);
m_chr_banks[0]->set_entry(0);
}
/**********************************************************************************
*
* Game and Board-specific initialization
*
**********************************************************************************/
//**********************************************************************************
// Most games: VROM Banking in controller 0 write
void vs_uni_state::vsnormal_vrom_banking(u8 data)
{
// switch vrom
v_set_videorom_bank(0, 8, (data & 4) ? 8 : 0);
// bit 1 ( data & 2 ) enables writes to extra ram, we ignore it
// move along
vsnes_in0_w<MAIN>(data);
}
void vs_uni_state::init_vsnormal()
{
// vrom switching is enabled with bit 2 of $4016
m_maincpu->space(AS_PROGRAM).install_write_handler(0x4016, 0x4016, write8smo_delegate(*this, FUNC(vs_uni_state::vsnormal_vrom_banking)));
}
//**********************************************************************************
// Gun games: VROM Banking in controller 0 write
void vs_uni_state::init_vsgun()
{
init_vsnormal();
m_has_gun = true;
}
//**********************************************************************************
// Konami VRC1 games: ROM banking at $8000-$ffff
void vs_uni_state::vskonami_rom_banking(offs_t offset, u8 data)
{
int reg = BIT(offset, 12, 3);
switch (reg)
{
case 0: // prg bank 0
case 2: // prg bank 1
case 4: // prg bank 2
prg8(reg >> 1, data);
break;
case 6: // vrom bank 0
v_set_videorom_bank(0, 4, data * 4);
break;
case 7: // vrom bank 1
v_set_videorom_bank(4, 4, data * 4);
break;
}
}
void vs_uni_state::init_vskonami()
{
// point program banks to last 32K
init_prg_banking();
// banking is done with writes to the $8000-$ffff area
m_maincpu->space(AS_PROGRAM).install_write_handler(0x8000, 0xffff, write8sm_delegate(*this, FUNC(vs_uni_state::vskonami_rom_banking)));
}
//**********************************************************************************
// Vs. Gumshoe
void vs_uni_state::vsgshoe_gun_in0_w(u8 data)
{
// Gumshoe uniquely has a bankable 16K EPROM in addition to the normal unbanked 8K slots
m_prg_banks[0]->set_entry(BIT(data, 2));
// otherwise do normal CHR banking and IO write
vsnormal_vrom_banking(data);
}
void vs_uni_state::init_vsgshoe()
{
// point program banks to last 32K
init_prg_banking();
// vrom switching is enabled with bit 2 of $4016
m_maincpu->space(AS_PROGRAM).install_write_handler(0x4016, 0x4016, write8smo_delegate(*this, FUNC(vs_uni_state::vsgshoe_gun_in0_w)));
m_has_gun = true;
}
//**********************************************************************************
// MMC1 (Dr Mario): ROM banking at $8000-$ffff
void vs_uni_state::drmario_rom_banking(offs_t offset, u8 data)
{
// reset mapper
if (data & 0x80)
{
m_mmc1_shiftcount = 0;
m_mmc1_prg16k = 1;
m_mmc1_switchlow = 1;
return;
}
// update shift register
m_mmc1_shiftreg = (m_mmc1_shiftreg >> 1) | (data & 1) << 4;
m_mmc1_shiftcount = (m_mmc1_shiftcount + 1) % 5;
// are we done shifting?
if (!m_mmc1_shiftcount)
{
// apply data to registers
switch (BIT(offset, 13, 2))
{
case 0: // mirroring and options
m_mmc1_chr4k = m_mmc1_shiftreg & 0x10;
m_mmc1_prg16k = m_mmc1_shiftreg & 0x08;
m_mmc1_switchlow = m_mmc1_shiftreg & 0x04;
// 0x03: mirroring bits unused on VS
break;
case 1: // video rom banking - bank 0 - 4k or 8k
if (m_mmc1_chr4k)
v_set_videorom_bank(0, 4, m_mmc1_shiftreg * 4);
else
v_set_videorom_bank(0, 8, (m_mmc1_shiftreg & ~1) * 4);
break;
case 2: // video rom banking - bank 1 - 4k only
if (m_mmc1_chr4k)
v_set_videorom_bank(4, 4, m_mmc1_shiftreg * 4);
break;
case 3: // program banking
if (m_mmc1_prg16k)
prg16(!m_mmc1_switchlow, m_mmc1_shiftreg);
else
prg32(m_mmc1_shiftreg >> 1);
break;
}
}
}
void vs_uni_state::init_drmario()
{
// point program banks to last 32K
init_prg_banking();
// MMC1 mapper at $8000-$ffff
m_maincpu->space(AS_PROGRAM).install_write_handler(0x8000, 0xffff, write8sm_delegate(*this, FUNC(vs_uni_state::drmario_rom_banking)));
m_mmc1_shiftreg = 0;
m_mmc1_shiftcount = 0;
}
//**********************************************************************************
// (UNROM) Games with VRAM instead of graphics ROMs: ROM banking at $8000-$ffff
void vs_uni_state::vsvram_rom_banking(u8 data)
{
prg16(0, data);
}
void vs_uni_state::init_vsvram()
{
// point program banks to last 32K
init_prg_banking();
// banking is done with writes to the $8000-$ffff area
m_maincpu->space(AS_PROGRAM).install_write_handler(0x8000, 0xffff, write8smo_delegate(*this, FUNC(vs_uni_state::vsvram_rom_banking)));
}
//**********************************************************************************
// (Namco) 108 (MMC3 predecessor) games
void vs_uni_state::vs108_rom_banking(offs_t offset, u8 data)
{
switch (offset & 0x6001)
{
case 0x0000: // $8000
m_108_reg = data & 0x07;
break;
case 0x0001: // $8001
switch (m_108_reg)
{
case 0: case 1:
v_set_videorom_bank(m_108_reg * 2, 2, data);
break;
case 2: case 3: case 4: case 5:
v_set_videorom_bank(m_108_reg + 2, 1, data);
break;
case 6: case 7:
prg8(m_108_reg - 6, data);
break;
}
break;
default:
logerror("vs108_rom_banking uncaught: %04x value: %02x\n", offset + 0x8000, data);
break;
}
}
// Common init for (Namco) 108 games
void vs_uni_state::init_vs108()
{
// point program banks to last 32K
init_prg_banking();
m_108_reg = 0;
// 108 chip at $8000-$9fff
m_maincpu->space(AS_PROGRAM).install_write_handler(0x8000, 0xffff, write8sm_delegate(*this, FUNC(vs_uni_state::vs108_rom_banking)));
}
// Vs. RBI Baseball
// rbibb uses a protection chip labeled '127'
// Tests indicate that '127' uses a LFSR with taps: 23, 18, 0
// It is still unknown how bits are then shuffled for readback at 0x5601/0x5e01
u8 vs_uni_state::rbibb_prot_r(offs_t offset)
{
static constexpr u8 prot_data[32] = {
0xff, 0xfd, 0xf5, 0xf4, 0xb4, 0xb4, 0xa6, 0x2e,
0x2f, 0x6f, 0x6f, 0x7d, 0xd5, 0xd4, 0x94, 0x94,
0x86, 0x2e, 0x2f, 0x6f, 0x6b, 0x79, 0xd1, 0xd0,
0x92, 0x92, 0x8d, 0x65, 0x64, 0x34, 0xb0, 0xa2
};
if (offset == 0)
{
m_prot_index = 0;
return 0;
}
return prot_data[m_prot_index++ & 0x1f];
}
void vs_uni_state::init_rbibb()
{
init_vs108();
// RBI Baseball protection, address fully decoded except A11
m_maincpu->space(AS_PROGRAM).install_read_handler(0x5600, 0x5601, read8sm_delegate(*this, FUNC(vs_uni_state::rbibb_prot_r)));
m_maincpu->space(AS_PROGRAM).install_read_handler(0x5e00, 0x5e01, read8sm_delegate(*this, FUNC(vs_uni_state::rbibb_prot_r)));
}
// Vs. Super Xevious
u8 vs_uni_state::supxevs_prot_1_r()
{
m_prot_index ^= 1;
return 0x05;
}
u8 vs_uni_state::supxevs_prot_2_r()
{
return m_prot_index ? 0x01 : 0x00;
}
u8 vs_uni_state::supxevs_prot_3_r()
{
return m_prot_index ? 0x89 : 0xd1;
}
u8 vs_uni_state::supxevs_prot_4_r()
{
return m_prot_index ? 0x37 : 0x3e;
}
void vs_uni_state::init_supxevs()
{
init_vs108();
// Vs. Super Xevious Protection
m_maincpu->space(AS_PROGRAM).install_read_handler(0x54ff, 0x54ff, read8smo_delegate(*this, FUNC(vs_uni_state::supxevs_prot_1_r)));
m_maincpu->space(AS_PROGRAM).install_read_handler(0x5678, 0x5678, read8smo_delegate(*this, FUNC(vs_uni_state::supxevs_prot_2_r)));
m_maincpu->space(AS_PROGRAM).install_read_handler(0x578f, 0x578f, read8smo_delegate(*this, FUNC(vs_uni_state::supxevs_prot_3_r)));
m_maincpu->space(AS_PROGRAM).install_read_handler(0x5567, 0x5567, read8smo_delegate(*this, FUNC(vs_uni_state::supxevs_prot_4_r)));
m_prot_index = 0;
}
// Vs. TKO Boxing
// tkoboxng uses a protection chip labeled '128'
u8 vs_uni_state::tkoboxng_prot_r(offs_t offset)
{
static constexpr u8 prot_data[32] = {
0xff, 0xbf, 0xb7, 0x97, 0x97, 0x17, 0x57, 0x4f,
0x6f, 0x6b, 0xeb, 0xa9, 0xb1, 0x90, 0x94, 0x14,
0x56, 0x4e, 0x6f, 0x6b, 0xeb, 0xa9, 0xb1, 0x90,
0xd4, 0x5c, 0x3e, 0x26, 0x87, 0x83, 0x13, 0x00
};
if (offset == 0)
{
m_prot_index = 0;
return 0;
}
return prot_data[m_prot_index++ & 0x1f];
}
void vs_uni_state::init_tkoboxng()
{
init_vs108();
// security device at $5e00-$5e01
m_maincpu->space(AS_PROGRAM).install_read_handler(0x5e00, 0x5e01, read8sm_delegate(*this, FUNC(vs_uni_state::tkoboxng_prot_r)));
}
// Vs. Freedom Force
void vs_uni_state::init_vsfdf()
{
init_vs108();
m_has_gun = true;
}
//**********************************************************************************
// Sunsoft-3 (Platoon) rom banking
void vs_uni_state::sunsoft3_rom_banking(offs_t offset, u8 data)
{
switch (offset & 0x7800)
{
case 0x0800:
case 0x1800:
case 0x2800:
case 0x3800:
v_set_videorom_bank((offset >> 11) & 0x06, 2, data * 2);
break;
case 0x7800:
prg16(0, data);
break;
}
}
void vs_uni_state::init_platoon()
{
// point program banks to last 32K
init_prg_banking();
m_maincpu->space(AS_PROGRAM).install_write_handler(0x8000, 0xffff, write8sm_delegate(*this, FUNC(vs_uni_state::sunsoft3_rom_banking)));
}
//**********************************************************************************
// Vs. Raid on Bungeling Bay (Japan)
// FIXME: this is a bad hack! The unused 8K ROM in the driver supposedly runs on the main CPU (protection?)
// and does some sort of handshake (with IRQs) with the game running on the sub CPU.
void vs_uni_state::set_bnglngby_irq_w(u8 data)
{
m_ret = data;
m_maincpu->set_input_line(0, (data & 2) ? ASSERT_LINE : CLEAR_LINE);
// other values ???
// 0, 4, 84
}
u8 vs_uni_state::set_bnglngby_irq_r()
{
return m_ret;
}
void vs_uni_state::init_bnglngby()
{
m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0x0231, 0x0231, read8smo_delegate(*this, FUNC(vs_uni_state::set_bnglngby_irq_r)), write8smo_delegate(*this, FUNC(vs_uni_state::set_bnglngby_irq_w)));
m_ret = 0;
// normal banking
init_vsnormal();
}
//**********************************************************************************
// VS DualSystem
template <u8 Side>
void vs_dual_state::vsdual_vrom_banking(u8 data)
{
// switch vrom
m_chr_banks[Side]->set_entry(BIT(data, 2));
// bit 1 ( data & 2 ) triggers irq on the other cpu
auto &cpu = (Side == SUB) ? *m_maincpu : *m_subcpu;
cpu.set_input_line(0, (data & 2) ? CLEAR_LINE : ASSERT_LINE);
// move along
vsnes_in0_w<Side>(data);
}
void vs_dual_state::init_vsdual()
{
// vrom switching is enabled with bit 2 of $4016
m_maincpu->space(AS_PROGRAM).install_write_handler(0x4016, 0x4016, write8smo_delegate(*this, FUNC(vs_dual_state::vsdual_vrom_banking<MAIN>)));
m_subcpu->space(AS_PROGRAM).install_write_handler(0x4016, 0x4016, write8smo_delegate(*this, FUNC(vs_dual_state::vsdual_vrom_banking<SUB>)));
}
//**********************************************************************************
// Vs. Super Mario Bros (Bootleg)
void vs_smbbl_state::smbbl_scanline_cb(int scanline, bool vblank, bool blanked)
{
// Z80 IRQ is controlled by two factors:
// - bit 6 of current (next) scanline number
// - bit 6 of latched scanline number from Z80 reading $4000
if (!BIT(m_bootleg_latched_scanline, 6))
{
m_subcpu->set_input_line(INPUT_LINE_IRQ0, BIT(scanline + 1, 6) ? ASSERT_LINE : CLEAR_LINE);
}
}
u8 vs_smbbl_state::smbbl_ppu_data_r()
{
// CPU always reads higher CHR ROM banks from $2007, PPU always reads lower ones
m_chr_banks[0]->set_entry(1);
u8 data = m_ppu1->read(0x2007);
m_chr_banks[0]->set_entry(0);
return data;
}
//******************************************************************************
void vs_base_state::vsnes_cpu1_map(address_map &map)
{
map(0x0000, 0x07ff).mirror(0x1800).ram();
map(0x2000, 0x3fff).rw(m_ppu1, FUNC(ppu2c0x_device::read), FUNC(ppu2c0x_device::write));
map(0x4014, 0x4014).w(m_ppu1, FUNC(ppu2c0x_device::spriteram_dma));
map(0x4016, 0x4016).rw(FUNC(vs_base_state::vsnes_in0_r<MAIN>), FUNC(vs_base_state::vsnes_in0_w<MAIN>));
map(0x4017, 0x4017).r(FUNC(vs_base_state::vsnes_in1_r<MAIN>)); // IN1 - input port 2 / PSG second control register
map(0x4020, 0x5fff).rw(FUNC(vs_base_state::vsnes_coin_counter_r<MAIN>), FUNC(vs_base_state::vsnes_coin_counter_w<MAIN>));
map(0x6000, 0x67ff).mirror(0x1800).ram().share("nvram");
// Games that don't bank PRG
map(0x8000, 0xffff).rom().region("prg", 0);
// Games that bank PRG
map(0x8000, 0xffff).view(m_prg_view);
m_prg_view[0](0x8000, 0x9fff).bankr(m_prg_banks[0]);
m_prg_view[0](0xa000, 0xbfff).bankr(m_prg_banks[1]);
m_prg_view[0](0xc000, 0xdfff).bankr(m_prg_banks[2]);