n65 0.5.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/.github/workflows/ci.yml +28 -0
  4. data/.gitignore +1 -1
  5. data/.rubocop.yml +125 -0
  6. data/Gemfile +3 -1
  7. data/README.md +3 -20
  8. data/Rakefile +15 -1
  9. data/bin/n65 +2 -0
  10. data/data/opcodes.yaml +39 -39
  11. data/everdrive_transfer/everdrive.rb +175 -0
  12. data/examples/pulse_chord.asm +1 -1
  13. data/examples/scales.asm +182 -0
  14. data/lib/n65/directives/ascii.rb +4 -19
  15. data/lib/n65/directives/bytes.rb +20 -35
  16. data/lib/n65/directives/dw.rb +22 -36
  17. data/lib/n65/directives/enter_scope.rb +14 -30
  18. data/lib/n65/directives/exit_scope.rb +7 -17
  19. data/lib/n65/directives/inc.rb +14 -30
  20. data/lib/n65/directives/incbin.rb +6 -24
  21. data/lib/n65/directives/ines_header.rb +66 -27
  22. data/lib/n65/directives/label.rb +8 -21
  23. data/lib/n65/directives/org.rb +9 -19
  24. data/lib/n65/directives/segment.rb +5 -19
  25. data/lib/n65/directives/space.rb +6 -18
  26. data/lib/n65/front_end.rb +36 -39
  27. data/lib/n65/instruction.rb +123 -159
  28. data/lib/n65/instruction_base.rb +6 -18
  29. data/lib/n65/memory_space.rb +51 -71
  30. data/lib/n65/opcodes.rb +3 -5
  31. data/lib/n65/parser.rb +20 -38
  32. data/lib/n65/regexes.rb +20 -21
  33. data/lib/n65/symbol_table.rb +58 -89
  34. data/lib/n65/version.rb +3 -1
  35. data/lib/n65.rb +120 -121
  36. data/n65.gemspec +17 -12
  37. data/nes_lib/nes.sym +2 -2
  38. data/spec/.rubocop.yml +4 -0
  39. data/spec/assembler_spec.rb +84 -0
  40. data/spec/lib/n65/memory_space_spec.rb +147 -0
  41. data/spec/lib/n65/symbol_table_spec.rb +291 -0
  42. data/utils/opcode_table_to_yaml.rb +65 -67
  43. data.tar.gz.sig +0 -0
  44. metadata +84 -41
  45. metadata.gz.sig +0 -0
  46. data/examples/music_driver.asm +0 -202
  47. data/test/test_memory_space.rb +0 -82
  48. data/test/test_symbol_table.rb +0 -238
  49. data/utils/midi/Makefile +0 -3
  50. data/utils/midi/c_scale.mid +0 -0
  51. data/utils/midi/convert +0 -0
  52. data/utils/midi/guitar.mid +0 -0
  53. data/utils/midi/include/event.h +0 -93
  54. data/utils/midi/include/file.h +0 -57
  55. data/utils/midi/include/helpers.h +0 -14
  56. data/utils/midi/include/track.h +0 -45
  57. data/utils/midi/lil_melody.mid +0 -0
  58. data/utils/midi/mi_feabhra.mid +0 -0
  59. data/utils/midi/midi_to_nes.rb +0 -204
  60. data/utils/midi/source/convert.cpp +0 -16
  61. data/utils/midi/source/event.cpp +0 -96
  62. data/utils/midi/source/file.cpp +0 -37
  63. data/utils/midi/source/helpers.cpp +0 -46
  64. data/utils/midi/source/track.cpp +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 88e99062a3530418a51a0526922501db4618a365
4
- data.tar.gz: 7edbe2868d6c004fbbbd2d350bc5e830a2ce3e42
2
+ SHA256:
3
+ metadata.gz: 4d948f6a095cf3b08252ee1492effbfee7e0f2dd752066b56f20c65e597c6cf2
4
+ data.tar.gz: 14b4fc8bdd0ecd15d39e3f65c3c71f0b9bdd2e12032e8b7bc21c1ad2a37c70dc
5
5
  SHA512:
