So when I try to call gui.bitmap_load('test.bmp') I get the rather strange error messge of "Wrong Magic" in the prompt.
I've tried various things, like including a full path or what have you and nothing seems to work.
Is the function broken or is it something I'm not doing right?
Also sort of off-topic but is there a way to load lua scripts in snes9x via the command line? I abandoned working on scripts for it because of this reason.
The format isn't BMP but something weird. Use the PNG versions (*load_png / *load_png_str) and have the bitmap as a PNG.
Note, the *load_png_str function eats BASE64 encoding of PNG, not PNG itself.
Ok that'll work. I guess I need to be looking at the function list inside the manual.txt
instead of the list here on the site, because those functions aren't listed at all.
*sigh*
Loading the pngs works just fine, I actually prefer that, but now I've hit yet another bump in the road.
Maybe I'm missing something obvious again, but I can't get the emulator to launch via a command line.
I tried lsnes-wxwidgets.exe --rom="c:\roms\Star Fox (USA).zip" and the command prompt sits there for a second then the emulator flashes on the screen and disappears.
I've tried several variants including removing the quotes, putting the rom in the lsnes folder and using a relative path, ect....
I tried lsnes-wxwidgets.exe --rom="c:\roms\Star Fox (USA).zip" and the command prompt sits there for a second then the emulator flashes on the screen and disappears.
You are trying to load the .zip as ROM, not a ROM file inside it.
lsnes-wxwidgets.exe --rom="c:\roms\Star Fox (USA).zip/Star Fox (USA).smc" or something like that (not sure about name of the file inside the .ZIP) should work.
And apparently lsnes will bomb with error message printed to console (no dialog) if one gives --rom, but it can't be loaded for some reason (edit: Fixed in last dev revision).
Well that got rid of the error, but it still isn't working properly. I couldn't get the extra switch to work so I just extracted the rom.
It sets the rom path, but it doesn't load it, I have to start the emulator manually via the menu.
Also if I add a --lua=test.lua to the command line, it crashes.
It sets the rom path, but it doesn't load it, I have to start the emulator manually via the menu.
What happens if you just unpause? "No signal" remains (no ROM loaded) or the game starts (ROM loaded)?
Lua script can trigger unpause by:
Language: lua
exec("unpause-emulator");
HowardC wrote:
Also if I add a --lua=test.lua to the command line, it crashes.
And the same script doesn't crash if started from the UI?
I think the cause is that Lua scripts started from commandline start up while emulator is still starting up and in who knows what state, so many operations just crash.
Yeah, should be fixed so that Lua scripts are not executed until emulator has finished starting up (the last step is loading a movie file). (Edit: Done in latest dev revision).
There is function named emulator_ready(). If it returns false, wait for call to on_startup before doing any more complicated initialization.
Adding callbacks is safe, since that is just writing functions into variables.
One way to do this is:
Language: lua
on_startup = function()
<startup code here...>
end
if emulator_ready() then on_startup(); end
Thanks for the tips, I'll mess with this sometime this evening and get back to you.
Honestly though this sort of thing is getting tedious. The idea was to write lua scripts to do menus instead of changing the source code so they would be future-proofed (I don't have to maintain a custom build) but at this stage I'm wondering if it wouldn't have made more sense to update all of the emulators with menu code.
I was looking at BizHawk... the scripting is much improved, but I'm not seeing a way to launch lua scripts from the command line.
Well it looks like the lua stuff is borked on this emulator as well.
What you suggested didn't work, that just made the code launch well before the rom was loaded. An infinite loop didn't work either, it didn't give the emulator time to breath and thus froze everything up.
What eventually worked was this highly convoluted script:
local X=0
BMTest=gui.bitmap_load_png("test.png")
function StartUp()
--need a function to set to full screen
end
function on_paint()
if X<100 then X=X+1 end;
gui.text(15,12,X)
gui.bitmap_draw(1, 1, BMTest);
end
function on_timer()
exec("unpause-emulator");
if X<100 then
set_timer_timeout(1000);
else
StartUp();
end
end
if emulator_ready() then
exec("unpause-emulator");
gui.repaint();
end
exec("unpause-emulator");
set_timer_timeout(1000)
I've still got problems though, namely I guess this emulator doesn't have a fullscreen mode?
What you suggested didn't work, that just made the code launch well before the rom was loaded.
Ah, unpausing there won't work, because on_startup is run before pause/unpause is initialized.
Fixed in latest dev revision.
Also, the screen can update even when paused: Call gui.repaint() to request on_paint() to happen after current callback finishes (I tried requesting a repaint from startup, worked).
Also, it is possible to get a keypress callback (including from physical gamepad).
HowardC wrote:
I've still got problems though, namely I guess this emulator doesn't have a fullscreen mode?
Dev versions do have fullscreen. But it is not enterable from Lua. Only from command line in very latest dev revisions.
I'm currently doing binary build of very bleeding edge dev version...
Yeah it was acting weird regardless. You'll notice in addition to my timer I've got two additional unpause calls in there.
It seems like one frame needed to be rendered before any of the calls even worked and strangely enough the png would render well before the rom loaded (putting the script in motion) but only if I unpaused the non-existant rom first.
So I'm not sure what that was all about.
I appreciate all the help btw.
It seems like one frame needed to be rendered before any of the calls even worked and strangely enough the png would render well before the rom loaded (putting the script in motion) but only if I unpaused the non-existant rom first.
Ugh, the dev versions have a bug, where painting when paused does not work. Fixed.
I uploaded a build to: http://ilari.tasvideos.org/lsnes-rrtest.7z
This works on both latest stable (including on "no signal" screen) and in latest dev revision (including on "no rom loaded" and ROM cover screens).
Language: lua
keystates = {}
keyorder = {};
on_paint = function()
local y = 0;
for k,v in ipairs(keyorder) do
gui.text(0, y, v, 0xFF8000, 0x80000000);
gui.text(240, y, string.format("%6d", keystates[v]), 0xFF8000, 0x80000000);
y = y + 16;
end
end
on_keyhook = function(name, value)
local val;
if value.value then val = value.value; else val = value.last_rawval; end
keystates[name] = val;
gui.repaint();
end
on_startup = function()
keys = {};
local t = input.raw();
for key,val in pairs(t) do
if string.sub(key, 1, 8) == "joystick" then
print(key);
input.keyhook(key, true);
local val2;
if val.value then val2 = val.value; else val2 = val.last_rawval; end
keystates[key] = val2;
table.insert(keyorder, key);
end
end
gui.repaint();
table.sort(keyorder);
end
if emulator_ready() then
on_startup();
end
Hmm... Perhaps Lua function to load the screenshot off savestate file would be useful...
Sorry I had been busy.
With your new exe and script I still have to put a exec("unpause-emulator") in there to start the thing. Mind you I don't have to do a loop now, which is a big improvement, but I've never seen an emulator that doesn't offer a command line option to start the game.
Also just for the record, fullscreen doesn't work. All it does is remove the menu and put the gameplay area in the top-left corner of the desktop.
Yeah being able to access the embedded snapshot would be nice.