int NSFLoad(int fp) { int x; FCEU_fseek(fp,0,SEEK_SET); FCEU_fread(&NSFHeader,1,0x80,fp); if(memcmp(NSFHeader.ID,"NESM\x1a",5)) return 0; NSFHeader.SongName[31]=NSFHeader.Artist[31]=NSFHeader.Copyright[31]=0; LoadAddr=NSFHeader.LoadAddressLow; LoadAddr|=NSFHeader.LoadAddressHigh<<8; if(LoadAddr<0x6000) { FCEUD_PrintError("Invalid load address."); return(0); } InitAddr=NSFHeader.InitAddressLow; InitAddr|=NSFHeader.InitAddressHigh<<8; PlayAddr=NSFHeader.PlayAddressLow; PlayAddr|=NSFHeader.PlayAddressHigh<<8; NSFSize=FCEU_fgetsize(fp)-0x80; NSFMaxBank=((NSFSize+(LoadAddr&0xfff)+4095)/4096); NSFMaxBank=uppow2(NSFMaxBank); if(!(NSFDATA=(uint8 *)FCEU_malloc(NSFMaxBank*4096))) return 0; FCEU_fseek(fp,0x80,SEEK_SET); memset(NSFDATA,0x00,NSFMaxBank*4096); FCEU_fread(NSFDATA+(LoadAddr&0xfff),1,NSFSize,fp); NSFMaxBank--; BSon=0; for(x=0;x<8;x++) BSon|=NSFHeader.BankSwitch[x]; FCEUGameInfo.type=GIT_NSF; FCEUGameInfo.input[0]=FCEUGameInfo.input[1]=SI_GAMEPAD; FCEUGameInfo.cspecial=SIS_NSF; for(x=0;;x++) { if(NSFROM[x]==0x20) { NSFROM[x+1]=InitAddr&0xFF; NSFROM[x+2]=InitAddr>>8; NSFROM[x+8]=PlayAddr&0xFF; NSFROM[x+9]=PlayAddr>>8; break; } }
int NSFLoad(const char *name, FCEUFILE *fp) { int x; fprintf(stderr,"NSFLoad ...\n"); FCEU_fseek(fp,0,SEEK_SET); FCEU_fread(&NSFHeader,1,0x80,fp); if(memcmp(NSFHeader.ID,"NESM\x1a",5)) return 0; NSFHeader.SongName[31]=NSFHeader.Artist[31]=NSFHeader.Copyright[31]=0; LoadAddr=NSFHeader.LoadAddressLow; LoadAddr|=NSFHeader.LoadAddressHigh<<8; if(LoadAddr<0x6000) { FCEUD_PrintError("Invalid load address."); return(0); } InitAddr=NSFHeader.InitAddressLow; InitAddr|=NSFHeader.InitAddressHigh<<8; PlayAddr=NSFHeader.PlayAddressLow; PlayAddr|=NSFHeader.PlayAddressHigh<<8; NSFSize=FCEU_fgetsize(fp)-0x80; NSFMaxBank=((NSFSize+(LoadAddr&0xfff)+4095)/4096); NSFMaxBank=PRGsize[0]=uppow2(NSFMaxBank); if(!(NSFDATA=(uint8 *)FCEU_malloc(NSFMaxBank*4096))) return 0; FCEU_fseek(fp,0x80,SEEK_SET); memset(NSFDATA,0x00,NSFMaxBank*4096); FCEU_fread(NSFDATA+(LoadAddr&0xfff),1,NSFSize,fp); NSFMaxBank--; BSon=0; for(x=0;x<8;x++) { BSon|=NSFHeader.BankSwitch[x]; } if(BSon==0) { BankCounter=0x00; if ((NSFHeader.LoadAddressHigh & 0x70) >= 0x70) { //Ice Climber, and other F000 base address tunes need this BSon=0xFF; } else { for(x=(NSFHeader.LoadAddressHigh & 0x70) / 0x10;x<8;x++) { NSFHeader.BankSwitch[x]=BankCounter; BankCounter+=0x01; } BSon=0; } } for(x=0;x<8;x++) BSon|=NSFHeader.BankSwitch[x]; GameInfo->type=GIT_NSF; GameInfo->input[0]=GameInfo->input[1]=SI_GAMEPAD; GameInfo->cspecial=SIS_NSF; for(x=0;;x++) { if(NSFROM[x]==0x20) { NSFROM[x+1]=InitAddr&0xFF; NSFROM[x+2]=InitAddr>>8; NSFROM[x+8]=PlayAddr&0xFF; NSFROM[x+9]=PlayAddr>>8; break; } }