•  Back 
  •  AES 
  •  Index 
  •  Tree View 
  •  Cross references 
  •  %About 
  •  Show info about hypertext 
  •  View a new file 
Topic       : The ATARI Compendium
Author      : Scott Sanders / JAY Software
Version     : 1.25 (20/6/2003)
Subject     : Documentation
Nodes       : 1117
Index Size  : 32614
HCP-Version : 6
Compiled on : Atari
@charset    : UTF-8
@lang       : en
@default    : 
@help       : %About
@options    : +g -i -t4 +y +z
@width      : 100
View Ref-File
                      AES  Function Calling Procedure


The GEM AES is accessed through a 680x0 TRAP #2 statement. Upon calling
the TRAP, register d0 should contain the magic number 0xC8 and register d1
should contain a pointer to the AES parameter block. The global data array
member of the parameter block is filled in with information about the AES
after an appl_init() call (see appl_init() for more details). The AES
parameter block is a structure containing pointers to several arrays
defined as follows:

struct aespb
{
    WORD *contrl;
    WORD *global;
    WORD *intin;
    WORD *intout;
    LONG *addrin;
    LONG *addrout;
};

The control array is filled in prior to an AES call with information
about the number of parameters the function is being passed, the number of
return values the function expects, and the opcode of the function itself
as follows:

contrl[x]  Contents

0          Function opcode.

1          Number of intin elements the function is being sent.

2          Number of intout elements the function is being sent.

3          Number of addrin elements the function returns.

4          Number of addrout elements the function returns.

The intin array and addrin arrays are used to pass integer and address
parameters respectively (consult each individual binding for details).
Upon return from the call, the intout and addrout arrays will be filled
in with any appropriate output values.

To add a binding for the AES to your compiler you will usually write
a short procedure that provides an interface to the AES arrays. The
following example illustrates the binding to graf_dragbox() in this
manner:

WORD
graf_dragbox( WORD width, WORD height, WORD start_x, WORD start_y,
              WORD box_x, WORD box_y, WORD box_w, WORD box_h,
              WORD *end_x, WORD *end_y )
{
    contrl[0] = 71;
    contrl[1] = 8;
    contrl[2] = 3;
    contrl[3] = 0;
    contrl[4] = 0;

    intin[0] = width;
    intin[1] = height;
    intin[2] = start_x;
    intin[3] = start_y;
    intin[4] = box_x;
    intin[5] = box_y;
    intin[6] = box_w;
    intin[7] = box_h;

    aes();

    *end_x = intout[1];
    *end_y = intout[2];

    return intout[0];
}

The following code is the assembly language function aes() used by the
function above:

            .globl      _aes

            .text
_aes:
            lea         _aespb,a0
            move.l      a0,d1
            move.w      #$C8,d0
            trap        #2
            lea         _intout,a0
            move.w      (a0),d0
            rts

            .data

_aespb:     .dc.l       _contrl, _global, _intin, _intout, _addrin, _addrout

            .bss

_contrl:    .ds.w       5
_global:    .ds.w      15
_intin:     .ds.w      16
_intout:    .ds.w       7
_addrin:    .ds.l       2
_addrout:   .ds.l       1

            .end

The bindings in the AES Function Reference call a specialized function
called crys_if() to actually call the AES. Many compilers use this method
as well (Lattice C calls the function _AESif() ).

crys_if() properly fills in the contrl array and calls the AES. It is
passed one WORD parameter in d0 which contains the opcode of the function
minus ten multiplied by four (for quicker table indexing). This gives an
index into a table from which the contrl array data may be loaded. The
crys_if() function is listed below:

* Note that this binding depends on the fact that no current AES call utilizes
* the addrout array

            .globl  _crys_if
            .globl  _aespb
            .globl  _contrl
            .globl  _global
            .globl  _intin
            .globl  _addrin
            .globl  _intout
            .globl  _addrout

            .text

_crys_if:
            lea     table(pc),a0    ; Table below
            move.l  0(a0,d0.w),d0   ; Load four packed bytes into d0
            lea     _aespb,a0       ; Load address of _aespb into a0
            movea.l (a0),a1         ; Move address of contrl into a1
            movep.l d0,1(a1)        ; Move four bytes into WORDs at 1(contrl)
            move.l  a0,d1           ; Move address of _aespb into d1
            move.w  #$C8,d0         ; AES magic number
            trap    #2              ; Call GEM
            lea     _intout,a0      ; Get return value
            move.w  (a0),d0         ; Put it into d0
            rts

