Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => HP Prime => Topic started by: DJ Omnimaga on August 07, 2013, 04:20:39 pm

Title: [HP Prime] Tunnel update! (now running at 90 FPS!)
Post by: DJ Omnimaga on August 07, 2013, 04:20:39 pm
I saw a mandelbrot program a while ago somewhere that is from an HP Prime BASIC program, which left the impression that we could use colors inside programs. However, I haven't figured out how to do it because the manual doesn't explain how, other than the four shades of gray

TEXTOUT_P(text [ ,G], x, y [ ,font, c1, width, c2])

c1 is basically the text color. However, no matter the colors I choose, the text and background stays black and to not have a backgroud I have to not specify c2. Am I doing something wrong or is it a newly introduced bug that wasn't in the version used for the mandelbrot program? ???

P.S: An HP forum section would be nice.
Title: Re: [HP Prime] Help using color in programs (other than grayscale)
Post by: bb010g on August 07, 2013, 04:26:19 pm
You can give a RGB[A] value to drawing functions. For example, you can do this for a colored hello world:
Code: [Select]
EXPORT hello_world()
BEGIN
RECT();
TEXTOUT_P("Hello World!",50,50,0,RGB(0,136,204));
FREEZE;
END;
The commands have changed. Look through the help while in the editor. It's amazing.
Title: Re: [HP Prime] Help using color in programs (other than grayscale)
Post by: Eiyeron on August 07, 2013, 04:32:32 pm
bb010g wrap tour code with [ code][ /code] ;)

Code: [Select]
EXPORT hello_world()
BEGIN
RECT();
TEXTOUT_P("Hello World!",50,50,0,RGB(0,136,204));
FREEZE;
END;
Title: Re: [HP Prime] Help using color in programs (other than grayscale)
Post by: DJ Omnimaga on August 07, 2013, 04:35:01 pm
Wait do you mean there's on-calc help? O.O I was actually checking the PDF file at C:\Program Files (x86)\Hewlett-Packard\HP Prime Virtual Calculator\User_Guide_EN.pdf lol. Thanks btw. :)

I guess it might be a good idea to notify HP about the misleading HP Prime manual in the emulator folder, in case they release it as it is when the calc comes out and some people decide to use it. Maybe they just replaced 39gII screenshots with Prime ones without bothering about changing the rest. The scary part is that this is supposedly the official emulator release, so I hope that the calc won't come with that version of the PDF.

Anyway that works now, thanks :D (changed the code a little bit)
Title: Re: [HP Prime] Help using color in programs (other than grayscale)
Post by: TIfanx1999 on August 07, 2013, 04:38:21 pm
Cool! Nice to see color text working. :)
Title: Re: [HP Prime] Help using color in programs (other than grayscale)
Post by: DJ Omnimaga on August 07, 2013, 06:07:50 pm
Yeah I was worried for a second there. I am still a little annoyed at the width command, though, since it can make it annoying to display long text. However I guess you just have to set the width very high (such as 320 px) and it solves your issues.

What intrigues me are the binary stuff I saw somewhere, because I am curious if we can actually store data in hex or bin then re-use it later for multiple purposes (such as displaying plenty of little pixels or squares to form a sprite/image), rather than having to store our data in a list or something (which are large)?

EDIT: Here's a little test with rectangles, although the emulator runs about 9E999 times faster than the calc, so I had to add extra slowdowns so we can see something. At the end of the screenshot, after modifying some values, the various rectangles display at various locations.

Assuming that the calc display is the same speed as the 39gII or a bit faster, then using rectangles for graphics will most likely rival Nspire Lua speed to a certain extent.

Now to find an efficient way to display Mario...
Title: Re: [HP Prime] Color Tunnel clone (formerly color usage help thread)
Post by: DJ Omnimaga on August 08, 2013, 01:36:01 am
UPDATE: My Tunnel 39gII game has been ported to the HP Prime, but first, I need someone who got the actual calculator (not the emulator) to try the code or the program on their calc, to see if it's too slow or too fast and tell me. Maybe make a video if you can so it is easier for me to help you adjust the speed. :P

