It is currently Thu Dec 13, 2018 4:57 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Sat Oct 13, 2018 9:22 am 
Offline
User avatar

Joined: Wed Sep 05, 2018 11:13 am
Posts: 152
Location: Colorado
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

_________________
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com


Top
 Profile  
 
PostPosted: Sat Oct 13, 2018 9:41 am 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2354
Location: DIGDUG
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.

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
PostPosted: Sat Oct 13, 2018 9:44 am 
Offline
User avatar

Joined: Wed Sep 05, 2018 11:13 am
Posts: 152
Location: Colorado
dougeff wrote:
Someone wrote a LUA script, I think it was for FCEUX, that put something on the screen depending on a RAM address value.


Thanks doug

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


Top
 Profile  
 
PostPosted: Sat Oct 13, 2018 9:53 am 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2354
Location: DIGDUG
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

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
PostPosted: Sat Oct 13, 2018 12:18 pm 
Offline
User avatar

Joined: Wed Sep 05, 2018 11:13 am
Posts: 152
Location: Colorado
It looks like Mesen also has a LUA api.

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


Top
 Profile  
 
PostPosted: Sat Oct 13, 2018 3:45 pm 
Offline

Joined: Sun Feb 07, 2016 6:16 pm
Posts: 530
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!)


Top
 Profile  
 
PostPosted: Sun Oct 14, 2018 7:58 am 
Offline
User avatar

Joined: Wed Sep 05, 2018 11:13 am
Posts: 152
Location: Colorado
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:
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);


Seems to work(ish). I'd like to have it called when the memory is updated instead of every frame, but I don't see that as a part of the lua api.

_________________
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com


Top
 Profile  
 
PostPosted: Mon Oct 15, 2018 8:47 am 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 940
Location: cypress, texas
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.


Top
 Profile  
 
PostPosted: Mon Oct 15, 2018 4:46 pm 
Offline

Joined: Sun Feb 07, 2016 6:16 pm
Posts: 530
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 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