; ***************************************************************************
; copyright   : (C) 2026 by Martin Preuss
; email       : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome".                              *
; * Please see toplevel file COPYING of that project for license details.   *
; ***************************************************************************

#ifndef AQH_AVR_NETWORK_MSG_VALUE_R_ASM
#define AQH_AVR_NETWORK_MSG_VALUE_R_ASM


; ***************************************************************************
; code

.cseg


; ---------------------------------------------------------------------------
; @routine NETMSG_ValueRead @global
; Read a VALUE message.
;
; @param  X       buffer to read from
; @return R17     value id
; @return R19:R18 value
; @return R21:R20 denom (e.g. 100, meaning value must be divided by 100)
; @return R22     source address
; @return R23     command
; @return R25:R24 message id

NETMSG_ValueRead:
  adiw xh:xl, 2  ; skip DEST, LEN     0
  ld r23, X+     ; command            2
  ld r22, X+     ; src address        3
  adiw xh:xl, 4  ; skip uid           4   ( 0)
  ld r24, X+     ; msg id (low)       8   ( 4)
  ld r25, X+     ; msg id (high)      9   ( 5)
  ld r17, X+     ; value id          10   ( 6)
  adiw xh:xl, 1  ; skip value type   11   ( 7)
  ld r18, X+     ; value (low)       12   ( 8)
  ld r19, X+     ; value (high)      13   ( 9)
  ld r20, X+     ; denom (low)       14   (10)
  ld r21, X+     ; denom (high)      15   (11)
  sbiw xh:xl, 16 ; back to msg begin 16   (12)
  ret
; @end



#endif

