1
1
// Imports
2
- import { Cpu } from " ./index" ;
2
+ import { Cpu } from ' ./index' ;
3
3
import {
4
4
rotateRegisterLeft ,
5
5
rotateRegisterRight ,
@@ -11,14 +11,14 @@ import {
11
11
shiftRightLogicalRegister ,
12
12
testBitOnRegister ,
13
13
setBitOnRegister
14
- } from " ./instructions" ;
15
- import { concatenateBytes , performanceTimestamp } from " ../helpers/index" ;
14
+ } from ' ./instructions' ;
15
+ import { concatenateBytes , performanceTimestamp } from ' ../helpers/index' ;
16
16
import {
17
17
eightBitStoreIntoGBMemoryWithTraps ,
18
18
sixteenBitStoreIntoGBMemoryWithTraps ,
19
19
eightBitLoadFromGBMemoryWithTraps ,
20
20
sixteenBitLoadFromGBMemory
21
- } from " ../memory/index" ;
21
+ } from ' ../memory/index' ;
22
22
23
23
// Handle CB Opcodes
24
24
// NOTE: Program stpes and cycles are standardized depending on the register type
@@ -57,9 +57,7 @@ export function handleCbOpcode(cbOpcode: i32): i32 {
57
57
break ;
58
58
case 6 :
59
59
// Value at register HL
60
- instructionRegisterValue = < u8 > eightBitLoadFromGBMemoryWithTraps (
61
- concatenateBytes ( Cpu . registerH , Cpu . registerL )
62
- ) ;
60
+ instructionRegisterValue = < u8 > eightBitLoadFromGBMemoryWithTraps ( concatenateBytes ( Cpu . registerH , Cpu . registerL ) ) ;
63
61
break ;
64
62
case 7 :
65
63
instructionRegisterValue = Cpu . registerA ;
@@ -76,33 +74,25 @@ export function handleCbOpcode(cbOpcode: i32): i32 {
76
74
if ( cbOpcode <= 0x07 ) {
77
75
// RLC register 8-bit
78
76
// Z 0 0 C
79
- instructionRegisterResult = rotateRegisterLeft (
80
- instructionRegisterValue
81
- ) ;
77
+ instructionRegisterResult = rotateRegisterLeft ( instructionRegisterValue ) ;
82
78
handledOpcode = true ;
83
79
} else if ( cbOpcode <= 0x0f ) {
84
80
// RRC register 8-bit
85
81
// Z 0 0 C
86
- instructionRegisterResult = rotateRegisterRight (
87
- instructionRegisterValue
88
- ) ;
82
+ instructionRegisterResult = rotateRegisterRight ( instructionRegisterValue ) ;
89
83
handledOpcode = true ;
90
84
}
91
85
break ;
92
86
case 0x01 :
93
87
if ( cbOpcode <= 0x17 ) {
94
88
// RL register 8-bit
95
89
// Z 0 0 C
96
- instructionRegisterResult = rotateRegisterLeftThroughCarry (
97
- instructionRegisterValue
98
- ) ;
90
+ instructionRegisterResult = rotateRegisterLeftThroughCarry ( instructionRegisterValue ) ;
99
91
handledOpcode = true ;
100
92
} else if ( cbOpcode <= 0x1f ) {
101
93
// RR register 8-bit
102
94
// Z 0 0 C
103
- instructionRegisterResult = rotateRegisterRightThroughCarry (
104
- instructionRegisterValue
105
- ) ;
95
+ instructionRegisterResult = rotateRegisterRightThroughCarry ( instructionRegisterValue ) ;
106
96
handledOpcode = true ;
107
97
}
108
98
break ;
@@ -115,26 +105,20 @@ export function handleCbOpcode(cbOpcode: i32): i32 {
115
105
} else if ( cbOpcode <= 0x2f ) {
116
106
// SRA register 8-bit
117
107
// Z 0 0 0
118
- instructionRegisterResult = shiftRightArithmeticRegister (
119
- instructionRegisterValue
120
- ) ;
108
+ instructionRegisterResult = shiftRightArithmeticRegister ( instructionRegisterValue ) ;
121
109
handledOpcode = true ;
122
110
}
123
111
break ;
124
112
case 0x03 :
125
113
if ( cbOpcode <= 0x37 ) {
126
114
// SWAP register 8-bit
127
115
// Z 0 0 0
128
- instructionRegisterResult = swapNibblesOnRegister (
129
- instructionRegisterValue
130
- ) ;
116
+ instructionRegisterResult = swapNibblesOnRegister ( instructionRegisterValue ) ;
131
117
handledOpcode = true ;
132
118
} else if ( cbOpcode <= 0x3f ) {
133
119
// SRL B
134
120
// Z 0 0 C
135
- instructionRegisterResult = shiftRightLogicalRegister (
136
- instructionRegisterValue
137
- ) ;
121
+ instructionRegisterResult = shiftRightLogicalRegister ( instructionRegisterValue ) ;
138
122
handledOpcode = true ;
139
123
}
140
124
break ;
@@ -143,243 +127,155 @@ export function handleCbOpcode(cbOpcode: i32): i32 {
143
127
// BIT 0,register 8-bit
144
128
// Z 0 1 -
145
129
//TODO: Optimize this not to do logic of setting register back
146
- instructionRegisterResult = testBitOnRegister (
147
- 0 ,
148
- instructionRegisterValue
149
- ) ;
130
+ instructionRegisterResult = testBitOnRegister ( 0 , instructionRegisterValue ) ;
150
131
handledOpcode = true ;
151
132
} else if ( cbOpcode <= 0x4f ) {
152
133
// BIT 1,register 8-bit
153
134
// Z 0 1 -
154
- instructionRegisterResult = testBitOnRegister (
155
- 1 ,
156
- instructionRegisterValue
157
- ) ;
135
+ instructionRegisterResult = testBitOnRegister ( 1 , instructionRegisterValue ) ;
158
136
handledOpcode = true ;
159
137
}
160
138
break ;
161
139
case 0x05 :
162
140
if ( cbOpcode <= 0x57 ) {
163
141
// BIT 2,register 8-bit
164
142
// Z 0 1 -
165
- instructionRegisterResult = testBitOnRegister (
166
- 2 ,
167
- instructionRegisterValue
168
- ) ;
143
+ instructionRegisterResult = testBitOnRegister ( 2 , instructionRegisterValue ) ;
169
144
handledOpcode = true ;
170
145
} else if ( cbOpcode <= 0x5f ) {
171
146
// BIT 3,register 8-bit
172
147
// Z 0 1 -
173
- instructionRegisterResult = testBitOnRegister (
174
- 3 ,
175
- instructionRegisterValue
176
- ) ;
148
+ instructionRegisterResult = testBitOnRegister ( 3 , instructionRegisterValue ) ;
177
149
handledOpcode = true ;
178
150
}
179
151
break ;
180
152
case 0x06 :
181
153
if ( cbOpcode <= 0x67 ) {
182
154
// BIT 4,register 8-bit
183
155
// Z 0 1 -
184
- instructionRegisterResult = testBitOnRegister (
185
- 4 ,
186
- instructionRegisterValue
187
- ) ;
156
+ instructionRegisterResult = testBitOnRegister ( 4 , instructionRegisterValue ) ;
188
157
handledOpcode = true ;
189
158
} else if ( cbOpcode <= 0x6f ) {
190
159
// BIT 5,register 8-bit
191
160
// Z 0 1 -
192
- instructionRegisterResult = testBitOnRegister (
193
- 5 ,
194
- instructionRegisterValue
195
- ) ;
161
+ instructionRegisterResult = testBitOnRegister ( 5 , instructionRegisterValue ) ;
196
162
handledOpcode = true ;
197
163
}
198
164
break ;
199
165
case 0x07 :
200
166
if ( cbOpcode <= 0x77 ) {
201
167
// BIT 6,register 8-bit
202
168
// Z 0 1 -
203
- instructionRegisterResult = testBitOnRegister (
204
- 6 ,
205
- instructionRegisterValue
206
- ) ;
169
+ instructionRegisterResult = testBitOnRegister ( 6 , instructionRegisterValue ) ;
207
170
handledOpcode = true ;
208
171
} else if ( cbOpcode <= 0x7f ) {
209
172
// BIT 7,register 8-bit
210
173
// Z 0 1 -
211
- instructionRegisterResult = testBitOnRegister (
212
- 7 ,
213
- instructionRegisterValue
214
- ) ;
174
+ instructionRegisterResult = testBitOnRegister ( 7 , instructionRegisterValue ) ;
215
175
handledOpcode = true ;
216
176
}
217
177
break ;
218
178
case 0x08 :
219
179
if ( cbOpcode <= 0x87 ) {
220
180
// Res 0,register 8-bit
221
181
// - - - -
222
- instructionRegisterResult = setBitOnRegister (
223
- 0 ,
224
- 0 ,
225
- instructionRegisterValue
226
- ) ;
182
+ instructionRegisterResult = setBitOnRegister ( 0 , 0 , instructionRegisterValue ) ;
227
183
handledOpcode = true ;
228
184
} else if ( cbOpcode <= 0x8f ) {
229
185
// Res 1,register 8-bit
230
186
// - - - -
231
- instructionRegisterResult = setBitOnRegister (
232
- 1 ,
233
- 0 ,
234
- instructionRegisterValue
235
- ) ;
187
+ instructionRegisterResult = setBitOnRegister ( 1 , 0 , instructionRegisterValue ) ;
236
188
handledOpcode = true ;
237
189
}
238
190
break ;
239
191
case 0x09 :
240
192
if ( cbOpcode <= 0x97 ) {
241
193
// Res 2,register 8-bit
242
194
// - - - -
243
- instructionRegisterResult = setBitOnRegister (
244
- 2 ,
245
- 0 ,
246
- instructionRegisterValue
247
- ) ;
195
+ instructionRegisterResult = setBitOnRegister ( 2 , 0 , instructionRegisterValue ) ;
248
196
handledOpcode = true ;
249
197
} else if ( cbOpcode <= 0x9f ) {
250
198
// Res 3,register 8-bit
251
199
// - - - -
252
- instructionRegisterResult = setBitOnRegister (
253
- 3 ,
254
- 0 ,
255
- instructionRegisterValue
256
- ) ;
200
+ instructionRegisterResult = setBitOnRegister ( 3 , 0 , instructionRegisterValue ) ;
257
201
handledOpcode = true ;
258
202
}
259
203
break ;
260
204
case 0x0a :
261
205
if ( cbOpcode <= 0xa7 ) {
262
206
// Res 4,register 8-bit
263
207
// - - - -
264
- instructionRegisterResult = setBitOnRegister (
265
- 4 ,
266
- 0 ,
267
- instructionRegisterValue
268
- ) ;
208
+ instructionRegisterResult = setBitOnRegister ( 4 , 0 , instructionRegisterValue ) ;
269
209
handledOpcode = true ;
270
210
} else if ( cbOpcode <= 0xaf ) {
271
211
// Res 5,register 8-bit
272
212
// - - - -
273
- instructionRegisterResult = setBitOnRegister (
274
- 5 ,
275
- 0 ,
276
- instructionRegisterValue
277
- ) ;
213
+ instructionRegisterResult = setBitOnRegister ( 5 , 0 , instructionRegisterValue ) ;
278
214
handledOpcode = true ;
279
215
}
280
216
break ;
281
217
case 0x0b :
282
218
if ( cbOpcode <= 0xb7 ) {
283
219
// Res 6,register 8-bit
284
220
// - - - -
285
- instructionRegisterResult = setBitOnRegister (
286
- 6 ,
287
- 0 ,
288
- instructionRegisterValue
289
- ) ;
221
+ instructionRegisterResult = setBitOnRegister ( 6 , 0 , instructionRegisterValue ) ;
290
222
handledOpcode = true ;
291
223
} else if ( cbOpcode <= 0xbf ) {
292
224
// Res 7,register 8-bit
293
225
// - - - -
294
- instructionRegisterResult = setBitOnRegister (
295
- 7 ,
296
- 0 ,
297
- instructionRegisterValue
298
- ) ;
226
+ instructionRegisterResult = setBitOnRegister ( 7 , 0 , instructionRegisterValue ) ;
299
227
handledOpcode = true ;
300
228
}
301
229
break ;
302
230
case 0x0c :
303
231
if ( cbOpcode <= 0xc7 ) {
304
232
// SET 0,register 8-bit
305
233
// - - - -
306
- instructionRegisterResult = setBitOnRegister (
307
- 0 ,
308
- 1 ,
309
- instructionRegisterValue
310
- ) ;
234
+ instructionRegisterResult = setBitOnRegister ( 0 , 1 , instructionRegisterValue ) ;
311
235
handledOpcode = true ;
312
236
} else if ( cbOpcode <= 0xcf ) {
313
237
// SET 1,register 8-bit
314
238
// - - - -
315
- instructionRegisterResult = setBitOnRegister (
316
- 1 ,
317
- 1 ,
318
- instructionRegisterValue
319
- ) ;
239
+ instructionRegisterResult = setBitOnRegister ( 1 , 1 , instructionRegisterValue ) ;
320
240
handledOpcode = true ;
321
241
}
322
242
break ;
323
243
case 0x0d :
324
244
if ( cbOpcode <= 0xd7 ) {
325
245
// SET 2,register 8-bit
326
246
// - - - -
327
- instructionRegisterResult = setBitOnRegister (
328
- 2 ,
329
- 1 ,
330
- instructionRegisterValue
331
- ) ;
247
+ instructionRegisterResult = setBitOnRegister ( 2 , 1 , instructionRegisterValue ) ;
332
248
handledOpcode = true ;
333
249
} else if ( cbOpcode <= 0xdf ) {
334
250
// SET 3,register 8-bit
335
251
// - - - -
336
- instructionRegisterResult = setBitOnRegister (
337
- 3 ,
338
- 1 ,
339
- instructionRegisterValue
340
- ) ;
252
+ instructionRegisterResult = setBitOnRegister ( 3 , 1 , instructionRegisterValue ) ;
341
253
handledOpcode = true ;
342
254
}
343
255
break ;
344
256
case 0x0e :
345
257
if ( cbOpcode <= 0xe7 ) {
346
258
// SET 4,register 8-bit
347
259
// - - - -
348
- instructionRegisterResult = setBitOnRegister (
349
- 4 ,
350
- 1 ,
351
- instructionRegisterValue
352
- ) ;
260
+ instructionRegisterResult = setBitOnRegister ( 4 , 1 , instructionRegisterValue ) ;
353
261
handledOpcode = true ;
354
262
} else if ( cbOpcode <= 0xef ) {
355
263
// SET 5,register 8-bit
356
264
// - - - -
357
- instructionRegisterResult = setBitOnRegister (
358
- 5 ,
359
- 1 ,
360
- instructionRegisterValue
361
- ) ;
265
+ instructionRegisterResult = setBitOnRegister ( 5 , 1 , instructionRegisterValue ) ;
362
266
handledOpcode = true ;
363
267
}
364
268
break ;
365
269
case 0x0f :
366
270
if ( cbOpcode <= 0xf7 ) {
367
271
// SET 6,register 8-bit
368
272
// - - - -
369
- instructionRegisterResult = setBitOnRegister (
370
- 6 ,
371
- 1 ,
372
- instructionRegisterValue
373
- ) ;
273
+ instructionRegisterResult = setBitOnRegister ( 6 , 1 , instructionRegisterValue ) ;
374
274
handledOpcode = true ;
375
275
} else if ( cbOpcode <= 0xff ) {
376
276
// SET 7,register 8-bit
377
277
// - - - -
378
- instructionRegisterResult = setBitOnRegister (
379
- 7 ,
380
- 1 ,
381
- instructionRegisterValue
382
- ) ;
278
+ instructionRegisterResult = setBitOnRegister ( 7 , 1 , instructionRegisterValue ) ;
383
279
handledOpcode = true ;
384
280
}
385
281
break ;
@@ -407,10 +303,7 @@ export function handleCbOpcode(cbOpcode: i32): i32 {
407
303
break ;
408
304
case 6 :
409
305
// Value at register HL
410
- eightBitStoreIntoGBMemoryWithTraps (
411
- concatenateBytes ( Cpu . registerH , Cpu . registerL ) ,
412
- instructionRegisterResult
413
- ) ;
306
+ eightBitStoreIntoGBMemoryWithTraps ( concatenateBytes ( Cpu . registerH , Cpu . registerL ) , instructionRegisterResult ) ;
414
307
break ;
415
308
case 7 :
416
309
Cpu . registerA = instructionRegisterResult ;
0 commit comments