|
|
DataMuseum.dkPresents historical artifacts from the history of: Commodore CBM-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Commodore CBM-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 6621 (0x19dd)
Types: TextFile
Notes: UNIX file
Names: »hrterm2.bold«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
└─⟦f4b8d8c84⟧ UNIX Filesystem
└─⟦this⟧ »hrtty/src/hrterm2.bold«
#include <signal.h>
#include <errno.h>
#include "../h/rico.h"
#include "../h/machine.h"
#include "../h/display.h"
#include "../h/subr.h"
#include "../h/font.h"
extern unsigned short nulls[];
uint line,
col,
iget,
iput,
inl;
state;
bool iesc;
/*
** Screen Initialization routine. Called by htload
*/
ricoload()
{
register unsigned short i,j;
unsigned short *sp;
for(i = 0; i <YSCROLL*WPERSL;i++)nulls[i] = 0xffff;
sp = SEG0;
for(i = 0; i<512; i++)
for(j = 0; j < 1024/16; j++)
*sp++ = 0xffff;
sp = SEG1;
for(i = 0; i< 800-512; i++)
for(j = 0; j < 1024/16; j++)
*sp++ = 0xffff;
state = 0;
col = 0;
line = MAXLINE-1;
cursor();
}
rico( c)
{
static uint
arg,
args[2];
switch (state) {
/*
* no ongoing escape sequence
*/
case 0:
switch (c) {
case '\33':
state = 1;
break;
case '\n':
++line;
if (line >= MAXLINE) {
uint i;
for(i=0;i<YSCROLL;++i)
scompute((MAXLINE-1)*YSCROLL+i);
line = MAXLINE - 1;
scroll( );
}
col = 0;
break;
case '\r':
col = 0;
break;
case '\t':
col = tab( col);
break;
case '\b':
if (col)
--col;
break;
case ctrl( 'G'):
bell( );
break;
default:
plotc( c, col, line);
++col;
}
break;
/*
* ESC
*/
case 1:
switch (c) {
case '[':
arg = nel( args);
do {
args[--arg] = 0;
} while (arg);
state = 2;
break;
default:
state = 0;
rico( c);
break;
}
break;
/*
* ESC [
*/
case 2:
switch (c) {
default:
if ((isascii( c))
and (isdigit( c))
and (arg < nel( args))) {
args[arg] = args[arg]*10 + c - '0';
break;
}
state = 0;
rico( c);
break;
case ';':
++arg;
break;
case 'H': /* Cursor Home */
col = 0;
if (args[1])
col = args[1] - 1;
if (args[0])
--args[0];
if (args[0] < MAXLINE)
line = args[0];
state = 0;
break;
case 'A': /* Cursor Up */
if (not args[0])
++args[0];
if (args[0] <= line)
line -= args[0];
state = 0;
break;
case 'B': /* Cursor Down */
if (not args[0])
++args[0];
if (args[0] < MAXLINE-1)
line += args[0];
state = 0;
break;
case 'D':
if (not args[0])
++args[0];
if (args[0] <= col)
col -= args[0];
state = 0;
break;
case 'C':
if (not args[0])
++col;
else
col += args[0];
state = 0;
break;
case 'E': /* Erase Screen */
for(line = 0; line < MAXLINE; line++)
{
linerase(line);
slcompute(line);
}
line = 0;
col = 0;
state = 0;
break;
case 'L':
scrolld( line);
col = 0;
state = 0;
break;
case 'M':
scrollu( line);
col = 0;
state = 0;
break;
case 'K':
eolerase( line, col);
state = 0;
break;
case '@':
cinsert( args[0]);
state = 0;
break;
case 'P':
cdelete( args[0]);
state = 0;
break;
}
}
}
isascii(c) char c;{ return((c >= 0x20)&&(c <= 0x7f));}
isdigit(c) char c;{ return((c >= '0')&&(c<='9'));}
scrolld( li)
uint li;
{
uint y,
ybase,
n,
o,
*p,
*q,
co;
int i;
for (n=MAXLINE-1; n>li; --n)
if (not (texttab[n]&SCROLLABLE))
slcompute( n);
for (n=MAXLINE-1; n>li; --n)
{
i = n-1;
texttab[n] = texttab[i];
}
ybase = li * YSCROLL;
y = (MAXLINE-1) * YSCROLL;
while (y > ybase) {
--y;
if (y >= YSPLIT) {
p = (uint *)SEG1 + (y-YSPLIT)*WPERSL;
q = p + YSCROLL*WPERSL;
} else if (y+YSCROLL < YSPLIT) {
p = (uint *)SEG0 + y*WPERSL;
q = p + YSCROLL*WPERSL;
} else {
p = (uint *)SEG0 + y*WPERSL;
q = (uint *)SEG1 + (y+YSCROLL-YSPLIT)*WPERSL;
}
n = scantab[y+YSCROLL].sc_nword;
if (n) {
o = scantab[y+YSCROLL].sc_off;
p += o;
q += o;
aldir( q, p, n);
}
scantab[y+YSCROLL] = scantab[y];
}
eolerase( li, 0);
if (li+1 < MAXLINE)
texttab[li+1] &= ~SCROLLABLE;
}
eolerase( li, co)
uint li,
co;
{
if (texttab[li] & ERASED)
return;
if (not co) {
linerase( li);
texttab[li] |= ERASED;
}
else
for (; co<MAXCOL; ++co)
plotc( ' ', co, li);
texttab[li] &= ~SCROLLABLE;
if (li+1 < MAXLINE)
texttab[li+1] &= ~SCROLLABLE;
}
cinsert( n)
uint n;
{
uint y,
ylim,
co;
char *p;
if (not n)
n = 1;
y = line * YSCROLL;
ylim = y + YSCROLL;
for (; y<ylim; ++y) {
if (y < YSPLIT)
p = (char *)SEG0 + y*BPERSL;
else
p = (char *)SEG1 + (y-YSPLIT)*BPERSL;
if (n <= MAXCOL)
for (co=MAXCOL-n; co>col; ) {
--co;
p[co+n] = p[co];
}
for (co=col; co<col+n && co<MAXCOL; ++co)
p[co] = 0;
}
texttab[line] &= ~SCROLLABLE;
if (line+1 < MAXLINE)
texttab[line+1] &= ~SCROLLABLE;
}
cdelete( n)
uint n;
{
uint y,
ylim,
co;
char *p;
if (not n)
n = 1;
y = line * YSCROLL;
ylim = y + YSCROLL;
for (; y<ylim; ++y) {
if (y < YSPLIT)
p = (char *)SEG0 + y*BPERSL;
else
p = (char *)SEG1 + (y-YSPLIT)*BPERSL;
for (co=col; co+n<MAXCOL; ++co)
p[co] = p[co+n];
for (; co<MAXCOL; ++co)
p[co] = 0;
}
texttab[line] &= ~SCROLLABLE;
if (line+1 < MAXLINE)
texttab[line+1] &= ~SCROLLABLE;
}
plotc( c, co, li)
uint co,
li;
{
register short *fp;
register char
*p,
b;
register uint y,
ylim;
if (co >= MAXCOL)
return;
if((c > 0x7f) && (c < 0xa0)) return;
if(c < 0x20) return;
fp = font[c-' '];
if(c & 0x80) fp = font[c-0x40];
y = li * YSCROLL;
ylim = y + YSCROLL;
if (col&1) {
for(; y<ylim; ++y) {
if(y < YSPLIT)
p = (char *)SEG0+y*BPERSL + (co*12)/8;
else
p = (char *)SEG1+(y-YSPLIT)*BPERSL+
(co*12)/8;
b = (char)((~((*fp>>12) | (*fp>>11)))&0xf);
*p = (*p&0xf0)|b;
*++p = ~(((char)(*fp>>4)) | ((char)(*fp>>3)));
fp++;
}
}
else {
for (; y<ylim; ++y) {
if (y < YSPLIT)
p = (char *)SEG0 + y*BPERSL + (co*12/8);
else
p = (char *)SEG1 + (y-YSPLIT)*BPERSL
+ (co*12)/8;
*p++ = (char)(~(((*fp)>>8)|(*fp>>7)));
*p = (*p&0xf) | (char)((~(*fp|(*fp<<1)))&0xf0);
fp++;
}
}
texttab[li] &= ~ (SCROLLABLE|ERASED);
if (line+1 < MAXLINE)
texttab[line+1] &= ~SCROLLABLE;
}
bell( )
{
uint i,
*p;
p = SEG0;
for (i=0; i<2*YSCROLL*WPERSL; ++i)
*p++ ^= ~0;
p = SEG0;
for (i=0; i<2*YSCROLL*WPERSL; ++i)
*p++ ^= ~0;
}
cursor( )
{
uchar *p;
uint y,
ylim;
if (col >= MAXCOL)
return;
y = line * YSCROLL;
ylim = y + YSCROLL;
if(col&1) {
for (; y<ylim; ++y) {
if (y < YSPLIT)
p = (char *)SEG0 + y*BPERSL + (col*12)/8;
else
p = (char *)SEG1 + (y-YSPLIT)*BPERSL +
(col*12)/8;
*p++ ^=0x0f;
*p ^= 0xff;
}
}
else{
for(; y<ylim; ++y) {
if( y < YSPLIT)
p = (char *)SEG0 + y*BPERSL +
(col*12)/8;
else
p = (char *)SEG1 + y*BPERSL +
(col*12)/8;
*p++ ^= 0xff;
*p ^= 0xf0;
}
}
}