#ifndef UPS_H
#define UPS_H
/*
**  $VER: ups.h 39.1 (05.07.95)
**
**  Structures and constants for Ultimate Patch System.
**
**  (C) Copyright 1994-1995 Glenz Points.
**      All Rights Reserved
*/

#ifndef EXEC_TYPES_H
#include <exec/types.h>
#endif

#ifndef EXEC_PORTS_H
#include <exec/ports.h>
#endif



/**
***  Version strcuture
**/

struct PVS {
  WORD        PVS_Version;              /// version word
  BYTE        PVS_Revision;             /// revision byte
  BYTE        PVS_User1;                ///
};




/**
***  Patcher file structure
**/

struct pfs {
  LONG        pfs_code[8];              /// 32 bytes of code
  LONG        pfs_ControlLong;          /// must be equal to ControlLong
  struct pfs *pfs_Next;                 /// pointer to next patcher
  struct pfs *pfs_Prev;                 /// pointer to prev patcher
  struct PVS  pfs_NeedVersion;          /// minimum version of UPS to start
  struct PVS  pfs_UsedVersion;          /// version of UPS which was used
                                        /// while patcher was developed
  APTR        pfs_PatcherName;          /// pointer to name of patcher
  struct PVS  pfs_Version;              /// version
  APTR        pfs_CoderName;            /// pointer to name of programmer
  APTR        pfs_VersionString;        /// pointer to $VER: string
  APTR        pfs_PatcherIDString;      /// listview entry
  LONG        pfs_Flags;                /// flags
  LONG        pfs_Status;               /// status of flags
  APTR        pfs_ExecBase;             /// exec base
  APTR        pfs_IntBase;              /// intuition base
  APTR        pfs_GadTBase;             /// gadtools base
  APTR        pfs_DosBase;              /// dos base
  APTR        pfs_GfxBase;              /// graphics base
  APTR        pfs_CxBase;               /// commodities base
  APTR        pfs_LayBase;              /// layers base
  APTR        pfs_UPSBase;              /// UPS lib base
  APTR        pfs_Init;                 /// pointer to init routine
  APTR        pfs_Exit;                 /// pointer to exit routine
  APTR        pfs_Prefs;                /// pointer to prefs routine
  APTR        pfs_PrefsKey;             /// pointer to cx keys to call
                                        /// prefs rout
  struct orl *pfs_ListPtr;              /// pointer to struct of requested
                                        /// opened resources
  struct mps *pfs_Patch;                /// pointer to struct for patches
  struct pls *pfs_pls;			/// pointer to pls structure
  APTR        pfs_UPSMsgPort;           /// pointer to main UPS msg port
  APTR        pfs_UPSRexxPort;          /// pointer to rexx port
  struct pxs *pfs_pxs;                  /// pointer to pxs structure
  BOOL       *pfs_fakesemaphore;        /// TRUE for UPS's setfunction
  LONG        pfs_User1;                ///
  LONG        pfs_User2;                ///
  LONG        pfs_ControlLong2;         /// ControlLong
  struct pfs *pfs_PFS;                  /// pointer to the beginning of struct
};


#define pfsControlLong  0x17061995
#define UPSMainVersion  39
#define UPSMainRevision 0
#define pfsPatcherStringLen   25
#define pfsPatchLinkStringLen 27
#define pfsPatcherStartupLen  31
#define pfsOffsetLen          26
#define pfsStartupCycleLen    29
#define pfsLibOverviewLen     38
#define pfsPMListviewLen      16
#define pfsOldNewLen           9
#define pfsPurposeLen         16
#define pfsLOPatcherStrLen    16


#define pfsDisableable  0x00000001      /// Enable disable patcher option
#define pfsPrefs        0x00000002      /// Prefs editor exists
#define pfsNoRemoveable 0x00000004      /// Disable Removing of Patcher


/**
***  Patcher Extended Structure
**/

struct pxs {
  LONG        pxs_CxID;                 /// Commodity hotkey id
  APTR        pxs_CxObjs;               /// Commodity object pointer
};


/**
***  Open resource List
**/

struct orl {
  struct orl *orl_Next;                 /// pointer to next entry
  struct orl *orl_Prev;                 /// pointer to previous entry
  LONG        orl_Type;                 /// type of resource
  LONG        orl_ID;                   /// resource id
  LONG        orl_Flags;                /// flags
  APTR        orl_Name;                 /// pointer to name of resource
  APTR        orl_Base;                 /// base of opened resource
  LONG        orl_Version;              /// version, if needed
  LONG        orl_DataRegs[8];          /// ...to put in data regs
  APTR        orl_Open;                 /// user open rout for user type
  APTR        orl_Close;                /// user close rout for user type
  APTR        orl_UTName;               /// pointer to name for user type
  LONG        orl_User1;                ///
  LONG        orl_User2;                ///
};

