-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnes.js
54 lines (46 loc) · 1.24 KB
/
nes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var Nes = (function () {
'use strict';
var Nes = function (rom) {
var interconnect = new Interconnect(rom);
this.rom = rom;
this.cpu = new Cpu(interconnect);
this.header = {};
};
Nes.prototype.runInstructions = function () {
for (var i = 0; i < 10; i+= 1) {
this.cpu.runInstruction();
}
};
Nes.prototype.parseHeader = function () {
var r = this.rom,
header = {},
byte;
if (r.getUint32(0, false) !== 0x4e45531a) {
console.error('Error: Not a iNES rom');
}
header.noOf16kPrgRomPageCount = r.getUint8(4);
header.noOf8kChrRomPageCount = r.getUint8(5);
byte = r.getUint8(6);
header.romControlByte1 = {
horizontalMirroring: byte & (1 << 0) === 0,
verticalMirroring: byte & (1 << 0) === 1,
battery: byte & (1 << 1) === 1,
trainer: byte & (1 << 2) === 1,
fourScreenVram: byte & (1 << 3) === 1
};
header.mapperLowerNibble = byte >> 4;
byte = r.getUint8(7);
header.romControlByte2 = {
vsUnisystem: byte & (1 << 0) === 1,
playChoice10: byte & (1 << 1) === 1,
nesV2: byte & (2 << 2) === 1
};
header.mapperUpperNibble = byte >> 4;
this.header = header;
if (!header.romControlByte1.trainer) {
this.cpu.registers.pc = 0x10;
}
console.log(header);
};
return Nes;
}());