Create Library - Basics
The external libraries are processed through this extra-existing library editor and / or created. The library editor supports the author of a library graphically by overviews and simple choices when creating methods and properties.
The library functions are classically programmed in assembler.
In the source code of the interfaces and modules, functions and macros of the standard library can be used. A external label can imported by .import <label>. The use of functions of other libraries is possible. By using cleverly named constants can be queried whether the Luna programmer has also incorporated the necessary library.
To avoid name collisions, all identifiers must be unique and unambiguous within a library.
It can be used all general Präprozessorfunktionen of Luna assembler as in Inline-Assembler possible, e.g. hi8(), lo8(), shift-commands and so on. In addition, special preprocessor commands are available that make sense only in the creation of libraries (see below).
See also:
Special Präprozessorfunktion(s)
MakeIdentifier( string )
Created from the string passed an identifier (symbol). The string is then no longer considered by the assembler as a string, but as a constant name (symbol). If this constant name already has a value, it can then be used as Such in the assembler source code.
Example
Allocation 0xf0 on the already existing register symbol PORTB. The constant MyPort then refers to the constant (symbol) PORTB so that the value of PORTB is used in the result here.
.set myport = MakeIdentifier("PORTB") ldi _HA0,0xf0 sts myport,_HA0
The following code demonstrates the assigning of a specific port-pin in the Luna-code and the further processing in the assembler source code in an interface.
Luna-Code
Spi.PinMiso = PortB.2
Interface Inline-Method "PinMiso"
.set SpiPinMisoPORT = MakeIdentifier(NthField({keyword},".",1)) .set SpiPinMisoPortPin = val(NthField({keyword},".",2)) .set SpiPinMisoDDR = MakeIdentifier("DDR"+right(NthField({keyword},".",1),1)) .set SpiPinMisoPIN = MakeIdentifier("PIN"+right(NthField({keyword},".",1),1))
In the Library-Editor
In such assignments which is a bit like word processing. It is the input of the programmer prepared so that you can work on the assembly level useful with the information. The declaration of this inline method in turn ensures that the programmer without receiving an error message that can only enter what he can add to. Here, this is ensured by the regular expression.
In this example, the four constants then contain the following values:
- SpiPinMisoPORT = PORTB
- SpiPinMisoPortPin = 2
- SpiPinMisoDDR = DDRB
- SpiPinMisoPIN = PINB
Methods and Inline-Methods
- Inline-Methods
The source code included is used directly at the point of use. There is no subroutine call. The first parameter or a real value assignment is stored to the register block A, so register _HA0 to _HA3 (depending on the value of width). All further on the stack. The parameters are retrieved in the order of declaration (from left to right) from the stack.
- Methoden
The source code included is treated as sub routine. There is a call to the corresponding labels as subroutine calls. The first parameter or a real value assignment is stored to the register block A, so register _HA0 to _HA3 (depending on the value of width). All further on the stack. The parameters are retrieved in the order of declaration (from left to right) from the stack. Before you pick up the other parameters from the stack, you have to pop/push the return address of the subroutine call first with the built-in-assembler macros „PopPC“ and „PushPC“ (see standard library).
Note
If a real value assignment (no text replacement) used in a method/inline-method, it will displace the first parameter store. That the first parameter will no longer end up in the register block A. The first parameter are stored to the stack like all the other parameters. The register block A is then the value assignment.