nurpax / c64jasm

C64 6502 assembler in TypeScript
51 stars 14 forks source link

added label support in disassembly (see issue #71) #73

Closed shazz closed 3 years ago

shazz commented 4 years ago

I never coded anything with Typescript so probably not the best way to do but at least it works. You'll tell me what to change :)

Basically what it does:

Execution example:

node cli.js ../../examples/sprites/sprites.asm --out ../../dummy.prg --disasm
Compiling ../../examples/sprites/sprites.asm
Compilation succeeded.  Output written to ../../dummy.prg
0801: 0C 08 00 00 9E 32 30 36
0809: 31 00 00 00
080D: 20 8C 08 frame_loop           JSR $088C
0810: A9 00                         LDA #$00
0812: A8                            TAY
0813: 85 20                         STA $20
0815: AD 9B 08 anim_sprites         LDA $089B
0818: 18                            CLC
0819: 65 20                         ADC $20
081B: 29 3F                         AND #$3F
081D: AA                            TAX
081E: BD AC 08                      LDA $08AC,X
0821: 18                            CLC
0822: 69 64                         ADC #$64
0824: 99 9C 08                      STA $089C,Y
0827: A5 20                         LDA $20
0829: 18                            CLC
082A: 69 05                         ADC #$05
082C: 85 20                         STA $20
082E: C8                            INY
082F: C0 08                         CPY #$08
0831: D0 E2                         BNE $0815
0833: EE 9B 08                      INC $089B
0836: 20 3C 08                      JSR $083C
0839: 4C 0D 08                      JMP $080D
083C: A9 00    set_sprites          LDA #$00
083E: 8D 1D D0                      STA $D01D
0841: 8D 17 D0                      STA $D017
0844: 8D 1C D0                      STA $D01C
0847: A9 24                         LDA #$24
0849: 8D F8 07                      STA $07F8
084C: 8D F9 07                      STA $07F9
084F: 8D FA 07                      STA $07FA
0852: 8D FB 07                      STA $07FB
0855: 8D FC 07                      STA $07FC
0858: 8D FD 07                      STA $07FD
085B: 8D FE 07                      STA $07FE
085E: 8D FF 07                      STA $07FF
0861: A9 1E                         LDA #$1E
0863: 85 20                         STA $20
0865: A2 00                         LDX #$00
0867: A0 00                         LDY #$00
0869: A5 20    set_sprites::xloop   LDA $20
086B: 9D 00 D0                      STA $D000,X
shazz commented 4 years ago

I also added the cycle count estimation by opcode

Output:

0801: 0C 08 00 00 9E 32 30 36
0809: 31 00 00 00
080D: 20 8C 08 frame_loop                                       JSR $088C   ; #6
0810: A9 00                                                     LDA #$00    ; #2
0812: A8                                                        TAY ; #2
0813: 85 20                                                     STA $20 ; #3
0815: AD 9B 08 anim_sprites                                     LDA $089B   ; #4
0818: 18                                                        CLC ; #2
0819: 65 20                                                     ADC $20 ; #3
081B: 29 3F                                                     AND #$3F    ; #2
081D: AA                                                        TAX ; #2
081E: BD AC 08                                                  LDA $08AC,X ; #4
0821: 18                                                        CLC ; #2
0822: 69 64                                                     ADC #$64    ; #2
0824: 99 9C 08                                                  STA $089C,Y ; #5
0827: A5 20                                                     LDA $20 ; #3
0829: 18                                                        CLC ; #2
082A: 69 05                                                     ADC #$05    ; #2
082C: 85 20                                                     STA $20 ; #3
082E: C8                                                        INY ; #2
082F: C0 08                                                     CPY #$08    ; #2
0831: D0 E2                                                     BNE $0815   ; #2
0833: EE 9B 08                                                  INC $089B   ; #6
0836: 20 3C 08                                                  JSR $083C   ; #6
0839: 4C 0D 08                                                  JMP $080D   ; #3
083C: A9 00    set_sprites                                      LDA #$00    ; #2
083E: 8D 1D D0                                                  STA $D01D   ; #4
nurpax commented 3 years ago

Sorry, this fell through the cracks, perhaps I will now have a bit of time to work on the assembler.

The feature looks very useful. How would you feel about changing the formatting a bit.. by moving the labels into the right sight in comments? Reason: having them in the hex byte data will increase the left margin significantly making the disassembly look ugly with longer labels. At least I'd like them on the right side.

I could pick this change and adapt it for different output format.

shazz commented 3 years ago

yeah formatting the way I did with possibly very long labels is not that good. Better your way I guess. Yes, please pick it up and improve it.

nurpax commented 3 years ago

Merged! Thank you very much, it's a really useful addition!

Added some minor clean up and enable/disable CLI options here: 6983fd06ff94abb16f17cbeef158d459fcb3735f

shazz commented 3 years ago

better like this :) Now I can delete my branches... I think I had another patch to save the listing using

parser.addArgument('--disasm-file', {
    dest: 'disasmFile',
    help: 'Save the disassembly in the given file.'
});
nurpax commented 3 years ago

Yes that was in https://github.com/nurpax/c64jasm/commit/c00b5545df66df95c4a46ea5eba12c042ca6d63e which is also in now.