;       Static Name Aliases
;
        TITLE   vputbox
;       NAME    vputbox.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  _vputbox
_vputbox        PROC NEAR
        push    bp
        mov     bp,sp
        mov     ax,16
        call    __chkstk
        push    si
        push    di

;       row = 4
;       col = 6
;       width = 8
;       height = 10
;       attr = 12
;       battr = 14
;       retrace = 16
;       frame = 18
;       register si = c
;       scr_ofs = -8
;       vstart = -12
;       iwid = -2
;       iht = -16
;       i = -14

        mov     ax,[bp+8]       ;width
        sub     ax,2
        mov     [bp-2],ax       ;iwid

        mov     ax,[bp+10]      ;height
        sub     ax,2
        mov     [bp-16],ax      ;iht

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

        mov     WORD PTR [bp+16],0      ;retrace
        mov     ax,0b000h
        jmp     short $vstart
$color:
        mov     ax,0b800h

$vstart:
        mov     es,ax           ;vstart seg

        mov     ax,160
        mov     bx,[bp+4]       ;row
        mul     bx              ;row
        mov     bx,[bp+6]       ;col
        shl     bx,1
        add     ax,bx
        push    ax
        mov     di,ax           ;scr_ofs offset

        mov     si,[bp+18]      ;frame
        mov     ax,[si]
        mov     ah,BYTE PTR [bp+14]      ;battr

        mov     dx,[bp+16]               ;retrace
        mov     cx,1
        call    vput

        mov     bx,[bp+18]              ;frame
        mov     al,BYTE PTR [bx+8]
        mov     cx,[bp-2]               ;iwid
        call    vput

        mov     bx,[bp+18]      ;frame
        mov     al,BYTE PTR [bx+2]
        mov     cx,1
        call    vput

        mov     cx,[bp-16]      ;iht
        jcxz    $JCC336
$WC29:
        pop     ax
        add     ax,160                  ;vstart
        mov     di,ax
        push    ax
        push    cx

        mov     bx,[bp+18]               ;frame
        mov     ax,[bx+10]
        mov     ah,BYTE PTR [bp+14]      ;battr
        mov     cx,1
        call    vput

        mov     bx,[bp+18]               ;frame
        mov     ax,[bx+12]
        mov     ah,BYTE PTR [bp+12]      ;attr
        mov     cx,[bp-2]
        call    vput

        mov     bx,[bp+18]      ;frame
        mov     ax,[bx+10]
        mov     ah,BYTE PTR [bp+14]      ;battr
        mov     cx,1
        call    vput

        pop     cx
        loop    $WC29
$JCC336:

        pop     ax
        add     ax,160                  ;vstart
        mov     di,ax

        mov     bx,[bp+18]      ;frame
        mov     ax,[bx+4]
        mov     ah,BYTE PTR [bp+14]      ;battr
        mov     cx,1
        call    vput

        mov     bx,[bp+18]      ;frame
        mov     al,BYTE PTR [bx+8]
        mov     cx,[bp-2]
        call    vput

        mov     bx,[bp+18]      ;frame
        mov     al,BYTE PTR [bx+6]
        mov     cX,1
        call    vput

cleanup:
        pop     di
        pop     si
        mov     sp,bp
        pop     bp
        ret

_vputbox        ENDP

vput    proc    near

        jcxz    $out
chloop:
        cmp     dx,0                    ;retrace
        je      $stashit

        push    dx
        push    ax
        mov     dx,3dah
$wait1:
        in      al,dx
        test    al,1
        jne     $wait1
        cli
$wait2:
        in      al,dx
        test    al,1
        je      $wait2
        pop     ax
        pop     dx
$stashit:
        stosw
        sti
        loop    chloop
$out:
        ret

vput    endp

_TEXT   ENDS
END
