www.riscos.com Technical Support:
BBC BASIC Reference Manual



The operating system allows the programmer to set up special rectangular areas of the screen, called viewports, in order to restrict where text or graphics can appear on the screen.

Text viewports provide automatic scrolling of text written into the viewport area, and so are also referred to as 'scrolling viewports'.

Graphics viewports restrict the area affected by graphics operations, so that, for example, lines are clipped to lie within the viewport area. Graphics viewports are therefore also referred to as 'clipping viewports'.

Note: the text and graphics viewports described here are supported directly by the VDU drivers, and are quite distinct from the bordered, moveable windows used by the window manager software, which uses graphics viewports as a stepping stone to greater functionality (for more details see the section entitled Window managed programs).

Text viewports

Normally, text may appear anywhere on the screen. However, you can define a text viewport, which allows the text to appear only inside the viewport. To set up a text viewport, use the VDU 28 command as follows:

VDU 28,left,bottom,right,top

where left,bottom is the bottom lefthand and right,top the top righthand position inside the viewport given in text coordinates:

Nothing outside the text viewport is affected by text statements, such as CLS to clear the text screen, or screen scrolling. Note that TAB(X,Y) positions the text cursor relative to the position of the top left of the current text viewport. The following program demonstrates how text viewports behave:

 10 MODE 1
 20 REM Set up a text viewport 6 characters square
 30 VDU 28,5,10,10,5
 40 REM Change the background colour to colour 1 (red)
 50 COLOUR 129
 60 REM Clear the text screen to show where it is
 70 CLS
 80 REM Demonstrate scrolling
 90 FOR N% = 1 TO 20
100   PRINT N%
110 NEXT N%
120 REM Show position of character (2,3)
130 PRINT TAB(2,3);"*"
140 END

To revert back to having the whole screen as the text viewport type

VDU 26

The precise actions of the VDU 26 command are as follows:

  • Restore text viewport to the whole screen
  • Restore graphics viewport to the whole screen
  • Home the text cursor
  • Restore graphic origin to bottom left of screen
  • Home graphics cursor to (0,0).

Graphics viewports

Just as text may have a text viewport defined, so a graphics viewport may be set up using

VDU 24, left;bottom;right;top;

where (left,bottom) and (right,top) are the coordinates of the lower lefthand and upper righthand pixels inside the viewport. Be sure to use semi-colons as indicated, not commas.

Nothing outside the graphics viewport is affected by graphics commands, such as CLG to clear the graphics screen. When a graphics viewport is set up, the graphics origin (0,0) is unaltered.

The following program demonstrates how graphics viewports behave:

 10 MODE 12
 20 REM Set up a graphics viewport,a quarter of the screen size
 30 VDU 24,320;256;960;768;
 40 REM Change the background colour to colour 1 (red)
 50 GCOL 129
 60 REM Clear the graphics viewport
 70 CLG
 80 REM Show position of 0,0
 90 CIRCLE 0,0,600
100 END

To revert back to having the whole screen as the graphics viewport type

VDU 26

This edition Copyright © 3QD Developments Ltd 2015
Last Edit: Tue,03 Nov 2015