unit system

Standard supported functions of Mad Pascal

author: Tomasz Biela (Tebe)


http://www.freepascal.org/docs-html/rtl/system/index-5.html

Constants:

name:value:description:
M_PI_2pi*2
D_PI_2pi/2
D_PI_180pi/180
mGTIA0
mVBXE$80
WINDOW$10text window
NARROW$20narrow screen
VBXE_XDLADR$0000XDLIST
VBXE_BCBADR$0100BLITTER LIST ADDRESS
VBXE_MAPADR$1000COLOR MAP ADDRESS
VBXE_OVRADR$5000OVERLAY ADDRESS
VBXE_WINDOW$B0004K WINDOW $B000..$BFFF
iDLI0set new DLI vector
iVBL1set new VBL vector
CH_DELCHRchr($FE)delete char under the cursor
CH_ENTERchr($9B)
CH_ESCchr($1B)
CH_CURS_UPchr(28)
CH_CURS_DOWNchr(29)
CH_CURS_LEFTchr(30)
CH_CURS_RIGHTchr(31)
CH_TABchr($7F)tabulator
CH_EOLchr($9B)end-of-line marker
CH_CLRchr($7D)clear screen
CH_BELLchr($FD)bell
CH_DELchr($7E)back space (delete char to the left)
CH_DELLINEchr($9C)delete line
CH_INSLINEchr($9D)insert line
COLOR_BLACK$00
COLOR_WHITE$0e
COLOR_RED$32
COLOR_CYAN$96
COLOR_VIOLET$68
COLOR_GREEN$c4
COLOR_BLUE$74
COLOR_YELLOW$ee
COLOR_ORANGE$4a
COLOR_BROWN$e4
COLOR_LIGHTRED$3c
COLOR_GRAY1$04
COLOR_GRAY2$06
COLOR_GRAY3$0a
COLOR_LIGHTGREEN$cc
COLOR_LIGHTBLUE$7c
fmOpenRead$04
fmOpenWrite$08
fmOpenAppend$09
fmOpenReadWrite$0c
threehalfs: single1.5

Types:

name:type:description:
TStringstring[32]
TSizerecord cx, cy: smallint endTSize is a type to describe the size of a rectangular area, where cx is the width, cy is the height (in pixels) of the rectangle.
TRectrecord left, top, right, bottom: smallint endTRect is a type to describe a rectangular area.
TPointrecord x,y: SmallInt endThis record describes a coordinate.

Global Variables:

name:type:description:
ScreenWidthsmallint = 40current screen width
ScreenHeightsmallint = 24current screen height
ScreenModebytecurrent screen mode
IOResultbyteresult of last file IO operation
EoLnBooleanend of line status

Interface:

name:description:
ReadConfig

function ReadConfig(devnum: byte): cardinal; assembler;


Read disk drive configuration
    parameters:
  • devnum - device number
ReadSector

procedure ReadSector(devnum: byte; sector: word; var buf); assembler;


Read disk sector to buffer
    parameters:
  • devnum - device number
  • sector - sector number
  • buf - pointer to buffer
WriteSector

procedure WriteSector(devnum: byte; sector: word; var buf); assembler;


Write disk sector from buffer
    parameters:
  • devnum - device number
  • sector - sector number
  • buf - pointer to buffer
RunError

procedure RunError(a: byte);


Print error message
    parameters:
  • a - error number
HexStr

function HexStr(Value: cardinal; Digits: byte): TString; register; assembler;


Convert cardinal value to string with hexadecimal representation.
    parameters:
  • Value
  • Digits
  • returns:
  • string[32]
Peek

function Peek(a: word): byte; register; assembler;


Reads BYTE from the desired memory address
    parameters:
  • a - memory address
  • returns:
  • byte
DPeek

function DPeek(a: word): word; register; assembler;


Reads WORD from the desired memory address
    parameters:
  • a - memory address
  • returns:
  • word
Randomize

procedure Randomize; assembler;


