home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol9n14.zip / CLICK.ASM < prev    next >
Assembly Source File  |  1990-03-30  |  2KB  |  84 lines

  1. ;=====================================================================
  2. ; CLICK.COM clicks the PC's speaker each time a key is pressed.
  3. ; Assemble and link with:
  4. ;
  5. ;    MASM CLICK;
  6. ;    LINK CLICK;
  7. ;    EXE2BIN CLICK CLICK.EXE
  8. ;
  9. ; Copyright (c) 1990 Ziff-Davis Publishing Company
  10. ;=====================================================================
  11.  
  12. code    segment    para public 'code'
  13.     assume    cs:code
  14.     org    100h
  15.  
  16. begin:    jmp    init            ;Jump to initialization code
  17.  
  18. intvec    dd    ?            ;Old interrupt 09H vector
  19.  
  20. ;---------------------------------------------------------------------
  21. ; KBINT intercepts interrupt 09H and calls CLICK when a key is pressed.
  22. ;---------------------------------------------------------------------
  23. kbint    proc    far
  24.     pushf                ;Save flags
  25.     push    ax            ;Save AX
  26.     in    al,60h            ;Read scan code
  27.     test    al,80h            ;Check for break code
  28.     jnz    exit            ;Exit on break
  29.     call    click            ;Click on make code
  30. exit:    pop    ax            ;Restore AX
  31.     popf                ;Restore flags
  32.     jmp    intvec            ;Jump to BIOS handler
  33. kbint    endp
  34.  
  35. ;---------------------------------------------------------------------
  36. ; CLICK programs the speaker to produce a short click.
  37. ;---------------------------------------------------------------------
  38. click    proc    near
  39.     sti                ;Interrupts on
  40.     mov    al,0B6h            ;Program timer 2 to generate
  41.     out    43h,al            ;  pulses
  42.     jmp    short $+2
  43.     mov    al,0            ;Send low byte of the 16-bit
  44.     out    42h,al            ;  value that will determine
  45.     jmp    short $+2        ;  the pulse frequency
  46.     mov    al,6            ;Then send the high byte
  47.     out    42h,al
  48.     jmp    short $+2
  49.     in    al,61h            ;Speaker on
  50.     jmp    short $+2
  51.     or    al,3
  52.     out    61h,al
  53.     push    cx            ;Save CX
  54.     mov    cx,1000h        ;Timing delay
  55. here:    loop    here
  56.     pop    cx            ;Restore CX
  57.     in    al,61h            ;Speaker off
  58.     jmp    short $+2
  59.     and    al,0FCh
  60.     out    61h,al
  61.     ret                ;Return to caller
  62. click    endp
  63.  
  64. ;*********************************************************************
  65. ; End of resident code -- start of initialization code.  Everything from
  66. ; here on is discarded when the program becomes memory-resident.
  67. ;*********************************************************************
  68.  
  69. init    proc    near
  70.     assume    cs:code,ds:code
  71.     mov    ax,3509h        ;Get the current interrupt
  72.     int    21h            ;  09H vector and store it
  73.     mov    word ptr intvec,bx
  74.     mov    word ptr intvec[2],es
  75.     mov    ax,2509h        ;Point interrupt 09H to
  76.     mov    dx,offset kbint        ;  the KBINT routine
  77.     int    21h
  78.     mov    dx,offset init        ;Use interrupt 27H to
  79.     int    27h            ;  terminate and stay
  80. init    endp                ;  resident
  81.  
  82. code    ends
  83.     end    begin
  84.