Previous Thread
Next Thread
Print Thread
#119683 09/11/21 11:01 PM
Joined: Feb 2014
Posts: 674
Likes: 9
G
Senior Member
OP Offline
Senior Member
G
Joined: Feb 2014
Posts: 674
Likes: 9
Hi guys,

I was trying to do some tracing and noticed that there's no way to get the time in the debugger, so I hacked a little bit on debugcmd.cpp:

You don't have floating point values, but we can break it into seconds and nanoseconds.

Cpunum looked like a pretty simple function to pattern off of, so I thought I'd add a couple of functions.

The function "time" will return the time in seconds and "timens" will return the fractional nanosecond part.

Code
debugger_commands::debugger_commands(running_machine& machine, debugger_cpu& cpu, debugger_console& console)
	: m_machine(machine)
	, m_console(console)
{
	m_global_array = std::make_unique<global_entry []>(MAX_GLOBALS);

	symbol_table &symtable = cpu.global_symtable();

	/* add a few simple global functions */
	using namespace std::placeholders;
	symtable.add("min", 2, 2, std::bind(&debugger_commands::execute_min, this, _1, _2));
	symtable.add("max", 2, 2, std::bind(&debugger_commands::execute_max, this, _1, _2));
	symtable.add("if", 3, 3, std::bind(&debugger_commands::execute_if, this, _1, _2));
	symtable.add("abs", 1, 1, std::bind(&debugger_commands::execute_abs, this, _1, _2));
	symtable.add("bit", 2, 3, std::bind(&debugger_commands::execute_bit, this, _1, _2));
	symtable.add("s8", 1, 1, std::bind(&debugger_commands::execute_s8, this, _1, _2));
	symtable.add("s16", 1, 1, std::bind(&debugger_commands::execute_s16, this, _1, _2));
	symtable.add("s32", 1, 1, std::bind(&debugger_commands::execute_s32, this, _1, _2));
	symtable.add("cpunum", std::bind(&debugger_commands::get_cpunum, this));
	symtable.add("time", std::bind(&debugger_commands::get_cputime_secs, this));            // get time in seconds
	symtable.add("timens", std::bind(&debugger_commands::get_cputime_ns, this));           // get time fractional part in nanoseconds

Code

u64 debugger_commands::get_cpunum()
{
	execute_interface_enumerator iter(m_machine.root_device());
	return iter.indexof(m_console.get_visible_cpu()->execute());
}


u64 debugger_commands::get_cputime_secs()
{
	return u64(m_console.get_visible_cpu()->machine().time().as_double());
}

u64 debugger_commands::get_cputime_ns()
{
	double fracpart, integralpart;
	fracpart = std::modf(m_console.get_visible_cpu()->machine().time().as_double(), &integralpart);
	
	return u64(fracpart * 1.0e9);
}

and adding a couple of function definitions in debugcmd.h:
Code
	u64 get_cpunum();
	u64 get_cputime_secs();
	u64 get_cputime_ns();
and then in the debugger you can use:

Code
printf "%d.%09d\n",time,timens

This helped me to figure out that my clock rate for the imagewriter wasn't correct. I thought since the effective rate was 4.9152mhz that's what I should supply as a parameter. However, it really takes 9.8304 mhz which is the input frequency.

Maybe that'll solve the glitches I've been seeing.

I stepped a single instruction, compared the time before and the time with the number of states from the datasheet.


[Linked Image from i.imgur.com]

Joined: Feb 2014
Posts: 674
Likes: 9
G
Senior Member
OP Offline
Senior Member
G
Joined: Feb 2014
Posts: 674
Likes: 9
since I'm experimenting, why not have a function for giving the clock rate and also the time as a number of clocks. It gets kind of fiddly doing the calculations by hand.

Code
	symtable.add("cpunum", std::bind(&debugger_commands::get_cpunum, this));
	symtable.add("time", std::bind(&debugger_commands::get_cputime_secs, this));
	symtable.add("timens", std::bind(&debugger_commands::get_cputime_ns, this));
	symtable.add("timeclocks", std::bind(&debugger_commands::get_cputime_as_clocks, this));
	symtable.add("clock", std::bind(&debugger_commands::get_clock, this));



u64 debugger_commands::get_cputime_as_clocks()
{
	return u64(m_console.get_visible_cpu()->machine().time().as_double() * m_console.get_visible_cpu()->clock());
}

u64 debugger_commands::get_clock()
{
	return u64(m_console.get_visible_cpu()->clock());
}

[Linked Image from i.imgur.com]


Link Copied to Clipboard
Who's Online Now
1 members (Heihachi_73), 32 guests, and 1 robot.
Key: Admin, Global Mod, Mod
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Forum Statistics
Forums9
Topics8,974
Posts117,896
Members5,001
Most Online890
Jan 17th, 2020
Forum Host
These forums are hosted by www.retrogamesformac.com
Forum hosted by www.retrogamesformac.com