Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 31

Thread: Further Developments in Asmosphere III

  1. #21

    Re: Further Developments in Asmosphere III


    Yes the help file needs refreshing. There have not been many additions to the basic instructions but they have acquired various enhancements over the last few months, but I think the o2_buf return was an omission.

    The code buffer has 512 places - alternatively the assembled code can be fed into strings eg
    dim sfun1 as string=o2_asm src then taking the strptr as the pointer

    Here is how to build many functions using the Oxygen buffer system

    [code=thinbasic]
    ' Asmosphere
    ' test Declare .. at

    uses "OXYGEN"

    dim src as string

    src="
    xor eax,eax
    mov al,[esp+4]
    (
    cmp al,97
    jl exit
    cmp al,122
    jg exit
    sub al,32
    )
    ret 4
    "
    o2_buf 1 : o2_asmo src

    Declare Function upper (ByVal cChar As Byte) As Long at o2_buf 1
    src="
    xor eax,eax
    mov al,[esp+4]
    (
    cmp al,65
    jl exit
    cmp al,90
    jg exit
    add al,32
    )
    ret 4
    "
    o2_buf 2 : o2_asmo src

    Declare Function lower (ByVal cChar As Byte) As Long at o2_buf 2


    msgbox 0,"uppercase of ascii 100 is "+upper (100) + $crlf + _
    "lowercase of ascii 68 is "+lower (6 + $crlf

    [/code]

  2. #22

    Re: Further Developments in Asmosphere III


    Another example for the manual:

    Around the first function, I have put a more typical framework, which involves preserving important registers, allocating workspace for local variables and giving parameters proper names to refer to. The EBX register also gets an address to the o2 runtime kernel.

    You will find that this is typical of compiled functions in other languages - but with Assembly code, if your function does not alter ebx esi or edi or use local variables then you can dispense with the overhead.

    [code=thinbasic]
    ' Asmosphere
    ' test Declare .. at

    uses "OXYGEN"

    dim src as string

    src="
    indexers `ebp` offset 8 ascending ' params
    var 4 cchar ' params passed on stack
    indexers `ebp` offset 0 descending ' locals
    var 4 a b c d ' local stack variables
    push ebp '
    mov ebp,esp ' set up local ptr
    sub esp,100 ' space for locals
    push ebx ' save vital registers
    push esi '
    push edi '
    mov ebx,KERNEL ' base address of o2 kernel funs
    ;------- start here
    mov eax,cchar
    and eax,0xff
    (
    cmp al,97
    jl exit
    cmp al,122
    jg exit
    sub al,32
    )
    ;------ restore status quo
    pop edi
    pop esi
    pop ebx
    mov esp,ebp
    pop ebp
    ret 4 ' return releasing param bytes from stack (stdcall)
    "
    o2_buf 1 : o2_asmo src
    if len(o2_error) then msgbox 0,o2_view src : stop

    Declare Function upper (ByVal cChar As Byte) As Long at o2_buf 1
    src="
    xor eax,eax
    mov al,[esp+4]
    (
    cmp al,65
    jl exit
    cmp al,90
    jg exit
    add al,32
    )
    ret 4
    "
    o2_buf 2 : o2_asmo src

    Declare Function lower (ByVal cChar As Byte) As Long at o2_buf 2


    msgbox 0,"uppercase of ascii 100 is "+upper (100) + $crlf + _
    "lowercase of ascii 68 is "+lower (6 + $crlf

    [/code]

  3. #23

    Re: Further Developments in Asmosphere III

    Adaptations for COM programmming

    The quest is to produce tidy COM in Assembler using the Oxygen OOP model. This is really more of a versatility test than a proper implementation of COM at this stage.

    One of the little problems that arose when I tried Oxygen's OOP model with COM is that multiple inheritance proved to be a mismatch, so I devised a way of indicating single inheritance using the keyword of.


    type IUnknown
    (
    4 QueryInterface (a p)
    4 AddRef ()
    4 Release()
    4 Counter
    /
    4 pvft
    )

    type IKnown
    (
    of IUnknown,
    /
    4 test_interface
    4 other_interface
    )




    To help with virtual structures and pointering, a variable can now be associated with a specific register and have a structure associated with it. Example:


    var IUnknown this [ecx]
    ...
    mov ecx,[esp+4]
    ...
    this.addref
    ...

    Class virtual table generation has also been internally simplified but apart from that not much has had to be altered. Inevitably reconfiguring the synapses to cope with the very abstract convolutions of COM is the biggest challenge.





    Oxygen Update:

    http://community.thinbasic.com/index.php?topic=1845.0


    The program below does very little other than to test the COM structures and pointering are performing correctly. An interface is switched by calling QueryInterface, with one of the GUIDs. A pointer to the new interface itest is granted. This interface is adopted then released.


    [code=thinbasic]
    ' Test COM


    uses "OXYGEN"
    uses "FILE"

    dim vv,ww as long
    dim src as string

    src="

    esi=dataspace 0x1000 ; persistent memory inline
    indexers `esi` offset 0 ascending


    type IUnknown
    (
    4 QueryInterface (a p) ; HRESULT QueryInterface( REFIID iid,void ** ppvObject)
    4 AddRef () ; ULONG AddRef(void)
    4 Release() ; ULONG Release(void)
    4 Counter
    /
    4 pvft
    )

    type IKnown
    (
    of IUnknown,
    /
    4 test_interface
    4 other_interface
    )


    ;class tables like IUnknown_table are automatically
    ;created whenever '/' is present in the type definition

    ;these interfaces are global ready-made
    var Iunknown iUnk
    var iKnown itest
    var iknown iother

    ;set pvft for each interface

    iunk.pvft =&Iunknown_table
    itest.pvft =&iknown_table
    iother.pvft =&iknown_table

    ;initialise properties

    with itest
    .test_interface=&itest
    .other_interface=&iother
    with iother
    .test_interface=&itest
    .other_interface=&iother
    with ``


    ( ; start of methods

    build IUnknown
    build Iknown

    [#vv]=itest.test_interface
    '[#ww]=i.counter

    ; create test and other interfaces

    exit

    var IKnown this [ecx]

    QueryInterface: (a p)
    (
    (
    data hl0 hw0 hw0 00 00 00 00 00 00 00 01
    mov edx,[esp+8]
    proc matchGuid edx eax
    cmp eax,0
    jz exit
    ecx=&itest
    var iknown this [ecx]
    mov ecx,this.test_interface
    jmp long matched
    )
    (
    data hl2339B54C hw3453 hw11D2 93 B9, 00, 00, 00, 00, 00, 00
    mov edx,[esp+8]
    proc matchGuid edx eax
    cmp eax,0
    jz exit
    mov ecx,[esp+4] ; self matched
    jmp long matched
    )
    (
    data hl3339B54C hw3453 hw11D2 93 B9, 00, 00, 00, 00, 00, 00
    mov edx,[esp+8]
    proc matchGuid edx eax
    cmp eax,0
    jz exit
    mov ecx,this.other_interface
    jmp long matched
    )

    unmatched: ; fall thru to here
    mov eax,[esp+12]
    mov [eax],0
    mov eax,0x80004002 ; E_NOINTERFACE
    ret 12

    matched:
    'mov ecx,[esp+4]
    this.addref
    mov eax,[esp+12]
    mov [eax],ecx ;
    mov eax,0 ; S_OK
    ret 12
    )

    AddRef: ()
    (
    mov ecx,[esp+4] ; address of this interface
    mov eax,this.pvft ; address of interface
    var Iknown i [eax]
    inc i.counter ; static counter in _table
    ret 4
    )

    Release: ()
    (
    mov ecx,[esp+4] ; address of this interface
    mov edx,this.pvft ; address of interface
    var IUnknown i [edx]
    (
    cmp i.counter,0
    jz exit
    dec i.counter ; static counter
    jnz exit
    ' counter is zero so release object here ...
    )
    ret 4
    )


    ; private function
    matchGUID: ; (pGUID1 pGUID2) as bool
    (
    push esi
    push edi
    mov esi,[esp+12]
    mov edi,[esp+16]
    mov eax,[esi]
    cmp eax,[edi]
    jnz nomatch
    add esi,4
    add edi,4
    mov eax,[esi]
    cmp eax,[edi]
    jnz nomatch
    add esi,4
    add edi,4
    mov eax,[esi]
    cmp eax,[edi]
    jnz nomatch
    add esi,4
    add edi,4
    mov eax,[esi]
    cmp eax,[edi]
    jnz nomatch
    mov eax,1
    jmp xit
    nomatch:
    mov eax,0
    xit:
    pop edi
    pop esi
    ret 8
    )

    ) ; end of methods Iknown



    ; kickstart
    ;----------
    var iunknown ii
    var 4 pi refiid
    refiid=data hl0 hw0 hw0 00 00 00 00 00 00 00 01
    ii.pvft=&iunknown_table
    ii.QueryInterface refiid &pi

    cmp eax,0 ; S_OK
    (
    jnz exit ; no interface available
    mov ecx,pi ; adopt the new interface
    var Iknown this [ecx]
    this.Release()
    )
    ret

    "
    'END OF SRC

    file_save("t.txt",o2_view(src))
    o2_asmo src
    if len(o2_error) then
    msgbox 0,"COM: "+o2_error()+o2_view (src)
    stop
    end if
    o2_exec
    msgbox 0,"0x"+hex$(vv)+$crlf+"0x"+hex$(ww)

    [/code]

  4. #24
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Further Developments in Asmosphere III



    very advanced stuff as usual, thanks Charles.

    One thing with following fragment:
    [code=thinbasic]
    with itest
    .test_interface=&itest
    .other_interface=&iother
    with iother
    .test_interface=&itest
    .other_interface=&iother
    with ``
    [/code]

    Is it legal to end two with statements with single with ``?


    Thanks,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #25

    Re: Further Developments in Asmosphere III


    Yes Petr, I have not made with a block structure. It simply holds the prefix until a new one is given or until it is nulled. This gives it considerable flexibility. With can take a whole name or part of a name involved in the assignment - anything you wish to avoid repeating. Quotes are optional but allow the possibility of prefixing several words

  6. #26
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Further Developments in Asmosphere III

    Thanks for explanation,

    so with serves again for kind of "state toggle".
    As I know it now, I understand it.
    I like state machines as well


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  7. #27

    Re: Further Developments in Asmosphere III

    The whole of Oxygen relies heavily on its global state. It has a very flat structure with lots of gotos . Breaks all the rules, but the compilation task really demands it. error trapping and reporting is very simple and its easy to climb back on the horse and continue. To get flexibility into the system, the preprocessor generates its own macros and feeds them back into the loop recursively until they resolve into assembly code.


  8. #28

    Re: Further Developments in Asmosphere III

    A few more features:

    Defs

    Defs is an efficient way to provide sets of equates. Example:

    defs key a 97 b 98 c 99 d 100 ...

    these can then be referred to a key.a key.b key.c etc


    OOP

    Private Members

    These are elements which are invisible to derived classes - but still exist in the object. So they are only accesible using methods inherited from the ancestral class.

    Any element can be made private by appending a dash (minus sign) after the element definition.


    Abstract Members

    These are denoted by any element that has a size of zero!

    Derived types must provide matching real elements to replace these before they can be used to instantiate objects. They specify the general structure of a type before getting down to specific implementations.

    These I hope complete the Oxygen OOP facilities. But there is much to explore - so many different combinations.



    Oxygen Update
    http://community.thinbasic.com/index.php?topic=1845.0



  9. #29

    Re: Further Developments in Asmosphere III

    Oxygen seems to be approaching the limit of what can be usefully added to its preprocessor. So this facility is one of the finishing touches - at least for Object Oriented Programming. I hope that after this, very few adjustments will be required to implement the next layer for high level programming, namely H2O

    Dynamic Objects

    static object:

    var myclass myobject

    dynamic object:

    var &myclass myobject


    By adding an extra level of indirection this enables objects to be created and destroyed dynamically during runtime.
    Methods can be called using the same syntax as static objects
    (currently this simplified syntax only applies to method calls not property setting)

    Using macros we can then implement new and delete, very similar to c++.


    new myclass myobject
    myobject.mymethod
    ...
    delete myobject


    Oxygen Update
    http://community.thinbasic.com/index.php?topic=1845.0


    [code=thinbasic]


    Uses "Oxygen"
    Uses "File"

    '------------------------------------------------------

    dim vv,ww as long
    dim src as string

    '------------------------------------------------------

    src="
    ; testing virtual objects
    def locals indexers ebp offset 0 descending %l push ebp %l mov ebp,esp %l sub esp,%1
    def free_locals mov esp,ebp %l pop ebp
    def workspace indexers esi offset 0 ascending %l esi=getmemory %1
    def free_workspace freememory esi

    locals 1024

    type cc 4 fn1! 4 fn2! / 4 pvt
    (
    static
    build cc
    exit

    var cc this [ecx]

    fn1:
    [#vv]=0xace1
    ret 4

    fn2:
    [#vv]=0xace2
    ret 4

    )
    def new
    (
    push edx
    var &%1 %2
    edx=getmemory sizeof %1
    [edx]=&%1_table
    mov %2,edx
    pop edx
    )

    def delete
    (
    freememory %1
    mov %1,0
    )

    new cc vo
    vo.fn1
    vo.fn2
    delete vo
    free_locals
    ret
    "
    'file_save("t.txt",o2_view (src))
    'msgbox 0,"ZM20: "+o2_error+o2_view (src) : stop
    o2_asmo src : if len(o2_error) then msgbox 0,"ZM20: "+o2_error+o2_view (src) : stop
    o2_exec : msgbox 0,"0x"+hex$(vv) : stop

    [/code]

  10. #30
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Further Developments in Asmosphere III

    Hi Charles,

    good update, with new and delete it is very easy to follow the code.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Page 3 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. Further Developments in Asmosphere I.
    By Charles Pegge in forum Legacy
    Replies: 78
    Last Post: 21-06-2008, 00:34

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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