-
Notifications
You must be signed in to change notification settings - Fork 0
/
recompiler_memory.c
1620 lines (1507 loc) · 40.7 KB
/
recompiler_memory.c
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
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Project 64 - A Nintendo 64 emulator.
*
* (c) Copyright 2001 zilmar ([email protected]) and
* Jabo ([email protected]).
*
* pj64 homepage: www.pj64.net
*
* Permission to use, copy, modify and distribute Project64 in both binary and
* source form, for non-commercial purposes, is hereby granted without fee,
* providing that this license information and copyright notice appear with
* all copies and any derived work.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event shall the authors be held liable for any damages
* arising from the use of this software.
*
* Project64 is freeware for PERSONAL USE only. Commercial users should
* seek permission of the copyright holders first. Commercial use includes
* charging money for Project64 or software derived from Project64.
*
* The copyright holders request that bug fixes and improvements to the code
* should be forwarded to them so if they want them.
*
*/
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <sys/mman.h>
#include "main.h"
#include "cpu.h"
#include "memory.h"
#include "x86.h"
#include "audio.h"
#include "rsp.h"
#include "usf.h"
#include "dma.h"
#include "exception.h"
#include "tlb.h"
#include "pif.h"
#include "registers.h"
uint8_t * RecompPos = 0;
uint32_t TempValue = 0;
#ifndef __USE_GNU
#define __USE_GNU
#endif
#include <sys/ucontext.h>
static struct sigaction act;
static struct sigaction oact;
static sigset_t sset;
void sig_handler(int signo, siginfo_t * info, ucontext_t * context);
void InitExceptionHandler(void)
{
sigset_t blockset;
sigemptyset(&blockset);
sigaddset(&blockset, SIGSEGV);
sigprocmask(SIG_UNBLOCK, &blockset, NULL);
sigemptyset(&sset);
sigaddset(&sset, SIGSEGV);
act.sa_flags = SA_SIGINFO ;
act.sa_mask = sset;
act.sa_sigaction = (void (*)(int, siginfo_t*, void*)) sig_handler;
if(sigaction(SIGSEGV, (const struct sigaction *) &act, &oact))
{
printf("error setting up exception handler\n");
}
}
int r4300i_CPU_MemoryFilter64_2( uintptr_t MemAddress, ucontext_t * context);
void sig_handler(int signo, siginfo_t * info, ucontext_t * context)
{
int i = 0;
if(signo==SIGSEGV)
{
uintptr_t MemAddress = ((char *)info->si_addr - (char *)N64MEM);
/*
A Hack to fix some crappy GCC thing when R15 gets overwritten.
R15 should _never_ be overwritten. >:(
*/
#ifdef USEX64
if(context->uc_mcontext.gregs[REG_R15] != (uintptr_t)TLB_Map)
{
context->uc_mcontext.gregs[REG_R15] = (uintptr_t)TLB_Map;
return;
}
#endif
i = r4300i_CPU_MemoryFilter64_2(MemAddress,context);
if(i==0)
{
return;
}
}
return;
}
static int32_t CONV_REG64(int32_t dest_reg)
{
switch(dest_reg)
{
case 0:
return 13;
break;
case 1:
return 14;
break;
case 2:
return 12;
break;
case 3:
return 11;
break;
case 6:
return 9;
break;
case 7:
return 8;
break;
case 8:
return 0;
break;
case 9:
return 1;
break;
case 10:
return 2;
break;
case 11:
return 3;
break;
case 12:
return 4;
break;
case 13:
return 5;
break;
case 14:
return 6;
break;
case 15:
return 7;
break;
default:
asm("int $3");
return 255;
break;
}
}
#ifdef __LP64__
int r4300i_CPU_MemoryFilter64_2( uintptr_t MemAddress, ucontext_t * context)
{
uint8_t * ip = (uint8_t *)context->uc_mcontext.gregs[REG_RIP];
if(MemAddress == 0)
{
return 1;
}
if((*ip & 0x40) && (*(ip+1) == 0xf) && (*(ip+2) == 0xb7))
{
uint8_t dest_reg = (*(ip+3) % 0x40) / 8;
uint32_t half = 0;
if(*ip & 4)
{
dest_reg += 8;
}
r4300i_LH_NonMemory(MemAddress, &half, 1);
context->uc_mcontext.gregs[CONV_REG64(dest_reg)] = (int32_t)half;
context->uc_mcontext.gregs[REG_RIP]+=4;
if((*(ip+3) & 0x7)==4)
{
context->uc_mcontext.gregs[REG_RIP]++;
}
if((*(ip+3) & 0xC0) == 0x80)
{
context->uc_mcontext.gregs[REG_RIP]+=4;
}
else if((*(ip+3) & 0xC0) == 0x40)
{
context->uc_mcontext.gregs[REG_RIP]+=1;
}
return 0;
}
else if((*ip & 0x40) && (*(ip+1) ==0x89)) // MOV [Rxx + Rxx], Exx
{
uint8_t dest_reg = (*(ip+2) % 0x40) / 8;
uint64_t dest = 0;
if(*ip & 4)
{
dest_reg += 8;
}
dest = context->uc_mcontext.gregs[CONV_REG64(dest_reg)];
r4300i_SW_NonMemory(MemAddress, dest);
if((*(ip+2) & 0x7)==4)
{
context->uc_mcontext.gregs[REG_RIP]+=4;
}
else
{
context->uc_mcontext.gregs[REG_RIP]+=3;
}
if((*(ip+2) & 0xC0) == 0x80)
{
context->uc_mcontext.gregs[REG_RIP]+=4;
}
else if((*(ip+2) & 0xC0) == 0x40)
{
context->uc_mcontext.gregs[REG_RIP]+=1;
}
return 0;
}
else if((*ip & 0x40) && (*(ip+1) ==0xC7)) // MOV [Rxx + Rxx], Imm32
{
uint32_t imm32 = *(uint32_t*)(ip+4);
r4300i_SW_NonMemory(MemAddress, imm32);
context->uc_mcontext.gregs[REG_RIP]+=7;
// 40 C7 04 07 0F 00 00 00
//if(*(ip+2)&0x4)
if((*(ip+2) & 0x7)==4)
{
context->uc_mcontext.gregs[REG_RIP]++;
}
if((*(ip+2) & 0xC0) == 0x80)
{
context->uc_mcontext.gregs[REG_RIP]+=4;
}
else if((*(ip+2) & 0xC0) == 0x40)
{
context->uc_mcontext.gregs[REG_RIP]+=1;
}
return 0;
}
else if ((*ip & 0x40) && (*(ip + 1) == 0x8B ))
{
uint8_t dest_reg = (*(ip+2) % 0x40) / 8;
uint32_t word = 0;
//uint64_t *dest = 0;
//41 8B BF 30 D0 00 01
if(*ip & 4)
{
dest_reg += 8;
}
r4300i_LW_NonMemory(MemAddress, &word);
context->uc_mcontext.gregs[CONV_REG64(dest_reg)] = word;
//*dest = 0;
//if(*(ip+2) & 0x4)
if((*(ip+2) & 0x7)==4)
{
context->uc_mcontext.gregs[REG_RIP]+=4;
}
else
{
context->uc_mcontext.gregs[REG_RIP]+=3;
}
if((*(ip+2) & 0xC0) == 0x80)
{
context->uc_mcontext.gregs[REG_RIP]+=4;
}
else if((*(ip+2) & 0xC0) == 0x40)
{
context->uc_mcontext.gregs[REG_RIP]+=1;
}
return 0;
}
//asm("int $3");
return 1;
}
#else
static int32_t CONV_REG(int32_t dest_reg)
{
switch(dest_reg)
{
case 0:
return 5;
break;
case 1:
return 4;
break;
case 2:
return 3;
break;
case 3:
return 2;
break;
case 6:
return 1;
break;
case 7:
return 0;
break;
default:
asm volatile("int $3");
return 255;
break;
}
}
int r4300i_CPU_MemoryFilter64_2( uintptr_t MemAddress, ucontext_t * context)
{
uint8_t * ip = (uint8_t *)context->uc_mcontext.gregs[REG_EIP];
if(MemAddress == 0)
{
return 1;
}
if((*(ip) == 0xf) && (*(ip+1) == 0xb7))
{
uint8_t dest_reg = (*(ip+2) % 0x40) / 8;
uint32_t half = 0;
r4300i_LH_NonMemory(MemAddress, &half, 1);
//((uint32_t*)(&lpEP->ContextRecord->Edi))[CONV_REG(dest_reg)] = (int32_t)half;
context->uc_mcontext.gregs[CONV_REG64(dest_reg)] = (int32_t)half;
context->uc_mcontext.gregs[REG_EIP]+=3;
if((*(ip+2) & 0x7)==4)
{
context->uc_mcontext.gregs[REG_EIP]++;
}
else if((*(ip+1) & 0x7)==5)
{
context->uc_mcontext.gregs[REG_EIP]+=4;
}
if((*(ip+2) & 0xC0) == 0x80)
{
context->uc_mcontext.gregs[REG_EIP]+=4;
}
else if((*(ip+2) & 0xC0) == 0x40)
{
context->uc_mcontext.gregs[REG_EIP]+=1;
}
return 0;
}
else if((*(ip) ==0x89)) // MOV [Rxx + Rxx], Exx
{
uint8_t dest_reg = (*(ip+1) % 0x40) / 8;
uint32_t dest = 0;
dest = context->uc_mcontext.gregs[CONV_REG64(dest_reg)];
r4300i_SW_NonMemory(MemAddress, dest);
if((*(ip+1) & 0x7)==4)
{
context->uc_mcontext.gregs[REG_EIP]+=3;
}
else
{
context->uc_mcontext.gregs[REG_EIP]+=2;
}
if((*(ip+1) & 0xC0) == 0x80)
{
context->uc_mcontext.gregs[REG_EIP]+=4;
}
else if((*(ip+1) & 0xC0) == 0x40)
{
context->uc_mcontext.gregs[REG_EIP]+=1;
}
return 0;
}
else if((*(ip) ==0xC7)) // MOV [Rxx + Rxx], Imm32
{
uint32_t imm32 = *(uint32_t*)(ip+2);
r4300i_SW_NonMemory(MemAddress, imm32);
context->uc_mcontext.gregs[REG_EIP]+=6;
// 40 C7 04 07 0F 00 00 00
//if(*(ip+2)&0x4)
if((*(ip+1) & 0x7)==4)
{
context->uc_mcontext.gregs[REG_EIP]++;
}
if((*(ip+1) & 0xC0) == 0x80)
{
context->uc_mcontext.gregs[REG_EIP]+=4;
}
else if((*(ip+1) & 0xC0) == 0x40)
{
context->uc_mcontext.gregs[REG_EIP]+=1;
}
return 0;
}
else if (*ip == 0x8B )
{
uint8_t dest_reg = CONV_REG((*(ip+1) % 0x40) / 8);
uint32_t word = 0;
uint32_t *dest = 0;
dest = (uint32_t *)context->uc_mcontext.gregs[CONV_REG64(dest_reg)];
r4300i_LW_NonMemory(MemAddress, &word);
*dest = word;
//*dest = 0;
//if(*(ip+2) & 0x4)
if((*(ip+1) & 0x7)==4)
{
context->uc_mcontext.gregs[REG_EIP]+=3;
}
else if((*(ip+1) & 0x7)==5)
{
context->uc_mcontext.gregs[REG_EIP]+=6;
}
else
{
context->uc_mcontext.gregs[REG_EIP]+=2;
}
if((*(ip+1) & 0xC0) == 0x80)
{
context->uc_mcontext.gregs[REG_EIP]+=4;
}
else if((*(ip+1) & 0xC0) == 0x40)
{
context->uc_mcontext.gregs[REG_EIP]+=1;
}
return 0;
}
return 1;
}
#endif
void Compile_LB ( int32_t Reg, uint32_t addr, uint32_t SignExtend )
{
uintptr_t Addr = addr;
if (!TranslateVaddr(&Addr))
{
MoveConstToX86reg(0,Reg);
return;
}
switch (Addr & 0xFFF00000)
{
case 0x00000000:
case 0x00100000:
case 0x00200000:
case 0x00300000:
case 0x00400000:
case 0x00500000:
case 0x00600000:
case 0x00700000:
case 0x10000000:
if (SignExtend)
{
MoveSxVariableToX86regByte(Addr + N64MEM,Reg);
}
else
{
MoveZxVariableToX86regByte(Addr + N64MEM,Reg);
}
break;
default:
MoveConstToX86reg(0,Reg);
}
}
void Compile_LH ( int32_t Reg, uint32_t addr, uint32_t SignExtend)
{
uintptr_t Addr = addr;
if (!TranslateVaddr(&Addr))
{
MoveConstToX86reg(0,Reg);
return;
}
switch (Addr & 0xFFF00000)
{
case 0x00000000:
case 0x00100000:
case 0x00200000:
case 0x00300000:
case 0x00400000:
case 0x00500000:
case 0x00600000:
case 0x00700000:
case 0x10000000:
if (SignExtend)
{
MoveSxVariableToX86regHalf(Addr + N64MEM,Reg);
}
else
{
MoveZxVariableToX86regHalf(Addr + N64MEM,Reg);
}
break;
default:
MoveConstToX86reg(0,Reg);
}
}
void Compile_LW ( int32_t Reg, uint32_t addr )
{
uintptr_t Addr = addr;
if (!TranslateVaddr(&Addr))
{
MoveConstToX86reg(0,Reg);
}
switch (Addr & 0xFFF00000)
{
case 0x00000000:
case 0x00100000:
case 0x00200000:
case 0x00300000:
case 0x00400000:
case 0x00500000:
case 0x00600000:
case 0x00700000:
case 0x10000000:
MoveVariableToX86reg(Addr + N64MEM,Reg);
break;
case 0x04000000:
if (Addr < 0x04002000)
{
MoveVariableToX86reg(Addr + N64MEM,Reg);
break;
}
switch (Addr)
{
case 0x04040010:
MoveVariableToX86reg(&SP_STATUS_REG,Reg);
break;
case 0x04040014:
MoveVariableToX86reg(&SP_DMA_FULL_REG,Reg);
break;
case 0x04040018:
MoveVariableToX86reg(&SP_DMA_BUSY_REG,Reg);
break;
case 0x04080000:
MoveVariableToX86reg(&SP_PC_REG,Reg);
break;
default:
MoveConstToX86reg(0,Reg);
break;
}
break;
case 0x04100000:
MoveVariableToX86reg(Addr + N64MEM,Reg);
break;
case 0x04300000:
switch (Addr)
{
case 0x04300000:
MoveVariableToX86reg(&MI_MODE_REG,Reg);
break;
case 0x04300004:
MoveVariableToX86reg(&MI_VERSION_REG,Reg);
break;
case 0x04300008:
MoveVariableToX86reg(&MI_INTR_REG,Reg);
break;
case 0x0430000C:
MoveVariableToX86reg(&MI_INTR_MASK_REG,Reg);
break;
default:
MoveConstToX86reg(0,Reg);
break;
}
break;
case 0x04400000:
switch (Addr)
{
case 0x04400010:
Pushad();
Call_Direct(&UpdateCurrentHalfLine);
Popad();
MoveVariableToX86reg(&HalfLine,Reg);
break;
default:
MoveConstToX86reg(0,Reg);
break;
}
break;
case 0x04500000: /* AI registers */
switch (Addr)
{
case 0x04500004:
Pushad();
Call_Direct(AiReadLength);
MoveX86regToVariable(x86_EAX,&TempValue);
Popad();
MoveVariableToX86reg(&TempValue,Reg);
break;
case 0x0450000C:
MoveVariableToX86reg(&AI_STATUS_REG,Reg);
break;
case 0x04500010:
MoveVariableToX86reg(&AI_DACRATE_REG,Reg);
break;
default:
MoveConstToX86reg(0,Reg);
break;
}
break;
case 0x04600000:
switch (Addr)
{
case 0x04600010:
MoveVariableToX86reg(&PI_STATUS_REG,Reg);
break;
case 0x04600014:
MoveVariableToX86reg(&PI_DOMAIN1_REG,Reg);
break;
case 0x04600018:
MoveVariableToX86reg(&PI_BSD_DOM1_PWD_REG,Reg);
break;
case 0x0460001C:
MoveVariableToX86reg(&PI_BSD_DOM1_PGS_REG,Reg);
break;
case 0x04600020:
MoveVariableToX86reg(&PI_BSD_DOM1_RLS_REG,Reg);
break;
case 0x04600024:
MoveVariableToX86reg(&PI_DOMAIN2_REG,Reg);
break;
case 0x04600028:
MoveVariableToX86reg(&PI_BSD_DOM2_PWD_REG,Reg);
break;
case 0x0460002C:
MoveVariableToX86reg(&PI_BSD_DOM2_PGS_REG,Reg);
break;
case 0x04600030:
MoveVariableToX86reg(&PI_BSD_DOM2_RLS_REG,Reg);
break;
default:
MoveConstToX86reg(0,Reg);
break;
}
break;
case 0x04700000:
switch (Addr)
{
case 0x0470000C:
MoveVariableToX86reg(&RI_SELECT_REG,Reg);
break;
case 0x04700010:
MoveVariableToX86reg(&RI_REFRESH_REG,Reg);
break;
default:
MoveConstToX86reg(0,Reg);
break;
}
break;
case 0x04800000:
switch (Addr)
{
case 0x04800018:
MoveVariableToX86reg(&SI_STATUS_REG,Reg);
break;
default:
MoveConstToX86reg(0,Reg);
break;
}
break;
case 0x1FC00000:
MoveVariableToX86reg(Addr + N64MEM,Reg);
break;
default:
MoveConstToX86reg(((Addr & 0xFFFF) << 16) | (Addr & 0xFFFF),Reg);
}
}
void Compile_SB_Const ( uint8_t Value, uint32_t addr )
{
uintptr_t Addr = addr;
if (!TranslateVaddr(&Addr))
{
return;
}
switch (Addr & 0xFFF00000)
{
case 0x00000000:
case 0x00100000:
case 0x00200000:
case 0x00300000:
case 0x00400000:
case 0x00500000:
case 0x00600000:
case 0x00700000:
MoveConstByteToVariable(Value,Addr + N64MEM);
break;
}
}
void Compile_SB_Register ( int32_t x86Reg, uint32_t addr )
{
uintptr_t Addr = addr;
if (!TranslateVaddr(&Addr))
{
return;
}
switch (Addr & 0xFFF00000)
{
case 0x00000000:
case 0x00100000:
case 0x00200000:
case 0x00300000:
case 0x00400000:
case 0x00500000:
case 0x00600000:
case 0x00700000:
MoveX86regByteToVariable(x86Reg,Addr + N64MEM);
break;
}
}
void Compile_SH_Const ( uint16_t Value, uint32_t addr )
{
uintptr_t Addr = addr;
if (!TranslateVaddr(&Addr))
{
return;
}
switch (Addr & 0xFFF00000)
{
case 0x00000000:
case 0x00100000:
case 0x00200000:
case 0x00300000:
case 0x00400000:
case 0x00500000:
case 0x00600000:
case 0x00700000:
MoveConstHalfToVariable(Value,Addr + N64MEM);
break;
}
}
void Compile_SH_Register ( int32_t x86Reg, uint32_t addr )
{
uintptr_t Addr = addr;
if (!TranslateVaddr(&Addr))
{
return;
}
switch (Addr & 0xFFF00000)
{
case 0x00000000:
case 0x00100000:
case 0x00200000:
case 0x00300000:
case 0x00400000:
case 0x00500000:
case 0x00600000:
case 0x00700000:
MoveX86regHalfToVariable(x86Reg,Addr + N64MEM);
break;
}
}
void Compile_SW_Const ( uint32_t Value, uint32_t addr )
{
uintptr_t Addr = addr;
if (!TranslateVaddr(&Addr))
{
return;
}
switch (Addr & 0xFFF00000)
{
case 0x00000000:
case 0x00100000:
case 0x00200000:
case 0x00300000:
case 0x00400000:
case 0x00500000:
case 0x00600000:
case 0x00700000:
MoveConstToVariable(Value,Addr + N64MEM);
break;
case 0x03F00000:
switch (Addr)
{
case 0x03F00000:
MoveConstToVariable(Value,&RDRAM_CONFIG_REG);
break;
case 0x03F00004:
MoveConstToVariable(Value,&RDRAM_DEVICE_ID_REG);
break;
case 0x03F00008:
MoveConstToVariable(Value,&RDRAM_DELAY_REG);
break;
case 0x03F0000C:
MoveConstToVariable(Value,&RDRAM_MODE_REG);
break;
case 0x03F00010:
MoveConstToVariable(Value,&RDRAM_REF_INTERVAL_REG);
break;
case 0x03F00014:
MoveConstToVariable(Value,&RDRAM_REF_ROW_REG);
break;
case 0x03F00018:
MoveConstToVariable(Value,&RDRAM_RAS_INTERVAL_REG);
break;
case 0x03F0001C:
MoveConstToVariable(Value,&RDRAM_MIN_INTERVAL_REG);
break;
case 0x03F00020:
MoveConstToVariable(Value,&RDRAM_ADDR_SELECT_REG);
break;
case 0x03F00024:
MoveConstToVariable(Value,&RDRAM_DEVICE_MANUF_REG);
break;
case 0x03F04004:
break;
case 0x03F08004:
break;
case 0x03F80004:
break;
case 0x03F80008:
break;
case 0x03F8000C:
break;
case 0x03F80014:
break;
}
break;
case 0x04000000:
if (Addr < 0x04002000)
{
MoveConstToVariable(Value,Addr + N64MEM);
break;
}
switch (Addr)
{
case 0x04040000:
MoveConstToVariable(Value,&SP_MEM_ADDR_REG);
break;
case 0x04040004:
MoveConstToVariable(Value,&SP_DRAM_ADDR_REG);
break;
case 0x04040008:
MoveConstToVariable(Value,&SP_RD_LEN_REG);
Pushad();
Call_Direct(&SP_DMA_READ);
Popad();
break;
case 0x04040010:
{
uint32_t ModValue = 0;
if ( ( Value & SP_CLR_HALT ) != 0 )
{
ModValue |= SP_STATUS_HALT;
}
if ( ( Value & SP_CLR_BROKE ) != 0 )
{
ModValue |= SP_STATUS_BROKE;
}
if ( ( Value & SP_CLR_SSTEP ) != 0 )
{
ModValue |= SP_STATUS_SSTEP;
}
if ( ( Value & SP_CLR_INTR_BREAK ) != 0 )
{
ModValue |= SP_STATUS_INTR_BREAK;
}
if ( ( Value & SP_CLR_SIG0 ) != 0 )
{
ModValue |= SP_STATUS_SIG0;
}
if ( ( Value & SP_CLR_SIG1 ) != 0 )
{
ModValue |= SP_STATUS_SIG1;
}
if ( ( Value & SP_CLR_SIG2 ) != 0 )
{
ModValue |= SP_STATUS_SIG2;
}
if ( ( Value & SP_CLR_SIG3 ) != 0 )
{
ModValue |= SP_STATUS_SIG3;
}
if ( ( Value & SP_CLR_SIG4 ) != 0 )
{
ModValue |= SP_STATUS_SIG4;
}
if ( ( Value & SP_CLR_SIG5 ) != 0 )
{
ModValue |= SP_STATUS_SIG5;
}
if ( ( Value & SP_CLR_SIG6 ) != 0 )
{
ModValue |= SP_STATUS_SIG6;
}
if ( ( Value & SP_CLR_SIG7 ) != 0 )
{
ModValue |= SP_STATUS_SIG7;
}
if (ModValue != 0)
{
AndConstToVariable(~ModValue,&SP_STATUS_REG);
}
ModValue = 0;
if ( ( Value & SP_SET_HALT ) != 0 )
{
ModValue |= SP_STATUS_HALT;
}
if ( ( Value & SP_SET_SSTEP ) != 0 )
{
ModValue |= SP_STATUS_SSTEP;
}
if ( ( Value & SP_SET_INTR_BREAK ) != 0)
{
ModValue |= SP_STATUS_INTR_BREAK;
}
if ( ( Value & SP_SET_SIG0 ) != 0 )
{
ModValue |= SP_STATUS_SIG0;
}
if ( ( Value & SP_SET_SIG1 ) != 0 )
{
ModValue |= SP_STATUS_SIG1;
}
if ( ( Value & SP_SET_SIG2 ) != 0 )
{
ModValue |= SP_STATUS_SIG2;
}
if ( ( Value & SP_SET_SIG3 ) != 0 )
{
ModValue |= SP_STATUS_SIG3;
}
if ( ( Value & SP_SET_SIG4 ) != 0 )
{
ModValue |= SP_STATUS_SIG4;
}
if ( ( Value & SP_SET_SIG5 ) != 0 )
{
ModValue |= SP_STATUS_SIG5;
}