1
0
mirror of https://github.com/parasyte/alt64 synced 2024-11-02 00:05:03 -04:00

#18 Aleck64 games now boot

get_cic() refactored to include Aleck64 roms
moved CIC functions to dedicated module
This commit is contained in:
Robin Jones 2017-10-13 18:47:19 +01:00
parent b25201a8ea
commit ac58a8736a
8 changed files with 133 additions and 89 deletions

12
inc/cic.h Normal file
View File

@ -0,0 +1,12 @@
#define CIC_6101 1
#define CIC_6102 2
#define CIC_6103 3
#define CIC_5101 4 //aleck64
//#define CIC_6104 6104 //Unused in any game so used for Aleck64 instead
#define CIC_6105 5
#define CIC_6106 6
#define CIC_5167 7 //64dd conv
int get_cic(unsigned char *rom_data);

View File

@ -148,14 +148,7 @@
#define FRAM_STATUS_REG 0xA8000000
#define FRAM_COMMAND_REG 0xA8010000
#define CIC_6101 1
#define CIC_6102 2
#define CIC_6103 3
#define CIC_5101 4 //aleck64
//#define CIC_6104 6104 //Unused in any game so used for Aleck64 instead
#define CIC_6105 5
#define CIC_6106 6
#define CIC_5167 7 //64dd conv
//void romFill(...);
void pif_boot();
@ -164,6 +157,5 @@ int is_valid_rom(unsigned char *buffer);
void swap_header(unsigned char* header, int loadlength);
u8 getCicType(u8 bios_cic);
int get_cic(unsigned char *buffer);
#endif

View File

@ -19,8 +19,6 @@ void dma_write_sram(void* src, u32 offset, u32 size);
void dma_read_sram(void *dest, u32 offset, u32 size);
u8 getSaveType();
unsigned int CRC_Calculate(unsigned int crc, unsigned char* buf, unsigned int len);
typedef struct SP_regs_s {
u32 mem_addr;

117
src/cic.c Normal file
View File

@ -0,0 +1,117 @@
//
// si/cic.c: PIF CIC security/lock out algorithms.
//
// CEN64: Cycle-Accurate Nintendo 64 Emulator.
// Copyright (C) 2015, Tyler J. Stachecki.
//
// This file is subject to the terms and conditions defined in
// 'LICENSE', which is part of this source code package.
//
//#include "common.h"
//#include "si/cic.h"
#include <stdint.h>
#include <stddef.h>
#include "cic.h"
// CIC seeds and status bits passed from PIF to IPL through PIF RAM
// Bits | Description
// 00080000 | ROM type (0 = Game Pack, 1 = DD)
// 00040000 | Version
// 00020000 | Reset Type (0 = cold reset, 1 = NMI)
// 0000FF00 | CIC IPL3 seed value
// 000000FF | CIC IPL2 seed value
// #define CIC_SEED_NUS_5101 0x0000AC00U
// #define CIC_SEED_NUS_6101 0x00043F3FU
// #define CIC_SEED_NUS_6102 0x00003F3FU
// #define CIC_SEED_NUS_6103 0x0000783FU
// #define CIC_SEED_NUS_6105 0x0000913FU
// #define CIC_SEED_NUS_6106 0x0000853FU
// #define CIC_SEED_NUS_8303 0x0000DD00U
#define CRC_NUS_5101 0x587BD543U
#define CRC_NUS_6101 0x6170A4A1U
#define CRC_NUS_7102 0x009E9EA3U
#define CRC_NUS_6102 0x90BB6CB5U
#define CRC_NUS_6103 0x0B050EE0U
#define CRC_NUS_6105 0x98BC2C86U
#define CRC_NUS_6106 0xACC8580AU
#define CRC_NUS_8303 0x0E018159U
static uint32_t si_crc32(const uint8_t *data, size_t size);
// Determines the CIC seed for a cart, given the ROM data.
//int get_cic_seed(const uint8_t *rom_data, uint32_t *cic_seed) {
int get_cic(unsigned char *rom_data) {
uint32_t crc = si_crc32(rom_data + 0x40, 0x1000 - 0x40);
uint32_t aleck64crc = si_crc32(rom_data + 0x40, 0xC00 - 0x40);
if (aleck64crc == CRC_NUS_5101)
return 4;//*cic_seed = CIC_SEED_NUS_5101;
else
{
switch (crc) {
case CRC_NUS_6101:
case CRC_NUS_7102:
//*cic_seed = CIC_SEED_NUS_6101;
return 1;
break;
case CRC_NUS_6102:
//*cic_seed = CIC_SEED_NUS_6102;
return 2;
break;
case CRC_NUS_6103:
//*cic_seed = CIC_SEED_NUS_6103;
return 3;
break;
case CRC_NUS_6105:
//*cic_seed = CIC_SEED_NUS_6105;
return 5;
break;
case CRC_NUS_6106:
//*cic_seed = CIC_SEED_NUS_6106;
return 6;
break;
//case CRC_NUS_8303: //not sure if this is necessary as we are using cart conversions
//*cic_seed = CIC_SEED_NUS_8303;
//return 7;
//break;
default:
break;
}
}
return 2;
}
uint32_t si_crc32(const uint8_t *data, size_t size) {
uint32_t table[256];
unsigned n, k;
uint32_t c;
for (n = 0; n < 256; n++) {
c = (uint32_t) n;
for (k = 0; k < 8; k++) {
if (c & 1)
c = 0xEDB88320L ^ (c >> 1);
else
c = c >> 1;
}
table[n] = c;
}
c = 0L ^ 0xFFFFFFFF;
for (n = 0; n < size; n++)
c = table[(c ^ data[n]) & 0xFF] ^ (c >> 8);
return c ^ 0xFFFFFFFF;
}

View File

@ -47,6 +47,7 @@
#include "rom.h"
#include "memorypak.h"
#include "menu.h"
#include "cic.h"
#ifdef USE_TRUETYPE
#define STB_TRUETYPE_IMPLEMENTATION
@ -2331,16 +2332,12 @@ void alterRomConfig(int type, int mode)
//down
if (rom_config[1] < max_cic)
rom_config[1]++;
if (rom_config[1] == 3)
rom_config[1]++;
}
else if (mode == 2)
{
//up
if (rom_config[1] > min_cic)
rom_config[1]--;
if (rom_config[1] == 3)
rom_config[1]--;
}
//end cic
break;

