1 // license:BSD-3-Clause
2 // copyright-holders:Luca Elia
3 #ifndef MAME_INCLUDES_WECLEMAN_H
4 #define MAME_INCLUDES_WECLEMAN_H
5 
6 #pragma once
7 
8 #include "machine/timer.h"
9 #include "sound/k007232.h"
10 #include "video/k051316.h"
11 #include "emupal.h"
12 #include "screen.h"
13 #include "tilemap.h"
14 
15 class wecleman_state : public driver_device
16 {
17 public:
wecleman_state(const machine_config & mconfig,device_type type,const char * tag)18 	wecleman_state(const machine_config &mconfig, device_type type, const char *tag)
19 		: driver_device(mconfig, type, tag)
20 		, m_videostatus(*this, "videostatus")
21 		, m_protection_ram(*this, "protection_ram")
22 		, m_blitter_regs(*this, "blitter_regs")
23 		, m_pageram(*this, "pageram")
24 		, m_txtram(*this, "txtram")
25 		, m_spriteram(*this, "spriteram")
26 		, m_roadram(*this, "roadram")
27 		, m_generic_paletteram_16(*this, "paletteram")
28 		, m_sprite_region(*this, "sprites")
29 		, m_maincpu(*this, "maincpu")
30 		, m_audiocpu(*this, "audiocpu")
31 		, m_subcpu(*this, "sub")
32 		, m_k051316(*this, "k051316_%u", 1)
33 		, m_k007232(*this, "k007232_%u", 1)
34 		, m_gfxdecode(*this, "gfxdecode")
35 		, m_palette(*this, "palette")
36 		, m_screen(*this, "screen")
37 		, m_led(*this, "led%u", 0U)
38 	{ }
39 
40 	void hotchase(machine_config &config);
41 	void wecleman(machine_config &config);
42 
43 	void init_wecleman();
44 	void init_hotchase();
45 
46 	DECLARE_READ_LINE_MEMBER(hotchase_sound_status_r);
47 
48 private:
49 	enum
50 	{
51 		WECLEMAN_ID = 0,
52 		HOTCHASE_ID
53 	};
54 
55 	optional_shared_ptr<uint16_t> m_videostatus;
56 	optional_shared_ptr<uint16_t> m_protection_ram;
57 	required_shared_ptr<uint16_t> m_blitter_regs;
58 	optional_shared_ptr<uint16_t> m_pageram;
59 	optional_shared_ptr<uint16_t> m_txtram;
60 	required_shared_ptr<uint16_t> m_spriteram;
61 	required_shared_ptr<uint16_t> m_roadram;
62 	required_shared_ptr<uint16_t> m_generic_paletteram_16;
63 
64 	required_region_ptr<uint8_t> m_sprite_region;
65 
66 	int m_multiply_reg[2];
67 	int m_spr_color_offs;
68 	int m_prot_state;
69 	int m_selected_ip;
70 	int m_irqctrl;
71 	int m_bgpage[4];
72 	int m_fgpage[4];
73 	const int *m_gfx_bank;
74 	tilemap_t *m_bg_tilemap;
75 	tilemap_t *m_fg_tilemap;
76 	tilemap_t *m_txt_tilemap;
77 	int *m_spr_idx_list;
78 	int *m_spr_pri_list;
79 	int *m_t32x32pm;
80 	int m_gameid;
81 	int m_spr_offsx;
82 	int m_spr_offsy;
83 	int m_spr_count;
84 	uint16_t *m_rgb_half;
85 	int m_cloud_blend;
86 	int m_cloud_ds;
87 	int m_cloud_visible;
88 	int m_sound_hw_type;
89 	bool m_hotchase_sound_hs;
90 	pen_t m_black_pen;
91 
92 	uint16_t wecleman_protection_r();
93 	void wecleman_protection_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
94 	void irqctrl_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
95 	void selected_ip_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
96 	uint8_t selected_ip_r();
97 	void blitter_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
98 	uint8_t multiply_r();
99 	void multiply_w(offs_t offset, uint8_t data);
100 	void hotchase_sound_control_w(offs_t offset, uint8_t data);
101 	void wecleman_txtram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
102 	void wecleman_pageram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
103 	void wecleman_videostatus_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
104 	void hotchase_paletteram16_SBGRBBBBGGGGRRRR_word_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
105 	void wecleman_paletteram16_SSSSBBBBGGGGRRRR_word_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
106 	void wecleman_K00723216_bank_w(uint8_t data);
107 	void wecleman_volume_callback(uint8_t data);
108 	template<int Chip> uint8_t hotchase_k007232_r(offs_t offset);
109 	template<int Chip> void hotchase_k007232_w(offs_t offset, uint8_t data);
110 
111 	TILE_GET_INFO_MEMBER(wecleman_get_txt_tile_info);
112 	TILE_GET_INFO_MEMBER(wecleman_get_bg_tile_info);
113 	TILE_GET_INFO_MEMBER(wecleman_get_fg_tile_info);
114 
115 	DECLARE_MACHINE_START(wecleman);
116 	DECLARE_MACHINE_RESET(wecleman);
117 	DECLARE_VIDEO_START(wecleman);
118 
119 	DECLARE_MACHINE_START(hotchase);
120 	DECLARE_MACHINE_RESET(hotchase);
121 	DECLARE_VIDEO_START(hotchase);
122 
123 	uint32_t screen_update_wecleman(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
124 	uint32_t screen_update_hotchase(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
125 	INTERRUPT_GEN_MEMBER(hotchase_sound_timer);
126 	TIMER_DEVICE_CALLBACK_MEMBER(wecleman_scanline);
127 	TIMER_DEVICE_CALLBACK_MEMBER(hotchase_scanline);
128 	void draw_cloud(bitmap_rgb32 &bitmap,gfx_element *gfx,uint16_t *tm_base,int x0,int y0,int xcount,int ycount,int scrollx,int scrolly,int tmw_l2,int tmh_l2,int alpha,int pal_offset);
129 	void wecleman_unpack_sprites();
130 	void bitswap(uint8_t *src,size_t len,int _14,int _13,int _12,int _11,int _10,int _f,int _e,int _d,int _c,int _b,int _a,int _9,int _8,int _7,int _6,int _5,int _4,int _3,int _2,int _1,int _0);
131 	void hotchase_sprite_decode( int num16_banks, int bank_size );
132 	void get_sprite_info();
133 	void sortsprite(int *idx_array, int *key_array, int size);
134 	void wecleman_draw_road(bitmap_rgb32 &bitmap, const rectangle &cliprect, int priority);
135 	void hotchase_draw_road(bitmap_ind16 &bitmap, const rectangle &cliprect);
136 	K051316_CB_MEMBER(hotchase_zoom_callback_1);
137 	K051316_CB_MEMBER(hotchase_zoom_callback_2);
138 
139 	void hotchase_sound_hs_w(uint8_t data);
140 
141 	required_device<cpu_device> m_maincpu;
142 	required_device<cpu_device> m_audiocpu;
143 	required_device<cpu_device> m_subcpu;
144 	optional_device_array<k051316_device, 2> m_k051316;
145 	optional_device_array<k007232_device, 3> m_k007232;
146 	required_device<gfxdecode_device> m_gfxdecode;
147 	required_device<palette_device> m_palette;
148 	required_device<screen_device> m_screen;
149 
150 	output_finder<1> m_led;
151 
152 	void hotchase_map(address_map &map);
153 	void hotchase_sound_map(address_map &map);
154 	void hotchase_sub_map(address_map &map);
155 	void wecleman_map(address_map &map);
156 	void wecleman_sound_map(address_map &map);
157 	void wecleman_sub_map(address_map &map);
158 
159 	struct sprite_t
160 	{
sprite_tsprite_t161 		sprite_t() { }
162 
163 		uint8_t *pen_data = nullptr;    /* points to top left corner of tile data */
164 		int line_offset = 0;
165 
166 		const pen_t *pal_data = nullptr;
167 		rgb_t pal_base;
168 
169 		int x_offset = 0, y_offset = 0;
170 		int tile_width = 0, tile_height = 0;
171 		int total_width = 0, total_height = 0;  /* in screen coordinates */
172 		int x = 0, y = 0;
173 		int shadow_mode = 0, flags = 0;
174 	};
175 
176 	template<class BitmapClass> void do_blit_zoom32(BitmapClass &bitmap, const rectangle &cliprect, const sprite_t &sprite);
177 	template<class BitmapClass> void sprite_draw(BitmapClass &bitmap, const rectangle &cliprect);
178 
179 	std::unique_ptr<sprite_t []> m_sprite_list;
180 	sprite_t **m_spr_ptr_list;
181 };
182 
183 #endif // MAME_INCLUDES_WECLEMAN_H
184