1 // license:BSD-3-Clause
2 // copyright-holders:Aaron Giles
3 /*************************************************************************
4 
5     P&P Marketing Police Trainer hardware
6 
7 **************************************************************************/
8 
9 #include "cpu/mips/mips1.h"
10 #include "machine/eepromser.h"
11 #include "sound/bsmt2000.h"
12 #include "video/ramdac.h"
13 #include "emupal.h"
14 #include "screen.h"
15 #include "speaker.h"
16 
17 class policetr_state : public driver_device
18 {
19 public:
policetr_state(const machine_config & mconfig,device_type type,const char * tag)20 	policetr_state(const machine_config &mconfig, device_type type, const char *tag)
21 		: policetr_state(mconfig, type, tag, 0x1fc028ac, 0x00000fc8)
22 	{ }
23 
24 	void policetr(machine_config &config);
25 
26 	void driver_init() override;
27 
28 	DECLARE_READ_LINE_MEMBER(bsmt_status_r);
29 
30 protected:
policetr_state(const machine_config & mconfig,device_type type,const char * tag,uint32_t speedup_pc,uint32_t speedup_addr)31 	policetr_state(const machine_config &mconfig, device_type type, const char *tag, uint32_t speedup_pc, uint32_t speedup_addr) :
32 		driver_device(mconfig, type, tag),
33 		m_srcbitmap(*this, "gfx"),
34 		m_rambase(*this, "rambase"),
35 		m_maincpu(*this, "maincpu"),
36 		m_bsmt(*this, "bsmt"),
37 		m_bsmt_region(*this, "bsmt"),
38 		m_lspeaker(*this, "lspeaker"),
39 		m_rspeaker(*this, "rspeaker"),
40 		m_eeprom(*this, "eeprom"),
41 		m_screen(*this, "screen"),
42 		m_palette(*this, "palette"),
43 		m_ramdac(*this, "ramdac"),
44 		m_leds(*this, "leds%u", 0U),
45 		m_gun_x_io(*this, "GUNX%u", 1U),
46 		m_gun_y_io(*this, "GUNY%u", 1U),
47 		m_speedup_pc(speedup_pc),
48 		m_speedup_addr(speedup_addr) { }
49 
50 	void machine_start() override;
51 	void video_start() override;
52 
53 	void mem(address_map &map);
54 
55 	void ramdac_map(address_map& map);
56 
57 	void control_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
58 	void speedup_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
59 
60 	void bsmt2000_reg_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
61 	void bsmt2000_data_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
62 	uint8_t bsmt2000_data_r(offs_t offset);
63 
64 	void video_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
65 	uint32_t video_r();
66 	DECLARE_WRITE_LINE_MEMBER(vblank);
67 	void render_display_list(offs_t offset);
68 	uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
69 
70 	required_region_ptr<uint8_t> m_srcbitmap;
71 	required_shared_ptr<uint32_t> m_rambase;
72 	required_device<r3041_device> m_maincpu;
73 	required_device<bsmt2000_device> m_bsmt;
74 	required_region_ptr<uint8_t> m_bsmt_region;
75 	required_device<speaker_device> m_lspeaker;
76 	required_device<speaker_device> m_rspeaker;
77 	required_device<eeprom_serial_93cxx_device> m_eeprom;
78 	required_device<screen_device> m_screen;
79 	required_device<palette_device> m_palette;
80 	required_device<ramdac_device> m_ramdac;
81 
82 	enum
83 	{
84 		LED_PCB_RED,
85 		LED_PCB_GREEN,
86 		LED_COIN1,
87 		LED_COIN2
88 	};
89 
90 	output_finder<4> m_leds;
91 
92 	required_ioport_array<2> m_gun_x_io;
93 	required_ioport_array<2> m_gun_y_io;
94 
95 	uint32_t m_control_data;
96 	uint32_t m_bsmt_data_bank;
97 	uint32_t m_bsmt_data_offset;
98 	uint32_t *m_speedup_data;
99 	uint64_t m_last_cycles;
100 	uint32_t m_loop_count;
101 	offs_t m_speedup_pc;
102 	offs_t m_speedup_addr;
103 	rectangle m_render_clip;
104 	std::unique_ptr<bitmap_ind8> m_dstbitmap;
105 	uint16_t m_src_xoffs;
106 	uint16_t m_src_yoffs;
107 	uint16_t m_dst_xoffs;
108 	uint16_t m_dst_yoffs;
109 	uint8_t m_video_latch;
110 	uint32_t m_srcbitmap_height_mask;
111 
112 	static constexpr uint32_t SRCBITMAP_WIDTH = 4096;
113 	static constexpr uint32_t SRCBITMAP_WIDTH_MASK = SRCBITMAP_WIDTH - 1;
114 	static constexpr uint32_t DSTBITMAP_WIDTH = 512;
115 	static constexpr uint32_t DSTBITMAP_HEIGHT = 256;
116 };
117 
118 class sshooter_state : public policetr_state
119 {
120 public:
sshooter_state(const machine_config & mconfig,device_type type,const char * tag)121 	sshooter_state(const machine_config &mconfig, device_type type, const char *tag)
122 		: sshooter_state(mconfig, type, tag, 0x1fc03440, 0x00018fd8)
123 	{ }
124 
125 	void sshooter(machine_config &config);
126 
127 protected:
sshooter_state(const machine_config & mconfig,device_type type,const char * tag,uint32_t speedup_pc,uint32_t speedup_addr)128 	sshooter_state(const machine_config &mconfig, device_type type, const char *tag, uint32_t speedup_pc, uint32_t speedup_addr)
129 		: policetr_state(mconfig, type, tag, speedup_pc, speedup_addr)
130 	{ }
131 
132 	void mem(address_map &map);
133 };
134 
135 class sshoot17_state : public sshooter_state
136 {
137 public:
sshoot17_state(const machine_config & mconfig,device_type type,const char * tag)138 	sshoot17_state(const machine_config &mconfig, device_type type, const char *tag)
139 		: sshooter_state(mconfig, type, tag, 0x1fc03470, 0x00018fd8)
140 	{ }
141 };
142 
143 class sshoot12_state : public sshooter_state
144 {
145 public:
sshoot12_state(const machine_config & mconfig,device_type type,const char * tag)146 	sshoot12_state(const machine_config &mconfig, device_type type, const char *tag)
147 		: sshooter_state(mconfig, type, tag, 0x1fc033e0, 0x00018fd8)
148 	{ }
149 };
150 
151 class sshoot11_state : public sshooter_state
152 {
153 public:
sshoot11_state(const machine_config & mconfig,device_type type,const char * tag)154 	sshoot11_state(const machine_config &mconfig, device_type type, const char *tag)
155 		: sshooter_state(mconfig, type, tag, 0x1fc032f8, 0x00018fd8)
156 	{ }
157 };
158 
159 class plctr13b_state : public sshooter_state
160 {
161 public:
plctr13b_state(const machine_config & mconfig,device_type type,const char * tag)162 	plctr13b_state(const machine_config &mconfig, device_type type, const char *tag)
163 		: sshooter_state(mconfig, type, tag, 0x1fc028bc, 0x00000fc8)
164 	{ }
165 };
166 
167 class polict10_state : public sshooter_state
168 {
169 public:
polict10_state(const machine_config & mconfig,device_type type,const char * tag)170 	polict10_state(const machine_config &mconfig, device_type type, const char *tag)
171 		: sshooter_state(mconfig, type, tag, 0x1fc028b4, 0x00000fc8)
172 	{ }
173 };
174