Files
aqhomecontrol/avr/common/ressource.asm
2025-12-15 21:12:51 +01:00

65 lines
1.8 KiB
NASM

; ***************************************************************************
; copyright : (C) 2025 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_COMMON_RESSOURCE_H
#define AQH_AVR_COMMON_RESSOURCE_H
; ***************************************************************************
; defs
; ***************************************************************************
; code
.cseg
; ---------------------------------------------------------------------------
; @routine RES_GetRessource
;
; The Ressource table has one entry for every ressource handled by this table.
; The first entry contains the number of ressource entries in the table.
; All following entries contain byte pointer addresses (for LPM) to ressources.
; Ressource ids start with zero.
;
; @param r17:r16 ressource id (starting with 0)
; @param Z pointer to start of ressources in FLASH (byte address)
; @return CF set if ressource found, cleared otherwise
; @return Z if CF set: pointer to ressource (byte address)
; @clobbers r16, r17, r18
RES_GetRessource:
lpm r18, Z+ ; first entry: number of entries in table
cp r16, r18 ; id must be < num entries
lpm r18, Z+ ; Z points to first entry now
cpc r17, r18
brcc RES_GetRessource_ret
RES_GetRessource_getRessource:
lsl r16 ; byte address, so we need to add ressource id twice (i.e. *2)
rol r17
add zl, r16
add zh, r17
lpm r16, Z+
lpm r17, Z+
mov zl, r16
mov zh, r17
sec
RES_GetRessource_ret:
ret
; @end
#endif