Jump to content
IGNORED

Timing loops in compiled BASIC/XB?


OLD CS1
 Share

Recommended Posts

The speed of TI BASIC can sometimes lend itself to a timing loop. Say you need to reduce a score every second, depending upon what needs to be done the loop can amount to a second: check for a key-press or joystick motion, decrement the timer, play a short tone, check the timer has not reached zero, jump back to the top of the loop (for a FOR/NEXT, however you want to do it.)

 

Compiled BASIC is far too fast for this to work unless you can figure out how many times the loop can run within the required time, or maybe a CALL SOUND as a NOP to take up the extra time.

 

Has anyone yet developed a sure-fire way to keep time in compiled BASIC or Extended BASIC? I just did a quick search of topics with a few keywords and did not turn up anything.

Link to comment
Share on other sites

From the compiler manual:

One frustration in developing an XB program intended for compilation is that is can be rather

tedious to adjust the speed of the gameplay. You try a value in a FOR/NEXT loop, save the

program, compile, assemble, load, only to find that it is too fast. Then you go back to XB, try

a larger value, repeat the process; find that it is still too fast, try another value, etc, etc.

If you are using XB256 to develop the game there is an easy way to streamline the process.

Let's say you are working in screen2. All you have to do is set up a “hot key” to go to a

diagnostic menu in screen1, where variables can be modified without disturbing screen2.

When done simply return to screen2 and resume where you left off.

In the simple demo program below, lines 100-200 define a ball and put it on the screen. The

ball can be moved with the ESDX keys. If you press <Fctn 1> line 160 will go to line 210

where the delay value can be modified. After pressing <Enter> control returns to the main

program loop with the modified delay value.

100 CALL LINK("CHAR2",65,"3C7EFFFFFFFF7E3C"):: R=12 :: C=16 :: DLY=1

110 CALL LINK("SCRN2")

120 CALL HCHAR(R,C,65)

130 FOR I=1 TO DLY

140 CALL KEY(0,K,S):: IF S=1 THEN 160

150 NEXT I

160 IF K=3 THEN 210

170 RN=R-(K=69)*(R>1)+(K=88)*(R<24):: CN=C-(K=83)*(C>1)+(K=68)*(C<32)

190 IF RN=R AND CN=C THEN 130

200 CALL HCHAR(R,C,32):: R=RN :: C=CN :: GOTO 120

210 CALL LINK("SCRN1"):: CALL CLEAR :: INPUT "DELAY VALUE? ":DLY ::

GOTO 110

**********************************************************************************************

Another way to fine tune a timing loop is to add line 1 to the XB loader program: 1 CALL HCHAR(1,1,20). If the compiled program has a line with CALL GCHAR(1,1,DLY) then you can retrieve a delay value to try out.


If you are scanning the keyboard you will have much better keyboard response if you set up a loop to scan the keyboard repeatedly rather than scanning it just once and then using DELAY or CALL SOUND to slow things down. After scanning, say 50 times then you go on if there is a new key or keep scanning if there isn't.


I will be adding a routine to XB256 and the compiler called SYNC which will let you determine how many 1/60 second ticks of the clock to use before repeating a loop. You would set it up with CALL LOAD(-1,3) for 3/60 second and then program a loop with CALL LINK("SYNC") at the end of the loop. SYNC takes into account the length of the loop so you can take 3/60 of a second per loop which is different from DELAY which adds a delay of known time after the loop. Since I have to repost the package to fix the IF THEN ELSE bug I will include this as well. Should be before the end of the week, and probably sooner.

Edited by senior_falcon
  • Like 2
Link to comment
Share on other sites

I don't have the code infront of me but there is the VDP interrupt and a timer that count downs. If it is 0, VDP interrupt is executed. This you can use for timing things. This will stay true after compilation.

Just peek for the value of this timer and wait with any Basic execution unless it has a certain value. If it has the value then you continue your Basic code.

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...