home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / PCVFREEZ.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-07-06  |  6.9 KB  |  354 lines

  1. ; pcvfreeze.asm
  2. ;
  3. ; 5/5/88 by Ted
  4. ;
  5. ; Low Level RAM functions for OWL
  6. ;
  7. ; Copyright (c) 1988, 1989 Oakland Group Inc.
  8. ; ALL RIGHTS RESERVED
  9. ;
  10. ;------------------------REVISION HISTORY--------------------------------------;
  11. ;------------------------------------------------------------------------------;
  12. include    PCDECL.MAC
  13.  
  14. extproc pc_hTimer
  15. extproc dig_SubHsecs    ;!!! renamed this - jmd 5/5/89
  16.  
  17. CRTCINDEX = 0400h
  18. INDEX1 = 07h
  19. INDEX2 = 1Eh
  20.  
  21. CRTCDATA  = 0401h
  22. VAL1   = 3Dh
  23. VAL1S  = 3Ch
  24. VAL2   = 00h
  25. VAL2S  = 84h
  26.  
  27. CNTRLREG   = 0402h
  28. FREEZE0BIT = 01h
  29. SYNC0BIT   = 02h
  30.  
  31. STATUSREG = 0403h
  32. VSYNCBIT  = 02h
  33. FIELDBIT  = 80h
  34.  
  35. VSYNCREG  = 0403h
  36. VSYNCBIT  = 02h
  37. ;------------------------------------------------------------------------------;
  38. DSEG
  39.     retrace    dw 0
  40. ENDDS
  41. ;------------------------------------------------------------------------------;
  42.     PSEG
  43. ;------------------------------------------------------------------------------;
  44. ; via_freeze (unsigned addr);
  45. ; /* Lock the via image and unsync the video */
  46. ; /* CRT controller first, then register. */
  47.  
  48. pubproc via_freeze <addr>
  49.     push bp
  50.     mov bp, sp
  51.     push es
  52.  
  53.     mov ax, [bp].addr
  54.     mov es, ax
  55.  
  56.     cmp retrace, 0
  57.     jnz doretracef
  58.     call setretrace
  59.     jc fnogood
  60. doretracef:
  61.     call retrace
  62.  
  63. ; freeze and unsync control reg
  64.     cli
  65.     mov al, es:[CNTRLREG]
  66.     and al, not FREEZE0BIT            ; set freeze by clearing freeze bit
  67.     or  al, SYNC0BIT                ; free sync by setting sync bit
  68.     
  69.     call setcntrl
  70.     sti
  71.     jc fnogood
  72.  
  73. ; unsync CRTC
  74.     mov byte ptr es:[CRTCINDEX], INDEX1
  75.     mov byte ptr es:[CRTCDATA],  VAL1
  76.     mov byte ptr es:[CRTCINDEX], INDEX2
  77.     mov byte ptr es:[CRTCDATA],  VAL2
  78.  
  79.     mov ax, 1
  80.     pop es
  81.     pop bp
  82.     ret
  83.  
  84. fnogood:
  85.     mov ax, 0
  86. ;; mov ax, 1        ;;; !!! debug
  87.     pop es
  88.     pop bp
  89.     ret
  90. endproc via_freeze
  91. ;------------------------------------------------------------------------------;
  92. ; /* Sync the video and unlock the via image */
  93. ; /* Register first, then CRT controller. */
  94. ; via_unfreeze (unsigned addr);
  95.  
  96. pubproc via_unfreeze <addr>
  97.     push bp
  98.     mov bp, sp
  99.     push es
  100.  
  101.     mov ax, [bp].addr
  102.     mov es, ax
  103.  
  104.     cmp retrace, 0
  105.     jnz doretrace
  106.     call setretrace
  107.     jc unogood
  108. doretrace:
  109.     call retrace
  110.  
  111. ; sync CRTC
  112.     mov byte ptr es:[CRTCINDEX], INDEX1
  113.     mov byte ptr es:[CRTCDATA],  VAL1S
  114.     mov byte ptr es:[CRTCINDEX], INDEX2
  115.     mov byte ptr es:[CRTCDATA],  VAL2S
  116.  
  117. ; sync and unfreeze control reg
  118.     cli
  119.     mov al, es:[CNTRLREG]
  120.     and al, not SYNC0BIT            ; lock sync by clearing sync bit
  121.     or  al, FREEZE0BIT                ; unfreeze image by setting freeze bit
  122.  
  123.     call setcntrl
  124.     sti
  125.     jc unogood
  126.  
  127.     call fldretrace            ; wait a frame or two for new image to get in
  128.     call fldretrace            ; before returning
  129.     call fldretrace
  130.     jc unogood
  131.  
  132.     mov ax, 1
  133.     pop es
  134.     pop bp
  135.     ret
  136. unogood:
  137.     mov ax, 0
  138. ;; mov ax, 1        ;;; !!! debug
  139.     pop es
  140.     pop bp
  141.     ret
  142. endproc via_unfreeze
  143. ;------------------------------------------------------------------------------;
  144. pubproc via_testretrace <addr>
  145.     push bp
  146.     mov bp, sp
  147.     push es
  148.  
  149.     mov ax, [bp].addr
  150.     mov es, ax
  151.  
  152.     call fldretrace
  153.     jc tnogood
  154.     sti
  155.     mov ax, 1
  156.     pop es
  157.     pop bp
  158.     ret
  159. tnogood:
  160.     mov ax, 0
  161. ;; mov ax, 1        ;;; !!! debug
  162.     pop es
  163.     pop bp
  164.     ret
  165. endproc via_testretrace
  166. ;------------------------------------------------------------------------------;
  167. setcntrl proc
  168.     push ax
  169.     push es
  170.     push ax
  171.     ocall pc_hTimer                    ; start in-vsync timer
  172.     add sp, 2
  173.     mov bx, ax
  174.     pop es
  175.     pop ax
  176.  
  177. inloops:
  178.     mov cx, 8000                    ; loop waiting for change in field bit
  179. inloops1:
  180.         mov es:[CNTRLREG], al
  181.         cmp es:[CNTRLREG], al
  182.         je dones
  183.     loop inloops1
  184.  
  185.     push ax
  186.     mov ax, 8
  187.     call istimeout                    ; test timeout
  188.     pop ax
  189.     jc inloops                    ; if not timed out, do waiting loop again
  190.  
  191.     stc                            ; if timed out, quit
  192.     ret
  193.  
  194. dones:
  195.     clc
  196.     ret
  197. setcntrl endp
  198. ;------------------------------------------------------------------------------;
  199. setretrace proc
  200.     mov retrace, offset vsretrace
  201.     call retrace
  202.     jnc doneset
  203.  
  204.     mov retrace, offset fldretrace
  205.     call retrace
  206.     jnc doneset
  207. noset:
  208.     mov retrace, 0
  209.     stc
  210.     ret
  211. doneset:
  212.     clc
  213.     ret
  214. setretrace endp
  215. ;------------------------------------------------------------------------------;
  216. ; VIA internal retrace poll - always fails on my MCB VIA board but is required
  217. ; on my PC BUS VIA board to set the sync control flag.
  218. ; Wait for end of current vsync(if in it) and start of fresh vsync period
  219. ; Returns w/carry flag set if timeout w/ no retrace found.
  220. ; Note!!! : if no timeout, retrace returns with interrupts disabled
  221.  
  222. vsretrace proc near
  223.  
  224.     push es
  225.     push ax
  226.     ocall pc_hTimer                    ; start in-vsync timer
  227.     add sp, 2
  228.     mov bx, ax
  229.     pop es
  230.  
  231. inloopb:
  232.     mov cx, 8000                    ; loop waiting for end of vsync
  233. inloopb1:
  234.         mov al, es:[STATUSREG]
  235.         cli
  236.         test al, VSYNCBIT
  237.         jz outofb                    ; not in vsync - success
  238.         sti
  239.     loop inloopb1
  240.  
  241.     mov ax, 8
  242.     call istimeout                    ; test in-vsync timer
  243.  
  244.     jnc timeoutb1                    ; if timed out, quit
  245.     jmp inloopb                        ; otherwise do waiting loop again
  246.  
  247. outofb:
  248.     push es
  249.     push ax
  250.     ocall pc_hTimer                    ; start out-of-vsync timer
  251.     add sp, 2
  252.     mov bx, ax
  253.     pop es
  254.  
  255. inloopnb:
  256.     mov cx, 8000                    ; loop waiting for start of new vsync
  257. inloopnb1:
  258.         mov al, es:[STATUSREG]
  259.         test al, VSYNCBIT
  260.  
  261.         jnz  doneb                        ; in vsync - success
  262.     loop inloopnb1
  263.  
  264.     mov ax, 12
  265.     call istimeout                    ; test in-vsync timer
  266.                                     ; if timed out, quit
  267.     jc inloopnb                        ; otherwise do waiting loop again
  268.  
  269. timeoutb:
  270.     sti
  271. timeoutb1:
  272.     stc
  273.     ret
  274. doneb:
  275.     clc
  276.     ret
  277. vsretrace endp
  278. ;------------------------------------------------------------------------------;
  279. ; Wait for end of current field state
  280. ; Returns w/carry flag set if timeout w/ no retrace found.
  281. ; Note!!! : if no timeout, retrace returns with interrupts disabled
  282.  
  283. fldretrace proc near
  284.  
  285.     push es
  286.     push ax
  287.     ocall pc_hTimer                    ; start in-vsync timer
  288.     add sp, 2
  289.     mov bx, ax
  290.     pop es
  291.  
  292. inloop:
  293.     mov ah, es:[STATUSREG]
  294.     and ah, FIELDBIT
  295.     mov cx, 8000                    ; loop waiting for change in field bit
  296.     cli
  297. inloop1:
  298.         mov al, es:[STATUSREG]
  299.         and al, FIELDBIT
  300.  
  301.         cmp al, ah
  302.         jne done                        ; bit changed - success
  303.     loop inloop1
  304.     sti
  305.  
  306.     mov ax, 8
  307.     call istimeout                    ; test in-vsync timer
  308.                                     ; if timed out, quit
  309.     jc inloop                        ; otherwise do waiting loop again
  310. timeout:
  311.     stc
  312.     ret
  313.  
  314. done:
  315.     clc
  316.     ret
  317. fldretrace endp
  318. ;------------------------------------------------------------------------------;
  319. istimeout proc    ; ax = duration, bx = starttime.
  320.  
  321.     push bx
  322.     push es        ; preserve es and bx
  323.  
  324.     push ax        ; save duration
  325.     push bx        ; save starttime
  326.  
  327.     push dx        ; junk for pcdata
  328.     ocall pc_hTimer            ; start in-vsync timer
  329.     add sp, 2
  330.  
  331.     pop bx        ; recover starttime
  332.  
  333.     push ax    ; current time
  334.     push bx    ; starttime
  335.     ocall dig_SubHsecs    ;(tstart, pc_hTimer(pchdata))
  336.     add sp, 4
  337.  
  338.     pop bx    ; recover duration
  339.     cmp ax, bx
  340.     ja    elapsed
  341.     stc            ; set carry = 1
  342.     pop es
  343.     pop bx
  344.     ret
  345. elapsed:        ; carry = 0
  346.     pop es
  347.     pop bx
  348.     ret
  349. istimeout endp    ; carry = 0 if duration has elapsed
  350. ;------------------------------------------------------------------------------;
  351.     ENDPS
  352.     END
  353.  
  354.