WebFPC

Linux specific questions.
Post Reply
Sigord
Posts: 153
Joined: Mar 14, 2013 9:54
Location: Hastings UK
Contact:

WebFPC

Post by Sigord »

Finding it way beyond me how to Install FB in any Linux, unless someone is clever and kind enough to create auto installing PET files, I am very pleased with being able to successfully compile FB code to run under Puppy using http://fbc.deltalabs.de/

But I am baffled why the file list always defaults to TXT files. This is especially as saving BAS files as TXT files are refused by the compiler. As a result we have to keep altering the file list to ALL FILES.
Sigord
Posts: 153
Joined: Mar 14, 2013 9:54
Location: Hastings UK
Contact:

Re: WebFPC

Post by Sigord »

As I just posted elsewhere here I have now successfully run a number of my compiled programs under Mint V 13. They also run under Puppy providing I do not use a Subroutine. But the compiler is only meant for Debian and Puppy is Slackware.

Does anyone know what the copyright Linux Mac is based, and if it likely to also run such compiled Linux. I intend to distribute some of my efforts as Freeware and would like to know.
chrowle
Posts: 47
Joined: Oct 21, 2013 23:32
Location: Alberta, Canada

Re: WebFPC

Post by chrowle »

That compiler has never worked for me. I can create a few packages for installing FreeBASIC if you want. Which Puppy do you use? Slacko, Wary or Precise?
Sigord
Posts: 153
Joined: Mar 14, 2013 9:54
Location: Hastings UK
Contact:

Re: WebFPC

Post by Sigord »

Thanks very much but I just refrain from using Sub routines for Puppy.
chrowle
Posts: 47
Joined: Oct 21, 2013 23:32
Location: Alberta, Canada

Re: WebFPC

Post by chrowle »

Subroutines seem very important. I insist. Also, why can't you use subroutines? Do you know? Are you able to post source for me to test?
Sigord
Posts: 153
Joined: Mar 14, 2013 9:54
Location: Hastings UK
Contact:

Re: WebFPC

Post by Sigord »

I should have mentioned my Puppy is v 5,4 Slackware. Below is the code that runs in Mint ( providing I set the Permission ) but not in Puppy, which does not need permission. I just replace the Cold Sub with a Then / End if

Pity someone cannot come us with the formula to calculate the RGB values from the Point (x,y). The formula used in other Basics is wrong with FB

Code: Select all

Dim As UInteger p, blue,green,red
Dim As Integer x, y, buttons, res 
Declare Sub Cols

ScreenRes 880, 600, 32
Cls : Locate 30,34 
Print "Produced with Free Basic for Linux. Ver 2.1"
Randomize , 1
Sleep 2000 : Cols
Locate 1,30
Print "Left click to show RSGB Values, Right click new colours"

Do
    ' Get mouse x, y and buttons. Discard wheel position.
    res = GetMouse (x, y, , buttons)
    Locate 74,30
    If res <> 0 Then '' Failure
        
        #ifdef __FB_DOS__
        Print "Mouse or mouse driver not available"
        #else
        Print "   ****** Mouse was not on the window ******    "
        #endif
        
    Else
        If buttons And 1 Then 
            locate 74,10 : Print Spc(20) : Locate 74,30 
            p = Point(x,y)           
            PRINT String$(20," ");"RGB CODE = ";p;String$(20," ")
        END If  
        If buttons And 2 then Cols : Sleep 500
        Sleep 20
    End If
Loop While Inkey = ""
End

Sub Cols
Dim As UInteger h,v,r,p,g,b,a
Cls 
v = 14
While v < 560
    For h = 30 To 840 step 140
        r = Int(Rnd * 256) : g = Int(Rnd * 256) : b = Int(Rnd * 256) : a = 0
        r = Rnd * 255 + 1 : g = Rnd * 255 + 1 : b = Rnd * 255 + 1
        Line (h, v)-(h + 60, v + 20), Rgba(r,g,b,a), BF
        Locate v/8+1,h/8+9 : Print "  R=";Str$(r)
        Locate v/8+2,h/8+9 : Print "G";Str$(g);" B";Str$(b)
    Next h
    v = v + 30
Wend
End Sub
Sigord
Posts: 153
Joined: Mar 14, 2013 9:54
Location: Hastings UK
Contact:

Re: WebFPC

Post by Sigord »

If of interest to some I now find code compiled using WebFPC also works OK on an old Knoppix v 3.3. But like the Puppy Slackware I have it will not accept programs using a Subrountine.

I believe Knoppix is also based on Debian.
chrowle
Posts: 47
Joined: Oct 21, 2013 23:32
Location: Alberta, Canada

Re: WebFPC

Post by chrowle »

