home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-04-04 | 45.2 KB | 1,924 lines |
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 2 (of 3)."
- # Contents: 8250dtr.c 8250xon.c _kb.c options.c screen.c
- # Wrapped by jb@deneb on Sat Mar 24 10:42:18 1990
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f '8250dtr.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'8250dtr.c'\"
- else
- echo shar: Extracting \"'8250dtr.c'\" \(11252 characters\)
- sed "s/^X//" >'8250dtr.c' <<'END_OF_FILE'
- X/*
- X * DTR8250.C
- X *
- X * NSC8250 DTR Handshake ISR Module
- X *
- X * Written for the
- X *
- X * Datalight
- X * Microsoft V 5.x
- X * TurboC
- X * &
- X * Zortech
- X *
- X * C Compilers
- X *
- X * Copyright (c) John Birchfield 1987, 1988, 1989
- X */
- X
- X#include <stdio.h>
- X#include "dependnt.h"
- X#include "queue.h"
- X#include "8250nsc.h"
- X#include "8250dtr.h"
- X#include "timer.h"
- X
- X#if (!defined (TRUE))
- X# define TRUE (1)
- X# define FALSE (0)
- X#endif
- X
- unsigned DTR_PORT_channel; /* Either 1 or 2 for COM1 or COM2 */
- char dtr8250_SAVE_int_mask, /* saved interrupt controller mask word */
- X dtr8250_IER_save = 0, /* Saved off Interrupt Enable Register */
- X dtr8250_LCR_save = 0, /* Saved off Line Control Register */
- X dtr8250_MCR_save = 0, /* Saved off Modem Control Register */
- X dtr8250_DL_lsb = 0, /* Saved off Baud Rate LSB */
- X dtr8250_DL_msb = 0; /* Saved off Baud Rate MSB */
- X
- X
- X
- volatile unsigned DTR_PORT_addr;
- volatile char DTR_PORT_status, RCV_disabled = FALSE, XMIT_disabled = TRUE, dtr8250_MSR_reg = 0;
- volatile QUEUE *dtr8250_inqueue;
- X#if (defined (DLC))
- extern void outp ();
- X#endif
- X
- X
- X#define DISABLE_xmit outbyte (DTR_PORT_addr+IER, RX_enable)
- X#define ENABLE_xmit outbyte (DTR_PORT_addr+IER, RX_TX_enable)
- X#define DROPPED_cts ((dtr8250_MSR_reg&0x10)==0)
- X#define DROPPED_dsr ((dtr8250_MSR_reg&0x20)==0)
- X#define DROPPED_dtr ((dtr8250_MSR_reg&0x30)!=0x30)
- X#define ASSERT_dtr outbyte (inbyte (DTR_PORT_addr+MCR)|9, DTR_PORT_addr+MCR)
- X#define DROP_dtr outbyte (inbyte (DTR_PORT_addr+MCR)&0x0A, DTR_PORT_addr+MCR)
- X#define ASSERT_rts outbyte (inbyte (DTR_PORT_addr+MCR)|0x0A, DTR_PORT_addr+MCR)
- X#define DROP_rts outbyte (inbyte (DTR_PORT_addr+MCR)&9, DTR_PORT_addr+MCR)
- X#define TSRE_bit 0x40
- X
- X
- X
- X/*
- X * DTR8250_ISR - This Interrupt Service Routine attached to either COM1
- X * or COM2. It drives the NSC8250 with Hardware
- X * Handshaking. i.e. Flow of Control is maintained by
- X * RTS (Request to Send) CTS (Clear to Send) Logic.
- X * After installation by Catch_Rt, it catches the
- X * 8250 interrupts and en_queues incoming characters
- X * from the Serial Port - and de-queues outgoing
- X * characters to the Serial Port.
- X */
- X
- X#if (!defined (DLC))
- void (interrupt far * dtr_save_vec) (void);
- void interrupt far
- dtr8250_isr (void)
- X#else
- int
- dtr8250_isr ()
- X#endif
- X{
- X int ch;
- X char test_status;
- X
- X enable ();
- X test_status = inbyte ((DTR_PORT_addr + IIR));
- X do
- X {
- X switch (test_status)
- X {
- X
- X case IIR_rls:
- X DTR_PORT_status |= inbyte ((DTR_PORT_addr + LSR));
- X break;
- X
- X case IIR_receive:
- X ch = inbyte (DTR_PORT_addr);
- X if ((en_queue (dtr8250_inqueue, ch) < 10) && !RCV_disabled)
- X {
- X RCV_disabled = TRUE;
- X DROP_dtr;
- X }
- X else
- X if (RCV_disabled && (queue_avail (dtr8250_inqueue) > 20))
- X {
- X RCV_disabled = FALSE;
- X ASSERT_dtr;
- X }
- X break;
- X
- X case IIR_transmit:
- X DISABLE_xmit;
- X break;
- X
- X case IIR_mstatus:
- X dtr8250_MSR_reg = inbyte (DTR_PORT_addr + MSR);
- X if (RCV_disabled && (queue_avail (dtr8250_inqueue) > 20))
- X {
- X RCV_disabled = FALSE;
- X ASSERT_dtr;
- X }
- X break;
- X }
- X } while ((test_status = inbyte (DTR_PORT_addr + IIR)) != IIR_complete);
- X disable ();
- X outbyte (INT_cntrl, EOI_word);
- X#if (defined (DLC))
- X return (1);
- X#endif
- X}
- X
- X
- X
- X
- X/*
- X * DTR8250_INIT - Here we get the address of the 8250 Port
- X * which corresponds to the channel passed in.
- X * We then massage the 8259 Interrupt Controller
- X * calculate the Physical Interrupt and save off
- X * the 8250's current contents. Then attach the
- X * nsc8250_interrupt routine to the interrupt and
- X * return the rt returned index for saving - it's
- X * needed to terminate the interrupt.
- X */
- X
- X#define DTR8250_STACK_SIZE 1024
- int dtr8250_intno;
- static int dtr_intmask [] = { 0xef, 0xf7, 0xef, 0xf7 };
- X/*
- X * The above 8259 mask bits are determined from the formula
- X * mask = ~(1 << (5 - PORT_CHANNEL));
- X * The array assumes that COM3 and COM4 use the same interrupts
- X * as COM1 and COM2.
- X */
- static int dtr_intno [] = { 12, 11, 12, 11 };
- X/*
- X * The above interrupt number array is based on the algorithm
- X * dtr8250_intno = (13 - PORT_channel);
- X */
- X
- X
- void
- dtr8250_init (channel, buf_size)
- int channel, buf_size;
- X{
- X int Dos_address, mask;
- X DTR_PORT_channel = channel;
- X dtr8250_inqueue = alloc_queue (buf_size);
- X Dos_address = (DTR_PORT_channel - 1) * 2;
- X peekmem (0x40, Dos_address, DTR_PORT_addr);
- X mask = dtr_intmask [DTR_PORT_channel-1];
- X dtr8250_SAVE_int_mask = inbyte (INT_mask);
- X mask &= dtr8250_SAVE_int_mask;
- X dtr8250_intno = dtr_intno [DTR_PORT_channel-1];
- X dtr8250_LCR_save = inbyte (DTR_PORT_addr + LCR);
- X disable ();
- X outbyte (DTR_PORT_addr + LCR, dtr8250_LCR_save | LCR_DLAB);
- X dtr8250_MCR_save = inbyte (DTR_PORT_addr + MCR);
- X dtr8250_DL_lsb = inbyte (DTR_PORT_addr);
- X dtr8250_DL_msb = inbyte (DTR_PORT_addr + 1);
- X outbyte (DTR_PORT_addr + LCR, dtr8250_LCR_save & 0x7F);
- X dtr8250_IER_save = inbyte (DTR_PORT_addr + IER);
- X enable ();
- X#if (defined (DLC))
- X int_intercept (dtr8250_intno, &dtr8250_isr, DTR8250_STACK_SIZE);
- X#else
- X dtr_save_vec = getvect (dtr8250_intno);
- X setvect (dtr8250_intno, dtr8250_isr);
- X#endif
- X DELAY_init ();
- X outbyte (INT_mask, mask);
- X}
- X
- X
- X
- X
- X/*
- X * DTR8250_TERM - This routine restores the RS232 Vector back to its
- X * state before DTR8250_INIT was called.
- X */
- X
- void
- dtr8250_term (int restore)
- X{
- X disable ();
- X outbyte (INT_mask, dtr8250_SAVE_int_mask);
- X if (restore)
- X {
- X outbyte (DTR_PORT_addr + LCR, LCR_DLAB);
- X outbyte (DTR_PORT_addr, dtr8250_DL_lsb);
- X outbyte (DTR_PORT_addr + 1, dtr8250_DL_msb);
- X outbyte (DTR_PORT_addr + MCR, dtr8250_MCR_save);
- X outbyte (DTR_PORT_addr + LCR, 0x7F);
- X outbyte (DTR_PORT_addr + IER, dtr8250_IER_save);
- X outbyte (DTR_PORT_addr + LCR, dtr8250_LCR_save);
- X }
- X#if (defined (DLC))
- X int_restore (dtr8250_intno);
- X#else
- X setvect (dtr8250_intno, dtr_save_vec);
- X#endif
- X}
- X
- X
- X
- X
- X/*
- X * DTR8250_READ - this routine looks in the RS232hw_inqueue for a character
- X *
- X */
- X
- int
- dtr8250_read (void)
- X{
- X int ch;
- X disable ();
- X ch = de_queue (dtr8250_inqueue);
- X enable ();
- X return (ch);
- X}
- X
- X
- X
- X
- X/*
- X * DTR8250_TIMED_READ - attempts to read rs232 port - if no char
- X * available in number of seconds passed
- X * returns -1
- X */
- X
- int
- dtr8250_timed_read (int sec)
- X{
- X int ch;
- X
- X timer_set ();
- X while ((ch = dtr8250_read ()) == -1)
- X if ((timer_read () / 18) > sec)
- X break;
- X return (ch);
- X}
- X
- X
- X
- X
- X/*
- X * DTR8250_WRITE - plain vanilla write to the port - check to see that
- X * the chip may need a kick in the pants before returning
- X */
- X
- int
- dtr8250_write (char ch)
- X{
- X while ((inbyte (DTR_PORT_addr + LSR) & TSRE_bit) == 0)
- X ;
- X dtr8250_MSR_reg = inbyte ((DTR_PORT_addr + MSR));
- X if (DROPPED_dtr)
- X return -1;
- X outbyte (DTR_PORT_addr, ch);
- X if (RCV_disabled && (queue_avail (dtr8250_inqueue) > 20))
- X {
- X RCV_disabled = FALSE;
- X ASSERT_dtr;
- X }
- X}
- X
- X
- X
- X
- X/*
- X * DTR8250_DTRNR - drop Data Terminal Ready Line
- X */
- void
- dtr8250_dtnr (void)
- X{
- X char mcr_save;
- X disable ();
- X mcr_save = inbyte (DTR_PORT_addr + MCR);
- X outbyte (DTR_PORT_addr + MCR, 0);
- X DELAY_loop (500);
- X outbyte (DTR_PORT_addr + MCR, mcr_save);
- X enable ();
- X}
- X
- X
- X
- X
- X/*
- X * DTR8250_GET_STATUS - returns the current NSC8250 status and
- X * resets any error condition.
- X */
- X
- int
- dtr8250_get_status (void)
- X{
- X char rval = DTR_PORT_status;
- X DTR_PORT_status &= ERROR_reset;
- X return ((int) rval);
- X}
- X
- X
- X
- X
- X
- X/*
- X * DTR8250_MODEM_STATUS - returns the current NSC8250 Modm Status Register
- X * contents.
- X */
- X
- int
- dtr8250_modem_status (void)
- X{
- X dtr8250_MSR_reg = inbyte (DTR_PORT_addr + MSR);
- X return ((int) dtr8250_MSR_reg);
- X}
- X
- X
- X
- X
- X
- X/*
- X * DTR8250_WRITE_BREAK - Write a BREAK Character
- X */
- X
- void
- dtr8250_write_break (void)
- X{
- X int i;
- X disable ();
- X while ((inbyte (DTR_PORT_addr + LSR) & 0x40) == 0)
- X ;
- X outbyte (DTR_PORT_addr + LCR, inbyte (DTR_PORT_addr + LCR) | 0x40);
- X for (i = 0; i < 13000; i++)
- X ;
- X outbyte (DTR_PORT_addr + LCR, inbyte (DTR_PORT_addr + LCR) & 0xBF);
- X enable ();
- X}
- X
- X
- X
- X
- X
- X/*
- X * DTR8250_PORT_INIT (Cmd) configures the 8250
- X * cmd is a string of the form baud parity stop data i.e
- X * 300 n 1 8
- X *
- X * baud - 300, 600, 1200, 2400, 4800, 9600
- X * parity - n -> no parity check
- X * o -> odd parity
- X * e -> even parity
- X * stop - 1 -> 1 stop bit
- X * 2 -> 2 stop bits
- X * data - 5, 6, 7, 8 data bits
- X */
- X
- void
- dtr8250_port_init (cmd)
- char *cmd;
- X{
- X unsigned baud, data, mode_word, parity, stop, xoff;
- X char pty[2];
- X sscanf (cmd, "%d %1s %d %d", &baud, pty, &stop, &data);
- X *pty = toupper (*pty);
- X switch (*pty)
- X {
- X case 'E':
- X parity = 3;
- X break;
- X case 'O':
- X parity = 1;
- X break;
- X case 'N':
- X parity = 0;
- X break;
- X default:
- X parity = 0;
- X break;
- X }
- X stop = (--stop & 1);
- X stop <<= 2;
- X baud /= 10;
- X baud = 11520 / baud;
- X parity <<= 3;
- X parity &= 0x018;
- X data -= 5;
- X data &= 3;
- X mode_word = data | stop | parity;
- X disable ();
- X outbyte (DTR_PORT_addr + LCR, inbyte (DTR_PORT_addr + LCR) | LCR_DLAB);
- X outbyte (DTR_PORT_addr, baud % 256);
- X outbyte (DTR_PORT_addr + 1, baud / 256);
- X outbyte (DTR_PORT_addr + LCR, mode_word & 0x7F);
- X outbyte (DTR_PORT_addr + IER, RX_enable);
- X outbyte (DTR_PORT_addr + MCR, 0x0B);
- X
- X inbyte (DTR_PORT_addr + LSR);
- X dtr8250_MSR_reg = inbyte ((DTR_PORT_addr + MSR));
- X inbyte (DTR_PORT_addr);
- X enable ();
- X}
- X
- X
- X
- X
- X/*---------------------- dtr8250_port_enable () ----------------------*/
- X/*
- X *
- X */
- void
- dtr8250_port_enable (void)
- X{
- X disable ();
- X outbyte (DTR_PORT_addr + IER, RX_enable);
- X outbyte (DTR_PORT_addr + MCR, 0x0B);
- X
- X inbyte (DTR_PORT_addr + LSR);
- X dtr8250_MSR_reg = inbyte ((DTR_PORT_addr + MSR));
- X inbyte (DTR_PORT_addr);
- X enable ();
- X}
- X
- X
- X
- X
- X/*------------------------ dtr8250_lines () ------------------------*/
- X/*
- X *
- X */
- void
- dtr8250_lines (void)
- X{
- X printf ("8250 DTR_PORT_addr = %04x\n", DTR_PORT_addr);
- X printf ("8250 MSR = %02x\n", inbyte (DTR_PORT_addr + MSR));
- X}
- END_OF_FILE
- if test 11252 -ne `wc -c <'8250dtr.c'`; then
- echo shar: \"'8250dtr.c'\" unpacked with wrong size!
- fi
- # end of '8250dtr.c'
- fi
- if test -f '8250xon.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'8250xon.c'\"
- else
- echo shar: Extracting \"'8250xon.c'\" \(12190 characters\)
- sed "s/^X//" >'8250xon.c' <<'END_OF_FILE'
- X/*
- X * 8250XON.C
- X *
- X * NSC8250 RS232 Xon/Xoff ISR Routine
- X *
- X * Written for the
- X *
- X * Datalight
- X * Microsoft V 5.x
- X * TurboC
- X * &
- X * Zortech
- X *
- X * C Compilers
- X *
- X * Copyright (c) John Birchfield 1987, 1988, 1989
- X */
- X
- X
- X#include <stdio.h>
- X#include "dependnt.h"
- X#include "delay.h"
- X#include "8250nsc.h"
- X#include "8250xon.h"
- X#include "queue.h"
- X#include "timer.h"
- X
- X#if (!defined (TRUE))
- X# define TRUE (1)
- X# define FALSE (0)
- X#endif
- X
- X
- X#define I_BUF_SIZE 4096 /* inbyteut Buffer Size */
- X#define O_BUF_SIZE 4096 /* output Buffer Size */
- X
- volatile unsigned XON_PORT_address = 0x03F8;
- volatile char xoff_enabled = FALSE,
- X xoff_sent = FALSE,
- X xoff_received = FALSE,
- X XON_PORT_status = 0,
- X XON_PORT_state = 0,
- X XON_PORT_command = 0,
- X XON_char = 0x11,
- X XOFF_char = 0x13;
- X
- char XON_PORT_channel = 1,
- X SAVE_int_mask = 0, /* saved interrupt controller mask word */
- X
- X/*
- X * 8250 register save locations and base address offsets
- X */
- X IER_save = 0, LCR_save = 0, MCR_save = 0, DL_lsb = 0, DL_msb = 0;
- X
- X
- X
- X
- QUEUE *xon8250_inqueue, *xon8250_outqueue;
- X
- X/*
- X * XON8250_ISR - This is the interrupt handler for the
- X * National Semiconducter 8250 Serial Chip.
- X * After installation by Catch_Rt, it catches the
- X * 8250 interrupts and en_queues incoming characters
- X * from the Serial Port - and de-queues outgoing
- X * characters to the Serial Port. The original code
- X * was written in assembler and provided about 80%
- X * of the Port's Bandwidth at 9600 baud running
- X * An Xmodem protocol. We'll see what this does...
- X */
- X
- X#if (!defined (DLC))
- void (interrupt far * xon_save_vec) (void);
- void interrupt far
- xon8250_isr (void)
- X#else
- int
- xon8250_isr ()
- X#endif
- X{
- X int ch;
- X char test_status;
- X
- X enable ();
- X test_status = inbyte ((XON_PORT_address + IIR));
- X do
- X {
- X switch (test_status)
- X {
- X case IIR_rls:
- X XON_PORT_status |= inbyte ((XON_PORT_address + LSR));
- X break;
- X
- X case IIR_receive:
- X ch = inbyte (XON_PORT_address);
- X if ((xoff_enabled && !xoff_sent) &&
- X (ch == XOFF_char))
- X {
- X xoff_received = TRUE;
- X }
- X else
- X if (xoff_received &&
- X (ch == XON_char))
- X {
- X xoff_received = FALSE;
- X outbyte (XON_PORT_address + IER, XON_PORT_command = RX_TX_enable);
- X }
- X else
- X if ((en_queue (xon8250_inqueue, ch) < 10) &&
- X xoff_enabled && !xoff_sent && !xoff_received)
- X {
- X xoff_sent = TRUE;
- X while ((inbyte ((XON_PORT_address + LSR)) & 0x20) == 0)
- X ;
- X outbyte (XON_PORT_address + IER, XON_PORT_command = RX_TX_enable);
- X outbyte (XON_PORT_address, XOFF_char);
- X }
- X break;
- X
- X case IIR_transmit:
- X if (xoff_sent && (queue_avail (xon8250_inqueue) > 20))
- X {
- X xoff_sent = FALSE;
- X outbyte (XON_PORT_address, XON_char);
- X }
- X else
- X if (xoff_received)
- X outbyte (XON_PORT_address + IER, XON_PORT_command = RX_enable);
- X else
- X if ((ch = de_queue (xon8250_outqueue)) != -1)
- X {
- X outbyte (XON_PORT_address, ch);
- X }
- X else
- X {
- X outbyte (XON_PORT_address + IER, XON_PORT_command = RX_enable);
- X }
- X break;
- X
- X case IIR_mstatus:
- X test_status = inbyte ((XON_PORT_address + MSR));
- X break;
- X }
- X } while ((test_status = inbyte (XON_PORT_address + IIR)) != IIR_complete);
- X disable ();
- X outbyte (INT_cntrl, EOI_word);
- X#if (defined (DLC))
- X return (1);
- X#endif
- X}
- X
- X
- X
- X
- X/*
- X * XON8250_INIT - Here we get the address of the 8250 Port
- X * which corresponds to the channel passed in.
- X * We then massage the 8259 Interrupt Controller
- X * calculate the Physical Interrupt and save off
- X * the 8250's current contents. Then attach the
- X * xon8250_isr routine to the interrupt and
- X * return the rt returned index for saving - it's
- X * needed to terminate the interrupt.
- X */
- X
- X#define XON8250_STACK_SIZE 512
- int xon8250_intno;
- static int xon_intmask [] = { 0xef, 0xf7, 0xef, 0xf7 };
- X/*
- X * The above 8259 mask bits are determined from the formula
- X * mask = ~(1 << (5 - PORT_CHANNEL));
- X * The array assumes that COM3 and COM4 use the same interrupts
- X * as COM1 and COM2.
- X */
- static int xon_intno [] = { 12, 11, 12, 11 };
- X/*
- X * The above interrupt number array is based on the algorithm
- X * xon8250_intno = (13 - PORT_channel);
- X */
- X
- X
- int
- xon8250_init (int channel, int buffer_size)
- X{
- X int Dos_address, mask;
- X XON_PORT_channel = channel;
- X xon8250_inqueue = alloc_queue (buffer_size);
- X xon8250_outqueue = alloc_queue (buffer_size);
- X Dos_address = (XON_PORT_channel - 1) * 2;
- X peekmem (0x40, Dos_address, XON_PORT_address);
- X mask = xon_intmask [XON_PORT_channel-1];
- X SAVE_int_mask = inbyte (INT_mask);
- X mask &= SAVE_int_mask;
- X xon8250_intno = xon_intno [XON_PORT_channel-1];
- X LCR_save = inbyte (XON_PORT_address + LCR);
- X disable ();
- X outbyte (XON_PORT_address + LCR, LCR_save | LCR_DLAB);
- X MCR_save = inbyte (XON_PORT_address + MCR);
- X DL_lsb = inbyte (XON_PORT_address);
- X DL_msb = inbyte (XON_PORT_address + 1);
- X outbyte (XON_PORT_address + LCR, LCR_save & 0x7F);
- X IER_save = inbyte (XON_PORT_address + IER);
- X enable ();
- X#if (defined (DLC))
- X int_intercept (xon8250_intno, &xon8250_isr, XON8250_STACK_SIZE);
- X#else
- X xon_save_vec = getvect (xon8250_intno);
- X setvect (xon8250_intno, xon8250_isr);
- X#endif
- X DELAY_init ();
- X outbyte (INT_mask, mask);
- X}
- X
- X
- X
- X
- X/*
- X * XON8250_TERM - This routine restores the rs232xon 8250 back to its
- X * state before xon8250_INIT was called and releases the
- X * corresponding interrupt back to the system.
- X */
- X
- void
- xon8250_term (int restore)
- X{
- X disable ();
- X outbyte (INT_mask, SAVE_int_mask);
- X if (restore)
- X {
- X outbyte (XON_PORT_address + LCR, LCR_DLAB);
- X outbyte (XON_PORT_address, DL_lsb);
- X outbyte (XON_PORT_address + 1, DL_msb);
- X outbyte (XON_PORT_address + MCR, MCR_save);
- X outbyte (XON_PORT_address + LCR, 0x7F);
- X outbyte (XON_PORT_address + IER, IER_save);
- X outbyte (XON_PORT_address + LCR, LCR_save);
- X }
- X#if (defined (DLC))
- X int_restore (xon8250_intno);
- X#else
- X setvect (xon8250_intno, xon_save_vec);
- X#endif
- X}
- X
- X
- X
- X
- X/*
- X * XON8250_READ - this routine looks in the xon8250_inqueue for a character
- X */
- X
- int
- xon8250_read (void)
- X{
- X int ch;
- X disable ();
- X ch = de_queue (xon8250_inqueue);
- X enable ();
- X if ((XON_PORT_command == RX_enable) &&
- X ((!queue_empty (xon8250_outqueue)) || xoff_sent))
- X outbyte (XON_PORT_address + IER, XON_PORT_command = RX_TX_enable);
- X return (ch);
- X}
- X
- X
- X
- X
- X/*
- X * XON8250_TIMED_READ - attempts to read rs232 port - if no char
- X * available in number of seconds passed
- X * returns -1
- X */
- X
- int
- xon8250_timed_read (int sec)
- X{
- X int ch;
- X
- X timer_set ();
- X while ((ch = xon8250_read ()) == -1)
- X if ((timer_read () / 18) > sec)
- X break;
- X return (ch);
- X}
- X
- X
- X
- X
- X/*
- X * XON8250_WRITE - plain vanilla write to the port - check to see that
- X * the chip may need a kick in the pants before returning
- X */
- X
- int
- xon8250_write (char ch)
- X{
- X int rval = -1;
- X disable ();
- X rval = en_queue (xon8250_outqueue, ch);
- X enable ();
- X if (XON_PORT_command != RX_TX_enable)
- X outbyte (XON_PORT_address + IER, XON_PORT_command = RX_TX_enable);
- X return (rval);
- X}
- X
- X
- X
- X
- X/*
- X * XON8250_DTRNR - drop Data Terminal Ready Line
- X */
- void
- xon8250_dtnr (void)
- X{
- X char mcr_save;
- X disable ();
- X mcr_save = inbyte (XON_PORT_address + MCR);
- X outbyte (XON_PORT_address + MCR, 0);
- X DELAY_loop (500);
- X outbyte (XON_PORT_address + MCR, mcr_save);
- X enable ();
- X}
- X
- X
- X
- X
- X/*
- X * XON8250_GET_STATUS - returns the current rs232xon status and
- X * resets any error condition.
- X */
- X
- int
- xon8250_get_status (void)
- X{
- X char rval = XON_PORT_status;
- X XON_PORT_status &= ERROR_reset;
- X return ((int) rval);
- X}
- X
- X
- X
- X
- X/*
- X * XON8250_XOFF_SENT - did we send an Xoff char?
- X */
- X
- int
- xon8250_xoff_sent (void)
- X{
- X return (xoff_sent);
- X}
- X
- X
- X
- X
- X
- X/*
- X * XON8250_WRITE_BUFFER_EMPTY
- X */
- X
- xon8250_write_buffer_empty (void)
- X{
- X return (queue_empty (xon8250_outqueue));
- X}
- X
- X
- X
- X
- X
- X/*
- X * IOCTL_SET_XOFF
- X * sets the rs232 xon/xoff protocol. It accepts a command string
- X * of the form
- X * "y n" or "n n" or "n y" or "y y" either upper or
- X * lower case.
- X * The 1st char enables or disables xon/xoff receive...
- X * the 2d char enables or disables xon/xoff transmit
- X */
- X
- int
- ioctl_set_xoff (char *cmd)
- X{
- X char temp;
- X char xrcv[2];
- X sscanf (cmd, "%1s", xrcv);
- X disable ();
- X xoff_enabled = (toupper (*xrcv) == 'Y') ? TRUE : FALSE;
- X enable ();
- X}
- X
- X
- X
- X
- X/*
- X * XON8250_WRITE_BREAK - Write a BREAK Character
- X */
- X
- void
- xon8250_write_break (void)
- X{
- X int i;
- X disable ();
- X while ((inbyte (XON_PORT_address + LSR) & 0x40) == 0)
- X ;
- X outbyte (XON_PORT_address + LCR, inbyte (XON_PORT_address + LCR) | 0x40);
- X DELAY_loop (500);
- X outbyte (XON_PORT_address + LCR, inbyte (XON_PORT_address + LCR) & 0xBF);
- X enable ();
- X}
- X
- X
- X
- X
- X
- X/*
- X * XON8250_XON_PORT_INIT (Cmd) configures the 8250
- X * cmd is a string of the form baud parity stop data xon/xoff... i.e.
- X * 300 n 1 8 y
- X *
- X * baud - 300, 600, 1200, 2400, 4800, 9600, 19200
- X * parity - n -> no parity check
- X * o -> odd parity
- X * e -> even parity
- X * stop - 1 -> 1 stop bit
- X * 2 -> 2 stop bits
- X * data - 5, 6, 7, 8 data bits
- X */
- X
- int
- xon8250_port_init (char *cmd)
- X{
- X unsigned baud, data, mode_word, parity, stop, xoff;
- X char pty[2];
- X sscanf (cmd, "%d %1s %d %d", &baud, pty, &stop, &data);
- X *pty = toupper (*pty);
- X switch (*pty)
- X {
- X case 'E':
- X parity = 1;
- X break;
- X case 'O':
- X parity = 3;
- X break;
- X case 'N':
- X parity = 0;
- X break;
- X default:
- X parity = 0;
- X break;
- X }
- X stop = (--stop & 1);
- X stop <<= 2;
- X baud /= 10;
- X baud = 11520 / baud;
- X parity <<= 3;
- X parity &= 0x018;
- X data -= 5;
- X data &= 3;
- X mode_word = data | stop | parity;
- X disable ();
- X xoff_received = FALSE;
- X outbyte (XON_PORT_address + LCR, inbyte (XON_PORT_address + LCR) | LCR_DLAB);
- X outbyte (XON_PORT_address, baud % 256);
- X outbyte (XON_PORT_address + 1, baud / 256);
- X outbyte (XON_PORT_address + LCR, mode_word & 0x7F);
- X outbyte (XON_PORT_address + IER, XON_PORT_command = RX_enable);
- X outbyte (XON_PORT_address + MCR, 0x0F);
- X
- X inbyte (XON_PORT_address + LSR);
- X inbyte (XON_PORT_address + MSR);
- X inbyte (XON_PORT_address);
- X enable ();
- X}
- X
- X
- X
- X
- X/*---------------------- xon8250_port_enable () ----------------------*/
- X/*
- X *
- X */
- void
- xon8250_port_enable (void)
- X{
- X disable ();
- X outbyte (XON_PORT_address + IER, XON_PORT_command = RX_enable);
- X outbyte (XON_PORT_address + MCR, 0x0F);
- X
- X inbyte (XON_PORT_address + LSR);
- X inbyte (XON_PORT_address + MSR);
- X inbyte (XON_PORT_address);
- X enable ();
- X}
- END_OF_FILE
- if test 12190 -ne `wc -c <'8250xon.c'`; then
- echo shar: \"'8250xon.c'\" unpacked with wrong size!
- fi
- # end of '8250xon.c'
- fi
- if test -f '_kb.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'_kb.c'\"
- else
- echo shar: Extracting \"'_kb.c'\" \(4794 characters\)
- sed "s/^X//" >'_kb.c' <<'END_OF_FILE'
- X/*
- X * _KB.C
- X *
- X * Keyboard i/o Handler
- X *
- X * Written for the
- X *
- X * Datalight
- X * Microsoft V 5.x
- X * TurboC
- X * &
- X * Zortech
- X *
- X * C Compilers
- X *
- X * Copyright (c) John Birchfield 1987, 1988, 1989
- X */
- X/*
- X * If we use the Microsoft Compiler, we need to bind in MSC.OBJ
- X * which contains the function _kbhit ().
- X */
- X
- X#include <dos.h>
- X
- X/*
- X * defines for the bits returned in regs.x.cflag and by int86 () ...
- X */
- X
- X#define ZERO_BIT 0x040
- X#define CARRY_BIT 1
- X#define SIGN_BIT 0x080
- X#define DIRECTION_FLAG 0x400
- X#define OVERFLOW_BIT 0x800
- X
- static union REGS regs;
- X
- X
- X/*
- X * The following Translate Table is used to convert the PC scan
- X * codes into something of use. The translated values are defined in
- X * the file "scr_iokb.h".
- X */
- X
- X#include "_kb.h"
- static struct xlate_tbl
- X{
- X int in, out;
- X} cvt[] =
- X
- X{
- X {
- X 72, up_char
- X } ,
- X {
- X 80, down_char
- X } ,
- X {
- X 75, left_char
- X } ,
- X {
- X 77, right_char
- X } ,
- X {
- X 115, ctl_lft_char
- X } ,
- X {
- X 116, ctl_rt_char
- X } ,
- X {
- X 71, home_char
- X } ,
- X {
- X 79, end_char
- X } ,
- X {
- X 119, ctl_home_char
- X } ,
- X {
- X 117, ctl_end_char
- X } ,
- X {
- X 73, pageup_char
- X } ,
- X {
- X 81, pagedown_char
- X } ,
- X {
- X 132, ctl_pu_char
- X } ,
- X {
- X 118, ctl_pd_char
- X } ,
- X {
- X 82, Ins_char
- X } ,
- X {
- X 83, Del_char
- X } ,
- X
- X /* Straight Ahead Function Keys */
- X {
- X 59, M1
- X } ,
- X {
- X 60, M2
- X } ,
- X {
- X 61, M3
- X } ,
- X {
- X 62, M4
- X } ,
- X {
- X 63, M5
- X } ,
- X {
- X 64, M6
- X } ,
- X {
- X 65, M7
- X } ,
- X {
- X 66, M8
- X } ,
- X {
- X 67, M9
- X } ,
- X {
- X 68, M10
- X } ,
- X
- X /* Shifted Function Keys */
- X {
- X 104, M11
- X } ,
- X {
- X 105, M12
- X } ,
- X {
- X 106, M13
- X } ,
- X {
- X 107, M14
- X } ,
- X {
- X 108, M15
- X } ,
- X {
- X 109, M16
- X } ,
- X {
- X 110, M17
- X } ,
- X {
- X 111, M18
- X } ,
- X {
- X 112, M19
- X } ,
- X {
- X 113, M20
- X } ,
- X
- X /* Alt Function Keys */
- X {
- X 84, M21
- X } ,
- X {
- X 85, M22
- X } ,
- X {
- X 86, M23
- X } ,
- X {
- X 87, M24
- X } ,
- X {
- X 88, M25
- X } ,
- X {
- X 89, M26
- X } ,
- X {
- X 90, M27
- X } ,
- X {
- X 91, M28
- X } ,
- X {
- X 92, M29
- X } ,
- X {
- X 93, M30
- X } ,
- X
- X /* Ctrl Function Keys */
- X {
- X 94, M31
- X } ,
- X {
- X 95, M32
- X } ,
- X {
- X 96, M33
- X } ,
- X {
- X 97, M34
- X } ,
- X {
- X 98, M35
- X } ,
- X {
- X 99, M36
- X } ,
- X {
- X 100, M37
- X } ,
- X {
- X 101, M38
- X } ,
- X {
- X 102, M39
- X } ,
- X {
- X 103, M40
- X } ,
- X
- X {
- X 0, 255
- X }
- X};
- X
- X
- X
- X
- X/*
- X * _KB can tell if the Keyboard has been touched. If it has, he returns
- X * the value of the key pressed. If the Control Key or one of the
- X * Numeric or Function Keys is pressed that value is returned
- X * from a look-up table.
- X *
- X * Usage: if ((ch=_kb ())!=-1) we_have_a_char=TRUE;
- X */
- X
- X
- int
- X_kb ()
- X{
- X int ix, flag;
- X#if (defined (DLC))
- X# if (defined (__ZTC__))
- X if (kbhit ())
- X# else
- X regs.h.ah = 1;
- X if ((int86 (0x16, ®s, ®s) & ZERO_BIT) == 0)
- X# endif
- X {
- X#else
- X# if (defined (__TURBOC__))
- X regs.h.ah = 1;
- X int86 (0x16, ®s, ®s);
- X if ((regs.x.flags & ZERO_BIT) == 0)
- X {
- X# else
- X if (_kbhit ())
- X {
- X# endif
- X#endif
- X regs.h.ah = 0;
- X int86 (0x16, ®s, ®s);
- X if (regs.h.al == 0)
- X {
- X for (ix = 0; cvt[ix].in; ix++)
- X if (cvt[ix].in == regs.h.ah)
- X break;
- X return (cvt[ix].out);
- X }
- X return ((int) regs.h.al);
- X }
- X return (-1);
- X}
- END_OF_FILE
- if test 4794 -ne `wc -c <'_kb.c'`; then
- echo shar: \"'_kb.c'\" unpacked with wrong size!
- fi
- # end of '_kb.c'
- fi
- if test -f 'options.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'options.c'\"
- else
- echo shar: Extracting \"'options.c'\" \(4538 characters\)
- sed "s/^X//" >'options.c' <<'END_OF_FILE'
- X/*
- X * OPTIONS.C
- X *
- X * Written for the
- X *
- X * Datalight
- X * Microsoft V 5.x
- X * TurboC
- X * &
- X * Zortech
- X *
- X * C Compilers
- X *
- X * Copyright (c) John Birchfield 1987, 1988, 1989
- X */
- X
- X#include <stdio.h>
- X#include "options.h"
- X
- X#if (!defined (TRUE))
- X# define TRUE (1)
- X# define FALSE (0)
- X#endif
- X
- int Port = 1;
- X
- char Opt_Msg [159] = { 0 },
- X Baud_rate[] = "1200",
- X Parity[] = "N",
- X Data[] = "8",
- X Stop[] = "1",
- X
- X Cfg_Str[15] = { 0 };
- X
- X
- int good_baud (char *);
- void usage (void);
- X
- void
- set_options (int cnt, char **args)
- X{
- X char *ch;
- X int c_flag = 0;
- X while (--cnt > 0)
- X {
- X ch = *++args;
- X if (*ch == '?')
- X usage ();
- X if (*ch == '-')
- X switch (toupper (*++ch))
- X {
- X case 'C':
- X switch (*++ch)
- X {
- X case '1':
- X Port = 1;
- X break;
- X case '2':
- X Port = 2;
- X break;
- X default:
- X usage ();
- X break;
- X }
- X break;
- X case 'B':
- X c_flag = TRUE;
- X if (good_baud (++ch))
- X strcpy (Baud_rate, ch);
- X else
- X usage ();
- X break;
- X case 'P':
- X c_flag = TRUE;
- X switch (toupper (*++ch))
- X {
- X case 'E':
- X Parity[0] = 'E';
- X break;
- X case 'O':
- X Parity[0] = 'O';
- X break;
- X case 'N':
- X Parity[0] = 'N';
- X break;
- X default:
- X usage ();
- X break;
- X }
- X break;
- X case 'S':
- X c_flag = TRUE;
- X switch (*++ch)
- X {
- X case '1':
- X Stop[0] = '1';
- X break;
- X case '2':
- X Stop[0] = '2';
- X break;
- X default:
- X usage ();
- X break;
- X }
- X break;
- X case 'D':
- X c_flag = TRUE;
- X switch (*++ch)
- X {
- X case '7':
- X case '8':
- X Data[0] = *ch;
- X break;
- X default:
- X usage ();
- X break;
- X }
- X break;
- X default:
- X break;
- X }
- X }
- X if (c_flag)
- X {
- X sprintf (Opt_Msg, "%s %d %s%s%s %s%s %s%s %s%s\n",
- X "Com Port", Port, "Initialized %--% ",
- X " Baud=", Baud_rate, "Parity=", Parity,
- X "Data=", Data, "Stop=", Stop);
- X strcpy (Cfg_Str, Baud_rate);
- X strcat (Cfg_Str, " ");
- X strcat (Cfg_Str, Parity);
- X strcat (Cfg_Str, " ");
- X strcat (Cfg_Str, Stop);
- X strcat (Cfg_Str, " ");
- X strcat (Cfg_Str, Data);
- X }
- X}
- X
- X
- X
- X
- X
- static char *baud_rates[] =
- X{
- X "300", "600", "1200", "2400", "4800", "9600", "19200", 0
- X};
- X
- int
- good_baud (char *s)
- X{
- X int i;
- X for (i = 0; baud_rates [i]; i++)
- X if (strcmp (baud_rates[i], s) == 0)
- X return (TRUE);
- X return (0);
- X}
- X
- X
- X
- void
- usage (void)
- X{
- X fputs ("Use the following command line options.\n\n", stderr);
- X fputs (" -C[1 or 2] Com Port 1 or 2 {Default Com Port 1}\n", stderr);
- X fputs (" -B[300 600 1200 2400 4800 9600] {Default 9600 Baud}\n", stderr);
- X fputs (" -D[7 or 8] Data Bits {Default 8}\n", stderr);
- X fputs (" -S[1 or 2] Stop Bits {Default 1}\n", stderr);
- X fputs (" -P[E O or N] Parity {Default None}\n\n", stderr);
- X fputs (" -b2400 -pn -s1 -d8 -c1\n\n", stderr);
- X exit (1);
- X}
- X
- END_OF_FILE
- if test 4538 -ne `wc -c <'options.c'`; then
- echo shar: \"'options.c'\" unpacked with wrong size!
- fi
- # end of 'options.c'
- fi
- if test -f 'screen.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'screen.c'\"
- else
- echo shar: Extracting \"'screen.c'\" \(9082 characters\)
- sed "s/^X//" >'screen.c' <<'END_OF_FILE'
- X/*
- X * SCREEN.C
- X *
- X * Screen i/o Handler
- X *
- X * Written for the
- X *
- X * Datalight
- X * Microsoft V 5.x
- X * TurboC
- X * &
- X * Zortech
- X *
- X * C Compilers
- X *
- X * Copyright (c) John Birchfield 1987, 1988, 1989
- X */
- X
- X#include <dos.h>
- X#include "screen.h"
- X/*
- X * defines for the bits returned in regs.x.cflag and by int86 () ...
- X */
- X
- X#define ZERO_BIT 0x040
- X#define CARRY_BIT 1
- X#define SIGN_BIT 0x080
- X#define DIRECTION_FLAG 0x400
- X#define OVERFLOW_BIT 0x800
- static union REGS regs;
- X
- X
- X
- X#define VIDEO 0x10 /* interrupt for dealing with screen */
- X#define MODE 0 /* code for setting new screen mode */
- X#define SETCURTYP 1 /* code for setting new cursor type */
- X#define SETCURSOR 2 /* code for addressing cursor */
- X#define GETCURSOR 3 /* code for reading cursor location */
- X#define READLP 4 /* code for reading light pen position */
- X#define SETPAGE 5 /* code to select active page */
- X#define SCROLLUP 6 /* code to scroll screen up */
- X#define SCROLLDN 7 /* code to scroll screen nown */
- X#define READCH 8 /* code to read a character from screen */
- X#define WRITEACH 9 /* code to write char and attributes */
- X#define WRITECH 10 /* code to write character only */
- X#define SETPAL 11 /* code to set new setpal or border */
- X#define WDOT 12 /* code to write a dot */
- X#define RDOT 13 /* code to read a dot */
- X#define WRITETTY 14 /* code to write as if teletype */
- X#define STATE 15 /* code to find current screen status */
- X
- X
- X/*
- X * note- make 25 for ms-dos and 24 for cp/m as cp/m steals the bottom
- X * line.
- X */
- X
- int Scr_Rows = 25; /* current number of rows */
- int Scr_Cols = 80; /* current number of columns */
- char Scr_Mode = 0; /* current screen mode */
- char Scr_Page = 0; /* current page */
- char Scr_ATTR = 7; /* current attributes for screen 7 is white letters
- X * on black */
- char Scr_Window_Top = 0; /* first line to scroll */
- X
- X
- X
- X/*
- X * SCREEN_INIT - screen_init must be called before any use of any
- X * other routine unless the starting mode is 80X25
- X * character mode (3,4 or 7). Must be called for
- X * monocrome (mode 7) for scr_curson to set a proper
- X * cursor.
- X *
- X * Usage: screen_init ();
- X */
- X
- int
- screen_init (void)
- X{
- X regs.h.ah = STATE;
- X int86 (VIDEO, ®s, ®s);
- X Scr_Mode = regs.h.al;
- X Scr_Cols = regs.h.ah;
- X Scr_Page = regs.h.bh;
- X Scr_ATTR = (regs.h.al < 4 || regs.h.al == 7) ? 7 : 0;
- X return (regs.h.al);
- X}
- X
- X
- X
- X
- X/*
- X * SCREEN_SMODE - set a new screen mode
- X *
- X * Usage: screen_smode (new mode);
- X */
- X
- int
- screen_smode (char newmode)
- X{
- X regs.h.al = newmode;
- X regs.h.ah = MODE;
- X int86 (VIDEO, ®s, ®s);
- X screen_init ();
- X}
- X
- X
- X
- X/*
- X * ROWCOL - sets cursor at any location.
- X *
- X * Usage: rowcol (new row, new column);
- X */
- X
- int
- rowcol (int row, int col)
- X{
- X regs.h.dl = col;
- X regs.h.dh = row;
- X regs.h.bh = Scr_Page;
- X regs.h.ah = SETCURSOR;
- X int86 (VIDEO, ®s, ®s);
- X}
- X
- X
- X
- X/*
- X * G_ROWCOL - returns the current screen row and column
- X * the row is the high order 8 bits and the
- X * column is the low order.
- X *
- X * Usage: rowcol = g_rowcol ();
- X * cur_row = rowcol >> 8;
- X * cur_col = rowcol && 0xFF;
- X */
- X
- int
- g_rowcol (void)
- X{
- X regs.h.ah = GETCURSOR;
- X regs.h.bh = Scr_Page;
- X int86 (VIDEO, ®s, ®s);
- X return (regs.x.dx);
- X}
- X
- X
- X
- X
- X/*
- X * CLRSCRN - clear entire screen
- X *
- X * Usage: clrscrn ();
- X */
- X
- int
- clrscrn (void)
- X{
- X regs.h.al = 0;
- X regs.x.cx = 0;
- X regs.h.dh = Scr_Rows - 1;
- X regs.h.dl = Scr_Cols - 1;
- X regs.h.bh = Scr_ATTR;
- X regs.h.ah = SCROLLUP;
- X int86 (VIDEO, ®s, ®s);
- X}
- X
- X
- X
- X
- X/*
- X * CLEOL - clear to End Of Line
- X *
- X * Usage: cleol ();
- X */
- X
- int
- cleol (void)
- X{
- X regs.h.bh = Scr_Page;
- X regs.h.ah = GETCURSOR;
- X int86 (VIDEO, ®s, ®s);
- X regs.h.cl = Scr_Cols - regs.h.dl;
- X regs.h.ch = 0;
- X regs.h.al = ' ';
- X regs.h.bl = Scr_ATTR;
- X regs.h.bh = Scr_Page;
- X regs.h.ah = WRITEACH;
- X int86 (VIDEO, ®s, ®s);
- X}
- X
- X
- X
- X
- X/*
- X * CLEOP - clear to End Of Page
- X *
- X * Usage: cleop ();
- X */
- X
- int
- cleop (void)
- X{
- X cleol ();
- X regs.h.ah = GETCURSOR;
- X regs.h.bh = Scr_Page;
- X int86 (VIDEO, ®s, ®s);
- X regs.h.al = 0;
- X if ((regs.h.ch = regs.h.dh + 1) < Scr_Rows - 1)
- X {
- X regs.h.cl = 0;
- X regs.h.dh = Scr_Rows - 1;
- X regs.h.dl = Scr_Cols - 1;
- X regs.h.bh = Scr_ATTR;
- X regs.h.ah = SCROLLUP;
- X int86 (VIDEO, ®s, ®s);
- X }
- X}
- X
- X
- X
- X/*
- X * SCROLL_UP - Scroll the screen up. The window is scrolled
- X * up nlines lines. A zero nlines will clear the
- X * window. Top left of the screen is 0,0.
- X *
- X * Usage: SCROLL_UP (nlines, start_row, start_col, end_row, end_col);
- X */
- X
- int
- scroll_up (int nlines,
- X int start_row, int start_col,
- X int end_row, int end_col)
- X{
- X regs.h.al = nlines;
- X regs.h.ch = start_row;
- X regs.h.cl = start_col;
- X regs.h.dh = end_row;
- X regs.h.dl = end_col;
- X regs.h.bh = Scr_ATTR;
- X regs.h.ah = SCROLLUP;
- X int86 (VIDEO, ®s, ®s);
- X}
- X
- X
- X
- X/*
- X * SCROLL_DN - scroll the screen down. the window is scrolled
- X * down nline lines. A zero nline will clear the
- X * window. Top left of the screen in 0,0.
- X *
- X * Usage: scroll_dn (nlines,start_row, start_col, end_row, end_col);
- X */
- X
- int
- scroll_dn (int nlines,
- X int start_row, int start_col,
- X int end_row, int end_col)
- X{
- X regs.h.al = nlines;
- X regs.h.ch = start_row;
- X regs.h.cl = start_col;
- X regs.h.dh = end_row;
- X regs.h.dl = end_col;
- X regs.h.bh = Scr_ATTR;
- X regs.h.ah = SCROLLDN;
- X int86 (VIDEO, ®s, ®s);
- X}
- X
- X
- X
- X
- X
- X/*
- X * SCREEN_CO - write a character to the screen. this
- X * routine increments the cursor position
- X * after writing. normal C88 puts and printf
- X * statements can also be used to write to the
- X * screen.
- X *
- X * Usage: screen_co (character);
- X */
- X
- int
- screen_co (char ch)
- X{
- X regs.h.al = ch;
- X regs.h.bh = Scr_Page;
- X regs.h.ah = WRITETTY;
- X int86 (VIDEO, ®s, ®s);
- X}
- X
- X
- X
- X
- X/*
- X * SINP - screen input (read character from the screen).
- X *
- X * Usage: character = sinp ();
- X */
- X
- int
- sinp (void)
- X{
- X regs.h.bh = Scr_Page;
- X regs.h.ah = READCH;
- X int86 (VIDEO, ®s, ®s);
- X return ((int) (regs.h.al) ? regs.h.al : ' ');
- X}
- X
- X
- X
- X
- X
- X/*
- X * CURSOR_OFF - turn cursor off.
- X *
- X * Usage: cursor_off ();
- X */
- X
- int
- cursor_off (void)
- X{
- X if (Scr_Mode < 4 || Scr_Mode == 7)
- X {
- X regs.x.cx = 0x0f00;
- X regs.h.ah = SETCURTYP;
- X int86 (VIDEO, ®s, ®s);
- X }
- X}
- X
- X
- X
- X
- X/*
- X * CURSOR_ON - turn cursor back on.
- X *
- X * Usage: cursor_on ();
- X */
- X
- int
- cursor_on (void)
- X{
- X if (Scr_Mode == 7)
- X regs.x.cx = 0x0C0D;
- X else
- X if (Scr_Mode < 4)
- X regs.x.cx = 0x0607;
- X else
- X return;
- X regs.h.ah = SETCURTYP;
- X int86 (VIDEO, ®s, ®s);
- X}
- X
- X
- X
- X
- X
- X/*
- X * APUTS - write a string in the current attribute to the screen.
- X *
- X * Usage: aputs (attr, "Write this out\n");
- X */
- X
- int
- aputs (int a, char *s)
- X{
- X while (*s)
- X aput (a, *s++);
- X}
- X
- X
- X
- X
- X/*
- X * APUT - write a string and attributes to the screen.
- X * the cursor is moved normally
- X *
- X * Usage: aput (INVERSE, 'x');
- X */
- X
- int
- aput (int attr, char ch)
- X{
- X switch (ch)
- X {
- X default:
- X regs.h.al = ch;
- X regs.h.bl = attr;
- X regs.x.cx = 1;
- X regs.h.bh = Scr_Page;
- X regs.h.ah = WRITEACH;
- X int86 (VIDEO, ®s, ®s);
- X regs.h.ah = GETCURSOR;
- X int86 (VIDEO, ®s, ®s);
- X if (!(++regs.h.dl < Scr_Cols))
- X {
- X regs.h.dl = 0;
- X if (!(++regs.h.dh < Scr_Rows))
- X {
- X scroll_up (1, 0, 0, 23, 79);
- X regs.h.dl = 0;
- X regs.h.dh = 23;
- X }
- X }
- X regs.h.bh = Scr_Page;
- X regs.h.ah = SETCURSOR;
- X int86 (VIDEO, ®s, ®s);
- X break;
- X case 10:
- X regs.h.ah = GETCURSOR;
- X int86 (VIDEO, ®s, ®s);
- X regs.h.dl = 0;
- X if (!(++regs.h.dh < Scr_Rows - 2))
- X {
- X scroll_up (0, 0, 0, Scr_Rows - 2, 79);
- X regs.h.dl = 0;
- X regs.h.dh = Scr_Rows - 2;
- X }
- X regs.h.bh = Scr_Page;
- X regs.h.ah = SETCURSOR;
- X int86 (VIDEO, ®s, ®s);
- X break;
- X case 13:
- X regs.h.ah = GETCURSOR;
- X int86 (VIDEO, ®s, ®s);
- X regs.h.dl = 0;
- X regs.h.bh = Scr_Page;
- X regs.h.ah = SETCURSOR;
- X int86 (VIDEO, ®s, ®s);
- X break;
- X }
- X}
- END_OF_FILE
- if test 9082 -ne `wc -c <'screen.c'`; then
- echo shar: \"'screen.c'\" unpacked with wrong size!
- fi
- # end of 'screen.c'
- fi
- echo shar: End of archive 2 \(of 3\).
- cp /dev/null ark2isdone
- MISSING=""
- for I in 1 2 3 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 3 archives.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
- +----------------------
- | John Birchfield
- | jb@altair.csustan.edu
- +----------------------
-
-
-