Options for slowing down compiled basic

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

Options for slowing down compiled basic

Post by Jodo » Tue Jan 22, 2019 9:37 am

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!
0 x

Ralf
Manic Miner
Posts: 977
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Options for slowing down compiled basic

Post by Ralf » Tue Jan 22, 2019 9:58 am

Yes, use FOR x=1 TO 1000:NEXT x ;) Won't get interrupted by keypress, unlike PAUSE
1 x

User avatar
R-Tape
Site Admin
Posts: 1927
Joined: Thu Nov 09, 2017 11:46 am

Re: Options for slowing down compiled basic

Post by R-Tape » 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.
1 x

Jodo
Berk
Posts: 13
Joined: Wed Apr 11, 2018 9:52 am
Location: West Yorkshire, UK

Re: Options for slowing down compiled basic

Post by Jodo » Tue Jan 22, 2019 11:31 am

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?
0 x

Kweepa
Microbot
Posts: 189
Joined: Sat Feb 03, 2018 6:14 pm
Location: Austin, Texas

Re: Options for slowing down compiled basic

Post by Kweepa » 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.
1 x

Jodo
Berk
Posts: 13
Joined: Wed Apr 11, 2018 9:52 am
Location: West Yorkshire, UK

Re: Options for slowing down compiled basic

Post by Jodo » 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!
0 x

User avatar
Cosmium
Berk
Posts: 16
Joined: Tue Dec 04, 2018 10:20 pm
Location: USA

Re: Options for slowing down compiled basic

Post by Cosmium » Fri Jan 25, 2019 10:15 pm

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.
0 x

Post Reply