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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 960ec7c6a8d76ad08c1b481f63e40788d3b2547c
|
4
|
+
data.tar.gz: f1a9a569beebd417784cc90c04513762d691d769
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d1f105e12fe48146e976436b1c68208698d9f8d536af64e2841a5fc70c78144d280e80951fdcf1eff4586454e15817cfe50bcef36f17a5797169df04150a2fb6
|
7
|
+
data.tar.gz: acd3e8a7b88ab659522d057494aa704905018d8238a3f80840896da7c78db34e871747055c0dd5a03189eee28ec7c161bea1c36055101c62a5aafe84f1d05c7d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
c8dasm - a disassembler for chip8
|
2
|
+
Copyright (C) 2015 Xavier Nayrac
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# C8dasm
|
2
|
+
|
3
|
+
`c8dasm` is a utility to disassemble a Chip8 binary file.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install it as:
|
8
|
+
|
9
|
+
$ gem install c8dasm
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
$ c8dasm chip8file
|
14
|
+
|
15
|
+
### Example
|
16
|
+
|
17
|
+
$ c8dasm MAZE
|
18
|
+
200:a21e LD I, 21e ;Puts 21e into register I.
|
19
|
+
202:c201 RND V2, 01 ;Puts random byte AND 01 into register V2.
|
20
|
+
204:3201 SE V2, 01 ;Skip next instruction if V2 = 01.
|
21
|
+
206:a21a LD I, 21a ;Puts 21a into register I.
|
22
|
+
208:d014 DRW V0, V1, 4 ;Draws 4-byte sprite from I at (V0, V1)
|
23
|
+
20a:7004 ADD V0, 04 ;V0 = V0 + 04.
|
24
|
+
20c:3040 SE V0, 40 ;Skip next instruction if V0 = 40.
|
25
|
+
20e:1200 JP 200 ;Jump to location 200.
|
26
|
+
210:6000 LD V0, 00 ;Puts the value 00 into register V0.
|
27
|
+
212:7104 ADD V1, 04 ;V1 = V1 + 04.
|
28
|
+
...
|
29
|
+
|
30
|
+
## License
|
31
|
+
|
32
|
+
GPLv3
|
33
|
+
|
34
|
+
## Standard Chip-8 Instructions (What's remain to do)
|
35
|
+
|
36
|
+
- [x] 00E0 - CLS
|
37
|
+
- [x] 00EE - RET
|
38
|
+
- [ ] 0nnn - SYS addr
|
39
|
+
- [x] 1nnn - JP addr
|
40
|
+
- [x] 2nnn - CALL addr
|
41
|
+
- [x] 3xkk - SE Vx, byte
|
42
|
+
- [x] 4xkk - SNE Vx, byte
|
43
|
+
- [x] 5xy0 - SE Vx, Vy
|
44
|
+
- [x] 6xkk - LD Vx, byte
|
45
|
+
- [x] 7xkk - ADD Vx, byte
|
46
|
+
- [x] 8xy0 - LD Vx, Vy
|
47
|
+
- [ ] 8xy1 - OR Vx, Vy
|
48
|
+
- [x] 8xy2 - AND Vx, Vy
|
49
|
+
- [x] 8xy3 - XOR Vx, Vy
|
50
|
+
- [x] 8xy4 - ADD Vx, Vy
|
51
|
+
- [x] 8xy5 - SUB Vx, Vy
|
52
|
+
- [x] 8xy6 - SHR Vx {, Vy}
|
53
|
+
- [ ] 8xy7 - SUBN Vx, Vy
|
54
|
+
- [x] 8xyE - SHL Vx {, Vy}
|
55
|
+
- [x] 9xy0 - SNE Vx, Vy
|
56
|
+
- [x] Annn - LD I, addr
|
57
|
+
- [x] Bnnn - JP V0, addr
|
58
|
+
- [x] Cxkk - RND Vx, byte
|
59
|
+
- [x] Dxyn - DRW Vx, Vy, nibble
|
60
|
+
- [x] Ex9E - SKP Vx
|
61
|
+
- [x] ExA1 - SKNP Vx
|
62
|
+
- [x] Fx07 - LD Vx, DT
|
63
|
+
- [x] Fx0A - LD Vx, KEY
|
64
|
+
- [x] Fx15 - LD DT, Vx
|
65
|
+
- [x] Fx18 - LD ST, Vx
|
66
|
+
- [x] Fx1E - ADD I, Vx
|
67
|
+
- [x] Fx29 - LD F, Vx
|
68
|
+
- [x] Fx33 - LD B, Vx
|
69
|
+
- [x] Fx55 - LD [I], Vx
|
70
|
+
- [x] Fx65 - LD Vx, [I]
|
71
|
+
|
72
|
+
## TODO
|
73
|
+
|
74
|
+
Check input file.
|
75
|
+
|
76
|
+
Option --help and --version.
|
77
|
+
|
78
|
+
Data range display option, for instance:
|
79
|
+
|
80
|
+
$ c8dasm --data=21a,221 MAZE
|
81
|
+
200:a21e LD I, 21e ;Puts 21e into register I.
|
82
|
+
202:c201 RND V2, 01 ;Puts random byte AND 01 into register V2.
|
83
|
+
204:3201 SE V2, 01 ;Skip next instruction if V2 = 01.
|
84
|
+
206:a21a LD I, 21a ;Puts 21a into register I.
|
85
|
+
208:d014 DRW V0, V1, 4 ;Draws 4-byte sprite from I at (V0, V1)
|
86
|
+
20a:7004 ADD V0, 04 ;V0 = V0 + 04.
|
87
|
+
20c:3040 SE V0, 40 ;Skip next instruction if V0 = 40.
|
88
|
+
20e:1200 JP 200 ;Jump to location 200.
|
89
|
+
210:6000 LD V0, 00 ;Puts the value 00 into register V0.
|
90
|
+
212:7104 ADD V1, 04 ;V1 = V1 + 04.
|
91
|
+
214:3120 SE V1, 20 ;Skip next instruction if V1 = 20.
|
92
|
+
216:1200 JP 200 ;Jump to location 200.
|
93
|
+
218:1218 JP 218 ;Jump to location 218.
|
94
|
+
21a:80 @.......
|
95
|
+
21b:40 .@......
|
96
|
+
21c:20 ..@.....
|
97
|
+
21d:10 ...@....
|
98
|
+
21e:20 ..@.....
|
99
|
+
21f:40 .@......
|
100
|
+
220:80 @.......
|
101
|
+
221:10 ...@....
|
102
|
+
|
103
|
+
## Contributing
|
104
|
+
|
105
|
+
1. Fork it ( https://github.com/[my-github-username]/c8dasm/fork )
|
106
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
107
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
108
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
109
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/c8dasm
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'c8dasm'
|
4
|
+
|
5
|
+
reader = C8dasm::Chip8Reader.new(ARGV[0])
|
6
|
+
|
7
|
+
counter_base = 0x200
|
8
|
+
|
9
|
+
opcodes = reader.opcodes.map.with_index do |item, index|
|
10
|
+
C8dasm::Opcode.new(item, address: counter_base + 2 * index)
|
11
|
+
end
|
12
|
+
|
13
|
+
opcodes.each {|opcode| puts opcode.line }
|
data/c8dasm.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'c8dasm/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "c8dasm"
|
8
|
+
spec.version = C8dasm::VERSION
|
9
|
+
spec.authors = ["lkdjiin"]
|
10
|
+
spec.email = ["xavier.nayrac@gmail.com"]
|
11
|
+
spec.summary = %q{Disassembler for Chip8 binaries.}
|
12
|
+
spec.description = %q{c8dasm is a utility to disassemble a Chip8 binary file.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "GPLv3"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
data/lib/c8dasm.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "c8dasm/version"
|
2
|
+
require "c8dasm/chip8_reader"
|
3
|
+
require "c8dasm/opcode"
|
4
|
+
require "c8dasm/assembly"
|
5
|
+
require "c8dasm/assemblies"
|
6
|
+
require "c8dasm/comment"
|
7
|
+
require "c8dasm/comments"
|
8
|
+
|
9
|
+
# A desassembly utility for Chip-8.
|
10
|
+
module C8dasm
|
11
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "c8dasm/assemblies/asm_base"
|
2
|
+
require "c8dasm/assemblies/asm0"
|
3
|
+
require "c8dasm/assemblies/asm1"
|
4
|
+
require "c8dasm/assemblies/asm2"
|
5
|
+
require "c8dasm/assemblies/asm3"
|
6
|
+
require "c8dasm/assemblies/asm4"
|
7
|
+
require "c8dasm/assemblies/asm5"
|
8
|
+
require "c8dasm/assemblies/asm6"
|
9
|
+
require "c8dasm/assemblies/asm7"
|
10
|
+
require "c8dasm/assemblies/asm8"
|
11
|
+
require "c8dasm/assemblies/asm9"
|
12
|
+
require "c8dasm/assemblies/asma"
|
13
|
+
require "c8dasm/assemblies/asmb"
|
14
|
+
require "c8dasm/assemblies/asmc"
|
15
|
+
require "c8dasm/assemblies/asmd"
|
16
|
+
require "c8dasm/assemblies/asme"
|
17
|
+
require "c8dasm/assemblies/asmf"
|
18
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module C8dasm
|
2
|
+
|
3
|
+
class Asm8 < AsmBase
|
4
|
+
|
5
|
+
def to_s
|
6
|
+
case last_opcode
|
7
|
+
when '0' then "LD V#{x}, V#{y}"
|
8
|
+
when '2' then "AND V#{x}, V#{y}"
|
9
|
+
when '3' then "XOR V#{x}, V#{y}"
|
10
|
+
when '4' then "ADD V#{x}, V#{y}"
|
11
|
+
when '5' then "SUB V#{x}, V#{y}"
|
12
|
+
when '6' then "SHR V#{x}, V#{y}"
|
13
|
+
when 'e' then "SHL V#{x}, V#{y}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def last_opcode
|
18
|
+
@opcode[3]
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module C8dasm
|
2
|
+
|
3
|
+
class AsmBase
|
4
|
+
|
5
|
+
def initialize(opcode)
|
6
|
+
@opcode = opcode
|
7
|
+
end
|
8
|
+
|
9
|
+
def nnn
|
10
|
+
@opcode[1, 3]
|
11
|
+
end
|
12
|
+
|
13
|
+
def kk
|
14
|
+
@opcode[2, 2]
|
15
|
+
end
|
16
|
+
|
17
|
+
def x
|
18
|
+
@opcode[1]
|
19
|
+
end
|
20
|
+
|
21
|
+
def y
|
22
|
+
@opcode[2]
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|