git @ Cat's Eye Technologies SixtyPical / c915741
First pass of buffer, pointer, copy b, [p] + y, indirect indexed. Chris Pressey 4 years ago
8 changed file(s) with 105 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
5151
5252 We will likely have a new mode of `copy` for this, like
5353
54 copy 100, p + y
54 copy 100, [ptr] + y
5555
56 where `p` is a user-defined storage location of `pointer` type, and `+ y`
56 where `ptr` is a user-defined storage location of `pointer` type, and `+ y`
5757 is mandatory (and you can/should set it to zero yourself if you want.)
5858
5959 This instruction will likely be unchecked, at least to start. Basically,
11
22 from sixtypical.ast import Program, Routine, Block, Instr
33 from sixtypical.model import (
4 TYPE_BYTE, TYPE_BYTE_TABLE,
5 VectorType, ExecutableType,
4 TYPE_BYTE, TYPE_BYTE_TABLE, BufferType, PointerType, VectorType, ExecutableType,
65 ConstantRef, LocationRef,
7 REG_A, FLAG_Z, FLAG_N, FLAG_V, FLAG_C
6 REG_A, REG_Y, FLAG_Z, FLAG_N, FLAG_V, FLAG_C
87 )
98
109
293292 context.assert_meaningful(src)
294293
295294 elif opcode == 'copy':
296 # check that their types are basically compatible
295 # check that their types are compatible
297296 if src.type == dest.type:
298297 pass
299298 elif isinstance(src.type, ExecutableType) and \
300299 isinstance(dest.type, VectorType):
301300 pass
301 elif isinstance(src.type, BufferType) and \
302 isinstance(dest.type, PointerType):
303 pass
302304 else:
303305 raise TypeMismatchError((src, dest))
304
306
305307 # if dealing with routines and vectors,
306308 # check that they're not incompatible
307309 if isinstance(src.type, ExecutableType) and \
312314 raise IncompatibleConstraintsError(src.type.outputs - dest.type.outputs)
313315 if not (src.type.trashes <= dest.type.trashes):
314316 raise IncompatibleConstraintsError(src.type.trashes - dest.type.trashes)
315
317
316318 context.assert_meaningful(src)
317319 context.set_written(dest)
318320 context.set_touched(REG_A, FLAG_Z, FLAG_N)
319321 context.set_unmeaningful(REG_A, FLAG_Z, FLAG_N)
322
323 elif opcode == 'copy[]+y':
324 # check that their types are compatible
325 if src.type == TYPE_BYTE and isinstance(dest.type, PointerType):
326 pass
327 else:
328 raise TypeMismatchError((src, dest))
329
330 context.assert_meaningful(src, REG_Y)
331 context.set_written(dest)
332 context.set_touched(REG_A, FLAG_Z, FLAG_N)
333 context.set_unmeaningful(REG_A, FLAG_Z, FLAG_N)
334
320335 elif opcode == 'with-sei':
321336 self.analyze_block(instr.block, context)
322337 elif opcode == 'goto':
22 from sixtypical.ast import Program, Routine, Block, Instr
33 from sixtypical.model import (
44 ConstantRef,
5 TYPE_BIT, TYPE_BYTE, TYPE_WORD,
6 RoutineType, VectorType,
5 TYPE_BIT, TYPE_BYTE, TYPE_WORD, BufferType, PointerType, RoutineType, VectorType,
76 REG_A, REG_X, REG_Y, FLAG_C
87 )
98 from sixtypical.emitter import Byte, Label, Offset, LowAddressByte, HighAddressByte
109 from sixtypical.gen6502 import (
11 Immediate, Absolute, AbsoluteX, AbsoluteY, Indirect, Relative,
10 Immediate, Absolute, AbsoluteX, AbsoluteY, Indirect, IndirectY, Relative,
1211 LDA, LDX, LDY, STA, STX, STY,
1312 TAX, TAY, TXA, TYA,
1413 CLC, SEC, ADC, SBC, ROL, ROR,
298297 self.emitter.emit(STA(Absolute(dest_label)))
299298 self.emitter.emit(LDA(Absolute(Offset(src_label, 1))))
300299 self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
300 elif isinstance(src.type, BufferType) and isinstance(dest.type, PointerType):
301 raise NotImplementedError('zeropage')
301302 elif isinstance(src.type, VectorType) and isinstance(dest.type, VectorType):
302303 src_label = self.labels[src.name]
303304 dest_label = self.labels[dest.name]
195195 context.set(REG_A, 0)
196196 context.set(FLAG_Z, 0)
197197 context.set(FLAG_N, 0)
198 elif opcode == 'copy[]':
199 addr = context.get(dest)
200 # memloc = memory[addr + context.get(REG_Y)]
201 # context.set(memloc, context.get(src))
202 context.set(dest, context.get(src))
203 # these are trashed; so could be anything really
204 context.set(REG_A, 0)
205 context.set(FLAG_Z, 0)
206 context.set(FLAG_N, 0)
198207 elif opcode == 'with-sei':
199208 self.eval_block(instr.block)
200209 else:
5858
5959
6060 class Indirect(AddressingMode):
61 def __init__(self, value):
62 assert isinstance(value, Label)
63 self.value = value
64
65 def size(self):
66 return 2
67
68 def serialize(self, addr=None):
69 return self.value.serialize()
70
71
72 class IndirectY(AddressingMode):
6173 def __init__(self, value):
6274 assert isinstance(value, Label)
6375 self.value = value
243255 Absolute: 0xad,
244256 AbsoluteX: 0xbd,
245257 AbsoluteY: 0xb9,
258 IndirectY: 0xb1,
246259 }
247260
248261
319332 Absolute: 0x8d,
320333 AbsoluteX: 0x9d,
321334 AbsoluteY: 0x99,
335 IndirectY: 0x91,
322336 }
323337
324338
235235 self.scanner.scan()
236236 src = self.locexpr()
237237 self.scanner.expect(',')
238 dest = self.locexpr()
238 if self.scanner.consume('['):
239 dest = self.locexpr()
240 self.scanner.expect(']')
241 self.scanner.expect('+')
242 self.scanner.expect('y')
243 opcode = 'copy[]+y'
244 else:
245 dest = self.locexpr()
239246 i = Instr(opcode=opcode, dest=dest, src=src)
240247 #print repr(i)
241248 return i
11711171 | }
11721172 ? TypeMismatchError
11731173
1174 ### copy[] ###
1175
1176 Buffers and pointers.
1177
1178 Note that `copy buf, ptr` should probably be `copy ^buf, ptr` and `^buf` should not
1179 be considered "reading" buf and should not require it in `inputs` for that reason.
1180
1181 | buffer[2048] buf
1182 | pointer ptr
1183 |
1184 | routine main
1185 | inputs buf
1186 | outputs buf, y
1187 | trashes a, z, n, ptr
1188 | {
1189 | ld y, 0
1190 | copy buf, ptr
1191 | copy 123, [ptr] + y
1192 | }
1193 = ok
1194
1195 It does use `y`.
1196
1197 | buffer[2048] buf
1198 | pointer ptr
1199 |
1200 | routine main
1201 | inputs buf
1202 | outputs buf
1203 | trashes a, z, n, ptr
1204 | {
1205 | copy buf, ptr
1206 | copy 123, [ptr] + y
1207 | }
1208 ? UnmeaningfulReadError
1209
11741210 ### routines ###
11751211
11761212 Routines are constants. You need not, and in fact cannot, specify a constant
128128 | word wor
129129 | vector vec
130130 | byte table tab
131 |
132 | routine main {
133 | }
134 = ok
135
136 Buffer and pointer types.
137
138 | byte byt
139 | word wor
140 | vector vec
141 | byte table tab
142131 | buffer[2048] buf
143132 | pointer ptr
144133 |
331320 | goto foo
332321 | }
333322 ? SyntaxError
323
324 Buffers and pointers.
325
326 | buffer[2048] buf
327 | pointer ptr
328 |
329 | routine main {
330 | copy buf, ptr
331 | copy 123, [ptr] + y
332 | }
333 = ok