1 // license:BSD-3-Clause
2 // copyright-holders:Paul Hampson
3 
4 #include "machine/gen_latch.h"
5 #include "machine/timer.h"
6 #include "emupal.h"
7 #include "screen.h"
8 #include "tilemap.h"
9 
10 class vball_state : public driver_device
11 {
12 public:
vball_state(const machine_config & mconfig,device_type type,const char * tag)13 	vball_state(const machine_config &mconfig, device_type type, const char *tag)
14 		: driver_device(mconfig, type, tag),
15 		m_maincpu(*this, "maincpu"),
16 		m_audiocpu(*this, "audiocpu"),
17 		m_gfxdecode(*this, "gfxdecode"),
18 		m_screen(*this, "screen"),
19 		m_palette(*this, "palette"),
20 		m_soundlatch(*this, "soundlatch"),
21 		m_attribram(*this, "attribram"),
22 		m_videoram(*this, "videoram"),
23 		m_scrolly_lo(*this, "scrolly_lo"),
24 		m_spriteram(*this, "spriteram") { }
25 
26 	void vball(machine_config &config);
27 
28 private:
29 	required_device<cpu_device> m_maincpu;
30 	required_device<cpu_device> m_audiocpu;
31 	required_device<gfxdecode_device> m_gfxdecode;
32 	required_device<screen_device> m_screen;
33 	required_device<palette_device> m_palette;
34 	required_device<generic_latch_8_device> m_soundlatch;
35 
36 	required_shared_ptr<uint8_t> m_attribram;
37 	required_shared_ptr<uint8_t> m_videoram;
38 	required_shared_ptr<uint8_t> m_scrolly_lo;
39 	required_shared_ptr<uint8_t> m_spriteram;
40 
41 	int m_scrollx_hi;
42 	int m_scrolly_hi;
43 	int m_scrollx_lo;
44 	int m_gfxset;
45 	int m_scrollx[256];
46 	int m_bgprombank;
47 	int m_spprombank;
48 	tilemap_t *m_bg_tilemap;
49 
50 	void irq_ack_w(offs_t offset, uint8_t data);
51 	void bankswitch_w(uint8_t data);
52 	void scrollx_hi_w(uint8_t data);
53 	void scrollx_lo_w(uint8_t data);
54 	void videoram_w(offs_t offset, uint8_t data);
55 	void attrib_w(offs_t offset, uint8_t data);
56 
57 	TILEMAP_MAPPER_MEMBER(background_scan);
58 	TILE_GET_INFO_MEMBER(get_bg_tile_info);
59 
60 	virtual void machine_start() override;
61 	virtual void video_start() override;
62 
63 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
64 	TIMER_DEVICE_CALLBACK_MEMBER(vball_scanline);
65 	void bgprombank_w(int bank);
66 	void spprombank_w(int bank);
67 	void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect);
68 	inline int scanline_to_vcount(int scanline);
69 
70 	void main_map(address_map &map);
71 	void sound_map(address_map &map);
72 };
73