Difference between revisions of "Using VDP with BASIC"

From Ninerpedia
Jump to navigation Jump to search
(Major new article on using POKEV in Basic with Mini Memory (starting with graphics))
 
m (moved BASIC use of VDP to Using VDP with BASIC: Easier to understand title. Will also set up redirect from old one.)
(No difference)

Revision as of 12:50, 12 September 2014

This article shows how you can use the VDP features in a TI BASIC program, for example by using the Mini Memory Module and then selecting BASIC and using the PEEKV and POKEV commands.

Using the MINI MEMORY, you have access to the VDP ram, and you can use this facility to change the definition and colour of the cursor, or even to have a sprite or two running in TI BASIC...

Cursor Definition

The cursor definition is held in VDP RAM 1008 to 1015 (eg 8 bytes). You are used to defining characters with sixteen hexadecimal characters, but your code is translated by the console to 8 bytes:

Each row of pixels can form a binary number of 8 bits, with the left most pixel having a value of 128. Thus a solid block of pixels in one row can be thought of as the binary number 11111111, which in decimal form is: 128+64+32+16+8+4+2+1 =255

For a block cursor, try:

100 CALL POKEV(1008,255,129,129,129,129,
    129,129,255)
110 INPUT A$                    

The cursor will retain its new definition until the console is reset by using NEW or loading a new program.

Cursor colour

The colour of the cursor is defined in VDP RAM 783.

The foreground colour and background colour are contained in a single byte. To separate them you need to divide the byte into two nybbles...

First form the two required colours into binary numbers (binary 0 has a colour value of 1):

WHITE=16 =binary 15 = 1111   
TRANSPARENT=1 = binary 0 = 0000 
Thus a white cursor on a transparent background would be:
11110000 in binary, which is decimal 240. 
To see if this works, try: CALL POKEV(783,240). 

Sprites in Basic

Although TI Basic does not recognise sprites, a small part of the memory used by sprites is free, and by placing values there we can place three sprites on screen (stationary): The sprite definitions must be placed in VDP RAM 768, and are made up of 4 values. The sprite definition must terminate with 208.

The first value is the pixel row (up to 192)
The 2nd value is the pixel column (up to 255)
The third value is the character code (NB: ASCII CODE +96 )
The fourth value is the colour code (-1) 
Thus: 
CALL POKEV(768,98,128,161,1,208)

OR FOR THREE SPRITES:
CALL POKEV(768,98,128,163,1,20,40,164,1,
130,170,165,1,208) 

Moving sprites in TI BASIC

The memory area dealing with sprite velocity is also clear, temporarily, but is used by BASIC for the value stack: in normal operation the computer will remove your velocity data as it moves stack data around. It IS possible to fool the computer though: the top of the stack can be pushed down out of the way by redefining some of the lower case characters (they are usually derived rather than defined, saving memory).

First use:
100 A$="F111"
110 FOR I=96 TO 120
120 CALL CHAR(I,A$)
130 NEXT I          


Now you can move your sprite(s): Velocity is to be placed in VDP RAM 1920-, and each sprite requires 4 bytes. The first two bytes are for row and column velocity (max 255) and the other two are for vdp use.

Having placed velocities in the correct VDP RAM, the computer must be instructed to move them! This is done by loading the number of sprites to be moved into CPU RAM -31878.

After the above memory relocation try:

200 CALL CLEAR   
210 CALL POKEV(768,98,128,161,1,208)   
220 CALL POKEV(1920,50,50)   
230 CALL LOAD(-31878,1)   
240 GOTO 240     

Being able to use one or two sprites can permit some advanced graphic work in your TI Basic programs. Each sprite can be positioned to within one pixel on the screen, and can be moved one pixel at a time. (A standard character is 8x8 pixels).

GRAPHICS MODES in BASIC

THE VDP chip permits the use of 4 graphics modes, but only three are available with BASIC programs, and only one if you only have the console.

32x24 characters

The standard mode is 32x24 characters. This is all that is available to you if you only have the console. Some utility programs are available giving pseudo hi resolution graphics, which work by redefining these characters, but they tend to be a little slow.

40x24 characters (requires assembly code)

TEXT mode allows 40x24 characters.It requires a machine code program to allow you to use it (various utilities are commercially available).

Block multicolor mode

MULTICOLOUR MODE divides each character into four blocks, and each block can be any colour. To see multicolour mode,try the following:

(Requires Mini Memory or Extended Basic + 32k ram):

100 CALL INIT
110 CALL LOAD(-31788,204)
120 CALL KEY(0,A,B)
130 IF B<1 THEN 120
140 CALL HCHAR(1,1,45,200)
150 FOR Z=1 TO 57
160 FOR X=1 TO 14
170 PRINT CHR$(Z+30);
180 NEXT X
190 NEXT Z
200 CALL LOAD(-31788,224)
210 CALL KEY(0,A,B)
220 IF B<1 THEN 210
230 END    

Enter RUN, then press any key to start the action. At program end,press another key to return to normal. If necessary switch off to return to normal!

Hi Resolution Mode (not in BASIC)

allows pixel plotting, but with nearly 49000 pixel positions (plus colour information) there is no room to operate both this mode and the BASIC operating system. It is only possible in machine code programs - such as PARSEC.