Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,4 @@
---
category:
- Initialization
from: http://rosettacode.org/wiki/Video_display_modes

View file

@ -0,0 +1 @@
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.

View file

@ -0,0 +1,2 @@
LDA #3
JSR $FE95

View file

@ -0,0 +1,2 @@
LDA #0
JSR $FE95

View file

@ -0,0 +1,3 @@
mov ah,00h
mov al,videoMode
int 10h

View file

@ -0,0 +1,3 @@
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.

View file

@ -0,0 +1,72 @@
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

View file

@ -0,0 +1 @@
SCREEN 1,320,200,5,1

View file

@ -0,0 +1 @@
SCREEN CLOSE 1

View file

@ -0,0 +1,20 @@
10 GR
20 FOR I = 0 TO 15 : COLOR = I : PLOT I,I : NEXT
30 HGR
40 FOR I = 1 TO 6 : HCOLOR = I : HPLOT I * 2, I TO I * 2 + 1, I : NEXT
50 TEXT
60 HOME : FOR I = 0 TO 7 : VTAB I + 1 : FOR J = 0 TO 31 : POKE PEEK(40) + PEEK(41) * 256 + 4 + J, I * 32 + J : NEXT J, I
70 HGR2
80 FOR I = 1 TO 6 : HCOLOR = I : HPLOT I * 2, I + 6 TO I * 2 + 1, I + 6 : NEXT
90 TEXT
100 GET A$
110 IF A$ = "H" THEN POKE -16297,0 : REM HI-RESOLUTION
120 IF A$ = "L" THEN POKE -16298,0 : REM LO-RESOLUTION
130 IF A$ = "2" THEN POKE -16299,0 : REM PAGE 2
140 IF A$ = "1" THEN POKE -16300,0 : REM PAGE 1
150 IF A$ = "M" THEN POKE -16301,0 : REM MIXED TEXT
160 IF A$ = "F" THEN POKE -16302,0 : REM FULL SCREEN
170 IF A$ = "T" THEN POKE -16303,0 : REM TEXT
180 IF A$ = "G" THEN POKE -16304,0 : REM GRAPHICS
190 IF A$ <> "Q" THEN 100
200 TEXT

View file

@ -0,0 +1 @@
10 MODE 1: REM 320x256 4 colour graphics

View file

