RTP Series - RTP5
VERBatim - V22
Play it Again, Cam
Reader's Forum - Mark Hirst Revelation C Interface - Part 1
Reader's Forum - Numeric Precision in R/Basic - Hal Wyman
QTIPS - Use of Mouse
Reader's Forum The C Interface Part 2 - Mark Hirst (Senior Techie - ICS) Reader's Clinic
QTIPS - Using @Upper.Case and @Lower.Case with Foreign Languages
QTIPS - Local Language Sets
Sorting out Collation Sequences by Mike Pope
Reader's Clinic - Functions and Subroutines
Reader's Letters - Jim Owen
Playing with Scan Codes
Argument passing - Subroutines and Functions - Mike Pope
Reader's Forum - Numeric Precision in R/Basic - Hal Wyman
Playing with Scan Codes
QTIPS - Compiling Protection Code
QTIPS - Invalid Code and Command
QTIPS - Code/Command Help
Compiling 64K on a Shoestring by Blaise Wrenn (LexStat Systems Ltd)
SecureUser
VERBatim - V25
@ATTACK - @Files.System
Advanced Revelation Initialisation Sequence (Overview) by Mike Pope
REVMEDIA Revisted
Version 3 Technical Highlights - Customising NewApplication Creation
Play it Again, Cam
Utility Diskette # 3 - Part II
Reader's Forum - Mark Hirst Revelation C Interface - Part 1
Reader's Forum The C Interface Part 2 - Mark Hirst (Senior Techie - ICS) Reader's Clinic
VERBatim - V86
@ATTACK - @Help.Level
@ATTACK - @Window.Level
VERBatim - V126
Esc.To.Exit
Uncommon Knowledge - WC_WST_CHAR%
Reader's Clinic - Screen Width
Screen Grabber
Reader's Clinic - Slow Multivalued Screen Display
Utility Diskette # 4
Flashing Background
Message
VERBatim - V41
Screen Grabber
Window or Not ?
Popups
Play it Again, Cam
QTIPS - Video.Rw
Window or Not?
Uncommon Knowledge - WC_Vprev%
Uncommon Knowledge - WC_VWindow%
QTIPS - Query Windows - Changing Colours
Video Control
Version 3 Technical Highlights - Input.Char
Playing with Scan Codes
What's New (and un(der)documented!) In 2.12
RTP Series - RTP27
QTIPS - Printing Large Variables from the Debugger
VERBatim - V87
RTP Series - RTP50
@ATTACK - @Messages
Advanced Revelation Initialisation Sequence (Overview) by Mike Pope
Caching in on the Frames Array - Mike Pope
Vroom
QTIPS - Replacing GAS.BAR routine during PERFORM "SELECT"
QTIPS - Extended Select BY
QTIPS - PERFORM Arguments and FMT Specifications
What's New (and un(der)documented!) In 2.12
Vroom
RTP Series - RTP5
VERBatim - V15
Play it Again, Cam
QTIPS - BASIC Options
Utility Diskette # 4
QTIPS - Improving the LH_VERIFY Window
QTIPS - Interrupt Proof Error Messages
Creating Your Own Background Processes
@ATTACK - @Last.Select.Process
Reader's Forum
QTIPS - Menu Item Pre-Processing
Merge Processor
@ATTACK - @Default.Stops
@ATTACK - @Tab.Stops
QTIPS - Default Stop Lists
Background Processing
Vroom - Window Processing
VROOM - Window Processing II
Reader's Forum - Mark Hirst Revelation C Interface - Part 1
Reader's Forum The C Interface Part 2 - Mark Hirst (Senior Techie - ICS) Reader's Clinic
Utility Diskette # 4
@ATTACK - @Return.Value
QTIPS - File Handle Structure
@ATTACK - @Help.Level
Background Processing
Creating Your Own Background Processes
@ATTACK - @Index.Time
How Indexes Are Updated
File Variables
Argument passing - Subroutines and Functions - Mike Pope
RevTech Replies - Mike Pope (RevTech UK Ltd)
Symbol Table Structure
QTIPS - DOS File Names
DOS Interfacing (Part II)
VERBatim - V116
@ATTACK - @Pri.File
@ATTACK - @Rollout.File
File Variables
How Indexes Are Updated
Index Record Layouts
QTIPS - File Variable of File In SELECT Statement
QTIPS - Amending non-Attached Files
LINEAR HASH FILE STRUCTURES - Part 1
Index Flush
QTIPS - File Handle Structure

RevMedia FKB

DocumentV3I8A2
TitleReader's Forum The C Interface Part 2 - Mark Hirst (Senior Techie - ICS) Reader's Clinic
KeywordsC
RBASIC
DOS
INTERFACE
ROM
BIOS
TextIntroduction
Part 1 dealt WITH the fundamentals of creating and COMPILING a C language
module for inclusion within Rev Part 2 will examine the methods used to
move information between the R/Basic and C language environments We begin
by USING a practical EXAMPLE of a C language routine that is used by R/Basic
to return information about the DOS version of the host machine The routine
is used as a function within R/Basic to return the version as an integer

Although this is a simple EXAMPLE it shows how C code can be used to give
R/Basic code access to fundamental operating system facilities The DOS
facility that is used in the EXAMPLE is part of a set of functions that are
available to the application programmer for portable programming across the
various IBM PC computers and their clones In order to appreciate the
relevance of these functions we will briefly examine the r“le that the ROM
BIOS and DOS functions play