Spoiler For "Entire Code":
Quote
EXPORTTunnel()
BEGIN
1->C;
0->P;
100->Y;
20->T;
128->L;
0->L1(512);
FOR Z FROM 0 TO 16 DO
INT(RANDOM(100))->L1(2*Z+1);
60-INT(RANDOM(4))->L1(2*Z+2);
END;
RECT_P(0,0,319,219,RGB(30,100,255),RGB(30,100,255));
RECT_P(0,35,319,219,RGB(0,100,0),RGB(0,100,0));
FOR Z FROM 0 TO 10 DO
TEXTOUT_P("Score:",Z,0,7,RGB(15*Z+100,155-(10*Z),0),250);
TEXTOUT_P("Tunnel Prime",122+Z,0,7,RGB(255-(18*Z),10*Z+99,0),250);
END;
FOR Z FROM 0 TO 4 DO
LINE_P(0,Z+35,319,Z+35,RGB(0,20*Z,0));
END;
WHILE Y>0 DO
FOR Z FROM 0 TO 15 DO
FOR U FROM 0 TO 19999 DO
END;
C+1->C;
IF C>16 THEN
1->C;
END;
L1(2*C+2)->O;
L1(2*C+1)->Q;
RECT_P(20*Z,40,20*Z+19,O,RGB(0,50+Q,0),RGB(0,50+Q,0));
RECT_P(20*Z,O,20*Z+19,O+L,RGB(100+Q,130,50),RGB(100+Q,130,50));
RECT_P(20*Z,O+L,20*Z+19,246,RGB(0,50+Q,0),RGB(0,50+Q,0));
IF Z=0 THEN
RECT_P(0,Y,8,Y+12,RGB(0,0,0),RGB(150,150,255));
RECT_P(2,Y+4,14,Y+8,RGB(0,0,0),RGB(255,0,0));
IF Y<O OR Y+12>O+L THEN
-9->Y;
END;
END;
END;
TEXTOUT_P(P,70,2,6,RGB(0,0,0),200,RGB(50,100,255));
TEXTOUT_P(P,72,2,6,RGB(5,255,255));
P+1->P;
L1(2*C+2)->S;
INT(RANDOM(100))->U;
S+INT(RANDOM(30)-15)->Ans;
IF Ans<45 THEN
45->Ans;
ELSE
IF Ans>213-L THEN
213-L->Ans;
END;
END;
C+1->C;
IF C>16 THEN
1->C;
L-1->L;
END;
Ans->L1(2*C+2);
U->L1(2*C+1);
Y-(5*ISKEYDOWN(2))+(5*ISKEYDOWN(12))->Y;
END;
FOR Z FROM 0 TO 5 DO
INVERT();
FOR Y FROM 0 TO 999 DO
END;
END;
RECT_P(0,15,256,126,0,0);
MSGBOX("SCORE:"+P,1);
END;

In the code, you'll see the following:

Code: [Select]
FOR U FROM 0 TO 19999 DO
END;

Just change the 19999 to something smaller or remove it completely to speed up the program.

Screenshot and download below. If you got the HP Prime emulator, close it, then copy the hpprgm file in C:\Users\DJOmnimaga\AppData\Roaming\HP_Prime or whatever is your application data directory.
Title: Re: [HP Prime] Color Tunnel clone (formerly color usage help thread)
Post by: critor on August 08, 2013, 02:10:33 pm
Just tested DJ_O's tunnel on the HP-Prime DVT prototype, with the wait-loop removed.

It's faster than flashes! :P


Prepare to include lots of wait-loops in your programs :P
Title: Re: [HP Prime] Color Tunnel clone (formerly color usage help thread)
Post by: Streetwalrus on August 08, 2013, 02:19:58 pm
OMG that is fast. *.*/me wants this calc NAOWZ
Title: Re: [HP Prime] Color Tunnel clone (formerly color usage help thread)
Post by: TIfanx1999 on August 08, 2013, 05:29:44 pm
Wow, that's fantastic! I think I like it without the wait loops. That's like around the speed of ASM tunnel games on the z80 series. :D
Title: Re: Re: [HP Prime] Color Tunnel clone (formerly color usage help thread)
Post by: DJ Omnimaga on August 08, 2013, 05:43:19 pm
Yeah I was shocked at how fast it ran. This means even better looking graphics could be used in games. :D

Thanks for the vid critor btw :)

Also although the game is fast, it seems more fun to play since the tunnel started really large, so you won't die within the first picosecond of gameplay.
Title: Re: [HP Prime] Color Tunnel clone (formerly color usage help thread)
Post by: Sorunome on August 08, 2013, 05:47:59 pm
This thing is faster than light. Now add assembly suport and give it to xeda and we will rule the world.
Title: Re: [HP Prime] Color Tunnel clone (formerly color usage help thread)
Post by: DJ Omnimaga on August 08, 2013, 06:00:37 pm
Lol if ASM support is added, I bet that we'll have a Nintendo 64 emulator or something. I would like some exclusives, though, because the Nspire got emulators early and this pretty much killed the Nspire dev scene (since people saw no point in making new games when hundreds were already available). Still, ASM would be cool, though.

Also here's a smaller screenshot that runs at the real calc speed:
Title: Re: [HP Prime] Color Tunnel clone (formerly color usage help thread)
Post by: timwessman on August 08, 2013, 06:12:15 pm
Prepare to include lots of wait-loops in your programs :P

Just an FYI - you can just put WAIT(<sec_value>) and wait for specified second value.

The commands have changed. Look through the help while in the editor. It's amazing.

Thanks! I really hoped it would be useful. You basically have about 30% of the 600+ page manual in there I estimate. The goal was that anywhere you are, pressing HELP would bring up useful stuff.

TW

