rubyboy 1.0.0 → 1.1.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +5 -0
- data/exe/rubyboy +12 -2
- data/lib/bench.rb +26 -0
- data/lib/rubyboy/cartridge/mbc1.rb +1 -1
- data/lib/rubyboy/cpu.rb +517 -517
- data/lib/rubyboy/joypad.rb +2 -2
- data/lib/rubyboy/ppu.rb +28 -29
- data/lib/rubyboy/timer.rb +1 -1
- data/lib/rubyboy/version.rb +1 -1
- data/lib/rubyboy.rb +15 -0
- metadata +4 -3
data/lib/rubyboy/cpu.rb
CHANGED
@@ -21,14 +21,14 @@ module Rubyboy
|
|
21
21
|
opcode = read_byte(@pc)
|
22
22
|
# print_log(opcode)
|
23
23
|
|
24
|
-
@halted &= @interrupt.interrupts
|
24
|
+
@halted &= @interrupt.interrupts == 0
|
25
25
|
|
26
26
|
return 16 if @halted
|
27
27
|
|
28
|
-
if @ime && @interrupt.interrupts
|
28
|
+
if @ime && @interrupt.interrupts > 0
|
29
29
|
pcs = [0x0040, 0x0048, 0x0050, 0x0058, 0x0060]
|
30
30
|
5.times do |i|
|
31
|
-
next if @interrupt.interrupts[i]
|
31
|
+
next if @interrupt.interrupts[i] == 0
|
32
32
|
|
33
33
|
@interrupt.reset_flag(i)
|
34
34
|
@ime = false
|
@@ -51,509 +51,509 @@ module Rubyboy
|
|
51
51
|
|
52
52
|
case opcode
|
53
53
|
when 0x00 then 4 # NOP
|
54
|
-
when 0x01 then ld16(
|
55
|
-
when 0x02 then ld8(
|
56
|
-
when 0x03 then inc16(
|
57
|
-
when 0x04 then inc8(
|
58
|
-
when 0x05 then dec8(
|
59
|
-
when 0x06 then ld8(
|
54
|
+
when 0x01 then ld16({ type: :register16, value: :bc }, { type: :immediate16 })
|
55
|
+
when 0x02 then ld8({ type: :indirect, value: :bc }, { type: :register8, value: :a })
|
56
|
+
when 0x03 then inc16({ type: :register16, value: :bc })
|
57
|
+
when 0x04 then inc8({ type: :register8, value: :b })
|
58
|
+
when 0x05 then dec8({ type: :register8, value: :b })
|
59
|
+
when 0x06 then ld8({ type: :register8, value: :b }, { type: :immediate8 })
|
60
60
|
when 0x07 then rlca
|
61
|
-
when 0x08 then ld16(
|
62
|
-
when 0x09 then add16(
|
63
|
-
when 0x0a then ld8(
|
64
|
-
when 0x0b then dec16(
|
65
|
-
when 0x0c then inc8(
|
66
|
-
when 0x0d then dec8(
|
67
|
-
when 0x0e then ld8(
|
61
|
+
when 0x08 then ld16({ type: :direct16 }, { type: :sp })
|
62
|
+
when 0x09 then add16({ type: :register16, value: :hl }, { type: :register16, value: :bc })
|
63
|
+
when 0x0a then ld8({ type: :register8, value: :a }, { type: :indirect, value: :bc })
|
64
|
+
when 0x0b then dec16({ type: :register16, value: :bc })
|
65
|
+
when 0x0c then inc8({ type: :register8, value: :c })
|
66
|
+
when 0x0d then dec8({ type: :register8, value: :c })
|
67
|
+
when 0x0e then ld8({ type: :register8, value: :c }, { type: :immediate8 })
|
68
68
|
when 0x0f then rrca
|
69
69
|
when 0x10 then 4 # STOP
|
70
|
-
when 0x11 then ld16(
|
71
|
-
when 0x12 then ld8(
|
72
|
-
when 0x13 then inc16(
|
73
|
-
when 0x14 then inc8(
|
74
|
-
when 0x15 then dec8(
|
75
|
-
when 0x16 then ld8(
|
70
|
+
when 0x11 then ld16({ type: :register16, value: :de }, { type: :immediate16 })
|
71
|
+
when 0x12 then ld8({ type: :indirect, value: :de }, { type: :register8, value: :a })
|
72
|
+
when 0x13 then inc16({ type: :register16, value: :de })
|
73
|
+
when 0x14 then inc8({ type: :register8, value: :d })
|
74
|
+
when 0x15 then dec8({ type: :register8, value: :d })
|
75
|
+
when 0x16 then ld8({ type: :register8, value: :d }, { type: :immediate8 })
|
76
76
|
when 0x17 then rla
|
77
77
|
when 0x18 then jr
|
78
|
-
when 0x19 then add16(
|
79
|
-
when 0x1a then ld8(
|
80
|
-
when 0x1b then dec16(
|
81
|
-
when 0x1c then inc8(
|
82
|
-
when 0x1d then dec8(
|
83
|
-
when 0x1e then ld8(
|
78
|
+
when 0x19 then add16({ type: :register16, value: :hl }, { type: :register16, value: :de })
|
79
|
+
when 0x1a then ld8({ type: :register8, value: :a }, { type: :indirect, value: :de })
|
80
|
+
when 0x1b then dec16({ type: :register16, value: :de })
|
81
|
+
when 0x1c then inc8({ type: :register8, value: :e })
|
82
|
+
when 0x1d then dec8({ type: :register8, value: :e })
|
83
|
+
when 0x1e then ld8({ type: :register8, value: :e }, { type: :immediate8 })
|
84
84
|
when 0x1f then rra
|
85
85
|
when 0x20 then jr(condition: !flags[:z])
|
86
|
-
when 0x21 then ld16(
|
87
|
-
when 0x22 then ld8(
|
88
|
-
when 0x23 then inc16(
|
89
|
-
when 0x24 then inc8(
|
90
|
-
when 0x25 then dec8(
|
91
|
-
when 0x26 then ld8(
|
86
|
+
when 0x21 then ld16({ type: :register16, value: :hl }, { type: :immediate16 })
|
87
|
+
when 0x22 then ld8({ type: :hl_inc }, { type: :register8, value: :a })
|
88
|
+
when 0x23 then inc16({ type: :register16, value: :hl })
|
89
|
+
when 0x24 then inc8({ type: :register8, value: :h })
|
90
|
+
when 0x25 then dec8({ type: :register8, value: :h })
|
91
|
+
when 0x26 then ld8({ type: :register8, value: :h }, { type: :immediate8 })
|
92
92
|
when 0x27 then daa
|
93
93
|
when 0x28 then jr(condition: flags[:z])
|
94
|
-
when 0x29 then add16(
|
95
|
-
when 0x2a then ld8(
|
96
|
-
when 0x2b then dec16(
|
97
|
-
when 0x2c then inc8(
|
98
|
-
when 0x2d then dec8(
|
99
|
-
when 0x2e then ld8(
|
94
|
+
when 0x29 then add16({ type: :register16, value: :hl }, { type: :register16, value: :hl })
|
95
|
+
when 0x2a then ld8({ type: :register8, value: :a }, { type: :hl_inc })
|
96
|
+
when 0x2b then dec16({ type: :register16, value: :hl })
|
97
|
+
when 0x2c then inc8({ type: :register8, value: :l })
|
98
|
+
when 0x2d then dec8({ type: :register8, value: :l })
|
99
|
+
when 0x2e then ld8({ type: :register8, value: :l }, { type: :immediate8 })
|
100
100
|
when 0x2f then cpl
|
101
101
|
when 0x30 then jr(condition: !flags[:c])
|
102
|
-
when 0x31 then ld16(
|
103
|
-
when 0x32 then ld8(
|
104
|
-
when 0x33 then inc16(
|
105
|
-
when 0x34 then inc8(
|
106
|
-
when 0x35 then dec8(
|
107
|
-
when 0x36 then ld8(
|
102
|
+
when 0x31 then ld16({ type: :sp }, { type: :immediate16 })
|
103
|
+
when 0x32 then ld8({ type: :hl_dec }, { type: :register8, value: :a })
|
104
|
+
when 0x33 then inc16({ type: :sp })
|
105
|
+
when 0x34 then inc8({ type: :indirect, value: :hl })
|
106
|
+
when 0x35 then dec8({ type: :indirect, value: :hl })
|
107
|
+
when 0x36 then ld8({ type: :indirect, value: :hl }, { type: :immediate8 })
|
108
108
|
when 0x37 then scf
|
109
109
|
when 0x38 then jr(condition: flags[:c])
|
110
|
-
when 0x39 then add16(
|
111
|
-
when 0x3a then ld8(
|
112
|
-
when 0x3b then dec16(
|
113
|
-
when 0x3c then inc8(
|
114
|
-
when 0x3d then dec8(
|
115
|
-
when 0x3e then ld8(
|
110
|
+
when 0x39 then add16({ type: :register16, value: :hl }, { type: :sp })
|
111
|
+
when 0x3a then ld8({ type: :register8, value: :a }, { type: :hl_dec })
|
112
|
+
when 0x3b then dec16({ type: :sp })
|
113
|
+
when 0x3c then inc8({ type: :register8, value: :a })
|
114
|
+
when 0x3d then dec8({ type: :register8, value: :a })
|
115
|
+
when 0x3e then ld8({ type: :register8, value: :a }, { type: :immediate8 })
|
116
116
|
when 0x3f then ccf
|
117
|
-
when 0x40 then ld8(
|
118
|
-
when 0x41 then ld8(
|
119
|
-
when 0x42 then ld8(
|
120
|
-
when 0x43 then ld8(
|
121
|
-
when 0x44 then ld8(
|
122
|
-
when 0x45 then ld8(
|
123
|
-
when 0x46 then ld8(
|
124
|
-
when 0x47 then ld8(
|
125
|
-
when 0x48 then ld8(
|
126
|
-
when 0x49 then ld8(
|
127
|
-
when 0x4a then ld8(
|
128
|
-
when 0x4b then ld8(
|
129
|
-
when 0x4c then ld8(
|
130
|
-
when 0x4d then ld8(
|
131
|
-
when 0x4e then ld8(
|
132
|
-
when 0x4f then ld8(
|
133
|
-
when 0x50 then ld8(
|
134
|
-
when 0x51 then ld8(
|
135
|
-
when 0x52 then ld8(
|
136
|
-
when 0x53 then ld8(
|
137
|
-
when 0x54 then ld8(
|
138
|
-
when 0x55 then ld8(
|
139
|
-
when 0x56 then ld8(
|
140
|
-
when 0x57 then ld8(
|
141
|
-
when 0x58 then ld8(
|
142
|
-
when 0x59 then ld8(
|
143
|
-
when 0x5a then ld8(
|
144
|
-
when 0x5b then ld8(
|
145
|
-
when 0x5c then ld8(
|
146
|
-
when 0x5d then ld8(
|
147
|
-
when 0x5e then ld8(
|
148
|
-
when 0x5f then ld8(
|
149
|
-
when 0x60 then ld8(
|
150
|
-
when 0x61 then ld8(
|
151
|
-
when 0x62 then ld8(
|
152
|
-
when 0x63 then ld8(
|
153
|
-
when 0x64 then ld8(
|
154
|
-
when 0x65 then ld8(
|
155
|
-
when 0x66 then ld8(
|
156
|
-
when 0x67 then ld8(
|
157
|
-
when 0x68 then ld8(
|
158
|
-
when 0x69 then ld8(
|
159
|
-
when 0x6a then ld8(
|
160
|
-
when 0x6b then ld8(
|
161
|
-
when 0x6c then ld8(
|
162
|
-
when 0x6d then ld8(
|
163
|
-
when 0x6e then ld8(
|
164
|
-
when 0x6f then ld8(
|
165
|
-
when 0x70 then ld8(
|
166
|
-
when 0x71 then ld8(
|
167
|
-
when 0x72 then ld8(
|
168
|
-
when 0x73 then ld8(
|
169
|
-
when 0x74 then ld8(
|
170
|
-
when 0x75 then ld8(
|
117
|
+
when 0x40 then ld8({ type: :register8, value: :b }, { type: :register8, value: :b })
|
118
|
+
when 0x41 then ld8({ type: :register8, value: :b }, { type: :register8, value: :c })
|
119
|
+
when 0x42 then ld8({ type: :register8, value: :b }, { type: :register8, value: :d })
|
120
|
+
when 0x43 then ld8({ type: :register8, value: :b }, { type: :register8, value: :e })
|
121
|
+
when 0x44 then ld8({ type: :register8, value: :b }, { type: :register8, value: :h })
|
122
|
+
when 0x45 then ld8({ type: :register8, value: :b }, { type: :register8, value: :l })
|
123
|
+
when 0x46 then ld8({ type: :register8, value: :b }, { type: :indirect, value: :hl })
|
124
|
+
when 0x47 then ld8({ type: :register8, value: :b }, { type: :register8, value: :a })
|
125
|
+
when 0x48 then ld8({ type: :register8, value: :c }, { type: :register8, value: :b })
|
126
|
+
when 0x49 then ld8({ type: :register8, value: :c }, { type: :register8, value: :c })
|
127
|
+
when 0x4a then ld8({ type: :register8, value: :c }, { type: :register8, value: :d })
|
128
|
+
when 0x4b then ld8({ type: :register8, value: :c }, { type: :register8, value: :e })
|
129
|
+
when 0x4c then ld8({ type: :register8, value: :c }, { type: :register8, value: :h })
|
130
|
+
when 0x4d then ld8({ type: :register8, value: :c }, { type: :register8, value: :l })
|
131
|
+
when 0x4e then ld8({ type: :register8, value: :c }, { type: :indirect, value: :hl })
|
132
|
+
when 0x4f then ld8({ type: :register8, value: :c }, { type: :register8, value: :a })
|
133
|
+
when 0x50 then ld8({ type: :register8, value: :d }, { type: :register8, value: :b })
|
134
|
+
when 0x51 then ld8({ type: :register8, value: :d }, { type: :register8, value: :c })
|
135
|
+
when 0x52 then ld8({ type: :register8, value: :d }, { type: :register8, value: :d })
|
136
|
+
when 0x53 then ld8({ type: :register8, value: :d }, { type: :register8, value: :e })
|
137
|
+
when 0x54 then ld8({ type: :register8, value: :d }, { type: :register8, value: :h })
|
138
|
+
when 0x55 then ld8({ type: :register8, value: :d }, { type: :register8, value: :l })
|
139
|
+
when 0x56 then ld8({ type: :register8, value: :d }, { type: :indirect, value: :hl })
|
140
|
+
when 0x57 then ld8({ type: :register8, value: :d }, { type: :register8, value: :a })
|
141
|
+
when 0x58 then ld8({ type: :register8, value: :e }, { type: :register8, value: :b })
|
142
|
+
when 0x59 then ld8({ type: :register8, value: :e }, { type: :register8, value: :c })
|
143
|
+
when 0x5a then ld8({ type: :register8, value: :e }, { type: :register8, value: :d })
|
144
|
+
when 0x5b then ld8({ type: :register8, value: :e }, { type: :register8, value: :e })
|
145
|
+
when 0x5c then ld8({ type: :register8, value: :e }, { type: :register8, value: :h })
|
146
|
+
when 0x5d then ld8({ type: :register8, value: :e }, { type: :register8, value: :l })
|
147
|
+
when 0x5e then ld8({ type: :register8, value: :e }, { type: :indirect, value: :hl })
|
148
|
+
when 0x5f then ld8({ type: :register8, value: :e }, { type: :register8, value: :a })
|
149
|
+
when 0x60 then ld8({ type: :register8, value: :h }, { type: :register8, value: :b })
|
150
|
+
when 0x61 then ld8({ type: :register8, value: :h }, { type: :register8, value: :c })
|
151
|
+
when 0x62 then ld8({ type: :register8, value: :h }, { type: :register8, value: :d })
|
152
|
+
when 0x63 then ld8({ type: :register8, value: :h }, { type: :register8, value: :e })
|
153
|
+
when 0x64 then ld8({ type: :register8, value: :h }, { type: :register8, value: :h })
|
154
|
+
when 0x65 then ld8({ type: :register8, value: :h }, { type: :register8, value: :l })
|
155
|
+
when 0x66 then ld8({ type: :register8, value: :h }, { type: :indirect, value: :hl })
|
156
|
+
when 0x67 then ld8({ type: :register8, value: :h }, { type: :register8, value: :a })
|
157
|
+
when 0x68 then ld8({ type: :register8, value: :l }, { type: :register8, value: :b })
|
158
|
+
when 0x69 then ld8({ type: :register8, value: :l }, { type: :register8, value: :c })
|
159
|
+
when 0x6a then ld8({ type: :register8, value: :l }, { type: :register8, value: :d })
|
160
|
+
when 0x6b then ld8({ type: :register8, value: :l }, { type: :register8, value: :e })
|
161
|
+
when 0x6c then ld8({ type: :register8, value: :l }, { type: :register8, value: :h })
|
162
|
+
when 0x6d then ld8({ type: :register8, value: :l }, { type: :register8, value: :l })
|
163
|
+
when 0x6e then ld8({ type: :register8, value: :l }, { type: :indirect, value: :hl })
|
164
|
+
when 0x6f then ld8({ type: :register8, value: :l }, { type: :register8, value: :a })
|
165
|
+
when 0x70 then ld8({ type: :indirect, value: :hl }, { type: :register8, value: :b })
|
166
|
+
when 0x71 then ld8({ type: :indirect, value: :hl }, { type: :register8, value: :c })
|
167
|
+
when 0x72 then ld8({ type: :indirect, value: :hl }, { type: :register8, value: :d })
|
168
|
+
when 0x73 then ld8({ type: :indirect, value: :hl }, { type: :register8, value: :e })
|
169
|
+
when 0x74 then ld8({ type: :indirect, value: :hl }, { type: :register8, value: :h })
|
170
|
+
when 0x75 then ld8({ type: :indirect, value: :hl }, { type: :register8, value: :l })
|
171
171
|
when 0x76 then halt
|
172
|
-
when 0x77 then ld8(
|
173
|
-
when 0x78 then ld8(
|
174
|
-
when 0x79 then ld8(
|
175
|
-
when 0x7a then ld8(
|
176
|
-
when 0x7b then ld8(
|
177
|
-
when 0x7c then ld8(
|
178
|
-
when 0x7d then ld8(
|
179
|
-
when 0x7e then ld8(
|
180
|
-
when 0x7f then ld8(
|
181
|
-
when 0x80 then add8(
|
182
|
-
when 0x81 then add8(
|
183
|
-
when 0x82 then add8(
|
184
|
-
when 0x83 then add8(
|
185
|
-
when 0x84 then add8(
|
186
|
-
when 0x85 then add8(
|
187
|
-
when 0x86 then add8(
|
188
|
-
when 0x87 then add8(
|
189
|
-
when 0x88 then adc8(
|
190
|
-
when 0x89 then adc8(
|
191
|
-
when 0x8a then adc8(
|
192
|
-
when 0x8b then adc8(
|
193
|
-
when 0x8c then adc8(
|
194
|
-
when 0x8d then adc8(
|
195
|
-
when 0x8e then adc8(
|
196
|
-
when 0x8f then adc8(
|
197
|
-
when 0x90 then sub8(
|
198
|
-
when 0x91 then sub8(
|
199
|
-
when 0x92 then sub8(
|
200
|
-
when 0x93 then sub8(
|
201
|
-
when 0x94 then sub8(
|
202
|
-
when 0x95 then sub8(
|
203
|
-
when 0x96 then sub8(
|
204
|
-
when 0x97 then sub8(
|
205
|
-
when 0x98 then sbc8(
|
206
|
-
when 0x99 then sbc8(
|
207
|
-
when 0x9a then sbc8(
|
208
|
-
when 0x9b then sbc8(
|
209
|
-
when 0x9c then sbc8(
|
210
|
-
when 0x9d then sbc8(
|
211
|
-
when 0x9e then sbc8(
|
212
|
-
when 0x9f then sbc8(
|
213
|
-
when 0xa0 then and8(
|
214
|
-
when 0xa1 then and8(
|
215
|
-
when 0xa2 then and8(
|
216
|
-
when 0xa3 then and8(
|
217
|
-
when 0xa4 then and8(
|
218
|
-
when 0xa5 then and8(
|
219
|
-
when 0xa6 then and8(
|
220
|
-
when 0xa7 then and8(
|
221
|
-
when 0xa8 then xor8(
|
222
|
-
when 0xa9 then xor8(
|
223
|
-
when 0xaa then xor8(
|
224
|
-
when 0xab then xor8(
|
225
|
-
when 0xac then xor8(
|
226
|
-
when 0xad then xor8(
|
227
|
-
when 0xae then xor8(
|
228
|
-
when 0xaf then xor8(
|
229
|
-
when 0xb0 then or8(
|
230
|
-
when 0xb1 then or8(
|
231
|
-
when 0xb2 then or8(
|
232
|
-
when 0xb3 then or8(
|
233
|
-
when 0xb4 then or8(
|
234
|
-
when 0xb5 then or8(
|
235
|
-
when 0xb6 then or8(
|
236
|
-
when 0xb7 then or8(
|
237
|
-
when 0xb8 then cp8(
|
238
|
-
when 0xb9 then cp8(
|
239
|
-
when 0xba then cp8(
|
240
|
-
when 0xbb then cp8(
|
241
|
-
when 0xbc then cp8(
|
242
|
-
when 0xbd then cp8(
|
243
|
-
when 0xbe then cp8(
|
244
|
-
when 0xbf then cp8(
|
172
|
+
when 0x77 then ld8({ type: :indirect, value: :hl }, { type: :register8, value: :a })
|
173
|
+
when 0x78 then ld8({ type: :register8, value: :a }, { type: :register8, value: :b })
|
174
|
+
when 0x79 then ld8({ type: :register8, value: :a }, { type: :register8, value: :c })
|
175
|
+
when 0x7a then ld8({ type: :register8, value: :a }, { type: :register8, value: :d })
|
176
|
+
when 0x7b then ld8({ type: :register8, value: :a }, { type: :register8, value: :e })
|
177
|
+
when 0x7c then ld8({ type: :register8, value: :a }, { type: :register8, value: :h })
|
178
|
+
when 0x7d then ld8({ type: :register8, value: :a }, { type: :register8, value: :l })
|
179
|
+
when 0x7e then ld8({ type: :register8, value: :a }, { type: :indirect, value: :hl })
|
180
|
+
when 0x7f then ld8({ type: :register8, value: :a }, { type: :register8, value: :a })
|
181
|
+
when 0x80 then add8({ type: :register8, value: :b })
|
182
|
+
when 0x81 then add8({ type: :register8, value: :c })
|
183
|
+
when 0x82 then add8({ type: :register8, value: :d })
|
184
|
+
when 0x83 then add8({ type: :register8, value: :e })
|
185
|
+
when 0x84 then add8({ type: :register8, value: :h })
|
186
|
+
when 0x85 then add8({ type: :register8, value: :l })
|
187
|
+
when 0x86 then add8({ type: :indirect, value: :hl })
|
188
|
+
when 0x87 then add8({ type: :register8, value: :a })
|
189
|
+
when 0x88 then adc8({ type: :register8, value: :b })
|
190
|
+
when 0x89 then adc8({ type: :register8, value: :c })
|
191
|
+
when 0x8a then adc8({ type: :register8, value: :d })
|
192
|
+
when 0x8b then adc8({ type: :register8, value: :e })
|
193
|
+
when 0x8c then adc8({ type: :register8, value: :h })
|
194
|
+
when 0x8d then adc8({ type: :register8, value: :l })
|
195
|
+
when 0x8e then adc8({ type: :indirect, value: :hl })
|
196
|
+
when 0x8f then adc8({ type: :register8, value: :a })
|
197
|
+
when 0x90 then sub8({ type: :register8, value: :b })
|
198
|
+
when 0x91 then sub8({ type: :register8, value: :c })
|
199
|
+
when 0x92 then sub8({ type: :register8, value: :d })
|
200
|
+
when 0x93 then sub8({ type: :register8, value: :e })
|
201
|
+
when 0x94 then sub8({ type: :register8, value: :h })
|
202
|
+
when 0x95 then sub8({ type: :register8, value: :l })
|
203
|
+
when 0x96 then sub8({ type: :indirect, value: :hl })
|
204
|
+
when 0x97 then sub8({ type: :register8, value: :a })
|
205
|
+
when 0x98 then sbc8({ type: :register8, value: :b })
|
206
|
+
when 0x99 then sbc8({ type: :register8, value: :c })
|
207
|
+
when 0x9a then sbc8({ type: :register8, value: :d })
|
208
|
+
when 0x9b then sbc8({ type: :register8, value: :e })
|
209
|
+
when 0x9c then sbc8({ type: :register8, value: :h })
|
210
|
+
when 0x9d then sbc8({ type: :register8, value: :l })
|
211
|
+
when 0x9e then sbc8({ type: :indirect, value: :hl })
|
212
|
+
when 0x9f then sbc8({ type: :register8, value: :a })
|
213
|
+
when 0xa0 then and8({ type: :register8, value: :b })
|
214
|
+
when 0xa1 then and8({ type: :register8, value: :c })
|
215
|
+
when 0xa2 then and8({ type: :register8, value: :d })
|
216
|
+
when 0xa3 then and8({ type: :register8, value: :e })
|
217
|
+
when 0xa4 then and8({ type: :register8, value: :h })
|
218
|
+
when 0xa5 then and8({ type: :register8, value: :l })
|
219
|
+
when 0xa6 then and8({ type: :indirect, value: :hl })
|
220
|
+
when 0xa7 then and8({ type: :register8, value: :a })
|
221
|
+
when 0xa8 then xor8({ type: :register8, value: :b })
|
222
|
+
when 0xa9 then xor8({ type: :register8, value: :c })
|
223
|
+
when 0xaa then xor8({ type: :register8, value: :d })
|
224
|
+
when 0xab then xor8({ type: :register8, value: :e })
|
225
|
+
when 0xac then xor8({ type: :register8, value: :h })
|
226
|
+
when 0xad then xor8({ type: :register8, value: :l })
|
227
|
+
when 0xae then xor8({ type: :indirect, value: :hl })
|
228
|
+
when 0xaf then xor8({ type: :register8, value: :a })
|
229
|
+
when 0xb0 then or8({ type: :register8, value: :b })
|
230
|
+
when 0xb1 then or8({ type: :register8, value: :c })
|
231
|
+
when 0xb2 then or8({ type: :register8, value: :d })
|
232
|
+
when 0xb3 then or8({ type: :register8, value: :e })
|
233
|
+
when 0xb4 then or8({ type: :register8, value: :h })
|
234
|
+
when 0xb5 then or8({ type: :register8, value: :l })
|
235
|
+
when 0xb6 then or8({ type: :indirect, value: :hl })
|
236
|
+
when 0xb7 then or8({ type: :register8, value: :a })
|
237
|
+
when 0xb8 then cp8({ type: :register8, value: :b })
|
238
|
+
when 0xb9 then cp8({ type: :register8, value: :c })
|
239
|
+
when 0xba then cp8({ type: :register8, value: :d })
|
240
|
+
when 0xbb then cp8({ type: :register8, value: :e })
|
241
|
+
when 0xbc then cp8({ type: :register8, value: :h })
|
242
|
+
when 0xbd then cp8({ type: :register8, value: :l })
|
243
|
+
when 0xbe then cp8({ type: :indirect, value: :hl })
|
244
|
+
when 0xbf then cp8({ type: :register8, value: :a })
|
245
245
|
when 0xc0 then ret_if(!flags[:z])
|
246
246
|
when 0xc1 then pop16(:bc)
|
247
|
-
when 0xc2 then jp(
|
248
|
-
when 0xc3 then jp(
|
249
|
-
when 0xc4 then call16(
|
247
|
+
when 0xc2 then jp({ type: :immediate16 }, condition: !flags[:z])
|
248
|
+
when 0xc3 then jp({ type: :immediate16 })
|
249
|
+
when 0xc4 then call16({ type: :immediate16 }, condition: !flags[:z])
|
250
250
|
when 0xc5 then push16(:bc)
|
251
|
-
when 0xc6 then add8(
|
251
|
+
when 0xc6 then add8({ type: :immediate8 })
|
252
252
|
when 0xc7 then rst(0x00)
|
253
253
|
when 0xc8 then ret_if(flags[:z])
|
254
254
|
when 0xc9 then ret
|
255
|
-
when 0xca then jp(
|
256
|
-
when 0xcc then call16(
|
257
|
-
when 0xcd then call16(
|
258
|
-
when 0xce then adc8(
|
255
|
+
when 0xca then jp({ type: :immediate16 }, condition: flags[:z])
|
256
|
+
when 0xcc then call16({ type: :immediate16 }, condition: flags[:z])
|
257
|
+
when 0xcd then call16({ type: :immediate16 })
|
258
|
+
when 0xce then adc8({ type: :immediate8 })
|
259
259
|
when 0xcf then rst(0x08)
|
260
260
|
when 0xd0 then ret_if(!flags[:c])
|
261
261
|
when 0xd1 then pop16(:de)
|
262
|
-
when 0xd2 then jp(
|
263
|
-
when 0xd4 then call16(
|
262
|
+
when 0xd2 then jp({ type: :immediate16 }, condition: !flags[:c])
|
263
|
+
when 0xd4 then call16({ type: :immediate16 }, condition: !flags[:c])
|
264
264
|
when 0xd5 then push16(:de)
|
265
|
-
when 0xd6 then sub8(
|
265
|
+
when 0xd6 then sub8({ type: :immediate8 })
|
266
266
|
when 0xd7 then rst(0x10)
|
267
267
|
when 0xd8 then ret_if(flags[:c])
|
268
268
|
when 0xd9 then reti
|
269
|
-
when 0xda then jp(
|
270
|
-
when 0xdc then call16(
|
271
|
-
when 0xde then sbc8(
|
269
|
+
when 0xda then jp({ type: :immediate16 }, condition: flags[:c])
|
270
|
+
when 0xdc then call16({ type: :immediate16 }, condition: flags[:c])
|
271
|
+
when 0xde then sbc8({ type: :immediate8 })
|
272
272
|
when 0xdf then rst(0x18)
|
273
|
-
when 0xe0 then ld8(
|
273
|
+
when 0xe0 then ld8({ type: :ff00 }, { type: :register8, value: :a })
|
274
274
|
when 0xe1 then pop16(:hl)
|
275
|
-
when 0xe2 then ld8(
|
275
|
+
when 0xe2 then ld8({ type: :ff00_c }, { type: :register8, value: :a })
|
276
276
|
when 0xe5 then push16(:hl)
|
277
|
-
when 0xe6 then and8(
|
277
|
+
when 0xe6 then and8({ type: :immediate8 })
|
278
278
|
when 0xe7 then rst(0x20)
|
279
279
|
when 0xe8 then add_sp_r8
|
280
|
-
when 0xe9 then jp(
|
281
|
-
when 0xea then ld8(
|
282
|
-
when 0xee then xor8(
|
280
|
+
when 0xe9 then jp({ type: :register16, value: :hl })
|
281
|
+
when 0xea then ld8({ type: :direct8 }, { type: :register8, value: :a })
|
282
|
+
when 0xee then xor8({ type: :immediate8 })
|
283
283
|
when 0xef then rst(0x28)
|
284
|
-
when 0xf0 then ld8(
|
284
|
+
when 0xf0 then ld8({ type: :register8, value: :a }, { type: :ff00 })
|
285
285
|
when 0xf1 then pop16(:af)
|
286
|
-
when 0xf2 then ld8(
|
286
|
+
when 0xf2 then ld8({ type: :register8, value: :a }, { type: :ff00_c })
|
287
287
|
when 0xf3 then di
|
288
288
|
when 0xf5 then push16(:af)
|
289
|
-
when 0xf6 then or8(
|
289
|
+
when 0xf6 then or8({ type: :immediate8 })
|
290
290
|
when 0xf7 then rst(0x30)
|
291
291
|
when 0xf8 then ld_hl_sp_r8
|
292
|
-
when 0xf9 then ld16(
|
293
|
-
when 0xfa then ld8(
|
292
|
+
when 0xf9 then ld16({ type: :sp }, { type: :register16, value: :hl })
|
293
|
+
when 0xfa then ld8({ type: :register8, value: :a }, { type: :direct8 })
|
294
294
|
when 0xfb then ei
|
295
|
-
when 0xfe then cp8(
|
295
|
+
when 0xfe then cp8({ type: :immediate8 })
|
296
296
|
when 0xff then rst(0x38)
|
297
297
|
when 0xcb # CB prefix
|
298
298
|
opcode = read_byte_and_advance_pc
|
299
299
|
|
300
300
|
case opcode
|
301
|
-
when 0x00 then rlc8(
|
302
|
-
when 0x01 then rlc8(
|
303
|
-
when 0x02 then rlc8(
|
304
|
-
when 0x03 then rlc8(
|
305
|
-
when 0x04 then rlc8(
|
306
|
-
when 0x05 then rlc8(
|
307
|
-
when 0x06 then rlc8(
|
308
|
-
when 0x07 then rlc8(
|
309
|
-
when 0x08 then rrc8(
|
310
|
-
when 0x09 then rrc8(
|
311
|
-
when 0x0a then rrc8(
|
312
|
-
when 0x0b then rrc8(
|
313
|
-
when 0x0c then rrc8(
|
314
|
-
when 0x0d then rrc8(
|
315
|
-
when 0x0e then rrc8(
|
316
|
-
when 0x0f then rrc8(
|
317
|
-
when 0x10 then rl8(
|
318
|
-
when 0x11 then rl8(
|
319
|
-
when 0x12 then rl8(
|
320
|
-
when 0x13 then rl8(
|
321
|
-
when 0x14 then rl8(
|
322
|
-
when 0x15 then rl8(
|
323
|
-
when 0x16 then rl8(
|
324
|
-
when 0x17 then rl8(
|
325
|
-
when 0x18 then rr8(
|
326
|
-
when 0x19 then rr8(
|
327
|
-
when 0x1a then rr8(
|
328
|
-
when 0x1b then rr8(
|
329
|
-
when 0x1c then rr8(
|
330
|
-
when 0x1d then rr8(
|
331
|
-
when 0x1e then rr8(
|
332
|
-
when 0x1f then rr8(
|
333
|
-
when 0x20 then sla8(
|
334
|
-
when 0x21 then sla8(
|
335
|
-
when 0x22 then sla8(
|
336
|
-
when 0x23 then sla8(
|
337
|
-
when 0x24 then sla8(
|
338
|
-
when 0x25 then sla8(
|
339
|
-
when 0x26 then sla8(
|
340
|
-
when 0x27 then sla8(
|
341
|
-
when 0x28 then sra8(
|
342
|
-
when 0x29 then sra8(
|
343
|
-
when 0x2a then sra8(
|
344
|
-
when 0x2b then sra8(
|
345
|
-
when 0x2c then sra8(
|
346
|
-
when 0x2d then sra8(
|
347
|
-
when 0x2e then sra8(
|
348
|
-
when 0x2f then sra8(
|
349
|
-
when 0x30 then swap8(
|
350
|
-
when 0x31 then swap8(
|
351
|
-
when 0x32 then swap8(
|
352
|
-
when 0x33 then swap8(
|
353
|
-
when 0x34 then swap8(
|
354
|
-
when 0x35 then swap8(
|
355
|
-
when 0x36 then swap8(
|
356
|
-
when 0x37 then swap8(
|
357
|
-
when 0x38 then srl8(
|
358
|
-
when 0x39 then srl8(
|
359
|
-
when 0x3a then srl8(
|
360
|
-
when 0x3b then srl8(
|
361
|
-
when 0x3c then srl8(
|
362
|
-
when 0x3d then srl8(
|
363
|
-
when 0x3e then srl8(
|
364
|
-
when 0x3f then srl8(
|
365
|
-
when 0x40 then bit8(0,
|
366
|
-
when 0x41 then bit8(0,
|
367
|
-
when 0x42 then bit8(0,
|
368
|
-
when 0x43 then bit8(0,
|
369
|
-
when 0x44 then bit8(0,
|
370
|
-
when 0x45 then bit8(0,
|
371
|
-
when 0x46 then bit8(0,
|
372
|
-
when 0x47 then bit8(0,
|
373
|
-
when 0x48 then bit8(1,
|
374
|
-
when 0x49 then bit8(1,
|
375
|
-
when 0x4a then bit8(1,
|
376
|
-
when 0x4b then bit8(1,
|
377
|
-
when 0x4c then bit8(1,
|
378
|
-
when 0x4d then bit8(1,
|
379
|
-
when 0x4e then bit8(1,
|
380
|
-
when 0x4f then bit8(1,
|
381
|
-
when 0x50 then bit8(2,
|
382
|
-
when 0x51 then bit8(2,
|
383
|
-
when 0x52 then bit8(2,
|
384
|
-
when 0x53 then bit8(2,
|
385
|
-
when 0x54 then bit8(2,
|
386
|
-
when 0x55 then bit8(2,
|
387
|
-
when 0x56 then bit8(2,
|
388
|
-
when 0x57 then bit8(2,
|
389
|
-
when 0x58 then bit8(3,
|
390
|
-
when 0x59 then bit8(3,
|
391
|
-
when 0x5a then bit8(3,
|
392
|
-
when 0x5b then bit8(3,
|
393
|
-
when 0x5c then bit8(3,
|
394
|
-
when 0x5d then bit8(3,
|
395
|
-
when 0x5e then bit8(3,
|
396
|
-
when 0x5f then bit8(3,
|
397
|
-
when 0x60 then bit8(4,
|
398
|
-
when 0x61 then bit8(4,
|
399
|
-
when 0x62 then bit8(4,
|
400
|
-
when 0x63 then bit8(4,
|
401
|
-
when 0x64 then bit8(4,
|
402
|
-
when 0x65 then bit8(4,
|
403
|
-
when 0x66 then bit8(4,
|
404
|
-
when 0x67 then bit8(4,
|
405
|
-
when 0x68 then bit8(5,
|
406
|
-
when 0x69 then bit8(5,
|
407
|
-
when 0x6a then bit8(5,
|
408
|
-
when 0x6b then bit8(5,
|
409
|
-
when 0x6c then bit8(5,
|
410
|
-
when 0x6d then bit8(5,
|
411
|
-
when 0x6e then bit8(5,
|
412
|
-
when 0x6f then bit8(5,
|
413
|
-
when 0x70 then bit8(6,
|
414
|
-
when 0x71 then bit8(6,
|
415
|
-
when 0x72 then bit8(6,
|
416
|
-
when 0x73 then bit8(6,
|
417
|
-
when 0x74 then bit8(6,
|
418
|
-
when 0x75 then bit8(6,
|
419
|
-
when 0x76 then bit8(6,
|
420
|
-
when 0x77 then bit8(6,
|
421
|
-
when 0x78 then bit8(7,
|
422
|
-
when 0x79 then bit8(7,
|
423
|
-
when 0x7a then bit8(7,
|
424
|
-
when 0x7b then bit8(7,
|
425
|
-
when 0x7c then bit8(7,
|
426
|
-
when 0x7d then bit8(7,
|
427
|
-
when 0x7e then bit8(7,
|
428
|
-
when 0x7f then bit8(7,
|
429
|
-
when 0x80 then res8(0,
|
430
|
-
when 0x81 then res8(0,
|
431
|
-
when 0x82 then res8(0,
|
432
|
-
when 0x83 then res8(0,
|
433
|
-
when 0x84 then res8(0,
|
434
|
-
when 0x85 then res8(0,
|
435
|
-
when 0x86 then res8(0,
|
436
|
-
when 0x87 then res8(0,
|
437
|
-
when 0x88 then res8(1,
|
438
|
-
when 0x89 then res8(1,
|
439
|
-
when 0x8a then res8(1,
|
440
|
-
when 0x8b then res8(1,
|
441
|
-
when 0x8c then res8(1,
|
442
|
-
when 0x8d then res8(1,
|
443
|
-
when 0x8e then res8(1,
|
444
|
-
when 0x8f then res8(1,
|
445
|
-
when 0x90 then res8(2,
|
446
|
-
when 0x91 then res8(2,
|
447
|
-
when 0x92 then res8(2,
|
448
|
-
when 0x93 then res8(2,
|
449
|
-
when 0x94 then res8(2,
|
450
|
-
when 0x95 then res8(2,
|
451
|
-
when 0x96 then res8(2,
|
452
|
-
when 0x97 then res8(2,
|
453
|
-
when 0x98 then res8(3,
|
454
|
-
when 0x99 then res8(3,
|
455
|
-
when 0x9a then res8(3,
|
456
|
-
when 0x9b then res8(3,
|
457
|
-
when 0x9c then res8(3,
|
458
|
-
when 0x9d then res8(3,
|
459
|
-
when 0x9e then res8(3,
|
460
|
-
when 0x9f then res8(3,
|
461
|
-
when 0xa0 then res8(4,
|
462
|
-
when 0xa1 then res8(4,
|
463
|
-
when 0xa2 then res8(4,
|
464
|
-
when 0xa3 then res8(4,
|
465
|
-
when 0xa4 then res8(4,
|
466
|
-
when 0xa5 then res8(4,
|
467
|
-
when 0xa6 then res8(4,
|
468
|
-
when 0xa7 then res8(4,
|
469
|
-
when 0xa8 then res8(5,
|
470
|
-
when 0xa9 then res8(5,
|
471
|
-
when 0xaa then res8(5,
|
472
|
-
when 0xab then res8(5,
|
473
|
-
when 0xac then res8(5,
|
474
|
-
when 0xad then res8(5,
|
475
|
-
when 0xae then res8(5,
|
476
|
-
when 0xaf then res8(5,
|
477
|
-
when 0xb0 then res8(6,
|
478
|
-
when 0xb1 then res8(6,
|
479
|
-
when 0xb2 then res8(6,
|
480
|
-
when 0xb3 then res8(6,
|
481
|
-
when 0xb4 then res8(6,
|
482
|
-
when 0xb5 then res8(6,
|
483
|
-
when 0xb6 then res8(6,
|
484
|
-
when 0xb7 then res8(6,
|
485
|
-
when 0xb8 then res8(7,
|
486
|
-
when 0xb9 then res8(7,
|
487
|
-
when 0xba then res8(7,
|
488
|
-
when 0xbb then res8(7,
|
489
|
-
when 0xbc then res8(7,
|
490
|
-
when 0xbd then res8(7,
|
491
|
-
when 0xbe then res8(7,
|
492
|
-
when 0xbf then res8(7,
|
493
|
-
when 0xc0 then set8(0,
|
494
|
-
when 0xc1 then set8(0,
|
495
|
-
when 0xc2 then set8(0,
|
496
|
-
when 0xc3 then set8(0,
|
497
|
-
when 0xc4 then set8(0,
|
498
|
-
when 0xc5 then set8(0,
|
499
|
-
when 0xc6 then set8(0,
|
500
|
-
when 0xc7 then set8(0,
|
501
|
-
when 0xc8 then set8(1,
|
502
|
-
when 0xc9 then set8(1,
|
503
|
-
when 0xca then set8(1,
|
504
|
-
when 0xcb then set8(1,
|
505
|
-
when 0xcc then set8(1,
|
506
|
-
when 0xcd then set8(1,
|
507
|
-
when 0xce then set8(1,
|
508
|
-
when 0xcf then set8(1,
|
509
|
-
when 0xd0 then set8(2,
|
510
|
-
when 0xd1 then set8(2,
|
511
|
-
when 0xd2 then set8(2,
|
512
|
-
when 0xd3 then set8(2,
|
513
|
-
when 0xd4 then set8(2,
|
514
|
-
when 0xd5 then set8(2,
|
515
|
-
when 0xd6 then set8(2,
|
516
|
-
when 0xd7 then set8(2,
|
517
|
-
when 0xd8 then set8(3,
|
518
|
-
when 0xd9 then set8(3,
|
519
|
-
when 0xda then set8(3,
|
520
|
-
when 0xdb then set8(3,
|
521
|
-
when 0xdc then set8(3,
|
522
|
-
when 0xdd then set8(3,
|
523
|
-
when 0xde then set8(3,
|
524
|
-
when 0xdf then set8(3,
|
525
|
-
when 0xe0 then set8(4,
|
526
|
-
when 0xe1 then set8(4,
|
527
|
-
when 0xe2 then set8(4,
|
528
|
-
when 0xe3 then set8(4,
|
529
|
-
when 0xe4 then set8(4,
|
530
|
-
when 0xe5 then set8(4,
|
531
|
-
when 0xe6 then set8(4,
|
532
|
-
when 0xe7 then set8(4,
|
533
|
-
when 0xe8 then set8(5,
|
534
|
-
when 0xe9 then set8(5,
|
535
|
-
when 0xea then set8(5,
|
536
|
-
when 0xeb then set8(5,
|
537
|
-
when 0xec then set8(5,
|
538
|
-
when 0xed then set8(5,
|
539
|
-
when 0xee then set8(5,
|
540
|
-
when 0xef then set8(5,
|
541
|
-
when 0xf0 then set8(6,
|
542
|
-
when 0xf1 then set8(6,
|
543
|
-
when 0xf2 then set8(6,
|
544
|
-
when 0xf3 then set8(6,
|
545
|
-
when 0xf4 then set8(6,
|
546
|
-
when 0xf5 then set8(6,
|
547
|
-
when 0xf6 then set8(6,
|
548
|
-
when 0xf7 then set8(6,
|
549
|
-
when 0xf8 then set8(7,
|
550
|
-
when 0xf9 then set8(7,
|
551
|
-
when 0xfa then set8(7,
|
552
|
-
when 0xfb then set8(7,
|
553
|
-
when 0xfc then set8(7,
|
554
|
-
when 0xfd then set8(7,
|
555
|
-
when 0xfe then set8(7,
|
556
|
-
when 0xff then set8(7,
|
301
|
+
when 0x00 then rlc8({ type: :register8, value: :b })
|
302
|
+
when 0x01 then rlc8({ type: :register8, value: :c })
|
303
|
+
when 0x02 then rlc8({ type: :register8, value: :d })
|
304
|
+
when 0x03 then rlc8({ type: :register8, value: :e })
|
305
|
+
when 0x04 then rlc8({ type: :register8, value: :h })
|
306
|
+
when 0x05 then rlc8({ type: :register8, value: :l })
|
307
|
+
when 0x06 then rlc8({ type: :indirect, value: :hl })
|
308
|
+
when 0x07 then rlc8({ type: :register8, value: :a })
|
309
|
+
when 0x08 then rrc8({ type: :register8, value: :b })
|
310
|
+
when 0x09 then rrc8({ type: :register8, value: :c })
|
311
|
+
when 0x0a then rrc8({ type: :register8, value: :d })
|
312
|
+
when 0x0b then rrc8({ type: :register8, value: :e })
|
313
|
+
when 0x0c then rrc8({ type: :register8, value: :h })
|
314
|
+
when 0x0d then rrc8({ type: :register8, value: :l })
|
315
|
+
when 0x0e then rrc8({ type: :indirect, value: :hl })
|
316
|
+
when 0x0f then rrc8({ type: :register8, value: :a })
|
317
|
+
when 0x10 then rl8({ type: :register8, value: :b })
|
318
|
+
when 0x11 then rl8({ type: :register8, value: :c })
|
319
|
+
when 0x12 then rl8({ type: :register8, value: :d })
|
320
|
+
when 0x13 then rl8({ type: :register8, value: :e })
|
321
|
+
when 0x14 then rl8({ type: :register8, value: :h })
|
322
|
+
when 0x15 then rl8({ type: :register8, value: :l })
|
323
|
+
when 0x16 then rl8({ type: :indirect, value: :hl })
|
324
|
+
when 0x17 then rl8({ type: :register8, value: :a })
|
325
|
+
when 0x18 then rr8({ type: :register8, value: :b })
|
326
|
+
when 0x19 then rr8({ type: :register8, value: :c })
|
327
|
+
when 0x1a then rr8({ type: :register8, value: :d })
|
328
|
+
when 0x1b then rr8({ type: :register8, value: :e })
|
329
|
+
when 0x1c then rr8({ type: :register8, value: :h })
|
330
|
+
when 0x1d then rr8({ type: :register8, value: :l })
|
331
|
+
when 0x1e then rr8({ type: :indirect, value: :hl })
|
332
|
+
when 0x1f then rr8({ type: :register8, value: :a })
|
333
|
+
when 0x20 then sla8({ type: :register8, value: :b })
|
334
|
+
when 0x21 then sla8({ type: :register8, value: :c })
|
335
|
+
when 0x22 then sla8({ type: :register8, value: :d })
|
336
|
+
when 0x23 then sla8({ type: :register8, value: :e })
|
337
|
+
when 0x24 then sla8({ type: :register8, value: :h })
|
338
|
+
when 0x25 then sla8({ type: :register8, value: :l })
|
339
|
+
when 0x26 then sla8({ type: :indirect, value: :hl })
|
340
|
+
when 0x27 then sla8({ type: :register8, value: :a })
|
341
|
+
when 0x28 then sra8({ type: :register8, value: :b })
|
342
|
+
when 0x29 then sra8({ type: :register8, value: :c })
|
343
|
+
when 0x2a then sra8({ type: :register8, value: :d })
|
344
|
+
when 0x2b then sra8({ type: :register8, value: :e })
|
345
|
+
when 0x2c then sra8({ type: :register8, value: :h })
|
346
|
+
when 0x2d then sra8({ type: :register8, value: :l })
|
347
|
+
when 0x2e then sra8({ type: :indirect, value: :hl })
|
348
|
+
when 0x2f then sra8({ type: :register8, value: :a })
|
349
|
+
when 0x30 then swap8({ type: :register8, value: :b })
|
350
|
+
when 0x31 then swap8({ type: :register8, value: :c })
|
351
|
+
when 0x32 then swap8({ type: :register8, value: :d })
|
352
|
+
when 0x33 then swap8({ type: :register8, value: :e })
|
353
|
+
when 0x34 then swap8({ type: :register8, value: :h })
|
354
|
+
when 0x35 then swap8({ type: :register8, value: :l })
|
355
|
+
when 0x36 then swap8({ type: :indirect, value: :hl })
|
356
|
+
when 0x37 then swap8({ type: :register8, value: :a })
|
357
|
+
when 0x38 then srl8({ type: :register8, value: :b })
|
358
|
+
when 0x39 then srl8({ type: :register8, value: :c })
|
359
|
+
when 0x3a then srl8({ type: :register8, value: :d })
|
360
|
+
when 0x3b then srl8({ type: :register8, value: :e })
|
361
|
+
when 0x3c then srl8({ type: :register8, value: :h })
|
362
|
+
when 0x3d then srl8({ type: :register8, value: :l })
|
363
|
+
when 0x3e then srl8({ type: :indirect, value: :hl })
|
364
|
+
when 0x3f then srl8({ type: :register8, value: :a })
|
365
|
+
when 0x40 then bit8(0, { type: :register8, value: :b })
|
366
|
+
when 0x41 then bit8(0, { type: :register8, value: :c })
|
367
|
+
when 0x42 then bit8(0, { type: :register8, value: :d })
|
368
|
+
when 0x43 then bit8(0, { type: :register8, value: :e })
|
369
|
+
when 0x44 then bit8(0, { type: :register8, value: :h })
|
370
|
+
when 0x45 then bit8(0, { type: :register8, value: :l })
|
371
|
+
when 0x46 then bit8(0, { type: :indirect, value: :hl })
|
372
|
+
when 0x47 then bit8(0, { type: :register8, value: :a })
|
373
|
+
when 0x48 then bit8(1, { type: :register8, value: :b })
|
374
|
+
when 0x49 then bit8(1, { type: :register8, value: :c })
|
375
|
+
when 0x4a then bit8(1, { type: :register8, value: :d })
|
376
|
+
when 0x4b then bit8(1, { type: :register8, value: :e })
|
377
|
+
when 0x4c then bit8(1, { type: :register8, value: :h })
|
378
|
+
when 0x4d then bit8(1, { type: :register8, value: :l })
|
379
|
+
when 0x4e then bit8(1, { type: :indirect, value: :hl })
|
380
|
+
when 0x4f then bit8(1, { type: :register8, value: :a })
|
381
|
+
when 0x50 then bit8(2, { type: :register8, value: :b })
|
382
|
+
when 0x51 then bit8(2, { type: :register8, value: :c })
|
383
|
+
when 0x52 then bit8(2, { type: :register8, value: :d })
|
384
|
+
when 0x53 then bit8(2, { type: :register8, value: :e })
|
385
|
+
when 0x54 then bit8(2, { type: :register8, value: :h })
|
386
|
+
when 0x55 then bit8(2, { type: :register8, value: :l })
|
387
|
+
when 0x56 then bit8(2, { type: :indirect, value: :hl })
|
388
|
+
when 0x57 then bit8(2, { type: :register8, value: :a })
|
389
|
+
when 0x58 then bit8(3, { type: :register8, value: :b })
|
390
|
+
when 0x59 then bit8(3, { type: :register8, value: :c })
|
391
|
+
when 0x5a then bit8(3, { type: :register8, value: :d })
|
392
|
+
when 0x5b then bit8(3, { type: :register8, value: :e })
|
393
|
+
when 0x5c then bit8(3, { type: :register8, value: :h })
|
394
|
+
when 0x5d then bit8(3, { type: :register8, value: :l })
|
395
|
+
when 0x5e then bit8(3, { type: :indirect, value: :hl })
|
396
|
+
when 0x5f then bit8(3, { type: :register8, value: :a })
|
397
|
+
when 0x60 then bit8(4, { type: :register8, value: :b })
|
398
|
+
when 0x61 then bit8(4, { type: :register8, value: :c })
|
399
|
+
when 0x62 then bit8(4, { type: :register8, value: :d })
|
400
|
+
when 0x63 then bit8(4, { type: :register8, value: :e })
|
401
|
+
when 0x64 then bit8(4, { type: :register8, value: :h })
|
402
|
+
when 0x65 then bit8(4, { type: :register8, value: :l })
|
403
|
+
when 0x66 then bit8(4, { type: :indirect, value: :hl })
|
404
|
+
when 0x67 then bit8(4, { type: :register8, value: :a })
|
405
|
+
when 0x68 then bit8(5, { type: :register8, value: :b })
|
406
|
+
when 0x69 then bit8(5, { type: :register8, value: :c })
|
407
|
+
when 0x6a then bit8(5, { type: :register8, value: :d })
|
408
|
+
when 0x6b then bit8(5, { type: :register8, value: :e })
|
409
|
+
when 0x6c then bit8(5, { type: :register8, value: :h })
|
410
|
+
when 0x6d then bit8(5, { type: :register8, value: :l })
|
411
|
+
when 0x6e then bit8(5, { type: :indirect, value: :hl })
|
412
|
+
when 0x6f then bit8(5, { type: :register8, value: :a })
|
413
|
+
when 0x70 then bit8(6, { type: :register8, value: :b })
|
414
|
+
when 0x71 then bit8(6, { type: :register8, value: :c })
|
415
|
+
when 0x72 then bit8(6, { type: :register8, value: :d })
|
416
|
+
when 0x73 then bit8(6, { type: :register8, value: :e })
|
417
|
+
when 0x74 then bit8(6, { type: :register8, value: :h })
|
418
|
+
when 0x75 then bit8(6, { type: :register8, value: :l })
|
419
|
+
when 0x76 then bit8(6, { type: :indirect, value: :hl })
|
420
|
+
when 0x77 then bit8(6, { type: :register8, value: :a })
|
421
|
+
when 0x78 then bit8(7, { type: :register8, value: :b })
|
422
|
+
when 0x79 then bit8(7, { type: :register8, value: :c })
|
423
|
+
when 0x7a then bit8(7, { type: :register8, value: :d })
|
424
|
+
when 0x7b then bit8(7, { type: :register8, value: :e })
|
425
|
+
when 0x7c then bit8(7, { type: :register8, value: :h })
|
426
|
+
when 0x7d then bit8(7, { type: :register8, value: :l })
|
427
|
+
when 0x7e then bit8(7, { type: :indirect, value: :hl })
|
428
|
+
when 0x7f then bit8(7, { type: :register8, value: :a })
|
429
|
+
when 0x80 then res8(0, { type: :register8, value: :b })
|
430
|
+
when 0x81 then res8(0, { type: :register8, value: :c })
|
431
|
+
when 0x82 then res8(0, { type: :register8, value: :d })
|
432
|
+
when 0x83 then res8(0, { type: :register8, value: :e })
|
433
|
+
when 0x84 then res8(0, { type: :register8, value: :h })
|
434
|
+
when 0x85 then res8(0, { type: :register8, value: :l })
|
435
|
+
when 0x86 then res8(0, { type: :indirect, value: :hl })
|
436
|
+
when 0x87 then res8(0, { type: :register8, value: :a })
|
437
|
+
when 0x88 then res8(1, { type: :register8, value: :b })
|
438
|
+
when 0x89 then res8(1, { type: :register8, value: :c })
|
439
|
+
when 0x8a then res8(1, { type: :register8, value: :d })
|
440
|
+
when 0x8b then res8(1, { type: :register8, value: :e })
|
441
|
+
when 0x8c then res8(1, { type: :register8, value: :h })
|
442
|
+
when 0x8d then res8(1, { type: :register8, value: :l })
|
443
|
+
when 0x8e then res8(1, { type: :indirect, value: :hl })
|
444
|
+
when 0x8f then res8(1, { type: :register8, value: :a })
|
445
|
+
when 0x90 then res8(2, { type: :register8, value: :b })
|
446
|
+
when 0x91 then res8(2, { type: :register8, value: :c })
|
447
|
+
when 0x92 then res8(2, { type: :register8, value: :d })
|
448
|
+
when 0x93 then res8(2, { type: :register8, value: :e })
|
449
|
+
when 0x94 then res8(2, { type: :register8, value: :h })
|
450
|
+
when 0x95 then res8(2, { type: :register8, value: :l })
|
451
|
+
when 0x96 then res8(2, { type: :indirect, value: :hl })
|
452
|
+
when 0x97 then res8(2, { type: :register8, value: :a })
|
453
|
+
when 0x98 then res8(3, { type: :register8, value: :b })
|
454
|
+
when 0x99 then res8(3, { type: :register8, value: :c })
|
455
|
+
when 0x9a then res8(3, { type: :register8, value: :d })
|
456
|
+
when 0x9b then res8(3, { type: :register8, value: :e })
|
457
|
+
when 0x9c then res8(3, { type: :register8, value: :h })
|
458
|
+
when 0x9d then res8(3, { type: :register8, value: :l })
|
459
|
+
when 0x9e then res8(3, { type: :indirect, value: :hl })
|
460
|
+
when 0x9f then res8(3, { type: :register8, value: :a })
|
461
|
+
when 0xa0 then res8(4, { type: :register8, value: :b })
|
462
|
+
when 0xa1 then res8(4, { type: :register8, value: :c })
|
463
|
+
when 0xa2 then res8(4, { type: :register8, value: :d })
|
464
|
+
when 0xa3 then res8(4, { type: :register8, value: :e })
|
465
|
+
when 0xa4 then res8(4, { type: :register8, value: :h })
|
466
|
+
when 0xa5 then res8(4, { type: :register8, value: :l })
|
467
|
+
when 0xa6 then res8(4, { type: :indirect, value: :hl })
|
468
|
+
when 0xa7 then res8(4, { type: :register8, value: :a })
|
469
|
+
when 0xa8 then res8(5, { type: :register8, value: :b })
|
470
|
+
when 0xa9 then res8(5, { type: :register8, value: :c })
|
471
|
+
when 0xaa then res8(5, { type: :register8, value: :d })
|
472
|
+
when 0xab then res8(5, { type: :register8, value: :e })
|
473
|
+
when 0xac then res8(5, { type: :register8, value: :h })
|
474
|
+
when 0xad then res8(5, { type: :register8, value: :l })
|
475
|
+
when 0xae then res8(5, { type: :indirect, value: :hl })
|
476
|
+
when 0xaf then res8(5, { type: :register8, value: :a })
|
477
|
+
when 0xb0 then res8(6, { type: :register8, value: :b })
|
478
|
+
when 0xb1 then res8(6, { type: :register8, value: :c })
|
479
|
+
when 0xb2 then res8(6, { type: :register8, value: :d })
|
480
|
+
when 0xb3 then res8(6, { type: :register8, value: :e })
|
481
|
+
when 0xb4 then res8(6, { type: :register8, value: :h })
|
482
|
+
when 0xb5 then res8(6, { type: :register8, value: :l })
|
483
|
+
when 0xb6 then res8(6, { type: :indirect, value: :hl })
|
484
|
+
when 0xb7 then res8(6, { type: :register8, value: :a })
|
485
|
+
when 0xb8 then res8(7, { type: :register8, value: :b })
|
486
|
+
when 0xb9 then res8(7, { type: :register8, value: :c })
|
487
|
+
when 0xba then res8(7, { type: :register8, value: :d })
|
488
|
+
when 0xbb then res8(7, { type: :register8, value: :e })
|
489
|
+
when 0xbc then res8(7, { type: :register8, value: :h })
|
490
|
+
when 0xbd then res8(7, { type: :register8, value: :l })
|
491
|
+
when 0xbe then res8(7, { type: :indirect, value: :hl })
|
492
|
+
when 0xbf then res8(7, { type: :register8, value: :a })
|
493
|
+
when 0xc0 then set8(0, { type: :register8, value: :b })
|
494
|
+
when 0xc1 then set8(0, { type: :register8, value: :c })
|
495
|
+
when 0xc2 then set8(0, { type: :register8, value: :d })
|
496
|
+
when 0xc3 then set8(0, { type: :register8, value: :e })
|
497
|
+
when 0xc4 then set8(0, { type: :register8, value: :h })
|
498
|
+
when 0xc5 then set8(0, { type: :register8, value: :l })
|
499
|
+
when 0xc6 then set8(0, { type: :indirect, value: :hl })
|
500
|
+
when 0xc7 then set8(0, { type: :register8, value: :a })
|
501
|
+
when 0xc8 then set8(1, { type: :register8, value: :b })
|
502
|
+
when 0xc9 then set8(1, { type: :register8, value: :c })
|
503
|
+
when 0xca then set8(1, { type: :register8, value: :d })
|
504
|
+
when 0xcb then set8(1, { type: :register8, value: :e })
|
505
|
+
when 0xcc then set8(1, { type: :register8, value: :h })
|
506
|
+
when 0xcd then set8(1, { type: :register8, value: :l })
|
507
|
+
when 0xce then set8(1, { type: :indirect, value: :hl })
|
508
|
+
when 0xcf then set8(1, { type: :register8, value: :a })
|
509
|
+
when 0xd0 then set8(2, { type: :register8, value: :b })
|
510
|
+
when 0xd1 then set8(2, { type: :register8, value: :c })
|
511
|
+
when 0xd2 then set8(2, { type: :register8, value: :d })
|
512
|
+
when 0xd3 then set8(2, { type: :register8, value: :e })
|
513
|
+
when 0xd4 then set8(2, { type: :register8, value: :h })
|
514
|
+
when 0xd5 then set8(2, { type: :register8, value: :l })
|
515
|
+
when 0xd6 then set8(2, { type: :indirect, value: :hl })
|
516
|
+
when 0xd7 then set8(2, { type: :register8, value: :a })
|
517
|
+
when 0xd8 then set8(3, { type: :register8, value: :b })
|
518
|
+
when 0xd9 then set8(3, { type: :register8, value: :c })
|
519
|
+
when 0xda then set8(3, { type: :register8, value: :d })
|
520
|
+
when 0xdb then set8(3, { type: :register8, value: :e })
|
521
|
+
when 0xdc then set8(3, { type: :register8, value: :h })
|
522
|
+
when 0xdd then set8(3, { type: :register8, value: :l })
|
523
|
+
when 0xde then set8(3, { type: :indirect, value: :hl })
|
524
|
+
when 0xdf then set8(3, { type: :register8, value: :a })
|
525
|
+
when 0xe0 then set8(4, { type: :register8, value: :b })
|
526
|
+
when 0xe1 then set8(4, { type: :register8, value: :c })
|
527
|
+
when 0xe2 then set8(4, { type: :register8, value: :d })
|
528
|
+
when 0xe3 then set8(4, { type: :register8, value: :e })
|
529
|
+
when 0xe4 then set8(4, { type: :register8, value: :h })
|
530
|
+
when 0xe5 then set8(4, { type: :register8, value: :l })
|
531
|
+
when 0xe6 then set8(4, { type: :indirect, value: :hl })
|
532
|
+
when 0xe7 then set8(4, { type: :register8, value: :a })
|
533
|
+
when 0xe8 then set8(5, { type: :register8, value: :b })
|
534
|
+
when 0xe9 then set8(5, { type: :register8, value: :c })
|
535
|
+
when 0xea then set8(5, { type: :register8, value: :d })
|
536
|
+
when 0xeb then set8(5, { type: :register8, value: :e })
|
537
|
+
when 0xec then set8(5, { type: :register8, value: :h })
|
538
|
+
when 0xed then set8(5, { type: :register8, value: :l })
|
539
|
+
when 0xee then set8(5, { type: :indirect, value: :hl })
|
540
|
+
when 0xef then set8(5, { type: :register8, value: :a })
|
541
|
+
when 0xf0 then set8(6, { type: :register8, value: :b })
|
542
|
+
when 0xf1 then set8(6, { type: :register8, value: :c })
|
543
|
+
when 0xf2 then set8(6, { type: :register8, value: :d })
|
544
|
+
when 0xf3 then set8(6, { type: :register8, value: :e })
|
545
|
+
when 0xf4 then set8(6, { type: :register8, value: :h })
|
546
|
+
when 0xf5 then set8(6, { type: :register8, value: :l })
|
547
|
+
when 0xf6 then set8(6, { type: :indirect, value: :hl })
|
548
|
+
when 0xf7 then set8(6, { type: :register8, value: :a })
|
549
|
+
when 0xf8 then set8(7, { type: :register8, value: :b })
|
550
|
+
when 0xf9 then set8(7, { type: :register8, value: :c })
|
551
|
+
when 0xfa then set8(7, { type: :register8, value: :d })
|
552
|
+
when 0xfb then set8(7, { type: :register8, value: :e })
|
553
|
+
when 0xfc then set8(7, { type: :register8, value: :h })
|
554
|
+
when 0xfd then set8(7, { type: :register8, value: :l })
|
555
|
+
when 0xfe then set8(7, { type: :indirect, value: :hl })
|
556
|
+
when 0xff then set8(7, { type: :register8, value: :a })
|
557
557
|
else
|
558
558
|
raise "unknown opcode: 0xcb 0x#{'%02x' % opcode}"
|
559
559
|
end
|
@@ -706,7 +706,7 @@ module Rubyboy
|
|
706
706
|
|
707
707
|
@registers.write8(:a, a_value)
|
708
708
|
update_flags(
|
709
|
-
z: @registers.read8(:a)
|
709
|
+
z: @registers.read8(:a) == 0,
|
710
710
|
h: false
|
711
711
|
)
|
712
712
|
|
@@ -747,12 +747,12 @@ module Rubyboy
|
|
747
747
|
value = (get_value(x) + 1) & 0xff
|
748
748
|
set_value(x, value)
|
749
749
|
update_flags(
|
750
|
-
z: value
|
750
|
+
z: value == 0,
|
751
751
|
n: false,
|
752
|
-
h: (value & 0x0f)
|
752
|
+
h: (value & 0x0f) == 0
|
753
753
|
)
|
754
754
|
|
755
|
-
x
|
755
|
+
x[:type] == :register8 ? 4 : 12
|
756
756
|
end
|
757
757
|
|
758
758
|
def inc16(x)
|
@@ -765,12 +765,12 @@ module Rubyboy
|
|
765
765
|
value = (get_value(x) - 1) & 0xff
|
766
766
|
set_value(x, value)
|
767
767
|
update_flags(
|
768
|
-
z: value
|
768
|
+
z: value == 0,
|
769
769
|
n: true,
|
770
770
|
h: (value & 0x0f) == 0x0f
|
771
771
|
)
|
772
772
|
|
773
|
-
x
|
773
|
+
x[:type] == :register8 ? 4 : 12
|
774
774
|
end
|
775
775
|
|
776
776
|
def dec16(x)
|
@@ -789,13 +789,13 @@ module Rubyboy
|
|
789
789
|
a_value += x_value
|
790
790
|
@registers.write8(:a, a_value)
|
791
791
|
update_flags(
|
792
|
-
z: @registers.read8(:a)
|
792
|
+
z: @registers.read8(:a) == 0,
|
793
793
|
n: false,
|
794
794
|
h: hflag,
|
795
795
|
c: cflag
|
796
796
|
)
|
797
797
|
|
798
|
-
x
|
798
|
+
x[:type] == :register8 ? 4 : 8
|
799
799
|
end
|
800
800
|
|
801
801
|
def add16(x, y)
|
@@ -842,13 +842,13 @@ module Rubyboy
|
|
842
842
|
a_value -= x_value
|
843
843
|
@registers.write8(:a, a_value)
|
844
844
|
update_flags(
|
845
|
-
z: a_value
|
845
|
+
z: a_value == 0,
|
846
846
|
n: true,
|
847
847
|
h: hflag,
|
848
848
|
c: cflag
|
849
849
|
)
|
850
850
|
|
851
|
-
x
|
851
|
+
x[:type] == :register8 ? 4 : 8
|
852
852
|
end
|
853
853
|
|
854
854
|
def adc8(x)
|
@@ -861,13 +861,13 @@ module Rubyboy
|
|
861
861
|
a_value += x_value + c_value
|
862
862
|
@registers.write8(:a, a_value)
|
863
863
|
update_flags(
|
864
|
-
z: @registers.read8(:a)
|
864
|
+
z: @registers.read8(:a) == 0,
|
865
865
|
n: false,
|
866
866
|
h: hflag,
|
867
867
|
c: cflag
|
868
868
|
)
|
869
869
|
|
870
|
-
x
|
870
|
+
x[:type] == :register8 ? 4 : 8
|
871
871
|
end
|
872
872
|
|
873
873
|
def sbc8(x)
|
@@ -880,52 +880,52 @@ module Rubyboy
|
|
880
880
|
a_value -= x_value + c_value
|
881
881
|
@registers.write8(:a, a_value)
|
882
882
|
update_flags(
|
883
|
-
z: @registers.read8(:a)
|
883
|
+
z: @registers.read8(:a) == 0,
|
884
884
|
n: true,
|
885
885
|
h: hflag,
|
886
886
|
c: cflag
|
887
887
|
)
|
888
888
|
|
889
|
-
x
|
889
|
+
x[:type] == :register8 ? 4 : 8
|
890
890
|
end
|
891
891
|
|
892
892
|
def and8(x)
|
893
893
|
a_value = @registers.read8(:a) & get_value(x)
|
894
894
|
@registers.write8(:a, a_value)
|
895
895
|
update_flags(
|
896
|
-
z: a_value
|
896
|
+
z: a_value == 0,
|
897
897
|
n: false,
|
898
898
|
h: true,
|
899
899
|
c: false
|
900
900
|
)
|
901
901
|
|
902
|
-
x
|
902
|
+
x[:type] == :register8 ? 4 : 8
|
903
903
|
end
|
904
904
|
|
905
905
|
def or8(x)
|
906
906
|
a_value = @registers.read8(:a) | get_value(x)
|
907
907
|
@registers.write8(:a, a_value)
|
908
908
|
update_flags(
|
909
|
-
z: a_value
|
909
|
+
z: a_value == 0,
|
910
910
|
n: false,
|
911
911
|
h: false,
|
912
912
|
c: false
|
913
913
|
)
|
914
914
|
|
915
|
-
x
|
915
|
+
x[:type] == :register8 ? 4 : 8
|
916
916
|
end
|
917
917
|
|
918
918
|
def xor8(x)
|
919
919
|
a_value = @registers.read8(:a) ^ get_value(x)
|
920
920
|
@registers.write8(:a, a_value)
|
921
921
|
update_flags(
|
922
|
-
z: a_value
|
922
|
+
z: a_value == 0,
|
923
923
|
n: false,
|
924
924
|
h: false,
|
925
925
|
c: false
|
926
926
|
)
|
927
927
|
|
928
|
-
x
|
928
|
+
x[:type] == :register8 ? 4 : 8
|
929
929
|
end
|
930
930
|
|
931
931
|
def push16(register16)
|
@@ -953,10 +953,10 @@ module Rubyboy
|
|
953
953
|
value = get_value(y)
|
954
954
|
set_value(x, value)
|
955
955
|
|
956
|
-
return 4 if x
|
957
|
-
return 12 if x
|
958
|
-
return 12 if x
|
959
|
-
return 16 if x
|
956
|
+
return 4 if x[:type] == :register8 && y[:type] == :register8
|
957
|
+
return 12 if x[:type] == :indirect && y[:type] == :immediate8
|
958
|
+
return 12 if x[:type] == :ff00 || y[:type] == :ff00
|
959
|
+
return 16 if x[:type] == :direct8 || y[:type] == :direct8
|
960
960
|
|
961
961
|
8
|
962
962
|
end
|
@@ -965,8 +965,8 @@ module Rubyboy
|
|
965
965
|
value = get_value(y)
|
966
966
|
set_value(x, value)
|
967
967
|
|
968
|
-
return 8 if y
|
969
|
-
return 20 if y
|
968
|
+
return 8 if y[:type] == :register16
|
969
|
+
return 20 if y[:type] == :sp
|
970
970
|
|
971
971
|
12
|
972
972
|
end
|
@@ -1013,7 +1013,7 @@ module Rubyboy
|
|
1013
1013
|
c: cflag
|
1014
1014
|
)
|
1015
1015
|
|
1016
|
-
x
|
1016
|
+
x[:type] == :register8 ? 4 : 8
|
1017
1017
|
end
|
1018
1018
|
|
1019
1019
|
def rst(addr)
|
@@ -1035,7 +1035,7 @@ module Rubyboy
|
|
1035
1035
|
addr = get_value(x)
|
1036
1036
|
@pc = addr if condition
|
1037
1037
|
|
1038
|
-
return 4 if x
|
1038
|
+
return 4 if x[:type] == :register16
|
1039
1039
|
|
1040
1040
|
condition ? 16 : 12
|
1041
1041
|
end
|
@@ -1074,13 +1074,13 @@ module Rubyboy
|
|
1074
1074
|
value = (value << 1) | (value >> 7)
|
1075
1075
|
set_value(x, value)
|
1076
1076
|
update_flags(
|
1077
|
-
z: value
|
1077
|
+
z: value == 0,
|
1078
1078
|
n: false,
|
1079
1079
|
h: false,
|
1080
1080
|
c: value[0] == 1
|
1081
1081
|
)
|
1082
1082
|
|
1083
|
-
x
|
1083
|
+
x[:type] == :register8 ? 8 : 16
|
1084
1084
|
end
|
1085
1085
|
|
1086
1086
|
def rrc8(x)
|
@@ -1088,13 +1088,13 @@ module Rubyboy
|
|
1088
1088
|
value = (value >> 1) | (value << 7)
|
1089
1089
|
set_value(x, value)
|
1090
1090
|
update_flags(
|
1091
|
-
z: value
|
1091
|
+
z: value == 0,
|
1092
1092
|
n: false,
|
1093
1093
|
h: false,
|
1094
1094
|
c: value[7] == 1
|
1095
1095
|
)
|
1096
1096
|
|
1097
|
-
x
|
1097
|
+
x[:type] == :register8 ? 8 : 16
|
1098
1098
|
end
|
1099
1099
|
|
1100
1100
|
def rl8(x)
|
@@ -1103,13 +1103,13 @@ module Rubyboy
|
|
1103
1103
|
value = ((value << 1) | bool_to_integer(flags[:c])) & 0xff
|
1104
1104
|
set_value(x, value)
|
1105
1105
|
update_flags(
|
1106
|
-
z: value
|
1106
|
+
z: value == 0,
|
1107
1107
|
n: false,
|
1108
1108
|
h: false,
|
1109
1109
|
c: cflag
|
1110
1110
|
)
|
1111
1111
|
|
1112
|
-
x
|
1112
|
+
x[:type] == :register8 ? 8 : 16
|
1113
1113
|
end
|
1114
1114
|
|
1115
1115
|
def rr8(x)
|
@@ -1118,13 +1118,13 @@ module Rubyboy
|
|
1118
1118
|
value = (value >> 1) | (bool_to_integer(flags[:c]) << 7)
|
1119
1119
|
set_value(x, value)
|
1120
1120
|
update_flags(
|
1121
|
-
z: value
|
1121
|
+
z: value == 0,
|
1122
1122
|
n: false,
|
1123
1123
|
h: false,
|
1124
1124
|
c: cflag
|
1125
1125
|
)
|
1126
1126
|
|
1127
|
-
x
|
1127
|
+
x[:type] == :register8 ? 8 : 16
|
1128
1128
|
end
|
1129
1129
|
|
1130
1130
|
def sla8(x)
|
@@ -1134,13 +1134,13 @@ module Rubyboy
|
|
1134
1134
|
value &= 0xff
|
1135
1135
|
set_value(x, value)
|
1136
1136
|
update_flags(
|
1137
|
-
z: value
|
1137
|
+
z: value == 0,
|
1138
1138
|
n: false,
|
1139
1139
|
h: false,
|
1140
1140
|
c: cflag
|
1141
1141
|
)
|
1142
1142
|
|
1143
|
-
x
|
1143
|
+
x[:type] == :register8 ? 8 : 16
|
1144
1144
|
end
|
1145
1145
|
|
1146
1146
|
def sra8(x)
|
@@ -1149,13 +1149,13 @@ module Rubyboy
|
|
1149
1149
|
value = (value >> 1) | (value[7] << 7)
|
1150
1150
|
set_value(x, value)
|
1151
1151
|
update_flags(
|
1152
|
-
z: value
|
1152
|
+
z: value == 0,
|
1153
1153
|
n: false,
|
1154
1154
|
h: false,
|
1155
1155
|
c: cflag
|
1156
1156
|
)
|
1157
1157
|
|
1158
|
-
x
|
1158
|
+
x[:type] == :register8 ? 8 : 16
|
1159
1159
|
end
|
1160
1160
|
|
1161
1161
|
def swap8(x)
|
@@ -1163,13 +1163,13 @@ module Rubyboy
|
|
1163
1163
|
value = ((value & 0x0f) << 4) | ((value & 0xf0) >> 4)
|
1164
1164
|
set_value(x, value)
|
1165
1165
|
update_flags(
|
1166
|
-
z: value
|
1166
|
+
z: value == 0,
|
1167
1167
|
n: false,
|
1168
1168
|
h: false,
|
1169
1169
|
c: false
|
1170
1170
|
)
|
1171
1171
|
|
1172
|
-
x
|
1172
|
+
x[:type] == :register8 ? 8 : 16
|
1173
1173
|
end
|
1174
1174
|
|
1175
1175
|
def srl8(x)
|
@@ -1178,24 +1178,24 @@ module Rubyboy
|
|
1178
1178
|
value >>= 1
|
1179
1179
|
set_value(x, value)
|
1180
1180
|
update_flags(
|
1181
|
-
z: value
|
1181
|
+
z: value == 0,
|
1182
1182
|
n: false,
|
1183
1183
|
h: false,
|
1184
1184
|
c: cflag
|
1185
1185
|
)
|
1186
1186
|
|
1187
|
-
x
|
1187
|
+
x[:type] == :register8 ? 8 : 16
|
1188
1188
|
end
|
1189
1189
|
|
1190
1190
|
def bit8(n, x)
|
1191
1191
|
value = get_value(x)
|
1192
1192
|
update_flags(
|
1193
|
-
z: value[n]
|
1193
|
+
z: value[n] == 0,
|
1194
1194
|
n: false,
|
1195
1195
|
h: true
|
1196
1196
|
)
|
1197
1197
|
|
1198
|
-
x
|
1198
|
+
x[:type] == :register8 ? 8 : 12
|
1199
1199
|
end
|
1200
1200
|
|
1201
1201
|
def res8(n, x)
|
@@ -1203,7 +1203,7 @@ module Rubyboy
|
|
1203
1203
|
value &= ((~(1 << n)) & 0xff)
|
1204
1204
|
set_value(x, value)
|
1205
1205
|
|
1206
|
-
x
|
1206
|
+
x[:type] == :register8 ? 8 : 16
|
1207
1207
|
end
|
1208
1208
|
|
1209
1209
|
def set8(n, x)
|
@@ -1211,19 +1211,19 @@ module Rubyboy
|
|
1211
1211
|
value |= (1 << n)
|
1212
1212
|
set_value(x, value)
|
1213
1213
|
|
1214
|
-
x
|
1214
|
+
x[:type] == :register8 ? 8 : 16
|
1215
1215
|
end
|
1216
1216
|
|
1217
1217
|
def get_value(operand)
|
1218
|
-
case operand
|
1219
|
-
when :register8 then @registers.read8(operand
|
1220
|
-
when :register16 then @registers.read16(operand
|
1218
|
+
case operand[:type]
|
1219
|
+
when :register8 then @registers.read8(operand[:value])
|
1220
|
+
when :register16 then @registers.read16(operand[:value])
|
1221
1221
|
when :sp then @sp
|
1222
1222
|
when :immediate8 then read_byte_and_advance_pc
|
1223
1223
|
when :immediate16 then read_word_and_advance_pc
|
1224
1224
|
when :direct8 then read_byte(read_word_and_advance_pc)
|
1225
1225
|
when :direct16 then read_word(read_word_and_advance_pc)
|
1226
|
-
when :indirect then read_byte(@registers.read16(operand
|
1226
|
+
when :indirect then read_byte(@registers.read16(operand[:value]))
|
1227
1227
|
when :ff00 then read_byte(0xff00 + read_byte_and_advance_pc)
|
1228
1228
|
when :ff00_c then read_byte(0xff00 + @registers.read8(:c))
|
1229
1229
|
when :hl_inc
|
@@ -1239,13 +1239,13 @@ module Rubyboy
|
|
1239
1239
|
end
|
1240
1240
|
|
1241
1241
|
def set_value(operand, value)
|
1242
|
-
case operand
|
1243
|
-
when :register8 then @registers.write8(operand
|
1244
|
-
when :register16 then @registers.write16(operand
|
1242
|
+
case operand[:type]
|
1243
|
+
when :register8 then @registers.write8(operand[:value], value)
|
1244
|
+
when :register16 then @registers.write16(operand[:value], value)
|
1245
1245
|
when :sp then @sp = value & 0xffff
|
1246
1246
|
when :direct8 then write_byte(read_word_and_advance_pc, value)
|
1247
1247
|
when :direct16 then write_word(read_word_and_advance_pc, value)
|
1248
|
-
when :indirect then write_byte(@registers.read16(operand
|
1248
|
+
when :indirect then write_byte(@registers.read16(operand[:value]), value)
|
1249
1249
|
when :ff00 then write_byte(0xff00 + read_byte_and_advance_pc, value)
|
1250
1250
|
when :ff00_c then write_byte(0xff00 + @registers.read8(:c), value)
|
1251
1251
|
when :hl_inc
|