git @ Cat's Eye Technologies SixtyPical / 1f992f8
Support of NOP opcode. Chris Pressey 7 years ago
12 changed file(s) with 134 addition(s) and 80 deletion(s). Raw diff Collapse all Expand all
77 be used in most places where literal values can be used.
88 * Specifying multiple SixtyPical source files will produce a single
99 compiled result from their combination.
10 * Added `nop` opcode, which compiles to `NOP` (mainly for timing.)
1011 * Rudimentary support for Atari 2600 prelude in a 4K cartridge image,
1112 and start of an example program in `eg/atari2600` directory.
1213
0 *.bin
1 *.disasm.txt
2525 byte luminosity @ $81
2626 byte joystick_delay @ $82
2727
28 byte table[8] image_data : "ZZZZUUUU"
28 byte table[8] image_data : "ZZZZUUUU" // [126, 129, 153, 165, 129, 165, 129, 126]
2929 // %01111110
3030 // %10000001
3131 // %10011001
8888 //; we draw it.
8989 //;
9090
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
106106
107107 //;
108108 //; OK, *now* display the player.
113113 main:
114114 jsr vertical_blank
115115 jsr display_frame
116 jsr read_joystick
116 ;;; jsr read_joystick
117117 jmp main
118118
119119 ;
254254 ; of the player.
255255 ;
256256
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
314314
315315 ;
316316 ; 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
598598 elif opcode == 'trash':
599599 context.set_touched(instr.dest)
600600 context.set_unmeaningful(instr.dest)
601 elif opcode == 'nop':
602 pass
601603 else:
602604 raise NotImplementedError(opcode)
603605
1717 BCC, BCS, BNE, BEQ,
1818 JMP, JSR, RTS,
1919 SEI, CLI,
20 NOP,
2021 )
2122
2223
353354 self.compile_copy(instr, instr.src, instr.dest)
354355 elif opcode == 'trash':
355356 pass
357 elif opcode == 'nop':
358 self.emitter.emit(NOP())
356359 else:
357360 raise NotImplementedError(opcode)
358361
311311 }
312312
313313
314 class NOP(Instruction):
315 opcodes = {
316 Implied: 0xEA,
317 }
318
319
314320 class SBC(Instruction):
315321 opcodes = {
316322 Immediate: 0xe9,
439439 self.scanner.scan()
440440 dest = self.locexpr()
441441 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)
442446 elif self.scanner.token in ("call", "goto"):
443447 opcode = self.scanner.token
444448 self.scanner.scan()
10091009
10101010 ### cmp ###
10111011
1012 Some rudimentary tests for cmp.
1012 Some rudimentary tests for `cmp`.
10131013
10141014 | routine main
10151015 | inputs a
10361036
10371037 ### and ###
10381038
1039 Some rudimentary tests for and.
1039 Some rudimentary tests for `and`.
10401040
10411041 | routine main
10421042 | inputs a
10631063
10641064 ### or ###
10651065
1066 Writing unit tests on a train. Wow.
1066 Some rudimentary tests for `or`.
10671067
10681068 | routine main
10691069 | inputs a
10901090
10911091 ### xor ###
10921092
1093 Writing unit tests on a train. Wow.
1093 Some rudimentary tests for `xor`.
10941094
10951095 | routine main
10961096 | inputs a
11171117
11181118 ### shl ###
11191119
1120 Some rudimentary tests for shl.
1120 Some rudimentary tests for `shl`.
11211121
11221122 | routine main
11231123 | inputs a, c
11451145
11461146 ### shr ###
11471147
1148 Some rudimentary tests for shr.
1148 Some rudimentary tests for `shr`.
11491149
11501150 | routine main
11511151 | inputs a, c
11701170 | shr a
11711171 | }
11721172 ? UnmeaningfulReadError: c
1173
1174 ### nop ###
1175
1176 Some rudimentary tests for `nop`.
1177
1178 | routine main
1179 | {
1180 | nop
1181 | }
1182 = ok
11731183
11741184 ### call ###
11751185
1616 | {
1717 | }
1818 = $080D RTS
19
20 `nop` program.
21
22 | routine main
23 | {
24 | nop
25 | }
26 = $080D NOP
27 = $080E RTS
1928
2029 Rudimentary program.
2130
7474 | routine main {
7575 | trash a
7676 | trash n
77 | }
78 = ok
79
80 `nop`.
81
82 | routine main
83 | {
84 | nop
7785 | }
7886 = ok
7987