TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: ALL
from: LOU SANDERS
date: 1995-04-15 08:22:00
subject: Print With Color.

Hello All!
This routine can save a lot of LOCATE and COLOR source code. Bytes 0 to 15 
are reserved bytes for color and can be placed anywhere within the string to 
allow the change of color.
Example:
Source$ = chr$(0) + chr$(15) + "Hello" + chr$(0) + chr$(14) " World!"
or
'set global variables
dim Black  as shared string : Black  = chr$(0)
dim White  as shared string : White  = chr$(15)
dim Yw.Bk  as shared string : Yw.Bk  = chr$(0) + chr$(14)
Source$ = Black + White + "Hello" + Yw.Bk + " World!"
PrintColor Source$, 1,1
This would print "Hello" white on black and " World!" yellow on black.
It retains the last color set. So the next time this function is called the
color would be yellow on black background.
PrintColor Source$,1,1  'would be yellow on black background.
  bit pattern
7 6 5 4 3 2 1 0
1 . . . . . . . Blinking of froeground character
  1 . . . . . . Red background color
    1 . . . . . Green background color
      1 . . . . Blue background color
        1 . . . Intensity foreground color
          1 . . Red foreground color
            1 . Green foreground color
              1 Blue foreground color
The routine below uses some of the built in procedures and variables in 
PowerBASIC.
If you would like to see more code like the routine below let me know and I 
will post it from time to time. if not, say so I'll keep it to myself and not 
bore you with simple routines. You won't hurt my feelings...
Have fun...
TTYL:
Lou Sanders
=== Cut ===
Comment|
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Title PrintColor
FileName PrColor.Asm
Copyright (c) 1993 Lou Sanders
Revised for TASM April 1995 by Lou Sanders
Asm routine for PowerBasic 3.1
BackGround$ = CHR$(0) ... CHR$(15) background color
ForeGround$ = CHR$(0) ... CHR$(15) foreground color
Declare Syntax:
Declare Sub PrintColor(Source$,byval Row,Byval Column)
To print White foreground on black background
Call: PrintColor Background$        +  ForeGround$       + Source$, Row, Col
                 CHR$(0)...CHR$(15)    CHR$(0)...CHR$(15)
Compiled with  MicroSoft MASM 6.0    ML /c PrColor.Asm
Compiled with  Borland's TASM 2.0    TASM PrColor.Asm
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ|
    ;PowerBASIC's internal procedures and variables
    Extrn      GetStrLoc      :Far        ;PowerBASIC internal procedure
    Extrn      PbvScrnBuff    :DWord      ;segment and offset to screen 
uffer
    Extrn      PbvScrnCols    :Byte       ;current column count
    Extrn      PbvScrnTxtAttr :Word       ;current text attribute
    Code Segment Byte Public 'Code'
    Assume cs:Code
Source$    EQU       ;segment and offset to string handle
Xrow       EQU       ;byval Xrow
Xcol       EQU       ;byval Xcol
PopStack = (2 * 2) + (1 * 4)
    Public PrintColor
    PrintColor Proc Far
        push   bp                ;Basic setup
        mov    bp,sp             ;
        push   ds                ;
        push   es                ;
        push   di                ;
        push   si                ;
        xor    ch,ch             ;clear upper cx
        mov    cl,ss:PbvScrnCols ;number of screen columns
        add    cx,cx             ;add attribute bytes
        mov    ax,ss:XRow        ;ax holds starting row
        cmp    ax,1              ;row can not enter this routine less then 1
        jb     Exit              ;if row less then 1 exit
        dec    ax                ;row starts a zero, so adjust start row
        mul    cx                ;(columns * row)
        mov    dx,ss:XCol        ;starting column
        cmp    dx,1              ;column can not enter this routine less then 
1
        jb     Exit              ;if less then 1 leave
        dec    dx                ;column start at zero, so adjust column
        add    ax,dx             ;add the columns
        add    ax,dx             ;and the attribute bytes
        mov    di,ax             ;make di point to first print row and column
        les    ax,ss:PbvScrnBuff ;es holds the screen segment
        lds    si,ss:Source$     ;setup for PowerBASIC GetStrLoc call
        push   [si]              ;put the string handle on the stack
        Call    FAR PTR GETSTRLOC ;PowerBASIC internal procedure
        JCXZ    EXIT              ;leave if string has no length
        mov    ds,dx              ;segment, string buffer
        mov    si,ax              ;offset, string buffer
        cld                         ;set the direction flag forward
        mov    bx,ss:PbvScrnTxtAttr ;PowerBASIC's internal variable
        mov    ah,bl                ;lower bx holds the attribute
        mov    bl,4                 ;get ready for our bit shift later
NextByte: ;Check for color bytes here
          ;this routine is very important, FixLength strings could contain
          ;the Nul character and be mistaken for a color change.
          ;So make sure to trim the string before passing it to this
          ;routine. The length of "CX" is checked with each byte below 10h
          ;but nul characters could cause the color change to be Black on
          ;Black, if not trimed off!
        lodsb                    ;get byte from string buffer
        cmp   al,0Fh             ;is it a color byte?
        ja    WriteChar          ;it's a printable byte
        mov   ah,al              ;assume it's background color
        xchg  bl,cl              ;get the shift count
        sal   ah,cl              ;move the lower four bits to upper four bits
        xchg  bl,cl              ;restore cl, bl holds the shift count
        dec   cx                 ;sub one from the string length count
        jcxz  Exit               ;are we at zero? if so somethings wrong, 
exit!
        lodsb                    ;get byte from string buffer
        cmp   al,0Fh             ;is it a color byte?
        ja    WriteChar          ;is it a printable byte
        add   ah,al              ;Now we have foreground and background 
olors
        dec   cx                 ;sub one from cx, are we at zero?
        jcxz  Exit               ;if so exit, something went wrong!
        jmp   short NextByte     ;do it again until we're done
WriteChar: ;printable bytes comes here
        mov  byte ptr ss:PbvScrnTxtAttr,ah ;hey, it works...
        stosw                              ;move the char to screen buffer
        loop NextByte                      ;get another byte from string 
buffer
Exit:
        pop   si                 ;Basic cleanup
        pop   di                 ;
        pop   es                 ;
        pop   ds                 ;
        pop   bp                 ;
        Ret   PopStack           ;
        PrintColor Endp
        Code       Ends
                   End
Comment|
=== Cut ===
--- GoldED/2 2.50.Beta5+
---------------
* Origin: The Basic OutPost System (1:143/333)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.