feather
ZXNet echo conference «code.zx»
From Mihail Zharov → To All 13 March 2001
Hello All!
I don’t remember in which echo this was recently discussed...
Then I accidentally came across something like this on some small disks:
╒═══< Begin file: lp .txt >════════════
Light Pen is an information input device. It is distinguished by its high
input speed limited only by the floor reaction
user and ease of control - the operator just needs to point with a light pen
section of the screen and confirm the selection by pressing the buttons
ki.
The light pen turned out to be not a convenient enough control device to
become equal in popularity to devices like "MOUS"
E", "KEYBOARD" and even "JOYSTICK". However, the light pen is still quite often
found under the guise of a pistol for various games
first video consoles. Previously, it could often be found as part of
professional computers (mainly used
or in graphical software packages).
I consider the main advantage of a light pen to be its elementary device (in my
execution - it is a photocell, a button and the only
transistor. Moreover, all this is connected to the standard Kempston input
joystick. I don’t require any special modifications to the computer
Yes.). True, it is based on quite complex calculations and many
experiments. The advantages also include a slight
The amount of memory required to accommodate the handler program (20-100 bytes)
and relatively short device response timea - from 0.000009157 sec to 0.017 - 0.02 sec. (depends on the screen area)
The main disadvantage is because my requirements for the light pen were low
(as long as it works), it has low resolution
stu: 7*312 segments. The explanation for this strange split screen follows:
below.
In order to understand the principle of operation of a light pen, you need to remember
system for constructing an image on a monitor screen (in
in our case, an ordinary black and white TV).
It is known that 25 frames are displayed on the TV screen in 1 second. Really
to extinguish the flickering effect, h is used
interlaced image construction (see Fig. 1). This means that for 1/25
seconds, two identical pictures are drawn on the screen, but
for the first 1/50 sec. 1,3,5,...,613 lines of the screen are displayed, and for the second 1/50
sec. 2,4,6,...,614 lines. Therefore, in future
In accounts, we will conventionally assume that the TV draws 50,312 per second
line frames.
Let's calculate the speed of the light beam moving across the screen during construction
frame:
312 lines in 1/50 sec., which means 1 line - 1/(312*50) = 1/15600 (sec.).
Everything is simple with the screen, but how does the pen itself work?
The principle of the pen is as follows: the computer just needs to calculate the time
elapsed from the beginning of screen formation (bright dot on
begins its movement and is now in the upper left corner of the screen) beforemoment when the light beam is recognized by the photoelectric
ment (in the light pen).
Let’s now make a list of problems that need to be solved for successful work
pen:
1). Make the program so that it starts working simultaneously with the start
screen construction.
2). Solve the signaling problem, i.e. how a photocell will indicate arrival
light beam.
3). Create the fastest counter.
4). Using the time calculated by the time counter, calculate the coordinates of the pen.
Let's solve them...
1).
This problem would be impossible to easily solve if computers did not have
interrupt system (this applies to any computer
eram).
The fact is that every 1/50th of a second a special generator in the computer
produces a signal synchronizing the operation of the TV and
special computer circuit, which, in accordance with the contents of video memory
controls the intensity of the light beam, resulting in
That's why we see symbols, graphics, etc. on the screen. and different
brightness So, the computer generates an impulse that
Forces the TV to place the light beam in the upper left corner of the screen. This
the same impulse is sent to the central processor, the cat
This interrupts the current task and transfers control to utilities such as
like: keyboard polling, mouse polling and (or) program
mothers, which we ourselves can write and place in our memory in a special way.
2).Everything is very simple. When the photocell “catch” the ray, it will generate electricity
impulse, small but sufficient to
the transistor (see Fig. 2) closed the "RIGHT" key of the Kempston Joystick.Others
in words, the photocell will simulate pressing "RIGHT"
Oh."
3).
Since the counter program must work very quickly, we will write it in machine code
code (for convenience in Assembly), and also potb
Here are the fastest commands:
start of the program Let's set the values of some registers:
DE is a counter, and 0 is written to it
HL - loop start address (needed to speed up work)
The program polls the "FIRE" button of the Kempston joystick and, if it is
pressed, will go to the counter.
LD HL,LOOP
LD DE,#0000
IN A,(#1F)
BIT 4.A
RET Z
the counter itself polls "RIGHT" and if not pressed (i.e. the signal is not yet
came) increases the counter.
LOOP IN A,(#1F) 11 measures
RRA 4 bars
RET C 5 bars
INC DE 6 bars
JP (HL) 4 bars
total - 30 processor cycles or 30/3500000 seconds.
Now, knowing the speed of execution of one cycle of our counter, knowing the speed
movement of the light beam (see above) we can estimate
there is the “resolution” of the pen, i.e. how many times in 1/50 sec. photocell will scan
screen.
(1/50)/(30/3500000)=2333.333(3) conditional segments.
2333/312=7.478632479 horizontal segments312 vertical segments.
4).
Everything is quite simple here. Knowing the time and knowing the solvability of 7 * 312 (precisely 7, not 7.5
(reason below)), you can easily calculate the coor
segment dinata in any programming language using the formulas:
Y(vertical)=INT ( time/7 )
X(horizontal)=time-Y*7
Well, decide for yourself what to do with these coordinates. You can depict
shot, you can draw a picture, you can activate the item
menu - it depends only on your imagination.
What else can you say about a light pen? The main thing, perhaps, is that real
light feathers are very different from the one proposed by many
yu models. For example, all calculations are carried out not by a program (like mine), but
special scheme. The central processor remains
just take ready-made coordinates. This improvement entails
a strong complication of the pen design, requiring special modifications
computer skills, etc.
The development of the light pen opened up many interesting problems for me. They
relate to computer science, physics, electronics and even
iology.
During tests of the pen, I noticed that its resolution was not 7.5, as it turned out
calculations, but a little more than 7 (7 - 7.3). This means that
o The clock frequency of the computer is not 3.5 MHz, as the reference books say, but 3.276 - 3.4
MHz.
The calculations I used to develop the pen allowed me to repeat
wonderful graphic effect "MULTYCOLOR" foundexisting back in the 80s, but practically not used until recently. Its
the gist is this:
On my Spectrum and many other low resolution computers
it is impossible to display more than one in one familiar place (8*8 pixels)
e two colors. This is a tragedy, especially considering that the screen consists of
32*24=768 acquaintances. "MULTYCOLOR" allows you to display
at least all 16 colors at once in one familiar place. It is based on the fact that during
transferring information from video memory to the screen, we can
Let's have time to change its contents.
Example:
Suppose we want to print "A" in blue, yellow, white colors on a black background (in
strip).
1. We record information about “A” drawn in blue into the video memory.
2. We are waiting for the beam to arrive. We are waiting for the moment when the beam draws two
the top line "A" in blue.
3. Quickly change the color information in memory from blue to yellow.
4. Repeat point 2, but with respect to the next two lines in yellow.
5. Quickly change the yellow color to white.
╘═══< End file: lp .txt >══════════════
Happy. Michael.