Uefi
Source: lib/Uefi.cs
This page is generated from the source by scripts/gen-reference.py.
The machine under UEFI, with no operating system: a graphics screen, the keyboard, a clock, files, power. Only for programs built with ./build.sh --uefi; the functions are in efi/machine.c, and a program for another target that calls them won't link.
It has the same members as lib/Dos.cs, so a DOS program runs here by using one name for the other (samples/Vga.cs does):
#if UEFI
using Machine = Uefi;
#else
using Machine = Dos;
#endif
The screen is the VGA's 320x200 with 256 colors, scaled up as far as the real screen allows and centered. Scan codes are the PC's, whatever the keyboard is. UEFI reports key presses but not releases, so KeyDown counts a key as held until its repeats stop. The PC speaker and In/Out exist on x64; on arm64 they do nothing (HasSpeaker says which).
Members
Width, Height
public const int Width = 320, Height = 200
Esc, Enter, Space
public const int Esc = 0x01, Enter = 0x1C, Space = 0x39
Up, Down, Left, Right
public const int Up = 0x48, Down = 0x50, Left = 0x4B, Right = 0x4D
Graphics
public static bool Graphics()
Switches to graphics: a 320x200 picture with 256 colors. Returns false if the machine has no graphics output.
Text
public static void Text()
Switches back to the text console.
Screen
public static Span<byte> Screen
What the screen shows, read back from it: Width * Height color numbers (255 where a pixel is no color defined with SetColor). Writing to it changes nothing on the screen; use Show.
Show
public static void Show(ReadOnlySpan<byte> picture)
Shows a picture of Width * Height bytes, a color number per pixel, row after row.
Fill
public static void Fill(Span<byte> picture, byte color)
Sets every byte of a picture (or a part of one) to a color.
SetColor
public static void SetColor(int index, int red, int green, int blue)
Defines one of the 256 colors. Red, green and blue are 0-63, as on the VGA.
WaitFrame
public static void WaitFrame()
Waits for the next frame: 70 a second, as the VGA's graphics mode.
PollKeys
public static int PollKeys()
Takes in the key presses since the last call. Returns how many wait for ReadKey.
KeyDown
public static bool KeyDown(int scanCode)
Whether a key is held down, as of the last PollKeys (see the top of this file).
ReadKey
public static int ReadKey()
The next key press: its scan code in the high byte, its character (0 for keys without one, or outside ASCII) in the low byte. 0 if no key was pressed.
Ticks
public static uint Ticks
Milliseconds since some fixed moment.
Sleep
public static void Sleep(uint milliseconds)
HasSpeaker
public static bool HasSpeaker
Whether Sound and In/Out reach a PC's hardware: true on x64, false on arm64.
Sound
public static void Sound(uint hertz)
Starts a tone on the PC speaker at this pitch; it sounds until the next call. 0 turns it off.
In
public static int In(int port)
Reads a byte from a hardware port (x64; 0 on arm64).
Out
public static void Out(int port, int value)
Writes a byte to a hardware port (x64; nothing on arm64).
MouseStart
public static int MouseStart()
There is no mouse support yet: always 0 buttons.
Mouse
public static int Mouse(out int x, out int y)
With no mouse, the middle of the screen and no buttons.
ForReading, ForWriting, ForAppending
public const int ForReading = 0, ForWriting = 1, ForAppending = 2
FromStart, FromHere, FromEnd
public const int FromStart = 0, FromHere = 1, FromEnd = 2
FileOpen
public static nint FileOpen(string path, int mode)
Opens a file. ForReading needs it to exist; ForWriting creates it or empties it; ForAppending creates it or continues at its end. Returns 0 if that fails.
FileRead
public static int FileRead(nint file, Span<byte> buffer)
Reads up to buffer.Length bytes. Returns how many were read (0 at the end of the file), or -1.
FileWrite
public static int FileWrite(nint file, ReadOnlySpan<byte> bytes)
Writes the bytes. Returns how many were written, or -1.
FileSeek
public static int FileSeek(nint file, int offset, int origin)
Moves to a position, counted FromStart, FromHere or FromEnd. Returns the new position, or -1.
FileSize
public static int FileSize(nint file)
FileClose
public static void FileClose(nint file)
FileDelete
public static bool FileDelete(string path)
Deletes a file. Returns false if there was none or it couldn't be deleted.
Shutdown
public static void Shutdown()
Turns the machine off. Doesn't return.
Reboot
public static void Reboot()
Restarts the machine. Doesn't return.