View File

@ -8,6 +8,7 @@
#include "everdrive.h"
#include "sys.h"
#include "rom.h"
#include "cic.h"
void pif_boot()
{
@ -76,27 +77,3 @@ u8 getCicType(u8 bios_cic) {
return cic_chip;
}
int get_cic(unsigned char *buffer) {
unsigned int crc;
// figure out the CIC
crc = CRC_Calculate(0, buffer, 1000);
switch(crc) {
case 0x303faac9:
case 0xf0da3d50:
return 1;
case 0xf3106101:
return 2;
case 0xe7cd9d51:
return 3;
case 0x7ae65c9:
return 5;
case 0x86015f8f:
return 6;
//case 0x86015f8f: TODO: need to find the correct number
//return 5167; 64dd
}
return 2;
}

View File

@ -114,50 +114,7 @@ void dma_write_sram(void* src, u32 offset, u32 size) {
}
//TODO: look at https://github.com/mamedev/mame/blob/master/3rdparty/zlib/crc32.c
#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
#define DO2(buf) DO1(buf); DO1(buf);
#define DO4(buf) DO2(buf); DO2(buf);
#define DO8(buf) DO4(buf); DO4(buf);
unsigned int CRC_Calculate(unsigned int crc, unsigned char* buf, unsigned int len) {
static unsigned int crc_table[256];
static int make_crc_table = 1;
if (make_crc_table) {
unsigned int c, n;
int k;
unsigned int poly;
const unsigned char p[] = {0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26};
/* make exclusive-or pattern from polynomial (0xedb88320L) */
poly = 0L;
for (n = 0; n < sizeof (p) / sizeof (unsigned char); n++)
poly |= 1L << (31 - p[n]);
for (n = 0; n < 256; n++) {
c = n;
for (k = 0; k < 8; k++)
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
crc_table[n] = c;
}
make_crc_table = 0;
}
if (buf == (void*) 0) return 0L;
crc = crc ^ 0xffffffffL;
while (len >= 8) {
DO8(buf);
len -= 8;
}
if (len)
do {
DO1(buf);
} while (--len);
return crc ^ 0xffffffffL;
}

View File

@ -13,6 +13,7 @@
#include "utils.h"
#include "sram.h"
#include "rom.h"
#include "cic.h"
extern short int gCheats; /* 0 = off, 1 = select, 2 = all */
@ -434,13 +435,6 @@ void restoreTiming(void) {
}
//#define CIC_6101 1
//#define CIC_6102 2
//#define CIC_6103 3
//#define CIC_6104 4
//#define CIC_6105 5
//#define CIC_6106 6
#define ROM ((vu32 *)0xB0000000)
#define EXE_START 0xB0001000
#define EXE_SIZE 0x00100004