浏览代码

NESBank can now be narrowed down to specific tile/sprite.

dev
Bryan Miller 6 年前
父节点
当前提交
ffb4d1362a
共有 1 个文件被更改,包括 56 次插入1 次删除
  1. +56
    -1
      app/js/models/NESBank.js

+ 56
- 1
app/js/models/NESBank.js 查看文件

off -= (off > 3) ? 4 : 0; off -= (off > 3) ? 4 : 0;
res.tileidx = (off * 64) + ((Math.floor(y/8) * 16) + Math.floor(x / 8)); res.tileidx = (off * 64) + ((Math.floor(y/8) * 16) + Math.floor(x / 8));
break; break;
case NESBank.ACCESSMODE_1T:
res.side = (off >= 256) ? 1 : 0;
res.tileidx = (off >= 256) ? off - 256 : off;
break;
} }


res.x = x%8; res.x = x%8;
return Math.floor(ooff * 0.5); return Math.floor(ooff * 0.5);
case NESBank.ACCESSMODE_1K: case NESBank.ACCESSMODE_1K:
return Math.floor(ooff * 0.25); return Math.floor(ooff * 0.25);
case NESBank.ACCESSMODE_1T:
return Math.floor(ooff / 256);
} }
} }
return ooff; return ooff;
return ooff * 2; return ooff * 2;
case NESBank.ACCESSMODE_1K: case NESBank.ACCESSMODE_1K:
return Math.floor(ooff * 0.5); return Math.floor(ooff * 0.5);
case NESBank.ACCESSMODE_1T:
return Math.floor(ooff * 0.0078125); // divide by 128
} }
break; break;
case NESBank.ACCESSMODE_1K: case NESBank.ACCESSMODE_1K:
return ooff * 4; return ooff * 4;
case NESBank.ACCESSMODE_2K: case NESBank.ACCESSMODE_2K:
return ooff * 2; return ooff * 2;
case NESBank.ACCESSMODE_1T:
return Math.floor(ooff * 0.015625); // divide by 64
}
break;
case NESBank.ACCESSMODE_1T:
switch(omode){
case NESBank.ACCESSMODE_4K:
return ooff * 256;
case NESBank.ACCESSMODE_2K:
return ooff * 128;
case NESBank.ACCESSMODE_1K:
return ooff * 64;
} }
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_1T:
if (side === Math.floor(this.__AccessOffset / 256)){
if (idx === this.__AccessOffset)
sendEmit = true;
}
case NESBank.ACCESSMODE_1K: case NESBank.ACCESSMODE_1K:
if (side === Math.floor(this.__AccessOffset / 4)){ if (side === Math.floor(this.__AccessOffset / 4)){
if (Math.floor(idx / 64) === Math.floor(this.__AccessOffset/4)) if (Math.floor(idx / 64) === Math.floor(this.__AccessOffset/4))
case NESBank.ACCESSMODE_1K: case NESBank.ACCESSMODE_1K:
this.__AccessMode = NESBank.ACCESSMODE_1K; this.__AccessMode = NESBank.ACCESSMODE_1K;
break; break;
case NESBank.ACCESSMODE_1T:
this.__AccessMode = NESBank.ACCESSMODE_1T;
break;
default: default:
throw new ValueError("Unknown Access Mode."); throw new ValueError("Unknown Access Mode.");
} }
if (o < 0 || o >= 8) if (o < 0 || o >= 8)
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; break;
case NESBank.ACCESSMODE_1T:
if (o < 0 || o >= 512)
throw new RangeError("Access Offset is out of bounds based on current Access Mode.");
} }


this.__AccessOffset = o; this.__AccessOffset = o;
return 4; return 4;
case NESBank.ACCESSMODE_1K: case NESBank.ACCESSMODE_1K:
return 8; return 8;
case NESBank.ACCESSMODE_1T:
return 512;
} }
return 0; return 0;
} }
offset += 16; offset += 16;
} }
break; break;
case NESBank.ACCESSMODE_1T:
var list = (this.__AccessOffset < 256) ? this.__LP : this.__RP;
var idx = this.__AccessOffset % 256;
buff = list[idx].chr;
} }
return buff; return buff;
} }
} }
} }


get width(){return (this.__AccessMode == NESBank.ACCESSMODE_8K) ? 256 : 128;}
get width(){
if (this.__AccessMode == NESBank.ACCESSMODE_8K)
return 256;
if (this.__AccessMode == NESBank.ACCESSMODE_1T)
return 8;
return 128;
}
get height(){ get height(){
switch(this.__AccessMode){ switch(this.__AccessMode){
case NESBank.ACCESSMODE_2K: case NESBank.ACCESSMODE_2K:
return 64; return 64;
case NESBank.ACCESSMODE_1K: case NESBank.ACCESSMODE_1K:
return 32; return 32;
case NESBank.ACCESSMODE_1T:
return 8;
} }
return 128; return 128;
} }
idx += 16; idx += 16;
} }
break; break;
case 16:
if (offset < 0)
offset = AdjOffsetToNewMode(NESBank.ACCESSMODE_1T, this.__AccessMode, this.__AccessOffset);
if (offset >= 512)
throw new RangeError("Offset mismatch based on Buffer length.");
var list = (offset < 256) ? this.__LP : this.__RP;
var idx = offset % 256;
list[idx].chr = buff;
break;
default: default:
throw new RangeError("Buffer length does not match any of the supported bank sizes."); throw new RangeError("Buffer length does not match any of the supported bank sizes.");
} }
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;

正在加载...
取消
保存