Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI-Nspire => Topic started by: rwill on June 15, 2014, 01:37:33 pm

Title: So I am porting Quake to the Nspire...
Post by: rwill on June 15, 2014, 01:37:33 pm
So with the recent release of ndless for 3.6 I have chosen to aquire a TI-Nspire CX and do some programming.

To get a feeling for the platform I have further chosen to port some first person shooter from 1996 and in nspire_emu it runs pretty well. However on my OS 3.6 Nspire CX CAS it first did not run at all and once I removed all printfs it ran but was kind of slow compared to nspire_emu. So I have some questions ..

1. Does it matter if I try to printf to the console ( serial port ? ) and there is no receiver connected ? From my program failure it appears so but I rather have the printfs() in so I can debug using nspire_emu. Are there other pitfalls that do not occur in nspire_emu but do on real hardware that can cause something like this ?

2. Either my Nspire ( hardware revision M ) is slower than normal Nspires or nspire_emu is faster than the actual hardware. As with porting some game most time is spent adapting to the new platform ( read optimizing ) I am wondering if nspire_emu is even cycle accurate or if I can only rely on benchmarks run on the real hardware.

So this is all that is going around in my head now.. I'll try to attach some photo to show my current progress.


PS: To skip my introduction in the introduction board I am the guy that did that Delsgolf FPS for the TI-89 last year.

*edit* Changed Title
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: kevinkore3 on June 15, 2014, 02:08:39 pm
From my experience, nspire_emu is a lot faster than the calculator, even at the same CPU frequency. It's not an accurate benchmark for performance (I wish it was).
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: pimathbrainiac on June 15, 2014, 02:10:44 pm
Are you using nGL for this, or some other libraries?
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: Vogtinator on June 15, 2014, 02:19:23 pm
Quote
1. Does it matter if I try to printf to the console ( serial port ? ) and there is no receiver connected ? From my program failure it appears so but I rather have the printfs() in so I can debug using nspire_emu. Are there other pitfalls that do not occur in nspire_emu but do on real hardware that can cause something like this ?
Don't call printf on real hardware, just use a macro like
Code: [Select]
#ifdef DEBUG
    #define debug(x, ...) printf(x, __VA_ARGS__)
#else
    #define debug(x, ...)
#endif
and only define DEBUG if you're using the emulator.
The HW waits for the data to be transmitted, nspire_emu doesn't wait and just emits it. This can cause a huge slowdown on HW.

Also, nspire_emu is a lot faster in some cases, but if you're doing heavy IO, such as memory access, it's roughly the same.
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: rwill on June 15, 2014, 02:25:20 pm
Are you using nGL for this, or some other libraries?

I am using the original WinQuake sources as released by id software without any additional libraries.
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: Streetwalrus on June 15, 2014, 03:14:25 pm
Wow that does look good. And yeah, Nspire_emu is totally not accurate. Memory accesses for example are a lot faster than on real hardware among other things.
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: DJ Omnimaga on June 15, 2014, 09:10:47 pm
This looks very nice, especially with the diagonal parts of the walls/ceiling. Knowing the great work you did in Desgolf I can only assume that this Nspire FPS will be very solid. :D

Welcome to the forums by the way :)
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: bb010g on June 15, 2014, 10:35:06 pm
This is looking awesome. Welcome to Omnimaga!
!peanuts

