]> git.sur5r.net Git - cc65/blob - include/modload.h
All module functions are fastcall
[cc65] / include / modload.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                   modload.h                               */
4 /*                                                                           */
5 /*                     o65 module loader interface for cc65                  */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2002      Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@musoftware.de                                            */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 /* Exports structures and functions to load relocatable o65 modules at
37  * runtime.
38  */
39
40
41
42 #ifndef _MODLOAD_H
43 #define _MODLOAD_H
44
45
46
47 /* The following struct is passed to the module loader. It contains stuff,
48  * the loader needs to work, and another area where the loader will place
49  * informational data if it was successful. You will have to check the return
50  * code of mod_load before accessing any of these additional struct members.
51  */
52 struct mod_ctrl {
53     /* Parameters passed into the loader routine. The member callerdata
54      * is an opaque 16 bit datatype that may be used by the caller to
55      * pass data through to the read routine. The read routine is used by the
56      * loader to load any required data. There are several calls where the
57      * read routine is passed a count of 1, so you may choose to make this
58      * a special case when implementing read(). The read() should return the
59      * number of bytes actually read. If the return value differs from the
60      * passed count, this is considered an error.
61      * NOTE: read() is designed so that the POSIX read() routine can be used
62      * for this vector, if you're loading from disk.
63      */
64     int __fastcall__  (*read) (int callerdata, void* buffer, unsigned count);
65     int               callerdata;
66
67     /* Parameters set by the loader routine */
68     void*             module;           /* Pointer to module data */
69     unsigned          module_size;      /* Total size of loaded module */
70     unsigned          module_id;        /* Module id */
71 };
72
73
74
75 unsigned char __fastcall__ mod_load (struct mod_ctrl* ctrl);
76 /* Load a module into memory and relocate it. The function will return an
77  * error code (see below). If MLOAD_OK is returned, the outgoing fields in
78  * the passed mod_ctrl struct contain information about the module just
79  * loaded.
80  */
81
82 void __fastcall__ mod_free (void* module);
83 /* Free a loaded module. Note: The given pointer is the pointer to the
84  * module memory, not a pointer to a control structure.
85  */
86
87
88
89 /* Errors */
90 #define MLOAD_OK                0       /* Module load successful */
91 #define MLOAD_ERR_READ          1       /* Read error */
92 #define MLOAD_ERR_HDR           2       /* Header error */
93 #define MLOAD_ERR_OS            3       /* Wrong OS */
94 #define MLOAD_ERR_FMT           4       /* Data format error */
95 #define MLOAD_ERR_MEM           5       /* Not enough memory */
96
97
98
99 /* End of modload.h */
100 #endif
101
102
103