Oxygen Basic

Information => Open Forum => Topic started by: JRS on May 26, 2013, 04:40:46 PM

Title: O2 JIT function calls
Post by: JRS on May 26, 2013, 04:40:46 PM
Charles,

Do you see anyway I can use DLLC to compile an O2 function (as a SB string) and call it from SB at runtime?

The old sbo2.dll looks like it is close. The only down side (maybe) is that SB & O2 talk via a buffer string. I'm not sure if that O2 code will even compile with the current version of OxygenBasic. (I'll give it a try.)

An example would be making the mandel() function in the JAPI Mandelbrot Set SB script an O2 compiled function generated at runtime from a SB string.

John
Title: Re: O2 JIT function calls
Post by: Charles Pegge on May 26, 2013, 08:58:34 PM
Hi John,

It should be possible to use oxygen like any other DLL. o2_mode 0..1 are used to specify that the source strings are char*, rather than bstrings. I will make an example.
Title: Re: O2 JIT function calls
Post by: JRS on May 26, 2013, 09:36:35 PM
Thank You!

This was the final installment to the DLLC masterpiece. This solves the last issue of using an interpreter. Being able to selectively compile CPU intensive tasks with O2 makes SB the dream scripting engine. IMHO.

Title: Re: O2 JIT function calls
Post by: Charles Pegge on May 28, 2013, 05:18:13 AM

Hi John,

Could you pls send a recent libscriba.dll (32 bit)
Title: Re: O2 JIT function calls
Post by: JRS on May 28, 2013, 07:17:46 AM
Just sent by e-mail.

John
Title: Re: O2 JIT function calls
Post by: Charles Pegge on May 28, 2013, 10:11:45 AM
Thanks John. I needed it for the sbembed tests.
Title: Re: O2 JIT function calls
Post by: JRS on May 28, 2013, 10:18:00 AM
Sitting on the edge of my seat!   :o

I also sent you (by e-mail) a link to the current SB 2.2 VC10 beta source.

Title: Re: O2 JIT function calls
Post by: Charles Pegge on May 28, 2013, 02:42:00 PM
Yes got it thanks.

Here is the simplest SB deployment of Oxygen:

direct execution.

  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="""

  print "Hello World!"

  """

  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)
  dllprnt "Return code: " & a & "\n"
  dllfile
  line input q
Title: Re: O2 JIT function calls
Post by: JRS on May 28, 2013, 02:57:50 PM
That looks simple enough.

Is there any changes to DLLC or Oxygen DLLs to try this?

Thanks for this great effort and contribution to the ScriptBasic project.

Title: Re: O2 JIT function calls
Post by: JRS on May 28, 2013, 03:19:28 PM
I tried your example with the current code base and it worked.

This is very cool!

