avr: work on simple GUI module to be used by node c02.
This commit is contained in:
368
avr/modules/lcd2/gui/window.asm
Normal file
368
avr/modules/lcd2/gui/window.asm
Normal file
@@ -0,0 +1,368 @@
|
||||
; ***************************************************************************
|
||||
; 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_GUI_WINDOW_ASM
|
||||
#define AQH_AVR_GUI_WINDOW_ASM
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Window_Clear @global
|
||||
;
|
||||
; @param Y pointer to screen object in SDRAM
|
||||
; @clobbers any, !Y
|
||||
|
||||
Window_Clear:
|
||||
ldd r2, Y+WIN_OFFS_BG_COL_LO ; background color low
|
||||
ldd r3, Y+WIN_OFFS_BG_COL_HI ; background color high
|
||||
ldd r4, Y+WIN_OFFS_X_LO ; X low
|
||||
ldd r5, Y+WIN_OFFS_X_HI ; X high
|
||||
ldd r6, Y+WIN_OFFS_Y_LO ; Y low
|
||||
ldd r7, Y+WIN_OFFS_Y_HI ; Y high
|
||||
ldd r8, Y+WIN_OFFS_WIDTH_LO ; width low
|
||||
ldd r9, Y+WIN_OFFS_WIDTH_HI ; width high
|
||||
ldd r10, Y+WIN_OFFS_HEIGHT_LO ; height low
|
||||
ldd r11, Y+WIN_OFFS_HEIGHT_HI ; height high
|
||||
bigcall Display_FillRect
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Window_DrawTextFlash @global
|
||||
;
|
||||
; @param Y pointer to screen object in SDRAM
|
||||
; @param R5:R4 X (dest)
|
||||
; @param R7:R6 Y (dest)
|
||||
; @return R5:R4 X pos behind string
|
||||
; @return R7:R6 Y pos behind string
|
||||
; @clobbers any, !Y
|
||||
|
||||
Window_DrawTextFlash:
|
||||
rcall winCalcAbsPosAndBorders ; (R18, R19)
|
||||
|
||||
ldd r0, Y+WIN_OFFS_BG_COL_LO
|
||||
ldd r1, Y+WIN_OFFS_BG_COL_HI
|
||||
ldd r2, Y+WIN_OFFS_FG_COL_LO
|
||||
ldd r3, Y+WIN_OFFS_FG_COL_HI
|
||||
|
||||
Window_DrawTextFlash_loop:
|
||||
lpm r16, Z
|
||||
tst r16
|
||||
breq Window_DrawTextFlash_loopEnd
|
||||
rcall winDrawChar
|
||||
brcc Window_DrawTextFlash_loopEnd
|
||||
adiw zh:zl, 1 ; next char
|
||||
rjmp Window_DrawTextFlash_loop
|
||||
Window_DrawTextFlash_loopEnd:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Window_DrawCharAt @global
|
||||
;
|
||||
; @param Y pointer to screen object in SDRAM
|
||||
; @param R16 char to write
|
||||
; @param R5:R4 X (dest)
|
||||
; @param R7:R6 Y (dest)
|
||||
; @return R5:R4 X pos behind char
|
||||
; @clobbers any, !Y, !R6, !R7
|
||||
|
||||
Window_DrawCharAt:
|
||||
rcall winCalcAbsPosAndBorders
|
||||
|
||||
ldd r0, Y+WIN_OFFS_BG_COL_LO
|
||||
ldd r1, Y+WIN_OFFS_BG_COL_HI
|
||||
ldd r2, Y+WIN_OFFS_FG_COL_LO
|
||||
ldd r3, Y+WIN_OFFS_FG_COL_HI
|
||||
|
||||
rjmp winDrawChar
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine winCalcAbsPosAndBorders
|
||||
;
|
||||
; @param Y pointer to screen object in SDRAM
|
||||
; @param R5:R4 X relative to window
|
||||
; @param R7:R6 Y relative to window
|
||||
; @return R9:R8 first X pos right of windows
|
||||
; @return R5:R4 X relative to screen
|
||||
; @return R7:R6 Y relative to screen
|
||||
; @return R9:R8 first X pos right of window (abs)
|
||||
; @return R11:R10 first Y pos below window (abs)
|
||||
; @clobbers r18, r19
|
||||
|
||||
winCalcAbsPosAndBorders:
|
||||
; calc abs X pos
|
||||
ldd r18, Y+WIN_OFFS_X_LO
|
||||
ldd r19, Y+WIN_OFFS_X_HI
|
||||
add r4, r18 ; add X of window
|
||||
adc r5, r19
|
||||
|
||||
; calc first X pos behind window
|
||||
ldd r8, Y+WIN_OFFS_WIDTH_LO
|
||||
ldd r9, Y+WIN_OFFS_WIDTH_HI
|
||||
add r8, r18
|
||||
adc r9, r19
|
||||
|
||||
; calc abs Y pos
|
||||
ldd r18, Y+WIN_OFFS_Y_LO
|
||||
ldd r19, Y+WIN_OFFS_Y_HI
|
||||
add r6, r18 ; add Y of window
|
||||
adc r7, r19
|
||||
|
||||
; calc first Y pos behind window
|
||||
ldd r10, Y+WIN_OFFS_HEIGHT_LO
|
||||
ldd r11, Y+WIN_OFFS_HEIGHT_HI
|
||||
add r10, r18
|
||||
adc r11, r19
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine winDrawChar
|
||||
;
|
||||
; @param Y pointer to screen object in SDRAM
|
||||
; @param R16 char to write
|
||||
; @param R5:R4 absolute X on screen
|
||||
; @param R7:R6 absolute Y on screen
|
||||
; @param R9:R8 first X pos right of windows
|
||||
; @return R5:R4 X pos behind char
|
||||
; @clobbers any, !Y, !R6, !R7
|
||||
|
||||
winDrawChar:
|
||||
push zl
|
||||
push zh
|
||||
mov r12, r16
|
||||
ldd zl, Y+WIN_OFFS_FONT_LO
|
||||
ldd zh, Y+WIN_OFFS_FONT_HI
|
||||
|
||||
; check whether the char fits inside window
|
||||
bigcall FONT_GetCharWidth ; r16=char width
|
||||
|
||||
clr r17
|
||||
add r16, r4 ; char width+X
|
||||
adc r17, r5
|
||||
sub r16, r8 ; check against window width
|
||||
sbc r17, r9
|
||||
brcc winDrawChar_ret ; not fit, jmp
|
||||
|
||||
; actually draw char
|
||||
mov r16, r12
|
||||
push r8
|
||||
push r9
|
||||
push r10
|
||||
push r11
|
||||
bigcall Display_DrawChar
|
||||
pop r11
|
||||
pop r10
|
||||
pop r9
|
||||
pop r8
|
||||
clr r16
|
||||
add r4, r18 ; increment X
|
||||
adc r5, r16
|
||||
sec ; write succeeded
|
||||
winDrawChar_ret:
|
||||
pop zh
|
||||
pop zl
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Window_DrawTextFlash @global
|
||||
;
|
||||
; @param Y pointer to screen object in SDRAM
|
||||
; @param R5:R4 X (dest)
|
||||
; @param R7:R6 Y (dest)
|
||||
; @return R5:R4 X pos behind string
|
||||
; @return R7:R6 Y pos behind string
|
||||
; @clobbers any, !Y
|
||||
|
||||
Window_DrawTextFlash:
|
||||
; calc abs X pos
|
||||
ldd r18, Y+WIN_OFFS_X_LO
|
||||
ldd r19, Y+WIN_OFFS_X_HI
|
||||
add r4, r18 ; add X of window
|
||||
adc r5, r19
|
||||
|
||||
; calc first X pos behind window
|
||||
ldd r8, Y+WIN_OFFS_WIDTH_LO
|
||||
ldd r9, Y+WIN_OFFS_WIDTH_HI
|
||||
add r8, r18
|
||||
adc r9, r19
|
||||
|
||||
; calc abs Y pos
|
||||
ldd r18, Y+WIN_OFFS_Y_LO
|
||||
ldd r19, Y+WIN_OFFS_Y_HI
|
||||
add r6, r18 ; add Y of window
|
||||
adc r7, r19
|
||||
|
||||
; calc first Y pos behind window
|
||||
ldd r10, Y+WIN_OFFS_HEIGHT_LO
|
||||
ldd r11, Y+WIN_OFFS_HEIGHT_HI
|
||||
add r10, r18
|
||||
adc r11, r19
|
||||
|
||||
Window_DrawTextFlash_loop:
|
||||
push zl
|
||||
push zh
|
||||
rcall winCalcLengthWordFlash
|
||||
pop zh
|
||||
pop zl
|
||||
mov r18, r4
|
||||
mov r19, r5
|
||||
add r18, r12
|
||||
adc r19, r13
|
||||
sub r18, r8
|
||||
sbc r19, r9
|
||||
brcs Window_DrawTextFlash_xOkay
|
||||
; we need to go to the beginning of the next line
|
||||
rcall Window_DrawTextFlash_nextLine
|
||||
brcc Window_DrawTextFlash_loopEnd ; outside the window, jmp
|
||||
Window_DrawTextFlash_xOkay:
|
||||
rcall winDrawWordFlash ; Z points at blank/0 byte after call
|
||||
lpm r16, Z+
|
||||
tst r16 ; end of string?
|
||||
breq Window_DrawTextFlash_loopEnd
|
||||
cpi r16, 13
|
||||
breq Window_DrawTextFlash_handle13
|
||||
; insert other handled chars here
|
||||
; write blank char
|
||||
push zl
|
||||
push zh
|
||||
ldd zl, Y+WIN_OFFS_FONT_LO
|
||||
ldd zh, Y+WIN_OFFS_FONT_HI
|
||||
ldi r16, 32 ; space
|
||||
bigcall Display_DrawChar
|
||||
pop zh
|
||||
pop zl
|
||||
add r4, r8 ; increment X
|
||||
adc r5, r9
|
||||
|
||||
|
||||
rjmp Window_DrawTextFlash_loopNext
|
||||
Window_DrawTextFlash_handle13:
|
||||
rcall Window_DrawTextFlash_nextLine
|
||||
Window_DrawTextFlash_loopNext:
|
||||
rjmp Window_DrawTextFlash_loop
|
||||
Window_DrawTextFlash_nextLine:
|
||||
push zl
|
||||
push zh
|
||||
ldd zl, Y+WIN_OFFS_FONT_LO
|
||||
ldd zh, Y+WIN_OFFS_FONT_HI
|
||||
bigcall FONT_GetCharWidth ; r16=char width
|
||||
pop zh
|
||||
pop zl
|
||||
ldd r4, Y+WIN_OFFS_X_LO ; X=left border
|
||||
ldd r5, Y+WIN_OFFS_X_HI
|
||||
clr r17
|
||||
add r6, r16 ; increment Y by font height
|
||||
adc r7, r17
|
||||
mov r16, r6 ; check against lower border of window
|
||||
mov r17, r7
|
||||
sub r16, r10
|
||||
sbc r17, r11 ; CF set if inside window, cleared otherwise
|
||||
ret
|
||||
Window_DrawTextFlash_loopEnd:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine winDrawWordFlash
|
||||
;
|
||||
; @param Y pointer to screen object in SDRAM
|
||||
; @param Z pointer to string in FLASH
|
||||
; @param R1:R0 background color
|
||||
; @param R3:R2 foreground color
|
||||
; @param R5:R4 X (dest)
|
||||
; @param R7:R6 Y (dest)
|
||||
; @return r5:r4 next X pos
|
||||
; @return Z pointer to next char behind current word
|
||||
; @clobbers any, !Y, !r1-r15
|
||||
|
||||
winDrawWordFlash:
|
||||
winDrawWordFlash_loop:
|
||||
lpm r16, Z
|
||||
cpi r16, 33
|
||||
brcs winDrawWordFlash_ret
|
||||
push zl
|
||||
push zh
|
||||
ldd zl, Y+WIN_OFFS_FONT_LO
|
||||
ldd zh, Y+WIN_OFFS_FONT_HI
|
||||
bigcall Display_DrawChar
|
||||
pop zh
|
||||
pop zl
|
||||
clr r16
|
||||
add r4, r18 ; increment X
|
||||
adc r5, r16
|
||||
adiw zh:zl, 1
|
||||
rjmp winDrawWordFlash_loop
|
||||
winDrawWordFlash_ret:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine winCalcLengthWordFlash
|
||||
;
|
||||
; @param Y pointer to screen object in SDRAM
|
||||
; @param Z pointer to string in FLASH
|
||||
; @return r13:r12 width of next word in pixels
|
||||
; @return Z pointer to next char behind current word
|
||||
; @clobbers any, !Y, !r1-r11, !r14, !r15
|
||||
|
||||
winCalcLengthWordFlash:
|
||||
clr r12
|
||||
clr r13
|
||||
winCalcLengthWordFlash_loop:
|
||||
lpm r16, Z
|
||||
cpi r16, 33
|
||||
brcs winCalcLengthWordFlash_ret
|
||||
push zl
|
||||
push zh
|
||||
ldd zl, Y+WIN_OFFS_FONT_LO
|
||||
ldd zh, Y+WIN_OFFS_FONT_HI
|
||||
bigcall FONT_GetCharWidth ; r16=char width
|
||||
clr r17
|
||||
add r12, r16
|
||||
adc r13, r17
|
||||
pop zh
|
||||
pop zl
|
||||
brcs winCalcLengthWordFlash_error
|
||||
adiw zh:zl, 1 ; next char
|
||||
rjmp winCalcLengthWordFlash_loop
|
||||
winCalcLengthWordFlash_error:
|
||||
ldi r12, 0xff
|
||||
ldi r13, 0xff
|
||||
winCalcLengthWordFlash_ret:
|
||||
ret
|
||||
; @end
|
||||
|
||||
#endif ; if 0
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user