Page 1 of 4 123 ... LastLast
Results 1 to 10 of 35

Thread: O2 - some basic questions

Share/Bookmark
  1. #1
    thinBasic MVPs ReneMiner's Avatar
    Join Date
    Oct 2012
    Location
    Germany
    Age
    47
    Posts
    1,214
    Blog Entries
    1
    Rep Power
    132

    Oxygen - some basic questions

    A couple of questions, hopefully someone has an answer to one or another.

    I think it's possible to run a few different O2-scripts from within one tB-script - at least I hope so. All examples I've studied use only one script once.

    So the first question would be: Is there any limit?

    When do I have to terminate an O2-script?

    And I want to know if it's possible to pass the source-string "src" also as a pointer from tB. Instead
    O2_Basic src
    
    it would be great if it were possible to pass the pointer of - for example some dictionary-bucket so I could 'feed' O2 just by passing some dictionary-keyname alike this:
    O2_BasicAt StrPtr(src)
    '...
    O2_BasicAt Peek(Dword, Dictionary_Exists(my02DrawingDict, "mandelbrot"))
    O2_BasicAt Peek(Dword, Dictionary_Exists(my02DrawingDict, "pyramids"))
    
    O2_BasicAt Peek(Dword, Dictionary_Exists(my02CollisionDict, "face2face"))
    O2_BasicAt Peek(Dword, Dictionary_Exists(my02CollisionDict, "face2point"))
    '...
    O2_BasicAt myStrPtr ' whereever - as long as valid stringpointer
    ' over the top:
    O2_BasicAt myPtr, SizeInBytes ' so could use Heap or any other memory to store different scripts
    
    is there such method? Only clue I have is thinBasic_keywords.ini which lists:
    O2_ASM
    O2_ASMO
    O2_ASMO_FILE
    O2_ASM_FILE
    O2_BASIC *
    O2_BUF
    O2_ERROR
    O2_EVAL *
    O2_EXEC
    O2_GET
    O2_LEN
    O2_LINK
    O2_PREP *
    O2_PUT
    O2_VIEW
    O2_VIEW_FILE
    OXYGEN_EVAL - suppose, has been replaced with O2_Eval ?
    * = no documentation found

    ...or would it be better to have all those example functions in the code above (drawing, collision) in one big O2-script that stays permanently "alive" as long as my tB-script runs?
    Last edited by ReneMiner; 21-07-2013 at 13:20.
    Windows 10 on
    Desktop: Intel Core i5-3330 @3.0 GHz, 8 GB Ram, nVidia GeForce GT630 2 GB
    Laptop: Intel Core i3-4005U @1.7GHz, 8 GB Ram, nVidia GeForce 940M 2 GB


    The limit is Imagination

  2. #2
    thinBasic MVPs ReneMiner's Avatar
    Join Date
    Oct 2012
    Location
    Germany
    Age
    47
    Posts
    1,214
    Blog Entries
    1
    Rep Power
    132
    How to Peek something from memory using oxygen?

    Uses "oxygen", "console"
    Alias Memory_Get As Get$
    Alias Long As FunctionPtr
    
    FunctionPtr P_O2End, P_GetPtr
    
    
    If Not run_O2() Then  
      PrintL "error within O2-script - can not run this"
      PrintL O2_ERROR
      WaitKey
      Stop
    EndIf
    
    Declare Sub finish() At P_O2End
    Declare Function GetPtr(ByVal String, Optional ByVal Long, Optional ByVal Long) As DWord At P_GetPtr
    
    ' some testing:
    Long foo = 123
    DWord myPtr = GetPtr("foo")
     
    PrintL "foo = " + CVL(Get$(myPtr, SizeOf(Long)))
    
    Dim dog(123) As Byte
    dog(42) = 42  
    
    myPtr = GetPtr("dog", 42, SizeOf(Byte))
    Dim olk(77) As Double
    olk(33) = CVBYT(Get$(myPtr, SizeOf(Byte))) + 0.125
    
    PrintL "olk(33) = " + CVD(Get$(GetPtr("olk", 33, SizeOf(Double)), SizeOf(Double)))
    
    String test = "I am an important string"
    myPtr = GetPtr("test")
    PrintL "memory found:" + Get$(myPtr, Peek(DWord, myPtr - 4))
    
    WaitKey
    finish()
    
    '----------------------------------------------
    Function run_O2() As Boolean
    
    Local src As String = "
      #basic
      include "thincore.inc" 
      
      Function GetPtr(Byval sName as String, Optional ByVal Index as Long, Optional Byval lSize as Long) As Dword link #P_GetPtr
        Long MainType, SubType, IsArray, DataPtr, nElements
        
        thinBasic_VariableGetInfoEX(sName, MainType, SubType, IsArray, DataPtr, nElements)
        If Index > 0 And Index <= nElements then
          If MainType = 30 Then ' string
            Function = *( DataPtr + (Index - 1) * 4) 
          Else
            Function =  DataPtr + (Index - 1) * lSize    
          EndIf
        Else
          If MainType = 30 Then ' string
             Function = *DataPtr 
          Else
            Function = DataPtr    
          EndIf
        EndIf                      
      End Function
      
      
      '------------------------------------------
      Sub finish() link #P_O2End
        terminate
      End Sub     
    "
    
    
      O2_BASIC src
      If O2_ERROR <> "" Then Return FALSE
      O2_EXEC
      
      Function = TRUE
      
    End Function
    
    Edit:Script corrected - returns pointers now for any thinBasic-variable-name passed as string
    Last edited by ReneMiner; 21-07-2013 at 18:27.
    Windows 10 on
    Desktop: Intel Core i5-3330 @3.0 GHz, 8 GB Ram, nVidia GeForce GT630 2 GB
    Laptop: Intel Core i3-4005U @1.7GHz, 8 GB Ram, nVidia GeForce 940M 2 GB


    The limit is Imagination

  3. #3
    Peeking longs and dwords can be done using the '*' pointer operator

    sys dat,adr
    string s="12345678"


    adr=strptr s
    print hex *(adr+4) 'result 38373635

    For more structured peeking, use an array overlay at...

    string s="12345678"


    long d at (strptr s)
    print hex d[2] 'result 38373635


    byte b at (strptr s)
    print hex b[5] 'result 35
    Last edited by Charles Pegge; 21-07-2013 at 15:07.

  4. #4
    thinBasic MVPs ReneMiner's Avatar
    Join Date
    Oct 2012
    Location
    Germany
    Age
    47
    Posts
    1,214
    Blog Entries
    1
    Rep Power
    132
    thanks. the idea to use an overlay came to me already but I think it's good to know some "GetDataAt-method" as *
    "sys" some alias for 'Dword' to store pointers?

    PS. instead of reposting the correct script now I just changed the one above
    Last edited by ReneMiner; 21-07-2013 at 15:28.
    Windows 10 on
    Desktop: Intel Core i5-3330 @3.0 GHz, 8 GB Ram, nVidia GeForce GT630 2 GB
    Laptop: Intel Core i3-4005U @1.7GHz, 8 GB Ram, nVidia GeForce 940M 2 GB


    The limit is Imagination

  5. #5
    Sys is a signed integer that is safe to use as a pointer. When compiling 64 bit binaries, it becomes 64 bits wide, whereas long, dword and int remain 32 bit integers.

  6. #6
    thinBasic MVPs ReneMiner's Avatar
    Join Date
    Oct 2012
    Location
    Germany
    Age
    47
    Posts
    1,214
    Blog Entries
    1
    Rep Power
    132
    ah, ok. there seems something not to work as I wish it would... I repost the changed script here - the line which makes it crash is commented (line-number 42) - oh what coincidence... perhaps I have made something wrong in line 61 with that * ?

    Problem seems to be that the pointers of a string-array are not there where I thought they would be. Straight in a row of Dwords starting at DataPtr...
    Uses "oxygen", "console"
    
    Alias Long As FunctionPtr
    
    FunctionPtr P_O2End, P_GetPtr
    
    
    If Not run_O2() Then  
      PrintL "error within O2-script - can not run this"
      PrintL O2_ERROR
      WaitKey
      Stop
    EndIf
    
    Declare Sub finish() At P_O2End
    Declare Function GetPtr(ByVal String, Optional ByVal Long, Optional ByVal Long) As DWord At P_GetPtr
    
    ' some testing:
    Long foo = 123
    DWord myPtr = GetPtr("foo")
     
    PrintL "foo = " + CVL(Memory_Get(myPtr, SizeOf(Long)))
    
    Dim dog(123) As Byte
    dog(42) = 42  
    
    myPtr = GetPtr("dog", 42, SizeOf(Byte))
    Dim olk(77) As Double
    olk(33) = CVBYT(Memory_Get(myPtr, SizeOf(Byte))) + 0.125
    
    PrintL "olk(33) = " + CVD(Memory_Get(GetPtr("olk", 33, SizeOf(Double)), SizeOf(Double)))
    
    String test = "I am an important string"
    myPtr = GetPtr("test")
    PrintL "memory found:" 
    PrintL Memory_Get(myPtr, Peek(DWord, myPtr - 4))  
    
    Dim s2(5) As String = "wrong", "wrong", "right", "wrong", "wrong"
    
    myPtr = GetPtr("s2", 3)
    PrintL "memory found:" 
    ' This crashes >>> PrintL Memory_Get(myPtr, Peek(DWord, myPtr - 4))
    
    WaitKey
    finish()
    
    '----------------------------------------------
    Function run_O2() As Boolean
    
    Local src As String = "
      #basic
      include "thincore.inc" 
      
      Function GetPtr(Byval sName as String, Optional ByVal Index as Long, Optional Byval lSize as Long) As Dword link #P_GetPtr
        long MainType, SubType, IsArray, DataPtr, nElements
        
        thinBasic_VariableGetInfoEX(sName, MainType, SubType, IsArray, DataPtr, nElements)
        If Index > 0 And Index <= nElements then
          If MainType = 30 Then ' string 
        '   print "String Array Check"
            Function = *(DataPtr + (Index-1) * SizeOf(Dword))  
          Else
            Function = DataPtr + (Index - 1) * lSize    
          EndIf
        Else
          If MainType = 30 Then ' string
            Function = *DataPtr 
          Else
            Function = DataPtr    
          EndIf
        EndIf                      
      End Function
      
      
      '------------------------------------------
      Sub finish() link #P_O2End
        terminate
      End Sub     
    "
    
    
      O2_BASIC src
      If O2_ERROR <> "" Then Return FALSE
      O2_EXEC
      
      Function = TRUE
      
    End Function
    
    and I still don't know how I could place some dword-array [nElements] at DataPtr - anyhow I try - error
    dword sPtrs[nElements] at DataPtr - error invalid constant autodim,
    the method in line 61 is not correct - I tested the result from thinBasic where I can find the Stringpointers in order as awaited and it returns wrong values.
    Last edited by ReneMiner; 21-07-2013 at 17:31.
    Windows 10 on
    Desktop: Intel Core i5-3330 @3.0 GHz, 8 GB Ram, nVidia GeForce GT630 2 GB
    Laptop: Intel Core i3-4005U @1.7GHz, 8 GB Ram, nVidia GeForce 940M 2 GB


    The limit is Imagination

  7. #7
    Member zlatkoAB's Avatar
    Join Date
    Apr 2008
    Age
    48
    Posts
    282
    Blog Entries
    1
    Rep Power
    38
    anyhow I try - error
    heh it looks that you trying to use wrong variable type but is not clear to me
    because code is mix of oxygen & thinBasic...
    Do you can use oxygen only code?

  8. #8
    thinBasic MVPs ReneMiner's Avatar
    Join Date
    Oct 2012
    Location
    Germany
    Age
    47
    Posts
    1,214
    Blog Entries
    1
    Rep Power
    132
    Quote Originally Posted by zlatkoAB View Post
    ...Do you can use oxygen only code?
    Sorry - I wouldn't know how - even after downloading oxygen-basic now...
    Problem is, I get on string-arrays the first elements pointer returned correct from O2 if I use just
    Function = DataPtr
    
    (line 61)

    and peek the desired Index from thinBaisc side correct like
    correctStrPtr = Peek(Dword, GetPtr("myvar",1) + (Index-1) * SizeOf(Dword))
    
    but
    Function = *( DataPtr + (Index-1) * SizeOf(Dword) )
    
    does not return the expected value. Maybe I've misunderstood the use of * ?
    Last edited by ReneMiner; 21-07-2013 at 18:18.
    Windows 10 on
    Desktop: Intel Core i5-3330 @3.0 GHz, 8 GB Ram, nVidia GeForce GT630 2 GB
    Laptop: Intel Core i3-4005U @1.7GHz, 8 GB Ram, nVidia GeForce 940M 2 GB


    The limit is Imagination

  9. #9
    Member zlatkoAB's Avatar
    Join Date
    Apr 2008
    Age
    48
    Posts
    282
    Blog Entries
    1
    Rep Power
    38
    Rene
    I am confused with what you trying to do ...
    what a heck is sizeOf(dWord) - i am not sure but i think that is not posible
    get size of reserved variable type as is DWORD...

    You say that you have oxygen - then try first directly in oxygen then if work
    properly tray in thinBasic...
    And what is not clear to you when you use Oxygen?

  10. #10
    thinBasic MVPs ReneMiner's Avatar
    Join Date
    Oct 2012
    Location
    Germany
    Age
    47
    Posts
    1,214
    Blog Entries
    1
    Rep Power
    132
    I'm trying to use oxygen to manipulate thinBasic-variables.

    SizeOf(Dword) should return the size of one element of variable type dword - can replace with 4 but won't help

    Imagine a data-bound listview, that shall for example display a phone numbers list. The user tells the listview once: Hey, data for that list to find in an array-variable named "Phonelist", in first column display content of Phonelist().Name, in second column fill in the numbers found at PhoneList().Numbers. So no matter what user does with this array thereafter- the list "knows" always what and how much to display and where to find it - even if pointers change - when list gets drawn it "knows" what it has to fill in.So therefor I need a method to not just receive the correct pointers but also one to change dynamic strings without "loosing and orphaning" their pointers so my list becomes editable
    Last edited by ReneMiner; 21-07-2013 at 18:53.
    Windows 10 on
    Desktop: Intel Core i5-3330 @3.0 GHz, 8 GB Ram, nVidia GeForce GT630 2 GB
    Laptop: Intel Core i3-4005U @1.7GHz, 8 GB Ram, nVidia GeForce 940M 2 GB


    The limit is Imagination

Page 1 of 4 123 ... LastLast

Similar Threads

  1. Replies: 0
    Last Post: 14-07-2013, 17:27
  2. Questions About Focus
    By gungadout in forum thinBasic General
    Replies: 2
    Last Post: 12-11-2010, 03:44
  3. three questions
    By christianssen in forum thinBasic General
    Replies: 6
    Last Post: 10-03-2010, 11:12
  4. A few more questions..
    By oldpapa49 in forum thinBasic General
    Replies: 12
    Last Post: 21-03-2009, 21:45
  5. DT questions
    By Dave in forum DT (Date module)
    Replies: 9
    Last Post: 16-04-2008, 09:48

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •