Difference between revisions of "Blitz:OS Calls"

From Amiga Coding
Jump to: navigation, search
m (Using OS Libraries)
(Using OS Libraries)
Line 13: Line 13:
  
 
If a function is treated as a statement, the return value is discarded. If a statement is treated as a function, the return value is 0.
 
If a function is treated as a statement, the return value is discarded. If a statement is treated as a function, the return value is 0.
 +
 +
There is no requirement to open or close libraries used in this manner - this is handled automatically by Blitz on program startup and end.
 +
 +
 +
==OS Structs and Constants==
 +
Many OS functions use structs and constants that are defined in the standard OS C header files. Blitz can't use the C header files (since they're in C code!), so it provides an alternative. In the Compiler Settings window, there is an area for entering resident files. These files are pre-compiled code that will then be included in your program. Generally they're similar to using include files but since they're already compiled they don't need to be recompiled every time you compile your program, saving compilation time.

Revision as of 13:35, 7 August 2015

OS calls use the Amiga API directly, ensuring compatibility with the operating system and the ability to use the techniques recommended by official SDK guidelines. The Amiga APIs are designed to be simple enough to use with the C language and so some almost all examples you will find are written in C. Nevertheless, with the more advanced features of Blitz mirroring the equivalent C features (structs, pointers etc.), it is possible to do pretty much anything with the API that you can do with C.


The AmiBlitz include files are generally written using the OS calls, so using these includes will allow you to easily access the OS functions properly without having to get deep into the official SDK documentation and trying to figure out how to adapt the examples to Blitz code. However there are also times when accessing the API directly is the simplest or only option.


Using OS Libraries

Blitz includes direct calls for several of the key Amiga libraries already built in as keywords. To call a specific function in Blitz, the name of the call is entered with an underscore on the end. This underscore denotes a command directly called from a library, which prevents any clashes with Blitz keywords. The official SDK is the best place to reference the specifics of each library and call, but in general, in contrast to most built in commands, library calls can be treated as either a statement or a function by simply using the relevant syntax. For example: Execute_ "SYS:Prefs/Font", 0, 0 This tries to run the program given in the quote marks. success = Execute_ ("SYS:Prefs/Font", 0, 0) This is the same call used as a function instead, which allows the result to be saved. For many calls, the result is a way of determining if the call was completed successfully or not. It also usually contains important information if successful which would be required later, such as file handles. Brackets must also be placed around the parameters to treat a call as a function.

If a function is treated as a statement, the return value is discarded. If a statement is treated as a function, the return value is 0.

There is no requirement to open or close libraries used in this manner - this is handled automatically by Blitz on program startup and end.


OS Structs and Constants

Many OS functions use structs and constants that are defined in the standard OS C header files. Blitz can't use the C header files (since they're in C code!), so it provides an alternative. In the Compiler Settings window, there is an area for entering resident files. These files are pre-compiled code that will then be included in your program. Generally they're similar to using include files but since they're already compiled they don't need to be recompiled every time you compile your program, saving compilation time.