FBC 1.00.0

General discussion for topics related to the FreeBASIC project or its community.
Amundo
Posts: 57
Joined: Feb 26, 2007 0:25

Re: FBC 1.00.0

Post by Amundo »

Better late than never!

Congratulations and thanks to everyone, from v1ctor to dkl and others, for reaching this milestone.

A lot of work must have gone (and still has to go) into FB.

I can only admire people's (dkl esp.) dedication and drive to work on something year after year to improve and progress it...
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FBC 1.00.0

Post by dodicat »

Hi Quark.
Xp is OK, but Pentium 3 is very slow, especially graphics.

I've changed the battery and keyboard on my other computer, still a blue screen.

Still I suppose what goes round comes round.

Not long ago I was blue-screening forum members.

Code: Select all

    'macro to read the text
    #macro rd(ln)
    s=string(ln," ")
    for n as integer=0 to ln-1
        read s[n]
    next n
    t+=s
    #endmacro

    dim as integer desktopW,desktopH
    screeninfo desktopW,desktopH

    'declare this function
    Declare Function ScaleWindow Alias "MoveWindow"(As Any Ptr,As Integer=0,As Integer=0,As Integer,As Integer,As Integer=1) As Integer



    'set the screen size
    dim as integer W=640
    dim as integer H=480

    'create the window (No-Frame)
    screenres W,H,,,8
    width W\8,H\16 'to make the text bigger
    color 7,1 'set the window colours
    cls


    'Get the text for printing into t
    dim as string s,t
    rd(68):rd(58):rd(2):rd(56):rd(69):rd(56):rd(2):rd(56)


    '========scaling method==========
    Dim As Integer I
    Screencontrol(2,I)
    'start at fullscreen
    ScaleWindow(Cast(Any Ptr,I),0,0,desktopW,desktopH)
    '===============  ===============

        locate 10,5
        print t
    sleep
    
    '===============================================================================
    'text data
    data 65,32,102,97,116,97,108,32,101,120,99,101,112,116,105,111,110,32,79,69,32,104,97,_
    115,32,111,99,99,117,114,114,101,100,32,97,116,32,48,48,50,56,58,67,48,48,49,49,_
    69,51,54,32,105,110,32,86,88,68,32,86,77,77,40,48,49,41,32,43,10
    data 32,32,32,32,48,48,48,49,48,69,51,54,46,32,84,104,101,32,99,117,114,114,101,110,116,32,97,112,_
    112,108,105,99,97,116,105,111,110,32,119,105,108,108,32,98,101,32,116,101,114,109,_
    105,110,97,116,101,100,46,10
    data 10,10
    data 32,32,32,32,42,32,80,114,101,115,115,32,97,110,121,32,107,101,121,32,116,111,32,_
    116,101,114,109,105,110,97,116,101,32,116,104,101,32,99,117,114,114,101,110,116,_
    32,97,112,112,108,105,99,97,116,105,111,110,10
    data 32,32,32,32,42,32,80,114,101,115,115,32,67,84,82,76,32,43,32,65,76,84,32,43,32,68,_
    69,76,32,97,103,97,105,110,32,116,111,32,114,101,115,116,97,114,116,32,121,111,_
    117,114,32,99,111,109,112,117,116,101,114,46,89,111,117,32,119,105,108,108,10
    data 32,32,32,32,32,32,108,111,111,115,101,32,97,110,121,32,117,110,115,97,118,101,100,_
    32,105,110,102,111,114,109,97,116,105,111,110,32,105,110,32,97,108,108,32,97,112,_
    112,108,105,99,97,116,105,111,110,115,46
    data 10,10
    data 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,_
    80,114,101,115,115,32,97,110,121,32,107,101,121,32,116,111,32,99,111,110,116,105,_
    110,117,101,32,95
    
      
Quark
Posts: 474
Joined: May 27, 2011 18:16
Location: Pennsylvania, U.S.
Contact:

Re: FBC 1.00.0

Post by Quark »

.
@Dodicat

