Home page

747,975 Visitors, Saturday 27 April 2024 04:30:00 CEST, IP: 3.144.93.73

memory_zone_library release 1.06 (2004-08-09)





I) What is this library???
II) What are the files in the archive? How do I use them?
III) What is a memory zone?
IV) Functions' description.

-----------********************************-----------

I) What is this library exactly???



This library allows you to use the memory zones (basic files...) of your AFX for writting data as if it was files on a PC hard drive:

- You can create new memory zones specifying their size.
- You can change the size of an existing one.
- Delete a memory zone.
- You can read and write data in theses area.
- Clear a whole area.
- Change the password of a basic file.

-----------********************************-----------

II) What are the files in the archive? How do I use them?



memzones.c is the file containing all the functions of the library, you have to add it to your makefile (or "Project").
memzones.h is the header file of memzones.c YOU HAVE TO "#INCLUDE" it in your .c files that use functions of memzones.c

DEF.h is a definition header file used by the lib.

-----------********************************-----------

III) What is a memory zone?



A memory zone is what the AFX (or GRAPH100) uses to store user's data in its memory: it can be a basic program (often called basic file), a variable, a list, a matrix...
There is 15 different types of memory zone, each type is used to store a special kind of data:

0 are variables (ALPHA):
This type of zone is very special: since it has to be the faster possible (variables are often used in basic programs),
their size are fixed and is always allocated. There is 29 different variables (A~Z, THETA, RHO and ANS).
Each variable uses 18 bytes in memory.

********If it's the first time you read this file you should jump to the next zone type explanation********

They don't have a name so you cannot address them with search_mem_zone, to write in it you have to fill the memory_zone structure yourself you can have the address of the first variable (A) using the function tell_mem_zone_seg as follow: var_A = tell_mem_zone_seg(0); where var_A is a void far pointer then to reach the variable B, for example, you just have to do this way: &var_A[18 * 1] (note the &) this will give you a char far pointer on the variable "B".
Variables are stored in alphabetical order from A to Z then RHO, THETA and finaly ANS.

1 are basic programs (PROGRAM):
This zone must have a size >=24 else I can't say how the calc basic program manager will handle it...

3 is a special zone (SYSTEM):
It is used to store the CLIP (CLIPBOARD) and the very special FNAME.
FNAME contains the name of the last program lauched from the main menu of your calc. It is used by CASIO(TM)'s programs to know the name under which they will save their data (name that appears in the system menu).

4: CHAR, 5: LIST, 6: MATRIX, 7: GENERAL, 8: WORK, 9: LOCAL, 10: DT 8, 11: DT 9.

These names come from the hidden menu that is accesible when the calc is off by pressing simultaneously the key:
[F1] [->] [AC/ON] then [1] once the menu is displayed.

NOTE that there is a zone denoted by "ALC" (ALLOC AREA) in this menu, its zone id is 16.
I don't know what is this zone for but for now you cannot access it through this library.
This zone works differently... I don't know which CASIO(TM)'s program use it; so I cannot understand its working way.
(address 1bf7h:3h till 1bf7h:5h influence it) If you have a clue please contact me!

12 is the add-in storage zone.
There you will find any data created by a CASIO(TM)'s add-in you uploaded. Add-in that have an icon in the main menu will directly use this zone to store data under the name of their executable name.

zone 13 till 15 can be used too but I don't know which CASIO program use it.

You'll be able to see the content of all the memory zone using TOUCHE 4.0.

IV) Functions' description.




** This package contains the following functions:


1) long search_mem_zone (int zone_id, unsigned char *zone_name, struct memory_zone *bf);

2) unsigned int write_mem_zone (struct memory_zone *bf, const void *src, int offset, unsigned length);

3) unsigned read_mem_zone (struct memory_zone *bf, void *dest, unsigned offset, unsigned length);

4) int change_password (struct memory_zone *bf, unsigned char *password);

5) void clear_mem_zone (const struct memory_zone *bf);

6) int create_mem_zone(unsigned char zone_id, char *zonename, unsigned int size, int flag);

7) unsigned long afxleft (void);

*********** Other functions ***********

8) char far *tell_mem_zone_seg( unsigned char id );

9) void huge_movedata(unsigned int src_seg, unsigned int src_off, unsigned int des_seg, unsigned int des_off, unsigned long num);

1: search_mem_zone
This function must be used before any of the functions 2 to 5, it sets the structure bf, it will return the size of the memory zone if success or -1 if an error happened.

A memory_zone structure is :

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 can 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 program zone only).
};


Example:

int main (void)
{
struct memory_zone bf;

if (search_mem_zone(1, "TEST", &bf) != -1)
printf("TEST found! The size is %u", bf.b_size);
else printf("TEST not found!");
exit(0);
}


IMPORTANT NOTE:

When you are writing within several memory zones at the same time, you have to call search_mem_zone() before calling any function that uses the memory_zone structure, each time you write to a memory zone, the whole memory changes and so if you have other memory_zone structures, you need to update each of them before any action using the structure).

