Support of NOP opcode.
Chris Pressey
7 years ago
7 | 7 | be used in most places where literal values can be used. |
8 | 8 | * Specifying multiple SixtyPical source files will produce a single |
9 | 9 | compiled result from their combination. |
10 | * Added `nop` opcode, which compiles to `NOP` (mainly for timing.) | |
10 | 11 | * Rudimentary support for Atari 2600 prelude in a 4K cartridge image, |
11 | 12 | and start of an example program in `eg/atari2600` directory. |
12 | 13 |
25 | 25 | byte luminosity @ $81 |
26 | 26 | byte joystick_delay @ $82 |
27 | 27 | |
28 | byte table[8] image_data : "ZZZZUUUU" | |
28 | byte table[8] image_data : "ZZZZUUUU" // [126, 129, 153, 165, 129, 165, 129, 126] | |
29 | 29 | // %01111110 |
30 | 30 | // %10000001 |
31 | 31 | // %10011001 |
88 | 88 | //; we draw it. |
89 | 89 | //; |
90 | 90 | |
91 | //// nop | |
92 | //// nop | |
93 | //// nop | |
94 | //// nop | |
95 | //// nop | |
96 | //// nop | |
97 | //// nop | |
98 | //// nop | |
99 | //// nop | |
100 | //// nop | |
101 | //// nop | |
102 | //// nop | |
103 | //// nop | |
104 | //// nop | |
105 | //// nop | |
91 | nop | |
92 | nop | |
93 | nop | |
94 | nop | |
95 | nop | |
96 | nop | |
97 | nop | |
98 | nop | |
99 | nop | |
100 | nop | |
101 | nop | |
102 | nop | |
103 | nop | |
104 | nop | |
105 | nop | |
106 | 106 | |
107 | 107 | //; |
108 | 108 | //; OK, *now* display the player. |
113 | 113 | main: |
114 | 114 | jsr vertical_blank |
115 | 115 | jsr display_frame |
116 | jsr read_joystick | |
116 | ;;; jsr read_joystick | |
117 | 117 | jmp main |
118 | 118 | |
119 | 119 | ; |
254 | 254 | ; of the player. |
255 | 255 | ; |
256 | 256 | |
257 | .scope | |
258 | read_joystick: | |
259 | lda joystick_delay | |
260 | beq _continue | |
261 | ||
262 | dec joystick_delay | |
263 | rts | |
264 | ||
265 | _continue: | |
266 | lda SWCHA | |
267 | and #$f0 | |
268 | cmp #$e0 | |
269 | beq _up | |
270 | cmp #$d0 | |
271 | beq _down | |
272 | cmp #$b0 | |
273 | beq _left | |
274 | cmp #$70 | |
275 | beq _right | |
276 | jmp _tail | |
277 | ||
278 | _up: | |
279 | inc luminosity | |
280 | jmp _tail | |
281 | _down: | |
282 | dec luminosity | |
283 | jmp _tail | |
284 | _left: | |
285 | dec colour | |
286 | jmp _tail | |
287 | _right: | |
288 | inc colour | |
289 | ;jmp _tail | |
290 | ||
291 | _tail: | |
292 | lda colour | |
293 | and #$0f | |
294 | sta colour | |
295 | ||
296 | lda luminosity | |
297 | and #$0f | |
298 | sta luminosity | |
299 | ||
300 | lda colour | |
301 | clc | |
302 | rol | |
303 | rol | |
304 | rol | |
305 | rol | |
306 | ora luminosity | |
307 | sta COLUP0 | |
308 | ||
309 | lda #$06 | |
310 | sta joystick_delay | |
311 | ||
312 | rts | |
313 | .scend | |
257 | ;;; .scope | |
258 | ;;; read_joystick: | |
259 | ;;; lda joystick_delay | |
260 | ;;; beq _continue | |
261 | ;;; | |
262 | ;;; dec joystick_delay | |
263 | ;;; rts | |
264 | ;;; | |
265 | ;;; _continue: | |
266 | ;;; lda SWCHA | |
267 | ;;; and #$f0 | |
268 | ;;; cmp #$e0 | |
269 | ;;; beq _up | |
270 | ;;; cmp #$d0 | |
271 | ;;; beq _down | |
272 | ;;; cmp #$b0 | |
273 | ;;; beq _left | |
274 | ;;; cmp #$70 | |
275 | ;;; beq _right | |
276 | ;;; jmp _tail | |
277 | ;;; | |
278 | ;;; _up: | |
279 | ;;; inc luminosity | |
280 | ;;; jmp _tail | |
281 | ;;; _down: | |
282 | ;;; dec luminosity | |
283 | ;;; jmp _tail | |
284 | ;;; _left: | |
285 | ;;; dec colour | |
286 | ;;; jmp _tail | |
287 | ;;; _right: | |
288 | ;;; inc colour | |
289 | ;;; ;jmp _tail | |
290 | ;;; | |
291 | ;;; _tail: | |
292 | ;;; lda colour | |
293 | ;;; and #$0f | |
294 | ;;; sta colour | |
295 | ;;; | |
296 | ;;; lda luminosity | |
297 | ;;; and #$0f | |
298 | ;;; sta luminosity | |
299 | ;;; | |
300 | ;;; lda colour | |
301 | ;;; clc | |
302 | ;;; rol | |
303 | ;;; rol | |
304 | ;;; rol | |
305 | ;;; rol | |
306 | ;;; ora luminosity | |
307 | ;;; sta COLUP0 | |
308 | ;;; | |
309 | ;;; lda #$06 | |
310 | ;;; sta joystick_delay | |
311 | ;;; | |
312 | ;;; rts | |
313 | ;;; .scend | |
314 | 314 | |
315 | 315 | ; |
316 | 316 | ; Player (sprite) data. |
0 | #!/bin/sh | |
1 | ||
2 | sixtypical --prelude=atari2600 atari-2600-example.60p > atari-2600-example-60p.bin | |
3 | if [ "x$COMPARE" != "x" ]; then | |
4 | ophis atari-2600-example.oph -o atari-2600-example.bin | |
5 | dcc6502 -o 0xf000 -m 200 atari-2600-example.bin > atari-2600-example.bin.disasm.txt | |
6 | dcc6502 -o 0xf000 -m 200 atari-2600-example-60p.bin > atari-2600-example-60p.bin.disasm.txt | |
7 | paste atari-2600-example.bin.disasm.txt atari-2600-example-60p.bin.disasm.txt | pr -t -e24 | |
8 | fi |
598 | 598 | elif opcode == 'trash': |
599 | 599 | context.set_touched(instr.dest) |
600 | 600 | context.set_unmeaningful(instr.dest) |
601 | elif opcode == 'nop': | |
602 | pass | |
601 | 603 | else: |
602 | 604 | raise NotImplementedError(opcode) |
603 | 605 |
17 | 17 | BCC, BCS, BNE, BEQ, |
18 | 18 | JMP, JSR, RTS, |
19 | 19 | SEI, CLI, |
20 | NOP, | |
20 | 21 | ) |
21 | 22 | |
22 | 23 | |
353 | 354 | self.compile_copy(instr, instr.src, instr.dest) |
354 | 355 | elif opcode == 'trash': |
355 | 356 | pass |
357 | elif opcode == 'nop': | |
358 | self.emitter.emit(NOP()) | |
356 | 359 | else: |
357 | 360 | raise NotImplementedError(opcode) |
358 | 361 |
311 | 311 | } |
312 | 312 | |
313 | 313 | |
314 | class NOP(Instruction): | |
315 | opcodes = { | |
316 | Implied: 0xEA, | |
317 | } | |
318 | ||
319 | ||
314 | 320 | class SBC(Instruction): |
315 | 321 | opcodes = { |
316 | 322 | Immediate: 0xe9, |
439 | 439 | self.scanner.scan() |
440 | 440 | dest = self.locexpr() |
441 | 441 | return SingleOp(self.scanner.line_number, opcode=opcode, dest=dest, src=None) |
442 | elif self.scanner.token in ("nop"): | |
443 | opcode = self.scanner.token | |
444 | self.scanner.scan() | |
445 | return SingleOp(self.scanner.line_number, opcode=opcode, dest=None, src=None) | |
442 | 446 | elif self.scanner.token in ("call", "goto"): |
443 | 447 | opcode = self.scanner.token |
444 | 448 | self.scanner.scan() |
1009 | 1009 | |
1010 | 1010 | ### cmp ### |
1011 | 1011 | |
1012 | Some rudimentary tests for cmp. | |
1012 | Some rudimentary tests for `cmp`. | |
1013 | 1013 | |
1014 | 1014 | | routine main |
1015 | 1015 | | inputs a |
1036 | 1036 | |
1037 | 1037 | ### and ### |
1038 | 1038 | |
1039 | Some rudimentary tests for and. | |
1039 | Some rudimentary tests for `and`. | |
1040 | 1040 | |
1041 | 1041 | | routine main |
1042 | 1042 | | inputs a |
1063 | 1063 | |
1064 | 1064 | ### or ### |
1065 | 1065 | |
1066 | Writing unit tests on a train. Wow. | |
1066 | Some rudimentary tests for `or`. | |
1067 | 1067 | |
1068 | 1068 | | routine main |
1069 | 1069 | | inputs a |
1090 | 1090 | |
1091 | 1091 | ### xor ### |
1092 | 1092 | |
1093 | Writing unit tests on a train. Wow. | |
1093 | Some rudimentary tests for `xor`. | |
1094 | 1094 | |
1095 | 1095 | | routine main |
1096 | 1096 | | inputs a |
1117 | 1117 | |
1118 | 1118 | ### shl ### |
1119 | 1119 | |
1120 | Some rudimentary tests for shl. | |
1120 | Some rudimentary tests for `shl`. | |
1121 | 1121 | |
1122 | 1122 | | routine main |
1123 | 1123 | | inputs a, c |
1145 | 1145 | |
1146 | 1146 | ### shr ### |
1147 | 1147 | |
1148 | Some rudimentary tests for shr. | |
1148 | Some rudimentary tests for `shr`. | |
1149 | 1149 | |
1150 | 1150 | | routine main |
1151 | 1151 | | inputs a, c |
1170 | 1170 | | shr a |
1171 | 1171 | | } |
1172 | 1172 | ? UnmeaningfulReadError: c |
1173 | ||
1174 | ### nop ### | |
1175 | ||
1176 | Some rudimentary tests for `nop`. | |
1177 | ||
1178 | | routine main | |
1179 | | { | |
1180 | | nop | |
1181 | | } | |
1182 | = ok | |
1173 | 1183 | |
1174 | 1184 | ### call ### |
1175 | 1185 |