From 48f0b3eb836162d41622cedc1eb5f5168168fb8e Mon Sep 17 00:00:00 2001 From: Robert de Bath Date: Sun, 1 Feb 1998 11:26:21 +0100 Subject: Import Dev86src-0.13.5.tar.gz --- libc/Config_sh | 4 +- libc/Makefile | 7 +- libc/bios/Makefile | 2 +- libc/bios/bios_vid.c | 7 + libc/bios/time.c | 127 ++ libc/error/sys_errlist.c | 13 +- libc/getent/pwent.c | 2 + libc/include/asm/limits.h | 16 +- libc/include/dos.h | 1 + libc/kinclude/Config | 2 +- libc/misc/Makefile | 2 +- libc/misc/crypt.c | 45 +- libc/misc/tmpnam.c | 50 + libc/msdos/Makefile | 2 +- libc/msdos/i86.c | 50 +- libc/msdos/time.c | 2 +- libc/msdos/xxx/KEYTEST.C | 575 ++++++ libc/msdos/xxx/KEYTEST.EXE | Bin 0 -> 12236 bytes libc/msdos/xxx/KEYTEST.OBJ | Bin 0 -> 5567 bytes libc/msdos/xxx/TALK.C | 3931 +++++++++++++++++++++++++++++++++++++ libc/msdos/xxx/TALK.EXE | Bin 0 -> 23166 bytes libc/msdos/xxx/ZIP.COM | Bin 0 -> 16336 bytes libc/msdos/xxx/comx.com | Bin 0 -> 7772 bytes libc/msdos/xxx/cpu.com | Bin 0 -> 4824 bytes libc/msdos/xxx/list.com | Bin 0 -> 25927 bytes libc/msdos/xxx/mail-to-lasu.html | 105 + libc/msdos/xxx/mailfilter-mh.html | 86 + libc/msdos/xxx/mailfilter.html | 153 ++ libc/msdos/xxx/mailfilter2.tar.gz | Bin 0 -> 7104 bytes libc/msdos/xxx/mips.com | Bin 0 -> 13312 bytes libc/msdos/xxx/tryit.com | Bin 0 -> 3504 bytes libc/stdio2/stdio.c | 54 +- libc/string/string.c | 2 +- libc/syscall/Makefile | 9 +- libc/syscall/TODO | 2 + libc/syscall/dirent.c | 28 - libc/syscall/exec.c | 4 +- libc/syscall/mkentry.sh | 83 + libc/syscall/mksyscall | 31 +- libc/syscall/syscall.dat | 142 -- libc/syscall/syscall.dev86 | 160 ++ 41 files changed, 5450 insertions(+), 247 deletions(-) create mode 100644 libc/bios/time.c create mode 100644 libc/misc/tmpnam.c create mode 100644 libc/msdos/xxx/KEYTEST.C create mode 100644 libc/msdos/xxx/KEYTEST.EXE create mode 100644 libc/msdos/xxx/KEYTEST.OBJ create mode 100644 libc/msdos/xxx/TALK.C create mode 100644 libc/msdos/xxx/TALK.EXE create mode 100644 libc/msdos/xxx/ZIP.COM create mode 100644 libc/msdos/xxx/comx.com create mode 100644 libc/msdos/xxx/cpu.com create mode 100644 libc/msdos/xxx/list.com create mode 100644 libc/msdos/xxx/mail-to-lasu.html create mode 100644 libc/msdos/xxx/mailfilter-mh.html create mode 100644 libc/msdos/xxx/mailfilter.html create mode 100644 libc/msdos/xxx/mailfilter2.tar.gz create mode 100644 libc/msdos/xxx/mips.com create mode 100644 libc/msdos/xxx/tryit.com create mode 100644 libc/syscall/mkentry.sh delete mode 100644 libc/syscall/syscall.dat create mode 100644 libc/syscall/syscall.dev86 (limited to 'libc') diff --git a/libc/Config_sh b/libc/Config_sh index 5b72652..9446f5d 100644 --- a/libc/Config_sh +++ b/libc/Config_sh @@ -46,7 +46,7 @@ main() do display echo - echon 'Option to flip [or quit] >' + echon 'Select config option to flip [or quit] >' read n v="" case "$n" in @@ -76,8 +76,6 @@ main() display() { clear - echo 'Configuration options' - echo awk -F: < .config.lst '{ if( $3 == "+" ) next; if( $2 == "+" ) { flags[$1] = 1; next; } diff --git a/libc/Makefile b/libc/Makefile index 5ddea9a..efd21e5 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -11,18 +11,13 @@ endif VERMAJOR=0 VERMINOR=13 -VERPATCH=0 +VERPATCH=5 VER=$(VERMAJOR).$(VERMINOR).$(VERPATCH) CC=bcc CCFLAGS=-I -I$(TOP)/include DEFS=-D__LIBC__ -ifeq ($(ELKSSRC),) -ELKSSRC=/usr/src/elks -endif -export ELKSSRC - include Make.defs CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS) diff --git a/libc/bios/Makefile b/libc/bios/Makefile index 57128e0..b617e50 100644 --- a/libc/bios/Makefile +++ b/libc/bios/Makefile @@ -10,7 +10,7 @@ AOBJ=bios_start.o bios_isatty.o \ BSRC=bios_vid.c BOBJ=bios_putc.o bios_getc.o bios_khit.o bios_rdline.o -OBJ=$(AOBJ) $(BOBJ) +OBJ=$(AOBJ) $(BOBJ) time.o CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS) diff --git a/libc/bios/bios_vid.c b/libc/bios/bios_vid.c index db2e91d..ec3c603 100644 --- a/libc/bios/bios_vid.c +++ b/libc/bios/bios_vid.c @@ -410,6 +410,13 @@ int len; int ch; int pos=0; + if( len < 0 ) { errno = EINVAL; return -1; } + if( len == 0 ) + { + if( bios_khit() == 0 ) return 0; + errno = EINTR; + return -1; + } if( len == 1 ) { buf[0]=((ch=bios_getc())&0xFF?ch&0xFF:((ch>>8)&0xFF|0x80)); diff --git a/libc/bios/time.c b/libc/bios/time.c new file mode 100644 index 0000000..9bc63e5 --- /dev/null +++ b/libc/bios/time.c @@ -0,0 +1,127 @@ +/* + * Time functions for standalone mode, on the first call to time() it tries + * to query the RTC, on success it sets it's own day counter an the PC's + * ticks since midnight clock. From the second call on it uses the day + * counter and ticks clock. + * + * NOTES: + * DOS's midnight bug is here too, it's actually in the bios. + * If there's no RTC the clock will fall to Jan 3 1970. + */ + +#include + +static int mdays[13] = { 0,31,31+28,31+28+31,31+28+31+30, + 31+28+31+30+31,31+28+31+30+31+30,31+28+31+30+31+30+31, + 31+28+31+30+31+30+31+31,31+28+31+30+31+30+31+31+30, + 31+28+31+30+31+30+31+31+30+31,31+28+31+30+31+30+31+31+30+31+30, + 365 }; + +#define SECSPERHOUR (60*60) +#define SECSPERDAY (SECSPERHOUR*24L) + +/**************************************** + * Return the number of seconds that have elapsed since the start + * of 1970. + * Input: + * timer pointer to where to store result (or NULL) + * Output: + * *timer = result (unless timer == NULL) + * Returns: + * time + */ + +static int xt_days = 0, ax_val, huns = 0; + +static long get_time(ah) +{ +#asm +#if !__FIRST_ARG_IN_AX__ + mov bx,sp + mov ax,[bx+2] +#endif + mov ah,al + int $1A + jnc intok + mov cx,#-1 + mov dx,cx +intok: + mov [_ax_val],ax + mov ax,dx + mov dx,cx +#endasm +} + +static int +unbcd(bcdval) +int bcdval; +{ + return (bcdval&0xF) + 10*((bcdval>>4)&0xF); +} + +time_t time(timer) +time_t *timer; +{ + unsigned day,month,year; + long rv; + time_t t; + + if( xt_days ) goto XT_time; + + rv = get_time(0x02); + if(rv == -1) goto XT_time; + huns = unbcd(rv & 0xFF); /* Save for stime */ + rv >>= 8; t = unbcd(rv & 0xFF); + rv >>= 8; t += unbcd(rv & 0xFF)*60; + rv >>= 8; t += unbcd(rv & 0xFF)*3600; + + rv = get_time(0x04); + if(rv == -1) goto XT_time; + day = unbcd(rv & 0xFF); + rv >>= 8; month = unbcd(rv & 0xFF) -1; + rv >>= 8; year = unbcd(rv & 0xFF); + rv >>= 8; year += unbcd(rv & 0xFF)*100; + year -= 1970; + if( year < 1950 && year >= 1900 ) + year += 100; /* Century is not updated on RTC */ + + if (month <= 1 || year & 3) /* if before Feb or not a leap year */ + day--; /* don't add day for leap year */ + day += mdays[month]; /* day in year */ + day += (year + 3) >> 2; /* add a day for each leap year */ + t += ((year * 365L) + day) * SECSPERDAY; + + stime(t); + + if(0) + { +XT_time: + rv = get_time(0); + xt_days += (ax_val&0xFF); + rv = xt_days*SECSPERDAY + rv * 1080 / 19663; + } + + if (timer) + *timer = t; + return t; +} + +static long ticks; + +stime(timer) +time_t timer; +{ + xt_days = (timer/SECSPERDAY); + + ticks = ((timer%SECSPERDAY) * 19663L + huns*196) / 1080; + huns = 0; + +#asm + mov cx,[_ticks+2] + mov dx,[_ticks] + mov ah,#1 + int $1A +#endasm + + return 0; +} diff --git a/libc/error/sys_errlist.c b/libc/error/sys_errlist.c index 79a40bf..48aa6a3 100644 --- a/libc/error/sys_errlist.c +++ b/libc/error/sys_errlist.c @@ -10,7 +10,7 @@ * Of course the best of all is to use strerror(). */ -#ifdef __AS386_16__ +#if defined(__AS386_16__) || defined(__AS386_32__) #define NR_ERRORS 128 extern char **__sys_errlist; @@ -19,12 +19,21 @@ extern int __sys_nerr; char *sys_errlist[NR_ERRORS]; int sys_nerr = NR_ERRORS; +#ifdef __AS386_16__ #asm loc 1 ! Make sure the pointer is in the correct segment auto_func: ! Label for bcc -M to work. .word _init_vars ! Pointer to the autorun function .text ! So the function after is also in the correct seg. #endasm +#else +#asm + loc 1 ! Make sure the pointer is in the correct segment +auto_func: ! Label for bcc -M to work. + .long _init_vars ! Pointer to the autorun function + .text ! So the function after is also in the correct seg. +#endasm +#endif static void init_vars() { @@ -71,4 +80,4 @@ static void init_vars() __sys_nerr = sys_nerr = NR_ERRORS; } -#endif /* __AS386_16__ */ +#endif /* __AS386_??__ */ diff --git a/libc/getent/pwent.c b/libc/getent/pwent.c index fd65db2..738c87a 100644 --- a/libc/getent/pwent.c +++ b/libc/getent/pwent.c @@ -53,6 +53,8 @@ endpwent(void) struct passwd * getpwent(void) { + if (pw_fd==-1) + setpwent(); if (pw_fd!=-1) return __getpwent(pw_fd); return NULL; diff --git a/libc/include/asm/limits.h b/libc/include/asm/limits.h index 54b48bc..531ea41 100644 --- a/libc/include/asm/limits.h +++ b/libc/include/asm/limits.h @@ -10,9 +10,9 @@ #define MB_LEN_MAX 1 /* Longest multi-byte character */ #define CHAR_BIT 8 /* number of bits in a char */ #define SHRT_MAX 32767 /* maximum (signed) short value */ -#define SHRT_MIN (-32767) /* minimum (signed) short value */ +#define SHRT_MIN (-32768) /* minimum (signed) short value */ #define LONG_MAX 2147483647 /* maximum (signed) long value */ -#define LONG_MIN (-2147483647) /* minimum (signed) long value */ +#define LONG_MIN (-2147483648) /* minimum (signed) long value */ #define UCHAR_MAX 255 /* maximum unsigned char value */ #define USHRT_MAX 0xffff /* maximum unsigned short value */ #define ULONG_MAX 0xffffffff /* maximum unsigned long value */ @@ -23,26 +23,26 @@ #ifdef __AS386_32__ #define INT_MAX 2147483647 /* maximum (signed) int value */ -#define INT_MIN (-2147483647) /* minimum (signed) int value */ +#define INT_MIN (-2147483648) /* minimum (signed) int value */ #define UINT_MAX 0xffffffff /* maximum unsigned int value */ #else #define INT_MAX 32767 /* maximum (signed) int value */ -#define INT_MIN (-32767) /* minimum (signed) int value */ +#define INT_MIN (-32768) /* minimum (signed) int value */ #define UINT_MAX 0xffff /* maximum unsigned int value */ #endif /* BCC doesn't have signed char */ /* #define SCHAR_MAX 127 /* maximum signed char value */ -/* #define SCHAR_MIN (-127) /* minimum signed char value */ +/* #define SCHAR_MIN (-128) /* minimum signed char value */ #endif #if defined(__GNUC__) && defined(__i386__) #define CHAR_MAX 127 /* maximum char value */ -#define CHAR_MIN (-127) /* mimimum char value */ +#define CHAR_MIN (-128) /* mimimum char value */ #define SCHAR_MAX 127 /* maximum signed char value */ -#define SCHAR_MIN (-127) /* minimum signed char value */ +#define SCHAR_MIN (-128) /* minimum signed char value */ #define INT_MAX 2147483647 /* maximum (signed) int value */ -#define INT_MIN (-2147483647) /* minimum (signed) int value */ +#define INT_MIN (-2147483648) /* minimum (signed) int value */ #define UINT_MAX 0xffffffff /* maximum unsigned int value */ #endif diff --git a/libc/include/dos.h b/libc/include/dos.h index 1e2b11e..d67e27f 100644 --- a/libc/include/dos.h +++ b/libc/include/dos.h @@ -24,6 +24,7 @@ void __setvect __P((int i, long j)); long __getvect __P((int vecno)); #endif +unsigned int __get_cs __P((void)); unsigned int __get_ds __P((void)); unsigned int __get_es __P((void)); void __set_es __P((unsigned int seg)); diff --git a/libc/kinclude/Config b/libc/kinclude/Config index 6c9970d..bd58ab7 100644 --- a/libc/kinclude/Config +++ b/libc/kinclude/Config @@ -1 +1 @@ -kinc: Example kernel include files +kinc: Example kernel include files and syscall.dat diff --git a/libc/misc/Makefile b/libc/misc/Makefile index 50d31b7..6634f18 100644 --- a/libc/misc/Makefile +++ b/libc/misc/Makefile @@ -12,7 +12,7 @@ GOBJ=atoi.o atol.o ltoa.o ltostr.o \ ctype.o qsort.o bsearch.o rand.o lsearch.o getopt.o \ itoa.o cputype.o strtol.o crypt.o -UOBJ=getenv.o putenv.o popen.o system.o setenv.o getcwd.o +UOBJ=getenv.o putenv.o popen.o system.o setenv.o getcwd.o tmpnam.o SSRC=syslib.c SOBJ=time.o abort.o wait.o wait3.o waitpid.o killpg.o setpgrp.o sleep.o \ diff --git a/libc/misc/crypt.c b/libc/misc/crypt.c index 906dea2..db69325 100644 --- a/libc/misc/crypt.c +++ b/libc/misc/crypt.c @@ -1,42 +1,65 @@ -#include -#include /* TEA based crypt(), version 0.0 * It looks like there are problems with key bits carrying through * to the encryted data, and I want to get rid of that libc call.. * This is just so rob could see it ;) */ + +/* + * I've: + * Compared the TEA implementation to a reference source - OK + * Noted the cycles count at 64 is twice the suggested value. + * Changed the types of 'n' and 'i' for better code with bcc. + * Removed a possible overrun of rkey by looping the values, it's now + * possible to _choose_ every bit of the 128bit PW with a 32 character word. + * Corrected the output transformation, it lost bits between words. + * Cleaned out all trace of the uncrypted PW from rkey. + * + * RDB. + */ + +#include + char * crypt(const char * key, const char * salt) { - /* n is the number of rounds, delta is a golden # derivative, - k is the key, v is the data to be encrypted. */ - unsigned long v[2], sum=0, delta=0x9e3779b9, n=64, k[4]; + /* n is the number of cycles (2 rounds/cycle), + delta is a golden # derivative, + k is the key, v is the data to be encrypted. */ + + unsigned long v[2], sum=0, delta=0x9e3779b9, k[4]; + int n=64, i, j; static char rkey[16]; - unsigned char i; /* Our constant string will be a string of zeros .. */ v[0]=v[1]=k[0]=k[1]=k[2]=k[3]=0; for(i=0;i<16;i++) rkey[i]=0; + rkey[0]=*salt; rkey[1]=salt[1]; - for (i=0;key[i];i++) rkey[i+1]=key[i]; + for (j=2,i=0;key[i];i++,j=((j+1)&15)) + rkey[j]=(rkey[j]<<4)+(rkey[j]>>4)+ key[i]; + memcpy(k, rkey, 4*sizeof(long)); - while (n-->0) { + while (n-->0) { sum += delta; v[0] += (v[1]<<4)+k[0] ^ v[1]+sum ^ (v[1]>>5)+k[1]; v[1] += (v[0]<<4)+k[2] ^ v[0]+sum ^ (v[0]>>5)+k[3]; } + /* Remove any trace of key */ + for(i=0;i<16;i++) rkey[i]=0; *rkey=*salt; rkey[1]=salt[1]; /* Now we need to unpack the bits and map it to "A-Za-z0-9./" for printing in /etc/passwd */ + sum=v[0]; for (i=2;i<13;i++) { /* This unpacks the 6 bit data, each cluster into its own byte */ - if (i==8) v[0]|=v[1]>>28; - rkey[i]=v[(i-2)/6]&0x3F; - v[(i-2)/6]>>=6; + rkey[i]=(sum&0x3F); + sum>>=6; + if(i==0+2) sum |= (v[1]<<26); + if(i==5+2) sum |= (v[1]>>4); /* Now we map to the proper chars */ if (rkey[i]>=0 && rkey[i]<12) rkey[i]+=46; diff --git a/libc/misc/tmpnam.c b/libc/misc/tmpnam.c new file mode 100644 index 0000000..5bb72c5 --- /dev/null +++ b/libc/misc/tmpnam.c @@ -0,0 +1,50 @@ +/* + * (C) Shane Kerr under terms of LGPL + */ + +#include +#include +#include + +#ifndef P_tmpdir +#define P_tmpdir "/tmp" +#endif + +#ifndef L_tmpnam +#define L_tmpnam 20 +#endif + +char *tmpnam(s) +char *s; +{ + static char ret_val[L_tmpnam]; + static char c1 = 0; + static char c2 = 0; + static char c3 = 0; + static char uniq_ch[] = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + struct stat stbuf; + + do { + sprintf(ret_val, "%s/%05d%c%c%c", P_tmpdir, getpid(), + uniq_ch[c1], uniq_ch[c2], uniq_ch[c3]); + if (++c1 >= 62) { + c1 = 0; + if (++c2 >= 62) { + c2 = 0; + if (++c3 >= 62) { + errno = EEXIST; + return 0; + } + } + } + } while (stat(ret_val, &stbuf) == 0); + + if (s != 0) { + strcpy(s, ret_val); + return s; + } else { + return ret_val; + } +} + diff --git a/libc/msdos/Makefile b/libc/msdos/Makefile index d929ee8..d4bc49a 100644 --- a/libc/msdos/Makefile +++ b/libc/msdos/Makefile @@ -10,7 +10,7 @@ AOBJ= dos_start.o __mkargv.o __mkenvp.o dos__fconv.o dos_read.o \ BSRC=i86.c BOBJ= __seg_regs.o __peek_es.o __poke_es.o __deek_es.o __doke_es.o \ - __strchr_es.o + __strnget_es.o __strchr_es.o __strlen_es.o ifeq ($(LIB_CPU),i86) ifeq ($(LIB_OS),DOS) diff --git a/libc/msdos/i86.c b/libc/msdos/i86.c index 44de3e3..6c613b2 100644 --- a/libc/msdos/i86.c +++ b/libc/msdos/i86.c @@ -173,20 +173,48 @@ got_it: } #endif -#ifdef L___strchr_es +#ifdef L___strnget_es char * __strnget_es(d, s, c) -char *d, *s; -int c; +char *d; +char *s; +register int c; { - int ds, es; - char *p = __strchr_es(s, '\0'); - if(p != 0 && p-s < c) - c = p-s+1; - ds = __get_ds(); - es = __get_es(); - - __movedata(es, s, ds, d, c); + register int i = __strlen_es(s); + if(i < c) c = i+1; + /* else s[--c] = 0; ?? */ + /* else return -E2BIG; ?? */ + + __movedata(__get_es(), s, __get_ds(), d, c); +} +#endif + +#ifdef L___strlen_es +int __strlen_es(str) +char * str; +{ +#asm +#if !__FIRST_ARG_IN_AX__ + mov bx,sp +#endif + push di + cld + +#if __FIRST_ARG_IN_AX__ + mov di,ax +#else + mov di,[bx+2] +#endif + mov cx,#-1 + xor ax,ax + repne + scasb ! Scans [ES:DI] + not cx + dec cx + mov ax,cx + + pop di +#endasm } #endif diff --git a/libc/msdos/time.c b/libc/msdos/time.c index 0a66da8..271ea05 100644 --- a/libc/msdos/time.c +++ b/libc/msdos/time.c @@ -24,7 +24,7 @@ static int mdays[13] = { 0,31,31+28,31+28+31,31+28+31+30, static long get_time(ah) { #asm -#if !__FIST_ARG_IN_AX__ +#if !__FIRST_ARG_IN_AX__ mov bx,sp mov ax,[bx+2] #endif diff --git a/libc/msdos/xxx/KEYTEST.C b/libc/msdos/xxx/KEYTEST.C new file mode 100644 index 0000000..6627647 --- /dev/null +++ b/libc/msdos/xxx/KEYTEST.C @@ -0,0 +1,575 @@ + +#include +#include +#include +#include + +#define KEY_SPECIAL 0x8000 +#define KEY_PAD 0x4000 +#define KEY_OTHER 0x2000 +#define KEY_DIRECT 0x1000 +#define KEY_ALT 0x0800 +#define KEY_ALTGR 0x0400 +#define KEY_CTRL 0x0200 +#define KEY_SHIFT 0x0100 + +#ifndef OBJ_FILE + +#define KEYBD 0x09 +#define cprintf printf + +int get_key(void); +void ( interrupt far *orig_keybd)(); +void interrupt far keybd(); + +int scrcol = 0; +int keymode = 1; + +int bios_key = -1, bios_flags = -1; + +#ifdef __BORLANDC__ +static int kbd_type = -1; +#else +static int kbd_type = 0; +#endif + +main(argc, argv) +int argc; +char ** argv; +{ + int ch, by; + union REGS regs; + short far * ptr = (short far * ) 0x0040001AL; + int i; + + if( argc > 1 ) keymode = atoi(argv[1]); + + if( keymode & 4 ) { keymode &= -5; kbd_type = 0 ; } + + signal(SIGINT, SIG_IGN); + + cprintf("Keyboard testing: Press Escape to exit\r\n"); + orig_keybd = _dos_getvect(KEYBD); + _dos_setvect(KEYBD, keybd); + + do + { + ch = get_key(); + + if( (ch&0xFF00) == KEY_SPECIAL + KEY_DIRECT + KEY_OTHER ) + { + if( bios_flags != -1 ) + { + cprintf(">\r\n"); + if( bios_key != -1 ) + cprintf( "BIOS %04x, FLGS: %04x\n", bios_key, bios_flags); + else if( bios_flags != -1 ) + cprintf( "BIOS ----, FLGS: %04x\n", bios_flags); + scrcol=2; + cprintf(" <"); + } + if( scrcol > 76 ) { cprintf("\r\n"); scrcol = 0; } + if( scrcol == 0 ) { cprintf("<"); scrcol += 1; } + write_scan(ch&0xFF); + } + else if( ch != -1 ) + { + cprintf(">\r\n"); + if( bios_key != -1 ) + cprintf( "BIOS %04x, FLGS: %04x: ", bios_key, bios_flags); + else if( bios_flags != -1 ) + cprintf( "BIOS ----, FLGS: %04x: ", bios_flags); + else + cprintf( "BIOS ----, FLGS: ----: "); + cprintf("Got key = 0x%04x is: ", ch); + + if( ch & KEY_SPECIAL ) + { + cprintf("Special-"); + if( ch & KEY_CTRL ) cprintf("Ctrl-"); + if( ch & KEY_SHIFT ) cprintf("Shift-"); + if( ch & KEY_ALT ) cprintf("Alt-"); + if( ch & KEY_ALTGR ) cprintf("AltGr-"); + if( ch & KEY_DIRECT ) cprintf("Scan-"); + by = (ch & 0xFF); + } + else + { + cprintf("ASCII-"); + by = (ch & 0xFFF); + if( ch & KEY_DIRECT ) cprintf("Code-"); + } + if( ch & KEY_PAD ) cprintf("KeyPad-"); + if( ch & KEY_OTHER ) cprintf("Other-"); + + switch( ch & KEY_SPECIAL ) + { + case KEY_SPECIAL: + if( ch & KEY_DIRECT ) + cprintf("0x%02x\r\n", by); + else if((by&0xF0)==0x80 ) + cprintf("F%d\r\n", by&0xF); + else if((by&0xF0)==0x90 ) + cprintf("K%d\r\n", by&0xF); + else + { + case 0: + if( by >= ' ' && by <= '~' ) + cprintf("'%c'\r\n", by); + else + cprintf("0x%02x\r\n", by); + } + } + + scrcol=5; + cprintf(": "); + if( keymode ) write_dosemu(ch); else write_xenix(ch); + cprintf(" <"); + } + } + while( (ch &0x80FF) != '\033' ); + + _dos_setvect(KEYBD, orig_keybd); + + while( get_key() != -1 ) ; + + if( scrcol ) { cprintf("\r\n"); scrcol = 0; } +} + +void interrupt far keybd() +{ +#ifdef __BORLANDC__ +register int i; + + i = inp(0x60); + + _CX = 0xFE00 + (i&0xFF); + _AH = 0x05; geninterrupt(0x16); + + if( keymode&2 ) + { + _AH = 0x12; geninterrupt(0x16); i = _AX; + _CX = 0xFF00 + (i&3) + ((i&0xF00)>>6) + ((i>>9)&0x40); + _AH = 0x05; geninterrupt(0x16); + } +#endif + + _chain_intr(orig_keybd); +} +#endif + +xmit(ch) +{ + ch &= 0xFF; + if( ch < ' ' ) + { + cprintf("^%c", ch+'@'); + scrcol++; + } + else + cprintf("%c", ch); + scrcol++; +} + +static int bioskeydecode[] = { + 0x0000, 0x3280, 0x3131, 0x3132, 0x3133, 0x3134, 0x3135, 0x3136, + 0x3137, 0x3138, 0x3139, 0x3130, 0x312d, 0x313d, 0x3308, 0x1209, + 0x3171, 0x3177, 0x3165, 0x3172, 0x3174, 0x3179, 0x3175, 0x3169, + 0x316f, 0x3170, 0x315b, 0x315d, 0x330d, 0x0000, 0x3161, 0x3173, + 0x3164, 0x3166, 0x3167, 0x3168, 0x316a, 0x316b, 0x316c, 0x313b, + 0x0100, 0x0100, 0x0000, 0x0400, 0x317a, 0x3178, 0x3163, 0x3176, + 0x3162, 0x316e, 0x316d, 0x312c, 0x312e, 0x312f, 0x0000, 0x0700, + 0x0000, 0x3520, 0x0000, 0x0481, 0x0482, 0x0483, 0x0484, 0x0485, + 0x0486, 0x0487, 0x0488, 0x0489, 0x048a, 0x0000, 0x0000, 0x0697, + 0x0698, 0x0699, 0x0700, 0x0694, 0x0695, 0x0696, 0x0700, 0x0691, + 0x0692, 0x0693, 0x0690, 0x069a, 0x1481, 0x1482, 0x1483, 0x1484, + 0x1485, 0x1486, 0x1487, 0x1488, 0x1489, 0x148a, 0x2481, 0x2482, + 0x2483, 0x2484, 0x2485, 0x2486, 0x2487, 0x2488, 0x2489, 0x248a, + 0x3481, 0x3482, 0x3483, 0x3484, 0x3485, 0x3486, 0x3487, 0x3488, + 0x3489, 0x348a, 0x0000, 0x2694, 0x2696, 0x2691, 0x2693, 0x2697, + 0x3131, 0x3132, 0x3133, 0x3134, 0x3135, 0x3136, 0x3137, 0x3138, + 0x3139, 0x3130, 0x002d, 0x003d, 0x2699, 0x048b, 0x048c, 0x148b, + 0x148c, 0x248b, 0x248c, 0x348b, 0x348c, 0x2698, 0x2700, 0x2695, + 0x2700, 0x2692, 0x2690, 0x269a, 0x2009, 0x2700, 0x2700, 0x3697, + 0x3698, 0x3699, 0x0000, 0x3694, 0x3695, 0x3696, 0x0000, 0x3691, + 0x3692, 0x3693, 0x3690, 0x369a, 0x3700, 0x3009, 0x3700, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0700, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 +}; + +int get_key() +{ +static int last_flgs = 0; +static int force_flgs[] = {0, 2, 4, 8}; +static int this_flags = -1; + + int ch, flgs, scan, flgs2; + int scand; + int i; + + bios_key = bios_flags = -1; +try_again:; /* If we get a scan generator */ + +#ifdef __BORLANDC__ + if( kbd_type < 0 ) + { + kbd_type = 0; + + for(i=0; i<16;i++) + { + _AH = 0x01; geninterrupt(0x16); if((_FLAGS&0x40)) break; + _AH = 0x00; geninterrupt(0x16); + } + _AH = 0x05; _CX= 0xFFFF; geninterrupt(0x16); + for(i=0; i<16;i++) + { + _AH = 0x11; geninterrupt(0x16); if((_FLAGS&0x40)) break; + _AH = 0x10; geninterrupt(0x16); + if( _AX == 0xFFFF ) + { + kbd_type = 0x10; + break; + } + } + cprintf("Keyboard is %sT\n", kbd_type?"A":"X"); + } + + _AH = kbd_type+1; geninterrupt(0x16); + i = (_FLAGS&0x40); + + _AH = kbd_type+2; geninterrupt(0x16); flgs = _AX; + if( !kbd_type ) flgs &= 0xFF; + +#else + i = !_bios_keybrd(_KEYBRD_READY); + + flgs = _bios_keybrd(_KEYBRD_SHIFTSTATUS); +#endif + + if( keymode == 3 ) { flgs = 0; this_flags= -1; } + + if(!(flgs&0x8)) flgs &= ~0x0A00; + + if(i) + { + if( flgs != last_flgs ) + { + ch = 0; + last_flgs = flgs; + i=0; + if( (flgs & 0x500) == 0x500 ) ch |= KEY_CTRL; + if( (flgs & 0xA00) == 0xA00 ) ch |= KEY_ALT|KEY_ALTGR; + if(!i) + { + if( (flgs & 0x001) ) i++; + if( (flgs & 0x002) ) i++; + if( (flgs & 0x004) ) i++; + if( (flgs & 0x008) ) i++; + } + + if( i>1 ) + { + if( flgs & 0x4 ) ch |= KEY_CTRL; + if( flgs & 0x3 ) ch |= KEY_SHIFT; + if( (flgs & 0x0A00) ) + ch |= ((flgs&0x0200)?KEY_ALT:0) + ((flgs&0x0800)?KEY_ALTGR:0) ; + else + ch |= ((flgs&0x08)?KEY_ALT:0); + } + + if( ch ) + { + bios_key = -1; bios_flags = flgs; + return (ch + KEY_SPECIAL); + } + } + return -1; + } + else + { +#ifdef __BORLANDC__ + _AH = kbd_type; geninterrupt(0x16); + ch = (unsigned) _AX; +#else + ch = _bios_keybrd(_KEYBRD_READ); +#endif + } + + if( this_flags != -1 ) + { + flgs = ( flgs & 0x70F0 ) + + ( this_flags & 3 ) + + ((this_flags & 0x3C) << 6 ) + + ((this_flags & 0x40) << 9 ); + if( flgs & 0x500 ) flgs |= 0x04; + if( flgs & 0xA00 ) flgs |= 0x08; + this_flags = -1; + } + + if( ( ch & 0xFF00 ) == 0xFF00 ) { this_flags = ch; goto try_again; } + if( ( ch & 0xFF00 ) == 0xFE00 ) + return KEY_SPECIAL + KEY_DIRECT + KEY_OTHER + (ch&0xFF); + + last_flgs = flgs; + bios_key = ch; bios_flags = flgs; + + flgs &= 0x0A0F; + if( ch == 0 ) return KEY_OTHER + 0x03; + + scan = ((ch>>8)&0xFF); + ch &= 0xFF; + + if( scan == 0 ) return ch + KEY_DIRECT; + if( scan == 0xE0 ) scan = 0xA4 + 2*(ch < ' '); + + flgs2 = 0; + if( ch == 0xE0 ) { flgs2 |= KEY_PAD; ch = 0; } + + /* Check for forced flags */ + if( ch == 0 && (flgs&0xF) == 0 ) + flgs |= force_flgs[(bioskeydecode[scan]>>12)&3]; + + if( flgs & 0x4 ) flgs2 |= KEY_CTRL; + if( flgs & 0x3 ) flgs2 |= KEY_SHIFT; + + if( (flgs & 0x0A00) ) + flgs2 |= ((flgs&0x0200)?KEY_ALT:0) + ((flgs&0x0800)?KEY_ALTGR:0) ; + else + flgs2 |= ((flgs&0x08)?KEY_ALT:0); + + if( ch ) switch(flgs2) + { + case 0: case KEY_CTRL: case KEY_SHIFT: + switch((bioskeydecode[scan]>>8)&7) + { + case 1: + return ch; + case 2: + if( flgs2 == 0 ) return ch + KEY_OTHER; + break; + case 3: + if( (flgs2 & ~KEY_CTRL) == 0 ) return ch + KEY_OTHER; + break; + case 4: + if( (flgs2 & ~KEY_SHIFT) == 0 ) return ch; + if( flgs2 == KEY_CTRL ) return (ch&0x1F); + break; + case 5: + if( flgs2 == 0 ) return ch; + break; + case 6: + if( flgs2 == 0 ) return ch + KEY_PAD; + break; + case 7: return ch + KEY_PAD; + } + } + + flgs2 |= KEY_SPECIAL; + + if( ((bioskeydecode[scan]>>8)&6) == 6 && (flgs&0x08) == 0 && kbd_type ) + flgs2 ^= KEY_PAD; + + if( ((bioskeydecode[scan]>>8)&7) == 4 && ch ) + ; + else if(bioskeydecode[scan]&0xFF) + return flgs2 + (bioskeydecode[scan]&0xFF); + + return flgs2 + KEY_DIRECT + scan; +} + +unsigned char scan_desc[] = { + 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 8, 0, + 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 10, 'C', 'a', 's', + 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', 0, 0, 'S', 0, 'z', 'x', 'c', 'v', + 'b', 'n', 'm', ',', '.', '/', 'T', 0, 'A', ' ', 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 'E', 'F', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +char hextbl[] = "0123456789abcdef"; + +/* Write scancodes, in this mode you really need a compatible program on + * the host, but you can just about type 'reset' and have it work + */ +write_scan(scan) +int scan; +{ +static int lastscan = -1; + int by; + + scan &= 0xFF; + + if( scan == lastscan+0x80 ) + { xmit('~'); xmit('\b'); } + else if( scan == 0xE0 || scan == 0xE1 ) + xmit('E'+scan-0xE0); + else if( by = scan_desc[scan&0x7F] ) + { + if( scan & 0x80 ) + { xmit('!'); xmit(by); } + else + xmit(by); + } + else + { xmit('~'); xmit(hextbl[scan>>4]); xmit(hextbl[scan&0xF]); } + lastscan = scan; +} + +/* + * This keyboard gives a pattern of control sequences that makes just about + * every keypress distinct. It does need a compatible host program but its + * useable as a generic terminal type unlike the scancodes. + */ +write_dosemu(ch) +int ch; +{ +#define CT_KEY 0x1E + int by = (ch & 0xFF); + + /* First we swap round ^M and Return, likewise BS, Tab and Esc */ + if( ( ch & 0xFF00 ) == KEY_OTHER || ( ch & 0xFF00 ) == 0 ) + { + /* Make it so we can detect the 'other' keys */ + if( strchr("\b\t\r\n\033\003\177", by) ) + { + if( ch & KEY_OTHER ) + ch ^= KEY_OTHER; + else + by = ((ch = KEY_SPECIAL+KEY_CTRL+tolower(by+'@')) & 0xFF); + } + } + + if( ch & 0xFF00 ) + { + if( ch & KEY_SPECIAL ) + { + if( by == 0 ) return; + + if( ch & KEY_ALT ) { xmit(CT_KEY); xmit('a'); } + if( ch & KEY_CTRL ) { xmit(CT_KEY); xmit('c'); } + if( ch & KEY_SHIFT ) { xmit(CT_KEY); xmit('s'); } + if( ch & KEY_ALTGR ) { xmit(CT_KEY); xmit('g'); } + if( ch & KEY_PAD ) { xmit(CT_KEY); xmit('k'); } + /* if( ch & KEY_OTHER ) { xmit(CT_KEY); xmit('o'); } */ + + if( ch & KEY_DIRECT ) + { + xmit(CT_KEY); xmit('~'); + xmit(hextbl[by>>4]); xmit(hextbl[by&0xF]); + } + else if((by&0xF0)==0x80 ) + { +static char fkeys[] = "01234567890-=.."; + if( by == 0x80 ) + { + xmit('\033'); + xmit('\033'); + } + else + { + xmit(CT_KEY); + xmit(fkeys[by&0xF]); + } + } + else if((by&0xF0)==0x90 ) + { + xmit(CT_KEY); + xmit('K'); + xmit(hextbl[by&0xF]); + } + else + xmit(by); + } + else + { + if( ch & KEY_PAD ) { xmit(CT_KEY); xmit('k'); } + if( ch & KEY_OTHER ) { xmit(CT_KEY); xmit('o'); } + if( ch & KEY_DIRECT ) { xmit(CT_KEY); xmit('z'); } + xmit(by); + } + } + else if( by == CT_KEY ) + { + xmit(CT_KEY); xmit('c'); xmit(tolower(CT_KEY+'@')); + } + else + { + xmit(by); + if( by == '\033' ) + xmit(by); + } +} + +/* + * This generates key sequences compatible with the SCO-Xenix console. + * In addition many extra key combinations generate distinct codes. + * But there are normally several ways of generating each standard key. + * + * This key mapping is designed for easy use with terminfo nevertheless + * it has potentially 96 function key + 104 alt/ctrl/shift&letter codes. + */ +write_xenix(ch) +int ch; +{ + int by; + /* 012345678901234567890123456 789012 */ +static char normal[] = " MNOPQRSTUVWX LFBGDECHAI\177 "; +static char shift [] = " YZabcdefghij 0123456789\177 "; +static char ctrl [] = " klmnopqrstuv \177 "; +static char ctrshf[] = " wxyz@[\\]^_`{ \177 "; + + /* This seems to be a pain if it stays */ + if( ch == KEY_SPECIAL+KEY_SHIFT+'\r' ) ch = '\r'; + if( ch == KEY_SPECIAL+KEY_SHIFT+' ' ) ch = ' '; + + if( ch & KEY_SPECIAL ) + { + if( ch & (KEY_ALT|KEY_ALTGR|KEY_DIRECT) ) + write_dosemu(ch); + else if( (ch & 0xE0) != 0x80 ) + write_dosemu(ch); + else + { + char * keys; + if( ch&KEY_SHIFT ) + { + if( ch&KEY_CTRL ) keys = ctrshf; else keys = shift; + } + else + { + if( ch&KEY_CTRL ) keys = ctrl; else keys = normal; + } + by = keys[ch&0x1F]; + if( by == ' ' ) write_dosemu(ch); + else if( by == '\177' || by >= '0' && by <= '9' ) + xmit(by); + else + { + xmit('\033'); + xmit('['); + xmit(by); + } + } + } + else + xmit(ch&0xFF); +} diff --git a/libc/msdos/xxx/KEYTEST.EXE b/libc/msdos/xxx/KEYTEST.EXE new file mode 100644 index 0000000..1dd6553 Binary files /dev/null and b/libc/msdos/xxx/KEYTEST.EXE differ diff --git a/libc/msdos/xxx/KEYTEST.OBJ b/libc/msdos/xxx/KEYTEST.OBJ new file mode 100644 index 0000000..10e5755 Binary files /dev/null and b/libc/msdos/xxx/KEYTEST.OBJ differ diff --git a/libc/msdos/xxx/TALK.C b/libc/msdos/xxx/TALK.C new file mode 100644 index 0000000..b84c435 --- /dev/null +++ b/libc/msdos/xxx/TALK.C @@ -0,0 +1,3931 @@ +/* + * Terminal emulator. + * + * This program is a terminal emulator for the IBM PC. + * It's basic emulation is as very close to the SCO-Xenix ANSI console + * but it's had a few additions that seemed a good idea at the time. + * + * Performance: I use this on a 16Mhz 286 at 115k2 baud with RTS flow + * control and experience NO lost characters. The PC cannot + * quite keep up if flow control is disabled though. + * + * This program can run at 19200 on a 4.77 Mhz XT with flow control. + * (Upto 57600 is possible if the BIOS doesn't disable interrupts) + */ + +/* + * TODO: + * + * - Add file operations (open, read/write block, close) + * - Add dubious hack to attempt to make keyboard & timer RTS-Flow active. + * - Adjust extra CSI codes to be in small range (CSI $A .. CSI $Z ?) + * - Add ZMODEM challange string. + * - Add local echo mode. (Only ascii chars ?) + * - Add magic echo mode - like local echo but display tempoary. + * - Merge BIOS serial with HW serial. + */ +/***************************************************************************** + + ANSI Emulation. + =============== + + Special characters + + ^G Beep + ^H Backspace + ^I Tab + ^J Linefeed + ^L Clear screen + ^M Carriage return + ^V Avatar code prefix. + ^X Cancel Escape code or string (XXX But ZMODEM) + ^[ Escape code prefix + + Escape codes + + ^[ [ CSI code - see below. + ^[ P DCS Code, as CSI followed by string and ST + ^[ \ ST - String terminator. + + ^[ ( Font select + U IBM CP 437 + u IBM CP 437 with 0x00-0x7f replicated to 0x80-0xFF + B ISO 8859-1 + DIRECT FONT 0x00-0x1F in 0x80-0x9F. + 0 VT100 Graphics + DIRECT FONT 0x80-0xFF + A UK ASCII + + ^[ 7 Save cursor position (XXX Attribute?) + ^[ 8 Restore cursor position (XXX Attribute?) + + ^[ M Reverse LF (Not implemented) + + ^[ Q SCO Function key redefinition (Only if !AT_BIOS_KEY) + + ^[ > Keyboard normal (if AT_BIOS_KEY) + ^[ = Keyboard in dosemu/keypad mode. (if AT_BIOS_KEY) + + Simple ANSI CSI codes + + CSI A Cursor Up + CSI B Cursor Down + CSI C Cursor Right + CSI D Cursor Left + CSI H Cursor to position. + CSI J Screen area clear (SCO honours attributes) + CSI K Line area clear (SCO honours attributes) + CSI m Attributes (See detail) + CSI s Save cursor position + CSI u Restore cursor position + + SCO ANSI CSI codes + + CSI @ Insert chars + CSI E Col 0, Cursor Down + CSI F Col 0, Cursor Up + CSI H Cursor to (r,c) position. + CSI L Insert lines + CSI M Delete lines + CSI P Delete characters + CSI S Scroll up (XXX) + CSI T Scroll Down (XXX) + CSI X Clear characters + CSI Z Back tab + CSI a Cursor Right + CSI e Col 0, Cursor Down + CSI f Cursor to (r,c) position. + CSI g Write Specific font char (AM mode always = 0, font always Raw) + CSI =B Beep type + CSI =C Cursor type + CSI =E Background bold or blink. + CSI =F Default foreground colour (NB Colour is in IBM VGA order) + CSI =G Default background colour (NB Colour is in IBM VGA order) + CSI =H Reverse foreground colour (NB Colour is in IBM VGA order) + CSI =I Reverse background colour (NB Colour is in IBM VGA order) + CSI =J Graphic foreground colour (NB Colour is in IBM VGA order) + CSI =K Graphic background colour (NB Colour is in IBM VGA order) + + Additional ANSI CSI codes + + CSI } Page flipping & Macros. + CSI ?lh Set/reset mode (am if arg == 7) + CSI i Printer control. + DCS $| Message line (DCS code) + + DCS for full setup (Keyboard, font, am, zapmsg, default attrs) + - (This page or all pages and default) + + CSI&DCS for open/read/write/close file. + CSI for inquire session hash key. + + Dangerous codes to have 4 digit PIN number (generated for session) + + + VT 52 codes - (Not implemented) + + if c in "ABCDHJK" do_ansi of same code. + if c == Y -> cursor position. + if c == I -> ^[M + if c == Z -> xmits("\033\\Z") or something + + if c == .. -> Add attribute and charset extras. + + +***************************************************************************** + +*****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LINUX_DEFAULTS + +#define RS8250 /* Hardware RS-232 driver */ +#define BEEPER /* Interrupt driven beeper */ +#define MEM_SCR /* Use Hardware screen memory */ +#define KBDRTS /* Flow control on keyboard interrupt */ +#define AT_BIOS_KEY /* AT keyboard + DOSemu keymapping */ +#define SCO_KEYMAP /* Make keyboard look SCOish */ + +#define XFORKDOS /* Key to spawn shell */ +#define XPRINTER /* Almost useless but does (just) work */ +#define XZMODEM /* Beware DSZ has an 16bit for the speed! */ +#define XAVATAR /* Decode dos 'AVATAR' screen codes */ + +#ifdef MEM_SCR /* All the following are possible only if MEM_SCR is set */ + +#define SCO_ANSI /* Decode SCO ansi control codes. */ +#define MAXPAGE 10 /* Multiple screens */ +#define SAVEBLOCK 3072 /* Screen macros */ +#define XSCO_REMAP /* Allow SCO key remap functions (!AT_BIOS_KEY) */ + +#define XTSRPROG /* Currently only works with MSC 5.1 */ +#define XAVATAR_PLUS /* More avatar functions */ +#endif + +/* Old or non-working stuff */ +#define XOLDBEEPER +#define XFLDATTR + +#if defined(__STDC__) || defined(__BORLANDC__) +#define _(x) x +#else +#define _(x) () +#endif + +#ifdef OLDBEEPER +int duration = 0x800; +int freq = 0x1000; +int warble = 1; + +int soundval = -1; +int soundcnt = -1; +int soundfreq= -1; +int sounddir = -1; +#endif +#ifdef BEEPER +int duration = 5; +int freq = 0x600; +int lastfreq; + +int soundval = -1; +int soundcnt = -1; + +#define TIMER 0x1C +void ( interrupt far *orig_timer_int)(); +void interrupt far timer_int(); +#endif + +#ifdef KBDRTS +#define KBDINT 0x09 +void ( interrupt far *orig_kbd_int) _((void)); +void interrupt far kbd_int _((void)); +#endif + +#ifdef PRINTER +int in_transprt = 0; +int print_dev = 0; +#endif + +#define FALSE 0 +#define TRUE !FALSE + +#define RS232 0x14 +#define INITRS 0 +#define WRITECH 1 +#define READCH 2 +#define STATUS 3 +#define FOSINIT 4 + +#define DTARDY 0x100 +#define ZFLAG 0x40 + +#define CHAROUT 2 +#define CHARIN 6 + +#ifdef AT_BIOS_KEY +#define KEY_SPECIAL (int)0x8000 +#define KEY_PAD 0x4000 +#define KEY_OTHER 0x2000 +#define KEY_DIRECT 0x1000 +#define KEY_ALT 0x0800 +#define KEY_ALTGR 0x0400 +#define KEY_CTRL 0x0200 +#define KEY_SHIFT 0x0100 + +#define DOS_KEY (KEY_SPECIAL+KEY_ALT+'d') +#define EXITKEY (KEY_SPECIAL+KEY_SHIFT) +#define SYSLKEY (KEY_SPECIAL+KEY_SHIFT) + +int sysline_warn = 0; +#else +#define EXITKEY 0x2D00 +#define DOS_KEY 0x2000 +#define SYSLKEY 0x1F00 +#endif + +void main _((int argc, char ** argv)); +int keybd _((void)); +int xmit _((int ch)); +void putstr _((char * str)); +void init_vid _((void)); +int test_svga_mode _((void)); +void end_vid _((void)); +void putscrn _((int c)); + +void init_beep _((void)); +void beep_on _((void)); +void sounder _((void)); +void beep_set _((int f, int p)); +void clear_beep _((void)); + +#ifdef MEM_SCR +void putansi _((int c)); +void litput _((int c)); +void rawput _((int c)); +void set_pos _((int line, int col)); +void update_page _((void)); +void updateline _((int to)); +void fetch_page _((void)); +void fetch_line _((int from)); +void do_ansi _((int cmd, int subcmd, int * args, int argc)); +void scroll _((int from, int to, int lines)); +void clrline _((int to)); +int reset_page _((void)); +void clr_eol _((void)); +void clr_sol _((void)); +void delch _((int chars)); +void inch _((int chars)); +void zapch _((int chars)); +void set_blink _((int flg)); +void move_cur _((int row, int col)); +void set_curtype _((int a, int top, int bot)); +#endif +#ifdef SAVEBLOCK +void read_block _((int blk)); +void save_block _((int blk)); +#endif + +void setup _((int port, int flags)); +void clearup _((void)); +void do_xmit _((void)); +void serial _((void)); + +#ifndef RS8250 +int chrdy _((void)); +#else +int get_c _((void)); +void chfetch _((void)); +void setints _((void)); +void clrints _((void)); +void rtsflow _((int stop)); +void init_kbd _((void)); +void clear_kbd _((void)); +#endif + +int get_key _((void)); +void write_scan _((int scan)); +void write_dosemu _((int ch)); +void write_unix _((int ch)); + +/*xYx*/ +void message(); + +int isfossil = 0; +int fossilfunc = 0; +int mnp_fossil = 0; + +int mask = 0xFF; + +union REGS iregs, oregs; + +int nsize = 0; +char empty[4096]; +#define full (empty+sizeof(empty)) +char * putptr = empty; +char * getptr = empty; + +char xmit_buf[512]; +char *xmit_put=xmit_buf, *xmit_get=xmit_buf; + +/***************************************************************************/ + +#ifdef MEM_SCR + +#define intvid(reg) int86(0x10, ®, ®) +#ifndef MAXPAGE +#define MAXPAGE 1 +#endif + +int page_no; +int dos_cur; +int dos_mode; +int dos_line; +int dos_col; +int line_len; +int scr_len; +int is_ega_plus; + +struct physical_scr +{ + int far * scrptr; + int dumb ; + int this_page ; + int line; + int col; +} + phy_scr; + +struct page_descr +{ + int ** lines; + int col; + int line; + int charflip; + int chartran; + int attr; + int dirtypg; + int * dirty; + + int * page; + int scol, sline; + int std_col; + int rev_col; + int gr_col; + int clr_col; + +#ifdef AT_BIOS_KEY + int key_mode; /* 0 = Unix, 1 = dosemu */ +#endif +#ifdef SCO_ANSI + int am; /* 1 = can't use col 80, 2 = no autowrap */ +#endif + int honour_attr; /* Area clears honour attribute */ + int reset_done; +} + pages[MAXPAGE]; + +#if MAXPAGE == 1 +#define curpage pages +#else +struct page_descr * curpage = pages; +#endif + +int args[10]; +int argc; +int tchar; +int echar; + +char dcs[256], *dcs_ptr; + +int sysline[80]; +int syslineno = -1; +int syslinetmp = 0; +int syslinedirty = 0; +int syslineold = -1; + +#endif + +/***************************************************************************/ + +#ifdef SCO_REMAP +extern int kbtab[]; +extern int keyxlate[]; +#define KEYTABSIZE 64 +#endif + +#ifdef SAVEBLOCK + +#define max_blk 100 + +int save_flag = 0; +int read_flag = 0; +char save_buf[SAVEBLOCK]; +char * save_ptr; +char * blocks[max_blk]; + +#endif + +/***************************************************************************/ + +#ifdef TSRPROG +#define TSR 0x31 +#define KEYBD 0x16 +#define OLDKB 0x65 + +void ( interrupt far *orig_key_int)(); +void interrupt far key_int(); +int tsrflag = 0; +char far * dos_screen; + +#ifndef __BORLANDC__ +extern +struct irq_stack +{ + int es; + int ds; + int di; + int si; + int bp; + int sp; + int bx; + int dx; + int cx; + int ax; + int pc; + int cs; + int flgs; +} far * sp_save; +#endif + +#endif + +/***************************************************************************/ + +long speeds[] = { 110, 150, 300, 600, + 1200, 2400, 4800, 9600, +#ifdef RS8250 + 19200, 38400, 115200, 57600, + 28800, 23040, 14400, 75, + 50, 134, 200, 1800, +#endif + 0 }; + +/*************************************************************************** + * Main, here we go + */ +void main(argc, argv) +int argc; +char ** argv; +{ + int ar; +#if defined(RS8250) && defined(LINUX_DEFAULTS) + int speed = 0x143; /* 115200, np, 1s, 8b */ +#else + int speed = 0xE3; /* 9600, np, 1s, 8b */ +#endif + int port = 0; + + signal(SIGINT, SIG_IGN); /* Ignore ^C */ + + init_vid(); + + for(ar=1; ar 3 || port < 0 || argv[ar][2] != '\0' ) + { + printf("Illegal Port number\n"); + exit(1); + } + } + else + { + printf("Illegal argument\n"); + exit(1); + } + } + +#ifdef TSRPROG + tsrinit(); +#endif + + setup(port, speed); + +#ifdef KBDRTS + init_kbd(); +#endif +#ifdef BEEPER + init_beep(); +#endif + +#ifdef MEM_SCR + fetch_page(); + for(ar=0; ar<80; ar++) sysline[ar] = 0x7020; +#endif + + putstr("Terminal emulator.\r\n"); + + if( isfossil && mnp_fossil ) + putstr("Fossil communications driver with MNP support found\r\n"); + else if( isfossil ) + putstr("Fossil communications driver found\r\n"); + putstr("Connected\r\n"); + + while(keybd()) + { +#ifdef OLDBEEPER + sounder(); +#endif + serial(); + } + +#ifdef OLDBEEPER + clear_beep(); +#endif +#ifdef TSRPROG + tsrexit(0); +#endif +#ifdef BEEPER + clear_beep(); +#endif +#ifdef KBDRTS + clear_kbd(); +#endif + clearup(); + end_vid(); + exit(0); +} + +/***************************************************************************/ + +#ifdef TSRPROG + +/*************************************************************************** + * Check the tsr isn't already running and install our IRQ handler. + */ +tsrinit() +{ + orig_key_int = _dos_getvect(OLDKB); + + if( orig_key_int != 0 ) + { + printf("ALREADY RUNNING USE HOTKEY\n"); + exit(0); + } + + if( tsrflag ) + { + save_stack(100); + + orig_key_int = _dos_getvect(KEYBD); + _dos_setvect(OLDKB, orig_key_int); + + dos_screen = (char far *) malloc(line_len*scr_len*2); + movedata( FP_SEG(phy_scr.scrptr), FP_OFF(phy_scr.scrptr), + FP_SEG(dos_screen), FP_OFF(dos_screen), + scr_len*line_len*2); + } +} + +/*************************************************************************** + * Actually go TSR. + */ +tsrexit(rtn) +int rtn; +{ + extern unsigned int _psp; + extern unsigned int _abrktb, _asizds, _atopsp, _abrkp; + unsigned int pgmsz; + struct SREGS srg; + + if( tsrflag ) + { + int i; + + movedata( FP_SEG(dos_screen), FP_OFF(dos_screen), + FP_SEG(phy_scr.scrptr), FP_OFF(phy_scr.scrptr), + scr_len*line_len*2); + move_cur(dos_line, dos_col); + + _dos_setvect(KEYBD, key_int); + + /* pgmsz Should be Data seg size + DS - PSP */ + segread(&srg); + pgmsz = (_asizds>>4); + pgmsz += 1; + pgmsz += srg.ds; + pgmsz -= _psp; + + _dos_keep(rtn, pgmsz); + } + /* Not tsring return */ +} + +/*************************************************************************** + * Check for keycodes to bring TSR in and out + */ +void interrupt far key_int() +{ +static int c; +static union REGS regs; +static int flg = 0; + + set_stack(); + c = (((sp_save->ax)>>8) & 0xFF); + if( c == 0 || c == 0x10 ) + { + regs.h.ah = c; + int86(OLDKB, ®s, ®s); + c = regs.x.ax; + sp_save->ax = c; + + if( flg == 0 && c == EXITKEY ) + { + flg=1; + _enable(); + do_looper(); + _disable(); + flg=0; + } + unset_stack(); + } + else + { + unset_stack(); + _chain_intr(orig_key_int); + } +} + +/*************************************************************************** + * This is the routine to run the TSR terminal in the foreground. + */ +do_looper() +{ + int c; + union REGS regs; + + regs.h.ah = 3; regs.h.bh = page_no; intvid(regs); + dos_line = regs.h.dh; + dos_col = regs.h.dl; + movedata( FP_SEG(phy_scr.scrptr), FP_OFF(phy_scr.scrptr), + FP_SEG(dos_screen), FP_OFF(dos_screen), + scr_len*line_len*2); + + curpage->dirtypg = 1; /* Whole screen will be updated 'soon' */ + phy_scr.line = -1; /* Cursor probably isn't in the right place */ + + while(keybd()) + { +#ifdef OLDBEEPER + sounder(); +#endif + serial(); + } + +#ifdef BEEPER + soundcnt = -1; /* Turn off beep asap */ +#endif + + movedata( FP_SEG(dos_screen), FP_OFF(dos_screen), + FP_SEG(phy_scr.scrptr), FP_OFF(phy_scr.scrptr), + scr_len*line_len*2); + move_cur(dos_line, dos_col); +} + +#endif + +/*************************************************************************** + * Beeper routines, standard version + */ + +#ifdef BEEPER +void +init_beep() +{ + orig_timer_int = _dos_getvect(TIMER); + _dos_setvect(TIMER, timer_int); +} + +void +beep_on() +{ + _disable(); + if(soundval == -1 ) + { + soundval = inp(0x61); + lastfreq = freq; + } + else if( lastfreq > 128 ) + lastfreq = lastfreq/2; + else + lastfreq = freq; + outp(0x61, soundval|3); + outp(0x43, 0xb6); + outp(0x42, lastfreq&0xFF); + outp(0x42, (lastfreq>>8)&0xFF); + soundcnt = duration; + _enable(); +} + +void interrupt far timer_int() +{ + if(soundval != -1) + { + if(soundcnt <= 0) + { + outp(0x61, soundval); + soundval = -1; + } + soundcnt--; + } + _chain_intr(orig_timer_int); +} + +void +beep_set(f,p) +int f,p; +{ + freq = f; + duration = (p%100)*182/100+1; +} + +void +clear_beep() +{ + _dos_setvect(TIMER, orig_timer_int); + if( soundval != -1 ) + outp(0x61, soundval); +} +#endif + +/*************************************************************************** + * Beeper routines, older non-interrupt version. + */ +#ifdef OLDBEEPER +void +beep_on() +{ + if(soundval == -1 ) + soundval = inp(0x61); + outp(0x61, soundval|3); + outp(0x43, 0xb6); + outp(0x42, freq&0xFF); + outp(0x42, (freq>>8)&0xFF); + soundcnt = duration; + soundfreq= freq; + sounddir = -warble; +} + +void +sounder() +{ + if( soundcnt > 0 ) + { + soundcnt--; + outp(0x42, soundfreq&0xFF); + outp(0x42, (soundfreq>>8)&0xFF); + soundfreq += sounddir; + if( soundfreq < freq-500 || soundfreq > freq ) + sounddir = -sounddir; + } + else if( soundcnt == 0 ) + { + soundcnt--; + outp(0x61, soundval); + soundval = -1; + sounddir = -warble; + } +} + +void +beep_set(f,p) +int f,p; +{ + freq = f; + duration = (p%100+1)*700; + if( p > 99 ) warble=1; + else warble = 0; +} + +void +clear_beep() +{ + if( soundval != -1 ) + outp(0x61, soundval); +} +#endif + +/*************************************************************************** + * Fetch a key and forward it to the serial port. + * While doing this look for the EXIT key and return FALSE if it is pressed + */ + +int +keybd() +{ + int c; + if( (c=get_key()) == -1 ) return TRUE; +#if SYSLKEY == EXITKEY + if( sysline_warn && (c&0xFF) == '\033' ) + return FALSE; +#else + if( c == EXITKEY ) + return FALSE; +#endif +#ifdef FORKDOS +#ifdef TSRPROG + else if(c == DOS_KEY && !tsrflag) +#else + else if(c == DOS_KEY) +#endif + { + int err; + char * cmd = getenv("COMSPEC"); + if( !cmd || !*cmd ) cmd = "command"; + err = spawnlp(P_WAIT, cmd, "command.com", NULL); + fetch_page(); + if( err == -1 ) + message("Error trying to run command.com"); + curpage->dirtypg = 1; + return TRUE; + } +#endif +#ifdef MEM_SCR + else if( c == SYSLKEY ) + { +#if SYSLKEY == EXITKEY + if(syslineno < 0 || syslineno >= scr_len) + { + syslineno = 0; + message("Press Escape to exit terminal emulator"); + sysline_warn = 1; + } + else + { + syslineno = -1; + sysline_warn = 0; + } +#else + if(syslineno < 0 || syslineno >= scr_len) + syslineno = 0; + else + syslineno = -1; +#endif + } +#endif +#ifdef AT_BIOS_KEY + else switch(curpage->key_mode) + { + default: write_unix(c); break; + case 1: write_dosemu(c); break; + case 2: write_scan(c); break; + } +#else +#ifdef SCO_KEYMAP + else if( bios_keymap(c) ) + ; +#endif + else if( c&0xFF ) + xmit(c & mask); + else + { + xmit(0); + xmit((c>>8)&mask); + } +#endif + return TRUE; +} + +int +xmit(ch) +int ch; +{ + if( xmit_put >= xmit_buf+sizeof(xmit_buf) && xmit_get != xmit_buf ) + { + int count = xmit_put-xmit_get; + memcpy(xmit_buf, xmit_get, count); + count = xmit_get - xmit_buf; + xmit_put -= count; + xmit_get -= count; + } + + if( xmit_put >= xmit_buf+sizeof(xmit_buf) ) + return -1; + + *xmit_put++ = ch; + + do_xmit(); + return 0; +} + +/*************************************************************************** + * Simple routine to forward output to LPT1 or the print device set as the + * second argument of the ' [ 5 ; i' + */ +#ifdef PRINTER +putprnt(ch) +{ +union REGS prt_regs; + + if( in_transprt ) + { + switch(in_transprt) + { + case 2: if( ch == '[' ) { in_transprt++; return; } + in_transprt = 0; + putprnt('\033'); break; + case 3: if( ch == '4' ) { in_transprt++; return; } + in_transprt = 0; + putprnt('\033'); putprnt('['); break; + case 4: if( ch == 'i' ) { in_transprt=0; return; } + in_transprt = 0; + putprnt('\033'); putprnt('['); putprnt('4'); break; + } + in_transprt = 1; + if( ch == '\033' ) { in_transprt++; return; } + } + + prt_regs.x.ax = 0x0200; + prt_regs.x.dx = print_dev; + int86(0x17, &prt_regs, &prt_regs); + if( ( prt_regs.x.ax & 0x2A00 ) != 0 ) + { + message("Printer Not Ready ... Please correct"); + return; + } + prt_regs.x.ax = ch; + prt_regs.x.dx = print_dev; + int86(0x17, &prt_regs, &prt_regs); +} +#endif + +/*************************************************************************** + * Quick routine to print a string to the screen. + */ +void +putstr(str) +char * str; +{ + while(*str) + putscrn(*str++); +} + + +#ifndef MEM_SCR + +/*************************************************************************** + * Dummy init and end for BIOS screen. + */ +void init_vid() { } +void end_vid() { } + +/*************************************************************************** + * BIOS screen message line; just print the text + */ +void +message(str, val1, val2) +char * str; +int val1, val2; +{ + static char buf[128]; + char * p; + int i=0; + + sprintf(buf, str, val1, val2); + strcat(buf, "\r\n"); + + putstr(buf); +} + +/*************************************************************************** + * BIOS screen put char. + */ +void +putscrn(c) +int c; +{ +#ifdef ZMODEM +static lastchar = ' '; +#endif +#ifdef AVATAR + extern int avcnt; + if( avcnt > 0 || ( avcnt == 0 && ( c == '\026' || c == '\031'))) + { + do_avatar(c); + return; + } + if( c == '\f' ) + { + putstr("\033[2J"); + return; + } +#endif +#ifdef OLDBEEPER + if( c == '\007' ) + { + beep_on(); + return; + } +#endif /* OLDBEEPER */ +#ifdef BEEPER + if( c == '\007' ) + { + beep_on(); + return; + } +#endif /* BEEPER */ +#ifdef ZMODEM + else if( c == 24 && lastchar == '*' ) /* CTRL-X */ + { +#ifdef TSRPROG + if( !tsrflag ) +#endif + system("dsz d handshake slow rz -rr"); + } + + lastchar = c; +#endif + + if( (c&-32)==0 + && c != '\r' + && c != '\n' + && c != '\b' + && c != '\007' + ) return; + + iregs.h.ah = CHAROUT; + iregs.h.dl = c; + intdos(&iregs, &oregs); +} + +#else + +/*************************************************************************** + * Hardware screen, message line is mobile between TOS and BOS. + */ +void +message(str, val1, val2) +char * str; +int val1, val2; +{ + static char buf[128]; + int i; + int flg=0; + + memset(buf, '\0', sizeof(buf)); + sprintf(buf, str, val1, val2); + + for(i=0; i<80; i++) + { + if( buf[i] == '\0' ) + { + if( sysline[i] == 0x7000 ) + break; + else + sysline[i] = 0x7000; + } + else + { + if( flg == 1 || buf[i] != ' ' ) + sysline[i] = buf[i]|(0x7000); + else + sysline[i] = 0x7000; + if( buf[i] != ' ' ) flg = 1; + } + } + syslinedirty = 1; + if( syslineno == -1 ) syslinetmp = 1; +#if SYSLKEY == EXITKEY + sysline_warn = 0; +#endif +} + +/*************************************************************************** + * Hardware screen, print character. + */ +void +putscrn(c) +int c; +{ +#ifdef AVATAR + extern int avcnt; +#endif +#ifdef ZMODEM +static lastchar = ' '; +#endif + +#ifdef SAVEBLOCK + if( save_flag && c != '\0' ) + { + *save_ptr++ = c; + if( save_ptr >= save_buf+sizeof(save_buf) ) save_ptr = save_buf; + } +#endif + + if(0); +#ifdef AVATAR + else if( avcnt > 0 || ( avcnt == 0 && ( c == '\026' || c == '\031'))) + do_avatar(c); +#endif +#ifdef ZMODEM + else if( c == 24 && lastchar == '*' ) /* CTRL-X */ + { +#ifdef TSRPROG + if( !tsrflag ) +#endif + { + system("dsz d handshake slow rz -rr"); + fetch_page(); + curpage->dirtypg = 1; + } + } +#endif + else + putansi(c); + +#ifdef ZMODEM + lastchar = c; +#endif + +#ifdef SAVEBLOCK + if( read_flag == 0 ) +#endif + { +static int cnt = 1000; + if( c == '\n' ) cnt -= 80; + if( --cnt < 0 ) + { + cnt=1000; + update_page(); + } + } +} + +/*************************************************************************** + * Hardware screen, decode ansi sequence. + */ +void +putansi(c) +int c; +{ +static int ansi_state=0; + int i; + c &= 0xFF; + + if( ansi_state <= 3 ) switch ( c ) + { + case '\t': i = (8 - (curpage->col&7) ); + curpage->col += i; + if( curpage->col > line_len ) + curpage->col = line_len; + return; + + case '\r': curpage->col = 0; + return; + + case '\b': if( curpage->col ) + curpage->col--; + return; + + case '\n': curpage->line++; + if( curpage->line == scr_len ) scroll(0, scr_len-1, 1); + return; + +#if defined(SCO_ANSI) || defined(AVATAR) + case '\f': scroll( scr_len-1, 0, scr_len); + curpage->line=0; + curpage->col=0; + return; +#endif + +#ifdef OLDBEEPER + case '\007':beep_on(); + return; +#endif /* OLDBEEPER */ +#ifdef BEEPER + case '\007':beep_on(); + return; +#endif /* BEEPER */ + + case '\030':ansi_state = 0; /* Ctrl-X */ + return; + + case '\032':ansi_state = 0; /* Ctrl-Z */ + rawput(0xA8); + return; + + case '\033':if( phy_scr.dumb == 0 ) + { + ansi_state = 1; + + for(argc=0; argc<10; argc++) args[argc] = 0; + argc = 0; + tchar = 0; + echar = 0; + + return; + } + /*FALLTHROUGH*/ + } + + switch(ansi_state) + { + default:ansi_state =0; + + case 0: if( c < ' ' && phy_scr.dumb == 0 ) break; + litput(c); + break; + + case 1: switch(c) + { + case '\\': /* NO-OP if not in DCS string */ + ansi_state = 0; + break; + case 'P': + dcs_ptr = dcs; + ansi_state = 2; + break; + case '[': + dcs_ptr = 0; + ansi_state = 2; + break; + case '(': + ansi_state = 8; + break; + case '7': + curpage->sline = curpage->line; + curpage->scol = curpage->col; + ansi_state = 0; + break; + case '8': + set_pos(curpage->sline, curpage->scol); + ansi_state = 0; + break; +#ifdef AT_BIOS_KEY + case '>': + curpage->key_mode = 0; + ansi_state = 0; + break; + case '=': + curpage->key_mode = 1; + ansi_state = 0; + break; + case '<': + curpage->key_mode = 2; + ansi_state = 0; + break; +#endif +#ifdef SCO_REMAP + case 'Q': + ansi_state = 10; + break; +#endif + default: + ansi_state = 0; + rawput('\033'); + rawput(c); + break; + } + break; + + case 2: if(( c >= ' ' && c < '0' ) || c == ':' || ( c > ';' && c <= '?' )) + { + tchar = c; + ansi_state = 3; + break; + } + case 3: if( c >= '0' && c <= '9' ) + { + args[argc] = args[argc]*10 + c - '0'; + break; + } + else if(c == ';' ) + { + if( ++argc >= 10 ) + { + ansi_state = 0; + break; + } + args[argc] = 0; + break; + } + else if( c >= '@' && c <= '~' ) + { + echar = c; + if( dcs_ptr == 0 ) + { + ansi_state = 0; + do_ansi( echar, tchar, args, argc+1 ); + } + else + { + ansi_state = 4; + break; + } + } + ansi_state = 0; + break; + + /* DCS ... ST processing */ + case 4: if( c == '\030' || dcs_ptr >= dcs+sizeof(dcs)-1 ) + ansi_state = 0; + else if( c == '\033' ) + ansi_state = 5; + else + *dcs_ptr++ = c; + break; + + case 5: if( c != '\\' ) + { + if( dcs_ptr >= dcs+sizeof(dcs)-2 || c == '\030' ) + ansi_state = 0; + else + { + *dcs_ptr++ = '\033'; + if( c != '\033' ) { *dcs_ptr++ = c; ansi_state = 4; } + } + break; + } + *dcs_ptr = '\0'; + ansi_state = 0; + + if( tchar == '$' && echar == '~' ) + { + dcs[80] = 0; + if( *dcs ) message("%s", dcs); + else + { + syslineno = -1; + sysline_warn = 0; + } + } + break; + + /* ESC ( Screen language processing */ + case 8: ansi_state =0; + switch(c) + { + case 'X': curpage->chartran = 0; break; + case 'B': curpage->chartran = 1; break; + case '0': curpage->chartran = 2; break; + case 'A': curpage->chartran = 3; break; + + case 'U': curpage->chartran = 0; break; + case 'u': curpage->chartran = 4; break; + + default: curpage->chartran = -1; break; + } + break; + + /* SCO Function key remapping */ +#ifdef SCO_REMAP + case 10: echar = c-'0'; /* FUNCTION KEY NUMBER 0=F1 .. 9=F10 */ + message("Define function key %d", echar+1); + ansi_state = 11; + break; + + case 11: tchar = c; + ansi_state = 12; + break; + + case 12: if( c == tchar ) ansi_state = 0; + if( echar >=0 && echar < KEYTABSIZE ) + { + if( c == tchar ) + { + set_key(echar); + kbtab[keyxlate[echar]] = (0x300|echar); + } + else if( c != '^' ) + add_fnchar(c); + else + ansi_state = 13; + } + break; + case 13: if( c == tchar ) ansi_state = 0; else ansi_state = 12; + if( echar >=0 && echar < KEYTABSIZE ) + { + if( c == tchar ) + { + set_key(echar); + kbtab[keyxlate[echar]] = (0x300|echar); + } + else if( c != '^' ) + add_fnchar(c& 0x1F); + else + add_fnchar(c); + } + break; +#endif + + } +} + +/*************************************************************************** + * Hardware screen, Write any byte to screen through the translation table. + */ + +unsigned char iso8859_1[] = { + 4, 177, -1, -1, -1, -1, 248, 241, 176, -1, 217, 191, 218, 192, 197, -1, + -1, 196, -1, 95, 195, 180, 193, 194, 179, 243, 242, 227, -1, 156, 250, -1, + +255, 173, 155, 156, 9, 157, 124, 21, 34, 67, 166, 174, 170, 45, 82, 196, +248, 241, 253, 51, 39, 230, 20, 250, 44, 49, 167, 175, 172, 171, 51, 168, + 65, 65, 65, 65, 142, 143, 146, 128, 69, 144, 69, 69, 73, 73, 73, 73, + 68, 165, 79, 79, 79, 79, 153, 120, 237, 85, 85, 85, 154, 89, 80, 225, +133, 160, 131, 97, 132, 134, 145, 135, 138, 130, 136, 137, 141, 161, 140, 139, + 11, 164, 149, 162, 147, 111, 148, 246, 237, 151, 163, 150, 129, 121, 112, 152 +}; +/* Yes I know, a good compiler should complain about that array */ + +void +litput(c) +int c; +{ + c &= 0xFF; + if( curpage->charflip ) c ^= 0x80; + if( curpage->chartran ) switch( curpage->chartran ) + { + case 1: + if( (c&0x80) ) + { + if( c&0x60 ) c = iso8859_1[c&0x7F]; + else c &= 0x1F; + } + break; + case 2: + if( c >= 0x60 && c < 0x80 ) c = iso8859_1[c&0x1F]; + break; + case 3: + if( c == '#' ) { c = 156; break; } + c &= 0x7F; + default: + if( c < ' ' || c > '~' ) c = -1; + break; + + case 4: + c &= 0x7F; + break; + } + rawput(c); +} + +void +rawput(c) +int c; +{ + c &= 0xFF; + if( curpage->col >= line_len ) + { + curpage->line++; + curpage->col=0; + if( curpage->line == scr_len ) scroll(0, scr_len-1, 1); + } + curpage->lines[curpage->line][curpage->col] = c + (curpage->attr<<8); + curpage->dirty[curpage->line] = 1; + curpage->col++; +#ifdef SCO_ANSI + if( curpage->am && curpage->col == line_len ) + { + if( curpage->am & 2 ) + curpage->col--; + else + { + curpage->line++; curpage->col=0; + } + if( ( curpage->am & 1 ) && curpage->line == scr_len ) + scroll(0, scr_len-1, 1); + } +#endif +} + +/*************************************************************************** + * Hardware screen, Set the virtual cursor position. + */ +void +set_pos(line, col) +int line; +int col; +{ + curpage->line = line; + curpage->col = col; + if( curpage->line < 0 ) curpage->line = 0; + if( curpage->line >= scr_len ) curpage->line = scr_len-1; + if( curpage->col < 0 ) curpage->col = 0; + if( curpage->col >=line_len ) curpage->col = line_len-1; +} + +/*************************************************************************** + * Hardware screen, Write screen image to physical screen. + */ +void +update_page() +{ + int i; + + if( curpage->col != phy_scr.col || curpage->line != phy_scr.line ) + { + int c; + phy_scr.col = curpage->col; + phy_scr.line = curpage->line; + + if( curpage->col == line_len ) + c = line_len-1; + else + c = curpage->col; + move_cur(curpage->line, c); + } + + if( syslineno == curpage->line ) + syslineno = scr_len -1 -syslineno; + + if( curpage->dirtypg ) + { + syslineold = syslineno; + syslinedirty = 0; + } + + if( syslinetmp && syslineold == -1 ) + { + if( curpage->line == 0 ) + syslineno = scr_len-1; + else + syslineno = 0; + syslineold = syslineno; + } + + if( syslineold != syslineno ) + { + if( syslinetmp ) + { + syslinetmp = 0; + syslineno = -1; + } + if( syslineold != -1 ) + curpage->dirty[syslineold] = 1; + if( syslineno != -1 ) + syslinedirty = 1; + syslineold = syslineno; + } + + for(i=0; idirtypg || curpage->dirty[i] ) + { +#ifdef FLDATTR + copyattr(i); +#endif + updateline(i); + } + + if( syslineno != -1 && syslinedirty ) + updateline(syslineno); + curpage->dirtypg = 0; +} + +#ifdef FLDATTR +copyattr(lno) +int lno; +{ +int i; +int lastattr = -1; + + for(i=0; ilines[lno][i]&0xFF) == 0xFF) + lastattr = (curpage->lines[lno][i]&0xFF00); + if( lastattr != -1 ) + curpage->lines[lno][i] = ((curpage->lines[lno][i]&0xFF)|lastattr); + } +} +#endif + +void +updateline(to) +int to; +{ + int ll = line_len*2; + char far * ptr; + + curpage->dirty[to] = 0; + if( to == syslineno ) + { + ptr = (char far *) sysline; + syslinedirty = 0; + } + else + ptr = (char far *)(curpage->lines[to]); + movedata(FP_SEG(ptr), FP_OFF(ptr), + FP_SEG(phy_scr.scrptr), ll*to, + ll); +} + +/*************************************************************************** + * Hardware screen, Fetch physical screen into image memory. + */ +void +fetch_page() +{ + int i; + + iregs.h.ah = 3; + iregs.h.bh = page_no; + intvid(iregs); + curpage->line = iregs.h.dh; + curpage->col = iregs.h.dl; + + for(i=0; ilines[from]); + movedata(FP_SEG(phy_scr.scrptr), ll*from, + FP_SEG(ptr), FP_OFF(ptr), + ll); +} + +/*************************************************************************** + * Hardware screen, apply an ansi sequence to the current screen image. + */ +void +do_ansi( cmd, subcmd, args, argc ) +int cmd; +int subcmd; +int * args; +int argc; +{ + int ar; +static int colconv[] = { 000, 004, 002, 006, 001, 005, 003, 007, + 010, 014, 012, 016, 011, 015, 013, 017 }; + switch( subcmd ) + { + case 0: switch( cmd ) + { +#ifdef SCO_ANSI + case '@': inch(args[0]); + break; +#endif + case 'A': if( args[0] < 1 ) args[0] = 1; + set_pos(curpage->line-args[0], curpage->col); + break; +#ifdef SCO_ANSI + case 'E': curpage->col = 0; + /* FALLTHROUGH */ + case 'e': +#endif + case 'B': if( args[0] < 1 ) args[0] = 1; + set_pos(curpage->line+args[0], curpage->col); + break; +#ifdef SCO_ANSI + case 'a': +#endif + case 'C': if( args[0] < 1 ) args[0] = 1; + curpage->col += args[0]; + if( curpage->col >= line_len ) + curpage->col = line_len -1; + break; + case 'D': if( args[0] < 1) args[0] = 1; + curpage->col -= args[0]; + if( curpage->col < 0 ) + curpage->col = 0; + break; +#ifdef SCO_ANSI + case 'F': if( args[0] < 1 ) args[0] = 1; + set_pos(curpage->line-args[0], 0); + break; +#endif + case 'f': + case 'H': set_pos(args[0]-1, args[1]-1); + break; + case 'J': /* cls */ + if( args[0] == 2) + { + scroll( scr_len-1, 0, scr_len); + curpage->line=0; + curpage->col=0; + } + else if( args[0] == 0 ) + { + clr_eol(); + if( curpage->line != scr_len-1 ) + scroll( scr_len-1, curpage->line+1, scr_len); + } + else if( args[0] == 1 ) + { + clr_sol(); + if( curpage->line != 0 ) + scroll( curpage->line-1, 0, scr_len); + } + break; + case 'K': /* Clear eol */ + if(args[0] == 0 ) + clr_eol(); + else if(args[0] == 1 ) + clr_sol(); + else if(args[0] == 2 ) + clrline(curpage->line); + break; + +#ifdef SCO_ANSI + case 'L': scroll(scr_len-1, curpage->line, args[0]); + break; + + case 'M': scroll(curpage->line, scr_len-1, args[0]); + break; + + case 'P': delch(args[0]); + break; + + case 'S': scroll(0, scr_len-1, args[0]); + break; + + case 'T': scroll(scr_len-1, 0, args[0]); + break; + + case 'X': zapch(args[0]); + break; + + case 'Z': if( args[0] == 0 ) args[0] = 1; + set_pos(curpage->line,((curpage->col+7-8*(args[0]))&-8)); + break; +#endif +#ifdef PRINTER + case 'i': if( args[0] == 5 ) + { + if( args[1] > 0 && args[1] < 3 ) print_dev = args[1]; + else print_dev = 0; + in_transprt = 1; + } + break; +#endif + + case 'm': /* Attributes */ + for(ar=0; arattr = curpage->std_col; + break; + case 1: curpage->attr |= 0x08; + break; +#ifdef SCO_ANSI + case 2: if( dos_mode != 2 && dos_mode != 7 && ar+2std_col = colconv[args[ar+1]&0xF] + + (colconv[args[ar+2]&0xF] << 4); + curpage->attr = curpage->std_col; + if( args[ar+2]&0x8 ) + set_blink(0); + ar+=2; + } + break; + case 3: if( dos_mode != 2 && dos_mode != 7 && ar+1attr = ((curpage->attr & 0xF0)|0x01); + break; + case 5: curpage->attr |= 0x80; + set_blink(1); + break; + case 7: +#ifdef SCO_ANSI + if( dos_mode != 2 && dos_mode != 7 && ar+2rev_col = colconv[args[ar+1]&0xF] + + (colconv[args[ar+2]&0xF] << 4); + if( args[ar+2]&0x8 ) + set_blink(0); + ar+=2; + } +#endif + curpage->attr = curpage->rev_col; + break; + case 8: curpage->attr = 0; + break; +#ifdef SCO_ANSI + case 10:curpage->charflip = 0; + curpage->attr = curpage->std_col; + break; + case 12:curpage->charflip = 1; + curpage->attr = curpage->gr_col; + break; +#endif + case 30:case 31:case 32:case 33: + case 34:case 35:case 36:case 37: + if( dos_mode != 2 && dos_mode != 7 ) + curpage->attr = ((curpage->attr & 0xF8) + |(colconv[args[ar]-30])); + break; + case 40:case 41:case 42:case 43: + case 44:case 45:case 46:case 47: + if( dos_mode != 2 && dos_mode != 7 ) + curpage->attr + = ((curpage->attr & 0x8F) + |((colconv[args[ar]-40]&0x7)<<4)); + break; + } + if( curpage->honour_attr ) + curpage->clr_col = curpage->attr; + break; +#ifdef SCO_ANSI + case 'g': if( curpage->col == line_len ) + { + curpage->line++; + curpage->col=0; + if( curpage->line == scr_len ) + scroll(0, scr_len-1, 1); + } + curpage->lines[curpage->line][curpage->col] = + args[0] + (curpage->gr_col<<8); + curpage->dirty[curpage->line] = 1; + curpage->col++; + break; +#endif + case '}': +#if MAXPAGE != 1 + if( args[0] == 0 ) + { + args[1] %= MAXPAGE; + if( args[1] == phy_scr.this_page ) break; + if( pages[args[1]].page == 0 ) + { + phy_scr.this_page = args[1]; + curpage= pages+phy_scr.this_page; + if( reset_page() < 0 ) + phy_scr.this_page = 0; + } + else + { + phy_scr.this_page = args[1]; + curpage= pages+phy_scr.this_page; + curpage->dirtypg = 1; + } + curpage= pages+phy_scr.this_page; + } +#endif +#ifdef SAVEBLOCK + if(args[0] == 1) + { + if( read_flag ) break; + read_flag = 1; save_flag = 0; + read_block(args[1]); + read_flag = 0; + } + else if( args[0] == 2 && argc == 1 ) + { + if( read_flag ) break; + save_flag = 1; + save_ptr = save_buf; + } + else if( args[0] == 2) + { + if( read_flag ) break; + save_block(args[1]); + } +#endif + break; + case 's': + curpage->sline = curpage->line; + curpage->scol = curpage->col; + break; + case 'u': + set_pos(curpage->sline, curpage->scol); + break; + } + break; + +#ifdef SCO_ANSI + case '=': switch( cmd ) + { +#ifdef OLDBEEPER + case 'B': beep_set(args[0], args[1]); + break; +#endif +#ifdef BEEPER + case 'B': beep_set(args[0], args[1]); + break; +#endif + case 'C': /* set cursor (0=>norm, 1=>off, 2=>big, x;y=>setit */ + if( argc <= 1 ) set_curtype(args[0]-1,0,15); + if( argc == 2 ) set_curtype(2,args[0],args[1]); + break; + case 'E': /* set cursor */ + set_blink(args[0]); + break; + case 'F': if( dos_mode != 2 && dos_mode != 7 ) + curpage->std_col = ((curpage->std_col & 0xF0) + |(args[0]&0xF)); + break; + case 'G': if( dos_mode != 2 && dos_mode != 7 ) + curpage->std_col = ((curpage->std_col & 0x0F) + |((args[0]&0xF)<<4)); + break; + case 'H': if( dos_mode != 2 && dos_mode != 7 ) + curpage->rev_col = ((curpage->rev_col & 0xF0) + |(args[0]&0xF)); + break; + case 'I': if( dos_mode != 2 && dos_mode != 7 ) + curpage->rev_col = ((curpage->rev_col & 0x0F) + |((args[0]&0xF)<<4)); + break; + case 'J': if( dos_mode != 2 && dos_mode != 7 ) + curpage->gr_col = ((curpage->gr_col & 0xF0) + |(args[0]&0xF)); + break; + case 'K': if( dos_mode != 2 && dos_mode != 7 ) + curpage->gr_col = ((curpage->gr_col & 0x0F) + |((args[0]&0xF)<<4)); + break; + } + break; + + case '?': if( cmd == 'l' || cmd == 'h' ) + { + int flg = (cmd == 'h'); + switch(args[0]) + { + case 7: curpage->am = flg; break; + } + } + break; +#endif + } +} + +/*************************************************************************** + * Hardware screen, scroll a set of lines on the cur screen. + */ +void +scroll(from, to, lines) +int from, to, lines; +{ + int win, tomove, toclr, dir, line, c; + int * tmp; + + if( curpage->line == scr_len) curpage->line--; + if( lines <= 0 ) lines = 1; + + dir = 1; + if( from > to ) { dir = from ; from = to ; to = dir ; dir = -1 ;} + win = to-from+1; + if( lines > win ) lines = win; + tomove = win - lines; + toclr = lines; + + if( dir == 1 ) + { + for(line=from; tomove>0; tomove--, line++) + { + tmp = curpage->lines[line]; + curpage->lines[line] = curpage->lines[line+lines]; + curpage->lines[line+lines] = tmp; + curpage->dirty[line] = 1; + curpage->dirty[line+lines] = 1; + } + for(line=to; toclr>0; toclr--, line--) + { + clrline(line); + } + } + else + { + for(line=to; tomove>0; tomove--, line--) + { + tmp = curpage->lines[line]; + curpage->lines[line] = curpage->lines[line-lines]; + curpage->lines[line-lines] = tmp; + curpage->dirty[line] = 1; + curpage->dirty[line+lines] = 1; + } + for(line=from; toclr>0; toclr--, line++) + { + clrline(line); + } + } +} + +/*************************************************************************** + * Hardware screen, clear one line. + */ +void +clrline(to) +int to; +{ + int * toptr = curpage->lines[to]; + int chars = line_len; + int pattern = ' ' + (curpage->clr_col << 8 ); + + curpage->dirty[to] = 1; + + do + { + *toptr++ = pattern; + chars--; + } + while( chars ); +} + +/*************************************************************************** + * Hardware screen, clear one page, reset dynamic values. + */ +int +reset_page() +{ +static int *sys_page = 0, **sys_lines, *sys_dirty; + int i; + + if( sys_page == 0 ) + { + sys_page = (int*) malloc(scr_len*line_len*2); + sys_lines = (int**) malloc(scr_len*sizeof(int*)); + sys_dirty = (int*) malloc(scr_len*sizeof(int)); + if( sys_page == 0 || sys_lines == 0 || sys_dirty == 0 ) + return -1; + } + + if( !curpage->reset_done ) + { + curpage->charflip = 0; + curpage->chartran = 0; + curpage->attr = 0x07; + curpage->std_col = 0x07; + curpage->rev_col = 0x70; + curpage->gr_col = 0x07; + curpage->clr_col = 0x07; + curpage->line = 0; + curpage->col = 0; + curpage->dirtypg = 1; + +#ifdef AT_BIOS_KEY + curpage->key_mode = 0; +#endif + curpage->am = 1; + curpage->honour_attr = 1; + +#ifdef LINUX_DEFAULTS + curpage->honour_attr = 0; + curpage->chartran = 1; +#endif + curpage->reset_done = 1; + } + +#if MAXPAGE != 1 + if( pages[phy_scr.this_page].page == 0 + || pages[phy_scr.this_page].lines == 0 + || pages[phy_scr.this_page].dirty == 0 ) + { + pages[phy_scr.this_page].page = (int*) malloc(scr_len*line_len*2); + pages[phy_scr.this_page].lines = (int**) malloc(scr_len*sizeof(int*)); + pages[phy_scr.this_page].dirty = (int*) malloc(scr_len*sizeof(int)); + } +#endif + + /* Out of memory, use the default page */ + if( pages[phy_scr.this_page].page == 0 + || pages[phy_scr.this_page].lines == 0 + || pages[phy_scr.this_page].dirty == 0 ) + { + if(pages[phy_scr.this_page].page ) free(pages[phy_scr.this_page].page); + if(pages[phy_scr.this_page].lines) free(pages[phy_scr.this_page].lines); + if(pages[phy_scr.this_page].dirty) free(pages[phy_scr.this_page].dirty); + + for(i=0; iclr_col << 8 ); + int * toptr = curpage->lines[curpage->line]+curpage->col; + int x = curpage->col; + + curpage->dirty[curpage->line] = 1; + while( x < line_len ) + { + *toptr++ = pattern; + x++; + } +} + +/*************************************************************************** + * Hardware screen, clear to start of line + */ +void +clr_sol() +{ + int pattern = ' ' +(curpage->clr_col << 8 ); + int * toptr = curpage->lines[curpage->line]+curpage->col; + int x = curpage->col; + + curpage->dirty[curpage->line] = 1; + while( x >= 0 ) + { + *toptr-- = pattern; + x--; + } +} + +/*************************************************************************** + * Hardware screen, delete some characters. + */ +void +delch(chars) +int chars; +{ + int pattern = ' ' +(curpage->clr_col << 8 ); + int * toptr = curpage->lines[curpage->line]+curpage->col; + int x = curpage->col; + int last; + + curpage->dirty[curpage->line] = 1; + if( chars <=0 ) chars = 1; + last = line_len-chars; + + while( x < last ) + { + *toptr = toptr[chars]; + toptr++; x++; + } + + while( x < line_len ) + { + *toptr++ = pattern; + x++; + } +} + +#ifdef SCO_ANSI +/*************************************************************************** + * Hardware screen, insert some characters. + */ +void +inch(chars) +int chars; +{ + int pattern = ' ' +(curpage->attr << 8 ); + int * toptr = curpage->lines[curpage->line]+line_len-1; + int x = line_len-1; + int last; + + curpage->dirty[curpage->line] = 1; + if( chars <= 0 ) chars = 1; + + last = curpage->col+chars; + chars = -chars; + + while( x >= last ) + { + *toptr = toptr[chars]; + toptr--; x--; + } + + while( x >= curpage->col ) + { + *toptr-- = pattern; + x--; + } +} + +/*************************************************************************** + * Hardware screen, clear some characters. + */ +void +zapch(chars) +int chars; +{ + int pattern = ' ' +(curpage->clr_col << 8 ); + int * toptr = curpage->lines[curpage->line]+curpage->col; + int x = curpage->col; + int last; + + curpage->dirty[curpage->line] = 1; + if( chars <= 0 ) chars = 1; + + last = curpage->col+chars; + if( last > line_len ) last = line_len; + + while( x < last ) + { + *toptr++ = pattern; + x++; + } +} +#endif + +/*************************************************************************** + * Hardware screen, init video, detect physical screen size and location + * if it's in a graphic mode complain. + */ +void +init_vid() +{ + union REGS ioregs; + int phy_mode=0; + char *p; + + phy_scr.scrptr = (int far *) 0xB0000000; + phy_scr.dumb = 0; + phy_scr.line = -1; + phy_scr.col = -1; + + ioregs.x.ax = 0x0500; + intvid(ioregs); + + ioregs.h.ah = 15; + intvid(ioregs); + dos_mode = ioregs.h.al; + line_len = ioregs.h.ah; + page_no = ioregs.h.bh; + + ioregs.h.ah = 3; + ioregs.h.bh = page_no; + intvid(ioregs); + dos_cur = ioregs.x.cx; + dos_line = ioregs.h.dh; + dos_col = ioregs.h.dl; + + ioregs.x.ax = 0x1130; /* EGA bios info */ + ioregs.x.dx = 0; + ioregs.h.bh = 0; + intvid(ioregs); + if( ioregs.x.dx ) + { + is_ega_plus = 1; + scr_len = ioregs.x.dx+1; + + if( ioregs.x.cx < 13 ) + dos_cur = 0x0405; + else if( dos_mode == 7 ) + dos_cur = 0x0C0D; + else + dos_cur = 0x0607; + } + else + { + is_ega_plus = 0; + scr_len = 25; + } + + if( dos_mode == 7 ) + phy_mode=1; + else + if(dos_mode == 2 || dos_mode == 3) + { + phy_scr.scrptr = (int far * ) 0xB8000000; + phy_mode=1; + } + else if( dos_mode > 0x13 ) + phy_mode = test_svga_mode(); + + if( line_len < 80 ) + { + printf("Screen needs to be at least 80 cols\r\n"); + exit(0); + } + if(phy_mode==0) { printf("Unusable display mode\n"); exit(1); } + + phy_scr.this_page = 0; + if( reset_page() < 0 ) + { + printf("Memory failure, cannot allocate screen memory\n"); + exit(1); + } + + putscrn('\r'); + putscrn('\n'); + set_curtype(-1,0,0); + set_blink(1); +} + +/*************************************************************************** + * Hardware screen, test for an svga text mode. + */ +int +test_svga_mode() +{ + union REGS ioregs; + int ch; + + phy_scr.scrptr = (int far * ) 0xB8000000; + + ioregs.h.ah = 8; + ioregs.h.bh = page_no; + intvid(ioregs); + + ch = phy_scr.scrptr[dos_line*line_len+dos_col]; + if( ch != ioregs.x.ax ) return 0; + phy_scr.scrptr[dos_line*line_len+dos_col] = ~ch; + + ioregs.h.ah = 8; + ioregs.h.bh = page_no; + intvid(ioregs); + + phy_scr.scrptr[dos_line*line_len+dos_col] = ch; + if( ( ~ch ) != ioregs.x.ax ) return 0; + return 1; +} + +/*************************************************************************** + * Hardware screen, reset the physical screen back to normal. + */ +void end_vid() +{ + move_cur(scr_len-1, 0); + set_blink(1); + set_curtype(-1,0,0); +} + +/*************************************************************************** + * Hardware screen, set the screen blink mode (blink or bg bold). + */ +void +set_blink(flg) +int flg; +{ + union REGS regs; +static int last = -1; +static int first = 1; + +/* This takes far too long (~ 8ms ) on some bioses. + * It apparently waits for a screen retrace and even then it isn't reliable. + * Will have to go directly to the HW only problem is how to do it + */ + + if( !is_ega_plus ) return; + + flg = (flg != 0); + if( flg == last ) return; + + regs.h.ah = 0x10; + regs.h.al = 0x03; + regs.h.bl = last = flg; + + int86(0x10, ®s, ®s); + + if( first && flg == 0 ) /* Workaround on some EGA's */ + { + regs.h.ah = 0x06; + regs.h.al = 0x00; + regs.h.bh = 0x00; + regs.h.ch = 1; + regs.h.cl = 1; + regs.h.dh = 1; + regs.h.dl = 1; + int86(0x10, ®s, ®s); + curpage->dirty[1] = 1; + first = 0; + } +} + +/*************************************************************************** + * Hardware screen, set the physical cursor position. + */ +void +move_cur(row, col) +int row, col; +{ + union REGS ioregs; + ioregs.h.ah = 2; + ioregs.h.bh = page_no; + ioregs.h.dh = row; + ioregs.h.dl = col; + intvid(ioregs); +} + +/*************************************************************************** + * Hardware screen, set the physical cursor type. + */ +void +set_curtype(a,top,bot) +int a, top, bot; +{ + union REGS ioregs; + ioregs.h.ah = 1; + ioregs.x.cx = dos_cur; + if( a == 0 ) ioregs.h.ch = 0x10; + if( a == 1 ) ioregs.h.ch = 0; + if( a == 2 ) { ioregs.h.ch = top; ioregs.h.cl = bot; } + intvid(ioregs); +} + +#endif + +#ifdef SAVEBLOCK +/*************************************************************************** + * Routines to save a chunk of data for a screen macro. + */ + +void +read_block(blk) +int blk; +{ + char * p; + if( blk < 0 || blk > max_blk ) return; + + p = blocks[blk]; + if( p ) while( *p ) putscrn(*p++ & 0xFF); +} + +void +save_block(blk) +int blk; +{ + if( blk < 0 || blk > max_blk ) return; + if( save_flag == 0 ) return; + *save_ptr++ = '\0'; + if( blocks[blk] ) free(blocks[blk]); + blocks[blk] = malloc(save_ptr-save_buf); + if( blocks[blk] ) + strcpy(blocks[blk], save_buf); +} + +#endif + +#ifndef RS8250 +/*************************************************************************** + * BIOS serial routines, also fossil driver compatible. + */ + +int port_no; + +void +setup(port, flags) +int port, flags; +{ + int c; + port_no = port; + + iregs.h.ah = FOSINIT; + iregs.x.dx = port_no; + iregs.x.bx = 0; + int86(RS232, &iregs, &oregs); + if( oregs.x.ax == 0x1954 ) + { + if( oregs.h.bh >= 4 ) + { + isfossil = oregs.h.bh; + fossilfunc = oregs.h.bl; + } + } + + iregs.h.ah = INITRS; + iregs.x.dx = port_no; + iregs.h.al = flags; + + int86(RS232, &iregs, &oregs); +} + +void +clearup() +{ +} + +/*************************************************************************** + * BIOS serial routines, transmit character + */ +void +do_xmit() +{ + int ch; + ch = *xmit_get++; + if( xmit_get == xmit_put ) xmit_get = xmit_put = xmit_buf; + + iregs.h.ah = WRITECH; + iregs.x.dx = port_no; + iregs.h.al = ch; + int86(RS232, &iregs, &oregs); + + if( oregs.h.ah & 0x80 ) + printf("Write Failed (0x%x)\r\n", oregs.h.ah); +} + +/*************************************************************************** + * BIOS serial routines, receive character + * + * Note the _long_ loop for successful collection of bytes so this can + * actually work moderatly reliably upto about 9600 bps even with a + * bios that doesn't use interrupts. + */ +void +serial() +{ + int c; + int cnt = 2048; /* Lots but eventually will break */ + + do_xmit(); + + while((c=chrdy()) >=0) + { +#ifdef PRINTER + if( in_transprt ) + putprnt(c); + else +#endif + putscrn(c); + if( cnt-- < 0 ) break; + } +#ifdef MEM_SCR + update_page(); +#endif +} + +/*************************************************************************** + * BIOS serial routines, get character from bios is ready. + */ +int +chrdy() +{ + iregs.h.ah = STATUS; + iregs.x.dx = port_no; + int86(RS232, &iregs, &oregs); + + if( oregs.x.ax & DTARDY ) + { + iregs.h.ah = READCH; + iregs.x.dx = port_no; + int86(RS232, &iregs, &oregs); + + if( oregs.h.ah & 0x80) + { + message("Read Failed 0x%2x", oregs.h.ah); + return -1; + } + else + return oregs.h.al & mask; + } + return -1; +} +#endif + +/****************************************************************************/ + +#ifdef RS8250 +/*************************************************************************** + * Hardware serial routines. + */ + +int com_phy[] = { 0x3F8, 0x2F8, 0x3E8, 0x2E8 }; +int com_irq[] = { 4, 3, 4, 3 }; + +#define IRQ_MASK /* 0x88 */ 0x00 + +int save_bitflgs; +int port_no; +int port_addr; +int port_int; +int rtsflag = 2; + +/*************************************************************************** + * Hardware serial routines, setup port and identify fossil port. + */ +void +setup(port, flags) +int port, flags; +{ + long i = -1; + port_no = port; + + iregs.h.ah = FOSINIT; + iregs.x.dx = port_no; + iregs.x.bx = 0; + int86(RS232, &iregs, &oregs); + if( oregs.x.ax == 0x1954 ) + { + if( oregs.h.bh >= 4 ) + { + isfossil = oregs.h.bh; + fossilfunc = oregs.h.bl; + iregs.h.ah = 0xE0; + iregs.h.al = 6; + iregs.x.bx = 0; + int86(RS232, &iregs, &oregs); + if( oregs.x.bx == 0x4d58 ) + { + mnp_fossil = 1; + } + } + } + + if( isfossil == 0 ) + { + port_addr = com_phy[port]; + port_int = 8 + com_irq[port]; + + save_bitflgs = inp(port_addr+4); + + if(flags > 255) + { + i = speeds[flags>>5]; + flags &= 0x1F; + flags |= 0xE0; + } + } + /* else possible message about speed problem */ + + iregs.h.ah = INITRS; + iregs.x.dx = port_no; + iregs.h.al = flags; + + int86(RS232, &iregs, &oregs); + + if( isfossil == 0 ) + { + if( i > 0 ) + { + long brd = 115200L / i; + outp(port_addr+3, inp(port_addr+3) | 0x80); + outp(port_addr+0, brd & 0xFF); + outp(port_addr+1, (brd >> 8) & 0xFF); + outp(port_addr+3, inp(port_addr+3) & 0x7F); + } + + outp(port_addr+2, 0x47); /* 16550A's FIFO cleared & at 4 char timeout */ + setints(); + outp(port_addr+4, inp(port_addr+4) | 0xB ); + } +} + +/*************************************************************************** + * Hardware serial routines, reset hardware. + */ +void +clearup() +{ + if( isfossil == 0 ) + { + outp(port_addr+4, save_bitflgs); + clrints(); + } +} + +/*************************************************************************** + * Hardware serial routines, get character from buffer. + */ +int +get_c() +{ + int c; + if( isfossil && putptr == empty) + chfetch(); + + if(putptr == empty ) + c = -1; + else + { + _disable(); + if(getptr >= full) getptr = empty; + c = *getptr++; + nsize--; + if( nsize == 0 ) + getptr = putptr = empty; + _enable(); + c &= mask; + } + + if( isfossil == 0 ) + { + if( rtsflag ) + { + /* if( nsize>sizeof(empty)/2) rtsflow(1) */ ; + } + else + { + if( nsize= 0x18 ) + { + iregs.h.ah = 0x18; + iregs.x.cx = sizeof(empty); + iregs.x.di = (unsigned) empty; + iregs.x.dx = port_no; + segread(&sregs); + sregs.es = sregs.ds; + int86x(RS232, &iregs, &oregs, &sregs); + putptr = empty + oregs.x.ax; + nsize = oregs.x.ax; + return; + } + + iregs.h.ah = STATUS; + iregs.x.dx = port_no; + int86(RS232, &iregs, &oregs); + + if( oregs.x.ax & DTARDY ) + { + iregs.h.ah = READCH; + iregs.x.dx = port_no; + int86(RS232, &iregs, &oregs); + + if( oregs.h.ah & 0x80) + message("Read Failed 0x%2x", oregs.h.ah); + else + { + *putptr++ = oregs.h.al & mask; + nsize++; + } + } +} + +/*************************************************************************** + * Hardware serial routines, send characters to port. + */ +void +do_xmit() +{ + int cnt; + int ch; + if( xmit_put == xmit_buf ) return; + + if( isfossil ) + { + ch = *xmit_get++; + if( xmit_get == xmit_put ) xmit_get = xmit_put = xmit_buf; + + iregs.h.ah = WRITECH; + iregs.x.dx = port_no; + iregs.h.al = ch; + int86(RS232, &iregs, &oregs); + + if( oregs.h.ah & 0x80 ) + message("Write Failed (0x%x)\r\n", oregs.h.ah); + } + else + { + if( !(inp(port_addr+5) & 0x20) ) return; + + ch = *xmit_get++; + if( xmit_get == xmit_put ) xmit_get = xmit_put = xmit_buf; + + outp(port_addr+0, ch); + } +} + +/*************************************************************************** + * Hardware serial routines, characters from port to screen. + */ +void +serial() +{ + int c; + + do_xmit(); + + if( (c= get_c()) >= 0 ) + { +#ifdef PRINTER + if( in_transprt ) + putprnt(c); + else +#endif + putscrn(c); + } +#ifdef MEM_SCR + else + update_page(); +#endif +} + +/*************************************************************************** + * Hardware serial routines, interrupt handling. + */ +void ( interrupt far * int_rs_orig) _((void)); + +void interrupt far int_rs _((void)); + +void +setints() +{ + int c; + int c1; + + int_rs_orig = _dos_getvect(port_int); + + _dos_setvect(port_int, int_rs); + + outp(port_addr+1, 0x01); + outp(port_addr+4, inp(port_addr+4)&0xF); + + inp(0x21); + outp(0x21, IRQ_MASK); + + inp(port_addr+0); +} + +void +clrints() +{ + int c; + + _disable(); + c = inp(port_addr+3); + outp(port_addr+3, c&0x7F); + outp(port_addr+1, 0); + outp(port_addr+3, c); + _enable(); + + _dos_setvect(port_int, int_rs_orig); +} + +/*************************************************************************** + * Hardware serial routines, interrupt routine. + * + * Normally this _only_ reads characters from the serial port, flow control + * is only asserted if the interrupts are arriving too fast for the main + * job to run. + */ +void interrupt far int_rs() +{ +register int lsr, prt_addr = port_addr; + + while( (lsr=inp(prt_addr+5)) & 0x1F ) + { + if( rtsflag ) + { + /* Is buffer too full ? */ + if( nsize>sizeof(empty)/4*3 ) + { + register int i; + rtsflag = 0; + i=prt_addr+4; + outp(i, inp(i) & ~2 ); + } + } + else + if( nsize>=sizeof(empty)-2 ) /* It didn't respond to RTS! */ + break; + + { + register char * ptr = putptr; + if( lsr & 0x1A ) + { + if(ptr >= full) ptr = empty; + if( lsr & 0x10 ) + *ptr++ = 0x07; /* Flag break */ + else + *ptr++ = '\032'; /* Flag overrun or frame error */ + nsize++; + } + if( lsr & 0x01 ) + { + if(ptr >= full) ptr = empty; + *ptr++ = inp(prt_addr+0); + nsize++; + } + putptr = ptr; + } + } + outp(prt_addr+1, 0x00); + outp(0x20, 0x20); /* Ensure late irq's retrigger */ + + if( nsize>6) + ((i>>9)&0x40); + _AH = 0x05; geninterrupt(0x16); +#endif +#endif + + int_rs(); + orig_kbd_int(); + outp(port_addr+4, inp(port_addr+4) | rtsflag ); +} + +void +clear_kbd() +{ + _dos_setvect(KBDINT, orig_kbd_int); +} +#endif +#endif + +/*************************************************************************** + * AVATAR -> ANSI conversion routines. + * + * Only the hardware screen version can use the avatar+ codes + * (except insert mode which needs large changes) + */ +#ifdef AVATAR +#ifndef MEM_SCR + +char avbuf[270]; +int avcnt = 0; + + /* @ A B C D E F G H I J K L M N */ +int avsizes[] = { 0, 3, 2, 2, 2, 2, 2, 2, 4, 2, 7, 7, 5, 6, 2 }; +int avzero [] = { 0, 3, 2, 2, 2, 2, 2, 2, 4 }; +int colconv[] = { 0, 4, 2, 6, 1, 5, 3, 7 }; + +do_avatar(ch) +{ + char tbuf[270]; + int i, j; + + if( avcnt == 0 ) + { + avbuf[0] = ch; + avcnt=1; + return; + } + else + { + avbuf[avcnt++] = ch; + if( avbuf[0] == '\031' ) + { + if( avcnt < 3 ) return; + j = (avbuf[2]&0x7F); + avcnt = -1; + for(i=0; i= sizeof(avsizes)/sizeof(int) ) + { + avcnt = -1; + putscrn('\026'); + putscrn(ch); + avcnt = 0; + return; + } + else + if( avcnt < avsizes[avbuf[1]]) return; + avcnt = -1; + tbuf[0] = '\0'; + switch( avbuf[1] ) + { + case 1: sprintf(tbuf, "\033[0;3%d;4%dm", + colconv[avbuf[2]&0x7], colconv[(avbuf[2]>>4)&0x7]); + if( avbuf[2]&0x08 ) sprintf(tbuf+strlen(tbuf), "\033[1m"); + break; + case 2: sprintf(tbuf, "\033[5m"); + break; + case 3: sprintf(tbuf, "\033[A"); + break; + case 4: sprintf(tbuf, "\033[B"); + break; + case 5: sprintf(tbuf, "\033[D"); + break; + case 6: sprintf(tbuf, "\033[C"); + break; + case 7: sprintf(tbuf, "\033[K"); + break; + case 8: if( avbuf[2] > 25 || avbuf[2] < 1 ) + { + putscrn(avbuf[2]); + putscrn(avbuf[3]); + } + else if( avbuf[3] > 80 || avbuf[3] < 1 ) + { + sprintf(tbuf, "\033[%dH", avbuf[2]); + j=strlen(tbuf); + tbuf[j] = avbuf[3]; + tbuf[j+1] = '\0'; + } + else + sprintf(tbuf, "\033[%d;%dH", avbuf[2], avbuf[3]); + break; + case 25: memcpy(tbuf, avbuf, 270); + j = (tbuf[tbuf[2]+3]&0xFF); + avcnt = 0; + for(;j>0; j--) + for(i=0; i<(tbuf[2]&0xff); i++) + putscrn(tbuf[i+3]); + + tbuf[0] = '\0'; + break; + default: sprintf(tbuf, "Unsupported avatar CTRL-V CTRL-%c ", + '@'+ avbuf[1] ); + break; + } + for(i=0; tbuf[i]; i++) + putscrn(tbuf[i]); + avcnt = 0; + } +} + +#else /* def MEM_SCR */ + +char avbuf[270]; +int avcnt = 0; + + /* @ A B C D E F G H I J K L M N */ +#ifdef AVATAR_PLUS +int avsizes[] = { 0, 3, 2, 2, 2, 2, 2, 2, 4, 2, 7, 7, 5, 6, 2 }; +#else +int avsizes[] = { 0, 3, 2, 2, 2, 2, 2, 2, 4 }; +#endif +int colconv[] = { 0, 4, 2, 6, 1, 5, 3, 7 }; + +do_avatar(ch) +{ + char tbuf[270]; + int i, j; + + if( avcnt == 0 ) + { + avbuf[0] = ch; + avcnt=1; + return; + } + else + { + avbuf[avcnt++] = ch; + if( avbuf[0] == '\031' ) + { + if( avcnt < 3 ) return; + j = (avbuf[2]&0x7F); + avcnt = -1; + for(i=0; i= sizeof(avsizes)/sizeof(int) ) + { + avcnt = -1; + litput('\026'); + litput(ch); + avcnt = 0; + return; + } + else + if( avcnt < avsizes[avbuf[1]]) return; + avcnt = -1; + tbuf[0] = '\0'; + switch( avbuf[1] ) + { + case 1: if( dos_mode != 2 && dos_mode != 7 ) + curpage->attr = (avbuf[2]&0x7F); + else + curpage->attr = ((avbuf[2]&0x08)|0x07); + if( curpage->honour_attr ) + curpage->clr_col = curpage->attr; + break; + case 2: curpage->attr |= 0x80; + if( curpage->honour_attr ) + curpage->clr_col = curpage->attr; + break; + case 3: set_pos(curpage->line-1, curpage->col); + break; + case 4: set_pos(curpage->line+1, curpage->col); + break; + case 5: curpage->col--; + if( curpage->col < 0 ) + curpage->col = 0; + break; + case 6: curpage->col++; + if( curpage->col >= line_len ) + curpage->col = line_len -1; + break; + case 7: clr_eol(); + break; + case 8: set_pos(avbuf[2]-1, avbuf[3]-1); + break; +#ifdef AVATAR_PLUS +/* case 9: insert mode (Gaud! this means lots of changes) */ + + case 10: /* scroll up */ + scroll_up(avbuf[2], avbuf[3], avbuf[4], avbuf[5], avbuf[6]); + break; + + case 11: /* scroll down */ + scroll_down(avbuf[2], avbuf[3], avbuf[4], avbuf[5], avbuf[6]); + break; + + case 12: clear_area(curpage->line, curpage->col, + avbuf[3], avbuf[4], avbuf[2] , ' '); + break; + case 13: clear_area(curpage->line, curpage->col, + avbuf[4], avbuf[5], avbuf[2], avbuf[3]); + break; + + case 14: /* del char */ + delch(1); + break; +#endif + case 25: memcpy(tbuf, avbuf, 270); + j = (tbuf[tbuf[2]+3]&0xFF); + avcnt = 0; + for(;j>0; j--) + for(i=0; i<(tbuf[2]&0xff); i++) + putscrn(tbuf[i+3]); + + tbuf[0] = '\0'; + break; + default: sprintf(tbuf, "Unsupported avatar CTRL-V CTRL-%c ", + '@'+ avbuf[1] ); + break; + } + for(i=0; tbuf[i]; i++) + putscrn(tbuf[i]); + avcnt = 0; + } +} + +#ifdef AVATAR_PLUS +clear_area(r, c, h, w, a, cc) +int w,h; +int r, c; +{ + int i, j; + int ch; + int attr; + + attr = a; + + ch = (cc&0xFF)+(attr<<8); + + if( r >= scr_len || c >= line_len + || r+h < 0 || c+w < 0 || h < 0 || w < 0 ) return; + if( r < 0 ) { h -= r; r = 0; } + if( c < 0 ) { w -= c; w = 0; } + if( r+h > scr_len ) { h = scr_len-r; } + if( c+w > line_len ) { w = line_len-c; } + + for(i=0; ilines[r+i][c+j] = ch; + } + } + dirty_lines(r, h); + curpage->attr = attr; +} + +scroll_up(lines, tlr, tlc, brr, brc) +int lines, tlr, tlc, brr, brc; +{ + int slines; + int rows, cols, i, k; + if( tlr < 1 ) tlr = 1; + if( tlc < 1 ) tlc = 1; + if( brr > scr_len ) brr = scr_len; + if( brc > line_len ) brc = line_len; + if( tlr > brr ) return; + if( tlc > brc ) return; + + rows = brr-tlr+1; + cols = brc-tlc+1; + tlr--; tlc--; brc--; brr--; + + if( lines <= 0 || lines >= rows ) + { + clear_area(tlr, tlc, rows, cols, curpage->attr, ' '); + return; + } + slines = rows - lines; + for(i=0;i < slines;i++) + { + /* copy from line tlr+i+lines to line tlr+i */ + for(k=tlc;k<=brc;k++) + { + curpage->lines[tlr+i][k] = curpage->lines[tlr+lines+i][k]; + } + } + for(i=slines; ilines[tlr+i][k] = (curpage->attr<<8)+' '; + } + } + dirty_lines(tlr, rows); +} + +scroll_down(lines, tlr, tlc, brr, brc) +int lines, tlr, tlc, brr, brc; +{ + int slines; + int rows, cols, i, k; + if( tlr < 1 ) tlr = 1; + if( tlc < 1 ) tlc = 1; + if( brr > scr_len ) brr = scr_len; + if( brc > line_len ) brc = line_len; + if( tlr > brr ) return; + if( tlc > brc ) return; + + rows = brr-tlr+1; + cols = brc-tlc+1; + tlr--; tlc--; brc--; brr--; + + if( lines <= 0 || lines >= rows ) + { + clear_area(tlr, tlc, rows, cols, curpage->attr, ' '); + return; + } + slines = rows - lines; + for(i=rows-1;i >= lines;i--) + { + /* copy from line tlr+i to line tlr+i+lines */ + for(k=tlc;k<=brc;k++) + { + curpage->lines[tlr+i][k] = curpage->lines[tlr+i-lines][k]; + } + } + for(i=0; ilines[tlr+i][k] = (curpage->attr<<8)+' '; + } + } + dirty_lines(tlr, rows); +} + +dirty_lines(top, count) +int top, count; +{ + int i; + for(i=0; idirty[top+i] = 1; + } +} +#endif +#endif +#endif + + +#ifdef AT_BIOS_KEY + +static int bioskeydecode[] = { + 0x0000, 0x3280, 0x3131, 0x3132, 0x3133, 0x3134, 0x3135, 0x3136, + 0x3137, 0x3138, 0x3139, 0x3130, 0x312d, 0x313d, 0x3308, 0x1209, + 0x3171, 0x3177, 0x3165, 0x3172, 0x3174, 0x3179, 0x3175, 0x3169, + 0x316f, 0x3170, 0x315b, 0x315d, 0x330d, 0x0000, 0x3161, 0x3173, + 0x3164, 0x3166, 0x3167, 0x3168, 0x316a, 0x316b, 0x316c, 0x313b, + 0x0100, 0x0100, 0x0000, 0x0400, 0x317a, 0x3178, 0x3163, 0x3176, + 0x3162, 0x316e, 0x316d, 0x312c, 0x312e, 0x312f, 0x0000, 0x0700, + 0x0000, 0x3520, 0x0000, 0x0481, 0x0482, 0x0483, 0x0484, 0x0485, + 0x0486, 0x0487, 0x0488, 0x0489, 0x048a, 0x0000, 0x0000, 0x0697, + 0x0698, 0x0699, 0x0700, 0x0694, 0x0695, 0x0696, 0x0700, 0x0691, + 0x0692, 0x0693, 0x0690, 0x069a, 0x1481, 0x1482, 0x1483, 0x1484, + 0x1485, 0x1486, 0x1487, 0x1488, 0x1489, 0x148a, 0x2481, 0x2482, + 0x2483, 0x2484, 0x2485, 0x2486, 0x2487, 0x2488, 0x2489, 0x248a, + 0x3481, 0x3482, 0x3483, 0x3484, 0x3485, 0x3486, 0x3487, 0x3488, + 0x3489, 0x348a, 0x0000, 0x2694, 0x2696, 0x2691, 0x2693, 0x2697, + 0x3131, 0x3132, 0x3133, 0x3134, 0x3135, 0x3136, 0x3137, 0x3138, + 0x3139, 0x3130, 0x002d, 0x003d, 0x2699, 0x048b, 0x048c, 0x148b, + 0x148c, 0x248b, 0x248c, 0x348b, 0x348c, 0x2698, 0x2700, 0x2695, + 0x2700, 0x2692, 0x2690, 0x269a, 0x2009, 0x2700, 0x2700, 0x3697, + 0x3698, 0x3699, 0x0000, 0x3694, 0x3695, 0x3696, 0x0000, 0x3691, + 0x3692, 0x3693, 0x3690, 0x369a, 0x3700, 0x3009, 0x3700, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0700, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 +}; + +int get_key() +{ +static int last_flgs = 0; +static int force_flgs[] = {0, 2, 4, 8}; +static int this_flags = -1; + +#ifdef __BORLANDC__ +static int kbd_type = -1; +#else +static int kbd_type = 0; +#endif + + int ch, flgs, scan, flgs2; + int scand; + int i; + +try_again:; /* If we get a scan generator */ + +#ifdef __BORLANDC__ + if( kbd_type < 0 ) + { + kbd_type = 0; + + for(i=0; i<16;i++) + { + _AH = 0x01; geninterrupt(0x16); if((_FLAGS&0x40)) break; + _AH = 0x00; geninterrupt(0x16); + } + _AH = 0x05; _CX= 0xFFFF; geninterrupt(0x16); + for(i=0; i<16;i++) + { + _AH = 0x11; geninterrupt(0x16); if((_FLAGS&0x40)) break; + _AH = 0x10; geninterrupt(0x16); + if( _AX == 0xFFFF ) + { + kbd_type = 0x10; + break; + } + } + } + + _AH = kbd_type+1; geninterrupt(0x16); + i = (_FLAGS&0x40); + + _AH = kbd_type+2; geninterrupt(0x16); flgs = _AX; + if( !kbd_type ) flgs &= 0xFF; + +#else + i = !_bios_keybrd(_KEYBRD_READY); + + flgs = _bios_keybrd(_KEYBRD_SHIFTSTATUS); +#endif + if(!(flgs&0x8)) flgs &= ~0x0A00; + + if(i) + { + if( flgs != last_flgs ) + { + ch = 0; + last_flgs = flgs; + i=0; + if( (flgs & 0x500) == 0x500 ) ch |= KEY_CTRL; + if( (flgs & 0xA00) == 0xA00 ) ch |= KEY_ALT|KEY_ALTGR; + if(!i) + { + if( (flgs & 0x001) ) i++; + if( (flgs & 0x002) ) i++; + if( (flgs & 0x004) ) i++; + if( (flgs & 0x008) ) i++; + } + + if( i>1 ) + { + if( flgs & 0x4 ) ch |= KEY_CTRL; + if( flgs & 0x3 ) ch |= KEY_SHIFT; + if( (flgs & 0x0A00) ) + ch |= ((flgs&0x0200)?KEY_ALT:0) + ((flgs&0x0800)?KEY_ALTGR:0) ; + else + ch |= ((flgs&0x08)?KEY_ALT:0); + } + + if( ch ) + { +#ifdef DEBUG + cprintf( "BIOS ----, FLGS: %04x:", flgs); +#endif + return (ch + KEY_SPECIAL); + } + } + return -1; + } + else + { +#ifdef __BORLANDC__ + _AH = kbd_type; geninterrupt(0x16); + ch = (unsigned) _AX; +#else + ch = _bios_keybrd(_KEYBRD_READ); +#endif + } + + if( this_flags != -1 ) + { + flgs = ( flgs & 0x70F0 ) + + ( this_flags & 3 ) + + ((this_flags & 0x3C) << 6 ) + + ((this_flags & 0x40) << 9 ); + if( flgs & 0x500 ) flgs |= 0x04; + if( flgs & 0xA00 ) flgs |= 0x08; + this_flags = -1; + } + + if( ( ch & 0xFF00 ) == 0xFE00 ) { this_flags = ch; goto try_again; } + + last_flgs = flgs; +#ifdef DEBUG + cprintf( "BIOS %04x, FLGS: %04x:", ch, flgs); +#endif + + flgs &= 0x0A0F; + if( ch == 0 ) return KEY_OTHER + 0x03; + + scan = ((ch>>8)&0xFF); + ch &= 0xFF; + + if( scan == 0 ) return ch + KEY_DIRECT; + if( scan == 0xE0 ) scan = 0xA4 + 2*(ch < ' '); + + flgs2 = 0; + if( ch == 0xE0 ) { flgs2 |= KEY_PAD; ch = 0; } + + /* Check for forced flags */ + if( ch == 0 && (flgs&0xF) == 0 ) + flgs |= force_flgs[(bioskeydecode[scan]>>12)&3]; + + if( flgs & 0x4 ) flgs2 |= KEY_CTRL; + if( flgs & 0x3 ) flgs2 |= KEY_SHIFT; + + if( (flgs & 0x0A00) ) + flgs2 |= ((flgs&0x0200)?KEY_ALT:0) + ((flgs&0x0800)?KEY_ALTGR:0) ; + else + flgs2 |= ((flgs&0x08)?KEY_ALT:0); + + if( ch ) switch(flgs2) + { + case 0: case KEY_CTRL: case KEY_SHIFT: + switch((bioskeydecode[scan]>>8)&7) + { + case 1: + return ch; + case 2: + if( flgs2 == 0 ) return ch + KEY_OTHER; + break; + case 3: + if( (flgs2 & ~KEY_CTRL) == 0 ) return ch + KEY_OTHER; + break; + case 4: + if( (flgs2 & ~KEY_SHIFT) == 0 ) return ch; + if( flgs2 == KEY_CTRL ) return (ch&0x1F); + break; + case 5: + if( flgs2 == 0 ) return ch; + break; + case 6: + if( flgs2 == 0 ) return ch + KEY_PAD; + break; + case 7: return ch + KEY_PAD; + } + } + + flgs2 |= KEY_SPECIAL; + + if( ((bioskeydecode[scan]>>8)&6) == 6 && (flgs&0x08) == 0 && kbd_type ) + flgs2 ^= KEY_PAD; + + if( ((bioskeydecode[scan]>>8)&7) == 4 && ch ) + ; + else if(bioskeydecode[scan]&0xFF) + return flgs2 + (bioskeydecode[scan]&0xFF); + + return flgs2 + KEY_DIRECT + scan; +} + +unsigned char scan_desc[] = { + 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 8, 0, + 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 10, 'C', 'a', 's', + 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', 0, 0, 'S', 0, 'z', 'x', 'c', 'v', + 'b', 'n', 'm', ',', '.', '/', 'T', 0, 'A', ' ', 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 'E', 'F', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +char hextbl[] = "0123456789abcdef"; + +/* Write scancodes, in this mode you really need a compatible program on + * the host, but you can just about type 'reset' and have it work + */ +void +write_scan(scan) +int scan; +{ +static int lastscan = -1; + int by; + + scan &= 0xFF; + + if( scan == lastscan+0x80 ) + { xmit('~'); xmit('\b'); } + else if( by = scan_desc[scan] ) + xmit(by); + else if( by = scan_desc[scan&0x7F] ) + { xmit('!'); xmit(by); } + else + { xmit('~'); xmit(hextbl[scan>>4]); xmit(hextbl[scan&0xF]); } + lastscan = scan; +} + +/* + * This keyboard gives a pattern of control sequences that makes just about + * every keypress distinct. It does need a compatible host program but its + * useable as a generic terminal type unlike the scancodes. + */ +void +write_dosemu(ch) +int ch; +{ +#define CT_KEY 0x1E + int by = (ch & 0xFF); + + /* First we swap round ^M and Return, likewise BS, Tab and Esc */ + if( ( ch & 0xFF00 ) == KEY_OTHER || ( ch & 0xFF00 ) == 0 ) + { + /* Make it so we can detect the 'other' keys */ + if( strchr("\b\t\r\n\033\003\177", by) ) + { + if( ch & KEY_OTHER ) + ch ^= KEY_OTHER; + else + by = ((ch = KEY_SPECIAL+KEY_CTRL+tolower(by+'@')) & 0xFF); + } + } + + if( ch & 0xFF00 ) + { + if( ch & KEY_SPECIAL ) + { + if( by == 0 ) return; + + if( ch & KEY_ALT ) { xmit(CT_KEY); xmit('a'); } + if( ch & KEY_CTRL ) { xmit(CT_KEY); xmit('c'); } + if( ch & KEY_SHIFT ) { xmit(CT_KEY); xmit('s'); } + if( ch & KEY_ALTGR ) { xmit(CT_KEY); xmit('g'); } + if( ch & KEY_PAD ) { xmit(CT_KEY); xmit('k'); } + /* if( ch & KEY_OTHER ) { xmit(CT_KEY); xmit('o'); } */ + + if( ch & KEY_DIRECT ) + { + xmit(CT_KEY); xmit('~'); + xmit(hextbl[by>>4]); xmit(hextbl[by&0xF]); + } + else if((by&0xF0)==0x80 ) + { +static char fkeys[] = "01234567890-=.."; + if( by == 0x80 ) + { + xmit('\033'); + xmit('\033'); + } + else + { + xmit(CT_KEY); + xmit(fkeys[by&0xF]); + } + } + else if((by&0xF0)==0x90 ) + { + xmit(CT_KEY); + xmit('K'); + xmit(hextbl[by&0xF]); + } + else + xmit(by); + } + else + { + if( ch & KEY_PAD ) { xmit(CT_KEY); xmit('k'); } + if( ch & KEY_OTHER ) { xmit(CT_KEY); xmit('o'); } + if( ch & KEY_DIRECT ) { xmit(CT_KEY); xmit('z'); } + xmit(by); + } + } + else if( by == CT_KEY ) + { + xmit(CT_KEY); xmit('c'); xmit(tolower(CT_KEY+'@')); + } + else + { + xmit(by); + if( by == '\033' ) + xmit(by); + } +} + +/* + * This key mapping is designed for easy use with terminfo nevertheless + * it has potentially 96 function key + 104 alt/ctrl/shift&letter codes. + * +#ifdef SCO_KEYMAP + * This generates key sequences compatible with the SCO-Xenix console. + * In addition many extra key combinations generate distinct codes. + * But there are normally several ways of generating each standard key. +#endif + */ +void +write_unix(ch) +int ch; +{ + int by; +#ifdef SCO_KEYMAP + /* 012345678901234567890123456 789012 */ +static char normal[] = " MNOPQRSTUVWX LFBGDECHAI\177 "; +static char shift [] = " YZabcdefghij 0123456789\177 "; +static char ctrl [] = " klmnopqrstuv \177 "; +static char ctrshf[] = " wxyz@[\\]^_`{ \177 "; +#endif + + /* This seems to be a pain if it stays */ + if( ch == KEY_SPECIAL+KEY_SHIFT+'\r' ) ch = '\r'; + if( ch == KEY_SPECIAL+KEY_SHIFT+' ' ) ch = ' '; + +#ifdef SCO_KEYMAP + if( ch & KEY_SPECIAL ) + { + if( ch & (KEY_ALT|KEY_ALTGR|KEY_DIRECT) ) + write_dosemu(ch); + else if( (ch & 0xE0) != 0x80 ) + write_dosemu(ch); + else + { + char * keys; + if( ch&KEY_SHIFT ) + { + if( ch&KEY_CTRL ) keys = ctrshf; else keys = shift; + } + else + { + if( ch&KEY_CTRL ) keys = ctrl; else keys = normal; + } + by = keys[ch&0x1F]; + if( by == ' ' ) write_dosemu(ch); + else if( by == '\177' || by >= '0' && by <= '9' ) + xmit(by); + else + { + xmit('\033'); + xmit('['); + xmit(by); + } + } + } +#else + if( ch & KEY_SPECIAL ) + write_dosemu(ch); +#endif + else + xmit(ch&0xFF); +} + +#else !AT_BIOS_KEY +/*************************************************************************** + * Get a key from the keyboard (-1 if none available) + * Simple XT-BIOS version + */ + +int get_key() +{ +#ifdef KEY_COMPAT + /* This is called so often that windows thinks we're idle; well we + * are _but_ windows also seems to stop us. + */ + + if( _bios_keybrd(_KEYBRD_READY) == 0 ) return -1; + return _bios_keybrd(_KEYBRD_READ); + +#else + + /* So we have to hack it */ + +#define bios_ram ((char far *)0x00400000L) + static char last_flags = 0; + int c; + + if( bios_ram[0x1C] != bios_ram[0x1A] ) + return _bios_keybrd(_KEYBRD_READ); + else + return -1; + +#endif + +} + +/*************************************************************************** + * XT-BIOS Keymap tables for SCO console. + */ + +#ifdef SCO_KEYMAP +#ifdef SCO_REMAP +char * keytab[95]; +char keybuf[33] = ""; +int keyxlate[KEYTABSIZE] = + { 0073, 0074, 0075, 0076, 0077, + 0100, 0101, 0102, 0103, 0104, 0, 0, /* F11, F12 oops */ + 0124, 0125, 0126, 0127, 0130, + 0131, 0132, 0133, 0134, 0135, 0, 0, + 0136, 0137, 0140, 0141, 0142, + 0143, 0144, 0145, 0146, 0147, 0, 0, + 0150, 0151, 0152, 0153, 0154, + 0155, 0156, 0157, 0160, 0161, 0, 0, + 0107, 0110, 0111, 0112, 0113, + 0114, 0115, 0116, 0117, 0120, + 0121, 0122 + }; +#endif + +int kbtab[] = +{ +/* 000 */ 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, +/* 010 */ 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x25A, +/* 020 */ 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, +/* 030 */ 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, +/* 040 */ 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, +/* 050 */ 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, +/* 060 */ 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, +/* 070 */ 0x000, 0x000, 0x000, 0x24D, 0x24E, 0x24F, 0x250, 0x251, +/* 100 */ 0x252, 0x253, 0x254, 0x255, 0x256, 0x000, 0x000, 0x248, +/* 110 */ 0x241, 0x249, 0x000, 0x244, 0x000, 0x243, 0x000, 0x246, +/* 120 */ 0x242, 0x247, 0x24C, 0x07F, 0x259, 0x25A, 0x261, 0x262, +/* 130 */ 0x263, 0x264, 0x265, 0x266, 0x267, 0x268, 0x26B, 0x26C, +/* 140 */ 0x26D, 0x26E, 0x26F, 0x270, 0x271, 0x272, 0x273, 0x274, +/* 150 */ 0x277, 0x278, 0x279, 0x27A, 0x240, 0x25B, 0x25C, 0x25D, +/* 160 */ 0x25E, 0x25F, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000 +}; + +bios_keymap(c) +int c; +{ + char * kptr; + c >>= 8; + + if(c>=0 && c<0x78 && kbtab[c]) + { + switch((kbtab[c] >> 8)&0xF) + { + case 1: xmit('\033'); + break; + case 2: xmit('\033'); + xmit('['); + break; +#ifdef SCO_REMAP + case 3: kptr = keytab[kbtab[c] & 0xFF]; + if(kptr) while( *kptr ) xmit(*kptr++); + return TRUE; +#endif + } + xmit(kbtab[c] & 0xFF); + return 1; + } + return 0; +} + +/*************************************************************************** + * These functions are used for defining alternate function keys. + */ + +#ifdef SCO_REMAP +add_fnchar(ch) +int ch; +{ + int s = strlen(keybuf); + if( s == 32 ) return; + keybuf[s] = ch; + s++; + keybuf[s] = 0; +} + +set_key(kno) +int kno; +{ + if( keybuf[0] == 0 ) return message("Function key %d cleared", kno+1); + if( keytab[kno] != 0 ) + { + free(keytab[kno]); + keytab[kno] = 0; + } + keytab[kno] = malloc(strlen(keybuf)+1); + strcpy(keytab[kno], keybuf); + keybuf[0] = 0; +} +#endif +#endif +#endif diff --git a/libc/msdos/xxx/TALK.EXE b/libc/msdos/xxx/TALK.EXE new file mode 100644 index 0000000..549c4fe Binary files /dev/null and b/libc/msdos/xxx/TALK.EXE differ diff --git a/libc/msdos/xxx/ZIP.COM b/libc/msdos/xxx/ZIP.COM new file mode 100644 index 0000000..cd06cf9 Binary files /dev/null and b/libc/msdos/xxx/ZIP.COM differ diff --git a/libc/msdos/xxx/comx.com b/libc/msdos/xxx/comx.com new file mode 100644 index 0000000..db80d00 Binary files /dev/null and b/libc/msdos/xxx/comx.com differ diff --git a/libc/msdos/xxx/cpu.com b/libc/msdos/xxx/cpu.com new file mode 100644 index 0000000..23ab7e8 Binary files /dev/null and b/libc/msdos/xxx/cpu.com differ diff --git a/libc/msdos/xxx/list.com b/libc/msdos/xxx/list.com new file mode 100644 index 0000000..f17d5e3 Binary files /dev/null and b/libc/msdos/xxx/list.com differ diff --git a/libc/msdos/xxx/mail-to-lasu.html b/libc/msdos/xxx/mail-to-lasu.html new file mode 100644 index 0000000..2babe2d --- /dev/null +++ b/libc/msdos/xxx/mail-to-lasu.html @@ -0,0 +1,105 @@ + + + + Sending mail to Lasu + +

Sending mail to Lasu

+ +

I get mail from a lot of people I don't know. Some of this mail is +welcome, some is not. Unwelcome mail annoys me, because I pay for my +Internet connection, and I don't want to pay for something I don't want. +Even if I didn't pay, unwanted mail still wastes my time, which alone +is bad enough. + +

+This page explains my mail preferences. I'm grateful if you read it +before sending me mail. + +

I don't want to receive: + +

    +
  • Advertisments I did not ask for. Making me pay for your ads is + rude, and possibly illegal. I react strongly to ads. +
  • Chain letters. Most of them are illegal. All of them are a waste + of network resources. I react strongly to chain letters. +
  • Mailing lists I did not subscribe to, whether they are for ads or + not. I react strongly to this. +
  • Questions about Linux from strangers. I'm somewhat well + known in the Linux community, and I often get questions related + to Linux. I don't have the time to answer a lot of questions, and + much of the time I don't even know the answer. If you send one + to me, I will probably just ignore it. (This point only applies + to general questions; I'm happy to discuss my own activities.) +
  • Questions on other things you think I might know, especially including + Procmail, unless you have reason to believe I'm the only person + (or one of a small group) able to answer the question. +
  • Anything that is big (more than about 50 kB), in one or more pieces. + If you want me to have a big file, ask me first. +
  • Privately mailed copies of public responses to my messages on mailing + lists or in newsgroups. Don't make me pay + for downloading duplicate copies of the same message or wasting + my time reading the same message twice. +
