Skip to content

Commit 6a8528e

Browse files
committed
chore: document VariableHandler
1 parent fab3210 commit 6a8528e

1 file changed

Lines changed: 30 additions & 35 deletions

File tree

source/common/expressions/term/variable.asm

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1-
; ************************************************************************************************
2-
; ************************************************************************************************
3-
;
4-
; Name: variable.asm
5-
; Purpose: Variable handler
6-
; Created: 30th September 2022
7-
; Reviewed: 28th November 2022
8-
; Author: Paul Robson (paul@robsons.org.uk)
9-
;
10-
; ************************************************************************************************
11-
; ************************************************************************************************
1+
;;
2+
; Variable term parsing and array access logic
3+
;;
124

135
.section code
146

15-
; ************************************************************************************************
7+
;;
8+
; Parse a variable term into a number-stack reference.
169
;
17-
; Variable handler
10+
; Reads the encoded variable reference at the current token position, resolves
11+
; the variable record address in `VariableSpace`, and constructs a reference
12+
; value in the current number-stack slot. Scalar variables return immediately as
13+
; references to their stored data; array references dispatch to the array
14+
; access logic, which also handles function-call syntax for procedure arrays.
1815
;
19-
; ************************************************************************************************
16+
; \in X Number-stack slot to receive the variable reference.
17+
; \in Y Parsing position at the encoded variable token.
18+
; \out Y Advanced past the encoded variable reference.
19+
; \out NSMantissa[0..3],x Reference payload pointing at the variable data.
20+
; \out NSExponent,x Cleared for the constructed reference.
21+
; \out NSStatus,x Variable base type with `NSBIsReference` set; array
22+
; variables also retain the array flag.
23+
; \sideeffects - Uses `zTemp0` as a pointer to the variable record.
24+
; - Reads the variable type byte from the record metadata.
25+
; - May dispatch to array indexing or `FunctionCall` handling
26+
; for array/procedure references.
27+
; - Modifies registers `A` and `Y`.
28+
; \see FunctionCall, Evaluate8BitInteger, CheckRightBracket
29+
;;
2030

2131
VariableHandler:
2232
.cget ; copy variable address to zTemp0
23-
clc
33+
clc
2434
adc #((VariableSpace >> 8) - $40) & $FF
2535
sta zTemp0+1
2636
iny
@@ -87,7 +97,7 @@ _VHNoSecondIndex:
8797
;
8898
; So at this point S[X] refers to the array record S[X+1] the 1st index, and S[X+2] the second
8999
; Status[X+2] is $FF if there was only one array index, $00 if there were two.
90-
;
100+
;
91101
; -----------------------------------------------------------------------------------------------------
92102
;
93103
; So first check if the number of indices match
@@ -118,15 +128,15 @@ _VHHas2Mask: ; so we are now 0 if there is 1 index, and $FF if there is
118128
;
119129
; Second index
120130
;
121-
ldy #3 ; check the 2nd size >= 2nd index
131+
ldy #3 ; check the 2nd size >= 2nd index
122132
lda (zaTemp),y
123133
cmp NSMantissa0+2,x
124134
bcc _VHBadIndex
125135
;
126136
; First index
127137
;
128138
_VHCheckFirstIndex:
129-
ldy #2 ; check the 2nd size >= 2nd index
139+
ldy #2 ; check the 2nd size >= 2nd index
130140
lda (zaTemp),y
131141
cmp NSMantissa0+1,x
132142
bcc _VHBadIndex
@@ -146,7 +156,7 @@ _VHCheckFirstIndex:
146156
ldy #2 ; get 1st size in A
147157
lda (zaTemp),y
148158
inc a ; add 1 for zero base
149-
plx
159+
plx
150160
jsr Multiply8x8 ; calculate -> Z0
151161
plx
152162
_VHNoMultiply:
@@ -161,7 +171,7 @@ _VHNoMultiply:
161171
adc #0
162172
sta zTemp0+1
163173
;
164-
; Get the type (from Status,0) and use it to scale up
174+
; Get the type (from Status,0) and use it to scale up
165175
;
166176
lda NSStatus,x
167177
jsr ScaleByBaseType
@@ -187,18 +197,3 @@ _VHBadArray:
187197
.error_arraydec
188198

189199
.send code
190-
191-
; ************************************************************************************************
192-
;
193-
; Changes and Updates
194-
;
195-
; ************************************************************************************************
196-
;
197-
; Date Notes
198-
; ==== =====
199-
; 06/12/22 Added array not declared error.
200-
; 06/12/22 At the check of indices match, around line 87, the copy into zaTemp was
201-
; done *before* zaTemp was initialised,so it checked the last assigned value.
202-
; Swapped round. Would only be picked up with uninitialised arrays.
203-
;
204-
; ************************************************************************************************

0 commit comments

Comments
 (0)