1 // license:BSD-3-Clause
2 // copyright-holders:David Haywood
3 #ifndef MAME_INCLUDES_DRGNMST_H
4 #define MAME_INCLUDES_DRGNMST_H
5 
6 #pragma once
7 
8 #include "cpu/pic16c5x/pic16c5x.h"
9 #include "sound/okim6295.h"
10 #include "sound/3812intf.h"
11 #include "sound/okim6295.h"
12 #include "sound/ym2151.h"
13 #include "emupal.h"
14 #include "tilemap.h"
15 
16 class drgnmst_base_state : public driver_device
17 {
18 public:
drgnmst_base_state(const machine_config & mconfig,device_type type,const char * tag)19 	drgnmst_base_state(const machine_config &mconfig, device_type type, const char *tag) :
20 		driver_device(mconfig, type, tag),
21 		m_maincpu(*this, "maincpu"),
22 		m_alt_scrolling(false),
23 		m_vidregs(*this, "vidregs"),
24 		m_fg_videoram(*this, "fg_videoram"),
25 		m_bg_videoram(*this, "bg_videoram"),
26 		m_md_videoram(*this, "md_videoram"),
27 		m_rowscrollram(*this, "rowscrollram"),
28 		m_vidregs2(*this, "vidregs2"),
29 		m_spriteram(*this, "spriteram"),
30 		m_gfxdecode(*this, "gfxdecode"),
31 		m_palette(*this, "palette")
32 	{ }
33 
34 	void drgnmst(machine_config &config);
35 
36 protected:
37 	virtual void machine_start() override;
38 	virtual void machine_reset() override;
39 	virtual void video_start() override;
40 
41 	void drgnmst_main_map(address_map &map);
42 	required_device<cpu_device> m_maincpu;
43 
44 	/* video-related */
45 	tilemap_t     *m_bg_tilemap;
46 	tilemap_t     *m_fg_tilemap;
47 	tilemap_t     *m_md_tilemap;
48 
49 	bool m_alt_scrolling;
50 
51 private:
52 	/* memory pointers */
53 	required_shared_ptr<uint16_t> m_vidregs;
54 	required_shared_ptr<uint16_t> m_fg_videoram;
55 	required_shared_ptr<uint16_t> m_bg_videoram;
56 	required_shared_ptr<uint16_t> m_md_videoram;
57 	required_shared_ptr<uint16_t> m_rowscrollram;
58 	required_shared_ptr<uint16_t> m_vidregs2;
59 	required_shared_ptr<uint16_t> m_spriteram;
60 
61 	/* devices */
62 	void coin_w(uint16_t data);
63 	void fg_videoram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
64 	void bg_videoram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
65 	void md_videoram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
66 	TILE_GET_INFO_MEMBER(get_fg_tile_info);
67 	TILE_GET_INFO_MEMBER(get_bg_tile_info);
68 	TILE_GET_INFO_MEMBER(get_md_tile_info);
69 	TILEMAP_MAPPER_MEMBER(fg_tilemap_scan_cols);
70 	TILEMAP_MAPPER_MEMBER(md_tilemap_scan_cols);
71 	TILEMAP_MAPPER_MEMBER(bg_tilemap_scan_cols);
72 	static rgb_t drgnmst_IIIIRRRRGGGGBBBB(uint32_t raw);
73 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
74 	void draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect);
75 	required_device<gfxdecode_device> m_gfxdecode;
76 	required_device<palette_device> m_palette;
77 
78 };
79 
80 class drgnmst_pic_state : public drgnmst_base_state
81 {
82 public:
drgnmst_pic_state(const machine_config & mconfig,device_type type,const char * tag)83 	drgnmst_pic_state(const machine_config& mconfig, device_type type, const char* tag) :
84 		drgnmst_base_state(mconfig, type, tag),
85 		m_audiocpu(*this, "audiocpu"),
86 		m_oki1bank(*this, "oki1bank"),
87 		m_oki(*this, "oki%u", 1U)
88 	{ }
89 
90 	void init_drgnmst();
91 
92 	void drgnmst_with_pic(machine_config& config);
93 
94 protected:
95 	virtual void machine_start() override;
96 	virtual void machine_reset() override;
97 
98 private:
99 	optional_device<pic16c55_device> m_audiocpu;
100 
101 	uint8_t drgnmst_asciitohex(uint8_t data);
102 
103 	required_memory_bank m_oki1bank;
104 	optional_device_array<okim6295_device, 2> m_oki;
105 
106 	/* misc */
107 	uint8_t       m_snd_command;
108 	uint16_t      m_snd_flag;
109 	uint8_t       m_oki_control;
110 	uint8_t       m_oki_command;
111 	uint8_t       m_pic16c5x_port0;
112 	uint8_t       m_oki_bank[2];
113 
114 	void snd_command_w(uint8_t data);
115 	void snd_flag_w(uint8_t data);
116 	uint8_t pic16c5x_port0_r();
117 	uint8_t snd_command_r();
118 	uint8_t snd_flag_r();
119 	void pcm_banksel_w(uint8_t data);
120 	void oki_w(uint8_t data);
121 	void snd_control_w(uint8_t data);
122 
123 	void drgnmst_main_map_with_pic(address_map& map);
124 
125 	void drgnmst_oki1_map(address_map &map);
126 };
127 
128 class drgnmst_ym_state : public drgnmst_base_state
129 {
130 public:
drgnmst_ym_state(const machine_config & mconfig,device_type type,const char * tag)131 	drgnmst_ym_state(const machine_config& mconfig, device_type type, const char* tag) :
132 		drgnmst_base_state(mconfig, type, tag),
133 		m_oki(*this, "oki")
134 	{ }
135 
136 	void drgnmst_ym(machine_config& config);
137 
138 protected:
139 	virtual void video_start() override;
140 
141 private:
142 	required_device<okim6295_device> m_oki;
143 
144 	void drgnmst_main_map_with_ym(address_map& map);
145 };
146 
147 
148 #endif // MAME_INCLUDES_DRGNMST_H
149