+ +

I welcome: + +

    +
  • Anything from friends, relatives, and other people I personally know. +
  • Anything I've specifically asked for, including ads or big files. +
  • Anything concerning something I've written (programs, documents, + articles, letters, etc), as long as it related to that. Replying + to my article with an unrelated ad invites hostility on my part. +
  • Anything related to comp.os.linux.announce, which I moderate. +
  • Anything related to the Linux Software Map, which I maintain. +
  • Anything concerning one of my other volunteer activities, such + as creating new groups in the sfnet hierarchy, or about one of the + associations or organizations I'm active in. +
  • Mailing lists I've subscribed to. +
+ +

If you aren't sure if I'm interested, send me one line and ask me. +Neither of the above lists are exhaustive, and I'm sure there will be +exceptions. + +

I used to have a mail filter that was quite aggressive and +deleted all mail from unknown people. I've since softened +it quite a bit: now, the filter deletes nothing, but puts +mail from unknown people in a separate folder, which I check +when I feel like it (not necessarily very often). The filter +also sends back a note that tells what happened. (Read the description of the filter, if you're +curious about it.) + + +

I don't engage in e-mail bombs (sending many large or mails to the same +address) or other forms of Internet terrorism. I don't even suggest +other do. On the contrary, I react with hostility to people who suggest +such things. Most of them are just ignorant, but that is not an excuse. +Network abuse is network abuse, regardless of why you do it. If you send +a mail bomb, you deserve to get thrown out of the net. Period. + +

