Microsoft KB Archive/68121

= Checking Game Port with CALL INTERRUPT If STICK & STRIG Fail =

Article ID: 68121

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft Visual Basic for MS-DOS
 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q68121



SUMMARY
If you are experiencing problems with Basic's game port (or joystick) routines, such as STICK or STRIG, this article provides information that may help you to diagnose whether the symptom is the result of a ROM BIOS problem. This information applies only if your computer has an Intel 80286 or 80386 microprocessor chip.



MORE INFORMATION
The way in which Basic SIC handles joystick commands (which include the STICK function, STRIG function, and STRIG statement) depends on which kind of Intel microprocessor chip the computer uses. If the computer has an 8086/8088 or 80186/80188 microprocessor, the joystick commands talk directly to the hardware without going through the ROM BIOS. If the computer has either an Intel 80286 or 80386 microprocessor, the joystick commands are handled by going through ROM BIOS Interrupt 15h. Because of errors in some ROM BIOS joystick functions on some computers, STICK or STRIG may not work at all, or may not work properly.

If your computer has an Intel 80286 or 80386 microprocessor chip, you can use the code example below to determine if the problem you are having is ROM BIOS related. The program accesses the game port by directly calling INTERRUPT &H15 with function &H84, which is the ROM BIOS joystick routine. If the problem still occurs when calling the ROM BIOS joystick routine directly, then the problem is with the computer's ROM BIOS joystick function and not with Basic's STICK or STRIG routines.

To access the ROM BIOS joystick routines, you call Interrupt &H15 (21 decimal). The AH register should contain &H84 (132 decimal) to indicate the game port support function.

Register values prior to issuing interrupt &H15 should be the following: AX = &H8400   ' This puts &H84 in the AH register. DX = 0 or 1 If DX = 0, this indicates to &quot;read switch settings.&quot; If DX = 1, this indicates &quot;read resistive inputs.&quot;

Depending on the value of DX when you make the call, different parameters will be returned by the interrupt. If DX = 1, then upon returning from Interrupt &H15, the registers will contain the following: AX = Port1 x coordinate BX = Port1 y coordinate CX = Port2 x coordinate DX = Port2 y coordinate If DX = 1, then bits 4 - 7 are used to represent switches. The AX register will contain the switch settings in bits 4 through 7. BX, CX, and DX will be unchanged.

Code example
The following code example shows how to use the CALL INTERRUPT routine to directly call the ROM BIOS joystick routines.

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.

To run this program in the VBDOS.EXE environment, you must invoke the VBDOS.EXE environment with the /L switch to load the default Quick library:

VBDOS.EXE /L

Note: The INTERRUPT routine is considered an external subroutine by the compiler. The routine is located in the files QB.LIB and QB.QLB for QuickBasic for MS-DOS 4.x and in QBX.LIB and QBX.QLB in Basic PDS for MS-DOS 7.x.

Programs that execute a CALL INTERRUPT statement when compiled in the QB.EXE editor require the presence of the QB.QLB or QBX.QLB Quick library. This means that QB.EXE and QBX.EXE must be invoked with the /L option, which automatically loads the correct Quick library.

Compiled programs that execute CALL INTERRUPT must be linked with the file QB.LIB or QBX.LIB. More information on the use of CALL INTERRUPT can be found under the CALL statement in the language reference manual for each Basic product. For more information on how to use CALL INTERRUPT, query on the following words:

CALL and INTERRUPT and application and note and QuickBasic

JOYSTICK.BAS
' This code prints to the screen the values of AX, BX, CX, DX registers ' when interrupt &H15, function &H84 is called with given values in the ' DX register. This will allow you to observe the values ' corresponding to a specific action taken on a given device attached ' to either of the two game ports supported by an IBM or compatible.

' Use the following include file for Visual Basic for MS-DOS: REM $INCLUDE: 'VBDOS.BI' ' Use the following include file for QuickBasic for MS-DOS: '$INCLUDE: 'QB.BI' ' Use the following include file for Basic PDS for MS-DOS: '$INCLUDE: 'QBX.BI'

DIM inregs AS RegType DIM outregs AS RegType inregs.ax = &H8400         ' Puts &H84 in AH register. DO inregs.dx = 1         ' 1 - read resistive inputs. CALL INTERRUPT(&H15, inregs, outregs) CLS LOCATE 16, 10: PRINT &quot;RESISTIVE INPUTS: (STICK)&quot; LOCATE 19, 20: PRINT &quot;AX&quot;,&quot;BX&quot;,&quot;CX&quot;,&quot;DX&quot; LOCATE 20, 20: PRINT outregs.ax, outregs.bx, outregs.cx, outregs.dx

inregs.dx = 0         ' 0 - read switch settings. CALL INTERRUPT(&H15, inregs, outregs) LOCATE 6, 10: PRINT &quot;SWITCH SETTINGS: (TRIGGER)&quot; LOCATE 9, 20: PRINT &quot; AX&quot; LOCATE 10,20: PRINT outregs.ax      ' Only bits 4 - 7 are important. LOOP WHILE INKEY$ = &quot;&quot;          ' Loop till any key is pressed. END

