System.currentDirectory("/CTGP-7/")
function getconfig()
local config = io.open(System.currentDirectory().."config/config.cfg",FWRITE)
local cfgtrack = io.open(System.currentDirectory().."config/tracknames.cfg",FWRITE)
local cfgcustra = io.open(System.currentDirectory().."config/ctnames.cfg",FWRITE)
trackn = (io.size(config) - 1)
local stringtrck = io.read(cfgtrack, 0, io.size(cfgtrack))
local stringct = io.read(cfgcustra, 0, io.size(cfgtrack))
tracks = {}
cts = {}
local l = 1
local m = 1
for i in string.gmatch(stringtrck, "%S+") do
tracks[l] = i -- Course order: GBABC, CTRIS, CTRTC, CTRWI1, N64KD, SFCMC.
l = l + 1
end
for s in string.gmatch(stringct, '([^,]+)') do
cts[m] = s -- Course order: GBABC, CTRIS, CTRTC, CTRWI1, N64KD, SFCMC.
m = m + 1
end
cts[trackn + 1] = nil
if not (tracks[trackn + 1] == nil) or not (cts[trackn + 1] == nil) then
System.exit()
end
if (tracks[trackn] == nil) or (cts[trackn] == nil) then
System.exit()
end
local tracken = {}
tracke = {}
local k = 1
for k = 1, trackn, 1 do
tracken[k] = io.read(config, (k-1), 1) -- Get data from config.cfg
if (tracken[k] == "0") then
tracke[k] = false
elseif (tracken[k] == "1") then
tracke[k] = true
end
end
io.close(config)
io.close(cfgtrack)
return true
end
function saveconfig()
local sconfig = io.open(System.currentDirectory().."config/config.cfg",FWRITE)
-- Course order: GBABC, CTRIS, CTRTC, CTRWI1, N64KD, SFCMC
local y
local tracken = {}
for y = 1, trackn, 1 do
if (tracke[y]) then
tracken[y] = "1"
elseif not (tracke[y]) then
tracken[y] = "0"
end
io.write(sconfig,(y - 1),tracken[y], 1)
end
io.close(sconfig)
return true
end
function applyconfig()
local z
for z = 1, trackn, 1 do
if (System.doesFileExist("/0004000000030"..gamergn.."00/Course/"..tracks[z]..".szs")) then
if not (tracke[z]) then
System.renameFile("/0004000000030"..gamergn.."00/Course/"..tracks[z]..".szs", "/0004000000030"..gamergn.."00/Course/"..tracks[z].."1.szs")
end
elseif (System.doesFileExist("/0004000000030"..gamergn.."00/Course/"..tracks[z].."1.szs")) then
if (tracke[z]) then
System.renameFile("/0004000000030"..gamergn.."00/Course/"..tracks[z].."1.szs", "/0004000000030"..gamergn.."00/Course/"..tracks[z]..".szs")
end
end
end
return true
end
function getgamergn()
local config = io.open(System.currentDirectory().."config/config.cfg",FWRITE)
if (io.read(config, io.size(config) - 1, 1) == "0") then
askrgn = 1
else
submen = 0
end
gamergn = io.read(config, io.size(config) - 1,1)
io.close(config)
return true
end
topimgl = Screen.loadImage(System.currentDirectory().."resources/top_l.bmp")
submen0 = Screen.loadImage(System.currentDirectory().."resources/submen0.bmp")
submen1 = Screen.loadImage(System.currentDirectory().."resources/submen1.bmp")
submen2 = Screen.loadImage(System.currentDirectory().."resources/submen2.bmp")
submen3 = Screen.loadImage(System.currentDirectory().."resources/submen3.bmp")
music0 = Sound.openWav(System.currentDirectory().."resources/music0.wav",false)
music1 = Sound.openWav(System.currentDirectory().."resources/music1.wav",false)
mus0 = 0
men = 0
men1 = 0
men3 = 1
getgamergn()
oldpad = Controls.read
topscreen = topimgl
bottomscreen = submen0
Sound.init()
Sound.play(music0,NO_LOOP,0x09)
while true do
Screen.waitVblankStart()
Screen.refresh()
Screen.clear(BOTTOM_SCREEN)
Screen.drawImage(0,0,topscreen,TOP_SCREEN)
Screen.drawImage(0,0,bottomscreen,BOTTOM_SCREEN)
checkbutton = true
pad = Controls.read()
if (mus0 == 0) then
if (Sound.getTime(music0) == 18) then
Sound.play(music1,LOOP,0x0A)
Sound.close(music0)
mus0 = 1
end
end
if (Controls.check(pad,KEY_DDOWN)) and not (Controls.check(oldpad,KEY_DDOWN)) then
men = men + 1
elseif (Controls.check(pad,KEY_DUP)) and not (Controls.check(oldpad,KEY_DUP)) then
men = men - 1
end
if (Controls.check(pad,KEY_DRIGHT)) and not (Controls.check(oldpad,KEY_DRIGHT)) then
men1 = men1 + 1
elseif (Controls.check(pad,KEY_DLEFT)) and not (Controls.check(oldpad,KEY_DLEFT)) then
men1 = men1 - 1
end
if (men > 1) then
men = 0
elseif (men < 0) then
men = 1
end
if (men1 > 1) then
men1 = 0
elseif (men1 < 0) then
men1 = 1
end
if (askrgn == 1) then
submen = 255
dispreg = "None"
if (men == 0) then
gamergn = 7
dispreg = "EUR"
elseif (men == 1) then
gamergn = 8
dispreg = "USA"
end
Screen.debugPrint(0, 0, "Current selected game region is: "..dispreg, Color.new(255,255,255), BOTTOM_SCREEN)
Screen.debugPrint(0, 0, "DPAD up or down to choose, A to confirm.", Color.new(255,255,255), BOTTOM_SCREEN)
if (Controls.check(pad,KEY_A)) and not (Controls.check(oldpad,KEY_A)) and not (dispreg == "None") then
config = io.open(System.currentDirectory().."config/config.cfg",FWRITE)
io.write(config, io.size(config) - 1, gamergn, 1)
io.close(config)
askrgn = 0
submen = 0
men = 0
men1 = 0
end
end
if (submen == 0) then -- main menu
bottomscreen = submen0
if (men == 0) then
if (men1 == 0) then
Screen.fillEmptyRect(0, 159, 0, 119, Color.new(255,255,255), BOTTOM_SCREEN)
if (Controls.check(pad,KEY_A)) and not (Controls.check(oldpad,KEY_A)) and (checkbutton) then
getconfig()
applyconfig()
System.launchGamecard()
end
else
Screen.fillEmptyRect(159, 319, 0, 119, Color.new(255,255,255), BOTTOM_SCREEN)
if (Controls.check(pad,KEY_A)) and not (Controls.check(oldpad,KEY_A)) and (checkbutton) then
submen = 1
men = 0
men1 = 0
checkbutton = false
end
end
else
if (men1 == 0) then
Screen.fillEmptyRect(0, 159, 119, 239, Color.new(255,255,255), BOTTOM_SCREEN)
if (Controls.check(pad,KEY_A)) and not (Controls.check(oldpad,KEY_A)) and (checkbutton) then
men = 0
men1 = 0
submen = 2
checkbutton = false
end
else
Screen.fillEmptyRect(159, 319, 119, 239, Color.new(255,255,255), BOTTOM_SCREEN)
if (Controls.check(pad,KEY_A)) and not (Controls.check(oldpad,KEY_A)) and (checkbutton) then
Sound.term()
System.exit()
end
end
end
end
if (submen == 1) then -- CTGP-7 manager
bottomscreen = submen1
if (men == 0) then
if (men1 == 0) then
Screen.fillEmptyRect(0, 159, 0, 119, Color.new(255,255,255), BOTTOM_SCREEN)
if (Controls.check(pad,KEY_A)) and not (Controls.check(oldpad,KEY_A)) and (checkbutton) then
submen = 3
men = 0
men1 = 0
checkbutton = false
getconfig()
end
else
Screen.fillEmptyRect(159, 319, 0, 119, Color.new(255,255,255), BOTTOM_SCREEN)
end
else
if (men1 == 0) then
Screen.fillEmptyRect(0, 159, 119, 239, Color.new(255,255,255), BOTTOM_SCREEN)
else
Screen.fillEmptyRect(159, 319, 119, 239, Color.new(255,255,255), BOTTOM_SCREEN)
if (Controls.check(pad,KEY_A)) and not (Controls.check(oldpad,KEY_A)) and (checkbutton) then
submen = 0
men = 0
men1 = 0
checkbutton = false
end
end
end
end
if (submen == 2) then -- Options
bottomscreen = submen2
if (men == 0) then
Screen.fillEmptyRect(0, 319, 0, 119, Color.new(255,255,255), BOTTOM_SCREEN)
if (Controls.check(pad,KEY_A)) and not (Controls.check(oldpad,KEY_A)) and (checkbutton) then
askrgn = 1
getconfig()
submen = 0
men = 0
men1 = 0
checkbutton = false
end
else
Screen.fillEmptyRect(0, 319, 119, 239, Color.new(255,255,255), BOTTOM_SCREEN)
if (Controls.check(pad,KEY_A)) and not (Controls.check(oldpad,KEY_A)) and (checkbutton) then
submen = 0
men = 0
men1 = 0
checkbutton = false
end
end
end
if (submen == 3) then -- Course manager
bottomscreen = submen3
if (Controls.check(pad,KEY_DDOWN)) and not (Controls.check(oldpad,KEY_DDOWN)) then
men3 = men3 - 1
elseif (Controls.check(pad,KEY_DUP)) and not (Controls.check(oldpad,KEY_DUP)) then
men3 = men3 + 1
end
if (men3 == trackn + 1) then
men3 = 1
elseif (men3 == 0) then
men3 = trackn
end
if (Controls.check(pad,KEY_DRIGHT)) and not (Controls.check(oldpad,KEY_DRIGHT)) and (checkbutton) or (Controls.check(pad,KEY_DLEFT)) and not (Controls.check(oldpad,KEY_DLEFT)) and (checkbutton)then
tracke[men3] = not tracke[men3]
end
if (Controls.check(pad,KEY_B)) and not (Controls.check(oldpad,KEY_B)) and (checkbutton) then
submen = 1
men = 0
men1 = 0
checkbutton = false
saveconfig()
end
enadisa = {}
for x = 1, trackn, 1 do
if (tracke[x]) then
enadisa[x] = "enabled"
elseif not (tracke[x]) then
enadisa[x] = "disabled"
end
end
Screen.debugPrint(0, 0, men3..": "..cts[men3].." = "..enadisa[men3], Color.new(255,255,255), BOTTOM_SCREEN)
end
Screen.debugPrint(0, 100, System.getGWRomID(), Color.new(255,255,255), BOTTOM_SCREEN)
oldpad = pad
Screen.flip()
end