Skip to content
Snippets Groups Projects
Commit 3f90bfc1 authored by echicken's avatar echicken
Browse files

Fixed busted screen pause in throttled display for non-cterms.

Don't delete non-property 'image' variable; set it to undefined instead.
Removed some convoluted and extraneous things I did years ago.
Various non-functional formatting things since I'm bored.
parent a97d4a7f
No related branches found
No related tags found
No related merge requests found
......@@ -10,16 +10,14 @@ var Graphic = load({}, "graphic.js");
var xbin = load({}, "xbin_lib.js");
var cterm = load({}, "cterm_lib.js");
Frame.prototype.drawBorder = function(color) {
Frame.prototype.drawBorder = function (color) {
var msg;
var theColor = color;
if (Array.isArray(color)) {
var sectionLength = Math.round(this.width / color.length);
}
const sectionLength = Array.isArray(color) ? Math.round(this.width / color.length) : 0;
this.pushxy();
for (var y = 1; y <= this.height; y++) {
for (var x = 1; x <= this.width; x++) {
if (x > 1 && x < this.width && y > 1 && y < this.height) continue;
var msg;
this.gotoxy(x, y);
if (y == 1 && x == 1) {
msg = ascii(218);
......@@ -34,7 +32,7 @@ Frame.prototype.drawBorder = function(color) {
} else {
msg = ascii(196);
}
if (Array.isArray(color)) {
if (sectionLength) {
if (x == 1) {
theColor = color[0];
} else if (x % sectionLength == 0 && x < this.width) {
......@@ -49,8 +47,7 @@ Frame.prototype.drawBorder = function(color) {
this.popxy();
}
var root = js.exec_dir,
settings,
var settings,
frame,
browserFrame,
statusBarFrame,
......@@ -58,7 +55,7 @@ var root = js.exec_dir,
speedFrame,
pauseFrame;
var state = {
const state = {
status : bbs.sys_status,
attr : console.attributes,
syncTerm : false,
......@@ -69,7 +66,7 @@ var state = {
browser : null
};
var speedMap = [
const speedMap = [
0, // 0 (unlimited)
300, // 1
600, // 2
......@@ -84,10 +81,9 @@ var speedMap = [
115200 // 11
];
function draw(file, cols, rows)
{
if ((typeof rows == 'undefined' || typeof cols == 'undefined') ||
(rows > console.screen_rows && cols <= console.screen_columns)
function draw(file, cols, rows) {
if ((typeof rows == 'undefined' || typeof cols == 'undefined')
|| (rows > console.screen_rows && cols <= console.screen_columns)
) {
return console.printfile(file, (state.pausing ? P_NONE : P_NOPAUSE) |P_CPM_EOF);
}
......@@ -95,13 +91,10 @@ function draw(file, cols, rows)
// Use graphic when the entire image fits on the screen
var graphic = new Graphic(cols, rows);
try {
if (!graphic.load(file))
if (!graphic.load(file)) {
alert("Graphic.load failure: " + file);
else {
if (state.drawfx) // Check this shit out
graphic.drawfx();
else
graphic.draw();
} else {
state.drawfx ? graphic.drawfx() : graphic.draw();
}
} catch(e) {
// alert(e);
......@@ -111,26 +104,25 @@ function draw(file, cols, rows)
function drawFile(file) {
var sauce = Sauce.read(file);
var ext = (file_getext(file) || '').toLowerCase();
var is_xbin = (ext == ".xb" || ext == ".xbin");
const sauce = Sauce.read(file);
const ext = (file_getext(file) || '').toLowerCase();
const is_xbin = (ext == ".xb" || ext == ".xbin");
if (ext == ".bin" || is_xbin) {
if (!state.syncTerm)
if (!state.syncTerm) {
return "Sorry, this file format is not supported by your terminal";
if (!is_xbin && (!sauce || sauce.datatype != Sauce.defs.datatype.bin)) {
}
if (!is_xbin && (!sauce || sauce.datatype != Sauce.defs.datatype.bin)) {
return "Sorry, this file has a missing or invalid SAUCE record";
}
var f = new File(file);
if (!f.open("rb"))
return "Failed to open: " + f.name;
if (!f.open("rb")) return "Failed to open: " + f.name;
var image = {};
if (!is_xbin) {
image.width = sauce.cols;
image.height = sauce.rows;
image.flags = 0;
if (sauce.ice_color)
image.flags |= xbin.FLAG_NONBLINK;
if (sauce.ice_color) image.flags |= xbin.FLAG_NONBLINK;
image.bin = f.read(image.width * image.height * 2);
} else { /* XBin */
image = xbin.read(f);
......@@ -138,15 +130,17 @@ function drawFile(file) {
f.close();
var warning = '';
if (image.font) {
if (cterm.supports_fonts() == false)
if (!cterm.supports_fonts()) {
warning += "Warning: your terminal does not support loadable fonts; font not used.\r\n";
else if (image.font.length && image.charheight != cterm.charheight(console.screen_rows))
warning += format("Warning: file intended for a different char height (%u); font not used.\r\n"
,image.charheight);
} else if (image.font.length && image.charheight != cterm.charheight(console.screen_rows)) {
warning += format(
"Warning: file intended for a different char height (%u); font not used.\r\n",
image.charheight
);
}
}
if (image.palette) {
if (cterm.supports_palettes() == false)
warning += "Warning: your terminal does not support loadable palettes; palette not used.\r\n";
if (image.palette && !cterm.supports_palettes()) {
warning += "Warning: your terminal does not support loadable palettes; palette not used.\r\n";
}
if (warning.length) {
alert(warning);
......@@ -154,50 +148,37 @@ function drawFile(file) {
}
cterm.xbin_draw(image);
cterm.xbin_cleanup(image);
delete image;
}
else if (state.syncTerm) {
image = undefined;
} else if (state.syncTerm) {
Ansi.send("speed", "set", state.speed);
Ansi.send("ext_mode", "clear", "cursor");
if (sauce.ice_color)
Ansi.send("ext_mode", "set", "bg_bright_intensity");
if (sauce.ice_color) Ansi.send("ext_mode", "set", "bg_bright_intensity");
mswait(500);
draw(file, sauce.cols, sauce.rows);
console.getkey();
Ansi.send("ext_mode", "clear", "bg_bright_intensity");
Ansi.send("ext_mode", "set", "cursor");
Ansi.send("speed", "clear");
} else if (state.speed == 0) {
draw(file, sauce.cols, sauce.rows);
console.getkey();
} else { // TODO: terminate on Ctrl-Z char (CPM EOF) in the file
var f = new File(file);
if (!f.open("r"))
return "Failed to open file: " + file.name;
var contents = f.read().split("");
if (!f.open("r")) return "Failed to open file: " + file.name;
const contents = f.read().split("");
f.close();
var buf = Math.ceil((speedMap[state.speed] / 8) / 1000);
const buf = Math.ceil((speedMap[state.speed] / 8) / 1000);
if (!state.pausing) {
bbs.sys_status&=(~SS_PAUSEON);
bbs.sys_status|=SS_PAUSEOFF;
}
while (contents.length > 0) {
console.write(contents.splice(0, buf).join(""));
console.print(contents.splice(0, buf).join(""));
if (console.inkey(K_NONE, 1) != "") break;
}
console.getkey();
bbs.sys_status|=SS_PAUSEON;
bbs.sys_status&=(~SS_PAUSEOFF);
}
return true;
}
......@@ -205,7 +186,7 @@ function drawFile(file) {
function printFile(file) {
console.clear(BG_BLACK|LIGHTGRAY);
frame.invalidate();
var result = drawFile(file);
const result = drawFile(file);
console.clear(BG_BLACK|LIGHTGRAY);
if (result !== true) {
alert(result);
......@@ -216,53 +197,43 @@ function printFile(file) {
// Basic check for SyncTERM; we don't really care which version it is
function isSyncTerm() {
console.clear(BG_BLACK|LIGHTGRAY);
console.write("Checking for SyncTERM ...");
var ret = true,
cTerm = "\x1B[=67;84;101;114;109;".split(""),
ckpt = console.ctrlkey_passthru;
var ret = true;
const cTerm = "\x1B[=67;84;101;114;109;".split("");
const ckpt = console.ctrlkey_passthru;
console.ctrlkey_passthru = -1;
console.write("\x1B[0c");
while (cTerm.length > 0) {
if (console.inkey(K_NONE, 5000) == cTerm.shift()) continue;
ret = false;
break;
}
do {} while (console.inkey(K_NONE) != "") // Flush the input toilet
console.clearkeybuffer();
console.ctrlkey_passthru = ckpt;
return ret;
}
function showSpeed() {
speedFrame.clear();
speedFrame.putmsg(
(state.speed == 0) ? "Full" : speedMap[state.speed]
);
speedFrame.putmsg(state.speed == 0 ? "Full" : speedMap[state.speed]);
}
function showPause() {
pauseFrame.clear();
pauseFrame.putmsg((state.pausing) ? "On" : "Off");
pauseFrame.putmsg(state.pausing ? "On" : "Off");
}
var GalleryChooser = function() {
function GalleryChooser() {
var frames = {
frame : null,
tree : null,
scrollBar : null
};
var frame;
var tree;
var scrollBar;
function getList() {
var f = new File(root + "settings.ini");
const f = new File(js.exec_dir + "settings.ini");
f.open("r");
var galleries = f.iniGetAllObjects();
const galleries = f.iniGetAllObjects();
f.close();
return galleries;
}
......@@ -272,7 +243,7 @@ var GalleryChooser = function() {
areaFrame.clear();
areaFrame.putmsg(settings.top_level);
frames.frame = new Frame(
frame = new Frame(
browserFrame.x,
browserFrame.y,
browserFrame.width,
......@@ -280,48 +251,42 @@ var GalleryChooser = function() {
browserFrame.attr,
browserFrame
);
frames.tree = new Tree(frames.frame);
frames.tree.colors.fg = getColor(settings.fg);
frames.tree.colors.bg = getColor(settings.bg);
frames.tree.colors.lfg = getColor(settings.lfg);
frames.tree.colors.lbg = getColor(settings.lbg);
var list = getList();
list.forEach(
function (item) {
item.colors = settings;
frames.tree.addItem(
format("%-32s %s", item.name, item.description),
function () {
state.browser.close();
state.browser = load(root + item.module, JSON.stringify(item));
state.browser.open();
areaFrame.clear();
areaFrame.putmsg(item.name);
}
);
}
);
tree = new Tree(frame);
tree.colors.fg = getColor(settings.fg);
tree.colors.bg = getColor(settings.bg);
tree.colors.lfg = getColor(settings.lfg);
tree.colors.lbg = getColor(settings.lbg);
getList().forEach(function (e) {
e.colors = settings;
tree.addItem(format("%-32s %s", e.name, e.description), function () {
state.browser.close();
state.browser = load(js.exec_dir + e.module, JSON.stringify(e));
state.browser.open();
areaFrame.clear();
areaFrame.putmsg(e.name);
});
});
frames.scrollBar = new ScrollBar(frames.tree);
scrollBar = new ScrollBar(tree);
frames.frame.open();
frames.tree.open();
frame.open();
tree.open();
}
this.close = function () {
frames.tree.close();
frames.scrollBar.close();
frames.frame.close();
tree.close();
scrollBar.close();
frame.close();
}
this.cycle = function () {
frames.scrollBar.cycle();
scrollBar.cycle();
}
this.getcmd = function (cmd) {
frames.tree.getcmd(cmd);
tree.getcmd(cmd);
}
}
......@@ -330,84 +295,36 @@ function initDisplay() {
console.clear(BG_BLACK|LIGHTGRAY);
frame = new Frame(
1,
1,
console.screen_columns,
console.screen_rows,
BG_BLACK|LIGHTGRAY
);
frame = new Frame(1, 1, console.screen_columns, console.screen_rows, BG_BLACK|LIGHTGRAY);
if (settings.header && settings.header_rows) {
frame.height -= settings.header_rows;
frame.y += settings.header_rows;
var headerFrame = new Frame(
1, 1, frame.width, settings.header_rows, BG_BLACK|LIGHTGRAY, frame
);
const headerFrame = new Frame(1, 1, frame.width, settings.header_rows, BG_BLACK|LIGHTGRAY, frame);
}
browserFrame = new Frame(
frame.x + 1,
frame.y + 1,
frame.width - 2,
frame.height - 3,
frame.attr,
frame
);
statusBarFrame = new Frame(
frame.x + 1,
frame.y + frame.height - 2,
frame.width - 2,
1,
settings.sbg|settings.sfg,
frame
);
statusBarFrame.putmsg(
format("%-41s%-16s%-13s", "Area:","S)peed:","P)ause:")
);
browserFrame = new Frame(frame.x + 1, frame.y + 1, frame.width - 2, frame.height - 3, frame.attr, frame);
statusBarFrame = new Frame(frame.x + 1, frame.y + frame.height - 2, frame.width - 2, 1, settings.sbg|settings.sfg, frame);
statusBarFrame.putmsg(format("%-41s%-16s%-13s", "Area:","S)peed:","P)ause:"));
statusBarFrame.gotoxy(statusBarFrame.width - 4, 1);
statusBarFrame.putmsg("Q)uit");
areaFrame = new Frame(
statusBarFrame.x + 6,
statusBarFrame.y,
35,
1,
statusBarFrame.attr,
statusBarFrame
);
speedFrame = new Frame(
statusBarFrame.x + 49,
statusBarFrame.y,
6,
1,
statusBarFrame.attr,
statusBarFrame
);
showSpeed();
pauseFrame = new Frame(
statusBarFrame.x + 65,
statusBarFrame.y,
3,
1,
statusBarFrame.attr,
statusBarFrame
);
areaFrame = new Frame(statusBarFrame.x + 6, statusBarFrame.y, 35, 1, statusBarFrame.attr, statusBarFrame);
speedFrame = new Frame(statusBarFrame.x + 49, statusBarFrame.y, 6, 1, statusBarFrame.attr, statusBarFrame);
pauseFrame = new Frame(statusBarFrame.x + 65, statusBarFrame.y, 3, 1, statusBarFrame.attr, statusBarFrame);
showSpeed();
showPause();
frame.open();
if (typeof headerFrame != 'undefined') headerFrame.load(settings.header);
frame.drawBorder(settings.border);
frame.gotoxy(frame.width - 24, 1);
frame.putmsg(ascii(180) + "\1h\1kansiview\1h\1w" + ascii(195));
if (headerFrame) headerFrame.load(settings.header);
}
function initSettings() {
var f = new File(js.exec_dir + "settings.ini");
const f = new File(js.exec_dir + "settings.ini");
f.open("r");
settings = f.iniGetObject();
f.close();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment