-
Notifications
You must be signed in to change notification settings - Fork 833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Game Genie support #89
Open
satoshinm
wants to merge
8
commits into
bfirsh:master
Choose a base branch
from
satoshinm:gg
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ea03fe2
Refactor this.nes.mmap.load() into this.loadFromCartridge()
satoshinm e031daf
Hardcode test for SMB infinite lives GG code (SXIOPO)
satoshinm a11137a
Add Game Genie module with decoding/encoding support
satoshinm 887230b
Remove sample code
satoshinm c18d859
GG can't modify SP or NMI, no need to bounce through loadFromCartridge()
satoshinm 5e9e307
Add support for decoding hex codes (e.g. 11d9:ad)
satoshinm 62f4513
Remove code examples
satoshinm 2f3eef3
Expand gg to GameGenie
satoshinm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
|
||
var GG = function(nes) { | ||
this.nes = nes; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
this.patches = []; | ||
this.enabled = true; | ||
}; | ||
|
||
var LETTER_VALUES = 'APZLGITYEOXUKSVN'; | ||
|
||
function toDigit(letter) { | ||
return LETTER_VALUES.indexOf(letter); | ||
} | ||
|
||
function toLetter(digit) { | ||
return LETTER_VALUES.substr(digit, 1); | ||
} | ||
|
||
function toHex(n, width) { | ||
var s = n.toString(16); | ||
return '0000'.substring(0, width - s.length) + s; | ||
} | ||
|
||
|
||
GG.prototype = { | ||
setEnabled: function(enabled) { | ||
this.enabled = enabled; | ||
}, | ||
|
||
addCode: function(code) { | ||
this.patches.push(this.decode(code)); | ||
}, | ||
|
||
addPatch: function(addr, value, key) { | ||
this.patches.push({addr: addr, value: value, key: key}); | ||
}, | ||
|
||
applyCodes: function(addr, value) { | ||
if (!this.enabled) return value; | ||
|
||
for (var i = 0; i < this.patches.length; ++i) { // TODO: optimize data structure? | ||
if (this.patches[i].addr === (addr & 0x7fff)) { | ||
if (this.patches[i].key === undefined || this.patches[i].key === value) { | ||
return this.patches[i].value; | ||
} | ||
} | ||
} | ||
return value; | ||
}, | ||
|
||
decode: function(code) { | ||
if (code.indexOf(':') !== -1) return this.decodeHex(code); | ||
|
||
var digits = code.toUpperCase().split('').map(toDigit); | ||
|
||
var value = ((digits[0] & 8) << 4) + ((digits[1] & 7) << 4) + (digits[0] & 7); | ||
var addr = ((digits[3] & 7) << 12) + ((digits[4] & 8) << 8) + ((digits[5] & 7) << 8) + | ||
((digits[1] & 8) << 4) + ((digits[2] & 7) << 4) + (digits[3] & 8) + (digits[4] & 7); | ||
var key; | ||
|
||
if (digits.length === 8) { | ||
value += (digits[7] & 8); | ||
key = ((digits[6] & 8) << 4) + ((digits[7] & 7) << 4) + (digits[5] & 8) + (digits[6] & 7); | ||
} else { | ||
value += (digits[5] & 8); | ||
} | ||
|
||
var wantskey = !!(digits[2] >> 3); | ||
|
||
return { value: value, addr: addr, wantskey: wantskey, key: key }; | ||
}, | ||
|
||
encodeHex: function(addr, value, key, wantskey) { | ||
var s = toHex(addr, 4) + ':' + toHex(value, 2); | ||
|
||
if (key !== undefined || wantskey) { | ||
s += '?'; | ||
} | ||
|
||
if (key !== undefined) { | ||
s += toHex(key, 2); | ||
} | ||
|
||
return s; | ||
}, | ||
|
||
decodeHex: function(s) { | ||
var match = s.match(/([0-9a-fA-F]+):([0-9a-fA-F]+)(\?[0-9a-fA-F]*)?/); | ||
if (!match) return null; | ||
|
||
var addr = parseInt(match[1], 16); | ||
var value = parseInt(match[2], 16); | ||
var wantskey = match[3] !== undefined; | ||
var key = (match[3] !== undefined && match[3].length > 1) ? parseInt(match[3].substring(1), 16) : undefined; | ||
|
||
return { value: value, addr: addr, wantskey: wantskey, key: key }; | ||
}, | ||
|
||
encode: function(addr, value, key, wantskey) { | ||
var digits = Array(6); | ||
|
||
digits[0] = (value & 7) + ((value >> 4) & 8); | ||
digits[1] = ((value >> 4) & 7) + ((addr >> 4) & 8); | ||
digits[2] = ((addr >> 4) & 7); | ||
digits[3] = (addr >> 12) + (addr & 8); | ||
digits[4] = (addr & 7) + ((addr >> 8) & 8); | ||
digits[5] = ((addr >> 8) & 7); | ||
|
||
if (key === undefined) { | ||
digits[5] += value & 8; | ||
if (wantskey) digits[2] += 8; | ||
} else { | ||
digits[2] += 8; | ||
digits[5] += key & 8; | ||
digits[6] = (key & 7) + ((key >> 4) & 8); | ||
digits[7] = ((key >> 4) & 7) + (value & 8); | ||
} | ||
|
||
var code = digits.map(toLetter).join(''); | ||
|
||
return code; | ||
}, | ||
}; | ||
|
||
module.exports = GG; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ var CPU = require("./cpu"); | |
var Controller = require("./controller"); | ||
var PPU = require("./ppu"); | ||
var PAPU = require("./papu"); | ||
var GG = require("./gg"); | ||
var ROM = require("./rom"); | ||
|
||
var NES = function(opts) { | ||
|
@@ -34,6 +35,7 @@ var NES = function(opts) { | |
this.cpu = new CPU(this); | ||
this.ppu = new PPU(this); | ||
this.papu = new PAPU(this); | ||
this.gg = new GG(this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, can be |
||
this.mmap = null; // set in loadROM() | ||
this.controllers = { | ||
1: new Controller(), | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to abbreviate -
GameGenie
is much clearer.