Skip to content

mad4j/c64-the-basics-of-BASIC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

The basics of BASIC

Introduction to CBM BASIC

by Daniele Olmisani and the contributions of @JaganGanesh

Please, see LICENSE file.

Hello World!

PRINT "HELLOWORLD!"

Simple Arithmetic

PRINT 3+3, 3-3, 3*3, 3/3, 3^3

Operator are evaluated left-to-right with this predence order: ^, */, +-.

PRINT 9*8+7+6^5/4-3-2+1

Math Functions

ABS

ABS evaluates to the absolute value (value without the sign) of the given numeric term.

PRINT ABS(-10)

Built-in Functions

Square function and natural logarithm with the basis E

PRINT SQR(4), 4*4
PRINT LOG(1), LOG(100)/LOG(10)

Build-in Constants

Pi value

PRINT {PI}

Logic operations

Equality operators =, <>, >, >.

PRINT 1=1, 1=0, 1<>1, 1<>0
PRINT 1>0, 1<0

True and False values are represented by numeric values -1 and 0.

Built-in operators AND, OR and NOT.

PRINT 0 AND 0, -1 AND 0, 0 AND -1=1, -1 AND -1
PRINT 0 OR 0, -1 OR 0, 0 OR -1=1, -1 OR -1
PRINT NOT 0, NOT -1

XOR operator is not included but it shall be derived using formula (p|q) & ~(p&q).

10 PRINT "P", "Q", "P XOR Q"
20 FOR P=0 TO 1
30 FOR Q=0 TO 1
40 : PRINT P, Q, (P OR Q) AND NOT(P AND Q)
50 NEXT Q
60 NEXT P

FOR-NEXT Loop

10 FOR I = 1 TO 4
20 PRINT "HELLOWORLD!"
30 NEXT I

INPUT Variables

10 DIM A$(1)
20 PRINT "PRESS RETURN TO CONTINUE"
30 INPUT A$
10 DIM N$(40)
20 PRINT "WHAT IS YOUR NAME: ";
30 INPUT N$
40 PRINT "HELLO, "; N$

IF Condition

10 DIM A$(4)
20 PRINT "DO YOU LIKE C64: ";
30 INPUT A$
40 IF A$ = "YES" THEN 60
50 END
60 PRINT "GREAT!"
70 GOTO 50

Random Numbers

10 PRINT RND(1)
10 PRINT INT(10*RND(1) + 1)

GOSUB

10  PRINT "HELLO"
20  GOSUB 100
30  END
100 PRINT "WORLD"
110 RETURN

Releases

No releases published

Packages

No packages published