;       Static Name Aliases
;
        TITLE   vidbuf
;       NAME    vidbuf.C

        .287
_TEXT   SEGMENT  BYTE PUBLIC 'CODE'
_TEXT   ENDS
_DATA   SEGMENT  WORD PUBLIC 'DATA'
_DATA   ENDS
CONST   SEGMENT  WORD PUBLIC 'CONST'
CONST   ENDS
_BSS    SEGMENT  WORD PUBLIC 'BSS'
_BSS    ENDS
DGROUP  GROUP   CONST,  _BSS,   _DATA
        ASSUME  CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
_TEXT      SEGMENT

        PUBLIC  _vidbuf
_vidbuf        PROC NEAR
        push    bp
        mov     bp,sp
        push    si
        push    di
        push    ds

;       vbuff = 4
;       retrace = 6
;       direction = 8

        mov     ah,15
        int     10h
        cmp     al,7
        jne     $color

        mov     WORD PTR [bp+6],0
        mov     ax,0b000h
        jmp     short $dir
$color:
        mov     ax,0b800h
$dir:
        cmp     WORD PTR [bp+8],0
        jne     $put

        xor     si,si                   ;scr_ofs
        mov     ds,ax
        pop     es
        push    es
        mov     di,WORD PTR [bp+4]
        jmp     short $retrace
$put:
        xor     di,di
        mov     es,ax
        mov     si,WORD PTR [bp+4]
$retrace:
        cmp     WORD PTR [bp+6],0
        je      mono

        mov     ah,5    ;i
        cld

$WC66:

        mov     dx,3dah
$vert:
        mov     cx,240
        in      al,dx
        test    al,8
        jnz     $vert

        cli
$vert2:
        in      al,dx
        test    al,8
        jz      $vert2
        rep     movsw
        sti

        mov     cx,160
$hor:
        in      al,dx
        test    al,1
        jnz     $hor

        cli
$hor2:
        in      al,dx
        test    al,1
        jz      $hor2
        movsw
        sti
        loop    $hor
        dec     ah
        jz      done
        jmp     $vert
mono:
        mov     cx,2000
        rep     movsw
done:
        pop     ds
        pop     di
        pop     si
        mov     sp,bp
        pop     bp
        ret

_vidbuf        ENDP
_TEXT   ENDS
END
