POKEV AND THE MINI-MEMORY

One of the most powerful aspects ofthe TI Mini-Memory Module is its abilityto access VDP RAM directly through the <POKEV> function. Since the video processor is directly accessed, the monitor screen, which is controlled by the VDP, is also directly accessed. The code entries forthe equivalent of Extended BASIC's <DISPLAY AT> and <COLOR> functions takea little getting used to, but they are actually easier to enter, once you master the conversion factors; and of course they are much faster than anything available in console BASIC. In fact, using <POKEV> to control color is even faster than anything in Extended BASIC.

Here are two possible approaches to using <POKEV> to display a string anywhere on the screen. The first method is the simplest and the fastest. First, you must determine the starting position of your text by row [R] and column [C]. To convert these values to the proper address in VDP RAM you apply this formula: PADDR=((R-1)*32)+C+1. VDP RAM reads the screen left to right and numbers each position consecutively, so the first part of the formula adds 32 places to the address for each complete row and then adds in the column number, correcting for the fact that print column #1 is screen column #3. Once you've determined the screen address in VDP RAM, you simply 'poke' the codes for each character in your string into the VDP RAM in one statement: <CALL POKEV(PADDR,CODE1,CODE2,CODE3...). The character codes in this application are the normal ASCII codes plus 96. This short program illustrates the method.

100 CALL CLEAR 
110 INPUT "ROW? ":R 
120 INPUT "COLUMN? ":C 
130 PADDR=((R-1)*32)+C+1 
140 CALL POKEV(PADDR,180,168,165,128,180,169,128,168,175,173,165,128,163,175,173,176,181,180,165,178) 
150 FOR D=1 TO 1000 
160 NEXT D
170 GOTO 100 

As you experiment with this program you will see that entering row and column values which cause a PADDR higher than 768 will yield some surprising and colorful results, but will not display your string. That's because 768 is the highest screen address in BASIC, and the next higher addresses contain the color tables. I'll demonstrate some easy and useful ways of altering those values later.

If you don't want to have to look up the ASCII value of each character in your string, add 96, and enter a long 'poke list,' you can use a FOR-NEXT loop to display your string. While it's a slower method, it can be put into the form of a useful sub-routine which could be accessed often in a single program.

100 CALL CLEAR 
110 INPUT "ROW? ":R 
120 INPUT "COLUMN? ":C 
130 INPUT "MESSAGE? ":M$ 
140 CALL CLEAR 
150 GOSUB 1000 
160 GOTO 110 
1000 PADDR=((R-1)*32)+C+1 
1010 FOR X=1 TO LEN(M$) 
1020 CALL POKEV(PADDR-1+X, ASC(SEG$(M$,X,1))+96) 
1030 NEXT X 
1040 RETURN 

An equivalent routine could be built using <HCHAR> instead of <POKEV>, but it would run about 16% more slowly. Of course we're not talking about blinding speed in any case, but 16% is an improvement. Another application where both speed and convenience would show up would be updating a short timing or scoring display on agame screen.

100 CALL CLEAR 
110 CALL POKEV(393,179,163,175,178,165,128,157) 
120 FOR X=1 TO 50 
130 RANDOMIZE 
140 SCORE=(99*RND) 
150 IF SCORE>9 THEN 180 
160 CALL POKEV(401,ASC(STR$(SCORE))+96) 
170 GOTO 190 
180 CALL POKEV(401,ASC(STR$(SCORE))+96,ASC(SEG$(STR$(SCORE),2,1))+96) 
190 CALL SOUND(50,2200,0) 
200 NEXT X 

This program is slower than it has to be because it is generating each random score before it is displayed and pausing during the execution of the <SOUND>command.

As I hinted above, you can also use <POKEV> to make direct alterations to the color tables located in VDP RAM. Since one integer value at a single address in the color table sets both the foreground and background colors, you need to enter only two values to fully define any one color set, as opposed to three values in the <COLOR> subroutine, and <POKEV> executes much faster than <COLOR>.

Probably the most useful application of using <POVEV> to define and redefine color sets is to make things flash. Since <POKEV> executes much more quickly than <COLOR>, you can make things flash more rapidly; and since you can alter several color sets virtually instantaneously, you can flash groups of characters in more than one color set...a line of text, for example. Here's a simple program to demonstrate flashing text.

100 BKG=0 
110 FGD=1 
120 CALL CLEAR 
130 PRINT TAB(3);"THIS DEMONSTRATES COLOR" 
140 PRINT TAB(3);"FLASHING USING <POVEV>" 
150 PRINT TAB(3);"AND THE MINI-MEM MODULE"
160 PRINT :::::::: 
170 FOR I=1 TO 50 
180 CC=(16*BKD)+FGD 
190 CALL POKEV(788,CC,CC,CC,CC) 
200 CC=(16*FGD)+BKD 
210 CALL POKEV(788,CC,CC,CC,CC) 
220 NEXT I

The necessary addresses and values are very easy to calculate. In BASIC, the color table for character set one is located at VDP RAM address 784, and the successive addresses control each successive set. Each address holds a two-place hexidecimal value, the right-hand hex digit is the background color code, the left-hand digit is the foreground. These codes are the TI BASIC color codes minus one. To convert the two-place hexidecimal code to decimal you multiply the foreground code by 16 and then add the background code, yielding a decimal value from 0 to 255. In the program, line 180 reverses that calculation to reverse the colors of the text, and line 200 restores the normal values. Lines 190 and 210 push these values into the VDP RAM color table starting at 788, which is the address of character set 5, and into the next three successive addresses and character sets. These four sets include all the upper-case characters. You can see how quickly the color codes of all four sets are altered.

Of course, you could makes the text flash any color combination you want. Try adding these lines to that program:

230 CALL CLEAR 
240 PRINT "ENTER TWO INTEGER VALUES" 
250 PRINT "BETWEEN 0 AND 15. REMEMBE 
260 PRINT "TO SUBTRACT ONE FROM THE" 
270 PRINT "VALUES IN TI BASIC..." 
280 PRINT
290 INPUT "FOREGROUND? ":FGD 
300 INPUT "BACKGROUND? ":BKD 
310 GOTO 170 

Again, equivalent statements exist in Extended BASIC, since you can enter a long parameter list in a <COLOR> statement and alter several color sets at once, but the execution of such a command isn't as fast, so the sequential changes to the several color sets is quite perceptable and destroys the crisp and rapid flash effect of <POKEV>. If you want to make the comparison for yourself, be sure to alter this program to take out lines 180 and 200 which execute between the flashes and slow the program down considerably!

Remember, BASIC and Extended BASIC functions like <COLOR>, <DISPLAY AT> and <HCHAR> are actually whole machine language routines which result in an alteration of the VDP RAM. <POKEV> makes the same alterations directly; that's where it gets its speed.

Richard G. Minutillo

August 15, 1983

-------------------

Back to main TI Page

Back to TI Download Page

This is FABbnet!

-------------------

Document maintained at the Fine-Arts Bluesband, © 2003. Direct comments to rgm at fabbnet.net.