1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-12-25 21:29:25 +00:00
millfork/docs/lang/interfacing.md
Karol Stasiak 63ff28e94e Changes to macros and parameter list syntax:
* non-asm macros can now take `const` and `call` parameters
* register parameters to asm functions and macros can be given names if annotated explicitly
2020-03-30 19:23:48 +02:00

44 lines
1.2 KiB
Markdown

[< back to index](../doc_index.md)
# Interfacing with external code
## Calling external functions at a static address
To call an external function, you need to declare it as `asm extern`. For example:
```
asm void putchar(byte register(a) char) @$FFD2 extern
```
In this example, the function parameter will be passed via the accumulator,
the function itself is located in ROM at $FFD2. A call like this:
```
putchar(13)
```
will be compiled to something like this on 6502:
```
LDA #13
JSR $FFD2
```
For more details about how to pass parameters to `asm` functions, see:
* for 6502: [Using 6502 assembly within Millfork programs#Assembly functions](./assembly.md#assembly-functions).
* for Z80: [Using Z80 assembly within Millfork programs#Assembly functions](./assemblyz80.md#assembly-functions).
## Calling external functions at a dynamic address
To call a function that has its address calculated dynamically,
you just need to do the same as what you would do in assembly; 6502 example:
```
asm void call_function(byte register(a) param) {
JMP (function_address)
}
```
where `function_address` is a variable that contains the address of the function to call.