git @ Cat's Eye Technologies SixtyPical / c194808
Label the various cases for compiling a `copy` instruction. Chris Pressey 4 years ago
1 changed file(s) with 15 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
381381 if isinstance(src, (LocationRef, ConstantRef)) and isinstance(dest, IndirectRef):
382382 if src.type == TYPE_BYTE and isinstance(dest.ref.type, PointerType):
383383 if isinstance(src, ConstantRef):
384 ### copy 123, [ptr] + y
384385 dest_label = self.get_label(dest.ref.name)
385386 self.emitter.emit(LDA(Immediate(Byte(src.value))))
386387 self.emitter.emit(STA(IndirectY(dest_label)))
387388 elif isinstance(src, LocationRef):
389 ### copy b, [ptr] + y
388390 src_label = self.get_label(src.name)
389391 dest_label = self.get_label(dest.ref.name)
390392 self.emitter.emit(LDA(Absolute(src_label)))
395397 raise NotImplementedError((src, dest))
396398 elif isinstance(src, IndirectRef) and isinstance(dest, LocationRef):
397399 if dest.type == TYPE_BYTE and isinstance(src.ref.type, PointerType):
400 ### copy [ptr] + y, b
398401 src_label = self.get_label(src.ref.name)
399402 dest_label = self.get_label(dest.name)
400403 self.emitter.emit(LDA(IndirectY(src_label)))
403406 raise NotImplementedError((src, dest))
404407 elif isinstance(src, AddressRef) and isinstance(dest, LocationRef) and \
405408 isinstance(src.ref.type, BufferType) and isinstance(dest.type, PointerType):
409 ### copy ^buf, ptr
406410 src_label = self.get_label(src.ref.name)
407411 dest_label = self.get_label(dest.name)
408412 self.emitter.emit(LDA(Immediate(HighAddressByte(src_label))))
411415 self.emitter.emit(STA(ZeroPage(Offset(dest_label, 1))))
412416 elif isinstance(src, LocationRef) and isinstance(dest, IndexedRef):
413417 if src.type == TYPE_WORD and TableType.is_a_table_type(dest.ref.type, TYPE_WORD):
418 ### copy w, wtab + y
414419 src_label = self.get_label(src.name)
415420 dest_label = self.get_label(dest.ref.name)
416421 self.emitter.emit(LDA(Absolute(src_label)))
418423 self.emitter.emit(LDA(Absolute(Offset(src_label, 1))))
419424 self.emitter.emit(STA(self.addressing_mode_for_index(dest.index)(Offset(dest_label, 256))))
420425 elif isinstance(src.type, VectorType) and isinstance(dest.ref.type, TableType) and isinstance(dest.ref.type.of_type, VectorType):
426 ### copy vec, vtab + y
421427 # FIXME this is the exact same as above - can this be simplified?
422428 src_label = self.get_label(src.name)
423429 dest_label = self.get_label(dest.ref.name)
426432 self.emitter.emit(LDA(Absolute(Offset(src_label, 1))))
427433 self.emitter.emit(STA(self.addressing_mode_for_index(dest.index)(Offset(dest_label, 256))))
428434 elif isinstance(src.type, RoutineType) and isinstance(dest.ref.type, TableType) and isinstance(dest.ref.type.of_type, VectorType):
435 ### copy routine, vtab + y
429436 src_label = self.get_label(src.name)
430437 dest_label = self.get_label(dest.ref.name)
431438 self.emitter.emit(LDA(Immediate(HighAddressByte(src_label))))
436443 raise NotImplementedError
437444 elif isinstance(src, ConstantRef) and isinstance(dest, IndexedRef):
438445 if src.type == TYPE_WORD and TableType.is_a_table_type(dest.ref.type, TYPE_WORD):
446 ### copy 9999, wtab + y
439447 dest_label = self.get_label(dest.ref.name)
440448 self.emitter.emit(LDA(Immediate(Byte(src.low_byte()))))
441449 self.emitter.emit(STA(self.addressing_mode_for_index(dest.index)(dest_label)))
445453 raise NotImplementedError
446454 elif isinstance(src, IndexedRef) and isinstance(dest, LocationRef):
447455 if TableType.is_a_table_type(src.ref.type, TYPE_WORD) and dest.type == TYPE_WORD:
456 ### copy wtab + y, w
448457 src_label = self.get_label(src.ref.name)
449458 dest_label = self.get_label(dest.name)
450459 self.emitter.emit(LDA(self.addressing_mode_for_index(src.index)(src_label)))
452461 self.emitter.emit(LDA(self.addressing_mode_for_index(src.index)(Offset(src_label, 256))))
453462 self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
454463 elif isinstance(dest.type, VectorType) and isinstance(src.ref.type, TableType) and isinstance(src.ref.type.of_type, VectorType):
464 ### copy vtab + y, vec
455465 # FIXME this is the exact same as above - can this be simplified?
456466 src_label = self.get_label(src.ref.name)
457467 dest_label = self.get_label(dest.name)
468478 if isinstance(src, ConstantRef):
469479 raise NotImplementedError
470480 else:
481 ### copy b1, b2
471482 src_label = self.get_label(src.name)
472483 dest_label = self.get_label(dest.name)
473484 self.emitter.emit(LDA(Absolute(src_label)))
474485 self.emitter.emit(STA(Absolute(dest_label)))
475486 elif src.type == TYPE_WORD and dest.type == TYPE_WORD:
476487 if isinstance(src, ConstantRef):
488 ### copy 9999, w
477489 dest_label = self.get_label(dest.name)
478490 self.emitter.emit(LDA(Immediate(Byte(src.low_byte()))))
479491 self.emitter.emit(STA(Absolute(dest_label)))
480492 self.emitter.emit(LDA(Immediate(Byte(src.high_byte()))))
481493 self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
482494 else:
495 ### copy w1, w2
483496 src_label = self.get_label(src.name)
484497 dest_label = self.get_label(dest.name)
485498 self.emitter.emit(LDA(Absolute(src_label)))
487500 self.emitter.emit(LDA(Absolute(Offset(src_label, 1))))
488501 self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
489502 elif isinstance(src.type, VectorType) and isinstance(dest.type, VectorType):
503 ### copy v1, v2
490504 src_label = self.get_label(src.name)
491505 dest_label = self.get_label(dest.name)
492506 self.emitter.emit(LDA(Absolute(src_label)))
494508 self.emitter.emit(LDA(Absolute(Offset(src_label, 1))))
495509 self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
496510 elif isinstance(src.type, RoutineType) and isinstance(dest.type, VectorType):
511 ### copy routine, vec
497512 src_label = self.get_label(src.name)
498513 dest_label = self.get_label(dest.name)
499514 self.emitter.emit(LDA(Immediate(HighAddressByte(src_label))))