Privacy

+ +

I like to keep my private stuff private. If you can, please do PGP encrypt +your mail to me (you can download my PGP public key +directly or from the +key servers). + +

Please also PGP sign your letters, because Netscape made +forging the sender trivial and popular. + +

The address

+ +

My personal e-mail address is liw@iki.fi. Other addresses may or may +not work. MIME is OK. My home page is at +http://www.iki.fi/liw/. + +

Articles meant for comp.os.linux.announce should be sent +to linux-announce@news.ornl.gov, not to my personal address. +The address must be in the To: or Cc: header. I reserve the +right to ignore any articles sent via mailing lists or with Bcc:. News +programs can usually send it to the correct address. See also the comp.os.linux.announce +home page. + +

(22 September 1997, Lars Wirzenius) diff --git a/libc/msdos/xxx/mailfilter-mh.html b/libc/msdos/xxx/mailfilter-mh.html new file mode 100644 index 0000000..f7d4fb9 --- /dev/null +++ b/libc/msdos/xxx/mailfilter-mh.html @@ -0,0 +1,86 @@ + + + + + +Saving the outgoing addresses automatically + + + +

Saving the outgoing addresses automatically

+ +

I have a anti-junk mail filter, which +uses a whitelist of people I know and want mail from. Maintaining this +list by hand is tiresome, so I have automated it. + +

