--
--	helpers.occ: helper code for occplayer wrapper
--	Copyright (C) 2009 Adam Sampson <ats@offog.org>
--
--	This library is free software; you can redistribute it and/or
--	modify it under the terms of the GNU Lesser General Public
--	License as published by the Free Software Foundation, either
--	version 2 of the License, or (at your option) any later version.
--
--	This library is distributed in the hope that it will be useful,
--	but WITHOUT ANY WARRANTY; without even the implied warranty of
--	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
--	Lesser General Public License for more details.
--
--	You should have received a copy of the GNU Lesser General Public
--	License along with this library.  If not, see
--	<http://www.gnu.org/licenses/>.
--

--** @module occplayer

#INCLUDE "occplayer.inc"

--* NUL-terminate a string.
-- @private
PROC nul.terminate (VAL []BYTE in, RESULT MOBILE []BYTE out)
  SEQ
    out := MOBILE [(SIZE in) + 1]BYTE
    [out FOR SIZE in] := in
    out[SIZE in] := '*#00'
:

--* Set an integer-valued property.
-- (See [@ref playerc.simulation.set.property].)
PROC playerc.simulation.set.property.int (VAL playerc.simulation.t device, VAL []BYTE name, VAL []BYTE property, VAL INT value, RESULT INT return.value)
  MOBILE []BYTE name.m, property.m, value.m:
  SEQ
    nul.terminate (name, name.m)
    nul.terminate (property, property.m)
    value.m := MOBILE [BYTESIN (INT)]BYTE
    -- FIXME: This should be a RETYPES, but that crashes occ21.
    PLACED [1]INT value.mi AT ADDROF (value.m):
    value.mi[0] := value
    playerc.simulation.set.property (device, name.m, property.m, ADDROF (value.m), SIZE value.m, return.value)
:

--* Set a string-valued property.
-- (See [@ref playerc.simulation.set.property].)
PROC playerc.simulation.set.property.string (VAL playerc.simulation.t device, VAL []BYTE name, VAL []BYTE property, VAL []BYTE value, RESULT INT return.value)
  MOBILE []BYTE name.m, property.m, value.m:
  SEQ
    nul.terminate (name, name.m)
    nul.terminate (property, property.m)
    nul.terminate (value, value.m)
    playerc.simulation.set.property (device, name.m, property.m, ADDROF (value.m), SIZE value, return.value)
:
