Options for slowing down compiled basic

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
Jodo
Drutt
Posts: 25
Joined: Wed Apr 11, 2018 10:52 am
Location: West Yorkshire, UK

Options for slowing down compiled basic

Post by Jodo »

Having completed writing about 80% of an arcade game I've compiled it in Hisoft Basic and now need to slow it down. I can do this with a Pause statement in the main loop and get it to the speed I require but is this good practice when Pause is interruptable?

Are there any other better options? My basic skills are, well, basic :D and the only other option I can think of is a For...Next loop.

Thanks!
Ralf
Rick Dangerous
Posts: 2279
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Options for slowing down compiled basic

Post by Ralf »

Yes, use FOR x=1 TO 1000:NEXT x ;) Won't get interrupted by keypress, unlike PAUSE
User avatar
R-Tape
Site Admin
Posts: 6353
Joined: Thu Nov 09, 2017 11:46 am

Re: Options for slowing down compiled basic

Post by R-Tape »

Have you considered a bit of in game BEEPer music? That can't be interrupted, and you could tailor it to the speed& mood you want.
Jodo
Drutt
Posts: 25
Joined: Wed Apr 11, 2018 10:52 am
Location: West Yorkshire, UK

Re: Options for slowing down compiled basic

Post by Jodo »

Ralf wrote: Tue Jan 22, 2019 9:58 am Yes, use FOR x=1 TO 1000:NEXT x ;) Won't get interrupted by keypress, unlike PAUSE
Thanks Ralf, I think I'll use this to get it where I want it for testing at least.
R-Tape wrote: Tue Jan 22, 2019 9:58 am Have you considered a bit of in game BEEPer music? That can't be interrupted, and you could tailor it to the speed& mood you want.
Thanks R-Tape for the reminder. I'd forgotten reading people use the sound to slow code down. Would it just be a case of calling a subroutine holding the music every lap of the main loop, and maybe use a counter in a computed goto to play the next note in the sequence? Or is there much more to it?
User avatar
Kweepa
Manic Miner
Posts: 311
Joined: Sat Feb 03, 2018 6:14 pm
Location: Albuquerque, New Mexico

Re: Options for slowing down compiled basic

Post by Kweepa »

If interrupts are still running, you could wait for the interrupt counter at 23672 to change, which it does every 1/50 seconds.
Jodo
Drutt
Posts: 25
Joined: Wed Apr 11, 2018 10:52 am
Location: West Yorkshire, UK

Re: Options for slowing down compiled basic

Post by Jodo »

Kweepa wrote: Wed Jan 23, 2019 4:43 pm If interrupts are still running, you could wait for the interrupt counter at 23672 to change, which it does every 1/50 seconds.
Thanks Kweepa, I'll look into it. Not sure I'll be capable of implementing that though!
User avatar
Cosmium
Microbot
Posts: 154
Joined: Tue Dec 04, 2018 10:20 pm
Location: USA

Re: Options for slowing down compiled basic

Post by Cosmium »

Jodo wrote: Fri Jan 25, 2019 8:10 pm
Kweepa wrote: Wed Jan 23, 2019 4:43 pm If interrupts are still running, you could wait for the interrupt counter at 23672 to change, which it does every 1/50 seconds.
Thanks Kweepa, I'll look into it. Not sure I'll be capable of implementing that though!
If the interrupts are running, something like this should work (though I haven't written any BASIC for 30+ years, so pls forgive any syntax errors!):

10 LET LAST_FR = 0: REM clear last frame variable

main loop:
...
100 IF LAST_FR = PEEK 23672 THEN GO TO 100 : REM keep looping (ie. wait) if frame counter hasn't changed, ie. we're still on the same frame
110 LET LAST_FR = PEEK 23672 : REM store new frame for next time
...

This BASIC should delay the game by a max of one frame in the main loop.
Post Reply