Beispiel #1
0
void start_his_step() {
	if (comm != COMX || isNewCommand != 1) return;
	isNewCommand = 0;

	chip usual, damka;
	if (HisColor == White) {
		usual = White;
		damka = WDamka;
	} else {
		usual = Black;
		damka = BDamka;
	}

	click_x = hishod[3] - 65;
	click_y = hishod[4] - 49;
	hishod_part = 1;

	if (board[click_y][click_x] == usual || board[click_y][click_x] == damka) {
		if (can_step(click_x, click_y, HisColor)) {
			apply_select(click_x, click_y, 1);
			futureDamka = 0;
			forbidden_direction = DNone;
			his_step();
		} else {
			debug_print("start_his_step error2", 21, 6);
			error();
		}
	} else {
		debug_print("start_his_step error1", 21, 6);
		debug_print_byte(click_x, 6);
		debug_print_byte(click_y, 6);
		debug_print_byte(board[click_y][click_x] + 48, 6);
		error();
	}
}
Beispiel #2
0
UBYTE sd_cmd58()
{
	BYTE r;
	sd_wait_ready();

	spi_send_byte(0x7a);
	spi_send_byte(0x00);
	spi_send_byte(0x00);
	spi_send_byte(0x00);
	spi_send_byte(0x00);
	spi_send_byte(0xff);

	r = sd_wait_r1();
	spi_delay(); // if &0xc0==0xc0 => SDHC
	spi_delay();
	spi_delay();
	spi_delay();

#ifdef DEBUG_SD
	debug_puts("cmd58:");
	debug_print_byte(r);
	debug_puts("\n");
#endif
	return r;
}
Beispiel #3
0
UBYTE sd_cmd8()
{
	BYTE r;
	sd_wait_ready();

	spi_send_byte(0x48);
	spi_send_byte(0x00);
	spi_send_byte(0x00);
	spi_send_byte(0x01);
	spi_send_byte(0xaa);
	spi_send_byte(0x87);

	r = sd_wait_r1();
	spi_delay();
	spi_delay();
	spi_delay();
	spi_delay();
	spi_delay();

#ifdef DEBUG_SD
	debug_puts("cmd8:");
	debug_print_byte(r);
	debug_puts("\n");
#endif
	return r;
}
Beispiel #4
0
int sd_load_sector(UBYTE* target, DWORD sector)
{
	DWORD address;
	BYTE r;
	BYTE timeout;

	address = sector<<9;

#ifdef DEBUG_SD
	debug_puts("loading address ");
	debug_print_dword(address);
	debug_puts("\n");
#endif

	sd_wait_ready();
	// read block
	spi_assert_cs();
	spi_send_byte(0x51);		// CMD17
	spi_send_byte((address>>24)&0xff);
	spi_send_byte((address>>16)&0xff);
	spi_send_byte((address>>8)&0xff);
	spi_send_byte(address&0xff);
	spi_send_byte(0xff);

	r = sd_wait_r1();
#ifdef DEBUG_SD
	debug_puts("cmd17:");
	debug_print_byte(r);
	debug_puts("\n");
#endif
	if ((r&0x80)!=0) {
		spi_deassert_cs();
		return FALSE;
	}

	// wait for 0xfe (start of block)
	timeout = 0xff;
	while (spi_receive_byte()!=0xfe) {
		if (timeout==0) {
			spi_deassert_cs();
			return FALSE;
		}
		timeout = timeout-1;
	}

	// read block
	load_data(target);

	// skip crc
	spi_delay();
	spi_delay();

	// shutdown
	spi_delay();
	spi_deassert_cs();
	return TRUE;
}
Beispiel #5
0
UBYTE sd_acmd41(UBYTE byte0)
{
	BYTE r;

	spi_send_byte(0x77); // CMD55
	spi_send_byte(0x00);
	spi_send_byte(0x00);
	spi_send_byte(0x00);
	spi_send_byte(0x00);
	spi_send_byte(0xff);

	r = sd_wait_r1();
	if (r>1) {
	#ifdef DEBUG_SD
		debug_puts("cmd55 failed:");
		debug_print_byte(r);
		debug_puts("\n");
	#endif
		return -1;
	}

	sd_wait_ready();

	spi_send_byte(0x69); // CMD41
	spi_send_byte(byte0);
	spi_send_byte(0x00);
	spi_send_byte(0x00);
	spi_send_byte(0x00);
	spi_send_byte(0xff);

	r = sd_wait_r1();

#ifdef DEBUG_SD
	debug_puts("acmd41:");
	debug_print_byte(r);
	debug_puts("\n");
#endif
	return r;
}
Beispiel #6
0
UBYTE sd_cmd0()
{
	BYTE r;
	sd_wait_ready();

	spi_send_byte(0x40);
	spi_send_byte(0x00);
	spi_send_byte(0x00);
	spi_send_byte(0x00);
	spi_send_byte(0x00);
	spi_send_byte(0x95);

	r = sd_wait_r1();

#ifdef DEBUG_SD
	debug_puts("cmd0:");
	debug_print_byte(r);
	debug_puts("\n");
#endif
	return r;
}