Author Topic: DLLC  (Read 26899 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
DLLC
« on: October 31, 2014, 11:37:29 PM »
Hi John, Mike

There are a number of DLLCO2 examples in ProjectsB/ScriptBasic/DLLC/

They require Oxygen for JIT compiling, as well as DLLC.

I'll zip the whole folder below, since I've been editing a few of the examples.

Here is a piece of Assembly code working in SB. It is treated just like any other o2 function source code.

dllco2_EAsm
Code: [Select]

  include "dllcinc.sb"

  oxy=dllfile("/scriptbasic/modules/oxygen.dll")

  o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )
  o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )
  o2_error = dllproc( oxy, "o2_error c*=()         " )
  o2_errno = dllproc( oxy, "o2_errno i =()         " )
  o2_len   = dllproc( oxy, "o2_len   i =()         " )
  o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " )

  dllcall o2_mode,1

' ==============================
  src="""
  extern

  function reverse(char*s)
  ========================
  addr ecx,s
  mov edx,0
 .rlen
  mov al,[ecx]
  cmp al,0
  jz xlen
  inc edx
  inc ecx
  jmp rlen
 .xlen
  ;
  addr ecx,s
  add  edx,ecx
  dec ecx
  ;
 .rswap
  inc ecx
  dec edx
  cmp edx,ecx
  jle xswap
  mov al,[ecx]
  mov ah,[edx]
  mov [ecx],ah
  mov [edx],al
  jmp rswap
 .xswap
  end function

  sub finish()
  terminate
  end sub

  function link(sys n) as sys
  select n
  case 0 : return @finish
  case 1 : return @reverse
  end select
  end function

  end extern
 

  addr link
  """
' ==============================

  function oxygen(src)
  dllcall o2_basic,src
  if (dllcall(o2_errno)<>0) then
    dllprnt dllcall(o2_error)
    a=0
  else
    a=dllcall(o2_exec,0)
  end if
  oxygen=a
  end function
  '
  a=oxygen(src)
  '
  if (a<>0) then
  '
' ==============================
  '
  Finish  = dllproc(a,"Finish     ()        ", dllcald(a,0) )
  Reverse = dllproc(a,"Reverse    (c*value) ", dllcald(a,1) )
  '
' ==============================
  '
  s="abcdef1234567"
  print "Reversed " & s & " = "
  dllcall(Reverse,s)
  print s & "\n"
  dllcall(Finish)
  '
  end if
  dllfile
  line input q





.
« Last Edit: November 01, 2014, 12:12:07 AM by Charles Pegge »

JRS

  • Guest
Re: DLLC
« Reply #1 on: October 31, 2014, 11:41:27 PM »
Too cool Charles, thanks!

Off to the playground.  :)

It works!


C:\OxygenBasic\projectsB\ScriptBasic\DLLC>scriba dllco2_EAsm.sb
Reversed abcdef1234567 = 7654321fedcba

C:\OxygenBasic\projectsB\ScriptBasic\DLLC>
« Last Edit: November 01, 2014, 12:02:54 AM by John »

Charles Pegge

  • Guest
Re: DLLC
« Reply #2 on: November 01, 2014, 12:06:03 AM »
To simplify the example, there is an include file for Oxygen: DLLCO2.sb. It takes care of Oxygen setup.

DLLCO2.sb
Code: [Select]
  include "dllcinc.sb"

  oxy=dllfile("/scriptbasic/modules/oxygen.dll")

  o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )
  o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )
  o2_error = dllproc( oxy, "o2_error c*=()         " )
  o2_errno = dllproc( oxy, "o2_errno i =()         " )
  o2_len   = dllproc( oxy, "o2_len   i =()         " )
  o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " )

  dllcall o2_mode,1

  function oxygen(src)
  dllcall o2_basic,src
  if (dllcall(o2_errno)<>0) then
    dllprnt dllcall(o2_error)
    a=0
    line input q
  else
    a=dllcall(o2_exec,0)
  end if
  oxygen=a
  end function

Example now simplified:

dllco22_EAsm.sb
Code: [Select]

  include "DLLCO2.sb"

' ==============================
  src="""
  extern

  function reverse(char*s)
  ========================
  addr ecx,s
  mov edx,0
 .rlen
  mov al,[ecx]
  cmp al,0
  jz xlen
  inc edx
  inc ecx
  jmp rlen
 .xlen
  ;
  addr ecx,s
  add  edx,ecx
  dec ecx
  ;
 .rswap
  inc ecx
  dec edx
  cmp edx,ecx
  jle xswap
  mov al,[ecx]
  mov ah,[edx]
  mov [ecx],ah
  mov [edx],al
  jmp rswap
 .xswap
  end function

  sub finish()
  terminate
  end sub

  function link(sys n) as sys
  select n
  case 0 : return @finish
  case 1 : return @reverse
  end select
  end function

  end extern
 

  addr link
  """
' ==============================

  '
  a=oxygen(src)
  '
  if (a<>0) then
  '
