vgm-conv
Version:
Chip-type and clock converter for VGM.
44 lines (43 loc) • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const vgm_parser_1 = require("vgm-parser");
class VGMWriteDataCommandBuffer {
_outRegs = [];
_buf = [];
constructor(maxRegs, maxPorts = 1) {
for (let i = 0; i < maxPorts; i++) {
this._outRegs.push(new Int16Array(maxRegs).fill(-1));
}
}
push(cmd, optimize = true) {
if (cmd instanceof vgm_parser_1.VGMWriteDataCommand && optimize) {
if (this._outRegs[cmd.port][cmd.addr] !== cmd.data) {
const index = this._buf.findIndex(e => {
if (e instanceof vgm_parser_1.VGMWriteDataCommand) {
return e.port === cmd.port && e.addr === cmd.addr;
}
return false;
});
if (0 <= index) {
this._buf.splice(index, 1);
}
this._buf.push(cmd);
}
}
else {
this._buf.push(cmd);
}
}
commit() {
const result = Array();
for (const cmd of this._buf) {
if (cmd instanceof vgm_parser_1.VGMWriteDataCommand) {
this._outRegs[cmd.port][cmd.addr] = cmd.data;
}
result.push(cmd);
}
this._buf = [];
return result;
}
}
exports.default = VGMWriteDataCommandBuffer;