Posts for HowardC

Experienced Forum User
Joined: 2/5/2014
Posts: 28
With all due respect, these are emulators of home consoles from the 90's and before. At the time, consoles were designed to be ran at one and only one aspect ratio, namely 4:3. Resolution was irrelevant because at this time video going into a tv would be analog and the tv would sync it and stretch it to 4:3. You mention things like broken tvs and differences in televisions, that's defective equipment for one thing and secondly has nothing to do with the aspect ratio. These machines were designed to display on a 4:3 crt television, so the only correct aspect ratio is 4;3, period, end of story. There are complications of course... all analog signals have a certain degree of garbage space to compensate for the differences in the televisions you were talking about. But when all is said and done, you get a 4:3 picture. So you can argue and justify all you want, but again with the upmost of respect, once all compensating and cropping is done, the result is a 4:3 image. That is unless your goal isn't emulation accuracy. You aren't just emulating the digital aspect of the consoles but also the analog aspect, which is how the timing and what-not of an analog tv takes a 240p image or what have you and makes it display as a 4:3 image on screen. You are displaying the correct pixel dimensions, but again, the incorrect aspect ratio.
Experienced Forum User
Joined: 2/5/2014
Posts: 28
I wasn't aware that you guys were working on the video, my bad. It's a lot of pages to read through. I don't know if you guys are taking requests but on the lua end of things it would sure be nice if there was a command to get the rom name. Making universal scripts is difficult because of this. Nothing fancy is needed... shoot just pass the command line along to lua and I'd be happy. I got around not being able to get the file/rom name on the stand-lone emulators via reading the header from the cart, but that isn't an idea solution tbh as the names aren't the same.
Experienced Forum User
Joined: 2/5/2014
Posts: 28
I've noticed more of a global issue, namely the aspect ratios on the 2d games are wrong. While the pixel dimensions of course vary, the aspect of every system except for the portables is supposed to be 4:3. Yet on nes/snes and I'm sure others the screen is too narrow, even in fullscreen mode. Before someone mentions the option that cuts off the garbage pixels, that is stuff that would have normally been in the over-scan area of the tv. The main gameplay area is still supposed to fill a 4:3 crt television.
Post subject: emu.yield() and rendering issues?
Experienced Forum User
Joined: 2/5/2014
Posts: 28
I'm trying to figure out how to properly pause the game while still drawing things to the screen and I'm not having much luck, maybe it's something I'm missing? The idea is this... scan the inputs, when a button is pressed pause the game and bring up a menu. I just can't seem to get things working right. emu.yield() doesn't seem to do anything by itself. I have to include a emu.pause() as well. While paused I can certainly read inputs and text "sort of" updates, but nothing else. I can't render images, and the last frame of the game doesn't seem to render, making any sort of changed text blurr together with the text from the last frame and whatever is left of the gameplay image. I've tried all kinds of stuff, client.paint() to get the game to re-render and maybe show my images, gui.ClearGraphics() to remove the old text ect... nothing works. I also looked at the registers listed in the docs, but unless I misunderstood one is before anything, even the game gets rendered (too soon) and one is after the frame is rendered (too late). Can somebody post an example please? Here is my rather cluttered (from trying various stuff) test script btw...
x=0

while true do
		x=x+1 --Test rendering while paused via constantly changing text
		if x>=100 then x =0 end;
			JOY1=joypad.getimmediate();
			
			if JOY1["P1 Start"]~=false and JOY1["P1 Select"]~=false then
				os.exit();
			end
			gui.text(10,10,"Hello World!");
			gui.text(10,40,x);
			if JOY1["P1 Start"]==true then
				gui.clearGraphics()
				client.paint()
				gui.drawImage("nes.png" , 0 , 8);
				gui.text(10,30,"True");
				client.paint()
				emu.yield()
				client.pause()
				--gui.clearGraphics()
			else
				client.unpause()
				gui.text(10,30,"False");
				emu.frameadvance()
			end
		
	end;
