git @ Cat's Eye Technologies SixtyPical / 2f513f7
Initial support for initializing byte tables with list of bytes. Chris Pressey 4 years ago
4 changed file(s) with 42 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
121121 elif type_ == TYPE_WORD:
122122 initial_data = Word(defn.initial)
123123 elif TableType.is_a_table_type(type_, TYPE_BYTE):
124 # FIXME convert defn.initial to a serializable type ... or when parsing.
124125 initial_data = Table(defn.initial, type_.size)
125126 else:
126127 raise NotImplementedError(type_)
137137
138138 initial = None
139139 if self.scanner.consume(':'):
140 if isinstance(type_, TableType) and self.scanner.on_type('string literal'):
141 initial = self.scanner.token
142 self.scanner.scan()
140 if isinstance(type_, TableType):
141 if self.scanner.on_type('string literal'):
142 initial = self.scanner.token
143 self.scanner.scan()
144 else:
145 initial = []
146 initial.append(self.const())
147 while self.scanner.consume(','):
148 initial.append(self.const())
143149 else:
144150 initial = self.const().value
145151
161161 = $081A .byte $BB
162162 = $081B .byte $0B
163163
164 Initialized byte table. Bytes allocated, but beyond the string, are 0's.
164 Initialized byte table, initialized with ASCII string. Bytes allocated, but beyond the string, are 0's.
165165
166166 | byte table[8] message : "WHAT?"
167 |
168 | routine main
169 | inputs message
170 | outputs x, a, z, n
171 | {
172 | ld x, 0
173 | ld a, message + x
174 | }
175 = $080D LDX #$00
176 = $080F LDA $0813,X
177 = $0812 RTS
178 = $0813 .byte $57
179 = $0814 PHA
180 = $0815 EOR ($54,X)
181 = $0817 .byte $3F
182 = $0818 BRK
183 = $0819 BRK
184 = $081A BRK
185
186 Initialized byte table, initialized with list of byte values.
187
188 | byte table[8] message : 255, 0, 129, 128, 127
167189 |
168190 | routine main
169191 | inputs message
301301 | }
302302 = ok
303303
304 Initialized byte table.
304 Initialized byte table, initialized with ASCII string.
305305
306306 | byte table[32] message : "WHAT DO YOU WANT TO DO NEXT?"
307307 |
316316 | routine main {
317317 | }
318318 ? SyntaxError
319
320 Initialized byte table, initialized with list of bytes.
321
322 | byte table[8] charmap : 0, 255, 129, 192, 0, 1, 2, 4
323 |
324 | routine main {
325 | }
326 = ok
319327
320328 Can't access an undeclared memory location.
321329