Difference between revisions of "MODE"

From BeebWiki
Jump to: navigation, search
(Updated MODE table.)
(Added OSBYTE &87, some tidying.)
 
(2 intermediate revisions by the same user not shown)
Line 11: Line 11:
 
| colspan="2" | Present in all original versions of BBC BASIC.
 
| colspan="2" | Present in all original versions of BBC BASIC.
 
|- style="vertical-align:top"
 
|- style="vertical-align:top"
| rowspan="2" | [[BASIC metasyntax|Syntax]]
+
| rowspan="3" | [[BASIC metasyntax|Syntax]]
 
| BASIC I-IV
 
| BASIC I-IV
 
| <code>MODE</code> <numeric>
 
| <code>MODE</code> <numeric>
 
|- style="vertical-align:top"
 
|- style="vertical-align:top"
| BASIC V
+
| BASIC V,VI
| <code>MODE</code> <numeric>&#124;<string><br><num-var> = <code>MODE</code>
+
| <code>MODE</code> <numeric>&#124;<string>
 +
|- style="vertical-align:top"
 +
| BASIC V and some<br> other BASICs
 +
| <code><numeric> = MODE</code>
 
|- style="vertical-align:top"
 
|- style="vertical-align:top"
 
| Token (hex)
 
| Token (hex)
| BASIC I-V
+
| All BASICs
 
| <code>EB</code> (statement, rvalue)<!-- a third category is 'lvalue' -->
 
| <code>EB</code> (statement, rvalue)<!-- a third category is 'lvalue' -->
 
|- style="vertical-align:top"
 
|- style="vertical-align:top"
 
| rowspan="2" | Description
 
| rowspan="2" | Description
| BASIC I-IV
+
| All BASICs
| Validates the new mode against available memory, sets the display mode,
+
| Validates the new mode against available memory, sets the display mode,<br> and sets <code>[[HIMEM]]</code> to the new end of BASIC memory where appropriate.
and sets <code>[[HIMEM]]</code> to the new start of the display memory area.
 
 
|- style="vertical-align:top"
 
|- style="vertical-align:top"
| BASIC V
+
| As a function
| In the first form, sets the display mode.<br>In the second form, returns
+
| Returns the number of the current display mode.
the number of the current display mode.
 
 
|- style="vertical-align:top"
 
|- style="vertical-align:top"
 
| Associated keywords
 
| Associated keywords
Line 37: Line 38:
 
== Description ==
 
== Description ==
 
<code>MODE</code> sets the display mode to the number or string given as the
 
<code>MODE</code> 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
+
argument. In some BASICs it can also be used as a function to return the
number.
+
the current mode number.
  
 
What the number or string means is dependent on the underlying OS; BASIC is
 
What the number or string means is dependent on the underlying OS; BASIC is
Line 75: Line 76:
 
memory does not directly interact with BASIC's application memory area, but
 
memory does not directly interact with BASIC's application memory area, but
 
external influences on this area are handled by a separate mechanism.
 
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 ==
Line 121: Line 126:
 
| [[MODE 9|9]] || Unofficial condensed <code>MODE</code> 2 || 160 &times; 256 || 40 &times; 32 || style="text-align: center;" | 16 || 4 &times; 8 || User || 2:1 (wide) || 4 || 20K || &3000..&7FFF
 
| [[MODE 9|9]] || Unofficial condensed <code>MODE</code> 2 || 160 &times; 256 || 40 &times; 32 || style="text-align: center;" | 16 || 4 &times; 8 || User || 2:1 (wide) || 4 || 20K || &3000..&7FFF
 
|- style="vertical-align:top"
 
|- style="vertical-align:top"
| [[MODE 9|9]] || Unofficial lower-res, text only <code>MODE</code> 2 || style="text-align: center;" | -- || 10 &times; 25 || style="text-align: center;" | 16 || 8 &times; 10 || User || 4:1 (ultra wide) || 4 || 8K || &6000..&7FFF
+
| [[MODE 9|9]] || Unofficial lower-res, text-only <code>MODE</code> 2 || style="text-align: center;" | -- || 10 &times; 25 || style="text-align: center;" | 16 || 8 &times; 10 || User || 4:1 (ultra wide) || 4 || 8K || &6000..&7FFF
 
