fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

BkacjiosAdded support for Super Smash Bros. Brawl (PAL v1.0, v1.1, v1.2) (#122) Simplified our game loader core library a bit. If we don't assign a translateCStick function to our game, just use the games translateJoyStick function instead.ffa28d1

v2.1.6
2.2 KiB83 linesraw
1-- Super Smash Bros. Brawl (NTSC v1.01)
2
3local core = require("games.core")
4
5local game = core.newGame()
6
7--[[
8Brawl seems to have 4 addresses dedicated to controller input values, each address polling around 15fps.
9If you poll all four addresses for the controller values, you get 60fps input!
10
11Structure:
12	Polling Address 1 [0x805BA480]
13		Port 1 [0x805BA480 + 0x40 * 0]
14		Port 2 [0x805BA480 + 0x40 * 1]
15		Port 3 [0x805BA480 + 0x40 * 2]
16		Port 4 [0x805BA480 + 0x40 * 3]
17	Polling Address 2 [0x805BA680]
18		Port 1 [0x805BA680 + 0x40 * 0]
19		Port 2 [0x805BA680 + 0x40 * 1]
20		Port 3 [0x805BA680 + 0x40 * 2]
21		Port 4 [0x805BA680 + 0x40 * 3]
22	Polling Address 3 [0x805BA880]
23		Port 1 [0x805BA880 + 0x40 * 0]
24		Port 2 [0x805BA880 + 0x40 * 1]
25		Port 3 [0x805BA880 + 0x40 * 2]
26		Port 4 [0x805BA880 + 0x40 * 3]
27	Polling Address 4 [0x805BAA80]
28		Port 1 [0x805BAA80 + 0x40 * 0]
29		Port 2 [0x805BAA80 + 0x40 * 1]
30		Port 3 [0x805BAA80 + 0x40 * 2]
31		Port 4 [0x805BAA80 + 0x40 * 3]
32]]
33
34local polling_addresses = {
35	0x805BA480,
36	0x805BA680,
37	0x805BA880,
38	0x805BAA80,
39}
40
41local controllers = {
42	[1] = 0x40 * 0,
43	[2] = 0x40 * 1,
44	[3] = 0x40 * 2,
45	[4] = 0x40 * 3,
46}
47
48local controller_struct = {
49	[0x04] = { type = "int",	name = "controller.%d.buttons.pressed" },
50	[0x34] = { type = "sbyte",	name = "controller.%d.joystick.x" },
51	[0x35] = { type = "sbyte",	name = "controller.%d.joystick.y" },
52	[0x36] = { type = "sbyte",	name = "controller.%d.cstick.x" },
53	[0x37] = { type = "sbyte",	name = "controller.%d.cstick.y" },
54	[0x38] = { type = "byte",	name = "controller.%d.analog.l" },
55	[0x39] = { type = "byte",	name = "controller.%d.analog.r" },
56	[0x3C] = { type = "byte",	name = "controller.%d.plugged" },
57}
58
59for _, polling_addr in ipairs(polling_addresses) do
60	-- For every polling address..
61	for port, controller_addr in ipairs(controllers) do
62		-- For every controller 
63		for offset, info in pairs(controller_struct) do
64			game.memorymap[polling_addr + controller_addr + offset] = {
65				type = info.type,
66				debug = info.debug,
67				name = info.name:format(port),
68			}
69		end
70	end
71end
72
73function game.translateJoyStick(x, y)
74	return x/100, y/100
75end
76
77local min = math.min
78
79function game.translateTriggers(l, r)
80	return min(1, l/128), min(1, r/128)
81end
82
83return game