// Function for simulating defense, includes Focus and Evade action
int SimulateEvadeDice(int numEvadeDice, bool EvadeFocus, bool EvadeToken)
{
	int EvadeCounter = 0;
	int DefenseFocusCounter = 0;

	std::uniform_int_distribution<int> d8(1, 8);

	for (int i = 0; i < numEvadeDice; i++)
	{
		int Dice = d8(mt);
		if (1 <= Dice && Dice <= 3)
		{
			++EvadeCounter;
		}
		else if (4 <= Dice && Dice <= 5 && EvadeFocus)
		{
			++DefenseFocusCounter;
		}
	}

	
	int totalEvade = EvadeCounter + DefenseFocusCounter;
	if (EvadeToken)
	{
		totalEvade = ++totalEvade;
	}
	return totalEvade;
}
Пример #2
0
int hdd_io(int hdd_n, void *buff, u16 sectors, u64 start, int read)
{
	u8       sbuf[32];
	rm_ctx   ctx;
	u32      head, cyl;
	u8       dos_n = hdd2dos(hdd_n);
	hdd_inf *hdd   = &iodb.p_hdd[hdd_n];
	lba_p   *lba   = pv(0x580); /* this needed for avoid stupid actions by buggy BIOSes */	
	int      succs = 0;

	/* setup initial context */
	set_ctx(0, &ctx);

	if (hdd->flags & HDD_LBA)
	{
		/* save old buffer */
		mincpy(sbuf, lba, sizeof(sbuf));

		/* setup LBA block */
		lba->size    = sizeof(lba_p);
		lba->unk     = 0;
		lba->dst_sel = rm_seg(buff);
		lba->dst_off = rm_off(buff);
		lba->numb    = sectors; 
		lba->sector  = start;
		
		ctx.ah = read ? 0x42:0x43;
		ctx.dl = dos_n; 
		ctx.si = 0x180; 
		ctx.ds = 0x40; /* if DS can be 0x40, we can avoid AWARD BIOS bug of int13/AX=4B01 */ 
		/* set additional registers to serve buggy BIOSes. */
		ctx.es = ctx.ds;
		ctx.di = ctx.si;
		ctx.bx = ctx.si;
		ctx.cx = ctx.ds;
		/* do not check AH because some buggy USB BIOSes fail to clear AH on success */
		succs = bios_call(0x13, &ctx);

		/* restore saved buffer */
		mincpy(lba, sbuf, sizeof(sbuf));
	} else
	{
		head = d32(start) / hdd->max_sect;		
		cyl  = head / hdd->max_head;

		ctx.ah = read ? 0x02:0x03;
		ctx.al = d8(sectors);
		ctx.ch = d8(cyl);
		ctx.cl = d8(((cyl & 0x0300) >> 2) | (d32(start) % hdd->max_sect + 1));
		ctx.dh = head % hdd->max_head;
		ctx.dl = dos_n;
		ctx.es = rm_seg(buff);
		ctx.bx = rm_off(buff);

		/* do not check AH because some buggy USB BIOSes fail to clear AH on success */
		succs = bios_call(0x13, &ctx);
	}
	return succs;
}
Пример #3
0
void 
DgSqrD4Grid2DS::setAddBoundaryChildren (const DgResAdd<DgIVec2D>& add, 
                                        DgLocVector& vec) const
{
   if (isCongruent() || radix() == 3)
   {
      // no boundary children in this topology; leave vec empty
   }
   else // must be aligned aperture 4
   {
      DgLocation* tmpLoc = makeLocation(add);

      // D8 neighbors is what we want

      DgSqrD8Grid2D d8(network(), grids()[add.res() + 1]->backFrame(), 
                       "dummyD8");
      d8.convert(tmpLoc);
      d8.setNeighbors(*tmpLoc, vec);

      grids()[add.res() + 1]->convert(vec);
      convert(vec);

      delete tmpLoc;
   }

} // void DgSqrD4Grid2DS::setAddBoundaryChildren
Пример #4
0
int on_int13(rm_ctx *ctx)
{
	hdd_inf *hdd;
	void    *buff;
	lba_p   *lba = NULL;
	u16      numb;
	u64      start;
	int      need = 0;
	int      res;
	u8       func;

	if (hdd = find_hdd(ctx->dl)) 
	{
		func = ctx->ah;

		if ( (func == 0x02) || (func == 0x03) )
		{
			start = ((ctx->ch + ((ctx->cl & 0xC0) << 2)) * 
				     hdd->max_head + ctx->dh) * hdd->max_sect + (ctx->cl & 0x3F) - 1;
			buff  = pm_off(ctx->es, ctx->bx);
			numb  = ctx->al;
			need  = 1; 
		}

		if ( (func == 0x42) || (func == 0x43) )
		{
			lba   = pm_off(ctx->ds, ctx->si);
			start = lba->sector;
			buff  = pm_off(lba->dst_sel, lba->dst_off);
			numb  = lba->numb;
			need  = 1; 
		}
	}

	if (need != 0) 
	{
		res = dc_disk_io(
			    hdd, buff, numb, start, 
				(func == 0x02) || (func == 0x42));

		if (res != 0) 
		{
			ctx->ah   = 0;
			ctx->efl &= ~FL_CF;

			if (lba != NULL) {
				lba->numb = numb;
			} else {
				ctx->al = d8(numb);
			}
		} else {
			ctx->efl |= FL_CF;
		}
	}

	return need;
}
Пример #5
0
unsigned int DiceBox::d8(const unsigned short int n)
{
  unsigned int result = 0;
  unsigned int i;
  for (i=0; i<n; i=i+1)
  {
    result += d8();
  }
  return result;
}
Пример #6
0
bool
AbLightningBolt::invoke(Actor *invoker, Level *level, bool &cancelled)
{
    bool done = false;
    Actor *target;
    while(!done){
        target = invoker->getTarget(TARGET_HOSTILE);
        if(target ==0){
            level->m_messages->showMessage("Are you sure that you do not want to target anyone? (y/n)", MESSAGE_WARNING);
            level->render();
            TCODConsole::flush();
            bool selected = false;
            while(!selected){
                TCOD_key_t key = TCODConsole::waitForKeypress(true);
                if(key.pressed){
                    switch(key.c) {
                        case 'y':
                        case 'Y':
                            done = true;selected = true; break;
                        case 'n':
                        case 'N':
                            selected = true; break;
                    }
                }
            }
        }
        else{
            done = true;
        }
    }
    if(target == 0){
        cancelled = true;
        return false;
    }
    else{
        std::string msg = "A spark of lightning shoots from your fingers and hits the ";
        msg += target->m_name;
        level->m_messages->showMessage(msg, MESSAGE_WARNING);
        int damage = 5;
        for(int i=0; i<1+invoker->m_hd/2;i++){
            damage += d8(RAND);
        }
        if(!target->takeDamage(damage, DAMAGE_FIRE, invoker)){
            level->killActor(target,invoker);
        }
    }
    cancelled = false;
    return true;
}
Пример #7
0
static void int13_callback()
{
	rm_ctx ctx;
	u16      p_efl = bdat->push_fl;
	int      need  = 0;
	hdd_inf *hdd   = NULL;
	lba_p   *lba   = NULL;
	void    *buff;
	u16      numb;
	u64      start;
	int      hdd_n;

	if (bdat->rmc.dl == 0x80) {
		bdat->rmc.dl = bdat->boot_dsk;
	} else if (bdat->rmc.dl == bdat->boot_dsk) {
		bdat->rmc.dl = 0x80;
	}
	/* copy context to temporary buffer */
	mincpy(&ctx, &bdat->rmc, sizeof(rm_ctx));

	if ( ((hdd_n = dos2hdd(ctx.dl)) >= 0) && (hdd_n < iodb.n_hdd) ) {
		hdd = &iodb.p_hdd[hdd_n];
	}
	if (hdd != NULL)
	{
		if ( (ctx.ah == 0x02) || (ctx.ah == 0x03) )
		{
			start = ((ctx.ch + ((ctx.cl & 0xC0) << 2)) * 
				    hdd->max_head + ctx.dh) * hdd->max_sect + (ctx.cl & 0x3F) - 1;
			buff  = pm_off(ctx.es, ctx.bx);
			numb  = ctx.al;
			need  = 1; 
		}
		if ( (ctx.ah == 0x42) || (ctx.ah == 0x43) )
		{
			lba   = pm_off(ctx.ds, ctx.si);
			start = lba->sector;
			buff  = pm_off(lba->dst_sel, lba->dst_off);
			numb  = lba->numb;
			need  = 1; 
		}
	}

	if (need != 0) 
	{
		if (dc_disk_io(hdd_n, buff, numb, start, (ctx.ah == 0x02) || (ctx.ah == 0x42)) != 0) 
		{
			ctx.ah   = 0;
			ctx.efl &= ~FL_CF;

			if (lba != NULL) {
				lba->numb = numb;
			} else {
				ctx.al = d8(numb);
			}
		} else {
			ctx.efl |= FL_CF;
		}		
		/* setup new context */
		mincpy(&bdat->rmc, &ctx, sizeof(rm_ctx));
	} else 
	{
		/* interrupt is not processed, call original handler */
		bdat->rmc.efl = FL_IF; /* enable interrupts */
		bdat->segoff  = bdat->old_int13;
		bdat->call_rm();		
	}
	/* copy saved interrupt flag to exit context */
	bdat->rmc.efl = (bdat->rmc.efl & ~FL_IF) | (p_efl & FL_IF);
}
Пример #8
0
void dpps::Pattern_random::generate () {
    // We have do declare them all. We cannot do a switch of if,
    // because distributions would get out of scope.
    // The only other possibility would be to place the switch inside
    // the loop, but it would be very inefficient to call the constructor
    // everytime.
    // So we have to pay for overhead and initialize them all in te beginning.
    // It's probably a negligible amount of time and memory as compared to the
    // loop.

    // signification of parametres depends on the engine. Some engines
    // need only one parametre.
    // For all user-changeable values (p1 and p2), 1.0 would have been the
    // default if we had not specified it, so it is an acceptable value for the
    // user as well.
    const double p1 {pattern_settings. p1} ;
    const double p2 {pattern_settings. p2} ;

    std::uniform_real_distribution<double> d0 (-p1, p1) ; // min, max
    // Normal-type
    std::normal_distribution<double> d1 (0.0, p1) ;    // average = 0, sigma
    std::lognormal_distribution<double> d2 (0.0, p1) ; // average = 0, m
    std::chi_squared_distribution<double> d3 (p1) ;    // n
    std::cauchy_distribution<double> d4 (p1, p2) ;     // a, b
    std::fisher_f_distribution<double> d5 (p1, p2) ;   // m, n
    std::student_t_distribution<double> d6 (p1) ;      // n
    // Poisson-type
    std::exponential_distribution<double> d7 (p1) ;    // lambda
    std::gamma_distribution<double> d8 (p1, p2) ;      // alpha, beta
    std::weibull_distribution<double> d9 (p1, p2) ;    // a, b

    Polyline p ;
    p. closed = true ;
    double x {0.0}, y {0.0} ;
    long_unsigned_int i {0}, attempts {0} ;
    //const double s {pattern_settings. side / 2.0} ;
    if (pattern_settings. max_attempts < pattern_settings. number)
        pattern_settings. max_attempts =
            std::numeric_limits<long_unsigned_int>::max () ;
    //std::cout << "hello" << i << " " << pattern_settings. number << " " <<  attempts << " " << pattern_settings. max_attempts << std::endl ;
    while ((i < pattern_settings. number) &&
           (attempts < pattern_settings. max_attempts)) {
        bool overlap = false ;
        switch (pattern_settings. type) {
            case type_uniform_real_distribution: // 0
                x = d0 (pseudorandom_generator) ;
                y = d0 (pseudorandom_generator) ;
                //std::cout << "alea 0 : " << x << " " << y << std::endl ;
                break ;
            case type_normal_distribution: // 1
                x = d1 (pseudorandom_generator) ;
                y = d1 (pseudorandom_generator) ;
                break ;
            case type_lognormal_distribution: // 2
                x = d2 (pseudorandom_generator) ;
                y = d2 (pseudorandom_generator) ;
                break ;
            case type_chi_squared_distribution: // 3
                x = d3 (pseudorandom_generator) ;
                y = d3 (pseudorandom_generator) ;
                break ;
            case type_cauchy_distribution: // 4
                x = d4 (pseudorandom_generator) ;
                y = d4 (pseudorandom_generator) ;
                break ;
            case type_fisher_f_distribution: // 5
                x = d5 (pseudorandom_generator) ;
                y = d5 (pseudorandom_generator) ;
                break ;
            case type_student_t_distribution: // 6
                x = d6 (pseudorandom_generator) ;
                y = d6 (pseudorandom_generator) ;
                break ;
            case type_exponential_distribution: // 7
                x = d7 (pseudorandom_generator) ;
                y = d7 (pseudorandom_generator) ;
                break ;
            case type_gamma_distribution: // 8
                x = d8 (pseudorandom_generator) ;
                y = d8 (pseudorandom_generator) ;
                break ;
            case type_weibull_distribution: // 9
                x = d9 (pseudorandom_generator) ;
                y = d9 (pseudorandom_generator) ;
                break ;
            default:
                break ;
        }
        if (pattern_settings. avoid_overlap) {
            for (long_unsigned_int j = 0 ; j < polylines. size () ; j++) {
                if ((polylines[j]. vertices[0] - Vertex(x, y)).norm2_square() <
                    pattern_settings. diametre*pattern_settings. diametre) {
                    overlap = true ;
                    break ;
                 }
            }
        }

        bool within_limits =
            (((fabs (x - pattern_settings. x0) < pattern_settings. lx / 2.0) ||
             (pattern_settings. lx <= 0)) &&
            ((fabs (y - pattern_settings. y0) < pattern_settings. ly / 2.0) ||
             (pattern_settings. ly <= 0))) ;

        // Either we are inside lx, or user set it to negative to disable it.
        if  (within_limits && !overlap) {
            p. push_back (Vertex (x, y)) ;
            p. dose = pattern_settings. diametre ;
            polylines. push_back (p) ;
            p. vertices. clear () ; // does not change that p. closed == true ;
            i++ ;
        }
        attempts++ ;
    }
}
Пример #9
0
int dc_mount_device(wchar_t *dev_name, dc_pass *password, u32 mnt_flags)
{
	dc_header *hcopy = NULL;
	dev_hook  *hook  = NULL;
	xts_key   *hdr_key = NULL;
	int        resl;
	
	DbgMsg("dc_mount_device %ws\n", dev_name);

	do 
	{
		if ( (hook = dc_find_hook(dev_name)) == NULL ) {
			resl = ST_NF_DEVICE; break;
		}

		wait_object_infinity(&hook->busy_lock);

		if (hook->flags & F_ENABLED) {
			resl = ST_ALR_MOUNT; break;
		}
		if (hook->flags & (F_UNSUPRT | F_DISABLE | F_FORMATTING)) {
			resl = ST_ERROR; break;
		}

		if ( !NT_SUCCESS(dc_fill_device_info(hook)) ) {
			resl = ST_IO_ERROR; break;
		}

		if ( ( (hook->flags & F_CDROM) && (hook->bps != CD_SECTOR_SIZE) ) ||
			 (!(hook->flags & F_CDROM) && IS_INVALID_SECTOR_SIZE(hook->bps) ) )
		{
			hook->flags |= F_UNSUPRT; resl = ST_ERROR; break;
		}
		if ( (resl = dc_probe_decrypt(hook, &hcopy, &hdr_key, password)) != ST_OK ) {
			break;
		}

		/* check volume header */		
		if ( (IS_INVALID_VOL_FLAGS(hcopy->flags) != 0) ||
			 ( (hcopy->flags & VF_STORAGE_FILE) && (hcopy->stor_off == 0) ) ||
			 (hcopy->alg_1 >= CF_CIPHERS_NUM) ||
			 (hcopy->alg_2 >= CF_CIPHERS_NUM) || 
			 (hcopy->tmp_wp_mode >= WP_NUM) ||
			 ( (hook->flags & F_CDROM) && (hcopy->flags & (VF_TMP_MODE | VF_STORAGE_FILE)) ) )
		{
			resl = ST_INV_VOLUME; break;
		}
		if (hcopy->version > DC_HDR_VERSION) {
			resl = ST_VOLUME_TOO_NEW; break;
		}
#if 0
		/* update volume header if needed */
		if ( (hcopy->version < DC_HDR_VERSION) && !(hook->flags & F_CDROM) )
		{
			hcopy->version = DC_HDR_VERSION;
			memset(hcopy->deprecated, 0, sizeof(hcopy->deprecated));
			
			io_write_header(hook, hcopy, hdr_key, NULL);
		}
#endif

		DbgMsg("hdr_key=%p, dsk_key=%p\n", hdr_key, hook->dsk_key);

		// initialize volume key
		if ( (hook->dsk_key = (xts_key*)mm_secure_alloc(sizeof(xts_key))) == NULL ) {
			resl = ST_NOMEM;
			break;
		}
		xts_set_key(hcopy->key_1, hcopy->alg_1, hook->dsk_key);

		DbgMsg("device mounted\n");

		if (hcopy->flags & VF_STORAGE_FILE) {
			hook->use_size = hook->dsk_size;
			hook->stor_off = hcopy->stor_off;
		} else {
			hook->use_size = hook->dsk_size - hook->head_len;
			hook->stor_off = hook->use_size;
		}		
		hook->crypt.cipher_id = d8(hcopy->alg_1);
		hook->disk_id    = hcopy->disk_id;
		hook->vf_version = hcopy->version;		
		hook->tmp_size   = 0;
		hook->mnt_flags  = mnt_flags;

		DbgMsg("hook->vf_version %d\n", hook->vf_version);
		DbgMsg("hook->bps %d\n", hook->bps);
		DbgMsg("hook->head_len %d\n", hook->head_len);		
		DbgMsg("flags %x\n", hcopy->flags);

		if (hcopy->flags & VF_STORAGE_FILE) {
			hook->flags |= F_PROTECT_DCSYS;
		}
		if (hcopy->flags & VF_NO_REDIR) {
			hook->flags   |= F_NO_REDIRECT;
			hook->stor_off = 0;			
		}

		if (hcopy->flags & VF_TMP_MODE)
		{
			hook->tmp_size      = hcopy->tmp_size;
			hook->hdr_key       = hdr_key;
			hook->crypt.wp_mode = hcopy->tmp_wp_mode;			

			if (hcopy->flags & VF_REENCRYPT) {
				hook->sync_init_type = S_CONTINUE_RE_ENC;
			} else {
				hook->sync_init_type = S_CONTINUE_ENC;
			}
				
			/* copy decrypted header to device data */
			memcpy(&hook->tmp_header, hcopy, sizeof(dc_header));
				
			if ( (resl = dc_enable_sync_mode(hook)) != ST_OK ) 
			{
				burn(&hook->tmp_header, sizeof(dc_header));
				hdr_key = hook->hdr_key;
			} else  {				
				hdr_key = NULL; /* prevent key wiping */
			}
		} else {			
			hook->flags |= F_ENABLED;
			resl = ST_OK;
		}
		if (resl == ST_OK) {
			/* increment mount changes counter */
			lock_inc(&hook->chg_mount);
		}
	} while (0);

	if (hdr_key != NULL) mm_secure_free(hdr_key);
	if (hcopy != NULL)   mm_secure_free(hcopy);

	if (hook != NULL)
	{
		if ((hook->flags & F_ENABLED) == 0 && hook->dsk_key != NULL) {
			mm_secure_free(hook->dsk_key);
			hook->dsk_key = NULL;
		}

		KeReleaseMutex(&hook->busy_lock, FALSE);
		dc_deref_hook(hook);
	}
	return resl;
}
Пример #10
0
int main (int, char**)
{
  UnitTest t (110);

  // Ensure environment has no influence.
  unsetenv ("TASKDATA");
  unsetenv ("TASKRC");

  // Path ();
  Path p0;
  t.is (p0._data, "", "Path::Path");

  // Path (const Path&);
  Path p1 = Path ("foo");
  t.is (p1._data, Directory::cwd () + "/foo", "Path::operator=");

  // Path (const std::string&);
  Path p2 ("~");
  t.ok (p2._data != "~", "~ expanded to " + p2._data);

  Path p3 ("/tmp");
  t.ok (p3._data == "/tmp", "/tmp -> /tmp");

  // operator==
  t.notok (p2 == p3, "p2 != p3");

  // Path& operator= (const Path&);
  Path p3_copy (p3);
  t.is (p3._data, p3_copy._data, "Path::Path (Path&)");

  // operator (std::string) const;
  t.is ((std::string) p3, "/tmp", "Path::operator (std::string) const");

  // std::string name () const;
  Path p4 ("/a/b/c/file.ext");
  t.is (p4.name (), "file.ext",  "/a/b/c/file.ext name is file.ext");

  // std::string parent () const;
  t.is (p4.parent (), "/a/b/c",  "/a/b/c/file.ext parent is /a/b/c");

  // std::string extension () const;
  t.is (p4.extension (), "ext",  "/a/b/c/file.ext extension is ext");

  // bool exists () const;
  t.ok (p2.exists (), "~ exists");
  t.ok (p3.exists (), "/tmp exists");

  // bool is_directory () const;
  t.ok (p2.is_directory (), "~ is_directory");
  t.ok (p3.is_directory (), "/tmp is_directory");

  // bool is_link () const;
  t.notok (p2.is_link (), "~ !is_link");

  // bool readable () const;
  t.ok (p2.readable (), "~ readable");
  t.ok (p3.readable (), "/tmp readable");

  // bool writable () const;
  t.ok (p2.writable (), "~ writable");
  t.ok (p3.writable (), "/tmp writable");

  // bool executable () const;
  t.ok (p2.executable (), "~ executable");
  t.ok (p3.executable (), "/tmp executable");

  // static std::string expand (const std::string&);
  t.ok (Path::expand ("~") != "~", "Path::expand ~ != ~");
  t.ok (Path::expand ("~/") != "~/", "Path::expand ~/ != ~/");

  // static std::vector <std::string> glob (const std::string&);
  std::vector <std::string> out = Path::glob ("/tmp");
  t.ok (out.size () == 1, "/tmp -> 1 result");
  t.is (out[0], "/tmp", "/tmp -> /tmp");

  out = Path::glob ("/t?p");
  t.ok (out.size () == 1, "/t?p -> 1 result");
  t.is (out[0], "/tmp", "/t?p -> /tmp");

  out = Path::glob ("/[s-u]mp");
  t.ok (out.size () == 1, "/[s-u]mp -> 1 result");
  t.is (out[0], "/tmp", "/[s-u]mp -> /tmp");

  // bool is_absolute () const;
  t.notok (p0.is_absolute (), "'' !is_absolute");
  t.ok    (p1.is_absolute (), "foo is_absolute");
  t.ok    (p2.is_absolute (), "~ is_absolute (after expansion)");
  t.ok    (p3.is_absolute (), "/tmp is_absolute");
  t.ok    (p4.is_absolute (), "/a/b/c/file.ext is_absolute");

  Directory tmp ("tmp");
  tmp.create ();
  t.ok (tmp.exists (), "tmp dir created.");

  File::write ("tmp/file.t.txt", "This is a test\n");
  File f6 ("tmp/file.t.txt");
  t.ok (f6.size () == 15, "File::size tmp/file.t.txt good");
  t.ok (f6.mode () & S_IRUSR, "File::mode tmp/file.t.txt good");
  t.ok (File::remove ("tmp/file.t.txt"), "File::remove tmp/file.t.txt good");

  // operator (std::string) const;
  t.is ((std::string) f6, Directory::cwd () + "/tmp/file.t.txt", "File::operator (std::string) const");

  t.ok (File::create ("tmp/file.t.create"), "File::create tmp/file.t.create good");
  t.ok (File::remove ("tmp/file.t.create"), "File::remove tmp/file.t.create good");

  // basename (std::string) const;
  t.is (f6.name (), "file.t.txt", "File::basename tmp/file.t.txt --> file.t.txt");

  // dirname (std::string) const;
  t.is (f6.parent (), Directory::cwd () + "/tmp", "File::dirname tmp/file.t.txt --> tmp");

  // bool rename (const std::string&);
  File f7 ("tmp/file.t.2.txt");
  f7.append ("something\n");
  f7.close ();

  t.ok (f7.rename ("tmp/file.t.3.txt"),  "File::rename did not fail");
  t.is (f7._data, Directory::cwd () + "/tmp/file.t.3.txt",    "File::rename stored new name");
  t.ok (f7.exists (),                    "File::rename new file exists");
  t.ok (f7.remove (),                    "File::remove tmp/file.t.3.txt good");
  t.notok (f7.exists (),                 "File::remove new file no longer exists");

  // Test permissions.
  File f8 ("tmp/file.t.perm.txt");
  f8.create (0744);
  t.ok (f8.exists (),                    "File::create perm file exists");
  mode_t m = f8.mode ();
  t.ok    (m & S_IFREG,                  "File::mode tmp/file.t.perm.txt S_IFREG good");
  t.ok    (m & S_IRUSR,                  "File::mode tmp/file.t.perm.txt r-------- good");
  t.ok    (m & S_IWUSR,                  "File::mode tmp/file.t.perm.txt -w------- good");
  t.ok    (m & S_IXUSR,                  "File::mode tmp/file.t.perm.txt --x------ good");
  t.ok    (m & S_IRGRP,                  "File::mode tmp/file.t.perm.txt ---r----- good");
  t.notok (m & S_IWGRP,                  "File::mode tmp/file.t.perm.txt ----w---- good");
  t.notok (m & S_IXGRP,                  "File::mode tmp/file.t.perm.txt -----x--- good");
  t.ok    (m & S_IROTH,                  "File::mode tmp/file.t.perm.txt ------r-- good");
  t.notok (m & S_IWOTH,                  "File::mode tmp/file.t.perm.txt -------w- good");
  t.notok (m & S_IXOTH,                  "File::mode tmp/file.t.perm.txt --------x good");
  f8.remove ();
  t.notok (f8.exists (),                 "File::remove perm file no longer exists");

  tmp.remove ();
  t.notok (tmp.exists (),                "tmp dir removed.");
  tmp.create ();
  t.ok (tmp.exists (), "tmp dir created.");

  // Directory (const File&);
  // Directory (const Path&);
  Directory d0 (Path ("tmp"));
  Directory d1 (File ("tmp"));
  Directory d2 (File (Path ("tmp")));
  t.is (d0._data, d1._data, "Directory(std::string) == Directory (File&)");
  t.is (d0._data, d2._data, "Directory(std::string) == Directory (File (Path &))");
  t.is (d1._data, d2._data, "Directory(File&)) == Directory (File (Path &))");

  // Directory (const Directory&);
  Directory d3 (d2);
  t.is (d3._data, Directory::cwd () + "/tmp", "Directory (Directory&)");

  // Directory (const std::string&);
  Directory d4 ("tmp/test_directory");

  // Directory& operator= (const Directory&);
  Directory d5 = d4;
  t.is (d5._data, Directory::cwd () + "/tmp/test_directory", "Directory::operator=");

  // operator (std::string) const;
  t.is ((std::string) d3, Directory::cwd () + "/tmp", "Directory::operator (std::string) const");

  // virtual bool create ();
  t.ok (d5.create (), "Directory::create tmp/test_directory");
  t.ok (d5.exists (), "Directory::exists tmp/test_directory");

  Directory d6 (d5._data + "/dir");
  t.ok (d6.create (), "Directory::create tmp/test_directory/dir");

  File::create (d5._data + "/f0");
  File::create (d6._data + "/f1");

  // std::vector <std::string> list ();
  std::vector <std::string> files = d5.list ();
  std::sort (files.begin (), files.end ());
  t.is ((int)files.size (), 2, "Directory::list 1 file");
  t.is (files[0], Directory::cwd () + "/tmp/test_directory/dir", "file[0] is tmp/test_directory/dir");
  t.is (files[1], Directory::cwd () + "/tmp/test_directory/f0", "file[1] is tmp/test_directory/f0");

  // std::vector <std::string> listRecursive ();
  files = d5.listRecursive ();
  std::sort (files.begin (), files.end ());
  t.is ((int)files.size (), 2, "Directory::list 1 file");
  t.is (files[0], Directory::cwd () + "/tmp/test_directory/dir/f1", "file is tmp/test_directory/dir/f1");
  t.is (files[1], Directory::cwd () + "/tmp/test_directory/f0", "file is tmp/test_directory/f0");

  // virtual bool remove ();
  t.ok (File::remove (d5._data + "/f0"), "File::remove tmp/test_directory/f0");
  t.ok (File::remove (d6._data + "/f1"), "File::remove tmp/test_directory/dir/f1");

  t.ok (d6.remove (), "Directory::remove tmp/test_directory/dir");
  t.notok (d6.exists (), "Directory::exists tmp/test_directory/dir - no");

  t.ok (d5.remove (), "Directory::remove tmp/test_directory");
  t.notok (d5.exists (), "Directory::exists tmp/test_directory - no");

  // bool remove (const std::string&);
  Directory d7 ("tmp/to_be_removed");
  t.ok (d7.create (), "Directory::create tmp/to_be_removed");
  File::create (d7._data + "/f0");
  Directory d8 (d7._data + "/another");
  t.ok (d8.create (), "Directory::create tmp/to_be_removed/another");
  File::create (d8._data + "/f1");
  t.ok (d7.remove (), "Directory::remove tmp/to_be_removed");
  t.notok (d7.exists (), "Directory tmp/to_be_removed gone");

  // static std::string cwd ();
  std::string cwd = Directory::cwd ();
  t.ok (cwd.length () > 0, "Directory::cwd returned a value");

  // bool parent (std::string&) const;
  Directory d9 ("/one/two/three/four.txt");
  t.ok (d9.up (),                   "parent /one/two/three/four.txt --> true");
  t.is (d9._data, "/one/two/three", "parent /one/two/three/four.txt --> /one/two/three");
  t.ok (d9.up (),                   "parent /one/two/three --> true");
  t.is (d9._data, "/one/two",       "parent /one/two/three --> /one/two");
  t.ok (d9.up (),                   "parent /one/two --> true");
  t.is (d9._data, "/one",           "parent /one/two --> /one");
  t.ok (d9.up (),                   "parent /one --> true");
  t.is (d9._data, "/",              "parent /one --> /");
  t.notok (d9.up (),                "parent / --> false");

  // Test permissions.
  umask (0022);
  Directory d10 ("tmp/dir.perm");
  d10.create (0750);
  t.ok (d10.exists (),               "Directory::create perm file exists");
  m = d10.mode ();
  t.ok    (m & S_IFDIR,             "Directory::mode tmp/dir.perm S_IFDIR good");
  t.ok    (m & S_IRUSR,             "Directory::mode tmp/dir.perm r-------- good");
  t.ok    (m & S_IWUSR,             "Directory::mode tmp/dir.perm -w------- good");
  t.ok    (m & S_IXUSR,             "Directory::mode tmp/dir.perm --x------ good");
  t.ok    (m & S_IRGRP,             "Directory::mode tmp/dir.perm ---r----- good");
  t.notok (m & S_IWGRP,             "Directory::mode tmp/dir.perm ----w---- good");
  t.ok    (m & S_IXGRP,             "Directory::mode tmp/dir.perm -----x--- good");
  t.notok (m & S_IROTH,             "Directory::mode tmp/dir.perm ------r-- good");
  t.notok (m & S_IWOTH,             "Directory::mode tmp/dir.perm -------w- good");
  t.notok (m & S_IXOTH,             "Directory::mode tmp/dir.perm --------x good");
  d10.remove ();
  t.notok (d10.exists (),           "Directory::remove temp/dir.perm file no longer exists");

  tmp.remove ();
  t.notok (tmp.exists (),           "tmp dir removed.");

  return 0;
}
int main()
{
    tQ4 a4( 1.1 );
    tQ4 b4( 1 );
    tQ12 a12( 3.3 );
    tQ12 b12( 3 );
    tQ18 a18;
    double ad;
    double bd;
    
    tQ8 a8( -2.3 );
    tQ8 b8( 2 );
    tQ8 c8( Q8CONST( -2,3 ) );
    tQ8 d8( a8 );
    tQ8 e8( a4 );
//  tQ8 f8( a12 );      // Warning: left shift count is negative
    tQ8 g8( a12.roundedTo< tQ8 >() );
    tQ8 h8( a12.roundedTo< 8 >() );
    
//  a8 = a4.roundedTo( h8 );  //Warning: left/right shift is negative
    
    a8 = 1;
    a8 = -2;
    a8 = 3;
    a8 = Q8CONST( 3,001 );
    a8 = tQ8( 3.001 );
    a8 = tQ8::truncated( 3.001 );
    a8 = tQ8::rounded( 3.001 );
    a8.setTruncated( 3.2 );
    a8.setRounded( 3.3 );
    a8 = tQ8( 123, 8 );
    a8 = tQ8::create( 123 << 8 );
    
    a8 = a4;
    a8 = a8;
//  a8 = a12;          // Warning: left shift count is negative
    a8 = a12.roundedTo< tQ8 >();
    a8 = a12.roundedTo( a8 );
    a8.setRounded( a12 );
    a8 = -a4;
    a8 = -a8;

    a8 += 3;
    a8 += 4u;
    a8 += 5l;
    a8 += 6lu;
    a8 += tQ8( 3.2 );
    a8 += truncatedTo( a8, 3.3 );
    a8 += roundedTo( a8, 3.4 );
    a8 += a4;
//  a8 += a12;          // Warning: left shift count is negative
    a8 += a12.roundedTo< tQ8 >();
    a8 += a12.roundedTo( a8 );
    a8 = a8 + 2;
    a8 = 3 + a8;
    a8 = a8 + a4;
//  a8 = a4 + a8;       // Warning: left shift count is negative
    
    a8 -= 3;
    a8 -= 4u;
    a8 -= 5l;
    a8 -= 6lu;
    a8 -= roundedTo< tQ8::cQBits >( 3.2 );
    a8 -= roundedTo( a8, 3.3 );
    a8 -= a4;
//  a8 -= a12;          // Warning: left shift count is negative
    a8 -= a12.roundedTo< tQ8 >();
    a8 -= a12.roundedTo( a8 );
    a8 = a8 - 2;
    a8 = 3 - a8;
    a8 = a8 - a4;
//  a8 = a4 - a8;       // Warning: left shift count is negative
    
    a8 *= 3;
    a8 *= 4u;
    a8 *= 5l;
    a8 *= 6lu;
//  a8 *= 3.2;          // Warning: converting to int from double
    a8 *= a4;
    a8 *= a12;
    a8 = a8 * 2;
    a8 = 3 * a8;
    a12 = a8 * a4;
    a12 = a4 * a8;
    
    a8 /= 3;
    a8 /= 4u;
    a8 /= 5l;
    a8 /= 6lu;
//  a8 /= 3.2;          // Warning: converting to int from double
    a8 /= a4;           // Note: possible overflow due to pre-shifting "(a8 << 4) / a4"
//  a8 /= a12;          // Warning: left shift count is negative
    a8 = a8.increasedBy( a12 ) / a12;
    a8 = a8 / 2;
//  a8 = 3 / a8;        // Error: no match for 'operator/'
    a8 = tQ16( 3 ) / a8;
    a12 = a8 / a4;
    a12 = a4 / a8;
    
    a8 == 3;
    a8 == 4u;
    a8 == 5l;
    a8 == 6lu;
    a8 == tQ8( 3.2 );
    a8 == truncatedTo( a8, 3.3 );
    a8 == roundedTo( a8, 3.4 );
    a8 == a4;
//  a8 == a12;          // Warning: left shift count is negative
    a8 == a12.roundedTo< tQ8 >();
    a8 == a12.roundedTo( a8 );
    3 == a8;
    int(4u) == a8;
    int(5l) == a8;
    int(6lu) == a8;
    
    a8 < 3;
    a8 < 4u;
    a8 < 5l;
    a8 < 6lu;
    a8 < tQ8( 3.2 );
    a8 < a4;
//  a8 < a12;          // Warning: left shift count is negative
    3 < a8;
    int(4u) < a8;
    int(5l) < a8;
    int(6lu) < a8;
    
    a8 > 3;
    a8 > 4u;
    a8 > 5l;
    a8 > 6lu;
    a8 > tQ8( 3.2 );
    a8 > a4;
//  a8 > a12;          // Warning: left shift count is negative
    3 > a8;
    int(4u) > a8;
    int(5l) > a8;
    int(6lu) > a8;
    
    !a8;
    int intPart = a8.intPart();
    int fracPart = a8.fracPart();
    int fracPlaces = a8.fracPlaces( 3 );
    unsigned abs = a8.absolute();

    ad = a8.toDouble();
    a8 = ad;
//  a8.set( ad );    // Warning: conversion from int to double, possible loss of data
    a8.setRounded( ad );
    a8 = truncatedTo( a8, ad );
    a8 = truncatedTo<8>( ad );
    a8 = truncatedTo<tQ8>( ad );
    
//  tBigQ36 aB36( 123567890 );     // Error: ambiguous
    tBigQ36 aB36( 123567890ll );
    tBigQ36 bB36( a8 );
    
    aB36 = tBigQ18( a18 ) * a18;
}
Пример #12
0
int main (int argc, char** argv)
{
  UnitTest t (49);

  // Ensure environment has no influence.
  unsetenv ("TASKDATA");
  unsetenv ("TASKRC");

  Directory tmp ("tmp");
  tmp.create ();
  t.ok (tmp.exists (), "tmp dir created.");

  // Directory (const File&);
  // Directory (const Path&);
  Directory d0 (Path ("tmp"));
  Directory d1 (File ("tmp"));
  Directory d2 (File (Path ("tmp")));
  t.is (d0._data, d1._data, "Directory(std::string) == Directory (File&)");
  t.is (d0._data, d2._data, "Directory(std::string) == Directory (File (Path &))");
  t.is (d1._data, d2._data, "Directory(File&)) == Directory (File (Path &))");

  // Directory (const Directory&);
  Directory d3 (d2);
  t.is (d3._data, Directory::cwd () + "/tmp", "Directory (Directory&)");

  // Directory (const std::string&);
  Directory d4 ("tmp/test_directory");

  // Directory& operator= (const Directory&);
  Directory d5 = d4;
  t.is (d5._data, Directory::cwd () + "/tmp/test_directory", "Directory::operator=");

  // operator (std::string) const;
  t.is ((std::string) d3, Directory::cwd () + "/tmp", "Directory::operator (std::string) const");

  // virtual bool create ();
  t.ok (d5.create (), "Directory::create tmp/test_directory");
  t.ok (d5.exists (), "Directory::exists tmp/test_directory");

  Directory d6 (d5._data + "/dir");
  t.ok (d6.create (), "Directory::create tmp/test_directory/dir");

  File::create (d5._data + "/f0");
  File::create (d6._data + "/f1");

  // std::vector <std::string> list ();
  std::vector <std::string> files = d5.list ();
  std::sort (files.begin (), files.end ());
  t.is ((int)files.size (), 2, "Directory::list 1 file");
  t.is (files[0], Directory::cwd () + "/tmp/test_directory/dir", "file[0] is tmp/test_directory/dir");
  t.is (files[1], Directory::cwd () + "/tmp/test_directory/f0", "file[1] is tmp/test_directory/f0");

  // std::vector <std::string> listRecursive ();
  files = d5.listRecursive ();
  std::sort (files.begin (), files.end ());
  t.is ((int)files.size (), 2, "Directory::list 1 file");
  t.is (files[0], Directory::cwd () + "/tmp/test_directory/dir/f1", "file is tmp/test_directory/dir/f1");
  t.is (files[1], Directory::cwd () + "/tmp/test_directory/f0", "file is tmp/test_directory/f0");

  // virtual bool remove ();
  t.ok (File::remove (d5._data + "/f0"), "File::remove tmp/test_directory/f0");
  t.ok (File::remove (d6._data + "/f1"), "File::remove tmp/test_directory/dir/f1");

  t.ok (d6.remove (), "Directory::remove tmp/test_directory/dir");
  t.notok (d6.exists (), "Directory::exists tmp/test_directory/dir - no");

  t.ok (d5.remove (), "Directory::remove tmp/test_directory");
  t.notok (d5.exists (), "Directory::exists tmp/test_directory - no");

  // bool remove (const std::string&);
  Directory d7 ("tmp/to_be_removed");
  t.ok (d7.create (), "Directory::create tmp/to_be_removed");
  File::create (d7._data + "/f0");
  Directory d8 (d7._data + "/another");
  t.ok (d8.create (), "Directory::create tmp/to_be_removed/another");
  File::create (d8._data + "/f1");
  t.ok (d7.remove (), "Directory::remove tmp/to_be_removed");
  t.notok (d7.exists (), "Directory tmp/to_be_removed gone");

  // static std::string cwd ();
  std::string cwd = Directory::cwd ();
  t.ok (cwd.length () > 0, "Directory::cwd returned a value");

  // bool parent (std::string&) const;
  Directory d9 ("/one/two/three/four.txt");
  t.ok (d9.up (),                   "parent /one/two/three/four.txt --> true");
  t.is (d9._data, "/one/two/three", "parent /one/two/three/four.txt --> /one/two/three");
  t.ok (d9.up (),                   "parent /one/two/three --> true");
  t.is (d9._data, "/one/two",       "parent /one/two/three --> /one/two");
  t.ok (d9.up (),                   "parent /one/two --> true");
  t.is (d9._data, "/one",           "parent /one/two --> /one");
  t.ok (d9.up (),                   "parent /one --> true");
  t.is (d9._data, "/",              "parent /one --> /");
  t.notok (d9.up (),                "parent / --> false");

  // Test permissions.
  umask (0022);
  Directory d10 ("tmp/dir.perm");
  d10.create (0750);
  t.ok (d10.exists (),               "Directory::create perm file exists");
  mode_t m = d10.mode ();
  t.ok    (m & S_IFDIR,             "Directory::mode tmp/dir.perm S_IFDIR good");
  t.ok    (m & S_IRUSR,             "Directory::mode tmp/dir.perm r-------- good");
  t.ok    (m & S_IWUSR,             "Directory::mode tmp/dir.perm -w------- good");
  t.ok    (m & S_IXUSR,             "Directory::mode tmp/dir.perm --x------ good");
  t.ok    (m & S_IRGRP,             "Directory::mode tmp/dir.perm ---r----- good");
  t.notok (m & S_IWGRP,             "Directory::mode tmp/dir.perm ----w---- good");
  t.ok    (m & S_IXGRP,             "Directory::mode tmp/dir.perm -----x--- good");
  t.notok (m & S_IROTH,             "Directory::mode tmp/dir.perm ------r-- good");
  t.notok (m & S_IWOTH,             "Directory::mode tmp/dir.perm -------w- good");
  t.notok (m & S_IXOTH,             "Directory::mode tmp/dir.perm --------x good");
  d10.remove ();
  t.notok (d10.exists (),           "Directory::remove temp/dir.perm file no longer exists");

  tmp.remove ();
  t.notok (tmp.exists (),           "tmp dir removed.");

  return 0;
}
Пример #13
0
// Function for simulating attack, includes Focus, Target Lock and Howlrunner
int SimulateAttackDice(int numAttackDice, bool AttackFocus,
	bool HowlRunner, bool CrackShot, bool TargetLock)
{
	int AttackHitCounter = 0;
	int AttackFocusCounter = 0;
	int CritCounter = 0;

	std::uniform_int_distribution<int> d8(1, 8);

	for (int i = 0; i < numAttackDice; i++)
	{
		int Dice = d8(mt);
		if (1 <= Dice && Dice <= 3)
		{
			++AttackHitCounter;
		}
		else if (4 <= Dice && Dice <= 5 && AttackFocus)
		{
			++AttackFocusCounter;
		}
		else if (6 == Dice)
		{
			++CritCounter;
		}
	}

	auto HowlRunnerHitCheck = AttackHitCounter + AttackFocusCounter + CritCounter;

	if (HowlRunner && HowlRunnerHitCheck < numAttackDice)
	{
		int HowlRunnerResult = d8(mt);
		if (1 <= HowlRunnerResult && HowlRunnerResult <= 3)
		{
			++AttackHitCounter;

		}
		else if (4 <= HowlRunnerResult && HowlRunnerResult <= 5 && AttackFocus)
		{
			++AttackFocusCounter;
		}
		else if (6 == HowlRunnerResult)
		{
			++CritCounter;
		}
	}

	auto TargetLockHitCheck = AttackHitCounter + AttackFocusCounter + CritCounter;

	if (TargetLock && TargetLockHitCheck < numAttackDice)
	{
		for (int i = 0; i < numAttackDice - TargetLockHitCheck; i++)
		{
			int TargetLockResult = d8(mt);
			if (1 <= TargetLockResult && TargetLockResult <= 3)
			{
				++AttackHitCounter;

			}
			else if (4 <= TargetLockResult && TargetLockResult <= 5 && AttackFocus)
			{
				++AttackFocusCounter;
			}
			else if (6 == TargetLockResult)
			{
				++CritCounter;
			}
		}
	}

	int totalDamage = AttackHitCounter + CritCounter + AttackFocusCounter;
	return totalDamage;
}
Пример #14
0
int dc_format_step(wchar_t *dev_name, int wp_mode)
{
	dev_hook *hook = NULL;
	u8       *buff;
	int       resl;
	u64       offs;
	u32       size;

	do
	{
		if ( (hook = dc_find_hook(dev_name)) == NULL ) {
			resl = ST_NF_DEVICE; break;
		}

		wait_object_infinity(&hook->busy_lock);

		if ( !(hook->flags & F_FORMATTING) ) {
			resl = ST_ERROR; break;
		}

		offs = hook->tmp_size;
		buff = hook->tmp_buff;
		size = d32(min(hook->dsk_size - offs, ENC_BLOCK_SIZE));

		if (size == 0) {
			dc_format_done(dev_name);
			resl = ST_FINISHED; break;
		}

		if (hook->crypt.wp_mode != wp_mode)
		{
			dc_wipe_free(&hook->wp_ctx);

			resl = dc_wipe_init(
				&hook->wp_ctx, hook, ENC_BLOCK_SIZE, wp_mode, hook->crypt.cipher_id);

			if (resl == ST_OK) {
				hook->crypt.wp_mode = d8(wp_mode);
			} else {
				dc_wipe_init(&hook->wp_ctx, hook, ENC_BLOCK_SIZE, WP_NONE, 0);
				hook->crypt.wp_mode = WP_NONE;
			}
		}

		/* wipe sectors */
		dc_wipe_process(&hook->wp_ctx, offs, size);

		/* zero buffer */
		memset(buff, 0, size);
		/* encrypt buffer with temporary key */
		cp_fast_encrypt(buff, buff, size, offs, hook->tmp_key);

		/* write pseudo-random data to device */
		resl = io_hook_rw(hook, buff, size, offs, 0);

		if ( (resl == ST_OK) || (resl == ST_RW_ERR) ) {
			hook->tmp_size += size;
		}
		if ( (resl == ST_MEDIA_CHANGED) || (resl == ST_NO_MEDIA) ) {			
			dc_process_unmount(hook, MF_NOFSCTL); resl = ST_FINISHED;
		}
	} while (0);

	if (hook != NULL) {
		KeReleaseMutex(&hook->busy_lock, FALSE);
		dc_deref_hook(hook);
	}
	return resl;
}
Пример #15
0
//--------------------------------------------------------------------------
int ana(void)
{
  int code = ua_next_byte();
  int saved_code = code;
  char dtyp = dt_byte;
  if ( code < 0x60 )
  {
    cmd.itype = A2[code];
  }
  else
  {
    if ( code & 8 )
    {
      cmd.auxpref |= aux_word;
      dtyp = dt_word;
    }
    else
    {
      cmd.auxpref |= aux_byte;
      dtyp = dt_byte;
    }
    cmd.itype = A2tail[(code>>4)-6];
  }
  if ( cmd.itype == H8500_null ) return 0;
  switch ( code )
  {
    case 0x02:  // ldm.w @sp+, <reglist>
//      cmd.auxpref |= aux_word;
      phrase(cmd.Op1, SP, ph_post, dt_word);
      cmd.Op2.type = o_reglist;
      cmd.Op2.reg  = ua_next_byte();
      if ( !cmd.Op2.reg ) return 0;
      break;
    case 0x12:  // stm.w <reglist>, @-sp
//      cmd.auxpref |= aux_word;
      cmd.Op1.type = o_reglist;
      cmd.Op1.reg  = ua_next_byte();
      if ( !cmd.Op1.reg ) return 0;
      phrase(cmd.Op2, SP, ph_pre, dt_word);
      break;
    case 0x01:  // scb/f
      cmd.auxpref |= aux_f;
      break;
    case 0x06:  // scb/ne
      cmd.auxpref |= aux_ne;
      break;
    case 0x07:  // scb/eq
      cmd.auxpref |= aux_eq;
      break;
    case 0x08:  // trapa #xx
      code = ua_next_byte();
      if ( (code & 0xF0) != 0x10 ) return 0;
      cmd.Op1.type = o_imm;
      cmd.Op1.dtyp = dt_byte;
      cmd.Op1.value = code & 15;
      break;
    case 0x0F:  // unlk
      reg(cmd.Op1, FP, dt_word);
      break;
    case 0x10:  // jmp @aa:16
    case 0x18:  // jsr @aa:16
      aa16(cmd.Op1, dt_code);
      cmd.Op1.type = o_near;
      cmd.Op1.addr += cmd.ea & ~0xFFFF;
      break;
    case 0x17:  // link #xx:8
      reg(cmd.Op1, FP, dt_word);
      imm8(cmd.Op2);
      break;
    case 0x1F:  // link #xx:16
      reg(cmd.Op1, FP, dt_word);
      imm16(cmd.Op2);
      break;
    case 0x03:  // pjsr @aa:24
    case 0x13:  // pjmp @aa:24
      {
        cmd.auxpref |= aux_disp24;
        uint32 page   = ua_next_byte();
        cmd.Op1.type = o_far;
        cmd.Op1.dtyp = dt_code;
        cmd.Op1.addr = (page<<16) | ua_next_word();
      }
      break;
    case 0x04:  // #xx:8
      cmd.auxpref |= aux_byte;
    case 0x14:  // #xx:8
      imm8(cmd.Op1);
      break;
    case 0x05:  // #aa:8.B
      cmd.auxpref |= aux_byte;
      aa8(cmd.Op1, dt_byte);
      break;
    case 0x15:  // #aa:16.B
      cmd.auxpref |= aux_byte;
      aa16(cmd.Op1, dt_byte);
      break;
    case 0x0C:  // #xx:16
      cmd.auxpref |= aux_word;
    case 0x1C:  // #xx:16
      imm16(cmd.Op1);
      break;
    case 0x0D:  // #aa:8.W
      cmd.auxpref |= aux_word;
      aa8(cmd.Op1, dt_word);
      dtyp = dt_word;
      break;
    case 0x1D:  // #aa:16.W
      cmd.auxpref |= aux_word;
      aa16(cmd.Op1, dt_word);
      dtyp = dt_word;
      break;
    case 0x0E:                                  // bsr d:8
    case 0x20: case 0x21: case 0x22: case 0x23: // d:8
    case 0x24: case 0x25: case 0x26: case 0x27:
    case 0x28: case 0x29: case 0x2A: case 0x2B:
    case 0x2C: case 0x2D: case 0x2E: case 0x2F:
      d8(cmd.Op1);
      break;
    case 0x1E:                                  // bsr d:16
    case 0x30: case 0x31: case 0x32: case 0x33: // d:16
    case 0x34: case 0x35: case 0x36: case 0x37:
    case 0x38: case 0x39: case 0x3A: case 0x3B:
    case 0x3C: case 0x3D: case 0x3E: case 0x3F:
      {
        cmd.auxpref |= aux_disp16;
        int32 disp = short(ua_next_word());
        cmd.Op1.type = o_near;
        cmd.Op1.dtyp = dt_code;
        cmd.Op1.addr = cmd.ip + cmd.size + disp;
      }
      break;
    case 0x40: case 0x41: case 0x42: case 0x43: // cmp:e #xx:8, Rn
    case 0x44: case 0x45: case 0x46: case 0x47:
    case 0x50: case 0x51: case 0x52: case 0x53: // mov:e #xx:8, Rn
    case 0x54: case 0x55: case 0x56: case 0x57:
      cmd.auxpref |= aux_byte;
      imm8(cmd.Op1);
      reg(cmd.Op2, code, dtyp);
      break;
    case 0x48: case 0x49: case 0x4A: case 0x4B: // cmp:i #xx:16, Rn
    case 0x4C: case 0x4D: case 0x4E: case 0x4F:
    case 0x58: case 0x59: case 0x5A: case 0x5B: // mov:i #xx:16, Rn
    case 0x5C: case 0x5D: case 0x5E: case 0x5F:
      cmd.auxpref |= aux_word;
      imm16(cmd.Op1);
      reg(cmd.Op2, code, dtyp);
      break;
    case 0x60: case 0x61: case 0x62: case 0x63: // @aa:8, Rn
    case 0x64: case 0x65: case 0x66: case 0x67:
    case 0x68: case 0x69: case 0x6A: case 0x6B:
    case 0x6C: case 0x6D: case 0x6E: case 0x6F:
      aa8(cmd.Op1, dtyp);
      reg(cmd.Op2, code, dtyp);
      break;
    case 0x70: case 0x71: case 0x72: case 0x73: // Rn, @aa:8
    case 0x74: case 0x75: case 0x76: case 0x77:
    case 0x78: case 0x79: case 0x7A: case 0x7B:
    case 0x7C: case 0x7D: case 0x7E: case 0x7F:
      reg(cmd.Op1, code, dtyp);
      aa8(cmd.Op2, dtyp);
      break;
    case 0x80: case 0x81: case 0x82: case 0x83: // mov:f @(d:8, R6), Rn
    case 0x84: case 0x85: case 0x86: case 0x87:
    case 0x88: case 0x89: case 0x8A: case 0x8B:
    case 0x8C: case 0x8D: case 0x8E: case 0x8F:
      ds8(cmd.Op1, R6, dtyp);
      reg(cmd.Op2, code, dtyp);
      break;
    case 0x90: case 0x91: case 0x92: case 0x93: // mov:f Rn, @(d:8, R6)
    case 0x94: case 0x95: case 0x96: case 0x97:
    case 0x98: case 0x99: case 0x9A: case 0x9B:
    case 0x9C: case 0x9D: case 0x9E: case 0x9F:
      reg(cmd.Op1, code, dtyp);
      ds8(cmd.Op2, R6, dtyp);
      break;
    case 0xA0: case 0xA1: case 0xA2: case 0xA3: // Rn, Rn
    case 0xA4: case 0xA5: case 0xA6: case 0xA7:
    case 0xA8: case 0xA9: case 0xAA: case 0xAB:
    case 0xAC: case 0xAD: case 0xAE: case 0xAF:
      reg(cmd.Op1, code, dtyp);
      break;
    case 0xB0: case 0xB1: case 0xB2: case 0xB3: // @-Rn, Rn
    case 0xB4: case 0xB5: case 0xB6: case 0xB7:
    case 0xB8: case 0xB9: case 0xBA: case 0xBB:
    case 0xBC: case 0xBD: case 0xBE: case 0xBF:
      phrase(cmd.Op1, code, ph_pre, dtyp);
      break;
    case 0xC0: case 0xC1: case 0xC2: case 0xC3: // @Rn+, Rn
    case 0xC4: case 0xC5: case 0xC6: case 0xC7:
    case 0xC8: case 0xC9: case 0xCA: case 0xCB:
    case 0xCC: case 0xCD: case 0xCE: case 0xCF:
      phrase(cmd.Op1, code, ph_post, dtyp);
      break;
    case 0xD0: case 0xD1: case 0xD2: case 0xD3: // @Rn, Rn
    case 0xD4: case 0xD5: case 0xD6: case 0xD7:
    case 0xD8: case 0xD9: case 0xDA: case 0xDB:
    case 0xDC: case 0xDD: case 0xDE: case 0xDF:
      phrase(cmd.Op1, code, ph_normal, dtyp);
      break;
    case 0xE0: case 0xE1: case 0xE2: case 0xE3: // @(d:8,Rn), Rn
    case 0xE4: case 0xE5: case 0xE6: case 0xE7:
    case 0xE8: case 0xE9: case 0xEA: case 0xEB:
    case 0xEC: case 0xED: case 0xEE: case 0xEF:
      ds8(cmd.Op1, code, dtyp);
      break;
    case 0xF0: case 0xF1: case 0xF2: case 0xF3: // @(d:16,Rn), Rn
    case 0xF4: case 0xF5: case 0xF6: case 0xF7:
    case 0xF8: case 0xF9: case 0xFA: case 0xFB:
    case 0xFC: case 0xFD: case 0xFE: case 0xFF:
      ds16(cmd.Op1, code, dtyp);
      break;
  }
  while ( cmd.itype > H8500_last )     // while MAPs are not resolved
  {
    int index = -(3+short(cmd.itype));
    if ( index < 0 || index >= qnumber(tables) ) interr("ana1");
    code = ua_next_byte();
    if ( code < 0x20 )
    {
      cmd.itype = tables[index].head[code];
    }
    else
    {
      cmd.itype = tables[index].tail[(code>>3)-4];
      reg(cmd.Op2, code, dtyp);
    }
    if ( index == 3 ) switch ( saved_code ) // MAP6
    {
      case 0x01:
      case 0x06:
      case 0x07:
        if ( cmd.itype != H8500_scb ) return 0;
        break;
      case 0x11:
        if ( cmd.itype != H8500_prts
          && cmd.itype != H8500_prtd
          && cmd.itype != H8500_jmp
          && cmd.itype != H8500_pjmp
          && cmd.itype != H8500_jsr
          && cmd.itype != H8500_pjsr ) return 0;
        break;
      default:
        if ( cmd.itype != H8500_movfpe
          && cmd.itype != H8500_movtpe
          && cmd.itype != H8500_dadd
          && cmd.itype != H8500_dsub ) return 0;
    }
    switch ( cmd.itype )
    {
      case H8500_null:
        return 0;
      case H8500_add_q:
        cmd.Op2 = cmd.Op1;
        switch ( code )
        {
          case 0x08: immv(cmd.Op1, 1);  break;
          case 0x09: immv(cmd.Op1, 2);  break;
          case 0x0C: immv(cmd.Op1, -1); break;
          case 0x0D: immv(cmd.Op1, -2); break;
        }
        break;
      case H8500_bset:
      case H8500_bclr:
      case H8500_bnot:
      case H8500_btst:
        cmd.Op2 = cmd.Op1;
        if ( code < 0xC0 )
          reg(cmd.Op1, code, dtyp);
        else
          immv(cmd.Op1, code & 15);
        break;
      case H8500_mov_g:
        if ( (code & 0xF8) == 0x80 ) break;
        cmd.Op2 = cmd.Op1;
        if ( code == 0x06 )
        {
          if ( (cmd.auxpref & aux_word) == 0 ) cmd.auxpref |= aux_byte;
          cmd.Op1.type  = o_imm;
          cmd.Op1.dtyp  = dt_byte;
          cmd.Op1.value = ua_next_byte();
        }
        else if ( code == 0x07 )
        {
          if ( (cmd.auxpref & aux_byte) == 0 ) cmd.auxpref |= aux_word;
          cmd.auxpref  |= aux_mov16;
          cmd.Op1.type  = o_imm;
          cmd.Op1.dtyp  = dt_word;
          cmd.Op1.value = ua_next_word();
        }
        else
          reg(cmd.Op1, code, dtyp);
        break;
      case H8500_cmp_g:
        if ( code > 5 ) break;
        cmd.Op2 = cmd.Op1;
        if ( code == 0x04 )
        {
          cmd.auxpref  |= aux_byte;
          cmd.Op1.type  = o_imm;
          cmd.Op1.dtyp  = dt_byte;
          cmd.Op1.value = ua_next_byte();
        }
        else
        {
          cmd.auxpref  |= aux_word;
          cmd.Op1.type  = o_imm;
          cmd.Op1.dtyp  = dt_word;
          cmd.Op1.value = ua_next_word();
        }
        break;
      case H8500_andc:
      case H8500_orc:
      case H8500_xorc:
      case H8500_ldc:
      case H8500_stc:
        cmd.Op2.reg += SR;
        if ( cmd.Op2.reg == RES1 || cmd.Op2.reg == CP ) return 0;
        if ( ((cmd.auxpref & aux_word) != 0) != (cmd.Op2.reg == SR) ) return 0;
        if ( cmd.itype != H8500_stc ) break;
        // no break
      case H8500_movtpe:
        {
          op_t x  = cmd.Op1;
          cmd.Op1 = cmd.Op2;
          cmd.Op2 = x;
        }
        break;
      case H8500_pjmp:
      case H8500_pjsr:
      case H8500_jmp:
      case H8500_jsr:
        cmd.Op2.type = o_void;
        switch ( code & 0xF0 )
        {
          case 0xC0:
          case 0xD0: phrase(cmd.Op1, code, ph_normal, dt_code); break;
          case 0xE0: ds8(cmd.Op1, code, dt_code); break;
          case 0xF0: ds16(cmd.Op1, code, dt_code); break;
        }
        break;
      case H8500_rtd:
      case H8500_prtd:
        if ( code == 0x14 )
          imm8(cmd.Op1);
        else
          imm16(cmd.Op1);
        break;
      case H8500_scb:
        cmd.Op1 = cmd.Op2;
        d8(cmd.Op2);
        break;
      case H8500_dadd:
      case H8500_dsub:
        if ( (cmd.auxpref & aux_byte) == 0 ) return 0;
        cmd.auxpref &= ~aux_byte;
        break;
    }
  }
  if ( (idpflags & AFIDP_MIXSIZE) == 0 ) // Disassemble mixed size instructions?
  {
    if ( (cmd.auxpref & aux_word) && cmd.Op1.dtyp == dt_byte
      || (cmd.auxpref & aux_byte) && cmd.Op1.dtyp == dt_word )
          if ( cmd.itype != H8500_mov_g ) return 0;
  }
  return cmd.size;
}