Hardware Reference
In-Depth Information
This is an extremely powerful feature and one that helps to make mixed language
programming very straightforward. The output produced by the program is
shown in Figure 6.6.
Accessing the I/O ports
in DOS or Windows 9x
environments
Direct port access from BASIC or assembly language is eminently feasible from
a true DOS environment. It is also possible using the Windows 95 or Windows
98 operating systems. Unfortunately, with modern 32-bit operating systems
this no longer applies (this topic is further developed later in this chapter when
we discuss methods of accessing I/O ports from within the Windows Protected
Mode environment on page 215).
The following PowerBASIC 3.5 program demonstrates alternative methods
of directly accessing the PC's parallel printer port. This program will operate
from a true DOS prompt or from a DOS Window in a Windows 9x operating
system:
' Title: portio.bas Version: 0.5 Modified: 25/08/04
' Language: PowerBASIC 3.5
' Function: Demonstrates methods of writing to and
' reading from I/O ports. Please see text for information
' about operation in a Windows XP environment
' For test purposes port addresses are currently set to LPT1
' Data data port = &H378 (output) : Status byte = &H379
(input)
'
color 15, 1
division$ = String$(40, Chr$(205))
'
' Display menu and get option from user
'
do
cls
print division$
print "I/O port read/write demonstration"
print division$
print "Select an option..."
print " [A] for in-line assembly language"
print " [B] for BASIC"
print " [Q] to quit"
do
r$ = Ucase$(Inkey$)
loop until r$ <> "" and instr("ABQ", r$)
print division$
if r$ = "Q" then goto shutdown
if r$ = "A" then gosub assem
if r$ = "B" then gosub basic
loop
'
' Demonstration of BASIC access to I/O ports
'
basic:
status% = inp(&H379) ' read value of status byte
print "Using BASIC: status byte (hex) = "; hex$(status%)
out &H378,&HAA ' write 10101010 to data port
print "Using BASIC: port data = 10101010"
delay 2
Search WWH ::




Custom Search