# cam.lua -rw-r--r-- 2.7 KiB View raw
                                                                                
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
-- Port of Salanewt's DD camera control AR code to Bizhawk Lua
-- https://docs.google.com/document/d/1gdVf59_w6COzJI6VI2dPqctewHCdcx8eh6DRWrlN5Xg/edit

local function write_words(ptr, xs)
        for i, x in ipairs(xs) do
                memory.write_u32_le(ptr+(i-1)*4, x, "Main RAM")
        end
end
local function write_nops(ptr, n)
        for i = 0, n-1 do
                memory.write_u32_le(ptr+i*4, 0, "Main RAM")
        end
end
local function increment(ptr, delta)
        local x = memory.read_u32_le(ptr, "Main RAM")
        memory.write_u32_le(ptr, x + delta, "Main RAM")
end

local P = 0x142D18
local Delta = 2408

while true do
        local btns = joypad.get();
        if btns.Select and btns.Start then -- Restore default camera
                write_words(P, {0xE8850005, 0xE5851008, 0xE5858018, 0xE585701C, 0xE5853020})
        elseif btns.Select and btns.A then -- Move Left
                write_nops(P, 5)
                increment(0x079304, -Delta)
                increment(0x0792E8, -Delta)
        elseif btns.Select and btns.B then -- Move Right
                write_nops(P, 5)
                increment(0x079304, Delta)
                increment(0x0792E8, Delta)
        elseif btns.Start and btns.B then -- Move South
                write_nops(P, 5)
                increment(0x07930C, Delta)
                increment(0x0792F0, Delta)
        elseif btns.Start and btns.A then -- Move North
                write_nops(P, 5)
                increment(0x07930C, -Delta)
                increment(0x0792F0, -Delta)
        elseif btns.Start and btns.L then -- Move Up
                write_nops(P, 5)
                increment(0x079308, Delta)
                increment(0x0792EC, Delta)
        elseif btns.Start and btns.R then -- Move Down
                write_nops(P, 5)
                increment(0x079308, -Delta)
                increment(0x0792EC, -Delta)
        elseif btns.A and btns.L then -- Rotate Left Only
                write_nops(P, 5)
                increment(0x0792EC, Delta)
        elseif btns.A and btns.R then -- Rotate Right Only
                write_nops(P, 5)
                increment(0x0792EC, -Delta)
        elseif btns.B and btns.L then -- Rotate North Only
                write_nops(P, 5)
                increment(0x0792F4, -Delta)
        elseif btns.B and btns.R then -- Rotate South Only
                write_nops(P, 5)
                increment(0x0792F4, Delta)
        elseif btns.Select and btns.L then -- Rotate Up Only
                write_nops(P, 5)
                increment(0x0792F0, -Delta)
        elseif btns.Select and btns.R then -- Rotate Down Only
                write_nops(P, 5)
                increment(0x0792F0, -Delta)
        end
        emu.frameadvance()
end