#define orlNoNecessary     0x00000001   /// dont care if not opened

#define rt_Library         1            /// resource type is library
#define rt_TrapVector      2            /// resource type is trap vector
#define rt_Device          3            /// resource type is device
#define rt_Handler         4            /// resource type is handler
#define rt_Resource        5            /// resource type is resource
#define rt_DataType        6            /// resource type is datatype
#define rt_User1        1024            /// User type. Needs user open/close
#define rt_User2        1025
#define rt_User3        1026
#define rt_User4        1027
#define rt_User5        1028
#define rt_User6        1029
#define rt_User7        1030
#define rt_User8        1031



/**
***  Main patch struct
**/

struct mps {
  struct mps *mps_Next;                 /// pointer to next patch
  struct mps *mps_Prev;                 /// pointer to prev patch
  LONG        mps_Pri;                  /// priority, less runs first
  struct pfs *mps_Patcher;              /// pointer to parent Patcher
  APTR        mps_PatchIDString;        /// listview entry
  APTR        mps_PurposeString;        /// pointer to purpose string
  LONG        mps_ID;                   /// id of resource to be patched
  LONG        mps_Flags;                /// flags
  LONG        mps_Status;               /// status of flags
  LONG        mps_Offset;               /// offset to change
  APTR        mps_New;                  /// pointer to new routine
  APTR        mps_Old;                  /// pointer to old routine
  struct pns *mps_pns;                  /// pointer to pns structure
  APTR        mps_NotifyDisable;        /// notified when enabled/disabled
  APTR        mps_Install;              /// install rout for user type
  APTR        mps_Remove;               /// uninstall rout for user type
  APTR        mps_Init;                 /// pointer to init routine
  APTR        mps_Exit;                 /// pointer to exit routine
  struct pls *mps_pls;                  /// pointer to pls structure
  LONG        mps_User1;                ///
  LONG        mps_User2;                ///
  LONG        mps_User3;                ///
  LONG        mps_User4;                ///
};


#define mpsIDStringLen  27

#define mpsDisableable  0x00000001      /// Enable disable patch option
#define mpsFullPatch    0x00000002      /// if full, don't call orig. patch
#define mpsDisTemp      0x00000004      /// While removed, previous status



/**
***  Patch node struct
**/

struct pns {
  WORD        pns_Jsr;                  /// jsr ($4eb9)
  APTR        pns_New;                  /// newrout
  WORD        pns_Jmp;                  /// jmp ($4ef9)
  struct pns *pns_Next;                 /// nextrout
  struct pns *pns_Prev;                 /// pointer to prev node
  LONG        pns_Pri;                  /// pri, less first
  APTR        pns_Orig;                 /// orginal routine
  struct mps *pns_Patch;                /// pointer to main patch
  struct pfs *pns_Patcher;              /// pointer to patcher
  LONG        pns_Mark;                 /// $fc263815
  struct pns *pns_pns;                  /// pointer to this structure
  LONG        pns_User1;                ///
  LONG        pns_User2;                ///
};



/**
***  UPS message
**/

struct um {
  struct Message
              um_Message;
  LONG        um_Command;               /// command to execute
  LONG        um_A0;                    /// adress register 0
  LONG        um_A1;                    /// adress register 1
  LONG        um_A2;                    /// adress register 2
  LONG        um_A3;                    /// adress register 3
  LONG        um_D0;                    /// data register 0
  LONG        um_D1;                    /// data register 1
  LONG        um_D2;                    /// data register 2
  LONG        um_D3;                    /// data register 3
};

#define umAllocUPS      0x00000001      /// Allocate UPS, in a0 ptr to
                                        /// app name
#define umFreeUPS       0x00000002      /// Free UPS, in a0 ptr to app
                                        /// name
#define umLoadPatcher   0x00000010      /// Initiate LoadPatcher routine
#define umAddPatcher    0x00000015      /// Load Patcher, in a0 ptr to
                                        /// filename, in d0 error code
#define umInstall       0x00000030      /// Install Patcher, in a0 ptr to
                                        /// patcher, in d0 error code
#define umRemove        0x00000031      /// Remove Patcher, in a0 ptr to
                                        /// patcher
#define umOpenResource  0x00000050      /// Open Resource, in a0 ptr to
                                        /// resource, in d0 return BOOL.
#define umCloseResource 0x00000051      /// Close Resource, in a0 ptr to
                                        /// resource
