; ***************************************************************************
; 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_GUI_WLIST_ELEM_ASM
#define AQH_AVR_GUI_WLIST_ELEM_ASM



; ***************************************************************************
; defines

.equ WLIST_ELEM_OFFS_BEGIN      =  LIST_SIZE
.equ WLIST_ELEM_OFFS_IMGRES_LO  =  WLIST_ELEM_OFFS_BEGIN+0
.equ WLIST_ELEM_OFFS_IMGRES_HI  =  WLIST_ELEM_OFFS_BEGIN+1
.equ WLIST_ELEM_OFFS_TXTRES_LO  =  WLIST_ELEM_OFFS_BEGIN+2
.equ WLIST_ELEM_OFFS_TXTRES_HI  =  WLIST_ELEM_OFFS_BEGIN+3
.equ WLIST_ELEM_OFFS_USER_LO    =  WLIST_ELEM_OFFS_BEGIN+4
.equ WLIST_ELEM_OFFS_USER_HI    =  WLIST_ELEM_OFFS_BEGIN+5
.equ WLIST_ELEM_OFFS_HEIGHT_LO  =  WLIST_ELEM_OFFS_BEGIN+6
.equ WLIST_ELEM_OFFS_HEIGHT_HI  =  WLIST_ELEM_OFFS_BEGIN+7
.equ WLIST_ELEM_SIZE            =  WLIST_ELEM_OFFS_BEGIN+8




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

.cseg



; ---------------------------------------------------------------------------
; @routine WidgetListElem_new @global
;
; @return Y address of created object

WidgetListElem_new:
  ldi r24, LOW(WLIST_ELEM_SIZE)
  ldi r25, HIGH(WLIST_ELEM_SIZE)
  bigcall Heap_AllocAndZero
  brcc WidgetListElem_new_ret
  mov yl, xl
  mov yh, xh
  bigcall List_InitObject          ; (r16)
  sec
  ret
WidgetListElem_new_ret:
  ret
; @end



; ---------------------------------------------------------------------------
; @routine WidgetListElem_free @global
;
; @param Y address of object
; @clobbers r16, r17, r24, r25, X

WidgetListElem_free:
  tst yl
  brne WidgetListElem_free_notNull
  tst yh
  brne WidgetListElem_free_notNull
  rjmp WidgetListElem_free_ret
WidgetListElem_free_notNull:
  bigcall List_FiniObject           ; (r16)
  mov xl, yl
  mov xh, yh
  bigcall Heap_Free                 ; (r16, r17, r24, r25, X)
WidgetListElem_free_ret:
  ret
; @end






#endif