Something is wrong with your code. I get a segmentation fault in zsh on my Fedora Core 19 system. Will test on other shells to see if it is just zsh.
chrowle
Posts: 47
Joined: Oct 21, 2013 23:32
Location: Alberta, Canada

Re: WebFPC

Post by chrowle »

Nope, it's your code. My FBC is custom built from 0.90.1. What version are you using and what is the error message? Will run the test through valgrind and gdb.
chrowle
Posts: 47
Joined: Oct 21, 2013 23:32
Location: Alberta, Canada

Re: WebFPC

Post by chrowle »

Ran it through valgrind. Useless. GDB returns something about getting screensize. Still investigating. I'm guessing it is GetMouse or Point.

EDIT: Doh, silly me, my custom FB has mouse support removed. Retesting with different FB.

Tested with different FB, same results.

Strange... It works on windows. Bug?
Sigord
Posts: 153
Joined: Mar 14, 2013 9:54
Location: Hastings UK
Contact:

Re: WebFPC

Post by Sigord »

Thanks for your interest and help folks. But i must emphasize being a Windows man with limited knowledge of all the complex code needing to be typed, I have NOT attempted to install FB in any Linux. Instead I just use http://fbc.deltalabs.de/ to compile code. This may explain why I need to reset permissions for each compiled code I before I can get it to run in Mint. Is there a way to avoid the need to reset permissions if I distribute my code to others such as online as Freeware?

Needless to say be assured I would not post code here unless it worked OK under FB along with Puppy Slackware, Knoppix, Mint ( and probably Ubuntu ) . I would be very interested to learn of any other Linux that runs my code. Below are 2 more versions of the program where I am no longer using Subroutines to avoid the problems with Puppy.

I hope to make a lot more FB code available to download from my site from the days of using QB and FB such as at http://www.sigord.co.uk/MISCL/QB/QBASIC.htm

Code: Select all

Dim As UInteger p,h,v,r,g,b,a
Dim As Integer x, y, buttons, res 

ScreenRes 880, 600, 32
Locate 30,34 
Print "Produced with Free Basic for Linux. Ver 2.1"
Locate 35,20
Print "Right click to start and then new colours. Left click to show RSGB Values" 
Sleep 1000 : Randomize , 1

Do
    ' Get mouse x, y and buttons. Discard wheel position.
    res = GetMouse (x, y, , buttons)
    Locate 74,30
    If res <> 0 Then '' Failure
        
        #ifdef __FB_DOS__
        Print "Mouse or mouse driver not available"
        #else
        Print "   ****** Mouse was not on the window ******    "
        #endif
        
    Else
        If buttons And 1 Then 
            locate 74,10 : Print Spc(20) : Locate 74,30 
            p = Point(x,y)           
            PRINT String$(20," ");"RGB CODE = ";p;String$(20," ")
        END If  
        If buttons And 2 then 
            Cls :v = 14
            While v < 560
                For h = 30 To 840 step 140
                    r = Int(Rnd * 256) : g = Int(Rnd * 256) : b = Int(Rnd * 256) : a = 0
                    r = Rnd * 255 + 1 : g = Rnd * 255 + 1 : b = Rnd * 255 + 1
                    Line (h, v)-(h + 60, v + 20), Rgba(r,g,b,a), BF
                    Locate v/8+1,h/8+9 : Print "  R=";Str$(r)
                    Locate v/8+2,h/8+9 : Print "G";Str$(g);" B";Str$(b)
                Next h
                v = v + 30
            Wend
            Sleep 500
        end if    
        Sleep 20
    End If
Loop While Inkey = ""
End

Code: Select all

Dim As UInteger p,h,v,r,g,b,a,c
Dim As Integer ok, s, f, l, d, k, x, y, buttons, res 
Dim As integer cr(300),cg(300),cb(300)

ScreenRes 880, 600, 32
Locate 30,28 
Print "Random Colour Chart Produced with Free Basic for Linux. Ver 2.1"
Locate 35,22
Print "Right click to start or for new colours. Left click to show RGB Values" 
Sleep 1000 : Randomize , 1

