; program  : monitorabschaltung
; syntax   : a86
; datum    : 25.08.1988

vid        equ 010
inicount   equ 1*60*18    ; minuten *60*18
cgaport    equ 03d8
mgaport    equ 03b8
mgamode    equ 7
true       equ 1
false      equ 0

dos        macro
           mov ah,#1
           int 021
#em

link       macro
           mov al,#1
           dos 035
           mov word ptr #2,bx
           mov word ptr 2[#2],es
           mov dx,offset #3
           mov al,#1
           dos 025
#em

start:     jmp init
count      dw inicount
oldint09   dw 00,00
oldint0b   dw 00,00
oldint0c   dw 00,00
oldint1c   dw 00,00
enabled    db true
event      db false
table      db 02c,028,02d,029,02a,02e,01e,029
int09:     proc far
           mov cs:[event],true
           jmp far cs:[oldint09]

int0b:     proc far
           mov cs:[event],true
           jmp far cs:[oldint0b]

int0c:     proc far
           mov cs:[event],true
           jmp far cs:[oldint0c]
           endp

getmod:    proc near
           mov ah,0f
           int vid
           mov dx,cgaport
           cmp al,mgamode
           jne getmod1
           mov dx,mgaport

getmod1:   mov bl,al
           xor bh,bh
           mov al,cs: bx[table]
           ret

int1c:     proc far
           push ax
           push bx
           push dx
           dec cs:[count]
           jne l01
           mov cs:[count],inicount
           mov cs:[enabled],false
           call getmod
           and al,0f7
           out dx,al
l01:       test cs:[event],true
           je end1c
           mov cs:[count],inicount
           mov cs:[event],false
           test cs:[enabled],true
           jne end1c
           mov cs:[enabled],true
           call getmod
           out dx,al
end1c:     pop dx
           pop bx
           pop ax
           jmp far cs:[oldint1c]
init:      proc near
           cli
           link 01c,oldint1c,int1c
           link 09,oldint09,int09
           link 0b,oldint0b,int0b
           link 0c,oldint0c,int0c
           sti
           mov dx,offset msg
           dos 9
           int 027
msg        db "saver ist installiert"
           db 13,10,10,"$"

