1 // license:BSD-3-Clause
2 // copyright-holders:Mike Coates, Couriersud
3 /***************************************************************************
4 
5     Century CVS System
6 
7 ****************************************************************************/
8 #ifndef MAME_INCLUDES_CVS_H
9 #define MAME_INCLUDES_CVS_H
10 
11 #pragma once
12 
13 #include "cpu/s2650/s2650.h"
14 #include "machine/gen_latch.h"
15 #include "machine/s2636.h"
16 #include "sound/dac.h"
17 #include "sound/tms5110.h"
18 #include "emupal.h"
19 #include "screen.h"
20 
21 #define CVS_S2636_Y_OFFSET     (-5)
22 #define CVS_S2636_X_OFFSET     (-26)
23 #define CVS_MAX_STARS          250
24 
25 struct cvs_star
26 {
27 	int x, y, code;
28 };
29 
30 class cvs_state : public driver_device
31 {
32 public:
cvs_state(const machine_config & mconfig,device_type type,const char * tag)33 	cvs_state(const machine_config &mconfig, device_type type, const char *tag)
34 		: driver_device(mconfig, type, tag)
35 		, m_video_ram(*this, "video_ram")
36 		, m_bullet_ram(*this, "bullet_ram")
37 		, m_cvs_4_bit_dac_data(*this, "4bit_dac")
38 		, m_tms5110_ctl_data(*this, "tms5110_ctl")
39 		, m_dac3_state(*this, "dac3_state")
40 		, m_maincpu(*this, "maincpu")
41 		, m_audiocpu(*this, "audiocpu")
42 		, m_speechcpu(*this, "speechcpu")
43 		, m_dac2(*this, "dac2")
44 		, m_dac3(*this, "dac3")
45 		, m_tms5110(*this, "tms")
46 		, m_s2636(*this, "s2636%u", 0U)
47 		, m_gfxdecode(*this, "gfxdecode")
48 		, m_screen(*this, "screen")
49 		, m_palette(*this, "palette")
50 		, m_soundlatch(*this, "soundlatch")
51 		, m_lamps(*this, "lamp%u", 1U)
52 	{ }
53 
54 	void init_raiders();
55 	void init_huncholy();
56 	void init_hero();
57 	void init_superbik();
58 	void init_hunchbaka();
59 	void cvs(machine_config &config);
60 
61 protected:
62 
63 	DECLARE_WRITE_LINE_MEMBER(write_s2650_flag); // used by galaxia_state
64 	uint8_t huncholy_prot_r(offs_t offset);
65 	uint8_t superbik_prot_r();
66 	uint8_t hero_prot_r(offs_t offset);
67 	DECLARE_READ_LINE_MEMBER(speech_rom_read_bit);
68 	DECLARE_WRITE_LINE_MEMBER(cvs_slave_cpu_interrupt);
69 	uint8_t cvs_input_r(offs_t offset);
70 	void cvs_speech_rom_address_lo_w(uint8_t data);
71 	void cvs_speech_rom_address_hi_w(uint8_t data);
72 	uint8_t cvs_speech_command_r();
73 	void audio_command_w(uint8_t data);
74 	uint8_t cvs_video_or_color_ram_r(offs_t offset);
75 	void cvs_video_or_color_ram_w(offs_t offset, uint8_t data);
76 	uint8_t cvs_bullet_ram_or_palette_r(offs_t offset);
77 	void cvs_bullet_ram_or_palette_w(offs_t offset, uint8_t data);
78 	uint8_t cvs_s2636_0_or_character_ram_r(offs_t offset);
79 	void cvs_s2636_0_or_character_ram_w(offs_t offset, uint8_t data);
80 	uint8_t cvs_s2636_1_or_character_ram_r(offs_t offset);
81 	void cvs_s2636_1_or_character_ram_w(offs_t offset, uint8_t data);
82 	uint8_t cvs_s2636_2_or_character_ram_r(offs_t offset);
83 	void cvs_s2636_2_or_character_ram_w(offs_t offset, uint8_t data);
84 	void cvs_video_fx_w(uint8_t data);
85 	uint8_t cvs_collision_r();
86 	uint8_t cvs_collision_clear();
87 	void cvs_scroll_w(uint8_t data);
88 	DECLARE_READ_LINE_MEMBER(tms_clock_r);
89 	void cvs_4_bit_dac_data_w(offs_t offset, uint8_t data);
90 	void cvs_unknown_w(offs_t offset, uint8_t data);
91 	void cvs_tms5110_ctl_w(offs_t offset, uint8_t data);
92 	void cvs_tms5110_pdc_w(offs_t offset, uint8_t data);
93 	DECLARE_VIDEO_START(cvs);
94 	void cvs_palette(palette_device &palette) const;
95 	uint32_t screen_update_cvs(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
96 	INTERRUPT_GEN_MEMBER(cvs_main_cpu_interrupt);
97 	TIMER_CALLBACK_MEMBER(cvs_393hz_timer_cb);
98 	void set_pens();
99 	void cvs_scroll_stars();
100 	void cvs_init_stars();
101 	void cvs_update_stars(bitmap_ind16 &bitmap, const rectangle &cliprect, const pen_t star_pen, bool update_always);
102 	void start_393hz_timer();
103 	void cvs_dac_cpu_map(address_map &map);
104 	void cvs_main_cpu_data_map(address_map &map);
105 	void cvs_main_cpu_io_map(address_map &map);
106 	void cvs_main_cpu_map(address_map &map);
107 	void cvs_speech_cpu_map(address_map &map);
108 
109 	virtual void machine_start() override;
110 	virtual void machine_reset() override;
111 
112 	/* memory pointers */
113 	required_shared_ptr<uint8_t> m_video_ram;
114 	required_shared_ptr<uint8_t> m_bullet_ram;
115 	optional_shared_ptr<uint8_t> m_cvs_4_bit_dac_data;
116 	optional_shared_ptr<uint8_t> m_tms5110_ctl_data;
117 	optional_shared_ptr<uint8_t> m_dac3_state;
118 
119 	/* video-related */
120 	struct cvs_star m_stars[CVS_MAX_STARS];
121 	bitmap_ind16   m_collision_background;
122 	bitmap_ind16   m_background_bitmap;
123 	bitmap_ind16   m_scrolled_collision_background;
124 	int        m_collision_register;
125 	int        m_total_stars;
126 	int        m_stars_on;
127 	uint8_t      m_scroll_reg;
128 	int        m_stars_scroll;
129 
130 	/* misc */
131 	int m_s2650_flag;
132 	emu_timer  *m_cvs_393hz_timer;
133 	uint8_t      m_cvs_393hz_clock;
134 	uint8_t      m_protection_counter;
135 
136 	uint8_t      m_character_banking_mode;
137 	uint16_t     m_character_ram_page_start;
138 	uint16_t     m_speech_rom_bit_address;
139 
140 	/* devices */
141 	required_device<s2650_device> m_maincpu;
142 	optional_device<s2650_device> m_audiocpu;
143 	optional_device<s2650_device> m_speechcpu;
144 	optional_device<dac_byte_interface> m_dac2;
145 	optional_device<dac_bit_interface> m_dac3;
146 	optional_device<tms5110_device> m_tms5110;
147 	optional_device_array<s2636_device, 3> m_s2636;
148 	required_device<gfxdecode_device> m_gfxdecode;
149 	required_device<screen_device> m_screen;
150 	required_device<palette_device> m_palette;
151 	optional_device<generic_latch_8_device> m_soundlatch;
152 	output_finder<2> m_lamps;
153 
154 	/* memory */
155 	uint8_t      m_color_ram[0x400];
156 	uint8_t      m_palette_ram[0x10];
157 	uint8_t      m_character_ram[3 * 0x800];  /* only half is used, but
158 	                                           by allocating twice the amount,
159 	                                           we can use the same gfx_layout */
160 };
161 
162 #endif // MAME_INCLUDES_CVS_H
163