git @ Cat's Eye Technologies SixtyPical / 1664904
I kind of forgot that indirect JSR needs a trampoline first :/ Chris Pressey 6 years ago
4 changed file(s) with 54 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
88 )
99 from sixtypical.emitter import Byte, Label, Offset
1010 from sixtypical.gen6502 import (
11 Immediate, Absolute, AbsoluteX, AbsoluteY, Relative,
11 Immediate, Absolute, AbsoluteX, AbsoluteY, Indirect, Relative,
1212 LDA, LDX, LDY, STA, STX, STY,
1313 TAX, TAY, TXA, TYA,
1414 CLC, SEC, ADC, SBC, ROL, ROR,
192192 else:
193193 raise UnsupportedOpcodeError(instr)
194194 elif opcode == 'call':
195 location = instr.location
195196 label = self.labels[instr.location.name]
196 self.emitter.emit(JSR(Absolute(label)))
197 if isinstance(location.type, RoutineType):
198 self.emitter.emit(JSR(Absolute(label)))
199 elif isinstance(location.type, VectorType):
200 # XXX NOT QUITE RIGHT, IS IT?
201 # We need to simulate an indirect JSR!
202 self.emitter.emit(JMP(Indirect(label)))
203 else:
204 raise NotImplementedError
197205 elif opcode == 'if':
198206 cls = {
199207 False: {
11181118 | copy vec, foo
11191119 | }
11201120 ? TypeMismatchError
1121
1122 Indirect call.
1123
1124 | vector foo outputs x trashes z, n
1125 |
1126 | routine bar outputs x trashes z, n {
1127 | ld x, 200
1128 | }
1129 |
1130 | routine main inputs bar outputs x, foo trashes a, z, n {
1131 | copy bar, foo
1132 | call foo
1133 | }
1134 = ok
1135
1136 Calling the vector has indeed trashed stuff etc,
1137
1138 | vector foo trashes x, z, n
1139 |
1140 | routine bar trashes x, z, n {
1141 | ld x, 200
1142 | }
1143 |
1144 | routine main inputs bar outputs x, foo trashes z, n {
1145 | ld x, 0
1146 | copy bar, foo
1147 | call foo
1148 | }
1149 ? UninitializedOutputError: x
260260 | }
261261 | }
262262 = 00c078ad0fc08d11c0ad10c08d12c05860e860
263
264 Indirect call.
265
266 | vector foo outputs x trashes z, n
267 |
268 | routine bar outputs x trashes z, n {
269 | ld x, 200
270 | }
271 |
272 | routine main inputs bar outputs x, foo trashes a, z, n {
273 | copy bar, foo
274 | call foo
275 | }
276 = 00c0
408408 | ld x, 200
409409 | }
410410 |
411 | routine main {
411 | routine main inputs bar outputs x, foo trashes a, z, n {
412412 | copy bar, foo
413413 | call foo
414414 | }