home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / microcrn / issue_36.arc / INT.FIG < prev    next >
Text File  |  1987-05-21  |  3KB  |  84 lines

  1.  
  2. title InterruptExample
  3.  
  4.  
  5. code    segment                ; everything goes in code segment
  6.         org     100h
  7.  
  8.         assume  cs:code
  9.  
  10. DOS_entry       label   far
  11.         jmp     setup
  12.  
  13. new_int         proc    far    ; beginning of our interrupt handler
  14.         sti                    ; reenable interrupts
  15.         push    ax             ; save registers
  16.         push    bx
  17.         push    dx
  18.         mov     al,0B6h        ; set up timer to generate tones
  19.         out     43h,al
  20.         in      al,61h         ; turn on 2 LS bits to enable speaker
  21.         or      al,03h
  22.         out     61h,al
  23.         mov     bx,3000h       ; initial tone divisor
  24.  
  25. top:    mov     ax,bx          ; set up tone
  26.         out     42h,al
  27.         mov     al,ah
  28.         out     42h,al
  29.         mov     dx,30h
  30. delay:  dec     dx             ; sound the tone for a short while
  31.         cmp     dx,0
  32.         jne     short   delay
  33.         dec     bx
  34.         cmp     bx,0
  35.         jne     short   top    ; set up new tone
  36.  
  37. done:   in      al,61h         ; turn off 2 LS bits to disable speaker
  38.         and     al,0FCh
  39.         out     61h,al
  40.         mov     al,20h         ; signal EOI (end of interrupt) to processor
  41.         out     20h, al
  42.         pop     dx             ; restore registers
  43.         pop     bx
  44.         pop     ax
  45.         iret
  46.  
  47. new_int endp                   ; end of our interrupt
  48.  
  49. end_res_code:
  50.  
  51. sign_on db      'INTERRUPT TEST NOW INSTALLED$'
  52.  
  53. err_msg db      'INTERRUPT TEST ALLREADY INSTALLED$'
  54.  
  55.         assume  ds:code
  56.  
  57. setup   proc    near           ; install our routine
  58.                                ; as resident code
  59.         in      ax,21h         ; get mask register
  60.         and     ax,0FBh        ; remove mask -- reset bit 2
  61.         out     21h,ax         ; send new mask to register
  62.         mov     ax,350Ah       ; get address of interrupt 0Ah
  63.         int     21h
  64.         mov     ax,es          ; segment is returned in es
  65.         cmp     ax,0f000h      ; is this address in ROM?
  66.         jae     short install  ; if so, install our code
  67.         mov     dx,offset err_msg       ; if not, write msg
  68.         mov     ah,9           ; that our code is already
  69.         int     21h            ; installed
  70.         int     20h            ; exit to DOS
  71. install:mov     dx,offset sign_on       ; write sign on msg
  72.         mov     ah,9
  73.         int     21h
  74.         mov     dx,offset new_int       ; set up new
  75.         mov     ax,250Ah                ; interrupt vector
  76.         int     21h
  77.         mov     dx,offset end_res_code  ; make our code
  78.         int     27h                     ; resident
  79.  
  80. setup   endp
  81. code    ends
  82.         end     DOS_entry
  83.  
  84.