Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Support

Pages: 1 2 3 [4] 5 6 ... 12
46
What's New / ScriptBasic JIT
« on: May 30, 2013, 12:00:53 PM »
Charles Pegge (OxygenBasic / DLLC author) has done it again and added JIT (Just-In-Time) function scripting, compiling and calling all at runtime. The following example is interesting as it shows DLLC supporting the JAPI  (Java Application Programming Interface) and using JIT for the Mandelbrot Set calculation. (76,800 pixel calculations)




The following code is using DLLC to interface with the JAPI DLL to produce the Mandelbrot Set.

Code: [Select]
' JAPI 2.0 DLLC

include "dllcinc.sb"

japi = dllfile("japi.dll")

j_start = dllproc(japi, "j_start i = ()")
j_frame = dllproc(japi, "j_frame i = (c * label)")
j_menubar = dllproc(japi, "j_menubar i = ( i obj)")
j_menu = dllproc(japi, "j_menu i = (i obj, c *label)")
j_menuitem = dllproc(japi, "j_menuitem i = (i obj, c *label)")
j_canvas = dllproc(japi, "j_canvas i = (i obj, i width , i height)")
j_setpos = dllproc(japi, "j_setpos (i obj, i xpos, i ypos)")
j_pack = dllproc(japi, "j_pack (i obj)")
j_show = dllproc(japi, "j_show (i obj)")
j_getaction = dllproc(japi, "j_getaction i = ()")
j_nextaction = dllproc(japi, "j_nextaction i = ()")
j_setcolor = dllproc(japi, "j_setcolor (i obj, i r, i g, i b)")
j_drawpixel = dllproc(japi, "j_drawpixel (i obj, i x, i y)")
j_quit = dllproc(japi, "j_quit ()")

CONST J_TRUE = 1
CONST J_FALSE = 0


xstart = -1.8
xend   =  0.8
ystart = -1.0
yend   =  1.0

hoehe  = 240
breite = 320

if (dllcall(j_start) = J_FALSE) then
  print("JAPI interface failed to start.\n")
  end
endif

jframe  = dllcall(j_frame,"JAPI 2.0 DLLC")
menubar = dllcall(j_menubar,jframe)
jfile   = dllcall(j_menu,menubar,"File")
calc    = dllcall(j_menu,menubar,"Calc")
quit    = dllcall(j_menuitem,jfile,"Quit")
start   = dllcall(j_menuitem,calc,"Start")
jstop   = dllcall(j_menuitem,calc,"Stop")

canvas  = dllcall(j_canvas,jframe,breite,hoehe)
dllcall(j_setpos,canvas,10,60)
dllcall(j_pack,jframe)
dllcall(j_show,jframe)

obj = 0
do_work = 0

while((obj <> jframe) and (obj <> quit))

    if(do_work = 1) then
        obj = dllcall(j_getaction)
    else
        obj = dllcall(j_nextaction)
    endif      

    if(obj = start) then
        x = -1
        y = -1
        do_work = 1
        st = dllsecs()
    endif

    if(obj = jstop) then
        do_work = 0
    endif
    
    if(do_work = 1) then
        x = (x+1) % breite
       if(x = 0) then
            y = (y+1) % hoehe
       endif
       if((x = breite-1) and (y = hoehe-1)) then
            do_work = 0
            PRINT format("%g",dllsecs() - st),"\n"
        else
            zre = xstart + x*(xend-xstart)/breite
            zim = ystart + y*(yend-ystart)/hoehe
            it = mandel(zre,zim,512)
            dllcall(j_setcolor,canvas,it*11,it*13,it*17)
            dllcall(j_drawpixel,canvas,x,y)
        endif
    endif

wend

dllcall(j_quit)


function mandel(zre,zim,maxiter)
    mx = 0.0
    my = 0.0
    iter=0
    betrag=0.0
 
    while ((iter < maxiter) and (betrag < 4.0))
        iter = iter+1
        tmp = mx*mx-my*my+zre
        my = 2*mx*my+zim
        mx = tmp
        betrag = (mx*mx + my*my)
    wend
    mandel=iter
end function

This version uses the new JIT compiling feature of DLLC with the mandel() function compiled at runtime.

Code: [Select]
' JAPI 2.0 DLLC JIT

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 mandel(float zre,zim,sys maxiter) as sys
    float mx,my,betrag
    sys iter
 
    while iter < maxiter and betrag < 4.0
        iter = iter+1
        tmp = mx*mx-my*my+zre
        my = 2*mx*my+zim
        mx = tmp
        betrag = (mx*mx + my*my)
    wend
    return iter
end function

sub finish()
  terminate
end sub

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

end extern

