summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/model2.cpp
blob: 600619d92b8670b2132cac5f9c0501b9d69a97df (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
// license:BSD-3-Clause
// copyright-holders:R. Belmont, Olivier Galibert, ElSemi, Angelo Salese
/*********************************************************************************************************************************

    Model 2 Debugger functions

*********************************************************************************************************************************/

#include "emu.h"
#include "includes/model2.h"

#include "debug/debugcon.h"
#include "debug/debugcmd.h"
#include "debugger.h"

#include <fstream>


void model2_state::debug_init()
{
	if (machine().debug_flags & DEBUG_FLAG_ENABLED)
	{
		using namespace std::placeholders;
		machine().debugger().console().register_command("m2", CMDFLAG_CUSTOM_HELP, 0, 1, 2, std::bind(&model2_state::debug_commands, this, _1, _2));
	}
}

void model2_state::debug_commands(int ref, const std::vector<std::string> &params)
{
	if (params.size() < 1)
		return;

	if (params[0] == "geodasm")
		debug_geo_dasm_command(ref, params);
	else if(params[0] == "trilist")
		debug_tri_dump_command(ref, params);
	else
		debug_help_command(ref, params);
}

void model2_state::debug_help_command(int ref, const std::vector<std::string> &params)
{
	debugger_console &con = machine().debugger().console();

	con.printf("Available Sega Model 2 commands:\n");
	con.printf("  m2 geodasm,<filename> -- dump current geometrizer DASM in <filename>\n");
	con.printf("  m2 trilist,<filename> -- dump current parsed triangles in <filename>\n");
	con.printf("  m2 help -- this list\n");
}

/*****************************************
 *
 * GEO DASM dumping
 *
 ****************************************/

void model2_state::debug_geo_dasm_command(int ref, const std::vector<std::string> &params)
{
	debugger_console &con = machine().debugger().console();

	if (params.size() < 2)
	{
		con.printf("Error: not enough parameters for m2 geodasm command\n");
		return;
	}

	if (params[1].empty() || params[1].length() > 127)
	{
		con.printf("Error: invalid filename parameter for m2 geodasm command\n");
		return;
	}

	std::ofstream f(params[1]);
	if (!f)
	{
		con.printf("Error: while opening %s for writing\n",params[1].c_str());
		return;
	}

	// print some basic info on top
	util::stream_format(f, "Dump Header info:\n");
	util::stream_format(f, "GEO address: %08x %08x\n",m_geo_read_start_address+0x900000,m_geo_write_start_address+0x900000);
	util::stream_format(f, "Screen Info: %d %d %d\n",m_screen->frame_number(),m_screen->hpos(),m_screen->vpos());
	util::stream_format(f, "====================\n");

	int ptr = m_geo_read_start_address/4;
	bool end_code = false;

	while (!end_code && ptr < 0x20000/4)
	{
		uint32_t opcode;
		uint32_t attr;

		util::stream_format(f, "%08x: \t",ptr*4+0x900000);
		opcode = m_bufferram[ptr++];

		// parse jump opcode
		if(opcode & 0x80000000)
		{
			// exit if the operand is illegal
			if(opcode & ~0x8001ffff)
			{
				util::stream_format(f, "(illegal jump)");
				end_code = true;
			}
			else
			{
				// jump and print into dasm
				ptr = (opcode & 0x1ffff) / 4;
				util::stream_format(f, "jump %08x",opcode & 0x1ffff);
			}
		}
		else
		{

			// parse the opcode info
			switch((opcode >> 23) & 0x1f)
			{
				// nop
				case 0x00:
					util::stream_format(f, "nop");
					break;
				// object data display
				case 0x01:
					util::stream_format(f, "object data  (point:%08x header:%08x start:%08x count:%08x)",m_bufferram[ptr],m_bufferram[ptr+1],m_bufferram[ptr+2],m_bufferram[ptr+3]);
					ptr+=4;
					break;
				// direct object data display
				case 0x02:
					util::stream_format(f, "direct data  (point:%08x header:%08x)",m_bufferram[ptr],m_bufferram[ptr+1]);
					ptr+=2;
					// skip first point
					ptr+=6;
					// parse and get next pointer address
					do{
						attr = m_bufferram[ptr];

						ptr++;
						if((attr & 3) == 0)
							continue;
						// check and skip quad/tri data
						ptr += (attr & 1) ? 8 : 5;
					}while((attr & 3) != 0);

					break;
				// set display window
				case 0x03:
					util::stream_format(f, "window data  (");
					for(attr=0;attr<6;attr++)
					{
						int x,y;
						x = (m_bufferram[ptr+attr] & 0xfff0000) >> 16;
						if(x & 0x800)
							x = -( 0x800 - (x & 0x7FF) );
						y = (m_bufferram[ptr+attr] & 0xfff) >> 0;
						if(y & 0x800)
							y = -( 0x800 - (y & 0x7FF) );

						util::stream_format(f,"%d [%d,%d] ",attr,x,y);
					}
					util::stream_format(f, ")");
					ptr+=6;
					break;
				// set texture color data to RAM
				case 0x04:
					util::stream_format(f, "texture data  (start:%08x count:%08x)",m_bufferram[ptr],m_bufferram[ptr+1]);
					ptr+=(2+m_bufferram[ptr+1]);
					break;
				// set polygon data to RAM
				case 0x05:
					attr = m_bufferram[ptr+1];
					util::stream_format(f, "polygon data  (start:%08x count:%08x)",m_bufferram[ptr],attr);
					ptr+=(2+attr);
					break;
				// set texture params
				case 0x06:
					attr = m_bufferram[ptr+1];
					util::stream_format(f, "texture param  (start:%08x count:%08x)",m_bufferram[ptr],attr);
					ptr+=(2+attr*2);
					break;
				// set mode
				case 0x07:
					util::stream_format(f, "mode  (%08x)",m_bufferram[ptr]);
					ptr++;
					break;
				// set z-sort mode
				case 0x08:
					util::stream_format(f, "zsort  (%08x)",m_bufferram[ptr]);
					ptr++;
					break;
				// set focus
				case 0x09:
					util::stream_format(f, "focus  [%f,%f]",u2f(m_bufferram[ptr]),u2f(m_bufferram[ptr+1]));
					ptr+=2;
					break;
				// set parallel light
				case 0x0a:
					util::stream_format(f, "light  [%f,%f,%f]",u2f(m_bufferram[ptr]),u2f(m_bufferram[ptr+1]),u2f(m_bufferram[ptr+2]));
					ptr+=3;
					break;
				// set transform matrix
				case 0x0B:
					util::stream_format(f, "matrix ");
					for(attr=0;attr<12;attr+=3)
						util::stream_format(f,"[%f,%f,%f] ",u2f(m_bufferram[ptr+attr]),u2f(m_bufferram[ptr+1+attr]),u2f(m_bufferram[ptr+2+attr]));

					ptr+=12;
					break;
				// set translate matrix
				case 0x0C:
					util::stream_format(f, "translate  [%f,%f,%f]",u2f(m_bufferram[ptr]),u2f(m_bufferram[ptr+1]),u2f(m_bufferram[ptr+2]));
					ptr+=3;
					break;
				// debug
				case 0x0D:
					util::stream_format(f, "debug  (%08x %08x)",m_bufferram[ptr],m_bufferram[ptr+1]);
					ptr+=2;
					break;
				// test
				case 0x0E:
					util::stream_format(f, "test  (blocks:%08x)",m_bufferram[ptr+32]);
					ptr+=32;
					ptr+=m_bufferram[ptr]*3;
					break;
				// end code
				case 0x0F:
					util::stream_format(f, "end");
					end_code = true;
					break;
				// dummy
				case 0x10:
					util::stream_format(f, "dummy");
					ptr++;
					break;
				// log data
				case 0x14:
					attr = m_bufferram[ptr+1];
					util::stream_format(f, "log  (start:%08x count:%08x)",m_bufferram[ptr],attr);
					ptr+=2+attr;
					break;
				// set lod mode
				case 0x16:
					util::stream_format(f, "lod  (%f)",u2f(m_bufferram[ptr]));
					ptr++;
					break;
				// unknown opcode
				default:
					util::stream_format(f, "unk %02x",(opcode >> 23) & 0x1f);
					break;
			}
		}

		// append the raw opcode and new line here
		util::stream_format(f,"\t%08x\n",opcode);
	}

	f.close();
	con.printf("Data dumped successfully\n");
}

/*****************************************
 *
 * Sorted Triangles dumping
 *
 ****************************************/

void model2_state::debug_tri_dump_command(int ref, const std::vector<std::string> &params)
{
	debugger_console &con = machine().debugger().console();
	FILE *f;

	if (params.size() < 2)
	{
		con.printf("Error: not enough parameters for m2 trilist command\n");
		return;
	}

	if (params[1].empty() || params[1].length() > 127)
	{
		con.printf("Error: invalid filename parameter for m2 trilist command\n");
		return;
	}

	if((f = fopen( params[1].c_str(), "w" )) == nullptr)
	{
		con.printf("Error: while opening %s for writing\n",params[1].c_str());
		return;
	}

	tri_list_dump(f);
	con.printf("Data dumped successfully\n");
}