Initialize random number generator
    Random

    function Random: Real; overload;


    Generate random number
      returns:
    • Real (Q24.8)
    RandomF

    function RandomF: Float;


    Generate random number
      returns:
    • Float (Single)
    Random

    function Random(range: byte): byte; assembler; overload;


    Generate random number
      parameters:
    • range (0..range-1)
    • returns:
    • byte
    Random

    function Random(range: smallint): smallint; overload;


    Generate random number
      parameters:
    • range (0..range-1), (-range..0)
    • returns:
    • smallint
    Abs

    function Abs(x: Real): Real; register; assembler; overload;


    Abs returns the absolute value of a variable.
    The result of the function has the same type as its argument, which can be any numerical type.
      parameters:
    • x - Real (Q24.8)
    • returns:
    • Real (Q24.8)
    Abs

    function Abs(x: Single): Single; register; assembler; overload;


    Abs returns the absolute value of a variable.
    The result of the function has the same type as its argument, which can be any numerical type.
      parameters:
    • x - Single
    • returns:
    • Single
    Abs

    function Abs(x: Integer): Integer; register; assembler; overload;


    Abs returns the absolute value of a variable.
    The result of the function has the same type as its argument, which can be any numerical type.
      parameters:
    • x - Integer
    • returns:
    • Integer
    Sqr

    function Sqr(x: Real): Real; overload;


    Sqr returns the square of its argument X
      parameters:
    • x - Real (Q24.8)
    • returns:
    • Real (Q24.8)
    Sqr

    function Sqr(x: Single): Single; overload;


    Sqr returns the square of its argument X
      parameters:
    • x - Single
    • returns:
    • Single
    Sqr

    function Sqr(x: integer): integer; overload;


    Sqr returns the square of its argument X
      parameters:
    • x - integer
    • returns:
    • integer
    Sqrt

    function Sqrt(x: Real): Real; overload;


    Sqrt returns the square root of its argument X, which must be positive
      parameters:
    • x - Real (Q24.8)
    • returns:
    • Real (Q24.8)
    Sqrt

    function Sqrt(x: Single): Single; overload;


    Sqrt returns the square root of its argument X, which must be positive
      parameters:
    • x - Single
    • returns:
    • Single
    Sqrt

    function Sqrt(x: Integer): Single; overload;


    Sqrt returns the square root of its argument X, which must be positive
      parameters:
    • x - integer
    • returns:
    • integer
    iSqrt

    function iSqrt(number: Single): Single;


    Fast inverse square root
    https://en.wikipedia.org/wiki/Fast_inverse_square_root
    https://pl.wikipedia.org/wiki/Szybka_odwrotno%C5%9B%C4%87_pierwiastka_kwadratowego
      parameters:
    • number - Single
    • returns:
    • Single
    ArcTan

    function ArcTan(value: real): real;


    Arctan returns the Arctangent of Value, which can be any Real type.
    The resulting angle is in radial units.
      parameters:
    • value - Real (Q24.8)
    • returns:
    • Real (Q24.8)
    Exp

    function Exp(x: Real): Real; overload;


    Exp returns the exponent of X, i.e. the number e to the power X.
    https://www.codeproject.com/Tips/311714/Natural-Logarithms-and-Exponent
      parameters:
    • x - Real (Q24.8)
    • returns:
    • Real (Q24.8)
    Exp

    function Exp(x: Float): Float; overload;


    Exp returns the exponent of X, i.e. the number e to the power X.
    https://www.codeproject.com/Tips/311714/Natural-Logarithms-and-Exponent
      parameters:
    • x - Float (Single)
    • returns:
    • Float (Single)
    Ln

    function Ln(x: Real): Real; overload;


    Ln returns the natural logarithm of the Real parameter X. X must be positive.
    https://www.codeproject.com/Tips/311714/Natural-Logarithms-and-Exponent
      parameters:
    • x - Real (Q24.8)
    • returns:
    • Real (Q24.8)
    Ln

    function Ln(x: Float): Float; overload;


    Ln returns the natural logarithm of the Real parameter X. X must be positive.
    https://www.codeproject.com/Tips/311714/Natural-Logarithms-and-Exponent
      parameters:
    • x - Float (Single)
    • returns:
    • Float (Single)
    FileSize

    function FileSize(var f: file): cardinal; assembler;


    Size of file (SDX only)
      parameters:
    • f - file handle
    • returns:
    • cardinal
    FilePos

    function FilePos(var f: file): cardinal; assembler;


    Get position in file (SDX only)
      parameters:
    • f - file handle
    • returns:
    • cardinal
    Seek

    procedure Seek(var f: file; a: cardinal); assembler;


    Set file position (SDX only)
      parameters:
    • f - file handle
    • a - new position
    Eof

    function Eof(var f: file): Boolean;


    Check for end of file
      parameters:
    • f - file handle
    • returns:
    • TRUE if the file-pointer has reached the end of the file
    LowerCase

    function LowerCase(a: char): char;


    Converts a character to lowercase
      parameters:
    • a - char
    • returns:
    • char
    UpCase

    function UpCase(a: char): char;


    Converts a character to uppercase
      parameters:
    • a - char
    • returns:
    • char
    Val

    procedure Val(const s: TString; var v: integer; var code: byte); assembler; overload;


    Calculate numerical value of a string
      parameters:
    • s - string[32]
    • v - pointer to integer - result
    • code - pointer to integer - error code
    Val

    procedure Val(const s: TString; var v: single; var code: byte); overload;


    Calculate numerical value of a string
      parameters:
    • s - string[32]
    • v - pointer to integer - result
    • code - pointer to integer - error code
    FloatToStr

    function FloatToStr(a: real): ^string; assembler;


    Convert a float value to a string
      parameters:
    • a - Real (Q24.8)
    • returns:
    • string[32]
    Str

    procedure Str(a: integer; var s: TString); assembler;


    Convert a numerical value to a string
      parameters:
    • a - integer
    • s - string[32] - result
    Poke

    procedure Poke(a: word; value: byte); register; assembler;


    Store BYTE at the desired memory address
      parameters:
    • a - memory address
    • value (0..255)
    DPoke

    procedure DPoke(a: word; value: word); register; assembler;


    Store WORD at the desired memory address
      parameters:
    • a - memory address
    • value (0..65535)
    FillChar

    procedure FillChar(a: pointer; count: word; value: char); assembler; register; overload;


    Fills the memory starting at A with Count Characters with value equal to Value
      parameters:
    • a - pointer
    • count
    • value - Char
    FillChar

    procedure FillChar(a: pointer; count: word; value: byte); assembler; register; overload;


    Fills the memory starting at A with Count Characters with value equal to Value
      parameters:
    • a - pointer
    • count
    • value - Byte
    FillChar

    procedure FillChar(a: pointer; count: word; value: Boolean); assembler; register; overload;


    Fills the memory starting at A with Count Characters with value equal to Value
      parameters:
    • a - pointer
    • count
    • value - Boolean
    FillChar

    procedure FillChar(var x; count: word; value: char); assembler; register; overload;



      FillChar

      procedure FillChar(var x; count: word; value: byte); assembler; register; overload;



        FillChar

        procedure FillChar(var x; count: word; value: Boolean); assembler; register; overload;



          FillByte

          procedure FillByte(a: pointer; count: word; value: byte); assembler; register; overload;


          Fills the memory starting at A with Count Characters with value equal to Value
            parameters:
          • a - pointer
          • count
          • value - Byte
          FillByte

          procedure FillByte(var x; count: word; value: byte); assembler; register; overload;



            Move

            procedure Move(source, dest: pointer; count: word); assembler; register; overload;


            Moves Count bytes from Source to Dest
              parameters:
            • source - pointer
            • dest - pointer
            • count - word
            • returns:
            • cardinal
            Move

            procedure Move(var source, dest; count: word); assembler; register; overload;



              Move

              procedure Move(var source; dest: pointer; count: word); assembler; register; overload;



                Sin

                function Sin(x: Real): Real; overload;


                Calculate sine of angle
                  parameters:
                • X - angle in radians (Q24.8)
                • returns:
                • Q24.8
                Cos

                function Cos(x: Real): Real; overload;


                Calculate cosine of angle
                  parameters:
                • X - angle in radians (Q24.8)
                • returns:
                • Q24.8
                Sin

                function Sin(x: single): single; overload;


                Calculate sine of angle
                  parameters:
                • X - angle in radians (Single)
                • returns:
                • Single
                Cos

                function Cos(x: single): single; overload;


                Calculate cosine of angle
                  parameters:
                • X - angle in radians (Single)
                • returns:
                • Single
                Space

                function Space(b: Byte): ^string; assembler;


                Return a string of spaces
                  parameters:
                • b - number of spaces
                • returns:
                • pointer to string
                StringOfChar

                function StringOfChar(c: Char; l: byte): ^string; assembler;


                Return a string consisting of 1 character repeated N times.
                  parameters:
                • c - character
                • l - counter (BYTE)
                • returns:
                • pointer to string
                SetLength

                procedure SetLength(var S: string; Len: byte); register; assembler;


                Set length of a string.
                  parameters:
                • S - string
                • len - new length (BYTE)
                BinStr

                function BinStr(Value: cardinal; Digits: byte): TString; assembler;


                Convert integer to string with binary representation.
                  parameters:
                • Value - Cardinal
                • Digits - Byte
                • returns:
                • string[32]
                OctStr

                function OctStr(Value: cardinal; Digits: byte): TString; assembler;


                Convert integer to a string with octal representation.
                  parameters:
                • Value - Cardinal
                • Digits - Byte
                • returns:
                • string[32]
                Pause

                procedure Pause; assembler; overload;


                Delay program execution (1/50 second).
                  Pause

                  procedure Pause(n: word); assembler; overload;


                  Delay program execution (N * 1/50 second).
                    parameters:
                  • N - number of '1/50 second'
                  ParamCount

                  function ParamCount: byte; assembler;


                  Return number of command-line parameters passed to the program.
                    returns:
                  • byte
                  ParamStr

                  function ParamStr(i: byte): TString; assembler;


                  Return value of a command-line argument.
                    parameters:
                  • i - of a command-line argument
                  • returns:
                  • string[32]
                  Concat

                  function Concat(a,b: string): string; assembler; overload;


                  Append one string to another.
                    parameters:
                  • a - first string
                  • b - second string
                  • returns:
                  • string (a+b)
                  Concat

                  function Concat(a: string; b: char): string; assembler; overload;



                    Concat

                    function Concat(a: char; b: string): string; assembler; overload;



                      Concat

                      function Concat(a,b: char): string; overload;



                        Swap

                        function Swap(a: word): word; overload;


                        Swap high and low bytes of a variable
                          parameters:
                        • a - word
                        • returns:
                        • word
                        Swap

                        function Swap(a: cardinal): cardinal; overload;


                        Swap high and low words of a variable
                          parameters:
                        • a - cardinal
                        • returns:
                        • cardinal