I have a certain animation that is sometimes running when it should, and sometimes not.
I'm currently using Mesen as my emulator, and I can't help but missing the printf or similar console output from higher level programming languages.
I'm not sure if anything like this exists, but I keep thinking it would be nice if there were some way an emulator could watch a chunk of memory for changes, and then write that out to a file whenever it is written to. Mesen already highlights in red parts of memory when it is written to. In the 6502 assembly a little macro called "Log" could be written that would just write a short message to the part of memory being monitored. The emulator would then detect the change and dump the contents to a file.
Does something like this exist?
If not, does it make sense that it should exist?
If so what would I need to go about doing to tweak Mesen or some other emulator to add this feature?
Thanks,
Rick
debugging equivalent of printf
Moderator: Moderators
- battagline
- Posts: 152
- Joined: Wed Sep 05, 2018 11:13 am
- Location: Colorado
- Contact:
debugging equivalent of printf
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
Re: debugging equivalent of printf
Someone wrote a LUA script, I think it was for FCEUX, that put something on the screen depending on a RAM address value.
You could also put a sprite in the top left corner if something happens, or flip the grayscale bit on 2001, or set a sound channel on or off depending if a thing happens.
I don't do any of that. I use breakpoints and step through the code.
You could also put a sprite in the top left corner if something happens, or flip the grayscale bit on 2001, or set a sound channel on or off depending if a thing happens.
I don't do any of that. I use breakpoints and step through the code.
nesdoug.com -- blog/tutorial on programming for the NES
- battagline
- Posts: 152
- Joined: Wed Sep 05, 2018 11:13 am
- Location: Colorado
- Contact:
Re: debugging equivalent of printf
Thanks dougdougeff wrote:Someone wrote a LUA script, I think it was for FCEUX, that put something on the screen depending on a RAM address value.
So do either FCEUX or Mesen support scripting?
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
Re: debugging equivalent of printf
I actually don't know much about the LUA stuff. I talked with a guy who does TAS speed runs, who told me that he wrote a LUA script that printed tha value of a RAM address in the screen, or something like that.
I don't have any example code though.
Here's an example of someone using LUA scripts...
https://youtu.be/L9xZ8b3wg-I
Edit,
This looks like a LUA for FCEUX which displays stats on screen...(river city ransom)
https://github.com/BillyWM/FCEUX-Lua-Sc ... isplay.lua
I don't have any example code though.
Here's an example of someone using LUA scripts...
https://youtu.be/L9xZ8b3wg-I
Edit,
This looks like a LUA for FCEUX which displays stats on screen...(river city ransom)
https://github.com/BillyWM/FCEUX-Lua-Sc ... isplay.lua
nesdoug.com -- blog/tutorial on programming for the NES
- battagline
- Posts: 152
- Joined: Wed Sep 05, 2018 11:13 am
- Location: Colorado
- Contact:
Re: debugging equivalent of printf
It looks like Mesen also has a LUA api.
https://www.mesen.ca/docs/apireference.html
Will investigate.
Thanks again Doug
https://www.mesen.ca/docs/apireference.html
Will investigate.
Thanks again Doug
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
Re: debugging equivalent of printf
For Mesen, you should be able to use the endFrame callback to read the value from ram and print its value on the screen with drawString. There are a number of Lua script examples built into the script editor window, you can take a look at those if you want to get a better understanding of how to write your script. (Don't have access to a computer at the moment, so can't write a proper example, sorry!)
- battagline
- Posts: 152
- Joined: Wed Sep 05, 2018 11:13 am
- Location: Colorado
- Contact:
Re: debugging equivalent of printf
Sour wrote:For Mesen, you should be able to use the endFrame callback to read the value from ram and print its value on the screen with drawString. There are a number of Lua script examples built into the script editor window, you can take a look at those if you want to get a better understanding of how to write your script. (Don't have access to a computer at the moment, so can't write a proper example, sorry!)
I came up with this:
Code: Select all
prev_string = "unknown"
address_start = 0x0300
function logIt()
--emu.memType.cpu
address = address_start
log_string = ""
repeat
byte_number = emu.read( address, emu.memType.cpu)
log_string = log_string .. string.char(byte_number)
address = address + 1
until byte_number == 0
-- if log_string ~= prev_string then
emu.log("log=" .. log_string)
-- end
prev_string = log_string
end
emu.log("begin")
emu.addEventCallback(logIt, emu.eventType.endFrame);
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
-
- Posts: 1318
- Joined: Thu Apr 23, 2009 11:21 pm
- Location: cypress, texas
Re: debugging equivalent of printf
battagline, look at page 97 of this thread where I asked a similar question. Make sure to read the two posts following my question.
Hope this helps.
edit: What really helped me to figure out why animations weren't running at the proper time was after I unchecked the View>"Memory Access Highlighting">Writes box in the Memory Tools part of Mesen. That allowed me to only view the Reads (blue) and that was so helpful to me because my reading logic needed much work. The reds used to overwrite the blues, for me, at least.
Hope this helps.
edit: What really helped me to figure out why animations weren't running at the proper time was after I unchecked the View>"Memory Access Highlighting">Writes box in the Memory Tools part of Mesen. That allowed me to only view the Reads (blue) and that was so helpful to me because my reading logic needed much work. The reds used to overwrite the blues, for me, at least.
Re: debugging equivalent of printf
You can use the addMemoryCallback function to log read/write operation for a given memory range, rather than checking/logging the value a single time per frame.