コード例 #1
0
ファイル: fileio.c プロジェクト: dschwen/jszip
/*
 * close_script
 *
 * Close the scripting file.
 *
 */
void close_script( void )
{
   /* Close scripting file if open */
   if ( scripting == ON )
   {
      fclose( sfp );
#if 0
      /* Cleanup */
      file_cleanup( script_name, GAME_SCRIPT );
#endif
      /* Turn off scripting */
      scripting = OFF;
   }

   /* Set the scripting flag in the game file flags */
   if ( scripting == OFF )
   {
      set_word( H_FLAGS, get_word( H_FLAGS ) & ( ~SCRIPTING_FLAG ) );
   }
   else
   {
      set_word( H_FLAGS, get_word( H_FLAGS ) | SCRIPTING_FLAG );
   }

}                               /* close_script */
コード例 #2
0
ファイル: directory.c プロジェクト: Distrotech/mtools
struct directory *mk_entry(const dos_name_t *dn, char attr,
			   unsigned int fat, size_t size, time_t date,
			   struct directory *ndir)
{
	struct tm *now;
	time_t date2 = date;
	unsigned char hour, min_hi, min_low, sec;
	unsigned char year, month_hi, month_low, day;

	now = localtime(&date2);
	dosnameToDirentry(dn, ndir);
	ndir->attr = attr;
	ndir->ctime_ms = 0;
	hour = now->tm_hour << 3;
	min_hi = now->tm_min >> 3;
	min_low = now->tm_min << 5;
	sec = now->tm_sec / 2;
	ndir->ctime[1] = ndir->time[1] = hour + min_hi;
	ndir->ctime[0] = ndir->time[0] = min_low + sec;
	year = (now->tm_year - 80) << 1;
	month_hi = (now->tm_mon + 1) >> 3;
	month_low = (now->tm_mon + 1) << 5;
	day = now->tm_mday;
	ndir -> adate[1] = ndir->cdate[1] = ndir->date[1] = year + month_hi;
	ndir -> adate[0] = ndir->cdate[0] = ndir->date[0] = month_low + day;

