Hi,
This is definitely do-able. I have it partially working so you can decide if you would like to take my approach.
There's a scripting engine in MAME that can query the memory of a machine as it is running. You just need to know where in memory to look and what to look for. It can be tricky but there is a process we can follow.
Looking at the long jump stage, I can see that the word "FOUL" appears on the board behind the athlete after the foul is given.
The word "FOUL" is made up of 4 sprites from the sprite bank of the rom. There are rom hacking tools (such as TuracoCL) that allow you to extract the sprite banks from a rom to an image file. I was able to pull this image from sprite bank 1 of trackfld.zip.
From this we can work out the offsets for each of the characters F, O, U and L. That's the position of those characters within the sprite bank.
Counting from the top left (offset 0) and working across, the character "F" appears at offset position 22. This is 16 in hexadecimal. Repeat for the others and we get.
F = 16
O = 1F
U = 25
L = 1CThe sprite offsets will be referenced in the video ram of the game as the screen is drawn so we need to figure out where abouts in memory is the video ram.
Thankfully, the guys at MAME have documented their driver.
/***************************************************************************
Konami games memory map (preliminary)
Based on drivers from Juno First emulator by Chris Hardy (chrish@kcbbs.gen.nz)
Track'n'Field
MAIN BOARD:
0000-17ff RAM
1800-183f Sprite RAM Pt 1
1C00-1C3f Sprite RAM Pt 2
3800-3bff Color RAM
3000-33ff Video RAM
6000-ffff ROM
1200-12ff IO
***************************************************************************
/
So "Video RAM" starts from memory address 3000.
To see the video ram, we can run launch the rom in MAME with -debug parameter, then open a memory window in the debugger, and type 3000 into the address box. To see a better textual representation of the video ram we can increase the number of bytes per line to 32 (from the default 16). There looks to be 32 sprites drawn on each row.
Watching the memory window closely, we can see the video data changing as the word FOUL is drawn to the screen. Fortunately, not much else is happening on screen at this time so it was easy to spot. The data highlighted in red below was changed from 10, 10, 10, 10 to 16, 1F, 25, 1C.
16, 1F, 25, 1C gives us "FOUL". Yay!
Now we know how to check for a long jump foul so we can write a script to react to it.
I made the following script and saved it to the plugins folder under MAME as foul.lua
mem = manager.machine.devices.maincpu.spaces["program"]
function check(offset, value)
return mem:read_i8(offset) == value
end
emu.register_frame(function()
-- Check for FOUL
if check(0xc34E5, 0x16) and check(0xc34E6, 0x1f) and check(0xc34E7, 0x25) and check(0xc34E8, 0x1c) then
if foul == nil then
-- React to the FOUL
os.execute("start c:\\emus\\mame_0234\\plugins\\foul.bat")
foul = 1
end
else
foul = nil
end
end)
If the script detects the foul then it reacts by launching the "foul.bat" batch file. This file is also saved into the plugins folder of MAME.
Here is the result of my test.
You can test this out my extracting files from the attached zip into your MAME plugins folder. Then run MAME with the following arguments (changing the path to your foul.lua).
mame trackfld -script c:\emus\mame_0234\plugins\foul.lua -window
I'm running MAME in a window so that you can see my popup message. Obviously, you can trigger any other action that you want either from the LUA script or from the batch file.
Jon