'=========================================================================== ' Subject: PRINT TO TEXT SCREEN Date: 03-23-97 (23:11) ' Author: Don Schullian Code: PB ' Origin: d83@ath.forthnet.gr Packet: PB.ABC '=========================================================================== $if 0 Hi, Here's a slightly modified version of the routine I use to print to the text screen. It is extremely fast while still preforming many small, but very useful, functions. 1) locates, sets color, prints a) cursor position is NOT changed b) color values are NOT changed 2) can print using current screen attributes 3) can switch color attribute within a string 4) can turn mouse OFF/ON ( if desired unREM the 4 lines in TPrint) 5) print all string types NOTE: this is accomplished by making a temporary copy of the data to be printed but this will be only 2000 characters at the maximum and causes no noticeable decrease in printing 6) prints to the last row without causing a scroll It will not, however..... a) print using attribute 17 which is blue on blue b) print using attribute 0 which is black on black c) stop at the end of the current video page so some care must be taken by the programmer to insure that there is sufficient room on the screen to hold the text being printed d) check for validity of incoming data PARAMS: Row% = starting text row Col% = starting text column Txt$ = the string data to be printed Attr% = the starting attribute NOTE: if = 0 then the screen's attribute is used NOTE: Attr% = ( BackGround% * 16 ) + Foreground% To change the default attribute within a string one uses a ^Q to indicate that the NEXT character is an attribute value and not a printed character. A single CHR$(17) can be printed by sending a double 17. "^Q^Q" DISCUSSION: Other than being a much quicker and easier way to get your plane- Jane strings onto the screen, Tprint can provide you with much easier menu coding too. My long, scrolling menus move through a stationary bar. This bar is usually has the colors reversed from the other items above and below. With Tprint you need not test if the row you are printing to is the selection bar when you use ZERO for the value of the attribute. The text will be printed in whatever color is found on the screen. So you need only prepare the menu box then commence printing with no more worries about color attributes. Using color attributes can, at first, be a bit confusing when you're used to using the separate background/foreground combination but it will soon become second nature and your favorite attributes will stick in your mind quickly. In the mean time you can either print an attribute chart or you can use HEX numbers for the attribute. &h1F, for example is blue background (1) with hi-white characters (F or 15). Because Tprint uses a copy of the incoming string data you can send all types of string data to it: Dynamic, Flex, Fixed-length, whole TYPE variables, TYPE members, FUNCTION results, etc. SHAMELESS COMMERCIAL PLUG: Tprint, and a whole family of text screen routines, can be found in my Nutz 'n Boltz library. For those of you who do not sell and/or distribute your software and do not wish to have the code may use if for free. It is compiled for and written with native 386 ASM code and PowerBASIC v3.2 and provides hundreds of every-day functions and routines each with a snippet of demo code to show you their uses and provide you with a ready-made playground in which you can explore them without writing lines and lines of code. $endif ' start of test code DECLARE FUNCTION GetStrLoc(BYVAL AllocHandle%) AS LONG COLOR 15, 1 ' screen color white on blue CLS ' LOCATE 13, 17, 1 ' down the middle PRINT "The cursor is here. "; ' cursor/color test DELAY 1 ' ' Bground% = 7 ' Lt.Gray ' this string tests all Fground% = 5 ' Magenta ' properties of Tprint Attr% = ( Bground% * 16 ) + Fground% ' except the use of the Txt$ = "Hello ^Qq World^Qt^Q^Q ^Q " ' ZERO attribute Tprint 1, 1, Txt$, Attr% ' ' DIM Text AS STRING * 20 ' this string tests the Text = "This is ^Qa test." ' ZERO attribute function Tprint 2, 1, Text, 0 ' ' M$ = "This is line # " ' Tprint 3, 1, USING$( M$, 3 ), &h5E ' use FUNCTION results ' TYPE DummyTYPE ' or whole TYPE variables H AS STRING * 6 ' T AS STRING * 2 ' W AS STRING * 7 ' END TYPE ' DIM tD AS DummyTYPE ' tD.H = " Hello" ' tD.T = "^Q " ' tD.W = " World " ' Tprint 25, 68, tD, 47 ' ' DELAY 2 ' PRINT "And it's still here!"; ' prove cursor/color test WHILE NOT INSTAT : WEND ' COLOR 7, 0 LOCATE ,,0 CLS END ' ======================================================================== SUB Tprint(BYVAL Row%,BYVAL Col%,BYVAL Txt$, BYVAL Attr%) LOCAL PUBLIC ! push ds ; save data segment ' ! mov al,&h02 ; mouse off | there are 2 more lines ' ! int &h33 ; | at the bottom of the rtn ! ;;;;;;;;;;;;;;;;;;;;;;;;; ! mov ax,Txt$ ; get/set string handle/address ! push ax ; ! call getstrloc ; call for string data | CX = length ! jcxz TprintDone ; IF CX = 0 GOTO done ! mov ds,dx ; set string segment ! mov si,ax ; set string offset ! ;;;;;;;;;;;;;;;;;;;;;;;;; ! mov ax,&hB800 ; color screen ! mov es,ax ; set video segment ! ;;;;;;;;;;;;;;;;;;;;;;;;; compute/set video offset ! mov ax,Row% ; row number ! dec al ; -1 for ZERO based ! mov bl,160 ; 80 column screens 2bytes @ each ! mul bl ; AX = ( Row? -1 ) * 160 ! mov bx,Col% ; column number ! dec bl ; -1 for ZERO based ! shl bl,1 ; BX = BX * 2 ! add ax,bx ; ! mov di,ax ; set video offset ! ;;;;;;;;;;;;;;;;;;;;;;;;; ! mov ax,Attr% ; set the starting attribute ! mov ah,al ; shift to AH ! mov dl,17 ; attribute trigger CHR$(17) or ^Q ! ;;;;;;;;;;;;;;;;;;;;;;;;; TprintLoop: '; top of print loop ! lodsb ; AL = next char in string ! cmp al,dl ; ! jne TprintDoIt ; IF AL <> ^Q THEN GOTO printing ! dec cx ; decr bytes left to process ! jcxz TprintDone ; IF end of string GOTO done ! lodsb ; AL = next char in string ! cmp al,dl ; ! je TprintDoIt ; IF AL = ^Q THEN GOTO printing ! mov ah,al ; set new attribute ! loop TprintLoop ; loop until CX=0 ! jmp TprintDone ; GOTO all done TprintDoIt: '; ! cmp ah,0 ; ! je TprintNoAttr ; IF attribute = 0 then GOTO ! stosw ; write char and attr to video memory ! loop TprintLoop ; loop until CX=0 ! jmp TprintDone ; GOTO all done TprintNoAttr: '; ! stosb ; write character to video memory ! inc di ; skip over attribute byte ! loop TprintLoop ; loop until CX = 0 ! ;;;;;;;;;;;;;;;;;;;;;;;;; TprintDone: '; ' ! mov al,&h01 ; mouse on ' ! int &h33 ; ! pop ds ; restore data segment END SUB