Skip to content

Commit

Permalink
Fix some issues with fused executable
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasvl committed Jun 9, 2020
1 parent 112e940 commit 48f8468
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,27 @@ function love.load(arg)
-- Load ROM data into ROM chips and connect them to the bus
local address = 0

if love.filesystem.isFused() then
love.filesystem.mount(love.filesystem.getSourceBaseDirectory(), "fused_dir")
local rom_files = {
"invaders.h",
"invaders.g",
"invaders.f",
"invaders.e"
}

local root_dir = ""
if love.filesystem.isFused() and love.filesystem.mount(love.filesystem.getSourceBaseDirectory(), "fused_dir") then
root_dir = "fused_dir/"
end

local num_files = 0
local rom_files = love.filesystem.getDirectoryItems("assets/")
table.sort(rom_files, function(a, b) return a > b end)
for _, file in ipairs(rom_files) do
file = string.lower(file)
if string.find(file, "invaders") then
num_files = num_files + 1
local rom_part = util.read_file("assets/" .. file)
local rom_part
if love.filesystem.getInfo(root_dir .. "assets/" .. file) then
rom_part = util.read_file(root_dir .. "assets/" .. file)
end

if rom_part then
num_files = num_files + 1
-- Read high score from save file and write it to ROM
if file == "invaders.e" then
local savefile = love.filesystem.newFile("hiscore")
Expand Down Expand Up @@ -80,7 +88,6 @@ function love.load(arg)
if num_files ~= 4 then
local font = love.graphics.newFont(20)
function love.draw()
love.graphics.print(num_files)
love.graphics.setFont(font)
love.graphics.printf(
"Couldn't locate Space Invaders ROM files.\n" ..
Expand Down Expand Up @@ -112,10 +119,10 @@ function love.load(arg)

-- Load sound files
for i = 0, 9 do
if love.filesystem.getInfo("assets/" .. i .. ".wav") then
sounds[i] = love.audio.newSource("assets/" .. i .. ".wav", "static")
elseif love.filesystem.getInfo("assets/" .. sound_names[i + 1] .. ".wav") then
sounds[i] = love.audio.newSource("assets/" .. sound_names[i + 1] .. ".wav", "static")
if love.filesystem.getInfo(root_dir .. "assets/" .. i .. ".wav") then
sounds[i] = love.audio.newSourcer(root_dir .. "assets/" .. i .. ".wav", "static")
elseif love.filesystem.getInfo(root_dir .. "assets/" .. sound_names[i + 1] .. ".wav") then
sounds[i] = love.audio.newSource(root_dir .. "assets/" .. sound_names[i + 1] .. ".wav", "static")
end

if sounds[0] then
Expand Down

0 comments on commit 48f8468

Please sign in to comment.