Active player (372)
Joined: 9/25/2011
Posts: 652
I'm having some difficulty getting lua scripts to work in JPC-rr. I've used scripts in Fceux before, but it doesn't seem to be working when I take the same commands over to JPC-rr. Are there any basic guides or someone who can provide basic pointers on lua scripting in JPC-rr? Specifically, I'm looking to enter keyboard and mouse commands, save and load states, and do memory inspection. Thanks in advance!
Reviewer, Expert player (2392)
Joined: 5/21/2013
Posts: 414
There's a full list of lua functions available here: http://repo.or.cz/w/jpcrr.git/blob/refs/heads/r11-maint:/datafiles/luakernel There's really never been a guide for lua scripting in JPC-rr, what I did to learn was just look at one of Ilari's scripts and go from there. Looking at this one should help you: http://tasvideos.org/userfiles/info/28795717603126010 The "lock" section of the while loop is for the HUD and runs every frame, and the "message" section is for typing commands into the lua window. Also, the extramenu file in the datafiles folder lists all the menu commands in JPC-rr and should help you figure out the arguments for the jpcrr.sendevent function, which is what you'll need to do keyboard and mouse commands. Look here for a full list of numbers to use with KEYEDGE: http://tasvideos.org/EmulatorResources/JPC/KeyNumbers.html
Active player (372)
Joined: 9/25/2011
Posts: 652
Thanks, slamo! I was able to find functions that will create and load save states, and I think I can figure out the mouse stuff and memory inspection. One thing I couldn't find is a command to do a single frame advance. There's pc_start, but I'm concerned that will start going through many frames instead of just one. Do you know how to just advance one frame at a time?
Reviewer, Expert player (2392)
Joined: 5/21/2013
Posts: 414
Looking at extramenu, it looks like it's just this sequence of commands:
jpcrr.vretrace_start_trap(is_on);
jpcrr.vretrace_end_trap(0);
jpcrr.timed_trap();
jpcrr.pc_start();
Active player (372)
Joined: 9/25/2011
Posts: 652
slamo wrote:
Looking at extramenu, it looks like it's just this sequence of commands:
jpcrr.vretrace_start_trap(is_on);
jpcrr.vretrace_end_trap(0);
jpcrr.timed_trap();
jpcrr.pc_start();
Awesome! Thanks a lot, slamo!
Active player (372)
Joined: 9/25/2011
Posts: 652
c-square wrote:
slamo wrote:
Looking at extramenu, it looks like it's just this sequence of commands:
jpcrr.vretrace_start_trap(is_on);
jpcrr.vretrace_end_trap(0);
jpcrr.timed_trap();
jpcrr.pc_start();
Awesome! Thanks a lot, slamo!
Hi slamo, the one frame increment works. Now I'm trying to create a function that advances a variable number of frames, but it keeps hanging. Any suggestions as to how to make this a variable advance?
Reviewer, Expert player (2392)
Joined: 5/21/2013
Posts: 414
Yeah, it looks like looping the frame advance code doesn't work. I think your best bet is to do this:
jpcrr.vretrace_start_trap();
jpcrr.vretrace_end_trap();
jpcrr.timed_trap(x*y);
jpcrr.pc_start();
This code will advance time by x*y ns, where x should be the number of nanoseconds per frame (will depend on your game's FPS) and y is the number of frames you want to advance.
Active player (372)
Joined: 9/25/2011
Posts: 652
slamo wrote:
Yeah, it looks like looping the frame advance code doesn't work. I think your best bet is to do this:
jpcrr.vretrace_start_trap();
jpcrr.vretrace_end_trap();
jpcrr.timed_trap(x*y);
jpcrr.pc_start();
This code will advance time by x*y ns, where x should be the number of nanoseconds per frame (will depend on your game's FPS) and y is the number of frames you want to advance.
Sweet, that seems to work! I tried something similar, but didn't send nil into start and end trap, and it only ever went a maximum of one frame, no matter how big I made the timed trap. Sending in nils makes it work, though. My first goal is to write a script that performs an optimized boot up so I don't have to do it myself each time. Next step is to see if I can advance x frames, provide some keyboard input and then advance y more frames. Thanks again for your help!! EDIT: Looks like a script already exists: optboot.lua, however it does it in a very different way than I'm trying
Active player (372)
Joined: 9/25/2011
Posts: 652
c-square wrote:
slamo wrote:
Yeah, it looks like looping the frame advance code doesn't work. I think your best bet is to do this:
jpcrr.vretrace_start_trap();
jpcrr.vretrace_end_trap();
jpcrr.timed_trap(x*y);
jpcrr.pc_start();
This code will advance time by x*y ns, where x should be the number of nanoseconds per frame (will depend on your game's FPS) and y is the number of frames you want to advance.
Okay, so that seems to work once, and only once. Once I have advanced X frames, then do something (like press a key on the keyboard), then I can't advance frames again. It just ignores the second frame advance. I've tried creating a sleep function to have it pause between frame advances, but then the second advance just hangs. My code so far:
function sleep(sec)
    for i=1,sec*18000000 do end
end

TimeAdvance = function(numMs)
	jpcrr.vretrace_start_trap(); 
	jpcrr.vretrace_end_trap(); 
	jpcrr.timed_trap(1000000 * numMs); 
	jpcrr.pc_start();
end

print("Testing frame increment")
TimeAdvance(10)
print("sleeping")
sleep(10);
print("waking")
TimeAdvance(10) -- This one hangs JPC-RR
print("Frame increment Complete!")
Any ideas on how to get that second frame advance working?
Active player (372)
Joined: 9/25/2011
Posts: 652
I found the answer to my own question:
while true do
	a, b = jpcrr.wait_event();
	if a == "lock" then
		[Code you want to execute each frame]
		if [optional condition if you want to stop processing] then
			jpcrr.pc_stop()
		end
		jpcrr.release_vga();
	end
end