AUTHOR'S PREFACE obvious. Adding up all the numbers (all the bits are set) gives us 255. So each byte can hold a number between zero (no bits are set) and 255 (all bits are set). Sometimes, instead of zero, no bits set is intended to mean 256. That will be noted in the relevant locations. So how do you set a bit? Simple: POKE it with the appropriate number. For example, to set Bit 5, POKE the location with 32. To set Bits 7, 5 and 4, add up their values, 128 + 32 + 16, and POKE the location with the total: 176. Sometimes you need to set a bit without changing other bits already set, so you: POKE number, PEEK (number) + decimal value for the bit to be set. (i.e., POKE 50418, PEEK (50418) + 32) To turn off a bit, instead of adding the value you would subtract it with POKE number, PEEK (number), minus the decimal value for the bit to be turned off. Binary math is simple and easy to learn; if you don't understand it now, you should do further reading on machine language before attempting any serious use of this guide. AND, OR, And EOR It is useful for the reader to know how to perform Boolean logic on bits. There are three functions used in assembly code for bit manipulation in this manner: AND, OR and EOR (exclusive OR). Each requires you to use two numbers, the one being acted upon and the one used to perform the function. Here is a brief explanation of how these logical functions work: AND is usually used as a mask--to zero out unwanted bits. You compare two binary numbers using AND; if both bits in the same location are one, then the result is one. If either bit is zero, then the result is zero. For example: 51 = 00110011 AND 15 = 00001111 -------- Result = 00000011 = 3 OR is freguently used to force setting of a bit. If either bit in the original or the mask is one, then the result is one. For example 65 = 01000001 OR 128 = 10000000 -------- Result = 11000001 = 193 In this case, 65 is the ATASCII "A". By ORing it with 128, we get 193, the ATASCII inverse "A". EOR "flips" bits in the original if the mask has a one in the same location. For example: