How do I print a log of port read/writes in FCEUX?
Moderator: Moderators
How do I print a log of port read/writes in FCEUX?
It's that time of year where I feel like exploring NES data compression again. This time I want to explore the possibility of a packetized nametable compression, which unpacks to something like popslide, and perhaps also sound and music on the side. To do this I would need some data on what bytes "normal" games sends to the PPU ports for each frame (and sound ports for that side project).
I don't know Lua that well nor do I know if the FCEUX Lua environment allows writing to text files on the file system.
I'll try to learn on my own how to do basic logic and data processing on Lua, but
How do I capture writes to certain cpu addresses?
Can I detect when NMI is fired?
How to I print to a file?
I don't know Lua that well nor do I know if the FCEUX Lua environment allows writing to text files on the file system.
I'll try to learn on my own how to do basic logic and data processing on Lua, but
How do I capture writes to certain cpu addresses?
Can I detect when NMI is fired?
How to I print to a file?
Re: How do I print a log of port read/writes in FCEUX?
Lua 5.1 (assuming FCEUX uses this based on the Lua DLL filename) documentation can be found here: https://www.lua.org/manual/5.1/manual.html
Writing "doh" to "temp.txt", overwriting anything in the file (mode "w+"; see docs for other possible options)
(Tested this in FCEUX v2.2.3, SVN revision 3372; it should work, assuming you have write access wherever the script is located.)
breakpoints in the debugger, or checking and comparing the value of memory.readbyte?JRoatch wrote:How do I capture writes to certain cpu addresses?
Not fully sure on this one, sorry.JRoatch wrote:Can I detect when NMI is fired?
Specifically, you'll want the io library.JRoatch wrote:How to I print to a file?
Writing "doh" to "temp.txt", overwriting anything in the file (mode "w+"; see docs for other possible options)
Code: Select all
local testFile = io.open("temp.txt","w+");
testFile:write("doh")
testFile:close();Re: How do I print a log of port read/writes in FCEUX?
Here's a reference for the Lua scripting in FCEUX: http://www.fceux.com/web/help/fceux.htm ... sList.htmlJRoatch wrote:I don't know Lua that well nor do I know if the FCEUX Lua environment allows writing to text files on the file system.
memory.registerwrite registers a function to be called whenever an address or range of addresses is written to.How do I capture writes to certain cpu addresses?
You can register a listener for when the NMI code is run usingmemory.registerexec with the address at $FFFA-$FFFB.Can I detect when NMI is fired?
- rainwarrior
- Posts: 8062
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: How do I print a log of port read/writes in FCEUX?
Might be worth pointing out that the callback now has a third parameter for the value about to be written, which is probably really important for OP's task. I don't think this was in the last stable release, but interim builds should have it.tokumaru wrote:memory.registerwrite registers a function to be called whenever an address or range of addresses is written to.
Re: How do I print a log of port read/writes in FCEUX?
Thanks, I seem to be getting a handle on this, I'll definitely be using a current interim build.
So there's callback registers for write and execute, but is there one for read?
If not, I'll just assume that the double write latch is reset every frame and not watch for reads of $2002.
So there's callback registers for write and execute, but is there one for read?
If not, I'll just assume that the double write latch is reset every frame and not watch for reads of $2002.
I'm guessing I have to register a listener every time the vectors change due to bank switching, and I'm not sure I can detect bank switching unless I simulate it by catching mapper writes in 0x5000-0xffff.tokumaru wrote:You can register a listener for when the NMI code is run usingmemory.registerexec with the address at $FFFA-$FFFB.
Last edited by JRoatch on Mon Jun 26, 2017 5:56 pm, edited 1 time in total.
- rainwarrior
- Posts: 8062
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: How do I print a log of port read/writes in FCEUX?
It seems very unfortunately omitted. ;P
I think just nobody has ever gotten around to adding it.
I think just nobody has ever gotten around to adding it.
Re: How do I print a log of port read/writes in FCEUX?
Looking at the documentation, it doesn't look like there is one, which is weird.JRoatch wrote:So there's callback registers for write and execute, but is there one for read?
Re: How do I print a log of port read/writes in FCEUX?
oops posted another question as a edit to my previous post.
- rainwarrior
- Posts: 8062
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: How do I print a log of port read/writes in FCEUX?
Yes, I generally detect bankswitching by watching mapper writes and keeping track of the bank in the lua script.
There's no mapper-specific stuff in the LUA interface, I don't think.
There's no mapper-specific stuff in the LUA interface, I don't think.
Re: How do I print a log of port read/writes in FCEUX?
Well I didn't want to do that and this hack doesn't seem to be too much of a performance hit...
Code: Select all
memory.registerexec(0x0000, 65536, function ()
if (memory.getregister("pc") == memory.readwordunsigned(0xfffa)) then
logFile:write("new frame\n")
ppuAddrLatch = false
end
end)- rainwarrior
- Posts: 8062
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: How do I print a log of port read/writes in FCEUX?
Sure, a lot of CPUs can handle 5000 lua calls per frame, if that's how you wanna do it. 
Re: How do I print a log of port read/writes in FCEUX?
the script writes out a YAML file of the PPU data being written. It's especially neat to watch that log file via tail -f ppulog.txt while it's running.
It currently has a major shortcoming of not intercepting PPU reads that are used by a few action 53 games for skipping over the background palettes.
A Interesting thing I already discovered is the backwards column loading of bytes used for the VWF renderer of the a53 menu.
Edit: Attachment moved off site to ppu-logger.lua