Ejemplo n.º 1
0
void SaveLCD(SAVESTATE_t* save, LCD_t* lcd) {
	if (!lcd) return;
	CHUNK_t* chunk = NewChunk(save, LCD_tag);

	WriteInt(chunk, lcd->active);
	WriteInt(chunk, lcd->word_len);
	WriteInt(chunk, lcd->x);
	WriteInt(chunk, lcd->y);
	WriteInt(chunk, lcd->z);
	WriteInt(chunk, lcd->cursor_mode);
	WriteInt(chunk, lcd->contrast);
	WriteInt(chunk, lcd->base_level);
	WriteBlock(chunk, lcd->display, DISPLAY_SIZE);

	WriteInt(chunk, lcd->front);
	WriteBlock(chunk, (unsigned char *) lcd->queue, LCD_MAX_SHADES * DISPLAY_SIZE);
	
	WriteInt(chunk, lcd->shades);
	WriteInt(chunk, lcd->mode);
	WriteDouble(chunk, lcd->time);
	WriteDouble(chunk, lcd->ufps);
	WriteDouble(chunk, lcd->ufps_last);
	WriteDouble(chunk, lcd->lastgifframe);
	WriteDouble(chunk, lcd->write_avg);
	WriteDouble(chunk, lcd->write_last);
}
Ejemplo n.º 2
0
TInt DMemModelProcess::CreateDataBssStackArea(TProcessCreateInfo& aInfo)
	{
	__KTRACE_OPT(KPROC,Kern::Printf("DMemModelProcess::CreateDataBssStackArea %O",this));
	TInt dataBssSize=Mmu::RoundToPageSize(aInfo.iTotalDataSize);
	TInt maxSize=dataBssSize+PP::MaxStackSpacePerProcess;
	TBool fixed=(iAttributes & EFixedAddress);

	__KTRACE_OPT(KPROC,Kern::Printf("DataBssSize=%x, chunk max size %x",dataBssSize,maxSize));

	SChunkCreateInfo cinfo;
	cinfo.iGlobal=EFalse;
	cinfo.iAtt=TChunkCreate::EDisconnected;
	cinfo.iForceFixed=EFalse;
	cinfo.iOperations=SChunkCreateInfo::EAdjust|SChunkCreateInfo::EAdd;
	cinfo.iType=EUserData;
	cinfo.iMaxSize=maxSize;
	cinfo.iInitialBottom=0;
	cinfo.iInitialTop=dataBssSize;
	cinfo.iPreallocated=0;
	cinfo.iName.Set(KDollarDat);
	cinfo.iOwner=this;
	if (fixed && dataBssSize!=0 && aInfo.iCodeLoadAddress)
		{
		const TRomImageHeader& rih=*(const TRomImageHeader*)aInfo.iCodeLoadAddress;
		cinfo.iRunAddress=rih.iDataBssLinearBase;
		}
	else
		cinfo.iRunAddress=0;
	TInt r=NewChunk((DChunk*&)iDataBssStackChunk,cinfo,iDataBssRunAddress);
	return r;
	}
Ejemplo n.º 3
0
 Address
 Zone::NewExpand(int size)
 { 
   static const int kChunkHeaderSize = sizeof(Chunk) + kAlignment;
   
   int old_size = (head_ != 0) ? head_->size() : 0 ;
   // double Chunk allocation size incrementally until we reach a certain limit
   int new_size = size + (old_size << 1);
         
   // do not allocate something that is too small
   if (new_size < kMinimumChunkSize) {
     new_size = kMinimumChunkSize;
   } else if (new_size > Zone::kMaximumChunkSize) {
     // do not allocate something that is too large unless specifically requested
     new_size = max(kChunkHeaderSize + size, kMaximumChunkSize);
   }
   // allocate chunk
   Chunk*  chunk = NewChunk(new_size);
   // align 'top_' and 'end_' according to new Chunk
   Address start = round_up(chunk->begin(), kAlignment);
   pos_ = start + size;
   end_ = chunk->end();      
   ASSERT(pos_ <= end_);
   return start;
 }
