git @ Cat's Eye Technologies SixtyPical / f92e1f1
Tired: copy [ptr]+y, a. Wired: ld a, [ptr]+y. Chris Pressey 3 years ago
6 changed file(s) with 40 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
00 History of SixtyPical
11 =====================
2
3 0.12
4 ----
5
6 * `copy` is now understood to trash `a`, thus `copy ..., a` is not valid.
7 Indirect addressing is supported in `ld`, as in `ld a, [ptr] + y`, to compensate.
28
39 0.11
410 ----
147147 LDA ($02), Y
148148 STA ($02), Y
149149
150 There are extended modes of `copy` for using these types of memory location.
150 There are extended instruction modes for using these types of memory location.
151151 See `copy` below, but here is some illustrative example code:
152152
153153 copy ^buf, ptr // this is the only way to initialize a pointer
236236
237237 Some combinations, such as `ld x, y`, are illegal because they do not map to
238238 underlying opcodes.
239
240 There is another mode of `ld` which reads into `a` indirectly through a pointer.
241
242 copy [<src-memory-location>] + y, <dest-memory-location>
243
244 The memory location in this syntax must be a pointer.
245
246 This syntax copies the contents of memory at the pointer (offset by the `y`
247 register) into a register (which must be the `a` register.)
248
249 In addition to the constraints above, `y` must be initialized before
250 this mode is used.
239251
240252 ### st ###
241253
283283 ld y, 0
284284
285285 // check collision.
286 copy [ptr] + y, a
286 ld a, [ptr] + y
287287 // if "collision" is with your own self, treat it as if it's blank space!
288288 cmp a, 81
289289 if z {
336336 ld y, 0
337337
338338 // check collision.
339 copy [ptr] + y, a
339 ld a, [ptr] + y
340340 // if "collision" is with your own self, treat it as if it's blank space!
341341 cmp a, 82
342342 if z {
245245 raise TypeMismatchError('%s and %s in %s' %
246246 (src.ref.name, dest.name, self.current_routine.name)
247247 )
248 context.assert_meaningful(src.index)
248 context.assert_meaningful(src, src.index)
249249 elif isinstance(src, IndirectRef):
250 raise NotImplementedError
250 # copying this analysis from the matching branch in `copy`, below
251 if isinstance(src.ref.type, PointerType) and dest.type == TYPE_BYTE:
252 pass
253 else:
254 raise TypeMismatchError((src, dest))
255 context.assert_meaningful(src.ref, REG_Y)
251256 elif src.type != dest.type:
252257 raise TypeMismatchError('%s and %s in %s' %
253258 (src.name, dest.name, self.current_routine.name)
254259 )
255 context.assert_meaningful(src)
260 else:
261 context.assert_meaningful(src)
256262 context.set_written(dest, FLAG_Z, FLAG_N)
257263 elif opcode == 'st':
258264 if instr.index:
418424 context.set_written(dest.ref)
419425 elif isinstance(src, IndirectRef) and isinstance(dest, LocationRef):
420426 context.assert_meaningful(src.ref, REG_Y)
421 # TODO this will need to be more sophisticated. the thing ref points to is touched, as well.
422427 context.set_written(dest)
423428 elif isinstance(src, LocationRef) and isinstance(dest, IndexedRef):
424429 context.assert_meaningful(src, dest.ref, dest.index)
435440 context.set_written(dest)
436441
437442 context.set_touched(REG_A, FLAG_Z, FLAG_N)
438 context.set_unmeaningful(FLAG_Z, FLAG_N)
439
440 # FIXME: this is just to support "copy [foo] + y, a". consider disallowing `a` as something
441 # that can be used in `copy`. should be using `st` or `ld` instead, probably.
442 if dest == REG_A:
443 context.set_touched(REG_A)
444 context.set_written(REG_A)
445 else:
446 context.set_unmeaningful(REG_A)
443 context.set_unmeaningful(REG_A, FLAG_Z, FLAG_N)
447444
448445 elif opcode == 'with-sei':
449446 self.analyze_block(instr.block, context)
133133 elif isinstance(src, IndexedRef) and src.index == REG_X:
134134 self.emitter.emit(LDA(AbsoluteX(self.labels[src.name])))
135135 elif isinstance(src, IndexedRef) and src.index == REG_Y:
136 self.emitter.emit(LDA(AbsoluteY(self.labels[src.name])))
137 elif isinstance(src, IndirectRef) and isinstance(src.ref.type, PointerType):
138 self.emitter.emit(LDA(IndirectY(self.labels[src.ref.name])))
139 elif isinstance(src, IndirectRef) and src.index == REG_Y:
136140 self.emitter.emit(LDA(AbsoluteY(self.labels[src.name])))
137141 else:
138142 self.emitter.emit(LDA(Absolute(self.labels[src.name])))
384388 else:
385389 raise NotImplementedError((src, dest))
386390 elif isinstance(src, IndirectRef) and isinstance(dest, LocationRef):
387 if dest == REG_A and isinstance(src.ref.type, PointerType):
388 src_label = self.labels[src.ref.name]
389 self.emitter.emit(LDA(IndirectY(src_label)))
390 elif dest.type == TYPE_BYTE and isinstance(src.ref.type, PointerType):
391 if dest.type == TYPE_BYTE and isinstance(src.ref.type, PointerType):
391392 src_label = self.labels[src.ref.name]
392393 dest_label = self.labels[dest.name]
393394 self.emitter.emit(LDA(IndirectY(src_label)))
16001600 | }
16011601 = ok
16021602
1603 Read through a pointer to the `a` register. Note that
1604 this is done with `ld`, not `copy`.
1603 Read through a pointer to the `a` register. Note that this is done with `ld`,
1604 not `copy`.
16051605
16061606 | buffer[2048] buf
16071607 | pointer ptr
16091609 |
16101610 | routine main
16111611 | inputs buf
1612 | outputs foo
1613 | trashes a, y, z, n, ptr
1612 | outputs a
1613 | trashes y, z, n, ptr
16141614 | {
16151615 | ld y, 0
16161616 | copy ^buf, ptr