addr link
"""

dllcall(o2_basic, src)
dfn = dllcall(o2_exec,0)
mandel = dllproc(dfn,"mandel i = (f zre, f zim, i maxiter)", dllcald(dfn, 1))
finish = dllproc(dfn,"finish ()", dllcald(dfn, 0))

japi = dllfile("japi.dll")

j_start = dllproc(japi, "j_start i = ()")
j_frame = dllproc(japi, "j_frame i = (c * label)")
j_menubar = dllproc(japi, "j_menubar i = ( i obj)")
j_menu = dllproc(japi, "j_menu i = (i obj, c *label)")
j_menuitem = dllproc(japi, "j_menuitem i = (i obj, c *label)")
j_canvas = dllproc(japi, "j_canvas i = (i obj, i width , i height)")
j_setpos = dllproc(japi, "j_setpos (i obj, i xpos, i ypos)")
j_pack = dllproc(japi, "j_pack (i obj)")
j_show = dllproc(japi, "j_show (i obj)")
j_getaction = dllproc(japi, "j_getaction i = ()")
j_nextaction = dllproc(japi, "j_nextaction i = ()")
j_setcolor = dllproc(japi, "j_setcolor (i obj, i r, i g, i b)")
j_drawpixel = dllproc(japi, "j_drawpixel (i obj, i x, i y)")
j_quit = dllproc(japi, "j_quit ()")

CONST J_TRUE = 1
CONST J_FALSE = 0


xstart = -1.8
xend   =  0.8
ystart = -1.0
yend   =  1.0

hoehe  = 240
breite = 320

if (dllcall(j_start) = J_FALSE) then
  print("JAPI interface failed to start.\n")
  end
endif

jframe  = dllcall(j_frame,"JAPI 2.0 DLLC JIT")
menubar = dllcall(j_menubar,jframe)
jfile   = dllcall(j_menu,menubar,"File")
calc    = dllcall(j_menu,menubar,"Calc")
quit    = dllcall(j_menuitem,jfile,"Quit")
start   = dllcall(j_menuitem,calc,"Start")
jstop   = dllcall(j_menuitem,calc,"Stop")

canvas  = dllcall(j_canvas,jframe,breite,hoehe)
dllcall(j_setpos,canvas,10,60)
dllcall(j_pack,jframe)
dllcall(j_show,jframe)

obj = 0
do_work = 0

while((obj <> jframe) and (obj <> quit))
    if(do_work = 1) then
        obj = dllcall(j_getaction)
    else
        obj = dllcall(j_nextaction)
    endif      

    if(obj = start) then
        x = -1
        y = -1
        do_work = 1
        st = dllsecs()
    endif

    if(obj = jstop) then
        do_work = 0
    endif
    
    if(do_work = 1) then
        x = (x+1) % breite
       if(x = 0) then
            y = (y+1) % hoehe
       endif
       if((x = breite-1) and (y = hoehe-1)) then
            do_work = 0
            PRINT format("%g",dllsecs() - st),"\n"
        else
            zre = xstart + x*(xend-xstart)/breite
            zim = ystart + y*(yend-ystart)/hoehe
            it = dllcall(mandel,zre,zim,512)
            dllcall(j_setcolor,canvas,it*11,it*13,it*17)
            dllcall(j_drawpixel,canvas,x,y)
        endif
    endif
wend

dllcall(Finish)
dllcall(j_quit)
dllfile

When the menu start option is clicked I record the time and print the results when the last pixel is displayed of the Mandelbrot Set.

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>


47
Extension Modules / JAPI 2.0 Enhancements
« on: May 26, 2013, 10:25:24 PM »
There seems to be some confusion on where the JAPI code was left. I made the assumption that there were two development branches. (AWT and SWING) A Pascal developer wanted to use the japi.dll I created and mentioned that the original version I created looks the same as what I'm calling the SWING version. He was right. I made some compares between the two directories and there is obvious changes to adapt to SWING compared to the AWT directory. (which the 2003 binaries were built from) The first complaint I seem to be getting is that buttons look like W2K style. Not like the examples of other Windows look&feel JAR applications I posted. I would like to solve this Java SWING button issue first and let it be a guide to bringing up to date other components in the JAPI library.





The real mystery is why do I get a SWING style button on Linux but not on Windows?



Mystery solved.


48
Extension Modules / ScriptBasic JAPI 2.0 (release canidate)
« on: May 23, 2013, 06:52:04 PM »
I have attached a JAPI 2.0 release candidate for ScriptBasic Windows 32. Feedback and example code would be appreciated.

Note: For those still interested in the AWT version, you should download the latest 1.x release. Version 2.0 is based on Swing.

49
Extension Modules / JAPI - ScriptBasic Java GUI extension module
« on: May 18, 2013, 01:24:15 PM »
JAPI Project Site

JAPI Reference Manual


I was strolling through the ScriptBasic source and noticed a JRE API extension module a user started on but didn't seem to finish. After tracking down the JAPI site I was able to download the source for the ScriptBasic binding and some examples. Here is a few screen shots and the ScriptBasic JAPI include declaring available functions. There is even a Java console/debugger that can be enable with J_ call.

This is nice that SB can interface through JRE to the Java VM under Linux. What has my interest is this JRE interface running on Android Linux and interfacing with Android's Java VM.



Code: [Select]
rem Example mandel.bas

import japi.bas

xstart = -1.8
xend   =  0.8
ystart = -1.0
yend   =  1.0

hoehe  = 240
breite = 320

if(j_start() = J_FALSE) then
    print("can't connect to JAPI server")
    end
endif

jframe  = j_frame("Variables Mandelbrot")
j_setborderlayout(jframe)

menubar = j_menubar(jframe)
jfile   = j_menu(menubar,"File")
calc    = j_menu(menubar,"Calc")
quit    = j_menuitem(jfile,"Quit")
start   = j_menuitem(calc,"Start")
jstop   = j_menuitem(calc,"Stop")

canvas  = j_canvas(jframe,breite,hoehe)

j_pack(jframe)
j_show(jframe)

obj = 0
do_work = 0

while((obj <> jframe) and (obj <> quit))

    if(do_work = 1) then
        obj = j_getaction()
    else
        obj = j_nextaction()
    endif      

    if(obj = start) then
        x = -1
        y = -1
        do_work = 1
    endif

    if(obj = jstop) then
       do_work = 0
    endif
    
    if(do_work = 1) then
        x = (x+1) % breite
        if(x = 0) then
            y = (y+1) % hoehe
        endif
        if((x = breite-1) and (y = hoehe-1)) then
            do_work = 0
        else
            zre = xstart + x*(xend-xstart)/breite
            zim = ystart + y*(yend-ystart)/hoehe
            it = mandel(zre,zim,512)
            j_setcolor(canvas,it*11,it*13,it*17)
            j_drawpixel(canvas,x,y)
        endif
    endif

    if(obj = canvas) then
        breite = j_getwidth(canvas)
        hoehe = j_getheight(canvas)
        x=-1
        y=-1
    endif
wend
j_quit()



function mandel(zre,zim,maxiter)
    mx = 0.0
    my = 0.0
    iter=0
    betrag=0.0
 
    while ((iter < maxiter) and (betrag < 4.0))
        iter = iter+1
        tmp = mx*mx-my*my+zre
        my = 2*mx*my+zim
        mx = tmp
        betrag = (mx*mx + my*my)
    wend
    mandel=iter
end function

This shows that animation is possible. (cool demo)

Code: [Select]
rem Example video.bas

    import japi.bas
    j_setdebug(0)

    if( j_start() = J_FALSE ) then
       print "can't connect to JAPI server"  
       end
    endif

    for i=0 to 17
       filename$ = "images/ms"&str$(fix(i+1))&".gif"
           print "Loading ",filename$,"\n"
           image[i]  = j_loadimage(filename$)
    next i
   
    breite  = j_getwidth(image[0])
    hoehe   = j_getheight(image[0])
    jframe   = j_frame("Video")

    menubar = j_menubar(jframe)
    jfile   = j_menu(menubar,"File")
    quit    = j_menuitem(jfile,"Quit")

    play    = j_menu(menubar,"Video")
    start   = j_menuitem(play,"Start")
    jstop   = j_menuitem(play,"Stop")

    canvas  = j_canvas(jframe,breite,hoehe)
    j_setpos(canvas,10,60)

    j_show(jframe)
    j_pack(jframe)
      
    i = 0
    do_work = J_FALSE
    obj = 0
    while((obj <> jframe) and (obj <> quit))

        if(do_work=J_TRUE) then
           obj=j_getaction()
        else
           obj=j_nextaction()
        endif
    
        if(obj = start) then
           do_work = J_TRUE
        endif
        
        if(obj = jstop) then
           do_work = J_FALSE
        endif
        
        if(do_work=J_TRUE) then
           j_drawimage(canvas,image[i],0,0)
           j_sync()
           j_sleep(50)
           i = (i+1) % 18
        endif

    wend
    j_quit()


Code: [Select]
rem Example vumeter.bas

    import japi.bas

    if( j_start() = J_FALSE ) then
        print "can't connect to JAPI server"  
        end
    endif

    jframe = j_frame("Meter")
    j_setborderlayout(jframe)
    j_setinsets(jframe,j_getinsets(jframe,J_TOP)+10,10,10,10)
    j_setvgap(jframe,10)

    progress=j_progressbar(jframe,J_HORIZONTAL)
    j_setborderpos(progress,J_BOTTOM)
    meter=j_meter(jframe,"Volt")

    j_setsize(jframe,150,170)
    j_show(jframe)

    value=50
    while(j_getaction()<>jframe)
       value=value-1
       if(j_random()>J_RANDMAX/2) then
         value = value+2
       endif
       j_setvalue(meter,value)
       j_setvalue(progress,value)
       j_sync()
       j_sleep(50)
    wend

    j_quit()
end


Code: [Select]
rem Example digits.bas

    import japi.bas
        
    if(j_start() = J_FALSE ) then
        print "can't connect to JAPI server"  
        goto 20
    endif

    jframe = j_frame("Digits")
    j_setborderlayout(jframe)
    j_setinsets(jframe,j_getinsets(jframe,J_TOP)+10,10,10,10)
    j_setvgap(jframe,10)

    panel = j_panel(jframe)
    j_setborderpos(panel,J_BOTTOM)
    j_setflowlayout(panel,J_HORIZONTAL)
    j_sethgap(panel,10)
    for i=4 to 1 step -1
       led[i]=j_led(panel,J_ROUND,J_RED)
       mouse[i]=j_mouselistener(led[i],J_RELEASED)
    next i

    seven = j_sevensegment(jframe,J_GREEN)

    j_setsize(jframe,150,250)
    j_show(jframe)
    
    obj=0

10  obj=j_nextaction()

        for i=1 to 4
            if(obj = mouse[i]) then
                j_setstate(led[i], j_getstate(led[i])-1)
            endif
        next i
          
        v=0
        if(j_getstate(led[4])) then v=v+8
        if(j_getstate(led[3])) then v=v+4
        if(j_getstate(led[2])) then v=v+2
        if(j_getstate(led[1])) then v=v+1
        j_setvalue(seven,v)
    
        if(obj = jframe) then goto 20
        
    goto 10

20  j_quit
    end


Code: [Select]
rem Example graphic.bas

    import japi.bas
    for i = 0 to 9
       x[i]=(i+1)*10
        if(even(i)) then
           y[i]=10
        else
           y[i]=90
        endif    
    next i
    
    if( j_start() = J_FALSE ) then
        print "can't connect to JAPI server"  
        end
    endif
 
    jframe   = j_frame("Graphic Primitives")
    j_setsize(jframe,720,260)

    canvas  = j_canvas(jframe,700,230)
    j_setpos(canvas,10,30)

    j_show(jframe)
    j_pack(jframe)

    j_setnamedcolor(canvas,J_BLUE)

rem      Normal

    j_translate(canvas,10,10)
    j_drawline(canvas,10,10,90,90)
    j_drawstring(canvas,0,105,"Line")

    j_translate(canvas,100,0)
    j_drawpolygon(canvas,10,x,y)
    j_drawstring(canvas,0,105,"Polygon")

    j_translate(canvas,100,0)
    j_drawrect(canvas,10,10,80,80)
    j_drawstring(canvas,0,105,"Rectangle")

    j_translate(canvas,100,0)
    j_drawroundrect(canvas,10,10,80,80,20,20)
    j_drawstring(canvas,0,105,"RoundRect")

    j_translate(canvas,100,0)
    j_drawcircle(canvas,50,50,40)
    j_drawstring(canvas,0,105,"Circle")
print "6"

    j_translate(canvas,100,0)
    j_drawoval(canvas,50,50,40,20)
    j_drawstring(canvas,0,105,"Oval")

    j_translate(canvas,100,0)
    j_drawarc(canvas,50,50,40,30,113,210)
    j_drawstring(canvas,0,105,"Arc")


rem     Filled

    j_translate(canvas,-600,100)
    j_drawpolyline(canvas,10,x,y)
    j_drawstring(canvas,0,105,"Polyline")

    j_translate(canvas,100,0)
    j_fillpolygon(canvas,10,x,y)
    j_drawstring(canvas,0,105,"FillPolygon")

    j_translate(canvas,100,0)
    j_fillrect(canvas,10,10,80,80)
    j_drawstring(canvas,0,105,"FillRectangle")

    j_translate(canvas,100,0)
    j_fillroundrect(canvas,10,10,80,80,20,20)
    j_drawstring(canvas,0,105,"FillRoundRect")

    j_translate(canvas,100,0)
    j_fillcircle(canvas,50,50,40)
    j_drawstring(canvas,0,105,"FillCircle")

    j_translate(canvas,100,0)
    j_filloval(canvas,50,50,40,20)
    j_drawstring(canvas,0,105,"FillOval")

    j_translate(canvas,100,0)
    j_fillarc(canvas,50,50,40,30,113,210)
    j_drawstring(canvas,0,105,"FillArc")


    while(j_nextaction()<>jframe)
wend
      
    j_quit()
    end


Code: [Select]
rem     Example graphicbutton.bas
    
    import japi.bas

    if( j_start() = J_FALSE ) then
        print "can't connect to JAPI server"  
        end
    endif

    jframe   = j_frame("Graphic Buttons")
    j_setflowlayout(jframe,J_HORIZONTAL)
    
    gbutton = j_graphicbutton(jframe,"images/open.gif")
    gbutton = j_graphicbutton(jframe,"images/new.gif")
    gbutton = j_graphicbutton(jframe,"images/save.gif")
    gbutton = j_graphicbutton(jframe,"images/cut.gif")
    gbutton = j_graphicbutton(jframe,"images/copy.gif")
    gbutton = j_graphicbutton(jframe,"images/paste.gif")
  
    j_pack(jframe)
    j_show(jframe)


    while(j_nextaction() <> jframe)
    wend
      
    j_quit()
    end


Code: [Select]
rem Example drawables.bas
    
    import japi.bas
    
    j_setdebug(1)
    
    if( j_start() = J_FALSE ) then
       print "can't connect to JAPI server"  
       end
    endif
    
    jframe = j_frame("")
    j_setborderlayout(jframe)
    
    menubar = j_menubar(jframe)
    jfile   = j_menu(menubar,"File")
    jprint  = j_menuitem(jfile,"Print")
    save    = j_menuitem(jfile,"Save BMP")
    quit    = j_menuitem(jfile,"Quit")
    canvas  = j_canvas(jframe,400,600)
    j_pack(jframe)
    j_show(jframe)
    
    a=drawgraphics(canvas,0,0,j_getwidth(canvas)-10,j_getheight(canvas)-10)
      
    obj=0
    while((obj <> jframe) and (obj <> quit))
        obj = j_nextaction()
    
        if(obj = canvas) then
            j_setnamedcolorbg(canvas,J_WHITE)
           call drawgraphics(canvas,10,10,j_getwidth(canvas)-10,j_getheight(canvas)-10)
        endif
    
        if(obj = jprint) then
           jprinter = j_printer(jframe)
           if(jprinter > 0) then
              call drawgraphics(jprinter,40,40,j_getwidth(jprinter)-80,j_getheight(jprinter)-80)
              j_print(jprinter)
           endif
        endif
    
        if(obj = save) then
           rem    NOTE: problems with WinNT 24 Bit Colordepth (use 16 Bit)
           image = j_image(600,800)
           call drawgraphics(image,0,0,600,800)
           if(j_saveimage(image,"test.bmp",J_BMP)=J_FALSE) then
               a=j_alertbox(jframe,"Problems","Can't save image","OK")
           endif
        endif
    
    wend
    j_quit()
    
    
            
    function drawgraphics(drawable,xmin,ymin,xmax,ymax)
    
        fntsize=10
        j_setfontsize(drawable,fntsize)
        j_setnamedcolor(drawable,J_RED)
    
        rem   Drawings
        j_drawline(drawable,xmin,ymin,xmax-1,ymax-1)
        j_drawline(drawable,xmin,ymax-1,xmax-1,ymin)
        j_drawrect(drawable,xmin,ymin,xmax-xmin-1,ymax-xmin-1)
    
        j_setnamedcolor(drawable,J_BLACK)
        j_drawline(drawable,xmin,ymax-30,xmax-1,ymax-30)
        tmpstr$ = "XMax = "+Str$(xmax)
        j_drawstring(drawable,xmax/2-j_getstringwidth(drawable,tmpstr$)/2,ymax-40,tmpstr$)
    
        j_drawline(drawable,xmin+30,ymin,xmin+30,ymax-1)
        tmpstr$ = "YMax = "+Str$(ymax)
        j_drawstring(drawable,xmin+50,40,tmpstr$)
    
        j_setnamedcolor(drawable,J_MAGENTA)
        for i=1 to 10
         j_drawoval(drawable,xmin+(xmax-xmin)/2,ymin+(ymax-ymin)/2,(xmax-xmin)/20*i,(ymax-ymin)/20*i)
        next i
            
        rem   Text
        j_setnamedcolor(drawable,J_BLUE)
        y=ymin
        for i=5 to 22
            j_setfontsize(drawable,i)
            x = xmax-j_getstringwidth(drawable,"JAPI Test Text")
            y = y+j_getfontheight(drawable)
            j_drawstring(drawable,x,y,"JAPI Test Text")
        next i
    
        rem   Images
        twux = j_loadimage("images/twux.gif")
        if(twux > 0) then
            j_drawimage(drawable,twux,100,200)
            j_drawscaledimage(drawable,twux,10,0,35,30,100,300,110,138)
        endif
                
    end function
   

JAPI.bas
Code: [Select]

REM
REM
REM   generated by makejapiscriba   DO NOT EDIT
REM
REM   Die Feb 25 17:56:47 MST 2003
REM
REM



REM BOOLEAN
    const J_TRUE              =    1
    const J_FALSE             =    0



REM ALIGNMENT
    const J_LEFT              =    0
    const J_CENTER            =    1
    const J_RIGHT             =    2
    const J_TOP               =    3
    const J_BOTTOM            =    4
    const J_TOPLEFT           =    5
    const J_TOPRIGHT          =    6
    const J_BOTTOMLEFT        =    7
    const J_BOTTOMRIGHT       =    8



REM CURSOR
    const J_DEFAULT_CURSOR    =    0
    const J_CROSSHAIR_CURSOR  =    1
    const J_TEXT_CURSOR       =    2
    const J_WAIT_CURSOR       =    3
    const J_SW_RESIZE_CURSOR  =    4
    const J_SE_RESIZE_CURSOR  =    5
    const J_NW_RESIZE_CURSOR  =    6
    const J_NE_RESIZE_CURSOR  =    7
    const J_N_RESIZE_CURSOR   =    8
    const J_S_RESIZE_CURSOR   =    9
    const J_W_RESIZE_CURSOR   =    10
    const J_E_RESIZE_CURSOR   =    11
    const J_HAND_CURSOR       =    12
    const J_MOVE_CURSOR       =    13



REM ORIENTATION
    const J_HORIZONTAL        =    0
    const J_VERTICAL          =    1



REM FONTS
    const J_PLAIN             =    0
    const J_BOLD              =    1
    const J_ITALIC            =    2
    const J_COURIER           =    1
    const J_HELVETIA          =    2
    const J_TIMES             =    3
    const J_DIALOGIN          =    4
    const J_DIALOGOUT         =    5



REM COLORS
    const J_BLACK             =    0
    const J_WHITE             =    1
    const J_RED               =    2
    const J_GREEN             =    3
    const J_BLUE              =    4
    const J_CYAN              =    5
    const J_MAGENTA           =    6
    const J_YELLOW            =    7
    const J_ORANGE            =    8
    const J_GREEN_YELLOW      =    9
    const J_GREEN_CYAN        =    10
    const J_BLUE_CYAN         =    11
    const J_BLUE_MAGENTA      =    12
    const J_RED_MAGENTA       =    13
    const J_DARK_GRAY         =    14
    const J_LIGHT_GRAY        =    15
    const J_GRAY              =    16



REM BORDERSTYLE
    const J_NONE              =    0
    const J_LINEDOWN          =    1
    const J_LINEUP            =    2
    const J_AREADOWN          =    3
    const J_AREAUP            =    4



REM MOUSELISTENER
    const J_MOVED             =    0
    const J_DRAGGED           =    1
    const J_PRESSED           =    2
    const J_RELEASED          =    3
    const J_ENTERERD          =    4
    const J_EXITED            =    5
    const J_DOUBLECLICK       =    6



REM COMPONENTLISTENER



REM J_MOVED
    const J_RESIZED           =    1
    const J_HIDDEN            =    2
    const J_SHOWN             =    3



REM WINDOWLISTENER
    const J_ACTIVATED         =    0
    const J_DEACTIVATED       =    1
    const J_OPENED            =    2
    const J_CLOSED            =    3
    const J_ICONIFIED         =    4
    const J_DEICONIFIED       =    5
    const J_CLOSING           =    6



REM IMAGEFILEFORMAT
    const J_GIF               =    0
    const J_JPG               =    1
    const J_PPM               =    2
    const J_BMP               =    3



REM LEDFORMAT
    const J_ROUND             =    0
    const J_RECT              =    1



REM RANDOMMAX
    const J_RANDMAX           =    2147483647




    declare sub j_start               alias "__j_scriba_start"              lib "japi"
    declare sub j_connect             alias "__j_scriba_connect"            lib "japi"
    declare sub j_setport             alias "__j_scriba_setport"            lib "japi"
    declare sub j_setdebug            alias "__j_scriba_setdebug"           lib "japi"
    declare sub j_frame               alias "__j_scriba_frame"              lib "japi"
    declare sub j_button              alias "__j_scriba_button"             lib "japi"
    declare sub j_graphicbutton       alias "__j_scriba_graphicbutton"      lib "japi"
    declare sub j_checkbox            alias "__j_scriba_checkbox"           lib "japi"
    declare sub j_label               alias "__j_scriba_label"              lib "japi"
    declare sub j_graphiclabel        alias "__j_scriba_graphiclabel"       lib "japi"
    declare sub j_canvas              alias "__j_scriba_canvas"             lib "japi"
    declare sub j_panel               alias "__j_scriba_panel"              lib "japi"
    declare sub j_borderpanel         alias "__j_scriba_borderpanel"        lib "japi"
    declare sub j_radiogroup          alias "__j_scriba_radiogroup"         lib "japi"
    declare sub j_radiobutton         alias "__j_scriba_radiobutton"        lib "japi"
    declare sub j_list                alias "__j_scriba_list"               lib "japi"
    declare sub j_choice              alias "__j_scriba_choice"             lib "japi"
    declare sub j_dialog              alias "__j_scriba_dialog"             lib "japi"
    declare sub j_window              alias "__j_scriba_window"             lib "japi"
    declare sub j_popupmenu           alias "__j_scriba_popupmenu"          lib "japi"
    declare sub j_scrollpane          alias "__j_scriba_scrollpane"         lib "japi"
    declare sub j_hscrollbar          alias "__j_scriba_hscrollbar"         lib "japi"
    declare sub j_vscrollbar          alias "__j_scriba_vscrollbar"         lib "japi"
    declare sub j_line                alias "__j_scriba_line"               lib "japi"
    declare sub j_printer             alias "__j_scriba_printer"            lib "japi"
    declare sub j_image               alias "__j_scriba_image"              lib "japi"
    declare sub j_filedialog          alias "__j_scriba_filedialog"         lib "japi"
    declare sub j_fileselect          alias "__j_scriba_fileselect"         lib "japi"
    declare sub j_messagebox          alias "__j_scriba_messagebox"         lib "japi"
    declare sub j_alertbox            alias "__j_scriba_alertbox"           lib "japi"
    declare sub j_choicebox2          alias "__j_scriba_choicebox2"         lib "japi"
    declare sub j_choicebox3          alias "__j_scriba_choicebox3"         lib "japi"
    declare sub j_progressbar         alias "__j_scriba_progressbar"        lib "japi"
    declare sub j_led                 alias "__j_scriba_led"                lib "japi"
    declare sub j_sevensegment        alias "__j_scriba_sevensegment"       lib "japi"
    declare sub j_meter               alias "__j_scriba_meter"              lib "japi"
    declare sub j_additem             alias "__j_scriba_additem"            lib "japi"
    declare sub j_textfield           alias "__j_scriba_textfield"          lib "japi"
    declare sub j_textarea            alias "__j_scriba_textarea"           lib "japi"
    declare sub j_menubar             alias "__j_scriba_menubar"            lib "japi"
    declare sub j_menu                alias "__j_scriba_menu"               lib "japi"
    declare sub j_helpmenu            alias "__j_scriba_helpmenu"           lib "japi"
    declare sub j_menuitem            alias "__j_scriba_menuitem"           lib "japi"
    declare sub j_checkmenuitem       alias "__j_scriba_checkmenuitem"      lib "japi"
    declare sub j_pack                alias "__j_scriba_pack"               lib "japi"
    declare sub j_print               alias "__j_scriba_print"              lib "japi"
    declare sub j_playsoundfile       alias "__j_scriba_playsoundfile"      lib "japi"
    declare sub j_play                alias "__j_scriba_play"               lib "japi"
    declare sub j_sound               alias "__j_scriba_sound"              lib "japi"
    declare sub j_setfont             alias "__j_scriba_setfont"            lib "japi"
    declare sub j_setfontname         alias "__j_scriba_setfontname"        lib "japi"
    declare sub j_setfontsize         alias "__j_scriba_setfontsize"        lib "japi"
    declare sub j_setfontstyle        alias "__j_scriba_setfontstyle"       lib "japi"
    declare sub j_seperator           alias "__j_scriba_seperator"          lib "japi"
    declare sub j_disable             alias "__j_scriba_disable"            lib "japi"
    declare sub j_enable              alias "__j_scriba_enable"             lib "japi"
    declare sub j_getstate            alias "__j_scriba_getstate"           lib "japi"
    declare sub j_getrows             alias "__j_scriba_getrows"            lib "japi"
    declare sub j_getcolumns          alias "__j_scriba_getcolumns"         lib "japi"
    declare sub j_getselect           alias "__j_scriba_getselect"          lib "japi"
    declare sub j_isselect            alias "__j_scriba_isselect"           lib "japi"
    declare sub j_isvisible           alias "__j_scriba_isvisible"          lib "japi"
    declare sub j_isparent            alias "__j_scriba_isparent"           lib "japi"
    declare sub j_isresizable         alias "__j_scriba_isresizable"        lib "japi"
    declare sub j_select              alias "__j_scriba_select"             lib "japi"
    declare sub j_deselect            alias "__j_scriba_deselect"           lib "japi"
    declare sub j_multiplemode        alias "__j_scriba_multiplemode"       lib "japi"
    declare sub j_insert              alias "__j_scriba_insert"             lib "japi"
    declare sub j_remove              alias "__j_scriba_remove"             lib "japi"
    declare sub j_removeitem          alias "__j_scriba_removeitem"         lib "japi"
    declare sub j_removeall           alias "__j_scriba_removeall"          lib "japi"
    declare sub j_setstate            alias "__j_scriba_setstate"           lib "japi"
    declare sub j_setrows             alias "__j_scriba_setrows"            lib "japi"
    declare sub j_setcolumns          alias "__j_scriba_setcolumns"         lib "japi"
    declare sub j_seticon             alias "__j_scriba_seticon"            lib "japi"
    declare sub j_setimage            alias "__j_scriba_setimage"           lib "japi"
    declare sub j_setvalue            alias "__j_scriba_setvalue"           lib "japi"
    declare sub j_setradiogroup       alias "__j_scriba_setradiogroup"      lib "japi"
    declare sub j_setunitinc          alias "__j_scriba_setunitinc"         lib "japi"
    declare sub j_setblockinc         alias "__j_scriba_setblockinc"        lib "japi"
    declare sub j_setmin              alias "__j_scriba_setmin"             lib "japi"
    declare sub j_setmax              alias "__j_scriba_setmax"             lib "japi"
    declare sub j_setdanger           alias "__j_scriba_setdanger"          lib "japi"
    declare sub j_setslidesize        alias "__j_scriba_setslidesize"       lib "japi"
    declare sub j_setcursor           alias "__j_scriba_setcursor"          lib "japi"
    declare sub j_setresizable        alias "__j_scriba_setresizable"       lib "japi"
    declare sub j_getlength           alias "__j_scriba_getlength"          lib "japi"
    declare sub j_getvalue            alias "__j_scriba_getvalue"           lib "japi"
    declare sub j_getdanger           alias "__j_scriba_getdanger"          lib "japi"
    declare sub j_getscreenheight     alias "__j_scriba_getscreenheight"    lib "japi"
    declare sub j_getscreenwidth      alias "__j_scriba_getscreenwidth"     lib "japi"
    declare sub j_getheight           alias "__j_scriba_getheight"          lib "japi"
    declare sub j_getwidth            alias "__j_scriba_getwidth"           lib "japi"
    declare sub j_getinsets           alias "__j_scriba_getinsets"          lib "japi"
    declare sub j_getlayoutid         alias "__j_scriba_getlayoutid"        lib "japi"
    declare sub j_getinheight         alias "__j_scriba_getinheight"        lib "japi"
    declare sub j_getinwidth          alias "__j_scriba_getinwidth"         lib "japi"
    declare sub j_gettext             alias "__j_scriba_gettext"            lib "japi"
    declare sub j_getitem             alias "__j_scriba_getitem"            lib "japi"
    declare sub j_getitemcount        alias "__j_scriba_getitemcount"       lib "japi"
    declare sub j_delete              alias "__j_scriba_delete"             lib "japi"
    declare sub j_replacetext         alias "__j_scriba_replacetext"        lib "japi"
    declare sub j_appendtext          alias "__j_scriba_appendtext"         lib "japi"
    declare sub j_inserttext          alias "__j_scriba_inserttext"         lib "japi"
    declare sub j_settext             alias "__j_scriba_settext"            lib "japi"
    declare sub j_selectall           alias "__j_scriba_selectall"          lib "japi"
    declare sub j_selecttext          alias "__j_scriba_selecttext"         lib "japi"
    declare sub j_getselstart         alias "__j_scriba_getselstart"        lib "japi"
    declare sub j_getselend           alias "__j_scriba_getselend"          lib "japi"
    declare sub j_getseltext          alias "__j_scriba_getseltext"         lib "japi"
    declare sub j_getcurpos           alias "__j_scriba_getcurpos"          lib "japi"
    declare sub j_setcurpos           alias "__j_scriba_setcurpos"          lib "japi"
    declare sub j_setechochar         alias "__j_scriba_setechochar"        lib "japi"
    declare sub j_seteditable         alias "__j_scriba_seteditable"        lib "japi"
    declare sub j_setshortcut         alias "__j_scriba_setshortcut"        lib "japi"
    declare sub j_quit                alias "__j_scriba_quit"               lib "japi"
    declare sub j_kill                alias "__j_scriba_kill"               lib "japi"
    declare sub j_setsize             alias "__j_scriba_setsize"            lib "japi"
    declare sub j_getaction           alias "__j_scriba_getaction"          lib "japi"
    declare sub j_nextaction          alias "__j_scriba_nextaction"         lib "japi"
    declare sub j_show                alias "__j_scriba_show"               lib "japi"
    declare sub j_showpopup           alias "__j_scriba_showpopup"          lib "japi"
    declare sub j_add                 alias "__j_scriba_add"                lib "japi"
    declare sub j_release             alias "__j_scriba_release"            lib "japi"
    declare sub j_releaseall          alias "__j_scriba_releaseall"         lib "japi"
    declare sub j_hide                alias "__j_scriba_hide"               lib "japi"
    declare sub j_dispose             alias "__j_scriba_dispose"            lib "japi"
    declare sub j_setpos              alias "__j_scriba_setpos"             lib "japi"
    declare sub j_getviewportheight   alias "__j_scriba_getviewportheight"  lib "japi"
    declare sub j_getviewportwidth    alias "__j_scriba_getviewportwidth"   lib "japi"
    declare sub j_getxpos             alias "__j_scriba_getxpos"            lib "japi"
    declare sub j_getypos             alias "__j_scriba_getypos"            lib "japi"
    declare sub j_getpos              alias "__j_scriba_getpos"             lib "japi"
    declare sub j_getparentid         alias "__j_scriba_getparentid"        lib "japi"
    declare sub j_setfocus            alias "__j_scriba_setfocus"           lib "japi"
    declare sub j_hasfocus            alias "__j_scriba_hasfocus"           lib "japi"
    declare sub j_getstringwidth      alias "__j_scriba_getstringwidth"     lib "japi"
    declare sub j_getfontheight       alias "__j_scriba_getfontheight"      lib "japi"
    declare sub j_getfontascent       alias "__j_scriba_getfontascent"      lib "japi"
    declare sub j_keylistener         alias "__j_scriba_keylistener"        lib "japi"
    declare sub j_getkeycode          alias "__j_scriba_getkeycode"         lib "japi"
    declare sub j_getkeychar          alias "__j_scriba_getkeychar"         lib "japi"
    declare sub j_mouselistener       alias "__j_scriba_mouselistener"      lib "japi"
    declare sub j_getmousex           alias "__j_scriba_getmousex"          lib "japi"
    declare sub j_getmousey           alias "__j_scriba_getmousey"          lib "japi"
    declare sub j_getmousepos         alias "__j_scriba_getmousepos"        lib "japi"
    declare sub j_getmousebutton      alias "__j_scriba_getmousebutton"     lib "japi"
    declare sub j_focuslistener       alias "__j_scriba_focuslistener"      lib "japi"
    declare sub j_componentlistener   alias "__j_scriba_componentlistener"  lib "japi"
    declare sub j_windowlistener      alias "__j_scriba_windowlistener"     lib "japi"
    declare sub j_setflowlayout       alias "__j_scriba_setflowlayout"      lib "japi"
    declare sub j_setborderlayout     alias "__j_scriba_setborderlayout"    lib "japi"
    declare sub j_setgridlayout       alias "__j_scriba_setgridlayout"      lib "japi"
    declare sub j_setfixlayout        alias "__j_scriba_setfixlayout"       lib "japi"
    declare sub j_setnolayout         alias "__j_scriba_setnolayout"        lib "japi"
    declare sub j_setborderpos        alias "__j_scriba_setborderpos"       lib "japi"
    declare sub j_sethgap             alias "__j_scriba_sethgap"            lib "japi"
    declare sub j_setvgap             alias "__j_scriba_setvgap"            lib "japi"
    declare sub j_setinsets           alias "__j_scriba_setinsets"          lib "japi"
    declare sub j_setalign            alias "__j_scriba_setalign"           lib "japi"
    declare sub j_setflowfill         alias "__j_scriba_setflowfill"        lib "japi"
    declare sub j_translate           alias "__j_scriba_translate"          lib "japi"
    declare sub j_cliprect            alias "__j_scriba_cliprect"           lib "japi"
    declare sub j_drawrect            alias "__j_scriba_drawrect"           lib "japi"
    declare sub j_fillrect            alias "__j_scriba_fillrect"           lib "japi"
    declare sub j_drawroundrect       alias "__j_scriba_drawroundrect"      lib "japi"
    declare sub j_fillroundrect       alias "__j_scriba_fillroundrect"      lib "japi"
    declare sub j_drawoval            alias "__j_scriba_drawoval"           lib "japi"
    declare sub j_filloval            alias "__j_scriba_filloval"           lib "japi"
    declare sub j_drawcircle          alias "__j_scriba_drawcircle"         lib "japi"
    declare sub j_fillcircle          alias "__j_scriba_fillcircle"         lib "japi"
    declare sub j_drawarc             alias "__j_scriba_drawarc"            lib "japi"
    declare sub j_fillarc             alias "__j_scriba_fillarc"            lib "japi"
    declare sub j_drawline            alias "__j_scriba_drawline"           lib "japi"
    declare sub j_drawpolyline        alias "__j_scriba_drawpolyline"       lib "japi"
    declare sub j_drawpolygon         alias "__j_scriba_drawpolygon"        lib "japi"
    declare sub j_fillpolygon         alias "__j_scriba_fillpolygon"        lib "japi"
    declare sub j_drawpixel           alias "__j_scriba_drawpixel"          lib "japi"
    declare sub j_drawstring          alias "__j_scriba_drawstring"         lib "japi"
    declare sub j_setxor              alias "__j_scriba_setxor"             lib "japi"
    declare sub j_getimage            alias "__j_scriba_getimage"           lib "japi"
    declare sub j_getimagesource      alias "__j_scriba_getimagesource"     lib "japi"
    declare sub j_drawimagesource     alias "__j_scriba_drawimagesource"    lib "japi"
    declare sub j_getscaledimage      alias "__j_scriba_getscaledimage"     lib "japi"
    declare sub j_drawimage           alias "__j_scriba_drawimage"          lib "japi"
    declare sub j_drawscaledimage     alias "__j_scriba_drawscaledimage"    lib "japi"
    declare sub j_setcolor            alias "__j_scriba_setcolor"           lib "japi"
    declare sub j_setcolorbg          alias "__j_scriba_setcolorbg"         lib "japi"
    declare sub j_setnamedcolor       alias "__j_scriba_setnamedcolor"      lib "japi"
    declare sub j_setnamedcolorbg     alias "__j_scriba_setnamedcolorbg"    lib "japi"
    declare sub j_loadimage           alias "__j_scriba_loadimage"          lib "japi"
    declare sub j_saveimage           alias "__j_scriba_saveimage"          lib "japi"
    declare sub j_sync                alias "__j_scriba_sync"               lib "japi"
    declare sub j_beep                alias "__j_scriba_beep"               lib "japi"
    declare sub j_random              alias "__j_scriba_random"             lib "japi"
    declare sub j_sleep               alias "__j_scriba_sleep"              lib "japi"

50
What's New / ScriptBasic GUI
« on: May 04, 2013, 05:59:40 PM »
I thought I would post a few screen shots from a project I'm working on that is using ScriptBasic and IUP

Windows 7




Windows XP (flat image buttons)




Ubuntu 12.04 64 bit



51
What's New / ScriptBasic in hardward
« on: May 02, 2013, 09:36:52 AM »



Babel Buster SP Custom is the ultimate "universal" BACnet IP gateway. You write your own ScriptBasic program to communicate via RS-232 or RS-485 serial, or via TCP socket connection, to your non-BACnet device. Translate your data as needed, then place that data into BACnet objects accessible to any BACnet IP Client.

Home Page

University of Toronto ScriptBasic embedding project

52
DLLC / ScriptBasic IUP Windows (DLLC)
« on: April 11, 2013, 10:28:11 AM »
I wanted to give DLLC a good workout and selected the IUP cbox.c example to convert to ScriptBasic. Not only does it use about every control, it shows fixed positioning which was the purpose of the example. This example is dynamically scripted at run time using DLLC and the IUP DLLs.



cbox.sb
Code: [Select]
' IupCbox Example - fixed positioning

INCLUDE "iupinc.sb"

img_bits1 = """
 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1
