PRINCIPLES OF 

ASSEMBLY LANGUAGE PROGRAMMING

 

DAVID J. KRUS

ARIZONA STATE UNIVERSITY

 

CRUISE SCIENTIFIC

Taipei Phoenix Amsterdam

 Edited by: James M. Webb

Designed by: Sie Han-Yen

Technical Advisor: Pei Sie-Ka

Information in this document is subject to change without notice. The software described in the text is not copy protected. However, both this manual and the software it describes are protected by copyright and should not be copied without the written consent of the publisher for any purpose other than the purchaser's personal use.

Microsoft is a registered trademark of Microsoft Corporation. Hewlett Packard is a registered trademark of Hewlett Packard Company. The Cruise Fortran and LaserJet Libraries are listed in the Microsoft Language Support Directory and in the Hewlett Packard Peripherals Catalog.

The development of the Fortran callable assembly language subroutines for control of HP LaserJet printers was made possible by the Hewlett Packard Peripherals Developer Program, providing a series of LaserJet printers for the final hardware tests. Sincere thanks are extended to Rachelle Wheatley and Lisa Menas, coordinators of the HP Peripherals Developer Program, for their help and support which contributed to the successful completion of this project.

  

Copyright 1997 by Cruise Scientific

5F, 11, 10, 329 Nei Hu Road

Taipei, Republic of China

 

In the Americas address inquiries to Cruise Scientific

3434 West Tulsa Street, Chandler, Arizona 85226-4035

 

In Europe address inquiries to Cruise Scientific

52 Zamenhofdreef, Utrecht, Netherlands 356JZ

  

Cover Art by Naoki Yoshimoto.

 

International Standard Book Number: 0-940325-20-9

  

Manufactured in the Republic of China

 

TABLE OF CONTENTS

  

CHAPTER

ONE

 

INTRODUCTION 1

Securing and Displaying Information - Windows - Programming at DOS, BIOS and Hardware Levels - The Keyboard - Disks and Disk Files - Coordination of Program Execution - Control of Laser Printers - Getting Started

 

CHAPTER

TWO

 

SYSTEM CONFIGURATION AND ORIENTATION IN TIME 7

Type of the Central Processor Unit - System Memory - Upper Memory - Memory Available to Program - Version of the Operating System - Presence of ANSI.SYS Driver - Retrieve Date and Day of the Week - Date Composition - Measure Elapsed Time - Delay Program Continuation

 

 

CHAPTER

THREE

 

THE KEYBOARD 15

Sensing the State of Caps Lock and and Num Lock Keys - Unlocking Caps and Keypad Keys - Redefine Keyboard Key Assignments - Input at the Level of DOS Interrupts - Input at the Level of BIOS Interrupts - The Mapped Keyboard Input - Secure Response to a Query

 

CHAPTER

FOUR

 

SCREEN DISPLAYS 22

Clear Screen - Reverse Screen - Blinking Message - Invisible Password Entry - Redefine Cursor Shape - Locate Cursor - Reposition Cursor - Frame a Screen Display Area - Screen Background Textures - Define Attributes of the Scrolled Screen - Cover Page Display - Pagination of Screen Displays - Windows - Read Numbers from Screen - Write Numbers to Screen - Read Text from Screen - Write Text to Screen - Write Text to Screen via DOS Calls - Write Text to Screen via BIOS Calls - Test Strings for Numbers - Fill String with Blank Spaces - Format Strings - Measure Length of Text within String - Text Strings in Upper and Lower Case - Separating Thousands in Numerical Strings

 

CHAPTER

FIVE

 

DISKS AND DISK FILES 44

How Many Drives are Present? - Where are We? - Where to Go? - Drive Description - How to Get There? - Change Directory - Remove Directory - Create a New Directory - View Directory - Delete a File - Read Only Files - Make File Invisible to Directory Search

 

CHAPTER

SIX

 

 

PROGRAM OPERATION AND COORDINATION 53

Command Line Arguments - Extract Parameters from the Environment - Invoke Operating System Commands - Catenate Programs - Program Termination

 

CHAPTER

SEVEN

 

 

THE SOUND 58

Sound Alert - Tones - Tunes - Phasers - Sound Effects

 

CHAPTER

EIGHT

 

 

ASYNCHRONOUS COMMUNICATIONS 61

Initialize a Serial Port - Transmit via Serial Port - Receive via Serial Port

 

CHAPTER

NINE

 

SELECTORS, MENUS, AND ELECTRONIC BLACKBOARDS 64

Design of the Central Menu - Vertical Free Floating Menus - Selectors - Electronic Blackboards

 

 

CHAPTER

TEN

 

CONTROL OF LASER PRINTERS 70

Opening and Closing Communication Channels - Escape Sequences - Transmission of Characters - Text Transmission - Printing Using the Row Column Grid - The Top Margin - Number of Lines per Page - Reset Margin Settings - Left and Right Margins - Wrap-Around Enable and Disable - Perforation Skip - Backspace - Cursor Movement Across Rows and Columns - Cursor Positioning - Horizontal and Vertical Cursor Movements - Horizontal Pitch - Vertical Spacing - Vertical Motion - Halfway Shifts Up and Down - Subscripts and Superscripts - Underlining - Carriage Return - Line Feed - Carriage Return Followed by Line Feed - Form Feed - Ejection of Page - Reset Printer Setting

 

CHAPTER

ELEVEN

 

 

SPECIAL FEATURES OF THE LASERJET 92

Number of Copies - Orientation - Simplex Printing - Duplex Printing - Binding Edge - Page Break - Paper Trays - Manual Paper Feed - Page Size - Envelopes

 

CHAPTER

TWELVE

 

 

CHARACTER GRAPHICS 99

Horizontal Line - Vertical Line - Coordinates of the XY Graph

 

CHAPTER

THIRTEEN

RASTER GRAPHIC 103

Resolution of Raster Graphics - Definition of the Paint Brush - Initiation of the Raster Graphics Transmission - Transmission of Raster Graphics - Termination of Raster Graphics - Creation of Raster Graphics - Horizontal Line - Vertical Line - Logo Design - Font Design

 

 

APPENDIX

 

ENVIRONMENT FOR PROGRAM DEVELOPMENT 225

Clavis - ASCII and Upper ASCII Templates - Screen Design Templates - Keyboard Codes - Program Development Aids

 

TABLES

 

TABLES FOR PROGRAM DEVELOPMENT 229

The ASCII Chart - The Chart of Design Characters - The BIOS Keyboard Scan Codes - Keyboard Codes Returned by Hardware Port 60h - Selected DOS Interrupts - Selected BIOS Interrupts

  

GLOSSARY 243

  

INDEX 259

  

CHAPTER

1

 

 

INTRODUCTION

 

Design of a modern computer program is a complex task which requires a substantial amount of knowledge of programming in a high level language and typically, also in assembly language. Aside of the development of the functional components of the program, correct structuring of the program components and their integration into a functional whole is crucial to the success of the programming project.

There are several excellent books of the program design, offering invaluable insights into the art of computer programming. Code defensively. Remember the Murhpy's dictum that if anything can go wrong, it will. Learn how to conceal complexity. Each subroutine should do one thing well and hide it, at the same time making the interface between the calling routine and itself highly visible. Find the optimal dividing line between interfacing subroutines, and communicate as few parameters, as possible. Avoid multiple exits from loops. Make sure your variables are initialized. Use meaningful variable names. Eschew temporary variables. Associate the decision points with their corresponding action codes as closely as possible. Do not write long subroutines. If a subroutine stretches over 3 or 4 full screen displays, it is probably too long. Localize input and output subroutines. Identify invalid input and make sure input does not violate program boundaries. Document your program and remember, that a program which runs slowly is far superior to a dysfunctional program running fast. These are maxims to be followed. However, the key difficulty in learning modern program design is that the global program design is developed from the top down, while the actual code has to be written from the bottom up. For the beginning programmer, faced with necessity to code component routines of the programming project, it is easy to loose track of the overriding concerns of the total design and to continue the development of the program along lines which ultimately lead to dysfunctional programs plagued by programming flaws next to impossible to remove.

The organizing principle of the present book is to help the beginning programmer to be aware of the requirements of the overall program design by initially presenting program fragments of calling statements to a variety of library subroutines, to make him or her to be aware of the programming possibilities a comprehensive set of library subroutines offers. Subsequently, the programmer can attempt the development of his or hers own assembly language subroutines, callable from the Fortran programs.

There are several libraries extending Fortran available, the discussion in this book will use the Cruise Fortran Libraries to describe programming concepts and tasks which can be used in the course of the program design and development. The use of the Cruise Libraries does not mean that you should not use other libraries, quite on the contrary. Even though the contents of many dedicated Fortran libraries overlap, typically every library contains many unique subroutines, extending the range of your programming possibilities. By associating several outside libraries with your program design, the range of your programming possibilities widens. Initially, however, let us look at the overall structure of the Cruise Fortran Library.

 

 

SECURING AND DISPLAYING INFORMATION

 

The Cruise Fortran Library replaces Fortran read and write statements with the reads, readn, and writes, writen subroutines to secure and display the textual or numerical information. The reads stands for read string, readn for read number, writes for write string and writen for write number. As different from the Fortran sequential read and write statements, the reads, writes, readn, and writen screen i/o statements can be executed in any order, both temporal and spatial. They also provide for definition of attributes of displayed information and for flexible conversion between numbers as entities which can be algebraically manipulated and entities, suitable for screen displays. They help you to think about numbers in a way you write them on a piece of paper and in a way you calculate them in your head, which are not the same kinds of numbers they appear to be.

The arguments of the reads, readn, writes and writen subroutines have similar syntax. The first argument defines the attributes of the display. The basic attributes are normal, reverse, highlighted, blinking, and their combinations. The following arguments define the offset of the input or the output operations, using the screen row and column coordinates. The fourth argument specifies the format and the last argument provides for transmission of the information to be retrieved or displayed.

 

 

WINDOWS

 

The window subroutine is the key subroutine of modern program design. It was developed following the growing awareness among programmers that the screen displays are windows into the computer memory and that the size of this window, identical to the size of the computer monitor is only one of many possible. By enlarging the area of the memory allocated to the screen displays they realized that more than window can be opened at the same time and by varying the size of these new windows, the modern computer design was born.

When you open a window, you have to first specify its size. The area on the screen, corresponding to the window, is read into memory, saved, and the window surface is cleared. Subsequently, you may write into the window area. When you close the window, the area of the window is read into the memory, saved, and the screen is restored into its original state. All of that is happening at speeds far higher than the normal screen i/o operations, thus creating an illusion that a window is laid on the top of the original screen display. By saving and restoring multiple windows, you may create displays simulating opening of a book and perusing its pages, movable menus, an majority of the paraphernalia typifying the modern screen displays making computing user friendly, flexible, complex, structured, and beautiful.

The reads, readn, writes, and writen are coordinated with the window subroutine to allow you to do all of that easily, efficiently, and sufficiently fast. Remember, it is all done with mirrors and lights, but the key ingredient is the speed which only coding in the assembly language can provide.

 

 

PROGRAMMING AT DOS, BIOS, AND

HARDWARE LEVELS

 

The speed of computing is directly related to the level of interrupts used for development a subroutine. The lower the level, the faster the subroutine. However, there is a price to be paid for the speed and the decision which level to use in which situation is one of the most important to be made in the course of the development of the programming design. There are three main interrupt levels, indicated by the a b or c prefix, as, e.g., a_name, b_name, c_name, where name symbolizes the name of a particular subroutine. The a prefix indicates that the DOS interrupts were used; the b prefix signifies the BIOS interrupts. Subroutines prefixed by the letter c utilize directly the hardware ports. This explicit typing is used when alternate subroutines operating at the different level of interrupts are provided and the decision about the interrupt level to use rests with the programmer.

Most of the subroutines are typed implicitly. In the case of the key subroutines used for design of screen displays, the windows work on the C level, addressing the screen microprocessor directly. The reads, writes, readn and writen subroutines operate either on the B level which is the preferred one, or, sometimes, ascend to the A level, when the nature of the task requires it. This selection of the level is done automatically and does not require the programmer's attention.

If the selection of the level of interrupts to be used is to be done by the programmer, the level of interrupts used is stressed in the description of the alternative subroutine. Thus, e.g., for the screen displays, the subroutine a_pen operates at the A level and the subroutine b_pen at the B level. The alternate subroutines for screen displays carry less overhead than the more general reads, readn, writes, writen subroutines and can be used for more specialized tasks. In selection of the level, one may consider that the direct hardware access subroutines (the C level) are the fastest while the level A subroutines are the slowest with the BIOS B level subroutines located in between. However, as usual, one trades the increased speed of execution for increased hardware dependency. Also, the DOS interrupts provide for more functions than the BIOS interrupts and BIOS interrupts are by far more varied than the interrupts accessing the hardware directly.

 

 

THE KEYBOARD

 

A large group of subroutines are the subroutines for the control and redefinition of keyboard. The keyboard can be imagined as consisting of three levels. The surface level, associated with the DOS keyboard interrupts and the ANSI keyboard driver programmed by the escape sequences, the intermediate level controlled by the BIOS interrupts, and the deep level which can be controlled by the in/out assembly language calls, accessing directly the pins of the keyboard microprocessor.

The surface level is typically used when writing utility programs, operating outside of the main application programs. The intermediate level is the level to use when writing the application programs. This level is impervious to key assignments frequently done by users at the DOS level which could impair the integrity of the input controls within your program. The deep level is seldom used, but some special programs necessitate input control at this level; an example of such an application might be a program for the redefinition of the QUERTY keyboard into the DVORAK keyboard which would be operational even within the application word processing programs.

The subroutines within this group may be classified to two groups. The first group consists of subroutines, controlling the state of the keyboard, as the state of the NUmLock, CapsLock, and Scroll Lock keys. These keys should be reset into the preferred states prior to passing control into the main routines of the program. The second group of subroutines in this category consists of the inkey types of subroutines; main subroutines of this group are the a_key, b_key, and key subroutines. These subroutines operate at the A and B level of interrupts. The subroutines of choice are the b_key and the key. One of the important decisions within this context is whether to use the BIOS interrupt 0h/16h for the control of the standard keyboard, or the BIOS interrupt 10h/16h for the control of the extended keyboard. The main advantage of using the extended keyboard is that you may use the function keys 11 and 12 and assign different function to the gray Insert, Delete, Home, End, Page Up, Page Down, to the arrow cluster of keys, and to the corresponding keys on the numerical keypad. However there is a price to pay in the incompatibility of your program with the older keyboards.

 

 

DISKS AND DISK FILES

 

Subroutines in this group can determine how many drives are installed on the system, can find the location of home directory, change a drive, describe drive in terms of size and used and free disk space, determine a path within a current directory, change a directory, remove directory, create a new directory, display a directory, delete files, and more. These are the necessary tools for development of larger programming projects, consisting of several programs working in concert.

 

 

COORDINATION OF PROGRAM EXECUTION

 

The distinct separate group are subroutines for control of the program execution, facilitating integration of programs and their coordination. The libraries contain subroutines for the program execution control via the environment tokens, switches located on the continuation of the program invoking command, subroutines for catenation of programs, and more.

 

 

CONTROL OF LASER PRINTERS

 

The Hewlett-Packard Printer Control Language is gaining wide acceptance as a standard for control of the printed output. The description of subroutines in the Cruise LaserJet Library is used to demonstrate low level control of the appearance of the output generated by the Laser printers.

 

 

GETTING STARTED

 

The subroutines and functions in the Cruise Fortran Libraries were named and structured as to become permanent additions to the general programming statements; written for computers using INTEL's iAPX 88 / 186 / 286 / 386 / 486 microprocessors and Microsoft DOS operating system, the subroutines were selected with stress on clarity of presentation, general utility, and anticipated frequency of use. Operations already implemented by the Microsoft Fortran compiler were not duplicated; some of them were extended or simplified. Most routines were written in assembly language, but higher languages, especially C, were used whenever appropriate.

The subroutines were originally tailored to the requirements of Microsoft Fortran Version 3.3. Following version of the library was Beta tested on the Version 4.0 and subsequently tuned to the requirements of the Versions 4.1 and 5.1. In most cases you need not worry about version compatibility, however to minimize possible version conflicts, your compiler should be in the compatible mode with the previous version.

After perusing the library subroutines, create a series of miniature Fortran programs and call the subroutines you think you may use in design of your programs. Every subroutine or function described in the following chapters contains a description of its calling conventions and a fragment of the code which surrounds its invoking and allows for demonstration of its essential properties. Subsequently, you may like to begin the development of your own routines; the chapters on the programming in the assembly language and chapters dedicated to interfacing of assembly language subroutines with the Fortran programs provide direction in this respect.

Initially, it is easier to start a programming project by using library subroutines already developed and complement the available subroutines with the custom designed subroutines according to the specific requirements of each design project. Thus, our discussion commences with the description of key routines contained by the Cruise Fortran Libraries.

CHAPTER

2

 

SYSTEM CONFIGURATION

AND ORIENTATION IN TIME

 

Few initial statements of some programs may pertain to inquiry about the computing environment. The determination of the type of the central processor unit may be of importance for certain applications. Sometimes, some parts of the program may run efficiently only on the 386 or 486 machines and may be better bypassed if the program is run on the iAPX 88 or 286 machines. Typical problem, related to the type of the microprocessor the program is running on is associated with the use of the sound routines. The sound may sound quite differently if the program is running on the 386 machine then when running on the PC or XT. In this case, the checking of the type of the central processor unit may be of importance. Often, the program may have special requirements about the presence of device handlers in the config.sys file or the type of microprocessor the computer was build around. Following these initial inquiries, the program may require the retrieval of time, as set within the computer. Some of the routines which can be employed to accomplish these tasks are discussed in this chapter.

 

 

TYPE OF THE CENTRAL PROCESSOR UNIT

 

The CPU subroutine determines the type of the central processor unit the program is running on. The subroutine is called as

 

call cpu(a)

 

The argument should be dimensioned as character a*1 and returns 1 if the central processing unit is Intel's iAPX 88, 86, 188, 186 or NEC V16 V20 processors. The 2 is returned for iAPX 286, 3 for iAPX 386 central processor unit, 4 for the iAPX 486 or higher. A program fragment, calling the subroutine is presented below.

 

 

Listing 2. Fortran Implementation of the CPU Subroutine

------------------------------------------------

character a*1

call cpu(a)

select case(a)

case('1')

write(*,*)'The Central Processing Unit is Intel''s iAPX 8088'

case('2')

write(*,*)'The Central Processing Unit is Intel''s iAPX 286'

case('3')

write(*,*)'The Central Processing Unit is Intel''s iAPX 386'

case('4')

write(*,*)'The Central Processing Unit is Intel''s iAPX 486 or higher'

end select

end

------------------------------------------------

 

 

VERSION OF THE OPERATING SYSTEM

 

The DOS_VER subroutine allows you to determine the version of the operating system. The subroutine is called as

 

call dos_ver(i,j)

 

where i returns the verson number and j the revision number. A program fragment, calling the subroutine is presented below.

 

 

Listing 2. Version of the Operating System

------------------------------------------------

call dos_ver(i,j)

write(*,*)i,j

end

------------------------------------------------

 

 

SYSTEM MEMORY

 

The MEMORY subroutine allows you to determine whether the system has at least the full amount of the 640K memory. The subroutine is called as

 

call memory(ix)

 

and the amount of memory available is returned in the ix parameter. A program fragment, calling the subroutine is presented below.

 

 

Listing 2. System Memory

------------------------------------------------

call memory(ix)

write(*,*)ix

end

------------------------------------------------

 

The subroutine uses the BIOS interrupt 12h which returns the number of contiguous 1k blocks of memory up to 640 K.

 

 

UPPER MEMORY

 

The MEM_UP subroutine determine the available amount of the memory above the 1M. The subroutine is called as

 

call mem_up(ix)

 

and returns the amount of the extended memory installed in the ix parameter. A program fragment, calling the subroutine is presented below.

 

 

Listing 2. System Memory

------------------------------------------------

call mem_up(ix)

write(*,*)ix

end

------------------------------------------------

 

The subroutine uses the BIOS interrupt 88h/15h, returning the number of contiguous 1k blocks of RAM above 1M.

 

 

MEMORY AVAILABLE TO PROGRAM

 

To determine the amount of memory available to the program, you may call the MEM subroutine. The mem subroutine uses the DOS interrupt 48h/21h to allocate memory which, on return, contains in the bx register the maximum number of continuous paragraphs available. The subroutine can be called form a Fortran program as

 

call mem(i)

 

where i is the amount of available memory in paragraphs. The mem subroutine in no way alters the memory contents. Since every paragraph is 16 bytes long, the conversion into bytes is easy to accomplish, as suggested in the following fragment of Fortran code.

 

 

Listing 6. Determining the Anmount of Remaining Memory

------------------------------------------------

call mem(i)

write(*,*)i*16

end

------------------------------------------------

 

 

PRESENCE OF ANSI.SYS DRIVER

 

Sometimes, the programmer may wish to make use of the ansi.sys driver. The ANSI subroutine detects the presence of this driver. The ansi.sys device driver facilitates extended screen and keyboard control by using series of standardized escape sequences. The driver is located in the config.sys file as a statement device=ansi.sys. The subroutine is called as:

 

call ansi(a)

 

The argument should be dimensioned as character a*1. The argument returns the plus sign if the driver is present and the minus sign if the driver was not installed at the time the computer was booted. Example of a Fortran program call is listed below.

 

 

