print ("Loading disc-selection.lua from global scripts")
require "sce-locale"
-- Registers the discs for the active language using EM_SetCDRom().
-- This takes into account region switching if given 2 disc maps to use.
--
-- default_disc_map: Cannot be nil. A table of the form
-- {
-- en = { <list of image paths> },
-- fr = { <list of image paths> },
-- de = { <list of image paths> },
-- it = { <list of image paths> },
-- es = { <list of image paths> }
-- }
--
-- ntsc_disc_map: Similar format to default_disc_map if region switching is supported. Can be nil which
-- will use default_disc_map in its place.
--
-- default_crypts: Can be nil which indicated no crypt will be used. A table of the form
-- {
-- en = "0xad70",
-- fr = "0x7c23",
-- de = "0xacb8",
-- it = "0xea8a",
-- es = "0x1c3d",
-- }
--
-- ntsc_crypts: Similar format to pal_crypts. If this is nil then the table from pal_crypts will be used.
-- If no crypt should be used then specify an empty table.
--
RegisterDiscs = function(default_disc_map, ntsc_disc_map, default_crypts, ntsc_crypts)
local region = EM_GetStoreRegion()
print ("[BOOT] Region = ", region)
local request_ntsc = EM_GetRequestNtscRegion()
print ("[BOOT] Request NTSC region = ", request_ntsc)
if ntsc_disc_map == nil then
ntsc_disc_map = default_disc_map
end
if default_crypts == nil then
default_crypts = {}
end
if ntsc_crypts == nil then
ntsc_crypts = default_crypts
end
local key = nil
local discs = nil
local crypt = nil
local locale, lang = GetLocaleLangPair()
local discs_map = nil
local crypts = nil
if request_ntsc then
printf("[BOOT] NTSC preferred, using that image.")
discs_map = ntsc_disc_map
crypts = ntsc_crypts
else
printf("[BOOT] Registering default images for the region.")
discs_map = default_disc_map
crypts = default_crypts
end
key = FindLocaleTableKey(discs_map, locale, lang, "en")
discs = discs_map[key]
crypt = crypts[key]
local i
for i, disc in ipairs(discs) do
-- patch up for older versions of the emulator that didn't understand /imagedata/ prefix.
-- [jstine] added 2023-02-01
if EM_GetTitleVaultPath == nil then
if string.match(disc, "^/xem_titlevault/data/") then
disc = string.gsub(disc, "^/xem_titlevault/data/", "")
elseif string.match(disc, "^/xem_imagedata/") then
disc = string.gsub(disc, "^/xem_imagedata/", "")
end
end
EM_SetCDRom(disc, i)
end
if crypt then
EM_SetSettingCli("--libcrypt=" .. crypt)
end
end