home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / PCVFREEZ.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-11-01  |  7.0 KB  |  356 lines

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