Author Topic: Lua port on nspire  (Read 6965 times)

0 Members and 1 Guest are viewing this topic.

Offline davyg

  • LV0 Newcomer (Next: 5)
  • Posts: 1
  • Rating: +4/-0
    • View Profile
Lua port on nspire
« on: April 17, 2011, 10:33:24 am »
Hello,

One or two months ago I worked on an editor and porting lua on the TI nspire.
I used lua 5.1.4 : http://www.lua.org/ftp/lua-5.1.4.tar.gz

I didn't manage to get more than an hello world from lua and I haven't had time to continue
it.

I've seen recently that TI made what i wanted to do but maybe my code can still interest
someone. This is a really crappy port, and the biggest problem is the longjmp support. I haven't
the qualification to do such a work and this was the occasion to learn so be indulgent.

The editor part is buggy but i think that most of them can rapidly be corrected. I lack of time so i didn't do
it.

This is generally buggy and launching it on a real calculator is at your own risk.

The source : ftp:// davyg.fr/spireEdit/spireEdit.zip (remove the space)

I used code from the skeleton available there, don't really know what to do with license since
it has no copyright : http://ourl.ca/4852.

This should compil with just a make.

If you have a questions, suggestions, if it doesn't work ... just ask.

Hoping that it can be usefull to someone.

Sorry for my english.

davyg
« Last Edit: April 17, 2011, 12:55:17 pm by davyg »

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: Lua port on nspire
« Reply #1 on: April 17, 2011, 10:58:15 am »
Thanks for releasing your code :)
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Lua port on nspire
« Reply #2 on: April 17, 2011, 09:39:53 pm »
Heya and welcome on the forums. Sorry to hear you don't have time to work on this anymore. Hopefully someone can finish it for people who don't have OS 3.0. :) Also a Lua 3.0 to Ndless Lua converter would be nice in the future.

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: Lua port on nspire
« Reply #3 on: May 05, 2011, 12:52:04 pm »
Bump :)

In order to achieve an even better performance than upstream Lua, we may want to use LuaJIT ( http://luajit.org/ ).
Quote
LuaJIT 2.0.0-beta7 — 2011-05-05

    New features:
        ARM port of the LuaJIT interpreter is complete.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline bsl

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 157
  • Rating: +14/-0
    • View Profile
Re: Lua port on nspire
« Reply #4 on: May 05, 2011, 01:09:58 pm »
Here are some math library routines revealed by Lua,
 and cross referenced to OS noncas 1.7

0X102A12E0   acos
0X102A1438   atan
0X102A1688   ceil
0X102A1840   exp
0X102A19D8   fabs
0X102A1A28   floor
0X102A1B20   frexp
0X102A1C58   ldexp
0X102A1D40   fmod
0X102A1FB8   pow
0X102A2118   sin
0X102A22D0   cos
0X102A2490   sqrt
0X105DD938   ln
0X105DDC70   pow
0X102A5ACC   rand
0X102A5B6C   srand
0X102A2630   tan

These are untested and useful for games that use game physics.

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: Lua port on nspire
« Reply #5 on: May 05, 2011, 01:15:02 pm »
Thanks :)

Have you sent a patch containing that information to the Ndless dev team ? ;)
[EDIT: maybe it's better to actually test them on OS 1.7 before doing so, though. I had missed the note when skimming through your post.]
« Last Edit: May 05, 2011, 01:16:03 pm by Lionel Debroux »
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Lua port on nspire
« Reply #6 on: May 09, 2011, 07:32:37 am »
Does this mean Lua on OS <3.x? Great! Good luck!

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: Lua port on nspire
« Reply #7 on: May 09, 2011, 07:33:28 am »
Yes, this could mean Lua on OS < 3.x... provided someone does the work of completing the port started by davyg :)

[EDIT: yup ruler501, I meant OS < 3.x :) ]
« Last Edit: May 09, 2011, 07:50:43 am by Lionel Debroux »
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: Lua port on nspire
« Reply #8 on: May 09, 2011, 07:47:20 am »
Lionel do you mean 3.x?

Would this be made so that code from 3.x Lua?
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: Lua port on nspire
« Reply #9 on: May 09, 2011, 08:11:28 am »
Being compatible with the Lua exposed by OS 3.0 needs additional work on top of porting Lua / LuaJIT.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline bsl

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 157
  • Rating: +14/-0
    • View Profile
Re: Lua port on nspire
« Reply #10 on: May 09, 2011, 10:37:09 pm »
The math functins I have listed above will work if the endiannes of the doubles are reversed.
Is there a compiler option for this ?
Here is an example:
Code: [Select]
// test program for NONCAS 1.7
static const unsigned sqrt_addrs[] = {0X102A2490, 0x0};
#define sqrt SYSCALL_CUSTOM(sqrt_addrs, double ,double)
int main(void) {
        double rr;
        rr = 2.0;
        printf("square root of 2 is %lf\n",sqrt(rr) );
        return 0;
}
The double breaks up into the registers r0 and r1 like this:
The working Lua version of this has at entry r0=00000000,r1=40000000
This C version has at entry  r0=40000000,r1=00000000
So a macro that flips the double or a compiler option will fix this.

EDIT: The above program works if changed to:
Code: [Select]
static const unsigned sqrt_addrs[] = {0X102A2490, 0x0};
#define sqrt SYSCALL_CUSTOM(sqrt_addrs, double ,double)

double dswap(double v) 
{
    union {
        unsigned long long i;
        double  d;
    } conv;
    conv.d = v;
    conv.i = (conv.i << 32) | (conv.i >> 32);
    return conv.d;
}

int main(void) {
        double rr;
        rr = 2.0;
        printf("square root of 2 = %15.15f\n",sqrt(dswap(rr)));
        return 0;
}
However, a custom call has to be specially made for the remaing math functions.
« Last Edit: May 10, 2011, 11:09:36 pm by bsl »