Megalextoria
Retro computing and gaming, sci-fi books, tv and movies and other geeky stuff.

Home » Digital Archaeology » Computer Arcana » Apple » Apple II » Apple II BASIC code for elapsed time
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Apple II BASIC code for elapsed time [message #348653] Tue, 18 July 2017 06:46 Go to next message
Anonymous
Karma:
Originally posted by: Chris Tobar

Hi,
I just joined this group. I recently bought an Apple II+ computer, and I've been writing some simple BASIC programs for it. I'm having a lot of fun with it so far! I'm liking the challenge of working within the limitations of a vintage computer. I remember using Apple II computers in school in the 1980's when I was a little kid, but actually learning to program them is completely new to me.

Since the Apple II didn't come with a real time clock, I made a simple program to display elapsed time. It uses the processor speed, so it's not going to be 100 percent accurate. But it's pretty darn close. (I tested it with a stopwatch). My Apple II has the standard 6502 1 Mhz processor. You can adjust the timer speed with a variable. I'm hoping maybe this code could be useful for someone. You could also modify it and use it for animations..

Here's the code...

10 REM * THIS PROGRAM IS A SIMPLE TIMER TO SHOW SECONDS AND MINUTES ELAPSED.. *
20 HOME
30 REM * INITIALIZE VARIABLES *
40 LET I=0: LET S=0: LET M=0: LET K=0
50 REM * V1 IS A VARIABLE TO DETERMINE HOW MANY COUNTS ARE EXECUTED IN EACH LOOP, AND IS USED TO 'TUNE' THE TIMER. THE COMPUTER'S PROCESSOR SPEED IS USED, SO THIS MAY NEED TO BE ADJUSTED. *
60 LET V1=12
70 PRINT "PRESS 1 TO START THE TIMER."
80 PRINT "PRESS 2 TO STOP THE TIMER."
90 PRINT "PRESS 3 TO RESET THE TIMER."
100 PRINT "PRESS 4 TO EXIT."
110 REM * START THE LOOP *
120 FOR I = 0 TO V1
130 REM * THIS CHECKS IF A KEY HAS BEEN PRESSED *
140 K = PEEK(-16384)
150 IF K=180 THEN HOME: END
160 IF (K=177 AND I >= V1 AND S >60) THEN M=M+1: S=0
170 IF K=179 THEN S=0: M=0
180 IF (I >= V1 AND S=0) THEN PRINT "0 SECONDS "
185 IF (I >= V1 AND S=1) THEN PRINT "1 SECOND "
190 IF (I >= V1 AND S>1) THEN PRINT S; " SECONDS "
191 VTAB 7
192 IF (I >= V1 AND M=0) THEN PRINT "0 MINUTES "
193 IF (I >= V1 AND M=1) THEN PRINT "1 MINUTE "
194 IF (I >= V1 AND M>1) THEN PRINT M; " MINUTES "
200 NEXT I
210 IF I >= V1+1 THEN GOTO 110
220 END


Let me know what you guys think and if this might be useful for you!
Re: Apple II BASIC code for elapsed time [message #348670 is a reply to message #348653] Tue, 18 July 2017 13:24 Go to previous messageGo to next message
anthonypaulo is currently offline  anthonypaulo
Messages: 531
Registered: September 2013
Karma: 0
Senior Member
On Tuesday, July 18, 2017 at 6:46:05 AM UTC-4, Chris Tobar wrote:
> Hi,
> I just joined this group. I recently bought an Apple II+ computer, and I've been writing some simple BASIC programs for it. I'm having a lot of fun with it so far! I'm liking the challenge of working within the limitations of a vintage computer. I remember using Apple II computers in school in the 1980's when I was a little kid, but actually learning to program them is completely new to me.
>
> Since the Apple II didn't come with a real time clock, I made a simple program to display elapsed time. It uses the processor speed, so it's not going to be 100 percent accurate. But it's pretty darn close. (I tested it with a stopwatch). My Apple II has the standard 6502 1 Mhz processor. You can adjust the timer speed with a variable. I'm hoping maybe this code could be useful for someone. You could also modify it and use it for animations.
>
> Here's the code...
>
> 10 REM * THIS PROGRAM IS A SIMPLE TIMER TO SHOW SECONDS AND MINUTES ELAPSED. *
> 20 HOME
> 30 REM * INITIALIZE VARIABLES *
> 40 LET I=0: LET S=0: LET M=0: LET K=0
> 50 REM * V1 IS A VARIABLE TO DETERMINE HOW MANY COUNTS ARE EXECUTED IN EACH LOOP, AND IS USED TO 'TUNE' THE TIMER. THE COMPUTER'S PROCESSOR SPEED IS USED, SO THIS MAY NEED TO BE ADJUSTED. *
> 60 LET V1=12
> 70 PRINT "PRESS 1 TO START THE TIMER."
> 80 PRINT "PRESS 2 TO STOP THE TIMER."
> 90 PRINT "PRESS 3 TO RESET THE TIMER."
> 100 PRINT "PRESS 4 TO EXIT."
> 110 REM * START THE LOOP *
> 120 FOR I = 0 TO V1
> 130 REM * THIS CHECKS IF A KEY HAS BEEN PRESSED *
> 140 K = PEEK(-16384)
> 150 IF K=180 THEN HOME: END
> 160 IF (K=177 AND I >= V1 AND S >60) THEN M=M+1: S=0
> 170 IF K=179 THEN S=0: M=0
> 180 IF (I >= V1 AND S=0) THEN PRINT "0 SECONDS "
> 185 IF (I >= V1 AND S=1) THEN PRINT "1 SECOND "
> 190 IF (I >= V1 AND S>1) THEN PRINT S; " SECONDS "
> 191 VTAB 7
> 192 IF (I >= V1 AND M=0) THEN PRINT "0 MINUTES "
> 193 IF (I >= V1 AND M=1) THEN PRINT "1 MINUTE "
> 194 IF (I >= V1 AND M>1) THEN PRINT M; " MINUTES "
> 200 NEXT I
> 210 IF I >= V1+1 THEN GOTO 110
> 220 END
>
>
> Let me know what you guys think and if this might be useful for you!

Hey Chris!

Welcome to the wonderful world of the Apple II! I remember when I first learned to program in BASIC and how awesome it was to be able to speak to the computer and make it do my bidding, but it was a while before I ran into the limitations you speak of so if you're bumping into it already then you're farther along than you think!

I'm not at home to run this but a quick look through the code has me wondering how you manage to count seconds since I don't see S being incremented anywhere. Am I missing something?

Cheers!

Anthony
Re: Apple II BASIC code for elapsed time [message #348676 is a reply to message #348653] Tue, 18 July 2017 14:49 Go to previous messageGo to next message
Michael AppleWin Debu is currently offline  Michael AppleWin Debu
Messages: 1262
Registered: March 2013
Karma: 0
Senior Member
On Tuesday, July 18, 2017 at 3:46:05 AM UTC-7, Chris Tobar wrote:
> Hi,
> I just joined this group.

Welcome to the Apple 2 world !

> I made a simple program to display elapsed time.
> Here's the code...
>
> 40 LET I=0: LET S=0: LET M=0: LET K=0
> 200 NEXT I
> 220 END

To save some typing here are a few Applesoft BASIC tips.

1. You don't need to use LET
2. You don't need to explicitly name your loops
3. You don't need an END statement on the very last line

Of course if you are using Integer Basic then ignore the above. :-)

Cheers
Michael
Re: Apple II BASIC code for elapsed time [message #348677 is a reply to message #348653] Tue, 18 July 2017 15:39 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: James Davis

On Tuesday, July 18, 2017 at 3:46:05 AM UTC-7, Chris Tobar wrote:
> Hi,
> I just joined this group. I recently bought an Apple II+ computer, and I've been writing some simple BASIC programs for it. I'm having a lot of fun with it so far! I'm liking the challenge of working within the limitations of a vintage computer. I remember using Apple II computers in school in the 1980's when I was a little kid, but actually learning to program them is completely new to me.
> . . .
> Let me know what you guys think and if this might be useful for you!

Hi Chris,

Welcome to the world of the Apple II+.

Two very good souces of downloadable information are:

The "Asimov Apple II Public Network" FTP site:
<ftp://public.asimov.net/pub/apple_II/>

and

The Apple II Documentation Project - A Brutal Deluxe (French) website:
< http://mirrors.apple2.org.za/Apple%20II%20Documentation%20Pr oject/>
(This is the South African Mirror website address.)


Download the Asimov site Index.txt, sort it, and then you can search it in any text editor for any subjects of interest (keywords).

Yours truly,

James Davis
Re: Apple II BASIC code for elapsed time [message #348683 is a reply to message #348653] Tue, 18 July 2017 16:53 Go to previous messageGo to next message
gids.rs is currently offline  gids.rs
Messages: 1395
Registered: October 2012
Karma: 0
Senior Member
On Tuesday, July 18, 2017 at 4:46:05 AM UTC-6, Chris Tobar wrote:
> Hi,
> I just joined this group. I recently bought an Apple II+ computer, and I've been writing some simple BASIC programs for it. I'm having a lot of fun with it so far! I'm liking the challenge of working within the limitations of a vintage computer. I remember using Apple II computers in school in the 1980's when I was a little kid, but actually learning to program them is completely new to me.
>
> Since the Apple II didn't come with a real time clock, I made a simple program to display elapsed time. It uses the processor speed, so it's not going to be 100 percent accurate. But it's pretty darn close. (I tested it with a stopwatch). My Apple II has the standard 6502 1 Mhz processor. You can adjust the timer speed with a variable. I'm hoping maybe this code could be useful for someone. You could also modify it and use it for animations.
>
> Here's the code...
>
> 10 REM * THIS PROGRAM IS A SIMPLE TIMER TO SHOW SECONDS AND MINUTES ELAPSED. *
> 20 HOME
> 30 REM * INITIALIZE VARIABLES *
> 40 LET I=0: LET S=0: LET M=0: LET K=0
> 50 REM * V1 IS A VARIABLE TO DETERMINE HOW MANY COUNTS ARE EXECUTED IN EACH LOOP, AND IS USED TO 'TUNE' THE TIMER. THE COMPUTER'S PROCESSOR SPEED IS USED, SO THIS MAY NEED TO BE ADJUSTED. *
> 60 LET V1=12
> 70 PRINT "PRESS 1 TO START THE TIMER."
> 80 PRINT "PRESS 2 TO STOP THE TIMER."
> 90 PRINT "PRESS 3 TO RESET THE TIMER."
> 100 PRINT "PRESS 4 TO EXIT."
> 110 REM * START THE LOOP *
> 120 FOR I = 0 TO V1
> 130 REM * THIS CHECKS IF A KEY HAS BEEN PRESSED *
> 140 K = PEEK(-16384)
> 150 IF K=180 THEN HOME: END
> 160 IF (K=177 AND I >= V1 AND S >60) THEN M=M+1: S=0
> 170 IF K=179 THEN S=0: M=0
> 180 IF (I >= V1 AND S=0) THEN PRINT "0 SECONDS "
> 185 IF (I >= V1 AND S=1) THEN PRINT "1 SECOND "
> 190 IF (I >= V1 AND S>1) THEN PRINT S; " SECONDS "
> 191 VTAB 7
> 192 IF (I >= V1 AND M=0) THEN PRINT "0 MINUTES "
> 193 IF (I >= V1 AND M=1) THEN PRINT "1 MINUTE "
> 194 IF (I >= V1 AND M>1) THEN PRINT M; " MINUTES "
> 200 NEXT I
> 210 IF I >= V1+1 THEN GOTO 110
> 220 END
>
>
> Let me know what you guys think and if this might be useful for you!


You can speed this up tremendously.

First remove all the greater-than (>) signs as "I" will never be greater than "V1", and you can also remove all the brackets in the IF statements which are not necessary with only one "AND" comparison.
Re: Apple II BASIC code for elapsed time [message #348684 is a reply to message #348683] Tue, 18 July 2017 16:55 Go to previous messageGo to next message
gids.rs is currently offline  gids.rs
Messages: 1395
Registered: October 2012
Karma: 0
Senior Member
On Tuesday, July 18, 2017 at 2:53:57 PM UTC-6, gid...@sasktel.net wrote:
> On Tuesday, July 18, 2017 at 4:46:05 AM UTC-6, Chris Tobar wrote:
>> Hi,
>> I just joined this group. I recently bought an Apple II+ computer, and I've been writing some simple BASIC programs for it. I'm having a lot of fun with it so far! I'm liking the challenge of working within the limitations of a vintage computer. I remember using Apple II computers in school in the 1980's when I was a little kid, but actually learning to program them is completely new to me.
>>
>> Since the Apple II didn't come with a real time clock, I made a simple program to display elapsed time. It uses the processor speed, so it's not going to be 100 percent accurate. But it's pretty darn close. (I tested it with a stopwatch). My Apple II has the standard 6502 1 Mhz processor. You can adjust the timer speed with a variable. I'm hoping maybe this code could be useful for someone. You could also modify it and use it for animations.
>>
>> Here's the code...
>>
>> 10 REM * THIS PROGRAM IS A SIMPLE TIMER TO SHOW SECONDS AND MINUTES ELAPSED. *
>> 20 HOME
>> 30 REM * INITIALIZE VARIABLES *
>> 40 LET I=0: LET S=0: LET M=0: LET K=0
>> 50 REM * V1 IS A VARIABLE TO DETERMINE HOW MANY COUNTS ARE EXECUTED IN EACH LOOP, AND IS USED TO 'TUNE' THE TIMER. THE COMPUTER'S PROCESSOR SPEED IS USED, SO THIS MAY NEED TO BE ADJUSTED. *
>> 60 LET V1=12
>> 70 PRINT "PRESS 1 TO START THE TIMER."
>> 80 PRINT "PRESS 2 TO STOP THE TIMER."
>> 90 PRINT "PRESS 3 TO RESET THE TIMER."
>> 100 PRINT "PRESS 4 TO EXIT."
>> 110 REM * START THE LOOP *
>> 120 FOR I = 0 TO V1
>> 130 REM * THIS CHECKS IF A KEY HAS BEEN PRESSED *
>> 140 K = PEEK(-16384)
>> 150 IF K=180 THEN HOME: END
>> 160 IF (K=177 AND I >= V1 AND S >60) THEN M=M+1: S=0
>> 170 IF K=179 THEN S=0: M=0
>> 180 IF (I >= V1 AND S=0) THEN PRINT "0 SECONDS "
>> 185 IF (I >= V1 AND S=1) THEN PRINT "1 SECOND "
>> 190 IF (I >= V1 AND S>1) THEN PRINT S; " SECONDS "
>> 191 VTAB 7
>> 192 IF (I >= V1 AND M=0) THEN PRINT "0 MINUTES "
>> 193 IF (I >= V1 AND M=1) THEN PRINT "1 MINUTE "
>> 194 IF (I >= V1 AND M>1) THEN PRINT M; " MINUTES "
>> 200 NEXT I
>> 210 IF I >= V1+1 THEN GOTO 110
>> 220 END
>>
>>
>> Let me know what you guys think and if this might be useful for you!
>
>
> You can speed this up tremendously.
>
> First remove all the greater-than (>) signs as "I" will never be greater than "V1", and you can also remove all the brackets in the IF statements which are not necessary with only one "AND" comparison.


In line 210, "THEN GOTO" is not necessary as "THEN" by itself will suffice.
Re: Apple II BASIC code for elapsed time [message #348692 is a reply to message #348653] Tue, 18 July 2017 18:22 Go to previous messageGo to next message
sicklittlemonkey is currently offline  sicklittlemonkey
Messages: 570
Registered: October 2012
Karma: 0
Senior Member
> Let me know what you guys think and if this might be useful for you!

As Anthony said, I think you've posted incomplete code.

It needs at least a couple of extra lines (which must be in your code if it works).

I'm guessing:
155 IF (K=177 AND I >= V1) THEN S=S+1
and:
175 VTAB 6

In any case, welcome to CSA2! : - )

Cheers,
Nick.
Re: Apple II BASIC code for elapsed time [message #348695 is a reply to message #348692] Tue, 18 July 2017 18:41 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: Chris Tobar

oops! Yeah, you're right, I made a typo! The code works, but I was re-typing it into a text file on my laptop and I made a few mistakes. Especially on line 160, where it's supposed to increment seconds.

This SHOULD be the right code now! :)

10 REM * THIS PROGRAM IS A SIMPLE TIMER TO SHOW SECONDS AND MINUTES ELAPSED. *
20 HOME
30 REM * INITIALIZE VARIABLES *
40 LET I=0: LET S=0: LET M=0: LET K=0
50 REM * V1 IS A VARIABLE TO DETERMINE HOW MANY COUNTS ARE EXECUTED IN EACH LOOP, AND IS USED TO 'TUNE' THE TIMER. THE COMPUTER'S PROCESSOR SPEED IS USED, SO THIS MAY NEED TO BE ADJUSTED. *
60 LET V1=12
70 PRINT "PRESS 1 TO START THE TIMER."
80 PRINT "PRESS 2 TO STOP THE TIMER."
90 PRINT "PRESS 3 TO RESET THE TIMER."
100 PRINT "PRESS 4 TO EXIT."
110 REM * START THE LOOP *
120 FOR I = 0 TO V1
130 REM * THIS CHECKS IF A KEY HAS BEEN PRESSED *
140 K = PEEK(-16384)
150 IF K=180 THEN HOME: END
160 IF (K=177 AND I >= V1) THEN S=S+1
161 IF (K=177 AND I >= V1 AND S>=60) THEN M=M+1: S=0
165 VTAB 6
170 IF K=179 THEN S=0: M=0
180 IF (I >= V1 AND S=0) THEN PRINT "0 SECONDS "
185 IF (I >= V1 AND S=1) THEN PRINT "1 SECOND "
190 IF (I >= V1 AND S>1) THEN PRINT S; " SECONDS "
191 VTAB 7
192 IF (I >= V1 AND M=0) THEN PRINT "0 MINUTES "
193 IF (I >= V1 AND M=1) THEN PRINT "1 MINUTE "
194 IF (I >= V1 AND M>1) THEN PRINT M; " MINUTES "
200 NEXT I
210 IF I >= V1+1 THEN GOTO 110
220 END
Re: Apple II BASIC code for elapsed time [message #348696 is a reply to message #348653] Tue, 18 July 2017 18:44 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: Chris Tobar

oops! Yeah, you're right, I made a typo! The code works, but I was re-typing it into a text file on my laptop and I made a few mistakes. Especially on line 160, where it's supposed to increment seconds.

This SHOULD be the right code now :)

10 REM * THIS PROGRAM IS A SIMPLE TIMER TO SHOW SECONDS AND MINUTES ELAPSED. *
20 HOME
30 REM * INITIALIZE VARIABLES *
40 LET I=0: LET S=0: LET M=0: LET K=0
50 REM * V1 IS A VARIABLE TO DETERMINE HOW MANY COUNTS ARE EXECUTED IN EACH LOOP, AND IS USED TO 'TUNE' THE TIMER. THE COMPUTER'S PROCESSOR SPEED IS USED, SO THIS MAY NEED TO BE ADJUSTED. *
60 LET V1=12
70 PRINT "PRESS 1 TO START THE TIMER."
80 PRINT "PRESS 2 TO STOP THE TIMER."
90 PRINT "PRESS 3 TO RESET THE TIMER."
100 PRINT "PRESS 4 TO EXIT."
110 REM * START THE LOOP *
120 FOR I = 0 TO V1
130 REM * THIS CHECKS IF A KEY HAS BEEN PRESSED *
140 K = PEEK(-16384)
150 IF K=180 THEN HOME: END
160 IF (K=177 AND I >= V1) THEN S=S+1
161 IF (K=177 AND I >= V1 AND S>=60) THEN M=M+1: S=0
165 VTAB 6
170 IF K=179 THEN S=0: M=0
180 IF (I >= V1 AND S=0) THEN PRINT "0 SECONDS "
185 IF (I >= V1 AND S=1) THEN PRINT "1 SECOND "
190 IF (I >= V1 AND S>1) THEN PRINT S; " SECONDS "
191 VTAB 7
192 IF (I >= V1 AND M=0) THEN PRINT "0 MINUTES "
193 IF (I >= V1 AND M=1) THEN PRINT "1 MINUTE "
194 IF (I >= V1 AND M>1) THEN PRINT M; " MINUTES "
200 NEXT I
210 IF I >= V1+1 THEN GOTO 110
220 END
Re: Apple II BASIC code for elapsed time [message #348697 is a reply to message #348653] Tue, 18 July 2017 18:48 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: Chris Tobar

oops! Yeah, you're right, I made a typo! The code works, but I re-typed it into a text file on my laptop, and I made a few mistakes. Especially on line 160, where it's supposed to increment the seconds. I also missed a couple of lines.

This SHOULD be the right code now :)

10 REM * THIS PROGRAM IS A SIMPLE TIMER TO SHOW SECONDS AND MINUTES ELAPSED. *
20 HOME
30 REM * INITIALIZE VARIABLES *
40 LET I=0: LET S=0: LET M=0: LET K=0
50 REM * V1 IS A VARIABLE TO DETERMINE HOW MANY COUNTS ARE EXECUTED IN EACH LOOP, AND IS USED TO 'TUNE' THE TIMER. THE COMPUTER'S PROCESSOR SPEED IS USED, SO THIS MAY NEED TO BE ADJUSTED. *
60 LET V1=12
70 PRINT "PRESS 1 TO START THE TIMER."
80 PRINT "PRESS 2 TO STOP THE TIMER."
90 PRINT "PRESS 3 TO RESET THE TIMER."
100 PRINT "PRESS 4 TO EXIT."
110 REM * START THE LOOP *
120 FOR I = 0 TO V1
130 REM * THIS CHECKS IF A KEY HAS BEEN PRESSED *
140 K = PEEK(-16384)
150 IF K=180 THEN HOME: END
160 IF (K=177 AND I >= V1) THEN S=S+1
161 IF (K=177 AND I >= V1 AND S>=60) THEN M=M+1: S=0
165 VTAB 6
170 IF K=179 THEN S=0: M=0
180 IF (I >= V1 AND S=0) THEN PRINT "0 SECONDS "
185 IF (I >= V1 AND S=1) THEN PRINT "1 SECOND "
190 IF (I >= V1 AND S>1) THEN PRINT S; " SECONDS "
191 VTAB 7
192 IF (I >= V1 AND M=0) THEN PRINT "0 MINUTES "
193 IF (I >= V1 AND M=1) THEN PRINT "1 MINUTE "
194 IF (I >= V1 AND M>1) THEN PRINT M; " MINUTES "
200 NEXT I
210 IF I >= V1+1 THEN GOTO 110
220 END
Re: Apple II BASIC code for elapsed time [message #348699 is a reply to message #348697] Tue, 18 July 2017 18:59 Go to previous messageGo to next message
sicklittlemonkey is currently offline  sicklittlemonkey
Messages: 570
Registered: October 2012
Karma: 0
Senior Member
On Wednesday, 19 July 2017 10:48:19 UTC+12, Chris Tobar wrote:
> The code works, but I re-typed it into a text file on my laptop, and I made a few mistakes.

Time to right things and make your laptop a slave of the Apple II!

Use ADTPro to transfer stuff rather than re-typing. (Or use VSDRIVE.)
http://adtpro.com/

Cheers,
Nick.
Re: Apple II BASIC code for elapsed time [message #348707 is a reply to message #348699] Tue, 18 July 2017 20:40 Go to previous message
Anonymous
Karma:
Originally posted by: Chris Tobar

I'm definitely going to have to check that program out! It would make things a lot easier. I just ordered a Super Serial card. I can't wait to get it hooked up.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Accessing FTP sites
Next Topic: Official Release Announcement - AppleWorks InitPack 2017
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Apr 19 04:18:15 EDT 2024

Total time taken to generate the page: 0.44199 seconds