z80_disassembler 0.2.1 → 0.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d89919a8e31426ffe53e01448701e22a11015ee15a2a750d294e6cc2b1d23b66
4
- data.tar.gz: 6fcb81e94bb2b94b8fffb5420585a6031445b12f8d05e59c632d20cc367f61ad
3
+ metadata.gz: 6d345233ff0d5429ba5c05cdb82c304de2ef46b6ebe7761bda8b805c986c85e2
4
+ data.tar.gz: e43f8bf8fd592ec156d5bb6c942e6847691e853701a65e2b0afdaffd827c626e
5
5
  SHA512:
6
- metadata.gz: a214c2d6f7d70af405911cd305a2213a327f00d33ace63e88c5a30d16bcfea243e6ff5f0a4175af176a7407514195a8ef9e97a5a240bb9a27d590ffae88d9669
7
- data.tar.gz: eb2dd90529f337f516691e5eacfcab0a619565baf008f4cfacb1b69a157a0edbb9e5e59eb0f7ec5e01da03a691d1c2d4a885f6caec8a1654fff4425b80611241
6
+ metadata.gz: 991885755e9d4fbe5128b6b81fdb5e4804d6921850acbf9e07bc8c0c66fb290d293ea32be1fc56c1a9da06d55a64d4100b2558f488999812ba832d9a8ab2434c
7
+ data.tar.gz: db4bdd7cb73f1ba8bdf430c54578f02f1a74ca5de3373bf2b1e4dda855b400652fa0604ca6e1e7cd1b3b0a228f0f4aa79ffb22e9d1d4116c6a0663d625c73bc7
data/README.md CHANGED
@@ -27,10 +27,10 @@ Or install it yourself as:
27
27
 
28
28
  - example: parse.C >> parse.C.txt and compare with parse.txt
29
29
  ```ruby
30
- Z80Disassembler::Disassembler.new(params[:file], 32768).start
30
+ z = Z80Disassembler::Disassembler.new(params[:file], 32768)
31
+ z.start # return [25114, "#621A", "LD IX,#6300", "DD 21 00 63", " ! c"
32
+ z.text # return asm text " LD IX,link_1 ; #621A / 25114 ; DD 21 00 63 ; ! c ;"
31
33
  ```
32
- return hash { 32768=>["#8000", "PUSH IY", "fd e5"], 32770=>[...], ... }
33
-
34
34
  ## Development
35
35
 
36
36
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -28,38 +28,19 @@ module Z80Disassembler
28
28
  @file_name = file_name; @addr = addr.to_i
29
29
  @x = 0; @y = 0; @z = 0; @p = 0; @q = 0; @xx = nil
30
30
  @lambda = nil; @prefix = nil; @prev = nil
31
- @bytes = []; @ascii = []; @result = {}
31
+ @bytes = []; @ascii = []; @result = []
32
32
  end
33
33
 
34
34
  def start
35
35
  File.open(@file_name).each_byte do |byte|
36
36
  load_vars(byte)
37
- str = case @prefix
38
- when 'cb' then @prefix = nil; cb_prefix
39
- when 'ed' then @prefix = nil; ed_prefix
40
- when 'dd' then @xx = 'IX'; xx_prefix(byte)
41
- when 'fd' then @xx = 'IY'; xx_prefix(byte)
42
- when 'xx' then temp = @temp; @temp = nil; displacement(byte, temp)
43
- when 2 then @prefix -= 1; @temp = byte.to_s(16).rjust(2, '0').upcase; nil
44
- when 1
45
- resp = @lambda.call(@arg, byte.to_s(16).rjust(2, '0').upcase)
46
- @prefix = nil; temp = @temp; @temp = nil
47
- if temp && resp.include?(')')
48
- resp = @xx ? displacement(temp.hex, resp) : resp.sub(')', "#{temp})").sub('(', '(#')
49
- elsif temp
50
- resp += temp
51
- end
52
- resp = hl_to_xx(resp, @xx) unless @xx.nil?
53
- @xx = nil
54
- resp
55
- else command
56
- end
37
+ str = command_from_byte(byte)
57
38
  @prev = byte.to_s(16)
58
- @ascii << ((32..126).include?(byte) ? ASCII[byte - 32] : '_')
39
+ @ascii << ((32..126).include?(byte) ? ASCII[byte - 32] : ' ')
59
40
  @bytes << @prev.rjust(2, '0').upcase
60
41
  next unless str
61
42
 
62
- @result[@addr] = ["##{@addr.to_s(16)}".upcase, str, @bytes.join(' '), @ascii.join]
43
+ @result << [@addr, "##{@addr.to_s(16)}".upcase, str, @bytes.join(' '), @ascii.join]
63
44
  @addr += @bytes.size
64
45
  @bytes = []
65
46
  @ascii = []
@@ -67,8 +48,51 @@ module Z80Disassembler
67
48
  @result
68
49
  end
69
50
 
51
+ def text
52
+ org = @addr - @file_name.size
53
+ hash_links = {}
54
+ link_num = 0
55
+ int_addrs = org..@addr
56
+ with_links = @result.select { |z| z[2] =~ /#[0-F]{4}/ && int_addrs.include?(z[2].split('#').last[0..3].hex) }
57
+ with_links.each { |x| hash_links["##{x[2].split('#').last[0..3]}"] = "link_#{link_num += 1}" }
58
+ [
59
+ " device zxspectrum48",
60
+ " ORG #{org}",
61
+ "begin_file:\n"
62
+ ].join("\n") +
63
+ @result.map do |addr, addr16, str, bytes, ascii|
64
+ link = (hash_links[addr16] || '').ljust(16, ' ')
65
+ adr = '#' + str.split('#').last[0..3]
66
+ string = hash_links.keys.include?(adr) ? str.sub(adr, hash_links[adr]) : str
67
+ "#{link} #{string.ljust(16, ' ')}; #{addr16.ljust(5, ' ')} / #{addr.to_s.ljust(5, ' ')} ; #{bytes.ljust(14, ' ')} ; #{ascii.ljust(4, ' ')} ;"
68
+ end.join("\n")
69
+ end
70
+
70
71
  private
71
72
 
73
+ def command_from_byte(byte)
74
+ case @prefix
75
+ when 'cb' then @prefix = nil; cb_prefix
76
+ when 'ed' then @prefix = nil; ed_prefix
77
+ when 'dd' then @xx = 'IX'; xx_prefix(byte)
78
+ when 'fd' then @xx = 'IY'; xx_prefix(byte)
79
+ when 'xx' then temp = @temp; @temp = nil; displacement(byte, temp)
80
+ when 2 then @prefix -= 1; @temp = byte.to_s(16).rjust(2, '0').upcase; nil
81
+ when 1
82
+ resp = @lambda.call(@arg, byte.to_s(16).rjust(2, '0').upcase)
83
+ @prefix = nil; temp = @temp; @temp = nil
84
+ if temp && resp.include?(')')
85
+ resp = @xx ? displacement(temp.hex, resp) : resp.sub(')', "#{temp})").sub('(', '(#')
86
+ elsif temp
87
+ resp += temp
88
+ end
89
+ resp = hl_to_xx(resp, @xx) unless @xx.nil?
90
+ @xx = nil
91
+ resp
92
+ else command
93
+ end
94
+ end
95
+
72
96
  def hl_to_xx(temp, reg)
73
97
  if temp.include?('HL')
74
98
  temp.sub('HL', reg)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Z80Disassembler
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: z80_disassembler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - dvitvitskiy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-05 00:00:00.000000000 Z
11
+ date: 2021-06-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: