Output for Dalvik VM (Android) for FB or other mobiles?

General discussion for topics related to the FreeBASIC project or its community.
MikeS
Posts: 56
Joined: Feb 05, 2006 17:47

Output for Dalvik VM (Android) for FB or other mobiles?

Post by MikeS »

I wonder if FB would be able to output to the Dalvik VM since FB already outputs to some intermediate format. Are there any current efforts to have FB output to Android or any of the mobile platforms?

I am wondering if we will be able to write FB programs for the new windows 8 phone since it supports native C++ apps. What efforts can be made? Any insights on how the XBox support was added a while ago?

Some resources:
http://www.dalvikvm.com/
jevans4949
Posts: 1186
Joined: May 08, 2006 21:58
Location: Crewe, England

Re: Output for Dalvik VM (Android) for FB or other mobiles?

Post by jevans4949 »

Probably the best option at present would be the -gen gcc output option, depending on whether the C++ compiler can cope with the code generated.

Having spent 5 minutes looking at your link, my main comment would be that the concept is heavily class-based, and although FB now has classes, it may not be the best vehicle for this target.

The code generation part of the compiler would need to be re-written, and if (as it seems) the virtual machine is substantially different from the Intel, this may require a lot of thought.

Actual development would require a delevloper with access to a development platform for the target devices, and the time and patience to do it.

Is this VM available for Intel platforms, or only ARM?
roook_ph
Posts: 402
Joined: Apr 01, 2006 20:50
Location: philippines
Contact:

Re: Output for Dalvik VM (Android) for FB or other mobiles?

Post by roook_ph »

The old Xbox has the same microprocessor as Intel and AMD. When xbox 360 arrives the microprocessor is alien, the graphics card is alien Freebasic capability stops there.
Java is different from c . It is not a native code it relies on virtual machine to run. Android converts java
byte code into davlik that runs like it was a native code but on very specific processor only.
There is hope though there's an ndk that will enable c++ to work on android. and freebasic has this gcc output maybe we can work from there .
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Output for Dalvik VM (Android) for FB or other mobiles?

Post by marcov »

MikeS wrote:I wonder if FB would be able to output to the Dalvik VM since FB already outputs to some intermediate format.
Pretty difficult I would guess. An easier route might be to compile to C, then have that compiled to native ARM code in dynamic libraries and have a Java skeleton call that.
Are there any current efforts to have FB output to Android or any of the mobile platforms?
Not that I know. There is gen C that has some ability to generate code for other architectures, but I haven't really seen many people reporting they had success with that route. So while possible on paper, that is all in the initial stages.
I am wondering if we will be able to write FB programs for the new windows 8 phone since it supports native C++ apps. What efforts can be made?
I doubt it is possible in a reasonable timeframe. One is skipping several steps here. The first target would be to get FB code running on something ARM with a standard Linux via cGEN. This because tooling and hardware is fairly easy to get, and there are not or few legal barriers. Hardware wise, thinking of NAS boxes and development boards like Panda board and Raspberry PI as target. Maybe those cheap tablets are also possible.

If the cgen can compile most programs for X86, a person who knows the compiler should be able to such step in a few months (in the evenings as a hobby, fultlime is a different matter).

Only then you can start thinking of going in the highly volatile market that is phone.

And keep in mind that in general to run own code on a mobile device you need (1) a developer connection subscription of the relevant vendor or (2) a rooted device or a device specially meant for Android. (which often makes the device useless as phone).

With Android (2) is said to be an option, for Mobile and Apple (1) is probably more realistic.
Any insights on how the XBox support was added a while ago?

XBox is basically a energy efficient Pentium-III. Most people run only software on it when Linux is installed on it.

Basically it is a power efficient PC in a strange looking box.
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Output for Dalvik VM (Android) for FB or other mobiles?

Post by marcov »

roook_ph wrote:The old Xbox has the same microprocessor as Intel and AMD. When xbox 360 arrives the microprocessor is alien,
(PowerPC based Cell actually, not THAT alien. )
MikeS
Posts: 56
Joined: Feb 05, 2006 17:47

Re: Output for Dalvik VM (Android) for FB or other mobiles?

Post by MikeS »

Thanks for the feedback guys. Perhaps something can be done to support an ARM architecture. I haven't read too much on the davlik, but I will try to look for some more resources such as where the NDK could maybe simplify the task. I really think it'd be great to get FB onto some mobile platforms. :)
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Output for Dalvik VM (Android) for FB or other mobiles?