,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1
,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1
,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1
,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1
,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1
,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1
,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,0,2,0,2,0,2,2,0,2,2,2,0,0,0,2,2,2,0,0,2,0,2,2,0,0,0,2,2,2
,2,2,2,0,2,0,0,2,0,0,2,0,2,0,2,2,2,0,2,0,2,2,0,0,2,0,2,2,2,0,2,2
,2,2,2,0,2,0,2,2,0,2,2,0,2,2,2,2,2,0,2,0,2,2,2,0,2,0,2,2,2,0,2,2
,2,2,2,0,2,0,2,2,0,2,2,0,2,2,0,0,0,0,2,0,2,2,2,0,2,0,0,0,0,0,2,2
,2,2,2,0,2,0,2,2,0,2,2,0,2,0,2,2,2,0,2,0,2,2,2,0,2,0,2,2,2,2,2,2
,2,2,2,0,2,0,2,2,0,2,2,0,2,0,2,2,2,0,2,0,2,2,0,0,2,0,2,2,2,0,2,2
,2,2,2,0,2,0,2,2,0,2,2,0,2,2,0,0,0,0,2,2,0,0,2,0,2,2,0,0,0,2,2,2
,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,2
,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,0,2,2,2,2,2,2,2,2
,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,2,2,2,2,2,2,2,2,2
,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1
,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1
,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1
,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1
,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
"""

img_bits2 = """
 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2
