Page principale | Structures de données | Liste des fichiers | Champs de donnée | Portée globale

memzones.h

Aller à la documentation de ce fichier.
00001 /*#################################################################################### 00002 # This Code is part of the libg100 library : http://libg100.sf.net # 00003 # # 00004 # THIS LIBRARY IS DISTRIBUTED "AS IS". # 00005 # NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED. # 00006 # YOU USE AT YOUR OWN RISK. # 00007 # THE AUTHOR WILL NOT BE LIABLE FOR DATA LOSS, DAMAGES, # 00008 # LOSS OF PROFITS OR ANY OTHER KIND OF LOSS # 00009 # WHILE USING OR MISUSING THIS LIBRARY. # 00010 # # 00011 # This library is Distributed in LGPL License, read lgpl.txt or go to : # 00012 # http://opensource.org/licenses/lgpl-license.php # #/ 00013 ####################################################################################*/ 00014 00024 #include <stddef.h> 00025 00026 /* 00027 * You must include this file in your source code and add mem_zones.c to your makefile or project file. 00028 * #include "mem_zones.h" 00029 */ 00030 00031 00032 /* 00033 * This structure is used by all the functions 00034 * to have information about the memory zone. 00035 * you have to define one and init it with the 00036 * function search_mem_zone. 00037 */ 00038 00039 //XXX 00040 void print_mzstruct (struct memory_zone *mz); 00041 00042 struct memory_zone { 00043 int b_ztype; // indicates the zone id 00044 unsigned int b_offset; // --| 00045 unsigned int b_segment; // --| point on the size of the zone (3 bytes before the name). 00046 unsigned int b_inner_offset;//point on the offset where it cans start to write/read data. 00047 unsigned int b_size; //total zone size. 00048 unsigned int b_real_size; //the real size available for data (used to prevent overflow). 00049 unsigned char b_name[10]; //name of the zone. 00050 unsigned char b_password[10];//password (for basic files only). 00051 }; 00052 00053 // MACRO FOR COMPATIBILITY WITH OLDER VERSONS OF THIS LIB 00054 #define search_basic_file(a,b) search_mem_zone(1,a,b) 00055 #define BASICfile memory_zone 00056 #define read_toBfile read_mem_zone 00057 #define write_toBfile write_mem_zone 00058 #define clear_basfile clear_mem_zone 00059 00060 // Flags for the function create_mem_zone 00061 #define CREATE_ZONE 0// Create a memory zone, if zone already exists it returns -1 00062 #define RESIZE_ZONE 2// create or change the size of an existing zone. 00063 #define DELETE_ZONE 3// can delete a memory zone. 00064 00065 // ######## internal use only ######### 00066 struct zone_info { 00067 unsigned int offset; 00068 unsigned char seg; 00069 }; 00070 00071 struct zone_info_num { 00072 unsigned int num; 00073 }; 00074 // #################################### 00075 #if __cplusplus 00076 extern "C" { 00077 #endif 00078 00079 /* ----------- create_mem_zone ----------- 00080 * Creates a memory zone specified which type is given by "id" with the name "zonename", and a size of "size" bytes. 00081 * (size >= 14 and >=24 for a basic file) 00082 * it returns -1 in case of failure (already exist...) and -2 if not enough memory to create the file 00083 * or not enough memory for the function itself. 00084 * flag can be one of these values: CREATE_ZONE RESIZE_ZONE DELETE_ZONE 00085 */ 00086 int create_mem_zone(unsigned char zone_id, unsigned char *zonename, unsigned int size, int flag); 00087 00088 /* ----------- search_mem_zone ----------- 00089 * This function must be used one time before functions read_mem_zone, write_mem_zone or change_password 00090 * to init the memory_zone structure 00091 * then you will have to send the ====> ADDRESS <==== of this structure to the other functions. 00092 * (you will have problems if you don't correctly understand the meaning od "address") 00093 * 00094 * zonename is the name of the memory zone 00095 * zone_id is the id type of the memory zone you want to find 00096 * bf is the name of a memory_zone structure 00097 * 00098 * this function returns the size of the memory zone if found and -1 if not. 00099 */ 00100 long search_mem_zone(int zone_id, unsigned char *zone_name, struct memory_zone *bf); 00101 00102 /* ----------- write_mem_zone ----------- 00103 * 00104 * This function works like the write function for real files, 00105 * src can be everything, an int, a string, a structure... 00106 * offset is the location in the memory zone where to write. 00107 * length is the length in byte of src to write, if length > b_size then only b_size -24 are written. 00108 * So your calculator memory is protected it CAN only write within the memory zone pointed by bf. 00109 */ 00110 00111 unsigned int write_mem_zone (struct memory_zone *bf, const void *src, unsigned offset, unsigned length); 00112 00113 00114 /* ----------- read_mem_zone ----------- 00115 * works like the write one, dest can be everything an int, a string... 00116 */ 00117 unsigned read_mem_zone (struct memory_zone *bf, void *dest, unsigned offset, unsigned length); 00118 00119 /* ----------- clear_mem_zone ----------- 00120 * This fill a memory zone with NULLs. 00121 */ 00122 void clear_mem_zone 00123 (const struct memory_zone *bf); 00124 00125 /* ----------- change_password ----------- 00126 * Well this change the password of a basic prog, password is the new one. 00127 * */ 00128 void change_password 00129 (struct memory_zone *bf, unsigned char *password); 00130 00131 /* ----------- afxleft ----------- 00132 * This return the available memory for user's data in the afx memory. 00133 * */ 00134 unsigned long afxleft (void); 00135 00136 /*############### The functions below are used by other function of this lib ###############*/ 00137 00138 /* ----------- tell_mem_zone_seg ----------- 00139 * This function returns a pointer to the first zone which type is id (0<=id<0xF). 00140 */ 00141 char far *tell_mem_zone_seg( unsigned char id ); 00142 00143 /* -------- huge_movedata -------- 00144 * Can move till 0xFFFFFFFF bytes of memory! 00145 */ 00146 00147 void 00148 huge_movedata(unsigned int src_seg, unsigned int src_off, unsigned int des_seg, unsigned int des_off, unsigned long num); 00149 00150 void 00151 my_movedata(unsigned int src_seg, unsigned int src_off, unsigned int des_seg, unsigned int des_off, size_t size_to_copy, int direction); 00152 00153 /* -------- init_area -------- 00154 * clear an area of "size" (<65536) bytes of memory since("direction"==0) or till(direction==1) b_segment:b_offset with the 00155 * two bytes contained in "value" 00156 */ 00157 00158 void init_area(unsigned int b_segment, unsigned int b_offset, unsigned int msize, unsigned int value, int direction); 00159 00160 unsigned long give_absolute_add(void far *pointer); 00161 00162 void far *give_far_pointer(unsigned long abs_add); 00163 00164 #if __cplusplus 00165 } 00166 #endif 00167 00168 #define GIVE_SEG_ABSADD(a) ((u_int)((a)>> 4)) 00169 #define GIVE_OFF_ABSADD(a) ((u_int)((a) & 0xF)) 00170 00171
Copyright 2004 The Libg100 Team
Sourceforge Project - LGPL Licensing