2 * The functions in this file negotiate with the operating system for
3 * characters, and write characters in a barely buffered fashion on the display.
4 * All operating systems.
13 #define AMG_MAXBUF 1024
15 static char scrn_tmp
[AMG_MAXBUF
+1];
16 static int scrn_tmp_p
= 0;
26 #define NIBUF 128 /* Input buffer size */
27 #define NOBUF 1024 /* MM says bug buffers win! */
28 #define EFN 0 /* Event flag */
30 char obuf
[NOBUF
]; /* Output buffer */
31 int nobuf
; /* # of bytes in above */
32 char ibuf
[NIBUF
]; /* Input buffer */
33 int nibuf
; /* # of bytes in above */
34 int ibufi
; /* Read index */
35 int oldmode
[2]; /* Old TTY mode bits */
36 int newmode
[2]; /* New TTY mode bits */
37 short iochan
; /* TTY I/O channel */
54 #include <sgtty.h> /* for stty/gtty functions */
55 struct sgttyb ostate
; /* saved tty state */
56 struct sgttyb nstate
; /* values for editor mode */
60 * This function is called once to set up the terminal device streams.
61 * On VMS, it translates SYS$INPUT until it finds the terminal, then assigns
62 * a channel to it and sets it raw. On CPM it is a no-op.
67 terminal
= Open("RAW:1/1/639/399/MicroEmacs", MODE_NEWFILE
);
68 return (terminal
!= 0);
72 struct dsc$descriptor idsc
;
73 struct dsc$descriptor odsc
;
78 odsc
.dsc$a_pointer
= "SYS$INPUT";
79 odsc
.dsc$w_length
= strlen(odsc
.dsc$a_pointer
);
80 odsc
.dsc$b_dtype
= DSC$K_DTYPE_T
;
81 odsc
.dsc$b_class
= DSC$K_CLASS_S
;
82 idsc
.dsc$b_dtype
= DSC$K_DTYPE_T
;
83 idsc
.dsc$b_class
= DSC$K_CLASS_S
;
85 idsc
.dsc$a_pointer
= odsc
.dsc$a_pointer
;
86 idsc
.dsc$w_length
= odsc
.dsc$w_length
;
87 odsc
.dsc$a_pointer
= &oname
[0];
88 odsc
.dsc$w_length
= sizeof(oname
);
89 status
= LIB$
SYS_TRNLOG(&idsc
, &odsc
.dsc$w_length
, &odsc
);
90 if (status
!=SS$_NORMAL
&& status
!=SS$_NOTRAN
)
92 if (oname
[0] == 0x1B) {
93 odsc
.dsc$a_pointer
+= 4;
94 odsc
.dsc$w_length
-= 4;
96 } while (status
== SS$_NORMAL
);
97 status
= SYS$
ASSIGN(&odsc
, &iochan
, 0, 0);
98 if (status
!= SS$_NORMAL
)
100 status
= SYS$
QIOW(EFN
, iochan
, IO$_SENSEMODE
, iosb
, 0, 0,
101 oldmode
, sizeof(oldmode
), 0, 0, 0, 0);
102 if (status
!=SS$_NORMAL
|| (iosb
[0]&0xFFFF)!=SS$_NORMAL
)
104 newmode
[0] = oldmode
[0];
105 newmode
[1] = oldmode
[1] | TT$M_PASSALL
| TT$M_NOECHO
;
106 status
= SYS$
QIOW(EFN
, iochan
, IO$_SETMODE
, iosb
, 0, 0,
107 newmode
, sizeof(newmode
), 0, 0, 0, 0);
108 if (status
!=SS$_NORMAL
|| (iosb
[0]&0xFFFF)!=SS$_NORMAL
)
116 gtty(1, &ostate
); /* save old state */
117 gtty(1, &nstate
); /* get base of new state */
118 nstate
.sg_flags
|= RAW
;
119 nstate
.sg_flags
&= ~(ECHO
|CRMOD
); /* no echo for now... */
120 stty(1, &nstate
); /* set mode */
125 * This function gets called just before we go back home to the command
126 * interpreter. On VMS it puts the terminal back in a reasonable state.
127 * Another no-operation on CPM.
140 status
= SYS$
QIOW(EFN
, iochan
, IO$_SETMODE
, iosb
, 0, 0,
141 oldmode
, sizeof(oldmode
), 0, 0, 0, 0);
142 if (status
!=SS$_NORMAL
|| (iosb
[0]&0xFFFF)!=SS$_NORMAL
)
144 status
= SYS$
DASSGN(iochan
);
145 if (status
!= SS$_NORMAL
)
158 * Write a character to the display. On VMS, terminal output is buffered, and
159 * we just put the characters in the big array, after checking for overflow.
160 * On CPM terminal I/O unbuffered, so we just write the byte out. Ditto on
161 * MS-DOS (use the very very raw console output routine).
169 scrn_tmp
[scrn_tmp_p
++] = c
;
170 if(scrn_tmp_p
>=AMG_MAXBUF
)
188 Put_Char(c
); /* fast video */
199 Write(terminal
,scrn_tmp
,scrn_tmp_p
);
204 * Flush terminal buffer. Does real work where the terminal output is buffered
205 * up. A no-operation on systems where byte at a time terminal I/O is done.
219 status
= SYS$
QIOW(EFN
, iochan
, IO$_WRITELBLK
|IO$M_NOFORMAT
,
220 iosb
, 0, 0, obuf
, nobuf
, 0, 0, 0, 0);
221 if (status
== SS$_NORMAL
)
222 status
= iosb
[0] & 0xFFFF;
240 * Read a character from the terminal, performing no editing and doing no echo
241 * at all. More complex in VMS that almost anyplace else, which figures. Very
242 * simple on CPM, because the system can do exactly what you want.
249 Read(terminal
, &ch
, 1);
257 while (ibufi
>= nibuf
) {
261 status
= SYS$
QIOW(EFN
, iochan
, IO$_READLBLK
|IO$M_TIMED
,
262 iosb
, 0, 0, ibuf
, NIBUF
, 0, term
, 0, 0);
263 if (status
!= SS$_NORMAL
)
265 status
= iosb
[0] & 0xFFFF;
266 if (status
!=SS$_NORMAL
&& status
!=SS$_TIMEOUT
)
268 nibuf
= (iosb
[0]>>16) + (iosb
[1]>>16);
270 status
= SYS$
QIOW(EFN
, iochan
, IO$_READLBLK
,
271 iosb
, 0, 0, ibuf
, 1, 0, term
, 0, 0);
272 if (status
!= SS$_NORMAL
273 || (status
= (iosb
[0]&0xFFFF)) != SS$_NORMAL
)
275 nibuf
= (iosb
[0]>>16) + (iosb
[1]>>16);
278 return (ibuf
[ibufi
++] & 0xFF); /* Allow multinational */
282 return (biosb(BCONIN
, 0, 0));
288 while ((Ch
= Read_Keyboard()) < 0);
290 if ((Ch
& Function_Key
) == 0)
291 if (!((Ch
& 0xFF) == 015 || (Ch
& 0xFF) == 0177))
298 return (dosb(CONRAW
, 0, 0));
302 return(fgetc(stdin
));