Skip to content

Commit b470284

Browse files
committed
1 parent 48d2950 commit b470284

34 files changed

Lines changed: 4399 additions & 4476 deletions

Makefile.menu2_gc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ OBJ =main/rom_gc.o \
7979
r4300/cop1_s.o \
8080
r4300/cop1_d.o \
8181
r4300/recomp.o \
82+
gc_memory/n64_cic_nus_6105.o \
8283
gc_memory/pif.o \
8384
r4300/bc.o \
8485
r4300/cop1_l.o \
@@ -88,7 +89,6 @@ OBJ =main/rom_gc.o \
8889
main/md5.o \
8990
main/savestates_gc.o \
9091
r4300/profile.o \
91-
main/adler32.o \
9292
main/ata.o
9393

9494
OBJ_PPC =r4300/ppc/MIPS-to-PPC.o \
@@ -102,6 +102,7 @@ OBJ_INPUT =gc_input/main.o \
102102

103103
OBJ_RSPHLE =rsp_hle/main.o \
104104
rsp_hle/jpeg.o \
105+
rsp_hle/idct.o \
105106
rsp_hle/ucode3.o \
106107
rsp_hle/ucode2.o \
107108
rsp_hle/ucode1.o \

Makefile.menu2_wii

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ OBJ =main/rom_gc.o \
7878
r4300/cop1_s.o \
7979
r4300/cop1_d.o \
8080
r4300/recomp.o \
81+
gc_memory/n64_cic_nus_6105.o \
8182
gc_memory/pif.o \
8283
r4300/bc.o \
8384
r4300/cop1_l.o \
@@ -87,7 +88,6 @@ OBJ =main/rom_gc.o \
8788
main/md5.o \
8889
main/savestates_gc.o \
8990
r4300/profile.o \
90-
main/adler32.o \
9191
main/ata.o
9292

9393
OBJ_PPC =r4300/ppc/MIPS-to-PPC.o \
@@ -103,6 +103,7 @@ OBJ_INPUT =gc_input/main.o \
103103

104104
OBJ_RSPHLE =rsp_hle/main.o \
105105
rsp_hle/jpeg.o \
106+
rsp_hle/idct.o \
106107
rsp_hle/ucode3.o \
107108
rsp_hle/ucode2.o \
108109
rsp_hle/ucode1.o \

gc_audio/audio.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ static void aesnd_callback(AESNDPB *pb, uint32_t state)
6060
}
6161
}
6262