Thanks for that chilling display. What unfond memories it evokes! Mis-spelling in 2nd to last line gives the game away (loose for lose), but still skillfully horrible. So close to Halloween too :-[

By battery, you refer to CMOS battery? I have had the weirdest symptoms from that before twigging to the problem and replacing it. Wish I had something useful to suggest. Maybe Knoppix?
.
stealth
Posts: 8
Joined: Mar 21, 2012 9:30

Re: FBC 1.00.0 issue with Draw statement

Post by stealth »

Well done, I use Freebasic for some years now, and like it very much.

Last night I've compiled an existing project with FBC 1.00.0 and noticed that the grafic part is changed or has a bug.
I've problems with the (compatibility) of the Draw statement which behaves differently in FBC 1.00.0.

I had to go back to Version 0.90.1 :-(

Is this a bug or a change?

BR
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: FBC 1.00.0

Post by fxm »

See at http://www.freebasic.net/forum/viewtopi ... 55#p200555 and the following posts.

This is a regression (on command 'X' of DRAW) which affects the 1.00.0 release.
That has now been corrected by gfxlib2: Don't forget contextual x/y position for X<address> subcommands, but this correction will only be applied in the future official version 1.01.0.

For the release, see http://www.freebasic.net/forum/viewtopi ... 48#p201948
Last edited by fxm on Oct 22, 2014 11:13, edited 2 times in total.
podvornyak
Posts: 148
Joined: Nov 12, 2007 11:46
Location: Russia

Re: FBC 1.00.0

Post by podvornyak »

Thanks for release!
Im in trouble again.

Code: Select all

Function AddFive (ByVal num As Integer) As Integer
    Asm
        mov eax, [num]
        add eax, 5
        mov [Function], eax
    End Asm
End Function

Dim i As Integer = 4
Print "4 + 5 ="; AddFive(i)
with fbc -asm intel
test2.c: Assembler messages:
test2.c:24: Error: incorrect register `eax' used with `q' suffix
test2.c:26: Error: incorrect register `eax' used with `q' suffix

ubuntu 12.04 x64 intel i3

Everything other is alright. Even old GL/gl.bi working
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: FBC 1.00.0

Post by dkl »

FB's Integer data type becomes 64bit on 64bit. Looks like the assembler refuses to mov a 64bit value into the 32bit eax register. Maybe it will work with rax instead of eax, or by using the 32bit Long data type instead of Integer.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: FBC 1.00.0

Post by MichaelW »

I can make the basic idea work in a 64-bit app:

Code: Select all

function AddFive( byval num as integer ) as integer
    asm
        ".intel_syntax noprefix"
        "mov    rax, [rbp+16]"
        "add    rax, 5"
        "mov    [rbp-8], rax"  
        ".att_syntax prefix"
    end asm
end function

dim as integer i = 4
print AddFive(i)
sleep
But to do so I had to determine where on the stack the num parameter and the function return value were stored, and the only reasonable way I can see to do this is to compile with the -RR option and look at the compiler-generated assembly.
podvornyak
Posts: 148
Joined: Nov 12, 2007 11:46
Location: Russia

Re: FBC 1.00.0

Post by podvornyak »

dkl wrote:FB's Integer data type becomes 64bit on 64bit. Looks like the assembler refuses to mov a 64bit value into the 32bit eax register. Maybe it will work with rax instead of eax, or by using the 32bit Long data type instead of Integer.
indeed

Code: Select all

function AddFive (ByVal num As long) As long
    Asm
        MOV EAX, [num]
        ADD EAX, 5
        MOV [function], EAX
    End Asm
End Function
function AddFiveI (ByVal num As Integer) As Integer
    Asm
        MOV RAX, [num]
        ADD RAX, 5
        MOV [function], RAX
    End Asm
End Function

Dim i As long = 4
Dim ii As Integer = 4

Print "4 + 5 ="; AddFive(i)
Print "4 + 5 ="; AddFiveI(ii)
Thanks
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: FBC 1.00.0

Post by MichaelW »

Here is a better example, that shows a (small) problem with naked functions for X64:

Code: Select all

function AddFiveNaked naked( byval num as integer ) as integer
    asm
        ".intel_syntax noprefix"
        "sub    rsp, 40"
        "mov    rax, rcx"
        "add    rax, 5"
        "add    rsp, 40"
        "ret"
        ".att_syntax prefix"
    end asm
end function

'' This will not work, get "undefined reference to J$":
''    dim shared as integer j = 4
'' But this does work:

dim shared as integer j,k
j = 4

'' This will not work, get "undefined reference to ADDFIVENAKED":
''    print AddFiveNaked(i)
'' And the reason is that the compiler adds a leading underscore
'' to the function label:"_ADDFIVENAKED", but the code to call
'' the function leaves off the underscore. So to test the function
'' I called it from assembly code:
asm
    ".intel_syntax noprefix"
    "mov    rcx, J$"
    "call    _ADDFIVENAKED"
    "mov    K$, rax"
    ".att_syntax prefix"
end asm
print k

sleep
And I forgot to add for my previous example that I used a DIM SHARED variable because the names are easy to predict, and so far I have not found any reasonable way to access a variable allocated from the stack.

Edit:

As a follow up I tried a similar app with the 1.01.0 compiler with the stated results:

Code: Select all

function AddFive( byval num as integer ) as integer
    return num + 5
end function

'' With the above function and the call to it below commented out,
'' the compiled app triggers an access violation exception.
'' With the above function and the call to it compiled into the
'' app, it displays "9" for both function calls and no exception
'' is triggered.

function AddFiveNaked naked( byval num as integer ) as integer
    asm
        ".intel_syntax noprefix"
        "sub    rsp, 32 "
        "mov    rax, rcx"
        "add    rax, 5"
        "add    rsp, 32"
        "ret"
        ".att_syntax prefix"
    end asm
end function

dim shared as integer i = 4

print AddFive(i)

print AddFiveNaked(i)

sleep

Sorry, I have no time ATM to investigate further.
Last edited by MichaelW on Dec 31, 2014 6:37, edited 1 time in total.
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: FBC 1.00.0

Post by dkl »

Oh, I didn't even know that Win64 doesn't use underscore prefixes for global symbols like Win32... should be easy to adjust fbc for this though.
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: FBC 1.00.0

Post by marcov »

That reminds me, are globals RIP relative in FB (win64)?

IIRC gcc does, and that is a common cause of breakage with "upgraded" 32-bit assembler.

See e.g. Eli Bendersky's
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: FBC 1.00.0

Post by dkl »

I don't know, but since 64bit FB is currently entirely based on the C backend, it's whatever gcc does.

On a possibly related note, I know that we need to use -fPIC on linux-x86_64 (and ARM etc.) for shared libraries, but for Win64, there is no need for -fPIC like that, and I think I read somewhere that that's because on Win64 all code always is position independant.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: FBC 1.00.0

Post by MichaelW »

marcov wrote:That reminds me, are globals RIP relative in FB (win64)?
See e.g. Eli Bendersky's
While I am familiar with IP-relative addressing in code, where a jump or call destination can be effectively encoded as a "displacement", and where the functional description of these operations makes perfect sense, IP-relative data addressing seems more than a little bizarre. The instruction pointer, which formerly was not directly accessible in code, now is directly accessible, and usable as part of an indirect-memory operand.

Code: Select all

dim shared as integer global_arr(99) = {2, 3}
static shared as integer static_arr(99) = {9, 7}
dim shared as integer global_arr_big(49999) = {5, 6}
static shared as integer static_arr_big(49999) = {10, 20}

function global_func(byval param as integer) as integer
    return param * 10
end function

function main(byval argc as integer, byval  argv as zstring ptr ptr) as integer
    dim as integer t = global_func(argc)
    t += global_arr(7)    
    t += static_arr(7)
    t += global_arr_big(7)
    t += static_arr_big(7)
    return t
end function

Code: Select all

	.file	"test.c"
	.data
	.align 64
GLOBAL_ARR$:
	.quad	2
	.quad	3
	.space 784
	.align 64
STATIC_ARR$:
	.quad	9
	.quad	7
	.space 784
	.align 64
GLOBAL_ARR_BIG$:
	.quad	5
	.quad	6
	.space 399984
	.align 64
STATIC_ARR_BIG$:
	.quad	10
	.quad	20
	.space 399984
	.text
	.globl	GLOBAL_FUNC
	.def	GLOBAL_FUNC;	.scl	2;	.type	32;	.endef
GLOBAL_FUNC:
	pushq	%rbp
	movq	%rsp, %rbp
	subq	$16, %rsp
	movq	%rcx, 16(%rbp)
	movq	$0, -8(%rbp)
.L2:
	movq	16(%rbp), %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	movq	%rax, -8(%rbp)
	nop
.L3:
	movq	-8(%rbp), %rax
	leave
	ret
	.globl	MAIN
	.def	MAIN;	.scl	2;	.type	32;	.endef
MAIN:
	pushq	%rbp
	movq	%rsp, %rbp
	subq	$64, %rsp
	movq	%rcx, 16(%rbp)
	movq	%rdx, 24(%rbp)
	movq	$0, -24(%rbp)
.L6:
	movq	16(%rbp), %rcx
	call	GLOBAL_FUNC
	movq	%rax, -8(%rbp)
	movq	-8(%rbp), %rax
	movq	%rax, -16(%rbp)
	movq	56+GLOBAL_ARR$(%rip), %rax
	addq	%rax, -16(%rbp)
	movq	56+STATIC_ARR$(%rip), %rax
	addq	%rax, -16(%rbp)
	movq	56+GLOBAL_ARR_BIG$(%rip), %rax
	addq	%rax, -16(%rbp)
	movq	56+STATIC_ARR_BIG$(%rip), %rax
	addq	%rax, -16(%rbp)
	movq	-16(%rbp), %rax
	movq	%rax, -24(%rbp)
	nop
.L7:
	movq	-24(%rbp), %rax
	leave
	ret
	.def	__main;	.scl	2;	.type	32;	.endef
	.globl	main
	.def	main;	.scl	2;	.type	32;	.endef
main:
	pushq	%rbp
	movq	%rsp, %rbp
	subq	$48, %rsp
	movl	%ecx, 16(%rbp)
	movq	%rdx, 24(%rbp)
	call	__main
	movl	$0, -4(%rbp)
	movq	24(%rbp), %rax
	movl	$0, %r8d
	movq	%rax, %rdx
	movl	16(%rbp), %ecx
	call	fb_Init
.L10:
.L11:
	movl	$0, %ecx
	call	fb_End
	movl	-4(%rbp), %eax
	leave
	ret
	.ident	"GCC: (x86_64-win32-sjlj-rev0, Built by MinGW-W64 project) 4.9.1"
	.def	fb_Init;	.scl	2;	.type	32;	.endef
	.def	fb_End;	.scl	2;	.type	32;	.endef
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: FBC 1.00.0

Post by MichaelW »

And a small test app, that displays the expected 90h:

Code: Select all

dim shared as integer x
asm
    ".intel_syntax noprefix"
    "movzx  rax, BYTE PTR [eip]"
    "nop"
    "mov    X$, rax"
    ".att_syntax prefix"
end asm
print hex(x);"h"
sleep
Post Reply