|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var EL = null; |
|
|
|
|
|
|
|
|
var ELCtrl = null; |
|
|
|
|
|
var ELSel = null; |
|
|
|
|
|
var ELLab = null; |
|
|
|
|
|
var ELOff = null; |
|
|
var SURF = null; |
|
|
var SURF = null; |
|
|
var LastVal = "all"; |
|
|
|
|
|
|
|
|
|
|
|
function GetSubControls(){ |
|
|
|
|
|
var els = []; |
|
|
|
|
|
if (EL !== null){ |
|
|
|
|
|
var ellab = EL.querySelectorAll(".painter-bank-offset"); |
|
|
|
|
|
var eloff = null; |
|
|
|
|
|
if (ellab.length === 1){ |
|
|
|
|
|
els.push(ellab[0]); |
|
|
|
|
|
eloff = els[0].querySelectorAll("#offset-select"); |
|
|
|
|
|
if (eloff.length === 1){ |
|
|
|
|
|
els.push(eloff[0]); |
|
|
|
|
|
} else { |
|
|
|
|
|
console.log("Ambiguous number of 'offset-select' elements."); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
console.log("Ambiguous number of 'painter-bank-offset' elements."); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return (els.length == 2) ? els : null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function OpenControls(){ |
|
|
function OpenControls(){ |
|
|
if (EL !== null && SURF !== null){ |
|
|
|
|
|
var subel = GetSubControls(); |
|
|
|
|
|
|
|
|
if (ELCtrl !== null && SURF !== null){ |
|
|
switch(SURF.access_mode){ |
|
|
switch(SURF.access_mode){ |
|
|
case NESBank.ACCESSMODE_8K: |
|
|
case NESBank.ACCESSMODE_8K: |
|
|
subel[0].classList.add("hidden"); |
|
|
|
|
|
|
|
|
ELSel.value = "8K"; |
|
|
|
|
|
ELLab.classList.add("hidden"); |
|
|
break; |
|
|
break; |
|
|
case NESBank.ACCESSMODE_4K: |
|
|
case NESBank.ACCESSMODE_4K: |
|
|
|
|
|
ELSel.value = "4K"; break; |
|
|
case NESBank.ACCESSMODE_2K: |
|
|
case NESBank.ACCESSMODE_2K: |
|
|
|
|
|
ELSel.value = "2K"; break; |
|
|
case NESBank.ACCESSMODE_1K: |
|
|
case NESBank.ACCESSMODE_1K: |
|
|
subel[0].classList.remove("hidden"); |
|
|
|
|
|
subel[1].setAttribute("max", SURF.access_offset_length - 1); |
|
|
|
|
|
subel[1].setAttribute("value", SURF.access_offset); |
|
|
|
|
|
|
|
|
ELSel.value = "1K"; break; |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
EL.classList.remove("hidden"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ELSel.value !== "8K"){ |
|
|
|
|
|
ELLab.classList.remove("hidden"); |
|
|
|
|
|
ELOff.setAttribute("max", SURF.access_offset_length - 1); |
|
|
|
|
|
ELOff.value = SURF.access_offset; |
|
|
|
|
|
//ELOff.setAttribute("value", SURF.access_offset); |
|
|
|
|
|
} |
|
|
|
|
|
ELCtrl.classList.remove("hidden"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function CloseControls(){ |
|
|
function CloseControls(){ |
|
|
if (EL !== null){ |
|
|
|
|
|
EL.classList.add("hidden"); |
|
|
|
|
|
|
|
|
if (ELCtrl !== null){ |
|
|
|
|
|
ELCtrl.classList.add("hidden"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function HANDLE_ModeChange(){ |
|
|
function HANDLE_ModeChange(){ |
|
|
if (EL !== null && SURF !== null){ |
|
|
|
|
|
|
|
|
if (ELCtrl !== null && SURF !== null){ |
|
|
var val = this.options[this.selectedIndex].value; |
|
|
var val = this.options[this.selectedIndex].value; |
|
|
var subel = GetSubControls(); |
|
|
|
|
|
switch(val){ |
|
|
switch(val){ |
|
|
case "8K": |
|
|
case "8K": |
|
|
SURF.access_mode = NESBank.ACCESSMODE_8K; |
|
|
SURF.access_mode = NESBank.ACCESSMODE_8K; |
|
|
subel[0].classList.add("hidden"); |
|
|
|
|
|
|
|
|
ELLab.classList.add("hidden"); |
|
|
break; |
|
|
break; |
|
|
case "4K": |
|
|
case "4K": |
|
|
SURF.access_mode = NESBank.ACCESSMODE_4K; |
|
|
|
|
|
subel[0].classList.remove("hidden"); |
|
|
|
|
|
subel[1].setAttribute("value", SURF.access_offset); |
|
|
|
|
|
subel[1].setAttribute("max", SURF.access_offset_length - 1); |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
SURF.access_mode = NESBank.ACCESSMODE_4K; break; |
|
|
case "2K": |
|
|
case "2K": |
|
|
SURF.access_mode = NESBank.ACCESSMODE_2K; |
|
|
|
|
|
subel[0].classList.remove("hidden"); |
|
|
|
|
|
subel[1].setAttribute("value", SURF.access_offset); |
|
|
|
|
|
subel[1].setAttribute("max", SURF.access_offset_length - 1); |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
SURF.access_mode = NESBank.ACCESSMODE_2K; break; |
|
|
case "1K": |
|
|
case "1K": |
|
|
SURF.access_mode = NESBank.ACCESSMODE_1K; |
|
|
|
|
|
subel[0].classList.remove("hidden"); |
|
|
|
|
|
subel[1].setAttribute("value", SURF.access_offset); |
|
|
|
|
|
subel[1].setAttribute("max", SURF.access_offset_length - 1); |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
SURF.access_mode = NESBank.ACCESSMODE_1K; break; |
|
|
|
|
|
} |
|
|
|
|
|
if (SURF.access_mode !== NESBank.ACCESSMODE_8K){ |
|
|
|
|
|
ELLab.classList.remove("hidden"); |
|
|
|
|
|
//ELOff.setAttribute("value", SURF.access_offset); |
|
|
|
|
|
ELOff.setAttribute("max", SURF.access_offset_length - 1); |
|
|
|
|
|
ELOff.value = SURF.access_offset; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function HANDLE_OffsetChange(){ |
|
|
function HANDLE_OffsetChange(){ |
|
|
if (EL !== null && SURF !== null){ |
|
|
|
|
|
|
|
|
if (ELCtrl !== null && SURF !== null){ |
|
|
var val = parseInt(this.value); |
|
|
var val = parseInt(this.value); |
|
|
SURF.access_offset = val; |
|
|
SURF.access_offset = val; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
GlobalEvents.listen("change_surface", HANDLE_SurfChange); |
|
|
GlobalEvents.listen("change_surface", HANDLE_SurfChange); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
close(){ |
|
|
|
|
|
if (ELSel) |
|
|
|
|
|
ELSel.removeEventListener("change", HANDLE_ModeChange); |
|
|
|
|
|
if (ELOff) |
|
|
|
|
|
ELOff.removeEventListener("change", HANDLE_OffsetChange); |
|
|
|
|
|
if (ELCtrl) |
|
|
|
|
|
ELCtrl.classList.add("hidden"); |
|
|
|
|
|
ELCTRL = null; |
|
|
|
|
|
ELSel = null; |
|
|
|
|
|
ELLab = null; |
|
|
|
|
|
ELOff = null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
initialize(){ |
|
|
initialize(){ |
|
|
if (EL === null){ |
|
|
|
|
|
EL = document.querySelectorAll(".painter-bank-controls"); |
|
|
|
|
|
if (EL.length !== 1){ |
|
|
|
|
|
console.log("ERROR: More than one painter-bank-controls element found. Ambiguous State."); |
|
|
|
|
|
|
|
|
if (ELCtrl === null){ |
|
|
|
|
|
ELCtrl = document.querySelector(".painter-bank-controls"); |
|
|
|
|
|
if (!ELCtrl){ |
|
|
|
|
|
console.log("ERROR: Failed to find 'painter-bank-controls' element"); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ELSel = ELCtrl.querySelector(".painter-bank-mode"); |
|
|
|
|
|
if (!ELSel){ |
|
|
|
|
|
this.close(); |
|
|
|
|
|
console.log("ERROR: Failed to find 'painter-bank-mode' element."); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
EL = EL[0]; |
|
|
|
|
|
var elsel = EL.querySelectorAll(".painter-bank-mode"); |
|
|
|
|
|
if (elsel.length !== 1){ |
|
|
|
|
|
console.log("Ambiguous number of 'painter-bank-mode' elements."); |
|
|
|
|
|
EL = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ELLab = ELCtrl.querySelector(".painter-bank-offset"); |
|
|
|
|
|
if (!ELLab){ |
|
|
|
|
|
this.close(); |
|
|
|
|
|
console.log("ERROR: Failed to find 'painter-bank-offset' element."); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ELOff = ELLab.querySelector("#offset-select"); |
|
|
|
|
|
if (!ELOff){ |
|
|
|
|
|
this.close(); |
|
|
|
|
|
console.log("ERROR: Failed to find 'offset-select' element."); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
elsel = elsel[0]; |
|
|
|
|
|
elsel.addEventListener("change", HANDLE_ModeChange); |
|
|
|
|
|
var subel = GetSubControls(); |
|
|
|
|
|
subel[1].addEventListener("change", HANDLE_OffsetChange); |
|
|
|
|
|
|
|
|
ELSel.addEventListener("change", HANDLE_ModeChange); |
|
|
|
|
|
ELOff.addEventListener("change", HANDLE_OffsetChange); |
|
|
OpenControls(); |
|
|
OpenControls(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |