_TL EQU 218
_TR EQU 191
_BL EQU 192
_BR EQU 217
_VL EQU 179
_HL EQU 196


MAXWINSAVES EQU 4


windowtype:
        CurWin_Row  db ?
        CurWin_Col  db ?
        CurWin_Hite db ?
        CurWin_Wide db ?
        CurWin_BAtr db ?
        CurWin_FChr db ?
        CurWin      db 1
        scrnblock   dw 0
        scrsave db (MAXWINSAVES*4096) dup(?)

; ws      db 3 dup (windowtype)


savescreen proc far
      push es
      push ds
      mov  al, CurWin
      cmp  al, MAXWINSAVES
      je   savestr_x 
      mov  ax, colorscr
      mov  es, ax
      mov  ax, 0
      mov  si, ax
      mov  ax, offset scrsave
        ;xor  bx, bx
        ;mov  bl, CurWin
        ;xor  dx, dx
        ;mul  bx
      mov  di, ax
      mov  cx, 4000
      call mcopy
       inc CurWin
savestr_x:
      pop  ds
      pop  es
      ret
savescreen endp

restorescreen proc far
      push es
      push ds
      push ds
      pop  es
      mov  al, CurWin
      cmp  al, 1  
      je   restr_x 
      mov  ax, offset scrsave
        ;xor  bx, bx
        ;mov  bl, CurWin
        ;xor  dx, dx
        ;mul  bx
      mov  si, ax
      mov  ax, colorscr
      mov  ds, ax
      mov  ax, 0
      mov  di, ax
      mov  cx, 4000
      call mcopy
       dec CurWin
restr_x:
      pop  ds
      pop  es
      ret
restorescreen endp

framewin proc far
; Input
;       AH - Top row
;       AL - left column
;       BH - number of rows
;       BL - number of columns
;       DH - attribute for frame
;       DL - character fro background
;
; Output
;       None
;
        push    cx
        push    dx
        push    ax
        push    bx
        mov     [CurWin_Row], ah
        mov     [CurWin_Col], al
        mov     [CurWin_Hite], bh
        mov     [CurWin_Wide], bl
        mov     [CurWin_BAtr], dh
        mov     [CurWin_FChr], dl
        mov     bl,'Õ'
        mov     bh,dh
        mov     cx,1
        call    DWriteCH                ; upper left corner
        inc     al
        pop     bx
        push    bx
        dec     bl
        dec     bl                      ; account for left/right edges
        xor     cx,cx
        mov     cl,bl
        mov     bh,dh
        mov     bl,'Í'
        call    DWriteCH                ; top edge
        pop     bx
        push    bx
        dec     bl
        dec     bl
        add     al,bl                   ; end of row
        mov     bh,dh
        mov     bl,'¸'
        mov     cx,1
        call    DWriteCH                ; upper right corner
        pop     bx
        pop     ax
        dec     bh

FW_Loop:

        inc     ah                      ; row counter
        dec     bh                      ; rows to do
        jz      FW_Bottom
        push    ax
        push    bx
        mov     bh,dh
        mov     bl,'³'
        mov     cx,1
        call    DWriteCH                ; left edge
        pop     bx
        push    bx
        add     al,bl
        dec     al
        mov     bh,dh
        mov     bl,'³'
        mov     cx,1
        call    DWriteCH                ; right edge
        pop     bx
        pop     ax
        jmp     FW_Loop

FW_Bottom:

        push    bx
        mov     bl,'Ô'
        mov     bh,dh
        mov     cx,1
        call    DWriteCH                ; lower left corner
        inc     al
        pop     bx
        push    bx
        dec     bl
        dec     bl
        xor     cx,cx   
        mov     cl,bl
        mov     bh,dh
        mov     bl,'Í'
        call    DWriteCH                ; bottom edge
        pop     bx
        push    bx
        dec     bl
        dec     bl
        add     al,bl
        mov     bh,dh
        mov     bl,'¾'
        mov     cx,1
        call    DWriteCH                ; lower right corner
        pop     bx
        pop     dx
        pop     cx

        mov     ah,[CurWin_Row]
        inc     ah
        mov     al,[CurWin_Col]
        inc     al
        mov     bh,[CurWin_Hite]
        dec     bh
        dec     bh
        mov     bl,[CurWin_Wide]
        dec     bl
        dec     bl
        mov     dh,[CurWin_BAtr]
        mov     dl,[CurWin_Fchr]
        call    DFillCH

      ret
framewin endp
        ret

_popbox macro _pby1, _pbx1, _pby2, _pbx2, _pbfc, _pbbc
           _textcolor _pbfc, _pbbc
           mov  al, _pby1
           mov  ah, _pbx1
           mov  bl, _pby2
           mov  bh, _pbx2
           mov  dh, _pbfc
           $textattr
           mov  dl, ' '
           call framewin
        endm

; ===========================================================================
initscrn proc far
; ===========================================================================
      mov     bx,MAXWINSAVES SHR 4
      mov     ah,48H        
      int     21H
      jc      initscrn_ex   
              mov  scrnblock, ax
              mov  ax, 0

      jmp  initscrn_ok
initscrn_ex:
      stc
      ret
initscrn_ok:
      clc
      ret
initscrn endp
