avr: added some unit tests for LIST and TREE.
This commit is contained in:
@@ -54,11 +54,26 @@ List_InitObject:
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine List_FiniObject @global
|
||||
;
|
||||
; @param Y pointer to object
|
||||
; @clobbers r16
|
||||
|
||||
List_FiniObject:
|
||||
clr r16 ; set this->NEXT to NULL
|
||||
std Y+LIST_OFFS_NEXT_LO, r16
|
||||
std Y+LIST_OFFS_NEXT_HI, r16
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine List_GetNextObject @global
|
||||
|
||||
; @param Y pointer to object
|
||||
; @return X pointer to parent object
|
||||
; @return X pointer to successor object
|
||||
; @clobbers none
|
||||
|
||||
List_GetNextObject:
|
||||
@@ -101,13 +116,13 @@ List_GetPredecessorFor:
|
||||
cp r16, yl
|
||||
brne List_GetPredecessorFor_next
|
||||
cp r17, yh
|
||||
breq List_GetLastObject_haveIt
|
||||
breq List_GetPredecessorFor_haveIt
|
||||
List_GetPredecessorFor_next:
|
||||
mov xl, r16
|
||||
mov xh, r17
|
||||
rjmp List_GetPredecessorFor
|
||||
List_GetPredecessorFor_haveIt:
|
||||
sbiw xh:xl, 1
|
||||
sbiw xh:xl, 2
|
||||
List_GetPredecessorFor_ret:
|
||||
ret
|
||||
; @end
|
||||
@@ -127,8 +142,14 @@ List_AddObject:
|
||||
rcall List_GetLastObject ; (r16, r17, X, Y)
|
||||
pop yh
|
||||
pop yl
|
||||
st X+, yl ; WID_OFFS_WNEXT_LO
|
||||
st X+, yh ; WID_OFFS_WNEXT_HI
|
||||
mov r16, xl
|
||||
or r16, xh
|
||||
clc
|
||||
breq List_AddObject_ret
|
||||
st X+, yl ; LIST_OFFS_NEXT_LO
|
||||
st X+, yh ; LIST_OFFS_NEXT_HI
|
||||
sec
|
||||
List_AddObject_ret:
|
||||
ret
|
||||
; @end
|
||||
|
||||
@@ -163,4 +184,68 @@ List_UnlinkObject_ret:
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine List_UnlinkAllObjects
|
||||
|
||||
; @param Y pointer to first object in a list
|
||||
; @clobbers r16, r17, r18, Y
|
||||
|
||||
List_UnlinkAllObjects:
|
||||
clr r18
|
||||
List_UnlinkAllObjects_loop:
|
||||
ldd r16, Y+LIST_OFFS_NEXT_LO
|
||||
ldd r17, Y+LIST_OFFS_NEXT_HI
|
||||
std Y+LIST_OFFS_NEXT_LO, r18
|
||||
std Y+LIST_OFFS_NEXT_HI, r18
|
||||
mov yl, r16
|
||||
mov yh, r17
|
||||
or r16, r17
|
||||
brne List_UnlinkAllObjects_loop
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine List_ForEveryObject
|
||||
;
|
||||
; Calls the given function for every object until it
|
||||
; returns with a set carry flag or until the full list
|
||||
; is handled.
|
||||
; Registers that can be used by the given function are all
|
||||
; except R16, R18 and R19 (those are used by this routine).
|
||||
;
|
||||
; @param Y pointer to first object in a list
|
||||
; @param Z routine to call for every object
|
||||
; @clobbers r16, r17, r18, r19, X, Y (r24, r25)
|
||||
|
||||
List_ForEveryObject:
|
||||
List_ForEveryObject_loop:
|
||||
ldd r18, Y+LIST_OFFS_NEXT_LO ; next
|
||||
ldd r19, Y+LIST_OFFS_NEXT_HI ; next
|
||||
clr r16
|
||||
std Y+LIST_OFFS_NEXT_LO, r16
|
||||
std Y+LIST_OFFS_NEXT_HI, r16
|
||||
push r18 ; next
|
||||
push r19 ; next
|
||||
rcall List_ForEveryObject_callZ
|
||||
pop r19 ; next
|
||||
pop r18 ; next
|
||||
brcs List_ForEveryObject_ret
|
||||
mov yl, r18
|
||||
mov yh, r19
|
||||
or r18, r19
|
||||
brne List_ForEveryObject_loop
|
||||
List_ForEveryObject_ret:
|
||||
ret
|
||||
List_ForEveryObject_callZ:
|
||||
ijmp
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif ; AQH_AVR_COMMON_LIST_H
|
||||
|
||||
240
avr/common/list_t.asm
Normal file
240
avr/common/list_t.asm
Normal file
@@ -0,0 +1,240 @@
|
||||
; ***************************************************************************
|
||||
; 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_LIST_T_H
|
||||
#define AQH_AVR_COMMON_LIST_T_H
|
||||
|
||||
|
||||
|
||||
.equ LIST_TEST_OBJECT_OFFS_LIST = 0
|
||||
.equ LIST_TEST_OBJECT_OFFS_VALUE1 = LIST_SIZE
|
||||
.equ LIST_TEST_OBJECT_OFFS_VALUE2 = LIST_SIZE+1
|
||||
.equ LIST_TEST_OBJECT_SIZE = LIST_SIZE+2
|
||||
|
||||
|
||||
|
||||
|
||||
.dseg
|
||||
|
||||
listTest_list: .byte 2
|
||||
listTest_object1: .byte LIST_TEST_OBJECT_SIZE
|
||||
listTest_object2: .byte LIST_TEST_OBJECT_SIZE
|
||||
listTest_object3: .byte LIST_TEST_OBJECT_SIZE
|
||||
|
||||
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine listTest_Object_Init
|
||||
; @param Y pointer to object to init
|
||||
; @param r18 value 1
|
||||
; @param r19 value 2
|
||||
|
||||
listTest_Object_Init:
|
||||
bigcall List_InitObject ; (R16)
|
||||
std Y+LIST_TEST_OBJECT_OFFS_VALUE1, r18
|
||||
std Y+LIST_TEST_OBJECT_OFFS_VALUE2, r19
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
listTest1:
|
||||
ldi yl, LOW(listTest_object1)
|
||||
ldi yh, HIGH(listTest_object1)
|
||||
ldi r18, 1
|
||||
ldi r19, 2
|
||||
rcall listTest_Object_Init
|
||||
sts listTest_list, yl
|
||||
sts listTest_list+1, yh
|
||||
mov xl, yl ; X=listTest_object1
|
||||
mov xh, yh
|
||||
|
||||
ldi yl, LOW(listTest_object2)
|
||||
ldi yh, HIGH(listTest_object2)
|
||||
ldi r18, 3
|
||||
ldi r19, 4
|
||||
rcall listTest_Object_Init
|
||||
|
||||
; X=object 1, Y=object 2
|
||||
bigcall List_AddObject ; (r16, r17, x)
|
||||
|
||||
lds yl, listTest_list
|
||||
lds yh, listTest_list+1
|
||||
|
||||
ldd r16, Y+LIST_TEST_OBJECT_OFFS_VALUE1
|
||||
cpi r16, 1
|
||||
ldi r16, 1
|
||||
brne listTest1_error
|
||||
ldd r16, Y+LIST_TEST_OBJECT_OFFS_VALUE2
|
||||
cpi r16, 2
|
||||
ldi r16, 2
|
||||
brne listTest1_error
|
||||
|
||||
bigcall List_GetNextObject
|
||||
ldi r16, 3
|
||||
cpi xl, LOW(listTest_object2)
|
||||
brne listTest1_error
|
||||
cpi xh, HIGH(listTest_object2)
|
||||
brne listTest1_error
|
||||
|
||||
mov yl, xl
|
||||
mov yh, xh
|
||||
ldd r16, Y+LIST_TEST_OBJECT_OFFS_VALUE1
|
||||
cpi r16, 3
|
||||
ldi r16, 4
|
||||
brne listTest1_error
|
||||
ldd r16, Y+LIST_TEST_OBJECT_OFFS_VALUE2
|
||||
cpi r16, 4
|
||||
ldi r16, 5
|
||||
brne listTest1_error
|
||||
|
||||
bigcall List_GetNextObject
|
||||
mov r16, xh
|
||||
or r16, xl
|
||||
ldi r16, 6
|
||||
brne listTest1_error
|
||||
sec
|
||||
ret
|
||||
listTest1_error:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
listTest2:
|
||||
lds xl, listTest_list
|
||||
lds xh, listTest_list+1
|
||||
|
||||
ldi yl, LOW(listTest_object3)
|
||||
ldi yh, HIGH(listTest_object3)
|
||||
ldi r18, 5
|
||||
ldi r19, 6
|
||||
rcall listTest_Object_Init
|
||||
|
||||
; X=object 1, Y=object 2
|
||||
bigcall List_AddObject ; (r16, r17, x)
|
||||
|
||||
mov xl, yl
|
||||
mov xh, yh
|
||||
bigcall List_GetLastObject
|
||||
ldi r16, 1
|
||||
cpi xl, LOW(listTest_object3)
|
||||
brne listTest2_error
|
||||
cpi xh, HIGH(listTest_object3)
|
||||
brne listTest2_error
|
||||
|
||||
mov yl, xl
|
||||
mov yh, xh
|
||||
ldd r16, Y+LIST_TEST_OBJECT_OFFS_VALUE1
|
||||
cpi r16, 5
|
||||
ldi r16, 2
|
||||
brne listTest2_error
|
||||
ldd r16, Y+LIST_TEST_OBJECT_OFFS_VALUE2
|
||||
cpi r16, 6
|
||||
ldi r16, 3
|
||||
brne listTest2_error
|
||||
|
||||
sec
|
||||
ret
|
||||
listTest2_error:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
listTest3:
|
||||
lds xl, listTest_list
|
||||
lds xh, listTest_list+1
|
||||
ldi yl, LOW(listTest_object2)
|
||||
ldi yh, HIGH(listTest_object2)
|
||||
bigcall List_UnlinkObject
|
||||
|
||||
lds yl, listTest_list
|
||||
lds yh, listTest_list+1
|
||||
|
||||
ldd r16, Y+LIST_TEST_OBJECT_OFFS_VALUE1
|
||||
cpi r16, 1
|
||||
ldi r16, 1
|
||||
brne listTest3_error
|
||||
ldd r16, Y+LIST_TEST_OBJECT_OFFS_VALUE2
|
||||
cpi r16, 2
|
||||
ldi r16, 2
|
||||
brne listTest3_error
|
||||
|
||||
bigcall List_GetNextObject
|
||||
ldi r16, 3
|
||||
cpi xl, LOW(listTest_object3)
|
||||
brne listTest3_error
|
||||
cpi xh, HIGH(listTest_object3)
|
||||
brne listTest3_error
|
||||
|
||||
mov yl, xl
|
||||
mov yh, xh
|
||||
ldd r16, Y+LIST_TEST_OBJECT_OFFS_VALUE1
|
||||
cpi r16, 5
|
||||
ldi r16, 4
|
||||
brne listTest3_error
|
||||
ldd r16, Y+LIST_TEST_OBJECT_OFFS_VALUE2
|
||||
cpi r16, 6
|
||||
ldi r16, 5
|
||||
brne listTest3_error
|
||||
|
||||
bigcall List_GetNextObject
|
||||
mov r16, xh
|
||||
or r16, xl
|
||||
ldi r16, 6
|
||||
brne listTest3_error
|
||||
sec
|
||||
ret
|
||||
listTest3_error:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
listTest4:
|
||||
lds xl, listTest_list
|
||||
lds xh, listTest_list+1
|
||||
ldi yl, LOW(listTest_object3)
|
||||
ldi yh, HIGH(listTest_object3)
|
||||
bigcall List_UnlinkObject
|
||||
|
||||
lds yl, listTest_list
|
||||
lds yh, listTest_list+1
|
||||
|
||||
ldd r16, Y+LIST_TEST_OBJECT_OFFS_VALUE1
|
||||
cpi r16, 1
|
||||
ldi r16, 1
|
||||
brne listTest4_error
|
||||
ldd r16, Y+LIST_TEST_OBJECT_OFFS_VALUE2
|
||||
cpi r16, 2
|
||||
ldi r16, 2
|
||||
brne listTest4_error
|
||||
|
||||
bigcall List_GetNextObject
|
||||
mov r16, xh
|
||||
or r16, xl
|
||||
ldi r16, 6
|
||||
brne listTest4_error
|
||||
sec
|
||||
ret
|
||||
listTest4_error:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -17,10 +17,10 @@
|
||||
; defs
|
||||
|
||||
.equ TREE_OFFS_LIST = 0
|
||||
.equ TREE_OFFS_WPARENT_LO = TREE_OFFS_LIST+LIST_SIZE
|
||||
.equ TREE_OFFS_WPARENT_HI = TREE_OFFS_LIST+LIST_SIZE+1
|
||||
.equ TREE_OFFS_WCHILD_LO = TREE_OFFS_LIST+LIST_SIZE+2
|
||||
.equ TREE_OFFS_WCHILD_HI = TREE_OFFS_LIST+LIST_SIZE+3
|
||||
.equ TREE_OFFS_PARENT_LO = TREE_OFFS_LIST+LIST_SIZE
|
||||
.equ TREE_OFFS_PARENT_HI = TREE_OFFS_LIST+LIST_SIZE+1
|
||||
.equ TREE_OFFS_CHILD_LO = TREE_OFFS_LIST+LIST_SIZE+2
|
||||
.equ TREE_OFFS_CHILD_HI = TREE_OFFS_LIST+LIST_SIZE+3
|
||||
.equ TREE_SIZE = TREE_OFFS_LIST+LIST_SIZE+4
|
||||
|
||||
|
||||
@@ -42,10 +42,10 @@
|
||||
Tree_InitObject:
|
||||
rcall List_InitObject ; (R16)
|
||||
clr r16 ; clear this->TREE data
|
||||
std Y+TREE_OFFS_LIST+TREE_OFFS_WPARENT_LO, r16
|
||||
std Y+TREE_OFFS_LIST+TREE_OFFS_WPARENT_HI, r16
|
||||
std Y+TREE_OFFS_LIST+TREE_OFFS_WCHILD_LO, r16
|
||||
std Y+TREE_OFFS_LIST+TREE_OFFS_WCHILD_HI, r16
|
||||
std Y+TREE_OFFS_LIST+TREE_OFFS_PARENT_LO, r16
|
||||
std Y+TREE_OFFS_LIST+TREE_OFFS_PARENT_HI, r16
|
||||
std Y+TREE_OFFS_LIST+TREE_OFFS_CHILD_LO, r16
|
||||
std Y+TREE_OFFS_LIST+TREE_OFFS_CHILD_HI, r16
|
||||
ret
|
||||
; @end
|
||||
|
||||
@@ -59,8 +59,8 @@ Tree_InitObject:
|
||||
; @clobbers none
|
||||
|
||||
Tree_GetParentObject:
|
||||
ldd xl, Y+TREE_OFFS_WPARENT_LO
|
||||
ldd xh, Y+TREE_OFFS_WPARENT_HI
|
||||
ldd xl, Y+TREE_OFFS_PARENT_LO
|
||||
ldd xh, Y+TREE_OFFS_PARENT_HI
|
||||
ret
|
||||
; @end
|
||||
|
||||
@@ -74,13 +74,46 @@ Tree_GetParentObject:
|
||||
; @clobbers none
|
||||
|
||||
Tree_GetFirstChildObject:
|
||||
ldd xl, Y+TREE_OFFS_WCHILD_LO
|
||||
ldd xh, Y+TREE_OFFS_WCHILD_HI
|
||||
ldd xl, Y+TREE_OFFS_CHILD_LO
|
||||
ldd xh, Y+TREE_OFFS_CHILD_HI
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Tree_GetLastChildObject @global
|
||||
|
||||
; @param Y pointer to object
|
||||
; @return X pointer to last child object
|
||||
; @clobbers none
|
||||
|
||||
Tree_GetLastChildObject:
|
||||
ldd xl, Y+TREE_OFFS_CHILD_LO
|
||||
ldd xh, Y+TREE_OFFS_CHILD_HI
|
||||
mov r16, xl
|
||||
or r16, xh
|
||||
breq Tree_GetLastChildObject_ret
|
||||
rcall List_GetLastObject
|
||||
Tree_GetLastChildObject_ret:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Tree_GetNextSibling @global
|
||||
|
||||
; @param Y pointer to object
|
||||
; @return X pointer to successor object
|
||||
; @clobbers none
|
||||
|
||||
Tree_GetNextSibling:
|
||||
rjmp List_GetNextObject
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Tree_GetObjectBelow @global
|
||||
|
||||
@@ -101,7 +134,7 @@ treeGetObjectBelow:
|
||||
mov r16, xl
|
||||
or r16, xh
|
||||
brne treeGetObjectBelow_ret ; got one
|
||||
rcall List_GetNextObject
|
||||
rcall Tree_GetNextSibling
|
||||
mov r16, xl
|
||||
or r16, xh
|
||||
brne treeGetObjectBelow_ret ; got one
|
||||
@@ -122,27 +155,27 @@ treeGetObjectBelow_ret:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Tree_AddChildObject @global
|
||||
|
||||
; @param X pointer to parent to add to
|
||||
; @param Y pointer to object to add
|
||||
; @param X pointer to parent to add to
|
||||
; @clobbers r16, r17, r18, x
|
||||
|
||||
Tree_AddChildObject:
|
||||
std Y+TREE_OFFS_WPARENT_LO, xl ; immediately store parent pointer
|
||||
std Y+TREE_OFFS_WPARENT_HI, xh
|
||||
adiw xh:xl, TREE_OFFS_WCHILD_LO
|
||||
std Y+TREE_OFFS_PARENT_LO, xl ; immediately store parent pointer
|
||||
std Y+TREE_OFFS_PARENT_HI, xh
|
||||
adiw xh:xl, TREE_OFFS_CHILD_LO ; read pointer to first child
|
||||
ld r16, X+
|
||||
ld r17, X
|
||||
mov r18, r16
|
||||
or r18, r17
|
||||
brne Tree_AddChildObject_addToChildList
|
||||
st X, yh ; no child, set THIS as first
|
||||
st X, yh ; no child, set THIS as first
|
||||
st -X, yl
|
||||
sbiw xh:xl, WID_OFFS_TREE+TREE_OFFS_WCHILD_LO
|
||||
sbiw xh:xl, TREE_OFFS_CHILD_LO
|
||||
ret
|
||||
Tree_AddChildObject_addToChildList:
|
||||
mov xl, r16
|
||||
mov xl, r16 ; X=first child
|
||||
mov xh, r17
|
||||
rjmp List_AddObject
|
||||
rjmp List_AddObject ; add Y as new object
|
||||
; @end
|
||||
|
||||
|
||||
@@ -154,17 +187,17 @@ Tree_AddChildObject_addToChildList:
|
||||
; @clobbers r16, r17, x
|
||||
|
||||
Tree_UnlinkObject:
|
||||
ldd xl, Y+TREE_OFFS_WPARENT_LO
|
||||
ldd xh, Y+TREE_OFFS_WPARENT_HI
|
||||
ldd xl, Y+TREE_OFFS_PARENT_LO
|
||||
ldd xh, Y+TREE_OFFS_PARENT_HI
|
||||
mov r16, xl
|
||||
or r16, xh
|
||||
breq Tree_UnlinkObject_ret ; not part of a tree
|
||||
adiw xh:xl, TREE_OFFS_WCHILD_LO ; get parent's first child to R17:R16
|
||||
adiw xh:xl, TREE_OFFS_CHILD_LO ; get parent's first child to R17:R16
|
||||
ld r16, X+
|
||||
ld r17, X
|
||||
cp r16, yl ; same as THIS?
|
||||
brne Tree_UnlinkObject_inList ; nope, need to check childList
|
||||
cp r17, yh
|
||||
cp r17, yh ; same as THIS?
|
||||
brne Tree_UnlinkObject_inList ; nope, need to check childList
|
||||
ldd r16, Y+TREE_OFFS_LIST+LIST_OFFS_NEXT_HI ; is first child, set this->NEXT as new first child
|
||||
st X, r16
|
||||
@@ -177,8 +210,8 @@ Tree_UnlinkObject_inList:
|
||||
rcall List_UnlinkObject ; (R16, R17, X)
|
||||
Tree_UnlinkObject_clrParentAndSibling:
|
||||
clr r16 ; clear this->PARENT
|
||||
std Y+TREE_OFFS_LIST+TREE_OFFS_WPARENT_LO, r16
|
||||
std Y+TREE_OFFS_LIST+TREE_OFFS_WPARENT_HI, r16
|
||||
std Y+TREE_OFFS_PARENT_LO, r16
|
||||
std Y+TREE_OFFS_PARENT_HI, r16
|
||||
std Y+LIST_OFFS_NEXT_LO, r16
|
||||
std Y+LIST_OFFS_NEXT_HI, r16 ; clear this->NEXT
|
||||
Tree_UnlinkObject_ret:
|
||||
@@ -188,5 +221,6 @@ Tree_UnlinkObject_ret:
|
||||
|
||||
|
||||
|
||||
|
||||
#endif ; AQH_AVR_COMMON_TREE_H
|
||||
|
||||
|
||||
381
avr/common/tree_t.asm
Normal file
381
avr/common/tree_t.asm
Normal file
@@ -0,0 +1,381 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
|
||||
.equ TREE_TEST_OBJECT_OFFS_LIST = 0
|
||||
.equ TREE_TEST_OBJECT_OFFS_VALUE1 = TREE_SIZE
|
||||
.equ TREE_TEST_OBJECT_OFFS_VALUE2 = TREE_SIZE+1
|
||||
.equ TREE_TEST_OBJECT_SIZE = TREE_SIZE+2
|
||||
|
||||
|
||||
|
||||
.dseg
|
||||
|
||||
testTree_root: .byte TREE_TEST_OBJECT_SIZE
|
||||
testTree_child1: .byte TREE_TEST_OBJECT_SIZE
|
||||
testTree_child2: .byte TREE_TEST_OBJECT_SIZE
|
||||
testTree_child3: .byte TREE_TEST_OBJECT_SIZE
|
||||
|
||||
|
||||
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine treeTest_Object_Init
|
||||
; @param Y pointer to object to init
|
||||
; @param r18 value 1
|
||||
; @param r19 value 2
|
||||
|
||||
treeTest_Object_Init:
|
||||
bigcall Tree_InitObject ; (R16)
|
||||
std Y+TREE_TEST_OBJECT_OFFS_VALUE1, r18
|
||||
std Y+TREE_TEST_OBJECT_OFFS_VALUE2, r19
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
treeTest1:
|
||||
ldi yl, LOW(testTree_root)
|
||||
ldi yh, HIGH(testTree_root)
|
||||
ldi r18, 1
|
||||
ldi r19, 2
|
||||
rcall treeTest_Object_Init
|
||||
mov xl, yl
|
||||
mov xh, yh
|
||||
|
||||
rcall treeTestCreateAndAddChild1
|
||||
ldi r16, 1 ; error code
|
||||
brcc treeTest1_error
|
||||
|
||||
rcall treeTestCreateAndAddChild2
|
||||
ldi r16, 2 ; error code
|
||||
brcc treeTest1_error
|
||||
|
||||
rcall treeTestCreateAndAddChild3
|
||||
ldi r16, 3 ; error code
|
||||
brcc treeTest1_error
|
||||
|
||||
ldi yl, LOW(testTree_root)
|
||||
ldi yh, HIGH(testTree_root)
|
||||
bigcall Tree_GetFirstChildObject
|
||||
ldi r16, 4 ; error code
|
||||
cpi xl, LOW(testTree_child1)
|
||||
brne treeTest1_error
|
||||
cpi xh, HIGH(testTree_child1)
|
||||
brne treeTest1_error
|
||||
|
||||
mov yl, xl
|
||||
mov yh, xh
|
||||
ldd r16, Y+TREE_TEST_OBJECT_OFFS_VALUE1
|
||||
cpi r16, 3
|
||||
ldi r16, 5 ; error code
|
||||
brne treeTest1_error
|
||||
ldd r16, Y+TREE_TEST_OBJECT_OFFS_VALUE2
|
||||
cpi r16, 4
|
||||
ldi r16, 6 ; error code
|
||||
brne treeTest1_error
|
||||
|
||||
rcall treeTestNextSiblingIs2
|
||||
ldi r16, 7 ; error code
|
||||
brcc treeTest1_error
|
||||
|
||||
rcall treeTestNextSiblingIs3
|
||||
ldi r16, 8 ; error code
|
||||
brcc treeTest1_error
|
||||
|
||||
rcall treeTestNextSiblingIsNull
|
||||
ldi r16, 9 ; error code
|
||||
brcc treeTest1_error
|
||||
|
||||
sec
|
||||
ret
|
||||
|
||||
treeTest1_error:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
treeTest2:
|
||||
ldi yl, LOW(testTree_child2)
|
||||
ldi yh, HIGH(testTree_child2)
|
||||
bigcall Tree_UnlinkObject
|
||||
|
||||
rcall treeTestCheckParentNull
|
||||
ldi r16, 1 ; error code
|
||||
brcc treeTest2_error
|
||||
|
||||
bigcall Tree_GetNextSibling
|
||||
mov r16, xl
|
||||
or r16, xh
|
||||
ldi r16, 2 ; error code
|
||||
brne treeTest2_error
|
||||
|
||||
ldi yl, LOW(testTree_root)
|
||||
ldi yh, HIGH(testTree_root)
|
||||
bigcall Tree_GetFirstChildObject
|
||||
ldi r16, 3 ; error code
|
||||
cpi xl, LOW(testTree_child1)
|
||||
brne treeTest2_error
|
||||
cpi xh, HIGH(testTree_child1)
|
||||
brne treeTest2_error
|
||||
mov yl, xl
|
||||
mov yh, xh
|
||||
|
||||
rcall treeTestNextSiblingIs3
|
||||
ldi r16, 4 ; error code
|
||||
brcc treeTest2_error
|
||||
|
||||
sec
|
||||
ret
|
||||
treeTest2_error:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
treeTest3:
|
||||
ldi yl, LOW(testTree_child1)
|
||||
ldi yh, HIGH(testTree_child1)
|
||||
bigcall Tree_UnlinkObject
|
||||
|
||||
rcall treeTestCheckParentNull
|
||||
ldi r16, 1 ; error code
|
||||
brcc treeTest3_error
|
||||
|
||||
bigcall Tree_GetNextSibling
|
||||
mov r16, xl
|
||||
or r16, xh
|
||||
ldi r16, 2 ; error code
|
||||
brne treeTest3_error
|
||||
|
||||
ldi yl, LOW(testTree_root)
|
||||
ldi yh, HIGH(testTree_root)
|
||||
bigcall Tree_GetFirstChildObject
|
||||
ldi r16, 3 ; error code
|
||||
cpi xl, LOW(testTree_child3)
|
||||
brne treeTest3_error
|
||||
cpi xh, HIGH(testTree_child3)
|
||||
brne treeTest3_error
|
||||
mov yl, xl
|
||||
mov yh, xh
|
||||
|
||||
rcall treeTestNextSiblingIsNull
|
||||
ldi r16, 4 ; error code
|
||||
brcc treeTest3_error
|
||||
|
||||
sec
|
||||
ret
|
||||
treeTest3_error:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
treeTest4:
|
||||
ldi yl, LOW(testTree_child1)
|
||||
ldi yh, HIGH(testTree_child1)
|
||||
ldi xl, LOW(testTree_root)
|
||||
ldi xh, HIGH(testTree_root)
|
||||
bigcall Tree_AddChildObject
|
||||
|
||||
rcall treeTestCheckParentRoot
|
||||
ldi r16, 1 ; error code
|
||||
brcc treeTest4_error
|
||||
|
||||
ldi yl, LOW(testTree_root)
|
||||
ldi yh, HIGH(testTree_root)
|
||||
bigcall Tree_GetFirstChildObject
|
||||
ldi r16, 2 ; error code
|
||||
cpi xl, LOW(testTree_child3)
|
||||
brne treeTest4_error
|
||||
cpi xh, HIGH(testTree_child3)
|
||||
brne treeTest4_error
|
||||
mov yl, xl
|
||||
mov yh, xh
|
||||
|
||||
rcall treeTestNextSiblingIs1
|
||||
ldi r16, 3 ; error code
|
||||
brcc treeTest4_error
|
||||
|
||||
rcall treeTestNextSiblingIsNull
|
||||
ldi r16, 4 ; error code
|
||||
brcc treeTest4_error
|
||||
|
||||
sec
|
||||
ret
|
||||
treeTest4_error:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
treeTestCreateAndAddChild1:
|
||||
ldi yl, LOW(testTree_child1)
|
||||
ldi yh, HIGH(testTree_child1)
|
||||
ldi r18, 3
|
||||
ldi r19, 4
|
||||
rcall treeTest_Object_Init
|
||||
|
||||
ldi xl, LOW(testTree_root)
|
||||
ldi xh, HIGH(testTree_root)
|
||||
bigcall Tree_AddChildObject
|
||||
|
||||
rcall treeTestCheckParentRoot
|
||||
brcc treeTestCreateAndAddChild1_error
|
||||
sec
|
||||
ret
|
||||
treeTestCreateAndAddChild1_error:
|
||||
clc
|
||||
ret
|
||||
|
||||
|
||||
|
||||
treeTestCreateAndAddChild2:
|
||||
ldi yl, LOW(testTree_child2)
|
||||
ldi yh, HIGH(testTree_child2)
|
||||
ldi r18, 5
|
||||
ldi r19, 6
|
||||
rcall treeTest_Object_Init
|
||||
|
||||
ldi xl, LOW(testTree_root)
|
||||
ldi xh, HIGH(testTree_root)
|
||||
bigcall Tree_AddChildObject
|
||||
|
||||
rcall treeTestCheckParentRoot
|
||||
brcc treeTestCreateAndAddChild2_error
|
||||
sec
|
||||
ret
|
||||
treeTestCreateAndAddChild2_error:
|
||||
clc
|
||||
ret
|
||||
|
||||
|
||||
|
||||
treeTestCreateAndAddChild3:
|
||||
ldi yl, LOW(testTree_child3)
|
||||
ldi yh, HIGH(testTree_child3)
|
||||
ldi r18, 7
|
||||
ldi r19, 8
|
||||
rcall treeTest_Object_Init
|
||||
|
||||
ldi xl, LOW(testTree_root)
|
||||
ldi xh, HIGH(testTree_root)
|
||||
bigcall Tree_AddChildObject
|
||||
|
||||
rcall treeTestCheckParentRoot
|
||||
brcc treeTestCreateAndAddChild3_error
|
||||
sec
|
||||
ret
|
||||
treeTestCreateAndAddChild3_error:
|
||||
clc
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
treeTestCheckParentNull:
|
||||
bigcall Tree_GetParentObject
|
||||
mov r16, xl
|
||||
or r16, xh
|
||||
brne treeTestCheckParentNull_error
|
||||
sec
|
||||
ret
|
||||
treeTestCheckParentNull_error:
|
||||
clc
|
||||
ret
|
||||
|
||||
|
||||
|
||||
treeTestCheckParentRoot:
|
||||
bigcall Tree_GetParentObject
|
||||
cpi xl, LOW(testTree_root)
|
||||
brne treeTestCheckParentRoot_error
|
||||
cpi xh, HIGH(testTree_root)
|
||||
brne treeTestCheckParentRoot_error
|
||||
sec
|
||||
ret
|
||||
treeTestCheckParentRoot_error:
|
||||
clc
|
||||
ret
|
||||
|
||||
|
||||
|
||||
treeTestNextSiblingIs1:
|
||||
bigcall Tree_GetNextSibling
|
||||
cpi xl, LOW(testTree_child1)
|
||||
brne treeTestNextSiblingIs1_error
|
||||
cpi xh, HIGH(testTree_child1)
|
||||
brne treeTestNextSiblingIs1_error
|
||||
mov yl, xl
|
||||
mov yh, xh
|
||||
sec
|
||||
ret
|
||||
treeTestNextSiblingIs1_error:
|
||||
clc
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
treeTestNextSiblingIs2:
|
||||
bigcall Tree_GetNextSibling
|
||||
cpi xl, LOW(testTree_child2)
|
||||
brne treeTestNextSiblingIs2_error
|
||||
cpi xh, HIGH(testTree_child2)
|
||||
brne treeTestNextSiblingIs2_error
|
||||
mov yl, xl
|
||||
mov yh, xh
|
||||
sec
|
||||
ret
|
||||
treeTestNextSiblingIs2_error:
|
||||
clc
|
||||
ret
|
||||
|
||||
|
||||
treeTestNextSiblingIs3:
|
||||
bigcall Tree_GetNextSibling
|
||||
cpi xl, LOW(testTree_child3)
|
||||
brne treeTestNextSiblingIs3_error
|
||||
cpi xh, HIGH(testTree_child3)
|
||||
brne treeTestNextSiblingIs3_error
|
||||
mov yl, xl
|
||||
mov yh, xh
|
||||
sec
|
||||
ret
|
||||
treeTestNextSiblingIs3_error:
|
||||
clc
|
||||
ret
|
||||
|
||||
|
||||
|
||||
treeTestNextSiblingIsNull:
|
||||
bigcall Tree_GetNextSibling
|
||||
mov r16, xl
|
||||
or r16, xh
|
||||
brne treeTestNextSiblingIsNull_error
|
||||
sec
|
||||
ret
|
||||
treeTestNextSiblingIsNull_error:
|
||||
clc
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -165,6 +165,20 @@
|
||||
.include "modules/lcd2/ili9341/text.asm"
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_FONT
|
||||
.include "modules/lcd2/font/defs.asm"
|
||||
.include "modules/lcd2/font/main.asm"
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_WIN
|
||||
.include "common/list.asm"
|
||||
.include "common/tree.asm"
|
||||
.include "modules/lcd2/win/defs.asm"
|
||||
.include "modules/lcd2/win/object.asm"
|
||||
.include "modules/lcd2/win/widget.asm"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef MODULES_FONT_8X8
|
||||
.include "modules/lcd2/font/defs.asm"
|
||||
.include "modules/lcd2/font/font8x8.asm"
|
||||
|
||||
@@ -38,15 +38,6 @@
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; heap
|
||||
|
||||
.equ HEAP_START = SRAM_START+0x200
|
||||
.equ HEAP_SIZE = SRAM_SIZE-HEAP_START
|
||||
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; firmware settings including list of modules used
|
||||
|
||||
@@ -61,9 +52,8 @@
|
||||
#define MODULES_UART_BITBANG
|
||||
#define MODULES_SPI_HW
|
||||
#define MODULES_ILI9341
|
||||
;#define MODULES_FONT_8X8
|
||||
#define MODULES_FONT_6X8
|
||||
;#define MODULES_UART_BITBANG
|
||||
#define MODULES_FONT
|
||||
#define MODULES_WIN
|
||||
;#define MODULES_TWI_MASTER
|
||||
;#define MODULES_LCD
|
||||
;#define LCD_MINIMAL_FONT
|
||||
@@ -229,9 +219,15 @@ onEveryLoop:
|
||||
|
||||
;.include "common/debug.asm"
|
||||
|
||||
.include "modules/lcd2/font/font3.asm"
|
||||
.include "modules/lcd2/font/font16x26.asm"
|
||||
|
||||
;.include "modules/lcd2/font/font2.asm"
|
||||
;.include "modules/lcd2/font/font3.asm"
|
||||
;.include "modules/lcd2/font/font16x26.asm"
|
||||
;.include "modules/lcd2/font/font4.asm"
|
||||
;.include "modules/lcd2/font/font12x16.asm"
|
||||
.include "modules/lcd2/font/font5.asm"
|
||||
.include "modules/lcd2/font/font12x20.asm"
|
||||
;.include "common/list_t.asm"
|
||||
.include "common/tree_t.asm"
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
@@ -314,8 +310,10 @@ test:
|
||||
mov r7, r16
|
||||
|
||||
; set font
|
||||
ldi zl, LOW(font3_16x26*2)
|
||||
ldi zh, HIGH(font3_16x26*2)
|
||||
; ldi zl, LOW(font3_16x26*2)
|
||||
; ldi zh, HIGH(font3_16x26*2)
|
||||
ldi zl, LOW(font5_12x20*2)
|
||||
ldi zh, HIGH(font5_12x20*2)
|
||||
|
||||
; set buffer
|
||||
ldi xl, LOW(glyphBuffer)
|
||||
@@ -340,15 +338,110 @@ test:
|
||||
ldi r16, 'E'
|
||||
bigcall ili9341_WriteCharacterX1At
|
||||
|
||||
#if 0
|
||||
push xl
|
||||
push xh
|
||||
rcall listTest1
|
||||
pop xh
|
||||
pop xl
|
||||
brcc test_error
|
||||
ldi r16, '!'
|
||||
bigcall ili9341_WriteCharacterX1At
|
||||
|
||||
push xl
|
||||
push xh
|
||||
rcall listTest2
|
||||
pop xh
|
||||
pop xl
|
||||
brcc test_error
|
||||
ldi r16, '!'
|
||||
bigcall ili9341_WriteCharacterX1At
|
||||
|
||||
push xl
|
||||
push xh
|
||||
rcall listTest3
|
||||
pop xh
|
||||
pop xl
|
||||
brcc test_error
|
||||
ldi r16, '!'
|
||||
bigcall ili9341_WriteCharacterX1At
|
||||
|
||||
push xl
|
||||
push xh
|
||||
rcall listTest4
|
||||
pop xh
|
||||
pop xl
|
||||
brcc test_error
|
||||
ldi r16, '!'
|
||||
bigcall ili9341_WriteCharacterX1At
|
||||
#endif
|
||||
|
||||
|
||||
#if 1
|
||||
push xl
|
||||
push xh
|
||||
rcall treeTest1
|
||||
pop xh
|
||||
pop xl
|
||||
brcc test_error
|
||||
ldi r16, '!'
|
||||
bigcall ili9341_WriteCharacterX1At
|
||||
|
||||
push xl
|
||||
push xh
|
||||
rcall treeTest2
|
||||
pop xh
|
||||
pop xl
|
||||
brcc test_error
|
||||
ldi r16, '!'
|
||||
bigcall ili9341_WriteCharacterX1At
|
||||
|
||||
push xl
|
||||
push xh
|
||||
rcall treeTest3
|
||||
pop xh
|
||||
pop xl
|
||||
brcc test_error
|
||||
ldi r16, '!'
|
||||
bigcall ili9341_WriteCharacterX1At
|
||||
|
||||
push xl
|
||||
push xh
|
||||
rcall treeTest4
|
||||
pop xh
|
||||
pop xl
|
||||
brcc test_error
|
||||
ldi r16, '!'
|
||||
bigcall ili9341_WriteCharacterX1At
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
ret
|
||||
|
||||
test_error:
|
||||
ldi r17, '0'
|
||||
add r16, r17
|
||||
bigcall ili9341_WriteCharacterX1At
|
||||
|
||||
|
||||
ret
|
||||
|
||||
|
||||
|
||||
helloWorld: .db "Hello World", 0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.dseg
|
||||
|
||||
glyphBuffer: .byte 1024
|
||||
heapStart:
|
||||
|
||||
|
||||
.equ HEAP_START = heapStart
|
||||
.equ HEAP_SIZE = SRAM_SIZE-HEAP_START
|
||||
|
||||
|
||||
@@ -72,6 +72,19 @@ Heap_Init:
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Heap_Alloc
|
||||
;
|
||||
; @param r25:r24 number of bytes to alloc
|
||||
; @return CFLAG set of okay, cleared otherwise
|
||||
; @return X start of allocated memory
|
||||
|
||||
Heap_Alloc:
|
||||
rjmp heapAllocFirstFit
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine heapAllocFirstFit
|
||||
|
||||
Reference in New Issue
Block a user