git @ Cat's Eye Technologies SixtyPical / 3c7d95a
Support for `copy [ptra]+y, [ptrb]+y` to indirect LDA indirect STA Chris Pressey 3 years ago
7 changed file(s) with 67 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
77 if the address of z < 256.
88 * More thorough tests and justifications written for the case of
99 assigning a routine to a vector with a "wider" type.
10 * Support for `copy [ptra]+y, [ptrb]+y` to indirect LDA indirect STA.
1011
1112 0.15
1213 ----
00 SixtyPical
11 ==========
22
3 _Version 0.15. Work-in-progress, everything is subject to change._
3 _Version 0.16. Work-in-progress, everything is subject to change._
44
55 **SixtyPical** is a 6502-like programming language with advanced
66 static analysis.
8686 * Add absolute addressing in shl/shr, absolute-indexed for add, sub, etc.
8787 * Automatic tail-call optimization (could be tricky, w/constraints?)
8888 * Possibly `ld x, [ptr] + y`, possibly `st x, [ptr] + y`.
89 * Maybe even `copy [ptra] + y, [ptrb] + y`, which can be compiled to indirect LDA then indirect STA!
9089
9190 [VICE]: http://vice-emu.sourceforge.net/
516516 pass
517517 else:
518518 raise TypeMismatchError(instr, (src, dest))
519 elif isinstance(src, IndirectRef) and isinstance(dest, IndirectRef):
520 if isinstance(src.ref.type, PointerType) and isinstance(dest.ref.type, PointerType):
521 pass
522 else:
523 raise TypeMismatchError(instr, (src, dest))
519524
520525 elif isinstance(src, (LocationRef, ConstantRef)) and isinstance(dest, IndexedRef):
521526 if src.type == TYPE_WORD and TableType.is_a_table_type(dest.ref.type, TYPE_WORD):
560565 context.set_written(dest.ref)
561566 elif isinstance(src, IndirectRef) and isinstance(dest, LocationRef):
562567 context.assert_meaningful(src.ref, REG_Y)
568 # TODO more sophisticated?
563569 context.set_written(dest)
570 elif isinstance(src, IndirectRef) and isinstance(dest, IndirectRef):
571 context.assert_meaningful(src.ref, REG_Y)
572 # TODO more sophisticated?
573 context.set_written(dest.ref)
564574 elif isinstance(src, LocationRef) and isinstance(dest, IndexedRef):
565575 context.assert_meaningful(src, dest.ref, dest.index)
566576 context.set_written(dest.ref)
427427 dest_label = self.get_label(dest.name)
428428 self.emitter.emit(LDA(IndirectY(src_label)))
429429 self.emitter.emit(STA(Absolute(dest_label)))
430 elif isinstance(src, IndirectRef) and isinstance(dest, IndirectRef) and isinstance(src.ref.type, PointerType) and isinstance(dest.ref.type, PointerType):
431 ### copy [ptra] + y, [ptrb] + y
432 src_label = self.get_label(src.ref.name)
433 dest_label = self.get_label(dest.ref.name)
434 self.emitter.emit(LDA(IndirectY(src_label)))
435 self.emitter.emit(STA(IndirectY(dest_label)))
430436 elif isinstance(src, AddressRef) and isinstance(dest, LocationRef) and isinstance(src.ref.type, BufferType) and isinstance(dest.type, PointerType):
431437 ### copy ^buf, ptr
432438 src_label = self.get_label(src.ref.name)
21132113 | }
21142114 = ok
21152115
2116 Read and write through two pointers.
2117
2118 | buffer[2048] buf
2119 | pointer ptra
2120 | pointer ptrb
2121 |
2122 | routine main
2123 | inputs buf
2124 | outputs buf
2125 | trashes a, y, z, n, ptra, ptrb
2126 | {
2127 | ld y, 0
2128 | copy ^buf, ptra
2129 | copy ^buf, ptrb
2130 | copy [ptra] + y, [ptrb] + y
2131 | }
2132 = ok
2133
21162134 Read through a pointer to the `a` register. Note that this is done with `ld`,
21172135 not `copy`.
21182136
10361036 = $081C LDA ($FE),Y
10371037 = $081E RTS
10381038
1039 Read and write through two pointers.
1040
1041 | buffer[2048] buf
1042 | pointer ptra @ 252
1043 | pointer ptrb @ 254
1044 |
1045 | routine main
1046 | inputs buf
1047 | outputs buf
1048 | trashes a, y, z, n, ptra, ptrb
1049 | {
1050 | ld y, 0
1051 | copy ^buf, ptra
1052 | copy ^buf, ptrb
1053 | copy [ptra] + y, [ptrb] + y
1054 | }
1055 = $080D LDY #$00
1056 = $080F LDA #$24
1057 = $0811 STA $FC
1058 = $0813 LDA #$08
1059 = $0815 STA $FD
1060 = $0817 LDA #$24
1061 = $0819 STA $FE
1062 = $081B LDA #$08
1063 = $081D STA $FF
1064 = $081F LDA ($FC),Y
1065 = $0821 STA ($FE),Y
1066 = $0823 RTS
1067
10391068 Write the `a` register through a pointer.
10401069
10411070 | buffer[2048] buf
564564
565565 | buffer[2048] buf
566566 | pointer ptr
567 | pointer ptrb
567568 | byte foo
568569 |
569570 | routine main {
570571 | copy ^buf, ptr
571572 | copy 123, [ptr] + y
572573 | copy [ptr] + y, foo
574 | copy [ptr] + y, [ptrb] + y
573575 | }
574576 = ok
575577