Skip to content

Commit

Permalink
Clear music and sound effects when skipping the intro
Browse files Browse the repository at this point in the history
  • Loading branch information
10yard committed Sep 7, 2021
1 parent fa9a46d commit 8f4e7d1
Showing 1 changed file with 39 additions and 19 deletions.
58 changes: 39 additions & 19 deletions dkcoach/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,34 +94,37 @@ function dkcoach.startplugin()
local barrel_starty_coach = 206

function initialize()
last_help_toggle = os.clock()
mame_version = tonumber(emu.app_version())

data_credits = os.getenv("DATA_CREDITS")
data_autostart = os.getenv("DATA_AUTOSTART")
data_allow_skip_intro = os.getenv("DATA_ALLOW_SKIP_INTRO")


if mame_version >= 0.227 then
cpu = manager.machine.devices[":maincpu"]
scr = manager.machine.screens[":screen"]
maincpu = manager.machine.devices[":maincpu"]
screen = manager.machine.screens[":screen"]
video = manager.machine.video
ports = manager.machine.ioport.ports
mem = cpu.spaces["program"]
soundcpu = manager.machine.devices[":soundcpu"]
elseif mame_version >= 0.196 then
cpu = manager:machine().devices[":maincpu"]
scr = manager:machine().screens[":screen"]
maincpu = manager:machine().devices[":maincpu"]
screen = manager:machine().screens[":screen"]
video = manager:machine():video()
ports = manager:machine():ioport().ports
mem = cpu.spaces["program"]
soundcpu = manager:machine().devices[":soundcpu"]
else
print("----------------------------------------------------------")
print("The dkcoach plugin requires MAME version 0.196 or greater.")
print("----------------------------------------------------------")
end
if maincpu ~= nil then
mem = maincpu.spaces["program"]
soundmem = soundcpu.spaces["data"]

data_credits = os.getenv("DATA_CREDITS")
data_autostart = os.getenv("DATA_AUTOSTART")
data_allow_skip_intro = os.getenv("DATA_ALLOW_SKIP_INTRO")
end
end

function main()
if cpu ~= nil then
if maincpu ~= nil then
stage, mode1, mode2 = mem:read_i8(0x6227), mem:read_u8(0xc6005), mem:read_u8(0xc600a)

dkafe_specific_features()
Expand All @@ -130,7 +133,7 @@ function dkcoach.startplugin()
write_message(0x76e0, " DK COACH TOGGLE")
write_message(0x7521, help_setting_name[help_setting].." HELP")

-- check for P2 button press.
-- check for toggle / P2 button press.
if string.sub(int_to_bin(mem:read_i8(0x7d00)), 5, 5) == "1" then
if os.clock() - last_help_toggle > 0.25 then
-- toggle the active help setting
Expand All @@ -142,6 +145,7 @@ function dkcoach.startplugin()
end
end

-- main loop
if mode2 == 0xc or mode2 == 0xd or mode2 == 0x16 then
-- get Jumpman's position and convert to drawing system coordinates (ignoring jump)
jm_x = mem:read_u8(0x6203)
Expand All @@ -151,7 +155,7 @@ function dkcoach.startplugin()
ds_y = 250 - jm_y
end

-- Mark Jumpman's location with a spot and output x, y position to console
---- Debug: Mark Jumpman's location with a spot and output x, y position to console
-- version_draw_box(ds_y - 1, ds_x - 1, ds_y + 1, ds_x + 1, 0xffffffff, 0xffffffff)
-- print(ds_x.." "..ds_y)

Expand Down Expand Up @@ -411,9 +415,9 @@ function dkcoach.startplugin()
function version_draw_box(y1, x1, y2, x2, c1, c2)
-- Handle the version specific syntax of draw_box
if mame_version >= 0.227 then
scr:draw_box(y1, x1, y2, x2, c1, c2)
screen:draw_box(y1, x1, y2, x2, c1, c2)
else
scr:draw_box(y1, x1, y2, x2, c2, c1)
screen:draw_box(y1, x1, y2, x2, c2, c1)
end
end

Expand All @@ -426,8 +430,8 @@ function dkcoach.startplugin()
elseif y1 > ds_y or y2 > ds_y then
if type == "hazard" then
version_draw_box(y1, x1, y2, x2, 0xffff0000, 0x66ff0000)
scr:draw_line(y1, x1, y2, x2, 0xffff0000)
scr:draw_line(y2, x1, y1, x2, 0xffff0000)
screen:draw_line(y1, x1, y2, x2, 0xffff0000)
screen:draw_line(y2, x1, y1, x2, 0xffff0000)
elseif type == "safe" then
version_draw_box(y1, x1, y2, x2, 0xff00ff00, 0x00000000)
version_draw_box(y1, x1, y2 + 3, x2, 0x00000000, 0x6000ff00)
Expand Down Expand Up @@ -472,6 +476,17 @@ function dkcoach.startplugin()
end
end

function clear_sounds()
-- clear music on soundcpu
for key = 0, 32 do
soundmem:write_i8(0x0 + key, 0x00)
end
-- clear soundfx buffer
for key = 0, 8 do
mem:write_i8(0xc6080 + key, 0x00)
end
end

function dkafe_specific_features()
-- Optionally set number of coins inserted into the machine
if data_credits ~= nil then
Expand All @@ -492,9 +507,14 @@ function dkcoach.startplugin()
if mode1 == 3 then
if mode2 == 7 then
if string.sub(int_to_bin(mem:read_i8(0xc7c00)), 4, 4) == "1" then
intro_skipped = true
max_frameskip(1)
end
if intro_skipped then
clear_sounds()
end
else
intro_skipped = false
max_frameskip(0)
end
end
Expand Down

0 comments on commit 8f4e7d1

Please sign in to comment.