Deja Vu #09
13 ноября 1999

Coding - coding for Dummies: More about one of the ways to survey the keyboard.

<b>Coding</b> - coding for Dummies: More about one of the ways to survey the keyboard.
(C) SKL-KEEPER aka Kolesnikov

    Leading the section "Coding for Dummies
__________________________________________



   For Dummies. " Detail about one of the

       ways to survey the keyboard.



   For Beginners "kodit" their programs
inevitably raises the question of whether and how

              to organize a poll the keyboard
              algebra? For without this, no

              program will not do, ka
              Coy would be easy, it was not!

                 There are several ways

              Poll the keyboard, for example,

              using the system

              variables KSTATE and LASTK.

              I think that these methods are unlikely

              whether the cause difficulties in

              understanding why they are not

              should stop. But

              way to poll the keyboard as

              external port, though exposition
              wives in a number of computer publications, but 
presented as something not very intelligible, and may not be 
very clear. Here at there we stop.


   This method, unlike the above, you can apply for the 
organization moving an object on the screen simultaneously two 
directions, or, for example, to monitor keystrokes 
simultaneously with another key (arrow keys, etc.). 

   Poll the keyboard in this way is
the only acceptable if
interruption is prohibited. Incidentally, this fact can be used 
to accelerate of your program. Put a DI before

poll the keyboard and the processor will not be 50
times a second call a procedure KEYSCAN.
A small, but time saving!
Just do not forget after you exit the procedure include 
interrupt command EI ... 

   Let me remind you that the poll the keyboard in this way is 