I have configured MH to run a small script for each letter that I +send. This is easy to do: edit ~/.mh_profile to include +a line like the following: + +

+postproc: /home/liw/bin/xtract-to-and-post
+
+ +This instructs MH to run the specified command for each outgoing letter. +The letter will be given as input to it. + +

xtract-to-and-post is a simple shell script: + +

+#!/bin/sh
+
+PATH=$PATH:$HOME/bin
+
+greylist=$HOME/.procmail/greylist
+whitelist=$HOME/.procmail/whitelist
+lock=$greylist.lock
+
+x=''
+for i in "$@"
+do
+	x="$i"
+done
+
+if test -r "$x"
+then
+	if lockfile $lock
+	then
+		xtract-to-cc < "$x" | sort -fu -o $greylist $greylist -
+		rm -f $lock
+	fi
+fi
+
+/usr/lib/mh/post "$@"
+
+ +It looks more complicated than it is. Essentially it only uses +xtract-to-cc to get all addresses from the To and Cc +headers and adds them to the greylist file. There's some locking +added to avoid concurrent updates. + +

xtract-to-cc is a small Python script that prints +out all addresses in the To and Cc headers of a mail message: + +

+#!/usr/bin/python
+
+import sys
+from rfc822 import Message
+
+x = Message(sys.stdin)
+for i in x.getaddrlist('to'):
+	print i[1]
+for i in x.getaddrlist('cc'):
+	print i[1]
+
+ +