Experienced Forum User
Joined: 2/5/2014
Posts: 28
The only tutorial I could find was the one on the google page and it doesn't actually draw anything to the screen, rather it just shows you how to hook up a code loop. Even then the comments are in Japanese, meaning you only get code and not an explanation of what it's doing. The only example script I could find was a lag counter script on these forums. Now while it DOES draw to the screen, it does it by making the gameplay area larger and drawing in the empty space. That only works in windowed mode unfortunately.
Experienced Forum User
Joined: 2/5/2014
Posts: 28
Thanks for the code. I'm not sure if it's needed though. I probably need to take the delay out of the buttons completely and use that, but the menu navigation needs a de-bounce instead. You want to be able to hold down up/down/whatever to scroll through the menu. It's not super important for gens and snes9x, but the game genie menu in fceux definitely needs it. That's why I was doing each one individually, (and have two calls to the joystick instead of one) but in the end I forgot to remove the delay for the buttons. Oops! :) That's a lot cleaner way of doing it though.
Experienced Forum User
Joined: 2/5/2014
Posts: 28
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.
Post subject: UCDP: Universal Console Dashboard Project.
Experienced Forum User
Joined: 2/5/2014
Posts: 28
All the strange questions I've been asking since I showed up here have been about the UCDP, my little project that uses lua scripting to add basic functionality to a menu accessible via your gamepad. I've made menus for FCEUX, Snes9x-rr and Gens-rr that allow you to load a state, save a state reset the game and exit the emulator via a menu accessable by pressing start+select(or mode in the case of gens). Video Previews and full details can be found on my site: http://dragonking.arcadecontrols.com/static.php?page=AboutUCDP This really covers multiple emulators, but I'm new here and wasn't sure where to post it. If the admins have a better place for it, feel free. Enjoy and thanks to everyone who helped.
Experienced Forum User
Joined: 2/5/2014
Posts: 28
Yeah some Mupen64 lua examples sure would be nice. Just as a test I wanted to paint a rectangle to the screen and no matter if I call my rect via a register function or in a good old "while true do" loop it flickers like crazy. I don't know if this is the fault of my scripting, or a video plugin problem, or a problem with the emulator itself. I can't find any example scripts that draw anything to the gameplay area and the documentation is partially in Japanese!
Experienced Forum User
Joined: 2/5/2014
Posts: 28
Ok this version is slightly improved. I switched to using post message which in theory works better. I also increased the delays slightly. I've found getting these right is crucial to getting the Run button pressed properly. It's a balance really. With a long enough delay it'll work 100% of the time, but how long are you willing to wait?


IniWrite, FALSE, snes9x.cfg, Display\Win, Fullscreen:Enabled ;Ensure fullscreen is off
IniWrite,%2%, snes9x.cfg, Settings\Script, LastScriptFile ;Write to the ini file the lua script name

Run, snes9x.exe "%1%",,, PID ;Launch snes9x
WinWait ahk_pid %PID% ;Wait until emulator loads
sleep, 50
WinMenuSelectItem, ahk_class Snes9X: WndClass, , File, Lua Scripting, New Lua Script Window... ;Open lua dialog box
WinWait ahk_class #32770 ;Wait for the dialog to load

sleep 100



p := 5 << 16 | (5 & 0xffff)

PostMessage, 0x201 , 1, p,Run,Lua Script ; Click down on the Run Button
sleep 100
PostMessage, 0x202 , 1, p,Run,Lua Script
  ;Release the Run Button 
sleep 50

WinMenuSelectItem, ahk_class Snes9X: WndClass, , Config, Video, Full Screen  ;Go to Full Screen mode
WinWaitClose ahk_pid %PID% ;Wait for exit.

