//Pascal &or the FreePascal use of nintendo 2ds, 3ds regime
//
// Copyright (c) 2013, 2015, 2017 Kenneth Dwayne Lee Bsc.
// all rights reserved
//

  type

     bossContext = record
          _property : array[0..6] of u32;
          url : array[0..511] of cchar;
          property_x8 : u32;
          property_x9 : u8;
          property_xa : array[0..255] of u8;
          property_xb : array[0..511] of u8;
          property_xd : array[0..863] of cchar;
          property_xe : u32;
          property_xf : array[0..($c shr 2)-1] of u32;
          property_x10 : u8;
          property_x11 : u8;
          property_x12 : u8;
          property_x13 : u32;
          property_x14 : u32;
          property_x15 : array[0..63] of u8;
          property_x16 : u32;
          property_x3b : u32;
          property_x3e : array[0..511] of u8;
       end;
  PbossContext  = ^bossContext;

  {/ BOSS task status. }
     bossTaskStatus = (BOSSTASKSTATUS_STARTED := $2,BOSSTASKSTATUS_ERROR := $7
       );
  {/ Type values for bossGetNsDataHeaderInfo(). }
  {/ Size of the content. }

     bossNsDataHeaderInfoTypes = (bossNsDataHeaderInfoType_ContentSize := $3
       );
  {/ Size of the output data for bossGetNsDataHeaderInfo(). }
  {/Type2 }

     bossNsDataHeaderInfoTypeSizes = (bossNsDataHeaderInfoTypeSize_ContentSize := $4
       );
  {*
   * @brief Initializes BOSS.
   * @param programID programID to use, 0 for the current process. Only used when BOSSP is available without *hax payload.
   * @param force_user When true, just use bossU instead of trying to initialize with bossP first.
    }

  function bossInit(programID:u64; force_user:bool):s32;cdecl;external;

  {*
   * @brief Run the InitializeSession service cmd. This is mainly for changing the programID associated with the current BOSS session.
   * @param programID programID to use, 0 for the current process.
    }
  function bossReinit(programID:u64):s32;cdecl;external;

  {/ Exits BOSS. }
  procedure bossExit;cdecl;external;

  {/ Returns the BOSS session handle. }
  function bossGetSessionHandle:Handle;cdecl;external;

  {*
   * @brief Set the content data storage location.
   * @param extdataID u64 extdataID, must have the high word set to the shared-extdata value when it's for NAND.
   * @param boss_size Probably the max size in the extdata which BOSS can use.
   * @param mediaType Roughly the same as FS mediatype.
    }
  function bossSetStorageInfo(extdataID:u64; boss_size:u32; mediaType:u8):s32;cdecl;external;

  {*
   * @brief Unregister the content data storage location, which includes unregistering the BOSS-session programID with BOSS.
    }
  function bossUnregisterStorage:s32;cdecl;external;

  {*
   * @brief Register a task.
   * @param taskID BOSS taskID.
   * @param unk0 Unknown, usually zero.
   * @param unk1 Unknown, usually zero.
    }

  function bossRegisterTask(taskID:pcchar; unk0:u8; unk1:u8):s32;cdecl;external;

  {*
   * @brief Send a property.
   * @param PropertyID PropertyID
   * @param buf Input buffer data.
   * @param size Buffer size.
    }
(* Const before type ignored *)
  function bossSendProperty(PropertyID:u16; buf:pointer; size:u32):s32;cdecl;external;

  {*
   * @brief Deletes the content file for the specified NsDataId.
   * @param NsDataId NsDataId
    }
  function bossDeleteNsData(NsDataId:u32):s32;cdecl;external;

  {*
   * @brief Gets header info for the specified NsDataId.
   * @param NsDataId NsDataId
   * @param type Type of data to load.
   * @param buffer Output buffer.
   * @param size Output buffer size.
    }
  function bossGetNsDataHeaderInfo(NsDataId:u32; _type:u8; buffer:pointer; size:u32):s32;cdecl;external;

  {*
   * @brief Reads data from the content for the specified NsDataId.
   * @param NsDataId NsDataId
   * @param offset Offset in the content.
   * @param buffer Output buffer.
   * @param size Output buffer size.
   * @param transfer_total Optional output actual read size, can be NULL.
   * @param unk_out Optional unknown output, can be NULL.
    }
  function bossReadNsData(NsDataId:u32; offset:u64; buffer:pointer; size:u32; transfer_total:Pu32; 
             unk_out:Pu32):s32;cdecl;external;

  {*
   * @brief Starts a task soon after running this command.
   * @param taskID BOSS taskID.
    }
  function bossStartTaskImmediate(taskID:pcchar):s32;cdecl;external;

  {*
   * @brief Similar to bossStartTaskImmediate?
   * @param taskID BOSS taskID.
    }
  function bossStartBgImmediate(taskID:pcchar):s32;cdecl;external;

  {*
   * @brief Deletes a task by using CancelTask and UnregisterTask internally.
   * @param taskID BOSS taskID.
   * @param unk Unknown, usually zero?
    }
  function bossDeleteTask(taskID:pcchar; unk:u32):s32;cdecl;external;

  {*
   * @brief Returns task state.
   * @param taskID BOSS taskID.
   * @param inval Unknown, normally 0?
   * @param status Output status, see bossTaskStatus.
   * @param out1 Output field.
   * @param out2 Output field.
    }
  function bossGetTaskState(taskID:pcchar; inval:s8; status:Pu8; out1:Pu32; out2:Pu8):s32;cdecl;external;

  {*
   * @brief This loads the current state of PropertyID 0x0 for the specified task.
   * @param taskID BOSS taskID.
    }
  function bossGetTaskProperty0(taskID:pcchar; BOSStask:Pu8):s32;cdecl;external;

  {*
   * @brief Setup a BOSS context with the default config.
   * @param bossContext BOSS context.
   * @param seconds_interval Interval in seconds for running the task automatically.
   * @param url Task URL.
    }
  procedure bossSetupContextDefault(ctx:PbossContext; seconds_interval:u32; url:pcchar);cdecl;external;

  {*
   * @brief Sends the config stored in the context. Used before registering a task.
   * @param bossContext BOSS context.
    }
  function bossSendContextConfig(ctx:PbossContext):s32;cdecl;external;