7575local APP_DIR_LOCAL = NormalizeDirPath (APP_DIR or BOOT_PATH_RAW )
7676LOG (" APP_DIR_NORM=" .. APP_DIR_LOCAL )
7777LOG (" APP_DIR_POPSTARTER_JOIN=" .. JoinPath (APP_DIR_LOCAL , " POPSTARTER.ELF" ))
78+ local SELECTOR_MODE = " basename"
7879
7980local function ResolveAsset (rel )
8081 return System .resolveAsset (rel ) or JoinPath (APP_DIR_LOCAL , rel )
@@ -287,9 +288,9 @@ function PLDR.CheckPOPStarterDEPS(device)
287288 if device == UI .SCENES .GUSB then
288289 return doesFileExist (" mass:/POPS/POPS_IOX.PAK" )
289290 elseif device == UI .SCENES .GHDD then
290- local a = HDD .MountPartition (" hdd0:__common" , 1 , FIO_MT_RDONLY )
291+ local a = HDD .MountPartition (" hdd0:__common" , 0 , FIO_MT_RDONLY )
291292 if a then
292- return a , doesFileExist (" pfs1 :/POPS/POPS.ELF" ), doesFileExist (" pfs1 :/POPS/IOPRP252.IMG" )
293+ return a , doesFileExist (" pfs0 :/POPS/POPS.ELF" ), doesFileExist (" pfs0 :/POPS/IOPRP252.IMG" )
293294 else
294295 return a , false , false
295296 end
@@ -361,17 +362,17 @@ end
361362function PLDR .HDD .CheckAvailableHddPopsParts ()
362363 if not PLDR .HDD .HAS_CHECKED then -- HDD is checked only once since it cannot be removed/replaced without damaging the console
363364 LOG (" Checking available __.POPS Partitions" )
364- if HDD .MountPartition (" hdd0:__.POPS" , 1 , FIO_MT_RDONLY ) then
365+ if HDD .MountPartition (" hdd0:__.POPS" , 0 , FIO_MT_RDONLY ) then
365366 PLDR .HDD .MAINPART = true
366- HDD .UMountPartition (1 )
367+ HDD .UMountPartition (0 )
367368 end
368369 LOG (" __.POPS" , PLDR .HDD .MAINPART )
369370 PLDR .HDD .FOUNDANY = PLDR .HDD .MAINPART
370371 for i = 1 , 9 do
371- if HDD .MountPartition ((" hdd0:__.POPS%d" ):format (i ), 1 , FIO_MT_RDONLY ) then
372+ if HDD .MountPartition ((" hdd0:__.POPS%d" ):format (i ), 0 , FIO_MT_RDONLY ) then
372373 PLDR .HDD .EXTRAPARTS [i ] = true
373374 PLDR .HDD .FOUNDANY = true
374- HDD .UMountPartition (1 )
375+ HDD .UMountPartition (0 )
375376 end
376377 LOG (" __.POPS" .. i , PLDR .HDD .EXTRAPARTS [i ])
377378 end
@@ -385,25 +386,25 @@ function PLDR.HDD.BuildGameList()
385386 PLDR .HDD .GAMEPARTS = {}
386387 if not PLDR .HDD .FOUNDANY then return end
387388 if PLDR .HDD .MAINPART then
388- if HDD .MountPartition (" hdd0:__.POPS" , 1 , FIO_MT_RDONLY ) then
389+ if HDD .MountPartition (" hdd0:__.POPS" , 0 , FIO_MT_RDONLY ) then
389390 local start_index = # PLDR .GAMES
390- PLDR .GetPS1GameLists (" pfs1 :/" , true )
391+ PLDR .GetPS1GameLists (" pfs0 :/" , true )
391392 for i = start_index + 1 , # PLDR .GAMES do
392393 PLDR .HDD .GAMEPARTS [PLDR .GAMES [i ]] = " hdd0:__.POPS"
393394 end
394- HDD .UMountPartition (1 )
395+ HDD .UMountPartition (0 )
395396 end
396397 end
397398 for i = 1 , 9 do
398399 if PLDR .HDD .EXTRAPARTS [i ] then
399- if HDD .MountPartition (" hdd0:__.POPS" .. i , 1 , FIO_MT_RDONLY ) then
400+ if HDD .MountPartition (" hdd0:__.POPS" .. i , 0 , FIO_MT_RDONLY ) then
400401 local start_index = # PLDR .GAMES
401402 local partition = " hdd0:__.POPS" .. i
402- PLDR .GetPS1GameLists (" pfs1 :/" , true )
403+ PLDR .GetPS1GameLists (" pfs0 :/" , true )
403404 for j = start_index + 1 , # PLDR .GAMES do
404405 PLDR .HDD .GAMEPARTS [PLDR .GAMES [j ]] = partition
405406 end
406- HDD .UMountPartition (1 )
407+ HDD .UMountPartition (0 )
407408 end
408409 end
409410 end
@@ -545,6 +546,34 @@ local function BuildPopstarterSelector(prefix, vcd_filename)
545546 return prefix .. vcd_filename .. " .ELF"
546547end
547548
549+ local function SelectPopstarterSelectorPrefix (device_page )
550+ if device_page == " USB" or device_page == " MMCE" or device_page == " SMB/MMCE" then
551+ return " XX."
552+ end
553+ if device_page == " HDD" then
554+ return " "
555+ end
556+ return " XX."
557+ end
558+
559+ local function BuildPopstarterSelectorPath (device_page , game_name )
560+ if game_name == nil or game_name == " " then
561+ return " "
562+ end
563+ if device_page == " HDD" then
564+ return " hdd0:__.POPS/" .. game_name .. " .ELF"
565+ end
566+ if device_page == " USB" or device_page == " MMCE" or device_page == " SMB/MMCE" then
567+ return " mass:/POPS/XX." .. game_name .. " .ELF"
568+ end
569+ return game_name .. " .ELF"
570+ end
571+
572+ local function DeriveGameNameFromSelection (raw_selection )
573+ local vcd_filename = ExtractVcdFilename (raw_selection or " " )
574+ return SanitizeGameName (StripVcdExtension (vcd_filename ))
575+ end
576+
548577local function HasBootPrefix (basename , desired_prefix )
549578 if basename == nil or basename == " " or desired_prefix == nil or desired_prefix == " " then
550579 return false
@@ -627,7 +656,7 @@ local function EnsureHDDReadyForLaunch(game)
627656 end
628657 local partition = PLDR .HDD .GAMEPARTS [game ] or " hdd0:__.POPS"
629658 result .mount_partition = partition
630- result .mount_ok = HDD .MountPartition (partition , 1 , FIO_MT_RDONLY )
659+ result .mount_ok = HDD .MountPartition (partition , 0 , FIO_MT_RDONLY )
631660 return result
632661end
633662
@@ -860,6 +889,12 @@ local function LaunchEngine(popstarter, argv, reboot_iop, context)
860889 context and context .bootparam or " unknown"
861890 )
862891 LaunchLog (" LAUNCH: stage A argv_count:" , exec_args and # exec_args or 0 )
892+ LaunchLog (
893+ " LAUNCH: selector=" .. tostring (argv0 ),
894+ " popstarter=" .. tostring (popstarter ),
895+ " reboot_iop=" .. tostring (reboot_iop )
896+ )
897+ LaunchLog (" LAUNCH: loadELF argc (caller):" , exec_args and # exec_args or 0 )
863898 local rc
864899 if exec_args ~= nil and # exec_args > 0 and unpack_fn ~= nil then
865900 rc = System .loadELF (popstarter , reboot_iop , unpack_fn (exec_args ))
@@ -984,10 +1019,37 @@ function PLDR.RunPOPStarterGame(gamelocation, game)
9841019 local fallback_exists = false
9851020 local bootparam_basename_used = normalized_basename
9861021 local prefix_used = HasBootPrefix (normalized_basename , prefix ) and prefix or " "
987- local vcd_filename = ExtractVcdFilename (game )
988- local game_name = SanitizeGameName (StripVcdExtension (vcd_filename ))
989- local selector_prefix = " XX."
990- local argv0_selector = BuildPopstarterSelector (selector_prefix , game_name )
1022+ local game_name = DeriveGameNameFromSelection (game )
1023+ if game_name == " " or string.upper (game_name ) == " POPSTARTER" then
1024+ LaunchLog (" LAUNCH: GameName derivation failed for selection:" , game )
1025+ BlockLaunchFailure (
1026+ " GameName derivation failed" ,
1027+ popstarter ,
1028+ device_page ,
1029+ nil ,
1030+ game ,
1031+ APP_DIR_LOCAL ,
1032+ nil ,
1033+ nil
1034+ )
1035+ return
1036+ end
1037+ local selector_prefix = SelectPopstarterSelectorPrefix (device_page )
1038+ local argv0_selector = BuildPopstarterSelectorPath (device_page , game_name )
1039+ if selector_prefix == " " and string.upper (game_name ) == " POPSTARTER" then
1040+ LaunchLog (" LAUNCH: Internal error: game_base derived as POPSTARTER; refusing to launch." , game )
1041+ BlockLaunchFailure (
1042+ " Internal error: game_base derived as POPSTARTER; refusing to launch." ,
1043+ popstarter ,
1044+ device_page ,
1045+ nil ,
1046+ game ,
1047+ APP_DIR_LOCAL ,
1048+ nil ,
1049+ nil
1050+ )
1051+ return
1052+ end
9911053 if boot_source_mode == " mass" and prefix_added and not bootparam_exists then
9921054 fallback_bootparam = EnsureTrailingSlash (pops_root ).. game
9931055 fallback_exists = doesFileExist (fallback_bootparam )
@@ -1010,7 +1072,10 @@ function PLDR.RunPOPStarterGame(gamelocation, game)
10101072 LaunchLog (" LAUNCH: vcd basename used:" , bootparam_basename_used )
10111073 LaunchLog (" LAUNCH: bootparam candidate:" , bootparam , " exists:" , tostring (bootparam_exists ))
10121074 LaunchLog (" LAUNCH: derived GameName:" , game_name )
1075+ LaunchLog (" LAUNCH: selector mode:" , SELECTOR_MODE )
1076+ LaunchLog (" LAUNCH: selector prefix:" , selector_prefix )
10131077 LaunchLog (" LAUNCH: argv0 selector:" , argv0_selector )
1078+ LaunchLog (" LAUNCH: loadELF argc (caller):" , # argv )
10141079 if fallback_bootparam ~= nil then
10151080 LaunchLog (" LAUNCH: bootparam fallback:" , fallback_bootparam , " exists:" , tostring (fallback_exists ))
10161081 end
0 commit comments