#define umInstallPatch  0x00000040      /// Install Patch, in a0 ptr to
                                        /// patch, in d0 error code
#define umRemovePatch   0x00000041      /// Remove Patch, in a0 ptr to
                                        /// patch
#define umEnablePatcher 0x00000035      /// Enable patcher in a0
#define umDisablePatcher 0x00000036     /// Disable patcher in a0
#define umEnablePLink   0x00000037      /// Enadle patch link in a0
#define umDisablePLink  0x00000038      /// Disable patch link in a0
#define umOpenMain      0x00000060      /// Open Main Window
#define umCloseMain     0x0000006f      /// Close Main Window
#define umOpenPM        0x00000061      /// Open Patcher Manager Window
#define umClosePM       0x0000006e      /// Close Patcher Man. Window
#define umOpenLO        0x00000062      /// Open Library Overview Window
#define umCloseLO       0x0000006d      /// Close Lib. Overview Window
#define umSpitRequester 0x00000070      /// Spit requester, with text in
                                        /// a0
#define umPrint         0x00000073      /// Print text line in a0
#define umPrefsPatcher  0x00000078      /// Call prefs from Patcher in a0
#define umPrefsPatchL   0x0000007a      /// Call prefs from PatchList in
                                        /// a0
#define umGetLibBase    0x00000008      /// Get base ptr from code in d0,
                                        /// result in a0
#define umGetPList      0x0000000a      /// Get PList ptr in a0, and
                                        /// PList itself in d0/d1/d2
#define umMakeEasyPatcher 0x0000001c    /// Make easy patcher with
                                        /// tagarray in a0. Pointer in
                                        /// a0, or null for error
#define umFreeEasyPatcher 0x0000001d    /// Remove easy patcher in a0.
#define umMakeEasyPatch 0x0000001e      /// Add Patch to easy patcher.
                                        /// Pointer to tagarray in a0,
                                        /// and parent patcher in a1.
                                        /// Pointer to patch in a0, null
                                        /// for error.
#define umFreeEasyPatch 0x0000001f      /// Remove east patch in a0.
#define umNoFree        0x80000000      /// Don't free memory after
                                        /// processing

#define umLibExec       0x00000001
#define umLibDOS        0x00000002
#define umLibIntuition  0x00000003
#define umLibGadTools   0x00000004
#define umLibUtility    0x00000005
#define umLibCommodities 0x0000006
#define umLibIcon       0x00000007
#define umLibReqTools   0x00000008
#define umLibLayers     0x00000009
#define umLibGraphics   0x0000000a
#define umLibWorkbench  0x0000000b

#define umTagNeedVer            0x80000001
#define umTagPatcherName        0x80000002
#define umTagCoderName          0x80000003
#define umTagPatcherIDString    0x80000004
#define umTagPatcherDisableable 0x80000005
#define umTagPatcherPrefs       0x80000006
#define umTagPatcherNoRemove    0x8000001b
#define umTagNeedVersion        0x80000007
#define umTagVersion            0x80000008
#define umTagInit               0x80000009
#define umTagExit               0x8000000a
#define umTagPrefs              0x8000000b
#define umTagPrefsKey           0x8000000c
#define umTagResourceType       0x8000000d
#define umTagResourceName       0x8000000e
#define umTagResourceVersion    0x8000000f
#define umTagResourceID         0x80000010
#define umTagPatchPri           0x80000011
#define umTagPatchPurposeString 0x80000012
#define umTagPatchIDString      0x80000013
#define umTagPatchOffset        0x80000014
#define umTagPatchDisableable   0x80000015
#define umTagPatchFullPatch     0x80000016
#define umTagPatch              0x80000017
#define umTagPatchNotifyDisable 0x80000018
#define umTagPatchInit          0x80000019
#define umTagPatchExit          0x8000001a      /// 1b is last


/**
***  Patchers list
**/

struct psl {
  struct MinNode
              node;                     /// simple node structure
  BPTR        psl_Segment;              /// BPTR to patcher segment
  struct pfs *psl_Patcher;              /// pointer to patcher structure
};


/**
***  Patch link structure
**/

struct pls {
  struct pls *pls_Next;                 /// pointer to next link
  struct pls *pls_Prev;                 /// pointer to prev link
  APTR        pls_LinkIDString;         /// listview string
  APTR        pls_Prefs;                /// pointer to prefs routine
  LONG        pls_Flags;                /// flags
  LONG        pls_Status;               /// status
  struct mps *pls_List[1000];           /// patches
}

#define plsPrefs       0x00000001
#define plsDisableable 0x00000002
#define plsDisTemp     0x00000004       /// While removed, previous status

#endif  /* UPS_H */

