Program location header
Created by: phil, Last modification: Wed 17 of Aug, 2011 (20:42 UTC)
From FLOS v568 onwards, programs (IE: files with .exe extensions) can load and run from a specific location. This is achieved by putting the following header at the start of the code (without it, programs load to $5000 as normal).
| $0 | $ED |
| $1 | $00 |
| $2 | Z80 instruction: JR start_of_user_program |
| $4 | Desired load location (of header, program follows on) |
| $6 | Desired load bank |
| $7 | Control byte (since FLOS v569) 1 = truncate load length using following 3 bytes |
| $8 | Load length 0:7 (LSB) |
| $9 | Load length 8:15 |
| $A | Load length 16:23 (MSB) |
| $B | Program starts here |
Source code version:
;======================================================================================
; Program Location File Header:
; FLOS v568+ will use this data to load the program to a specific location
; Earlier versions of FLOS will ignore it and load the program to $5000
;======================================================================================
my_location equ $f000
my_bank equ $0e
org my_location ; desired load address
load_loc db $ed,$00 ; header ID (Invalid, harmless Z80 instruction)
jr exec_addr ; jump over remaining header data
dw load_loc ; location file should load to
db my_bank ; upper bank the file should load to
db 0 ; zero = load entire file
exec_addr
The first two bytes are the header ID (a safe non-instruction) and the following JR allows the header size to vary in future.
Main program execution begins from "exec_addr". The labels "my_location" and "my_bank" obviously should be set to suit the program. (Note: The header is loaded to "my_location" as a normal part of the file). It is advisable to add some code to check that the program has been loaded into its correct location, see the "example source" folder for a method to do this.