80 lines
2.6 KiB
JavaScript
80 lines
2.6 KiB
JavaScript
// Generated by CoffeeScript 1.7.1
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
this.ImageTextModeIDF = (function(_super) {
|
|
__extends(ImageTextModeIDF, _super);
|
|
|
|
function ImageTextModeIDF(options) {
|
|
var k, v;
|
|
ImageTextModeIDF.__super__.constructor.apply(this, arguments);
|
|
this.header = {
|
|
x0: 0,
|
|
x1: 0,
|
|
y0: 0,
|
|
y1: 0
|
|
};
|
|
for (k in options) {
|
|
if (!__hasProp.call(options, k)) continue;
|
|
v = options[k];
|
|
this[k] = v;
|
|
}
|
|
}
|
|
|
|
ImageTextModeIDF.prototype.parse = function(content) {
|
|
var attr, buffer, ch, eodata, headerData, i, info, len, offset, x, y, _i;
|
|
headerData = content.substr(0, 12);
|
|
if (headerData.length !== 12 || !headerData.match('^\x041.4')) {
|
|
throw new Error('File is not an IDF');
|
|
}
|
|
this.header.x0 = this.unpackShort(headerData.substr(4, 2));
|
|
this.header.y0 = this.unpackShort(headerData.substr(6, 2));
|
|
this.header.x1 = this.unpackShort(headerData.substr(8, 2));
|
|
this.header.y1 = this.unpackShort(headerData.substr(10, 2));
|
|
eodata = content.length - 48 - 4096;
|
|
if (content.substr(content.length - 128, 5) === 'SAUCE') {
|
|
eodata -= 128;
|
|
}
|
|
this.parseFontData(content.substr(eodata, 4096));
|
|
this.parsePaletteData(content.substr(eodata + 4096, 48));
|
|
y = 0;
|
|
x = 0;
|
|
this.screen[y] = [];
|
|
offset = 12;
|
|
while (offset < eodata) {
|
|
buffer = content.substr(offset, 2);
|
|
info = this.unpackShort(buffer);
|
|
offset += 2;
|
|
len = 1;
|
|
if (info === 1) {
|
|
len = this.unpackShort(content.substr(offset, 2)) & 255;
|
|
offset += 2;
|
|
buffer = content.substr(offset, 2);
|
|
offset += 2;
|
|
}
|
|
ch = buffer.substr(0, 1);
|
|
attr = this.getByteAt(buffer, 1);
|
|
for (i = _i = 1; 1 <= len ? _i <= len : _i >= len; i = 1 <= len ? ++_i : --_i) {
|
|
this.screen[y][x] = {
|
|
'ch': ch,
|
|
'attr': attr
|
|
};
|
|
x++;
|
|
if (x > this.header.x1) {
|
|
x = 0;
|
|
y++;
|
|
this.screen[y] = [];
|
|
}
|
|
}
|
|
}
|
|
if (this.screen[y].length === 0) {
|
|
return this.screen.pop();
|
|
}
|
|
};
|
|
|
|
return ImageTextModeIDF;
|
|
|
|
})(this.ImageTextMode);
|
|
|
|
}).call(this);
|