├── .babelrc ├── .eslintignore ├── .gitignore ├── README.md ├── package.json ├── public ├── image │ ├── screenshot1.png │ ├── screenshot2.png │ └── screenshot3.png ├── index.html ├── js │ └── main.js └── rom │ ├── bad_apple_2_5.nes │ ├── megaari.nes │ ├── nestest.nes │ └── nittori.nes ├── src └── js │ ├── Mapper │ ├── 0.js │ ├── 1.js │ ├── 10.js │ ├── 101.js │ ├── 118.js │ ├── 119.js │ ├── 140.js │ ├── 152.js │ ├── 16.js │ ├── 18.js │ ├── 180.js │ ├── 184.js │ ├── 185.js │ ├── 19.js │ ├── 2.js │ ├── 207.js │ ├── 22.js │ ├── 23.js │ ├── 24.js │ ├── 25.js │ ├── 26.js │ ├── 3.js │ ├── 32.js │ ├── 33.js │ ├── 34.js │ ├── 4.js │ ├── 48.js │ ├── 5.js │ ├── 65.js │ ├── 66.js │ ├── 67.js │ ├── 68.js │ ├── 69.js │ ├── 7.js │ ├── 70.js │ ├── 72.js │ ├── 73.js │ ├── 75.js │ ├── 76.js │ ├── 77.js │ ├── 78.js │ ├── 80.js │ ├── 82.js │ ├── 85.js │ ├── 86.js │ ├── 87.js │ ├── 88.js │ ├── 89.js │ ├── 9.js │ ├── 92.js │ ├── 93.js │ ├── 94.js │ ├── 95.js │ ├── 97.js │ └── Base.js │ ├── NES.js │ └── main.js ├── todo.txt └── webpack.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | presets: [ 3 | "@babel/preset-env", 4 | ["env", { modules: false }] 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | public/js/main.js 2 | public/js/main.min.js 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .DS_Store 3 | package-lock.json 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FaithJS 2 | FaithJS is a JavaScript NES emulator which runs on your chrome. 3 | 4 | # Demo 5 | [Demo](https://sairoutine.github.io/faithjs/public/) 6 | 7 | # Screenshot 8 | ![](public/image/screenshot1.png) 9 | ![](public/image/screenshot2.png) 10 | ![](public/image/screenshot3.png) 11 | 12 | 13 | # How to build 14 | To run locally: 15 | ``` 16 | $ npm install 17 | $ npm run watch 18 | ``` 19 | And it'll be available at http://localhost:3000/ 20 | 21 | To build a distribution: 22 | ``` 23 | $ npm run build 24 | ``` 25 | This will create `main.js`. 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "faithjs", 3 | "version": "0.0.1", 4 | "description": "FaithJS is a NES emulator which runs on your chrome.", 5 | "main": "index.js", 6 | "scripts": { 7 | "watch": "webpack-dev-server", 8 | "build": "MODE=production webpack --progress" 9 | }, 10 | "author": "sairoutine", 11 | "license": "MIT", 12 | "devDependencies": { 13 | "@babel/preset-env": "7.16.4", 14 | "@babel/register": "7.16.0", 15 | "babel-core": "6.26.3", 16 | "babel-loader": "8.2.3", 17 | "babel-minify": "0.5.1", 18 | "babel-preset-env": "1.7.0", 19 | "babel-preset-es2015": "6.24.1", 20 | "electron-packager": "15.4.0", 21 | "electron": "16.0.4", 22 | "eslint": "7.32.0", 23 | "eslint-loader": "3.0.3", 24 | "extract-text-webpack-plugin": "4.0.0-beta.0", 25 | "webpack": "5.65.0", 26 | "webpack-build-notifier": "2.3.0", 27 | "webpack-cli": "4.9.1", 28 | "webpack-dev-server": "4.6.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /public/image/screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sairoutine/faithjs/f9b0c693573f0bfe68a66e7ba1989def881a3150/public/image/screenshot1.png -------------------------------------------------------------------------------- /public/image/screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sairoutine/faithjs/f9b0c693573f0bfe68a66e7ba1989def881a3150/public/image/screenshot2.png -------------------------------------------------------------------------------- /public/image/screenshot3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sairoutine/faithjs/f9b0c693573f0bfe68a66e7ba1989def881a3150/public/image/screenshot3.png -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | FaithJS 4 | 5 | 6 | 7 | 8 | Unsupported CANVAS 9 | 10 |
11 | ROM選択: 12 | 18 | 19 |
20 |
21 | 22 | 23 | ROMファイル(.nes)を選択または、ドラッグ&ドロップすることで
24 | 自分の持っているROMファイルも遊べます。
25 | 26 |
27 |
28 |
29 | 30 | 31 | 32 |
33 |
34 | 35 | 操作方法
36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
1P2P
AZNum 7
BXNum 9
STARTEnter
SELECTShift
UPNum 8
DOWNNum 2
LEFTNum 4
RIGHTNum 6
47 | 48 |
49 | 「Bad Apple!! PV-FC 2.5」「MegaAri」「河童ニットリちゃん」
50 | については私の制作物ではなく、
51 | Little Limit 門真 なむ様の作成されたものを
52 | 利用させていただいております。
53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /public/rom/bad_apple_2_5.nes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sairoutine/faithjs/f9b0c693573f0bfe68a66e7ba1989def881a3150/public/rom/bad_apple_2_5.nes -------------------------------------------------------------------------------- /public/rom/megaari.nes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sairoutine/faithjs/f9b0c693573f0bfe68a66e7ba1989def881a3150/public/rom/megaari.nes -------------------------------------------------------------------------------- /public/rom/nestest.nes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sairoutine/faithjs/f9b0c693573f0bfe68a66e7ba1989def881a3150/public/rom/nestest.nes -------------------------------------------------------------------------------- /public/rom/nittori.nes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sairoutine/faithjs/f9b0c693573f0bfe68a66e7ba1989def881a3150/public/rom/nittori.nes -------------------------------------------------------------------------------- /src/js/Mapper/0.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | 5 | /**** Mapper0 ****/ 6 | var Mapper0 = function(nes) { 7 | Base.apply(this, arguments); 8 | }; 9 | 10 | Mapper0.prototype = Object.create(Base.prototype); 11 | 12 | Mapper0.prototype.Init = function() { 13 | this.nes.SetPrgRomPage(0, 0); 14 | this.nes.SetPrgRomPage(1, this.nes.PrgRomPageCount - 1); 15 | this.nes.SetChrRomPage(0); 16 | }; 17 | 18 | 19 | module.exports = Mapper0; 20 | -------------------------------------------------------------------------------- /src/js/Mapper/1.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | 5 | /**** Mapper1 ****/ 6 | var Mapper1 = function(nes) { 7 | Base.apply(this, arguments); 8 | this.MAPPER_REG = new Array(16); 9 | }; 10 | 11 | Mapper1.prototype = Object.create(Base.prototype); 12 | 13 | Mapper1.prototype.Init = function() { 14 | var i; 15 | for(i=0; i> 13; 73 | this.MAPPER_REG[reg_num] = this.MAPPER_REG[14]; 74 | 75 | this.MAPPER_REG[13] = 0; 76 | this.MAPPER_REG[14] = 0x00; 77 | 78 | var bank_num; 79 | 80 | switch (reg_num) { 81 | case 0 : 82 | if((this.MAPPER_REG[0] & 0x02) !== 0) { 83 | if((this.MAPPER_REG[0] & 0x01) !== 0) { 84 | this.nes.SetMirror(true); 85 | } else { 86 | this.nes.SetMirror(false); 87 | } 88 | } else { 89 | if((this.MAPPER_REG[0] & 0x01) !== 0) { 90 | this.nes.SetMirrors(1, 1, 1, 1); 91 | } else { 92 | this.nes.SetMirrors(0, 0, 0, 0); 93 | } 94 | } 95 | break; 96 | 97 | case 1 : 98 | bank_num = this.MAPPER_REG[1]; 99 | if(this.MAPPER_REG[10] === 2) { 100 | if((this.MAPPER_REG[0] & 0x10) !== 0) { 101 | if(this.MAPPER_REG[12] !== 0) { 102 | this.MAPPER_REG[11] = (this.MAPPER_REG[1] & 0x10) >> 4; 103 | if((this.MAPPER_REG[0] & 0x08) !== 0) { 104 | this.MAPPER_REG[11] |= ((this.MAPPER_REG[2] & 0x10) >> 3); 105 | } 106 | this.SetPrgRomPages8K_Mapper01(); 107 | this.MAPPER_REG[12] = 0; 108 | } else { 109 | this.MAPPER_REG[12] = 1; 110 | } 111 | } else { 112 | this.MAPPER_REG[11] = (this.MAPPER_REG[1] & 0x10) !== 0 ? 3 : 0; 113 | this.SetPrgRomPages8K_Mapper01(); 114 | } 115 | } else if((this.MAPPER_REG[10] === 1) && (this.nes.ChrRomPageCount === 0)) { 116 | this.MAPPER_REG[11] = (this.MAPPER_REG[1] & 0x10) >> 4; 117 | this.SetPrgRomPages8K_Mapper01(); 118 | } else if(this.nes.ChrRomPageCount !== 0) { 119 | if((this.MAPPER_REG[0] & 0x10) !== 0) { 120 | bank_num <<= 2; 121 | this.nes.SetChrRomPage1K(0, bank_num + 0); 122 | this.nes.SetChrRomPage1K(1, bank_num + 1); 123 | this.nes.SetChrRomPage1K(2, bank_num + 2); 124 | this.nes.SetChrRomPage1K(3, bank_num + 3); 125 | } else { 126 | bank_num <<= 2; 127 | this.nes.SetChrRomPages1K(bank_num + 0, bank_num + 1, bank_num + 2, bank_num + 3, 128 | bank_num + 4, bank_num + 5, bank_num + 6, bank_num + 7); 129 | } 130 | } else { 131 | if((this.MAPPER_REG[0] & 0x10) !== 0) { 132 | bank_num <<= 2; 133 | this.nes.VRAM[0] = this.nes.VRAMS[bank_num + 0]; 134 | this.nes.VRAM[1] = this.nes.VRAMS[bank_num + 1]; 135 | this.nes.VRAM[2] = this.nes.VRAMS[bank_num + 2]; 136 | this.nes.VRAM[3] = this.nes.VRAMS[bank_num + 3]; 137 | } 138 | } 139 | break; 140 | 141 | case 2 : 142 | bank_num = this.MAPPER_REG[2]; 143 | 144 | if((this.MAPPER_REG[10] === 2) && (this.MAPPER_REG[0] & 0x08) !== 0) { 145 | if(this.MAPPER_REG[12] !== 0) { 146 | this.MAPPER_REG[11] = (this.MAPPER_REG[1] & 0x10) >> 4; 147 | this.MAPPER_REG[11] |= ((this.MAPPER_REG[2] & 0x10) >> 3); 148 | this.SetPrgRomPages8K_Mapper01(); 149 | this.MAPPER_REG[12] = 0; 150 | } else { 151 | this.MAPPER_REG[12] = 1; 152 | } 153 | } 154 | 155 | if(this.nes.ChrRomPageCount === 0) { 156 | if((this.MAPPER_REG[0] & 0x10) !== 0) { 157 | bank_num <<= 2; 158 | this.nes.VRAM[4] = this.nes.VRAMS[bank_num + 0]; 159 | this.nes.VRAM[5] = this.nes.VRAMS[bank_num + 1]; 160 | this.nes.VRAM[6] = this.nes.VRAMS[bank_num + 2]; 161 | this.nes.VRAM[7] = this.nes.VRAMS[bank_num + 3]; 162 | break; 163 | } 164 | } 165 | 166 | if((this.MAPPER_REG[0] & 0x10) !== 0) { 167 | bank_num <<= 2; 168 | this.nes.SetChrRomPage1K(4, bank_num + 0); 169 | this.nes.SetChrRomPage1K(5, bank_num + 1); 170 | this.nes.SetChrRomPage1K(6, bank_num + 2); 171 | this.nes.SetChrRomPage1K(7, bank_num + 3); 172 | } 173 | break; 174 | 175 | 176 | case 3 : 177 | bank_num = this.MAPPER_REG[3]; 178 | 179 | if((this.MAPPER_REG[0] & 0x08) !== 0) { 180 | bank_num <<= 1; 181 | 182 | if((this.MAPPER_REG[0] & 0x04) !== 0) { 183 | this.MAPPER_REG[4] = bank_num; 184 | this.MAPPER_REG[5] = bank_num + 1; 185 | this.MAPPER_REG[6] = this.MAPPER_REG[8]; 186 | this.MAPPER_REG[7] = this.MAPPER_REG[9]; 187 | } else { 188 | if(this.MAPPER_REG[10] === 0) { 189 | this.MAPPER_REG[4] = 0; 190 | this.MAPPER_REG[5] = 1; 191 | this.MAPPER_REG[6] = bank_num; 192 | this.MAPPER_REG[7] = bank_num + 1; 193 | } 194 | } 195 | } else { 196 | bank_num <<= 1; 197 | this.MAPPER_REG[4] = bank_num; 198 | this.MAPPER_REG[5] = bank_num + 1; 199 | if(this.MAPPER_REG[10] === 0) { 200 | this.MAPPER_REG[6] = bank_num + 2; 201 | this.MAPPER_REG[7] = bank_num + 3; 202 | } 203 | } 204 | 205 | this.SetPrgRomPages8K_Mapper01(); 206 | break; 207 | } 208 | }; 209 | 210 | Mapper1.prototype.SetPrgRomPages8K_Mapper01 = function (){ 211 | this.nes.SetPrgRomPage8K(0, (this.MAPPER_REG[11] << 5) + (this.MAPPER_REG[4] & 31)); 212 | this.nes.SetPrgRomPage8K(1, (this.MAPPER_REG[11] << 5) + (this.MAPPER_REG[5] & 31)); 213 | this.nes.SetPrgRomPage8K(2, (this.MAPPER_REG[11] << 5) + (this.MAPPER_REG[6] & 31)); 214 | this.nes.SetPrgRomPage8K(3, (this.MAPPER_REG[11] << 5) + (this.MAPPER_REG[7] & 31)); 215 | }; 216 | 217 | module.exports = Mapper1; 218 | -------------------------------------------------------------------------------- /src/js/Mapper/10.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper10 ****/ 5 | var Mapper10 = function(nes) {//<-- 6 | Base.apply(this, arguments); 7 | //this.MAPPER_REG = new Array(6); 8 | this.MAPPER_REG = new Array(4); 9 | this.MAPPER_Latch0 = true; 10 | this.MAPPER_Latch1 = true; 11 | }; 12 | 13 | Mapper10.prototype = Object.create(Base.prototype); 14 | 15 | Mapper10.prototype.Init = function() { 16 | this.nes.SetPrgRomPages8K(0, 0, this.nes.PrgRomPageCount * 2 - 2, this.nes.PrgRomPageCount * 2 - 1); 17 | this.nes.SetChrRomPages1K(0, 0, 0, 0, 0, 0, 0, 0); 18 | for(var i=0; i> 12) | (this.nes.IO1[0x00] & 0x10) << 8; 58 | var nameAddrHigh = nameAddr >> 10; 59 | var nameAddrLow = nameAddr & 0x03FF; 60 | var tmpVRAMHigh = tmpVRAM[nameAddrHigh]; 61 | var tmpPaletteArray = this.nes.PaletteArray; 62 | var tmpSPBitArray = this.nes.SPBitArray; 63 | 64 | var q = 0; 65 | var s = this.nes.HScrollTmp; 66 | 67 | for(var p=0; p<33; p++) { 68 | var ptnDist = (tmpVRAMHigh[nameAddrLow] << 4) | tableAddr; 69 | var tmpptnDist = ptnDist; 70 | 71 | this.SetChrRom(tmpptnDist); 72 | 73 | var tmpSrcV = tmpVRAM[ptnDist >> 10]; 74 | ptnDist &= 0x03FF; 75 | var attr = ((tmpVRAMHigh[((nameAddrLow & 0x0380) >> 4) | ((nameAddrLow & 0x001C) >> 2) + 0x03C0] << 2) >> (((nameAddrLow & 0x0040) >> 4) | (nameAddrLow & 0x0002))) & 0x0C; 76 | var ptn = tmpSPBitArray[tmpSrcV[ptnDist]][tmpSrcV[ptnDist + 8]]; 77 | 78 | for(; s<8; s++, q++) 79 | tmpBgLineBuffer[q] = tmpPaletteArray[ptn[s] | attr]; 80 | s = 0; 81 | 82 | this.SetLatch(tmpptnDist); 83 | 84 | if((nameAddrLow & 0x001F) === 0x001F) { 85 | nameAddrLow &= 0xFFE0; 86 | tmpVRAMHigh = tmpVRAM[(nameAddrHigh ^= 0x01)]; 87 | } else 88 | nameAddrLow++; 89 | } 90 | }; 91 | 92 | Mapper10.prototype.SetLatch = function (addr) { 93 | addr &= 0x1FF0; 94 | if(addr === 0x0FD0) 95 | this.MAPPER_Latch0 = false; 96 | //this.MAPPER_REG[4] = false; 97 | if(addr === 0x1FD0) 98 | this.MAPPER_Latch1 = false; 99 | //this.MAPPER_REG[5] = false; 100 | if(addr === 0x0FE0) 101 | this.MAPPER_Latch0 = true; 102 | //this.MAPPER_REG[4] = true; 103 | if(addr === 0x1FE0) 104 | this.MAPPER_Latch1 = true; 105 | //this.MAPPER_REG[5] = true; 106 | }; 107 | 108 | Mapper10.prototype.SetChrRom = function (addr) { 109 | if((addr & 0x1000) === 0x0000) { 110 | if(!this.MAPPER_Latch0) { 111 | //if(!this.MAPPER_REG[4]) { 112 | this.nes.SetChrRomPage1K(0, this.MAPPER_REG[0] * 4); 113 | this.nes.SetChrRomPage1K(1, this.MAPPER_REG[0] * 4 + 1); 114 | this.nes.SetChrRomPage1K(2, this.MAPPER_REG[0] * 4 + 2); 115 | this.nes.SetChrRomPage1K(3, this.MAPPER_REG[0] * 4 + 3); 116 | } else { 117 | this.nes.SetChrRomPage1K(0, this.MAPPER_REG[1] * 4); 118 | this.nes.SetChrRomPage1K(1, this.MAPPER_REG[1] * 4 + 1); 119 | this.nes.SetChrRomPage1K(2, this.MAPPER_REG[1] * 4 + 2); 120 | this.nes.SetChrRomPage1K(3, this.MAPPER_REG[1] * 4 + 3); 121 | } 122 | } else { 123 | if(!this.MAPPER_Latch1) { 124 | //if(!this.MAPPER_REG[5]) { 125 | this.nes.SetChrRomPage1K(4, this.MAPPER_REG[2] * 4); 126 | this.nes.SetChrRomPage1K(5, this.MAPPER_REG[2] * 4 + 1); 127 | this.nes.SetChrRomPage1K(6, this.MAPPER_REG[2] * 4 + 2); 128 | this.nes.SetChrRomPage1K(7, this.MAPPER_REG[2] * 4 + 3); 129 | } else { 130 | this.nes.SetChrRomPage1K(4, this.MAPPER_REG[3] * 4); 131 | this.nes.SetChrRomPage1K(5, this.MAPPER_REG[3] * 4 + 1); 132 | this.nes.SetChrRomPage1K(6, this.MAPPER_REG[3] * 4 + 2); 133 | this.nes.SetChrRomPage1K(7, this.MAPPER_REG[3] * 4 + 3); 134 | } 135 | } 136 | }; 137 | 138 | Mapper10.prototype.BuildSpriteLine = function () { 139 | var tmpBgLineBuffer = this.nes.BgLineBuffer; 140 | var tmpIsSpriteClipping = (this.nes.IO1[0x01] & 0x04) === 0x04 ? 0 : 8; 141 | 142 | if((this.nes.IO1[0x01] & 0x10) === 0x10) { 143 | var tmpSpLine = this.nes.SpriteLineBuffer; 144 | for(var p=0; p<256; p++) 145 | tmpSpLine[p] = 256; 146 | 147 | var tmpSpRAM = this.nes.SPRITE_RAM; 148 | var tmpBigSize = (this.nes.IO1[0x00] & 0x20) === 0x20 ? 16 : 8; 149 | var tmpSpPatternTableAddress = (this.nes.IO1[0x00] & 0x08) << 9; 150 | 151 | var tmpVRAM = this.nes.VRAM; 152 | var tmpSPBitArray = this.nes.SPBitArray; 153 | 154 | var lineY = this.nes.PpuY; 155 | var count = 0; 156 | 157 | for(var i=0; i<=252; i+=4) { 158 | var isy = tmpSpRAM[i] + 1; 159 | if(isy > lineY || (isy + tmpBigSize) <= lineY) 160 | continue; 161 | 162 | if(i === 0) 163 | this.nes.Sprite0Line = true; 164 | 165 | if(++count === 9) { 166 | i = 256; 167 | continue; 168 | } 169 | 170 | var x = tmpSpRAM[i + 3]; 171 | var ex = x + 8; 172 | if(ex > 256) 173 | ex = 256; 174 | 175 | var attr = tmpSpRAM[i + 2]; 176 | 177 | var attribute = ((attr & 0x03) << 2) | 0x10; 178 | var bgsp = attr & 0x20; 179 | 180 | var iy = (attr & 0x80) === 0x80 ? tmpBigSize - 1 - (lineY - isy) : lineY - isy; 181 | var tileNum = ((iy & 0x08) << 1) + (iy & 0x07) + 182 | (tmpBigSize === 8 ? (tmpSpRAM[i + 1] << 4) + tmpSpPatternTableAddress : ((tmpSpRAM[i + 1] & 0xFE) << 4) + ((tmpSpRAM[i + 1] & 0x01) << 12)); 183 | 184 | this.SetChrRom(tileNum); 185 | 186 | var tmpHigh = tmpVRAM[tileNum >> 10]; 187 | var tmpLow = tileNum & 0x03FF; 188 | var ptn = tmpSPBitArray[tmpHigh[tmpLow]][tmpHigh[tmpLow + 8]]; 189 | 190 | var is; 191 | var ia; 192 | if((attr & 0x40) === 0x00) { 193 | is = 0; 194 | ia = 1; 195 | } else { 196 | is = 7; 197 | ia = -1; 198 | } 199 | 200 | for(; x= tmpIsSpriteClipping && (bgsp === 0x00 || tmpBgLineBuffer[x] === 0x10)) 206 | tmpBgLineBuffer[x] = tmpPtn | attribute; 207 | } 208 | } 209 | 210 | this.SetLatch(tileNum); 211 | } 212 | 213 | if(count >= 8) 214 | this.nes.IO1[0x02] |= 0x20; 215 | else 216 | this.nes.IO1[0x02] &= 0xDF; 217 | } 218 | }; 219 | 220 | Mapper10.prototype.GetState = function() { 221 | this.nes.StateData.Mapper = {}; 222 | this.nes.StateData.Mapper.MAPPER_REG = this.MAPPER_REG.slice(0); 223 | 224 | this.nes.StateData.Mapper.MAPPER_Latch0 = this.MAPPER_Latch0; 225 | this.nes.StateData.Mapper.MAPPER_Latch1 = this.MAPPER_Latch1; 226 | }; 227 | 228 | Mapper10.prototype.SetState = function() { 229 | for(var i=0; i> 3; 20 | this.nes.SetPrgRomPage(0, tmp); 21 | this.nes.SetPrgRomPage(1, tmp + 1); 22 | this.nes.SetChrRomPage(data & 0x0F); 23 | }; 24 | 25 | module.exports = Mapper140; 26 | -------------------------------------------------------------------------------- /src/js/Mapper/152.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | 5 | /**** Mapper152 ****/ 6 | var Mapper152 = function(nes) { 7 | Base.apply(this, arguments); 8 | }; 9 | 10 | Mapper152.prototype = Object.create(Base.prototype); 11 | 12 | Mapper152.prototype.Init = function() { 13 | this.nes.SetPrgRomPage(0, 0); 14 | this.nes.SetPrgRomPage(1, this.nes.PrgRomPageCount - 1); 15 | this.nes.SetChrRomPage(0); 16 | }; 17 | 18 | Mapper152.prototype.WriteSRAM = function(address, data) { 19 | this.nes.SetPrgRomPage(0, (data & 0x70) >> 4); 20 | this.nes.SetChrRomPage(data & 0x0F); 21 | 22 | if((data & 0x80) === 0x80) 23 | this.nes.SetMirrors(0, 0, 0, 0); 24 | else 25 | this.nes.SetMirrors(1, 1, 1, 1); 26 | }; 27 | 28 | module.exports = Mapper152; 29 | -------------------------------------------------------------------------------- /src/js/Mapper/16.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | 5 | /**** Mapper16 ****/ 6 | var Mapper16 = function(nes) { 7 | Base.apply(this, arguments); 8 | this.MAPPER_REG = new Array(5); 9 | 10 | this.EEPROM_ADDRESS = 0; 11 | this.OUT_DATA = 0; 12 | this.BIT_DATA = 0; 13 | this.BIT_DATA_TMP = 0; 14 | this.BIT_COUNTER = 0; 15 | this.READ_WRITE = false; 16 | this.SCL_OLD = false; 17 | this.SCL = false; 18 | this.SDA_OLD = false; 19 | this.SDA = false; 20 | this.STATE = 0; 21 | 22 | this.EEPROM = new Array(256); 23 | for(var i=0; i>> 3; 163 | 164 | this.BIT_DATA = (this.BIT_DATA << 1) & 0xFF; 165 | this.BIT_COUNTER++; 166 | } 167 | return false; 168 | }; 169 | 170 | Mapper16.prototype.BIT_IN = function () { 171 | if(this.BIT_COUNTER === 8) { 172 | this.BIT_COUNTER = 0; 173 | this.OUT_DATA = 0;//ACK; 174 | return true; 175 | } else { 176 | this.BIT_DATA = ((this.BIT_DATA << 1) | (this.SDA ? 0x01 : 0x00)) & 0xFF; 177 | this.BIT_COUNTER++; 178 | } 179 | return false; 180 | }; 181 | 182 | Mapper16.prototype.ReadSRAM = function(address) { 183 | return this.OUT_DATA; 184 | }; 185 | 186 | Mapper16.prototype.WriteSRAM = function(address, data) { 187 | this.Write(address, data); 188 | }; 189 | 190 | Mapper16.prototype.CPUSync = function(clock) { 191 | if(this.MAPPER_REG[0] === 0x01) { 192 | if(this.MAPPER_REG[1] === 0x0000) 193 | this.MAPPER_REG[1] = 0x10000; 194 | 195 | this.MAPPER_REG[1] -= clock; 196 | 197 | if(this.MAPPER_REG[1] <= 0) { 198 | this.SetIRQ(); 199 | this.MAPPER_REG[0] = 0x00; 200 | this.MAPPER_REG[1] = 0x0000; 201 | } 202 | } 203 | }; 204 | 205 | module.exports = Mapper16; 206 | -------------------------------------------------------------------------------- /src/js/Mapper/18.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | 5 | /**** Mapper18 ****/ 6 | var Mapper18 = function(nes) { 7 | Base.apply(this, arguments); 8 | this.MAPPER_REG = new Array(15); 9 | this.IRQ_Counter = 0; 10 | }; 11 | 12 | Mapper18.prototype = Object.create(Base.prototype); 13 | 14 | Mapper18.prototype.Init = function() { 15 | for(var i=0; i= 0x8000 && address < 0xE000) { 25 | var i = ((address & 0x7000) >>> 11) | ((address & 0x0002) >>> 1); 26 | if((address & 0x0001) === 0x0000) 27 | this.MAPPER_REG[i] = (this.MAPPER_REG[i] & 0xF0) | (data & 0x0F); 28 | else 29 | this.MAPPER_REG[i] = (this.MAPPER_REG[i] & 0x0F) | ((data & 0x0F) << 4); 30 | if(i < 3) 31 | this.nes.SetPrgRomPage8K(i, this.MAPPER_REG[i]); 32 | if(i >= 4) 33 | this.nes.SetChrRomPage1K(i - 4, this.MAPPER_REG[i]); 34 | return; 35 | } 36 | 37 | switch (address & 0xF003) { 38 | case 0xE000: 39 | case 0xE001: 40 | case 0xE002: 41 | case 0xE003: 42 | var tmp = (address & 0x0003) * 4; 43 | this.MAPPER_REG[12] = (this.MAPPER_REG[12] & ~(0x000F << tmp)) | ((data & 0x0F) << tmp); 44 | break; 45 | case 0xF000: 46 | this.IRQ_Counter = this.MAPPER_REG[12]; 47 | this.ClearIRQ(); 48 | break; 49 | case 0xF001: 50 | this.MAPPER_REG[13] = data; 51 | this.ClearIRQ(); 52 | break; 53 | case 0xF002: 54 | this.MAPPER_REG[14] = data; 55 | data &= 0x03; 56 | if(data === 0) { 57 | this.nes.SetMirror(true); 58 | } else if(data === 1) { 59 | this.nes.SetMirror(false); 60 | } else if(data === 2) { 61 | this.nes.SetMirrors(0, 0, 0, 0); 62 | } else { 63 | this.nes.SetMirrors(1, 1, 1, 1); 64 | } 65 | break; 66 | } 67 | }; 68 | 69 | Mapper18.prototype.CPUSync = function(clock) { 70 | if((this.MAPPER_REG[13] & 0x01) === 0x01) { 71 | var mask; 72 | switch(this.MAPPER_REG[13] & 0x0E) { 73 | case 0x00: 74 | mask = 0xFFFF; 75 | break; 76 | case 0x02: 77 | mask = 0x0FFF; 78 | break; 79 | case 0x04: 80 | case 0x06: 81 | mask = 0x00FF; 82 | break; 83 | case 0x08: 84 | case 0x0A: 85 | case 0x0C: 86 | case 0x0E: 87 | mask = 0x000F; 88 | break; 89 | } 90 | 91 | var tmp = (this.IRQ_Counter & mask) - clock; 92 | 93 | if(tmp < 0) 94 | this.SetIRQ(); 95 | 96 | this.IRQ_Counter = (this.IRQ_Counter & ~mask) | (tmp & mask); 97 | } 98 | }; 99 | 100 | module.exports = Mapper18; 101 | -------------------------------------------------------------------------------- /src/js/Mapper/180.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper180 ****/ 5 | var Mapper180 = function(nes) { 6 | Base.apply(this, arguments); 7 | }; 8 | 9 | Mapper180.prototype = Object.create(Base.prototype); 10 | 11 | Mapper180.prototype.Init = function() { 12 | this.nes.SetPrgRomPage(0, 0); 13 | this.nes.SetPrgRomPage(1, this.nes.PrgRomPageCount - 1); 14 | this.nes.SetChrRomPage(0); 15 | }; 16 | 17 | Mapper180.prototype.Write = function(address, data) { 18 | this.nes.SetPrgRomPage(1, data); 19 | }; 20 | 21 | module.exports = Mapper180; 22 | -------------------------------------------------------------------------------- /src/js/Mapper/184.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper184 ****/ 5 | var Mapper184 = function(nes) { 6 | Base.apply(this, arguments); 7 | }; 8 | 9 | Mapper184.prototype = Object.create(Base.prototype); 10 | 11 | Mapper184.prototype.Init = function() { 12 | this.nes.SetPrgRomPage(0, 0); 13 | this.nes.SetPrgRomPage(1, this.nes.PrgRomPageCount - 1); 14 | }; 15 | 16 | Mapper184.prototype.WriteSRAM = function(address, data) { 17 | var chrpage = this.nes.ChrRomPageCount * 2 - 1; 18 | var tmp; 19 | tmp = (data & chrpage) * 4; 20 | this.nes.SetChrRomPage1K(0, tmp); 21 | this.nes.SetChrRomPage1K(1, tmp + 1); 22 | this.nes.SetChrRomPage1K(2, tmp + 2); 23 | this.nes.SetChrRomPage1K(3, tmp + 3); 24 | 25 | tmp = ((data >>> 4) & chrpage) * 4; 26 | this.nes.SetChrRomPage1K(4, tmp); 27 | this.nes.SetChrRomPage1K(5, tmp + 1); 28 | this.nes.SetChrRomPage1K(6, tmp + 2); 29 | this.nes.SetChrRomPage1K(7, tmp + 3); 30 | }; 31 | 32 | module.exports = Mapper184; 33 | -------------------------------------------------------------------------------- /src/js/Mapper/185.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper185 ****/ 5 | var Mapper185 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.MAPPER_REG = 0; 8 | this.EX_ChrRom = new Array(0x0400); 9 | }; 10 | 11 | Mapper185.prototype = Object.create(Base.prototype); 12 | 13 | Mapper185.prototype.Init = function() { 14 | for(var i=0; i= 1){ 27 | this.nes.SetChrRomPages1K(this.nes.ChrRomPageCount * 8 - 8, this.nes.ChrRomPageCount * 8 - 7, 28 | this.nes.ChrRomPageCount * 8 - 6, this.nes.ChrRomPageCount * 8 - 5, 29 | this.nes.ChrRomPageCount * 8 - 4, this.nes.ChrRomPageCount * 8 - 3, 30 | this.nes.ChrRomPageCount * 8 - 2, this.nes.ChrRomPageCount * 8 - 1); 31 | } 32 | 33 | }; 34 | 35 | Mapper19.prototype.ReadLow = function(address) { 36 | switch(address & 0xF800) { 37 | case 0x4800: 38 | return this.nes.Read_N163_RAM(); 39 | case 0x5000: 40 | this.ClearIRQ(); 41 | return (this.MAPPER_REG[4] & 0x00FF); 42 | case 0x5800: 43 | this.ClearIRQ(); 44 | return (this.MAPPER_REG[3] << 7) | ((this.MAPPER_REG[4] & 0x7F00) >> 8); 45 | } 46 | return 0x00; 47 | }; 48 | 49 | Mapper19.prototype.WriteLow = function(address, data) { 50 | switch (address & 0xF800) { 51 | case 0x4800: 52 | if(address === 0x4800) { 53 | this.nes.Write_N163_RAM(data); 54 | } 55 | break; 56 | 57 | case 0x5000: 58 | this.MAPPER_REG[4] = (this.MAPPER_REG[4] & 0xFF00) | data; 59 | this.ClearIRQ(); 60 | break; 61 | 62 | case 0x5800: 63 | this.MAPPER_REG[4] = (this.MAPPER_REG[4] & 0x00FF) | ((data & 0x7F) << 8); 64 | this.MAPPER_REG[3] = (data & 0x80) >> 7; 65 | this.ClearIRQ(); 66 | break; 67 | } 68 | }; 69 | 70 | Mapper19.prototype.Write = function(address, data) { 71 | switch (address & 0xF800) { 72 | case 0x8000: 73 | if(data < 0xE0 || this.MAPPER_REG[0] === 1) { 74 | this.nes.SetChrRomPage1K(0, data); 75 | } else { 76 | this.nes.VRAM[0] = this.EX_VRAM[data &0xE0]; 77 | } 78 | break; 79 | 80 | case 0x8800: 81 | if(data < 0xE0 || this.MAPPER_REG[0] === 1) { 82 | this.nes.SetChrRomPage1K(1, data); 83 | } else { 84 | this.nes.VRAM[1] = this.EX_VRAM[data &0xE0]; 85 | } 86 | break; 87 | 88 | case 0x9000: 89 | if(data < 0xE0 || this.MAPPER_REG[0] === 1) { 90 | this.nes.SetChrRomPage1K(2, data); 91 | } else { 92 | this.nes.VRAM[2] = this.EX_VRAM[data &0xE0]; 93 | } 94 | break; 95 | 96 | case 0x9800: 97 | if(data < 0xE0 || this.MAPPER_REG[0] === 1) { 98 | this.nes.SetChrRomPage1K(3, data); 99 | } else { 100 | this.nes.VRAM[3] = this.EX_VRAM[data &0xE0]; 101 | } 102 | break; 103 | 104 | case 0xA000: 105 | if(data < 0xE0 || this.MAPPER_REG[1] === 1) { 106 | this.nes.SetChrRomPage1K(4, data); 107 | } else { 108 | this.nes.VRAM[4] = this.EX_VRAM[data &0xE0]; 109 | } 110 | break; 111 | 112 | case 0xA800: 113 | if(data < 0xE0 || this.MAPPER_REG[1] === 1) { 114 | this.nes.SetChrRomPage1K(5, data); 115 | } else { 116 | this.nes.VRAM[5] = this.EX_VRAM[data &0xE0]; 117 | } 118 | break; 119 | 120 | case 0xB000: 121 | if(data < 0xE0 || this.MAPPER_REG[1] === 1) { 122 | this.nes.SetChrRomPage1K(6, data); 123 | } else { 124 | this.nes.VRAM[6] = this.EX_VRAM[data &0xE0]; 125 | } 126 | break; 127 | 128 | case 0xB800: 129 | if(data < 0xE0 || this.MAPPER_REG[1] === 1) { 130 | this.nes.SetChrRomPage1K(7, data); 131 | } else { 132 | this.nes.VRAM[7] = this.EX_VRAM[data &0xE0]; 133 | } 134 | break; 135 | 136 | case 0xC000: 137 | if(data < 0xE0) { 138 | this.nes.SetChrRomPage1K(8, data); 139 | } else { 140 | this.nes.VRAM[8] = this.nes.VRAMS[(data & 0x01) + 8]; 141 | } 142 | break; 143 | 144 | case 0xC800: 145 | if(data < 0xE0) { 146 | this.nes.SetChrRomPage1K(9, data); 147 | } else { 148 | this.nes.VRAM[9] = this.nes.VRAMS[(data & 0x01) + 8]; 149 | } 150 | break; 151 | 152 | case 0xD000: 153 | if(data < 0xE0) { 154 | this.nes.SetChrRomPage1K(10, data); 155 | } else { 156 | this.nes.VRAM[10] = this.nes.VRAMS[(data & 0x01) + 8]; 157 | } 158 | break; 159 | 160 | case 0xD800: 161 | if(data < 0xE0) { 162 | this.nes.SetChrRomPage1K(11, data); 163 | } else { 164 | this.nes.VRAM[11] = this.nes.VRAMS[(data & 0x01) + 8]; 165 | } 166 | break; 167 | 168 | case 0xE000: 169 | this.nes.SetPrgRomPage8K(0, data & 0x3F); 170 | break; 171 | 172 | case 0xE800: 173 | this.nes.SetPrgRomPage8K(1, data & 0x3F); 174 | this.MAPPER_REG[0] = (data & 0x40) >> 6; 175 | this.MAPPER_REG[1] = (data & 0x80) >> 7; 176 | break; 177 | 178 | case 0xF000: 179 | this.nes.SetPrgRomPage8K(2, data & 0x3F); 180 | break; 181 | 182 | case 0xF800: 183 | if(address === 0xF800) { 184 | this.nes.N163_Address = data; 185 | } 186 | break; 187 | } 188 | }; 189 | 190 | Mapper19.prototype.CPUSync = function(clock) { 191 | if(this.MAPPER_REG[3] !== 0) { 192 | this.MAPPER_REG[4] += clock; 193 | if(this.MAPPER_REG[4] >= 0x7FFF) { 194 | this.MAPPER_REG[4] -= 0x7FFF; 195 | this.SetIRQ(); 196 | } 197 | } 198 | }; 199 | 200 | Mapper19.prototype.OutEXSound = function(soundin) { 201 | return (soundin >> 1) + (this.nes.Out_N163() >> 1); 202 | }; 203 | 204 | Mapper19.prototype.EXSoundSync = function(clock) { 205 | this.nes.Count_N163(clock); 206 | }; 207 | 208 | module.exports = Mapper19; 209 | -------------------------------------------------------------------------------- /src/js/Mapper/2.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper2 ****/ 5 | var Mapper2 = function(nes) { 6 | Base.apply(this, arguments); 7 | }; 8 | 9 | Mapper2.prototype = Object.create(Base.prototype); 10 | 11 | Mapper2.prototype.Init = function() { 12 | this.nes.SetPrgRomPage(0, 0); 13 | this.nes.SetPrgRomPage(1, this.nes.PrgRomPageCount - 1); 14 | this.nes.SetChrRomPage(0); 15 | }; 16 | 17 | Mapper2.prototype.Write = function(address, data) { 18 | this.nes.SetPrgRomPage(0, data); 19 | }; 20 | 21 | module.exports = Mapper2; 22 | -------------------------------------------------------------------------------- /src/js/Mapper/207.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper207 ****/ 5 | var Mapper207 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.MAPPER_REG = new Array(11); 8 | this.EX_RAM = new Array(128); 9 | }; 10 | 11 | Mapper207.prototype = Object.create(Base.prototype); 12 | 13 | Mapper207.prototype.Init = function() { 14 | var i; 15 | for(i=0; i= 0x7F00 && address <= 0x7FFF) 28 | return this.EX_RAM[address & 0x007F]; 29 | 30 | switch(address) { 31 | case 0x7EF0: 32 | return this.MAPPER_REG[0]; 33 | case 0x7EF1: 34 | return this.MAPPER_REG[1]; 35 | case 0x7EF2: 36 | return this.MAPPER_REG[2]; 37 | case 0x7EF3: 38 | return this.MAPPER_REG[3]; 39 | case 0x7EF4: 40 | return this.MAPPER_REG[4]; 41 | case 0x7EF5: 42 | return this.MAPPER_REG[5]; 43 | case 0x7EF6: 44 | case 0x7EF7: 45 | return this.MAPPER_REG[6]; 46 | case 0x7EF8: 47 | case 0x7EF9: 48 | return this.MAPPER_REG[7]; 49 | case 0x7EFA: 50 | case 0x7EFB: 51 | return this.MAPPER_REG[8]; 52 | case 0x7EFC: 53 | case 0x7EFD: 54 | return this.MAPPER_REG[9]; 55 | case 0x7EFE: 56 | case 0x7EFF: 57 | return this.MAPPER_REG[10]; 58 | } 59 | 60 | return 0x00; 61 | }; 62 | 63 | Mapper207.prototype.WriteSRAM = function(address, data) { 64 | if(address >= 0x7F00 && address <= 0x7FFF) { 65 | this.EX_RAM[address & 0x007F] = data; 66 | return; 67 | } 68 | 69 | switch(address) { 70 | case 0x7EF0: 71 | this.MAPPER_REG[0] = data; 72 | if((data & 0x80) === 0x00) { 73 | this.nes.VRAM[8] = this.nes.VRAMS[8]; 74 | this.nes.VRAM[9] = this.nes.VRAMS[8]; 75 | } else { 76 | this.nes.VRAM[8] = this.nes.VRAMS[9]; 77 | this.nes.VRAM[9] = this.nes.VRAMS[9]; 78 | } 79 | this.nes.SetChrRomPage1K(0, data & 0x7E); 80 | this.nes.SetChrRomPage1K(1, (data & 0x7E) + 1); 81 | break; 82 | case 0x7EF1: 83 | this.MAPPER_REG[1] = data; 84 | if((data & 0x80) === 0x00) { 85 | this.nes.SetChrRomPage1K(10, 8 + 0x0100); 86 | this.nes.SetChrRomPage1K(11, 8 + 0x0100); 87 | } else { 88 | this.nes.SetChrRomPage1K(10, 9 + 0x0100); 89 | this.nes.SetChrRomPage1K(11, 9 + 0x0100); 90 | } 91 | this.nes.SetChrRomPage1K(2, data & 0x7E); 92 | this.nes.SetChrRomPage1K(3, (data & 0x7E) + 1); 93 | break; 94 | case 0x7EF2: 95 | this.MAPPER_REG[2] = data; 96 | this.nes.SetChrRomPage1K(4, data); 97 | break; 98 | case 0x7EF3: 99 | this.MAPPER_REG[3] = data; 100 | this.nes.SetChrRomPage1K(5, data); 101 | break; 102 | case 0x7EF4: 103 | this.MAPPER_REG[4] = data; 104 | this.nes.SetChrRomPage1K(6, data); 105 | break; 106 | case 0x7EF5: 107 | this.MAPPER_REG[5] = data; 108 | this.nes.SetChrRomPage1K(7, data); 109 | break; 110 | case 0x7EF8: 111 | case 0x7EF9: 112 | this.MAPPER_REG[7] = data; 113 | break; 114 | case 0x7EFA: 115 | case 0x7EFB: 116 | this.MAPPER_REG[8] = data; 117 | this.nes.SetPrgRomPage8K(0, data); 118 | break; 119 | case 0x7EFC: 120 | case 0x7EFD: 121 | this.MAPPER_REG[9] = data; 122 | this.nes.SetPrgRomPage8K(1, data); 123 | break; 124 | case 0x7EFE: 125 | case 0x7EFF: 126 | this.MAPPER_REG[10] = data; 127 | this.nes.SetPrgRomPage8K(2, data); 128 | break; 129 | } 130 | }; 131 | 132 | module.exports = Mapper207; 133 | -------------------------------------------------------------------------------- /src/js/Mapper/22.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper22 ****/ 5 | var Mapper22 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.MAPPER_REG = new Array(16); 8 | }; 9 | 10 | Mapper22.prototype = Object.create(Base.prototype); 11 | 12 | Mapper22.prototype.Init = function() { 13 | var i; 14 | for(i=0; i> 1); 59 | break; 60 | 61 | case 0xB002: 62 | case 0xB008: 63 | this.MAPPER_REG[0] = (this.MAPPER_REG[0] & 0x0F) | ((data & 0x0F) << 4); 64 | this.nes.SetChrRomPage1K(0, this.MAPPER_REG[0] >> 1); 65 | break; 66 | 67 | case 0xB001: 68 | case 0xB004: 69 | this.MAPPER_REG[1] = (this.MAPPER_REG[1] & 0xF0) | (data & 0x0F); 70 | this.nes.SetChrRomPage1K(1, this.MAPPER_REG[1] >> 1); 71 | break; 72 | 73 | case 0xB003: 74 | case 0xB00C: 75 | this.MAPPER_REG[1] = (this.MAPPER_REG[1] & 0x0F) | ((data & 0x0F) << 4); 76 | this.nes.SetChrRomPage1K(1, this.MAPPER_REG[1] >> 1); 77 | break; 78 | 79 | case 0xC000: 80 | this.MAPPER_REG[2] = (this.MAPPER_REG[2] & 0xF0) | (data & 0x0F); 81 | this.nes.SetChrRomPage1K(2, this.MAPPER_REG[2] >> 1); 82 | break; 83 | 84 | case 0xC002: 85 | case 0xC008: 86 | this.MAPPER_REG[2] = (this.MAPPER_REG[2] & 0x0F) | ((data & 0x0F) << 4); 87 | this.nes.SetChrRomPage1K(2, this.MAPPER_REG[2] >> 1); 88 | break; 89 | 90 | case 0xC001: 91 | case 0xC004: 92 | this.MAPPER_REG[3] = (this.MAPPER_REG[3] & 0xF0) | (data & 0x0F); 93 | this.nes.SetChrRomPage1K(3, this.MAPPER_REG[3] >> 1); 94 | break; 95 | 96 | case 0xC003: 97 | case 0xC00C: 98 | this.MAPPER_REG[3] = (this.MAPPER_REG[3] & 0x0F) | ((data & 0x0F) << 4); 99 | this.nes.SetChrRomPage1K(3, this.MAPPER_REG[3] >> 1); 100 | break; 101 | 102 | case 0xD000: 103 | this.MAPPER_REG[4] = (this.MAPPER_REG[4] & 0xF0) | (data & 0x0F); 104 | this.nes.SetChrRomPage1K(4, this.MAPPER_REG[4] >> 1); 105 | break; 106 | 107 | case 0xD002: 108 | case 0xD008: 109 | this.MAPPER_REG[4] = (this.MAPPER_REG[4] & 0x0F) | ((data & 0x0F) << 4); 110 | this.nes.SetChrRomPage1K(4, this.MAPPER_REG[4] >> 1); 111 | break; 112 | 113 | case 0xD001: 114 | case 0xD004: 115 | this.MAPPER_REG[5] = (this.MAPPER_REG[5] & 0xF0) | (data & 0x0F); 116 | this.nes.SetChrRomPage1K(5, this.MAPPER_REG[5] >> 1); 117 | break; 118 | 119 | case 0xD003: 120 | case 0xD00C: 121 | this.MAPPER_REG[5] = (this.MAPPER_REG[5] & 0x0F) | ((data & 0x0F) << 4); 122 | this.nes.SetChrRomPage1K(5, this.MAPPER_REG[5] >> 1); 123 | break; 124 | 125 | case 0xE000: 126 | this.MAPPER_REG[6] = (this.MAPPER_REG[6] & 0xF0) | (data & 0x0F); 127 | this.nes.SetChrRomPage1K(6, this.MAPPER_REG[6] >> 1); 128 | break; 129 | 130 | case 0xE002: 131 | case 0xE008: 132 | this.MAPPER_REG[6] = (this.MAPPER_REG[6] & 0x0F) | ((data & 0x0F) << 4); 133 | this.nes.SetChrRomPage1K(6, this.MAPPER_REG[6] >> 1); 134 | break; 135 | 136 | case 0xE001: 137 | case 0xE004: 138 | this.MAPPER_REG[7] = (this.MAPPER_REG[7] & 0xF0) | (data & 0x0F); 139 | this.nes.SetChrRomPage1K(7, this.MAPPER_REG[7] >> 1); 140 | break; 141 | 142 | case 0xE003: 143 | case 0xE00C: 144 | this.MAPPER_REG[7] = (this.MAPPER_REG[7] & 0x0F) | ((data & 0x0F) << 4); 145 | this.nes.SetChrRomPage1K(7, this.MAPPER_REG[7] >> 1); 146 | break; 147 | } 148 | }; 149 | 150 | module.exports = Mapper22; 151 | -------------------------------------------------------------------------------- /src/js/Mapper/23.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | 5 | /**** Mapper23 ****/ 6 | var Mapper23 = function(nes) { 7 | Base.apply(this, arguments); 8 | this.MAPPER_REG = new Array(16); 9 | }; 10 | 11 | Mapper23.prototype = Object.create(Base.prototype); 12 | 13 | Mapper23.prototype.Init = function() { 14 | var i; 15 | for(i=0; i= 0xFF) { 191 | this.MAPPER_REG[12] = this.MAPPER_REG[13]; 192 | this.SetIRQ(); 193 | } else 194 | this.MAPPER_REG[12] += clock; 195 | } 196 | }; 197 | 198 | module.exports = Mapper23; 199 | -------------------------------------------------------------------------------- /src/js/Mapper/24.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper24 ****/ 5 | var Mapper24 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.MAPPER_REG = new Array(3); 8 | }; 9 | 10 | Mapper24.prototype = Object.create(Base.prototype); 11 | 12 | Mapper24.prototype.Init = function() { 13 | this.MAPPER_REG[0] = 0x00; 14 | this.MAPPER_REG[1] = 0x00; 15 | this.MAPPER_REG[2] = 0x00; 16 | this.nes.SetPrgRomPages8K(0, 1, 2, this.nes.PrgRomPageCount * 2 - 1); 17 | this.nes.SetChrRomPages1K(0, 1, 2, 3, 4, 5, 6, 7); 18 | }; 19 | 20 | Mapper24.prototype.Write = function(address, data) { 21 | switch(address & 0xF003) { 22 | case 0x8000: 23 | case 0x8001: 24 | case 0x8002: 25 | case 0x8003: 26 | this.nes.SetPrgRomPage8K(0, data * 2); 27 | this.nes.SetPrgRomPage8K(1, data * 2 + 1); 28 | break; 29 | 30 | 31 | case 0x9000: 32 | case 0x9001: 33 | case 0x9002: 34 | this.nes.Write_VRC6_REG(address & 0x03, data); 35 | break; 36 | 37 | 38 | case 0xA000: 39 | case 0xA001: 40 | case 0xA002: 41 | this.nes.Write_VRC6_REG((address & 0x03) + 4, data); 42 | break; 43 | 44 | 45 | case 0xB000: 46 | case 0xB001: 47 | case 0xB002: 48 | this.nes.Write_VRC6_REG((address & 0x03) + 8, data); 49 | break; 50 | 51 | 52 | case 0xB003: 53 | data &= 0x0C; 54 | if(data === 0x00) { 55 | this.nes.SetMirror(false); 56 | } else if(data === 0x04) { 57 | this.nes.SetMirror(true); 58 | } else if(data === 0x08) { 59 | this.nes.SetMirrors(0, 0, 0, 0); 60 | } else { 61 | this.nes.SetMirrors(1, 1, 1, 1); 62 | } 63 | break; 64 | 65 | case 0xC000: 66 | case 0xC001: 67 | case 0xC002: 68 | case 0xC003: 69 | this.nes.SetPrgRomPage8K(2, data); 70 | break; 71 | 72 | case 0xD000: 73 | case 0xD001: 74 | case 0xD002: 75 | case 0xD003: 76 | this.nes.SetChrRomPage1K(address & 0x03, data); 77 | break; 78 | 79 | case 0xE000: 80 | case 0xE001: 81 | case 0xE002: 82 | case 0xE003: 83 | this.nes.SetChrRomPage1K((address & 0x03) + 4, data); 84 | break; 85 | 86 | case 0xF000: 87 | this.MAPPER_REG[0] = data; 88 | break; 89 | 90 | case 0xF001: 91 | this.MAPPER_REG[1] = data & 0x07; 92 | if((this.MAPPER_REG[1] & 0x02) !== 0) { 93 | this.MAPPER_REG[2] = this.MAPPER_REG[0]; 94 | } 95 | break; 96 | 97 | case 0xF002: 98 | if((this.MAPPER_REG[1] & 0x01) !== 0) { 99 | this.MAPPER_REG[1] |= 0x02; 100 | } else { 101 | this.MAPPER_REG[1] &= 0x01; 102 | } 103 | this.ClearIRQ(); 104 | break; 105 | } 106 | }; 107 | 108 | Mapper24.prototype.HSync = function(y) { 109 | if((this.MAPPER_REG[1] & 0x06) === 0x02) { 110 | if(this.MAPPER_REG[2] === 0xFF) { 111 | this.MAPPER_REG[2] = this.MAPPER_REG[0]; 112 | this.SetIRQ(); 113 | } else 114 | this.MAPPER_REG[2]++; 115 | } 116 | }; 117 | 118 | Mapper24.prototype.CPUSync = function(clock) { 119 | if((this.MAPPER_REG[1] & 0x06) === 0x06) { 120 | if(this.MAPPER_REG[2] >= 0xFF) { 121 | this.MAPPER_REG[2] = this.MAPPER_REG[0]; 122 | this.SetIRQ(); 123 | } else 124 | this.MAPPER_REG[2] += clock; 125 | } 126 | }; 127 | 128 | Mapper24.prototype.OutEXSound = function(soundin) { 129 | return (soundin >> 1) + (this.nes.Out_VRC6() >> 1); 130 | }; 131 | 132 | Mapper24.prototype.EXSoundSync = function(clock) { 133 | this.nes.Count_VRC6(clock); 134 | }; 135 | 136 | module.exports = Mapper24; 137 | -------------------------------------------------------------------------------- /src/js/Mapper/25.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper25 ****/ 5 | var Mapper25 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.MAPPER_REG = new Array(16); 8 | }; 9 | 10 | Mapper25.prototype = Object.create(Base.prototype); 11 | 12 | Mapper25.prototype.Init = function() { 13 | var i; 14 | for(i=0; i= 0xFF) { 202 | this.MAPPER_REG[12] = this.MAPPER_REG[13]; 203 | this.SetIRQ(); 204 | } else 205 | this.MAPPER_REG[12] += clock; 206 | } 207 | }; 208 | 209 | module.exports = Mapper25; 210 | -------------------------------------------------------------------------------- /src/js/Mapper/26.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper26 ****/ 5 | var Mapper26 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.MAPPER_REG = new Array(3); 8 | }; 9 | 10 | Mapper26.prototype = Object.create(Base.prototype); 11 | 12 | Mapper26.prototype.Init = function() { 13 | this.MAPPER_REG[0] = 0x00; 14 | this.MAPPER_REG[1] = 0x00; 15 | this.MAPPER_REG[2] = 0x00; 16 | this.nes.SetPrgRomPages8K(0, 1, 2, this.nes.PrgRomPageCount * 2 - 1); 17 | this.nes.SetChrRomPages1K(0, 1, 2, 3, 4, 5, 6, 7); 18 | }; 19 | 20 | Mapper26.prototype.Write = function(address, data) { 21 | address = (address & 0xFFFC) | ((address & 0x0002) >> 1) | ((address & 0x0001) << 1); 22 | 23 | switch(address & 0xF003) { 24 | case 0x8000: 25 | case 0x8001: 26 | case 0x8002: 27 | case 0x8003: 28 | this.nes.SetPrgRomPage8K(0, data * 2); 29 | this.nes.SetPrgRomPage8K(1, data * 2 + 1); 30 | break; 31 | 32 | 33 | case 0x9000: 34 | case 0x9001: 35 | case 0x9002: 36 | this.nes.Write_VRC6_REG(address & 0x03, data); 37 | break; 38 | 39 | 40 | case 0xA000: 41 | case 0xA001: 42 | case 0xA002: 43 | this.nes.Write_VRC6_REG((address & 0x03) + 4, data); 44 | break; 45 | 46 | 47 | case 0xB000: 48 | case 0xB001: 49 | case 0xB002: 50 | this.nes.Write_VRC6_REG((address & 0x03) + 8, data); 51 | break; 52 | 53 | 54 | case 0xB003: 55 | data &= 0x0C; 56 | if(data === 0x00) { 57 | this.nes.SetMirror(false); 58 | } else if(data === 0x04) { 59 | this.nes.SetMirror(true); 60 | } else if(data === 0x08) { 61 | this.nes.SetMirrors(0, 0, 0, 0); 62 | } else { 63 | this.nes.SetMirrors(1, 1, 1, 1); 64 | } 65 | break; 66 | 67 | case 0xC000: 68 | case 0xC001: 69 | case 0xC002: 70 | case 0xC003: 71 | this.nes.SetPrgRomPage8K(2, data); 72 | break; 73 | 74 | case 0xD000: 75 | case 0xD001: 76 | case 0xD002: 77 | case 0xD003: 78 | this.nes.SetChrRomPage1K(address & 0x03, data); 79 | break; 80 | 81 | case 0xE000: 82 | case 0xE001: 83 | case 0xE002: 84 | case 0xE003: 85 | this.nes.SetChrRomPage1K((address & 0x03) + 4, data); 86 | break; 87 | 88 | case 0xF000: 89 | this.MAPPER_REG[0] = data; 90 | break; 91 | 92 | case 0xF001: 93 | this.MAPPER_REG[1] = data & 0x07; 94 | if((this.MAPPER_REG[1] & 0x02) !== 0) { 95 | this.MAPPER_REG[2] = this.MAPPER_REG[0]; 96 | } 97 | this.ClearIRQ(); 98 | break; 99 | 100 | case 0xF002: 101 | if((this.MAPPER_REG[1] & 0x01) !== 0) { 102 | this.MAPPER_REG[1] |= 0x02; 103 | } else { 104 | this.MAPPER_REG[1] &= 0x01; 105 | } 106 | break; 107 | } 108 | }; 109 | 110 | Mapper26.prototype.HSync = function(y) { 111 | if((this.MAPPER_REG[1] & 0x06) === 0x02) { 112 | if(this.MAPPER_REG[2] === 0xFF) { 113 | this.MAPPER_REG[2] = this.MAPPER_REG[0]; 114 | this.SetIRQ(); 115 | } else 116 | this.MAPPER_REG[2]++; 117 | } 118 | }; 119 | 120 | Mapper26.prototype.CPUSync = function(clock) { 121 | if((this.MAPPER_REG[1] & 0x06) === 0x06) { 122 | if(this.MAPPER_REG[2] >= 0xFF) { 123 | this.MAPPER_REG[2] = this.MAPPER_REG[0]; 124 | this.SetIRQ(); 125 | } else 126 | this.MAPPER_REG[2] += clock; 127 | } 128 | }; 129 | 130 | Mapper26.prototype.OutEXSound = function(soundin) { 131 | return (soundin >> 1) + (this.nes.Out_VRC6() >> 1); 132 | }; 133 | 134 | Mapper26.prototype.EXSoundSync = function(clock) { 135 | this.nes.Count_VRC6(clock); 136 | }; 137 | 138 | module.exports = Mapper26; 139 | -------------------------------------------------------------------------------- /src/js/Mapper/3.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper3 ****/ 5 | var Mapper3 = function(nes) { 6 | Base.apply(this, arguments); 7 | }; 8 | 9 | Mapper3.prototype = Object.create(Base.prototype); 10 | 11 | Mapper3.prototype.Init = function() { 12 | this.nes.SetPrgRomPage(0, 0); 13 | this.nes.SetPrgRomPage(1, this.nes.PrgRomPageCount - 1); 14 | this.nes.SetChrRomPage(0); 15 | }; 16 | 17 | Mapper3.prototype.Write = function(address, data) { 18 | this.nes.SetChrRomPage(data & 0x0F); 19 | }; 20 | 21 | module.exports = Mapper3; 22 | -------------------------------------------------------------------------------- /src/js/Mapper/32.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper32 ****/ 5 | var Mapper32 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.MAPPER_REG = new Array(11); 8 | }; 9 | 10 | Mapper32.prototype = Object.create(Base.prototype); 11 | 12 | Mapper32.prototype.Init = function() { 13 | for(var i=0; i= 0x5C00) { 72 | return this.MAPPER_EXRAM2[address - 0x5C00]; 73 | } 74 | 75 | if (address === 0x5204) { 76 | var ret = this.MAPPER_IRQ_STATUS; 77 | this.MAPPER_IRQ_STATUS &= 0x7F; 78 | this.ClearIRQ(); 79 | return ret; 80 | } 81 | 82 | if (address === 0x5205) { 83 | return (this.MAPPER_REG[0x0205] * this.MAPPER_REG[0x0206]) & 0x00FF; 84 | } 85 | 86 | if (address === 0x5206) { 87 | return (this.MAPPER_REG[0x0205] * this.MAPPER_REG[0x0206]) >>> 8; 88 | } 89 | }; 90 | 91 | Mapper5.prototype.WriteLow = function(address, data) { 92 | var i; 93 | if(address >= 0x5C00) { 94 | this.MAPPER_EXRAM2[address - 0x5C00] = data; 95 | return; 96 | } 97 | 98 | if(address >= 0x5000 && address <= 0x5015) { 99 | this.MAPPER_REG[address - 0x5000] = data; 100 | this.nes.Write_MMC5_REG(address - 0x5000, data); 101 | return; 102 | } 103 | 104 | if((address >= 0x5100 && address <= 0x5104) || 105 | address === 0x5130 || 106 | (address >= 0x5200 && address <= 0x5206)) { 107 | this.MAPPER_REG[address - 0x5000] = data; 108 | return; 109 | } 110 | 111 | if(address === 0x5105) { 112 | this.MAPPER_REG[0x0105] = data; 113 | for(i=0; i<4; i++) { 114 | switch((data >>> (i * 2)) & 0x03) { 115 | case 0: 116 | this.nes.VRAM[8 + i] = this.nes.VRAMS[8]; 117 | break; 118 | case 1: 119 | this.nes.VRAM[8 + i] = this.nes.VRAMS[9]; 120 | break; 121 | case 2: 122 | this.nes.VRAM[8 + i] = this.MAPPER_EXRAM2; 123 | break; 124 | case 3: 125 | this.nes.VRAM[8 + i] = this.MAPPER_EXRAM3; 126 | break; 127 | } 128 | } 129 | return; 130 | } 131 | 132 | if(address === 0x5106) { 133 | this.MAPPER_REG[0x0106] = data; 134 | for(i=0; i<30*32; i++) 135 | this.MAPPER_EXRAM3[i] = data; 136 | return; 137 | } 138 | 139 | if(address === 0x5107) { 140 | this.MAPPER_REG[0x0107] = data; 141 | for(i=30*32; i<32*32; i++) 142 | this.MAPPER_EXRAM3[i] = data; 143 | return; 144 | } 145 | 146 | if(address === 0x5113) { 147 | this.MAPPER_REG[0x0113] = data; 148 | this.nes.SRAM = this.MAPPER_EXRAM[data & 0x07]; 149 | return; 150 | } 151 | 152 | if(address >= 0x5114 && address <= 0x5117) { 153 | this.MAPPER_REG[address - 0x5000] = data; 154 | this.SetPrgRomPages8K_Mapper05(address - 0x5000); 155 | return; 156 | } 157 | 158 | if(address >= 0x5120 && address <= 0x5127) { 159 | this.MAPPER_REG[address - 0x5000] = (this.MAPPER_REG[0x0130] << 8) | data; 160 | this.SetChrRomPages1K_Mapper05_A(); 161 | return; 162 | } 163 | 164 | if(address >= 0x5128 && address <= 0x512B) { 165 | this.MAPPER_REG[address - 0x5000] = (this.MAPPER_REG[0x0130] << 8) | data; 166 | this.SetChrRomPages1K_Mapper05_B(); 167 | return; 168 | } 169 | }; 170 | 171 | Mapper5.prototype.SetChrRomPages1K_Mapper05_A = function (){ 172 | var tmp; 173 | switch(this.MAPPER_REG[0x0101] & 0x03) { 174 | case 0: 175 | tmp = this.MAPPER_REG[0x0127] * 8; 176 | this.MAPPER_CHR_REG[0][0] = tmp; 177 | this.MAPPER_CHR_REG[0][1] = tmp + 1; 178 | this.MAPPER_CHR_REG[0][2] = tmp + 2; 179 | this.MAPPER_CHR_REG[0][3] = tmp + 3; 180 | this.MAPPER_CHR_REG[0][4] = tmp + 4; 181 | this.MAPPER_CHR_REG[0][5] = tmp + 5; 182 | this.MAPPER_CHR_REG[0][6] = tmp + 6; 183 | this.MAPPER_CHR_REG[0][7] = tmp + 7; 184 | break; 185 | case 1: 186 | tmp = this.MAPPER_REG[0x0123] * 4; 187 | this.MAPPER_CHR_REG[0][0] = tmp; 188 | this.MAPPER_CHR_REG[0][1] = tmp + 1; 189 | this.MAPPER_CHR_REG[0][2] = tmp + 2; 190 | this.MAPPER_CHR_REG[0][3] = tmp + 3; 191 | 192 | tmp = this.MAPPER_REG[0x0127] * 4; 193 | this.MAPPER_CHR_REG[0][4] = tmp; 194 | this.MAPPER_CHR_REG[0][5] = tmp + 1; 195 | this.MAPPER_CHR_REG[0][6] = tmp + 2; 196 | this.MAPPER_CHR_REG[0][7] = tmp + 3; 197 | break; 198 | case 2: 199 | tmp = this.MAPPER_REG[0x0121] * 2; 200 | this.MAPPER_CHR_REG[0][0] = tmp; 201 | this.MAPPER_CHR_REG[0][1] = tmp + 1; 202 | 203 | tmp = this.MAPPER_REG[0x0123] * 2; 204 | this.MAPPER_CHR_REG[0][2] = tmp; 205 | this.MAPPER_CHR_REG[0][3] = tmp + 1; 206 | 207 | tmp = this.MAPPER_REG[0x0125] * 2; 208 | this.MAPPER_CHR_REG[0][4] = tmp; 209 | this.MAPPER_CHR_REG[0][5] = tmp + 1; 210 | 211 | tmp = this.MAPPER_REG[0x0126] * 2; 212 | this.MAPPER_CHR_REG[0][6] = tmp; 213 | this.MAPPER_CHR_REG[0][7] = tmp + 1; 214 | break; 215 | case 3: 216 | this.MAPPER_CHR_REG[0][0] = this.MAPPER_REG[0x0120]; 217 | this.MAPPER_CHR_REG[0][1] = this.MAPPER_REG[0x0121]; 218 | this.MAPPER_CHR_REG[0][2] = this.MAPPER_REG[0x0122]; 219 | this.MAPPER_CHR_REG[0][3] = this.MAPPER_REG[0x0123]; 220 | this.MAPPER_CHR_REG[0][4] = this.MAPPER_REG[0x0124]; 221 | this.MAPPER_CHR_REG[0][5] = this.MAPPER_REG[0x0125]; 222 | this.MAPPER_CHR_REG[0][6] = this.MAPPER_REG[0x0126]; 223 | this.MAPPER_CHR_REG[0][7] = this.MAPPER_REG[0x0127]; 224 | break; 225 | } 226 | }; 227 | 228 | Mapper5.prototype.SetChrRomPages1K_Mapper05_B = function (){ 229 | var tmp; 230 | switch(this.MAPPER_REG[0x0101] & 0x03) { 231 | case 0: 232 | tmp = this.MAPPER_REG[0x012B] * 8; 233 | this.MAPPER_CHR_REG[1][0] = tmp; 234 | this.MAPPER_CHR_REG[1][1] = tmp + 1; 235 | this.MAPPER_CHR_REG[1][2] = tmp + 2; 236 | this.MAPPER_CHR_REG[1][3] = tmp + 3; 237 | this.MAPPER_CHR_REG[1][4] = tmp + 4; 238 | this.MAPPER_CHR_REG[1][5] = tmp + 5; 239 | this.MAPPER_CHR_REG[1][6] = tmp + 6; 240 | this.MAPPER_CHR_REG[1][7] = tmp + 7; 241 | break; 242 | case 1: 243 | tmp = this.MAPPER_REG[0x012B] * 4; 244 | this.MAPPER_CHR_REG[1][0] = tmp; 245 | this.MAPPER_CHR_REG[1][1] = tmp + 1; 246 | this.MAPPER_CHR_REG[1][2] = tmp + 2; 247 | this.MAPPER_CHR_REG[1][3] = tmp + 3; 248 | this.MAPPER_CHR_REG[1][4] = tmp; 249 | this.MAPPER_CHR_REG[1][5] = tmp + 1; 250 | this.MAPPER_CHR_REG[1][6] = tmp + 2; 251 | this.MAPPER_CHR_REG[1][7] = tmp + 3; 252 | break; 253 | case 2: 254 | tmp = this.MAPPER_REG[0x0129] * 2; 255 | this.MAPPER_CHR_REG[1][0] = tmp; 256 | this.MAPPER_CHR_REG[1][1] = tmp + 1; 257 | this.MAPPER_CHR_REG[1][4] = tmp; 258 | this.MAPPER_CHR_REG[1][5] = tmp + 1; 259 | 260 | tmp = this.MAPPER_REG[0x012B] * 2; 261 | this.MAPPER_CHR_REG[1][2] = tmp; 262 | this.MAPPER_CHR_REG[1][3] = tmp + 1; 263 | this.MAPPER_CHR_REG[1][6] = tmp; 264 | this.MAPPER_CHR_REG[1][7] = tmp + 1; 265 | break; 266 | case 3: 267 | tmp = this.MAPPER_REG[0x0128]; 268 | this.MAPPER_CHR_REG[1][0] = tmp; 269 | this.MAPPER_CHR_REG[1][4] = tmp; 270 | 271 | tmp = this.MAPPER_REG[0x0129]; 272 | this.MAPPER_CHR_REG[1][1] = tmp; 273 | this.MAPPER_CHR_REG[1][5] = tmp; 274 | 275 | tmp = this.MAPPER_REG[0x012A]; 276 | this.MAPPER_CHR_REG[1][2] = tmp; 277 | this.MAPPER_CHR_REG[1][6] = tmp; 278 | 279 | tmp = this.MAPPER_REG[0x012B]; 280 | this.MAPPER_CHR_REG[1][3] = tmp; 281 | this.MAPPER_CHR_REG[1][7] = tmp; 282 | break; 283 | } 284 | }; 285 | 286 | Mapper5.prototype.SetPrgRomPages8K_Mapper05 = function (no){ 287 | var tmp; 288 | switch(this.MAPPER_REG[0x0100] & 0x03) { 289 | case 0x00: 290 | if(no === 0x0117) { 291 | tmp = this.MAPPER_REG[0x0117] & 0x7C; 292 | this.nes.SetPrgRomPage8K(0, tmp); 293 | this.nes.SetPrgRomPage8K(1, tmp + 1); 294 | this.nes.SetPrgRomPage8K(2, tmp + 2); 295 | this.nes.SetPrgRomPage8K(3, tmp + 3); 296 | } 297 | break; 298 | case 0x01: 299 | if(no === 0x0115) { 300 | tmp = this.MAPPER_REG[0x0115]; 301 | if((tmp & 0x80) === 0x80) { 302 | tmp &= 0x7E; 303 | this.nes.SetPrgRomPage8K(0, tmp); 304 | this.nes.SetPrgRomPage8K(1, tmp + 1); 305 | } else { 306 | this.nes.ROM[0] = this.MAPPER_EXRAM[tmp & 0x07]; 307 | this.nes.ROM[1] = this.MAPPER_EXRAM[(tmp + 1) & 0x07]; 308 | } 309 | } 310 | if(no === 0x0117) { 311 | tmp = this.MAPPER_REG[0x0117] & 0x7E; 312 | this.nes.SetPrgRomPage8K(2, tmp); 313 | this.nes.SetPrgRomPage8K(3, tmp + 1); 314 | } 315 | break; 316 | case 0x02: 317 | if(no === 0x0115) { 318 | tmp = this.MAPPER_REG[0x0115]; 319 | if((tmp & 0x80) === 0x80) { 320 | tmp &= 0x7E; 321 | this.nes.SetPrgRomPage8K(0, tmp); 322 | this.nes.SetPrgRomPage8K(1, tmp + 1); 323 | } else { 324 | this.nes.ROM[0] = this.MAPPER_EXRAM[tmp & 0x07]; 325 | this.nes.ROM[1] = this.MAPPER_EXRAM[(tmp + 1) & 0x07]; 326 | } 327 | } 328 | if(no === 0x0116) { 329 | tmp = this.MAPPER_REG[0x0116]; 330 | if((tmp & 0x80) === 0x80) { 331 | this.nes.SetPrgRomPage8K(2, tmp & 0x7F); 332 | } else { 333 | this.nes.ROM[2] = this.MAPPER_EXRAM[tmp & 0x07]; 334 | } 335 | } 336 | if(no === 0x0117) 337 | this.nes.SetPrgRomPage8K(3, this.MAPPER_REG[0x0117] & 0x7F); 338 | break; 339 | case 0x03: 340 | if(no === 0x0114 || no === 0x0115 || no === 0x0116) { 341 | tmp = this.MAPPER_REG[no]; 342 | if((tmp & 0x80) === 0x80) { 343 | this.nes.SetPrgRomPage8K(no - 0x0114, tmp & 0x7F); 344 | } else { 345 | this.nes.ROM[no - 0x0114] = this.MAPPER_EXRAM[tmp & 0x07]; 346 | } 347 | } 348 | if(no === 0x0117) 349 | this.nes.SetPrgRomPage8K(3, this.MAPPER_REG[0x0117] & 0x7F); 350 | break; 351 | } 352 | }; 353 | 354 | Mapper5.prototype.BuildBGLine = function () { 355 | this.nes.SetChrRomPages1K(this.MAPPER_CHR_REG[1][0], this.MAPPER_CHR_REG[1][1], this.MAPPER_CHR_REG[1][2], this.MAPPER_CHR_REG[1][3], 356 | this.MAPPER_CHR_REG[1][4], this.MAPPER_CHR_REG[1][5], this.MAPPER_CHR_REG[1][6], this.MAPPER_CHR_REG[1][7]); 357 | 358 | this.nes.BuildBGLine_SUB(); 359 | 360 | if((this.MAPPER_REG[0x0200] & 0x80) === 0x80) { 361 | var chrpage = this.MAPPER_REG[0x0202] * 4; 362 | this.nes.SetChrRomPage1K(0, chrpage); 363 | this.nes.SetChrRomPage1K(1, chrpage + 1); 364 | this.nes.SetChrRomPage1K(2, chrpage + 2); 365 | this.nes.SetChrRomPage1K(3, chrpage + 3); 366 | 367 | var spilt_index = this.MAPPER_REG[0x0200] & 0x1F; 368 | 369 | var si; 370 | var ei; 371 | if((this.MAPPER_REG[0x0200] & 0x40) === 0x00) { 372 | si = 0; 373 | ei = spilt_index - 1; 374 | } else { 375 | si = spilt_index; 376 | ei = 31; 377 | } 378 | 379 | var tmpVRAM = this.nes.VRAM; 380 | var tmpPaletteArray = this.nes.PaletteArray; 381 | var tmpSPBitArray = this.nes.SPBitArray; 382 | 383 | var tmpBgLineBuffer = this.nes.BgLineBuffer; 384 | var nameAddr = 0x0000; 385 | var tmpy = (this.nes.PpuY + this.MAPPER_REG[0x0201]) % 240; 386 | nameAddr += (tmpy >>> 3) << 5; 387 | var iy = tmpy & 0x07; 388 | 389 | for(var i=si; i<=ei; i++) { 390 | var ptnDist = (this.MAPPER_EXRAM2[nameAddr + i] << 4) + iy; 391 | var tmpSrcV = tmpVRAM[ptnDist >> 10]; 392 | ptnDist &= 0x03FF; 393 | var attr = ((this.MAPPER_EXRAM2[((nameAddr & 0x0380) >> 4) | ((nameAddr & 0x001C) >> 2) + 0x03C0] << 2) >> (((nameAddr & 0x0040) >> 4) | (nameAddr & 0x0002))) & 0x0C; 394 | var ptn = tmpSPBitArray[tmpSrcV[ptnDist]][tmpSrcV[ptnDist + 8]]; 395 | 396 | for(var j=0; j<8; j++) { 397 | tmpBgLineBuffer[i * 8 + j] = tmpPaletteArray[ptn[j] | attr]; 398 | } 399 | } 400 | } 401 | }; 402 | 403 | Mapper5.prototype.BuildSpriteLine = function () { 404 | this.nes.SetChrRomPages1K(this.MAPPER_CHR_REG[0][0], this.MAPPER_CHR_REG[0][1], this.MAPPER_CHR_REG[0][2], this.MAPPER_CHR_REG[0][3], 405 | this.MAPPER_CHR_REG[0][4], this.MAPPER_CHR_REG[0][5], this.MAPPER_CHR_REG[0][6], this.MAPPER_CHR_REG[0][7]); 406 | this.nes.BuildSpriteLine_SUB(); 407 | }; 408 | 409 | Mapper5.prototype.ReadPPUData = function () { 410 | this.nes.SetChrRomPages1K(this.MAPPER_CHR_REG[0][0], this.MAPPER_CHR_REG[0][1], this.MAPPER_CHR_REG[0][2], this.MAPPER_CHR_REG[0][3], 411 | this.MAPPER_CHR_REG[0][4], this.MAPPER_CHR_REG[0][5], this.MAPPER_CHR_REG[0][6], this.MAPPER_CHR_REG[0][7]); 412 | return this.nes.ReadPPUData_SUB(); 413 | }; 414 | 415 | Mapper5.prototype.WritePPUData = function (value) { 416 | this.nes.SetChrRomPages1K(this.MAPPER_CHR_REG[0][0], this.MAPPER_CHR_REG[0][1], this.MAPPER_CHR_REG[0][2], this.MAPPER_CHR_REG[0][3], 417 | this.MAPPER_CHR_REG[0][4], this.MAPPER_CHR_REG[0][5], this.MAPPER_CHR_REG[0][6], this.MAPPER_CHR_REG[0][7]); 418 | this.nes.WritePPUData_SUB(value); 419 | }; 420 | 421 | Mapper5.prototype.OutEXSound = function(soundin) { 422 | return (soundin >> 1) + (this.nes.Out_MMC5() >> 1); 423 | }; 424 | 425 | Mapper5.prototype.EXSoundSync = function(clock) { 426 | this.nes.Count_MMC5(clock); 427 | }; 428 | 429 | module.exports = Mapper5; 430 | -------------------------------------------------------------------------------- /src/js/Mapper/65.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper65 ****/ 5 | var Mapper65 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.IRQ_Counter = 0; 8 | this.IRQ_Value = 0; 9 | this.IRQ_Flag = false; 10 | }; 11 | 12 | Mapper65.prototype = Object.create(Base.prototype); 13 | 14 | Mapper65.prototype.Init = function() { 15 | this.nes.SetPrgRomPages8K(0, 1, this.nes.PrgRomPageCount * 2 - 2, this.nes.PrgRomPageCount * 2 - 1); 16 | this.nes.SetChrRomPages1K(0, 1, 2, 3, 4, 5, 6, 7); 17 | this.IRQ_Counter = 0; 18 | }; 19 | 20 | Mapper65.prototype.Write = function(address, data) { 21 | switch (address & 0xF000) { 22 | case 0x8000: 23 | this.nes.SetPrgRomPage8K(0, data); 24 | break; 25 | case 0x9000: 26 | switch(address) { 27 | case 0x9001: 28 | if((data & 0x80) === 0x00) 29 | this.nes.SetMirror(false); 30 | else 31 | this.nes.SetMirror(true); 32 | break; 33 | case 0x9003: 34 | this.IRQ_Flag = (data & 0x80) === 0x80; 35 | this.ClearIRQ(); 36 | break; 37 | case 0x9004: 38 | this.IRQ_Counter = this.IRQ_Value; 39 | this.IRQ_Flag = true; 40 | this.ClearIRQ(); 41 | break; 42 | case 0x9005: 43 | this.IRQ_Value = (data << 8) | (this.IRQ_Value & 0x00FF); 44 | break; 45 | case 0x9006: 46 | this.IRQ_Value = (this.IRQ_Value & 0xFF00) | data; 47 | break; 48 | } 49 | break; 50 | case 0xA000: 51 | this.nes.SetPrgRomPage8K(1, data); 52 | break; 53 | case 0xB000: 54 | case 0xB001: 55 | case 0xB002: 56 | case 0xB003: 57 | case 0xB004: 58 | case 0xB005: 59 | case 0xB006: 60 | case 0xB007: 61 | this.nes.SetChrRomPage1K(address & 0x0007, data); 62 | break; 63 | case 0xC000: 64 | this.nes.SetPrgRomPage8K(2, data); 65 | break; 66 | } 67 | }; 68 | 69 | Mapper65.prototype.CPUSync = function(clock) { 70 | if(this.IRQ_Flag) { 71 | if(this.IRQ_Counter !== 0) { 72 | this.IRQ_Counter -= clock; 73 | if(this.IRQ_Counter <= 0) { 74 | this.IRQ_Counter = 0; 75 | this.IRQ_Flag = false; 76 | this.SetIRQ(); 77 | } 78 | } 79 | } 80 | }; 81 | 82 | module.exports = Mapper65; 83 | -------------------------------------------------------------------------------- /src/js/Mapper/66.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper66 ****/ 5 | var Mapper66 = function(nes) { 6 | Base.apply(this, arguments); 7 | }; 8 | 9 | Mapper66.prototype = Object.create(Base.prototype); 10 | 11 | Mapper66.prototype.Init = function() { 12 | this.nes.SetPrgRomPage(0, 0); 13 | this.nes.SetPrgRomPage(1, 1); 14 | this.nes.SetChrRomPage(0); 15 | }; 16 | 17 | Mapper66.prototype.Write = function(address, data) { 18 | var tmp = (data & 0x30) >> 3; 19 | this.nes.SetPrgRomPage(0, tmp); 20 | this.nes.SetPrgRomPage(1, tmp + 1); 21 | 22 | this.nes.SetChrRomPage(data & 0x03); 23 | }; 24 | 25 | module.exports = Mapper66; 26 | -------------------------------------------------------------------------------- /src/js/Mapper/67.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper67 ****/ 5 | var Mapper67 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.MAPPER_REG = new Array(8); 8 | this.IRQ_Toggle = 0x00; 9 | }; 10 | 11 | Mapper67.prototype = Object.create(Base.prototype); 12 | 13 | Mapper67.prototype.Init = function() { 14 | for(var i=0; i> 1) + (this.nes.Out_AY() >> 1); 112 | }; 113 | 114 | Mapper69.prototype.EXSoundSync = function(clock) { 115 | this.nes.Count_AY(clock); 116 | }; 117 | 118 | module.exports = Mapper69; 119 | -------------------------------------------------------------------------------- /src/js/Mapper/7.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper7 ****/ 5 | var Mapper7 = function(nes) { 6 | Base.apply(this, arguments); 7 | }; 8 | 9 | Mapper7.prototype = Object.create(Base.prototype); 10 | 11 | Mapper7.prototype.Init = function() { 12 | this.nes.SetPrgRomPage(0, 0); 13 | this.nes.SetPrgRomPage(1, 1); 14 | this.nes.SetChrRomPage(0); 15 | }; 16 | 17 | Mapper7.prototype.Write = function(address, data) { 18 | var tmp = (data & 0x07) << 1; 19 | this.nes.SetPrgRomPage(0, tmp); 20 | this.nes.SetPrgRomPage(1, tmp + 1); 21 | 22 | if((data & 0x10) === 0x00) 23 | this.nes.SetMirrors(0,0,0,0); 24 | else 25 | this.nes.SetMirrors(1,1,1,1); 26 | }; 27 | 28 | module.exports = Mapper7; 29 | -------------------------------------------------------------------------------- /src/js/Mapper/70.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper70 ****/ 5 | var Mapper70 = function(nes) { 6 | Base.apply(this, arguments); 7 | }; 8 | 9 | Mapper70.prototype = Object.create(Base.prototype); 10 | 11 | Mapper70.prototype.Init = function() { 12 | this.nes.SetPrgRomPage(0, 0); 13 | this.nes.SetPrgRomPage(1, this.nes.PrgRomPageCount - 1); 14 | this.nes.SetChrRomPage(0); 15 | }; 16 | 17 | Mapper70.prototype.Write = function(address, data) { 18 | this.nes.SetPrgRomPage(0, (data & 0x70)>> 4); 19 | this.nes.SetChrRomPage(data & 0x0F); 20 | 21 | if((data & 0x80) === 0x00) 22 | this.nes.SetMirrors(0,0,0,0); 23 | else 24 | this.nes.SetMirrors(1,1,1,1); 25 | }; 26 | 27 | module.exports = Mapper70; 28 | -------------------------------------------------------------------------------- /src/js/Mapper/72.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper72 ****/ 5 | var Mapper72 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.MAPPER_REG = new Array(1); 8 | }; 9 | 10 | Mapper72.prototype = Object.create(Base.prototype); 11 | 12 | Mapper72.prototype.Init = function() { 13 | this.MAPPER_REG[0] = 0; 14 | 15 | this.nes.SetPrgRomPages8K(0, 1, this.nes.PrgRomPageCount * 2 - 2, this.nes.PrgRomPageCount * 2 - 1); 16 | this.nes.SetChrRomPages1K(0, 1, 2, 3, 4, 5, 6, 7); 17 | }; 18 | 19 | Mapper72.prototype.Write = function(address, data) { 20 | var tmp; 21 | if((this.MAPPER_REG[0] & 0xC0) === 0x00) { 22 | if((data & 0x80) === 0x80) { 23 | tmp = (data & 0x07) * 2; 24 | this.nes.SetPrgRomPage8K(0, tmp); 25 | this.nes.SetPrgRomPage8K(1, tmp + 1); 26 | } 27 | if((data & 0x40) === 0x40) { 28 | tmp = (data & 0x0F) * 8; 29 | this.nes.SetChrRomPages1K(tmp, tmp + 1, tmp + 2, tmp + 3, tmp + 4, tmp + 5, tmp + 6, tmp + 7); 30 | } 31 | } 32 | this.MAPPER_REG[0] = data; 33 | }; 34 | 35 | module.exports = Mapper72; 36 | -------------------------------------------------------------------------------- /src/js/Mapper/73.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper73 ****/ 5 | var Mapper73 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.MAPPER_REG = new Array(3); 8 | }; 9 | 10 | Mapper73.prototype = Object.create(Base.prototype); 11 | 12 | Mapper73.prototype.Init = function() { 13 | this.nes.SetPrgRomPages8K(0, 1, this.nes.PrgRomPageCount * 2 - 2, this.nes.PrgRomPageCount * 2 - 1); 14 | this.MAPPER_REG[0] = 0; 15 | this.MAPPER_REG[1] = 0; 16 | this.MAPPER_REG[2] = 0; 17 | }; 18 | 19 | Mapper73.prototype.Write = function(address, data) { 20 | switch (address) { 21 | case 0x8000: 22 | this.MAPPER_REG[0] = (this.MAPPER_REG[0] & 0xFFF0) | (data & 0x0F); 23 | this.MAPPER_REG[2] = this.MAPPER_REG[0]; 24 | break; 25 | 26 | case 0x9000: 27 | this.MAPPER_REG[0] = (this.MAPPER_REG[0] & 0xFF0F) | ((data & 0x0F) << 4); 28 | this.MAPPER_REG[2] = this.MAPPER_REG[0]; 29 | break; 30 | 31 | case 0xA000: 32 | this.MAPPER_REG[0] = (this.MAPPER_REG[0] & 0xF0FF) | ((data & 0x0F) << 8); 33 | this.MAPPER_REG[2] = this.MAPPER_REG[0]; 34 | break; 35 | 36 | case 0xB000: 37 | this.MAPPER_REG[0] = (this.MAPPER_REG[0] & 0x0FFF) | ((data & 0x0F) << 12); 38 | this.MAPPER_REG[2] = this.MAPPER_REG[0]; 39 | break; 40 | 41 | case 0xC000: 42 | this.MAPPER_REG[1] = data & 0x07; 43 | if((this.MAPPER_REG[1] & 0x02) !== 0) { 44 | this.MAPPER_REG[2] = this.MAPPER_REG[0]; 45 | } 46 | break; 47 | 48 | case 0xD000: 49 | if((this.MAPPER_REG[1] & 0x01) !== 0) { 50 | this.MAPPER_REG[1] |= 0x02; 51 | } else { 52 | this.MAPPER_REG[1] &= 0x01; 53 | } 54 | this.ClearIRQ(); 55 | break; 56 | 57 | case 0xF000: 58 | this.nes.SetPrgRomPage8K(0, data * 2); 59 | this.nes.SetPrgRomPage8K(1, data * 2 + 1); 60 | break; 61 | } 62 | }; 63 | 64 | Mapper73.prototype.CPUSync = function(clock) { 65 | if((this.MAPPER_REG[1] & 0x02) !== 0) { 66 | if((this.MAPPER_REG[1] & 0x04) !== 0) { 67 | this.MAPPER_REG[2] += clock; 68 | if(this.MAPPER_REG[2] > 0xFF) { 69 | this.MAPPER_REG[2] = this.MAPPER_REG[0]; 70 | this.SetIRQ(); 71 | } 72 | } else { 73 | this.MAPPER_REG[2] += clock; 74 | if(this.MAPPER_REG[2] > 0xFFFF) { 75 | this.MAPPER_REG[2] = this.MAPPER_REG[0]; 76 | this.SetIRQ(); 77 | } 78 | } 79 | } 80 | }; 81 | 82 | module.exports = Mapper73; 83 | -------------------------------------------------------------------------------- /src/js/Mapper/75.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper75 ****/ 5 | var Mapper75 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.MAPPER_REG = new Array(1); 8 | }; 9 | 10 | Mapper75.prototype = Object.create(Base.prototype); 11 | 12 | Mapper75.prototype.Init = function() { 13 | this.nes.SetPrgRomPages8K(0, 0, 0, this.nes.PrgRomPageCount * 2 - 1); 14 | this.nes.SetChrRomPages1K(0, 0, 0, 0, 0, 0, 0, 0); 15 | this.MAPPER_REG[0] = 0x00; 16 | }; 17 | 18 | Mapper75.prototype.Write = function(address, data) { 19 | var tmp; 20 | switch (address) { 21 | case 0x8000: 22 | this.nes.SetPrgRomPage8K(0, data & 0x0F); 23 | break; 24 | 25 | case 0x9000: 26 | this.MAPPER_REG[0] = data; 27 | if((data & 0x01) === 0x00) 28 | this.nes.SetMirror(false); 29 | else 30 | this.nes.SetMirror(true); 31 | break; 32 | 33 | case 0xA000: 34 | this.nes.SetPrgRomPage8K(1, data & 0x0F); 35 | break; 36 | 37 | case 0xC000: 38 | this.nes.SetPrgRomPage8K(2, data & 0x0F); 39 | break; 40 | 41 | case 0xE000: 42 | tmp = (((this.MAPPER_REG[0] & 0x02) << 3) | (data & 0x0F)) << 2; 43 | this.nes.SetChrRomPage1K(0, tmp); 44 | this.nes.SetChrRomPage1K(1, tmp + 1); 45 | this.nes.SetChrRomPage1K(2, tmp + 2); 46 | this.nes.SetChrRomPage1K(3, tmp + 3); 47 | break; 48 | 49 | case 0xF000: 50 | tmp = (((this.MAPPER_REG[0] & 0x04) << 2) | (data & 0x0F)) << 2; 51 | this.nes.SetChrRomPage1K(4, tmp); 52 | this.nes.SetChrRomPage1K(5, tmp + 1); 53 | this.nes.SetChrRomPage1K(6, tmp + 2); 54 | this.nes.SetChrRomPage1K(7, tmp + 3); 55 | break; 56 | } 57 | }; 58 | 59 | module.exports = Mapper75; 60 | -------------------------------------------------------------------------------- /src/js/Mapper/76.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper76 ****/ 5 | var Mapper76 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.MAPPER_REG = new Array(1); 8 | }; 9 | 10 | Mapper76.prototype = Object.create(Base.prototype); 11 | 12 | Mapper76.prototype.Init = function() { 13 | this.nes.SetPrgRomPages8K(0, 0, this.nes.PrgRomPageCount * 2 - 2, this.nes.PrgRomPageCount * 2 - 1); 14 | this.nes.SetChrRomPages1K(0, 0, 0, 0, 0, 0, 0, 0); 15 | this.MAPPER_REG[0] = 0x00; 16 | }; 17 | 18 | Mapper76.prototype.Write = function(address, data) { 19 | if(address === 0x8000) 20 | this.MAPPER_REG[0] = data & 0x07; 21 | 22 | if(address === 0x8001) { 23 | switch(this.MAPPER_REG[0]) { 24 | case 0x02: 25 | this.nes.SetChrRomPage1K(0, (data & 0x3F) * 2); 26 | this.nes.SetChrRomPage1K(1, (data & 0x3F) * 2 + 1); 27 | break; 28 | case 0x03: 29 | this.nes.SetChrRomPage1K(2, (data & 0x3F) * 2); 30 | this.nes.SetChrRomPage1K(3, (data & 0x3F) * 2 + 1); 31 | break; 32 | case 0x04: 33 | this.nes.SetChrRomPage1K(4, (data & 0x3F) * 2); 34 | this.nes.SetChrRomPage1K(5, (data & 0x3F) * 2 + 1); 35 | break; 36 | case 0x05: 37 | this.nes.SetChrRomPage1K(6, (data & 0x3F) * 2); 38 | this.nes.SetChrRomPage1K(7, (data & 0x3F) * 2 + 1); 39 | break; 40 | case 0x06: 41 | this.nes.SetPrgRomPage8K(0, data & 0x0F); 42 | break; 43 | case 0x07: 44 | this.nes.SetPrgRomPage8K(1, data & 0x0F); 45 | break; 46 | } 47 | } 48 | }; 49 | 50 | module.exports = Mapper76; 51 | -------------------------------------------------------------------------------- /src/js/Mapper/77.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper77 ****/ 5 | var Mapper77 = function(nes) { 6 | Base.apply(this, arguments); 7 | }; 8 | 9 | Mapper77.prototype = Object.create(Base.prototype); 10 | 11 | Mapper77.prototype.Init = function() { 12 | this.nes.SetPrgRomPage(0, 0); 13 | this.nes.SetPrgRomPage(1, 1); 14 | 15 | this.nes.SetChrRomPage1K(0, 0); 16 | this.nes.SetChrRomPage1K(1, 1); 17 | this.nes.SetChrRomPage1K(2, 2 + 0x0100); 18 | this.nes.SetChrRomPage1K(3, 3 + 0x0100); 19 | this.nes.SetChrRomPage1K(4, 4 + 0x0100); 20 | this.nes.SetChrRomPage1K(5, 5 + 0x0100); 21 | this.nes.SetChrRomPage1K(6, 6 + 0x0100); 22 | this.nes.SetChrRomPage1K(7, 7 + 0x0100); 23 | }; 24 | 25 | Mapper77.prototype.Write = function(address, data) { 26 | var tmp = (data & 0x0F) << 1; 27 | this.nes.SetPrgRomPage(0, tmp); 28 | this.nes.SetPrgRomPage(1, tmp + 1); 29 | 30 | tmp = (data & 0xF0) >> 3; 31 | this.nes.SetChrRomPage1K(0, tmp); 32 | this.nes.SetChrRomPage1K(1, tmp + 1); 33 | }; 34 | 35 | module.exports = Mapper77; 36 | -------------------------------------------------------------------------------- /src/js/Mapper/78.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper78 ****/ 5 | var Mapper78 = function(nes) { 6 | Base.apply(this, arguments); 7 | }; 8 | 9 | Mapper78.prototype = Object.create(Base.prototype); 10 | 11 | Mapper78.prototype.Init = function() { 12 | this.nes.SetPrgRomPage(0, 0); 13 | this.nes.SetPrgRomPage(1, this.nes.PrgRomPageCount - 1); 14 | 15 | this.nes.SetChrRomPage(0); 16 | }; 17 | 18 | Mapper78.prototype.Write = function(address, data) { 19 | this.nes.SetPrgRomPage(0, data & 0x07); 20 | this.nes.SetChrRomPage(data >> 4); 21 | 22 | if((data & 0x08) === 0x08) 23 | this.nes.SetMirror(false); 24 | else 25 | this.nes.SetMirror(true); 26 | }; 27 | 28 | module.exports = Mapper78; 29 | -------------------------------------------------------------------------------- /src/js/Mapper/80.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper80 ****/ 5 | var Mapper80 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.MAPPER_REG = new Array(11); 8 | this.EX_RAM = new Array(128); 9 | }; 10 | 11 | Mapper80.prototype = Object.create(Base.prototype); 12 | 13 | Mapper80.prototype.Init = function() { 14 | var i; 15 | for(i=0; i= 0x7F00 && address <= 0x7FFF) 28 | return this.EX_RAM[address & 0x007F]; 29 | 30 | switch(address) { 31 | case 0x7EF0: 32 | return this.MAPPER_REG[0]; 33 | case 0x7EF1: 34 | return this.MAPPER_REG[1]; 35 | case 0x7EF2: 36 | return this.MAPPER_REG[2]; 37 | case 0x7EF3: 38 | return this.MAPPER_REG[3]; 39 | case 0x7EF4: 40 | return this.MAPPER_REG[4]; 41 | case 0x7EF5: 42 | return this.MAPPER_REG[5]; 43 | case 0x7EF6: 44 | case 0x7EF7: 45 | return this.MAPPER_REG[6]; 46 | case 0x7EF8: 47 | case 0x7EF9: 48 | return this.MAPPER_REG[7]; 49 | case 0x7EFA: 50 | case 0x7EFB: 51 | return this.MAPPER_REG[8]; 52 | case 0x7EFC: 53 | case 0x7EFD: 54 | return this.MAPPER_REG[9]; 55 | case 0x7EFE: 56 | case 0x7EFF: 57 | return this.MAPPER_REG[10]; 58 | } 59 | 60 | return 0x00; 61 | }; 62 | 63 | Mapper80.prototype.WriteSRAM = function(address, data) { 64 | if(address >= 0x7F00 && address <= 0x7FFF) { 65 | this.EX_RAM[address & 0x007F] = data; 66 | return; 67 | } 68 | 69 | switch(address) { 70 | case 0x7EF0: 71 | this.MAPPER_REG[0] = data; 72 | this.nes.SetChrRomPage1K(0, data & 0xFE); 73 | this.nes.SetChrRomPage1K(1, (data & 0xFE) + 1); 74 | break; 75 | case 0x7EF1: 76 | this.MAPPER_REG[1] = data; 77 | this.nes.SetChrRomPage1K(2, data & 0xFE); 78 | this.nes.SetChrRomPage1K(3, (data & 0xFE) + 1); 79 | break; 80 | case 0x7EF2: 81 | this.MAPPER_REG[2] = data; 82 | this.nes.SetChrRomPage1K(4, data); 83 | break; 84 | case 0x7EF3: 85 | this.MAPPER_REG[3] = data; 86 | this.nes.SetChrRomPage1K(5, data); 87 | break; 88 | case 0x7EF4: 89 | this.MAPPER_REG[4] = data; 90 | this.nes.SetChrRomPage1K(6, data); 91 | break; 92 | case 0x7EF5: 93 | this.MAPPER_REG[5] = data; 94 | this.nes.SetChrRomPage1K(7, data); 95 | break; 96 | case 0x7EF6: 97 | case 0x7EF7: 98 | this.MAPPER_REG[6] = data; 99 | if((data & 0x01) === 0x01) 100 | this.nes.SetMirror(false); 101 | else 102 | this.nes.SetMirror(true); 103 | break; 104 | case 0x7EF8: 105 | case 0x7EF9: 106 | this.MAPPER_REG[7] = data; 107 | break; 108 | case 0x7EFA: 109 | case 0x7EFB: 110 | this.MAPPER_REG[8] = data; 111 | this.nes.SetPrgRomPage8K(0, data); 112 | break; 113 | case 0x7EFC: 114 | case 0x7EFD: 115 | this.MAPPER_REG[9] = data; 116 | this.nes.SetPrgRomPage8K(1, data); 117 | break; 118 | case 0x7EFE: 119 | case 0x7EFF: 120 | this.MAPPER_REG[10] = data; 121 | this.nes.SetPrgRomPage8K(2, data); 122 | break; 123 | } 124 | }; 125 | 126 | module.exports = Mapper80; 127 | -------------------------------------------------------------------------------- /src/js/Mapper/82.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper82 ****/ 5 | var Mapper82 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.MAPPER_REG = new Array(13); 8 | this.EX_RAM = new Array(0x1400); 9 | }; 10 | 11 | Mapper82.prototype = Object.create(Base.prototype); 12 | 13 | Mapper82.prototype.Init = function() { 14 | var i; 15 | for(i=0; i= 0x6000 && address <= 0x73FF) 28 | return this.EX_RAM[address - 0x6000]; 29 | 30 | if(address >= 0x7EF0 && address <= 0x7EFC) 31 | return this.MAPPER_REG[address - 0x7EF0]; 32 | }; 33 | 34 | Mapper82.prototype.WriteSRAM = function(address, data) { 35 | if(address >= 0x6000 && address <= 0x73FF) { 36 | this.EX_RAM[address - 0x6000] = data; 37 | return; 38 | } 39 | 40 | switch(address) { 41 | case 0x7EF0: 42 | this.MAPPER_REG[0] = data; 43 | this.SetChr(); 44 | break; 45 | case 0x7EF1: 46 | this.MAPPER_REG[1] = data; 47 | this.SetChr(); 48 | break; 49 | case 0x7EF2: 50 | this.MAPPER_REG[2] = data; 51 | this.SetChr(); 52 | break; 53 | case 0x7EF3: 54 | this.MAPPER_REG[3] = data; 55 | this.SetChr(); 56 | break; 57 | case 0x7EF4: 58 | this.MAPPER_REG[4] = data; 59 | this.SetChr(); 60 | break; 61 | case 0x7EF5: 62 | this.MAPPER_REG[5] = data; 63 | this.SetChr(); 64 | break; 65 | case 0x7EF6: 66 | this.MAPPER_REG[6] = data; 67 | this.SetChr(); 68 | if((data & 0x01) === 0x01) 69 | this.nes.SetMirror(false); 70 | else 71 | this.nes.SetMirror(true); 72 | break; 73 | case 0x7EF7: 74 | this.MAPPER_REG[7] = data; 75 | break; 76 | case 0x7EF8: 77 | this.MAPPER_REG[8] = data; 78 | break; 79 | case 0x7EF9: 80 | this.MAPPER_REG[9] = data; 81 | break; 82 | case 0x7EFA: 83 | this.MAPPER_REG[10] = data; 84 | this.nes.SetPrgRomPage8K(0, data >>> 2); 85 | break; 86 | case 0x7EFB: 87 | this.MAPPER_REG[11] = data; 88 | this.nes.SetPrgRomPage8K(1, data >>> 2); 89 | break; 90 | case 0x7EFC: 91 | this.MAPPER_REG[12] = data; 92 | this.nes.SetPrgRomPage8K(2, data >>> 2); 93 | break; 94 | } 95 | }; 96 | 97 | Mapper82.prototype.SetChr = function() { 98 | if((this.MAPPER_REG[6] & 0x02) === 0x00) { 99 | this.nes.SetChrRomPage1K(0, this.MAPPER_REG[0] & 0xFE); 100 | this.nes.SetChrRomPage1K(1, (this.MAPPER_REG[0] & 0xFE) + 1); 101 | this.nes.SetChrRomPage1K(2, this.MAPPER_REG[1] & 0xFE); 102 | this.nes.SetChrRomPage1K(3, (this.MAPPER_REG[1] & 0xFE) + 1); 103 | this.nes.SetChrRomPage1K(4, this.MAPPER_REG[2]); 104 | this.nes.SetChrRomPage1K(5, this.MAPPER_REG[3]); 105 | this.nes.SetChrRomPage1K(6, this.MAPPER_REG[4]); 106 | this.nes.SetChrRomPage1K(7, this.MAPPER_REG[5]); 107 | } else { 108 | this.nes.SetChrRomPage1K(4, this.MAPPER_REG[0] & 0xFE); 109 | this.nes.SetChrRomPage1K(5, (this.MAPPER_REG[0] & 0xFE) + 1); 110 | this.nes.SetChrRomPage1K(6, this.MAPPER_REG[1] & 0xFE); 111 | this.nes.SetChrRomPage1K(7, (this.MAPPER_REG[1] & 0xFE) + 1); 112 | this.nes.SetChrRomPage1K(0, this.MAPPER_REG[2]); 113 | this.nes.SetChrRomPage1K(1, this.MAPPER_REG[3]); 114 | this.nes.SetChrRomPage1K(2, this.MAPPER_REG[4]); 115 | this.nes.SetChrRomPage1K(3, this.MAPPER_REG[5]); 116 | } 117 | }; 118 | 119 | module.exports = Mapper82; 120 | -------------------------------------------------------------------------------- /src/js/Mapper/85.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper85 ****/ 5 | var Mapper85 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.MAPPER_REG = new Array(15); 8 | this.MAPPER_EXVRAM = new Array(8); 9 | }; 10 | 11 | Mapper85.prototype = Object.create(Base.prototype); 12 | 13 | Mapper85.prototype.Init = function() { 14 | var i; 15 | for(i=0; i= 0xFF) { 167 | this.MAPPER_REG[12] = this.MAPPER_REG[13]; 168 | this.SetIRQ(); 169 | } else 170 | this.MAPPER_REG[12] += clock; 171 | } 172 | }; 173 | 174 | module.exports = Mapper85; 175 | -------------------------------------------------------------------------------- /src/js/Mapper/86.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper86 ****/ 5 | var Mapper86 = function(nes) { 6 | Base.apply(this, arguments); 7 | }; 8 | 9 | Mapper86.prototype = Object.create(Base.prototype); 10 | 11 | Mapper86.prototype.Init = function() { 12 | this.nes.SetPrgRomPages8K(this.nes.PrgRomPageCount * 2 - 4, this.nes.PrgRomPageCount * 2 - 3, this.nes.PrgRomPageCount * 2 - 2, this.nes.PrgRomPageCount * 2 - 1); 13 | this.nes.SetChrRomPages1K(0, 1, 2, 3, 4, 5, 6, 7); 14 | }; 15 | 16 | Mapper86.prototype.WriteSRAM = function(address, data) { 17 | if(address >= 0x6000 && address < 0x6FFF) { 18 | var prg = ((data & 0x30) >>> 4) << 2; 19 | var chr = (((data & 0x40) >>> 4) | (data & 0x03)) << 3; 20 | this.nes.SetPrgRomPages8K(prg, prg + 1, prg + 2, prg + 3); 21 | this.nes.SetChrRomPages1K(chr, chr + 1, chr + 2, chr + 3, chr + 4, chr + 5, chr + 6, chr + 7); 22 | } 23 | }; 24 | 25 | module.exports = Mapper86; 26 | -------------------------------------------------------------------------------- /src/js/Mapper/87.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper87 ****/ 5 | var Mapper87 = function(nes) { 6 | Base.apply(this, arguments); 7 | }; 8 | 9 | Mapper87.prototype = Object.create(Base.prototype); 10 | 11 | Mapper87.prototype.Init = function() { 12 | this.nes.SetPrgRomPage(0, 0); 13 | this.nes.SetPrgRomPage(1, this.nes.PrgRomPageCount - 1); 14 | this.nes.SetChrRomPage(0); 15 | }; 16 | 17 | Mapper87.prototype.WriteSRAM = function(address, data) { 18 | var chr = ((data & 0x02) >>> 1) | ((data & 0x01) << 1); 19 | this.nes.SetChrRomPage(chr); 20 | }; 21 | 22 | module.exports = Mapper87; 23 | -------------------------------------------------------------------------------- /src/js/Mapper/88.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper88 ****/ 5 | var Mapper88 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.MAPPER_REG = new Array(1); 8 | }; 9 | 10 | Mapper88.prototype = Object.create(Base.prototype); 11 | 12 | Mapper88.prototype.Init = function() { 13 | this.nes.SetPrgRomPages8K(0, 0, this.nes.PrgRomPageCount * 2 - 2, this.nes.PrgRomPageCount * 2 - 1); 14 | this.nes.SetChrRomPages1K(0, 0, 0, 0, 0, 0, 0, 0); 15 | this.MAPPER_REG[0] = 0x00; 16 | }; 17 | 18 | Mapper88.prototype.Write = function(address, data) { 19 | if(address === 0x8000) 20 | this.MAPPER_REG[0] = data & 0x07; 21 | 22 | if(address === 0x8001) { 23 | switch(this.MAPPER_REG[0]) { 24 | case 0x00: 25 | this.nes.SetChrRomPage1K(0, data & 0x3E); 26 | this.nes.SetChrRomPage1K(1, (data & 0x3E) + 1); 27 | break; 28 | case 0x01: 29 | this.nes.SetChrRomPage1K(2, data & 0x3E); 30 | this.nes.SetChrRomPage1K(3, (data & 0x3E) + 1); 31 | break; 32 | case 0x02: 33 | this.nes.SetChrRomPage1K(4, (data & 0x3F) | 0x40); 34 | break; 35 | case 0x03: 36 | this.nes.SetChrRomPage1K(5, (data & 0x3F) | 0x40); 37 | break; 38 | case 0x04: 39 | this.nes.SetChrRomPage1K(6, (data & 0x3F) | 0x40); 40 | break; 41 | case 0x05: 42 | this.nes.SetChrRomPage1K(7, (data & 0x3F) | 0x40); 43 | break; 44 | case 0x06: 45 | this.nes.SetPrgRomPage8K(0, data & 0x0F); 46 | break; 47 | case 0x07: 48 | this.nes.SetPrgRomPage8K(1, data & 0x0F); 49 | break; 50 | } 51 | } 52 | }; 53 | 54 | module.exports = Mapper88; 55 | -------------------------------------------------------------------------------- /src/js/Mapper/89.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper89 ****/ 5 | var Mapper89 = function(nes) { 6 | Base.apply(this, arguments); 7 | }; 8 | 9 | Mapper89.prototype = Object.create(Base.prototype); 10 | 11 | Mapper89.prototype.Init = function() { 12 | this.nes.SetPrgRomPage(0, 0); 13 | this.nes.SetPrgRomPage(1, this.nes.PrgRomPageCount - 1); 14 | 15 | this.nes.SetChrRomPage(0); 16 | }; 17 | 18 | Mapper89.prototype.Write = function(address, data) { 19 | this.nes.SetPrgRomPage(0, (data & 0x70) >> 4); 20 | this.nes.SetChrRomPage(((data & 0x80) >> 4) | (data & 0x07)); 21 | 22 | if((data & 0x08) === 0x00) 23 | this.nes.SetMirrors(0, 0, 0, 0); 24 | else 25 | this.nes.SetMirrors(1, 1, 1, 1); 26 | }; 27 | 28 | module.exports = Mapper89; 29 | -------------------------------------------------------------------------------- /src/js/Mapper/9.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper9 ****/ 5 | var Mapper9 = function(nes) {//<-- 6 | Base.apply(this, arguments); 7 | //this.MAPPER_REG = new Array(6); 8 | this.MAPPER_REG = new Array(4); 9 | this.MAPPER_Latch0 = true; 10 | this.MAPPER_Latch1 = true; 11 | }; 12 | 13 | Mapper9.prototype = Object.create(Base.prototype); 14 | 15 | Mapper9.prototype.Init = function() { 16 | this.nes.SetPrgRomPages8K(0, this.nes.PrgRomPageCount * 2 - 3, this.nes.PrgRomPageCount * 2 - 2, this.nes.PrgRomPageCount * 2 - 1); 17 | this.nes.SetChrRomPages1K(0, 0, 0, 0, 0, 0, 0, 0); 18 | for(var i=0; i> 12) | (this.nes.IO1[0x00] & 0x10) << 8; 57 | var nameAddrHigh = nameAddr >> 10; 58 | var nameAddrLow = nameAddr & 0x03FF; 59 | var tmpVRAMHigh = tmpVRAM[nameAddrHigh]; 60 | var tmpPaletteArray = this.nes.PaletteArray; 61 | var tmpSPBitArray = this.nes.SPBitArray; 62 | 63 | var q = 0; 64 | var s = this.nes.HScrollTmp; 65 | 66 | for(var p=0; p<33; p++) { 67 | var ptnDist = (tmpVRAMHigh[nameAddrLow] << 4) | tableAddr; 68 | var tmpptnDist = ptnDist; 69 | 70 | this.SetChrRom(tmpptnDist); 71 | 72 | var tmpSrcV = tmpVRAM[ptnDist >> 10]; 73 | ptnDist &= 0x03FF; 74 | var attr = ((tmpVRAMHigh[((nameAddrLow & 0x0380) >> 4) | ((nameAddrLow & 0x001C) >> 2) + 0x03C0] << 2) >> (((nameAddrLow & 0x0040) >> 4) | (nameAddrLow & 0x0002))) & 0x0C; 75 | var ptn = tmpSPBitArray[tmpSrcV[ptnDist]][tmpSrcV[ptnDist + 8]]; 76 | 77 | for(; s<8; s++, q++) 78 | tmpBgLineBuffer[q] = tmpPaletteArray[ptn[s] | attr]; 79 | s = 0; 80 | 81 | this.SetLatch(tmpptnDist); 82 | 83 | if((nameAddrLow & 0x001F) === 0x001F) { 84 | nameAddrLow &= 0xFFE0; 85 | tmpVRAMHigh = tmpVRAM[(nameAddrHigh ^= 0x01)]; 86 | } else 87 | nameAddrLow++; 88 | } 89 | }; 90 | 91 | Mapper9.prototype.SetLatch = function (addr) { 92 | addr &= 0x1FF0; 93 | if(addr === 0x0FD0) 94 | this.MAPPER_Latch0 = false; 95 | //this.MAPPER_REG[4] = false; 96 | if(addr === 0x1FD0) 97 | this.MAPPER_Latch1 = false; 98 | //this.MAPPER_REG[5] = false; 99 | if(addr === 0x0FE0) 100 | this.MAPPER_Latch0 = true; 101 | //this.MAPPER_REG[4] = true; 102 | if(addr === 0x1FE0) 103 | this.MAPPER_Latch1 = true; 104 | //this.MAPPER_REG[5] = true; 105 | }; 106 | 107 | Mapper9.prototype.SetChrRom = function (addr) { 108 | if((addr & 0x1000) === 0x0000) { 109 | if(!this.MAPPER_Latch0) { 110 | //if(!this.MAPPER_REG[4]) { 111 | this.nes.SetChrRomPage1K(0, this.MAPPER_REG[0] * 4); 112 | this.nes.SetChrRomPage1K(1, this.MAPPER_REG[0] * 4 + 1); 113 | this.nes.SetChrRomPage1K(2, this.MAPPER_REG[0] * 4 + 2); 114 | this.nes.SetChrRomPage1K(3, this.MAPPER_REG[0] * 4 + 3); 115 | } else { 116 | this.nes.SetChrRomPage1K(0, this.MAPPER_REG[1] * 4); 117 | this.nes.SetChrRomPage1K(1, this.MAPPER_REG[1] * 4 + 1); 118 | this.nes.SetChrRomPage1K(2, this.MAPPER_REG[1] * 4 + 2); 119 | this.nes.SetChrRomPage1K(3, this.MAPPER_REG[1] * 4 + 3); 120 | } 121 | } else { 122 | if(!this.MAPPER_Latch1) { 123 | //if(!this.MAPPER_REG[5]) { 124 | this.nes.SetChrRomPage1K(4, this.MAPPER_REG[2] * 4); 125 | this.nes.SetChrRomPage1K(5, this.MAPPER_REG[2] * 4 + 1); 126 | this.nes.SetChrRomPage1K(6, this.MAPPER_REG[2] * 4 + 2); 127 | this.nes.SetChrRomPage1K(7, this.MAPPER_REG[2] * 4 + 3); 128 | } else { 129 | this.nes.SetChrRomPage1K(4, this.MAPPER_REG[3] * 4); 130 | this.nes.SetChrRomPage1K(5, this.MAPPER_REG[3] * 4 + 1); 131 | this.nes.SetChrRomPage1K(6, this.MAPPER_REG[3] * 4 + 2); 132 | this.nes.SetChrRomPage1K(7, this.MAPPER_REG[3] * 4 + 3); 133 | } 134 | } 135 | }; 136 | 137 | Mapper9.prototype.BuildSpriteLine = function () { 138 | var tmpBgLineBuffer = this.nes.BgLineBuffer; 139 | var tmpIsSpriteClipping = (this.nes.IO1[0x01] & 0x04) === 0x04 ? 0 : 8; 140 | 141 | if((this.nes.IO1[0x01] & 0x10) === 0x10) { 142 | var tmpSpLine = this.nes.SpriteLineBuffer; 143 | for(var p=0; p<256; p++) 144 | tmpSpLine[p] = 256; 145 | 146 | var tmpSpRAM = this.nes.SPRITE_RAM; 147 | var tmpBigSize = (this.nes.IO1[0x00] & 0x20) === 0x20 ? 16 : 8; 148 | var tmpSpPatternTableAddress = (this.nes.IO1[0x00] & 0x08) << 9; 149 | 150 | var tmpVRAM = this.nes.VRAM; 151 | var tmpSPBitArray = this.nes.SPBitArray; 152 | 153 | var lineY = this.nes.PpuY; 154 | var count = 0; 155 | 156 | for(var i=0; i<=252; i+=4) { 157 | var isy = tmpSpRAM[i] + 1; 158 | if(isy > lineY || (isy + tmpBigSize) <= lineY) 159 | continue; 160 | 161 | if(i === 0) 162 | this.nes.Sprite0Line = true; 163 | 164 | if(++count === 9) { 165 | i = 256; 166 | continue; 167 | } 168 | 169 | var x = tmpSpRAM[i + 3]; 170 | var ex = x + 8; 171 | if(ex > 256) 172 | ex = 256; 173 | 174 | var attr = tmpSpRAM[i + 2]; 175 | 176 | var attribute = ((attr & 0x03) << 2) | 0x10; 177 | var bgsp = attr & 0x20; 178 | 179 | var iy = (attr & 0x80) === 0x80 ? tmpBigSize - 1 - (lineY - isy) : lineY - isy; 180 | var tileNum = ((iy & 0x08) << 1) + (iy & 0x07) + 181 | (tmpBigSize === 8 ? (tmpSpRAM[i + 1] << 4) + tmpSpPatternTableAddress : ((tmpSpRAM[i + 1] & 0xFE) << 4) + ((tmpSpRAM[i + 1] & 0x01) << 12)); 182 | 183 | this.SetChrRom(tileNum); 184 | 185 | var tmpHigh = tmpVRAM[tileNum >> 10]; 186 | var tmpLow = tileNum & 0x03FF; 187 | var ptn = tmpSPBitArray[tmpHigh[tmpLow]][tmpHigh[tmpLow + 8]]; 188 | 189 | var is; 190 | var ia; 191 | if((attr & 0x40) === 0x00) { 192 | is = 0; 193 | ia = 1; 194 | } else { 195 | is = 7; 196 | ia = -1; 197 | } 198 | 199 | for(; x= tmpIsSpriteClipping && (bgsp === 0x00 || tmpBgLineBuffer[x] === 0x10)) 205 | tmpBgLineBuffer[x] = tmpPtn | attribute; 206 | } 207 | } 208 | 209 | this.SetLatch(tileNum); 210 | } 211 | 212 | if(count >= 8) 213 | this.nes.IO1[0x02] |= 0x20; 214 | else 215 | this.nes.IO1[0x02] &= 0xDF; 216 | } 217 | }; 218 | 219 | Mapper9.prototype.GetState = function() { 220 | this.nes.StateData.Mapper = {}; 221 | this.nes.StateData.Mapper.MAPPER_REG = this.MAPPER_REG.slice(0); 222 | 223 | this.nes.StateData.Mapper.MAPPER_Latch0 = this.MAPPER_Latch0; 224 | this.nes.StateData.Mapper.MAPPER_Latch1 = this.MAPPER_Latch1; 225 | }; 226 | 227 | Mapper9.prototype.SetState = function() { 228 | for(var i=0; i= 0x9000) { 21 | if((address & 0xF0) === 0xD0) { 22 | this.nes.SetPrgRomPages8K(0, 1, prg, prg + 1); 23 | } else if((address & 0xF0) === 0xE0) { 24 | this.nes.SetChrRomPages1K(chr, chr + 1, chr + 2, chr + 3, chr + 4, chr + 5, chr + 6, chr + 7); 25 | } 26 | } else { 27 | if((address & 0xF0) === 0xB0) { 28 | this.nes.SetPrgRomPages8K(0, 1, prg, prg + 1); 29 | } else if((address & 0xF0) === 0x70) { 30 | this.nes.SetChrRomPages1K(chr, chr + 1, chr + 2, chr + 3, chr + 4, chr + 5, chr + 6, chr + 7); 31 | } 32 | } 33 | }; 34 | 35 | module.exports = Mapper92; 36 | -------------------------------------------------------------------------------- /src/js/Mapper/93.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper93 ****/ 5 | var Mapper93 = function(nes) { 6 | Base.apply(this, arguments); 7 | }; 8 | 9 | Mapper93.prototype = Object.create(Base.prototype); 10 | 11 | Mapper93.prototype.Init = function() { 12 | this.nes.SetPrgRomPages8K(0, 1, this.nes.PrgRomPageCount * 2 - 2, this.nes.PrgRomPageCount * 2 - 1); 13 | this.nes.SetChrRomPages1K(0, 1, 2, 3, 4, 5, 6, 7); 14 | }; 15 | 16 | Mapper93.prototype.WriteSRAM = function(address, data) { 17 | if(address === 0x6000) { 18 | this.nes.SetPrgRomPage8K(0, data * 2); 19 | this.nes.SetPrgRomPage8K(1, data * 2 + 1); 20 | } 21 | }; 22 | 23 | module.exports = Mapper93; 24 | -------------------------------------------------------------------------------- /src/js/Mapper/94.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper94 ****/ 5 | var Mapper94 = function(nes) { 6 | Base.apply(this, arguments); 7 | }; 8 | 9 | Mapper94.prototype = Object.create(Base.prototype); 10 | 11 | Mapper94.prototype.Init = function() { 12 | this.nes.SetPrgRomPage(0, 0); 13 | this.nes.SetPrgRomPage(1, this.nes.PrgRomPageCount - 1); 14 | this.nes.SetChrRomPage(0); 15 | }; 16 | 17 | Mapper94.prototype.Write = function(address, data) { 18 | this.nes.SetPrgRomPage(0, data >> 2); 19 | }; 20 | 21 | module.exports = Mapper94; 22 | -------------------------------------------------------------------------------- /src/js/Mapper/95.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper95 ****/ 5 | var Mapper95 = function(nes) { 6 | Base.apply(this, arguments); 7 | this.MAPPER_REG = new Array(1); 8 | }; 9 | 10 | Mapper95.prototype = Object.create(Base.prototype); 11 | 12 | Mapper95.prototype.Init = function() { 13 | this.nes.SetPrgRomPages8K(0, 0, this.nes.PrgRomPageCount * 2 - 2, this.nes.PrgRomPageCount * 2 - 1); 14 | this.nes.SetChrRomPages1K(0, 0, 0, 0, 0, 0, 0, 0); 15 | this.MAPPER_REG[0] = 0x00; 16 | }; 17 | 18 | Mapper95.prototype.Write = function(address, data) { 19 | if((address & 0x0001) === 0x0000) 20 | this.MAPPER_REG[0] = data & 0x07; 21 | 22 | if((address & 0x0001) === 0x0001) { 23 | if(this.MAPPER_REG[0] <= 0x05) { 24 | if((data & 0x20) === 0x20) 25 | this.nes.SetMirrors(1, 1, 1, 1); 26 | else 27 | this.nes.SetMirrors(0, 0, 0, 0); 28 | } 29 | 30 | switch(this.MAPPER_REG[0]) { 31 | case 0x00: 32 | this.nes.SetChrRomPage1K(0, data & 0x1E); 33 | this.nes.SetChrRomPage1K(1, (data & 0x1E) + 1); 34 | break; 35 | case 0x01: 36 | this.nes.SetChrRomPage1K(2, data & 0x1E); 37 | this.nes.SetChrRomPage1K(3, (data & 0x1E) + 1); 38 | break; 39 | case 0x02: 40 | this.nes.SetChrRomPage1K(4, data & 0x1F); 41 | break; 42 | case 0x03: 43 | this.nes.SetChrRomPage1K(5, data & 0x1F); 44 | break; 45 | case 0x04: 46 | this.nes.SetChrRomPage1K(6, data & 0x1F); 47 | break; 48 | case 0x05: 49 | this.nes.SetChrRomPage1K(7, data & 0x1F); 50 | break; 51 | case 0x06: 52 | this.nes.SetPrgRomPage8K(0, data & 0x0F); 53 | break; 54 | case 0x07: 55 | this.nes.SetPrgRomPage8K(1, data & 0x0F); 56 | break; 57 | } 58 | } 59 | }; 60 | 61 | module.exports = Mapper95; 62 | -------------------------------------------------------------------------------- /src/js/Mapper/97.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = require('./Base'); 4 | /**** Mapper97 ****/ 5 | var Mapper97 = function(nes) { 6 | Base.apply(this, arguments); 7 | }; 8 | 9 | Mapper97.prototype = Object.create(Base.prototype); 10 | 11 | Mapper97.prototype.Init = function() { 12 | this.nes.SetPrgRomPage(0, this.nes.PrgRomPageCount - 1); 13 | this.nes.SetPrgRomPage(1, 0); 14 | 15 | this.nes.SetChrRomPage(0); 16 | }; 17 | 18 | Mapper97.prototype.Write = function(address, data) { 19 | this.nes.SetPrgRomPage(1, data & 0x0F); 20 | 21 | switch(data & 0xC0) { 22 | case 0x00: 23 | this.nes.SetMirrors(0, 0, 0, 0); 24 | break; 25 | case 0x40: 26 | this.nes.SetMirror(true); 27 | break; 28 | case 0x80: 29 | this.nes.SetMirror(false); 30 | break; 31 | case 0xC0: 32 | this.nes.SetMirrors(1, 1, 1, 1); 33 | break; 34 | } 35 | }; 36 | 37 | module.exports = Mapper97; 38 | -------------------------------------------------------------------------------- /src/js/Mapper/Base.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var Base = function(nes) { 4 | this.nes = nes; 5 | this.MAPPER_REG = null; 6 | }; 7 | 8 | Base.prototype.Init = function() { 9 | }; 10 | 11 | Base.prototype.ReadLow = function(address) { 12 | return 0x40; 13 | }; 14 | 15 | Base.prototype.WriteLow = function(address, data) { 16 | }; 17 | 18 | Base.prototype.ReadPPUData = function () { 19 | return this.nes.ReadPPUData_SUB(); 20 | }; 21 | 22 | Base.prototype.WritePPUData = function (value) { 23 | this.nes.WritePPUData_SUB(value); 24 | }; 25 | 26 | Base.prototype.BuildBGLine = function () { 27 | this.nes.BuildBGLine_SUB(); 28 | }; 29 | 30 | Base.prototype.BuildSpriteLine = function () { 31 | this.nes.BuildSpriteLine_SUB(); 32 | }; 33 | 34 | // セーブ用RAM読み込み 35 | Base.prototype.ReadSRAM = function(address) { 36 | return this.nes.SRAM[address & 0x1FFF]; 37 | }; 38 | // セーブ用RAM書き込み 39 | Base.prototype.WriteSRAM = function(address, data) { 40 | this.nes.SRAM[address & 0x1FFF] = data; 41 | }; 42 | 43 | Base.prototype.Write = function(address, data) { 44 | }; 45 | 46 | Base.prototype.HSync = function(y) { 47 | }; 48 | 49 | Base.prototype.CPUSync = function(clock) { 50 | }; 51 | 52 | Base.prototype.SetIRQ = function() { 53 | this.nes.toIRQ |= 0x04; 54 | }; 55 | 56 | Base.prototype.ClearIRQ = function() { 57 | this.nes.toIRQ &= ~0x04; 58 | }; 59 | 60 | Base.prototype.OutEXSound = function(soundin) { 61 | return soundin; 62 | }; 63 | 64 | Base.prototype.EXSoundSync = function(clock) { 65 | }; 66 | 67 | Base.prototype.GetState = function() { 68 | if(this.MAPPER_REG === null) 69 | return; 70 | 71 | this.nes.StateData.Mapper = {}; 72 | this.nes.StateData.Mapper.MAPPER_REG = this.MAPPER_REG.slice(0); 73 | }; 74 | 75 | Base.prototype.SetState = function() { 76 | if(this.MAPPER_REG === null) 77 | return; 78 | 79 | for(var i=0; i