Listing 2. Fortran Implementation of the ANSI Subroutine

------------------------------------------------

character a*1

call ansi(a)

if(a.eq.'+')then

write(*,*)'Ansi.sys detected'

else

write(*,*)'Ansi.sys absent.'

endif

end

------------------------------------------------

 

 

RETRIEVE DATE AND DAY OF THE WEEK

 

The Microsoft Fortran intrinsic function GETDAT retrieves the year, month, and day. The DAY subroutine returns the current date as set in the operating system, including the day of the week. Parameters of the subroutine are month, day of the month, year, and the day of the week. The subroutine is called as

 

call day(im,id,iy,iw)

The month and the day are returned as one or two digit integers, the year is a four digit integer, the day of the week is returned as a one digit integer which indexes Sunday with zero, Monday with 1, etc. An example calling this subroutine from the Fortran program is listed below.

 

 

Listing 2. Retrieving Date and Day of the Week

------------------------------------------------

call day(im,id,iy,iw)

if(iw.eq.3)write(*,*)'Call Maurice.'

end

------------------------------------------------

 

 

DATE COMPOSITION

 

The DAYS subroutine allows to write the system date with months and days spelled out. It also allows to integrate the date into the surrounding text and add the specification of the locale. The subroutine is called as

 

call days(len1,len2,datum)

 

and calculates the relevant lengths within the returned alphanumeric string allowing for writing date without unsightly gaps between months of the varying length. The len1 argument is the length of the datum string up to the end of the year and len2 the length of the datum string up to the end of the day of the week. The datum array is variably dimensioned, the recommended size of the datum array is datum*30. The Fortran calls are presented below.

 

 

Listing 2. Composing the Date

------------------------------------------------

character datum*30

call days(len1,len2,datum)

write(*,'(6h Date:,1x,a)')datum(1:len1)

write(*,'(6h Date:,1x,a,1h.)')datum(1:len2)

write(*,*)datum

write(*,'(a,a)')' Minneapolis, Minnesota, ',datum

end

------------------------------------------------

 

result in date formats (for a certain system date), as tabulated below.

 

Table 2. Date Formats of the Days Subroutine

------------------------------------------------

Date: January 7, 1991

Date: January 7, 1991; Friday.

January 7, 1991; Friday

Minneapolis, Minnesota, January 7, 1991; Friday

 

------------------------------------------------

 

 

MEASURE ELAPSED TIME

 

The CENTIS subroutine computes elapsed time in centiseconds. It is used in benchmarking and comparisons of efficiency of alternative routines. The subroutine returns the elapsed time in centiseconds in its argument. It is called as

 

call centis(itime1)

 

An example of its usage is given below.

 

 

Listing 2. Measuring the Elapsed Time in Centiseconds

------------------------------------------------

call centis(itime1)

... code...

call centis(itime2)

ics=itime2-itime1

write(*,*)ics

------------------------------------------------

 

The SECNDS subroutine computes elapsed time in seconds. It is used for timing execution of various tasks, such as iteration routines or lengthy calculations, it indicates that something is happening, that the computer didn't just go down, but is working on some task which takes time, and it tells how much time the task takes. This timing also helps the user learn to estimate the time it will take to execute some other lengthy task, by providing experience with timing of similar tasks. An example of its usage follows.

 

 

Listing 2. Measuring the Elapsed Time in Seconds

------------------------------------------------

logical*1 terminate \.false.\

ics=0

call secnds(it1)

1 write(*,'(1h+,40x,5hTime:,i7)')ics

call iterate(terminate)

if(terminate)goto 9

call secnds(it2)

ics=it2-it1

goto 1

9 write(*,*)'Iteration terminated.'

------------------------------------------------

 

 

DELAY PROGRAM CONTINUATION

 

The DELAYS subroutine delays execution of the next program statement by the number of deciseconds specified by its argument. The subroutine is called as

 

call delays(idecs)

 

The valid time range is 1-600 deciseconds, i.e., from .1 second to one minute. The values of the argument and their corresponding time values are presented below.

 

Table 2. Translations of Seconds and Minutes to Centiseconds

------------------------------------------------

 

.5 sec

1.0 sec

3.0 sec

10.0 sec

1.0 min

5 deciseconds

10 deciseconds

30 deciseconds

100 deciseconds

600 deciseconds

 

 

An example of the Fortran call follows.

 

 

Listing 2. Delaying Execution of the Next Program Statement by Specified Number of Deciseconds

------------------------------------------------

call cls

write(*,*)'Hello'

call delays(30)

call cls

------------------------------------------------

 

The delays subroutine uses the BIOS interrupt 86h/15h which is available only on the i286 class of computers or higher. An alternative form of this subroutine is the subroutine delay which performs the same task by calling the computer timer directly. The argument of the delay subroutine is calibrated in centiseconds; thus the equivalent of the call of the delays subroutine as call delays(30) would be the call of the delay subroutine as call delay(300).

CHAPTER

3

 

 

THE KEYBOARD

 

The subroutines for the control of the keyboard help to determine the initial status of the keyboard, i.e., are the capitals locked in or what is the status of the numerical keypad. They also allow for redefinition of key assignments. The main subroutines of this group secure input of information into the program. The input can be sceured at the level of DOS interrupts, at the level of BIOS interrupts, or by directly addressing the keyboard hardware ports. It is quite important to decide which level of input from the keyboard to use for specific features of the program. This is the central issue of discussion in this chapter.

 

 

TYPE OF KEYBOARD

 

The extended keyboard was introduced in 1987 and added the keypad keys, several new 'grey' keys and Function 11 and Function 12 keys. In BIOS, new interrupt 10h/16h was added, allowing to acces keystrokes not recognized by the old interrupt 0h/16h. The extended keyboard is available only on the i286 class of computers or higher. To recognize the presence of the extended keyboard, the keyboard subroutine writes a test pattern to the keyboard buffer and reads it back. The subroutine is called as

 

call keyboard(a)

 

The keyboard's subroutine single argument returns a plus sign if the extended keyboard was detected, the minus sign if the extended keyboard is not attached to the computer. An example of a Fortran call is

 

Listing 3. Type of Keyboard

character*1 a

call keyboard(a)

write(*,*)a

end

 

and the subroutine is listed below.

 

 

Listing 3. Type of Keyboard Source Listing

------------------------------------------------

;T H E KEYBOARD S U B R O U T I N E

;call keyboard(a) ;a typical Fortran call

public keyboard

.model large

.stack 64

.code

keyboard proc far

;Save base

push bp

mov bp,sp

;Save registers

push ax

push bx

push cx

push dx

mov bx,[bp+6] ;the last argument

;Write Test Pattern to Keyboard Buffer

mov cx,0ffffh

mov ah,05h

int 16h

mov cx,16 ;set loop counter

do: mov ah,10h

int 16h

cmp ax,0ffffh

je ext

loop do

jmp old

ext: mov al,'+'

mov [bx],al

jmp adieu

old: mov al,'-'

mov [bx],al

adieu: pop dx

pop cx

pop bx

pop ax

pop bp

ret 4

keyboard endp

end

 

 

SENSING THE STATE OF CAPS LOCK AND

NUM LOCK KEYS

 

The C_LOCK subroutine acknowledges whether the CapsLock is engaged. Checking for the engaged CapsLock key before requesting case sensitive input is a considerate practice. The subroutine is called as

 

call c_lock(x)

 

where the argument x is declared as character*1. The plus character is returned if the capital letters are locked in, otherwise the minus is reported upon the return of the subroutine to the calling program. A fragment of the program, using this subroutine is presented below.

 

 

Listing 3. Sensing whether the CapsLock Key is Engaged

------------------------------------------------

character*1 x

call c_lock(x)

if(x.eq.'+')write(*,*)'Please reset the CapsLock key'

end

------------------------------------------------

 

The N_LOCK subroutine reports whether the NumLock key is engaged. Most computers boot with the keypad locked in the numerical mode. Applications which use extensively the Insert key often have problems with users pressing the Insert key on the keypad locked in the numerical mode and getting zero inserted instead. Similar problems may be encountered when using the End, Home, Delete, or Page Up and Page Down keys for the program execution control. The subroutine is called as

 

call n_lock(x)

 

with the argument x declared as character*1, returning the plus sign if the NumLock key is engaged and the minus sigh otherwise. A program fragment forcing the user to reset the NumLock key is presented below.

 

 

Listing 3. Sensing whether the NumLock Key is Engaged

------------------------------------------------

character*1 x

1 call n_lock(x)

if(x.eq.'+')then

call writes('n',23,40,'n','Please reset the NumLock key')

goto 1

endif

------------------------------------------------

 

Both the c_lock and n_lock subroutine help with the development of the user interfaces sections of the application programs.

 

 

UNLOCKING CAPS AND KEYPAD KEYS

 

The LOCK subroutine gives you direct control over the keyboard Lock keys. Calling the subroutine unlocks the NumLock, CapsLocks, and the Scroll Lock keys. The subroutine is called as

 

call locks

 

and has no arguments. A fragment of the program, using this subroutine is presented below.

 

 

Listing 3. Unlocking the Lock Keys on the Keyboard

------------------------------------------------

call locks

end

------------------------------------------------

 

 

REDEFINE KEYBOARD KEY ASSIGNMENTS

 

The KEY_DEF subroutine facilitates the assignment of alternate characters, text, or commands to virtually any keyboard key from within the Fortran program. The key_def subroutine can be called in a declarative mode or as a query. The declarative mode, signified by an exclamation mark, appends the carriage return after the text string so that the command gets executed. The query mode does not append the carriage return, so that further specifications may be added to the command before its execution. An example of the declarative mode, defining the ALT D key as a MS-DOS directory command, is

call key_def('0;32,dir/p!')

An example of a query is presented below

call key_def('0;46,copy *.* ?')

assigning the copy all command to the ALT C key. The argument of the key_def subroutine must always be terminated with either a question mark or with an exclamation mark, the scan code must be separated from the text by a comma, and the whole argument must be enclosed in single quotes. An example of a Fortran program, using the key_def subroutine, is listed below.

 

 

Listing 3. Assigning Text or Commands to Keyboard Keys

------------------------------------------------

call key_def('0;30,Hi there!') ! Alt A

call key_def('0;46,Copy ?') ! Alt C

stop 'Keys defined.'

end

------------------------------------------------

 

 

INPUT AT THE LEVEL OF DOS INTERRUPTS

 

Subroutine A_KEY accepts input of a single character from the keyboard without depression of the enter key. The keyboard input is via MS-DOS call 7h/21h, which does not echo and ignores the control c sequence. This routine is called as

 

call a_key(a,'*')

 

The first argument has to be dimensioned as character*1. The second argument, if entered as '+', translates of the secured characters into the uppercase; if entered as '-', translates the character in the first argument to lowercase. Any other character causes the subroutine to ignore the uppercase or lowercase translation options. A program fragment, illustrating the use of the a_key subroutine is presented below.

 

 

Listing 3. The A_KEY Subroutine for Keyboard Input

------------------------------------------------

character*1 a

write(*,*)'Translate input into lowercase'

call a_key(a,'-')

write(*,*)a

write(*,*)'Translate input into uppercase'

call a_key(a,'+')

write(*,*)a

write(*,*)'Input without translation of case'

call a_key(a,'0')

write(*,*)a

end

------------------------------------------------

 

The a_key subroutine is capable of reading the keyboard key assignments made by the key_def subroutine; it also can recognize the F11 and F12 function keys.

 

 

INPUT AT THE LEVEL OF BIOS INTERRUPTS

 

Subroutine B_KEY accepts input of a single character from the keyboard without depression of the enter key. Typically, it is used used to secure input from the special keys as arrows, page up, page down, home, end, etc. The keyboard input is via BIOS call 0h/16h, which does not echo, ignores the control c sequence and checks for the control break sequence only if the DOS command break on is stored in the environment. Also, the BIOS 0h/16h interrupt does not recognize the F11 and F12 keys. This routine is called as

 

character a*1

call b_key(a,ix,'*')

 

where the first argument returns the character typed at the keyboard and the second argument returns the key scan code. The third argument, if specified as '+', translates the input characters into uppercase, if specified as '-', into the lowercase. Any other character in the third argument causes the subroutine to ingnore the case translation options.

Subroutine X_KEY is the upgraded b_key subroutine, calling the 10h/16h interrupt and making possible to secure input from the enhanced keyboard, including the input from the F11 and F12 Keys and over 20 new control and alternate keys combinations.

A tour de force is the subroutine XB_KEY which tests the keyboard and selects the appropriate call, either via the 0h/16h, or the 10h/16h interrupts. Using this subroutine you may write programs using all keys of the extended keyboard which are also compatible with the old PC and XT machines. The new keys should be used as accelerator keys only. In case the program is run on computer with an old keyboard, the program should provide some roundabout path to access all its features. The penalty for using the xb_key subroutine is the increase in size compared to either b_key or the x_key subroutines, and inability to type ahead, since the input buffer must be flushed after the keyboard test. Since this subroutine is typically not used for the input of text, but only to secure input at the decision points, this typically presents no problem. Where the compatibility is at premium, the xb_key subroutine is the subroutine of choice.

An example of the use of the x_key subroutine is listed below

 

 

Listing 3. The X_KEY Subroutine for Keyboard Input

------------------------------------------------

character*1 a

1 write(*,*)'Translate input into lowercase'

call x_key(a,ix,'-')

write(*,*)a,ix

write(*,*)'Translate input into uppercase'

call x_key(a,ix,'+')

write(*,*)a,ix

write(*,*)'Input without translation of case'

call x_key(a,ix,'*') !terminates on ctrl break if break on

write(*,*)a,ix

write(*,*)'Press F12'

call x_key(a,ix,'*')

write(*,*)a,ix

write(*,*)'Press CTRL U'

call x_key(a,ix,'*')

write(*,*)ichar(a),ix

write(*,*)'Press ALT U'

call x_key(a,ix,'*')

write(*,*)ichar(a),ix

write(*,*)'Press GRAY INS'

call x_key(a,ix,'*')

write(*,*)ichar(a),ix

write(*,*)'Press INS on the Keypad'

call x_key(a,ix,'*')

write(*,*)ichar(a),ix

write(*,*)'Lock Keyboard and Press INS on the Keypad'

call x_key(a,ix,'*')

write(*,*)ichar(a),ix

goto 1

end

------------------------------------------------

 

 

and its source code listing is

 

 

Listing 3. Source Code of the X_KEY Subroutine

------------------------------------------------

 

;T H E X_KEY S U B R O U T I N E

;call x_key(a,ix,'+') ;a typical Fortran call

public x_key

.model large

.stack 64

.code

x_key proc far

;Save base

push bp

mov bp,sp

;Save registers

push ax

push bx

push cx

push dx

mov bx,[bp+6] ;the last argument

mov cl,[bx]

;Input character and scan code

mov ah,10h ;extended keyboard

int 16h

;Conversions to upper or lower case

cmp cl,'+'

je uppercase

cmp cl,'-'

je lowercase

jmp deposit

uppercase label near

cmp al,'a'

jb deposit

cmp al,'z'

ja deposit

and al,01011111b ;mask out the fifth bit

jmp deposit

lowercase label near

cmp al,'A'

jb deposit

cmp al,'Z'

ja deposit

or al,00100000b ;convert to lowercase

deposit label near

mov bx,[bp+14] ;first argument address

mov [bx],al ;ASCII char out

mov si,[bp+10] ;address of ix

mov [si],ah ;scan code out

;Return

pop dx

pop cx

pop bx

pop ax

pop bp

ret 12

x_key endp

end

------------------------------------------------

 

 

THE MAPPED KEYBOARD INPUT

 

The KEY subroutine secures input of both upper and lower parts of the ASCII character set by mapping selected characters from the upper ASCII set into the alternate keys of the keyboard. The chart of the mapped keys can be overlayed over the current screen display by pressing a selectable key on the keyboard, typically the F1 or F2 key. The display of the chart is context sensitive. The selection of the mapped characters and their assignments are quite general and confirm to the requirements of most programming designs. The alt 0, alt 1 and alt 2 keys add the capability to use the zero, 1/2, and 2 powers. The Greek characters are mapped into their corresponding Latin character alt keys and the scientific notation characters between ASCII 224 and ASCII 255 are mnemonically assigned to alternate keys of the keyboard, as, e.g., the infinity sign being mapped to alt i, and the square root sign into the alt r. The key subroutine is called as

 

call key(a,ix,'*',map)

 

The first three arguments of the key subroutine are the same as of the b_key or b_keys subroutines. The first argument returns the character typed, the second argument returns the scan code. The scan codes returned by the BIOS interrupt 0h/16h are listed in the last chapter, describing the programming environment utilities, including the relevant tables. The third argument, if set to '+", translates the input into uppercase, if set to '-', into the lowercase. The last argument defines the key to be used as the 'help' key displaying the chart of the mapped characters. A program fragment, using the key subroutine is listed below.

 

 

Listing 3. The KEY Subroutine for Keyboard Input

------------------------------------------------

character a*1

call key(a,ix,'*',59) !The help key is F1

if(ix.eq.1)stop

call writes('r',7,7,'n',a)

---------------------------------------------

 

The Key subroutine is typically called from the Reads subroutine.

 

 

SECURE RESPONSE TO A QUERY

 

The QUERY subroutine saves coding of several Fortran statements frequently used to obtain keyboard input, check for input errors, and branch according to the value of the input character. The argument field of the query subroutine consists of two parts. The first part contains an integer variable returning the ordinal position of the selected character located in the second argument field. The second part contains list of tokens to be matched. All tokens must be in lowercase. The Fortran call of this subroutine is as, e.g.,

call query(ians,'a,b')

Following the call, a match is attempted between a keyboard reply (no carriage return, inkey type) and the argument list. If no match is found, the query routine expects additional input. Any uppercase input is translated into lowercase. Single digit numbers such as 0,1,2,3,4,5,6,7,8,9 can be used. To specify keys with no corresponding keyboard characters, associate the BIOS keyboard code with an ASCII character code; thus, e.g., the function key F1 with the BIOS keyboard code of 59 translates into a semicolon. The query subroutine also checks for the escape key. If the escape key is depressed, the ians argument will be returned as equal to zero. An example of a Fortran program using this subroutine is listed below

 

 

Listing 3. The QUERY Subroutine for Selection from a List of Alternatives

------------------------------------------------

write(*,*)'Select alternative A B or C'

call query(ians,'a,b,c')

select case(ians)

case(0)

stop

case(1)

write(*,*)'The first decision point'

case(2)

write(*,*)'The second decision point'

case(3)

write(*,*)'The third decision point'

end select

------------------------------------------------

 

 

The source code for the Query subroutine is

 

 

Listing 3. Source Code of the QUERY Subroutine

------------------------------------------------

subroutine query(iorder,a)

character *(*)a,x*1

max=length(a)

1 call b_key(x,iterm,'-')

if(iterm.eq.1)then !Escape

iorder=0

return

endif

iorder=0

do i=1,max

if(a(i:i).ne.',')iorder=iorder+1

if(a(i:i).eq.x)return

if(ichar(x).eq.0.and.ichar(a(i:i)).eq.iterm)retu rn

end do

call tone 0

goto 1

end

------------------------------------------------

CHAPTER

4

 

 

SCREEN DISPLAYS

 

The subroutines controlling the screen displays are the principal tools of the program development. In this chapter we are going to discuss subroutines for displaying information on the computer's screen, reading information displayed on the screen, and designing screen displays. The characters, used in screen displays and their corresponding codes are listed in Tables on the end of the book. Aside of the regular letters of the alphabet, they also include special characters, Greek characters, characters for drawing lines and borders and characters for creation of special graphic effects.

Each character displayed in the video buffer contains two bytes of information. The ASCII value of the character and the character's display attribute. The attribute byte determines whether a character is highlighted, blinking, underlined, or in reverse video. The subroutines discussed frequently provide for specification of the attribute byte of the displayed characters in the first parameter of their arguments.

The key procedures for programming screen displays are the window, reads, readn, writes, writen subroutines. They are complemented by the subroutines for framing screen display areas, creation of screen background textures, and by numerous auxiliary subroutines.

 

 

CLEAR SCREEN

 

The CLS subroutine clears the screen by scrolling it up and positioning the cursor to the upper left corner. The Fortran call is

call cls

The cls subroutine scrolls the screen and repositions the cursor by using the BIOS interrupt 10h. This routine is the Fortran callable counterpart of the MS-DOS keyboard callable utility cls.

A variation of the cls subroutine is the subroutine SCD. The SCreen Down subroutine is functionally equivalent to the CLS subroutine. However, it scrolls the screen down and positions the cursor to the lower left corner of the screen. The subsequent screen displays will be scrolled from the bottom to the top of the screen. The subroutine is called from a the Fortran program as

 

call scd

 

and has no arguments.

 

 

REVERSE SCREEN

 

The REVERS subroutine changes the surface of a video screen into the reverse video and back to the normal state. This subroutine has two parameters. The plus sign to change screen to a reverse video and the minus sign to obverse screen to the normal state. Example of the Fortran call is

call revers('+')

Sample usage is presented in Listing 4..

 

 

Listing 4. Reverse Video Screen

------------------------------------------------

character*1 a

write(*,*)' Revers <+/->'

read(*,'(a)')a

call cls

call revers(a)

write(*,*)' Hello world'

call tab

call scd

write(*,'(24(1x,77(1h*)/))')

call tab

------------------------------------------------

 

 

BLINKING MESSAGE

 