Do
    ' Get mouse x, y snd buttons. Discsrd wheel position.
    res = GetMouse (x, y, , buttons)
    Locate 74,30
    If res <> 0 Then '' Fsilure
        
        #ifdef __FB_DOS__
        Print "        Mouse or mouse driver not visible     "
        #else
        Print "           Mouse was not on the window        "
        #endif
        
    Else
        If buttons and 1 Then 
            locate 74,12 : Print Spc(20) : Locate 74,34 
            p = Point(x,y) : ok = 1 
            if x < 10 or x > 870 then ok = 0
            s = 14 : f = 34 : l = -1
            for d = 1 to 19          ' CHECK MOUSE CURSOR VERTICsLLY
                if y > s and y < f then l = d -1
                s = s + 30 : f = f + 30
            next d
            l = l * 11
            s = 10 : f = 70 : k = 0
            for d = 1 to 11           ' CHECK MOUSE CURSOR HORIZONTsLLY
                if x > s and x < f then k = d
                s = s + 80 : f = f + 80
            next d
            if d = 0 or l < 0 or k = 0 then ok = 0 ' NO BUTTON SELECTED
            k = k + l                               ' VsLUE OF BUTTON
            if k > c then ok = 0                ' NO BUTTON SELECTED
            If ok = 1 Then 
                Print "RED=";cr(k);" GREEN=";cg(k);" BLUE=";cb(k);" ID=";p
            End If    
            REM Sleep 500
        End If  
        If buttons and 2 then 
            Cls :v = 14 : c = 0
            While v < 560
                For h = 10 To 840 step 80
                    r = Int(Rnd * 256) : g = Int(Rnd * 256) : b = Int(Rnd * 256) : s = 0
                    r = Rnd * 255 + 1 : g = Rnd * 255 + 1 : b = Rnd * 255 + 1
                    c = c + 1 : cr(c) = r : cg(c) = g : cb(c) = b
                    Line (h, v)-(h + 60, v + 20), Rgba(r,g,b,a), BF
                Next h
                v = v + 30
            Wend
            Sleep 500
        end if    
        Sleep 20
    End If
Loop While Inkey = ""
End
angros47
Posts: 2324
Joined: Jun 21, 2005 19:04

Re: WebFPC

Post by angros47 »

Try in this way:

Code: Select all

    Dim As UInteger p, blue,green,red
    Dim As Integer x, y, buttons, res
    Declare Sub _Cols

    ScreenRes 880, 600, 32
    Cls : Locate 30,34
    Print "Produced with Free Basic for Linux. Ver 2.1"
    Randomize , 1
    Sleep 2000 : _Cols
    Locate 1,30
    Print "Left click to show RSGB Values, Right click new colours"

    Do
        ' Get mouse x, y and buttons. Discard wheel position.
        res = GetMouse (x, y, , buttons)
        Locate 74,30
        If res <> 0 Then '' Failure
           
            #ifdef __FB_DOS__
            Print "Mouse or mouse driver not available"
            #else
            Print "   ****** Mouse was not on the window ******    "
            #endif
           
        Else
            If buttons And 1 Then
                locate 74,10 : Print Spc(20) : Locate 74,30
                p = Point(x,y)           
                PRINT String$(20," ");"RGB CODE = ";p;String$(20," ")
            END If 
            If buttons And 2 then _Cols : Sleep 500
            Sleep 20
        End If
    Loop While Inkey = ""
    End

    Sub _Cols
    Dim As UInteger h,v,r,p,g,b,a
    Cls
    v = 14
    While v < 560
        For h = 30 To 840 step 140
            r = Int(Rnd * 256) : g = Int(Rnd * 256) : b = Int(Rnd * 256) : a = 0
            r = Rnd * 255 + 1 : g = Rnd * 255 + 1 : b = Rnd * 255 + 1
            Line (h, v)-(h + 60, v + 20), Rgba(r,g,b,a), BF
            Locate v/8+1,h/8+9 : Print "  R=";Str$(r)
            Locate v/8+2,h/8+9 : Print "G";Str$(g);" B";Str$(b)
        Next h
        v = v + 30
    Wend
    End Sub
I replaced "Cols" with "_Cols", it seems to work... somehow, FreeBasic in Linux does not like the name "Cols" for a sub.

It could be a bug related to this:
http://www.freebasic.net/forum/viewtopi ... =3&t=21947
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: WebFPC

Post by dkl »

Yea, it's the same kind of problem (#515). "Cols" becomes "COLS" thanks to FB's all upper case mangling, but unfortunately COLS is a global variable used by ncurses. Here, ncurses will end up using the COLS symbol provided by the FB program (due to how the linking works), instead of its own global COLS variable, and the crash probably happens because it tries to modify the COLS variable but ends up writing into read-only .text memory.

Normally the all upper case mangling prevents such issues, e.g. if one were to write a function called memcpy(), it would become MEMCPY(), thus not colliding with the memcpy() from libc/msvcrt. Of course by using Extern blocks are Alias it's still easy to "override" system functions. It's very unfortunate though that it happens even with the default all upper case mangling, without there being and warning/error message about it. So far I have only observed this with the global variables used by ncurses, but I'm sure there are other libraries (perhaps even the msvcrt/Win32API ones) that have all upper case symbols.
Post Reply