Hardware Reference
In-Depth Information
If it is, it works out what byte or value this location represents in the sequence and what bit
within that byte it is. Then this line toggles the bit:
seq[byte] ^= 1 << bit
It will look a bit odd and so calls for some explanation. The right side of the equals sign makes
a number with a one in the bit position that you want to change. This is done by taking the
value 1 and shifting it to the left the number of times you calculated when you worked out
what bit was clicked. The equals sign is preceded by a caret symbol ^ and means the exclusive
OR operation. So this number you have created by shifting is exclusive OR ed with the value of
the sequence at this point, and it is then put pack into the sequence list. It is a shorthand way
of saying this:
seq[byte] = seg[byte] ^ (1 << bit)
When you exclusive OR , or XOR as it is sometimes called, two numbers, the result is that you
set bits that are only set to a logic one in one of the numbers and you invert the bits that are
a set to a logic one in both numbers. So doing this operation simply inverts the bit corre-
sponding to the bit you have clicked. You can then go and draw the whole column; again you
update the screen image when you have finished all the drawing.
Next, the mouseGet function looks to see if the mouse has been clicked in any of the control
boxes. If it has, it does the appropriate action. Clearing the sequence writes zero in every value
in the sequence, while inverting applies an exclusive OR operation to all the bits in every value.
The number 0xff is simply a byte with all bits set to one. This notation is called hexadecimal and
believe it or not is simpler to think about than decimal when it comes to creating bit patterns.
The faster and slower control boxes change the value to add to the nextTime variable. There
are also some checks which stop the value from going below zero. Finally the last control
changes the variable that determines where the sequence advance is coming from. In order to
inform you where the advance trigger is coming from the text in this control box is changed
when you click it. Figure 3-2 shows the sequencer as it appears on the screen.
Figure 3-2:
he sequencer
application.
Search WWH ::




Custom Search