Lua scripting support in emulators

You can talk about almost anything that you want to on this board.

Moderator: Moderators

User avatar
miau
Posts: 189
Joined: Mon Nov 06, 2006 9:34 am
Location: Potsdam, Germany
Contact:

Lua scripting support in emulators

Post by miau »

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
Bananmos
Posts: 551
Joined: Wed Mar 09, 2005 9:08 am
Contact:

Post by Bananmos »

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!
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

I wonder how efficient a Lua interpreter for the NES itself could be. There are plenty of BASIC interpreters for NES-class hardware.
User avatar
Memblers
Site Admin
Posts: 3901
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers »

That's the first I've heard of any of this. It does sound good for debugging.

Nice videos, the laser eyes were cool.
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

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.
User avatar
Dwedit
Posts: 4470
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit »

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.
I was considering doing something like this for a Zelda Oracle of Ages Level Editor...
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
miau
Posts: 189
Joined: Mon Nov 06, 2006 9:34 am
Location: Potsdam, Germany
Contact:

Post by miau »

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.

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.
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.
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.
User avatar
Hamtaro126
Posts: 783
Joined: Thu Jan 19, 2006 5:08 pm

Post by Hamtaro126 »

tepples wrote:There are plenty of BASIC interpreters for NES-class hardware.
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 concept
frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

wow.. that mario hack turns it into a whole new game!
User avatar
miau
Posts: 189
Joined: Mon Nov 06, 2006 9:34 am
Location: Potsdam, Germany
Contact:

Post by miau »

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.
Xkeeper
Posts: 90
Joined: Fri Feb 29, 2008 10:35 am

Post by Xkeeper »

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".
strat
Posts: 396
Joined: Mon Apr 07, 2008 6:08 pm
Location: Missouri

Post by strat »

Just to clear things up, is this Lua scripting executed over the ROM, so it would be more like modifying the system instead of the ROM itself?
User avatar
miau
Posts: 189
Joined: Mon Nov 06, 2006 9:34 am
Location: Potsdam, Germany
Contact:

Post by miau »

Exactly. Lua acts as a second independent PPU and processor that has access to the original processor's memory space.

There's no way (yet?) to modify rom contents from within Lua.
strat
Posts: 396
Joined: Mon Apr 07, 2008 6:08 pm
Location: Missouri

Post by strat »

Heeey, could this be used to rapidly prototype an original NES game?
User avatar
Jeroen
Posts: 1048
Joined: Tue Jul 03, 2007 1:49 pm

Post by Jeroen »

Not really. Suppose it could be used as some debug tools. Unless theres something i'm not thinking of
Post Reply