Gallery
Software
Music
Programming
Archive
Tuesday, May 21 Week 21

Commodore 64 source code examples for educational purpose.

1. c64-colors.prg
2. c64-chars.prg
3. c64-flicker.prg
4. c64-random.prg
5. c64-reset.prg
6. hi-there-1-2.prg
7. hi-there-1-3.prg
8. hi-there-2-1.prg
9. hi-there-2-2.prg
10. hi-there-2-3.prg
11. hi-there-2-4.prg

c64-colors.prg

Shows a list of the 16 available colors (0..F)
# Source-code
5 REM SAVE "@0:C64-COLORS",8
10 :
15 POKE 53281,0
20 PRINT "?":REM CLEAR SCREEN
100 FOR C=0 TO 15
102 S$=STR$(C)
104 IF LEN(S$)=1 THEN S$=" "S$
110 POKE 646,C
120 PRINT "?"S$
150 NEXT
200 POKE 646,14:REM ORG COLOR
READY.

c64-chars.prg

Shows a list of printable characters. Must choose between shifted or unshifted character set.
# Source code
5 REM SAVE "@0:C64-CHARS",8
10 REM --------------------------------
12 POKE 53281,0 :REM BLACK BG
14 POKE 646,1 :REM WHITE TEXT
16 REM PRINT CHR$(14) :REM LOWER CASE
18 PRINT "?"; :REM CLR SCREEN
19 REM --------------------------------
20 FOR N=32 TO 127:PRINT CHR$(N);:NEXT
22 FOR N=160 TO 255:PRINT CHR$(N);:NEXT
29 REM --------------------------------
30 PRINT "" :REM EMPTY LINE
32 POKE 646,14 :REM RESET TEXT
READY.

c64-flicker.prg

Shows some color flicker by changing background color.
# Source code
5 REM SAVE "@0:C64-FLICKER",8
10 LC=5:REM LOOP COUNT
20 OC=PEEK(53281)
99 :
100 FOR I=1 TO LC
110 FOR C=0 TO 15
120 POKE 53281,C
125 PRINT "?"
150 NEXT
190 NEXT
199 :
200 POKE 53281,OC:REM RESTORE ORG.COLOR
READY.

c64-random.prg

Shows random characters in random colors.
# Source code
5 REM SAVE "@0:C64-RANDOM",8
10 :
11 REM --------------------------------
50 POKE 53281,0 :REM BLACK BG COLOR
51 POKE 646,1 :REM WHITE FONT COLOR
80 PRINT "?"; :REM CLR SCREEN
100 :
114 POKE 646,1+(RND(1)*14):REM COLOR
118 K=RND(1)*95
120 PRINT CHR$(32+(RND(1)*95));
190 NEXT
200 POKE 646,1
READY.

c64-reset.prg

Reset stuff in the memory.
# Source code
5 REM SAVE "@0:C64-RESET",8
10 :
100 REM --------------------------------
102 POKE 53281,1 :REM WHITE BG COLOR
104 POKE 646,0 :REM BLACK TEXT
106 POKE 788,52 :REM STOP OFF
110 PRINT "?":REM CLEAR SCREEN
112 PRINT "???RESET...":REM PRINT MSG
180 FOR N=1 TO 1500:NEXT :REM PAUSE
199 REM --------------------------------
202 POKE 53281,6 :REM RESET BG
204 POKE 646,14 :REM RESET TEXT
206 PRINT CHR$(142) :REM RESET CHARS
299 REM --------------------------------
300 REM RESET SOUND
301 FOR N=54272 TO 54300:POKE N,0:NEXT
302 FOR N=54528 TO 55295:POKE N,0:NEXT
304 POKE 788,49 :STOP ON
306 POKE 650,0 :REM NORMAL KEYB
308 POKE 657,0 :REM USE SHIFT
997 PRINT "?":REM CLEAR SCREEN
998 REM --------------------------------
999 NEW
READY.

hi-there-1-2.prg

Demo/teaching program written by Henning Hansen.
# Source code
5 REM SAVE "@0:C64-HEJ 1-2",8
10 T$="HEJ MED DIG !!!           "
20 PRINT "?"T$
30 T$=MID$(T$,2)+LEFT$(T$,1)
40 PRINT "?"T$
50 FOR P=1 TO 100:NEXT:REM PAUSE
60 GOTO 30
READY.

hi-there-1-3.prg

Demo/teaching program written by Henning Hansen.
# Source code
5 REM SAVE "@0:C64-HEJ 1-3",8
10 T$="HEJ MED DIG !!!           "
20 PRINT "?"T$
21 PRINT "------------------"
25 FOR I=1 TO 5
30 PRINT "LEFT$(T$,1)="LEFT$(T$,1)
32 PRINT "MID$(T$,2) ="MID$(T$,2)
34 T$=MID$(T$,2)+LEFT$(T$,1)
35 PRINT "T$         ="T$
36 PRINT "------------------"
40 :
50 FOR P=1 TO 100:NEXT
60 NEXT
READY.

hi-there-2-1.prg

