Author Topic: Mode 7 engine  (Read 25485 times)

0 Members and 2 Guests are viewing this topic.

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Mode 7 engine
« Reply #15 on: January 09, 2013, 09:50:06 pm »
The whole thing is a bug.

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: Mode 7 engine
« Reply #16 on: January 09, 2013, 10:01:28 pm »
Weird shit happens with rotation.  :P

Also, CalcCapture is acting weird. At the end, you can see that it inserted a picture of itself into a few frames.
It always did that for me. You see CalcCapture at the end in almost all screenshots I made with it (see this screenshot from Early 2004 for example)



It also has poor framerate (although it still does the job I guess). Anyway nice to see more work being done on Mode 7 lately for the Nspire :)

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Mode 7 engine
« Reply #17 on: January 13, 2013, 11:25:22 am »
Which method are you using ? Maybe I can help you :)

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Mode 7 engine
« Reply #18 on: January 22, 2013, 10:36:57 pm »
I suspect the problem is inaccurate trig or more likely fixed point multiplication routines.

I was originally calculating a lookup table for every pixel and then translating the values for each pixel based on the camera position and rotation. Now, I am only doing a lookup table for every row of the screen, and interpolating values within the row, which is actually how the GBA and SNES do it. It also improved the framerate as you can see in the FPS counter.

I still have to add back in rotation. Fortunately, it shouldn't be as much of a performance hit as you saw last time, because all the translation will be done per row, instead of per pixel.

« Last Edit: January 22, 2013, 10:37:15 pm by t0xic_kitt3n »

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: Mode 7 engine
« Reply #19 on: January 24, 2013, 12:29:48 am »
Looks kinda nice. I like how the resolution is maximum :D

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Mode 7 engine
« Reply #20 on: January 25, 2013, 10:43:28 pm »
Well, I've got rotation by a fixed angle working, and it still runs >60FPS at full resolution. (Not that it matters given how slow the response time of the LCD on the actual thing is.) Now to write *accurate* trig functions so I can change the angle dynamically. Also - screen tearing is from the emulator, not the program.
« Last Edit: January 25, 2013, 10:44:55 pm by t0xic_kitt3n »

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: Mode 7 engine
« Reply #21 on: January 25, 2013, 11:58:39 pm »
60 FPS??? I Wonder if it would be as fast on the CX? O.O (without the screen blur and stuff)


