2010-07-09 23:52:30 +00:00
|
|
|
|
//
|
|
|
|
|
// PTSE.mm
|
|
|
|
|
// 2Term
|
|
|
|
|
//
|
|
|
|
|
// Created by Kelvin Sherlock on 7/9/2010.
|
|
|
|
|
// Copyright 2010 __MyCompanyName__. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include <sys/ttydefaults.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#import "PTSE.h"
|
|
|
|
|
|
|
|
|
|
#include "OutputChannel.h"
|
|
|
|
|
#include "Screen.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation PTSE
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
StateText,
|
|
|
|
|
|
|
|
|
|
StateDCAX,
|
|
|
|
|
StateDCAY,
|
|
|
|
|
|
|
|
|
|
StateRepeatChar,
|
|
|
|
|
StateRepeatCount,
|
|
|
|
|
|
|
|
|
|
StateTone1,
|
|
|
|
|
StateTone2,
|
|
|
|
|
StateToneDuration
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2010-10-06 00:39:09 +00:00
|
|
|
|
+(void)load
|
2010-07-09 23:52:30 +00:00
|
|
|
|
{
|
2010-10-06 00:39:09 +00:00
|
|
|
|
[EmulatorManager registerClass: self];
|
2010-07-09 23:52:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-10-05 18:56:45 +00:00
|
|
|
|
+(NSString *)name
|
|
|
|
|
{
|
|
|
|
|
return @"Proterm Special Emulation";
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-09 23:52:30 +00:00
|
|
|
|
-(NSString *)name
|
|
|
|
|
{
|
|
|
|
|
return @"Proterm Special Emulation";
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-06 00:39:09 +00:00
|
|
|
|
-(const char *)termName
|
|
|
|
|
{
|
|
|
|
|
return "proterm-special";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-07-09 23:52:30 +00:00
|
|
|
|
-(void)reset
|
|
|
|
|
{
|
|
|
|
|
_state = StateText;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-05 18:56:45 +00:00
|
|
|
|
-(BOOL)resizable
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(struct winsize)defaultSize
|
|
|
|
|
{
|
|
|
|
|
struct winsize ws = { 24, 80, 0, 0 };
|
|
|
|
|
|
|
|
|
|
return ws;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-01-11 00:29:59 +00:00
|
|
|
|
-(void)initTerm: (struct termios *)term
|
|
|
|
|
{
|
|
|
|
|
// Control-U is used by the up-arrow key.
|
|
|
|
|
term->c_cc[VKILL] = CTRL('X');
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-09 23:52:30 +00:00
|
|
|
|
-(void)processCharacter:(uint8_t)c screen:(Screen *)screen output:(OutputChannel *)output
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (_state == StateText)
|
|
|
|
|
{
|
|
|
|
|
switch (c)
|
|
|
|
|
{
|
|
|
|
|
case CTRL('N'):
|
|
|
|
|
//Set: inverse off, mousetext off.
|
|
|
|
|
screen->setFlag(Screen::FlagNormal);
|
|
|
|
|
break;
|
|
|
|
|
case CTRL('O'):
|
|
|
|
|
//Set: inverse on, mousetext off.
|
|
|
|
|
screen->setFlag(Screen::FlagInverse);
|
|
|
|
|
break;
|
|
|
|
|
case CTRL('P'):
|
|
|
|
|
//Set inverse off, mousetext on.
|
2011-02-03 02:39:06 +00:00
|
|
|
|
screen->setFlag(Screen::FlagMouseText | Screen::FlagInverse);
|
2010-07-09 23:52:30 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case CTRL('H'):
|
|
|
|
|
//Move cursor left one character.
|
|
|
|
|
screen->decrementX();
|
|
|
|
|
break;
|
|
|
|
|
case CTRL('U'):
|
|
|
|
|
//Move cursor right one character.
|
|
|
|
|
screen->incrementX();
|
|
|
|
|
break;
|
|
|
|
|
case CTRL('K'):
|
|
|
|
|
//Move cursor up one line.
|
|
|
|
|
screen->decrementY();
|
|
|
|
|
break;
|
|
|
|
|
case CTRL('J'):
|
|
|
|
|
//Move cursor down one line.
|
2010-12-20 23:37:02 +00:00
|
|
|
|
//screen->incrementY();
|
|
|
|
|
screen->lineFeed();
|
2010-07-09 23:52:30 +00:00
|
|
|
|
break;
|
|
|
|
|
case CTRL('I'):
|
|
|
|
|
//Move cursor to next tab stop (every 8 chars).
|
2010-12-20 23:37:02 +00:00
|
|
|
|
screen->tabTo((screen->x() + 8) & ~0x07);
|
2010-07-09 23:52:30 +00:00
|
|
|
|
break;
|
|
|
|
|
case CTRL('A'):
|
|
|
|
|
//Move cursor to beginning of line.
|
|
|
|
|
screen->setX(0);
|
|
|
|
|
break;
|
|
|
|
|
case CTRL('B'):
|
|
|
|
|
//Move cursor to end of line.
|
|
|
|
|
screen->setX(screen->width() - 1);
|
|
|
|
|
break;
|
|
|
|
|
case CTRL('X'):
|
|
|
|
|
//Move cursor to upper-left corner.
|
|
|
|
|
screen->setCursor(0, 0);
|
|
|
|
|
break;
|
|
|
|
|
case CTRL('^'):
|
|
|
|
|
// CONTROL-^, X + 32, Y + 32
|
|
|
|
|
//Position cursor to the X, Y coordinates.
|
|
|
|
|
_state = StateDCAX;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CTRL('M'):
|
2010-12-20 23:37:02 +00:00
|
|
|
|
//screen->lineFeed();
|
2010-07-09 23:52:30 +00:00
|
|
|
|
screen->setX(0);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case CTRL('D'):
|
|
|
|
|
//Delete current character (under cursor).
|
2010-12-18 17:40:58 +00:00
|
|
|
|
// TODO -- does this shift the rest of the row?
|
2010-12-20 23:37:02 +00:00
|
|
|
|
screen->deletec();
|
2010-07-09 23:52:30 +00:00
|
|
|
|
break;
|
|
|
|
|
case CTRL('F'):
|
|
|
|
|
//Insert space at cursor.
|
2010-12-20 23:37:02 +00:00
|
|
|
|
screen->insertc(' ');
|
2010-07-09 23:52:30 +00:00
|
|
|
|
break;
|
2010-12-20 23:37:02 +00:00
|
|
|
|
|
2010-07-09 23:52:30 +00:00
|
|
|
|
case CTRL('Z'):
|
|
|
|
|
//Delete current line.
|
2010-12-23 20:42:24 +00:00
|
|
|
|
screen->deleteLine(screen->y());
|
2010-07-09 23:52:30 +00:00
|
|
|
|
break;
|
|
|
|
|
case CTRL('V'):
|
|
|
|
|
//Insert blank like.
|
2010-12-20 23:37:02 +00:00
|
|
|
|
// TODO -- verify if the line is before or after the current line,
|
|
|
|
|
// TODO -- verify if x/y change
|
|
|
|
|
// TODO -- verify scrolling behavior.
|
2010-12-23 20:42:24 +00:00
|
|
|
|
screen->insertLine(screen->y());
|
2010-07-09 23:52:30 +00:00
|
|
|
|
break;
|
|
|
|
|
case CTRL('Y'):
|
|
|
|
|
//Clear to end of line.
|
|
|
|
|
screen->eraseLine();
|
|
|
|
|
break;
|
|
|
|
|
case CTRL('W'):
|
|
|
|
|
//Clear to end of screen.
|
|
|
|
|
screen->eraseScreen();
|
|
|
|
|
break;
|
|
|
|
|
case CTRL('L'):
|
|
|
|
|
//Clear the screen (and home cursor)
|
|
|
|
|
screen->setCursor(0, 0);
|
|
|
|
|
screen->eraseScreen();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case CTRL('E'):
|
|
|
|
|
//Inquire if using ProTERM Special Emulation
|
|
|
|
|
/*
|
|
|
|
|
* When you send out [CONTROL-E] to a caller using ProTERM
|
|
|
|
|
* Special, the caller’s ProTERM will send back [CONTROL-“]”]
|
|
|
|
|
* (ASCII code 29). This allows a BBS to transparently
|
|
|
|
|
* detect the use of PSE.
|
|
|
|
|
*/
|
|
|
|
|
output->write(29);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CTRL('R'):
|
|
|
|
|
//CONTROL-R, character, count
|
|
|
|
|
//Display character, count times.
|
|
|
|
|
/*
|
|
|
|
|
* This allows a three character code to be used to display
|
|
|
|
|
* multiple characters. For example, to display a window frame,
|
|
|
|
|
* it is necessary to show the top and bottom borders which are
|
|
|
|
|
* long lines of the same character (dashes, underlines, etc.).
|
|
|
|
|
* To draw a 64-character line consisting of equal signs, send
|
|
|
|
|
* [CONTROL-R = @] where “@” is the ASCII code for 64.
|
|
|
|
|
*/
|
|
|
|
|
_state = StateRepeatChar;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CTRL('G'):
|
|
|
|
|
//Sound the Bell.
|
|
|
|
|
NSBeep();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CTRL('T'):
|
|
|
|
|
//Sound single/dual-tone for duration.
|
|
|
|
|
/*
|
|
|
|
|
* The tone command has two forms. The first invokes the single-tone
|
|
|
|
|
* generator, which produces relatively pure tones. The second
|
|
|
|
|
* invokes the dual-tone generator, which produces some rather
|
|
|
|
|
* interesting sounds. The three parameters, tone1, tone2, and
|
|
|
|
|
* duration, can all take values from 1 through 127. There is
|
|
|
|
|
* currently no known translation between pitch/duration values
|
|
|
|
|
* and actual frequencies/times.
|
|
|
|
|
*/
|
|
|
|
|
//NB - parsed but ignored, for now.
|
|
|
|
|
_state = StateTone1;
|
|
|
|
|
break;
|
|
|
|
|
|
2010-12-18 17:40:58 +00:00
|
|
|
|
default:
|
|
|
|
|
if (c >= 0x20 && c < 0x7f)
|
|
|
|
|
{
|
|
|
|
|
screen->putc(c);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2010-07-09 23:52:30 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (_state)
|
|
|
|
|
{
|
|
|
|
|
case StateDCAX:
|
|
|
|
|
_dca.x = c - 32;
|
|
|
|
|
_state = StateDCAY;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case StateDCAY:
|
|
|
|
|
_dca.y = c - 32;
|
|
|
|
|
screen->setCursor(_dca);
|
|
|
|
|
|
|
|
|
|
_state = StateText;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case StateRepeatChar:
|
|
|
|
|
_repeatChar = c;
|
|
|
|
|
_state = StateRepeatCount;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case StateRepeatCount:
|
|
|
|
|
for (unsigned i = 0; i < c; ++i)
|
|
|
|
|
{
|
|
|
|
|
screen->putc(_repeatChar);
|
|
|
|
|
}
|
|
|
|
|
_state = StateText;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case StateTone1:
|
|
|
|
|
_state = StateTone2;
|
|
|
|
|
break;
|
|
|
|
|
case StateTone2:
|
|
|
|
|
// CONTROL-A indicates same as tone1.
|
|
|
|
|
_state = StateToneDuration;
|
|
|
|
|
break;
|
|
|
|
|
case StateToneDuration:
|
|
|
|
|
_state = StateText;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-07-11 15:26:53 +00:00
|
|
|
|
-(void)keyDown:(NSEvent *)event screen:(Screen *)screen output:(OutputChannel *)output
|
|
|
|
|
{
|
|
|
|
|
unsigned flags = [event modifierFlags];
|
|
|
|
|
NSString *chars = [event charactersIgnoringModifiers];
|
|
|
|
|
|
|
|
|
|
unsigned length = [chars length];
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < length; ++i)
|
|
|
|
|
{
|
|
|
|
|
unichar uc = [chars characterAtIndex: i];
|
|
|
|
|
|
|
|
|
|
switch (uc)
|
|
|
|
|
{
|
2010-12-20 23:37:02 +00:00
|
|
|
|
case NSEnterCharacter:
|
|
|
|
|
output->write(CTRL('M'));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NSDeleteCharacter:
|
|
|
|
|
output->write(0x7f);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// backspace and left arrow use the same code, alas.
|
|
|
|
|
case NSBackspaceCharacter:
|
2011-02-03 02:39:06 +00:00
|
|
|
|
output->write(0x7f);
|
2010-12-20 23:37:02 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2010-07-11 15:26:53 +00:00
|
|
|
|
case NSLeftArrowFunctionKey:
|
2010-12-18 17:40:58 +00:00
|
|
|
|
output->write(CTRL('H'));
|
|
|
|
|
break;
|
|
|
|
|
|
2010-07-11 15:26:53 +00:00
|
|
|
|
case NSRightArrowFunctionKey:
|
2010-12-18 17:40:58 +00:00
|
|
|
|
output->write(CTRL('U'));
|
|
|
|
|
break;
|
|
|
|
|
|
2010-07-11 15:26:53 +00:00
|
|
|
|
case NSUpArrowFunctionKey:
|
2010-12-18 17:40:58 +00:00
|
|
|
|
output->write(CTRL('K'));
|
|
|
|
|
break;
|
|
|
|
|
|
2010-07-11 15:26:53 +00:00
|
|
|
|
case NSDownArrowFunctionKey:
|
2010-12-18 17:40:58 +00:00
|
|
|
|
output->write(CTRL('J'));
|
|
|
|
|
break;
|
2010-12-20 23:37:02 +00:00
|
|
|
|
|
2010-07-11 15:26:53 +00:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
if (uc <= 0x7f)
|
|
|
|
|
{
|
|
|
|
|
char c = uc;
|
|
|
|
|
if (flags & NSControlKeyMask)
|
|
|
|
|
c = CTRL(c);
|
|
|
|
|
|
|
|
|
|
output->write(c);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-09 23:52:30 +00:00
|
|
|
|
@end
|