git @ Cat's Eye Technologies SixtyPical / 81aeb6c
Use dcc6502 to disassemble code for comparison in unit tests. Chris Pressey 3 years ago
2 changed file(s) with 226 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
88 * Adding `word table` type (in progress).
99 * Implementation: `--debug` shows some extra info during analysis.
1010 * Fixed bug where `copy`ing literal word into word storage used wrong endianness.
11 * Fixed bug where every memory location was allocated 2 bytes of storage, regardless of type.
12 * Tests: use https://github.com/tcarmelveilleux/dcc6502 to disassemble code for comparison.
1113
1214 0.8
1315 ---
66 [Falderal]: http://catseye.tc/node/Falderal
77
88 -> Functionality "Compile SixtyPical program" is implemented by
9 -> shell command "bin/sixtypical --compile %(test-body-file) | fa-bin-to-hex"
9 -> shell command "bin/sixtypical --basic-prelude --compile %(test-body-file) | bin/dcc6502-adapter"
1010
1111 -> Tests for functionality "Compile SixtyPical program"
1212
1515 | routine main
1616 | {
1717 | }
18 = 00c060
18 = $080D RTS
1919
2020 Rudimentary program.
2121
2727 | st off, c
2828 | add a, 4
2929 | }
30 = 00c018690460
30 = $080D CLC
31 = $080E ADC #$04
32 = $0810 RTS
3133
3234 Call extern.
3335
4345 | ld a, 65
4446 | call chrout
4547 | }
46 = 00c0a94120d2ff60
48 = $080D LDA #$41
49 = $080F JSR $FFD2
50 = $0812 RTS
4751
4852 Call defined routine.
4953
6165 | {
6266 | call foo
6367 | }
64 = 00c02004c060a900a200a00060
68 = $080D JSR $0811
69 = $0810 RTS
70 = $0811 LDA #$00
71 = $0813 LDX #$00
72 = $0815 LDY #$00
73 = $0817 RTS
6574
6675 Access a defined memory location.
6776
7483 | st y, foo
7584 | ld a, foo
7685 | }
77 = 00c0a0008c09c0ad09c060
86 = $080D LDY #$00
87 = $080F STY $0816
88 = $0812 LDA $0816
89 = $0815 RTS
7890
7991 Memory location with explicit address.
8092
8698 | ld a, 100
8799 | st a, screen
88100 | }
89 = 00c0a9648d000460
101 = $080D LDA #$64
102 = $080F STA $0400
103 = $0812 RTS
90104
91105 Memory location with initial value.
92106
98112 | {
99113 | ld a, lives
100114 | }
101 = 00c0ad04c06003
115 = $080D LDA $0811
116 = $0810 RTS
117 = $0811 .byte $03
102118
103119 Some instructions.
104120
140156 | shl a
141157 | shr a
142158 | }
143 = 00c0a900a200a0008d46c08e46c08c46c0381869016d46c0e901ed46c0ee46c0e8c8ce46c0ca8829ff2d46c009ff0d46c049ff4d46c0c901cd46c0e001ec46c0c001cc46c02a6a60
159 = $080D LDA #$00
160 = $080F LDX #$00
161 = $0811 LDY #$00
162 = $0813 STA $0853
163 = $0816 STX $0853
164 = $0819 STY $0853
165 = $081C SEC
166 = $081D CLC
167 = $081E ADC #$01
168 = $0820 ADC $0853
169 = $0823 SBC #$01
170 = $0825 SBC $0853
171 = $0828 INC $0853
172 = $082B INX
173 = $082C INY
174 = $082D DEC $0853
175 = $0830 DEX
176 = $0831 DEY
177 = $0832 AND #$FF
178 = $0834 AND $0853
179 = $0837 ORA #$FF
180 = $0839 ORA $0853
181 = $083C EOR #$FF
182 = $083E EOR $0853
183 = $0841 CMP #$01
184 = $0843 CMP $0853
185 = $0846 CPX #$01
186 = $0848 CPX $0853
187 = $084B CPY #$01
188 = $084D CPY $0853
189 = $0850 ROL A
190 = $0851 ROR A
191 = $0852 RTS
144192
145193 Compiling `if`.
146194
154202 | ld y, 2
155203 | }
156204 | }
157 = 00c0a900d005a0014c0bc0a00260
205 = $080D LDA #$00
206 = $080F BNE $0816
207 = $0811 LDY #$01
208 = $0813 JMP $0818
209 = $0816 LDY #$02
210 = $0818 RTS
158211
159212 Compiling `if not`.
160213
168221 | ld y, 2
169222 | }
170223 | }
171 = 00c0a900f005a0014c0bc0a00260
224 = $080D LDA #$00
225 = $080F BEQ $0816
226 = $0811 LDY #$01
227 = $0813 JMP $0818
228 = $0816 LDY #$02
229 = $0818 RTS
172230
173231 Compiling `if` without `else`.
174232
180238 | ld y, 1
181239 | }
182240 | }
183 = 00c0a900d002a00160
241 = $080D LDA #$00
242 = $080F BNE $0813
243 = $0811 LDY #$01
244 = $0813 RTS
184245
185246 Compiling `repeat`.
186247
194255 | cmp y, 91
195256 | } until z
196257 | }
197 = 00c0a04198c8c05bd0fa60
258 = $080D LDY #$41
259 = $080F TYA
260 = $0810 INY
261 = $0811 CPY #$5B
262 = $0813 BNE $080F
263 = $0815 RTS
198264
199265 Compiling `repeat until not`.
200266
208274 | cmp y, 91
209275 | } until not z
210276 | }
211 = 00c0a04198c8c05bf0fa60
277 = $080D LDY #$41
278 = $080F TYA
279 = $0810 INY
280 = $0811 CPY #$5B
281 = $0813 BEQ $080F
282 = $0815 RTS
212283
213284 Compiling `repeat forever`.
214285
220291 | inc y
221292 | } forever
222293 | }
223 = 00c0a041c84c02c060
294 = $080D LDY #$41
295 = $080F INY
296 = $0810 JMP $080F
297 = $0813 RTS
224298
225299 Indexed access.
226300
236310 | st a, many + x
237311 | ld a, many + x
238312 | }
239 = 00c0a200a9009d0dc0bd0dc060
240
241 Byte tables take up 256 bytes in memory. This is clearer if you disassemble the output,
242 but what we don't want to see, is something like:
243
244 $800E LDX #$00
245 $8010 LDA $0816,X
246 $8013 STA $0818,X
247 $8016 RTS
313 = $080D LDX #$00
314 = $080F LDA #$00
315 = $0811 STA $0819,X
316 = $0814 LDA $0819,X
317 = $0817 RTS
318
319 Byte tables take up 256 bytes in memory.
248320
249321 | byte table tab1
250322 | byte table tab2
258330 | ld a, tab1 + x
259331 | st a, tab2 + x
260332 | }
261 = 00c0a200bd09c09d0bc060
262
263 Byte storage locations take up only 1 byte in memory. This is clearer if you disassemble the output,
264 but what we don't want to see, is something like:
265
266 $800E LDX #$00
267 $8010 LDA $0816
268 $8013 STA $0818
269 $8016 RTS
333 = $080D LDX #$00
334 = $080F LDA $0816,X
335 = $0812 STA $0916,X
336 = $0815 RTS
337
338 Byte storage locations take up only 1 byte in memory.
270339
271340 | byte one
272341 | byte two
279348 | st a, one
280349 | st a, two
281350 | }
282 = 00c0a200bd09c09d0bc060
351 = $080D LDA #$00
352 = $080F STA $0816
353 = $0812 STA $0817
354 = $0815 RTS
283355
284356 Copy byte to byte.
285357
293365 | {
294366 | copy baz, bar
295367 | }
296 = 00c0ad09c08d07c060
368 = $080D LDA $0815
369 = $0810 STA $0814
370 = $0813 RTS
297371
298372 Copy word to word.
299373
307381 | {
308382 | copy baz, bar
309383 | }
310 = 00c0ad0fc08d0dc0ad10c08d0ec060
384 = $080D LDA $081C
385 = $0810 STA $081A
386 = $0813 LDA $081D
387 = $0816 STA $081B
388 = $0819 RTS
311389
312390 Copy literal word to word.
313391
319397 | {
320398 | copy 2000, bar
321399 | }
322 = 00c0a9d08d0bc0a9078d0cc060
400 = $080D LDA #$D0
401 = $080F STA $0818
402 = $0812 LDA #$07
403 = $0814 STA $0819
404 = $0817 RTS
323405
324406 Copy vector to vector.
325407
333415 | {
334416 | copy baz, bar
335417 | }
336 = 00c0ad0fc08d0dc0ad10c08d0ec060
418 = $080D LDA $081C
419 = $0810 STA $081A
420 = $0813 LDA $081D
421 = $0816 STA $081B
422 = $0819 RTS
337423
338424 Copy routine to vector, inside an `interrupts off` block.
339425
356442 | copy foo, bar
357443 | }
358444 | }
359 = 00c078a90d8d0fc0a9c08d10c05860e860
445 = $080D SEI
446 = $080E LDA #$1A
447 = $0810 STA $081C
448 = $0813 LDA #$08
449 = $0815 STA $081D
450 = $0818 CLI
451 = $0819 RTS
452 = $081A INX
453 = $081B RTS
360454
361455 Copy word to word table and back.
362456
373467 | copy one, many + x
374468 | copy many + x, one
375469 | }
376 = 00c0a200a9009d0dc0bd0dc060....
470 = $080D LDX #$00
471 = $08.. LDA #$D0
472 = $080F STA $0818
473 = $0812 LDA #$07
474 = $0814 STA $0819
475 = ...
476 = $08.. RTS
377477
378478 Indirect call.
379479
387487 | copy bar, foo
388488 | call foo
389489 | }
390 = 00c0a90e8d14c0a9c08d15c02011c060a2c8606c14c0
490 = $080D LDA #$1B
491 = $080F STA $0821
492 = $0812 LDA #$08
493 = $0814 STA $0822
494 = $0817 JSR $081E
495 = $081A RTS
496 = $081B LDX #$C8
497 = $081D RTS
498 = $081E JMP ($0821)
391499
392500 goto.
393501
399507 | ld y, 200
400508 | goto bar
401509 | }
402 = 00c0a0c84c06c060a2c860
510 = $080D LDY #$C8
511 = $080F JMP $0813
512 = $0812 RTS
513 = $0813 LDX #$C8
514 = $0815 RTS
403515
404516 ### word operations
405517
414526 | st off, c
415527 | add score, 1999
416528 | }
417 = 00c018ad12c069cf8d12c0ad13c069078d13c060
529 = $080D CLC
530 = $080E LDA $081F
531 = $0811 ADC #$CF
532 = $0813 STA $081F
533 = $0816 LDA $0820
534 = $0819 ADC #$07
535 = $081B STA $0820
536 = $081E RTS
418537
419538 Adding a word memory location to another word memory location.
420539
428547 | st off, c
429548 | add score, delta
430549 | }
431 = 00c018ad14c06d16c08d14c0ad15c06d17c08d15c060
550 = $080D CLC
551 = $080E LDA $0821
552 = $0811 ADC $0823
553 = $0814 STA $0821
554 = $0817 LDA $0822
555 = $081A ADC $0824
556 = $081D STA $0822
557 = $0820 RTS
432558
433559 ### Buffers and Pointers
434560
445571 | ld y, 0
446572 | copy ^buf, ptr
447573 | }
448 = 00c0a000a90b85fea9c085ff60
574 = $080D LDY #$00
575 = $080F LDA #$18
576 = $0811 STA $FE
577 = $0813 LDA #$08
578 = $0815 STA $FF
579 = $0817 RTS
449580
450581 Write literal through a pointer.
451582
461592 | copy ^buf, ptr
462593 | copy 123, [ptr] + y
463594 | }
464 = 00c0a000a90f85fea9c085ffa97b91fe60
595 = $080D LDY #$00
596 = $080F LDA #$1C
597 = $0811 STA $FE
598 = $0813 LDA #$08
599 = $0815 STA $FF
600 = $0817 LDA #$7B
601 = $0819 STA ($FE),Y
602 = $081B RTS
465603
466604 Write stored value through a pointer.
467605
478616 | copy ^buf, ptr
479617 | copy foo, [ptr] + y
480618 | }
481 = 00c0a000a91085fea9c085ffad12c091fe60
619 = $080D LDY #$00
620 = $080F LDA #$1D
621 = $0811 STA $FE
622 = $0813 LDA #$08
623 = $0815 STA $FF
624 = $0817 LDA $101D
625 = $081A STA ($FE),Y
626 = $081C RTS
482627
483628 Read through a pointer.
484629
495640 | copy ^buf, ptr
496641 | copy [ptr] + y, foo
497642 | }
498 = 00c0a000a91085fea9c085ffb1fe8d12c060
643 = $080D LDY #$00
644 = $080F LDA #$1D
645 = $0811 STA $FE
646 = $0813 LDA #$08
647 = $0815 STA $FF
648 = $0817 LDA ($FE),Y
649 = $0819 STA $101D
650 = $081C RTS
499651
500652 Add a word memory location, and a literal word, to a pointer, and then read through it.
501653 Note that this is *not* range-checked. (Yet.)
517669 | add ptr, word 1
518670 | copy [ptr] + y, foo
519671 | }
520 = 00c0a96b8d38c0a9028d39c0a000a93485fea9c085ffa5fe6d38c085fea5ff6d39c085ffa5fe690185fea5ff690085ffb1fe8d36c060
672 = $080D LDA #$6B
673 = $080F STA $1042
674 = $0812 LDA #$02
675 = $0814 STA $1043
676 = $0817 LDY #$00
677 = $0819 LDA #$41
678 = $081B STA $FE
679 = $081D LDA #$08
680 = $081F STA $FF
681 = $0821 LDA $FE
682 = $0823 ADC $1042
683 = $0826 STA $FE
684 = $0828 LDA $FF
685 = $082A ADC $1043
686 = $082D STA $FF
687 = $082F LDA $FE
688 = $0831 ADC #$01
689 = $0833 STA $FE
690 = $0835 LDA $FF
691 = $0837 ADC #$00
692 = $0839 STA $FF
693 = $083B LDA ($FE),Y
694 = $083D STA $1041
695 = $0840 RTS