Similar hacks can be done for other systems. If nothing else +works, have your mailer send a copy of each sent message, and +periodically run a suitable program to extract the addresses. + +

(9 September 1996, +Lars Wirzenius) + + + diff --git a/libc/msdos/xxx/mailfilter.html b/libc/msdos/xxx/mailfilter.html new file mode 100644 index 0000000..035c26e --- /dev/null +++ b/libc/msdos/xxx/mailfilter.html @@ -0,0 +1,153 @@ + + + + + +Lasu's mail filters + + + +Note: I've updated this page a little bit, but it still describes +the previous version of the filter. The new filter is quite similar to +the old one, but has easier configurability, and is (by default) rather +less aggressive. + +

Lasu's mail filters

+ +

This page explains how I use procmail to filter +my mail. Perhaps the most interesting part is how I reject mail from +strangers in order to avoid getting spammed. This is not an introduction +to spam or why it's bad, or to procmail or mail filtering; see links at +end for some suggestions, but I do assume you're able to implement the +filtering on your own. + +

The approach

+ +

My filtering approach is like this: +

    +
  1. If the sender is on the blacklist, delete the letter. +
  2. Put mailing lists in their own folders. This must be done + correctly! Otherwise the mailing list mail is treated as + junk e-mail. +
  3. Put local administrative e-mail in its own folder. I administrate my + own Linux + box. This catches mail from system crontabs, news log summaries, + and so on. (Maybe not relevant to you.) +
  4. At this point, it should be personal mail. Check that the To or Cc + headers address me. If not, delete the mail. +
  5. Put bounce messages in their own mailbox. +
  6. If the sender is on my whitelist: +
      +
    1. If I'm on vacation, send back automatic response. +
    2. Put the letter in inbox. +
    +
  7. If the subject includes password, put in special folder for + unknown people. +
  8. Otherwise, autoreply with request to use password and delete the mail. +
