z80_disassembler 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/z80_disassembler.rb +65 -16
- data/lib/z80_disassembler/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56e8580f70e53450065ba78d68f19758e0072a28f1eec1c67ac4cff7d825e464
|
4
|
+
data.tar.gz: 62f84332480a3e3cd218f41db288e9050d908e05fccb550a288823b23193a9e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ea0700062335768dbf0d6fe916f1b3c318a8312c018c6a84519d95a6c9d218fb0fe7277ed93dfc9ddcdbecc7d62c37a1eed15110bc2501ecde3b9870245f147
|
7
|
+
data.tar.gz: 173aa895338469e982c9f82f41a8d1b458eb7bfd5cf357ba0c0dd81db56d555754597b266ce6cae83d6d327bb04d39026bd320f0b9d34b6703a7e0f605fa60a7
|
data/lib/z80_disassembler.rb
CHANGED
@@ -6,7 +6,7 @@ module Z80Disassembler
|
|
6
6
|
class Error < StandardError; end
|
7
7
|
|
8
8
|
class Disassembler
|
9
|
-
attr_reader :org
|
9
|
+
attr_reader :org, :file_size
|
10
10
|
|
11
11
|
# 0 1 2 3 4 5 6 7
|
12
12
|
T_R = [ 'B', 'C', 'D', 'E', 'H', 'L', '(HL)', 'A'].freeze
|
@@ -69,29 +69,75 @@ module Z80Disassembler
|
|
69
69
|
del_links = []
|
70
70
|
link_num = 0
|
71
71
|
int_addrs = @org..(@org + @file_size)
|
72
|
-
|
73
|
-
with_links.each do |x|
|
72
|
+
@result.select { |z| z[2] =~ /#[0-F]{4}/ && int_addrs.include?(z[2].split('#').last[0..3].hex) }.each do |x|
|
74
73
|
z = "##{x[2].split('#').last[0..3]}"
|
75
74
|
hash_links[z] = "link_#{link_num += 1}" unless hash_links[z]
|
76
75
|
end
|
77
|
-
|
76
|
+
@result.select { |z| z[2] =~ /\$/ }.each do |x|
|
77
|
+
z = "##{ (x[0] + x[2].split('$').last.to_i).to_s(16).upcase }"
|
78
|
+
hash_links[z] = "link_#{link_num += 1}" unless hash_links[z]
|
79
|
+
end
|
78
80
|
code = @result.map do |addr, addr16, str, bytes, ascii|
|
79
81
|
del_links << hash_links[addr16] if hash_links[addr16]
|
80
|
-
link = (hash_links[addr16]
|
81
|
-
adr =
|
82
|
-
|
82
|
+
link = (hash_links[addr16] ? (hash_links[addr16] + ':') : '').ljust(16, ' ')
|
83
|
+
substr, adr = if str.include?('$')
|
84
|
+
["$#{str.split('$').last}", "##{(addr + str.split('$').last.to_i).to_s(16).upcase}"]
|
85
|
+
else
|
86
|
+
adr = "##{str.split('#').last[0..3]}"
|
87
|
+
[adr, adr]
|
88
|
+
end
|
89
|
+
string = hash_links.keys.include?(adr) ? str.sub(substr, hash_links[adr]) : str
|
90
|
+
|
83
91
|
"#{link} #{string.ljust(16, ' ')}; #{addr16.ljust(5, ' ')} / #{addr.to_s.ljust(5, ' ')} ; #{bytes.ljust(14, ' ')} ; #{ascii.ljust(4, ' ')} ;"
|
84
92
|
end.join("\n")
|
85
93
|
|
94
|
+
header = [
|
95
|
+
";--- #{Date.today} --- https://rmda.su ",
|
96
|
+
'; _______ _/| __ ______ ____ ',
|
97
|
+
'; / __ // |/ \\\\ _ \ / \ ',
|
98
|
+
'; / _/ _// \\\\ \\\\ \\\\ \ \ ',
|
99
|
+
'; \___\ \\\\___\/___//______//__/\__\ ',
|
100
|
+
'; \__/ ',
|
101
|
+
";--- size: #{@file_size} --- filename: #{@file_name} "
|
102
|
+
]
|
86
103
|
[
|
104
|
+
*header,
|
87
105
|
' device zxspectrum48',
|
88
106
|
' ORG #' + @org.to_s(16),
|
89
107
|
hash_links.map { |key, val| "#{val.ljust(16, ' ')} equ #{key}" unless del_links.include?(val) }.compact.join("\n"),
|
90
108
|
'begin:',
|
91
109
|
code,
|
92
110
|
'end:',
|
111
|
+
'length equ end - begin',
|
112
|
+
'CODE = #AF',
|
113
|
+
'USR = #C0',
|
114
|
+
'LOAD = #EF',
|
115
|
+
'CLEAR = #FD',
|
116
|
+
'RANDOMIZE = #F9',
|
117
|
+
' org #5C00',
|
118
|
+
' baszac db 0, 1', # Line number
|
119
|
+
' dw linlen', # Line length
|
120
|
+
' linzac',
|
121
|
+
' db CLEAR, "8", #0E, 0, 0',
|
122
|
+
' dw begin - 1',
|
123
|
+
' db 0, ":"',
|
124
|
+
' db LOAD, "\""',
|
125
|
+
' codnam ds 10, 32',
|
126
|
+
' org codnam',
|
127
|
+
' db "disasm"',
|
128
|
+
' org codnam + 10',
|
129
|
+
' db "\"", CODE, ":"',
|
130
|
+
' db RANDOMIZE, USR, "8", #0E, 0, 0',
|
131
|
+
' dw begin', # call address
|
132
|
+
' db 0, #0D',
|
133
|
+
' linlen = $ - linzac',
|
134
|
+
' baslen = $ - baszac',
|
135
|
+
' emptytap "disasm.tap"',
|
136
|
+
' savetap "disasm.tap", BASIC, "disasm", baszac, baslen, 1',
|
137
|
+
' savetap "disasm.tap", CODE, "disasm", begin, length, begin',
|
93
138
|
' savesna "disasm.sna", begin',
|
94
|
-
' savebin "disasm.C",
|
139
|
+
' savebin "disasm.C", begin, length',
|
140
|
+
' savehob "disasm.$C", "disasm.C", begin, length',
|
95
141
|
''
|
96
142
|
].join("\n")
|
97
143
|
end
|
@@ -113,16 +159,18 @@ module Z80Disassembler
|
|
113
159
|
when 1
|
114
160
|
resp = @lambda.call(@arg, byte.to_s(16).rjust(2, '0').upcase)
|
115
161
|
@prefix = nil; temp = @temp; @temp = nil
|
116
|
-
if temp && resp.include?(')')
|
117
|
-
|
162
|
+
if temp && resp.include?('(HL)')
|
163
|
+
@xx ? resp = displacement(temp.hex, resp) : resp += temp
|
164
|
+
elsif temp && resp.include?(')')
|
165
|
+
# resp = displacement(temp.hex, resp) if @xx
|
166
|
+
resp = resp.sub(')', "#{temp})").sub('(', '(#')
|
118
167
|
elsif temp
|
119
168
|
resp += temp
|
120
169
|
end
|
121
170
|
resp = hl_to_xx(resp, @xx) unless @xx.nil?
|
122
|
-
@xx = nil
|
123
171
|
if resp.include?('JR') || resp.include?('DJNZ')
|
124
172
|
z = resp.split('#')
|
125
|
-
z[1] = z[1].hex < 127 ? "$+#{z[1].hex}" : "$-#{255 - z[1].hex}"
|
173
|
+
z[1] = z[1].hex < 127 ? "$+#{z[1].hex + 2}" : "$-#{255 - z[1].hex - 1}"
|
126
174
|
resp = z.join
|
127
175
|
end
|
128
176
|
resp
|
@@ -131,6 +179,7 @@ module Z80Disassembler
|
|
131
179
|
end
|
132
180
|
|
133
181
|
def hl_to_xx(temp, reg)
|
182
|
+
@xx = nil
|
134
183
|
if temp.include?('HL')
|
135
184
|
temp.sub('HL', reg)
|
136
185
|
elsif temp.include?(' L')
|
@@ -149,7 +198,7 @@ module Z80Disassembler
|
|
149
198
|
def displacement(byte, temp)
|
150
199
|
@prefix = nil
|
151
200
|
byte -= 256 if byte > 127
|
152
|
-
des = ['', "+#{byte
|
201
|
+
des = ['+0', "+#{byte}", byte.to_s][byte <=> 0]
|
153
202
|
temp.sub('HL', @xx + des)
|
154
203
|
end
|
155
204
|
|
@@ -195,7 +244,7 @@ module Z80Disassembler
|
|
195
244
|
case @z
|
196
245
|
when 0 then "RET #{T_CC[@y]}"
|
197
246
|
when 1 then @q ? ['RET','EXX','JP HL','LD SP, HL'][@p] : "POP #{T_RP2[@p]}"
|
198
|
-
when 2 then calc_bytes(->(a, b){ "JP #{a}
|
247
|
+
when 2 then calc_bytes(->(a, b){ "JP #{a},##{b}" }, T_CC[@y], 2)
|
199
248
|
when 3
|
200
249
|
case @y
|
201
250
|
when 0 then calc_bytes(->(a, b){ "JP ##{b}" }, nil, 2)
|
@@ -234,8 +283,8 @@ module Z80Disassembler
|
|
234
283
|
if @temp&.include?('(')
|
235
284
|
@prefix = 'xx'; nil
|
236
285
|
elsif ['dd', 'fd'].include?(@prev) && @temp
|
237
|
-
temp = @temp; @temp = nil; @prefix = nil
|
238
|
-
hl_to_xx(temp, xx)
|
286
|
+
temp = @temp; @temp = nil; @prefix = nil
|
287
|
+
hl_to_xx(temp, @xx)
|
239
288
|
elsif @lambda && !@arg&.include?('HL')
|
240
289
|
@prefix = 1; @temp
|
241
290
|
else
|
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.
|
4
|
+
version: 0.3.0
|
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-
|
11
|
+
date: 2021-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|