diff --git a/avr/devices/c03/test/a_c03.asm b/avr/devices/c03/test/a_c03.asm new file mode 100644 index 0000000..228bd84 --- /dev/null +++ b/avr/devices/c03/test/a_c03.asm @@ -0,0 +1,384 @@ +; *************************************************************************** +; 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_A_C03_ASM +#define AQH_AVR_A_C03_ASM + + +; *************************************************************************** +; defines + +.equ C03APP_OFFS_BEGIN = GUIAPP_SIZE +.equ C03APP_OFFS_WMENU_LO = C03APP_OFFS_BEGIN+0 +.equ C03APP_OFFS_WMENU_HI = C03APP_OFFS_BEGIN+1 +.equ C03APP_OFFS_WCLIMATE_LO = C03APP_OFFS_BEGIN+2 +.equ C03APP_OFFS_WCLIMATE_HI = C03APP_OFFS_BEGIN+3 +.equ C03APP_OFFS_WLIGHT_LO = C03APP_OFFS_BEGIN+4 +.equ C03APP_OFFS_WLIGHT_HI = C03APP_OFFS_BEGIN+5 +.equ C03APP_OFFS_WWINDOWS_LO = C03APP_OFFS_BEGIN+6 +.equ C03APP_OFFS_WWINDOWS_HI = C03APP_OFFS_BEGIN+7 +.equ C03APP_OFFS_WDEBUG_LO = C03APP_OFFS_BEGIN+8 +.equ C03APP_OFFS_WDEBUG_HI = C03APP_OFFS_BEGIN+9 +.equ C03APP_SIZE = C03APP_OFFS_BEGIN+10 + + +; selectors for main windows +.equ C03APP_SEL_BACK = 1 +.equ C03APP_SEL_MENU = 2 +.equ C03APP_SEL_CLIMATE = 3 +.equ C03APP_SEL_LIGHT = 4 +.equ C03APP_SEL_WINDOWS = 5 +.equ C03APP_SEL_DEBUG = 6 + + + + +; *************************************************************************** +; data + +.dseg + + + +; *************************************************************************** +; code + +.cseg + + + +; --------------------------------------------------------------------------- +; @routine C03App_new @global +; +; @return CFLAG set of okay, cleared otherwise +; @return Y address of newly created object +; @param r16 value for OBJECT_OFFS_OPTS +; @clobbers any + +C03App_new: + ldi r24, LOW(C03APP_SIZE) + ldi r25, HIGH(C03APP_SIZE) + bigcall Object_Alloc ; (!r16, !r17) + brcc C03App_new_ret + rcall C03App_Init ; (r16, r17, X) + sec +C03App_new_ret: + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine C03App_Init @global +; +; @param Y address of object in SDRAM +; @param r16 value for OBJECT_OFFS_OPTS + +C03App_Init: + ; call base class + bigcall GuiApp_Init ; (r16, r17, X) + + ; set default signal map + ldi r16, LOW(C03App_DefaultSignalmap*2) + std Y+OBJECT_OFFS_SIGNALMAP_LO, r16 + ldi r16, HIGH(C03App_DefaultSignalmap*2) + std Y+OBJECT_OFFS_SIGNALMAP_HI, r16 + + ; create main windows + rcall c03AppCreateWinMenu ; (!Y) + rcall c03AppCreateWinClimate ; (!Y) + + ; enter menu window + rcall C03App_EnterMenuWin + sec + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine c03AppCreateWinMenu +; +; @clobbers !X + +c03AppCreateWinMenu: + push yl + push yh + bigcall MenuWin_new + mov xl, yl + mov xh, yh + pop yh + pop yl + brcc c03AppCreateWinMenu_ret + std Y+C03APP_OFFS_WMENU_LO, xl + std Y+C03APP_OFFS_WMENU_HI, xh + ldi r16, C03APP_SEL_MENU + rcall c03AppSetTargetAndSelector + sec +c03AppCreateWinMenu_ret: + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine c03AppCreateWinClimate +; +; @clobbers !X + +c03AppCreateWinClimate: + push yl + push yh + bigcall ClimateWin_new + mov xl, yl + mov xh, yh + pop yh + pop yl + brcc c03AppCreateWinClimate_ret + std Y+C03APP_OFFS_WCLIMATE_LO, xl + std Y+C03APP_OFFS_WCLIMATE_HI, xh + ldi r16, C03APP_SEL_CLIMATE + rcall c03AppSetTargetAndSelector + sec +c03AppCreateWinClimate_ret: + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine c03AppSetTargetAndSelector +; +; @param r16 selector +; @param X pointer to new main window to set target/selector to +; @clobbers none + +c03AppSetTargetAndSelector: + adiw xh:xl, OBJECT_OFFS_SELECTOR + st X, r16 + sbiw xh:xl, OBJECT_OFFS_SELECTOR + adiw xh:xl, OBJECT_OFFS_TARGET_LO + st X+, yl ; set target + st X, yh + sbiw xh:xl, (OBJECT_OFFS_TARGET_LO+1) + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine C03App_EnterMenuWin +; +; @param Y ptr to this guiapp + +C03App_EnterMenuWin: + ldd xl, Y+C03APP_OFFS_WMENU_LO + ldd xh, Y+C03APP_OFFS_WMENU_HI + mov r16, xl ; was window created? + or r16, xh + breq C03App_EnterMenuWin_ret ; nope, jump + bigcall GuiApp_EnterWindow +C03App_EnterMenuWin_ret: + sec + ret +; @end + + + + +; --------------------------------------------------------------------------- +; @routine C03App_OnCmdClimate +; +; @param Y ptr to this guiapp + +C03App_OnCmdClimate: + ldd xl, Y+C03APP_OFFS_WCLIMATE_LO + ldd xh, Y+C03APP_OFFS_WCLIMATE_HI + mov r16, xl ; was window created? + or r16, xh + breq C03App_OnCmdClimate_ret ; nope, ignore this signal + bigcall GuiApp_EnterWindow +C03App_OnCmdClimate_ret: + sec + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine C03App_OnCmdLight +; +; @param Y ptr to this guiapp + +C03App_OnCmdLight: + ldd xl, Y+C03APP_OFFS_WLIGHT_LO + ldd xh, Y+C03APP_OFFS_WLIGHT_HI + mov r16, xl ; was window created? + or r16, xh + breq C03App_OnCmdLight_ret ; nope, ignore this signal + bigcall GuiApp_EnterWindow +C03App_OnCmdLight_ret: + sec + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine C03App_OnCmdWindows +; +; @param Y ptr to this guiapp + +C03App_OnCmdWindows: + ldd xl, Y+C03APP_OFFS_WWINDOWS_LO + ldd xh, Y+C03APP_OFFS_WWINDOWS_HI + mov r16, xl ; was window created? + or r16, xh + breq C03App_OnCmdWindows_ret ; nope, ignore this signal + bigcall GuiApp_EnterWindow +C03App_OnCmdWindows_ret: + sec + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine C03App_OnCmdDebug +; +; @param Y ptr to this guiapp + +C03App_OnCmdDebug: + ldd xl, Y+C03APP_OFFS_WDEBUG_LO + ldd xh, Y+C03APP_OFFS_WDEBUG_HI + mov r16, xl ; was window created? + or r16, xh + breq C03App_OnCmdDebug_ret ; nope, ignore this signal + bigcall GuiApp_EnterWindow +C03App_OnCmdDebug_ret: + sec + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine C03App_OnCmdBack +; +; @param Y ptr to this guiapp + +C03App_OnCmdBack: + bigcall GuiApp_LeaveWindow + sec + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine C03App_CreateButton +; +; @param X parent +; @param r16 value for OBJECT_OFFS_OPTS +; @param r17 value for WIDGET_OFFS_PACK +; @param r21:r20 img ressource +; @param r22 selector +; @return CFLAG set if new object created, cleared on error +; @return Y button created +; @clobbers any, !X + +C03App_CreateButton: + push xl + push xh + push r20 + push r21 + push r22 + ldi r20, BUTTON_MODE_NORMAL + rcall Button_new + pop r22 + pop r21 + pop r20 + brcc C03App_CreateButton_done + mov xl, yl + mov xh, yh + push xl ; Button + push xh + push r22 + ldi r16, 0 + ldi r17, (WIDGET_PACK_BEGIN<