MODE

From BeebWiki
Jump to: navigation, search

MODE is a BASIC statement to change the display mode. A display mode is a particular set-up of the video display, with regards to its width, height, resolution, the number of colours available and the video standard (such as PAL, NTSC or VGA). There is usually a limited number of display modes available on any given machine.

MODE
Availability Present in all original versions of BBC BASIC.
Syntax BASIC I-IV MODE <numeric>
BASIC V,VI MODE <numeric>|<string>
BASIC V and some
other BASICs
<numeric> = MODE
Token (hex) All BASICs EB (statement, rvalue)
Description All BASICs Validates the new mode against available memory, sets the display mode,
and sets HIMEM to the new end of BASIC memory where appropriate.
As a function Returns the number of the current display mode.
Associated keywords CLS, CLG, HIMEM

Description

MODE sets the display mode to the number or string given as the argument. In some BASICs it can also be used as a function to return the the current mode number.

What the number or string means is dependent on the underlying OS; BASIC is not too concerned with the details, except that 6502 BASIC, when running on the I/O processor, anticipates that the amount of memory available to it will change.

6502 BASIC first finds out what processor it is running on using OSBYTE &82. If it is running on the I/O processor, it then finds what the start of display memory would be in the new mode using OSBYTE &85. If the display area would overlap the heap (whose end address is VARTOP), it aborts with a Bad MODE error. To free enough memory for the mode change, the user may need to discard all variables with the CLEAR statement, or reduce the size of the program with editing, DELETE or even NEW.

6502 BASIC also gives a Bad MODE error if the MODE statement is in a procedure or function when running on the I/O processor -- meaning the BASIC stack is in use, which would definitely be lost if HIMEM were to change.

If there is no memory conflict, BASIC issues a VDU 22 command with the new mode as a parameter, and sets HIMEM to the new display address. Non-6502 BASICs simply go ahead with issuing the VDU 22 sequence, as by definition, they cannot be running in the 6502 I/O memory.

BASIC has no way of knowing when the display area has changed in size; if a VDU 22 command is issued other than by MODE, HIMEM will not be updated and part of the user's memory may be wiped, with potentially disastrous results.

Under RISC OS, BASIC calls SWI &65 "OS_ScreenMode" either to set the numerical mode or return its number to the user. If the mode to be set is a string, it issues the command *WimpMode <string>. The display memory does not directly interact with BASIC's application memory area, but external influences on this area are handled by a separate mechanism.

OSBYTE &87 reads the current screen MODE number, but without the shadow screen bit if a shadow screen is selected. Reading screen mode shows how to determine if a shadow screen is selected.

Display modes

