git @ Cat's Eye Technologies SixtyPical / a9bd8a3
Indexed access, + x / + y, at least for LDA and STA. --HG-- rename : eg/screen.60p => eg/screen1.60p Chris Pressey 6 years ago
8 changed file(s) with 70 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
00 History of SixtyPical
11 =====================
2
3 0.5-PRE
4 -------
5
6 * Added `byte table` type locations and indexed addressing (`+ x`, `+ y`).
27
38 0.4
49 ---
3232
3333 For 0.5:
3434
35 * `table` type constructor and indirect addressing.
35 * hexadecimal literals.
36 * source code comments.
3637
3738 For 0.6:
3839
39 * hexadecimal literals.
40 * source code comments.
40 * `interrupt` routines.
41 * `vector` type.
4142
4243 For 0.7:
4344
4445 * `word` type.
46 * `copy` instruction.
47 * `trash` instruction.
4548
4649 For 0.8:
47
48 * `vector` type.
49
50 For 0.9:
5150
5251 * add line number (or at least routine name) to error messages.
5352 * 6502-mnemonic aliases (`sec`, `clc`)
+0
-8
eg/screen.60p less more
0 byte screen @ 1024
1
2 routine main
3 trashes a, z, n, screen
4 {
5 ld a, 100
6 st a, screen
7 }
0 byte screen @ 1024
1
2 routine main
3 trashes a, z, n, screen
4 {
5 ld a, 83
6 st a, screen
7 }
0 byte table screen @ 1024
1
2 routine main
3 trashes a, x, z, n, screen
4 {
5 ld x, 0
6 ld a, 83
7 repeat {
8 st a, screen + x
9 inc x
10 } until z
11 }
77 )
88 from sixtypical.emitter import Label, Byte
99 from sixtypical.gen6502 import (
10 Immediate, Absolute, Relative,
10 Immediate, Absolute, AbsoluteX, AbsoluteY, Relative,
1111 LDA, LDX, LDY, STA, STX, STY,
1212 TAX, TAY, TXA, TYA,
1313 CLC, SEC, ADC, SBC, ROL, ROR,
8080 self.emitter.emit(TYA())
8181 elif isinstance(src, ConstantRef):
8282 self.emitter.emit(LDA(Immediate(Byte(src.value))))
83 elif instr.index == REG_X:
84 self.emitter.emit(LDA(AbsoluteX(self.labels[src.name])))
85 elif instr.index == REG_Y:
86 self.emitter.emit(LDA(AbsoluteY(self.labels[src.name])))
8387 else:
8488 self.emitter.emit(LDA(Absolute(self.labels[src.name])))
8589 elif dest == REG_X:
8791 self.emitter.emit(TAX())
8892 elif isinstance(src, ConstantRef):
8993 self.emitter.emit(LDX(Immediate(Byte(src.value))))
94 elif instr.index == REG_Y:
95 self.emitter.emit(LDX(AbsoluteY(self.labels[src.name])))
9096 else:
9197 self.emitter.emit(LDX(Absolute(self.labels[src.name])))
9298 elif dest == REG_Y:
94100 self.emitter.emit(TAY())
95101 elif isinstance(src, ConstantRef):
96102 self.emitter.emit(LDY(Immediate(Byte(src.value))))
103 elif instr.index == REG_X:
104 self.emitter.emit(LDY(AbsoluteX(self.labels[src.name])))
97105 else:
98106 self.emitter.emit(LDY(Absolute(self.labels[src.name])))
99107 else:
103111 self.emitter.emit(CLC())
104112 elif dest == FLAG_C and src == ConstantRef(TYPE_BIT, 1):
105113 self.emitter.emit(SEC())
106 elif src == REG_A:
107 self.emitter.emit(STA(Absolute(self.labels[dest.name])))
108 elif src == REG_X:
109 self.emitter.emit(STX(Absolute(self.labels[dest.name])))
110 elif src == REG_Y:
111 self.emitter.emit(STY(Absolute(self.labels[dest.name])))
112 else:
113 raise UnsupportedOpcodeError(instr)
114 else:
115 op_cls = {
116 REG_A: STA,
117 REG_X: STX,
118 REG_Y: STY
119 }.get(src, None)
120 mode_cls = {
121 REG_X: AbsoluteX,
122 REG_Y: AbsoluteY,
123 None: Absolute
124 }.get(instr.index, None)
125 if op_cls is None or mode_cls is None:
126 raise UnsupportedOpcodeError(instr)
127 self.emitter.emit(op_cls(mode_cls(self.labels[dest.name])))
114128 elif opcode == 'add':
115129 if dest == REG_A:
116130 if isinstance(src, ConstantRef):
251251 Reading from a table, you must use an index, and vice-versa.
252252
253253 | byte one
254 | byte table many
255254 |
256255 | routine main
257256 | outputs one
264263 = ok
265264
266265 | byte one
267 | byte table many
268266 |
269267 | routine main
270268 | outputs one
276274 | }
277275 ? TypeMismatchError
278276
279 | byte one
280277 | byte table many
281278 |
282279 | routine main
290287 | }
291288 ? TypeMismatchError
292289
293 | byte one
294290 | byte table many
295291 |
296292 | routine main
207207 | } forever
208208 | }
209209 = 00c0a041c84c02c060
210
211 Indexed access.
212
213 | byte one
214 | byte table many
215 |
216 | routine main
217 | outputs many
218 | trashes a, x, n, z
219 | {
220 | ld x, 0
221 | ld a, 0
222 | st a, many + x
223 | ld a, many + x
224 | }
225 = 00c0a200a9009d0dc0bd0dc060