Files
aqhomecontrol/avr/modules/lcd2/font/main.asm
2025-06-02 21:13:44 +02:00

168 lines
3.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. *
; ***************************************************************************
; ***************************************************************************
; code
.cseg
; ---------------------------------------------------------------------------
; @routine FONT_RenderChar
; @param R16 character to write
; @param R1:R0 background color
; @param R3:R2 foreground color
; @param Z pointer to font
; @param X pointer to RAM to store data to
; @param r18 char width in pixel
; @param r19 char height in pixel
; @clobbers any, !Z
FONT_RenderChar:
ldi r23, FONT_FN_RENDER
rjmp fontCallHandler
; @end
; ---------------------------------------------------------------------------
; @routine FONT_GetCharWidth
; @param Z pointer to font
; @return R16 character width for given character set
; @clobbers any, !Z
FONT_GetCharWidth:
ldi r23, FONT_FN_GETCHARWIDTH
rjmp fontCallHandler
; @end
; ---------------------------------------------------------------------------
; @routine FONT_GetCharHeight
; @param Z pointer to font
; @return R16 character height for given character set
; @clobbers any, !Z
FONT_GetCharHeight:
ldi r23, FONT_FN_GETCHARHEIGHT
rjmp fontCallHandler
; @end
; ---------------------------------------------------------------------------
; @routine FONT_GetStringWidth
; @param Z pointer to font
; @param X pointer to null-terminated string in flash
; @return R16 character width for given character set
; @clobbers any, !Z
FONT_GetStringWidthFlash:
ldi r23, FONT_FN_GETSTRINGWIDTH
rjmp fontCallHandler
; @end
; ---------------------------------------------------------------------------
; @routine FONT_GetStringHeight
; @param Z pointer to font
; @param X pointer to null-terminated string in flash
; @return R16 character width for given character set
; @clobbers any, !Z
FONT_GetStringHeight:
ldi r23, FONT_FN_GETSTRINGHEIGHT
rjmp fontCallHandler
; @end
; ---------------------------------------------------------------------------
; @routine fontCallHandler
;
; @param r23 function number
; @param Z pointer to font
fontCallHandler:
lpm r17, Z+
push r17
lpm r17, Z
push r17
sbiw zh:zl, 1
ret
; @end
; ---------------------------------------------------------------------------
; @routine FONT_GenericHandler
;
; Generic handler for font functions.
; @param R23 function to call (see @ref FONT_FN_RENDER et al)
FONT_GenericHandler:
cpi r23, FONT_FN_GETCHARWIDTH
breq fontGenericFnGetCharWidth
cpi r23, FONT_FN_GETCHARHEIGHT
breq fontGenericFnGetCharHeight
cpi r23, FONT_FN_GETSTRINGWIDTH
breq fontGenericFnGetStringWidth
cpi r23, FONT_FN_GETSTRINGHEIGHT
breq fontGenericFnGetStringHeight
ret
fontGenericFnGetCharWidth:
adiw zh:zl, FONT_OFFS_WIDTH
ld r16, X
sbiw zh:zl, FONT_OFFS_WIDTH
ret
fontGenericFnGetCharHeight:
adiw zh:zl, FONT_OFFS_HEIGHT
ld r16, X
sbiw zh:zl, FONT_OFFS_HEIGHT
ret
fontGenericFnGetStringWidth:
adiw zh:zl, FONT_OFFS_WIDTH
ld r17, X
sbiw zh:zl, FONT_OFFS_WIDTH
clr r16
push zl
push zh
mov zl, xl
mov zh, xh
fontGenericFnGetStringWidth_loop:
lpm r18, Z+
tst r18
breq fontGenericFnGetStringWidth_loopEnd
add r16, r17
rjmp fontGenericFnGetStringWidth_loop
fontGenericFnGetStringWidth_loopEnd:
pop zh
pop zl
ret
fontGenericFnGetStringHeight:
rjmp fontGenericFnGetCharHeight ; for now monospace fonts only
; @end