Skip to content

Commit 3a6f75f

Browse files
committed
Use pointer addresses for Metroid Prime (Fixes #8)
1 parent 63ef4ca commit 3a6f75f

File tree

2 files changed

+42
-34
lines changed

2 files changed

+42
-34
lines changed

source/modules/games/GM8E01-0.lua

+21-17
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,38 @@ local game = {
66
memorymap = {}
77
}
88

9-
local controllers = {
10-
[1] = 0x807A55A4 + 0xC * 0,
11-
[2] = 0x807A55A4 + 0xC * 1,
12-
[3] = 0x807A55A4 + 0xC * 2,
13-
[4] = 0x807A55A4 + 0xC * 3,
14-
}
9+
-- Pointer to where some struct is stored that contains the controller data..
10+
local game_data_loc = 0x804576FC
1511

1612
local controller_struct = {
17-
[0x0] = { type = "short", name = "controller.%d.buttons.pressed" },
18-
[0x2] = { type = "sbyte", name = "controller.%d.joystick.x" },
19-
[0x3] = { type = "sbyte", name = "controller.%d.joystick.y" },
20-
[0x4] = { type = "sbyte", name = "controller.%d.cstick.x" },
21-
[0x5] = { type = "sbyte", name = "controller.%d.cstick.y" },
22-
[0x6] = { type = "byte", name = "controller.%d.analog.l" },
23-
[0x7] = { type = "byte", name = "controller.%d.analog.r" },
24-
[0xA] = { type = "byte", name = "controller.%d.plugged" },
13+
[0x0] = { type = "short", name = "%d.buttons.pressed" },
14+
[0x2] = { type = "sbyte", name = "%d.joystick.x" },
15+
[0x3] = { type = "sbyte", name = "%d.joystick.y" },
16+
[0x4] = { type = "sbyte", name = "%d.cstick.x" },
17+
[0x5] = { type = "sbyte", name = "%d.cstick.y" },
18+
[0x6] = { type = "byte", name = "%d.analog.l" },
19+
[0x7] = { type = "byte", name = "%d.analog.r" },
20+
[0xA] = { type = "byte", name = "%d.plugged" },
21+
}
22+
23+
local controller_ptr = {
24+
type = "pointer",
25+
name = "controller",
26+
struct = {}
2527
}
2628

27-
for port, address in ipairs(controllers) do
29+
for i=1,4 do
2830
for offset, info in pairs(controller_struct) do
29-
game.memorymap[address + offset] = {
31+
controller_ptr.struct[0x04 + (0xC * (i-1)) + offset] = {
3032
type = info.type,
3133
debug = info.debug,
32-
name = info.name:format(port),
34+
name = info.name:format(i),
3335
}
3436
end
3537
end
3638

39+
game.memorymap[game_data_loc] = controller_ptr
40+
3741
game.translateAxis = core.translateAxis
3842
game.translateTriggers = core.translateTriggers
3943

source/modules/games/GM8E01-2.lua

+21-17
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,38 @@ local game = {
66
memorymap = {}
77
}
88

9-
local controllers = {
10-
[1] = 0x807A6864 + 0xC * 0,
11-
[2] = 0x807A6864 + 0xC * 1,
12-
[3] = 0x807A6864 + 0xC * 2,
13-
[4] = 0x807A6864 + 0xC * 3,
14-
}
9+
-- Pointer to a struct that contains the controller data
10+
local game_data_loc = 0x8045875C
1511

1612
local controller_struct = {
17-
[0x0] = { type = "short", name = "controller.%d.buttons.pressed" },
18-
[0x2] = { type = "sbyte", name = "controller.%d.joystick.x" },
19-
[0x3] = { type = "sbyte", name = "controller.%d.joystick.y" },
20-
[0x4] = { type = "sbyte", name = "controller.%d.cstick.x" },
21-
[0x5] = { type = "sbyte", name = "controller.%d.cstick.y" },
22-
[0x6] = { type = "byte", name = "controller.%d.analog.l" },
23-
[0x7] = { type = "byte", name = "controller.%d.analog.r" },
24-
[0xA] = { type = "byte", name = "controller.%d.plugged" },
13+
[0x0] = { type = "short", name = "%d.buttons.pressed" },
14+
[0x2] = { type = "sbyte", name = "%d.joystick.x" },
15+
[0x3] = { type = "sbyte", name = "%d.joystick.y" },
16+
[0x4] = { type = "sbyte", name = "%d.cstick.x" },
17+
[0x5] = { type = "sbyte", name = "%d.cstick.y" },
18+
[0x6] = { type = "byte", name = "%d.analog.l" },
19+
[0x7] = { type = "byte", name = "%d.analog.r" },
20+
[0xA] = { type = "byte", name = "%d.plugged" },
21+
}
22+
23+
local controller_ptr = {
24+
type = "pointer",
25+
name = "controller",
26+
struct = {}
2527
}
2628

27-
for port, address in ipairs(controllers) do
29+
for i=1,4 do
2830
for offset, info in pairs(controller_struct) do
29-
game.memorymap[address + offset] = {
31+
controller_ptr.struct[0x04 + (0xC * (i-1)) + offset] = {
3032
type = info.type,
3133
debug = info.debug,
32-
name = info.name:format(port),
34+
name = info.name:format(i),
3335
}
3436
end
3537
end
3638

39+
game.memorymap[game_data_loc] = controller_ptr
40+
3741
game.translateAxis = core.translateAxis
3842
game.translateTriggers = core.translateTriggers
3943

0 commit comments

Comments
 (0)