-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfceuxppudump.lua
54 lines (48 loc) · 2.03 KB
/
fceuxppudump.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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