63+
static void reset_buffer(void)
64+
{
65+
write_ptr = buffer;
66+
read_ptr = buffer;
67+
buffered = 0;
68+
memset(buffer, 0, BUFFER_SIZE);
69+
}
70+
6371
EXPORT void CALL AiDacrateChanged(int SystemType)
6472
{
6573
freq = DEFAULT_FREQUENCY;
@@ -85,21 +93,22 @@ EXPORT void CALL AiLenChanged(void)
8593
if (audioEnabled) {
8694
uint32_t level = IRQ_Disable();
8795

88-
short *stream = (short *)(AudioInfo.RDRAM + (*AudioInfo.AI_DRAM_ADDR_REG & 0xFFFFFF));
96+
void *stream = AudioInfo.RDRAM + (*AudioInfo.AI_DRAM_ADDR_REG & 0xFFFFFF);
8997
unsigned int length = *AudioInfo.AI_LEN_REG;
9098

91-
do {
92-
int len = MIN(end_ptr - write_ptr, length);
93-
memcpy(write_ptr, stream, len);
94-
stream = ((char *)stream + len);
95-
96-
write_ptr += len;
97-
if (write_ptr >= end_ptr)
98-
write_ptr = buffer;
99-
buffered += len;
100-
101-
length -= len;
102-
} while (length > 0);
99+
if (buffered + length < BUFFER_SIZE) {
100+
do {
101+
int size = MIN(end_ptr - write_ptr, length);
102+
memcpy(write_ptr, stream, size);
103+
stream = (char *)stream + size;
104+
105+
write_ptr += size;
106+
if (write_ptr >= end_ptr)
107+
write_ptr = buffer;
108+
buffered += size;
109+
length -= size;
110+
} while (length > 0);
111+
}
103112

104113
if (scalePitch)
105114
AESND_SetVoiceFrequency(voice, freq * (Timers.vis / VILimit));
@@ -129,11 +138,9 @@ EXPORT BOOL CALL InitiateAudio(AUDIO_INFO Audio_Info)
129138
return TRUE;
130139
}
131140

132-
EXPORT void CALL RomOpen()
141+
EXPORT void CALL RomOpen(void)
133142
{
134-
write_ptr = buffer;
135-
read_ptr = buffer;
136-
buffered = 0;
143+
reset_buffer();
137144
AESND_SetVoiceStop(voice, false);
138145
}
139146

@@ -151,6 +158,7 @@ void pauseAudio(void) {
151158
}
152159

153160
void resumeAudio(void) {
161+
reset_buffer();
154162
AESND_SetVoiceFrequency(voice, freq);
155163
AESND_Pause(!audioEnabled);
156164
}

gc_memory/MEM2.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,15 @@
3535
#define MEM2_HI ((char*)0x933E0000)
3636
#define MEM2_SIZE (MEM2_HI - MEM2_LO)
3737

38-
// Testing the xfb in MEM2 (reduce Texture Cache by 2MB to accomodate)
39-
/*#define XFB_SIZE (720*480*2) // XFB_SIZE*2 ~= 1.4MB
38+
// Testing the xfb in MEM2
39+
#define XFB_SIZE (720*576*2) // XFB_SIZE*2 ~= 1.6MB
4040
#define XFB0_LO (MEM2_LO)
4141
#define XFB1_LO (XFB0_LO + XFB_SIZE)
42-
#define XFB_HI (XFB1_LO + XFB_SIZE)*/
42+
#define XFB_HI (XFB1_LO + XFB_SIZE)
4343

4444
// We want 16MB for our ROM Cache
4545
#define ROMCACHE_SIZE (16*MB)
46-
#define ROMCACHE_LO (MEM2_LO)
47-
//#define ROMCACHE_LO (XFB_HI)
46+
#define ROMCACHE_LO (XFB_HI)
4847
#define ROMCACHE_HI (ROMCACHE_LO + ROMCACHE_SIZE)
4948

5049
// We want 8MB for TLB lut's

gc_memory/n64_cic_nus_6105.c

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright 2011 X-Scale. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
*
7+
* 1. Redistributions of source code must retain the above copyright notice,
8+
* this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY X-Scale ``AS IS'' AND ANY EXPRESS OR IMPLIED
14+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
16+
* EVENT SHALL X-Scale OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
17+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
19+
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
20+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
22+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23+
*
24+
* The views and conclusions contained in the software and documentation are
25+
* those of the authors and should not be interpreted as representing official
26+
* policies, either expressed or implied, of X-Scale.
27+
*
28+
* This software provides an algorithm that emulates the protection scheme of
29+
* N64 PIF/CIC-NUS-6105, by determining the proper response to each challenge.
30+
* It was synthesized after a careful, exhaustive and detailed analysis of the
31+
* challenge/response pairs stored in the 'pif2.dat' file from Project 64.
32+
* These challenge/response pairs were the only resource used during this
33+
* project. There was no kind of physical access to N64 hardware.
34+
*
35+
* This project would have never been possible without the contribuitions of
36+
* the following individuals and organizations:
37+
*
38+
* - Oman: For being at the right place at the right time and being brave
39+
* enough to pay a personal price so we could understand in a much deeper
40+
* way how this magical console really works. We owe you so much.
41+
*
42+
* - Jovis: For all the positive energy and impressive hacking spirit that you
43+
* shared with the N64 community. You were absolutely instrumental in
44+
* several key events that shaped the N64 community in the last 14 years.
45+
* Even if you're not physically with us anymore, your heritage, your
46+
* knowledge and your attitude will never be forgotten.
47+
*
48+
* 'The candle that burns twice as bright burns half as long.'
49+
*
50+
* - LaC: For the endless contributions that you've given to the N64 community
51+
* since the early days, when N64 was the next big thing. I've always
52+
* admired the deep knowledge that you've gathered about the most little
53+
* hardware details. Recently, you challanged us to find a small and
54+
* concise algorithm that would emulate the behaviour of CIC-NUS-6105
55+
* challenge/response protection scheme and here is the final result.
56+
* LaC, Oman and Jovis were definitly the dream team of N64 reversing in
57+
* the late 90's. Without your contributions, we would be much poorer.
58+
*
59+
* - marshall: For keeping the N64 scene alive during the last decade, when
60+
* most people lost interest and moved along to different projects. You
61+
* are the force that has been keeping us all together in the later
62+
* years. When almost nobody cared about N64 anymore, you were always
63+
* there, spreading the word, developing in the console, and lately,
64+
* making impressive advances on the hardware side. I wish the best
65+
* success to your new 64drive project.
66+
*
67+
* - hcs: For your contributions to the better understanding of the inner
68+
* workings of the Reality Co-Processor (RCP). Your skills have impressed
69+
* me for a long time now. And without your precious help by sharing your
70+
* kownledge, I would have never understood the immense importance of
71+
* Oman, Jovis and LaC achievements. Thank you !
72+
*
73+
* - Azimer & Tooie: For sharing with the N64 community your findings about the
74+
* challenge/response pair used in 'Jet Force Gemini' and the 267
75+
* challenge/response pairs used in 'Banjo Tooie', all stored in the
76+
* 'pif2.dat' file of Project 64. They were instrumental to the final
77+
* success of this endeavour.
78+
*
79+
* - Silicon Graphics, Inc. (SGI): For creating MIPS R4000, MIPS R4300 and
80+
* Reality Co-Processor (RCP). You were the ultimate dream creator during
81+
* the late 80's and early 90's. A very special word of gratitude goes to
82+
* the two teams that during those years created RCP and MIPS R4300. They
83+
* were technological breakthroughs back then.
84+
*
85+
* On a personal note, I would like to show my deepest gratitude to _Bijou_,
86+
* for being always a source of endless hope and inspiration.
87+
*
88+
* -= X-Scale =- (#n64dev@EFnet)
89+
*/
90+
91+
#include "n64_cic_nus_6105.h"
92+
93+
void n64_cic_nus_6105(char chl[], char rsp[], int len)
94+
{
95+
static char lut0[0x10] = {
96+
0x4, 0x7, 0xA, 0x7, 0xE, 0x5, 0xE, 0x1,
97+
0xC, 0xF, 0x8, 0xF, 0x6, 0x3, 0x6, 0x9
98+
};
99+
static char lut1[0x10] = {
100+
0x4, 0x1, 0xA, 0x7, 0xE, 0x5, 0xE, 0x1,
101+
0xC, 0x9, 0x8, 0x5, 0x6, 0x3, 0xC, 0x9
102+
};
103+
char key, *lut;
104+
int i, sgn, mag, mod;
105+
106+
for (key = 0xB, lut = lut0, i = 0; i < len; i++) {
107+
rsp[i] = (key + 5 * chl[i]) & 0xF;
108+
key = lut[(int) rsp[i]];
109+
sgn = (rsp[i] >> 3) & 0x1;
110+
mag = ((sgn == 1) ? ~rsp[i] : rsp[i]) & 0x7;
111+
mod = (mag % 3 == 1) ? sgn : 1 - sgn;
112+
if (lut == lut1 && (rsp[i] == 0x1 || rsp[i] == 0x9))
113+
mod = 1;
114+
if (lut == lut1 && (rsp[i] == 0xB || rsp[i] == 0xE))
115+
mod = 0;
116+
lut = (mod == 1) ? lut1 : lut0;
117+
}
118+
}
119+

gc_memory/n64_cic_nus_6105.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright 2011 X-Scale. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
*
7+
* 1. Redistributions of source code must retain the above copyright notice,
8+
* this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY X-Scale ``AS IS'' AND ANY EXPRESS OR IMPLIED
14+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
16+
* EVENT SHALL X-Scale OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
17+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
19+
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
20+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
22+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23+
*
24+
* The views and conclusions contained in the software and documentation are
25+
* those of the authors and should not be interpreted as representing official
26+
* policies, either expressed or implied, of X-Scale.
27+
*
28+
* This software provides an algorithm that emulates the protection scheme of
29+
* N64 PIF/CIC-NUS-6105, by determining the proper response to each challenge.
30+
* It was synthesized after a careful, exhaustive and detailed analysis of the
31+
* challenge/response pairs stored in the 'pif2.dat' file from Project 64.
32+
* These challenge/response pairs were the only resource used during this
33+
* project. There was no kind of physical access to N64 hardware.
34+
*
35+
* This project would have never been possible without the contribuitions of
36+
* the following individuals and organizations:
37+
*
38+
* - Oman: For being at the right place at the right time and being brave
39+
* enough to pay a personal price so we could understand in a much deeper
40+
* way how this magical console really works. We owe you so much.
41+
*
42+
* - Jovis: For all the positive energy and impressive hacking spirit that you
43+
* shared with the N64 community. You were absolutely instrumental in
44+
* several key events that shaped the N64 community in the last 14 years.
45+
* Even if you're not physically with us anymore, your heritage, your
46+
* knowledge and your attitude will never be forgotten.
47+
*
48+
* 'The candle that burns twice as bright burns half as long.'
49+
*
50+
* - LaC: For the endless contributions that you've given to the N64 community
51+
* since the early days, when N64 was the next big thing. I've always
52+
* admired the deep knowledge that you've gathered about the most little
53+
* hardware details. Recently, you challanged us to find a small and
54+
* concise algorithm that would emulate the behaviour of CIC-NUS-6105
55+
* challenge/response protection scheme and here is the final result.
56+
* LaC, Oman and Jovis were definitly the dream team of N64 reversing in
57+
* the late 90's. Without your contributions, we would be much poorer.
58+
*
59+
* - marshall: For keeping the N64 scene alive during the last decade, when
60+
* most people lost interest and moved along to different projects. You
61+
* are the force that has been keeping us all together in the later
62+
* years. When almost nobody cared about N64 anymore, you were always
63+
* there, spreading the word, developing in the console, and lately,
64+
* making impressive advances on the hardware side. I wish the best
65+
* success to your new 64drive project.
66+
*
67+
* - hcs: For your contributions to the better understanding of the inner
68+
* workings of the Reality Co-Processor (RCP). Your skills have impressed
69+
* me for a long time now. And without your precious help by sharing your
70+
* kownledge, I would have never understood the immense importance of
71+
* Oman, Jovis and LaC achievements. Thank you !
72+
*
73+
* - Azimer & Tooie: For sharing with the N64 community your findings about the
74+
* challenge/response pair used in 'Jet Force Gemini' and the 267
75+
* challenge/response pairs used in 'Banjo Tooie', all stored in the
76+
* 'pif2.dat' file of Project 64. They were instrumental to the final
77+
* success of this endeavour.
78+
*
79+
* - Silicon Graphics, Inc. (SGI): For creating MIPS R4000, MIPS R4300 and
80+
* Reality Co-Processor (RCP). You were the ultimate dream creator during
81+
* the late 80's and early 90's. A very special word of gratitude goes to
82+
* the two teams that during those years created RCP and MIPS R4300. They
83+
* were technological breakthroughs back then.
84+
*
85+
* On a personal note, I would like to show my deepest gratitude to _Bijou_,
86+
* for being always a source of endless hope and inspiration.
87+
*
88+
* -= X-Scale =- (#n64dev@EFnet)
89+
*/
90+
91+
#ifndef N64_CIC_NUS_6105_H
92+
#define N64_CIC_NUS_6105_H
93+
94+
#define CHL_LEN 0x20
95+
96+
void n64_cic_nus_6105(char chl[], char rsp[], int len);
97+
98+
#endif /* N64_CIC_NUS_6105_H */

0 commit comments

Comments
 (0)