,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2
,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2
,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2
,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2
,2,2,2,2,2,2,2,2,2,2,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2
,2,2,2,2,2,2,2,2,2,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2
,2,2,2,2,2,2,2,2,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2
,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
,3,3,3,0,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
,3,3,3,0,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
,3,3,3,0,3,0,3,0,3,3,0,3,3,3,1,1,0,3,3,3,0,0,3,0,3,3,0,0,0,3,3,3
,3,3,3,0,3,0,0,3,0,0,3,0,3,0,1,1,3,0,3,0,3,3,0,0,3,0,3,3,3,0,3,3
,3,3,3,0,3,0,3,3,0,3,3,0,3,3,1,1,3,0,3,0,3,3,3,0,3,0,3,3,3,0,3,3
,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
,3,3,3,0,3,0,3,3,0,3,3,0,3,0,1,1,3,0,3,0,3,3,0,0,3,0,3,3,3,0,3,3
,3,3,3,0,3,0,3,3,0,3,3,0,3,3,1,1,0,0,3,3,0,0,3,0,3,3,0,0,0,3,3,3
,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,0,3,3,3,3,3,3,3,3
,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,0,3,3,3,0,3,3,3,3,3,3,3,3
,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,0,0,0,3,3,3,3,3,3,3,3,3
,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
,2,2,2,2,2,2,2,3,3,3,3,3,3,3,1,1,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,2,2,2,3,3,3,3,3,3,3,3,1,1,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
"""

FUNCTION create_mat
  mat = dllcall(IupMatrix, "")
  dllcall(IupSetAttribute, mat, "NUMCOL", "1")
  dllcall(IupSetAttribute, mat, "NUMLIN", "3")
  dllcall(IupSetAttribute, mat, "NUMCOL_VISIBLE", "1")
  dllcall(IupSetAttribute, mat, "NUMLIN_VISIBLE", "3")
  dllcall(IupSetAttribute, mat, "EXPAND", "NO")
  dllcall(IupSetAttribute, mat, "SCROLLBAR", "NO")

  dllcall(IupSetAttribute, mat, "0:0", "Inflation")
  dllcall(IupSetAttribute, mat, "1:0", "Medicine ")
  dllcall(IupSetAttribute, mat, "2:0", "Food")
  dllcall(IupSetAttribute, mat, "3:0", "Energy")
  dllcall(IupSetAttribute, mat, "0:1", "January 2000")
  dllcall(IupSetAttribute, mat, "1:1", "5.6")
  dllcall(IupSetAttribute, mat, "2:1", "2.2")
  dllcall(IupSetAttribute, mat, "3:1", "7.2")

  dllcall(IupSetAttribute, mat, "BGCOLOR", "255 255 255")
  dllcall(IupSetAttribute, mat, "BGCOLOR1:0", "255 128 0")
  dllcall(IupSetAttribute, mat, "BGCOLOR2:1", "255 128 0")
  dllcall(IupSetAttribute, mat, "FGCOLOR2:0", "255 0 128")
  dllcall(IupSetAttribute, mat, "FGCOLOR1:1", "255 0 128")

  dllcall(IupSetAttribute, mat, "CX", "600")
  dllcall(IupSetAttribute, mat, "CY", "250")

  create_mat = mat

END FUNCTION

FUNCTION createtree
  tree = dllcall(IupTree)
  dllcall(IupSetAttributes, tree, "FONT=COURIER_NORMAL_10, " & _
                         "NAME=Figures, " & _
                         "ADDBRANCH=3D, " & _
                         "ADDBRANCH=2D, " & _
                         "ADDLEAF1=trapeze, " & _
                         "ADDBRANCH1=parallelogram, " & _
                         "ADDLEAF2=diamond, " & _
                         "ADDLEAF2=square, " & _
                         "ADDBRANCH4=triangle, " & _
                         "ADDLEAF5=scalenus, " & _
                         "ADDLEAF5=isosceles, " & _
                         "ADDLEAF5=equilateral, " & _
                         "RASTERSIZE=180x180, " & _
                         "VALUE=6, " & _
                         "CTRL=ON, " & _
                         "SHIFT=ON, " & _
                         "CX=600, " & _
                         "CY=10, " & _
                         "ADDEXPANDED=NO")
  createtree = tree
END FUNCTION

SUB func_1
  img_1 = dllcall(IupImage, 32, 32, SB_CreateImg(img_bits1))
  dllcall(IupSetHandle, "img1", img_1)
  dllcall(IupSetAttribute, img_1, "0", "0 0 0")
  dllcall(IupSetAttribute, img_1, "1", "BGCOLOR")
  dllcall(IupSetAttribute, img_1, "2", "255 0 0")

  img_2 = dllcall(IupImage, 32, 32, SB_CreateImg(img_bits2))
  dllcall(IupSetHandle, "img2", img_2)
  dllcall(IupSetAttribute, img_2, "0", "0 0 0")
  dllcall(IupSetAttribute, img_2, "1", "0 255 0")
  dllcall(IupSetAttribute, img_2, "2", "BGCOLOR")
  dllcall(IupSetAttribute, img_2, "3", "255 0 0")

  _frm_1 = dllcall(IupFrame, _
    dllcall(IupVbox, _
      dllcall(IupSetAttributes, dllcall(IupButton, "Button Text", ""), "CINDEX=1"), _
      dllcall(IupSetAttributes, dllcall(IupButton, "", ""), "IMAGE=img1,CINDEX=2"), _
      dllcall(IupSetAttributes, dllcall(IupButton, "", ""), "IMAGE=img1,IMPRESS=img2,CINDEX=3"),0))
  dllcall(IupSetAttribute, _frm_1, "TITLE", "IupButton")
  dllcall(IupSetAttribute, _frm_1, "CX", "10")
  dllcall(IupSetAttribute, _frm_1, "CY", "180")

  _frm_2 = dllcall(IupFrame, _
    dllcall(IupVbox, _
      dllcall(IupSetAttributes, dllcall(IupLabel, "Label Text"), "CINDEX=1"), _
      dllcall(IupSetAttributes, dllcall(IupLabel, ""), "SEPARATOR=HORIZONTAL,CINDEX=2"), _
      dllcall(IupSetAttributes, dllcall(IupLabel, ""), "IMAGE=img1,CINDEX=3"), 0))
  dllcall(IupSetAttribute, _frm_2, "TITLE", "IupLabel")
  dllcall(IupSetAttribute, _frm_2, "CX", "200")
  dllcall(IupSetAttribute, _frm_2, "CY", "250")

  _frm_3 = dllcall(IupFrame, _
    dllcall(IupVbox, _
      dllcall(IupSetAttributes, dllcall(IupToggle, "Toggle Text", ""), "VALUE=ON,CINDEX=1"), _
      dllcall(IupSetAttributes, dllcall(IupToggle, "", ""), "IMAGE=img1,IMPRESS=img2,CINDEX=2"), _
      dllcall(IupSetAttributes, dllcall(IupFrame, dllcall(IupRadio, dllcall(IupVbox, _
        dllcall(IupSetAttributes, dllcall(IupToggle, "Toggle Text", ""), "CINDEX=3"), _
        dllcall(IupSetAttributes, dllcall(IupToggle, "Toggle Text", ""), "CINDEX=4"), 0))), "TITLE=IupRadio"), 0))
  dllcall(IupSetAttribute, _frm_3, "TITLE", "IupToggle")
  dllcall(IupSetAttribute, _frm_3, "CX", "400")
  dllcall(IupSetAttribute, _frm_3, "CY", "250")

  _text_1 = dllcall(IupText, "")
  dllcall(IupSetAttribute, _text_1, "VALUE", "IupText Text")
  dllcall(IupSetAttribute, _text_1, "SIZE", "80x")
  dllcall(IupSetAttribute, _text_1, "CINDEX", "1")
  dllcall(IupSetAttribute, _text_1, "CX", "10")
  dllcall(IupSetAttribute, _text_1, "CY", "100")

  _ml_1 = dllcall(IupMultiLine, "")
  dllcall(IupSetAttribute, _ml_1, "VALUE", "IupMultiline Text\nSecond Line\nThird Line")
  dllcall(IupSetAttribute, _ml_1, "SIZE", "80x60")
  dllcall(IupSetAttribute, _ml_1, "CINDEX", "1")
  dllcall(IupSetAttribute, _ml_1, "CX", "200")
  dllcall(IupSetAttribute, _ml_1, "CY", "100")

  _list_1 = dllcall(IupList, "")
  dllcall(IupSetAttribute, _list_1, "VALUE", "1")
  dllcall(IupSetAttribute, _list_1, "1", "Item 1 Text")
  dllcall(IupSetAttribute, _list_1, "2", "Item 2 Text")
  dllcall(IupSetAttribute, _list_1, "3", "Item 3 Text")
  dllcall(IupSetAttribute, _list_1, "CINDEX", "1")
  dllcall(IupSetAttribute, _list_1, "CX", "10")
  dllcall(IupSetAttribute, _list_1, "CY", "10")

  _list_2 = dllcall(IupList, "")
  dllcall(IupSetAttribute, _list_2, "DROPDOWN", "YES")
  dllcall(IupSetAttribute, _list_2, "VALUE", "2")
  dllcall(IupSetAttribute, _list_2, "1", "Item 1 Text")
  dllcall(IupSetAttribute, _list_2, "2", "Item 2 Text")
  dllcall(IupSetAttribute, _list_2, "3", "Item 3 Text")
  dllcall(IupSetAttribute, _list_2, "CINDEX", "2")
  dllcall(IupSetAttribute, _list_2, "CX", "200")
  dllcall(IupSetAttribute, _list_2, "CY", "10")

  _list_3 = dllcall(IupList, "")
  dllcall(IupSetAttribute, _list_3, "EDITBOX", "YES")
  dllcall(IupSetAttribute, _list_3, "VALUE", "3")
  dllcall(IupSetAttribute, _list_3, "1", "Item 1 Text")
  dllcall(IupSetAttribute, _list_3, "2", "Item 2 Text")
  dllcall(IupSetAttribute, _list_3, "3", "Item 3 Text")
  dllcall(IupSetAttribute, _list_3, "CINDEX", "3")
  dllcall(IupSetAttribute, _list_3, "CX", "400")
  dllcall(IupSetAttribute, _list_3, "CY", "10")

  _cnv_1 = dllcall(IupCanvas, "")
  dllcall(IupSetAttribute, _cnv_1, "RASTERSIZE", "100x100")
  dllcall(IupSetAttribute, _cnv_1, "POSX", "0")
  dllcall(IupSetAttribute, _cnv_1, "POSY", "0")
  dllcall(IupSetAttribute, _cnv_1, "BGCOLOR", "128 255 0")
  dllcall(IupSetAttribute, _cnv_1, "CX", "400")
  dllcall(IupSetAttribute, _cnv_1, "CY", "150")

  _ctrl_1 = dllcall(IupVal, "")
  dllcall(IupSetAttribute, _ctrl_1, "CX", "600")
  dllcall(IupSetAttribute, _ctrl_1, "CY", "200")

  _cbox = dllcall(IupCbox, _
                  _text_1, _
                    _ml_1, _
                  _list_1, _
                  _list_2, _
                  _list_3, _
                   _cnv_1, _
                  _ctrl_1, _
             createtree(), _
             create_mat(), _
                   _frm_1, _
                   _frm_2, _
                   _frm_3, _
                        0)
  dllcall(IupSetAttribute, _cbox, "SIZE", "480x200")

  hbox = dllcall(IupSetAttributes, dllcall(IupHbox, _cbox, 0), "MARGIN=10x10")

  dlg = dllcall(IupDialog, hbox)
  dllcall(IupSetHandle, "dlg", dlg)
  dllcall(IupSetAttribute, dlg, "TITLE", "Cbox Test")
END SUB


FUNCTION main(pProg)
  dllcall(IupOpen, 0, 0)
  dllcall(IupControlsOpen)
  func_1()
  dllcall(IupShowXY, dllcall(IupGetHandle, "dlg"), IUP_CENTER, IUP_CENTER)
  dllcall(IupMainLoop)
  dllcall(IupClose)
  main = TRUE
END FUNCTION



cbox.c



53
What's New / ScriptBasic Games
« on: March 20, 2013, 09:44:54 AM »
I converted a couple of Peter Wirbelauer's OxygenBasic games to ScriptBasic. If you haven't done so already, download the ScriptBasic 2.2 beta release for Windows and unzip it in the directory of choice. Set your system search path to the ScriptBasic bin directory. That will allow you to run ScriptBasic from anywhere and allow it to find it's configuration file that points to it's include and modules directories.

I have attached everything that is needed for each game. Make sure you copy the dllc.dll from the modules directory in the zip to the ScriptBasic modules directory. Feedback welcome.



SM.sbx
Code: [Select]
' ScriptBasic SokoMouse

INCLUDE "sbsw.inc"

SUB Initialize
  SW_DrawBmp p1, 0, 0, 640, 480, 0
' SW_BmpText fo, 200, 8, "SokoMouse", 24, 24
  zA = 0
  Notified = FALSE
  CALL ShowLevel
  FOR bc = 0 TO 299
    xBox[bc] = 0
    yBox[bc] = 0
    rBox[bc] = 0
    zBox[bc] = 0
    iBox[bc] = 0
  NEXT
  zR = 0
  vR = 0
  pHead = 3
  Ready = 0
  sl = 0
  cV = 0
  cR = 0
  Steps = 0
  RasReg = 0
  KeyR = 0
  KeyL = 0
  KeyU = 0
  KeyD = 0
  BoxRas = 0
  Turn = 1
  zTurn = 0
END SUB

SUB LoadMaps
  SW_LoadBytes "Maps/Map" & lev & "-1.bin", Map1
  SW_LoadBytes "Maps/Map" & lev & "-2.bin", Map2
  SW_LoadBytes "Maps/Map" & lev & "-3.bin", Map3
END SUB  
  
SUB ShowLevel
  SW_Sprite s8, 480, 450, zA
  SW_Sprite s9, 576, 450, zA
  SW_BmpText fo, 520, 450, FORMAT("%~00~",lev), 24, 24
  vA += 1
  IF vA = 8 THEN
    vA = 0
    zA = zA + 1
    IF zA = 4 THEN zA = 0
  END IF
END SUB

SUB ShowMaps
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map1[ibx]) = 3 THEN SW_Sprite s1, idx * 32, icx * 32, 3
      IF ASC(Map3[ibx]) = 2 THEN SW_Sprite s1, idx * 32, icx * 32, 2
      IF ASC(Map2[ibx]) = 5 THEN SW_Sprite s2, idx * 32, icx * 32, zR
    NEXT
  NEXT
  vR += 1
  IF vR = 10 THEN
    vR = 0
    zR += 1
  END IF
  IF zR = 4 THEN zR = 0
END SUB

SUB FindHead
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map3[ibx]) = 6 THEN
        xHead = idx * 32
        yHead = icx * 32
        rHead = 0
        zHead = 0
        EXIT SUB
      END IF
    NEXT
  NEXT
END SUB

SUB AllDone
  IF Ready >= 1 THEN EXIT SUB
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map2[ibx]) = 5 AND ASC(Map3[ibx]) <> 4 THEN
        EXIT SUB
      END IF
    NEXT
  NEXT
  Ready = 2
  RasReg = 1
  Turn = 0
  pHead = 0
  rTurn = SW_Rnd(1, 2)
  xTurn = xHead
  yTurn = yHead
END SUB

SUB TurnHead
  IF Turn > 0 THEN EXIT SUB
  IF rTurn = 1 THEN
    SW_Sprite s6, xTurn, yTurn, zTurn
  ELSE IF rTurn = 2 THEN
    SW_Sprite s7, xTurn, yTurn, zTurn
  END IF
  zTurn = zTurn + 1
  IF zTurn = 64 THEN zTurn = 0
END SUB

SUB FlashBox
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map2[ibx]) = 5 AND ASC(Map3[ibx]) = 4 THEN
        SW_Sprite s4, idx * 32, icx * 32, cR
      END IF
    NEXT
  NEXT
  cV += 1
  IF cV = 10 THEN
    cV = 0
    cR += 1
  END IF
  IF cR = 4 THEN cR = 0
END SUB

SUB ScanBoxes
  IF BoxRas > 0 THEN EXIT SUB
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map3[ibx]) = 4 THEN
        iBox[ibx] = 1
        xBox[ibx] = idx * 32
        yBox[ibx] = icx * 32
        rBox[ibx] = 0
      END IF
    NEXT
  NEXT
END SUB

SUB ShowBoxes
  FOR ibx = 20 TO 280
    IF iBox[ibx] = 1 AND rBox[ibx] = 0 THEN
      SW_Sprite s1, xBox[ibx], yBox[ibx], 4
    ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 1 THEN
      xBox[ibx] = xBox[ibx] + 2
      SW_Sprite s1, xBox[ibx], yBox[ibx], 4
      zBox[ibx] = zBox[ibx] + 2
      IF zBox[ibx] = 32 THEN
        zBox[ibx] = 0
        iBox[ibx] = 0
        icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
        Map3[icx] = CHR(4)
      END IF
    ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 2 THEN
      xBox[ibx] = xBox[ibx] - 2
      SW_Sprite s1, xBox[ibx], yBox[ibx], 4
      zBox[ibx] = zBox[ibx] + 2
      IF zBox[ibx] = 32 THEN
        zBox[ibx] = 0
        iBox[ibx] = 0
        icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
        Map3[icx] = CHR(4)
      END IF
    ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 3 THEN
      yBox[ibx] = yBox[ibx] - 2
      SW_Sprite s1, xBox[ibx], yBox[ibx], 4
      zBox[ibx] = zBox[ibx] + 2
      IF zBox[ibx] = 32 THEN
        zBox[ibx] = 0
        iBox[ibx] = 0
        icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
        Map3[icx] = CHR(4)
      END IF
    ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 4 THEN
      yBox[ibx] = yBox[ibx] + 2
      SW_Sprite s1, xBox[ibx], yBox[ibx], 4
      zBox[ibx] = zBox[ibx] + 2
      IF zBox[ibx] = 32 THEN
        zBox[ibx] = 0
        iBox[ibx] = 0
        icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
        Map3[icx] = CHR(4)
      END IF
    END IF
  NEXT
END SUB

SUB ScanHead
  IF RasReg > 0 THEN EXIT SUB
  idx = xHead / 32
  icx = yHead / 32
  ibx = icx * 20 + idx
  IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_right) AND ASC(Map3[ibx + 1]) = 4 AND ASC(Map3[ibx + 2]) = 0 AND KeyR = 0 THEN
    Map3[ibx] = CHR(0)
    Map3[ibx + 1] = CHR(6)
    rHead = 1
    pHead = 1
    BoxRas = 0
    xBox[ibx + 1] = xHead + 32
    yBox[ibx + 1] = yHead
    rBox[ibx + 1] = 1
    iBox[ibx + 1] = 1
    Steps += 1
    SW_PlayWav w2
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_left) AND ASC(Map3[ibx - 1]) = 4 AND ASC(Map3[ibx - 2]) = 0 AND KeyL = 0 THEN
    Map3[ibx] = CHR(0)
    Map3[ibx - 1] = CHR(6)
    rHead = 2
    pHead = 2
    BoxRas = 0
    xBox[ibx - 1] = xHead - 32
    yBox[ibx - 1] = yHead
    rBox[ibx - 1] = 2
    iBox[ibx - 1] = 1
    Steps += 1
    SW_PlayWav w2
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_up) AND ASC(Map3[ibx - 20]) = 4 AND ASC(Map3[ibx - 40]) = 0 AND KeyU = 0 THEN
    Map3[ibx] = CHR(0)
    Map3[ibx - 20] = CHR(6)
    rHead = 3
    pHead = 3
    BoxRas = 0
    xBox[ibx - 20] = xHead
    yBox[ibx - 20] = yHead - 32
    rBox[ibx - 20] = 3
    iBox[ibx - 20] = 1
    Steps += 1
    SW_PlayWav w2
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_down) AND ASC(Map3[ibx + 20]) = 4 AND ASC(Map3[ibx + 40]) = 0 AND KeyD = 0 THEN
    Map3[ibx] = CHR(0)
    Map3[ibx + 20] = CHR(6)
    rHead = 4
    pHead = 4
    BoxRas = 0
    xBox[ibx + 20] = xHead
    yBox[ibx + 20] = yHead + 32
    rBox[ibx + 20] = 4
    iBox[ibx + 20] = 1
    Steps += 1
    SW_PlayWav w2
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_right) AND ASC(Map3[ibx + 1]) = 0 AND KeyR = 0 THEN
    rHead = 1
    pHead = 1
    Map3[ibx] = CHR(0)
    Map3[ibx + 1] = CHR(6)
    Steps += 1
    SW_PlayWav w1
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_left) AND ASC(Map3[ibx - 1]) = 0 AND KeyL = 0 THEN
    rHead = 2
    pHead = 2
    Map3[ibx] = CHR(0)
    Map3[ibx - 1] = CHR(6)
    Steps += 1
    SW_PlayWav w1
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_up) AND ASC(Map3[ibx - 20]) = 0 AND KeyU = 0 THEN
    rHead = 3
    pHead = 3
    Map3[ibx] = CHR(0)
    Map3[ibx - 20] = CHR(6)
    Steps += 1
    SW_PlayWav w1
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_down) AND ASC(Map3[ibx + 20]) = 0 AND KeyD = 0 THEN
    rHead = 4
    pHead = 4
    Map3[ibx] = CHR(0)
    Map3[ibx + 20] = CHR(6)
    Steps += 1
    SW_PlayWav w1
  ELSE
    rHead = 0
  END IF
END SUB

SUB ShowHead
  IF rHead = 0 AND pHead = 1 THEN
    SW_Sprite s3, xHead, yHead, 3
  ELSE IF rHead = 0 AND pHead = 2 THEN
    SW_Sprite s3, xHead, yHead, 1
  ELSE IF rHead = 0 AND pHead = 3 THEN
    SW_Sprite s3, xHead, yHead, 0
  ELSE IF rHead = 0 AND pHead = 4 THEN
    SW_Sprite s3, xHead, yHead, 2
  ELSE IF rHead = 1 THEN
    xHead += 2
    SW_Sprite s3, xHead, yHead, 3
    RasReg += 2
    IF RasReg = 32 THEN
      RasReg = 0
      rHead = 0
    END IF
  ELSE IF rHead = 2 THEN
    xHead -= 2
    SW_Sprite s3, xHead, yHead, 1
    RasReg += 2
    IF RasReg = 32 THEN
      RasReg = 0
      rHead = 0
    END IF
  ELSE IF rHead = 3 THEN
    yHead -= 2
    SW_Sprite s3, xHead, yHead, 0
    RasReg += 2
    IF RasReg = 32 THEN
      RasReg = 0
      rHead = 0
    END IF
  ELSE IF rHead = 4 THEN
    yHead += 2
    SW_Sprite s3, xHead, yHead, 2
    RasReg += 2
    IF RasReg = 32 THEN
      RasReg = 0
      rHead = 0
    END IF
  END IF
END SUB

SUB MousePos
  xPos = FIX(SW_xMouse() / 32)
  yPos = FIX(SW_yMouse() / 32)
  IF SW_MouseButton() = 1 THEN
    IF xPos = 15 AND yPos = 14 AND lev > 1 AND ButtonC = 0 THEN
      lev -= 1
      ButtonC = 1
      SW_PlayWav w4
      Initialize
      LoadMaps
      FindHead
      EXIT SUB
    END IF
  END IF
  IF SW_MouseButton() = 1 THEN
    IF xPos = 18 AND yPos = 14 AND lev < 30 AND ButtonC = 0 THEN
      lev += 1
      ButtonC = 1
      SW_PlayWav w4
      Initialize
      LoadMaps
      FindHead
    END IF
  END IF
  IF SW_MouseButton() = 0 THEN ButtonC = 0
END SUB


' MAIN

SW_Window 640, 480, 1
SW_SetCaption "ScriptBasic SokoMouse"

SW_SetFps(60)

Q  = SW_LoadBmp("SokoMedia/sokomouse.bmp", 1)
p1 = SW_LoadBmp("SokoMedia/smbg.bmp", 1)
Fo = SW_LoadBmp("SokoMedia/FontStrip.bmp", 96)
s1 = SW_LoadBmp("SokoMedia/SokoStrip.bmp", 5)
s2 = SW_LoadBmp("SokoMedia/RundStrip.bmp", 4)
s3 = SW_LoadBmp("SokoMedia/HeadStrip.bmp", 4)
s4 = SW_LoadBmp("SokoMedia/BoxsStrip.bmp", 4)
s6 = SW_LoadBmp("SokoMedia/HeadStripR.bmp", 64)
s7 = SW_LoadBmp("SokoMedia/HeadStripL.bmp", 64)
s8 = SW_LoadBmp("SokoMedia/ArroStripL.bmp", 4)
s9 = SW_LoadBmp("SokoMedia/ArroStripR.bmp", 4)

w1 = "SokoMedia/move.wav"
w2 = "SokoMedia/push.wav"
w3 = "SokoMedia/done.wav"
w4 = "SokoMedia/clic.wav"


SW_Cls  0xCCCCCC
SW_Sprite Q, 180, 60, 0
SW_BmpText fo, 205, 32, "SOKOMOUSE", 24, 24
SW_BmpText fo, 170, 428, "PRESS ANY KEY", 24, 24
SW_WaitKey

lev = 1
Initialize
LoadMaps
ShowLevel
FindHead

WHILE SW_Key(27) = 0
  ShowMaps
  IF sl THEN ShowLevel
  ScanBoxes
  ScanHead
  ShowBoxes
  ShowHead
  FlashBox
  AllDone
  MousePos
  TurnHead
  IF SW_Key(vk_space) THEN
    SW_BmpText fo, 64, 420, "Wait...", 24, 24
    Initialize
    LoadMaps
    FindHead
  END IF
  IF Ready = 2 AND NOT(Notified) THEN
    SW_BmpText fo, 64, 450, Steps & " moves to solve.", 20, 20
    SW_Sync
    SW_PlayWav w3
    sl = 1
    Notified = TRUE
  END IF
  BoxRas += 2
  IF BoxRas = 32 THEN BoxRas = 0
  IF SW_Key(vk_right) = 0 THEN KeyR = 1
  IF SW_Key(vk_right)THEN
    KeyR = 0
    SW_Wait(10)
  END IF
  IF SW_Key(vk_left) = 0 THEN KeyL = 1
  IF SW_Key(vk_left) THEN
    KeyL = 0
    SW_Wait(10)
  END IF
  IF SW_Key(vk_up) = 0 THEN KeyU = 1
  IF SW_Key(vk_up) THEN
    KeyU = 0
    SW_Wait(10)
  END IF
  IF SW_Key(vk_down) = 0 THEN KeyD = 1
  IF SW_Key(vk_down) THEN
    KeyD = 0
    SW_Wait(10)
  END IF
  SW_Sync
WEND
SW_CloseWindow




BS.sbx
Code: [Select]
' ScriptBasic Angry Birds Lite

INCLUDE "sbsw.inc"

'   ********
SUB InitVars
'   ********
  SPLITA STRING(40,"0") BY "" TO xMeg
  SPLITA STRING(40,"0") BY "" TO yMeg
  SPLITA STRING(40,"0") BY "" TO zMeg
  SPLITA STRING(40,"0") BY "" TO xUfo
  SPLITA STRING(40,"0") BY "" TO yUfo
  SPLITA STRING(40,"0") BY "" TO zUfo
  SPLITA STRING(40,"0") BY "" TO rUfo
  SPLITA STRING(40,"0") BY "" TO iUfo
  SPLITA STRING(40,"0") BY "" TO nUfo
  SPLITA STRING(40,"0") BY "" TO xRok
  SPLITA STRING(40,"0") BY "" TO yRok
  SPLITA STRING(40,"0") BY "" TO rRok
  SPLITA STRING(40,"0") BY "" TO xBum
  SPLITA STRING(40,"0") BY "" TO yBum
  SPLITA STRING(40,"0") BY "" TO iBum
  SPLITA STRING(40,"0") BY "" TO zBum
  SPLITA STRING(40,"0") BY "" TO vBum
  
  xRak = 0
  yRak = 0
  rRak = 0
  zRak = 0
  iBx = 0
  iDx = 0
  iCx = 0
  iAx = 0
  zFrame = 0
  z1 = 0
  z2 = 0
  z3 = 0
  z4 = 0
  bmap = 0
  w1 = 0
  w2 = 0
  w3 = 0
  s = 0
  y = 0
  sc = 0
  uz = 0
  jx = 0
  drop = 0
  Ok = 0
  count = 0
  px = 0
  
  jv = 0.0
  zv = 0.0
  dv = 0.0
  za = 0.0

END SUB

'        *************
FUNCTION CircleCollide(x1, y1, r1, x2, y2, r2)
'        *************
  IF SQR((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) <  r1 + r2 THEN
    CircleCollide = 1
  END IF
END FUNCTION

'   ******
SUB Timer1
'   ******
  dv = dv + 0.1
  IF dv >= 1 THEN
    dv = 0
    zFrame += 1
    IF zFrame = 8 THEN zFrame = 0
  END IF
END SUB

'   ******
SUB Timer2
'   ******
  jv = jv + 1
  IF jv = 50 THEN
    jv = 0
    jx = jx + 1
    IF jx = 21 THEN jx = 0
  END IF
END SUB

'   ******
SUB Timer3
'   ******
  Drop = SW_Rnd(0,40)
END SUB

'   ******
SUB Timer4
'   ******
  IF Ok = 1 THEN EXIT SUB
  za += .2
  IF za >= 5 THEN
    za = 0
    count = count - 1
    IF count <= 0 THEN count = 0
  END IF
END SUB

'   *********
SUB SetExplos(xx, yy, ii)
'   *********
  FOR iDx = 0 TO 39
    IF yBum[iDx] = 0 THEN
      xBum[iDx] = xx
      yBum[iDx] = yy
      iBum[iDx] = ii
      EXIT SUB
    END IF
  NEXT
END SUB

'   **********
SUB ShowExplos
'   **********
  FOR iDx = 0 TO 39
  IF iBum[iDx] = 1 THEN
    SW_DrawTile bmap, xBum[iDx], yBum[iDx], 64, 64, zBum[iDx], 1
    vBum[iDx] = vBum[iDx] + 0.1
    IF vBum[iDx] >= 1 THEN
      vBum[iDx] = 0
      zBum[iDx] = zBum[iDx] + 1
    END IF
    IF zBum[iDx] = 8 THEN
      zBum[iDx] = 0
      yBum[iDx] = 0
      iBum[iDx] = 0
      vBum[iDx] = 0
    END IF
  END IF
  NEXT
END SUB

'   *********
SUB SetRocket(xx, yy)
'   *********
  FOR iAx = 0 TO 39
  IF yRok[iAx] = 0 THEN
    xRok[iAx] = xx
    yRok[iAx] = yy
    rRok[iAx] = 1
    EXIT SUB
  END IF
  NEXT
END SUB

'   **********
SUB ScanRocket
'   **********
  FOR iAx = 0 TO 39
  IF rRok[iAx] = 1 AND yRok[iAx] <= -32 THEN
    rRok[iAx] = 0
    yRok[iAx] = 0
  END IF
  NEXT
END SUB

'   **********
SUB ShowRocket
'   **********
  FOR iAx = 0 TO 39
  IF rRok[iAx] = 1 THEN
    SW_DrawTile bmap, xRok[iAx], yRok[iAx], 64, 64, zFrame, 0
    yRok[iAx] = yRok[iAx] - 4
    IF yRok[iAx] = 400 THEN zRak = 0
  END IF
  NEXT
END SUB

'   **********
SUB ScanRakete
'   **********
  IF rRak = 5 THEN EXIT SUB
  IF SW_Key(32) AND SW_Key(39) AND zRak = 0 THEN
    SetRocket(xRak, yRak)
    rRak = 1
    zRak = 1
    SW_PlayWav w1
  ELSE IF SW_Key(32) AND SW_Key(37) AND zRak = 0 THEN
    SetRocket(xRak, yRak)
    rRak = 2
    zRak =1
    SW_PlayWav w1
  ELSE IF SW_Key(32) AND zRak = 0 THEN
    SetRocket(xRak, yRak)
    zRak = 1
    SW_PlayWav w1
  ELSE IF SW_Key(39) AND xRak < 736 THEN
    rRak = 1
  ELSE IF SW_Key(37) AND xRak > 0 THEN
    rRak = 2
  ELSE
    rRak = 0  
  END IF
END SUB

'   **********
SUB ShowRakete
'   **********
  IF rRak = 0 THEN
    SW_DrawTile bmap, xRak, yRak, 64, 64, zFrame, 4
  ELSE IF rRak = 1 THEN
    SW_DrawTile bmap, xRak, yRak, 64, 64, zFrame, 4
    xRak = xRak + 1
  ELSE IF rRak = 2 THEN
    SW_DrawTile bmap, xRak, yRak, 64, 64, zFrame, 4
    xRak = xRak - 1
  END IF
END SUB

'   ***************
SUB RocketCollision
'   ***************
  FOR iBx = 0 TO uz
    FOR iCx = 0 TO 39
      IF rRok[iCx] > 0 AND rUfo[iBx] > 0 THEN
        IF CircleCollide(xRok[iCx] + 32, yRok[iCx] + 32, 16, xUfo[iBx] + 32, yUfo[iBx] + 32, 16) = 1 THEN
          SetExplos(xUfo[iBx], yUfo[iBx], 1)
          rRok[iCx] = 0
          yRok[iCx] = 0
          rUfo[iBx] = 0
          yUfo[iBx] = 0
          SW_PlayWav w2
          sc = sc + 25
          EXIT SUB
        END IF
      END IF
    NEXT
  NEXT
END SUB

'   ***************
SUB RaketeCollision
'   ***************
  IF Ok = 1 THEN EXIT SUB
  FOR iAx = 0 TO 40
    IF yMeg[iAx] > 0 THEN
      IF CircleCollide(xRak, yRak, 16, xMeg[iAx], yMeg[iAx], 16) = 1 THEN
        SetExplos(xRak, yRak, 1)
        rRak = 5
        Ok = 1
        SW_PlayWav w3
        EXIT SUB
      END IF
    END IF
  NEXT
END SUB

'   *******
SUB SetUfos
'   *******
  FOR iAx = 0 TO uz
    xUfo[iAx] = SW_Rnd(16,736)
    yUfo[iAx] = SW_Rnd(16,300)
    rUfo[iAx] = SW_Rnd(1,4)
    zUfo[iAx] = 0
    nUfo[iAX] = 0
  NEXT
END SUB

'   ********
SUB ScanUfos
'   ********
  FOR iBx = 0 TO uz
    IF rUfo[iBx] = 1 AND xUfo[iBx] >= 736 THEN
      rUfo[iBx] = 2
    ELSE IF rUfo[iBx] = 2 AND xUfo[iBx] <= 0 THEN
      rUfo[iBx] = 1
    ELSE IF rUfo[iBx] = 3 AND yUfo[iBx] <= 0 THEN
      rUfo[iBx] = 4
    ELSE IF rUfo[iBx] = 4 AND yUfo[iBx] >= 350 THEN
      rUfo[iBx] = 3
    ELSE IF jx = 5 AND rUfo[iBx] = 4 THEN
      rUfo[iBx] = SW_Rnd(1,4)
    ELSE IF jx = 10 AND rUfo[iBx] = 3 THEN
      rUfo[iBx] = SW_Rnd(1,4)
    ELSE IF jx = 15 AND rUfo[iBx] = 2 THEN
      rUfo[iBx] = SW_Rnd(1,4)
    ELSE IF jx = 20 AND rUfo[iBx] = 1 THEN
      rUfo[iBx] = SW_Rnd(1,4)
    END IF
  NEXT
END SUB

'   ********
SUB ShowUfos
'   ********
  FOR iBx = 0 TO uz
    IF rUfo[iBx] = 1 THEN
      SW_DrawTile bmap, xUfo[iBx], yUfo[iBx], 64, 64, zFrame, 2
      xUfo[iBx] = xUfo[iBx] + 1
    ELSE IF rUfo[iBx] = 2 THEN
      SW_DrawTile bmap, xUfo[iBx], yUfo[iBx], 64, 64, zFrame, 2
      xUfo[iBx] = xUfo[iBx] - 1
    ELSE IF rUfo[iBx] = 3 THEN
      SW_DrawTile bmap, xUfo[iBx], yUfo[iBx], 64, 64, zFrame, 2
      yUfo[iBx] = yUfo[iBx] - 1
    ELSE IF rUfo[iBx] = 4 THEN
      SW_DrawTile bmap, xUfo[iBx], yUfo[iBx], 64, 64, zFrame, 2
      yUfo[iBx] = yUfo[iBx] + 1
    END IF
  NEXT
END SUB

'   *******
SUB SetData
'   *******
  xRak = 384
  yRak = 536
  rRak = 0
  za = 0
  uz = 40
  sc = 0
  Ok = 0
  count = 300
  SetUfos
  FOR iBx = 0 TO 40
    yMeg[iBx] = 0
    xMeg[iBx] = 0
  NEXT
END SUB

'   ********
SUB TestUfos
'   ********
  FOR iAx = 0 TO 40
    IF yUfo[iAx] > 0 OR Ok = 1 THEN EXIT SUB
  NEXT
  Ok = 1
  sc += count
END SUB

'   ************
SUB ScanUfoBombs
'   ************
  FOR iAx = 0 TO drop STEP 2
    IF rUfo[iAx] > 0 THEN
      IF yMeg[iAx] = 0 THEN
        xMeg[iAx] = xUfo[iAx]
        yMeg[iAx] = yUfo[iAx] + 32
      END IF
    END IF
  NEXT
END SUB

'   ********
SUB UfoBombs
'   ********
  FOR iDx = 0 TO 40
    IF yMeg[iDx] > 0 THEN
      IF iDx < 20 THEN
        SW_DrawTile bmap, xMeg[iDx], yMeg[iDx], 64, 64, zFrame, 3
      ELSE IF iDx >= 20 THEN
        SW_DrawTile bmap, xMeg[iDx], yMeg[iDx], 64, 64, zFrame, 3
      END IF
      yMeg[iDx] = yMeg[iDx] + 1
      IF yMeg[iDx] >= 600 THEN yMeg[iDx] = 0
    END IF
  NEXT
END SUB

' *******
'  MAIN *
' *******  

InitVars

SW_Window 800, 600, 1
SW_SetFont 28, 48, 0, ""
bmap = SW_LoadTile("bmp/bitmap.bmp", 8, 5)
w1 = "bmp/shoot.wav"
w2 = "bmp/explo.wav"
w3 = "bmp/xship.wav"
SW_ShowMouse 0
SetData
SW_SetFPS 60

WHILE SW_Key(27) = 0
  SW_Cls 0
  SW_SetCaption "Frames " & SW_ShowFPS()
  IF Ok = 1 THEN
    SW_SetText 460, 0, "SCORE " & sc, SW_RGB(255,255,255)
  ELSE IF Ok = 0 THEN
    SW_SetText 460, 0, "SCORE " & sc, SW_RGB(255,255,255)
  END IF
  ScanUfos
  ShowUfos
  ScanRocket
  ShowRocket
  ScanRakete
  ShowRakete
  ScanUfoBombs
  UfoBombs
  ShowExplos
  RocketCollision
  RaketeCollision
  TestUfos
  Timer1
  Timer2
  Timer3
  Timer4
  IF Ok = 1 THEN
    SW_SetText 240, 300, "ONCE AGAIN?", SW_RGB(255,255,255)
    SW_SetText 240, 344, "HIT [c] KEY", SW_RGB(255,255,255)
    IF SW_Key(67) THEN SetData()
  END IF
  SW_SetText 16, 0, "BONUS " & count, SW_RGB(255,255,255)
  SW_Sync
WEND
SW_Quit

The competition aspect of these games is being featured on the All Basic Forum if you would like to participate.


54
DLLC / FreeImage with DLLC
« on: March 13, 2013, 09:52:29 PM »
I converted one of my old FreeImage SB examples using GTK-Server to DLLC. I have attached a new DLLC that handles the weird FreeImage function names. (direct access without going through a wrapper)

Code: OxygenBasic
  1. ' FreeImage Example
  2.  
  3. DECLARE SUB DLLC_File ALIAS "dllfile" LIB "DLLC"
  4. DECLARE SUB DLLC_Proc ALIAS "dllproc" LIB "DLLC"
  5. DECLARE SUB DLLC_Call ALIAS "dllcall" LIB "DLLC"
  6.  
  7. fih = DLLC_File("FreeImage.dll")
  8.  
  9. Version = DLLC_Proc(fih,"_FreeImage_GetVersion@0 z = ( )")
  10. Copyright = DLLC_Proc(fih,"_FreeImage_GetCopyrightMessage@0 z = ( )")
  11. LoadImage  = DLLC_Proc(fih,"_FreeImage_Load@12 i = (i fif, z filename, i flag)")
  12. Width = DLLC_Proc(fih,"_FreeImage_GetWidth@4 i = (i dib)")
  13. Height = DLLC_Proc(fih,"_FreeImage_GetHeight@4 i = (i dib)")
  14. Rescale = DLLC_Proc(fih,"_FreeImage_Rescale@16 i = (i dib, i dst_width, i dst_height, i filter)")
  15. Rotate = DLLC_Proc(fih,"_FreeImage_Rotate@16 i = (i dib, d angle, p bkcolor)")
  16. Save = DLLC_Proc(fih,"_FreeImage_Save@16 b = (i fif, i dib, z fname, i flage)")
  17.  
  18. CONST FIF_BMP  =  0
  19. CONST FIF_JPEG =  2
  20. CONST FIF_PNG  = 13
  21. CONST FIF_GIF  = 25
  22. CONST FILTER_BICUBIC = 1
  23.  
  24. PRINT DLLC_Call(Version),"\n"
  25. PRINT DLLC_Call(Copyright),"\n"
  26. fbmp = DLLC_Call(LoadImage, FIF_JPEG, "world.jpg", 0)
  27. PRINT "Width: ",DLLC_Call(Width, fbmp),"\n"
  28. PRINT "Height: ",DLLC_Call(Height, fbmp),"\n"
  29. fbmps = DLLC_Call(Rescale, fbmp, 100, 100, FILTER_BICUBIC)
  30. DLLC_Call(Save, FIF_PNG, fbmps, "world_small.png", 0)
  31. fbmpr = DLLC_Call(Rotate, fbmp, 180, 0)
  32. DLLC_Call(Save, FIF_PNG, fbmpr, "world_flip.png", 0)
  33.  

C:\SB22\test>scriba testfi.sb
3.15.4
This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See http://freeimage.sourceforge.net for details
Width: 225
Height: 225
C:\SB22\test>

Original .jpg image


Rescaled and converted to .png


Flipped 180 degrees


55
What's New / ScriptBasic 2.2 Beta - Feedback
« on: February 21, 2013, 10:01:33 AM »
Most if not all of these issues are due to missing dependencies. I attached a Text File that listed the packages that needed to be installed. You also need to install IUP. (runtime files are all that is needed)

My mistake. The wc.sb word count program is using the sort option for Windows not Linux. Change them to -o instead and it will work fine. I'll fix that in the next build.

Make sure you are using the hash.so that came with 2.2 as the 2.1 version had issues.
Make sure your scriba|basic.conf is pointing to the right modules directory. (scriba -D)

testhash.sb
Code: [Select]
IMPORT hash.bas

h = hash::New()
hash::SetValue(h,"1234567890A",1)
hash::SetValue(h,"12345678901234567890B",2)
hash::SetValue(h,"123456789012345678901234567890C",3)
hash::Start(h)

FOR x = 1 to 3
  PRINT hash::ThisKey(h), " - "
  PRINT hash::ThisValue(h),"\n"
  hash::Next(h)
NEXT x

hash::Release(h)

jrs@U32VB:~/sb22/test$ scriba testhash.sb
1234567890A - 1
12345678901234567890B - 2
123456789012345678901234567890C - 3
jrs@U32VB:~/sb22/test$


Thanks again for your testing and feedback.



56
What's New / ScriptBasic SokoMouse Game
« on: February 20, 2013, 09:38:51 PM »




The attached zip contains all the files to run the SokoMouse game on a ScriptBasic for Windows installed system. The spacebar will reset the level if you need to start the level over. Click the rotating arrows to scroll through the levels. SokoMouse supports sound so don't forget to turn on those speakers.

This project was just a proof of concept to show that ScriptBasic is robust enough to support a GUI game engine.

Code: [Select]
' ScriptBasic SokoMouse

INCLUDE "sw.inc"

SUB Initialize
  DrawBmp p1, 0, 0, 640, 480, 0
  CALL ShowLevel
  FOR bc = 0 TO 299
    xBox[bc] = 0
    yBox[bc] = 0
    rBox[bc] = 0
    zBox[bc] = 0
    iBox[bc] = 0
  NEXT
  zR = 0
  vR = 0
  zA = 0
  pHead = 3
  Ready = 0
  sl = 0
  cV = 0
  cR = 0
  Steps = 0
  RasReg = 0
  KeyR = 0
  KeyL = 0
  KeyU = 0
  KeyD = 0
  BoxRas = 0
  Turn = 1
  zTurn = 0
END SUB

SUB LoadMaps
  LoadBytes "Maps/Map" & lev & "-1.bin", Map1
  LoadBytes "Maps/Map" & lev & "-2.bin", Map2
  LoadBytes "Maps/Map" & lev & "-3.bin", Map3
END SUB  
  
SUB ShowLevel
  Sprite s8, 480, 420, zA
  Sprite s9, 576, 420, zA
  IF lev < 10 THEN
    BmpText fo, 520, 420, Nums[lev], 24, 24
  ELSE
    BmpText fo, 520, 420, STR(lev), 24, 24
  END IF
  vA += 1
  IF vA = 8 THEN
    vA = 0
    zA = zA + 1
    IF zA = 4 THEN zA = 0
  END IF
END SUB

SUB ShowMaps
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map1[ibx]) = 3 THEN Sprite s1, idx * 32, icx * 32, 3
      IF ASC(Map3[ibx]) = 2 THEN Sprite s1, idx * 32, icx * 32, 2
      IF ASC(Map2[ibx]) = 5 THEN Sprite s2, idx * 32, icx * 32, zR
    NEXT
  NEXT
  vR += 1
  IF vR = 10 THEN
    vR = 0
    zR += 1
  END IF
  IF zR = 4 THEN zR = 0
END SUB

SUB FindHead
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map3[ibx]) = 6 THEN
        xHead = idx * 32
        yHead = icx * 32
        rHead = 0
        zHead = 0
        EXIT SUB
      END IF
    NEXT
  NEXT
END SUB

SUB AllDone
  IF Ready >= 1 THEN EXIT SUB
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map2[ibx]) = 5 AND ASC(Map3[ibx]) <> 4 THEN
        EXIT SUB
      END IF
    NEXT
  NEXT
  PlaySound w3
  Ready = 2
  RasReg = 1
  Turn = 0
  pHead = 0
  rTurn = Rand(1, 2)
  xTurn = xHead
  yTurn = yHead
END SUB

SUB TurnHead
  IF Turn > 0 THEN EXIT SUB
  IF rTurn = 1 THEN
    Sprite s6, xTurn, yTurn, zTurn
  ELSE IF rTurn = 2 THEN
    Sprite s7, xTurn, yTurn, zTurn
  END IF
  zTurn = zTurn + 1
  IF zTurn = 64 THEN zTurn = 0
END SUB

SUB FlashBox
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map2[ibx]) = 5 AND ASC(Map3[ibx]) = 4 THEN
        Sprite s4, idx * 32, icx * 32, cR
      END IF
    NEXT
  NEXT
  cV += 1
  IF cV = 10 THEN
    cV = 0
    cR += 1
  END IF
  IF cR = 4 THEN cR = 0
END SUB

SUB ScanBoxes
  IF BoxRas > 0 THEN EXIT SUB
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map3[ibx]) = 4 THEN
        iBox[ibx] = 1
        xBox[ibx] = idx * 32
        yBox[ibx] = icx * 32
        rBox[ibx] = 0
      END IF
    NEXT
  NEXT
END SUB

SUB ShowBoxes
  FOR ibx = 20 TO 280
    IF iBox[ibx] = 1 AND rBox[ibx] = 0 THEN
      Sprite s1, xBox[ibx], yBox[ibx], 4
    ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 1 THEN
      xBox[ibx] = xBox[ibx] + 2
      Sprite s1, xBox[ibx], yBox[ibx], 4
      zBox[ibx] = zBox[ibx] + 2
      IF zBox[ibx] = 32 THEN
        zBox[ibx] = 0
        iBox[ibx] = 0
        icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
        Map3[icx] = CHR(4)
      END IF
    ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 2 THEN
      xBox[ibx] = xBox[ibx] - 2
      Sprite s1, xBox[ibx], yBox[ibx], 4
      zBox[ibx] = zBox[ibx] + 2
      IF zBox[ibx] = 32 THEN
        zBox[ibx] = 0
        iBox[ibx] = 0
        icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
        Map3[icx] = CHR(4)
      END IF
    ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 3 THEN
      yBox[ibx] = yBox[ibx] - 2
      Sprite s1, xBox[ibx], yBox[ibx], 4
      zBox[ibx] = zBox[ibx] + 2
      IF zBox[ibx] = 32 THEN
        zBox[ibx] = 0
        iBox[ibx] = 0
        icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
        Map3[icx] = CHR(4)
      END IF
    ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 4 THEN
      yBox[ibx] = yBox[ibx] + 2
      Sprite s1, xBox[ibx], yBox[ibx], 4
      zBox[ibx] = zBox[ibx] + 2
      IF zBox[ibx] = 32 THEN
        zBox[ibx] = 0
        iBox[ibx] = 0
        icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
        Map3[icx] = CHR(4)
      END IF
    END IF
  NEXT
END SUB

SUB ScanHead
  IF RasReg > 0 THEN EXIT SUB
  idx = xHead / 32
  icx = yHead / 32
  ibx = icx * 20 + idx
  IF ASC(Map3[ibx]) = 6 AND Key(vk_right) AND ASC(Map3[ibx + 1]) = 4 AND ASC(Map3[ibx + 2]) = 0 AND KeyR = 0 THEN
    Map3[ibx] = CHR(0)
    Map3[ibx + 1] = CHR(6)
    rHead = 1
    pHead = 1
    BoxRas = 0
    xBox[ibx + 1] = xHead + 32
    yBox[ibx + 1] = yHead
    rBox[ibx + 1] = 1
    iBox[ibx + 1] = 1
    Steps += 1
    PlaySound w2
  ELSE IF ASC(Map3[ibx]) = 6 AND Key(vk_left) AND ASC(Map3[ibx - 1]) = 4 AND ASC(Map3[ibx - 2]) = 0 AND KeyL = 0 THEN
    Map3[ibx] = CHR(0)
    Map3[ibx - 1] = CHR(6)
    rHead = 2
    pHead = 2
    BoxRas = 0
    xBox[ibx - 1] = xHead - 32
    yBox[ibx - 1] = yHead
    rBox[ibx - 1] = 2
    iBox[ibx - 1] = 1
    Steps += 1
    PlaySound w2
  ELSE IF ASC(Map3[ibx]) = 6 AND Key(vk_up) AND ASC(Map3[ibx - 20]) = 4 AND ASC(Map3[ibx - 40]) = 0 AND KeyU = 0 THEN
    Map3[ibx] = CHR(0)
    Map3[ibx - 20] = CHR(6)
    rHead = 3
    pHead = 3
    BoxRas = 0
    xBox[ibx - 20] = xHead
    yBox[ibx - 20] = yHead - 32
    rBox[ibx - 20] = 3
    iBox[ibx - 20] = 1
    Steps += 1
    PlaySound w2
  ELSE IF ASC(Map3[ibx]) = 6 AND Key(vk_down) AND ASC(Map3[ibx + 20]) = 4 AND ASC(Map3[ibx + 40]) = 0 AND KeyD = 0 THEN
    Map3[ibx] = CHR(0)
    Map3[ibx + 20] = CHR(6)
    rHead = 4
    pHead = 4
    BoxRas = 0
    xBox[ibx + 20] = xHead
    yBox[ibx + 20] = yHead + 32
    rBox[ibx + 20] = 4
    iBox[ibx + 20] = 1
    Steps += 1
    PlaySound w2
  ELSE IF ASC(Map3[ibx]) = 6 AND Key(vk_right) AND ASC(Map3[ibx + 1]) = 0 AND KeyR = 0 THEN
    rHead = 1
    pHead = 1
    Map3[ibx] = CHR(0)
    Map3[ibx + 1] = CHR(6)
    Steps += 1
    PlaySound w1
  ELSE IF ASC(Map3[ibx]) = 6 AND Key(vk_left) AND ASC(Map3[ibx - 1]) = 0 AND KeyL = 0 THEN
    rHead = 2
    pHead = 2
    Map3[ibx] = CHR(0)
    Map3[ibx - 1] = CHR(6)
    Steps += 1
    PlaySound w1
  ELSE IF ASC(Map3[ibx]) = 6 AND Key(vk_up) AND ASC(Map3[ibx - 20]) = 0 AND KeyU = 0 THEN
    rHead = 3
    pHead = 3
    Map3[ibx] = CHR(0)
    Map3[ibx - 20] = CHR(6)
    Steps += 1
    PlaySound w1
  ELSE IF ASC(Map3[ibx]) = 6 AND Key(vk_down) AND ASC(Map3[ibx + 20]) = 0 AND KeyD = 0 THEN
    rHead = 4
    pHead = 4
    Map3[ibx] = CHR(0)
    Map3[ibx + 20] = CHR(6)
    Steps += 1
    PlaySound w1
  ELSE
    rHead = 0
  END IF
END SUB

SUB ShowHead
  IF rHead = 0 AND pHead = 1 THEN
    Sprite s3, xHead, yHead, 3
  ELSE IF rHead = 0 AND pHead = 2 THEN
    Sprite s3, xHead, yHead, 1
  ELSE IF rHead = 0 AND pHead = 3 THEN
    Sprite s3, xHead, yHead, 0
  ELSE IF rHead = 0 AND pHead = 4 THEN
    Sprite s3, xHead, yHead, 2
  ELSE IF rHead = 1 THEN
    xHead += 2
    Sprite s3, xHead, yHead, 3
    RasReg += 2
    IF RasReg = 32 THEN
      RasReg = 0
      rHead = 0
    END IF
  ELSE IF rHead = 2 THEN
    xHead -= 2
    Sprite s3, xHead, yHead, 1
    RasReg += 2
    IF RasReg = 32 THEN
      RasReg = 0
      rHead = 0
    END IF
  ELSE IF rHead = 3 THEN
    yHead -= 2
    Sprite s3, xHead, yHead, 0
    RasReg += 2
    IF RasReg = 32 THEN
      RasReg = 0
      rHead = 0
    END IF
  ELSE IF rHead = 4 THEN
    yHead += 2
    Sprite s3, xHead, yHead, 2
    RasReg += 2
    IF RasReg = 32 THEN
      RasReg = 0
      rHead = 0
    END IF
  END IF
END SUB

SUB MousePos
  xPos = FIX(xMouse() / 32)
  yPos = FIX(yMouse() / 32)
  IF MouseButton() = 1 THEN
    IF xPos = 15 AND yPos = 13 AND lev > 1 AND ButtonC = 0 THEN
      lev -= 1
      ButtonC = 1
      PlaySound w4
      ' Sync
      Initialize
      LoadMaps
      FindHead
      EXIT SUB
    END IF
  END IF
  IF MouseButton() = 1 THEN
    IF xPos = 18 AND yPos = 13 AND lev < 9 AND ButtonC = 0 THEN
      lev += 1
      ButtonC = 1
      PlaySound w4
      ' Sync
      Initialize
      LoadMaps
      FindHead
    END IF
  END IF
  IF MouseButton() = 0 THEN ButtonC = 0
END SUB


' MAIN

Window 640, 480, 1
SetCaption "ScriptBasic SokoMouse"

SetFps(60)

Q  = LoadBmp("SokoMedia/sokomouse.bmp", 1)
p1 = LoadBmp("SokoMedia/Phantasie.bmp", 1)
Fo = LoadBmp("SokoMedia/FontStrip.bmp", 96)
s1 = LoadBmp("SokoMedia/SokoStrip.bmp", 5)
s2 = LoadBmp("SokoMedia/RundStrip.bmp", 4)
s3 = LoadBmp("SokoMedia/HeadStrip.bmp", 4)
s4 = LoadBmp("SokoMedia/BoxsStrip.bmp", 4)
s6 = LoadBmp("SokoMedia/HeadStripR.bmp", 64)
s7 = LoadBmp("SokoMedia/HeadStripL.bmp", 64)
s8 = LoadBmp("SokoMedia/ArroStripL.bmp", 4)
s9 = LoadBmp("SokoMedia/ArroStripR.bmp", 4)

w1 = "SokoMedia/move.wav"
w2 = "SokoMedia/push.wav"
w3 = "SokoMedia/done.wav"
w4 = "SokoMedia/clic.wav"

Nums[1] = "01"
Nums[2] = "02"
Nums[3] = "03"
Nums[4] = "04"
Nums[5] = "05"
Nums[6] = "06"
Nums[7] = "07"
Nums[8] = "08"
Nums[9] = "09"

Cls  0xCCCCCC
Sprite Q, 180, 60, 0
BmpText fo, 205, 32, "SOKOMOUSE", 24, 24
BmpText fo, 170, 428, "PRESS ANY KEY", 24, 24
WaitKey

lev = 1
Initialize
LoadMaps
ShowLevel
FindHead

WHILE Key(27) = 0
  ShowMaps
  IF sl THEN ShowLevel
  ScanBoxes
  ScanHead
  ShowBoxes
  ShowHead
  FlashBox
  AllDone
  MousePos
  TurnHead
  IF Key(vk_space) THEN
    BmpText fo, 64, 420, "Wait...", 24, 24
    Initialize
    LoadMaps
    FindHead
  END IF
  BmpText fo, 200, 8, "SokoMouse", 24, 24
  IF Ready = 2 THEN
    BmpText fo, 64, 420, "Advance to the next level ...", 16, 16
    sl = 1
  END IF
  BoxRas += 2
  IF BoxRas = 32 THEN BoxRas = 0
  IF Key(vk_right) = 0 THEN KeyR = 1
  IF Key(vk_right)THEN KeyR = 0
  IF Key(vk_left) = 0 THEN KeyL = 1
  IF Key(vk_left) THEN KeyL = 0
  IF Key(vk_up) = 0 THEN KeyU = 1
  IF Key(vk_up) THEN KeyU = 0
  IF Key(vk_down) = 0 THEN KeyD = 1
  IF Key(vk_down) THEN KeyD = 0
  Sync
WEND
CloseWindow

Update: I notice a memory freeing issue with Simple Windows and will post an updated version of the game when it is resolved.

57
What's New / SBx
« on: February 12, 2013, 07:16:54 PM »
I expanded on the SBx IUP wrapper library enough to convert the online dictionary example. (see attached - running on Ubuntu 64) The same code runs on Win7-64 (as a 32 bit application) untouched.

SBx_dict.sb
Code: [Select]
' SBx Online Dictionary

servers[0]="dict.org"
servers[1]="dict1.us.dict.org"
servers[2]="all.dict.org"

about="""This is a Demo
of the IUP GUI Binding
for Scriptbasic"""

INCLUDE "SBx"

' Create main window
win = DIALOG()
  SETPROPERTIES win, "TITLE=\"SBx Dictionary\", SIZE = 500x300"
  SETEVENT win, "CLOSE_CB", ADDRESS(Win_exit())

' Create container to house ALL GUI objects
vbx = VBOX()
  SETPROPERTIES vbx, "MARGIN=10x10"

' Create server panel
topBox = HBOX()
  SETPROPERTIES topBox, "GAP=10"
  APPEND vbx, topBox
serverFrame = FRAME()
  SETPROPERTIES serverFrame, "TITLE=Servers, EXPAND=YES"
  APPEND topBox, serverFrame
serverBox = HBOX()
  SETPROPERTIES serverBox, "GAP=5"
  APPEND serverFrame, serverBox
serverCombo = LIST()
  SETPROPERTIES serverCombo, "DROPDOWN=YES, SIZE=120x, EXPAND=HORIZONTAL, VALUE=1"
  APPEND serverBox, serverCombo
  SETEVENT serverCombo, "ACTION", ADDRESS(serverCombo_selected())
btnFetch = BUTTON()
  SETPROPERTIES btnFetch, "TITLE=Fetch, SIZE = 50x"
  APPEND serverBox, btnFetch
  SETEVENT btnFetch, "ACTION", ADDRESS(btnFetch_clicked())

' Create control panel
controlFrame = FRAME()
  SETPROPERTIES controlFrame, "TITLE=Controls"
  APPEND topBox, controlFrame
controlBox = HBOX()
  SETPROPERTIES controlBox, "GAP=5"
  APPEND controlFrame, controlBox
btnAbout = BUTTON()
  SETPROPERTIES btnAbout, "TITLE=About, SIZE = 50x"
  APPEND controlBox, btnAbout
  SETEVENT btnAbout, "ACTION", ADDRESS(btnAbout_clicked())
btnClear = BUTTON()
  SETPROPERTIES btnClear, "TITLE=Clear, SIZE = 50x"
  APPEND controlBox, btnClear
  SETEVENT btnClear, "ACTION", ADDRESS(btnClear_clicked())
btnExit = BUTTON()
  SETPROPERTIES btnExit, "TITLE=Exit, SIZE = 50x"
  APPEND controlBox, btnExit
  SETEVENT btnExit,"ACTION",ADDRESS(Win_exit())

' Create dictionary panel
dictFrame = FRAME()
  SETPROPERTIES dictFrame, "TITLE=\"Dictionaries\""
  APPEND vbx, dictFrame
serverList = LIST()
  SETPROPERTIES serverList, "EXPAND=YES, VISIBLELINES=1"
  APPEND dictFrame, serverList
  SETEVENT serverList, "ACTION", ADDRESS(serverList_selected())

' Create text part
transFrame = FRAME()
  SETPROPERTIES transFrame, "TITLE=\"Translation\""
  APPEND vbx, transFrame
txt = TEXT()
  SETPROPERTIES txt, "MULTILINE=YES, EXPAND=YES"
  APPEND transFrame, txt


' Create entry and search button
bottomBox = HBOX()
  SETPROPERTIES bottomBox, "GAP=10"
  APPEND vbx, bottomBox
lbl = LABEL()
  SETPROPERTIES lbl, "TITLE=\"Enter Word to Search For:\", SIZE=x12"
  APPEND bottomBox, lbl
entry = TEXT()
  SETPROPERTIES entry, "EXPAND=HORIZONTAL"
  APPEND bottomBox, entry
btnSearch = BUTTON()
  SETPROPERTIES btnSearch,"TITLE=Search, SIZE=50x"
  APPEND bottomBox, btnSearch
  SETEVENT btnSearch, "ACTION", ADDRESS(btnSearch_clicked())
chkAll = TOGGLE()
  SETPROPERTIES chkAll, "TITLE=ALL, SIZE=x12"
  APPEND bottomBox, chkAll
chkUTF = TOGGLE()
  SETPROPERTIES chkUTF, "TITLE=UTF-8, SIZE=x12"
  APPEND bottomBox, chkUTF

' Add the main GUI container to the Window
APPEND win, vbx

' Setup dialog defaults
SHOW win
FOCUS btnFetch
FOR i = 0 TO UBOUND(servers)
  SETPROPERTY serverCombo, "APPENDITEM", servers[i]
NEXT
SETPROPERTY serverCombo, "VALUE", "1"
UPDATE serverCombo
server_selection = servers[0]
GETEVENT()
END


' Callback routines

SUB Win_exit
  Iup::ExitLoop = TRUE
END SUB

SUB btnAbout_clicked
  MESSAGE "ABOUT", about
END SUB

SUB serverCombo_selected
  server_selection = GETITEM()
END SUB

SUB serverList_selected
  whichDictionary = GETITEM()
END SUB

SUB btnFetch_clicked
  LOCAL dat, total, count
  ON ERROR GOTO G_NetError
  OPEN server_selection & ":2628" FOR SOCKET AS #1
  PRINT#1,"SHOW DB\n"
  LINE INPUT#1, dat
  LINE INPUT#1, dat
  count = 0
  WHILE LEFT(dat, 1) <> "."
    LINE INPUT#1, dat
    IF LEFT(dat, 1) <> "." THEN total[count] = TRIM(dat)
    count+=1
  WEND
  PRINT#1,"QUIT\n"
  CLOSE(#1)
  FOR cnt = 0 TO count - 2
    SETPROPERTY serverList, "APPENDITEM", total[cnt]
  NEXT
  SETPROPERTY serverList, "VALUE", "1"
  UPDATE serverCombo
  whichDictionary = total[0]
  EXIT SUB

  G_NetError:
  PRINT "Server ",server_selection," not available. (",ERROR,")\n"
END SUB

SUB btnClear_clicked
  CLEAR serverList
  SETPROPERTY txt, "VALUE", ""
  SETPROPERTY entry, "VALUE", ""
END SUB

SUB btnSearch_clicked
  LOCAL dict, dat, total, info
  SETPROPERTY txt, "VALUE", "Fetching...."
  ON ERROR GOTO L_NetError
  dict = LEFT(whichDictionary, INSTR(whichDictionary, " "))
  OPEN server_selection & ":2628" FOR SOCKET AS 1
  IF GETPROPERTY(chkAll, "VALUE") THEN
    PRINT#1,"DEFINE * " & GETPROPERTY(entry, "VALUE") & "\n"
  ELSE
    PRINT#1,"DEFINE " & dict & " " & GETPROPERTY(entry, "VALUE") & "\n"
  END IF
  REPEAT
    LINE INPUT#1, dat
    IF LEFT(dat, 3) = "151" THEN
      total &= "------------------------------\r\n"
      total &= RIGHT(dat, LEN(dat) - LEN(GETPROPERTY(entry, "VALUE")) - LEN(dict))
      total &= "------------------------------\r\n"
      REPEAT
        LINE INPUT#1, info
        info = REPLACE(info, CHR(34), CHR(92) & CHR(34))
        IF LEFT(info, 1) <> "." THEN total &= TRIM(info) & "\n"
      UNTIL LEFT(info, 1) = "."
      total &= "\n"
    END IF
  UNTIL LEFT(dat, 3) = "250" OR VAL(LEFT(dat, 3)) > 499
  PRINT#1,"QUIT\n"
  CLOSE(#1)
  IF LEFT(dat, 3) = "552" THEN
    total = "No match found."
  ELSE IF LEFT(dat, 3) = "501" THEN
    total = "Select a dictionary first!"
  ELSE IF LEFT(dat, 3) = "550" THEN
    total = "Invalid database!"
  END IF
  SETPROPERTY txt, "VALUE", total
EXIT SUB

L_NetError:
  dat[0] = "Could not lookup word! (" & ERROR & ")"
  SETPROPERTY txt, "VALUE", dat
END SUB

SBx
Code: [Select]
' ScriptBasic IUP Interface

IMPORT iup.bas

Iup::Open()

FUNCTION DIALOG
  DIALOG = Iup::Create("dialog")
END FUNCTION

SUB SETPROPERTIES(ih, propstr)
  Iup::SetAttributes(ih, propstr)
END SUB

SUB SETPROPERTY(ih, typ, value)
  Iup::SetAttribute(ih, typ, value)
END SUB

FUNCTION GETPROPERTY(ih, typ)
  GETPROPERTY = Iup::GetAttribute(ih, typ)
END FUNCTION

FUNCTION VBOX
  VBOX = Iup::Create("vbox")
END FUNCTION

FUNCTION HBOX
  HBOX = Iup::Create("hbox")
END FUNCTION

FUNCTION FRAME
  FRAME = Iup::Create("frame")
END FUNCTION

FUNCTION BUTTON
  BUTTON = Iup::Create("button")
END FUNCTION

FUNCTION LIST
  LIST = Iup::Create("list")
END FUNCTION

FUNCTION TEXT
  TEXT = Iup::Create("text")
END FUNCTION

FUNCTION LABEL
  LABEL = Iup::Create("label")
END FUNCTION

FUNCTION TOGGLE
  TOGGLE = Iup::Create("toggle")
END FUNCTION

SUB MESSAGE(title, body)
  Iup::Message(title, body)
END SUB

FUNCTION GETITEM
  GETITEM = Iup::GetListText()
END FUNCTION
 
SUB APPEND(ih_to, ih_from)
  Iup::Append(ih_to, ih_from)
END SUB

FUNCTION FOCUS(ih)
  FOCUS = Iup::SetFocus(ih)
END FUNCTION

FUNCTION UPDATE(ih)
  UPDATE = Iup::Update(ih)
END FUNCTION

SUB CLEAR(ih)
  Iup::ClearList(ih)
END SUB

SUB SETEVENT(ih, class, funcaddr)
  Iup::SetCallback(ih, class,  funcaddr)
END SUB

SUB SHOW(ih)
  Iup::Show(ih)
END SUB  

SUB GETEVENT
  Iup::MainLoop
  Iup::Close
END SUB

58
What's New / ScriptBasic 2.2 Beta Release - (Windows 32)
« on: February 10, 2013, 09:21:02 AM »
Attached is a beta ScriptBasic 2.2 release for Windows. (IUP included)  The only installation step is to adjust your PATH variable to point to the bin directory of this beta. I have included a test directory with examples and their output. (.out) Some of the extension module like MySQL and cURL require their runtime libraries/clients installed before using the ScriptBasic extension modules for them. I have uploaded a zip of extension module support DLLs that should go in your system32 on XP and SysWOW64 on 64 bit Windows 7.

Note: There are two version of the ScriptBasic interpreter. For console applications and redirection (stdin/out) use scriba.exe. If you wish to run GUI based applications, use the Windows sbiup.exe version of the interpreter that has no console support. If you like you could associate the .sbx attribute for example to sbiup.exe which would allow you to run the script directly by clicking on them in explorer or as a shortcut.

Feedback welcome.

ScriptBasic Documentation

ScriptBasic Forum




SBx_buttons
Code: [Select]
' SBx_buttons Example

INCLUDE "SBx"

SUB Btn1_clicked
  PRINT "BUTTON 1 Event\n"
END SUB

SUB Btn2_clicked
  PRINT "BUTTON 2 Event\n"
END SUB

SUB Btn3_clicked
  PRINT "BUTTON 3 Event\n"
END SUB

SUB Win_exit
  Iup::ExitLoop = TRUE
END SUB


win = WINDOW()
SETPROPERTY(win, "TITLE=\"SBx Buttons\", SIZE=300x")
horzbox = HBOX()
SETPROPERTY(horzbox, "GAP=5")
btn1 = BUTTON()
SETPROPERTY(btn1, "TITLE=Button1, EXPAND=HORIZONTAL")
btn2 = BUTTON()
SETPROPERTY(btn2, "TITLE=Button2, EXPAND=HORIZONTAL")
btn3 = BUTTON()
SETPROPERTY(btn3, "TITLE=Button3, EXPAND=HORIZONTAL")
APPEND(horzbox, btn1)
APPEND(horzbox, btn2)
APPEND(horzbox, btn3)
APPEND(win, horzbox)
EVENT(win,"CLOSE_CB",ADDRESS(Win_exit()))
EVENT(btn1,"ACTION",ADDRESS(Btn1_clicked()))
EVENT(btn2,"ACTION",ADDRESS(Btn2_clicked()))
EVENT(btn3,"ACTION",ADDRESS(Btn3_clicked()))
SHOW(win)



sbiupdict.sb
Code: [Select]
IMPORT iup.bas

servers[0]="dict.org"
servers[1]="dict1.us.dict.org"
servers[2]="all.dict.org"

about="""This is a Demo
of the IUP GUI Binding
for Scriptbasic"""

' Initialize IUP
Iup::Open()

' Create main window

win = Iup::Create("dialog")
  Iup::SetAttributes(win, "TITLE=\"ScriptBasic IUP Online Dictionary\", SIZE=500x300")
  Iup::SetCallback(win,"CLOSE_CB",ADDRESS(Win_exit()))

' Create container to house ALL GUI objects

vbox = Iup::Create("vbox")
  Iup::SetAttributes(vbox, "MARGIN=10x10")

' Create server panel

topBox = Iup::Create("hbox")
  Iup::SetAttributes(topBox, "GAP=10")
  Iup::Append(vbox, topBox)
serverFrame = Iup::Create("frame")
  Iup::SetAttributes(serverFrame, "TITLE=Servers, EXPAND=YES")
  Iup::Append(topBox, serverFrame)
serverBox = Iup::Create("hbox")
  Iup::SetAttributes(serverBox, "GAP=5")
  Iup::Append(serverFrame, serverBox)
serverCombo = Iup::Create("list")
  Iup::SetAttributes(serverCombo, "DROPDOWN=YES, SIZE=120x, EXPAND=HORIZONTAL, VALUE=1")
  Iup::Append(serverBox, serverCombo)
  Iup::SetCallback(serverCombo, "ACTION", ADDRESS(serverCombo_selected()))
btnFetch = Iup::Create("button")
  Iup::SetAttributes(btnFetch, "TITLE=Fetch, SIZE = 50x")
  Iup::Append(serverBox, btnFetch)
  Iup::SetCallback(btnFetch, "ACTION", ADDRESS(btnFetch_clicked()))

' Create control panel

controlFrame = Iup::Create("frame")
  Iup::SetAttributes(controlFrame, "TITLE=Controls")
  Iup::Append(topBox, controlFrame)
controlBox = Iup::Create("hbox")
  Iup::SetAttributes(controlBox, "GAP=5")
  Iup::Append(controlFrame, controlBox)
btnAbout = Iup::Create("button")
  Iup::SetAttributes(btnAbout, "TITLE=About, SIZE = 50x")
  Iup::Append(controlBox, btnAbout)
  Iup::SetCallback(btnAbout, "ACTION", ADDRESS(btnAbout_clicked()))
btnClear = Iup::Create("button")
  Iup::SetAttributes(btnClear, "TITLE=Clear, SIZE = 50x")
  Iup::Append(controlBox, btnClear)
  Iup::SetCallback(btnClear, "ACTION", ADDRESS(btnClear_clicked()))
btnExit = Iup::Create("button")
  Iup::SetAttributes(btnExit, "TITLE=Exit, SIZE = 50x")
  Iup::Append(controlBox, btnExit)
  Iup::SetCallback(btnExit,"ACTION",ADDRESS(Win_exit()))

' Create dictionary panel

dictFrame = Iup::Create("frame")
  Iup::SetAttributes(dictFrame, "TITLE=Dictionaries")
  Iup::Append(vbox, dictFrame)
serverList = Iup::Create("list")
  Iup::SetAttributes(serverList, "EXPAND=YES, VISIBLELINES=1")
  Iup::Append(dictFrame, serverList)
  Iup::SetCallback(serverList, "ACTION", ADDRESS(serverList_selected()))

' Create text part

transFrame = IUP::Create("frame")
  Iup::SetAttributes(transFrame, "TITLE=Translation")
  Iup::Append(vbox, transFrame)
text = Iup::Create("text")
  Iup::SetAttributes(text, "MULTILINE=YES, EXPAND=YES")
  Iup::Append(transFrame, text)

' Create entry and search button

bottomBox = Iup::Create("hbox")
  Iup::SetAttributes(bottomBox, "GAP=10")
  Iup::Append(vbox, bottomBox)
label = Iup::Create("label")
  Iup::SetAttributes(label, "TITLE=\"Enter Word to Search For:\", SIZE=x12")
  Iup::Append(bottomBox, label)
entry = Iup::Create("text")
  Iup::SetAttributes(entry, "EXPAND=HORIZONTAL")
  Iup::Append(bottomBox, entry)
btnSearch = Iup::Create("button")
  Iup::SetAttributes(btnSearch,"TITLE=Search, SIZE=50x")
  Iup::Append(bottomBox, btnSearch)
  Iup::SetCallback(btnSearch, "ACTION", ADDRESS(btnSearch_clicked()))
chkAll = Iup::Create("toggle")
  Iup::SetAttributes(chkAll, "TITLE=ALL, SIZE=x12")
  Iup::Append(bottomBox, chkAll)
chkUTF = Iup::Create("toggle")
  Iup::SetAttributes(chkUTF, "TITLE=UTF-8, SIZE=x12")
  Iup::Append(bottomBox, chkUTF)

' Add the main GUI container to the Window

Iup::Append(win, vbox)

' Setup dialog defaults

Iup::Show(win)
Iup::SetFocus(btnFetch)
FOR i = 0 TO UBOUND(servers)
  Iup::SetAttribute(serverCombo, "APPENDITEM", servers[i])
NEXT
Iup::SetAttribute(serverCombo, "VALUE", "1")
Iup::Update(serverCombo)
server_selection = servers[0]

' Main processing loop

Iup::MainLoop()
Iup::Close()
END

' Callback routines

SUB Win_exit
  Iup::ExitLoop = TRUE
END SUB

SUB btnAbout_clicked
  Iup::Message("ABOUT", about)
END SUB

SUB serverCombo_selected
  server_selection = Iup::GetListText()
END SUB

SUB serverList_selected
  whichDictionary = Iup::GetListText()
END SUB

SUB btnFetch_clicked
  LOCAL dat, total, count
  ON ERROR GOTO G_NetError
  OPEN server_selection & ":2628" FOR SOCKET AS #1
  PRINT#1,"SHOW DB\n"
  LINE INPUT#1, dat
  LINE INPUT#1, dat
  count = 0
  WHILE LEFT(dat, 1) <> "."
    LINE INPUT#1, dat
    IF LEFT(dat, 1) <> "." THEN total[count] = TRIM(dat)
    count+=1
  WEND
  PRINT#1,"QUIT\n"
  CLOSE(#1)
  FOR cnt = 0 TO count - 2
    Iup::SetAttribute(serverList, "APPENDITEM", total[cnt])
  NEXT
  Iup::SetAttribute(serverList, "VALUE", "1")
  Iup::Update(serverCombo)
  whichDictionary = total[0]
  EXIT SUB

  G_NetError:
  PRINT "Server ",server_selection," not available. (",ERROR,")\n"
END SUB

SUB btnClear_clicked
  Iup::ClearList(serverList)
  Iup::SetAttribute(text, "VALUE", "")
  Iup::SetAttribute(entry, "VALUE", "")
END SUB

SUB btnSearch_clicked
  LOCAL dict, dat, total, info
  IUP::SetAttribute(text, "VALUE","Fetching....")
  ON ERROR GOTO L_NetError
  dict = LEFT(whichDictionary, INSTR(whichDictionary, " "))
  OPEN server_selection & ":2628" FOR SOCKET AS 1
  IF Iup::GetAttribute(chkAll, "VALUE") THEN
    PRINT#1,"DEFINE * " & Iup::GetAttribute(entry,"VALUE") & "\n"
  ELSE
    PRINT#1,"DEFINE " & dict & " " & Iup::GetAttribute(entry,"VALUE") & "\n"
  END IF
  REPEAT
    LINE INPUT#1, dat
    IF LEFT(dat, 3) = "151" THEN
      total$ &= "------------------------------\r\n"
      total$ &= RIGHT(dat, LEN(dat) - LEN(Iup::GetAttribute(entry, "VALUE")) - LEN(dict))
      total$ &= "------------------------------\r\n"
      REPEAT
        LINE INPUT#1, info
        info = REPLACE(info, CHR(34), CHR(92) & CHR(34))
        IF LEFT(info, 1) <> "." THEN total &= TRIM(info) & "\n"
      UNTIL LEFT(info, 1) = "."
      total &= "\n"
    END IF
  UNTIL LEFT(dat, 3) = "250" OR VAL(LEFT(dat, 3)) > 499
  PRINT#1,"QUIT\n"
  CLOSE(#1)
  IF LEFT(dat, 3) = "552" THEN
    total = "No match found."
  ELSE IF LEFT(dat, 3) = "501" THEN
    total = "Select a dictionary first!"
  ELSE IF LEFT(dat, 3) = "550" THEN
    total = "Invalid database!"
  END IF
  Iup::SetAttribute(text, "VALUE", total)
EXIT SUB

L_NetError:
  dat[0] = "Could not lookup word! (" & ERROR & ")"
  Iup::SetAttribute(text, "VALUE", dat)
END SUB

testsqlite3.sb
Code: [Select]
import sqlite.bas

db = sqlite::open("sqlite3.db")

sqlite::execute(db,"create table demo (someval integer, sometxt text);")
sqlite::execute(db,"insert into demo values (123,'hello');")
sqlite::execute(db, "INSERT INTO demo VALUES (234, 'cruel');")
sqlite::execute(db, "INSERT INTO demo VALUES (345, 'world');")

stmt = sqlite::query(db,"SELECT * FROM demo")

while (sqlite::row(stmt) = sqlite::SQLITE3_ROW)
  if sqlite::fetchhash(stmt,column) then
    print column{"someval"},"\t-\t",column{"sometxt"},"\n"
  end if
wend

sqlite::close(db)

123   -   hello
234   -   cruel
345   -   world

testmysql.sb
Code: [Select]
' MySQL Test Program

INCLUDE mysql.bas

dbh = mysql::RealConnect("localhost","root","your_password","test")

mysql::query(dbh,"SELECT * FROM city LIMIT 0,10")

WHILE mysql::FetchHash(dbh,column)

PRINT "| "
PRINT column{"ID"}," | "
PRINT column{"Name"}," | "
PRINT column{"CountryCode"}," | "
PRINT column{"District"}," | "
PRINT column{"Population"}," |"
PRINTNL

WEND

PRINTNL
PRINT "The database handle is: ",dbh,"\n"
PRINT "Affected rows by SELECT: ",mysql::AffectedRows(dbh),"\n"
PRINT "Character set name is: ",mysql::CharacterSetName(dbh),"\n"
PRINT "Last error is: ",mysql::ErrorMessage(dbh),"\n"
PRINT "Client info is: ",mysql::GetClientInfo(),"\n"
PRINT "Host info is: ",mysql::GetHostInfo(dbh),"\n"
PRINT "Proto info is: ",mysql::GetProtoInfo(dbh),"\n"
PRINT "Server info is: ",mysql::GetServerInfo(dbh),"\n"
PRINT "PING result: ",mysql::Ping(dbh),"\n"
PRINT "Thread ID: ",mysql::ThreadId(dbh),"\n"
PRINT "Status is: ",mysql::Stat(dbh),"\n"

mysql::Close(dbh)

| 1 | Kabul | AFG | Kabol | 1780000 |
| 2 | Qandahar | AFG | Qandahar | 237500 |
| 3 | Herat | AFG | Herat | 186800 |
| 4 | Mazar-e-Sharif | AFG | Balkh | 127800 |
| 5 | Amsterdam | NLD | Noord-Holland | 731200 |
| 6 | Rotterdam | NLD | Zuid-Holland | 593321 |
| 7 | Haag | NLD | Zuid-Holland | 440900 |
| 8 | Utrecht | NLD | Utrecht | 234323 |
| 9 | Eindhoven | NLD | Noord-Brabant | 201843 |
| 10 | Tilburg | NLD | Noord-Brabant | 193238 |

The database handle is: 1
Affected rows by SELECT: 10
Character set name is: latin1
Last error is:
Client info is: 6.0.0
Host info is: localhost via TCP/IP
Proto info is: 10
Server info is: 5.5.28
PING result: -1
Thread ID: 0
Status is: Uptime: 23820  Threads: 1  Questions: 4  Slow queries: 0  Opens: 35  Flush tables: 1  Open tables: 1  Queries per second avg: 0.000

testodbc.sb
Code: [Select]
IMPORT odbc.bas

dbh = odbc::RealConnect("SBSQL3","","")

odbc::query(dbh,"SELECT * FROM demo")

WHILE odbc::FetchHash(dbh,dbcol)
  PRINT dbcol{"someval"},"\t-\t",dbcol{"sometxt"},"\n"
WEND

odbc::Close(dbh)

123   -   hello
234   -   cruel
345   -   world

testmxml.sb
Code: [Select]
import mxml.bas

filename = "stuff.xml"

doc = mxml::LoadDoc(filename)

node =  mxml::GetNode(doc,"/stufflist/stuff_test")
if node then print "Test1: ", mxml::GetNodeValue(node),"\n"

node =  mxml::GetNode(doc,"/stufflist/stuff_test2")
if (node) then print "Test2: ", mxml::GetNodeValue(node),"\n\n"
  
node = mxml::GetNode(doc,"/stufflist/stuff_test3/painting/img")
if node then
print "Image: ", mxml::GetProperty(node,"src"), "\n"
print "Alt Image: ", mxml::GetProperty(node,"alt"), "\n\n"
endif

node = mxml::GetNode(doc,"/stufflist/books")
child = mxml::GetChild(node)

while child
node = mxml::GetNode(child,"id")
if node then print "ID = ", mxml::GetNodeValue(node),"\n"
node = mxml::GetNode(child,"name")
if node then print "Name = ", mxml::GetNodeValue(node),"\n"

child = mxml::GetNext(child)
wend

if doc then mxml::FreeDoc(doc)

stuff.xml
Code: [Select]
<?xml version="1.0" encoding="UTF-8" ?>


<stufflist>
<stuff_test>This is a test!</stuff_test>
<stuff_test2>And this is another test!</stuff_test2>
<stuff_test3>
<painting>
<img src="madonna.jpg" alt='Foligno Madonna, by Raphael'/>
<caption>This is Raphael's "Foligno" Madonna, painted in
<date>1511</date>.
</caption>
</painting>
</stuff_test3>
<books>
    <book>
        <id>1</id>
        <name>Hello, world!</name>
    </book>
    <book>
        <id>2</id>
        <name>Hello, China!</name>
    </book>
</books>
</stufflist>

Test1: This is a test!
Test2: And this is another test!

Image: madonna.jpg
Alt Image: Foligno Madonna, by Raphael

ID = 1
Name = Hello, world!
ID = 2
Name = Hello, China!

testcurl.sb
Code: [Select]
INCLUDE curl.bas

ch = curl::init()
curl::option(ch,"URL","http://localhost/index.html")
' curl::option(ch,"FILE","test.html")
wp = curl::perform(ch)
' curl::perform(ch)
curl::finish(ch)

PRINT wp

<html><body><h1>It works!</h1></body></html>

ScriptBasic CGI response to a thinBasic QOD (Question of the Day) on operator precedence.

Quote
Which of the expressions will provide a different answer?

qod1.cgi
Code: [Select]
#! /usr/bin/scriba -c
INCLUDE cgi.bas
cgi::Header(200, "text/html")
cgi::FinishHeader()
 
PRINT """
<html>
<header>
  <title>thinBasic QOD #1</title>