(http://files.allbasic.info/ScriptBasic/o2hello.png)

Code: [Select]
include "dllcinc.sb"

oxy=dllfile("/sb22/bin/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="""

print "Hello World!"

"""

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)
dllprnt "Return code: " & a & "\n"
dllfile
line input q

C:\SB22\o2call>scriba o2c_1.sb
Return code: 0

C:\SB22\o2call>
Title: Re: O2 JIT function calls
Post by: JRS on May 28, 2013, 07:29:29 PM
Charles,

It looks like Hello World! is as far as I can go. the following (or anything else I try) produces an error.

Code: [Select]
src="""

sys x

for x = 1 to 10
next x

"""


C:\SB22\o2call>scriba o2c_1.sb
ERROR:
Unidentified operand
WORD:   n
LINE:   3
Return code: 0

C:\SB22\o2call>
Title: Re: O2 JIT function calls
Post by: Charles Pegge on May 28, 2013, 08:17:53 PM
Hi John,

If you do a full download of Oxygen, there are 4 examples dllco2_A .. dllco2_D, the last being a dll emulation. DLLC has been tweaked so that oxygen-compiled functions can be declared with dllproc(..).

All the sb examples require DLLC.dll, a copy of the new Oxygen.dll and IUP.dll to go into /scriptbasic/modules/.

I will be adding error reporting to DLLC shortly.

Charles


X
Title: Re: O2 JIT function calls
Post by: JRS on May 28, 2013, 08:21:06 PM
I always tend to show up at the party early.

I will download and start testing now.

Thank You!
Title: Re: O2 JIT function calls
Post by: JRS on May 28, 2013, 08:49:26 PM
Charles,

When I try to return a result from a O2 generated function it goes into an endless loop in the function. (Hello World! message box repeats)

John

Code: [Select]

  include "dllcinc.sb"

  oxy=dllfile("/sb22/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 funA(sys v) as sys
  print "Hello World!"
  funA = v
  end function

  function funB(sys v) as sys
  print "Goodbye World! "
  funB = v
  end function

  sub finish()
  terminate
  end sub

  function link(sys n) as sys
  select n
  case 0 : return @finish
  case 1 : return @funA
  case 2 : return @funB
  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
  '
' ==============================
  '
  Hello   = dllproc(a,"Hello   i=(i value) ", dllcald(a,1) )
  Goodbye = dllproc(a,"Goodbye i=(i value) ", dllcald(a,2) )
  Finish  = dllproc(a,"Finish    ()        ", dllcald(a,0) )
  '
' ==============================
  '
  h = dllcall(hello,123)
  g = dllcall(Goodbye,321)
  dllcall(Finish)
  print "hello return: ",h,"\n"
  print "goodbye return: ",g,"\n"
  dllprnt "Return code: " & a & "\n"
  '
  end if
  dllfile
  line input q
Title: Re: O2 JIT function calls
Post by: JRS on May 28, 2013, 08:59:29 PM
Too funny!!!

I need to remember what BASIC I'm coding in.

Code: [Select]
 function funA(sys v) as sys
  print "Hello World!"
  return v
  end function

  function funB(sys v) as sys
  print "Goodbye World! "
  return v
  end function

C:\SB22\o2call>scriba dllco2_D.sb
hello return: 123
goodbye return: 321
Return code: 17864768

C:\SB22\o2call>

I hope I can find a way someday to compensate you for this incredible work of coding art. Just saying thank you doesn't seem quite enough.
Title: Re: O2 JIT function calls
Post by: Charles Pegge on May 28, 2013, 09:10:52 PM
Phew! You had me worried there. Yes, your syntax caused a recursion.

here is another example with char strings. You will need to change to \sb22.



X
Title: Re: O2 JIT function calls
Post by: JRS on May 28, 2013, 09:41:19 PM
I'm in BASIC heaven!

Code: [Select]
  include "dllcinc.sb"

  oxy=dllfile("/sb22/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 funA(char* s) as char*
  static char c[256]
  c="Hello "+s
  return c
  end function

  function funB(char*s) as char*
  static char c[256]
  c="Goodbye "+s
  return c
  end function

  function reverse(char*s)
  byte b at (strptr s)
  sys i,d,e,j,t
  e=len s
  d=e>>1
  for i=1 to d
  j=e-i+1
  t=b[i] : b[i]=b[j] : b[j]=t
  next
  end function

  sub finish()
  terminate
  end sub

  function link(sys n) as sys
  select n
  case 0 : return @finish
  case 1 : return @funA
  case 2 : return @funB
  case 3 : 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
  '
' ==============================
  '
  Hello   = dllproc(a,"Hello   c*=(c*value) ", dllcald(a,1) )
  Goodbye = dllproc(a,"Goodbye c*=(c*value) ", dllcald(a,2) )
  Reverse = dllproc(a,"Reverse    (c*value) ", dllcald(a,3) )
  Finish  = dllproc(a,"Finish     ()        ", dllcald(a,0) )
  '
' ==============================
  '
  print dllcall(hello,"Henry") & "\n"
  print dllcall(Goodbye,"Henry") & "\n"
  s="abcdef"
  print "Reversed " & s & " = "
  dllcall(Reverse,s)
  print s & "\n"
  dllcall(Finish)
  '
  end if
  dllfile
  line input q

C:\SB22\o2call>scriba dllco2_E.sb
Hello Henry
Goodbye Henry
Reversed abcdef = fedcba

C:\SB22\o2call>
Title: Re: O2 JIT function calls
Post by: Charles Pegge on May 28, 2013, 09:52:50 PM
Glad it's working. I must catch some more sleep.
Title: Re: O2 JIT function calls
Post by: JRS on May 29, 2013, 11:59:11 PM
Charles,

I can't seem to get by the defining of the JIT function from the SB side. It GPF's on either function. (mandel or Finish) I can get to just prior defining these functions.

Code: OxygenBasic
  1. ' JAPI 2.0 DLLC JIT
  2.  
  3. include "dllcinc.sb"
  4.  
  5. oxy = dllfile("/sb22/modules/oxygen.dll")
  6.  
  7. o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )
  8. o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )
  9. o2_error = dllproc( oxy, "o2_error c*=()         " )
  10. o2_errno = dllproc( oxy, "o2_errno i =()         " )
  11. o2_len   = dllproc( oxy, "o2_len   i =()         " )
  12. o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " )
  13.  
  14. dllcall(o2_mode,1)
  15.  
  16. src = """
  17. extern
  18. function mandel(float zre,zim,sys maxiter) as sys
  19.     float mx,my,betrag
  20.     sys iter
  21.  
  22.     while iter < maxiter and betrag < 4.0
  23.         iter = iter+1
  24.         tmp = mx*mx-my*my+zre
  25.         my = 2*mx*my+zim
  26.         mx = tmp
  27.         betrag = (mx*mx + my*my)
  28.     wend
  29.     return iter
  30. end function
  31.  
  32. sub finish()
  33.   terminate
  34. end sub
  35.  
  36. function link(sys n) as sys
  37.   select n
  38.     case 0
  39.       return @finish
  40.     case 1
  41.       return @mandel
  42.   end select
  43. end function
  44.  
  45. end extern
  46.  
  47. addr link
  48. """
  49.  
  50. dllcall(o2_basic, src)
  51. dfn = dllcall(o2_exec,0)
  52. mandel = dllproc(dfn,"mandel i = (f zre, f zim, i maxiter)", dllcald(dfn, 1))
  53. Finish = dllproc(dfn,"Finish ()", dllcald(dfn, 0))
  54.  
  55. japi = dllfile("japi.dll")
  56.  
  57. j_start = dllproc(japi, "j_start i = ()")
  58. j_frame = dllproc(japi, "j_frame i = (c * label)")
  59. j_menubar = dllproc(japi, "j_menubar i = ( i obj)")
  60. j_menu = dllproc(japi, "j_menu i = (i obj, c *label)")
  61. j_menuitem = dllproc(japi, "j_menuitem i = (i obj, c *label)")
  62. j_canvas = dllproc(japi, "j_canvas i = (i obj, i width , i height)")
  63. j_setpos = dllproc(japi, "j_setpos (i obj, i xpos, i ypos)")
  64. j_pack = dllproc(japi, "j_pack (i obj)")
  65. j_show = dllproc(japi, "j_show (i obj)")
  66. j_getaction = dllproc(japi, "j_getaction i = ()")
  67. j_nextaction = dllproc(japi, "j_nextaction i = ()")
  68. j_setcolor = dllproc(japi, "j_setcolor (i obj, i r, i g, i b)")
  69. j_drawpixel = dllproc(japi, "j_drawpixel (i obj, i x, i y)")
  70. j_quit = dllproc(japi, "j_quit ()")
  71.  
  72. CONST J_TRUE = 1
  73. CONST J_FALSE = 0
  74.  
  75.  
  76. xstart = -1.8
  77. xend   =  0.8
  78. ystart = -1.0
  79. yend   =  1.0
  80.  
  81. hoehe  = 240
  82. breite = 320
  83.  
  84. if (dllcall(j_start) = J_FALSE) then
  85.   print("JAPI interface failed to start.\n")
  86.   end
  87. end if
  88.  
  89. jframe  = dllcall(j_frame,"JAPI 2.0 DLLC")
  90. menubar = dllcall(j_menubar,jframe)
  91. jfile   = dllcall(j_menu,menubar,"File")
  92. calc    = dllcall(j_menu,menubar,"Calc")
  93. quit    = dllcall(j_menuitem,jfile,"Quit")
  94. start   = dllcall(j_menuitem,calc,"Start")
  95. jstop   = dllcall(j_menuitem,calc,"Stop")
  96.  
  97. canvas  = dllcall(j_canvas,jframe,breite,hoehe)
  98. dllcall(j_setpos,canvas,10,60)
  99. dllcall(j_pack,jframe)
  100. dllcall(j_show,jframe)
  101.  
  102. obj = 0
  103. do_work = 0
  104.  
  105. while((obj <> jframe) and (obj <> quit))
  106.     if(do_work = 1) then
  107.         obj = dllcall(j_getaction)
  108.     else
  109.         obj = dllcall(j_nextaction)
  110.     end if      
  111.  
  112.     if(obj = start) then
  113.         x = -1
  114.         y = -1
  115.         do_work = 1
  116.     end if
  117.  
  118.     if(obj = jstop) then
  119.         do_work = 0
  120.     end if
  121.    
  122.     if(do_work = 1) then
  123.         x = (x+1) % breite
  124.        if(x = 0) then
  125.             y = (y+1) % hoehe
  126.        end if
  127.        if((x = breite-1) and (y = hoehe-1)) then
  128.             do_work = 0
  129.        else
  130.             zre = xstart + x*(xend-xstart)/breite
  131.             zim = ystart + y*(yend-ystart)/hoehe
  132.             it = dllcall(mandel,zre,zim,512)
  133.             dllcall(j_setcolor,canvas,it*11,it*13,it*17)
  134.             dllcall(j_drawpixel,canvas,x,y)
  135.        end if
  136.     end if
  137. wend
  138.  
  139. dllcall(Finish)
  140. dllcall(j_quit)
  141. dllfile
  142.  
Title: Re: O2 JIT function calls
Post by: Charles Pegge on May 30, 2013, 07:28:14 AM
Hi John,

Something very strange. I got it to work eventually by indenting the o2 source lines by 2 spaces. I will have to see what is happening to the source string as it enters the compiler.

Anyway, I will add the one attached here to the ScriptBasic examples.


X
Title: Re: O2 JIT function calls
Post by: JRS on May 30, 2013, 07:43:54 AM
I indented my version that didn't work and it now it does.

Can't believe the difference between calling the O2 mandel() function and calling it in SB.

Great job, couldn't be happier!
Title: Re: O2 JIT function calls
Post by: JRS on May 30, 2013, 08:31:26 AM
ScriptBasic
C:\SB22\japi_dllc>scriba mandel_dllc.sb
56.9223

C:\SB22\japi_dllc>

ScriptBasic JIT

C:\SB22\japi_dllc>scriba mandel_dllc2.sb
17.608

C:\SB22\japi_dllc>

If my math is correct, that's 309% faster than stock SB.

Title: Re: O2 JIT function calls
Post by: Charles Pegge on May 30, 2013, 09:08:42 AM
I've fixed the source problem. It was chr(10) line terminators again. Oxygen should now be able to handle these and Mac line terminators chr(13) as well as MS lines chr(13,10) and any combination of them.

Posted the updates:

http://www.oxygenbasic.org/forum/index.php?topic=749.0
Title: Re: O2 JIT function calls
Post by: JRS on May 30, 2013, 09:43:53 AM
Quote
I've fixed the source problem. It was chr(10) line terminators again.

Sorry Charles. The downside of working with a Linux user.

The blame may be SB itself as multi-line strings may use CHR(10) no matter what platform it's running under. Lets blame Peter Verhas. I haven't abused him in awhile.  ;D

Update

After giving this some thought, I agree with Peter's direction at the time as SB was primary targeted at web scripting and all web servers typically use CHR(10) as HTML line termination.
Title: Re: O2 JIT function calls
Post by: JRS on May 31, 2013, 11:18:22 PM
I converted the JAPI Mandelbrot Set to Simple Window to compare the speed of the two libraries.

(http://files.allbasic.info/ScriptBasic/swmadeljit.png)

Code: OxygenBasic
  1. ' Simple Window DLLC JIT
  2.  
  3. include "dllcinc.sb"
  4.  
  5. oxy = dllfile("/sb22/modules/oxygen.dll")
  6.  
  7. o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )
  8. o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )
  9. o2_error = dllproc( oxy, "o2_error c*=()         " )
  10. o2_errno = dllproc( oxy, "o2_errno i =()         " )
  11. o2_len   = dllproc( oxy, "o2_len   i =()         " )
  12. o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " )
  13.  
  14. dllcall(o2_mode,1)
  15.  
  16. src = """
  17. extern
  18. function mandel(float zre,zim,sys maxiter) as sys
  19.     float mx,my,betrag
  20.     sys iter
  21.  
  22.     while iter < maxiter and betrag < 4.0
  23.         iter = iter+1
  24.         tmp = mx*mx-my*my+zre
  25.         my = 2*mx*my+zim
  26.         mx = tmp
  27.         betrag = (mx*mx + my*my)
  28.     wend
  29.     return iter
  30. end function
  31.  
  32. sub finish()
  33.   terminate
  34. end sub
  35.  
  36. function link(sys n) as sys
  37.   select n
  38.     case 0
  39.       return @finish
  40.     case 1
  41.       return @mandel
  42.   end select
  43. end function
  44.  
  45. end extern
  46.  
  47. addr link
  48. """
  49.  
  50. dllcall(o2_basic, src)
  51. dfn = dllcall(o2_exec,0)
  52. mandel = dllproc(dfn,"mandel i = (f zre, f zim, i maxiter)", dllcald(dfn, 1))
  53. finish = dllproc(dfn,"finish ()", dllcald(dfn, 0))
  54.  
  55. sw = dllfile("sw.dll")
  56.  
  57. Window = dllproc(sw, "Window i = (i width, i height, i mode)")
  58. SetCaption = DLLC_Proc(sw, "SetCaption i = (c *capText)")
  59. SetPixel = dllproc(sw, "SetPixel i = (i xPos, i yPos, i color)")
  60. RGB = dllproc(sw, "RGB i = (i rValue, i gValue, i bValue)")
  61. Redraw = DLLC_Proc(sw, "Redraw ( )")
  62. WaitKey = dllproc(sw, "WaitKey i = ( )")
  63. Quit = DLLC_Proc(sw, "Quit i = ( )")
  64.  
  65.  
  66. xstart = -1.8
  67. xend   =  0.8
  68. ystart = -1.0
  69. yend   =  1.0
  70.  
  71. hoehe  = 240
  72. breite = 320
  73.  
  74. dllcall(Window,320,240,1)
  75. dllcall(SetCaption,"SB SW DLLC JIT")
  76.  
  77. st = dllsecs()
  78.  
  79. x = -1
  80. y = -1
  81.  
  82. REPEAT
  83.   x = (x+1) % breite
  84.   if(x = 0) then y = (y+1) % hoehe
  85.   zre = xstart + x*(xend-xstart)/breite
  86.   zim = ystart + y*(yend-ystart)/hoehe
  87.   it = dllcall(mandel,zre,zim,512)
  88.   dllcall(SetPixel,x, y, dllcall(RGB,it*11,it*13,it*17))
  89.   dllcall(Redraw)
  90. UNTIL ((x = breite-1) and (y = hoehe-1))
  91. PRINT format("%g",dllsecs() - st),"\n"
  92. dllcall(WaitKey)
  93.  
  94. dllcall(Finish)
  95. dllcall(Quit)
  96. dllfile
  97.  

C:\SB22\japi_dllc>scriba swmandeldllc.sb
5.57576

C:\SB22\japi_dllc>

If I remove the Redraw() function and wait until the it's done to refresh the screen.

C:\SB22\japi_dllc>scriba swmandeldllc.sb
1.05691

C:\SB22\japi_dllc>
Title: Re: O2 JIT function calls
Post by: JRS on June 01, 2013, 12:03:32 AM
This is stock SB with no JIT assist.

Code: OxygenBasic
  1. ' Simple Window DLLC
  2.  
  3. include "dllcinc.sb"
  4.  
  5. sw = dllfile("sw.dll")
  6.  
  7. Window = dllproc(sw, "Window i = (i width, i height, i mode)")
  8. SetCaption = DLLC_Proc(sw, "SetCaption i = (c *capText)")
  9. SetPixel = dllproc(sw, "SetPixel i = (i xPos, i yPos, i color)")
  10. RGB = dllproc(sw, "RGB i = (i rValue, i gValue, i bValue)")
  11. Redraw = DLLC_Proc(sw, "Redraw ( )")
  12. WaitKey = dllproc(sw, "WaitKey i = ( )")
  13. Quit = DLLC_Proc(sw, "Quit i = ( )")
  14.  
  15. function mandel(zre,zim,maxiter)
  16.     mx = 0.0
  17.     my = 0.0
  18.     iter=0
  19.     betrag=0.0
  20.  
  21.     while ((iter < maxiter) and (betrag < 4.0))
  22.         iter = iter+1
  23.         tmp = mx*mx-my*my+zre
  24.         my = 2*mx*my+zim
  25.         mx = tmp
  26.         betrag = (mx*mx + my*my)
  27.     wend
  28.     mandel=iter
  29. end function
  30.  
  31. xstart = -1.8
  32. xend   =  0.8
  33. ystart = -1.0
  34. yend   =  1.0
  35.  
  36. hoehe  = 240
  37. breite = 320
  38.  
  39. dllcall(Window,320,240,1)
  40. dllcall(SetCaption,"SB SW DLLC")
  41.  
  42. st = dllsecs()
  43.  
  44. x = -1
  45. y = -1
  46.  
  47. REPEAT
  48.   x = (x+1) % breite
  49.   if(x = 0) then y = (y+1) % hoehe
  50.   zre = xstart + x*(xend-xstart)/breite
  51.   zim = ystart + y*(yend-ystart)/hoehe
  52.   it = mandel(zre,zim,512)
  53.   dllcall(SetPixel,x, y, dllcall(RGB,it*11,it*13,it*17))
  54. UNTIL ((x = breite-1) and (y = hoehe-1))
  55. dllcall(Redraw)
  56. PRINT format("%g",dllsecs() - st),"\n"
  57. dllcall(WaitKey)
  58.  
  59. dllcall(Quit)
  60. dllfile
  61.  

With Redraw() in the loop.

C:\SB22\japi_dllc>scriba swnojit.sb
45.0972

C:\SB22\japi_dllc>

Wait until the end to display the results.

C:\SB22\japi_dllc>scriba swnojit.sb
39.637

C:\SB22\japi_dllc>