Ejemplo n.º 4
0
void SaveTIMER(SAVESTATE_t *save, timerc *time) {
	if (!time) return;
	CHUNK_t* chunk = NewChunk(save,TIMER_tag);
	WriteLong(chunk, time->tstates);
	WriteLong(chunk, time->freq);
	WriteDouble(chunk, tc_elapsed(time));
	WriteDouble(chunk, time->lasttime);
}
Ejemplo n.º 5
0
void SaveCPU(SAVESTATE_t* save, CPU_t* cpu) {
	int i;
	if (!cpu) return;
	CHUNK_t* chunk = NewChunk(save,CPU_tag);
	
	WriteChar(chunk, cpu->a);
	WriteChar(chunk, cpu->f);
	WriteChar(chunk, cpu->b);
	WriteChar(chunk, cpu->c);
	WriteChar(chunk, cpu->d);
	WriteChar(chunk, cpu->e);
	WriteChar(chunk, cpu->h);
	WriteChar(chunk, cpu->l);
	
	WriteChar(chunk, cpu->ap);
	WriteChar(chunk, cpu->fp);
	WriteChar(chunk, cpu->bp);
	WriteChar(chunk, cpu->cp);
	WriteChar(chunk, cpu->dp);
	WriteChar(chunk, cpu->ep);
	WriteChar(chunk, cpu->hp);
	WriteChar(chunk, cpu->lp);
	
	WriteChar(chunk, cpu->ixl);
	WriteChar(chunk, cpu->ixh);
	WriteChar(chunk, cpu->iyl);
	WriteChar(chunk, cpu->iyh);

	WriteShort(chunk, cpu->pc);
	WriteShort(chunk, cpu->sp);

	WriteChar(chunk, cpu->i);
	WriteChar(chunk, cpu->r);
	WriteChar(chunk, cpu->bus);
	
	WriteInt(chunk, cpu->imode);

	WriteInt(chunk, cpu->interrupt);
	WriteInt(chunk, cpu->ei_block);
	WriteInt(chunk, cpu->iff1);
	WriteInt(chunk, cpu->iff2);
	WriteInt(chunk, cpu->halt);
	
	WriteInt(chunk, cpu->read);
	WriteInt(chunk, cpu->write);
	WriteInt(chunk, cpu->output);
	WriteInt(chunk, cpu->input);
	WriteInt(chunk, cpu->prefix);

	
	/* pio */
	for(i = 0; i < 256; i++) {
		interrupt_t *val = &cpu->pio.interrupt[i];
		WriteInt(chunk, val->interrupt_val);
		WriteInt(chunk, val->skip_factor);
		WriteInt(chunk, val->skip_count);
	}
}
Ejemplo n.º 6
0
void SaveSTDINT(SAVESTATE_t* save, STDINT_t *stdint) {
	int i;
	if (!stdint) return;
	CHUNK_t* chunk = NewChunk(save, STDINT_tag);
	WriteChar(chunk, stdint->intactive);

	WriteDouble(chunk, stdint->lastchk1);
	WriteDouble(chunk, stdint->timermax1);
	WriteDouble(chunk, stdint->lastchk2);
	WriteDouble(chunk, stdint->timermax2);
	for(i = 0; i < 4; i++) {
		WriteDouble(chunk, stdint->freq[i]);
	}
	WriteInt(chunk, stdint->mem);
	WriteInt(chunk, stdint->xy);
}
Ejemplo n.º 7
0
void *CHeap::Allocate(unsigned Size)
{
	char *pMem;

	// try to allocate from current chunk
	pMem = (char *)AllocateFromChunk(Size);
	if(!pMem)
	{
		// allocate new chunk and add it to the heap
		NewChunk();
		
		// try to allocate again
		pMem = (char *)AllocateFromChunk(Size);
	}
	
	return pMem;
}
Ejemplo n.º 8
0
TInt DMemModelProcess::CreateDllDataChunk()
//
// Call with CodeSegLock held
//
	{
	__KTRACE_OPT(KDLL,Kern::Printf("DMemModelProcess %O CreateDllDataChunk",this));
	Mmu& m = Mmu::Get();
	SChunkCreateInfo c;
	c.iGlobal=EFalse;
	c.iAtt=TChunkCreate::EDisconnected;
	c.iForceFixed=EFalse;
	c.iOperations=SChunkCreateInfo::EAdjust|SChunkCreateInfo::EAdd;
	c.iRunAddress=0;
	c.iPreallocated=0;
	c.iType=EDllData;
	c.iMaxSize=(iAttributes&EFixedAddress) ? 1 : m.iMaxDllDataSize;	// minimal size for fixed processes
	c.iName.Set(KLitDllDollarData);
	c.iOwner=this;
	c.iInitialBottom=0;
	c.iInitialTop=0;
	TLinAddr runAddr;
	return NewChunk((DChunk*&)iDllDataChunk,c,runAddr);
	}
