1 // license:BSD-3-Clause
2 // copyright-holders:Samuele Zannoli
3 #ifndef MAME_INCLUDES_XBOX_H
4 #define MAME_INCLUDES_XBOX_H
5 
6 #pragma once
7 
8 #include "xbox_nv2a.h"
9 #include "xbox_usb.h"
10 
11 #include "machine/idectrl.h"
12 #include "machine/pic8259.h"
13 
14 /*
15  * PIC16LC connected to SMBus
16  */
17 
18 class xbox_pic16lc_device : public device_t, public smbus_interface
19 {
20 public:
21 	xbox_pic16lc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
22 	virtual int execute_command(int command, int rw, int data) override;
23 
24 protected:
25 	virtual void device_start() override;
26 	virtual void device_reset() override;
27 
28 private:
29 	uint8_t buffer[0xff];
30 };
31 
DECLARE_DEVICE_TYPE(XBOX_PIC16LC,xbox_pic16lc_device)32 DECLARE_DEVICE_TYPE(XBOX_PIC16LC, xbox_pic16lc_device)
33 
34 /*
35  * CX25871 connected to SMBus
36  */
37 
38 class xbox_cx25871_device : public device_t, public smbus_interface
39 {
40 public:
41 	xbox_cx25871_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
42 	virtual int execute_command(int command, int rw, int data) override;
43 
44 protected:
45 	virtual void device_start() override;
46 	virtual void device_reset() override;
47 
48 private:
49 };
50 
DECLARE_DEVICE_TYPE(XBOX_CX25871,xbox_cx25871_device)51 DECLARE_DEVICE_TYPE(XBOX_CX25871, xbox_cx25871_device)
52 
53 /*
54  * EEPROM connected to SMBus
55  */
56 
57 class xbox_eeprom_device : public device_t, public smbus_interface
58 {
59 public:
60 	xbox_eeprom_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
61 	virtual int execute_command(int command, int rw, int data) override;
62 
63 	std::function<void(void)> hack_eeprom;
64 
65 protected:
66 	virtual void device_start() override;
67 	virtual void device_reset() override;
68 
69 private:
70 };
71 
DECLARE_DEVICE_TYPE(XBOX_EEPROM,xbox_eeprom_device)72 DECLARE_DEVICE_TYPE(XBOX_EEPROM, xbox_eeprom_device)
73 
74 /*
75  * Super-io connected to lpc bus used as a rs232 debug port
76  */
77 
78 class xbox_superio_device : public device_t, public lpcbus_device_interface
79 {
80 public:
81 	xbox_superio_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
82 	virtual void map_extra(address_space *memory_space, address_space *io_space) override;
83 	virtual void set_host(int index, lpcbus_host_interface *host) override;
84 
85 	uint8_t read(offs_t offset);
86 	void write(offs_t offset, uint8_t data);
87 	uint8_t read_rs232(offs_t offset);
88 	void write_rs232(offs_t offset, uint8_t data);
89 
90 protected:
91 	virtual void device_start() override;
92 
93 private:
94 	void internal_io_map(address_map &map);
95 
96 	lpcbus_host_interface *lpchost;
97 	int lpcindex;
98 	address_space *memspace;
99 	address_space *iospace;
100 	bool configuration_mode;
101 	int index;
102 	int selected;
103 	uint8_t registers[16][256]; // 256 registers for up to 16 devices, registers 0-0x2f common to all
104 };
105 
DECLARE_DEVICE_TYPE(XBOX_SUPERIO,xbox_superio_device)106 DECLARE_DEVICE_TYPE(XBOX_SUPERIO, xbox_superio_device)
107 
108 /*
109  * Base
110  */
111 
112 class xbox_base_state : public driver_device
113 {
114 public:
115 	xbox_base_state(const machine_config &mconfig, device_type type, const char *tag) :
116 		driver_device(mconfig, type, tag),
117 		nvidia_nv2a(nullptr),
118 		debug_irq_active(false),
119 		debug_irq_number(0),
120 		m_maincpu(*this, "maincpu"),
121 		mcpxlpc(*this, ":pci:01.0"),
122 		ide(*this, ":pci:09.0:ide1"),
123 		debugc_bios(nullptr) { }
124 
125 	void xbox_base(machine_config &config);
126 
127 protected:
128 	void debug_generate_irq(int irq, bool active);
129 	virtual void hack_eeprom() {};
130 	virtual void hack_usb() {};
131 
132 	DECLARE_WRITE_LINE_MEMBER(vblank_callback);
133 	uint32_t screen_update_callback(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
134 
135 	virtual void machine_start() override;
136 	DECLARE_WRITE_LINE_MEMBER(maincpu_interrupt);
137 	IRQ_CALLBACK_MEMBER(irq_callback);
138 
139 	nv2a_renderer *nvidia_nv2a;
140 	bool debug_irq_active;
141 	int debug_irq_number;
142 	required_device<cpu_device> m_maincpu;
143 	required_device<mcpx_isalpc_device> mcpxlpc;
144 	required_device<bus_master_ide_controller_device> ide;
145 	static const struct debugger_constants
146 	{
147 		uint32_t id;
148 		uint32_t parameter[8]; // c c c ? ? ? x x
149 	} debugp[];
150 	const debugger_constants *debugc_bios;
151 
152 private:
153 	void dump_string_command(int ref, const std::vector<std::string> &params);
154 	void dump_process_command(int ref, const std::vector<std::string> &params);
155 	void dump_list_command(int ref, const std::vector<std::string> &params);
156 	void dump_dpc_command(int ref, const std::vector<std::string> &params);
157 	void dump_timer_command(int ref, const std::vector<std::string> &params);
158 	void curthread_command(int ref, const std::vector<std::string> &params);
159 	void threadlist_command(int ref, const std::vector<std::string> &params);
160 	void generate_irq_command(int ref, const std::vector<std::string> &params);
161 	void nv2a_combiners_command(int ref, const std::vector<std::string> &params);
162 	void nv2a_wclipping_command(int ref, const std::vector<std::string> &params);
163 	void waitvblank_command(int ref, const std::vector<std::string> &params);
164 	void grab_texture_command(int ref, const std::vector<std::string> &params);
165 	void grab_vprog_command(int ref, const std::vector<std::string> &params);
166 	void vprogdis_command(int ref, const std::vector<std::string> &params);
167 	void vdeclaration_command(int ref, const std::vector<std::string> &params);
168 	void help_command(int ref, const std::vector<std::string> &params);
169 	void xbox_debug_commands(int ref, const std::vector<std::string> &params);
170 	int find_bios_index();
171 	bool find_bios_hash(int bios, uint32_t &crc32);
172 	void find_debug_params();
173 };
174 
175 #endif // MAME_INCLUDES_XBOX_H
176