Video display modes: Difference between revisions

m
→‎{{header|Wren}}: Removed a blank line
(Added ARM Assembly for Game Boy Advance)
m (→‎{{header|Wren}}: Removed a blank line)
 
(31 intermediate revisions by 10 users not shown)
Line 1:
{{task}}[[Category:Initialization]]
The task is to demonstrate how to switch video display modes within the language. A brief description of the supported video modes would be useful.
=={{header|6502 Assembly}}==
===Apple II===
* Change to 80-column display:
<syntaxhighlight lang="6502asm">LDA #3
JSR $FE95</syntaxhighlight>
* Change to 40-column display:
<syntaxhighlight lang="6502asm">LDA #0
JSR $FE95</syntaxhighlight>
 
For the following, the value stored to these memory locations does not matter. It is the mere act of writing to them that causes the Apple II to change modes. You can read from them as well to do the same, but there's really no reason to do so, as both <code>LDA $????</code> and <code>STA $????</code> both take 4 clock cycles, and you've only got 3 registers you can use so there's no sense in wiping the accumulator with a garbage value that has no actual meaning.
 
{{trans|Applesoft BASIC}}
 
* <code>STA $C050</code>:Change to text mode
* <code>STA $C051</code>:Change to graphics mode
* <code>STA $C052</code>:Change to full screen (whatever mode you're "in" takes up the whole screen)
* <code>STA $C053</code>:Change to mixed screen (graphics mode is the majority of the screen, but there's 4 rows of text on the bottom)
* <code>STA $C054</code>:Display page 1 of video memory
* <code>STA $C055</code>:Display page 2 of video memory
* <code>STA $C056</code>:Change graphics mode to low-resolution (16-color) mode
* <code>STA $C057</code>:Change graphics mode to hi-resolution (6-color) mode
 
===Nintendo Entertainment System===
[https://nesdev-wiki.nes.science/wikipages/PPU_registers.xhtml NES Picture Processing Unit Registers]
 
=={{header|8086 Assembly}}==
{{works with|MS-DOS}}
<syntaxhighlight lang="asm">mov ah,00h
mov al,videoMode
int 10h</syntaxhighlight>
 
There are quite a few valid values for <code>videoMode</code>, here are a few of them:
* 03h is the standard MS-DOS command prompt that appears upon startup.
* 04h is CGA mode, which is typically 4-color when using an RBGI cable and can be up to 16 colors when using a composite cable. The resolution is 320x200 pixels.
* 09h is used by the Tandy 1000 computer.
* 0Dh is EGA mode, which uses 4 bitplanes and is 16 colors, with a resolution of 320x200 pixels.
* 13h is VGA mode, which uses one byte per pixel, 256 colors, and has a resolution of 320x200 pixels.
 
 
Some other trivia about changing video modes:
 
* Using the above command to switch video modes to the same video mode you're already in will wipe the screen of all graphics, reset the text cursor, and, for VGA mode, reloads the standard VGA palette, destroying whatever user-defined palette was stored in the graphics card's memory. "Switching" to the same video mode again is a quick and easy way to clear the screen.
* Regardless of whether you use CGA or EGA, the same text-related commands and service calls will work just as they do in MS-DOS mode. The only difference is the font which is a lot larger and supports the change of text color.
* If you use <code>mov ax,4C00h int 21h</code> to return to DOS while in a different video mode, you will still be in that video mode when you return.
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">PROC ShowMode(BYTE m,split,gr
CARD w, BYTE h,
CARD size,
CHAR ARRAY descr)
BYTE CH=$02FC
CARD i
BYTE POINTER ptr
 
Graphics(0)
PrintF("Next video mode: %B%E",m)
IF split THEN
PrintF("Split video mode%E%EUpper part:%E")
FI
 
IF gr THEN
Print("Graphics")
ELSE
Print("Text")
FI
PrintF(" mode, %Ux%B, %S%E",w,h,descr)
 
IF split THEN
PrintF("%ELower part:%EText mode 40x4, 2 luminances%E")
FI
PrintF("%EPress any key to change video mode.")
 
DO UNTIL CH#$FF OD
CH=$FF
 
Graphics(m)
ptr=PeekC(88)
 
FOR i=1 TO size
DO
ptr^=Rand(0)
ptr==+1
OD
 
DO UNTIL CH#$FF OD
CH=$FF
RETURN
 
PROC Main()
ShowMode(0,0,0,40,24,960,"2 luminances")
ShowMode(1,1,0,20,20,640,"5 colors")
ShowMode(2,1,0,20,10,400,"5 colors")
ShowMode(3,1,1,40,20,400,"4 colors")
ShowMode(4,1,1,80,40,640,"2 colors")
ShowMode(5,1,1,80,40,1120,"4 colors")
ShowMode(6,1,1,160,80,2080,"2 colors")
ShowMode(7,1,1,160,80,4000,"4 colors")
ShowMode(8,1,1,320,160,7856,"2 luminances")
ShowMode(9,0,1,80,192,7680,"16 luminances")
ShowMode(10,0,1,80,192,7680,"9 colors")
ShowMode(11,0,1,80,192,7680,"16 hues")
ShowMode(12,1,0,40,20,1120,"5 colors")
ShowMode(13,1,0,40,10,640,"5 colors")
ShowMode(14,1,1,160,160,4000,"2 colors")
ShowMode(15,1,1,160,160,7856,"4 colors")
ShowMode(17,0,0,20,24,480,"5 colors")
ShowMode(18,0,0,20,12,240,"5 colors")
ShowMode(19,0,1,40,24,240,"4 colors")
ShowMode(20,0,1,80,48,480,"2 colors")
ShowMode(21,0,1,80,48,960,"4 colors")
ShowMode(22,0,1,160,96,1920,"2 colors")
ShowMode(23,0,1,160,96,3840,"4 colors")
ShowMode(24,0,1,320,192,7680,"2 luminances")
ShowMode(28,0,0,40,24,960,"5 colors")
ShowMode(29,0,0,40,12,480,"5 colors")
ShowMode(30,0,1,160,192,3840,"2 colors")
ShowMode(31,0,1,160,192,7680,"4 colors")
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Video_display_modes.png Screenshot from Atari 8-bit computer]
 
=={{header|AmigaBASIC}}==
 
<langsyntaxhighlight lang="amigabasic">SCREEN 1,320,200,5,1</langsyntaxhighlight>
This command creates a new screen #1 (4 max) with 320x200 pixels and 5 bits per pixel (for a total of 2⁵=32 colors). The final parameter, 1, sets the monitor to 320x200 (NTSC Amiga) or 320x256 (PAL Amiga) non-interlaced mode. If set to 2, it would use 640*200/640*256, while 3 and 4 would result in corresponding interlaced modes with twice the vertical resolution.
 
The screen can be closed again with
<syntaxhighlight lang ="amigabasic">SCREEN CLOSE 1</langsyntaxhighlight>
 
=={{header|Applesoft BASIC}}==
Line 23 ⟶ 143:
hgr, page 2, 280 x 160, 6 colors, mixed with four lines of text
 
<syntaxhighlight lang="applesoftbasic">10 GR
<lang ApplesoftBasic>10 GR
20 FOR I = 0 TO 15 : COLOR = I : PLOT I,I : NEXT
30 HGR
Line 42 ⟶ 162:
180 IF A$ = "G" THEN POKE -16304,0 : REM GRAPHICS
190 IF A$ <> "Q" THEN 100
200 TEXT</langsyntaxhighlight>
 
=={{header|ARM Assembly}}==
=== Game Boy Advance===
#[[https://mgba-emu.github.io/gbatek/#lcdiodisplaycontrol|GBATek Game Boy Advance Specifications]]
 
The video display mode is a 16 bit value that is written to address 0x04000000. The lowest 3 bits control the screen mode. There are 5 to choose from. Modes 0-1 use tile graphics, Mode 2 is similar to the famous "Mode 7" on the SNES, and Modes 3, 4, and 5 are bitmap modes much like 80s home computers where individual pixels can be edited. Visibility of the background layers are controlled by bits 8 through 12 (going from right to left).
 
For example, to set the screen to Mode 3 with Background 2 visible:
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
MOV R1,#0x04000000
MOV R0,#0x403
STR r1r0,[r0r1] ;the game boy advance is little-endian, so I would have expected this not to work. However it does indeed work.
</syntaxhighlight>
 
=={{header|BBC BASIC}}==
<langsyntaxhighlight lang="bbcbasic">10 MODE 1: REM 320x256 4 colour graphics</langsyntaxhighlight>
 
=={{header|Commodore BASIC}}==
Line 150 ⟶ 271:
====Program Listing====
 
<langsyntaxhighlight lang="gwbasic">10 rem video modes - c64
15 rem rosetta code
20 print chr$(147);chr$(14):poke 53280,0:poke 53281,0:poke 646,1
Line 254 ⟶ 375:
9000 print "Press any key for next screen.";
9010 get k$:if k$="" then 9010
9020 return</langsyntaxhighlight>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
Delphi is primarily a language used under advanced operating systems such as Windows, Linux and iOS. Under Windows, the video resolution and color depth is controlled by Windows, the monitor, the video card and the choices of the user. These days, color is almost always set to 32-bit pixels with 8-bits for Red, Green and Blue, plus an alpha channel for transparency. Most people run their displays at 1080P resolution or higher. So under Windows, you typically have the highest possible resolution. Given these resolutions and the size of monitors these days, there is so much graphics real estate on the average display, that most programs only need to use a portion of the screen to display all their information.
 
Under these circumstances, the only way you could change the screen resolution or color depth would be to change it downward. The only reason you'd ever want lower resolution displays is if you were simulating the pixelated, low quality graphics of old computers. And, if you really want to display a low graphics, it is pretty easy to simulate it with high resolution graphics.
 
Delphi supports working in the world of high resolution displays by allowing you to easily create windows that are sizable by the programmer or the user. It supports putting text in a window with components like the "TMemo" object. Likewise, you can draw or put images into a window with the "TImage" component.
 
As an example of how this works, here is some code that would wrote text into a text window:
 
<syntaxhighlight lang="Delphi">
begin
Memo.Line.Add('Hello World');
end;
</syntaxhighlight>
 
Here's an example of drawing lines in a graphics window;
 
<syntaxhighlight lang="Delphi">
 
begin
Image.Canvas.MoveTo(0,0);
Image.Canvas.LineTo(100,100);
end;
 
 
 
 
</syntaxhighlight>
{{out}}
[[File:DelphiMemoWindow.png|frame|none]]
[[File:DelphiImageWindow.png|frame|none]]
<pre>
 
</pre>
 
=={{header|ERRE}}==
Line 268 ⟶ 426:
 
ERRE language (for C-64) support high resolution graphic (320x200) using HGR.LIB library.
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">dim as integer i, w, h, d
 
for i = 0 to 21
if i>2 and i<7 then continue for 'screens 3-6 are not defined
screen i
screeninfo w, h, d
print "Screen ";i
print using "#### x ####, color depth ##";w;h;d
sleep
next i
 
'a more flexible alternative is ScreenRes
 
'this sets up a window of 1618x971 pixels, colour depth 8, and 2 pages
screenres 1618, 971, 8, 2
windowtitle "Foo bar baz"
sleep
 
 
'see https://documentation.help/FreeBASIC/KeyPgScreengraphics.html
'for more information
</syntaxhighlight>
 
=={{header|Go}}==
{{trans|UNIX Shell}}
{{works with|Ubuntu 16.04}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 302 ⟶ 484:
log.Fatal(err)
}
}</langsyntaxhighlight>
 