6
- metadata.gz: ebb762c5d13b3afd91f377843ee3d3a9a5f86ce411a6641ddfa8b079ec5336a8008a542fb38295ccec71bce1738cc7b1f43444ae1ef4ac0c6b7d12d93e1909b2
7
- data.tar.gz: afffcc397378820005841ed1b96476f2c38fb3492ebae275b4840b6870cdd529c4ccb2dee582fb17861b4989a55bed896b995f149380ddbc95802e49592975e8
6
+ metadata.gz: 99f258197dc54ff9b6344082a582d26939c9f92a0706800bbe09b8dd68748b5e9d75064193f44523c6bcb15ae3ac4970887cadea39738e34cb8221072dd06a60
7
+ data.tar.gz: 9414b4416538a4fd583b014846f34120462f554400d3262fa0ec2ca57931ed377374f058262d5895c1bad706951bfdffecd5255bbc11d820f511b112567faf94
checksums.yaml.gz.sig ADDED
Binary file
@@ -0,0 +1,28 @@
1
+ name: N65
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ os: [ubuntu-latest, macos-latest]
15
+ ruby: ['3.2', '4.0']
16
+
17
+ runs-on: ${{ matrix.os }}
18
+ steps:
19
+ - uses: actions/checkout@v6
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler-cache: true
25
+ - name: Install dependencies
26
+ run: bundle install
27
+ - name: Run tests
28
+ run: bundle exec rspec -f d
data/.gitignore CHANGED
@@ -1,6 +1,6 @@
1
- demo.asm
2
1
  *.nes
3
2
  *.nes.yaml
3
+ *.nes.cycles.yaml
4
4
  .DS_Store
5
5
  Desktop.ini
6
6
  Thumbs.db
data/.rubocop.yml ADDED
@@ -0,0 +1,125 @@
1
+ Layout/LineLength:
2
+ Max: 120
3
+
4
+ Naming/MethodParameterName:
5
+ MinNameLength: 1
6
+
7
+ Style/FormatStringToken:
8
+ Enabled: false
9
+
10
+ Style/Documentation:
11
+ Enabled: false
12
+
13
+ Lint/MissingSuper:
14
+ Enabled: false
15
+
16
+ Style/ParallelAssignment:
17
+ Enabled: false
18
+
19
+ Layout/EmptyLinesAroundAttributeAccessor:
20
+ Enabled: true
21
+
22
+ Layout/SpaceAroundMethodCallOperator:
23
+ Enabled: true
24
+
25
+ Lint/BinaryOperatorWithIdenticalOperands:
26
+ Enabled: true
27
+
28
+ Lint/DeprecatedOpenSSLConstant:
29
+ Enabled: true
30
+
31
+ Lint/DuplicateElsifCondition:
32
+ Enabled: true
33
+
34
+ Lint/DuplicateRescueException:
35
+ Enabled: true
36
+
37
+ Lint/EmptyConditionalBody:
38
+ Enabled: true
39
+
40
+ Lint/FloatComparison:
41
+ Enabled: true
42
+
43
+ Lint/MixedRegexpCaptureTypes:
44
+ Enabled: true
45
+
46
+ Lint/OutOfRangeRegexpRef:
47
+ Enabled: true
48
+
49
+ Lint/RaiseException:
50
+ Enabled: true
51
+
52
+ Lint/SelfAssignment:
53
+ Enabled: true
54
+
55
+ Lint/StructNewOverride:
56
+ Enabled: true
57
+
58
+ Lint/TopLevelReturnWithArgument:
59
+ Enabled: true
60
+
61
+ Lint/UnreachableLoop:
62
+ Enabled: true
63
+
64
+ Style/AccessorGrouping:
65
+ Enabled: true
66
+
67
+ Style/ArrayCoercion:
68
+ Enabled: true
69
+
70
+ Style/BisectedAttrAccessor:
71
+ Enabled: true
72
+
73
+ Style/CaseLikeIf:
74
+ Enabled: true
75
+
76
+ Style/ExplicitBlockArgument:
77
+ Enabled: true
78
+
79
+ Style/ExponentialNotation:
80
+ Enabled: true
81
+
82
+ Style/GlobalStdStream:
83
+ Enabled: true
84
+
85
+ Style/HashAsLastArrayItem:
86
+ Enabled: true
87
+
88
+ Style/HashEachMethods:
89
+ Enabled: true
90
+
91
+ Style/HashLikeCase:
92
+ Enabled: true
93
+
94
+ Style/HashTransformKeys:
95
+ Enabled: true
96
+
97
+ Style/HashTransformValues:
98
+ Enabled: true
99
+
100
+ Style/OptionalBooleanParameter:
101
+ Enabled: true
102
+
103
+ Style/RedundantAssignment:
104
+ Enabled: true
105
+
106
+ Style/RedundantFetchBlock:
107
+ Enabled: true
108
+
109
+ Style/RedundantFileExtensionInRequire:
110
+ Enabled: true
111
+
112
+ Style/RedundantRegexpCharacterClass:
113
+ Enabled: true
114
+
115
+ Style/RedundantRegexpEscape:
116
+ Enabled: true
117
+
118
+ Style/SingleArgumentDig:
119
+ Enabled: true
120
+
121
+ Style/SlicingWithRange:
122
+ Enabled: true
123
+
124
+ Style/StringConcatenation:
125
+ Enabled: true
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
- # Specify your gem's dependencies in n65.gemspec
5
+ # Specify gem dependencies in n65.gemspec
4
6
  gemspec
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # N65 NES assembler version 0.5
1
+ # N65 NES assembler
2
2
 
