1 /*****************************************************************************/
5 /* API for extended memory access */
9 /* (C) 2002-2003 Ullrich von Bassewitz */
10 /* Römerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
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. */
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: */
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 */
32 /*****************************************************************************/
41 /*****************************************************************************/
43 /*****************************************************************************/
47 /* Size of an extended memory page */
48 #define EM_PAGE_SIZE 256
51 #define EM_ERR_OK 0 /* No error */
52 #define EM_ERR_NO_DRIVER 1 /* No driver available */
53 #define EM_ERR_CANNOT_LOAD 2 /* Error loading driver */
54 #define EM_ERR_INV_DRIVER 3 /* Invalid driver */
55 #define EM_ERR_NO_DEVICE 4 /* Device (hardware) not found */
57 /* Parameters for the em_copy_... functions. NOTE: The first seven bytes
58 * have the same order and alignment as needed for the Commodore REU, so
59 * don't change the order without changing the assembler file that defines
60 * the struct offsets and the code in the REU driver.
63 void* buf; /* Memory buffer to copy from or to */
64 unsigned char offs; /* Offset into page */
65 unsigned page; /* Starting page to copy from or to */
66 unsigned count; /* Number of bytes to copy */
67 unsigned char unused; /* Make the size 8 bytes */
72 /*****************************************************************************/
74 /*****************************************************************************/
78 unsigned char __fastcall__ em_load_driver (const char* driver);
79 /* Load and install an extended memory driver. Return an error code. */
81 unsigned char __fastcall__ em_unload (void);
82 /* Uninstall, then unload the currently loaded driver. */
84 unsigned char __fastcall__ em_install (void* driver);
85 /* Install an already loaded driver. Return an error code. */
87 unsigned char __fastcall__ em_uninstall (void);
88 /* Uninstall the currently loaded driver and return an error code.
89 * Note: This call does not free allocated memory.
92 unsigned __fastcall__ em_pagecount (void);
93 /* Return the total number of 256 byte pages available in extended memory. */
95 void* __fastcall__ em_map (unsigned page);
96 /* Unmap the current page from memory and map a new one. The function returns
97 * a pointer to the location of the page in memory. Note: Without calling
98 * em_commit, the old contents of the memory window may be lost!
101 void* __fastcall__ em_use (unsigned page);
102 /* Tell the driver that the memory window is associated with a given page.
103 * This call is very similar to em_map. The difference is that the driver
104 * does not necessarily transfer the current contents of the extended
105 * memory into the returned window. If you're going to just write to the
106 * window and the current contents of the window are invalid or no longer
107 * use, this call may perform better than em_map.
110 void __fastcall__ em_commit (void);
111 /* Commit changes in the memory window to extended storage. If the contents
112 * of the memory window have been changed, these changes may be lost if
113 * em_map, em_copyfrom or em_copyto are called without calling em_commit
114 * first. Note: Not calling em_commit does not mean that the changes are
115 * discarded, it does just mean that some drivers will discard the changes.
118 void __fastcall__ em_copyfrom (const struct em_copy* copy_data);
119 /* Copy from extended into linear memory. Note: This may invalidate the
120 * currently mapped page.
123 void __fastcall__ em_copyto (const struct em_copy* copy_data);
124 /* Copy from linear into extended memory. Note: This may invalidate the
125 * currently mapped page.