mirror of
https://github.com/RevCurtisP/C02.git
synced 2024-11-25 21:33:44 +00:00
122 lines
4.9 KiB
Plaintext
122 lines
4.9 KiB
Plaintext
C02 for C programmers
|
|
|
|
TYPES
|
|
|
|
C02 only supports one data type: unsigned char.
|
|
|
|
POINTERS
|
|
|
|
C02 does not support pointer type variables or parameters. However, the
|
|
address-of operator may be used in function calls and the inline
|
|
statement.
|
|
|
|
DIRECTIVES
|
|
|
|
C02 does not use a preprocessor. All directives are directly processed
|
|
by the compiler. C02 supports the directives #include and #pragma. The
|
|
directive #define is currently unimplemented and generates an error.
|
|
The #if, #else, and #endif directives are not recognized by C02.
|
|
|
|
CONSTANTS
|
|
|
|
The syntax of the const keyword in C02 differs from that use in standard C.
|
|
In C02, all constant names are prefixed with a # symbol.
|
|
|
|
ENUMERATION
|
|
|
|
The syntax of an enum statement in C02 is similar to standard C, except
|
|
that no type name is specified and values may not be explicitly assigned
|
|
to the enumerated constants.
|
|
|
|
DECLARATIONS
|
|
|
|
Variable and function names may be no more than six characters in length.
|
|
Multiple variable declarations separated by commas are allowed.
|
|
|
|
A variable in a declaration may be initialized by following it with an
|
|
equal sign and a constant, however this declaration is done at compile
|
|
time, so no re-initialization will occur during code execution.
|
|
|
|
Array declarations using bracket syntax specify the upper bound, rather
|
|
than the array size. Therefore, the array will be allocated with one more
|
|
element than the specified number.
|
|
|
|
Only one-dimensional arrays of type char are allowed and are limited to
|
|
a total of 256 elements. Multi-dimensional arrays, arrays of arrays, and
|
|
arrays of structs are not supported.
|
|
|
|
Struct definition and syntax is similar to standard C. When defining a
|
|
struct, the char keyword is optional, since char the char type is implied.
|
|
Struct members may only be simple variables or arrays. The maximum total
|
|
size of a struct is 256 bytes. Initialization of members during declaration
|
|
of a struct variable is not supported.
|
|
|
|
REGISTERS
|
|
|
|
The 6502 registers may be explicitly referenced by name, i.e. A, X, and Y.
|
|
These may only be used in specific places due to the nature of the compiled
|
|
code a well as the limitations of the 6502 instruction set.
|
|
|
|
EXPRESSIONS
|
|
|
|
C02 supports the addition, subtraction, bitwise-and, bitwise-or, and
|
|
exclusive-or operators. The multiplication, division, and binary shift
|
|
operators are not supported. These can be implemented through functions.
|
|
|
|
Unary minus may only be used at the beginning of an expression, in which
|
|
case it is treated as a literal 0 and the subtraction operater, and the
|
|
term following the minus is used as the second term of the expression.
|
|
|
|
Functions calls may only be used in the first term of an expression.
|
|
However, the first argument of any function call may be any expression
|
|
(including one with a function call as the first term).
|
|
|
|
As in standard C, subscripted array elements may be used in any term of
|
|
an exptression and the index may be any expression (including one with
|
|
a function call as the first term).
|
|
|
|
The sizeof operator in C02 is the at sign @. It may only be used with
|
|
declared variables and struct members, not types.
|
|
|
|
CONDITIONALS
|
|
|
|
Conditional operations, including comparisons and logical operators,
|
|
may not be used within or in place of normal expressions, and are only
|
|
allowed in if, while, and for statements, as well as shortcut-ifs.
|
|
|
|
The comparison operators are ==, <, <=, >=, >, and <>. Unlike standard
|
|
C, the not-equals operator is <> instead of !=. In addition, = may be
|
|
substituted for ==. The logical not operator ! negates an entire
|
|
comparison rather than an individual term within the comparison, thus
|
|
the C02 code !b<x is equivalent to the C code !(b<x).
|
|
|
|
C02 uses the logical operators "and" and "or" instead of "&&" and "||",
|
|
and performs short-circuit evaluation of logical operators, making them
|
|
effectively right associative.
|
|
|
|
FUNCTIONS
|
|
|
|
Parameter passing uses the 6502's A, Y, and X registers. This limits
|
|
function calls to a maximum of three char variables or address reference
|
|
plus and optional char variable. However this also allows the return
|
|
of up to three char variables (see assignments below). However, the
|
|
non-standard push and pop statements allow explicit parameter passing
|
|
via the stack, and the inline keyword has been re-purposed to allow
|
|
explicit passing of inline parameters.
|
|
|
|
ASSIGNMENTS
|
|
|
|
Unlike standard C, struct contents may not be copied via simple assignment.
|
|
Struct variables may be copied byte by byte or using memory move functions.
|
|
|
|
Up to three comma-separated variables may be specified on the left side of
|
|
the = assignment operator. This is generally only useful when the expression
|
|
contains a function with multiple return values.
|
|
|
|
|
|
STATEMENTS
|
|
|
|
Instead of the switch statement, C02 uses the select statement. The
|
|
select statement works almost identically to the switch statement except
|
|
that case blocks do not fall through.
|