Author Topic: HP Programming help  (Read 7628 times)

0 Members and 1 Guest are viewing this topic.

alexgt

• Just your friendly neighborhood Ninja Stach Fancy Iron Man
• Super User
• Join Date: Dec 2014
• Location: Behind you
• Posts: 2615
• Post Rating Ratio: +6/-1
• Something should go here...
• Gender:
HP Programming help
« on: April 18, 2015, 04:57:44 pm »
Hello, I am making a game that you all know called Minecraft on my Prime and I need help with sprites! Also the way I move in the world is by drawing blocks from values in a matrix so every time I move I have to redraw the entire screen and that takes time so I was wondering if there is any way to copy part of the screen and paste it at another part so I would just have to fill in one part, or even if there is a way to shift the screen over at all like the horizontal+ command in Axe?

Thanks for the help in advance
« Last Edit: April 18, 2015, 05:37:30 pm by alexgt »

• Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

xlibman

• Omni founder & CW co-founder
• CodeWalrus Staff
• Super User
• Forum Maintenance
• Original 5
• CodeWalrus Supporter
• Join Date: Nov 2014
• Posts: 19013
• Post Rating Ratio: +100/-5
• Gender:
Re: HP Programming help
« Reply #1 on: April 20, 2015, 07:37:07 pm »
In order to use sprites you need to use the DIMGROB_P and BLIT_P commands. DIMGROB_P creates a graphical buffer of any size you want (keep them small to avoid stability issues, though) where you can store sprite data or a blank picture with a background color of your choice. There are 10 available (G0 to G9), G0 being the screen itself. Then you use BLIT_P to display one part of a buffer of your choice onto another. Typical use is to create a GROB for your sprite data and a 320x240 GROB to draw your tilemap and sprites, then once you are done, copying the result on G0.

It's also possible to store graphical data outside GROB's by using ICON format, which is much smaller than DIMGROB format.

To generate the sprite data you must use http://h30499.www3.hp.com/t5/Calculators/HP-Prime-Help-Entry-ICON-Setting-App-Icons/td-p/6298613#.VTVQt6bfJ8F .

Walrii sprite data with a light blue background would look like this:

Code: [Select]
`ICON name 89504E470D0A1A0A0000000D49484452000000180000003008030000003C564A91000000ED504C5445A6DCFF030303EEF0F1F6F6F6FAFAFAEAEAEBEDEFF1E3E5E7E7E7E7FFFFFFF3F4F6DCDEE13394E83191DFF2F4F60357FF0453F02986D79A9B9D2E8FE3EEEEEEAFAFAFAAADAE9B9E9F777A7E044FE3044CDB3193E8E4E4E48080808B8B8BB1B1B17B7B7B74767A6A6F7A0449D2D6D9DA7E7E7E868686A7A8A96D6D6D737373ADADADCACACA7A7A7A7F7F7FE8E8E8DFDFDFF0F0F0F8F8F8D7D7D7A8A8A8E3E3E3828282848484CECECEB7B7B7A8AAAC8989897D7D7DC3C3C5A2A2A2939393C5C5C5BEBEBEAAAAAA8383837171717676767878789E9E9E6E7071666768A7A7A76E6E6E787B7C71747776787A9B9B9B4FDB67010000004F74524E53000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002903720E0000017D494441547801EDD2DD56DA401440617680DA5414B5C5FA5386515BDA5423481BC02015249452D4F77F1CCF844948A4BDF3D259CB9BF391332B6617E20314FE75708A0E85759479A954C6719E09E537B0C15BD77D971736A96CC92DDBAEEBE4D641A5BAC36E45A4C85E46E0BDC04EB542F103B5FD54F878C0E11187D5633E51578D15E8FA099C72C667BE3495FA6A05BEE169AD05E3B9FA9EC0B94C2E3CB4AF7D3357B5042E5BB169951CBB8B769BCBAB4E067EACA0EDB633E093AECA83B6D08196FB13BF19C4772BD5B5D0939B5B5C049A6069FD6B2C983F1DA0C390819146FCAFE4469E1030BFEED7449A5D355C0ABFB8B5578CC6F83EDDE53BC2F88E4914C94366CB54335DBE23BFD56026EBFEE0F9A19AF377C642DF8BE02DEC4A78A83F9A604806996FF69F8ED6C37A0D2EDBD5CB07B7DE950DCE74C55A572DD355188A998D8D04E2AEA8F5956CD3D215C3F893F7181B1C8F948064B5EA4DB2BA8586CC355134CDF43680C95C85BE8700696F9295E863FDC11645D25B5A5BBE9927223B45CB11B69EBA0000000049454E44AE426082;`
This is stored at the very end of the code, outside any sub-routine/main block, after the last END.