@ -0,0 +1,105 @@
10 rem video modes - c64
15 rem rosetta code
20 print chr$(147);chr$(14):poke 53280,0:poke 53281,0:poke 646,1
25 poke 53282,2:poke 53283,11:poke 53284,9:rem set extended and multi colors
30 if peek(12288)=60 and peek(12289)=102 then goto 100
35 poke 52,32:poke 56,32:clr
40 print "Initializing - Please wait..."
45 poke 56334,peek(56334) and 254:poke1,peek(1) and 251
50 for i=0 to 4096:poke i+12288,peek(i+53248):next
55 poke1,peek(1) or 4:poke56334,peek(56334) or 1
60 for i=0 to 31:read d:poke 15368+i,d:next i
65 x=0:for i=8192 to 10239:poke i,2^x:x=(x+1) and 7:next
70 for i=10240 to 12287:poke i,228:next
100 data 60,66,165,129,165,153,66,60
105 data 60,66,165,129,153,165,66,60
110 data 245,245,245,245,10,10,10,10
115 data 10,10,10,10,245,245,245,245
480 print chr$(147);"Demonstration of Video Modes"
485 print
490 print "The video modes described at Rosetta "
495 print "Code will be demonstrated in order. "
500 print "Simply press a key to advance to the"
505 print "next video mode."
510 print
515 print "See rosettacode.org for description."
516 print
517 print "http://www.rosettacode.org/wiki/";
518 print "Video";chr$(164);"display";chr$(164);"modes#";
519 print "Commodore";chr$(164);"BASIC"
520 print
525 print "Press any key to begin."
530 gosub 9010
600 print chr$(147);"Standard Character Mode"
605 print " - ROM Characters"
610 print:gosub 1000:print:gosub 9000:print chr$(147)
615 gosub 1210
620 print chr$(147);"Multicolor Character Mode"
625 print " - ROM Characters"
630 print:gosub 1000:print:gosub 9000:print chr$(147)
635 gosub 1220
640 gosub 1310
645 print chr$(147);"Extended Color Character Mode"
650 print " - ROM Characters"
655 print:gosub 1000:print:gosub 9000:print chr$(147)
660 gosub 1320
665 gosub 1100
670 print chr$(147);"Standard Character Mode"
675 print " - Programmed Characters"
680 print:gosub 1000:print:gosub 9000:print chr$(147)
685 gosub 1210
690 print chr$(147);"Multicolor Character Mode"
695 print " - Programmed Characters"
700 print:gosub 1000:print:gosub 9000:print chr$(147)
705 gosub 1220
710 gosub 1310
715 print chr$(147);"Extended Color Character Mode"
720 print " - Programmed Characters"
725 print:gosub 1000:print:gosub 9000:print chr$(147)
730 gosub 1320
735 print chr$(147);"The next screen will be the"
740 print "High Resolution Bit Map Mode"
745 print
750 gosub 9000
755 gosub 1430:gosub 1410
760 print:gosub 1050:print:gosub 9010:print chr$(147)
765 gosub 1420:gosub 1120
770 print chr$(147);"The next screen will be the"
775 print "Multicolor High Resolution Bit Map Mode"
780 print
785 gosub 9000
790 gosub 1430:gosub 1410:gosub 1210
795 print:gosub 1050:print:gosub 9010:print chr$(147)
800 gosub 1420:gosub 1220:gosub 1120
805 print chr$(147);"End of demonstration."
810 end
1000 rem put some characters up for demo
1005 for i=0 to 15:poke 646,i
1010 print" a b c d ";
1011 print chr$(160);"A";chr$(160);"B";chr$(160);"C";chr$(160);"D";chr$(160);
1012 print chr$(18);" a b c d ";
1013 print chr$(160);"A";chr$(160);"B";chr$(160);"C";chr$(160);"D";chr$(160);
1014 print chr$(146)
1015 next i:poke 646,1
1020 return
1050 rem show color variety for hi-res modes
1051 print chr$(147)
1055 for i=0 to 255:poke 1024+i,i:poke 55296+i,1:next
1060 for i=0 to 255:poke 1280+i,i:poke 55552+i,int(rnd(1)*16):next
1065 return
1100 rem programmable character mode
1110 poke 53272,(peek(53272) and 240)+14:return:rem on
1120 poke 53272,(peek(53272) and 240)+6:return:rem off
1200 rem multicolor mode
1210 poke 53270,peek(53270) or 16:return:rem on
1220 poke 53270,peek(53270) and 239:return:rem off
1300 rem extended color mode
1310 poke 53265,peek(53265) or 64:return:rem on
1320 poke 53265,peek(53265) and 191:return:rem off
1400 rem hi res mode
1410 poke 53265,(peek(53265) or 32):return:rem on
1420 poke 53265,(peek(53265) and 223):return:rem off
1430 poke 53272,peek(53272) or 8:return:rem place bitmap at 8192
9000 print "Press any key for next screen.";
9010 get k$:if k$="" then 9010
9020 return

View file

@ -0,0 +1,3 @@
begin
Memo.Line.Add('Hello World');
end;

View file

@ -0,0 +1,4 @@
begin
Image.Canvas.MoveTo(0,0);
Image.Canvas.LineTo(100,100);
end;

View file

@ -0,0 +1,21 @@
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

View file

@ -0,0 +1,2 @@
10 REM GW Basic can switch VGA modes
20 SCREEN 18: REM Mode 12h 640x480 16 colour graphics

View file

