void Patch_FfsModule(u32 version) { switch (version) { /** 12/24/08 13:48:17 **/ case 0x49523DA1: /* Permissions check */ Write8(0x200012F2, 0xE0); break; /** 12/23/09 17:26:21 **/ case 0x49511F3D: /* Permissions check */ Write8(0x2000347E, 0xE0); break; /** 11/24/08 15:36:10 **/ case 0x492AC9EA: /* Permissions check */ Write8(0x20001306, 0xE0); break; } }
static void write_movie_header(FILE* fd, const SMovie* movie) { uint8 header[SMV_HEADER_SIZE]; uint8* ptr=header; Write32(SMV_MAGIC, ptr); Write32(SMV_VERSION, ptr); Write32(movie->MovieId, ptr); Write32(movie->RerecordCount, ptr); Write32(movie->MaxFrame, ptr); Write8(movie->ControllersMask, ptr); Write8(movie->Opts, ptr); Write8(movie->SyncFlags2, ptr); // previously reserved byte Write8(movie->SyncFlags, ptr); // previously reserved byte Write32(movie->SaveStateOffset, ptr); Write32(movie->ControllerDataOffset, ptr); assert(ptr-header==SMV_HEADER_SIZE); fwrite(header, 1, SMV_HEADER_SIZE, fd); assert(!ferror(fd)); }
void kexBinFile::WriteString(const kexStr &val) { const char *c = val.c_str(); for(int i = 0; i < val.Length(); i++) { Write8(c[i]); } Write8(0); }
void kexBinFile::Write32(const int val) { Write8(val & 0xff); Write8((val >> 8) & 0xff); Write8((val >> 16) & 0xff); Write8((val >> 24) & 0xff); }
void PrepareTestEnvironment(const CGameTestSheet::EnvironmentActionArray& environment) { //TODO: There's a bug if there's a slash at the end of the path for the memory card auto mcPathPreference = Iop::CMcServ::GetMcPathPreference(0); auto memoryCardPath = boost::filesystem::path("./memorycard"); boost::filesystem::remove_all(memoryCardPath); CAppConfig::GetInstance().RegisterPreferencePath(mcPathPreference, ""); CAppConfig::GetInstance().SetPreferencePath(mcPathPreference, memoryCardPath); for(const auto& environmentAction : environment) { if(environmentAction.type == CGameTestSheet::ENVIRONMENT_ACTION_CREATE_DIRECTORY) { auto folderToCreate = memoryCardPath / boost::filesystem::path(environmentAction.name); Framework::PathUtils::EnsurePathExists(folderToCreate); } else if(environmentAction.type == CGameTestSheet::ENVIRONMENT_ACTION_CREATE_FILE) { auto fileToCreate = memoryCardPath / boost::filesystem::path(environmentAction.name); auto inputStream = Framework::CreateOutputStdStream(fileToCreate.native()); inputStream.Seek(environmentAction.size - 1, Framework::STREAM_SEEK_SET); inputStream.Write8(0x00); } } }
/// reads unsigned int void Write32(unsigned int ui) { Write8(static_cast<unsigned char>(ui & 0x000000ff)); Write8(static_cast<unsigned char>((ui >> 8)& 0x000000ff)); Write8(static_cast<unsigned char>((ui >> 16)& 0x000000ff)); Write8(static_cast<unsigned char>((ui >> 24)& 0x000000ff)); }
void WriteEhdr(const fs::file& f, Elf32_Ehdr& ehdr) { Write32(f, ehdr.e_magic); Write8(f, ehdr.e_class); Write8(f, ehdr.e_data); Write8(f, ehdr.e_curver); Write8(f, ehdr.e_os_abi); Write64(f, ehdr.e_abi_ver); Write16(f, ehdr.e_type); Write16(f, ehdr.e_machine); Write32(f, ehdr.e_version); Write32(f, ehdr.e_entry); Write32(f, ehdr.e_phoff); Write32(f, ehdr.e_shoff); Write32(f, ehdr.e_flags); Write16(f, ehdr.e_ehsize); Write16(f, ehdr.e_phentsize); Write16(f, ehdr.e_phnum); Write16(f, ehdr.e_shentsize); Write16(f, ehdr.e_shnum); Write16(f, ehdr.e_shstrndx); }
void WriteBlock(const VAddr addr, const u8* data, const size_t size) { u32 offset = 0; while (offset < (size & ~3)) { Write32(addr + offset, *(u32*)&data[offset]); offset += 4; } if (size & 2) { Write16(addr + offset, *(u16*)&data[offset]); offset += 2; } if (size & 1) Write8(addr + offset, data[offset]); }
static void write_movie_header(FILE* fd, const SMovie* movie) { uint8 header[SMV_HEADER_SIZE]; uint8* ptr=header; Write32(SMV_MAGIC, ptr); Write32(SMV_VERSION, ptr); Write32(movie->MovieId, ptr); Write32(movie->RerecordCount, ptr); Write32(movie->MaxFrame, ptr); Write8(movie->ControllersMask, ptr); Write8(movie->Opts, ptr); Write8(0, ptr); // reserved byte Write8(movie->SyncFlags, ptr); Write32(movie->SaveStateOffset, ptr); Write32(movie->ControllerDataOffset, ptr); // not part of original v1 SMV format: Write32(movie->MaxSample, ptr); Write8(movie->PortType[0], ptr); Write8(movie->PortType[1], ptr); int i, p; for(p=0;p<2;p++) for(i=0;i<4;i++) Write8(movie->PortIDs[p][i], ptr); // 18 reserved bytes, could be anything, ignored by this version when reading for(i=0;i<18-4;i++) Write8(0, ptr); Write32(movie->RerecordCount/2, ptr); // why not... assert(ptr-header==SMV_HEADER_SIZE); fwrite(header, 1, SMV_HEADER_SIZE, fd); assert(!ferror(fd)); }
NS_IMETHODIMP nsBinaryOutputStream::WriteID(const nsIID& aIID) { nsresult rv = Write32(aIID.m0); NS_ENSURE_SUCCESS(rv, rv); rv = Write16(aIID.m1); NS_ENSURE_SUCCESS(rv, rv); rv = Write16(aIID.m2); NS_ENSURE_SUCCESS(rv, rv); for (int i = 0; i < 8; ++i) { rv = Write8(aIID.m3[i]); NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; }
NS_IMETHODIMP nsBinaryOutputStream::WriteID(const nsIID& aIID) { nsresult rv = Write32(aIID.m0); if (NS_WARN_IF(NS_FAILED(rv))) return rv; rv = Write16(aIID.m1); if (NS_WARN_IF(NS_FAILED(rv))) return rv; rv = Write16(aIID.m2); if (NS_WARN_IF(NS_FAILED(rv))) return rv; for (int i = 0; i < 8; ++i) { rv = Write8(aIID.m3[i]); if (NS_WARN_IF(NS_FAILED(rv))) return rv; } return NS_OK; }
/** \fn EndAndPaddTilleSizeMatchesAviListAvi \brief Warning we assume everything is even */ bool AviListAvi::EndAndPaddTilleSizeMatches(int sizeFilled) { uint64_t pos=Tell(); // Current position uint64_t start=TellBegin()+8; // Payload start uint64_t end=start+sizeFilled; // Next chunk if(pos&1) ADM_backTrack("[AVI]CHUNK is at a even position",__LINE__,__FILE__); if(pos+8>end) { ADM_error("No space to add junk chunk ( %d, filler=%d)\n",(int)pos-start,sizeFilled); if(end<=pos) { ADM_error("CHUNK OVERFLOW ( %d, filler=%d)\n",(int)pos-start,sizeFilled); ADM_error("CHUNK OVERFLOW ( %d, filler=%d)\n",(int)pos-start,sizeFilled); ADM_error("CHUNK OVERFLOW ( %d, filler=%d)\n",(int)pos-start,sizeFilled); ADM_error("CHUNK OVERFLOW ( %d, filler=%d)\n",(int)pos-start,sizeFilled); ADM_backTrack("CHUNK overflow",__LINE__,__FILE__); return false; } int left=(int)(end-pos); for(int i=0;i<left;i++) Write8(0); // we dont have enough space to put a junk() End(); return true; } End(); uint64_t left=end-8-pos; AviListAvi junk("JUNK",getFile()); junk.Begin(); for(int i=0;i<left;i++) // Inefficient, but can be fairly large junk.Write8(0); junk.End(); return true; }
int main(int argc, char** argv) { int zip_mode = 0; if (argc >= 2 && strcmp(argv[1], "-z") == 0) { zip_mode = 1; --argc; ++argv; } size_t bonus_size = 0; unsigned char* bonus_data = NULL; if (argc >= 3 && strcmp(argv[1], "-b") == 0) { struct stat st; if (stat(argv[2], &st) != 0) { printf("failed to stat bonus file %s: %s\n", argv[2], strerror(errno)); return 1; } bonus_size = st.st_size; bonus_data = malloc(bonus_size); FILE* f = fopen(argv[2], "rb"); if (f == NULL) { printf("failed to open bonus file %s: %s\n", argv[2], strerror(errno)); return 1; } if (fread(bonus_data, 1, bonus_size, f) != bonus_size) { printf("failed to read bonus file %s: %s\n", argv[2], strerror(errno)); return 1; } fclose(f); argc -= 2; argv += 2; } if (argc != 4) { usage: printf("usage: %s [-z] [-b <bonus-file>] <src-img> <tgt-img> <patch-file>\n", argv[0]); return 2; } int num_src_chunks; ImageChunk* src_chunks; int num_tgt_chunks; ImageChunk* tgt_chunks; int i; if (zip_mode) { if (ReadZip(argv[1], &num_src_chunks, &src_chunks, 1) == NULL) { printf("failed to break apart source zip file\n"); return 1; } if (ReadZip(argv[2], &num_tgt_chunks, &tgt_chunks, 0) == NULL) { printf("failed to break apart target zip file\n"); return 1; } } else { if (ReadImage(argv[1], &num_src_chunks, &src_chunks) == NULL) { printf("failed to break apart source image\n"); return 1; } if (ReadImage(argv[2], &num_tgt_chunks, &tgt_chunks) == NULL) { printf("failed to break apart target image\n"); return 1; } // Verify that the source and target images have the same chunk // structure (ie, the same sequence of deflate and normal chunks). if (!zip_mode) { // Merge the gzip header and footer in with any adjacent // normal chunks. MergeAdjacentNormalChunks(tgt_chunks, &num_tgt_chunks); MergeAdjacentNormalChunks(src_chunks, &num_src_chunks); } if (num_src_chunks != num_tgt_chunks) { printf("source and target don't have same number of chunks!\n"); printf("source chunks:\n"); DumpChunks(src_chunks, num_src_chunks); printf("target chunks:\n"); DumpChunks(tgt_chunks, num_tgt_chunks); return 1; } for (i = 0; i < num_src_chunks; ++i) { if (src_chunks[i].type != tgt_chunks[i].type) { printf("source and target don't have same chunk " "structure! (chunk %d)\n", i); printf("source chunks:\n"); DumpChunks(src_chunks, num_src_chunks); printf("target chunks:\n"); DumpChunks(tgt_chunks, num_tgt_chunks); return 1; } } } for (i = 0; i < num_tgt_chunks; ++i) { if (tgt_chunks[i].type == CHUNK_DEFLATE) { // Confirm that given the uncompressed chunk data in the target, we // can recompress it and get exactly the same bits as are in the // input target image. If this fails, treat the chunk as a normal // non-deflated chunk. if (ReconstructDeflateChunk(tgt_chunks+i) < 0) { printf("failed to reconstruct target deflate chunk %d [%s]; " "treating as normal\n", i, tgt_chunks[i].filename); ChangeDeflateChunkToNormal(tgt_chunks+i); if (zip_mode) { ImageChunk* src = FindChunkByName(tgt_chunks[i].filename, src_chunks, num_src_chunks); if (src) { ChangeDeflateChunkToNormal(src); } } else { ChangeDeflateChunkToNormal(src_chunks+i); } continue; } // If two deflate chunks are identical (eg, the kernel has not // changed between two builds), treat them as normal chunks. // This makes applypatch much faster -- it can apply a trivial // patch to the compressed data, rather than uncompressing and // recompressing to apply the trivial patch to the uncompressed // data. ImageChunk* src; if (zip_mode) { src = FindChunkByName(tgt_chunks[i].filename, src_chunks, num_src_chunks); } else { src = src_chunks+i; } if (src == NULL || AreChunksEqual(tgt_chunks+i, src)) { ChangeDeflateChunkToNormal(tgt_chunks+i); if (src) { ChangeDeflateChunkToNormal(src); } } } } // Merging neighboring normal chunks. if (zip_mode) { // For zips, we only need to do this to the target: deflated // chunks are matched via filename, and normal chunks are patched // using the entire source file as the source. MergeAdjacentNormalChunks(tgt_chunks, &num_tgt_chunks); } else { // For images, we need to maintain the parallel structure of the // chunk lists, so do the merging in both the source and target // lists. MergeAdjacentNormalChunks(tgt_chunks, &num_tgt_chunks); MergeAdjacentNormalChunks(src_chunks, &num_src_chunks); if (num_src_chunks != num_tgt_chunks) { // This shouldn't happen. printf("merging normal chunks went awry\n"); return 1; } } // Compute bsdiff patches for each chunk's data (the uncompressed // data, in the case of deflate chunks). DumpChunks(src_chunks, num_src_chunks); printf("Construct patches for %d chunks...\n", num_tgt_chunks); unsigned char** patch_data = malloc(num_tgt_chunks * sizeof(unsigned char*)); size_t* patch_size = malloc(num_tgt_chunks * sizeof(size_t)); for (i = 0; i < num_tgt_chunks; ++i) { if (zip_mode) { ImageChunk* src; if (tgt_chunks[i].type == CHUNK_DEFLATE && (src = FindChunkByName(tgt_chunks[i].filename, src_chunks, num_src_chunks))) { patch_data[i] = MakePatch(src, tgt_chunks+i, patch_size+i); } else { patch_data[i] = MakePatch(src_chunks, tgt_chunks+i, patch_size+i); } } else { if (i == 1 && bonus_data) { printf(" using %zu bytes of bonus data for chunk %d\n", bonus_size, i); src_chunks[i].data = realloc(src_chunks[i].data, src_chunks[i].len + bonus_size); memcpy(src_chunks[i].data+src_chunks[i].len, bonus_data, bonus_size); src_chunks[i].len += bonus_size; } patch_data[i] = MakePatch(src_chunks+i, tgt_chunks+i, patch_size+i); } printf("patch %3d is %zd bytes (of %zd)\n", i, patch_size[i], tgt_chunks[i].source_len); } // Figure out how big the imgdiff file header is going to be, so // that we can correctly compute the offset of each bsdiff patch // within the file. size_t total_header_size = 12; for (i = 0; i < num_tgt_chunks; ++i) { total_header_size += 4; switch (tgt_chunks[i].type) { case CHUNK_NORMAL: total_header_size += 8*4; break; case CHUNK_DEFLATE: total_header_size += 8*6 + 4*5; break; case CHUNK_RAW: total_header_size += 4 + patch_size[i]; break; } } size_t offset = total_header_size; FILE* f = fopen(argv[3], "wb"); // Write out the headers. fwrite("IMGDIFFX", 1, 8, f); Write4(num_tgt_chunks, f); for (i = 0; i < num_tgt_chunks; ++i) { Write4(tgt_chunks[i].type, f); switch (tgt_chunks[i].type) { case CHUNK_NORMAL: printf("chunk %3d: normal (%10zd, %10zd) %10zd\n", i, tgt_chunks[i].start, tgt_chunks[i].len, patch_size[i]); Write8(tgt_chunks[i].source_start, f); Write8(tgt_chunks[i].source_len, f); Write8(offset, f); Write8(patch_size[i], f); offset += patch_size[i]; break; case CHUNK_DEFLATE: printf("chunk %3d: deflate (%10zd, %10zd) %10zd %s\n", i, tgt_chunks[i].start, tgt_chunks[i].deflate_len, patch_size[i], tgt_chunks[i].filename); Write8(tgt_chunks[i].source_start, f); Write8(tgt_chunks[i].source_len, f); Write8(offset, f); Write8(patch_size[i], f); Write8(tgt_chunks[i].source_uncompressed_len, f); Write8(tgt_chunks[i].len, f); Write4(tgt_chunks[i].level, f); Write4(tgt_chunks[i].method, f); Write4(tgt_chunks[i].windowBits, f); Write4(tgt_chunks[i].memLevel, f); Write4(tgt_chunks[i].strategy, f); offset += patch_size[i]; break; case CHUNK_RAW: printf("chunk %3d: raw (%10zd, %10zd)\n", i, tgt_chunks[i].start, tgt_chunks[i].len); Write4(patch_size[i], f); fwrite(patch_data[i], 1, patch_size[i], f); break; } } // Append each chunk's bsdiff patch, in order. for (i = 0; i < num_tgt_chunks; ++i) { if (tgt_chunks[i].type != CHUNK_RAW) { fwrite(patch_data[i], 1, patch_size[i], f); } } fclose(f); return 0; }
NS_IMETHODIMP nsBinaryOutputStream::WriteBoolean(PRBool aBoolean) { return Write8(aBoolean); }
/// reads unsigned short void Write16(unsigned short us) { Write8(static_cast<unsigned char>(us & 0x00ff)); // low byte Write8(static_cast<unsigned char>((us >> 8)& 0x00ff)); // high byte }
void setWildPokemonfromAddress( u32 pokemonAddress, u32 pokemonVariation, u32 pokemonLevel, bool enableObtainedCheck, bool updatePokeRadar) { if (PointerOffset != 0x00) { unsigned int ZOOffset = Read32(PointerOffset); //Check for valid pointer if ((ZOOffset >= 0x08000000) && (ZOOffset < 0x08DF0000)) { //Check if ZO File contains encounter data if (Read32(ZOOffset + 0x10) != Read32(ZOOffset + 0x14)) { unsigned int EncOffset = ZOOffset + Read32(ZOOffset + 0x10) + ByteJump; int i; int pokemon=1; u32 currentEncOffset; for (i = 0; i < EncDataLength; i += 4) { if (Read8(EncOffset + i + 2) != 0x01) { currentEncOffset=EncOffset+i; //setPokemon if(pokemonAddress>1) pokemon=Read16(pokemonAddress); else if(pokemonAddress==1) pokemon=GetRandomPokemon(enableObtainedCheck); else pokemon=Read16(currentEncOffset); //setPokemonVariation if(pokemonVariation>1) pokemon+=0x800 *(Read16(pokemonVariation)-1); else if(pokemonVariation==1) pokemon=getRandomVariation(pokemon); //setPokemonLevel if(pokemonLevel>1) { u8 level=Read8(pokemonLevel); if(level<2) level=2; Write8(currentEncOffset+2, level); } else if(pokemonLevel==1) Write8(currentEncOffset+2, RandMinMax(2,100)); //Write8(EncOffset + i+3, 1); //maybefiller? Write16(currentEncOffset, pokemon); } } //Update DexNav if(updatePokeRadar&&curEdition==ORAS) { int j; for (i = 0; i < 96; i++) { for (j = 0; j < EncDataLength; j += 4) { Write32(0x16B3E7B6 + (0x104 * i) + j, Read32(EncOffset + j)); } } } } } } }
int main(int argc, char** argv) { if (argc != 4) { fprintf(stderr, "usage: %s <src-img> <tgt-img> <patch-file>\n", argv[0]); return 2; } int num_src_chunks; ImageChunk* src_chunks; if (ReadImage(argv[1], &num_src_chunks, &src_chunks) == NULL) { fprintf(stderr, "failed to break apart source image\n"); return 1; } int num_tgt_chunks; ImageChunk* tgt_chunks; if (ReadImage(argv[2], &num_tgt_chunks, &tgt_chunks) == NULL) { fprintf(stderr, "failed to break apart target image\n"); return 1; } // Verify that the source and target images have the same chunk // structure (ie, the same sequence of gzip and normal chunks). if (num_src_chunks != num_tgt_chunks) { fprintf(stderr, "source and target don't have same number of chunks!\n"); return 1; } int i; for (i = 0; i < num_src_chunks; ++i) { if (src_chunks[i].type != tgt_chunks[i].type) { fprintf(stderr, "source and target don't have same chunk " "structure! (chunk %d)\n", i); return 1; } } // Confirm that given the uncompressed chunk data in the target, we // can recompress it and get exactly the same bits as are in the // input target image. If this fails, treat the chunk as a normal // non-gzipped chunk. for (i = 0; i < num_tgt_chunks; ++i) { if (tgt_chunks[i].type == CHUNK_GZIP) { if (ReconstructGzipChunk(tgt_chunks+i) < 0) { printf("failed to reconstruct target gzip chunk %d; " "treating as normal chunk\n", i); ChangeGzipChunkToNormal(tgt_chunks+i); ChangeGzipChunkToNormal(src_chunks+i); } else { printf("reconstructed target gzip chunk %d\n", i); } } } // Compute bsdiff patches for each chunk's data (the uncompressed // data, in the case of gzip chunks). unsigned char** patch_data = malloc(num_src_chunks * sizeof(unsigned char*)); size_t* patch_size = malloc(num_src_chunks * sizeof(size_t)); for (i = 0; i < num_src_chunks; ++i) { patch_data[i] = MakePatch(src_chunks+i, tgt_chunks+i, patch_size+i); printf("patch %d is %d bytes (of %d)\n", i, patch_size[i], tgt_chunks[i].type == CHUNK_NORMAL ? tgt_chunks[i].len : tgt_chunks[i].gzip_len); } // Figure out how big the imgdiff file header is going to be, so // that we can correctly compute the offset of each bsdiff patch // within the file. size_t total_header_size = 12; for (i = 0; i < num_src_chunks; ++i) { total_header_size += 4 + 8*3; if (src_chunks[i].type == CHUNK_GZIP) { total_header_size += 8*2 + 4*6 + tgt_chunks[i].gzip_header_len + 8; } } size_t offset = total_header_size; FILE* f = fopen(argv[3], "wb"); // Write out the headers. fwrite("IMGDIFF1", 1, 8, f); Write4(num_src_chunks, f); for (i = 0; i < num_tgt_chunks; ++i) { Write4(tgt_chunks[i].type, f); Write8(src_chunks[i].start, f); Write8(src_chunks[i].type == CHUNK_NORMAL ? src_chunks[i].len : (src_chunks[i].gzip_len + src_chunks[i].gzip_header_len + 8), f); Write8(offset, f); if (tgt_chunks[i].type == CHUNK_GZIP) { Write8(src_chunks[i].len, f); Write8(tgt_chunks[i].len, f); Write4(tgt_chunks[i].level, f); Write4(tgt_chunks[i].method, f); Write4(tgt_chunks[i].windowBits, f); Write4(tgt_chunks[i].memLevel, f); Write4(tgt_chunks[i].strategy, f); Write4(tgt_chunks[i].gzip_header_len, f); fwrite(tgt_chunks[i].gzip_header, 1, tgt_chunks[i].gzip_header_len, f); fwrite(tgt_chunks[i].gzip_footer, 1, GZIP_FOOTER_LEN, f); } offset += patch_size[i]; } // Append each chunk's bsdiff patch, in order. for (i = 0; i < num_tgt_chunks; ++i) { fwrite(patch_data[i], 1, patch_size[i], f); } fclose(f); return 0; }
bool MemoryBase::Write8NN(u64 addr, const u8 data) { if(!IsGoodAddr(addr)) return false; Write8(addr, data); return true; }
void Patch_EsModule(u32 version) { switch (version) { /** 06/03/09 03:45:06 **/ case 0x4A25F1C2: /* Signature check */ Write16(0x13A752E6, 0x2000); /* Identify check */ Write16(0x20100D4A, 0x2803); Write16(0x20100DC2, 0x2803); /* Open content permissions */ Write8(0x20104D7A, 0xE0); Write8(0x20104D9E, 0xE0); Write8(0x20104DC2, 0xE0); /* Read content permissions */ Write16(0x20104EBC, 0x46C0); Write16(0x20104EC0, 0x46C0); Write8 (0x20104EC4, 0xE0); /* Close content permissions */ Write16(0x20104F58, 0x46C0); Write16(0x20104F5C, 0x46C0); Write8 (0x20104F60, 0xE0); /* Set UID check */ Write16(0x2010522A, 0x46C0); /* Title version check */ Write8(0x201027AC, 0xE0); /* Title delete check */ Write8(0x20107B22, 0xE0); break; /** 06/03/09 03:36:55 **/ case 0x4A25EFD7: /* Signature check */ Write16(0x13A750A6, 0x2000); /* Identify check */ Write16(0x20100CC8, 0x2803); Write16(0x20100D40, 0x2803); /* Open content permissions */ Write8(0x20104B68, 0xE0); Write8(0x20104B8C, 0xE0); /* Read content permissions */ Write16(0x20104C84, 0x46C0); Write16(0x20104C88, 0x46C0); Write8 (0x20104C8C, 0xE0); /* Close content permissions */ Write16(0x20104D20, 0x46C0); Write16(0x20104D24, 0x46C0); Write8 (0x20104D28, 0xE0); /* Set UID check */ Write16(0x20104FF2, 0x46C0); /* Title version check */ Write8(0x20102724, 0xE0); /* Title delete check */ Write8(0x20107682, 0xE0); break; /** 06/03/09 07:46:02 **/ case 0x4A262A3A: /* Signature check */ Write16(0x13A75626, 0x2000); /* Identify check */ Write16(0x20100E74, 0x2803); Write16(0x20100EEC, 0x2803); /* Open content permissions */ Write8(0x20105290, 0xE0); Write8(0x201052D0, 0xE0); Write8(0x201052F4, 0xE0); /* Read content permissions */ Write16(0x201053FC, 0x46C0); Write16(0x20105400, 0x46C0); Write8 (0x20105404, 0xE0); /* Close content permissions */ Write16(0x20105498, 0x46C0); Write16(0x2010549C, 0x46C0); Write8 (0x201054A0, 0xE0); /* Set UID check */ Write16(0x2010576A, 0x46C0); /* Title version check */ Write8(0x20102C74, 0xE0); /* Title delete check */ Write8(0x2010849A, 0xE0); /* Decrypt check */ Write8(0x2010650C, 0xE0); break; /** 11/24/08 15:36:08 **/ case 0x492AC9E8: /* Signature check */ Write16(0x13A754FA, 0x2000); Write16(0x13A756A6, 0x2000); /* Identify check */ Write16(0x20100DA4, 0x2803); Write16(0x20100E1C, 0x2803); /* Open content permissions */ Write8(0x20104D60, 0xE0); Write8(0x20104DA0, 0xE0); Write8(0x20104DC4, 0xE0); /* Read content permissions */ Write16(0x20104ECC, 0x46C0); Write16(0x20104ED0, 0x46C0); Write8 (0x20104ED4, 0xE0); /* Close content permissions */ Write16(0x20104F68, 0x46C0); Write16(0x20104F6C, 0x46C0); Write8 (0x20104F70, 0xE0); /* Set UID check */ Write16(0x2010523A, 0x46C0); /* Title version check */ Write8(0x20102800, 0xE0); /* Title delete check */ Write8(0x20107B32, 0xE0); /* Decrypt check */ Write8(0x20105FD0, 0xE0); break; /** 03/03/10 10:40:14 **/ case 0x4B8E90EE: /* Signature check */ Write16(0x13A75626, 0x2000); /* Identify check */ Write16(0x20100E74, 0x2803); Write16(0x20100EEC, 0x2803); /* Open content permissions */ Write8(0x201052E4, 0xE0); Write8(0x20105324, 0xE0); Write8(0x20105348, 0xE0); /* Read content permissions */ Write16(0x20105450, 0x46C0); Write16(0x20105454, 0x46C0); Write8 (0x20105458, 0xE0); /* Close content permissions */ Write16(0x201054A0, 0x46C0); Write16(0x201054A4, 0x46C0); Write8 (0x201054A8, 0xE0); /* Set UID check */ Write16(0x201057BE, 0x46C0); /* Title version check */ Write8(0x20102CB8, 0xE0); /* Title delete check */ Write8(0x20108562, 0xE0); break; /** 03/01/10 03:26:03 **/ case 0x4B8B882B: /* Signature check */ Write16(0x13A752E6, 0x2000); /* Identify check */ Write16(0x20100D46, 0x2803); Write16(0x20100DBE, 0x2803); /* Open content permissions */ Write8(0x20104DF6, 0xE0); Write8(0x20104E1A, 0xE0); Write8(0x20104E3E, 0xE0); /* Read content permissions */ Write16(0x20104F38, 0x46C0); Write16(0x20104F3C, 0x46C0); Write8 (0x20104F40, 0xE0); /* Close content permissions */ Write16(0x20104F88, 0x46C0); Write16(0x20104F8C, 0x46C0); Write8 (0x20104F90, 0xE0); /* Set UID check */ Write16(0x201052A6, 0x46C0); /* Title version check */ Write8(0x20102818, 0xE0); /* Title delete check */ Write8(0x20107BAA, 0xE0); break; /** 03/01/10 03:18:58 **/ case 0x4B8B8682: /* Signature check */ Write16(0x13A75266, 0x2000); /* Identify check */ Write16(0x20100CC4, 0x2803); Write16(0x20100D3C, 0x2803); /* Open content permissions */ Write8(0x20104B20, 0xE0); Write8(0x20104B44, 0xE0); /* Read content permissions */ Write16(0x20104C3C, 0x46C0); Write16(0x20104C40, 0x46C0); Write8 (0x20104C44, 0xE0); /* Close content permissions */ Write16(0x20104C8C, 0x46C0); Write16(0x20104C90, 0x46C0); Write8 (0x20104C94, 0xE0); /* Set UID check */ Write16(0x20104FAA, 0x46C0); /* Title version check */ Write8(0x201026CC, 0xE0); /* Title delete check */ Write8(0x20107642, 0xE0); break; } }
void kexBinFile::Write16(const short val) { Write8(val & 0xff); Write8((val >> 8) & 0xff); }
void Io::Write16 (uint32_t add, uint16_t val) { //debug ("IO Write16 at " << IOS_ADD << add << " of " << IOS_ADD << val); //*(uint16_t*)(m_iomem + (add & 0xFFF)) = val; switch (add & 0xFFF) { case KEYINPUT: case VCOUNT: break; case DMA0CNT_L: case DMA1CNT_L: case DMA2CNT_L: case DMA3CNT_L: //W16(add, val); DMA.SetReload(((add & 0xFFF) - DMA0CNT_L) / DMA_CHANSIZE, val); break; case KEYCNT: W16(add, val & 0xC3FF); break; case IME: W16(add, val & 0x0001); CPU.CheckInterrupt(); break; case IE: W16(add, val & 0x3FFF); CPU.CheckInterrupt(); break; case IF: *((uint16_t*)(m_iomem+IF)) ^= (val & (*((uint16_t*)(m_iomem+IF)))); CPU.CheckInterrupt(); break; case BG0CNT: W16(add, val & 0xFFCF); LCD.UpdateBg0Cnt(val & 0xFFCF); break; case BG1CNT: W16(add, val & 0xFFCF); LCD.UpdateBg1Cnt(val & 0xFFCF); break; case BG2CNT: W16(add, val & 0xFFCF); LCD.UpdateBg2Cnt(val & 0xFFCF); break; case BG3CNT: W16(add, val & 0xFFCF); LCD.UpdateBg3Cnt(val & 0xFFCF); break; case DISPSTAT: // the first 3 bits are read only and they are used by the lcd // NOTE : we are in LITTLE ENDIAN // FIXME : if vcount setting has changed to current vcount, we should // update the vcounter flag and eventually trigger an interrupt W16(add, (val & 0xFFF8) | (m_iomem[add & 0xFFF] & 0x07)); break; // The BG*OFS are write-only, we don't need to W16() // You do if you're ever going to load them from a savestate... case BG0HOFS: W16(add, val & 0x1FF); LCD.UpdateBg0XOff(val & 0x1FF); break; case BG0VOFS: W16(add, val & 0x1FF); LCD.UpdateBg0YOff(val & 0x1FF); break; case BG1HOFS: W16(add, val & 0x1FF); LCD.UpdateBg1XOff(val & 0x1FF); break; case BG1VOFS: W16(add, val & 0x1FF); LCD.UpdateBg1YOff(val & 0x1FF); break; case BG2HOFS: W16(add, val & 0x1FF); LCD.UpdateBg2XOff(val & 0x1FF); break; case BG2VOFS: W16(add, val & 0x1FF); LCD.UpdateBg2YOff(val & 0x1FF); break; case BG3HOFS: W16(add, val & 0x1FF); LCD.UpdateBg3XOff(val & 0x1FF); break; case BG3VOFS: W16(add, val & 0x1FF); LCD.UpdateBg3YOff(val & 0x1FF); break; case BG2X_H: val &= 0x0FFF; case BG2X_L: W16(add, val); LCD.UpdateBg2RefX(IO.DRead32(Io::BG2X_L)); break; case BG2Y_H: val &= 0x0FFF; case BG2Y_L: W16(add, val); LCD.UpdateBg2RefY(IO.DRead32(Io::BG2Y_L)); break; case BG3X_H: val &= 0x0FFF; case BG3X_L: W16(add, val); LCD.UpdateBg3RefX(IO.DRead32(Io::BG3X_L)); break; case BG3Y_H: val &= 0x0FFF; case BG3Y_L: W16(add, val); LCD.UpdateBg3RefY(IO.DRead32(Io::BG3Y_L)); break; case WIN0H: case WIN1H: case WIN0V: case WIN1V: case WININ: case WINOUT: W16(add, val); break; case BLDCNT: W16(add, val); break; case MOSAIC: W16(add, val); break; case DISPCNT: W16(add, val); LCD.UpdateDispCnt(val); break; case DMA0CNT_H: case DMA1CNT_H: case DMA2CNT_H: case DMA3CNT_H: W16(add, val & 0xFFE0); DMA.UpdateCnt(((add & 0xFFF) - DMA0CNT_H) / DMA_CHANSIZE); break; case WAITCNT: W16(add, val & 0xDFFF); MEM.UpdateWaitStates (val & 0xDFFF); break; case SOUND1CNT_L: case SOUND1CNT_H: case SOUND1CNT_X: case SOUND2CNT_L: case SOUND2CNT_H: case SOUND4CNT_L: case SOUND4CNT_H: case SOUNDCNT_L: case SOUNDCNT_H: case SOUNDCNT_X: case POSTFLG: Write8(add, val & 0xFF); Write8(add + 1, val >> 8); break; case TM0CNT_L: TIMER0.SetReload(val); break; case TM1CNT_L: TIMER1.SetReload(val); break; case TM2CNT_L: TIMER2.SetReload(val); break; case TM3CNT_L: TIMER3.SetReload(val); break; case TM0CNT_H: W16(add, val & 0x00C7); TIMER0.Reload(); break; case TM1CNT_H: W16(add, val & 0x00C7); TIMER1.Reload(); break; case TM2CNT_H: W16(add, val & 0x00C7); TIMER2.Reload(); break; case TM3CNT_H: W16(add, val & 0x00C7); TIMER3.Reload(); break; default: //met_abort("Unknown IO at " << IOS_ADD << add); W16(add, val); break; } }