update vt05 terminal. since linefeed is only effective on the last line, it's not really usable.

git-svn-id: svn://qnap.local/TwoTerm/trunk@3174 5590a31f-7b70-45f8-8c82-aa3a8e5f4507
This commit is contained in:
Kelvin Sherlock 2017-02-21 03:20:53 +00:00
parent a34341dd69
commit 102e7a824a
2 changed files with 68 additions and 49 deletions

View File

@ -11,14 +11,12 @@
#include "iGeometry.h" #include "iGeometry.h"
class OutputChannel; #include "Screen.h"
class Screen;
@interface VT05 : NSObject <Emulator> { @interface VT05 : NSObject <Emulator> {
unsigned _state; unsigned _state;
struct iPoint _dca; context _context;
BOOL _upperCase; BOOL _upperCase;
} }

View File

@ -6,6 +6,10 @@
// Copyright 2010 __MyCompanyName__. All rights reserved. // Copyright 2010 __MyCompanyName__. All rights reserved.
// //
/*
* http://vt100.net/docs/vt05-rm/contents.html
*/
#include <sys/ttydefaults.h> #include <sys/ttydefaults.h>
#include <cctype> #include <cctype>
@ -63,6 +67,17 @@ enum {
-(void)reset -(void)reset
{ {
_state = StateText; _state = StateText;
_context.cursor = iPoint(0,0);
_context.window = iRect(0, 0, 72, 20);
_upperCase = YES;
}
-(id)init {
if ((self = [super init])) {
[self reset];
}
return self;
} }
-(void)keyDown: (NSEvent *)event screen: (Screen *)screen output: (OutputChannel *)output -(void)keyDown: (NSEvent *)event screen: (Screen *)screen output: (OutputChannel *)output
@ -135,26 +150,29 @@ enum {
case VTCursorLeft: case VTCursorLeft:
// backspace aka left arrow. // backspace aka left arrow.
screen->decrementX(); if (_context.cursor.x) _context.cursor.x--;
break; break;
case VTTab: case VTTab:
[self tab: screen]; if (_context.cursor.x < 64) _context.cursor.x = (_context.cursor.x + 8) & ~7;
else if (_context.cursor.x < _context.window.maxX() -1) _context.cursor.x++;
break; break;
case VTLineFeed: case VTLineFeed:
// line feed. // line feed.
screen->lineFeed(); // only if in line 20.
if (_context.cursor.y == _context.window.maxY() -1)
screen->scrollUp();
break; break;
case VTCursorDown: case VTCursorDown:
// arrow down. // arrow down.
screen->incrementY(); if (_context.cursor.y < _context.window.maxY() -1) _context.cursor.y++;
break; break;
case VTCarriageReturn: case VTCarriageReturn:
// carriage return; // carriage return;
screen->setX(0); _context.cursor.x = 0;
break; break;
case VTCAD: case VTCAD:
@ -164,96 +182,99 @@ enum {
case VTCursorRight: case VTCursorRight:
// right arrow. // right arrow.
screen->incrementX(); if (_context.cursor.x < _context.window.maxX() -1) _context.cursor.x++;
break; break;
case VTCursorUp: case VTCursorUp:
// up arrow // up arrow
screen->decrementY(); if (_context.cursor.y) _context.cursor.y--;
break; break;
case VTHome: case VTHome:
// home // home
screen->setCursor(0, 0); _context.cursor = iPoint(0,0);
break; break;
case VTEOL: case VTEOL: {
// erase line (EOL) // erase line (EOL)
// erase all data from the current cursor position // erase all data from the current cursor position
// (including data in the cursor position) // (including data in the cursor position)
// to end of the line. // to end of the line.
screen->erase(Screen::EraseLineAfterCursor);
break; iRect tmp;
tmp.origin = _context.cursor;
tmp.size = iSize(_context.window.size.width - _context.cursor.x, 1);
case VTEOS: screen->eraseRect(tmp);
break;
}
case VTEOS: {
// erase screen (EOS) // erase screen (EOS)
// erase all data on the crt screen from the current // erase all data on the crt screen from the current
// cursor position (including data in the cursor position) // cursor position (including data in the cursor position)
// to line 20, character position 72. // to line 20, character position 72.
// //
screen->erase(Screen::EraseAfterCursor);
iRect tmp;
tmp.origin = _context.cursor;
tmp.size = iSize(_context.window.size.width - _context.cursor.x, 1);
screen->eraseRect(tmp);
tmp = _context.window;
tmp.origin.y = _context.cursor.y+1;
tmp.size.height -= _context.cursor.y+1;
screen->eraseRect(tmp);
break; break;
}
default: default:
if (c >= ' ' && c < 0x7f) if (c >= ' ' && c < 0x7f)
{ {
// if cursor at end of screen, overwrite previous contents, doesn't advance cursor. // if cursor at end of screen, overwrite previous contents, doesn't advance cursor.
if (_upperCase) c = toupper(c); if (_upperCase) {
screen->putc(c); // uppercase algorithm (from vt50)
if (c & 0x40) c &= ~0x20;
}
screen->putc(c, _context);
if (_context.cursor.x < _context.window.maxX() -1) _context.cursor.x++;
} }
break; break;
} }
break; break;
} }
// based on the padding requirement -after- Y component of DCA, I assume
// the cursor is updated immediately.
case StateDCAY: case StateDCAY:
{ {
// not sure how invalid values are handled.
if (c != 0x00) if (c != 0x00)
{ {
c -= 32;
if (c >= 0 || c <= _context.window.maxY()-1) _context.cursor.y = c;
_state = StateDCAX; _state = StateDCAX;
_dca.y = c - ' ';
} }
break; break;
} }
case StateDCAX: case StateDCAX:
{ {
if (c != 0x00) if (c != 0x00) {
{ c -= 32;
if (c >= 0 || c <= _context.window.maxX()-1) _context.cursor.x = c;
_state = StateText; _state = StateText;
_dca.x = c - ' ';
screen->setCursor(_dca);
} }
break; break;
} }
} }
screen->setCursor(_context.cursor);
} }
-(void)tab: (Screen *)screen
{
/*
* TAB (011_8) causes the cursor to move right to the next TAB stop each time the TAB code is received.
* TAB stops are preset eight character spaces apart. TAB stop locations are at characters positions 1, 9,
* 17, 25, 33, 41, 49, 57, and 65. Once the cursor reaches character position 65, all TAB commands
* received thereafter will cause the cursor to move only one character position. Once the cursor reaches
* character position 72, receipt of the the TAB code has no effect.
*/
int x = screen->x();
if (x >= screen->width() - 8)
{
screen->setX(x + 1);
}
else
{
screen->setX((x + 8) & ~7);
}
}
-(BOOL)resizable -(BOOL)resizable
{ {