BASIC Screen Techniques

(Reading MSDOS.BASIC.SCREEN.TIPS, listing time = 3:14)

BASIC Screen Techniques

                       Dave Gardner

                       Phoenix PC Users Group

One problem  about  the IBM BASIC interpreter
is  the  speed  at  which   the   screen   is
displayed.  On the market today you can  find
many  products devoted to  aiding  the  BASIC
programmer in screen development  and  screen
display.  Most of these products use assembly
language routines  to  directly  POKE  screen
contents  into video RAM.  This  practice  is
indeed  fast,   but  it  causes  problems  of
hardware  and software compatibility.   BASIC
offers some procedures, calls and  functions,
which can greatly increase the speed at which
screens can be changed.  In this article some
of these  procedures will be presented.  This
article does  not cover every possible aspect
introductory  knowledge  of  them.    Through
experimentation,  they  can  be  developed to
meet your own specific needs.

The  hardware of the IBM PC supports the  use
of a color and a monochrome screen.  For both
screens there  is  an  area  in  memory which
holds  the  current  contents  (character  or
graphics)  of  that  screen.   The  areas  in
memory  are  located  at   &HB0000   for  the
monochrome screen, and &HB8000 for the  color
screen.   In   text   mode,  to  represent  a
character position  on  the screen, two bytes
are required.  The first  byte  contains  the
ASCII value of the character  to be displayed
and the  second  byte contains a color code.
Therefore  to  calculate the number of  bytes
needed to represent an entire screen of data,
we would use the following equation:

rows X columns X 2 = # of bytes needed
25   X   80    X 2 = 4000 bytes needed
If you compare the length of available screen
area  and  the  size  required  to  contain a
screen on the  color  graphics  card, you can
see  there  is extra  space  provided.   This
space  can  be  used  to  contain  additional
screens  of information to be displayed at  a
later time.  The video portion of  the system
normally displays the contents  of the lowest
portion  of  these  blocks  of memory on  the
screen.  A simple command  can  be  issued to
Šthe video system instructing it to change and
point to  another  address  within the screen
area.  Since  the  video  screen  is merely a
copy of the RAM area in memory, the change is
done  instantly.   BASIC  provides  a  SCREEN
command to do this.  The format of the screen
command is:

SCREEN A,B,C,D

Where:

A=Screen mode (O=Text display)

B=Burst mode  (1=colored text)

C=Active page (0-3 to indicate
the "Page" within the screen area
that is currently being written
to from BASIC)

D=Visual page (0-3 to indicate
the "Page" within the screen area
that the user currently is viewing)

This  command can be used  to  alter  screens
very quickly.  I have  included  two programs
which  demonstrate  how to use this  command.
The  first  program takes a "picture" of  the
current screen and saves it into a file.  The
second  program  reads  in  several of  these
picture  files and places  them  in  separate
"page"  areas  of the  video  RAM.  When  the
pictures have  all  been  read,  the  program
waits for you to press a key.   Each  time  a
key  is  pressed,  the next page of video  is
displayed.   Try  holding down the space  bar
and  see  how quickly the screen is changed.
To exit the program, type an upper case  "X".
In  addition to loading screen pages  from  a
file, you also can change  the  active screen
and use  normal  "print"  statements to build
them.  When the screen has been completed you
can then use the SCREEN command to change the
"active" screen to the "visual" screen.

The following  commands  can  be  useful  for
changing and developing screens:

SCREEN  BSAVE  BLOAD
DEF SEG  COLOR  PRINT

][][][][][][][][][][][][][][

10 '  Sample program #1
Š
20 '  This program creates three files containing different colored screens
30 '
40 KEY OFF
50 COLOR 7,1:CLS:PRINT TAB(30);"All blue  screen":GOSUB 100
60 COLOR 0,2:CLS:PRINT TAB(30);"All green screen":GOSUB 100
70 COLOR 0,4:CLS:PRINT TAB(30);"All red   screen":GOSUB 100
80 COLOR 7,0:CLS:END
90 '
100 '  Subroutine to take the current contents of the screen and save it in
110 '  a file.  The file name starts out at "SCRN0001.BIN" and the numeric
120 '  portion is incremented by one each time this subroutine is called.
130 '
140 SCN%=SCN%+1      : '  Add to previous screen file number
150 DEF SEG=&HB800   : '  Change to &HB000 for monochrome screen
160 SCN$="SCRN"+"000"+RIGHT$(STR$(SCN%),1)+".BIN" : ' Build name
170 BSAVE SCN$,0,4000 : '  Write out entire screen to file
180 RETURN

][][][][][][][][][][][][][][

100 '  Sample program #2   "DISPLAY.BAS"
110 '  This program reads and displays screen files
120 '
130 COLOR 15,5 : CLS
140 PRINT "Reading screen files...."
150 FOR X=1 TO 3
160    SCN$="SCRN"+"000"+RIGHT$(STR$(X),1)+".BIN"
170    ON ERROR GOTO 250
180       OPEN SCN$ FOR INPUT AS #1 : CLOSE #1
190    ON ERROR GOTO 0
200    DEF SEG=&HB800        :' Change to %HB000 for monochrome screen
210    BLOAD SCN$,(X*&H1000) :' load screen to appropriate "page"
220 NEXT X
230 X=3:GOTO 260
240 '
250 X=X-1:RESUME 260     :'  Come here if 3 screens not available
260 PRINT X; "screens read, press space bar to change screens"
270 Y=1                      :'  loop through all available screens
280    A$=INKEY$ : IF A$="" THEN 280 :       'Wait for user to press a key
290    IF A$="x" THEN SCREEN 0,1,0,0 : END : 'Stop program if user type "x"
300    SCREEN 0,1,Y,Y
310    Y = (Y+1) MOD (X+1)
320    GOTO 280                            : 'Display next screen and loop


end of file

Comments

Popular posts from this blog

BOTTOM LIVE script

Fawlty Towers script for "A Touch of Class"