|- style="vertical-align:top"
 
|- style="vertical-align:top"
 
| [[MODE 10|10]] || ASCII (Archimedes/RISC OS) || 160 &times; 256 || 20 &times; 32 || style="text-align: center;" | 256 || 8 &times; 8 || User || 2:1 (wide) || 8 || 40K ||  
 
| [[MODE 10|10]] || ASCII (Archimedes/RISC OS) || 160 &times; 256 || 20 &times; 32 || style="text-align: center;" | 256 || 8 &times; 8 || User || 2:1 (wide) || 8 || 40K ||  
 
|- style="vertical-align:top"
 
|- style="vertical-align:top"
| [[MODE 10|10]] || Unofficial text only <code>MODE</code> 5 || style="text-align: center;" | -- || 20 &times; 25 || style="text-align: center;" | 4 || 8 &times; 10 || User || 2:1 (wide) || 2 || 8K || &6000..&7FFF
+
| [[MODE 10|10]] || Unofficial text-only <code>MODE</code> 5 || style="text-align: center;" | -- || 20 &times; 25 || style="text-align: center;" | 4 || 8 &times; 10 || User || 2:1 (wide) || 2 || 8K || &6000..&7FFF
 
|- style="vertical-align:top"
 
|- style="vertical-align:top"
 
| [[MODE 11|11]] || ASCII (Archimedes/RISC OS) || style="text-align: center;" | -- || 80 &times; 25 || style="text-align: center;" | 4 || 8 &times; 10 || User || 1:2 (tall) || 2 || 40K ||  
 
| [[MODE 11|11]] || ASCII (Archimedes/RISC OS) || style="text-align: center;" | -- || 80 &times; 25 || style="text-align: center;" | 4 || 8 &times; 10 || User || 1:2 (tall) || 2 || 40K ||  
Line 131: Line 136:
 
| [[MODE 11|11]] || Unofficial 4-colour <code>MODE</code> 3/condensed <code>MODE</code> 3 || style="text-align: center;" | -- || 80 &times; 25 || style="text-align: center;" | 4 || 4 &times; 10 || User || 1:1 (square) || 2 || 20K || &3000..&7FFF
 
| [[MODE 11|11]] || Unofficial 4-colour <code>MODE</code> 3/condensed <code>MODE</code> 3 || style="text-align: center;" | -- || 80 &times; 25 || style="text-align: center;" | 4 || 4 &times; 10 || User || 1:1 (square) || 2 || 20K || &3000..&7FFF
 
|- style="vertical-align:top"
 
|- style="vertical-align:top"
| [[MODE 13|13]] || Unofficial 4-colour <code>MODE</code> 4/condensed <code>MODE</code> 5 || 160 &times; 256 || 40 &times; 32 || style="text-align: center;" | 4 || 4 &times; 8 || User || 2:1 (wide) || 2 || 10K || &5800..&7FFF
+
| [[MODE 12|12]] || Unofficial 4-colour <code>MODE</code> 4/condensed <code>MODE</code> 5 || 160 &times; 256 || 40 &times; 32 || style="text-align: center;" | 4 || 4 &times; 8 || User || 2:1 (wide) || 2 || 10K || &5800..&7FFF
 +
|- style="vertical-align:top"
 +
| [[MODE 13|13]] || Unofficial 16-colour <code>MODE</code> 5/condensed <code>MODE</code> 5 || style="text-align: center;" | 80 &times; 256 || 20 &times; 32 || style="text-align: center;" | 16 || 4 &times; 8 || User || 4:1 (ultra wide) || 4 || 10K || &5800..&7FFF
 
|- style="vertical-align:top"
 
|- style="vertical-align:top"
 
| [[MODE 14|14]] || Unofficial 4-colour <code>MODE</code> 6/condensed <code>MODE</code> 6 || style="text-align: center;" | -- || 40 &times; 25 || style="text-align: center;" | 16 || 4 &times; 8 || User || 2:1 (wide) || 4 || 8K || &5800..&7FFF
 
