1 // license:BSD-3-Clause
2 // copyright-holders:Nicola Salmoria
3 #ifndef MAME_INCLUDES_SCRAMBLE_H
4 #define MAME_INCLUDES_SCRAMBLE_H
5 
6 #pragma once
7 
8 #include "machine/gen_latch.h"
9 #include "machine/i8255.h"
10 #include "includes/galaxold.h"
11 #include "sound/digitalk.h"
12 #include "sound/flt_rc.h"
13 #include "sound/tms5110.h"
14 #include "emupal.h"
15 
16 class scramble_state : public galaxold_state
17 {
18 public:
scramble_state(const machine_config & mconfig,device_type type,const char * tag)19 	scramble_state(const machine_config &mconfig, device_type type, const char *tag) :
20 		galaxold_state(mconfig, type, tag),
21 		m_konami_7474(*this, "konami_7474"),
22 		m_ppi8255_0(*this, "ppi8255_0"),
23 		m_ppi8255_1(*this, "ppi8255_1"),
24 		m_tmsprom(*this, "tmsprom"),
25 		m_soundram(*this, "soundram"),
26 		m_digitalker(*this, "digitalker"),
27 		m_soundlatch(*this, "soundlatch"),
28 		m_dial(*this, "DIAL")
29 	{
30 	}
31 
32 	optional_device<ttl7474_device> m_konami_7474;
33 	optional_device<i8255_device>  m_ppi8255_0;
34 	optional_device<i8255_device>  m_ppi8255_1;
35 	optional_device<tmsprom_device>  m_tmsprom;
36 	optional_shared_ptr<uint8_t> m_soundram;
37 	optional_device<digitalker_device> m_digitalker;
38 	optional_device<generic_latch_8_device> m_soundlatch;
39 
40 	optional_ioport m_dial;
41 
42 	DECLARE_CUSTOM_INPUT_MEMBER(darkplnt_dial_r);
43 	template <int Mask> DECLARE_READ_LINE_MEMBER(ckongs_coinage_r);
44 	uint8_t hncholms_prot_r();
45 	uint8_t scramble_soundram_r(offs_t offset);
46 	uint8_t mars_ppi8255_0_r(offs_t offset);
47 	uint8_t mars_ppi8255_1_r(offs_t offset);
48 	void scramble_soundram_w(offs_t offset, uint8_t data);
49 	uint8_t scramble_portB_r();
50 	uint8_t hustler_portB_r();
51 	void hotshock_sh_irqtrigger_w(uint8_t data);
52 	uint8_t hotshock_soundlatch_r();
53 	void mars_ppi8255_0_w(offs_t offset, uint8_t data);
54 	void mars_ppi8255_1_w(offs_t offset, uint8_t data);
55 	void ad2083_tms5110_ctrl_w(uint8_t data);
56 
57 	// harem
58 	void harem_decrypt_bit_w(uint8_t data);
59 	void harem_decrypt_clk_w(uint8_t data);
60 	void harem_decrypt_rst_w(uint8_t data);
61 	uint8_t harem_digitalker_intr_r();
62 	void harem_digitalker_control_w(uint8_t data);
63 
64 	void init_cavelon();
65 	void init_mariner();
66 	void init_scramble_ppi();
67 	void init_mars();
68 	void init_mimonscr();
69 	void init_hotshock();
70 	void init_ad2083();
71 	void init_devilfsh();
72 	void init_mrkougar();
73 	void init_harem();
74 	void init_newsin7a();
75 
76 	void init_scobra();
77 	void init_stratgyx();
78 	void init_tazmani2();
79 	void init_tazmaniet();
80 	void init_darkplnt();
81 	void init_mimonkey();
82 	void init_mimonsco();
83 	void init_rescue();
84 	void init_minefld();
85 	void init_hustler();
86 	void init_hustlerd();
87 	void init_billiard();
88 	DECLARE_MACHINE_RESET(scramble);
89 	DECLARE_MACHINE_RESET(explorer);
90 	DECLARE_WRITE_LINE_MEMBER(scramble_sh_7474_q_callback);
91 	uint8_t mariner_protection_1_r();
92 	uint8_t mariner_protection_2_r();
93 	uint8_t triplep_pip_r();
94 	uint8_t triplep_pap_r();
95 	uint8_t cavelon_banksw_r(offs_t offset);
96 	void cavelon_banksw_w(offs_t offset, uint8_t data);
97 	uint8_t hunchbks_mirror_r(address_space &space, offs_t offset);
98 	void hunchbks_mirror_w(address_space &space, offs_t offset, uint8_t data);
99 	void scramble_sh_irqtrigger_w(uint8_t data);
100 	void mrkougar_sh_irqtrigger_w(uint8_t data);
101 	IRQ_CALLBACK_MEMBER( scramble_sh_irq_callback );
102 
103 	void scramble(machine_config &config);
104 	void hncholms(machine_config &config);
105 	void cavelon(machine_config &config);
106 	void harem(machine_config &config);
107 	void ad2083(machine_config &config);
108 	void ad2083_audio(machine_config &config);
109 	void mrkougar(machine_config &config);
110 	void mars(machine_config &config);
111 	void hunchbks(machine_config &config);
112 	void hotshock(machine_config &config);
113 	void mariner(machine_config &config);
114 	void devilfsh(machine_config &config);
115 	void triplep(machine_config &config);
116 	void newsin7(machine_config &config);
117 	void mimonscr(machine_config &config);
118 	void ckongs(machine_config &config);
119 	void mrkougb(machine_config &config);
120 	void ad2083_map(address_map &map);
121 	void ad2083_sound_io_map(address_map &map);
122 	void ad2083_sound_map(address_map &map);
123 	void ckongs_map(address_map &map);
124 	void decrypted_opcodes_map(address_map &map);
125 	void harem_map(address_map &map);
126 	void harem_sound_io_map(address_map &map);
127 	void harem_sound_map(address_map &map);
128 	void hotshock_map(address_map &map);
129 	void hotshock_sound_io_map(address_map &map);
130 	void hunchbks_map(address_map &map);
131 	void hunchbks_readport(address_map &map);
132 	void mars_map(address_map &map);
133 	void mimonscr_map(address_map &map);
134 	void mrkougar_map(address_map &map);
135 	void newsin7_map(address_map &map);
136 	void scramble_map(address_map &map);
137 	void scramble_sound_io_map(address_map &map);
138 	void scramble_sound_map(address_map &map);
139 	void triplep_io_map(address_map &map);
140 	void triplep_map(address_map &map);
141 
142 private:
143 	void cavelon_banksw();
144 	inline int bit(int i,int n);
145 	void sh_init();
146 
147 	uint8_t m_cavelon_bank;
148 
149 	// harem
150 	uint8_t m_harem_decrypt_mode;
151 	uint8_t m_harem_decrypt_bit;
152 	uint8_t m_harem_decrypt_clk;
153 	uint8_t m_harem_decrypt_count;
154 	std::unique_ptr<uint8_t[]> m_harem_decrypted_data;
155 	std::unique_ptr<uint8_t[]> m_harem_decrypted_opcodes;
156 };
157 
158 #endif // MAME_INCLUDES_SCRAMBLE_H
159