Gallery
Software
Music
Programming
Archive
Monday, Oct 14 Week 42

Using 5.25" diskettes or tape cassettes, mostly game-programs were loaded into it's 64 Kb -
of memory. The program was run by it's ~1 MHz processor, to a TV or monitor at 320x200 -
pixels and 16 colors (8:5 aspect).

Various C64 basic commands

Command Description
NEW Clear memory, new program...
RUN Run program
LOAD"$",8 Load device 8
LOAD"NAME",8 Load program by name from device 8
SAVE"@:filename",8 Overwrite file, device 8
OPEN 1,8,15,"N:NAME,01":CLOSE 1 Format disk, device 8 (clear memory first)
OPEN 1,8,15,"S:filename":CLOSE 1 Delete file, device 8
OPEN 1,8,15,"R:NEW=OLD":CLOSE 1 Rename file, device 8
LIST List all
LIST 10 List line number 10
LIST -100 List all lines to 100
LIST 110-400 List from line 110 to 400
LIST 1000- List from line 1000
REM Comment Comments/remarks
Multiple commands can be separated in a single call with a colon.

Variables and data types

Name Range Data type PC Description Extension
Byte $00..$FF (0..255) BYTE 8-Bit unsigned B
Int $0000..$FFFF (0..65535) WORD 16-Bit unsigned I%
Float 2.94E-39..1.70E+38, +/- 2-128..2127 FLOAT F
Str len(S$) STRING(255) Max 255 chars S$
Variable names should not be longer than 2 characters...
String variable names is extended by "$", and integer names is extended by "%".

C64 Data type conversion

Command Title Description
B=VAL(S$) STR to BYTE
I%=VAL(S$) STR to INT
F=VAL(S$) STR to FLOAT
S$=STR$(B) BYTE to STR
S$=STR$(I%) INT to STR
S$=STR$(F) FLOAT to STR
B=ASC(S$) CHAR (STR) to BYTE
S$=CHR$(B) BYTE to CHAR (STR)
HB=INT(I%/256) INT to BYTE (high) Extract high BYTE from INT
LB=I%-(INT(I%/256)*256) INT to BYTE (low) Extract low BYTE from INT

Extract low and high byte from integer

I%=2047
HB=INT(I%/256)
LB=I%-(HB*256)

Colors

ID Title Color Value
0 Black
#000000
1 White
#FCF9FC
2 Red
#933A4C
3 Cyan
#B6FAFA
4 Purple
#D27DED
5 Green
#6ACF6F
6 Blue
#4F44D8
7 Yellow
#FBFB8B
8 Orange
#D89C5B
9 Brown
#7F5307
10 Light red
#EF839F
11 Dark gray
#575753
12 Gray
#A3A7A7
13 Light green
#B7FBBF
14 Light blue
#A397FF
15 Light gray
#EFE9E7

Color & display commands

Command Description
POKE 53280,0 Black border color
POKE 53281,0 Black background color
POKE 646,1 White text/cursor color
POKE 53265,PEEK(53265) AND 23 Turn off screen display
POKE 53265,PEEK(53265) OR 16 Turn on screen display

Input commands

Command Description
INPUT "QUERY: ";S$:PRINT "INPUT WAS: ";S$ Keyboard input text
10 GET K$:IF K$="" THEN 10 Keyboard input char/key
J=PEEK(56321) Read joystick port 1
J=PEEK(56320) Read joystick port 2
IF (J AND 1)=0 THEN S$="UP" Check joystick value if moved up
IF (J AND 2)=0 THEN S$="DOWN" Check joystick value if moved down
IF (J AND 4)=0 THEN S$="LEFT" Check joystick value if moved left
IF (J AND 8)=0 THEN S$="RIGHT" Check joystick value if moved right
IF (J AND 16)=0 THEN S$="FIRE" Check joystick value if pushed fire

Keyboard commands

