|
Optron #32
22 октября 1999 |
|
Likbez - Assembler view from afar: Working with external devices. Reading data from port. Write commands to the port.

Assembler - a view from afar
Continued.
Beginning at | | 20, 21, 24, 25, 28-30
{} Infarh, 1999
Working with external devices
These include the keyboard, tape recorder, a printer, a lot
more then (depending on specific option). So how does a
processor exchanges information with them? Obviously, they are
not incorporated directly a data bus (SM). Between the external
unit (VU) and the processor is a
thing as a "port".
Do not think that I'm talking about the sea
port to tell you I will! Actually
"Port" - a device that the command processor connects to a
certain SM BY. Which - depending on its address. For example,
the port has an address kempston joystick'a # 1F, beeper - #
FE, etc.
Theoretically, the number of ports can
be 65536, but in practice this number is much smaller and
depends on the hardware implementation of your Speccy. It is
important method of decoding the port, ie, definition of what
UW currently has be connected to the SM. For example, although
the port joystick has the number # 1F, its decoding
usually occurs only in the category of A5
Address Bus (SHA).
We consider this process in detail. Sign of the port, the low
signal IORQ. What process happens (read from the port or write
to it) tell low level signals or RD
WR, respectively. And if the combination of signals per se
(IORQ = 0; RD = 0) signal A5 Sha has a low level, will be
selected joystick port. In this case, the values read from
it, appears in the SM. Record is similar, but uses
signal WR and the number of SM enters the port.
And here is how to manage all these signals without the aid
of a soldering iron and plenty of beer? To this end, the
processor has special teams that I have now demonstrate.
Reading data from port
Certainly in BASIC you met the team IN. So, in the assembly
have exactly the is the same. It is present in these ways:
IN A, (n)
IN r, (C)
The first version of the command reads
from the port, low byte address is written in parentheses, and
the senior - in the battery. Bytes read from the port will be
placed in the "A". In order to help this command to read the
state kempston joystick'a, we need to write it as follows:
IN A, (# 1F)
As I said earlier, decoding port # 1F
occurs, usually only one discharge IRA, so the contents of
register "A" can be anything. Show off to all,
that your computer has 256 ports
joystick!
Now turn to the second option.
As receiver for the read bytes
is "r", which in practice may be
one of the registers:
A, B, C, D, E, H, L
Port address is placed in the register pair BC. This option
is most useful if you should use the full addressing
port.
For example, consider reading the keyboard.
Keyboard port addresses differ only in
significant byte, and the younger all the time is
# FE. What poluryad currently being read, seen from the panel:
Poluryad Address
port
Space ... B 7FFE
Enter ... H BFFE
P. ...... Y DFFE
0 ....... 6 EFFE
1 ....... 5 F7FE
Q. ...... T FBFE
A. ...... G FDFE
CS ...... V FEFE
One of the features read from the port
the keyboard is that the lower bits
obtained values refer to the extreme
poluryada keys. Narimer, if we make something like
LD BC, # EFFE
IN A, (C)
then the resulting byte will have the following
value:
x x x 6 7 8 9 0 Key
D7 D6 D5 D4 D3 D2 D1 D0 Bit
Bits D7, D6, D5 are lucky - they had
the honor to remain unused. The fact
that some key is pressed, we learn
as the corresponding bit - he
will be cleared. We extend the above
example:
LD BC, # EFFE; poluryad 6 ... 0
IN A, (C); reading status
RRCA; check
JR NC, ZERO; pressed "0"
; Continue to work
.....
.....
ZERO
That's how proshodit work with the keyboard. Does not that
all that simple?
Now let's consider the reverse process -
Write command to port
They are very similar to a read command.
Here's a look:
OUT (n), A
OUT (C), r
Entry to the port is similar to reading, to
At least, that relates to the transfer parameters.
For example, consider the entry to the port # FE.
Is charged with not one problem, and immediately
several: lower three bits determine
Border color, bit D3 sends a pulse on the
MIC jack and the EAR, and bit D4 includes or
off the beeper.
So, let's say you have to install red curb. To do this,
the following:
LD A, 2
OUT (# FE), A
A few words about the bit D4. Whenever
you translate it into its opposite state (of course, sending
the result port), the internal speaker produces a short
-clicking. Thus, by manipulating these
bit at a certain speed, you can
create simple sounds.
So, today everything seems to be ...
What? Ah, yes, I completely forgot about the impact on
Flags! Well, let's look at what we do
here ...
Mnemonic Flags
operation
C Z P / V S N H
OUT (n), A. . . . . .
OUT (C), r. . . . . .
IN A, (n). . . . . .
IN r, (C). x P x 0 x
As you see, everything here is quite simple.
Well, now is really everything.
So, until next time!
To be continued ...
Other articles:
Non Possumus - Network ... What is it really? |
ZX-waggons - Overview of electronic media: Nicron 112-113, Polesie 11, ZX-News 49, Born Dead 0D. |
entire life of the game - Operation RR (End of the Adventures of the latter). |
Likbez - Assembler view from afar: Working with external devices. Reading data from port. Write commands to the port. |
Advertising - Advertisements and announcements ... |
Category X - Solemn pointovka. |
Similar articles:
В этот день... 15 November