/
subsino2.cpp
4068 lines (3369 loc) · 164 KB
/
subsino2.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:Luca Elia
/************************************************************************************************************
-= Subsino (Newer) Tilemaps Hardware =-
driver by Luca Elia (l.elia@tin.it)
Two 1024x512 tilemaps. 256 color tiles. Tiles are 8x8 or a multiple (dynamic tile size).
There is RAM for 512 scroll values (line scroll). Video RAM is mirrored on multiple ranges.
One peculiarity is that video RAM access is split into high and low byte. The former is mapped
in program space, the latter in I/O space.
----------------------------------------------------------------------------------------------------------------
Year Game CPU Sound Custom Other
----------------------------------------------------------------------------------------------------------------
1996 Magic Train HD647180* U6295 SS9601, SS9602 HM86171 RAMDAC, Battery
1996 Water-Nymph HD647180* U6295 SS9601, SS9602 HM86171 RAMDAC, Battery
1998 Express Card AM188-EM M6295 SS9601, SS9802, SS9803 HM86171 RAMDAC, Battery
1998 Ying Hua Lian AM188-EM M6295 + YM3812? SS9601, SS9602 HM86171 RAMDAC, Battery
1999 Bishou Jan H8/3044** SS9904 SS9601, SS9802, SS9803 HM86171 RAMDAC, Battery
1999 X-Train/P-Train AM188-EM M6295 SS9601, SS9802, SS9803 HM86171 RAMDAC, Battery
2000 New 2001 H8/3044** SS9904 SS9601, SS9802, SS9803 HM86171 RAMDAC, Battery
2001 Queen Bee H8/3044** SS9804 SS9601, SS9802, SS9803 HM86171 RAMDAC, Battery
2001 Humlan's Lyckohjul H8/3044** SS9804 SS9601, SS9802, SS9803 HM86171 RAMDAC, Battery
2002 Super Queen Bee H8/3044** ? ? ?
2006 X-Plan AM188-EM M6295 SS9601, SS9802, SS9803 HM86171 RAMDAC, Battery
----------------------------------------------------------------------------------------------------------------
*SS9600 **SS9689
Graphics for the H8-based games are stored in either four socketed DIP28 8-bit EPROMs, two socketed DIP40 16-bit EPROMs or one
surface-mounted SSOP70 32-bit ROM. Later H8-based PCBs have a custom QFP device labeled "SG 003" instead of the off-the-shelf
RAMDAC.
To do:
- Add sound to SS9804/SS9904 games.
- ptrain: missing scroll in race screens.
- humlan: empty reels when bonus image should scroll in via L0 scroll. The image (crown/fruits) is at y > 0x100 in the tilemap.
- bishjan, new2001, humlan, saklove, squeenb: game is sometimes too fast (can bishjan read the VBLANK state? saklove and xplan can).
- xtrain: it runs faster than a video from the real thing. It doesn't use vblank irqs (but reads the vblank bit).
- mtrain: implement hopper.
- xplan: starts with 4 credits, no controls to move the aircraft
Protection seems to work the same way on every game in this driver, using a bitbanged Dallas 1-Wire EEPROM. First a Read ROM
command is issued, and only the first 8 bits returned are examined to determine whether they match the expected device code (0x14).
If this test passes, the EEPROM contents are recalled and the first 64 bits are read out. These 64 bits are then unscrambled using
a permutation table common to all games. The second and final protection check compares byte 6 in the unscrambled data buffer
against a game-specific ID code. This byte is composed of EEPROM bits 22 (MSB), 27, 52, 50, 42, 9, 38 and 35 (LSB). This EEPROM
comes in a small TO-92 package which is very difficult to spot on PCB photos, though it appears to be typically positioned near
one of the edge connectors.
Timings in the Z180-based and H8-based games consistently fail to meet 1-Wire specifications. In the case of the H8-based games,
this likely has to do with CPU clocks and emulated cycle timings being both too fast. There may also be wait states programmed
by the otherwise seemingly unnecessary internal ROMs.
************************************************************************************************************/
#include "emu.h"
#include "subsino_crypt.h"
#include "subsino_io.h"
#include "cpu/h8/h83048.h"
#include "cpu/i86/i186.h"
#include "cpu/z180/hd647180x.h"
#include "machine/ds2430a.h"
#include "machine/nvram.h"
#include "machine/ticket.h"
#include "sound/okim6295.h"
#include "sound/ymopl.h"
#include "video/ramdac.h"
#include "emupal.h"
#include "screen.h"
#include "speaker.h"
#include "tilemap.h"
enum tilesize_t : uint8_t
{
TILE_8x8,
TILE_8x32,
TILE_64x32
};
ALLOW_SAVE_TYPE(tilesize_t);
enum vram_t
{
VRAM_LO,
VRAM_HI
};
// Layers
struct layer_t
{
std::unique_ptr<uint16_t[]> videoram;
std::unique_ptr<uint16_t[]> scrollram;
int scroll_x;
int scroll_y;
tilemap_t *tmap;
tilesize_t tilesize;
};
class subsino2_state : public driver_device
{
public:
subsino2_state(const machine_config &mconfig, device_type type, const char *tag)
: driver_device(mconfig, type, tag)
, m_maincpu(*this, "maincpu")
, m_oki(*this, "oki")
, m_gfxdecode(*this, "gfxdecode")
, m_screen(*this, "screen")
, m_palette(*this, "palette")
, m_hopper(*this, "hopper")
, m_ticket(*this, "ticket")
, m_eeprom(*this, "eeprom")
, m_keyb(*this, "KEYB_%u", 0U)
, m_dsw(*this, "DSW%u", 1U)
, m_leds(*this, "led%u", 0U)
{ }
void bishjan(machine_config &config);
void xiaoao(machine_config &config);
void saklove(machine_config &config);
void mtrain(machine_config &config);
void tbonusal(machine_config &config);
void humlan(machine_config &config);
void new2001(machine_config &config);
void expcard(machine_config &config);
void xplan(machine_config &config);
void xtrain(machine_config &config);
void ptrain(machine_config &config);
void init_bishjan();
void init_xiaoao();
void init_new2001();
void init_queenbee();
void init_queenbeeb();
void init_queenbeei();
void init_humlan();
void init_squeenb();
void init_qbeebing();
void init_treamary();
void init_wtrnymph();
void init_mtrain();
void init_tbonusal();
protected:
virtual void video_start() override;
private:
void ss9601_byte_lo_w(uint8_t data);
void ss9601_byte_lo2_w(uint8_t data);
void ss9601_videoram_0_hi_w(offs_t offset, uint8_t data);
void ss9601_videoram_0_lo_w(offs_t offset, uint8_t data);
void ss9601_videoram_0_hi_lo_w(offs_t offset, uint8_t data);
void ss9601_videoram_0_hi_lo2_w(offs_t offset, uint8_t data);
uint8_t ss9601_videoram_0_hi_r(offs_t offset);
uint8_t ss9601_videoram_0_lo_r(offs_t offset);
void ss9601_videoram_1_hi_w(offs_t offset, uint8_t data);
void ss9601_videoram_1_lo_w(offs_t offset, uint8_t data);
void ss9601_videoram_1_hi_lo_w(offs_t offset, uint8_t data);
void ss9601_videoram_1_hi_lo2_w(offs_t offset, uint8_t data);
uint8_t ss9601_videoram_1_hi_r(offs_t offset);
uint8_t ss9601_videoram_1_lo_r(offs_t offset);
void ss9601_reelram_hi_lo_w(offs_t offset, uint8_t data);
uint8_t ss9601_reelram_hi_r(offs_t offset);
uint8_t ss9601_reelram_lo_r(offs_t offset);
void ss9601_scrollctrl_w(uint8_t data);
void ss9601_tilesize_w(uint8_t data);
void ss9601_scroll_w(offs_t offset, uint8_t data);
void ss9601_scrollram_0_hi_w(offs_t offset, uint8_t data);
void ss9601_scrollram_0_lo_w(offs_t offset, uint8_t data);
void ss9601_scrollram_0_hi_lo_w(offs_t offset, uint8_t data);
uint8_t ss9601_scrollram_0_hi_r(offs_t offset);
uint8_t ss9601_scrollram_0_lo_r(offs_t offset);
void ss9601_scrollram_1_hi_w(offs_t offset, uint8_t data);
void ss9601_scrollram_1_lo_w(offs_t offset, uint8_t data);
void ss9601_scrollram_1_hi_lo_w(offs_t offset, uint8_t data);
uint8_t ss9601_scrollram_1_hi_r(offs_t offset);
uint8_t ss9601_scrollram_1_lo_r(offs_t offset);
void ss9601_disable_w(uint8_t data);
void dsw_mask_w(uint8_t data);
uint8_t dsw_r();
uint8_t vblank_bit2_r();
uint8_t vblank_bit6_r();
uint8_t bishjan_sound_r();
void bishjan_sound_w(uint8_t data);
uint8_t bishjan_serial_r();
uint8_t xiaoao_serial_r();
uint8_t bishjan_unknown_r();
void bishjan_input_w(uint8_t data);
uint8_t bishjan_input_r();
void bishjan_outputs_w(uint8_t data);
uint8_t new2001_sound_ready_r();
void new2001_output0_w(uint8_t data);
void new2001_output1_w(uint8_t data);
void humlan_output0_w(uint8_t data);
void humlan_output1_w(uint8_t data);
void expcard_out_b_w(uint8_t data);
void expcard_out_a_w(uint8_t data);
void mtrain_output0_w(uint8_t data);
void mtrain_output1_w(uint8_t data);
void mtrain_output2_w(uint8_t data);
void mtrain_output3_w(uint8_t data);
void mtrain_videoram_w(offs_t offset, uint8_t data);
void mtrain_tilesize_w(uint8_t data);
void saklove_output0_w(uint8_t data);
void saklove_output1_w(uint8_t data);
void saklove_output2_w(uint8_t data);
void saklove_output3_w(uint8_t data);
void xplan_out_d_w(uint8_t data);
void xplan_out_c_w(uint8_t data);
void xplan_out_b_w(uint8_t data);
void xplan_out_a_w(uint8_t data);
void xtrain_out_d_w(uint8_t data);
void xtrain_out_c_w(uint8_t data);
void xtrain_out_b_w(uint8_t data);
void xtrain_out_a_w(uint8_t data);
void oki_bank_bit0_w(uint8_t data);
void oki_bank_bit4_w(uint8_t data);
TILE_GET_INFO_MEMBER(ss9601_get_tile_info_0);
TILE_GET_INFO_MEMBER(ss9601_get_tile_info_1);
uint32_t screen_update_subsino2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
void bishjan_map(address_map &map);
void mtrain_io(address_map &map);
void mtrain_base_map(address_map &map);
void mtrain_map(address_map &map);
void tbonusal_map(address_map &map);
void new2001_map(address_map &map);
void ramdac_map(address_map &map);
void saklove_io(address_map &map);
void saklove_map(address_map &map);
void xplan_io(address_map &map);
void xplan_map(address_map &map);
virtual void machine_start() override { m_leds.resolve(); }
layer_t m_layers[2];
uint8_t m_ss9601_byte_lo;
uint8_t m_ss9601_byte_lo2;
std::unique_ptr<uint16_t[]> m_ss9601_reelram;
bitmap_ind16 m_reelbitmap;
uint8_t m_ss9601_scrollctrl;
uint8_t m_ss9601_tilesize;
uint8_t m_ss9601_disable;
uint8_t m_dsw_mask;
uint8_t m_bishjan_sound;
uint8_t m_bishjan_input;
required_device<cpu_device> m_maincpu;
optional_device<okim6295_device> m_oki;
required_device<gfxdecode_device> m_gfxdecode;
required_device<screen_device> m_screen;
required_device<palette_device> m_palette;
optional_device<ticket_dispenser_device> m_hopper;
optional_device<ticket_dispenser_device> m_ticket;
required_device<ds2430a_device> m_eeprom;
optional_ioport_array<5> m_keyb;
optional_ioport_array<4> m_dsw;
output_finder<9> m_leds;
inline void ss9601_get_tile_info(layer_t *l, tile_data &tileinfo, tilemap_memory_index tile_index);
};
/***************************************************************************
Tilemaps Access
***************************************************************************/
inline void subsino2_state::ss9601_get_tile_info(layer_t *l, tile_data &tileinfo, tilemap_memory_index tile_index)
{
int addr;
uint16_t offs;
switch (l->tilesize)
{
default:
case TILE_8x8: addr = tile_index; offs = 0; break;
case TILE_8x32: addr = tile_index & (~0x180); offs = (tile_index/0x80) & 3; break;
case TILE_64x32: addr = tile_index & (~0x187); offs = ((tile_index/0x80) & 3) + (tile_index & 7) * 4; break;
}
tileinfo.set(0, l->videoram[addr] + offs, 0, 0);
}
// Layer 0
TILE_GET_INFO_MEMBER(subsino2_state::ss9601_get_tile_info_0)
{
ss9601_get_tile_info(&m_layers[0], tileinfo, tile_index);
}
// Layer 1
TILE_GET_INFO_MEMBER(subsino2_state::ss9601_get_tile_info_1)
{
ss9601_get_tile_info(&m_layers[1], tileinfo, tile_index);
}
void subsino2_state::ss9601_byte_lo_w(uint8_t data)
{
m_ss9601_byte_lo = data;
}
void subsino2_state::ss9601_byte_lo2_w(uint8_t data)
{
m_ss9601_byte_lo2 = data;
}
static inline void ss9601_videoram_w(layer_t *l, vram_t vram, offs_t offset, uint8_t data)
{
switch (vram)
{
case VRAM_HI:
l->videoram[offset] = uint8_t(data) << 8 | (l->videoram[offset] & 0xff);
break;
case VRAM_LO:
l->videoram[offset] = data | (l->videoram[offset] & 0xff00);
break;
}
switch (l->tilesize)
{
default:
case TILE_8x8:
l->tmap->mark_tile_dirty(offset);
break;
case TILE_8x32:
offset &= ~0x180;
for (int y = 0; y < 0x80*4; y += 0x80)
l->tmap->mark_tile_dirty(offset + y);
break;
case TILE_64x32:
offset &= ~0x187;
for (int x = 0; x < 8; x++)
for (int y = 0; y < 0x80*4; y += 0x80)
l->tmap->mark_tile_dirty(offset + y + x);
break;
}
}
// Layer 0
void subsino2_state::ss9601_videoram_0_hi_w(offs_t offset, uint8_t data)
{
ss9601_videoram_w(&m_layers[0], VRAM_HI, offset, data);
}
void subsino2_state::ss9601_videoram_0_lo_w(offs_t offset, uint8_t data)
{
ss9601_videoram_w(&m_layers[0], VRAM_LO, offset, data);
}
void subsino2_state::ss9601_videoram_0_hi_lo_w(offs_t offset, uint8_t data)
{
ss9601_videoram_w(&m_layers[0], VRAM_HI, offset, data);
ss9601_videoram_w(&m_layers[0], VRAM_LO, offset, m_ss9601_byte_lo);
}
void subsino2_state::ss9601_videoram_0_hi_lo2_w(offs_t offset, uint8_t data)
{
ss9601_videoram_w(&m_layers[0], VRAM_HI, offset, data);
ss9601_videoram_w(&m_layers[0], VRAM_LO, offset, m_ss9601_byte_lo2);
}
uint8_t subsino2_state::ss9601_videoram_0_hi_r(offs_t offset)
{
return m_layers[0].videoram[offset] >> 8;
}
uint8_t subsino2_state::ss9601_videoram_0_lo_r(offs_t offset)
{
return m_layers[0].videoram[offset] & 0xff;
}
// Layer 1
void subsino2_state::ss9601_videoram_1_hi_w(offs_t offset, uint8_t data)
{
ss9601_videoram_w(&m_layers[1], VRAM_HI, offset, data);
}
void subsino2_state::ss9601_videoram_1_lo_w(offs_t offset, uint8_t data)
{
ss9601_videoram_w(&m_layers[1], VRAM_LO, offset, data);
}
void subsino2_state::ss9601_videoram_1_hi_lo_w(offs_t offset, uint8_t data)
{
ss9601_videoram_w(&m_layers[1], VRAM_HI, offset, data);
ss9601_videoram_w(&m_layers[1], VRAM_LO, offset, m_ss9601_byte_lo);
}
void subsino2_state::ss9601_videoram_1_hi_lo2_w(offs_t offset, uint8_t data)
{
ss9601_videoram_w(&m_layers[1], VRAM_HI, offset, data);
ss9601_videoram_w(&m_layers[1], VRAM_LO, offset, m_ss9601_byte_lo2);
}
uint8_t subsino2_state::ss9601_videoram_1_hi_r(offs_t offset)
{
return m_layers[1].videoram[offset] >> 8;
}
uint8_t subsino2_state::ss9601_videoram_1_lo_r(offs_t offset)
{
return m_layers[1].videoram[offset] & 0xff;
}
// Layer 0 Reels
void subsino2_state::ss9601_reelram_hi_lo_w(offs_t offset, uint8_t data)
{
m_ss9601_reelram[offset] = uint16_t(data) << 8 | m_ss9601_byte_lo;
}
uint8_t subsino2_state::ss9601_reelram_hi_r(offs_t offset)
{
return m_ss9601_reelram[offset] >> 8;
}
uint8_t subsino2_state::ss9601_reelram_lo_r(offs_t offset)
{
return m_ss9601_reelram[offset] & 0xff;
}
/***************************************************************************
Tilemaps Tile Size
mtrain:
80 = 00 40 = - L0 = 8x8 L1 = 8x8 ; title screen
80 = 01 40 = - L0 = REEL L1 = 8x8 ; gameplay (center reel)
80 = 01 40 = - L0 = REEL L1 = 8x8 ; girl slot (top, bottom reels)
xtrain:
80 = 00 40 = FD L0 = - L1 = 8x8 ; ram test (disable = 01 -> L0 disabled)
80 = 40 40 = FD L0 = REEL L1 = 8x8 ; game play (center reel) as well as "BONUS" screen (top reel)
80 = 40 40 = FD L0 = REEL L1 = 8x8 ; lose/treasure slot (center reel)
80 = 00 40 = BF L0 = 8x8 L1 = 8x8 ; car screen [L0 line scroll every 32]
80 = 00 40 = EF L0 = 8x8 L1 = 8x8 ; title screen, L0 normal scroll (scrollram is 0) [L1 line scroll every 8]
80 = 40 40 = 00 L0 = 8x16? L1 = 8x8 ; girl dancing
80 = 00 40 = FF L0 = 8x8 L1 = 8x8 ; soft dsw screen
xplan:
80 = 00 40 = FD L0 = - L1 = 8x8 ; ram test (disable = 01 -> L0 disabled)
80 = 40 40 = BF L0 = 8x32 L1 = 8x8 ; title screen [L0 line scroll every 32, L1 line scroll disabled?] / 3 planes with scrolling clouds (before title screen)
80 = 00 40 = EF L0 = 8x8 L1 = 8x8 ; parachutist and cars demo [L1 line scroll every 8]
80 = 70 40 = FF L0 = 64x32 L1 = 8x8 ; shoot'em up demo / gambling demo
80 = 00 40 = FF L0 = 8x8 L1 = 8x8 ; test mode and stat screens
bishjan:
80 = 00 40 = FD L0 = - L1 = 8x8 ; ram test (disable = 01 -> L0 disabled)
80 = 00 40 = 0F L0 = 8x8 L1 = 8x8 ; soft dsw screen
80 = 00 40 = 0x L0 = 8x8 L1 = 8x8 ; stat screens and gameplay (40 = 07/0d, seems a don't care)
saklove:
80 = 00 40 = 0D L0 = - L1 = 8x8 ; ram test (disable = 01 -> L0 disabled)
80 = 00 40 = 0D L0 = 8x8 L1 = 8x8 ; gameplay / square of tiles screen
80 = 00 40 = 0F L0 = 8x8 L1 = 8x8 ; title screen / instructions / double up screen
80 = 00 40 = 07 L0 = 8x8 L1 = 8x8 ; pool [L0 line scroll]
-----
More registers, at boot (never changed AFAICT):
mtrain, saklove xtrain, expcard
wtrnymph xplan
C0 = 0A C0 = 0A
E0 = 18 E0 = 18
9100 = 13 200 = 13 200 = 13 200 = 13
9101 = 20 201 = 20 201 = 20 201 = 20
9102 = 20 202 = 20 202 = 20 202 = 20
9103 = 33 203 = 33 203 = 33 203 = 33
9104 = DC 204 = DC 204 = DC 204 = DC
9105 = A0 205 = A0 205 = A0 205 = A0
9106 = FA 206 = FA 206 = FA 206 = FA
9107 = 00 207 = 00 207 = 00 207 = 00
9108 = 33 208 = 33 208 = 33 208 = 33
9109 = 16 209 = 0E 209 = 0E 209 = 0E
910A = F6 20A = FD 20A = FD 20A = FD *F5 in wtrnymph
910B = 22 20B = 22 20B = 22 20B = 22
910C = FE 20C = FE 20C = FE 20C = FE
910D = FB 20D = FB 20D = FB 20D = FB
910E = F8 20E = F8 20E = F8 20E = F8
910F = 02 20F = 02 20F = 02 20F = 02
9110 = 13 210 = 13 210 = 13 210 = 13
9111 = 10 211 = 00 211 = 00 211 = 00
9112 = 62 212 = 82 212 = 82 212 = 82
9113 = 13 213 = 33 213 = 33 213 = 33
9114 = 80 214 = 0E 214 = 0E 214 = 0E
9115 = 80 215 = FD 215 = FD 215 = FD
9116 = 13 216 = 13 216 = 13 216 = 13
9117 = 42 217 = 42 217 = 42 217 = 42
9118 = 42 218 = 42 218 = 42 218 = 42
9119 = 13 219 = 13 219 = 13 219 = 13
911A = 20 21A = 20 21A = 20 21A = 20
911B = 42 21B = 62 21B = 62 21B = 62
9126 = 0C 226 = 08 226 = 08 226 = 08
9127 = 0C 227 = 0C 227 = 0C 227 = 0C
9130 = 00 230 = 00 230 = 00 230 = 00
9131 = 00 231 = 00 231 = 00 231 = 00
9132 = 00 232 = FB 232 = FB 232 = FB
9133 = 00 233 = FF 233 = FF 233 = FF
9134 = 00 234 = 22 234 = 20 234 = 20
9135 = 00 235 = 02
9136 = 00
9137 = 00 237 = 00 237 = 00 237 = 00
9149 = FF 312 = FF 309 = FF 312 = FF
914A = FF 311 = FF 30A = FF 311 = FF
914B = FF 310 = FF 30B = FF 310 = FF
914C = 47 30F = 47 30C = 47 30F = 47
914D = 00 30E = 00 30D = 00 30E = 00
914E = 00 30D = 00 30E = 00 30D = 00
914F = 00 30C = 00 30F = 00 30C = 00
9150 = C0 30B = C0 310 = C0 30B = C0
9151 = FF 30A = FF 311 = FF 30A = FF
9153 = 00 313 = 00
***************************************************************************/
// These are written in sequence
void subsino2_state::ss9601_scrollctrl_w(uint8_t data)
{
m_ss9601_scrollctrl = data;
}
void subsino2_state::ss9601_tilesize_w(uint8_t data)
{
m_ss9601_tilesize = data;
tilesize_t sizes[2];
switch ((data&0xf0)>>4)
{
case 0x0:
sizes[0] = TILE_8x8;
break;
case 0x4:
sizes[0] = TILE_8x32;
break;
case 0x7:
sizes[0] = TILE_64x32;
break;
default:
sizes[0] = TILE_8x8;
logerror("%s: warning, layer 0 unknown tilesize = %02x\n", machine().describe_context(), data);
popmessage("layer 0 UNKNOWN TILESIZE %02X", data);
break;
}
switch (data&0x0f)
{
case 0x0:
sizes[1] = TILE_8x8;
break;
case 0x4:
sizes[1] = TILE_8x32;
break;
case 0x7:
sizes[1] = TILE_64x32;
break;
default:
sizes[1] = TILE_8x8;
logerror("%s: warning, layer 1 unknown tilesize = %02x\n", machine().describe_context(), data);
popmessage("layer 1 UNKNOWN TILESIZE %02X", data);
break;
}
for (int i = 0; i < 2; i++)
{
layer_t *l = &m_layers[i];
if (l->tilesize != sizes[i])
{
l->tilesize = sizes[i];
l->tmap->mark_all_dirty();
}
}
}
/***************************************************************************
Tilemaps Scroll
***************************************************************************/
void subsino2_state::ss9601_scroll_w(offs_t offset, uint8_t data)
{
layer_t *layers = m_layers;
switch ( offset )
{
// Layer 0
case 0: layers[0].scroll_x = (layers[0].scroll_x & 0xf00) | data; break; // x low
case 1: layers[0].scroll_y = (layers[0].scroll_y & 0xf00) | data; break; // y low
case 2: layers[0].scroll_x = (layers[0].scroll_x & 0x0ff) | ((data & 0x0f) << 8); // y|x high bits
layers[0].scroll_y = (layers[0].scroll_y & 0x0ff) | ((data & 0xf0) << 4); break;
// Layer 1
case 3: layers[1].scroll_x = (layers[1].scroll_x & 0xf00) | data; break; // x low
case 4: layers[1].scroll_y = (layers[1].scroll_y & 0xf00) | data; break; // y low
case 5: layers[1].scroll_x = (layers[1].scroll_x & 0x0ff) | ((data & 0x0f) << 8); // y|x high bits
layers[1].scroll_y = (layers[1].scroll_y & 0x0ff) | ((data & 0xf0) << 4); break;
}
}
// Layer 0
void subsino2_state::ss9601_scrollram_0_hi_w(offs_t offset, uint8_t data)
{
m_layers[0].scrollram[offset] = uint16_t(data) << 8 | (m_layers[0].scrollram[offset] & 0xff);
}
void subsino2_state::ss9601_scrollram_0_lo_w(offs_t offset, uint8_t data)
{
m_layers[0].scrollram[offset] = data | (m_layers[0].scrollram[offset] & 0xff00);
}
void subsino2_state::ss9601_scrollram_0_hi_lo_w(offs_t offset, uint8_t data)
{
m_layers[0].scrollram[offset] = uint16_t(data) << 8 | m_ss9601_byte_lo;
}
uint8_t subsino2_state::ss9601_scrollram_0_hi_r(offs_t offset)
{
return m_layers[0].scrollram[offset] >> 8;
}
uint8_t subsino2_state::ss9601_scrollram_0_lo_r(offs_t offset)
{
return m_layers[0].scrollram[offset] & 0xff;
}
// Layer 1
void subsino2_state::ss9601_scrollram_1_hi_w(offs_t offset, uint8_t data)
{
m_layers[1].scrollram[offset] = uint16_t(data) << 8 | (m_layers[1].scrollram[offset] & 0xff);
}
void subsino2_state::ss9601_scrollram_1_lo_w(offs_t offset, uint8_t data)
{
m_layers[1].scrollram[offset] = data | (m_layers[1].scrollram[offset] & 0xff00);
}
void subsino2_state::ss9601_scrollram_1_hi_lo_w(offs_t offset, uint8_t data)
{
m_layers[1].scrollram[offset] = uint16_t(data) << 8 | m_ss9601_byte_lo;
}
uint8_t subsino2_state::ss9601_scrollram_1_hi_r(offs_t offset)
{
return m_layers[1].scrollram[offset] >> 8;
}
uint8_t subsino2_state::ss9601_scrollram_1_lo_r(offs_t offset)
{
return m_layers[1].scrollram[offset] & 0xff;
}
/***************************************************************************
Tilemaps Disable
***************************************************************************/
void subsino2_state::ss9601_disable_w(uint8_t data)
{
m_ss9601_disable = data;
}
/***************************************************************************
Video Update
***************************************************************************/
void subsino2_state::video_start()
{
// SS9601 Regs:
m_ss9601_tilesize = TILE_8x8;
m_ss9601_scrollctrl = 0xfd; // not written by mtrain, default to reels on
m_ss9601_disable = 0x00;
save_item(NAME(m_ss9601_byte_lo));
save_item(NAME(m_ss9601_byte_lo2));
save_item(NAME(m_ss9601_tilesize));
save_item(NAME(m_ss9601_scrollctrl));
save_item(NAME(m_ss9601_disable));
// SS9601 Layers:
for (int i = 0; i < 2; i++)
{
layer_t *l = &m_layers[i];
l->tmap = &machine().tilemap().create(*m_gfxdecode, i ?
tilemap_get_info_delegate(*this, FUNC(subsino2_state::ss9601_get_tile_info_1)) :
tilemap_get_info_delegate(*this, FUNC(subsino2_state::ss9601_get_tile_info_0)),
TILEMAP_SCAN_ROWS, 8,8, 0x80,0x40);
l->tmap->set_transparent_pen(0);
// line scroll
l->tmap->set_scroll_rows(0x200);
l->videoram = std::make_unique<uint16_t[]>(0x80 * 0x40);
l->scrollram = make_unique_clear<uint16_t[]>(0x200);
save_pointer(NAME(l->videoram), 0x80 * 0x40, i);
save_pointer(NAME(l->scrollram), 0x200, i);
save_item(NAME(l->scroll_x), i);
save_item(NAME(l->scroll_y), i);
save_item(NAME(l->tilesize), i);
}
// SS9601 Reels:
m_ss9601_reelram = make_unique_clear<uint16_t[]>(0x2000);
m_reelbitmap.allocate(0x80*8, 0x40*8);
save_pointer(NAME(m_ss9601_reelram), 0x2000);
save_item(NAME(m_dsw_mask));
save_item(NAME(m_bishjan_sound));
save_item(NAME(m_bishjan_input));
}
uint32_t subsino2_state::screen_update_subsino2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
int layers_ctrl = ~m_ss9601_disable;
int y;
#ifdef MAME_DEBUG
if (machine().input().code_pressed(KEYCODE_Z))
{
int msk = 0;
if (machine().input().code_pressed(KEYCODE_Q)) msk |= 1;
if (machine().input().code_pressed(KEYCODE_W)) msk |= 2;
if (msk != 0) layers_ctrl &= msk;
}
#endif
// Line Scroll / Reel Control
int mask_y[2] = {0, 0};
bool l0_reel = false;
switch ( m_ss9601_scrollctrl )
{
case 0xbf:
mask_y[0] = ~(32-1);
break;
case 0xef:
mask_y[1] = ~(8-1);
break;
case 0x07:
mask_y[0] = ~(8-1);
break;
// case 0x7f: // ptrain
// break;
case 0xfd:
l0_reel = true;
break;
}
// Scroll
for (int i = 0; i < 2; i++)
{
layer_t *l = &m_layers[i];
l->tmap->set_scroll_cols(1);
l->tmap->set_scroll_rows(0x200);
l->tmap->set_scrolly(0, l->scroll_y + 1);
// line scroll
uint16_t scroll_dx = 0;
for (y = 0; y < 0x200; y++)
{
if (mask_y[i])
scroll_dx = l->scrollram[y & mask_y[i]];
l->tmap->set_scrollx(y, l->scroll_x + scroll_dx);
}
}
bitmap.fill(m_palette->black_pen(), cliprect);
if (layers_ctrl & 1)
{
layer_t *l = &m_layers[0];
if (l0_reel)
{
l->tmap->set_scroll_rows(1);
l->tmap->set_scroll_cols(1);
for (int y = 0; y < 0x20/4; y++)
{
for (int x = 0; x < 0x80; x++)
{
rectangle visible;
visible.min_x = 8 * x;
visible.max_x = 8 * (x+1) - 1;
visible.min_y = 4 * 0x10 * y;
visible.max_y = 4 * 0x10 * (y+1) - 1;
int reeladdr = y * 0x80 * 4 + x;
uint16_t reelscroll = m_ss9601_reelram[reeladdr];
l->tmap->set_scrollx(0, (reelscroll >> 9) * 8 - visible.min_x);
// wrap around at half tilemap (0x100)
int reelscroll_y = (reelscroll & 0x100) + ((reelscroll - visible.min_y) & 0xff);
int reelwrap_y = 0x100 - (reelscroll_y & 0xff);
//visible &= cliprect;
rectangle tmp = visible;
// draw above the wrap around y
if ( reelwrap_y-1 >= visible.min_y )
{
if ( reelwrap_y-1 <= visible.max_y )
tmp.max_y = reelwrap_y-1;
l->tmap->set_scrolly(0, reelscroll_y);
l->tmap->draw(screen, m_reelbitmap, tmp, TILEMAP_DRAW_OPAQUE);
tmp.max_y = visible.max_y;
}
// draw below the wrap around y
if ( reelwrap_y <= visible.max_y )
{
if ( reelwrap_y >= visible.min_y )
tmp.min_y = reelwrap_y;
l->tmap->set_scrolly(0, -((reelwrap_y &0xff) | (reelscroll_y & 0x100)));
l->tmap->draw(screen, m_reelbitmap, tmp, TILEMAP_DRAW_OPAQUE);
tmp.min_y = visible.min_y;
}
}
}
int32_t sx = -l->scroll_x;
int32_t sy = -(l->scroll_y + 1);
copyscrollbitmap(bitmap, m_reelbitmap, 1, &sx, 1, &sy, cliprect);
}
else
{
l->tmap->draw(screen, bitmap, cliprect, 0, 0);
}
}
if (layers_ctrl & 2) m_layers[1].tmap->draw(screen, bitmap, cliprect, 0, 0);
// popmessage("scrl: %03x,%03x - %03x,%03x dis: %02x siz: %02x ctrl: %02x", m_layers[0].scroll_x,m_layers[0].scroll_y, m_layers[1].scroll_x,m_layers[1].scroll_y, m_ss9601_disable, m_ss9601_tilesize, m_ss9601_scrollctrl);
return 0;
}
/***************************************************************************
Input / Output
***************************************************************************/
void subsino2_state::dsw_mask_w(uint8_t data)
{
m_dsw_mask = data;
}
uint8_t subsino2_state::dsw_r()
{
return ( (m_dsw[0]->read() & m_dsw_mask) ? 0x01 : 0 ) |
( (m_dsw[1]->read() & m_dsw_mask) ? 0x02 : 0 ) |
( (m_dsw[2]->read() & m_dsw_mask) ? 0x04 : 0 ) |
( (m_dsw[3]->read() & m_dsw_mask) ? 0x08 : 0 ) ;
}
uint8_t subsino2_state::vblank_bit2_r()
{
return m_screen->vblank() ? 0x04 : 0x00;
}
uint8_t subsino2_state::vblank_bit6_r()
{
return m_screen->vblank() ? 0x40 : 0x00;
}
void subsino2_state::oki_bank_bit0_w(uint8_t data)
{
// it writes 0x32 or 0x33
m_oki->set_rom_bank(data & 1);
}
void subsino2_state::oki_bank_bit4_w(uint8_t data)
{
// it writes 0x23 or 0x33
m_oki->set_rom_bank((data >> 4) & 1);
}
/***************************************************************************
Memory Maps
***************************************************************************/
/***************************************************************************
Bishou Jan
***************************************************************************/
uint8_t subsino2_state::bishjan_sound_r()
{
return 0;
}
void subsino2_state::bishjan_sound_w(uint8_t data)
{
/*
sound writes in service mode:
01 88 04 00 (coin in)
02 89 04 0v (v = voice = 0..3)
*/
switch (data)
{
case 0x10:
m_eeprom->data_w(1);
break;
case 0x13:
m_eeprom->data_w(0);
break;
}
m_bishjan_sound = data;
}
uint8_t subsino2_state::bishjan_serial_r()
{
return
(m_eeprom->data_r() ? 0x80 : 0) | // bit 7 - serial communication
(machine().rand() & 0x18) |
((m_bishjan_sound == 0x12) ? 0x40:0x00); // bit 6 - sound communication
}
uint8_t subsino2_state::xiaoao_serial_r()
{
return
(m_eeprom->data_r() ? 0x80 : 0) | // bit 7 - serial communication
(machine().rand() & 0x18) |
((m_bishjan_sound == 0x11) ? 0x40:0x00); // bit 6 - sound communication
}
uint8_t subsino2_state::bishjan_unknown_r()
{
return
// (machine().rand() & 0xff);
// (((m_screen->frame_number()%60)==0)?0x18:0x00);
0x18;
}
void subsino2_state::bishjan_input_w(uint8_t data)
{
m_bishjan_input = data;
}
uint8_t subsino2_state::bishjan_input_r()
{
uint8_t res = 0xff;
for (int i = 0; i < 5; i++)
if (m_bishjan_input & (1 << i))
res = m_keyb[i]->read();
return res;
}
void subsino2_state::bishjan_outputs_w(uint8_t data)
{
// coin out BIT(data, 0)
m_hopper->motor_w(BIT(data, 1)); // hopper
machine().bookkeeping().coin_counter_w(0, BIT(data, 4));
}
void subsino2_state::bishjan_map(address_map &map)