Discussion:
Apple II BASIC code for elapsed time
(too old to reply)
Chris Tobar
2017-07-18 10:46:03 UTC
Permalink
Raw Message
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!
Anthony Ortiz
2017-07-18 17:24:57 UTC
Permalink
Raw Message
Post 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!
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
Michael 'AppleWin Debugger Dev'
2017-07-18 18:49:47 UTC
Permalink
Raw Message
Post by Chris Tobar
Hi,
I just joined this group.
Welcome to the Apple 2 world !
Post by Chris Tobar
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
James Davis
2017-07-18 19:39:44 UTC
Permalink
Raw Message
Post 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.
. . .
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%20Project/>
(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
g***@sasktel.net
2017-07-18 20:53:55 UTC
Permalink
Raw Message
Post 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!
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.
g***@sasktel.net
2017-07-18 20:55:22 UTC
Permalink
Raw Message
Post by g***@sasktel.net
Post 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!
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.
Nick Westgate
2017-07-18 22:22:40 UTC
Permalink
Raw Message
Post by Chris Tobar
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.
Chris Tobar
2017-07-18 22:41:25 UTC
Permalink
Raw Message
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
Chris Tobar
2017-07-18 22:44:08 UTC
Permalink
Raw Message
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
Chris Tobar
2017-07-18 22:48:18 UTC
Permalink
Raw Message
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
Nick Westgate
2017-07-18 22:59:16 UTC
Permalink
Raw Message
Post by Chris Tobar
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.
Chris Tobar
2017-07-19 00:40:14 UTC
Permalink
Raw Message
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.
Loading...