</header>
<body>
<h1>Answer:</h1>
  <table border="0"  cellpadding="5">
    <tr><td>(1)</td><td>""" & ( 45 * ( 9 - 5 + 8 ) - 36 / 4 ) & """</td></tr>
    <tr><td>(2)</td><td>""" & ( 45 * ( 9 - ( 5 + 8 ) ) - 36 / 4 ) & """</td></tr>
    <tr><td>(3)</td><td>""" & ( 45 * ( 9 - 5 + 8 ) - ( 36 / 4 ) ) & """</td></tr>
    <tr><td>(4)</td><td>""" & ( 45 * ( ( 9 - 5 ) + 8 ) - 36 / 4 ) & """</td></tr>
  </table>  
</body>
</html>
"""

testnt.sb
Code: [Select]
IMPORT nt.bas

PRINT nt::RegRead("HKCU\\SOFTWARE\\SCRIPTBASIC\\DEBUGGER\\"),"\n"

C:\scriptbasic\test>scriba testnt.sb
sdbg

C:\scriptbasic\test>

ScriptBasic 2.2 (Windows 32) Attached
 

59
What's New / ScriptBasic API Example
« on: December 27, 2012, 10:03:43 PM »
Peter van Eerten's BaCon (Basic to C translator) which syntax is very close to ScriptBasic has made it really easy to integrate C libraries into the Basic. I created a series of examples showing how ScriptBasic as an embedded scripting engine gives BaCon the best of both worlds. (compiler and interpreter in one)

more ...

60
DBG / SDBG (Remote Socket Debugger)
« on: December 08, 2012, 11:14:00 PM »
The debugger support for ScriptBasic has been pretty much Windows centric with the original DBG internal preprocessor debugger. It was dependent on the Windows console screen API which left Linux without a debugger. One of Peter Verhas's last projects was a socket version of DBG and using a GUI client written in C++. (still a Windows solution) The socket debugger allowed remote debugging of the ScriptBasic multi-threaded web server. I didn't get around to testing the new debugger internal preprocessor until a couple years after Peter moved on.

I recently fixed a couple bugs with SDBG and wrote a console mode client for it in ScriptBasic under Linux. (which will also work in Windows) Here is a list of debugging features which mirror the old DBG debugger which documentation exists on this board.

  • h help
  • s step one line, or just press return on the line
  • S step one line, do not step into functions or subs
  • o step until getting out of the current function
      (if you stepped into but changed your mind)
  • ? var  print the value of a variable
  • u step one level up in the stack
  • d step one level down in the stack (for variable printing)
  • D step down in the stack to current execution depth
  • G list all global variables
  • L list all local variables
  • l [n-m] list the source lines
  • r [n] run to line n
  • R [n] run to line n but do not stop in recursive function call
  • b [n] set breakpoint on the line n or the current line
  • B [n-m] remove breakpoints from lines
  • q quit the program


Note:

  • This is not an IDE but a console mode remote debugger.
  • You can only display the executing scripts source, not change it.
  • You can view the state of global and local variables but not alter them.
  • If you set up the SB conf file for SDBG, you only need to insert USE SDBG in your source to use the debugger console with it. (no matter where the program is actually running)


I will be releasing both Windows32 and Ubuntu64 versions of the SDBG remote ScriptBasic debugger. I will also setup a CGI or SBHTTPD server example page that you can debug with the included DBGCON(.exe) standalone debugger. (source withheld until final release)

Pages: 1 2 3 [4] 5 6 ... 12