Browse Source

atari: add some more AES/VDI functions

Thorsten Otto 3 years ago
parent
commit
d3c87f9c58

File diff suppressed because it is too large
+ 164 - 677
packages/tosunits/src/aes.pas


+ 782 - 0
packages/tosunits/src/aestypes.inc

@@ -0,0 +1,782 @@
+type
+  PAESContrl = ^TAESContrl;
+  TAESContrl = record
+    opcode: SmallInt;
+    case boolean of
+      true: (
+        nums: array[0..3] of SmallInt; );
+      false: (
+        num_intin: SmallInt;
+        num_intout: SmallInt;
+        num_addrin: SmallInt;
+        num_addrout: SmallInt; );
+  end;
+
+  PAESGlobal = ^TAESGlobal;
+  TAESGlobal = array[0..14] of SmallInt;
+
+  PAESIntIn = ^TAESIntIn;
+  TAESIntIn = array[0..15] of SmallInt;
+
+  PAESIntOut = ^TAESIntOut;
+  TAESIntOut = array[0..9] of SmallInt;
+
+  PAESAddrIn = ^TAESAddrIn;
+  TAESAddrIn = array[0..7] of Pointer;
+
+  PAESAddrOut = ^TAESAddrOut;
+  TAESAddrOut = array[0..1] of Pointer;
+
+type
+  PAESPB = ^TAESPB;
+  TAESPB = record
+    control: PAESContrl;
+    global: PAESGlobal;
+    intin: PAESIntIn;
+    intout: PAESIntOut;
+    addrin: PAESAddrIn;
+    addrout: PAESAddrOut;
+  end;
+
+const
+  AES_TRAP_MAGIC = $C8;
+
+{ object flags }
+const
+    NONE            = 0;
+    SELECTABLE      = 1;
+    DEFAULT         = 2;
+    F_EXIT          = 4;
+    EDITABLE        = 8;
+    RBUTTON         = 16;
+    LASTOB          = 32;
+    TOUCHEXIT       = 64;
+    HIDETREE        = 128;
+    INDIRECT        = 256;
+    FL3DMASK        = $0600;
+    FL3DNONE        = $0000;
+    FL3DIND         = $0200;
+    FL3DBAK         = $0400;
+    FL3DACT         = $0600;
+    SUBMENU         = $0800;         {* falcon aes hierarchical menus *}
+
+{ object state }
+const
+    NORMAL          = $0000;
+    SELECTED        = $0001;
+    CROSSED         = $0002;
+    CHECKED         = $0004;
+    DISABLED        = $0008;
+    OUTLINED        = $0010;
+    SHADOWED        = $0020;
+    WHITEBAK        = $0040;
+    DRAW3D          = $0080;
+
+{ AES object types }
+const
+    G_BOX           = 20;
+    G_TEXT          = 21;
+    G_BOXTEXT       = 22;
+    G_IMAGE         = 23;
+    G_USERDEF       = 24;
+    G_IBOX          = 25;
+    G_BUTTON        = 26;
+    G_BOXCHAR       = 27;
+    G_STRING        = 28;
+    G_FTEXT         = 29;
+    G_FBOXTEXT      = 30;
+    G_ICON          = 31;
+    G_TITLE         = 32;
+    G_CICON         = 33;
+    G_SWBUTTON      = 34;
+    G_POPUP         = 35;
+    G_WINTITLE      = 36;
+    G_EDIT          = 37;
+    G_SHORTCUT      = 38;
+    G_SLIST         = 39;
+    G_EXTBOX        = 40;
+    G_OBLINK        = 41;
+
+
+type
+    PTEDINFO = ^TTEDINFO;
+    TTEDINFO = record
+        te_ptext        : Pchar;
+        te_ptmplt       : Pchar;
+        te_pvalid       : Pchar;
+        te_font         : smallint;
+        te_resvd1       : smallint;
+        te_just         : smallint;
+        te_color        : smallint;
+        te_resvd2       : smallint;
+        te_thickness    : smallint;
+        te_txtlen       : smallint;
+        te_tmplen       : smallint;
+    end;
+
+    PICONBLK = ^TICONBLK;
+    TICONBLK = record
+        ib_pmask        : Pointer;
+        ib_pdata        : Pointer;
+        ib_ptext        : Pchar;
+        ib_char         : smallint;
+        ib_xchar        : smallint;
+        ib_ychar        : smallint;
+        ib_xicon        : smallint;
+        ib_yicon        : smallint;
+        ib_wicon        : smallint;
+        ib_hicon        : smallint;
+        ib_xtext        : smallint;
+        ib_ytext        : smallint;
+        ib_wtext        : smallint;
+        ib_htext        : smallint;
+    end;
+
+    PCICON = ^TCICON;
+    TCICON = record
+        num_planes      : smallint;
+        col_data        : Pointer;
+        col_mask        : Pointer;
+        sel_data        : Pointer;
+        sel_mask        : Pointer;
+        next_res        : PCICON;
+    end;
+
+    PCICONBLK = ^TCICONBLK;
+    TCICONBLK = record
+        monoblk         : TICONBLK;
+        mainlist        : PCICON;
+    end;
+
+    PBITBLK = ^TBITBLK;
+    TBITBLK = record
+        bi_pdata        : Pointer;
+        bi_wb           : smallint;
+        bi_hl           : smallint;
+        bi_x            : smallint;
+        bi_y            : smallint;
+        bi_color        : smallint;
+    end;
+
+    PUSERBLK = ^TUSERBLK;
+    TUSERBLK = record
+        ub_code         : Pointer;
+        ub_parm         : LongInt;
+    end;
+
+    POBSPEC = ^TOBSPEC;
+    TOBSPEC = record
+        case smallint of
+            0,
+            G_BOX,
+            G_IBOX,
+            G_BOXCHAR:  ( index:        LongInt     );
+            G_BOXTEXT,
+            G_TEXT,
+            G_FTEXT,
+            G_FBOXTEXT: ( ted_info:     PTEDINFO    );
+            G_IMAGE:    ( bit_blk:      PBITBLK );
+            G_USERDEF:  ( user_blk:     PUSERBLK    );
+            G_BUTTON,
+            G_STRING,
+            G_TITLE:    ( free_string:  Pchar       );
+            G_ICON:     ( icon_blk:     PICONBLK    );
+            G_CICON:    ( cicon_blk:    PCICONBLK   );
+
+            INDIRECT:   ( ob_spec:      POBSPEC );
+    end;
+
+type
+  PAESOBJECT = ^TAESOBJECT;
+  TAESOBJECT = record
+    ob_next: smallint;   {* The next object               *}
+    ob_head: smallint;   {* First child                   *}
+    ob_tail: smallint;   {* Last child                    *}
+    ob_type: word;       {* Object type                   *}
+    ob_flags: word;      {* Manipulation flags            *}
+    ob_state: word;      {* Object status                 *}
+    ob_spec: TOBSPEC;    {* More under object type        *}
+    ob_x: smallint;      {* X-coordinate of the object    *}
+    ob_y: smallint;      {* Y-coordinate of the object    *}
+    ob_width: smallint;  {* Width of the object           *}
+    ob_height: smallint; {* Height of the object          *}
+  end;
+
+    PAESTree = ^TAESTree;
+    TAESTree = Array[0..2339] of TAESOBJECT;
+
+    PPARMBLK = ^TPARMBLK;
+    TPARMBLK = record
+        pb_tree         : PAESTree;
+        pb_obj          : smallint;
+        pr_prevstate    : smallint; {* maybe bug in PP; should be pb_prevstate *}
+        pr_currstate    : smallint; {* maybe bug in PP; should be pb_currstate *}
+        pb_x            : smallint;
+        pb_y            : smallint;
+        pb_w            : smallint;
+        pb_h            : smallint;
+        pb_xc           : smallint;
+        pb_yc           : smallint;
+        pb_wc           : smallint;
+        pb_hc           : smallint;
+        pb_parm         : LongInt;
+    end;
+
+    PRSHDR = ^TRSHDR;
+    TRSHDR = record
+        rsh_vrsn:       Word;
+        rsh_object:     Word;
+        rsh_tedinfo:    Word;
+        rsh_iconblk:    Word;
+        rsh_bitblk:     Word;
+        rsh_frstr:      Word;
+        rsh_string:     Word;
+        rsh_imdata:     Word;
+        rsh_frimg:      Word;
+        rsh_trindex:    Word;
+        rsh_nobs:       Word;
+        rsh_ntree:      Word;
+        rsh_nted:       Word;
+        rsh_nib:        Word;
+        rsh_nbb:        Word;
+        rsh_nstring:    Word;
+        rsh_nimages:    Word;
+        rsh_rssize:     Word;
+    end;
+
+type
+    PEVENT = ^TEVENT;
+    TEVENT = record
+        ev_mflags:      smallint;        { input parameters }
+        ev_mbclicks:    smallint;
+        ev_bmask:       smallint;
+        ev_mbstate:     smallint;
+        ev_mm1flags:    smallint;
+        ev_mm1x:        smallint;
+        ev_mm1y:        smallint;
+        ev_mm1width:    smallint;
+        ev_mm1height:   smallint;
+        ev_mm2flags:    smallint;
+        ev_mm2x:        smallint;
+        ev_mm2y:        smallint;
+        ev_mm2width:    smallint;
+        ev_mm2height:   smallint;
+        ev_mtlocount:   smallint;
+        ev_mthicount:   smallint;
+        ev_mwich:       smallint;       { output parameters }
+        ev_mmox:        smallint;
+        ev_mmoy:        smallint;
+        ev_mmobutton:   smallint;
+        ev_mmokstate:   smallint;
+        ev_mkreturn:    smallint;
+        ev_mbreturn:    smallint;
+        ev_mmgpbuf:     ARRAY_8;
+    end;
+
+type
+  PGRECT = ^TGRECT;
+  TGRECT = record
+    x: smallint;   {* X-coordinate *}
+    y: smallint;   {* Y-coordinate *}
+    w: smallint;   {* Width        *}
+    h: smallint;   {* Height       *}
+  end;
+
+{ kinds, as used by wind_create() }
+const
+  NAME    = $01;   { Window has a title bar. }
+  CLOSER  = $02;   { Window has a close box. }
+  FULLER  = $04;   { Window has a fuller box. }
+  MOVER   = $08;   { Window may be moved by the user. }
+  INFO    = $10;   { Window has an information line. }
+  SIZER   = $20;   { Window has a sizer box. }
+  UPARROW = $40;   { Window has an up arrow. }
+  DNARROW = $80;   { Window has a down arrow. }
+  VSLIDE  = $100;  { Window has a vertical slider. }
+  LFARROW = $200;  { Window has a left arrow. }
+  RTARROW = $400;  { Window has a right arrow. }
+  HSLIDE  = $800;  { Window has a horizontal slider. }
+  MENUBAR = $1000; { Window has a menu bar (XaAES) }
+  SMALLER = $4000; { Window has an iconifier. }
+  ICONIFIER = SMALLER;
+  BORDER  = $8000; { Window has an sizeing border }
+
+{ messages as used by evnt_mesag() }
+const
+  MN_SELECTED   = 10;
+  WM_REDRAW     = 20;
+  WM_TOPPED     = 21;
+  WM_CLOSED     = 22;
+  WM_FULLED     = 23;
+  WM_ARROWED    = 24;
+  WM_HSLID      = 25;
+  WM_VSLID      = 26;
+  WM_SIZED      = 27;
+  WM_MOVED      = 28;
+  WM_NEWTOP     = 29;
+  WM_UNTOPPED   = 30;
+  WM_ONTOP      = 31;
+  WM_OFFTOP     = 32;
+  WM_BOTTOMED   = 33;
+  WM_ICONIFY    = 34;
+  WM_UNICONIFY  = 35;
+  WM_ALLICONIFY = 36;
+  WM_TOOLBAR    = 37;
+  AC_OPEN       = 40;
+  AC_CLOSE      = 41;
+  CT_UPDATE     = 50;
+  CT_MOVE       = 51;
+  CT_NEWTOP     = 52;
+  AP_TERM       = 50;
+  AP_TFAIL      = 51;
+  AP_RESCHG     = 57;
+  SHUT_COMPLETED = 60;
+  RESCHG_COMPLETED = 61;
+  AP_DRAGDROP   = 63;
+  SH_EXIT       = 68;          {* AES 4.0 *}
+  SH_START      = 69;          {* AES 4.0 *}
+  SH_WDRAW      = 72;          {* AES 4.0 *}
+  SC_CHANGED    = 80;
+  PRN_CHANGED   = 82;          {* NVDI *}
+  FNT_CHANGED   = 83;          {* NVDI *}
+  COLORS_CHANGED = 84;         {* NVDI *}
+  THR_EXIT      = 88;          {* MagiC 4.5 *}
+  PA_EXIT       = 89;          {* MagiC 3 *}
+  CH_EXIT       = 90;
+  WM_WHEEL      = 345;         {* XaAES *}
+  WM_MOUSEWHEEL = 2352;
+  WM_SHADED     = 22360;       {* WiNX *}
+  WM_UNSHADED   = 22361;       {* WinX *}
+
+    WA_UPPAGE       = 0;
+    WA_DNPAGE       = 1;
+    WA_UPLINE       = 2;
+    WA_DNLINE       = 3;
+    WA_LFPAGE       = 4;
+    WA_RTPAGE       = 5;
+    WA_LFLINE       = 6;
+    WA_RTLINE       = 7;
+    WA_WHEEL        = 8;
+
+{* AP_DRAGDROP return codes *}
+const
+    DD_OK        = 0;
+    DD_NAK       = 1;
+    DD_EXT       = 2;
+    DD_LEN       = 3;
+    DD_TRASH     = 4;
+    DD_PRINTER   = 5;
+    DD_CLIPBOARD = 6;
+
+    DD_TIMEOUT  = 4000;     {* Timeout in ms *}
+
+    DD_NUMEXTS  = 8;        {* Number of formats *}
+    DD_EXTLEN   = 4;
+    DD_EXTSIZE  = DD_NUMEXTS * DD_EXTLEN;
+
+    DD_FNAME    = 'U:\\PIPE\\DRAGDROP.AA';
+    DD_NAMEMAX  = 128;      {* Maximum length of a format name *}
+    DD_HDRMIN   = 9;            {* Minimum length of Drag&Drop headers *}
+    DD_HDRMAX   = 8 + DD_NAMEMAX;   {* Maximum length *}
+
+{ message flags as used by evnt_multi() }
+const
+  MU_KEYBD  = $0001; { Keyboard event }
+  MU_BUTTON = $0002; { Button event   }
+  MU_M1     = $0004; { Mouse event 1  }
+  MU_M2     = $0008; { Mouse event 2  }
+  MU_MESAG  = $0010; { Messages       }
+  MU_TIMER  = $0020; { Timer events   }
+  MU_WHEEL         = $0040;      {* AES 4.09 & XaAES *}
+  MU_MX            = $0080;      {* XaAES *}
+  MU_NORM_KEYBD    = $0100;      {*   "   *}
+  MU_DYNAMIC_KEYBD = $0200;      {* keybd as a bunch of buttons, includes release of key *}
+
+{ window update flags as used by wind_update() }
+const
+  END_UPDATE = (0);  { Screen redraw is compete and the flag set by BEG_UPDATE is reset }
+  BEG_UPDATE = (1);  { Screen redraw starts, rectangle lists are frozen, flag is set to prevent any other processes updating the screen }
+  END_MCTRL  = (2);  { Application releases control of the mouse to the AES and resumes mouse click message reactions }
+  BEG_MCTRL  = (3);  { The application wants to have sole control over mouse button messages }
+  BEG_CHECK  = $100;
+
+{ window flags as used by wind_set()/wind_get() }
+const
+  WF_KIND      = (1);
+  WF_NAME      = (2);
+  WF_INFO      = (3);
+  WF_WORKXYWH  = (4);
+  WF_CURRXYWH  = (5);
+  WF_PREVXYWH  = (6);
+  WF_FULLXYWH  = (7);
+  WF_HSLIDE    = (8);
+  WF_VSLIDE    = (9);
+  WF_TOP       = (10);
+  WF_FIRSTXYWH = (11);
+  WF_NEXTXYWH  = (12);
+  WF_NEWDESK   = (14);
+  WF_HSLSIZE   = (15);
+  WF_VSLSIZE   = (16);
+  WF_SCREEN    = (17);
+  WF_COLOR     = 18;
+  WF_TATTRB    = 18;
+  WF_DCOLOR    = 19;
+  WF_SIZTOP    = 19;
+  WF_OWNER     = 20;
+  WF_BEVENT    = 24;
+  WF_BOTTOM    = 25;
+  WF_ICONIFY   = 26;
+  WF_UNICONIFY = 27;
+  WF_UNICONIFYXYWH = 28;
+  WF_TOOLBAR   = (30);
+  WF_FTOOLBAR  = 31;
+  WF_NTOOLBAR  = 32;
+  WF_MENU      = 33;
+  WF_WIDGET    = 34;
+  WF_WHEEL     = 40;
+  WF_OPTS      = 41;
+  WF_TOPMOST   = 232;             {* XaAES, MyAES *}
+  WF_WINX      = $5758;
+  WF_WINXCFG   = $5759;
+  WF_DDELAY    = $575a;
+  WF_SHADE     = $575d;
+  WF_STACK     = $575e;
+  WF_TOPALL    = $575f;
+  WF_BOTTOMALL = $5760;
+  WF_XAAES     = $5841;
+
+{ window calculation types as used by wind_calc() }
+const
+  WC_BORDER = 0;
+  WC_WORK   = 1;
+
+{ WF_DCOLOR objects }
+const
+    W_BOX           = 0;
+    W_TITLE         = 1;
+    W_CLOSER        = 2;
+    W_NAME          = 3;
+    W_FULLER        = 4;
+    W_INFO          = 5;
+    W_DATA          = 6;
+    W_WORK          = 7;
+    W_SIZER         = 8;
+    W_VBAR          = 9;
+    W_UPARROW       = 10;
+    W_DNARROW       = 11;
+    W_VSLIDE        = 12;
+    W_VELEV         = 13;
+    W_HBAR          = 14;
+    W_LFARROW       = 15;
+    W_RTARROW       = 16;
+    W_HSLIDE        = 17;
+    W_HELEV         = 18;
+    W_SMALLER       = 19;
+    W_BOTTOMER      = 20;
+    W_HIDER         = 30;
+
+{* wind_set(WF_BEVENT) *}
+    BEVENT_WORK     = $0001;          {* AES 4.0  *}
+    BEVENT_INFO     = $0002;          {* MagiC 6  *}
+
+{* wind_set(WF_OPTS) bitmask flags *}
+    WO0_WHEEL       = $0001;  {* see mt_wind_set() with #WF_OPTS mode *}
+    WO0_FULLREDRAW  = $0002;  {* see mt_wind_set() with #WF_OPTS mode *}
+    WO0_NOBLITW     = $0004;  {* see mt_wind_set() with #WF_OPTS mode *}
+    WO0_NOBLITH     = $0008;  {* see mt_wind_set() with #WF_OPTS mode *}
+    WO0_SENDREPOS   = $0010;  {* see mt_wind_set() with #WF_OPTS mode *}
+    WO1_NONE        = $0000;  {* see mt_wind_set() with #WF_OPTS mode *}
+    WO2_NONE        = $0000;  {* see mt_wind_set() with #WF_OPTS mode *}
+
+{* wind_set(WF_WHEEL) modes *}
+    WHEEL_MESAG     = 0;   {* AES will send #WM_WHEEL messages *}
+    WHEEL_ARROWED   = 1;   {* AES will send #WM_ARROWED messages *}
+    WHEEL_SLIDER    = 2;   {* AES will convert mouse wheel events to slider events *}
+
+
+{ AES standard object colors }
+const
+  WHITE    = (00);  { White          1000, 1000, 1000 }
+  BLACK    = (01);  { Black             0,    0,    0 }
+  RED      = (02);  { Red            1000,    0,    0 }
+  GREEN    = (03);  { Green             0, 1000,    0 }
+  BLUE     = (04);  { Blue              0,    0, 1000 }
+  CYAN     = (05);  { Cyan              0, 1000, 1000 }
+  YELLOW   = (06);  { Yellow         1000, 1000,    0 }
+  MAGENTA  = (07);  { Magenta        1000,    0, 1000 }
+  DWHITE   = (08);  { Light grey      752,  752,  752 }
+  DBLACK   = (09);  { Dark grey       501,  501,  501 }
+  DRED     = (10);  { Dark red        713,    0,    0 }
+  DGREEN   = (11);  { Dark green        0,  713,    0 }
+  DBLUE    = (12);  { Dark blue         0,    0,  713 }
+  DCYAN    = (13);  { Dark cyan         0,  713,  713 }
+  DYELLOW  = (14);  { Dark yellow     713,  713,    0 }
+  DMAGENTA = (15);  { Dark magenta    713,    0,  713 }
+
+{* editable text justification *}
+const
+    TE_LEFT         = 0;
+    TE_RIGHT        = 1;
+    TE_CNTR         = 2;
+    TE_JUST_MASK    = 3;
+
+{* font types *}
+const
+    GDOS_PROP        = 0; {* Speedo GDOS font *}
+    GDOS_MONO        = 1; {* Speedo GDOS font, force monospace output *}
+    GDOS_BITM        = 2; {* GDOS bit map font *}
+    IBM              = 3;
+    SMALL            = 5;
+    TE_FONT_MASK     = 7;
+
+{* editable text field definitions *}
+const
+    ED_START        = 0;
+    ED_INIT         = 1;
+    ED_CHAR         = 2;
+    ED_END          = 3;
+    ED_CRSR         = 100;            {* MAG!X *}
+    ED_DRAW         = 103;            {* MAG!X 2.00 *}
+    EDSTART         = 0;
+    EDINIT          = 1;
+    EDCHAR          = 2;
+    EDEND           = 3;
+
+{$IFNDEF IP_HOLLOW_defined}
+{* inside patterns *}
+    IP_HOLLOW       = 0;
+    IP_1PATT        = 1;
+    IP_2PATT        = 2;
+    IP_3PATT        = 3;
+    IP_4PATT        = 4;
+    IP_5PATT        = 5;
+    IP_6PATT        = 6;
+    IP_SOLID        = 7;
+{$DEFINE IP_HOLLOW_defined}
+{$ENDIF}
+
+    ROOT            = 0;
+    MAX_DEPTH       = 8;
+
+{ AES mouse cursor number }
+const
+  ARROW          = 0;       { Arrow                               }
+  TEXT_CRSR      = 1;       { Text cursor                         }
+  HOURGLASS      = 2;       { Hourglass, bee                      }
+  BUSY_BEE       = 2;       { See HOURGLASS                       }
+  BUSYBEE        = 2;       { See HOURGLASS                       }
+  POINT_HAND     = 3;       { Pointing hand                       }
+  FLAT_HAND      = 4;       { Flat hand                           }
+  THIN_CROSS     = 5;       { Thin crosshairs                     }
+  THICK_CROSS    = 6;       { Thick crosshairs                    }
+  OUTLN_CROSS    = 7;       { Outlined crosshairs                 }
+  USER_DEF       = 255;     { User-defined mouse form             }
+  M_OFF          = 256;     { Switch off mouse pointer            }
+  M_ON           = 257;     { Switch on mouse pointer             }
+  M_SAVE         = 258;     { Save current mouse form             }
+  M_LAST         = 259;     { Restore most recently saved form    }
+  M_PREVIOUS     = 259;     { See M_LAST                          }
+  M_RESTORE      = 260;     { Restore last shape                  }
+  M_FORCE        = $8000;
+  X_MRESET       = 1000;
+  X_MGET         = 1001;
+  X_MSET_SHAPE   = 1100;
+
+{ Menu definitions as used by menu_bar() }
+const
+  MENU_INQUIRE   = -1;
+  MENU_HIDE      = 0;
+  MENU_SHOW      = 1;
+
+{ Form dialog space actions, as used by form_dial() }
+const
+  FMD_START  = 0; { Reserve screen space for a dialog }
+  FMD_GROW   = 1; { Draw several expanding rectangles from the coordinates fo_dilittlx/y/w/hto fo_dibigx/y/w/h }
+  FMD_SHRINK = 2; { Draw several shrinking rectangles from fo_dibigx/y/w/h to fo_dilittlx/y/w/h }
+  FMD_FINISH = 3; { Release the reserved screen space again }
+
+{ Resource structure types as used by rsrc_gaddr()/rsrc_saddr() }
+const
+  R_TREE      = 0;  { Object tree                          }
+  R_OBJECT    = 1;  { Individual OBJECT (TAESOBJECT)       }
+  R_TEDINFO   = 2;  { TEDINFO structure                    }
+  R_ICONBLK   = 3;  { ICONBLK structure                    }
+  R_BITBLK    = 4;  { BITBLK structure                     }
+  R_STRING    = 5;  { Free string data                     }
+  R_IMAGEDATA = 6;  { Free image data                      }
+  R_OBSPEC    = 7;  { ob_spec field in OBJECT (TAESOBJECT) }
+  R_TEPTEXT   = 8;  { te_ptext in TEDINFO                  }
+  R_TEPTMPLT  = 9;  { te_ptmplt in TEDINFO                 }
+  R_TEPVALID  = 10; { te_pvalid in TEDINFO                 }
+  R_IBPMASK   = 11; { ib_pmask in ICONBLK                  }
+  R_IBPDATA   = 12; { ib_pdata in ICONBLK                  }
+  R_IBPTEXT   = 13; { ib_ptext in ICONBLK                  }
+  R_BIPDATA   = 14; { ib_pdate in BITBLK                   }
+  R_FRSTR     = 15; { ad_frstr free string                 }
+  R_FRIMG     = 16; { ad_frimg free image                  }
+
+{* keyboard states (same as in bios) *}
+    K_RSHIFT        = $0001;
+    K_LSHIFT        = $0002;
+    K_SHIFT         = $0003;
+    K_CTRL          = $0004;
+    K_ALT           = $0008;
+    K_CAPSLOCK      = $0010;
+
+{* appl_read modes *}
+    APR_NOWAIT      = -1;   {* Do not wait for message -- see mt_appl_read() *}
+
+{* appl_search modes *}
+    APP_FIRST = 0;
+    APP_NEXT  = 1;
+    APP_DESK  = 2;
+    X_APS_CHILD0    = $7100; {* Geneva *}
+    X_APS_CHILD     = $7101; {* Geneva *}
+    X_APS_CHEXIT    = -1;    {* Geneva *}
+
+{* application type (appl_search return values) *}
+    APP_SYSTEM          = $001;
+    APP_APPLICATION     = $002;
+    APP_ACCESSORY       = $004;
+    APP_SHELL           = $008;
+    APP_AESSYS          = $010;
+    APP_AESTHREAD       = $020;
+    APP_TASKINFO        = $100; {* XaAES extension for taskbar applications. *}
+    APP_HIDDEN          = $100; {* Task is disabled; XaAES only for APP_TASKINFO *}
+    APP_FOCUS           = $200; {* Active application; XaAES only for APP_TASKINFO *}
+
+{* menu_attach modes *}
+    ME_INQUIRE      = 0;
+    ME_ATTACH       = 1;
+    ME_REMOVE       = 2;
+{* menu_attach attributes *}
+    SCROLL_NO       = 0;
+    SCROLL_YES      = 1;
+
+{* menu_popup modes *}
+    SCROLL_LISTBOX      = -1;
+
+{* the objc_sysvar ob_swhich values *}
+    LK3DIND      = 1;
+    LK3DACT      = 2;
+    INDBUTCOL    = 3;
+    ACTBUTCOL    = 4;
+    BACKGRCOL    = 5;
+    AD3DVAL      = 6;
+    MX_ENABLE3D  = 10;
+    MENUCOL      = 11;
+
+    OB_GETVAR = 0;
+    OB_SETVAR = 1;
+
+{* objc_sysvar modes *}
+    SV_INQUIRE      = 0;
+    SV_SET          = 1;
+
+{* scrp_read return values *}
+    SCRAP_CSV       = $0001;
+    SCRAP_TXT       = $0002;
+    SCRAP_GEM       = $0004;
+    SCRAP_IMG       = $0008;
+    SCRAP_DCA       = $0010;
+    SCRAP_DIF       = $0020;
+    SCRAP_USR       = $8000;
+
+{* shel_write modes for parameter "isover" *}
+    SHW_IMMED        = 0;
+    SHW_CHAIN        = 1;
+    SHW_DOS          = 2;
+    SHW_PARALLEL   = 100;
+    SHW_SINGLE     = 101;
+
+{* shel_write sh_wdoex parameter flags in MSB *}
+    SHD_PSETLIM = (1 shl 8);    { MiNT memory allocation limit }
+    SHD_PRENICE = (1 shl 9);    { MiNT Prenice (priority) level }
+    SHD_DFLTDIR = (1 shl 10);   { Default directory string }
+    SHD_ENVIRON = (1 shl 11);   { Environment string }
+    SHD_UID     = (1 shl 12);   { set user id }
+    SHD_GID     = (1 shl 13);   { set group id }
+
+{* shel_write modes for parameter "doex" *}
+    SWM_LAUNCH       = 0;
+    SWM_LAUNCHNOW    = 1;
+    SWM_LAUNCHACC    = 3;
+    SWM_SHUTDOWN     = 4;
+    SWM_REZCHANGE    = 5;
+    SWM_BROADCAST    = 7;
+    SWM_ENVIRON      = 8;
+    SWM_NEWMSG       = 9;
+    SWM_AESMSG      = 10;
+    SWM_THRCREATE   = 20;
+    SWM_THREXIT     = 21;
+    SWM_THRKILL     = 22;
+
+{* shel_write, parameter wisgr *}
+    TOSAPP              = 0;
+    GEMAPP              = 1;
+
+{* command line parser (shel_write: parameter "wiscr") *}
+    CL_NORMAL       = 0;
+    CL_PARSE        = 1;
+
+{* shutdown action (shel_write: mode SWM_SHUTDOWN, parameter "wiscr") *}
+    SD_ABORT        = 0;
+    SD_PARTIAL      = 1;
+    SD_COMPLETE     = 2;
+
+{* shel_write: mode SWM_ENVIRON, parameter 'wisgr' *}
+    ENVIRON_SIZE    = 0;
+    ENVIRON_CHANGE  = 1;
+    ENVIRON_COPY    = 2;
+
+type
+    PMENU = ^TMENU;
+    TMENU = record
+        mn_tree:        PAESTree;
+        mn_menu:        smallint;
+        mn_item:        smallint;
+        mn_scroll:      smallint;
+        mn_keystate:    smallint;
+    end;
+
+    PMN_SET = ^TMN_SET;
+    TMN_SET = record
+        Display:        LongInt;
+        Drag:           LongInt;
+        Delay:          LongInt;
+        Speed:          LongInt;
+        Height:     smallint;
+    end;
+
+{* extended appl_write structure *}
+    PXAESMSG = ^TXAESMSG;
+    TXAESMSG = record
+        dst_apid: smallint;
+        unique_flg: smallint;
+        attached_mem: Pointer;
+        msgbuf: Psmallint;
+    end;
+
+{* tail for default shell *}
+    PSHELTAIL = ^TSHELTAIL;
+    TSHELTAIL = record
+        dummy: smallint;
+        magic: longint;
+        isfirst: smallint;
+        lasterr: longint;
+        wasgr: smallint;
+    end;
+
+{* shel_write alternative structure for sh_wpcmd parameter *}
+    PSHELW = ^TSHELW;
+    TSHELW = record
+        newcmd: Pchar;
+        psetlimit: longint;
+        prenice: longint;
+        defdir: pchar;
+        env: pointer;
+        case boolean of
+          false: (uid, gid: smallint;);
+          true: (flags: longint;);
+    end;
+

+ 547 - 71
packages/tosunits/src/gem.pas

@@ -17,146 +17,622 @@
     consider using the aes/vdi units instead.
 }
 
+{$MODE FPC}
+{$MODESWITCH OUT+}
+{$PACKRECORDS 2}
+
 unit gem;
 
 interface
 
-uses aes, vdi, sysutils;
+uses aes, vdi, gemcommon;
+
+const
+        LWhite          = DWHITE;
+        LBlack          = DBLACK;
+        LRed            = DRED;
+        LGreen          = DGREEN;
+        LBlue           = DBLUE;
+        LCyan           = DCYAN;
+        LYellow         = DYELLOW;
+        LMagenta        = DMAGENTA;
 
 const
-		LWhite			= DWHITE;
-		LBlack			= DBLACK;
-		LRed			= DRED;
-		LGreen			= DGREEN;
-		LBlue			= DBLUE;
-		LCyan			= DCYAN;
-		LYellow			= DYELLOW;
-		LMagenta		= DMAGENTA;
+        BackSpace       = $0E08;
+        Tab             = $0F09;
+        S_Delete        = $537F;
+        S_Insert        = $5200;
+        Shift_Ins       = $5230;
+        Return          = $1C0D;
+        Enter           = $720D;
+        Undo            = $6100;
+        Help            = $6200;
+        Home            = $4700;
+        Cur_Up          = $4800;
+        Cur_Down        = $5000;
+        Cur_Left        = $4B00;
+        Cur_Right       = $4D00;
+        Shift_Home      = $4737;
+        Shift_CU        = $4838;
+        Shift_CD        = $5032;
+        Shift_CL        = $4B34;
+        Shift_CR        = $4D36;
+        Esc             = $011B;
+        Ctrl_A          = $1E01;
+        Ctrl_B          = $3002;
+        Ctrl_C          = $2E03;
+        Ctrl_D          = $2004;
+        Ctrl_E          = $1205;
+        Ctrl_F          = $2106;
+        Ctrl_G          = $2207;
+        Ctrl_H          = $2308;
+        Ctrl_I          = $1709;
+        Ctrl_J          = $240A;
+        Ctrl_K          = $250B;
+        Ctrl_L          = $260C;
+        Ctrl_M          = $320D;
+        Ctrl_N          = $310E;
+        Ctrl_O          = $180F;
+        Ctrl_P          = $1910;
+        Ctrl_Q          = $1011;
+        Ctrl_R          = $1312;
+        Ctrl_S          = $1F13;
+        Ctrl_T          = $1414;
+        Ctrl_U          = $1615;
+        Ctrl_V          = $2F16;
+        Ctrl_W          = $1117;
+        Ctrl_X          = $2D18;
+        Ctrl_Y          = $2C19;
+        Ctrl_Z          = $151A;
+        Ctrl_1          = $0211;
+        Ctrl_2          = $0300;
+        Ctrl_3          = $0413;
+        Ctrl_4          = $0514;
+        Ctrl_5          = $0615;
+        Ctrl_6          = $071E;
+        Ctrl_7          = $0817;
+        Ctrl_8          = $0918;
+        Ctrl_9          = $0A19;
+        Ctrl_0          = $0B10;
+        Alt_A           = $1E00;
+        Alt_B           = $3000;
+        Alt_C           = $2E00;
+        Alt_D           = $2000;
+        Alt_E           = $1200;
+        Alt_F           = $2100;
+        Alt_G           = $2200;
+        Alt_H           = $2300;
+        Alt_I           = $1700;
+        Alt_J           = $2400;
+        Alt_K           = $2500;
+        Alt_L           = $2600;
+        Alt_M           = $3200;
+        Alt_N           = $3100;
+        Alt_O           = $1800;
+        Alt_P           = $1900;
+        Alt_Q           = $1000;
+        Alt_R           = $1300;
+        Alt_S           = $1F00;
+        Alt_T           = $1400;
+        Alt_U           = $1600;
+        Alt_V           = $2F00;
+        Alt_W           = $1100;
+        Alt_X           = $2D00;
+        Alt_Y           = $2C00;
+        Alt_Z           = $1500;
+        Alt_1           = $7800;
+        Alt_2           = $7900;
+        Alt_3           = $7A00;
+        Alt_4           = $7B00;
+        Alt_5           = $7C00;
+        Alt_6           = $7D00;
+        Alt_7           = $7E00;
+        Alt_8           = $7F00;
+        Alt_9           = $8000;
+        Alt_0           = $8100;
+        F1              = $3B00;
+        F2              = $3C00;
+        F3              = $3D00;
+        F4              = $3E00;
+        F5              = $3F00;
+        F6              = $4000;
+        F7              = $4100;
+        F8              = $4200;
+        F9              = $4300;
+        F10             = $4400;
+        Shift_F1        = $5400;
+        Shift_F2        = $5500;
+        Shift_F3        = $5600;
+        Shift_F4        = $5700;
+        Shift_F5        = $5800;
+        Shift_F6        = $5900;
+        Shift_F7        = $5A00;
+        Shift_F8        = $5B00;
+        Shift_F9        = $5C00;
+        Shift_F10       = $5D00;
+
+        Ctrl_AE         = $2804;
+        Ctrl_OE         = $2714;
+        Ctrl_UE         = $1A01;
+        Alt_AE          = $285D;
+        Alt_OE          = $275B;
+        Alt_UE          = $1A40;
+        SH_Alt_AE       = $287D;
+        SH_Alt_OE       = $277B;
+        SH_Alt_UE       = $1A5C;
+
+
 
 type
-	AESPB = TAESPB;
-	AESPBPtr = ^AESPB;
-	AESOBJECT = TAESOBJECT;
-	VDIPB = TVDIPB;
-	VDIPBPtr = ^VDIPB;
-	TEDINFO = TTEDINFO;
-	TEDINFOPtr = ^TEDINFO;
-	ICONBLK = TICONBLK;
-	ICONBLKPtr = ^ICONBLK;
-	CICON = TCICON;
-	CICONPtr = ^CICON;
-	CICONBLK = TCICONBLK;
-	CICONBLKPtr = ^CICONBLK;
-	BITBLK = TBITBLK;
-	BITBLKPtr = ^BITBLK;
-	MFORM = TMFORM;
-	MFORMPtr = ^MFORM;
-	USERBLK = TUSERBLK;
-	USERBLKPtr = ^USERBLK;
-	OBSPEC = TOBSPEC;
-	OBSPECPtr = ^OBSPEC;
-	PARMBLK = TPARMBLK;
-	PARMBLKPtr = ^PARMBLK;
-	AESTree = TAESTree;
-	AESTreePtr = ^AESTree;
-	RSHDR = TRSHDR;
-	RSHDRPtr = ^RSHDR;
-	EVENT = TEVENT;
-	EVENTPtr = ^EVENT;
-	MENU = TMENU;
-	MENUPtr = ^MENU;
-	MN_SET = TMN_SET;
-	MN_SETPtr = ^MN_SET;
-	FONT_HDR = TFONT_HDR;
-	FONT_HDRPtr = ^FONT_HDR;
-	MFDB = TMFDB;
-	MFDBPtr = ^MFDB;
+    AESPB = TAESPB;
+    AESPBPtr = ^AESPB;
+    AESOBJECT = TAESOBJECT;
+    AESOBJECTPtr = ^TAESOBJECT;
+    VDIPB = TVDIPB;
+    VDIPBPtr = ^VDIPB;
+    TEDINFO = TTEDINFO;
+    TEDINFOPtr = ^TEDINFO;
+    ICONBLK = TICONBLK;
+    ICONBLKPtr = ^ICONBLK;
+    CICON = TCICON;
+    CICONPtr = ^CICON;
+    CICONBLK = TCICONBLK;
+    CICONBLKPtr = ^CICONBLK;
+    BITBLK = TBITBLK;
+    BITBLKPtr = ^BITBLK;
+    MFORM = TMFORM;
+    MFORMPtr = ^MFORM;
+    USERBLK = TUSERBLK;
+    USERBLKPtr = ^USERBLK;
+    OBSPEC = TOBSPEC;
+    OBSPECPtr = ^OBSPEC;
+    PARMBLK = TPARMBLK;
+    PARMBLKPtr = ^PARMBLK;
+    AESTree = TAESTree;
+    AESTreePtr = ^AESTree;
+    RSHDR = TRSHDR;
+    RSHDRPtr = ^RSHDR;
+    EVENT = TEVENT;
+    EVENTPtr = ^EVENT;
+    MENU = TMENU;
+    MENUPtr = ^MENU;
+    MN_SET = TMN_SET;
+    MN_SETPtr = ^MN_SET;
+    FONT_HDR = TFONT_HDR;
+    FONT_HDRPtr = ^FONT_HDR;
+    MFDB = vdi.TMFDB;
+    MFDBPtr = ^MFDB;
+
+    global_ARRAY    = TAESGlobal;
+
+    workout_ARRAY   = ARRAY[0..56] of smallint;
+    workin_ARRAY    = ARRAY[0..10] of smallint;
+    intin_ARRAY     = TVDIIntIn;
+    intout_ARRAY    = TVDIIntOut;
+    ptsin_ARRAY     = TVDIPtsIn;
+    ptsout_ARRAY    = TVDIPtsOut;
+
+(*
+ * PurePascal has all the AES parameter arrays exposed.
+ * We don't want to do that, because various arrays are
+ * implementation specific. For Compatibility we
+ * need to make the global array available however;
+ *)
+type
+        AES_block = record
+            global  : TAESGlobal;
+        end;
+
+var Gem_pb: AES_block; external name 'aes_global';
+
+(*
+ * we also need to make the parameter block available,
+ * so applications can define missing functions
+ * that are not yet implemented here.
+ *)
+
+var
+    AES_pb: TAESPB; external name 'aespb';
+    VDI_pb: TVDIPB; external name 'vdipb';
+
+{*
+ * overloaded AES functions that take an AESTreePtr as parameter
+ *}
+function menu_bar(me_btree: AESTreePtr; me_bshow: smallint): smallint; overload;
+function menu_icheck(me_ctree: AESTreePtr; me_citem, me_ccheck: smallint): smallint; overload;
+function menu_ienable(me_etree: AESTreePtr; me_eitem, me_eenable: smallint): smallint; overload;
+function menu_tnormal(me_ntree: AESTreePtr; me_ntitle, me_nnormal: smallint): smallint; overload;
+function menu_text(me_ttree: AESTreePtr; me_titem: smallint; me_ttext: String): smallint; overload;
+function menu_attach(me_flag: smallint; me_tree: AESTreePtr; me_item: smallint; me_mdata: PMENU): smallint; overload;
+function menu_istart(me_flag: smallint; me_tree: AESTreePtr; me_imenu, me_item: smallint): smallint; overload;
+
+function objc_add(ob_atree: AESTreePtr;	ob_aparent, ob_achild: smallint): smallint; overload;
+function objc_delete(ob_dltree: AESTreePtr; ob_dlobject: smallint): smallint; overload;
+function objc_draw(ob_drtree: AESTreePtr;
+	ob_drstartob, ob_drdepth,
+	ob_drxclip, ob_dryclip,
+	ob_drwclip, ob_drhclip: smallint): smallint; overload;
+function objc_find(ob_ftree: AESTreePtr;
+	ob_fstartob, ob_fdepth,
+	ob_fmx, ob_fmy: smallint): smallint; overload;
+function objc_offset(ob_oftree: AESTreePtr;
+	ob_ofobject: smallint;
+	out ob_ofxoff, ob_ofyoff: smallint): smallint; overload;
+function objc_order(ob_ortree: AESTreePtr;
+	ob_orobject, ob_ornewpos: smallint): smallint; overload;
+function objc_edit(ob_edtree: AESTreePtr;
+	ob_edobject, ob_edchar: smallint;
+	var ob_edidx: smallint;
+	ob_edkind: smallint): smallint; overload;
+function objc_change(ob_ctree: AESTreePtr;
+	ob_cobject, ob_cresvd,
+	ob_xclip, ob_yclip,
+	ob_wclip, ob_hclip,
+	ob_cnewstate,
+	ob_credraw: smallint): smallint; overload;
 
+function form_do(fo_dotree: AESTreePtr;	fo_dostartob: smallint): smallint; overload;
+function form_center(fo_ctree: AESTreePtr; out fo_cx, fo_cy, fo_cw, fo_ch: smallint): smallint; overload;
+function form_keybd(fo_ktree: AESTreePtr;
+	fo_kobject, fo_kobnext, fo_kchar: smallint;
+	out fo_knxtobject, fo_knxtchar: smallint): smallint; overload;
+function form_button(fo_btree: AESTreePtr; fo_bobject, fo_bclicks: smallint;
+	out fo_bnxtobj: smallint): smallint; overload;
+
+function rsrc_obfix(re_obtree: AESTreePtr; re_oobject: smallint): smallint; overload;
+
+{*
+ * overloaded VDI functions
+ *}
+procedure v_opnwk(const WorkIn: workin_Array; out handle: smallint; out WorkOut: workout_Array); overload;
+procedure v_opnvwk(const WorkIn: workin_Array; var handle: smallint; out WorkOut: workout_Array); overload;
+procedure vq_extnd(handle, owflag: smallint; out WorkOut: workout_Array); overload;
+procedure vro_cpyfm(handle, vr_mode: smallint; const pxyarray: ARRAY_8; const psrcMFDB, pdesMFDB: TMFDB); overload;
+procedure vrt_cpyfm(handle, vr_mode: smallint; const pxyarray: ARRAY_8; const psrcMFDB, pdesMFDB: TMFDB; const color_index: ARRAY_2); overload;
+procedure vqt_extent(handle: smallint; const calcString: String; out extent: ARRAY_8); overload;
+procedure vqt_f_extent(handle: smallint; const str: String; out extent: ARRAY_8);
+
+{*
+ * Utility functions
+ *}
 procedure SetFreeString(tree: PAESTree; obj: smallint; const str: String);
-procedure GetFreeString(tree: PAESTree; obj: smallint; var str: String);
+procedure GetFreeString(tree: PAESTree; obj: smallint; out str: String);
 procedure SetPtext(tree: PAESTree; obj: smallint; const str: String);
-procedure GetPtext(tree: PAESTree; obj: smallint; var str: String);
+procedure GetPtext(tree: PAESTree; obj: smallint; out str: String);
 procedure SetPtmplt(tree: PAESTree; obj: smallint; const str: String);
-procedure GetPtmplt(tree: PAESTree; obj: smallint; var str : String);
+procedure GetPtmplt(tree: PAESTree; obj: smallint; out str :String);
 procedure SetPvalid(tree: PAESTree; obj: smallint; const str: String);
-procedure GetPvalid(tree: PAESTree; obj: smallint; var str: String);
+procedure GetPvalid(tree: PAESTree; obj: smallint; out str: String);
 procedure SetIcontext(tree: PAESTree; obj: smallint; const str: String);
-procedure GetIcontext(tree: PAESTree; obj: smallint; var str: String);
+procedure GetIcontext(tree: PAESTree; obj: smallint; out str: String);
 procedure WindSetTitle(handle: smallint; const str: String; var buf: String);
 procedure WindSetInfo(handle: smallint; const str: String; var buf: String);
 procedure WindSetNewDesk(tree: PAESTree; firstObj: smallint);
 
 implementation
 
+type
+  aesstr = array[0..255] of char;
+
+
+function string_to_vdi(const src: String; dst: psmallint): smallint;
+var
+  i, len: longint;
+begin
+  len:=length(src);
+  for i:=0 to len-1 do
+    dst[i]:=byte(src[i + 1]);
+
+  string_to_vdi:=len;
+end;
+
+
+procedure v_opnwk(const WorkIn: workin_Array; out handle: smallint; out WorkOut: workout_Array);
+var pb: TVDIPB;
+begin
+  vdi.v_opnwk(@workin[0], @handle, @workout[0]);
+end;
+
+
+procedure v_opnvwk(const WorkIn: workin_Array; var handle: smallint; out WorkOut: workout_Array);
+var pb: TVDIPB;
+begin
+  vdi.v_opnvwk(@workin[0], @handle, @workout[0]);
+end;
+
+
+procedure vq_extnd(handle, owflag: smallint; out WorkOut: workout_Array);
+var pb: TVDIPB;
+begin
+  vdi.vq_extnd(handle, owflag, @workout[0]);
+end;
+
+procedure vro_cpyfm(handle, vr_mode: smallint; const pxyarray: ARRAY_8; const psrcMFDB, pdesMFDB: TMFDB);
+begin
+  vdi.vro_cpyfm(handle, vr_mode, @pxyarray, @psrcMFDB, @pdesMFDB);
+end;
+
+procedure vrt_cpyfm(handle, vr_mode: smallint; const pxyarray: ARRAY_8; const psrcMFDB, pdesMFDB: TMFDB; const color_index: ARRAY_2);
+begin
+  vdi.vrt_cpyfm(handle, vr_mode, @pxyarray, @psrcMFDB, @pdesMFDB, @color_index);
+end;
+
+
+procedure vqt_extent(handle: smallint; const calcString: String; out extent: ARRAY_8);
+var len: smallint;
+begin
+  len:=string_to_vdi(calcstring, @vdi_pb.intin^[0]);
+  vdi_pb.control^[0]:=116;
+  vdi_pb.control^[1]:=0;
+  vdi_pb.control^[3]:=len;
+  vdi_pb.control^[5]:=0;
+  vdi_pb.control^[6]:=handle;
+
+  vdi.vdi;
+
+  extent[0]:=vdi_pb.ptsout^[0];
+  extent[1]:=vdi_pb.ptsout^[1];
+  extent[2]:=vdi_pb.ptsout^[2];
+  extent[3]:=vdi_pb.ptsout^[3];
+  extent[4]:=vdi_pb.ptsout^[4];
+  extent[5]:=vdi_pb.ptsout^[5];
+  extent[6]:=vdi_pb.ptsout^[6];
+  extent[7]:=vdi_pb.ptsout^[7];
+end;
+
+procedure vqt_f_extent(handle: smallint; const str: String;
+                       out extent: ARRAY_8);
+var len: longint;
+begin
+  len:=string_to_vdi(str, @vdi_pb.intin^[0]);
+  vdi_pb.control^[0]:=240;
+  vdi_pb.control^[1]:=0;
+  vdi_pb.control^[3]:=len;
+  vdi_pb.control^[5]:=0;
+  vdi_pb.control^[6]:=handle;
+
+  vdi.vdi;
+
+  extent[0]:=vdi_pb.ptsout^[0];
+  extent[1]:=vdi_pb.ptsout^[1];
+  extent[2]:=vdi_pb.ptsout^[2];
+  extent[3]:=vdi_pb.ptsout^[3];
+  extent[4]:=vdi_pb.ptsout^[4];
+  extent[5]:=vdi_pb.ptsout^[5];
+  extent[6]:=vdi_pb.ptsout^[6];
+  extent[7]:=vdi_pb.ptsout^[7];
+end;
+
+
+function menu_bar(me_btree: AESTreePtr; me_bshow: smallint): smallint;
+begin
+	menu_bar := aes.menu_bar(@me_btree[0], me_bshow);
+end;
+
+function menu_icheck(me_ctree: AESTreePtr; me_citem, me_ccheck: smallint): smallint;
+begin
+	menu_icheck := aes.menu_icheck(@me_ctree[0], me_citem, me_ccheck);
+end;
+
+function menu_ienable(me_etree: AESTreePtr; me_eitem, me_eenable: smallint): smallint;
+begin
+	menu_ienable := aes.menu_ienable(@me_etree[0], me_eitem, me_eenable);
+end;
+
+function menu_tnormal(me_ntree: AESTreePtr; me_ntitle, me_nnormal: smallint): smallint;
+begin
+	menu_tnormal := aes.menu_ienable(@me_ntree[0], me_ntitle, me_nnormal);
+end;
+
+function menu_text(me_ttree: AESTreePtr; me_titem: smallint; me_ttext: String): smallint;
+var s: aesstr;
+begin
+  menu_text:=aes.menu_text(@me_ttree[0], me_titem, @s);
+end;
+
+function menu_attach(me_flag: smallint; me_tree: AESTreePtr; me_item: smallint; me_mdata: PMENU): smallint;
+begin
+  menu_attach:=aes.menu_attach(me_flag, @me_tree[0], me_item, me_mdata);
+end;
+
+function menu_istart(me_flag: smallint; me_tree: AESTreePtr; me_imenu, me_item: smallint): smallint; overload;
+begin
+  menu_istart:=aes.menu_istart(me_flag, @me_tree[0], me_item, me_item);
+end;
+
+
+function objc_add(ob_atree: AESTreePtr;	ob_aparent, ob_achild: smallint): smallint;
+begin
+  objc_add:=aes.objc_add(@ob_atree[0], ob_aparent, ob_achild);
+end;
+
+function objc_delete(ob_dltree: AESTreePtr; ob_dlobject: smallint): smallint;
+begin
+  objc_delete:=aes.objc_delete(@ob_dltree[0], ob_dlobject);
+end;
+
+function objc_draw(ob_drtree: AESTreePtr;
+	ob_drstartob, ob_drdepth,
+	ob_drxclip, ob_dryclip,
+	ob_drwclip, ob_drhclip: smallint): smallint;
+begin
+  objc_draw:=aes.objc_draw(@ob_drtree[0], ob_drstartob, ob_drdepth, ob_drxclip, ob_dryclip, ob_drwclip, ob_drhclip);
+end;
+
+function objc_find(ob_ftree: AESTreePtr;
+	ob_fstartob, ob_fdepth,
+	ob_fmx, ob_fmy: smallint): smallint;
+begin
+  objc_find:=aes.objc_find(@ob_ftree[0], ob_fstartob, ob_fdepth, ob_fmx, ob_fmx);
+end;
+
+function objc_offset(ob_oftree: AESTreePtr;
+	ob_ofobject: smallint;
+	out ob_ofxoff, ob_ofyoff: smallint): smallint;
+begin
+  objc_offset:=aes.objc_offset(@ob_oftree[0], ob_ofobject, ob_ofxoff, ob_ofyoff);
+end;
+
+function objc_order(ob_ortree: AESTreePtr;
+	ob_orobject, ob_ornewpos: smallint): smallint;
+begin
+  objc_order:=aes.objc_order(@ob_ortree[0], ob_orobject, ob_ornewpos);
+end;
+
+function objc_edit(ob_edtree: AESTreePtr;
+	ob_edobject, ob_edchar: smallint;
+	var ob_edidx: smallint;
+	ob_edkind: smallint): smallint;
+begin
+  objc_edit:=aes.objc_edit(@ob_edtree[0], ob_edobject, ob_edchar, ob_edidx, ob_edkind);
+end;
+
+function objc_change(ob_ctree: AESTreePtr;
+	ob_cobject, ob_cresvd,
+	ob_xclip, ob_yclip,
+	ob_wclip, ob_hclip,
+	ob_cnewstate,
+	ob_credraw: smallint): smallint;
+begin
+  objc_change:=aes.objc_change(@ob_ctree[0], ob_cobject, ob_cresvd, ob_xclip, ob_yclip, ob_wclip, ob_hclip, ob_cnewstate, ob_credraw);
+end;
+
+function form_do(fo_dotree: AESTreePtr;	fo_dostartob: smallint): smallint;
+begin
+  form_do:=aes.form_do(@fo_dotree[0], fo_dostartob);
+end;
+
+function form_center(fo_ctree: AESTreePtr; out fo_cx, fo_cy, fo_cw, fo_ch: smallint): smallint;
+begin
+  form_center:=aes.form_center(@fo_ctree[0], fo_cx, fo_cy, fo_cw, fo_ch);
+end;
+
+function form_keybd(fo_ktree: AESTreePtr;
+	fo_kobject, fo_kobnext, fo_kchar: smallint;
+	out fo_knxtobject, fo_knxtchar: smallint): smallint;
+begin
+  form_keybd:=aes.form_keybd(@fo_ktree[0], fo_kobject, fo_kobnext, fo_kchar, fo_knxtobject, fo_knxtchar);
+end;
+
+function form_button(fo_btree: AESTreePtr; fo_bobject, fo_bclicks: smallint;
+	out fo_bnxtobj: smallint): smallint;
+begin
+  form_button:=aes.form_button(@fo_btree[0], fo_bobject, fo_bclicks, fo_bnxtobj);
+end;
+
+function rsrc_obfix(re_obtree: AESTreePtr; re_oobject: smallint): smallint;
+begin
+  rsrc_obfix:=aes.rsrc_obfix(@re_obtree[0], re_oobject);
+end;
+
+
 procedure SetFreeString(tree: PAESTree; obj: smallint; const str: String);
+var len: SizeInt;
+    p: pchar;
 begin
-  StrPCopy(tree^[obj].ob_spec.free_string, str);
+  len:=length(str);
+  p:=tree^[obj].ob_spec.free_string;
+  move(str[1], p^, len);
+  p[len]:=#0;
 end;
 
-procedure GetFreeString(tree: PAESTree; obj: smallint; var str: String);
+procedure GetFreeString(tree: PAESTree; obj: smallint; out str: String);
 begin
-  str := StrPas(tree^[obj].ob_spec.free_string);
+  str := tree^[obj].ob_spec.free_string;
 end;
 
 procedure SetPtext(tree: PAESTree; obj: smallint; const str: String);
+var len: SizeInt;
+    p: pchar;
 begin
-  StrPCopy(tree^[obj].ob_spec.ted_info^.te_ptext, str);
+  len:=length(str);
+  p:=tree^[obj].ob_spec.ted_info^.te_ptext;
+  if (len >= tree^[obj].ob_spec.ted_info^.te_txtlen) then
+    len := tree^[obj].ob_spec.ted_info^.te_txtlen-1;
+  move(str[1], p^, len);
+  p[len]:=#0;
 end;
 
-procedure GetPtext(tree: PAESTree; obj: smallint; var str: String);
+procedure GetPtext(tree: PAESTree; obj: smallint; out str: String);
 begin
-  str := StrPas(tree^[obj].ob_spec.ted_info^.te_ptext);
+  str := tree^[obj].ob_spec.ted_info^.te_ptext;
 end;
 
 procedure SetPtmplt(tree: PAESTree; obj: smallint; const str: String);
+var len: SizeInt;
+    p: pchar;
 begin
-  StrPCopy(tree^[obj].ob_spec.ted_info^.te_ptmplt, str);
+  len:=length(str);
+  p:=tree^[obj].ob_spec.ted_info^.te_ptmplt;
+  if (len >= tree^[obj].ob_spec.ted_info^.te_tmplen) then
+    len := tree^[obj].ob_spec.ted_info^.te_tmplen-1;
+  move(str[1], p^, len);
+  p[len]:=#0;
 end;
 
-procedure GetPtmplt(tree: PAESTree; obj: smallint; var str : String);
+procedure GetPtmplt(tree: PAESTree; obj: smallint; out str: String);
 begin
-  str := StrPas(tree^[obj].ob_spec.ted_info^.te_ptmplt);
+  str := tree^[obj].ob_spec.ted_info^.te_ptmplt;
 end;
 
 procedure SetPvalid(tree: PAESTree; obj: smallint; const str: String);
+var len: SizeInt;
+    p: pchar;
 begin
-  StrPCopy(tree^[obj].ob_spec.ted_info^.te_pvalid, str);
+  len:=length(str);
+  p:=tree^[obj].ob_spec.ted_info^.te_pvalid;
+  move(str[1], p^, len);
+  p[len]:=#0;
 end;
 
-procedure GetPvalid(tree: PAESTree; obj: smallint; var str: String);
+procedure GetPvalid(tree: PAESTree; obj: smallint; out str: String);
 begin
-  str := StrPas(tree^[obj].ob_spec.ted_info^.te_pvalid);
+  str := tree^[obj].ob_spec.ted_info^.te_pvalid;
 end;
 
 procedure SetIcontext(tree: PAESTree; obj: smallint; const str: String);
+var len: SizeInt;
+    p: pchar;
 begin
-  StrPCopy(tree^[obj].ob_spec.icon_blk^.ib_ptext, str);
+  len:=length(str);
+  p:=tree^[obj].ob_spec.icon_blk^.ib_ptext;
+  move(str[1], p^, len);
+  p[len]:=#0;
 end;
 
-procedure GetIcontext(tree: PAESTree; obj: smallint; var str: String);
+procedure GetIcontext(tree: PAESTree; obj: smallint; out str: String);
 begin
-  str := StrPas(tree^[obj].ob_spec.icon_blk^.ib_ptext);
+  str := tree^[obj].ob_spec.icon_blk^.ib_ptext;
 end;
 
 procedure WindSetTitle(handle: smallint; const str: String; var buf: String);
-var pstr: Pchar;
+var len: SizeInt;
+    pstr: Pchar;
 begin
   pstr := @buf[0];
-  StrPCopy(pstr, str);
+  len:=length(str);
+  move(str[1], pstr^, len);
+  pstr[len]:=#0;
   wind_set(handle, WF_NAME, Pointer(pstr));
 end;
 
 procedure WindSetInfo(handle: smallint; const str: String; var buf: String);
-var pstr: Pchar;
+var len: SizeInt;
+    pstr: Pchar;
 begin
   pstr := @buf[0];
-  StrPCopy(pstr, str);
+  len:=length(str);
+  move(str[1], pstr^, len);
+  pstr[len]:=#0;
   wind_set(handle, WF_INFO, Pointer(pstr));
 end;
 
 procedure WindSetNewDesk(tree: PAESTree; firstObj: smallint);
 begin
-  wind_set(0, WF_NEWDESK, dword(tree) shr 16, word(tree), firstObj, 0);
+{$PUSH}
+{$WARN 4055 OFF} { Conversion between ordinals and pointers is not portable }
+  wind_set(0, WF_NEWDESK, hi(ptruint(tree)), lo(ptruint(tree)), firstObj, 0);
+{$POP}
 end;
 
 end.

+ 46 - 0
packages/tosunits/src/gemcommon.pas

@@ -0,0 +1,46 @@
+{
+    Copyright (c) 2022 by Free Pascal development team
+
+    GEM interface unit for Atari TOS
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+{
+    Shared types between aes/vdi/gem.
+    Only type declarations should go here.
+}
+
+{$MODE FPC}
+{$MODESWITCH OUT+}
+{$PACKRECORDS 2}
+
+unit gemcommon;
+
+interface
+
+type
+    ARRAY_8     = ARRAY[0..7] of smallint;
+
+{ AES/VDI mouse form structure }
+type
+  PMFORM = ^TMFORM;
+  TMFORM = record
+    mf_xhot: smallint;       {* X-position hot-spot *}
+    mf_yhot: smallint;       {* Y-position hot-spot *}
+    mf_nplanes: smallint;    {* Number of planes    *}
+    mf_fg: smallint;         {* Mask colour         *}
+    mf_bg: smallint;         {* Pointer colour      *}
+    mf_mask: array[0..15] of smallint;   {* Mask form           *}
+    mf_data: array[0..15] of smallint;   {* Pointer form        *}
+  end;
+
+implementation
+
+end.

+ 3051 - 372
packages/tosunits/src/vdi.pas

@@ -12,291 +12,383 @@
 
  **********************************************************************}
 
+{$MODE FPC}
+{$MODESWITCH OUT+}
 {$PACKRECORDS 2}
+
 unit vdi;
 
 interface
 
+uses gemcommon;
+
 { The API description of this file is based on the information available
   online at: https://freemint.github.io/tos.hyp/en/index.html }
 
-const
-	GDOS_NONE		= -2;			(* no GDOS installed           *)
-	GDOS_FSM		= $5F46534D;	(* '_FSM' - FSMGDOS installed  *)
-	GDOS_FNT		= $5F464E54;	(* '_FNT' - FONTGDOS installed *)
-
-const
-{* vst_alignment modes *}
-	TA_LEFT			= 0;
-	TA_CENTER		= 1;
-	TA_RIGHT		= 2;
-	TA_BASELINE		= 0;
-	TA_HALF			= 1;
-	TA_ASCENT		= 2;
-	TA_BOTTOM		= 3;
-	TA_DESCENT		= 4;
-	TA_TOP			= 5;
-
-{* gsx modes *}
-	MD_REPLACE		= 1;
-	MD_TRANS		= 2;
-	MD_XOR			= 3;
-	MD_ERASE		= 4;
-
-{* gsx styles *}
-	FIS_HOLLOW		= 0;
-	FIS_SOLID		= 1;
-	FIS_PATTERN		= 2;
-	FIS_HATCH		= 3;
-	FIS_USER		= 4;
-
-{* polymarker types *}
-	MT_DOT			= 1;
-	MT_PLUS			= 2;
-	MT_ASTERISK		= 3;
-	MT_SQUARE		= 4;
-	MT_DCROSS		= 5;
-	MT_DIAMOND		= 6;
-
-{* linetypes *}
-	LT_SOLID		= 1;
-	LT_LONGDASH		= 2;
-	LT_DOTTED		= 3;
-	LT_DASHDOT		= 4;
-	LT_DASHED		= 5;
-	LT_DASHDOTDOT	= 6;
-	LT_USERDEF		= 7;
-
-{* line ends *}
-	LE_SQUARED		= 0;
-	LE_ARROWED		= 1;
-	LE_ROUNDED		= 2;
-
-{* text effects *}
-	TF_NORMAL		= 0;
-	TF_THICKENED	= 1;
-	TF_LIGHTENED	= 2;
-	TF_SLANTED		= 4;
-	TF_UNDERLINED	= 8;
-	TF_OUTLINED		= 16;
-	TF_SHADOWED		= 32;
-
-{* bit blt rules *}
-	ALL_WHITE		= 0;
-	S_AND_D			= 1;
-	S_AND_NOTD		= 2;
-	S_ONLY			= 3;
-	NOTS_AND_D		= 4;
-	D_ONLY			= 5;
-	S_XOR_D			= 6;
-	S_OR_D			= 7;
-	NOT_SORD		= 8;
-	NOT_SXORD		= 9;
-	D_INVERT		= 10;
-	S_OR_NOTD		= 11;
-	NOT_D			= 12;
-	NOTS_OR_D		= 13;
-	NOT_SANDD		= 14;
-	ALL_BLACK		= 15;
-
-{* input mode *}
-	MODE_REQUEST	= 1;
-	MODE_SAMPLE		= 2;
-
-{* vqin_mode & vsin_mode modes *}
-	DEV_LOCATOR		= 1;
-	DEV_VALUATOR	= 2;
-	DEV_CHOICE		= 3;
-	DEV_STRING		= 4;
-
-type
-  PCOLOR_RGB = ^TCOLOR_RGB;
-  TCOLOR_RGB = record
-      reserved: word;     {* Set to 0 or the index of the entry *}
-      red: word;          {* Red:   0<->65535 *}
-      green: word;        {* Green: 0<->65535 *}
-      blue: word;         {* Blue:  0<->65535 *}
-  end;
-
-{$WARNING type TCOLOR_ENTRY is incomplete}
-type
-  TCOLOR_ENTRY = record
-    case byte of
-      0: ( rgb: TCOLOR_RGB; );
-      1: ( cymk: array[0..1] of longint; ); // dummy
-  end;
-
-type
-  PCOLOR_TAB = ^TCOLOR_TAB;
-  TCOLOR_TAB = record             {* Colour table                    *}
-      magic: array[0..3] of char; {* 'ctab'                          *}
-      length: longint;
-      format: longint;            {* Format (0)                      *}
-      reserved: longint;          {* Reserved, set to 0              *}
-      map_id: longint;            {* Colour table ID                 *}
-      color_space: longint;       {* Colour space (at present only
-                                     CSPACE_RGB)                     *}
-      flags: longint;             {* VDI-internal flags, set to 0    *}
-      no_colors: longint;         {* Number of colour entries        *}
-      reserved1: longint;         {* Reserved, must be 0             *}
-      reserved2: longint;         {* Reserved, must be 0             *}
-      reserved3: longint;         {* Reserved, must be 0             *}
-      reserved4: longint;         {* Reserved, must be 0             *}
-      colors: array[0..0] of TCOLOR_ENTRY; { repeated no_colors times }
-  end;
-
-type
-  PPOINT16 = ^TPOINT16;
-  TPOINT16 = record               {* Point for 16-bit coordinates *}
-      x: smallint;
-      y: smallint;
-  end;
-
-type
-  PPOINT32 = ^TPOINT32;
-  TPOINT32 = record               {* Point for 32-bit coordinates *}
-      x: longint;
-      y: longint;
-  end;
-
-type
-  PRECT16 = ^TRECT16;
-  TRECT16 = record                {* Rectangle for 16-bit coordinates *}
-      x1: smallint;
-      y1: smallint;
-      x2: smallint;
-      y2: smallint;
-  end;
-
-type
-  PRECT32 = ^TRECT32;
-  TRECT32 = record                {* Rectangle for 32-bit coordinates *}
-      x1: longint;
-      y1: longint;
-      x2: longint;
-      y2: longint;
-  end;
-
-type
-  PMFDB = ^TMFDB;
-  TMFDB = record
-      fd_addr: pointer;          {* Pointer to the start of the
-                                    memory block, e.g. the
-                                    screen memory base address  *}
-      fd_w: smallint;            {* Width in pixels             *}
-      fd_h: smallint;            {* Height in pixels            *}
-      fd_wdwidth: smallint;      {* Width of a line in words    *}
-      fd_stand: smallint;        {* 0 = Device-specific format  *}
-                                 {* 1 = Standard format         *}
-      fd_nplanes: smallint;      {* Number of planes            *}
-      fd_r1: smallint;           {* Reserved, must be 0         *}
-      fd_r2: smallint;           {* Reserved, must be 0         *}
-      fd_r3: smallint;           {* Reserved, must be 0         *}
-  end;
-
-type
-	String33	= String[33];
-	String80	= String[80];
-	String125	= String[125];
-
-type
-  PVDIContrl = ^TVDIContrl;
-  TVDIContrl = array[0..11] of smallint;
-
-  PVDIPtsIn  = ^TVDIPtsIn;
-  TVDIPtsIn  = array[0..1023] of smallint;
-
-  PVDIPtsOut = ^TVDIPtsOut;
-  TVDIPtsOut = array[0..255] of smallint;
-
-  PVDIIntIn  = ^TVDIIntIn;
-  TVDIIntIn  = array[0..1023] of smallint;
-
-  PVDIIntOut = ^TVDIIntOut;
-  TVDIIntOut = array[0..511] of smallint;
+{$I vditypes.inc}
 
 type
-  PVDIPB = ^TVDIPB;
-  TVDIPB = record
-      contrl: PVDIContrl;        {* Pointer to contrl array *}
-      intin: PVDIIntIn;          {* Pointer to intin array  *}
-      ptsin: PVDIPtsIn;          {* Pointer to ptsin array  *}
-      intout: PVDIIntOut;        {* Pointer to intout array *}
-      ptsout: PVDIPtsOut;        {* Pointer to ptsout array *}
-  end;
-
-	PFONT_HDR = ^TFONT_HDR;
-	TFONT_HDR = record
-		font_id			: smallint;
-		point			: smallint;
-		name			: Array[0..31] of Char;
-		first_ade		: Word;
-		last_ade		: Word;
-		top				: Word;
-		ascent			: Word;
-		half			: Word;
-		descent			: Word;
-		bottom			: Word;
-		max_char_width	: Word;
-		max_cell_width	: Word;
-		left_offset		: Word;
-		right_offset	: Word;
-		thicken			: Word;
-		ul_size			: Word;
-		lighten			: Word;
-		skew			: Word;
-		flags			: Word;
-		hor_table		: Pointer;
-		off_table		: Pointer;
-		dat_table		: Pointer;
-		form_width		: Word;
-		form_height		: Word;
-		next_font		: PFONT_HDR;
-	end;
-
-const
-  VDI_TRAP_MAGIC = $73;
+   ARRAY_8 = gemcommon.ARRAY_8;
+   PMFORM = gemcommon.PMFORM;
+   TMFORM = gemcommon.TMFORM;
 
 procedure vdi;
+procedure vdi(pb: PVDIPB);
+
+function vq_gdos: smallint;
+function vq_vgdos: LongInt;
 
 procedure vdi_str_to_pchar(src: psmallint; des: pchar; len: smallint);
 function pchar_str_to_vdi(src: pchar; des: psmallint): longint;
 
 procedure v_opnwk(work_in: psmallint; handle: psmallint; work_out: psmallint);
 procedure v_clswk(handle: smallint);
+procedure v_clrwk(handle: smallint);
+procedure v_updwk(handle: smallint);
+
+procedure vq_chcells(handle: smallint; out rows, columns: smallint);
+procedure v_exit_cur(handle: smallint);
+procedure v_enter_cur(handle: smallint);
+procedure v_curup(handle: smallint);
+procedure v_curdown(handle: smallint);
+procedure v_curright(handle: smallint);
+procedure v_curleft(handle: smallint);
+procedure v_curhome(handle: smallint);
+procedure v_eeos(handle: smallint);
+procedure v_eeol(handle: smallint);
+procedure v_curaddress(handle, row, column: smallint);
+procedure v_curtext(handle: smallint; const outString: String);
+procedure v_rvon(handle: smallint);
+procedure v_rvoff(handle: smallint);
+procedure vq_curaddress(handle: smallint; out row, column: smallint);
+function vq_tabstatus(handle: smallint): smallint;
+procedure v_hardcopy(handle: smallint);
+procedure v_dspcur(handle, x, y: smallint);
+procedure v_rmcur(handle: smallint);
+procedure v_form_adv(handle: smallint);
+procedure v_output_window(handle: smallint; xyarray: ARRAY_4);
+procedure v_clear_disp_list(handle: smallint);
+procedure v_bit_image(handle: smallint; const filename: string;
+                aspect, x_scale, y_scale, h_align, v_align: smallint;
+                const xyarray: ARRAY_4);
+procedure vq_scan(handle: smallint; out g_slice, g_page, a_slice, a_page, div_fac: smallint);
+procedure v_alpha_text(handle: smallint; const outString: String);
+function v_orient(handle, orientation: smallint): smallint;
+function v_copies(handle, count: smallint): smallint;
+procedure v_tray(handle, tray: smallint);
+function v_page_size(handle, page_id: smallint): smallint;
+function vs_palette(handle, palette: smallint): smallint;
+procedure v_sound(handle, frequency, duration: smallint);
+function vs_mute(handle, action: smallint): smallint;
+procedure vt_resolution(handle, xres, yres: smallint;
+                        out xset, yset: smallint);
+procedure vt_axis(handle, xres, yres: smallint;
+                  out xset, yset: smallint);
+procedure vt_origin(handle, xorigin, yorigin: smallint);
+procedure vq_tdimensions(handle: smallint; out xdimension, ydimension: smallint);
+procedure vt_alignment(handle, dx, dy: smallint);
+procedure vsp_film(handle, index, lightness: smallint);
+function vqp_filmname(handle, index: smallint; out name: String): smallint;
+procedure vsc_expose(handle, state: smallint);
+procedure v_meta_extents(handle, min_x, min_y, max_x, max_y: smallint);
+procedure v_write_meta(handle, num_intin: smallint; a_intin: Pointer;
+                       num_ptsin: smallint;a_ptsin: Pointer);
+procedure vm_pagesize(handle, pgwidth, pgheight: smallint);
+procedure vm_coords(handle, llx, lly, urx, ury: smallint);
+function v_bez_qual(handle, prcnt: smallint; out actual: smallint): smallint;
+procedure vm_filename(handle: smallint; const filename: String);
+procedure v_offset(handle, offset: smallint);
+procedure v_fontinit(handle: smallint; var fh: TFONT_HDR);
+procedure v_escape2000(handle, times: smallint);
 
 procedure v_pline(handle: smallint; count: smallint; pxyarray: psmallint);
-
-procedure v_gtext(handle: smallint; x: smallint; y: smallint; _string: pchar);
+procedure v_pline(handle, count: smallint; const pxyarray: Array of smallint);
+procedure v_bez(handle, count: smallint; xyarr, bezarr: Pointer;
+                out extent: ARRAY_4;
+                out totpts, totmoves: smallint);
+procedure v_bez_fill(handle, count: smallint;
+                    xyarr, bezarr: Pointer;
+                    out extent: ARRAY_4;
+                    out totpts, totmoves: smallint);
+
+procedure v_pmarker(handle, count: smallint; const pxyarray: Array of smallint);
+procedure v_gtext(handle: smallint; x: smallint; y: smallint; outputstring: pchar);
+procedure v_gtext(handle, x, y: smallint; const outputstring: string);
+procedure v_fillarea(handle, count: smallint; const pxyarray: Array of smallint);
 
 procedure v_bar(handle: smallint; pxyarray: psmallint);
-procedure v_circle (handle: smallint; x: smallint; y: smallint; radius: smallint);
+procedure v_bar(handle: smallint; const pxyarray: ARRAY_4);
+procedure v_arc(handle, x, y, radius, begang, endang: smallint);
+procedure v_pieslice(handle, x, y, radius, begang, endang: smallint);
+procedure v_circle(handle: smallint; x: smallint; y: smallint; radius: smallint);
+procedure v_ellipse(handle, x, y, xradius, yradius: smallint);
+procedure v_ellarc(handle, x, y, xradius, yradius, begang, endang: smallint);
+procedure v_ellpie(handle, x, y, xradius, yradius, begang, endang: smallint);
+procedure v_rbox(handle: smallint; const xyarray: ARRAY_4);
+procedure v_rfbox(handle: smallint; const xyarray: ARRAY_4);
+procedure v_justified(handle, x, y: smallint;
+        const outputstring: string;
+        width, wordspace, charspace: smallint);
+function v_bez_on(handle: smallint): smallint;
+procedure v_bez_off(handle: smallint);
+
+procedure vst_height(handle, height: smallint; out char_width, char_height, cell_width, cell_height: smallint);
+function vst_rotation(handle, angle: smallint): smallint;
 
 procedure vs_color(handle: smallint; index: smallint; rgb_in: psmallint);
+procedure vs_color(handle, index: smallint; const rgb_in: ARRAY_3);
 
+function vsl_type(handle, style: smallint): smallint;
+function vsl_width(handle, width: smallint): smallint;
 function vsl_color(handle: smallint; color_index: smallint): smallint;
+function vsm_type(handle, symbol: smallint): smallint;
+function vsm_height(handle, height: smallint): smallint;
+function vsm_color(handle, color_index: smallint): smallint;
+function vst_font(handle, font: smallint): smallint;
+function vsf_interior(handle, style: smallint): smallint;
+function vsf_style(handle, style_index: smallint): smallint;
+function vq_color(handle, color_index, set_flag: smallint; out rgb: ARRAY_3): smallint;
+procedure vrq_locator(handle, x, y: smallint; out xout, yout, term: smallint);
+function vsm_locator(handle, x, y: smallint; out xout, yout, term: smallint): smallint;
+procedure vrq_valuator(handle, valuator_in: smallint; out valuator_out, terminator: smallint);
+procedure vsm_valuator(handle, val_in: smallint; out val_out, term, status: smallint);
+procedure vrq_choice(handle, ch_in: smallint; out ch_out: smallint);
+function vsm_choice(handle: smallint; out choice: smallint): smallint;
+procedure vrq_string(handle, max_length, echo_mode: smallint; const echo_xy: ARRAY_2; out resString: string);
+function vsm_string(handle, max_length, echo_mode: smallint; const echo_xy: ARRAY_2; out resString: string): smallint;
+
 function vst_color(handle: smallint; color_index: smallint): smallint;
 function vsf_color(handle: smallint; color_index: smallint): smallint;
 
 function vswr_mode(handle: smallint; mode: smallint): smallint;
-
-procedure v_opnvwk(work_in: psmallint; handle: psmallint; work_out: psmallint);
-procedure v_clsvwk(handle: smallint);
+function vsin_mode(handle, dev_type, mode: smallint): smallint;
+procedure vql_attributes(handle: smallint; out attrib: ARRAY_4);
+procedure vql_attributes(handle: smallint; out attrib: ARRAY_6);
+procedure vqm_attributes(handle: smallint; out attrib: ARRAY_4);
+procedure vqf_attributes(handle: smallint; out attrib: ARRAY_5);
+procedure vqt_attributes(handle: smallint; out attrib: ARRAY_10);
+procedure vst_alignment(handle, hor_in, vert_in: smallint; out hor_out, vert_out: smallint);
+
+procedure v_opnvwk(work_in: psmallint; handle: psmallint; work_out: psmallint); overload;
+procedure v_clsvwk(handle: smallint); overload;
+procedure vq_extnd(handle, owflag: smallint; WorkOut: psmallint); overload;
+procedure vq_scrninfo(handle: smallint; out WorkOut: ARRAY_273);
+procedure v_contourfill(handle, x, y, index: smallint);
+function vsf_perimeter(handle, per_vis: smallint): smallint;
 
 procedure v_get_pixel(handle: smallint; x: smallint; y: smallint;
                       pel: psmallint; index: psmallint);
+procedure v_get_pixel(handle, x, y: smallint; out pel, index: smallint);
+function vst_effects(handle, effect: smallint): smallint;
+function vst_point(handle, point: smallint; out char_width, char_height, cell_width, cell_height: smallint): smallint;
+procedure vsl_ends(handle, beg_style, end_style: smallint);
 
-procedure vro_cpyfm(handle: smallint; vr_mode: smallint; pxyarray: psmallint; psrcMFDB: PMFDB; pdesMFDB: PMFDB);
+procedure vro_cpyfm(handle: smallint; vr_mode: smallint; pxyarray: psmallint; psrcMFDB: PMFDB; pdesMFDB: PMFDB); overload;
+procedure vr_trnfm(handle: smallint; psrcMFDB, pdesMFDB: PMFDB);
+procedure vr_trnfm(handle: smallint; const psrcMFDB, pdesMFDB: TMFDB);
+procedure vsc_form(handle: smallint; pcur_form: PMFORM);
+procedure vsf_udpat(handle: smallint; pfill_pat: Pointer; planes: smallint);
+procedure vsl_udsty(handle, pattern: smallint);
+procedure vr_recfl(handle: smallint; const pxyarray: ARRAY_4);
+procedure vqin_mode(handle, dev_type: smallint; out input_mode: smallint);
+procedure vqt_extent(handle: smallint; calcString: pchar; extent: psmallint); overload;
+function vqt_width(handle, character: smallint; out cell_width, left_delta, right_delta: smallint): smallint;
 
-procedure vrt_cpyfm(handle: smallint; vr_mode: smallint; pxyarray: psmallint; psrcMFDB: PMFDB; pdesMFDB: PMFDB; color_index: psmallint);
+procedure vex_timv(handle: smallint; tim_addr: Pointer; out otim_addr: Pointer; out tim_conv: smallint);
+
+function vst_load_fonts(handle, select: smallint): smallint;
+procedure vst_unload_fonts(handle, select: smallint);
+
+procedure vrt_cpyfm(handle: smallint; vr_mode: smallint; pxyarray: psmallint; psrcMFDB: PMFDB; pdesMFDB: PMFDB; color_index: psmallint); overload;
 
 procedure v_show_c(handle: smallint; reset: smallint);
 procedure v_hide_c(handle: smallint);
+procedure vq_mouse(handle: smallint; out pstatus, x, y: smallint);
+procedure vex_butv(handle: smallint; pusrcode: Pointer; out psavcode: Pointer);
+procedure vex_motv(handle: smallint; pusrcode: Pointer; out psavcode: Pointer);
+procedure vex_curv(handle: smallint; pusrcode: Pointer; out psavcode: Pointer);
+procedure vex_wheelv(handle: smallint; pusrcode: Pointer; out psavcode: Pointer);
+procedure vq_key_s(handle: smallint; out pstatus: smallint);
 
 procedure vs_clip(handle: smallint; clip_flag: smallint; pxyarray: psmallint);
+procedure vs_clip(handle, clip_flag: smallint; const pxyarray: ARRAY_4);
+procedure vs_clip_off(handle: smallint);
+
+function vqt_name(handle, element_num: smallint; out name: String33): smallint;
+procedure vqt_fontinfo(handle: smallint;
+        out minADE, maxADE: smallint;
+        out distances: ARRAY_5;
+        out maxwidth: smallint;
+        out effects: ARRAY_3);
+
+procedure vqt_justified(handle, x, y: smallint; const outString: String;
+            length, word_space, char_space: smallint;
+            offsets: Pointer);
+
+procedure vst_width(handle, width: smallint; out char_width, char_height, cell_width, cell_height: smallint);
+procedure vqt_fontheader(handle: smallint; buffer: Pointer;
+                         out pathname: String);
+procedure vqt_trackkern(handle: smallint; out x, y: fix31);
+procedure vqt_pairkern(handle, ch1, ch2: smallint; out x, y: fix31);
+procedure vst_charmap(handle, mode: smallint);
+function vst_map_mode(handle, mode: smallint): smallint;
+procedure vst_kern(handle, tmode, pmode: smallint; out tracks, pairs: smallint);
+procedure vst_track_offset(handle: smallint; offset: fix31; pairmode: smallint; out tracks, pairs: smallint);
+procedure v_getbitmap_info(handle, ch: smallint;
+                           out advx, advy, xoff, yoff: fix31;
+                           out width, height: smallint;
+                           out bitmap: pointer);
+
+procedure v_ftext(handle, x, y: smallint; const str: String);
+procedure v_ftext_offset(handle, x, y: smallint;
+                         const outputstring: string;
+                         const offset: Array of smallint);
+procedure v_killoutline(handle: smallint; component: Pointer);
+procedure v_getoutline(handle, ch: smallint;
+                       const xyarray: Array of smallint;
+                       const bezarray: Array of ShortInt;
+                       maxverts: smallint;
+                       out numverts: smallint);
+procedure vst_scratch(handle, mode: smallint);
+procedure vst_error(handle, mode: smallint; out errorvar: smallint);
+function vst_arbpt(handle, point: smallint;
+                   out chwd, chht, cellwd, cellht: smallint): smallint;
+function vst_arbpt32(handle: smallint; point: fix31;
+                     out chwd, chht, cellwd, cellht: smallint): fix31;
+procedure vqt_advance(handle, ch: smallint; out advx, advy, remx, remy: smallint);
+procedure vqt_advance32(handle, ch: smallint; out advx, advy: fix31);
+function vq_devinfo(handle, devnum: smallint;
+                      out devexists: smallint;
+                      out filename: String;
+                      out devicename: String): smallint;
+procedure vqt_devinfo(handle, devnum: smallint;
+                      out dev_busy: smallint;
+                      out filename: String;
+                      out devicename: String);
+
+function v_savecache(handle: smallint; const filename: String): smallint;
+function v_loadcache(handle: smallint; const filename: String; mode: smallint): smallint;
+function v_flushcache(handle: smallint): smallint;
+function vst_setsize(handle, point: smallint;
+                     out chwd, chht, cellwd, cellht: smallint): smallint;
+function  vst_setsize32(handle: smallint; point: fix31;
+                        out chwd, chht, cellwd, cellht: smallint): fix31;
+function vst_skew(handle, skew: smallint): smallint;
+procedure vqt_get_table(handle: smallint; out map: Pointer);
+procedure vqt_cachesize(handle, which_cache: smallint; out size: LongInt);
+
+procedure v_set_app_buff(handle: smallint; address: Pointer; nparagraphs: smallint);
+
+
+(*
+ * NOT YET IMPLEMENTED:
+fix31_to_point(a) ((_WORD)((((a) + 32768L) >> 16)))
+point_to_fix31(a) (((fix31)(a)) << 16)
+
+v_trays
+
+v_ps_halftone
+vq_calibrate
+vq_page_name
+vq_tray_names
+vs_calibrate
+v_etext
+
+v_setrgbi
+v_xbit_image
+v_topbot
+vs_bkcolor
+v_pat_rotate
+vs_grayoverride
+
+v_opnbm
+v_clsbm
+
+v_get_driver_info
+vqt_real_extent
+
+vq_margins
+vq_driver_info
+vq_bit_image
+vs_page_info
+vs_crop
+vq_image_type
+vs_save_disp_list
+vs_load_disp_list
+
+vqt_xfntinfo
+vq_ext_devinfo
+vqt_ext_name
+vqt_name_and_id
+vst_name
+
+vqt_char_index
+
+vqt_is_char_available
+
+v_color2nearest
+v_color2value
+v_create_ctab
+v_create_itab
+v_ctab_idx2value
+v_ctab_idx2vdi
+v_ctab_vdi2idx
+v_delete_ctab
+v_delete_itab
+v_get_ctab_id
+v_get_outline
+v_open_bm
+v_resize_bm
+v_setrgb
+v_value2color
+vq_ctab
+vq_ctab_entry
+vq_ctab_id
+vq_dflt_ctab
+vq_hilite_color
+vq_margins
+vq_max_color
+vq_min_color
+vq_prn_scaling
+vq_px_format
+vq_weight_color
+vqf_bg_color
+vqf_fg_color
+vql_bg_color
+vql_fg_color
+vqm_bg_color
+vqm_fg_color
+vqr_bg_color
+vqr_fg_color
+vqt_bg_color
+vqt_fg_color
+vr_transfer_bits
+vs_ctab
+vs_ctab_entry
+vs_dflt_ctab
+vs_document_info
+vs_hilite_color
+vs_max_color
+vs_min_color
+vs_weight_color
+vsf_bg_color
+vsf_fg_color
+vsl_bg_color
+vsl_fg_color
+vsm_bg_color
+vsm_fg_color
+vsr_bg_color
+vsr_fg_color
+vst_bg_color
+vst_fg_color
+*)
+
 
 implementation
 
+const
+  VDI_TRAP_MAGIC = $73;
+
 var
   _contrl: TVDIContrl;
   _intin: TVDIIntIn;
@@ -306,19 +398,69 @@ var
 
 const
   pblock: TVDIPB = (
-    contrl: @_contrl;
+    control: @_contrl;
     intin: @_intin;
     ptsin: @_ptsin;
     intout: @_intout;
     ptsout: @_ptsout;
-  );
+  ); public name 'vdipb';
+
+function string_to_vdi(const src: String; dst: psmallint): smallint;
+var
+  i, len: longint;
+begin
+  len:=length(src);
+  for i:=0 to len-1 do
+    dst[i]:=byte(src[i + 1]);
+
+  string_to_vdi:=len;
+end;
+
+procedure vdi_to_string(src: psmallint; out dst: String; len: longint);
+var
+  i: longint;
+begin
+  for i:=0 to len-1 do
+    dst[i + 1]:=chr(src[i]);
+  setlength(dst, len);
+end;
 
-procedure vdi; assembler;
+procedure vdi; assembler; nostackframe;
 asm
+  pea.l       (a2)
   lea.l pblock, a0
   move.l a0, d1
   move.w #VDI_TRAP_MAGIC, d0
   trap #2
+  movea.l     (a7)+,a2
+end;
+
+procedure vdi(pb: PVDIPB); assembler; nostackframe;
+asm
+  pea.l       (a2)
+  move.l pb,a0
+  move.l a0,d1
+  move.w #VDI_TRAP_MAGIC,d0
+  trap #2
+  movea.l     (a7)+,a2
+end;
+
+function vq_gdos: smallint; assembler; nostackframe;
+asm
+  pea.l       (a2)
+  moveq.l     #-2,d0
+  trap        #2
+  addq.w      #2,d0
+  ext.l       d0
+  movea.l     (a7)+,a2
+end;
+
+function vq_vgdos: LongInt; assembler; assembler; nostackframe;
+asm
+  pea.l       (a2)
+  moveq.l     #-2,d0
+  trap        #2
+  movea.l     (a7)+,a2
 end;
 
 procedure vdi_str_to_pchar(src: psmallint; des: pchar; len: smallint);
@@ -339,7 +481,7 @@ var
 begin
   len:=0;
   repeat
-    des[len]:=ord(src[len]);
+    des[len]:=byte(src[len]);
     inc(len);
   until (src[len-1] = #0);
 
@@ -347,22 +489,26 @@ begin
 end;
 
 procedure v_opnwk(work_in: psmallint; handle: psmallint; work_out: psmallint);
+var pb: TVDIPB;
 begin
+  pb.control := @_contrl;
   // _intin[0..15] = work_in[0..15];
-  move(work_in^,_intin,16*sizeof(smallint));
+  pb.intin := PVDIIntIn(work_in);
+  pb.ptsin := @_ptsin;
+  // work_out[0..44] = intout[0..44];
+  pb.intout := PVDIIntOut(work_out);
+  // work_out[45..56] = ptsout[0..11];
+  pb.ptsout := PVDIPtsOut(@work_out[45]);
 
   _contrl[0]:=1;
   _contrl[1]:=0;
   _contrl[3]:=16;
+  _contrl[5]:=0;
   _contrl[6]:=0;
 
-  vdi;
+  vdi(@pb);
 
   handle^:=_contrl[6];
-  // work_out[0..44] = intout[0..44];
-  // work_out[45..56] = ptsout[0..11];
-  move(_intout,work_out[0],45*sizeof(smallint));
-  move(_ptsout,work_out[45],12*sizeof(smallint));
 end;
 
 procedure v_clswk(handle: smallint);
@@ -370,70 +516,74 @@ begin
   _contrl[0]:=2;
   _contrl[1]:=0;
   _contrl[3]:=0;
+  _contrl[5]:=0;
   _contrl[6]:=handle;
 
   vdi;
 end;
 
-procedure v_pline(handle: smallint; count: smallint; pxyarray: psmallint);
+procedure v_clrwk(handle: smallint);
 begin
-  // _ptsin[0..2*count-1] = pxyarray[0..2*count-1];
-  move(pxyarray^,_ptsin,count*2*sizeof(smallint));
-
-  _contrl[0]:=6;
-  _contrl[1]:=count;
+  _contrl[0]:=3;
+  _contrl[1]:=0;
   _contrl[3]:=0;
   _contrl[6]:=handle;
 
   vdi;
 end;
 
-procedure v_gtext(handle: smallint; x: smallint; y: smallint; _string: pchar);
-var
-  i: smallint;
+procedure v_updwk(handle: smallint);
 begin
-  _ptsin[0]:=x;
-  _ptsin[1]:=y;
+  _contrl[0]:=4;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
 
-  i:=0;
-  repeat
-    _intin[i]:=byte(_string[i]);
-    inc(i);
-  until (_string[i-1] = #0);
-  dec(i);
+  vdi;
+end;
 
-  _contrl[0]:=8;
-  _contrl[1]:=1;
-  _contrl[3]:=-i;
+
+procedure vq_chcells(handle: smallint; out rows, columns: smallint);
+begin
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=1;
   _contrl[6]:=handle;
 
   vdi;
+
+  rows:=_intout[0];
+  columns:=_intout[1];
 end;
 
-procedure v_bar(handle: smallint; pxyarray: psmallint);
+procedure v_exit_cur(handle: smallint);
 begin
-  // _ptsin[0..3] = pxyarray[0..3];
-  move(pxyarray^,_ptsin,4*sizeof(smallint));
-  _contrl[0]:=11;
-  _contrl[1]:=2;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
   _contrl[3]:=0;
-  _contrl[5]:=1;
+  _contrl[5]:=2;
   _contrl[6]:=handle;
 
   vdi;
 end;
 
-procedure v_circle (handle: smallint; x: smallint; y: smallint; radius: smallint);
+procedure v_enter_cur(handle: smallint);
 begin
-  _ptsin[0]:=x;
-  _ptsin[1]:=y;
-  _ptsin[2]:=0;
-  _ptsin[3]:=0;
-  _ptsin[4]:=radius;
-  _ptsin[5]:=0;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=3;
+  _contrl[6]:=handle;
 
-  _contrl[0]:=11;
-  _contrl[1]:=3;
+  vdi;
+end;
+
+procedure v_curup(handle: smallint);
+begin
+  _contrl[0]:=5;
+  _contrl[1]:=0;
   _contrl[3]:=0;
   _contrl[5]:=4;
   _contrl[6]:=handle;
@@ -441,192 +591,2721 @@ begin
   vdi;
 end;
 
-procedure vs_color(handle: smallint; index: smallint; rgb_in: psmallint);
+procedure v_curdown(handle: smallint);
 begin
-  _intin[0]:=index;
-  _intin[1]:=rgb_in[0];
-  _intin[2]:=rgb_in[1];
-  _intin[3]:=rgb_in[2];
-
-  _contrl[0]:=14;
+  _contrl[0]:=5;
   _contrl[1]:=0;
-  _contrl[3]:=4;
+  _contrl[3]:=0;
+  _contrl[5]:=5;
   _contrl[6]:=handle;
 
   vdi;
 end;
 
-function vsl_color(handle: smallint; color_index: smallint): smallint;
+procedure v_curright(handle: smallint);
 begin
-  _intin[0]:=color_index;
-
-  _contrl[0]:=17;
+  _contrl[0]:=5;
   _contrl[1]:=0;
-  _contrl[3]:=1;
+  _contrl[3]:=0;
+  _contrl[5]:=6;
   _contrl[6]:=handle;
 
   vdi;
+end;
 
-  vsl_color:=_intout[0];
+procedure v_curleft(handle: smallint);
+begin
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=7;
+  _contrl[6]:=handle;
+
+  vdi;
 end;
 
-function vst_color(handle: smallint; color_index: smallint): smallint;
+procedure v_curhome(handle: smallint);
 begin
-  _intin[0]:=color_index;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=8;
+  _contrl[6]:=handle;
 
-  _contrl[0]:=22;
+  vdi;
+end;
+
+procedure v_eeos(handle: smallint);
+begin
+  _contrl[0]:=5;
   _contrl[1]:=0;
-  _contrl[3]:=1;
+  _contrl[3]:=0;
+  _contrl[5]:=9;
   _contrl[6]:=handle;
 
   vdi;
+end;
 
-  vst_color:=_intout[0];
+procedure v_eeol(handle: smallint);
+begin
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=10;
+  _contrl[6]:=handle;
+
+  vdi;
 end;
 
-function vsf_color(handle: smallint; color_index: smallint): smallint;
+procedure v_curaddress(handle, row, column: smallint);
 begin
-  _intin[0]:=color_index;
+  _intin[0]:=row;
+  _intin[1]:=column;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=11;
+  _contrl[6]:=handle;
 
-  _contrl[0]:=25;
+  vdi;
+end;
+
+procedure v_curtext(handle: smallint; const outString: String);
+var len: longint;
+begin
+  len:=string_to_vdi(outString, @_intin[0]);
+  _contrl[0]:=5;
   _contrl[1]:=0;
-  _contrl[3]:=1;
+  _contrl[3]:=len;
+  _contrl[5]:=12;
   _contrl[6]:=handle;
 
   vdi;
+end;
 
-  vsf_color:=_intout[0];
+procedure v_rvon(handle: smallint);
+begin
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=13;
+  _contrl[6]:=handle;
+
+  vdi;
 end;
 
-function vswr_mode(handle: smallint; mode: smallint): smallint;
+procedure v_rvoff(handle: smallint);
 begin
-  _intin[0]:=mode;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=14;
+  _contrl[6]:=handle;
 
-  _contrl[0]:=32;
+  vdi;
+end;
+
+procedure vq_curaddress(handle: smallint; out row, column: smallint);
+begin
+  _contrl[0]:=5;
   _contrl[1]:=0;
-  _contrl[3]:=1;
+  _contrl[3]:=0;
+  _contrl[5]:=15;
   _contrl[6]:=handle;
 
   vdi;
 
-  vswr_mode:=_intout[0];
+  row:=_intout[0];
+  column:=_intout[1];
 end;
 
-procedure v_opnvwk(work_in: psmallint; handle: psmallint; work_out: psmallint);
+function vq_tabstatus(handle: smallint): smallint;
 begin
-  // _intin[0..10] = work_in[0..10];
-  move(work_in^,_intin,11*sizeof(smallint));
-
-  _contrl[0]:=100;
+  _contrl[0]:=5;
   _contrl[1]:=0;
-  _contrl[3]:=11;
-  _contrl[6]:=handle^;
+  _contrl[3]:=0;
+  _contrl[5]:=16;
+  _contrl[6]:=handle;
 
   vdi;
 
-  handle^:=_contrl[6];
-  // work_out[0..44] = intout[0..44];
-  // work_out[45..56] = ptsout[0..11];
-  move(_intout,work_out[0],45*sizeof(smallint));
-  move(_ptsout,work_out[45],12*sizeof(smallint));
+  vq_tabstatus:=_intout[0];
 end;
 
-procedure v_clsvwk(handle: smallint);
+procedure v_hardcopy(handle: smallint);
 begin
-  _contrl[0]:=101;
+  _contrl[0]:=5;
   _contrl[1]:=0;
   _contrl[3]:=0;
+  _contrl[5]:=17;
   _contrl[6]:=handle;
 
   vdi;
 end;
 
-procedure v_get_pixel(handle: smallint; x: smallint; y: smallint;
-                      pel: psmallint; index: psmallint);
+procedure v_dspcur(handle, x, y: smallint);
 begin
-  _ptsin[0]:=x;
   _ptsin[0]:=x;
   _ptsin[1]:=y;
-  _contrl[0]:=105;
+  _contrl[0]:=5;
   _contrl[1]:=1;
   _contrl[3]:=0;
+  _contrl[5]:=18;
   _contrl[6]:=handle;
 
   vdi;
-
-  pel^:=_intout[0];
-  index^:=_intout[1];
 end;
 
-procedure vro_cpyfm(handle: smallint; vr_mode: smallint; pxyarray: psmallint; psrcMFDB: PMFDB; pdesMFDB: PMFDB);
+procedure v_rmcur(handle: smallint);
 begin
-  _intin[0]:=vr_mode;
-  // ptsin[0..7] = pxyarray[0..7];
-  move(pxyarray[0],_ptsin[0],8*sizeof(smallint));
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=19;
+  _contrl[6]:=handle;
 
-  PPointer(@_contrl[7])^:=psrcMFDB;
-  PPointer(@_contrl[9])^:=pdesMFDB;
+  vdi;
+end;
 
-  _contrl[0]:=109;
-  _contrl[1]:=4;
-  _contrl[3]:=1;
+procedure v_form_adv(handle: smallint);
+begin
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=20;
   _contrl[6]:=handle;
 
   vdi;
 end;
 
-procedure vrt_cpyfm(handle: smallint; vr_mode: smallint; pxyarray: psmallint; psrcMFDB: PMFDB; pdesMFDB: PMFDB; color_index: psmallint);
+procedure v_output_window(handle: smallint; xyarray: ARRAY_4);
 begin
-  _intin[0]:=vr_mode;
-  _intin[1]:=color_index[0];
-  _intin[2]:=color_index[1];
-  // ptsin[0..7] = pxyarray[0..7];
-  move(pxyarray[0],_ptsin[0],8*sizeof(smallint));
+  _ptsin[0]:=xyarray[0];
+  _ptsin[1]:=xyarray[1];
+  _ptsin[2]:=xyarray[2];
+  _ptsin[3]:=xyarray[3];
+  _contrl[0]:=5;
+  _contrl[1]:=2;
+  _contrl[3]:=0;
+  _contrl[5]:=21;
+  _contrl[6]:=handle;
 
-  PPointer(@_contrl[7])^:=psrcMFDB;
-  PPointer(@_contrl[9])^:=pdesMFDB;
+  vdi;
+end;
 
-  _contrl[0]:=121;
-  _contrl[1]:=4;
-  _contrl[3]:=3;
+procedure v_clear_disp_list(handle: smallint);
+begin
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=22;
   _contrl[6]:=handle;
 
   vdi;
 end;
 
-procedure v_show_c(handle: smallint; reset: smallint);
+procedure v_bit_image(handle: smallint; const filename: string;
+                aspect, x_scale, y_scale, h_align, v_align: smallint;
+                const xyarray: ARRAY_4);
+var len: longint;
 begin
-  _intin[0]:=reset;
-
-  _contrl[0]:=122;
-  _contrl[1]:=0;
-  _contrl[3]:=1;
+  _ptsin[0]:=xyarray[0];
+  _ptsin[1]:=xyarray[1];
+  _ptsin[2]:=xyarray[2];
+  _ptsin[3]:=xyarray[3];
+  _intin[0]:=aspect;
+  _intin[1]:=x_scale;
+  _intin[2]:=y_scale;
+  _intin[3]:=h_align;
+  _intin[4]:=v_align;
+  len:=string_to_vdi(filename, @_intin[5]);
+  _contrl[0]:=5;
+  _contrl[1]:=2;
+  _contrl[3]:=len+5;
+  _contrl[5]:=23;
   _contrl[6]:=handle;
 
   vdi;
 end;
 
-procedure v_hide_c(handle: smallint);
+procedure vq_scan(handle: smallint; out g_slice, g_page, a_slice, a_page, div_fac: smallint);
 begin
-  _contrl[0]:=123;
+  _contrl[0]:=5;
   _contrl[1]:=0;
   _contrl[3]:=0;
+  _contrl[5]:=24;
   _contrl[6]:=handle;
 
   vdi;
+
+  g_slice:=_intout[0];
+  g_page:=_intout[1];
+  a_slice:=_intout[2];
+  a_page:=_intout[3];
+  div_fac:=_intout[4];
 end;
 
-procedure vs_clip(handle: smallint; clip_flag: smallint; pxyarray: psmallint);
+procedure v_alpha_text(handle: smallint; const outString: String);
+var len: longint;
 begin
-  _intin[0]:=clip_flag;
-  _ptsin[0]:=pxyarray[0];
-  _ptsin[1]:=pxyarray[1];
-  _ptsin[2]:=pxyarray[2];
-  _ptsin[3]:=pxyarray[3];
+  len:=string_to_vdi(outString, @_intin[0]);
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=len;
+  _contrl[5]:=25;
+  _contrl[6]:=handle;
 
-  _contrl[0]:=129;
+  vdi;
+end;
+
+function v_orient(handle, orientation: smallint): smallint;
+begin
+  _intin[0]:=orientation;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=27;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  v_orient:=_intout[0];
+end;
+
+function v_copies(handle, count: smallint): smallint;
+begin
+  _intin[0]:=count;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=28;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  v_copies:=_intout[0];
+end;
+
+procedure v_tray(handle, tray: smallint);
+begin
+  _intin[0]:=tray;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=29;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+function v_page_size(handle, page_id: smallint): smallint;
+begin
+  _intin[0]:=page_id;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=37;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  v_page_size:=_intout[0];
+end;
+
+function vs_palette(handle, palette: smallint): smallint;
+begin
+  _intin[0]:=palette;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=60;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vs_palette:=_intout[0];
+end;
+
+procedure v_sound(handle, frequency, duration: smallint);
+begin
+  _intin[0]:=frequency;
+  _intin[1]:=duration;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=61;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+function vs_mute(handle, action: smallint): smallint;
+begin
+  _intin[0]:=action;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=62;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vt_resolution(handle, xres, yres: smallint;
+                        out xset, yset: smallint);
+begin
+  _intin[0]:=xres;
+  _intin[1]:=yres;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=81;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  xset:=_intout[0];
+  yset:=_intout[1];
+end;
+
+procedure vt_axis(handle, xres, yres: smallint;
+                  out xset, yset: smallint);
+begin
+  _intin[0]:=xres;
+  _intin[1]:=yres;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=82;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  xset:=_intout[0];
+  yset:=_intout[1];
+end;
+
+procedure vt_origin(handle, xorigin, yorigin: smallint);
+begin
+  _intin[0]:=xorigin;
+  _intin[1]:=yorigin;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=83;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vq_tdimensions(handle: smallint; out xdimension, ydimension: smallint);
+begin
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=84;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  xdimension:=_intout[0];
+  ydimension:=_intout[1];
+end;
+
+procedure vt_alignment(handle, dx, dy: smallint);
+begin
+  _intin[0]:=dx;
+  _intin[1]:=dy;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=85;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vsp_film(handle, index, lightness: smallint);
+begin
+  _intin[0]:=index;
+  _intin[1]:=lightness;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=91;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+function vqp_filmname(handle, index: smallint; out name: String): smallint;
+begin
+  _intin[0]:=index;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=92;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vdi_to_string(@_intout[0], name, _contrl[4]);
+  vqp_filmname:=_contrl[4];
+end;
+
+procedure vsc_expose(handle, state: smallint);
+begin
+  _intin[0]:=state;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=93;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_meta_extents(handle, min_x, min_y, max_x, max_y: smallint);
+begin
+  _ptsin[0]:=min_x;
+  _ptsin[1]:=min_y;
+  _ptsin[2]:=max_x;
+  _ptsin[3]:=max_y;
+  _contrl[0]:=5;
   _contrl[1]:=2;
+  _contrl[3]:=0;
+  _contrl[5]:=98;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_write_meta(handle, num_intin: smallint; a_intin: Pointer;
+                       num_ptsin: smallint;a_ptsin: Pointer);
+var pb: TVDIPB;
+begin
+  pb.control := @_contrl;
+  pb.intin := PVDIIntIn(a_intin);
+  pb.ptsin := PVDIPtsIn(a_ptsin);
+  pb.intout := @_intout;
+  pb.ptsout := @_ptsout;
+  _contrl[0]:=5;
+  _contrl[1]:=num_ptsin;
+  _contrl[3]:=num_intin;
+  _contrl[5]:=99;
+  _contrl[6]:=handle;
+
+  vdi(@pb);
+end;
+
+procedure vm_pagesize(handle, pgwidth, pgheight: smallint);
+begin
+  _intin[0]:=0;
+  _intin[1]:=pgwidth;
+  _intin[2]:=pgheight;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=3;
+  _contrl[5]:=99;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vm_coords(handle, llx, lly, urx, ury: smallint);
+begin
+  _intin[0]:=1;
+  _intin[1]:=llx;
+  _intin[2]:=lly;
+  _intin[3]:=urx;
+  _intin[4]:=ury;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=5;
+  _contrl[5]:=99;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+function v_bez_qual(handle, prcnt: smallint; out actual: smallint): smallint;
+begin
+  _intin[0]:=32;
+  _intin[1]:=1;
+  _intin[2]:=prcnt;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=3;
+  _contrl[5]:=99;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  actual:=_intout[0];
+  v_bez_qual:=_intout[0];
+end;
+
+procedure vm_filename(handle: smallint; const filename: String);
+var len: longint;
+begin
+  len:=string_to_vdi(filename, @_intin[0]);
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=len;
+  _contrl[5]:=100;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_offset(handle, offset: smallint);
+begin
+  _intin[0]:=offset;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=101;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_fontinit(handle: smallint; var fh: TFONT_HDR);
+begin
+  PPointer(@_intin[0])^:=@fh;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=102;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_escape2000(handle, times: smallint);
+begin
+  _intin[0]:=times;
+  _contrl[0]:=5;
+  _contrl[1]:=0;
   _contrl[3]:=1;
+  _contrl[5]:=2000;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+
+procedure v_pline(handle: smallint; count: smallint; pxyarray: psmallint);
+var pb: TVDIPB;
+begin
+  pb.control := @_contrl;
+  pb.intin := @_intin;
+  // _ptsin[0..2*count-1] = pxyarray[0..2*count-1];
+  pb.ptsin := PVDIPtsIn(pxyarray);
+  pb.intout := @_intout;
+  pb.ptsout := @_ptsout;
+
+  _contrl[0]:=6;
+  _contrl[1]:=count;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi(@pb);
+end;
+
+procedure v_pline(handle, count: smallint; const pxyarray: Array of smallint);
+var pb: TVDIPB;
+begin
+  pb.control := @_contrl;
+  pb.intin := @_intin;
+  // _ptsin[0..2*count-1] = pxyarray[0..2*count-1];
+  pb.ptsin := @pxyarray;
+  pb.intout := @_intout;
+  pb.ptsout := @_ptsout;
+
+  _contrl[0]:=6;
+  _contrl[1]:=count;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi(@pb);
+end;
+
+procedure v_bez(handle, count: smallint; xyarr, bezarr: Pointer;
+                out extent: ARRAY_4;
+                out totpts, totmoves: smallint);
+var pb: TVDIPB;
+begin
+  pb.control := @_contrl;
+  pb.intin := PVDIIntIn(bezarr);
+  // _ptsin[0..2*count-1] = pxyarray[0..2*count-1];
+  pb.ptsin := PVDIPtsIn(xyarr);
+  pb.intout := @_intout;
+  pb.ptsout := @_ptsout;
+
+  _contrl[0]:=6;
+  _contrl[1]:=count;
+  _contrl[3]:=(count + 1) shr 1;
+  _contrl[5]:=13;
+  _contrl[6]:=handle;
+
+  vdi(@pb);
+
+  totpts:=_intout[0];
+  totmoves:=_intout[1];
+  extent[0]:=_ptsout[0];
+  extent[1]:=_ptsout[1];
+  extent[2]:=_ptsout[2];
+  extent[3]:=_ptsout[3];
+end;
+
+procedure v_pmarker(handle, count: smallint; const pxyarray: Array of smallint);
+var pb: TVDIPB;
+begin
+  pb.control := @_contrl;
+  pb.intin := @_intin;
+  // _ptsin[0..2*count-1] = pxyarray[0..2*count-1];
+  pb.ptsin := @pxyarray;
+  pb.intout := @_intout;
+  pb.ptsout := @_ptsout;
+
+  _contrl[0]:=7;
+  _contrl[1]:=count;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi(@pb);
+end;
+
+procedure v_gtext(handle: smallint; x: smallint; y: smallint; outputstring: pchar);
+var len: smallint;
+begin
+  _ptsin[0]:=x;
+  _ptsin[1]:=y;
+
+  len:=pchar_str_to_vdi(outputstring, @_intin[0]);
+
+  _contrl[0]:=8;
+  _contrl[1]:=1;
+  _contrl[3]:=len;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_gtext(handle, x, y: smallint; const outputstring: string);
+var len: smallint;
+begin
+  _ptsin[0]:=x;
+  _ptsin[1]:=y;
+
+  len:=string_to_vdi(outputstring, @_intin[0]);
+
+  _contrl[0]:=8;
+  _contrl[1]:=1;
+  _contrl[3]:=len;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_fillarea(handle, count: smallint; const pxyarray: Array of smallint);
+var pb: TVDIPB;
+begin
+  pb.control := @_contrl;
+  pb.intin := @_intin;
+  // _ptsin[0..2*count-1] = pxyarray[0..2*count-1];
+  pb.ptsin := @pxyarray;
+  pb.intout := @_intout;
+  pb.ptsout := @_ptsout;
+
+  _contrl[0]:=9;
+  _contrl[1]:=count;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi(@pb);
+end;
+
+procedure v_bez_fill(handle, count: smallint;
+                    xyarr, bezarr: Pointer;
+                    out extent: ARRAY_4;
+                    out totpts, totmoves: smallint);
+var pb: TVDIPB;
+begin
+  pb.control := @_contrl;
+  pb.intin := PVDIIntIn(bezarr);
+  // _ptsin[0..2*count-1] = pxyarray[0..2*count-1];
+  pb.ptsin := PVDIPtsIn(xyarr);
+  pb.intout := @_intout;
+  pb.ptsout := @_ptsout;
+
+  _contrl[0]:=9;
+  _contrl[1]:=count;
+  _contrl[3]:=(count + 1) shr 1;
+  _contrl[5]:=13;
+  _contrl[6]:=handle;
+
+  vdi(@pb);
+
+  totpts:=_intout[0];
+  totmoves:=_intout[1];
+  extent[0]:=_ptsout[0];
+  extent[1]:=_ptsout[1];
+  extent[2]:=_ptsout[2];
+  extent[3]:=_ptsout[3];
+end;
+
+procedure v_bar(handle: smallint; pxyarray: psmallint);
+begin
+  // _ptsin[0..3] = pxyarray[0..3];
+  _ptsin[0]:=pxyarray[0];
+  _ptsin[1]:=pxyarray[1];
+  _ptsin[2]:=pxyarray[2];
+  _ptsin[3]:=pxyarray[3];
+  _contrl[0]:=11;
+  _contrl[1]:=2;
+  _contrl[3]:=0;
+  _contrl[5]:=1;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_bar(handle: smallint; const pxyarray: ARRAY_4);
+begin
+  // _ptsin[0..3] = pxyarray[0..3];
+  _ptsin[0]:=pxyarray[0];
+  _ptsin[1]:=pxyarray[1];
+  _ptsin[2]:=pxyarray[2];
+  _ptsin[3]:=pxyarray[3];
+  _contrl[0]:=11;
+  _contrl[1]:=2;
+  _contrl[3]:=0;
+  _contrl[5]:=1;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_arc(handle, x, y, radius, begang, endang: smallint);
+begin
+  _intin[0]:=begang;
+  _intin[1]:=endang;
+  _ptsin[0]:=x;
+  _ptsin[1]:=y;
+  _ptsin[2]:=0;
+  _ptsin[3]:=0;
+  _ptsin[4]:=0;
+  _ptsin[5]:=0;
+  _ptsin[6]:=radius;
+  _ptsin[7]:=0;
+  _contrl[0]:=11;
+  _contrl[1]:=4;
+  _contrl[3]:=2;
+  _contrl[5]:=2;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_pieslice(handle, x, y, radius, begang, endang: smallint);
+begin
+  _intin[0]:=begang;
+  _intin[1]:=endang;
+  _ptsin[0]:=x;
+  _ptsin[1]:=y;
+  _ptsin[2]:=0;
+  _ptsin[3]:=0;
+  _ptsin[4]:=0;
+  _ptsin[5]:=0;
+  _ptsin[6]:=radius;
+  _ptsin[7]:=0;
+  _contrl[0]:=11;
+  _contrl[1]:=4;
+  _contrl[3]:=2;
+  _contrl[5]:=3;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+
+procedure v_circle (handle: smallint; x: smallint; y: smallint; radius: smallint);
+begin
+  _ptsin[0]:=x;
+  _ptsin[1]:=y;
+  _ptsin[2]:=0;
+  _ptsin[3]:=0;
+  _ptsin[4]:=radius;
+  _ptsin[5]:=0;
+
+  _contrl[0]:=11;
+  _contrl[1]:=3;
+  _contrl[3]:=0;
+  _contrl[5]:=4;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_ellipse(handle, x, y, xradius, yradius: smallint);
+begin
+  _ptsin[0]:=x;
+  _ptsin[1]:=y;
+  _ptsin[2]:=xradius;
+  _ptsin[3]:=yradius;
+
+  _contrl[0]:=11;
+  _contrl[1]:=2;
+  _contrl[3]:=0;
+  _contrl[5]:=5;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_ellarc(handle, x, y, xradius, yradius, begang, endang: smallint);
+begin
+  _intin[0]:=begang;
+  _intin[1]:=endang;
+  _ptsin[0]:=x;
+  _ptsin[1]:=y;
+  _ptsin[2]:=xradius;
+  _ptsin[3]:=yradius;
+
+  _contrl[0]:=11;
+  _contrl[1]:=2;
+  _contrl[3]:=2;
+  _contrl[5]:=6;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_ellpie(handle, x, y, xradius, yradius, begang, endang: smallint);
+begin
+  _intin[0]:=begang;
+  _intin[1]:=endang;
+  _ptsin[0]:=x;
+  _ptsin[1]:=y;
+  _ptsin[2]:=xradius;
+  _ptsin[3]:=yradius;
+
+  _contrl[0]:=11;
+  _contrl[1]:=2;
+  _contrl[3]:=2;
+  _contrl[5]:=7;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_rbox(handle: smallint; const xyarray: ARRAY_4);
+begin
+  _ptsin[0]:=xyarray[0];
+  _ptsin[1]:=xyarray[1];
+  _ptsin[2]:=xyarray[2];
+  _ptsin[3]:=xyarray[3];
+
+  _contrl[0]:=11;
+  _contrl[1]:=2;
+  _contrl[3]:=0;
+  _contrl[5]:=8;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_rfbox(handle: smallint; const xyarray: ARRAY_4);
+begin
+  _ptsin[0]:=xyarray[0];
+  _ptsin[1]:=xyarray[1];
+  _ptsin[2]:=xyarray[2];
+  _ptsin[3]:=xyarray[3];
+
+  _contrl[0]:=11;
+  _contrl[1]:=2;
+  _contrl[3]:=0;
+  _contrl[5]:=9;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_justified(handle, x, y: smallint;
+        const outputstring: string;
+        width, wordspace, charspace: smallint);
+var len: smallint;
+begin
+  {* TODO: handle char_space $8000/$8001 (returns interspace information) *}
+  _intin[0]:=wordspace;
+  _intin[1]:=charspace;
+  _ptsin[0]:=x;
+  _ptsin[1]:=y;
+  _ptsin[2]:=width;
+  _ptsin[3]:=0;
+
+  len:=string_to_vdi(outputstring, @_intin[2]);
+
+  _contrl[0]:=11;
+  _contrl[1]:=2;
+  _contrl[3]:=len+2;
+  _contrl[4]:=0;
+  _contrl[5]:=11;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+function v_bez_on(handle: smallint): smallint;
+begin
+  _contrl[0]:=11;
+  _contrl[1]:=1;
+  _contrl[3]:=0;
+  _contrl[5]:=13;
+  _contrl[6]:=handle;
+  _intout[0]:=0;
+
+  vdi;
+
+  v_bez_on:=_intout[0];
+end;
+
+procedure v_bez_off(handle: smallint);
+begin
+  _contrl[0]:=11;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=13;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vst_height(handle, height: smallint; out char_width, char_height, cell_width, cell_height: smallint);
+begin
+  _ptsin[0]:=0;
+  _ptsin[1]:=height;
+
+  _contrl[0]:=12;
+  _contrl[1]:=1;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  char_width:=_ptsout[0];
+  char_height:=_ptsout[1];
+  cell_width:=_ptsout[2];
+  cell_height:=_ptsout[3];
+end;
+
+function vst_rotation(handle, angle: smallint): smallint;
+begin
+  _intin[0]:=angle;
+
+  _contrl[0]:=13;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vst_rotation:=_intout[0];
+end;
+
+procedure vs_color(handle: smallint; index: smallint; rgb_in: psmallint);
+begin
+  _intin[0]:=index;
+  _intin[1]:=rgb_in[0];
+  _intin[2]:=rgb_in[1];
+  _intin[3]:=rgb_in[2];
+
+  _contrl[0]:=14;
+  _contrl[1]:=0;
+  _contrl[3]:=4;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vs_color(handle, index: smallint; const rgb_in: ARRAY_3);
+begin
+  _intin[0]:=index;
+  _intin[1]:=rgb_in[0];
+  _intin[2]:=rgb_in[1];
+  _intin[3]:=rgb_in[2];
+
+  _contrl[0]:=14;
+  _contrl[1]:=0;
+  _contrl[3]:=4;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+function vsl_type(handle, style: smallint): smallint;
+begin
+  _intin[0]:=style;
+
+  _contrl[0]:=15;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vsl_type:=_intout[0];
+end;
+
+function vsl_width(handle, width: smallint): smallint;
+begin
+  _ptsin[0]:=width;
+  _ptsin[0]:=0;
+
+  _contrl[0]:=16;
+  _contrl[1]:=1;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vsl_width:=_ptsout[0];
+end;
+
+function vsl_color(handle: smallint; color_index: smallint): smallint;
+begin
+  _intin[0]:=color_index;
+
+  _contrl[0]:=17;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vsl_color:=_intout[0];
+end;
+
+function vsm_type(handle, symbol: smallint): smallint;
+begin
+  _intin[0]:=symbol;
+
+  _contrl[0]:=18;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vsm_type:=_intout[0];
+end;
+
+function vsm_height(handle, height: smallint): smallint;
+begin
+  _ptsin[0]:=0;
+  _ptsin[1]:=height;
+
+  _contrl[0]:=19;
+  _contrl[1]:=1;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vsm_height:=_ptsout[1];
+end;
+
+function vsm_color(handle, color_index: smallint): smallint;
+begin
+  _intin[0]:=color_index;
+
+  _contrl[0]:=20;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vsm_color:=_intout[0];
+end;
+
+function vst_font(handle, font: smallint): smallint;
+begin
+  _intin[0]:=font;
+
+  _contrl[0]:=21;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vst_font:=_intout[0];
+end;
+
+function vst_color(handle: smallint; color_index: smallint): smallint;
+begin
+  _intin[0]:=color_index;
+
+  _contrl[0]:=22;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vst_color:=_intout[0];
+end;
+
+function vsf_interior(handle, style: smallint): smallint;
+begin
+  _intin[0]:=style;
+
+  _contrl[0]:=23;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vsf_interior:=_intout[0];
+end;
+
+function vsf_style(handle, style_index: smallint): smallint;
+begin
+  _intin[0]:=style_index;
+
+  _contrl[0]:=24;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vsf_style:=_intout[0];
+end;
+
+function vsf_color(handle: smallint; color_index: smallint): smallint;
+begin
+  _intin[0]:=color_index;
+
+  _contrl[0]:=25;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vsf_color:=_intout[0];
+end;
+
+function vq_color(handle, color_index, set_flag: smallint; out rgb: ARRAY_3): smallint;
+begin
+  _intin[0]:=color_index;
+  _intin[1]:=set_flag;
+
+  _contrl[0]:=26;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  rgb[0]:=_intout[1];
+  rgb[1]:=_intout[2];
+  rgb[2]:=_intout[3];
+  vq_color:=_intout[0];
+end;
+
+procedure vrq_locator(handle, x, y: smallint; out xout, yout, term: smallint);
+begin
+  _ptsin[0]:=x;
+  _ptsin[1]:=y;
+
+  _contrl[0]:=28;
+  _contrl[1]:=1;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  xout:=_ptsout[0];
+  yout:=_ptsout[1];
+  term:=_intout[0];
+end;
+
+function vsm_locator(handle, x, y: smallint; out xout, yout, term: smallint): smallint;
+begin
+  _ptsin[0]:=x;
+  _ptsin[1]:=y;
+
+  _contrl[0]:=28;
+  _contrl[1]:=1;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  xout:=_ptsout[0];
+  yout:=_ptsout[1];
+  term:=_intout[0];
+
+  vsm_locator:=(_contrl[4] shl 1) or (_contrl[2]);
+end;
+
+procedure vrq_valuator(handle, valuator_in: smallint; out valuator_out, terminator: smallint);
+begin
+  _intin[0]:=valuator_in;
+
+  _contrl[0]:=29;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  valuator_out:=_intout[0];
+  terminator:=_intout[1];
+end;
+
+procedure vsm_valuator(handle, val_in: smallint; out val_out, term, status: smallint);
+begin
+  _intin[0]:=val_in;
+
+  _contrl[0]:=29;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  val_out:=_intout[0];
+  term:=_intout[1];
+  status:=_contrl[4];
+end;
+
+procedure vrq_choice(handle, ch_in: smallint; out ch_out: smallint);
+begin
+  _intin[0]:=ch_in;
+
+  _contrl[0]:=30;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  ch_out:=_intout[0];
+end;
+
+function vsm_choice(handle: smallint; out choice: smallint): smallint;
+begin
+  _intin[0]:=choice;
+
+  _contrl[0]:=30;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  choice:=_intout[0];
+  vsm_choice:=_contrl[4];
+end;
+
+procedure vrq_string(handle, max_length, echo_mode: smallint; const echo_xy: ARRAY_2; out resString: string);
+begin
+  _intin[0]:=max_length;
+  _intin[1]:=echo_mode;
+  _ptsin[0]:=echo_xy[0];
+  _ptsin[1]:=echo_xy[1];
+
+  _contrl[0]:=31;
+  _contrl[1]:=1;
+  _contrl[3]:=2;
+  _contrl[4]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vdi_to_string(@_intout, resString, _contrl[4]);
+end;
+
+function vsm_string(handle, max_length, echo_mode: smallint; const echo_xy: ARRAY_2; out resString: string): smallint;
+begin
+  _intin[0]:=max_length;
+  _intin[1]:=echo_mode;
+  _ptsin[0]:=echo_xy[0];
+  _ptsin[1]:=echo_xy[1];
+
+  _contrl[0]:=31;
+  _contrl[1]:=1;
+  _contrl[3]:=2;
+  _contrl[4]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vdi_to_string(@_intout, resString, _contrl[4]);
+  vsm_string:=_contrl[4];
+end;
+
+function vswr_mode(handle: smallint; mode: smallint): smallint;
+begin
+  _intin[0]:=mode;
+
+  _contrl[0]:=32;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vswr_mode:=_intout[0];
+end;
+
+function vsin_mode(handle, dev_type, mode: smallint): smallint;
+begin
+  _intin[0]:=mode;
+  _intin[1]:=dev_type;
+
+  _contrl[0]:=33;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vsin_mode:=_intout[0];
+end;
+
+procedure vql_attributes(handle: smallint; out attrib: ARRAY_4);
+begin
+  _contrl[0]:=35;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  attrib[0]:=_intout[0];
+  attrib[1]:=_intout[1];
+  attrib[2]:=_intout[2];
+  attrib[3]:=_ptsout[0];
+end;
+
+procedure vql_attributes(handle: smallint; out attrib: ARRAY_6);
+begin
+  _contrl[0]:=35;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  attrib[0]:=_intout[0];
+  attrib[1]:=_intout[1];
+  attrib[2]:=_intout[2];
+  attrib[3]:=_ptsout[0];
+  {* TOS/EmuTOS do not return the line end styles in intout[3/4] *}
+  if (_contrl[4] >= 5) then
+    begin
+      attrib[4]:=_intout[3];
+      attrib[5]:=_intout[4];
+    end else begin
+      attrib[4]:=0;
+      attrib[5]:=0;
+    end;
+end;
+
+procedure vqm_attributes(handle: smallint; out attrib: ARRAY_4);
+begin
+  _contrl[0]:=36;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  attrib[0]:=_intout[0];
+  attrib[1]:=_intout[1];
+  attrib[2]:=_intout[2];
+  attrib[3]:=_ptsout[0];
+end;
+
+procedure vqf_attributes(handle: smallint; out attrib: ARRAY_5);
+begin
+  _contrl[0]:=37;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  attrib[0]:=_intout[0];
+  attrib[1]:=_intout[1];
+  attrib[2]:=_intout[2];
+  attrib[3]:=_intout[3];
+  attrib[4]:=_intout[4];
+end;
+
+procedure vqt_attributes(handle: smallint; out attrib: ARRAY_10);
+begin
+  _contrl[0]:=38;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  attrib[0]:=_intout[0];
+  attrib[1]:=_intout[1];
+  attrib[2]:=_intout[2];
+  attrib[3]:=_intout[3];
+  attrib[4]:=_intout[4];
+  attrib[5]:=_intout[5];
+  attrib[6]:=_ptsout[0];
+  attrib[7]:=_ptsout[1];
+  attrib[8]:=_ptsout[2];
+  attrib[9]:=_ptsout[3];
+end;
+
+procedure vst_alignment(handle, hor_in, vert_in: smallint; out hor_out, vert_out: smallint);
+begin
+  _intin[0]:=hor_in;
+  _intin[1]:=vert_in;
+
+  _contrl[0]:=39;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  hor_out:=_intout[0];
+  vert_out:=_intout[1];
+end;
+
+procedure v_opnvwk(work_in: psmallint; handle: psmallint; work_out: psmallint);
+var pb: TVDIPB;
+begin
+  pb.control := @_contrl;
+  // _intin[0..10] = work_in[0..10];
+  pb.intin := PVDIIntIn(work_in);
+  pb.ptsin := @_ptsin;
+  // work_out[0..44] = intout[0..44];
+  pb.intout := PVDIIntOut(work_out);
+  // work_out[45..56] = ptsout[0..11];
+  pb.ptsout := PVDIPtsOut(@work_out[45]);
+
+  _contrl[0]:=100;
+  _contrl[1]:=0;
+  _contrl[3]:=11;
+  _contrl[5]:=0;
+  _contrl[6]:=handle^;
+
+  vdi(@pb);
+
+  handle^:=_contrl[6];
+end;
+
+procedure v_clsvwk(handle: smallint);
+begin
+  _contrl[0]:=101;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vq_extnd(handle, owflag: smallint; WorkOut: psmallint);
+var pb: TVDIPB;
+begin
+  pb.control := @_contrl;
+  pb.intin := @_intin;
+  pb.ptsin := @_ptsin;
+  // work_out[0..44] = intout[0..44];
+  pb.intout := @workout;
+  // work_out[45..56] = ptsout[0..11];
+  pb.ptsout := @workout[45];
+
+  _intin[0]:=owflag;
+
+  _contrl[0]:=102;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi(@pb);
+end;
+
+
+procedure vq_scrninfo(handle: smallint; out WorkOut: ARRAY_273);
+var pb: TVDIPB;
+begin
+  pb.control := @_contrl;
+  pb.intin := @_intin;
+  pb.ptsin := @_ptsin;
+  pb.intout := @workout;
+  pb.ptsout := @_ptsout;
+
+  _intin[0]:=2;
+
+  _contrl[0]:=102;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=1;
+  _contrl[6]:=handle;
+
+  vdi(@pb);
+end;
+
+procedure v_contourfill(handle, x, y, index: smallint);
+begin
+  _intin[0]:=index;
+  _ptsin[0]:=x;
+  _ptsin[1]:=y;
+  _contrl[0]:=103;
+  _contrl[1]:=1;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+function vsf_perimeter(handle, per_vis: smallint): smallint;
+begin
+  _intin[0]:=per_vis;
+  _contrl[0]:=104;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vsf_perimeter:=_intout[0];
+end;
+
+procedure v_get_pixel(handle: smallint; x: smallint; y: smallint;
+                      pel: psmallint; index: psmallint);
+begin
+  _ptsin[0]:=x;
+  _ptsin[1]:=y;
+  _contrl[0]:=105;
+  _contrl[1]:=1;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  pel^:=_intout[0];
+  index^:=_intout[1];
+end;
+
+procedure v_get_pixel(handle, x, y: smallint; out pel, index: smallint);
+begin
+  _ptsin[0]:=x;
+  _ptsin[1]:=y;
+  _contrl[0]:=105;
+  _contrl[1]:=1;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  pel:=_intout[0];
+  index:=_intout[1];
+end;
+
+function vst_effects(handle, effect: smallint): smallint;
+begin
+  _intin[0]:=effect;
+  _contrl[0]:=106;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vst_effects:=_intout[0];
+end;
+
+function vst_point(handle, point: smallint; out char_width, char_height, cell_width, cell_height: smallint): smallint;
+begin
+  _intin[0]:=point;
+  _contrl[0]:=107;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  char_width:=_ptsout[0];
+  char_height:=_ptsout[1];
+  cell_width:=_ptsout[2];
+  cell_height:=_ptsout[3];
+end;
+
+procedure vsl_ends(handle, beg_style, end_style: smallint);
+begin
+  _intin[0]:=beg_style;
+  _intin[1]:=end_style;
+  _contrl[0]:=108;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vro_cpyfm(handle: smallint; vr_mode: smallint; pxyarray: psmallint; psrcMFDB: PMFDB; pdesMFDB: PMFDB);
+begin
+  _intin[0]:=vr_mode;
+  _ptsin[0]:=pxyarray[0];
+  _ptsin[1]:=pxyarray[1];
+  _ptsin[2]:=pxyarray[2];
+  _ptsin[3]:=pxyarray[3];
+  _ptsin[4]:=pxyarray[4];
+  _ptsin[5]:=pxyarray[5];
+  _ptsin[6]:=pxyarray[6];
+  _ptsin[7]:=pxyarray[7];
+
+  PPointer(@_contrl[7])^:=psrcMFDB;
+  PPointer(@_contrl[9])^:=pdesMFDB;
+
+  _contrl[0]:=109;
+  _contrl[1]:=4;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vr_trnfm(handle: smallint; psrcMFDB, pdesMFDB: PMFDB);
+begin
+  PPointer(@_contrl[7])^:=psrcMFDB;
+  PPointer(@_contrl[9])^:=pdesMFDB;
+
+  _contrl[0]:=110;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vr_trnfm(handle: smallint; const psrcMFDB, pdesMFDB: TMFDB);
+begin
+  PPointer(@_contrl[7])^:=@psrcMFDB;
+  PPointer(@_contrl[9])^:=@pdesMFDB;
+
+  _contrl[0]:=110;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vsc_form(handle: smallint; pcur_form: PMFORM);
+var pb: TVDIPB;
+begin
+  {* TODO: NVDI also returns current form in intout *}
+  pb.control := @_contrl;
+  pb.intin := PVDIIntIn(pcur_form);
+  pb.ptsin := @_ptsin;
+  pb.intout := @_intout;
+  pb.ptsout := @_ptsout;
+  _contrl[0]:=111;
+  _contrl[1]:=0;
+  _contrl[3]:=37;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi(@pb);
+end;
+
+procedure vsf_udpat(handle: smallint; pfill_pat: Pointer; planes: smallint);
+var pb: TVDIPB;
+begin
+  pb.control := @_contrl;
+  pb.intin := PVDIIntIn(pfill_pat);
+  pb.ptsin := @_ptsin;
+  pb.intout := @_intout;
+  pb.ptsout := @_ptsout;
+  _contrl[0]:=112;
+  _contrl[1]:=0;
+  _contrl[3]:=planes*16;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi(@pb);
+end;
+
+procedure vsl_udsty(handle, pattern: smallint);
+begin
+  _intin[0]:=pattern;
+  _contrl[0]:=113;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vr_recfl(handle: smallint; const pxyarray: ARRAY_4);
+begin
+  _ptsin[0]:=pxyarray[0];
+  _ptsin[1]:=pxyarray[1];
+  _ptsin[2]:=pxyarray[2];
+  _ptsin[3]:=pxyarray[3];
+  _contrl[0]:=114;
+  _contrl[1]:=2;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vqin_mode(handle, dev_type: smallint; out input_mode: smallint);
+begin
+  _intin[0]:=dev_type;
+  _contrl[0]:=115;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  input_mode:=_intout[0];
+end;
+
+procedure vqt_extent(handle: smallint; calcString: pchar; extent: psmallint);
+var len: smallint;
+begin
+  len:=pchar_str_to_vdi(calcstring, @_intin[0]);
+  _contrl[0]:=116;
+  _contrl[1]:=0;
+  _contrl[3]:=len;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  extent[0]:=_ptsout[0];
+  extent[1]:=_ptsout[1];
+  extent[2]:=_ptsout[2];
+  extent[3]:=_ptsout[3];
+  extent[4]:=_ptsout[4];
+  extent[5]:=_ptsout[5];
+  extent[6]:=_ptsout[6];
+  extent[7]:=_ptsout[7];
+end;
+
+function vqt_width(handle, character: smallint; out cell_width, left_delta, right_delta: smallint): smallint;
+begin
+  _intin[0]:=character;
+  _contrl[0]:=117;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  cell_width:=_ptsout[0];
+  left_delta:=_ptsout[2];
+  right_delta:=_ptsout[4];
+  vqt_width:=_intout[0];
+end;
+
+procedure vex_timv(handle: smallint; tim_addr: Pointer; out otim_addr: Pointer; out tim_conv: smallint);
+begin
+  _contrl[0]:=118;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+  PPointer(@_contrl[7])^:=tim_addr;
+
+  vdi;
+
+  otim_addr:=PPointer(@_contrl[9])^;
+  tim_conv:=_intout[0];
+end;
+
+function vst_load_fonts(handle, select: smallint): smallint;
+begin
+  _intin[0]:=select;
+
+  _contrl[0]:=119;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vst_load_fonts:=_intout[0];
+end;
+
+procedure vst_unload_fonts(handle, select: smallint);
+begin
+  _intin[0]:=select;
+
+  _contrl[0]:=120;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vrt_cpyfm(handle: smallint; vr_mode: smallint; pxyarray: psmallint; psrcMFDB: PMFDB; pdesMFDB: PMFDB; color_index: psmallint);
+begin
+  _intin[0]:=vr_mode;
+  _intin[1]:=color_index[0];
+  _intin[2]:=color_index[1];
+  _ptsin[0]:=pxyarray[0];
+  _ptsin[1]:=pxyarray[1];
+  _ptsin[2]:=pxyarray[2];
+  _ptsin[3]:=pxyarray[3];
+  _ptsin[4]:=pxyarray[4];
+  _ptsin[5]:=pxyarray[5];
+  _ptsin[6]:=pxyarray[6];
+  _ptsin[7]:=pxyarray[7];
+
+  PPointer(@_contrl[7])^:=psrcMFDB;
+  PPointer(@_contrl[9])^:=pdesMFDB;
+
+  _contrl[0]:=121;
+  _contrl[1]:=4;
+  _contrl[3]:=3;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_show_c(handle: smallint; reset: smallint);
+begin
+  _intin[0]:=reset;
+
+  _contrl[0]:=122;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_hide_c(handle: smallint);
+begin
+  _contrl[0]:=123;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vq_mouse(handle: smallint; out pstatus, x, y: smallint);
+begin
+  _contrl[0]:=124;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  pstatus:=_intout[0];
+  x:=_ptsout[0];
+  y:=_ptsout[1];
+end;
+
+procedure vex_butv(handle: smallint; pusrcode: Pointer; out psavcode: Pointer);
+begin
+  _contrl[0]:=125;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+  PPointer(@_contrl[7])^:=pusrcode;
+
+  vdi;
+
+  psavcode:=PPointer(@_contrl[9])^;
+end;
+
+procedure vex_motv(handle: smallint; pusrcode: Pointer; out psavcode: Pointer);
+begin
+  _contrl[0]:=126;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+  PPointer(@_contrl[7])^:=pusrcode;
+
+  vdi;
+
+  psavcode:=PPointer(@_contrl[9])^;
+end;
+
+procedure vex_curv(handle: smallint; pusrcode: Pointer; out psavcode: Pointer);
+begin
+  _contrl[0]:=127;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+  PPointer(@_contrl[7])^:=pusrcode;
+
+  vdi;
+
+  psavcode:=PPointer(@_contrl[9])^;
+end;
+
+procedure vq_key_s(handle: smallint; out pstatus: smallint);
+begin
+  _contrl[0]:=128;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  pstatus:=_intout[0];
+end;
+
+procedure vs_clip(handle: smallint; clip_flag: smallint; pxyarray: psmallint);
+begin
+  _intin[0]:=clip_flag;
+  _ptsin[0]:=pxyarray[0];
+  _ptsin[1]:=pxyarray[1];
+  _ptsin[2]:=pxyarray[2];
+  _ptsin[3]:=pxyarray[3];
+
+  _contrl[0]:=129;
+  _contrl[1]:=2;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vs_clip(handle, clip_flag: smallint; const pxyarray: ARRAY_4);
+begin
+  _intin[0]:=clip_flag;
+  _ptsin[0]:=pxyarray[0];
+  _ptsin[1]:=pxyarray[1];
+  _ptsin[2]:=pxyarray[2];
+  _ptsin[3]:=pxyarray[3];
+
+  _contrl[0]:=129;
+  _contrl[1]:=2;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vs_clip_off(handle: smallint);
+begin
+  _intin[0]:=0;
+  _ptsin[0]:=0;
+  _ptsin[1]:=0;
+  _ptsin[2]:=0;
+  _ptsin[3]:=0;
+
+  _contrl[0]:=129;
+  _contrl[1]:=2;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+function vqt_name(handle, element_num: smallint; out name: String33): smallint;
+begin
+  _intin[0]:=element_num;
+
+  _contrl[0]:=130;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vdi_to_string(@_intout[1], name, _contrl[4] - 1);
+
+  vqt_name:=_intout[0];
+end;
+
+procedure vqt_fontinfo(handle: smallint;
+        out minADE, maxADE: smallint;
+        out distances: ARRAY_5;
+        out maxwidth: smallint;
+        out effects: ARRAY_3);
+begin
+  _contrl[0]:=131;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  minADE:=_intout[0];
+  maxADE:=_intout[1];
+  maxwidth:=_ptsout[0];
+  distances[0]:=_ptsout[1];
+  distances[1]:=_ptsout[3];
+  distances[2]:=_ptsout[5];
+  distances[3]:=_ptsout[7];
+  distances[4]:=_ptsout[9];
+  effects[0]:=_ptsout[2];
+  effects[1]:=_ptsout[4];
+  effects[2]:=_ptsout[6];
+end;
+
+procedure vqt_justified(handle, x, y: smallint; const outString: String;
+            length, word_space, char_space: smallint;
+            offsets: Pointer);
+var len: smallint;
+var pb: TVDIPB;
+begin
+  pb.control := @_contrl;
+  pb.intin := @_intin;
+  pb.ptsin := @_ptsin;
+  pb.intout := @_intout;
+  pb.ptsout := PVDIPtsOut(offsets);
+  _intin[0]:=word_space;
+  _intin[1]:=char_space;
+  len:=string_to_vdi(outstring, @_intin[2]);
+  _ptsin[0]:=x;
+  _ptsin[1]:=y;
+  _ptsin[2]:=length;
+  _ptsin[3]:=0;
+  _contrl[0]:=132;
+  _contrl[1]:=2;
+  _contrl[3]:=len+2;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi(@pb);
+end;
+
+procedure vex_wheelv(handle: smallint; pusrcode: Pointer; out psavcode: Pointer);
+begin
+  _contrl[0]:=134;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+  PPointer(@_contrl[7])^:=pusrcode;
+
+  vdi;
+
+  psavcode:=PPointer(@_contrl[9])^;
+end;
+
+
+procedure vst_width(handle, width: smallint; out char_width, char_height, cell_width, cell_height: smallint);
+begin
+  _intin[0]:=width;
+  _contrl[0]:=231;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  char_width:=_intout[0];
+  char_height:=_intout[1];
+  cell_width:=_intout[2];
+  cell_height:=_intout[3];
+end;
+
+procedure vqt_fontheader(handle: smallint; buffer: Pointer;
+                         out pathname: String);
+begin
+  Ppointer(@_intin[0])^:=buffer;
+  _contrl[0]:=232;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vdi_to_string(@_intout[0], pathname, _contrl[4]);
+end;
+
+procedure vqt_trackkern(handle: smallint; out x, y: fix31);
+begin
+  _contrl[0]:=234;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  x:=PLongint(@_intout[0])^;
+  y:=PLongint(@_intout[2])^;
+end;
+
+procedure vqt_pairkern(handle, ch1, ch2: smallint; out x, y: fix31);
+begin
+  _intin[0]:=ch1;
+  _intin[2]:=ch2;
+  _contrl[0]:=235;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  x:=PLongint(@_intout[0])^;
+  y:=PLongint(@_intout[2])^;
+end;
+
+
+procedure vst_charmap(handle, mode: smallint);
+begin
+  _intin[0]:=mode;
+  _contrl[0]:=236;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+function vst_map_mode(handle, mode: smallint): smallint;
+begin
+  _intin[0]:=mode;
+  _intin[1]:=1;
+  _contrl[0]:=236;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  vst_map_mode:=_intout[0];
+end;
+
+procedure vst_kern(handle, tmode, pmode: smallint; out tracks, pairs: smallint);
+begin
+  _intin[0]:=tmode;
+  _intin[1]:=pmode;
+  _contrl[0]:=237;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  tracks:=_intout[0];
+  pairs:=_intout[0];
+end;
+
+procedure vst_track_offset(handle: smallint; offset: fix31; pairmode: smallint; out tracks, pairs: smallint);
+begin
+  _intin[0]:=255;
+  _intin[1]:=pairmode;
+  PLongint(@_intin[2])^:=offset;
+  _contrl[0]:=237;
+  _contrl[1]:=0;
+  _contrl[3]:=4;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  tracks:=_intout[0];
+  pairs:=_intout[0];
+end;
+
+procedure v_getbitmap_info(handle, ch: smallint;
+                           out advx, advy, xoff, yoff: fix31;
+                           out width, height: smallint;
+                           out bitmap: pointer);
+begin
+  _intin[0]:=ch;
+  _contrl[0]:=239;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  width:=_intout[0];
+  height:=_intout[1];
+  advx:=PLongint(@_intout[2])^;
+  advy:=PLongint(@_intout[4])^;
+  xoff:=PLongint(@_intout[6])^;
+  yoff:=PLongint(@_intout[8])^;
+  if (bitmap <> nil) then
+    bitmap:=PPointer(@_intout[10])^;
+end;
+
+
+procedure v_ftext(handle, x, y: smallint; const str: String);
+var len: longint;
+begin
+  len:=string_to_vdi(str, @_intin[0]);
+  _ptsin[0]:=x;
+  _ptsin[0]:=y;
+  _contrl[0]:=241;
+  _contrl[1]:=1;
+  _contrl[3]:=len;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_ftext_offset(handle, x, y: smallint;
+                         const outputstring: string;
+                         const offset: Array of smallint);
+var i, len: longint;
+    src, dst: psmallint;
+begin
+  len:=string_to_vdi(outputstring, @_intin[0]);
+  _ptsin[0]:=x;
+  _ptsin[1]:=y;
+  src:=offset;
+  dst:=@_ptsin[2];
+  for i:=0 to len-1 do
+    begin
+      dst^:=src^;
+      inc(dst);
+      inc(src);
+      dst^:=src^;
+      inc(dst);
+      inc(src);
+    end;
+  _contrl[0]:=241;
+  _contrl[1]:=len+1;
+  _contrl[3]:=len;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_killoutline(handle: smallint; component: Pointer);
+begin
+  PPointer(@_intin[0])^:=component;
+  _contrl[0]:=242;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure v_getoutline(handle, ch: smallint;
+                       const xyarray: Array of smallint;
+                       const bezarray: Array of ShortInt;
+                       maxverts: smallint;
+                       out numverts: smallint);
+begin
+  _intin[0]:=ch;
+  _intin[1]:=maxverts;
+  PPointer(@_intin[2])^:=@xyarray;
+  PPointer(@_intin[4])^:=@bezarray;
+  _contrl[0]:=243;
+  _contrl[1]:=0;
+  _contrl[3]:=6;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  numverts:=_intout[0];
+end;
+
+procedure vst_scratch(handle, mode: smallint);
+begin
+  _intin[0]:=mode;
+  _contrl[0]:=244;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+procedure vst_error(handle, mode: smallint; out errorvar: smallint);
+begin
+  _intin[0]:=mode;
+  PPointer(@_intin[1])^:=@errorvar;
+  _contrl[0]:=245;
+  _contrl[1]:=0;
+  _contrl[3]:=3;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+end;
+
+function vst_arbpt(handle, point: smallint;
+                   out chwd, chht, cellwd, cellht: smallint): smallint;
+begin
+  _intin[0]:=point;
+  _contrl[0]:=246;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  chwd:=_ptsout[0];
+  chht:=_ptsout[1];
+  cellwd:=_ptsout[2];
+  cellht:=_ptsout[3];
+
+  vst_arbpt:=_intout[0];
+end;
+
+function vst_arbpt32(handle: smallint; point: fix31;
+                     out chwd, chht, cellwd, cellht: smallint): fix31;
+begin
+  PLongint(@_intin[0])^:=point;
+  _contrl[0]:=246;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  chwd:=_ptsout[0];
+  chht:=_ptsout[1];
+  cellwd:=_ptsout[2];
+  cellht:=_ptsout[3];
+
+  vst_arbpt32:=PLongint(@_intout[0])^;
+end;
+
+procedure vqt_advance(handle, ch: smallint; out advx, advy, remx, remy: smallint);
+begin
+  _intin[0]:=ch;
+  _contrl[0]:=247;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  advx:=_ptsout[0];
+  advy:=_ptsout[1];
+  remx:=_ptsout[2];
+  remy:=_ptsout[3];
+end;
+
+procedure vqt_advance32(handle, ch: smallint; out advx, advy: fix31);
+begin
+  _intin[0]:=ch;
+  _contrl[0]:=247;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  advx:=PLongint(@_ptsout[4])^;
+  advy:=PLongint(@_ptsout[6])^;
+end;
+
+function vq_devinfo(handle, devnum: smallint;
+                      out devexists: smallint;
+                      out filename: String;
+                      out devicename: String): smallint;
+var i, len: smallint;
+    ch: char;
+begin
+  _intin[0]:=devnum;
+  _contrl[0]:=248;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+  if (_contrl[4] = 0) or (_intout[4] = 0) then
+    begin
+      devexists:= 0;
+      filename := '';
+      devicename := '';
+      vq_devinfo:=0;
+    end
+  else
+    begin
+      (* here, the driver exists *)
+      devexists:=1;
+      (* set the filename. The value in vdi_intout may be "DRIVER.SYS"
+       * or "DRIVER   SYS". vdi_intout is not a nul-terminated string.
+       * In both cases, this binding returns a valid filename: "DRIVER.SYS"
+       * with a null-character to ended the string.
+       *)
+      len := 0;
+      for i:=0 to _contrl[4]-1 do
+        begin
+          ch := chr(_intout[i]);
+          inc(len);
+          filename[len]:=ch;
+          if (ch = ' ') and (chr(_intout[i+1]) <> ' ') then
+            begin
+              inc(len);
+              filename[len]:='.';
+            end
+          else
+            begin
+              inc(len);
+              filename[len]:=ch;
+            end
+        end;
+      setlength(filename, len);
+
+      (* device name in ptsout is a C-String, (a nul-terminated string with 8bits per characters)
+       * each short value (vdi_ptsout[x]) contains 2 characters.
+       * When ptsout contains a device name, NVDI/SpeedoGDOS seems to always write the value "13"
+       * in vdi_control[1] (hey! this should be a read only value from the VDI point of view!!!),
+       * and SpeedoGDOS 5 may set vdi_control[2] == 1 (intead of the size of vdi_ptsout, including
+       * the device_name). It's seems that this value "13" (written in vdi_control[1]) has missed
+       * its target (vdi_control[2]). So, here is a workaround:
+       *)
+       if (_contrl[2] = 1) and (_contrl[1] > 0) then
+         len := _contrl[1] * 2
+       else
+         len := (_contrl[2] - 1) * 2;
+       setlength(devicename, len);
+       move(_ptsout[1], devicename[1], len);
+       vq_devinfo:=_intout[0];;
+    end;
+
+end;
+
+procedure vqt_devinfo(handle, devnum: smallint;
+                      out dev_busy: smallint;
+                      out filename: String;
+                      out devicename: String);
+var dummy: smallint;
+begin
+  dev_busy:=vq_devinfo(handle, devnum, dummy, filename, devicename);
+end;
+
+function v_savecache(handle: smallint; const filename: String): smallint;
+var len: longint;
+begin
+  len:=string_to_vdi(filename, @_intin[0]);
+  _contrl[0]:=249;
+  _contrl[1]:=0;
+  _contrl[3]:=len;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  v_savecache:=_intout[0];
+end;
+
+function v_loadcache(handle: smallint; const filename: String; mode: smallint): smallint;
+var len: longint;
+begin
+  len:=string_to_vdi(filename, @_intin[1]);
+  _intin[0]:=mode;
+  _contrl[0]:=250;
+  _contrl[1]:=0;
+  _contrl[3]:=len+1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  v_loadcache:=_intout[0];
+end;
+
+function v_flushcache(handle: smallint): smallint;
+begin
+  _contrl[0]:=251;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  v_flushcache:=_intout[0];
+end;
+
+function vst_setsize(handle, point: smallint;
+                     out chwd, chht, cellwd, cellht: smallint): smallint;
+begin
+  _intin[0]:=point;
+  _contrl[0]:=252;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  chwd:=_ptsout[0];
+  chht:=_ptsout[1];
+  cellwd:=_ptsout[2];
+  cellht:=_ptsout[3];
+  vst_setsize:=_intout[0];
+end;
+
+function  vst_setsize32(handle: smallint; point: fix31;
+                        out chwd, chht, cellwd, cellht: smallint): fix31;
+begin
+  PLongint(@_intin[0])^:=point;
+  _contrl[0]:=252;
+  _contrl[1]:=0;
+  _contrl[3]:=2;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  chwd:=_ptsout[0];
+  chht:=_ptsout[1];
+  cellwd:=_ptsout[2];
+  cellht:=_ptsout[3];
+  vst_setsize32:=PLongint(@_intout[0])^;
+end;
+
+function vst_skew(handle, skew: smallint): smallint;
+begin
+  _intin[0]:=skew;
+  _contrl[0]:=253;
+  _contrl[1]:=0;
+  _contrl[3]:=1;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+  vst_skew:=_intout[0];
+end;
+
+procedure vqt_get_table(handle: smallint; out map: Pointer);
+begin
+  _contrl[0]:=254;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  map:=PPointer(@_intout[0])^;
+end;
+
+procedure vqt_cachesize(handle, which_cache: smallint; out size: LongInt);
+begin
+  _intin[0]:=which_cache;
+  _contrl[0]:=255;
+  _contrl[1]:=0;
+  _contrl[3]:=0;
+  _contrl[5]:=0;
+  _contrl[6]:=handle;
+
+  vdi;
+
+  size:=PLongint(@_intout[0])^;
+end;
+
+
+procedure v_set_app_buff(handle: smallint; address: Pointer; nparagraphs: smallint);
+begin
+  PPointer(@_intin[0])^:=address;
+  _intin[2]:=nparagraphs;
+  _contrl[0]:=-1;
+  _contrl[1]:=0;
+  _contrl[3]:=3;
+  _contrl[5]:=6;
   _contrl[6]:=handle;
 
   vdi;

+ 326 - 0
packages/tosunits/src/vditypes.inc

@@ -0,0 +1,326 @@
+
+{* return values for vq_vgdos() inquiry *}
+const
+    GDOS_NONE       = -2;           (* no GDOS installed           *)
+    GDOS_FSM        = $5F46534D;    (* '_FSM' - FSMGDOS installed  *)
+    GDOS_FNT        = $5F464E54;    (* '_FNT' - FONTGDOS installed *)
+    GDOS_ATARI      = $0007E88A;    (* GDOS 1.1 von Atari Corp.    *)
+    GDOS_AMC        = $0007E864;    (* AMCGDos von Arnd Beissner   *)
+    GDOS_AMCLIGHT   = $0007E8BA;    (* GEMINI-Spezial-GDos von Arnd Beissner *)
+    GDOS_NVDI       = $00000000;    (* NVDI von Bela GmbH *)
+    GDOS_TTF        = $3e5d0957;    (* TTF-GDOS *)
+
+const
+{* vst_alignment modes *}
+    TA_LEFT         = 0;
+    TA_CENTER       = 1;
+    TA_RIGHT        = 2;
+    TA_BASELINE     = 0;
+    TA_HALF         = 1;
+    TA_ASCENT       = 2;
+    TA_BOTTOM       = 3;
+    TA_DESCENT      = 4;
+    TA_TOP          = 5;
+
+{* gsx modes *}
+    MD_REPLACE      = 1;
+    MD_TRANS        = 2;
+    MD_XOR          = 3;
+    MD_ERASE        = 4;
+
+{$IFNDEF IP_HOLLOW_defined}
+{* patterns (also in AES) *}
+    IP_HOLLOW       = 0;
+    IP_1PATT        = 1;
+    IP_2PATT        = 2;
+    IP_3PATT        = 3;
+    IP_4PATT        = 4;
+    IP_5PATT        = 5;
+    IP_6PATT        = 6;
+    IP_SOLID        = 7;
+{$DEFINE IP_HOLLOW_defined}
+{$ENDIF}
+
+{* gsx styles *}
+    FIS_HOLLOW      = 0;
+    FIS_SOLID       = 1;
+    FIS_PATTERN     = 2;
+    FIS_HATCH       = 3;
+    FIS_USER        = 4;
+
+{* polymarker types *}
+    MT_DOT          = 1;
+    MT_PLUS         = 2;
+    MT_ASTERISK     = 3;
+    MT_SQUARE       = 4;
+    MT_DCROSS       = 5;
+    MT_DIAMOND      = 6;
+
+{* linetypes *}
+    LT_SOLID        = 1;
+    LT_LONGDASH     = 2;
+    LT_DOTTED       = 3;
+    LT_DASHDOT      = 4;
+    LT_DASHED       = 5;
+    LT_DASHDOTDOT   = 6;
+    LT_USERDEF      = 7;
+
+{* line ends *}
+    LE_SQUARED      = 0;
+    LE_ARROWED      = 1;
+    LE_ROUNDED      = 2;
+
+{* text effects *}
+    TF_NORMAL       = 0;
+    TF_THICKENED    = 1;
+    TF_LIGHTENED    = 2;
+    TF_SLANTED      = 4;
+    TF_UNDERLINED   = 8;
+    TF_OUTLINED     = 16;
+    TF_SHADOWED     = 32;
+
+{* bit blt rules *}
+    ALL_WHITE       = 0;
+    S_AND_D         = 1;
+    S_AND_NOTD      = 2;
+    S_ONLY          = 3;
+    NOTS_AND_D      = 4;
+    D_ONLY          = 5;
+    S_XOR_D         = 6;
+    S_OR_D          = 7;
+    NOT_SORD        = 8;
+    NOT_SXORD       = 9;
+    D_INVERT        = 10;
+    S_OR_NOTD       = 11;
+    NOT_D           = 12;
+    NOTS_OR_D       = 13;
+    NOT_SANDD       = 14;
+    ALL_BLACK       = 15;
+
+{* input mode *}
+    MODE_REQUEST    = 1;
+    MODE_SAMPLE     = 2;
+
+{* vqin_mode & vsin_mode modes *}
+    DEV_LOCATOR     = 1;
+    DEV_VALUATOR    = 2;
+    DEV_CHOICE      = 3;
+    DEV_STRING      = 4;
+
+{* v_bez modes *}
+    BEZ_BEZIER      = $01;
+    BEZ_POLYLINE    = $00;
+    BEZ_NODRAW      = $02;
+
+{* v_bit_image modes *}
+    IMAGE_LEFT      = 0;
+    IMAGE_CENTER    = 1;
+    IMAGE_RIGHT     = 2;
+    IMAGE_TOP       = 0;
+    IMAGE_BOTTOM    = 2;
+
+{* vq_color modes *}
+    COLOR_REQUESTED     = 0;
+    COLOR_ACTUAL        = 1;
+
+{* vst_charmap modes *}
+    MAP_BITSTREAM   = 0;
+    MAP_ATARI       = 1;
+    MAP_UNICODE     = 2; {* for vst_map_mode, NVDI 4 *}
+
+{* vst_kern tmodes *}
+    TRACK_NONE      = 0;
+    TRACK_NORMAL    = 1;
+    TRACK_TIGHT     = 2;
+    TRACK_VERYTIGHT = 3;
+
+{* vst_kern pmodes *}
+    PAIR_OFF        = 0;
+    PAIR_ON         = 1;
+
+{* vst_scratch modes *}
+    SCRATCH_BOTH        = 0;
+    SCRATCH_BITMAP      = 1;
+    SCRATCH_NONE        = 2;
+
+{* definitions for vs_mute *}
+    MUTE_RETURN     = -1;
+    MUTE_ENABLE      = 0;
+    MUTE_DISABLE     = 1;
+
+{* definitions for v_orient *}
+    OR_PORTRAIT      = 0;
+    OR_LANDSCAPE     = 1;
+
+{* definitions for v_tray *}
+    TRAY_MANUAL     = -1;
+    TRAY_DEFAULT     = 0;
+    TRAY_FIRSTOPT    = 1;
+
+{* definitions for v_xbit_image *}
+    XBIT_FRACT       = 0;
+    XBIT_INTEGER     = 1;
+
+    XBIT_LEFT        = 0;
+    XBIT_CENTER      = 1;
+    XBIT_RIGHT       = 2;
+
+    XBIT_TOP         = 0;
+    XBIT_MIDDLE      = 1;
+    XBIT_BOTTOM      = 2;
+
+
+type
+  PCOLOR_RGB = ^TCOLOR_RGB;
+  TCOLOR_RGB = record
+      reserved: word;     {* Set to 0 or the index of the entry *}
+      red: word;          {* Red:   0<->65535 *}
+      green: word;        {* Green: 0<->65535 *}
+      blue: word;         {* Blue:  0<->65535 *}
+  end;
+
+{$WARNING type TCOLOR_ENTRY is incomplete}
+type
+  TCOLOR_ENTRY = record
+    case byte of
+      0: ( rgb: TCOLOR_RGB; );
+      1: ( cymk: array[0..1] of longint; ); // dummy
+  end;
+
+type
+  PCOLOR_TAB = ^TCOLOR_TAB;
+  TCOLOR_TAB = record             {* Colour table                    *}
+      magic: array[0..3] of char; {* 'ctab'                          *}
+      length: longint;
+      format: longint;            {* Format (0)                      *}
+      reserved: longint;          {* Reserved, set to 0              *}
+      map_id: longint;            {* Colour table ID                 *}
+      color_space: longint;       {* Colour space (at present only
+                                     CSPACE_RGB)                     *}
+      flags: longint;             {* VDI-internal flags, set to 0    *}
+      no_colors: longint;         {* Number of colour entries        *}
+      reserved1: longint;         {* Reserved, must be 0             *}
+      reserved2: longint;         {* Reserved, must be 0             *}
+      reserved3: longint;         {* Reserved, must be 0             *}
+      reserved4: longint;         {* Reserved, must be 0             *}
+      colors: array[0..0] of TCOLOR_ENTRY; { repeated no_colors times }
+  end;
+
+type
+  PPOINT16 = ^TPOINT16;
+  TPOINT16 = record               {* Point for 16-bit coordinates *}
+      x: smallint;
+      y: smallint;
+  end;
+
+type
+  PPOINT32 = ^TPOINT32;
+  TPOINT32 = record               {* Point for 32-bit coordinates *}
+      x: longint;
+      y: longint;
+  end;
+
+type
+  PRECT16 = ^TRECT16;
+  TRECT16 = record                {* Rectangle for 16-bit coordinates *}
+      x1: smallint;
+      y1: smallint;
+      x2: smallint;
+      y2: smallint;
+  end;
+
+type
+  PRECT32 = ^TRECT32;
+  TRECT32 = record                {* Rectangle for 32-bit coordinates *}
+      x1: longint;
+      y1: longint;
+      x2: longint;
+      y2: longint;
+  end;
+
+type
+  PMFDB = ^TMFDB;
+  TMFDB = record
+      fd_addr: pointer;          {* Pointer to the start of the
+                                    memory block, e.g. the
+                                    screen memory base address  *}
+      fd_w: smallint;            {* Width in pixels             *}
+      fd_h: smallint;            {* Height in pixels            *}
+      fd_wdwidth: smallint;      {* Width of a line in words    *}
+      fd_stand: smallint;        {* 0 = Device-specific format  *}
+                                 {* 1 = Standard format         *}
+      fd_nplanes: smallint;      {* Number of planes            *}
+      fd_r1: smallint;           {* Reserved, must be 0         *}
+      fd_r2: smallint;           {* Reserved, must be 0         *}
+      fd_r3: smallint;           {* Reserved, must be 0         *}
+  end;
+
+type
+    String33    = String[33];
+    String80    = String[80];
+    String125   = String[125];
+
+type
+  PVDIContrl = ^TVDIContrl;
+  TVDIContrl = ARRAY[0..11] of smallint;
+
+  PVDIPtsIn  = ^TVDIPtsIn;
+  TVDIPtsIn  = array[0..1023] of smallint;
+
+  PVDIPtsOut = ^TVDIPtsOut;
+  TVDIPtsOut = array[0..255] of smallint;
+
+  PVDIIntIn  = ^TVDIIntIn;
+  TVDIIntIn  = array[0..1023] of smallint;
+
+  PVDIIntOut = ^TVDIIntOut;
+  TVDIIntOut = array[0..511] of smallint;
+
+type
+  PVDIPB = ^TVDIPB;
+  TVDIPB = record
+      control: PVDIContrl;       {* Pointer to contrl array *}
+      intin: PVDIIntIn;          {* Pointer to intin array  *}
+      ptsin: PVDIPtsIn;          {* Pointer to ptsin array  *}
+      intout: PVDIIntOut;        {* Pointer to intout array *}
+      ptsout: PVDIPtsOut;        {* Pointer to ptsout array *}
+  end;
+
+    PFONT_HDR = ^TFONT_HDR;
+    TFONT_HDR = record
+        font_id         : smallint;
+        point           : smallint;
+        name            : Array[0..31] of Char;
+        first_ade       : Word;
+        last_ade        : Word;
+        top             : Word;
+        ascent          : Word;
+        half            : Word;
+        descent         : Word;
+        bottom          : Word;
+        max_char_width  : Word;
+        max_cell_width  : Word;
+        left_offset     : Word;
+        right_offset    : Word;
+        thicken         : Word;
+        ul_size         : Word;
+        lighten         : Word;
+        skew            : Word;
+        flags           : Word;
+        hor_table       : Pointer;
+        off_table       : Pointer;
+        dat_table       : Pointer;
+        form_width      : Word;
+        form_height     : Word;
+        next_font       : PFONT_HDR;
+    end;
+
+type
+    fix31 = LongInt;
+    ARRAY_2     = ARRAY[0..1] of smallint;
+    ARRAY_3     = ARRAY[0..2] of smallint;
+    ARRAY_4     = ARRAY[0..3] of smallint;
+    ARRAY_5     = ARRAY[0..4] of smallint;
+    ARRAY_6     = ARRAY[0..5] of smallint;
+    ARRAY_10    = ARRAY[0..9] of smallint;
+    ARRAY_273   = ARRAY[0..272] of smallint;

Some files were not shown because too many files changed in this diff