Dec 072017
 
Fast video procedures in C.
File FASTVI3.ZIP from The Programmer’s Corner in
Category C Source Code
Fast video procedures in C.
File Name File Size Zip Size Zip Type
VIDDEMO.C 17731 4748 deflated
VIDDEMO.COM 21093 7677 deflated
VIDEO.H 2405 771 deflated
VIDEO.LIB 3584 1986 deflated
WINDOW.H 1435 560 deflated
WINDOW.LIB 8704 2955 deflated
WINDOWS.DOC 16101 5628 deflated

Download File FASTVI3.ZIP Here

Contents of the WINDOWS.DOC file



Documentation for VIDEO.LIB and WINDOW.LIB by Timothy Legant - 8/05/87

Version 1.01

+---------------------+
| BUG FIXES & UPDATES |
+---------------------+

+ Version 1.0 of these libraries did not include a demo. This version
does include a demo (compiled as a TINY program) with source.

+ The qputxy() routine in version 1.0 did NOT work properly. It put the
string 1 line beneath where it should have been, and 1 character to the
right. This has been fixed in version 1.01

+ The "explode from center" window routine has been modified so that the
top and bottom borders are two characters shorter during the exploding
stage (1 character less on each side, right and left). I thought the
previous routine was sort of ugly, so I changed it.


+---------+
| HISTORY |
+---------+

Right around the end of June I got my copy of TURBO C (w/ free T-shirt)
and I started working through the User's Guide. I discovered that no video
"goodies" were provided. In fact, although there are hooks to the ROM BIOS
diskette, serial port, and printer routines, there is no call to the video
interrupt. I was dismayed. I understand the philosopy behind the desire to
be portable, and all that, and I'm not knocking it, but a teletype interface
isn't exactly my idea of an exciting program.

I decided to write my own video interface, and so for the last three
weeks, I have been working a summer job (10 hours a day), learning C, and
writing a video interface for my own programs. One of my friends, a consul-
tant/developer saw several of my routines and suggested that I try to sell
them. Not a bad idea, I thought, but I didn't go out and buy some pre-written
routines for two reasons: 1> because I couldn't afford any at the time, and
2> most of the time, somebody writes these packages, but uses something else
in their own programs, that is, they don't want to sell their best routines,
so they write stuff to sell, but not necessarily easy-to-use or intuitive
routines.

I wrote these for my own programs, and I am using them. I decided that
maybe some other people could as well, so I decided to distribute them via
Borland's Compuserve SIG. They are an on-going project with me, and I do
plan to add more routines, and improve the current ones. I would appreciate
hearing from anybody using them, especially what you like, or would like to
see as possible, future improvements.

As far as using them goes, they are copyright by me, and may not be sold
as libraries. However, you are certainly welcome to use them in any programs
you write, for yourself or for commercial sale. That's why I'm making them
available. If you do use them, and feel so led, send me five or ten dollars,
or whatever you feel they are worth to you. That would make me able to spend
a little more time on improving them, and also let me know what people are
thinking. Even if you don't send anything, drop me a postcard/letter or
leave a message for me on Compuserve with any comments. Above all, enjoy!




WINDOW.LIB, WINDOW.H, VIDEO.LIB, & VIDEO.H, VIDDEMO.C, & VIDDEMO.COM

(c) COPRYRIGHT 1987 by Timothy Legant


These libraries are provided as is, with no warranty of any kind. They are
not warranted to suitable for your purposes. To the best of my knowledge
these library routines work as documented. However, I shall not be respon-
sible for any damages or loss of data which you may experience while using
these routines. These are distributed for general use AT YOUR OWN RISK.

If you do find bugs, please be thoughtful enough to let me know, and I will
do my best to correct them and get a working copy to you as quickly as
possible. Thanks.


My address:

SUMMER: SCHOOL YEAR: (Sep. - May)

Timothy Legant Timothy Legant
9039 Bennett Lake Rd. Box C-556
Fenton, MI 48430 Trinity College
Phone: (313) 629-4088 Deerfield, IL 60015