TW
Title: Re: [HP Prime] Color Tunnel clone (formerly color usage help thread)
Post by: TIfanx1999 on August 08, 2013, 06:21:19 pm
Hey timwessman, welcome to Omnimaga. If you have a quick thought to add, please use the "modify" button rather than add another post.
Title: Re: Re: [HP Prime] Color Tunnel clone (formerly color usage help thread)
Post by: DJ Omnimaga on August 08, 2013, 06:29:33 pm
Heya welcome here :). Nice to hear about the wait command. I wondered if there was one, since it could be handy to ensure our programs run at the right speed in both the emu (assuming the emulator clock is accurate) and the calc.

I should calculate in my program how many rectangles are shown every second approximately, to see if a pseudo 3D racing game like Outrun or Lotus Turbo Challenge would be possible.

EDIT: Also an update: I changed the text color a bit, fixed one minor color issue with the score and am now gonna release the game in the archives!

EDIT 2: Done! http://www.omnimaga.org/index.php?action=downloads;sa=view;down=859
Title: Re: [HP Prime] Color Tunnel clone (formerly color usage help thread)
Post by: DJ Omnimaga on August 12, 2013, 04:16:22 am
Another update:

The game speed is slowed down a little bit but now gameplay should almost run at the same speed as the real calc because I added WAIT commands.

I also got rid of the msgbox at the end and just display a zoomed-in, shaky copy of the score. The msgbox kept crashing the emu. There is also an intro animation at the start but I would need critor to see if it runs fast enough on-calc.
Title: Re: [HP Prime] Color Tunnel clone (formerly color usage help thread)
Post by: DJ Omnimaga on September 13, 2013, 01:00:18 am
This is a new version, although it doesn't add anything other than a copyright. Since HP distributed the game in source code in a PDF with at least one prototype (and an outdated version of the game which ran at 2 FPS on calc due to me forgetting to remove the FOR U FROM 0 TO 19999 DO line lol), I added a small copyright to the game so people don't think HP made the game or something lol.

There might be future updates, though, such as switching to DIMGROB and BLIT to scroll the screen. It will depend if it's faster than the current method.
Title: Re: [HP Prime] Color Tunnel clone (formerly color usage help thread)
Post by: TIfanx1999 on September 16, 2013, 05:37:23 pm
Maybe you could contact Tim Wessman(and point him to the updated version) and let him know. Perhaps he can pass it on to the proper people. I saw in the Cemetech topic that your game was included. I was a bit surprised that they just tossed it in there(in the pdf). It is pretty neat that they did though. :D
Title: Re: Re: [HP Prime] Color Tunnel clone (formerly color usage help thread)
Post by: DJ Omnimaga on September 17, 2013, 12:52:52 am
Yeah I Did that actually this weekend. Not sure if he got the 3-mail since in the past I had issues with Critor not receiving my e-mails (from my main address), but yeah the fact that one game was included shows that they are open to such development and wanted to show what could be done.
Title: Re: [HP Prime] Color Tunnel clone (formerly color usage help thread)
Post by: DJ Omnimaga on October 19, 2013, 01:09:06 am
Ok so some updates!

I managed to solve the issue with the intro transition only displaying partially or not at all and I also finally moved everything from G0 to G1, so that I can update the entire screen content at once via BLIT. The max speed dropped from the totally unplayable 60+ FPS to something slightly above 50 FPS, but there's less tearing and there's no more flicker.

The next step will be to attempt getting rid of the For loop used to generate the road every frame and instead shift the screen around and only redraw the missing part of the road. To avoid copying the entire screen content twice, I might make G1 a bit larger in width. However, I will most likely go back to not updating the entire screen at once because I currently redraw the entire HUD every frame, which isn't efficient. In the future, the score will be once again be displayed directly to G0.
Title: Re: [HP Prime] Tunnel update! (now implementing BLIT for more smoothness)
Post by: DJ Omnimaga on December 03, 2013, 11:01:58 pm
Ok so my attempt a while ago to switch to DIMGROB was futile, but I found out that I was using INT in this game too, which is not the integer command we all think of. I got rid of them and now guess what: The game runs around 90 FPS on a real calc instead of 60! *.*
Title: Re: [HP Prime] Tunnel update! (now running at 90 FPS!)
Post by: TIfanx1999 on December 04, 2013, 12:23:25 am
Wow, that's awesome DJ! :D
Title: Re: [HP Prime] Tunnel update! (now running at 90 FPS!)
Post by: Streetwalrus on December 06, 2013, 01:19:16 pm
Holy crap that's epic. O.O This calc keeps impressing me.
Title: Re: [HP Prime] Tunnel update! (now running at 90 FPS!)
Post by: DJ Omnimaga on December 06, 2013, 03:38:14 pm
Thanks, and I can't imagine what can be done with the new polygon feature now, especially that it has alpha transparency support.
Title: Re: [HP Prime] Tunnel update! (now running at 90 FPS!)
Post by: Streetwalrus on December 09, 2013, 01:00:19 pm
Yeah when TIm Wessman anounced it I knew that it'd be epic.