@ -0,0 +1,31 @@
package main
import (
"fmt"
"log"
"os/exec"
"time"
)
func main() {
// query supported display modes
out, err := exec.Command("xrandr", "-q").Output()
if err != nil {
log.Fatal(err)
}
fmt.Println(string(out))
time.Sleep(3 * time.Second)
// change display mode to 1024x768 say (no text output)
err = exec.Command("xrandr", "-s", "1024x768").Run()
if err != nil {
log.Fatal(err)
}
time.Sleep(3 * time.Second)
// change it back again to 1366x768 (or whatever is optimal for your system)
err = exec.Command("xrandr", "-s", "1366x768").Run()
if err != nil {
log.Fatal(err)
}
}

View file

@ -0,0 +1,9 @@
def invoke(String cmd) { println(cmd.execute().text) }
invoke("xrandr -q")
Thread.sleep(3000)
invoke("xrandr -s 1024x768")
Thread.sleep(3000)
invoke("xrandr -s 1366x768")

View file

@ -0,0 +1,5 @@
procedure main(A)
mode := A[1]
if \mode then system("xrandr -s " || \mode || " >/dev/null")
else system("xrandr -q") # Display available modes
end

View file

@ -0,0 +1,68 @@
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.";
}

View file

@ -0,0 +1,9 @@
if Base.Sys.islinux()
run(`xrandr -s 640x480`)
sleep(3)
run(`xrandr -s 1280x960`)
else # windows
run(`mode CON: COLS=40 LINES=100`)
sleep(3)
run(`mode CON: COLS=100 LINES=50`)
end

View file

@ -0,0 +1,25 @@
// version 1.1.51
import java.util.Scanner
fun runSystemCommand(command: String) {
val proc = Runtime.getRuntime().exec(command)
Scanner(proc.inputStream).use {
while (it.hasNextLine()) println(it.nextLine())
}
proc.waitFor()
println()
}
fun main(args: Array<String>) {
// query supported display modes
runSystemCommand("xrandr -q")
Thread.sleep(3000)
// change display mode to 1024x768 say (no text output)
runSystemCommand("xrandr -s 1024x768")
Thread.sleep(3000)
// change it back again to 1366x768 (or whatever is optimal for your system)
runSystemCommand("xrandr -s 1366x768")
}

View file

@ -0,0 +1 @@
10 MODE 0: REM switch to mode 0

View file

@ -0,0 +1,2 @@
print("\33[?3h") -- 132-column text
print("\33[?3l") -- 80-column text

View file

@ -0,0 +1,31 @@
import os, osproc, strformat, strscans
# Retrieve video modes.
let p = startProcess("xrandr", "", ["-q"], nil, {poUsePath})
var currWidth, currHeight = 0 # Current video mode.
var width, height = 0 # Some other video mode.
for line in p.lines:
echo line
# Find current display mode, marked by an asterisk.
var f: float
if currWidth == 0:
# Find current width and height.
discard line.scanf(" $s$ix$i $s$f*", currWidth, currHeight, f)
elif width == 0:
# Find another width and height.
discard line.scanf(" $s$ix$i $s$f", width, height, f)
p.close()
# Change video mode.
let newMode = &"{width}x{height}"
sleep 1000
echo "\nSwitching to ", newMode
sleep 2000
discard execProcess("xrandr", "", ["-s", newMode], nil, {poUsePath})
# Restore previous video mode.
let prevMode = &"{currWidth}x{currHeight}"
sleep 1000
echo "\nSwitching back to ", prevMode
sleep 2000
discard execProcess("xrandr", "", ["-s", prevMode], nil, {poUsePath})

View file

@ -0,0 +1,19 @@
$| = 1;
my @info = `xrandr -q`;
$info[0] =~ /current (\d+) x (\d+)/;
my $current = "$1x$2";
my @resolutions;
for (@info) {
push @resolutions, $1 if /^\s+(\d+x\d+)/
}
system("xrandr -s $resolutions[-1]");
print "Current resolution $resolutions[-1].\n";
for (reverse 1 .. 9) {
print "\rChanging back in $_ seconds...";
sleep 1;
}
system("xrandr -s $current");
print "\rResolution returned to $current.\n";

View file

