1 // license:BSD-3-Clause
2 // copyright-holders:Bryan McPhail
3 /*************************************************************************
4 
5     Karnov - Wonder Planet - Chelnov
6 
7 *************************************************************************/
8 
9 #include "cpu/mcs51/mcs51.h"
10 #include "machine/gen_latch.h"
11 #include "video/bufsprite.h"
12 #include "video/deckarn.h"
13 #include "video/decrmc3.h"
14 #include "tilemap.h"
15 
16 class karnov_state : public driver_device
17 {
18 public:
karnov_state(const machine_config & mconfig,device_type type,const char * tag)19 	karnov_state(const machine_config &mconfig, device_type type, const char *tag)
20 		: driver_device(mconfig, type, tag),
21 		m_maincpu(*this, "maincpu"),
22 		m_audiocpu(*this, "audiocpu"),
23 		m_mcu(*this, "mcu"),
24 		m_screen(*this, "screen"),
25 		m_spriteram(*this, "spriteram") ,
26 		m_spritegen(*this, "spritegen"),
27 		m_gfxdecode(*this, "gfxdecode"),
28 		m_palette(*this, "palette"),
29 		m_soundlatch(*this, "soundlatch"),
30 		m_ram(*this, "ram"),
31 		m_videoram(*this, "videoram"),
32 		m_pf_data(*this, "pf_data"),
33 		m_scroll(*this, "scroll") { }
34 
35 	/* devices */
36 	required_device<cpu_device> m_maincpu;
37 	required_device<cpu_device> m_audiocpu;
38 	optional_device<mcs51_cpu_device> m_mcu;
39 	required_device<screen_device> m_screen;
40 	required_device<buffered_spriteram16_device> m_spriteram;
41 	required_device<deco_karnovsprites_device> m_spritegen;
42 	required_device<gfxdecode_device> m_gfxdecode;
43 	required_device<deco_rmc3_device> m_palette;
44 	required_device<generic_latch_8_device> m_soundlatch;
45 
46 	/* memory pointers */
47 	required_shared_ptr<uint16_t> m_ram;
48 	required_shared_ptr<uint16_t> m_videoram;
49 	required_shared_ptr<uint16_t> m_pf_data;
50 	required_shared_ptr<uint16_t> m_scroll;
51 
52 	/* video-related */
53 	tilemap_t     *m_bg_tilemap;
54 	tilemap_t     *m_fix_tilemap;
55 
56 	/* misc */
57 	uint16_t      m_i8751_return;
58 	uint16_t      m_i8751_needs_ack;
59 	uint16_t      m_i8751_coin_pending;
60 	uint16_t      m_i8751_command_queue;
61 	int         m_latch;
62 
63 	u16 wndrplnt_mcu_r();
64 	void wndrplnt_mcu_w(u16 data);
65 	void wndrplnt_mcu_ack_w(u16 data);
66 	void wndrplnt_mcu_reset_w(u16 data);
67 
68 	void vint_ack_w(u16 data);
69 	void videoram_w(offs_t offset, u16 data, u16 mem_mask = ~0);
70 	void playfield_w(offs_t offset, u16 data, u16 mem_mask = ~0);
71 	TILE_GET_INFO_MEMBER(get_bg_tile_info);
72 	TILE_GET_INFO_MEMBER(get_fix_tile_info);
73 	DECLARE_VIDEO_START(karnov);
74 	DECLARE_VIDEO_START(wndrplnt);
75 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
76 	DECLARE_WRITE_LINE_MEMBER(wndrplnt_mcusim_vbint_w);
77 	void vbint_w(int state);
78 
79 	void chelnovjbl(machine_config &config);
80 	void karnov(machine_config &config);
81 	void wndrplnt(machine_config &config);
82 	void karnovjbl(machine_config &config);
83 
84 	void base_sound_map(address_map &map);
85 	void chelnovjbl_mcu_map(address_map &map);
86 	void chelnovjbl_mcu_io_map(address_map &map);
87 	void karnov_map(address_map &map);
88 	void karnovjbl_map(address_map &map);
89 	void wndrplnt_map(address_map &map);
90 	void karnov_sound_map(address_map &map);
91 	void karnovjbl_sound_map(address_map &map);
92 
93 protected:
94 	virtual void machine_start() override;
95 	virtual void machine_reset() override;
96 
97 private:
98 	// protection mcu
99 	void mcu_coin_irq(int state);
100 	void mcu_ack_w(uint16_t data);
101 	uint16_t mcu_r();
102 	void mcu_w(uint16_t data);
103 	void mcu_p2_w(uint8_t data);
104 
105 	// protection mcu (bootleg specific)
106 	uint8_t mcu_data_l_r();
107 	void mcu_data_l_w(uint8_t data);
108 	uint8_t mcu_data_h_r();
109 	void mcu_data_h_w(uint8_t data);
110 	void mcubl_p1_w(uint8_t data);
111 
112 	uint8_t m_mcu_p0;
113 	uint8_t m_mcu_p1;
114 	uint8_t m_mcu_p2;
115 	uint16_t m_mcu_to_maincpu;
116 	uint16_t m_maincpu_to_mcu;
117 	bool m_coin_state;
118 };
119