What is the speed for bigger maps?
« Last Edit: January 26, 2013, 01:09:28 am by DJ_O »

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Mode 7 engine
« Reply #22 on: January 26, 2013, 12:05:00 am »
If you're measuring 64FPS on the emulator you can be sure it's lower oncalc. The emulator doesn't have very accurate timing, because it executes every instruction in 1 cycle and doesn't emulate memory access delays (not that I'd expect it to).
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: Mode 7 engine
« Reply #23 on: January 26, 2013, 12:35:42 am »
Yeah, real calc is like ~25% the speed of the emulator for me :P
« Last Edit: January 26, 2013, 12:36:10 am by epic7 »

Offline Stefan Bauwens

  • Creator of Myst 89 - סטיבן
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1799
  • Rating: +162/-24
  • 68k programmer
    • View Profile
    • Portfolio
Re: Mode 7 engine
« Reply #24 on: January 26, 2013, 04:00:35 am »
Since I'm getting quite interested in Mode7, I was planning to see how it worked.
I though of a way, that would look a bit like like the screenshots you give: Each "pixel" is shows as a trapezoid, from small(up) to big(down).
However when I look at screenshots of F-zero(68k) for example: http://www.ticalc.org/archives/files/fileinfo/381/38175.html this doesn't look the case.
Is that then a different kind of mode7?


Very proud Ticalc.org POTY winner (2011 68k) with Myst 89!
Very proud TI-Planet.org DBZ winner(2013)

Interview with me

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Mode 7 engine
« Reply #25 on: January 26, 2013, 09:05:59 am »
Looks like it is doing the same thing, but at a lower resolution so you can't see the trapezoid shape.

EDIT: So I'm having trouble running this code that tests my fixed point sine and cosine functions. The input and output are 16.16 fixed point numbers, and there is four units (in fixed point, so it would be an integer 4 << 16) to a rotation.

When I run it, I get this:
Code: [Select]
Error at PC=00000104: Invalid condition code
        Backtrace:
Frame     PrvFrame Self     Return   Start
00000004: invalid address
debug>

This is the actual code, to compile, just put it in main.c and compile with the Ndless SDK. (Or however else you compile Ndless programs).
Code: [Select]
#include <os.h>
#include <nspireio2.h>

#define numToFix(a) (a << 16)
#define floatToFix(a) (int32_t)(a * 65536)

int32_t sin(int32_t a) {
int32_t sine_table[257] =
{0x0000, 0x0192, 0x0324, 0x04B6, 0x0648, 0x07DA, 0x096C, 0x0AFE,
0x0C8F, 0x0E21, 0x0FB2, 0x1144, 0x12D5, 0x1466, 0x15F6, 0x1787,
0x1917, 0x1AA7, 0x1C37, 0x1DC7, 0x1F56, 0x20E5, 0x2273, 0x2402,
0x2590, 0x271D, 0x28AA, 0x2A37, 0x2BC4, 0x2D50, 0x2EDB, 0x3066,
0x31F1, 0x337B, 0x3505, 0x368E, 0x3817, 0x399F, 0x3B26, 0x3CAD,
0x3E33, 0x3FB9, 0x413E, 0x42C3, 0x4447, 0x45CA, 0x474D, 0x48CE,
0x4A50, 0x4BD0, 0x4D50, 0x4ECF, 0x504D, 0x51CA, 0x5347, 0x54C3,
0x563E, 0x57B8, 0x5931, 0x5AAA, 0x5C22, 0x5D98, 0x5F0E, 0x6083,
0x61F7, 0x636A, 0x64DC, 0x664D, 0x67BD, 0x692D, 0x6A9B, 0x6C08,
0x6D74, 0x6EDF, 0x7049, 0x71B1, 0x7319, 0x7480, 0x75E5, 0x774A,
0x78AD, 0x7A0F, 0x7B70, 0x7CD0, 0x7E2E, 0x7F8B, 0x80E7, 0x8242,
0x839C, 0x84F4, 0x864B, 0x87A1, 0x88F5, 0x8A48, 0x8B9A, 0x8CEA,
0x8E39, 0x8F87, 0x90D3, 0x921E, 0x9368, 0x94B0, 0x95F6, 0x973C,
0x987F, 0x99C2, 0x9B02, 0x9C42, 0x9D7F, 0x9EBC, 0x9FF6, 0xA12F,
0xA267, 0xA39D, 0xA4D2, 0xA605, 0xA736, 0xA866, 0xA994, 0xAAC0,
0xABEB, 0xAD14, 0xAE3B, 0xAF61, 0xB085, 0xB1A8, 0xB2C8, 0xB3E7,
0xB504, 0xB620, 0xB73A, 0xB852, 0xB968, 0xBA7C, 0xBB8F, 0xBCA0,
0xBDAE, 0xBEBC, 0xBFC7, 0xC0D0, 0xC1D8, 0xC2DE, 0xC3E2, 0xC4E3,
0xC5E4, 0xC6E2, 0xC7DE, 0xC8D8, 0xC9D1, 0xCAC7, 0xCBBB, 0xCCAE,
0xCD9F, 0xCE8D, 0xCF7A, 0xD064, 0xD14D, 0xD233, 0xD318, 0xD3FA,
0xD4DB, 0xD5B9, 0xD695, 0xD770, 0xD848, 0xD91E, 0xD9F2, 0xDAC4,
0xDB94, 0xDC61, 0xDD2D, 0xDDF6, 0xDEBE, 0xDF83, 0xE046, 0xE106,
0xE1C5, 0xE282, 0xE33C, 0xE3F4, 0xE4AA, 0xE55E, 0xE60F, 0xE6BE,
0xE76B, 0xE816, 0xE8BF, 0xE965, 0xEA09, 0xEAAB, 0xEB4B, 0xEBE8,
0xEC83, 0xED1C, 0xEDB2, 0xEE46, 0xEED8, 0xEF68, 0xEFF5, 0xF080,
0xF109, 0xF18F, 0xF213, 0xF294, 0xF314, 0xF391, 0xF40B, 0xF484,
0xF4FA, 0xF56D, 0xF5DE, 0xF64D, 0xF6BA, 0xF724, 0xF78B, 0xF7F1,
0xF853, 0xF8B4, 0xF912, 0xF96E, 0xF9C7, 0xFA1E, 0xFA73, 0xFAC5,
0xFB14, 0xFB61, 0xFBAC, 0xFBF5, 0xFC3B, 0xFC7E, 0xFCBF, 0xFCFE,
0xFD3A, 0xFD74, 0xFDAB, 0xFDE0, 0xFE13, 0xFE43, 0xFE70, 0xFE9B,
0xFEC4, 0xFEEA, 0xFF0E, 0xFF2F, 0xFF4E, 0xFF6A, 0xFF84, 0xFF9C,
0xFFB1, 0xFFC3, 0xFFD3, 0xFFE1, 0xFFEC, 0xFFF4, 0xFFFB, 0xFFFE, 0x10000};

switch ((a & 0x3000) >> 16) {
case 0:
return sine_table[((a >> 8) & 0xFF)];
case 1:
return sine_table[256 - ((a >> 8) & 0xFF)];
case 2:
return -sine_table[((a >> 8) & 0xFF)];
case 3:
return -sine_table[256 - ((a >> 8) & 0xFF)];
}

}

inline int32_t cos(int32_t a) {
return sin(a + 0x1000);
}

int main(void) {
int n;
for (n = 0; n < 1024; n++) {
uart_printf("\n%4l, %08X, %08X", n, sin(n << 8), cos(n << 8));
}
return 0;
}
« Last Edit: January 26, 2013, 09:31:07 am by t0xic_kitt3n »

Offline lkj

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +58/-1
    • View Profile
Re: Mode 7 engine
« Reply #26 on: January 26, 2013, 12:06:30 pm »
The problem is something with the uart_printf() and not your sin() and cos(). I don't know much about printf specifiers, but %4l doesn't seem to be valid and results in a warning (if you'd use printf instead of uart_printf, obviously).
Why do you use uart_printf and not the normal printf?

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: Mode 7 engine
« Reply #27 on: January 26, 2013, 12:22:42 pm »
The function uart_printf fails.
Your code is correct, replace uart_printf with printf.

Code: [Select]
printf("\n%4l, %08X, %08X", n, sin(n << 8), cos(n << 8));

I have basically no idea what uart_printf does...
« Last Edit: January 26, 2013, 12:23:05 pm by Levak »
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Mode 7 engine
« Reply #28 on: January 26, 2013, 03:15:45 pm »
There's also a bug in this code, (a & 0x3000) >> 16 always gives zero. I think you meant to use 0x30000?
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Mode 7 engine
« Reply #29 on: January 26, 2013, 04:43:21 pm »
uart_printf is in nspireio2.h, and it works fine. I guess it's to differentiate printing to the screen or RS232. I was using that because the regular printf was not working for me for some reason. Anyways, I fixed the bug calc84 pointed out and another one where part of the code thought the angle was stored in a floating point number which I had neglected to change when I switched to the fixed point trig functions and rotation works now :D Tilemapping is next on my list.

EDIT: Tested on the actual calculator (Clickpad Nspire), and it runs at 35fps.

EDIT: Enabling -O3 in gcc increases it to 44fps on the calculator.
« Last Edit: January 26, 2013, 07:01:50 pm by t0xic_kitt3n »