1- ; ************************************************************************************************
2- ; ************************************************************************************************
3- ;
4- ; Name: 04data.inc
5- ; Purpose: Main Data
6- ; Created: 18th September 2022
7- ; Reviewed: 23rd November 2022
8- ; Author: Paul Robson (paul@robsons.org.uk)
9- ;
10- ; ************************************************************************************************
11- ; ************************************************************************************************
121
13- ; ************************************************************************************************
14- ;
15- ; Mandatory Zero page code
16- ;
17- ; ************************************************************************************************
2+ ; Mandatory zero-page data
183
194 . section zeropage
205
216codePtr: ; address of current line (allow for 32 bit)
227 .fill 4
238basicStack: ; BASIC stack address
24- .fill 2
9+ .fill 2
2510zTemp0: ; temporary words used in the interpreter.
2611 .fill 2
2712zTemp1:
@@ -32,61 +17,68 @@ zsTemp: ; allocated string temporary.
3217 .fill 2
3318zaTemp: ; allocated array temporary
3419 .fill 2
35-
20+
3621safePtr = codePtr ; minimise direct tinkering
37-
38- .send zeropage
3922
40- ; ************************************************************************************************
41- ;
42- ; Preferable Zero page code
43- ;
44- ; ************************************************************************************************
23+ .send zeropage
4524
46- NSBIsNegative = $ 80 ; bit 7 : sign of mantissa (where numeric)
47- NSBIsReference = $ 20 ; bit 5 : is a reference
48- NSBIsString = $ 10 ; bit 4 : set if string (procedures don't go on the stack)
49- NSBTypeMask = $ 18 ; bits 4,3 : 00 int 01 float 10 string 11 procedure
50- NSBRefMask = $ 03 ; bits 0,1 : Bytes of reference, 00 = 4,01 = 1,10=2
51- NSBIsArray = $ 04
5225
53- NSTInteger = $ 00 ; base types for bits 3..4
54- NST Float = $ 08
55- NSTString = $ 10
56- NSTProcedure = $ 18
26+ ; Preferably zero-page data
5727
5828 . section zeropref
5929
60- ; ************************************************************************************************
61- ;
62- ; The number stack (works up from zero)
63- ;
64- ; ************************************************************************************************
30+ ; Number stack status masks
6531
32+ NSBIsNegative = $ 80 ; bit 7: sign of mantissa (where numeric)
33+ NSBIsReference = $ 20 ; bit 5: is a reference
34+ NSBIsString = $ 10 ; bit 4: set if string (procedures don't go on the stack)
35+ NSBTypeMask = $ 18 ; bits 4,3: 00 int 01 float 10 string 11 procedure
36+ NSBRefMask = $ 03 ; bits 0,1: Bytes of reference, 00 = 4,01 = 1,10=2
37+ NSBIsArray = $ 04
38+
39+ NSTInteger = $ 00 ; base types for bits 3..4
40+ NST Float = $ 08
41+ NSTString = $ 10
42+ NSTProcedure = $ 18
43+
44+ ;;
45+ ; The number stack (works up from zero)
46+ ;;
6647NSStatus: ; Status bits of stack.
6748 .fill MathStackSize
68- NSMantissa0: ; Mantissa on stack (address in 0,1 for string/reference)
69- .fill MathStackSize ; (this is my integer mantissa system)
70- NSMantissa1: ; the order of the mantissa elements is required.
49+
50+ ; 4 mantissa bytes (little-endian, 31 bits + sign)
51+ ;
52+ ; Stores an integer magnitude. Normalized non-zero mantissa always has bit 30 set.
53+ ;
54+ ; Note that on the number stack, the sign is kept in `NSStatus` (`NSBIsNegative` mask), so the
55+ ; mantissa itself only carries magnitude; when a float is written out to a variable, the sign
56+ ; bit gets packed into the top bit of the highest mantissa byte.
57+ NSMantissa0:
58+ .fill MathStackSize
59+ NSMantissa1:
7160 .fill MathStackSize
7261NSMantissa2:
7362 .fill MathStackSize
7463NSMantissa3:
7564 .fill MathStackSize
76- NSExponent: ; Exponent , 0 = Mantissa is integer
65+
66+
67+ ; a signed 8-bit base-2 exponent stored in two's complement format; 0 if mantissa is integer
68+ ;
69+ ; floating-point value = mantissa x 2^decoded exponent, where
70+ ; decoded exponent = exponent if exponent < 128 else exponent - 256
71+ NSExponent:
7772 .fill MathStackSize
7873
79- fnStackLevel: ; saved stack level for function evaluation
74+ ; saved stack level for function evaluation
75+ fnStackLevel:
8076 .fill 1
8177
8278 .send zeropref
8379
8480
85- ; ************************************************************************************************
86- ;
87- ; Non Zero Page Data
88- ;
89- ; ************************************************************************************************
81+ ; Non-zero page data
9082
9183 . section storage
9284
@@ -95,7 +87,7 @@ identStart: ; start of identifier in line buffer
9587identTypeStart: ; start of type information (#$ and ( in the line buffer)
9688 .fill 1
9789identTypeEnd: ; character after end of type information in the line buffer
98- .fill 1
90+ .fill 1
9991identHash: ; hash of identifier (including the type characters)
10092 .fill 1
10193identTypeByte: ; type descriptor in format used in identifier record
@@ -113,63 +105,63 @@ lowMemPtr: ; memory allocation after program.
113105arrayMemPtr: ; array/alloc storage pointer (slots 2-3, $4000-$7FFF)
114106 .fill 2
115107stringMemory: ; allocate concrete strings from here
116- .fill 2
117- stringInitialised: ; string
118- .fill 1
108+ .fill 2
109+ stringInitialised: ; string
110+ .fill 1
119111stringTempPointer: ; temporary string
120- .fill 2
112+ .fill 2
121113
122114breakCheck: ; break check counter/shift
123115 .fill 1
124-
116+
125117decimalPlaces: ; no of decimals.
126118 .fill 1
127119dbOffset: ; offset into decimal buffer.
128- .fill 1
120+ .fill 1
129121
130122lastParameter: ; final stack offset when all parameters handled.
131123 .fill 1
132-
124+
133125dataPointer: ; operates like code pointer for DATA statements
134126 .fill 5
135127inDataStatement: ; non zero when in data statement, e.g. pointing to data
136- .fill 1
128+ .fill 1
137129
138130tbOffset: ; offset into token buffer
139- .fill 1
131+ .fill 1
140132
141133AssemblerAddress: ; address being assembled at
142134 .fill 2
143135AssemblerControl: ; assembler control byte - bit 0 (errors ok), bit 1 (listing on)
144- .fill 1
136+ .fill 1
145137ParamStart: ; offset of parameter.
146- .fill 2
138+ .fill 2
147139IsGroup1: ; flag set if group.1
148- .fill 1
140+ .fill 1
149141BaseOpcode: ; base opcode
150- .fill 1
142+ .fill 1
151143ModeMask: ; modes allowed
152- .fill 1
144+ .fill 1
153145listIndent: ; list indent level.
154146 .fill 1
155147listElseFound: ; flag set when ELSE found on line (for indent fix)
156148 .fill 1
157149listEndToken: ; closing token for LIST proc/fn
158150 .fill 1
159151lcLastCharacter: ; last character output.
160- .fill 1
152+ .fill 1
161153isPrintFlag: ; zero if input, non-zero if print, bit 6 zero = character print
162- .fill 1
154+ .fill 1
163155currentListColour: ; current set colour when listing.
164156 .fill 1
165157;
166158; New tokenised line - these three *must* be contiguous as they are used as a single entity
167- ;
159+ ;
168160tokenOffset: ; used for tokenising - tokenised result goes here
169- .fill 1
161+ .fill 1
170162tokenLineNumber:
171- .fill 2
172- tokenBuffer:
163+ .fill 2
164+ tokenBuffer:
173165 .fill 253
174166
175167lineBuffer: ; used for input - ASCII line goes here
@@ -193,19 +185,3 @@ decimalBuffer: ; buffer for number -> string conversion.
193185 .fill 24
194186
195187 .send storage
196-
197- ; ************************************************************************************************
198- ;
199- ; Changes and Updates
200- ;
201- ; ************************************************************************************************
202- ;
203- ; Date Notes
204- ; ==== =====
205- ; 1/12/2022 Changed the recorded values used in the reference byte size which were
206- ; incorrect, no code change.
207- ; 2/12/2022 Made line buffer long again, as long lines can be entered via cross
208- ; development which would crash the interpreter.
209- ;
210- ; ************************************************************************************************
211-
0 commit comments