unsigned long decomp_dac(unsigned char *srcp, unsigned long srcl, unsigned char *desp, unsigned long desl) { if (strncmp((char *)srcp, "EZPK", 4)) return 0; unsigned long ul = GetDwordLE(srcp + 4); if (desl == 0) return ul & 0xfffffff; if ((ul & 0xf0000000) == 0) { unsigned int ui = desl; if (BZ2_bzBuffToBuffDecompress((char *)desp, &ui, (char *)(srcp + 8), srcl, 0, 0) < 0) return 0; return desl; } else { z_stream zs; memset(&zs, 0, sizeof(z_stream)); zs.next_in = (Bytef *)(srcp + 8); zs.avail_in = srcl - 8; zs.next_out = (Bytef *)desp; zs.avail_out = desl; if ((inflateInit(&zs)) < 0) return 0; if ((inflate(&zs, Z_FINISH)) >= 0) ul = zs.total_out; else ul = 0; inflateEnd(&zs); return ul; } }
void VRC7SetTone(Uint8 *p, Uint type) { extern void OPLLSetTone(Uint8 *p, Uint32 type); switch (type) { case 1: if ((GetDwordLE(p) & 0xf0ffffff) == GetDwordLEM("ILL0")) XMEMCPY(usertone[0], p, 16 * 19); else XMEMCPY(usertone[0], p, 8 * 15); usertone_enable[0] = 1; break; case 2: OPLLSetTone(p, 0); break; case 3: OPLLSetTone(p, 1); break; } }
Uint NSDPlayerInstall(Uint8 *pData, Uint uSize) { nsdplayer.sync1 = pData[7]; nsdplayer.sync2 = GetDwordLE(pData + 0x08); nsdplayer.top = XMALLOC(GetDwordLE(pData + 0x30)); if (!nsdplayer.top) return NESERR_SHORTOFMEMORY; XMEMCPY(nsdplayer.top, pData + GetDwordLE(pData + 0x38), GetDwordLE(pData + 0x30)); if (GetDwordLE(pData + 0x3C)) { nsdplayer.loop = nsdplayer.top + GetDwordLE(pData + 0x3C) - GetDwordLE(pData + 0x38); } else { nsdplayer.loop = 0; } NESAudioHandlerInstall(nsdplay_audio_handler); NESResetHandlerInstall(nsdplay_reset_handler); NESTerminateHandlerInstall(nsdplay_terminate_handler); NSDPLAYReset(); return NESERR_NOERROR; }
int input_gym::load_ezpk_gym(void *gymFile) { unsigned int unezbuf_l = gym_tag -> compressed + 0x24; gym_start = new unsigned char[unezbuf_l]; if (!gym_start) { gym_backup.set_size(0); gym_tag = 0; return 0; } unsigned char *unezbuf_v = new unsigned char[unezbuf_l]; if (!unezbuf_v) { delete[] gym_start; gym_backup.set_size(0); gym_tag = 0; return 0; } int bzerr = BZ2_bzBuffToBuffDecompress((char *)unezbuf_v, &unezbuf_l, (char *)gymFile + sizeof(GYMTAG) + 8, gym_backup.get_size() - sizeof(GYMTAG) - 8, 0, 0); if(bzerr != BZ_OK) { delete[] unezbuf_v; delete[] gym_start; gym_backup.set_size(0); gym_start = 0; gym_tag = 0; return 0; } unsigned long undacbuf_l = GetDwordLE(&unezbuf_v[0x18]) + GetDwordLE(&unezbuf_v[0x1c]); if (undacbuf_l > 0) //>= 100) { unsigned char *undacbuf_v = new unsigned char[undacbuf_l]; if (!undacbuf_v) { delete[] unezbuf_v; delete[] gym_start; gym_backup.set_size(0); gym_start = 0; gym_tag = 0; return 0; } unsigned long ret = decomp_dac(&unezbuf_v[GetDwordLE(&unezbuf_v[0x20])],GetDwordLE(&unezbuf_v[0x14]), &undacbuf_v[0], undacbuf_l); if (ret) memcpy(&unezbuf_v[GetDwordLE(&unezbuf_v[0x20])], &undacbuf_v[0], ret); delete[] undacbuf_v; } unsigned char *typep, *sngp, *regp, *datmp, *datsp, *dacmp, *dacsp; { unsigned char *p1; p1 = &unezbuf_v[0x24]; typep = p1; p1 += GetDwordLE(&unezbuf_v[0x00]); regp = p1; p1 += GetDwordLE(&unezbuf_v[0x04]); datmp = p1; p1 += GetDwordLE(&unezbuf_v[0x08]); datsp = p1; p1 += GetDwordLE(&unezbuf_v[0x0c]); sngp = p1; p1 += GetDwordLE(&unezbuf_v[0x10]); dacmp = p1; p1 += GetDwordLE(&unezbuf_v[0x18]); dacsp = p1; } unsigned idx = 0; do { unsigned char uc; gym_start[idx++] = uc = *(typep++); switch (uc) { case 1: gym_start[idx++] = uc = *(regp++); if (uc == 0x2a && undacbuf_l > 0) gym_start[idx++] = *(dacmp++); else gym_start[idx++] = *(datmp++); break; case 2: gym_start[idx++] = uc = *(regp++); if (uc == 0x2a && undacbuf_l > 0) gym_start[idx++] = *(dacsp++); else gym_start[idx++] = *(datsp++); break; case 3: gym_start[idx++] = *(sngp++); break; } } while (idx < gym_tag -> compressed); delete[] unezbuf_v; gym_size = gym_tag -> compressed; return 1; }