IniWrite, FALSE, snes9x.cfg, Display\Win, Fullscreen:Enabled ;Set the fullscreen mode back to false.             
Experienced Forum User
Joined: 2/5/2014
Posts: 28
Yeah it's not perfect though. Sometimes it doesn't quite hit the run button. I think I need to see if I can do that via a post message call, which would work regardless of the mouse. snes9x in general, not just the rr versions needs some work. It hasn't had a major overhaul in years. I think it's being phased out by bsnes and some of the newer ones, but it's a shame because I've been using it for almost a decade now. I'm actually having to use 1.51, because the windows version of 1.52 breaks a bunch of the lua calls. I thought of just submitting new source, but I really don't have the kind of time to setup the compile environment atm and I think the build is sort of dead atm anyway.
Post subject: Here is a ahk script to Launch Snes9xrr with a lua script
Experienced Forum User
Joined: 2/5/2014
Posts: 28
Since you guys have been helping me out so much I thought I better at least post something useful. The following auto hot key script (crudely) will launch snes9xrr, load up the script you specify and go to fullscreen. The command line options are as follows: snes9xlauncher.ahk "c:\path\to\rom\rom.zip" ".\script.lua" The paths MUST be in quotes and there shouldn't be any extra spaces.
IniWrite, FALSE, snes9x.cfg, Display\Win, Fullscreen:Enabled ;Ensure fullscreen is off
IniWrite,%2%, snes9x.cfg, Settings\Script, LastScriptFile ;Write to the ini file the lua script name

Run, snes9x.exe "%1%",,, PID ;Launch snes9x
WinWait ahk_pid %PID% ;Wait until emulator loads
sleep, 50
WinMenuSelectItem, ahk_class Snes9X: WndClass, , File, Lua Scripting, New Lua Script Window... ;Open lua dialog box
WinWait ahk_class #32770 ;Wait for the dialog to load

sleep 50

ControlClick, Run, Lua Script,,,, NA  ;Press the Run Button

 

sleep 50

WinMenuSelectItem, ahk_class Snes9X: WndClass, , Config, Video, Full Screen  ;Go to Full Screen mode

WinWaitClose ahk_pid %PID% ;Wait for exit.

