Artifact 6f8bdad686cd537c5ea02934a11852c4a3b4fe95:
- Executable file freshlib/_doc/starting.wiki — part of check-in [b53e7559f5] at 2011-04-01 05:16:05 on branch FreshLibDev — TestLib is crashing in Linux while previous version without animation was working properly. Timer granularity seems to be 10ms also on Debian. (user: pelaillo size: 4288) [more...]
The first thing to do is to download fasm in your platform of choice. Fasm does not require installation nor do you need special administrative privileges or a root account in order to start using it.
The second thing is to get a copy of FreshLib. FreshLib is just fasm source code, simply save it in a directory of choice.
FreshLib needs an environment variable called TargetOS in order to know the target platform of the generated application. Currently, the allowed values are: Win32 and Linux.
A second environment variable is suggested called lib having the full path to FreshLib. The library does not need this, but it will make your own sources more portable.
From Linux:
export TargetOS=Linux export lib=/home/test/freshlib
From Windows:
set TargetOS=Win32 set lib=c:\projects\freshlib
That's all. Now it is time to produce the first FreshLib application using just Fasm.
Hello World
include '%lib%/compiler/executable.inc'
include '%lib%/macros/allmacros.inc'
include '%lib%/equates/allequates.inc'
_BinaryType console
include '%lib%/system/process.asm'
include '%lib%/simpledebug/debug.asm'
_CodeSection
start:
InitializeAll
DebugMsg 'Hello world!'
FinalizeAll
call Terminate
_ImportSection
include '%lib%/imports/allimports.asm'
_DataSection
IncludeAllGlobals
The most important thing to note is that regardless the platform you have chosen, the code is exactly the same. In other words, if you change the value of your environment variable TargetOS, the same code will produce a different executable file targeting that platform. This is the main characteristic of the FreshLib and this is the first design criteria that you will want to follow to have a truly platform independent application.
This is a highly portable development environment, perhaps the most portable among non interpreted languages. The entire development process could run from removable media and the same set of source code files could be used from Win32 and Linux to produce binaries for either of them.
Creating Files
include '%lib%/compiler/executable.inc'
include '%lib%/macros/allmacros.inc'
include '%lib%/equates/allequates.inc'
_BinaryType console
include '%lib%/simpledebug/debug.asm'
include '%lib%/system/files.asm'
include '%lib%/system/process.asm'
_CodeSection
start:
InitializeAll
DebugMsg 'FreshLib Tutorials - Module: Files'
iglobal
filename db './tut01.txt',0
sizeof.filename = $-filename
endg
uglobal
hFile dd ?
endg
stdcall FileCreate, filename
jc .error
mov [hFile], eax
DebugMsg "A new file was created:"
stdcall OutputNumber, [hFile], 16, 2
DebugMsg " is the handle of the file"
stdcall FileWrite, [hFile], filename, sizeof.filename
jc .error
stdcall OutputNumber, eax, 10, 2
DebugMsg " bytes were written into the file"
stdcall FileClose, [hFile]
jc .error
DebugMsg "The file was properly closed"
stdcall FileDelete, filename
jc .error
DebugMsg "The file was finally deleted"
jmp .exit
.error:
DebugMsg "Sorry, an error occurred"
.exit:
FinalizeAll
stdcall Terminate, 0
_ImportSection
include '%lib%/imports/allimports.asm'
_DataSection
IncludeAllGlobals