TITLE   Keyboard fun!      
;==============================================================
;This program demonstrates the things you can do with
;assembler.  It flashes the lights on the keyboard
;by outputting a command to the keyboard then telling it
;what lights we want on.  After the program is done
;it restores the previous light configuration.  Compile
;into a .COM file.
;===============================================================
.MODEL TINY     ;Set tiny memory model
.186           ; Use crusty 186 code

.CODE
.STARTUP

START:
	MOV     SI,0
	MOV     AX,0619h        ; Clear the screen
	MOV     BH,7
	XOR     CX,CX
	MOV     DX,1950h        ;Scroll 25 lines to clear the screen
	INT     10h
	MOV     AX,0200h        ;Put cursor in top left hand corner
	XOR     BX,BX           ;Video Page 0
	XOR     DX,DX           ;Pos 0,0
	INT     10h
        MOV     DX,OFFSET MESSAGE      ;Print startup message
	MOV     AH,09h
	INT     21h
        MOV     DX,OFFSET WATCH
	INT     21h

	XOR     AX,AX
	MOV     ES,AX
	MOV     DI,0417h        ;Point ES:[DI] to memory location of keyboard status
	MOV     BX,ES:[DI]      ;Save current keyboard status in BX
	MOV     DX,60H          ;Put keyboard port in DX
LOOP1:
	MOV     AL,0EDH ;Send command to keyboard to allow us
	OUT     DX,AL            ;to change lights
	INC     SI
        MOV     AL,BYTE PTR KBSEQ[SI]   ;Put in AL the lights we want on
					;by setting the appropriate bits
	HLT                             ;Wait for keyboard to acknowledge
	OUT     DX,AL            ;Tell keyboard which lights we want
	HLT                     ;Pause a little
	HLT
	HLT
	TEST    AL,AL           ;See if we have reached end of KBSEQ
	JNZ     LOOP1           ;If not go agin
	MOV     SI,0            ;else point to start of sequence
	MOV     AH,1
	INT	16h		 ;and go again if no key was pressed
	JZ      LOOP1

	MOV     AL,0EDH       ;Send command to keyboard to allow us
        OUT     DX,AL         ;to change lights
        HLT
        MOV     AL,BL         ;Move light status we obtained earlier in AL
        SHR     AL,4          ;We need to move the bits 4 positions right
			      ;because the bits we set to turn the lights
	OUT     DX,AL         ;on are in a different position that
			      ;the ones we read earlier

        MOV     DX,OFFSET FINISHED     ;Else print that we are done
	MOV     AH,09h
	INT     21h
	MOV     AX,4C00H         ; Send exit code to dos
	INT     21H             ; Send command to DOS

MESSAGE         DB      09,09,09,"**** Assembly Test Program ****",0ah,0dh,0ah,09,09,09,"        Keyboard Fun!",09,09,"DK SOFT, 2000",0ah,0dh,24h
WATCH           DB      0ah,0ah,"Watch the lights on your keyboard!",0ah,0ah,0dh,"Press any key to exit.",0ah,0ah,0dh,24h
FINISHED        DB      "By Dennis Katsonis",0ah,0dh,24h
KBSEQ           DB      7,3,1,6,4,2,0

END		      ; Set end of program
