View Full Version : Learning Oxygen and discussion of ideas for projects
I guess this should be moved out from User Tools Eros now and in some other suitable category as you see fit.
Original Post:I thought I would start a new topic for the development of thinForm Version 2.
I am going to use O2H to make classes for the various form control objects.
http://community.thinbasic.com/index.php?board=175.0
I am thinking of making each class a separate txt file that can be combined into a final source file to be compiled. This way the classes could be easily used in other projects when needed.
Charles, I am going to follow your convention of prefixing class files as:
class_controlname.txt
Should we use something other than txt for the file extension? The reason, I am thinking that perhaps you could add a new command to O2H that will load all class files into a single source file or
@Eros this could be a new thinBasic command.
Something like: LoadClasses ( class folder path ) this would return a single combined text file.
Then the programmer could add additional code and then terminate the source file for compiling as usual.
Charles, here is a test script that is not working, when you have a chance can you look it over and help me see the light thanks.
ErosOlmi
12-04-2009, 00:03
Kent,
maybe better to send a PM to Charles about your idea. Maybe he miss this post.
Ciao
Eros
Charles Pegge
12-04-2009, 06:53
Hi Kent,
Here's one way to do it.
NB: one complication of creating a union inside the class: the hidden virtual table pointer!
Uses "Oxygen"
dim src as string
src="
Uses "Oxygen"
dim src as string
src="
class color_rgba
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
/
r as byte
g as byte
b as byte
a as byte
=
pvt as long ' hidden virtual table pointer
rgba as long
end class
methods of color_rgba
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
with this.
r = r
g = g
b = b
a = a
end with
end method
method get() as long
method=this.rgba
end method
end methods
dim c as color_rgba
c.set(125,50,0,128)
print hex c.get()
terminate
"
o2_basic src
if len(o2_error) then
msgbox 0,o2_error
stop
end if
o2_exec
Charles thanks for the correction, but I am lost in some areas.
1. I don't understand why pvt is a member variable and I don't see it used elsewhere?
2. Also, why do we use hex in the print statement for a long value-- when I take hex out, the app doesn't print?
3. I am also not sure what the = in the class declaration does?
Another request is if you can just give me a list of available keywords for oxygen it would give me an idea of what is there to play with for testing and learning.
Looking at the corrected code, I really like the syntax and layout you came up with. It is just so much fun to play with objects thanks for giving us this capability!
Charles, I am playing with method overloading and it is fun!
Anyways I did this test and I thought I should get the same value back, but I am not. Not sure why? Sorry to keep bugging you, but the only way to learn is to try, try, try and then ask for help :)
Uses "Oxygen"
dim src as string
src="
class color_rgba
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
method set(byval rgba as long )
/
r as byte
g as byte
b as byte
a as byte
=
pvt as long ' hidden virtual table pointer
rgba as long
end class
methods of color_rgba
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
with this.
r = r
g = g
b = b
a = a
end with
end method
method set(byval rgba as long )
this.rgba = rgba
end method
method get() as long
method=this.rgba
end method
end methods
dim c as color_rgba
c.set(255,255,255,255)
print hex c.get()
c.set(hex c.get()) 'Which would we use? Both return values, but they don't match the first c.get.
'c.set(c.get())
print hex c.get()
terminate
"
o2_basic src
if len(o2_error) then
msgbox 0,o2_error
stop
end if
o2_exec
Michael Hartlef
12-04-2009, 22:03
Another request is if you can just give me a list of available keywords for oxygen it would give me an idea of what is there to play with for testing and learning.
Have a look here: http://community.thinbasic.com/index.php?topic=2541.0
Thanks Mike for the link!
Charles Pegge
13-04-2009, 09:19
Hi Kent,
Yes there was a bug affecting functions being used as operands. Many thanks for exposing it! I've posted the repaired Oxygen.
http://community.thinbasic.com/index.php?topic=2517
The only error I found in your code was passing a string argument:
c.set (hex c.get())
c.set(c.get())
With Basic there is automatic type conversion, so the rules start to get a little complicated when function overloading is added. If Oxygen cannot convert the parameters to the required type then it goes in search of next method/function bearing the same name and tries that.
Uses "Oxygen"
dim src as string
src="
class color_rgba
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
method set(byval rgba as long )
/
r as byte
g as byte
b as byte
a as byte
=
pvt as long ' hidden virtual table pointer
rgba as long
end class
methods of color_rgba
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
with this.
r = r
g = g
b = b
a = a
end with
end method
method set(byval rgba as long )
this.rgba = rgba
end method
method get() as long
method=this.rgba
end method
end methods
dim c as color_rgba
c.set(1,2,3,4) : print hex c.get
c.set(0x04030201) : print hex c.get
c.set(c.get) : print hex c.get ' did not work correctly
c.set(c.get+0) : print hex c.get
terminate
"
o2_basic src
if len(o2_error) then
msgbox 0,o2_error
stop
end if
o2_exec
zlatkoAB
13-04-2009, 20:06
Hi Kent...
I have written something but for CBasic and still is unfinished.
Completly is written in Cbasic nothing external.
I think that is best way that you make form maker in thinBasic.
Zlatko
Thanks Zlatko, but in talking about using external applications... Eros mentioned how he would like it to be made with thinBasic and it made sense. This way working on such a program, new commands and ideas might show up that can be added to the language to make it that much better. And even if that were not the case, the source would provide a lot to learn from for a complex project.
Good luck on your project!
Thanks Charles, I can continue on with the experiments.
The short path of the steps coming up:
1. Finish getting a grasp of O2H, by no means fully understanding it :)
2. Work on a mini version of the form designer with very limited set of controls for development.
A. the Form Object
B. label, textbox and button objects
3. Loading all the separate files from disk and making it all work.
4. Then the cool stuff hopefully:
double click the button control in the form editor
it will allow you to enter the code for the button click event
For the test, this will entail taking the text in the label control
and putting it into the textbox
Part of this will be to have intellisense that as the code is
written, that the label and textbox controls will show their
properties at the appropriate time, in the this case their
text/caption properties.
As you can see just like MS IDE, well that is the goal at least.
Petr Schreiber
13-04-2009, 21:03
Hi Kent,
that is nice plan.
Will you handle events like <ControlName>_<Event>?
In case you will, I would recommend to stick with Win32 naming conventions, as .NET new naming makes my head spin.
I think to achieve this, you would need to auto-generate one big callback, which will redirect the events to the procedures.
Like:
CALLBACK FUNCTION Dialog1Proc()
SELECT CASE CBMSG
CASE %WM_COMMAND
SELECT CASE CBCTL
CASE %Button1
SELECT CASE CBCTLMSG
CASE %BN_CLICKED
Button1_Clicked( )
CASE %BN_KILLFOCUS
Button1_KillFocus( )
CASE %BN_SETFOCUS
Button1_SetFocus( )
END SELECT
CASE ...
END SELECT
END SELECT
END CALLBACK
Thanks Petr for the input! To tell you the truth, I had not thought about how it will come about. So I am glad you are in there to help! I just know I want this to be as cool as it can be. Once we get to some real code, I hope the community of users will join in on working on this. thinBasic has changed so much since I was away studying c++. It is almost like learning it all over. And O2H, I am fudging my way through it with Charles help. The syntax is so nice I forget it is based on writing assembly in an easier fashion.
@Charles: I saw an example where o2 can store values in thinBasic variables. The workflow direction seemed to be from o2 to thinBasic. Can it go both ways? If so, can you make a simple example where o2 and thinBasic work together and go in both directions? Thanks.
Charles Pegge
13-04-2009, 21:38
Hi Kent,
Just to clarify some contractions of the full Basic syntax that Oxygen will tolerate:
For the benefit of all who suffer from Bracketeer's Migraine or Cramp of the shift key, these are all equivalent:
c.set(1,2,3,4) : print (`1: `+hex$(c.get()))
c.set(1,2,3,4) : print `1: `+hex$(c.get())
c.set(1,2,3,4) : print `1: `+hex$(c.get)
c.set 1,2,3,4 : print `1: `+hex$ c.get
c.set 1,2,3,4 : print `1: `+hex c.get' LOSE $ SUFFIX
c.set 1,2,3,4 : print `1: ` hex c.get 'ASSUMED CONCATENATION
It's still quite easy to get caught out - so when in doubt use the full syntax then try stripping out redundant symbols.
Charles
PS: I found a few problems with overloded methods passing strings byref - fix very shortly.
Wow, so we can make it very clean looking, didn't know that Charles, thanks! I can't imagine writing a parser to deal with so many variations in syntax for the same results!!
Charles Pegge
13-04-2009, 22:15
This is how to map thinBasic Types and Oxygen classes together so that the elements/properties are shared and accessible to both.
In Oxygen: dim as color_rgba c at #mcolor
In the thinBasic Type you must also explicitly declare a Long variable for the virtual table pointer
(Special considerations apply to sharing strings)
Uses "Oxygen"
type color_rgba
pvt as long ' VIRTUAL TABLE POINTER
r as byte
g as byte
b as byte
a as byte
end type
dim mcolor as color_rgba
dim src as string
src="
class color_rgba
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
method set(byval rgba as long )
method set( byval rgba as string )
/
r as byte
g as byte
b as byte
a as byte
=
pvt as long ' hidden virtual table pointer
rgba as long
end class
methods of color_rgba
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
with this.
r = r
g = g
b = b
a = a
end with
end method
method set( byval rgba as string )
this.rgba = val rgba
end method
method set(byval rgba as long )
this.rgba = rgba
end method
method get() as long
method=this.rgba
end method
end methods
dim as string s=`0x04030201`
dim as color_rgba c at #mcolor
c.set 1,2,3,4 : print `1: `+hex c.get
terminate
"
'msgbox 0,o2_prep "#o2h "+src
o2_basic src
if len(o2_error) then
msgbox 0,o2_error
stop
end if
o2_exec
msgbox 0,mcolor.r+$crlf+mcolor.g+$crlf+mcolor.b+$crlf+mcolor.a+$crlf
Thank you for the nice example Charles. Pretty amazing how it can be embedded within the thinBasic code, I guess that never really came across to me in studying before. Thanks again!
Not that I need to pass as a string, but just to test it out I tried this and when the hex value is passed as a string, it is not working as I would expect Charles.
Uses "Oxygen"
type color_rgba
pvt as long ' VIRTUAL TABLE POINTER
r as byte
g as byte
b as byte
a as byte
end type
dim mcolor as color_rgba
dim src as string
src="
class color_rgba
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
method set(byval rgba as long )
method set( byval rgba as string )
/
r as byte
g as byte
b as byte
a as byte
=
pvt as long ' hidden virtual table pointer
rgba as long
end class
methods of color_rgba
method set byval r as byte, byval g as byte, byval b as byte, byval a as byte
with this.
r = r
g = g
b = b
a = a
end with
end method
method set byval rgba as string
this.rgba = val rgba
end method
method set byval rgba as long
this.rgba = rgba
end method
method get() as long
method=this.rgba
end method
end methods
dim as color_rgba c at #mcolor
c.set 1,2,3,4 : print `1: `+hex c.get
dim as string s=`0xffffffff`
c.set s : print `2: `+hex c.get
terminate
"
'msgbox 0,o2_prep "#o2h "+src
o2_basic src
if len(o2_error) then
msgbox 0,o2_error
stop
end if
o2_exec
msgbox 0,mcolor.r+$crlf+mcolor.g+$crlf+mcolor.b+$crlf+mcolor.a+$crlf
Charles Pegge
14-04-2009, 00:18
Yes Kent, I've been working on the string side today:
Latest posting
http://community.thinbasic.com/index.php?topic=2517
This is included as KS_test2.tbasic and has an overloaded string method and some string examples
Uses "Oxygen"
type color_rgba
pvt as long ' VIRTUAL TABLE POINTER
r as byte
g as byte
b as byte
a as byte
end type
dim mcolor as color_rgba
dim src as string
src="
class color_rgba
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
method set(byval rgba as long )
method set( byref rgba as string )
/
r as byte
g as byte
b as byte
a as byte
=
pvt as long ' hidden virtual table pointer
rgba as long
end class
methods of color_rgba
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
with this.
r = r
g = g
b = b
a = a
end with
end method
method set( byref rgba as string )
this.rgba = val rgba
end method
method set(byval rgba as long )
this.rgba = rgba
end method
method get() as long
method=this.rgba
end method
end methods
dim as string s=`0x04030201`
dim as color_rgba c at #mcolor
c.set (`0x04030201`) : print `A: ` hex c.get
c.set `&h04030201` : print `B: ` hex c.get
c.set (s) : print `C: ` hex c.get
c.set (`0x` `04` `03` `02` `01` : print `D: ` hex c.get
c.set 1,2,3,4 : print `1: `+hex c.get
c.set(1,2,3,4) : print (`2: `+hex$(c.get()))
c.set(0x04030201) : print `3: ` hex c.get
c.set(c.get) : print `4: ` hex c.get
c.set(c.get+0) : print `5: ` hex c.get
'c.set c.get : print `6: ` hex c.get
terminate
"
'msgbox 0,o2_prep "#o2h "+src
o2_basic src
if len(o2_error) then
msgbox 0,o2_error
stop
end if
o2_exec
msgbox 0,mcolor.r+$crlf+mcolor.g+$crlf+mcolor.b+$crlf+mcolor.a+$crlf
PS: I think there is a way to call Oxygen methods directly from thinBasic - I'll have to sleep on it first :)
Charles
Thanks Charles downloading the updates now.
Sleep well and good luck with making methods from classes accessible in thinBasic itself, not sure how you would pull that one off!!!
Just ran the updated files, great!! Thanks again.
Charles Pegge
14-04-2009, 10:00
Well I got this to work: thinBasic calling Oxygen methods. The object has to be passed byref as the first parameter.
Then inside Oxygen, each method has to be marked external - this triggers extra initialisation so the methods can be safely called externally.
The address of the virtual function table is passed back to thinBasic in variable pp, which is used to map out the method pointers in array p(1)..p(4)
Dim p(100) at pp
The method prototypes are then declared at corresponding array values:
declare function color_rgba_get (ob as color_rgba) as long at p(1)
... etc
This is a half-way house as I am sure it won't be long before Eros will be able to implement function overloading and OOP directly in thinBasic :). I hope this example at least demystifies the mechanics.
Charles.
'
'CALLING O2 METHODS FROM THINBASIC
'
Uses "Oxygen"
'
type color_rgba
pvt as long ' VIRTUAL TABLE POINTER
r as byte
g as byte
b as byte
a as byte
end type
dim mcolor as color_rgba
dim src as string
src="
class color_rgba
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
method set(byval rgba as long )
method set( byval rgba as string )
/
r as byte
g as byte
b as byte
a as byte
=
pvt as long ' hidden virtual table pointer
rgba as long
end class
methods of color_rgba
method get() as long external
method=this.rgba
end method
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte ) external
with this.
r = r
g = g
b = b
a = a
end with
end method
method set(byval rgba as long ) external
this.rgba = rgba
end method
method set( byval rgba as string ) external
this.rgba = val rgba
end method
end methods
dim as color_rgba c at #mcolor
'copyn #p, &color_rgba_table, sizeof color_rgba_table
[#pp]=&color_rgba_table
sub finish() at #p0
terminate
end sub
c.set `1`
"
'msgbox 0,o2_prep "#o2h "+src
dim p0,pp as long
o2_basic src
if len(o2_error) then
msgbox 0,o2_error
stop
end if
o2_exec ' 02 INITIALISE
declare sub o2_finish at p0 ' O2 TERMINATION PROCEDURES
'
' MAP METHODS
'
dim p(100) as long at pp
declare function color_rgba_get (ob as color_rgba) as long at p(1)
declare sub color_rgba_set_bytes (ob as color_rgba, byval r as byte, byval g as byte, byval b as byte, byval a as byte ) at p(2)
declare sub color_rgba_set_long (ob as color_rgba, byval rgba as long ) at p(3)
declare sub color_rgba_set_string(ob as color_rgba, byval rgba as string ) at p(4)
dim s as string="&h04030201"
'
' INVOKE METHODS PASSING OBJECT BYREF AS 1ST PARAM
'
color_rgba_set_long mcolor,&h04030201
color_rgba_set_bytes mcolor,1,2,3,4
color_rgba_set_string mcolor,"0x04030201"
color_rgba_set_string mcolor,s
msgbox 0,hex$(color_rgba_get mcolor)
o2_finish
Charles I log on today and was surprised that you have this solved already, amazing how you figured all of this out, but to do it all so quickly!
I know you started Oxygen to bring Assembly programming to allow for compiled super fast functions. Then you took it a step further to make programming easier introduced the clean basic like syntax to produce such code.
Then you brought in oop to all of the above and now have it interacting in many ways with thinBasic itself.
What a history in such a short time! Thanks.
ErosOlmi
14-04-2009, 17:59
When there is passion (and time), nothing is impossible! ;)
Charles Pegge
14-04-2009, 19:23
And good feedback is one of the essential components. This hospitable place makes progress very smooth :)
Many Thanks to all!
Now just to be a little Contra, travelling back in time I am attempting to support line numbers ( for GOSUB and GOTO )
Should be ready tonight.
Charles
ErosOlmi
14-04-2009, 19:42
;--)
No, no, no ! GOSUB and GOTO I'm very contrary on them :xyzw:
:D
Charles Pegge
14-04-2009, 20:17
Just as Arsenic and Mercury have their occasional medical uses - so does GOTO and GOSUB ;). They can help to reduce deep nestings, and also as a transient feature during code development. I think they will also be useful when porting ancient manuscripts dating from the early days when Djikstra thought that programming in Basic would inflict permanent brain damage.
Charles, am studying the HelloWin example tonight. It seems like we could do the editor all in O2, have it output a form description file and then write the script generator in thinBasic. What do you think?
If we try to use both thinBasic and O2 mixed together it looks like we need to write similar code for both which is fine for the things you developed O2 for which is giving blazing speed to functions and code sections that need it. But for a big application writing so much similar code and maintaining it seems counter intuitive to me. For such jobs I think picking one or the other is the way to go and in this case since we want to really use the cool new features in O2, I think it might be better to focus the editor with it and then the script generation in thinBasic. Does this make sense in your opinion?
Since we do have OOP in o2, do you think we can use MFC instead of just winapi, or should we develop our own MFC in a way by developing our own classes for the winapi?
Doing some reading tonight, found out ATL is a cleaner less bloated sort of MFC, but this is because it doesn't have the functionality that MFC has. Here is a link to just the window class:
ATL version: http://msdn.microsoft.com/en-us/library/dhedazz8(VS.80).aspx
MFC version: http://msdn.microsoft.com/en-us/library/1xb05f0h(VS.71).aspx
This is a neat tutorial showing how to make your own control and then using on a web page for instance:
http://msdn.microsoft.com/en-us/library/599w5e7x(VS.80).aspx
It is good to look at for ideas and discussion in our project for ideas and features and how that can lead to how we make this happen :)
Charles Pegge
15-04-2009, 22:25
Hi Kent,
Preferring incremental developement in small steps, my instinct is to go with a thinBasic GUI since a huge amount of work has gone into its development already. Then use Oxygen to manage the design data and logistics.
If the interfacing between TB and O2 proves to be too complex then I would consider deploying the GUI in Oxygen using the standard Windows API. This requires quite a lot of extra header code however.
Taking a lead from Patrice Terrier I would favour using the standard API over ATL or MFC - it's more stuff to learn!
Would like to see what you have duveloped in thinForm 1.8, but it wont run under TB 1.7.8 - maybe because of a change in control structure rules mixing case blocks with if ..else..endif.
Charles
ErosOlmi
15-04-2009, 22:38
I suppose Ken was fascinated by Oxygen OOP capabilities (as we all are). That's why he started with Oxygen. Am I wrong :D
But Kent, in a Form Designer speed is not a crucial aspect. All controls and GDI drawing are enough fast even on an interpreted application. I'm pretty sure about that. Very hardly speed will be an option to consider while dragging or designing or dimensioning a control over a dialog.
Also data structure will hardly be a problem because thinBasic can handle whatever complex structure you can have in your mind. Ok, you will not have any "method" inside that structure but a good "on paper" design and strong method in developing and maintaining/organizing source code can make the real difference.
As usual the way is to start simple but well organized till the very beginning.
Ciao
Eros
Charles Pegge
15-04-2009, 23:21
Kent, I wanted to show you this example. It uses a dynamic color object and unlike the previous example, it is isolated from thinBasic variable space. When the object is created, it returns a handle to thinBasic. This is used in all subsequent method calls. Apart from the declarations, thinBasic does not need to know anything else about the object, or indeed that it is OOPed.
'
'CALLING O2 METHODS FROM THINBASIC
'This example shows how to create use and delete a dynamic object
'The actual object is isolated from thinBasic. The object is referenced
'only by its handle.
Uses "Oxygen"
'
dim src as string
src="
class color_rgba
method create() as long
method delete()
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
method set(byval rgba as long )
method set( byval rgba as string )
/
r as byte
g as byte
b as byte
a as byte
=
pvt as long ' hidden virtual table pointer
rgba as long
end class
methods of color_rgba
method create() as long external
method = news sizeof color_rgba
end method
method delete() external
frees this
end method
method get() as long external
method=this.rgba
end method
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte ) external
with this.
r = r
g = g
b = b
a = a
end with
end method
method set(byval rgba as long ) external
this.rgba = rgba
end method
method set( byval rgba as string ) external
this.rgba = val rgba
end method
end methods
[#pp]=&color_rgba_table
sub finish() at #p0
terminate
end sub
"
'msgbox 0,o2_prep "#o2h "+src
dim p0,pp as long
o2_basic src
if len(o2_error) then
msgbox 0,o2_error
stop
end if
o2_exec ' 02 INITIALISE
declare sub o2_finish at p0 ' O2 TERMINATION PROCEDURES
'
' MAP METHODS
'
dim p(100) as long at pp
declare function color_rgba_create (byval xx as long) as long at p(1)
declare sub color_rgba_delete (byval ob as long) as long at p(2)
declare function color_rgba_get (byval ob as long) as long at p(3)
declare sub color_rgba_set_bytes (byval ob as long, byval r as byte, byval g as byte, byval b as byte, byval a as byte ) at p(4)
declare sub color_rgba_set_long (byval ob as long, byval rgba as long ) at p(5)
declare sub color_rgba_set_string(byval ob as long, byval rgba as string ) at p(6)
dim s as string="&h04030201"
'
' INVOKE METHODS PASSING OBJECT BYREF AS 1ST PARAM
'
dim mcolor as long=color_rgba_create(0)
color_rgba_set_long mcolor,&h04030201
color_rgba_set_bytes mcolor,1,2,3,4
color_rgba_set_string mcolor,"0x04030201"
color_rgba_set_string mcolor,s
msgbox 0,hex$(color_rgba_get mcolor)
color_rgba_delete(mcolor)
o2_finish
@Eros, you are 100% correct the oop aspect of oxygen is drawing me in like a light does a moth. You are also correct that for the form designer speed is not critical. As you know I love thinBasic not only for the language but for the team here and community. It is the best! But I am so convinced that OOP is the future, seeing the applications out there on the cutting edge, it is hard to imagine such complex applications coming out in a reasonable time could be done without OOP.
Also just looking at the last 5 years, look at all the new devices coming out in all shapes and sizes. My hidden agenda is to take all this creative and productive work being done here and move it to an infrastructure that is set for the incredible future coming up. Every month of development of code that goes by based on infrastructure of the past is that much more code that eventually will have to be rewritten. I would rather say, set a date for thinBasic PowerBasic core to finish and move onto a more future safe development language as soon as possible, or start development of OOP version now too alongside thinBasic PBCore version. There are many foundation languages out there that I think are better suited for many reasons, but the reason to go with a Microsoft language is that you are always working with cutting edge and future safe languages, that is supporting latest hardware and programming features. The languages are free. So anyone wanting to develop can and make the community even that more accessible. There is an incredible amount of help and support for MS based languages. Also, if MS is hated because of size and .net requirements, then codeblocks, netbeans or any other free ide could be used. I think for writing non .net applications, the only real choice is c++. FreePascal I love too, but you always have the problem of having to convert perfectly good MS code ready to use in C++ for another language and so you are either dependent on other developers or have to do so much work yourself that is really a waste of time if you ask me. But Lazarus Free Pascal combo should be looked at seriously as it runs on many OS and plaftorms and I think the coding style is so close to Basic that it won't have the allergic reaction that we lovers of clean syntax get with c++.
You might say, well then we will end up with Visual Basic, why develop thinBasicEvolution? The answer is that it will be a non .net dependent language that can be small but able to run on many platforms. It will be an easy small install as thinBasic is now and maintain all the things that make thinBasic what it is but with the added advantage of being future safe and powered to do any project any size in a modern manner.
So the bottom line: pros: c++ access to new things in programming available immediately. Lot of help and support for the language. If you use MS Visual Studio, an incredible IDE and work environment.
But you have access to many smaller and nice free IDE's too. You can write apps in procedural or oop.
Cons: syntax and complexity. Also in playing around with it, not really truly cross platform. GUI's need to be written for different OS's etc.
LazarusFreePascal: pros: nicer syntax. Almost everything you need today already converted and ready to use. A nice IDE that makes cross platform GUI apps that run on many many platforms.
Cons: Not having access to the latest programming features, methodologies as well as libraries. You don't have a choice in coding as procedural or OOP. I might be wrong on this as I don't know if Lazarus supports pre oop pascal?
Another thought is maintain 2 thinBasics. thinBasic and thinBasicOOP. thinBasic will be powerbasic based for the future. thinBasicOOP will be another language.
@Charles, thanks for the example. It is great to have this availability for why you originally developed your module for, that is writing performance code and routines for speed sensitive parts. But I don't think it makes sense to write the form designer in both. I think to show what can be done with oxygen to write a fully oop based complex application will be really cool to push its development and flesh out ideas. But I will follow your lead on this project... you have an exponentially more deeper understanding of all things in involved with oxygen and even thinBasic.
@Eros and Charles, I think on a project like this you guys are the brain trust to plan and set maybe a workflow and plan for how this should go. I will be a happy worker bee just to see and learn and have fun coding.
If somehow, I can light the fires to move as soon as possible at least on starting thinBasicOOP... then maybe we should wait to develop in that environment. Or establish a team to start working on it... I would be game, I think Charles would enjoy it. Eros could be like Python's founder Guido van Rossum in giving guidance on how he wants the new thinBasicOOP syntax to be etc. He would have final thumbs up or down on features and ways of doing things. I think Charles could be the lead on the OOP thinBasic and the rest of us could learn a lot and have lots of fun in contributing language code.
ErosOlmi
16-04-2009, 04:43
Kent,
PowerBasic 9.x has now almost full OOP capabilities. More, it is fully COM compliant both for creating client and server COM. Power Basic future is bright if you ask me.
Having a compiler with OOP does not mean you need to have an interpreted with OOP. I could have written thinBasic 100% in some .Net languages and be exactly the same as it is now. Maybe in future thinBasic will have OOP capabilities but this must come during the natural evolution of thinBasic and not just because a single project would like to have it.
As I said many times, running under Windows only we are getting around 87% of the possible computer market, so quite enough arena.
And again, for the future I do not see Windows Mobile "forever" but I see a great upgrade of the hardware (see Intel Atom) so it is more possible to see XP compatible operating system over a mobile phone than a mobile phone of the year 2015 having a downgraded/reduced version of XP (Windows Mobile).
That said, you did a quite agreeable picture of the software situation. And I perfectly know you are telling all that in a positive and open minded way. And for this I will always thank you.
Ciao
Eros
ErosOlmi
16-04-2009, 07:06
Hoping to possibly help, I've attached to this post a TAB control editor that is very very close to a form editor. It has all the main functionalities of a form editor.
Project name was QTab. It is also able to generate Basic Source Code as output so also this functionality is covered.
Included in .zip file your can find full Power Basic source code from which one can take some of the needed part/ideas on how to make a form designer.
Source code is public domain from "JULES MARCHILDON".
One of my original idea was to add some functionalities of a form designer directly into thinBasic UI module so, for example, a control can "selected" and handlers painted and their event managed directly by the UI module. The same for control moving and control properties. Also add to UI module a sort of running flag: design mode, run mode in order to be able to switch in design mode at script runtime.
But this can be something for the future.
Hope this can help.
Ciao
Eros
Michael Hartlef
16-04-2009, 07:26
Nice one. Thanks a lot!!! :eusadance:
Eros, I only mean to bring these things up only to get our minds thinking of possibilities and a dialog going on in the state of things and possible paths. As always my intent is always in a positive way.
PowerBasic has many pros and especially with what I read in the email newsletters from Mr. Zale now is going to be able to offer solutions in the Windows world for some time and project sizes.
All of you developing for thinBasic using it-- show its power.
For now I guess I will concentrate on Oxygen as the oop setup that Charles came up with is neat. If the form designer is not a good application to develop with it, I am sure we can come up with something else. I think there is so much there that needs to be seen by the rest of the programming community and I think it is such a great module for thinBasic in that it does open up many secret doors.
I will wait to see what sort of plan you guys come up with and keep plugging away at learning oxygen and thinking of other projects just in case.
ErosOlmi
16-04-2009, 09:53
Eros, I only mean to bring these things up only to get our minds thinking of possibilities and a dialog going on in the state of things and possible paths. As always my intent is always in a positive way.
I perfectly know :D
And remember: you are welcome even when you made critics !
Charles Pegge
16-04-2009, 10:39
Looking at the QTAB package posted by Eros (above), we can see that thinForm is likely to be a major major project involving many months of work. The source code of QTAB is 1.3 Megabytes - about 2.5 times the size of Oxygen, allbeit with a simpler architecture.
But I wonder if we might consider 3D controls - based on TBGL/Opengl with less emphasis on traditional Windows graphics. This would be a good long-term investment of time and effort with many useful components and opportunities for group participation, both artistic and technical.
Just imagine what controls a web browser might have in 2020 and what it would look like...
Eros, I only mean to bring these things up only to get our minds thinking of possibilities and a dialog going on in the state of things and possible paths. As always my intent is always in a positive way.
I perfectly know :D
And remember: you are welcome even when you made critics !
That is why this community is so great to be in, the leadership loves dialogs and creative discussions and not bottling up free speech, thanks!!
Looking at the QTAB package posted by Eros (above), we can see that thinForm is likely to be a major major project involving many months of work. The source code of QTAB is 1.3 Megabytes - about 2.5 times the size of Oxygen, allbeit with a simpler architecture.
But I wonder if we might consider 3D controls - based on TBGL/Opengl with less emphasis on traditional Windows graphics. This would be a good long-term investment of time and effort with many useful components and opportunities for group participation, both artistic and technical.
Just imagine what controls a web browser might have in 2020 and what it would look like...
Charles, this is a good idea. It would test and push Oxygen as making thinForm would, but again this could be made with tbgl alone I think. What about taking it a step further... making a visual programming synthesizer. We would write code visually with synth modules, imagine a module for variables, loops statements, conditionals etc. The programmer would drop modules and just fill in the components (Properties) and then wire the modules together. Here is the neat thing. Using the new compile command, each module would self compile making for a really pushing test of Oxygen and bringing something unique to thinBasic that could not be done with thinBasic alone?
We could do this in steps, for instance for a console application at first to develop the logic modules, input and output. Then once we have those modules working and see that we can do it, we could try to expand it to other areas of thinBasic modules (tbgl, tbem, tbdi ) and then to thinBasic itself.
I need to run and won't be home till late, so forgive me in advance for not replying to anything today, till what will probably be tomorrow for you guys.
Eros I guess we should move this thread somewhere else as it didn't turn out to be a user tool thread. This way when something is finished it can be here I guess. Thanks.
Charles playing around with inherited method and default value. Couldn't get neither to work, wonder what I am doing wrong. Thanks.
Uses "Oxygen"
dim src as string
src="
class color_rgba
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
method set(byval rgba as long )
method set( byval rgba as string )
/
r as byte
g as byte
b as byte
a as byte
=
pvt as long ' hidden virtual table pointer
rgba as long
end class
methods of color_rgba
method set (byval r as byte, byval g as byte, byval b as byte, byval a as byte)
with this.
r = r
g = g
b = b
a = a
end with
end method
method set (byval rgba as string)
this.rgba = val rgba
end method
method set (byval rgba as long)
this.rgba = rgba
end method
method get() as long
method=this.rgba
end method
end methods
class dummy_object
c as color_rgba 'color
n as string = `Arthur` 'trying out asssigning default values
end class
dim o as dummy_object
print `1: ` + o.n 'looking for Arthur to show up here
o.n = `Henry`
print `2: ` + o.n
o.c.set(128,255,0,128)
print `3: `+hex o.c.get
terminate
"
o2_basic src
if len(o2_error) then
msgbox 0,o2_error
stop
end if
o2_exec
msgbox 0,"Finished"
Charles Pegge
17-04-2009, 07:03
Hi Kent,
Here is the fuxed code:
class dummy_object
method init()
c as color_rgba ' inherited
/
n as string
end class
methods of dummy_object
method init()
'asssigning default values
this.c.set 1,2,3,4
this.n= `Arthur`
end method
end methods
I've spotted an o2 glitch further down the line but this works okay:
uses "Oxygen"
dim src as string
src="
class color_rgba
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
method set(byval rgba as long )
method set( byval rgba as string )
/
r as byte
g as byte
b as byte
a as byte
=
pvt as long ' hidden virtual table pointer
rgba as long
end class
methods of color_rgba
method set (byval r as byte, byval g as byte, byval b as byte, byval a as byte)
with this.
r = r
g = g
b = b
a = a
end with
end method
method set (byval rgba as string)
this.rgba = val rgba
end method
method set (byval rgba as long)
this.rgba = rgba
end method
method get() as long
method=this.rgba
end method
end methods
class dummy_object
method init()
c as color_rgba 'color
/
n as string
end class
methods of dummy_object
method init()
this.c.set 1,2,3,4
this.n= `Arthur` 'trying out asssigning default values
end method
end methods
dim o as dummy_object : o.init
print `1: ` + o.n 'looking for Arthur to show up here
o.n = `Henry`
print `2: ` + o.n
'o.c.set(128,255,0,128)
print `3: `+hex o.c.get
terminate
"
o2_basic src
if len(o2_error) then
msgbox 0,o2_error
stop
end if
o2_exec
msgbox 0,"Finished"
Charles Pegge
17-04-2009, 07:24
Kent
=>making a visual programming synthesizer.
I dream of this :)
When I first heard about visual-C, I thought it must be a new technique of programming with icons and diagrams!
But it didn't quite live up to my expectations.
But with instant compiling of objects, we could make the coding process far more interactive.
ErosOlmi
17-04-2009, 09:37
Eros I guess we should move this thread somewhere else as it didn't turn out to be a user tool thread. This way when something is finished it can be here I guess. Thanks.
Moved to Oxygen dedicated forum where Charles is moderator so he can take care of it ;)
Charles Pegge
17-04-2009, 13:16
Hi Kent
I've just cleared out a few Object assignment problems and put some alternative expressions into your code.
While we are on the subject of multiassignment today, I'll point out a new feature which can be used with inherited structures.
Since Dummy_Object inherits Color_RGBA, object o will incorporate colours as:
o.c.r
o.c.g
o.c.b
o.c.a
It is now possible to assign values to the color components c in o directly like this:
o.c=>10,20,30,40
Oxygen can identify any inherited type and assign values to its elements in the correct format.
Eros has pointed out that multiassigning is not good practice (where the Type structure is likely to change), but
I see its main application in efficiently transferring data to small stable structures including Complex numbers, vectors, matrices and dictionaries.
Oxygen Upate:
http://community.thinbasic.com/index.php?topic=2517
uses "Oxygen"
dim src as string
src="
class color_rgba
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
method set(byval rgba as long )
method set( byval rgba as string )
/
r as byte
g as byte
b as byte
a as byte
=
pvt as long ' hidden virtual table pointer
rgba as long
end class
methods of color_rgba
method set (byval r as byte, byval g as byte, byval b as byte, byval a as byte)
with this.
r = r
g = g
b = b
a = a
end with
end method
method set (byval rgba as string)
this.rgba = val rgba
end method
method set (byval rgba as long)
this.rgba = rgba
end method
method get() as long
method=this.rgba
end method
end methods
#view
class dummy_object
method init()
c as color_rgba
/
n as string
end class
#endv
methods of dummy_object
method init()
'asssigning default values
'this.n= `Arthur`
'this.c.rgba=0x40302010
'this.c.r=>1,2,3,4
'this.c=>1,2,3,4,5
'this.c.set 1,2,3,4
this=>`Arthur`,1,2,3,4
end method
end methods
dim o as dummy_object : o.init
print `1: ` + o.n 'looking for Arthur to show up here
o.n = `Henry`
'o=>`henry`,1,2,3,4
'o.c=>1,2,3,4
print `2: ` + o.n
'o.c.set(128,255,0,128)
print `3: `+hex o.c.get
terminate
"
o2_basic src
'msgbox 0,o2_prep "o2h "+src
if len(o2_error) then
msgbox 0,o2_error
stop
end if
o2_exec
Lionheart008
17-04-2009, 18:59
hi charles :)
hi all...
my dummy question (sorry about that!): as I have never used before oxygen script, can you tell me what I have to need to use these scripts and I like your massive improvements about this chapter... perhaps I have in mind to improve my undesigned game script with oxygen tbgl... at the board (some days before) was a post with this oxygen/tbgl feature...
can you help me? I haven't time enough the last week to read all posts... uargh... ;)
by the way: Great work! Compliments ! and good luck for further developments :occasion:
ciao, servus, Lionheart
Charles Pegge
17-04-2009, 21:08
Hi Lionheart,
thinBasic_Oxygen.zip comes with the Oxygen dll and a number of examples
TBGL_O2H.zip has some mixed 3D examples
I'm updating these files at least twice a day - with new examples, tuning up features and fixing problems.
Eros will include the latest Oxygen with the next release of thinBasic but I will continue posting to this board as the project develops over the next few months.
The original manual only covers Assembly code but I hope useful material for a new manual will emerge from our discussions here.
As you can see, some aspects are quite experimental, and we may have to set up a separate panel to isolate the more fiendish features :diablo:
http://community.thinbasic.com/index.php?topic=2517
Charles
Eros I guess we should move this thread somewhere else as it didn't turn out to be a user tool thread. This way when something is finished it can be here I guess. Thanks.
Moved to Oxygen dedicated forum where Charles is moderator so he can take care of it ;)
Thanks for moving Eros!
Thanks Charles, that is so cool! I really like how you are handling the syntax and am blown away that you have method inheritance already in there.
I wasn't sure about the / symbol, I am pretty sure it is to separate methods from properties now. I like how it looks as it is easy to see the property section from the method section!
I am very excited that working on a visual programming synth is something you always wanted to work on... it with games have always been my goals.
Here are some links to show a history of what I have seen, the little I have played with and then after you have time to look at these I will give my thoughts on why I think they do some things certain ways and you can give me your ideas and then we can brainstorm on our own version.
The earliest video archive I have found of visual programming, if you have not ever seen this you will really enjoy it I think:
http://www.archive.org/details/VisualPr
These days I am finding many of the advanced 3D programs to have what they call procedurals, networks or nodes:
This is Houdini 3D Application, it is all underneath writing and creating the network for the project.This video shows how they put nodes, edit and link, you only need to see one to see how it works, as this would be how they visual program. This is how most of the apps seem to be these days in one way or another.
http://download.sidefx.com/images/stories/tutorials/ray_normals/ray_normals_part1.mov
Here is a screenshot of Blender's nodes.
http://www.blender.org/index.php?eID=tx_cms_showpic&file=uploads%2Fpics%2Fed_bridge_comp_nodes.png&width=800m&height=600m&bodyTag=%3Cbody%20style%3D%22margin%3A0%3B%20background%3A%23fff%3B%22%3E&wrap=%3Ca%20href%3D%22javascript%3Aclose%28%29%3B%22%3E%20%7C%20%3C%2Fa%3E&md5=287bed63eb4455349b99723180eda4d6
Are you on Skype or Google Chat/Video? We can voice conference and sort of collab on a whiteboard together. I will make another post of this cool web application I have been using to help my Old Boss in Ohio with computer problems as well as family and friends. It is really neat. But with Skype as that is what I mainly use it is better sounding than a phone, it works really well.
http://community.thinbasic.com/index.php?topic=2626.0
This should be really fun to work on this visual programming synth!
Michael Hartlef
18-04-2009, 01:21
Actually Quest3D is a tool that has a method like this too.
http://quest3d.com/
Actually Quest3D is a tool that has a method like this too.
http://quest3d.com/
Thanks Mike, I forgot all about this program... but many of the bigger 3D Apps are going this route as it is easier for artists to do programming without really realizing that they are.
Charles, in:
class color_rgba
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
method set(byval rgba as long )
method set( byval rgba as string )
/
r as byte
g as byte
b as byte
a as byte
=
pvt as long ' hidden virtual table pointer
rgba as long
end class
Do I need to write a get method for r, g, b and a? The reason I ask is when I try to print them directly with
print `4: `+ str o.c.r
or with
print `5: `+ hex o.c.r
I get zero.
Do I need to write a get method for them? This is no problem as it would be like having private members, just curious.
Charles Pegge
18-04-2009, 14:31
Hi Kent,
I don't have any audio-visual for Skype at the moment but it sounds a good idea later on.
Thanks for the links, there's much to think about. I have not come across visual programming down to the single expression level yet. Its more configuring pre-existing code. I'm intrigued by the node graphs and wonder how far you can take them, since there must be considerable underlying complexity in connecting the nodes together.
On the O2 side, All of these should work:
o.c=>1,2,3,4
print hex o.c.r
print hex o.c.rgba
o.c.set 1,2,3,4
print hex o.c.get
A private flag for methods and properties is in the plan buts needs further work which I hope to do later today.
Charles
Charles I assembled a bunch of links that we can look at and discuss when you get Skype with Audio working. Many have similar features and each has a certain way of doing things, but when we collab and look together we can discuss what we like and don't like in each. I think both of us have a similar idea from looking at your previous projects that I saw on Jose's site. I am sure this image for the project in our mind's eye is different from what is out there in many ways.
About properties in a class, I will paste the code as I didn't seem to explain my question clearly before:
' Empty ASSEMBLER file template
uses "Oxygen"
dim src as string
src="
class color_rgba
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
method set(byval rgba as long )
method set( byval rgba as string )
/
r as byte
g as byte
b as byte
a as byte
=
pvt as long ' hidden virtual table pointer
rgba as long
end class
methods of color_rgba
method set (byval r as byte, byval g as byte, byval b as byte, byval a as byte)
with this.
r = r
g = g
b = b
a = a
end with
end method
method set (byval rgba as string)
this.rgba = val rgba
end method
method set (byval rgba as long)
this.rgba = rgba
end method
method get() as long
method=this.rgba
end method
end methods
#view
class dummy_object
method init()
c as color_rgba
/
n as string
end class
#endv
methods of dummy_object
method init()
'asssigning default values
'this.n= `Arthur`
'this.c.rgba=0x40302010
'this.c.r=>1,2,3,4
'this.c=>1,2,3,4,5
'this.c.set 1,2,3,4
this=>`Arthur`,1,2,3,4
end method
end methods
dim o as dummy_object : o.init
print `1: ` + o.n 'looking for Arthur to show up here
o.n = `Henry`
'o=>`henry`,1,2,3,4
'o.c=>1,2,3,4
print `2: ` + o.n
o.c.set(128,50,175,255)
' I would expect to see some sort of value
' for r, since it has been set and that
' should be 128 in this example
'print `3: `+hex o.c.get
print `4: `+ str o.c.r
print `5: `+ hex o.c.r
print `6: `+ o.c.r
terminate
"
o2_basic src
'msgbox 0,o2_prep "o2h "+src
if len(o2_error) then
msgbox 0,o2_error
stop
end if
o2_exec
Also, I was trying to see if I can use a simple ASM example I found on the freeBasic site within Oxygen.
How could I translate this correctly, it will help me perhaps figure out where to find tutorials to
learn asm more.
Thanks in advance!
'testing example asm code from FreeBasic site
Uses "Oxygen"
dim src as string
src="
.model small
.stack
.data
message db `Hello world, I'm learning Assembly !!!`, `$`
.code
main proc
mov ax,seg message
mov ds,ax
mov ah,09
lea dx,message
int 21h
mov ax,4c00h
int 21h
main endp
end main
"
if len(o2_error) then msgbox 0,o2_error
o2_asmo src
o2_exec
if len(o2_error) then msgbox 0,o2_error
Charles Pegge
18-04-2009, 23:26
Hi Kent,
that assembler example is 16bit DOS. Is it Masm? I have not attempted any DOS Asm for decades.
I would go for 32 bit code in the Windows environment - You don't have to worry about segment registers and the addressing scheme is uniformly 32 bit.
This is something you may remember - I was playing with the GAS Assembler to produce a complete HelloWin
http://www.jose.it-berater.org/smfforum/index.php?topic=1579.0
You can compare this with Oxygen's Assembly Code HelloWin below. WinAPI is dependent on Oxygen - but the HelloWin has all the code to generate a standalone EXE file. It's a big hairy beast because it has all the code needed to build the PE Header tables.
If you play with this, it contains many of the the essentials for low level windows programming. And it will be my platform for building O2H EXEs and DLLs later on. :)
You will find other examples in the Oxygen zip under o2Asm\exe_dll_pe
Lionheart008
19-04-2009, 00:01
hi all, hi charles:)
I have tried my first example with oxygen and have seen the difference to thinbasic :) messages and syntax as far as I have used it for this example...
' ARITHMETIC EXAMPLE BY LIONHEART :)
uses "oxygen", "math"
dim a, b, c as long
dim d as string = "Hey, what's going on here with oxygon???"
a = 2
b = 4
c = a*b
d = "what's going on here with oxygen?"
o2_basic " print str 1+2+3+4+5 : terminate " '15
msgbox 0, "result 1: " + c
o2_exec
o2_basic " print str 6+7+8+9+10 : terminate " '40
msgbox 0, "result 2: " + d
o2_exec
o2_basic " print str pi : terminate " + pi
o2_exec
msgbox 0, "my lovely little pi is: " + pi
I am not sure if I have all the time to have a closer look at these very interesting script syntaxes... I like it, but confuse me more at the moment than clear my mind... I have enough to do with understanding all thinbasic stuff ! :D
good luck for further developments, Ciao and good night, Lionheart
Charles Pegge
19-04-2009, 00:03
This example shows how to mark members as private - including entire inherited members.
Members which are marked private are only visible in the current class - nowhere else.
Members may be tagged private by adding a minus sign at the end of the line
or by putting private to the left of the member name.
There were a few problems to sort out (one affecting byte variable parameters passed byval).
So here's the update:
http://community.thinbasic.com/index.php?topic=2517
uses "Oxygen"
'
'TESTING PRIVATE MEMBERS
'
dim src as string
src="
class color_rgba
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
method set(byval rgba as long )
method set( byval rgba as string )
/
r as byte -
g as byte -
b as byte -
a as byte -
=
pvt as long ' hidden virtual table pointer
rgba as long -
end class
methods of color_rgba
method set (byval r as byte, byval g as byte, byval b as byte, byval a as byte)
with this.
r = r
g = g
b = b
a = a
end with
end method
method set (byval rgba as string)
this.rgba = val rgba
end method
method set (byval rgba as long)
this.rgba = rgba
end method
method get() as long
method=this.rgba
end method
end methods
#view
class dummy_object
method init()
method set(s as string, byval v as long)
method set(s as string, byval r as byte, byval g as byte, byval b as byte, byval a as byte)
method get() as string
private c as color_rgba
/
private n as string
end class
#endv
methods of dummy_object
method init()
this.n=>`Arthur`
this.c.set 1,2,3,4
end method
method set(s as string, byval v as long)
this.n=s
this.c.set v
end method
method set(s as string, byval r as byte, byval g as byte, byval b as byte, byval a as byte)
this.n=s
this.c.set r,g,b,a
end method
method get() as string
method=this.n+` `+hex this.c.get
end method
end methods
dim o as dummy_object
o.init
o.set `Fred`,0x10203040
o.set `Fred`, 5,6,7,8
print o.get
terminate
"
o2_basic src
if len(o2_error) then
msgbox 0,o2_error
stop
end if
'msgbox 0,o2_prep "o2h "+src
o2_exec
Lionheart008
19-04-2009, 00:15
hi charles...
everything is ok with the script... checked it with the current oxygen dll and scripts... :D
the last script with mark members as private I can run again :)... updated the o2h folder... sorry, you are very fast with updating the module :D
lionheart :)
ps: edit and delete my error messages according to having not-updating-dll ;)
ErosOlmi
19-04-2009, 00:32
Oxygen module is under continuous developed by Charles.
To test latest features you need to download latest version (updated very very frequently) from http://community.thinbasic.com/index.php?topic=2517.0
Thanks Charles, but I still can't print the member variable r
print hex+o.c.r
In many OOP I see that you need to write get and set methods for internal member variables and I was wondering if this is how Oxygen is setup.
I am fine with it, just wanted to know.
But for testing, when I assign a value to dummy object's color sub class via the set method, as you have shown the set works and the get works,
but retrieving individual member variables are not working. Again, this could be by design as internal member variables should be protected and accessor
methods should be used. So just wanted to clarify it.
So if I use o.c.set(128,0,0,255)
then if I want get r
print hex o.c.r
This doesn't work or I am doing something wrong.
But if we need to write a method like this that would be fine too.
print o.c.get(r)
In the mean time I will study your other source file.
Charles Pegge
19-04-2009, 01:02
Hi Lionheart,
Glad you got it working
I checked myself too:
Not much wrong. I just rearranged it slightly and fixed punctuation.
The PI output from Oxygen is only double precision (I've temporarily borrowed FreeBasic's runtime str)
To check for errors after o2_basic.
if len(o2_error) then msgbox 0,o2_error
I hope this is what you were aiming for.
Charles
' ARITHMETIC EXAMPLE BY LIONHEART
uses "oxygen", "math"
dim a, b, c,d as long
a = 2
b = 4
c = 1+2+3+4+5
d = 6+7+8+9+10
o2_basic " print str 1+2+3+4+5 : terminate " '15
o2_exec
msgbox 0, "result 1: " + c
o2_basic " print str 6+7+8+9+10 : terminate " '40
o2_exec
msgbox 0, "result 2: " + d
o2_basic " print `only double precis pi ` str pi : terminate " ' pi
o2_exec
msgbox 0, "my lovely extended precis pi is: " + pi
'msgbox 0,o2_view " o2h : print str pi : terminate " ' ASM LISTING
Charles, just bumping this in case we cross posted. Can you review the message above your last response to Lionheart. Thanks.
Charles Pegge
19-04-2009, 01:27
Hi Kent,
>Thanks Charles, but I still can't print the member variable r
>print hex+o.c.r
In the last example, I'v made all the proerties private so only the methods can be used.
If you take off the private tags - all is visible again
print hex+o.c.r
replace + sign with space
print hex o.c.r
this is equivalent to
print hex$(o.c.r) which also works
I think we will need a protected mode as well as private so derived classes can alter their inherited proprtties directly if so desired.
Morpheus approaches. Good night!
Charles
Thanks Charles, good night.
Lionheart008
19-04-2009, 01:45
hi again.. my last input this night... added my last script and I am satisfied to grap some new knowledge :) thanks for your reply, charles... ;)
try this one... with inputbox$... not perfect as the usual script example, just to find out if it's run clearly...
' ARITHMETIC EXAMPLE WITH INPUTBOX BY LIONHEART
uses "oxygen", "math"
dim a, b,c,d,e as long
a = 2
b = 4
c = 1+2+3+4+5
d = 6+7+8+9+10
e = a*b
o2_basic " print str 1+2+3+4+5 : terminate " '15
o2_exec
msgbox 0, "result 1: " + c
o2_basic " print str 6+7+8+9+10 : terminate " '40
o2_exec
msgbox 0, "result 2: " + d
o2_basic inputbox$ "hello dear o2h user :)"
o2_exec
o2_basic " print `only double precise pi ` str pi : terminate " ' pi
o2_exec
msgbox 0, "my lovely extended precise pi is: " + pi
msgbox 0, "...all is correct now, simple math. result : " + e
good night, lionheart
ps: what is asm??? ;) I tried it and makes a list with unknown signs for me , I laugh :D
'msgbox 0,o2_view " o2h : print str pi : terminate " ' ASM LISTING
Lionheart, ASM is for Assembly language that is compiled by an Assembler for a particular CPU. As I am finding out, it seems as the number of bits that a cpu changes so does the Assembly language to adjust to it and this is probably due to more registers, which are like memory locations right in the cpu itself. Sorry that is the best I can explain it at the moment as I trying to find a good tutorial for the right assembly language on the net.
I did read that Charles is using the Assembly for FreeBasic, which is called "AS" and this in turn is based on "GAS" which is used for gnu's gcc compiler.
So I will try to find a good tutorial sight for GAS and see if we can figure it out.
Charles Pegge
19-04-2009, 06:51
Hi Lionheart,
Excellent idea using the input box. 8)
An instant calculator:
uses "oxygen"
dim q as string
do
q=inputbox$ "Enter An Expression: "
if q="" then exit do
o2_basic " print str "+q+" : terminate"
if len(o2_error) then msgbox 0,o2_error
o2_exec
loop
Charles, that is not right, how can it do so much with just so few lines????
I've been reading asm tutorials on the web and getting nowhere when trying to get them to run in Oxygen.
Looking over the hello window example, it just seems like having to write too much code in this day and age.
Isn't there a Windows Class Library we could tap into written for assembly out there?
I would hate to think that you would have to write such a beast or to replicate what has been written in thinBasic and its modules for Oxygen.
At the moment I am very confused on the end of one thing and the start of another :)
I know Oxygen was written to bring incredibly fast code for needed sections for thinBasic and as you show write very powerful code that is Magic.
In both of those it is perfect that is for sure from what we have seen.
Perhaps a new approach can be made.... instead of having to write the whole program in Oxygen, why not tap into an existing oop language like c++
to create the code for windows, controls and all the things that would need to be written, then use those classes in Oxygen?
Since both are oop, could an object be shared as a reference. Or second choice, as a pointer?
Charles Pegge
19-04-2009, 07:45
Hi Kent,
Here is a possible way into Assembler.
Another variation on the calculator ;)
uses "oxygen"
'
'INSTANT ASSEMBLY CODE TESTER
'
'
'Use colons as instruction separators
'
dim p,q,t as string
t="ASSEMBLY CODE TESTER"
p="Use colons as separators."+$cr+_
"Variables A to Z available."+$cr+_
"Safe registers to alter:"+$cr+" eax"+$cr+" ecx"+$cr+" edx"+$cr+" edi"+$cr+$cr+_
"Simple instructions:"+$cr+" mov add sub and or xor shl shr sar"+$cr+$cr+_
"Answer is Hexadecimal value of EAX."
q="mov eax,21 : add eax,eax"
do
q=inputbox$ p,t,q
if q="" then exit do
o2_basic " dim a,b,c,d,e,f,g,h,i : "+q+" : mov a,eax : print hex a : terminate"
if len(o2_error) then msgbox 0,o2_error
o2_exec
loop
Lionheart008
19-04-2009, 10:51
hi charles, kent, all oxygen friends :)
thanks for compliments too ;)
little question after building last night this first hello script... at the end I have got an 02 message with a always changing number... why ??? :)
' THE HELLO PROGRAM WITH STRING
uses "oxygen", "math"
dim Lionheart as string = "print `starts new x-men movie: so you can knowing more about woolverine's mutant power!` "
o2_basic " print `Hello dear thinbasic & oxygen user: nice to meet you !` : terminate "
if len(o2_error) then msgbox 0,o2_error
o2_exec
o2_basic " print str "+Lionheart+" : terminate"
o2_exec
'16230484
'16229884
'16229076
I am thinking I can fall in love with oxygen power... although I am totally fit and need no o2 for daily life :D ... and today it's a private day (sunday) and fairytale party here in my little hometown... need more sunshine as a lion :) help you if I can... with some examples...
ciao and thanks again for responding my questions..., nice sunday :-D
Lionheart
ps: instant calculator is great... btw ... I have to quit now, my girlfriend is pushing me! :)
pps: the inputbox example can be improved.. I will do that next days ;)
ppps: "dim chiffre as long(???) = 1045-XPA-4839ABC"
how can I build this one ??? tried it last night, but cannot find it... for chiffre or password creation...
Charles Pegge
19-04-2009, 11:03
Lionheart already contains the print command.
' THE HELLO PROGRAM WITH STRING
uses "oxygen", "math"
dim Lionheart as string = "print `starts new x-men movie: so you can knowing more about woolverine's mutant power!` "
o2_basic " print `Hello dear thinbasic & oxygen user: nice to meet you !` : terminate "
if len(o2_error) then msgbox 0,o2_error
o2_exec
o2_basic Lionheart+" : terminate"
o2_exec
Charles Pegge
19-04-2009, 11:23
ppps: "dim chiffre as long(???) = 1045-XPA-4839ABC"
how can I build this one ??? tried it last night, but cannot find it... for chiffre or password creation...
uses "Oxygen"
o2_basic "dim as string chiffre=`1045-XPA-4839ABC` : print `psst! Lonheart's password is: ` chiffre : terminate"
o2_exec
Charles Pegge
19-04-2009, 14:27
Kent,
Protected Members
A dot at the end of the line or 'protected' to the left of the member name.
Protected members are invisible from outside the class hierarchy but visible to the current class and all its derived classes.
class color_rgba
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
method set(byval rgba as long )
method set( byval rgba as string )
/
r as byte .
g as byte .
protected b as byte
protected a as byte
=
pvt as long ' hidden virtual table pointer
protected rgba as long
end class
http://community.thinbasic.com/index.php?topic=2517
uses "Oxygen"
'
'TESTING PROTECTED MEMBERS
'
dim src as string
src="
class color_rgba
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
method set(byval rgba as long )
method set( byval rgba as string )
/
r as byte .
g as byte .
protected b as byte
protected a as byte
=
pvt as long ' hidden virtual table pointer
protected rgba as long
end class
methods of color_rgba
method set (byval r as byte, byval g as byte, byval b as byte, byval a as byte)
with this.
r = r
g = g
b = b
a = a
end with
end method
method set (byval rgba as string)
this.rgba = val rgba
end method
method set (byval rgba as long)
this.rgba = rgba
end method
method get() as long
method=this.rgba
end method
end methods
#view
class dummy_object
method init()
method set(s as string, byval v as long)
method set(s as string, byval r as byte, byval g as byte, byval b as byte, byval a as byte)
method get() as string
c as color_rgba .
/
protected n as string
end class
#endv
methods of dummy_object
method init()
this.c.r=1 'allowed
this.c.a=1 'allowed
this.n=>`Arthur`
this.c.set 1,2,3,4
end method
method set(s as string, byval v as long)
this.n=s
this.c.set v
end method
method set(s as string, byval r as byte, byval g as byte, byval b as byte, byval a as byte)
this.n=s
this.c.set r,g,b,a
end method
method get() as string
method=this.n+` `+hex this.c.get
end method
end methods
dim o as dummy_object
o.init
o.set `Fred`,0x10203040
o.set `Fred`, 5,6,7,8
print o.get
'print o.n ' not allowed
'print hex o.c.r ' not allowed
'print hex o.c.g ' not allowed
'print hex o.c.b ' not allowed
'print hex o.c.a ' not allowed
'print hex o.c.rba ' not allowed
terminate
"
o2_basic src
if len(o2_error) then
msgbox 0,o2_error
stop
end if
'msgbox 0,o2_prep "o2h "+src
o2_exec
Petr Schreiber
19-04-2009, 14:30
Good job Charles!,
I think it is best to use protected instead of private in most cases, both hide members and protected has good use in inheritance.
Petr
Charles Pegge
19-04-2009, 14:45
I agree Petr.
It's quite a simple mechanism. Private and protected members are only accessible if the variable name begins with this.. Private members, when they are inherited have their names blanked, which is rather mean really :twisted:
Charles
This has turned out to be a very cool implementation of OOP that I think is probably the easiest to read. Having private and protected now is really cool too!! Thanks Charles!
I saw this on the thread for oxygen and svn:
...helpfile source folder which is due to be worked on
I am going to stop asking questions and let you finish the help Charles along with whatever else you want to finish with Oxygen, before you start the help.
Thanks again.
Charles Pegge
19-04-2009, 22:00
No please carry on Kent, your questions inform the development process. It gives me a different perspective! And I am sure there are a number of other gaps to deal with.
On the question of duplication of effort - I'm trying to make it as easy as possible to assimilate various dialects of Basic, Opengl and Windows API code where needed. The latter are almost language neutral anyway. So I hope we will be able to rapidly port procedural code at least from a wide range of sources with minimal translation.
Sounds great Charles. In the meantime I decided that since you answered most of my OOP questions for classes, that I would start making some classes for us to use in the future. That I can do now, at least declare them, I am not sure if I will be able to flesh out all of the methods at the moment, but once the help is out there, I will give it a try and then I will post away asking for help :)
Lionheart008
21-04-2009, 21:11
hi charles, petr, kent... hi all :)
can you or somebody else check please my vertex array script ??? doesn't run anymore... wish to understand all this new stuff... uff... :?
wanted to add new vertex (vx) and don't grasp it... I like oxygen, very fast, only with few script lines you can build great things ! ;) - but it's also hard stuff as a stone...!
=>You have built #p1 and #p2 in correctly way for new vertices... and so I have to do it in the second part for new ones at #p3 and #p4 ??? - I am thinking this was my mistake... isn't it... :violent:
??? function rnd as single... line for example... I like to learn more... not so easy... see the next script box:
function rnd() as single
static as long s=0x12345678 ' FIXED SEED
static as single f, d=1/0x7fffffff
mov eax,s
rol eax,7
imul eax,eax,13
mov s,eax
push eax
fild dword [esp]
add esp,4
fmul dword d
fstp dword f
function=f
end function
three of four part I have checked well ... but the other section is too crude for me :)
best regards, Lionheart
edit: have delete the vertex script... build or waiting for a new one... ;)
Charles Pegge
22-04-2009, 10:03
Hi Lionheart,
I had a good look at your script (based on PSVA2?) but I was'nt sure what your intentions were. I can provide more examples of vertex array objects and try to make the code easier to understand and modify. Would that help?
Charles
Lionheart008
22-04-2009, 14:07
;) that would helps... and perhaps one, two simple oxygen/tbgl examples... thanks in advance...
... cause it's sometime too much for me to mix usual thinbasic code and oxygen :D and I will not confuse myself too much... had some trouble with my car... ;( and daily life is hard and complicated enough at this moment for me ...
yes, tried to modified "psva2" ;)
ciao, lionheart
ps: I need a oxygen, tbgl script to fix my light machine engine at my audi :)
Charles Pegge
22-04-2009, 15:29
Hi Lionheart,
I find the best way to handle an unfamiliar system is to make make very small changes to the code then test no matter how trivial the modification. Then you will get some idea of cause and effect.
But I don't know whether this works with an Audi. (Modern cars are not spanner-friendly :) )
Anyway I'm working on a small change to the syntax which I hope will make building polygons and other complex things much simpler. So I'll produce some vertex array polygons for you, as soon as I have this working.
Charles
Lionheart008
22-04-2009, 17:40
hi charles :)
thank you... also for a little cup of humour ;)
I find the best way to handle an unfamiliar system is to make make very small changes to the code then test no matter how trivial the modification. Then you will get some idea of cause and effect.
oh yes! that's the way I am working here with thinbasic examples since half a year ;) good !
I have built a little mixed example and perhaps you will find something strange in it... ???
by the way... the src (source?) message in the script shows the machine code... isn't it? I ask for it because it's new for me to see such messages... I have no fear of blaming myself, so I ask one more before I will die :D
the other oxygen scripts examples I like it and see the power of oxygen :)
personal question: but a few wondering why you have written oxygen with freebasic... thinair was written in powerbasic... tse-tse-tse, today you would create oxygen with thinbasic ??? ;)
ciao, Lionheart
PS: I add my new input example as script
Charles Pegge
23-04-2009, 05:24
Hi Lionheart,
Thanks for your script -I'll look at it ASAP.
o2_prep("o2h "+src) returns a listing of Oxygen assembly code after the first stage of compiling.
o2_view("o2h "+src) lists the translation of assembly code into low level O2 script which is mostly machine code and labels.
The final stage is to link the o2 script and turn it into binary ready for execution.
For small programs these can be used to display listings in a msgbox, but for anything substantial they can be stored in a text file.
You can also display small windows of translated code using #view ... #endv in the source code.. This excludes code above and below these markers from the listings but does not affect compiling. ( I use this a lot for checking code )
The reason for using FreeBasic for developing Oxygen is to produce it for Linux as well as MS. I have an early version of the assembler that runs in Linux but more work is needed - and completely different OS calls for I/O and memory allocation.
Charles
Charles Pegge
23-04-2009, 11:25
Hi LionHeart,
I've added a TetraHedron to the Vertex array demo. - one way of building polygons with Oxygen.
The multi assign: => has been enhanced to allow whole points and other UDTs to be assigned to any part of an array of the same type. This makes the syntax cleaner and the code faster since you don't have to transfer each x,y and z individually.
Charles
Oxygen Update
http://community.thinbasic.com/index.php?topic=2517
'
' VERTEX ARRAYS
'
' TETRAHEDRON +
'
' Petr Schreiber / Charles Pegge , started on 03-27-2009
'
Uses "TBGL", "OXYGEN"
#include "thinbasic_gl.inc"
type VertexArrayObject
'...
pvft as long
n as long 'VERTICES
v as string 'VERTEX ARRAY
w as string 'NORMAL ARRAY
c as string 'COLOR ARRAY
t as string 'TEXCOR ARRAY
'
end type
FUNCTION TBMAIN()
LOCAL hWnd AS DWORD
LOCAL FrameRate AS DOUBLE
LOCAL va as VertexArrayObject
'------------------------
'OXYGEN COMPILED SECTION
'=======================
LOCAL src as string
LOCAL p0,p1,p2,p3,p4,p5,p6,p7,p8,p9 as long
src="
'
'VERTEX ARRAY OBJECT (sync with thinBasic counterpart)
'
type VertexArrayObject
'...
/
n as long 'VERTICES
v as bstring 'VERTEX ARRAY
w as bstring 'NORMAL ARRAY
c as bstring 'COLOR ARRAY
t as bstring 'TEXCOR ARRAY
'
end type
type Point3D
x as single
y as single
z as single
end type
type RGBColor
r as single
g as single
b as single
end type
'
'RANDOMISER
'----------------
'
function rnd() as single
static as long s=0x12345678 ' FIXED SEED
static as single f, d=1/0x7fffffff
mov eax,s
rol eax,7
imul eax,eax,13
mov s,eax
push eax
fild dword [esp]
add esp,4
fmul dword d
fstp dword f
function=f
end function
'COLOR RANDOMISER
'----------------
'
function hrnd() as single
function=abs(rnd)
end function
'COORDINATE RANDOMISER
'---------------------
'
function grnd() as single
function=8*rnd
end function
'
'VERTEX GENERATOR
'----------------
'
function add_vertex(va as VertexArrayObject) at #p1
'
dim e
va.n+=1
'
'POSITION
'
dim as Point3D p at e
e=?va.v ' EQUIVALENT TO: e=as long va.v
p(va.n)=>grnd(),grnd(),grnd()
'
'COLOR
'
dim as RGBColor c at e
e=?va.c
c(va.n)=>hrnd(),hrnd(),hrnd()
'
end function
'
'BUILD VERTEX ARRAY OBJECT A
'---------------------------
'
function build_vertices_A(va as VertexArrayObject, byval n as long) at #p2
'
dim m
m=n*sizeof Point3D
frees va.v : ?va.v=news m 'BSTR
frees va.c : ?va.c=news m 'BSTR
va.n=0
'
dim i
for i=1 to n
add_vertex va
next
'
end function
function add_tetrahedron(va as VertexArrayObject)
'
dim e
va.n+=1 'FIRST VERTEX
'
dim as Point3D tetv(12)
dim as RGBcolor tetc(12)
'
'DEFINE 4 POINTS
'---------------
'
tetv=>
0 , 7 , 0 , '1 TOP
0 , 0 , -7 , '2 FAR SIDE
-7 , 0 , 5 , '3 LEFT
7 , 0 , 5 '4 RIGHT
'
'DEFINE COLORS FOR EACH VERTEX
'-----------------------------
tetc=> 1,1,0, 0,1,1, 1,0,1, 0,0,1
'
'DEFINE FACES
'------------
'
dim as Point3D p at e
e=?va.v 'LOCATION OF POINT ARRAY
'
p(va.n)=>
tetv(1),tetv(2),tetv(3), 'REAR LEFT
tetv(1),tetv(3),tetv(4), 'FRONT
tetv(1),tetv(4),tetv(2), 'REAR RIGHT
tetv(4),tetv(3),tetv(2) 'BASE
'
'DEFINE FACE COLORS
'------------------
'
dim as RGBColor c at e
e=?va.c 'LOCATION OF COLOR ARRAY
'
'VERTEX COLORS FOR EACH FACE
'
c(va.n)=>
tetc(1),tetc(2),tetc(3), 'REAR LEFT
tetc(1),tetc(3),tetc(4), 'FRONT
tetc(1),tetc(4),tetc(2), 'REAR RIGHT
tetc(4),tetc(3),tetc(2) 'BASE
va.n+=11 'UPDATE VERTEX POINTER
end function
'
'BUILD VERTEX ARRAY OBJECT B
'---------------------------
'
function build_vertices_B(va as VertexArrayObject, byval n as long) at #p3
'
dim mv=n*sizeof Point3D*12
dim mc=n*sizeof RGBColor*12
frees va.v : va.v=news mv
frees va.c : va.c=news mc
va.n=0
'
dim i
for i=1 to n
add_tetrahedron va
next
'
end function
sub finish() at #p0 :
terminate
end sub
"
'COMPILE & INITIALISE
'--------------------
'msgbox 0,o2_prep "o2h"+src
o2_basic src : if len(o2_error) then msgbox 0,o2_error : stop
o2_exec
declare sub OXYGEN_finish() at p0
declare function add_vertex(va as vertexArrayObject) at p1
declare function build_vertices_A(va as VertexArrayObject, byval n as long) at p2
declare function build_vertices_B(va as VertexArrayObject, byval n as long) at p3
'------------
'TBGL SECTION
'============
dim angle as single
dim ke,sel as long
' -- Create and show window
hWnd = TBGL_CreateWindowEx("Vertex Array Demo", 640, 480, 32, %TBGL_WS_WINDOWED or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
TBGL_BackColor( 30, 30, 100 )
'build_vertices_A va,400
build_vertices_B va,1
' -- Main loop
While TBGL_IsWindow(hWnd)
'
FrameRate = TBGL_GetFrameRate
'
'tbgl_setWindowTitle(hWnd, "Triangles:"+STR$(va.n\3)+", FPS:"+FORMAT$(FrameRate, "#.00"))
tbgl_setWindowTitle(hWnd, "Vertex Array Demo LHVA2: Press 1, 2, Esc")
TBGL_ClearFrame
TBGL_Camera 15, 15, 15, 0, 0, 0
tbgl_rotate angle, 1.0, 0.0, 0.0 ' Rotation Setup
tbgl_rotate angle, 0.0, 1.0, 0.0 ' Rotation Setup
angle += .5
mTriangleBuffer_Render va
TBGL_DrawFrame
' -- KeyBoard Action
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
If TBGL_GetWindowKeyState(hWnd, %VK_1) Then build_vertices_A va,400
If TBGL_GetWindowKeyState(hWnd, %VK_2) Then build_vertices_B va,1
Wend
' -- Release subsystems
TBGL_DestroyWindow : OXYGEN_finish
END FUNCTION
'--------------
'TBGL FUNCTIONS
'==============
' -- Rendering
sub mTriangleBuffer_Render(byref va as VertexArrayObject)
' -- Lets enable vertex array use
glEnableClientState(%GL_VERTEX_ARRAY) ' -- Vertices
glEnableClientState(%GL_COLOR_ARRAY) ' -- Colors
' -- We give GPU pointer for coords, no need to call TBGL_Color, TBGL_Vertex like ... mad
glVertexPointer(3, %GL_FLOAT, 0, strptr(va.v) ) ' -- 3 values of SINGLE create one vertex, we start with 0 offset for the array
glColorPointer(3, %GL_FLOAT, 0, strptr(va.c) ) ' -- 3 values of SINGLE create one color, we start with 0 offset for the array
glDrawArrays(%GL_TRIANGLES, 0, va.n) ' -- Just triangles, they are fastest, everybody loves them :)
' -- Disable arrays
glDisableClientState(%GL_COLOR_ARRAY)
glDisableClientState(%GL_VERTEX_ARRAY)
end sub
Lionheart008
23-04-2009, 13:29
8) many thanks charles, I will check it closer this evening... great :)
and thank you more for content infos about oxygen, freebasic, linux and updates ;)
Another little question... I am doing some experiments with these lines...
- how can I type some info text to my script???
dim c as color_rgba
c.set(1,2,3,4 + 5) : print hex c.get ' ----- `first result: `
c.set(0x040302010) : print hex c.get ' ----- `second result: `
c.set(c.get+1) : print hex c.get ' ----- `third result: `
c.set(c.get+101) : print hex c.get
c.set(c.get+20) : print hex c.get
c.set(c.get+6) : print hex c.get
c.set(5,6,7,8) : print hex c.get
c.set(0123456) : print hex c.get
c.set(0x10203060) : print CHR$(68) : print hex c.get
print CHR$(134)
print CHR$(251)
print CHR$(90)
print CHR$(41)
print CHR$(88)
terminate
"c.set(0123456) : print hex c.get" ' I would like to make a simple text info when all messages are printed, shown one after another... only a little question and problem, but the pyramids of gizeh wasn't built at one day, isn't it ???
ciao and good ideas, good luck, Lionheart
ps: Hey, I have used the first time "syntax highlight" :D - looks pretty nice!!!
Charles Pegge
23-04-2009, 15:11
Hi Lionheart,
Here are 2 techniques for accumulating messages. The first is ok for a small number of messages - but this becomes exponentially inefficient because the whole string is recreated with each message.
The second technique shows the solution for accumulating large amounts a data (I do this extensively in the compiler) is to use a buffer which automatically extends when it becomes full.
Then you can print or store the messages in one string.
Charles
'
Uses "OXYGEN"
LOCAL src as string
LOCAL p0,p1,p2,p3,p4,p5,p6,p7,p8,p9 as long
src="
global seed=&h12345678
function rnd() as single
static as single f, d=1/0x7fffffff
mov eax,seed
rol eax,7
imul eax,eax,13
mov seed,eax
push eax
fild dword [esp]
add esp,4
fmul dword d
fstp dword f
function=f
end function
dim as string s,cr,tab
tab=chr 9
cr=chr(13)+chr(10)
'-------------------------
'technique A for few data
'========================
dim i
for i=1 to 8
s=s+str(rnd)+cr
next
print s+cr+`ok`
'-------------------------
'technique B for many data
'=========================
global as string buf, as long ib=1
sub addbuf(byval s as string)
dim i=len s
dim j=len buf
if j<i+ib then buf+=nuls(1000+i) 'extend buffer
mid buf,ib,s : ib+=i
end sub
for i=1 to 32
addbuf str(rnd)+cr
next
addbuf `ok` cr
print left buf,ib-1
terminate
"
'COMPILE
'-------
o2_basic src : if len(o2_error) then msgbox 0,o2_error : stop
o2_exec
PS I see a bug
s=`` : s+=`oops!`
but the example avoids this.
Lionheart008
23-04-2009, 16:12
thank you for accumulating messages example ! :D
here my example...
'-------- oxygen script by lionheart for learning :)
Uses "Oxygen", "UI", "Console"
printl
printl "------- experimental testscript for oxygen -----------"
dim src as string
src="
class color_rgba
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
method set(byval rgba as long )
/
r as byte
g as byte
b as byte
a as byte
=
pvt as long ' hidden virtual table pointer
rgba as long
end class
methods of color_rgba
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
with this.
r = r
g = g
b = b
a = a
end with
end method
method set(byval rgba as long )
this.rgba = rgba
end method
method get() as long
method=this.rgba
end method
end methods
dim c as color_rgba
dim s as string
print s+`Yes, wash your head only with oxygen and thinbasic!` : c.set(1,2,3,4 + 5) : print hex c.get
print s+`ok with example 1`
c.set(0x040302010) : print hex c.get
print s+`ok with example 2`
c.set(c.get+1) : print hex c.get
print s+`ok with example 3`
c.set(c.get+3) : print hex c.get
print s+`ok with example 4`
c.set(5,6,7,8) : print hex c.get
print s+`ok with example 5`
c.set(0123456) : print hex c.get
print s+`ok with example 6`
c.set(0x10203060) : print CHR$(68) : print hex c.get
print s+`was not really ok with this 7. line `
print CHR$(134)
print s+`ok ??? with this CHR$ number??? example line 8`
print CHR$(251)
print CHR$(90)
print CHR$(41)
print CHR$(88)
terminate
"
o2_basic src
if len(o2_error) then
msgbox 0,o2_error
stop
end if
o2_exec
printl
printl inputbox$ "-- type in something senseless text, press return to see your text on console --"
printl
sleep 100
printl "---- end of script, push any key to exit --------"
waitkey
makes a lot of fun... , when I can see some bright and green light at the horizont ;)
ciao, servus, Lionheart
Charles Pegge
23-04-2009, 18:03
And here is your code using the type A print buffer :)
Charles
'-------- oxygen script by lionheart for learning :)
Uses "Oxygen", "UI", "Console"
printl
printl "------- experimental testscript for oxygen -----------"
dim src as string
src="
class color_rgba
method get() as long
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
method set(byval rgba as long )
/
r as byte
g as byte
b as byte
a as byte
=
pvt as long ' hidden virtual table pointer
rgba as long
end class
methods of color_rgba
method set(byval r as byte, byval g as byte, byval b as byte, byval a as byte )
with this.
r = r
g = g
b = b
a = a
end with
end method
method set(byval rgba as long )
this.rgba = rgba
end method
method get() as long
method=this.rgba
end method
end methods
dim c as color_rgba
dim s as string
sub pri(t as string)
s=s+t+chr(13)+chr(10)
end sub
pri `Yes, wash your head only with oxygen and thinbasic!` : c.set(1,2,3,4 + 5) : pri hex c.get
pri `ok with example 1`
c.set(0x040302010) : pri hex c.get
pri `ok with example 2`
c.set(c.get+1) : pri hex c.get
pri `ok with example 3`
c.set(c.get+3) : pri hex c.get
pri s+`ok with example 4`
c.set(5,6,7,8) : pri hex c.get
pri `ok with example 5`
c.set(0123456) : pri hex c.get
pri `ok with example 6`
c.set(0x10203060) : pri CHR$(68) : pri hex c.get
pri `was not really ok with this 7. line `
pri CHR$(134)
pri `ok ??? with this CHR$ number??? example line 8`
pri CHR$(251)
pri CHR$(90)
pri CHR$(41)
pri CHR$(88)
print s
terminate
"
o2_basic src
if len(o2_error) then
msgbox 0,o2_error
stop
end if
o2_exec
printl
printl inputbox$ "-- type in something senseless text, press return to see your text on console --"
printl
sleep 100
printl "---- end of script, push any key to exit --------"
waitkey
`Yes, wash your head only with oxygen and thinbasic!`
Thanks for the examples guys and that line made me laugh and put me in a good mood, thanks!
Lionheart008
23-04-2009, 18:50
shorty:)
thanks charles... "pri" is damned good! :)
@kent: in the early morning there was a shampoo tube in my bathroom, I had to wash my hair... and I have thought to make this joke :D with oxygen...
thanks... the mostly time with very engaged programming guys here at the board is for me often too serious... , so I had to push it with some humour... talking and programming with / about script language can be much more funny... ;) even with some text coding :D
ciao, Lionheart
Lionheart008
25-04-2009, 19:20
hi charles, hi dear oxygenists :)
it's possible to code with oxygen like msgbox "UI" style can do it to output the rgb value?? Not as hex, but as a result by user clicking the wished color... some like 'print' for red = 255,0,0 after clicking the colorpicker gadget... or "you have choosed the RED Color with 255,0,0 values" ?
here my example so you can understand my idea:
'------ type example by lionheart with oxygen :)
'USER DEFINED TYPES
uses "oxygen","file","UI"
dim src as string
dim lColor as long
src = "
type color32
r as byte
g as byte
b as byte
y as byte
a as byte
lbl as string
abc as string
end type
dim c as color32
c.r=16 : print `for red: 255,0,0` '---my idea ;)
c.b=16 : print `for blue: 0,0,255`
c.g=16 : print `for green: 0,255,0`
c.y=16 : print `for yellow: 255,255,0`
c.a=32
c.lbl=`Dark: `
c.abc=`Asterix: `
print c.lbl hex c.a
print c.abc hex c.y
terminate
"
o2_basic src
'msgbox 0, o2_view "o2h "+src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
lColor = Dialog_ChooseColor(0, rgb(0, 0, 255), %CC_RGBINIT OR %CC_FULLOPEN )
if lColor = -1 then
msgbox 0, "Color Dialog was cancelled by thinbasic user"
else
msgbox 0, "Your color is: " & hex$(lColor, 6)
end if
o2_exec
best regards, Lionheart
thanks in advance ;)
Charles Pegge
26-04-2009, 12:20
Hi Lionheart,
This leads us into the task of combining Windows controls, TBGL and Oxygen. Then we will be able to pass color values to and from the color picker and all the other parts of a program.
To find out the best way to do this I need to put myself through a crash course in thinBasic UI controls and callbacks, which will take a few days - but it will be well worth it - we can start to do something useful with Oxygen :)
Charles
Charles Pegge
27-04-2009, 05:22
Hi LionHeart,
I thought I'd better share this example with you before it gets too elaborate :)
It supports color choosing for forground, background using the color picker and also by Oxygen script which you can edit and execute while the demo is running. (If you make a mistake it will politely ignore you.)
I am sure you will recognise the excellent callbacks example it is based upon. - and a scarlet spider is still the scariest.
Charles
Thanks for the example Charles. I am too sleepy to figure out what is going on at the moment, hope I can see and understand better after some sleep. Thanks.
Lionheart008
28-04-2009, 17:22
hi charles, hi kent, all...
short: great thank U for the ui/tbgl/oxygen script!!! :D I test it and looks superb! wow!!!... I will check it closer the next time... I was some days on the road... examining graphic courses and more... sorry, I will feedback your script as soon as I can :)
ciao, Lionheart
ps: can you check this script for oxygen compatibility ??? script it's running, OK and sorry, have had some problems with my win xp notebook at the moment ... :telephone:, the script below works fine :)... uargh...
'--- testscript
uses "oxygen"
dim vv as long = 8
dim eax, ebx, ecx, edx as long
dim src as string
ecx = vv
edx = 0
do
eax = 8
do
edx += 1
eax -= 1
loop until eax <= 0
ecx -= 1
loop until ecx <= 0
eax = edx
msgbox 0, "This result is fine: "+STR$(eax)
msgbox 0, Hex$(edx)
thanks in advance :)
Lionheart008
28-04-2009, 22:18
so... as I have looked very close to the ui/tbgl/oxygen script I can only repeat myself... GREAT ! :D charles... have checked it and was astonished about the color input control ;) and you can change the values by the oxygen color text box :occasion:
my little variation I add here... compliments ! :) I like oxygen more and more, but I am far from your status quo!... must laugh...
only the third render picture with pyramid (and my little box) you cannot change the colour as they are fixed, isn't it ???
(I am not sure...)
Ciao, best regards, Lionheart
Charles Pegge
29-04-2009, 03:43
Thanks LionHeart,
Yes the pyramid determines is own colors, but you could try mixing:
sub drawPyramid()
tbgl_beginpoly %GL_TRIANGLE_FAN
tbgl_color 40, fg, fb : tbgl_vertex 0.0, 1.5, 0.0
tbgl_color fr, 40, 40 : tbgl_vertex -1.5, -1.5, 1.5
tbgl_color fr, fg, fb : tbgl_vertex 1.5, -1.5, 1.5
tbgl_color 40, 40, fb : tbgl_vertex 1.5, -1.5, -1.5
tbgl_color 40, fg, 40 : tbgl_vertex -1.5, -1.5, -1.5
tbgl_color fr, 40, 40 : tbgl_vertex -1.5, -1.5, 1.5
tbgl_endpoly
tbgl_color fr,fg,fb ' restore controled foreground color
end sub
Charles Pegge
29-04-2009, 04:21
Here's a simple piece of O2 assembler in the BASIC environment:
passes results from and to thinBasic variables directly.
#view .. #endv restricts the code window when you do an o2_view or o2_prep listing.
Charles
' O2 ASM EXAMPLE
uses "oxygen"
dim vv,ww as long
dim src as string
src="
'
'EAX,ECX,EDX,EDI are safe to use with o2_basic but the others must be preserved.
'
#view
mov edx,[#vv]
mov eax,0
(
inc eax
dec edx
jg repeat
)
shl eax,3
mov [#vv],edx
mov [#ww],eax
#endv
terminate
"
o2_basic src
if len(o2_error) then msgbox 0,o2_error : stop
msgbox 0,o2_view "o2h "+src
vv=8
o2_exec
msgbox 0, "This result is fine: "+$cr+"EAX: "+ww+$cr+"EDX: "+vv
Lionheart008
29-04-2009, 13:06
thank you charles :) this second example helps to understand more and more... ;)
and I add the new colour input (first example) for the pyramid, it works very fine! :)
one more favour...
how can I calculate fahrenheit to celsius with oxygen ??? example I add here...
'
'CALCULATOR
'
uses "oxygen"
dim q,v as string
dim fahrenheit,celsius as double
do
q=inputbox$ "Enter An Expression: ","CALCULATOR",q
if q="" then exit do
o2_basic " print str "+q+" : terminate"
if len(o2_error) then msgbox 0,o2_error
o2_exec
loop
do
v=inputbox$ "calculate fahrenheit to celsius: ","CALCULATOR",v
if v="" then exit do
' fahrenheit = ((celsius * 9) / 5) + 32
o2_basic " print str "+v+" : terminate"
if len(o2_error) then msgbox 0,o2_error
o2_exec
loop
best regards, Lionheart
Charles Pegge
29-04-2009, 15:52
Hi Lionheart,
I'd do it like this:
'TEMPERATURE CONVERSION
'
uses "oxygen"
dim q,v as string
dim fahrenheit,celsius as double
do
v=inputbox$ "calculate fahrenheit to celsius: ","CALCULATOR",v
if v="" then exit do
' fahrenheit = ((celsius * 9) / 5) + 32
o2_basic " print str (("+v+"-32)*5/9) : terminate" 'OKAY
'o2_basic " print str ("+v+"-32)*5/9 : terminate" 'WRONG RESULt
'o2_basic " print str 5/9*("+v+"-32) : terminate" 'OKAY
if len(o2_error) then msgbox 0,o2_error
o2_exec
loop
Hi Charles Pegge,
what about labels ?
How can i use they ?
Brackets stand for a bloc beginn and end ?
Can i use the WINDOW API and DDRAW/DSOUND ?
What must be done therefor ?
It is possible to write a complete game with oxygen !
Here is a game that was written with FASM from me.
http://www.zshare.net/download/59359230d60d0f0c/
Can i do this likewise with oxygen !
It would be a provocation, to write games with oxygen and thinBasic.
It could give a interesting strong fusion.
Thank you for reading this post.
Peter
Lionheart008
29-04-2009, 19:30
hi charles :)
short question... again...
- why it's the second result of your asm (assembler) example zero ??? belongs to #view and #endv modus? I think so... ;)
- my input... but same result...
' O2 ASM EXAMPLE BY LIONHEART ;)
uses "oxygen"
dim vv,ww,xx as long
dim src as string
dim eax, ebx, ecx, edx as long
src="
'
'EAX,ECX,EDX,EDI are safe to use with o2_basic but the others must be preserved.
'
#view
mov edx,[#vv]
mov eax,0
(
inc eax
dec edx
jg repeat
)
shl eax,3
mov [#vv],edx
mov [#ww],eax
mov [#xx],ecx
#endv
terminate
"
o2_basic src
if len(o2_error) then msgbox 0,o2_error : stop
msgbox 0,o2_view "o2h "+src
vv=16
xx=24
o2_exec
msgbox 0, "This result is fine: "+$cr+"EAX: "+ww+$cr+"EDX: "+vv
ciao, nice evening, lionheart
ps: => attention! JOKE! :) we need also a "H20" (for 'water') module for thinbasic ? :lol:
Charles Pegge
29-04-2009, 20:35
Hi Peter,
Some answers:
what about labels ?
.xyz
or
xyz:
How can i use they ?
call xyz
jmp xyz
Brackets stand for a bloc beginn and end ?
Yes, the blocks can be used for loops and conditionals - can be nested too. Blocks work in conjuction with Exit and Repeat.
mov ecx, 10
(
dec ecx : jnz repeat
)
Can i use the WINDOW API and DDRAW/DSOUND ?
Yes, this can be done with regular Basic declarations or the primitive way to bind to DLL functions is like this:
(LoadLibrary FreeLibrary and GetProcAddress are built-in.)
var 4 kernel32
kernel32=LoadLibrary `kernel32.dll`
bind kernel32
(
GetCommandLine GetCommandLineA
GetModuleHandle GetModuleHandleA
ExitProcess ExitProcess
QueryPerformanceCounter QueryPerformanceCounter
)
What must be done therefor ?
It is possible to write a complete game with oxygen !
Yes. I think it will be easiest to take advantage of the range of thinBasic modules, write critical sections using Oxygen Basic the do final optimisations in Assembler - the Basic and Assembler share the same namespace and are easy to mix.
Here is a game that was written with FASM from me.
http://www.zshare.net/download/59359230d60d0f0c/
Many thanks - looks great! I'll see what the boys make of it.
Can i do this likewise with oxygen !
That is an aspiration! You will see a number of examples included with thinbasic_Oxygen.zip - some 3D. Both Basic and Assembler. I hope we can build a substantial library of useful code.
Your expertise will be very welcome.
http://community.thinbasic.com/index.php?topic=2517
Charles Pegge
29-04-2009, 20:54
Hi Lionheart,
Someone has already got a compiler called H2O so I thought O2H was preferable and a more logical extension to O2, though as a chemical substance it might prove to be extremely volatile :).
EDX is zero because it was used as the down counter (and EAX was an up counter)
You can use #view .. #endv to give a partial listing when used in conjunction with either of these:
msgbox 0,o2_prep "o2h "+src
or lower level oxygen opcode script:
msgbox 0,o2_view "o2h "+src
Charles
Hi Charles,
thank you for your reply.
I'm writing a 'C' project right now, but besides i will try to write a small game
with oxygen and thinBasic. I hope that i will learn your syntax in this experiment fast. Time is rare and is going to quickly over.
Assembler programming is not really difficult. I grew up therewith.
Peter
Lionheart008
30-04-2009, 00:15
1) :) so far I am learning also step by step and making a lot of fun... I have mixed some functions, add new things (included new #view - # endv) and I see that I like it... save the file as "k.txt" with machine code... nice to see it :D
2) hi peter, I am curious to see the game including oxygen/thinbasic features , good luck!
ciao, good night, Lionheart
' MIXED O2 ASM EXAMPLE BY LIONHEART
uses "oxygen", "file"
dim vv,ww,xx,ff as long
dim src as string
dim eax, ebx, ecx, edx as long
src="
'
'EAX,ECX,EDX,EDI are safe to use with o2_basic but the others must be preserved.
'
#view
mov edx,[#vv]
mov eax,0
(
inc eax 'integer
dec edx
jg repeat
)
shl eax,4
mov [#vv],edx
mov [#ww],eax
mov [#xx],ecx
fld dword [#ff] 'float
fld1
faddp st(1)
fst dword [#ff]
#endv
def ff print `Runtime first compiled, result is ` +str g +
dim a
dim g=41
dim s as string
s=`#dependent #o2h : ff`
a=compile s : call a
if len(error) then print `runtime error: ` error
frees a
terminate
"
o2_basic src
if len(o2_error) then msgbox 0,o2_error : stop
msgbox 0,o2_view "o2h "+src
vv=16
xx=48
o2_exec
msgbox 0, "This result is quite fine: "+$cr+"EAX: "+ww+$cr+"EDX: "+vv
msgbox 0,o2_prep "o2h "+src
src = "
o2h
dim i,j=1 as long
dim s,t as string
s=space 500
for i=1 to 24
t=str(i)+chr(13)+chr(10)
mid (s,j)=t
j+=len t
next
dec j
print left s,j
print `Hello, everything is ok with oxygen! ` + t
terminate
"
file_save ("k.txt", o2_prep src)
o2_basic src
o2_exec
Lionheart008
30-04-2009, 10:17
hi charles, hi all :)
good morning... must go back at work now, but here a new question... about error message behaviour with oxygen:
'--- error message script about oxygen behaviour
uses "OXYGEN"
dim src as string
src="
basic
(
function arith(byval a as long, byval b as long, byval c as long, byval d as long) as long
function=a+b*c+d
'set.a : print `1`
'set.b : print `2`
'set.c : print `3`
'set.d : print `4`
end function
)
"
o2_asmo src
if len(o2_error) then msgbox 0,"Problem: "+o2_error()+o2_view (src) : stop
Declare Function arith(byval a as long, byval b as long, byval c as long, byval d as long) at o2_buf 0
msgbox 0,arith(1,2,3,4)
- by the way: it's possible to 'set' a special value (number, word) and print it???
ciao and thank you for diagnostic scripts... :) I will check it later... bye, Lionheart
have all a nice day here...
Charles Pegge
30-04-2009, 11:57
Hi Lionheart,
Here is a fixed version of your script - I've put in a few comments to clarify.
To answer your question about special values, low-level macros are very useful. (Constants are not operational yet :( )
Here are a few ways to define them:
'
%h `hello` cr
$h `hello` cr
def h `hello` cr
def cr `
`
print h
uses "OXYGEN"
dim p0,p1 as long
dim src as string
src="
'basic
#o2h 'ACTIVATES BASIC SYNTAX (NOT NEEDED WHEN COMPILING WITH o2_basic ..)
function arith(byval a as long, byval b as long, byval c as long, byval d as long) as long at #p1
function=a+b*c+d
'THESE ARE ALL LOW LEVEL MACROS
'
%h `hello` cr
$h `hello` cr
def h `hello` cr
def cr `
`
print h h 'SAME AS print h+h
end function
sub finish() at #p0
terminate
end sub
"
o2_asmo src ' ASSEMBLE (OR COMPILE AS BASIC IF #O2H FLAG IS PRESENT)
if len(o2_error) then msgbox 0,"Problem: "+o2_error()+o2_view (src) : stop
o2_exec
Declare Function arith(byval a as long, byval b as long, byval c as long, byval d as long) at p1
Declare Sub Finish() at p0
msgbox 0,arith(1,2,3,4)
finish
I haven't had the time this week I thought I would to study, but have been amazed by the amount of posts and information that came out this week. Just wanted to say thanks to you guys, it gives me a lot to study when the time comes. The progress of things being done with o2 and thinBasic combo looks great!
uses "OXYGEN"
dim p0,p1 as long
dim src as string
src="
'basic
#o2h 'ACTIVATES BASIC SYNTAX (NOT NEEDED WHEN COMPILING WITH o2_basic ..)
function arith(byval a as long, byval b as long, byval c as long, byval d as long) as long at #p1
function=a+b*c+d
'THESE ARE ALL LOW LEVEL MACROS
'
%h `hello` cr
$h `hello` cr
def h `hello` cr
def cr `
`
print h h 'SAME AS print h+h
end function
sub finish() at #p0
terminate
end sub
"
o2_asmo src ' ASSEMBLE (OR COMPILE AS BASIC IF #O2H FLAG IS PRESENT)
if len(o2_error) then msgbox 0,"Problem: "+o2_error()+o2_view (src) : stop
o2_exec
Declare Function arith(byval a as long, byval b as long, byval c as long, byval d as long) at p1
Declare Sub Finish() at p0
msgbox 0,arith(1,2,3,4)
I am confused, I see Terminate in the sub finish, but it is never called anywhere. Does oxygen see terminate and exit even if it is in a sub that is not called?
Charles Pegge
01-05-2009, 07:13
Yes Kent, my mistake. the terminate macro releases any libraries, strings and static memory used by the o2 code.
I've added the finish call to the code above
Charles
PS There will be another simpler way of defining classes, combining the class block and methods of blocks into one unit. The compiler will do the extra work for you. But first some final checks...
Lionheart008
01-05-2009, 10:12
theme: low level macros...
good morning charles, kent :)
1) my question to the following script... I can change the macros as I like %k 'text' cr, %p 'text' cr or something else.. for printing it I have to print k or print p in my case... that's right???
2) def h `text` cr = is just another thing.. it's printing what I want... I define it in this one line ???
3) yes: we need a sdk and pdf documents for this language... :D
I ask you here better one more than leaving me confused... ;)
'-- lionhearts low-level macro example :)
uses "OXYGEN"
dim p0,p1 as long
dim src as string
src="
'basic
#o2h 'ACTIVATES BASIC SYNTAX (NOT NEEDED WHEN COMPILING WITH o2_basic ..)
function arith(byval a as long, byval b as long, byval c as long, byval d as long) as long at #p1
function=a+b*c+d*2*4*6*3
'THESE ARE ALL LOW LEVEL MACROS
'
%h `hello` cr
$h `hello dear thinbasic users :) ` cr
%h `go for oxygen gold` cr
%g `ciao: go for new assembler oxygen examples` cr
%k `take attention: wolverine is not your friend! ` cr1
print `simple: go for thinbasic gold`
def h `easy: hello dear oxygen sunshine :) ` cr
def cr ` / `
def cr1 ` STOP `
print h h 'SAME AS print h+h
print g g
print k k k k
end function
sub finish() at #p0
terminate
end sub
"
o2_asmo src ' ASSEMBLE (OR COMPILE AS BASIC IF #O2H FLAG IS PRESENT)
if len(o2_error) then msgbox 0,"Problem: "+o2_error()+o2_view (src) : stop
o2_exec
Declare Function arith(byval a as long, byval b as long, byval c as long, byval d as long) at p1
Declare Sub Finish() at p0
msgbox 0,arith(1,2,3,4)
finish
ciao, servus, Lionheart
today it's "the first may" in germany, holiday for hard working people ;)
Thanks Charles for the clarification.
I was thinking and I have been looking for a website that had tutorials for assembly.
The thinking is this... if we could find such a site that taught assembly with nice examples... it would be neat to tie into those examples and show how MASM or FASM code could be converted to Oxygen.
So in the oxygen example, in a code comment at the top of the source code would be a url to the website with the tutorial written for MASM or FASM.
I am just assuming MASM or FASM code is similar, you could substitute which ever other Assembler is the closest to study for Oxygen.
I know you mentioned the intel site, but for a beginner it didn't have simple tutorials it seems to build on and start playing with it to learn.
It was more reference for programmers who already know Assembly.
I think seeing code you might see on the internet and then being able to convert it to what Oxygen expects it would be very beneficial for those like me trying to wrap my head around assembly.
Lionheart008
01-05-2009, 12:31
hi charles... can you check for me my last script ???
would be nice, the post before kent's one :)
ciao, Lionheart, nice day, I am off now ! time to relax with private pleasures ;)
Charles Pegge
01-05-2009, 13:20
Hi Lionheart,
Your script looks fine to me :)
There a several ways to use def:
Single line:
def greet `Hello`
def greet (`Hello`)
multiline:
def greet
`hello`
end def
def greet
(
`hello`
)
These do not insert crlf at the end
def greet (
`hello` )
def greet
(
`hello` )
Def can also use parameters in the form of %1 %2 %3 and you can even use them inside strings.
def greet print `Good %1 %2 !
A fine %1 for programming.`
greet morning Lionheart..
Good morning Lionheart !
A fine morning for programming.
Macros are good for fixed structures. The expression is fixed at compile time but cannot be changed at run time.
Charles
Charles Pegge
01-05-2009, 13:57
Hi Kent,
I have only looked at Masm very briefly but if you find a nice piece of 32bit code we can try translating it. I would prefer to avoid old 16 bit stuff with ax and cx and segment registers because this adds complexity and will disappear forever when we move to the 64bit environment.
I'm hoping Oxygen will be able to read Josés Windows header files and FreeBasic's - syntax compatibility to be resolved, which will make it easier to write windows code. Opengl code is no problem because it can understand all of Petr's thinBasic Opengl headers.
Before attempting the manual, I would like to consolidate this version of Oxygen in its minimal form, testing for completeness. I don't think we are too far away from that point.
Charles
Hi Charles,
have a look at this code.
this does not go ! I have no knowledge what it do mean with 'EXPECTING ']' here.
A few explanations would be good.
This is running with MASM,FASM,GOASM,ROASM,NASM and with C INLINE ASSEMBER.
I guess, it takes a long way to understand oxygen !
But anyway, it is very interesting.
Thank you.
Peter
'------------------------------------------------
Uses "OXYGEN","UI","FBGFX"
'Declare Function GetAsyncKeyState Lib "user32.dll" Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer
FBGFX_ScreenRes 640,480,32
Dim x,y,iEax,iEbx,iEcx,iEdx,yPos,xPos,xScr,yScr As DWORD
Dim Map(1200) As BYTE
Dim s As STRING
s = "
mov [#y],0 'For y = 0 To 29
a2: mov [#x],0 'For x = 0 To 39
a1: imul ebx,[#y],40 'iEbx = y*40 + x +1
add ebx,[#x]
inc ebx
mov [#Map+ebx],1 'Map(iEbx) =1
inc [#x] 'Next x
cmp [#x],40
jnz a1
inc [#y] 'Next y
cmp [#y],30
jnz a2
mov [#yPos],15
mov [#xPos],20
While %True
FbgFx_Cls
pushad
xor edx,edx 'iEdx = Int(xScr /32)
mov esi,32
mov eax,[#xScr]
idiv esi
mov [#iEdx],eax
xor edx,edx 'iEcx = Int(yScr /32)
mov eax,[#yScr]
idiv esi
mov [#iEcx],eax
a5: mov ecx,[#iEcx] 'For y = iEcx To iEcx + yPos
mov [#y],ecx
a4: mov edx,[#iEdx] 'For x = iEdx To iEdx + xPos
mov [#x],edx
imul ebx,[#y],20
add ebx,[#x]
inc ebx
cmp [#Map+ebx],1 'iF Map(ebx) =1 then
jnz a3
FbgFx_Circle x*32 -xScr,y*32 -yScr,10,Rgb(80,170,255)
a3: inc [#iEdx]
mov eax,[#iEdx]
add eax,[#xPos]
cmp [#iEdx],eax
jnz a4
inc [#iEcx]
mov eax,[#iEcx]
add eax,[#yPos]
cmp [#iEcx],eax
jnz a4
popad
iF GetAsyncKeyState(%vk_Left) Then xScr = xScr -4
'invoke GetAsyncKeyState,VK_LEFT
'cmp eax,0
'jz n1
'add [#xScr],4
'n1:
iF GetAsyncKeyState(%vk_Up) Then yScr = yScr -4
iF GetAsyncKeyState(%vk_Right) Then xScr = xScr +4
iF GetAsyncKeyState(%vk_Down) Then yScr = yScr +4
iF xScr < 0 Then xScr = 0
iF yScr < 0 Then yScr = 0
iF xScr > 640 Then xScr = 640
iF yScr > 480 Then yScr = 480
IF GetAsyncKeyState(%vk_escape) Then Exit While
Sleep 10 'invoke Sleep,10
Wend
terminate "
o2_asmo s
if len(o2_error) then msgbox 0,o2_error : stop
o2_exec
@Frank,sorry I wrote my post at the same time and it came in after yours. I am glad you got your answer from Charles as it helps all of us learn.
@Charles, I will keep looking and posting links as I find possible education sites.
Your idea of using the incredible repository of Jose's and freeBasics header files is a great idea!!
Here is a neat looking OS that fits on a floppy written in assembly for 32 and 64 bit assembly programmers.
http://www.menuetos.net/screens.htm
Here is a really nice video tutorial series on 32 bit assembly programming.
http://showmedo.com/videotutorials/series?name=qdrYRTz8Z
zlatkoAB
02-05-2009, 21:21
I also know for one interesting OS written in FASM
http://www.dex4u.com/
Petr Schreiber
02-05-2009, 21:51
Hi Peter,
till the time Charles answers, I have few tips for you.
mov [#Map+ebx], 1 cannot be used for some reason, but mov [ebx+#Map], 1 seems to work
You can't use ThinBasic commands in string representing Oxygen BASIC. I would recommend to split the assembler code to multiple strings, which can be executed using o2_exec commands called from ThinBasic code.
I hope it helped, I'm sure Charles will tell better :),
Petr
Hi Charles,
have a look at this code.
this does not go ! I have no knowledge what it do mean with 'EXPECTING ']' here.
A few explanations would be good.
This is running with MASM,FASM,GOASM,ROASM,NASM and with C INLINE ASSEMBER.
I guess, it takes a long way to understand oxygen !
But anyway, it is very interesting.
Thank you.
Peter
Hi Petr,
thanks for your help, but i cannot write [ebx+#Map],1.
because, ebx is an index !
Yes, i think this with the basic commands is wrong.
I will write it in pure oxygen over again.
It should become a test for me.
But this errror is really wierd and prepares headaches. "joke!"
Peter
I also know for one interesting OS written in FASM
http://www.dex4u.com/
Thanks for the link Zlatko, that sure looks interesting and a great idea too.
Charles Pegge
02-05-2009, 23:22
Hi Peter,
You can't mix thinBasic code inside Oxygen scripts so I have attempted to separate the asm into two parts separately assembled, and insert the o2_execs into the thinBasic main code.
[ebx+#offset] is okay in Oxygen but not the other way round. Perhaps I need to make it order tolerant but at present it supports [BaseReg + IndexReg * Stride + Offset].
I use pusha and popa only but can add pushad / popad if these are in common use.
I've also put some block structures around your labels
Perhaps you can see why the second part crashes - but without further study I have to follow your code mechanistically.
I hope this helps anyway or at least demonstrates how to use the Assembler in thinBasic
Charles.
'------------------------------------------------
Uses "OXYGEN","UI","FBGFX"
'Declare Function GetAsyncKeyState Lib "user32.dll" Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer
FBGFX_ScreenRes 640,480,32
Dim x,y,iEax,iEbx,iEcx,iEdx,yPos,xPos,xScr,yScr As DWORD
Dim Map(1200) As BYTE
Dim s As STRING
s = "
mov [#y],0 'For y = 0 To 29
a2:
(
mov [#x],0 'For x = 0 To 39
a1:
(
imul ebx,[#y],40 'iEbx = y*40 + x +1
add ebx,[#x]
inc ebx
mov [ebx+#Map],1 'Map(iEbx) =1
inc [#x] 'Next x
cmp [#x],40
jnz repeat 'a1
)
inc [#y] 'Next y
cmp [#y],30
jnz repeat 'a2
)
mov [#yPos],15
mov [#xPos],20
ret 'split here
"
o2_buf 1
o2_asmo s
if len(o2_error) then msgbox 0,o2_error : stop
s="
pusha
xor edx,edx 'iEdx = Int(xScr /32)
mov esi,32
mov eax,[#xScr]
idiv esi
mov [#iEdx],eax
xor edx,edx 'iEcx = Int(yScr /32)
mov eax,[#yScr]
idiv esi
mov [#iEcx],eax
a5:
mov ecx,[#iEcx] 'For y = iEcx To iEcx + yPos
mov [#y],ecx
a4:
(
mov edx,[#iEdx] 'For x = iEdx To iEdx + xPos
mov [#x],edx
imul ebx,[#y],20
add ebx,[#x]
inc ebx
(
cmp [ebx+#Map],1 'iF Map(ebx) =1 then
jnz exit
'needs to go into thinBasic
'FbgFx_Circle x*32 -xScr,y*32 -yScr,10,Rgb(80,170,255)
)
a3:
inc [#iEdx]
mov eax,[#iEdx]
add eax,[#xPos]
cmp [#iEdx],eax
jnz repeat 'a4
'
inc [#iEcx]
mov eax,[#iEcx]
add eax,[#yPos]
cmp [#iEcx],eax
jnz repeat 'a4
)
popa
ret
"
o2_buf 2
o2_asmo s
if len(o2_error) then msgbox 0,o2_error : stop
o2_buf 1 : o2_exec
o2_buf 2
FbgFx_Cls
While %True
o2_exec ' crash!
iF GetAsyncKeyState(%vk_Left) Then xScr = xScr -4
'invoke GetAsyncKeyState,VK_LEFT
'cmp eax,0
'jz n1
'add [#xScr],4
'n1:
iF GetAsyncKeyState(%vk_Up) Then yScr = yScr -4
iF GetAsyncKeyState(%vk_Right) Then xScr = xScr +4
iF GetAsyncKeyState(%vk_Down) Then yScr = yScr +4
iF xScr < 0 Then xScr = 0
iF yScr < 0 Then yScr = 0
iF xScr > 640 Then xScr = 640
iF yScr > 480 Then yScr = 480
IF GetAsyncKeyState(%vk_escape) Then Exit While
Sleep 10 'invoke Sleep,10
Wend
Hi Charles,
thank you.
pusha lays only the 16 Bit Register onto the stack !
What are doing the higher 16 Bit ?
[ebx+#Maps] is new for me !
What, when i do have a displacement ?
Might i write [ebx+1+#Map] ?
Peter
Charles Pegge
03-05-2009, 06:51
Hi Peter,
pusha lays only the 16 Bit Register onto the stack !
What are doing the higher 16 Bit ?
I've interprreted Pusha and Popa as 32 bit. The stack is always 32 bits wide in a 32 bit system, even if you dont use all the bits. In 64 bit modes, Pushes ans Pops become 64 bits wide.
[ebx+#Maps] is new for me !
Might i write [ebx+1+#Map] ?
What, when i do have a displacement ?
The #VarName instructs Oxygen to substitute the absolute address of the host (thinBasic) variable name as a displacement. At present, Oxygen will not resolve a displacement expression like: 1+#Map, But I can add this capability - for these and other constants.
Charles
Hi Charles,
oxygen is using the x86 specification ?
jumps are here ( -126 to +127) !
With effect from 80386 , we will have no limits on jumps !
I was trying to allot all routines into Functions.
But without long jumps is it not possible.
I am familiar with other Assembler's .
That's a obstacle now, which takes me the oxygen! LOL!
ps:
There are none invoke's ?
Writing in such manner is not so good.
String db 'Hello',0
push 5 'Numbers of String
push addr String 'String
push 100 'y position
push 100 'x position
push [hdc] 'device contex
call TextOut 'api application
This here is better !
invoke TextOut ,hdc,x,y,String,number
Thank you for your needed time.
Peter
Charles Pegge
03-05-2009, 22:32
Hi Peter,
Oxygen supports long jumps: jnz long ...
and STDCALL convention is assumed using the word CALL or PROC with one or more params. If the functions are built-in or bound DLL calls then they can be invoked just by name like C or Basic.
The code below shows these points and demonstrates in-line string / data.
Charles
' ASSEMBLER CALLS
uses "oxygen","file"
dim src as string
dim vv as long
'------------------------------------------------------
src="
mbox `1 hello` ' no need to `CALL` for intrinsics and bound DLL functions
'NO NEED TO PUSH EXPLICITLY (STDCALL IS UNDERSTOOD)
call mbox `2 hello`
proc mbox `3 hello`
`4 hello`
mov ecx,eax
call mbox ecx
data
(
`5a hello` 0d 0a
`5b hello` 0d 0a
00 00
)
mov ecx,eax
call mbox ecx
data
(
36 20 68 65 6c 6c 6f 00 00
)
mbox eax
call myfunction `Hello World!`
xor eax,eax
jz long done
myfunction: ' byval string pointer
mbox [esp+4]
ret 4
done:
ret
"
o2_asmo src
if len(o2_error) then
msgbox 0,o2_error+o2_view (src)
'file_save("t.txt",o2_view (src))
stop
end if
o2_exec
'------------------------------------------------------
Lionheart008
06-05-2009, 18:11
hi charles, hi all..
I am back again from stressy school time ;)
one question to this script... test loop with sin, cos, tan, log... functions...
' Test of loop optimization with Oxygen by lionheart, mai 2009
uses "Console", "Oxygen"
dim T1 as quad
dim T2 as quad
dim p0,p1,p2 as dword
dim src as string
' -- Prepare Oxygen script
src = "
function Calculate_basic(c as long) as long at #p1
local ic, jc, pc, lc as double, i as long 'lc
'
'BASIC VERSION
'
for i=1 to c
ic = sin(i)
jc = cos(i)
pc = tan(i)
lc = log(i)
next
end function
function Calculate_asm(c as long) as long at #p2
local ic, jc, pc, lc as double, i as long
'
'ASSEMBLER VERSION
'
'
dim a=&c
mov eax,a
mov edx,[eax]
fld1
fld1
(
fsincos
fstp qword jc
fstp qword ic
fstp qword pc
fstp qword lc
fld1
faddp st(1),st(0)
fld st(0),st(0)
dec edx
jg repeat
)
fcomp st(0),st(0)
'
end function
sub finish() at #p0
terminate
end sub
"
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
dim c as long=250000
declare function Calculate_o2bas(c as long) as long at p1
declare function Calculate_o2asm(c as long) as long at p2
declare sub finish () at p0
printl "-- NEW SPEED BENCHMARKS: --"
printl ""
printl "-- Double precision Sin & Cos & Tan Test: loops= " & c
printl ""
doevents(off)
hirestimer_init
T1 = hirestimer_get
Counter c
T2 = hirestimer_get
printl "Script time: microSecs:" & $tab & FORMAT$(T2 - T1, "##,")
T1 = hirestimer_get
Calculate_o2bas c
T2 = hirestimer_get
printl "Compiled time: microSecs:" & $tab & FORMAT$(T2 - T1, "##,")
T1 = hirestimer_get
Calculate_o2asm c
T2 = hirestimer_get
printl "Assembler time: microSecs:" & $tab & FORMAT$(T2 - T1, "##,")
function Counter( MaxCount as long ) as long
local ic, jc, pc, lc as double,i as long
For i = 1 To MaxCount
jc = sin(i)
ic = cos(i)
pc = tan(i)
lc = log(i)
Next
end function
printl
printl "end of fantastic oxygen script and push a key"
finish
waitkey
I have got an error message for the log command... can you check it ??? without log (basic code part, first lines...) the script runs very well... see my added script ;)
ciao and I will check all things happened the last days... best regards, Lionheart
nice evening :)
Petr Schreiber
06-05-2009, 18:19
I think he error is reported because "log" is not the name for logarithm function in O2H - you can use "log2", "log10" or "logN" instead.
As LOG returns natural logarithm in TB, you can use "LOGn(i, 2.71828182846)" in Oxygen ( that odd number is e ).
Lionheart008
06-05-2009, 19:10
:occasion:
1) thank you petr, good idea! works fine now... ;)
2) next question... what does these lines mean...
myfunction: ' byval string pointer
mbox [esp+4]
ret 4
I cannot simply rise the numbers... to [esp+5] , ret 5... , isn't it?
' ASSEMBLER CALLS
uses "oxygen","file"
dim src as string
dim vv as long
'------------------------------------------------------
src="
mbox `1 hello dear sunshine` ' no need to `CALL` for intrinsics and bound DLL functions
'NO NEED TO PUSH EXPLICITLY (STDCALL IS UNDERSTOOD)
call mbox `2 hello planet earth`
proc mbox `3 hello night shining moon`
`4 hello red planet mars`
mov ecx,eax
call mbox ecx
data
(
`5a hello my wife` 0d 0a
`5b hello thinbasic` 0d 0a
`5c hello oxygen` 0d 0a
`5d hello children` 0d 0a
00 00
01 01
)
mov ecx,eax
call mbox ecx
data
(
36 20 68 65 6c 6c 6f 00 00 01 01
)
mbox eax
call myfunction `Hello Lionhearts EffectBox World!`
call mbox ecx
xor eax,eax
jz long done
myfunction: ' byval string pointer
mbox [esp+4]
ret 4
done:
ret
"
o2_asmo src
if len(o2_error) then
msgbox 0,o2_error+o2_view (src)
'file_save("t.txt",o2_view (src))
stop
end if
o2_exec
'------------------------------------------------------
bye, lionheart
Charles Pegge
06-05-2009, 21:37
Hi Lionheart,
I've used LIN() for natural logarithms.
Oxygen Assembler performs a few tricks with internal macros:
When using quoted strings in Oxygen, it is treated as inline data where the CPU records where it is in memory then leaps over the string. After making a small adjustment it leaves the address of the string in its eax register.
When using call address, any further params are collected then pushed onto the stack in reverse order, prior to the call to make a stdcall or cdecl..
The function receiving the call will then have access to the parameters in normal order:
using the stack pointer directly:
[esp] the return address
[esp+4] param1
[esp+8] param2
[esp+12] param3 ...
With stdcall which is most commonly used in MS Windows, the function must deallocate these params, which is done by giving the total param space in bytes following the ret instruction
ret 4
ret 8
ret 12
With cdecl only the simple ret instruction is used and the call is expected to clean up the stack afterwards.
call myfunc a,b,c
add esp,12
Charles
PS: In the next release I'll add LOG() for natural logaritms - same as LIN()
Lionheart008
07-05-2009, 19:44
hi charles, thank you first of all for log() and lin() infos :)
can you help me to QUIT or CLOSE the plasma example... I am thinking there is missing a silly, but important thing... I cannot figure it out... or try it later again...
best regards, nice evening, Lionheart
'Plasma-like effect with FBGFX
uses "FBGFX"
uses "OXYGEN"
Dim w,h As long
Dim hWnd As Dword
w=500-1
h=400-1
FBGFX_ScreenRes(w,h,32,2)
Dim x,y,page As single
Dim c,t As single
dim divisor, two, fifteen As single
divisor = 100
two = 2
fifteen = 15
dim ColorCalcSrc as string="
'-----
fld dword [#x] ' Sin((x+y+t)/100)
fadd dword [#y]
fadd dword [#t]
fdiv DWORD [#divisor]
fsin
fld dword [#x] ' Cos((x-t)/100)
fsub dword [#t]
fdiv DWORD [#divisor]
fcos
faddp st(1)
fld dword [#y] ' Cos((y-t)/100)
fsub dword [#t]
fdiv DWORD [#divisor]
fcos
faddp st(1)
fld dword [#x] ' Cos((x-y+t)/100)
fsub dword [#y]
fadd dword [#t]
fdiv DWORD [#divisor]
fcos
faddp st(1) ')
fmul DWORD [#two] '*2
fld dword [#t] ' Sin(t/100)*15
fdiv DWORD [#divisor]
fsin
fmul DWORD [#fifteen]
faddp st(1)
fstp dword [#c] ' -> store to c
'-----
fld dword [#c]
fcos
fmul DWORD [#v64]
fadd DWORD [#v128]
fistp dword [#Green] ' -> store to Green
'-----
fld dword [#c]
fsin
fmul DWORD [#v64]
fadd DWORD [#v128]
fistp dword [#Red] ' -> store to Red
'-----
fld dword [#c]
fchs ' change sign
fdiv DWORD [#two]
fcos
fmul DWORD [#v64]
fadd DWORD [#v128]
fistp dword [#Blue] ' -> store to Blue
'-----
xor eax,eax
add eax,[#red]
shl eax,8
add eax,[#green]
shl eax,8
add eax,[#blue]
'or eax,0xff000000
mov [#compo],eax ' composite ARGB color
ret
"
dim v64, v128 as single
dim Red, Green, Blue, Compo as long = 255
v64 = 64
v128 = 128
dim ColorCalc as string = O2_ASM(ColorCalcSrc)
if len(O2_ERROR) then
msgbox 0, O2_ERROR+$crlf+"Program will end now"
stop
end if
dim t1, t2 as double
FBGFX_ScreenRes(w,h,32,2)
O2_EXEC ' initialise
while FBGFX_InKey() <> "q" 'Program runs until "q" is pressed
'k=asc(FBGFX_inkey())
'if (k=27)or(k=&h51)or(k=&h71) then exit do ' esc or Q or q
t1 = gettickcount
t=t+1
For x = 0 To w step 3
For y = 0 To h step 3
MC_EXEC ColorCalc
FBGFX_circle x, y, 3, compo
Next
Next
'pageflip
page=-page+1
FBGFX_Sync(1)
FBGFX_ScreenSet(page,-page+1)
t2 = gettickcount
wend
O2_PROC2 ' terminate
'msgbox 0, ":"+hex$(fbgfx_rgb(0,0,1))
'msgbox 0, "FrameTime:"+STR$(t2-t1)
thanks in advance...
btw: the forum is dead or quite offline today ;) bill gates checked the new thinbasic release and will give a donation of 1.000.000 dollar ???
:dog24:
Lionheart008
07-05-2009, 19:50
hi charles, found a similar example and checked it, I can close the script by "q" pressing...
but when I am changing some values like two=2 into four=4 and rise the value of fifteen to thirteen... I have the same problem as my last example above ;)
the plasma example is really impressive, thanks ! :D
'Plasma-like effect with FBGFX
uses "FBGFX"
uses "OXYGEN"
Dim w,h,x,y,i,syn As long
w=600 ' x boundary
h=480 ' y boundary
i=2 ' step
syn=0 ' loop flag
FBGFX_ScreenRes(w,h,32,2)
Dim page As single
Dim c,t As single
dim divisor, two, four, fifteen, thirteen As single
divisor = 100
two = 2
fifteen = 15
dim ColorCalcSrc as string="
'-----
fild dword [#x] ' Sin((x+y+t)/100)
fiadd dword [#y]
fadd dword [#t]
fdiv DWORD [#divisor]
fsin
fild dword [#x] ' Cos((x-t)/100)
fsub dword [#t]
fdiv DWORD [#divisor]
fcos
faddp st(1)
fild dword [#y] ' Cos((y-t)/100)
fsub dword [#t]
fdiv DWORD [#divisor]
fcos
faddp st(1)
fild dword [#x] ' Cos((x-y+t)/100)
fisub dword [#y]
fadd dword [#t]
fdiv DWORD [#divisor]
fcos
faddp st(1) ')
fmul DWORD [#two] '*2
fld dword [#t] ' Sin(t/100)*15
fdiv DWORD [#divisor]
fsin
fmul DWORD [#fifteen]
faddp st(1)
fstp dword [#c] ' -> store to c
'-----
fld dword [#c]
fcos
fmul DWORD [#v64]
fadd DWORD [#v128]
fistp dword [#Green] ' -> store to Green
'-----
fld dword [#c]
fsin
fmul DWORD [#v64]
fadd DWORD [#v128]
fistp dword [#Red] ' -> store to Red
'-----
fld dword [#c]
fchs ' change sign
fdiv DWORD [#two]
fcos
fmul DWORD [#v64]
fadd DWORD [#v128]
fistp dword [#Blue] ' -> store to Blue
'-----
'compose rgb color
xor eax,eax
add eax,255
shl eax,8 ' alpha byte optional
add eax,[#red]
shl eax,8
add eax,[#green]
shl eax,8
add eax,[#blue]
mov [#compo],eax ' composite ARGB color
'-----
' increment x y and clear syn flag afer each screen cycle
mov eax,[#x]
mov ecx,[#y]
(
add eax,[#i] ' increment x
cmp eax,[#w] '
jl exit '
xor eax,eax ' zero x
add ecx,[#i] ' increment y
cmp ecx,[#h] '
jl exit
xor ecx,ecx ' zero y
mov [#syn],ecx ' zero sync
)
mov [#x],eax
mov [#y],ecx
ret
"
dim v64, v128, v256 as single
dim Red, Green, Blue, Compo as long = 255
v64 = 64
v128 = 128
v256 = 256
dim ColorCalc as string = O2_ASM(ColorCalcSrc)
if len(O2_ERROR) then
msgbox 0, O2_ERROR+$crlf+"Program will end now"
stop
end if
'msgbox 0,o2_view(ColorCalcSrc) ' look at O2 translated source
'stop
dim t1, t2 as double
while FBGFX_InKey() <> "q" 'Program runs until "q" is pressed
t1 = gettickcount
t=t+1
syn=1
while syn
MC_EXEC ColorCalc
FBGFX_circle x, y, i, compo
wend
page=-page+1 ' page flip
FBGFX_Sync(1)
FBGFX_ScreenSet(page,-page+1)
't2 = gettickcount
wend
'msgbox 0, "press q to stop and end the script"
'msgbox 0, "FrameTime:"+STR$(t2-t1)
Michael Hartlef
07-05-2009, 20:31
btw: the forum is dead or quite offline today ;) bill gates checked the new thinbasic release and will give a donation of 1.000.000 dollar ???
I'm busy coding atm, nothing i can show right now.
ErosOlmi
07-05-2009, 21:02
btw: the forum is dead or quite offline today ;) bill gates checked the new thinbasic release and will give a donation of 1.000.000 dollar ???
:whacky34: I'm always here as far as I can but sometimes real life and real job take priority.
I'm in "real job priority status on" at the moment. And (under the curtains) I'm also preparing new thinBasic web site, improving thinBasic, developing old requests, and things like that.
:aggressive:
Bill can keep his money or use for donations to people in need. We do not need them.
Charles Pegge
07-05-2009, 21:05
Hi Lionheart,
I think the plasma has gone off into a wild loop, and you see how the frame rate has become very slow, so the keyboard is not consistently monitored.
The algorithm came from Mysthema via Petr, I have not explored its characteristics. It was really a performance test.
Charles
Petr Schreiber
07-05-2009, 22:08
Hi,
as FBGFX is not actively developed, here is UI/Canvas version:
'Plasma-like effect with Canvas
uses "UI", "oxygen"
function TBMain()
dim w as long = 320
dim h as long = 240
' -- Creating canvas window
dim hWnd As Dword = Canvas_Window("Plasma", 100, 100, w, h)
' -- Attaching it for drawing and setting coordinate system
Canvas_Attach(hWnd, 0, %true)
Canvas_Scale (1,1,w,h)
' -- Preparation for compilation
dim compiledCode as string
dim x,y As single
dim c,t As single
dim divisor as single = 100
dim two as single = 2
dim fifteen as single = 15
dim v64 as single = 64
dim v128 as single = 128
dim Red, Green, Blue as long = 255
dim compo as long= 255
dim ColorCalcSrc as string="
'-----
fld dword [#x] ' Sin((x+y+t)/100)
fadd dword [#y]
fadd dword [#t]
fdiv DWORD [#divisor]
fsin
fld dword [#x] ' Cos((x-t)/100)
fsub dword [#t]
fdiv DWORD [#divisor]
fcos
faddp st(1)
fld dword [#y] ' Cos((y-t)/100)
fsub dword [#t]
fdiv DWORD [#divisor]
fcos
faddp st(1)
fld dword [#x] ' Cos((x-y+t)/100)
fsub dword [#y]
fadd dword [#t]
fdiv DWORD [#divisor]
fcos
faddp st(1) ')
fmul DWORD [#two] '*2
fld dword [#t] ' Sin(t/100)*15
fdiv DWORD [#divisor]
fsin
fmul DWORD [#fifteen]
faddp st(1)
fstp dword [#c] ' -> store to c
'-----
fld dword [#c]
fcos
fmul DWORD [#v64]
fadd DWORD [#v128]
fistp dword [#Green] ' -> store to Green
'-----
fld dword [#c]
fsin
fmul DWORD [#v64]
fadd DWORD [#v128]
fistp dword [#Red] ' -> store to Red
'-----
fld dword [#c]
fchs ' change sign
fdiv DWORD [#two]
fcos
fmul DWORD [#v64]
fadd DWORD [#v128]
fistp dword [#Blue] ' -> store to Blue
'-----
xor eax,eax
add eax,[#red]
shl eax,8
add eax,[#green]
shl eax,8
add eax,[#blue]
'or eax,0xff000000
mov [#compo],eax ' composite ARGB color
ret
"
' -- Compiling
compiledCode = O2_ASM(ColorCalcSrc)
if len(O2_ERROR) then
msgbox 0, O2_ERROR+$crlf+"Program will end now"
stop
end if
O2_EXEC ' initialise
' -- Main loop
GetAsyncKeyState(-1)
do
t+= 1
for x = 1 to w step 3
for y = 1 to h step 3
MC_EXEC compiledCode
Canvas_Box_WH(x,y, 4, 4, 0, compo, compo)
if GetAsyncKeyState(%VK_ESCAPE) then exit do
next
next
Canvas_Redraw
loop
Canvas_Window end
O2_PROC2 ' terminate
end function
Petr
Lionheart008
07-05-2009, 23:26
great :) thank you... both... and the rich little robot master ;) I will check the UI/Canvas script next time... good night !
:zzz:
lionheart
Charles Pegge
08-05-2009, 07:27
Thanks Petr,
Will go with canvas from now on.
Petr and Frank:
I've translated the plasma program into o2 basic and reworked it a bit to make the algorithm clearer.
Now it is much easier to play with the formula and numbers. Try enabling the Hendrix factor near the end ;)
To make the formulae less cluttered I have suppressed to normal operator precedence rules with the #noprec prefix.
Charles
PS since most of the CPU clocks go on the trig functions - there should be negligable difference between Assembler and compiled basic.
'Plasma-like effect with Canvas
uses "UI", "oxygen"
'----------------
function TBMain()
'================
dim w as long = 320
dim h as long = 240
' -- Creating canvas window
dim hWnd As Dword = Canvas_Window("Plasma", 256, 128, w, h)
' -- Attaching it for drawing and setting coordinate system
Canvas_Attach(hWnd, 0, %true)
Canvas_Scale (1,1,w,h)
' -- Preparation for compilation
dim compiledCode as string
dim x,y As single
dim c,t As single
dim divisor as single = 100
dim compo as long= 255
dim p0,p1 as long
dim ColorCalcSrc as string="
o2h
'-------------------------------------
function plasma_pixel() as long at #p1
'=====================================
dim as single x at #x, y at #y, t at #t, d at #divisor, c at #c
dim as long red,green,blue,compo
'SIMPLE LEFT TO RIGHT EVALUATION
'-------------------------------
d=100
#noprec
c= sin(x+y+t /d) +
cos(x-t /d) +
cos(y-t /d) +
cos(x-y+t /d) *2 +
(sin(t/d)*15)
'-------------------------------
dim satur = 32 ' 0..127
dim white = 255-satur*2
dim as single bright=.90
'LEFT TO RIGH EVALUATED
#noprec red = 1+sin(c)*satur + white * bright
#noprec green = 1+cos(c)*satur + white * bright
#noprec blue = 1+cos(-c*.5)*satur + white * bright
compo=blue : shl compo,8 : compo+=green : shl compo,8 : compo+=red
'COMPO=COMPO*.75 'HENDRIX FACTOR :)
function=compo
end function
'------------------
sub finish() at #p0
'==================
terminate
end sub
'ret
"
' -- Compiling
o2_basic ColorCalcSrc
if len(O2_ERROR) then
'msgbox 0,o2_prep ColorCalcSrc
msgbox 0, O2_ERROR+$crlf+"Program will end now"
stop
end if
O2_EXEC ' initialise
declare sub plasma_pixel() at p1
declare sub finish() at p0
' -- Main loop
GetAsyncKeyState(-1)
do
t+= 1
for x = 1 to w step 3
for y = 1 to h step 3
compo=plasma_pixel
Canvas_Box_WH(x,y, 4, 4, 0, compo, compo)
if GetAsyncKeyState(%VK_ESCAPE) then exit do
next
next
Canvas_Redraw
loop
Canvas_Window end
finish ' terminate
end function
Lionheart008
08-05-2009, 10:15
shorty... good morning all and thank you charles... very good script, I have checked it and saved it in my mind... have a nice day, here's raining again... brrr... missing more sunshine :)
it was possible to add tan function but plasma structure became horrible diagonal lines;)
my plasma example:
'Plasma-like effect with Canvas
uses "UI", "oxygen"
'----------------
function TBMain()
'================
dim w as long = 520
dim h as long = 440
' -- Creating canvas window
dim hWnd As Dword = Canvas_Window("Plasma", 256, 128, w, h)
' -- Attaching it for drawing and setting coordinate system
Canvas_Attach(hWnd, 0, %true)
Canvas_Scale (1,1,w,h)
' -- Preparation for compilation
dim compiledCode as string
dim x,y As single
dim c,t As single
dim divisor as single = 100
dim compo as long= 255
dim p0,p1 as long
dim ColorCalcSrc as string="
o2h
'-------------------------------------
function plasma_pixel() as long at #p1
'=====================================
dim as single x at #x, y at #y, t at #t, d at #divisor, c at #c
dim as long red,green,blue,dark, compo
'SIMPLE LEFT TO RIGHT EVALUATION
'-------------------------------
d=100
#noprec
c= sin(x+y+t /d) +
cos(x-t /d) +
sin(x-y+t /d) *4 +
cos(y-t /d) +
cos(x-y+t /d) *2 +
(sin(t/d)*15)
'-------------------------------
dim satur = 32 ' 0..127
dim white = 255-satur*2
dim as single bright=.90
'LEFT TO RIGH EVALUATED
#noprec red = 1+sin(c)*satur + white * bright
#noprec green = 1+cos(c)*satur + white * bright
#noprec blue = 1+cos(-c*.5)*satur + white * bright
#noprec dark = 1+sin(-c*.75)*satur + white * bright
compo=blue : shl compo,8 : compo+=green : shl compo,8 : compo+=red : compo+=dark
'COMPO=COMPO*.75 'HENDRIX FACTOR :)
function=compo
end function
'------------------
sub finish() at #p0
'==================
terminate
end sub
'ret
"
' -- Compiling
o2_basic ColorCalcSrc
if len(O2_ERROR) then
'msgbox 0,o2_prep ColorCalcSrc
msgbox 0, O2_ERROR+$crlf+"Program will end now"
stop
end if
O2_EXEC ' initialise
declare sub plasma_pixel() at p1
declare sub finish() at p0
' -- Main loop
GetAsyncKeyState(-1)
do
t+= 1
for x = 1 to w step 4
for y = 1 to h step 4
compo=plasma_pixel
Canvas_Box_WH(x,y, 5, 5, 0, compo, compo)
if GetAsyncKeyState(%VK_ESCAPE) then exit do
next
next
Canvas_Redraw
loop
Canvas_Window end
finish ' terminate
end function
works fine for me ! see you alligators, ciao, salve, salute, Lionheart
...now back at work again...
Petr Schreiber
08-05-2009, 10:34
Charles,
great job, Hendrix factor causes very nice output :)
Does #noprec force ignoring of operator precedence?
I think for this demo it could be advantageous to fill whole array of colors instead of single pixel, and the use TB just for plotting. I am not sure how to bind 2D array from TB to O2H.
Petr
Charles Pegge
08-05-2009, 13:40
Hi Petr,
#noprec prevents the precedenter from being used on expressions. (it inserts brackets to establish operator precendence)
I've got the plasma_box function ready as an rgb texture array generator for a thinBasic array texmap(w,h) : can this be bound to a canvas box or the canvas background?
Charles
Lionheart008
09-05-2009, 18:15
bonjour, bon giorno dear oxygenists,
one more simple question:)
- how can I split a #view list into two or three parts ? my display/ monitor doesn't show longer list...
- #view - #endv: I can use it in one script more than one time?
thank you charles for #noprec and plasma_box, I would like to see more... :)
have examined this morning your classes2 script and played around with it...
'CLASSES AND MULTIPLE INHERITANCE
uses "oxygen","file"
dim src as string
src = "
class color_rgba
r as byte
g as byte
b as byte
a as byte
=
rgba as long
end class
class vector_2d
x as single
y as single
end class
class texmap_2d
u as single
v as single
width as single
height as single
end class
class vector_3d
x as single
y as single
z as single
end class
#view
class point
vector_3d,
color_rgba,
normal as vector_3d
texmap as vector_2d
material as texmap_2d
end class
' #endv
class surface
method append(byval pt as long)
method clear()
method render()
/
list as string
po as long
le as long
mat_diffuse as color_rgba
mat_specular as color_rgba
mat_shininess as single
mat_ambiente as single
mat_transparency as single
end class
#endv
methods of surface
method append(byval pt as long)
dim p,q as long
'
'CHECK BUFFER SPACE
'
p=this.po + sizeof point
if p>=this.le then
this.list+=space 1000
p=*this.list-4
this.le=*p
end if
'
'COPY IN
'
q=*this.list + this.po
copyn q, pt, sizeof point
this.po+=sizeof point
proc mbox `3 hello mrs. lionheart`
end method
method clear()
this.po=0
this.le=0
this.list=``
end method
method render()
'...
end method
end methods
proc mbox `1 hello paula, anne and mary`
`2 hello superb oxygen with water`
mov ecx,eax
call mbox ecx
'====
'TEST
'====
dim pt as point
dim sf as surface
sf.append &pt
sf.render
sf.clear
print `end: all is ok with me :) ` &pt
'
terminate
"
o2_basic src
msgbox 0, o2_len+$cr+o2_prep "o2h "+src
if len(o2_error) then msgbox 0, o2_error : stop
o2_exec
ciao, nice day, Lionheart
ps: I have tried yesterday evening to include a canvas_box into the plasma script.. but didn't manage it... or a picture... uargh :D I will wait for new instructions with canvas mode coding , I am curious so what petr says about this theme... ;)
Charles Pegge
10-05-2009, 07:18
Hi Frank,
Yes we can explore variations on the plasma algorithm and generate TBGL textures from them without using BMP files. Many possibilities here. :)
- how can I split a #view list into two or three parts ? my display/ monitor doesn't show longer list...
You can save the o2_view to a file or lprint it to the console, which gives you scrollable output.
- #view - #endv: I can use it in one script more than one time?
At the moment only one #view .. #endv is supported.
Charles
uses "oxygen","console"
dim src as string
src="o2h : #view : dim a,b,c : a=b*c : #endv : terminate"
printl o2_prep src
printl "==================="
printl o2_view src
waitkey
Lionheart008
10-05-2009, 15:19
thank you charles for infos:)
hi all oxygen friends...
You can save the o2_view to a file or lprint it to the console, which gives you scrollable output.
good to know... have checked the view split and made this example... all is ok with oxygen now, I like it...
have a nice sunday... enjoy the sun, ice cream, walking and shopping now :D
ciao, Lionheart
uses "oxygen", "console", "UI"
dim src as string
dim a, b, c, d, e, f as long
dim lionheart_is_an_oxygen_explorer as string
src="o2h : #view : dim a,b,c as long : b=2 : c=4 : a=b*c : print `lionheart_is_an_oxygen_explorer` : #endv : terminate"
printl o2_prep src
msgbox 0, o2_prep src
printl "==================="
'--new numbers
dim g as string = "Hey, what's a nice and beautiful sunday! "
a = 2
b = 4
c = 12
d = a*b+c
g = "Hey, what's a nice and beautiful sunday! "
o2_basic " print `second result is: ` str 1+2+3+4+5+6-4 : terminate " '15 - `1+2+3+4+5 = `
printl "result one: " + d
printl
msgbox 0, "result one: " + d
o2_exec
'
printl o2_view src
msgbox 0, o2_view src
src="o2h : #view : dim a, d,e,f : f=d*e+a : #endv : terminate"
msgbox 0, o2_prep src
printl "==================="
printl o2_view src
printl "push any key to exit"
waitkey
Lionheart008
12-05-2009, 14:12
hi charles, hi all other oxygen friends :)
simple but heavy questions about your "tomdk" I have checked this morning, how can I use it for my own purposes ???
- it's necessary to compile the tomdk every time new, when I am making changes ???
- How can I know what's possible with this "T" file??? confuse me a little... sorry, it's quite new stuff for me... so I can compile a thinbasic module with this script and do everything with it I wish ??? :shock:
' TOMDK test
' thinBasic Oxygen Module Development Kit
' compiles thinBasic modules, my first test :)
Uses "File"
Uses "T"
USES "Console"
'=================================================
'test line:
msgbox 0,t_len, "", "Oxy"
msgbox 0,t_view("my new input")
msgbox 0,t_error
msgbox 0,t_Act
msgbox 0,t_Buf
printl t_Buf
dim a, b, c, 2, 6 as long
a=2
b=6
c=a*b
printl c
msgbox 0, t_exec
waitkey
'=================================================
ciao, have all a nice and sunny day, Lionheart :)
Petr Schreiber
12-05-2009, 14:49
Hi Frank,
it's necessary to compile the tomdk every time new, when I am making changes ???
Yes. You are compiling DLL, so to make changes visible you must create new machine code soup after each change :)
As you are compiling with Oxygen magic, you could, in theory, let part of the file source external, so Oxy would compile it from string at the time of calling module ( thats wild, but possible ).
How can I know what's possible with this "T" file
ThinBasic modules work on simple and ellegant principle. They are like normal DLLs + the following:
In compiler of your choice (this time Oxygen) you create custom functions
In those custom functions, you use ThinBasic SDK functions to take control over parsing parameters
You "register" the custom functions by "thinBasic_LoadSymbol" in LoadLocalSymbols
Of course, it does not have to be named T, just change fdll string in your TOMDK to something else, like "thinBasic_LionHeartMegaModule.DLL". So the module can do really anything you manage to compile :)
Try to browse samples from SDK directory in TB installation to get the general idea.
Petr
Lionheart008
12-05-2009, 17:57
hi petr! :) thank you for important infos... and I am surprised... I have really got my first own DLL ! WOW! :D... must laugh and I am feeling a little bit exciting...
thanks also for thinbasic, tbgl, ui, console and oxygen... 8)
Of course, it does not have to be named T, just change fdll string in your TOMDK to something else, like "thinBasic_LionHeartMegaModule.DLL". So the module can do really anything you manage to compile Smile
Try to browse samples from SDK directory in TB installation to get the general idea.
thanks petr, very good to know that... :) this may helps a lot... if it's really so simple I will see it with the next example... I may ask a lot, I am sure...
thinBasic_LoadSymbol `t_Color`,thinBasic_ReturnString, pColor, thinBasic_ForceOverWrite
-> qt 1) see above line: that's simply possible??? (charles, petr, anybody else..)
I need for this only the TOMDK script to change??? I am not sure about this...
-> qt 2) I have nearly understood how to do implement new Symbols in theory ! ;)
if you like, now you can use a new module... for testing... new functions and inputs I will check... as soon as possible... and more to come that's for sure... ;)
' Lionhearts TOMDK test, 12.may.2009
' thinBasic Oxygen Module Development Kit
' compiles thinBasic modules
Uses "File", "UI"
Uses "lionhearts_megamodule"
Uses "Console", "Oxygen"
dim res as long = 30*12*45
dim u as string = " ...are my sunny days on this planet earth "
dim v as ext = 3.14159265
randomize timer
dim ButtonClicked as long = rnd(1, 3)
dim FunctionToCall as string
dim src as string
'---- first part oxygen -------------------------------
src = "
o2h
dim i,j=1 as long
dim s,t as string
s=space 500
for i=1 to 24
t=str(i)+chr(13)+chr(10)
#view
mid (s,j)=t
j+=len t
#endv
next
dec j
print left s,j
print `hello you are welcome to the thinbasic & lionhearts_megamodule script :) ` + j
terminate
"
file_save ("tb_lionmodule.txt", o2_prep src)
msgbox 0, o2_len+$cr+o2_view "o2h "+src
o2_basic src
o2_exec
dim q, calc as string
'do
calc=inputbox$ "Enter here an math. Expression: ","OXYGEN CALCULATOR",calc
if calc="" then exit do
o2_basic " print str "+calc+" : terminate"
if len(o2_error) then msgbox 0,o2_error
o2_exec
'loop
'---- second part lionhearts_megamodule ------------------------------- :D
printl
msgbox 0, res + u, "", "lionhearts_megamodule"
res = Msgbox(0, "pi: " & str$(v) )
printl ("-- next step, please go on... -- ")
printl
msgbox 0,t_len, "", "Oxygen & thinbasic friendly like :) "
msgbox 0,t_view(" => this is my new TB Lionhearts_Megamodule script example ")
msgbox 0,t_error
msgbox 0,t_Act
msgbox 0,t_Buf
printl t_Buf
dim a, b, c, d, 2, 6 as long
a=2
b=6
c=a*b
d=a*b/2
printl c
print d
printl
msgbox 0, t_exec
printl " -- push me to continue the script --"
waitkey
printl
'---- third part thinbasic -------------------------------
IF ButtonClicked > 0 THEN
FunctionToCall = "Test" & ButtonClicked '---Compose the name as preferred
'---Check if function name exists. If yes, call it, otherwise error.
if function_exists(FunctionToCall) then
CALL FunctionToCall(timer)
else
msgbox 0, FunctionToCall & " does not exists."
end if
end if
SUB Test1(optional byval LionsParam as ext)
msgbox 0, "Test 1" & $crlf & "NewParam equal to: " & LionsParam
END SUB
printl "Hey, that's really funny with thinbasic modules !"
waitkey
SUB Test2(optional byval NewParam as long)
dim a, b, c as long
a= 5
b=26
c=240
newparam = a*b*c
msgbox 0, "Test 2" & $crlf & "NewParam equal to: " & NewParam
END SUB
printl
printl "-- Everything is ok with thinbasic ! Push any key to EXIT the script -- "
waitkey
SUB Test3(optional byval MyParam as long)
msgbox 0, "Test 3 is also good: " & MyParam
end sub
this is my own *.dll script based upon "tomdk" oxygen script... it's the first test for me... and now I have to check the sdk... to find a way for my new ideas... perhaps for my early idea of a "inka 3d" modeller script... uargh :P no, no... just a joke...
-> test my script.. I have added all into the zip file... script and dll :)
-> the script includes three parts... examine and have fun with it...
ciao, Lionheart
ps: thank you charles... for oxygen... some weeks ago I wanted to build a completely new DLL, but didn't know how to manage it... thanks for TOMDK :D !!!
edit new: updated the script, today at 20:31 pm
Lionheart008
13-05-2009, 11:25
hi all oxygen friends :)
hi charles, petr, good morning...
In this way I have grasp to manage all for two new dummy functions with "t_lion" and "t_color"... to understand the method of compiling such a nice script ... must be a lot of damned work to create a big DLL with fully functionality... respect to all they are building such great modules!
msgbox 0,t_len, "", "Oxygen & thinbasic friendly like :) "
msgbox 0,t_view(" => this is my new TB Lionhearts_Megamodule script example ")
msgbox 0,t_error
msgbox 0,t_Act
msgbox 0,t_Buf
msgbox 0, t_Lion
msgbox 0, t_Color
It was a good test for me, learn new things and how to handle with such an exciting script like oxygen's TOMDK ! to build perhaps sometimes a completely new thinbasic module ... I am now on the right way I can feel and see it (step one from hundred!) ...;) but it's a very time spending work to create such a big script like thinair, thincore or tbgl :D, I can imagine... but there is a lot of fun, satisfaction, pleasure to do these exciting things, isn't it ???
I add at least the little update with script and dll and stop now working with this idea for this moment ! for me it was very exciting to see how heavy and hard it is to program and compile such a new module... (eros, petr, michael, charles, roberto and all people I don't know yet) ... :drink:
ciao, cheerio, have all a nice day, Lionheart
- must go back at work again...
:dog16:
Frank congratulations on your first dll. I love your excitement and it is an exciting step in programming. All your study efforts are helping the rest of us and will be a nice footprint to follow to learn in the future or to refresh our understandings.
Charles Pegge
14-05-2009, 01:01
Hi Frank,
Yes that was courageous of you to dig into this code. - TOMDK really needs revising to take advantage of the newer o2h syntax. Parts of it are heavily dependent on macros, and the low level runtime was very limited.
Once I have a run-time library without FreeBasic dependencies, I can make this much more user-friendly. There are only a few functions I have to do - file i/o for example.
Charles
Lionheart008
14-05-2009, 15:24
you are welcome charles... and kent for your knowing such "feelings" and sharing it, good to hear that ! ;)
... so I will wait some days for the next TOMDK Update :)
dear oxygen friends...
- it's possible for you (if you have time...?)... or somebody else... to check my bible-test-speed script with my lionheart_megamodule dll ??? I have played around with it and combined it with oxygen too ;) don't see it too serious... or too close at the script...it was just an experiment for me... but it works fine... and fast, the first script even around one second faster... :)
and the results are good for this thinbasic/oxygen/lionheart_megamodul script ! :D
'-- speed textanalyse script for bible example by lionheart, 13.-14. may 2009
uses "Console", "File", "Oxygen", "Lionhearts_Megamodul"
#DEFAULT BOUNDCHECK OFF
dim src as string
' -- Prepare Oxygen script
src = "
o2h
function Calculate_asm(c as long) as long
local ic, jc as double, i as long
'
dim a=&c
mov eax,a
mov edx,[eax]
fld1
fld1
(
fmul st(0),st(0)
fstp qword ic
fld1
faddp st(1),st(0)
fld st(0),st(0)
dec edx
jg repeat
)
fcomp st(0),st(0)
'
end function
sub finish() at #p0
'print `running.. testing the bible text`
terminate
end sub
"
o2_basic " print `Hello and Ciao dear Bible Tester` : terminate "
Console_WriteLine
Console_SetTitle("-- TextSpeedAnalyse Script with bible.txt by lionheart --")
dim inString as string = app_sourcepath & "bible.txt"
dim outString(1024) as string = inString & "lion_mysorted_bible.txt"
dim t1, t2 as quad
dim i as long
doevents(off)
hiResTimer_Init
t1 = hiResTimer_Get
printl "Reading bible text file: ", inString
dim inStringBuffer as string = file_load(inString)
printl "Input file size:", len(inStringBuffer), "all my bytes"
'---Change all delimiters to $SPC chars
dim stringSearch as string = chr$(1 to 64)+"0123456789:-|(){}[]';,.?!/\^!@#$%^&*_<>=+"+$DQ+chr$(i-1)
dim stringReplace as string = string$(len(stringSearch), $spc)
inStringBuffer = ucase$(Replace$( inStringBuffer, any stringSearch, stringReplace))
'---Remove all double $SPC to single $SPC in order to have all words separated by a single $SPC
printl "Removing double spaces from buffer ..."
inStringBuffer = trimFull$(inStringBuffer)
'---Parse the buffer into an array
Dim Words() As string '---All words uncounted
Dim cWords() As string '---All words counted
Dim nWords As Long '---Original number of words
Dim nWordsOk As Long
dim cWord as long
dim Counter as long
printl "Parsing every word into an array ..."
nWords = PARSE(inStringBuffer, Words, $spc)
'---Sort ASC
printl "Sorting array asc ..."
array sort Words
'---Scann all words and count
printl "Counting bible words ..."
redim cWords(nWords)
for Counter = 1 to nWords - 1
cWord += 1
if Words(Counter) <> Words(Counter + 1) then
nWordsOk += 1
cWords(nWordsOk) = Words(Counter) & " (" & cWord & ")"
cWord = 0
end if
next
'---Last compare to check if last item is equal to previous of is different alone
if cWord = 0 then
cWord += 1
nWordsOk += 1
cWords(nWordsOk) = Words(Counter) & " (" & cWord & ")"
else
cWord += 1
cWords(nWordsOk) = Words(Counter) & " (" & cWord & ")"
end if
'---Redim to the last found word
printl "Saving output results to: ", outString(1024)
redim preserve cWords(nWordsOk)
file_save(outString(1024), join$(cWords, $crlf))
dim Characters(256) as long
dim stringLen as long = len(inString)
for i = 1 to stringLen
Characters( asc(inString, i)+1 ) += 1
next
for i = 1 to 256
if Characters(i) > 0 then outString(i) = Characters(i)+$TAB+iif$( i<4, PARSE$( inString,",F",i), chr$(i-1))
next
array sort outString(i), descend
T2 = hiResTimer_Get
printl
printl "------ all work is done ------"
printl
printl "Number of all words found ....... : ", nWords
printl "Number of unique words counted: ", nWordsOK
printl "lionhearts total time:" & format$(t2 - t1, "#,"), "milliseconds complete "
o2_exec
waitkey
So far as I have seen it's a little bit faster than conventional thinbasic (pur) scripts... ;)
ciao, best regards, good ideas for further development, see you, Lionheart
ps: have done all in one zip folder... two scripts for testing, two dll's :)
LionHeart:
Here are the results running you'r "faster" test program on my laptop--
TOTAL TIME = 5,532.283 milliseconds
Don
Lionheart008
14-05-2009, 19:38
Hi don! :)
very good! thank you for testing... may I ask you what script you have tested??? ;)
as I have included in zip file two scripts... for bible text testing... I can imagine you have tested the second one..., isn't it ?
a) Frankos_TextSpeedAnalyse_Bible_Try2_oxy.tbasic
(after my test behaviour with notebook this script is over one second faster ! ) :)
or
b) Frankos_TextSpeedAnalyse_Bible_Try_Faster_Lionmodule.tbasic
(this script needs extra the lionheart_megamodul dll and it's running not so fast as
my first script.. that's my experience with script speed testing for today...)
and my mistake... must call 5.532.283 seconds, not milliseconds... I will change it... ;)
would be nice to hear what script you have checked...?
good evening, by the way: what are your experiences with oxygen / thinair module ???
ciao, Lionheart
Lionheart:
Using TRY2_OXY, result is 5.526.163 SEC.
Using TRY_FASTER_LIONMODULE, result is 5.726.216 SEC
I am afraid I have not done very much with O2 so far; I am still trying to figure out how to use it with thinBasic. Some user documentation would sure be helpful.
Don
Lionheart, here are my results:
Frankos_TextSpeedAnalyse_Bible_Try_Faster_Lionmodule.tbasic : 5,590,961 ms
Frankos_TextSpeedAnalyse_Bible_Try2_oxy.tbasic : 5,582,135 ms
Lionheart008
15-05-2009, 09:23
hi dear oxygen friends,
dear kent and don, thank you very much for your speed results :) Good to see that the script is as fast as I thought...
dear charles :) here comes a little oxygen diagnose and U2 script... and the next question for you or somebody else how to build a list with oxygen ??? I would like to have the list for all U2 lp's with oxygen by name and date, I can check the details for lp's and cd's (I am sure) or live concerts at the U2 toor 2009 :D ...
'----- by lionheart for learning stuff :)
' DIAGNOSTICS + CALLS
uses "oxygen","file","console"
dim src as string
dim msg as string = "...because U2 rockmusicicians are my best friends! :) "
src = "
o2h
dim i,j=1 as long
dim s,t as string
dim ciao dear rocker as string
`2009 European live tour: hello U2 friends from all over the world...`
mov ecx,eax
call mbox ecx
proc mbox `Tourbegin of < U2: 360° Tournee, Europe > starts at 30. Juni in Barcelona, Nou Camp...
U2 band members are:
Vocals: Paul David Hewson (Bono),
Guitar: David Howell Evans (The Edge),
Drums: Larry Mullen Junior,
E-Bass: Adam Clayton
more infos: 1) http://www.u2tour.de/tour/
`
call myfunction `Bono: I only can play very bad guitar but I am a good singer :) `
myfunction: ' byval string pointer
mbox [esp+4]
proc mbox `Tracklist: U2 CD - NO LINE ON THE HORIZON -
1. No Line On The Horizon (4:14)
2. Magnificent (5:23)
3. Moment of Surrender (7:23)
4. Unknown Caller (6:02)
5. I will Go Crazy If I Do not Go Crazy Tonight (4:13)
6. Get On Your Boots (3:24)
7. Stand Up Comedy (3:48)
8. Fez – Being Born (5:14)
9. White As Snow (4:39)
10. Breathe (4:58)
11. Cedars Of Lebanon (4:13)`
proc mbox `U2 list of all LP and CDs (1981-2009)
1) October (1981)
2) War
3) Under a Blood Red Sky
4) The Unforgettable Fire
5) Wide Awake in America
(EP)
6) The Joshua Tree
7) Rattle and Hum
8) Achtung Baby
9) Zooropa
10) Pop
11) All That You Cant Leave Behind
12) How to Dismantle an Atomic Bomb
13) No Line on the Horizon (2009)`
s=space 500
for i=1 to 13
t=str(i)+chr(13)+chr(10)
mid (s,j)=t
j+=len t
next
dec j
print left s,j
print `Enjoy U2 tour 2009 also live in California `
terminate
"
o2_basic src
printl
printl ("--- Oxygen Script example with Calls and Diagnostic by lionheart :) ---")
printl
printl msg
printl
printl ("1) http://www.u2tour.de/tour/")
printl ("2) http://www.u2.com/tour/index/")
sleep 100
'printl "push any key to continue"
'waitkey
'-------
'OUTPUTS
'=======
file_save ("s-assembler.txt", o2_prep "o2h "+src) ' o2 Assembler output
file_save ("t-lionscript.txt", o2_view "o2h "+src) ' o2 script output
'file_save ("t-binary.bin", o2_get) ' o2 binary
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
nice day, best regards from bono and the edge, Lionheart :music:
Charles Pegge
15-05-2009, 16:45
Hi Lionheart,
This takes us into database territory. We could use the color picker / Canvas demo - reusing some of the controls and the edit box. Then combine this with some of the word-counter code for efficient searching. Is your music list as long as the bible? 8)
Charles
Lionheart008
20-05-2009, 13:43
hi charles, hi all dear oxygen friends...
my little 4 cents for today... :)
a) why does the result of "sizeof oo " is 0 ???
b) what's the meaning of double "dim dim" oo as cc ???
'-STATIC MEMBERS
'-test by lionheart, 20.mai2009
uses "oxygen","file"
dim src as string
src = "
o2h
class cc
static a as string
end class
dim dim oo as cc
oo.a=`bonjour monsieur et madame clouseau de paris!`
print oo.a
print `size of oo type is: `str sizeof oo
class bb
static b as string
end class
#view
print `yeah! it is very hot this day!`
dim dim oo as bb
oo.b=`quiz: who has found the pink panther juwel?`
print oo.b
'print `size of type: `str sizeof oo
call mbox `of course: the incredible stupid inspector clouseau! :) `
#endv
terminate
"
o2_asmo src
msgbox 0, o2_prep src
msgbox 0, o2_view src
if len(o2_error) then
msgbox 0, o2_error : stop
else msgbox 0, "all is ok with this oxygen script while the roof is on fire! :) "
end if
file_save ("one-assembler.txt", o2_prep "o2h "+src) ' o2 Assembler output
file_save ("two-lionscript.txt", o2_view "o2h "+src) ' o2 script output
o2_exec
so far I have checked it with the new thinbasic release and worked fine for me, thank your for giving new o2 scripts ... go on for new gold :)
cheerio, Lionheart
ps: uhps... have found this one.. have overseen it... ;)
http://community.thinbasic.com/index.php?topic=2674.msg20167;topicseen
Charles Pegge
20-05-2009, 18:03
Thanks Lionheart,
I was trying to think of a suitable analogy for a static members only class. Then I thought of cables - connecting many different kinds of objects together all sharing the same lines. In a car, for instance, there will be a number of cables, each with several kinds of devices using them: engine control, heating, lighting, windows, stereo etc.
Traditionally - in a small program at least, global variables are used to pass common data around different functions but this gets very messy as the complexity of the program increases. Using these class/types is an efficient way to bunch global variables together and distribute them where they are needed.
Having zero size is an interesting consequence of having a virtual table but no body. So when one of these is dim'ed, nothing new is created - you just have a name to gain access to the shared class table of variables.
As for dim dim - that's stuttering finger syndrome :) I'm not sure why the compiler accepted it.
Charles
Lionheart008
24-05-2009, 21:04
hi charles, thank you for the infos about the last script with static members... :)
theme: loops, speed script for math. results... here it comes two new examples I have created the last days... while I have had a stressy time the last days... I haven't time enough to have a closer look to the new o2h scripts... ;(
example one: have fixed the log (lin)script... with your last oxygen update...do you remember ??? ;) thanks for fixing my wish...
' Test of loop optimization with Oxygen by lionheart, mai 2009
uses "Console", "Oxygen"
dim T1 as quad
dim T2 as quad
dim p0,p1,p2 as dword
dim src as string
' -- Prepare Oxygen script
src = "
o2h
function Calculate_basic(c as long) as long at #p1
local ic, jc, pc, lc as double, i as long 'lc
'
'BASIC VERSION
'
for i=1 to c
ic = sin(i)
jc = cos(i)
pc = tan(i)
lc = log(i)
next
end function
function Calculate_asm(c as long) as long at #p2
local ic, jc, pc, lc as double, i as long
'
'ASSEMBLER VERSION
'
'
dim a=&c
mov eax,a
mov edx,[eax]
fld1
fld1
(
fsincos
fstp qword jc
fstp qword ic
fstp qword pc
fstp qword lc
fld1
faddp st(1),st(0)
fld st(0),st(0)
dec edx
jg repeat
)
fcomp st(0),st(0)
'
end function
sub finish() at #p0
terminate
end sub
"
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
dim c as long=250000
declare function Calculate_o2bas(c as long) as long at p1
declare function Calculate_o2asm(c as long) as long at p2
declare sub finish () at p0
printl "-- NEW SPEED BENCHMARKS: --"
printl ""
printl "-- Double precision Sin & Cos & Tan & Log Test: loops= " & c
printl ""
doevents(off)
hirestimer_init
T1 = hirestimer_get
Counter c
T2 = hirestimer_get
printl "Script time: microSecs:" & $tab & FORMAT$(T2 - T1, "##,")
T1 = hirestimer_get
Calculate_o2bas c
T2 = hirestimer_get
printl "Compiled time: microSecs:" & $tab & FORMAT$(T2 - T1, "##,")
T1 = hirestimer_get
Calculate_o2asm c
T2 = hirestimer_get
printl "Assembler time: microSecs:" & $tab & FORMAT$(T2 - T1, "##,")
function Counter( MaxCount as long ) as long
local ic, jc, pc, lc as double,i as long
For i = 1 To MaxCount
jc = sin(i)
ic = cos(i)
pc = tan(i)
lc = log(i)
Next
end function
printl
printl "end of fantastic oxygen script and push a key"
finish
waitkey
for me this script works very fine now :)
ciao1, Lionheart
Lionheart008
24-05-2009, 21:10
second input... a bigger one :)
about this script I have became headache... because after my testing period over two hours and searching after a solution the math. commands "rnd(1,2)" or "atan" doesn't work with oxygen... do possible I am right? I am nearly sure... tested the scripts with my laptop...
here a really nice and good sub function (with a lot of message boxes!) script I have built new, I like it very :)
'- oxygen power :)
'- some Functions and Subs example by lionheart
'- 22.may.2009 :)
uses "oxygen","file", "math"
dim p0,p1,p2,p3 as long, src as string
dim kk(100) as double
dim rr(100) as double
dim xx(100) as double
dim x, y, z as integer
o2_basic " print ` ..follows some math. functions & results with oxygen power: ` str 1+2+3+4+5+6+7+8+9+10-13 : terminate "
o2_exec
src = "
function addmynumber(kk as double, byval n as long) as double at #p1
dim a, b, c, d as long
dim x,y,z as integer
a = 2009 : b = 2010 : c = 2011
#view
for i=1 to 4
d+= a+b+c
print `A: ..adding some year values: ` + d
next
function=a/4
#endv
dim y = lin(10)
for i=1 to 4
x+= y+2*360/32
print `B: x.object degree results = ` + x + `: ` + y ' + z +
next
function=x*lin(y)
dim k as double, i as long
for i=1 to 5
k+=kk(i)
print `C: some more exciting addmynumbers results: ` + k
next
function=k/8
'dim y as integer = 4*rnd(1,2)
'dim z as integer = 4*rnd(1,2)
end function
function curves(xx as double) as double at #p3
dim x, y, z as integer
dim i as long
dim xx as double = 2009
for i=1 to 5
x+ = xx(i)
y- = Log( x )
z+ = SIN( y )
Print `simply constant factor: ` str$ 1+2+3+4 : print `new incredible curves values: ` str$ cos(x)*sin(y) : terminate
Print ` y: ` + y
Print ` z: ` + z
Next
mbox `all is ok with this math. sub functions script :) `
end function
function foofighter(rr as double) as double at #p2
dim a, b,c, r as long
a= 2 : b = 4
dim i as long
dim rr as double = 1969
for i=1 to 5
r+= rr(i)
c+=a+b*2
print `foofighter: yeah, listen to ACDC music is allright: ` + c
next
end function
sub finish() at #p0
terminate
end sub
"
o2_basic src
'msgbox 0, o2_view "o2h "+src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
'msgbox 0, "thinbasic today is: " + date$ + ", oxygen time: " + time$
o2_exec
declare function addmynumber( kk as double, byval n as long ) as double at p1
declare function curves(xx as double) as double at p3
declare function foofighter(rr as double) as double at p2
declare sub finish () at p0
array assign kk=1,2,3,4,5,6,7,8
msgbox 0, "..addmynumber average result is : " + addmynumber kk, 8, "", " hey crazy android!"
array assign rr=1,2,3,4,5,6,7,8,9,10
msgbox 0, "..sorry, oxygen does not like to calculate: rnd(1,2) ! " + foofighter rr, 1969
array assign xx=1,2,3,4,5,6,7,8,9,10
'msgbox 0, lbound(xx,8),"" + curves xx,10, "" , "Total crazy"
msgbox 0, "..curves results are quite good : " + curves xx,10, "" , "Total crazy"
finish
end function
for eg: 'dim y as integer = 4*rnd(1,2) doesn't really work...
the script works! try it and you will like it :D
best wishes for new updates, see you, ciao2, Lionheart
Charles Pegge
25-05-2009, 09:06
Hi Lionheart,
There are ArcTangent comes in two forms:
Atn take one parameter eg atn(y/x)
Atan takes 2 arguments: atan(y,x)
uses "oxygen","file"
dim src as string
'-------------
'TRIG
'=============
src = "
#o2h
dim as string tab=chr 9
dim as double ra,de,xx,yy
yy=2
xx=1
ra=atn yy/xx
ra=atan (yy,xx) 'ALTERNATIVE
de=deg ra
print `
Y ` tab str(yy) `
X ` tab str(xx) `
Degrees ` tab str(de) `
Radians ` tab str(ra) `
`
terminate
"
'msgbox 0, o2_prep src
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
Oxygen does not have random in its core functions yet so here is a rnd() function. The rndstate number can be both read and set at any time.
uses "oxygen","file"
dim src as string
'-------------
'RANDOM
'=============
src = "
#o2h
dim as string tab=chr 9
dim as long rndstate
'
'RETURNS RANDOM NUMBER BETWEEN -1 AND 1
'
function rnd() as single
static as single f, d=1/0x7fffffff
mov eax,rndstate
rol eax,7 : xor eax,0x5a935a72
mov rndstate,eax
f=rndstate*d
function=f
end function
dim as single n1,n2,n3,n4
'
n1=rnd : n2=rnd : n3=rnd : n4=rnd
'
print `PSEUDORANDOM NUMBERS:
state: ` tab str(rndstate) `
N1 ` tab str(n1) `
N2 ` tab str(n2) `
N3 ` tab str(n3) `
N4 ` tab str(n4) `
`
terminate
"
'msgbox 0, o2_prep src
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
Lionheart008
25-05-2009, 16:07
hi charles :)
I needed only the random command for my last example and with your new example I can use this, thank you again for both ;)
uses "oxygen","file"
dim src as string
'-------------
'RANDOM
'=============
src = "
#o2h
dim as string tab=chr 9
dim as long rndstate
'
'RETURNS RANDOM NUMBER BETWEEN -1 AND 1
'
function rnd() as single
static as single f, d=1/0x7fffffff
mov eax,rndstate
rol eax,7 : xor eax,0x5a935a72
mov rndstate,eax
f=rndstate*d
function=f
end function
dim as single y1,y2,x3,x4,z1,z2,a1,b2
'
y1=rnd : y2=rnd : x3=5*rnd : x4=rnd : z1=4*rnd : z2=rnd : a1=2*rnd : b2=rnd ' z2=rnd(-1,1)
'
print `Some more of pseudorandom numbers:
state: ` tab str(rndstate) `
y1 ` tab str(y1) `
y2 ` tab str(y2) `
x3 ` tab str(x3) `
x4 ` tab str(x4) `
z1 ` tab str(z1) `
z2 ` tab str(z2) `
a1 ` tab str(a1) `
b2 ` tab str(b2) `
`
terminate
"
'msgbox 0, o2_prep src
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
best regards, Lionheart from very sunny and hot centre of germany, puh :beach:
Lionheart008
30-05-2009, 13:03
hi charles :)
perhaps you can use this "stack" one for more oxygen power ... found it this morning...
uses "oxygen","file"
dim s as string
s="
DIM stack AS INTEGER PTR
'stack last adress of stackplace
stack = stack - 15 'stack about 60 BYTE backwards ;)
' Expand down stack
' processor DATA
stack[14] = &h202 ' EFLAGS
stack[13] = &h08 ' CS
stack[12] = thread ' EIP
' pusha
stack[11] = 0 ' EDI
stack[10] = 0 ' ESI
stack[9] = 0 ' EBP
stack[8] = 0 ' NULL
stack[7] = 0 ' EBX
stack[6] = 0 ' EDX
stack[5] = 0 ' ECX
stack[4] = 0 ' EAX
' DATA segments
stack[3] = &h10 ' DS
stack[2] = &h10 ' ES
stack[1] = &h10 ' FS
stack[0] = &h10 ' GS
SUB Paging_activate
' we activate paging by enabling the last BIT of cr0.
ASM
mov eax, cr0 ' GET the value of cr0 into eax
bts eax, 31 ' set BIT 31
OR eax, &H80000000
mov cr0, eax ' GET the new value of eax into cr0
END ASM
END SUB
terminate
"
o2_basic s
if len(o2_error) then msgbox 0,o2_error
'msgbox 0,o2_prep "o2h "+s
'file_save ("t.txt",o2_prep "o2h "+s)
o2_exec
bye, Lionheart, nice day :)
Charles Pegge
31-05-2009, 07:10
Hi Frank,
This is operating system stuff. Normally access to the CR registers is available only to the OS itself. This is an area I have not studied yet.
Another weighty tome from Intel:
Intel Architecture Software Developer’s Manual Volume 3: System Programming
http://download.intel.com/design/PentiumII/manuals/24319202.pdf
Charles
Lionheart008
13-07-2009, 12:40
hi charles :)
can you check please for me this code you have done some days ago for peter... was an experiments I am thinking... and why I cannot see the print message ?
I have got an error message (gpf) at the end because I have tried to save the file.. .;)
'-- testscript :)
uses "oxygen","file"
dim src as string
src = "
#basic
function franko(byval score as long) as long
dim as long lev,HsData
oxy_asm:
push ebx : push esi
WriteHighScore:
mov edi,HsData
xor edx,edx
mov esi,lev
dec esi
imul esi,esi,16
mov ax,Score
add edi,esi
s1: cmp [edi+edx],ax
jae s2
mov [edi+edx],ax
call SetNames
ret
s2: add edx,2
cmp edx,16
jnz s1
pop esi : pop ebx
exit function
SetNames:
franko = 1
ret
oxy_end:
end function
dim a
a=franko 42
print `all is ok with franko`
terminate
"
file_save ( "franko-test.txt", o2_prep src )
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
best regards, nice day, I have a cold, damned ... Lionheart
Charles Pegge
13-07-2009, 13:24
Hi FranK,
This was just a piece of demo code, where I adapted Peter's example to fit in with Oxygen syntax. It was never a operational piece. But here is an example showing how basic can be mixed in with Assembler. And it is intended to work :)
Charles
uses "oxygen"
dim src as string
'--------------------------------
'USING BASIC INSIDE ASSEMBLY CODE
'================================
src = "
#basic
'----------------------------------
function fun(byval v as long) as long
'==================================
'ASSEMBLY CODE MUST NOT OVERWRITE THE ESI & EBX REGISTERS
'AS THESE ARE NEEDED BY OXYGEN BASIC
mov ecx,3 'NUMBER OF LOOPS
edx=v 'VALUE TO PROCESS
#view 'LIST VIEWING WINDOW
;==============================================
(
dec ecx 'DOWNCOUNT
jl exit 'JUMP OVER NEXT CLOSING BRACKET
imul edx,edx 'SQUARE
pushad 'SAVE ALL REGISTERS
'---------
v=edx 'DO SOME BASIC ..
print str V
'---------
popad 'RESTORE REGISTERS
repeat 'LOOP BACK TO THE PREVIOUS OPENING BRACKET
)
;===============================================
#endv 'END LIST VIEWING WINDOW
function=v
end function
fun 2
terminate
"
msgbox 0,o2_view src
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
Hi Charles,
this piece of assembler is a high score.
you can write your score and your name into
a spreadsheet.
you must still the spreadsheet to display.
This for fifty levels.
each table has 8 names and 8 score data.
Here the whole code therefor:
Lev dd 1
Score dw 0
HsData dw 400 dup(0)
Names db 3200 dup('?')
xName db 'PETER ',0
proc WriteHighScore
mov edi,HsData
xor edx,edx
mov esi,[lev]
dec esi
imul esi,16
mov ax,[Score]
add edi,esi
s1: cmp [edi+edx],ax
jae s2
mov [edi+edx],ax
call SetNames
ret
s2: add edx,2
cmp edx,16
jnz s1
ret
endp
proc SetNames
xor ebx,ebx
mov edi,Names
mov esi,[lev]
dec esi
imul esi,64
add edi,esi
s3: mov al,[xName+ebx]
cmp edx,0
jnz s7
mov [edi+ebx],al
s7: cmp edx,2
jnz s8
mov [edi+ebx+8],al
s8: cmp edx,4
jnz s9
mov [edi+ebx+16],al
s9: cmp edx,6
jnz s10
mov [edi+ebx+24],al
s10: cmp edx,8
jnz s11
mov [edi+ebx+32],al
s11: cmp edx,10
jnz s12
mov [edi+ebx+40],al
s12: cmp edx,12
jnz s13
mov [edi+ebx+48],al
s13: cmp edx,14
jnz s14
mov [edi+ebx+56],al
s14: inc ebx
cmp ebx,8
jnz s3
ret
endp
Peter
Charles Pegge
13-07-2009, 20:13
Hi Peter
Here is a quick Oxygen translation. You can see the differences where I have commented out your original code. Oxygen uses relocatable (pointered memory) for all its variables and does not use fixups. The variables here are all stack based. Static variables in Oxygen are based on offsets of the esi register - so further coding would be needed to map some of these variables into persistent memory.
Charles
uses "oxygen", "file"
dim src as string
'--------------------------------
'
'================================
src = "
#basic
'-------------------------
function scoring() as long
'=========================
'THESE ARE STACK BASED LOCALS [ebp-4] ... [ebp-??]
dim Lev ' Lev dd 1
dim Score ' Score dw 0
dim HsData(400) ' HsData dw 400 dup(0)
dim Names(3200) as zstring ' Names db 3200 dup('?')
dim xName(32) as zstring ' xName db 'PETER ',0
xName=`PETER`
pushad
call proc_WriteHighScore
popad
exit function
;-------------------
proc_WriteHighScore:
;===================
lea edi,HsData 'mov edi,[HsData]
xor edx,edx
mov esi,lev
dec esi
imul esi,esi,16 'imul esi,16
mov ax,Score
add edi,esi
s1: cmp [edi+edx],ax
jae s2
mov [edi+edx],ax
call proc_SetNames
s2: add edx,2
cmp edx,16
jnz s1
ret
endp:
;-------------
proc_SetNames:
;=============
xor ebx,ebx
lea edi,Names 'mov edi,[Names]
mov esi,lev
dec esi
imul esi,esi,64 'imul esi,64
add edi,esi
s3: lea eax,xName ' mov al,[xName+ebx]
mov al,[eax+ebx]
cmp edx,0
jnz s7
mov [edi+ebx],al
s7: cmp edx,2
jnz s8
mov [edi+ebx+8],al
s8: cmp edx,4
jnz s9
mov [edi+ebx+16],al
s9: cmp edx,6
jnz s10
mov [edi+ebx+24],al
s10: cmp edx,8
jnz s11
mov [edi+ebx+32],al
s11: cmp edx,10
jnz s12
mov [edi+ebx+40],al
s12: cmp edx,12
jnz s13
mov [edi+ebx+48],al
s13: cmp edx,14
jnz s14
mov [edi+ebx+56],al
s14: inc ebx
cmp ebx,8
jnz s3
ret
endp:
;---------------------------
end function
scoring
print `ok`
terminate
"
'file_save ("t.txt",o2_prep src )
'file_save ("t.txt",o2_view src )
'msgbox 0,o2_view src
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
Hi Charles,
why i get this message ?
#basic !! Unidentified: #basic.
AFTER: stt_
Peter
Petr Schreiber
13-07-2009, 21:04
You probably do not have latest Oxy,
get it here http://community.thinbasic.com/index.php?topic=2517.msg18970#msg18970
and copy to Lib folder of your thinBasic installation.
Lionheart008
13-07-2009, 22:50
@all ;) thank you too (petr, peter) , so my question about the scoring oxygen script was replied what I have made to run with my question this morning ;) that's the way I like and love thinbasic and this forum ! perhaps you know this kind of feeling too, if you are curious to get new inputs and making experiments... and then one ball hit another one... I am laughing.. I have made some exercises for oxygen too to see what happened with "fun" and / or "scoring" functions.. special thanks to charles...
nice evening, Lionheart
Lionheart008
15-07-2009, 09:49
hi all, hi charles...
have tested a new assembling code part and my little test works fine here...
uses "oxygen"
dim src as string
'--------------------------------
'USING BASIC INSIDE ASSEMBLY CODE
'================================
src = "
#basic
'----------------------------------
function lion(byval v as long) as long
'==================================
'ASSEMBLY CODE MUST NOT OVERWRITE THE ESI & EBX REGISTERS
'AS THESE ARE NEEDED BY OXYGEN BASIC
mov ecx,3 'NUMBER OF LOOPS
edx=v 'VALUE TO PROCESS
#view 'LIST VIEWING WINDOW
;==============================================
(
dec ecx 'DOWNCOUNT
jl exit 'JUMP OVER NEXT CLOSING BRACKET
imul edx,edx 'SQUARE
pushad 'SAVE ALL REGISTERS
'---------
v=edx 'DO SOME BASIC ..
print str V
'---------
popad 'RESTORE REGISTERS
repeat 'LOOP BACK TO THE PREVIOUS OPENING BRACKET
)
;===============================================
#endv 'END LIST VIEWING WINDOW
function=v
end function
Lion 2
dim a,b
a=Lion 42
b= Lion 12
print `all is ok with my lion`
print `lionpower: `+ a
print `more lionpower: `+ b
terminate
'----------------------------------
function maria(byval k as long) as long
'==================================
mov ecx,2 'NUMBER OF LOOPS
edx=k 'VALUE TO PROCESS
#view 'LIST VIEWING WINDOW
;==============================================
(
dec ecx 'DOWNCOUNT
jl exit 'JUMP OVER NEXT CLOSING BRACKET
imul edx,edx 'SQUARE
pushad 'SAVE ALL REGISTERS
'---------
k=edx 'DO SOME BASIC ..
print str k
'---------
popad 'RESTORE REGISTERS
repeat 'LOOP BACK TO THE PREVIOUS OPENING BRACKET
)
;===============================================
#endv 'END LIST VIEWING WINDOW
function=k
end function
Maria 4
dim c,d
c=Maria 12
d= Maria 18
print `all is ok with Maria`
print `marias shopping power: `+ c
print `more maria power by shopping: `+ d
terminate
"
msgbox 0,o2_view src
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
question: the lines after #view, I can here include other asm code calculations, isn't it ? and it's necessary to uses brackets ?
thank you for this little asm example some posts before :)
best regards, Lionheart
Charles Pegge
15-07-2009, 23:31
Hi Frank,
The round brackets are used to define the boundaries of the loop. They are low level markers and Basic also uses them internally to express while..wend and if .. then .. else .. end if and all the other program control constructs.
The semicolon is used to denote a comment, similar to ' only they will show up in a #view listing.
Charles
Lionheart008
16-07-2009, 17:30
hi charles, hi all :)
I tried again to include asm code for an oxygen script, they should write one byte to an port... (out) and read this byte (in)... I am not sure, but there might be only one or two little mistake.. (see the error messages! ;) ), so the script can run... perhaps you can check the in-out script, would be nice... so I have understood this little chapter one percent more than yesterday, I hope so ;)
'- in and out oxygen test script by lionheart :)
uses "console", "oxygen"
dim src as string
src = "
#basic
sub thinb_Out (byval port as long, byval value1 as byte)
movw dx, [port]
movb al, [value1]
outb dx, al
end sub
function thinb_In (byval port as long, byval k as long) as long
dim value1 as byte
movw dx, [port]
inb al, dx
mov [value1], al
return value1
end function
thinb_in 1
dim a,b
a= thinb_in 2
b= thinb_in 3
'print `all is ok with in and out progress` + b
terminate
"
msgbox 0,o2_view src
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
best regards, Lionheart
Charles Pegge
16-07-2009, 19:05
Hi Frank,
I've corrected the code (removing square brackets and changing movb and movw to mov. Differences in Assembler notation).
It compiles correctly now but GPFs because you are trying to access a forbidden area. I am unfamiliar with PC I/O and it's mappings. Unless you are writing custom device drivers this is normally left entirely to the BIOS which mediates between the operating system and the PC hardware.
Charles
'--------------------------------
'
'================================
uses "console", "oxygen"
dim src as string
src = "
#basic
sub thinb_Out (byval port as long, byval value1 as long)
mov dx, port
mov al, value1
out dx,al
end sub
function thinb_In (byval port as long) as long
dim value1 as byte
mov dx, port
in al, dx
mov value1, al
mov function,al
end function
thinb_in 1
dim a,b
a= thinb_in 2
b= thinb_in 3
'print `all is ok with in and out progress` + b
terminate
"
msgbox 0,o2_view src
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
Charles Pegge
18-07-2009, 11:47
Reverse Bits
Thanks to Frank for this example. (ported from FreeBasic)
Just had to protect the ebx register since it is used in the assembly code.
Charles
uses "oxygen"
dim src as string
src = "
#basic
Function reversebits(Byval number1 As Integer, Byval bits As Integer) as long
push ebx ' PROTECT EBX FOR BASIC
Xor eax, eax ' eax = result
mov ecx, bits ' ecx = bits
cmp ecx, 0
jle label3
mov ebx, number1 ' ebx = number
'------
label2:
'------
mov edx, ebx ' edx = number
Shl eax, 1 ' result <<= 1
And edx, 1 ' edx = number & 1
Shr ebx, 1 ' ebx = number >> 1
Or eax, edx ' eax = result | (number & 1)
Sub ecx, 1 ' bits--
jnz label2 ' if (bits) goto label2
'------
label3:
'======
pop ebx ' RESTORE EBX
mov Function, eax
End Function
dim a,b
'------
'INPUTS
'======
a=&h3 ' BIT PATTERN
b=&h8 ' NUMBER OF BITS IN BIT PATTERN
print `reverse bits in ` hex(a) ` width ` hex(b) ` >> ` hex(reversebits a,b)
terminate
"
'msgbox 0,o2_view src
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
Lionheart008
31-07-2009, 00:13
hi charles, mr. dark oxygen magic :D
here's perhaps some interesting code for you for cpu detection, I have found it this morning from freebasic example and perhaps you can adept it for oxygen ;)
uses "oxygen", "console"
dim src as string
src = "
#basic
'CPU speed
Dim start64,diff64 as long 'Ulongint
Dim starttimer,onesecond as Single
onesecond = 1.0045
'get timer
starttimer = Timer
'CPU Counter catching
rdtsc
mov dword Ptr [start64], eax
mov dword Ptr [start64+4], edx
'wait one second
While (timer-starttimer)<onesecond:Wend
'CPU Counter reading again
rdtsc
'get the difference
mov ebx, eax
mov eax, edx
Sub ebx, dword Ptr [start64]
sbb eax, dword Ptr [start64+4]
mov dword Ptr [diff64], ebx
mov dword Ptr [diff64+4], eax
'Difference divide per 1 millions
mov ecx, 1000000
mov eax, ebx
cdq
idiv ecx
mov dword Ptr [diff64], eax
print ` CPU Speed `, Str$(diff64), " MHz."
terminate
"
msgbox 0,o2_view src
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
wish you a nice evening, cheerio, Lionheart
ps: see also: http://community.thinbasic.com/index.php?topic=2824.msg21326;topicseen#new
(petr called you 'dark master' - really nice nick name ;) )
John Spikowski
31-07-2009, 01:49
Once I figure out what Charles's avatar is all about, I'll take a shot at Oxygen. :)
Charles Pegge
31-07-2009, 07:35
I happen to be wearing a black hat today. (but not a pointy one)
The example below uses the microtimer to measure performance: You can try commenting out the idiv line and enabling one of the other lines or just see how the empty loop performs. (division is usually many times slower than all other arithmetical operations).
On my PC the empty assembly code loop runs about 1 billion cycles per second - about three times faster than the empty for..nextloop.
Charles
'------------------------
'MEASURING EXECUTION TIME
'========================
uses "oxygen"
dim src as string
src = "
#basic
DECLARE FUNCTION QueryPerformanceCounter LIB `KERNEL32.DLL` ALIAS `QueryPerformanceCounter` (lpPerformanceCount AS QUAD) AS LONG
DECLARE FUNCTION QueryPerformanceFrequency LIB `KERNEL32.DLL` ALIAS `QueryPerformanceFrequency` (lpFrequency AS QUAD) AS LONG
dim as quad t1,t2,fr
QueryPerformanceCounter t1
dim i,e
e=1E6 'NUMBER OF LOOPS
'-------------------
'CODE BEING MEASURED
'===================
'
'for i=1 to e
'next
mov ecx,e
mov edi,100
(
mov eax,ecx : mov edx,0 : idiv edi
'mov eax,ecx : mov edx,0 : imul edi
'mov eax,ecx : mov edx,0 : add eax,edi
dec ecx : jge repeat
)
'===================
QueryPerformanceCounter t2
QueryPerformanceFrequency fr
dim as double c,d
d=(t2-t1)/fr
c=round(e/d)
print `
Loops: ` e ` Exec time: ` d `
Loops per second ` c `
`
terminate
"
'msgbox 0,o2_view src
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
Petr Schreiber
31-07-2009, 09:10
My results:
Type of loopLoops/second
Assembly
902 330 479
Oxygen
267 729 619
ThinBASIC
9 700 356
MED Script
:lol: 32 000
MED script is my own scripting engine for 3D editor ModelEd I stopped developing in 2005.
I cannot believe with this speed I used it to render animations :)
Petr