Ninja edit: Is that Quake? O.O
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: aeTIos on June 16, 2014, 09:23:42 am
Is that Quake? O.O
My reaction exactly.
also.
!peanuts
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: Princetonlion.tibd on June 16, 2014, 09:26:29 am
(http://www.omnimaga.org/Smileys/classic/peanut-bag.gif)
And it's a FPS!
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: rwill on June 16, 2014, 03:58:34 pm
This is looking awesome. Welcome to Omnimaga!

Ninja edit: Is that Quake? O.O

Yes it is Quake. I kind of overestimated the speed of the Nspire CX though so it will never run really fast i guess. TI calculators do not seem to follow Moore's law.
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: DJ Omnimaga on June 16, 2014, 04:00:43 pm
Indeed. In 1997, Z80 calcs had 96 KB of user RAM available. Now in 2014, they have fewer than 24 KB and cost as much. Granted, there is Flash, but still, it all comes back to XKCD #768. At least the HP Prime is a signifiant hardware:price ratio improvement, although there is still work to do and it cannot run ASM/C yet.
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: Streetwalrus on June 17, 2014, 04:07:34 am
Wow that's epic. O.O

Also the game welcome to Omni ! :D
!peanuts
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: Roondak on June 18, 2014, 05:35:43 pm
Very impressive, can't wait to try this on my Nspire!
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: rwill on June 25, 2014, 04:10:26 pm
-- Development Update --

Although I have run my fair share of tests it would be cool if some other people can test it and report any errors found. Like graphical errors or crashes.

So if someone wants to test it here is a current build + sources. You need a CX to run, non-color nspire wont work.

In addition to the quake binary for the nspire you need at least the shareware data file pak0.pak. This is kind of hard to get when not running MS-DOS and one wants to honor the license so I deliver instructions:

-- Begin of Instructions of how to get the Shareware pak0.pak --

Get the quake shareware release quake106.zip somewhere of the internet.
One place is here: ftp://ftp.netbsd.org/pub/pkgsrc/distfiles/quake106.zip

Inside the quake106.zip is a file called resource.1 - Extract it and rename it to resource.x

Get the LHa compression/uncompression utility. For Unix ask your packet manager. On windows this is somewhat hard but you can get a binary release here: http://gnuwin32.sourceforge.net/packages/lha.htm ( Binaries, the lha.exe inside the .zip is in /bin ). I read somewhere that the japanese Windows 7 gets it as an addon for the file explorer so you can also try that.

Move resource.x to a temporary directory and extract it. On windows you can do this with "lha x resource.x" if you moved lha.exe to the same temporary folder or lha.exe is in your $PATH. This hopefully creates a lot of obsolete files and a directory called "id1" which contains "pak0.pak"

You can also get Quake off Steam or so I heard.

-- End Of Instruction of how to get the Shareware pak0.pak --

MD5 Sums of the quake data files
pak0.pak 5906e5998fc3d896ddaf5e6a62e03abb
pak1.pak d76b3e5678f0b64ac74ce5e340e6a685 ( registered version )

On the calculator you need a directory structure like so:

quake/nquake.tns
quake/id1/pak0.pak.tns
quake/id1/pak1.pak.tns ( optional, if you bought Quake and got the pak1.pak file of the registered version put it there )


Then run nquake.tns

Title: Re: So I am porting that first person shooter to the Nspire...
Post by: Vogtinator on June 25, 2014, 05:19:40 pm
I took a quick look and the source code:
Is it really so slow that you had to use assembler for custom "incorrect" division  O.O ? How much was the speedup?
And if you want to make it as fast as possible without any source changes, I'd advise you to use the genzehn tool and the zehn format from
my ndless fork (https://github.com/Vogtinator/ndless) and the same optimization options in the Makefile that I use in crafti (https://github.com/Vogtinator/crafti/blob/master/Makefile#L6) (especially -flto, -mcpu, -Ofast). In crafti there isn't anything in assembler yet, pure C++ and it runs fast enough (I may change the asm thing, if your "incorrect" version makes a significant difference).
But if you really want to dig into the "every cycle counts" I may point you to __builtin_prefetch or the "PLD"(preload) arm instruction.

I didn't follow any of the steps and actually ran it, though, too much work to do for a game I'm not really a fan of, sorry.  :/
It looks really awesome though  :o
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: gameblabla on June 26, 2014, 12:51:29 am
Hello,
i tried it on my TI nspire CX and it's actually very playable , i'm impressed !
Here's how it runs on my calc :


(I have overclocked mine to 264 Mhz but it runs well too in 132 Mhz if you lower the screen size a bit)
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: DJ Omnimaga on June 26, 2014, 03:12:18 am
This is awaiting in the Omnimaga front page headlines queue right now. I am astonished by how fast it runs in the video above (although I guess it helps that you overclocked your calc to 264 MHz. Mine can only go up to 242 or so before it goes unstable). Still, awesome work!


Does it work under OS 3.1?
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: mdr1 on June 26, 2014, 05:48:34 am
I get the following:

Quote
Sys Error:
W_LoadWadFile: couldn't load gfx.wad

And then I have to reset. I followed your instructions.

Nota: I've got a TI-Nspire CX CAS with ndless 3.1.
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: rwill on June 26, 2014, 09:06:19 am
Vogtinator: The assembler file is missing the following comment because I am not quite done yet:

@ Division routines are implemented with using the book
@ "ARM System Developer's Guide: Designing and Optimizing System Software"
@ by Andrew N. Sloss, Dominic Symes, Chris Wright
@ as a reference.
@ I am not good at math :(

The division routine is called _incorrect because I removed the error correction of the quotient and remainder at some point but added them back later because of.. issues. So it is actually providing correct results. If you are interested in the mathematical proof and more ARM optimizing shizzle I strongly recommend the book. Speedup is significant if you have to do a division every 8 pixels.

DJ Omnimaga: I do not know if it runs on 3.1. My emulator setup is 3.1 and my calc is 3.6 and it runs in/on both.

mdr1: Quake cannot find the pak0.pak(.tns) in the /quake/id1/ folder. Are you sure its there ? I identified the reason you had to reset instead of just having to press a key so thank you for your feedback :)

Title: Re: So I am porting that first person shooter to the Nspire...
Post by: mdr1 on June 26, 2014, 11:37:04 am
I have a folder containing both pak0.pak and nquake (not only).
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: rwill on June 27, 2014, 03:38:26 am
mdr1: Well it should look something like in the attached picture:


Title: Re: So I am porting that first person shooter to the Nspire...
Post by: TIfanx1999 on June 27, 2014, 08:00:46 am
Geezus, I didn't realize this was Quake. I kind of missed this topic since the title is really vague(I was also viewing it on my phone and the picture did not show up). This is fantastic! I can't believe how fast it runs in the video. I also didn't realize that quake could run at that low of a resolution. Anyhow, amazing job!!!
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: rwill on June 27, 2014, 12:30:46 pm
New build. I fixed the system error message so you can exit graceful by keypress instead of having to reset. I also changed the keypad read routine for the touchpad which gave some speedup. I also added more keys for interpretation.

I also noticed that I never explained the key bindings. For the game you can bind any key nQuake understands. You can set these through the menus..
ESC opens the menu which you can navigate with the arrow keys. Enter goes to a sub-menu and ESC returns from it. In the sub-menu Options is "customize controls", if you select that you can remap all in game actions to different keys. nQuake currently understands the following keys:
Arrow Keys, A-Z, 0-9, SPACE, TAB, CTRL, SHIFT, SPACE, +/-/=, TRIG, ^, X^2, e^x, 10^x, (), .

The Quake console is bound to the "?!" key. There you can type commands like "map start" or "timedemo demo1" and other stuff from the 90s.

I included the Windows Visual Studio solution this time because its where I do development so it kind of belongs in the package.
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: ExtendeD on June 30, 2014, 04:17:38 pm
Welcome on Omnimaga rwill, keep up the good work :)
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: DJ Omnimaga on June 30, 2014, 04:37:33 pm
Geezus, I didn't realize this was Quake. I kind of missed this topic since the title is really vague(I was also viewing it on my phone and the picture did not show up). This is fantastic! I can't believe how fast it runs in the video. I also didn't realize that quake could run at that low of a resolution. Anyhow, amazing job!!!
To be honest I'M not surprised, because Unreal Tournament GOTY came out 3 years after Quake, yet it supported resolutions as low as 320x200, which is smaller than calcs. :P

Geezus
At first I thought Drak (http://www.omnimaga.org/profile/Drak/) (NSFW) was back on Omni O.O
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: Adriweb on June 30, 2014, 05:22:17 pm
I included the Windows Visual Studio solution this time because its where I do development so it kind of belongs in the package.

Ha, pretty cool ! And nice job again in general :P

Just for fun, I ran PVS-Studio (static analyzer) on it :
33 level 1 warnings, 16 level 2, 379 level 3... Quake 1 source is fun .... :P

Examples:
Spoiler For Spoiler:
V583 The '?:' operator, regardless of its conditional expression, always returns one and the same value: m + 8. sbar.c 418
Code: [Select]
int Sbar_ColorForMap (int m)
{
return m < 128 ? m + 8 : m + 8;
}

V570 The 'r_drawsurf.surfwidth' variable is assigned to itself. d_surf.c 302
Code: [Select]
if( r_drawsurf.surfwidth & 3 )
{
r_drawsurf.surfwidth = r_drawsurf.surfwidth;
}

V501 There are identical sub-expressions to the left and to the right of the '-' operator: (byte *) sv.edicts - (byte *) sv.edicts pr_cmds.c 634
(http://i.imgur.com/1Buhpz1.png)

V523 The 'then' statement is equivalent to the 'else' statement. cl_input.c 190
Code: [Select]
if (impulseup && !impulsedown)
if (down)
val = 0; // I_Error ();
else
val = 0; // released this frame


V673 The '2000 << 24' expression evaluates to 33554432000. 35 bits are required to store the value, but the expression evaluates to the 'int' type which can only hold '32' bits. r_edge.c 700
I lol'd at this one :
Code: [Select]
// FIXME: do we need this now that we clamp x in r_draw.c?
edge_sentinel.u = 2000 << 24; // make sure nothing sorts past this
edge_sentinel.prev = &edge_aftertail;

Title: Re: So I am porting that first person shooter to the Nspire...
Post by: rwill on July 04, 2014, 03:55:11 am
So I did some more optimizations and submitted it to ticalc.org as I was able to play through the first episode without noticing anything wrong.

ExtendeD: A problem I noticed with Ndless 3.1 in the emulator is that the stack was not aligned to 8 bytes upon entry of main() which leads to failure of functions taking 8 byte datatypes. ARM EABI requires the stack to be aligned to 8 byte. I worked around that by aligning the stack myself so printf and the likes work. This could be related to http://www.omnimaga.org/calculator-c-language/nspire-printf-syscall-is-not-ansi-compliant/ (http://www.omnimaga.org/calculator-c-language/nspire-printf-syscall-is-not-ansi-compliant/) as I got the same symptoms. I have not tested with Ndless 3.6 or on the real HW.
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: DJ Omnimaga on July 04, 2014, 01:55:26 pm
Make sure to e-mail ticalc so they notice the game, because this is definitively something newsworthy.
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: ExtendeD on July 05, 2014, 05:57:47 am
rwill : thanks, I think Vogtinator's SDK fork ( https://github.com/Vogtinator/Ndless/ ) fixed this. It should hopefully be merged back soon.
Title: Re: So I am porting that first person shooter to the Nspire...
Post by: mdr1 on July 07, 2014, 10:31:30 am
rwill : could you make it not mandatory to put the file in the folder "id1"? The duration of opening "My documents" inscreases with the number of folders.

(Moreover, I can't put files in a subfolder currently, so I can't play to the game)
Title: Re: So I am porting Quake to the Nspire...
Post by: rwill on July 12, 2014, 06:18:09 am
rwill : could you make it not mandatory to put the file in the folder "id1"? The duration of opening "My documents" inscreases with the number of folders.

(Moreover, I can't put files in a subfolder currently, so I can't play to the game)

I am sorry, I was not aware of the problems Non-Windows users are faced with when uploading files to the Nspire.

So I attached a new Release Candidate to this post that lets you specify command-line options. Please see the included readme.txt for instructions on how to change the game directory from "id1" to "".
Title: Re: So I am porting Quake to the Nspire...
Post by: mdr1 on July 12, 2014, 01:38:38 pm
Thanks rwill! Unfortunately, the quotation marks seem impossible to write in the console.

EDIT: Nevermind, it works now without entering any command!
EDIT2: I suggest to enable the touchpad so that the user doesn't have to click, juste as in nDoom. And scratchpad/doc for move on the right and on the left instead of the decimal point? And an other key than the space to jump.
Title: Re: So I am porting Quake to the Nspire...
Post by: rwill on July 12, 2014, 02:23:36 pm
Thanks rwill! Unfortunately, the quotation marks seem impossible to write in the console.

EDIT: Nevermind, it works now without entering any command!
EDIT2: I suggest to enable the touchpad so that the user doesn't have to click, juste as in nDoom. And scratchpad/doc for move on the right and on the left instead of the decimal point? And an other key than the space to jump.

Uh... now you have to explain to me which console you tried to type the quotation marks into.. because I intended to have nquake.cmd.tns to be constructed on the host PC with a text editor ( without a newline at the end of the command line, thats missing from the readme.txt ) and then just uploaded to the calc. Remember I am a Nspire newbie.

Regarding the touchpad, for me it is a pain to play nDoom without mechanical feedback ( the click of the arrow keys ). Like I barely touch anything and the player begins to move.. I do not like that at all. I will add the scratchpad/doc keys for keypress evalutation though.
Title: Re: So I am porting Quake to the Nspire...
Post by: Hayleia on July 12, 2014, 02:29:34 pm
Regarding the touchpad, for me it is a pain to play nDoom without mechanical feedback ( the click of the arrow keys ). Like I barely touch anything and the player begins to move.. I do not like that at all. I will add the scratchpad/doc keys for keypress evalutation though.
I agree that the touchpad is awful. Keys (like on Clickpads) are a lot better. However, we have that touchpad on CXes, and what's worse than a touchpad in my opinion is a touchpad where we have to click because then we are tempted to use it as keys, put two fingers on it and then when we press, the touchpad doesn't know where we press. That's why I agree with your point on keys, but I agree with mdr1's point with the touchpad.
At worst, can't you make that an option somewhere ? Let the user choose if clicking is needed or not ?
Title: Re: So I am porting Quake to the Nspire...
Post by: DJ Omnimaga on July 13, 2014, 11:45:47 am
Regarding the touchpad, for me it is a pain to play nDoom without mechanical feedback ( the click of the arrow keys ). Like I barely touch anything and the player begins to move.. I do not like that at all. I will add the scratchpad/doc keys for keypress evalutation though.
I agree that the touchpad is awful. Keys (like on Clickpads) are a lot better. However, we have that touchpad on CXes, and what's worse than a touchpad in my opinion is a touchpad where we have to click because then we are tempted to use it as keys, put two fingers on it and then when we press, the touchpad doesn't know where we press. That's why I agree with your point on keys, but I agree with mdr1's point with the touchpad.
At worst, can't you make that an option somewhere ? Let the user choose if clicking is needed or not ?
Yeah I hate this when I start pressing the touchpad in the right direction to move right, only to end up moving left instead because I had another finger on the left side. I always prefered the Clickpad Nspires except the horrible screen and the fact the calc is almost as large as a boat.
Title: Re: So I am porting Quake to the Nspire...
Post by: Streetwalrus on July 13, 2014, 07:35:13 pm
The calc is almost as large as a boat.
I died. XD
Title: Re: So I am porting Quake to the Nspire...
Post by: Vsod99 on August 19, 2014, 01:51:05 am
Sweet, now all we need is half-life! Also, if you are using a paid version of quake, you will also need to put your gfx.wad file in the id1 directory.