The BLINK subroutine makes the text blink. The text should be terminated with another call blink statement, this time with the minus argument. To remove the blinking text, overwrite it with blanks. The Fortran call is

call blink('+')

An example of its use is listed below.

 

 

Listing 4. Blinking Messages

------------------------------------------------

call blink('+')

write(*,*)' Hello world'

call blink('-')

------------------------------------------------

 

The Blink subroutine operates on the level of DOS interrupts.

 

 

INVISIBLE PASSWORD ENTRY

 

The SECRET subroutine turns the screen display off. It can be used in situations when you want to secure input from some peripheral device as, e.g., the keyboard, without echoing the input on the screen. This subroutine is useful when entering a secret password. Another use of this subroutine is in situations when a graphic display fills the whole screen and a response to a query would write over some part of the display.

The +/- [on/off] switch constitutes the only parameter. The plus sign turns the screen display off. The minus sign restores the normal screen display. The cursor is not turned off by this subroutine. To totally blank the screen, you have also to call the cursor('i') subroutine. Example of the Fortran call is

call secret ('+')

An example of the use of this subroutine is listed below.

 

 

Listing 4. Invisible Writing into the Screen

------------------------------------------------

character string*6,mask*6

mask='sesame'

write(*,'(a\)')' Enter password: '

call secret('+')

read(*,'(a)')string

call secret('-')

if(string.eq.mask)then

write(*,*)'Access permitted.'

else

write(*,*)'Access denied.'

endif

------------------------------------------------

 

 

REDEFINE CURSOR SHAPE

 

The CURSOR subroutine, although simple, is indispensable for the modern screen design. To make the cursor take on a different shape when a different type of input is expected, or to make the cursor disappear, is one of the most mundane programming chores. The subroutine is called as, e.g.,

 

call cursor('i')

 

with possible values of the argument summarized in Table 4..

 

Table 4. Definitions of Cursor Shape

[i] invisible

[h] hair

[l] line

[d] dash

[c] cube

[b] block

[s] split

[u] underlined

makes cursor disappear

a thin bottom line

a double line cursor

a heavy line cursor

a small square

a large rectangle

a top-bottom thin line cursor

an exclamation mark shape

 

LOCATE CURSOR

 

The GETCUR subroutine returns the screen coordinates of the current cursor location. The determination of these coordinates is necessary for the flexible screen display control. This subroutine is called from the Fortran program as

 

call getcur(i,j)

 

The integer parameters i and j are the screen row and column cursor coordinates. An example of the use of this subroutine is given below.

 

 

Listing 4. Location of the Cursor

------------------------------------------------

call getcur(i,j)

write(*,'(a,2i3)')' Cursor location:',i,j

call tab

end

------------------------------------------------

 

 

REPOSITION CURSOR

 

The SETCUR subroutine repositions cursor to a new location on the screen. The subroutine is called as

 

call setcur(i,j)

 

The integer parameters i and j are row and column screen coordinates where the cursor is to be repositioned. The setcur subroutine is called in an absolute manner as, e.g.,

 

call setcur(12,30)

 

which repositions the cursor to a certain location on the screen. The relative call to this subroutine has to be preceded by the call to the getcur subroutine, as shown in the example below.

 

 

Listing 4. Location of the Cursor

------------------------------------------------

call getcur(i,j)

call setcur(i+3,j+7)

write(*,'(a,2i3)')' The Offset of this Message is',i+3,j+7'

------------------------------------------------

 

 

FRAME A SCREEN DISPLAY AREA

 

The square areas, delineated by single or double line borders, are the building blocks of the modern screen designs. Calling the FRAME subroutine will create a box on the screen, optionally in reverse video. The arguments of the Frame subroutine are similar to those of the Window subroutine and the Frame subroutine should be used whenever possible in lieu of the Windows subroutine, since it carries substantially lower overhead. The use of the Frame subroutine is mandatory in cases of chaining a number of boxes in circular menus which can recur dozens or hundreds of times, since the repeated use of the Windows subroutine will eventually run out of the memory storage. Obviously, the Frame subroutine does not preserve the content of the overlaid area on the screen, as the Window subroutine. Often, the Window and the Frame subroutines can be combined. The Window subroutine is called first to overlay the screen display, and the window is subdivided into the areas dictated by its design by the Frame subroutine.

To position the box on the screen, first, define its appearance by using one of the q r t s arguments, described below, and then define its coordinates by using the standard screen grid indexed from 0 to 24 by its rows and from 0 to 79 by its columns. The Fortran call is

 

call frame('x',i,j,k,l)

 

where x determines the character of the border lines and i,j,k,l are the coordinates of the upper left and the lower right corner of the box. The values of the x parameter are 'b' for bold(thick) borders, 'c' for borders combining double and single line border, 'q' for the double line borders, 'r' for the double line border and the reverse video fill, 's' for the single line border, and 't' for the single line border and the reverse video fill. A fragment of a program, calling the frame subroutine, is listed below.

 

 

Listing 4. Framing a Screen Area

------------------------------------------------

call cursor('i')

call cls

call frame('q', 0, 0,23,79)

call frame('r',10,15,12,45)

call frame('s',17, 8,20,60)

call frame('t',17, 8,20,60)

call tab

call setcur(0,0)

------------------------------------------------

 

 

SCREEN BACKGROUND TEXTURES

 

The SHADOW subroutine changes the ordinarily black screen background into mellow textures, well suited to be superimposed on screen windows or for subsequent framing. Three texture types are available. These types are selected by calling the shadow subroutine as shown in the following statements.

 

call shadow('dark',i,j,k,l)

call shadow('medium',i,j,k,l)

call shadow('light',i,j,k,l)

 

where the i,j,k,and l arguments define the screen coordinates of the upper left and bottom right corners of the area to be painted over. The shadow subroutine can well complement the window subroutine or be complemented by the frame subroutine, as shown in the example of Fortran implementation of the window, frame, and shadow subroutines below.

 

 

Listing 4. Framed Screen Areas With Textured Background

------------------------------------------------

call cursor('i')

call window('s',0,0,24,79)

call shadow('dark',1,1,23,78)

call tab

call shadow('medium',15,15,20,60)

call frame('d',15,15,20,60)

call tab

call shadow('light',17,17,19,70)

call frame('d',17,17,19,70)

call tab

call shut

call cls

call cursor('h')

------------------------------------------------

 

In the above example, notice that the shadow routine painting the suface of the window must be called after the window subroutine and must be dimensioned to cover a smaller area than the window subroutine not to overwrite the borders of the window. On the other hand, the frame subroutine should be either called after the shadow subroutine, or dimensioned with coordinates not overlapping with the coordinates of the shadow subroutine.

 

 

DEFINE ATTRIBUTES OF THE SCROLLED SCREEN

 

The SCROLL subroutine imposes a new attribute on selected areas of the screen surface. In some respects, this operation opens a "window" on the video screen. However, as contrasted with the window subroutine, the screen area painted over is not saved and cannot be subsequently restored. It is also possible to use the scroll subroutine just for clearing of selected screen areas without changing the screen surface attribute. The first parameter of the scroll subroutine is the attribute to be imposed on the scrolled screen area. Three attributes are supported. Reverse [r], underlined [u] and normal [n]. The next four parameters are the left upper row and column [i,j] and the right lower row and column [k,l] coordinates. The example of Fortran call is

call scroll('r',0,0,15,79)

A sample Fortran program, demonstrating the properties of the scroll subroutine is presented below.

 

 

Listing 4. Scrolling the Screen Areas

------------------------------------------------

character*1 x

write(*,*)'Define the Scroll Attribute <r,u,n>'

read(*,'(a)')x

write(*,*)'Coordinates of the Upper Left and Lower Right Corners:'

read(*,*)i,j,k,l

call scroll(x,i,j,k,l)

------------------------------------------------

 

 

COVER PAGE DISPLAY

 

The COVER subroutine composes full screen displays using characters from the Cruise Font Library. This subroutine has two arguments. The first argument is the character to use for the writing letters, selected from the font library. Letters in the font library were constructed by using character 219. Using another fill characters, as # 221 or 240 can improve the appearance of the front page of your program. The second argument of the subroutine is the file name, containing your front page display. The subroutine is called, as, e.g.,

 

call cover(x,'front_disp.fnt')

 

and can be preceded by calls to screen formatting subroutines such as the cls, shadow or frame subroutines. An example of a program, demonstrating how the selection of the fill character can change the appearance of the font is listed below.

 

 

Listing 4. Cover Page Displays

------------------------------------------------

character x*1

x=char(219)

call cls

call frame('s',0,0,23,79)

call cover(x,'front_disp.fnt')

call tab

------------------------------------------------

 

 

PAGINATION OF SCREEN DISPLAYS

 

 

Subroutine TAB stops the display until a key is depressed. It also checks whether the key depressed generates an extended keyboard code, preceded by the ASCII null character. If detected, the leading null character is deleted. Thus, e.g., pressing the space bar or the down arrow results in the same behavior of the program. The tab routine can be called as

 

call tab

 

Functionally similar is the VTAB subroutine. However, the message "Press a key to continue," is displayed in the lower right corner of the screen when this subroutine is invoked. The vtab subroutine is called as

call vtab

Subroutine PAGES stops the display until a key is depressed. The right-adjusted message is displayed in the lower right corner of the screen. When any key is touched, the execution of the program continues. This routine can be called as

