home *** CD-ROM | disk | FTP | other *** search
- ; pcvfreeze.asm
- ;
- ; 5/5/88 by Ted
- ;
- ; Low Level RAM functions for OWL
- ;
- ; Copyright (c) 1988, 1989 Oakland Group Inc.
- ; ALL RIGHTS RESERVED
- ;
- ;------------------------REVISION HISTORY--------------------------------------;
- ;------------------------------------------------------------------------------;
- include PCDECL.MAC
-
- extproc pc_hTimer
- extproc dig_SubHsecs ;!!! renamed this - jmd 5/5/89
-
- CRTCINDEX = 0400h
- INDEX1 = 07h
- INDEX2 = 1Eh
-
- CRTCDATA = 0401h
- VAL1 = 3Dh
- VAL1S = 3Ch
- VAL2 = 00h
- VAL2S = 84h
-
- CNTRLREG = 0402h
- FREEZE0BIT = 01h
- SYNC0BIT = 02h
-
- STATUSREG = 0403h
- VSYNCBIT = 02h
- FIELDBIT = 80h
-
- VSYNCREG = 0403h
- VSYNCBIT = 02h
- ;------------------------------------------------------------------------------;
- DSEG
- retrace dw 0
- ENDDS
- ;------------------------------------------------------------------------------;
- PSEG
- ;------------------------------------------------------------------------------;
- ; via_freeze (unsigned addr);
- ; /* Lock the via image and unsync the video */
- ; /* CRT controller first, then register. */
-
- pubproc via_freeze <addr>
- push bp
- mov bp, sp
- push es
-
- mov ax, [bp].addr
- mov es, ax
-
- cmp retrace, 0
- jnz doretracef
- call setretrace
- jc fnogood
- doretracef:
- call retrace
-
- ; freeze and unsync control reg
- cli
- mov al, es:[CNTRLREG]
- and al, not FREEZE0BIT ; set freeze by clearing freeze bit
- or al, SYNC0BIT ; free sync by setting sync bit
-
- call setcntrl
- sti
- jc fnogood
-
- ; unsync CRTC
- mov byte ptr es:[CRTCINDEX], INDEX1
- mov byte ptr es:[CRTCDATA], VAL1
- mov byte ptr es:[CRTCINDEX], INDEX2
- mov byte ptr es:[CRTCDATA], VAL2
-
- mov ax, 1
- pop es
- pop bp
- ret
-
- fnogood:
- mov ax, 0
- ;; mov ax, 1 ;;; !!! debug
- pop es
- pop bp
- ret
- endproc via_freeze
- ;------------------------------------------------------------------------------;
- ; /* Sync the video and unlock the via image */
- ; /* Register first, then CRT controller. */
- ; via_unfreeze (unsigned addr);
-
- pubproc via_unfreeze <addr>
- push bp
- mov bp, sp
- push es
-
- mov ax, [bp].addr
- mov es, ax
-
- cmp retrace, 0
- jnz doretrace
- call setretrace
- jc unogood
- doretrace:
- call retrace
-
- ; sync CRTC
- mov byte ptr es:[CRTCINDEX], INDEX1
- mov byte ptr es:[CRTCDATA], VAL1S
- mov byte ptr es:[CRTCINDEX], INDEX2
- mov byte ptr es:[CRTCDATA], VAL2S
-
- ; sync and unfreeze control reg
- cli
- mov al, es:[CNTRLREG]
- and al, not SYNC0BIT ; lock sync by clearing sync bit
- or al, FREEZE0BIT ; unfreeze image by setting freeze bit
-
- call setcntrl
- sti
- jc unogood
-
- call fldretrace ; wait a frame or two for new image to get in
- call fldretrace ; before returning
- call fldretrace
- jc unogood
-
- mov ax, 1
- pop es
- pop bp
- ret
- unogood:
- mov ax, 0
- ;; mov ax, 1 ;;; !!! debug
- pop es
- pop bp
- ret
- endproc via_unfreeze
- ;------------------------------------------------------------------------------;
- pubproc via_testretrace <addr>
- push bp
- mov bp, sp
- push es
-
- mov ax, [bp].addr
- mov es, ax
-
- call fldretrace
- jc tnogood
- sti
- mov ax, 1
- pop es
- pop bp
- ret
- tnogood:
- mov ax, 0
- ;; mov ax, 1 ;;; !!! debug
- pop es
- pop bp
- ret
- endproc via_testretrace
- ;------------------------------------------------------------------------------;
- setcntrl proc
- push ax
- push es
- push ax
- ocall pc_hTimer ; start in-vsync timer
- add sp, 2
- mov bx, ax
- pop es
- pop ax
-
- inloops:
- mov cx, 8000 ; loop waiting for change in field bit
- inloops1:
- mov es:[CNTRLREG], al
- cmp es:[CNTRLREG], al
- je dones
- loop inloops1
-
- push ax
- mov ax, 8
- call istimeout ; test timeout
- pop ax
- jc inloops ; if not timed out, do waiting loop again
-
- stc ; if timed out, quit
- ret
-
- dones:
- clc
- ret
- setcntrl endp
- ;------------------------------------------------------------------------------;
- setretrace proc
- mov retrace, offset vsretrace
- call retrace
- jnc doneset
-
- mov retrace, offset fldretrace
- call retrace
- jnc doneset
- noset:
- mov retrace, 0
- stc
- ret
- doneset:
- clc
- ret
- setretrace endp
- ;------------------------------------------------------------------------------;
- ; VIA internal retrace poll - always fails on my MCB VIA board but is required
- ; on my PC BUS VIA board to set the sync control flag.
- ; Wait for end of current vsync(if in it) and start of fresh vsync period
- ; Returns w/carry flag set if timeout w/ no retrace found.
- ; Note!!! : if no timeout, retrace returns with interrupts disabled
-
- vsretrace proc near
-
- push es
- push ax
- ocall pc_hTimer ; start in-vsync timer
- add sp, 2
- mov bx, ax
- pop es
-
- inloopb:
- mov cx, 8000 ; loop waiting for end of vsync
- inloopb1:
- mov al, es:[STATUSREG]
- cli
- test al, VSYNCBIT
- jz outofb ; not in vsync - success
- sti
- loop inloopb1
-
- mov ax, 8
- call istimeout ; test in-vsync timer
-
- jnc timeoutb1 ; if timed out, quit
- jmp inloopb ; otherwise do waiting loop again
-
- outofb:
- push es
- push ax
- ocall pc_hTimer ; start out-of-vsync timer
- add sp, 2
- mov bx, ax
- pop es
-
- inloopnb:
- mov cx, 8000 ; loop waiting for start of new vsync
- inloopnb1:
- mov al, es:[STATUSREG]
- test al, VSYNCBIT
-
- jnz doneb ; in vsync - success
- loop inloopnb1
-
- mov ax, 12
- call istimeout ; test in-vsync timer
- ; if timed out, quit
- jc inloopnb ; otherwise do waiting loop again
-
- timeoutb:
- sti
- timeoutb1:
- stc
- ret
- doneb:
- clc
- ret
- vsretrace endp
- ;------------------------------------------------------------------------------;
- ; Wait for end of current field state
- ; Returns w/carry flag set if timeout w/ no retrace found.
- ; Note!!! : if no timeout, retrace returns with interrupts disabled
-
- fldretrace proc near
-
- push es
- push ax
- ocall pc_hTimer ; start in-vsync timer
- add sp, 2
- mov bx, ax
- pop es
-
- inloop:
- mov ah, es:[STATUSREG]
- and ah, FIELDBIT
- mov cx, 8000 ; loop waiting for change in field bit
- cli
- inloop1:
- mov al, es:[STATUSREG]
- and al, FIELDBIT
-
- cmp al, ah
- jne done ; bit changed - success
- loop inloop1
- sti
-
- mov ax, 8
- call istimeout ; test in-vsync timer
- ; if timed out, quit
- jc inloop ; otherwise do waiting loop again
- timeout:
- stc
- ret
-
- done:
- clc
- ret
- fldretrace endp
- ;------------------------------------------------------------------------------;
- istimeout proc ; ax = duration, bx = starttime.
-
- push bx
- push es ; preserve es and bx
-
- push ax ; save duration
- push bx ; save starttime
-
- push dx ; junk for pcdata
- ocall pc_hTimer ; start in-vsync timer
- add sp, 2
-
- pop bx ; recover starttime
-
- push ax ; current time
- push bx ; starttime
- ocall dig_SubHsecs ;(tstart, pc_hTimer(pchdata))
- add sp, 4
-
- pop bx ; recover duration
- cmp ax, bx
- ja elapsed
- stc ; set carry = 1
- pop es
- pop bx
- ret
- elapsed: ; carry = 0
- pop es
- pop bx
- ret
- istimeout endp ; carry = 0 if duration has elapsed
- ;------------------------------------------------------------------------------;
- ENDPS
- END
-