Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Feb 4, 2015
1 parent 48d2950 commit b470284
Show file tree
Hide file tree
Showing 34 changed files with 4,399 additions and 4,476 deletions.
3 changes: 2 additions & 1 deletion Makefile.menu2_gc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ OBJ =main/rom_gc.o \
r4300/cop1_s.o \
r4300/cop1_d.o \
r4300/recomp.o \
gc_memory/n64_cic_nus_6105.o \
gc_memory/pif.o \
r4300/bc.o \
r4300/cop1_l.o \
Expand All @@ -88,7 +89,6 @@ OBJ =main/rom_gc.o \
main/md5.o \
main/savestates_gc.o \
r4300/profile.o \
main/adler32.o \
main/ata.o

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

OBJ_RSPHLE =rsp_hle/main.o \
rsp_hle/jpeg.o \
rsp_hle/idct.o \
rsp_hle/ucode3.o \
rsp_hle/ucode2.o \
rsp_hle/ucode1.o \
Expand Down
3 changes: 2 additions & 1 deletion Makefile.menu2_wii
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ OBJ =main/rom_gc.o \
r4300/cop1_s.o \
r4300/cop1_d.o \
r4300/recomp.o \
gc_memory/n64_cic_nus_6105.o \
gc_memory/pif.o \
r4300/bc.o \
r4300/cop1_l.o \
Expand All @@ -87,7 +88,6 @@ OBJ =main/rom_gc.o \
main/md5.o \
main/savestates_gc.o \
r4300/profile.o \
main/adler32.o \
main/ata.o

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

OBJ_RSPHLE =rsp_hle/main.o \
rsp_hle/jpeg.o \
rsp_hle/idct.o \
rsp_hle/ucode3.o \
rsp_hle/ucode2.o \
rsp_hle/ucode1.o \
Expand Down
42 changes: 25 additions & 17 deletions gc_audio/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ static void aesnd_callback(AESNDPB *pb, uint32_t state)
}
}

static void reset_buffer(void)
{
write_ptr = buffer;
read_ptr = buffer;
buffered = 0;
memset(buffer, 0, BUFFER_SIZE);
}

