Updated specific locations to be searchable, take a look at Las Vegas as an example.

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

29
An NES emulator: LuaNES
Post Body

Link: https://github.com/nico-abram/LuaNES/

I'm writing an NES emulator in Lua (It's heavily inspired/based on a ruby NES emulator https://github.com/mame/optcarrot ). It's not finished, but it currently it can run almost consistently at 50 FPS (While running mario it usually runs at 49-114 fps) and take input, however, it has no audio yet. I've run a couple test roms, and it passes them. It uses love2d to for input and video output (Though I've managed to also use it inside a rhythm game that embeds luajit, https://github.com/etternagame/etterna ). Currently it's about 5000-6000 lines of code.

I've rushed the process quite a bit, and a lot of the code is probably not particularly nice nor lua-ish. A couple tables use 0 indexing to make it easier (Since a lot of the time it needs to perform bitwise operations on data, and adding one can be confusing), and when i dont sometimes it needs to add 1 right before indexing because the index is the result of a bitwise operation. It uses a pretty basic and probably ugly class utility function (I didn't think using something like middleclass was worth it considering it barely even uses inheritance). As a result, most of the utility functions find out the starting point with "t[0] and 0 or 1" which breaks my soul every time i see it. I promise I'll normalize things eventually. There are also a few utility functions in utils.lua present in ruby that may or may not have a faster, more standard equivalent in lua and I'll replace eventually.

I think luajit should be able to run this *far* better, and I blame it's current performance on myself (And my heavily basing it on a ruby emulator). For reference, mesen, an emulator in C is able to run mario pretty consistently at around 350fps on my machine when uncapped. Any help to try and improve performance is *very* welcome (I've tried profiling using "luajit -jp", "luajit -jp=v" and see tracing output using "luajit -jv". I managed to remove one NYI thanks to -jv output, but I couldn't find many other useful things from their output (Other than a lot of coroutine messages. The NES has 2 components that have different speeds/clock rates (cpu and apu(audio)) and the ppu has a pretty specific order of operation, and some games rely on it. Which is why it uses a coroutine. Could that be what's slowing it down?). The profiler output, with and without "v" (And other flags) hasn't been particularly helpful, mostly because it doesn't seem to be deterministic (I get output that varies every time). I'm not doing anything with random numbers or I/O, so my guess is it might be disk or RAM cache, or some other hardware thing changing things (What was surprising was that even the % of things getting JITted seemed to change randomly)). I also tried replacing a couple array-tables that, according to the profiler output, were related to bottlenecks in most executions with FFI arrays. It didn't have any noticeable impact (FPS felt a bit worse overall).

Also, on audio: If anyone knows a way to stream samples from lua to love2d, and how to encode 8bit or 16bit samples into the -1 to 1 normalized sampling that the setSample love2d audio function seems to need (According to the docs) any help or insight would be much apprecciated.

Is there any lua/luajit discord to ask for help optimizing code?

Does anyone know good tooling to debug/profile love applications?

Does anyone know if love2d uses luajit? (I'm pretty sure it does) Does it have JIT enabled? (I haven't been able to access the jit module, or any luajit specific module for that matter)

Does anyone know good love2d tooling (IDE, debugger, profiler, etc). Currently I'm using vscode, and it works pretty well for formatting/linting/error warnings, but afaik has no love2d specific plugins.

Author
Account Strength
100%
Account Age
8 years
Verified Email
Yes
Verified Flair
No
Total Karma
10,073
Link Karma
786
Comment Karma
9,204
Profile updated: 4 days ago
Posts updated: 6 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
5 years ago