Post by marcov »

Btw, I might have said it before, but if some of the devels is considering developing for other architectures (via cgen or else), I would consider getting a powerpc mac mini. Reasons:
  • Affordable, 2nd hand minis can be had for Eur 100-125 here. Maybe lower if you wait for a good deal.
  • That Eur 125 purchase can be anything you need except for a normal PC monitor, network cable and usb kbd/mouse. No additional hidden costs. Make sure you have enough memory though!!!
  • In general it is a "full" workable system, not just an embedded target where you can run the results to test only.
  • All equipment and expansions are not ridiculously expensive. Think SDRAM as RAM, 2.5" IDE drive, usb kbd and mouse, dvi and vga monitor.
  • Since SDRAM is getting old, memory wise get 256MB for the OS + the space you need for FB and its tools. Get the minimal amount directly, since upgrades can be relatively expensive and are not trivial to install due to the rigid aluminium shell
  • HDD is less important. Even the minimal 40GB is enough for these cases. The smallest ones are 4300rpm though afaik, while newer/bigger ones are 5400rpm. Is noticable.
  • care for price and memory more than exact CPU speed (range 1.25GHz...1.5GHz, but they are relatively slow GHz). It will be painfully slow anyway, and for longer periods you don't notice a 10 % speedup. The newer models are more interesting due to the upgrades to the rest of the hardware than the raw CPU speed.
  • Most came with a DVI->VGA converter in the box. Make sure it is there. Make also sure the install media is there (probably it will be an older version than it is running, but at least it is something)
  • Get a simple USB KVM and it doesn't really eat up much space.
  • No "difficult" problems in the these iterations of the architecture like exceptions on misalignment.
  • Big endian though.
  • An OS to work with that has a browser (firefox derivative tenfourfox), gcc comes on the OS CD, most *nix software though in older versions, you can SSH to it, put samba on it etc.
  • One could also put Linux on it, but I would start with OS X.
To give you an idea of the speed:
- On a Core2 6600 (2.4GHz), a bootstrap of FPC takes slightly under 2minutes.
- On a powerpc (G4e 1.42Hgz) it is in the magnitude of 10-11min. No compromises though.
- I compiled the open edition of QT once. It took 8hrs (but memory was a severe bottleneck, I still had 512MB back then)
- on a Sheevaplug (armv5, 1.2GHz, your average cheap NAS with USB HDD) it takes about 30mins, and that is *WITH* several simplifying parameters.

.. you don't want to know about a Quadra 840AV

Note that I'm NOT a Mac nut. I got the mini's at the time for exactly the same purpose (playing with other architectures development wise).
Last edited by marcov on Jun 26, 2012 21:17, edited 1 time in total.
roook_ph
Posts: 402
Joined: Apr 01, 2006 20:50
Location: philippines
Contact:

Re: Output for Dalvik VM (Android) for FB or other mobiles?

Post by roook_ph »

I dont think freebasic even with gcc out will work on powerPC or ARM , If they do this forum will be flooded with snippets and codes. Mac and ARM should be off topic or should I say dreamer's topic.
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Output for Dalvik VM (Android) for FB or other mobiles?

Post by marcov »

roook_ph wrote:I dont think freebasic even with gcc out will work on powerPC or ARM,
I think you could get it to hello world level pretty quickly. But the road to clean the whole project of x86 assumptions will be harder and longer. Not particularly difficult, but just a period of an year where multiple x86isms and assumptions turn up .
If they do this forum will be flooded with snippets and codes.
Why? While there are many arm devices, there are less people that program for them (if only because ARM is heavily fragmented and an arm binary for an newer device won't work on an older)
Mac and ARM should be off topic or should I say dreamer's topic.
I don't see any reason for that. Maybe concrete stuff only, but off topic?
Last edited by marcov on Jun 26, 2012 6:41, edited 1 time in total.
MikeS
Posts: 56
Joined: Feb 05, 2006 17:47

Re: Output for Dalvik VM (Android) for FB or other mobiles?

Post by MikeS »

marcov, I actually do have a Mac Mini for many of the reasons you've stated. On my laptop I have Win7 with a virtual box with android installed. I am ready to program on multiple platforms. :)
roook_ph
Posts: 402
Joined: Apr 01, 2006 20:50
Location: philippines
Contact:

Re: Output for Dalvik VM (Android) for FB or other mobiles?

Post by roook_ph »

I think you could get it to hello world level pretty quickly. But the road to clean the whole project of x86 assumptions will be harder and longer. Not particularly difficult, but just a period of an year where multiple x86isms and assumptions turn up .
I was here in 2006 the oldest ones since 2004 and I have never heard of freebasic outside x86 , must be pretty difficult.
I am ready to program on multiple platforms. :)
good luck on that
sgaba
Posts: 31
Joined: Aug 15, 2005 19:18
Location: Czech Republic

