// // read magic number from file // return true if this is your image type, false if it is not // bool DICOMParser::IsDICOMFile(DICOMFile* file) { char magic_number[4]; file->SkipToStart(); file->Read(static_cast<void*>(magic_number),4); if (CheckMagic(magic_number)) { return(true); } // try with optional skip else { file->Skip(OPTIONAL_SKIP-4); file->Read(static_cast<void*>(magic_number),4); if (CheckMagic(magic_number)) { return true; } else { #ifndef DICOMPARSER_IGNORE_MAGIC_NUMBER return false; #else // // Try it anyways... // file->SkipToStart(); doublebyte group = file->ReadDoubleByte(); bool dicom; if (group == 0x0002 || group == 0x0008) { dicom_stream::cerr << "No DICOM magic number found, but file appears to be DICOM." << dicom_stream::endl; dicom_stream::cerr << "Proceeding without caution." << dicom_stream::endl; dicom = true; } else { dicom = false; } file->SkipToStart(); return dicom; #endif // DICOMPARSER_IGNORE_MAGIC_NUMBER } } }
// // ReadHeader // // Returns TRUE if successful, or FALSE if there was a problem (in // which case the error message as been setup). // static int ReadHeader(const char *filename) { size_t len; raw_wad_header_t header; len = fread(&header, sizeof(header), 1, in_file); if (len != 1) { SetErrorMsg("Trouble reading wad header for %s [%s]", filename, strerror(errno)); return FALSE; } if (! CheckMagic(header.type)) { SetErrorMsg("%s does not appear to be a wad file (bad magic)", filename); return FALSE; } wad.kind = (header.type[0] == 'I') ? IWAD : PWAD; wad.num_entries = UINT32(header.num_entries); wad.dir_start = UINT32(header.dir_start); // initialise stuff wad.dir_head = NULL; wad.dir_tail = NULL; wad.current_level = NULL; wad.level_names = NULL; wad.num_level_names = 0; return TRUE; }
// load all songs from ROM into memory void GlobalData::LoadSongs() { u16 checkmagic=0; offset = 0; REG_IME = 0; // disable interrupts debug("Loading songs."); // black = starting SetBG(0, 0, 0); ReadNumber(&checkmagic, sizeof(u16)); // check first if there is any saved data in the databank if (checkmagic == magic) { // until we find the end of the songs while (!CheckMagic()) { // red = song SetBG(10, 0, 0); // start a new song debug("Creating a new song struct."); NewSong(); debug("Reading basic song data."); // read in the song name ReadString(¤tsong->name); debug("Song Name: %s", currentsong->name); // write bpm ReadNumber(¤tsong->bpm, sizeof(u16)); debug("Song Speed: %d", currentsong->bpm); // until we find the end of the loops while (!CheckMagic()) { // green = loop SetBG(0, 10, 0); // create a new loop debug("Creating a new loop struct."); NewLoop(); debug("Reading basic loop data."); // write the loop name ReadString(¤tloop->name); // write the sample number ReadNumber(¤tloop->sample, sizeof(u16)); // write the panning direction ReadNumber(¤tloop->pan, sizeof(bool)); // write the pitch ReadNumber(¤tloop->pitch, sizeof(u16)); // write the number of divisions ReadNumber(¤tloop->divisions, sizeof(u16)); while (!CheckMagic()) { // blue = note SetBG(0, 0, 10); // create a new note debug("Creating a new note struct."); NewNote(); debug("Reading basic note data."); // write the note end action; ReadNumber(¤tnote->noteEnd, sizeof(u8)); // write the beat offset ReadNumber(¤tnote->offset, sizeof(u8)); // write the pitch ReadNumber(¤tnote->pitch, sizeof(u8)); // write the swing ReadNumber(¤tnote->swing, sizeof(u8)); } } } } // if we don't have a default song set yet if (!songdata) { debug("No load data; creating a new song."); NewSong(); } REG_IME = 1; // enable interrupts }