Exemple #1
0
void			ldi(t_vm *vm, t_process *proc)
{
	t_instruction	*instr;
	t_arg_type		type[2];
	int				ops[2];
	int				data;
	size_t			reg;

	instr = &proc->instruction;
	reg = instr->params[2];
	type[0] = instr->args_types[0];
	type[1] = instr->args_types[1];
	if (check_param(instr->args_types[2], reg)
		&& check_param(type[0], instr->params[0])
		&& check_param(type[1], instr->params[1]))
	{
		ops[0] = get_value(type[0], instr->params[0], &vm->arena, proc);
		ops[1] = get_value(type[1], instr->params[1], &vm->arena, proc);
		data = loadmem(&vm->arena, REG_SIZE,
						proc->pc + (ops[0] + ops[1]) % IDX_MOD);
		ltob(&data, REG_SIZE);
		storeg(&proc->registers[reg], &data, REG_SIZE);
	}
	move_pc(&proc->pc, instr->size);
}
Exemple #2
0
/*
ULONG FAR retcs(int i)
{
    char *p = (char*)&i;
    
    p -= 4;
    return *(ULONG *)p;
}
*/
COUNT do_printf(CONST BYTE * fmt, BYTE ** arg)
{
  int base;
  BYTE s[11], FAR * p;
  int c, flag, size, fill;
  int longarg;
  long currentArg;

/*  
  long cs = retcs(1);
  put_console("0123456789ABCDEF"[(cs >> 28) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >> 24) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >> 20) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >> 16) & 0x0f]);
  put_console(':');
  put_console("0123456789ABCDEF"[(cs >> 12) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >>  8) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >>  4) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >>  0) & 0x0f]);
*/
  while ((c = *fmt++) != '\0')
  {
    if (c != '%')
    {
      handle_char(c);
      continue;
    }

    longarg = FALSE;
    size = 0;
    flag = RIGHT;
    fill = ' ';

    if (*fmt == '-')
    {
      flag = LEFT;
      fmt++;
    }

    if (*fmt == '0')
    {
      fill = '0';
      fmt++;
    }

    while (*fmt >= '0' && *fmt <= '9')
    {
      size = size * 10 + (*fmt++ - '0');
    }

    if (*fmt == 'l')
    {
      longarg = TRUE;
      fmt++;
    }

    c = *fmt++;
    switch (c)
    {
      case '\0':
        return 0;

      case 'c':
        handle_char(*(COUNT *) arg++);
        continue;

      case 'p':
        {
          UWORD w[2];
          w[1] = *((UWORD *) arg);
          arg += sizeof(UWORD) / sizeof(BYTE *);
          w[0] = *((UWORD *) arg);
          arg += sizeof(UWORD) / sizeof(BYTE *);
          do_printf("%04x:%04x", (BYTE **) & w);
          continue;
        }

      case 's':
        p = *arg++;
        goto do_outputstring;

      case 'F':
        fmt++;
        /* we assume %Fs here */
      case 'S':
        p = *((BYTE FAR **) arg);
        arg += sizeof(BYTE FAR *) / sizeof(BYTE *);
        goto do_outputstring;

      case 'i':
      case 'd':
        base = -10;
        goto lprt;

      case 'o':
        base = 8;
        goto lprt;

      case 'u':
        base = 10;
        goto lprt;

      case 'X':
      case 'x':
        base = 16;

      lprt:
        if (longarg)
        {
          currentArg = *((LONG *) arg);
          arg += sizeof(LONG) / sizeof(BYTE *);
        }
        else
        {
          if (base < 0)
          {
            currentArg = *((int *)arg);
            arg += sizeof(int) / sizeof(BYTE *);
          }
          else
          {
            currentArg = *((unsigned int *)arg);
            arg += sizeof(unsigned int) / sizeof(BYTE *);
          }
        }

        ltob(currentArg, s, base);

        p = s;
      do_outputstring:

        size -= fstrlen(p);

        if (flag == RIGHT)
        {
          for (; size > 0; size--)
            handle_char(fill);
        }
        for (; *p != '\0'; p++)
          handle_char(*p);

        for (; size > 0; size--)
          handle_char(fill);

        continue;

      default:
        handle_char('?');

        handle_char(c);
        break;

    }
  }
  return 0;
}