home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource4
/
240_01
/
ciao.c
< prev
next >
Wrap
Text File
|
1987-07-31
|
30KB
|
995 lines
/*
** ciao.c
** sept 10, 1986, by david c. oshel, ames, iowa
**
** -----> COMPILE USING UNSIGNED CHAR
**
** Console input and output for the 101% IBM PC clone. This is the first
** module in my CIAO.LIB library.
**
** These are FAST primitives to read from and write to the IBM video RAM.
** Ignores the ROM-BIOS except to set text mode and/or to read or set the
** machine cursor (see just below).
**
** The module is self-initializing. Vid_init(n) is only required to set
** a particular mode, e.g., vid_init(3) to set 80x25 color text. The
** requested mode is only set if the hardware supports it, and only
** monochrome mode 7 and cga modes 2 or 3 are valid. No graphics modes.
**
** Global functions which ALTER THE CONTENTS OF THE SCREEN test the
** initialized flag. In general, static, ROM-BIOS and cursor functions
** do NOT test the flag. If the flag is still zero, vid_init executes.
**
** The machine cursor and the video RAM write location ("soft cursor")
** are independent, but are synchronized by default. See setsynch fn.
**
** Compiler is Microsoft C ver. 4.00, but this particular module should be
** fairly portable to another compiler (such as Microsoft C ver. 3.00).
**
*/
/*=======================================================================*
There are 16 public Video Attribute Registers: vid[0] ... vid[15]
The Clairol routine (CLAIROL.OBJ) recognizes four major message
levels, associated with vid[0], vid[1], vid[2], vid[3]. This is
the popout window that allows user access to the first four video
registers (only).
Programmers have access to all 16 registers at all times, using
the CLAIROL.H header file.
Clairol VidReg ^ commands that set the attribute
-------------------------------------------------------------------
Normal vid[0] wputs("^0"); wputs("^");
Bold vid[1] wputs("^1");
Emphasis vid[2] wputs("^2");
Attention! vid[3] wputs("^3");
vid[4] wputs("^4");
.
.
.
vid[ 9] wputs("^9");
vid[10] wputs("^Ω"); keystroke is ALT 234
vid[11] wputs("^δ"); " ALT 235
vid[12] wputs("^∞"); " ALT 236
vid[13] wputs("^φ"); " ALT 237
vid[14] wputs("^ε"); " ALT 238
vid[15] wputs("^∩"); " ALT 239
The DEFAULT contents of these registers is as follows:
Contents *Color/Graphics Adapt. Monochrome Adapter
-----------------------------------------------------------------
Normal brite white on blue normal
Bold brite yellow on black bright normal
Emphasis brite blue on white reverse
Attention blink br. white on red blinking reverse
vid[ 4] *red, 4 underline
vid[ 5] magenta, 5 bright underline
vid[ 6] dark yellow, 6 blinking normal
vid[ 7] ordinary white, 7 blinking underline
vid[ 8] dark grey, 8 blinking bright normal
vid[ 9] brite blue, 9 blinking bright underline
vid[10] brite green, 0x0a normal
vid[11] brite cyan, 0x0b normal
vid[12] brite red, 0x0c normal
vid[13] brite magenta, 0x0d normal
vid[14] brite yellow, 0x0e normal
vid[15] brite white, 0x0f normal
*The default background is black for registers vid[4]..vid[15], and
blink is off.
*=======================================================================*/
#define LINT_ARGS
#include <alloc.h> /* _fmalloc(), _ffree() */
#include <conio.h> /* direct console: putch(), getch(), etc */
#include "ciao.h"
/* these defines are for ciao.c alone; they are local, not for ciao.h
*/
#define SCRLIM 4000 /* 80x25 chars & attrs in screen */
#define TOPX 0 /* 80x25 screen margin defaults */
#define TOPY 0
#define BTMX 79
#define BTMY 24
#define GOXY (2*(col+(row*80))) /* yields absolute screen address */
#define SPC ' ' /* blank char, for clreol(), etc. */
/* monochrome monitor attributes :----------------*/
#define INV '\000' /* invisible */
#define UNL '\001' /* underline */
#define NRM '\007' /* normal */
#define BRU '\011' /* bright underline */
#define BRN '\017' /* bright normal */
#define RVR '\160' /* reverse */
#define BLU '\201' /* blinking underline */
#define BLN '\207' /* blinking normal */
#define BBU '\211' /* blinking bright underline */
#define BBN '\217' /* blinking bright normal */
#define BLR '\360' /* blinking reverse */
/*
** globals
*/
int vid[16] = /* vid_init() changes this table if cga */
{
NRM, BRN, RVR, BLR,
UNL, BRU, BLN, BLU,
BBN, BBU, NRM, NRM,
NRM, NRM, NRM, NRM
};
int vid_mode = 7; /* monochrome is default */
int rasterh = 12, rasterl = 13; /* monochrome cursor default raster lines */
/*
** locals
*/
static int Initialized = 0; /* are all the critical pointers set? */
static union REGS old_vid;
static int vid_seg = 0xB000, /* monochrome screen RAM base address */
vid_attr = 7, /* HEAVILY USED HEREIN */
vid_page = 0, /* "active" page is default (unused?) */
vid_wide = 80; /* unused */
static char far *scribble; /* transfer depot for RAM read/write */
static char far *hidescreen; /* pointer to invisible screen buffer */
static int activescreen = 0xB000,
row = 0,
col = 0;
static union REGS xy; /* holds machine cursor address for set */
static int synchronized = 1; /* default to hard & soft cursors alike */
static int lm = TOPX,
rm = BTMX,
tm = TOPY,
bm = BTMY; /* default window margins */
/* H_pfill(). Pattern fill routine, hardwired to active screen, scribble.
**
** Called by rptchar(), scrollup(), scrolldn(). Use with discretion
** because there is NO error checking!
**
** Assumes scribble is already set, plus any number of other hardwired
** characteristics. Generalizing this for any size of pattern source buffer
** and any size of destination fill buffer might be useful.
**
** Movedata is very efficient. I suspect it just sets up registers and
** then executes a single 8086 machine instruction to do the block move.
** The result is instantaneous, at least to the proverbial naked orb.
*/
static void H_pfill( base, cnt ) int base, cnt;
{
static int width = 2; /* hardwired pattern (scribble) size */
cnt *= width; /* translate number of pattern objects
** to number of destination bytes
*/
/* SET PATTERN IN DEST BUFFER: Write pattern at least once.
*/
movedata( FP_SEG(scribble), FP_OFF(scribble), /* from */
activescreen, base, /* to */
width);
cnt -= width; /* one object already moved */
if (cnt > 0) /* shall we continue? */
{
/* ULTRAFAST PATTERN FILL: A source byte moved to the destination
** on iteration N extends the source pattern for iteration N+1.
*/
movedata( activescreen, base, /* srce (!) */
activescreen, base + width, /* dest (!!) */
cnt);
}
}
static void set