Re: Output for Dalvik VM (Android) for FB or other mobiles?

Post by sgaba »

Hello
I have (maybe) good news for you.
I found C4droid (C/C++ compiler) on https://play.google.com/store/apps/deta ... 4.droidsdl
There is GCC,G++ plug in and SDL plug in too.

So I tried to install it. Then compile PRINT "Hello Android" by Freebasic.
I found hv.c after it.

Code: Select all

// Compilation of zakad.bas started at 18:28:42 on 07-18-2012
typedef char byte;
typedef unsigned char ubyte;
typedef unsigned short ushort;
typedef int integer;
typedef unsigned int uinteger;
typedef unsigned long ulong;
typedef long long longint;
typedef unsigned long long ulongint;
typedef float single;
typedef struct _string { char *data; int len; int size; } string;
typedef char fixstr;
typedef ushort wchar;
void __attribute__((stdcall)) fb_PrintString( integer, string*, integer );
string* __attribute__((stdcall)) fb_StrAllocTempDescZEx( char*, integer );
void __attribute__((stdcall)) fb_Init( integer, char**, integer );
void __attribute__((stdcall)) fb_End( integer );
typedef struct _$fb_RTTI $fb_RTTI$type;
typedef struct _$fb_RTTI {
	void* STDLIBVT;
	char* ID;
	$fb_RTTI$type* PRTTIBASE;
} $fb_RTTI;
extern $fb_RTTI$type __fb_ZTS6Object;

integer main( integer __FB_ARGC__$, char** __FB_ARGV__$ )
{
	integer fb$result$;
	#define vr$0 ((integer*)(&fb$result$))
	__builtin_memset( vr$0, 0, (integer)4 );
	fb_Init( __FB_ARGC__$, __FB_ARGV__$, (integer)0 );
	label$0:;
	string* vr$1 = (string*)(fb_StrAllocTempDescZEx( (char*)"Test", (integer)4 ));
	fb_PrintString( (integer)0, vr$1, (integer)1 );
	label$1:;
	fb_End( (integer)0 );
	#define vr$2 ((integer)(fb$result$))
	return vr$2;
}
// Total compilation time: 8.768515864687743e-005 seconds. 
And next i tried compile these C file by c4droid... and error...

undefined reference to `fb_int
undefined reference to `fb_End@4|
....and so on
This is what I got

I tryed compile it by Code::Blocks minGW and the same..
What I have to include to compile it?

good luck
and sorry for my English....
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Output for Dalvik VM (Android) for FB or other mobiles?

Post by marcov »

sgaba wrote:Hello
I have (maybe) good news for you.
I found C4droid (C/C++ compiler) on https://play.google.com/store/apps/deta ... 4.droidsdl
There is GCC,G++ plug in and SDL plug in too.
The stdcall stuff doesn't make sense. There is no stdcall on *nix. At least the @4 missing symbol is related to that.
sgaba
Posts: 31
Joined: Aug 15, 2005 19:18
Location: Czech Republic

Re: Output for Dalvik VM (Android) for FB or other mobiles?

Post by sgaba »

OK. And why Freebasic C emitter emitor use stdcall when it is not Cross-platform? What can be done with it?
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: Output for Dalvik VM (Android) for FB or other mobiles?

Post by dkl »

FB uses Stdcall by default on Win32, but Cdecl on Linux. The code generated for either platform (no matter whether asm or C backend) cannot be generic enough to work on all platforms. I think Android is Linux, so you'll need to compile for Linux, not Win32. The easiest way to do that with FB 0.23 is to install the Linux version on a Linux system and compile there.

The internal fb_*() functions are implemented in libfb.a, linking manually (i.e. not using fbc to do it) requires the inclusion of -lfb and fbrt0.o, and potentially other libraries. Check fbc -v to see the linking command it usually uses.

I'm not sure whether the FB Linux rtlib binaries could work as-is on Android (is the libc compatible enough? what about ncurses? gpm? X11?), so it may be necessary to port and/or recompile it.
Post Reply