EXPORT void CALL AiDacrateChanged(int SystemType)
{
freq = DEFAULT_FREQUENCY;
Expand All @@ -85,21 +93,22 @@ EXPORT void CALL AiLenChanged(void)
if (audioEnabled) {
uint32_t level = IRQ_Disable();

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

do {
int len = MIN(end_ptr - write_ptr, length);
memcpy(write_ptr, stream, len);
stream = ((char *)stream + len);

write_ptr += len;
if (write_ptr >= end_ptr)
write_ptr = buffer;
buffered += len;

length -= len;
} while (length > 0);
if (buffered + length < BUFFER_SIZE) {
do {
int size = MIN(end_ptr - write_ptr, length);
memcpy(write_ptr, stream, size);
stream = (char *)stream + size;

write_ptr += size;
if (write_ptr >= end_ptr)
write_ptr = buffer;
buffered += size;
length -= size;
} while (length > 0);
}

if (scalePitch)
AESND_SetVoiceFrequency(voice, freq * (Timers.vis / VILimit));
Expand Down Expand Up @@ -129,11 +138,9 @@ EXPORT BOOL CALL InitiateAudio(AUDIO_INFO Audio_Info)
return TRUE;
}

EXPORT void CALL RomOpen()
EXPORT void CALL RomOpen(void)
{
write_ptr = buffer;
read_ptr = buffer;
buffered = 0;
reset_buffer();
AESND_SetVoiceStop(voice, false);
}

Expand All @@ -151,6 +158,7 @@ void pauseAudio(void) {
}

void resumeAudio(void) {
reset_buffer();
AESND_SetVoiceFrequency(voice, freq);
AESND_Pause(!audioEnabled);
}
9 changes: 4 additions & 5 deletions gc_memory/MEM2.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@
#define MEM2_HI ((char*)0x933E0000)
#define MEM2_SIZE (MEM2_HI - MEM2_LO)

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

// We want 16MB for our ROM Cache
#define ROMCACHE_SIZE (16*MB)
#define ROMCACHE_LO (MEM2_LO)
//#define ROMCACHE_LO (XFB_HI)
#define ROMCACHE_LO (XFB_HI)
#define ROMCACHE_HI (ROMCACHE_LO + ROMCACHE_SIZE)

// We want 8MB for TLB lut's
Expand Down
119 changes: 119 additions & 0 deletions gc_memory/n64_cic_nus_6105.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright 2011 X-Scale. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY X-Scale ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL X-Scale OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of X-Scale.
*
* This software provides an algorithm that emulates the protection scheme of
* N64 PIF/CIC-NUS-6105, by determining the proper response to each challenge.
* It was synthesized after a careful, exhaustive and detailed analysis of the
* challenge/response pairs stored in the 'pif2.dat' file from Project 64.
* These challenge/response pairs were the only resource used during this
* project. There was no kind of physical access to N64 hardware.
*
* This project would have never been possible without the contribuitions of
* the following individuals and organizations:
*
* - Oman: For being at the right place at the right time and being brave
* enough to pay a personal price so we could understand in a much deeper
* way how this magical console really works. We owe you so much.
*
* - Jovis: For all the positive energy and impressive hacking spirit that you
* shared with the N64 community. You were absolutely instrumental in
* several key events that shaped the N64 community in the last 14 years.
* Even if you're not physically with us anymore, your heritage, your
* knowledge and your attitude will never be forgotten.
*
* 'The candle that burns twice as bright burns half as long.'
*
* - LaC: For the endless contributions that you've given to the N64 community
* since the early days, when N64 was the next big thing. I've always
* admired the deep knowledge that you've gathered about the most little
* hardware details. Recently, you challanged us to find a small and
* concise algorithm that would emulate the behaviour of CIC-NUS-6105
* challenge/response protection scheme and here is the final result.
* LaC, Oman and Jovis were definitly the dream team of N64 reversing in
* the late 90's. Without your contributions, we would be much poorer.
*
* - marshall: For keeping the N64 scene alive during the last decade, when
* most people lost interest and moved along to different projects. You
* are the force that has been keeping us all together in the later
* years. When almost nobody cared about N64 anymore, you were always
* there, spreading the word, developing in the console, and lately,
* making impressive advances on the hardware side. I wish the best
* success to your new 64drive project.
*
* - hcs: For your contributions to the better understanding of the inner
* workings of the Reality Co-Processor (RCP). Your skills have impressed
* me for a long time now. And without your precious help by sharing your
* kownledge, I would have never understood the immense importance of
* Oman, Jovis and LaC achievements. Thank you !
*
* - Azimer & Tooie: For sharing with the N64 community your findings about the
* challenge/response pair used in 'Jet Force Gemini' and the 267
* challenge/response pairs used in 'Banjo Tooie', all stored in the
* 'pif2.dat' file of Project 64. They were instrumental to the final
* success of this endeavour.
*
* - Silicon Graphics, Inc. (SGI): For creating MIPS R4000, MIPS R4300 and
* Reality Co-Processor (RCP). You were the ultimate dream creator during
* the late 80's and early 90's. A very special word of gratitude goes to
* the two teams that during those years created RCP and MIPS R4300. They
* were technological breakthroughs back then.
*
* On a personal note, I would like to show my deepest gratitude to _Bijou_,
* for being always a source of endless hope and inspiration.
*
* -= X-Scale =- (#n64dev@EFnet)
*/

#include "n64_cic_nus_6105.h"

void n64_cic_nus_6105(char chl[], char rsp[], int len)
{
static char lut0[0x10] = {
0x4, 0x7, 0xA, 0x7, 0xE, 0x5, 0xE, 0x1,
0xC, 0xF, 0x8, 0xF, 0x6, 0x3, 0x6, 0x9
};
static char lut1[0x10] = {
0x4, 0x1, 0xA, 0x7, 0xE, 0x5, 0xE, 0x1,
0xC, 0x9, 0x8, 0x5, 0x6, 0x3, 0xC, 0x9
};
char key, *lut;
int i, sgn, mag, mod;

for (key = 0xB, lut = lut0, i = 0; i < len; i++) {
rsp[i] = (key + 5 * chl[i]) & 0xF;
key = lut[(int) rsp[i]];
sgn = (rsp[i] >> 3) & 0x1;
mag = ((sgn == 1) ? ~rsp[i] : rsp[i]) & 0x7;
mod = (mag % 3 == 1) ? sgn : 1 - sgn;
if (lut == lut1 && (rsp[i] == 0x1 || rsp[i] == 0x9))
mod = 1;
if (lut == lut1 && (rsp[i] == 0xB || rsp[i] == 0xE))
mod = 0;
lut = (mod == 1) ? lut1 : lut0;
}
}

98 changes: 98 additions & 0 deletions gc_memory/n64_cic_nus_6105.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright 2011 X-Scale. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY X-Scale ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL X-Scale OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of X-Scale.
*
* This software provides an algorithm that emulates the protection scheme of
* N64 PIF/CIC-NUS-6105, by determining the proper response to each challenge.
* It was synthesized after a careful, exhaustive and detailed analysis of the
* challenge/response pairs stored in the 'pif2.dat' file from Project 64.
* These challenge/response pairs were the only resource used during this
* project. There was no kind of physical access to N64 hardware.
*
* This project would have never been possible without the contribuitions of
* the following individuals and organizations:
*
* - Oman: For being at the right place at the right time and being brave
* enough to pay a personal price so we could understand in a much deeper
* way how this magical console really works. We owe you so much.
*
* - Jovis: For all the positive energy and impressive hacking spirit that you
* shared with the N64 community. You were absolutely instrumental in
* several key events that shaped the N64 community in the last 14 years.
* Even if you're not physically with us anymore, your heritage, your
* knowledge and your attitude will never be forgotten.
*
* 'The candle that burns twice as bright burns half as long.'
*
* - LaC: For the endless contributions that you've given to the N64 community
* since the early days, when N64 was the next big thing. I've always
* admired the deep knowledge that you've gathered about the most little
* hardware details. Recently, you challanged us to find a small and
* concise algorithm that would emulate the behaviour of CIC-NUS-6105
* challenge/response protection scheme and here is the final result.
* LaC, Oman and Jovis were definitly the dream team of N64 reversing in
* the late 90's. Without your contributions, we would be much poorer.
*
* - marshall: For keeping the N64 scene alive during the last decade, when
* most people lost interest and moved along to different projects. You
* are the force that has been keeping us all together in the later
* years. When almost nobody cared about N64 anymore, you were always
* there, spreading the word, developing in the console, and lately,
* making impressive advances on the hardware side. I wish the best
* success to your new 64drive project.
*
* - hcs: For your contributions to the better understanding of the inner
* workings of the Reality Co-Processor (RCP). Your skills have impressed
* me for a long time now. And without your precious help by sharing your
* kownledge, I would have never understood the immense importance of
* Oman, Jovis and LaC achievements. Thank you !
*
* - Azimer & Tooie: For sharing with the N64 community your findings about the
* challenge/response pair used in 'Jet Force Gemini' and the 267
* challenge/response pairs used in 'Banjo Tooie', all stored in the
* 'pif2.dat' file of Project 64. They were instrumental to the final
* success of this endeavour.
*
* - Silicon Graphics, Inc. (SGI): For creating MIPS R4000, MIPS R4300 and
* Reality Co-Processor (RCP). You were the ultimate dream creator during
* the late 80's and early 90's. A very special word of gratitude goes to
* the two teams that during those years created RCP and MIPS R4300. They
* were technological breakthroughs back then.
*
* On a personal note, I would like to show my deepest gratitude to _Bijou_,
* for being always a source of endless hope and inspiration.
*
* -= X-Scale =- (#n64dev@EFnet)
*/

#ifndef N64_CIC_NUS_6105_H
#define N64_CIC_NUS_6105_H

#define CHL_LEN 0x20

void n64_cic_nus_6105(char chl[], char rsp[], int len);

#endif /* N64_CIC_NUS_6105_H */
Loading

0 comments on commit b470284

Please sign in to comment.