gfabasic

For everything that's not in any way related to PureBasic. General chat etc...
User avatar
Michael Vogel
Addict
Addict
Posts: 2819
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

GFA Library

Post by Michael Vogel »

Thanks einander!

I added it to my library, which will shall help me to "understand" the PB wording...

Michael


;{ PureBasic 4.0-Library including useful GFA-16Bit-Functions }
; 2006/02/09 started by Michael Vogel
; ..... everyone can help!
;}

;{ Mathematics }
; V0.0.1
;}
Procedure Max(a,b)
; Function: returns smaller of two numbers
If a>b
ProcedureReturn a
Else
ProcedureReturn b
EndIf
EndProcedure
Procedure Min(a,b)
; Function: returns bigger of two numbers
If a<b
ProcedureReturn a
Else
ProcedureReturn b
EndIf
EndProcedure
Procedure Div(a,b)
; Function: returns a div b
ProcedureReturn a/b
EndProcedure
Procedure Mod(a,b)
; Function: returns a mod b
ProcedureReturn a%b
EndProcedure
Procedure Succ(a)
; Function: returns increment of a
ProcedureReturn a+1
EndProcedure
Procedure Pred(a)
; Function: returns decrement of a
ProcedureReturn a-1
EndProcedure
Procedure Scale(a,b,c)
; Function: returns a*b/c
ProcedureReturn a*b/c
EndProcedure

;{ Logic }
; V0.0.1
;}
Procedure No(a)
; Function: returns not a
ProcedureReturn ~a
EndProcedure
Procedure BTst(a,b)
; Function: check, if bit is set
; Return: true, If bit b is set in number a, otherwise false
If a&(1<<b)<>0
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure BClr(a,b)
; Function: clear bit b in number a
ProcedureReturn a&~(1<<b)
EndProcedure
Procedure BSet(a,b)
; Function: set bit b in number a
ProcedureReturn a|(1<<b)
EndProcedure
Procedure IsEqual(a,b)
; Function: return -1 if a equals b, otherwise 0
If a=b
ProcedureReturn -#True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure IsGreater(a,b)
; Function: return -1 if a is greater than b, otherwise 0
If a>b
ProcedureReturn -#True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure IsLess(a,b)
; Function: return -1 if a is less than b, otherwise 0
If a<b
ProcedureReturn -#True
Else
ProcedureReturn #False
EndIf
EndProcedure

;{ Strings & Arrays}
; V0.0.1
;}
Procedure Rinstr(x$,search$,start=#MAXSHORT)
; Function: returns the rightmost position of the search text within the string s, begin with searching at position start
start=min(start,Len(x$))-Len(search$)
While start>0
If Mid(x$,start,Len(search$))=search$
Break
EndIf
start-1
Wend
ProcedureReturn start
EndProcedure
Procedure.s BinS(value,length)
; Function: returns a strings of the given length with the binary equivalent of the value
ProcedureReturn RSet(Bin(value),length,"0")
EndProcedure
Procedure.s HexS(value,length)
; Function: returns a strings of the given length with hex equivalent of the value
ProcedureReturn RSet(Hex(value),length,"0")
EndProcedure
Procedure DimX(x())
; Function: returns the number of elements of the given array
ProcedureReturn 0
; UNSOLVED
EndProcedure
Procedure Arrayfill(x(),y)
; Function: fills array x() with value y
; UNSOLVED
EndProcedure

;{ Graphics }
; V0.0.1
;}
Procedure Cls(color)
EndProcedure
Procedure Get(x,y,w,h)
EndProcedure
Procedure Put(x,y,w,h)
EndProcedure
Procedure Stretch(x,y,w,h)
EndProcedure

;{ Windows }
; V0.0.1
;}
Procedure OpenW(n,x,y,w,h,mode)
EndProcedure
Procedure CloseW(n)
EndProcedure

