1 // license:BSD-3-Clause
2 // copyright-holders:Phil Stroffolino
3 #ifndef MAME_INCLUDES_TWIN16_H
4 #define MAME_INCLUDES_TWIN16_H
5 
6 #pragma once
7 
8 #include "video/bufsprite.h"
9 #include "sound/upd7759.h"
10 #include "sound/k007232.h"
11 #include "emupal.h"
12 #include "screen.h"
13 #include "tilemap.h"
14 
15 class twin16_state : public driver_device
16 {
17 public:
twin16_state(const machine_config & mconfig,device_type type,const char * tag)18 	twin16_state(const machine_config &mconfig, device_type type, const char *tag) :
19 		driver_device(mconfig, type, tag),
20 		m_maincpu(*this, "maincpu"),
21 		m_subcpu(*this, "sub"),
22 		m_audiocpu(*this, "audiocpu"),
23 		m_k007232(*this, "k007232"),
24 		m_upd7759(*this, "upd"),
25 		m_gfxdecode(*this, "gfxdecode"),
26 		m_screen(*this, "screen"),
27 		m_palette(*this, "palette"),
28 		m_spriteram(*this, "spriteram"),
29 		m_gfxrombank(*this, "gfxrombank"),
30 		m_fixram(*this, "fixram"),
31 		m_videoram(*this, "videoram.%u", 0),
32 		m_zipram(*this, "zipram"),
33 		m_sprite_gfx_ram(*this, "sprite_gfx_ram"),
34 		m_gfxrom(*this, "gfxrom")
35 	{ }
36 
37 	void devilw(machine_config &config);
38 	void miaj(machine_config &config);
39 	void twin16(machine_config &config);
40 
41 	void init_twin16();
42 
43 	void volume_callback(uint8_t data);
44 	DECLARE_WRITE_LINE_MEMBER(screen_vblank_twin16);
45 	uint32_t screen_update_twin16(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
46 
47 protected:
48 	required_device<cpu_device> m_maincpu;
49 	optional_device<cpu_device> m_subcpu;
50 	required_device<cpu_device> m_audiocpu;
51 	required_device<k007232_device> m_k007232;
52 	required_device<upd7759_device> m_upd7759;
53 	required_device<gfxdecode_device> m_gfxdecode;
54 	required_device<screen_device> m_screen;
55 	required_device<palette_device> m_palette;
56 	required_device<buffered_spriteram16_device> m_spriteram;
57 	optional_memory_bank m_gfxrombank;
58 	required_shared_ptr<uint16_t> m_fixram;
59 	required_shared_ptr_array<uint16_t, 2> m_videoram;
60 	optional_shared_ptr<uint16_t> m_zipram;
61 	optional_shared_ptr<uint16_t> m_sprite_gfx_ram;
62 	required_region_ptr<uint16_t> m_gfxrom;
63 
64 	uint16_t m_CPUA_register;
65 	uint16_t m_CPUB_register;
66 	bool m_is_fround;
67 	uint16_t m_sprite_buffer[0x800];
68 	emu_timer *m_sprite_timer;
69 	int m_sprite_busy;
70 	int m_need_process_spriteram;
71 	uint16_t m_scrollx[3];
72 	uint16_t m_scrolly[3];
73 	uint16_t m_video_register;
74 	tilemap_t *m_fixed_tmap;
75 	tilemap_t *m_scroll_tmap[2];
76 
77 	void CPUA_register_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
78 	void CPUB_register_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
79 
80 	uint16_t sprite_status_r();
81 	void video_register_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
82 	void fixram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
83 	void videoram0_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
84 	void videoram1_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
85 	void zipram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
86 
87 	uint8_t upd_busy_r();
88 	void upd_reset_w(uint8_t data);
89 	void upd_start_w(uint8_t data);
90 
91 	TILE_GET_INFO_MEMBER(fix_tile_info);
92 	TILE_GET_INFO_MEMBER(layer0_tile_info);
93 	TILE_GET_INFO_MEMBER(layer1_tile_info);
94 
95 	TIMER_CALLBACK_MEMBER(sprite_tick);
96 
97 	void main_map(address_map &map);
98 	void sound_map(address_map &map);
99 	void sub_map(address_map &map);
100 
101 	virtual void machine_start() override;
102 	virtual void machine_reset() override;
103 	virtual void video_start() override;
104 
105 	virtual void tile_get_info(tile_data &tileinfo, uint16_t data, int color_base);
106 
107 	int set_sprite_timer();
108 	void spriteram_process();
109 	void draw_sprites( screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect );
110 	int spriteram_process_enable();
111 	void twin16_postload();
112 };
113 
114 class fround_state : public twin16_state
115 {
116 public:
fround_state(const machine_config & mconfig,device_type type,const char * tag)117 	fround_state(const machine_config &mconfig, device_type type, const char *tag)
118 		: twin16_state(mconfig, type, tag)
119 	{}
120 
121 	void fround(machine_config &config);
122 
123 	void init_fround();
124 
125 private:
126 	void fround_CPU_register_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
127 	void gfx_bank_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
128 
129 	void fround_map(address_map &map);
130 
131 	virtual void video_start() override;
132 	virtual void tile_get_info(tile_data &tileinfo, uint16_t data, int color_base) override;
133 
134 	uint8_t m_gfx_bank[4];
135 };
136 
137 class cuebrickj_state : public twin16_state
138 {
139 public:
cuebrickj_state(const machine_config & mconfig,device_type type,const char * tag)140 	cuebrickj_state(const machine_config &mconfig, device_type type, const char *tag)
141 		: twin16_state(mconfig, type, tag)
142 	{}
143 
144 	void cuebrickj(machine_config &config);
145 
146 	void init_cuebrickj();
147 
148 private:
149 	void nvram_bank_w(uint8_t data);
150 
151 	uint16_t m_nvram[0x400 * 0x20 / 2];
152 };
153 
154 #endif // MAME_INCLUDES_TWIN16_H
155