Re: WANTED: "BASIC Forum" References
- From: Bill H <bill@xxxxxxxxx>
- Date: Fri, 26 Jun 2009 04:18:46 -0700 (PDT)
On Jun 25, 3:49 pm, "Mr Emmanuel Roche, France" <roche...@xxxxxxxxxxx>
wrote:
Today, while searching for something else, I found an old photocopy
about the INP, OUT, and WAIT commands of Altair 8K BASIC. Since this
is not a very common subject in microcomputer magazines, I retyped it
and had a problem: I did not write down from which US magazines I got
it. Anybody remembers a "BASIC Forum"? ("KiloBaud"?)
Yours Sincerely,
Mr. Emmanuel Roche, France
IOWAIT.WS4 (= Inp, Out, WAIT commands of BASIC)
----------
- "Data to & from Cassette"
Dick Whipple & John Arnold
"The BASIC Forum", ? Magazine, ? 19??, pp.13-14
(Retyped by Emmanuel ROCHE.)
In this month's "BASIC Forum", we will discuss a question
submitted by George Haller of Naples, Florida. He is interested
in an explanation of a comment he found in the "Altair BASIC
Reference Manual" indicating that BASIC program data can be
saved on cassette tape for future use. So, we are going to
discuss how this is done.
The software used to drive a UART board cassette tape system is
generally written in machine language to achieve maximum data
rate advantage. It is possible (and perhaps a good exercise) to
write the cassette routines in BASIC itself. Since BASIC
statements take longer to execute, the overall data rate will be
lower.
In order to read and write the data values to the system I/O
ports, the BASIC interpreter used must have certain specialized
statements. Altair 8K BASIC, for instance, has the INP, OUT, and
WAIT statements that can be used for this purpose. Since some
readers may not be familiar with these statements, we will
present a brief description of each in Program A.
INP (I)
A function that reads the data byte available at the
input port specified by the variable (or constant) I.
The input data value will range from 0 to 255 decimal
(255 is the maximum decimal value of an 8-bit binary
number).
OUT I,J
The data byte J is output to port I. Both I and J must
have values between 0 and 255 decimal.
WAIT I,J,K
This statement inputs data from port I, eXclusive-OR it
with K, then ANDs J with the result. The statement
following the WAIT is delayed until the logical
operations produce a non-zero value. K is optional and,
when not present, is assumed to be zero.. The AND
operation is used to select the bit or bits whose value
is to be monitored. The eXclusive-OR is used to
selectively invert bits within the inputted word. I, J,
and K must have values between 0 and 255 decimal.
Program A.
Consider first the problem of writing data to a cassette tape.
Let us first assume that the cassette interface has two ports:
one a status port, the other a data port. Further, assume bit 7
on the status port is connected to the Transmitter Buffer Empty
(TBE) flag of the UART. Thus, whenever the UART is ready to
receive a new data byte for transmission, bit 7 will go to logic
1. While the UART is transmitting a data byte, bit 7 will be
low. When writing a BASIC program to output data to the cassette
interface, some means must be provided to hold-up execution
while the TBE status flag is low. This is easily done with the
WAIT command. Suppose the status port is 6 and the data port is
7. The BASIC program (Program B) will output a data byte to the
cassette again and again.
5 LET x = 65 : REM ASCII for "A"
10 WAIT 6, 128
20 OUT 7, x
30 GOTO 10
Program B.
The program, when executed, proceeds in this manner. Statement 5
sets the ASCII value for the letter A into the variable named X.
At statement 10, the data at port 6 is inputted and eXclusive-
ORed with 00000000 binary (the default option; i.e., 0 assumed,
since the third WAIT argument not specified). Any bit eXclusive-
ORed with 0 remains unchanged, while a bit eXclusive-ORed with 1
is complemented. In the case above, all bit positions remain the
same. The data byte is then ANDed with 128 decimal, which is
10000000 binary. If bit 7 is a logic one (indicating that the
UART is ready to receive a new value), the result of the AND
operation will be non-zero and execution will proceed to line 20
of the program. Otherwise, the status port will be read again
and again, until bit 7 (TBE) goes to 1.
In some cassette interfaces, TBE is inverted before being
presented to the status port. In such a system, bit 7 will go to
logic zero when the buffer is empty. For the WAIT to work
correctly in this case, it is necessary to complement bit 7
before the AND operation. This is accomplished by changing line
10 as follows:
10 WAIT 6,128,128
The difference being that the status byte is eXclusive-ORed with
10000000 (128 decimal), which has the effect of complementing
bit 7. This extra step negates the inversion of TBE within the
interface.
Continuing with the program at line 20 -- the data stored in
variable A (65 decimal or 01000001 binary) is outputted through
data port 7. In line 30, program execution is returned to line
10, where it again holds up if necessary until the previous data
byte has been transmitted.
Data stored in an array can be outputted a byte at a time, using
the subroutine in Program C.
95 ...
100 REM B is array containing data
105 FOR i = 1 TO 10
110 WAIT 6, 128
115 OUT 7, b (i)
120 NEXT i
125 WAIT 6, 128
130 OUT 7, 255
135 ...
Program C.
Statement 130 is used to place an end-of-data character on the
tape. This can be used by the read program to detect the end of
a block of data. The choice of 255 decimal (11111111 binary) is
purely arbitrary. Any non-conflicting value can be used.
Now that we have made a cassette tape with BASIC, let us write a
program to read the data back. When reading data from a cassette
with a UART-based system, there is another status flag called
the Read Data Available (RDA) that goes high to indicate when a
data byte has been received by the UART. It is necessary to
monitor this bit and wait for it to go to logic 1 BEFORE
actually inputting from the data port. Here again, we find ready
use for the WAIT command.
Consider the following program fragment:
95 ...
100 WAIT 6, 1
105 LET x = INP (7)
110 ...
In line 100, the status port is read and, as before, eXclusive-
ORed with 00000000 binary, resulting in no change to any bits.
The status byte is then ANDed with 00000001, where it is assumed
that RDA is available on bit 0. So long as this result is 0
(resulting no data is available from the UART), the program
remains at line 100, reading the status port. When bit 0 goes to
1, the program will proceed to line 105, where the data port (7)
is read and its value placed in variable X. Ths completes the
reading of a single byte. As before, if RDA is electronically
inverted in the cassette interface, line 100 would be modified
as follows:
100 WAIT 6, 1, 1
If several values are to be read from the tape, a loop can be
set up to place the value in an array. Program D illustrates
this technique.
200 ...
205 LET i = 1
210 WAIT 6, 1
215 LET b (i) = INP (7)
220 IF b (i) < 255 THEN i = i + 1 : GOTO 210
225 ...
Program D.
As each byte is read and stored, a check is made for the end-of-
data character -- in this case, 255 decimal. When it is
encountered, program execution drops to line 225. Otherwise,
data continues to be read from the tape into array B.
A problem can arise due to the difference in execution time of
the BASIC statements in the read and write programs. The actual
data rate for a single byte is determined by the UART clock on
the cassette interface. The time between bytes, however, is a
function of the execution delay in the BASIC cassette write
program. It is important to be sure that the delay in the write
routine is equal to or slightly greater than the read routine
delay. Otherwise, data may be lost while reading the tape. It
may be necessary to add dummy or do-nothing statements to the
write routine. Such a delay can be realized by adding a line to
the write program, such as:
FOR j = 1 TO n : NEXT j
where N is chosen to give the necessay delay.
A possible application for the techniques described above
appears below. The program can be used to dump consecutive
memory locations to a cassette tape. Use is made of the Altair
8K BASIC PEEK function, which permits examination of the data
byte stored in specified memory locations.
10 INPUT a, b
20 FOR i = a TO b
30 WAIT 6, 128
40 OUT 7, PEEK (i)
50 NEXT i
The beginning and ending addresses of the block of memory to be
dumped are defined by variables A and B.
The memory image can be read back into memory using the Altair
8K BASIC POKE command. An example program appears below:
10 INPUT a, b
20 FOR i = a TO b
30 WAIT 6, 1
40 POKE i, INP (7)
50 NEXT i
It must be stressed that all of the programs which we have
discussed so far will read or write only the contents of those
variables which represent positive integer values between 0 and
255 decimal. Reading and writing Floating-Point or string data
is somewhat more complex and will be treated in the next "BASIC
Forum". We would encourage readers to experiment with their
BASIC systems and try some of the techniques discussed in this
article. A hint on saving Floating-Point numbers: convert the
numbers to string data and then write the string characters one
by one to tape.
Please remember the "BASIC Forum" is for the exchange of ideas
in BASIC language programming. Send in your input, so that it
can be shared with others. Address correspondence to:
BASIC Forum
305 Clemson Drive
Tyler
TX 75703
EOF
Interesting read. Never used the wait command before but it seems to
be a powerful little statement.
Bill H
.
- Follow-Ups:
- Re: WANTED: "BASIC Forum" References
- From: CBFalconer
- Re: WANTED: "BASIC Forum" References
- From: Tom Lake
- Re: WANTED: "BASIC Forum" References
- References:
- WANTED: "BASIC Forum" References
- From: Mr Emmanuel Roche, France
- WANTED: "BASIC Forum" References
- Prev by Date: Re: ASM-to-WS4 File Converter
- Next by Date: Re: WANTED: "BASIC Forum" References
- Previous by thread: WANTED: "BASIC Forum" References
- Next by thread: Re: WANTED: "BASIC Forum" References
- Index(es):
Relevant Pages
|