Lua scripting support in emulators
Moderator: Moderators
Lua scripting support in emulators
Unfortunately, I haven't been following emulator development much for the past few months. I was excited when I heard that FCEUX, Snes9x and Gens now have a Lua scripting interface.
This means you can write custom scripts running alongside a rom. They can read and modify ram contents and draw additional stuff on screen.
It really came in handy when debugging my game, I wrote a script that printed all game objects' important variables at their actual position on screen. Far more convenient than browsing through FCEUX's hex editor.
That's just one of Lua's many possible applications, though.
After that, I quickly decided to suspend work on my game project and instead delve into Lua a bit more. What I've come up with since isn't nearly as practical, but... see for yourself.
Super Mario Bros 3. Rainbow Riding
Mega Man 2 LASER EYES
F-Zero SNES + Wii Wheel
Gradius goes bullet hell
This means you can write custom scripts running alongside a rom. They can read and modify ram contents and draw additional stuff on screen.
It really came in handy when debugging my game, I wrote a script that printed all game objects' important variables at their actual position on screen. Far more convenient than browsing through FCEUX's hex editor.
That's just one of Lua's many possible applications, though.
After that, I quickly decided to suspend work on my game project and instead delve into Lua a bit more. What I've come up with since isn't nearly as practical, but... see for yourself.
Super Mario Bros 3. Rainbow Riding
Mega Man 2 LASER EYES
F-Zero SNES + Wii Wheel
Gradius goes bullet hell
Wow, this is just hilarious to watch! I really look forward to trying these crazy "ROM script hacks" (we need a new name for them, don't we?) out!
I've been prototyping my puzzle game intended for the NES in Python due to the complicated algorithms I've been needing to try out in a more debug-friendly environment. But after reading this post, I really think I'll switch to using Lua and FCEUX instead! Besides, Lua is being used at my new work, so I'll probably need to learn it sooner or later anyway. :)
The idea of integrating a high-level language into a NES emulator has always intrigued me, and It's awesome that it's finally happened!
I've been prototyping my puzzle game intended for the NES in Python due to the complicated algorithms I've been needing to try out in a more debug-friendly environment. But after reading this post, I really think I'll switch to using Lua and FCEUX instead! Besides, Lua is being used at my new work, so I'll probably need to learn it sooner or later anyway. :)
The idea of integrating a high-level language into a NES emulator has always intrigued me, and It's awesome that it's finally happened!
Yeah, I loved the SMB3 hack to turn it into a Kirby DS-like game. I haven't looked at your implementation (if you've even posted it). It'd be neat to have an emulator that you could use as a subordinate for making a super game hack. It would allow you to run frames and routines individually, put breakpoints where you get control back so the script can do whatever it likes. The breakpoints could go beyond mere program counter, with things like certain register values, values in memory, etc.
I was considering doing something like this for a Zelda Oracle of Ages Level Editor...blargg wrote:Yeah, I loved the SMB3 hack to turn it into a Kirby DS-like game. I haven't looked at your implementation (if you've even posted it). It'd be neat to have an emulator that you could use as a subordinate for making a super game hack. It would allow you to run frames and routines individually, put breakpoints where you get control back so the script can do whatever it likes. The breakpoints could go beyond mere program counter, with things like certain register values, values in memory, etc.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
Apparently you can at least intercept writes to memory in FCEUX by declaring a hooking function and telling the emulator about it.
It's still buggy, but hopefully they'll fix it in the next official version.
That would increase debugging possibilities even more.
But yeah, more advanced breakpoint capabilities would be even cooler!
Got some cleaning up to do on the code of these scripts, probably releasing them when the new version of FCEUX is out.
However, relatively small and fast could easily become ridiculously HUGE and "might as well go and make coffee until this hello world script has finished execution" when applied to the NES.
It would be a neat proof-of-concept, though.
It's still buggy, but hopefully they'll fix it in the next official version.
That would increase debugging possibilities even more.
But yeah, more advanced breakpoint capabilities would be even cooler!
Got some cleaning up to do on the code of these scripts, probably releasing them when the new version of FCEUX is out.
Yeah, Lua is popular for having a relatively small memory footprint and fast code execution since it translates the script into tight byte-code which it then interprets.tepples wrote:I wonder how efficient a Lua interpreter for the NES itself could be. There are plenty of BASIC interpreters for NES-class hardware.
However, relatively small and fast could easily become ridiculously HUGE and "might as well go and make coffee until this hello world script has finished execution" when applied to the NES.
It would be a neat proof-of-concept, though.
- Hamtaro126
- Posts: 783
- Joined: Thu Jan 19, 2006 5:08 pm
Wrong! There are 2 of them, Family Basic is too limited, and the problem with the BASIC interperter (NBasic/NESASM) we have now is the incompatibility with the real NES. I wish a new compiler comes, like a Batari basic for NES. Although not compatible with Atari, Containing PPU and APU constants instead of TIA constants (http://bataribasic.com/) but this is a concepttepples wrote:There are plenty of BASIC interpreters for NES-class hardware.
FCEUX 2.1 has been released yesterday. It comes with a variety of fun and interesting Lua scripts including those I've posted videos of.
It also has a documentation on Lua scripting and a list of functions now.
It also has a documentation on Lua scripting and a list of functions now.
http://www.youtube.com/watch?v=NnZz5A9Z6A8
This is mine.
Debugging features are fairly limited, though, but it's really useful for making sense of RAM addresses quickly or giving visual feedback that isn't "87".
This is mine.
Debugging features are fairly limited, though, but it's really useful for making sense of RAM addresses quickly or giving visual feedback that isn't "87".