507 lines
12 KiB
NASM
507 lines
12 KiB
NASM
; ***************************************************************************
|
|
; 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_TEXTSEL_ASM
|
|
#define AQH_AVR_GUI_TEXTSEL_ASM
|
|
|
|
|
|
; ***************************************************************************
|
|
; ***************************************************************************
|
|
|
|
|
|
|
|
|
|
; ***************************************************************************
|
|
; defines
|
|
|
|
.equ TEXTSEL_OFFS_BEGIN = HLAYOUT_SIZE
|
|
.equ TEXTSEL_OFFS_CURVALUE_LO = TEXTSEL_OFFS_BEGIN+0
|
|
.equ TEXTSEL_OFFS_CURVALUE_HI = TEXTSEL_OFFS_BEGIN+1
|
|
.equ TEXTSEL_OFFS_TEXTLIST_LO = TEXTSEL_OFFS_BEGIN+2
|
|
.equ TEXTSEL_OFFS_TEXTLIST_HI = TEXTSEL_OFFS_BEGIN+3
|
|
.equ TEXTSEL_OFFS_CURRIDX = TEXTSEL_OFFS_BEGIN+4
|
|
.equ TEXTSEL_OFFS_COUNT = TEXTSEL_OFFS_BEGIN+5
|
|
.equ TEXTSEL_SIZE = TEXTSEL_OFFS_BEGIN+6
|
|
|
|
|
|
; selectors
|
|
.equ TEXTSEL_SEL_LEFT = 1
|
|
.equ TEXTSEL_SEL_RIGHT = 2
|
|
|
|
|
|
; child widgets
|
|
.equ TEXTSEL_CHILDIDX_LEFT = 0
|
|
.equ TEXTSEL_CHILDIDX_VALUE = 1
|
|
.equ TEXTSEL_CHILDIDX_EIGHT = 2
|
|
|
|
|
|
; ***************************************************************************
|
|
; code
|
|
|
|
.cseg
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine TextSel_new @global
|
|
;
|
|
; @return CFLAG set of okay, cleared otherwise
|
|
; @return Y address of newly created object
|
|
; @param X parent widget
|
|
; @param r16 value for OBJECT_OFFS_OPTS
|
|
; @param r17 value for WIDGET_OFFS_PACK
|
|
; @param r21:r20 pointer to null-terminated list of text ressources in FLASH (byte address for LPM!)
|
|
; @clobbers any
|
|
|
|
TextSel_new:
|
|
ldi r24, LOW(TEXTSEL_SIZE)
|
|
ldi r25, HIGH(TEXTSEL_SIZE)
|
|
push r20
|
|
push r21
|
|
bigcall Object_Alloc ; (!r16, !r17, !X)
|
|
pop r21
|
|
pop r20
|
|
brcc TextSel_new_ret
|
|
rcall TextSel_Init ; (any, !Y)
|
|
sec
|
|
TextSel_new_ret:
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine TextSel_Init @global
|
|
;
|
|
; @param Y address of widget
|
|
; @param X parent widget (if any)
|
|
; @param r16 value for OBJECT_OFFS_OPTS
|
|
; @param r17 value for WIDGET_OFFS_PACK
|
|
; @param r21:r20 pointer to null-terminated list of text ressources in FLASH (byte address for LPM!)
|
|
; @clobbers any, !Y
|
|
|
|
TextSel_Init:
|
|
; call base class
|
|
push r20
|
|
push r21
|
|
ldi r20, HLAYOUT_MODE_EXPAND
|
|
bigcall HLayout_Init
|
|
pop r21
|
|
pop r20
|
|
brcc TextSel_Init_ret
|
|
|
|
; set values
|
|
std Y+TEXTSEL_OFFS_TEXTLIST_LO, r20
|
|
std Y+TEXTSEL_OFFS_TEXTLIST_HI, r21
|
|
|
|
; set default signal map
|
|
ldi r16, LOW(TextSel_DefaultSignalmap*2)
|
|
std Y+OBJECT_OFFS_SIGNALMAP_LO, r16
|
|
ldi r16, HIGH(TextSel_DefaultSignalmap*2)
|
|
std Y+OBJECT_OFFS_SIGNALMAP_HI, r16
|
|
|
|
rcall textSelCreateChildren ; (any, !Y)
|
|
TextSel_Init_ret:
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine textSelCreateChildren
|
|
;
|
|
; @param Y spinner object
|
|
; @clobbers any, !Y
|
|
|
|
textSelCreateChildren:
|
|
push yl
|
|
push yh
|
|
mov xl, yl ; parent
|
|
mov xh, yh
|
|
|
|
; create left button
|
|
call textSelCreateLeftButton
|
|
brcc textSelCreateChildren_popRet
|
|
; create label
|
|
ldi r16, 0 ; OPTS
|
|
ldi r17, (WIDGET_PACK_END<<WIDGET_PACK_HSELF0_BIT) | (WIDGET_PACK_CENTER<<WIDGET_PACK_VSELF0_BIT) | \
|
|
(WIDGET_PACK_END<<WIDGET_PACK_HCONTENT0_BIT) | (WIDGET_PACK_CENTER<<WIDGET_PACK_VCONTENT0_BIT) ; PACK
|
|
clr r20
|
|
clr r21
|
|
push xl
|
|
push xh
|
|
bigcall Label_new
|
|
pop xh
|
|
pop xl
|
|
brcc textSelCreateChildren_popRet
|
|
|
|
; create right button
|
|
call textSelCreateRightButton
|
|
textSelCreateChildren_popRet:
|
|
pop yh
|
|
pop yl
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
textSelCreateLeftButton:
|
|
push xl
|
|
push xh
|
|
; create button
|
|
ldi r16, (1<<WIDGET_OPTS_BORDER_BIT) ; OPTS
|
|
ldi r17, (WIDGET_PACK_BEGIN<<WIDGET_PACK_HSELF0_BIT) | (WIDGET_PACK_CENTER<<WIDGET_PACK_VSELF0_BIT) ; PACK
|
|
ldi r20, LOW(RESSOURCE_TXT_LESSERTHAN_C) ; text ressource
|
|
ldi r21, HIGH(RESSOURCE_TXT_LESSERTHAN_C)
|
|
ldi r22, TEXTSEL_SEL_LEFT ; selector
|
|
ldi r23, BUTTON_MODE_REPEATED
|
|
bigcall TextButton_new
|
|
brcc textSelCreateLeftButton_done
|
|
|
|
; set style in Label part of the text button
|
|
bigcall OBJ_GetFirstChild
|
|
brcc textSelCreateLeftButton_done
|
|
mov yl, r18
|
|
mov yh, r19
|
|
ldi r16, LOW(TextSel_ButtonStyle*2)
|
|
std Y+WIDGET_OFFS_STYLE_LO, r16
|
|
ldi r16, HIGH(TextSel_ButtonStyle*2)
|
|
std Y+WIDGET_OFFS_STYLE_HI, r16
|
|
textSelCreateLeftButton_done:
|
|
pop xh
|
|
pop xl
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
textSelCreateRightButton:
|
|
push xl
|
|
push xh
|
|
; create button
|
|
ldi r16, (1<<WIDGET_OPTS_BORDER_BIT) ; OPTS
|
|
ldi r17, (WIDGET_PACK_BEGIN<<WIDGET_PACK_HSELF0_BIT) | (WIDGET_PACK_CENTER<<WIDGET_PACK_VSELF0_BIT) ; PACK
|
|
ldi r20, LOW(RESSOURCE_TXT_GREATERTHAN_C) ; text ressource
|
|
ldi r21, HIGH(RESSOURCE_TXT_GREATERTHAN_C)
|
|
ldi r22, TEXTSEL_SEL_RIGHT ; selector
|
|
ldi r23, BUTTON_MODE_REPEATED
|
|
bigcall TextButton_new
|
|
brcc textSelCreateRightButton_done
|
|
|
|
; set style in Label part of the text button
|
|
bigcall OBJ_GetFirstChild
|
|
brcc textSelCreateRightButton_done
|
|
mov yl, r18
|
|
mov yh, r19
|
|
ldi r16, LOW(TextSel_ButtonStyle*2)
|
|
std Y+WIDGET_OFFS_STYLE_LO, r16
|
|
ldi r16, HIGH(TextSel_ButtonStyle*2)
|
|
std Y+WIDGET_OFFS_STYLE_HI, r16
|
|
textSelCreateRightButton_done:
|
|
pop xh
|
|
pop xl
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine textSelSetValue
|
|
;
|
|
; @param Y widget
|
|
; @param X new value
|
|
; @clobbers any, !Y
|
|
|
|
textSelSetValue:
|
|
std Y+TEXTSEL_OFFS_CURVALUE_LO, xl
|
|
std Y+TEXTSEL_OFFS_CURVALUE_HI, xh
|
|
rjmp textSelSendValue
|
|
; @end
|
|
|
|
|
|
|
|
textSelSendValue:
|
|
ldi r16, TEXTSEL_CHILDIDX_VALUE
|
|
bigcall OBJ_GetChildAt ; r19:r18=value label (r16)
|
|
brcc textSelSendValue_ret
|
|
push yl
|
|
push yh
|
|
ldd xl, Y+TEXTSEL_OFFS_CURVALUE_LO
|
|
ldd xh, Y+TEXTSEL_OFFS_CURVALUE_HI
|
|
mov yl, r18
|
|
mov yh, r19
|
|
ldi r17, LABEL_VALUE_TEXTRES
|
|
bigcall Widget_SetValue ; (any, !Y)
|
|
pop yh
|
|
pop yl
|
|
rcall textSelEmitCmdSignal
|
|
textSelSendValue_ret:
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine textSelEmitCmdSignal
|
|
;
|
|
; @param Y widget
|
|
; @clobbers any, !Y
|
|
|
|
textSelEmitCmdSignal:
|
|
ldi r16, WIDGET_SIGNAL_COMMAND
|
|
ldd xl, Y+TEXTSEL_OFFS_CURVALUE_LO
|
|
ldd xh, Y+TEXTSEL_OFFS_CURVALUE_HI
|
|
bigjmp OBJ_EmitSignal
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine textCountRessources
|
|
;
|
|
; @param Y widget
|
|
; @clobbers r16-r19
|
|
|
|
textCountRessources:
|
|
push zl
|
|
push zh
|
|
ldd zl, Y+TEXTSEL_OFFS_TEXTLIST_LO
|
|
ldd zh, Y+TEXTSEL_OFFS_TEXTLIST_HI
|
|
mov r16, zl
|
|
or r16, zh
|
|
breq textCountRessources_done
|
|
clr r17
|
|
textCountRessources_loop:
|
|
lpm r18, Z+
|
|
lpm r19, Z+
|
|
mov r16, r18
|
|
or r16, r19
|
|
breq textCountRessources_done
|
|
inc r17
|
|
rjmp textCountRessources_loop
|
|
textCountRessources_done:
|
|
pop zh
|
|
pop zl
|
|
std Y+TEXTSEL_OFFS_COUNT, r17
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine textSelGetRessIdAt
|
|
;
|
|
; @param Y widget
|
|
; @param r16 idx
|
|
; @return CFLAG set if ressource id found
|
|
; @return X ressource id (if CFLAG set)
|
|
; @clobbers r16, r17
|
|
|
|
textSelGetRessIdAt:
|
|
push zl
|
|
push zh
|
|
ldd r17, Y+TEXTSEL_OFFS_COUNT
|
|
cp r16, r17
|
|
brcc textSelGetRessIdAt_done
|
|
add r16, r16
|
|
ldd zl, Y+TEXTSEL_OFFS_TEXTLIST_LO
|
|
ldd zh, Y+TEXTSEL_OFFS_TEXTLIST_HI
|
|
mov r17, zl
|
|
or r17, zh
|
|
clc
|
|
breq textSelGetRessIdAt_done
|
|
add zl, r16
|
|
adc zh, r16
|
|
sub zh, r16
|
|
lpm xl, Z+
|
|
lpm xh, Z
|
|
mov r17, xl
|
|
or r17, xh
|
|
clc
|
|
breq textSelGetRessIdAt_done
|
|
sec
|
|
textSelGetRessIdAt_done:
|
|
pop zh
|
|
pop zl
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine textGetIdxForRessource
|
|
;
|
|
; @param Y widget
|
|
; @param X ressource id to look for
|
|
; @return CFLAG set if found, cleared otherwise
|
|
; @return r16 idx
|
|
|
|
textGetIdxForRessource:
|
|
push zl
|
|
push zh
|
|
ldd zl, Y+TEXTSEL_OFFS_TEXTLIST_LO
|
|
ldd zh, Y+TEXTSEL_OFFS_TEXTLIST_HI
|
|
mov r16, zl
|
|
or r16, zh
|
|
breq textGetIdxForRessource_done
|
|
clr r16
|
|
textGetIdxForRessource_loop:
|
|
lpm r18, Z+
|
|
lpm r19, Z+
|
|
mov r17, r18
|
|
or r17, r19
|
|
clc
|
|
breq textGetIdxForRessource_done
|
|
cp r18, xl
|
|
brne textGetIdxForRessource_next
|
|
cp r19, xh
|
|
brne textGetIdxForRessource_next
|
|
sec
|
|
rjmp textGetIdxForRessource_done
|
|
textGetIdxForRessource_next:
|
|
inc r16
|
|
rjmp textGetIdxForRessource_loop
|
|
textGetIdxForRessource_done:
|
|
pop zh
|
|
pop zl
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
|
|
|
|
; ***************************************************************************
|
|
; signal handlers
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine TextSel_OnCmdLeft @global
|
|
;
|
|
; @param Y widget
|
|
|
|
TextSel_OnCmdLeft:
|
|
ldd r16, Y+TEXTSEL_OFFS_CURRIDX
|
|
tst r16
|
|
breq TextSel_OnCmdLeft_ret
|
|
dec r16
|
|
std Y+TEXTSEL_OFFS_CURRIDX, r16
|
|
rcall textSelGetRessIdAt ; X=ressource id (r16, r17)
|
|
brcc TextSel_OnCmdLeft_ret
|
|
std Y+TEXTSEL_OFFS_CURVALUE_LO, xl
|
|
std Y+TEXTSEL_OFFS_CURVALUE_HI, xh
|
|
rcall textSelSetValue
|
|
TextSel_OnCmdLeft_ret:
|
|
sec
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine TextSel_OnCmdRight @global
|
|
;
|
|
; @param Y widget
|
|
|
|
TextSel_OnCmdRight:
|
|
ldd r16, Y+TEXTSEL_OFFS_CURRIDX
|
|
ldd r17, Y+TEXTSEL_OFFS_COUNT
|
|
inc r16
|
|
cp r16, r17
|
|
brcc TextSel_OnCmdRight_ret
|
|
std Y+TEXTSEL_OFFS_CURRIDX, r16
|
|
rcall textSelGetRessIdAt ; X=ressource id (r16, r17)
|
|
brcc TextSel_OnCmdRight_ret
|
|
std Y+TEXTSEL_OFFS_CURVALUE_LO, xl
|
|
std Y+TEXTSEL_OFFS_CURVALUE_HI, xh
|
|
rcall textSelSetValue
|
|
TextSel_OnCmdRight_ret:
|
|
sec
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine TextSel_OnSetValue @global
|
|
;
|
|
; @param Y widget
|
|
; @param X new value (selected text ressource id)
|
|
|
|
TextSel_OnSetValue:
|
|
rcall textGetIdxForRessource
|
|
brcc TextSel_OnSetValue_ret
|
|
std Y+TEXTSEL_OFFS_CURRIDX, r16
|
|
std Y+TEXTSEL_OFFS_CURVALUE_LO, xl
|
|
std Y+TEXTSEL_OFFS_CURVALUE_HI, xh
|
|
rcall textSelSendValue
|
|
TextSel_OnSetValue_ret:
|
|
sec
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine TextSel_OnGetValue @global
|
|
;
|
|
; @param Y widget
|
|
; @return r19:r18 value
|
|
|
|
TextSel_OnGetValue:
|
|
ldd r18, Y+TEXTSEL_OFFS_CURVALUE_LO
|
|
ldd r19, Y+TEXTSEL_OFFS_CURVALUE_HI
|
|
sec
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
|
|
|
|
; ***************************************************************************
|
|
; data in FLASH
|
|
|
|
|
|
TextSel_ButtonStyle:
|
|
.dw DISPLAY_COLOR_BLACK ; frontCol_norm
|
|
.dw DISPLAY_COLOR_WHITE ; backCol_norm
|
|
.dw DISPLAY_COLOR_BLACK ; borderCol_norm
|
|
.dw DISPLAY_COLOR_WHITE ; shadowCol_norm
|
|
|
|
.dw DISPLAY_COLOR_WHITE ; frontCol_activated
|
|
.dw DISPLAY_COLOR_NAVY ; backCol_activated
|
|
.dw DISPLAY_COLOR_BLACK ; borderCol_activated
|
|
.dw DISPLAY_COLOR_WHITE ; shadowCol_activated
|
|
|
|
.db 6, 0 ; outerBorderSize, innerBorderSize
|
|
.dw ili9341Font12x16_1*2 ; font
|
|
.db 12, 16 ; charWidth, charHeight
|
|
; @end
|
|
|
|
|
|
|
|
TextSel_DefaultSignalmap:
|
|
; header
|
|
.dw HLayout_DefaultSignalmap*2 ; next table to use
|
|
; entries
|
|
|
|
.db TEXTSEL_SEL_LEFT, WIDGET_SIGNAL_COMMAND, LOW(TextSel_OnCmdLeft), HIGH(TextSel_OnCmdLeft)
|
|
.db TEXTSEL_SEL_RIGHT, WIDGET_SIGNAL_COMMAND, LOW(TextSel_OnCmdRight), HIGH(TextSel_OnCmdRight)
|
|
.db WIDGET_VALUE_CURRENTVALUE, WIDGET_SIGNAL_SETVALUE, LOW(TextSel_OnSetValue), HIGH(TextSel_OnSetValue)
|
|
.db WIDGET_VALUE_CURRENTVALUE, WIDGET_SIGNAL_GETVALUE, LOW(TextSel_OnGetValue), HIGH(TextSel_OnGetValue)
|
|
.db 0, 0, 0, 0 ; end of table
|
|
|
|
|
|
|
|
#endif
|
|
|