1 // license:BSD-3-Clause
2 // copyright-holders:David Haywood, Paul Priest
3 #ifndef MAME_INCLUDES_PSIKYOSH_H
4 #define MAME_INCLUDES_PSIKYOSH_H
5 
6 #pragma once
7 
8 #include "machine/eepromser.h"
9 #include "cpu/sh/sh2.h"
10 #include "emupal.h"
11 #include "screen.h"
12 
13 
14 #define MASTER_CLOCK 57272700   // main oscillator frequency
15 
16 /* Psikyo PS6406B */
17 
18 
19 
20 class psikyosh_state : public driver_device
21 {
22 public:
psikyosh_state(const machine_config & mconfig,device_type type,const char * tag)23 	psikyosh_state(const machine_config &mconfig, device_type type, const char *tag) :
24 		driver_device(mconfig, type, tag),
25 		m_spriteram(*this, "spriteram"),
26 		m_zoomram(*this, "zoomram"),
27 		m_vidregs(*this, "vidregs"),
28 		m_ram(*this, "ram"),
29 		m_gfxrombank(*this, "gfxbank"),
30 		m_controller_io(*this, "CONTROLLER"),
31 		m_inputs(*this, "INPUTS"),
32 		m_mahjong_io(*this, "MAHJONG"),
33 		m_maincpu(*this, "maincpu"),
34 		m_eeprom(*this, "eeprom"),
35 		m_gfxdecode(*this, "gfxdecode"),
36 		m_screen(*this, "screen"),
37 		m_palette(*this, "palette")
38 	{ }
39 
40 	void psikyo3v1(machine_config &config);
41 	void psikyo5(machine_config &config);
42 	void psikyo5_mahjong(machine_config &config);
43 	void psikyo5_240(machine_config &config);
44 
45 	void init_ps3();
46 	void init_ps5();
47 
48 private:
49 	/* memory pointers */
50 	required_shared_ptr<u32> m_spriteram;
51 	required_shared_ptr<u32> m_zoomram;
52 	required_shared_ptr<u32> m_vidregs;
53 	required_shared_ptr<u32> m_ram;
54 
55 	required_memory_bank m_gfxrombank;
56 
57 	optional_ioport m_controller_io;
58 	optional_ioport m_inputs;
59 	optional_ioport m_mahjong_io;
60 
61 	/* video-related */
62 	struct sprite_t
63 	{
64 		s32 ypos, xpos;
65 		u8 high, wide;
66 		u8 flpy, flpx;
67 		u8 spr_pri, bg_pri;
68 		u8 zoomy, zoomx;
69 		u32 tnum;
70 		u16 colr;
71 		u8 dpth;
72 		s16 alpha;
73 	};
74 
75 	bitmap_ind8                 m_zoom_bitmap;
76 	bitmap_ind16                m_z_bitmap;
77 	bitmap_rgb32                m_bg_bitmap;
78 	std::unique_ptr<u16[]>      m_bg_zoom;
79 	std::unique_ptr<u8[]>       m_alphatable;
80 	std::unique_ptr<struct sprite_t []> m_spritelist;
81 	const struct sprite_t *m_sprite_end;
82 
83 	/* devices */
84 	required_device<sh2_device> m_maincpu;
85 	required_device<eeprom_serial_93cxx_device> m_eeprom;
86 	required_device<gfxdecode_device> m_gfxdecode;
87 	required_device<screen_device> m_screen;
88 	required_device<palette_device> m_palette;
89 
FLIPSCREEN()90 	bool const FLIPSCREEN() { return ((m_vidregs[3] & 0x0000c000) == 0x0000c000); } // currently ignored
91 
BG_LARGE(u8 const n)92 	bool const BG_LARGE(u8 const n)        { return ((m_vidregs[7] << (4 * n)) & 0x00001000); }
BG_DEPTH_8BPP(u8 const n)93 	bool const BG_DEPTH_8BPP(u8 const n)   { return ((m_vidregs[7] << (4 * n)) & 0x00004000); }
BG_LAYER_ENABLE(u8 const n)94 	bool const BG_LAYER_ENABLE(u8 const n) { return ((m_vidregs[7] << (4 * n)) & 0x00008000); }
95 
BG_TYPE(u8 const n)96 	u8 const BG_TYPE(u8 const n) { return ((m_vidregs[6] << (8 * n)) & 0x7f000000) >> 24; }
BG_LINE(u8 const n)97 	bool const BG_LINE(u8 const n)    { return ((m_vidregs[6] << (8 * n)) & 0x80000000); }
98 
SPRITE_PRI(u8 const n)99 	u8 const SPRITE_PRI(u8 const n) { return ((m_vidregs[2] << (4 * n)) & 0xf0000000) >> 28; }
100 
101 	void irqctrl_w(u32 data);
102 	void vidregs_w(offs_t offset, u32 data, u32 mem_mask);
103 	u32 mjgtaste_input_r();
104 	void eeprom_w(u8 data);
105 	virtual void machine_start() override;
106 	virtual void video_start() override;
107 	u32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
108 	DECLARE_WRITE_LINE_MEMBER(screen_vblank);
109 	INTERRUPT_GEN_MEMBER(interrupt);
110 	void draw_scanline32_alpha(bitmap_rgb32 &bitmap, s32 destx, s32 desty, s32 length, const u32 *srcptr, int alpha);
111 	void draw_scanline32_argb(bitmap_rgb32 &bitmap, s32 destx, s32 desty, s32 length, const u32 *srcptr);
112 	void draw_scanline32_transpen(bitmap_rgb32 &bitmap, s32 destx, s32 desty, s32 length, const u32 *srcptr);
113 	void draw_bglayer(u8 const layer, bitmap_rgb32 &bitmap, const rectangle &cliprect, u8 const req_pri);
114 	void cache_bitmap(s16 const scanline, gfx_element *gfx, u8 const size, u8 const tilebank, s16 const alpha, u8 *last_bank);
115 	void draw_bglayerscroll(u8 const layer, bitmap_rgb32 &bitmap, const rectangle &cliprect, u8 const req_pri);
116 	void draw_background(bitmap_rgb32 &bitmap, const rectangle &cliprect, u8 const req_pri);
117 	void draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect, u8 const req_pri);
118 	void get_sprites();
119 	void prelineblend(bitmap_rgb32 &bitmap, const rectangle &cliprect );
120 	void postlineblend(bitmap_rgb32 &bitmap, const rectangle &cliprect, u8 const req_pri);
121 	void psikyosh_drawgfxzoom(bitmap_rgb32 &dest_bmp, const rectangle &clip, gfx_element *gfx,
122 	u32 const code, u16 const color, u8 const flipx, u8 const flipy, s32 const offsx, s32 const offsy,
123 	s16 const alpha, u32 const zoomx, u32 const zoomy, u8 const wide, u8 const high, u16 const z);
124 	void ps3v1_map(address_map &map);
125 	void ps5_map(address_map &map);
126 	void ps5_mahjong_map(address_map &map);
127 };
128 
129 #endif // MAME_INCLUDES_PSIKYOSH_H
130