{{out}}
Line 330 ⟶ 512:
{{trans|Kotlin}}
{{works with|Ubuntu 14.04}}
<langsyntaxhighlight lang="groovy">def invoke(String cmd) { println(cmd.execute().text) }
 
invoke("xrandr -q")
Line 338 ⟶ 520:
Thread.sleep(3000)
 
invoke("xrandr -s 1366x768")</langsyntaxhighlight>
 
{{out}}
Line 360 ⟶ 542:
GWBASIC version used: 3.23'''
 
<langsyntaxhighlight lang="gwbasic">10 REM GW Basic can switch VGA modes
20 SCREEN 18: REM Mode 12h 640x480 16 colour graphics</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
Line 369 ⟶ 551:
 
{{trans|UNIX Shell}}
<langsyntaxhighlight lang="unicon">procedure main(A)
mode := A[1]
if \mode then system("xrandr -s " || \mode || " >/dev/null")
else system("xrandr -q") # Display available modes
end</langsyntaxhighlight>
 
Output with no arguments:
Line 401 ⟶ 583:
640x480 75.0 59.9
->
</pre>
 
=={{header|J}}==
 
{{omit from|J}} This isn't a J issue, it's an OS issue. Thus, for example, we could use <code>2!:0'xrandr -s 640x480'</code> on an operating system where that provides meaningful behavior. And, we could use <code>shell'mode CON: COLS=40 LINES=100'[require'task'</code> on an operating system where that provides meaningful behavior (and <tt>2!:0</tt> does not work on windows -- on linux this <tt>shell</tt> command is equivalent to <tt>2!:0</tt>). But these won't work in the general case of an arbitrary operating system and arbitrary video hardware, and it's probably best handle such tasks before starting J.
 
=={{header|Java}}==
<syntaxhighlight lang="java">
 
import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.util.concurrent.TimeUnit;
 
import javax.swing.JFrame;
import javax.swing.JLabel;
 
public final class VideoDisplay {
public static void main(String[] aArgs) throws InterruptedException {
GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] screens = environment.getScreenDevices();
System.out.println("Number of video screens: " + screens.length + System.lineSeparator());
for ( GraphicsDevice screen : screens ) {
System.out.println("Full screen display is supported: "
+ screen.isFullScreenSupported() + System.lineSeparator());
GraphicsConfiguration[] configurations = screen.getConfigurations();
System.out.println("This screen has number of configurations: " + configurations.length);
for ( GraphicsConfiguration config : configurations ) {
System.out.println("Configuration supports translucency: " + config.isTranslucencyCapable());
}
DisplayMode[] modes = screen.getDisplayModes();
System.out.println(System.lineSeparator() + "This screen has " + modes.length + " modes of operation");
for ( DisplayMode mode : modes ) {
System.out.println(mode.getWidth() + " X " + mode.getHeight()
+ " with refresh rate " + mode.getRefreshRate() + " Hz");
}
}
// Uncomment the line below to see an example of programmatically changing the video display.
// new VideoDisplay();
}
private VideoDisplay() throws InterruptedException {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Video Display Demonstration");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBackground(Color.LIGHT_GRAY);
frame.add( new JLabel(MESSAGE) );
frame.setSize(800, 600);
GraphicsDevice screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
DisplayMode originalDisplayMode = screen.getDisplayMode();
screen.setFullScreenWindow(frame);
screen.setDisplayMode( new DisplayMode(800, 600, 32, 60) );
frame.setVisible(true);
TimeUnit.SECONDS.sleep(3);
screen.setDisplayMode(originalDisplayMode);
TimeUnit.SECONDS.sleep(3);
Runtime.getRuntime().exit(0);
}
private static final String MESSAGE = "Please wait for a few seconds."
+ " Your video display will then be returned to its original setting.";
}
</syntaxhighlight>
{{ out }}
<pre>
Number of video screens: 1
 
Full screen display is supported: true
 
This screen has number of configurations: 1
Configuration supports translucency: true
 
This screen has 11 modes of operation
640 X 480 with refresh rate 60 Hz
800 X 600 with refresh rate 60 Hz
1024 X 768 with refresh rate 60 Hz
1128 X 634 with refresh rate 60 Hz
1280 X 720 with refresh rate 60 Hz
1280 X 1024 with refresh rate 60 Hz
1366 X 768 with refresh rate 60 Hz
1600 X 900 with refresh rate 60 Hz
1680 X 1050 with refresh rate 60 Hz
1760 X 990 with refresh rate 60 Hz
1920 X 1080 with refresh rate 60 Hz
</pre>
 
=={{header|Julia}}==
{{trans|Phix}}
<langsyntaxhighlight lang="julia">
if Base.Sys.islinux()
run(`xrandr -s 640x480`)
Line 415 ⟶ 696:
run(`mode CON: COLS=100 LINES=50`)
end
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{trans|UNIX Shell}}
{{works with|Ubuntu 14.04}}
<langsyntaxhighlight lang="scala">// version 1.1.51
 
import java.util.Scanner
Line 444 ⟶ 725:
// change it back again to 1366x768 (or whatever is optimal for your system)
runSystemCommand("xrandr -s 1366x768")
}</langsyntaxhighlight>
 
{{out}}
Line 469 ⟶ 750:
* Mode 2 - Graphics: 640x200 Text: 80x25 Colours: 2
Note that text can be displayed using conventional means in all display modes.
<langsyntaxhighlight lang="locobasic">10 MODE 0: REM switch to mode 0</langsyntaxhighlight>
 
=={{header|Lua}}==
Certain terminals may support the following..
<syntaxhighlight lang="lua">print("\33[?3h") -- 132-column text
print("\33[?3l") -- 80-column text</syntaxhighlight>
 
=={{header|Nim}}==
{{works with|Linux}}
Using the command "xrandr" on Linux systems.
<langsyntaxhighlight Nimlang="nim">import os, osproc, strformat, strscans
 
# Retrieve video modes.
Line 505 ⟶ 790:
echo "\nSwitching back to ", prevMode
sleep 2000
discard execProcess("xrandr", "", ["-s", prevMode], nil, {poUsePath})</langsyntaxhighlight>
 
{{out}}
Line 539 ⟶ 824:
Same caveats as with Raku.
{{trans|Raku}}
<langsyntaxhighlight lang="perl">$| = 1;
 
my @info = `xrandr -q`;
Line 557 ⟶ 842:
}
system("xrandr -s $current");
print "\rResolution returned to $current.\n";</langsyntaxhighlight>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(notonline)-->
<lang Phix>if platform()=LINUX then
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (system, system_exec, sleep)</span>
{} = system_exec("xrandr -s 640x480")
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()=</span><span style="color: #004600;">LINUX</span> <span style="color: #008080;">then</span>
sleep(3)
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">system_exec</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"xrandr -s 640x480"</span><span style="color: #0000FF;">)</span>
{} = system_exec("xrandr -s 1280x960")
<span style="color: #7060A8;">sleep</span><span style="color: #0000FF;">(</span><span style="color: #000000;">3</span><span style="color: #0000FF;">)</span>
else -- WINDOWS
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">system_exec</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"xrandr -s 1280x960"</span><span style="color: #0000FF;">)</span>
puts(1,"") -- (ensure console exists)
<span style="color: #008080;">else</span> <span style="color: #000080;font-style:italic;">-- WINDOWS</span>
system("mode CON: COLS=40 LINES=25")
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (ensure console exists)</span>
sleep(3)
<span style="color: #7060A8;">system</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"mode CON: COLS=8040 LINES=25"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">sleep</span><span style="color: #0000FF;">(</span><span style="color: #000000;">3</span><span style="color: #0000FF;">)</span>
end if</lang>
<span style="color: #7060A8;">system</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"mode CON: COLS=80 LINES=25"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</syntaxhighlight>-->
Obviously running xrandr -q or mode -? will tell you more.
 
Line 577 ⟶ 865:
{{libheader|win32pywintypes}}
This program changes the resolution the screen is running at to 640x480.
<langsyntaxhighlight lang="python">import win32api
import win32con
import pywintypes
Line 584 ⟶ 872:
devmode.PelsHeight=480
devmode.Fields=win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT
win32api.ChangeDisplaySettings(devmode,0)</langsyntaxhighlight>
 
=={{header|QBasic}}==
'''This example is wrong! QBASIC can use EGA/VGA Graphics until SCREEN 13 (320x200 - 256 colors) or SCREEN 12 (640x480 - 16 colors).QBASIC version used: 1.1'''
<langsyntaxhighlight lang="qbasic">'QBasic can switch VGA modes
SCREEN 18 'Mode 12h 640x480 16 colour graphics</langsyntaxhighlight>
 
=={{header|Raku}}==
Line 599 ⟶ 887:
{{works with|Rakudo|2018.05}}
 
<syntaxhighlight lang="raku" perl6line>my @info = QX('xrandr -q').lines;
 
@info[0] ~~ /<?after 'current '>(\d+) ' x ' (\d+)/;
Line 614 ⟶ 902:
}
QX("xrandr -s $current");
say "\rResolution returned to {$current}. ";</langsyntaxhighlight>
 
=={{header|REXX}}==
Line 624 ⟶ 912:
 
===version 1: no checking for which OS===
<langsyntaxhighlight lang="rexx">/*REXX program to switch video display modes based on columns and lines.*/
 
parse arg cols lines .
'MODE' "CON: COLS="cols 'LINES='lines
/*stick a fork in it, we're done.*/</langsyntaxhighlight>
===version 2: checks for which OS===
The prologue code (at the bottom of the program) is a collection of some general-purpose subroutines which determine:
Line 644 ⟶ 932:
All the prologue was left intact to give a general feel of the scope of the boilerplate code.
The prologue code is in many REXX programs and it's easier to keep them on one line for copying purposes and sorting.
<langsyntaxhighlight lang="rexx">/*REXX program to switch video display modes based on columns and lines.*/
parse arg !; if !all() then exit /*exit if documentation specified*/
if \!dos & \!os2 then exit /*if this isn't DOS, then exit. */
Line 659 ⟶ 947:
!rex:parse upper version !ver !vernum !verdate .;!brexx='BY'==!vernum;!kexx='KEXX'==!ver;!pcrexx='REXX/PERSONAL'==!ver|'REXX/PC'==!ver;!r4='REXX-R4'==!ver;!regina='REXX-REGINA'==left(!ver,11);!roo='REXX-ROO'==!ver;call !env;return
!sys:!cms=!sys=='CMS';!os2=!sys=='OS2';!tso=!sys=='TSO'|!sys=='MVS';!vse=!sys=='VSE';!dos=pos('DOS',!sys)\==0|pos('WIN',!sys)\==0|!sys=='CMD';call !rex;return
!var:call !fid;if !kexx then return space(dosenv(arg(1)));return space(value(arg(1),,!env))</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
system("mode 40, 25")
</syntaxhighlight>
</lang>
 
=={{header|Scala}}==
{{trans|UNIX Shell}}
{{works with|Ubuntu 14.04}}
<langsyntaxhighlight lang="scala">object VideoDisplayModes extends App {
 
import java.util.Scanner
Line 695 ⟶ 983:
runSystemCommand("xrandr -s 1366x768")
 
}</langsyntaxhighlight>
 
=={{header|smart BASIC}}==
Line 706 ⟶ 994:
 
'''EXAMPLE:'''
<langsyntaxhighlight lang="qbasic">GRAPHICS
FILL RECT 50,50 SIZE 50
GRAPHICS MODE CLEAR
FILL RECT 50,50 SIZE 25</langsyntaxhighlight>
 
=={{header|UNIX Shell}}==
If the system runs X11 and supports XRANDR, then
<syntaxhighlight lang ="bash">$ xrandr -q</langsyntaxhighlight>
lists the available modes, and
<syntaxhighlight lang ="bash">$ xrandr -s 1024x768</langsyntaxhighlight>
sets the screen to the given size.
 
With modern LCD monitors, this feature is not very useful. These monitors have a single best mode, and the X server discovers and uses that mode by default. Smaller screen modes might work, but make a blurry picture.
 
=={{header|Wren}}==
The ability to call external processes such as ''xrandr'' is expected to be added to Wren-cli in the next release. In the meantime, we embed the following Wren script in a minimal C host (no error checking) to complete this task.
<syntaxhighlight lang="wren">/* Video_display_modes.wren */
 
class C {
foreign static xrandr(args)
 
foreign static usleep(usec)
}
 
// query supported display modes
C.xrandr("-q")
 
C.usleep(3000)
 
// change display mode to 1368x768
System.print("\nChanging to 1368 x 768 mode.")
C.xrandr("-s 1368x768")
 
C.usleep(3000)
 
// change it back again to 1920x1080
System.print("\nReverting to 1920 x 1080 mode.")
C.xrandr("-s 1920x1080")</syntaxhighlight>
<br>
We now embed this in the following C program, compile and run it.
<syntaxhighlight lang="c">/* gcc Video_display_modes.c -o Video_display_modes -lwren -lm */
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "wren.h"
 
void C_xrandr(WrenVM* vm) {
const char *arg = wrenGetSlotString(vm, 1);
char command[strlen(arg) + 8];
strcpy(command, "xrandr ");
strcat(command, arg);
system(command);
}
 
void C_usleep(WrenVM* vm) {
useconds_t usec = (useconds_t)wrenGetSlotDouble(vm, 1);
usleep(usec);
}
 
WrenForeignMethodFn bindForeignMethod(
WrenVM* vm,
const char* module,
const char* className,
bool isStatic,
const char* signature) {
if (strcmp(module, "main") == 0) {
if (strcmp(className, "C") == 0) {
if (isStatic && strcmp(signature, "xrandr(_)") == 0) return C_xrandr;
if (isStatic && strcmp(signature, "usleep(_)") == 0) return C_usleep;
}
}
return NULL;
}
 
static void writeFn(WrenVM* vm, const char* text) {
printf("%s", text);
}
 
char *readFile(const char *fileName) {
FILE *f = fopen(fileName, "r");
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
rewind(f);
char *script = malloc(fsize + 1);
fread(script, 1, fsize, f);
fclose(f);
script[fsize] = 0;
return script;
}
 
int main(int argc, char **argv) {
WrenConfiguration config;
wrenInitConfiguration(&config);
config.writeFn = &writeFn;
config.bindForeignMethodFn = &bindForeignMethod;
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "Video_display_modes.wren";
char *script = readFile(fileName);
wrenInterpret(vm, module, script);
wrenFreeVM(vm);
free(script);
return 0;
}</syntaxhighlight>
 
{{out}}
<pre>
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384
eDP-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 344mm x 193mm
1920x1080 60.01*+ 60.01 59.97 59.96 59.93
1680x1050 59.95 59.88
1600x1024 60.17
1400x1050 59.98
1600x900 59.99 59.94 59.95 59.82
1280x1024 60.02
1440x900 59.89
1400x900 59.96 59.88
1280x960 60.00
1440x810 60.00 59.97
1368x768 59.88 59.85
1360x768 59.80 59.96
1280x800 59.99 59.97 59.81 59.91
1152x864 60.00
1280x720 60.00 59.99 59.86 59.74
1024x768 60.04 60.00
960x720 60.00
928x696 60.05
896x672 60.01
1024x576 59.95 59.96 59.90 59.82
960x600 59.93 60.00
960x540 59.96 59.99 59.63 59.82
800x600 60.00 60.32 56.25
840x525 60.01 59.88
864x486 59.92 59.57
800x512 60.17
700x525 59.98
800x450 59.95 59.82
640x512 60.02
720x450 59.89
700x450 59.96 59.88
640x480 60.00 59.94
720x405 59.51 58.99
684x384 59.88 59.85
680x384 59.80 59.96
640x400 59.88 59.98
576x432 60.06
640x360 59.86 59.83 59.84 59.32
512x384 60.00
512x288 60.00 59.92
480x270 59.63 59.82
400x300 60.32 56.34
432x243 59.92 59.57
320x240 60.05
360x202 59.51 59.13
320x180 59.84 59.32
DP-1 disconnected (normal left inverted right x axis y axis)
HDMI-1 disconnected (normal left inverted right x axis y axis)
HDMI-2 disconnected (normal left inverted right x axis y axis)
 
Changing to 1368 x 768 mode.
 
Reverting to 1920 x 1080 mode.
</pre>
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">code SetVid=45;
SetVid(Mode)</langsyntaxhighlight>
Any display mode supported by the IBM-PC-compatible hardware and by the VGA or VESA standards can be enabled by calling the SetVid intrinsic routine. This works without problem on computers booted into DOS and under versions of Windows up until XP. DOSBox[http://www.dosbox.com/] gets around most of the incompatibilities introduced by WinXP and later versions.
 
9,482

edits