Command Description
POKE 788,52 Turn RUN/STOP key off
POKE 788,49 Turn RUN/STOP key on
POKE 657,128 Turn SHIFT key off
POKE 657,0 Turn SHIFT key on
POKE 792,193 Turn RESTORE key off
POKE 792,71 Turn RESTORE key on
POKE 198,0 Clear keyboard buffer
POKE 650,127 No keyboard repeat
POKE 650,0 Normal keyboard repeat
POKE 56341,12 Fast cursor speed [1..255]
POKE 56341,25 Normal cursor speed

Sound waveforms (SID)

17 Triangle
33 Sawtooth
65 Square
129 Noise

Sound commands

Command Description
POKE 54296,15 Set master-volume [0..F]
POKE 54276,17 Set voice 1 waveform [17/33/65/129]
POKE 54283,33 Set voice 2 waveform [17/33/65/129]
POKE 54290,129 Set voice 3 waveform [17/33/65/129]
POKE 54275,15 Set voice 1 square duration [0..F] (High)
POKE 54282,15 Set voice 2 square duration [0..F] (High)
POKE 54289,15 Set voice 3 square duration [0..F] (High)
POKE 54274,0 Set voice 1 square duration [0] (Low)
POKE 54281,0 Set voice 2 square duration [0] (Low)
POKE 54288,0 Set voice 3 square duration [0] (Low)
POKE 54277,(ATTACK1*16)+DECAY1 Set voice 1 attack [0..F] + decay [0..F]
POKE 54284,(ATTACK2*16)+DECAY2 Set voice 2 attack [0..F] + decay [0..F]
POKE 54291,(ATTACK3*16)+DECAY3 Set voice 3 attack [0..F] + decay [0..F]
POKE 54278,(SUSTAIN1*16)+RELEASE1 Set voice 1 sustain [0..F] + release [0..F]
POKE 54285,(SUSTAIN2*16)+RELEASE2 Set voice 2 sustain [0..F] + release [0..F]
POKE 54292,(SUSTAIN3*16)+RELEASE3 Set voice 3 sustain [0..F] + release [0..F]
POKE 54272,2145-(INT(2145/256)*256) Set voice 1 frequency (ex. 2145=C3) (Low)
POKE 54273,INT(2145/256) Set voice 1 frequency (ex. 2145=C3) (High)
POKE 54279,2703-(INT(2703/256)*256) Set voice 2 frequency (ex. 2703=E3) (Low)
POKE 54280,INT(2703/256) Set voice 2 frequency (ex. 2703=E3) (High)
POKE 54286,3215-(INT(3215/256)*256) Set voice 3 frequency (ex. 3215=G3) (Low)
POKE 54287,INT(3215/256) Set voice 3 frequency (ex. 3215=G3) (High)
POKE 53295,(RESONANCE*16)+FILTER VOICE Set resonance [0..F] + filter voice number [1/2/3]
FOR N=1 TO 500:NEXT Pause
POKE 54272,0:POKE 54273,0 Stop sound, voice 1
POKE 54279,0:POKE 54280,0 Stop sound, voice 2
POKE 54286,0:POKE 54287,0 Stop sound, voice 3
FOR N=54272 TO 54296:POKE N,0:NEXT Reset sound

Sound: Table of musical notes

Note 0 1 2 3 4 5 6 7
C 268 536 1072 2145 4291 8583 17167 34334
C# 284 568 1136 2273 4547 9094 18188 36376
D 301 602 1204 2408 4817 9634 19269 38539
D# 318 637 1275 2551 5103 10207 20415 40830
E 337 675 1351 2703 5407 10814 21629 43258
F 358 716 1432 2864 5728 11457 22915 45830
F# 379 758 1517 3034 6069 12139 24278 48556
G 401 803 1607 3215 6430 12860 25721 51443
G# 425 851 1703 3406 6812 13625 27251 54502
A 451 902 1804 3608 7217 14435 28871 57743
A# 477 955 1911 3823 7647 15294 30588 61176
B 506 1012 2025 4050 8101 16293 32407 64814

Related pages of Commodore 64

Commodore 64 synth
Programming
Commodore 64 examples
Colors and formats