2017-07-18 10:46:03 UTC
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. *
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
Let me know what you guys think and if this might be useful for you!