3
3
  This is an assembler for the Nintendo Entertainment System's 2A03
4
4
  microprocessor.
5
5
 
6
+ ![N65](https://github.com/safiire/n65/workflows/N65/badge.svg)
7
+
6
8
  The 2A03 is an 8-bit processor based on the MOS 6502.
7
9
 
8
10
  ```bash
@@ -69,22 +71,6 @@ The 2A03 is an 8-bit processor based on the MOS 6502.
69
71
  There is an example file included (shown below) that is a modified port of
70
72
  the NES101 tutorial by Michael Martin.
71
73
 
72
- # MIDI converter
73
-
74
- Included in the utils/midi directory is a my first version of a MIDI
75
- to NES music converter, which is composed of a Ruby script backed
76
- by a C++ program I wrote to parse MIDI files into YAML data.
77
-
78
- At present, it can convert a MIDI file to a binary stream of values
79
- that, when written to the APU in your 60hz VBlank, can be played
80
- by the included sound driver code.
81
-
82
- The idea is to be able to compose music for the NES using your
83
- favourite digital audio workstation in MIDI, and be able to convert
84
- the square, triangle, and noise sequences to something playable
85
- on the NES.
86
-
87
-
88
74
  # Some new additions:
89
75
  - .byte can now handle hex and binary literals, and symbols
90
76
  - First version of Midi to NES music converter
@@ -119,8 +105,5 @@ The 2A03 is an 8-bit processor based on the MOS 6502.
119
105
  - Tested a ROM that changes background color
120
106
 
121
107
  # Some Todos:
122
- - Create NES music from MIDI files easily
123
108
  - Make macros that can be used interchangably inline or as a subroutine
124
109
  - Create a library for common operations, DMA, sound, etc both inline and subroutine options
125
- - Create an interactive read eval compile loop?
126
-
data/Rakefile CHANGED
@@ -1,2 +1,16 @@
1
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
2
 
3
+ require 'bundler/gem_tasks'
4
+
5
+ begin
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ task(default: :spec)
9
+ rescue LoadError
10
+ warn("Couldn't load RSpec gem")
11
+ end
12
+
13
+ # Check the syntax of all Ruby files
14
+ task :syntax do
15
+ sh 'find . -name *.rb -type f -exec ruby -c {} \; -exec echo {} \;'
16
+ end
data/bin/n65 CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  ###############################################################################
3
5
  ## 6502 Assembler for the NES's 2A03
4
6
  ##
data/data/opcodes.yaml CHANGED
@@ -1,17 +1,17 @@
1
1
  ---
2
2
  :adc:
3
3
  :description: "ADd with Carry"
4
- :flags:
4
+ :flags:
5
5
  - :s
6
6
  - :v
7
7
  - :z
8
8
  - :c
9
- :immediate:
9
+ :immediate:
10
10
  :hex: 0x69
11
11
  :len: 2
12
12
  :cycles: 2
13
13
  :boundry_add: false
14
- :zero_page:
14
+ :zero_page:
15
15
  :hex: 0x65
16
16
  :len: 2
17
17
  :cycles: 3
@@ -49,7 +49,7 @@
49
49
 
50
50
  :and:
51
51
  :description: "bitwise AND with accumulator"
52
- :flags:
52
+ :flags:
53
53
  - :s
54
54
  - :z
55
55
  :immediate:
@@ -95,7 +95,7 @@
95
95
 
96
96
  :asl:
97
97
  :description: "Arithmetic Shift Left"
98
- :flags:
98
+ :flags:
99
99
  - :s
100
100
  - :z
101
101
  - :c
@@ -127,7 +127,7 @@
127
127
 
128
128
  :bit:
129
129
  :description: "test BITs"
130
- :flags:
130
+ :flags:
131
131
  - :n
132
132
  - :v
133
133
  - :z
@@ -202,9 +202,9 @@
202
202
 
203
203
  :brk:
204
204
  :description: "BReaK"
205
- :flags:
205
+ :flags:
206
206
  - :b
207
- :implied:
207
+ :implied:
208
208
  :hex: 0x0
209
209
  :len: 1
210
210
  :cycles: 7
@@ -212,7 +212,7 @@
212
212
 
213
213
  :cmp:
214
214
  :description: "CoMPare accumulator"
215
- :flags:
215
+ :flags:
216
216
  - :s
217
217
  - :c
218
218
  - :z
@@ -259,7 +259,7 @@
259
259
 
260
260
  :cpx:
261
261
  :description: "ComPare X register"
262
- :flags:
262
+ :flags:
263
263
  - :s
264
264
  - :c
265
265
  - :z
@@ -281,7 +281,7 @@
281
281
 
282
282
  :cpy:
283
283
  :description: "ComPare Y register"
284
- :flags:
284
+ :flags:
285
285
  - :s
286
286
  - :c
287
287
  - :z
@@ -303,7 +303,7 @@
303
303
 
304
304
  :dec:
305
305
  description: "DECrement memory"
306
- :flags:
306
+ :flags:
307
307
  - :s
308
308
  - :z
309
309
  :zero_page:
@@ -329,7 +329,7 @@
329
329
 
330
330
  :eor:
331
331
  :description: "bitwise Exclusive OR"
332
- :flags:
332
+ :flags:
333
333
  - :s
334
334
  - :z
335
335
  :immediate:
@@ -375,7 +375,7 @@
375
375
 
376
376
  :clc:
377
377
  :description: "CLear Carry"
378
- :flags:
378
+ :flags:
379
379
  - :c
380
380
  :implied:
381
381
  :hex: 0x18
@@ -383,7 +383,7 @@
383
383
  :cycles: 2
384
384
  :sec:
385
385
  :description: "SEt Carry"
386
- :flags:
386
+ :flags:
387
387
  - :c
388
388
  :implied:
389
389
  :hex: 0x38
@@ -391,7 +391,7 @@
391
391
  :cycles: 2
392
392
  :cli:
393
393
  :description: "CLear Interrupt"
394
- :flags:
394
+ :flags:
395
395
  - :i
396
396
  :implied:
397
397
  :hex: 0x58
@@ -399,7 +399,7 @@
399
399
  :cycles: 2
400
400
  :sei:
401
401
  :description: "SEt Interrupt"
402
- :flags:
402
+ :flags:
403
403
  - :i
404
404
  :implied:
405
405
  :hex: 0x78
@@ -407,7 +407,7 @@
407
407
  :cycles: 2
408
408
  :clv:
409
409
  :description: "CLear oVerflow"
410
- :flags:
410
+ :flags:
411
411
  - :v
412
412
  :implied:
413
413
  :hex: 0xB8
@@ -415,7 +415,7 @@
415
415
  :cycles: 2
416
416
  :cld:
417
417
  :description: "CLear Decimal"
418
- :flags:
418
+ :flags:
419
419
  - :d
420
420
  :implied:
421
421
  :hex: 0xD8
@@ -423,7 +423,7 @@
423
423
  :cycles: 2
424
424
  :sed:
425
425
  :description: "SEt Decimal"
426
- :flags:
426
+ :flags:
427
427
  - :d
428
428
  :implied:
429
429
  :hex: 0xF8
@@ -432,7 +432,7 @@
432
432
 
433
433
  :inc:
434
434
  :description: "INCrement memory"
435
- :flags:
435
+ :flags:
436
436
  - :s
437
437
  - :z
438
438
  :zero_page:
@@ -481,7 +481,7 @@
481
481
 
482
482
  :lda:
483
483
  :description: "LoaD Accumulator"
484
- :flags:
484
+ :flags:
485
485
  - :s
486
486
  - :z
487
487
  :immediate:
@@ -527,7 +527,7 @@
527
527
 
528
528
  :ldx:
529
529
  :description: "LoaD X register"
530
- :flags:
530
+ :flags:
531
531
  - :s
532
532
  - :z
533
533
  :immediate:
@@ -558,7 +558,7 @@
558
558
 
559
559
  :ldy:
560
560
  :description: "LoaD Y register"
561
- :flags:
561
+ :flags:
562
562
  - :s
563
563
  - :z
564
564
  :immediate:
@@ -589,7 +589,7 @@
589
589
 
590
590
  :lsr:
591
591
  :description: "Logical Shift Right"
592
- :flags:
592
+ :flags:
593
593
  - :s
594
594
  - :z
595
595
  - :c
@@ -630,7 +630,7 @@
630
630
 
631
631
  :ora:
632
632
  :description: "bitwise OR with Accumulator"
633
- :flags:
633
+ :flags:
634
634
  - :s
635
635
  - :z
636
636
  :immediate:
@@ -676,7 +676,7 @@
676
676
 
677
677
  :tax:
678
678
  :description: "Transfer A to X"
679
- :flags:
679
+ :flags:
680
680
  - :s
681
681
  - :z
682
682
  :implied:
@@ -686,7 +686,7 @@
686
686
  :boundry_add: false
687
687
  :txa:
688
688
  :description: "Transfer X to A"
689
- :flags:
689
+ :flags:
690
690
  - :s
691
691
  - :z
692
692
  :implied:
@@ -696,7 +696,7 @@
696
696
  :boundry_add: false
697
697
  :dex:
698
698
  :description: "DEcrement X"
699
- :flags:
699
+ :flags:
700
700
  - :s
701
701
  - :z
702
702
  :implied:
@@ -706,7 +706,7 @@
706
706
  :boundry_add: false
707
707
  :inx:
708
708
  :description: "INcrement X"
709
- :flags:
709
+ :flags:
710
710
  - :s
711
711
  - :z
712
712
  :implied:
@@ -716,7 +716,7 @@
716
716
  :boundry_add: false
717
717
  :tay:
718
718
  :description: "Transfer A to Y"
719
- :flags:
719
+ :flags:
720
720
  - :s
721
721
  - :z
722
722
  :implied:
@@ -726,7 +726,7 @@
726
726
  :boundry_add: false
727
727
  :tya:
728
728
  :description: "Transfer Y to A"
729
- :flags:
729
+ :flags:
730
730
  - :s
731
731
  - :z
732
732
  :implied:
@@ -736,7 +736,7 @@
736
736
  :boundry_add: false
737
737
  :dey:
738
738
  :description: "DEcrement Y"
739
- :flags:
739
+ :flags:
740
740
  - :s
741
741
  - :z
742
742
  :implied:
@@ -746,7 +746,7 @@
746
746
  :boundry_add: false
747
747
  :iny:
748
748
  :description: "INcrement Y"
749
- :flags:
749
+ :flags:
750
750
  - :s
751
751
  - :z
752
752
  :implied:
@@ -757,7 +757,7 @@
757
757
 
758
758
  :rol:
759
759
  :description: "ROtate Left"
760
- :flags:
760
+ :flags:
761
761
  - :s
762
762
  - :z
763
763
  - :c
@@ -789,7 +789,7 @@
789
789
 
790
790
  :ror:
791
791
  :description: "ROtate Right"
792
- :flags:
792
+ :flags:
793
793
  - :s
794
794
  - :z
795
795
  - :c
@@ -821,7 +821,7 @@
821
821
 
822
822
  :rti:
823
823
  :description: "ReTurn from Interrupt, TODO: Flags could be wrong"
824
- :flags:
824
+ :flags:
825
825
  - :n
826
826
  - :v
827
827
  - :u
@@ -847,7 +847,7 @@
847
847
 
848
848
  :sbc:
849
849
  :description: "SuBtract with Carry"
850
- :flags:
850
+ :flags:
851
851
  - :s
852
852
  - :v
853
853
  - :z
@@ -976,7 +976,7 @@
976
976
  :boundry_add: false
977
977
  :plp:
978
978
  :description: "PuLl Processor status"
979
- :flags:
979
+ :flags:
980
980
  - :n
981
981
  - :v
982
982
  - :u