1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-07-04 16:29:52 +00:00
millfork/docs/lang/interfacing.md

41 lines
976 B
Markdown
Raw Normal View History

2018-04-02 22:21:26 +00:00
[< back to index](../index.md)
2018-01-04 00:15:04 +00:00
# Interfacing with external code
2018-01-18 21:35:25 +00:00
## 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 a) @$FFD2 extern
```
2018-01-31 21:25:06 +00:00
The function parameter will be passed via the accumulator,
2018-01-18 21:35:25 +00:00
the function itself is located in ROM at $FFD2. A call like this:
```
putchar(13)
```
will be compiled to something like this:
```
LDA #13
JSR $FFD2
```
For more details about how to pass parameters to `asm` functions,
see [Using assembly within Millfork programs#Assembly functions](./assembly.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:
```
asm void call_function(byte a) {
JMP (function_address)
}
```
where `function_address` is a variable that contains the address of the function to call.