TABLE OF CONTENTS
- /Common
- Common/Os_search_option
- Common/Get_lsb_b
- Common/Get_msb_b
- Common/Get_msb_w
- Common/Getbyte
- Common/Getword
- Common/Os_double_list_insert
- Common/Os_double_list_remove
- Common/Os_double_list_search
- Common/Os_enter_critical
- Common/Os_exit_critical
- Common/Os_list_getnext
- Common/Os_list_insert
- Common/Os_list_remove
- Common/Os_mem_clear
- Common/Os_mem_copy
- Common/Setbyte
- Common/Setword
/Common [ Modules ]
DESCRIPTION
Contains commonly used, generic functions
Common/Os_search_option [ Constants ]
[ Top ] [ Common ] [ Constants ]
DESCRIPTION
criteria to search for
DECLARATION
Const Os_options_search_equal = 1 Const Os_options_search_greater = 2 Const Os_options_search_less = 3
Common/Get_lsb_b [ Functions ]
[ Top ] [ Common ] [ Functions ]
DESCRIPTION
DECLARATION
Function Get_lsb_b(byval X As Byte) As Byte
SEE ALSO
Common/Get_msb_w
SOURCE
Local Y As Byte , Found As Byte Found = 1 If X = 0 Then Get_lsb_b = 0 Exit Function End If Y = X And &HF If Y = 0 Then Shift X , Right , 4 Found = Found + 4 End If Y = X And 3 If Y = 0 Then Shift X , Right , 2 Found = Found + 2 End If Y = X And 1 If Y = 0 Then Found = Found + 1 End If Get_lsb_b = Found End Function
Common/Get_msb_b [ Functions ]
[ Top ] [ Common ] [ Functions ]
DESCRIPTION
Returns the position of the most significant bit set, zero if not found
DECLARATION
Function Get_msb_b(byval X As Byte) As Byte
SEE ALSO
Common/Get_msb_w, Common/Get_lsb_b
SOURCE
Local Y As Byte , Found As Byte Found = 8 If X = 0 Then Get_msb_w = 0 Exit Function End If Y = X And &HF0 If Y = 0 Then Shift X , Left , 4 Found = Found - 4 End If Y = X And &HC0 If Y = 0 Then Shift X , Left , 2 Found = Found - 2 End If Y = X And &H80 If Y = 0 Then Found = Found - 1 End If Get_msb_w = Found End Function
Common/Get_msb_w [ Functions ]
[ Top ] [ Common ] [ Functions ]
DESCRIPTION
Returns the position of the most significant bit set, zero if not found
DECLARATION
Function Get_msb_w(byval X As Word) As Byte
SEE ALSO
Common/Get_lsb_b
SOURCE
Local Y As Word , Found As Byte Found = 16 If X = 0 Then Get_msb_w = 0 Exit Function End If Y = X And &HFF00 If Y = 0 Then Shift X , Left , 8 Found = Found - 8 End If Y = X And &HF000 If Y = 0 Then Shift X , Left , 4 Found = Found - 4 End If Y = X And &HC000 If Y = 0 Then Shift X , Left , 2 Found = Found - 2 End If Y = X And &H8000 If Y = 0 Then Found = Found - 1 End If Get_msb_w = Found End Function
Common/Getbyte [ Functions ]
[ Top ] [ Common ] [ Functions ]
DESCRIPTION
Reads a byte value from the memory location addressed by pointer and offset
DECLARATION
Function Getbyte(byref Address As Word , Byval Offset As Word) As Byte
SEE ALSO
Common/Setbyte, Common/Setword, Common/Getword
SOURCE
' load parameter Address ' ldd R26, Y+2 LDD R27, Y+3 LD R16, X+ LD R17, X ' load parameter Offset ' LDD R26, Y+0 LDD R27, Y+1 LD R20, X+ LD R21, X ' add ' add R16, R20 aDC R17, R21 ' move Address -> X ' mov R26, R16 MOV R27, R17 ' load data ' LD R20, X ' return data ' LDD R26, Y+4 LDD R27, Y+5 ST X, R20 End Function
Common/Getword [ Functions ]
[ Top ] [ Common ] [ Functions ]
DESCRIPTION
Reads a word value from the memory location addressed by pointer and offset
DECLARATION
Function Getword(byref Address As Word , Byval Offset As Word) As Word
SEE ALSO
Common/Setword, Common/Setbyte, Common/Getbyte
SOURCE
' load parameter Address ' ldd R26, Y+2 LDD R27, Y+3 LD R16, X+ LD R17, X ' load parameter Offset ' LDD R26, Y+0 LDD R27, Y+1 LD R20, X+ LD R21, X ' add ' add R16, R20 aDC R17, R21 ' move Address -> X ' mov R26, R16 MOV R27, R17 ' load data ' LD R20, X+ LD R21, X ' return data ' LDD R26, Y+4 LDD R27, Y+5 ST X+, R20 ST X, R21 End Function
Common/Os_double_list_insert [ Functions ]
[ Top ] [ Common ] [ Functions ]
DESCRIPTION
Inserts an element into a double linked list
DECLARATION
Sub Os_double_list_insert(byref Listhead As Word , Byref Object As Word , Byval Next_ptr_offset As Word , Byval Prev_ptr_offset As Word)
SEE ALSO
Common/Os_double_list_remove, Common/Os_double_list_search
SOURCE
Local Tempblock As Word Local Listblock As Word If Listhead = 0 Then Setword Object , Next_ptr_offset , Object Setword Object , Prev_ptr_offset , Object Listhead = Object Else Tempblock = Getword(listhead , Next_ptr_offset) Listblock = Getword(tempblock , Prev_ptr_offset) Setword Object , Next_ptr_offset , Tempblock Setword Object , Prev_ptr_offset , Listhead Setword Listhead , Next_ptr_offset , Object Setword Listblock , Prev_ptr_offset , Object End If End Sub
Common/Os_double_list_remove [ Functions ]
[ Top ] [ Common ] [ Functions ]
DESCRIPTION
Removes an object from a double linked list
DECLARATION
Sub Os_double_list_remove(byref Listhead As Word , Byref Object As Word , Byval Next_ptr_offset As Word , Byval Prev_ptr_offset As Word)
SEE ALSO
Common/Os_double_list_insert, Common/Os_double_list_search
SOURCE
Local Prev_object As Word Local Next_object As Word If Object = Listhead Then Listhead = 0 Else Next_object = Getword(object , Next_ptr_offset) Prev_object = Getword(object , Prev_ptr_offset) Setword Next_object , Prev_ptr_offset , Prev_object Setword Prev_object , Next_ptr_offset , Next_object End If Setword Object , Next_ptr_offset , 0 Setword Object , Prev_ptr_offset , 0 End Sub
Common/Os_double_list_search [ Functions ]
[ Top ] [ Common ] [ Functions ]
DESCRIPTION
Searches for an element in a double linked list. matches elements with values that are equal, greater or less.
DECLARATION
Sub Os_double_list_search(byref Object As Word , Byval Next_ptr_offset As Word , Byval Value_ptr_offset As Word , Byval Value As Word , Byval Options As Byte)
SEE ALSO
Common/Os_double_list_insert, Common/Os_double_list_remove
SOURCE
Local Startobject As Word Local Objectvalue As Word Startobject = Object Do Objectvalue = Getword(object , Value_ptr_offset) Select Case Options Case Os_options_search_equal If Objectvalue = Value Then Exit Do Case Os_options_search_greater If Value < Objectvalue Then Exit Do Case Os_options_search_less If Objectvalue < Value Then Exit Do End Select Object = Getword(object , Next_ptr_offset) If Object = Startobject Then Exit Do Loop End Sub
Common/Os_enter_critical [ Functions ]
[ Top ] [ Common ] [ Functions ]
DESCRIPTION
Begins a critical section (accessing shared resources). Deactivates global interrupts at first call and increments recoursive call count.
DECLARATION
Sub Os_enter_critical()
SEE ALSO
Common/Os_exit_critical
SOURCE
' first nesting level? ' lds R16, {Os_critical_nesting_level} cpi R16, 0 brne Os_enter_critical_2 ' no other Task should interfere by now ' cli Os_enter_critical_2: ' increment recoursive call count ' inc R16 sts {Os_critical_nesting_level}, R16 End Sub
Common/Os_exit_critical [ Functions ]
[ Top ] [ Common ] [ Functions ]
DESCRIPTION
Ends a critical section (finished accessing a shared resource). Decrements the recoursive call count and enables global interrupts after last finished section.
DECLARATION
Sub Os_exit_critical()
SEE ALSO
Common/Os_enter_critical
SOURCE
' decrement recoursive call count ' lds R16, {Os_critical_nesting_level} dec R16 ' first nesting level? ' cpi R16, 0 brne Os_exit_critical_2 ' other tasks and interrupts are allowed by now. ' sei Os_exit_critical_2: sts {Os_critical_nesting_level}, R16 End Sub
Common/Os_list_getnext [ Functions ]
[ Top ] [ Common ] [ Functions ]
DESCRIPTION
Switches to the next element in list
DECLARATION
Sub Os_list_getnext(byref Listhead As Word , Byref Object As Word , Byval Next_ptr_offset As Word)
INPUTS
Listhead: address of the first object in list Object: address of the current object Next_ptr_offset: offset of the objects storage location for the next pointer
SEE ALSO
Common/Os_list_insert, Common/Os_list_remove
SOURCE
Os_enter_critical Object = Getword(object , Next_ptr_offset) If Object = 0 Then Object = Listhead Os_exit_critical End Sub
Common/Os_list_insert [ Functions ]
[ Top ] [ Common ] [ Functions ]
DESCRIPTION
Inserts an object into a single linked list as first element
DECLARATION
Sub Os_list_insert(byref Listhead As Word , Byref Object As Word , Byval Next_ptr_offset As Word)
INPUTS
Listhead: address of the first object in list Object: address of the object to insert Next_ptr_offset: offset of the objects storage location for the next pointer
SEE ALSO
Common/Os_list_remove, Common/Os_list_getnext
SOURCE
Os_enter_critical Setword Object , Next_ptr_offset , Listhead Listhead = Object Os_exit_critical End Sub
Common/Os_list_remove [ Functions ]
[ Top ] [ Common ] [ Functions ]
DESCRIPTION
Removes an object from a single linked list
DECLARATION
Sub Os_list_remove(byref Listhead As Word , Byref Object As Word , Byval Next_ptr_offset As Word)
INPUTS
Listhead: address of the first object in list Object: address of the object to remove Next_ptr_offset: offset of the objects storage location for the next pointer
SEE ALSO
Common/Os_list_insert, Common/Os_list_getnext
SOURCE
Local Prevblock As Word Local Listblock As Word Os_enter_critical If Listhead <> 0 Then Prevblock = 0 Listblock = Listhead Do If Listblock = Object Then ' found ' Listblock = Getword(object , Next_ptr_offset) If Prevblock <> 0 Then Setword Prevblock , Next_ptr_offset , Listblock If Object = Listhead Then Listhead = Listblock Setword Object , Next_ptr_offset , 0 Exit Do End If Prevblock = Listblock Listblock = Getword(listblock , Next_ptr_offset) If Listblock = 0 Then Exit Do ' end of list ' Loop End If Os_exit_critical End Sub
Common/Os_mem_clear [ Functions ]
[ Top ] [ Common ] [ Functions ]
DESCRIPTION
Clears a memory block given by the start address and length in bytes
DECLARATION
Sub Os_mem_clear(byref Start_addr As Word , Byval Length As Word)
SEE ALSO
Common/Os_mem_copy
SOURCE
Local Datapointer As Word Length = Start_addr + Length ' calc end address ' For Datapointer = Start_addr To Length Out Datapointer , 0 Next End Sub
Common/Os_mem_copy [ Functions ]
[ Top ] [ Common ] [ Functions ]
DESCRIPTION
Copies a memory block given by the start address and length in bytes to the specified destination address. The source and destination block may overlap.
DECLARATION
Sub Os_mem_copy(byval Source_addr As Word , Byval Destination_addr As Word , Byval Length As Word)
SEE ALSO
Common/Os_mem_clear
SOURCE
Local Datapointer As Word , Databyte As Byte If Destination_addr < Source_addr Then ' destination is below source, copy in normal order ' Length = Source_addr + Length ' store end address in Length ' For Datapointer = Source_addr To Length Databyte = Inp(datapointer) Out Destination_addr , Databyte Incr Destination_addr Next Else Destination_addr = Destination_addr + Length ' source is below destination, copy in reverse order ' Length = Source_addr + Length ' store end address in Length ' For Datapointer = Length To Source_addr Step -1 Databyte = Inp(datapointer) Out Destination_addr , Databyte Decr Destination_addr Next End If End Sub
Common/Setbyte [ Functions ]
[ Top ] [ Common ] [ Functions ]
DESCRIPTION
Writes a byte value to the memory location addressed by pointer and offset
DECLARATION
Sub Setbyte(byref Address As Word , Byval Offset As Word , Byval Userdata As Byte)
SEE ALSO
Common/Getbyte, Common/Setword, Common/Getword
SOURCE
' load parameter Address ' ldd R26, Y+4 LDD R27, Y+5 LD R16, X+ LD R17, X ' load parameter Offset ' LDD R26, Y+2 LDD R27, Y+3 LD R20, X+ LD R21, X ' add ' add R16, R20 aDC R17, R21 ' load parameter Userdata ' ldd R26, Y+0 LDD R27, Y+1 LD R20, X ' move Address -> X ' mov R26, R16 MOV R27, R17 ' store data at address ' ST X, R20 End Sub
Common/Setword [ Functions ]
[ Top ] [ Common ] [ Functions ]
DESCRIPTION
Writes a word value to the memory location addressed by pointer and offset
DECLARATION
Sub Setword(byref Address As Word , Byval Offset As Word , Byval Userdata As Word)
SEE ALSO
Common/Getword, Common/Setbyte, Common/Getbyte
SOURCE
' load parameter Address ' ldd R26, Y+4 LDD R27, Y+5 LD R16, X+ LD R17, X ' load parameter Offset ' LDD R26, Y+2 LDD R27, Y+3 LD R20, X+ LD R21, X ' add ' add R16, R20 aDC R17, R21 ' load parameter Userdata ' ldd R26, Y+0 LDD R27, Y+1 LD R20, X+ LD R21, X ' move Address -> X ' mov R26, R16 MOV R27, R17 ' store data at address ' ST X+, R20 ST X, R21 End Sub