(**************************************************************************

     $RCSfile: CardRes.mod $
  Description: Interface to card.resource

   Created by: fjc (Frank Copeland)
    $Revision: 3.1 $
      $Author: fjc $
        $Date: 1994/08/08 01:15:52 $

  Includes Release 40.15

  (C) Copyright 1990-1993 Commodore-Amiga, Inc.
      All Rights Reserved

  Oberon-A Interface Copyright © 1994, Frank Copeland.
  This file is part of the Oberon-A Interface.
  See Oberon-A.doc for conditions of use and distribution.

*************************************************************************)

MODULE CardRes;

(*
** $C- CaseChk       $I- IndexChk  $L+ LongAdr   $N- NilChk
** $P- PortableCode  $R- RangeChk  $S- StackChk  $T- TypeChk
** $V- OvflChk       $Z- ZeroVars
*)

IMPORT E := Exec, SYS := SYSTEM;

(*
**      $VER: card.h 1.11 (14.12.92)
**
**      card.resource include file
*)

CONST

  name * = "card.resource";

TYPE

(* Structures used by the card.resource                         *)

  CardHandlePtr * = CPOINTER TO CardHandle;
  CardHandle  * = RECORD (E.Node)
    removed *  : E.InterruptPtr;
    inserted * : E.InterruptPtr;
    status *   : E.InterruptPtr;
    flags *    : E.BSET;
  END;

  DeviceTDataPtr * = CPOINTER TO DeviceTData;
  DeviceTData  * = RECORD
    size *  : E.ULONG;       (* Size in bytes                *)
    speed * : E.ULONG;       (* Speed in nanoseconds         *)
    type *  : E.UBYTE;       (* Type of card                 *)
    flags * : E.BSET;        (* Other flags                  *)
  END;

  CardMemoryMapPtr * = CPOINTER TO CardMemoryMap;
  CardMemoryMap  * = RECORD
    commonMemory *    : E.APTR;
    attributeMemory * : E.APTR;
    ioMemory *        : E.APTR;

(* Extended for V39 - These are the size of the memory spaces above *)

    commonMemSize *    : E.ULONG;
    attributeMemSize * : E.ULONG;
    ioMemSize *        : E.ULONG;

  END;

CONST

(* CardHandle.cah_CardFlags for OwnCard() function              *)

  resetRemove * = 0;

  ifAvailable * = 1;

  delayOwnership * = 2;

  postStatus * = 3;

(* ReleaseCreditCard() function flags                           *)

  removeHandle * = 0;

(* ReadStatus() return flags                                    *)

  statusCCDET * = 6;

  statusBVD1 * = 5;

  statusSC * = 5;

  statusBVD2 * = 4;

  statusDA * = 4;

  statusWR * = 3;

  statusBSY * = 2;

  statusIRQ * = 2;

(* CardProgramVoltage() defines *)

  voltage0V * = 0;                 (* Set to default; may be the same as 5V *)
  voltage5V * = 1;
  voltage12V * = 2;

(* CardMiscControl() defines *)

  enableDigAudio * = 1;

  disableWP * = 3;

(*
 * New CardMiscControl() bits for V39 card.resource.  Use these bits to set,
 * or clear status change interrupts for BVD1/SC, BVD2/DA, and BSY/IRQ.
 * Write-enable/protect change interrupts are always enabled.  The defaults
 * are unchanged (BVD1/SC is enabled, BVD2/DA is disabled, and BSY/IRQ is enabled).
 *
 * IMPORTANT -- Only set these bits for V39 card.resource or greater (check
 * resource base VERSION)
 *
 *)

  intSetClr * = 7;

  intBVD1 * = 5;

  intSC * = 5;

  intBVD2 * = 4;

  intDA * = 4;

  intBSY * = 2;

  intIRQ * = 2;


(* CardInterface() defines *)

  interfaceAmiga0 * = 0;

(*
 * Tuple for Amiga execute-in-place software (e.g., games, or other
 * such software which wants to use execute-in-place software stored
 * on a credit-card, such as a ROM card).
 *
 * See documentatin for IfAmigaXIP().
 *)

  cistplAmigaXip * = 091H;

