fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
7277dd1
v2.1.6
1local core ={} 2 3local GAME ={} 4GAME . __index =GAME 5 6function GAME : map ( address , structure ) 7self . memorymap [ address ] =structure 8end 9 10function core . newGame ( ... ) 11local game =setmetatable ( { 12memorymap ={} , 13translateJoyStick =core . translateJoyStick , 14translateCStick =core . translateCStick , 15translateTriggers =core . translateTriggers , 16} , GAME ) 17 18local genericControllers ={ ... } 19 20if # genericControllers > 0 then 21for k , addr in ipairs ( genericControllers ) do 22core . loadGenericControllerMap ( addr , game ) 23end 24end 25 26return game 27end 28 29function core . loadGenericControllerMap ( addr , game ) 30local controllers ={ 31[ 1 ] =addr + 0xC * 0 , 32[ 2 ] =addr + 0xC * 1 , 33[ 3 ] =addr + 0xC * 2 , 34[ 4 ] =addr + 0xC * 3 , 35} 36 37local controller_struct ={ 38[ 0x0 ] ={ type ="short" , name ="controller.%d.buttons.pressed" } , 39[ 0x2 ] ={ type ="sbyte" , name ="controller.%d.joystick.x" } , 40[ 0x3 ] ={ type ="sbyte" , name ="controller.%d.joystick.y" } , 41[ 0x4 ] ={ type ="sbyte" , name ="controller.%d.cstick.x" } , 42[ 0x5 ] ={ type ="sbyte" , name ="controller.%d.cstick.y" } , 43[ 0x6 ] ={ type ="byte" , name ="controller.%d.analog.l" } , 44[ 0x7 ] ={ type ="byte" , name ="controller.%d.analog.r" } , 45[ 0xA ] ={ type ="byte" , name ="controller.%d.plugged" } , 46} 47 48for port , address in ipairs ( controllers ) do 49for offset , info in pairs ( controller_struct ) do 50game . memorymap [ address + offset ] ={ 51type =info . type , 52debug =info . debug , 53name =info . name : format ( port ), 54} 55end 56end 57end 58 59local abs =math . abs 60 61-- These functions seem to apply to many games 62 63function core . translateJoyStick ( x , y ) 64x =x / 72 65y =y / 72 66 67local near =1 - ( abs ( abs ( x ) - abs ( y ))) 68 69local angle =math . atan2 ( x , y ) 70local mag =math . sqrt ( x * x + y * y ) 71 72-- Amplify the magnitute when x,y values are headed towards a diagonal 73return x + math . sin ( angle ) * mag * near * 0.25 , y + math . cos ( angle ) * mag * near * 0.25 74end 75 76function core . translateCStick ( x , y ) 77x =x / 59 78y =y / 59 79 80local near =1 - ( abs ( abs ( x ) - abs ( y ))) 81 82local angle =math . atan2 ( x , y ) 83local mag =math . sqrt ( x * x + y * y ) 84 85-- Amplify the magnitute when x,y values are headed towards a diagonal 86return x + math . sin ( angle ) * mag * near * 0.25 , y + math . cos ( angle ) * mag * near * 0.25 87end 88 89local min =math . min 90 91function core . translateTriggers ( l , r ) 92return min ( 1 , l / 125 ), min ( 1 , r / 125 ) 93end 94 95return core