MODE 6 VDU 19,0,4,0,0,0
Some users find this type of display more pleasing than the normal one, with a coloured rather than black background, and the lines separated by black gaps. Redefined characters can be used with these modes, however, and this is one reason why they use nearly as much memory as the graphics modes (the difference arises from the saving due to the smaller number of lines of pixels stored).
The remaining modes: 0, 1, 2, 4 and 5, all nominally give a 32 line text display with no gaps between the lines. They vary both in the number of characters per line and the number of colours available. Modes 0 to 2 require 20 Kbytes of memory and are only available on Model B computers, while Modes 4 and 5 take up 10 Kbytes, and can thus be used on Model A computers also, although in this case they leave rather little memory available for the BASIC program.
Table 6.1 summarizes the properties of Modes 0 to 6.
Table 6.1 Properties of the display modes
Mode | Characters | Colours | Memory | Graphics | Resolution |
per line | available | used | |||
0 | 80 | 2 | 20K | YES | 640×256 |
1 | 40 | 4 | 20K | YES | 320×256 |
2 | 20 | 16 | 20K | YES | 160×256 |
3 | 80 | 2 | 16K | NO | |
4 | 40 | 2 | 10K | YES | 320×256 |
5 | 20 | 4 | 10K | YES | 160×256 |
6 | 40 | 2 | 8K | NO |
Figure 6.1 Coordinate system for the graphics modes.
Figure 6.2 The size of a pixel in screen units for the different graphics modes.
The biggest problem with the limited resolution available on a microcomputer is not, as might be expected, the limitation on fine detail, although this is a consideration, but the unpleasant effect that can occur with straight lines. This particularly affects lines that are nearly horizontal or nearly vertical. With a slightly sloping line, the ideal line will pass successively through several pixels in the same row, after which it will cross the boundary between one row of pixels and the adjacent row, and abruptly the screen line will jump to that row for several more pixels. The result is that the sloping line becomes a jagged series of horizontal or vertical lines.
The effect is not confined to microcomputers, and you can observe the effect, for example, on television clocks. It is most easily seen on the second hand as it reaches one second to or one second past the minute.
MODE 1 MOVE 0,496: DRAW 1279,528 MOVE 0,0: DRAW 1279,1023 MOVE 628,1023: DRAW 656,0 MOVE 0,1023: DRAW 1279,0
Try these commands in other graphics modes as well, and notice the non-square effect showing up in the unequal line widths in Modes 0, 2 and 5.
COLOUR n
where n is the number for the desired colour. If n is greater than the range of colours available for the mode in use but less than 128, it is treated modulo that number. For example, in a four colour mode COLOUR 6 would actually select colour number 2, and in a two colour mode COLOUR 4 would select colour number 0.
For graphics the same rules apply, but the command is
GCOL 0,n
The first number specified can have a range of values in order to give rise to special effects, but in most cases it will be zero.
The colour numbers for the different modes are given in Table 6.2. In all cases the default colours for both text and graphics, set when the mode selection statement is executed, are white foreground and black background.
Table 6.2 Colours available in different modes.
Mode | Colour | Colour | Background |
number | number | ||
0,3,4,6 | black | 0 | 128 |
white | 1 | 129 | |
1,5 | black | 0 | 128 |
red | 1 | 129 | |
yellow | 2 | 130 | |
white | 3 | 131 | |
2 | black | 0 | 128 |
red | 1 | 129 | |
green | 2 | 130 | |
yellow | 3 | 131 | |
blue | 4 | 132 | |
magenta | 5 | 133 | |
cyan | 6 | 134 | |
white | 7 | 135 | |
flashing | 8-15 | 136-143 |
COLOUR 129
or
GCOL 0,129
Note that this will not turn the whole screen red. It will simply provide a red background to any subsequent characters (including spaces) that are printed. The whole screen can be turned red by using CLS, which clears the screen to the current background colour. Similarly the graphics screen can be cleared to the current graphics background colour by CLG. Note that unless a text or graphics window has been set, these two ways of changing the background colour of the whole screen give the same result.
MOVE 0,512 DRAW 1279,512
will draw a horizontal line through the middle of the screen.
Although the size of the screen is 1280 units by 1024 units, it is possible to plot outside this area, though obviously nothing will be seen. The plotting does exist, however, at least in the sense that a line drawn from somewhere off the screen to a position on the screen will appear to come from that hypothetical off-screen position. The overall limits on the x and y parameters to MOVE and DRAW are -32768 to 32767. (Larger values will not cause an error. It is a general feature of graphics commands, as well as other VDU commands, that they do not give rise to execution errors -- they simply produce incorrect effects. For instance, numbers between 32768 and 65535 will he. treated as neeative numbers.
MODE 1 GCOL 0,1 MOVE 0,512: DRAW 1279,512 MOVE 640,0: DRAW 640,1023 GCOL 0,2 MOVE 0,0: DRAW 1279,1023 MOVE 0,1023: DRAW 1279,0
1000 DEF PR0C_line(X1,Y1,X2,Y2,COL) 1010 GCOL 0,COL 1020 MOVE X1,Y1 1030 DRAW X2,Y2 1040 ENDPROC
5 DIM SALES(12) 10 REPEAT 20 MODE 1 30 PRINT "Input the monthly sales figures" 40 PRINT "one per line, for January" 50 PRINT "to December." 60 MAX=0 70 FOR J=1 TO 12 80 INPUT SALES(J) 90 IF SALES(J)>MAX THEN MAX=SALES(J) 100 REM MAX IS THE MAXIMUM SALES FIGURE 110 NEXT J 120 CLS 130 MULT=1: POW10=0 140 IF MAX<50 THEN GOTO 200 150 REPEAT 160 MAX=MAX/10 170 MULT=MULT*10: POW10=POW10+1 180 REM MULT IS MULTIPLE OF 10 SCALE FACTOR, I.E. 10^POW10 190 UNTIL MAX<50 200 SCALE=1-(MAX>10)-3*(MAX>20) 210 REM SCALE*MULT IS SCALE FACTOR PER DIVISION 220 GCOL 0,3 230 MOVE 128,148 240 FOR J=148 TO 948 STEP 80 250 MOVE 128,J: DRAW 1184,J: REM PLOT GRID 260 NEXT J 270 MOVE 128,144: DRAW 1184,144: REM PLOT ORIGIN DOUBLE THICKNESS 280 MOVE 124,144: DRAW 124,948 290 MOVE 128,148 300 FOR J=128 TO 1184 STEP 96 310 MOVE J,148: DRAW J,948 320 NEXT J 330 FOR J=0 TO 10 STEP 2 340 PRINT TAB(1,27-2.5*J);SPC(2-LEN(STR$(SCALE*J))); SCALE*J; 350 NEXT J 360 PRINT TAB(0,0);"x10^";POW10 370 PRINT TAB(3,28);"Jn Fb Mr Ap My Jn Jl Au Sp Oc Nv Dc" 380 PRINT 390 GCOL 0,1: PROC_pltpt(1,FN_ycoord(1,SCALE,MULT)) 400 FOR J=2 TO 12 410 DRAW 32+J*96,FN_ycoord(J,SCALE,MULT) 420 PROC_pltpt(J,FN_ycoord(J,SCALE,MULT)) 430 NEXT J 440 PRINT "Press SPACE for another graph" 450 PRINT "or any other key to end"; 460 UNTIL GET$<>" " 470 END 2000 DEF PROC_pltpt(X,Y) 2010 LOCAL Y1 2020 FOR Y1=-8 TO 8 2030 MOVE 24+X*96,Y+Y1: DRAW 40+X*96,Y+Y1 2040 NEXT Y1 2050 MOVE 32+X*96,Y: REM MOVE TO CENTRE OF POINT READY TO DRAW LINE 2060 ENDPROC 2070 DEF FN_ycoord(J,SCALE,MULT) 2080 =148+80*SALES(J)/(SCALE*MULT)
This program plots a suitable sales graph for a set of monthly figures typed in by the user.
From the point of view of the graphics commands required, the only problem in the above program is in scaling the graph, since the screen is fixed at 1024 units high by 1280 units wide. If we are plotting the graph for one year, then a convenient horizontal scale would be 96 units per month (which corresponds to exactly three characters in Mode 1 or 4), leaving 128 units blank on the sides of the graph.
The choice of the vertical scale is not so simple. If the chart is to be split up into 10 divisions, it would be convenient to use 80 units per division, with 224 units (56 pixels or 7 lines of characters) shared between the spaces at the top and bottom.
After this choice has been made it will be necessary to find the largest monthly sales figure, and use this to determine the vertical scale for each of the ten divisions. If we want each division to represent a round quantity (normally 1, 2 or 5 times some power of 10) it is also necessary to make the scale larger still to accommodate the next higher round value.
Line 90 determines MAX, the maximum value to be plotted, which is used to calculate the vertical scaling. Lines 150 to 190 ascertain the power of ten needed in the scaling factor, the whole factor being stored in the variable MULT and the power in POW10. Line 200 determines whether each division will represent 1, 2 or 5 times MULT, using the fact that when evaluating a Boolean test, TRUE is -1 and FALSE is zero.
Lines 340, 360 and 370 print the scale and months on the graph, using the TAB command as described in Chapter 11.
Finally and most importantly, lines 250 and 310 respectively draw the horizontal and vertical grid lines, PROC_pltpt at line 2000 plots each sales 'point' and line 410 draws the lines joining the points, calling FN ycoord at line 3000 to calculate the screen y-coordinate from the sales values SALES(J).
y=f(x)
which allows the curve to be built up by stepping along the x-axis, calculating y from the function at every step.
A simple example of plotting a sine wave is shown in Example 6.4. Try different values of the order n of the curve (which is of the form sin(nx)) and the step length (step length here means the horizontal length of each line in pixels) to see what step length gives an acceptable compromise between resolution of the curve and speed of execution for different orders. Note that some interesting effects can be obtained with the program below if very large values are specified for n.
10 MODE 1 15 REPEAT 20 PRINT TAB(0,26); "What order of sine curve would you" 30 INPUT "like? (1-10) "N 40 PRINT "What step length would you like?" 50 INPUT "(1-50) "STP 60 GCOL 0,3 70 X0=640: Y0=608 80 MOVE 0,Y0: DRAW 1279,Y0 90 MOVE X0,192: DRAW X0,1023 100 REM PLOT AXES 110 XMAX=INT(636/STP)*STP 120 YMAX=400 130 MOVE X0-XMAX,Y0+YMAX*SIN(-N*PI) 140 FOR J=-XMAX+4*STP TO XMAX STEP 4*STP 150 X=PI*J/XMAX: REM SCALE ANGLES 160 Y=YMAX*SIN(N*X) 170 DRAW J+X0,Y+Y0 180 NEXT J 190 PRINT "Press SPACE to plot another curve" 200 PRINT "or any other key to end "; 210 UNTIL GET$<>" "
The variable STP specifies the step length, and is multiplied by 4 (since the program is working in Mode 1) so that it directly represents the number of pixels. Remember in your own applications that this step length always needs to be an integral number of pixels, otherwise you may get uneven results in your curves.
For sine curves scaling is simple since sin(nx) has a maximum value of 1, so y values are simply multiplied by YMAX (400). Similarly, the maximum value of angle wanted is p so the x values can be scaled fairly simply. The X0 and Y0 added to the x and y values shift the origin to the centre of the top section of the screen (leaving room for a few lines of text at the bottom). Note that there is an alternative way of moving the origin to the centre of the screen, which is discussed in Section 6.3.2.
The next example plots a parabola, with a variable position for the focus, which means that the function must be scaled horizontally so that the curve makes the maximum use of the screen area. This is done by the scale factor SCALE, calculated in line 140 and used to scale X*X in line 170.
10 MODE 1 15 REPEAT 20 PRINT TAB(0,26)"What focal length would you like?" 30 INPUT "(12-400) "A 40 PRINT "What step length would you like?" 50 INPUT "(1-50) "STP 60 GCOL 0,3 70 X0=640: Y0=192 80 MOVE X0-12,Y0+2*A: DRAW X0+12,Y0+2*A 90 MOVE X0,Y0+2*A-12: DRAW X0,Y0+2*A+12 100 REM PLOT FOCUS 110 XMAX=INT(636/STP)*STP 120 MOVE X0-XMAX,Y0: DRAW X0+XMAX,Y0 130 REM PLOT BASE LINE 140 SCALE=(800-A)*4*A/(XMAX*XMAX) 150 YOLD=A 160 FOR X=4*STP TO XMAX STEP 4*STP 170 Y=A+SCALE*X*X/(4*A) 180 REM FORMULA FOR A PARABOLA IS X*X - 4A(Y-A) 190 MOVE X-4*STP+X0,YOLD+Y0: DRAW X+X0,Y+Y0 200 MOVE -X+4*STP+X0,YOLD+Y0: DRAW -X+X0,Y+Y0 210 YOLD=Y 220 NEXT X 230 PRINT "Press SPACE to plot another curve" 240 PRINT "or any other key to end "; 250 UNTIL GET$<>" "
Plotting a curve as a series of straight lines for equal steps of X is not always the best method. One occasion when this is not the optimum strategy is when the curve has a vertical section. Compare the next two programs, both of which plot a circle of variable radius. The first uses equal steps of X, whereas the second program plots around the circle in equal steps of angle, which is much more satisfactory in the case of a geometric form such as a circle. The circle drawn on the screen may in practice be slightly elliptical due to variation in the height and width gain settings on your TV or monitor.
10 MODE 1 20 INPUT "Radius of circle? (4-400) "R 30 STP=INT(R/20): IF STP<1 THEN STP=1 40 X0=640: Y0=512 50 MOVE X0-R,Y0 60 FOR X=-R TO R STEP STP 70 Y=SQR(R*R-X*X) 80 DRAW X+X0,Y+Y0 90 NEXT X 100 REM FORMULA FOR A CIRCLE IS X*X+Y*Y=R*R 110 FOR X=R TO -R STEP -STP 120 Y=SQR(R*R-X*X) 130 DRAW X+X0,-Y+Y0 140 NEXT X 150 DRAW X0-R,Y0
Here the number of steps has automatically been set to about 40, which is a reasonable compromise between speed of drawing and smoothness of the circle drawn.
10 MODE 1 20 INPUT "Radius of circle? (4-400) "R 30 X0=640: Y0=512 40 MOVE X0-R,Y0 50 FOR ANGLE=0 TO 360 STEP 5 60 Y=R*SIN(RAD(ANGLE)) 70 X=-R*COS(RAD(ANGLE)) 80 DRAW X+X0,Y+Y0 90 NEXT ANGLE
This time the step length is 5 degrees, giving 36 steps in each semi-circle.
15 INPUT "Semi-major axis of ellipse? (4-636)"A 20 INPUT "Semi-minor axis of ellipse? (4-400)"B 40 MOVE X0-A,Y0 55 R=1/SQR(SIN(RAD(ANGLE))^2/(B*B)+COS(RAD(ANGLE))^2/(A*A))
20 R=0 50 FOR ANGLE=0 TO 3600 STEP 5 55 R=ANGLE/10
PLOT K,X,Y
X and Y are the screen coordinates just as with DRAW, but K can take a large number of possible values, each giving a different form of plotting action. The factor K itself can be subdivided into three components, L + M + N.
L chooses the pen colour, while M determines whether the pen movement is relative or absolute. The choice of colours is: L=0, none (i.e. pen-up movement); L=1, the graphics foreground colour; L=3, the graphics background colour (this is not exactly the same as pen up movement because it will effectively eradicate any line already present by merging it with the background); and L=2, the logical inverse colour. This last colour we shall not consider further.
M=0 gives relative plotting, while M=4 gives absolute plotting. The latter means that the X and Y values specify the actual x- and y-coordinates on the screen, whereas when X and Y are relative, the value of X and Y specify the distance to be moved from the present pen position. Care must be taken when using relative plotting, as each relative movement can contribute a cumulative error to the position of the pen.
The effect of different combinations of L and M are shown in Table 6.3.
Table 6.3 Plot codes for different plotting colours.
Plotting colour | Relative movement (M=0) | Absolute movement (M=4) |
L + M | L + M | |
Move only | 0 | 4 |
Current graphics | 1 | 5 |
foreground | ||
Logical inverse | 2 | 6 |
Current graphics | 3 | 7 |
background |
Table 6.4 Effects of different N values in PLOT.
N | Action |
0 | Simple drawing |
8 | Omitting the last point for inverting actions |
16 | Drawing a dotted line |
24 | Combination of 8 and 16 |
64 | Plotting a single point only |
80 | Triangle filling |
PLOT 69,X,Y
The triangle filling option is very useful. It works on the point specified along with the previous two pen positions. This provides a way of very rapidly filling any desired area with solid colour.
1000 DEF PROC_rectangLe(X1,Y1,X2,Y2) 1010 MOVE X1,Y1 1020 MOVE X1,Y2 1030 PLOT 85,X2,Y1 1040 PLOT 85,X2,Y2 1050 ENDPROC
1000 DEF PROC_circle(R,X0,Y0) 1010 LOCAL ANGLE 1020 MOVE X0+R,Y0 1030 FOR ANGLE=5 TO 360 STEP 5 1040 MOVE X0,Y0 1050 PLOT 85,X0+R*COS(RAD(ANGLE)),Y0+R*SIN(RAD(ANGLE)) 1060 NEXT ANGLE 1070 ENDPROC
VDU M,N,...
is exactly equivalent to
PRINT CHR$(M);CHR$(N);...
The most valuable use of the command is to control the screen display (or VDU display, hence the name of the command) by the issue of control characters. Indeed, in direct mode a third way of achieving the same result is to type CTRL characters. For instance, CTRL-V CTRL-A would select Mode 1, as would VDU 22,1 (or MODE 1). The reason for this redundancy is presumably simply to enable advanced users to achieve all their needs with the VDU command, while beginners have simpler, easy to remember commands for the functions that they will need. The VDU commands which have an alternativ form are listed in Table 6.5, and will not be considered further.
Table 6.5 VDU commands and their equivalents.
VDU number | Control code | Equivalent |
9 | CTRL-I | <TAB> |
12 | CTRL-L | CLS |
13 | CTRL-M | <RETURN> |
16 | CTRL-P | CLG |
17 | CTRL-Q | COLOUR |
18 | CTRL-R | GCOL |
22 | CTRL-V | MODE |
25 | CTRL-Y | PLOT |
27 | CTRL-[ | <ESCAPE> |
31 | CTRL-_ | PRINT TAB( ); |
127 | N/A | <DELETE> |
Table 6.6 Non-graphics VDU commands.
VDU number | Control code | Effect |
0 | CTRL-@ | Does nothing |
1 | CTRL-A | Send next character to printer only |
2 | CTRL-B | Enable printer |
3 | CTRL-C | Disable printer |
6 | CTRL-F | Enable VDU drivers |
7 | CTRL-G | Beep the speaker (bell) |
8 | CTRL-H | Backspace cursor (but not delete) |
10 | CTRL-J | Move cursor down |
11 | CTRL-K | Move cursor up one line |
14 | CTRL-N | Switch on page mode |
15 | CTRL-O | Switch off page mode |
21 | CTRL-U | Disable VDU drivers or delete current line |
30 | CTRL-^ | Home text cursor to top left |
Table 6.7 Graphics-based VDU commands.
VDU number | Extra bytes | Effect |
4 | 0 | Write text at text cursor |
5 | 0 | Write text at graphics cursor |
19 | 5 | Define logical colour |
20 | 0 | Restore default logical colours |
23 | 9 | Define new character |
24 | 8 | Set graphics window |
26 | 0 | Restore default windows |
28 | 4 | Set text window |
29 | 4 | Set new graphics origin |
10 ON ERROR GOTO 500 20 MODE 1 30 VDU 5 40 J=0 50 REPEAT 60 MOVE 0,1023-48*J 70 INPUT "" A$ 80 J=J+1 90 IF J>21 THEN J=0 100 UNTIL FALSE 500 VDU 4
VDU 29 alters the position of the graphics origin. Very often, you will wish to centre your graphs, not on the default of the bottom left corner, but elsewhere such as at the centre of the screen. In our previous examples, this was achieved by defining X0 and Y0 and adding these into all MOVE and DRAW commands, but it can be more convenient to move the origin instead. VDU 29 is the first of these commands we have met that requires extra parameters. The 29 must be followed by two further numbers or variables, the x and y screen coordinates of the position where you want the new origin.
To move the graphics origin to the centre of the screen, for example, the command would be
VDU 29,640;512;
Successive parameters to the VDU command are normally separated by commas, but note that the x- and y-coordinates for VDU 29 must be followed by semi-colons. This tells the computer that they are two-byte numbers (since they may be greater than 255; you can alternatively break them up into low and high bytes, but this is very tedious). The semi-colon can be used at any time to indicate that the preceding parameter is a two-byte number, and this technique is sometimes used to concatenate redundant zeros, such as those at the end of VDU 19. Be careful, if you are doing this, that you do not omit the final semi-colon, as VDU commands do not give rise to error messages but can nevertheless result in peculiar effects. In this case, the next character input or issued would be seized as the last byte of the VDU command.
If VDU 29 is issued more than once, the newly specified coordinates are always relative to the initial origin at the bottom left-hand corner, not to the previously set origin.
Figure 6.3 A text window as set up by the command VDU 28,5,7,34,0.
The command to set a text window is
VDU 28,XLEFT,YBOTTOM,XRIGHT,YTOP
You could think of this as specifying the bottom left and top right corners of the window. Note that for text Y is measured from the top, so YBOTTOM will be the maximum value of Y allowed. For the case shown in Figure 6.3, the command becomes
VDU 28,5,7,34,0
Note that the coordinates are the same as with the TAB command, and that the allowed ranges will vary with the mode in force. In this context you must remember that there are no error messages or error trapping for 'faulty' VDU statements - the command is simply ignored.
There are several reasons why you may wish to use a text window, quite apart from graphics windows. It would be the most convenient way of breaking program output into columns, particularly if the length of output may vary. A more important use is to keep a section of text permanently on the screen while other parts scroll. Once a text window is in force that does not encompass existing text, that text will not scroll, and so remains permanently on display. This technique is a favourite device in commercial programs such as word processors, where a top or bottom line showing status information remains permanently on display.
Any text window (or graphic window) may be cancelled with the command
VDU 26
The default full screen displays are also restored by a mode change (or, of course, a <BREAK>).
10 MODE 6 20 PRINT "TEXT WINDOW DEMONSTRATION - THE ALPHABET" 30 VDU 28,5,9,34,2 40 FOR J=1 TO 26 50 FOR K=1 TO 240 60 PRINT CHR$(J+64); 70 NEXT K 80 PRINT 90 NEXT J
VDU 24,XLEFT;YBOTTOM;XRIGHT;YTOP;
Note that this is the same convention as for the text window, specifying bottom left and top right corners of the window, but you must remember that this time YBOTTOM represents the smallest allowed value for Y.
The many conceivable uses include setting a window for a graph so that any lines that would otherwise spill outside the grid are suppressed. Another use could be to put a coloured border around a display.
A very useful application of windows is where text and graphics are to be used separately, but in the same display. Independent windows for the text and graphics may be set so that they do not overlap, thus avoiding the possibility of one interfering with the other.
10 MODE 1 20 GCOL 0,130 30 CLG 40 VDU 24,128;128;1151;895; 50 GCOL 0,129 60 CLG 70 MOVE 0,0: DRAW 1279,1023 80 MOVE 0,1023: DRAW 1279,0
Note that when no windows have been set, a background can be set to colour n either by
COLOUR 128+n: CLS
or
GCOL 0,128+n: CLG
but here CLG must be used because we wish to change the colour only within the graphics window. However, if text is subsequently printed onto the screen each character will have a black background unless COLOUR 128+n is also set, or VDU 5 is used to have text printed on a transparent background.
VDU 19,<colour number>,<actual colour>,0,0,0
The <actual colour> is specified by a number which is the same as the colour number sequence for Mode 2, as listed earlier. The trailing zeros are to allow for possible future expansion of the system.
Thus to change colour number 2 in Mode 1 from yellow to green the command would be
VDU 19,2,2,0,0,0
(or VDU 19,2,2;0; using the semi-colon to abbreviate the command).
The double occurrence of 2 in this particular example can be confusing, but a little thought will show that it is quite logical. If the colour number is outside the permitted range, then it is treated modulo the number of permissible colours, so in Mode 1 the same effect as above would be achieved by VDU 19,6,2,0,0,0. The command is not specifically a graphics command, and applies both to text and graphics colour.
Redefined colour numbers can all be set back to their default colours by
VDU 20
VDU 19,0,4;0;
VDU 23,<char no>,a,b,c,d,e,f,g,h
The <char no> is the ASCII code of the character being defined, and a to h are the 8 numbers defining the rows of pixels, a representing the top row, b the second, down to h for the bottom row.
Let us now see how to define a new character, the greek character pi. First it is necessary to plan out the character on a piece of squared paper. Since it is to be a normal character, there must be a line of unlit pixels along the bottom and left hand sides, following the same convention used for normal characters so that they are separated from one another. Figure 6.4 shows the shape to be defined.
The values for the rows are calculated as follows: the top row has just the right hand pixel lit, so the value is 1. The second row has pixels 2 to 6 lit, so the value is 62 (32+16+8+4+2). The next row has a value of 84 (64+16+4), the following two have the same value of 20 (16+4) and row f, 18 (16+2). The seventh row has a value of 33 (32+I) and we must not forget the blank row at the bottom, which simply has a value of 0. If this is to be the first special character available, 224, the required VDU command is
VDU 23,224,1,62,84,20,20,18,33,0
Figure 6.4 The shape needed for a user-defined character p
VDU 23,224,1,62,84,20,20,18,33,0 MODE 6 PRINT CHR$(224);" = ";PI
Note that the character, once defined, is preserved through a mode change [or even a BREAK).
Try to define another greek letter, such as phi.
User-defined characters are not restricted to single character cells. You can plan out a shape larger than 8x8 pixels, and spread it out over several character cells, which can be printed side by side or one above the other (using the TAB command). The sort of shapes that you might want are mathematical integral or summation signs, or small pictures. The latter will be plotted much faster in the form of user defined characters than by graphics commands. Each character can only be plotted in a single colour, but even this is not a major restriction, because the different colour components could be plotted as separate characters, superimposed with the aid of the VDU 5 command.
Table 6.8 Making room for new characters.
ASCII | Command |
character | required |
codes | |
128-159 | none |
160-191 | PAGE=PAGE+256 |
192-223 | PAGE=PAGE+512 |
224-255 | PAGE=PAGE+768 |
32-63 (! to ?) | PAGE=PAGE+1024 |
64-95 (@ to _) | PAGE=PAGE+1280 |
96-126 (£ to ~) | PAGE=PAGE+1536 |
VDU 23,1,0;0;0;0;
and switched on again by
VDU 23,1,1;0;0;0;
Note however that when text is linked to the graphics cursor by VDU 5, this also suppresses the flashing cursor, and if you are not wanting to print text at the text cursor position this is an easier way of removing it (VDU 4 brings it back, of course).
The second extra use of VDU 23, strictly for advanced users only, is to program the 6845 cathode ray tube controller chip (CRTC) which handles the screen display. We will mention only two possibilities here. First, the interlace which gives the screen display a slightly jittery effect, especially on some monitors, cannot be turned off in Mode 7 by the normal command *TV 0,1. It can be turned off, however, by
VDU 23,0,8,16,128;0;0;: VDU 23,0,9,9,0;0;0;
though you may think that the distorted character set that results is worse than the jitter.
The cursor can be altered in various ways by
VDU 23,0,10,n,0;0;0;
and
VDU 23,0,11,n,0;0;0;
In particular it can be turned off by
VDU 23,0,10,32,0;0;0;
and turned on again in its normal form by the VDU 23,1 commands. The above form will work even with the old 0.1 operating system.