nesdev.com
http://forums.nesdev.com/

Lua Scripting (Mesen)
http://forums.nesdev.com/viewtopic.php?f=3&t=16399
Page 2 of 2

Author:  Sour [ Fri Aug 25, 2017 5:17 pm ]
Post subject:  Re: Lua Scripting (Mesen)

Got most of it working now - just a matter of implementing the API at this point.
Here's what it looks like in the UI. It's possible to have multiple script windows open, each running in their own independent "sandbox".
Attachment:
scriptwindow.png
scriptwindow.png [ 63.54 KiB | Viewed 305 times ]

For the API, so far I've got this roughly planned:
Code:
//read/write have side-effects, debugRead/debugWrite have none.
//Allows you to read all kinds of memory (cpu, ppu, chr rom/ram, prg rom/ram, oam, etc.)
emu.read(address, type): int
emu.write(address, value, type): void
emu.debugRead(address, type): int
emu.debugWrite(address, value, type): void

//The "state" object should contain most of what is important about the emulator's state
//CPU, PPU, APU & Cartridge
emu.getState(): table
emu.setState(state: table): void

//Callbacks for read/write/exec and events like nmi, irq, reset, start of frame, end of frame
//The bulk of a script's code will need to be in these callbacks
emu.addMemoryCallback(func, type, start, end): void
emu.removeMemoryCallback(func, type, start, end): void
emu.addEventCallback(func, eventtype): void
emu.removeEventCallback(func, eventtype): void

//Drawing-related
emu.drawString(x, y, string, color, frameCount): void
emu.drawLine(x, y, x2, y2, color, frameCount): void
emu.drawRectangle(x, y, width, height, color, fill, frameCount): void
emu.getPixel(x, y): int
emu.setPixel(x, y, color): void
emu.getMousePosition(): table [x, y]

//Logging
emu.log(message: string): void  //Log to LUA-specific console
emu.displayMessage(message: string): void  //Print via OSD

//Cheats
emu.addCheatCode(cheat: string, type: enum): void
emu.clearCheatCodes(): void

//Input
emu.getInput(port: int): table [a,b,start,select,up,down,left,right]
emu.setInput(port: int, state: table, durationInFrames: int): void

//Controlling the emulation
emu.reset(hardReset: bool): void
emu.break(): void
emu.resume(): void
emu.execute(cycleCount: int, type: int): void
emu.rewind(seconds: int): void

//Screenshots, savestates
emu.takeScreenshot(): string (png)
emu.saveSavestate(): string
emu.loadSavestate(state: string): void

Some stuff is definitely missing, but I think it's a decent start. If you see anything critical missing, or something terribly bad, let me know.

Author:  dullahan [ Fri Aug 25, 2017 7:11 pm ]
Post subject:  Re: Lua Scripting (Mesen)

I am excited for this, thx for your work Sour!

Author:  Sour [ Sun Aug 27, 2017 3:32 pm ]
Post subject:  Re: Lua Scripting (Mesen)

Almost finished implementing the API - pretty much everything except setState/setInput is done.
As a test, I decided to try porting feos' SoundDisplay2.lua script from FCEUX and it pretty much works:
Attachment:
sounddisplay2.png
sounddisplay2.png [ 81.8 KiB | Viewed 235 times ]
I used the exact same font/draw logic as FCEUX for the drawString function, so it makes it easier to port something like this over.

Author:  tepples [ Sun Aug 27, 2017 6:00 pm ]
Post subject:  Re: Lua Scripting (Mesen)

Sour wrote:
I used the exact same font/draw logic as FCEUX for the drawString function, so it makes it easier to port something like this over.

In "Triangle", the raised "g" looks distracting. Would it be worth sacrificing one pixel of the capital letters' height to make the descenders look less off-kilter?

Attachments:
BaseSeven_vx8.png
BaseSeven_vx8.png [ 1.12 KiB | Viewed 212 times ]

Author:  Sour [ Sun Aug 27, 2017 6:59 pm ]
Post subject:  Re: Lua Scripting (Mesen)

Good point - since I'm not actually restricted by a grid, I cheated and added some code to manually offset some of the characters.
Moved down g/y/p/q & increased the height of the p/q characters (the bottom part seemed too short otherwise)
The background color isn't shifted since that would look odd in most scenarios.
Attachment:
font.png
font.png [ 3.09 KiB | Viewed 203 times ]

Page 2 of 2 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/