Ejemplo n.º 9
0
void SaveSE_AUX(SAVESTATE_t* save, SE_AUX_t *se_aux) {
	int i;
	if (!se_aux) return;
	CHUNK_t* chunk = NewChunk(save, SE_AUX_tag);
	
	if (save->model > TI_83P) {
		WriteChar(chunk, se_aux->clock.enable);
		WriteInt(chunk, (uint32_t)se_aux->clock.set);
		WriteInt(chunk, (uint32_t)se_aux->clock.base);
		WriteDouble(chunk, se_aux->clock.lasttime);
	
		for(i = 0; i < 7; i++) {
			WriteChar(chunk, se_aux->delay.reg[i]);
		}
	
		for(i = 0; i < 6; i++) {
			WriteInt(chunk, se_aux->md5.reg[i]);
		}
		WriteChar(chunk, se_aux->md5.s);
		WriteChar(chunk, se_aux->md5.mode);
	}
	
	
	WriteChar(chunk, se_aux->linka.link_enable);
	WriteChar(chunk, se_aux->linka.in);
	WriteChar(chunk, se_aux->linka.out);
	WriteChar(chunk, se_aux->linka.working);
	WriteInt(chunk, se_aux->linka.receiving);
	WriteInt(chunk, se_aux->linka.read);
	WriteInt(chunk, se_aux->linka.ready);
	WriteInt(chunk, se_aux->linka.error);
	WriteInt(chunk, se_aux->linka.sending);
	WriteDouble(chunk, se_aux->linka.last_access);
	WriteInt(chunk, se_aux->linka.bit);

	if (save->model < TI_83PSE)
		return;
	
	WriteDouble(chunk, se_aux->xtal.lastTime);
	WriteLong(chunk, se_aux->xtal.ticks);
	for(i = 0; i < 3; i++) {
		WriteLong(chunk, se_aux->xtal.timers[i].lastTstates);
		WriteDouble(chunk, se_aux->xtal.timers[i].lastTicks);
		WriteDouble(chunk, se_aux->xtal.timers[i].divsor);
		WriteInt(chunk, se_aux->xtal.timers[i].loop);
		WriteInt(chunk, se_aux->xtal.timers[i].interrupt);
		WriteInt(chunk, se_aux->xtal.timers[i].underflow);
		WriteInt(chunk, se_aux->xtal.timers[i].generate);
		WriteInt(chunk, se_aux->xtal.timers[i].active);
		WriteChar(chunk, se_aux->xtal.timers[i].clock);
		WriteChar(chunk, se_aux->xtal.timers[i].count);
		WriteChar(chunk, se_aux->xtal.timers[i].max);
	}
	WriteInt(chunk, se_aux->model_bits);
	chunk = NewChunk(save, USB_tag);
	WriteInt(chunk, se_aux->usb.USBLineState);
	WriteInt(chunk, se_aux->usb.USBEvents);
	WriteInt(chunk, se_aux->usb.USBEventMask);
	WriteInt(chunk, se_aux->usb.LineInterrupt);
	WriteInt(chunk, se_aux->usb.ProtocolInterrupt);
	WriteInt(chunk, se_aux->usb.ProtocolInterruptEnabled);
	WriteInt(chunk, se_aux->usb.DevAddress);
	WriteChar(chunk, se_aux->usb.Port4A);
	WriteChar(chunk, se_aux->usb.Port4C);
	WriteChar(chunk, se_aux->usb.Port54);
}
Ejemplo n.º 10
0
void SaveLINK(SAVESTATE_t* save, link_t* link) {
	CHUNK_t* chunk = NewChunk(save, LINK_tag);
	WriteChar(chunk, link->host);
}
Ejemplo n.º 11
0
void SaveMEM(SAVESTATE_t* save, memc* mem) {
	int i;
	if (!mem) return;
	CHUNK_t *chunk = NewChunk(save, MEM_tag);

	WriteInt(chunk, mem->flash_size);
	WriteInt(chunk, mem->flash_pages);
	WriteInt(chunk, mem->ram_size);
	WriteInt(chunk, mem->ram_pages);
	WriteInt(chunk, mem->step);
	WriteChar(chunk, mem->cmd);
	
	WriteInt(chunk, mem->boot_mapped);
	WriteInt(chunk, mem->flash_locked);
	WriteInt(chunk, mem->flash_version);	

	for(i = 0; i < 5; i++) {
		WriteInt(chunk, mem->normal_banks[i].page);
		WriteInt(chunk, mem->normal_banks[i].read_only);
		WriteInt(chunk, mem->normal_banks[i].ram);
		WriteInt(chunk, mem->normal_banks[i].no_exec);
	}
	
	WriteInt(chunk, mem->read_OP_flash_tstates);
	WriteInt(chunk, mem->read_NOP_flash_tstates);
	WriteInt(chunk, mem->write_flash_tstates);
	WriteInt(chunk, mem->read_OP_ram_tstates);
	WriteInt(chunk, mem->read_NOP_ram_tstates);
	WriteInt(chunk, mem->write_ram_tstates);
	
	WriteInt(chunk, mem->flash_upper);
	WriteInt(chunk, mem->flash_lower);

	chunk = NewChunk(save, ROM_tag);
	WriteBlock(chunk, mem->flash, mem->flash_size);

	chunk = NewChunk(save, RAM_tag);
	WriteBlock(chunk, mem->ram, mem->ram_size);
	
	chunk = NewChunk(save, REMAP_tag);
	WriteInt(chunk, mem->port27_remap_count);
	WriteInt(chunk, mem->port28_remap_count);

	chunk = NewChunk(save, RAM_LIMIT_tag);
	WriteInt(chunk, mem->ram_upper);
	WriteInt(chunk, mem->ram_lower);

	int count = 0;
	chunk = NewChunk(save, FLASH_BREAKS_tag);
	for (int i = 0; i < mem->flash_size; i++)
	{
		if (mem->flash_break[i])
		{
			count++;
			WriteInt(chunk, i);
			WriteInt(chunk, mem->flash_break[i]);
		}
	}
	chunk = NewChunk(save, NUM_FLASH_BREAKS_tag);
	WriteInt(chunk, count);

	count = 0;
	chunk = NewChunk(save, RAM_BREAKS_tag);
	for (int i = 0; i < mem->ram_size; i++)
	{
		if (mem->ram_break[i])
		{
			count++;
			WriteInt(chunk, i);
			WriteInt(chunk, mem->ram_break[i]);
		}
	}
	chunk = NewChunk(save, NUM_RAM_BREAKS_tag);
	WriteInt(chunk, count);
}
Ejemplo n.º 12
0
SAVESTATE_t* ReadSave(FILE *ifile) {
	int i;
	int compressed = false;
	int chunk_offset,chunk_count;
	char string[128];
	char temp_save[PATH_MAX];
	SAVESTATE_t *save;
	CHUNK_t *chunk;
	FILE *tmpfile;

	fread(string, 1, 8, ifile);
	string[8] = 0;
	if (strncmp(DETECT_CMP_STR, string, 8) == 0) {
		i = fgetc(ifile);
		GetAppDataString(temp_save, PATH_MAX - 1 - strlen(tmpSuffix));
		strcat(temp_save, tmpSuffix);
		mkstemp(temp_save);
		tmpfile = fopen(temp_save,"wb");
		if (!tmpfile) {
			return nullptr;
		}
		//int error;
		switch(i) {
#ifdef ZLIB_WINAPI
			case ZLIB_CMP:
				{
					int error = inf(ifile,tmpfile);
					fclose(tmpfile);
					ifile = fopen(temp_save,"rb");	//this is not a leak, file gets closed
													// outside of this routine.
					if (!ifile) {
						return nullptr;
					}
					compressed = true;
					fread(string, 1, 8, ifile);
					break;
				}
#endif
			default:
				fclose(tmpfile);
				remove(temp_save);
				return nullptr;
		}
	}
		
	if (strncmp(DETECT_STR, string, 8) != 0){

		if (compressed == true) fclose(ifile);
		return nullptr;
	}		
	
	save = (SAVESTATE_t *) malloc(sizeof(SAVESTATE_t));
	if (!save) {
		if (compressed == true) fclose(ifile);
		return nullptr;
	}

	chunk_offset = fgeti(ifile);
	
	save->version_major = fgeti(ifile);
	save->version_minor = fgeti(ifile);
	save->version_build = fgeti(ifile);


	if (save->version_major != CUR_MAJOR) {
		fclose(ifile);
		free(save);
		return nullptr;
	}

	save->model = fgeti(ifile);

	chunk_count = fgeti(ifile);
	fread(save->author,1,32,ifile);
	fread(save->comment,1,64,ifile);

	fseek(ifile, chunk_offset + 8 + 4, SEEK_SET);
	
	for(i = 0; i < 512; i++) {
		save->chunks[i] = nullptr;
	}
	save->chunk_count = 0;
	for(i = 0; i < chunk_count; i++) {
		string[0]	= fgetc(ifile);
		string[1]	= fgetc(ifile);
		string[2]	= fgetc(ifile);
		string[3]	= fgetc(ifile);
		string[4]	= 0;
		chunk		= NewChunk(save,string);
		chunk->size	= fgeti(ifile);
		chunk->data	= (unsigned char *) malloc(chunk->size);
		fread(chunk->data,1,chunk->size,ifile);
	}
	if (compressed == true) {
		fclose(ifile);
		remove(temp_save);
	}
/* check for read errors... */
	return save;
}
Ejemplo n.º 13
0
int WriteOutDTD(struct DTDesc *TheDTDesc)
{
    struct IFFHandle *IH;
    struct FileDataTypeHeader FileDTH;
    int i;

    if(!TheDTDesc)
    {
        return(FALSE);
    }

    if(strlen(TheDTDesc->Name)==0)
    {
        return(FALSE);
    }

    if(strlen(TheDTDesc->BaseName)==0)
    {
        return(FALSE);
    }

#if 0
    if(TheDTDesc->DTH.dth_MaskLen==0)
    {
        return(FALSE);
    }
#endif

    if(strlen(TheDTDesc->Pattern)==0)
    {
        TheDTDesc->Pattern[0]='#';
        TheDTDesc->Pattern[1]='?';
        TheDTDesc->Pattern[2]='\0';
    }

    IH=NewIFF(TheDTDesc->OutputName, MAKE_ID('D','T','Y','P'));
    if(!IH)
    {
        return(FALSE);
    }

    if(!NewChunk(IH, MAKE_ID('N','A','M','E')))
    {
        CloseIFF(IH);
        remove(TheDTDesc->Name);
        return(FALSE);
    }

    if(WriteChunkData(IH, TheDTDesc->Name, (strlen(TheDTDesc->Name)+1))<=0)
    {
        EndChunk(IH);
        CloseIFF(IH);
        remove(TheDTDesc->Name);
        return(FALSE);
    }

    EndChunk(IH);

    if(strlen(TheDTDesc->Version) > 0)
    {
        if(!NewChunk(IH, MAKE_ID('F','V','E','R')))
        {
            CloseIFF(IH);
            remove(TheDTDesc->Name);
            return(FALSE);
        }

        if(WriteChunkData(IH, TheDTDesc->Version, (strlen(TheDTDesc->Version)+1))<=0)
        {
            EndChunk(IH);
            CloseIFF(IH);
            remove(TheDTDesc->Name);
            return(FALSE);
        }

        EndChunk(IH);
    }

    if(!NewChunk(IH, MAKE_ID('D','T','H','D')))
    {
        CloseIFF(IH);
        remove(TheDTDesc->Name);
        return(FALSE);
    }

    FileDTH.dth_Name     = (((unsigned int) sizeof(struct FileDataTypeHeader)));
    FileDTH.dth_BaseName = (((unsigned int) FileDTH.dth_Name) + strlen(TheDTDesc->DTH.dth_Name) + 1);
    FileDTH.dth_Pattern  = (((unsigned int) FileDTH.dth_BaseName) + strlen(TheDTDesc->DTH.dth_BaseName) + 1);
    FileDTH.dth_Mask     = (((unsigned int) FileDTH.dth_Pattern) + strlen(TheDTDesc->DTH.dth_Pattern) + 1);
    FileDTH.dth_GroupID  = TheDTDesc->DTH.dth_GroupID;
    FileDTH.dth_ID       = TheDTDesc->DTH.dth_ID;
    FileDTH.dth_MaskLen  = TheDTDesc->DTH.dth_MaskLen;
    FileDTH.dth_Pad      = TheDTDesc->DTH.dth_Pad;
    FileDTH.dth_Flags    = TheDTDesc->DTH.dth_Flags;
    FileDTH.dth_Priority = TheDTDesc->DTH.dth_Priority;

    FileDTH.dth_Name     = Swap32IfLE(((uint32_t) FileDTH.dth_Name));
    FileDTH.dth_BaseName = Swap32IfLE(((uint32_t) FileDTH.dth_BaseName));
    FileDTH.dth_Pattern  = Swap32IfLE(((uint32_t) FileDTH.dth_Pattern));
    FileDTH.dth_Mask     = Swap32IfLE(((uint32_t) FileDTH.dth_Mask));
    FileDTH.dth_GroupID  = Swap32IfLE(FileDTH.dth_GroupID);
    FileDTH.dth_ID       = Swap32IfLE(FileDTH.dth_ID);
    FileDTH.dth_MaskLen  = Swap16IfLE(FileDTH.dth_MaskLen);
    FileDTH.dth_Pad      = Swap16IfLE(FileDTH.dth_Pad);
    FileDTH.dth_Flags    = Swap16IfLE(FileDTH.dth_Flags);
    FileDTH.dth_Priority = Swap16IfLE(FileDTH.dth_Priority);

    if(WriteChunkData(IH, (char *) &FileDTH, sizeof(struct FileDataTypeHeader))<=0)
    {
        EndChunk(IH);
        CloseIFF(IH);
        remove(TheDTDesc->Name);
        return(FALSE);
    }

    if(WriteChunkData(IH, TheDTDesc->DTH.dth_Name, (strlen(TheDTDesc->DTH.dth_Name)+1))<=0)
    {
        EndChunk(IH);
        CloseIFF(IH);
        remove(TheDTDesc->Name);
        return(FALSE);
    }

    if(WriteChunkData(IH, TheDTDesc->DTH.dth_BaseName, (strlen(TheDTDesc->DTH.dth_BaseName)+1))<=0)
    {
        EndChunk(IH);
        CloseIFF(IH);
        remove(TheDTDesc->Name);
        return(FALSE);
    }

    if(WriteChunkData(IH, TheDTDesc->DTH.dth_Pattern, (strlen(TheDTDesc->DTH.dth_Pattern)+1))<=0)
    {
        EndChunk(IH);
        CloseIFF(IH);
        remove(TheDTDesc->Name);
        return(FALSE);
    }

    for(i=0; i<TheDTDesc->DTH.dth_MaskLen; i++)
    {
        TheDTDesc->DTH.dth_Mask[i]=Swap16IfLE(TheDTDesc->DTH.dth_Mask[i]);
    }

    if (TheDTDesc->DTH.dth_MaskLen)
    {
        if(WriteChunkData(IH, (char *) TheDTDesc->DTH.dth_Mask, TheDTDesc->DTH.dth_MaskLen*sizeof(uint16_t))<=0)
        {
            EndChunk(IH);
            CloseIFF(IH);
            remove(TheDTDesc->Name);
            return(FALSE);
        }
    }

    EndChunk(IH);

    CloseIFF(IH);

    return(TRUE);
}
Ejemplo n.º 14
0
void CHeap::Reset()
{
	Clear();
	NewChunk();
}
Ejemplo n.º 15
0
SAVESTATE_t* ReadSave(FILE *ifile) {
	int i;
	int compressed = FALSE;
	int chunk_offset,chunk_count;
	char string[128];
	TCHAR tmpfn[L_tmpnam];
	TCHAR temp_save[MAX_PATH];
	SAVESTATE_t *save;
	CHUNK_t *chunk;
	FILE *tmpfile;

	fread(string, 1, 8, ifile);
	string[8] = 0;
	if (strncmp(DETECT_CMP_STR, string, 8) == 0) {
		i = fgetc(ifile);
#ifdef WINVER
		_ttmpnam_s(tmpfn);
		GetAppDataString(temp_save, sizeof(temp_save));
		StringCbCat(temp_save, sizeof(temp_save), tmpfn);
		_tfopen_s(&tmpfile, temp_save, _T("wb"));
#else
		tmpnam(tmpfn);
		strcpy(temp_save, getenv("appdata"));
		strcat(temp_save, tmpfn);
		tmpfile = fopen(temp_save,"wb");
#endif
		if (!tmpfile) {
			return NULL;
		}
		//int error;
		switch(i) {
#ifdef ZLIB_WINAPI
			case ZLIB_CMP:
				{
					int error = inf(ifile,tmpfile);
					break;
				}
#endif
			default:
				fclose(tmpfile);
#ifdef _WINDOWS
				_tremove(tmpfn);
#else
				remove(tmpfn);
#endif
				return NULL;
		}
		
		fclose(tmpfile);
#ifdef WINVER
		_tfopen_s(&ifile, temp_save, _T("rb"));	//this is not a leak, file gets closed
											// outside of this routine.
#else
		ifile = fopen(temp_save,"rb");	//this is not a leak, file gets closed
										// outside of this routine.
#endif
		if (!ifile) {
			return NULL;
		}
		compressed = TRUE;
		fread(string, 1, 8, ifile);
	}
		
	if (strncmp(DETECT_STR, string, 8) != 0){

		if (compressed == TRUE) fclose(ifile);
		return NULL;
	}		
	
	save = (SAVESTATE_t *) malloc(sizeof(SAVESTATE_t));
	if (!save) {
		if (compressed == TRUE) fclose(ifile);
		return NULL;
	}

	chunk_offset = fgeti(ifile);
	
	save->version_major = fgeti(ifile);
	save->version_minor = fgeti(ifile);
	save->version_build = fgeti(ifile);


	if (save->version_major != CUR_MAJOR) {
		fclose(ifile);
		free(save);
		return NULL;
	}

	save->model = fgeti(ifile);

	chunk_count = fgeti(ifile);
	fread(save->author,1,32,ifile);
	fread(save->comment,1,64,ifile);

	fseek(ifile, chunk_offset + 8 + 4, SEEK_SET);
	
	for(i = 0; i < 512; i++) {
		save->chunks[i] = NULL;
	}
	save->chunk_count = 0;
	for(i = 0; i < chunk_count; i++) {
		string[0]	= fgetc(ifile);
		string[1]	= fgetc(ifile);
		string[2]	= fgetc(ifile);
		string[3]	= fgetc(ifile);
		string[4]	= 0;
		chunk		= NewChunk(save,string);
		chunk->size	= fgeti(ifile);
		chunk->data	= (unsigned char *) malloc(chunk->size);
		fread(chunk->data,1,chunk->size,ifile);
	}
	if (compressed == TRUE) {
		fclose(ifile);
#ifdef _WINDOWS
		_tremove(temp_save);
#else
		remove(temp_save);
#endif
	}
/* check for read errors... */
	return save;
}
Ejemplo n.º 16
0
// LR 1.66 -- complete rewrite (basically) of this entire routine...it was UGLY!
OSStatus HandleMenu( long mSelect, short modifiers )
{
	short			menuID = HiWord( mSelect );
	short			menuItem = LoWord( mSelect );
	short 		colorResID;
	WindowRef		frontWindow;
	DialogPtr		dlgRef = NULL;
	EditWindowPtr	dWin = NULL;

	Str255			currentWindowName, newFrontWindowName;		// NS: v1.6.6, for window menu
	WindowRef		currentWindow;								// NS:			this too
	
	// Predetermine what type of window we have to work with
	frontWindow = FrontNonFloatingWindow();
	if( frontWindow )
	{
		DialogPtr dlg = GetDialogFromWindow( frontWindow );

		if( kHexEditWindowTag == GetWindowKind( frontWindow ) )
			dWin = (EditWindowPtr) GetWRefCon( frontWindow );
		else if( g.gotoDlg == dlg || g.searchDlg == dlg )
			dlgRef = dlg;
	}

	switch( menuID )
	{
		case kAppleMenu:
			if( menuItem == AM_About )
				HexEditAboutBox();
#if !TARGET_API_MAC_CARBON
			else
			{
				GrafPtr savePort;
				Str255 name;

				GetPort( &savePort );
				GetMenuItemText( appleMenu, menuItem, name );
				OpenDeskAcc( name );
				SetPort( savePort );
			}
#endif
			break;
		
	case kFileMenu:
		switch( menuItem )
		{
		case FM_New:
			gPrefs.overwrite = false;  //LR 190 -- overwrite mode makes no sense in a new document
			NewEditWindow();
			break;

		case FM_Open:
			AskEditWindow( kWindowNormal );
			break;

		//	HR/LR 050328 - Handle FM_Disassemble menu item
		case FM_Disassemble:
			g.disassemble = !g.disassemble;
			if ( g.disassemble ) {
				dWin->drawMode = DM_Disassembly;
				dWin->bytesPerLine = kDisBytesPerLine;
				dWin->hexStart = kDisHexStart;
				dWin->asciiStart = kDisASCIIStart;
			} else {
				dWin->drawMode = DM_Dump;
				dWin->bytesPerLine = kHexBytesPerLine;
				dWin->hexStart = kHexHexStart;
				dWin->asciiStart = kHexASCIIStart;
			}
			/* Make sure the editOffset position starts on a new line */
			dWin->editOffset -= dWin->editOffset % dWin->bytesPerLine;
			UpdateEditWindows();
			break;

		case FM_OtherFork:	// LR: I want to see both!
			if( dWin )
			{
				short fork;
//LR 180				EditWindowPtr ewin;

				if( dWin->fork == FT_Data )
					fork = FT_Resource;
				else
					fork = FT_Data;

/*LR 180 -- OpenEditWindow checks for this
				if( NULL != (ewin = LocateEditWindow( &dWin->fsSpec, fork )) )	// LR: 1.7 - boolean typecast causes failure!
				{
					SelectWindow( ewin->oWin.theWin );	// just select existing theWin
				}
				else	// try to open other fork in new theWin!
*/				{
					g.forkMode = fork;
					OpenEditWindow( &dWin->fsSpec, kWindowNormal, true );
				}
			}
			break;

		case FM_CompareFiles:		//LR 180 -- now pass in modifiers to allow select override
			if( GetCompareFiles( modifiers ) )
				DoComparison();
			break;

		//LR: 1.66 - NOTE: dWin == NULL == frontWindow!
		case FM_Save:
			if( dWin && dWin->oWin.Save )
				dWin->oWin.Save( frontWindow );
			break;

		case FM_SaveAs:
			if( dWin && dWin->oWin.SaveAs )
				dWin->oWin.SaveAs( frontWindow );
			break;

		case FM_Revert:
			if( dWin && dWin->oWin.Revert )	//LR 1.72 -- check before reverting (could be dangerous!)
			{
				ParamText( dWin->fsSpec.name, NULL, NULL, NULL );
				switch( CautionAlert( alertRevert, NULL ) )
				{
					case ok:
						dWin->oWin.Revert( frontWindow );
						break;
				}
			}
			break;

		case FM_Close:
			if( dWin )
				CloseEditWindow( frontWindow );
			else if( dlgRef )
			{
				HideWindow( frontWindow );	//LR: 1.7 -- no need.GetDialogWindow( dlgRef ) );
			}
			break;

		case FM_Quit:
			if( CloseAllEditWindows() )
				g.quitFlag = true;
			break;

		case FM_PageSetup:
#if TARGET_API_MAC_CARBON  // sel - carbon session based printing
			_doPageSetupDialog(&g.pageFormat);
#else
			PrOpen();
			PrStlDialog( g.HPrint );
			PrClose();
#endif
			break;

		case FM_Print:
			if( dWin )
				PrintWindow( dWin );
			break;
		}
		break;

	case kEditMenu:
#if !TARGET_API_MAC_CARBON
		if( !SystemEdit( menuItem -1 ) )
#endif
		{
			if( dWin ) switch( menuItem ) 
			{
				case EM_Undo:
					UndoOperation();
					break;

				case EM_Cut:
					CutSelection( dWin );				
					break;

				case EM_Copy:
					CopySelection( dWin );	
					break;

				case EM_Paste:
					PasteSelection( dWin );
					break;

				case EM_Clear:
					ClearSelection( dWin );			
					break;

				case EM_SelectAll:
					dWin->startSel = 0;
					dWin->endSel = dWin->fileSize;
					UpdateOnscreen( dWin->oWin.theWin );
					break;
			}
			else if( dlgRef ) switch( menuItem )
			{
				case EM_Cut:
					DialogCut( dlgRef );
					TEToScrap();
					break;

				case EM_Copy:
					DialogCopy( dlgRef );
					TEToScrap();
					break;

				case EM_Paste:
					TEFromScrap();
					DialogPaste( dlgRef );
					break;

				case EM_Clear:
					DialogDelete( dlgRef );
					break;

				case EM_SelectAll:
					break;
			}
		}
		break;

	case kFindMenu:
		switch ( menuItem )
		{
			case SM_Find:
openfind:
				OpenSearchDialog();
				break;

			case SM_FindForward:
				gPrefs.searchForward = true;
				PerformTextSearch( dWin, kSearchUpdateUI );  //LR 190 -- if dWin is NULL will operate on first edit window, if any (allows search in find dialog)
				break;

			case SM_FindBackward:
				gPrefs.searchForward = false;
				PerformTextSearch( dWin, kSearchUpdateUI );  //LR 190 -- if dWin is NULL will operate on first edit window
				break;

			case SM_Replace:	//LR 190 -- add replace & find next (must have a window with selection to start!)
				if( !dWin )
					dWin = FindFirstEditWindow(); // allow this to work in find dialog, etc.

				if( dWin  && dWin->startSel != dWin->endSel )
				{
					EditChunk	**replaceChunk;

					if( !g.searchBuffer[0] )	// if nothing to find open dialog
						goto openfind;

					replaceChunk = NewChunk( g.replaceText[0], 0, 0, CT_Unwritten );
					if( replaceChunk )
					{
						// Copy replacement text to chunk buffer
						BlockMoveData( g.replaceText+1, *(*replaceChunk)->data, g.replaceText[0] );

						// Do the replacement (with undo)
						g.replaceAll = false;
						RememberOperation( dWin, EO_Paste, &gUndo );
						PasteOperation( dWin, replaceChunk );

						// We're done with the chunk now
						DisposeChunk( NULL, replaceChunk );
					}

					// Then try to find the next occurance (in LAST direction searched!) and display it
					if( !PerformTextSearch( dWin, kSearchUpdateUI ) )
						ScrollToSelection( dWin, dWin->startSel, true );
				}
				break;

			case SM_GotoAddress:
				OpenGotoAddress();
				break;
		}
		break;

	case kOptionsMenu:
		switch ( menuItem )
		{
			case OM_HiAscii:
				gPrefs.asciiMode = !gPrefs.asciiMode;
				if( gPrefs.asciiMode )	g.highChar = 0xFF;
				else					g.highChar = 0x7F;
				UpdateEditWindows();
				break;

			case OM_DecimalAddr:
				gPrefs.decimalAddr = !gPrefs.decimalAddr;
				UpdateEditWindows();
				break;

			case OM_Backups:
				gPrefs.backupFlag = !gPrefs.backupFlag;
				break;

			case OM_WinSize:
				gPrefs.constrainSize = !gPrefs.constrainSize;
				break;

			case OM_Overwrite:
				gPrefs.overwrite = !gPrefs.overwrite;
				break;

			case OM_NonDestructive:
				gPrefs.nonDestructive = !gPrefs.nonDestructive;
				break;

			case OM_MoveOnlyPaging:
				gPrefs.moveOnlyPaging = !gPrefs.moveOnlyPaging;
				break;

			case OM_Unformatted:
				gPrefs.formatCopies = !gPrefs.formatCopies;
				break;

			case OM_VertBars:
				gPrefs.vertBars = !gPrefs.vertBars;
				UpdateEditWindows();
				break;

			case OM_ComparePref:	// LR: compare options
				ComparisonPreferences();
				break;

 			case OM_OpenOnLaunch:
 				gPrefs.dialogAtLaunch = !gPrefs.dialogAtLaunch;	//LR -- 192
 				break;
		}
		break;

	// LR: Add color scheme menu
	case kColorMenu:
		colorResID = GetColorMenuResID( menuItem );

		if( menuItem == CM_UseColor )
		{
			gPrefs.useColor = !gPrefs.useColor;		// toggle color usage
		}
		else if( dWin && dWin->csResID > 0 )		// can't color B&W windows!
		{
			if( _cmCheckedItem )
				CheckMenuItem( colorMenu, _cmCheckedItem, false );

			if( (modifiers & optionKey) )	// option down == change all windows (set default color)
			{
				EditWindowPtr eWin = FindFirstEditWindow();

				while( eWin )
				{
					if( GetWindowKind( eWin->oWin.theWin ) == kHexEditWindowTag )
					{
						eWin->csResID = colorResID;
						eWin->csMenuID = menuItem;	//LR 181 -- for menu tagging
					}

					eWin = FindNextEditWindow( eWin );
				}
				goto savepref;
			}
			else	//LR 181 -- default is (back) to changing color of a single window!
			{
				if( GetWindowKind( dWin->oWin.theWin ) == kHexEditWindowTag )
				{
					dWin->csResID = colorResID;
					dWin->csMenuID = menuItem;	//LR 181 -- for menu tagging
				}
			}
		}
		else
		{
savepref:	//LR 190 -- no window open == set preferred color
			gPrefs.csResID = colorResID;	//LR 180 -- save prefs when changing all
			gPrefs.csMenuID = menuItem;
		}

		UpdateEditWindows();
		break;

	// LR : 1.7 - rewrite with bug checking (could crash accessing NULL window)
	case kWindowMenu:
		GetMenuItemText( windowMenu, menuItem, newFrontWindowName );
		currentWindow = FrontNonFloatingWindow();
		while( currentWindow )
		{
			GetWTitle( currentWindow, currentWindowName );
			if( EqualPStrings( currentWindowName, newFrontWindowName ) )
			{
				SelectWindow( currentWindow );
				break;
			}
			currentWindow = GetNextWindow( currentWindow );
		}
		break;
	}

	HiliteMenu( 0 );
	AdjustMenus();

	return( noErr );
}