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". For the API, so far I've got this roughly planned:
Code: Select all
//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