' ==============================
  '
  Finish  = dllproc(a,"Finish     ()        ", dllcald(a,0) )
  Reverse = dllproc(a,"Reverse    (c*value) ", dllcald(a,1) )
  '
' ==============================
  '
  s="abcdef1234567"
  print "Reversed " & s & " = "
  dllcall(Reverse,s)
  print s & "\n"
  dllcall(Finish)
  '
  end if
  dllfile
  line input q
« Last Edit: November 01, 2014, 12:16:52 AM by Charles Pegge »

JRS

  • Guest
Re: DLLC
« Reply #3 on: November 01, 2014, 12:34:59 AM »
Sweet!

Who needs an Olly mess on your hands.  ;D

JRS

  • Guest
Re: DLLC
« Reply #4 on: November 01, 2014, 12:46:04 AM »
Charles,

The new sweet version went sour. :-(

1. You need to REM all your =================== lines.

2.
C:\OxygenBasic\projectsB\ScriptBasic\DLLC>scriba dllco2_EAsm.sb
 ; ASM ERR:     rlen!!  Unidentified instruction: rlen
 ; AFTER:       .reverse#char
 ; LINE:        8



Charles Pegge

  • Guest
Re: DLLC
« Reply #5 on: November 01, 2014, 12:55:01 AM »
John, could you ensure that you have a recent Oxygen.dll in ScriptBasic/modules

http://www.oxygenbasic.org/o2zips/Oxygen.zip

JRS

  • Guest
Re: DLLC
« Reply #6 on: November 01, 2014, 01:02:09 AM »
Only thing I did was update the two programs you posted. It worked before.

Returning back to the (saved) original SB include and script works fine.

I updated the oxygen.dll (just downloaded the WIP ZIP a couple hours before) and no change. Original works, updated doesn't.
« Last Edit: November 01, 2014, 01:35:13 AM by John »

JRS

  • Guest
Re: DLLC
« Reply #7 on: November 01, 2014, 01:51:06 AM »
Stop Debugging!

My FU!!!

I trimmed off the leading indent and I must of chopped something off. The missing REM should have been a clue.

Sorry!

Charles Pegge

  • Guest
Re: DLLC
« Reply #8 on: November 01, 2014, 02:25:50 AM »
John, Did you trim off the .rlen dot ? :)

Mike Lobanovsky

  • Guest
Re: DLLC
« Reply #9 on: November 01, 2014, 08:20:18 AM »
John, Did you trim off the .rlen dot ? :)

;D

I suggest we move all our ASM exercises from now on to the ScriptBASIC forum as a retribution for John's recent attempts to prosecute assembly on BASIC sites. He's been found guilty of illegal possession of this drug in his SB in massive quantities.

JRS

  • Guest
Re: DLLC
« Reply #10 on: November 01, 2014, 09:18:30 AM »
Thanks again Charles for the refresh on just how powerful the DLLC extension module is. I have only tapped a small portion of it's ability.

1 + 1 = 3 (If you don't use a condom)   :o

Just noticed the t.txt hooker tease. Helpful!

.
« Last Edit: November 01, 2014, 11:23:14 AM by John »

Aurel

  • Guest
Re: DLLC
« Reply #11 on: November 01, 2014, 12:00:23 PM »
Quote
Original works, updated doesn't.
and what is new ?....
I constantly have a feeling that oxygen is in wrong direction....

JRS

  • Guest
Re: DLLC
« Reply #12 on: November 01, 2014, 12:04:04 PM »
Quote
I constantly have a feeling that oxygen is in wrong direction....

Thanks Aurel for your conformation Charles is on the right path. (white is black, good is evil, ...)

@Mike - prosecute assembly? Do you mean prostitute assembly?

Mike Lobanovsky

  • Guest
Re: DLLC
« Reply #13 on: November 01, 2014, 12:19:32 PM »
@Mike - prosecute assembly? Do you mean prostitute assembly?

No John, I mean the former. I've just recalled some recent message of yours where you would wonder what the purpose of discussing assembly at a BASIC forum was. Noone realized at that time that SB itself was in a state of secret liaison with the subject... ;)

Quote
Just noticed the t.txt hooker tease.

I remember perfectly well that my message #666 was addressed to the late Mr.Vidlanovic. ;D

JRS

  • Guest
Re: DLLC
« Reply #14 on: November 01, 2014, 12:28:08 PM »
Quote from: Mike
Noone realized at that time that SB itself was in a state of secret liaison with the subject...

Quote from: Mike
you would wonder what the purpose of discussing assembly at a BASIC forum was.

That topic got started when Rob and I were discussing how some people make simple tasks look difficult to presume self worth. Probably should of just let it go.

DLLC has been around for some time now as SB's O2 super hero. I just wasn't clear where Charles stood with in-line ASM. I don't have official approval from Charles but I coined the JIT function in SB as a Virtual DLL. To me that is the easiest way to explain its use. As icing, DLLC can run them in a thread.  8)
« Last Edit: November 01, 2014, 09:25:40 PM by John »