| [[MODE 14|14]] || Unofficial 4-colour <code>MODE</code> 6/condensed <code>MODE</code> 6 || style="text-align: center;" | -- || 40 &times; 25 || style="text-align: center;" | 16 || 4 &times; 8 || User || 2:1 (wide) || 4 || 8K || &5800..&7FFF
 +
|- style="vertical-align:top"
 +
| [[MODE &60|&60]] || 1-bit extended-colour <code>MODE</code> 0 || style="text-align: center;" | -- || 80 &times; 32 || style="text-align: center;" | 5 || 7 &times; 8 || User || 1:2 (tall) || 1 || 20K || &3000..&7FFF
 +
|- style="vertical-align:top"
 +
| [[MODE &61|&61]] || 1-bit extended-colour <code>MODE</code> 1 || style="text-align: center;" | -- || 40 &times; 32 || style="text-align: center;" | 13 || 7 &times; 8 || User || 1:1 (square) || 2 || 20K || &3000..&7FFF
 +
|- style="vertical-align:top"
 +
| [[MODE &63|&63]] || 1-bit extended-colour <code>MODE</code> 3 || style="text-align: center;" | -- || 80 &times; 25 || style="text-align: center;" | 5 || 7 &times; 8 || User || 1:2 (tall) || 1 || 16K || &4000..&7FFF
 +
|- style="vertical-align:top"
 +
| [[MODE &64|&64]] || 1-bit extended-colour <code>MODE</code> 4 || style="text-align: center;" | -- || 40 &times; 32 || style="text-align: center;" | 5 || 7 &times; 8 || User || 2:2 (square) || 2 || 16K || &4000..&7FFF
 +
|- style="vertical-align:top"
 +
| [[MODE &66|&66]] || 1-bit extended-colour <code>MODE</code> 6 || style="text-align: center;" | -- || 40 &times; 25 || style="text-align: center;" | 5 || 7 &times; 8 || User || 1:1 (square) || 2 || 10K || &5800..&7FFF
 +
|- style="vertical-align:top"
 +
| [[MODE &68|&68]] || 2-bit extended-colour <code>MODE</code> 0 || style="text-align: center;" | -- || 80 &times; 32 || style="text-align: center;" | 9 || 6 &times; 8 || User || 1:2 (tall) || 1 || 20K || &3000..&7FFF
 +
|- style="vertical-align:top"
 +
| [[MODE &69|&69]] || 2-bit extended-colour <code>MODE</code> 1 || style="text-align: center;" | -- || 40 &times; 32 || style="text-align: center;" | 16 || 6 &times; 8 || User || 1:1 (square) || 2 || 20K || &3000..&7FFF
 +
|- style="vertical-align:top"
 +
| [[MODE &6B|&6B]] || 2-bit extended-colour <code>MODE</code> 3 || style="text-align: center;" | -- || 80 &times; 25 || style="text-align: center;" | 9 || 6 &times; 8 || User || 1:2 (tall) || 1 || 16K || &4000..&7FFF
 +
|- style="vertical-align:top"
 +
| [[MODE &6C|&6C]] || 2-bit extended-colour <code>MODE</code> 4 || style="text-align: center;" | -- || 40 &times; 32 || style="text-align: center;" | 9 || 6 &times; 8 || User || 2:2 (square) || 2 || 16K || &4000..&7FFF
 +
|- style="vertical-align:top"
 +
| [[MODE &6E|&6E]] || 2-bit extended-colour <code>MODE</code> 6 || style="text-align: center;" | -- || 40 &times; 25 || style="text-align: center;" | 9 || 6 &times; 8 || User || 1:1 (square) || 2 || 10K || &5800..&7FFF
 
|}
 
|}
 
(*) User-generated graphics. (**) Colours via Teletext control codes.
 
(*) User-generated graphics. (**) Colours via Teletext control codes.

Latest revision as of 10:43, 7 September 2019

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)