Ä Fido Pascal Conference ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ PASCAL Ä Msg : 286 of 360 From : Ruurd Pels 2:282/317.19 28 May 93 16:31 To : David Todd 1:259/423.0 Subj : Masking...... ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Howdy David! On 21 May 93, David Todd wrote the following message to All: DT> Can anybody tell me how to bitmask? Well here what I'm, doing. I am DT> setting the Map Mask Register to plane 0, and writing all the data needed DT> for plane 0 to the screen with a Movsb, samething with plane 1, and so on. DT> Now I want to mask out any pixels that are 0 on the palette. How would I go DT> about doing that? Do I have to do a compare for each pixel to make sure DT> it's not a 0, before I write it or what? Well thanks to anybody who can DT> help me... ================= S T A R T O F L E C T U R E ======================== A lecture on Boolean Algebra. Just look at bit 3, counting from 0 from the left. ==============================AND========================================= Before : 01101110 bit 3 is ON Mask : 00001000 ---------AND Result : 00001000 equals mask if bit 3 is ON ======== So for ANDing bits, the truth table for each bit is: AND | 0 | 1 ------+--------+-------- 0 | 0 | 0 ------+--------+-------- 1 | 0 | 1 Read this table as: 0 AND 0 equals 0 0 AND 1 equals 0 1 AND 0 equals 0 1 AND 1 equals 1 Use: To check if a bit is set. ============================OR============================================ Before : 01100110 bit 3 is OFF Mask : 00001000 ---------OR Result : 01101110 bit 3 is ON ======== So you switched the bit ON, regardless of its state, without affecting the other bits. For each bit, the truth table for each bit is: OR | 0 | 1 ------+--------+-------- 0 | 0 | 1 ------+--------+-------- 1 | 1 | 1 Use: To switch a bit on regardless of its prior state. ====================================XOR=================================== Before : 01101110 bit 3 is on Mask : 00001000 ---------XOR Result : 01100110 bit 3 is off Mask : 00001000 ---------XOR Result : 01101110 bit 3 is on again ======== So for XORing bits, the truth table for each bit is: XOR | 0 | 1 ------+--------+-------- 0 | 0 | 1 ------+--------+-------- 1 | 1 | 0 Use: To toggle a bit regardless of its state ===============================NOT======================================== The effect of NOTing is inverting each bit in a variable. Truth table: NOT(1) --> 0 NOT(0) --> 1 So if you NOT the mask, you get: NOT(00001000) --> 11110111 So if you want to switch a bit off, regardless of state, you do this: Before : 01101110 bit 3 is ON} Mask : NOT(00001000) --> 11110111 ---------AND Result 01100110 bit 3 is OFF ======== ===============================NOT======================================== Keep in mind that all operators are binary, except for NOT, which is unary. =================== E N D O F L E C T U R E ========================== By substituting a different value for the mask, you may manipulate more than one bit at the same time. Grtz, RFP ;-) --- FMail 0.94 * Origin: Mail Munger (2:282/317.19)