ASSEMBLY LANGUAGE - WEEK IV					November 15, 1986



KEYBOARD I/O



ROM KEYBOARD ROUTINES



NOTE: All of the following keyboard routines use the ROM keyboard driver routine.



002BH --  INKEY subroutine: scans the keyboard and returns, zeroing A if no key is depressed, else returns character from keyboard in A. Data is not echoed to video. Uses AF, DE.



0049H --  INPUT subroutine: scans the keyboard and waits for a key to be depressed. Returns character in A. Uses AF, DE.




05D9H --  LINE INPUT subroutine: accepts an entire line of input terminated by ENTER or BREAK. Displays characters typed, recognizing control functions (backspace, etc.).
On entry, HL points to start of buffer that will hold
 input.
B = maximum number of bytes to input.
                  
Input is terminated by ENTER or BREAK.
On return:HL points to start of text.
B = actual input length (less terminator).
C = original contents of B register.
A = terminating character.
The C flag is set if line ends with BREAK.
       
Uses AF, DE.




EXERCISES:

I. Input some data from the keyboard and make it appear on the video display:




       START   EQU     7003H

       CHKIO   EQU     002BH

       OUTC    EQU     0033H



     
	          CALL    CHKIO          CD 2B 00

               XOR     A              AF
       
	  LOOP    CALL    CHKIO          CD 2B 00

               JP      Z,LOOP         CA 07 70

               CALL    OUTC           CD 33 00

       MORCOD  CP      0DH            FE 0D

               JP      NZ,LOOP        C2 07 70








Ia.
   Make the input neater by clearing screen first

Add the clear screen subroutine at 7000H.


       
	  CLS     EQU     01C9H

       START   EQU     7000H



        
	          CALL    CLS            CD C9 01





II.
   Input a string of characters and start storing them at 7050H.



      LINEINP  EQU     05D9H

      START    EQU     7020H

               CALL    CLS            CD C9 01

               LD      HL,7050H       21 50 70

               LD      B,E0H          06 E0

               CALL    LINEINP        CD D9 05






IIa.
   What happens if we limit input to 10 characters?









III. Let's have computer prompt you for your name and then greet you.



Basically routine will go like:

   Call Cls

   Call screen msg "What is your name" @ 7050H

   Line input name and store @ 7070H

   Call screen greeting "Hello" @ 7063H

   Call screen name @ 7070H.



Devious people that we are, lets use the line input routine to load messages in memory by changing routine.



a)Change the no. of characters input in register B to 14H.

b) Run routine, typing in <What is your name? >

c) Change the memory location in HL to store message at 7063H

d) Run routine again, typing in <Hello! >



Now, let's write routine starting @ 7000H.



     START     EQU    7000H

     DISPLAY   EQU    021BH

     LINEINP   EQU    05D9H

     CLS       EQU    01C9H

     MSG1      EQU    7050H

     MSG2      EQU    7063H

     NAME      EQU    7070H



               CALL   CLS                    CD C9 01

               LD     HL,MSG1                21 50 70

               CALL   DISPLAY                CD 1B 02

               LD     HL,NAME                21 70 70

               LD     B,20H                  06 20

               CALL   LINEINP                CD D9 05

               PUSH   HL                     E5
     
          LD     HL,MSG2                21 63 70

               CALL   DISPLAY                CD 1B 02

               POP    HL                     E1
    
           CALL   DISPLAY                CD 1B 02

     HOLD      CALL   CHKIO                  CD 2B 00

               JP     Z,HOLD                 CA 1C 70

               CP     "@"                    FE 40

               JP     NZ,HOLD                C2 1C 70


                                                                                                                                                  