1 // license:GPL-2.0+
2 // copyright-holders:Norbert Kehrer
3 /***************************************************************************
4 
5     Mad Alien (c) 1980 Data East Corporation
6 
7     Original driver by Norbert Kehrer (February 2004)
8 
9 ***************************************************************************/
10 #ifndef MAME_INCLUDES_MADALIEN_H
11 #define MAME_INCLUDES_MADALIEN_H
12 
13 #pragma once
14 
15 #include "machine/gen_latch.h"
16 #include "sound/discrete.h"
17 #include "emupal.h"
18 #include "tilemap.h"
19 
20 
21 #define MADALIEN_MAIN_CLOCK     XTAL(10'595'000)
22 
23 
24 class madalien_state : public driver_device
25 {
26 public:
madalien_state(const machine_config & mconfig,device_type type,const char * tag)27 	madalien_state(const machine_config &mconfig, device_type type, const char *tag) :
28 		driver_device(mconfig, type, tag),
29 		m_videoram(*this, "videoram"),
30 		m_charram(*this, "charram"),
31 		m_video_control(*this, "video_control"),
32 		m_shift_hi(*this, "shift_hi"),
33 		m_shift_lo(*this, "shift_lo"),
34 		m_video_flags(*this, "video_flags"),
35 		m_headlight_pos(*this, "headlight_pos"),
36 		m_edge1_pos(*this, "edge1_pos"),
37 		m_edge2_pos(*this, "edge2_pos"),
38 		m_scroll(*this, "scroll"),
39 		m_maincpu(*this, "maincpu"),
40 		m_audiocpu(*this, "audiocpu"),
41 		m_discrete(*this, "discrete"),
42 		m_gfxdecode(*this, "gfxdecode"),
43 		m_palette(*this, "palette"),
44 		m_soundlatch(*this, "soundlatch"),
45 		m_soundlatch2(*this, "soundlatch2")
46 	{ }
47 
48 	void madalien(machine_config &config);
49 	void madalien_video(machine_config &config);
50 
51 	DECLARE_INPUT_CHANGED_MEMBER(coin_inserted);
52 
53 protected:
54 	virtual void video_start() override;
55 
56 private:
57 	required_shared_ptr<uint8_t> m_videoram;
58 	required_shared_ptr<uint8_t> m_charram;
59 	required_shared_ptr<uint8_t> m_video_control;
60 	required_shared_ptr<uint8_t> m_shift_hi;
61 	required_shared_ptr<uint8_t> m_shift_lo;
62 	required_shared_ptr<uint8_t> m_video_flags;
63 	required_shared_ptr<uint8_t> m_headlight_pos;
64 	required_shared_ptr<uint8_t> m_edge1_pos;
65 	required_shared_ptr<uint8_t> m_edge2_pos;
66 	required_shared_ptr<uint8_t> m_scroll;
67 
68 	tilemap_t *m_tilemap_fg;
69 	tilemap_t *m_tilemap_edge1[4];
70 	tilemap_t *m_tilemap_edge2[4];
71 	std::unique_ptr<bitmap_ind16> m_headlight_bitmap;
72 	uint8_t shift_r();
73 	uint8_t shift_rev_r();
74 	void madalien_output_w(uint8_t data);
75 	void madalien_videoram_w(offs_t offset, uint8_t data);
76 	void madalien_charram_w(offs_t offset, uint8_t data);
77 	void madalien_portA_w(uint8_t data);
78 	void madalien_portB_w(uint8_t data);
79 	TILEMAP_MAPPER_MEMBER(scan_mode0);
80 	TILEMAP_MAPPER_MEMBER(scan_mode1);
81 	TILEMAP_MAPPER_MEMBER(scan_mode2);
82 	TILEMAP_MAPPER_MEMBER(scan_mode3);
83 	TILE_GET_INFO_MEMBER(get_tile_info_BG_1);
84 	TILE_GET_INFO_MEMBER(get_tile_info_BG_2);
85 	TILE_GET_INFO_MEMBER(get_tile_info_FG);
86 	void madalien_palette(palette_device &palette) const;
87 	uint32_t screen_update_madalien(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
88 	inline int scan_helper(int col, int row, int section);
89 	void draw_edges(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int flip, int scroll_mode);
90 	void draw_headlight(bitmap_ind16 &bitmap, const rectangle &cliprect, int flip);
91 	void draw_foreground(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int flip);
92 	inline uint8_t shift_common(uint8_t hi, uint8_t lo);
93 	required_device<cpu_device> m_maincpu;
94 	required_device<cpu_device> m_audiocpu;
95 	required_device<discrete_device> m_discrete;
96 	required_device<gfxdecode_device> m_gfxdecode;
97 	required_device<palette_device> m_palette;
98 	required_device<generic_latch_8_device> m_soundlatch;
99 	required_device<generic_latch_8_device> m_soundlatch2;
100 	void audio_map(address_map &map);
101 	void main_map(address_map &map);
102 };
103 
104 /*----------- defined in audio/madalien.c -----------*/
105 
106 DISCRETE_SOUND_EXTERN( madalien_discrete );
107 
108 /* Discrete Sound Input Nodes */
109 #define MADALIEN_8910_PORTA         NODE_01
110 #define MADALIEN_8910_PORTB         NODE_02
111 
112 #endif // MAME_INCLUDES_MADALIEN_H
113