Post subject: Using FCEUX to log memory variable over time?
Joined: 2/15/2015
Posts: 2
Location: Danmark
Hi, Watching Double Fine's video on how to hack Zelda, I thought it would be interesting to try out. I think I have found Mario's X velocity in Super Mario Bros. I want to log this data over time, so I can see how his speed changes (going from idle to walking to running). However, I am unsure how to do this. I have tried the various debug and tracing options, but I am a bit confused how to specify the program to only look at a single memory address and its value. It would be nice to log this value and see how it changes for each frame. How do I do this? Thanks :)
Site Admin, Skilled player (1254)
Joined: 4/17/2010
Posts: 11478
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.
Joined: 2/15/2015
Posts: 2
Location: Danmark
Thank you very much. I ended up with this code, which works fine for my purpose :)
require("x_functions");

marioXspeed = 0x0057;

marioyspeed			= memory.readbytesigned(0x009F);
marioxpos			= memory.readbyte(0x4AC);
marioypos			= memory.readbyte(0x4AD);

LogFile = io.open('SuperMarioBros_horizontal_log.txt','w');

s = 0;
FCEU.frameadvance();

while (true) do
  joyput = joypad.read(1);
  s = s+1;

  frame = FCEU.framecount();

  isPressingButton = 0;

if (joyput['left'] or joyput['right']) then
	isPressingButton = 1;
end;

  speedX = memory.readbytesigned(marioXspeed);

  outs = string.format('%d, %d, %d\n', isPressingButton, frame, speedX);

  LogFile:write(outs);  

  FCEU.frameadvance();

end;
print('done');
print(s);


LogFile:close();