Video display modes: Difference between revisions

m
→‎{{header|Wren}}: Removed a blank line
m (→‎{{header|Wren}}: Removed a blank line)
 
(17 intermediate revisions by 6 users not shown)
Line 4:
===Apple II===
* Change to 80-column display:
<langsyntaxhighlight lang="6502asm">LDA #3
JSR $FE95</langsyntaxhighlight>
* Change to 40-column display:
<langsyntaxhighlight lang="6502asm">LDA #0
JSR $FE95</langsyntaxhighlight>
 
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}}
* Change to text mode:<code>STA $C050</code>
 
* Change to graphics mode:<code>STA $C051</code>
* Display page 1 of video memory:<code>STA $C054C050</code>:Change to text mode
* Display page 2 of video memory:<code>STA $C055C051</code>:Change to graphics mode
* <code>STA $C052</code>:Change to full screen (whatever mode you're "in" takes up the whole screen)
* Change graphics mode to low-resolution (16-color) mode:<code>STA $C056</code>
* <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)
* Change graphics mode to hi-resolution (6-color) mode:<code>STA $C057</code>
* <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}}
<langsyntaxhighlight lang="asm">mov ah,00h
mov al,videoMode
int 10h</langsyntaxhighlight>
 
There are quite a few valid values for <code>videoMode</code>, here are a few of them:
Line 40 ⟶ 47:
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">PROC ShowMode(BYTE m,split,gr
CARD w, BYTE h,
CARD size,
Line 111 ⟶ 118:
ShowMode(30,0,1,160,192,3840,"2 colors")
ShowMode(31,0,1,160,192,7680,"4 colors")
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Video_display_modes.png Screenshot from Atari 8-bit computer]
Line 117 ⟶ 124:
=={{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 136 ⟶ 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 155 ⟶ 162:
180 IF A$ = "G" THEN POKE -16304,0 : REM GRAPHICS
190 IF A$ <> "Q" THEN 100
200 TEXT</langsyntaxhighlight>
 
=={{header|ARM Assembly}}==
Line 164 ⟶ 171:
 
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 r0,[r1] ;the game boy advance is little-endian, so I would have expected this not to work. However it does indeed work.
</syntaxhighlight>
</lang>
 
=={{header|BBC BASIC}}==
<langsyntaxhighlight lang="bbcbasic">10 MODE 1: REM 320x256 4 colour graphics</langsyntaxhighlight>
 
=={{header|Commodore BASIC}}==
Line 264 ⟶ 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 368 ⟶ 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 384 ⟶ 428:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">dim as integer i, w, h, d
 
for i = 0 to 21
Line 405 ⟶ 449:
'see https://documentation.help/FreeBASIC/KeyPgScreengraphics.html
'for more information
</syntaxhighlight>
</lang>
 
=={{header|Go}}==
{{trans|UNIX Shell}}
{{works with|Ubuntu 16.04}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 440 ⟶ 484:
log.Fatal(err)
}
}</langsyntaxhighlight>
 
{{out}}
Line 468 ⟶ 512:
{{trans|Kotlin}}
{{works with|Ubuntu 14.04}}
<langsyntaxhighlight lang="groovy">def invoke(String cmd) { println(cmd.execute().text) }
 
invoke("xrandr -q")
Line 476 ⟶ 520:
Thread.sleep(3000)
 
invoke("xrandr -s 1366x768")</langsyntaxhighlight>
 
{{out}}
Line 498 ⟶ 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 507 ⟶ 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 539 ⟶ 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 553 ⟶ 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 582 ⟶ 725:
// change it back again to 1366x768 (or whatever is optimal for your system)
runSystemCommand("xrandr -s 1366x768")
}</langsyntaxhighlight>
 
{{out}}
Line 607 ⟶ 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..
<langsyntaxhighlight lang="lua">print("\33[?3h") -- 132-column text
print("\33[?3l") -- 80-column text</langsyntaxhighlight>
 
=={{header|Nim}}==
{{works with|Linux}}
Using the command "xrandr" on Linux systems.
<langsyntaxhighlight Nimlang="nim">import os, osproc, strformat, strscans
 
# Retrieve video modes.
Line 647 ⟶ 790:
echo "\nSwitching back to ", prevMode
sleep 2000
discard execProcess("xrandr", "", ["-s", prevMode], nil, {poUsePath})</langsyntaxhighlight>
 
{{out}}
Line 681 ⟶ 824:
Same caveats as with Raku.
{{trans|Raku}}
<langsyntaxhighlight lang="perl">$| = 1;
 
my @info = `xrandr -q`;
Line 699 ⟶ 842:
}
system("xrandr -s $current");
print "\rResolution returned to $current.\n";</langsyntaxhighlight>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(notonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (system, system_exec, sleep)</span>
<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>
Line 714 ⟶ 857:
<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>
<!--</langsyntaxhighlight>-->
Obviously running xrandr -q or mode -? will tell you more.
 
Line 722 ⟶ 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 729 ⟶ 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 744 ⟶ 887:
{{works with|Rakudo|2018.05}}
 
<syntaxhighlight lang="raku" perl6line>my @info = QX('xrandr -q').lines;
 
@info[0] ~~ /<?after 'current '>(\d+) ' x ' (\d+)/;
Line 759 ⟶ 902:
}
QX("xrandr -s $current");
say "\rResolution returned to {$current}. ";</langsyntaxhighlight>
 
=={{header|REXX}}==
Line 769 ⟶ 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 789 ⟶ 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 804 ⟶ 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 840 ⟶ 983:
runSystemCommand("xrandr -s 1366x768")
 
}</langsyntaxhighlight>
 
=={{header|smart BASIC}}==
Line 851 ⟶ 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.
 
Line 867 ⟶ 1,010:
=={{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.
<langsyntaxhighlight ecmascriptlang="wren">/* video_display_modesVideo_display_modes.wren */
 
class C {
Line 888 ⟶ 1,031:
// change it back again to 1920x1080
System.print("\nReverting to 1920 x 1080 mode.")
C.xrandr("-s 1920x1080")</langsyntaxhighlight>
<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 */
<lang c>#include <stdio.h>
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Line 948 ⟶ 1,093:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "video_display_modesVideo_display_modes.wren";
char *script = readFile(fileName);
wrenInterpret(vm, module, script);
Line 954 ⟶ 1,099:
free(script);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 1,016 ⟶ 1,161:
 
=={{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