mirror of
https://github.com/RevCurtisP/C02.git
synced 2024-06-15 07:29:29 +00:00
Updated general documentation
This commit is contained in:
parent
976dd4cf44
commit
90196f8762
20
doc/c02.txt
20
doc/c02.txt
|
@ -398,7 +398,7 @@ the form of an = character and literal after the variable name.
|
||||||
A const array may be declared in one of two ways: the variable name
|
A const array may be declared in one of two ways: the variable name
|
||||||
suffixed with a [ character, a literal specifying the upper bound of
|
suffixed with a [ character, a literal specifying the upper bound of
|
||||||
the array, and a ] character; or a variable name followed by an = character
|
the array, and a ] character; or a variable name followed by an = character
|
||||||
and string literal or series of atring and numeric literals separated by
|
and string literal or series of atring and/or numeric literals separated by
|
||||||
commas and surrounded by the { or } characters.
|
commas and surrounded by the { or } characters.
|
||||||
|
|
||||||
The zeropage modifier specifies that the variable will be defined in page
|
The zeropage modifier specifies that the variable will be defined in page
|
||||||
|
@ -406,15 +406,17 @@ zero (addresses 0 through 255). It should be used in conjunction with the
|
||||||
pragma zeropage directive.
|
pragma zeropage directive.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
alias char putcon = $F001; //Defines variable putcon with address $F001
|
alias char putcon = $F001; //Defines variable putcon with address $F001
|
||||||
alias char alpha = omega; //Defines variable alpha aliased to omega
|
alias char alpha = omega; //Defines variable alpha aliased to omega
|
||||||
aligned char table[240]; //Defines 241 byte array aligned to page boundary
|
aligned char table[240]; //Defines 241 byte array aligned to page boundary
|
||||||
const char debug = #TRUE; //Defines variable debug initialized to constant
|
const char debug = #TRUE; //Defines variable debug initialized to constant
|
||||||
const char flag = 1; //Defines variable flag initialized to 1
|
const char flag = 1; //Defines variable flag initialized to 1
|
||||||
const char s = "string"; //Defines 7 byte string s initialized to "string"
|
const char s = "string"; //Defines 7 byte string s initialized to "string"
|
||||||
const char m = {1,2,3}; //Defines 3 byte array m containing 1, 2, and 3
|
const char n = {1,2,3}; //Defines 3 byte array m containing 1, 2, and 3
|
||||||
|
const char m = {"abc", 123); //Defines 5 byte array containing string and byte
|
||||||
|
const char t = {"ab", "cd"); //Defines 6 byte array of two strings
|
||||||
aligned const char fbncci[] = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34};
|
aligned const char fbncci[] = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34};
|
||||||
zeropage char ptr, tmp; //Defines zero page variables
|
zeropage char ptr, tmp; //Defines zero page variables
|
||||||
|
|
||||||
EXPRESSIONS
|
EXPRESSIONS
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,7 @@ Likewise if a 16-bit integer variable type was added to C02,
|
||||||
then one could be assigned to the other using the exact same
|
then one could be assigned to the other using the exact same
|
||||||
assembly code.
|
assembly code.
|
||||||
|
|
||||||
A derefenced pointer can be used anywhere an array references
|
A dereferenced pointer can be used anywhere an array references
|
||||||
is allowed and would be subject to the same restrictions.
|
is allowed and would be subject to the same restrictions.
|
||||||
|
|
||||||
A raw pointer used as an argument to a function will be passed
|
A raw pointer used as an argument to a function will be passed
|
||||||
|
@ -198,10 +198,10 @@ For the declarations
|
||||||
|
|
||||||
references to the members of the struct REC will generate the code:
|
references to the members of the struct REC will generate the code:
|
||||||
|
|
||||||
XXA REC+$09 ;REC.INDEX
|
XXX REC+$09 ;REC.INDEX
|
||||||
|
|
||||||
LDX I ;REC.DATA[I]
|
LDX I ;REC.DATA[I]
|
||||||
XXA REC+$0A,X
|
XXX REC+$0A,X
|
||||||
|
|
||||||
Using the address of operator on a struct member generates assembly
|
Using the address of operator on a struct member generates assembly
|
||||||
code with parentherical expressions, which are not recognized by all
|
code with parentherical expressions, which are not recognized by all
|
||||||
|
@ -214,13 +214,13 @@ assemblers:
|
||||||
The compiler could optimize the generation of code for references
|
The compiler could optimize the generation of code for references
|
||||||
to the first member of a struct, producing
|
to the first member of a struct, producing
|
||||||
|
|
||||||
XXA REC ;REC.NAME
|
XXX REC ;REC.NAME
|
||||||
|
|
||||||
instead of
|
instead of
|
||||||
|
|
||||||
XXA REC+$00 ;REC.NAME
|
XXX REC+$00 ;REC.NAME
|
||||||
|
|
||||||
but the machine code produced by the assembler should be indentical
|
but the machine code produced by the assembler should be identical
|
||||||
in either case.
|
in either case.
|
||||||
|
|
||||||
|
|
||||||
|
@ -233,19 +233,19 @@ Array Indexes
|
||||||
Array indexing normally uses the X register and indexed addressing mode:
|
Array indexing normally uses the X register and indexed addressing mode:
|
||||||
|
|
||||||
LDX I ;R[I]
|
LDX I ;R[I]
|
||||||
XXA R,X
|
XXX R,X
|
||||||
|
|
||||||
If the index is a constant or literal, absolute addressing is used:
|
If the index is a constant or literal, absolute addressing is used:
|
||||||
|
|
||||||
LDA R+1 ;R[1]
|
LDA R+1 ;R[1]
|
||||||
XXA S+0 ;S[0]
|
XXX S+0 ;S[0]
|
||||||
|
|
||||||
Specifying a register as the index also uses indexed addressing mode:
|
Specifying a register as the index also uses indexed addressing mode:
|
||||||
|
|
||||||
TAX ;R[A]
|
TAX ;R[A]
|
||||||
XXA R,X
|
XXX R,X
|
||||||
XXA R,Y ;R[Y]
|
XXX R,Y ;R[Y]
|
||||||
XXA R,X ;R[X]
|
XXX R,X ;R[X]
|
||||||
|
|
||||||
Allowing for an expression as the index in the first term of an
|
Allowing for an expression as the index in the first term of an
|
||||||
expression uses only one extra byte of code and two machine cycles:
|
expression uses only one extra byte of code and two machine cycles:
|
||||||
|
@ -261,7 +261,7 @@ and ten machine cycles:
|
||||||
expr code ;code to evaluate the expression
|
expr code ;code to evaluate the expression
|
||||||
TAX
|
TAX
|
||||||
PLA
|
PLA
|
||||||
XXA R,X
|
XXX R,X
|
||||||
|
|
||||||
compared to the extra four to six bytes and six to eight machine cycles
|
compared to the extra four to six bytes and six to eight machine cycles
|
||||||
used by the equivalent C02 code required to achieve the same result:
|
used by the equivalent C02 code required to achieve the same result:
|
||||||
|
@ -269,7 +269,7 @@ used by the equivalent C02 code required to achieve the same result:
|
||||||
expr code ;Z = expr
|
expr code ;Z = expr
|
||||||
STA Z
|
STA Z
|
||||||
LDX Z ;R[Z]
|
LDX Z ;R[Z]
|
||||||
XXA R,X
|
XXX R,X
|
||||||
|
|
||||||
Function Calls
|
Function Calls
|
||||||
--------------
|
--------------
|
||||||
|
@ -348,20 +348,20 @@ withing an expression:
|
||||||
|
|
||||||
DEC I ;R[--I]
|
DEC I ;R[--I]
|
||||||
LDX I
|
LDX I
|
||||||
XXA R,X
|
XXX R,X
|
||||||
|
|
||||||
LDX I ;R[I++]
|
LDX I ;R[I++]
|
||||||
XXA R,X
|
XXX R,X
|
||||||
INC I
|
INC I
|
||||||
|
|
||||||
Is indentical to the code generated when using a standalone post-operator;
|
Is indentical to the code generated when using a standalone post-operator;
|
||||||
|
|
||||||
DEC I ;I--
|
DEC I ;I--
|
||||||
LDX I ;R[I]
|
LDX I ;R[I]
|
||||||
XXA R,X
|
XXX R,X
|
||||||
|
|
||||||
LDX I ;R[I]
|
LDX I ;R[I]
|
||||||
XXA R,X
|
XXX R,X
|
||||||
INC I ;I++
|
INC I ;I++
|
||||||
|
|
||||||
Assignments
|
Assignments
|
||||||
|
@ -449,7 +449,7 @@ and works with all three variables of a plural assignment.
|
||||||
Conditionals
|
Conditionals
|
||||||
============
|
============
|
||||||
|
|
||||||
Conditionals are separate and distinct from expessions, due to the fact
|
Conditionals are separate and distinct from expressions, due to the fact
|
||||||
that the comparison operators all set status flags which affect the various
|
that the comparison operators all set status flags which affect the various
|
||||||
branch instructions:
|
branch instructions:
|
||||||
|
|
||||||
|
@ -458,11 +458,22 @@ branch instructions:
|
||||||
Reg = Data BEQ BNE
|
Reg = Data BEQ BNE
|
||||||
Reg ≥ Data BCS BCC
|
Reg ≥ Data BCS BCC
|
||||||
Reg ≠ Data BNE BEQ
|
Reg ≠ Data BNE BEQ
|
||||||
|
|
||||||
|
The remaining operators can be implemented with CLC and SBC, but this will
|
||||||
|
change the value in the accumulator.
|
||||||
|
|
||||||
CLC:SBC DATA Normal Inverted
|
CLC:SBC DATA Normal Inverted
|
||||||
Reg ≤ Data BCC BCS
|
Reg ≤ Data BCC BCS
|
||||||
Reg > Data BCS BCC
|
Reg > Data BCS BCC
|
||||||
|
|
||||||
|
Or they could be implemented using multiple branch instructions. This would
|
||||||
|
leave the value of the left side expression in the accumulator, but use one
|
||||||
|
more byte of code and require and extra label.
|
||||||
|
|
||||||
|
CMP DATA Normal Inverted
|
||||||
|
Reg ≤ Data BEQ exec:BCC exec BNE exec:BCS exec
|
||||||
|
Reg > Data BEQ skip:BCS exec BNE skip:BCC exec
|
||||||
|
|
||||||
When compiling a comparison, the generated code will usually, but not
|
When compiling a comparison, the generated code will usually, but not
|
||||||
always, branch when the condition is false, skipping to the end of the
|
always, branch when the condition is false, skipping to the end of the
|
||||||
block of code following the comparison. In addition, the logical not
|
block of code following the comparison. In addition, the logical not
|
||||||
|
@ -491,16 +502,16 @@ Logical Operators
|
||||||
Parsing the logical operators && and || is trivial if the preceding
|
Parsing the logical operators && and || is trivial if the preceding
|
||||||
condition is a comparison or flag operation, since any expression
|
condition is a comparison or flag operation, since any expression
|
||||||
evaluation is complete before the parse encounters the initial & or |
|
evaluation is complete before the parse encounters the initial & or |
|
||||||
character. For a standalone evaluation of an expression as true or\
|
character. For a standalone evaluation of an expression as true or
|
||||||
false, however, the expression evaluator will mistake the initial
|
false, however, the expression evaluator will mistake the initial
|
||||||
character of the && or || as a bitwise operator. Differentiating
|
character of the && or || as a bitwise operator. Differentiating
|
||||||
the two would require changing to a look-ahead parser.
|
the two would require changing to a look-ahead parser.
|
||||||
|
|
||||||
One solution is to enclose require parenthises around each comparison
|
One solution is to enclose require parentheses around each comparison
|
||||||
when using logical operators, which is allowable in C syntax, but
|
when using logical operators, which is allowable in C syntax, but
|
||||||
it's just as easy, and arguably cleaner looking, to use the words
|
it's just as easy, and arguably cleaner looking, to use the words
|
||||||
"and" and "or" instead. This is be allowble in standard C by using
|
"and" and "or" instead. This is allowable in standard C by using
|
||||||
the @define directive to alias "and" to "&&" and "or" to "||".
|
the #define directive to alias "and" to "&&" and "or" to "||".
|
||||||
|
|
||||||
The most efficient way to implement logical operators is to use shortcut
|
The most efficient way to implement logical operators is to use shortcut
|
||||||
evaluations.
|
evaluations.
|
||||||
|
@ -528,4 +539,5 @@ first comparison was false.
|
||||||
block
|
block
|
||||||
|
|
||||||
When chaining multiple && and/or || operators, the shortcut evaluation
|
When chaining multiple && and/or || operators, the shortcut evaluation
|
||||||
effectively make them right-associative.
|
effectively make them right-associative.
|
||||||
|
|
||||||
|
|
|
@ -42,11 +42,6 @@ module. The available modules are as follows:
|
||||||
Contains functions for writing formatted data to the
|
Contains functions for writing formatted data to the
|
||||||
screen, including decimal and hexadecimal numbers.
|
screen, including decimal and hexadecimal numbers.
|
||||||
|
|
||||||
memio Memory Input/Ouput
|
|
||||||
|
|
||||||
Provides functions to simulate reading and writing to
|
|
||||||
a section of memory as though it were a file.
|
|
||||||
|
|
||||||
string String functions
|
string String functions
|
||||||
|
|
||||||
Contains functions for copying, searching, comparing,
|
Contains functions for copying, searching, comparing,
|
||||||
|
@ -68,7 +63,18 @@ module. The available modules are as follows:
|
||||||
for fixed length segments of data to an arbitrarily large
|
for fixed length segments of data to an arbitrarily large
|
||||||
section of memory.
|
section of memory.
|
||||||
|
|
||||||
Stack Stack functions
|
stack Stack functions
|
||||||
|
|
||||||
Contains functions for pushing and popping variable
|
Contains functions for pushing and popping variable
|
||||||
length segments of data onto and off of a stack in memory.
|
length segments of data onto and off of a stack in memory.
|
||||||
|
|
||||||
|
memio Memory Input/Ouput
|
||||||
|
|
||||||
|
Provides functions to simulate reading and writing to
|
||||||
|
a section of memory as though it were a file.
|
||||||
|
|
||||||
|
fileio File Input/Ouput
|
||||||
|
|
||||||
|
Provides functions to access, read from, and write to
|
||||||
|
files on cassette and/or disk.
|
||||||
|
|
||||||
|
|
BIN
doc/quickref.odt
BIN
doc/quickref.odt
Binary file not shown.
Loading…
Reference in New Issue
Block a user