27.01.2015 Views

titus-larsen-titus-1981-apple-interfacing

titus-larsen-titus-1981-apple-interfacing

titus-larsen-titus-1981-apple-interfacing

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Gei'!eral-fi!Jrp@S('; I/ 0 Commaru:li:><br />

Although there are some general-purpose I/0 commands in the<br />

INTEGER BASIC interpreter program for the Apple computer, for<br />

this book we have chosen to use what we consider to be the more<br />

flexible APPLESOFT BASIC interpreter program If you wish to<br />

convert your Apple computer to this program, a local Apple computer<br />

dealer can assist you.<br />

The two If 0 device commands are PEEK and POKE. They are<br />

used to transfer data to an external device from the computer<br />

(POKE), and to the computer from an external device (PEEK).<br />

There is a specific format for these instrnctions that must be used if<br />

the instructions are to operate properly.<br />

Input and output devices will be referred to as ports. Thus, an output<br />

device will be an output port and an input device will be an inport.<br />

This is standard nomenclature used throughout the microcomputer<br />

industry.<br />

The output instruction, POKE, must specify the address of the<br />

I/0 device that is to be involved in the transfer of data and also the<br />

value that is to be transferred to the addressed device. The actual<br />

format for the POKE instruction is POKE, x,y, where the x value<br />

represents the decimal address of the output device that is to receive<br />

the data value, y. The data, y, must also be a decimal number. Since<br />

the 6502 microprocessor chip can address 65536 memory locations,<br />

the address must be within the range of 0 to 65535, inclusive. The<br />

data value must be within the range of 0 to 255, inclusive, since the<br />

computer uses an 8-bit data bus for all data transfers, and the largest<br />

number that can be transferred on such a bus is 255.<br />

The value 215 is sent to output port 12684 in the following statement:<br />

POKE 12684,215.<br />

The input instruction, PEEK, is similar to the POKE instruction,<br />

except that no data value is incorporated into the command. VVe are<br />

interested in determining the value present at the specific input device,<br />

so only the decimal address of the input device is specified;<br />

PEEK ( x), where x is the decimal address of the input device.<br />

It does little good to input a value without doing something with<br />

it, so the input command is always incorporated in a complete statement,<br />

rather than being a statement by itself. An example of this is<br />

Q= PEEK ( 34579) .<br />

In this case, the variable, Q, is assigned the decimal value that has<br />

been input from device 34579. It is important that you remember to<br />

enclose the address of the input device in parentheses.<br />

Whenever a PEEK command is used, the value that is input will be<br />

between 0 and 255, :inclusive. Again, this is due to the limitation of<br />

8-bit transfers.<br />

l )'

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!