1 // license:BSD-3-Clause
2 // copyright-holders:David Haywood,Paul Priest
3 #ifndef MAME_INCLUDES_MS32_H
4 #define MAME_INCLUDES_MS32_H
5 
6 #pragma once
7 
8 #include "machine/gen_latch.h"
9 #include "machine/timer.h"
10 #include "video/ms32_sprite.h"
11 #include "emupal.h"
12 #include "screen.h"
13 #include "tilemap.h"
14 
15 class ms32_state : public driver_device
16 {
17 public:
ms32_state(const machine_config & mconfig,device_type type,const char * tag)18 	ms32_state(const machine_config &mconfig, device_type type, const char *tag) :
19 		driver_device(mconfig, type, tag),
20 		m_palette(*this, "palette"),
21 		m_gfxdecode(*this, "gfxdecode"),
22 		m_maincpu(*this, "maincpu"),
23 		m_audiocpu(*this, "audiocpu"),
24 		m_sprite(*this, "sprite"),
25 		m_soundlatch(*this, "soundlatch"),
26 		m_screen(*this, "screen"),
27 		m_mainram(*this, "mainram"),
28 		m_roz_ctrl(*this, "roz_ctrl"),
29 		m_tx_scroll(*this, "tx_scroll"),
30 		m_bg_scroll(*this, "bg_scroll"),
31 		m_mahjong_input_select(*this, "mahjong_select"),
32 		m_priram(*this, "priram", 32),
33 		m_palram(*this, "palram", 32),
34 		m_rozram(*this, "rozram", 32),
35 		m_lineram(*this, "lineram", 32),
36 		m_sprram(*this, "sprram", 32),
37 		m_txram(*this, "txram", 32),
38 		m_bgram(*this, "bgram", 32),
39 		m_f1superb_extraram(*this, "f1sb_extraram", 32),
40 		m_z80bank(*this, "z80bank%u", 1)
41 	{ }
42 
43 	void ms32(machine_config &config);
44 	void f1superb(machine_config &config);
45 
46 	void init_ss92047_01();
47 	void init_ss91022_10();
48 	void init_kirarast();
49 	void init_suchie2();
50 	void init_ss92048_01();
51 	void init_bnstars();
52 	void init_f1superb();
53 	void init_ss92046_01();
54 
55 	IRQ_CALLBACK_MEMBER(irq_callback);
56 	DECLARE_CUSTOM_INPUT_MEMBER(mahjong_ctrl_r);
57 
58 protected:
59 
60 	void configure_banks();
61 
62 	TIMER_DEVICE_CALLBACK_MEMBER(ms32_interrupt);
63 	void ms32_snd_bank_w(u8 data);
64 
65 	u8 latch_r();
66 	void to_main_w(u8 data);
67 	u32 ms32_sound_r();
68 	void ms32_sound_w(u32 data);
69 	void reset_sub_w(u32 data);
70 
71 	required_device<palette_device> m_palette;
72 	required_device<gfxdecode_device> m_gfxdecode;
73 
74 	int m_reverse_sprite_order;
75 	int m_flipscreen;
76 
77 	required_device<cpu_device> m_maincpu;
78 	required_device<cpu_device> m_audiocpu;
79 	required_device<ms32_sprite_device> m_sprite;
80 	optional_device<generic_latch_8_device> m_soundlatch;
81 
82 private:
83 	optional_device<screen_device> m_screen;
84 	optional_shared_ptr<u32> m_mainram;
85 	optional_shared_ptr<u32> m_roz_ctrl;
86 	optional_shared_ptr<u32> m_tx_scroll;
87 	optional_shared_ptr<u32> m_bg_scroll;
88 	optional_shared_ptr<u32> m_mahjong_input_select;
89 	optional_shared_ptr<u8> m_priram;
90 	optional_shared_ptr<u16> m_palram;
91 	optional_shared_ptr<u16> m_rozram;
92 	optional_shared_ptr<u16> m_lineram;
93 	optional_shared_ptr<u16> m_sprram;
94 	optional_shared_ptr<u16> m_txram;
95 	optional_shared_ptr<u16> m_bgram;
96 	optional_shared_ptr<u16> m_f1superb_extraram;
97 
98 	optional_memory_bank_array<2> m_z80bank;
99 	std::unique_ptr<u8[]> m_nvram_8;
100 	std::unique_ptr<u16[]> m_sprram_buffer;
101 	u32 m_to_main;
102 	u16 m_irqreq;
103 	tilemap_t *m_tx_tilemap;
104 	tilemap_t *m_roz_tilemap;
105 	tilemap_t *m_bg_tilemap;
106 	tilemap_t *m_bg_tilemap_alt;
107 	u32 m_tilemaplayoutcontrol;
108 	tilemap_t* m_extra_tilemap;
109 	bitmap_ind16 m_temp_bitmap_tilemaps;
110 	bitmap_ind16 m_temp_bitmap_sprites;
111 	bitmap_ind8 m_temp_bitmap_sprites_pri;
112 	u32 m_brt[4];
113 	int m_brt_r;
114 	int m_brt_g;
115 	int m_brt_b;
116 	u32 ms32_read_inputs3();
117 	u8 ms32_nvram_r8(offs_t offset);
118 	void ms32_nvram_w8(offs_t offset, u8 data);
119 	u8 ms32_priram_r8(offs_t offset);
120 	void ms32_priram_w8(offs_t offset, u8 data);
121 	u16 ms32_palram_r16(offs_t offset);
122 	void ms32_palram_w16(offs_t offset, u16 data, u16 mem_mask = ~0);
123 	u16 ms32_rozram_r16(offs_t offset);
124 	void ms32_rozram_w16(offs_t offset, u16 data, u16 mem_mask = ~0);
125 	u16 ms32_lineram_r16(offs_t offset);
126 	void ms32_lineram_w16(offs_t offset, u16 data, u16 mem_mask = ~0);
127 	u16 ms32_sprram_r16(offs_t offset);
128 	void ms32_sprram_w16(offs_t offset, u16 data, u16 mem_mask = ~0);
129 	u16 ms32_txram_r16(offs_t offset);
130 	void ms32_txram_w16(offs_t offset, u16 data, u16 mem_mask = ~0);
131 	u16 ms32_bgram_r16(offs_t offset);
132 	void ms32_bgram_w16(offs_t offset, u16 data, u16 mem_mask = ~0);
133 	void pip_w(u32 data);
134 	void ms32_extra_w16(offs_t offset, u16 data, u16 mem_mask = ~0);
135 	u16 ms32_extra_r16(offs_t offset);
136 	void ms32_irq2_guess_w(u32 data);
137 	void ms32_irq5_guess_w(u32 data);
138 	void ms32_brightness_w(offs_t offset, u32 data, u32 mem_mask = ~0);
139 	void ms32_gfxctrl_w(offs_t offset, u32 data, u32 mem_mask = ~0);
140 	void coin_counter_w(u32 data);
141 	void init_ms32_common();
142 
143 	TILE_GET_INFO_MEMBER(get_ms32_tx_tile_info);
144 	TILE_GET_INFO_MEMBER(get_ms32_roz_tile_info);
145 	TILE_GET_INFO_MEMBER(get_ms32_bg_tile_info);
146 	TILE_GET_INFO_MEMBER(get_ms32_extra_tile_info);
147 	virtual void machine_reset() override;
148 	virtual void video_start() override;
149 	DECLARE_VIDEO_START(f1superb);
150 	u32 screen_update_ms32(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
151 	DECLARE_WRITE_LINE_MEMBER(screen_vblank_ms32);
152 	void irq_init();
153 	void irq_raise(int level);
154 	void update_color(int color);
155 	void draw_sprites(bitmap_ind16 &bitmap, bitmap_ind8 &bitmap_pri, const rectangle &cliprect, u16 *sprram_top, size_t sprram_size, int reverseorder);
156 	void draw_roz(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect,int priority);
157 	void f1superb_map(address_map &map);
158 	void ms32_map(address_map &map);
159 	void ms32_sound_map(address_map &map);
160 };
161 
162 #endif // MAME_INCLUDES_MS32_H
163