IniWrite, FALSE, snes9x.cfg, Display\Win, Fullscreen:Enabled ;Set the fullscreen mode back to false.
Note that the script is designed to only work if you specify a lua script and the lua path must use lua-style path syntax if you are using a relative path. I hope someone finds this useful, and remember, 1.51 is the last revision of snes9xrr with proper lua implementation.
Experienced Forum User
Joined: 2/5/2014
Posts: 28
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.
Experienced Forum User
Joined: 2/5/2014
Posts: 28
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?
Experienced Forum User
Joined: 2/5/2014
Posts: 28
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.
Experienced Forum User
Joined: 2/5/2014
Posts: 28
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.
Experienced Forum User
Joined: 2/5/2014
Posts: 28
*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....
Post subject: Re: lsnes gui.bitmap_load problems.
Experienced Forum User
Joined: 2/5/2014
Posts: 28
Ilari wrote:
HowardC wrote:
So when I try to call gui.bitmap_load('test.bmp') I get the rather strange error messge of "Wrong Magic" in the prompt. Is the function broken or is it something I'm not doing right?
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.
Post subject: lsnes gui.bitmap_load problems.
Experienced Forum User
Joined: 2/5/2014
Posts: 28
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.
Experienced Forum User
Joined: 2/5/2014
Posts: 28
Hmm... nevermind. The framerate drop was so great that I had to adjust my de-bounce code waaay down. The game was responding, just very slowly. I think I can work with this, thanks a ton!
Experienced Forum User
Joined: 2/5/2014
Posts: 28
Thanks for the code, but unfortunately this looks like a bust anyway. Any calls to gui.text seem to update fine while the game is paused, but absolutely nothing else does. Even with joypad.getimmediate, the gamepad state doesn't update and none of my gdoverlay calls are working. If you have any ideas let me know.
Experienced Forum User
Joined: 2/5/2014
Posts: 28
FatRatKnight wrote:
Here's more inconsistency: FCEUX has a gui.register that runs while emulation is actually paused. DeSmuME also runs that function's code while paused. Snes9x doesn't do that. You'll need to fake a pause, I believe. VBA doesn't either. Don't know about Gens, but you've certainly went through it carefully already. gui.register takes a function as a parameter. The function is to be called whenever the display updates. For some reason, FCEUX's display is updated fairly frequently when emulation is paused. Therefore, you can pause emulation and still have code running. Use emu.pause and emu.unpause as well to get things holding still or going. I'm not sure why the different emulators are all over the map with these functions. Most of them are similar, but there are a few irritating moments. I couldn't port my old Multitrack2 script to VBA at all. EDIT: As a bonus, when I was first messing around with gui.register, the help texts gave no mention of this "run while paused" feature. FCEUX 2.2.1 help still gives no mention of this.
Well darn, I should have checked out this reply first. Note my other post. I'm almost there anyway. Let me ask you this though. Is gui.regster called multiple times per frame? If so then it might hurt performance and/or effect my de-bounce code for navigation.
Post subject: Is there a way to clear the sound buffers in fceux?
Experienced Forum User
Joined: 2/5/2014
Posts: 28
Ok that script I mentioned in another thread is almost there: http://youtu.be/XEpoKYkeupU The one thing I'm having issue with is getting the game to freeze when going into the menu. I'm faking it via creating a temporary save state upon entering the menu and constantly loading it prior to frameadvance() until exiting the menu. (Not shown in this video obviously) That works amazingly well BUT the sound, as you would expect is frozen and keeps playing, similar to a game locking up on a modern console. So is there a way to clear the sound buffers universally? I was thinking maybe using some of the memory functions to clear it, but I'm not sure how to go about it. Thanks.
Experienced Forum User
Joined: 2/5/2014
Posts: 28
Well it solved my issue so thanks on that. I don't mean to argue by I still don't think you guys are getting my point. Yeah these emulators were developed separately, of course. But the lua implementation, that was decided upon by the community and the syntax was purposefully made universal (stuff like fceux.function has been depreciated by emu.function, specifically so that code is universal). So how the emulator handles savestates and what have you is irrelevant. Because when the lua was implemented and modeled specifically after another emulator's lua implementation (I believe in this case snes9xrr) it should have been hooked up in such a way that it worked identically. I'm a programmer I assure you this is possible. Just to use this specific issue as an example: Ok so I need to call savestate.persist first. Why? Why wasn't lua hooked up to automatically do whatever savestate.persist is doing behind the scenes when savestate.load or save is called so that it operates exactly like snes9x or Gens? The authors want to add non-persistant states? Well then make an option for that, don't make persistence the option as it breaks universal scripting support. Remember, lua is "hooked up" to functions native to the emulator. So any differences in the functions, extra stuff that needs done ect, should be handled, internally, not at the scripting level. I've got a gens menu finished, and it's working quite well: http://youtu.be/Fi6g55hfpNw For the most part scripting is fairly consistent between the two, except for the save/load state issues. Now I've got to try and figure out how to fake a pause in FCEUX, because the function available in Gens isn't available in this emulator.
Post subject: Help with input.registerhotkey() attempt to index a functio
Experienced Forum User
Joined: 2/5/2014
Posts: 28
So I've got a standard "while true do" loop setup for this lua script I'm building. Prior to entering the main loop I call a "input.registerhotkey(1,TglMenu)" The TglMenu function is before the register call as per lua specifications. There is absolutely nothing in the TglMenu function.... actually here it is:
function TglMenu()
	if MenuDis>=1 then
		MenuDis=0;
	else
		MenuDis=1;
		sound.clear();
	end
end
As you can see all it is doing is toggling the value of the variable "MenuDis" which in my main loop is used to determine if a menu should be drawn on screen. If you toggle off and on the menu a few times, it doesn't matter how slow... seemingly at random the error "attempt to index a function" will throw and the script exits. Any ideas what could be causing this?