📄 halsimuv.c
字号:
/* ============================================================================ Project Name : jayaCard Module Name : proto/hal/simu/halsimuv.c Version : $Id: halsimuv.c,v 1.3 2004/01/11 09:56:33 dgil Exp $ Description: Hardware Abstract Layer - VARIABLE SIMULATOR The Original Code is jayaCard code. The Initial Developer of the Original Code is Gilles Dumortier. Portions created by the Initial Developer are Copyright (C) 2002-2004 the Initial Developer. All Rights Reserved. Contributor(s): This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see http://www.gnu.org/licenses/gpl.html History Rev Description 101703 dgil wrote it from halsimu.h ============================================================================*/#include "precomp.h"/* ========================================================================= Local Defs ========================================================================= */typedef struct tagSimuVariable { char* name; jword pos; jbyte size; jbyte type; /* IDATA, XDATA, ... */ struct tagSimuVariable* next;} SIMUVAR,*PSIMUVAR;/* ========================================================================= Local globals ========================================================================= */PSIMUVAR gListSimuVar = NULL;/* ========================================================================= newSimuVar() ========================================================================= */PSIMUVAR newSimuVar(char* name,jword pos,jbyte size,jbyte type){ PSIMUVAR pVar; if (name==NULL) return NULL; pVar = (PSIMUVAR)malloc(sizeof(SIMUVAR)); if (pVar==NULL) return NULL; memset(pVar,0,sizeof(SIMUVAR)); pVar->name = (char*)malloc(strlen(name)+1); if (pVar->name==NULL) { free(pVar); return NULL; } strcpy(pVar->name,name); pVar->pos = pos; pVar->size = size; pVar->type = type; return pVar;}/* ========================================================================= freeSimuVar() ========================================================================= */void freeSimuVar(PSIMUVAR pVar){ if (pVar==NULL) return; if (pVar->name!=NULL) { free(pVar->name); pVar->name = NULL; } pVar->next = NULL; free(pVar);}/* ========================================================================= addSimuVar() ========================================================================= */void addSimuVar(char* name,jword pos,jbyte size,jbyte type){ PSIMUVAR pVar; pVar = newSimuVar(name,pos,size,type); if (pVar==NULL) { fprintf(stderr,"addSimuVar(%s) : error allocation the SIMUVAR structure !\n",name); exit(-1); } pVar->next = gListSimuVar; gListSimuVar = pVar; LOG2("SimuVar","addSimuVar %s %lx",name,gListSimuVar);}/* ========================================================================= delSimuVar() ========================================================================= */void delSimuVar(char* name,jbyte type){ PSIMUVAR pPrev; PSIMUVAR pCur; pPrev = NULL; pCur = gListSimuVar; while (pCur!=NULL) { if ( (type==pCur->type) && (strcmp(name,pCur->name)==0) ) { LOG1("SimuVar","delSimuVar %s",name); if (pPrev==NULL) { gListSimuVar = pCur->next; } else { pPrev->next = pCur->next; } freeSimuVar(pCur); return; } /* try on the next node */ pPrev = pCur; pCur = pCur->next; } fprintf(stderr,"delSimuVar(%s) : SIMUVAR structure not found in the list !\n",name);}/* ========================================================================= doneListSimuVar() ========================================================================= */void doneListSimuVar(void){ PSIMUVAR pVar; if (gListSimuVar == NULL) return; while (gListSimuVar != NULL) { pVar = gListSimuVar; gListSimuVar = gListSimuVar->next; freeSimuVar(pVar); }}/* ========================================================================= initListSimuVar() ========================================================================= */void initListSimuVar(void){ if (gListSimuVar != NULL) doneListSimuVar();}/* ========================================================================= dumpSimuVar() Dump a specific variable content inside the buffer; also manage very special case through a bios simulator helper function. ========================================================================= */void dumpSimuVar(char* buf,PSIMUVAR pVar){ char szType[80]; char szVal[80]; jbyte v; jword i; switch (pVar->type) { case SIMUVAR_IDATA: strcpy(szType,"IDATA"); break; case SIMUVAR_XDATA: strcpy(szType,"XDATA"); break; case SIMUVAR_LOCAL: strcpy(szType,"LOCAL"); break; case SIMUVAR_BDATA: strcpy(szType,"BDATA"); break; case SIMUVAR_BLOCAL: strcpy(szType,"BLOCAL"); break; default: strcpy(szType,"???"); break; } sprintf(buf,"%s [%s:%.4X - %.2X(%d)]:",pVar->name,szType,pVar->pos,pVar->size,pVar->size); for (i=0; i<pVar->size; i++) { switch (pVar->type) { case SIMUVAR_IDATA: v = gIDATA.cells()[pVar->pos+i]; break; case SIMUVAR_XDATA: v = gXDATA.cells()[pVar->pos+i]; break; case SIMUVAR_LOCAL: v = gIDATA.cells()[pVar->pos+i]; break; default: return; } if ((i%16)==15) { sprintf(szVal," %.2X\n",v); } else { sprintf(szVal," %.2X",v); } strcat(buf,szVal); }}/* ========================================================================= dumpAllSimuVar() ========================================================================= */void dumpAllSimuVar(int step){ PSIMUVAR pVar; char buf[1024]; FILE* f; char szFilename[80]; if (step==RAM_FILE_LIVE) { strcpy(szFilename,"ram.txt"); } else { sprintf(szFilename,"ram%.3d.txt",step); } f = fopen(szFilename,"wt"); if (f==NULL) { fprintf(stderr,"dumpAllSimuVar(): can't open the '%s' file to write to !\n",szFilename); return; } pVar = gListSimuVar; while (pVar != NULL) { dumpSimuVar(buf,pVar); fprintf(f,"%s\n",buf); pVar = pVar->next; } fclose(f);}/* ========================================================================= That's all folks ! ========================================================================= */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -