home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / asm / SCRNSAVE.ZIP / SCRNSAVE.ASM next >
Encoding:
Assembly Source File  |  1991-04-18  |  8.8 KB  |  189 lines

  1. ;
  2. ; Author: Scott Hopson  Mail: 76207,674
  3. ;
  4. ; If you like this program you don't have to pay me.
  5. ; If you don't like my comments go steal someone elses code
  6. ; In either case I hope you find this usefull
  7. ;
  8. ; This program revectors the timer and keyboard interrupts
  9. ; if a key has not been pressed after 15 minutes the timer routine
  10. ; saves the current screen into the buffer and clears video memory
  11. ; when a key is pressed the keyboard interrupt restores the screen to
  12. ; its previous state and resets the counter. The keystroke is not passed
  13. ; onto the system so the user can use any key to restore the screen without
  14. ; affecting the application.
  15. ;
  16. ; You could use int 8 instead of int 1c but it really doesn't matter
  17. ; int 8 calls int 1c which is normally vectored to an IRET unless you
  18. ; change it.
  19. ;
  20. ; Note: on some keyboards using the Left-Alt or Left-Ctrl keys to restore the
  21. ; screen does wierd stuff. Just press the opposite key to restore keyboard.
  22.  
  23.                 .model  tiny
  24.                 
  25. code            segment para    public 'CODE'
  26.                 assume  cs:code
  27.                 org     100h            ; this is going to be a .COM file
  28. start:          jmp     main            ; skip passed data
  29.  
  30. oldint9         dd      ?               ; previous keyboard vector (09h)
  31. oldint1c        dd      ?               ; previous timer vector (1ch)
  32. video           dw      ?               ; video memory location
  33. cursor          dw      ?               ; current curso info
  34. count           dw      0               ; count of ticks since keypress
  35. vflag           db      0               ; just a flag        
  36. _page           db      ?               ; active page
  37. buffer          dw      2000 dup(?)     ; you could put this in EMS or just
  38.                                         ; load the whole program high
  39.                                                 
  40. int9            proc    far
  41.                 mov     cs:[count],0    ; reset counter
  42.                 cmp     cs:[vflag],1    ; is screen currently saved
  43.                 jne     exit9           ; nope, he's going to hell
  44.                 push    ax              ; save those register like a good
  45.                 push    bx              ; little programmer
  46.                 push    cx
  47.                 push    ds
  48.                 push    es
  49.                 push    si
  50.                 push    di
  51.                 in      al,60h     ; must read byte from keyboard
  52.                                    ; or you'll just hang
  53.                 in      al,61h     ; get keyboard control lines
  54.                 mov     ah,al      ; save present settings
  55.                 or      al,80h     ; set enable keyboard bit
  56.                 out     61h,al     ; write it out
  57.                 xchg    ah,al      ; get original values
  58.                 out     61h,al     ; restore orginal bits
  59.                 mov     al,20h     ; signal End Of Interrupt (EOI)
  60.                 out     20h,al     ; to Programmable Interrupt Controller (PIC)
  61.                 mov     cs:[vflag],0    ; reset video saved flag  
  62.                 mov     bh,cs:[_page]   ; set video page to active
  63.                 mov     cx,cs:[cursor]  ; get cursor info
  64.                 mov     ah,01h          ; restore cursor
  65.                 int     10h             ; call bios video routine
  66.                 mov     es,cs:[video]   ; destination is address by es
  67.                 mov     di,0       ; start at top of screen
  68.                 mov     cx,2000    ; 2000 words = 4000 bytes = 80*25*2
  69.                 push    cs         ; setup source of saved info
  70.                 pop     ds         ; which is address by the data segment
  71.                 mov     si,offset cs:buffer  ; in buffer
  72.                 cld                
  73.                 rep     movsw   ; move the data from buffer to screen fast
  74.  
  75.                 pop     di      ; remember kiddies when your done playing
  76.                 pop     si      ; always put your toys back where you found
  77.                 pop     es      ; them or mommy DOS will spank you hard
  78.                 pop     ds
  79.                 pop     cx
  80.                 pop     bx
  81.                 pop     ax
  82.                 iret                    ; return from interrupt
  83. exit9:          jmp     cs:[oldint9]    ; chain to previous vector
  84. int9            endp                
  85.  
  86. int1c           proc    near
  87.                 inc     cs:[count]      ; increment the counter
  88.                 cmp     cs:[count],16200; has fifteen minutes passed
  89.                 jb      exit1c          ; no so just go on
  90.                 mov     cs:[count],0    ; yes so reset counter 
  91.                 cmp     cs:[vflag],1    ; is screen saved already
  92.                 je      exit1c          ; praise the Lord he is
  93.                 push    ax              ; nope, well let's convert him
  94.                 push    bx              ; save all those little reggies
  95.                 push    cx              ; like we're supposed to
  96.                 push    es
  97.                 push    ds
  98.                 push    si
  99.                 push    di                
  100.                 mov     ah,0ffh         ; get video state
  101.                 int     10h
  102.                 cmp     al,7            ; need to check screen modes 
  103.                 jbe     mode4           ; can't mess with a graphics screen
  104. mode4:          cmp     al,4            ; modes 4,5,6 and anything above 7
  105.                 je      exit1c          ; are graphics modes
  106.                 cmp     al,5
  107.                 je      exit1c
  108.                 cmp     al,6
  109.                 je      exit1c
  110.                 mov     cs:[vflag],1    ; screen is gettin saved    
  111.                 mov     cs:[_page],bh   ; save active video page
  112.                 mov     ah,03h          ; get cursor info
  113.                 int     10h
  114.                 mov     cs:[cursor],cx  ; save for later
  115.                 or      ch,20h          ; turn it off for now
  116.                 mov     ah,01h
  117.                 int     10h      
  118.                 push    cs
  119.                 pop     es
  120.                 mov     di,offset cs:buffer
  121.                 mov     ds,cs:[video]
  122.                 mov     si,0
  123.                 mov     cx,2000
  124.                 cld
  125.                 rep     movsw           ; moving 2000 words is supposed to be
  126.                 mov     cx,2000         ; faster than moving 4000 bytes
  127.                 mov     ax,0700h        ; setup video attributes
  128.                 mov     es,cs:[video]   ; get destination 
  129.                 mov     di,0
  130.                 cld
  131.                 rep     stosw           ; write words to clear screen
  132.                 pop     di              ; restore registers so system stays
  133.                 pop     si              ; happy...
  134.                 pop     ds
  135.                 pop     es
  136.                 pop     cx
  137.                 pop     bx
  138.                 pop     ax
  139. exit1c:         jmp     cs:[oldint1c]   ; chain to previous vector
  140. int1c           endp
  141.  
  142. LAST_BYTE       db      ?               ; marker used for freeing memory
  143.  
  144. message         db      'Screen Saver Loaded...',13,10,24h
  145.  
  146. main            proc    near
  147.                 push    cs
  148.                 pop     ds              ; setup data segment
  149.                                 
  150.                 mov     es,word ptr cs:[2ch]    ; free environment
  151.                 mov     ah,49h          ; we don't need it so why keep it?
  152.                 int     21h
  153.                                 
  154.                 int     11h             ; get video hardware info
  155.                 test    al,30h          ; check for monochrome video
  156.                 jz      mono            ; yes it is
  157.                 
  158.                 mov     word ptr video,0b800h   ; nope, a cga
  159.                 jmp     getvect
  160. mono:           mov     word ptr video,0b000h   
  161.  
  162. getvect:        mov     ax,351ch        ; get timer vector
  163.                 int     21h
  164.                 mov     word ptr [oldint1c],bx   ; save it
  165.                 mov     word ptr [oldint1c+2],es
  166.  
  167.                 mov     ax,3509h        ; get keyboard vector
  168.                 int     21h
  169.                 mov     word ptr [oldint9],bx    ; save it also
  170.                 mov     word ptr [oldint9+2],es
  171.  
  172.                 mov     ax,251ch        ; set new timer vector
  173.                 mov     dx,offset int1c
  174.                 int     21h                
  175.                 mov     ax,2509h        ; and new keyboard vector
  176.                 mov     dx,offset int9
  177.                 int     21h
  178.  
  179.                 mov     ah,9            ; print message
  180.                 mov     dx,offset message
  181.                 int     21h
  182.                                 
  183.                 mov     dx,offset LAST_BYTE     ; point to end of memory to
  184.                 int     27h                     ; save and terminate but
  185.                                                 ; stay resident
  186. main            endp
  187.  
  188. code            ends
  189.                 end     start