0% found this document useful (0 votes)
2 views4 pages

Commodore64 Basic Reference Expanded

Commodore 64 BASIC is a version of the BASIC programming language designed for the Commodore 64, featuring commands for loading, saving, and executing programs, as well as control structures and functions. It includes a memory map, graphics and sound capabilities, error codes, and examples of usage. The document also covers keyboard scan codes, color codes, and token abbreviations for efficient coding.

Uploaded by

kaziczusiek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Commodore64 Basic Reference Expanded

Commodore 64 BASIC is a version of the BASIC programming language designed for the Commodore 64, featuring commands for loading, saving, and executing programs, as well as control structures and functions. It includes a memory map, graphics and sound capabilities, error codes, and examples of usage. The document also covers keyboard scan codes, color codes, and token abbreviations for efficient coding.

Uploaded by

kaziczusiek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

INTRODUCTION

============

Commodore 64 BASIC (Beginner's All-purpose Symbolic Instruction Code) is a dialect


of the BASIC programming language.
It is based on Microsoft BASIC and includes a set of instructions for writing
programs on the C64.

Version: BASIC V2
Memory available: ~38911 bytes

COMMANDS
========

- LOAD "filename",8 ; Load from disk drive


- SAVE "filename",8 ; Save to disk
- LIST ; Show current program
- RUN ; Execute the loaded BASIC program
- NEW ; Clear current program from memory
- CONT ; Continue a program after STOP
- CLR ; Clear variables
- SYS address ; Jump to machine code at specified address
- POKE addr, value ; Write value to memory address
- PEEK(addr) ; Read value from memory address

CONTROL STRUCTURES
==================

- IF condition THEN statement


Example: IF X > 10 THEN PRINT "Too big!"

- FOR var = start TO end [STEP increment]


Example: FOR I = 1 TO 10 : PRINT I : NEXT I

- GOTO line_number
- GOSUB line_number / RETURN

- ON expr GOTO line1, line2, ...


Example: ON X GOTO 100, 200, 300

FUNCTIONS
=========

- RND(x) ; Return pseudo-random number


- ABS(x) ; Absolute value
- INT(x) ; Truncate to integer
- SGN(x) ; Sign of number
- LEN(string) ; Length of string
- LEFT$(str,n) ; Left n chars of string
- MID$(str,start,n) ; Middle part of string
- RIGHT$(str,n) ; Right n chars
- CHR$(code) ; Return character
- ASC(char) ; Return ASCII code

INPUT/OUTPUT
============

- INPUT var
- PRINT expr
Example: PRINT "HELLO WORLD"

- GET var
Example: GET A$ ; Read a single character into A$

EXAMPLES
========

10 PRINT "HELLO WORLD"


20 INPUT "WHAT IS YOUR NAME";N$
30 PRINT "HELLO ";N$
40 FOR I=1 TO 5: PRINT I: NEXT I
50 POKE 53280,0 : REM SET BORDER COLOR TO BLACK

ERROR CODES
===========

?SYNTAX ERROR ; Typing mistake or illegal syntax


?OUT OF MEMORY ERROR ; Not enough RAM
?TYPE MISMATCH ERROR ; Wrong variable type used
?UNDEF'D STATEMENT ; GOTO to a line that doesn't exist

MEMORY MAP
==========

Commodore 64 Memory Map (partial overview):


0000-00FF Zero Page
0100-01FF Stack
0200-03FF Screen Editor Buffer
0400-07FF Screen RAM (default: 1024)
0800-9FFF BASIC Program/Text
A000-BFFF BASIC ROM
C000-CFFF Free for machine code
D000-DFFF I/O Area (VIC-II, SID, CIA)
E000-FFFF Kernal ROM

GRAPHICS & SPRITES


==================

VIC-II Graphics Chip:

Screen Resolution: 320x200 (hi-res), 160x200 (multicolor)


Colors: 16 fixed
Screen RAM starts at $0400 (default)
Color RAM: $D800 - $DBE7

SPRITES:
- 8 hardware sprites
- Each sprite is 24x21 pixels
- Enable: POKE 53269,1 for sprite 0
- X/Y position: POKE 53248 + N*2, X : POKE 53249 + N*2, Y
- Multicolor: POKE 53276,1

SOUND & SID CHIP


================

SID (Sound Interface Device) at $D400

Voice 1:
- Frequency Low: 54272 ($D400)
- Frequency High: 54273 ($D401)
- Waveform Control: 54276 ($D404)
- Attack/Decay: 54277 ($D405)
- Sustain/Release: 54278 ($D406)

Example:
POKE 54296,15 ; Volume = max
POKE 54272,100 ; Set frequency low byte
POKE 54273,0 ; Set frequency high byte
POKE 54276,17 ; Triangle waveform + Gate on

To silence: POKE 54276,0

DISK/TAPE I/O
=============

Disk Commands (with device 8):


- LOAD "PROGRAM",8
- SAVE "PROGRAM",8
- OPEN15,8,15,"I" ; Initialize drive
- PRINT#15,"S0:FILE" ; Scratch file
- CLOSE15

Tape:
- LOAD and SAVE work without specifying device
- Tape counter and motor control not programmable

USR FUNCTION AND MACHINE CODE


=============================

USR Function:
You can define USR(x) to call a machine code routine.

Example:
POKE 785,0 : POKE 786,2 : POKE 787,0 ; Set USR pointer to 512
POKE 512,96 ; RTS instruction at $0200
PRINT USR(0) ; Call the routine

You can embed your own machine code starting at 512 (or other locations).

KEYBOARD SCAN CODES


===================

Each row of the keyboard matrix is mapped to a specific bit in a CIA port.

Example:
- Row 0 (Ctrl, 1, Q, etc.): POKE 56320,254 : PRINT PEEK(56321)
- You can detect keypresses by scanning each row with POKE/PEEK.

COLOR CODES
===========

0 - Black 8 - Orange
1 - White 9 - Brown
2 - Red 10 - Light red
3 - Cyan 11 - Dark grey
4 - Purple 12 - Grey
5 - Green 13 - Light green
6 - Blue 14 - Light blue
7 - Yellow 15 - Light grey

To set border color: POKE 53280, color


To set background: POKE 53281, color

TOKENS AND ABBREVIATIONS


========================

BASIC keywords can be shortened:


- PR. = PRINT
- G. = GOTO
- L. = LIST

Each keyword is stored as a single byte token internally:


PRINT = $99, IF = $89, FOR = $81, etc.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy