|
|
|
|
|
|
|
|
res.side = (off >= 256) ? 1 : 0; |
|
|
res.side = (off >= 256) ? 1 : 0; |
|
|
res.tileidx = (off >= 256) ? off - 256 : off; |
|
|
res.tileidx = (off >= 256) ? off - 256 : off; |
|
|
break; |
|
|
break; |
|
|
|
|
|
case NESBank.ACCESSMODE_2T: |
|
|
|
|
|
res.side = (off >= 128) ? 1 : 0; |
|
|
|
|
|
off -= (off >= 128) ? 128 : 0; |
|
|
|
|
|
//res.tileidx = (Math.floor(off % 8)*32) + Math.floor(off / 16) + ((y >= 8) ? 16 : 0); |
|
|
|
|
|
res.tileidx = ((Math.floor(off/16)*32) + (off % 16)) + ((y >= 8) ? 16 : 0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
res.x = x%8; |
|
|
res.x = x%8; |
|
|
|
|
|
|
|
|
return Math.floor(ooff * 0.25); |
|
|
return Math.floor(ooff * 0.25); |
|
|
case NESBank.ACCESSMODE_1T: |
|
|
case NESBank.ACCESSMODE_1T: |
|
|
return Math.floor(ooff / 256); |
|
|
return Math.floor(ooff / 256); |
|
|
|
|
|
case NESBank.ACCESSMODE_2T: |
|
|
|
|
|
return Math.floor(ooff / 128); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return ooff; |
|
|
return ooff; |
|
|
|
|
|
|
|
|
return Math.floor(ooff * 0.5); |
|
|
return Math.floor(ooff * 0.5); |
|
|
case NESBank.ACCESSMODE_1T: |
|
|
case NESBank.ACCESSMODE_1T: |
|
|
return Math.floor(ooff * 0.0078125); // divide by 128 |
|
|
return Math.floor(ooff * 0.0078125); // divide by 128 |
|
|
|
|
|
case NESBank.ACCESSMODE_2T: |
|
|
|
|
|
return Math.floor(ooff * 0.015625); // divide by 64 |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case NESBank.ACCESSMODE_1K: |
|
|
case NESBank.ACCESSMODE_1K: |
|
|
|
|
|
|
|
|
return ooff * 2; |
|
|
return ooff * 2; |
|
|
case NESBank.ACCESSMODE_1T: |
|
|
case NESBank.ACCESSMODE_1T: |
|
|
return Math.floor(ooff * 0.015625); // divide by 64 |
|
|
return Math.floor(ooff * 0.015625); // divide by 64 |
|
|
|
|
|
case NESBank.ACCESSMODE_2T: |
|
|
|
|
|
return Math.floor(ooff * 0.03125); // divide by 32 |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case NESBank.ACCESSMODE_1T: |
|
|
case NESBank.ACCESSMODE_1T: |
|
|
|
|
|
|
|
|
return ooff * 128; |
|
|
return ooff * 128; |
|
|
case NESBank.ACCESSMODE_1K: |
|
|
case NESBank.ACCESSMODE_1K: |
|
|
return ooff * 64; |
|
|
return ooff * 64; |
|
|
|
|
|
case NESBank.ACCESSMODE_2T: |
|
|
|
|
|
return (Math.floor(ooff / 16)*32) + (ooff % 16); |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
case NESBank.ACCESSMODE_2T: |
|
|
|
|
|
switch(omode){ |
|
|
|
|
|
case NESBank.ACCESSMODE_4K: |
|
|
|
|
|
return ooff * 128; |
|
|
|
|
|
case NESBank.ACCESSMODE_2K: |
|
|
|
|
|
return ooff * 64; |
|
|
|
|
|
case NESBank.ACCESSMODE_1K: |
|
|
|
|
|
return ooff * 32; |
|
|
|
|
|
case NESBank.ACCESSMODE_1T: |
|
|
|
|
|
let _off = (ooff >= 128) ? ooff - 128 : ooff; |
|
|
|
|
|
return ((ooff >= 128) ? 256 : 0) + ((Math.floor(_off / 16)*32) + (_off % 16)); |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var handle_datachanged = Utils.debounce((function(side, idx){ |
|
|
var handle_datachanged = Utils.debounce((function(side, idx){ |
|
|
var sendEmit = false; |
|
|
var sendEmit = false; |
|
|
switch(this.__AccessMode){ |
|
|
switch(this.__AccessMode){ |
|
|
|
|
|
case NESBank.ACCESSMODE_2T: |
|
|
|
|
|
if (side === Math.floor(this.__AccessOffset / 128)){ |
|
|
|
|
|
if (idx === this.__AccessOffset) |
|
|
|
|
|
sendEmit = true; |
|
|
|
|
|
} |
|
|
case NESBank.ACCESSMODE_1T: |
|
|
case NESBank.ACCESSMODE_1T: |
|
|
if (side === Math.floor(this.__AccessOffset / 256)){ |
|
|
if (side === Math.floor(this.__AccessOffset / 256)){ |
|
|
if (idx === this.__AccessOffset) |
|
|
if (idx === this.__AccessOffset) |
|
|
|
|
|
|
|
|
case NESBank.ACCESSMODE_1T: |
|
|
case NESBank.ACCESSMODE_1T: |
|
|
this.__AccessMode = NESBank.ACCESSMODE_1T; |
|
|
this.__AccessMode = NESBank.ACCESSMODE_1T; |
|
|
break; |
|
|
break; |
|
|
|
|
|
case NESBank.ACCESSMODE_2T: |
|
|
|
|
|
this.__AccessMode = NESBank.ACCESSMODE_2T; |
|
|
|
|
|
break; |
|
|
default: |
|
|
default: |
|
|
throw new ValueError("Unknown Access Mode."); |
|
|
|
|
|
|
|
|
throw new Error("Unknown Access Mode."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.__AccessOffset = AdjOffsetToNewMode(m, oam, this.__AccessOffset); |
|
|
this.__AccessOffset = AdjOffsetToNewMode(m, oam, this.__AccessOffset); |
|
|
|
|
|
|
|
|
case NESBank.ACCESSMODE_1T: |
|
|
case NESBank.ACCESSMODE_1T: |
|
|
if (o < 0 || o >= 512) |
|
|
if (o < 0 || o >= 512) |
|
|
throw new RangeError("Access Offset is out of bounds based on current Access Mode."); |
|
|
throw new RangeError("Access Offset is out of bounds based on current Access Mode."); |
|
|
|
|
|
break; |
|
|
|
|
|
case NESBank.ACCESSMODE_2T: |
|
|
|
|
|
if (o < 0 || o >= 256) |
|
|
|
|
|
throw new RangeError("Access Offset is out of bounds based on current Access Mode."); |
|
|
|
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.__AccessOffset = o; |
|
|
this.__AccessOffset = o; |
|
|
|
|
|
|
|
|
return 8; |
|
|
return 8; |
|
|
case NESBank.ACCESSMODE_1T: |
|
|
case NESBank.ACCESSMODE_1T: |
|
|
return 512; |
|
|
return 512; |
|
|
|
|
|
case NESBank.ACCESSMODE_2T: |
|
|
|
|
|
return 256; |
|
|
} |
|
|
} |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var list = (this.__AccessOffset < 256) ? this.__LP : this.__RP; |
|
|
var list = (this.__AccessOffset < 256) ? this.__LP : this.__RP; |
|
|
var idx = this.__AccessOffset % 256; |
|
|
var idx = this.__AccessOffset % 256; |
|
|
buff = list[idx].chr; |
|
|
buff = list[idx].chr; |
|
|
|
|
|
break; |
|
|
|
|
|
case NESBank.ACCESSMODE_2T: |
|
|
|
|
|
var list = (this.__AccessOffset < 128) ? this.__LP : this.__RP; |
|
|
|
|
|
var off = this.__AccessOffset % 128; |
|
|
|
|
|
var idx = ((Math.floor(off / 16)*32) + (off % 16)); |
|
|
|
|
|
buff = new Uint8Array(32); |
|
|
|
|
|
buff.set(list[idx].chr, 0); |
|
|
|
|
|
buff.set(list[idx+16].chr, 16); |
|
|
|
|
|
break; |
|
|
} |
|
|
} |
|
|
return buff; |
|
|
return buff; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
get width(){ |
|
|
get width(){ |
|
|
if (this.__AccessMode == NESBank.ACCESSMODE_8K) |
|
|
if (this.__AccessMode == NESBank.ACCESSMODE_8K) |
|
|
return 256; |
|
|
return 256; |
|
|
if (this.__AccessMode == NESBank.ACCESSMODE_1T) |
|
|
|
|
|
|
|
|
if (this.__AccessMode == NESBank.ACCESSMODE_1T || this.__AccessMode == NESBank.ACCESSMODE_2T) |
|
|
return 8; |
|
|
return 8; |
|
|
return 128; |
|
|
return 128; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return 32; |
|
|
return 32; |
|
|
case NESBank.ACCESSMODE_1T: |
|
|
case NESBank.ACCESSMODE_1T: |
|
|
return 8; |
|
|
return 8; |
|
|
|
|
|
case NESBank.ACCESSMODE_2T: |
|
|
|
|
|
return 16; |
|
|
} |
|
|
} |
|
|
return 128; |
|
|
return 128; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
idx += 16; |
|
|
idx += 16; |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
|
|
|
case 32: |
|
|
|
|
|
if (offset < 0) |
|
|
|
|
|
offset = AdjOffsetToNewMode(NESBank.ACCESSMODE_2T, this.__AccessMode, this.__AccessOffset); |
|
|
|
|
|
if (offset >= 256) |
|
|
|
|
|
throw new RangeError("Offset mismatch based on Buffer length."); |
|
|
|
|
|
var list = (offset < 128) ? this.__LP : this.__RP; |
|
|
|
|
|
var off = offset % 128; |
|
|
|
|
|
var idx = ((Math.floor(off / 32)*16) + (off % 16)); |
|
|
|
|
|
list[idx].chr = buff.slice(0, 16); |
|
|
|
|
|
list[idx+16].char = buff.slice(16, 32); |
|
|
|
|
|
break; |
|
|
case 16: |
|
|
case 16: |
|
|
if (offset < 0) |
|
|
if (offset < 0) |
|
|
offset = AdjOffsetToNewMode(NESBank.ACCESSMODE_1T, this.__AccessMode, this.__AccessOffset); |
|
|
offset = AdjOffsetToNewMode(NESBank.ACCESSMODE_1T, this.__AccessMode, this.__AccessOffset); |
|
|
|
|
|
|
|
|
NESBank.ACCESSMODE_1K = 1; |
|
|
NESBank.ACCESSMODE_1K = 1; |
|
|
NESBank.ACCESSMODE_2K = 2; |
|
|
NESBank.ACCESSMODE_2K = 2; |
|
|
NESBank.ACCESSMODE_4K = 3; |
|
|
NESBank.ACCESSMODE_4K = 3; |
|
|
NESBank.ACCESSMODE_1T = 4; |
|
|
|
|
|
|
|
|
NESBank.ACCESSMODE_1T = 4; // 8x8 Tile size |
|
|
|
|
|
NESBank.ACCESSMODE_2T = 5; // 8x16 Tile size |
|
|
|
|
|
|