2: write_mem_zone
This function allows you to write to the memory zone pointed by the bf strucure, note that the parameter src can be everything: a string, an int, a float, or even a very complex structure. offset is the position in the memory zone and length is the number of bytes to write,
if this number is higher than the size of the memory zone, it will write the maximum number of bytes according to the memory zone size (to protect the memory).

EXAMPLE :


{
write_mem_zone(&bf, &f1, 2, sizeof(f1));
}



The example above write the whole structure "f1" in the file described by "bf" writting on and after the offset 2.

3: read_mem_zone
This function read data in the memory zone pointed by the structure bf.
dest is the destination of the read bytes, like for write_mem_zone it can be everything
(char, int, struct...), length is the number of bytes to read and offset is the location of these bytes in the memory zone.

EXAMPLE:


{
unsigned int file_begining;

read_mem_zone(&bf, &file_begining, 0, sizeof(unsigned int));
}


NOTE: the functions read_mem_zone and write_mem_zone return the number of bytes processed.

4: change_password
This function like its name says change the password of a basic program (zone_id==1).
password is the new password that will replace the previous one.

5: clear_mem_zone
This funtion just fill a memory zone with (char)0 (NULL). Note that this function is very fast.

6: create_mem_zone
This function allows you to create a memory zone.
A memory zone is a basic file, a list, etc... everything that the calculator can store in its memory,
each zone is denoted with a type identifier from 0x0 to 0xF and its name following the identifier.
For example the basic files are zones denoted by 0x1.

zone_id is the zone identifier.
zonename is the zone name (8 bytes only).
size the size of the zone in the RAM(any memory zone must have a size >=14 bytes).
flag can be either: CREATE_ZONE, RESIZE_ZONE or DELETE_ZONE.

If flag is set to CREATE_ZONE then if the memory zone already exists it returns -1.
If flag is set to RESIZE_ZONE then if the memory zone already exists it resizes the zone name (data already in the zone aren't deleted if possible).
if flag is set to DELETE_ZONE then if the memory zone already exists it delete it form the memory. (size can be 0)

Return values :
- 0 if OK.
- -1 on error (an absurd size, no name, impossible id...).
- -2 if not enough memory to create the zone or if the function cannot allocate memory for its own work.

NOTE 1: If you attempt to create a zone which size is 0xFFFF the last 16 bytes will not be cleared but it works.

NOTE 2: Remember that if you want a memzone with 16 bytes available for writing you need to create a memzone of:
- 40 bytes if this is a type 1 zone
- 30 bytes for any other type

######## GENERAL EXAMPLE ########

Example:


include <dos.h>
#include <conio.h>
#include <bios.h>
#include <stdlib.h>
#include <stdio.h>
#include "memzones.h"

int main (void)
{
struct memory_zone bf;
char text[16];


if (create_mem_zone(1,"TEST", 230, RESIZE_ZONE) != -2)
{
if (search_mem_zone(1, (unsigned char *)"TEST", &bf) != -1) {
printf("TEST found! The size is %u\n", bf.b_size);

write_mem_zone(&bf, "Hello world!", 0, 14);

read_mem_zone(&bf, text, 0, 14);

printf("%s", text);
} else printf("TEST not found!\n");
//this line is useless since it cannot happen!?!
}
else printf("Not enough memory!\n");
bioskey(0);
return 0;
}


7) afxleft

This function returns the available memory for user data of the AFX (the same value that you can see in the system menu).

THE FUNCTIONA BELOW ARE USED BY THE LIBRARY ITSELF

8: tell_mem_zone_seg
This functions returns a char far pointer which point on the size of the first zone of this type in the memory.

9: huge_movedata
This function allows you to move huge block of memory (more than 65535 Ko). This function always works.


********************************************************************
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*
********************************************************************


If you want details about the memory zones, just wait for my tutorial about them, I'll probably release one a day.

NOTE: all these functions have been tested and are currently WORKING without any known bugs, if you find some, please contact me at 2072 AT 2072productions DOT com (click on the "webmaster" link).

To have more information on how to use these functions, see the source files (.c and .h) there are comments in it that you should read.

Remember:
To use these function you must include the file memzones.h in your .c file(s) and add memzones.c to your make file or project.

These functions are copyrighted to John Wellesz, I allow you to use it only if you use the source files WITHOUT MODIFYING THEM. And of course only if you put my name in the "Thanks" part of your prog ;-)

THIS LIBRARY IS DISTRIBUTED "AS IS". NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED. YOU USE AT YOUR OWN RISK.
THE AUTHOR WILL NOT BE LIABLE FOR DATA LOSS, DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS LIBRARY.

Thank you to use my programs!


Valid HTML 4.01! Best viewed in sRGB Valid CSS!
Previous page - Next page
This page has been seen 430 times ; last update: Sun Aug 19 11:58:47 2018
Copyright © 2001 - 2024 John Wellesz
All rights reserved.
All trademarks and registered trademarks mentioned on this website are the properties of their respective companies.

Privacy Policy