Documented the .SET operator that has been available for about 6 years now :-)

git-svn-id: svn://svn.cc65.org/cc65/trunk@5309 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-12-10 12:09:46 +00:00
parent 494b0619d7
commit 0d04730ddf

View file

@ -677,7 +677,7 @@ Numeric constants are defined using the equal sign or the label assignment
operator. After doing operator. After doing
<tscreen><verb> <tscreen><verb>
two = 2 two = 2
</verb></tscreen> </verb></tscreen>
may use the symbol "two" in every place where a number is expected, and it is may use the symbol "two" in every place where a number is expected, and it is
@ -686,13 +686,46 @@ almost identical, but causes the symbol to be marked as a label, so it may be
handled differently in a debugger: handled differently in a debugger:
<tscreen><verb> <tscreen><verb>
io := $d000 io := $d000
</verb></tscreen> </verb></tscreen>
The right side can of course be an expression: The right side can of course be an expression:
<tscreen><verb> <tscreen><verb>
four = two * two four = two * two
</verb></tscreen>
<label id=".SET">
<sect1>Numeric variables<p>
Within macros and other control structures (<tt><ref id=".REPEAT"
name=".REPEAT"></tt>, ...) it is sometimes useful to have some sort of
variable. This can be achieved by the <tt>.SET</tt> operator. It creates a
symbol that may get assigned a different value later:
<tscreen><verb>
four .set 4
lda #four ; Loads 4 into A
four .set 3
lda #four ; Loads 3 into A
</verb></tscreen>
Since the value of the symbol can change later, it must be possible to
evaluate it when used (no delayed evaluation as with normal symbols). So the
expression used as the value must be constant.
Following is an example for a macro that generates a different label each time
it is used. It uses the <tt><ref id=".SPRINTF" name=".SPRINTF"></tt> function
and a numeric variable named <tt>lcount</tt>.
<tscreen><verb>
.lcount .set 0 ; Initialize the counter
.macro genlab
.ident (.sprintf ("L%04X", lcount)):
lcount .set lcount + 1
.endmacro
</verb></tscreen> </verb></tscreen>
@ -731,14 +764,14 @@ You may use cheap local labels as an easy way to reuse common label
names like "Loop". Here is an example: names like "Loop". Here is an example:
<tscreen><verb> <tscreen><verb>
Clear: lda #$00 ; Global label Clear: lda #$00 ; Global label
ldy #$20 ldy #$20
@Loop: sta Mem,y ; Local label @Loop: sta Mem,y ; Local label
dey dey
bne @Loop ; Ok bne @Loop ; Ok
rts rts
Sub: ... ; New global label Sub: ... ; New global label
bne @Loop ; ERROR: Unknown identifier! bne @Loop ; ERROR: Unknown identifier!
</verb></tscreen> </verb></tscreen>
<sect1>Unnamed labels<p> <sect1>Unnamed labels<p>
@ -754,23 +787,23 @@ reference (use the n'th label in forward direction). An example will help to
understand this: understand this:
<tscreen><verb> <tscreen><verb>
: lda (ptr1),y ; #1 : lda (ptr1),y ; #1
cmp (ptr2),y cmp (ptr2),y
bne :+ ; -> #2 bne :+ ; -> #2
tax tax
beq :+++ ; -> #4 beq :+++ ; -> #4
iny iny
bne :- ; -> #1 bne :- ; -> #1
inc ptr1+1 inc ptr1+1
inc ptr2+1 inc ptr2+1
bne :- ; -> #1 bne :- ; -> #1
: bcs :+ ; #2 -> #3 : bcs :+ ; #2 -> #3
ldx #$FF ldx #$FF
rts rts
: ldx #$01 ; #3 : ldx #$01 ; #3
: rts ; #4 : rts ; #4
</verb></tscreen> </verb></tscreen>
As you can see from the example, unnamed labels will make even short As you can see from the example, unnamed labels will make even short
@ -792,15 +825,15 @@ possible with the other symbol types).
Example: Example:
<tscreen><verb> <tscreen><verb>
.DEFINE two 2 .DEFINE two 2
.DEFINE version "SOS V2.3" .DEFINE version "SOS V2.3"
four = two * two ; Ok four = two * two ; Ok
.byte version ; Ok .byte version ; Ok
.PROC ; Start local scope .PROC ; Start local scope
two = 3 ; Will give "2 = 3" - invalid! two = 3 ; Will give "2 = 3" - invalid!
.ENDPROC .ENDPROC
</verb></tscreen> </verb></tscreen>
@ -3079,7 +3112,7 @@ Here's a list of all control commands and a description, what they do:
<sect1><tt>.MACPACK</tt><label id=".MACPACK"><p> <sect1><tt>.MACPACK</tt><label id=".MACPACK"><p>
Insert a predefined macro package. The command is followed by an Insert a predefined macro package. The command is followed by an
identifier specifying the macro package to insert. Available macro identifier specifying the macro package to insert. Available macro
packages are: packages are: