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

  1. ; pcvscan.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.     PSEG
  15. ;------------------------------------------------------------------------------;
  16. EGA_LINEBYTES    equ 320/8
  17.  
  18. VGA_LINEBYTES    equ 320
  19.  
  20. VIA_LINES        equ    240
  21. VIA_LINEWORDS    equ    320
  22. VIA_LINEBYTES    equ    640
  23. VIA_BANKSIZE    equ 1024
  24.  
  25. VIAQUICKMASK    equ 1111011111011110b    ; knocks out low bits of r, g, and b
  26.  
  27.     tbuf        db 8 dup(0)
  28.     planes        dd 4 dup(0)
  29.     nplanes        dw 0
  30.     abort        dd 0
  31.     progdseg    dw 0
  32.  
  33.     DevLineByteso2        db  0
  34.     DevLineBytesx1        dw  0
  35.     DevLineBytesx2        dw  0
  36.     DevLineBytesx3        dw  0
  37.     DevLineBytesx6        dw  0
  38.     Pix64set            dw  0
  39.     DevLineBytesxLines    dw  0
  40.  
  41. ;;    testpix        dw 0        ;; !!! for debugging
  42.  
  43. ;------------------------------------------------------------------------------;
  44. ; via_evgacapture(unsigned viaseg, unsigned viareg,
  45. ;                 byte **pmplanes, int pmnplanes,
  46. ;                 boolean (*abortfunc)(void), int lines)
  47. ; write into pixmap planes the grey value of each VIA pixel.
  48. ; NOTE: THE PIXMAP MUST BE 1, 2 OR 4 PLANES,
  49. ; 320 x 240 pixels = 80 x 240 bytes IF lines IS 240, OR
  50. ; 320 x 200 pixels = 80 x 200 bytes IF lines IS 200, OR
  51. ; 320 x 120 pixels = 80 x 120 bytes IF lines IS 120, OR
  52. ; NOTE ALSO: ONLY FAR_PROC MEMORY MODELS SUPPORTED
  53.  
  54. pubproc via_evgacapture <viaseg, viareg, pmplanes, dptr, pmnplanes, abortfunc, cptr, lines>
  55.     push bp
  56.     mov bp, sp
  57.  
  58.     pushm <ds, es, di, si>
  59.  
  60.     mov ax, [bp].pmnplanes
  61.     mov cs:nplanes, ax
  62.  
  63.     les cx, [bp].abortfunc
  64.     mov dx, es
  65.     or dx, cx
  66.     mov dx, es
  67.     jnz saveab
  68.     mov cx, offset dummyabort
  69.     mov dx, seg dummyabort
  70. saveab:
  71.     mov word ptr cs:abort, cx
  72.     mov word ptr cs:abort+2, dx
  73.  
  74.     mov progdseg, ds
  75.  
  76. IF FAR_DATA
  77.     lds bx, [bp].pmplanes
  78. ELSE
  79.     mov bx, [bp].pmplanes
  80. ENDIF
  81.     mov ax, ds
  82.     cmp cs:nplanes, 1
  83.     jne multiplanes
  84.         mov word ptr cs:planes, bx
  85.         mov word ptr cs:planes+2, ax
  86.     jmp short setvia
  87. multiplanes:
  88.         mov es, ax
  89.  
  90. IF FAR_DATA
  91.         lds dx, es:[bx+0*4]
  92. ELSE
  93.         mov dx, es:[bx+0*2]
  94. ENDIF
  95.         mov word ptr cs:planes+0*4, dx
  96.         mov ax, ds
  97.         mov word ptr cs:planes+0*4+2, ax
  98.         
  99. IF FAR_DATA
  100.         lds dx, es:[bx+1*4]
  101. ELSE
  102.         mov dx, es:[bx+1*2]
  103. ENDIF
  104.         mov word ptr cs:planes+1*4, dx
  105.         mov ax, ds
  106.         mov word ptr cs:planes+1*4+2, ax
  107.         
  108. ;it's easier to just load 'em up than to test nplanes and quit
  109.  
  110. IF FAR_DATA
  111.         lds dx, es:[bx+2*4]
  112. ELSE
  113.         mov dx, es:[bx+2*2]
  114. ENDIF
  115.         mov word ptr cs:planes+2*4, dx
  116.         mov ax, ds
  117.         mov word ptr cs:planes+2*4+2, ax
  118.         
  119. IF FAR_DATA
  120.         lds dx, es:[bx+3*4]
  121. ELSE
  122.         mov dx, es:[bx+3*2]
  123. ENDIF
  124.         mov word ptr cs:planes+3*4, dx
  125.         mov ax, ds
  126.         mov word ptr cs:planes+3*4+2, ax
  127. setvia:
  128.     mov ax, [bp].viaseg        ; get via address segment in ds
  129.     mov ds, ax
  130.  
  131.     mov cs:DevLineByteso2, EGA_LINEBYTES/2
  132.     mov cs:DevLineBytesx1, EGA_LINEBYTES
  133.     mov cs:DevLineBytesx2, EGA_LINEBYTES*2
  134.     mov cs:DevLineBytesx3, EGA_LINEBYTES*3
  135.     mov cs:DevLineBytesx6, EGA_LINEBYTES*6
  136.     mov cs:Pix64set, 64/8
  137.  
  138.     mov cs:DevLineBytesxLines, EGA_LINEBYTES*120
  139.     cmp word ptr [bp].lines, 120
  140.     je linesset
  141.         mov cs:DevLineBytesxLines, EGA_LINEBYTES*200
  142.     cmp word ptr [bp].lines, 200
  143.     je linesset
  144.         mov cs:DevLineBytesxLines, EGA_LINEBYTES*240
  145. linesset:
  146.  
  147.     mov dx, offset evgapix    ; pixfunc
  148.     call via_domatch
  149.     mov ax, 0
  150.     adc ax, 0                ; return 1 if carry set indicates user abort
  151.  
  152.     popm <si, di, es, ds>
  153.     pop bp
  154.     ret
  155. endproc via_evgacapture
  156. ;------------------------------------------------------------------------------;
  157. ; via_mcgacapture(unsigned viaseg, unsigned viareg,
  158. ;                 byte **pmplanes, int pmnplanes,
  159. ;                 boolean (*abortfunc)(void))
  160. ; write into vga pixmap the grey value of each VIA pixel.
  161. ; NOTE: THE PIXMAP MUST BE 1 PLANE, BYTE PER PIXEL, 320 x 200 pixels/bytes.
  162. ; NOTE ALSO: ONLY FAR_PROC MEMORY MODELS SUPPORTED
  163.  
  164. pubproc via_mcgacapture <viaseg, viareg, pmplanes, dptr, pmnplanes, abortfunc, cptr>
  165.     push bp
  166.     mov bp, sp
  167.  
  168.     pushm <ds, es, di, si>
  169.  
  170.     mov ax, [bp].pmnplanes
  171.     mov cs:nplanes, ax
  172.  
  173.     les cx, [bp].abortfunc
  174.     mov dx, es
  175.     or dx, cx
  176.     mov dx, es
  177.     jnz vsaveab
  178.     mov cx, offset dummyabort
  179.     mov dx, seg dummyabort
  180. vsaveab:
  181.     mov word ptr cs:abort, cx
  182.     mov word ptr cs:abort+2, dx
  183.  
  184.     mov progdseg, ds
  185.  
  186. IF FAR_DATA
  187.     lds bx, [bp].pmplanes
  188. ELSE
  189.     mov bx, [bp].pmplanes
  190. ENDIF
  191.     mov ax, ds
  192.     mov word ptr cs:planes, bx
  193.     mov es, ax
  194.  
  195.     mov ax, [bp].viaseg        ; get via address segment in ds
  196.     mov ds, ax
  197.  
  198.     mov cs:DevLineByteso2, VGA_LINEBYTES/2
  199.     mov cs:DevLineBytesx1, VGA_LINEBYTES
  200.     mov cs:DevLineBytesx2, VGA_LINEBYTES*2
  201.     mov cs:DevLineBytesx3, VGA_LINEBYTES*3
  202.     mov cs:DevLineBytesx6, VGA_LINEBYTES*6
  203.     mov cs:Pix64set, 64
  204.     mov cs:DevLineBytesxLines, VGA_LINEBYTES*200
  205.  
  206.     mov dx, offset mcgapix    ; pixfunc
  207.     call via_domatch
  208.     mov ax, 0
  209.     adc ax, 0                ; return 1 if carry set indicates user abort
  210.  
  211.     popm <si, di, es, ds>
  212.     pop bp
  213.     ret
  214. endproc via_mcgacapture
  215. ;------------------------------------------------------------------------------;
  216.  
  217. igroup    equ BL ; current group of 4 interlaced sets of via lines
  218. bank    equ BH ; currently selected bank of via memory
  219. goffs    equ CX ; offset of current pixel in current group on vga
  220. boffs    equ SI ; offset of current pixel in current bank
  221. ooffs    equ DI ; offset of current pixel in output pixmap
  222. iline    equ AH ; (current line in group + init val) mod 3 (says when to skip a line)
  223. iblock    equ AL ; current block in line out of 5 (from -1 to 4)
  224. ;viaseg    equ DS ; segment address of via registers and memory bank.
  225. ;pmseg    equ ES ; segment address of vga pixbuf.
  226.  
  227. via_domatch proc
  228.  
  229.     cld
  230.     mov igroup, 0
  231. grouploop:
  232.     mov al, cs:DevLineByteso2    ; set up starting VGA group output address;
  233.     mul igroup                    ; starting ooffs = igroup * DevLineBytes
  234.     shl ax, 1
  235.     cmp DevLineByteso2, VGA_LINEBYTES/2    ; if vga, add plane addr to ooffs
  236.     jne novga                    ; because we're going to blast right through
  237.         add ax, word ptr cs:planes    ; start offset of pixbuf in es:
  238. novga:
  239.     mov ooffs, ax
  240.  
  241.     cmp cs:DevLineBytesxLines, EGA_LINEBYTES*120
  242.     jne not120
  243.         shl igroup, 1    ; double the group to skip group 1 for 120 lines
  244. not120:
  245.     cmp igroup, 3
  246.     jbe notdone
  247.     jmp  doneimage        ; note: if we jump here, cf=0
  248. notdone:
  249.  
  250.     mov si, [bp].viareg            ; si is boffs so we can trash it
  251.     mov bank, igroup
  252.     mov ds:[si], bank            ; set bank switch
  253.  
  254.     mov goffs, 0
  255.     mov boffs, 0
  256.  
  257.     mov iline, igroup
  258.     shr iline, 1
  259.     xor iline, 1            ; set iline to 2 in groups 0,1; 1 in groups 2,3
  260.     inc iline
  261.  
  262.     mov iblock, 5
  263.  
  264. offsloop:
  265.         call dx    ;pixfunc        ; Do whatever with 64 pixels in pix
  266.         add goffs, cs:Pix64set    ; boffs and ooffs are done in pixfunc.
  267.  
  268.         dec iblock                ; fall through to lineend when we get to 5
  269.         jnz  midline
  270.     lineend:
  271.             mov iblock, 5
  272.  
  273.             cmp cs:DevLineBytesxLines, EGA_LINEBYTES*240
  274.             je img240
  275.             cmp cs:DevLineBytesxLines, EGA_LINEBYTES*120
  276.             je img120
  277. ;--------------
  278.         img200:
  279.                 inc iline
  280.                 cmp iline, 3
  281.                 jb skip3
  282.             skip4:
  283.                     test igroup, 1
  284.                     jz noskip                ; only skip 3rd via line in groups 1,3
  285.                         mov iline, 1
  286.                         add boffs, VIA_LINEBYTES    ; ignore one via line
  287.                         add ooffs, cs:DevLineBytesx6    ; skip to next-next vga line
  288.                     jmp short doneimgx ;(doneskip4)
  289.                 noskip:
  290.                     mov iline, 0
  291.                     add ooffs, cs:DevLineBytesx3    ; skip 3 vga lines to next line in group
  292.             doneskip4:
  293.                     jmp short doneimgx
  294.             skip3:
  295.                     add ooffs, cs:DevLineBytesx2    ; skip 2 vga lines to next line in group
  296.                 jmp short doneimgx
  297. ;--------------
  298.         img240:
  299.                 add ooffs, cs:DevLineBytesx3    ; skip 3 vga lines to next line in group
  300.                 jmp short doneimgx
  301. ;--------------
  302.         img120:
  303.                 add ooffs, cs:DevLineBytesx1    ; skip 1 vga line to next line in group
  304. ;--------------
  305.     doneimgx:
  306.             cmp ooffs, cs:DevLineBytesxLines    ; test for end of this group
  307.             jb midline
  308.             jmp nextgroup
  309.     midline:
  310.         cmp boffs, VIA_BANKSIZE
  311.         jb samebank
  312.         sub boffs, VIA_BANKSIZE
  313.         add bank, 4
  314.         push si
  315.         mov si, [bp].viareg            ; si is boffs so we can trash it
  316.         mov ds:[si], bank            ; set bank switch
  317.         call checkabort            ; check for user abort (si not preserved)
  318.         pop si
  319.         jc doneimage            ; and quit if abort requested
  320. samebank:
  321.         jmp offsloop
  322. nextgroup:
  323.     inc igroup
  324.     jmp grouploop
  325. doneimage:            ; carry is set for abort; is not set on normal return
  326.     ret
  327. via_domatch endp
  328. ;------------------------------------------------------------------------------;
  329. evgapix proc
  330.     pushm <ax, bx, cx>
  331.  
  332.     mov cx, 64
  333. egaloop:
  334.     lodsw                        ; get via pixel
  335. ;; mov ax, ss:testpix            ;;; !!! debugging
  336. ;; inc ss:testpix
  337.  
  338. ; customized version of pixunpack ; Take pix in ax, end with avg grey in al
  339.     mov bh, al
  340.     and bh, 00011111b    ; 5 bit blue in bh
  341.  
  342.     shr ax, 1
  343.     shr ax, 1
  344.     mov bl, ah
  345.     and bl, 00111110b    ; add 6 bit red in bl
  346.  
  347.     add bh, bl
  348.     shr bl, 1            ; add 5 bit red from bl
  349.     add bl, bh            ; bl now has blue + 3*red
  350.  
  351.     shr ax, 1
  352.     shr al, 1
  353.     and al, 01111110b    ; 7 bit green in al
  354.     add al, bl            ; al now has blue/2 + 3*red/2 + 4*green/2 = wtd sum*8/2
  355.                         ; al is 8 bit grey value
  356.  
  357.     ; write ega pixel to buffers
  358.     dec cx
  359.     mov bx, cx
  360.     and bx, 7
  361.     mov cs:tbuf[bx], al    ; stash grey value
  362.     jnz egaloop            ; if not a group of 8, loop again
  363.  
  364.     ; save the 8 saved bytes in ega format 4 planes
  365.  
  366.     shl cs:tbuf[0], 1
  367.     rcr ah, 1
  368.     shl cs:tbuf[1], 1
  369.     rcr ah, 1
  370.     shl cs:tbuf[2], 1
  371.     rcr ah, 1
  372.     shl cs:tbuf[3], 1
  373.     rcr ah, 1
  374.     shl cs:tbuf[4], 1
  375.     rcr ah, 1
  376.     shl cs:tbuf[5], 1
  377.     rcr ah, 1
  378.     shl cs:tbuf[6], 1
  379.     rcr ah, 1
  380.     shl cs:tbuf[7], 1
  381.     rcr ah, 1
  382.  
  383.     cmp cs:nplanes, 1
  384.     ja save2
  385.     
  386.     les bx, cs:planes[0*4]
  387.     mov es:[bx+di], ah
  388.     jmp donesave
  389. save2:
  390.     shl cs:tbuf[0], 1
  391.     rcr al, 1
  392.     shl cs:tbuf[1], 1
  393.     rcr al, 1
  394.     shl cs:tbuf[2], 1
  395.     rcr al, 1
  396.     shl cs:tbuf[3], 1
  397.     rcr al, 1
  398.     shl cs:tbuf[4], 1
  399.     rcr al, 1
  400.     shl cs:tbuf[5], 1
  401.     rcr al, 1
  402.     shl cs:tbuf[6], 1
  403.     rcr al, 1
  404.     shl cs:tbuf[7], 1
  405.     rcr al, 1
  406.  
  407.     cmp cs:nplanes, 2
  408.     ja save3
  409.  
  410.     les bx, cs:planes[1*4]
  411.     mov es:[bx+di], ah
  412.     les bx, cs:planes[0*4]
  413.     mov es:[bx+di], al
  414.     jmp donesave
  415. save3:
  416.     les bx, cs:planes[3*4]
  417.     mov es:[bx+di], ah
  418.     les bx, cs:planes[2*4]
  419.     mov es:[bx+di], al
  420.  
  421.     shl cs:tbuf[0], 1
  422.     rcr ah, 1
  423.     shl cs:tbuf[1], 1
  424.     rcr ah, 1
  425.     shl cs:tbuf[2], 1
  426.     rcr ah, 1
  427.     shl cs:tbuf[3], 1
  428.     rcr ah, 1
  429.     shl cs:tbuf[4], 1
  430.     rcr ah, 1
  431.     shl cs:tbuf[5], 1
  432.     rcr ah, 1
  433.     shl cs:tbuf[6], 1
  434.     rcr ah, 1
  435.     shl cs:tbuf[7], 1
  436.     rcr ah, 1
  437.  
  438.     shl cs:tbuf[0], 1
  439.     rcr al, 1
  440.     shl cs:tbuf[1], 1
  441.     rcr al, 1
  442.     shl cs:tbuf[2], 1
  443.     rcr al, 1
  444.     shl cs:tbuf[3], 1
  445.     rcr al, 1
  446.     shl cs:tbuf[4], 1
  447.     rcr al, 1
  448.     shl cs:tbuf[5], 1
  449.     rcr al, 1
  450.     shl cs:tbuf[6], 1
  451.     rcr al, 1
  452.     shl cs:tbuf[7], 1
  453.     rcr al, 1
  454.  
  455.     les bx, cs:planes[1*4]
  456.     mov es:[bx+di], ah
  457.     les bx, cs:planes[0*4]
  458.     mov es:[bx+di], al
  459.  
  460. donesave:
  461.     inc di
  462.     jcxz done64
  463.     jmp egaloop
  464.  
  465. done64:
  466.     popm <cx, bx, ax>
  467.     ret
  468. evgapix endp
  469. ;------------------------------------------------------------------------------;
  470. mcgapix proc
  471.     pushm <ax, bx, cx>
  472.  
  473.     mov cx, 64
  474. bwloop:
  475.     lodsw                        ; get via pixel
  476. ;; mov ax, ss:testpix            ;;; !!! debugging
  477. ;; inc ss:testpix
  478.  
  479. ; customized version of pixunpack ; Take pix in ax, end with avg grey in al
  480.     mov bh, al
  481.     and bh, 00011111b    ; 5 bit blue in bh
  482.  
  483.     shr ax, 1
  484.     shr ax, 1
  485.     mov bl, ah
  486.     and bl, 00111110b    ; add 6 bit red in bl
  487.  
  488.     add bh, bl
  489.     shr bl, 1            ; add 5 bit red from bl
  490.     add bl, bh            ; bl now has blue + 3*red
  491.  
  492.     shr ax, 1
  493.     shr al, 1
  494.     and al, 01111110b    ; 7 bit green in al
  495.     add al, bl            ; al now has blue/2 + 3*red/2 + 4*green/2 = wtd sum*8/2
  496.  
  497.     shr al, 1
  498.     shr al, 1        ; weighted gray average = al/(8/2).
  499.  
  500.     stosb            ; write vga pixel
  501.     loop bwloop
  502.  
  503.     popm <cx, bx, ax>
  504.     ret
  505. mcgapix endp
  506. ;------------------------------------------------------------------------------;
  507. checkabort proc        ; return with carry set if user wants to abort.
  508.     push ax
  509.     push bx
  510.     push cx
  511.     push dx
  512.     push di        ; save all registers (bp is preserved, si already saved)
  513.     push ds
  514.     push es
  515.  
  516.     mov ax, progdseg    ; restore es and ds for abort call
  517.     mov es, ax
  518.     mov ds, ax
  519.  
  520.     call dword ptr cs:abort
  521.     add ax, -1    ; set carry flag if ax is non-zero
  522.  
  523.     pop es
  524.     pop ds
  525.     pop di
  526.     pop dx
  527.     pop cx
  528.     pop bx
  529.     pop ax
  530.     ret
  531. checkabort endp    
  532. ;------------------------------------------------------------------------------;
  533. dummyabort proc far
  534.     xor ax, ax
  535.     ret
  536. dummyabort endp
  537. ;------------------------------------------------------------------------------;
  538.     ENDPS
  539.     end
  540. ;------------------------------------------------------------------------------;
  541.  
  542.