Skip to main content
correction of program
Source Link
Voitcus
  • 755
  • 4
  • 11

Commodore 64 BASIC, 1619 16 bytes

10 FOR I=1 TO1000 960FORI=1TO930*N:NEXT:RETURN

With a call N=<number-of-secods>:GOSUB1000.

However, I cannot provide enough accuracy. Because C64 had about 1 MHz CPU speed, I remember it was good enough to make an empty FOR-NEXT loop 1000 times so that it was about 1 second.

In fact there were two main versions of the machine: PAL 0.985 MHz and NTSC 1.023 MHz (all data from C64 Wikipedia Page). As I had NTSC version, it was required to run loop about 950930 times.

Tests with the following program (5N seconds, asprovided by user in the JINPUT variable):

10 INPUT N
20 PRINT TI$
2030 FORGOSUB J=11000
40 TOPRINT 5TI$
3050 END
1000 FOR I=1 TO 960930*N:NEXT I
40 NEXT J
50 PRINT TI$:RETURN

where TI$ is a system variable containing string (hhmmss format) with time elapsed from last reset (1 second accuracy, however also depending on CPU speed, so this is not quite relevant, because it's the same clock).

C64 programenter image description here

Screenshot made with online C64 emulator http://codeazur.com.br/stuff/fc64_final/.

This program (line 1000 only) occupies 1616 19 bytes in memory, as tested with PRINT FRE(0)+65535 both before typing the code (3890938908 bytes) and after (3889338893 38889 bytes). PRINT FRE(0) returns free memory for BASIC program (it's a negative value and constant 65535 should be added, but in fact it does not matter).

Because this program does not test the time elapsed in a loop, it qualifies for a bounty.

Commodore 64 BASIC, 16 bytes

10 FOR I=1 TO 960:NEXT

However, I cannot provide enough accuracy. Because C64 had about 1 MHz CPU speed, I remember it was good enough to make an empty FOR-NEXT loop 1000 times so that it was about 1 second.

In fact there were two main versions of the machine: PAL 0.985 MHz and NTSC 1.023 MHz (all data from C64 Wikipedia Page). As I had NTSC version, it was required to run loop about 950 times.

Tests with the following program (5 seconds, as in the J variable):

10 PRINT TI$
20 FOR J=1 TO 5
30 FOR I=1 TO 960:NEXT I
40 NEXT J
50 PRINT TI$

where TI$ is a system variable containing string with time elapsed from last reset (1 second accuracy, however also depending on CPU speed, so this is not quite relevant, because it's the same clock).

C64 program

Screenshot made with online C64 emulator http://codeazur.com.br/stuff/fc64_final/.

This program occupies 16 bytes in memory, as tested with PRINT FRE(0)+65535 both before typing the code (38909 bytes) and after (38893 bytes). PRINT FRE(0) returns free memory for BASIC program (it's a negative value and constant 65535 should be added, but in fact it does not matter).

Because this program does not test the time elapsed in a loop, it qualifies for a bounty.

Commodore 64 BASIC, 19 16 bytes

1000 FORI=1TO930*N:NEXT:RETURN

With a call N=<number-of-secods>:GOSUB1000.

However, I cannot provide enough accuracy. Because C64 had about 1 MHz CPU speed, I remember it was good enough to make an empty FOR-NEXT loop 1000 times so that it was about 1 second.

In fact there were two main versions of the machine: PAL 0.985 MHz and NTSC 1.023 MHz (all data from C64 Wikipedia Page). As I had NTSC version, it was required to run loop about 930 times.

Tests with the following program (N seconds, provided by user in INPUT):

10 INPUT N
20 PRINT TI$
30 GOSUB 1000
40 PRINT TI$
50 END
1000 FOR I=1 TO 930*N:NEXT I:RETURN

where TI$ is a system variable containing string (hhmmss format) with time elapsed from last reset (1 second accuracy, however also depending on CPU speed, so this is not quite relevant, because it's the same clock).

enter image description here

Screenshot made with online C64 emulator http://codeazur.com.br/stuff/fc64_final/.

This program (line 1000 only) occupies 16 19 bytes in memory, as tested with PRINT FRE(0)+65535 both before typing the code (38908 bytes) and after (38893 38889 bytes). PRINT FRE(0) returns free memory for BASIC program (it's a negative value and constant 65535 should be added, but in fact it does not matter).

Because this program does not test the time elapsed in a loop, it qualifies for a bounty.

Source Link
Voitcus
  • 755
  • 4
  • 11

Commodore 64 BASIC, 16 bytes

10 FOR I=1 TO 960:NEXT

However, I cannot provide enough accuracy. Because C64 had about 1 MHz CPU speed, I remember it was good enough to make an empty FOR-NEXT loop 1000 times so that it was about 1 second.

In fact there were two main versions of the machine: PAL 0.985 MHz and NTSC 1.023 MHz (all data from C64 Wikipedia Page). As I had NTSC version, it was required to run loop about 950 times.

Tests with the following program (5 seconds, as in the J variable):

10 PRINT TI$
20 FOR J=1 TO 5
30 FOR I=1 TO 960:NEXT I
40 NEXT J
50 PRINT TI$

where TI$ is a system variable containing string with time elapsed from last reset (1 second accuracy, however also depending on CPU speed, so this is not quite relevant, because it's the same clock).

C64 program

Screenshot made with online C64 emulator http://codeazur.com.br/stuff/fc64_final/.

This program occupies 16 bytes in memory, as tested with PRINT FRE(0)+65535 both before typing the code (38909 bytes) and after (38893 bytes). PRINT FRE(0) returns free memory for BASIC program (it's a negative value and constant 65535 should be added, but in fact it does not matter).

Because this program does not test the time elapsed in a loop, it qualifies for a bounty.