Main > Driving & Racing Cabinets

Adding Race Leader lights - advice needed

<< < (10/14) > >>

jorgenjl2:
Got it!!!  :cheers:  I still need to put together a walk through of the race leader light setup (completely solderless and uses a full color led strip unlike how I always see individual leds shown in code). But for now, here is the code to get custom race leader lights working for mame games that dont support it. This is Crusn USA, Crusn world, and California Speed so far. This assumes you have mamehooker already working and games that support race leader lights (Daytona USA, Rush the Rock, etc.) working but I will show those steps for the other walkthrough.

1) Create a text file with code below and rename to <game>raceleader.lua for example crusnwldraceleader.lua and place in mame folder

2) Add a line to your mamehooker ini files at the end of the ini file like below for the mamehooker games ini 
raceleader=cmw 4 3, cmw 4 %s%, cmw 4 x

NOTE: This assumes your com port is 4 and you want to send 3,1,x to turn on the light (other arduino code will do this and I will provide later). It also assumes you are updating a mamehooker fiile called C:\mamehooker5.1\ini\MAME\crusnwld.ini

3) Startup mame with the lua file from command prompt (or add to Launchbox/etc. flag)
cd C:\Users\JLJ\Downloads\Mame\
mame crusnwld -autoboot_script crusnwldraceleader.lua -window

--NOTE: Take away the -window flag once you test. That just makes it easy to see your mamehooker debug window to make sure you see the raceleader output turning to 1 when in first place.

That is it! Now get in first place and your race leader light will light up!!!



--- Code: --- --crusnwldraceleader.lua
local mem = manager.machine.devices.maincpu.spaces["program"]

function check(offset, value)
    return mem:read_i8(offset) == value
end

local baseAddress = 0xEBBA
local output = manager.machine.output

-- Function to handle the Leader Light situation
function handleLeaderLightOn()
    output:set_value("raceleader",1)
end

function handleLeaderLightOff()
    output:set_value("raceleader",0)
end

-- Register a function that gets called every frame
emu.register_frame(function()
    if check(baseAddress, 1) then
        -- If the value at the memory address is 1
        handleLeaderLightOn()
    else
        -- If the value at the memory address is not 1
        handleLeaderLightOff()
    end
end)

--- End code ---


--- Code: -----crusnusaraceleader.lua
local mem = manager.machine.devices.maincpu.spaces["program"]

function check(offset, value)
    return mem:read_i8(offset) == value
end

local baseAddress = 0xE637
local output = manager.machine.output

-- Function to handle the Leader Light situation
function handleLeaderLightOn()
    output:set_value("raceleader",1)
end

function handleLeaderLightOff()
    output:set_value("raceleader",0)
end

-- Register a function that gets called every frame
emu.register_frame(function()
    if check(baseAddress, 1) then
        -- If the value at the memory address is 1
        handleLeaderLightOn()
    else
        -- If the value at the memory address is not 1
        handleLeaderLightOff()
    end
end)

--- End code ---


--- Code: -----californiaspeedraceleader.lua (change 9 in script below to 1 once you want to try to get in 1st place. 9th is for testing)
local mem = manager.machine.devices['pci:00.0'].spaces['memory_space']

function checkPosition()
    -- Assuming the racer's position is stored in the last byte at the given address
    local data = mem:read_u8(0x04B0EEE)
    -- Extract the last byte which indicates the position
    local position = data & 0xFF -- This masks out all but the last byte

    return position -- Return the extracted position
end

local output = manager.machine.output

function handleLeaderLightOn()
    output:set_value("raceleader", 1)
end

function handleLeaderLightOff()
    output:set_value("raceleader", 0)
end

emu.register_frame(function()
    -- Check if the racer's position is 1st
    if checkPosition() == 9 then
        handleLeaderLightOn()
    else
        handleLeaderLightOff()
    end
end)

--- End code ---

buttersoft:
ok, i keep forgetting to post up but i've certainly been watching :)

This is great stuff. I haven't gone through the system in detail, but... will you take requests? I'd like to add leader lights to F1 Super Lap, certainly :)

