Qbasicnews.com
freeBASIC (a 32-bit QB-syntax compatible compiler) preview.. - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: General (http://qbasicnews.com/newforum/forum-6.html)
+--- Forum: General/Misc (http://qbasicnews.com/newforum/forum-18.html)
+--- Thread: freeBASIC (a 32-bit QB-syntax compatible compiler) preview.. (/thread-4948.html)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40


freeBASIC (a 32-bit QB-syntax compatible compiler) preview.. - marzecTM - 11-06-2004

threads are already easily supported in the sdl port. sdl offers some neat functions to make threading:

* easy to handle
* plattformindependend (except for mac iirc)

so.... get the sdl header files and check out the sdl documentation


freeBASIC (a 32-bit QB-syntax compatible compiler) preview.. - Z!re - 11-06-2004

What will FRE return?

And what does the arrays use?, I'm guessing XMS?


freeBASIC (a 32-bit QB-syntax compatible compiler) preview.. - marzecTM - 11-06-2004

it's a 32-bit protected mode compiler, thus there is no need for xms/ems or the like. it's just like every other win32 app, you simply use all the mem the os gives you. that's it, no xms, no ems

on the FRE i'm not sure, to lazy to look up what it did

@v3c (since you're not on mirc)
'$define bar integer
dim var as bar

giving

dim var as integer


works already. '$define does the following:

*it registers the SYMBOLNAME
* it registers the VALUE of the symbol if provided, were the value
is the first token after the SYMBOLNAME (tokens are delimited by space and tab)
* it then checks every token in the source wheter is a SYMBOLNAME (things SYMBOLNAME*234+13/SYMBOLNAME work too, cause that token would be tokenized again, with operators as delimiters, thus giving my SYMbOLNAME on it's own)

so there you go...


freeBASIC (a 32-bit QB-syntax compatible compiler) preview.. - v3cz0r - 11-07-2004

Just to show how creating threads is simple in Windows, here is it: http://freebasic.bad-logic.com/downloads/fb_threads.zip

Code is no more than:

Code:
declare sub mythread cdecl ( byval num as integer )

    dim shared threadsRunning as integer
    
    dim i as integer

    '' create and call the threads
    threadsRunning = 0
    for i = 0 to THREADS-1
        if( beginthread( @mythread(), 0, byval i ) <> -1 ) then
            threadsRunning = threadsRunning + 1
        end if
    next i
    
    '' wait all threads to finish
    do while( threadsRunning > 0 )
        Sleep 100
    loop
    
    
'':::::    
sub mythread cdecl ( byval num as integer )
    dim i as integer
    
    for i = 0 to SECS-1
        print "Hello from thread: " + str$( num ) + " (" + str$( SECS-i ) + " sec(s) left)"
        Sleep 1000
    next i
    
    threadsRunning = threadsRunning - 1

end sub



freeBASIC (a 32-bit QB-syntax compatible compiler) preview.. - marzecTM - 11-07-2004

and here threading in fb with sdl

Code:
'$include: 'sdl.bi'
'$include: 'kernel32.bi'

declare function threadproc cdecl ( byref datas as byte ) as integer

dim shared threadRunning as integer
dim threadid as unsigned integer


if(SDL_Init(SDL_INIT_EVERYTHING)) then
  print "error: couldn't init SDL"
  end
end if

threadRunning = 1

threadid = SDL_CreateThread(@threadproc, byval 0)
if(threadid=0) then
  print "error: couldn't create thread"
  end
end if

print "threadid is:" + str$(threadid)

call Sleep(3000)

threadRunning = 0
SDL_WaitThread threadid, byval 0

SDL_Quit


function threadproc cdecl ( byref datas as byte ) as integer
    while ( threadrunning=1 )
      print "i'm in the thread"
    wend
end function

see http://ratatoskr.bad-logic.com/fb/ for the sdlthr.bas file and http://ratatoskr.bad-logic.com/fb/sdl/sdl.rar for the needed includefiles

and now, sleep...


freeBASIC (a 32-bit QB-syntax compatible compiler) preview.. - relsoft - 11-07-2004

Since you're all offline:

5 minutes work with FB and no prior experience with TinyPTC.

http://quickhost.qbtk.com/download.php?id=313

Code:
defint a-z
'//Plasma using y*xwidth +x addresing
'//Relsoft 2004
'//Uses the superhot FB compiler

'$include: 'tinyptc.bi'

const SCR_WIDTH = 320
const SCR_HEIGHT = 200
const SCR_SIZE = SCR_WIDTH*SCR_HEIGHT

const PI = 3.141593

    redim shared buffer( 0 to SCR_SIZE-1 ) as integer
    redim shared Lsin1( -1024 to 1024) as integer
    redim shared Lsin2( -1024 to 1024) as integer
    redim shared Lsin3( -1024 to 1024) as integer
    redim shared Lcols(2, 255) as integer



    dim frame as long
    dim col as integer
    dim i as integer
    dim ofs as long
    dim rot as integer
    dim counter as long
    dim pixel as integer

    if( ptc_open( "freeBASIC v0.01 - plasma test (relsoft)", SCR_WIDTH, SCR_HEIGHT ) = 0 ) then
        end -1
    end if

    for i = -1024 to 1024
        Lsin1(i) = SIN(i / (128)) * 256      'Play with these values
        Lsin2(i) = SIN(i / (64)) * 128       'for different types of fx
        Lsin3(i) = SIN(i / (32)) * 64        ';*)
    next i

    for i = 0 to 255
        Lcols(0,i)=  abs(INT(128 - 127 * SIN(i * PI / 32)))
        Lcols(1,i)=  abs(INT(128 - 127 * SIN(i * PI / 64)))
        Lcols(2,i)=  abs(INT(128 - 127 * SIN(i * PI / 128)))
    next i

    counter = 0

    do
      counter = counter + 1
      rot = 64 * (((counter AND 1) = 1) OR 1)
      FOR y = 0 TO SCR_HEIGHT-1
          FOR x = 0 TO SCR_WIDTH-2
              rot = -rot
              col = (Lsin3(x + Rot) + Lsin1(x + Rot + Counter) + Lsin2(y + Rot)) and 255
              pixel = Lcols(0,col) shl 16 or  Lcols(1,col) shl 8 or Lcols(2,col)
              buffer( y * SCR_WIDTH + x ) = pixel
          NEXT x
      NEXT y
        ptc_update varptr( buffer(0) )

    loop


    ptc_close



freeBASIC (a 32-bit QB-syntax compatible compiler) preview.. - VonGodric - 11-07-2004

Cool!

marzecTM -you could put the exe file too of your demo :wink:


freeBASIC (a 32-bit QB-syntax compatible compiler) preview.. - marzecTM - 11-07-2004

wow pretty kwel rel

@van: it's up search the http://ratatoskr.bad-logic.com/fb/ folder (sdlthr.exe), though as you may have read in the sourcecode nothing big really happens hehe....


freeBASIC (a 32-bit QB-syntax compatible compiler) preview.. - Neo - 11-07-2004

Quote:Since you're all offline:

5 minutes work with FB and no prior experience with TinyPTC.

Heh, my first (and only) Allegro program so far was a Plasma as well Wink


freeBASIC (a 32-bit QB-syntax compatible compiler) preview.. - v3cz0r - 11-08-2004

Really nice rel.. i liked the "superhot" comment ;)

It would be twice as fast if you didn't use dynamic arrays, ie, do

Code:
dim shared buffer( 0 to SCR_SIZE-1 ) as integer
   ...

instead.

FB stores multi-dimensional arrays in row-major order, so (a,0) gens better code than (0,a) with 2d arrays, you could also declare Lcols() as:

Code:
type RGB
    r as ubyte
    g as ubyte
    b as ubyte
    a as ubyte
end type

    dim shared Lcols(255) as RGB

And access to buffer() could be done as a pointer, so the whole thing would look like:

Code:
defint a-z
'$include: 'tinyptc.bi'

const SCR_WIDTH = 320
const SCR_HEIGHT = 200
const SCR_SIZE = SCR_WIDTH*SCR_HEIGHT

const PI = 3.141593

type RGB
    r as ubyte
    g as ubyte
    b as ubyte
    a as ubyte
end type

    dim shared buffer( 0 to SCR_SIZE-1 ) as integer
    dim shared Lsin1( -1024 to 1024) as integer
    dim shared Lsin2( -1024 to 1024) as integer
    dim shared Lsin3( -1024 to 1024) as integer
    dim shared Lcols(255) as RGB
    
    
    dim frame as long
    dim col as integer
    dim i as integer
    dim ofs as long
    dim rot as integer
    dim counter as integer, cdir as integer
    dim pixel as integer

    if( ptc_open( "freeBASIC v0.01 - plasma test (relsoft)", SCR_WIDTH, SCR_HEIGHT ) = 0 ) then
        end -1
    end if

    for i = -1024 to 1024
        Lsin1(i) = SIN(i / 128) * 256      'Play with these values
        Lsin2(i) = SIN(i / 64) * 128       'for different types of fx
        Lsin3(i) = SIN(i / 32) * 64        ';*)
    next i

    for i = 0 to 255
        Lcols(i).r = cint(abs(INT(128 - 127 * SIN(i * PI / 32))))
        Lcols(i).g = cint(abs(INT(128 - 127 * SIN(i * PI / 64))))
        Lcols(i).b = cint(abs(INT(128 - 127 * SIN(i * PI / 128))))
    next i

    counter = 0
    cdir = 1

    dim p as integer ptr
    do
        counter = counter + cdir
          if( (counter < 1) or (counter > 4096) ) then
            cdir = -cdir
          end if
    
          rot = 64 * (((counter AND 1) = 1) OR 1)
      
          p = @buffer(0)
          FOR y = 0 TO SCR_HEIGHT-1
              FOR x = 0 TO SCR_WIDTH-1
                rot = -rot
                  col = (Lsin3(x + Rot) + Lsin1(x + Rot + Counter) + Lsin2(y + Rot)) and 255
                  
                  *p = Lcols(col).r shl 16 or Lcols(col).g shl 8 or Lcols(col).b
                  p = p + len( integer )
              NEXT x
          NEXT y
    
        ptc_update varptr( buffer(0) )
    loop

    ptc_close

(Btw, to compile the code above you need the last version, coz i had to fix some bugs)