home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / utils / kylock.zip / SCRNOFF3.ASM < prev    next >
Assembly Source File  |  1987-06-16  |  18KB  |  337 lines

  1. ;
  2.                  page 66,132
  3. ;
  4. ;SCRNOFF3.ASM for the IBM PC/XT & PCJR - 1987 by Ocean
  5. ;
  6. ;This is part 1 of a 2 part utilities set consisting of -----------------------
  7. ;SCRNOFF3.ASM & KYLOCK.ASM.  --------------------- THEY MUST BE USED TOGETHER!
  8. ;                                                       -----------------------
  9. ;
  10. eoi                 equ 20h                     ;end-of-interrupt signal
  11. int_ctrl_port       equ 20h                     ;8259 interrupt controller port
  12. ;
  13. code             segment para public 'code'
  14.                  assume cs:code
  15.                  org 0
  16. seg_org             equ $
  17. ;
  18. bios_data        segment at 40h                 ;bios data area
  19.                  org 063h
  20. addr_6845        dw ?                           ;define location that holds
  21.                                                 ;word address of active display
  22.                  org 065h
  23. crt_mode_set     db ?                           ;define location that holds
  24.                                                 ;byte loaded into pc active
  25.                                                 ;display port or pcjr's vga
  26. bios_data        ends
  27. ;
  28.                  org 0100h
  29. begin:           jmp initialize                 ;goto initialization routine
  30. ;
  31. adapter          db 0                           ;0 = EGA, 1 = CGA or MDA, and
  32.                                                 ;2 = PCJR
  33. pcjr_mode        db ?                           ;current setting of PCJR video
  34. pc_mode          db ?                           ;current setting of 6845 mode
  35.                                                 ;control register of the pc
  36. count            dw 0cc8h                       ;initial 3 min. to blank screen
  37. timer_stat       db 01h                         ;initialize timer - on
  38. msr_address      dw ?                           ;address of mode select register
  39. pcjr_signature   db 0fdh                        ;PCJR BIOS signature
  40. ibm_signature    db 'IBM'                       ;EGA BIOS signature
  41. errmsg           db 13,10,'SCRNOFF3 ALREADY LOADED!',13,10,'$'
  42. ;
  43. old_int_1ch      label dword                    ;holding area for INT 8h vector
  44. int_1ch_ptr       dw 2 dup (?)
  45. old_int_16h      label dword                    ;holding area for INT 16h vector
  46. int_16h_ptr      dw 2 dup (?)
  47. ;
  48. ;------------------------------------------------------------------------------
  49. ;All calls to INT 16h will henceforth be routed thru here.  If ah = 255 on
  50. ;entry, bh is set to 255 to signal the caller that this routine was indeed
  51. ;invoked.
  52. ;------------------------------------------------------------------------------
  53. new_int_16h      proc near
  54.                  cmp ah,127                     ;ah = 127?
  55.                  jne switch                     ;no, then jump
  56.                  mov bh,ah                      ;yes, set bh to 255 and exit
  57.                  iret
  58. switch:          cmp ah,158                     ;INT called by ALT O keypress?
  59.                  jne newint1                    ;no, then jump
  60.                  add timer_stat,01h             ;yes, toggle timer on/off
  61.                  iret
  62. newint1:         jmp old_int_16h                ;goto normal 16h handler
  63. new_int_16h      endp
  64. ;
  65. ;------------------------------------------------------------------------------
  66. ;User timer INT 1Ch is now routed through here.
  67. ;------------------------------------------------------------------------------
  68. ;
  69. countdown3       proc near
  70.                  test timer_stat,01h            ;timer activated?
  71.                  jz do_nothing                  ;no, exit
  72.                  cmp count,00                   ;yes, check if count has zeroed
  73.                  jz do_nothing                  ;already zero, exit
  74.                  dec count                      ;active & not zero, tick & ...
  75.                  jnz do_nothing                 ;not zero, exit ... else ...
  76. ;
  77. ;Time has run out, call the video_disable routine to blank the screen only.
  78. ;The rest of the program is still ready to lock the keyboard with a password if
  79. ;desired.
  80. ;
  81.                  push ax                        ;save ax register
  82.                  push dx                        ;save dx register
  83.                  cli                            ;disable all interrupts
  84.                  call video_disable             ;time is up - disable the video
  85.                  mov al,eoi                     ;get eoi value
  86.                  out int_ctrl_port,al           ;send eoi signal to the 8259
  87.                  pop dx                         ;restore dx register
  88.                  pop ax                         ;restore ax register
  89.                  sti
  90. do_nothing:      jmp old_int_1ch                ;iret thru old_int_1Ch
  91. countdown3       endp
  92. ;
  93. ;------------------------------------------------------------------------------
  94. ;This routine is user vector interrupt 4dh!
  95. ;------------------------------------------------------------------------------
  96. unblank          proc near
  97.                  cmp count,00                   ;if timer is not 0 the screen
  98.                                                 ;is still visible - jump to
  99.                  jnz reset_count                ;reset count to 3 min., since
  100.                                                 ;a keypress has occured
  101.                  push ax                        ;save ax register
  102.                  push dx                        ;save dx register
  103.                  call video_enable              ;timer was 0 when a keypress
  104.                                                 ;occured, so make the screen
  105.                                                 ;visible
  106.                  pop dx                         ;restore dx register
  107.                  pop ax                         ;restore ax register
  108. reset_count:     mov count,0cc8h                ;reset timer to 3 min. then 
  109.                                                 ;return to caller (KYLOCK.COM)
  110.                  iret
  111. unblank          endp
  112.  
  113. ;
  114. ;------------------------------------------------------------------------------
  115. ;VIDEO ENABLE and VIDEO DISABLE enable and disable the VIDEO output to the
  116. ;screen of the PCJR
  117. ;------------------------------------------------------------------------------
  118. ;
  119. video_disable    proc near                      ;disable the video display
  120.                  cmp adapter,0                  ;is video adapter an EGA?
  121.                  je ega_disable                 ;yes, then jump
  122.                  test adapter,2                 ;is computer a PCJR?
  123.                  jnz jr_disable                 ;yes, then jump
  124. ;
  125. ;Disable video of PC with CGA or MDA adapter.
  126. ;
  127.                  push ds                        ;save ds
  128.                  mov ax,bios_data               ;set es to bios data area
  129.                  mov ds,ax
  130.                  assume ds:bios_data
  131.                  mov al,crt_mode_set            ;get current value (dynamic) of
  132.                                                 ;6845 mode control register
  133.                  mov pc_mode,al                 ;save it
  134.                  mov ax,addr_6845               ;get active display address
  135.                  add ax,4                       ;add 4 to get MSR address
  136.                  mov msr_address,ax             ;save address
  137.                  mov al,0ah                     ;out 6845 index register...
  138.                  mov dx,03b4h                   ;points to 6845 data reg. 10
  139.                  out dx,al
  140.                  mov al,2bh                     ;value to turn off cursor
  141.                  mov dx,03b5h                   ;6845 data registers port
  142.                  out dx,al                      ;disable cursor
  143.                  mov dx,msr_address             ;6845 mode control register
  144.                  mov al,pc_mode                 ;get current value of 6845 mode
  145.                  and al,37h                     ;strip enable bit
  146.                  out dx,al                      ;disable video display
  147.                  pop ds                         ;restore ds
  148.                  ret
  149. ;
  150. ;disable video of PC with an EGA card.
  151. ;
  152. ega_disable:     xor al,al                      ;zero al (clear bit 5)
  153.                  call set_ega                   ;disable EGA
  154.                  ret
  155. ;
  156. ;Disable video of PCJR.
  157. ;
  158. jr_disable:      push ds                        ;save ds register
  159.                  mov ax,bios_data               ;set es to bios data area
  160.                  mov ds,ax                      ;                              
  161.                  assume ds:bios_data            ;                              
  162.                  mov al,crt_mode_set            ;get current value (dynamic) of
  163.                                                 ;PCJR VGA mode control register
  164.                  mov pcjr_mode,al               ;store current value, VGA mode
  165.                  mov dx,03dah                   ;PCJR VGA I/O port 
  166.                  in  al,dx                      ;addr/data f/f to proper state
  167.                  mov al,02h                     ;VGA border color register
  168.                  out dx,al                      ;set VGA to border color cont.
  169.                  mov al,00h                     ;color black
  170.                  out dx,al                      ;set border color black
  171.                  mov al,00                      ;VGA mode control 1 register
  172.                  out dx,al                      ;set VGA to mode control 1
  173.                  mov al,pcjr_mode               ;get current value of VGA mode
  174.                  and al,0f7h                    ;strip enable bit
  175.                  out dx,al                      ;disable video display
  176.                  pop ds                         ;restore ds register
  177.                  ret
  178. video_disable    endp
  179. ;
  180. video_enable     proc near                      ;enable the video display
  181.                  cmp adapter,0                  ;is video adapter an EGA?
  182.                  je ega_enable                  ;yes,then jump
  183.                  test adapter,2                 ;is the computer a PCJR?
  184.                  jnz jr_enable                  ;yes, then jump
  185. ;
  186. ;Enable video of PC with CGA or MDA adapter card.
  187. ;
  188.                  mov al,0ah                     ;out 6845 index register...
  189.                  mov dx,03b4h                   ;points to 6845 data reg. 10
  190.                  out dx,al
  191.                  mov al,0bh                     ;value to turn cursor on
  192.                  mov dx,03b5h                   ;6845 data registers port
  193.                  out dx,al                      ;enable cursor
  194.                  mov dx,msr_address             ;6845 mode control register
  195.                  mov al,pc_mode                 ;get stored value 6845 mode
  196.                  out dx,al                      ;enable pc display
  197.                  ret
  198. ;
  199. ;Enable video of PC with an EGA adapter card.
  200. ;
  201. ega_enable:      mov al,20h                     ;set bit 5 of al
  202.                  call set_ega                   ;enable EGA video
  203.                  ret
  204. ;
  205. ;Enable video of PCJR.
  206. ;
  207. jr_enable:       mov dx,03dah                   ;set PCJR VGA address
  208.                  in al,dx                       ;addr/data f/f to proper state
  209.                  mov al,00h                     ;VGA mode control 1 register
  210.                  out dx,al                      ;set VGA to mode control 1
  211.                  mov al,pcjr_mode               ;get stored value VGA mode
  212.                  out dx,al                      ;enable PCJR video display ...
  213.                                                 ;border remains black
  214.                  ret
  215. video_enable     endp
  216. ;
  217. ;-----------------------------------------------------------------------------
  218. ;SET_EGA is called by VIDEO_ENABLE and VIDEO_DISABLE routines to selectively
  219. ;set or clear bit 5 of the EGA Attribute Address Register.
  220. ;Entry:  AL - value to OUT to Attribute Address Register
  221. ;-----------------------------------------------------------------------------
  222. ;
  223. set_ega          proc near
  224.                  push ax                        ;save AL
  225.                  mov dx,3bah                    ;reset monochrome flip-flop...
  226.                  in al,dx                       ;for write to Address Register
  227.                  mov dx,3dah                    ;reset color flip-flop
  228.                  in al,dx
  229.                  mov dx,3c0h                    ;set DX to Attr Addr Register
  230.                  pop ax                         ;retrieve entry value of AL
  231.                  out dx,al                      ;write value to register
  232.                  ret
  233. set_ega          endp
  234. ;
  235. ;------------------------------------------------------------------------------
  236. ;INITIALIZE routine checks if SCRNOFF3 has already been loaded.  If it has,
  237. ;execution aborts with an error message.  If it hasn't, then the value of 
  238. ;ADAPTER is set according to the type of display adapter present in the system
  239. ;and the vectors in low memory pointing to the INT 9h and 16h routines are set
  240. ;to point to our own newly installed code.
  241. ;------------------------------------------------------------------------------
  242. ;
  243. initialize       proc near
  244. ;
  245. ;See if SCRNOFF3 has been previously loaded by calling INT 16h with AH set to
  246. ;254 and BH set to 0.  If BH comes back unchanged, then SCRNOFF3 is NOT
  247. ;currently resident in memory; if BH = 255, then SCRNOFF3 has been loaded.
  248. ;
  249.                  mov ah,127                     ;set AH and BH
  250.                  xor bh,bh
  251.                  int 16h                        ;call interrupt routine
  252.                  or bh,bh                       ;is BH = 0?
  253.                  je init1                       ;yes, then continue
  254.                  lea dx,errmsg                  ;no, print error message & exit
  255.                  mov ah,09h
  256.                  int 21h
  257.                  ret
  258. ;
  259. ;Check the computer's ID to see if its a PC or PCJR.
  260. ;
  261. init1:           mov ax,0f000h                  ;es to BIOS segment holding
  262.                  mov es,ax                      ;computer ID value
  263.                  mov al,byte ptr es:[0fffeh]    ;offset address and load to al
  264.                  sub al,0fch                    ;
  265.                  or al,al                       ;al = 0?
  266.                  jz pc                          ;AT, try the pc routine...
  267.                  dec al                         ;al = 1?
  268.                  jz pcjr                        ;yes, then computer is a PCJR
  269.                  dec al                         ;al = 2?
  270.                  jz pc                          ;XT, try the PC routine...
  271.                  dec al                         ;al = 3?
  272.                  jz pc                          ;PC
  273.                  jnz pc                         ;unidentified computer, try PC
  274.                  ret
  275. ;
  276. ;The computer is a PCJR.
  277. ;
  278. pcjr:            mov adapter,2                  ;set adapter to PCJR
  279.                  jmp init2                      ;jump to install program
  280. ;
  281. ;The computer is a PC.  Check for the presence of an Enhanced Graphics Adapter
  282. ;by looking for an 'IBM'signature in the EGA Bios area.
  283. ;
  284. pc:              mov ax,0c000h                  ;set ES to EGA BIOS segment
  285.                  mov es,ax
  286.                  mov di,1eh                     ;starting address of signature
  287.                  lea si,ibm_signature           ;point si to 'IBM' text
  288.                  mov cx,3                       ;three characters to check
  289.                  cld                            ;clear df
  290.                  repe cmpsb                     ;compare the three bytes
  291.                  je init2                       ;signature found - EGA present
  292. ;
  293. ;The computer is a PC, but the display adapter is not an EGA.  It must be
  294. ;either a CGA or an MDA.
  295. ;
  296.                  mov adapter,1                  ;set ADAPTER for CGA or MDA
  297. ;
  298. ;Save the current interrupt 1Ch vector and replace it with a new routine.
  299. ;
  300. init2:           mov ah,35h                     ;DOS function - get vector
  301.                  mov al,1ch                     ;interrupt 1ch
  302.                  int 21h                        ;get the vector
  303.                  mov int_1ch_ptr,bx             ;save offset of vector
  304.                  mov int_1ch_ptr[2],es          ;save segment of vector
  305.                  mov ah,25h                     ;DOS function - set vector
  306.                  mov al,1ch                     ;interrupt 1ch
  307.                  lea dx,countdown3              ;point - countdown3 routine
  308.                  int 21h                        ;set vector
  309. ;                                               
  310. ;Save the current interrupt 16h vector and replace it with a new routine.
  311. ;
  312.                  mov ah,35h                     ;DOS function - get vector
  313.                  mov al,16h                     ;interrupt 16h
  314.                  int 21h                        ;get the vector
  315.                  mov int_16h_ptr,bx             ;save offset of vector
  316.                  mov int_16h_ptr[2],es          ;save segment of vector
  317.                  mov ah,25h                     ;DOS function - set vector
  318.                  mov al,16h                     ;interrupt 16h
  319.                  lea dx,new_int_16h             ;pointer to new routine
  320.                  int 21h                        ;set vector
  321. ;
  322. ;Set user vector interrupt 4dh to unblank routine.
  323. ;
  324.                  mov ah,25h                     ;DOS function - set vector
  325.                  mov al,4dh                     ;interrupt 4dh
  326.                  lea dx,unblank                 ;point to unblank routine
  327.                  int 21h                        ;set vector
  328.                  mov dx,(offset initialize - seg_org + 15) shr 4     ;...
  329.                                                 ;prepare DX for exit
  330.                  mov ah,31h                     ;terminate-but-stay-resident
  331.                  int 21h                        ;dos function call
  332. initialize       endp
  333. ;
  334. code             ends
  335.                  end begin
  336.                             
  337.