-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemzones.h
152 lines (121 loc) · 5.64 KB
/
memzones.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*********************************************
** memory_zone_libraries release 1.02 **
** **
** Copyright (c) John Wellesz 2001 - 2003 **
** All rights Reserved. **
*********************************************/
#include <stddef.h>
/*
* You must include this file in your source code and add mem_zones.c to your makefile or project file.
* #include "mem_zones.h"
*/
/*
* This structure is used by all the functions
* to have information about the memory zone.
* you have to define one and init it with the
* function search_mem_zone.
*/
struct memory_zone {
int b_ztype; // indicates the zone id
unsigned int b_offset; // --|
unsigned int b_segment; // --| point on the size of the zone (3 bytes before the name).
unsigned int b_inner_offset;//point on the offset where it cans start to write/read data.
unsigned int b_size; //total zone size.
unsigned int b_real_size; //the real size available for data (used to prevent overflow).
unsigned char b_name[10]; //name of the zone.
unsigned char b_password[10];//password (for basic files only).
};
// MACRO FOR COMPATIBILITY WITH OLDER VERSONS OF THIS LIB
#define search_basic_file(a,b) search_mem_zone(1,a,b)
#define BASICfile memory_zone
#define read_toBfile read_mem_zone
#define write_toBfile write_mem_zone
#define clear_basfile clear_mem_zone
// Flags for the function create_mem_zone
#define CREATE_ZONE 0// Create a memory zone, if zone already exists it returns -1
#define RESIZE_ZONE 2// create or change the size of an existing zone.
#define DELETE_ZONE 3// can delete a memory zone.
// ######## internal use only #########
struct zone_info {
unsigned int offset;
unsigned char seg;
};
struct zone_info_num {
unsigned int num;
};
// ####################################
#ifdef __cplusplus
extern "C" {
#endif
/* ----------- create_mem_zone -----------
* Creates a memory zone specified which type is given by "id" with the name "zonename", and a size of "size" bytes.
* (size >= 14 and >=24 for a basic file)
* it returns -1 in case of failure (already exist...) and -2 if not enough memory to create the file
* or not enough memory for the function itself.
* flag can be one of these values: CREATE_ZONE RESIZE_ZONE DELETE_ZONE
*/
int create_mem_zone(unsigned char zone_id, unsigned char *zonename, unsigned int size, int flag);
/* ----------- search_mem_zone -----------
* This function must be used one time before functions read_mem_zone, write_mem_zone or change_password
* to init the memory_zone structure
* then you will have to send the ====> ADDRESS <==== of this structure to the other functions.
* (you will have problems if you don't correctly understand the meaning od "address")
*
* zonename is the name of the memory zone
* zone_id is the id type of the memory zone you want to find
* bf is the name of a memory_zone structure
*
* this function returns the size of the memory zone if found and -1 if not.
*/
long search_mem_zone(int zone_id, unsigned char *zone_name, struct memory_zone *bf);
/* ----------- write_mem_zone -----------
*
* This function works like the write function for real files,
* src can be everything, an int, a string, a structure...
* offset is the location in the memory zone where to write.
* length is the length in byte of src to write, if length > b_size then only b_size -24 are written.
* So your calculator memory is protected it CAN only write within the memory zone pointed by bf.
*/
unsigned int write_mem_zone (struct memory_zone *bf, const void *src, unsigned offset, unsigned length);
/* ----------- read_mem_zone -----------
* works like the write one, dest can be everything an int, a string...
*/
unsigned read_mem_zone (struct memory_zone *bf, void *dest, unsigned offset, unsigned length);
/* ----------- clear_mem_zone -----------
* This fill a memory zone with NULLs.
*/
void clear_mem_zone
(const struct memory_zone *bf);
/* ----------- change_password -----------
* Well this change the password of a basic prog, password is the new one.
* */
void change_password
(struct memory_zone *bf, unsigned char *password);
/* ----------- afxleft -----------
* This return the available memory for user's data in the afx memory.
* */
unsigned long afxleft (void);
/*############### The functions below are used by other function of this lib ###############*/
/* ----------- tell_mem_zone_seg -----------
* This function returns a pointer to the first zone which type is id (0<=id<0xF).
*/
char far *tell_mem_zone_seg( unsigned char id );
/* -------- huge_movedata --------
* Can move till 0xFFFFFFFF bytes of memory!
*/
void
huge_movedata(unsigned int src_seg, unsigned int src_off, unsigned int des_seg, unsigned int des_off, unsigned long num);
void
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);
/* -------- init_area --------
* clear an area of "size" (<65536) bytes of memory since("direction"==0) or till(direction==1) b_segment:b_offset with the
* two bytes contained in "value"
*/
void init_area(unsigned int b_segment, unsigned int b_offset, unsigned int size, unsigned int value, int direction);
unsigned long give_absolute_add(void far *pointer);
void far *give_far_pointer(unsigned long abs_add);
#ifdef __cplusplus
}
#endif
#define GIVE_SEG_ABSADD(a) ((u_int)((a)>> 4))
#define GIVE_OFF_ABSADD(a) ((u_int)((a) & 0xF))