1 // license:BSD-3-Clause
2 // copyright-holders:David Haywood, Andreas Naive, Tomasz Slanina, ElSemi
3 #ifndef MAME_INCLUDES_CPS3_H
4 #define MAME_INCLUDES_CPS3_H
5 
6 #pragma once
7 
8 /***************************************************************************
9 
10     Capcom CPS-3 Hardware
11 
12 ****************************************************************************/
13 
14 #include "machine/intelfsh.h"
15 #include "cpu/sh/sh2.h"
16 #include "audio/cps3.h"
17 #include "machine/timer.h"
18 #include "emupal.h"
19 
20 
21 class cps3_state : public driver_device
22 {
23 public:
cps3_state(const machine_config & mconfig,device_type type,const char * tag)24 	cps3_state(const machine_config &mconfig, device_type type, const char *tag)
25 		: driver_device(mconfig, type, tag)
26 		, m_maincpu(*this, "maincpu")
27 		, m_gfxdecode(*this, "gfxdecode")
28 		, m_palette(*this, "palette")
29 		, m_cps3sound(*this, "cps3sound")
30 		, m_dma_timer(*this, "dma_timer")
31 		, m_spritelist_dma_timer(*this, "spritelist_dma_timer")
32 		, m_simm{{*this, "simm1.%u", 0U},
33 				 {*this, "simm2.%u", 0U},
34 				 {*this, "simm3.%u", 0U},
35 				 {*this, "simm4.%u", 0U},
36 				 {*this, "simm5.%u", 0U},
37 				 {*this, "simm6.%u", 0U},
38 				 {*this, "simm7.%u", 0U}}
39 		, m_mainram(*this, "mainram")
40 		, m_spriteram(*this, "spriteram")
41 		, m_colourram(*this, "colourram", 0)
42 		, m_ppu_gscroll(*this, "ppu_gscroll_regs")
43 		, m_tilemap_regs(*this, "ppu_tmap_regs")
44 		, m_ppu_crtc_zoom(*this, "ppu_crtc_zoom")
45 		, m_sh2cache_ram(*this, "sh2cache_ram")
46 		, m_decrypted_gamerom(*this, "decrypted_gamerom")
47 		, m_sh2cache_ram_decrypted(*this, "sh2cache_ram_decrypted")
48 		, m_user4_region(*this, "user4")
49 		, m_user5_region(*this, "user5")
50 	{
51 	}
52 
53 	void init_sfiii3();
54 	void init_sfiii();
55 	void init_redearth();
56 	void init_jojo();
57 	void init_jojoba();
58 	void init_sfiii2();
59 	void init_cps3boot();
60 
61 	void cps3(machine_config &config);
62 	void jojo(machine_config &config);
63 	void redearth(machine_config &config);
64 	void sfiii2(machine_config &config);
65 	void sfiii3(machine_config &config);
66 	void sfiii(machine_config &config);
67 	void jojoba(machine_config &config);
68 	void simm_config(machine_config &config, unsigned slot, unsigned count);
69 	void simm1_64mbit(machine_config &config);
70 	void simm2_64mbit(machine_config &config);
71 	void simm3_128mbit(machine_config &config);
72 	void simm4_128mbit(machine_config &config);
73 	void simm5_128mbit(machine_config &config);
74 	void simm5_32mbit(machine_config &config);
75 	void simm6_128mbit(machine_config &config);
76 
77 protected:
78 	virtual void device_post_load() override;
79 	virtual void machine_start() override;
80 	virtual void machine_reset() override;
81 	virtual void video_start() override;
82 
83 	void copy_from_nvram();
84 	u32 m_current_table_address;
85 	required_device<sh2_device> m_maincpu;
86 	required_device<gfxdecode_device> m_gfxdecode;
87 	required_device<palette_device> m_palette;
88 	required_device<cps3_sound_device> m_cps3sound;
89 	required_device<timer_device> m_dma_timer;
90 	required_device<timer_device> m_spritelist_dma_timer;
91 	optional_device_array<fujitsu_29f016a_device, 8> m_simm[7];
92 
93 	required_shared_ptr<u32> m_mainram;
94 	required_shared_ptr<u32> m_spriteram;
95 	required_shared_ptr<u16> m_colourram;
96 	required_shared_ptr<u32> m_ppu_gscroll;
97 	required_shared_ptr<u32> m_tilemap_regs;
98 	required_shared_ptr<u32> m_ppu_crtc_zoom;
99 	required_shared_ptr<u32> m_sh2cache_ram;
100 	required_shared_ptr<u32> m_decrypted_gamerom;
101 	required_shared_ptr<u32> m_sh2cache_ram_decrypted;
102 
103 	optional_memory_region      m_user4_region;
104 	optional_memory_region      m_user5_region;
105 
106 private:
107 	u32 m_cram_gfxflash_bank;
108 	std::unique_ptr<u32[]> m_char_ram;
109 	std::unique_ptr<u32[]> m_eeprom;
110 	std::unique_ptr<u8[]>  m_ss_ram;
111 	std::unique_ptr<u32[]> m_spritelist;
112 	u32 m_ppu_gscroll_buff[0x20/4];
113 	s16 m_ss_hscroll;
114 	s16 m_ss_vscroll;
115 	u8  m_ss_pal_base;
116 	u32 m_screenwidth;
117 	std::unique_ptr<u32[]> m_mame_colours;
118 	bitmap_rgb32 m_renderbuffer_bitmap;
119 	rectangle m_renderbuffer_clip;
120 	u8* m_user4;
121 	u32 m_key1;
122 	u32 m_key2;
123 	int m_altEncryption;
124 	u16 m_dma_status;
125 	u16 m_spritelist_dma;
126 	u32 m_cram_bank;
127 	u16 m_current_eeprom_read;
128 	u32 m_paldma_source;
129 	u32 m_paldma_realsource;
130 	u32 m_paldma_dest;
131 	u32 m_paldma_fade;
132 	u32 m_paldma_other2;
133 	u32 m_paldma_length;
134 	u32 m_chardma_source;
135 	u32 m_chardma_other;
136 	int m_rle_length;
137 	int m_last_normal_byte;
138 	u16 m_lastb;
139 	u16 m_lastb2;
140 	u8* m_user5;
141 
142 	u8 ssram_r(offs_t offset);
143 	void ssram_w(offs_t offset, u8 data);
144 	void ssregs_w(offs_t offset, u8 data);
145 	void sh2cache_ram_w(offs_t offset, u32 data, u32 mem_mask = ~0);
146 	void cram_bank_w(offs_t offset, u32 data, u32 mem_mask = ~0);
147 	u32 cram_data_r(offs_t offset);
148 	void cram_data_w(offs_t offset, u32 data, u32 mem_mask = ~0);
149 	u32 gfxflash_r(offs_t offset, u32 mem_mask = ~0);
150 	void gfxflash_w(offs_t offset, u32 data, u32 mem_mask = ~0);
151 	u32 flash1_r(offs_t offset, u32 mem_mask = ~0);
152 	u32 flash2_r(offs_t offset, u32 mem_mask = ~0);
153 	void flash1_w(offs_t offset, u32 data, u32 mem_mask = ~0);
154 	void flash2_w(offs_t offset, u32 data, u32 mem_mask = ~0);
155 	void cram_gfxflash_bank_w(offs_t offset, u32 data, u32 mem_mask = ~0);
156 	u16 dma_status_r();
157 	u16 dev_dipsw_r();
158 	u32 eeprom_r(offs_t offset, u32 mem_mask = ~0);
159 	void eeprom_w(offs_t offset, u32 data, u32 mem_mask = ~0);
160 	void palettedma_w(offs_t offset, u32 data, u32 mem_mask = ~0);
161 	void characterdma_w(offs_t offset, u32 data, u32 mem_mask = ~0);
162 	u16 colourram_r(offs_t offset);
163 	void colourram_w(offs_t offset, u16 data, u16 mem_mask = ~0);
164 	void outport_w(offs_t offset, u16 data, u16 mem_mask = ~0);
165 	void spritedma_w(offs_t offset, u16 data, u16 mem_mask = ~0);
166 	SH2_DMA_KLUDGE_CB(dma_callback);
167 	void draw_fg_layer(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
168 	u32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
169 	WRITE_LINE_MEMBER(vbl_interrupt);
170 	TIMER_DEVICE_CALLBACK_MEMBER(dma_interrupt);
171 	TIMER_DEVICE_CALLBACK_MEMBER(sprite_dma_cb);
172 	u16 rotate_left(u16 value, int n);
173 	u16 rotxor(u16 val, u16 xorval);
174 	u32 cps3_mask(u32 address, u32 key1, u32 key2);
175 	void decrypt_bios();
176 	void init_crypt(u32 key1, u32 key2, int altEncryption);
177 	void set_mame_colours(int colournum, u16 data, u32 fadeval);
178 	void draw_tilemapsprite_line(u32* regs, int drawline, bitmap_rgb32 &bitmap, const rectangle &cliprect );
179 	u32 flashmain_r(int which, u32 offset, u32 mem_mask);
180 	void flashmain_w(int which, u32 offset, u32 data, u32 mem_mask);
181 	u32 process_byte( u8 real_byte, u32 destination, int max_length );
182 	void do_char_dma( u32 real_source, u32 real_destination, u32 real_length );
183 	u32 ProcessByte8(u8 b,u32 dst_offset);
184 	void do_alt_char_dma( u32 src, u32 real_dest, u32 real_length );
185 	void process_character_dma(u32 address);
186 	inline void cps3_drawgfxzoom(bitmap_rgb32 &dest_bmp, const rectangle &clip, gfx_element *gfx,
187 		u32 code, u32 color, int flipx, int flipy, int sx, int sy,
188 		int transparency, int transparent_color,
189 		int scalex, int scaley);
190 	void cps3_map(address_map &map);
191 	void decrypted_opcodes_map(address_map &map);
192 };
193 
194 #endif // MAME_INCLUDES_CPS3_H
195