c8dasm 0.99.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +15 -0
- data/README.md +109 -0
- data/Rakefile +7 -0
- data/bin/c8dasm +13 -0
- data/c8dasm.gemspec +24 -0
- data/lib/c8dasm.rb +11 -0
- data/lib/c8dasm/assemblies.rb +18 -0
- data/lib/c8dasm/assemblies/asm0.rb +15 -0
- data/lib/c8dasm/assemblies/asm1.rb +10 -0
- data/lib/c8dasm/assemblies/asm2.rb +10 -0
- data/lib/c8dasm/assemblies/asm3.rb +10 -0
- data/lib/c8dasm/assemblies/asm4.rb +9 -0
- data/lib/c8dasm/assemblies/asm5.rb +12 -0
- data/lib/c8dasm/assemblies/asm6.rb +9 -0
- data/lib/c8dasm/assemblies/asm7.rb +9 -0
- data/lib/c8dasm/assemblies/asm8.rb +23 -0
- data/lib/c8dasm/assemblies/asm9.rb +11 -0
- data/lib/c8dasm/assemblies/asm_base.rb +26 -0
- data/lib/c8dasm/assemblies/asma.rb +11 -0
- data/lib/c8dasm/assemblies/asmb.rb +12 -0
- data/lib/c8dasm/assemblies/asmc.rb +11 -0
- data/lib/c8dasm/assemblies/asmd.rb +11 -0
- data/lib/c8dasm/assemblies/asme.rb +16 -0
- data/lib/c8dasm/assemblies/asmf.rb +20 -0
- data/lib/c8dasm/assembly.rb +22 -0
- data/lib/c8dasm/chip8_reader.rb +38 -0
- data/lib/c8dasm/comment.rb +23 -0
- data/lib/c8dasm/comments.rb +17 -0
- data/lib/c8dasm/comments/comment0.rb +14 -0
- data/lib/c8dasm/comments/comment1.rb +10 -0
- data/lib/c8dasm/comments/comment2.rb +11 -0
- data/lib/c8dasm/comments/comment3.rb +11 -0
- data/lib/c8dasm/comments/comment4.rb +11 -0
- data/lib/c8dasm/comments/comment5.rb +12 -0
- data/lib/c8dasm/comments/comment6.rb +11 -0
- data/lib/c8dasm/comments/comment7.rb +11 -0
- data/lib/c8dasm/comments/comment8.rb +25 -0
- data/lib/c8dasm/comments/comment9.rb +11 -0
- data/lib/c8dasm/comments/comment_base.rb +26 -0
- data/lib/c8dasm/comments/commenta.rb +11 -0
- data/lib/c8dasm/comments/commentb.rb +12 -0
- data/lib/c8dasm/comments/commentc.rb +11 -0
- data/lib/c8dasm/comments/commentd.rb +11 -0
- data/lib/c8dasm/comments/commente.rb +15 -0
- data/lib/c8dasm/comments/commentf.rb +30 -0
- data/lib/c8dasm/opcode.rb +34 -0
- data/lib/c8dasm/version.rb +3 -0
- data/spec/15-puzzle.ch8 +0 -0
- data/spec/MAZE +0 -0
- data/spec/c8dasm_spec.rb +7 -0
- data/spec/chip8_reader_spec.rb +27 -0
- data/spec/opcode_0_spec.rb +39 -0
- data/spec/opcode_1_spec.rb +23 -0
- data/spec/opcode_2_spec.rb +23 -0
- data/spec/opcode_3_spec.rb +23 -0
- data/spec/opcode_4_spec.rb +23 -0
- data/spec/opcode_5_spec.rb +25 -0
- data/spec/opcode_6_spec.rb +23 -0
- data/spec/opcode_7_spec.rb +23 -0
- data/spec/opcode_8_spec.rb +119 -0
- data/spec/opcode_9_spec.rb +24 -0
- data/spec/opcode_a_spec.rb +23 -0
- data/spec/opcode_b_spec.rb +24 -0
- data/spec/opcode_c_spec.rb +23 -0
- data/spec/opcode_d_spec.rb +23 -0
- data/spec/opcode_e_spec.rb +39 -0
- data/spec/opcode_f_spec.rb +151 -0
- data/spec/opcode_spec.rb +45 -0
- data/spec/spec_helper.rb +2 -0
- metadata +183 -0
data/spec/15-puzzle.ch8
ADDED
Binary file
|
data/spec/MAZE
ADDED
Binary file
|
data/spec/c8dasm_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include C8dasm
|
4
|
+
|
5
|
+
describe Chip8Reader do
|
6
|
+
|
7
|
+
before do
|
8
|
+
reader = Chip8Reader.new('./spec/MAZE')
|
9
|
+
@opcodes = reader.opcodes
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns the right amount of opcodes' do
|
13
|
+
expect(@opcodes.size).to eq 17
|
14
|
+
end
|
15
|
+
|
16
|
+
specify 'an opcode is a string' do
|
17
|
+
expect(@opcodes.first).to be_a String
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "MAZE's opcodes" do
|
21
|
+
specify { expect(@opcodes[0]).to eq 'a21e' }
|
22
|
+
specify { expect(@opcodes[2]).to eq '3201' }
|
23
|
+
specify { expect(@opcodes[8]).to eq '6000' }
|
24
|
+
specify { expect(@opcodes[16]).to eq '8010' }
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include C8dasm
|
4
|
+
|
5
|
+
describe Opcode do
|
6
|
+
|
7
|
+
describe '00e0' do
|
8
|
+
before { @opcode = Opcode.new('00e0') }
|
9
|
+
|
10
|
+
it 'returns the opcode' do
|
11
|
+
expect(@opcode.opcode).to eq '00e0'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns the assembly' do
|
15
|
+
expect(@opcode.assembly).to eq 'CLS'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns a comment' do
|
19
|
+
expect(@opcode.comment).to eq 'Clear the display.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '00ee' do
|
24
|
+
before { @opcode = Opcode.new('00ee') }
|
25
|
+
|
26
|
+
it 'returns the opcode' do
|
27
|
+
expect(@opcode.opcode).to eq '00ee'
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns the assembly' do
|
31
|
+
expect(@opcode.assembly).to eq 'RET'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns a comment' do
|
35
|
+
expect(@opcode.comment).to eq 'Returns from this subroutine.'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include C8dasm
|
4
|
+
|
5
|
+
describe Opcode do
|
6
|
+
|
7
|
+
describe '1200' do
|
8
|
+
before { @opcode = Opcode.new('1200') }
|
9
|
+
|
10
|
+
it 'returns the opcode' do
|
11
|
+
expect(@opcode.opcode).to eq '1200'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns the assembly' do
|
15
|
+
expect(@opcode.assembly).to eq 'JP 200'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns a comment' do
|
19
|
+
expect(@opcode.comment).to eq 'Jump to location 200.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include C8dasm
|
4
|
+
|
5
|
+
describe Opcode do
|
6
|
+
|
7
|
+
describe '22a2' do
|
8
|
+
before { @opcode = Opcode.new('22a2') }
|
9
|
+
|
10
|
+
it 'returns the opcode' do
|
11
|
+
expect(@opcode.opcode).to eq '22a2'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns the assembly' do
|
15
|
+
expect(@opcode.assembly).to eq 'CALL 2a2'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns a comment' do
|
19
|
+
expect(@opcode.comment).to eq 'Call subroutine at 2a2.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include C8dasm
|
4
|
+
|
5
|
+
describe Opcode do
|
6
|
+
|
7
|
+
describe '3201' do
|
8
|
+
before { @opcode = Opcode.new('3201') }
|
9
|
+
|
10
|
+
it 'returns the opcode' do
|
11
|
+
expect(@opcode.opcode).to eq '3201'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns the assembly' do
|
15
|
+
expect(@opcode.assembly).to eq 'SE V2, 01'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns a comment' do
|
19
|
+
expect(@opcode.comment).to eq 'Skip next instruction if V2 = 01.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include C8dasm
|
4
|
+
|
5
|
+
describe Opcode do
|
6
|
+
|
7
|
+
describe '4800' do
|
8
|
+
before { @opcode = Opcode.new('4800') }
|
9
|
+
|
10
|
+
it 'returns the opcode' do
|
11
|
+
expect(@opcode.opcode).to eq '4800'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns the assembly' do
|
15
|
+
expect(@opcode.assembly).to eq 'SNE V8, 00'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns a comment' do
|
19
|
+
expect(@opcode.comment).to eq 'Skip next instruction if V8 != 00.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include C8dasm
|
4
|
+
|
5
|
+
describe Opcode do
|
6
|
+
|
7
|
+
describe '5210' do
|
8
|
+
before { @opcode = Opcode.new('5210') }
|
9
|
+
|
10
|
+
it 'returns the opcode' do
|
11
|
+
expect(@opcode.opcode).to eq '5210'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns the assembly' do
|
15
|
+
expect(@opcode.assembly).to eq 'SE V2, V1'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns a comment' do
|
19
|
+
expect(@opcode.comment).to eq 'Skip next instruction if V2 = V1.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include C8dasm
|
4
|
+
|
5
|
+
describe Opcode do
|
6
|
+
|
7
|
+
describe '6012' do
|
8
|
+
before { @opcode = Opcode.new('6012') }
|
9
|
+
|
10
|
+
it 'returns the opcode' do
|
11
|
+
expect(@opcode.opcode).to eq '6012'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns the assembly' do
|
15
|
+
expect(@opcode.assembly).to eq 'LD V0, 12'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns a comment' do
|
19
|
+
expect(@opcode.comment).to eq 'Puts the value 12 into register V0.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include C8dasm
|
4
|
+
|
5
|
+
describe Opcode do
|
6
|
+
|
7
|
+
describe '7004' do
|
8
|
+
before { @opcode = Opcode.new('7004') }
|
9
|
+
|
10
|
+
it 'returns the opcode' do
|
11
|
+
expect(@opcode.opcode).to eq '7004'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns the assembly' do
|
15
|
+
expect(@opcode.assembly).to eq 'ADD V0, 04'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns a comment' do
|
19
|
+
expect(@opcode.comment).to eq 'V0 = V0 + 04.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include C8dasm
|
4
|
+
|
5
|
+
describe Opcode do
|
6
|
+
|
7
|
+
describe '8a10' do
|
8
|
+
before { @opcode = Opcode.new('8a10') }
|
9
|
+
|
10
|
+
it 'returns the opcode' do
|
11
|
+
expect(@opcode.opcode).to eq '8a10'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns the assembly' do
|
15
|
+
expect(@opcode.assembly).to eq 'LD Va, V1'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns a comment' do
|
19
|
+
expect(@opcode.comment).to eq 'Set Va = V1.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '8d52' do
|
24
|
+
before { @opcode = Opcode.new('8d52') }
|
25
|
+
|
26
|
+
it 'returns the opcode' do
|
27
|
+
expect(@opcode.opcode).to eq '8d52'
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns the assembly' do
|
31
|
+
expect(@opcode.assembly).to eq 'AND Vd, V5'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns a comment' do
|
35
|
+
expect(@opcode.comment).to eq 'Set Vd = Vd AND V5.'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '8903' do
|
40
|
+
before { @opcode = Opcode.new('8903') }
|
41
|
+
|
42
|
+
it 'returns the opcode' do
|
43
|
+
expect(@opcode.opcode).to eq '8903'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns the assembly' do
|
47
|
+
expect(@opcode.assembly).to eq 'XOR V9, V0'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns a comment' do
|
51
|
+
expect(@opcode.comment).to eq 'Set V9 = V9 XOR V0.'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '8bd4' do
|
56
|
+
before { @opcode = Opcode.new('8bd4') }
|
57
|
+
|
58
|
+
it 'returns the opcode' do
|
59
|
+
expect(@opcode.opcode).to eq '8bd4'
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'returns the assembly' do
|
63
|
+
expect(@opcode.assembly).to eq 'ADD Vb, Vd'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns a comment' do
|
67
|
+
expect(@opcode.comment).to eq 'Set Vb = Vb + Vd, set VF = carry.'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '8b25' do
|
72
|
+
before { @opcode = Opcode.new('8b25') }
|
73
|
+
|
74
|
+
it 'returns the opcode' do
|
75
|
+
expect(@opcode.opcode).to eq '8b25'
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'returns the assembly' do
|
79
|
+
expect(@opcode.assembly).to eq 'SUB Vb, V2'
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'returns a comment' do
|
83
|
+
expect(@opcode.comment).to eq 'Set Vb = Vb - V2, set VF = NOT borrow.'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '87a6' do
|
88
|
+
before { @opcode = Opcode.new('87a6') }
|
89
|
+
|
90
|
+
it 'returns the opcode' do
|
91
|
+
expect(@opcode.opcode).to eq '87a6'
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'returns the assembly' do
|
95
|
+
expect(@opcode.assembly).to eq 'SHR V7, Va'
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'returns a comment' do
|
99
|
+
expect(@opcode.comment).to eq 'Set V7 = Va SHR 1.'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe '87ae' do
|
104
|
+
before { @opcode = Opcode.new('87ae') }
|
105
|
+
|
106
|
+
it 'returns the opcode' do
|
107
|
+
expect(@opcode.opcode).to eq '87ae'
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'returns the assembly' do
|
111
|
+
expect(@opcode.assembly).to eq 'SHL V7, Va'
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'returns a comment' do
|
115
|
+
expect(@opcode.comment).to eq 'Set V7 = Va SHL 1.'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include C8dasm
|
4
|
+
|
5
|
+
describe Opcode do
|
6
|
+
|
7
|
+
describe '9210' do
|
8
|
+
before { @opcode = Opcode.new('9210') }
|
9
|
+
|
10
|
+
it 'returns the opcode' do
|
11
|
+
expect(@opcode.opcode).to eq '9210'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns the assembly' do
|
15
|
+
expect(@opcode.assembly).to eq 'SNE V2, V1'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns a comment' do
|
19
|
+
expect(@opcode.comment).to eq 'Skip next instruction if V2 != V1.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include C8dasm
|
4
|
+
|
5
|
+
describe Opcode do
|
6
|
+
|
7
|
+
describe 'a21e' do
|
8
|
+
before { @opcode = Opcode.new('a21e') }
|
9
|
+
|
10
|
+
it 'returns the opcode' do
|
11
|
+
expect(@opcode.opcode).to eq 'a21e'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns the assembly' do
|
15
|
+
expect(@opcode.assembly).to eq 'LD I, 21e'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns a comment' do
|
19
|
+
expect(@opcode.comment).to eq 'Puts 21e into register I.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include C8dasm
|
4
|
+
|
5
|
+
describe Opcode do
|
6
|
+
|
7
|
+
describe 'b123' do
|
8
|
+
before { @opcode = Opcode.new('b123') }
|
9
|
+
|
10
|
+
it 'returns the opcode' do
|
11
|
+
expect(@opcode.opcode).to eq 'b123'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns the assembly' do
|
15
|
+
expect(@opcode.assembly).to eq 'JP V0, 123'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns a comment' do
|
19
|
+
expect(@opcode.comment).to eq 'Jump to location 123 + V0.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|