static boolean WriteTime(unsigned int time, MEMFILE *midioutput) { unsigned int buffer = time & 0x7F; byte writeval; while ((time >>= 7) != 0) { buffer <<= 8; buffer |= ((time & 0x7F) | 0x80); } for (;;) { writeval = (byte)(buffer & 0xFF); if (mem_fwrite(&writeval, 1, 1, midioutput) != 1) { return true; } ++tracksize; if ((buffer & 0x80) != 0) { buffer >>= 8; } else {
static int SubWrite(MEMFILE *st, SFORMAT *sf) { uint32 acc=0; while(sf->v) { if(sf->s==~0) /* Link to another struct. */ { uint32 tmp; if(!(tmp=SubWrite(st,(SFORMAT *)sf->v))) return(0); acc+=tmp; sf++; continue; } acc+=8; /* Description + size */ acc+=sf->s&(~RLSB); if(st) /* Are we writing or calculating the size of this block? */ { mem_fwrite(sf->desc,1,4,st); mem_write32le(sf->s&(~RLSB),st); #ifndef LSB_FIRST if(sf->s&RLSB) FlipByteOrder(sf->v,sf->s&(~RLSB)); #endif mem_fwrite((uint8 *)sf->v,1,sf->s&(~RLSB),st); /* Now restore the original byte order. */ #ifndef LSB_FIRST if(sf->s&RLSB) FlipByteOrder(sf->v,sf->s&(~RLSB)); #endif } sf++; } return(acc); }
size_t abfwrite(void const *buf, size_t n1, size_t n2, File *f) { switch(f->type) { case FileType_Mem: return mem_fwrite(buf,n1,n2,f); case FileType_CRT: return fwrite(buf,n1,n2,f->fp.crt); default: abassertmsg(0,"unknown file type %i",f->type); return 0; }; }
void SaveState(const char *fname) { MEMFILE *st=NULL; TempAddrT=TempAddr; RefreshAddrT=RefreshAddr; if(geniestage==1) { FCEU_DispMessage("Cannot save FCS in GG screen."); return; } st=mem_fopen_write(fname); if(st!=NULL) { static uint32 totalsize; static uint8 header[16]="FCS"; memset(header+4,0,13); header[3]=VERSION_NUMERIC; mem_fwrite(header,1,16,st); #ifdef ASM_6502 asmcpu_pack(); #endif totalsize=WriteStateChunk(st,1,SFCPU); totalsize+=WriteStateChunk(st,2,SFCPUC); totalsize+=WriteStateChunk(st,3,FCEUPPU_STATEINFO); totalsize+=WriteStateChunk(st,4,FCEUCTRL_STATEINFO); totalsize+=WriteStateChunk(st,5,SFSND); if(SPreSave) SPreSave(); totalsize+=WriteStateChunk(st,0x10,SFMDATA); if(SPostSave) SPostSave(); mem_fseek(st,4,SEEK_SET); mem_write32(totalsize,st); SaveStateStatus[CurrentState]=1; mem_fclose(st); } }