Beispiel #1
0
  long __declspec(dllexport) DLL_LoadGYM(const char *szFileName)
  {    
    GYMSong* result = new GYMSong;
    FILE* f = fopen(szFileName,"rb");
    int iResult = 0;
    if (f)
    {
      WaitForSingleObject(hMutex,INFINITE);
      fseek(f,0,SEEK_END);
      result->gymSize = ftell(f);
      fseek(f,0,SEEK_SET);
      result->gym = (unsigned char*)malloc(result->gymSize*sizeof(unsigned char));
      unsigned int iRead = 0;
      result->gymPos = result->gym;
      while (iRead < result->gymSize)
      {
        fread(result->gym,1,result->gymSize,f);
        int iCurrRead = fread(result->gymPos,1,16384,f);
        if (iCurrRead > 0)
        {
          iRead += iCurrRead;
          ReleaseMutex(hMutex);
          Sleep(10); // prevent starving pap during xfade
          WaitForSingleObject(hMutex,INFINITE);
        }
        else
          break;
      }

      fclose(f);
      result->gymTag = (GYMSong::GYMTAG*)result->gym;
      if (strncmp(((GYMSong::GYMTAG*)result->gym)->gym_id, "GYMX", 4) == 0)
      {
        result->gymStart = result->gymPos = result->gym+sizeof(GYMSong::GYMTAG);
        result->gymSize -= sizeof(GYMSong::GYMTAG);
        result->iLength = calc_gym_time_length(result);
      }
      else
      {
        result->gymStart = result->gymPos = result->gym;
        result->gymTag = NULL;
      }

      
      result->YM2612 = YM2612;
      result->PSG = PSG;
      Start_Play_GYM(48000);
      iResult = (long)result;
      ReleaseMutex(hMutex);
    }

    return (int)iResult;
  }
Beispiel #2
0
		int input_gym::open_file(CFILE *r, SONGINFO *info, unsigned int flags)
		{
			__int64 size64 = r->get_length();
			if (size64 < 0) return 0;
			unsigned int size = (unsigned int)size64;

			if (!gym_backup.new_block(size))
				return 0;

			void *gymFile = gym_backup.get_ptr();

			if (r->read(gymFile, size) != size)
			{
				r->seek(0);
				return 0;
			}

			gym_tag = (GYMTAG *)gym_backup.get_ptr();

			if (memcmp(gym_tag->gym_id, "GYMX", 4) == 0)
			{
				// strings might not be null-terminated...
				char tempStr[257];

				memcpy(tempStr, gym_tag->song_title, 32);
				tempStr[32] = '\0';
				if (strcmp(tempStr, "") != 0)
				{
					info->meta_add_ansi("TITLE", tempStr);
				}

				memcpy(tempStr, gym_tag->game_title, 32);
				tempStr[32] = '\0';
				if (strcmp(tempStr, "") != 0)
				{
					info->meta_add_ansi("ALBUM", tempStr);
				}

				memcpy(tempStr, gym_tag->game_publisher, 32);
				tempStr[32] = '\0';
				if (strcmp(tempStr, "") != 0)
				{
					info->meta_add_ansi("PUBLISHER", tempStr);
				}

				memcpy(tempStr, gym_tag->dumper_emu, 32);
				tempStr[32] = '\0';
				if (strcmp(tempStr, "") != 0)
				{
					info->meta_add_ansi("EMULATOR", tempStr);
				}

				memcpy(tempStr, gym_tag->dumper_person, 32);
				tempStr[32] = '\0';
				if (strcmp(tempStr, "") != 0)
				{
					info->meta_add_ansi("DUMPER", tempStr);
				}

				memcpy(tempStr, gym_tag->comments, 256);
				tempStr[256] = '\0';
				if (strcmp(tempStr, "") != 0)
				{
					info->meta_add_ansi("COMMENT", tempStr);
				}

				gym_loop = gym_tag->looped;

				if (gym_loop)
				{
					sprintf(tempStr, "%.2f seconds", gym_loop / 60.0);
					info->meta_add_ansi("LOOPSAT", tempStr);
				}

				if (gym_tag->compressed)
				{
					gym_compressed = true;
					if (memcmp((char *)((int)gym_tag + sizeof(GYMTAG)), "EZPK", 4) == 0)
					{
						info->meta_add_ansi("COMPRESSION", "EZPK");

						if (!gym_loaded)
						{
							if (!load_ezpk_gym(gymFile)) return 0;
							calc_gym_time_length(info);
							gym_loaded = true;
						}
					}
					else
					{
						info->meta_add_ansi("COMPRESSION", "ZLIB");

						if (!gym_loaded)
						{
							if (!load_zlib_gym(gymFile)) return 0;

							calc_gym_time_length(info);
							gym_loaded = true;
						}
					}
				}
				else
				{
					gym_compressed = false;
					info->meta_add_ansi("COMPRESSION", "none");

					gym_start = (unsigned char *)gymFile + sizeof(GYMTAG);
					gym_size = gym_backup.get_size() - sizeof(GYMTAG);

					if (!gym_loaded)
					{
						calc_gym_time_length(info);
						gym_loaded = true;
					}
				}

			}
			else
			{
				gym_tag = 0;
				gym_loop = 0;

				gym_compressed = false;
				info->meta_add_ansi("COMPRESSION", "none");

				gym_start = (unsigned char *)gymFile;
				gym_size = gym_backup.get_size();

				if (!gym_loaded)
				{
					calc_gym_time_length(info);
					gym_loaded = true;
				}
			}

			info->info_set("codec", "GYM");
			info->info_set("extrainfo", "GYM");

			return 1;
		}