/
terracre.cpp
1378 lines (1147 loc) · 70.4 KB
/
terracre.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: Carlos A. Lozano
/******************************************************************
Terra Cresta (preliminary)
Nichibutsu 1985
68000 + Z80
driver by Carlos A. Lozano (calb@gsyc.inf.uc3m.es)
TODO:
- I'm playing samples with a DAC, but they could be ADPCM
- find correct high-scores table for 'amazon' (update: uses same protection data as amatelas hence same data)
Stephh's notes (based on the games M68000 code and some tests) :
1) 'terracr*'
- Each high-score name is made up of 10 chars.
2) 'amazon'
- Each high-score name is made up of 3 chars followed by 7 0x00.
3) 'amatelas'
- Each high-score name is made up of 10 chars.
4) 'horekid*'
- Each high-score name is made up of 3 chars.
- There is a "debug mode" !
Set "Debug Mode" Dip Switch to ON and be sure that "Cabinet" Dip Switch
is set to "Upright". Its features (see below) only affect player 1 !
Features :
* invulnerability and infinite time :
. insert a coin
. press player 2 button 1 and 2 and START1 (player 1 buttons 1 and 2 must NOT be pressed !)
* level select (there are 32 levels) :
. insert a coin
. press player 2 button 1 and 2 ("00" will be displayed - this is an hex. display)
. press player 2 button 1 and 2 and player 1 button 1 to increase level
. press player 2 button 1 and 2 and player 1 button 2 to decrease level
. press START1 to start a game with the selected level
Amazon
(c)1986 Nichibutsu
AT-1
16MHz
6116 - - 10 9
6116 - - 12 11 68000-8
6116
6116
SW
15 14 13 clr.12f clr.11f clr.10f SW
16 1412M2 XBA
AT-2
2G 6 7 8
4E 4 5 6116
Z80A YM3526
2148 2148
2148 2148 2148 2148
1 2 3 6116
22MHz
*/
#include "emu.h"
#include "nb1412m2.h"
#include "cpu/m68000/m68000.h"
#include "cpu/z80/z80.h"
#include "machine/gen_latch.h"
#include "machine/rescap.h"
#include "sound/dac.h"
#include "sound/flt_biquad.h"
#include "sound/mixer.h"
#include "sound/ymopn.h"
#include "sound/ymopl.h"
#include "video/bufsprite.h"
#include "emupal.h"
#include "screen.h"
#include "speaker.h"
#include "tilemap.h"
namespace {
class terracre_state : public driver_device
{
public:
terracre_state(const machine_config &mconfig, device_type type, const char *tag)
: driver_device(mconfig, type, tag)
, m_maincpu(*this, "maincpu")
, m_audiocpu(*this, "audiocpu")
, m_gfxdecode(*this, "gfxdecode")
, m_palette(*this, "palette")
, m_spriteram(*this, "spriteram")
, m_soundlatch(*this, "soundlatch")
, m_dacfilter1(*this, "dacfilter1")
, m_dacfilter2(*this, "dacfilter2")
, m_ymfilter(*this, "ymfilter")
, m_ssgmixer(*this, "ssgmixer")
, m_ssgfilter_abfilt(*this, "ssg_abfilt")
, m_ssgfilter_abgain(*this, "ssg_abgain")
, m_ssgfilter_cgain(*this, "ssg_cgain")
, m_bg_videoram(*this, "bg_videoram")
, m_fg_videoram(*this, "fg_videoram")
, m_coltable(*this, "palbank_prom")
{ }
void amazon_base(machine_config &config);
void horekidb2(machine_config &config);
void tc_base(machine_config &config);
void ym2203(machine_config &config);
void ym3526(machine_config &config);
protected:
virtual void video_start() override;
required_device<cpu_device> m_maincpu;
required_device<cpu_device> m_audiocpu;
void amazon_base_map(address_map &map);
private:
required_device<gfxdecode_device> m_gfxdecode;
required_device<palette_device> m_palette;
required_device<buffered_spriteram16_device> m_spriteram;
required_device<generic_latch_8_device> m_soundlatch;
required_device<filter_biquad_device> m_dacfilter1;
required_device<filter_biquad_device> m_dacfilter2;
required_device<filter_biquad_device> m_ymfilter;
optional_device<mixer_device> m_ssgmixer;
optional_device<filter_biquad_device> m_ssgfilter_abfilt;
optional_device<filter_biquad_device> m_ssgfilter_abgain;
optional_device<filter_biquad_device> m_ssgfilter_cgain;
required_shared_ptr<uint16_t> m_bg_videoram;
required_shared_ptr<uint16_t> m_fg_videoram;
required_region_ptr<uint8_t> m_coltable;
uint16_t m_xscroll = 0;
uint16_t m_yscroll = 0;
tilemap_t *m_background = nullptr;
tilemap_t *m_foreground = nullptr;
void sound_w(uint16_t data);
uint8_t soundlatch_clear_r();
void background_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
void foreground_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
void flipscreen_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
void scrolly_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
void scrollx_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
TILE_GET_INFO_MEMBER(get_bg_tile_info);
TILE_GET_INFO_MEMBER(get_fg_tile_info);
void palette(palette_device &palette) const;
uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect);
void horekidb2_map(address_map &map);
void sound_2203_io_map(address_map &map);
void sound_3526_io_map(address_map &map);
void sound_map(address_map &map);
void terracre_map(address_map &map);
};
class amazon_state : public terracre_state
{
public:
amazon_state(const machine_config &mconfig, device_type type, const char *tag) :
terracre_state(mconfig, type, tag),
m_prot(*this, "prot_chip")
{ }
void amazon_1412m2(machine_config &config);
private:
required_device<nb1412m2_device> m_prot;
void amazon_1412m2_map(address_map &map);
};
TILE_GET_INFO_MEMBER(terracre_state::get_bg_tile_info)
{
/* xxxx.----.----.----
* ----.xx--.----.----
* ----.--xx.xxxx.xxxx */
const unsigned data = m_bg_videoram[tile_index];
const unsigned color = data >> 11;
tileinfo.set(1, data & 0x3ff, color, 0);
}
TILE_GET_INFO_MEMBER(terracre_state::get_fg_tile_info)
{
const unsigned data = m_fg_videoram[tile_index];
tileinfo.set(0, data & 0xff, 0, 0);
}
void terracre_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
{
gfx_element *pGfx = m_gfxdecode->gfx(2);
const uint16_t *pSource = m_spriteram->buffer();
const int flip = flip_screen();
int transparent_pen;
if (pGfx->elements() > 0x200)
transparent_pen = 0xf; // HORE HORE Kid
else
transparent_pen = 0x0;
for (int i = 0; i < 0x200; i += 8)
{
int tile = pSource[1] & 0xff;
const int attrs = pSource[2];
int flipx = attrs & 0x04;
int flipy = attrs & 0x08;
int color = (attrs & 0xf0) >> 4;
int sx = (pSource[3] & 0xff) - 0x80 + 256 * (attrs & 1);
int sy = 240 - (pSource[0] & 0xff);
if (transparent_pen)
{
if (attrs & 0x02) tile |= 0x200;
if (attrs & 0x10) tile |= 0x100;
int bank = (tile & 0xfc) >> 1;
if (tile & 0x200) bank |= 0x80;
if (tile & 0x100) bank |= 0x01;
color &= 0xe;
color += 16 * (m_coltable[bank] & 0xf);
}
else
{
if (attrs & 0x02) tile|= 0x100;
color += 16 * (m_coltable[(tile >> 1) & 0xff] & 0x0f);
}
if (flip)
{
sx = 240 - sx;
sy = 240 - sy;
flipx = !flipx;
flipy = !flipy;
}
pGfx->transpen(bitmap, cliprect, tile, color, flipx, flipy, sx, sy, transparent_pen);
pSource += 4;
}
}
void terracre_state::palette(palette_device &palette) const
{
const uint8_t *color_prom = memregion("proms")->base();
// create a lookup table for the palette
for (int i = 0; i < 0x100; i++)
{
int const r = pal4bit(color_prom[i + 0x000]);
int const g = pal4bit(color_prom[i + 0x100]);
int const b = pal4bit(color_prom[i + 0x200]);
palette.set_indirect_color(i, rgb_t(r, g, b));
}
// color_prom now points to the beginning of the lookup table
color_prom += 0x300;
// characters use colors 0-0x0f
for (int i = 0; i < 0x10; i++)
palette.set_pen_indirect(i, i);
// background tiles use colors 0xc0-0xff in four banks
// the bottom two bits of the color code select the palette bank for pens 0-7;
// the top two bits for pens 8-0x0f.
for (int i = 0; i < 0x100; i++)
{
uint8_t const ctabentry = 0xc0 | (i & 0x0f) | ((i >> ((i & 0x08) ? 2 : 0)) & 0x30);
palette.set_pen_indirect(0x10 + i, ctabentry);
}
// sprites use colors 128-191 in four banks
// The lookup table tells which colors to pick from the selected bank
// the bank is selected by another PROM and depends on the top 8 bits of the sprite code.
// The PROM selects the bank *separately* for pens 0-7 and 8-15 (like for tiles).
for (int i = 0; i < 0x1000; i++)
{
uint8_t const ctabentry = 0x80 | ((i << ((i & 0x80) ? 2 : 4)) & 0x30) | (color_prom[i >> 4] & 0x0f);
int i_swapped = ((i & 0x0f) << 8) | ((i & 0xff0) >> 4);
palette.set_pen_indirect(0x110 + i_swapped, ctabentry);
}
}
void terracre_state::background_w(offs_t offset, uint16_t data, uint16_t mem_mask)
{
COMBINE_DATA(&m_bg_videoram[offset]);
m_background->mark_tile_dirty(offset);
}
void terracre_state::foreground_w(offs_t offset, uint16_t data, uint16_t mem_mask)
{
COMBINE_DATA(&m_fg_videoram[offset]);
m_foreground->mark_tile_dirty(offset);
}
void terracre_state::flipscreen_w(offs_t offset, uint16_t data, uint16_t mem_mask)
{
if (ACCESSING_BITS_0_7)
{
machine().bookkeeping().coin_counter_w(0, data & 0x01);
machine().bookkeeping().coin_counter_w(1, (data & 0x02) >> 1);
flip_screen_set(data & 0x04);
}
}
void terracre_state::scrolly_w(offs_t offset, uint16_t data, uint16_t mem_mask)
{
COMBINE_DATA(&m_yscroll);
m_background->set_scrolly(0, m_yscroll);
}
void terracre_state::scrollx_w(offs_t offset, uint16_t data, uint16_t mem_mask)
{
COMBINE_DATA(&m_xscroll);
m_background->set_scrollx(0, m_xscroll);
}
void terracre_state::video_start()
{
m_background = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(terracre_state::get_bg_tile_info)), TILEMAP_SCAN_COLS, 16,16, 64,32);
m_foreground = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(terracre_state::get_fg_tile_info)), TILEMAP_SCAN_COLS, 8, 8, 64,32);
m_foreground->set_transparent_pen(0xf);
// register for saving
save_item(NAME(m_xscroll));
save_item(NAME(m_yscroll));
}
uint32_t terracre_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
if (m_xscroll & 0x2000)
bitmap.fill(m_palette->black_pen(), cliprect);
else
m_background->draw(screen, bitmap, cliprect, 0, 0);
draw_sprites(bitmap, cliprect);
if ((m_xscroll & 0x1000) == 0)
m_foreground->draw(screen, bitmap, cliprect, 0, 0);
return 0;
}
void terracre_state::sound_w(uint16_t data)
{
m_soundlatch->write(((data & 0x7f) << 1) | 1);
}
uint8_t terracre_state::soundlatch_clear_r()
{
m_soundlatch->clear_w();
return 0;
}
void terracre_state::terracre_map(address_map &map)
{
map(0x000000, 0x01ffff).rom();
map(0x020000, 0x0201ff).ram().share("spriteram");
map(0x020200, 0x021fff).ram();
map(0x022000, 0x022fff).w(FUNC(terracre_state::background_w)).share(m_bg_videoram);
map(0x023000, 0x023fff).ram();
map(0x024000, 0x024001).portr("P1");
map(0x024002, 0x024003).portr("P2");
map(0x024004, 0x024005).portr("SYSTEM");
map(0x024006, 0x024007).portr("DSW");
map(0x026000, 0x026001).w(FUNC(terracre_state::flipscreen_w)); // flip screen & coin counters
map(0x026002, 0x026003).w(FUNC(terracre_state::scrollx_w));
map(0x026004, 0x026005).nopr().w(FUNC(terracre_state::scrolly_w));
map(0x02600a, 0x02600b).noprw(); // video related
map(0x02600c, 0x02600d).w(FUNC(terracre_state::sound_w));
map(0x02600e, 0x02600f).noprw(); // video related
map(0x028000, 0x0287ff).ram().w(FUNC(terracre_state::foreground_w)).share(m_fg_videoram);
}
void terracre_state::amazon_base_map(address_map &map)
{
map(0x000000, 0x01ffff).rom();
map(0x040000, 0x0401ff).ram().share("spriteram");
map(0x040200, 0x040fff).ram();
map(0x042000, 0x042fff).w(FUNC(terracre_state::background_w)).share(m_bg_videoram);
map(0x044000, 0x044001).portr("IN0");
map(0x044002, 0x044003).portr("IN1");
map(0x044004, 0x044005).portr("IN2");
map(0x044006, 0x044007).portr("IN3");
map(0x046000, 0x046001).w(FUNC(terracre_state::flipscreen_w)); // flip screen & coin counters
map(0x046002, 0x046003).w(FUNC(terracre_state::scrollx_w));
map(0x046004, 0x046005).nopr().w(FUNC(terracre_state::scrolly_w));
map(0x04600a, 0x04600b).noprw(); // video related
map(0x04600c, 0x04600d).w(FUNC(terracre_state::sound_w));
map(0x04600e, 0x04600f).noprw(); // video related
map(0x050000, 0x050fff).ram().w(FUNC(terracre_state::foreground_w)).share(m_fg_videoram);
map(0x070000, 0x070003).noprw(); // protection (nop for bootlegs)
}
void terracre_state::horekidb2_map(address_map &map) // weirdly, this bootleg inverts the order of the inputs
{
amazon_base_map(map);
map(0x044000, 0x044001).portr("IN3");
map(0x044002, 0x044003).portr("IN2");
map(0x044004, 0x044005).portr("IN1");
map(0x044006, 0x044007).portr("IN0");
}
void amazon_state::amazon_1412m2_map(address_map &map)
{
amazon_base_map(map);
map(0x070000, 0x070001).rw("prot_chip", FUNC(nb1412m2_device::data_r), FUNC(nb1412m2_device::data_w)).umask16(0x00ff);
map(0x070002, 0x070003).w("prot_chip", FUNC(nb1412m2_device::command_w)).umask16(0x00ff);
}
void terracre_state::sound_map(address_map &map)
{
map(0x0000, 0xbfff).rom();
map(0xc000, 0xcfff).ram();
}
void terracre_state::sound_3526_io_map(address_map &map)
{
map.global_mask(0xff);
map(0x00, 0x01).w("ymsnd", FUNC(ym3526_device::write));
map(0x02, 0x02).w("dac1", FUNC(dac_byte_interface::data_w));
map(0x03, 0x03).w("dac2", FUNC(dac_byte_interface::data_w));
map(0x04, 0x04).r(FUNC(terracre_state::soundlatch_clear_r));
map(0x06, 0x06).r(m_soundlatch, FUNC(generic_latch_8_device::read));
}
void terracre_state::sound_2203_io_map(address_map &map)
{
map.global_mask(0xff);
map(0x00, 0x01).w("ym1", FUNC(ym2203_device::write));
map(0x02, 0x02).w("dac1", FUNC(dac_byte_interface::data_w));
map(0x03, 0x03).w("dac2", FUNC(dac_byte_interface::data_w));
map(0x04, 0x04).r(FUNC(terracre_state::soundlatch_clear_r));
map(0x06, 0x06).r(m_soundlatch, FUNC(generic_latch_8_device::read));
}
static INPUT_PORTS_START( terracre )
PORT_START("P1")
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 )
PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_START("P2")
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_COCKTAIL
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_COCKTAIL
PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_COCKTAIL
PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_COCKTAIL
PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL
PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_START("SYSTEM")
PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_START1 )
PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_START2 )
PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_COIN1 )
PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_COIN2 )
PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_SERVICE1 )
PORT_SERVICE( 0x2000, IP_ACTIVE_LOW )
PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_START("DSW")
PORT_DIPNAME( 0x0003, 0x0003, DEF_STR( Lives ) ) PORT_DIPLOCATION("DSW1:1,2")
PORT_DIPSETTING( 0x0003, "3" )
PORT_DIPSETTING( 0x0002, "4" )
PORT_DIPSETTING( 0x0001, "5" )
PORT_DIPSETTING( 0x0000, "6" )
PORT_DIPNAME( 0x000c, 0x000c, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("DSW1:3,4")
PORT_DIPSETTING( 0x000c, "20k then every 60k" ) // "20000 60000" in the "test mode"
PORT_DIPSETTING( 0x0008, "30k then every 70k" ) // "30000 70000" in the "test mode"
PORT_DIPSETTING( 0x0004, "40k then every 80k" ) // "40000 80000" in the "test mode"
PORT_DIPSETTING( 0x0000, "50k then every 90k" ) // "50000 90000" in the "test mode"
PORT_DIPNAME( 0x0010, 0x0010, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("DSW1:5")
PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
PORT_DIPSETTING( 0x0010, DEF_STR( On ) )
PORT_DIPNAME( 0x0020, 0x0000, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("DSW1:6")
PORT_DIPSETTING( 0x0000, DEF_STR( Upright ) )
PORT_DIPSETTING( 0x0020, DEF_STR( Cocktail ) )
PORT_DIPUNUSED_DIPLOC( 0x0040, 0x0040, "DSW1:7" )
PORT_DIPUNUSED_DIPLOC( 0x0080, 0x0080, "DSW1:8" )
PORT_DIPNAME( 0x0300, 0x0300, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("DSW2:1,2")
PORT_DIPSETTING( 0x0100, DEF_STR( 2C_1C ) )
PORT_DIPSETTING( 0x0300, DEF_STR( 1C_1C ) )
PORT_DIPSETTING( 0x0200, DEF_STR( 1C_2C ) )
PORT_DIPSETTING( 0x0000, DEF_STR( Free_Play ) )
PORT_DIPNAME( 0x0c00, 0x0c00, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("DSW2:3,4")
PORT_DIPSETTING( 0x0000, DEF_STR( 3C_1C ) )
PORT_DIPSETTING( 0x0400, DEF_STR( 2C_3C ) )
PORT_DIPSETTING( 0x0c00, DEF_STR( 1C_3C ) )
PORT_DIPSETTING( 0x0800, DEF_STR( 1C_6C ) )
PORT_DIPNAME( 0x1000, 0x1000, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("DSW2:5")
PORT_DIPSETTING( 0x1000, DEF_STR( Easy ) )
PORT_DIPSETTING( 0x0000, DEF_STR( Hard ) )
PORT_DIPNAME( 0x2000, 0x2000, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("DSW2:6") // not in the "test mode"
PORT_DIPSETTING( 0x2000, DEF_STR( Off ) )
PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
PORT_DIPNAME( 0x4000, 0x4000, "Complete Invulnerability (Cheat)") PORT_DIPLOCATION("DSW2:7")
PORT_DIPSETTING( 0x4000, DEF_STR( Off ) )
PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
PORT_DIPNAME( 0x8000, 0x8000, "Base Ship Invulnerability (Cheat)") PORT_DIPLOCATION("DSW2:8")
PORT_DIPSETTING( 0x8000, DEF_STR( Off ) )
PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
INPUT_PORTS_END
static INPUT_PORTS_START( amazon )
PORT_START("IN0")
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_CONDITION("IN3", 0x80, EQUALS, 0x80)
PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("2 Players Start / Fast Forward") PORT_CONDITION("IN3", 0x80, EQUALS, 0x00)
PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_START("IN1")
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_COCKTAIL
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_COCKTAIL
PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_COCKTAIL
PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_COCKTAIL
PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL
PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_START("IN2")
PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_START2 )
PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_START1 )
PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_COIN1 )
PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_COIN2 )
PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_SERVICE1 )
PORT_SERVICE( 0x2000, IP_ACTIVE_LOW )
PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_START("IN3")
PORT_DIPNAME( 0x0003, 0x0003, DEF_STR( Lives ) ) PORT_DIPLOCATION("DSW1:1,2")
PORT_DIPSETTING( 0x0003, "3" )
PORT_DIPSETTING( 0x0002, "4" )
PORT_DIPSETTING( 0x0001, "5" )
PORT_DIPSETTING( 0x0000, "6" )
PORT_DIPNAME( 0x000c, 0x000c, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("DSW1:3,4")
PORT_DIPSETTING( 0x000c, "20k then every 40k" ) // "20000 40000" in the "test mode"
PORT_DIPSETTING( 0x0008, "50k then every 40k" ) // "50000 40000" in the "test mode"
PORT_DIPSETTING( 0x0004, "20k then every 70k" ) // "20000 70000" in the "test mode"
PORT_DIPSETTING( 0x0000, "50k then every 70k" ) // "50000 70000" in the "test mode"
PORT_DIPNAME( 0x0010, 0x0010, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("DSW1:5")
PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
PORT_DIPSETTING( 0x0010, DEF_STR( On ) )
PORT_DIPNAME( 0x0020, 0x0000, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("DSW1:6")
PORT_DIPSETTING( 0x0000, DEF_STR( Upright ) )
PORT_DIPSETTING( 0x0020, DEF_STR( Cocktail ) )
PORT_DIPUNUSED_DIPLOC( 0x0040, 0x0040, "DSW1:7" )
PORT_DIPNAME( 0x0080, 0x0080, "Debug Mode" ) PORT_DIPLOCATION("DSW1:8") // makes player invulnerable, and 2P start for fast forward
PORT_DIPSETTING( 0x0080, DEF_STR( Off ) )
PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
PORT_DIPNAME( 0x0300, 0x0300, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("DSW2:1,2")
PORT_DIPSETTING( 0x0100, DEF_STR( 2C_1C ) )
PORT_DIPSETTING( 0x0300, DEF_STR( 1C_1C ) )
PORT_DIPSETTING( 0x0200, DEF_STR( 1C_2C ) )
PORT_DIPSETTING( 0x0000, DEF_STR( Free_Play ) )
PORT_DIPNAME( 0x0c00, 0x0c00, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("DSW2:3,4")
PORT_DIPSETTING( 0x0000, DEF_STR( 3C_1C ) )
PORT_DIPSETTING( 0x0800, DEF_STR( 1C_1C ) )
PORT_DIPSETTING( 0x0400, DEF_STR( 2C_3C ) )
PORT_DIPSETTING( 0x0c00, DEF_STR( 1C_3C ) )
PORT_DIPNAME( 0x1000, 0x1000, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("DSW2:5")
PORT_DIPSETTING( 0x1000, DEF_STR( Easy ) )
PORT_DIPSETTING( 0x0000, DEF_STR( Hard ) )
PORT_DIPNAME( 0x2000, 0x2000, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("DSW2:6") // not in the "test mode"
PORT_DIPSETTING( 0x2000, DEF_STR( Off ) )
PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
PORT_DIPNAME( 0x4000, 0x4000, "Level" ) PORT_DIPLOCATION("DSW2:7")
PORT_DIPSETTING( 0x4000, DEF_STR( Low ) )
PORT_DIPSETTING( 0x0000, DEF_STR( High ) )
PORT_DIPNAME( 0x8000, 0x8000, "Sprite Test" ) PORT_DIPLOCATION("DSW2:8")
PORT_DIPSETTING( 0x8000, DEF_STR( Off ) )
PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
INPUT_PORTS_END
static INPUT_PORTS_START( horekid )
PORT_START("IN0")
PORT_DIPNAME( 0x0003, 0x0003, DEF_STR( Lives ) ) PORT_DIPLOCATION("DSW1:1,2")
PORT_DIPSETTING( 0x0003, "3" )
PORT_DIPSETTING( 0x0002, "4" )
PORT_DIPSETTING( 0x0001, "5" )
PORT_DIPSETTING( 0x0000, "6" )
PORT_DIPNAME( 0x000c, 0x000c, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("DSW1:3,4")
PORT_DIPSETTING( 0x000c, "20k then every 60k" ) // "20000 60000" in the "test mode"
PORT_DIPSETTING( 0x0008, "50k then every 60k" ) // "50000 60000" in the "test mode"
PORT_DIPSETTING( 0x0004, "20k then every 90k" ) // "20000 90000" in the "test mode"
PORT_DIPSETTING( 0x0000, "50k then every 90k" ) // "50000 90000" in the "test mode"
PORT_DIPNAME( 0x0010, 0x0000, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("DSW1:5")
PORT_DIPSETTING( 0x0010, DEF_STR( Off ) )
PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
PORT_DIPNAME( 0x0020, 0x0000, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("DSW1:6")
PORT_DIPSETTING( 0x0000, DEF_STR( Upright ) )
PORT_DIPSETTING( 0x0020, DEF_STR( Cocktail ) )
PORT_DIPNAME( 0x00c0, 0x00c0, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("DSW1:7,8")
PORT_DIPSETTING( 0x00c0, DEF_STR( Easy ) )
PORT_DIPSETTING( 0x0080, DEF_STR( Normal ) )
PORT_DIPSETTING( 0x0040, DEF_STR( Hard ) )
PORT_DIPSETTING( 0x0000, DEF_STR( Hardest ) )
PORT_DIPNAME( 0x0300, 0x0300, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("DSW2:1,2")
PORT_DIPSETTING( 0x0100, DEF_STR( 2C_1C ) )
PORT_DIPSETTING( 0x0300, DEF_STR( 1C_1C ) )
PORT_DIPSETTING( 0x0200, DEF_STR( 1C_2C ) )
PORT_DIPSETTING( 0x0000, DEF_STR( Free_Play ) )
PORT_DIPNAME( 0x0c00, 0x0c00, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("DSW2:3,4")
PORT_DIPSETTING( 0x0400, DEF_STR( 2C_1C ) )
PORT_DIPSETTING( 0x0c00, DEF_STR( 1C_1C ) )
PORT_DIPSETTING( 0x0000, DEF_STR( 2C_3C ) )
PORT_DIPSETTING( 0x0800, DEF_STR( 1C_2C ) )
PORT_DIPUNUSED_DIPLOC( 0x1000, IP_ACTIVE_LOW, "DSW2:5" )
PORT_DIPNAME( 0x2000, 0x2000, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("DSW2:6")
PORT_DIPSETTING( 0x2000, DEF_STR( Off ) )
PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
PORT_DIPNAME( 0xc000, 0xc000, "Debug Mode" ) PORT_DIPLOCATION("DSW2:7,8")
PORT_DIPSETTING( 0xc000, DEF_STR( Off ) )
PORT_DIPSETTING( 0x8000, DEF_STR( On ) ) // "Cabinet" Dip Switch must be set to "Upright" too !
PORT_DIPSETTING( 0x4000, DEF_STR( Off ) ) // duplicated setting
PORT_DIPSETTING( 0x0000, DEF_STR( Off ) ) // duplicated setting
PORT_START("IN1")
PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_START1 )
PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_START2 )
PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_COIN1 )
PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_COIN2 )
PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_SERVICE1 )
PORT_SERVICE_NO_TOGGLE( 0x2000, IP_ACTIVE_LOW)
PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_START("IN2")
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_4WAY PORT_PLAYER(2)
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY PORT_PLAYER(2)
PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY PORT_PLAYER(2)
PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY PORT_PLAYER(2)
PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_START("IN3")
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_4WAY PORT_PLAYER(1)
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY PORT_PLAYER(1)
PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY PORT_PLAYER(1)
PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY PORT_PLAYER(1)
PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
INPUT_PORTS_END
static INPUT_PORTS_START( horekidb2 )
PORT_INCLUDE(horekid)
PORT_MODIFY("IN1")
PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_START2 )
PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_START1 )
INPUT_PORTS_END
static const gfx_layout sprite_layout =
{
16,16,
RGN_FRAC(1,2),
4,
{ 0, 1, 2, 3 },
{
4, 0, RGN_FRAC(1,2)+4, RGN_FRAC(1,2)+0,
12, 8, RGN_FRAC(1,2)+12, RGN_FRAC(1,2)+8,
20, 16, RGN_FRAC(1,2)+20, RGN_FRAC(1,2)+16,
28, 24, RGN_FRAC(1,2)+28, RGN_FRAC(1,2)+24
},
{
0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32,
8*32, 9*32, 10*32, 11*32, 12*32, 13*32, 14*32, 15*32
},
32*16
};
static GFXDECODE_START( gfx_terracre )
GFXDECODE_ENTRY( "fgtiles", 0, gfx_8x8x4_packed_lsb, 0, 1 )
GFXDECODE_ENTRY( "bgtiles", 0, gfx_16x16x4_packed_lsb, 1*16, 16 )
GFXDECODE_ENTRY( "sprites", 0, sprite_layout, 1*16+16*16, 256 )
GFXDECODE_END
void terracre_state::tc_base(machine_config &config)
{
M68000(config, m_maincpu, XTAL(16'000'000) / 2); // 8MHz verified on PCB
m_maincpu->set_addrmap(AS_PROGRAM, &terracre_state::terracre_map);
m_maincpu->set_vblank_int("screen", FUNC(terracre_state::irq1_line_hold));
Z80(config, m_audiocpu, XTAL(16'000'000) / 4); // 4MHz verified on PCB
m_audiocpu->set_addrmap(AS_PROGRAM, &terracre_state::sound_map);
// z80 io map set in 2203 or 3526 configs below
m_audiocpu->set_periodic_int(FUNC(terracre_state::irq0_line_hold), attotime::from_hz(XTAL(16'000'000) / 4 / 512)); // ?
BUFFERED_SPRITERAM16(config, m_spriteram);
screen_device &screen(SCREEN(config, "screen", SCREEN_TYPE_RASTER));
screen.set_refresh_hz(60);
screen.set_vblank_time(ATTOSECONDS_IN_USEC(2500)); // not accurate
screen.set_size(32*8, 32*8);
screen.set_visarea(0*8, 32*8-1, 2*8, 30*8-1);
screen.set_screen_update(FUNC(terracre_state::screen_update));
screen.screen_vblank().set(m_spriteram, FUNC(buffered_spriteram16_device::vblank_copy_rising));
screen.set_palette(m_palette);
GFXDECODE(config, m_gfxdecode, m_palette, gfx_terracre);
PALETTE(config, m_palette, FUNC(terracre_state::palette), 1*16+16*16+16*256, 256);
SPEAKER(config, "speaker").front_center();
GENERIC_LATCH_8(config, m_soundlatch);
}
void terracre_state::ym3526(machine_config &config)
{
tc_base(config);
m_audiocpu->set_addrmap(AS_IO, &terracre_state::sound_3526_io_map);
// Note: The terra cresta filters are not identical to the later Nichibutsu filters(galivan.cpp, armedf.cpp)
// While the yamaha (ym2203/ym3526 digital/FM portion) filter is the same, the dac filters are not,
// and (if present) the ym2203 (analog/SSG section only) filter is entirely new.
// Mixing resistor calculations for ym3526 set:
// R9 - Yamaha (digital/FM) - 1kohm = 0.4074 of total
// R12 - DAC1 - 2.2kohm = 0.1852 of total
// R8 - DAC2 - 1kohm = 0.4074 of total
// However, the actual volume output by the ym3014 dac and the r2r resistors
// is not the same range on each!
// The YM3014 dac has a DC offset of 1/2 VDD, then +- 1/4 VDD of signal,
// so min of 1.25v and max of 3.75v, vpp of 2.5v
// The R2R dacs are full range, min of 0v and max of (almost) 5v, vpp of ~5.0v
// Because of this, we have to compensate as MAME's ymfm core outputs full range.
// Math::
// YMFM: 0.407407 * 0.5 = 0.203704
// DAC1: 0.185185 * 1.0 = 0.185185
// DAC2: 0.407407 * 1.0 = 0.407407
// Sum: 0.796296
// Multiply all 3 values by 1 / 0.796296 (i.e. 1.255814):
// Final values are: ym: 0.255814; dac1: 0.232558; dac2: 0.511628)
FILTER_BIQUAD(config, m_ymfilter).opamp_sk_lowpass_setup(RES_K(4.7), RES_K(4.7), RES_M(999.99), RES_R(0.001), CAP_N(3.3), CAP_N(1.0)); // R10, R11, nothing(infinite resistance), wire(short), C11, C12
m_ymfilter->add_route(ALL_OUTPUTS, "speaker", 1.0);
FILTER_BIQUAD(config, m_dacfilter1).opamp_sk_lowpass_setup(RES_K(22), RES_K(22), RES_M(999.99), RES_R(0.001), CAP_N(10), CAP_N(4.7)); // R17, R18, nothing(infinite resistance), wire(short), C19, C17
m_dacfilter1->add_route(ALL_OUTPUTS, "speaker", 1.0);
FILTER_BIQUAD(config, m_dacfilter2).opamp_sk_lowpass_setup(RES_K(22), RES_K(22), RES_M(999.99), RES_R(0.001), CAP_N(10), CAP_N(4.7)); // R16, R15, nothing(infinite resistance), wire(short), C18, C21
m_dacfilter2->add_route(ALL_OUTPUTS, "speaker", 1.0);
YM3526(config, "ymsnd", XTAL(16'000'000) / 4).add_route(ALL_OUTPUTS, m_ymfilter, 0.2558); // 4MHz verified on PCB
DAC_8BIT_R2R(config, "dac1", 0).add_route(ALL_OUTPUTS, m_dacfilter1, 0.2326); // SIP R2R DAC @ RA-1 with 74HC374P latch
DAC_8BIT_R2R(config, "dac2", 0).add_route(ALL_OUTPUTS, m_dacfilter2, 0.5116); // SIP R2R DAC @ RA-2 with 74HC374P latch
}
void terracre_state::ym2203(machine_config &config)
{
tc_base(config);
m_audiocpu->set_addrmap(AS_IO, &terracre_state::sound_2203_io_map);
//subdevice<z80_device>("audiocpu")->set_addrmap(AS_IO, &terracre_state::sound_2203_io_map);
// Note: The Terra Cresta filters are not identical to the later Nichibutsu filters(galivan.cpp, armedf.cpp)
// While the yamaha (ym2203/ym3526 digital/FM portion) filter is the same, the dac filters are not,
// and (if present) the ym2203 (analog/SSG section only) filter is entirely new.
// Mixing resistor calculations for ym2203 set:
// R9 - Yamaha (digital/FM) - 1kohm = 0.3500 of total
// R12 - DAC1 - 2.2kohm = 0.1590 of total
// R8 - DAC2 - 1kohm = 0.3500 of total
// Yamaha (analog/SSG, channels A and B) - 3.3k = 0.1060
// Yamaha (analog/SSG, channel C) - 10k = 0.0350
// However, the actual volume output by the ym3014 dac and the r2r resistors
// is not the same range on each!
// The YM3014 dac has a DC offset of 1/2 VDD, then +- 1/4 VDD of signal,
// so min of 1.25v and max of 3.75v, vpp of 2.5v
// The YM2203's 3 SSG analog channels each have a vpp of about 1.15v
// (i.e. midway between 0.95 and 1.35v on datasheet), before mixing.
// (we assume mixing is perfectly additive, which probably isn't 100% true)
// The R2R dacs are full range, min of 0v and max of (almost) 5v, vpp of ~5.0v
// Because of this, we have to compensate as MAME's ymfm core outputs full range.
// Math: (assuming a constant current for each component)
// YMFM: 0.350000 * 0.5 = 0.175
// DAC1: 0.159000 * 1.0 = 0.159
// DAC2: 0.350000 * 1.0 = 0.350
// SSGA+B:0.106000 * 0.46 = 0.04876
// SSGC: 0.035000 * 0.23 = 0.00805
// Sum: 0.74081
// Multiply all 5 values by 1 / 0.74081 (i.e. 1.349873):
// ym: 0.236228; dac1: 0.21463; dac2: 0.472456, ssgA+B: 0.06582; ssg3: 0.010866)
FILTER_BIQUAD(config, m_ymfilter).opamp_sk_lowpass_setup(RES_K(4.7), RES_K(4.7), RES_M(999.99), RES_R(0.001), CAP_N(3.3), CAP_N(1.0)); // R10, R11, nothing(infinite resistance), wire(short), C11, C12
m_ymfilter->add_route(ALL_OUTPUTS, "speaker", 1.0);
FILTER_BIQUAD(config, m_dacfilter1).opamp_sk_lowpass_setup(RES_K(22), RES_K(22), RES_M(999.99), RES_R(0.001), CAP_N(10), CAP_N(4.7)); // R17, R18, nothing(infinite resistance), wire(short), C19, C17
m_dacfilter1->add_route(ALL_OUTPUTS, "speaker", 1.0);
FILTER_BIQUAD(config, m_dacfilter2).opamp_sk_lowpass_setup(RES_K(22), RES_K(22), RES_M(999.99), RES_R(0.001), CAP_N(10), CAP_N(4.7)); // R16, R15, nothing(infinite resistance), wire(short), C18, C21
m_dacfilter2->add_route(ALL_OUTPUTS, "speaker", 1.0);
// This filter is a simple first order inverting op-amp lowpass circuit with a gain of
// -4.54545 and a cutoff at effectively infinity, as it has nothing but parasitic
// capacitance as the capacitor part of said circuit. (YR12, YR15).
// Technically there may be some capacitance from YC3, although that is intended to be part of the SK filter below.
FILTER_BIQUAD(config, m_ssgfilter_abgain).opamp_mfb_lowpass_setup(RES_K(4.7), 0.0, RES_K(10), 0.0, CAP_N(22)/100.0); // YR12, N/A(short), YR15, N/A(unpopulated), (parasitic capacitance from YC3)
m_ssgfilter_abgain->add_route(ALL_OUTPUTS, "speaker", 1.0);
// This filter is a 2nd order sallen-key lowpass, unity gain.
FILTER_BIQUAD(config, m_ssgfilter_abfilt).opamp_sk_lowpass_setup(RES_K(10), RES_K(10), RES_M(999.99), RES_R(0.001), CAP_N(22), CAP_N(10)); // YR3, YR5, nothing(infinite resistance), wire(short), YC3, YC6
m_ssgfilter_abfilt->add_route(ALL_OUTPUTS, m_ssgfilter_abgain, 1.0);
// This filter is a first order inverting op-amp lowpass circuit with a gain of -4.54545 and a
// cutoff at 10.1hz (YR8, YR7, YC1).
// Technically it was probably intended as first order MFB lowpass, but the cap ("YC0")
// near/bypassing YR7 was left unpopulated.
// It turns out this cap is mathematically redundant vs the cap at YC1, and serves the
// exact same purpose for calculating the cutoff.
FILTER_BIQUAD(config, m_ssgfilter_cgain).opamp_mfb_lowpass_setup(RES_K(33), 0.0, RES_K(150), 0.0, CAP_N(100)); // YR8, N/A(short), YR7, N/A(unpopulated), YC1
m_ssgfilter_cgain->add_route(ALL_OUTPUTS, "speaker", 1.0);
MIXER(config, m_ssgmixer);
m_ssgmixer->add_route(0, m_ssgfilter_abfilt, 0.06582);
ym2203_device &ym1(YM2203(config, "ym1", XTAL(16'000'000) / 4)); // 4MHz verified on PCB
ym1.add_route(0, m_ssgmixer, 1.0);
ym1.add_route(1, m_ssgmixer, 1.0);
ym1.add_route(2, m_ssgfilter_cgain, 0.010866);
ym1.add_route(3, m_ymfilter, 0.2362);
DAC_8BIT_R2R(config, "dac1", 0).add_route(ALL_OUTPUTS, m_dacfilter1, 0.2146); // SIP R2R DAC @ RA-1 with 74HC374P latch
DAC_8BIT_R2R(config, "dac2", 0).add_route(ALL_OUTPUTS, m_dacfilter2, 0.4725); // SIP R2R DAC @ RA-2 with 74HC374P latch
}
void terracre_state::amazon_base(machine_config &config)
{
ym3526(config);
m_maincpu->set_addrmap(AS_PROGRAM, &terracre_state::amazon_base_map);
}
void amazon_state::amazon_1412m2(machine_config &config)
{
amazon_base(config);
m_maincpu->set_addrmap(AS_PROGRAM, &amazon_state::amazon_1412m2_map);
NB1412M2(config, m_prot, XTAL(16'000'000) / 4); // divided by 4 maybe
}
void terracre_state::horekidb2(machine_config &config)
{
amazon_base(config);
m_maincpu->set_addrmap(AS_PROGRAM, &terracre_state::horekidb2_map);
}
/**************************************
ROM definitions
***************************************/
/* newer PCB, manufactured in 1987, basically the same as the Amazon layout above.
Has 4*32K prg ROMs instead of 8*16K, contents is the same as other terracre sets though.
top board: BK-1 (1502), 16MHz XTAL, 68K-8, Nichibutsu 1412M2 XBA (protection chip)
bottom board: BK-2 (1502), 22MHz XTAL, Z80, YM3526 */
ROM_START( terracre )
ROM_REGION( 0x20000, "maincpu", 0 ) // 68000 code on BK-1 PCB
ROM_LOAD16_BYTE( "1.4b", 0x00001, 0x8000, CRC(60932770) SHA1(887be7a44cb7bf30d11274d34896217cc87ae158) )
ROM_LOAD16_BYTE( "3.4d", 0x00000, 0x8000, CRC(cb36240e) SHA1(24696503d9720ced869bb96ec64f336679726668) )
ROM_LOAD16_BYTE( "2.6b", 0x10001, 0x8000, CRC(539352f2) SHA1(b960f75d12ebdcd6781a073a66b8e503a8f55186) )
ROM_LOAD16_BYTE( "4.6d", 0x10000, 0x8000, CRC(19387586) SHA1(76473493d173efde83ded52ad721d2c532f590e2) )
ROM_REGION( 0x10000, "audiocpu", 0 )// Z80 code on BK-2 PCB, with intro fill-in in the main theme
ROM_LOAD( "11.15b", 0x0000, 0x4000, CRC(604c3b11) SHA1(c01d1ddae40fa8b65dfc72f959942cb9664a548b) )
ROM_LOAD( "12.17b", 0x4000, 0x4000, CRC(affc898d) SHA1(a78f06fa125de16fcdb8f4dc1629eb775aad913a) )
ROM_LOAD( "13.18b", 0x8000, 0x4000, CRC(302dc0ab) SHA1(4db8f12e70f9adf1eb993c6a8af68b5edbf79773) )
ROM_REGION( 0x02000, "fgtiles", 0 ) // on BK-2 PCB
ROM_LOAD( "14.16g", 0x00000, 0x2000, CRC(591a3804) SHA1(e1b46f5652e7f9677d75f01c6132975ace4facdd) )
ROM_REGION( 0x10000, "bgtiles", 0 ) // on BK-1 PCB
ROM_LOAD( "5.15f", 0x00000, 0x8000, CRC(984a597f) SHA1(1f33892f160691c44872b37f0f6cb1493c9f7fb1) )
ROM_LOAD( "6.17f", 0x08000, 0x8000, CRC(30e297ff) SHA1(9843826ae63039d6693c8a0b30af721d70f40056) )
ROM_REGION( 0x10000, "sprites", 0 ) // on BK-2 PCB
ROM_LOAD( "7.6e", 0x00000, 0x4000, CRC(bcf7740b) SHA1(8701862c35eb8fb1ec239253136a3858ebea4d0c) )
ROM_LOAD( "8.7e", 0x04000, 0x4000, CRC(a70b565c) SHA1(153e5f5a9927c294660dd0d636a9f651d4984d6d) )
ROM_LOAD( "9.6g", 0x08000, 0x4000, CRC(4a9ec3e6) SHA1(0a35b82fb49ecf7edafd02744a48490e744c0a00) )
ROM_LOAD( "10.7g", 0x0c000, 0x4000, CRC(450749fc) SHA1(376ab98ab8db56ed45f7d97a221dfd52e389cb5a) )
ROM_REGION( 0x0400, "proms", 0 ) // all type 82S129
ROM_LOAD( "3.10f", 0x0000, 0x0100, CRC(ce07c544) SHA1(c3691cb420c88f1887a55e3035b5d017decbc17a) ) // red component on BK-1 PCB
ROM_LOAD( "2.11f", 0x0100, 0x0100, CRC(566d323a) SHA1(fe83585a0d9c7f942a5e54620b627a5a17a0fcf4) ) // green component on BK-1 PCB
ROM_LOAD( "1.12f", 0x0200, 0x0100, CRC(7ea63946) SHA1(d7b89694a80736c7605b5c83d25d8b706f4504ab) ) // blue component on BK-1 PCB
ROM_LOAD( "4.2g", 0x0300, 0x0100, CRC(08609bad) SHA1(e5daee3c3fea6620e3c2b91becd93bc4d3cdf011) ) // (82s129 with white dot) sprite lookup table on BK-2 PCB
ROM_REGION( 0x0100, "palbank_prom", 0 ) // 82S129
ROM_LOAD( "5.4e", 0x0000, 0x0100, CRC(2c43991f) SHA1(312112832bee511b0545524295aa9bc2e756db0f) ) // (82s129 with pink dot) sprite palette bank on BK-2 PCB
ROM_REGION( 0x030c, "plds", 0 )
ROM_LOAD( "11e", 0x000, 0x104, NO_DUMP ) // PAL16L8 on BK-1 PCB
ROM_LOAD( "12a", 0x104, 0x104, NO_DUMP ) // PAL16R4 on BK-1 PCB
ROM_LOAD( "12f", 0x208, 0x104, NO_DUMP ) // PAL16R4 on BK-2 PCB
ROM_END
ROM_START( terracreo ) // older PCB TC-1A & TC-2A and oldest ROM-set
ROM_REGION( 0x20000, "maincpu", 0 ) // 68000 code on TC-1A PCB
ROM_LOAD16_BYTE( "1.4b", 0x00001, 0x4000, CRC(76f17479) SHA1(e6be7f78fe7dc9d66feb3ada6ad08d461c66640d) )
ROM_LOAD16_BYTE( "5.4d", 0x00000, 0x4000, CRC(8119f06e) SHA1(314e2d8e75f66862cf6567ac05f417a3a66f1254) )
ROM_LOAD16_BYTE( "2.6b", 0x08001, 0x4000, CRC(ba4b5822) SHA1(0de3ce04e14aa5757936babdec9cd1341d4a06d6) )
ROM_LOAD16_BYTE( "6.6d", 0x08000, 0x4000, CRC(ca4852f6) SHA1(12e968efb890ff4f982c2e04e090ac4339a97fc0) )
ROM_LOAD16_BYTE( "3.7b", 0x10001, 0x4000, CRC(d0771bba) SHA1(ebbc24562d677488a536cb515d761f07cd50425c) )
ROM_LOAD16_BYTE( "7.7d", 0x10000, 0x4000, CRC(029d59d9) SHA1(51053cafd5e7a4a5ba7008c6c6b28c612d935f40) )
ROM_LOAD16_BYTE( "4.9b", 0x18001, 0x4000, CRC(69227b56) SHA1(58c8aa4baa1f5ddfc151f5ed6284a06e87866dd7) )
ROM_LOAD16_BYTE( "8.9d", 0x18000, 0x4000, CRC(5a672942) SHA1(3890f87edb9047f3e4c6f4d4b47b7f9873962148) )
ROM_REGION( 0x10000, "audiocpu", 0 ) // Z80 code on TC-2A PCB, with intro fill-in in the main theme
ROM_LOAD( "11.15b", 0x0000, 0x4000, CRC(604c3b11) SHA1(c01d1ddae40fa8b65dfc72f959942cb9664a548b) )
ROM_LOAD( "12.17b", 0x4000, 0x4000, CRC(affc898d) SHA1(a78f06fa125de16fcdb8f4dc1629eb775aad913a) )
ROM_LOAD( "13.18b", 0x8000, 0x4000, CRC(302dc0ab) SHA1(4db8f12e70f9adf1eb993c6a8af68b5edbf79773) )
ROM_REGION( 0x02000, "fgtiles", 0 ) // on TC-2A PCB
ROM_LOAD( "18.16g", 0x00000, 0x2000, CRC(591a3804) SHA1(e1b46f5652e7f9677d75f01c6132975ace4facdd) )
ROM_REGION( 0x10000, "bgtiles", 0 ) // on TC-1A PCB
ROM_LOAD( "9.15f", 0x00000, 0x8000, CRC(984a597f) SHA1(1f33892f160691c44872b37f0f6cb1493c9f7fb1) )
ROM_LOAD( "10.17f", 0x08000, 0x8000, CRC(30e297ff) SHA1(9843826ae63039d6693c8a0b30af721d70f40056) )
ROM_REGION( 0x10000, "sprites", 0 ) // on TC-2A PCB
ROM_LOAD( "14.6e", 0x00000, 0x4000, CRC(bcf7740b) SHA1(8701862c35eb8fb1ec239253136a3858ebea4d0c) )
ROM_LOAD( "15.7e", 0x04000, 0x4000, CRC(a70b565c) SHA1(153e5f5a9927c294660dd0d636a9f651d4984d6d) )
ROM_LOAD( "16.6g", 0x08000, 0x4000, CRC(4a9ec3e6) SHA1(0a35b82fb49ecf7edafd02744a48490e744c0a00) )
ROM_LOAD( "17.7g", 0x0c000, 0x4000, CRC(450749fc) SHA1(376ab98ab8db56ed45f7d97a221dfd52e389cb5a) )
ROM_REGION( 0x0400, "proms", 0 ) // all type 82S129
ROM_LOAD( "3.10f", 0x0000, 0x0100, CRC(ce07c544) SHA1(c3691cb420c88f1887a55e3035b5d017decbc17a) ) // red component on BK-1 PCB
ROM_LOAD( "2.11f", 0x0100, 0x0100, CRC(566d323a) SHA1(fe83585a0d9c7f942a5e54620b627a5a17a0fcf4) ) // green component on BK-1 PCB
ROM_LOAD( "1.12f", 0x0200, 0x0100, CRC(7ea63946) SHA1(d7b89694a80736c7605b5c83d25d8b706f4504ab) ) // blue component on BK-1 PCB
ROM_LOAD( "4.2g", 0x0300, 0x0100, CRC(08609bad) SHA1(e5daee3c3fea6620e3c2b91becd93bc4d3cdf011) ) // sprite lookup table on BK-2 PCB
ROM_REGION( 0x0100, "palbank_prom", 0 )
ROM_LOAD( "5.4e", 0x0000, 0x0100, CRC(2c43991f) SHA1(312112832bee511b0545524295aa9bc2e756db0f) ) // sprite palette bank on TC-2A PCB
ROM_REGION( 0x030c, "plds", 0 )
ROM_LOAD( "cp1408.11e", 0x000, 0x104, NO_DUMP ) // PAL16L8 on TC-1A PCB
ROM_LOAD( "tc1411.12a", 0x104, 0x104, NO_DUMP ) // PAL16R4 on TC-1A PCB
ROM_LOAD( "tc1412.12f", 0x208, 0x104, NO_DUMP ) // PAL16R4 on TC-2A PCB
ROM_END
// probably newest TC-1A/2A board ROM-set for YM3526 version
// for unknown reasons, intro fill-in in the main theme had been removed
ROM_START( terracrea ) // older PCB TC-1A & TC-2A, the only difference is one sound ROM
ROM_REGION( 0x20000, "maincpu", 0 ) // 68000 code on TC-1A PCB
ROM_LOAD16_BYTE( "1.4b", 0x00001, 0x4000, CRC(76f17479) SHA1(e6be7f78fe7dc9d66feb3ada6ad08d461c66640d) )
ROM_LOAD16_BYTE( "5.4d", 0x00000, 0x4000, CRC(8119f06e) SHA1(314e2d8e75f66862cf6567ac05f417a3a66f1254) )
ROM_LOAD16_BYTE( "2.6b", 0x08001, 0x4000, CRC(ba4b5822) SHA1(0de3ce04e14aa5757936babdec9cd1341d4a06d6) )
ROM_LOAD16_BYTE( "6.6d", 0x08000, 0x4000, CRC(ca4852f6) SHA1(12e968efb890ff4f982c2e04e090ac4339a97fc0) )
ROM_LOAD16_BYTE( "3.7b", 0x10001, 0x4000, CRC(d0771bba) SHA1(ebbc24562d677488a536cb515d761f07cd50425c) )
ROM_LOAD16_BYTE( "7.7d", 0x10000, 0x4000, CRC(029d59d9) SHA1(51053cafd5e7a4a5ba7008c6c6b28c612d935f40) )
ROM_LOAD16_BYTE( "4.9b", 0x18001, 0x4000, CRC(69227b56) SHA1(58c8aa4baa1f5ddfc151f5ed6284a06e87866dd7) )
ROM_LOAD16_BYTE( "8.9d", 0x18000, 0x4000, CRC(5a672942) SHA1(3890f87edb9047f3e4c6f4d4b47b7f9873962148) )