/
stv.cpp
4031 lines (3231 loc) · 217 KB
/
stv.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:LGPL-2.1+
// copyright-holders:David Haywood, Angelo Salese, Olivier Galibert, Mariusz Wojcieszek, R. Belmont
/************************************************************************************************************************
stv.cpp
ST-V hardware
This file contains all game specific overrides
TODO:
- clean this up!
- Properly emulate the protection chips, used by several games
(per-game issues)
- stress: accesses the Sound Memory Expansion Area (0x05a80000-0x05afffff), unknown purpose;
- smleague / finlarch: it randomly hangs / crashes, it works if you use a ridiculous set_maximum_quantum() number,
might need strict SH-2 synching or it's actually a m68k comms issue.
- groovef: ugly back screen color, caused by incorrect usage of the Color Calculation function.
- myfairld: Apparently this game gives a black screen (either test mode and in-game mode), but let it wait for about
10 seconds and the game will load everything. This is because of a hellishly slow m68k sub-routine located at 54c2.
Likely to not be a bug but an in-game design issue.
- danchih / danchiq: currently hangs randomly (regression).
- vfremix: when you play as Akira, there is a problem with third match: game doesn't upload all textures
and tiles and doesn't enable display, although gameplay is normal - wait a while to get back
to title screen after losing a match (fixed?)
- vfremix: various problems with SCU DSP: Jeffry causes a black screen hang. Akira's kick sometimes
sends the opponent out of the ring from whatever position.
- critcrsh: has a 2 digits 7-seg LED. The current implementation works in test mode, but during gameplay it's stuck
on the day's best score, while according to reports it should update the number of critters you have crushed.
At the end of the round it outputs the number of crushed critters. Also needs ticket dispenser hookup (redemption
is disabled by the game by default, but can be turned on in test menu).
Reference video: https://www.youtube.com/watch?v=O9PyIKdSFnU
************************************************************************************************************************/
#include "emu.h"
#include "stv.h"
#include "cpu/m68000/m68000.h"
#include "cpu/scudsp/scudsp.h"
#include "cpu/sh/sh7604.h"
#include "machine/smpc.h"
#include "machine/stvcd.h"
#include "sound/scsp.h"
#include "softlist.h"
#include "speaker.h"
#include "critcrsh.lh"
#include "segabill.lh"
#include "segabillv.lh"
#define FIRST_SPEEDUP_SLOT (2) // in case we remove/alter the BIOS speedups later
/*
Sega 315-5649 IO IC, functional same as 315-5338A, also used in Model 2/3, integrated into 315-6146 'MIE' MCU, etc
I/O overview: Connector (as described in service manual)
PORT-A 1st player inputs JAMMA (56P)
PORT-B 2nd player inputs JAMMA (56P)
PORT-C system input JAMMA (56P)
PORT-D system output JAMMA (56P) + CN25 (JST NH 5P) RESERVED OUTPUT 4bit. (?)
PORT-E I/O 1 CN32 (JST NH 9P) EXTENSION I/O 8bit.
PORT-F I/O 2 CN21 (JST NH 11P) EXTENSION I/O 8bit.
PORT-G I/O 3 CN20 (JST HN 10P) EXTENSION INPUT 8bit. (?)
PORT-AD AD-Stick inputs? CN19 (JST NH 12P) A/D INPUT 8Ch.
SERIAL COM CN18 (JST NH 6P) SERIAL COMMUNICATION
??? CN22 (JST NH 3P) MIDI OUT
??? CN27 (JST NH 3P) LIGHT GUN TRIGGER
??? CN24 (JST NH 4P) AUDIO LINE OUTPUT
offsets:
0x0001 PORT-A (P1)
0x0003 PORT-B (P2)
0x0005 PORT-C (SYSTEM)
0x0007 PORT-D (OUTPUT)
0x0009 PORT-E (P3)
0x000b PORT-F (P4 / Extra 6B layout)
0x000d PORT-G
0x000f unused
0x0011 PORT_DIRECTION (each bit configure above IO ports, 1 - input, 0 - output)
---x ---- joystick/mahjong panel select
---- x--- used in danchih (different mux scheme for the hanafuda panel?)
0x0013 RS422 TXD1
0x0015 RS422 TXD2 SERIAL COM Tx
0x0017 RS422 RXD1
0x0019 RS422 RXD2 SERIAL COM Rx
0x001b RS422 FLAG
0x001d MODE (bit 7 - set PORT-G to counter-mode, bits 0-5 - RS422 satellite mode and node#) <Technical Bowling>
0x001f PORT-AD (8ch, write: bits 0-2 - set channel, read: channel data with autoinc channel number)
*/
uint8_t stv_state::stv_ioga_r(offs_t offset)
{
uint8_t res;
res = 0xff;
if(offset & 0x10 && !machine().side_effects_disabled())
logerror("Reading from mirror %08x?\n",offset * 2 + 1);
offset &= 0x0f; // mirror?
switch((offset * 2) + 1)
{
case 0x0d:
if (m_ioga_mode & 0x80) // PORT-G in counter mode
{
uint8_t const sel = (m_ioga_portg >> 1) & 0x03;
res = ((m_ioga_counters[sel]->read() - m_ioga_count[sel]) >> ((~m_ioga_portg & 1) * 8) & 0xff);
m_ioga_portg = (m_ioga_portg & 0xf8) | ((m_ioga_portg + 1) & 0x07); // counter# is auto-incremented on read
break;
}
[[fallthrough]];
case 0x01: // P1
case 0x03: // P2
case 0x05: // SYSTEM
case 0x09: // P3
case 0x0b: // P4
res = m_ioga_ports[offset]->read();
break;
case 0x07: res = m_system_output; break; // port D, read-backs value written
case 0x1b: res = 0; break; // Serial COM READ status
case 0x1d: res = m_ioga_mode; break;
}
return res;
}
void stv_state::stv_ioga_w(offs_t offset, uint8_t data)
{
if(offset & 0x10 && !machine().side_effects_disabled())
logerror("Writing to mirror %08x %02x?\n",offset * 2 + 1,data);
offset &= 0x0f; // mirror?
switch(offset * 2 + 1)
{
case 0x07:
m_system_output = data;
machine().bookkeeping().coin_counter_w(0, data & 0x01);
machine().bookkeeping().coin_counter_w(1, data & 0x02);
machine().bookkeeping().coin_lockout_w(0, ~data & 0x04);
machine().bookkeeping().coin_lockout_w(1, ~data & 0x08);
break;
case 0x09:
m_billboard->write(data);
break;
case 0x0d:
if(!BIT(data, 7)) // when bit 7==0 reset counters
{
for(unsigned i = 0; m_ioga_counters.size() > i; ++i)
m_ioga_count[i] = m_ioga_counters[i]->read();
}
m_ioga_portg = data;
break;
case 0x1d:
m_ioga_mode = data;
break;
}
}
uint8_t stv_state::critcrsh_ioga_r(offs_t offset)
{
const char *const lgnames[] = { "LIGHTX", "LIGHTY" };
uint8_t res = 0xff;
switch(offset * 2 + 1)
{
case 0x01:
case 0x03:
res = ioport(lgnames[offset])->read();
res = bitswap<8>(res, 2, 3, 0, 1, 6, 7, 5, 4) & 0xf3;
res |= (ioport("PORTC")->read() & 0x10) ? 0x0 : 0x4; // x/y hit latch actually
break;
default:
res = stv_ioga_r(offset);
break;
}
return res;
}
void stv_state::critcrsh_ioga_w(offs_t offset, uint8_t data)
{
static uint8_t const bcd2hex[] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7c, 0x07, 0x7f, 0x67, 0x58, 0x4c, 0x62, 0x49, 0x78, 0x00 }; // TODO: chip type unknown
switch (offset * 2 + 1)
{
case 0x0b:
m_cc_digits[0] = bcd2hex[(data & 0xf0) >> 4];
m_cc_digits[1] = bcd2hex[data & 0x0f];
break;
default:
stv_ioga_w(offset, data);
break;
}
}
uint8_t stv_state::magzun_ioga_r(offs_t offset)
{
uint8_t res;
res = 0xff;
// 0x4a 0x40 0x47
switch(offset * 2 + 1)
{
case 0x17:
res = 0;
break;
case 0x19:
res = 0;
break;
default: res = stv_ioga_r(offset); break;
}
return res;
}
void stv_state::magzun_ioga_w(offs_t offset, uint8_t data)
{
switch(offset * 2 + 1)
{
case 0x13: m_serial_tx = (data << 8) | (m_serial_tx & 0xff); break;
case 0x15: m_serial_tx = (data & 0xff) | (m_serial_tx & 0xff00); break;
default: stv_ioga_w(offset,data); break;
}
}
uint8_t stv_state::stvmp_ioga_r(offs_t offset)
{
uint8_t res = 0xff;
switch(offset * 2 + 1)
{
case 0x01:
case 0x03:
if(m_port_sel & 0x10) // joystick select <<< this is obviously wrong, this bit only selects PORTE direction
{
res = stv_ioga_r(offset);
}
else // mahjong panel select
{
for(unsigned i = 0; m_ioga_mahjong[i].size() > i; i++)
{
if(BIT(m_mux_data, i))
res &= m_ioga_mahjong[offset][i]->read();
}
}
break;
default: res = stv_ioga_r(offset); break;
}
return res;
}
void stv_state::stvmp_ioga_w(offs_t offset, uint8_t data)
{
switch(offset * 2 + 1)
{
case 0x09: m_mux_data = data ^ 0xff; break;
case 0x11: m_port_sel = data; break;
default: stv_ioga_w(offset,data); break;
}
}
void stv_state::hop_ioga_w(offs_t offset, uint8_t data)
{
if ((offset * 2 + 1) == 7)
m_hopper->motor_w(data & 0x80);
stv_ioga_w(offset, data);
}
// ST-V hookup for 315-5881 encryption/compression chip
/*
Known ST-V Games using this kind of protection
Astra Superstars (text layer gfx transfer)
Elandoree (gfx transfer of textures)
Final Fight Revenge (boot vectors etc.)
Radiant Silvergun (game start protection)
Steep Slope Sliders (gfx transfer of character portraits)
Tecmo World Cup '98 (Tecmo logo, player movement)
*/
/*************************************
*
* Common Handlers
*
*************************************/
uint32_t stv_state::common_prot_r(offs_t offset)
{
uint32_t *ROM = (uint32_t *)memregion("abus")->base();
if(m_abus_protenable & 0x00010000)//protection calculation is activated
{
if(offset == 3)
{
uint8_t* base;
uint16_t res = m_cryptdevice->do_decrypt(base);
uint16_t res2 = m_cryptdevice->do_decrypt(base);
res = ((res & 0xff00) >> 8) | ((res & 0x00ff) << 8);
res2 = ((res2 & 0xff00) >> 8) | ((res2 & 0x00ff) << 8);
return res2 | (res << 16);
}
return m_a_bus[offset];
}
else
{
if(m_a_bus[offset] != 0) return m_a_bus[offset];
else return ROM[(0x02fffff0/4)+offset];
}
}
uint16_t stv_state::crypt_read_callback(uint32_t addr)
{
uint16_t dat= m_maincpu->space().read_word((0x02000000+2*addr));
return ((dat&0xff00)>>8)|((dat&0x00ff)<<8);
}
void stv_state::common_prot_w(offs_t offset, uint32_t data, uint32_t mem_mask)
{
COMBINE_DATA(&m_a_bus[offset]);
if (offset == 0)
{
COMBINE_DATA(&m_abus_protenable);
}
else if(offset == 2)
{
if (ACCESSING_BITS_16_31) m_cryptdevice->set_addr_low(data >> 16);
if (ACCESSING_BITS_0_15) m_cryptdevice->set_addr_high(data&0xffff);
}
else if(offset == 3)
{
COMBINE_DATA(&m_abus_protkey);
m_cryptdevice->set_subkey(m_abus_protkey>>16);
}
}
void stv_state::install_common_protection()
{
m_maincpu->space(AS_PROGRAM).install_read_handler(0x4fffff0, 0x4ffffff, read32sm_delegate(*this, FUNC(stv_state::common_prot_r)));
m_maincpu->space(AS_PROGRAM).install_write_handler(0x4fffff0, 0x4ffffff, write32s_delegate(*this, FUNC(stv_state::common_prot_w)));
}
void stv_state::stv_register_protection_savestates()
{
save_item(NAME(m_a_bus));
}
/*
06013AE8: MOV.L @($D4,PC),R5
06013AEA: MOV.L @($D8,PC),R0
06013AEC: MOV.W @R5,R5
06013AEE: MOV.L @R0,R0
06013AF0: AND R10,R5
06013AF2: TST R0,R0
06013AF4: BTS $06013B00
06013AF6: EXTS.W R5,R5
06013B00: EXTS.W R5,R5
06013B02: TST R5,R5
06013B04: BF $06013B0A
06013B06: TST R4,R4
06013B08: BT $06013AE8
(loops for 375868 instructions)
*/
void stv_state::install_stvbios_speedups( void )
{
// flushes 0 & 1 on both CPUs are for the BIOS speedups
m_maincpu->sh2drc_add_pcflush(0x60154b2);
m_maincpu->sh2drc_add_pcflush(0x6013aee);
m_slave->sh2drc_add_pcflush(0x60154b2);
m_slave->sh2drc_add_pcflush(0x6013aee);
}
void stv_state::init_stv()
{
/* amount of time to boost interleave for on MINIT / SINIT, needed for communication to work */
m_minit_boost = 400;
m_sinit_boost = 400;
m_minit_boost_timeslice = attotime::zero;
m_sinit_boost_timeslice = attotime::zero;
// m_scu_regs = std::make_unique<uint32_t[]>(0x100/4);
m_backupram = std::make_unique<uint8_t[]>(0x8000);
memset(m_backupram.get(), 0, sizeof(uint8_t) * 0x8000);
install_stvbios_speedups();
// do strict overwrite verification - maruchan and rsgun crash after coinup without this.
// cottonbm needs strict PCREL
// todo: test what games need this and don't turn it on for them...
m_maincpu->sh2drc_set_options(SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
m_slave->sh2drc_set_options(SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
m_maincpu->sh2drc_add_fastram(0x00000000, 0x0007ffff, 1, &m_rom[0]);
m_maincpu->sh2drc_add_fastram(0x00200000, 0x002fffff, 0, &m_workram_l[0]);
m_maincpu->sh2drc_add_fastram(0x06000000, 0x060fffff, 0, &m_workram_h[0]);
m_slave->sh2drc_add_fastram(0x00000000, 0x0007ffff, 1, &m_rom[0]);
m_slave->sh2drc_add_fastram(0x00200000, 0x002fffff, 0, &m_workram_l[0]);
m_slave->sh2drc_add_fastram(0x06000000, 0x060fffff, 0, &m_workram_h[0]);
m_vdp2.pal = 0;
}
/*
- if pc==604bf20 && 608e832 <- 1 (HWEF)
- if pc==604bfbe && 608e832 <- 2 (HREF)
- if pc==604c006 && 60ff3b7 <- 0x40 (they tries to read-back 0x40?)
TODO: game doesn't work if not in debugger?
*/
uint32_t stv_state::magzun_hef_hack_r()
{
if(m_maincpu->pc()==0x604bf20) return 0x00000001; //HWEF
if(m_maincpu->pc()==0x604bfbe) return 0x00000002; //HREF
return m_workram_h[0x08e830/4];
}
uint32_t stv_state::magzun_rx_hack_r()
{
if(m_maincpu->pc()==0x604c006) return 0x40;
return m_workram_h[0x0ff3b4/4];
}
void stv_state::init_magzun()
{
m_maincpu->sh2drc_add_pcflush(0x604bf20);
m_maincpu->sh2drc_add_pcflush(0x604bfbe);
m_maincpu->sh2drc_add_pcflush(0x604c006);
init_stv();
m_maincpu->space(AS_PROGRAM).install_read_handler(0x608e830, 0x608e833, read32smo_delegate(*this, FUNC(stv_state::magzun_hef_hack_r)));
m_maincpu->space(AS_PROGRAM).install_read_handler(0x60ff3b4, 0x60ff3b7, read32smo_delegate(*this, FUNC(stv_state::magzun_rx_hack_r)));
/* Program ROM patches, don't understand how to avoid these two checks ... */
{
uint32_t *ROM = (uint32_t *)memregion("cart")->base();
ROM[0x90054/4] = 0x00e00001; // END error
ROM[0x34f4/4] = 0x00000009; // Time Out sub-routine
}
}
void stv_state::init_shienryu()
{
// master
m_maincpu->sh2drc_add_pcflush(0x60041c6);
// slave
m_slave->sh2drc_add_pcflush(0x600440e);
init_stv();
}
void stv_state::init_prikura()
{
/*
06018640: MOV.B @R14,R0 // 60b9228
06018642: TST R0,R0
06018644: BF $06018640
(loops for 263473 instructions)
*/
// master
m_maincpu->sh2drc_add_pcflush(0x6018640);
// slave
m_slave->sh2drc_add_pcflush(0x6018c6e);
init_stv();
m_minit_boost = m_sinit_boost = 0;
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(50);
}
void stv_state::init_hanagumi()
{
/*
06013E1E: NOP
0601015E: MOV.L @($6C,PC),R3
06010160: MOV.L @R3,R0 (6094188)
06010162: TST R0,R0
06010164: BT $0601015A
0601015A: JSR R14
0601015C: NOP
06013E20: MOV.L @($34,PC),R3
06013E22: MOV.B @($00,R3),R0
06013E24: TST R0,R0
06013E26: BT $06013E1C
06013E1C: RTS
06013E1E: NOP
(loops for 288688 instructions)
*/
m_maincpu->sh2drc_add_pcflush(0x6010160);
init_stv();
}
/* these idle loops might change if the interrupts change / are fixed because i don't really think these are vblank waits... */
/* puyosun
CPU0: Aids Screen
06021CF0: MOV.B @($13,GBR),R0 (60ffc13)
06021CF2: CMP/PZ R0
06021CF4: BT $06021CF0
(loops for xxx instructions)
this is still very slow .. but i don't think it can be sped up further
*/
void stv_state::init_puyosun()
{
m_maincpu->sh2drc_add_pcflush(0x6021cf0);
m_slave->sh2drc_add_pcflush(0x60236fe);
init_stv();
m_minit_boost = m_sinit_boost = 0;
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(50);
}
/* mausuke
CPU0 Data East Logo:
060461A0: MOV.B @($13,GBR),R0 (60ffc13)
060461A2: CMP/PZ R0
060461A4: BT $060461A0
(loops for 232602 instructions)
*/
void stv_state::init_mausuke()
{
m_maincpu->sh2drc_add_pcflush(0x60461A0);
init_stv();
m_minit_boost = m_sinit_boost = 0;
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(50);
}
void stv_state::init_cottonbm()
{
// m_maincpu->sh2drc_add_pcflush(0x6030ee2);
// m_slave->sh2drc_add_pcflush(0x6032b52);
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(10);
}
void stv_state::init_cotton2()
{
m_maincpu->sh2drc_add_pcflush(0x6031c7a);
m_slave->sh2drc_add_pcflush(0x60338ea);
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(50);
}
void stv_state::init_dnmtdeka()
{
// install all 3 speedups on both master and slave
m_maincpu->sh2drc_add_pcflush(0x6027c90);
m_maincpu->sh2drc_add_pcflush(0xd04);
m_maincpu->sh2drc_add_pcflush(0x60051f2);
m_slave->sh2drc_add_pcflush(0x6027c90);
m_slave->sh2drc_add_pcflush(0xd04);
m_slave->sh2drc_add_pcflush(0x60051f2);
init_stv();
}
void stv_state::init_diehard()
{
// install all 3 speedups on both master and slave
m_maincpu->sh2drc_add_pcflush(0x6027c98);
m_maincpu->sh2drc_add_pcflush(0xd04);
m_maincpu->sh2drc_add_pcflush(0x60051f2);
m_slave->sh2drc_add_pcflush(0x6027c98);
m_slave->sh2drc_add_pcflush(0xd04);
m_slave->sh2drc_add_pcflush(0x60051f2);
init_stv();
}
void stv_state::init_fhboxers()
{
m_maincpu->sh2drc_add_pcflush(0x60041c2);
m_maincpu->sh2drc_add_pcflush(0x600bb0a);
m_maincpu->sh2drc_add_pcflush(0x600b31e);
init_stv();
// m_instadma_hack = 1;
}
void stv_state::init_groovef()
{
m_maincpu->sh2drc_add_pcflush(0x6005e7c);
m_maincpu->sh2drc_add_pcflush(0x6005e86);
m_maincpu->sh2drc_add_pcflush(0x60a4970);
m_slave->sh2drc_add_pcflush(0x60060c2);
init_stv();
m_minit_boost = m_sinit_boost = 0;
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(50);
}
void stv_state::init_danchih()
{
m_maincpu->sh2drc_add_pcflush(0x6028b28);
m_maincpu->sh2drc_add_pcflush(0x6028c8e);
m_slave->sh2drc_add_pcflush(0x602ae26);
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(5);
}
void stv_state::init_danchiq()
{
m_maincpu->sh2drc_add_pcflush(0x6028b28);
m_maincpu->sh2drc_add_pcflush(0x6028c8e);
m_slave->sh2drc_add_pcflush(0x602ae26);
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(5);
}
void stv_state::init_astrass()
{
m_maincpu->sh2drc_add_pcflush(0x60011ba);
m_maincpu->sh2drc_add_pcflush(0x605b9da);
install_common_protection();
init_stv();
}
void stv_state::init_thunt()
{
m_maincpu->sh2drc_add_pcflush(0x602A024);
m_maincpu->sh2drc_add_pcflush(0x6013EEA);
m_slave->sh2drc_add_pcflush(0x602AAF8);
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(1);
}
void stv_state::init_sandor()
{
m_maincpu->sh2drc_add_pcflush(0x602a0f8);
m_maincpu->sh2drc_add_pcflush(0x6013fbe);
m_slave->sh2drc_add_pcflush(0x602abcc);
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(1);
}
void stv_state::init_grdforce()
{
m_maincpu->sh2drc_add_pcflush(0x6041e32);
m_slave->sh2drc_add_pcflush(0x6043aa2);
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(50);
}
void stv_state::init_batmanfr()
{
m_maincpu->sh2drc_add_pcflush(0x60121c0);
m_slave->sh2drc_add_pcflush(0x60125bc);
init_stv();
m_maincpu->space(AS_PROGRAM).install_write_handler(0x04800000, 0x04800003, write32s_delegate(*this, FUNC(stv_state::batmanfr_sound_comms_w)));
m_slave->space(AS_PROGRAM).install_write_handler(0x04800000, 0x04800003, write32s_delegate(*this, FUNC(stv_state::batmanfr_sound_comms_w)));
m_minit_boost = m_sinit_boost = 0;
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(50);
}
void stv_state::init_colmns97()
{
m_slave->sh2drc_add_pcflush(0x60298a2);
init_stv();
m_minit_boost = m_sinit_boost = 0;
}
void stv_state::init_winterht()
{
m_maincpu->sh2drc_add_pcflush(0x6098aea);
m_slave->sh2drc_add_pcflush(0x609ae4e);
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(2);
}
void stv_state::init_seabass()
{
m_maincpu->sh2drc_add_pcflush(0x602cbfa);
m_slave->sh2drc_add_pcflush(0x60321ee);
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(5);
}
void stv_state::init_vfremix()
{
m_maincpu->sh2drc_add_pcflush(0x602c30c);
m_slave->sh2drc_add_pcflush(0x604c332);
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(20);
}
void stv_state::init_sss()
{
m_maincpu->sh2drc_add_pcflush(0x6026398);
m_slave->sh2drc_add_pcflush(0x6028cd6);
install_common_protection();
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(50);
}
void stv_state::init_othellos()
{
m_maincpu->sh2drc_add_pcflush(0x602bcbe);
m_slave->sh2drc_add_pcflush(0x602d92e);
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(50);
}
void stv_state::init_sasissu()
{
m_slave->sh2drc_add_pcflush(0x60710be);
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(2);
}
void stv_state::init_gaxeduel()
{
// m_maincpu->sh2drc_add_pcflush(0x6012ee4);
init_stv();
}
void stv_state::init_suikoenb()
{
m_maincpu->sh2drc_add_pcflush(0x6013f7a);
init_stv();
}
void stv_state::init_sokyugrt()
{
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(50);
}
void stv_state::init_znpwfv()
{
m_maincpu->sh2drc_add_pcflush(0x6012ec2);
m_slave->sh2drc_add_pcflush(0x60175a6);
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_nsec(500);
}
void stv_state::init_twcup98()
{
m_maincpu->sh2drc_add_pcflush(0x605edde);
m_slave->sh2drc_add_pcflush(0x6062bca);
init_stv();
install_common_protection();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(5);
}
void stv_state::init_smleague()
{
m_maincpu->sh2drc_add_pcflush(0x6063bf4);
m_slave->sh2drc_add_pcflush(0x6062bca);
init_stv();
/* tight sync to avoid dead locks */
m_minit_boost = m_sinit_boost = 5000;
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(5000);
}
void stv_state::init_finlarch()
{
m_maincpu->sh2drc_add_pcflush(0x6064d60);
init_stv();
/* tight sync to avoid dead locks */
m_minit_boost = m_sinit_boost = 5000;
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(5000);
}
void stv_state::init_maruchan()
{
m_maincpu->sh2drc_add_pcflush(0x601ba46);
m_slave->sh2drc_add_pcflush(0x601ba46);
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(50);
}
void stv_state::init_pblbeach()
{
m_maincpu->sh2drc_add_pcflush(0x605eb78);
init_stv();
}
void stv_state::init_shanhigw()
{
m_maincpu->sh2drc_add_pcflush(0x6020c5c);
init_stv();
}
void stv_state::init_elandore()
{
m_maincpu->sh2drc_add_pcflush(0x604eac0);
m_slave->sh2drc_add_pcflush(0x605340a);
install_common_protection();
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(0);
}
void stv_state::init_rsgun()
{
m_maincpu->sh2drc_add_pcflush(0x6034d04);
m_slave->sh2drc_add_pcflush(0x6036152);
install_common_protection();
init_stv();
m_minit_boost_timeslice = m_sinit_boost_timeslice = attotime::from_usec(20);
}
void stv_state::init_ffreveng()
{
install_common_protection();
init_stv();
}
uint32_t stv_state::decathlt_prot_r(offs_t offset, uint32_t mem_mask)
{
// needs to be a way to indicate if device is enabled and fall through to cartridge data if not?
if (m_newprotection_element)
{
m_newprotection_element = false;
m_5838crypt->debug_helper(m_protbankval);
}
uint32_t ret = 0;
if (mem_mask & 0xffff0000) ret |= (m_5838crypt->data_r()<<16);
if (mem_mask & 0x0000ffff) ret |= m_5838crypt->data_r();
return ret;
}
void stv_state::decathlt_prot_srcaddr_w(offs_t offset, uint32_t data, uint32_t mem_mask)
{
int offs = offset * 4;
m_protbankval = (offs & 0x1800000)>>23;
m_protbank->set_entry(m_protbankval); // if the protection device is accessed at this address data is fetched from 0x02000000
m_newprotection_element = true;
if ((offs & 0x7fffff) == 0x7FFFF0)
{
m_5838crypt->srcaddr_w(offs, data, mem_mask);
}
else if ((offs & 0x7fffff) == 0x7FFFF4)
{
m_5838crypt->data_w(offs, data, mem_mask);
}
}
void stv_state::init_decathlt()
{
m_maincpu->space(AS_PROGRAM).install_write_handler(0x2000000, 0x37fffff, write32s_delegate(*this, FUNC(stv_state::decathlt_prot_srcaddr_w))); // set compressed data source address, write data
// really needs installing over the whole range, with fallbacks to read rom if device is disabled or isn't accessed on given address
m_maincpu->space(AS_PROGRAM).install_read_handler(0x27ffff8, 0x27ffffb, read32s_delegate(*this, FUNC(stv_state::decathlt_prot_r))); // read decompressed data
m_maincpu->space(AS_PROGRAM).install_read_handler(0x2fffff8, 0x2fffffb, read32s_delegate(*this, FUNC(stv_state::decathlt_prot_r))); // ^
m_maincpu->space(AS_PROGRAM).install_read_handler(0x37ffff8, 0x37ffffb, read32s_delegate(*this, FUNC(stv_state::decathlt_prot_r))); // ^
m_protbank->configure_entry(0, memregion("cart")->base() + 0x0000000);
m_protbank->configure_entry(1, memregion("cart")->base() + 0x0800000);
m_protbank->configure_entry(2, memregion("cart")->base() + 0x1000000);
//m_protbank->configure_entry(3, memregion("cart")->base() + 0x1800000);
m_protbank->set_entry(0);
m_newprotection_element = false;
init_stv();
}
void stv_state::init_decathlt_nokey()
{
init_decathlt();
m_5838crypt->set_hack_mode(sega_315_5838_comp_device::HACK_MODE_NO_KEY);
}
void stv_state::init_nameclv3()
{
m_maincpu->sh2drc_add_pcflush(0x601eb4c);
m_slave->sh2drc_add_pcflush(0x602b80e);
init_stv();
}
void stv_state::init_stv_us()
{
init_stv();
m_smpc_hle->set_region_code(4); // 4 - USA, configured via jumpers, should be added to input ports as DIPSW ?
}
void stv_state::stv_mem(address_map &map)
{
map(0x00000000, 0x0007ffff).rom().mirror(0x20000000).region("bios", 0); // bios
map(0x00100000, 0x0010007f).rw(m_smpc_hle, FUNC(smpc_hle_device::read), FUNC(smpc_hle_device::write));
map(0x00180000, 0x0018ffff).rw(FUNC(stv_state::saturn_backupram_r), FUNC(stv_state::saturn_backupram_w)).share("share1");
map(0x00200000, 0x002fffff).ram().mirror(0x20100000).share("workram_l");
map(0x00400000, 0x0040003f).rw(FUNC(stv_state::stv_ioga_r), FUNC(stv_state::stv_ioga_w)).umask32(0x00ff00ff);