Display modes
MODE Type Resolution Colours Characters Pixel aspect Bits per
pixel
Memory Address range
Graphics Text Size Definition
0 ASCII 640 × 256 80 × 32 2 8 × 8 User 1:2 (tall) 1 20K &3000..&7FFF
1 ASCII 320 × 256 40 × 32 4 8 × 8 User 1:1 (square) 2 20K &3000..&7FFF
2 ASCII 160 × 256 20 × 32 16 8 × 8 User 2:1 (wide) 4 20K &3000..&7FFF
3 ASCII -- 80 × 25 2 8 × 10 User 1:2 (tall) 1 16K &4000..&7FFF
4 ASCII 320 × 256 40 × 32 2 8 × 8 User 1:1 (square) 1 10K &5800..&7FFF
5 ASCII 160 × 256 20 × 32 4 8 × 8 User 2:1 (wide) 2 10K &5800..&7FFF
6 ASCII -- 40 × 25 2 8 × 10 User 1:1 (square) 1 8K &6000..&7FFF
7 Teletext 78 × 75* 40 × 25 8** 12 × 20 Hardware 1:1 (square) 1 1K &7C00..&7FFF
8 ASCII (Archimedes/RISC OS) 640 × 256 80 × 32 4 8 × 8 User 1:2 (tall) 2 40K
8 Unofficial 4-colour MODE 0/condensed MODE 1 320 × 256 80 × 32 4 4 × 8 User 1:1 (square) 2 20K &3000..&7FFF
8 Unofficial lower-res MODE 2 80 × 256 10 × 32 16 8 × 8 User 4:1 (ultra wide) 4 10K &5800..&7FFF
9 ASCII (Archimedes/RISC OS) 320 × 256 40 × 32 16 8 × 8 User 1:1 (square) 4 40K
9 Unofficial condensed MODE 2 160 × 256 40 × 32 16 4 × 8 User 2:1 (wide) 4 20K &3000..&7FFF
9 Unofficial lower-res, text-only MODE 2 -- 10 × 25 16 8 × 10 User 4:1 (ultra wide) 4 8K &6000..&7FFF
10 ASCII (Archimedes/RISC OS) 160 × 256 20 × 32 256 8 × 8 User 2:1 (wide) 8 40K
10 Unofficial text-only MODE 5 -- 20 × 25 4 8 × 10 User 2:1 (wide) 2 8K &6000..&7FFF
11 ASCII (Archimedes/RISC OS) -- 80 × 25 4 8 × 10 User 1:2 (tall) 2 40K
11 Unofficial 4-colour MODE 3/condensed MODE 3 -- 80 × 25 4 4 × 10 User 1:1 (square) 2 20K &3000..&7FFF
12 Unofficial 4-colour MODE 4/condensed MODE 5 160 × 256 40 × 32 4 4 × 8 User 2:1 (wide) 2 10K &5800..&7FFF
13 Unofficial 16-colour MODE 5/condensed MODE 5 80 × 256 20 × 32 16 4 × 8 User 4:1 (ultra wide) 4 10K &5800..&7FFF
14 Unofficial 4-colour MODE 6/condensed MODE 6 -- 40 × 25 16 4 × 8 User 2:1 (wide) 4 8K &5800..&7FFF
&60 1-bit extended-colour MODE 0 -- 80 × 32 5 7 × 8 User 1:2 (tall) 1 20K &3000..&7FFF
&61 1-bit extended-colour MODE 1 -- 40 × 32 13 7 × 8 User 1:1 (square) 2 20K &3000..&7FFF
&63 1-bit extended-colour MODE 3 -- 80 × 25 5 7 × 8 User 1:2 (tall) 1 16K &4000..&7FFF
&64 1-bit extended-colour MODE 4 -- 40 × 32 5 7 × 8 User 2:2 (square) 2 16K &4000..&7FFF
&66 1-bit extended-colour MODE 6 -- 40 × 25 5 7 × 8 User 1:1 (square) 2 10K &5800..&7FFF
&68 2-bit extended-colour MODE 0 -- 80 × 32 9 6 × 8 User 1:2 (tall) 1 20K &3000..&7FFF
&69 2-bit extended-colour MODE 1 -- 40 × 32 16 6 × 8 User 1:1 (square) 2 20K &3000..&7FFF
&6B 2-bit extended-colour MODE 3 -- 80 × 25 9 6 × 8 User 1:2 (tall) 1 16K &4000..&7FFF
&6C 2-bit extended-colour MODE 4 -- 40 × 32 9 6 × 8 User 2:2 (square) 2 16K &4000..&7FFF
&6E 2-bit extended-colour MODE 6 -- 40 × 25 9 6 × 8 User 1:1 (square) 2 10K &5800..&7FFF

(*) User-generated graphics. (**) Colours via Teletext control codes.

The Model A supports modes 4 to 7; the Electron, modes 0 to 6; and all other BBC Micros, modes 0 to 7.

The B+ and Master series can set up a shadow screen that resides in shadow RAM and leaves the top of main memory free for the user. Shadow mode is selected by adding 128 to the mode number (hence MODEs 128 to 135), or giving the command *SHADOW before a mode change. As a result HIMEM is always reset to &8000, the end of main memory.

The Archimedes does not have shadow RAM, but supports many more modes.

Screen display MODEs

MODE 0 | MODE 1 | MODE 2 | MODE 3 | MODE 4 | MODE 5 | MODE 6 | MODE 7
MODE 8 | MODE 9 | MODE 10 | MODE 11 | MODE 12 | MODE 13 | MODE 14
MODE &60 | MODE &61 | MODE &63 | MODE &64 | MODE &66
MODE &68 | MODE &69 | MODE &6B | MODE &6C | MODE &6E
MODE | VDU 22

beardo 16:24, 14 September 2007 (BST)