* Table of AES opcode/control values
* Values are: opcode, intin, intout, addrin
* As stated before, addrout is left at 0 since no AES calls use it

table:
            .dc.b        10, 0, 1, 0        ; appl_init
            .dc.b        11, 2, 1, 1        ; appl_read
            .dc.b        12, 2, 1, 1        ; appl_write
            .dc.b        13, 0, 1, 1        ; appl_find
            .dc.b        14, 2, 1, 1        ; appl_tplay
            .dc.b        15, 1, 1, 1        ; appl_trecord
            .dc.b        16, 0, 0, 0        ;
            .dc.b        17, 0, 0, 0        ;
            .dc.b        18, 1, 1, 3        ; appl_search (v4.0)
            .dc.b        19, 0, 1, 0        ; appl_exit
            .dc.b        20, 0, 1, 0        ; evnt_keybd
            .dc.b        21, 3, 5, 0        ; evnt_button
            .dc.b        22, 5, 5, 0        ; evnt_mouse
            .dc.b        23, 0, 1, 1        ; evnt_mesag
            .dc.b        24, 2, 1, 0        ; evnt_timer
            .dc.b        25,16, 7, 1        ; evnt_multi
            .dc.b        26, 2, 1, 0        ; evnt_dclick
            .dc.b        27, 0, 0, 0        ;
            .dc.b        28, 0, 0, 0        ;
            .dc.b        29, 0, 0, 0        ;
            .dc.b        30, 1, 1, 1        ; menu_bar
            .dc.b        31, 2, 1, 1        ; menu_icheck
            .dc.b        32, 2, 1, 1        ; menu_ienable
            .dc.b        33, 2, 1, 1        ; menu_tnormal
            .dc.b        34, 1, 1, 2        ; menu_text
            .dc.b        35, 1, 1, 1        ; menu_register
            .dc.b        36, 2, 1, 2        ; menu_popup (v3.3)
            .dc.b        37, 2, 1, 2        ; menu_attach (v3.3)
            .dc.b        38, 3, 1, 1        ; menu_istart (v3.3)
            .dc.b        39, 1, 1, 1        ; menu_settings (v3.3)
            .dc.b        40, 2, 1, 1        ; objc_add
            .dc.b        41, 1, 1, 1        ; objc_delete
            .dc.b        42, 6, 1, 1        ; objc_draw
            .dc.b        43, 4, 1, 1        ; objc_find
            .dc.b        44, 1, 3, 1        ; objc_offset
            .dc.b        45, 2, 1, 1        ; objc_order
            .dc.b        46, 4, 2, 1        ; objc_edit
            .dc.b        47, 8, 1, 1        ; objc_change
            .dc.b        48, 4, 3, 0        ; objc_sysvar (v3.4)
            .dc.b        49, 0, 0, 0        ;
            .dc.b        50, 1, 1, 1        ; form_do
            .dc.b        51, 9, 1, 0        ; form_dial
            .dc.b        52, 1, 1, 1        ; form_alert
            .dc.b        53, 1, 1, 0        ; form_error
            .dc.b        54, 0, 5, 1        ; form_center
            .dc.b        55, 3, 3, 1        ; form_keybd
            .dc.b        56, 2, 2, 1        ; form_button
            .dc.b        57, 0, 0, 0        ;
            .dc.b        58, 0, 0, 0        ;
            .dc.b        59, 0, 0, 0        ;
            .dc.b        60, 0, 0, 0        ;
            .dc.b        61, 0, 0, 0        ;
            .dc.b        62, 0, 0, 0        ;
            .dc.b        63, 0, 0, 0        ;
            .dc.b        64, 0, 0, 0        ;
            .dc.b        65, 0, 0, 0        ;
            .dc.b        66, 0, 0, 0        ;
            .dc.b        67, 0, 0, 0        ;
            .dc.b        68, 0, 0, 0        ;
            .dc.b        69, 0, 0, 0        ;
            .dc.b        70, 4, 3, 0        ; graf_rubberbox
            .dc.b        71, 8, 3, 0        ; graf_dragbox
            .dc.b        72, 6, 1, 0        ; graf_movebox
            .dc.b        73, 8, 1, 0        ; graf_growbox
            .dc.b        74, 8, 1, 0        ; graf_shrinkbox
            .dc.b        75, 4, 1, 1        ; graf_watchbox
            .dc.b        76, 3, 1, 1        ; graf_slidebox
            .dc.b        77, 0, 5, 0        ; graf_handle
            .dc.b        78, 1, 1, 1        ; graf_mouse
            .dc.b        79, 0, 5, 0        ; graf_mkstate
            .dc.b        80, 0, 1, 1        ; scrp_read
            .dc.b        81, 0, 1, 1        ; scrp_write
            .dc.b        82, 0, 0, 0        ;
            .dc.b        83, 0, 0, 0        ;
            .dc.b        84, 0, 0, 0        ;
            .dc.b        85, 0, 0, 0        ;
            .dc.b        86, 0, 0, 0        ;
            .dc.b        87, 0, 0, 0        ;
            .dc.b        88, 0, 0, 0        ;
            .dc.b        89, 0, 0, 0        ;
            .dc.b        90, 0, 2, 2        ; fsel_input
            .dc.b        91, 0, 2, 3        ; fsel_exinput
            .dc.b        92, 0, 0, 0        ;
            .dc.b        93, 0, 0, 0        ;
            .dc.b        94, 0, 0, 0        ;
            .dc.b        95, 0, 0, 0        ;
            .dc.b        96, 0, 0, 0        ;
            .dc.b        97, 0, 0, 0        ;
            .dc.b        98, 0, 0, 0        ;
            .dc.b        99, 0, 0, 0        ;
            .dc.b       100, 5, 1, 0        ; wind_create
            .dc.b       101, 5, 1, 0        ; wind_open
            .dc.b       102, 1, 1, 0        ; wind_close
            .dc.b       103, 1, 1, 0        ; wind_delete
            .dc.b       104, 2, 5, 0        ; wind_get
            .dc.b       105, 6, 1, 0        ; wind_set
            .dc.b       106, 2, 1, 0        ; wind_find
            .dc.b       107, 1, 1, 0        ; wind_update
            .dc.b       108, 6, 5, 0        ; wind_calc
            .dc.b       109, 0, 1, 0        ; wind_new
            .dc.b       110, 0, 1, 1        ; rsrc_load
            .dc.b       111, 0, 1, 0        ; rsrc_free
            .dc.b       112, 2, 1, 0        ; rsrc_gaddr
            .dc.b       113, 2, 1, 1        ; rsrc_saddr
            .dc.b       114, 1, 1, 1        ; rsrc_obfix
            .dc.b       115, 0, 1, 1        ; rsrc_rcfix (v4.0)
            .dc.b       116, 0, 0, 0        ;
            .dc.b       117, 0, 0, 0        ;
            .dc.b       118, 0, 0, 0        ;
            .dc.b       119, 0, 0, 0        ;
            .dc.b       120, 0, 1, 2        ; shel_read
            .dc.b       121, 3, 1, 2        ; shel_write
            .dc.b       122, 1, 1, 1        ; shel_get
            .dc.b       123, 1, 1, 1        ; shel_put
            .dc.b       124, 0, 1, 1        ; shel_find
            .dc.b       125, 0, 1, 2        ; shel_envrn
            .dc.b       126, 0, 0, 0        ;
            .dc.b       127, 0, 0, 0        ;
            .dc.b       128, 0, 0, 0        ;
            .dc.b       129, 0, 0, 0        ;
            .dc.b       130, 1, 5, 0        ; appl_getinfo (v4.0)

            .data

_aespb:         .dc.l       _contrl, _global, _intin, _intout, _addrin, _addrout
_contrl:        .dc.l       0, 0, 0, 0, 0

            .bss

* _contrl = opcode
* _contrl+2 = num_intin
* _contrl+4 = num_addrin
* _contrl+6 = num_intout
* _contrl+8 = num_addrout

_global         .ds.w       15
_intin          .ds.w       16
_intout         .ds.w       7
_addrin         .ds.l       2
_addrout        .ds.l       1

            .end