gb-opcodes
Advanced tools
Comparing version 4.0.0 to 5.0.0
@@ -5,7 +5,9 @@ #! /usr/bin/env node | ||
const fs = require('fs'); | ||
const fetch = require('node-fetch'); | ||
const request = require('request'); | ||
const cheerio = require('cheerio'); | ||
const stream = require('JSONStream').stringify(); | ||
const URL = 'http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html'; | ||
const parseContent = (i, elem) => { | ||
@@ -15,23 +17,13 @@ | ||
const inst = { opcode: `0x${(i).toString(16)}` }; | ||
const l1 = elem.get(0).data.split(' '); | ||
const l2 = elem.get(1).data.match(/^(\w+)\s*([0-9\/]+)$/) || []; | ||
inst.mnemonic = l1[0]; | ||
if (l1.length > 1) { | ||
inst.operands = l1[1].split(','); | ||
} | ||
if (l2.length > 1) { | ||
inst.bytes = parseInt(l2[1], 10); | ||
// Note: | ||
// For opcodes with conditional duration (e.g. CALL C,a16 3 12/24) will | ||
// use the first value. | ||
inst.cycles = parseInt(l2[2], 10); | ||
} | ||
inst.flagsZNHC = elem.get(2).data.split(' '); | ||
return inst; | ||
return { | ||
opcode: `0x${(i).toString(16)}`, | ||
mnemonic: l1[0], | ||
operands: l1.length > 1 ? l1[1].split(',') : [], | ||
bytes: parseInt(l2[1], 10), | ||
cycles: l2[2].split('/').reduce((p, c) => Math.max(p, c), 0), | ||
flagsZNHC: elem.get(2).data.split(' ') | ||
}; | ||
}; | ||
@@ -43,24 +35,21 @@ | ||
.map((i, elem) => $('td:nth-of-type(n+2)', elem).get()) | ||
.map((i, elem) => $(elem).contents()) | ||
.map((i, elem) => $(elem).filter((i, elem) => elem.type == 'text')) | ||
.map((i, elem) => parseContent(index ? i + 0xcb00 : i, elem)) | ||
.map((i, elem) => { | ||
const textNodes = $(elem) | ||
.contents() | ||
.filter((i, elem) => elem.type == 'text'); | ||
return parseContent(index ? i + 0xcb00 : i, textNodes); | ||
}) | ||
.each((i, elem) => stream.write(elem)); | ||
}; | ||
// References: | ||
// - http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html | ||
// - https://github.com/NewbiZ/gbemu/tree/master/scripts | ||
request(URL, (err, response) => { | ||
fetch('http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html') | ||
.then((res) => res.text()) | ||
.then((body) => { | ||
const $ = cheerio.load(body); | ||
$('table').splice(0, 2).forEach((v, i) => parseTable($, v, i)); | ||
}) | ||
.then(() => stream.end()) | ||
.catch((err) => { | ||
console.error(err.message); | ||
process.exit(1); | ||
}); | ||
if (err) throw err; | ||
const $ = cheerio.load(response.body); | ||
$('table').splice(0, 2).forEach((v, i) => parseTable($, v, i)); | ||
stream.end(); | ||
}); | ||
stream.pipe(process.stdout); |
[ | ||
{"opcode":"0x0","mnemonic":"NOP","bytes":1,"cycles":4,"flagsZNHC":["-","-","-","-"]} | ||
{"opcode":"0x0","mnemonic":"NOP","operands":[],"bytes":1,"cycles":4,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
@@ -16,3 +16,3 @@ {"opcode":"0x1","mnemonic":"LD","operands":["BC","d16"],"bytes":3,"cycles":12,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
{"opcode":"0x7","mnemonic":"RLCA","bytes":1,"cycles":4,"flagsZNHC":["0","0","0","C"]} | ||
{"opcode":"0x7","mnemonic":"RLCA","operands":[],"bytes":1,"cycles":4,"flagsZNHC":["0","0","0","C"]} | ||
, | ||
@@ -33,3 +33,3 @@ {"opcode":"0x8","mnemonic":"LD","operands":["(a16)","SP"],"bytes":3,"cycles":20,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
{"opcode":"0xf","mnemonic":"RRCA","bytes":1,"cycles":4,"flagsZNHC":["0","0","0","C"]} | ||
{"opcode":"0xf","mnemonic":"RRCA","operands":[],"bytes":1,"cycles":4,"flagsZNHC":["0","0","0","C"]} | ||
, | ||
@@ -50,3 +50,3 @@ {"opcode":"0x10","mnemonic":"STOP","operands":["0"],"bytes":2,"cycles":4,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
{"opcode":"0x17","mnemonic":"RLA","bytes":1,"cycles":4,"flagsZNHC":["0","0","0","C"]} | ||
{"opcode":"0x17","mnemonic":"RLA","operands":[],"bytes":1,"cycles":4,"flagsZNHC":["0","0","0","C"]} | ||
, | ||
@@ -67,3 +67,3 @@ {"opcode":"0x18","mnemonic":"JR","operands":["r8"],"bytes":2,"cycles":12,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
{"opcode":"0x1f","mnemonic":"RRA","bytes":1,"cycles":4,"flagsZNHC":["0","0","0","C"]} | ||
{"opcode":"0x1f","mnemonic":"RRA","operands":[],"bytes":1,"cycles":4,"flagsZNHC":["0","0","0","C"]} | ||
, | ||
@@ -84,3 +84,3 @@ {"opcode":"0x20","mnemonic":"JR","operands":["NZ","r8"],"bytes":2,"cycles":12,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
{"opcode":"0x27","mnemonic":"DAA","bytes":1,"cycles":4,"flagsZNHC":["Z","-","0","C"]} | ||
{"opcode":"0x27","mnemonic":"DAA","operands":[],"bytes":1,"cycles":4,"flagsZNHC":["Z","-","0","C"]} | ||
, | ||
@@ -101,3 +101,3 @@ {"opcode":"0x28","mnemonic":"JR","operands":["Z","r8"],"bytes":2,"cycles":12,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
{"opcode":"0x2f","mnemonic":"CPL","bytes":1,"cycles":4,"flagsZNHC":["-","1","1","-"]} | ||
{"opcode":"0x2f","mnemonic":"CPL","operands":[],"bytes":1,"cycles":4,"flagsZNHC":["-","1","1","-"]} | ||
, | ||
@@ -118,3 +118,3 @@ {"opcode":"0x30","mnemonic":"JR","operands":["NC","r8"],"bytes":2,"cycles":12,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
{"opcode":"0x37","mnemonic":"SCF","bytes":1,"cycles":4,"flagsZNHC":["-","0","0","1"]} | ||
{"opcode":"0x37","mnemonic":"SCF","operands":[],"bytes":1,"cycles":4,"flagsZNHC":["-","0","0","1"]} | ||
, | ||
@@ -135,3 +135,3 @@ {"opcode":"0x38","mnemonic":"JR","operands":["C","r8"],"bytes":2,"cycles":12,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
{"opcode":"0x3f","mnemonic":"CCF","bytes":1,"cycles":4,"flagsZNHC":["-","0","0","C"]} | ||
{"opcode":"0x3f","mnemonic":"CCF","operands":[],"bytes":1,"cycles":4,"flagsZNHC":["-","0","0","C"]} | ||
, | ||
@@ -246,3 +246,3 @@ {"opcode":"0x40","mnemonic":"LD","operands":["B","B"],"bytes":1,"cycles":4,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
{"opcode":"0x76","mnemonic":"HALT","bytes":1,"cycles":4,"flagsZNHC":["-","-","-","-"]} | ||
{"opcode":"0x76","mnemonic":"HALT","operands":[],"bytes":1,"cycles":4,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
@@ -413,3 +413,3 @@ {"opcode":"0x77","mnemonic":"LD","operands":["(HL)","A"],"bytes":1,"cycles":8,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
{"opcode":"0xc9","mnemonic":"RET","bytes":1,"cycles":16,"flagsZNHC":["-","-","-","-"]} | ||
{"opcode":"0xc9","mnemonic":"RET","operands":[],"bytes":1,"cycles":16,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
@@ -444,3 +444,3 @@ {"opcode":"0xca","mnemonic":"JP","operands":["Z","a16"],"bytes":3,"cycles":16,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
{"opcode":"0xd9","mnemonic":"RETI","bytes":1,"cycles":16,"flagsZNHC":["-","-","-","-"]} | ||
{"opcode":"0xd9","mnemonic":"RETI","operands":[],"bytes":1,"cycles":16,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
@@ -483,3 +483,3 @@ {"opcode":"0xda","mnemonic":"JP","operands":["C","a16"],"bytes":3,"cycles":16,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
{"opcode":"0xf3","mnemonic":"DI","bytes":1,"cycles":4,"flagsZNHC":["-","-","-","-"]} | ||
{"opcode":"0xf3","mnemonic":"DI","operands":[],"bytes":1,"cycles":4,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
@@ -498,3 +498,3 @@ {"opcode":"0xf5","mnemonic":"PUSH","operands":["AF"],"bytes":1,"cycles":16,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
{"opcode":"0xfb","mnemonic":"EI","bytes":1,"cycles":4,"flagsZNHC":["-","-","-","-"]} | ||
{"opcode":"0xfb","mnemonic":"EI","operands":[],"bytes":1,"cycles":4,"flagsZNHC":["-","-","-","-"]} | ||
, | ||
@@ -501,0 +501,0 @@ {"opcode":"0xfe","mnemonic":"CP","operands":["d8"],"bytes":2,"cycles":8,"flagsZNHC":["Z","1","H","C"]} |
{ | ||
"name": "gb-opcodes", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "generate gameboy opcodes table in JSON format", | ||
@@ -14,3 +14,3 @@ "engines": { | ||
"node-fetch": "^1.5.1", | ||
"request": "2.x.x" | ||
"request": "^2.72.0" | ||
}, | ||
@@ -17,0 +17,0 @@ "devDependencies": {}, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
0
59422
1041
Updatedrequest@^2.72.0