;{ File System }
; V0.01
;}
Procedure Exist(file$)
; Function: checks, if the given filename exists
; Return: True if the file exists, otherwise False
If FileSize(file$)>=0
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure _Drive()
; Function: returns ordinal number of actual drive
ProcedureReturn Asc(ProgramName())-64
EndProcedure
Procedure.s DIR(dummy)
; Function: returns actual directory path, where program has been started from
; thanks to einander...
Protected Buff$=Space(256)
GetCurrentDirectory_(256,@buff$)
ProcedureReturn buff$;
; my "solution"...
;Protected path.s=ProgramName()
;Protected pos=rinstr(path,"\")
;ProcedureReturn Mid(path,3,pos-3)
EndProcedure

;{ Extras }
; V0.0.2
;}
Procedure ShiftKey()
; Function: returns True, when the Shift key is actually pressed, otherwise False
ProcedureReturn GetKeyState_(#VK_SHIFT) & 128
EndProcedure
Procedure ControlKey()
; Function: returns True, when the Control key is actually pressed, otherwise False
ProcedureReturn GetKeyState_(#VK_CONTROL) & 128
EndProcedure
Procedure AltKey()
; Function: returns True, when the Alt key is actually pressed, otherwise False
ProcedureReturn GetKeyState_(#VK_MENU) & 128
EndProcedure

;{ Debugging & Testing }
;}
Procedure Test(what)
Dim x(10)
Select what
Case 1
Debug "File handling"
Debug Exist("\boot.ini")
Debug Exist("c:\Win")
Debug Exist("c:\autoexec.bat")
Case 2
Debug "Actual drive & directory"
Debug _drive()
Debug dir(0)
Case 3
Debug "Mathematics"
Debug min(9,2)
Debug div(19,5)
Debug 59%50
Case 4
Debug "Logic"
Debug No(0)
Debug No(1)
Debug BTst(%1011,2)
Debug BSet(%1011,2)
Debug BClr(%1011,3)
Case 5
Debug "Strings & Arrays"
Debug Rinstr("Hallo PureBasic","Pure")
Debug BinS(999,8)
Debug HexS(45054,8)
;Debug DimX(x())
Case 6
Debug "Shift-Key..."
Debug shiftkey()
EndSelect
EndProcedure

test(2);{ change number for testing... }
test(5);{ change number for testing... }

; IDE Options = PureBasic v4.00 - Beta 2 (Windows - x86)
; CursorPosition = 162
; FirstLine = 32
; Folding = AAAAAAA+
User avatar
Michael Vogel
Addict
Addict
Posts: 2819
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

well, the basics would be simple, i mean, i do not want to write my own
editor (but don't tempt me ) as i already have too many projects at hand

but what we could cook up is perhaps a procedure that would validate a line of code to see if it is correct purebasic syntax or not, from that point onwards we could either convince the pb team to include our realtime syntax check in the ide (by, for example, letting the ide highlight a 'faulty' line in a different colour) or use it as a building block

i have, to be honest, no clue how difficult such a thing would be it's great to be ignorant and naive
there are (at least) two things to keep in mind:
  • * syntax line check
    * code structure check
to check the code structure is simple (see if do/loop, if/endif-pairs match, etc.)

a syntax line check could be done forming a tree, but this can a really complex thing...

a%=function(a*abs(a)+instr(chr(22),"j",val("x"+"y"))

...each detail of all integrated operations must be listed, what means number and type of parameters, if they are required or optional, etc.
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post by RichardL »

I used GFA for over 8 years and used it to produce all manner of applications. It worked well, but the lack of support, lack of further developments and above all 16-bit internals and applications made me say a sad farewell. I still support some of my earlier GFA creations though.

I tried Power Basic, for me all it offered was a quick route into having to solve most of my requirements with API calls; but this was mainly due to the type of stuff I needed to program… which included simple 2D graphics.

Out of the box Pure Basic offered 2D graphics that did all I needed without resorting to the API. Now it’s got even better. With over a year of serious Pure Basic development I find it produces reliable, fast and compact code. Upgrades are regular, bugs get… quote “FIXED” and the community is helpful.

This brings me to the editor; which, for it age, was something GFA excelled at. I will say loud and clear “If you use Pure BASIC then use the jaPBe editor… it is what makes Pure Basic fly”. The folding, auto-complete, intelligent indenting and comment alignment mean your code stays tidy, readable and structured in appearance. This cuts down development time significantly and ensures you don’t produce “write only code” (A.K.A ‘C’) A big thank you is due to GPI for jaPBe and to ‘gnozal’ who is now supporting it.

GFA included an interpreter as well as a compiler. Having an interpreter allows you to ‘run’ a line of code and detect errors. Yes, it truly meant you could not get your cursor off a non-syntactic line of code (unless you commented it off) ! But, as most of my errors are typos and jaPBe reduces these thanks to the auto-complete I’m not feeling the loss of the syntax checking too much.

With the release of PB V4 Beta and many third part libraries slated to become V4 compliant soon I think PB is set fair for another year. If I have one criticism it is that Pure BASIC should cost more. I admire Fred’s attitude towards free upgrades but I for one will not hold it against him if he made a charge for each major revision.

I think a fair price for Pure BASIC would be about 60 Euro plus the amount of money you earn in one day when using it; but I cannot come up with a marketing strategy that would make this work! Pure BASIC is evolving into a truly productive tool, but for the trend to continue it must generate income to pay a talented and productive development team.

RichardL.
Post Reply