TYPE

  TPAmigaXIPPtr * = CPOINTER TO TPAmigaXIP;
  TPAmigaXIP  * = RECORD
    code *  : E.UBYTE;
    link *  : E.UBYTE;
    loc *   : ARRAY 4 OF E.UBYTE;
    flags * : E.BSET;
    resrv * : E.UBYTE;
  END;

CONST

(*

        ; The XIPFLAGB_AUTORUN bit means that you want the machine
        ; to perform a reset if the execute-in-place card is inserted
        ; after DOS has been started.  The machine will then reset,
        ; and execute your execute-in-place code the next time around.
        ;
        ; NOTE -- this flag may be ignored on some machines, in which
        ; case the user will have to manually reset the machine in the
        ; usual way.

*)

  xipFlagsAutoRun * = 0;

(**-- Library Base variable --------------------------------------------*)

TYPE

  CardResBasePtr* = CPOINTER TO CardResBase;
  CardResBase* = RECORD END;

VAR

  base* : CardResBasePtr;


(**-- Library Functions ------------------------------------------------*)

(*
**      $VER: cardres_protos.h 1.2 (8.9.92)
*)

LIBCALL (base : CardResBasePtr) OwnCard *
  ( handle [9] : CardHandlePtr )
  : CardHandlePtr;
  -6;
LIBCALL (base : CardResBasePtr) ReleaseCard *
  ( handle [9] : CardHandlePtr;
    flags  [0] : E.ULONG );
  -12;
LIBCALL (base : CardResBasePtr) GetCardMap * ()
  : CardMemoryMapPtr;
  -18;
LIBCALL (base : CardResBasePtr) BeginCardAccess *
  ( handle [9] : CardHandlePtr )
  : BOOLEAN;
  -24;
LIBCALL (base : CardResBasePtr) EndCardAccess *
  ( handle [9] : CardHandlePtr )
  : BOOLEAN;
  -30;
LIBCALL (base : CardResBasePtr) ReadCardStatus * ()
  : E.UBYTE;
  -36;
LIBCALL (base : CardResBasePtr) CardResetRemove *
  ( handle [9] : CardHandlePtr;
    flag   [0] : E.ULONG )
  : BOOLEAN;
  -42;
LIBCALL (base : CardResBasePtr) CardMiscControl *
  ( handle      [9] : CardHandlePtr;
    controlBits [1] : E.BSET )
  : E.BSET;
  -48;
LIBCALL (base : CardResBasePtr) CardAccessSpeed *
  ( handle      [9] : CardHandlePtr;
    nanoseconds [0] : E.ULONG )
  : E.ULONG;
  -54;
LIBCALL (base : CardResBasePtr) CardProgramVoltage *
  ( handle  [9] : CardHandlePtr;
    voltage [0] : E.ULONG )
  : LONGINT;
  -60;
LIBCALL (base : CardResBasePtr) CardResetCard *
  ( handle [9] : CardHandlePtr )
  : BOOLEAN;
  -66;
LIBCALL (base : CardResBasePtr) CopyTuple *
  ( handle    [9] : CardHandlePtr;
    buffer    [8] : ARRAY OF SYS.BYTE;
    tuplecode [1] : E.ULONG;
    size      [0] : E.ULONG )
  : BOOLEAN;
  -72;
LIBCALL (base : CardResBasePtr) DeviceTuple *
  ( tupleData [8] : E.APTR;
    storage   [9] : DeviceTDataPtr )
  : E.ULONG;
  -78;
LIBCALL (base : CardResBasePtr) IfAmigaXIP *
  ( handle [10] : CardHandlePtr )
  : E.ResidentPtr;
  -84;
LIBCALL (base : CardResBasePtr) CardForceChange * ()
  : BOOLEAN;
  -90;
LIBCALL (base : CardResBasePtr) CardChangeCount * ()
  : E.ULONG;
  -96;
LIBCALL (base : CardResBasePtr) CardInterface * ()
  : E.ULONG;
  -102;

(**-- Library Base variable --------------------------------------------*)

(**-----------------------------------*)
PROCEDURE OpenResource * (mustOpen : BOOLEAN);

BEGIN (* OpenResource *)
  IF base = NIL THEN
    base := SYS.VAL (CardResBasePtr, E.base.OpenResource (name));
    IF mustOpen & (base = NIL) THEN HALT (100) END
  END
END OpenResource;

BEGIN
  base := NIL
END CardRes.
