From df6dfccd08ed7344b77f8e64ffcf150659bff0a7 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 18 Nov 2021 03:35:39 +0100 Subject: [PATCH] Cleanups --- libretro.cpp | 6 - mednafen/Stream.h | 2 - mednafen/cdrom/CDAFReader.h | 1 - mednafen/cdrom/CDAccess_CCD.cpp | 11 - mednafen/cdrom/CDAccess_CHD.cpp | 8 - mednafen/cdrom/CDAccess_Image.cpp | 28 - mednafen/cdrom/CDUtility.cpp | 11 - mednafen/cdrom/cdromif.cpp | 19 - mednafen/cdrom/galois.cpp | 8 - mednafen/cdrom/lec.cpp | 93 -- mednafen/cdrom/recover-raw.cpp | 7 +- mednafen/file.c | 1 - mednafen/hw_misc/arcade_card/arcade_card.cpp | 33 +- mednafen/mempatcher.cpp | 2 - mednafen/okiadpcm.cpp | 7 - mednafen/pce_fast/huc6280.c | 1 - mednafen/pce_fast/huc6280_ops.h | 11 +- mednafen/pce_fast/pcecd.cpp | 31 - mednafen/pce_fast/pcecd_drive.cpp | 31 - mednafen/pce_fast/psg.cpp | 18 - mednafen/pce_fast/vdc.c | 49 - mednafen/pce_fast/vdc.h | 6 - mednafen/state.c | 46 +- mednafen/state.h | 1 - mednafen/tremor/bitwise.c | 336 ------ mednafen/tremor/block.c | 1 - mednafen/tremor/framing.c | 1068 ------------------ mednafen/tremor/ivorbisfile.h | 1 - mednafen/tremor/mapping0.c | 1 - mednafen/tremor/synthesis.c | 1 - mednafen/tremor/vorbisfile.c | 18 +- 31 files changed, 32 insertions(+), 1825 deletions(-) diff --git a/libretro.cpp b/libretro.cpp index 508577f..7299431 100644 --- a/libretro.cpp +++ b/libretro.cpp @@ -677,13 +677,11 @@ static DECLFW(HuCSF2Write) static DECLFR(PCEBusRead) { - //printf("BUS Read: %02x %04x\n", A >> 13, A); return(0xFF); } static DECLFW(PCENullWrite) { - //printf("Null Write: %02x, %08x %02x\n", A >> 13, A, V); } static DECLFR(BaseRAMRead) @@ -1350,10 +1348,6 @@ extern "C" int StateAction(StateMem *sm, int load, int data_only) SFEND }; - //for(int i = 8192; i < 32768; i++) - // if(BaseRAM[i] != 0xFF) - // printf("%d %02x\n", i, BaseRAM[i]); - int ret = MDFNSS_StateAction(sm, load, data_only, StateRegs, "MAIN", false); ret &= HuC6280_StateAction(sm, load, data_only); diff --git a/mednafen/Stream.h b/mednafen/Stream.h index 7295cfb..4f20a38 100644 --- a/mednafen/Stream.h +++ b/mednafen/Stream.h @@ -6,8 +6,6 @@ // TODO?: BufferedStream, no virtual functions, yes inline functions, constructor takes a Stream* argument. #include - -#include // For SEEK_* defines, which we will use in Stream out of FORCE OF HABIT. #include #include "mednafen-types.h" diff --git a/mednafen/cdrom/CDAFReader.h b/mednafen/cdrom/CDAFReader.h index 51c7f94..16e63a4 100644 --- a/mednafen/cdrom/CDAFReader.h +++ b/mednafen/cdrom/CDAFReader.h @@ -37,7 +37,6 @@ class CDAFReader if(LastReadPos != frame_offset) { - //puts("SEEK"); if(!Seek_(frame_offset)) return(0); LastReadPos = frame_offset; diff --git a/mednafen/cdrom/CDAccess_CCD.cpp b/mednafen/cdrom/CDAccess_CCD.cpp index 69bf9d3..b26d06a 100644 --- a/mednafen/cdrom/CDAccess_CCD.cpp +++ b/mednafen/cdrom/CDAccess_CCD.cpp @@ -53,7 +53,6 @@ static T CCD_ReadInt(CCD_Section &s, const std::string &propname, const bool hav { if(have_defval) return defval; - printf("Missing property: %s", propname.c_str()); return 0; } @@ -77,10 +76,7 @@ static T CCD_ReadInt(CCD_Section &s, const std::string &propname, const bool hav ret = strtoul(vp, &ep, scan_base); if(!vp[0] || ep[0]) - { - printf("Property %s: Malformed integer: %s", propname.c_str(), v.c_str()); return 0; - } return ret; } @@ -140,8 +136,6 @@ bool CDAccess_CCD::Load(const std::string& path, bool image_memcache) } } - //printf("%s %d %d %d\n", file_ext.c_str(), extupt[0], extupt[1], extupt[2]); - linebuf.reserve(256); while(cf.get_line(linebuf) >= 0) @@ -208,8 +202,6 @@ bool CDAccess_CCD::Load(const std::string& path, bool image_memcache) return false; } - //printf("MOO: %d\n", toc_entries); - for(unsigned te = 0; te < toc_entries; te++) { char tmpbuf[64]; @@ -351,8 +343,6 @@ bool CDAccess_CCD::CheckSubQSanity(void) uint8_t as_bcd = buf.qbuf[8]; uint8_t af_bcd = buf.qbuf[9]; - //printf("%2x %2x %2x\n", am_bcd, as_bcd, af_bcd); - if(!BCD_is_valid(track_bcd) || !BCD_is_valid(index_bcd) || !BCD_is_valid(rm_bcd) || !BCD_is_valid(rs_bcd) || !BCD_is_valid(rf_bcd) || !BCD_is_valid(am_bcd) || !BCD_is_valid(as_bcd) || !BCD_is_valid(af_bcd) || rs_bcd > 0x59 || rf_bcd > 0x74 || as_bcd > 0x59 || af_bcd > 0x74) @@ -392,7 +382,6 @@ bool CDAccess_CCD::CheckSubQSanity(void) } } - //printf("%u/%u\n", checksum_pass_counter, img_numsectors); return true; } diff --git a/mednafen/cdrom/CDAccess_CHD.cpp b/mednafen/cdrom/CDAccess_CHD.cpp index 700fad7..24149ee 100644 --- a/mednafen/cdrom/CDAccess_CHD.cpp +++ b/mednafen/cdrom/CDAccess_CHD.cpp @@ -150,7 +150,6 @@ bool CDAccess_CHD::Load(const std::string &path, bool image_memcache) toc.tracks[NumTracks].lba = plba; fileOffset += Tracks[NumTracks].pregap_dv; - //printf("Tracks[%d].fileOffset=%d\n",NumTracks, fileOffset); Tracks[NumTracks].fileOffset = fileOffset; fileOffset += frames - Tracks[NumTracks].pregap_dv; fileOffset += Tracks[NumTracks].postgap; @@ -179,8 +178,6 @@ bool CDAccess_CHD::Load(const std::string &path, bool image_memcache) toc.first_track = 1; toc.last_track = NumTracks; - - //printf("Track=%d pregap=%d pregap_dv=%d sectors=%d LBA=%d\n", NumTracks, Tracks[NumTracks].pregap, Tracks[NumTracks].pregap_dv, Tracks[NumTracks].sectors, Tracks[NumTracks].LBA); } FirstTrack = 1; @@ -371,7 +368,6 @@ bool CDAccess_CHD::Read_Raw_Sector(uint8_t *buf, int32_t lba) // TODO: Zero out optional(?) checksum bytes? break; } - printf("Pre/post-gap read, LBA=%d(LBA-track_start_LBA=%d)\n", lba, lba - ct->LBA); } else { @@ -462,7 +458,6 @@ int32_t CDAccess_CHD::MakeSubPQ(int32_t lba, uint8_t *SubPWBuf) const // Handle pause(D7 of interleaved subchannel byte) bit, should be set to 1 when in pregap or postgap. if ((lba < Tracks[track].LBA) || (lba >= Tracks[track].LBA + Tracks[track].sectors)) { - //printf("pause_or = 0x80 --- %d\n", lba); pause_or = 0x80; } @@ -478,10 +473,7 @@ int32_t CDAccess_CHD::MakeSubPQ(int32_t lba, uint8_t *SubPWBuf) const if (pg_offset < -150) { if ((Tracks[track].subq_control & SUBQ_CTRLF_DATA) && (FirstTrack < track) && !(Tracks[track - 1].subq_control & SUBQ_CTRLF_DATA)) - { - //printf("Pregap part 1 audio->data: lba=%d track_lba=%d\n", lba, Tracks[track].LBA); control = Tracks[track - 1].subq_control; - } } } diff --git a/mednafen/cdrom/CDAccess_Image.cpp b/mednafen/cdrom/CDAccess_Image.cpp index 483cc35..c629a52 100644 --- a/mednafen/cdrom/CDAccess_Image.cpp +++ b/mednafen/cdrom/CDAccess_Image.cpp @@ -179,8 +179,6 @@ uint32_t CDAccess_Image::GetSectorCount(CDRFILE_TRACK_INFO *track) else { const int64_t size = track->fp->size(); - - //printf("%d %d %d\n", (int)stat_buf.st_size, (int)track->FileOffset, (int)stat_buf.st_size - (int)track->FileOffset); if(track->SubchannelMode) return((size - track->FileOffset) / (2352 + 96)); return((size - track->FileOffset) / 2352); @@ -255,7 +253,6 @@ bool CDAccess_Image::ParseTOCFileLineInfo(CDRFILE_TRACK_INFO *track, const int t track->FileOffset = offset; // Make sure this is set before calling GetSectorCount()! sectors = GetSectorCount(track); - //printf("Track: %d, offset: %ld, %ld\n", tracknum, offset, sectors); if(length) { @@ -352,11 +349,6 @@ bool CDAccess_Image::LoadSBI(const std::string& sbi_path) tmpq[11] ^= 0xFF; // - //printf("%02x:%02x:%02x --- ", ed[0], ed[1], ed[2]); - //for(unsigned i = 0; i < 12; i++) - // printf("%02x ", tmpq[i]); - //printf("\n"); - uint32_t aba = AMSF_to_ABA(BCD_to_U8(ed[0]), BCD_to_U8(ed[1]), BCD_to_U8(ed[2])); memcpy(SubQReplaceMap[aba].data(), tmpq, 12); @@ -462,8 +454,6 @@ bool CDAccess_Image::ImageOpen(const std::string& path, bool image_memcache) MDFN_strtoupper(cmdbuf); } - //printf("%s\n", cmdbuf.c_str()); //: %s %s %s %s\n", cmdbuf.c_str(), args[0].c_str(), args[1].c_str(), args[2].c_str(), args[3].c_str()); - if(IsTOC) { if(cmdbuf == "TRACK") @@ -554,7 +544,6 @@ bool CDAccess_Image::ImageOpen(const std::string& path, bool image_memcache) msfoffset = args[1].c_str(); length = args[2].c_str(); } - //printf("%s, %s, %s, %s\n", args[0].c_str(), binoffset, msfoffset, length); if (!ParseTOCFileLineInfo(&TmpTrack, active_track, args[0], binoffset, msfoffset, length, image_memcache, toc_streamcache)) return false; } @@ -949,11 +938,9 @@ bool CDAccess_Image::ImageOpen(const std::string& path, bool image_memcache) Tracks[x].sectors = Tracks[x + 1].index[0] - Tracks[x].index[1]; //Tracks[x + 1].index - Tracks[x].index; } - //printf("Poo: %d %d\n", x, Tracks[x].sectors); RunningLBA += Tracks[x].sectors; RunningLBA += Tracks[x].postgap; - //printf("%d, %ld %d %d %d %d\n", x, FileOffset, Tracks[x].index, Tracks[x].pregap, Tracks[x].sectors, Tracks[x].LBA); FileOffset += Tracks[x].sectors * DI_Size_Table[Tracks[x].DIFormat]; } // end to cue sheet handling @@ -1118,7 +1105,6 @@ bool CDAccess_Image::Read_Raw_Sector(uint8_t *buf, int32_t lba) // TODO: Zero out optional(?) checksum bytes? break; } - //printf("Pre/post-gap read, LBA=%d(LBA-track_start_LBA=%d)\n", lba, lba - ct->LBA); } else { @@ -1130,10 +1116,7 @@ bool CDAccess_Image::Read_Raw_Sector(uint8_t *buf, int32_t lba) ct->LastSamplePos += frames_read; if(frames_read > 588) // This shouldn't happen. - { - printf("Error: frames_read out of range: %llu\n", (unsigned long long)frames_read); frames_read = 0; - } if(frames_read < 588) memset((uint8_t *)AudioBuf + frames_read * 2 * sizeof(int16_t), 0, (588 - frames_read) * 2 * sizeof(int16_t)); @@ -1268,10 +1251,7 @@ int32_t CDAccess_Image::MakeSubPQ(int32_t lba, uint8_t *SubPWBuf) const // Handle pause(D7 of interleaved subchannel byte) bit, should be set to 1 when in pregap or postgap. if((lba < Tracks[track].LBA) || (lba >= Tracks[track].LBA + Tracks[track].sectors)) - { - //printf("pause_or = 0x80 --- %d\n", lba); pause_or = 0x80; - } // Handle pregap between audio->data track { @@ -1285,10 +1265,7 @@ int32_t CDAccess_Image::MakeSubPQ(int32_t lba, uint8_t *SubPWBuf) const if(pg_offset < -150) { if((Tracks[track].subq_control & SUBQ_CTRLF_DATA) && (FirstTrack < track) && !(Tracks[track - 1].subq_control & SUBQ_CTRLF_DATA)) - { - //printf("Pregap part 1 audio->data: lba=%d track_lba=%d\n", lba, Tracks[track].LBA); control = Tracks[track - 1].subq_control; - } } } @@ -1329,15 +1306,10 @@ int32_t CDAccess_Image::MakeSubPQ(int32_t lba, uint8_t *SubPWBuf) const if(!SubQReplaceMap.empty()) { - //printf("%d\n", lba); - std::map >::const_iterator it = SubQReplaceMap.find(LBA_to_ABA(lba)); if(it != SubQReplaceMap.end()) - { - //printf("Replace: %d\n", lba); memcpy(buf, (void*)it->second.data(), 12); - } } for(int i = 0; i < 96; i++) diff --git a/mednafen/cdrom/CDUtility.cpp b/mednafen/cdrom/CDUtility.cpp index aa01d47..ab4c16e 100644 --- a/mednafen/cdrom/CDUtility.cpp +++ b/mednafen/cdrom/CDUtility.cpp @@ -81,9 +81,6 @@ static void InitScrambleTable(void) scramble_table[i - 12] = z; } - - //for(int i = 0; i < 2352 - 12; i++) - // printf("0x%02x, ", scramble_table[i]); } void CDUtility_Init(void) @@ -319,20 +316,12 @@ void subpw_synth_udapp_lba(const TOC& toc, const int32_t lba, const int32_t lba_ uint32_t lba_relative; uint32_t ma, sa, fa; uint32_t m, s, f; - -#if 0 - if(lba < -150 || lba >= 0) - printf("[BUG] subpw_synth_udapp_lba() lba out of range --- %d\n", lba); -#endif - - { int32_t lba_tmp = lba + lba_subq_relative_offs; if(lba_tmp < 0) lba_relative = 0 - 1 - lba_tmp; else lba_relative = lba_tmp - 0; - } f = (lba_relative % 75); s = ((lba_relative / 75) % 60); diff --git a/mednafen/cdrom/cdromif.cpp b/mednafen/cdrom/cdromif.cpp index 9255d67..08c85e2 100644 --- a/mednafen/cdrom/cdromif.cpp +++ b/mednafen/cdrom/cdromif.cpp @@ -83,10 +83,7 @@ int CDIF::ReadSector(uint8_t* buf, int32_t lba, uint32_t sector_count, bool supp uint8_t tmpbuf[2352 + 96]; if(!ReadRawSector(tmpbuf, lba)) - { - puts("CDIF Raw Read error"); return(FALSE); - } if(!ValidateRawSector(tmpbuf)) { @@ -102,18 +99,11 @@ int CDIF::ReadSector(uint8_t* buf, int32_t lba, uint32_t sector_count, bool supp ret = mode; if(mode == 1) - { memcpy(buf, &tmpbuf[12 + 4], 2048); - } else if(mode == 2) - { memcpy(buf, &tmpbuf[12 + 4 + 8], 2048); - } else - { - printf("CDIF_ReadSector() invalid sector type at LBA=%u\n", (unsigned int)lba); return(false); - } buf += 2048; lba++; @@ -130,16 +120,9 @@ int CDIF::ReadSector(uint8_t* buf, int32_t lba, uint32_t sector_count, bool supp CDIF_ST::CDIF_ST(CDAccess *cda) : CDIF(cda) { - //puts("***WARNING USING SINGLE-THREADED CD READER***"); - UnrecoverableError = false; disc_cdaccess->Read_TOC(&disc_toc); - - if(disc_toc.first_track < 1 || disc_toc.last_track > 99 || disc_toc.first_track > disc_toc.last_track) - { - printf("TOC first(%d)/last(%d) track numbers bad.", disc_toc.first_track, disc_toc.last_track); - } } CDIF_ST::~CDIF_ST() @@ -162,7 +145,6 @@ bool CDIF_ST::ReadRawSector(uint8_t *buf, int32_t lba) if(lba < LBA_Read_Minimum || lba > LBA_Read_Maximum) { - printf("Attempt to read sector out of bounds; LBA=%d\n", lba); memset(buf, 0, 2352 + 96); return(false); } @@ -182,7 +164,6 @@ bool CDIF_ST::ReadRawSectorPWOnly(uint8_t* pwbuf, int32_t lba, bool hint_fullrea if(lba < LBA_Read_Minimum || lba > LBA_Read_Maximum) { - printf("Attempt to read sector out of bounds; LBA=%d\n", lba); memset(pwbuf, 0, 96); return(false); } diff --git a/mednafen/cdrom/galois.cpp b/mednafen/cdrom/galois.cpp index 4e1fac3..6e14291 100644 --- a/mednafen/cdrom/galois.cpp +++ b/mednafen/cdrom/galois.cpp @@ -62,14 +62,6 @@ GaloisTables* CreateGaloisTables(int32_t gf_generator) b = b ^ gf_generator; } - if(b!=1) - { -#if 0 - printf("Failed to create the Galois field log tables!\n"); -#endif - exit(1); - } - /* we're even closed using infinity (makes things easier) */ gt->indexOf[0] = GF_ALPHA0; /* log(0) = inf */ diff --git a/mednafen/cdrom/lec.cpp b/mednafen/cdrom/lec.cpp index f1677e9..f997310 100644 --- a/mednafen/cdrom/lec.cpp +++ b/mednafen/cdrom/lec.cpp @@ -590,96 +590,3 @@ void lec_scramble(uint8_t *sector) *p++ = tmp; } } - -#if 0 -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - char *infile; - char *outfile; - int fd_in, fd_out; - uint8_t buffer1[2352]; - uint8_t buffer2[2352]; - uint32_t lba; - int i; - -#if 0 - for (i = 0; i < 2048; i++) - buffer1[i + 16] = 234; - - lba = 150; - - for (i = 0; i < 100000; i++) { - lec_encode_mode1_sector(lba, buffer1); - lec_scramble(buffer2); - lba++; - } - -#else - - if (argc != 3) - return 1; - - infile = argv[1]; - outfile = argv[2]; - - - if ((fd_in = open(infile, O_RDONLY)) < 0) { - perror("Cannot open input file"); - return 1; - } - - if ((fd_out = open(outfile, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) { - perror("Cannot open output file"); - return 1; - } - - lba = 150; - - do { - if (read(fd_in, buffer1, 2352) != 2352) - break; - - switch (*(buffer1 + 12 + 3)) { - case 1: - memcpy(buffer2 + 16, buffer1 + 16, 2048); - - lec_encode_mode1_sector(lba, buffer2); - break; - - case 2: - if ((*(buffer1 + 12 + 4 + 2) & 0x20) != 0) { - /* form 2 sector */ - memcpy(buffer2 + 16, buffer1 + 16, 2324 + 8); - lec_encode_mode2_form2_sector(lba, buffer2); - } - else { - /* form 1 sector */ - memcpy(buffer2 + 16, buffer1 + 16, 2048 + 8); - lec_encode_mode2_form1_sector(lba, buffer2); - } - break; - } - - if (memcmp(buffer1, buffer2, 2352) != 0) { - printf("Verify error at lba %ld\n", lba); - } - - lec_scramble(buffer2); - write(fd_out, buffer2, 2352); - - lba++; - } while (1); - - close(fd_in); - close(fd_out); - -#endif - - return 0; -} -#endif diff --git a/mednafen/cdrom/recover-raw.cpp b/mednafen/cdrom/recover-raw.cpp index 7cfee1e..4cccccc 100644 --- a/mednafen/cdrom/recover-raw.cpp +++ b/mednafen/cdrom/recover-raw.cpp @@ -62,14 +62,9 @@ int CheckEDC(const unsigned char *cd_frame, bool xa_mode) real_crc = EDCCrc32(cd_frame+16, 2056); else real_crc = EDCCrc32(cd_frame, 2064); - if(expected_crc == real_crc) return(1); - else - { - //printf("Bad EDC CRC: Calculated: %08x, Recorded: %08x\n", real_crc, expected_crc); - return(0); - } + return(0); } /*** diff --git a/mednafen/file.c b/mednafen/file.c index 6fde969..65c40a6 100644 --- a/mednafen/file.c +++ b/mednafen/file.c @@ -15,7 +15,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include #include #include #include diff --git a/mednafen/hw_misc/arcade_card/arcade_card.cpp b/mednafen/hw_misc/arcade_card/arcade_card.cpp index 9a0cb8f..2e30cb2 100644 --- a/mednafen/hw_misc/arcade_card/arcade_card.cpp +++ b/mednafen/hw_misc/arcade_card/arcade_card.cpp @@ -31,40 +31,20 @@ static INLINE void ACAutoIncrement(ACPort_t *port) if(port->control & 0x1) { if(port->control & 0x10) - { - //if(port->control & 0x4) - //{ - // printf("BOONY: %04x\n", port->increment); - // port->base = (port->base + port->increment + 0xFF0000) & 0xFFFFFF; - // printf("%04x\n", port->base); - //} - //else port->base = (port->base + port->increment) & 0xFFFFFF; - } else - { port->offset = (port->offset + port->increment) & 0xFFFF; - } } } uint8 ArcadeCard::Read(uint32 A, bool peek) { - //printf("AC Read: %04x\n", A); if((A & 0x1F00) != 0x1A00) - { - //if(!peek) - // printf("AC unknown read: %08x\n", A); return(0xFF); - } if(A < 0x1A80) { ACPort_t *port = &AC.ports[(A >> 4) & 0x3]; - // if(!peek) - // if(A & 0x40) - // printf("AC mirrored port read: %08x\n", A); // Madou Monogatari does! - switch(A & 0xF) { case 0x00: @@ -121,19 +101,13 @@ uint8 ArcadeCard::Read(uint32 A, bool peek) } } - //if(!peek) - // printf("AC unknown read: %08x\n", A); return(0xFF); } void ArcadeCard::Write(uint32 A, uint8 V) { - //printf("AC Write: %04x %02x\n", A, V); if((A & 0x1F00) != 0x1A00) - { - //printf("AC unknown write: %08x:%02x\n", A, V); return; - } if(A < 0x1A80) { @@ -141,7 +115,7 @@ void ArcadeCard::Write(uint32 A, uint8 V) switch(A & 0xF) { - default: //printf("AC unknown write: %08x:%02x\n", A, V); + default: break; case 0x00: @@ -218,15 +192,12 @@ void ArcadeCard::Write(uint32 A, uint8 V) } break; } - - //if(A & 0x40) - // printf("AC mirrored port write: %08x:%02x\n", A, V); } else if(A >= 0x1AE0) { switch(A & 0x1F) { - default: //printf("Unknown AC write: %04x %02x\n", A, V); + default: break; case 0x00: diff --git a/mednafen/mempatcher.cpp b/mednafen/mempatcher.cpp index 138c32d..8f88004 100644 --- a/mednafen/mempatcher.cpp +++ b/mednafen/mempatcher.cpp @@ -273,7 +273,6 @@ static bool TestConditions(const char *string) unsigned int bytelen; bool passed = 1; - //printf("TR: %s\n", string); while(sscanf(string, "%u %c %63s %63s %63s", &bytelen, &endian, address, operation, value) == 5 && passed) { uint32 v_address; @@ -302,7 +301,6 @@ static bool TestConditions(const char *string) value_at_address |= MemRead(v_address + x) << shiftie; } - //printf("A: %08x, V: %08llx, VA: %08llx, OP: %s\n", v_address, v_value, value_at_address, operation); if(!strcmp(operation, ">=")) { if(!(value_at_address >= v_value)) diff --git a/mednafen/okiadpcm.cpp b/mednafen/okiadpcm.cpp index 358fec9..f5fb477 100644 --- a/mednafen/okiadpcm.cpp +++ b/mednafen/okiadpcm.cpp @@ -21,13 +21,6 @@ const int OKIADPCM_StepSizes[49] = { - // These can also be generated like: - // double start = 16; - // for(int x = 0; x < 49; x++) - // { - // printf("%d, ", (int)start); - // start *= 1.1; - // } 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, diff --git a/mednafen/pce_fast/huc6280.c b/mednafen/pce_fast/huc6280.c index 619691c..eced545 100644 --- a/mednafen/pce_fast/huc6280.c +++ b/mednafen/pce_fast/huc6280.c @@ -677,7 +677,6 @@ void HuC6280_Run(int32 cycles) } } // end if(HU_IRQlow) - //printf("%04x\n", GetRealPC()); HU_PI = HU_P; HuCPU.IRQMaskDelay = HuCPU.IRQMask; diff --git a/mednafen/pce_fast/huc6280_ops.h b/mednafen/pce_fast/huc6280_ops.h index e775422..88a92e8 100644 --- a/mednafen/pce_fast/huc6280_ops.h +++ b/mednafen/pce_fast/huc6280_ops.h @@ -18,8 +18,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define TEST_WEIRD_TFLAG(n) { /* if(HU_P & T_FLAG) puts("RAWR" n); */} - case 0x00: /* BRK */ IncPC(); HU_P &= ~T_FLAG; @@ -44,9 +42,6 @@ case 0x40: /* RTI */ /* HU_PI=HU_P; This is probably incorrect, so it's commented out. */ HU_PI = HU_P; POP_PC(); - - // T-flag handling here: - TEST_WEIRD_TFLAG("RTI"); break; case 0x60: /* RTS */ @@ -89,9 +84,6 @@ case 0x7A: // PLY 65C02 case 0x28: /* PLP */ HU_P = POP(); EXPAND_FLAGS(); - - // T-flag handling here: - TEST_WEIRD_TFLAG("PLP"); break; case 0x4C: @@ -216,7 +208,6 @@ case 0x58: /* CLI */ ((RdOp(GetRealPC() + 1) & 0x3) == 0) && ((RdOp(GetRealPC() + 2) & 0xFC) == 0)) { HU_IRQlow |= 0x200; - //puts("CLI/LDA madness!"); } } HU_P&=~I_FLAG; @@ -568,7 +559,7 @@ case 0xF4: /* SET */ switch(RdAtPC()) { - default: //puts("Bad SET"); + default: break; case 0x69: IncPC(); LD_IM(ADC); diff --git a/mednafen/pce_fast/pcecd.cpp b/mednafen/pce_fast/pcecd.cpp index fa73273..29e35ca 100644 --- a/mednafen/pce_fast/pcecd.cpp +++ b/mednafen/pce_fast/pcecd.cpp @@ -55,12 +55,6 @@ static int32 ClearACKDelay; static int32 lastts; static int32 pcecd_drive_ne = 0; -// ADPCM variables and whatnot -static inline void ADPCM_DEBUG(const char *format, ...) -{ -/*printf("[Half=%d, End=%d, Playing=%d] "x, ADPCM.HalfReached, ADPCM.EndReached, ADPCM.Playing, ## __VA_ARGS__);*/ -} - typedef Blip_Synth ADSynth; static ADSynth ADPCMSynth; static OKIADPCM_Decoder MSM5205; @@ -413,7 +407,6 @@ uint8 PCECD_Read(uint32 timestamp, uint32 A) break; case 0xa: - ADPCM_DEBUG("ReadBuffer\n"); ADPCM.ReadPending = 19 * 3; //24 * 3; ret = ADPCM.ReadBuffer; break; @@ -423,7 +416,6 @@ uint8 PCECD_Read(uint32 timestamp, uint32 A) break; case 0xc: - //printf("ADPCM Status Read: %d\n", timestamp); ret = 0x00; ret |= (ADPCM.EndReached) ? 0x01 : 0x00; @@ -531,14 +523,9 @@ void PCECD_Write(uint32 timestamp, uint32 physAddr, uint8 data) ADPCM.Addr &= 0xFF00; ADPCM.Addr |= V; - ADPCM_DEBUG("SAL: %02x, %d\n", V, timestamp); - // Length appears to be constantly latched when D4 is set(tested on a real system) if(ADPCM.LastCmd & 0x10) - { - ADPCM_DEBUG("Set length(crazy way L): %04x\n", ADPCM.Addr); ADPCM.LengthCount = ADPCM.Addr; - } break; case 0x9: // Set ADPCM address high @@ -548,24 +535,17 @@ void PCECD_Write(uint32 timestamp, uint32 physAddr, uint8 data) ADPCM.Addr &= 0x00FF; ADPCM.Addr |= V << 8; - ADPCM_DEBUG("SAH: %02x, %d\n", V, timestamp); - // Length appears to be constantly latched when D4 is set(tested on a real system) if(ADPCM.LastCmd & 0x10) - { - ADPCM_DEBUG("Set length(crazy way H): %04x\n", ADPCM.Addr); ADPCM.LengthCount = ADPCM.Addr; - } break; case 0xa: - //ADPCM_DEBUG("Write: %02x, %d\n", V, timestamp); ADPCM.WritePending = 3 * 11; ADPCM.WritePendingValue = data; break; case 0xb: // adpcm dma - ADPCM_DEBUG("DMA: %02x\n", V); _Port[0xb] = data; break; @@ -573,7 +553,6 @@ void PCECD_Write(uint32 timestamp, uint32 physAddr, uint8 data) break; case 0xd: - ADPCM_DEBUG("Write180D: %02x\n", V); if(data & 0x80) { ADPCM.Addr = 0; @@ -611,7 +590,6 @@ void PCECD_Write(uint32 timestamp, uint32 physAddr, uint8 data) // Length appears to be constantly latched when D4 is set(tested on a real system) if(data & 0x10) { - ADPCM_DEBUG("Set length: %04x\n", ADPCM.Addr); ADPCM.LengthCount = ADPCM.Addr; ADPCM.EndReached = false; } @@ -624,7 +602,6 @@ void PCECD_Write(uint32 timestamp, uint32 physAddr, uint8 data) else ADPCM.ReadAddr = (ADPCM.Addr - 1) & 0xFFFF; - ADPCM_DEBUG("Set ReadAddr: %04x, %06x\n", ADPCM.Addr, ADPCM.ReadAddr); } // D0 and D1 control write address @@ -633,7 +610,6 @@ void PCECD_Write(uint32 timestamp, uint32 physAddr, uint8 data) ADPCM.WriteAddr = ADPCM.Addr; if(!(data & 0x1)) ADPCM.WriteAddr = (ADPCM.WriteAddr - 1) & 0xFFFF; - ADPCM_DEBUG("Set WriteAddr: %04x, %06x\n", ADPCM.Addr, ADPCM.WriteAddr); } ADPCM.LastCmd = data; UpdateADPCMIRQState(); @@ -642,10 +618,7 @@ void PCECD_Write(uint32 timestamp, uint32 physAddr, uint8 data) case 0xe: // Set ADPCM playback rate { uint8 freq = V & 0x0F; - ADPCM.SampleFreq = freq; - - ADPCM_DEBUG("Freq: %02x\n", freq); } break; @@ -728,7 +701,6 @@ static INLINE void ADPCM_PB_Run(int32 basetime, int32 run_time) static INLINE void ADPCM_Run(const int32 clocks, const int32 timestamp) { - //printf("ADPCM Run: %d\n", clocks); ADPCM_PB_Run(timestamp, clocks); if(ADPCM.WritePending) @@ -794,9 +766,6 @@ extern "C" void PCECD_Run(uint32 in_timestamp) int32 clocks = in_timestamp - lastts; int32 running_ts = lastts; - //printf("Run Begin: Clocks=%d(%d - %d), cl=%d\n", clocks, in_timestamp, lastts, CalcNextEvent); - //fflush(stdout); - while(clocks > 0) { int32 chunk_clocks = CalcNextEvent(clocks); diff --git a/mednafen/pce_fast/pcecd_drive.cpp b/mednafen/pce_fast/pcecd_drive.cpp index cecf76b..cb96072 100644 --- a/mednafen/pce_fast/pcecd_drive.cpp +++ b/mednafen/pce_fast/pcecd_drive.cpp @@ -217,25 +217,21 @@ void PCECD_Drive_Power(pcecd_drive_timestamp_t system_timestamp) void PCECD_Drive_SetDB(uint8 data) { cd_bus.DB = data; - //printf("Set DB: %02x\n", data); } void PCECD_Drive_SetACK(bool set) { SetkingACK(set); - //printf("Set ACK: %d\n", set); } void PCECD_Drive_SetSEL(bool set) { SetkingSEL(set); - //printf("Set SEL: %d\n", set); } void PCECD_Drive_SetRST(bool set) { SetkingRST(set); - //printf("Set RST: %d\n", set); } static void GenSubQFromSubPW(void) @@ -244,12 +240,6 @@ static void GenSubQFromSubPW(void) subq_deinterleave(cd.SubPWBuf, SubQBuf); - //printf("Real %d/ SubQ %d - ", read_sec, BCD_to_U8(SubQBuf[7]) * 75 * 60 + BCD_to_U8(SubQBuf[8]) * 75 + BCD_to_U8(SubQBuf[9]) - 150); - // Debug code, remove me. - //for(int i = 0; i < 0xC; i++) - // printf("%02x ", SubQBuf[i]); - //printf("\n"); - if(subq_check_checksum(SubQBuf)) { memcpy(cd.SubQBuf_Last, SubQBuf, 0xC); @@ -258,10 +248,6 @@ static void GenSubQFromSubPW(void) if(adr <= 0x3) memcpy(cd.SubQBuf[adr], SubQBuf, 0xC); - - //if(adr == 0x02) - //for(int i = 0; i < 12; i++) - // printf("%02x\n", cd.SubQBuf[0x2][i]); } } @@ -305,7 +291,6 @@ static void GenSubQFromSubPW(void) static void ChangePhase(const unsigned int new_phase) { - //printf("New phase: %d %lld\n", new_phase, monotonic_timestamp); switch(new_phase) { case PHASE_BUS_FREE: @@ -524,7 +509,6 @@ static void DoNEC_PCE_SAPSP(const uint8 *cdb) { uint32 new_read_sec_start; - //printf("Set audio start: %02x %02x %02x %02x %02x %02x %02x\n", cdb[9], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], cdb[6]); switch (cdb[9] & 0xc0) { default: @@ -550,7 +534,6 @@ static void DoNEC_PCE_SAPSP(const uint8 *cdb) break; } - //printf("%lld\n", (long long)(monotonic_timestamp - pce_lastsapsp_timestamp) * 1000 / System_Clock); if(cdda.CDDAStatus == CDDASTATUS_PLAYING && new_read_sec_start == read_sec_start && ((int64)(monotonic_timestamp - pce_lastsapsp_timestamp) * 1000 / System_Clock) < 190) { pce_lastsapsp_timestamp = monotonic_timestamp; @@ -595,8 +578,6 @@ static void DoNEC_PCE_SAPEP(const uint8 *cdb) { uint32 new_read_sec_end; - //printf("Set audio end: %02x %02x %02x %02x %02x %02x %02x\n", cdb[9], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], cdb[6]); - switch (cdb[9] & 0xc0) { default: @@ -963,12 +944,7 @@ static INLINE void RunCDRead(uint32 system_timestamp, int32 run_time) { if(din.CanWrite() < 2048) { - //printf("Carp: %d %d %d\n", din.CanWrite(), SectorCount, CDReadTimer); - //CDReadTimer = (cd.data_in_size - cd.data_in_pos) * 10; - CDReadTimer += (uint64) 1 * 2048 * System_Clock / CD_DATA_TRANSFER_RATE; - - //CDReadTimer += (uint64) 1 * 128 * System_Clock / CD_DATA_TRANSFER_RATE; } else { @@ -1045,10 +1021,7 @@ uint32 PCECD_Drive_Run(pcecd_drive_timestamp_t system_timestamp) cd.last_RST_signal = RST_signal; if(ResetNeeded) - { - //puts("RST"); VirtualReset(); - } else switch(CurrentPhase) { case PHASE_BUS_FREE: @@ -1061,7 +1034,6 @@ uint32 PCECD_Drive_Run(pcecd_drive_timestamp_t system_timestamp) case PHASE_COMMAND: if(REQ_signal && ACK_signal) // Data bus is valid nowww { - //printf("Command Phase Byte I->T: %02x, %d\n", cd_bus.DB, cd.command_buffer_pos); cd.command_buffer[cd.command_buffer_pos++] = cd_bus.DB; SetREQ(FALSE); } @@ -1131,7 +1103,6 @@ uint32 PCECD_Drive_Run(pcecd_drive_timestamp_t system_timestamp) case PHASE_DATA_IN: if(!REQ_signal && !ACK_signal) { - //puts("REQ and ACK false"); if(din.in_count == 0) // aaand we're done! { CDIRQCallback(0x8000 | PCECD_Drive_IRQ_DATA_TRANSFER_READY); @@ -1151,7 +1122,6 @@ uint32 PCECD_Drive_Run(pcecd_drive_timestamp_t system_timestamp) } if(REQ_signal && ACK_signal) { - //puts("REQ and ACK true"); SetREQ(FALSE); } break; @@ -1296,7 +1266,6 @@ int PCECD_Drive_StateAction(StateMem * sm, int load, int data_only, const char * if(cdda.CDDADiv <= 0) cdda.CDDADiv = 1; - //printf("%d %d %d\n", din.in_count, din.read_pos, din.write_pos); } return (ret); diff --git a/mednafen/pce_fast/psg.cpp b/mednafen/pce_fast/psg.cpp index 7b41feb..585d5f3 100644 --- a/mednafen/pce_fast/psg.cpp +++ b/mednafen/pce_fast/psg.cpp @@ -101,8 +101,6 @@ void PCEFast_PSG::RecalcUOFunc(int chnum) { psg_channel *ch = &channel[chnum]; - //printf("UO Update: %d, %02x\n", chnum, ch->control); - if(!(ch->control & 0xC0)) ch->UpdateOutput = &PCEFast_PSG::UpdateOutput_Off; else if(ch->noisectrl & ch->control & 0x80) @@ -154,8 +152,6 @@ void PCEFast_PSG::RecalcNoiseFreqCache(int chnum) PCEFast_PSG::PCEFast_PSG(Blip_Buffer *bb_l, Blip_Buffer *bb_r) { - //printf("Test: %u, %u\n", sizeof(psg_channel), (uint8*)&channel[0].balance - (uint8*)&channel[0].waveform[0]); - sbuf[0] = bb_l; sbuf[1] = bb_r; @@ -235,9 +231,6 @@ void PCEFast_PSG::Write(int32 timestamp, uint8 A, uint8 V) psg_channel *ch = &channel[select]; - //if(A == 0x01 || select == 5) - // printf("Write Ch: %d %04x %02x, %d\n", select, A, V, timestamp); - switch(A) { default: break; @@ -330,11 +323,9 @@ void PCEFast_PSG::Write(int32 timestamp, uint8 A, uint8 V) case 0x08: /* LFO frequency */ lfofreq = V & 0xFF; - //printf("LFO Freq: %02x\n", V); break; case 0x09: /* LFO trigger and control */ - //printf("LFO Ctrl: %02x\n", V); if(V & 0x80) { channel[1].waveform_index = 0; @@ -504,22 +495,13 @@ void PCEFast_PSG::Update(int32 timestamp) if(!phase) { - //printf("Volume update(Read, %d since last): ch=%d, lr=%d, ts=%d\n", running_timestamp - last_read, chnum, lr, running_timestamp); - if(chnum < 6) - { vol_update_vllatch = GetVL(chnum, lr); - } - //last_read = running_timestamp; } else { - // printf("Volume update(Apply): ch=%d, lr=%d, ts=%d\n", chnum, lr, running_timestamp); if(chnum < 6) - { channel[chnum].vl[lr] = vol_update_vllatch; - } - //last_apply = running_timestamp; } vol_update_which = (vol_update_which + 1) & 0x1F; diff --git a/mednafen/pce_fast/vdc.c b/mednafen/pce_fast/vdc.c index 2c7fd24..d3f4185 100644 --- a/mednafen/pce_fast/vdc.c +++ b/mednafen/pce_fast/vdc.c @@ -128,13 +128,8 @@ static INLINE void CheckFixSpriteTileCache(vdc_t *which_vdc, uint16 no, uint32 s if((special | 0x80) == which_vdc->spr_tile_clean[no]) return; - //printf("Oops: %d, %d, %d\n", no, special | 0x100, which_vdc->spr_tile_clean[no]); if((no * 64) >= VRAM_Size) { - //printf("Unmapped: %d\n", no); - //VDC_UNDEFINED("Unmapped VRAM sprite tile read"); - // Unnecessary, since we reset the sprite tile cache to 0 on reset/init anyway. - //memset(which_vdc->spr_tile_cache[no], 0x00, 16 * 16 * sizeof(uint16)); } else if(special) { @@ -301,7 +296,6 @@ DECLFR(VCE_Read) DECLFW(VCE_Write) { - //printf("%04x %02x, %04x\n", A, V, HuCPU.PC); switch(A&0x7) { case 0: SetVCECR(V); break; @@ -327,7 +321,6 @@ void VDC_SetLayerEnableMask(uint64 mask) void MDFN_FASTCALL VDC_Write_ST(uint32 A, uint8 V) { - //printf("WriteST: %04x %02x\n", A, V); VDC_Write(A, V); } @@ -353,9 +346,6 @@ static void DoDMA(vdc_t *vdc) vdc->spr_tile_clean[vdc->DESR >> 6] = 0; } - //if(vdc->DCR & 0xC) - //printf("Pllal: %02x\n", vdc->DCR); - vdc->SOUR += (((vdc->DCR & 0x4) >> 1) ^ 2) - 1; vdc->DESR += (((vdc->DCR & 0x8) >> 2) ^ 2) - 1; vdc->LENR--; @@ -381,9 +371,6 @@ DECLFW(VDC_Write) int chip = 0; A &= 0x3; - //if((A == 0x2 || A == 0x3) && ((vdc->select & 0x1f) >= 0x09) && ((vdc->select & 0x1f) <= 0x13)) - - //printf("%04x, %02x: %02x, %d\n", A, vdc->select, V, vdc->display_counter); switch(A) { @@ -415,11 +402,6 @@ DECLFW(VDC_Write) FixTileCache(vdc, vdc->MAWR); vdc->spr_tile_clean[vdc->MAWR >> 6] = 0; } - else - { - //VDC_UNDEFINED("Unmapped VRAM write"); - //printf("VROOM: %04x, %02x\n", vdc->MAWR, (vdc->CR >> 11) & 0x3); - } vdc->MAWR += vram_inc_tab[(vdc->CR >> 11) & 0x3]; } break; @@ -428,7 +410,6 @@ DECLFW(VDC_Write) case 0x07: REGSETP(vdc->BXR, V, msb); vdc->BXR &= 0x3FF; break; case 0x08: REGSETP(vdc->BYR, V, msb); vdc->BYR &= 0x1FF; vdc->BG_YOffset = vdc->BYR; // Set it on LSB and MSB writes(only changing on MSB breaks Youkai Douchuuki) - //printf("%04x\n", HuCPU.PC); break; case 0x09: REGSETP(vdc->MWR, V, msb); break; case 0x0a: REGSETP(vdc->HSR, V, msb); break; @@ -456,7 +437,6 @@ DECLFW(VDC_Write) } break; case 0x13: REGSETP(vdc->SATB, V, msb); vdc->SATBPending = 1; break; - // default: printf("Oops 2: %04x %02x\n", vdc->select, V);break; } break; } @@ -637,7 +617,6 @@ static void DrawSprites(vdc_t *vdc, const int32 end, uint16 *spr_linebuf) SpriteList[active_sprites].flags = flags; - //printf("Found: %d %d\n", vdc->RCRCount, x); SpriteList[active_sprites].x = x; SpriteList[active_sprites].palette_index = palette_index; @@ -774,8 +753,6 @@ static void MixNone(const uint32 count, uint16_t *target) static void DrawOverscan(const vdc_t *vdc, uint16_t *target, const MDFN_Rect *lw, const bool full, const int32 vpl, const int32 vpr) { uint32 os_color = vce.color_table_cache[0x100]; - - //printf("%d %d\n", lw->x, lw->w); int x = lw->x; if(!full) @@ -845,31 +822,6 @@ void VDC_RunFrame(EmulateSpecStruct *espec, bool IsHES) line_leadin1 = cyc_tot; #endif -#if 0 - { - int vdc_to_master = 4; - - line_leadin1 = 1365 - ((M_vdc_HDW + 1) * 8 - 4 + 6) * vdc_to_master; - - if(line_leadin1 < 0) - { - line_leadin1 = 0; - puts("Eep"); - } - - if(M_vdc_HDS > 2) - line_leadin1 += 2; - - line_leadin1 = line_leadin1 / 3; - } - - if(line_leadin1 < 0) - line_leadin1 = 0; - else if(line_leadin1 > 400) - line_leadin1 = 400; -#endif - - //printf("%d\n", line_leadin1); if(max_dc < vce.dot_clock) max_dc = vce.dot_clock; @@ -1108,7 +1060,6 @@ void VDC_RunFrame(EmulateSpecStruct *espec, bool IsHES) } frame_counter = (frame_counter + 1) % (vce.lc263 ? 263 : 262); - //printf("%d\n", vce.lc263); } while(frame_counter != VBlankFL); // big frame loop! DisplayRect->w = defined_width[vce.dot_clock]; diff --git a/mednafen/pce_fast/vdc.h b/mednafen/pce_fast/vdc.h index 136a211..6472b3f 100644 --- a/mednafen/pce_fast/vdc.h +++ b/mednafen/pce_fast/vdc.h @@ -9,9 +9,7 @@ #define REGGETP(_reg, _msb) ((_reg >> ((_msb) ? 8 : 0)) & 0xFF) #define VDC_DEBUG(x) -//printf("%s: %d\n", x, vdc->display_counter); #define VDC_UNDEFINED(x) { } -//{ printf("%s: %d\n", x, vdc->display_counter); } #ifdef __cplusplus extern "C" { @@ -157,14 +155,10 @@ static INLINE uint8 VDC_Read(unsigned int A, bool SGX) break; } - //if(HuCPU.isopread && (A == 1 || A == 3)) //(A == 2 || A == 3)) // && A == 1) if(A == 1) { - //if(vdc->display_counter >= (VDS + VSW) && vdc->display_counter < (VDS + VSW + VDW + 1) && vce.dot_clock > 0) if(vce.dot_clock > 0) ret = 0x40; - //printf("%d %d %02x\n", vdc->display_counter, vce.dot_clock, ret); - //ret = 0x40; } return(ret); } diff --git a/mednafen/state.c b/mednafen/state.c index 84aa9be..110446d 100644 --- a/mednafen/state.c +++ b/mednafen/state.c @@ -15,7 +15,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include #include #include @@ -27,6 +26,10 @@ #include "mednafen-endian.h" #include "state.h" +#define SSEEK_END 2 +#define SSEEK_CUR 1 +#define SSEEK_SET 0 + #define RLSB MDFNSTATE_RLSB /* 0x80000000 */ /* Forward declaration */ @@ -67,13 +70,13 @@ static int32_t smem_seek(StateMem *st, uint32_t offset, int whence) { switch(whence) { - case SEEK_SET: + case SSEEK_SET: st->loc = offset; break; - case SEEK_END: + case SSEEK_END: st->loc = st->len - offset; break; - case SEEK_CUR: + case SSEEK_CUR: st->loc += offset; break; } @@ -109,7 +112,7 @@ static int smem_read32le(StateMem *st, uint32_t *b) return(4); } -static bool SubWrite(StateMem *st, SFORMAT *sf, const char *name_prefix) +static bool SubWrite(StateMem *st, SFORMAT *sf) { /* Size can sometimes be zero, so also check for the * text name. These two should both be zero only at @@ -128,23 +131,17 @@ static bool SubWrite(StateMem *st, SFORMAT *sf, const char *name_prefix) if(sf->size == (uint32_t)~0) /* Link to another struct. */ { - if(!SubWrite(st, (SFORMAT *)sf->v, name_prefix)) + if(!SubWrite(st, (SFORMAT *)sf->v)) return(0); sf++; continue; } - bytesize = sf->size; + bytesize = sf->size; - if (name_prefix) - slen = snprintf( - nameo + 1, 256, "%s%s", name_prefix, sf->name); - else - { - slen = strlcpy(nameo + 1, sf->name, 256); - nameo[256] = 0; - } + slen = strlcpy(nameo + 1, sf->name, 256); + nameo[256] = 0; nameo[0] = slen; smem_write(st, nameo, 1 + nameo[0]); @@ -221,14 +218,14 @@ static int WriteStateChunk(StateMem *st, const char *sname, SFORMAT *sf) data_start_pos = st->loc; - if(!SubWrite(st, sf, NULL)) + if(!SubWrite(st, sf)) return(0); end_pos = st->loc; - smem_seek(st, data_start_pos - 4, SEEK_SET); + smem_seek(st, data_start_pos - 4, SSEEK_SET); smem_write32le(st, end_pos - data_start_pos); - smem_seek(st, end_pos, SEEK_SET); + smem_seek(st, end_pos, SSEEK_SET); return(end_pos - data_start_pos); } @@ -292,7 +289,7 @@ static int ReadStateChunk(StateMem *st, SFORMAT *sf, int size) if(recorded_size != expected_size) { - if(smem_seek(st, recorded_size, SEEK_CUR) < 0) + if(smem_seek(st, recorded_size, SSEEK_CUR) < 0) return(0); } else @@ -322,7 +319,7 @@ static int ReadStateChunk(StateMem *st, SFORMAT *sf, int size) } else { - if(smem_seek(st, recorded_size, SEEK_CUR) < 0) + if(smem_seek(st, recorded_size, SSEEK_CUR) < 0) return(0); } } @@ -360,13 +357,13 @@ static int MDFNSS_StateAction_internal(void *st_p, int load, int data_only, stru } else { - if(smem_seek(st, tmp_size, SEEK_CUR) < 0) + if(smem_seek(st, tmp_size, SSEEK_CUR) < 0) return(0); } } - if(smem_seek(st, -total, SEEK_CUR) < 0) + if(smem_seek(st, -total, SSEEK_CUR) < 0) return(0); - if(!found && !section->optional) /* Not found. We are sad! */ + if(!found) /* Not found. We are sad! */ return(0); } else @@ -385,7 +382,6 @@ int MDFNSS_StateAction(void *st_p, int load, int data_only, SFORMAT *sf, const c love.sf = sf; love.name = name; - love.optional = optional; return(MDFNSS_StateAction_internal(st, load, 0, &love)); } @@ -410,7 +406,7 @@ int MDFNSS_SaveSM(void *st_p, int a, int b, const void *c, const void *d, const return(0); sizy = st->loc; - smem_seek(st, 16 + 4, SEEK_SET); + smem_seek(st, 16 + 4, SSEEK_SET); smem_write32le(st, sizy); return(1); diff --git a/mednafen/state.h b/mednafen/state.h index 674c33b..eca11b2 100644 --- a/mednafen/state.h +++ b/mednafen/state.h @@ -38,7 +38,6 @@ struct SSDescriptor { SFORMAT *sf; const char *name; - bool optional; }; #ifdef __cplusplus diff --git a/mednafen/tremor/bitwise.c b/mednafen/tremor/bitwise.c index 30f7680..08434ad 100644 --- a/mednafen/tremor/bitwise.c +++ b/mednafen/tremor/bitwise.c @@ -520,339 +520,3 @@ unsigned char *oggpack_get_buffer(oggpack_buffer *b){ unsigned char *oggpackB_get_buffer(oggpack_buffer *b){ return oggpack_get_buffer(b); } - -/* Self test of the bitwise routines; everything else is based on - them, so they damned well better be solid. */ - -#ifdef _V_SELFTEST -#include - -static int ilog(unsigned int v){ - int ret=0; - while(v){ - ret++; - v>>=1; - } - return(ret); -} - -oggpack_buffer o; -oggpack_buffer r; - -void report(char *in){ - fprintf(stderr,"%s",in); - exit(1); -} - -void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){ - long bytes,i; - unsigned char *buffer; - - oggpack_reset(&o); - for(i=0;i #include #include #include "ogg.h" diff --git a/mednafen/tremor/framing.c b/mednafen/tremor/framing.c index 64fbf1e..4ac6823 100644 --- a/mednafen/tremor/framing.c +++ b/mednafen/tremor/framing.c @@ -1004,1071 +1004,3 @@ void ogg_packet_clear(ogg_packet *op) { free(op->packet); memset(op, 0, sizeof(*op)); } - -#ifdef _V_SELFTEST -#include - -ogg_stream_state os_en, os_de; -ogg_sync_state oy; - -void checkpacket(ogg_packet *op,long len, int no, long pos){ - long j; - static int sequence=0; - static int lastno=0; - - if(op->bytes!=len){ - fprintf(stderr,"incorrect packet length (%ld != %ld)!\n",op->bytes,len); - exit(1); - } - if(op->granulepos!=pos){ - fprintf(stderr,"incorrect packet granpos (%ld != %ld)!\n",(long)op->granulepos,pos); - exit(1); - } - - /* packet number just follows sequence/gap; adjust the input number - for that */ - if(no==0){ - sequence=0; - }else{ - sequence++; - if(no>lastno+1) - sequence++; - } - lastno=no; - if(op->packetno!=sequence){ - fprintf(stderr,"incorrect packet sequence %ld != %d\n", - (long)(op->packetno),sequence); - exit(1); - } - - /* Test data */ - for(j=0;jbytes;j++) - if(op->packet[j]!=((j+no)&0xff)){ - fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n", - j,op->packet[j],(j+no)&0xff); - exit(1); - } -} - -void check_page(unsigned char *data,const int *header,ogg_page *og){ - long j; - /* Test data */ - for(j=0;jbody_len;j++) - if(og->body[j]!=data[j]){ - fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n", - j,data[j],og->body[j]); - exit(1); - } - - /* Test header */ - for(j=0;jheader_len;j++){ - if(og->header[j]!=header[j]){ - fprintf(stderr,"header content mismatch at pos %ld:\n",j); - for(j=0;jheader[j]); - fprintf(stderr,"\n"); - exit(1); - } - } - if(og->header_len!=header[26]+27){ - fprintf(stderr,"header length incorrect! (%ld!=%d)\n", - og->header_len,header[26]+27); - exit(1); - } -} - -void print_header(ogg_page *og){ - int j; - fprintf(stderr,"\nHEADER:\n"); - fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n", - og->header[0],og->header[1],og->header[2],og->header[3], - (int)og->header[4],(int)og->header[5]); - - fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n", - (og->header[9]<<24)|(og->header[8]<<16)| - (og->header[7]<<8)|og->header[6], - (og->header[17]<<24)|(og->header[16]<<16)| - (og->header[15]<<8)|og->header[14], - ((long)(og->header[21])<<24)|(og->header[20]<<16)| - (og->header[19]<<8)|og->header[18]); - - fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (", - (int)og->header[22],(int)og->header[23], - (int)og->header[24],(int)og->header[25], - (int)og->header[26]); - - for(j=27;jheader_len;j++) - fprintf(stderr,"%d ",(int)og->header[j]); - fprintf(stderr,")\n\n"); -} - -void copy_page(ogg_page *og){ - unsigned char *temp=malloc(og->header_len); - memcpy(temp,og->header,og->header_len); - og->header=temp; - - temp=malloc(og->body_len); - memcpy(temp,og->body,og->body_len); - og->body=temp; -} - -void free_page(ogg_page *og){ - free (og->header); - free (og->body); -} - -void error(void){ - fprintf(stderr,"error!\n"); - exit(1); -} - -/* 17 only */ -const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0x15,0xed,0xec,0x91, - 1, - 17}; - -/* 17, 254, 255, 256, 500, 510, 600 byte, pad */ -const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0x59,0x10,0x6c,0x2c, - 1, - 17}; -const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04, - 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,1,0,0,0, - 0x89,0x33,0x85,0xce, - 13, - 254,255,0,255,1,255,245,255,255,0, - 255,255,90}; - -/* nil packets; beginning,middle,end */ -const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0xff,0x7b,0x23,0x17, - 1, - 0}; -const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04, - 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,1,0,0,0, - 0x5c,0x3f,0x66,0xcb, - 17, - 17,254,255,0,0,255,1,0,255,245,255,255,0, - 255,255,90,0}; - -/* large initial packet */ -const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0x01,0x27,0x31,0xaa, - 18, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,10}; - -const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04, - 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,1,0,0,0, - 0x7f,0x4e,0x8a,0xd2, - 4, - 255,4,255,0}; - - -/* continuing packet test */ -const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0xff,0x7b,0x23,0x17, - 1, - 0}; - -const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00, - 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, - 0x01,0x02,0x03,0x04,1,0,0,0, - 0xf8,0x3c,0x19,0x79, - 255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255}; - -const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05, - 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,2,0,0,0, - 0x38,0xe6,0xb6,0x28, - 6, - 255,220,255,4,255,0}; - - -/* spill expansion test */ -const int head1_4b[] = {0x4f,0x67,0x67,0x53,0,0x02, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0xff,0x7b,0x23,0x17, - 1, - 0}; - -const int head2_4b[] = {0x4f,0x67,0x67,0x53,0,0x00, - 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,1,0,0,0, - 0xce,0x8f,0x17,0x1a, - 23, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,10,255,4,255,0,0}; - - -const int head3_4b[] = {0x4f,0x67,0x67,0x53,0,0x04, - 0x07,0x14,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,2,0,0,0, - 0x9b,0xb2,0x50,0xa1, - 1, - 0}; - -/* page with the 255 segment limit */ -const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0xff,0x7b,0x23,0x17, - 1, - 0}; - -const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00, - 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,1,0,0,0, - 0xed,0x2a,0x2e,0xa7, - 255, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10}; - -const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04, - 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,2,0,0,0, - 0x6c,0x3b,0x82,0x3d, - 1, - 50}; - - -/* packet that overspans over an entire page */ -const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0xff,0x7b,0x23,0x17, - 1, - 0}; - -const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00, - 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,1,0,0,0, - 0x68,0x22,0x7c,0x3d, - 255, - 100, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255}; - -const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01, - 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, - 0x01,0x02,0x03,0x04,2,0,0,0, - 0xf4,0x87,0xba,0xf3, - 255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255}; - -const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05, - 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,3,0,0,0, - 0xf7,0x2f,0x6c,0x60, - 5, - 254,255,4,255,0}; - -/* packet that overspans over an entire page */ -const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,0,0,0,0, - 0xff,0x7b,0x23,0x17, - 1, - 0}; - -const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00, - 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,1,0,0,0, - 0x68,0x22,0x7c,0x3d, - 255, - 100, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255, - 255,255,255,255,255,255}; - -const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05, - 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00, - 0x01,0x02,0x03,0x04,2,0,0,0, - 0xd4,0xe0,0x60,0xe5, - 1, - 0}; - -void test_pack(const int *pl, const int **headers, int byteskip, - int pageskip, int packetskip){ - unsigned char *data=malloc(1024*1024); /* for scripted test cases only */ - long inptr=0; - long outptr=0; - long deptr=0; - long depacket=0; - long granule_pos=7,pageno=0; - int i,j,packets,pageout=pageskip; - int eosflag=0; - int bosflag=0; - - int byteskipcount=0; - - ogg_stream_reset(&os_en); - ogg_stream_reset(&os_de); - ogg_sync_reset(&oy); - - for(packets=0;packetsbyteskip){ - memcpy(next,og.header,byteskipcount-byteskip); - next+=byteskipcount-byteskip; - byteskipcount=byteskip; - } - - byteskipcount+=og.body_len; - if(byteskipcount>byteskip){ - memcpy(next,og.body,byteskipcount-byteskip); - next+=byteskipcount-byteskip; - byteskipcount=byteskip; - } - - ogg_sync_wrote(&oy,next-buf); - - while(1){ - int ret=ogg_sync_pageout(&oy,&og_de); - if(ret==0)break; - if(ret<0)continue; - /* got a page. Happy happy. Verify that it's good. */ - - fprintf(stderr,"(%d), ",pageout); - - check_page(data+deptr,headers[pageout],&og_de); - deptr+=og_de.body_len; - pageout++; - - /* submit it to deconstitution */ - ogg_stream_pagein(&os_de,&og_de); - - /* packets out? */ - while(ogg_stream_packetpeek(&os_de,&op_de2)>0){ - ogg_stream_packetpeek(&os_de,NULL); - ogg_stream_packetout(&os_de,&op_de); /* just catching them all */ - - /* verify peek and out match */ - if(memcmp(&op_de,&op_de2,sizeof(op_de))){ - fprintf(stderr,"packetout != packetpeek! pos=%ld\n", - depacket); - exit(1); - } - - /* verify the packet! */ - /* check data */ - if(memcmp(data+depacket,op_de.packet,op_de.bytes)){ - fprintf(stderr,"packet data mismatch in decode! pos=%ld\n", - depacket); - exit(1); - } - /* check bos flag */ - if(bosflag==0 && op_de.b_o_s==0){ - fprintf(stderr,"b_o_s flag not set on packet!\n"); - exit(1); - } - if(bosflag && op_de.b_o_s){ - fprintf(stderr,"b_o_s flag incorrectly set on packet!\n"); - exit(1); - } - bosflag=1; - depacket+=op_de.bytes; - - /* check eos flag */ - if(eosflag){ - fprintf(stderr,"Multiple decoded packets with eos flag!\n"); - exit(1); - } - - if(op_de.e_o_s)eosflag=1; - - /* check granulepos flag */ - if(op_de.granulepos!=-1){ - fprintf(stderr," granule:%ld ",(long)op_de.granulepos); - } - } - } - } - } - } - } - free(data); - if(headers[pageno]!=NULL){ - fprintf(stderr,"did not write last page!\n"); - exit(1); - } - if(headers[pageout]!=NULL){ - fprintf(stderr,"did not decode last page!\n"); - exit(1); - } - if(inptr!=outptr){ - fprintf(stderr,"encoded page data incomplete!\n"); - exit(1); - } - if(inptr!=deptr){ - fprintf(stderr,"decoded page data incomplete!\n"); - exit(1); - } - if(inptr!=depacket){ - fprintf(stderr,"decoded packet data incomplete!\n"); - exit(1); - } - if(!eosflag){ - fprintf(stderr,"Never got a packet with EOS set!\n"); - exit(1); - } - fprintf(stderr,"ok.\n"); -} - -int main(void){ - - ogg_stream_init(&os_en,0x04030201); - ogg_stream_init(&os_de,0x04030201); - ogg_sync_init(&oy); - - /* Exercise each code path in the framing code. Also verify that - the checksums are working. */ - - { - /* 17 only */ - const int packets[]={17, -1}; - const int *headret[]={head1_0,NULL}; - - fprintf(stderr,"testing single page encoding... "); - test_pack(packets,headret,0,0,0); - } - - { - /* 17, 254, 255, 256, 500, 510, 600 byte, pad */ - const int packets[]={17, 254, 255, 256, 500, 510, 600, -1}; - const int *headret[]={head1_1,head2_1,NULL}; - - fprintf(stderr,"testing basic page encoding... "); - test_pack(packets,headret,0,0,0); - } - - { - /* nil packets; beginning,middle,end */ - const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1}; - const int *headret[]={head1_2,head2_2,NULL}; - - fprintf(stderr,"testing basic nil packets... "); - test_pack(packets,headret,0,0,0); - } - - { - /* large initial packet */ - const int packets[]={4345,259,255,-1}; - const int *headret[]={head1_3,head2_3,NULL}; - - fprintf(stderr,"testing initial-packet lacing > 4k... "); - test_pack(packets,headret,0,0,0); - } - - { - /* continuing packet test; with page spill expansion, we have to - overflow the lacing table. */ - const int packets[]={0,65500,259,255,-1}; - const int *headret[]={head1_4,head2_4,head3_4,NULL}; - - fprintf(stderr,"testing single packet page span... "); - test_pack(packets,headret,0,0,0); - } - - { - /* spill expand packet test */ - const int packets[]={0,4345,259,255,0,0,-1}; - const int *headret[]={head1_4b,head2_4b,head3_4b,NULL}; - - fprintf(stderr,"testing page spill expansion... "); - test_pack(packets,headret,0,0,0); - } - - /* page with the 255 segment limit */ - { - - const int packets[]={0,10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,10, - 10,10,10,10,10,10,10,50,-1}; - const int *headret[]={head1_5,head2_5,head3_5,NULL}; - - fprintf(stderr,"testing max packet segments... "); - test_pack(packets,headret,0,0,0); - } - - { - /* packet that overspans over an entire page */ - const int packets[]={0,100,130049,259,255,-1}; - const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL}; - - fprintf(stderr,"testing very large packets... "); - test_pack(packets,headret,0,0,0); - } - - { - /* test for the libogg 1.1.1 resync in large continuation bug - found by Josh Coalson) */ - const int packets[]={0,100,130049,259,255,-1}; - const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL}; - - fprintf(stderr,"testing continuation resync in very large packets... "); - test_pack(packets,headret,100,2,3); - } - - { - /* term only page. why not? */ - const int packets[]={0,100,64770,-1}; - const int *headret[]={head1_7,head2_7,head3_7,NULL}; - - fprintf(stderr,"testing zero data page (1 nil packet)... "); - test_pack(packets,headret,0,0,0); - } - - - - { - /* build a bunch of pages for testing */ - unsigned char *data=malloc(1024*1024); - int pl[]={0, 1,1,98,4079, 1,1,2954,2057, 76,34,912,0,234,1000,1000, 1000,300,-1}; - int inptr=0,i,j; - ogg_page og[5]; - - ogg_stream_reset(&os_en); - - for(i=0;pl[i]!=-1;i++){ - ogg_packet op; - int len=pl[i]; - - op.packet=data+inptr; - op.bytes=len; - op.e_o_s=(pl[i+1]<0?1:0); - op.granulepos=(i+1)*1000; - - for(j=0;j0)error(); - - /* Test fractional page inputs: incomplete fixed header */ - memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3, - 20); - ogg_sync_wrote(&oy,20); - if(ogg_sync_pageout(&oy,&og_de)>0)error(); - - /* Test fractional page inputs: incomplete header */ - memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23, - 5); - ogg_sync_wrote(&oy,5); - if(ogg_sync_pageout(&oy,&og_de)>0)error(); - - /* Test fractional page inputs: incomplete body */ - - memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28, - og[1].header_len-28); - ogg_sync_wrote(&oy,og[1].header_len-28); - if(ogg_sync_pageout(&oy,&og_de)>0)error(); - - memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000); - ogg_sync_wrote(&oy,1000); - if(ogg_sync_pageout(&oy,&og_de)>0)error(); - - memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000, - og[1].body_len-1000); - ogg_sync_wrote(&oy,og[1].body_len-1000); - if(ogg_sync_pageout(&oy,&og_de)<=0)error(); - - fprintf(stderr,"ok.\n"); - } - - /* Test fractional page inputs: page + incomplete capture */ - { - ogg_page og_de; - fprintf(stderr,"Testing sync on 1+partial inputs... "); - ogg_sync_reset(&oy); - - memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header, - og[1].header_len); - ogg_sync_wrote(&oy,og[1].header_len); - - memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body, - og[1].body_len); - ogg_sync_wrote(&oy,og[1].body_len); - - memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header, - 20); - ogg_sync_wrote(&oy,20); - if(ogg_sync_pageout(&oy,&og_de)<=0)error(); - if(ogg_sync_pageout(&oy,&og_de)>0)error(); - - memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20, - og[1].header_len-20); - ogg_sync_wrote(&oy,og[1].header_len-20); - memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body, - og[1].body_len); - ogg_sync_wrote(&oy,og[1].body_len); - if(ogg_sync_pageout(&oy,&og_de)<=0)error(); - - fprintf(stderr,"ok.\n"); - } - - /* Test recapture: garbage + page */ - { - ogg_page og_de; - fprintf(stderr,"Testing search for capture... "); - ogg_sync_reset(&oy); - - /* 'garbage' */ - memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body, - og[1].body_len); - ogg_sync_wrote(&oy,og[1].body_len); - - memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header, - og[1].header_len); - ogg_sync_wrote(&oy,og[1].header_len); - - memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body, - og[1].body_len); - ogg_sync_wrote(&oy,og[1].body_len); - - memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header, - 20); - ogg_sync_wrote(&oy,20); - if(ogg_sync_pageout(&oy,&og_de)>0)error(); - if(ogg_sync_pageout(&oy,&og_de)<=0)error(); - if(ogg_sync_pageout(&oy,&og_de)>0)error(); - - memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20, - og[2].header_len-20); - ogg_sync_wrote(&oy,og[2].header_len-20); - memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body, - og[2].body_len); - ogg_sync_wrote(&oy,og[2].body_len); - if(ogg_sync_pageout(&oy,&og_de)<=0)error(); - - fprintf(stderr,"ok.\n"); - } - - /* Test recapture: page + garbage + page */ - { - ogg_page og_de; - fprintf(stderr,"Testing recapture... "); - ogg_sync_reset(&oy); - - memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header, - og[1].header_len); - ogg_sync_wrote(&oy,og[1].header_len); - - memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body, - og[1].body_len); - ogg_sync_wrote(&oy,og[1].body_len); - - memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header, - og[2].header_len); - ogg_sync_wrote(&oy,og[2].header_len); - - memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header, - og[2].header_len); - ogg_sync_wrote(&oy,og[2].header_len); - - if(ogg_sync_pageout(&oy,&og_de)<=0)error(); - - memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body, - og[2].body_len-5); - ogg_sync_wrote(&oy,og[2].body_len-5); - - memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header, - og[3].header_len); - ogg_sync_wrote(&oy,og[3].header_len); - - memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body, - og[3].body_len); - ogg_sync_wrote(&oy,og[3].body_len); - - if(ogg_sync_pageout(&oy,&og_de)>0)error(); - if(ogg_sync_pageout(&oy,&og_de)<=0)error(); - - fprintf(stderr,"ok.\n"); - } - - /* Free page data that was previously copied */ - { - for(i=0;i<5;i++){ - free_page(&og[i]); - } - } - } - - return(0); -} - -#endif diff --git a/mednafen/tremor/ivorbisfile.h b/mednafen/tremor/ivorbisfile.h index 12e15d4..ffe6b16 100644 --- a/mednafen/tremor/ivorbisfile.h +++ b/mednafen/tremor/ivorbisfile.h @@ -23,7 +23,6 @@ extern "C" { #endif /* __cplusplus */ -#include #include "ivorbiscodec.h" #define CHUNKSIZE 1024 diff --git a/mednafen/tremor/mapping0.c b/mednafen/tremor/mapping0.c index 4da4865..1b7cb0c 100644 --- a/mednafen/tremor/mapping0.c +++ b/mednafen/tremor/mapping0.c @@ -16,7 +16,6 @@ ********************************************************************/ #include -#include #include #include #include "ogg.h" diff --git a/mednafen/tremor/synthesis.c b/mednafen/tremor/synthesis.c index bb50b4f..975926a 100644 --- a/mednafen/tremor/synthesis.c +++ b/mednafen/tremor/synthesis.c @@ -16,7 +16,6 @@ ********************************************************************/ -#include #include "ogg.h" #include "ivorbiscodec.h" #include "codec_internal.h" diff --git a/mednafen/tremor/vorbisfile.c b/mednafen/tremor/vorbisfile.c index 0730af9..469acf1 100644 --- a/mednafen/tremor/vorbisfile.c +++ b/mednafen/tremor/vorbisfile.c @@ -17,7 +17,6 @@ ********************************************************************/ #include -#include #include #include #include @@ -28,6 +27,10 @@ #include "os.h" #include "misc.h" +#define VSEEK_END 2 +#define VSEEK_CUR 1 +#define VSEEK_SET 0 + /* A 'chained bitstream' is a Vorbis bitstream that contains more than one logical bitstream arranged end to end (the only form of Ogg multiplexing allowed in a Vorbis bitstream; grouping [parallel @@ -86,7 +89,7 @@ static long _get_data(OggVorbis_File *vf){ static int _seek_helper(OggVorbis_File *vf,int64_t offset){ if(vf->datasource){ if(!(vf->callbacks.seek_func)|| - (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET) == -1) + (vf->callbacks.seek_func)(vf->datasource, offset, VSEEK_SET) == -1) return OV_EREAD; vf->offset=offset; ogg_sync_reset(&vf->oy); @@ -635,7 +638,7 @@ static int _open_seekable2(OggVorbis_File *vf){ /* we can seek, so set out learning all about this file */ if(vf->callbacks.seek_func && vf->callbacks.tell_func){ - (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END); + (vf->callbacks.seek_func)(vf->datasource,0,VSEEK_END); vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource); }else{ vf->offset=vf->end=-1; @@ -874,16 +877,9 @@ static int _fetch_and_process_packet(OggVorbis_File *vf, } } -/* if, eg, 64 bit stdio is configured by default, this will build with - fseek64 */ -static int _fseek64_wrap(FILE *f,int64_t off,int whence){ - if(f==NULL)return(-1); - return fseek(f,off,whence); -} - static int _ov_open1(void *f,OggVorbis_File *vf,const char *initial, long ibytes, ov_callbacks callbacks){ - int offsettest=((f && callbacks.seek_func)?callbacks.seek_func(f,0,SEEK_CUR):-1); + int offsettest=((f && callbacks.seek_func)?callbacks.seek_func(f,0,VSEEK_CUR):-1); uint32_t *serialno_list=NULL; int serialno_list_size=0; int ret;