home *** CD-ROM | disk | FTP | other *** search
- ; pcvscan.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
-
- PSEG
- ;------------------------------------------------------------------------------;
- EGA_LINEBYTES equ 320/8
-
- VGA_LINEBYTES equ 320
-
- VIA_LINES equ 240
- VIA_LINEWORDS equ 320
- VIA_LINEBYTES equ 640
- VIA_BANKSIZE equ 1024
-
- VIAQUICKMASK equ 1111011111011110b ; knocks out low bits of r, g, and b
-
- tbuf db 8 dup(0)
- planes dd 4 dup(0)
- nplanes dw 0
- abort dd 0
- progdseg dw 0
-
- DevLineByteso2 db 0
- DevLineBytesx1 dw 0
- DevLineBytesx2 dw 0
- DevLineBytesx3 dw 0
- DevLineBytesx6 dw 0
- Pix64set dw 0
- DevLineBytesxLines dw 0
-
- ;; testpix dw 0 ;; !!! for debugging
-
- ;------------------------------------------------------------------------------;
- ; via_evgacapture(unsigned viaseg, unsigned viareg,
- ; byte **pmplanes, int pmnplanes,
- ; boolean (*abortfunc)(void), int lines)
- ; write into pixmap planes the grey value of each VIA pixel.
- ; NOTE: THE PIXMAP MUST BE 1, 2 OR 4 PLANES,
- ; 320 x 240 pixels = 80 x 240 bytes IF lines IS 240, OR
- ; 320 x 200 pixels = 80 x 200 bytes IF lines IS 200, OR
- ; 320 x 120 pixels = 80 x 120 bytes IF lines IS 120, OR
- ; NOTE ALSO: ONLY FAR_PROC MEMORY MODELS SUPPORTED
-
- pubproc via_evgacapture <viaseg, viareg, pmplanes, dptr, pmnplanes, abortfunc, cptr, lines>
- push bp
- mov bp, sp
-
- pushm <ds, es, di, si>
-
- mov ax, [bp].pmnplanes
- mov cs:nplanes, ax
-
- les cx, [bp].abortfunc
- mov dx, es
- or dx, cx
- mov dx, es
- jnz saveab
- mov cx, offset dummyabort
- mov dx, seg dummyabort
- saveab:
- mov word ptr cs:abort, cx
- mov word ptr cs:abort+2, dx
-
- mov progdseg, ds
-
- IF FAR_DATA
- lds bx, [bp].pmplanes
- ELSE
- mov bx, [bp].pmplanes
- ENDIF
- mov ax, ds
- cmp cs:nplanes, 1
- jne multiplanes
- mov word ptr cs:planes, bx
- mov word ptr cs:planes+2, ax
- jmp short setvia
- multiplanes:
- mov es, ax
-
- IF FAR_DATA
- lds dx, es:[bx+0*4]
- ELSE
- mov dx, es:[bx+0*2]
- ENDIF
- mov word ptr cs:planes+0*4, dx
- mov ax, ds
- mov word ptr cs:planes+0*4+2, ax
-
- IF FAR_DATA
- lds dx, es:[bx+1*4]
- ELSE
- mov dx, es:[bx+1*2]
- ENDIF
- mov word ptr cs:planes+1*4, dx
- mov ax, ds
- mov word ptr cs:planes+1*4+2, ax
-
- ;it's easier to just load 'em up than to test nplanes and quit
-
- IF FAR_DATA
- lds dx, es:[bx+2*4]
- ELSE
- mov dx, es:[bx+2*2]
- ENDIF
- mov word ptr cs:planes+2*4, dx
- mov ax, ds
- mov word ptr cs:planes+2*4+2, ax
-
- IF FAR_DATA
- lds dx, es:[bx+3*4]
- ELSE
- mov dx, es:[bx+3*2]
- ENDIF
- mov word ptr cs:planes+3*4, dx
- mov ax, ds
- mov word ptr cs:planes+3*4+2, ax
- setvia:
- mov ax, [bp].viaseg ; get via address segment in ds
- mov ds, ax
-
- mov cs:DevLineByteso2, EGA_LINEBYTES/2
- mov cs:DevLineBytesx1, EGA_LINEBYTES
- mov cs:DevLineBytesx2, EGA_LINEBYTES*2
- mov cs:DevLineBytesx3, EGA_LINEBYTES*3
- mov cs:DevLineBytesx6, EGA_LINEBYTES*6
- mov cs:Pix64set, 64/8
-
- mov cs:DevLineBytesxLines, EGA_LINEBYTES*120
- cmp word ptr [bp].lines, 120
- je linesset
- mov cs:DevLineBytesxLines, EGA_LINEBYTES*200
- cmp word ptr [bp].lines, 200
- je linesset
- mov cs:DevLineBytesxLines, EGA_LINEBYTES*240
- linesset:
-
- mov dx, offset evgapix ; pixfunc
- call via_domatch
- mov ax, 0
- adc ax, 0 ; return 1 if carry set indicates user abort
-
- popm <si, di, es, ds>
- pop bp
- ret
- endproc via_evgacapture
- ;------------------------------------------------------------------------------;
- ; via_mcgacapture(unsigned viaseg, unsigned viareg,
- ; byte **pmplanes, int pmnplanes,
- ; boolean (*abortfunc)(void))
- ; write into vga pixmap the grey value of each VIA pixel.
- ; NOTE: THE PIXMAP MUST BE 1 PLANE, BYTE PER PIXEL, 320 x 200 pixels/bytes.
- ; NOTE ALSO: ONLY FAR_PROC MEMORY MODELS SUPPORTED
-
- pubproc via_mcgacapture <viaseg, viareg, pmplanes, dptr, pmnplanes, abortfunc, cptr>
- push bp
- mov bp, sp
-
- pushm <ds, es, di, si>
-
- mov ax, [bp].pmnplanes
- mov cs:nplanes, ax
-
- les cx, [bp].abortfunc
- mov dx, es
- or dx, cx
- mov dx, es
- jnz vsaveab
- mov cx, offset dummyabort
- mov dx, seg dummyabort
- vsaveab:
- mov word ptr cs:abort, cx
- mov word ptr cs:abort+2, dx
-
- mov progdseg, ds
-
- IF FAR_DATA
- lds bx, [bp].pmplanes
- ELSE
- mov bx, [bp].pmplanes
- ENDIF
- mov ax, ds
- mov word ptr cs:planes, bx
- mov es, ax
-
- mov ax, [bp].viaseg ; get via address segment in ds
- mov ds, ax
-
- mov cs:DevLineByteso2, VGA_LINEBYTES/2
- mov cs:DevLineBytesx1, VGA_LINEBYTES
- mov cs:DevLineBytesx2, VGA_LINEBYTES*2
- mov cs:DevLineBytesx3, VGA_LINEBYTES*3
- mov cs:DevLineBytesx6, VGA_LINEBYTES*6
- mov cs:Pix64set, 64
- mov cs:DevLineBytesxLines, VGA_LINEBYTES*200
-
- mov dx, offset mcgapix ; pixfunc
- call via_domatch
- mov ax, 0
- adc ax, 0 ; return 1 if carry set indicates user abort
-
- popm <si, di, es, ds>
- pop bp
- ret
- endproc via_mcgacapture
- ;------------------------------------------------------------------------------;
-
- igroup equ BL ; current group of 4 interlaced sets of via lines
- bank equ BH ; currently selected bank of via memory
- goffs equ CX ; offset of current pixel in current group on vga
- boffs equ SI ; offset of current pixel in current bank
- ooffs equ DI ; offset of current pixel in output pixmap
- iline equ AH ; (current line in group + init val) mod 3 (says when to skip a line)
- iblock equ AL ; current block in line out of 5 (from -1 to 4)
- ;viaseg equ DS ; segment address of via registers and memory bank.
- ;pmseg equ ES ; segment address of vga pixbuf.
-
- via_domatch proc
-
- cld
- mov igroup, 0
- grouploop:
- mov al, cs:DevLineByteso2 ; set up starting VGA group output address;
- mul igroup ; starting ooffs = igroup * DevLineBytes
- shl ax, 1
- cmp DevLineByteso2, VGA_LINEBYTES/2 ; if vga, add plane addr to ooffs
- jne novga ; because we're going to blast right through
- add ax, word ptr cs:planes ; start offset of pixbuf in es:
- novga:
- mov ooffs, ax
-
- cmp cs:DevLineBytesxLines, EGA_LINEBYTES*120
- jne not120
- shl igroup, 1 ; double the group to skip group 1 for 120 lines
- not120:
- cmp igroup, 3
- jbe notdone
- jmp doneimage ; note: if we jump here, cf=0
- notdone:
-
- mov si, [bp].viareg ; si is boffs so we can trash it
- mov bank, igroup
- mov ds:[si], bank ; set bank switch
-
- mov goffs, 0
- mov boffs, 0
-
- mov iline, igroup
- shr iline, 1
- xor iline, 1 ; set iline to 2 in groups 0,1; 1 in groups 2,3
- inc iline
-
- mov iblock, 5
-
- offsloop:
- call dx ;pixfunc ; Do whatever with 64 pixels in pix
- add goffs, cs:Pix64set ; boffs and ooffs are done in pixfunc.
-
- dec iblock ; fall through to lineend when we get to 5
- jnz midline
- lineend:
- mov iblock, 5
-
- cmp cs:DevLineBytesxLines, EGA_LINEBYTES*240
- je img240
- cmp cs:DevLineBytesxLines, EGA_LINEBYTES*120
- je img120
- ;--------------
- img200:
- inc iline
- cmp iline, 3
- jb skip3
- skip4:
- test igroup, 1
- jz noskip ; only skip 3rd via line in groups 1,3
- mov iline, 1
- add boffs, VIA_LINEBYTES ; ignore one via line
- add ooffs, cs:DevLineBytesx6 ; skip to next-next vga line
- jmp short doneimgx ;(doneskip4)
- noskip:
- mov iline, 0
- add ooffs, cs:DevLineBytesx3 ; skip 3 vga lines to next line in group
- doneskip4:
- jmp short doneimgx
- skip3:
- add ooffs, cs:DevLineBytesx2 ; skip 2 vga lines to next line in group
- jmp short doneimgx
- ;--------------
- img240:
- add ooffs, cs:DevLineBytesx3 ; skip 3 vga lines to next line in group
- jmp short doneimgx
- ;--------------
- img120:
- add ooffs, cs:DevLineBytesx1 ; skip 1 vga line to next line in group
- ;--------------
- doneimgx:
- cmp ooffs, cs:DevLineBytesxLines ; test for end of this group
- jb midline
- jmp nextgroup
- midline:
- cmp boffs, VIA_BANKSIZE
- jb samebank
- sub boffs, VIA_BANKSIZE
- add bank, 4
- push si
- mov si, [bp].viareg ; si is boffs so we can trash it
- mov ds:[si], bank ; set bank switch
- call checkabort ; check for user abort (si not preserved)
- pop si
- jc doneimage ; and quit if abort requested
- samebank:
- jmp offsloop
- nextgroup:
- inc igroup
- jmp grouploop
- doneimage: ; carry is set for abort; is not set on normal return
- ret
- via_domatch endp
- ;------------------------------------------------------------------------------;
- evgapix proc
- pushm <ax, bx, cx>
-
- mov cx, 64
- egaloop:
- lodsw ; get via pixel
- ;; mov ax, ss:testpix ;;; !!! debugging
- ;; inc ss:testpix
-
- ; customized version of pixunpack ; Take pix in ax, end with avg grey in al
- mov bh, al
- and bh, 00011111b ; 5 bit blue in bh
-
- shr ax, 1
- shr ax, 1
- mov bl, ah
- and bl, 00111110b ; add 6 bit red in bl
-
- add bh, bl
- shr bl, 1 ; add 5 bit red from bl
- add bl, bh ; bl now has blue + 3*red
-
- shr ax, 1
- shr al, 1
- and al, 01111110b ; 7 bit green in al
- add al, bl ; al now has blue/2 + 3*red/2 + 4*green/2 = wtd sum*8/2
- ; al is 8 bit grey value
-
- ; write ega pixel to buffers
- dec cx
- mov bx, cx
- and bx, 7
- mov cs:tbuf[bx], al ; stash grey value
- jnz egaloop ; if not a group of 8, loop again
-
- ; save the 8 saved bytes in ega format 4 planes
-
- shl cs:tbuf[0], 1
- rcr ah, 1
- shl cs:tbuf[1], 1
- rcr ah, 1
- shl cs:tbuf[2], 1
- rcr ah, 1
- shl cs:tbuf[3], 1
- rcr ah, 1
- shl cs:tbuf[4], 1
- rcr ah, 1
- shl cs:tbuf[5], 1
- rcr ah, 1
- shl cs:tbuf[6], 1
- rcr ah, 1
- shl cs:tbuf[7], 1
- rcr ah, 1
-
- cmp cs:nplanes, 1
- ja save2
-
- les bx, cs:planes[0*4]
- mov es:[bx+di], ah
- jmp donesave
- save2:
- shl cs:tbuf[0], 1
- rcr al, 1
- shl cs:tbuf[1], 1
- rcr al, 1
- shl cs:tbuf[2], 1
- rcr al, 1
- shl cs:tbuf[3], 1
- rcr al, 1
- shl cs:tbuf[4], 1
- rcr al, 1
- shl cs:tbuf[5], 1
- rcr al, 1
- shl cs:tbuf[6], 1
- rcr al, 1
- shl cs:tbuf[7], 1
- rcr al, 1
-
- cmp cs:nplanes, 2
- ja save3
-
- les bx, cs:planes[1*4]
- mov es:[bx+di], ah
- les bx, cs:planes[0*4]
- mov es:[bx+di], al
- jmp donesave
- save3:
- les bx, cs:planes[3*4]
- mov es:[bx+di], ah
- les bx, cs:planes[2*4]
- mov es:[bx+di], al
-
- shl cs:tbuf[0], 1
- rcr ah, 1
- shl cs:tbuf[1], 1
- rcr ah, 1
- shl cs:tbuf[2], 1
- rcr ah, 1
- shl cs:tbuf[3], 1
- rcr ah, 1
- shl cs:tbuf[4], 1
- rcr ah, 1
- shl cs:tbuf[5], 1
- rcr ah, 1
- shl cs:tbuf[6], 1
- rcr ah, 1
- shl cs:tbuf[7], 1
- rcr ah, 1
-
- shl cs:tbuf[0], 1
- rcr al, 1
- shl cs:tbuf[1], 1
- rcr al, 1
- shl cs:tbuf[2], 1
- rcr al, 1
- shl cs:tbuf[3], 1
- rcr al, 1
- shl cs:tbuf[4], 1
- rcr al, 1
- shl cs:tbuf[5], 1
- rcr al, 1
- shl cs:tbuf[6], 1
- rcr al, 1
- shl cs:tbuf[7], 1
- rcr al, 1
-
- les bx, cs:planes[1*4]
- mov es:[bx+di], ah
- les bx, cs:planes[0*4]
- mov es:[bx+di], al
-
- donesave:
- inc di
- jcxz done64
- jmp egaloop
-
- done64:
- popm <cx, bx, ax>
- ret
- evgapix endp
- ;------------------------------------------------------------------------------;
- mcgapix proc
- pushm <ax, bx, cx>
-
- mov cx, 64
- bwloop:
- lodsw ; get via pixel
- ;; mov ax, ss:testpix ;;; !!! debugging
- ;; inc ss:testpix
-
- ; customized version of pixunpack ; Take pix in ax, end with avg grey in al
- mov bh, al
- and bh, 00011111b ; 5 bit blue in bh
-
- shr ax, 1
- shr ax, 1
- mov bl, ah
- and bl, 00111110b ; add 6 bit red in bl
-
- add bh, bl
- shr bl, 1 ; add 5 bit red from bl
- add bl, bh ; bl now has blue + 3*red
-
- shr ax, 1
- shr al, 1
- and al, 01111110b ; 7 bit green in al
- add al, bl ; al now has blue/2 + 3*red/2 + 4*green/2 = wtd sum*8/2
-
- shr al, 1
- shr al, 1 ; weighted gray average = al/(8/2).
-
- stosb ; write vga pixel
- loop bwloop
-
- popm <cx, bx, ax>
- ret
- mcgapix endp
- ;------------------------------------------------------------------------------;
- checkabort proc ; return with carry set if user wants to abort.
- push ax
- push bx
- push cx
- push dx
- push di ; save all registers (bp is preserved, si already saved)
- push ds
- push es
-
- mov ax, progdseg ; restore es and ds for abort call
- mov es, ax
- mov ds, ax
-
- call dword ptr cs:abort
- add ax, -1 ; set carry flag if ax is non-zero
-
- pop es
- pop ds
- pop di
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- checkabort endp
- ;------------------------------------------------------------------------------;
- dummyabort proc far
- xor ax, ax
- ret
- dummyabort endp
- ;------------------------------------------------------------------------------;
- ENDPS
- end
- ;------------------------------------------------------------------------------;
-