@ -0,0 +1,13 @@
(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>
<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>
<span style="color: #7060A8;">sleep</span><span style="color: #0000FF;">(</span><span style="color: #000000;">3</span><span style="color: #0000FF;">)</span>
<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>
<span style="color: #008080;">else</span> <span style="color: #000080;font-style:italic;">-- WINDOWS</span>
<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>
<span style="color: #7060A8;">system</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"mode CON: COLS=40 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>
<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>
<!--

View file

@ -0,0 +1,8 @@
import win32api
import win32con
import pywintypes
devmode=pywintypes.DEVMODEType()
devmode.PelsWidth=640
devmode.PelsHeight=480
devmode.Fields=win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT
win32api.ChangeDisplaySettings(devmode,0)

View file

@ -0,0 +1,2 @@
'QBasic can switch VGA modes
SCREEN 18 'Mode 12h 640x480 16 colour graphics

View file

@ -0,0 +1,5 @@
/*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.*/

View file

@ -0,0 +1,16 @@
/*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. */
parse arg cols lines .
'MODE' "CON: COLS="cols 'LINES='lines
exit /*stick a fork in it, we're done.*/
/*══════════════════════════════════general 1-line subs═════════════════*/
!all:!!=!;!=space(!);upper !;call !fid;!nt=right(!var('OS'),2)=='NT';!cls=word('CLS VMFCLEAR CLRSCREEN',1+!cms+!tso*2);if arg(1)\==1 then return 0;if wordpos(!,'? ?SAMPLES ?AUTHOR ?FLOW')==0 then return 0;!call=']$H';call '$H' !fn !;!call=;return 1
!cal:if symbol('!CALL')\=="VAR" then !call=;return !call
!env:!env='ENVIRONMENT';if !sys=='MSDOS'|!brexx|!r4|!roo then !env='SYSTEM';if !os2 then !env='OS2'!env;!ebcdic=1=='f0'x;return
!fid:parse upper source !sys !fun !fid . 1 . . !fn !ft !fm .;call !sys;if !dos then do;_=lastpos('\',!fn);!fm=left(!fn,_);!fn=substr(!fn,_+1);parse var !fn !fn '.' !ft;end;return word(0 !fn !ft !fm,1+('0'arg(1)))
!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))

View file

@ -0,0 +1,16 @@
my @info = QX('xrandr -q').lines;
@info[0] ~~ /<?after 'current '>(\d+) ' x ' (\d+)/;
my $current = "$0x$1";
my @resolutions;
@resolutions.push: $0 if $_ ~~ /^\s+(\d+'x'\d+)/ for @info;
QX("xrandr -s @resolutions[*-1]");
say "Current resolution {@resolutions[*-1]}.";
for 9 ... 1 {
print "\rChanging back in $_ seconds...";
sleep 1;
}
QX("xrandr -s $current");
say "\rResolution returned to {$current}. ";

View file

@ -0,0 +1 @@
system("mode 40, 25")

View file

@ -0,0 +1,27 @@
object VideoDisplayModes extends App {
import java.util.Scanner
def runSystemCommand(command: String) {
val proc = Runtime.getRuntime.exec(command)
val a: Unit = {
val a = new Scanner(proc.getInputStream)
while (a.hasNextLine) println(a.nextLine())
}
proc.waitFor()
println()
}
// query supported display modes
runSystemCommand("xrandr -q")
Thread.sleep(3000)
// change display mode to 1024x768 say (no text output)
runSystemCommand("xrandr -s 1024x768")
Thread.sleep(3000)
// change it back again to 1366x768 (or whatever is optimal for your system)
runSystemCommand("xrandr -s 1366x768")
}

View file

@ -0,0 +1,4 @@
GRAPHICS
FILL RECT 50,50 SIZE 50
GRAPHICS MODE CLEAR
FILL RECT 50,50 SIZE 25

View file

@ -0,0 +1 @@
$ xrandr -q

View file

@ -0,0 +1 @@
$ xrandr -s 1024x768

View file

@ -0,0 +1,22 @@
/* 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")

View file

@ -0,0 +1,64 @@
#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;
}

View file

@ -0,0 +1,2 @@
code SetVid=45;
SetVid(Mode)