•  Back 
  •  MagiC PC interface 
  •  Index 
  •  Tree View 
  •  Cross references 
  •  Help page 
  •  Show info about hypertext 
  •  View a new file 
Topic       : TOS - The Operating System
Author      : 
Version     : tos.hyp (December 19, 2008)
Subject     : Programmieren/Atari
Nodes       : 3010
Index Size  : 93790
HCP-Version : 5
Compiled on : Atari
@charset    : atarist
@lang       : 
@default    : Title
@help       : 
@options    : +g -i -s +x +zz -t4
@width      : 70
View Ref-File12.2.1  mec0 (MPS) interface                                       TOS

0. General remarks

MPS = Magic_Programmier_Schnittstelle = MagiC programmer's interface

Files of the demo example:

 mps_base.def   The export list of the DLL, DO NOT ALTER!
 mps_base.h     Definition of the MPS interface, DO NOT ALTER!
 mps_base.cpp   Basic functions of the DLL, DO NOT ALTER!
 mps_demo.h     Definitions for the demo-DLL
 mps_demo.cpp   The MPS_functions of the demo-DLL
 testmps.s      Motorola - Example for calling the MPS functions of 
                the demo

To develop your own MPS_DLLs, please use mps_base.def, mps_base.h and 
mps_base.cpp unaltered. You can alter/supplement mps_demo.h and 
mps_demo.cpp. In particular, please choose your own DLL_ID in 
mps_demo.h for differentiation from other MPS_DLLs.

I. Concept

Windows-side one can use dynamic link libraries (DLLs) to establish 
any number of functions (called 'MPS_functions' in the following) 
which can be called within MagiC PC (Motorola-side).

In the start-up phase MagiC PC attempts to load and start all DLLs in 
the MPS subdirectory. For this MagiC PC calls three functions to be 
exported from the DLL (in this order):

  1. mps_get_type(): Must return 0x4701!

  2. mps_get_functionlist(...): Obtains DLL_ID and MPS_functions list 
     of the DLL.

  3. mps_magicinfo: Provides information about MagiC PC's own data and 
     functions which the DLL may use on demand.

All functions declared in 2) can be called via special opcodes on the 
Motorola side. See part IV for more about the call.

II. Functions of the DLL to be exported ('Basic functions')

An MPS_DLL must export exactly 3 C functions under fixed ordinal 
numbers (these are also called basic functions): (see mfp_base.def, 
mfp_base.cpp, mfp_base.h)

   . @101: int mps_get_type()

     Purpose: Serves for reassurance that it was really MPS_DLL that 
     was caught. !! Return value: 0x4701 !!

   . @102: int mps_get_functionlist(DWORD *mps_dll_id,MPS_fuptr 
     **p_funktionsliste);

     Purpose: MagiC PC wants to know DLL_ID and MPS_functionlist.

     Return values:
     *mps_ddl_id: DLL_ID (4 bytes, to be selected DLL-specifically!)
     *p_functionslist: Pointer to list of the MPS_functions.
     Return: 1: All OK

   . @103: void mps_magicinfo(MPS_magicinfo *is);

     Purpose: Provides information about MagiC PC's own info / 
     function pointers which the DLL may use:

             typedef struct {
              DWORD sizeof_str;               // Size of MPS_magicinfo
              DWORD magic_version;            // e.g. 0x010001
              DWORD magic_date;               // e.g. 19960815  (ascending)
              BYTE  is_demo;                  // Is it a demo version?
              BYTE  uu1, uu2, uu3;            // Still unused, 0
 
              BYTE *(*intel_adr)(DWORD motadr);   // Convert address Motorola -> Intel
              BYTE *(*intel_ptr)(DWORD motptr);   // Convert pointer Motorola -> Intel (NULL stays NULL!)
 
              WORD (*swap_word)(WORD w);      // Swap one WORD
              DWORD (*swap_long)(DWORD dw);   // Swap one LONGword
              } MPS_magicinfo;

     The address conversions return NULL if motadr or motptr is 
     invalid.

III. The freely definable MPS_functions of a DLL:

MPS_functions basically have the form:

void function_blabla( MPS_motregs *motregs )

motregs here points to a list of the Motorola registers d0-a7. The 
contents of the registers is already in the correct Intel byte order. 
The Motorola registers may also have new values written to them.

With mps_get_functionlist the DLL passes the list of addresses of all 
such MPS_functions. The function numbers correspond to the position of 
the function within the list. If a number is to remain free, then its 
address is passed as 0xffffffff (= -1). See also mps_demo.cpp.

IV. Motorola-side call

MPS_functions are called by a Motorola-side 8-byte opcode:

    dc.w    $4fbf       * 2 bytes: Do not alter!
    dc.l    DLL_ID      * 4 bytes: DLL-specific DLL_ID
    dc.w    Fkt_no.     * 2 bytes: Function number

DLL_ID is the DLL_ID (4 bytes!) passed via mps_get_functionlist. 
Function number is the position of the function in the function list 
passed by mps_get_functionlist (count starts at 0).

V. Miscellaneous

  1. Each DLL should use an individual DLL_ID to prevent conflicts 
     between multiple DLLs (see mps_demo.h). DLL_IDs with bit 31 set 
     are reserved for us (Application Systems) or for allocated IDs. 
     Therefore please do not choose a DLL_ID with set bit 31! If we 
     are to allocate a reserved DLL_ID to you, please get in touch 
     with Herr Hoffmann of Application Systems Heidelberg.

     The following DLL_IDs have been allocated:

      DLL_ID      Program name              Author 
      0x003f5c66  MPCTime                   Robert Weiß 
      0x2053434B  MPCSTiK                   Dan Ackerman 
      0x21342812  Draconis Windows Sockets 
      0x44594a01  In2Cat                    Dimitri Junker 
      0x44594a02  Win_Lnk                   Dimitri Junker 
      0x50475752  MPC_POWR                  Emanuel Welter 

  2. Pay attention to the displacement of the address space!! If you 
     want to use a Motorola address on the DLL side, you should call 
     intel_adr(..) or intel_ptr(..) respectively for conversion (see 
     MPS_magicinfo in mps_base.h). Addresses from the DLL address 
     space can not be used Motorola-side!

  3. Also pay attention to the different byte order between Motorola 
     and Intel processors. WORDs and LONGwords from the Motorola 
     address space have to be swapped so that they lie correctly in 
     the DLL. If anything is written back then it has to be swapped 
     once more. For this you can call the functions swap_word(..) or 
     swap_long(..) (see MPS_magicinfo in mps_base.h). BUT: Elements of 
     MPS_motregs (d0-a7) are already in the Intel order and do not 
     have to be swapped.