Fresh IDE . Documentation
Not logged in

This repository is a mirror!

The original is located on: https://fresh.flatassembler.net/fossil/repo/fresh
If you want to follow the project, please update your remote-url

FreshLib directory: system

This directory contains two libraries: "memory.asm" and "files.asm". They constitute the interface to the overlaying system for the rest of the FreshLib modules.

FreshLib Memory

This library contains simple but pretty complete functions for dynamic memory allocation, reallocation and release.

The Win32 implementation of the library uses the process heap, returned by GetProcessHeap to manage the memory allocations. Linux implementation uses libc functions: "malloc", "free" and "realloc".

GetMem

proc GetMem, .size

This procedure allocates dynamic memory block with size in bytes in the argument [.size]

If there is no error the procedure returns CF=0 and pointer to the requested memory in EAX. If the memory cannot be allocated, the procedure returns CF=1

FreeMem

proc FreeMem, .ptr

This procedure frees the memory block pointed by [.ptr] argument.

ResizeMem

proc ResizeMem, .ptr, .newsize

This procedure tries to resize the memory block pointed by [.ptr] to the new size, given by [.newsize] argument.

FreshLib Files

This library provides simple file access procedures.

FileOpen

proc FileOpen, .filename

This procedure opens the file with a filename in the string pointed by [.filename] argument.

On success (CF=0) FileOpen returns a handle of the open file. On error (CF=1) returns error code.

FileCreate

proc FileCreate, .filename

This procedure creates new empty file with a filename in the string pointed by [.filename] argument.

On success (CF=0) FileCreate returns a handle of the open file. On error (CF=1) returns error code in EAX.

FileClose

proc FileClose, .handle

This procedure closes the open file with a handle in [.handle] argument.

On success (CF=0) does not return any value and preserves EAX.

On error (CF=1) returns error code in EAX.

FileRead

proc FileRead, .handle, .buffer, .count

This procedure reads [.count] bytes from the file [.handle] in the buffer pointed by [.buffer] arguments.

On success (CF=0) returns the count of actually read bytes in EAX.

On error (CF=1) returns error code in EAX.

FileWrite

proc FileWrite, .handle, .buffer, .count

This procedure writes [.count] bytes from the buffer pointed by [.buffer] argument to the file [.handle] that have to be open for write.

On success (CF=0) returns the count of actually read bytes in EAX.

On error (CF=1) returns error code in EAX.

FileSeek

proc FileSeek, .handle, .dist, .direction

This procedure moves the file pointer to the some position. The handle of the file is in [.handle], the target position is in [.dist] and the direction of the move is in [.direction] arguments.

[.direction] accept one of the following values: fsFromBegin, fsFromEnd and fsFromCurrent.

The exact values of these constants may vary between different OSes, so the programmer have to use the symbolic names, predefined in "files.asm" library.

On success (CF=0) returns the new position of the file in EAX.

On error (CF=1) returns error code in EAX.

FileDelete

proc FileDelete, .filename

This procedure deletes a file with name in pointed by [.filename] argument.

On success (CF=0) no value.

On error (CF=1) returns error code in EAX.

GetErrorString

proc GetErrorString, .code

This procedure returns in EAX a pointer to a human readable error string for the error code passed in [.code]. The string is dynamically allocated by the OS and should be released after use with the procedure FreeErrorString.

FreeErrorString

proc FreeErrorString, .ptrString

This procedure frees the memory allocated for error string from the procedure GetErrorString.

LoadBinaryFile

proc LoadBinaryFile, .ptrFileName

This procedure allocates needed memory and loads the whole file with filename pointed by [.ptrFileName] to the allocated buffer.

The memory is allocated with the library memory.asm, so the user have to free the memory after use with the procedure FreeMem.

On success (CF=0) the procedure returns a pointer to the allocated memory in EAX and the count of bytes read in ECX.

On error (CF=1) the procedure returns nothing.

SaveBinaryFile

proc SaveBinaryFile, .ptrFileName, .aptr, .size

This procedure creates new file with the name pointed by [.ptrFileName] and saves [.size] bytes from the buffer pointed by [.aptr].

The procedure returns error flag in CF.

FileExists

proc FileExists, .ptrFileName

This procedure checks whether the file with name pointed by [.ptrFileName] exists on disk.

The procedure returns CF=0 if the file exists, otherwise it returnsCF=1.