	set_word(ndir->start, fat & 0xffff);
	set_word(ndir->startHi, fat >> 16);
	set_dword(ndir->size, size);
	return ndir;
}
コード例 #3
0
static int flush_file(Stream_t *Stream)
{
	DeclareThis(File_t);
	direntry_t *entry = &This->direntry;

	if(isRootDir(Stream)) {
		return 0;
	}

	if(This->FirstAbsCluNr != getStart(entry->Dir, &entry->dir)) {
		set_word(entry->dir.start, This->FirstAbsCluNr & 0xffff);
		set_word(entry->dir.startHi, This->FirstAbsCluNr >> 16);
		dir_write(entry);
	}
コード例 #4
0
ファイル: configur.cpp プロジェクト: digitall/AZIP
void restart_screen( void )
{
    zbyte_t high = 1, low = 0;

    set_byte( H_STANDARD_HIGH, high );
    set_byte( H_STANDARD_LOW, low );

    if ( h_type < V4 )
        set_byte( H_CONFIG, ( get_byte( H_CONFIG ) | CONFIG_NOSTATUSLINE ) );

    /* Force graphics off as we can't do them */
    set_word( H_FLAGS, ( get_word( H_FLAGS ) & ( ~GRAPHICS_FLAG ) ) );

}                               /* restart_screen */
コード例 #5
0
ファイル: mpa_io.c プロジェクト: MALATTAR/optee_os
int mpa_set_oct_str(mpanum dest, const uint8_t *buffer, size_t buffer_len,
		  bool negative)
{
	const uint8_t *buf = buffer;
	int bufidx = buffer_len;
	mpa_word_t *w;

	/* Strip of leading zero octets */
	while (bufidx > 0) {
		if (*buf != 0)
			break;
		bufidx--;
		buf++;
	}

	if (bufidx == 0) {
		mpa_set_word(dest, 0);
		return 0;
	}

	/*
	 * bufidx is now indexing one byte past past the last byte in the octet
	 * string relative to buf.
	 */

	if ((size_t) (bufidx - 1) > (BYTES_PER_WORD * __mpanum_alloced(dest)))
		return -1;	/* No space */

	w = dest->d;
	mpa_set_word(dest, 0);
	/* start converting */
	dest->size = 0;
	while (bufidx > 0) {
		int l = __MIN(BYTES_PER_WORD, bufidx);

		bufidx -= l;
		*w = set_word(buf + bufidx, l);
		w++;
		dest->size++;
	}

	if (negative)
		__mpanum_neg(dest);

	return 0;
}
コード例 #6
0
ファイル: operand.cpp プロジェクト: digitall/AZIP
void z_store( int number, zword_t variable )
{

    if ( number )
    {
        if ( number < 16 )

            /* number in range 1 - 15, it's a stack local variable */

            stack[fp - ( number - 1 )] = variable;
        else
            /* number > 15, it's a global variable */

            set_word( h_globals_offset + ( ( number - 16 ) * 2 ), variable );
    }
    else
        /* number = 0, get from top of stack */

        stack[sp] = variable;

}                               /* z_store */
コード例 #7
0
ファイル: shell.c プロジェクト: Sh4d1/projet_mips2016
int shell_smem(char **args)
{
    if (!args[2]) return MISSING_ARGS;

    // activation du masque pour ne pas quitter lors d'un check d'adresse
    switch_exitMask();

    uint32_t value = get_value_from_string(args[2]);
    uint32_t nbOctets = (args[3]) ? get_value_from_string(args[3]) : 1;
    switch (nbOctets) {
    case 1:
        if (is_byte(value)) {
            set_byte(get_value_from_string(args[1]), value);
        } else {
            fprintf(stderr, "La valeur est trop grande pour rentrer sur un octet\n");
        }
        break;
    case 2:
        if (is_half_word(value)) {
            set_half_word(get_value_from_string(args[1]), value);
        } else {
            fprintf(stderr, "La valeur est trop grande pour rentrer sur un demi-mot\n");
        }
        break;
    case 4:
        set_word(get_value_from_string(args[1]), value);
        break;
    default:
        fprintf(stderr, "Le nombre d'octets à écrire est soit 1, 2 ou 4\n");
    }

    // on desactive le masque, les checks d'addresse sont termines
    switch_exitMask();

    return OK;
}
コード例 #8
0
ファイル: io.c プロジェクト: Razofiter/Luminary-Micro-Library
//*****************************************************************************
//
// This function restarts the screen.
//
//*****************************************************************************
void
restart_screen(void)
{
    //
    // Set the current column to the beginning of the line.
    //
    g_lCurColumn = 1;

    //
    // Discard any saved cursor column.
    //
    g_lCursorSaved = 0;

    //
    // Characters should be displayed.
    //
    g_lDisplay = 1;

    //
    // The the ZIP configuration flags based on the type of the game.
    //
    if(h_type < V4)
    {
        set_byte(H_CONFIG, get_byte(H_CONFIG) | CONFIG_WINDOWS);
    }
    else
    {
        set_byte(H_CONFIG,
                 get_byte(H_CONFIG) | CONFIG_EMPHASIS | CONFIG_WINDOWS);
    }

    //
    // Set the ZIP flags.
    //
    set_word(H_FLAGS, (get_word(H_FLAGS) & ~GRAPHICS_FLAG));
}
コード例 #9
0
ファイル: fileio.c プロジェクト: dschwen/jszip
void open_script( void )
{
   char new_script_name[Z_FILENAME_MAX + Z_PATHNAME_MAX + 1];

   /* Open scripting file if closed */
   if ( scripting == OFF )
   {
      if ( script_file_valid == TRUE )
      {
         sfp = fopen( script_name, "a" );

         /* Turn on scripting if open succeeded */
         if ( sfp != NULL )
         {
#if defined BUFFER_FILES        
            setbuf( sfp, sfpbuffer ); 
#endif 
            scripting = ON;
         }
         else
         {
            output_line( "Script file open failed" );
         }
      }
      else
      {                         /* Get scripting file name and record it */
         if ( get_file_name( new_script_name, script_name, GAME_SCRIPT ) == 0 )
         {
            /* Open scripting file */
            sfp = fopen( new_script_name, "w" );

            /* Turn on scripting if open succeeded */
            if ( sfp != NULL )
            {
#if defined BUFFER_FILES        
               setbuf( sfp, sfpbuffer ); 
#endif 
               script_file_valid = TRUE;

               /* Make file name the default name */
               strcpy( script_name, new_script_name );

               /* Turn on scripting */
               scripting = ON;
            }
            else
            {
               output_line( "Script file create failed" );
            }
         }
      }
   }

   /* Set the scripting flag in the game file flags */
   if ( scripting == ON )
   {
      set_word( H_FLAGS, get_word( H_FLAGS ) | SCRIPTING_FLAG );
   }
   else
   {
      set_word( H_FLAGS, get_word( H_FLAGS ) & ( ~SCRIPTING_FLAG ) );
   }

}                               /* open_script */
コード例 #10
0
ファイル: fileio.c プロジェクト: dschwen/jszip
static int save_restore( const char *file_name, int flag )
{
   FILE *tfp = NULL;

#if defined BUFFER_FILES        
   char tfpbuffer[BUFSIZ];      
#endif 
   int scripting_flag = 0, status = 0;

#if !defined(USE_QUETZAL)
   zword_t zw;
   int little_endian = 0;

   /* Find out if we are big-endian */
   zw = 0x0001;
   if ( *( zbyte_t * ) & zw )
   {                            /* We are little-endian, like an Intel 80x86 chip. */
      little_endian = 1;
   }
#endif

   /* Open the save file and disable scripting */

   if ( flag == GAME_SAVE || flag == GAME_RESTORE )
   {
      if ( ( tfp = fopen( file_name, ( flag == GAME_SAVE ) ? "wb" : "rb" ) ) == NULL )
      {
         output_line( "Cannot open SAVE file" );
         return ( 1 );
      }
#if defined BUFFER_FILES        
      setbuf( tfp, tfpbuffer ); 
#endif 
      scripting_flag = get_word( H_FLAGS ) & SCRIPTING_FLAG;
      set_word( H_FLAGS, get_word( H_FLAGS ) & ( ~SCRIPTING_FLAG ) );
   }

#if defined(USE_QUETZAL)
   if ( flag == GAME_SAVE )
   {
      status = !save_quetzal( tfp, gfp );
   }
   else if ( flag == GAME_RESTORE )
   {
      status = !restore_quetzal( tfp, gfp );
   }
   else
   {
#endif /* defined(USE_QUETZAL) */
      /* Push PC, FP, version and store SP in special location */

      stack[--sp] = ( zword_t ) ( pc / PAGE_SIZE );
      stack[--sp] = ( zword_t ) ( pc % PAGE_SIZE );
      stack[--sp] = fp;
      stack[--sp] = h_version;
      stack[0] = sp;

      /* Save or restore stack */

#if !defined(USE_QUETZAL)
      if ( flag == GAME_SAVE )
      {
         if ( little_endian )
            swap_bytes( stack, sizeof ( stack ) );
         if ( status == 0 && fwrite( stack, sizeof ( stack ), 1, tfp ) != 1 )
            status = 1;
         if ( little_endian )
            swap_bytes( stack, sizeof ( stack ) );
      }
      else if ( flag == GAME_RESTORE )
      {
         if ( little_endian )
            swap_bytes( stack, sizeof ( stack ) );
         if ( status == 0 && fread( stack, sizeof ( stack ), 1, tfp ) != 1 )
            status = 1;
         if ( little_endian )
            swap_bytes( stack, sizeof ( stack ) );
      }
      else
#endif /* !defined(USE_QUETZAL) */
      {
         if ( flag == UNDO_SAVE )
         {
            memmove( undo_stack, stack, sizeof ( stack ) );
         }
         else                   /* if (flag == UNDO_RESTORE) */
         {
            memmove( stack, undo_stack, sizeof ( stack ) );
         }
      }

      /* Restore SP, check version, restore FP and PC */

      sp = stack[0];

      if ( stack[sp++] != h_version )
      {
         fatal( "save_restore(): Wrong game or version" );
      }

      fp = stack[sp++];
      pc = stack[sp++];
      pc += ( unsigned long ) stack[sp++] * PAGE_SIZE;

      /* Save or restore writeable game data area */

#if !defined(USE_QUETZAL)
      if ( flag == GAME_SAVE )
      {
         if ( status == 0 && fwrite( datap, h_restart_size, 1, tfp ) != 1 )
            status = 1;
      }
      else if ( flag == GAME_RESTORE )
      {
         if ( status == 0 && fread( datap, h_restart_size, 1, tfp ) != 1 )
            status = 1;
      }
      else
#endif /* !defined(USE_QUETZAL) */
      {
         if ( flag == UNDO_SAVE )
         {
            memmove( undo_datap, datap, h_restart_size );
         }
         else                   /* if (flag == UNDO_RESTORE) */
         {
            memmove( datap, undo_datap, h_restart_size );
         }
      }

#if defined(USE_QUETZAL)
   }
#endif /* defined(USE_QUETZAL) */


   /* Close the save file and restore scripting */

   if ( flag == GAME_SAVE )
   {
      fclose( tfp );
      if ( scripting_flag )
      {
         set_word( H_FLAGS, get_word( H_FLAGS ) | SCRIPTING_FLAG );
      }
   }
   else if ( flag == GAME_RESTORE )
   {
      fclose( tfp );
      restart_screen(  );
      restart_interp( scripting_flag );
   }

   /* Handle read or write errors */

   if ( status )
   {
      if ( flag == GAME_SAVE )
      {
         output_line( "Write to SAVE file failed" );
         remove( file_name );
      }
      else
      {
         fatal( "save_restore(): Read from SAVE file failed" );
      }
   }

   return ( status );

}                               /* save_restore */
コード例 #11
0
ファイル: sim.c プロジェクト: jmesmon/iloc_sim
int main(int argc, char* argv[])
{
    int mem_size = 0;
    int reg_size = 0;
    int current_argument = 1;
    int machine_initialized = 0;
    Instruction* code;

    /* Set default stall mode - branches, registers, and memory */
    set_stall_mode(3 /*2*/);

    while(current_argument < argc) 
    {
	if (strcmp(argv[current_argument],"-h") == 0)
	{
	    print_help();
	    return 0;
	}
	
	/* All of the following flags require at least one additional parameter,
	   so perform check here. */
	if (current_argument == argc - 1)
	{
	    fprintf(stderr,"Invalid flag sequence: make sure any required numbers are included.\n");
	    return(1);
	}


	if (strcmp(argv[current_argument],"-r") == 0)
	{
	    reg_size = (int) strtol(argv[current_argument+1],(char**)NULL,10);
	    current_argument += 2;
	}
	else
	{
	    if (strcmp(argv[current_argument],"-m") == 0)
	    {
		mem_size = (int) strtol(argv[current_argument+1],(char**)NULL,10);
		current_argument += 2;
	    }
	    else
	    {
		if (strcmp(argv[current_argument],"-s") == 0)
		{
		    set_stall_mode((int)strtol(argv[current_argument+1],(char**)NULL,10));
		    current_argument += 2;
		}
		else
		{
		    if (strcmp(argv[current_argument],"-i") == 0)
		    {
			int i;
			int start_location = (int)strtol(argv[current_argument+1],(char**)NULL,10);
			initialize_machine(reg_size,mem_size);
			machine_initialized = 1;
			for(i = 0; i < (argc - current_argument - 2); i++)
			    set_word(start_location + 4*i, (int)strtol(argv[current_argument+2+i],
								       (char**)NULL,10));
			current_argument = argc;
		    }
		    else
		    {
			if (strcmp(argv[current_argument],"-c") == 0)
			{
			    int i;
			    int start_location = (int)strtol(argv[current_argument+1],
							     (char**)NULL,10);
			    initialize_machine(reg_size,mem_size);
			    machine_initialized = 1;
			    for(i = 0; i < (argc - current_argument - 2); i++)
				set_memory(start_location + i, 
					 (char)strtol(argv[current_argument+2+i],
						     (char**)NULL,10));
			    current_argument = argc;
			}
			else
			{
			    fprintf(stderr,"Invalid flag specified\n");
			    return 0;
			}
		    }
		}
	    }
	}
	
    }
    
    if (!machine_initialized)
	initialize_machine(reg_size,mem_size);

    code = parse();

    if (!code)
    {
	fprintf(stderr,"Error reading input file, simulator not run.\n");
	return 1;
    }

    simulate(code);

    return 0;
};