gpt4 book ai didi

lua - 如何在 Lua 中从 FCEUX 获取 PPU 内存?

转载 作者:行者123 更新时间:2023-12-02 00:48:26 24 4
gpt4 key购买 nike

我不确定这是否适合这个社区,但我想我会试一试。

FCEUX是一个令人惊叹的 NES 模拟器,它具有丰富的调试工具。它还为用户提供了运行有权访问 various emulator functions 的 Lua 脚本的能力。 .但是,我似乎无法弄清楚如何访问 PPU memory的 NES。它提供对 CPU memory 的直接访问和 ROM 数据,但似乎无法直接访问 PPU 内存。由于 NES 使用 memory-mapped I/O ,理论上可以从特殊的 CPU 内存地址获取数据,但这看起来很麻烦,而且可能会干扰仿真。

有谁知道通过 FCEUX 的 Lua API 以编程方式提取 PPU 内存的方法吗?如果没有,有谁知道有一个模拟器具有以编程方式提取 PPU 内存的 API?

最佳答案

这是我使用的:

function memory.readbyteppu(a)
memory.writebyte(0x2001,0x00) -- Turn off rendering
memory.readbyte(0x2002) -- PPUSTATUS (reset address latch)
memory.writebyte(0x2006,math.floor(a/0x100)) -- PPUADDR high byte
memory.writebyte(0x2006,a % 0x100) -- PPUADDR low byte
if a < 0x3f00 then
dummy=memory.readbyte(0x2007) -- PPUDATA (discard contents of internal buffer if not reading palette area)
end
ret=memory.readbyte(0x2007) -- PPUDATA
memory.writebyte(0x2001,0x1e) -- Turn on rendering
return ret
end

function memory.readbytesppu(a,l)
memory.writebyte(0x2001,0x00) -- Turn off rendering
local ret
local i
ret=""
for i=0,l-1 do
memory.readbyte(0x2002) -- PPUSTATUS (reset address latch)
memory.writebyte(0x2006,math.floor((a+i)/0x100)) -- PPUADDR high byte
memory.writebyte(0x2006,(a+i) % 0x100) -- PPUADDR low byte
if (a+i) < 0x3f00 then
dummy=memory.readbyte(0x2007) -- PPUDATA (discard contents of internal buffer if not reading palette area)
end
ret=ret..string.char(memory.readbyte(0x2007)) -- PPUDATA
end
memory.writebyte(0x2001,0x1e) -- Turn on rendering
return ret
end


function memory.writebyteppu(a,v)
memory.writebyte(0x2001,0x00) -- Turn off rendering
memory.readbyte(0x2002) -- PPUSTATUS (reset address latch)
memory.writebyte(0x2006,math.floor(a/0x100)) -- PPUADDR high byte
memory.writebyte(0x2006,a % 0x100) -- PPUADDR low byte
memory.writebyte(0x2007,v) -- PPUDATA
memory.writebyte(0x2001,0x1e) -- Turn on rendering
end

function memory.writebytesppu(a,str)
memory.writebyte(0x2001,0x00) -- Turn off rendering

local i
for i = 0, #str-1 do
memory.readbyte(0x2002) -- PPUSTATUS (reset address latch)
memory.writebyte(0x2006,math.floor((a+i)/0x100)) -- PPUADDR high byte
memory.writebyte(0x2006,(a+i) % 0x100) -- PPUADDR low byte
memory.writebyte(0x2007,string.byte(str,i+1)) -- PPUDATA
end

memory.writebyte(0x2001,0x1e) -- Turn on rendering
end

在 2.2.3 中,它似乎不适用于旧的 PPU 内核,但在 2.2.2 中可以。适用于两个版本的新 ppu 内核。

关于lua - 如何在 Lua 中从 FCEUX 获取 PPU 内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41954718/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com