1 /*****************************************************************************/
5 /* API for extended memory access */
9 /* (C) 2002-2012, Ullrich von Bassewitz */
10 /* Roemerstrasse 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 */
56 #define EM_ERR_INSTALLED 5 /* A driver is already installed */
58 /* Parameters for the em_copy_... functions. NOTE: The first seven bytes
59 ** have the same order and alignment as needed for the Commodore REU, so
60 ** don't change the order without changing the assembler file that defines
61 ** the struct offsets and the code in the REU driver.
64 void* buf; /* Memory buffer to copy from or to */
65 unsigned char offs; /* Offset into page */
66 unsigned page; /* Starting page to copy from or to */
67 unsigned count; /* Number of bytes to copy */
68 unsigned char unused; /* Make the size 8 bytes */
73 /*****************************************************************************/
75 /*****************************************************************************/
79 unsigned char __fastcall__ em_load_driver (const char* driver);
80 /* Load and install an extended memory driver. Return an error code. */
82 unsigned char em_unload (void);
83 /* Uninstall, then unload the currently loaded driver. */
85 unsigned char __fastcall__ em_install (void* driver);
86 /* Install an already loaded driver. Return an error code. */
88 unsigned char em_uninstall (void);
89 /* Uninstall the currently loaded driver and return an error code.
90 ** Note: This call does not free allocated memory.
93 unsigned em_pagecount (void);
94 /* Return the total number of 256 byte pages available in extended memory. */
96 void* __fastcall__ em_map (unsigned page);
97 /* Unmap the current page from memory and map a new one. The function returns
98 ** a pointer to the location of the page in memory. Note: Without calling
99 ** em_commit, the old contents of the memory window may be lost!
102 void* __fastcall__ em_use (unsigned page);
103 /* Tell the driver that the memory window is associated with a given page.
104 ** This call is very similar to em_map. The difference is that the driver
105 ** does not necessarily transfer the current contents of the extended
106 ** memory into the returned window. If you're going to just write to the
107 ** window and the current contents of the window are invalid or no longer
108 ** use, this call may perform better than em_map.
111 void em_commit (void);
112 /* Commit changes in the memory window to extended storage. If the contents
113 ** of the memory window have been changed, these changes may be lost if
114 ** em_map, em_copyfrom or em_copyto are called without calling em_commit
115 ** first. Note: Not calling em_commit does not mean that the changes are
116 ** discarded, it does just mean that some drivers will discard the changes.
119 void __fastcall__ em_copyfrom (const struct em_copy* copy_data);
120 /* Copy from extended into linear memory. Note: This may invalidate the
121 ** currently mapped page.
124 void __fastcall__ em_copyto (const struct em_copy* copy_data);
125 /* Copy from linear into extended memory. Note: This may invalidate the
126 ** currently mapped page.