Dos
Source: lib/Dos.cs
This page is generated from the source by scripts/gen-reference.py.
The PC under DOS: the VGA's 320x200, 256-color graphics mode, the keyboard, the mouse, the speaker, a clock and files. Only for programs built with ./build.sh --dos; the functions are in dos/runtime.c, and a program for another target that calls them won't link.
Dos.Graphics(); // 320x200, one byte per pixel
Dos.SetColor(1, 63, 0, 0); // color 1: bright red (0-63 each)
Span<byte> screen = Dos.Screen; // screen[y * 320 + x] = color
while (!Dos.KeyDown(Dos.Esc)) { Dos.PollKeys(); ...; Dos.WaitFrame(); }
Dos.Text(); // back to the text screen
Draw into a buffer of your own and Dos.Show it right after WaitFrame: writing the screen while it's being shown flickers. Dos.Show and Dos.Fill use the processor's block instructions; on a 386 a whole screen takes them a few milliseconds, against a hundred for Span's CopyTo and Fill.
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 void Graphics()
Switches to 320x200 with 256 colors.
Text
public static void Text()
Switches back to the 80x25 text screen.
Screen
public static Span<byte> Screen
The screen in graphics mode: Width * Height bytes, a color number per pixel, row after row.
Show
public static void Show(ReadOnlySpan<byte> picture)
Copies a picture of Width * Height bytes to the screen.
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.
WaitFrame
public static void WaitFrame()
Waits for the next screen refresh: 70 a second in graphics mode. Returns at the moment to copy a finished picture to Screen.
PollKeys
public static int PollKeys()
Takes in what happened on the keyboard since the last call. Returns how many key presses wait for ReadKey.
KeyDown
public static bool KeyDown(int scanCode)
Whether a key is held down, as of the last PollKeys.
ReadKey
public static int ReadKey()
The next key press: its scan code in the high byte, its character (0 for keys without one) 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)
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.
MouseStart
public static int MouseStart()
Looks for a mouse driver (CTMOUSE, MOUSE.COM, ...). Returns the number of buttons, or 0 without one. Call it after Graphics(): drivers reset themselves when the screen mode changes.
Mouse
public static int Mouse(out int x, out int y)
Where the mouse is on the graphics screen (0 to Width - 1 and Height - 1). Returns the buttons held: 1 left, 2 right, 4 middle, added up.
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 (fewer if the disk is full), 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.
In
public static int In(int port)
Reads a byte from a hardware port.
Out
public static void Out(int port, int value)
Writes a byte to a hardware port.