1 // license:BSD-3-Clause
2 // copyright-holders:Ernesto Corvi, Juergen Buchmueller, Alex Pasadyn, Aaron Giles, Nicola Salmoria
3 /*************************************************************************
4 
5     Pole Position hardware
6 
7 *************************************************************************/
8 #ifndef MAME_INCLUDES_POLEPOS_H
9 #define MAME_INCLUDES_POLEPOS_H
10 
11 #pragma once
12 
13 #include "machine/74259.h"
14 #include "machine/adc0804.h"
15 #include "machine/gen_latch.h"
16 #include "machine/timer.h"
17 #include "sound/namco.h"
18 #include "emupal.h"
19 #include "screen.h"
20 #include "tilemap.h"
21 
22 
23 class polepos_state : public driver_device
24 {
25 public:
polepos_state(const machine_config & mconfig,device_type type,const char * tag)26 	polepos_state(const machine_config &mconfig, device_type type, const char *tag) :
27 		driver_device(mconfig, type, tag),
28 		m_maincpu(*this, "maincpu"),
29 		m_subcpu(*this, "sub"),
30 		m_subcpu2(*this, "sub2"),
31 		m_sound_z80(*this, "soundz80bl"),
32 		m_soundlatch(*this, "soundlatch"),
33 		m_namco_sound(*this, "namco"),
34 		m_latch(*this, "latch"),
35 		m_adc(*this, "adc"),
36 		m_sprite16_memory(*this, "sprite16_memory"),
37 		m_road16_memory(*this, "road16_memory"),
38 		m_alpha16_memory(*this, "alpha16_memory"),
39 		m_view16_memory(*this, "view16_memory"),
40 		m_gfxdecode(*this, "gfxdecode"),
41 		m_screen(*this, "screen"),
42 		m_palette(*this, "palette")
43 	{ }
44 
45 	DECLARE_READ_LINE_MEMBER(auto_start_r);
46 
47 	void init_polepos2();
48 
49 	void polepos2bi(machine_config &config);
50 	void topracern(machine_config &config);
51 	void polepos(machine_config &config);
52 
53 protected:
54 	virtual void machine_start() override;
55 	virtual void machine_reset() override;
56 	virtual void video_start() override;
57 
58 private:
59 	required_device<cpu_device> m_maincpu;
60 	required_device<cpu_device> m_subcpu;
61 	required_device<cpu_device> m_subcpu2;
62 	optional_device<cpu_device> m_sound_z80;
63 	optional_device<generic_latch_8_device> m_soundlatch;
64 	optional_device<namco_device> m_namco_sound;
65 	required_device<ls259_device> m_latch;
66 	required_device<adc0804_device> m_adc;
67 	required_shared_ptr<uint16_t> m_sprite16_memory;
68 	required_shared_ptr<uint16_t> m_road16_memory;
69 	required_shared_ptr<uint16_t> m_alpha16_memory;
70 	required_shared_ptr<uint16_t> m_view16_memory;
71 	required_device<gfxdecode_device> m_gfxdecode;
72 	required_device<screen_device> m_screen;
73 	required_device<palette_device> m_palette;
74 
75 	uint8_t m_steer_last;
76 	uint8_t m_steer_delta;
77 	int16_t m_steer_accum;
78 	int16_t m_last_result;
79 	int8_t m_last_signed;
80 	uint8_t m_last_unsigned;
81 	int m_adc_input;
82 	int m_auto_start_mask;
83 
84 	uint16_t m_vertical_position_modifier[256];
85 	uint16_t m_road16_vscroll;
86 	tilemap_t *m_bg_tilemap;
87 	tilemap_t *m_tx_tilemap;
88 	int m_chacl;
89 	uint16_t m_scroll;
90 	uint8_t m_sub_irq_mask;
91 
92 	uint16_t polepos2_ic25_r(offs_t offset);
93 	uint8_t analog_r();
94 	uint8_t ready_r();
95 	DECLARE_WRITE_LINE_MEMBER(gasel_w);
96 	DECLARE_WRITE_LINE_MEMBER(sb0_w);
97 	DECLARE_WRITE_LINE_MEMBER(chacl_w);
98 	template<bool sub1> void z8002_nvi_enable_w(uint16_t data);
99 	uint8_t sprite_r(offs_t offset);
100 	void sprite_w(offs_t offset, uint8_t data);
101 	uint8_t road_r(offs_t offset);
102 	void road_w(offs_t offset, uint8_t data);
103 	void road16_vscroll_w(offs_t offset, uint16_t data, uint16_t mem_mask = 0);
104 	void view16_w(offs_t offset, uint16_t data, uint16_t mem_mask = 0);
105 	uint8_t view_r(offs_t offset);
106 	void view_w(offs_t offset, uint8_t data);
107 	void view16_hscroll_w(offs_t offset, uint16_t data, uint16_t mem_mask = 0);
108 	void alpha16_w(offs_t offset, uint16_t data, uint16_t mem_mask = 0);
109 	uint8_t alpha_r(offs_t offset);
110 	void alpha_w(offs_t offset, uint8_t data);
111 	void out(uint8_t data);
112 	DECLARE_WRITE_LINE_MEMBER(lockout);
113 	uint8_t namco_52xx_rom_r(offs_t offset);
114 	uint8_t namco_52xx_si_r();
115 	uint8_t namco_53xx_k_r();
116 	uint8_t steering_changed_r();
117 	uint8_t steering_delta_r();
118 	void bootleg_soundlatch_w(uint8_t data);
119 	TILE_GET_INFO_MEMBER(bg_get_tile_info);
120 	TILE_GET_INFO_MEMBER(tx_get_tile_info);
121 	void polepos_palette(palette_device &palette);
122 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
123 	TIMER_DEVICE_CALLBACK_MEMBER(scanline);
124 	void draw_road(bitmap_ind16 &bitmap);
125 	void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect );
126 	void zoom_sprite(bitmap_ind16 &bitmap,int big,uint32_t code,uint32_t color,int flipx,int sx,int sy,int sizex,int sizey);
127 	void sound_z80_bootleg_iomap(address_map &map);
128 	void sound_z80_bootleg_map(address_map &map);
129 	void topracern_io(address_map &map);
130 	void z8002_map(address_map &map);
131 	void z8002_map_1(address_map &map);
132 	void z8002_map_2(address_map &map);
133 	void z80_io(address_map &map);
134 	void z80_map(address_map &map);
135 };
136 
137 #endif // MAME_INCLUDES_POLEPOS_H
138