Join us on Discord!
You can help CodeWalrus stay online by donating here.

[HP Prime][HP PPL] Make program run at same speed on both emu & calculator

Started by Dream of Omnimaga, August 28, 2015, 01:44:45 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dream of Omnimaga

I made a small proof of concept routine that lets you make an HP Prime program run at the same speed on both the emulator and real calculator. It is not perfect and could use major code improvements, but it was more to show that it's possible and it somewhat gets the job done, even if not 100% accurate:

EXPORT spdThrt()
BEGIN
DIMGROB_P(G1,80,60);
WHILE 1 DO
T:=TICKS();

RECT_P(G1,#FFFFFF);
FOR A FROM 0 TO 3 DO
FOR B FROM 0 TO 3 DO
PIXON_P(G1,A,B,RGB(RANDOM*255,RANDOM*255,RANDOM*255));
END;
END;
U:=TICKS();
WAIT(.01666-(U-T)/1000);
V:=TICKS();
TEXTOUT_P(U-T,G1,12,30);
TEXTOUT_P(V-T,G1,12,40);
BLIT_P(G0,0,0,320,240,G1,0,0,80,60);
END;
END;




While the speed is still slightly different, at least it would allow games to be playable on the emulator. I might just not have gotten the numbers right. The other alternative is to use WAIT(.016) or something that matches the on-calc frame rate, but then the game will lose speed on the calc)

@alexgt might find this handy for his games.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Unicorn

Oh,thats good. But wouldn't it just be simple to make to versions?
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Dream of Omnimaga

It depends. If the slowdown code is used as subroutine then you can simply replace the routine I guess. But ideally it's best to not have 2 versions to update each time people reports bugs.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Unicorn

Oh, yeah. Or you could ask what the player was running on, and then change a variable in wait( according to the answer.
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Dream of Omnimaga

That can be an idea too actually. I could simply detect which platform the game runs on on launch by running some code then check how long it took to run, then if it took longer then it means you are either using the calculator or a very old computer. Then the delay in-game is set accordingly at the same value everywhere.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

alexgt

Cool, In MinePrime the only thing that makes it not playable on PC is movement since the delay on calc for displaying GROBS is much greater (It displays the same GROB 16 times to achive the smooth scrolling)

But this is helpful in games like Nagoji 4x3. But what would really be nice it to have a command that will tell you if you are on calc or on emu
  • Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

c4ooo

I would probably suggest using delta values. It's practically what DJ_ O is doing  except instead of a wait()  function you have the player move less/more depending on performance. That's how all new games are made to run at the same speeds across platforms. Basicly you have to measure how long one game loop takes, and store it. If the measurement of how long one game loop takes is in nano seconds, It is recommended that you divide that number by a million, or if you are measuring in milliseconds, a thousand ect. Bassicly you don't want your delta value to be big. From now on, you pass that value to all your movement functions. If a player is supposed to move x+playerSpeed->x, then have him move x+playerSpeed*delta->x. You will have to adjust the playerSpeed a bit though.this way if the loop takes longer, delta is bigger and the player/entity moves a bit further then usual. Or vice versa, if this game is running on an op computer, delta will be very small and the player movement will be smother.

Dream of Omnimaga

That would definitively be an idea. Another idea for HP Prime slowdowns could be frame skipping, although right now the issue is more about games running too fast in the emulator. I'll have to read documentation about how delta values work.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Unicorn

Hmmm that sounds like it could work to. Alex, you could implement a command like this into your lib that you are making.
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Dream of Omnimaga

That would be a nice idea actually. It would be nice to have the perfect speed throttling command as standalone as well, though, for people who don't want to make their games dependent on another lib.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

alexgt

It  would have to be very customizeable which is not a big problem.
  • Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

Dream of Omnimaga

What kind of customizing ideas did you havein mind? The main goal is to have games run at identical speeds on both hardware and emulator, without requiring the user to change any setting, file or outright download a different file. Basically, no config required (although having the ability to change settings would definitively be a plus)
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

alexgt

the one I was thinking was have a base setting that the user would specify that would run the loop at the same time again and again.
  • Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

Dream of Omnimaga

Do you mean have him set it to run every 2 frame, every 3 frame, etc? Or just change the speed?
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

alexgt

change the speed as it would depend on the games coding of when it would display frames
  • Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

Powered by EzPortal