This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
vbbs/app/Classes/Server/Videotex.php

88 lines
2.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Classes\Server;
use Illuminate\Support\Facades\Log;
use App\Classes\Server as AbstractServer;
use App\Models\Mode;
class Videotex extends AbstractServer {
public function __construct(Mode $o)
{
define('ESC', chr(27));
define('CON', chr(17)); // Cursor On
define('COFF', chr(20)); // Cursor Off
define('HOME', chr(30));
define('LEFT', chr(8)); // Move Cursor
define('RIGHT', chr(9)); // Move Cursor
define('DOWN', chr(10)); // Move Cursor
define('UP', chr(11)); // Move Cursor
define('CR', chr(13));
define('LF', chr(10));
define('CLS', chr(12));
define('HASH', '_'); // Enter
define('STAR', '*'); // Star Entry
define('SPACE', ''); // Space
// NOTE: This consts are effective output
define('RED', ESC.'A');
define('GREEN', ESC.'B');
define('YELLOW', ESC.'C');
define('BLUE', ESC.'D');
define('MAGENTA', ESC.'E');
define('CYAN', ESC.'F');
define('WHITE', ESC.'G');
define('NEWBG', ESC.']');
// Raw attributes - used when storing frames.
define('R_RED', chr(1));
define('R_GREEN', chr(2));
define('R_YELLOW', chr(3));
define('R_BLUE', chr(4));
define('R_MAGENTA', chr(5));
define('R_CYAN', chr(6));
define('R_WHITE', chr(7));
define('FLASH', chr(8));
parent::__construct($o);
}
public function outputPosition($x,$y) {
// Take the shortest path.
if ($y < 12) {
return HOME.
(($x < 21)
? str_repeat(DOWN,$y).str_repeat(RIGHT,$x)
: str_repeat(DOWN,$y+1).str_repeat(LEFT,40-$x));
} else {
return HOME.str_repeat(UP,24-$y).
(($x < 21)
? str_repeat(RIGHT,$x)
: str_repeat(LEFT,40-$x));
}
}
public function sendBaseline($client,$text,$reposition=FALSE) {
$client->send(HOME.UP.$text.
($this->blp > $this->strlenv($text)
? str_repeat(' ',$this->blp-$this->strlenv($text)).
($reposition ? HOME.UP.str_repeat(RIGHT,$this->strlenv($text)) : '')
: '')
);
$this->blp = $this->strlenv($text);
}
// Abstract function
public function strlenv($text):int {
return strlen($text)-substr_count($text,ESC);
}
// Abstract function
public function testFrame()
{
return \App\Classes\Frame\Videotex::testFrame($this);
}
}