                   OPT l-,c+,d-
;
; ModemDTR  -  Brutal way to set DTR off on serial line.
;              First of all! I realy HATE!!!! this. I Sorry. This was my last
;              chance to make an hangup when StarNet and TrapDoor use the serial-
;              line opened in shared mode. No normal hangup will work :-)
;              Once again! I'am sorry. I realy hate this.
;
;              WARNING! This program uses the hardware directly without
;              allocating any resources. This is NOT the way you should
;              talk to the serial port. But in this unusual case it was
;              necessary, by definition. Don't use it as an example...
;
;              Hacked by kc 92-07-23!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

ExecBase                   =      4
BACKGROUND                 =      $dff180  ; Background Color
SERDTR                     =      $bfd000  ; Adress for 8520 (bit 7 is DTR)
pr_CLI                     =      $ac
_LVOFindTask               =      -294
_LVOOpenLibrary            =      -552
_LVOCloseLibrary           =      -414
_LVODelay                  =      -198


		section CODE
		move.l	 sp,initialSP

                           move.l  (ExecBase).w,a6
		suba.l	 a1,a1
		jsr	 _LVOFindTask(a6)
		move.l	 d0,a4
		tst.l	 pr_CLI(a4)
		beq.s   Quit                ; doesn't run from WB

                           moveq   #0,d0
                           lea     DosName,a1
                           jsr     _LVOOpenLibrary(a6)
                           move.l  d0,DosBase         ;Save Dosbase
                           beq.s   Quit               ;Error on open. Exit


TestDTR:
		btst    #7,SERDTR           ; Address for 8520 (bit 7 is DTR)
		beq.s   ClearDTR            ;bit 7 = 0
		bra.s   Quit

ClearDTR:
		bset	 #7,SERDTR           ; Address for 8520 (bit 7 is DTR) bit 7 = 1

wait:
		move.w	 #$0f00,BACKGROUND   ; background = red
                           move.l  DosBase,a6
                           move.l  #100,d1            ;get pointer to alloced mem
                           jsr     _LVODelay(a6)
		move.w	 #$0f00,BACKGROUND   ; background = red


SetDTR:
		bclr	 #7,SERDTR           ; Address for 8520 (bit 7 is DTR) bit 7 = 0

                           move.l  (ExecBase).w,a6
                           move.l  DosBase,a1            ;get Dosbase
                           cmp.l   #0,a1                     ;have we any dosbase?
                           beq.s   Quit                      ;no!
                           jsr     _LVOCloseLibrary(a6)      ;yes close Doslibrary:
Quit:
		move.l	 initialSP,sp
		moveq	 #0,d0
		rts

		section DATA
initialSP:                 dc.l	0
DosBase:                   dc.l   0
DosName:                   dc.b   'dos.library',0
		END