the external port 254 (# FE HEX). Since the address of the 
keyboard port is a two-byte number, then # FE is the low byte 
address port, and the senior must be pre-installed in the 
battery. 

   Analyzes five bits. When
Moreover, if a key is pressed, the bit is turned off
(Conversely, in comparison with the Kempston joystick). In this 
method checks the status of one half of a number keypad. 


      Consider Figure keyboard:

N: BITA 0 1 2 3 4 4 3 2 1 0

                                      N_
N_ 3 1 2 3 4 5 6 7 8 9 0 4 P
P O
O 2 Q W E R T Y U I O P A 5
A Y
At 1 A S D F G H J K L ENT6 P
P I
I 0 CS Z X C V B N M SS SPC7 D
DA
A

         3 - # F7 4 - # EF

         2 - # FB 5 - # DF

         1 - # FD 6 - # BF

         0 - # FE 7 - # 7F



   A small explanation of the figure. Above the keyboard, 
horizontal, I put down number of bits that are active after 
pressing a certain klavishi.Po vertical numbered rooms 
poluryadov. By the way, poluryady numbered conventionally.

Now, for example, if we press the button
"1", then the third will be used poluryad and active will be 
zero bits. 

   Now let us consider a concrete example:
We must organize a poll on the keyboard
keystrokes: "1" and "2". In accordance
so what key is pressed, will change
Border color (so clearly). So ...

KEY HALT; wait for the next interrupt

     XOR A; zero out the battery.

     LD A, # F7; record in the battery

               ; Poluryad our (third).

     IN A, (# FE); low bit port address.

     BIT 0, A; define consist. bits

               ; Sootvetstvuyusch.klavishe "1"

               , If the bit is active, the flag

               ; Z = 1, if not, then Z = 0.

     JR Z, BLUE; if Z = 1, then the operation

               ; JR Z. .. will be executed

               And if Z = 0, we have it "Prosky
               ; Chili.

     LD A, # F7; again our poluryad.

     IN A, (# FE); poll clave.

     BIT 1, A; determine the status of the first
               ; Vågå bit which corresponds to
               , Corresponds to key "2".

     JR Z, RED; here is similar to previous
               ; Schemu.

     JR KEY; more personal interview

               ; Do not, "loops".
BLUE LD A, 1; to accumulate. - Color blue

     OUT (254), A; BORDER 1.

     RET
RED LD A, 2, deuce, respectively. red

     OUT (254), A; BORBER 2.

     RET



   We hope you all became clear. Note that the bits of the 
right poluryada go from right to left. To really quite and for 
all deal with this issue, give an example, the same program, but

for another poll poluryada.Organizuem keys: "9" and "0":


KEY HALT; waiting for the next interrupt

     XOR A; zero out the battery.

     LD A, # EF; record in the battery

               ; Our poluryad (fourth).

     IN A, (# FE); low bit port address.

     BIT 0, A; define consist. bits

               ; Sootvetstvuyusch.klavishe "0"

               , If the bit is active, the flag

               ; Z = 1, if not, then Z = 0.

     JR Z, BLUE; if Z = 1, then the operation

               ; JR Z, BLUE will be satisfied
               ; Nyatsya

     LD A, # EF; again our poluryad.

     IN A, (# FE); poll clave.

     BIT 1, A; determine the status of the first
               ; Vågå bit which corresponds to
               , Corresponds to the key "9".

     JR Z, RED; here is similar to previous
               ; Schemu.

     JR KEY; "loops."
BLUE LD A, 1

     OUT (254), A

     RET
RED LD A, 2

     OUT (254), A

     RET



   It's over. And if we need to identify pressing together
with CAPS SHIFT? Here is program for you where we do a poll 
pressed "6" and 7 "together with the CAPS SHIFT: 


KEY HALT; expect to interrupt.

     XOR A; resets the battery.

     LD A, # FE; because CAPS SHIFT is

               ; In zero poluryadu.

     IN A, (# FE); poll clave.

     BIT 0, A; define the state

               ; Zero bits.

     JR NZ, PROG; if the fold. "CSh" not clicking
               ; That, we'll go to the label

               ; PROG, where we have some

               ; Own program, but if

               ; Pressed, Z = 1 and JR Z, PROG

               And we "go clear."

     LD A, # EF; here we take 4 poluryad.

     IN A, (# FE); poll clave.

     BIT 3, A; third bit-key "7".

     CALL Z, BLUE; when pressed-> tag BLUE.

     LD A, # EF; fourth poluryad.

     IN A, (# FE); poll clave.

     BIT 4, A; fourth bit - champ. "6."

     CALL Z, RED; when pressed -> Tag RED.
PROG .......... And here is your

     .......... ; Program, for example,

     .......... ; Survey of other keys.

     JR KEY; loops.
BLUE LD A, 1; here is all clear ...

     OUT (254), A

     RET
RED LD A, 2

     OUT (254), A

     RET



   Now, hopefully, the issues on this topic will not arise.

   It should be noted that there is another
almost exactly the same way to survey the keyboard, which 
differs from the above that the larger number of verifiable is 
in the register pair BC, and a code key that was pressed is 
transferred into register A. It is:



     LD BC, nnnn

     IN A, (C); input data from port

                ; In the battery.


   Here nnnn - address the external port to be installed in BC. 
We need only remember that case C would be # FE (constantly), 
and B - value corresponding to the number poluryada. For 
example, for our first applets instead: 


     LD A, # F7

     IN A, (# FE)


should dial:


     LD BC, # F7FE

     IN A, (C)



   Another small subtlety.

   Check bit 0 can not produce
team BIT 0, A, and a team of RRCA, if
verifiable key extreme on the keyboard
as, for example, the keys Q, A and P.

   As is known, RRCA means ROTATE ACCUMULATOR RIGHT WITHOUT 
CARRY (rotate accumulator right without carry flag). Flag 
transfer even though changes in the light of the operation, but 
in the rotation is not involved. 

   Using the command RRCA saves memory, because a single-byte 
command. When We use it to produce rotation of the contents of 
the battery to the right, when you audited key flag off

(C = 0). Thus, instead of:


     BIT 0, A

     JR Z, BLUE


in our first program can be put
Design:


     RRCA

     JR C, BLUE; if a key is pressed,

               , As indicated by the established
               ; Lenny bit, the team of "pro
               ; Skakivaetsya.


   And here is a piece of software that lets you check your 
keystrokes and O P:


      ........
KEY1 LD A, # DF; cells. O and P - 5 poluryad

      IN A, (# FE)

      RRCA; key P

      JR C, LABEL1; conditional tag.
, Because press O and P are in one of; luryadu, run the command 
twice IN No ; Necessary. Just another shift bi, you're right 
battery. 


     RRCA; key ON

     JR C, LABEL2

     ......... ; Well, and so on.


   I think this is possible and finish.

   In conclusion, I want to thank Andrew Rila (ICB) for 
assistance in preparing article.

----------------------------------------- P. S. And we, in 
turn, would like to thank Sergei Kolesnikov for his active work 
in preparing articles for the magazine, and congratulate him on 
his appointment as the lead section. We're really pleased to be 
dealing with here is people!

-----------------------------------------





Other articles:

Apperativchik - the entry of the authors.

Apperativchik - On the control of Deja Vu.

Apperativchik - Freebie number 2: pirates and hacked versions of the magazine.

Apperativchik - Dejavu Info: How to buy the magazine Deja Vu.

Topic - Swap: "From letters to parcels" as found in the city Spektrumistov.

Topic - Tusovka: CSP'99 - interview with Slack Den.

Topic - Tusovka: CSP'99 - an interview with the main coder'om young Novosibirsk group AREASoft

Topic - Tusovka: CSP'99 - interview with one of the publishers 'electronic journal Deja Vu' Daniel / Playgear Co. / Binary Dimension.

Topic - Tusovka: CSP'99 - interview with one of Rybinsk of Cav / Auryn.

Topic - Tusovka: CSP'99 - an interview with the father of Playgear cool uncle Ze Pagan.

Topic - Tusovka: CSP'99 - an interview with the main coder'om Flash and concurrently one of the founders of the group - Alex Rider.

Topic - Tusovka: CSP'99 - poll as the party was held in a nutshell, the general impression.

Topic - Tusovka: Legend of the way passed Crazy Siberian Party 1999.

drop of solder - HD discs: Finalization of the drive controller to work with HD-disks.

drop of solder - The decision PROBLEMS 1.2MB drive.

drop of solder - increase the amount of RAM up to 1024K on SPECCY option Taganrog 128K!

drop of solder - circuit programmer for chip-only memory (ROM).

drop of solder - a dot-matrix printers.

drop of solder - ISA-Spectrum: card inserted into the ISA slot is IBM, which is part or a complete computer ZX-Spectrum.

Software - demoscene: Obzor'ing demozov: 63 bit III, Jam, Anamnesis, 7 Up, 63 bit IV, DemoDyin, Napalm, Crapmo 2, Bunch of Arce, Devotion, WorkStop, Energy , Yes.

Software - Game Review: MIST: Monstrland Part Two, Bomb Lakes, Marbles, KluXer, 4x4 Puzzle, Soldiers, Boats.

Software - Gun Commander: User's Guide.

Coding - coding for Dummies: civilized way in TR-DOS.

Coding - coding for Dummies: More about one of the ways to survey the keyboard.

Coding - coding for Dummies: How does the "Boot" from the inside.

Coding - coding for Dummies: refine MINI BOOT V3.0.

Coding - how to print 42 characters per line (with trabutami), the procedure is quick print sprites with pixel precision.

Coding - Bystrai printing 64 characters per line.

Coding - Conversion of numbers from the stack calculator in the character string.

Coding - fast print 2x2 sprite familiarity, up to familiarity.

Coding - Hrust Library svobodnopasppostpanyaemaya library window procedure by means of eccentricity can be packaged and paspakovyvat VARIOUS data.

Coding - Error Handling TR-DOS when working through # 3D13.

Coding - a set of procedures for constructing the user interface.

Coding - pishim virus invisible to TR-DOS.

Another world - The illusion of safety: Terrifying tales of Windows security and the Internet (Part One).

Hall of Fame - 3 methods to distinguish pealny ZX Spectrum from emulyatopov.

Hall of Fame - the charter of the National Fund of the Spectrum (HFSP).

Hall of Fame - Reserves: an attempt to present the perfect ZX Spectrum.

Hall of Fame - boiling: "And there still alive Speccy, sympathy Boxing?" Reflections in hearing.

Hall of Fame - schA say number 1: optimization of procedures, the announcement of the magazine and the new arcade toy.

Hall of Fame - schA say number 1: disassembly and Serg'a Playgear, hacking calling card, the announcement Crazy Siberian Party '2000.

Hall of Fame - A brief history of the Kemerovo group Digital Life Group.

Seven and 1 / 2 - Student mythology.

Seven and 1 / 2 - April Fools' Day 2 (end).

Seven and 1 / 2 - fairy tales for children.

Seven and 1 / 2 - Features a national ruleza or pure Siberian project (the story of Crazy Siberian Party 1999).

Samples pen - memory: story of the game "Black Crow".

Samples pen - story, "Elixir of the Beast."

Samples pen - "Last Warrior".

Advertising - text ads and announcements.

Advertising - a graphical advertising and announcements.


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
IS-DOS - "IS-DOS - for beginners" No 3
Plus-minus - the fact that such CB RADIO, about its pros and cons.
Enlight'96 - Kano talks about future projects and their proteges.
Stuck? - Description of the game "Dustin".
From the Author - start the new school year ...

В этот день...   21 November