Demo/teaching program written by Henning Hansen.
# Source-code
5 REM SAVE "@0:C64-HEJ 2-1",8
10 T$="HEJ MED DIG !!!           "
13 KO$ = "????????????????????????????????????????"
14 LI$ = "????????????????????????"
20 PRINT "?":REM CLEAR SCREEN
21 REM WRITE LINE 10, COLUMN 1
22 KO=1:LI=10:GOSUB 100:PRINT T$
30 T$=MID$(T$,2)+LEFT$(T$,1)
40 GOSUB 100:PRINT T$
50 FOR P=1 TO 100:NEXT:REM PAUSE
60 GOTO 30
70 :
100 :REM CURSOR SUBROUTINE
110 PRINT "?";
120 IF KO>1 THEN PRINT LEFT$(KO$,KO-1);
130 IF LI>1 THEN PRINT LEFT$(LI$,LI-1);
140 RETURN
150 :REM CURSOR SUBROUTINE END
160 :
READY.

hi-there-2-2.prg

Demo/teaching program written by Henning Hansen.
# Source-code
5 REM SAVE "@0:C64-HEJ 2-2",8
10 T$="HEJ MED DIG !!!"
11 :REM NO SPACES
12 SP$ = "                                        "
13 KO$ = "????????????????????????????????????????"
14 LI$ = "????????????????????????"
20 :
30 KO=1:LI=10:REM WRITE LINE 10
40 PRINT "?":REM CLEAR SCREEN
44 T$=T$+LEFT$(SP$,40-LEN(T$))
45 :REM ADD SPACE UNTIL LINE FULL
50 GOSUB 200 :REM WRITE TEXT
60 GOTO 50
70 :
100 :REM CURSOR SUBROUTINE
110 PRINT "?";
120 IF KO>1 THEN PRINT LEFT$(KO$,KO-1);
130 IF LI>1 THEN PRINT LEFT$(LI$,LI-1);
140 RETURN
150 :REM CURSOR SUBROUTINE END
160 :
200 REM TEXT SUBROUTINE
210 T$=MID$(T$,2)+LEFT$(T$,1)
220 GOSUB 100:PRINT T$
240 FOR P=1 TO 100:NEXT:REM PAUSE
250 RETURN
260 :REM TEXT SUBROUTINE END
270 :
READY.

hi-there-2-3.prg

Demo/teaching program written by Henning Hansen.
# Source-code
5 REM SAVE "@0:C64-HEJ 2-3",8
10 T$="HEJ MED DIG !!!"
20 SP$ = "                                        "
30 LI$ = "????????????????????????"
35 KO$ = "????????????????????????????????????????"
40 P=100 :REM PAUSE TIME
50 KO=10 :REM COLUMN
90 GOTO 1000
99 :
100 :REM CURSOR SUBROUTINE
110 PRINT "?";
120 IF KO>1 THEN PRINT LEFT$(KO$,KO-1);
130 IF LI>1 THEN PRINT LEFT$(LI$,LI-1);
140 RETURN
150 :REM CURSOR SUBROUTINE END
160 :
400 :REM PAUSE SUBROUTINE
410 FOR X=1 TO P:NEXT
420 RETURN
440 :
1000 :: REM MAIN PROGRAM ::
1010 PRINT "?":REM CLEAR SCREEN
1020 FOR I=1 TO 20
1030 LI=I
1040 GOSUB 100:REM SET CURSOR
1050 PRINT T$
1060 IF LI>1 THEN LI=LI-1
1070 GOSUB 100:REM SET CURSOR
1080 PRINT LEFT$(SP$,LEN(T$)):REM DELETE
1090 GOSUB 400 :REM PAUSE
1100 NEXT
READY.

hi-there-2-4.prg

Demo/teaching program written by Henning Hansen.
# Source-code
5 REM SAVE "@0:C64-HEJ 2-4",8
10 T$="HEJ MED DIG !!!"
20 SP$ = "                                        "
30 LI$ = "????????????????????????"
35 KO$ = "????????????????????????????????????????"
40 P=100 :REM PAUSE TIME
50 KO=10 :REM COLUMN
60 FL=3  :REM FIRST LINE
70 SL=20 :REM LAST LINE
90 GOTO 1000
99 :
100 :REM CURSOR SUBROUTINE
110 PRINT "?";
120 IF KO>1 THEN PRINT LEFT$(KO$,KO-1);
130 IF LI>1 THEN PRINT LEFT$(LI$,LI-1);
140 RETURN
150 :REM CURSOR SUBROUTINE END
160 :
400 :REM PAUSE SUBROUTINE
410 FOR X=1 TO P:NEXT
420 RETURN
430 :REM PAUSE SUBROUTINE END
440 :
500 :REM DELETE SUBROUTINE
510 GOSUB 100 :REM SET CURSOR
520 PRINT LEFT$(SP$,LEN(T$))
530 RETURN
540 :REM DELETE SUBROUTINE END
550 :
600 :REM MOVE UP ROUTINE
610 FOR I=SL TO FL STEP -1
620 LI=I
630 GOSUB 100 :REM SET CURSOR
640 PRINT T$
650 IF LI:REM DELETE LINE
660 GOSUB 400 :REM PAUSE
670 NEXT
680 RETURN
690 :REM END MOVE UP
695 :
1000 ::REM MAIN PROGRAM::
1010 PRINT "?":REM CLEAR SCREEN
1020 FOR I=SL TO FL STEP -1
1030 LI=I
1040 GOSUB 100 :REM SET CURSOR
1050 PRINT T$
1060 IF LI:REM DELETE LINE
1070 GOSUB 400 :REM PAUSE
1080 NEXT
READY.