+ +

Instead of deleting the unwanted mail, it is also possible to just store +it in a special folder. You should do this while testing the setup, so that +you don't lose any important mail due to errors. It's best to use separate +folders for each case; I have folders no-password and new-OTHER, but feel +free to use other names. + +

When using this scheme, it is imperative to put all addresses you send +mail to on your whitelist or else to put the password in the subject. +Otherwise, you will annoy people. I have an automatic setup for the +MH mailer. + +

Problems

+ +

My approach has some problems: +

    +
  • If someone sends you mail using the Bcc header, it will be treated as + junk, since your address won't be visible in the To or Cc headers. + The Bcc header is removed before the mail is sent, so there is + no way to distinguish interesting Bcc'd messages and junk mail. + This is not really a problem for me, because I almost never get + Bcc'd mail, and when I do it is via one specific mailing list. +
  • Subscribing to mailing lists. You can't filter away the list until + you know what the headers look like, so you have to turn off + the check for personal mail until you can get the list filtering + to work. (The new version of the filter attempts to put stuff from + unknown mailing lists to a separate folder, but better safe than + sorry.) +
  • Spam sent to mailing lists won't be filtered away. This is not too big + a problem, because many mailing lists + now only allow subscribers to post to avoid spam. +
  • Not all bounce messages are filtered correctly. Unfortunately, there + are about as many bounce message formats as there are mail + transport programs. This is a real problem, because it's not + really a good idea to not lose bounce messages. It also opens + a glaring hole, because spammers can make their junk look like + bounce messaages. +
  • If the filter starts acting up, you'd better know Procmail, or be + prepared to drop it at once. +