The ROM BIOS forms a layer between high level languages that form
applications and the underlying HARDWARE The ROM BIOS services deal with
fundamental tasks such as writing data on the screen or operating the disk
drives These services are standardised across the IBM PC family and are
always incorporated in any enhanced version of a PC or its clone This means
that software will run across a wide range of PCs and clones and their new
versions as they appear The services fall into a number of groups including
disk drives video and keyboard When a ROM BIOS service is used the
calling program does not have to be concerned about the location of the
service in memory simply that the service will perform the documented
function These basic services are enhanced by the DOS services provided by
the familiar MSDOS/PCDOS operating system and provides a rich set of
primarily disk orientated services Once again because these services are
documented and always supported in subsequent versions of DOS applications
continue to run across versions of DOS The services are all accessed by
means of an interrupt a process by which the processor stops processing
looks up an address in memory telling it where the service is found runs
it and then resumes processing

The intricacies of the ROM BIOS and DOS services and the use of interrupts
are fortunately hidden in the high level languages that we generally use
such as BASIC If the language we use is rich then many of the services
provided at a low level are available in a high level in an easy to use
form Since the high level services in our languages are in fact
collections of low level services in the ROM BIOS and DOS our programs have
portability In the circumstances where our language does not provide the
service we require we must drop down a layer and communicate more directly
with these low level services and it is for this reason that we might resort
to a C language module and Revelation C interface to extend the
functionality of R/Basic

Calling an interrupt requires the programmer to store the number of the
service he/she wants and any relevant parameters in the some of the
registers of the CPU before invoking the service AFTER the service has been
called and executed some of these registers may contain useful results
information which can be extracted The 8086 chip contains fourteen 16 bit
registers four of which are known as the scratch pad registers Termed AX
BX CX and DX they are subdivided into two 8 bit registers the high order
registers are called AH BH CH and DH while the low order registers are
AL BL CL and DL They are used as temporary storage areas and are used in
arithmetic and counting operations The EXAMPLE program demonstrates how
some of these registers are used but it is beyond the scope of this article
to explain the role of these registers in any further detail The
Programmers Guide To The IBM PC & PS/2 is recommended for further reading

The C program uses the DOS interrupt 21h (decimal 33) function 30h (decimal
48) to return the DOS version The major version number is returned in
register AL the minor version number is returned in register AH The
program multiplies the major version by 100 and adds that to the minor
version number and then returns the value as an integer to the calling
R/Basic routine

#define MSC 1
#include

main()
{
HANDLE hdl;
ah_reg = 0x30;
dosfunc();
RevStoreInteger(al_reg*100+ah_reg hdl block);
RevStoreReturnValue(hdl block);
}

The basic elements of the program should already clear FROM the previous
example namely the definition of the compilation control variable MSC
(indicating Microsoft C compiler) and the inclusion of the header file
revintrf h used to define various global VARIABLES and routines incorporated
in the C interface function LIBRARY

A number of elements are of immediate interest to the experienced C
programmer first the way in which the registers are loaded and second the
execution of the interrupt itself and so the following paragraph is of
particular interest to experienced C programmers

The use of interrupts is DONE USING a COMMON block of VARIABLES DEFINED in
the #include file revintrf h These common VARIABLES are loaded and
examined by the programmer and REPLACE the use of a REGS union The
invocation of the interrupt is performed by the dosfunc CALL which replaces
the more conventional C call intdos Another routine provided by the C
interface intfunc replaces the conventional C function int86 This routine
would be required when USING services outside of the general DOS services
(interrupt 0x21) provided by dosfunc

The program begins by declaring a special TYPE of variable known as a
structure This is used later to return information back to R/Basic using
functions provided by the interface The program then loads a common
variable ah_reg to indicate that the DOS function we wish to use is 30h
The service is then invoked by the LINE dosfunc() The function returns
data into the common VARIABLES al_reg and ah_reg and these contain the major
and minor version numbers respectively; hence 3 30 will return 3 in al_reg
and 30 in ah_reg

The result is converted into a single integer and stored in the structure
hdl USING the C interface function RevStoreInteger before making the value
available to Rev USING RevStoreReturnValue The program is compiled linked
and converted into BIN FORMAT and loaded into a Rev file (see REVMEDIA
October 1991) CALLING is done USING conventional R/Basic procedures The
following R/Basic code illustrates how this can be done


SUBROUTINE C_TEST
DECLARE FUNCTION EXAMPLE2
DOS = EXAMPLE2()
CALL MSG('DOS Version is %1%' '' '' DOS/100)
RETURN


The NEXT part in the series will demonstrate the PASSING of parameters to
the C language module and the CALLING of R/Basic routines FROM the C
environment

Bibliography
Readers interested in finding out more about the ROM BIOS and DOS services
and the use of interrupts will FIND the following essential reading: The New
Peter Norton Programmer's Guide To The IBM PC & PS/2 Peter Norton and
Richard Wilton Microsoft Press ISBN 1 55615 131 4

Details on the screen and GRAPHICS services are explained in greater detail
in the following book: Programmer's Guide To PC And PS/2 Video SYSTEMS
Richard Wilton Microsoft Press ISBN 1 55615 103 9

A number of texts are available on C programming the most definitive of
which is: The C Programming Language Kernighan & Ritchie Prentice Hall
ISBN 0 13 110362 8


(Volume 3 Issue 8 Pages 5 7)
[revmedia/copyrigh.htm]

Page last modified: 08/02/03