The Liberty Basic Newsletter - Issue #80 - AUG 2000

© 2003, http://groups.yahoo.com/group/lbnews/

All Rights Reserved

Individual authors retain copyrights to their works.

Ammended after being proof read by Bill J.. who has kindly offered his services to proof read future newsletters before publishing..

Thanks Bill J

Special notice:

Although the newsletter has been handed over to me, Alyce will be in there still helping out with LBNews, she has decided to take a back seat for a while. Let me be the first to say thanks on behalf of the LB community for all the time, devotion and excellence she has brought to the community. I hope to see/hear a lot more from her in the future. Who knows what masterpieces of programs she'll come up with now that she has more time to spend programming :-)

Good Luck, Alyce

Welcome to my first Newsletter, I'll try to keep up the standards set by Alyce, however the newsletters are what YOU make them. I can only do so much. I'll need Suggestions and Contributions. I don't claim to know everything, far from it. I'm an advanced beginner to intermediate programmer. I'll collate all information given and try to answer questions. If I can't answer them, I'll try to find someone who can.

The Liberty Basic Newsletter - Issue #80 - AUG 2000

Special Issue

© 2000, Cameron Arnott

All Rights Reserved

In this issue:

LB 2.0+ Real Time Programming

Future Issues:

How to Wrap your programs into LB programs into executable's

Programming Etiquette

How do I start writing a program

I could take you through a program I'm working on or ask others if they'd like to do the same.

I'd like to have stuff related to both LB1.4 and LB2.0+ in each issue. As I'm using LB2.0 alphas, most of my contributions will be written in it. Some may work in both. I'll test and list them accordingly.

IT'S UP TO YOU. I'M OPEN TO SUGGESTIONS.

Real Time Programming

In today's world of fast and faster processors it is important to remember that just because it works on your system, the beautiful program you've written might not stand the test of TIME. You might have noticed that a lot of older programs that you've loved on your old XT/286/386/486 computer now run too fast. This is because they weren't written for real time use. The problem is in the timing loops. If you just do:

For loop=1 to 10000

next loop

then its timing won't necessarily be the same on all computers. In fact, you can guarantee that it won't. Some will be slower and some faster and this will affect the way your program runs, even to the end result of making the program unplayable.

Back in the 60's and 70's people didn't think ahead when writing their programs. They didn't take into consideration that computers would get faster.

The way to get around this is to tie your loop to the REAL TIME CLOCK in all computers. This will then set your program up so that it will run at the same speed on newer faster machines. Slower machines however could still probably run your program too slow. This is one reason why they state a minimum system requirement on most software.

Here is a sample program showing you the correct way to do timing loops.

' -------- Start Cut Here
' Real Loop Timing
' Note: this program requires LB 2.0

MaxLoops       = 100000         ' Loop Counter
TimeToDelay    = 3000           ' Milliseconds for first delay
DelayedTime    = 0              ' Real Time Program has been delayed
TimeNow        = 0              ' Milliseconds since midnight

[delay]
    TimeNow = time$("milliseconds")
    for Loop = 0 to MaxLoops
        DelayedTime = time$("milliseconds")-TimeNow

' New Lines to Handle crossing Midnight
        if DelayedTime < OldDelayedTime then goto[finishdelay]
' or  if DelayedTime TimeToDelay then goto [finishdelay]
    next Loop
    print "Your loop was too short to reach the desired real time delay!"
    print "Please increase the value of MaxLoops"
[finishdelay]

    print "The program has been delayed for ";TimeToDelay;
    print "milliseconds."

    goto [endprog]

[endprog]

    print "DelayedTime = ";DelayedTime
    print "Loop =";Loop
    print "TimeNow =";TimeNow
    print "It took ";Loop;" Loops to delay program by ";
    print TimeToDelay;" milliseconds"
    end
' ------- End Cut Here

Note: Due to the different speeds of computers, don't check to see if DelayedTime = TimeToDelay because in the running of the loop it will probably skip your value when running another instruction and be past it already when you check the value.

Do this and your program should run a lot better on faster systems.

Now you don't need to do this with loops that you don't need to run as fast as they can, such as sorting, reading in data etc. Mainly when moving things on the screen or waiting for input, then updating the screen. Just ask yourself: would the program run the same on a faster system?

Comments, requests or corrections: Hit 'REPLY' now!

Cameron Arnott -- mailto:blue_steel@globalfreeway.com.au