Stephen Patten is a senior analyst with the Lincoln Savings Bank in New York and teaches C at New York University. He can be reached at (516) 932-3484.
C Express: 250+ Ready-To-Run Assembly-Language Routines for Turbo C, Microsoft C and QuickC, a book and accompanying diskettes, was written (both the assembly source code and text) by Robert Jourdain and published by Brady Books, a division of Simon & Schuster, Inc. The copy I reviewed was dated 1989.
Companion Diskettes
Two 5.25" diskettes accompany the 412-page book. One diskette contains the eight library files which house the 250 plus routines in object code form along with eight parallel header files for function prototyping. The other diskette contains the assembly language source of the routines in compressed form. (You can exchange the 5.25" disks for 3.5").You install the libraries and header files on a hard drive by a simple copy, and then call routines as you would any C function inside source code. A global variable is also set which is used by the compiler to configure the correct memory model.
Book Contents
Chapter 1 provides a short introduction to using the library. Chapters 2-9 document the library files included on the companion disk. Chapter 10 includes a discussion on writing your own assembly subroutines to link with C programs. This is followed by indices of general topics, the routines, and their object files.The routines or functions are documented pretty much as you would expect, each described in terms of its purpose, parameters, globals required, kinds of errors checked, and relevant peculiarities. Examples of calls are also amply provided.
The book also presents background information on groups of routines. For example, functions that implement expanded memory are preceded by a description of the LIM specification, not in great detail, but enough for the programmer to understand what the routines do and why.
Interestingly, video routines which can be implemented in either ROM BIOS or memory-mapped form are presented both ways, with the ROM BIOS routines suffixed with an underscore and lower case b. Depending upon the application, the programmer can choose between speed and portability.
Overview of Functions
The equipment configuration routines access the usual details of installed hardware and are only notable in that they eliminate the bit manipulations required when using the compiler library to extract the same information.The memory management routines test for extended and expanded memory, and allow programming of expanded memory applications. Pages can be allocated, switched and deallocated, and data exchanged between expanded memory and RAM quickly and easily. This can be a real plus to a C programmer restricted by the one megabyte limitation of the MS-DOS environment.
C Express routines, like hex_to_char, hex_to_int, binary_to_char, and binary_to_int, interpret such strings as numbers, producing values which can then be entered as numeric data in C programs. Combined with existing stdlib.h utility functions, like itoa, they can also be used to convert binary to hex, or vice versa, a nice library facility.
There are string manipulation routines to add or delete characters to or from strings, change string characters, and perform various substring operations. There are also keyboard routines that provide for fast operating system calls to check, read, clear, wait on and change characters, and scan codes in the keyboard buffer.
filter_in, for example, captures the next keystroke in the buffer then looks for the same character in a predefined table. If found, the keystroke is accepted; otherwise, it's rejected. A related routine, filter_out, does the opposite, rejecting a character found in the table.
key_pause allows a key to act like an ON-OFF switch. Hold it down and, let's say, a help screen appears. Release it, and the help screen disappears. This can replace long and complicated if and switch statements with cleaner, faster code.
Mouse routines, based on Microsoft's driver, position the mouse cursor, turn it on and off, capture a button press, report mouse positioning and control mouse motion to cursor movement. With pixel_ratio, you can set the exact movement ratio between the mouse and its cursor motion. With define_graphics_cursor, you can set the precise pixel or "hot spot" inside the pattern of pixels that fall under the cursor display.
Screen control routines set the video adapter, position the cursor, set mono or color attributes, and control the writing of strings to the screen. For example, clear_blink changes the 7 bit in the attribute byte so that it controls the intensity of background colors rather than blinking, effectively doubling background colors in CGA text mode. set_blink restores the bit to its original interpretation.
display and display_b, unlike printf, are passed arguments to both position a string before displaying, and display with an attribute.
The graphics in C Express are limited to the CGA text mode. Like the screen control routines, there are both memory-mapped and BIOS versions. They draw the usual assortment of graphics figures as well as scroll sections of the screen either vertically or horizontally. Written in assembly, they run very fast.
The file routines are built around a data structure called tree_array which holds directory names and pointers to sub-directories. The routines work with the structure displaying a directory tree or searching through the tree for a file. It's a little tricky going at first, but the book makes it all pretty clear.
Finally, a variety of printer output services are included. They simplify sending output to the printer inside a C program, do a certain amount of printer formatting, interpret embedded control codes in strings and implement the BIOS print screen function. wrap_line formats a string for printing in word wrapped form, while justify_line formats a string in right-justified, word wrapped form. The prtsc routine performs a screen dump, sending both text and graphics images to the printer.
In conclusion, the C Express package provides a collection of object code files and routines for calling within a C program. The routines are not unique in terms of their functionality but are a fairly standard collection that can be found in other off the shelf libraries. They are easy to set up and use, and they run fast. I was unable to find any bugs. The book provides good, well-organized documentation, and guidance for using the library files.
Particularly for new C programmers, the package would very likely make an excellent starter kit and base from which to build their own language libraries.
C Express: 250+ Ready-To-Run Assembly-Language Routines for Turbo C, Microsoft C and QuickC
Robert Jourdain
Brady Books, 1989
ISBN 0-13-933185-9