jorgenjl2:
 ::)
--- Quote from: buttersoft on November 07, 2023, 05:51:21 am ---ok, i keep forgetting to post up but i've certainly been watching :)

This is great stuff. I haven't gone through the system in detail, but... will you take requests? I'd like to add leader lights to F1 Super Lap, certainly :)

--- End quote ---
Yes now that I know how to find the memory addresses with Mame debug (at least for a few games) I can try to get others pretty easily for other Mame games. One thing I should have mentioned is that we can also cheat a little and download the Mame Cheats file from here (Pugsys Cheats - http://www.mamecheat.co.uk/ ) and extract the cheats file and find the xml for the game which sometimes has the memory address listed already for us. For example Crusn USA and World had it listed whereas California Speed only had a couple unrelated to the racers position. It could still help with knowing the rough memory address range though. The file name of the xml corresponds to the rom version so crusnusa20.xml (if I recall) is rom 2.0 of crusn USA or crusnusa44.xml is 4.4 rom. Luckily the address listed still worked for crusn 4.5 Mame.

What I really want is someone who knows how to find the memory address for Teknoparrot (Mario Kart Arcade GP DX, Outrun 2 SP SDX, and FnF Supercars). Although I saw a video of a four player Outrun 2 special with 8 wheels and physical cars that had race leader positions so I need to check if outputblaster shows that data already.

buttersoft:

--- Quote from: jorgenjl2 on November 07, 2023, 07:13:40 am ---What I really want is someone who knows how to find the memory address for Teknoparrot (Mario Kart Arcade GP DX, Outrun 2 SP SDX, and FnF Supercars). Although I saw a video of a four player Outrun 2 special with 8 wheels and physical cars that had race leader positions so I need to check if outputblaster shows that data already.

--- End quote ---

Boomslangnz, and all the TP devs, are on the discord pretty often. Boom's FFB and output plugin channels are quieter, so you could try leaving a message in there.

jorgenjl2:

--- Quote from: buttersoft on November 07, 2023, 07:50:50 pm ---
--- Quote from: jorgenjl2 on November 07, 2023, 07:13:40 am ---What I really want is someone who knows how to find the memory address for Teknoparrot (Mario Kart Arcade GP DX, Outrun 2 SP SDX, and FnF Supercars). Although I saw a video of a four player Outrun 2 special with 8 wheels and physical cars that had race leader positions so I need to check if outputblaster shows that data already.

--- End quote ---

Boomslangnz, and all the TP devs, are on the discord pretty often. Boom's FFB and output plugin channels are quieter, so you could try leaving a message in there.

--- End quote ---

It sounds like Boomslangz is going to find the address for some Teknoparrot games (Mario Kart/Outrun2SPDX/FnFSupercars) so that is awesome. I still am not clear if Teknoparrot and Outputblaster supports lua scripts but hopefully Boomslangz knows how to do from a high level if not. You would think we could mimic the way we are doing it with mame though.

Here is F1 Super Lap for you.


--- Code: -----f1lapraceleader.lua
-- Assuming ':mainpcb:maincpu' is the correct device tag based on your dump command
local cpu_tag = ':mainpcb:maincpu'
local mem = manager.machine.devices[cpu_tag].spaces['program']

function check(offset)
    -- Reading signed byte (8-bit) value from memory
    return mem:read_i8(offset)
end

local baseAddress = 0x201048
local output = manager.machine.output

-- Function to handle the Leader Light situation
function handleLeaderLightOn()
    output:set_value("raceleader", 1)
end

function handleLeaderLightOff()
    output:set_value("raceleader", 0)
end

-- Register a function that gets called every frame
emu.register_frame(function()
    -- Check the current value at baseAddress
    local racePosition = check(baseAddress)
    -- Assuming 0 is the value for the 1st place
    if racePosition == 0 then
        -- If the value at the memory address is 0 (1st place)
        handleLeaderLightOn()
    else
        -- If the value at the memory address is not 0 (not 1st place)
        handleLeaderLightOff()
    end
end)

--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version