コード例 #1
0
ファイル: vSDP_struct.cpp プロジェクト: nberth/apron4opam
//---------------------------------------------------------------------//
void GeneralMatrix::initialize(bool sparse, int nb, int* blStruct)
{
  CheckVectorRange(nb);
  nBlock = nb;
  isSparse = sparse;
  if (blockStruct) delete[] blockStruct; 
  blockStruct = new int[nb];
  CheckMemory(blockStruct);
  if (!isSparse)
  {
    mat.resize(nBlock);
  }
  else
  {
    smat.resize(nBlock);
  }
  for (int j=0; j<nBlock; j++)
  {
    blockStruct[j] = blStruct[j];
    int nRow = abs(blStruct[j]);
    if (!isSparse)
    {
      Resize(mat[j], nRow, nRow);
      Initialize(mat[j], 0);
    }
    else
    {
      Resize(smat[j], nRow, nRow);
    }
  }
}
コード例 #2
0
ファイル: vSDP_struct.cpp プロジェクト: nberth/apron4opam
//----------------------------------------------------------------------
GeneralMatrix::GeneralMatrix(const GeneralMatrix &source)
{
  isSparse = source.isSparse;
  nBlock = source.nBlock;
  blockStruct = new int[nBlock];
  CheckMemory(blockStruct);
  if (isSparse)
  {
    mat.clear();
    smat.resize(nBlock);
  }
  else
  {
    smat.clear();
    mat.resize(nBlock);
  }
  for(int j=0; j<nBlock; j++)
  {
    blockStruct[j] = source.blockStruct[j];
    if (isSparse)
    {
      smat[j] = SPARSE_INTERVAL_MATRIX(source.smat[j]);
    }
    else
    {
      mat[j] = INTERVAL_MATRIX(source.mat[j]);
    }
  }
}
コード例 #3
0
ファイル: vSDP_struct.cpp プロジェクト: nberth/apron4opam
//----------------------------------------------------------------------
void GeneralMatrix::initialize(rBlockSparseMatrix &M, bool sparse, bool inverse)
{
  CheckVectorRange(M.nBlock);
  nBlock = M.nBlock;
  if (blockStruct) delete[] blockStruct;
  blockStruct = new int[nBlock];
  CheckMemory(blockStruct);
  for (int l=0; l<nBlock; ++l) blockStruct[l] = abs(M.blockStruct[l]);
  if(sparse)
  {
    isSparse = true;
    smat.resize(nBlock);  
    mat.clear();
    for (int l=0; l<nBlock; ++l) 
    {
      matrixCopy(smat[l], M.ele[l], inverse); 
    }
  }
  else
  {
    isSparse = false;
    mat.resize(nBlock);
    smat.clear();
    for (int l=0; l<nBlock; ++l) matrixCopy(mat[l], M.ele[l], inverse);
  } 
}
コード例 #4
0
ファイル: vSDP_struct.cpp プロジェクト: nberth/apron4opam
//----------------------------------------------------------------------
void GeneralMatrix::initialize(GeneralMatrix &source)
{
  isSparse = source.isSparse;
  nBlock = source.nBlock;
  if (blockStruct) delete[] blockStruct;
  blockStruct = new int[nBlock];
  CheckMemory(blockStruct);
  if (isSparse)
  {
    if (!mat.empty()) mat.clear();
    smat.resize(nBlock);
  }
  else
  {
    if (!smat.empty()) smat.clear();
    mat.resize(nBlock);
  }
  for(int j=0; j<nBlock; j++)
  {
    blockStruct[j] = source.blockStruct[j];
    if (isSparse)
    {
      Resize(smat[j],RowDimension(source.smat[j]),ColDimension(source.smat[j]),Allocated(source.smat[j]));
      for (int i=1; i<=ColDimension(smat[j]); i++) SetCol(smat[j], i, Col(source.smat[j], i));
    }
    else
    {
      mat[j] = source.mat[j];
    }
  }
}
コード例 #5
0
GekkoF EMU_FASTCALL GekkoCPURecompiler::CompileIL(u32 OldPC, u32 NewPC)
{
	u8				*X86Buffer;
	u32				BufferSize;
	u32				InstSize;
	RecInstruction	*CurInstructionsBegin;
	u32				LastInstIsBranch;
	CompiledBlock	*NewCompiledBlock;
	CompiledBlock	*CurBlock;
	JumpList		*CurJump;
	PPCRegInfo		X86Regs[X86_REG_COUNT+1];	//current PPC assigned to this register
												//last entry is a dummy for verifying counts
	PPCRegInfo		FPURegs[FPU_REG_COUNT+1];	//current PPC FPU assigned to this register
												//last entry is a dummy for verifying counts

	LastInstIsBranch = (LastInstruction->Flags & RecInstrFlag_Branch);

	//allocate 2k for a buffer
	X86Buffer = (u8 *)RecompileAlloc(1024*1024);
	if(!X86Buffer)
	{
		printf("ERROR! Unable to allocate Recompile Buffer!\n");
		CheckMemory();
		DumpMemoryLayout();
		CompiledTable[(OldPC >> 2) & 0x7FFFFF] = (u32)&CompileErrorBlock;
		CompileErrorBlock.CodeBlock = (GekkoFP)&CompileErrorFunction;
		cpu->pause = true;
		return;
	}
コード例 #6
0
ファイル: vSDP_struct.cpp プロジェクト: nberth/apron4opam
//----------------------------------------------------------------------
void GeneralMatrix::copyFrom(GeneralMatrix* source)
{
  CheckVectorRange(source->nBlock);
  nBlock = source->nBlock;
  if (blockStruct) delete[] blockStruct;
  blockStruct = new int[nBlock];
  CheckMemory(blockStruct);
  for (int l=0; l<nBlock; ++l) blockStruct[l] = source->blockStruct[l];
  mat.clear();
  smat.clear();
  
  if(source->isSparse)
  {
    isSparse = true;
    smat.resize(nBlock);
    for (int l=0; l<nBlock; ++l)
    {
	MakePermanent(source->smat[l]);    
	smat[l] = SPARSE_INTERVAL_MATRIX(source->smat[l]);    
    }
  }
  else
  {
    isSparse = false;
    mat.resize(nBlock);
    for (int l=0; l<nBlock; ++l) 
    {
      int dim = abs(blockStruct[l]);
      Resize(mat[l], dim, dim);
      Initialize(mat[l], 0);
      for (int i=1; i<=dim; i++)
        for (int j=1; j<=i; j++) mat[l](i,j) = mat[l](j,i) = source->mat[l](i,j);
    }
  }
}
コード例 #7
0
ファイル: context.c プロジェクト: KaneRoot/COSE-C
void MyFree(void * ptr, void * context)
{
    MyItem * pb = (MyItem *) ((byte *) ptr - sizeof(MyItem) + 4);
    MyContext * myContext = (MyContext *)context;

    CheckMemory(myContext);

    memset(&pb->pad, 0xab, pb->size + 8);
}
コード例 #8
0
ファイル: memory.cpp プロジェクト: 8l/objeck-lang
void MemoryManager::CheckObject(long* mem, bool is_obj, long depth)
{
  if(mem) {
    StackClass* cls;
    if(is_obj) {
      cls = GetClass(mem);
    }
    else {
      cls = GetClassMapping(mem);
    }

    if(cls) {
#ifdef _DEBUG
      for(int i = 0; i < depth; i++) {
        wcout << L"\t";
      }
      wcout << L"\t----- object: addr=" << mem << L"(" << (long)mem << L"), num="
        << cls->GetNumberInstanceDeclarations() << L" -----" << endl;
#endif

      // mark data
      if(MarkMemory(mem)) {
        CheckMemory(mem, cls->GetInstanceDeclarations(), cls->GetNumberInstanceDeclarations(), depth);
      }
    } 
    else {
      // NOTE: this happens when we are trying to mark unidentified memory
      // segments. these segments may be parts of that stack or temp for
      // register variables
#ifdef _DEBUG
      for(int i = 0; i < depth; i++) {
        wcout << L"\t";
      }
      wcout <<"$: addr/value=" << mem << endl;
      if(is_obj) {
        assert(cls);
      }
#endif
      // primitive or object array
      if(MarkValidMemory(mem)) {
        // ensure we're only checking int and obj arrays
        if(std::binary_search(allocated_memory.begin(), allocated_memory.end(), mem) && 
          (mem[TYPE] == NIL_TYPE || mem[TYPE] == INT_TYPE)) {
            long* array = mem;
            const long size = array[0];
            const long dim = array[1];
            long* objects = (long*)(array + 2 + dim);
            for(long k = 0; k < size; k++) {
              CheckObject((long*)objects[k], false, 2);
            }
        }
      }
    }
  }
}
コード例 #9
0
// The original starting point of the game EXE
void cat3d_exe_main (void)
{
	//id0_short_t i;

	if (refkeen_current_gamever == BE_GAMEVER_CAT3D122)
	{
		if (BE_Cross_strcasecmp(id0_argv[1], "/VER") == 0)
		{
			BE_ST_printf("Catacomb 3-D version 1.22  (Rev 1)\n");
			BE_ST_printf("Copyright 1991-93 Softdisk Publishing\n");
			BE_ST_printf("Developed for use with 100%% IBM compatibles\n");
			BE_ST_printf("that have 640K memory and DOS version 3.3 or later\n");
			BE_ST_printf("and EGA graphics or better.\n");
			BE_ST_HandleExit(0);
		}

		if (BE_Cross_strcasecmp(id0_argv[1], "/?") == 0)
		{
			BE_ST_printf("Catacomb 3-D version 1.22\n");
			BE_ST_printf("Copyright 1991-93 Softdisk Publishing\n\n");
			BE_ST_printf("Syntax:\n");
			BE_ST_printf("CAT3D [/<switch>]\n\n");
			BE_ST_printf("Switch       What it does\n");
			BE_ST_printf("/?           This Information\n");
			BE_ST_printf("/VER         Display Program Version Information\n");
			BE_ST_printf("/COMP        Fix problems with SVGA screens\n");
			BE_ST_printf("/NOAL        No AdLib or SoundBlaster detection\n");
			BE_ST_printf("/NOJOYS      Tell program to ignore joystick\n");
			BE_ST_printf("/NOMOUSE     Tell program to ignore mouse\n");
			BE_ST_printf("/HIDDENCARD  Overrides video detection\n\n");
			BE_ST_printf("Each switch must include a '/' and multiple switches\n");
			BE_ST_printf("must be seperated by at least one space.\n\n");

			BE_ST_HandleExit(0);
		}
	}
	// jabhack(); // REFKEEN - Commented out

	InitGame ();

	CheckMemory ();

	LoadLatchMem ();

#ifdef PROFILE
	NewGame ();
	GameLoop ();
#endif

//NewGame ();
//GameLoop ();

	DemoLoop();
	Quit("Demo loop exited???");
}
コード例 #10
0
ファイル: memory.cpp プロジェクト: 8l/objeck-lang
size_t WINAPI MemoryManager::CheckStatic(void* arg)
{
  StackClass** clss = prgm->GetClasses();
  int cls_num = prgm->GetClassNumber();

  for(int i = 0; i < cls_num; i++) {
    StackClass* cls = clss[i];
    CheckMemory(cls->GetClassMemory(), cls->GetClassDeclarations(), 
      cls->GetNumberClassDeclarations(), 0);
  }

  return 0;
}
コード例 #11
0
ファイル: xHeap.cpp プロジェクト: galek/xform-megatexture
void xHeap::Free(void * p)
{
  if(!p)
    return;

#ifndef USE_STD_MALLOC
  #ifndef USE_APP_HEAP_SAVING_MODE
    switch(((uint8*)p)[-1-(int)DUMMY_ID_SIZE/2])
    {
    case BT_SMALL:
      FreeSmall(p);
      break;

    case BT_MEDIUM:
    #if defined(DEBUG_APP_HEAP) && defined(AEE_SIMULATOR)
      // CheckMemory();
    #endif
      FreeMedium(p);
      break;

    case BT_LARGE:
    #if defined(DEBUG_APP_HEAP) && defined(AEE_SIMULATOR)
      // CheckMemory();
    #endif
      FreeLarge(p);
      break;

    default:
    #if defined(DEBUG_APP_HEAP) && defined(AEE_SIMULATOR)
      CheckMemory();
    #endif
      ASSERT(false);
    }
  #else
    if(((uint8*)p)[-1-(int)DUMMY_ID_SIZE/2] & BLOCK_TYPE_MASK)
    {
      FreeSmall(p);
    }
    else
    {
      FreeLarge(p);
    }
  #endif

#else
  FREE(p);
#endif
}
コード例 #12
0
ファイル: context.c プロジェクト: KaneRoot/COSE-C
void * MyCalloc(size_t count, size_t size, void * context)
{
    MyItem * pb = (MyItem *) malloc(sizeof(MyItem) + count*size);
    MyContext * myContext = (MyContext *)context;

    CheckMemory(myContext);

    memset(pb, 0xef, sizeof(MyItem) + count*size);
    memset(&pb->data, 0, count*size);

    pb->pNext = (struct _MyItem *) myContext->pFirst;
    myContext->pFirst = (byte *) pb;
    pb->size = count*size;

    return &pb->data;
}
コード例 #13
0
ファイル: context.c プロジェクト: KaneRoot/COSE-C
void FreeContext(cn_cbor_context* pContext)
{
    MyContext * myContext = (MyContext *)pContext;
    MyItem * pItem;
    MyItem * pItem2;

    CheckMemory(myContext);

    for (pItem = (MyItem *) myContext->pFirst; pItem != NULL;  pItem = pItem2) {
        pItem2 = pItem->pNext;
        free(pItem);
    }

    free(myContext);

    return;
}
コード例 #14
0
void CMonitorService::WatchSystem()
{

	time_t	now;

    now = uptime();
	if ((now-m_tmLastCheck) < 60)
	{
//		XDEBUG(ANSI_COLOR_GREEN " #######################################debug sungyeung this is not check time yet : %s : %d \n" ANSI_NORMAL, __FILE__, __LINE__);
		return;
	}

	if (!CheckMemory())
	{
		UpdateLogFile(LOG_DIR, EVENT_LOG_FILE, 0, TRUE, "SYSMON::MEMORY FULL\xd\xa");
		RebootSystem();
	}
	
	if (!CheckFlash())
	{
		XDEBUG(ANSI_COLOR_RED " #######################################debug sungyeung WatchSystem().!CheckFlash() : %s : %d \n", __FILE__, __LINE__);
		ReduceFileSystem();
		UpdateLogFile(LOG_DIR, EVENT_LOG_FILE, 0, TRUE, "SYSMON::FLASH FULL\xd\xa");
		RebootSystem();
	}

	if (!CheckLauncher())
	{
		UpdateLogFile(LOG_DIR, EVENT_LOG_FILE, 0, TRUE, "SYSMON::LAUNCHER FAIL\xd\xa");
		RebootSystem();

	}
	if (!CheckAgent())
	{
		UpdateLogFile(LOG_DIR, EVENT_LOG_FILE, 0, TRUE, "SYSMON::AGENT FAIL\xd\xa");
		RebootSystem();

	}
	if (!CheckTelnet())
	{
		UpdateLogFile(LOG_DIR, EVENT_LOG_FILE, 0, TRUE, "SYSMON::TELNET FAIL\xd\xa");
		KillTelnet();
	}
    m_tmLastCheck = uptime();
}
コード例 #15
0
ファイル: vSDP_struct.cpp プロジェクト: nberth/apron4opam
//----------------------------------------------------------------------
GeneralMatrix::GeneralMatrix(double** data, int n, int* blkStruct)
{
  CheckVectorRange(n);
  nBlock = n;
  blockStruct = new int[n];
  CheckMemory(blockStruct);
  isSparse = false;
  mat.resize(n);
  for (int j=0; j<n; j++)
  {
    blockStruct[j] = blkStruct[j];  
    int nRow = abs(blkStruct[j]);  
    Resize(mat[j], nRow, nRow);
    Initialize(mat[j], 0);
    for (int k=0; k<nRow; k++)
      for (int l=0; l<nRow; l++) mat[j](k+1,l+1) = data[j][k + nRow*l];
  }
}
コード例 #16
0
ファイル: vSDP_struct.cpp プロジェクト: nberth/apron4opam
//----------------------------------------------------------------------
void GeneralMatrix::blockResize()
{
  nBlock++;
  int* bufBlStr = new int[nBlock];
  CheckMemory(bufBlStr);
  for (int i=0; i<nBlock-1; i++) bufBlStr[i] = blockStruct[i];
  bufBlStr[nBlock-1] = 1;
  blockStruct = bufBlStr;
  if (isSparse)
  {
    smat.push_back(SPARSE_INTERVAL_MATRIX(1,1,1));
  }
  else
  {
    mat.push_back(INTERVAL_MATRIX(1,1));
    Clear(mat[nBlock-1]);
  }
}
コード例 #17
0
bool AttributeContainer::DeserializeInternal(const uchar *&data,uint &len_left,uint max_depth,uint &memory_left)
{
	if(!max_depth) return false;
	if(!len_left) return false;
	if(*data!='A')
	    return false;
	len_left--;
	data++;
	uint attrs;
	if(!DecodeUint(attrs,data,len_left)) return false;
	Attrs.EnsureOverhead ((attrs<100)?attrs:100);
	for(uint i=0;i<attrs;i++)
	{
		CheckMemory(sizeof(Attribute));
		Attribute *a=Attrs.Append();
		if(!a->OldDeserialize(data,len_left,max_depth,memory_left)) return false;
	}
	return true;
}
コード例 #18
0
int main(void){
	ListOfProcesses *LReady;
	ListOfProcesses *LBlock;
	ListOfProcesses *LFinished;
	Memory *Mmemory;
	FILE *pEntry;
	FILE *pOut;
	int i;
	int counter = 0;
	int retRunning;
	int TamReady = 0;

	tempoTotal = 0;

	pOut = fopen("OutputFIRST.txt", "w");
	if (pOut == NULL){
		printf("Erro ao tentar abrir o arquivo!\n");
		exit(1);
	}

	pEntry = fopen("teste.txt", "r");
	if (pEntry == NULL){
		printf("Erro ao tentar abrir o arquivo!\n");
		exit(1);
	}

	LReady = FileReader(pEntry, &TamReady);

	Mmemory = MemoryCreator();
	LBlock = BlockCreator(TamReady);
	LFinished = FinishedCreator(TamReady);
	Mmemory->LMemory->quantity = 0;

	for (i = 0; i < LReady->quantity; i++){
		PrintProcess(&(LReady->proc[i]), pOut);
	}

	while ((Mmemory->LMemory->quantity + LReady->quantity + LBlock->quantity) != 0){
		while ((CheckMemory(Mmemory) >= LReady->proc[0].Memory) && (LReady->proc[0].order != -1)){
			ReadyToMemory(LReady, Mmemory);
			OrganizeList(LReady);
			fprintf(pOut, "\n-----------------------Mapa de Alocação de Memória-----------------------\n");
			PrintMemory(Mmemory, pOut);
			fprintf(pOut, "-----------------------Fim Mapa de Alocação de Memória-----------------------\n");
		}
		counter++;
		retRunning = RunningProcess(Mmemory, LBlock, pOut);
		BlockToReady(LReady, LBlock);
		ProcessToEverywhere(Mmemory, LBlock, LReady, LFinished, retRunning);
		PrintMemory(Mmemory, pOut);
		fprintf(pOut, "\n-----------------------Processos na Fila de Prontos-----------------------\n");
		PrintListOfProcesses(LReady, pOut);
		fprintf(pOut, "\n-----------------------Processos em IO-----------------------\n");
		PrintListOfProcesses(LBlock, pOut);
		fprintf(pOut, "\n-----------------------Processos Já Terminados-----------------------\n");
		PrintListOfProcesses(LFinished, pOut);

		if ((Mmemory->LMemory->quantity == 0) && (LReady->quantity == 0) && (LBlock->quantity != 0)){
			for (i = 0; i < LBlock->quantity; i++){
				while (LBlock->proc[i].TimeIO[0] != 0){
					ExecutaBloqueados(LBlock);
					Mmemory->LMemory->quantity = 1;
				}
				LBlock->proc[i].order = -1;
				LBlock->quantity = LBlock->quantity - 1;
			}

		}

	}

	printf("Tempo Decorrido: %ds\n", tempoTotal);
	fprintf(pOut, "Tempo Total Decorrido: %d\n", tempoTotal);
	printf("Counter: %d\n", counter);
	fprintf(pOut, "Numero de iterações do while: %d\n", counter);

	free(LReady->proc);
	free(LBlock->proc);
	free(LFinished->proc);
	free(LReady);
	free(LBlock);
	free(LFinished);

	free(Mmemory->LMemory->proc);
	free(Mmemory->LMemory);
	free(Mmemory);

	fclose(pEntry);
	fclose(pOut);

	return 0;
}
コード例 #19
0
    FIABITMAP * BORDER < Tsrc >::SetBorder (FIBITMAP * src, int xborder, int yborder,
                                            BorderType type, Tsrc constant)
{
    int width = FreeImage_GetWidth (src);
    int height = FreeImage_GetHeight (src);
    int dst_width = width + (2 * xborder);
    int dst_height = height + (2 * yborder);

    FIABITMAP *dst = (FIABITMAP *) malloc (sizeof (FIABITMAP));

    CheckMemory (dst);
    dst->fib = FIA_CloneImageType (src, dst_width, dst_height);
    dst->xborder = xborder;
    dst->yborder = yborder;
    FIA_Paste (dst->fib, src, xborder, yborder);

    if (type == BorderType_Constant && constant != 0.0)
    {
        // Set the bottom line of the image to constant value
        this->SetImageRowToConstant (dst->fib, 0, yborder, constant);

        // Set the top line of the image to constant value
        this->SetImageRowToConstant (dst->fib, dst_height - yborder, yborder, constant);

        // Set the left pixels of the image
        this->SetImageColToConstant (dst->fib, 0, xborder, constant);

        // Set the right pixels of the image
        this->SetImageColToConstant (dst->fib, dst_width - xborder, xborder, constant);
    }
    else if (type == BorderType_Copy)
    {
        // Get the bottom line of the original image and copy into bottom border
        CopyImageRow (dst->fib, yborder, 0, yborder);

        // Get the top line of the original image and copy into top border
        CopyImageRow (dst->fib, dst_height - yborder - 1, dst_height - yborder, yborder);

        // Get the left pixels of the image and copy into left border
        CopyImageCol (dst->fib, xborder, 0, xborder);

        // Get the right pixels of the image and copy into right border
        CopyImageCol (dst->fib, dst_width - xborder - 1, dst_width - xborder, xborder);
    }
    else if (type == BorderType_Mirror)
    {
        int pitch = FreeImage_GetPitch (dst->fib);

        Tsrc *src_bits, *dst_bits;

        // Get the bottom line of the original image and copy into bottom border
        int border_row_start = yborder - 1;     // First row on border for bottom
        int image_row_start = yborder;

        for(int i = 0; i < yborder; i++)
        {
            dst_bits = (Tsrc *) FreeImage_GetScanLine (dst->fib, border_row_start);
            src_bits = (Tsrc *) FreeImage_GetScanLine (dst->fib, image_row_start);
            memcpy (dst_bits, src_bits, pitch);
            border_row_start--;
            image_row_start++;
        }

        // Top
        border_row_start = dst_height - yborder;        // First row on border fort bottom
        image_row_start = border_row_start - 1;

        for(int i = 0; i < yborder; i++)
        {
            dst_bits = (Tsrc *) FreeImage_GetScanLine (dst->fib, border_row_start);
            src_bits = (Tsrc *) FreeImage_GetScanLine (dst->fib, image_row_start);
            memcpy (dst_bits, src_bits, pitch);
            border_row_start++;
            image_row_start--;
        }
        // Left
        dst_bits = (Tsrc *) FreeImage_GetBits (dst->fib);
        for(int y = 0; y < dst_height; y++)
        {
            dst_bits = (Tsrc *) FreeImage_GetScanLine (dst->fib, y);
            for(int x = 0; x < xborder; x++)
            {
                dst_bits[x] = dst_bits[2 * xborder - 1 - x];
            }
        }
        // Right
        dst_bits = (Tsrc *) FreeImage_GetBits (dst->fib);
        border_row_start = dst_width - xborder;
        for(int y = 0; y < dst_height; y++)
        {
            dst_bits = (Tsrc *) FreeImage_GetScanLine (dst->fib, y);
            for(int x = 0; x < xborder; x++)
            {
                dst_bits[border_row_start + x] = dst_bits[border_row_start - 1 - x];
            }
        }
    }

    return dst;
}
コード例 #20
0
/*************************************************************************
	module		:[アナログ・ファンクション・チェッカー、メイン]
	function	:[アナログ・ファンクション・チェッカー、メイン]
	return		:[なし]
	common		:[]
	condition	:[]
	comment		:[]
	machine		:[V53]
	language	:[MS-C(Ver.6.0)]
	keyword		:[CHK]
	date		:[1995/02/10]
	author		:[増田]
*************************************************************************/
void	AnalogFunctionCheckerMain( void )						/* なし */
{
	UWORD	command;		/*コマンド*/
	UBYTE	machine;		/*機種(0:桐、1:椛)*/
	UBYTE	result;			/*検査結果*/
	UBYTE	result_out;		/*検査結果出力 ON/OFF*/
/*	UBYTE	lcd_work[31];	*/	/* LCD表示ワーク */

	UBYTE	data;
	UWORD	word_data;

	/** コマンド読み込み */
	command = inpw(COMMAND_PORT);	/** コマンド読み込み */
	command &= 0x00ff;
	machine = (UBYTE)(command >> 7);	/** 機種 */

	outpw(COMMAND_PORT,(UWORD)command);					/** 検査結果ステータス出力 */

	/* RTCポートチェック時は、周波数チェックを外す 1997/11/17  By T.Yamaguchi */
	if ((command != CHECK_OUT_RTC_PORT1) && (command != CHECK_OUT_RTC_PORT2)) {
		/** 周波数チェック */
		CheckClock( 0 );			/** 周波数チェック */
	}

	/** コマンド解析 */
	result = 0;						/** 検査結果=OK */
	result_out = OUT_ON;			/** 検査結果出力=ON */

	/** ブザー音消去 */
#if (PRO_KEYPANEL == PANEL_POPLAR_B) || (PRO_KEYPANEL == PANEL_POPLAR_L)
	outpw(ETC_PORT , IO_BIT_MUTE);
#endif
#if (PRO_KEYPANEL == PANEL_ANZU_L)
	IO__PADRH = 0x00ff;
#endif

	switch ( (command & 0x00ff) ) {	/** コマンド内容を調べる */
		case	CHECK_OUT_CPU_PA1:						/* ポートAデータレジスタH */
			CMN_DisableInterrupt();
			outpw(IO_PADRH_PORT, OUT_CPU_PA1);					/* A0H書き込み */
			result = OUT_CPU_PA1;
			break;
		case	CHECK_OUT_CPU_PA2:						/* ポートAデータレジスタH */
			CMN_DisableInterrupt();
			outpw(IO_PADRH_PORT, OUT_CPU_PA2);					/** 51H書き込み */
			result = OUT_CPU_PA2;
			break;
		case	CHECK_OUT_CPU_PA_UB1:					/* ポートAデータレジスタL */
			CMN_DisableInterrupt();
			outpw(IO_PADRL_PORT, OUT_CPU_PA_UB1);					/** A8H書き込み */
			result = OUT_CPU_PA_UB1;
			break;
		case	CHECK_OUT_CPU_PA_UB2:					/* ポートAデータレジスタL */
			CMN_DisableInterrupt();
			outpw(IO_PADRL_PORT, OUT_CPU_PA_UB2);					/** 55H書き込み */
			result = OUT_CPU_PA_UB2;
			break;
#if (PRO_KEYPANEL == PANEL_ANZU_L)
		case	CHECK_OUT_CPU_PA_UB1H:						/* ポートAデータレジスタL */
			CMN_DisableInterrupt();
			outpw(IO_PADRL_PORT, OUT_CPU_PA_UB1H);					/** AAH書き込み */
			result = RSLT_CPU_PA_UB1H;
			break;
		case	CHECK_OUT_CPU_PA_UB2H:						/* ポートAデータレジスタL */
			CMN_DisableInterrupt();
			outpw(IO_PADRL_PORT, OUT_CPU_PA_UB2H);					/** 51H書き込み */
			result = RSLT_CPU_PA_UB2H;
			break;
		case	CHECK_OUT_CPU_PD1H:							/* ポートDデータレジスタH */
			CMN_DisableInterrupt();
			outpw(IO_PDDRH_PORT, OUT_CPU_PD1H);					/* 40H書き込み */
			result = RSLT_CPU_PD1H;
			break;
		case	CHECK_OUT_CPU_PD2H:							/* ポートDデータレジスタH */
			CMN_DisableInterrupt();
			outpw(IO_PDDRH_PORT, OUT_CPU_PD2H);					/** 80H書き込み */
			result = RSLT_CPU_PD2H;
			break;
		case	CHECK_OUT_COM_PORT1:							/* COM・ポ−ト */
			CMN_DisableInterrupt();
			outpw(COM_PORT, OUT_COM_PORT1);					/** 28H書き込み */
			result = OUT_COM_PORT1;
			break;
		case	CHECK_OUT_COM_PORT2:							/* COM・ポ−ト */
			CMN_DisableInterrupt();
			outpw(COM_PORT, OUT_COM_PORT2);					/** 10H書き込み */
			result = OUT_COM_PORT2;
			break;
		case	CHECK_OUT_RTC_PORT1:							/* RTC・ポ−ト */
			CMN_DisableInterrupt();
			outpw(RTC_PORT, OUT_RTC_PORT1);					/** 0AH書き込み */
			result = OUT_RTC_PORT1;
			break;
		case	CHECK_OUT_RTC_PORT2:							/* RTC・ポ−ト */
			CMN_DisableInterrupt();
			outpw(RTC_PORT, OUT_RTC_PORT2);					/** 0AH書き込み */
			result = OUT_RTC_PORT2;
			break;
#endif
#if (PRO_KEYPANEL == PANEL_POPLAR_B) || (PRO_KEYPANEL == PANEL_POPLAR_L)
		case	CHECK_OUT_CPU_PE1:						/* ポートEデータレジスタH */
			CMN_DisableInterrupt();
			outpw(IO_PEDR_PORT, OUT_CPU_PE1);					/* 80H書き込み */
			result = OUT_CPU_PE1;
			break;
		case	CHECK_OUT_CPU_PE2:						/* ポートEデータレジスタH */
			CMN_DisableInterrupt();
			outpw(IO_PEDR_PORT, OUT_CPU_PE2);					/** 00H書き込み */
			result = OUT_CPU_PE2;
			break;
		case	CHECK_OUT_CPU_PE_UB1:					/* ポートEデータレジスタL */
			CMN_DisableInterrupt();
			outpw(IO_PEDR_PORT, OUT_CPU_PE_UB1);				/** 40H書き込み */
			result = RSLT_CPU_PE_UB1;
			break;
		case	CHECK_OUT_CPU_PE_UB2:					/* ポートEデータレジスタL */
			CMN_DisableInterrupt();
			outpw(IO_PEDR_PORT, OUT_CPU_PE_UB2);				/** 00H書き込み */
			result = RSLT_CPU_PE_UB2;
			break;
		case	CHECK_OUT_EXT1:							/* 外部ポート */
			CMN_DisableInterrupt();
			outpw(MODEM2_PORT, OUT_EXT1);					/* 2AH書き込み */
			result = OUT_EXT1;
			break;
		case	CHECK_OUT_EXT2:							/* 外部ポート */
			CMN_DisableInterrupt();
			outpw(MODEM2_PORT, OUT_EXT2);					/** 55H書き込み */
			result = OUT_EXT2;
			break;
		case	CHECK_OUT_EXT_UB1:						/* 外部ポート */
			CMN_DisableInterrupt();
			outpw(MODEM2_PORT, OUT_EXT_UB1);					/** 2AH書き込み */
			result = RSLT_EXT_UB1;
			break;
		case	CHECK_OUT_EXT_UB2:						/* 外部ポート */
			CMN_DisableInterrupt();
			outpw(MODEM2_PORT, OUT_EXT_UB2);					/** 55H書き込み */
			result = RSLT_EXT_UB2;
			break;
		/* I/Oリード項目 */
		case	CHECK_IN_CPU_PA:
			for (;;) {						/** 無限ループ */
				outpw( COMMAND_PORT, (inpw(IO_PADRL_PORT) & IN_CPU_PA));	/** ジャムカバーを読み、ステータスポートに出力 */
			}
			break;
		case	CHECK_IN_CPU_PA_UB:
			for (;;) {						/** 無限ループ */
				outpw( COMMAND_PORT, ((inpw(IO_PADRL_PORT) >> 8) & IN_CPU_PA_UB));	/** ドラムステータスを読み、ステータスポートに出力 */
			}
			break;
		case	CHECK_IN_CPU_PD:
			for (;;) {						/** 無限ループ */
				outpw( COMMAND_PORT, ((inpw(IO_PDDRH_PORT) >> 8) & IN_CPU_PD));	/** モータステータスを読み、ステータスポートに出力 */
			}
			break;
#endif
		case	CHECK_IN_CPU_PE:
			for (;;) {						/** 無限ループ */
				outpw( COMMAND_PORT, (inpw(IO_PEDR_PORT) & IN_CPU_PE));	/** ポートEデータレジスタを読み、ステータスポートに出力 */
			}
			break;
		case	CHECK_IN_CPU_PE_UB:
			for (;;) {						/** 無限ループ */
				outpw( COMMAND_PORT, ((inpw(IO_PEDR_PORT) >> 8) & IN_CPU_PE_UB));	/** ポートEデータレジスタを読み、ステータスポートに出力 */
			}
			break;
		case	CHECK_IN_CPU_PF:
			for (;;) {						/** 無限ループ */
				outpw( COMMAND_PORT, (UWORD)(inp(IO_PFDR_PORT) & IN_CPU_PF));	/** ポートFデータレジスタを読み、ステータスポートに出力 */
			}
			break;
		case	CHECK_IN_MD9604:
			for (;;) {						/** 無限ループ */
				outpw( COMMAND_PORT, (inpw(SENSOR1_PORT) & IN_MD9604) );	/** 入力ポートCS06を読み、ステータスポートに出力 */
			}
			break;
#if 0	/* (PRO_KEYPANEL == PANEL_ANZU_L) 削除1997/11/14  By T.Yamaguchi */
//		case	CHECK_IN_MD9604H:
//			for (;;) {						/** 無限ループ */
//				outpw( COMMAND_PORT, ((inpw(SENSOR1_PORT) >> 8) & IN_MD9604H) );	/** 入力ポートCS06を読み、ステータスポートに出力 */
//			}
//			break;
#endif
#if (PRO_KEYPANEL == PANEL_POPLAR_B) || (PRO_KEYPANEL == PANEL_POPLAR_L)
		case	CHECK_IN_EXT2:		/** ディップスイッチチェックが指定された */
			for (;;) {						/** 無限ループ */
				outpw( COMMAND_PORT, (inpw(SENSOR2_PORT) & IN_EXT2) );	/** 入力ポートCS06を読み、ステータスポートに出力 */
			}
			break;
#endif
#if (PRO_KEYPANEL == PANEL_POPLAR_B)
		case	CHECK_APS_SENSOR:
			for (;;) {						/** 無限ループ */
				outpw( COMMAND_PORT, (inpw(APS_SENSOR_PORT) & IO_BIT_XAPS) );	/** 入力ポートCS06を読み、ステータスポートに出力 */
			}
			break;
#endif
		case	CHECK_BUZZER_HIGH:	/* ブザー大	*/
			SCN_SetBuzzerFrequency( ACK_BUZZER_FREQ );		/** 周波数の設定 */
			SYB_MonitorSpeakerOutLevel = SYS_VOLUME_MAXIMUM;	/* ボリューム最大に設定 */
			MonitorSpeakerVolumeControl();
			SpeakerMuteOff();
			SpeakerOutBuzzer();
#if 0
//			SYS_ETC_PortStatus = (IO_BIT_SPVR1 | IO_BIT_SPVR2);		/* ボリューム最大に設定 */
//			SYS_ETC_PortStatus &= ~IO_BIT_MUTE;
//			outpw(ETC_PORT , SYS_ETC_PortStatus);
//
//			SYS_Modem2PortStatus &= ~IO_BIT_RXA_BZ;
//			outpw(MODEM2_PORT, SYS_Modem2PortStatus );
#endif
			SCN_SetBuzzer(SCN_ENABLE);						/** ブザー許可 */
			result = BUZZER_HIGH_OK;
			break;
		case	CHECK_BUZZER_LOW:
			SCN_SetBuzzerFrequency( ACK_BUZZER_FREQ );		/** 周波数の設定 */
			SYB_MonitorSpeakerOutLevel = SYS_VOLUME_MINIMUM;	/* ボリューム最小に設定 */
			MonitorSpeakerVolumeControl();
			SpeakerMuteOff();
			SpeakerOutBuzzer();
#if 0
//			SYS_ETC_PortStatus = IO_BIT_SPVR1;		/* ボリューム最小に設定 */
//			SYS_ETC_PortStatus &= ~IO_BIT_MUTE;
//			outpw(ETC_PORT , SYS_ETC_PortStatus);
//
//			SYS_Modem2PortStatus &= ~IO_BIT_RXA_BZ;
//			outpw(MODEM2_PORT, SYS_Modem2PortStatus );
#endif
			SCN_SetBuzzer(SCN_ENABLE);						/** ブザー許可 */
			result = BUZZER_LOW_OK;
			break;
		case	CHECK_DRAM_WR:
			/** DRAMチェック(WR) */
			CMN_DisableInterrupt();				/** 割り込み禁止 */
			CheckMemory(CHK_WRITE,0x1000000);	/** チェック IC36 */
			result = CHECK_RAM_WRITE;			/* RAMライト完了 */
			break;
		case	CHECK_DRAM_RD:
			/** DRAMチェック(RD) */
			CMN_DisableInterrupt();				/** 割り込み禁止 */
			result = CHECK_DRAM_OK;			/** 検査結果=OK */
			if (CheckMemory(CHK_READ,0x1000000) != OK ) {	/** チェック IC36 */
				result = CHECK_ERROR;	/** IC36 NG */
			}
			break;
		case	CHECK_SRAM_WR:
			/** SRAMチェック(WR) */
			CMN_DisableInterrupt();				/** 割り込み禁止 */
			CheckMemory(CHK_WRITE,0x400000);	/** チェック IC36 */
			CheckMemory(CHK_WRITE,0x440000);	/** チェック IC36 add 1998/01/23  By T.Yamaguchi */
			result = CHECK_RAM_WRITE;			/* RAMライト完了 */
			break;
		case	CHECK_SRAM_RD:
			/** SRAMチェック(RD) */
			CMN_DisableInterrupt();				/** 割り込み禁止 */
			result = CHECK_SRAM_OK;			/** 検査結果=OK */
			if (CheckMemory(CHK_READ,0x400000) != OK ) {	/** チェック IC36 */
				result = CHECK_ERROR;	/** NG */
			}
			if (CheckMemory(CHK_READ,0x440000) != OK ) {	/** チェック IC36  add 1998/01/23  By T.Yamaguchi */
				result = CHECK_ERROR;	/** NG */
			}
			break;
		case	CHECK_MD9604:
			/* MD9604チェック(IC12) */
			/* 何処のアドレスをチェックするかよう確認すること */
			result = CheckIoWordLoop(PRINTER1_PORT ,CHECK_MD9604_OK , CHECK_ERROR );
#if 0
//			result = CheckIoLoop(PRINTER2_PORT ,CHECK_MD9604_OK , CHECK_ERROR );
//			result = CheckIoLoop(PRINTER3_PORT ,CHECK_MD9604_OK , CHECK_ERROR );
//			result = CheckIoLoop(PRINTER6_PORT ,CHECK_MD9604_OK , CHECK_ERROR );
//			result = CheckIoLoop(PRINTER7_PORT ,CHECK_MD9604_OK , CHECK_ERROR );
#endif
			break;
		case	CHECK_MD9605:
			/* MD9605チェック(IDP) */
			/** IDP301チェックが指定された */
			result = CheckIDP( machine, CHECK_IDP301_OK, CHECK_IDP301_NG );	/** IDP301チェック */
			break;
#if (PRO_KEYPANEL == PANEL_POPLAR_B)
		case	CHECK_MD9509:
			/* MD9509チェック(プリンタ) */
			/* 何処のアドレスをチェックするかよう確認すること */
			if (CheckMortor(1)) {
				result = 0xC0;		/* モーター回転中 */
			}
			result = CHECK_MD9509_OK;
			break;
#endif
		case	CHECK_EXTEND_RAM:
			/** 拡張DRAMチェック(RD) */
			result = CHECK_EXT_DRAM_OK;			/** 検査結果=OK */
			CMN_DisableInterrupt();				/** 割り込み禁止 */
			CheckMemory(CHK_WRITE,0x1200000);	/** チェック IC36 */
			if (CheckMemory(CHK_READ,0x1200000) != OK ) {	/** チェック IC36 */
				result |= CHECK_DRAM_EX12_NG;	/** IC36 NG */
			}
			CheckMemory(CHK_WRITE,0x1400000);	/** チェック IC36 */
			if (CheckMemory(CHK_READ,0x1400000) != OK ) {	/** チェック IC36 */
				result |= CHECK_DRAM_EX14_NG;	/** IC36 NG */
 			}
			CheckMemory(CHK_WRITE,0x1600000);	/** チェック IC36 */
			if (CheckMemory(CHK_READ,0x1600000) != OK ) {	/** チェック IC36 */
				result |= CHECK_DRAM_EX16_NG;	/** IC36 NG */
			}
			CheckMemory(CHK_WRITE,0x1800000);	/** チェック IC36 */
			if (CheckMemory(CHK_READ,0x1800000) != OK ) {	/** チェック IC36 */
				result |= CHECK_DRAM_EX18_NG;	/** IC36 NG */
			}
			break;
#if (PRO_CLASS1 == ENABLE)
		case	CHECK_RS232C:
			/*	??????????????????????????????????????????????????????	*/
			/* RS-232C速度19200
			** RS-232Cキャラクタービット8
			** RS-232Cパリティなし
			** RS-232Cストップビット1
			*/
			SYB_SettingStatus[5] = 0x0e;
			Class1InitVar();
			result = CHECK_ERROR;	/* チェックエラー */
			RsTestMode = 0x03;	/* 折り返しテスト */
			RsTestChar = RsTestMode;	/**	テスト用キャラクタ=?をセット	**/
			if (RsOpen('t', 'c', 60) == 1) {
				if ( RsClose('t') == 1) {		/**	テスト終了を待つ	**/
					result = CHECK_RS232C_OK;
				}
			}
#endif
			break;
		case	CHECK_OPTION:
			if (DPRD_CheckSlaveBoardEnable() == 1) {
				result = CHECK_OPTION_OK;
			}
			else {
				result = CHECK_ERROR;	/* チェックエラー */
			}
			break;
#if (PRO_KEYPANEL == PANEL_POPLAR_B) || (PRO_KEYPANEL == PANEL_POPLAR_L)
		case	CHECK_AD_PORT_F0:	/* CASET1 */
			for (;;) {						/** 無限ループ */
				outpw( COMMAND_PORT, (AD__ADDRA >> 2));	/** A/DデータレジスタA */
			}
			break;
		case	CHECK_AD_PORT_F1:	/* CASET2 */
			for (;;) {						/** 無限ループ */
				outpw( COMMAND_PORT, (AD__ADDRB >> 2));	/** A/DデータレジスタB */
			}
			break;
		case	CHECK_AD_PORT_F2:	/* CASET3 */
			for (;;) {						/** 無限ループ */
				outpw( COMMAND_PORT, (AD__ADDRC >> 2));	/** A/DデータレジスタB */
			}
			break;
		case	CHECK_AD_PORT_F3:	/* TEMPR */
			for (;;) {						/** 無限ループ */
				outpw( COMMAND_PORT, (AD__ADDRD >> 2));	/** A/DデータレジスタB */
			}
			break;
		case	CHECK_AD_PORT_F5:	/* HVR */
			for (;;) {						/** 無限ループ */
				outpw( COMMAND_PORT, (AD__ADDRF >> 2));	/** A/DデータレジスタB */
			}
			break;
		case	CHECK_AD_PORT_F6:	/* THMST */
			for (;;) {						/** 無限ループ */
				outpw( COMMAND_PORT, (AD__ADDRG >> 2));	/** A/DデータレジスタB */
			}
			break;
		case	CHECK_AD_PORT_F7:	/* TS */
			for (;;) {						/** 無限ループ */
				outpw( COMMAND_PORT, (AD__ADDRH >> 2));	/** A/DデータレジスタB */
			}
			break;
#endif
		case	CHECK_AD_PORT_F4:	/* BAT */
			for (;;) {						/** 無限ループ */
				outpw( COMMAND_PORT, (AD__ADDRE >> 2));	/** A/DデータレジスタB */
			}
			break;
		case	CHECK_MODEM_TX:				/** モデム送信チェックが指定された */
			CheckModemTx(0);						/** モデム送信チェック */
			result = CHECK_MODEM_TX;
			break;
		case	CHECK_MODEM_RX:				/** モデム受信チェックが指定された */
			result = CheckModemRx();			/** モデム受信チェック */
			break;
/*	その他の項目	*/
		case	CHECK_DMAU:			/** DMAUチェックが指定された */
			CMN_DisableInterrupt();				/** 割り込み禁止 */
			result = CheckIoLoop(DMAU_PORT,CHECK_DMAU_OK,CHECK_DMAU_NG);/** DMAUチェック */
			break;
		case	CHECK_RXA_RXOUT:	/** RXA−RXOUTチェックが指定された*/
			result_out = OUT_OFF;				/** 検査結果出力=OFF */
			outp( ModemFilterControl, CHECK_RXA_RXOUT_BIT);	/** RXA−RXOUT*/
			break;
		case	CHECK_1100_BPF:		/** 1100BPFチェックが指定された*/
			result_out = OUT_OFF;				/** 検査結果出力=OFF */
			outp( ModemFilterControl, CHECK_1100_BPF_BIT);	/** 1100BPF*/
			break;
		case	CHECK_462_LPF:		/** 462LPFチェックが指定された*/
			result_out = OUT_OFF;				/** 検査結果出力=OFF */
			outp( ModemFilterControl, CHECK_462_LPF_BIT);	/** 462LPF*/
			break;
		case	CHECK_CODEC_SCN:	/** CODECスキャナーチェックが指定された */
			result = CheckIoWordLoop( CodecRegisterAddressTable[0][1], CHECK_CODEC_SCN_OK, CHECK_CODEC_SCN_NG );	/** CODECスキャナーチェック */
			break;
		case	CHECK_CODEC_PRN:	/** CODECプリンターチェックが指定された */
			result = CheckIoWordLoop( CodecRegisterAddressTable[1][1], CHECK_CODEC_PRN_OK, CHECK_CODEC_PRN_NG );	/** CODECプリンターチェック */
			break;
		case	CHECK_CODEC_COM:	/** CODEC通信チェックが指定された */
			result = CheckIoWordLoop( CodecRegisterAddressTable[2][1], CHECK_CODEC_COM_OK, CHECK_CODEC_COM_NG );	/** CODEC通信チェック */
			break;
		case	CHECK_SHADING:		/** 白黒判定 for ANZU_L */
			CheckShading();
/*
//			if (DIPP_ShadingExecute() == OK) {
//				result = 0xC0;			@* 終了 *@
//			}
//			else {
//				result = CHECK_ERROR;	@* チェックエラー *@
//			}
*/
			break;
		case CHECK_MOTOR:
			if (CheckMortor(1)) {
				result = 0xC0;		/* モーター回転中 */
			}
			break;
		case CHECK_MOTOR_STOP:
			CheckMortor(0);
			result = 0xC0;		/* モーターSTOP */
			break;
#if (PRO_KEYPANEL == PANEL_POPLAR_B)
		case CHECK_FBS_MOTOR:
			if (CheckMortor(3)) {
				result = 0xC0;		/* FBSモーター回転中 */
			}
			break;
		case CHECK_FBS_MOTOR_STOP:
			CheckMortor(2);
			result = 0xC0;		/* FBSモーターSTOP */
			break;
#endif
		case CHECK_TX_OUT_1080HZ:
			CheckModemTx(1);						/** モデム送信チェック */
		case CHECK_TX_OUT_5000HZ:
			CheckModemTx(2);						/** モデム送信チェック */
		default:	/* ここには来ないはず */
			break;

	}

	/** 検査結果出力 */
	if ( result_out == OUT_ON ) {		/** 検査結果出力=ONの時 */
		for (;;) {						/** 無限ループ */
			outpw(COMMAND_PORT,(UWORD)result);		/** 検査結果ステータス出力 */
		}
	}

	/** 終了処理 */
	CMN_DisableInterrupt();		/** 割り込み禁止 */
	for (;;);						/** 無限ループ */
}
コード例 #21
0
ファイル: disasm.cpp プロジェクト: Kriole/snes9x-rr
void S9xTraceCPUToBuf(char *output) {
  static PC_t pc;
  char t[256];
  char *s = output;

  pc.xPBPC = Registers.PBPC;
  sprintf(s, "%.6x ", (uint32)pc.xPBPC);

  uint8 op  = dreadb(pc.xPBPC); pc.W.xPC++;
  uint8 op0 = dreadb(pc.xPBPC); pc.W.xPC++;
  uint8 op1 = dreadb(pc.xPBPC); pc.W.xPC++;
  uint8 op2 = dreadb(pc.xPBPC);

  #define op8  ((op0))
  #define op16 ((op0) | (op1 << 8))
  #define op24 ((op0) | (op1 << 8) | (op2 << 16))
  #define a8   (CheckEmulation() || CheckMemory())
  #define x8   (CheckEmulation() || CheckIndex())

  switch(op) {
    case 0x00: sprintf(t, "brk #$%.2x              ", op8); break;
    case 0x01: sprintf(t, "ora ($%.2x,x)   [%.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
    case 0x02: sprintf(t, "cop #$%.2x              ", op8); break;
    case 0x03: sprintf(t, "ora $%.2x,s     [%.6x]", op8, decode(OPTYPE_SR, op8)); break;
    case 0x04: sprintf(t, "tsb $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0x05: sprintf(t, "ora $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0x06: sprintf(t, "asl $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0x07: sprintf(t, "ora [$%.2x]     [%.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
    case 0x08: sprintf(t, "php                   "); break;
    case 0x09: if(a8)sprintf(t, "ora #$%.2x              ", op8);
               else  sprintf(t, "ora #$%.4x            ", op16); break;
    case 0x0a: sprintf(t, "asl a                 "); break;
    case 0x0b: sprintf(t, "phd                   "); break;
    case 0x0c: sprintf(t, "tsb $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0x0d: sprintf(t, "ora $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0x0e: sprintf(t, "asl $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0x0f: sprintf(t, "ora $%.6x   [%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
    case 0x10: sprintf(t, "bpl $%.4x     [%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
    case 0x11: sprintf(t, "ora ($%.2x),y   [%.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
    case 0x12: sprintf(t, "ora ($%.2x)     [%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
    case 0x13: sprintf(t, "ora ($%.2x,s),y [%.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
    case 0x14: sprintf(t, "trb $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0x15: sprintf(t, "ora $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0x16: sprintf(t, "asl $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0x17: sprintf(t, "ora [$%.2x],y   [%.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
    case 0x18: sprintf(t, "clc                   "); break;
    case 0x19: sprintf(t, "ora $%.4x,y   [%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
    case 0x1a: sprintf(t, "inc                   "); break;
    case 0x1b: sprintf(t, "tcs                   "); break;
    case 0x1c: sprintf(t, "trb $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0x1d: sprintf(t, "ora $%.4x,x   [%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
    case 0x1e: sprintf(t, "asl $%.4x,x   [%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
    case 0x1f: sprintf(t, "ora $%.6x,x [%.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
    case 0x20: sprintf(t, "jsr $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR_PC, op16)); break;
    case 0x21: sprintf(t, "and ($%.2x,x)   [%.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
    case 0x22: sprintf(t, "jsl $%.6x   [%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
    case 0x23: sprintf(t, "and $%.2x,s     [%.6x]", op8, decode(OPTYPE_SR, op8)); break;
    case 0x24: sprintf(t, "bit $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0x25: sprintf(t, "and $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0x26: sprintf(t, "rol $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0x27: sprintf(t, "and [$%.2x]     [%.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
    case 0x28: sprintf(t, "plp                   "); break;
    case 0x29: if(a8)sprintf(t, "and #$%.2x              ", op8);
               else  sprintf(t, "and #$%.4x            ", op16); break;
    case 0x2a: sprintf(t, "rol a                 "); break;
    case 0x2b: sprintf(t, "pld                   "); break;
    case 0x2c: sprintf(t, "bit $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0x2d: sprintf(t, "and $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0x2e: sprintf(t, "rol $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0x2f: sprintf(t, "and $%.6x   [%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
    case 0x30: sprintf(t, "bmi $%.4x     [%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
    case 0x31: sprintf(t, "and ($%.2x),y   [%.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
    case 0x32: sprintf(t, "and ($%.2x)     [%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
    case 0x33: sprintf(t, "and ($%.2x,s),y [%.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
    case 0x34: sprintf(t, "bit $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0x35: sprintf(t, "and $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0x36: sprintf(t, "rol $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0x37: sprintf(t, "and [$%.2x],y   [%.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
    case 0x38: sprintf(t, "sec                   "); break;
    case 0x39: sprintf(t, "and $%.4x,y   [%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
    case 0x3a: sprintf(t, "dec                   "); break;
    case 0x3b: sprintf(t, "tsc                   "); break;
    case 0x3c: sprintf(t, "bit $%.4x,x   [%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
    case 0x3d: sprintf(t, "and $%.4x,x   [%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
    case 0x3e: sprintf(t, "rol $%.4x,x   [%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
    case 0x3f: sprintf(t, "and $%.6x,x [%.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
    case 0x40: sprintf(t, "rti                   "); break;
    case 0x41: sprintf(t, "eor ($%.2x,x)   [%.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
    case 0x42: sprintf(t, "wdm                   "); break;
    case 0x43: sprintf(t, "eor $%.2x,s     [%.6x]", op8, decode(OPTYPE_SR, op8)); break;
    case 0x44: sprintf(t, "mvp $%.2x,$%.2x           ", op1, op8); break;
    case 0x45: sprintf(t, "eor $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0x46: sprintf(t, "lsr $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0x47: sprintf(t, "eor [$%.2x]     [%.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
    case 0x48: sprintf(t, "pha                   "); break;
    case 0x49: if(a8)sprintf(t, "eor #$%.2x              ", op8);
               else  sprintf(t, "eor #$%.4x            ", op16); break;
    case 0x4a: sprintf(t, "lsr a                 "); break;
    case 0x4b: sprintf(t, "phk                   "); break;
    case 0x4c: sprintf(t, "jmp $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR_PC, op16)); break;
    case 0x4d: sprintf(t, "eor $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0x4e: sprintf(t, "lsr $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0x4f: sprintf(t, "eor $%.6x   [%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
    case 0x50: sprintf(t, "bvc $%.4x     [%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
    case 0x51: sprintf(t, "eor ($%.2x),y   [%.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
    case 0x52: sprintf(t, "eor ($%.2x)     [%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
    case 0x53: sprintf(t, "eor ($%.2x,s),y [%.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
    case 0x54: sprintf(t, "mvn $%.2x,$%.2x           ", op1, op8); break;
    case 0x55: sprintf(t, "eor $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0x56: sprintf(t, "lsr $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0x57: sprintf(t, "eor [$%.2x],y   [%.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
    case 0x58: sprintf(t, "cli                   "); break;
    case 0x59: sprintf(t, "eor $%.4x,y   [%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
    case 0x5a: sprintf(t, "phy                   "); break;
    case 0x5b: sprintf(t, "tcd                   "); break;
    case 0x5c: sprintf(t, "jml $%.6x   [%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
    case 0x5d: sprintf(t, "eor $%.4x,x   [%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
    case 0x5e: sprintf(t, "lsr $%.4x,x   [%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
    case 0x5f: sprintf(t, "eor $%.6x,x [%.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
    case 0x60: sprintf(t, "rts                   "); break;
    case 0x61: sprintf(t, "adc ($%.2x,x)   [%.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
    case 0x62: sprintf(t, "per $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0x63: sprintf(t, "adc $%.2x,s     [%.6x]", op8, decode(OPTYPE_SR, op8)); break;
    case 0x64: sprintf(t, "stz $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0x65: sprintf(t, "adc $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0x66: sprintf(t, "ror $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0x67: sprintf(t, "adc [$%.2x]     [%.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
    case 0x68: sprintf(t, "pla                   "); break;
    case 0x69: if(a8)sprintf(t, "adc #$%.2x              ", op8);
               else  sprintf(t, "adc #$%.4x            ", op16); break;
    case 0x6a: sprintf(t, "ror a                 "); break;
    case 0x6b: sprintf(t, "rtl                   "); break;
    case 0x6c: sprintf(t, "jmp ($%.4x)   [%.6x]", op16, decode(OPTYPE_IADDR_PC, op16)); break;
    case 0x6d: sprintf(t, "adc $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0x6e: sprintf(t, "ror $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0x6f: sprintf(t, "adc $%.6x   [%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
    case 0x70: sprintf(t, "bvs $%.4x     [%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
    case 0x71: sprintf(t, "adc ($%.2x),y   [%.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
    case 0x72: sprintf(t, "adc ($%.2x)     [%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
    case 0x73: sprintf(t, "adc ($%.2x,s),y [%.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
    case 0x74: sprintf(t, "stz $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0x75: sprintf(t, "adc $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0x76: sprintf(t, "ror $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0x77: sprintf(t, "adc [$%.2x],y   [%.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
    case 0x78: sprintf(t, "sei                   "); break;
    case 0x79: sprintf(t, "adc $%.4x,y   [%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
    case 0x7a: sprintf(t, "ply                   "); break;
    case 0x7b: sprintf(t, "tdc                   "); break;
    case 0x7c: sprintf(t, "jmp ($%.4x,x) [%.6x]", op16, decode(OPTYPE_IADDRX, op16)); break;
    case 0x7d: sprintf(t, "adc $%.4x,x   [%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
    case 0x7e: sprintf(t, "ror $%.4x,x   [%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
    case 0x7f: sprintf(t, "adc $%.6x,x [%.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
    case 0x80: sprintf(t, "bra $%.4x     [%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
    case 0x81: sprintf(t, "sta ($%.2x,x)   [%.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
    case 0x82: sprintf(t, "brl $%.4x     [%.6x]", uint16(decode(OPTYPE_RELW, op16)), decode(OPTYPE_RELW, op16)); break;
    case 0x83: sprintf(t, "sta $%.2x,s     [%.6x]", op8, decode(OPTYPE_SR, op8)); break;
    case 0x84: sprintf(t, "sty $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0x85: sprintf(t, "sta $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0x86: sprintf(t, "stx $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0x87: sprintf(t, "sta [$%.2x]     [%.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
    case 0x88: sprintf(t, "dey                   "); break;
    case 0x89: if(a8)sprintf(t, "bit #$%.2x              ", op8);
               else  sprintf(t, "bit #$%.4x            ", op16); break;
    case 0x8a: sprintf(t, "txa                   "); break;
    case 0x8b: sprintf(t, "phb                   "); break;
    case 0x8c: sprintf(t, "sty $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0x8d: sprintf(t, "sta $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0x8e: sprintf(t, "stx $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0x8f: sprintf(t, "sta $%.6x   [%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
    case 0x90: sprintf(t, "bcc $%.4x     [%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
    case 0x91: sprintf(t, "sta ($%.2x),y   [%.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
    case 0x92: sprintf(t, "sta ($%.2x)     [%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
    case 0x93: sprintf(t, "sta ($%.2x,s),y [%.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
    case 0x94: sprintf(t, "sty $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0x95: sprintf(t, "sta $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0x96: sprintf(t, "stx $%.2x,y     [%.6x]", op8, decode(OPTYPE_DPY, op8)); break;
    case 0x97: sprintf(t, "sta [$%.2x],y   [%.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
    case 0x98: sprintf(t, "tya                   "); break;
    case 0x99: sprintf(t, "sta $%.4x,y   [%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
    case 0x9a: sprintf(t, "txs                   "); break;
    case 0x9b: sprintf(t, "txy                   "); break;
    case 0x9c: sprintf(t, "stz $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0x9d: sprintf(t, "sta $%.4x,x   [%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
    case 0x9e: sprintf(t, "stz $%.4x,x   [%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
    case 0x9f: sprintf(t, "sta $%.6x,x [%.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
    case 0xa0: if(x8)sprintf(t, "ldy #$%.2x              ", op8);
               else  sprintf(t, "ldy #$%.4x            ", op16); break;
    case 0xa1: sprintf(t, "lda ($%.2x,x)   [%.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
    case 0xa2: if(x8)sprintf(t, "ldx #$%.2x              ", op8);
               else  sprintf(t, "ldx #$%.4x            ", op16); break;
    case 0xa3: sprintf(t, "lda $%.2x,s     [%.6x]", op8, decode(OPTYPE_SR, op8)); break;
    case 0xa4: sprintf(t, "ldy $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0xa5: sprintf(t, "lda $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0xa6: sprintf(t, "ldx $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0xa7: sprintf(t, "lda [$%.2x]     [%.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
    case 0xa8: sprintf(t, "tay                   "); break;
    case 0xa9: if(a8)sprintf(t, "lda #$%.2x              ", op8);
               else  sprintf(t, "lda #$%.4x            ", op16); break;
    case 0xaa: sprintf(t, "tax                   "); break;
    case 0xab: sprintf(t, "plb                   "); break;
    case 0xac: sprintf(t, "ldy $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0xad: sprintf(t, "lda $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0xae: sprintf(t, "ldx $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0xaf: sprintf(t, "lda $%.6x   [%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
    case 0xb0: sprintf(t, "bcs $%.4x     [%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
    case 0xb1: sprintf(t, "lda ($%.2x),y   [%.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
    case 0xb2: sprintf(t, "lda ($%.2x)     [%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
    case 0xb3: sprintf(t, "lda ($%.2x,s),y [%.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
    case 0xb4: sprintf(t, "ldy $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0xb5: sprintf(t, "lda $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0xb6: sprintf(t, "ldx $%.2x,y     [%.6x]", op8, decode(OPTYPE_DPY, op8)); break;
    case 0xb7: sprintf(t, "lda [$%.2x],y   [%.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
    case 0xb8: sprintf(t, "clv                   "); break;
    case 0xb9: sprintf(t, "lda $%.4x,y   [%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
    case 0xba: sprintf(t, "tsx                   "); break;
    case 0xbb: sprintf(t, "tyx                   "); break;
    case 0xbc: sprintf(t, "ldy $%.4x,x   [%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
    case 0xbd: sprintf(t, "lda $%.4x,x   [%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
    case 0xbe: sprintf(t, "ldx $%.4x,y   [%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
    case 0xbf: sprintf(t, "lda $%.6x,x [%.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
    case 0xc0: if(x8)sprintf(t, "cpy #$%.2x              ", op8);
               else  sprintf(t, "cpy #$%.4x            ", op16); break;
    case 0xc1: sprintf(t, "cmp ($%.2x,x)   [%.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
    case 0xc2: sprintf(t, "rep #$%.2x              ", op8); break;
    case 0xc3: sprintf(t, "cmp $%.2x,s     [%.6x]", op8, decode(OPTYPE_SR, op8)); break;
    case 0xc4: sprintf(t, "cpy $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0xc5: sprintf(t, "cmp $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0xc6: sprintf(t, "dec $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0xc7: sprintf(t, "cmp [$%.2x]     [%.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
    case 0xc8: sprintf(t, "iny                   "); break;
    case 0xc9: if(a8)sprintf(t, "cmp #$%.2x              ", op8);
               else  sprintf(t, "cmp #$%.4x            ", op16); break;
    case 0xca: sprintf(t, "dex                   "); break;
    case 0xcb: sprintf(t, "wai                   "); break;
    case 0xcc: sprintf(t, "cpy $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0xcd: sprintf(t, "cmp $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0xce: sprintf(t, "dec $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0xcf: sprintf(t, "cmp $%.6x   [%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
    case 0xd0: sprintf(t, "bne $%.4x     [%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
    case 0xd1: sprintf(t, "cmp ($%.2x),y   [%.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
    case 0xd2: sprintf(t, "cmp ($%.2x)     [%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
    case 0xd3: sprintf(t, "cmp ($%.2x,s),y [%.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
    case 0xd4: sprintf(t, "pei ($%.2x)     [%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
    case 0xd5: sprintf(t, "cmp $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0xd6: sprintf(t, "dec $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0xd7: sprintf(t, "cmp [$%.2x],y   [%.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
    case 0xd8: sprintf(t, "cld                   "); break;
    case 0xd9: sprintf(t, "cmp $%.4x,y   [%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
    case 0xda: sprintf(t, "phx                   "); break;
    case 0xdb: sprintf(t, "stp                   "); break;
    case 0xdc: sprintf(t, "jmp [$%.4x]   [%.6x]", op16, decode(OPTYPE_ILADDR, op16)); break;
    case 0xdd: sprintf(t, "cmp $%.4x,x   [%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
    case 0xde: sprintf(t, "dec $%.4x,x   [%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
    case 0xdf: sprintf(t, "cmp $%.6x,x [%.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
    case 0xe0: if(x8)sprintf(t, "cpx #$%.2x              ", op8);
               else  sprintf(t, "cpx #$%.4x            ", op16); break;
    case 0xe1: sprintf(t, "sbc ($%.2x,x)   [%.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
    case 0xe2: sprintf(t, "sep #$%.2x              ", op8); break;
    case 0xe3: sprintf(t, "sbc $%.2x,s     [%.6x]", op8, decode(OPTYPE_SR, op8)); break;
    case 0xe4: sprintf(t, "cpx $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0xe5: sprintf(t, "sbc $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0xe6: sprintf(t, "inc $%.2x       [%.6x]", op8, decode(OPTYPE_DP, op8)); break;
    case 0xe7: sprintf(t, "sbc [$%.2x]     [%.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
    case 0xe8: sprintf(t, "inx                   "); break;
    case 0xe9: if(a8)sprintf(t, "sbc #$%.2x              ", op8);
               else  sprintf(t, "sbc #$%.4x            ", op16); break;
    case 0xea: sprintf(t, "nop                   "); break;
    case 0xeb: sprintf(t, "xba                   "); break;
    case 0xec: sprintf(t, "cpx $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0xed: sprintf(t, "sbc $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0xee: sprintf(t, "inc $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0xef: sprintf(t, "sbc $%.6x   [%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
    case 0xf0: sprintf(t, "beq $%.4x     [%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
    case 0xf1: sprintf(t, "sbc ($%.2x),y   [%.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
    case 0xf2: sprintf(t, "sbc ($%.2x)     [%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
    case 0xf3: sprintf(t, "sbc ($%.2x,s),y [%.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
    case 0xf4: sprintf(t, "pea $%.4x     [%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
    case 0xf5: sprintf(t, "sbc $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0xf6: sprintf(t, "inc $%.2x,x     [%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
    case 0xf7: sprintf(t, "sbc [$%.2x],y   [%.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
    case 0xf8: sprintf(t, "sed                   "); break;
    case 0xf9: sprintf(t, "sbc $%.4x,y   [%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
    case 0xfa: sprintf(t, "plx                   "); break;
    case 0xfb: sprintf(t, "xce                   "); break;
    case 0xfc: sprintf(t, "jsr ($%.4x,x) [%.6x]", op16, decode(OPTYPE_IADDRX, op16)); break;
    case 0xfd: sprintf(t, "sbc $%.4x,x   [%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
    case 0xfe: sprintf(t, "inc $%.4x,x   [%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
    case 0xff: sprintf(t, "sbc $%.6x,x [%.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
  }

  #undef op8
  #undef op16
  #undef op24
  #undef a8
  #undef x8

  strcat(s, t);
  strcat(s, " ");

  sprintf(t, "A:%.4x X:%.4x Y:%.4x S:%.4x D:%.4x DB:%.2x ",
    Registers.A.W, Registers.X.W, Registers.Y.W, Registers.S.W, Registers.D, Registers.DB);
  strcat(s, t);

  if(CheckEmulation()) {
    sprintf(t, "%c%c%c%c%c%c%c%c",
      CheckNegative() ? 'N' : 'n', CheckOverflow() ? 'V' : 'v',
      CheckMemory()   ? '1' : '0', CheckIndex()    ? 'B' : 'b',
      CheckDecimal()  ? 'D' : 'd', CheckIRQ()      ? 'I' : 'i',
      CheckZero()     ? 'Z' : 'z', CheckCarry()    ? 'C' : 'c');
  } else {
    sprintf(t, "%c%c%c%c%c%c%c%c",
      CheckNegative() ? 'N' : 'n', CheckOverflow() ? 'V' : 'v',
      CheckMemory()   ? 'M' : 'm', CheckIndex()    ? 'X' : 'x',
      CheckDecimal()  ? 'D' : 'd', CheckIRQ()      ? 'I' : 'i',
      CheckZero()     ? 'Z' : 'z', CheckCarry()    ? 'C' : 'c');
  }

  strcat(s, t);
  strcat(s, " ");

  //sprintf(t, "V:%3d H:%4d", cpu.vcounter(), cpu.hcounter());
  sprintf(t, "V:%3d", CPU.V_Counter);

  strcat(s, t);
  //strcat(s, "\n");
}
コード例 #22
0
ファイル: memory.cpp プロジェクト: 8l/objeck-lang
uintptr_t WINAPI MemoryManager::CheckPdaRoots(void* arg)
{
#ifndef _GC_SERIAL
  EnterCriticalSection(&pda_frame_cs);
#endif

#ifdef _DEBUG
  wcout << L"----- PDA frames(s): num=" << pda_frames.size() 
        << L"; thread=" << GetCurrentThread()<< L" -----" << endl;
  wcout << L"memory types:" <<  endl;
#endif
  
  set<StackFrame**, StackFrame**>::iterator iter;
  for(iter = pda_frames.begin(); iter != pda_frames.end(); ++iter) {
    StackFrame** frame = *iter;
    StackMethod* mthd = (*frame)->method;
    long* mem = (*frame)->mem;
    
#ifdef _DEBUG
    wcout << L"\t===== PDA method: name=" << mthd->GetName() << L", addr="
          << mthd << L", num=" << mthd->GetNumberDeclarations() << L" =====" << endl;
#endif
    
    // mark self
    CheckObject((long*)(*mem), true, 1);
    
    if(mthd->HasAndOr()) {
      mem += 2;
    } 
    else {
      mem++;
    }
    
    // mark rest of memory
    CheckMemory(mem, mthd->GetDeclarations(), mthd->GetNumberDeclarations(), 0);
  }
#ifndef _GC_SERIAL
  LeaveCriticalSection(&pda_frame_cs);
#endif 
  
#ifndef GC_SERIAL
  EnterCriticalSection(&pda_monitor_cs);
#endif

#ifdef _DEBUG
  wcout << L"----- PDA method root(s): num=" << pda_monitors.size() 
    << L"; thread=" << GetCurrentThread()<< L" -----" << endl;
  wcout << L"memory types:" <<  endl;
#endif
  // look at pda methods
  unordered_map<StackFrameMonitor*, StackFrameMonitor*>::iterator pda_iter;
  for(pda_iter = pda_monitors.begin(); pda_iter != pda_monitors.end(); ++pda_iter) {
    // gather stack frames
    StackFrameMonitor* monitor = pda_iter->first;
    long call_stack_pos = *(monitor->call_stack_pos);
    
    if (call_stack_pos > 0) {
      StackFrame** call_stack = monitor->call_stack;
      StackFrame* cur_frame = *(monitor->cur_frame);

      // copy frames locally
      vector<StackFrame*> frames;
      frames.push_back(cur_frame);
      while (--call_stack_pos > -1) {
        frames.push_back(call_stack[call_stack_pos]);
      }

      for (size_t i = 0; i < frames.size(); ++i) {
        StackMethod* mthd = frames[i]->method;
        long* mem = frames[i]->mem;

#ifdef _DEBUG
        wcout << L"\t===== PDA method: name=" << mthd->GetName() << L", addr="
          << mthd << L", num=" << mthd->GetNumberDeclarations() << L" =====" << endl;
#endif

        // mark self
        CheckObject((long*)(*mem), true, 1);

        if (mthd->HasAndOr()) {
          mem += 2;
        }
        else {
          mem++;
        }

        // mark rest of memory
        CheckMemory(mem, mthd->GetDeclarations(), mthd->GetNumberDeclarations(), 0);
      }
    }
  }
#ifndef GC_SERIAL
  LeaveCriticalSection(&pda_monitor_cs);
#endif

  return 0;
}
コード例 #23
0
ファイル: winmain.c プロジェクト: mojca/gnuplot
int main(int argc, char **argv)
#endif
{
        /*WNDCLASS wndclass;*/
        LPSTR tail;

#ifdef WGP_CONSOLE
# define _argv argv
# define _argc argc
        HINSTANCE hInstance = GetModuleHandle(NULL), hPrevInstance = NULL;
#else
#if defined(__MSC__) || defined(__WATCOMC__)
#  define _argv __argv
#  define _argc __argc
#endif
#endif /* WGP_CONSOLE */

        szModuleName = (LPSTR)malloc(MAXSTR+1);
        CheckMemory(szModuleName);

        /* get path to EXE */
        GetModuleFileName(hInstance, (LPSTR) szModuleName, MAXSTR);
        if ((tail = (LPSTR)_fstrrchr(szModuleName,'\\')) != (LPSTR)NULL)
        {
                tail++;
                *tail = 0;
        }
        szModuleName = (LPSTR)realloc(szModuleName, _fstrlen(szModuleName)+1);
        CheckMemory(szModuleName);

        if (_fstrlen(szModuleName) >= 5 && _fstrnicmp(&szModuleName[_fstrlen(szModuleName)-5], "\\bin\\", 5) == 0)
        {
                int len = _fstrlen(szModuleName)-4;
                szPackageDir = (LPSTR)malloc(len+1);
                CheckMemory(szPackageDir);
                _fstrncpy(szPackageDir, szModuleName, len);
                szPackageDir[len] = '\0';
        }
        else
                szPackageDir = szModuleName;

#ifndef WGP_CONSOLE
        textwin.hInstance = hInstance;
        textwin.hPrevInstance = hPrevInstance;
        textwin.nCmdShow = nCmdShow;
        textwin.Title = "gnuplot";
#endif

		/* create structure of first graph window */
		graphwin = calloc(1, sizeof(GW));
		listgraphs = graphwin;

		/* locate ini file */
		{
			char * inifile;
			get_user_env(); /* this hasn't been called yet */
			inifile = gp_strdup("~\\wgnuplot.ini");
			gp_expand_tilde(&inifile);

			/* if tilde expansion fails use current directory as
			   default - that was the previous default behaviour */
			if (inifile[0] == '~') {
				free(inifile);
				inifile = "wgnuplot.ini";
			}

#ifndef WGP_CONSOLE
			textwin.IniFile = inifile;
#endif
			graphwin->IniFile = inifile;

			ReadMainIni(inifile, "WGNUPLOT");
		}

#ifndef WGP_CONSOLE
        textwin.IniSection = "WGNUPLOT";
        textwin.DragPre = "load '";
        textwin.DragPost = "'\n";
        textwin.lpmw = &menuwin;
        textwin.ScreenSize.x = 80;
        textwin.ScreenSize.y = 80;
        textwin.KeyBufSize = 2048;
        textwin.CursorFlag = 1; /* scroll to cursor after \n & \r */
        textwin.shutdown = MakeProcInstance((FARPROC)ShutDown, hInstance);
        textwin.AboutText = (LPSTR)malloc(1024);
        CheckMemory(textwin.AboutText);
        sprintf(textwin.AboutText,
	    "Version %s patchlevel %s\n" \
	    "last modified %s\n" \
	    "%s\n%s, %s and many others\n" \
	    "gnuplot home:     http://www.gnuplot.info\n",
            gnuplot_version, gnuplot_patchlevel,
	    gnuplot_date,
	    gnuplot_copyright, authors[1], authors[0]);
        textwin.AboutText = (LPSTR)realloc(textwin.AboutText, _fstrlen(textwin.AboutText)+1);
        CheckMemory(textwin.AboutText);

        menuwin.szMenuName = szMenuName;
#endif

        pausewin.hInstance = hInstance;
        pausewin.hPrevInstance = hPrevInstance;
        pausewin.Title = "gnuplot pause";

        graphwin->hInstance = hInstance;
        graphwin->hPrevInstance = hPrevInstance;
#ifdef WGP_CONSOLE
        graphwin->lptw = NULL;
#else
        graphwin->lptw = &textwin;
#endif

		/* init common controls */
	{
	    INITCOMMONCONTROLSEX initCtrls;
	    initCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX);
	    initCtrls.dwICC = ICC_WIN95_CLASSES;
	    InitCommonControlsEx(&initCtrls);
	}

#ifndef WGP_CONSOLE
        if (TextInit(&textwin))
                exit(1);
        textwin.hIcon = LoadIcon(hInstance, "TEXTICON");
        SetClassLong(textwin.hWndParent, GCL_HICON, (DWORD)textwin.hIcon);
        if (_argc>1) {
                int i,noend=FALSE;
                for (i=0; i<_argc; ++i)
                        if (!stricmp(_argv[i],"-noend") || !stricmp(_argv[i],"/noend")
                            || !stricmp(_argv[i],"-persist"))
                                noend = TRUE;
                if (noend)
                        ShowWindow(textwin.hWndParent, textwin.nCmdShow);
        }
        else
                ShowWindow(textwin.hWndParent, textwin.nCmdShow);
        if (IsIconic(textwin.hWndParent)) { /* update icon */
                RECT rect;
                GetClientRect(textwin.hWndParent, (LPRECT) &rect);
                InvalidateRect(textwin.hWndParent, (LPRECT) &rect, 1);
                UpdateWindow(textwin.hWndParent);
        }
#else /* WGP_CONSOLE */
#ifdef CONSOLE_SWITCH_CP
        /* Change codepage of console to match that of the graph window.
           WinExit() will revert this.
           Attention: display of characters does not work correctly with
           "Terminal" font! Users will have to use "Lucida Console" or similar.
        */
        cp_input = GetConsoleCP();
        cp_output = GetConsoleOutputCP();
        if (cp_input != GetACP()) {
            cp_changed = TRUE;
            SetConsoleCP(GetACP()); /* keyboard input */
            SetConsoleOutputCP(GetACP()); /* screen output */
            SetFileApisToANSI(); /* file names etc. */
        }
#endif
#endif

        atexit(WinExit);

        if (!isatty(fileno(stdin)))
            setmode(fileno(stdin), O_BINARY);

        gnu_main(_argc, _argv, environ);

        /* First chance to close help system for console gnuplot,
        second for wgnuplot */
        WinCloseHelp();
        return 0;
}
コード例 #24
0
ファイル: winmain.c プロジェクト: Sheetalm9/test
int
main(int argc, char **argv)
#endif
{
	LPSTR tail;
	int i;

#ifdef WGP_CONSOLE
	HINSTANCE hInstance = GetModuleHandle(NULL), hPrevInstance = NULL;
#endif


#ifndef WGP_CONSOLE
# if defined( __MINGW32__) && !defined(_W64)
#  define argc _argc
#  define argv _argv
# else /* MSVC, WATCOM, MINGW-W64 */
#  define argc __argc
#  define argv __argv
# endif
#endif /* WGP_CONSOLE */

        szModuleName = (LPSTR)malloc(MAXSTR+1);
        CheckMemory(szModuleName);

        /* get path to EXE */
        GetModuleFileName(hInstance, (LPSTR) szModuleName, MAXSTR);
        if ((tail = (LPSTR)_fstrrchr(szModuleName,'\\')) != (LPSTR)NULL)
        {
                tail++;
                *tail = 0;
        }
        szModuleName = (LPSTR)realloc(szModuleName, _fstrlen(szModuleName)+1);
        CheckMemory(szModuleName);

        if (_fstrlen(szModuleName) >= 5 && _fstrnicmp(&szModuleName[_fstrlen(szModuleName)-5], "\\bin\\", 5) == 0)
        {
                int len = _fstrlen(szModuleName)-4;
                szPackageDir = (LPSTR)malloc(len+1);
                CheckMemory(szPackageDir);
                _fstrncpy(szPackageDir, szModuleName, len);
                szPackageDir[len] = '\0';
        }
        else
                szPackageDir = szModuleName;

#ifndef WGP_CONSOLE
        textwin.hInstance = hInstance;
        textwin.hPrevInstance = hPrevInstance;
        textwin.nCmdShow = nCmdShow;
        textwin.Title = "gnuplot";
#endif

		/* create structure of first graph window */
		graphwin = (LPGW) calloc(1, sizeof(GW));
		listgraphs = graphwin;

		/* locate ini file */
		{
			char * inifile;
			get_user_env(); /* this hasn't been called yet */
			inifile = gp_strdup("~\\wgnuplot.ini");
			gp_expand_tilde(&inifile);

			/* if tilde expansion fails use current directory as
			   default - that was the previous default behaviour */
			if (inifile[0] == '~') {
				free(inifile);
				inifile = "wgnuplot.ini";
			}

#ifndef WGP_CONSOLE
			textwin.IniFile = inifile;
#endif
			graphwin->IniFile = inifile;

			ReadMainIni(inifile, "WGNUPLOT");
		}

#ifndef WGP_CONSOLE
        textwin.IniSection = "WGNUPLOT";
        textwin.DragPre = "load '";
        textwin.DragPost = "'\n";
        textwin.lpmw = &menuwin;
        textwin.ScreenSize.x = 80;
        textwin.ScreenSize.y = 80;
        textwin.KeyBufSize = 2048;
        textwin.CursorFlag = 1; /* scroll to cursor after \n & \r */
        textwin.shutdown = MakeProcInstance((FARPROC)ShutDown, hInstance);
        textwin.AboutText = (LPSTR)malloc(1024);
        CheckMemory(textwin.AboutText);
        sprintf(textwin.AboutText,
	    "Version %s patchlevel %s\n" \
	    "last modified %s\n" \
	    "%s\n%s, %s and many others\n" \
	    "gnuplot home:     http://www.gnuplot.info\n",
            gnuplot_version, gnuplot_patchlevel,
	    gnuplot_date,
	    gnuplot_copyright, authors[1], authors[0]);
        textwin.AboutText = (LPSTR)realloc(textwin.AboutText, _fstrlen(textwin.AboutText)+1);
        CheckMemory(textwin.AboutText);

        menuwin.szMenuName = szMenuName;
#endif

        pausewin.hInstance = hInstance;
        pausewin.hPrevInstance = hPrevInstance;
        pausewin.Title = "gnuplot pause";

        graphwin->hInstance = hInstance;
        graphwin->hPrevInstance = hPrevInstance;
#ifdef WGP_CONSOLE
        graphwin->lptw = NULL;
#else
        graphwin->lptw = &textwin;
#endif

		/* init common controls */
	{
	    INITCOMMONCONTROLSEX initCtrls;
	    initCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX);
	    initCtrls.dwICC = ICC_WIN95_CLASSES;
	    InitCommonControlsEx(&initCtrls);
	}

#ifndef WGP_CONSOLE
	if (TextInit(&textwin))
		gp_exit(EXIT_FAILURE);
	textwin.hIcon = LoadIcon(hInstance, "TEXTICON");
	SetClassLongPtr(textwin.hWndParent, GCLP_HICON, (LONG_PTR)textwin.hIcon);

	/* Note: we want to know whether this is an interactive session so that we can
	 * decide whether or not to write status information to stderr.  The old test
	 * for this was to see if (argc > 1) but the addition of optional command line
	 * switches broke this.  What we really wanted to know was whether any of the
	 * command line arguments are file names or an explicit in-line "-e command".
	 * (This is a copy of a code snippet from plot.c)
	 */
	for (i = 1; i < argc; i++) {
		if (!stricmp(argv[i], "/noend"))
			continue;
		if ((argv[i][0] != '-') || (argv[i][1] == 'e')) {
			interactive = FALSE;
			break;
		}
	}
	if (interactive)
		ShowWindow(textwin.hWndParent, textwin.nCmdShow);
	if (IsIconic(textwin.hWndParent)) { /* update icon */
		RECT rect;
		GetClientRect(textwin.hWndParent, (LPRECT) &rect);
		InvalidateRect(textwin.hWndParent, (LPRECT) &rect, 1);
		UpdateWindow(textwin.hWndParent);
	}
# ifndef __WATCOMC__
	/* Finally, also redirect C++ standard output streams. */
	RedirectOutputStreams(TRUE);
# endif
#else /* WGP_CONSOLE */
#ifdef CONSOLE_SWITCH_CP
        /* Change codepage of console to match that of the graph window.
           WinExit() will revert this.
           Attention: display of characters does not work correctly with
           "Terminal" font! Users will have to use "Lucida Console" or similar.
        */
        cp_input = GetConsoleCP();
        cp_output = GetConsoleOutputCP();
        if (cp_input != GetACP()) {
            cp_changed = TRUE;
            SetConsoleCP(GetACP()); /* keyboard input */
            SetConsoleOutputCP(GetACP()); /* screen output */
            SetFileApisToANSI(); /* file names etc. */
        }
#endif
#endif

	gp_atexit(WinExit);

	if (!isatty(fileno(stdin)))
		setmode(fileno(stdin), O_BINARY);

	gnu_main(argc, argv);

	/* First chance to close help system for console gnuplot,
	   second for wgnuplot */
	WinCloseHelp();
	gp_exit_cleanup();
	return 0;
}
コード例 #25
0
ファイル: gc.cpp プロジェクト: MadMartian/polyml
/*
    How the garbage collector works.
    The GC has two phases.  The minor (quick) GC is a copying collector that
    copies data from the allocation area into the mutable and immutable area.
    The major collector is started when either the mutable or the immutable
    area is full.  The major collector uses a mark/sweep scheme.
    The GC has three phases:

    1.  Mark phase.
    Working from the roots; which are the the permanent mutable segments and
    the RTS roots (e.g. thread stacks), mark all reachable cells.
    Marking involves setting bits in the bitmap for reachable words.

    2. Compact phase.
    Marked objects are copied to try to compact, upwards, the heap segments.  When
    an object is moved the length word of the object in the old location is set as
    a tombstone that points to its new location.  In particular this means that we
    cannot reuse the space where an object previously was during the compaction phase.
    Immutable objects are moved into immutable segments.  When an object is moved
    to a new location the bits are set in the bitmap as though the object had been
    marked at that location.

    3. Update phase.
    The roots and objects marked during the first two phases are scanned and any
    addresses for moved objects are updated.  The lowest address used in the area
    then becomes the base of the area for future allocations.

    There is a sharing phase which may be performed before the mark phase.  This
    merges immutable cells with the same contents with the aim of reducing the
    size of the live data.  It is expensive so is not performed by default.

    Updated DCJM 12/06/12

*/
static bool doGC(const POLYUNSIGNED wordsRequiredToAllocate)
{
    unsigned j;
    gHeapSizeParameters.RecordAtStartOfMajorGC();
    gHeapSizeParameters.RecordGCTime(HeapSizeParameters::GCTimeStart);
    globalStats.incCount(PSC_GC_FULLGC);

    // Remove any empty spaces.  There will not normally be any except
    // if we have triggered a full GC as a result of detecting paging in the
    // minor GC but in that case we want to try to stop the system writing
    // out areas that are now empty.
    gMem.RemoveEmptyLocals();

    if (debugOptions & DEBUG_GC)
        Log("GC: Full GC, %lu words required %u spaces\n", wordsRequiredToAllocate, gMem.nlSpaces);

    if (debugOptions & DEBUG_HEAPSIZE)
        gMem.ReportHeapSizes("Full GC (before)");

    // Data sharing pass.
    if (gHeapSizeParameters.PerformSharingPass())
        GCSharingPhase();
/*
 * There is a really weird bug somewhere.  An extra bit may be set in the bitmap during
 * the mark phase.  It seems to be related to heavy swapping activity.  Duplicating the
 * bitmap causes it to occur only in one copy and write-protecting the bitmap apart from
 * when it is actually being updated does not result in a seg-fault.  So far I've only
 * seen it on 64-bit Linux but it may be responsible for other crashes.  The work-around
 * is to check the number of bits set in the bitmap and repeat the mark phase if it does
 * not match.
 */
    
    for (unsigned p = 3; p > 0; p--)
    {
        for(j = 0; j < gMem.nlSpaces; j++)
        {
            LocalMemSpace *lSpace = gMem.lSpaces[j];
            ASSERT (lSpace->top >= lSpace->upperAllocPtr);
            ASSERT (lSpace->upperAllocPtr >= lSpace->lowerAllocPtr);
            ASSERT (lSpace->lowerAllocPtr >= lSpace->bottom);
            // Set upper and lower limits of weak refs.
            lSpace->highestWeak = lSpace->bottom;
            lSpace->lowestWeak = lSpace->top;
            lSpace->fullGCLowerLimit = lSpace->top;
            // Put dummy objects in the unused space.  This allows
            // us to scan over the whole of the space.
            gMem.FillUnusedSpace(lSpace->lowerAllocPtr,
                lSpace->upperAllocPtr-lSpace->lowerAllocPtr);
        }

        // Set limits of weak refs.
        for (j = 0; j < gMem.npSpaces; j++)
        {
            PermanentMemSpace *pSpace = gMem.pSpaces[j];
            pSpace->highestWeak = pSpace->bottom;
            pSpace->lowestWeak = pSpace->top;
        }

        /* Mark phase */
        GCMarkPhase();
        
        POLYUNSIGNED bitCount = 0, markCount = 0;
        
        for (j = 0; j < gMem.nlSpaces; j++)
        {
            LocalMemSpace *lSpace = gMem.lSpaces[j]; 
            markCount += lSpace->i_marked + lSpace->m_marked;
            bitCount += lSpace->bitmap.CountSetBits(lSpace->spaceSize());
        }
        
        if (markCount == bitCount)
            break;
        else
        {
            // Report an error.  If this happens again we crash.
            Log("GC: Count error for space %u - mark count %lu, bitCount %lu\n", j, markCount, bitCount);
            if (p == 1)
            {
                ASSERT(markCount == bitCount);
            }
        }
    }
    for(j = 0; j < gMem.nlSpaces; j++)
    {
        LocalMemSpace *lSpace = gMem.lSpaces[j];
        // Reset the allocation pointers.  They will be set to the
        // limits of the retained data.
        lSpace->lowerAllocPtr = lSpace->bottom;
        lSpace->upperAllocPtr = lSpace->top;
    }

    if (debugOptions & DEBUG_GC) Log("GC: Check weak refs\n");
    /* Detect unreferenced streams, windows etc. */
    GCheckWeakRefs();

    // Check that the heap is not overfull.  We make sure the marked
    // mutable and immutable data is no more than 90% of the
    // corresponding areas.  This is a very coarse adjustment.
    {
        POLYUNSIGNED iMarked = 0, mMarked = 0;
        POLYUNSIGNED iSpace = 0, mSpace = 0;
        for (unsigned i = 0; i < gMem.nlSpaces; i++)
        {
            LocalMemSpace *lSpace = gMem.lSpaces[i];
            iMarked += lSpace->i_marked;
            mMarked += lSpace->m_marked;
            if (! lSpace->allocationSpace)
            {
                if (lSpace->isMutable)
                    mSpace += lSpace->spaceSize();
                else
                    iSpace += lSpace->spaceSize();
            }
        }
        // Add space if necessary and possible.
        while (iMarked > iSpace - iSpace/10 && gHeapSizeParameters.AddSpaceBeforeCopyPhase(false) != 0)
            iSpace += gMem.DefaultSpaceSize();
        while (mMarked > mSpace - mSpace/10 && gHeapSizeParameters.AddSpaceBeforeCopyPhase(true) != 0)
            mSpace += gMem.DefaultSpaceSize();
    }

    /* Compact phase */
    GCCopyPhase();

    gHeapSizeParameters.RecordGCTime(HeapSizeParameters::GCTimeIntermediate, "Copy");

    // Update Phase.
    if (debugOptions & DEBUG_GC) Log("GC: Update\n");
    GCUpdatePhase();

    gHeapSizeParameters.RecordGCTime(HeapSizeParameters::GCTimeIntermediate, "Update");

    {
        POLYUNSIGNED iUpdated = 0, mUpdated = 0, iMarked = 0, mMarked = 0;
        for(j = 0; j < gMem.nlSpaces; j++)
        {
            LocalMemSpace *lSpace = gMem.lSpaces[j];
            iMarked += lSpace->i_marked;
            mMarked += lSpace->m_marked;
            if (lSpace->isMutable)
                mUpdated += lSpace->updated;
            else
                iUpdated += lSpace->updated;
        }
        ASSERT(iUpdated+mUpdated == iMarked+mMarked);
    }

    // Delete empty spaces.
    gMem.RemoveEmptyLocals();

    if (debugOptions & DEBUG_GC)
    {
        for(j = 0; j < gMem.nlSpaces; j++)
        {
            LocalMemSpace *lSpace = gMem.lSpaces[j];
            Log("GC: %s space %p %d free in %d words %2.1f%% full\n", lSpace->spaceTypeString(),
                lSpace, lSpace->freeSpace(), lSpace->spaceSize(),
                ((float)lSpace->allocatedSpace()) * 100 / (float)lSpace->spaceSize());
        }
    }

    // Compute values for statistics
    globalStats.setSize(PSS_AFTER_LAST_GC, 0);
    globalStats.setSize(PSS_AFTER_LAST_FULLGC, 0);
    globalStats.setSize(PSS_ALLOCATION, 0);
    globalStats.setSize(PSS_ALLOCATION_FREE, 0);

    for (j = 0; j < gMem.nlSpaces; j++)
    {
        LocalMemSpace *space = gMem.lSpaces[j];
        POLYUNSIGNED free = space->freeSpace();
        globalStats.incSize(PSS_AFTER_LAST_GC, free*sizeof(PolyWord));
        globalStats.incSize(PSS_AFTER_LAST_FULLGC, free*sizeof(PolyWord));
        if (space->allocationSpace)
        {
            globalStats.incSize(PSS_ALLOCATION, free*sizeof(PolyWord));
            globalStats.incSize(PSS_ALLOCATION_FREE, free*sizeof(PolyWord));
        }
#ifdef FILL_UNUSED_MEMORY
        memset(space->bottom, 0xaa, (char*)space->upperAllocPtr - (char*)space->bottom);
#endif
        if (debugOptions & DEBUG_GC)
            Log("GC: %s space %p %d free in %d words %2.1f%% full\n", space->spaceTypeString(),
                space, space->freeSpace(), space->spaceSize(),
                ((float)space->allocatedSpace()) * 100 / (float)space->spaceSize());
    }

    // End of garbage collection
    gHeapSizeParameters.RecordGCTime(HeapSizeParameters::GCTimeEnd);

    // Now we've finished we can adjust the heap sizes.
    gHeapSizeParameters.AdjustSizeAfterMajorGC(wordsRequiredToAllocate);
    gHeapSizeParameters.resetMajorTimingData();

    bool haveSpace = gMem.CheckForAllocation(wordsRequiredToAllocate);

    // Invariant: the bitmaps are completely clean.
    if (debugOptions & DEBUG_GC)
    {
        if (haveSpace)
            Log("GC: Completed successfully\n");
        else Log("GC: Completed with insufficient space\n");
    }

    if (debugOptions & DEBUG_HEAPSIZE)
        gMem.ReportHeapSizes("Full GC (after)");

    if (profileMode == kProfileLiveData || profileMode == kProfileLiveMutables)
        printprofile();

    CheckMemory();

    return haveSpace; // Completed
}
コード例 #26
0
template<class Tsrc> FIBITMAP* 
FFT2D<Tsrc>::FFT(FIBITMAP *src)
{
	int height, width;

	int i=0, x, y;
	int dims[2];
	int ndims = 2;
    size_t bufsize;
	Tsrc *bits; 
	FICOMPLEX *outbits;
	FIBITMAP *dst = NULL;
	
	kiss_fftnd_cfg st;
	kiss_fft_cpx* fftbuf;
	kiss_fft_cpx* fftoutbuf;
    kiss_fft_cpx* tmp_fftoutbuf;

	// Dims needs to be {rows, cols}, if you have contiguous rows.
	dims[0] = height = FreeImage_GetHeight(src);
	dims[1] = width = FreeImage_GetWidth(src);
	
    bufsize = width * height * sizeof(kiss_fft_cpx);
	fftbuf = (kiss_fft_cpx*) malloc(bufsize);
	tmp_fftoutbuf = fftoutbuf = (kiss_fft_cpx*) malloc(bufsize); 
	
    CheckMemory(fftbuf);
    CheckMemory(fftoutbuf);

	memset(fftbuf,0,bufsize);
    memset(tmp_fftoutbuf,0,bufsize);

	st = kiss_fftnd_alloc (dims, ndims, 0, 0, 0);

	for(y = height - 1; y >= 0; y--) { 
		
		bits = (Tsrc *) FreeImage_GetScanLine(src, y);
		
		for(x=0; x < width; x++) {
		
			fftbuf[i].r = (float) bits[x];
   		    fftbuf[i].i = 0.0;
   		 
   		    i++;
		}
	}

	kiss_fftnd(st, fftbuf, tmp_fftoutbuf);

	if ( (dst = FreeImage_AllocateT(FIT_COMPLEX, width, height, 32, 0, 0, 0)) == NULL )
		goto Error;

	for(y = height - 1; y >= 0; y--) { 
		
		outbits = (FICOMPLEX *) FreeImage_GetScanLine(dst, y);

		for(x=0; x < width; x++) {
				
			(outbits + x)->r = (double)((tmp_fftoutbuf + x)->r);
			(outbits + x)->i = (double)((tmp_fftoutbuf + x)->i);	  
		}

		tmp_fftoutbuf += width;
	}

Error:
 
    free(fftbuf);
    free(fftoutbuf);
    free(st);

	return dst;
}
コード例 #27
0
int
main(int argc, char **argv)
#endif
{
    LPTSTR tail;
#ifdef WGP_CONSOLE
    HINSTANCE hInstance = GetModuleHandle(NULL), hPrevInstance = NULL;
#else
    int i;
#endif

#ifndef WGP_CONSOLE
# if defined( __MINGW32__) && !defined(_W64)
#  define argc _argc
#  define argv _argv
# else /* MSVC, WATCOM, MINGW-W64 */
#  define argc __argc
#  define argv __argv
# endif
#endif /* WGP_CONSOLE */

    szModuleName = (LPTSTR) malloc((MAXSTR + 1) * sizeof(TCHAR));
    CheckMemory(szModuleName);

    /* get path to gnuplot executable  */
    GetModuleFileName(hInstance, szModuleName, MAXSTR);
    if ((tail = _tcsrchr(szModuleName, '\\')) != NULL) {
	tail++;
	*tail = 0;
    }
    szModuleName = (LPTSTR) realloc(szModuleName, (_tcslen(szModuleName) + 1) * sizeof(TCHAR));
    CheckMemory(szModuleName);

    if (_tcslen(szModuleName) >= 5 && _tcsnicmp(&szModuleName[_tcslen(szModuleName)-5], TEXT("\\bin\\"), 5) == 0) {
	size_t len = _tcslen(szModuleName) - 4;
	szPackageDir = (LPTSTR) malloc((len + 1) * sizeof(TCHAR));
	CheckMemory(szPackageDir);
	_tcsncpy(szPackageDir, szModuleName, len);
	szPackageDir[len] = NUL;
    } else {
	szPackageDir = szModuleName;
    }

#ifndef WGP_CONSOLE
    textwin.hInstance = hInstance;
    textwin.hPrevInstance = hPrevInstance;
    textwin.nCmdShow = nCmdShow;
    textwin.Title = L"gnuplot";
#endif

    /* create structure of first graph window */
    graphwin = (LPGW) calloc(1, sizeof(GW));
    listgraphs = graphwin;

    /* locate ini file */
    {
	char * inifile;
#ifdef UNICODE
	LPWSTR winifile;
#endif
	get_user_env(); /* this hasn't been called yet */
	inifile = gp_strdup("~\\wgnuplot.ini");
	gp_expand_tilde(&inifile);

	/* if tilde expansion fails use current directory as
	    default - that was the previous default behaviour */
	if (inifile[0] == '~') {
	    free(inifile);
	    inifile = "wgnuplot.ini";
	}
#ifdef UNICODE
	graphwin->IniFile = winifile = UnicodeText(inifile, S_ENC_DEFAULT);
#else
	graphwin->IniFile = inifile;
#endif
#ifndef WGP_CONSOLE
	textwin.IniFile = graphwin->IniFile;
#endif
	ReadMainIni(graphwin->IniFile, TEXT("WGNUPLOT"));
    }

#ifndef WGP_CONSOLE
    textwin.IniSection = TEXT("WGNUPLOT");
    textwin.DragPre = L"load '";
    textwin.DragPost = L"'\n";
    textwin.lpmw = &menuwin;
    textwin.ScreenSize.x = 80;
    textwin.ScreenSize.y = 80;
    textwin.KeyBufSize = 2048;
    textwin.CursorFlag = 1; /* scroll to cursor after \n & \r */
    textwin.shutdown = MakeProcInstance((FARPROC)ShutDown, hInstance);
    textwin.AboutText = (LPTSTR) malloc(1024 * sizeof(TCHAR));
    CheckMemory(textwin.AboutText);
    wsprintf(textwin.AboutText,
	TEXT("Version %hs patchlevel %hs\n") \
	TEXT("last modified %hs\n") \
	TEXT("%hs\n%hs, %hs and many others\n") \
	TEXT("gnuplot home:     http://www.gnuplot.info\n"),
	gnuplot_version, gnuplot_patchlevel,
	gnuplot_date,
	gnuplot_copyright, authors[1], authors[0]);
    textwin.AboutText = (LPTSTR) realloc(textwin.AboutText, (_tcslen(textwin.AboutText) + 1) * sizeof(TCHAR));
    CheckMemory(textwin.AboutText);

    menuwin.szMenuName = szMenuName;
#endif

    pausewin.hInstance = hInstance;
    pausewin.hPrevInstance = hPrevInstance;
    pausewin.Title = L"gnuplot pause";

    graphwin->hInstance = hInstance;
    graphwin->hPrevInstance = hPrevInstance;
#ifdef WGP_CONSOLE
    graphwin->lptw = NULL;
#else
    graphwin->lptw = &textwin;
#endif

    /* init common controls */
    {
	INITCOMMONCONTROLSEX initCtrls;
	initCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX);
	initCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&initCtrls);
    }

#ifndef WGP_CONSOLE
    if (TextInit(&textwin))
	gp_exit(EXIT_FAILURE);
    textwin.hIcon = LoadIcon(hInstance, TEXT("TEXTICON"));
    SetClassLongPtr(textwin.hWndParent, GCLP_HICON, (LONG_PTR)textwin.hIcon);

    /* Note: we want to know whether this is an interactive session so that we can
     * decide whether or not to write status information to stderr.  The old test
     * for this was to see if (argc > 1) but the addition of optional command line
     * switches broke this.  What we really wanted to know was whether any of the
     * command line arguments are file names or an explicit in-line "-e command".
     * (This is a copy of a code snippet from plot.c)
     */
    for (i = 1; i < argc; i++) {
	if (!_stricmp(argv[i], "/noend"))
	    continue;
	if ((argv[i][0] != '-') || (argv[i][1] == 'e')) {
	    interactive = FALSE;
	    break;
	}
    }
    if (interactive)
	ShowWindow(textwin.hWndParent, textwin.nCmdShow);
    if (IsIconic(textwin.hWndParent)) { /* update icon */
	RECT rect;
	GetClientRect(textwin.hWndParent, (LPRECT) &rect);
	InvalidateRect(textwin.hWndParent, (LPRECT) &rect, 1);
	UpdateWindow(textwin.hWndParent);
    }
# ifndef __WATCOMC__
    /* Finally, also redirect C++ standard output streams. */
    RedirectOutputStreams(TRUE);
# endif
#else  /* !WGP_CONSOLE */
# ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#  define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
# endif
    {
	/* Enable Windows 10 Console Virtual Terminal Sequences */
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	DWORD  mode;
	GetConsoleMode(handle, &mode);
	SetConsoleMode(handle, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
    }
#endif

    gp_atexit(WinExit);

    if (!_isatty(_fileno(stdin)))
	_setmode(_fileno(stdin), O_BINARY);

    gnu_main(argc, argv);

    /* First chance to close help system for console gnuplot,
	second for wgnuplot */
    WinCloseHelp();
    gp_exit_cleanup();
    return 0;
}
コード例 #28
0
ファイル: vSDP_struct.cpp プロジェクト: nberth/apron4opam
//----------------------------------------------------------------------
void smat(GeneralMatrix& M, double s, GeneralVector& vec, int* blkStruct, int nb)
{
  CheckVectorRange(nb);
  M.nBlock = nb;
  if (M.blockStruct) delete[] M.blockStruct; 
  M.blockStruct = new int[nb];
  CheckMemory(M.blockStruct);
  M.isSparse = vec.isSparse;
  if (!vec.isSparse)
  { 
    M.mat.resize(nb);
    int pos = 1;
    for (int l=0; l<nb; ++l) 
    {
      int bls = abs(blkStruct[l]);
      M.blockStruct[l] = blkStruct[l];
      Resize(M.mat[l], bls, bls);
      Initialize(M.mat[l], 0.0);
      for (int j=1; j<=bls; j++)
        for (int i=j; i<=bls; i++, pos++)
        {
	  INTERVAL buf;
	  CheckVectorIndex(pos, vec.n);
	  buf = vec.dvec(pos);
          if (i==j) M.mat[l](i,j) = buf;
            else M.mat[l](i,j) = M.mat[l](j,i) = buf/s;
        }
    }
  }
  else
  {
    M.smat.resize(nb);
    BIASINTERVAL *bbuf;
    int NonZeroInBlock;
    int blockShift = 0;
    int NonZeroCount = 0;
    for (int l=0; l<nb; ++l)
    {
      int bls = abs(blkStruct[l]);
      int vecbls = (bls*(bls+1))/2;
      M.blockStruct[l] = blkStruct[l];
      NonZeroInBlock = NonZeroCount;
      while (vec.svec.rowIndices[NonZeroInBlock]-blockShift < vecbls) NonZeroInBlock++;
      NonZeroInBlock -= NonZeroCount;
      Resize(M.smat[l], bls, bls, NonZeroInBlock);
      for (int eleCount=NonZeroCount; eleCount<NonZeroCount+NonZeroInBlock; eleCount++)
      {
	bbuf = vec.svec.theElements + eleCount;      
	int p = vec.svec.rowIndices[eleCount]-blockShift;
        int st = bls;
	int i = 0, j = 0;
	while (p > 0) {p -= st; st--; j++;}
	i = bls + p;	
	if (i==j)
        {
          SetElement(vec.svec, i, j, *((INTERVAL *)bbuf));
        }
        else
        {
          SetElement(vec.svec, i, j, *((INTERVAL *)bbuf)/s);
          SetElement(vec.svec, j, i, *((INTERVAL *)bbuf)/s);
        }
      }
      blockShift += vecbls;      
      NonZeroCount += NonZeroInBlock;
    }
    //if (NonZeroCount != vec.svec.colStarts[1]) cout << "smat: wrong NonZeroCount value...\n"; // just for debugging purposes
  }
}