call pages('message$,iterm)

where the iterm parameter returns the termination code of the keyboard input. The termination code allows to determine whether, e.g., the input was terminated by the carriage return, or by the insert key, which may be of importance in some programming contexts. However, the most important use of the iterm parameter is to detect the use of the escape key. Illustration of the use of the subroutines for pagination of screen displays is presented below.

 

 

Listing 4. Pagination of Screen Displays

------------------------------------------------

1 call cls

write(*,*)'Hello'

call tab

write(*,*)'Hello world'

call vtab

call pages('Turn page$',iterm)

if(iterm.eq.1)stop

goto 1

end

------------------------------------------------

 

 

WINDOWS

 

The WINDOW subroutine can simultaneously open multiple overlapping windows on the screen surface. The window subroutine has five arguments. The first argument describes the surface of the window and the window borders. The possible values of this argument are 'q r s t u v'. If specified as 'q', the window is opened with the normal surface bordered by the double line frame. This is the default switch and entering any other character aside of the q r s t u v group triggers this switch. This permits renaming the q switch as n, a better mnemonics for 'normal'. If specified as 'r', the window surface is painted as the reverse video with double borders. The 's' switch defines the window as having the normal surface and single line borders. The 't' switch opens the window in reverse video, surrounded by a frame consisting of single lines. The 'u' switch opens a window with the normal surface and no borders and the 'v' switch, also deleting the borders, opens the window in reverse video. In most situations, the simplest and aesthetically pleasing displays are achieved by using the s or v switches.

The following arguments specify the coordinates of upper left and lower right corners of the window. The standard screen grid is used for the description of the window location. The grid has the origin 0,0 in the upper left screen corner. The screen has 24 lines and 80 columns, so the right lower corner of the screen has the 24,79 row, column coordinates. The window coordinates may be any within these limits. The Fortran call to the window subroutine is

 

call window('x',i,j,k,l)

 

To close the window, call the SHUT subroutine as

 

call shut

 

The SHUT subroutine has no arguments and should be called as many times as the window subroutine, to close the windows opened and to restore the screen to its original state. Both the window and the shut subroutines use the direct screen writes, bypassing both the DOS and the BIOS interrupts when saving and restoring the screen surface. They are fast and permit for about six full screens to overlap. An example of the Fortran implementation follows. It demonstrates opening of several stacked windows preserving the information previously stored on the screen, originally filled with dots. Answering in the affirmative to the query whether to close the window removes the previously opened windows in the reverse order, restoring their original surfaces, and, finally, uncovering the intact original screen surface.

 

 

Listing 4. The Window and Shut Subroutines

------------------------------------------------

character x*1

call cursor('i')

call cls

write(*,'(2000(1h.))')

n=0

1 n=n+1

write(*,*)

call b_pen(22,0,' $')

call b_pen(22,0,'Enter window attribute <q,r,s,t> and coordinates$')

read(*,*,err=9)x,i,j,k,l

call window(x,i,j,k,l)

call b_pen(i+1,j+1,'Hello$')

call b_pen(24,50,'Close window? <y,n>$')

call query(ians,'y,n')

if(ians.eq.1)goto 3

goto 1

3 n=n-1

do i=1,n

call shut

call tab

end do

9 call cls

call cursor('h')

end

------------------------------------------------

 

 

READ NUMBERS FROM SCREEN

 

The READN (READ Number) subroutine reads a number from a screen or a screen window and translates the number from a character representation into an internal computer representation of a number. The readn subroutine is called as

 

call readn('x',i,j,format,an,iterm,'0,1,82') !BREAK,ESCAPE,INSERT

 

where 'x' defines the text attributes of a number, as it is read from the screen. The attributes are coded as normal ('n'), reverse video ('r'), blinking ('b'), highlighted ('h'), attention getting, i.e. highlighted and blinking ('a'), underlined ('u') and invisible ('i').

The i and j are the offset coordinates of the screen location the number is going to be read from. The coordinates use the standard screen row, column grid with origin located at 0,0 and lower right corner located at 24,79.

The fourth parameter defines the format of the number. If set to 0.0, it will cause the number to be read in an inkey fashion, securing input of single digit numbers without having to depress the termination key. Formats where the period is followed by zero will read the integer numbers. However, the read number is always encoded as an floating point number. The valid format is any two number combination, separated by a period, within the 0.0 and 9.9 interval. However, only integer numbers smaller than 999,999 (formatted as 6.0) and floating point numbers smaller than 9999.999 (formatted as 4.3) are encoded reliably. Outside of these limits, the floating point numbers may be corrupted past the third decimal place and the integer numbers greater than one million will be unreliable. The encoded number is returned in the last but one argument, always as a floating point number.

The iterm parameter returns the scan code of the key the input was terminated with. If the iterm parameter is returned is equal to -1, a blank string was read. The blank input string typically indicates a missing value. The subroutine checks for the termination codes, listed following the iterm parameter. At least one termination code (e.g., '0' for the CTRL BREAK) must be listed. Up to 64 termination codes can be listed. The readn subroutine recognizes the backspace and delete keys. A program fragment, using the readn subroutine is listed below.

 

 

Listing 4. Reading Numbers from the Screen

------------------------------------------------

call cursor('i')

call cls

an=0.0

1 call writen('r',20,0,10.3,an)

call readn('r',10,15,5.3,an,iterm,'0,1,82') !Break,Escape,Insert

if(iterm.eq. 0)goto 9

if(iterm.eq. 1)goto 9

if(iterm.eq.82)goto 9

goto 1

9 call cursor('h')

end

------------------------------------------------

 

 

The source code listing for the readn subroutine is

 

 

Listing 4. Source Code for the Readn Subroutine

------------------------------------------------

subroutine readn(a,i,j,format,an,iterm,list)

integer*2 itoken(64)

character s*20,z*1,x*1,a*1,slip*3,list *(*)

logical*1 floating,integer,inkey

x=a

if(a.eq.'a')x='n'

if(a.eq.'b')x='b'

if(a.eq.'c')x='r'

if(a.eq.'d')x='h'

if(a.eq.'e')x='a'

if(a.eq.'f')x='u'

if(a.eq.'g')x='i'

2 inkey=.false.

max=format

maxx=anint((format-max)*10.0)

if(max+maxx.gt.20)then

pause 'Format error in CS subroutine readn'

return

endif

if(format.eq.0.0)then

inkey=.true.

max=1

maxx=0

end if

"===DECODE LIST

call blank(slip)

ix=0

ntokens=1

do is=1,len_trim(list)

if(list(is:is).eq.',')then

read(slip,'(i3)')itoken(ntokens)

ix=0

ntokens=ntokens+1

call blank(slip)

cycle

end if

ix=ix+1

slip(ix:ix)=list(is:is)

end do

read(slip,'(i3)')itoken(ntokens)

an=0

call blank(s)

index=1

iterm=0

1 call b_key(z,iterm,'*')

do is=1,ntokens

if(iterm.eq.itoken(is))return

end do

if(index.eq.1.and.iterm.eq.28)then !Missing value

iterm=-1

return

endif

if(iterm.eq.28)goto 5 !CR

if(iterm.eq.14)goto 4 !BS

if(z.eq.'-'.or.z.eq.'+')then

"max=max+1

goto 3

end if

if(z.eq.'.')then

max=max+maxx+1

goto 3

end if

if(a.ge.'a'.and.a.le.'g')goto 3 !Alphanumeric mode

if(z.lt.'0'.or.z.gt.'9')then

call tone 0

goto 1

endif

"_____Echo character

3 index=index+1

if(index.gt.max+1)then

call tone 0

index=index-1

goto 1

endif

call writes(x,i,j,'x',z)

j=j+1

s(index:index)=z

"_____Inkey type

if(inkey)then

iterm=28

goto 5

endif

4 if(iterm.eq.14)then !Backspace

if(index.lt.2)then

call tone 0

index=1

goto 1

endif

index=index-1

j=j-1

if(s(index+1:index+1).eq.'-')max=max-1

if(s(index+1:index+1).eq.'.')max=max-maxx-1

s(index+1:index+1)=1h

call pen(i,j,' $')

goto 1

endif

goto 1

"_____TRANSLATE STRING TO NUMBER

5 floating=.false.

integer=.true.

do ix=1,length(s)

if(s(ix:ix).eq.'.')then

floating=.true.

integer=.false.

end if

end do

if(integer)then

read(s,'(i10)',err=9)num

an=num

elseif(floating)then

read(s,'(f15.2)',err=9)an

endif

return

9 call tone 0 !Internal error read

pause 'Internal error read in CS subroutine readn'

end

 

------------------------------------------------

 

 

WRITE NUMBERS TO SCREEN

 

The WRITEN (WRITE Number) subroutine translates a number in an internal computer representation into a character string. The written subroutine is called as

 

call writen('x',i,j,format,an)

 

The first parameter defines the text attributes of a number, the next two parameters are the screen coordinates, the fourth parameter is the format of the number and the last parameter is the number to be converted into a string and written to any place on screen. An example of an call to the written subroutine is

 

 

Listing 4. Writing Numbers to Screen

-----------------------------------------------

------------------------------------------------

 

"an=99999.99 !Max number

call cls

an=12345.67

call writen('R',6,10,14.2,an)

call tab

end

 

The text attributes are [n]ormal, [r]everse video, [b]linking, [h]ighlighted, [a]ttention getting (highlighted and blinking), [u]nderlined and [i]nvisible. The attributes are case sensitive. If specified in capital letters, the comma, separating thousands, will be inserted if output number is 1,000 or greater. In this case, make sure that the format is wide enough to accomodate the expanded length of the number.

The screen coordinates may vary between 0 and 24 for rows and 0 and 79 for columns. The format follows the format conventions for a floating point number, however is not preceded by the letter f. Thus, e.g.,

 

call writen(i,j,6.3,an)

 

defines a number with five digits, containing a decimal point with three digits following. The format

 

call writen(i,j,5.0,an)

 

defines an integer up to five digits. Decimal point is not printed. The largest format permitted is 15.5, the smallest formats are 2.1 and 1.0. The format must be always a floating point number, for the above example, specifying the format as 5 instead of 5.0 would return an error message.

 

 

The source code for the writen subroutine is listed below.

 

 

Listing 4. Source Code for the Writen Subroutine

-----------------------------------------------

subroutine writen(x,i,j,f,an)

character string*20,out*20,x*1

logical*1 integ,comma

integ=.false.

comma=.false.

if(ichar(x).gt.64.and.ichar(x).lt.91)comma=.true . !Uppercase=insert commas

nw=0

nf=0

nw=f

nf=amod(f,1.0)*10.0+.5

if(nw.gt.15)goto 9

if(nf.gt. 5)goto 9

if(nf.le.0)integ=.true.

call blank(string)

if(integ)then

in=an

write(string,'(i15)',err=9)in

goto 1

endif

if(nf.eq.1)then

write(string,'(f15.1)',err=9)an

elseif(nf.eq.2)then

write(string,'(f15.2)',err=9)an

elseif(nf.eq.3)then

write(string,'(f15.3)',err=9)an

elseif(nf.eq.4)then

write(string,'(f15.4)',err=9)an

elseif(nf.eq.5)then

write(string,'(f15.5)',err=9)an

endif

1 call blank(out)

if(comma)call thousand(string)

if(nw.lt.1)goto 9

out(1:nw)=string(15-nw+1:15)

out(nw+1:nw+1)=1h$

"_____Write number out

call stylus(x,i,j,out)

return

9 write(*,*)'Error in CS FOR.LIB subroutine writen'

end

------------------------------------------------

 

 

READ TEXT FROM SCREEN

 

The READS (READ String) subroutine reads text from any place on screen and echoes the characters read in a display style defined by their corresponding attribute. The subroutine can be also invoked in an 'inkey' mode. The subroutine is called as

 

call reads('x',i,j,format,string,iterm,'0,1,82') !BREAK,ESCAPE,INSERT

 

where 'x' defines the text attribute, i,j, are screen coordinates followed by the format parameter, a variable dimensioned string, and the iterm parameter which upon return contains information how the string was terminated.

The text attributes can be defined as normal ('n'), reverse video ('r'), blinking ('b'), highlighted ('h'), attention getting, i.e. highlighted and blinking ('a'), underlined ('u') and invisible ('i') attributes.

The i,j parameters define the offset of the display on the standard screen grid with the 0,0 origin in the upper left corner, stretching to the 24,79 coordinate point in the lower right corner of the screen.

The format parameter has to be specified as a floating point number and specifies the maximum length of a string. If this maximum length is exceeded at input, cursor stops advancing and a soft murmur sound sounds. The number following the decimal point (1 to 9) can be used to define the width of the right margin of the string which can be optionally overriden by pressing the tab key on the keyboard. The margin can be up to 9 characters wide. If the format is specified as 0.0, the reads subroutine append the carriage return and functions in an 'inkey' mode.

The subroutine checks for termination codes, listed following the iterm parameter. At least one and up to 64 termination codes may be listed. The termination codes returned by the iterm parameter facilitate development of screen displays and parsing algorithms. If a blank string was entered, the iterm parameter is returned as equal to -1.

The prompt of the reads subroutine is an asterisks. Pressing the grey asterisk key on the keypad displays a chart of extended ASCII characters which may be used as input. A fragment of code, using the reads subroutine is listed below.

 

 

Listing 4. Reading Text from the Screen

------------------------------------------------

character string*50

call cursor('i')

call cls

1 call writes('r',20,0,'l',string)

call reads('r',10,15,5.9,string,iterm,'0,1,82') !Break,Escape,Insert

if(iterm.eq. 0)goto 9

if(iterm.eq. 1)goto 9

if(iterm.eq.82)goto 9

goto 1

9 call cursor('h')

end

------------------------------------------------

 

 

Source code of the reads subroutine is

 

 

Listing 4. Source Code of the Reads Subroutine

------------------------------------------------

subroutine reads(x,i,j,format,s,iterm,list)

integer*2 itoken(64)

character * (*) s

character * (*) list

character x*1,z*1,slip*3

logical*1 inkey

call writes(x,i,j,'x','*')

"===Format decoding

inkey=.false.

if(format.gt.0.0)then

max=format

maxx=anint((format-max)*10.0)

maxxx=max+maxx

if(maxxx.gt.len(s))then

write(*,*)'Format is greater than lenght of the string.'

pause 'Error in CS subroutine reads'

goto 9

endif

elseif(format.eq.0.0)then

inkey=.true.

max=1

elseif(format.lt.0.0)then

pause 'Format error in CS subroutine reads'

goto 9

end if

"===DECODE LIST

call blank(slip)

ix=0

ntokens=1

do is=1,len_trim(list)

if(list(is:is).eq.',')then

read(slip,'(i3)')itoken(ntokens)

ix=0

ntokens=ntokens+1

call blank(slip)

cycle

end if

ix=ix+1

slip(ix:ix)=list(is:is)

end do

read(slip,'(i3)')itoken(ntokens)

iterm=0

index=0

1 call key(z,iterm,'*',55) !HELP KEY IS GREY STAR

do is=1,ntokens

if(iterm.eq.itoken(is))goto 9

end do

if(index.eq.0.and.iterm.eq.28)then !Missing value

iterm=-1

goto 9

endif

if(iterm.eq.28)goto 9 !CR

if(iterm.eq.14)goto 4 !BS

if(iterm.eq.15)then

max=maxxx !TAB

goto 1

end if

"===Check if Characters are ASCII

do is=1,57 !Past space are control codes

if(iterm.eq.is)goto 3

end do

call tone 0

goto 1

"_____Echo character

3 index=index+1

if(index.gt.max)then

call tone 0

index=index-1

goto 1

endif

call writes(x,i,j,'x',z)

j=j+1

s(index:index)=z

"_____Inkey type

if(inkey)then

iterm=28

goto 9

endif

4 if(iterm.eq.14)then !Backspace

if(index.lt.1)then

call tone 0

index=0

goto 1

endif

index=index-1

j=j-1

s(index+1:index+1)=0

call writes('x',i,j,'x',' ')

goto 1

endif

goto 1

9 return

end

------------------------------------------------

 

 

WRITE TEXT TO SCREEN

 

The WRITES (WRITE String) subroutine positions string on any place on the screen. It provides for definition of text attributes and for string formatting. The subroutine is called from a Fortran program as

 

call writes('x',i,j,format,string)

 

where x contains information about text attributes, i,j, are the screen coordinates followed by the format parameter and a variable dimensioned string. The i parameter specifies the row of the screen where the text is to originate.

The text attributes can be defined as normal [n], reverse video [r], blinking [b], highlighted [h], attention getting (blinking and highlighted) [a], underlined [u], and invisible [i].

The format parameter specifies the formatting of the text within the displayed string and can be written as as 'l' for left justified, 'c' for centered, and 'r' for right justified. Any other character specified skips the string formatting routines.

The j parameter, if used together with the 'l' format defines the left margin of the text line. Used in conjunction with the 'c' or 'r' formats, the j parameter moves the origin of the text string toward the left by the specified numbers of columns. In the case of the 'r' format, the j parameter defines the right margin. Together with the 'c' format allows for optically correct centering of the string. A fragment of the code, using the writes subroutine is presented below.

 

 

Listing 4. Writing Text to the Screen

------------------------------------------------

call cursor('i')

j=0

1 call cls

call writes('r',10,j,'n','Hello')

call tab

call writes('r',11,j,'c','Hello')

call tab

call writes('r',12,j,'r','Hello')

call tab

call setcur(22,0)

write(*,*)'Read j Press E to Exit'

read(*,*,err=9)j

goto 1

9 call cursor('h')

end

------------------------------------------------

 

Source code for the writes subroutine is listed as

 

Listing 4. Source Code for the Writes Subroutine

------------------------------------------------

subroutine writes(x,i,jj,f,s)

character *(*)s,x*1,f*1

k=len(s)

j=jj

if(f.eq.'r')then

j=79-k-jj

elseif(f.eq.'c')then

j=40-k/2-jj

end if

call scribe(x,i,j,k,s)

end

;T H E S C R I B E S U B R O U T I N E

;call scribe(a,i,j,k,'Message$') ;a typical Fortran call

public scribe

stack segment stack 'stack'

db 64 dup (?)

stack ends

code segment

assume cs:code,ss:stack

scribe proc far

;Save base

push bp

mov bp,sp

;Save registers

push ax

push bx

push cx

push dx

push si

push di

;Get the arguments

mov si,[bp+6] ;message

push si ;save message address

mov di,[bp+14] ;column

mov bx,[bp+18] ;row

mov si,[bp+22] ;attribute

;Define cursor

mov dh,[bx] ;row

mov dl,[di] ;column

;Set cursor

mov ah,2

mov bh,0 ;page

int 10h

;Decode the attribute

mov cl,[si] ;get attribute

and cl,11011111b ;convert to uppercase

xor bx,bx ;zero bx register

cmp cl,'R'

je reverse

cmp cl,'H'

je intensity

cmp cl,'B'

je blink

cmp cl,'U'

je underline

cmp cl,'I'

je invisible

cmp cl,'A'

je attention

jmp normal

reverse label near

mov bl,01110000b

jmp go

intensity label near

mov bl,00001111b

jmp go

blink label near

mov bl,10000111b

jmp go

underline label near

mov bl,00000001b

jmp go

invisible label near

mov bl,00000000b

jmp go

attention label near

mov bl,10001111b

jmp go

normal label near

mov bl,00000111b

;Output the string

go label near

mov si,[bp+10] ;message length

mov cx,[si] ;length

pop si ;restore message address

write label near

lodsb

push cx

xor cx,cx

mov cx,1 ;write only one character

mov ah,9 ;BIOS 9/10h write

int 10h

inc dl ;increment cursor

mov ah,2 ;reset cursor

int 10h

pop cx

loop write

;Return

pop di

pop si

pop dx

pop cx

pop bx

pop ax

pop bp

ret 20

scribe endp

code ends

end

------------------------------------------------

 

 

FILL STRING WITH BLANK SPACES

 

The BLANK subroutine fills a string with blank spaces. It has a single parameter; i.e., the string to be filled with blanks. The string is variable dimensioned. An example of the subroutine call is

 

character string*30

call blank(string)

 

A variation of the blank subroutine is the subroutine PRIME. The prime subroutine fills a string with ASCII characters 255. This character does not echo and on the screen behaves as a blank. The subroutine has two parameters. The first parameter is the length of a string to be filled with ASCII 255; the second parameter is the string itself. The string is variable dimensioned. An example of the subroutine call is

 

character string*30

call prime(23,string)

 

The subroutine facilitates work in situations when it is helpful to differentiate between 'soft' and 'hard' blank space.

 

 

FORMAT STRINGS

 

The string formatting subroutines L_ADJUST, CENTER, and R_ADJUST left adjust text within a string, center text, and right adjust text, respectively. This group of subroutines is complemented by the L_PACK and R_PACK subroutines. While the l_adjust and r_adjust subroutines shift text toward their respective margins, the l_pack and r_pack subroutines shift text toward left or right by the indicated number of spaces. Also, the negative arguments are permitted for the l_pack and r_pack subroutines. In this case these subroutines function as shift right/left statements where the shifted characters overflowing the length of the string are discarded. These subroutines are called as

 

call l_adjust(margin,string)

call center(s)

call r_adjust(string,margin)

 

call l_pack(ishift,string)

call r_pack(string,ishift)

 

The strings in all above subroutines are variable dimensioned. A program fragments, illustrating the use of the string formatting subroutines follow.

 

 

Listing 4. Formatting the Text Strings

------------------------------------------------

character string*20

1 read(*,*)string

read(*,*)margin

call l_adjust(margin,string)

write(*,'(1x,a)')'----+----+----+----+'

write(*,'(1x,a)')string

write(*,*)length(string)

goto 1

end

 

-------------------------

character string*20

1 read(*,*)string

read(*,*)margin

call r_adjust(string,margin)

write(*,'(1x,a)')'----+-- --+----+----+'

write(*,'(1x,a)')string

write(*,*)length(string)

goto 1

end

 

------------------------------------------------

character a*10

a='eldorado'

write(*,*)a

call center(a)

write(*,*)a

write(*,*)'----------'

end

 

------------------------------------------------

character xdrive*80,p_drive*64

1 call cls

write(*,*)'Read string'

read(*,*)p_drive

write(*,*)'Read margin'

read(*,*)margin

xdrive=p_drive//'.NAM'

call l_pack(margin,xdrive)

write(*,'(1x,a)')'----+----+----+----+'

write(*,'(1x,a)')xdrive

write(*,*)length(xdrive)

call tab

goto 1

end

 

------------------------------------------------

character string*20

1 read(*,*)string

read(*,*)margin

call r_pack(string,margin)

write(*,'(1x,a)')'----+----+----+----+'

write(*,'(1x,a)')string

write(*,*)length(string)

goto 1

end

------------------------------------------------

 

 

MEASURE LENGTH OF TEXT WITHIN STRING

 

The LENGTH function is similar, but not equivalent to the Fortran intrinsic function len_trim. It returns the true length of the text within the string, even though the text might have been backspaced or written over. It also recognizes the hard spaces (ASCII 225). An example of its use follows.

 

 

Listing 4. Measuring Text Length

------------------------------------------------

character string*100

"_____Blanking over previously written spaces

string='123456789'

call setcur(3,0)

write(*,*)string

call prime(5,string)

call setcur(3,0)

write(*,*)string

string='123456789'

call writes('b',12,12,'x',string)

pause ' '

call prime(5,string)

call writes('n',12,12,'x',string)

pause ' '

write(*,*)'================================'

n1=len(string)

call blank(string)

string(10:14)='hello'

n=length(string)

nn=llen(string)

write(*,*)'Raw: n nn',n,nn

"_____Primed

call prime(nn,string)

n2=len(string)

string(10:14)='hello'

n=length(string)

nn=llen(string)

write(*,*)'Primed: n,nn',n,nn

"_____Blanked

call blank(string)

string(10:14)='hello'

n3=len(string)

n=length(string)

nn=llen(string)

write(*,*)'Blanked: n,nn',n,nn

"_____Len

write(*,*)'------------------------------------- '

write(*,*)'Len: Raw, Primed, Blanked: ',n1,n2,n3

end

------------------------------------------------

 

 

TEXT STRINGS IN UPPER AND LOWER CASE

 

To convert characters within a string to uppercase, the UCASE subroutine is called as

 

call ucase(s)

 

where s is a variable dimensioned string.

A complementary subroutine is the LCASE subroutine which turns the text within a string into lowercase. The lcase subroutine is called as

 

call lcase(s)

 

where, as in the case of the ucase subroutine, the s is a variable dimensioned string. A program fragment, illustrating the use of both subroutines follows.

 

 

Listing 4. Changing Characters to Uppercase or Lowercase

------------------------------------------------

character a*11

"Uppercase

call prime(a)

a='pearson'

call ucase(a)

write(*,*)a

"Lowercase

call prime(a)

a='FISHER'

call lcase(a)

write(*,*)a

end

CHAPTER

5

 

DISKS AND DISK FILES

 

Frequently, a program has to determine on which drive and in which subroutine its executable files are located. It also has to know how many physical and logical drives a particular machine it is running on has, change a disk drive location, create a new subdirectory or remove an old one, open or close a file, and safely return to its home drive and directory. A related tasks are to determine how much free space a disk drive has, display its directory, make a file invisible to a directory display, or make a file write protected. Subroutines helping a programmer to accomplish these tasks are discussed in the present chapter.

 

 

HOW MANY DRIVES ARE PRESENT?

 

To determine the valid drive designators for a particular computer configuration, you may choose from several viable alternatives. The frequently adopted approach is to use the DOS interrupt 19h/21h, returning the code of the currently selected drive. This method necessitates to check if the currently selected drive is valid, change the drive, check if the selected drive is valid, etc. This approach also reports as real drives declared in the config.sys file which may or may not really exist. The subroutine drives_a adapts this approach.

An alternative approach is to use the DOS interrupt 21h, service 29h. This service is used to parse a text string in the File Control Block to see if the file name, extension, and drive designator are valid. The control of the parsing process is via the lower part of the al register. The third bit controls the parsing of the file extension, the second bit controls the parsing of the file name, and the first bit, if set, instructs the 29h/21h interrupt to parse the file drive designator. On return, the lower part of the accumulator register indicates the parsing status. If al=0ffh, the drive specifier was invalid. This approach was adapted by the subroutine drives_b.

Another approach is to use the DOS interrupt 36h/21h to inquire about space on hard disk drives 3-26 (c: to z:). If the space is not zero, a disk is counted as existing on the system. This subroutine is the reccomended one. The Fortran call is

 

call drives_c(n)

 

where n returns the number of drives present in your system. A fragment of code, accomplishing this task, is presented below.

 

 

Listing 5. Inquiring How Many Drives are Present

------------------------------------------------

call cls

call drives_c(n)

write(*,*)n

end

------------------------------------------------

 

 

WHERE ARE WE?

 

Sometimes, it is necessary to make excursions from the program to some other subdirectory, located perhaps on a different drive. In order to return safely to the home destination, it is important to determine where the home directory is before we leave it. The WHERE_DR subroutine does just that. It can be called from a Fortran program as

 

call where_dr(idrive)

 

where idrive is the number of the drive from which the call was issued. The drive A: is associated with the idrive value of zero, drive B: is idrive 1, drive C: is idrive 2, etc. A program fragment, calling the subroutine, is listed below.

 

 

Listing 5. Location of the Home Drive

------------------------------------------------

call where_dr(idrive)

write(*,*)idrive

end

 

-------------------------------

 

 

WHERE TO GO?

 

The NEW_DR subroutine allows you to change a drive from your Fortran program. The subroutine is called as

 

call new_dr(idrive)

 

where idrive should be specified as 0 to change to drive A:, 1 to change to drive B:, 3 to change to drive C:, etc. A fragment of Fortran code, calling the subroutine, is presented below.

 

 

Listing 5. Change to a New Drive

------------------------------------------------

write(*,*)'Change to drive'

read(*,*)idrive

call new_dr(idrive)

end

 

-------------------------------

 

 

DRIVE DESCRIPTION

 

Once we have located a drive and moved there, the first questions asked are How big is the drive? How much space is used? How much space is left? The D_SELECT subroutine provides answers to these questions. The subroutine is called as

 

call d_select(x,locus,nd,nkeys,key_def,max,idr,ifree, iterm)

 

where the character*1 parameter x defines the border of the output information box as 's' the single or 'd' double line border. The locus parameter defines the line (row) location of the information frame on the screen. The nd id the dimension of the nkeys array, containing the number of keys defined, specified in the key_def parameter. The max is the number of drives on the system, idr parameter returns the selected drive. The A: drive is number 1, the B: drive is number 2, the C: drive is number 3, etc. The ifree parameter returns the amount of free space onb the selected drive. The exit code from the subroutine is given by the iterm parameter. An example of calling of this subroutine is given below.

 

 

Listing 5. Drive Selection Subroutine

------------------------------------------------

integer*2 key_def(7)

call cls

locus=10

nd=7

nkeys=3

call drives_c(max)

key_def(1)=28 !ENTER

key_def(2)=82 !INSERT

key_def(3)= 1 !ESCAPE

call d_select('s',locus,nd,nkeys,key_def,max,idr,ifre e,iterm)

call setcur(20,30)

write(*,*)'idr, ifree, iterm'

write(*,*)idr,ifree,iterm

end

------------------------------------------------

 

 

HOW TO GET THERE?

 

The DIR_PATH subroutine determines the path within the current directory. The subroutine is called as

 

call dir_path(idrive,string,iterm)

 

where idrive is the drive number designator; drive A: being number one, drive B: number two, drive C: number three, etc. The drive number zero is the default drive. The path is returned as an ASCIZ string, terminated by zero. The path names may be as 64 bytes long and the [c] string should be dimensioned accordingly. If the subroutine executed correctly, the iterm parameter is returned as zero.

 

 

Listing 5. Path within the Current Directory

------------------------------------------------

character string[c]*64

call count_dr(ndr)

do ix=3,ndr

idr=ix

call dir_path(idr,string,iterm)

write(*,*)string

write(*,*)idr

end do

end

------------------------------------------------

 

 

CHANGE DIRECTORY

 

The CHANGE_D functions as the DOS command CHDIR or CD. It can be called from a Fortran program as

 

call change_d(string,iterm)

 

where string is an ASCIZ (zero terminated) string, containing the name of an existing directory on the current drive. The termination parameter returns zero if the change of directory was successful. An example of the Fortran implementation of this subroutine is presented below.

 

 

Listing 5. Change the Default Directory

------------------------------------------------

character drive[c]*64,xdrive[c]*80

drive='d:\CSSP\'

lgth=length(drive)

xdrive(1:lgth-3)=drive(3:lgth-1)

call change_d(xdrive,iterm)

write(*,*)iterm

end

------------------------------------------------

 

 

REMOVE DIRECTORY

 

The REMOVE_D functions as the DOS command RMDIR or RD. It can be called from a Fortran program as

 

call remove_d(string,iterm)

 

where string is an ASCIZ (zero terminated) string, containing the name of an existing empty directory on the current drive. The termination parameter returns zero if the deletion of the directory was successful. An example of the Fortran implementation of this subroutine is presented below.

 

 

Listing 5. Remove Empty Directory on Default Drive

------------------------------------------------

character drive[c]*5

drive(1:4)='\TRY'

call remove_d(drive,iterm)

write(*,*)iterm

end

------------------------------------------------

 

 

CREATE A NEW DIRECTORY

 

The CREATE_D functions as the DOS command MKDIR or MD. It can be called from a Fortran program as

 

call create_d(string,iterm)

 

where string is an ASCIZ (zero terminated) string, containing the name of a directory to be created on the current drive. The termination parameter returns zero if the creation of the directory was successful. An example of the Fortran implementation of this subroutine is presented below.

 

 

Listing 5. Creation of a Directory on the Current Drive

------------------------------------------------

character drive[c]*64,xdrive[c]*80

drive='d:\TRY\'

lgth=length(drive)

xdrive(1:lgth-3)=drive(3:lgth-1)

call create_d(xdrive,iterm)

write(*,*)iterm

end

------------------------------------------------

 

 

VIEW DIRECTORY

 

The VIEW_DIR subroutine permits viewing directories from the Fortran programs. The subroutine reads either all files from a directory [if the file extension parameter is specified as '???'], or all files with the specified extension [if the file extension parameter is specified as 'EXT', giving the intended extension name. The subroutine is called from a Fortran program as

 

call view_dir(nfiles,'???',nd,store)

 

where the nfiles parameter returns the count of the files located in the directory. The file names are stored in store array which must be dimensioned by the Nd parameter and must be 13 characters wide. The file names are read into the store array without the period, separating the file extension from the file name and with the extension right adjusted within the store array. Before displaying the directory, the files may be optionally sorted, converted into lowercase, the file - extension separator may be added and the names of files may be reformatted. An example of the Fortran implementation of the view_dir subroutine follows.

 

 

Listing 5. Viewing Directories from Fortran Programs

------------------------------------------------

character store(500)*13

nd=500

call view_dir(nfiles,'???',nd,store)

do i=1,nfiles

write(*,*)store(i)

end do

end

------------------------------------------------

 

 

DELETE A FILE

 

And then there comes a time when the temporary files must be deleted, and everything has to be tidied so the user will never know that your program substituted dozens of scratch files for the lacking memory. A file may be deleted from a Fortran program by calling the DELETE_F subroutine as

 

call delete_f(x,'HELLO.DAT')

 

where x on return contains a plus sign if the file was indeed deleted, and the minus sign, if it was not. A fragment of the Fortran code, calling the delete_f subroutine, is presented below.

 

 

Listing 5. Delete a File

------------------------------------------------

character x*1

call delete_f(x,'HELLO.DAT')

write(*,'(1x,a)')x

end

------------------------------------------------

 

 

READ ONLY FILES

 

The SAFE subroutine protects the file from being overwritten. Its parameter field consists of two parameters. The first parameter is the +/- switch. To write-protect a file, enclose a plus sign in quotes. To unprotect a file, enclose a minus sign in quotes. The second parameter is the file name and its extension. The period, followed by three characters, serves as the string terminator. If a file does not have an extension, it is necessary to include a dollar sign as the string terminator. Thus, the subroutine may be called either as

call safe('+','file.ext') or call safe('+','file$')

An example of the use of the subroutine within a Fortran program is presented below.

 

 

Listing 5. Making the Read Only Files

------------------------------------------------

call safe('-','diary.txt')

stop 'Bye now'

end

------------------------------------------------

 

 

MAKE FILE INVISIBLE TO DIRECTORY SEARCH

 

The HIDE subroutine makes the associated file invisible to the directory search. Its parameter field consists of two parameters.. The first parameter is the hide/uncover switch. To hide a file, enclose a plus sign in quotes. To uncover a file, enclose a minus sign in quotes. The second parameter is the file name and its extension. The period, followed by three characters, serves as the string terminator. If a file does not have an extension, it is necessary to include the dollar sign as the string terminator. Thus, the subroutine may be called either as

call hide('+','file.ext') or call hide('+','file$')

An example of the use of the subroutine within a Fortran program is presented below.

 

 

Listing 5. Hiding Files

------------------------------------------------

call hide('-','diary.txt')

stop 'Bye now'

end

CHAPTER

6

 

PROGRAM OPERATION

AND COORDINATION

 

Programming within the computer environment crippled by the 640K memory barrier is a constant struggle with the lack of memory. The Fortran compiler offers an option to overlay segments of programs which do not execute at the same time, but this not solves the memory problems of most programming projects. Typically, one runs out of memory when the size of the .exe binary file starts to approximate 300,000 bytes. Thus, most serious programming projects consist of a series of programs, usually between 150,000 to 270,000 bytes large, passing parameters and calling each other in a variety of ways. Present chapter discusses several subroutines which make programs more aware of their environment and which facilitate some of the tasks necessary to perform when integrating a group of programs to function in concert.

 

 

COMMAND LINE ARGUMENTS

 

The SELECT logical*1 function is used to extract arguments defined at the time of the program execution at the program invoking line. It partialy duplicates the existing function of the Microsoft Fortran compiler, however, the select function is more compact and easier to use. The function is called as

if(select('token'))then

The function is true if the token matches an argument specified anywhere after the command invoking the program. Consider a program stat invoked as

 

stat c

 

The fragment of the stat program may include code as presented below.

 

 

Listing 6. Retrieving the Command Line Arguments

------------------------------------------------

logical select*1

if(select('a'))write(*,*)'Message 1'

if(select('b'))write(*,*)'Message 2'

if(select('c'))write(*,*)'Message 3'

------------------------------------------------

 

For the above example, the third message should be displayed.

 

 

EXTRACT PARAMETERS FROM

THE ENVIRONMENT

 

The ENVIRON subroutine is used to extract information about configuration or modes of execution of the program, defined by the DOS SET command. The subroutine is called as

 

call environ(x,'TOKEN=switch')

The token parameter MUST be capitalized. It is set by the DOS SET command as, e.g.,

 

SET TOKEN = switch

 

The first parameter returns '+' if match was found. Otherwise, '-' is returned. An example of the call of this subroutine follows.

 

 

Listing 6. Retrieving Tokens from the Environment

------------------------------------------------

character*1 x

call environ(x,'CSSP=1')

write(*,*)x

end

------------------------------------------------

 

If, e.g., the token was set as SET CSSP = 1, the subroutine would return the plus sign. The environ subroutine checks the environment up to 1024 bytes long.

 

 

INVOKE OPERATING SYSTEM COMMANDS

 

The INVOKE subroutine invokes the command.com processor from within a Fortran program. Using the invoke subroutine you may display a directory, rename a file, delete a file or a directory, copy files and perform other functions directly from your program. The subroutine has a single argument, a variable dimensioned string which has not to be explicitly declared; it is called as

 

call invoke(string)

 

Program fragment, illustrating the use if the invoke subroutine is listed below.

 

 

Listing 6. Invoking Operating System Commands

------------------------------------------------

call invoke('dir/w')

call invoke('ren a b.dat')

call invoke('del z.fnt')

call invoke('cd new')

------------------------------------------------

 

The invoke subroutine can be also used to execute batch files, as, e.g., call invoke('chain.bat').

 

 

CATENATE PROGRAMS

 

The CATENA subroutine executes other program from within the calling program, allowing for program chaining. The *.exe, and *.com files may be executed by specifying the name of the calling program and the name of the program to be executed. To execute the batch files, use the invoke subroutine. The catena subroutine has two arguments. The first argument is the name of the calling program, the second argument is the program to be executed:

 

call catena('from.exe','to.exe')

 

The program fragment using the catena subroutine is listed below. The calling program is try.exe, the program to be executed is hello.exe.

 

 

Listing 6. Program Catenation

------------------------------------------------

call catena('try.exe','hello.exe')

end

------------------------------------------------

 

 

PROGRAM TERMINATION

 

The EXIT subroutine allows a user to set the error level at the time of program termination. The subroutine is called from the Fortran program as

 

call exit(level)

where the integer argument is the exit level. An example of a Fortran program using this subroutine is presented below.

 

 

Listing 6. Setting the Error Level Upon Exit from the Program

------------------------------------------------

if(iagain.eq.0)call exit(0)

if(iagain.eq.1)call exit(1)

end

------------------------------------------------

 

If the program called analysis is run from a batch file such as listed below, and terminates with error level 1, it will be executed again.

 

 

Listing 6. Batch File Containing a Program Setting the Error Level

------------------------------------------------

:restart

analysis

if errorlevel 1 goto end

if errorlevel 0 goto restart

:end

------------------------------------------------

 

When using this subroutine, it is important to arrange the errorlevel checking in the batch file in descending order, as, e.g.,

 

if errorlevel 3 ...

if errorlevel 2 ...

if errorlevel 1 ...

if errorlevel 0 ...

 

The checking of the errorlevels in any other progression will not work correctly.

 

 

CHAPTER

7

 

THE SOUND

 

Simple calls of the DOS interrupts may produce plain beeps via the speaker, attached to the computer. By directly controlling the hardware ports, the speaker can be programmed to emit tones, cascades of tones, sounds, even simple speech. The subroutines described in this chapter describe programming of several sound effects, from simple beeps, through generation of pure tones, cascades of tones, to combination of tone primitives, generating elaborate sound effects.

 

 

SOUND ALERT

 

The BEEP subroutine can be used to call the operator's attention to necessary tasks in many real time operations. The calling syntax for this subroutine is

call beep

The subroutine has no parameters and will make the speaker to emit a single beep.

 

 

TONES

 

The TONE subroutine generates a pure tone. To vary the tone, define the subroutine's parameter by a letter. All the characters from A to Z may be used. The calling syntax of this subroutine is

 

call tone(x)

 

where the x may be a letter a, b, ..., z.

 

 

TUNES

 

Simple tunes may be played by evoking a row of tone subroutines, interspersed with the delay statements. Try, e.g.,

 

 

Listing 7. Tone Generating Subroutines

------------------------------------------------

call tone('c')

call tone('e')

call tone('g')

call delay(20)

call tone('g')

call tone('g')

etc.

------------------------------------------------

 

 

PHASERS

 

An elaboration of the tone subroutine is a collection of sound effect subroutines tone 0, tone 1, ..., tone 9. They are called as, e.g.,

 

call tone 7

 

The tone 0 subroutine emits soft murmur, the tone 1 to tone 9 subroutines contain various auditory effects.

 

 

SOUND EFFECTS

 

Sound effects can be created by combinations of the phaser subroutines. Two or more subroutines may be called in tandem, as, e.g.,

 

 

Listing 7. Generation of Sound Effects

------------------------------------------------

call tone 8

call tone 9

call tone 5

------------------------------------------------

 

To select an appropriate sound effect for a particular application, you may like to try several combinations of the tone subroutine.

 

 

CHAPTER

8

 

 

ASYNCHRONOUS

COMMUNICATIONS

 

By programming the serial ports, it is possible to communicate with various peripheral devices, often situated in remote locations. In the present chapter, simple initialization of a serial port is described, followed by description of subroutines sending and receiving information via the com1 port using the RS232C communication protocol. Even though the BIOS and DOS interrupts were implemented into the DOS operating system by several independent vendors, the IBM and Microsoft versions of DOS do not have these interrupts. Thus, one has to resort to the direct programming of the pins of the Motorola 8250 microprocessor, controlling the serial communications within the Standard Industry Architecture design of computers, build around the Intel iAPX 88-486 chips.

 

 

INITIALIZE A SERIAL PORT

 

The PORT subroutine initializes the communications via the serial port. The parameters of the Port subroutine define the operating characteristics of the serial transmission. The first parameters id the port number. This number depends on how many ports you have and which port you want to use. If you have only a single communication port, specify the port number as zero. Other ports are not currently supported. The next parameter is the baud rate. The supported baud rates are 300/ 600/ 1200/ 1800/ 2000/ 2400/ 3600/ 4800/ 7200/ 9600 bauds. Parity has to be specified in the following parameter. Select [o]dd, [e]ven, or [n]one. The number of stop bits can be selected as either 1 stop bit or 2 stop bits. The word length can be selected as either 7 bits or 8 bits. The subroutine is called as

call port(port#,baud rate,parity,stop bits,word length)

A program fragment, utilizing the port subroutine is presented below.

 

 

Listing 8. Initialization of a Serial Port

------------------------------------------------

call port(0,9600,'n',1,8)

call lift

write(*,*)'Solenoid lifted'

------------------------------------------------

 

The above program fragment specifies the opening of the asynchronous communication channel number one at the 9600 baud rate with no parity, one stop bit, and an 8-bit word length.

 

 

TRANSMIT VIA A SERIAL PORT

 

The TRANS subroutine transmits a character into the RS232C port. This parameter must be declared literal. The call is via the UART processor. The Fortran call is

character*1 a

call trans(a)

An example given below illustrates the use of the subroutine to unlock the reader of a peripheral device by sending a direct control one (dc1) character (ASCII 17 decimal).

 

 

Listing 8. Transmission of Characters Using a Serial Port

------------------------------------------------

character*1 dc1

call port(1,9600,'e',1,7)

dc1=char(17)

call trans(dc1)

------------------------------------------------

 

 

RECEIVE VIA A SERIAL PORT

 

The RECEIV subroutine reads a buffer from the serial port. The size of the buffer is 2000 characters. The call is via the UART processor. The Fortran call is

character*1 buffer(2000)

call receiv(buffer)

An example of the use of the subroutine is given below.

 

 

Listing 8. Reception of Characters Sent Via Serial Port

------------------------------------------------

character*1 a(320)

dc1=char(17)

write(*,*)'Activate ScanTron'

call tab

call trans(dc1)

call receiv(a)

write(*,'(a/10(1x,70a1/)')' Received data:',a

end

CHAPTER

9

SELECTORS, MENUS AND

ELECTRONIC BLACKBOARDS

 

The most program designs are menu driven. Typically, the program is structured around a central menu, complemented by dedicated menu system offering selections between the main features offered by the program. A selection from the central menu typically opens a secondary menu, offering more specific options.

The central menu is usually displayed along one of the sides of the monitor. This leads to classification of menus into upper or lower horizontal menus and into left or right vertical menus. Some designs also employ the concept of the free floating menu which is initially displayed in a corner of a screen and user can float it into a convenient location which depends on a particular screen display at the time the menu appears.

Another category of displays with designs similar to designs of menus are selectors, employing the concept of the conveyor belt to tag selections not of the program features, as menus do, but of components the program is operating upon. Subsequently, the tagged items are processed together as a group.

In this chapter we are going to discuss a program design a system of floating menus. Superimposed upon the menu bar are movable tokens, rotated by the arrow keys. The selections from the menu are by pressing the enter key at the highlighted alternative, or by pressing the key corresponding to the capitalized initial of the token. Menu are initially displayed at any screen location, selected by the programmer. The user than can reposition the menu to any corner of the screen by pressing Control Arrows Keys, or move it to any screen location by Alternate Arrows Keys. Pressing the delete key makes temporarily menu to disappear; the menu reappears by pressing any key on the keyboard. This feature is convenient when selection from the menu depends on valued, displayed somewhere on the screen at the moment the menu is called.

To preserve integrity of the program, all possible keyboard strokes must be accounted for. Pressing a key which does not apply elicits a soft murmur, to give user an auditory feedback that the input is in error. Typically, the Escape and Ctrl Break keys are the way out of the menu, restoring the previous state of the screen.

Following discussion centers about the design concepts of item selectors and electronic blackboards. The item selectors are a conveyor-belt type of movable tokens for tagging selected items. The concept of the electronic blackboard is one of the most exciting modern screen designs. It utilizes the series of tiled windows which can be turned in either direction at will, permitting the comprehensive displays of well structured information panels.

 

 

VERTICAL FREE FLOATING MENUS

 

The VERT_M subroutine displays a vertical menu at any screen location. The subroutine is called as

 

call vert_m(x,i,j,nd,L,iselect)

 

The first parameter defines the appearance of the display. The first argument specifies the attributes of the text to be displayed and the surface of the window. The 'q' defines appearance of the menu as a rectangle surrounded by double borders; the menu tokens are in reverse video. The 'r' changes the surface of the menu into a reverse video, surrounded by double borders. The movable tokens are in obverse video. The 's' defines the movable tokens in reverse video, the surface of the menu in obverse video, and menu borders as single lines. The 't' value exchanges the video modes of the tokens and the surface of the menu; thus the tokens are in obverse video, the surface in revers video, and the borders remain a single line. Finally, the 'u' and 'v' values chage the design of the menu by deleting the borders. The 'u' menu displays only the tokens on the normal surface. The 'v' menu displays tokens on obverse video on the reverse video menu surface. The following two parameters, i and j, define the screen coordinates of the upper left corner of the menu; i.e., the location on the screen the menu will initially appear. The permissible ranges of these coordinates are the 0-24 range for rows and the 0-79 range for columns.

The menu floats on the screen surface and can be moved by the Control or Alternate Arrow Keys. Selection of menu options is according to capitalized letters of the menu options or by the up and down keyboard arrows. The selected menu item is indicated by the its ordinal position, returned by the iselect argument. Pressing HOME or END Keys moves the selector bar to the top or to the bottom of the menu. The DELETE Key is a toggle key, making menu temporarily to appear, and to disappear.

The maximum length of any menu item is 78 characters. Up to 22 menu items can be used on a single screen display. The menu items are variable dimensioned and their correct length must be declared in the calling program. All menu items must be dimensioned and the number of dimensions (menu items) must be specified in the fourth argument nd. Code fragment, using the subroutine is listed below. Optionally, menu can contain titles and subtitles, identified by the hard blank character at the beginning of the line, as, eg.,

 

L(1)='x T I T L E'

 

where the invisible hard blank character (ASCII 255) is symbolized by the letter x. Titles should not stretch over two adjacent lines. Also, title should not be the last line on the menu.

 

Listing 9. Displaying Vertical Menu

------------------------------------------------

character L(3)*43,x*1

call cursor('i')

1 call cls

write(*,*)'Select menu type q r s t u v'

read(*,*,err=1)x

L(1)=' T I T L E'

L(2)=' A] Text'

L(3)=' B] Relation'

L(4)=' Text'

call vert_m(x,14,20,4,L,iselect)

write(*,*)iselect

call tab

call shut

goto 1

end

 

SELECTORS

 

The SELECTOR subroutine overlays a window on a screen displays. On the window surface appears a series of up to twelve boxes, movable by the keyboard left and right arrows. Inside of the boxes appears the description of items to be selected. The tagging of selected items is by the Space Bar. Pressing the Insert key accepts the tagged selections and exits the subroutine. The Escape key allows to escape from the subroutine. The subroutine is called as

 

call selector(nbox,kd,kmax,clab,itag,mark,'TITLE',iba ck)

 

The nbox parameter defines the number of selector boxes to display. The possible values of this parameter are from 1 to 12. The kd parameter is the dimension of the clab and mark arrays. This dimension defines the number of items which can be tagged and is limited only by memory considerations. The clab array describes the items. The itag parameter returns the numerical value associated with the selected mark array. The zero represents blank, 1 stands for the first selected group, 2 for the second selected group, etc. If an item is tagged, the truth value of its corresponding logical array mark is changed from false to true. The title parameter is a variably dimensioned array labelling the selector display and the iback parameter allows to escape from the subroutine. Pressing the Escape key sets the iback argument to 1, otherwise, this argoment returns zero. An example of the subroutine call is presented below.

 

 

Listing 9. Displaying Selectors

------------------------------------------------

character clab(25)*5

integer*2 mark(25) !RETURNS SELECTED ITEMS

kd=25

call cursor('i')

do i=1,kd

write(clab(i),'(3hVAR,1x,a)')char(i+64)

end do

1 call cls

nbox=9

itag=1

kmax=20

call selector(nbox,kd,kmax,clab,itag,mark,'ITEMS',iba ck)

write(*,*)

write(*,'(25i2)')mark

write(*,*)'1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2'

write(*,*)' 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5'

if(iback.eq.1)stop

call tab

goto 1

end

------------------------------------------------

ELECTRONIC BLACKBOARDS

 

The BLACK_B subroutine defines an electronic blackboard display. The subrutine is called as

 

call black_b('*',leaves,nd,LINE,sound)

 

where the first parameter is a character*1 constant, defining the background of the electronic keyboard. The leaves parameter defines the number of panels to be displayed. The possible range of this parameter is from 1 to 5. The next parameter is the dimension of the line array, specifying the number of lines of text to be displayed. The last argument allows, if true, to turn on the sound, accompanying rotation of the display panels. A fragment of the Fortran code, calling the black_b subroutine is presented below.

 

 

Listing 9. Displaying Electronic Blackboards

------------------------------------------------

character LINE(8)*60

logical*1 sound

sound=.true.

leaves=2

nd=8

LINE( 1)='B-1 Main Title of Display B'

LINE( 2)='B-2 Subtitle'

LINE( 3)='B 1 Line 1 of Screen B'

LINE( 4)='B 2 Line 2 of Screen B'

LINE( 5)='A-1 Main Title of Display A'

LINE( 6)='A-2 Subtitle'

LINE( 7)='A 1 Line 1 of Screen A'

LINE( 8)='A 2 Line 2 of Screen A'

call black_b('*',leaves,nd,LINE,sound)

end

------------------------------------------------

CHAPTER

10

 

CONTROL OF

LASER PRINTERS

 

The subroutines discussed in this chapter help to write well formatted output on LaserJet printers. The majority of subroutines described in this and subsequent chapters on printing from Fortran programs communicate with the printers by using the group of DOS interrupts 3D01h/21h, 40h/21h, and 3Eh/21h. These interrupts support the foreground printing and error handling which can be redirected and also used on local area networks. No data interpretation or translation is done by DOS or BIOS, so this interface can be also used to print graphical data. The communication with printers is via the device drivers. The device drivers, including the standard printer drivers LPT1:, LPT2:, and LPT3 can be used in either FCB or handle function calls to open, write to, and close the communication channels. Thus, the Fortran program can interact with up to three different printers and a variety of other output devices, including the screen.

The primary communication routines are the brush, text and quill subroutines. The quill subroutine allows for direct writing to the printed page in a manner similar to the nonsequential writing to the monitor's display screen. It should be used whenever more complicated output formatting is to be done. The quill subroutine uses the printed page's row and column grid as a reference for placement of text or character graphics. The brush subroutine is especially useful when using proportionally spaced fonts. You may also use regular Fortran write statements for standard output formats.

 

 

OPENING AND CLOSING

COMMUNICATION CHANNELS

 

The LJ_OPEN subroutine opens the communication channel to an output device. It is called from the Fortran program as

 

call lj_open('*')

 

where the value of the arguments defines the handle to be used in the course of the DOS foreground printing. The standard printer ports lpt1:, lpt2:, and lpt3: are specified as logical units 1, 2, and 3. Thus, e.g., to open the communication with the lpt2:, call the lj_open subroutine as call lj_open('2'). The default printer port prn, identical with the lpt1 port can be assigned by either specifying the logical unit 1 or by an asterisk. The plus sign in the argument, used as call lj_open('+'), will redirect the output to the computer screen. This option is especially useful in the course of program development.

To close or reassign the communication channel, the previously opened channel must be closed by calling the subroutine LJ_CLOSE. This subroutine is called form the Fortran program as

 

call lj_close

 

and has no arguments.

 

 

ESCAPE SEQUENCES

 

The ESCAPE subroutine allows you to send any escape sequence to the LaserJet. The call of the escape subroutine from a Fortran program is

call escape('escape sequence')

The escape subroutine inserts the escape character and sends the escape sequence to the printer. An example calling this subroutine from the Fortran program is listed below.

 

 

Listing 10. Sending Escape Sequences to Laser Printers

------------------------------------------------

call lj_open('*')

call escape('&10O^[(0U^[(s1p10v0s0b5T$')

call text('Hello$')

call lj_close

call eject

end

------------------------------------------------

 

The above example, sending the escape sequences Esc&10O, Esc(0U, and Esc(s1p10v0s0b5T to the printer selects the Times Roman font 10 point Medium from the HP 92286K Math TMS Font Cartridge or from the HP 92286B TMS Font Cartridge. The Esc stands for actually depressing the escape key when writing the Fortran source code by using a text editor permitting insertion of escape characters. If your text editor does not provide for the direct insertion of the escape character, issue three calls to the escape subroutine, as, e.g.,

 

call escape('&l0O')

call escape('(0U')

call escape('(s1p10v0s0b5T')

 

The escape subroutine is the most general subroutine of the LaserJet Library permitting to send any command to a printer using the HP PCL protocol.

 

 

TRANSMISSION OF CHARACTERS

 

The BRUSH subroutine transmits a character or a string of characters into the parallel port. The Fortran call is listed below.

character*1 a

call brush(a)

An example of its use is presented below.

 

 

Listing 10. Transmitting Characters

------------------------------------------------

character mask*80,line(80)*1

equivalence(mask,line)

mask='Hello'

do i=1,5

call brush(line(i))

end do

call eject

end

------------------------------------------------

 

 

TEXT TRANSMISSION

 

The TEXT subroutine transmits a string of characters into the parallel port. The Fortran call is listed below.

call text('message$')

An example of its use is presented below.

 

 

Listing 10. Transmitting Text

------------------------------------------------

call lj_open('+')

call text('Hello')

end

------------------------------------------------

 

The subroutine checks for both the null and $ string termination characters, i.e., the subroutine can be called both as call text('string') and call text(string$'). The use of the $ termination character, due to the constraints imposed by the Fortran calling conventions, is the safer choice.

 

 

PRINTING USING THE ROW COLUMN GRID

 

The QUILL subroutine allows for positioning of cursor to any point of intersecting row column page coordinates and transmission of up to 2000 characters originating from that point. The Fortran call is

 

call quill(i,j,'Message$')

 

where the i stands for the row coordinate and the j for the column coordinate. The third argument must be enclosed in single quotes and terminated by the $ sign. An example of its use is presented below.

 

 

Listing 10. Setting Writting Offset and Transmitting Text

------------------------------------------------

write(*,*)'Set cursor: row,column'

read(*,*)i,j

call quill(i,j,'Hello$')

call eject

end

------------------------------------------------

 

 

THE TOP MARGIN

 

The TOP subroutine specifies the number of lines to skip at the top of the page. The top margin may be set at any value ranging from two to the length of the page. If the top margin rightmost argument is larger than the page length, the top margin setting call will be ignored. The line count uses the current vertical line spacing. Once the top margin is set, subsequent redefinition of the vertical line spacing will not affect the top margin. The Fortran call is

call top(i)

where the argument defines the number of lines to skip. The count starts with line zero. Lines zero and one lie in the unprintable region. The default value for the top margin is one-half inch from the top of the page. An example of a call from within a Fortran program is listed below.

 

 

Listing 10. Setting Top Margin

------------------------------------------------

character line(120)*1

maxl=120

open(1,file='lpt1')

write(*,*)'Set top margin'

read(*,*)itop

call top(itop)

write(*,*)'Input a message'

read(*,'(120a1)')line

write(1,'(120a1)')line

call eject

end

------------------------------------------------

 

 

NUMBER OF LINES PER PAGE

 

The LTEXT subroutine specifies the number of lines to define a page. If it is set to zero, the text length will be defaulted to the physical page length minus the top margin and minus one-half inch. If the text length is greater then the physical page length minus the top margin, the command will be ignored. The line count uses the current vertical line spacing. The Fortran call is

call ltext(i)

where the argument defines the number of lines to print on a page. An example of a Fortran implementation follows.

 

 

Listing 10. Setting Number of Lines per Page

------------------------------------------------

write(*,*)'Set text length'

read(*,*)ix

call ltext(ix)

do i=1,ix

call brush('x')

call crlf

end do

call eject

end

------------------------------------------------

 

 

RESET MARGIN SETTINGS

 

The CLEARM subroutine will set the margins into their default values and return the cursor to column zero. To call the clearm subroutine, write:

call clearm

An example of the use of this subroutine is listed below.

 

 

Listing 10. Clearing Margin Settings

------------------------------------------------

open(1,file='lpt1')

call clearm

write(*,*)'Set left and right margins:'

read(*,*)n,k

call leftm(n)

call rightm(k)

write(1,*)-

'00000000001111111111222222222233333333334444444 444-

555555555566666666667777777777888888888899999999 99'

end

------------------------------------------------

 

 

LEFT AND RIGHT MARGINS

 

The LEFTM subroutine will reset the left margin to the column specified. To call the margin subroutine, write:

call leftm(i)

where i is the column to which the margin should be set. For example, statement call leftm(8) will set the left margin to column eight. An example of the use of this subroutine is listed below.

 

 

Listing 10. Setting Left Margin

------------------------------------------------

open(1,file='lpt1')

write(*,'(a)')' Set left margin to col:'

read(*,*)n

call leftm(n)

write(1,*)'Hello'

end

------------------------------------------------

 

The RIGHTM subroutine will reset the right margin to the column specified in its parameter. To call the margin subroutine, write:

call rightm(i)

where i is the column to which the right margin should be set. For example, the statement call rightm(72) will set the right margin to the 72nd column. An example of the use of this subroutine is listed below.

 

 

Listing 10. Setting Right Margin

------------------------------------------------

open(1,file='lpt1')

call clearm

write(*,*)'Set left and right margins:'

read(*,*)n,k

call leftm(n)

call rightm(k)

write(1,*)-

'00000000001111111111222222222233333333334444444 444-

555555555566666666667777777777888888888899999999 99'

end

------------------------------------------------

 

 

WRAP-AROUND ENABLE AND DISABLE

 

The WRAP subroutine enables the printing of text longer than the defined line width. Normally, the wrap-around mode is disabled and character strings longer than the right margin boundary are truncated. With the wrap-around mode activated, characters which would ordinarily be lost will be printed on the next line. To enable the wrap around, call the wrap-around subroutine as

call wrap('+')

To disable the wrap-around mode, replace the plus sign in the argument with the minus sign. An example of the use of this subroutine is suggested below.

 

 

Listing 10. Setting the Wrap-Around Mode

------------------------------------------------

call wrap('+')

do i=1,120

call brush('x')

end do

call crlf

do i=1,120

call wrap('-')

call brush('y')

end do

call eject

end

------------------------------------------------

 

 

PERFORATION SKIP

 

The PERF subroutine disables the perforation skip mode. Normally, the perforation skip mode is on. Text longer than the defined text length will be printed on the next page. Turning the perforation skip mode off allows you to print below the lower text margin, but not in the unprintable region. To disable the perforation skip mode, call the subroutine as:

call perf('-')

To return to the default state, call the subroutine with the plus sigh in its argument as call perf('+'). An example of the use of this subroutine is listed below.

 

 

Listing 10. Controlling the Perforation Skip Mode

------------------------------------------------

character a*1

open(1,file='lpt1')

write(1,*)'Perforation skip mode on'

call perf('+')

a='x'

do i=1,70

call brush(a)

call crlf

end do

call eject

write(1,*)'Perforation skip mode off'

call perf('-')

a='y'

do i=1,70

call brush(a)

call crlf

end do

call eject

end

------------------------------------------------

 

 

BACKSPACE

 

The BS subroutine will backspace the cursor one column toward the left. This feature allows character overprinting, as illustrated in the example below. To call the bs subroutine, write the statement

call bs

An example of the use of this subroutine is listed below.

 

 

Listing 10. Backspacing to Overprint a Character

------------------------------------------------

character mask*78,line(78)*1

equivalence(mask,line)

mask='The matrix differencing operant is frequently -

symbolized by the O<- sign.'

do i=1,78

if(line(i).eq.'<')then

call bs

cycle

endif

call brush(line(i))

end do

call eject

end

------------------------------------------------

 

 

CURSOR MOVEMENT ACROSS

ROWS AND COLUMNS

 

The ROWCUR subroutine positions the cursor vertically by moving the cursor across printing paper rows whose width is determined by the current vertical line spacing. The first argument is the directional parameter. It has three possible values. The minus sign sets the direction toward bottom of the page, the plus sign reverses the direction toward the top of the page and the zero character indicates the absolute positioning. The second argument is an integer, specifying the number of rows the cursor should be moved. An example of the Fortran call is

 

call rowcur('+',i)

 

An example illustrating writing on a page in a random (nonsequential) order is listed below.

 

 

Listing 10. Controlling Cursor Movement Accross Rows

------------------------------------------------

character line(120)*1

maxl=120

write(*,*)'Set cursor: row,column

read(*,*)i,j

call rowcur('0',i)

call colcur('0',j)

write(*,*)'Input a message'

read(*,'(200a1)',end=9)line

do i=1,maxl

call brush(line(i))

end do

call eject

end

------------------------------------------------

 

The COLCUR subroutine positions the cursor horizontally by moving the cursor across printing paper columns whose width is determined by the active print pitch (nonproportional characters) or by the space character width (proportional fonts). The first argument is the directional parameter. It has three possible values:

-direction toward right '+'

-direction toward left '-'

-absolute positioning '0'

The second argument is an integer number, specifying the number of columns the cursor should be moved. The Fortran call is:

call colcur('+',i)

An example of the use of this subroutine is listed below.

 

 

Listing 10. Controlling Cursor Movement Accross Columns

------------------------------------------------

integer*2 itab(15)

character line(120)*1

data itab /8,16,24,32,40,48,56,64,72,80,88,96,104,112,120/

maxl=120

maxtab=15

open(1,file='try.txt')

read(1,'(200a1)',end=9)line

n=0

do i=1,max

n=n+1

if(ichar(line(i)).eq.9)then

do j=1,maxtab

if(itab(j).gt.n)then

n=itab(j)-1

exit

endif

end do

call colcur('0',n)

cycle

endif

call brush(line(i))

end do

call crlf

9 call eject

end

------------------------------------------------

 

 

CURSOR POSITIONING

 

The CUR subroutine positions the cursor with respect of row column grid. The cur subroutine is the combination of rowcur and colcur subroutines in the absolute positioning mode. The Fortran call of the cur subroutine is

 

call cur(i,j)

 

where the first argument is the ordinal position of the page row and j the ordinal position of the page column. An example of its use is presented below.

 

 

Listing 10. Setting the Cursor

------------------------------------------------

character line(120)*1

maxl=120

write(*,*)'Set cursor: row,column'

read(*,*)i,j

call cur(i,j)

write(*,*)'Input a message'

read(*,'(200a1)',end=9)line

do i=1,maxl

call brush(line(i))

end do

9 call eject

end

------------------------------------------------

 

 

HORIZONTAL AND VERTICAL

CURSOR MOVEMENTS

 

The HCUR (horizontal cursor positioning) subroutine moves the cursor horizontally in 1/720 inch increments, called decipoints. The first argument is the directional parameter. It has three possible values. The plus sign specifies the left to right direction, the minus sign the right to left direction and the zero value indicates the absolute positioning of the cursor. The second argument is an integer, specifying the number of decipoints the cursor should be moved. An example of the Fortran call is

call hcur('+',i)

 

An example of the use of this subroutine is listed below.

 

 

Listing 10. Moving Cursor in the Horizontal Direction

------------------------------------------------

character mask*78,line(78)*1

equivalence(mask,line)

write(*,'(a)')' Move cursor by how many decipoints?'

read(*,*)n

call hcur('+',n)

mask='Hello'

do i=1,5

call brush(line(i))

end do

call eject

end

------------------------------------------------

 

The VCUR (vertical cursor positioning) subroutine moves the cursor vertically in 1/720 inch increments, called decipoints. The first argument is the directional parameter. It has three possible values. The plus sign indicates the downward direction, the minus sign the direction upward. The zero value indicates the absolute positioning of the cursor. The second argument is an integer, specifying the number of decipoints the cursor should be moved. An example of the Fortran call is

 

call vcur('+',i)

 

An example of the use of this subroutine is listed below.

 

 

Listing 10. Moving Cursor in the Vertical Direction

------------------------------------------------

open(1,file='lpt1')

write(*,'(a)')' Move cursor by how many decipoints?'

read(*,*)n

call vcur('+',n)

write(1,*)'Hello'

call eject

end

------------------------------------------------

 

 

HORIZONTAL PITCH

 

The PITCH subroutine sets the horizontal motion index to the required spacing. Typical settings are 10 or 12, setting the pitch of nonproportionally spaced fonts such as Courier or Line Printer to 10 or 12 characters per inch. Setting the pitch to twice or three times the default causes characters to be double spaced or triple spaced. Setting pitch to slightly lower than default values results in compressed font styles. Only pitch values between 0 and 126 are defined. When proportionally spaced fonts are selected, only the width of the space character is affected by the value of the horizontal motion index. The Fortran call of the subroutine is

call pitch(i)

where the integer value i defines the pitch. An example of the Fortran implementation of the pitch subroutine is listed below.

 

 

Listing 10. Setting the Horizontal Pitch

------------------------------------------------

character line(120)*1

write(*,*)'Set pitch: '

write(*,*)'0 <10> <12> 126'

read(*,*)lpitch

call pitch(lpitch)

write(*,*)'Read a message'

read(*,'(120a1)')line

do i=1,120

call brush(line(i))

end do

call crlf

call eject

end

------------------------------------------------

 

 

VERTICAL SPACING

 

The LPI subroutine sets the vertical increments in lines per inch units. Permissible increments are listed below

1 2 3 4 <6> 8 12 16 24 48

with six lines per inch being the default value. The Fortran call is

call lpi(i)

The argument defines the vertical spacing increment. An example of a Fortran implementation is listed below.

 

 

Listing 10. Setting the Vertical Spacing

------------------------------------------------

write(*,*)'Lines per inch?'

write(*,*)'1,2,3,4<6>8,12,16,48'

read(*,*)lpix

call lpi(lpix)

do i=1,10

call brush('x')

call crlf

end do

call eject

end

------------------------------------------------

 

 

VERTICAL MOTION

 

The VMI subroutine defines the vertical motion increments in 1/48 inch units. Permissible increments are 0.0000 to 126.000. The increment equal to 8 is the default value for 8.5 by 11 inch paper (6 lpi / 60 lpp). To compute the vmi increment, first determine the text length. For example, for 8.5 by 11 inch paper, the default text length is 10 inches (11 inches length minus 1 inch for the top and bottom margins). Second, select the desired number of lines per page and compute the lpi value as the lpp divided by text length in inches. The default is 60lpp, i.e.; 6 lpi. Third, use the formula 48 divided by lpi to compute the value of the vmi increment. Thus, the default value of the vmi is 48/6 = 8. The Fortran call of the vmi subroutine is

call vmi(i,j)

The first argument defines the vertical spacing increment; the second argument defines the decimal places for the increment. An example of a Fortran implementation, selecting 66 lines per 10 inch page is presented below.

 

 

Listing 10. Setting the Vertical Motion Index

------------------------------------------------

write(*,*)'Set vertical motion index: <0.0000 to 126.0000>'

write(*,*)'To print 66lpp set vmi as 48/lpi = 48/6.6 =7,2727'

read(*,*)ivmi,idec

call vmi(ivmi,idec)

call ltext(66)

do i=1,132

call brush('a')

call crlf

end do

call eject

end

------------------------------------------------

 

 

HALFWAY SHIFTS UP AND DOWN

 

The UHALF (for "half a line up") subroutine will move the cursor half line up. The subroutine is called as:

call uhalf

The call to this subroutine must be followed by a call to the dhalf ("half a line down) subroutine to return to the text line. The DHALF (for "half a line down") subroutine will move the cursor half a line down. The subroutine is called as:

call dhalf

The call to this subroutine must be followed by a call to the uhalf ("half a line up) subroutine to return to the text line. An example of use of the uhalf and dhalf subroutines follows.

 

 

Listing 10. Shifting Print Positions Up and Down

------------------------------------------------

character mask*80,line(80)*1,a*1

equivalence(mask,line)

mask='H2O'

do i=1,3

if(line(i).eq.'2')call dhalf

if(line(i).eq.'O')call uhalf

call brush(line(i))

end do

call hcur('+',720)

mask='X2'

do i=1,2

if(line(i).eq.'2')call uhalf

call brush(line(i))

end do

call dhalf

call eject

end

------------------------------------------------

 

 

SUBSCRIPTS AND SUPERSCRIPTS

 

The SUBscript subroutine moves the cursor 20 decipoints down, writes the subscript, and raises the cursor to the current line level. The subroutine is called as

call sub(a)

the argument is the character to be used as a subscript.

The SUPERscript subroutine moves the cursor 40 decipoints up, writes the superscript, and lowers the cursor to the current line level. The subroutine is called as

call super(a)

The argument is the character to be used as a superscript. An example of use of the subscript and superscript subroutines is presented below.

 

 

Listing 10. Using Subscripts and Superscripts

------------------------------------------------

character mask*80,line(80)*1,a*1

equivalence(mask,line)

mask='The correlation rxy equals...'

do i=1,28

if(line(i).eq.'x'.or.line(i).eq.'y')then

call sub(line(i))

cycle

endif

call brush(line(i))

end do

mask='The y=x2 is an equation ...'

do i=1,28

if(line(i).eq.'2')then

call super(line(i))

cycle

endif

call brush(line(i))

end do

call eject

end

------------------------------------------------

 

 

UNDERLINING

 

The UNDERLINE subroutine will activate the automatic underlining feature of the LaserJet. To call the underline subroutine, write a statement

call underline('+')

To turn the underlining off, call the uoff subroutine as call underline('-'). An example of the use of these subroutines is listed below.

 

 

Listing 10. Turning the Underlining On and Off

------------------------------------------------

call lj_open('*')

call text('This is a $')

call underline('+')

call text('truly important matter$')

call underline('-')

call text(' to consider$')

call eject

end

------------------------------------------------

 

 

CARRIAGE RETURN

 

The CR subroutine will return the cursor to the beginning of the current line. No line feed is appended. This subroutine is useful mostly for overprinting. To call the cr subroutine, write:

call cr

An example of the use of this subroutine is listed below.

 

 

Listing 10. Carriage Return

------------------------------------------------

character mask*78,line(78)*1

equivalence(mask,line)

mask='OOOOO'

n=0

1 do i=1,6

call brush(line(i))

end do

n=n+1

if(n.eq.5)then

mask='+++++'

call cr

endif

if(n.ge.10)goto 9

goto 1

9 call eject

end

------------------------------------------------

 

 

LINE FEED

 

The LF subroutine will perform the line feed. The cursor position will be preserved. To call the lf subroutine, write

call lf

An example of the use of this subroutine is listed below.

 

 

Listing 10. Line Feed

------------------------------------------------

character mask*78,line(78)*1

equivalence(mask,line)

mask='Hello'

do 10 i=1,6

call brush(line(i))

call lf

end do

call eject

end

------------------------------------------------

 

 

CARRIAGE RETURN FOLLOWED BY LINE FEED

 

The CRLF subroutine will send the carriage return character to the printer, followed by the line feed. To call the crlf subroutine, write

call crlf

An example of the use of this subroutine is listed below.

 

 

Listing 10. Carriage Return Followed by Line Feed

------------------------------------------------

 

call lj_open('+')

do i=1,20

call text('Hello$')

call crlf

end do

call eject

end

 

--------------------------------

 

 

FORM FEED

 

The FF subroutine will perform the form feed and move the cursor to the first line at top of the next page, preserving the column location of the cursor. To call the ff subroutine, write

call ff

An example of the use of this subroutine is listed below.

 

 

Listing 10. Using the Form Feed While Writing Directly to the Printer

------------------------------------------------

character mask*78,line(78)*1

equivalence(mask,line)

mask='Hello'

n=0

1 do i=1,5

call brush(line(i))

end do

n=n+1

if(n.eq.5)call ff

if(n.ge.10)goto 9

goto 1

9 call reset

end

------------------------------------------------

 

Notice that Fortran write statements automatically append the carriage return to the end of the line. Thus, in the following example, ff will behave exactly as eject.

 

 

Listing 10. Using the Form Feed With Fortran Write Statements

------------------------------------------------

open(1,file='lpt1')

mask='Hello'

do i=1,20

write(1,*)'Hello'

if(i.eq.5)call ff

if(i.eq.10)call ff

end do

call eject

end

------------------------------------------------

 

 

EJECTION OF PAGE

 

The EJECT subroutine will perform the form feed, followed by the carriage return. The page will be ejected and the cursor positioned at the beginning of the first line on the top of the next page. To call the eject subroutine, write

call eject

An example of the use of this subroutine is listed below.

 

 

Listing 10. Ejecting a Page

------------------------------------------------

call lj_open('*')

call text('Hello$')

call eject

end

------------------------------------------------

 

 

RESET PRINTER SETTINGS

 

The RESET subroutine will purge any partial text received by the printer and reset all programmable features to their default values. To call the reset subroutine write

call reset

An example of the use of this subroutine is listed below.

 

 

Listing 11. Resetting Printer

------------------------------------------------

call lj_open('*')

call text('Hello$')

call reset

end

------------------------------------------------

CHAPTER

11

SPECIAL FEATURES OF

THE LASERJET

 

Subroutines described in this chapter permit the control of the special features of the LaserJet printers, such as the manual paper feed, or the selection of the number of copies to be printed. Introduction of the duplex printing on Hewlett-Packard LaserJet printers IID and IIID opened a new range of programming possibilities with features as selection of the short or long paper edge for various types of bindings and specification of page breaks starting the the back page of the printed document or on the front page of a new sheet of paper. Also, the simplex or duplex printing mode itself can be selected directly from the Fortran programs. The dual trays of the LaserJets IID and IIID also permit selection of papers of different colors or paper sheets with letterheads from different feeding bins. The addition of the envelope feeder permits the redirection of the printer output as to print logo and return address on the plain envelopes at the same time they are being addressed.

 

 

NUMBER OF COPIES

 

The COPIES subroutine sets the number of repeated printings of a page. One to 99 copies may be specified. The Fortran call is

call copies(i)

An example of Fortran implementation follows.

 

 

Listing 11. Specifying the Number of Copies

------------------------------------------------

open(1,file='lpt1')

write(*,'(a)')' How many copies?'

read(*,*)n

call copies(n)

write(1,*)'Hello'

call copies(1)

end

------------------------------------------------

 

 

ORIENTATION

 

The ORIENT subroutine permits selection of the printing in the portrait or landscape mode. It is called from the Fortran program as

 

call orient('L')

 

where the value of the argument may be either the letter P designating the portrait orientation of the printed page, or the letter L, for the landscape printing mode. An example of calling the orient subroutine from the Fortran program is presented below.

 

 

Listing 11. Changing the Printing Orientation

------------------------------------------------

call lj_open('*')

call orient('p')

call text('Portrait$')

call orient('l')

call text('Landscape$')

call reset

end

------------------------------------------------

 

 

SIMPLEX PRINTING

 

The SIMPLEX subroutine permits the return to simplex page printing after the duplex page printing mode was selected. The subroutine is called from the Fortran programs as

 

call simplex

 

and has no arguments. An example of calling of the simplex subroutine from the Fortran program is presented in the section on duplex printing.

 

 

DUPLEX PRINTING

 

The DUPLEX subroutine is used to select duplex printing on laser printers permitting the duplex printing and emulating the Hewlett-Packard protocol for LaserJet printers IID and IIID. The subroutine is called as

 

call duplex

 

and has no arguments. The example of the duplex subroutine, called from as Fortran program, is presented in the listing below.

 

 

Listing 11. Duplex Printing

------------------------------------------------

call lj_open('*')

call simplex

call text('Hello$')

call crlf

call eject

call duplex

do i=1,70

call text('Front Page$')

call crlf

end do

call text('Back Page$')

call duplex

do i=1,70

call text('Front Page A$')

call crlf

end do

call text('Front Page B$')

call reset

end

------------------------------------------------

 

 

BINDING EDGE

 

The BINDING subroutine permits the selection of the binding edge during the course of duplex printing. The subroutine permits selection of the long edge or short edge binding. It is called from the Fortran program as

 

call binding('L')

 

The value of the argument can be either L for the long edge binding or S for the short edge binding. The binding subroutine, in conjunction with the orient subroutine, selecting the page orientation, permits printing of the four basic formats of bound documents. In the portrait mode, the selection of the long edge binding defines the standard book binding format. The selection of the short edge binding format defines the binding format of a note pad. In the landscape mode, the selection of the long edge binding defines the calendar style of binding while the selection of the short edge binding defines the leporello binding format, typical of children's book.

 

 

PAGE BREAK

 

The PG_BREAK subroutine, in the course of duplex printing, allows to start a new page on the back page of the printed document, or on the new physical page. The subroutine is called fron the Fortran program as

 

call pg_break('X')

 

where the value of the x argument can be either F for the front page or B for the back physical page of the printed document. An example of the use of the p_break subroutine within the Fotran program is presented in the listing below.

 

 

Listing 11. Page Break

------------------------------------------------

call lj_open('*')

call duplex

call text('Hello$')

call pg_break('B')

call text('Back Page$')

call reset

end

------------------------------------------------

 

 

PAPER TRAYS

 

The TRAY subroutine permits selection of the paper tray from which the paper is fed into the printer. The Fortran call is

call tray('X')

where the value of the x argument can be either U for the upper tray or L for the lower tray. An example of the Fortran implementation is presented below.

 

 

Listing 11. Paper Tray

------------------------------------------------

call lj_open('*')

call tray('U')

call text('Upper Tray$')

call tray('L')

call text('Lower Tray$')

call reset

end

------------------------------------------------

 

 

MANUAL PAPER FEED

 

The MANUAL subroutine allows for insertions of single sheets of paper. The Fortran call of the subroutine is

call manual('+')

To disable the manual paper feed option, call the manual subroutine as call manual('-'). An example of the use of this subroutine is listed below.

 

 

Listing 11. Feeding Paper Manually

------------------------------------------------

 

call lj_open('*')

call manual('+')

call text('Hello$')

call manual('-')

call text('Hi$')

call reset

end

 

-----------------------

 

 

PAGE SIZE

 

The PG_SIZE subroutine defines the physical page size. The standard page size is the 8.5'' x 11'' paper format. The standard page size can be changed to the executive paper size (7.25'' x 10.5''), legal paper size (8.5'' x 14'') and European A4 standard paper size format (210 mm x 297 mm). Also, the pg_size subroutine can be used to select the envelope sizes. The supported envelope sizes are Monarch (3 7/8'' x 7 1/2''), Business (4 1/8'' x 9 1/2''), International (110 mm x 220 mm) and the European C5 format (162 mm x 229 mm). The subroutine is called from the Fortran program as

 

call pg_size('S')

 

where the argument can be specified as to define the physical size of the paper as S (Standard), E (Executive), L (Legal), and A (European A4). The envelope sizes can be designated as M (Monarch), B (Business), I (International) and C (European C5 standard).

 

 

ENVELOPES

 

The ENVELOPE subroutine allows to print envelopes from the envelope feeder. Feed the envelope face up, with the bottom of the envelope toward the right, facing the printer. Change the page orientation to the landscape mode, select the envelope size, and set the top and left margins. The Fortran call is

call envelope('+')

To disable the envelope feeder and return to the feed from the upper or lower bins, call the envelope subroutine as call envelope('-'). An example of a Fortran implementation is presented below.

 

 

Listing 11. Printing Envelopes

------------------------------------------------

call lj_open('*')

call orient('L') !Landscape orientation

call pg_size('M') !Monarch envelope

call envelope('+')

do i=1,8

call crlf

end do

call text('Mr. John Doe$')

call crlf

call text('125 Main Street$')

call crlf

call text('Anytown, AZ 01234$')

call envelope('-')

call pg_size('S') !Standard page size

call eject

end

CHAPTER

12

CHARACTER GRAPHICS

 

Subroutines for the control of laser printers, described in preceding chapters, can be used in more complex subroutines to generate simple graphic effects on the printed page. The subroutines described here are ancillary and should not be substituted for generation of graphics which really necessitate a separate programming language commands. The suggested use for the graphic primitives described in this chapter is to add a finishing touch to the ordinary printed output.

 

 

HORIZONTAL LINE

 

The HCLINE subroutine composes a line of certain length by concatenating some ASCII characters. The Fortran call of the subroutine is

 

call hcline('-',ir,ic,length)

 

where the first argument is the character to be used in line drawing. Typically, the dash (-) and underline (_) characters are used. The dash character results in a line centered within the row; the underline character can be used to position the line toward the top or bottom of the row. The second and third arguments are the row and column coordinates of the origin of the line, to be drawn toward right. The last argument is the length of the line. An example of the use of the hcline subroutine is listed below.

 

 

Listing 12. Drawing a Horizontal Line

------------------------------------------------

call escape('&10O^[(0U^[(s1p10v0s0b5T')

length=15

call quill(10,10,'Moderate 50-$')

call hcline('+','_',10,23,length)

call quill(20,10,'Moderate 50-$')

call hcline('+','-',20,23,length)

call eject

end

------------------------------------------------

 

 

VERTICAL LINE

 

The VCLINE subroutine composes a line of certain length by concatenating some ASCII characters. The Fortran call of the subroutine is

 

call vcline('+',ir,ic,length)

 

The first argument determines the direction in which the line is to be drawn. The plus sig signifies the direction toward the top of the page, the minus sign the direction toward the bottom. The second and third arguments are the row and column coordinates of the origin of the line. The last argument is the length of the line. An example of the use of the vcline subroutine is listed below.

 

 

Listing 12. Drawing a Vertical Line

------------------------------------------------

call vcline('+',20,50,10)

call eject

end

------------------------------------------------

 

 

COORDINATES OF THE X Y GRAPH

 

The use of the character graphics is illustrated on an example drawing the abscissa and the ordinate of a graph, together with the numerical annotation of the X and Y axes, as presented in the listing below.

 

 

Listing 12. Drawing Coordinates of the XY Graph

------------------------------------------------

character a*1,b*1,c*1

ic=ic-4

a='|'

b='_'

"Ordinate

call rowcur('0',ir)

call colcur('0',ic+3)

call brush(a)

call rowcur('0',ir)

call colcur('0',ic+3)

call brush(b)

ix=48

do i=1,9

call colcur('0',ic)

call rowcur('-',1)

ix=ix+1

c=char(ix)

call brush(' ')

call brush(c)

call brush('0')

call brush(b)

call colcur('0',ic+3)

call brush(a)

end do

call colcur('0',ic)

call rowcur('-',1)

call brush('1')

call brush('0')

call brush('0')

call brush(a)

call colcur('0',ic+3)

call rowcur('-',0)

call brush(b)

"Abscissa

call rowcur('0',ir)

call colcur('0',ic+4)

do i=1,15

call colcur('+',0)

call brush(b)

end do

call rowcur('0',ir+1)

call colcur('0',ic+4)

call uhalf

open(1,file='lpt1')

write(1,'(a)')' | | | | |'

close(1)

call rowcur('0',ir+2)

call colcur('0',ic+4)

call uhalf

open(1,file='lpt1')

write(1,'(a)')' 10 30 50 70 100'

close(1)

end

-----CHAPTER

13

RASTER GRAPHICS

 

Sometimes, the regular output to the printer needs to be complemented by a special feature. The output needs to be framed by using lines of varying thickness. A custom designed logo needs to be added to the upper left corner of the printed envelope. Another example when one would resort to generation of a graphic primitives at a very low level, described in this chapter, would be to complement the printer's font by a needed special character, not provided for by the regular font.

 

 

RESOLUTION OF RASTER GRAPHICS

 

The RES (raster graphics resolution) subroutine sets the "thickness" of the beam painting the image. The "a" beam (75dpi) paints thick lines consisting of 16 dots, as

* * * *

* * * *

* * * *

* * * *

The thickness of the "b" beam (100dpi) is 9 dots, as

* * *

* * *

* * *

The "c" beam (150dpi) emits 4 dots, as

* *

* *

and the "d" beams paints the sharp line of a single dot (300 dpi), as

 

*

 

The Fortran call of the subroutine setting the resolution of the laser beam, painting the image is

call res('b')

where the parameter is a character, determining the heaviness of the line. The res subroutine should be called before all other raster graphics commands.

 

 

DEFINITION OF THE PAINT BRUSH

 

The PACK subroutine converts binary arrays into byte chunks. The transmission of raster graphics into LaserJet is by means of bursts of eight bits, packed into byte chunks. The pack subroutine, together with the res subroutine allows for definition of the paint brush for raster graphics. The binary 1 prints a dot, binary zero represents a blank dot. Thus the binary pattern

 

1 1 0 0 0 0 1 1

 

will paint two parallel lines. The binary pattern

 

1 0 0 0 0 0 0 1

 

will paint two very thin parallel lines. To paint a line, a binary patterns as

 

1 0 0 0 0 0 0 0

or

0 0 0 0 0 0 0 1

 

may be used. Wider lines can be obtained by defining transmission chunks as

 

1 1 0 0 0 0 0 0

or

0 0 0 0 0 0 1 1

 

Heavy lines are painted as

 

1 1 1 1 1 1 1 1

 

The thickness of the line will also depend on the thickness of the beam painting the image, as defined by the a b c d (75, 100, 150, 300 dpi) arguments of the graphic resolution subroutine res. The pack subroutine has two arguments. The first character is a literal array, eight characters wide. The second argument is a single character. The subroutine is called as

 

character a*8,b*1

call pack(a,b)

 

The packed byte chunks are typically send to LaserJet by the brush subroutine. The transmission must be preceded by the call to the rtrans subroutine.

 

 

INITIATION OF RASTER GRAPHICS

TRANSMISSION

 

The RSTART subroutine initiates the raster graphics transmission. Its parameter determines the start position. The subroutine is called as

call rstart('<')

or

call rstart('^')

 

When the "less than" sign is used, it indicates that raster graphics should start at the leftmost printable position on the page (not at the left margin). When the upper arrow is used, it specifies that printing should start at the current cursor position.

 

 

TRANSMISSION OF RASTER GRAPHICS

 

The RTRANS subroutine transmits the raster graphics. It must precede each line of graphics mode transmission. To call this subroutine, write a Fortran statement

call rtrans(i)

Here, the i parameter is the number of bytes in the line of data sent to printer. For example,

call rtrans(4)

will send four bytes (four characters, i.e., 32 bits) to the printer. The call to this subroutine is usually followed by the calls of the brush subroutine, sending the eight bit chunks defined by the pack subroutine to the LaserJet.

 

 

TERMINATION OF RASTER GRAPHICS

 

The REND signals the end of raster graphic transmission. The subroutine is called as

 

call rend

 

and must be included in the Fortran program every time the transmission of raster graphics is terminated.

 

 

CREATION OF RASTER GRAPHICS

 

To illustrates of the use of the graphic primitives for the development of graphic routines, let us draw a line. The listing of the Fortran code, calling the raster graphics primitives follows.

 

 

Listing 13. Drawing a Line

------------------------------------------------

i=20

j=30

k=1000

call res('a')

do n=1,k

call rowcur('0',i)

call colcur('0',j)

call hcur('+',n)

call rstart('^')

call rtrans(1)

call brush('@')

call rend

call vcur('-',1)

end do

end

------------------------------------------------

 

Here, the resolution of the paint beam is not defined by the pack subroutine; instead the @ character, defined by the 1 0 0 0 0 0 0 0 bit pattern is used. The backspacing over the seven blank spaces is controlled by the vcur subroutine called at the end of the do loop.

 

 

HORIZONTAL LINE

 

The HLINE subroutine draws a horizontal line of a specific length either in the left to right or right to left directions. The length of the line is in points. The subroutine has the arguments specifying the origin of the line on the page row - column grid (irow, icol) and the length of the line. The '+' or '-' argument at the beginning of the argument field specifies the direction in which the line is to be drawn. The '-' character indicates the left to right direction, the '+' character the right to left direction. An fragment of a program, illustrating the use of the subroutine is presented below.

 

 

Listing 13. Drawing Horizontal Line

------------------------------------------------

irow=20

icol=30

length=100

call hline('-',irow,icol,length)

call eject

end

------------------------------------------------

 

 

VERTICAL LINE

 

The VLINE subroutine draws a vertical line of a specific length either in the upward or downward directions. The length of the line is in points. The subroutine has the arguments specifying the origin of the line on the page row - column grid (irow, icol) and the length of the line. The '+' or '-' argument at the beginning of the argument field specifies the direction in which the line is to be drawn. The '-' character indicates the upward direction, the '+' character the downward direction. An illustration of the use of the subroutine within the Fortran program follows.

 

 

Listing 13. Drawing Vertical Line

------------------------------------------------

irow=20

icol=30

length=100

call vline('-',irow,icol,length)

call reset

end

------------------------------------------------

 

 

LOGO DESIGN

 

The RASTER subroutine prints graphics sketched on any screen-oriented text editor as a pattern of asterisks and any other characters, serving as a grid, or blanks. The subroutine converts asterisks to ones, all other characters to zeroes, packs chunks of eight ones and/or zeroes into a character, sets up the graphics mode, and sends the picture to the LaserJet. The subroutine is called as

call raster(lu,r)

where lu is the logical unit of the opened graphics file and the r parameter is set to a, b, c, or d, to set the resolution. An example of the use of this subroutine is listed below.

 

 

Listing 13. Logo Design

------------------------------------------------

character file*16,r*1

write(*,*)'Name of the graphics file:'

read(*,'(a)')file

open(1,file=file)

lu=1

write(*,*)'Resolution? <a,b,c,d>'

read(*,'(a)')r

call raster(lu,r)

end

------------------------------------------------

 

 

FONT DESIGN

 

The LETTER subroutine allows for composition of new printer characters. This character creation routine was designed to enable you to create letters which happen to be missing from your character set, or to create a character of your own. This routine was not meant to create new character sets, just to complement existing ones.

To create a font, create an oversized pattern of a letter with asterisks. The working space is typically 40 rows and 32 columns. As in the raster routine, pixels are turned on by asterisks. Other characters are translated to zeroes. Any text editor as, e.g., Brief, can be used. The vertical structure of the character raster is typically as follows. Ascenders are 11 rows (26.4 decipoints), the body is 21 rows (50.4 decipoints) and the descenders are 8 rows (19.0 decipoints). The horizontal dimension of the character is 32 columns (4x8 bytes), enough to accommodate most special characters. However, some extra wide characters such as M or H will require up to 40 columns (5x8 bytes). As a general rule, there should be no abrupt changes in the letter contours; the successive differences in the curved contours should not be more than one point at a time. Inspection of the generated character with a magnifying glass will probably reveal minor flaws which may be removed by reediting the file.

When a proportionally spaced character is being constructed, some minor adjustments in the character left and right horizontal margins may be necessary. These adjustments are controllable by the iha and ihz arguments of the letter routine. Also, proper alignment of the character with the line of the printed text is controllable by the vertical adjustment parameters iva and ivz of the letter subroutine. All adjustment parameters are in decipoints.

The iha parameter specifies the left margin of a letter. A positive number expands the margin, negative number reduces the margin. The ihz parameter specifies the right margin of a letter. A positive number augments the margin, negative number decrements the margin. The iva parameter specifies the letter line adjustments. A positive number raises the letter above the preceding line, negative number lowers the letter with respect to the preceding line. The ivz parameter determines the line adjustment of the subsequent text; positive number raises the following text line vertical adjustment, negative number lowers the text which follows. An example of the subroutine implementation is presented below.

 

 

Listing 13. Font Design

------------------------------------------------

character text(80)*1,mask*80,file*16

equivalence(text,mask)

mask='The Greek letter indicates summation'

call font(2)

len=80

do i=80,1,-1

if(text(i).ne.' ')then

len=i

exit

endif

end do

do i=1,len

if(ichar(text(i)).eq.228)then

file='sum.fnt'

open(8,file=file)

call letter(8,25,77,57,24)

cycle

endif

call brush(text(i))

end do

call eject

end

 

APPENDIX

ENVIRONMENT FOR

PROGRAM DEVELOPMENT

 

Programming involves many repetitive tasks. Source code file must be edited, compiled and linked. Often, other source code files have to be located and inspected. Within large program subdirectories, selective directories have to be displayed. Linker command modules have to be modified. Compilers and assemblers have to be selectively invoked. Tables of binary, hexadecimal, and decimal codes have to be consulted. Codes corresponding to ASCII graphics characters have to be ascertained.

The manifold tasks associated with the program development should be organized, abbreviated, and personalized. The organization of computer operation tasks can be approached via several avenues. The graphical user interfaces are good in visual organization of programs and routines available; however, reaching for the mouse, locating an icon, and clicking the mouse's button cannot even approximate the speed of invoking an operation system command from the keyboard by typing a d or dir for a directory or l for a listing utility. The abbreviation of names of utilities is the simplest remedy, but has its limits since the list of two or three letter meaningful abbreviations is easy to deplete. The use of batch files is sometimes helpful; however, the organization of manifold batch files itself presents a problem.

 

 

CLAVIS

 

Clavis (lat., key) keyboard extender allows for assignment of over 120 commands to any key on the keyboard. The 12 function keys can be extended to 48 by shift, control, and alternated commands. The 26 keys of the alphabet, good as mnemonic tools, can be extended to 52 by the control and alternate commands, as can be the numerical keys 0 1 2 3 4 5 6 7 8 9, adding another 20 possibilities for assignment of command sequences. If these are not enough, the alternate and control states of many special character keys, including keys in the keypad can be also used for the storage of frequently requested commands. The front page of the Clavis keyboard extender is presented below.

 

The front page of the Clavis display screen shows assignments of the function keys. These assignments represent the most frequently invoked commands. Directories, directory trees, command for changing subdirectories, and batch files for automated compiling and linking with both the Microsoft Fortran and Microsoft Assembler. The function key assignments also include command to invoke the programmer's editor brief and a file viewing utility program.

To anyone but a programmer, the assignment of a single letter b to a function key may seem ludicrous. However, the function key assignment also contains the blank space, following the letter b and preceding the name of the file to be edited. If the text editor is invoked over a hundred times during a typical working day, the saving of a hundred keystrokes becomes significant. This is, however, an extreme example. Consider, e.g., the specialized directory dirigo with several optional switches, controlling the various kinds of directory displays. In this case, the savings in time and effort become significant, even if the program is invoked only a several times a day.

The Clavis permits the invocation of commands either in the declarative mode, or in a form an inquiry. In the declarative mode, the carriage return is appended at the end of the command so the command gets executed without the necessity of pressing the enter key. The execution of a command, as, e.g., dir/p is thus abbreviated into a single key press. Tn the form of a query, the clavis displays the command name, followed by a blank space, and waits for the further specification of the command. Thus, e.g., the DOS command copy *.* is displayed by a single stroke, a blank space is appended, and Clavis awaits the specification of the destination of the copy all files operation.

The Clavis operates in the outermost shell of the operating system, using a custom ansi.sys driver which can be installed and deinstalled by a single keystroke. The key assignments do not conflict with the function and accelerator keys of most commercial programs which use the BIOS level for the control of the keyboard. If a rare interference is encountered, usually in running an old or home-brew program, the Clavis keyboard assignments can be unloaded in an instant. However, the most important feature of Clavis is that all commands are assigned on the basis of the personal preferences. The use of Clavis is ultimately based on a personal system of mnemonic commands which can be assigned with an unprecedented ease. Also the selection of the commands and the utility routines provides a full latitude to each individual programmer.

The pages of the Clavis displays contain dozens useful commands and names of the utilities. One page is reserved to the programming aids to which we will now turn our attention.

 

 

ASCII AND UPPER ASCII TEMPLATES

 

The chart frequently consulted is the chart of the ASCII characters and their extensions. The extensions of the standard ASCII characters is located above the 7f. The definition of the original 128 characters was possible by using only seven bits in an 8 bit computer word. The eight bit was used for the parity control. By defining the eight bit the original IBM display doubled the number of available characters to 256. Culturally, one of the most insensitive acts of the computer age, the IBM did not adopt the mapping of the Latin characters into their Greek counterparts by changing the eight bit of the character byte. The Greek letter alpha is one bit off its corresponding Latin letter a. Worse, the set of the Greek characters is incomplete, impending scientific and scholarly applications of the computing to some degree. The IBM did not fare better with their Roman extensions of the classical Latin alphabet any better. By any standards, the roman extensions of the upper ASCII sets are incomplete and not suitable for word processing in a majority of languages using the diacritical extensions of the Roman alphabet.

 

 

SCREEN DESIGN TEMPLATES

 

The characters for the screen design were adopted following the discussion on the pages of Byte about the design of screens using the character graphics, as different from graphics which manipulate the screen at the pixel level. Scattered throughout the table of the upper ASCII characters, the graphical screen design characters can be organized as in this table, facilitating the construction of screen displays substantially.

 

 

KEYBOARD CODES

 

The scan codes returned by BIOS after a key is pressed can be called from the Clavis keyboard shell, as well as keyboard codes generated after a key is pressed and accessed through the hardware port 60h.

 

 

PROGRAM DEVELOPMENT AIDS

 

Often, to consult a complete table of keyboard codes is too time consuming, especially when the programmer is looking for a single specific code. Keystroke decoders a_code, b_code and c_code, directly accessible from the Clavis keyboard shell, return the scan codes at either the DOS, BIOS, or hardware keyboard control levels of any key pressed. Some more involved work necessitates the use of binary codes, corresponding to character codes, provided by the bin_codes table under Clavis. An example of such a work can be the encoding of the binary patterns of raster graphics into ASCII characters to be transmitted over the telephone lines by using the standard serial communication protocol and subsequent decoding of the received communication into raster graphic images. The list can go on, but for many tasks, dedicated, task specific environment is needed. The open architecture of Clavis is inviting to personalized, task specific customizations of the working environments, facilitating the manifold program development activities.

 

 

TABLES

 

 

 

Table A The ASCII Chart

----------------------------------------------------

 

Table B The Chart of Design Characters

 

Table C The BIOS Keyboard Scan Codes

--------------------------------------------------

 

 

 

Table E Selected DOS Interrupts

----------------------------------------------------

 

4ch/21h

 

Terminate program. The for Charlie interrupt for termination of stand alone assembly language programs. Set the ah register to 4ch and execute interrupt 21h.

 

1h/21h

 

Read and display keyboard character. The input character is returned in the al register. Set the ah register to 1h and execute interrupt 21h.

 

2h/21h

 

Write character to screen. Displays character contained in the dl register. Set the ah register to 2h and execute interrupt 21h.

 

5h/21h

 

Write to lpt1. Other parallel ports, lpt2 or lpt3, may be selected with the MODE program. Set the ah register to 5h and execute interrupt 21h.

 

7h/21h

 

Read keyboard. The character is returned in the al register and is not displayed. Does not check for ctrl c. Set the ah register to 7h and execute interrupt 21h.

8h/21h

 

Read keyboard without echo. The character is returned in the al register. Checks for ctrl c. Set the ah register to 8h and execute interrupt 21h.

 

9h/21h

 

Display a string of characters. The address of the string goes to the ds:dx registers. Terminate message with the $ sign. Set the ah register to 9h and execute interrupt 21h.

3ch/21h

 

Create file. Point the ds:dx registers to the offset of the ASCIZ path and file name stored in a memory area. Set the ah register to 3ch and execute interrupt 21h.

 

3dh/21h

Open file. To read an existing file, the file has to be first opened. Point the ds:dx register to the offset of the ASCIZ path and file name stored

 

in a memory area. Place in the al register the access mode codes; zero for read only, one for write only, and two for both read and write. Set the ah register to 3dh and execute interrupt 21h.

 

 

 

3eh/21h

 

Close disk file. After creation of file and writing to it, the file must be closed to be usable. Place the file handle in the bx register, set the ah register to 3eh, and execute interrupt 21h.

 

3fh/21h

 

Read file or device. After a file has been created, written to, and closed, it can be read. Open the file again to get the file handle. Move the handle into the bx register and place in the cx register the number of bytes to read. Point the ds:dx register to the memory area where to copy the data. Set the ah register to 3fh and execute interrupt 21h.

 

40h/21h

 

Write file or device. File handle 1 in the bx register writes to screen, file handle 4 writes to lpt1. The ds:dx registers point to the location of message in memory. The number of bytes to write goes to the cx register. Set the ah register to 40h and execute interrupt 21h.

 

41h/21h

 

Delete disk file. Point the ds:dx registers at the offset of the ASCIZ path and file name. Set the ah register to 41h and execute interrupt 21h. The first character in the file name will be changed to the lowercase Greek character sigma, marking the file as deleted.

 

43h/21h

 

Set or change file attributes; archive, read only, hidden. Point the ds:dx registers at the offset of the ASCIZ path and file name. Set the ah register to 43h and execute interrupt 21h. The file attributes are returned in the cx register. To change the attributes, set the al register to 1 and the cx register to the requested attributes.

 

 

 

56h/21h

 

Rename file. Point the ds:dx registers to the offset of the ASCIZ path and file name, the es:di registers to the new name. Set the ah register to 56h and execute interrupt 21h.

 

 

62h/21h

 

Program segment prefix address for the current program. Set the ah register to 62h and execute interrupt 21h. The program segment prefix address will be returned in the bx register.

 

6ch/21h

 

 

Open and crete files. Combines functions provided by 3c/21h, 3d/21h, and 5b/21h.

 

 

Table F Selected BIOS Interrupts

----------------------------------------------------

 

0h/16h

 

Keyboard scan codes. Set the ah register to 0h and execute interrupt 16h. The ASCII value of the keystroke will be returned in al and the scan code in ah. The scan codes are listed in Appendix, Table C. The ASCII values are listed in Appendix, Table A.

 

1h/10h

 

Change cursor appearance or make it disappear. To change the cursor size, put the starting row in register ch and the ending row in register cl. Set the ah register to 1h and execute interrupt 10h.

 

2h/10h

 

Change cursor position. The monochrome screen has only one page, number zero, to be specified in the bh register. The new row number goes to the dh register and the new column number to the dl register. Set the ah register to 2h and execute interrupt 10h.

 

3h/10h

 

Find cursor position. The page number, normally zero, goes to the bh register. On return from the interrupt, the row and column coordinates of the cursor are in the dh and the dl registers.

 

6h/10h

 

Scroll active page up. Place the number of lines to scroll (1 to 24 lines) to the al register. A value of zero scrolls the entire screen. The upper left corner coordinates of the rectangle to scroll do to the ch and cl registers. The coordinates of the lower right corner go to the dh and dl registers. As the screen is scrolled up, blank lines appear below. The attributes of these lines can be defined by using the bh register. Set the ah register to 6h and execute interrupt 10h.

 

 

7h/10h

 

 

Scroll active page down. Place the number of lines to scroll (1 to 24 lines) to the al register. A value of zero scrolls the entire screen. The upper left corner coordinates of the rectangle to scroll do to the ch and cl registers. The coordinates of the lower right corner go to the dh and dl registers. As the screen is scrolled down, blank lines appear above. The attributes of these lines can be defined by using the bh register. Set the ah register to 7h and execute interrupt 10h.

 

8h/10h

 

Read a charcter and its attribute at the current cursor position. Set the bh register to zero, indicating the normal display page. Set the ah register to 8h and execute interrupt 10h. The character is returned in the alregister and its attribute in the ah register.

 

9h/10h

 

 

Write a character and its attribute at the current cursor position. The character to write is placed in the al register and its attribute in the bl register. The page number (zero) is placed in the bh register and the number of characters to write (normally 1) is placed in the cx register. Set the ah register to 9h and execute interrupt 10h.

 

0ah/10h

 

 

Write character only at the current cursor position. The character to write is placed in the al register. The page number (zero) is placed in the bh register and the number of copies of the character (normally 1) is placed in the cx register. Set the ah register to 0ah and execute interrupt 10h.

 

0eh/10h

 

 

 

Write character in teletype fashion. Interpret the control characters. Set the ah register to 0eh and execute interrupt 10h.

 

GLOSSARY

A_KEY subroutine secures input from the keyboard at the level of DOS interrupts.

 

 

ANSI subroutine detects the presence of the American National Standard for Information Interchange driver.

 

 

A_PEN subroutine writes to screen at the level of DOS interrupts.

 

 

BEEP subroutine makes the speaker to emit a single beep.

 

 

BINDING subroutine permits the selection of the long or short binding edge in the course of the duplex printing.

 

 

B_KEY subroutine secures input from the keyboard at the level of BIOS interrupts.

 

 

BLACK_B subroutine displays electronic blackboards.

 

 

B_PEN subroutine writes to screen at the level of BIOS interrupts.

 

 

BLANK subroutine fills a string with blank spaces.

 

 

BLINK subroutine makes text blink.

 

 

BRUSH subroutine transmits a character or a string of characters into the parallel port of a printer.

 

 

BS subroutine will backspace the cursor one column toward the left on a page of a LaserJet printer.

 

 

CATENA subroutine executes other programs from within the calling program.

 

 

CENTER subroutine centers text within a string.

 

 

CENTIS subroutine measures the elapsed time in centiseconds.

 

 

CENTRAL_M subroutine displays a menu on the screen. Each menu item occupies a column within the menu window. Selection of menu items is either by moving a highlighted bar by arrow keys or by pressing the capitalized letter of an item. The menu items are defined from within the program. The menu is floating and can be moved by Page Up, Page Down, Home, and End keys to any location on the screen.

 

 

CHANGE_D subroutine functions as the DOS command CHDIR or CD.

 

 

COVER subroutine composes full screen displays using characters from the Cruise Font Library.

 

 

CLEARM subroutine will set the margins of a printer into their default values and return the cursor to column zero.

 

 

C_LOCK subroutine reports whether the CapsLock key is engaged.

 

 

COLCUR subroutine positions the cursor horizontally by moving the cursor across printing paper columns whose width is determined by the active print pitch (nonproportional characters) or by the space character width (proportional fonts).

 

 

COPIES subroutine sets the number of repeated printings of a page.

 

 

CLS subroutine clears the screen by scrolling the screen up and returning the cursor into the upper left corner of the screen.

 

 

CPU subroutine ascertains what kind of Intel's iAPX series of 88 / 186 / 286 / 386 microprocessors the computer the programs is being run on has.

 

 

CR subroutine will return the cursor to the beginning of the current line on the page of a printer.

 

 

CRLF subroutine will send the carriage return character to the printer, followed by the line feed.

 

 

CUR subroutine positions the cursor with respect of row column grid of a printer.

 

 

CURSOR subroutine alters the shape of the cursor or makes it disappear.

 

 

CREATE_D subroutine functions as the DOS command MKDIR or MD.

 

 

DAY subroutine returns the current data as set in the operating system.

 

 

DAYS subroutine formats the date and supplies the names of the days of the week.

 

 

DELAY subroutine delays execution of the next program statement by the number of centiseconds, specified by its argument.

 

 

DELETE_F subroutine deletes files from the Fortran programs.

 

 

DHALF subroutine will move the cursor half a line down the page of a printer.

 

 

DIR_PATH determines the path within the current directory.

 

 

DUPLEX subroutine changes the printing from the simplex into the duplex mode; i.e., both sides of a paper sheet are printed.

 

 

DRIVES subroutine counts the number of logical and physical drives attached to the system.

 

 

EJECT subroutine will send the form feed, followed by the carriage return to the printer.

 

 

ENVELOPE subroutine allows to print envelopes using the envelope feeder.

 

 

ENVIRON subroutine parses and extract parameters defined in the program environment by the set command.

 

 

ESCAPE subroutine allows you to send any escape sequence to the printer.

 

 

EXISTS subroutine reports to the calling program whether a file to be associated with a logical unit exists.

 

 

EXIT subroutine defines the exit errorlevel at the time of program termination.

 

 

FF subroutine will perform the form feed and move the cursor to the first line at top of the next page of the printer, preserving the column location of the cursor.

 

 

FRAME subroutine creates a framed box on a screen or within the screen window.

 

 

GETCUR subroutine returns the screen coordinates of the cursor location.

 

 

HCUR subroutine moves the cursor horizontally on the page of a printer in 1/720 inch increments (decipoints).

 

 

HCLINE subroutine composes a string filled with defined characters on the page of a printer.

 

 

HIDE subroutine makes the file, specified in its argument, invisible to directory search.

 

 

HLINE subroutine draws a horizontal line of a specific length either in the left to right or right to left directions on the page of a printer.

 

 

INVOKE subroutine invokes the command.com processor from within a Fortran program. It allows for execution of the operating system commands from a Fortran program.

 

 

KEY_DEF subroutine assigns substitute characters, text or commands to keyboard keys in the normal, shifted, control, or alternate states.

 

 

KEY subroutine secures the input from the keyboard at the level of BIOS interrupts and maps the upper ASCII characters between 0E0H and 0FFH into the alternate keys of the keyboard.

 

 

LADJ subroutine left adjusts text within a string.

 

 

LENGTH subroutine measures length of a text within a string.

 

 

LCASE subroutine converts text within a string into lowercase.

 

 

LEFTM subroutine will reset the left margin of the printer's page to the column specified.

 

 

LENGTH function returns the length of text within the string.

 

 

LETTER subroutine allows for composition of new printer characters.

 

 

LF subroutine will perform the line feed on the page of a printer.

 

 

LJ_CLOSE subroutine closes the communicationj channel with a peripheral device capable of receiving characters or pixels.

 

 

LJ_OPEN subroutine opens the communicationj channel with a peripheral device capable of receiving characters or pixels.

 

 

LLEN function returns the distance of text from the beginning of the string.

 

 

LOCKS subroutine unlocks the NumLock, CapsLock, and Scroll Lock on the keyboard.

 

 

LPI subroutine sets the vertical increments on the printer's page in lines per inch units.

 

 

LTEXT subroutine specifies the number of lines to define a printer's page.

 

 

MANUAL subroutine allows for insertion of single sheets of paper to Laser printers.

 

 

MEMORY subroutine reports available memory up to 640K.

 

 

MEM_UP subroutine returns the amount of memory above the 1M.

 

 

MEM subroutine reports amount of memory available to the program during the time of its execution.

 

 

NEW_DR subroutine allows to change a drive from the calling program.

 

 

N_LOCK subroutine reports whether the numerical keypad is locked in the number mode.

 

 

ORIENT subroutine changes the printing orientation from portrait to landscape and vice versa.

 

 

PACK subroutine converts binary arrays into byte chunks within the context of raster graphics.

 

 

PAGES subroutine stops a screen display until a key is depressed. Message specified in its argument is displayed in the lower right corner of the screen. The subroutine clears the screen and repositions the cursor.

 

 

PERF subroutine disables the perforation skip mode of a printer.

 

 

PG_BREAK subroutine, in the course of the duplex printing, allows to start a new page on the back page of the printed document, or on the new page.

 

 

PG_SIZE subroutine defines the physical page size of paper used in the course of Laser printing.

 

 

PITCH subroutine sets the horizontal motion index of a printer to the required spacing.

 

 

PORT subroutine initializes a serial port with respect to baud rate, parity, number of stop bits, and word length.

 

 

PRIME subroutine fills a string with ASCII 255 characters which screen echo as blanks.

 

 

QUERY subroutine secures keyboard input, checks for input errors, and returns the ordinal position of the response with respect to the displayed menu.

 

 

QUILL subroutine allows for positioning of cursor to any point of intersecting row column page coordinates of a printer's page and transmission of character strings originating from that point.

 

 

RADJ subroutine right adjusts text within a string.

 

 

RASTER subroutine prints graphics sketched on any screen-oriented text editor as a pattern of asterisks.

 

 

READS subroutine directs the text string to be echoed during its input into predefined screen locations. It also defines the attributes of the textual material during the input and translates control codes into special characters. The reads subroutine can be used either in the inkey mode or in the mode requiring carriage return, insert, or end key to terminate the input string.

 

 

RECEIV subroutine receives communication from the RS232C serial port.

 

 

REMOVE_D subroutine functions as the DOS command RMDIR or RD.

 

 

REND signals the end of raster graphic transmission.

 

 

RES subroutine sets the "thickness" of the laser beam painting the image on the page of a printer.

 

 

RESET subroutine will purge any partial text received by the printer and reset all programmable features to their default values.

 

 

REVERS subroutine changes the screen surface into the reverse video mode and back, depending on the value of its argument.

 

 

RIGHTM subroutine will reset the right margin of the printer's page to the column specified in its parameter.

 

 

ROWCUR subroutine positions the cursor on the printer's page vertically by moving the cursor across printing paper rows whose width is determined by the current vertical line spacing.

 

 

RSTART subroutine initiates the raster graphics transmission.

 

 

RTRANS subroutine transmits the raster graphics.

 

 

SAFE subroutine makes a file a read only file.

 

 

SCAT subroutine prints a scattergram for variable number of scales.

 

 

SCD subroutine clears the screen by scrolling the screen down and repositioning the cursor into the lower left corner of the screen.

 

 

SCENTER subroutine terminates and centers text within a string.

 

 

SCROLL subroutine imposes new attributed on selected areas of screen surface.

 

 

SECNDS subroutine measures the elapsed time in seconds.

 

 

SECRET subroutine makes screen text displays and keyboard input invisible.

 

 

SELECT function extracts parameters defined at the time of the program execution on the continuation of the program invoking line.

 

 

SETCUR subroutine moves cursor to a new location on the screen.

 

 

SHADOW subroutine changes the screen background by imposing the dark, medium, and light textures to the screen surface.

 

 

SHUT subroutine is used in conjunction with the window subroutine to close the open windows.

 

 

SIMPLEX subroutine reverses the printing from the duplex into the simplex mode.

 

 

SLEFT subroutine terminates and left adjusts text within a string.

 

 

SPACE_D returns the total, used, and available space on a drive.

 

 

SRIGHT subroutine terminates and right adjusts text within a string.

 

 

SUBscript subroutine moves the cursor on the page of a printer 20 decipoints down, writes the subscript, raises the cursor to the current line level.

 

 

SUPERscript subroutine moves the cursor 40 decipoints up on the page of a printer, writes the superscript, and lowers the cursor to the current line level.

 

 

TAB subroutine stops a screen display until a key is depressed. It checks for the extended keyboard codes preceded by the null characters and deletes the null character.

 

 

TEST function reports whether text strings are numerical, alphabetical, or alphanumerical.

 

 

TEXT subroutines sends character strings to a peripheral device, typicaly a Laser printer.

 

 

TONE subroutine generates pure tones.

 

 

TONE 0 to 9 subroutines generate phaser tone effects.

 

 

TOP subroutine specifies the number of lines to skip at the top of the printer's page.

 

 

TRANS subroutine transmits via the RS232C serial port.

 

 

TRAY subroutine allows selection of the upper or lower paper tray for paper feed to Laser printers.

 

 

UCASE subroutine converts text within a string into uppercase.

 

 

UHALF subroutine will move the cursor half line up on the page of a printer.

 

 

UNDERLINE subroutine will activate and deactivate the automatic underlining feature of a printer.

 

 

VCLINE subroutine composes and prints a line of certain length by concatenating predefined characters.

 

 

VERT_M subroutine displays a menu on the screen. Each menu item occupies a single row within the menu window. Selection of menu items is either by moving a highlighted bar by arrow keys or by pressing the capitalized letter of an item. The menu items are defined from within the program. The menu is floating and can be moved by Page Up, Page Down, Home, and End keys to any location on the screen.

 

 

VIEW_D subroutine permits viewing directories from the Fortran programs.

 

 

VLINE subroutine draws a vertical line of a specific length either in the upward or downward directions on the page of a printer.

 

 

VMI subroutine defines the vertical motion increments in 1/48 inch units on the page of a printer.

 

 

VTAB subroutine stops a screen display until a key is depressed. Message Press a key to continue is displayed in the lower right corner of the screen.

 

 

WHERE_DR subroutine returns the location of the home directory.

 

 

WINDOW subroutine saves and restores framed screen surfaces. It opens and restores multiple screen windows. It overlays screen displays with new pages of text or graphics and permits up and down pagination among them.

 

 

WRAP subroutine enables the printing of text longer than the defined line width.

 

 

WRITEN subroutine translates numbers from internal computer representation into text strings to be displayed on the screen.

 

 

WRITES subroutine formats and displays text strings. It also defines the text attributes.

 

 

X_SELECT subroutine permits to tag selected items.