home *** CD-ROM | disk | FTP | other *** search
- ;=============================================================================
- ; High Level Video Routines
- ;
- ; These are routines to display formatted text strings. All registers are
- ; preserved except those used to return parameters. All parameters are passed
- ; through the registers. VIDEO1.INC must be included in the source code.
- ; VIDEO_INIT must be called before any of these routines. It is assumed that
- ; DS = ES = CS.
-
- ;================================================
- ; Global data.
-
- ;--- display attributes
-
- Video_Norm Db 07h ;normal
- Video_Emph Db 02h ;emphasized (underline)
- Video_High Db 70h ;highlight (reverse video)
- Video_Bold Db 0fh ;bold (intense)
-
- ;--- attribute stack
-
- Video_AtrM Equ 10 ;maximum stack entries (n > 0)
- Video_AtrN Dw 0 ;present stack number
- Video_AtrS Db 07h ;start of stack
- Ds Video_AtrM, ? ;rest of stack
-
- ;--- string formatting controls
-
- FrmEnd Equ 0 ;end of string
- FrmCtl Equ 1 ;control character mask
- FrmNorm Equ 2 ;switch to normal attribute
- FrmEmph Equ 3 ;switch to emphasized
- FrmHigh Equ 4 ;switch to highlight
- FrmBold Equ 5 ;switch to bold
- FrmAtr Equ 6 ;user defined attribute
- FrmPush Equ 7 ;push the present attribute
- FrmPop Equ 8 ;pop an attribute
- FrmHor Equ 9 ;horizontally repeated character (left to right)
- FrmVer Equ 10 ;vertically repeated character (up to down)
- FrmStr Equ 11 ;nested string
- FrmLoc Equ 12 ;locate cursor
-
- Video_StrM Equ 10 ;maximum nested strings
-
- ;================================================
- ; Write a formatted string. Note: uses (32 =
- ; Video_AtrM * 2 + 14) stack bytes.
- ;
- ; In: SI= string location.
-
- Video_Wstr Proc Near
- Pushf
- Push Ax
- Push Bx
- Push Cx
- Push Dx
- Push Di
- Push Si
- Push Bp
- Sub Sp, Video_AtrM * 2 + 2 ;room for local data
- Mov Bp, Sp
-
- Cld
- Mov Word [Bp], 0 ;clear nested string stack
- Mov Di, Video_AtrN ;get the present stack number
- Mov Bl, [Video_AtrS + Di] ;get attribute
-
- ;--- loop for each byte in the string
-
- Vidwst1
- Lodsb ;get the next byte
- Cmp Al, FrmEnd ;check if end of string
- Je Vidwst5
- Cmp Al, 32 ;check if control character
- Jb Vidwst2
- Call Video_Wchr ;write character
- Jmps Vidwst1
-
- ;--- control character
-
- Vidwst2
- Mov Di, Offset Video_Ftab ;location of table
-
- Vidwst3
- Cmp Byte [Di], -1 ;check if end of table
- Je Vidwst1 ;jump if so, ignore this character
- Cmp Al, [Di] ;check if match command
- Je Vidwst4 ;jump if so, call command routine
- Add Di, 3 ;next location
- Jmps Vidwst3 ;loop back until end of table or match
-
- Vidwst4
- Call Word [Di + 1] ;call the routine
- Jmps Vidwst1
-
- ;--- check if within nested string
-
- Vidwst5
- Mov Ax, [Bp] ;get the number
- Or Ax, Ax ;check if any entries
- Jz Vidwst6
-
- Dec Ax ;reduce count
- Mov [Bp], Ax ;save it
- Mov Di, Ax
- Shl Di ;times two
- Mov Si, [Bp + 2 + Di] ;get the saved offset
- Jmps Vidwst1 ;continue
-
- ;--- finished, save the attribute in the attribute stack
-
- Vidwst6
- Mov Di, Video_AtrN ;get the present stack number
- Mov [Video_AtrS + Di], Bl ;save attribute
-
- Add Sp, Video_AtrM * 2 + 2 ;fix stack
- Pop Bp
- Pop Si
- Pop Di
- Pop Dx
- Pop Cx
- Pop Bx
- Pop Ax
- Popf
- Ret
- Endp ;Video_Wfstr
-
- ;------------------------------------------------
- ; This is the table to access the formatting
- ; routines below. The table consists of a format
- ; command byte followed by the 16 bit address of
- ; the routine to handle the command. The table
- ; is terminated with a -1 (FFH).
-
- Video_Ftab Label Byte
- Db FrmCtl, Offset Vidwstr1
- Db FrmNorm, Offset Vidwstr2
- Db FrmEmph, Offset Vidwstr3
- Db FrmHigh, Offset Vidwstr4
- Db FrmBold, Offset Vidwstr5
- Db FrmAtr, Offset Vidwstr6
- Db FrmPush, Offset Vidwstr7
- Db FrmPop, Offset Vidwstr8
- Db FrmHor, Offset Vidwstr9
- Db FrmStr, Offset Vidwstr10
- Db FrmLoc, Offset Vidwstr11
- Db FrmVer, Offset Vidwstr12
- Db -1
-
- ;------------------------------------------------
- ; These are the individual routines to handle
- ; the special formatting commands.
-
- ;--- control character mask
-
- Vidwstr1 Proc Near
- Lodsb ;get the character
- Call Video_Wchr ;display
- Ret
- Endp
-
- ;--- normal attribute
-
- Vidwstr2 Proc Near
- Mov Bl, Video_Norm ;set to normal attribute
- Ret
- Endp
-
- ;--- emphasized attribute
-
- Vidwstr3 Proc Near
- Mov Bl, Video_Emph ;set to normal attribute
- Ret
- Endp
-
- ;--- highlighted attribute
-
- Vidwstr4 Proc Near
- Mov Bl, Video_High ;set to normal attribute
- Ret
- Endp
-
- ;--- bold attribute
-
- Vidwstr5 Proc Near
- Mov Bl, Video_Bold ;set to normal attribute
- Ret
- Endp
-
- ;--- user defined attribute
-
- Vidwstr6 Proc Near
- Lodsb ;get the attribute
- Mov Bl, Al ;set attribute
- Ret
- Endp
-
- ;--- push the present attribute
-
- Vidwstr7 Proc Near
- Mov Ax, Video_AtrN ;get the present stack number
- Cmp Ax, Video_AtrM - 1 ;check if stack full
- Jae Vidwstr71
-
- Mov Di, Ax ;load index
- Mov [Video_AtrS + Di], Bl ;save the present attribute
-
- Inc Ax ;increment stack
- Mov Video_AtrN, Ax ;save it
-
- Vidwstr71 Ret
- Endp
-
- ;--- pop an attribute
-
- Vidwstr8 Proc Near
- Mov Ax, Video_AtrN ;get the present stack number
- Or Ax, Ax ;check if at bottom
- Jz Vidwstr81
-
- Dec Ax ;reduce stack number
- Mov Di, Ax ;load index
- Mov Bl, [Video_AtrS + Di] ;set the present attribute
-
- Mov Video_AtrN, Ax ;save stack number
- Vidwstr81 Ret
- Endp
-
- ;--- repeat display a character
-
- Vidwstr9 Proc Near
- Lodsb ;get the character
- Push Ax
- Lodsb ;load the count
- Mov Cl, Al
- Sub Ch, Ch ;count in CX
- Pop Ax
- Call Video_Wchrs ;display characters
- Ret
- Endp
-
- ;--- nested string
-
- Vidwstr10 Proc Near
- Lodsw ;get the offset
- Cmp Word [Bp], Video_StrM ;check if stack full
- Je Vidwstr101
-
- Mov Di, [Bp] ;stack entries
- Shl Di ;times two
- Mov [Bp + 2 + Di], Si ;save present location
- Inc Word [Bp] ;increment entries
- Mov Si, Ax ;new string location
- Vidwstr101 Ret
- Endp
-
- ;--- cursor move
-
- Vidwstr11 Proc Near
- Lodsw ;load location
- Xchg Ah, Al ;get row and column in right register halves
- Mov Dx, Ax
- Call Video_Cset ;set cursor location
- Ret
- Endp
-
- ;--- vertically repeated character
-
- Vidwstr12 Proc Near
- Lodsb ;get the character
- Push Ax
- Lodsb ;load the count
- Mov Cl, Al
- Sub Ch, Ch ;count in CX
- Pop Ax
- Call Video_Cget ;get the cursor location
-
- Vidwstr121
- Push Dx
- Call Video_Wchr ;display character
- Pop Dx
- Inc Dh ;next row
- Call Video_Cset ;set the cursor location
- Loop Vidwstr121
- Ret
- Endp
-
- ;================================================
- ; Calculate the horizontal length of the text in
- ; a formatted string. Note: uses (32 =
- ; Video_AtrM * 2 + 10) stack bytes. Used for
- ; justifying strings.
- ;
- ; In: SI= string location.
- ;
- ; Out: BX= length.
-
- Video_Scnt Proc Near
- Push Ax
- Push Di
- Push Si
- Push Bp
- Sub Sp, Video_AtrM * 2 + 2 ;room for local data
- Mov Bp, Sp
-
- Sub Bx, Bx ;clear the count
- Mov Word [Bp], 0 ;clear nested string stack
-
- ;--- loop for each byte in the string
-
- Vidscn1
- Lodsb ;get the next byte
- Cmp Al, FrmEnd ;check if end of string
- Je Vidscn8
- Cmp Al, 32 ;check if control character
- Jb Vidscn2
- Inc Bx ;increment count
- Jmps Vidscn1
-
- ;--- control character
-
- Vidscn2
- Cmp Al, FrmCtl
- Jne Vidscn3
- Inc Si ;skip character
- Inc Bx ;add to total
- Jmps Vidscn1
-
- ;--- user attribute
-
- Vidscn3
- Cmp Al, FrmAtr
- Jne Vidscn4
- Inc Si ;skip attribute byte
- Jmps Vidscn1
-
- ;--- horizontal repeated byte
-
- Vidscn4
- Cmp Al, FrmHor
- Jne Vidscn5
- Inc Si ;skip character
- Lodsb ;load length
- Sub Ah, Ah
- Add Bx, Ax ;add to total
- Jmps Vidscn1
-
- ;--- nested string
-
- Vidscn5
- Cmp Al, FrmStr
- Jne Vidscn6
- Call Vidwstr10 ;start nested string
- Jmps Vidscn1
-
- ;--- cursor move
-
- Vidscn6
- Cmp Al, FrmLoc
- Jne Vidscn7
- Inc Si
- Inc Si ;skip location
- Jmps Vidscn1
-
- ;--- vertical repeated byte
-
- Vidscn7
- Cmp Al, FrmVer
- Jne Vidscn1
- Inc Si
- Inc Si ;skip byte and count
- Inc Bx ;add one for the first byte
- Jmps Vidscn1
-
- ;--- check if within nested string
-
- Vidscn8
- Mov Ax, [Bp] ;get the number
- Or Ax, Ax ;check if any entries
- Jz Vidscn9
-
- Dec Ax ;reduce count
- Mov [Bp], Ax ;save it
- Mov Di, Ax
- Shl Di ;times two
- Mov Si, [Bp + 2 + Di] ;get the saved offset
- Jmps Vidscn1 ;continue
-
- ;--- finished
-
- Vidscn9
- Add Sp, Video_AtrM * 2 + 2 ;fix stack
- Pop Bp
- Pop Si
- Pop Di
- Pop Ax
- Ret
- Endp ;Video_Scnt
-
- ;================================================
- ; Write a string padded with some character on
- ; both sides.
- ;
- ; In: SI= string location; AL= pad character;
- ; BX= left side pad number; CX= right side pad
- ; number.
-
- Video_Wstrp Proc Near
- Push Bx
- Push Cx
- Push Di
- Mov Di, Video_AtrN ;get the present stack number
- Push Cx
- Mov Cx, Bx
- Mov Bl, [Video_AtrS + Di] ;get attribute
- Call Video_Wchrs ;write preceding spaces
- Call Video_Wstr ;write string
- Pop Cx
- Mov Bl, [Video_AtrS + Di] ;get attribute
- Call Video_Wchrs ;write following spaces
- Pop Di
- Pop Cx
- Pop Bx
- Ret
- Endp ;Video_Wstrp
-
- ;================================================
- ; Write a left justified string.
- ;
- ; In: SI= string location; AL= pad character;
- ; CX= total column width.
-
- Video_Wstrl Proc Near
- Pushf
- Cld
- Push Bx
- Push Cx
- Call Video_Scnt ;get string width
- Cmp Bx, Cx ;check if too big
- Jbe Vidwsl1
- Mov Bx, Cx ;set to maximum length
- Vidwsl1
- Sub Cx, Bx ;get difference
- Sub Bx, Bx ;no padding in front
- Call Video_Wstrp ;print with padding
- Pop Cx
- Pop Bx
- Popf
- Ret
- Endp ;Video_Wstrl
-
- ;================================================
- ; Write a right justified string.
- ;
- ; In: SI= string location; AL= pad character;
- ; CX= total column width.
-
- Video_Wstrr Proc Near
- Pushf
- Cld
- Push Bx
- Push Cx
- Call Video_Scnt ;get string width
- Cmp Bx, Cx ;check if too big
- Jbe Vidwsr1
- Mov Bx, Cx ;set to maximum length
- Vidwsr1
- Sub Cx, Bx ;get difference
- Mov Bx, Cx ;padding is before
- Sub Cx, Cx ;no padding after
- Call Video_Wstrp ;print with padding
- Pop Cx
- Pop Bx
- Popf
- Ret
- Endp ;Video_Wstrr
-
- ;================================================
- ; Write a center justified string.
- ;
- ; In: SI= string location; AL= pad character;
- ; CX= total column width.
-
- Video_Wstrc Proc Near
- Pushf
- Cld
- Push Bx
- Push Cx
- Call Video_Scnt ;get string width
- Cmp Bx, Cx ;check if too big
- Jbe Vidwsc1
- Mov Bx, Cx ;set to maximum length
- Vidwsc1
- Sub Cx, Bx ;get difference
- Mov Bx, Cx
- Shr Bx ;divide by two, preceding pad
- Sub Cx, Bx ;difference is end pad
- Call Video_Wstrp ;print with padding
- Pop Cx
- Pop Bx
- Popf
- Ret
- Endp ;Video_Wstrc
-