Example of How to Call Basic SetUEvent from C; ON UEVENT GOSUB
ID: Q69159
|
The information in this article applies to:
-
Microsoft Visual Basic Standard and Professional Editions for MS-DOS, version 1.0
-
Microsoft QuickBASIC for MS-DOS, versions 4.0b, 4.5
-
Microsoft BASIC Compiler for MS-DOS, versions 6.0, 6.0b
-
Microsoft BASIC Professional Development System (PDS) for MS-DOS, versions 7.0, 7.1
SUMMARY
Page 310 of the "Microsoft Basic 7.0: Programmer's Guide" states
the following:
Trapping a user-defined event involves writing a non-Basic
routine, such as in Microsoft Macro Assembler (MASM) or C, ....
On the same page, this statement is followed by an example of how to
set up the ON UEVENT GOSUB routine in assembly language.
This article shows how the same example can be written in the
Microsoft C language by using the SetUEvent function.
MORE INFORMATION
Use the following command to compile the C program listed below:
CL -Od -AM -c uevent.c
Use the following command to compile the Basic program listed below:
BC /O/V Basic.BAS;
Link the programs together with the following command:
LINK /NOE Basic+UEVENT, UEVENT.EXE;
When the program is executed, the line "Arrived here after 4.5
seconds" will print every 4.5 seconds.
Note: The C program must be compiled with the medium memory model
because the DS register must point to Basic's DGROUP space when
SetUEvent is called.
Basic Code Example, Basic.BAS
' To try this example in VBDOS.EXE:
' 1. From the File menu, choose New Project.
' 2. Copy the code example to the Code window.
' 3. Press F5 to run the program.
DECLARE SUB SetInt
DECLARE SUB RestInt
' Install new interrupt service routine:
CALL SetInt
' Set up the Basic event handler:
ON UEVENT GOSUB SpecialTask
UEVENT ON
DO
' Normal program operation occurs here.
' Program ends when any key is pressed.
LOOP UNTIL INKEY$ <> ""
' Restore old interrupt service routine before quitting:
CALL RestInt
END
' Program branches here every 4.5 seconds:
SpecialTask:
' Code for special task goes here, for example:
PRINT "Arrived here after 4.5 seconds"
RETURN
C Code Example, UEVENT.C
' To try this example in VBDOS.EXE:
' 1. From the File menu, choose New Project.
' 2. Copy the code example to the Code window.
' 3. Press F5 to run the program.
DECLARE SUB SetInt
DECLARE SUB RestInt
' Install new interrupt service routine:
CALL SetInt
' Set up the Basic event handler:
ON UEVENT GOSUB SpecialTask
UEVENT ON
DO
' Normal program operation occurs here.
' Program ends when any key is pressed.
LOOP UNTIL INKEY$ <> ""
' Restore old interrupt service routine before quitting:
CALL RestInt
END
' Program branches here every 4.5 seconds:
SpecialTask:
' Code for special task goes here, for example:
PRINT "Arrived here after 4.5 seconds"
RETURN
C Code Example, UEVENT.C
#include <dos.h>
extern pascal SetUEvent(); // Define SetUEvent, which is in
// the Basic run-time library.
void (_interrupt _far *OldInt) (void); // The old interrupt vector.
void _interrupt _far EventHandler (void); // The UEVENT handler.
char TimerTicks = 0; // Number of ticks elapsed.
void pascal SetInt() // Set up the interrupts
{ // to point to the UEVENT
OldInt = _dos_getvect(0x1C); // handler.
_dos_setvect(0x1C, EventHandler);
}
void interrupt EventHandler() // This is the UEVENT handler.
{
if (++TimerTicks > 82) // Check to see if 4.5 seconds
{ // has elapsed (18.2
TimerTicks = 0; // ticks = 1 second).
SetUEvent();
}
_chain_intr(OldInt); // Continue through old
} // interrupt routine.
void pascal RestInt() // Restore old interrupt
{ // when done to avoid
_dos_
setvect(0x1C, OldInt); // conflicts after exit.
}
Additional query words:
VBmsdos QuickBas BasicCom 1.00 4.00 4.00b 4.50 6.00 6.00b 7.00 7.10
Keywords :
Version : MS-DOS:1.0,4.0b,4.5; :6.0,6.0b,7.0,7.1
Platform : MS-DOS
Issue type :