If I wanted, for example, to display frame 1 at 2x zoom on the LCD in the top-left corner, I would need to use BLIT_P(G0,0,0,48,48,"name",0,0,24,24) . Frame 2 would be BLIT_P(G0,0,0,48,48,"name",0,24,24,48) .

BLIT_P(G0,0,0,48,48,"name",0,24,24,48,#A6DCFF) would make the light blue color transparent.

With BLIT and multiple GROBs you can also copy stuff around to do special effects including what you want to do, although I never tried shifting the screen using BLIT. But the most notable feature of BLIT is the ability to display graphical data of any size from anywhere inside a buffer and scale it up or down (although scaling is slow)

The following code:

Code: [Select]
`EXPORT Walrii()BEGINFOR Z FROM 1 TO 320 DOBLIT_P(G0,0,0,Z,Z,"name",0,0,24,24,#A6DCFF);WAIT(.016);END;END;ICON name 89504E470D0A1A0A0000000D49484452000000180000003008030000003C564A91000000ED504C5445A6DCFF030303EEF0F1F6F6F6FAFAFAEAEAEBEDEFF1E3E5E7E7E7E7FFFFFFF3F4F6DCDEE13394E83191DFF2F4F60357FF0453F02986D79A9B9D2E8FE3EEEEEEAFAFAFAAADAE9B9E9F777A7E044FE3044CDB3193E8E4E4E48080808B8B8BB1B1B17B7B7B74767A6A6F7A0449D2D6D9DA7E7E7E868686A7A8A96D6D6D737373ADADADCACACA7A7A7A7F7F7FE8E8E8DFDFDFF0F0F0F8F8F8D7D7D7A8A8A8E3E3E3828282848484CECECEB7B7B7A8AAAC8989897D7D7DC3C3C5A2A2A2939393C5C5C5BEBEBEAAAAAA8383837171717676767878789E9E9E6E7071666768A7A7A76E6E6E787B7C71747776787A9B9B9B4FDB67010000004F74524E53000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002903720E0000017D494441547801EDD2DD56DA401440617680DA5414B5C5FA5386515BDA5423481BC02015249452D4F77F1CCF844948A4BDF3D259CB9BF391332B6617E20314FE75708A0E85759479A954C6719E09E537B0C15BD77D971736A96CC92DDBAEEBE4D641A5BAC36E45A4C85E46E0BDC04EB542F103B5FD54F878C0E11187D5633E51578D15E8FA099C72C667BE3495FA6A05BEE169AD05E3B9FA9EC0B94C2E3CB4AF7D3357B5042E5BB169951CBB8B769BCBAB4E067EACA0EDB633E093AECA83B6D08196FB13BF19C4772BD5B5D0939B5B5C049A6069FD6B2C983F1DA0C390819146FCAFE4469E1030BFEED7449A5D355C0ABFB8B5578CC6F83EDDE53BC2F88E4914C94366CB54335DBE23BFD56026EBFEE0F9A19AF377C642DF8BE02DEC4A78A83F9A604806996FF69F8ED6C37A0D2EDBD5CB07B7DE950DCE74C55A572DD355188A998D8D04E2AEA8F5956CD3D215C3F893F7181B1C8F948064B5EA4DB2BA8586CC355134CDF43680C95C85BE8700696F9295E863FDC11645D25B5A5BBE9927223B45CB11B69EBA0000000049454E44AE426082;`
Would give this result:

I hope this helps!
• Calculators owned: TI-84 Plus C Silver Edition, TI-84 Plus CE, Casio fx-CG10
• Consoles, mobile devices and vintage computers owned: Samsung i5510, Nintendo Switch, Playstation TV

alexgt

• Just your friendly neighborhood Ninja Stach Fancy Iron Man
• Super User
• Join Date: Dec 2014
• Location: Behind you
• Posts: 2615
• Post Rating Ratio: +6/-1
• Something should go here...
• Gender:
Re: HP Programming help
« Reply #2 on: April 20, 2015, 07:58:40 pm »
Thank you very much after I posted that I tinkered around with that and found out most of the stuff you told me! NVM the stuff about copying the screen because now I have two GROBS that I draw the entire world to and then just shift them around the screen (I can speed the camera movements up so much you pretty much teleport!). The GROB's size did give me problems at first but I found that you can just make their dimensions 0x0 and then I boost it up to 1600x800 each and it works all the time now! I also saw the ICON page when I was looking for info but I did not scroll down before to see the download for the program thank you very much for that .

Thanks for the help (that Walrii looks good lol)
• Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

xlibman

• Omni founder & CW co-founder
• CodeWalrus Staff
• Super User
• Forum Maintenance
• Original 5
• CodeWalrus Supporter
• Join Date: Nov 2014
• Posts: 19013
• Post Rating Ratio: +100/-5
• Gender:
Re: HP Programming help
« Reply #3 on: April 20, 2015, 08:09:09 pm »
If I was you I would avoid 1600x800 GROBs. For some reasons once you run many programs parts of large GROBs will not show up. I think it's a memory leak or garbage collecting issue on the HP Prime firmware. I generally keep them around 640x240 or stuff like that maximum. You can always use larger ones, but backup often so you can revert back to an older version using smaller GROBs if you run into major fatal problem.
• Calculators owned: TI-84 Plus C Silver Edition, TI-84 Plus CE, Casio fx-CG10
• Consoles, mobile devices and vintage computers owned: Samsung i5510, Nintendo Switch, Playstation TV

alexgt

• Just your friendly neighborhood Ninja Stach Fancy Iron Man
• Super User
• Join Date: Dec 2014
• Location: Behind you
• Posts: 2615
• Post Rating Ratio: +6/-1
• Something should go here...
• Gender:
Re: HP Programming help
« Reply #4 on: April 20, 2015, 08:38:01 pm »
Yeah, that happened for me when I did not set them to 0x0 before but now it runs fine what was happening is that it would not fit the correct dimensions. If it was at 400x400 it would stay that way but now it seems that doing
Code: [Select]
`DIMGROB(G1,0,0);DIMGROB(G2,0,0);DIMGROB(G1,1600,800);DIMGROB(G2,1600,800);`But yes I would not go over that limit but I am surprised is has not thrown the "insufficient memory" error for any GROBs because in testing them I put one at 4800x800 although I did not use it in any PRGMs.

the reason that I want to speed it up really fast is that I plan on there being portals and I want an animation to get there!
• Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

xlibman

• Omni founder & CW co-founder
• CodeWalrus Staff
• Super User
• Forum Maintenance
• Original 5
• CodeWalrus Supporter
• Join Date: Nov 2014
• Posts: 19013
• Post Rating Ratio: +100/-5
• Gender:
Re: HP Programming help
« Reply #5 on: April 21, 2015, 06:02:25 am »
Ooh, portals would be a nice addition. By the way, if you ever run into the memory issues or display problems I mentionned above and you know in which order you did stuff that triggered it, feel free to let Tim Wessman know on the forums. I need to do so as well at one point, but I still haven't gotten time to check how exactly to recreate the issue.
• Calculators owned: TI-84 Plus C Silver Edition, TI-84 Plus CE, Casio fx-CG10
• Consoles, mobile devices and vintage computers owned: Samsung i5510, Nintendo Switch, Playstation TV

alexgt

• Just your friendly neighborhood Ninja Stach Fancy Iron Man
• Super User
• Join Date: Dec 2014
• Location: Behind you
• Posts: 2615
• Post Rating Ratio: +6/-1
• Something should go here...
• Gender:
Re: HP Programming help
« Reply #6 on: April 21, 2015, 10:18:41 pm »
My problems come when trying to create a matrix with a size of 400x50. That was when I was trying to add world sized specified by the user so I would have to use two matrices but I was too lazy . So I have no problems at the moment, Thanks though !
• Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

xlibman

• Omni founder & CW co-founder
• CodeWalrus Staff
• Super User
• Forum Maintenance
• Original 5
• CodeWalrus Supporter
• Join Date: Nov 2014
• Posts: 19013
• Post Rating Ratio: +100/-5
• Gender:
Re: HP Programming help
« Reply #7 on: April 21, 2015, 10:29:35 pm »
By the way you can also use images to store map data. Since ICON format has compression, some very simple maps could actually be as small, if not smaller, than their matrix counterpart I think. But then I don't know if pixel test collision is much slower than matrix collision.
• Calculators owned: TI-84 Plus C Silver Edition, TI-84 Plus CE, Casio fx-CG10
• Consoles, mobile devices and vintage computers owned: Samsung i5510, Nintendo Switch, Playstation TV

alexgt

• Just your friendly neighborhood Ninja Stach Fancy Iron Man
• Super User
• Join Date: Dec 2014
• Location: Behind you
• Posts: 2615
• Post Rating Ratio: +6/-1
• Something should go here...
• Gender:
Re: HP Programming help
« Reply #8 on: April 21, 2015, 10:34:38 pm »
Well there is that but I am satisfied with the current world size so I will keep it the same although that is a good idea!
• Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

alexgt

• Just your friendly neighborhood Ninja Stach Fancy Iron Man
• Super User
• Join Date: Dec 2014
• Location: Behind you
• Posts: 2615
• Post Rating Ratio: +6/-1
• Something should go here...
• Gender:
Re: HP Programming help
« Reply #9 on: May 15, 2015, 08:51:14 pm »
Do you guys know if there is any way to make the lock screen appear when you turn on your calc. It is just like a slide thing to get into your phone but it only happened for me when I installed a new firm ware. And I updated just now and it didn't happen.
• Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

xlibman

• Omni founder & CW co-founder
• CodeWalrus Staff
• Super User
• Forum Maintenance
• Original 5
• CodeWalrus Supporter
• Join Date: Nov 2014
• Posts: 19013
• Post Rating Ratio: +100/-5
• Gender:
Re: HP Programming help
« Reply #10 on: May 16, 2015, 06:04:53 pm »
I don't think so. It seems like an intro to the HP Prime screen that appeared only on a firmware update. Many people were confused about what to do on that screen (in my case I just pressed the reset button and was scared that my calc was bricked), since a lock screen on a calculator is not something anybody would expect. I wouldn't be surprised if it was removed due to that.
• Calculators owned: TI-84 Plus C Silver Edition, TI-84 Plus CE, Casio fx-CG10
• Consoles, mobile devices and vintage computers owned: Samsung i5510, Nintendo Switch, Playstation TV

alexgt

• Just your friendly neighborhood Ninja Stach Fancy Iron Man
• Super User
• Join Date: Dec 2014
• Location: Behind you
• Posts: 2615
• Post Rating Ratio: +6/-1
• Something should go here...
• Gender:
Re: HP Programming help
« Reply #11 on: May 16, 2015, 10:22:37 pm »
I just slid it over but it never appeared again .

Also look at the Var > Home > System > and you will find Date, Time, Language, Notes, Programs, TOff, HVars, and DelHVars variables that you can change to make cool stuff happen. I am thinking about a shell, program/note editor, even full blown Jarvis and  mods for MinePrime could be possible. I am looking into it but I need help figuring out if you can run a program in a program, then we could make a fully functional shell and mods for MinePrime
• Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

bb010g

• Full User
• Safe-haven access
• Join Date: Dec 2014
• Location: Seattle, WA
• Posts: 93
• Post Rating Ratio: +1/-1
• I do stuff, I guess
• Gender:
Re: HP Programming help
« Reply #12 on: May 16, 2015, 10:56:52 pm »
I've been playing around with libraries and a launcher for a couple of months. The Prime's sense of scope is weird. However, to build it, I want to put together some libraries, and at the current state, use of them doesn't feel good (to me at least), esp. with list-based datatypes. There's not a "real" object system, just integer-based hand-made slot enum working as the indexes for a list. I want to put some tooling together, kind of like Source, but starting with a base of PPL. That requires building a grammar, usable documentation of commands, and me actually sitting down and working out the AST. From there my language would consist of a similar grammar that can be reduced via AST to PPL and converted back, albeit with some loss (e.g. types defaulting to normal values). I don't want to make its output too far off from normal PPL either (see also: Xtend/any Xtext lang–generated Java). Unless I suddenly have a stroke of genius, I'm probably finishing that before my hash & whatever else libraries and a launcher & assorted metadata standard. If you have any ideas on how to structure and use generic libraries without killing the calc under load, please tell.
• Calculators owned: HP 50g, Prime, 28S, 35S, Casio Prizm, dead Nspire CX CAS

alexgt

• Just your friendly neighborhood Ninja Stach Fancy Iron Man
• Super User
• Join Date: Dec 2014
• Location: Behind you
• Posts: 2615
• Post Rating Ratio: +6/-1
• Something should go here...
• Gender:
Re: HP Programming help
« Reply #13 on: May 16, 2015, 11:48:36 pm »
glad to  hear that you are making a library/ new language . any stuff like that would be helpful .

Have you come across any way to run a program within a program?
• Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

xlibman

• Omni founder & CW co-founder
• CodeWalrus Staff
• Super User
• Forum Maintenance
• Original 5
• CodeWalrus Supporter
• Join Date: Nov 2014
• Posts: 19013
• Post Rating Ratio: +100/-5
• Gender:
Re: HP Programming help
« Reply #14 on: May 18, 2015, 04:44:57 pm »
It would definitively be nice to see a new language for the Prime, although since I have an hard time getting used to new languages I will probably stick to HP PPL and xLIBC for the time being.

Also while this is not helpful nor relevant to your last two posts, I feel that this post by Tim Wessman has to be quoted in this thread too, because that's an important bit of info that might be lost  otherwise. It explains how to convert your HP programs into applications and how to create a custom icon, which is now supported in the new firmware:

Whats a GROB btw?

It's been the HP parlance for GRaphic OBject since 1989 or so.

As for the problem for which I was summoned - there are a couple of questions to ask here.

Are you really meaning to create a 1600x800 <unit> sized GROB?

If so, are you remembering that the <unit> size comes from the Cartesian grid of the current application? So if the function app is running and the user has zoomed in by 2x on the graph, your GROB size just doubled which would already cause your memory to run out. My recommendation would be to always use the _P options to specify an exact size else you are left at the mercy of what the user has done to the Cartesian grid. If you really want to use the cartesian grid, you'd better make certain you set the values to the desired setting by using the Xmin/Xmax/Ymin/Ymax. However, those only exists for about half of the apps that have graphing. Better to just pick your correct pixel size.

Are you cleaning up after the exit of the game? By this, I'd recommend clearing out your large graphics by setting them to 0 or 1 pixel in size. Else that memory will stay in use until the user either resets, or stores something else in there.

With the new firmware, I'd recommend switching to an application. That will give you access to permanent variables that aren't lost on editing, as well as files and an icon for your program. My recommendation would be:

1. Save a copy of the Quad Explorer app (this will be very tiny).
2. Make your START routine be to launch the game, as well as the Plot, Symb and Num routines.
3. In the code itself, get rid of all the uses of ICON. On the PC, you will see that the applications are now folders of the form "<name>.hpappdir". Put all your graphic assets into that directory as png files (.png on the name is not necessary for use/loading - we check the header to determine type) and they will be sent along with it when sending from the connkit.
4. Give a 38x38pix item a name of "icon.png". That will be what is used for your application icon.
5. When you want to load your png files, use G2:=AFiles("filename") or similar. I'd avoid using the AFiles(1) as that file order could change! It depends on what the underlying file system does with the files in how it lists them. Then once you have G2, you can use that to create your larger GROB. Going directly from the png decode to the blit will definitely increase load time.
6. If you have data you want to save, AFiles("name"):=G1 will store it out. You might even be able to store the PNG as built to disk. Not certain of that though due to the large sizes that appear to be involved.
7. If you have data you want saved (scores, map info, etc), do a AVars("name"):=<list_or_whatever>. Note that the primary difference between using AFiles or AVars is that AVars will allow you to use the object directly as a variable (tying MyVar for example) while AFiles will not. You have to load to a variable from AFiles before use. AVars will consume RAM when the app is loaded. AFiles will not until they are recalled to a variable.

8. To distribute your new application, just package the "name.hpappdir" in a zip file! People just need to drop that zip on the calc in the connkit and it will send the application. No messing with pasting of source. This is the strucutre we like to use for distributing HP developed apps for teacher use for example:

<ZIP>
|-- appname.hpappdir
|    |-- stuff
|--help.pdf
\--last file

Provided your stuff is not an hp object type (.txt, .pdf, etc) it will not be sent. Anything in the hpappdir WILL be sent as a file, but it will not recursively add things (aka, no nesting of directories in there).

• Calculators owned: TI-84 Plus C Silver Edition, TI-84 Plus CE, Casio fx-CG10
• Consoles, mobile devices and vintage computers owned: Samsung i5510, Nintendo Switch, Playstation TV