/*
    Living Realms is a primate evolution simulator.
    Copyright (C) 2011  Sterling Pickens

    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 3 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.  If not, see <http://www.gnu.org/licenses/>.
*/


void SET_ZERO(unsigned char **array, size_t src_y, size_t src_x){
	size_t byte_x = src_x>>3;
	unsigned char bit = src_x % 8;
	unsigned char cur = array[src_y][byte_x];
	unsigned char b0 = (bit == 0) ? 0 : (((cur<<7) & 128) >= 128);
	unsigned char b1 = (bit == 1) ? 0 : (((cur<<6) & 128) >= 128)<<1;
	unsigned char b2 = (bit == 2) ? 0 : (((cur<<5) & 128) >= 128)<<2;
	unsigned char b3 = (bit == 3) ? 0 : (((cur<<4) & 128) >= 128)<<3;
	unsigned char b4 = (bit == 4) ? 0 : (((cur<<3) & 128) >= 128)<<4;
	unsigned char b5 = (bit == 5) ? 0 : (((cur<<2) & 128) >= 128)<<5;
	unsigned char b6 = (bit == 6) ? 0 : (((cur<<1) & 128) >= 128)<<6;
	unsigned char b7 = (bit == 7) ? 0 : (((cur) & 128)  >= 128)<<7;

	array[src_y][byte_x] = b0+b1+b2+b3+b4+b5+b6+b7;
}

void SET_ONE(unsigned char **array, size_t src_y, size_t src_x){
	size_t byte_x = src_x>>3;
	unsigned char bit = src_x % 8;
	unsigned char cur = array[src_y][byte_x];
	unsigned char b0 = (bit == 0) ? 1   : (((cur<<7) & 128) >= 128);
	unsigned char b1 = (bit == 1) ? 2   : (((cur<<6) & 128) >= 128)<<1;
	unsigned char b2 = (bit == 2) ? 4   : (((cur<<5) & 128) >= 128)<<2;
	unsigned char b3 = (bit == 3) ? 8   : (((cur<<4) & 128) >= 128)<<3;
	unsigned char b4 = (bit == 4) ? 16  : (((cur<<3) & 128) >= 128)<<4;
	unsigned char b5 = (bit == 5) ? 32  : (((cur<<2) & 128) >= 128)<<5;
	unsigned char b6 = (bit == 6) ? 64  : (((cur<<1) & 128) >= 128)<<6;
	unsigned char b7 = (bit == 7) ? 128 : (((cur) & 128)  >= 128)<<7;

	array[src_y][byte_x] = b0+b1+b2+b3+b4+b5+b6+b7;
}

char IS_SET(unsigned char **array, size_t src_y, size_t src_x){
	unsigned char bit = src_x % 8;
	unsigned char cur = array[src_y][src_x>>3];
	cur <<= (7-bit);
	cur &= 128;

	if(cur >= 128)
		return 1;
	else
		return 0;
}
