;       Static Name Aliases
;
        TITLE   vbufwin
;       NAME    vbufwin.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
EXTRN   __chkstk:NEAR
_TEXT      SEGMENT

        PUBLIC  _vbufwin
_vbufwin        PROC NEAR
        push    bp
        mov     bp,sp
        mov     ax,10
        call    __chkstk
        push    si
        push    di

;       buffer = 4
;       row = 6
;       col = 8
;       width = 10
;       height = 12
;       direction = 14
;       retrace = 16
;       scr_ofs = -4
;       vstart = -8
;       times = -10

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


        mov     WORD PTR [bp-8],0       ;vstart
        mov     WORD PTR [bp-6],0b000h

        mov     WORD PTR [bp+16],0      ;retrace


        jmp     SHORT $I23
$I22:

        mov     WORD PTR [bp-8],0       ;vstart
        mov     WORD PTR [bp-6],0b800h
$I23:

        mov     ax,160
        mul     WORD PTR [bp+6] ;row
        add     [bp-8],ax       ;vstart

        jmp     SHORT $L20002
$WC24:
        mov     ax,[bp+8]       ;col
        shl     ax,1
        add     ax,[bp-8]       ;vstart
        mov     dx,[bp-6]
        mov     [bp-4],ax       ;scr_ofs
        mov     [bp-2],dx

        mov     ax,[bp+10]      ;width
        mov     [bp-10],ax      ;times

        jmp     SHORT $L20001
$WC26:
        cmp     WORD PTR [bp+16],0      ;retrace
        je      $I28

        mov     dx,3dah
$WC30:
        in      al,dx
        test    al,1
        jnz     $WC30
        cli
$WC32:
        in      al,dx
        test    al,1
        jz      $WC32
$I28:
        cmp     WORD PTR [bp+14],0      ;direction
        jne     $I34

        mov     bx,[bp+4]       ;buffer
        les     si,[bp-4]       ;scr_ofs
        mov     ax,es:[si]
        mov     [bx],ax

        jmp     SHORT $I35
$I34:

        les     bx,[bp-4]       ;scr_ofs
        mov     si,[bp+4]       ;buffer
        mov     ax,[si]
        mov     es:[bx],ax
$I35:
        sti
        add     WORD PTR [bp+4],2       ;buffer
        add     WORD PTR [bp-4],2       ;scr_ofs
        dec     WORD PTR [bp-10]        ;times

$L20001:
        cmp     WORD PTR [bp-10],0      ;times
        jne     $WC26

        dec     WORD PTR [bp+12]        ;height

        add     WORD PTR [bp-8],160     ;vstart

$L20002:
        cmp     WORD PTR [bp+12],0      ;height
        jne     $WC24

        pop     di
        pop     si
        mov     sp,bp
        pop     bp
        ret

_vbufwin        ENDP
_TEXT   ENDS
END