+ +

Alternative methods

+ +

Many ways to fight junk mail have been proposed. Below is a list of +a few of them and the reasons why I don't do that. + +

    + +
  • Just delete them. +This is what I've been doing. It takes time to read enough of a letter + to positively identify it as junk. Not a whole lot of time, but + doing something unproductive several times a day is not fun. + It is annoying and lowers my work morale. I do computers because + it's fun, and junkmail makes it not fun. + +
  • Complain to sender or in public. +This takes time. I don't want to spend time on dealing with junk. +Using tools to automate most of the complaint process is not good +enough, since no tool is able to decode forged headers completely, +and sending the complaints to the wrong address is wrong. + +
  • Just filter away known baddies. +I won't know who they are, unless I get the mail, and by then it's too + late. Actually, I could read suitable newsgroups and mailing lists + and find reports of spammers, but again, it takes time I don't want + to spend. It also never ends, since the most persistent spammers + change accounts often, and there are hordes of new spammers on + the horizon. + +
  • Use a service that removes your address from spammers' lists. +Which one? How do I know they're reputable? What guarantee do I have that + the spammers use the services? Also, many of them have + been shown to be just another way to harvest e-mail addresses. + +
  • Use a munged mail address in public. +This causes postmasters (the people who keep the mail systems running) +extra work. Not polite, and counter-productive on the long run. + +
+ +

Related links

+ + +

Feedback

+ +

I'd be glad to hear any suggestions on how this filtering scheme +can be improved. Don't hesitate to tell me if you have ideas on solving +the above problems or if you can think of a new problem. I'd also be +grateful if tell me if you use this filtering scheme so that I can tell +you about important updates. I'd also like to hear of alternative filtering +schemes, especially for people using non-Unix systems. Follow the link +at the bottom before mailing, so you'll know how to avoid my filtering. + +

