It is currently Fri Jul 21, 2017 11:33 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Mon Jun 26, 2017 6:41 am 
Offline
Formerly 43110
User avatar

Joined: Wed Feb 05, 2014 7:01 am
Posts: 299
Location: us-east
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?


Top
 Profile  
 
PostPosted: Mon Jun 26, 2017 9:01 am 
Offline
User avatar

Joined: Mon Oct 01, 2012 3:47 pm
Posts: 151
Location: freemland (NTSC-U)
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

JRoatch wrote:
How do I capture writes to certain cpu addresses?

breakpoints in the debugger, or checking and comparing the value of memory.readbyte?

JRoatch wrote:
Can I detect when NMI is fired?

Not fully sure on this one, sorry.

JRoatch wrote:
How to I print to a file?

Specifically, you'll want the io library.

Writing "doh" to "temp.txt", overwriting anything in the file (mode "w+"; see docs for other possible options)
Code:
local testFile = io.open("temp.txt","w+");
testFile:write("doh")
testFile:close();

(Tested this in FCEUX v2.2.3, SVN revision 3372; it should work, assuming you have write access wherever the script is located.)


Top
 Profile  
 
PostPosted: Mon Jun 26, 2017 10:04 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 9787
Location: Rio de Janeiro - Brazil
JRoatch 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.

Here's a reference for the Lua scripting in FCEUX: http://www.fceux.com/web/help/fceux.htm ... sList.html

Quote:
How do I capture writes to certain cpu addresses?

memory.registerwrite registers a function to be called whenever an address or range of addresses is written to.

Quote:
Can I detect when NMI is fired?

You can register a listener for when the NMI code is run usingmemory.registerexec with the address at $FFFA-$FFFB.


Top
 Profile  
 
PostPosted: Mon Jun 26, 2017 10:27 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5403
Location: Canada
tokumaru wrote:
memory.registerwrite registers a function to be called whenever an address or range of addresses is written to.

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.


Top
 Profile  
 
PostPosted: Mon Jun 26, 2017 5:11 pm 
Offline
Formerly 43110
User avatar

Joined: Wed Feb 05, 2014 7:01 am
Posts: 299
Location: us-east
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.

tokumaru wrote:
You can register a listener for when the NMI code is run usingmemory.registerexec with the address at $FFFA-$FFFB.

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.


Last edited by JRoatch on Mon Jun 26, 2017 5:56 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Mon Jun 26, 2017 5:54 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5403
Location: Canada
It seems very unfortunately omitted. ;P

I think just nobody has ever gotten around to adding it.


Top
 Profile  
 
PostPosted: Mon Jun 26, 2017 5:55 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 9787
Location: Rio de Janeiro - Brazil
JRoatch wrote:
So there's callback registers for write and execute, but is there one for read?

Looking at the documentation, it doesn't look like there is one, which is weird.


Top
 Profile  
 
PostPosted: Mon Jun 26, 2017 5:56 pm 
Offline
Formerly 43110
User avatar

Joined: Wed Feb 05, 2014 7:01 am
Posts: 299
Location: us-east
oops posted another question as a edit to my previous post.


Top
 Profile  
 
PostPosted: Mon Jun 26, 2017 5:59 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5403
Location: Canada
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.


Top
 Profile  
 
PostPosted: Mon Jun 26, 2017 6:09 pm 
Offline
Formerly 43110
User avatar

Joined: Wed Feb 05, 2014 7:01 am
Posts: 299
Location: us-east
Well I didn't want to do that and this hack doesn't seem to be too much of a performance hit...
Code:
memory.registerexec(0x0000, 65536, function ()
  if (memory.getregister("pc") == memory.readwordunsigned(0xfffa)) then
    logFile:write("new frame\n")
    ppuAddrLatch = false
  end
end)


Top
 Profile  
 
PostPosted: Mon Jun 26, 2017 6:28 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5403
Location: Canada
Sure, a lot of CPUs can handle 5000 lua calls per frame, if that's how you wanna do it. :)


Top
 Profile  
 
PostPosted: Sat Jul 15, 2017 10:24 am 
Offline
Formerly 43110
User avatar

Joined: Wed Feb 05, 2014 7:01 am
Posts: 299
Location: us-east
Attached is the lua script that I eventually made up with all you guy's help. It probably only works in the latest interim build as it very much relies on that third callback parameter.
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.


Attachments:
ppu-logger.lua [3.01 KiB]
Downloaded 5 times
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: Bing [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group