home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / AMISL082 / VGABLANK.ASM < prev   
Assembly Source File  |  1992-04-19  |  5KB  |  207 lines

  1. ;-----------------------------------------------------------------------
  2. ; VGABLANK.ASM    Public Domain 1992 Ralf Brown
  3. ;        You may do with this software whatever you want, but
  4. ;        common courtesy dictates that you not remove my name
  5. ;        from it.
  6. ;
  7. ; Minimalist VGA screen blanker.
  8. ;
  9. ; Version 0.80
  10. ; LastEdit: 4/19/92
  11. ;-----------------------------------------------------------------------
  12.  
  13. __TINY__ equ 1                ; using Tiny model
  14.     INCLUDE AMIS.MAC
  15.  
  16. ;-----------------------------------------------------------------------
  17. ;
  18. VERSION_NUM equ 0050h    ; v0.80
  19. VERSION_STR equ "0.80"
  20.  
  21. ;-----------------------------------------------------------------------
  22. ; Declare our segments in the order we want them in the executable.
  23. ;
  24. _TEXT    SEGMENT PUBLIC BYTE 'CODE'
  25. _TEXT    ENDS
  26. TSRcode@
  27. TSRcodeEnd@
  28.  
  29. BIOS_SEG SEGMENT AT 40h
  30.     ORG 63h
  31. video_base dw ?
  32. BIOS_SEG ENDS
  33.  
  34. ;-----------------------------------------------------------------------
  35. ; Useful definitions
  36. ;
  37. VIDEO_DISABLE_BIT equ 20h
  38. VGA_REG       equ 3C4h
  39. TICKS_PER_MINUTE equ 0444h
  40.  
  41. ;-----------------------------------------------------------------------
  42. ; Put the resident code into its own segment so that all the offsets are
  43. ; proper for the new location after copying it into a UMB or down into
  44. ; the PSP.
  45. ;
  46. TSRcode@
  47. start_TSRcode label byte
  48.  
  49. ;-----------------------------------------------------------------------
  50. ; Declare the interrupt vectors hooked by the program, then set up the
  51. ; Alternate Multiplex Interrupt Spec handler
  52. ;
  53.     HOOKED_INTS 09h,1Ch
  54.     ALTMPX    'Ralf B','VGABLANK',VERSION_NUM
  55.  
  56. ;-----------------------------------------------------------------------
  57. ; Now the meat of the resident portion, the keyboard and timer tick
  58. ; interrupt handlers.
  59. ; We can save two bytes by specifying the hardware reset handler set up by
  60. ; the ALTMPX macro above
  61. ;
  62. time_count dw 0                ; patched to actual timeout tick count
  63.  
  64. set_video_state:
  65.     push    dx
  66.     mov    dx,VGA_REG
  67.     mov    al,1
  68.     out    dx,al
  69.     inc    dx
  70.     in    al,dx
  71.     dec    dx
  72.     and    al,not VIDEO_DISABLE_BIT
  73.     or    ah,al
  74.     mov    al,1
  75.     out    dx,al
  76.     inc    dx
  77.     mov    al,ah
  78.     out    dx,al
  79.     pop    dx
  80.     ret
  81.  
  82. ISP_HEADER 1Ch,hw_reset_2Dh
  83.     dec    time_count        ; count down, and each time we hit
  84.     jnz    int1C_done        ; zero, force the video off
  85.     push    ax
  86.     mov    ah,VIDEO_DISABLE_BIT
  87.     call    set_video_state
  88.     pop    ax
  89. int1C_done:
  90.     JMP    ORIG_INT1Ch
  91.  
  92. ISP_HEADER 09h,hw_reset_2Dh
  93.     push    ax            ; keystroke, so unblank display
  94.     mov    ah,0
  95.     call    set_video_state
  96.     pop    ax
  97.     mov    time_count,0FFFFh    ; patched with actual timeout count
  98. MAX_TIME equ word ptr ($-2)
  99.     jmp    ORIG_INT09h
  100.  
  101. resident_code_size equ offset $
  102.  
  103. TSRcodeEnd@
  104.  
  105. ;-----------------------------------------------------------------------
  106.  
  107. _TEXT SEGMENT 'CODE'
  108.     ASSUME cs:_TEXT,ds:_TEXT,es:_TEXT,ss:_TEXT
  109.     ORG 100h
  110.  
  111. VGABLANK:
  112.     DISPLAY_STRING banner
  113.     CHECK_DOS_VER 2,00
  114.     mov    bx,1000h        ; set memory block to 64K
  115.     mov    ah,4Ah
  116.     int    21h
  117.     mov    si,81h            ; SI -> command line
  118.     cld                ; ensure proper direction for string ops
  119. cmdline_loop:
  120.     lodsb
  121.     cmp    al,' '            ; skip blanks and tabs on commandline
  122.     je    cmdline_loop
  123.     cmp    al,9
  124.     je    cmdline_loop
  125.     cmp    al,'1'            ; number of minutes specified?
  126.     jb    not_digit
  127.     cmp    al,'9'            ; if digit, go install TSR
  128.     jbe    installing
  129. not_digit:
  130.     and    al,0DFh            ; force to uppercase
  131.     cmp    al,'R'
  132.     je    removing
  133. usage:
  134.     mov    dx,offset _TEXT:usage_msg
  135.     jmp     exit_with_error
  136.  
  137. removing:
  138.     UNINSTALL <offset _TEXT:start_TSRcode>,RELBYTE,cant_uninstall
  139.     ;
  140.     ; force video back on in case we are called from a batch file while
  141.     ; the screen is blanked
  142.     ;
  143.     mov    ah,0
  144.     call    near ptr _TEXT:set_video_state
  145.     push    cs
  146.     pop    ds
  147.     ASSUME    DS:_TEXT
  148.     DISPLAY_STRING uninstalled_msg
  149.         mov     ax,4C00h
  150.     int    21h
  151.  
  152. installing:
  153.     sub    al,'0'
  154.     cbw
  155.     mov    bx,TICKS_PER_MINUTE
  156.     mul    bx
  157.     mov    timeout,ax        ; and remember for later
  158.     mov    ax,1A00h        ; get display combination code
  159.     int    10h
  160.     cmp    al,1Ah            ; supported? (i.e. VGA present?)
  161.     mov    dx,offset _TEXT:need_VGA_msg
  162.     jne    exit_with_error
  163.     ;
  164.     ; place any necessary pre-initialization here
  165.     ;
  166.     INSTALL_TSR <offset _TEXT:start_TSRcode>,RELBYTE,resident_code_size,BYTE,,BEST,TOPMEM,inst_patch,already_installed
  167.  
  168. cant_uninstall:
  169.     mov    dx,offset _TEXT:cant_remove_msg
  170.     jmp short exit_with_error
  171. already_installed:
  172.     mov    dx,offset _TEXT:already_inst_msg
  173. exit_with_error:
  174.     mov    ah,9
  175.     int    21h
  176.     mov    ax,4C01h
  177.     int    21h
  178.  
  179. inst_patch:
  180.     push    es
  181.     mov    es,ax
  182.     ASSUME    ES:RESIDENT_CODE
  183.     mov    ax,timeout
  184.     mov    time_count,ax
  185.     mov    MAX_TIME,ax
  186.     pop    es
  187.     ASSUME    ES:NOTHING
  188.     DISPLAY_STRING installed_msg
  189.     ret
  190.  
  191. banner       db 'VGABLANK v',VERSION_STR,'  Public Domain 1992 Ralf Brown',13,10,'$'
  192. usage_msg  db 'Usage:',9,'VGABLANK n',9,"(n=1-9) install to blank after 'n' minutes",13,10
  193.        db 9,'VGABLANK R',9,'remove from memory',13,10
  194.        db "$"
  195. need_VGA_msg     db "This program requires a VGA.",13,10,"$"
  196. installed_msg    db "Installed.",13,10,"$"
  197. already_inst_msg db "Already installed.",13,10,"$"
  198. cant_remove_msg  db "Can't remove from memory.",13,10,"$"
  199. uninstalled_msg  db "Removed.",13,10,"$"
  200.  
  201. timeout            dw ?
  202.  
  203. _TEXT ENDS
  204.  
  205.      end VGABLANK
  206.  
  207.