(22 September 1997, +Lars Wirzenius) + + + diff --git a/libc/msdos/xxx/mailfilter2.tar.gz b/libc/msdos/xxx/mailfilter2.tar.gz new file mode 100644 index 0000000..233090d Binary files /dev/null and b/libc/msdos/xxx/mailfilter2.tar.gz differ diff --git a/libc/msdos/xxx/mips.com b/libc/msdos/xxx/mips.com new file mode 100644 index 0000000..66cc110 Binary files /dev/null and b/libc/msdos/xxx/mips.com differ diff --git a/libc/msdos/xxx/tryit.com b/libc/msdos/xxx/tryit.com new file mode 100644 index 0000000..71ff71b Binary files /dev/null and b/libc/msdos/xxx/tryit.com differ diff --git a/libc/stdio2/stdio.c b/libc/stdio2/stdio.c index 4bada7e..bc96100 100644 --- a/libc/stdio2/stdio.c +++ b/libc/stdio2/stdio.c @@ -13,6 +13,10 @@ #include #include +#ifndef O_BINARY +#define O_BINARY 0 +#endif + extern FILE *__IO_list; /* For fflush at exit */ #ifdef __AS386_16__ @@ -131,12 +135,12 @@ FILE *fp; if ((v & __MODE_READING) && fflush(fp)) return EOF; - /* Can't write or there's been an EOF or error then return EOF */ + /* Can't write if there's been an EOF or error then return EOF */ if ((v & (__MODE_WRITE | __MODE_EOF | __MODE_ERR)) != __MODE_WRITE) return EOF; /* In MSDOS translation mode */ -#if __MODE_IOTRAN +#if __MODE_IOTRAN && !O_BINARY if (ch == '\n' && (v & __MODE_IOTRAN) && fputc('\r', fp) == EOF) return EOF; #endif @@ -197,7 +201,7 @@ FILE *fp; } ch = *(fp->bufpos++); -#if __MODE_IOTRAN +#if __MODE_IOTRAN && !O_BINARY /* In MSDOS translation mode; WARN: Doesn't work with UNIX macro */ if (ch == '\r' && (fp->mode & __MODE_IOTRAN)) goto try_again; @@ -407,11 +411,12 @@ FILE *fp; { memcpy(buf, fp->bufpos, (unsigned) bytes); fp->bufpos += bytes; - return bytes; + return nelm; } else if (len > 0) /* Some buffered */ { memcpy(buf, fp->bufpos, len); + fp->bufpos += len; got = len; } @@ -473,12 +478,18 @@ FILE *fp; len = fp->bufend - fp->bufpos; if (bytes <= len) /* It'll fit in the buffer ? */ { + register int do_flush=0; fp->mode |= __MODE_WRITING; memcpy(fp->bufpos, buf, bytes); + if (v & _IOLBF) + { + if(memchr(fp->bufpos, '\n', bytes)) + do_flush=1; + } fp->bufpos += bytes; - /* If we're not fully buffered */ - if (v & (_IOLBF | _IONBF)) + /* If we're unbuffered or line buffered and have seen nl */ + if (do_flush || (v & _IONBF) != 0) fflush(fp); return nelm; @@ -584,7 +595,7 @@ FILE *fp; char *mode; { int open_mode = 0; -#if __MODE_IOTRAN +#if __MODE_IOTRAN && !O_BINARY int do_iosense = 1; #endif int fopen_mode = 0; @@ -617,14 +628,19 @@ char *mode; case '+': fopen_mode |= __MODE_RDWR; break; -#if __MODE_IOTRAN +#if __MODE_IOTRAN || O_BINARY case 'b': /* Binary */ fopen_mode &= ~__MODE_IOTRAN; + open_mode |= O_BINARY; +#if __MODE_IOTRAN && !O_BINARY do_iosense=0; +#endif break; case 't': /* Text */ fopen_mode |= __MODE_IOTRAN; +#if __MODE_IOTRAN && !O_BINARY do_iosense=0; +#endif break; #endif } @@ -674,7 +690,7 @@ char *mode; if( isatty(fd) ) { fp->mode |= _IOLBF; -#if __MODE_IOTRAN +#if __MODE_IOTRAN && !O_BINARY if( do_iosense ) fopen_mode |= __MODE_IOTRAN; #endif } @@ -786,6 +802,7 @@ char * buf; int mode; size_t size; { + int rv = 0; fflush(fp); if( fp->mode & __MODE_FREEBUF ) free(fp->bufstart); fp->mode &= ~(__MODE_FREEBUF|__MODE_BUF); @@ -796,14 +813,21 @@ size_t size; if( mode == _IOFBF || mode == _IOLBF ) { if( size <= 0 ) size = BUFSIZ; - if( buf == 0 ) buf = malloc(size); - if( buf == 0 ) return EOF; - - fp->bufstart = buf; - fp->bufend = buf+size; - fp->mode |= mode; + if( buf == 0 ) + { + if( (buf = malloc(size)) != 0 ) + fp->mode |= __MODE_FREEBUF; + else rv = EOF; + } + if( buf ) + { + fp->bufstart = buf; + fp->bufend = buf+size; + fp->mode |= mode; + } } fp->bufpos = fp->bufread = fp->bufwrite = fp->bufstart; + return rv; } #endif diff --git a/libc/string/string.c b/libc/string/string.c index 3e6d2e4..ffce96c 100644 --- a/libc/string/string.c +++ b/libc/string/string.c @@ -632,7 +632,7 @@ unsigned int srcseg, srcoff, destseg, destoff, len; cld #endif - ! sei ! Are we _really_ paranoid ? + ! sti ! Are we _really_ paranoid ? #if !__FIRST_ARG_IN_AX__ mov ds,[bp+4] ! Careful, [bp+xx] is SS based. diff --git a/libc/syscall/Makefile b/libc/syscall/Makefile index 07b1428..0fd2ad6 100644 --- a/libc/syscall/Makefile +++ b/libc/syscall/Makefile @@ -4,7 +4,7 @@ LSRC=syslib0.c LOBJ=__cstartup.o lseek.o getpid.o getppid.o getuid.o geteuid.o getgid.o \ - getegid.o dup2.o dup.o getpgrp.o times.o + getegid.o dup2.o getpgrp.o times.o ESRC=exec.c EOBJ=execve.o execl.o execv.o execle.o execlp.o execvp.o @@ -13,7 +13,7 @@ DSRC=dirent.c DOBJ=opendir.o closedir.o readdir.o ifeq ($(LIB_CPU)-$(LIB_OS),i86-ELKS) -OBJ=$(LOBJ) $(LOBJ) $(DOBJ) $(EOBJ) signal.o setjmp.o +OBJ=$(LOBJ) $(DOBJ) $(EOBJ) signal.o setjmp.o SYSCALLS=call_i86 endif @@ -32,6 +32,9 @@ call_i86: syscall.mak syscall.mak: mksyscall syscall.dat sh mksyscall +syscall.dat: + @touch syscall.dat + $(LIBC): $(LIBC)($(OBJ)) $(LIBC)($(LOBJ)): $(LSRC) @@ -48,5 +51,5 @@ $(LIBC)($(EOBJ)): $(ESRC) clean: rm -f *.o libc.a - rm -f syscall.c syscall.mak + rm -f syscall.c syscall.mak syscall.dat rm -f call_tab.v defn_tab.v diff --git a/libc/syscall/TODO b/libc/syscall/TODO index f396897..ff14000 100644 --- a/libc/syscall/TODO +++ b/libc/syscall/TODO @@ -10,6 +10,8 @@ Subject: 8086 Shared Libs and local RPC. True shared libs are impossible with the 8086 in small model. BUT we can use RPC type links to provide a similar system. +This is very machine specific. + Client side ----------- diff --git a/libc/syscall/dirent.c b/libc/syscall/dirent.c index 8f7574c..b928757 100644 --- a/libc/syscall/dirent.c +++ b/libc/syscall/dirent.c @@ -60,33 +60,6 @@ DIR *dirp; } #endif -#ifdef __AS386_16__ -#ifdef L_readdir -/* - * This currently assumes we see a v. simple diectory structure, it's - * probably faked! - */ -struct dirent * -readdir(dirp) -DIR *dirp; -{ - int cc; - cc = read(dirp->dd_fd, dirp->dd_buf, sizeof(struct dirent)); - - if (cc <= 0) - return 0; - if (cc != sizeof(struct dirent)) - { - errno = EBADF; - return 0; - } - return dirp->dd_buf; -} -#endif -#else - -/* This is for 386 linux */ - #ifdef L_readdir struct dirent * readdir(dirp) @@ -103,4 +76,3 @@ DIR *dirp; } #endif -#endif diff --git a/libc/syscall/exec.c b/libc/syscall/exec.c index 411b744..8337f11 100644 --- a/libc/syscall/exec.c +++ b/libc/syscall/exec.c @@ -107,7 +107,7 @@ char ** envp; } *pip++ = 0; - rv = __exec(fname, stk_ptr, stack_bytes); + rv = __execve(fname, stk_ptr, stack_bytes); /* FIXME: This will probably have to interpret '#!' style exe's */ sbrk(-stack_bytes); return rv; @@ -283,7 +283,7 @@ char ** envp; } *pip++ = 0; - rv = __exec(fname, stk_ptr, stack_bytes); + rv = __execve(fname, stk_ptr, stack_bytes); /* FIXME: This will probably have to interpret '#!' style exe's */ sbrk(-stack_bytes); return rv; diff --git a/libc/syscall/mkentry.sh b/libc/syscall/mkentry.sh new file mode 100644 index 0000000..aae4904 --- /dev/null +++ b/libc/syscall/mkentry.sh @@ -0,0 +1,83 @@ +#!/bin/sh - +# +# This program generates entry.c from syscall.dat + +cat << \Trailer +/* Switched to V7 system call layout... Chad - 1/5/96 +*/ +#asm +* +* The call table - autogenerated from syscall.dat +* + .data +sys_call_table: +Trailer + +tr '[A-Z]' '[a-z]' < syscall.dat | \ +awk '/^#/{next;} +/^[ ]$/{next;} +{ + callno = 0+$2; + if( $4 != "-" ) + assigned_to[callno] = $1; + + if( $3 == "x" || $3 == "" ) next; + else if( $4 == "@" || $4 == "-" ) next; + + # Not implemented yet + if( substr($2, 1, 1) != "+" ) next; + + if( maxno < callno ) maxno = callno; + + str = "\t.word _sys_" $1; + line[callno] = sprintf("%-25s ! %d", str, callno); +} +END{ + for(callno=0; callno<=maxno; callno++) + { + if( assigned_to[callno] == "fork" ) + gsub("_sys_fork", "_do_fork ", line[callno]); + + if( callno in line ) + print line[callno]; + else + { + if( assigned_to[callno] == "" ) + assigned_to[callno] = "unassigned"; + if( assigned_to[callno] == "vfork" ) + { + str = "\t.word _do_fork"; + } + else + str = "\t.word _no_syscall"; + printf "%-25s ! %d - %s\n", str, callno, assigned_to[callno]; + } + } +} +' + +cat <<\Trailer +sys_call_table_end: + +* +* Despatch a syscall (called from syscall_int) +* Entry: ax=function code, stack contains parameters +* + .text + .globl _syscall +_syscall: + cmp ax,#((sys_call_table_end - sys_call_table)/2) + ja _no_syscall + ! look up address and jump to function + mov bx,ax + shl bx,#1 ! multiply by 2 + add bx,#sys_call_table + j [bx] +* +* Unimplemented calls +* +_no_syscall: + mov ax,#-38 + ret +#endasm +Trailer diff --git a/libc/syscall/mksyscall b/libc/syscall/mksyscall index f7b91a6..190554c 100644 --- a/libc/syscall/mksyscall +++ b/libc/syscall/mksyscall @@ -15,7 +15,16 @@ COMPACT=1 -rm -f syscall.c syscall.mak call_tab.v defn_tab.v +rm -f syscall.c syscall.mak call_tab.v defn_tab.v syscall.dat + +if [ -r ${ELKSSRC}/arch/i86/kernel/syscall.dat \ + -a ! -r ${TOPDIR}/libc/kinclude/Used ] + +then echo Using syscalls from ${ELKSSRC} + cp -p ${ELKSSRC}/arch/i86/kernel/syscall.dat syscall.dat +else echo Using syscalls from syscall.dev86 + cp -p syscall.dev86 syscall.dat +fi tr '[A-Z]' '[a-z]' < syscall.dat | \ awk -v COMPACT=$COMPACT 'BEGIN{ @@ -148,16 +157,18 @@ awk -v COMPACT=$COMPACT 'BEGIN{ /^[ ]*#/ { next; } /^[ ]*$/ { next; } { - if( $2 > max_call ) max_call = $2; - if( !($2 in calltab) ) - callwas[$2] = " /* " $1 " */"; + callno = 0+$2; + if( !(callno in calltab) ) + callwas[callno] = " /* " $1 " */"; if( $3 == "x" || $3 == "" ) next; - else if( $4 == "-" ) next; + else if( $4 == "@" || $4 == "-" ) next; else if( $4 == "*" ) funcname="__" $1; else funcname=$1; - calltab[$2] = $1; + if( callno > max_call ) max_call = callno; + + calltab[callno] = $1; if( length(obj) > 60 ) { @@ -178,14 +189,14 @@ awk -v COMPACT=$COMPACT 'BEGIN{ { if( $3 == 0 ) { - printf(" mov ax,#%d\n", $2); + printf(" mov ax,#%d\n", callno); } else { printf("#if __FIRST_ARG_IN_AX__\n"); - printf(" mov dx,#%d\n", $2); + printf(" mov dx,#%d\n", callno); printf("#else\n"); - printf(" mov ax,#%d\n", $2); + printf(" mov ax,#%d\n", callno); printf("#endif\n"); } printf(" br sys_call%d\n", $3); @@ -231,7 +242,7 @@ awk -v COMPACT=$COMPACT 'BEGIN{ if( $3 >= 1 ) printf("#endif\n"); - printf(" mov ax,#%d\n", $2); + printf(" mov ax,#%d\n", callno); printf(" int $80\n"); diff --git a/libc/syscall/syscall.dat b/libc/syscall/syscall.dat deleted file mode 100644 index de5ed9b..0000000 --- a/libc/syscall/syscall.dat +++ /dev/null @@ -1,142 +0,0 @@ -# -# Name No Args Flag, comment -# -# . = Ok, with comment -# * = Needs libc code (Prefix __) -# - = Obsolete/not required -# -# WARNING! -# This file is used to generate includes for ELKSemu too. -# This file is continually changing, when you upgrade you _MUST_ ensure -# that ELKSemu is of a matching build! -# -# Calls that use one fd -READ 3 3 -WRITE 4 3 -CLOSE 6 1 -LSEEK 19 3 * NB 2nd arg is an IO ptr to long not a long. -FSTAT 28 2 -IOCTL 54 3 . Make this and fcntl the same ? -FCNTL 55 3 -FTRUNCATE 93 3 -FCHMOD 94 2 -FCHOWN 95 3 -FSYNC 118 1 -FCHDIR 133 1 -LLSEEK 140 3 * 2nd arg is ptr to two longs -READV 145 3 -WRITEV 146 3 -FLOCK 143 2 - Use fcntl -DUP 41 1 - Using nasty fcntl function - -# -SETUP 0 X -EXIT 1 1 * C exit does stdio, _exit in crt0 -FORK 2 0 -OPEN 5 3 -WAIT4 7 4 -VFORK 8 0 . Needed for 8086 -GETINFO 49 1 - Possible? Gets pid,ppid,uid,euid etc -LINK 9 2 -UNLINK 10 1 -EXEC 11 3 * Minix style exec -CHDIR 12 1 -GETTIMEOFDAY 13 2 . time() exists only in libc -MKNOD 14 3 -CHMOD 15 2 -CHOWN 16 3 -BRK 17 1 * This is only to tell the system -STAT 18 2 -GETPID 20 1 * This gets both pid & ppid -MOUNT 21 5 -UMOUNT 22 1 -SETUID 23 1 -GETUID 24 1 * This gets both uid and euid -SETTIMEOFDAY 25 2 . STIME should _NOT_ exist even as a libc. -STIME 25 2 - This must NOT exist - even as a libc. -PTRACE 26 4 -ALARM 27 2 -PAUSE 29 0 -UTIME 30 2 -ACCESS 33 2 -NICE 34 1 . -FTIME 35 1 - Use gettimeofday -SYNC 36 0 -KILL 37 2 -RENAME 38 2 -MKDIR 39 2 -RMDIR 40 1 -PIPE 42 1 -TIMES 43 2 * 2nd arg is pointer for long ret val. -SETGID 46 1 -GETGID 47 1 * This gets both gid and egid -SIGNAL 48 2 * Have put the despatch table in user space. -ACCT 51 1 - -SETPGID 57 2 -ULIMIT 58 2 -UMASK 60 1 -CHROOT 61 1 -USTAT 62 2 -GETPGRP 65 0 - use getpgid(0) -SETSID 66 0 -SIGACTION 67 X -SGETMASK 68 X -SSETMASK 69 X -SETREUID 70 2 -SETREGID 71 2 -SIGSUSPEND 72 X -SIGPENDING 73 X -SETHOSTNAME 74 2 -SETRLIMIT 75 2 -GETRLIMIT 76 2 -GETRUSAGE 77 2 -GETGROUPS 80 2 -SETGROUPS 81 2 -SYMLINK 83 2 -LSTAT 84 2 -READLINK 85 3 -SWAPON 87 X -REBOOT 88 3 . The magic number is 0xfee1,0xdead,... -MUNMAP 91 X -TRUNCATE 92 3 -GETPRIORITY 96 2 -SETPRIORITY 97 3 -PROFIL 98 X -STATFS 99 2 -FSTATFS 100 2 -SOCKETCALL 102 X -SYSLOG 103 X -SETITIMER 104 3 -GETITIMER 105 2 -UNAME 109 1 -VHANGUP 111 0 -SWAPOFF 115 X -SYSINFO 116 X - Use /proc -IPC 117 5 * This is for all SYSV IPC -SIGRETURN 119 X -SETDOMAINNAME 121 X -ADJTIMEX 124 X -MPROTECT 125 X -SIGPROCMASK 126 X -QUOTACTL 131 X -GETPGID 132 1 -SYSFS 135 X -PERSONALITY 136 X -SETFSUID 138 1 -SETFSGID 139 1 -GETDENTS 141 X -SELECT 142 5 * -MSYNC 144 X -GETSID 147 X -FDATASYNC 148 X -SYSCTL 149 X -MUNLOCK 151 X -MUNLOCKALL 153 X -SCHED_SETPARAM 154 X -SCHED_GETPARAM 155 X -SCHED_SETSCHEDULER 156 X -SCHED_GETSCHEDULER 157 X -SCHED_YIELD 158 X -SCHED_GET_PRIORITY_MAX 159 X -SCHED_GET_PRIORITY_MIN 160 X -SCHED_RR_GET_INTERVAL 161 X diff --git a/libc/syscall/syscall.dev86 b/libc/syscall/syscall.dev86 new file mode 100644 index 0000000..29e7b5e --- /dev/null +++ b/libc/syscall/syscall.dev86 @@ -0,0 +1,160 @@ +# +# WARNING! +# This file is used to generate the system call lists for Dev86(elks) +# ELKSemu and elks itself. Changes to this may require changes in +# all three of those packages. +# +# . = Ok, with comment +# * = Needs libc code (Prefix __) +# - = Obsolete/not required +# @ = May be required later +# +# An initial plus on the call number specifies that this call is +# implemented in the kernel. +# +# Package versions are matched. +# Dev86/Elksemu version - 0.13.1 +# Elks version - 0.0.66 +# +# Name No Args Flag, comment +# +exit +1 1 * c exit does stdio, _exit in crt0 +fork +2 0 +read +3 3 +write +4 3 +open +5 3 +close +6 1 +wait4 +7 4 +creat 8 0 - Not needed alias for open +link +9 2 +unlink +10 1 +execve +11 3 * execve minix style +chdir +12 1 +time 13 1 - Use settimeofday +mknod +14 3 +chmod +15 2 +chown +16 3 +brk +17 1 * This is only to tell the system +stat +18 2 +lseek +19 3 * nb 2nd arg is an io ptr to long not a long. +getpid +20 1 * this gets both pid & ppid +mount +21 5 +umount +22 1 +setuid +23 1 +getuid +24 1 * this gets both uid and euid +stime 25 2 - this must not exist - even as a libc. +ptrace 26 4 @ adb/sdb/dbx need this. +alarm 27 2 +fstat +28 2 +pause 29 0 +utime 30 2 +chroot +31 1 +vfork 32 0 +access +33 2 +nice 34 1 +sleep 35 1 +sync +36 0 +kill 37 2 +rename +38 2 +mkdir +39 2 +rmdir +40 1 +dup +41 1 . There is a fcntl lib function too. +pipe 42 1 +times 43 2 * 2nd arg is pointer for long ret val. +profil 44 4 @ +dup2 +45 2 +setgid +46 1 +getgid 47 1 * this gets both gid and egid +signal 48 2 * have put the despatch table in user space. +getinfo 49 1 @ possible? gets pid,ppid,uid,euid etc +fcntl +50 3 +acct 51 1 @ Accounting to named file (off if null) +phys 52 3 - Replaced my mmap() +lock 53 1 @ Prevent swapping for this proc if flg!=0 +ioctl +54 3 . make this and fcntl the same ? +reboot +55 3 . the magic number is 0xfee1,0xdead,... +mpx 56 2 - Replaced by fifos and select. +lstat +57 2 +symlink +58 2 +readlink +59 3 +umask +60 1 +settimeofday 61 2 +gettimeofday 62 2 +select 63 5 * +readdir +64 3 * + +# +# Name No Args Flag&comment +# +# ( awk '{$2=NR+500;OFS="\t";print ;}'| expand -24,32,40 | unexpand ) <