+---------------------+
| General Information |
+---------------------+

LIMITATIONS

These routines are designed for machines which use IBM or IBM compatible
video adapters - specifically the MDA, CGA and EGA. They work by directly
changing video memory, and will not work with most windowing environments.

These routines will only work with the TINY or SMALL memory models!!!
As I mentioned before, I am in the middle of learning C, and the highest
priority for future work on these routines is to make them work with ALL
memory models. I need to mess around with mixed model programming for a
while so I can avoid some of the insidious bugs mentioned in the User's
Guide. Mixed model programming is NOT easy, especially since these routines
involve some 35k of assembler source code. I am working on this, however.

COMPILING

Since TURBO C doesn't know that these libraries exist, you must tell it.
This is done with a project make file. Simply list these two libraries in the
project file along with the name of your source, and use "O/Build all" or F9.

Included in FASTVI.ARC are two header files (includes) which you should
include in your C source file (#include , #include ). If
you don't, you will get errors, because some modifiable variables are declared
in these headers. They also declare all available functions so TURBO C can
error check your calls.

FLOATING POINT LIBRARIES

These routines use NO floating point math, and so should compile with
any of the available C choices - none, 8087, emulation.


+---------------------+
| Specs for VIDEO.LIB |
+---------------------+

VARIABLES

w_x1, w_y1, w_x2, w_y2: The coordinates of the current window.
They are "unsigned char," initialized
to coordinates of 0, 0, 79, and 24
respectively, that is, the full video
screen on CGA, and MDA (and usually on
EGA). Don't change these in your
program. Use a call to the window()
function. You may, however, read them
to find out the current window.
NOTE: if your EGA is in 43 row mode,
these routines will detect and
support that mode.

current_color: An "unsigned char" that is the value
of the current window attribute. This
is the same format as an attribute
byte in screen memory.

retrace_mode: This byte is set to 1 if the video
initialization determines that a CGA
is installed in the machine. Normally
you would not be interested in this
variable, but it you have a CGA that
doesn't snow, you can set it to 0 and
the video output will be substantially
speeded up. "unsigned char"

EGA: This is sort of a constant, so I used
capitals. It is 1 if the video init-
ialization determines that the current
active monitor is an EGA. Otherwise
it is set to 0. You can read this if
you need the information.
"unsigned char"

vid_mode: This is the current video mode (from
the ROM BIOS data area). This is set
by the video initialization.
"unsigned char"

*vid_addr: A far pointer to the current video
address (segment:offset).

FUNCTIONS

initvid();

Initializes the variables listed above as well as some internal variables.
Call this after every mode change. Normally, you would only use this once,
but if your program can switch between two different monitors (MDA, CGA), call
this after your switch routine. It will reset all the necessary variables.


qputch(int char,int length);

Prints 1 to n characters, n equals the number of columns in the current
window. This function will not go outside the current window, not will it
wrap to the next line in the window. Any excess characters will be truncated.
Character(s) begin at current cursor location, but the cursor position is not
changed.


qputs(char *string);

Takes a char pointer as a parameter and prints the string in the current
window and current color. This function will wrap strings within the window,
scrolling the window if necessary. It will specifically handle a carriage
return, a linefeed (newline), a backspace, and the BEL character (ASCII 7).

A carriage return returns to beginning of current line.
A linefeed returns to beginning of next line, scrolling if necessary.
A backspace moves the cursor back one character and erases the character
at that position. This does NOT work across linefeeds. That is, the
cursor won't back up onto the next line.
A BEL (ASCII 7, or CTRL-G) beeps without moving the cursor.

This function writes the string at the current cursor position, and updates
cursor.


qputxy(int x, int y, char *string);

Writes the string pointed to by *string at the X,Y location specified.
Does not take into account any window, and does not move the cursor at all.
The X,Y coordinates are absolute to the screen, not relative to the window.


qputa(int attribute, int length);

Changes the attribute from the current cursor location for length char-
acters. Does not change cursor location or characters at location. Useful
for menus with moving bars, etc.


color(int foregroundcolor, int backgroundcolor);

Sets the current color to specified colors. The variable current_color
is updated. Also, two macros are provided that change only the foreground
color or the background color.

forecolor(int foregroundcolor);
backcolor(int backgroundcolor);


vidoff();
vidon();

Blank the screen on a CGA or MDA monitor. None of my routines use these,
but if you need them, here they are. They work by reprogramming the 6845 chip
on the video adapters, so will only work on close compatibles.


window(int x1, int y1, int x2, int y2);

Sets the new window coordinates. Most of these routines work relative to
the current window settings. This function updates the w_x1, w_y1, w_x2, w_y2
variables.


clrwin();

Clears the current window in current_color. Does not flicker or snow.


insline();

Inserts a line in current_color at the cursor location. All lines below
current line are scrolled down, the bottom line disappearing from the window.


delline();

Deletes a line at the cursor location. All lines below current line are
scrolled up and a blank line is inserted at bottom of window (current_color).


gotoxy(int x, int y);

Moves the cursor to X,Y location. This is RELATIVE to current window!!!


wherex();
wherey();

Return the cursor X or Y location. This is RELATIVE to current window!!!


clreol();

Clears to end of line in current_color. This is ONLY in current window.


getpage();
setpage(int videopage);

Get or set video display page. Only for adapters which support multiple
pages. If you are setting the page, the vid_addr pointer is reset, as are
most of the other variables, including retrace_mode. If you have modified
retrace_mode, remember to reset it after calling setpage();


getcursor(int *startline, int *stopline);
setcursor(int startline, int stopline);

Get or set the cursor size. Remember to pass ADDRESSES to getcursor() so
that it can return the values back to you. setcursor(16,16) will turn most
cursors off.


savewin(unsigned *anyarray);
restorewin(unsigned *anyarray);

Saves or restores the current window (w_x1,w_y1,w_x2,w_y2) to an array
pointed to by "anyarray." You must make sure you have enough room for data,
otherwise something will get overwritten!


+----------------------+
| Specs for WINDOW.LIB |
+----------------------+

VARIABLES

activewin; The handle of the currently active
window. DO NOT CHANGE. You will bomb
spectacularly!

delaywin; This is normally zero, but on some fast
machines with EGA or MDA adapters, the
exploding window happens too fast, so
setting this variable will slow it down.
About 200 seems to work right for an
8 mhz. machine with an EGA. You can
modify this to your heart's content.


FUNCTIONS

initwin();

Initializes the necessary window parameters. Sets delaywin to 0. If you
want a different value, set it AFTER you call initwin(). You must call this
before any window routines.


mkwindow(int x1,int y1,int x2,int y2, int frameforecolor, int framebackcolor,
int windowforecolor, int windowbackcolor, int framestyle, int type);

The x1,y1,x2,y2 variables are self explanatory, as are the colors. The
framestyle refers to the kind of frame:

0 = no frame - framecolors are not used
1 = single line frame
2 = double line frame

The type refers to how the window should appear:

0 = popup window - only the border is drawn, and current_color is set to
the window colors. If you immediately clrwin() after
calling mkwindow(), you won't have any problems. This
is written this way with an eye to the future... and I
won't say anymore.
1 = pulldown window - instead of corners on the top left and top right,
this routine puts connectors so the window appears
to be connected to the line above it.
2 = sprout window - also known as "exploding windows." This option causes
the window to "grow" out from the center to the final
location. Clears the center to window colors.
3 = sprout from top left - like sprout, but from top left corner.
4 = sprout from top right - like sprout, but from top right corner.
5 = sprout from bottom left - like sprout, but from bottom left corner.
6 = sprout from bottom right - like sprout, but from bottom right corner.

All windows initialize the cursor location to 1,1 (top left corner of window).

rmwindow();

Removes the top (active) window from the screen, resets all specs to the
window beneath it, which becomes the new active window. If no other windows
are on the screen, the window goes back to the full screen.


 December 7, 2017  Add comments

Leave a Reply