-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm_test.go
757 lines (633 loc) · 14.1 KB
/
vm_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
package main
import "testing"
var runParams RunParams = RunParams{
instCount: 1,
frameDuration: 1,
}
type TestIO struct {
drawCalled bool
clearScreenCalled bool
}
func (testIO *TestIO) Draw(pixels Pixels) {
testIO.drawCalled = true
}
func (testIO *TestIO) ClearScreen() {
testIO.clearScreenCalled = true
}
func (testIO *TestIO) WaitKeyPress() (byte, bool) {
return 12, true
}
func (testIO *TestIO) GetKeysPressed() [16]bool {
return [16]bool{true, true}
}
var testIO = &TestIO{}
func Test0nnn(t *testing.T) {
}
func Test00E0(t *testing.T) {
ram := []byte{0x00, 0xE0}
vm, _ := NewVm(ram, testIO)
vm.Run(runParams)
if !testIO.clearScreenCalled {
t.Error("Clear screen instruction err; not called")
}
}
func Test00EE(t *testing.T) {
ram := []byte{0x00, 0xEE}
vm, _ := NewVm(ram, testIO)
vm.Stack[vm.Sp] = 0xABC
vm.Sp = 1
vm.Run(runParams)
if vm.Pc != 0xABE || vm.Sp != 0 {
t.Errorf("Return instruction err; Pc: %x, Sp: %x", vm.Pc, vm.Sp)
}
}
func Test1nnn(t *testing.T) {
ram := []byte{0x1A, 0xBC}
vm, _ := NewVm(ram, testIO)
vm.Run(runParams)
if vm.Pc != 0xABC {
t.Errorf("Jump instruction err; Pc: %x", vm.Pc)
}
}
func Test2nnn(t *testing.T) {
ram := make([]byte, 6)
ram[0] = 0x20
ram[1] = 0x04
ram[4] = 0xFF
vm, _ := NewVm(ram, testIO)
vm.Run(runParams)
if vm.Pc != 4 {
t.Errorf("Call instruction err; Pc: %x", vm.Pc)
}
if vm.Stack[vm.Sp-1] != 0x200 || vm.Stack[vm.Sp] != 0 {
t.Errorf("Call instruction err; Stack[Sp]: %x", vm.Stack[vm.Sp])
}
}
func Test3xkk(t *testing.T) {
ram := make([]byte, 6)
ram[0] = 0x31
ram[1] = 0xFF
ram[4] = 0x32
ram[5] = 0xAB
vm, _ := NewVm(ram, testIO)
vm.Regs[1] = 0xFF
vm.Regs[2] = 0xCD
vm.Run(runParams)
if vm.Pc != 0x200+4 {
t.Errorf("Skip instruction err; Pc: %x", vm.Pc)
}
vm.Run(runParams)
if vm.Pc != 0x200+6 {
t.Errorf("Skip instruction err; Pc: %x", vm.Pc)
}
}
func Test4xkk(t *testing.T) {
ram := make([]byte, 6)
ram[0] = 0x41
ram[1] = 0xAB
ram[4] = 0x42
ram[5] = 0xFF
vm, _ := NewVm(ram, testIO)
vm.Regs[1] = 0xCD
vm.Regs[2] = 0xFF
vm.Run(runParams)
if vm.Pc != 0x200+4 {
t.Errorf("Skip instruction err; Pc: %x", vm.Pc)
}
vm.Run(runParams)
if vm.Pc != 0x200+6 {
t.Errorf("Skip instruction err; Pc: %x", vm.Pc)
}
}
func Test5xy0(t *testing.T) {
ram := make([]byte, 8)
ram[0] = 0x51
ram[1] = 0x20
ram[4] = 0x5A
ram[5] = 0xB0
ram[6] = 0x5C
ram[7] = 0xC1
vm, _ := NewVm(ram, testIO)
vm.Regs[1] = 0xAA
vm.Regs[2] = 0xAA
vm.Regs[0xA] = 0x12
vm.Regs[0xB] = 0x34
vm.Run(runParams)
if vm.Pc != 0x200+4 {
t.Errorf("Skip instruction err; Pc: %x", vm.Pc)
}
vm.Run(runParams)
if vm.Pc != 0x200+6 {
t.Errorf("Skip instruction err; Pc: %x", vm.Pc)
}
err := vm.Run(runParams)
if err == nil {
t.Errorf("Skip instruction err; Pc: %x", vm.Pc)
}
}
func Test6xkk(t *testing.T) {
ram := []byte{0x6A, 0xFF}
vm, _ := NewVm(ram, testIO)
vm.Run(runParams)
if vm.Regs[0xA] != 0xFF {
t.Errorf("Load instruction err; Reg value: %x", vm.Regs[0xA])
}
}
func Test7xkk(t *testing.T) {
ram := []byte{0x7A, 2}
vm, _ := NewVm(ram, testIO)
vm.Regs[0xA] = 3
vm.Run(runParams)
if vm.Regs[0xA] != 5 {
t.Errorf("Add instruction err; Reg value: %x", vm.Regs[0xA])
}
}
func Test8xyz(t *testing.T) {
ram := []byte{
0x81,
0x20,
0x81,
0x21,
0x81,
0x22,
0x81,
0x23,
0x81,
0x2A}
vm, _ := NewVm(ram, testIO)
vm.Regs[0x2] = 128
vm.Run(runParams)
if vm.Regs[0x1] != 128 || vm.Regs[0xF] != 0 {
t.Errorf("0x8xy0 instruction err; Reg value: %x", vm.Regs[0x1])
}
vm.Regs[0x1] = 0b0101
vm.Regs[0x2] = 0b0010
vm.Run(runParams)
if vm.Regs[0x1] != 0b111 || vm.Regs[0xF] != 0 {
t.Errorf("0x8xy1 instruction err; Reg value: %x", vm.Regs[0x1])
}
vm.Regs[0x1] = 0b1101
vm.Regs[0x2] = 0b1010
vm.Run(runParams)
if vm.Regs[0x1] != 0b1000 || vm.Regs[0xF] != 0 {
t.Errorf("0x8xy2 instruction err; Reg value: %x", vm.Regs[0x1])
}
vm.Regs[0x1] = 0b1101
vm.Regs[0x2] = 0b1010
vm.Run(runParams)
if vm.Regs[0x1] != 0b0111 || vm.Regs[0xF] != 0 {
t.Errorf("0x8xy3 instruction err; Reg value: %x", vm.Regs[0x1])
}
err := vm.Run(runParams)
if err == nil {
t.Error("0x8xyA should return an error")
}
}
func Test8xy4(t *testing.T) {
ram := []byte{
0x81,
0x24,
0x8E,
0xF4,
0x8F,
0xE4,
0x81,
0x24,
0x8E,
0xF4,
0x8F,
0xE4,
}
vm, _ := NewVm(ram, testIO)
vm.Regs[0x1] = 1
vm.Regs[0x2] = 7
vm.Run(runParams)
if vm.Regs[0x1] != 8 || vm.Regs[0xF] != 0 {
t.Errorf("0x8xy4 instruction err; Reg value: %x", vm.Regs[0x1])
}
vm.Regs[0xE] = 1
vm.Regs[0xF] = 7
vm.Run(runParams)
if vm.Regs[0xE] != 8 || vm.Regs[0xF] != 0 {
t.Errorf("0x8xy4 instruction err; Reg value: %x", vm.Regs[0xE])
}
vm.Regs[0xE] = 1
vm.Regs[0xF] = 7
vm.Run(runParams)
if vm.Regs[0xF] != 0 {
t.Errorf("0x8xy4 instruction err; Reg value: %x", vm.Regs[0xF])
}
vm.Regs[0x1] = 255
vm.Regs[0x2] = 255
vm.Run(runParams)
if vm.Regs[0x1] != 0b1111_1110 || vm.Regs[0xF] != 1 {
t.Errorf("0x8xy4 instruction err; Reg value: %x", vm.Regs[0x1])
}
vm.Regs[0xE] = 255
vm.Regs[0xF] = 255
vm.Run(runParams)
if vm.Regs[0xE] != 0b1111_1110 || vm.Regs[0xF] != 1 {
t.Errorf("0x8xy4 instruction err; Reg value: %x", vm.Regs[0xE])
}
vm.Regs[0xE] = 255
vm.Regs[0xF] = 255
vm.Run(runParams)
if vm.Regs[0xF] != 1 {
t.Errorf("0x8xy4 instruction err; Reg value: %x", vm.Regs[0xF])
}
}
func Test8xy5(t *testing.T) {
ram := []byte{
0x81,
0x25,
0x8E,
0xF5,
0x8F,
0xE5,
0x81,
0x25,
0x8E,
0xF5,
0x8F,
0xE5,
}
vm, _ := NewVm(ram, testIO)
vm.Regs[0x1] = 5
vm.Regs[0x2] = 7
vm.Run(runParams)
if vm.Regs[0x1] != 0b1111_1110 || vm.Regs[0xF] != 0 {
t.Errorf("0x8xy5 instruction err; Reg value: %x", vm.Regs[0x1])
}
vm.Regs[0xE] = 5
vm.Regs[0xF] = 7
vm.Run(runParams)
if vm.Regs[0xE] != 0b1111_1110 || vm.Regs[0xF] != 0 {
t.Errorf("0x8xy5 instruction err; Reg value: %x", vm.Regs[0xE])
}
vm.Regs[0xE] = 7
vm.Regs[0xF] = 5
vm.Run(runParams)
if vm.Regs[0xF] != 0 {
t.Errorf("0x8xy5 instruction err; Reg value: %x", vm.Regs[0xF])
}
vm.Regs[0x1] = 7
vm.Regs[0x2] = 5
vm.Run(runParams)
if vm.Regs[0x1] != 0b10 || vm.Regs[0xF] != 1 {
t.Errorf("0x8xy5 instruction err; Reg value: %x", vm.Regs[0x1])
}
vm.Regs[0xE] = 7
vm.Regs[0xF] = 5
vm.Run(runParams)
if vm.Regs[0xE] != 0b10 || vm.Regs[0xF] != 1 {
t.Errorf("0x8xy5 instruction err; Reg value: %x", vm.Regs[0xE])
}
vm.Regs[0xF] = 7
vm.Regs[0xE] = 5
vm.Run(runParams)
if vm.Regs[0xF] != 1 {
t.Errorf("0x8xy5 instruction err; Reg value: %x", vm.Regs[0xF])
}
}
func Test8xy6(t *testing.T) {
ram := []byte{
0x81,
0x26,
0x8F,
0x26,
0x81,
0x26,
0x8F,
0x26,
}
vm, _ := NewVm(ram, testIO)
vm.Regs[0x2] = 0b1110
vm.Run(runParams)
if vm.Regs[0x1] != 0b0111 || vm.Regs[0xF] != 0 {
t.Errorf("0x8xy6 instruction err; Reg value: %x", vm.Regs[0x1])
}
vm.Regs[0x2] = 0b1110
vm.Run(runParams)
if vm.Regs[0xF] != 0 {
t.Errorf("0x8xy6 instruction err; Reg value: %x", vm.Regs[0xF])
}
vm.Regs[0x2] = 0b1111
vm.Run(runParams)
if vm.Regs[0x1] != 0b0111 || vm.Regs[0xF] != 1 {
t.Errorf("0x8xy6 instruction err; Reg value: %x", vm.Regs[0x1])
}
vm.Regs[0x2] = 0b1111
vm.Run(runParams)
if vm.Regs[0xF] != 1 {
t.Errorf("0x8xy6 instruction err; Reg value: %x", vm.Regs[0xF])
}
}
func Test8xy7(t *testing.T) {
ram := []byte{
0x81,
0x27,
0x8E,
0xF7,
0x8F,
0xE7,
0x81,
0x27,
0x8E,
0xF7,
0x8F,
0xE7,
}
vm, _ := NewVm(ram, testIO)
vm.Regs[0x1] = 7
vm.Regs[0x2] = 5
vm.Run(runParams)
if vm.Regs[0x1] != 0b1111_1110 || vm.Regs[0xF] != 0 {
t.Errorf("0x8xy7 instruction err; Reg value: %x", vm.Regs[0x1])
}
vm.Regs[0xE] = 7
vm.Regs[0xF] = 5
vm.Run(runParams)
if vm.Regs[0xE] != 0b1111_1110 || vm.Regs[0xF] != 0 {
t.Errorf("0x8xy7 instruction err; Reg value: %x", vm.Regs[0xE])
}
vm.Regs[0xF] = 7
vm.Regs[0xE] = 5
vm.Run(runParams)
if vm.Regs[0xF] != 0 {
t.Errorf("0x8xy7 instruction err; Reg value: %x", vm.Regs[0xF])
}
vm.Regs[0x1] = 5
vm.Regs[0x2] = 7
vm.Run(runParams)
if vm.Regs[0x1] != 0b10 || vm.Regs[0xF] != 1 {
t.Errorf("0x8xy7 instruction err; Reg value: %x", vm.Regs[0x1])
}
vm.Regs[0xE] = 5
vm.Regs[0xF] = 7
vm.Run(runParams)
if vm.Regs[0xE] != 0b10 || vm.Regs[0xF] != 1 {
t.Errorf("0x8xy7 instruction err; Reg value: %x", vm.Regs[0xE])
}
vm.Regs[0xF] = 5
vm.Regs[0xE] = 7
vm.Run(runParams)
if vm.Regs[0xF] != 1 {
t.Errorf("0x8xy7 instruction err; Reg value: %x", vm.Regs[0xF])
}
}
func Test8xyE(t *testing.T) {
ram := []byte{
0x81,
0x2E,
0x8F,
0x2E,
0x81,
0x2E,
0x8F,
0x2E,
}
vm, _ := NewVm(ram, testIO)
vm.Regs[0x2] = 0b0111
vm.Run(runParams)
if vm.Regs[0x1] != 0b1110 || vm.Regs[0xF] != 0 {
t.Errorf("0x8xyE instruction err; Reg value: %x", vm.Regs[0x1])
}
vm.Regs[0x2] = 0b0111
vm.Run(runParams)
if vm.Regs[0xF] != 0 {
t.Errorf("0x8xyE instruction err; Reg value: %x", vm.Regs[0xF])
}
vm.Regs[0x2] = 0b1111_1111
vm.Run(runParams)
if vm.Regs[0x1] != 0b1111_1110 || vm.Regs[0xF] != 1 {
t.Errorf("0x8xyE instruction err; Reg value: %x", vm.Regs[0x1])
}
vm.Regs[0x2] = 0b1111_1111
vm.Run(runParams)
if vm.Regs[0xF] != 1 {
t.Errorf("0x8xyE instruction err; Reg value: %x", vm.Regs[0xF])
}
}
func Test9xy0(t *testing.T) {
ram := make([]byte, 8)
ram[0] = 0x91
ram[1] = 0x20
ram[4] = 0x9A
ram[5] = 0xB0
ram[6] = 0x9C
ram[7] = 0xC1
vm, _ := NewVm(ram, testIO)
vm.Regs[1] = 0x12
vm.Regs[2] = 0x34
vm.Regs[0xA] = 0xAA
vm.Regs[0xB] = 0xAA
vm.Run(runParams)
if vm.Pc != 0x200+4 {
t.Errorf("Skip instruction err; Pc: %x", vm.Pc)
}
vm.Run(runParams)
if vm.Pc != 0x200+6 {
t.Errorf("Skip instruction err; Pc: %x", vm.Pc)
}
err := vm.Run(runParams)
if err == nil {
t.Errorf("Skip instruction err; Pc: %x", vm.Pc)
}
}
func TestAnnn(t *testing.T) {
ram := []byte{0xAA, 0xBC}
vm, _ := NewVm(ram, testIO)
vm.Run(runParams)
if vm.I != 0xABC {
t.Errorf("Load I instruction err; I: %x", vm.I)
}
}
func TestBnnn(t *testing.T) {
ram := []byte{0xBA, 0xBC}
vm, _ := NewVm(ram, testIO)
vm.Regs[0] = 0xFF
vm.Run(runParams)
if vm.Pc != 0xBBB {
t.Errorf("Jump V0, addr instruction err; Pc: %x", vm.Pc)
}
}
func TestCnnn(t *testing.T) {
t.Skip()
}
func TestDxyn(t *testing.T) {
ram := make([]byte, 14)
ram[0] = 0xD1
ram[1] = 0x23
ram[2] = 0xD3
ram[3] = 0x43
ram[4] = 0xD3
ram[5] = 0x43
ram[10] = 0xAB
ram[11] = 0xCD
ram[12] = 0xEF
vm, _ := NewVm(ram, testIO)
vm.I = 0x200 + 10
vm.Regs[1] = 0
vm.Regs[2] = 31
vm.Run(runParams)
if !testIO.drawCalled {
t.Error("Draw function not called")
}
if vm.Regs[0xF] != 0 {
t.Error("Draw instruction err; VF != 0")
}
row1 := [64]byte{1, 0, 1, 0, 1, 0, 1, 1}
row2 := [64]byte{1, 1, 0, 0, 1, 1, 0, 1}
row3 := [64]byte{1, 1, 1, 0, 1, 1, 1, 1}
emptyRow := [64]byte{}
if vm.Pixels[31] != row1 {
t.Errorf("Draw instruction err; Expected: %v, Received: %v", row1, vm.Pixels[31])
}
// pixels should be clipped
if vm.Pixels[0] != [64]byte{} {
t.Errorf("Draw instruction err; Expected: %v, Received: %v", emptyRow, vm.Pixels[0])
}
if vm.Pixels[1] != [64]byte{} {
t.Errorf("Draw instruction err; Expected: %v, Received: %v", emptyRow, vm.Pixels[1])
}
vm.Regs[3] = 64
vm.Regs[4] = 32
vm.Run(runParams)
// pixels should wrap
if vm.Pixels[0] != row1 {
t.Errorf("Draw instruction err; Expected: %v, Received: %v", row1, vm.Pixels[0])
}
if vm.Pixels[1] != row2 {
t.Errorf("Draw instruction err; Expected: %v, Received: %v", row2, vm.Pixels[1])
}
if vm.Pixels[2] != row3 {
t.Errorf("Draw instruction err; Expected: %v, Received: %v", row3, vm.Pixels[2])
}
vm.Run(runParams)
// Calling the same instruction again should result in the
// erasure of the sprite
if vm.Regs[0xF] != 1 {
t.Error("Draw instruction err; VF != 1")
}
row1 = [64]byte{}
if vm.Pixels[0] != emptyRow || vm.Pixels[1] != emptyRow || vm.Pixels[2] != emptyRow {
t.Errorf("Draw instruction err; Expected: %v, Received: %v", emptyRow, vm.Pixels[31])
}
}
func TestEx9EAndExA1(t *testing.T) {
ram := make([]byte, 6)
ram[0] = 0xEA
ram[1] = 0x9E
ram[4] = 0xEB
ram[5] = 0xA1
vm, _ := NewVm(ram, testIO)
vm.Regs[0xA] = 0
vm.Regs[0xB] = 1
vm.Run(runParams)
if vm.Pc != 0x200+4 {
t.Errorf("Skip on key instruction err; Pc: %x", vm.Pc)
}
vm.Run(runParams)
if vm.Pc != 0x200+6 {
t.Errorf("Skip on key instruction err; Pc: %x", vm.Pc)
}
}
func TestFx0A(t *testing.T) {
ram := []byte{0xF1, 0x0A}
vm, _ := NewVm(ram, testIO)
vm.Run(runParams)
if vm.Regs[1] != 12 {
t.Errorf("Load on key instruction err; V1: %x", vm.Regs[1])
}
}
func TestFxInsts(t *testing.T) {
ram := []byte{
// 0xF1,
// 0x07,
// 0xF2,
// 0x15,
0xF3,
0x18,
0xF4,
0x1E,
0xF0,
0x29,
0xF1,
0x29,
0xF7,
0x33,
0xF6,
0x55,
0xF6,
0x65,
}
vm, _ := NewVm(ram, testIO)
// TO DO: Some other test for these instructions
// since the Run method decrements DT
// vm.DT = 0xAA
// vm.Run(runParams)
// if vm.Regs[1] != 0xAA {
// t.Errorf("Load Vx, DT err; V1: %x", vm.Regs[1])
// }
// vm.Regs[2] = 0xBB
// vm.Run(runParams)
// if vm.DT != 0xBB {
// t.Errorf("Load DT, Vx err; DT: %x", vm.DT)
// }
vm.Regs[3] = 0xCC
vm.Run(runParams)
if vm.ST != 0xCC {
t.Errorf("Load ST, Vx err; ST: %x", vm.ST)
}
vm.Regs[4] = 0xDD
vm.I = 0x1
vm.Run(runParams)
if vm.I != 0xDE {
t.Errorf("Add I, Vx err; I: %x", vm.I)
}
vm.Regs[0] = 0
vm.Run(runParams)
if vm.I != 0x00 {
t.Errorf("Load F, Vx err, I: %x", vm.I)
}
vm.Regs[1] = 0xF
vm.Run(runParams)
if vm.I != 75 {
t.Errorf("Load F, Vx err, I: %x", vm.I)
}
vm.Regs[7] = 123
vm.Run(runParams)
if vm.Mem[vm.I] != 1 || vm.Mem[vm.I+1] != 2 || vm.Mem[vm.I+2] != 3 {
t.Errorf("Load B, Vx err, B: %d C: %d D: %d", vm.Mem[vm.I], vm.Mem[vm.I+1], vm.Mem[vm.I+2])
}
I := vm.I
vm.Regs[0] = 0xA
vm.Regs[1] = 0xB
vm.Regs[2] = 0xC
vm.Regs[3] = 0xD
vm.Regs[4] = 0xE
vm.Regs[5] = 0xF
vm.Regs[6] = 0x1
vm.Run(runParams)
for i, v := range vm.Mem[I : I+7] {
if vm.Regs[i] != v {
t.Errorf("Load [I], Vx err, I: %x val: %x", vm.I+uint16(i), v)
}
}
if vm.I != I+7 {
t.Errorf("Load [I], Vx err, I: %x", vm.I)
}
I = vm.I
for i := 0; i <= 7; i++ {
vm.Mem[vm.I+uint16(i)] = byte(123 + i)
}
vm.Run(runParams)
for i := 0; i <= 6; i++ {
if vm.Regs[i] != byte(123+i) {
t.Errorf("Load Vx, [I] err; Vx: %d, vm.Mem[I]: %d", vm.Regs[i], vm.Mem[vm.I+uint16(i)])
}
}
if vm.I != I+7 {
t.Errorf("Load Vx, [I] err, I: %x", vm.I)
}
}