00001 // 00002 // Copyright 2002 Sony Corporation 00003 // 00004 // Permission to use, copy, modify, and redistribute this software for 00005 // non-commercial use is hereby granted. 00006 // 00007 // This software is provided "as is" without warranty of any kind, 00008 // either expressed or implied, including but not limited to the 00009 // implied warranties of fitness for a particular purpose. 00010 // 00011 00012 #include <string.h> 00013 #include <ODA.h> 00014 00015 ODA::ODA() : toc(0) 00016 { 00017 } 00018 00019 ODA::ODA(byte* oda) 00020 { 00021 Set(oda); 00022 } 00023 00024 void 00025 ODA::Set(byte* oda) 00026 { 00027 toc = (ODATOC*)oda; 00028 } 00029 00030 int 00031 ODA::Find(char* name) const 00032 { 00033 if (toc == 0) return -1; 00034 if (toc->info.magic != ODA_MAGIC_ODAR) return -1; 00035 00036 for (int i = 0; i < toc->info.numFiles; i++) { 00037 if (strcmp(name, toc->entry[i].name) == 0) return i; 00038 } 00039 00040 return -1; 00041 } 00042 00043 int 00044 ODA::Find(ODAMagic magic, char* name) const 00045 { 00046 if (toc == 0) return -1; 00047 if (toc->info.magic != ODA_MAGIC_ODAR) return -1; 00048 00049 if (magic == ODA_MAGIC_OSND) { 00050 00051 for (int i = 0; i < toc->info.numFiles; i++) { 00052 if (toc->entry[i].magic == ODA_MAGIC_WAVE && 00053 strcmp(name, toc->entry[i].name) == 0) return i; 00054 } 00055 00056 for (int i = 0; i < toc->info.numFiles; i++) { 00057 if (toc->entry[i].magic == ODA_MAGIC_MIDI && 00058 strcmp(name, toc->entry[i].name) == 0) return i; 00059 } 00060 00061 } else { 00062 00063 for (int i = 0; i < toc->info.numFiles; i++) { 00064 if (toc->entry[i].magic == magic && 00065 strcmp(name, toc->entry[i].name) == 0) return i; 00066 } 00067 } 00068 00069 return -1; 00070 } 00071 00072 int 00073 ODA::GetNumFiles() const 00074 { 00075 if (toc == 0) return -1; 00076 if (toc->info.magic != ODA_MAGIC_ODAR) return -1; 00077 return toc->info.numFiles; 00078 } 00079 00080 ODAMagic 00081 ODA::GetMagic(int index) const 00082 { 00083 if (toc == 0) return ODA_MAGIC_UNDEF; 00084 if (toc->info.magic != ODA_MAGIC_ODAR) return ODA_MAGIC_UNDEF; 00085 if (index >= toc->info.numFiles) return ODA_MAGIC_UNDEF; 00086 00087 return toc->entry[index].magic; 00088 } 00089 00090 char* 00091 ODA::GetName(int index) const 00092 { 00093 if (toc == 0) return 0; 00094 if (toc->info.magic != ODA_MAGIC_ODAR) return 0; 00095 if (index >= toc->info.numFiles) return 0; 00096 00097 return toc->entry[index].name; 00098 } 00099 00100 int 00101 ODA::GetSize(int index) const 00102 { 00103 if (toc == 0) return -1; 00104 if (toc->info.magic != ODA_MAGIC_ODAR) return -1; 00105 if (index >= toc->info.numFiles) return -1; 00106 00107 return toc->entry[index].size; 00108 } 00109 00110 byte* 00111 ODA::GetData(int index) const 00112 { 00113 if (toc == 0) return 0; 00114 if (toc->info.magic != ODA_MAGIC_ODAR) return 0; 00115 if (index >= toc->info.numFiles) return 0; 00116 00117 byte* ptr = (byte*)toc; 00118 return ptr + toc->entry[index].offset; 00119 } 00120 00121 int 00122 ODA::GetOffset(int index) const 00123 { 00124 if (toc == 0) return -1; 00125 if (toc->info.magic != ODA_MAGIC_ODAR) return -1; 00126 if (index >= toc->info.numFiles) return -1; 00127 00128 return toc->entry[index].offset; 00129 }