MODE

From BeebWiki
Revision as of 15:29, 30 July 2010 by Jgharston (talk) (Added BASIC I/O category.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 MODE <numeric>|<string>
<num-var> = MODE
Token (hex) BASIC I-V EB (statement, rvalue)
Description BASIC I-IV Validates the new mode against available memory, sets the display mode,

and sets HIMEM to the new start of the display memory area.

BASIC V In the first form, sets the display mode.
In the second form, 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 BASIC V and Z80 BASIC IV it can also return 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.


Display modes

Display modes
MODE Type Resolution Characters Pixel aspect Bits per pixel Colours Memory Address range
Text Graphics Size Definition
0 ASCII 80 × 32 640 × 256 8 × 8 User 1:2 (tall) 1 2 20K &3000..&7FFF
1 ASCII 40 × 32 320 × 256 8 × 8 User 1:1 (square) 2 4 20K &3000..&7FFF
2 ASCII 20 × 32 160 × 256 8 × 8 User 2:1 (wide) 4 16 20K &3000..&7FFF
3 ASCII 80 × 25 -- 8 × 10 User 1:2 (tall) 1 2 16K &4000..&7FFF
4 ASCII 40 × 32 320 × 256 8 × 8 User 1:1 (square) 1 2 10K &5800..&7FFF
5 ASCII 20 × 32 160 × 256 8 × 8 User 2:1 (wide) 2 4 10K &5800..&7FFF
6 ASCII 40 × 25 -- 8 × 10 User 1:1 (square) 1 2 8K &6000..&7FFF
7 Teletext 40 × 25 78 × 75* 12 × 20 Hardware 1:1 (square) 1 8** 1K &7C00..&7FFF
8 ASCII (Archimedes) 80 × 32 640 × 256 8 × 8 User 1:2 (tall) 2 4 40K  ?
8 Unofficial ("lower-res MODE 2") 10 × 32 80 × 256 8 × 8 User 4:1 (ultra wide) 4 16 10K &5800..&7FFF
8 Unofficial ("condensed MODE 1") 80 × 32 320 × 256 4 × 8 User 1:1 (square) 2 4 20K &3000..&7FFF
9 ASCII (Archimedes) 40 × 32 320 × 256 8 × 8 User 1:1 (square) 4 16 40K  ?
9 Unofficial ("lower-res, text only MODE 2") 10 × 25 -- 8 × 10 User 4:1 (ultra wide) 4 16 8K &6000..&7FFF
9 Unofficial ("condensed MODE 5") 40 × 32 160 × 256 4 × 8 User 2:1 (wide) 4 16 20K &3000..&7FFF
10 ASCII (Archimedes) 20 × 32 160 × 256 8 × 8 User 2:1 (wide) 8 256 40K  ?
10 Unofficial ("text only MODE 5") 20 × 25 -- 8 × 10 User 2:1 (wide) 2 4 8K &6000..&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.

-- beardo 16:24, 14 September 2007 (BST)