Copyright (c) Hyperion Entertainment and contributors.

Difference between revisions of "Graphics Minterms"

From AmigaOS Documentation Wiki
Jump to navigation Jump to search
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
Several graphics function calls require a ''minterm'' value to be specified which defines a logic function to perform.
+
Several blitter graphics function calls require a ''minterm'' argument to be specified which defines a Logic Function (LF) to perform during the blit.
   
  +
Here is a table of the most often used graphics blitter logic functions and what they do:
Some background knowledge of the classic Amiga blitter hardware is helpful to understand how to calculate it.
 
  +
{| class="wikitable"
  +
! Logic equation
  +
! LF code (minterm)
  +
! Logic operation performed during copy
  +
|-
  +
| D = A + NB
  +
| 0x30
  +
| Replace destination area with inverted source.
  +
|-
  +
| D = A + NC
  +
| 0x50
  +
| Replace destination area with an inverted version of itself.
  +
|-
  +
| D = A + BNC + NBC
  +
| 0x60
  +
| Put source where the mask is not, put the mask where the source is not (cookie cut).
  +
|-
  +
| D = A + BC
  +
| 0x80
  +
| Only put bits into destination where there is a bit in the same position for both source and destination (sieve operation).
  +
|-
  +
| D = A + B
  +
| 0xC0
  +
| Copy from source to destination.
  +
|-
  +
| D = A + B + C
  +
| 0xE0
  +
| Copy from source to destination through mask
  +
|}
  +
  +
{{Note|The logic equations only make sense when you know what the four channels are assigned to as explained below.}}
  +
  +
Some background knowledge of the classic Amiga blitter hardware is helpful to understand how to derive the minterm argument and decode what it means.
   
 
= Classic Amiga Blitter =
 
= Classic Amiga Blitter =
Line 29: Line 62:
 
| 1 || 1 || 1 || ? || 7 || ABC
 
| 1 || 1 || 1 || ? || 7 || ABC
 
|}
 
|}
 
Where 'N' represents 'not'.
 
   
 
This information is collected in a standard format, the LF (Logic Function) control byte in the BLTCON0 register. This byte programs the blitter to perform one of the 256 possible logic operations on three sources for a given blit.
 
This information is collected in a standard format, the LF (Logic Function) control byte in the BLTCON0 register. This byte programs the blitter to perform one of the 256 possible logic operations on three sources for a given blit.
Line 40: Line 71:
 
would fill in the last four entries of the truth table with 1 (because the A bit is set) and the third, fourth, seven, and eight entries with 1
 
would fill in the last four entries of the truth table with 1 (because the A bit is set) and the third, fourth, seven, and eight entries with 1
 
(because the B bit is set), and all others (the first and second) with 0, because neither A nor B is set. Then, we read the truth table from the
 
(because the B bit is set), and all others (the first and second) with 0, because neither A nor B is set. Then, we read the truth table from the
bottom up, reading 11111100, or $FC.
+
bottom up, reading 11111100, or 0xFC.
   
For another example, an LF control byte of $80 ( = 1000 0000 binary) turns on bits only for those points of the D destination rectangle where the
+
For another example, an LF control byte of 0x80 (= 1000 0000 binary) turns on bits only for those points of the D destination rectangle where the
 
corresponding bits of A, B, and C sources were all on (ABC = 1, bit 7 of LF on). All other points in the rectangle, which correspond to other combinations for A, B, and C, will be 0. This is because bits 6 through 0 of the LF control byte, which specify the D output for these situations,
 
corresponding bits of A, B, and C sources were all on (ABC = 1, bit 7 of LF on). All other points in the rectangle, which correspond to other combinations for A, B, and C, will be 0. This is because bits 6 through 0 of the LF control byte, which specify the D output for these situations,
 
are set to 0.
 
are set to 0.
   
= Graphics Minterms =
+
= Graphics Logic Functions =
   
The blitter functions provided by graphics.library were originally designed to support the classic Amiga blitter with a total of 4 DMA channels. Modern graphics cards have their own blitter(s) which programmers are not allowed direct access to. However, the minterm value still exists to help specify logic operations to perform while performing the copy which may or may not be assisted by the graphics card hardware.
+
The original blitter functions provided by graphics.library like BltBitMap() were originally designed to support the classic Amiga blitter with a total of 4 DMA channels. Modern graphics cards have their own blitter(s) which programmers are not allowed direct access to. However, the minterm value still exists to help specify logic operations to perform while performing the copy which may or may not be assisted by the graphics card hardware.
   
 
The roles of each of the 4 channels are as follows:
 
The roles of each of the 4 channels are as follows:
Line 79: Line 110:
 
This means only the upper 4 bits (bits 4 to 7) of the minterm are used to select the logic operation. The lower bits (0 to 3) will always be zero because channel A is always non-zero or inside the rectangle.
 
This means only the upper 4 bits (bits 4 to 7) of the minterm are used to select the logic operation. The lower bits (0 to 3) will always be zero because channel A is always non-zero or inside the rectangle.
   
= Creating Minterms =
+
== Creating Graphics Logic Functions ==
   
Creating your own logic function is easy if you understand there are four channels (A, B, C, D) and what each channel is assigned to do.
+
Creating your own graphics logic functions is easier if you understand there are four channels (A, B, C, D) and what each channel is assigned to do.
   
== Select channel A ==
+
'''1. Select channel A'''
   
With all of the graphics.library functions channel A is non-zero only when inside the rectangle. This ensures that all pixels outside the rectangle are ignored for purposes of the blit. There is no other choice for channel A.
+
With all of the graphics.library functions, channel A is non-zero only when inside the rectangle. This ensures that all pixels outside the rectangle are ignored for purposes of the blit. There is no other choice for channel A.
   
== Select channel B ==
+
'''2. Select channel B'''
   
 
Channel B is always the source rectangle. You may choose to select pixels as-is (B) or invert them as they are read from the source (NB).
 
Channel B is always the source rectangle. You may choose to select pixels as-is (B) or invert them as they are read from the source (NB).
   
== Select channel C ==
+
'''3. Select channel C'''
   
 
Channel C is either a mask the same dimensions as the channel B source rectangle or it is not used and defined as the destination. When used as a mask, you can choose to select pixels in the mask (C) or not in the mask (NC).
 
Channel C is either a mask the same dimensions as the channel B source rectangle or it is not used and defined as the destination. When used as a mask, you can choose to select pixels in the mask (C) or not in the mask (NC).
   
== Determine channel D logic function ==
+
'''4. Determine logic function'''
  +
  +
Channel D is always the destination channel. Select a logic function to perform using channel D as the destination.
  +
  +
'''5. Derive the minterms'''
  +
  +
Derive the minterms required to implement the selected logic function using whatever method is most convenient.
  +
  +
=== Copy Source to Destination ===
  +
  +
To perform a simple copy from source rectangle to destination the logic function is:
  +
: D = A + B
  +
or in words:
  +
: The destination is all the bits within the rectangle and from the source rectangle.
  +
  +
In this case, there is no source mask involved so channels C and D are identical.
  +
  +
You know channel A is always non-zero so our logic function becomes:
  +
: D = 1 + B
  +
or simplified:
  +
: D = B
  +
  +
=== Copy Inverted Source to Destination ===
  +
  +
To perform a copy from inverted source rectangle to destination the logic function is:
  +
: D = A + NB
  +
or in words:
  +
: The destination is all the bits within the rectangle and from the inverted source rectangle.
  +
  +
In this case, there is no mask involved so channel C and D are identical.
  +
  +
You know channel A is always non-zero so our logic function becomes:
  +
: D = 1 + NB
  +
or simplified:
  +
: D = NB
  +
  +
=== Copy Source and Blit Through Mask ===
  +
  +
To perform a copy from source rectangle to destination through a mask the logic function is:
  +
: D = A + B + C
  +
or in words:
  +
: The destination is all the bits within the rectangle and from the source rectangle and in the source mask.
  +
  +
You know channel A is always non-zero so our logic function becomes:
  +
: D = 1 + B + C
  +
or simplified:
  +
: D = B + C
  +
  +
== Deriving Graphics Minterms ==
  +
  +
With our logic function determined we can then derive the minterms. Each minterm in our truth table requires both B and C channels to be present. Channel A is always non-zero as stated previously.
  +
  +
=== Copy Source to Destination ===
  +
  +
As determined above, the logic function is:
  +
: D = B
  +
  +
Even though the C channel is the same as the D channel we still need to add the C term in order to utilize the logic table. This is easily accomplished given 1 = C + NC as follows:
  +
: D = B(1)
  +
: D = B(C + NC)
  +
: D = BC + BNC
  +
  +
Looking in our truth table that means bit 7 (BC) and bit 6 (BNC) are required.
  +
  +
In binary, that looks like this:
  +
: 11000000
  +
or in hex:
  +
: 0xC0
  +
  +
=== Copy Inverted Source to Destination ===
  +
  +
As determined above, the logic function is:
  +
: D = NB
  +
  +
Even though the C channel is the same as the D channel we still need to add the C term in order to utilize the logic table. This is easily accomplished given 1 = C + NC as follows:
  +
: D = NB(1)
  +
: D = NB(C + NC)
  +
: D = NBC + NBNC
  +
  +
Looking in our truth table that means bit 5 (NBC) and bit 4 (NBNC) are required.
  +
  +
In binary, that looks like this:
  +
: 00110000
  +
or in hex:
  +
: 0x30
  +
  +
=== Copy Source and Blit Through Mask ===
  +
  +
As determined above, the logic function is:
  +
: D = B + C
  +
  +
There are not minterms yet so we do some manipulations:
  +
: D = B1 + 1C
  +
: D = B(C + NC) + (B + NB)C
  +
: D = BC + BNC + BC + NBC
  +
removing duplicates:
  +
: D = BC + BNC + NBC
  +
  +
Looking in our truth table that means bit 7 (BC), bit 6 (BNC) and bit 5 (NBC) are required.
  +
  +
In binary, that looks like this:
  +
: 11100000
  +
or in hex:
  +
: 0xE0
  +
  +
= Designing the LF Control Byte with Minterms =
  +
  +
One approach to designing the LF control byte uses logic equations. Each of the rows in the truth table corresponds to a "minterm", which is a
  +
particular assignment of values to the A, B, and C bits. For instance, the first minterm is usually written:
  +
: NANBNC
  +
or "not A and not B and not C". The last is written as ABC.
  +
  +
{{Note|title=Blitter logic|text=Two terms that are adjacent are AND'ed, and two terms that are separated by "+" are OR'ed. AND has a higher precedence, so AB + BC is equal to (AB) + (BC).}}
  +
  +
Any function can be written as a sum of minterms. If we wanted to calculate the function where D is one when the A bit is set and the C bit
  +
is clear, or when the B bit is set, we can write that as:
  +
: ANC + B
  +
  +
or "A and not C or B". Since "1 and A" is "A":
  +
  +
: D = ANC + B
  +
  +
: D = A(1)NC + (1)B(1)
  +
  +
Since either A or NA is true (1 = A + NA), and similarly for B, and C; we can expand the above equation further:
  +
  +
: D = A(1)NC + (1)B(1)
  +
  +
: D = A(B + NB)NC + (A + NA)B(C + NC)
  +
  +
: D = ABNC + ANBNC + AB(C + NC) + NAB(C + NC)
  +
  +
: D = ABNC + ANBNC + ABC + ABNC + NABC + NABNC
  +
  +
After eliminating duplicates, we end up with the five minterms:
  +
  +
: ANC + B = ABNC + ANBNC + ABC + NABC + NABNC
  +
  +
These correspond to bit positions of 6, 4, 7, 3 and 2 according to our full truth table, which we would then set, and clear the rest.
   
  +
The wide range of logic operations allow some sophisticated graphics techniques. For instance, you can move the image of a car across some pre-existing building images with a few blits. Producing this effect requires predrawn images of the car, the buildings (or background), and a
Channel D is always the destination channel.
 
  +
car "mask" that contains bits set wherever the car image is not transparent. This mask can be visualized as the shadow of the car from a light source at the same position as the viewer.

Latest revision as of 23:13, 28 September 2015

Several blitter graphics function calls require a minterm argument to be specified which defines a Logic Function (LF) to perform during the blit.

Here is a table of the most often used graphics blitter logic functions and what they do:

Logic equation LF code (minterm) Logic operation performed during copy
D = A + NB 0x30 Replace destination area with inverted source.
D = A + NC 0x50 Replace destination area with an inverted version of itself.
D = A + BNC + NBC 0x60 Put source where the mask is not, put the mask where the source is not (cookie cut).
D = A + BC 0x80 Only put bits into destination where there is a bit in the same position for both source and destination (sieve operation).
D = A + B 0xC0 Copy from source to destination.
D = A + B + C 0xE0 Copy from source to destination through mask
Note
The logic equations only make sense when you know what the four channels are assigned to as explained below.

Some background knowledge of the classic Amiga blitter hardware is helpful to understand how to derive the minterm argument and decode what it means.

Classic Amiga Blitter

The blitter can combine the data from the three source DMA channels in up to 256 different ways to generate the values stored by the destination DMA channel. These sources might be one bitplane from each of three separate graphics images. While each of these sources is a rectangular region composed of many points, the same logic operation will be performed on each point throughout the rectangular region. Thus, for purposes of defining the blitter logic operation it is only necessary to consider what happens for all of the possible combinations of one bit from each of the three sources.

There are eight possible combinations of values of the three bits, for each of which we need to specify the corresponding destination bit as a zero or one. This can be visualized with a standard truth table, as shown below. We have listed the three source channels, and the possible values for a single bit from each one.

A B C D BLTCON0
position
Minterm
0 0 0 ? 0 NANBNC
0 0 1 ? 1 NANBC
0 1 0 ? 2 NABNC
0 1 1 ? 3 NABC
1 0 0 ? 4 ANBNC
1 0 1 ? 5 ANBC
1 1 0 ? 6 ABNC
1 1 1 ? 7 ABC

This information is collected in a standard format, the LF (Logic Function) control byte in the BLTCON0 register. This byte programs the blitter to perform one of the 256 possible logic operations on three sources for a given blit.

To calculate the LF control byte in BLTCON0, fill in the truth table with desired values for D, and read the function value from the bottom of the table up.

For example, if we wanted to set all bits in the destination where the corresponding A source bit is 1 or the corresponding B source bit is 1, we would fill in the last four entries of the truth table with 1 (because the A bit is set) and the third, fourth, seven, and eight entries with 1 (because the B bit is set), and all others (the first and second) with 0, because neither A nor B is set. Then, we read the truth table from the bottom up, reading 11111100, or 0xFC.

For another example, an LF control byte of 0x80 (= 1000 0000 binary) turns on bits only for those points of the D destination rectangle where the corresponding bits of A, B, and C sources were all on (ABC = 1, bit 7 of LF on). All other points in the rectangle, which correspond to other combinations for A, B, and C, will be 0. This is because bits 6 through 0 of the LF control byte, which specify the D output for these situations, are set to 0.

Graphics Logic Functions

The original blitter functions provided by graphics.library like BltBitMap() were originally designed to support the classic Amiga blitter with a total of 4 DMA channels. Modern graphics cards have their own blitter(s) which programmers are not allowed direct access to. However, the minterm value still exists to help specify logic operations to perform while performing the copy which may or may not be assisted by the graphics card hardware.

The roles of each of the 4 channels are as follows:

Channel Description
A Non-zero when inside the rectangle
B Source rectangle
C Source mask or destination rectangle
D Destination rectangle

Channel A is non-zero only when inside the rectangle and we don't care about any pixels outside the source rectangle. Therefore, the truth table can be simplified to:

B C D Bit Minterm
0 0 ? 4 NBNC
0 1 ? 5 NBC
1 0 ? 6 BNC
1 1 ? 7 BC

This means only the upper 4 bits (bits 4 to 7) of the minterm are used to select the logic operation. The lower bits (0 to 3) will always be zero because channel A is always non-zero or inside the rectangle.

Creating Graphics Logic Functions

Creating your own graphics logic functions is easier if you understand there are four channels (A, B, C, D) and what each channel is assigned to do.

1. Select channel A

With all of the graphics.library functions, channel A is non-zero only when inside the rectangle. This ensures that all pixels outside the rectangle are ignored for purposes of the blit. There is no other choice for channel A.

2. Select channel B

Channel B is always the source rectangle. You may choose to select pixels as-is (B) or invert them as they are read from the source (NB).

3. Select channel C

Channel C is either a mask the same dimensions as the channel B source rectangle or it is not used and defined as the destination. When used as a mask, you can choose to select pixels in the mask (C) or not in the mask (NC).

4. Determine logic function

Channel D is always the destination channel. Select a logic function to perform using channel D as the destination.

5. Derive the minterms

Derive the minterms required to implement the selected logic function using whatever method is most convenient.

Copy Source to Destination

To perform a simple copy from source rectangle to destination the logic function is:

D = A + B

or in words:

The destination is all the bits within the rectangle and from the source rectangle.

In this case, there is no source mask involved so channels C and D are identical.

You know channel A is always non-zero so our logic function becomes:

D = 1 + B

or simplified:

D = B

Copy Inverted Source to Destination

To perform a copy from inverted source rectangle to destination the logic function is:

D = A + NB

or in words:

The destination is all the bits within the rectangle and from the inverted source rectangle.

In this case, there is no mask involved so channel C and D are identical.

You know channel A is always non-zero so our logic function becomes:

D = 1 + NB

or simplified:

D = NB

Copy Source and Blit Through Mask

To perform a copy from source rectangle to destination through a mask the logic function is:

D = A + B + C

or in words:

The destination is all the bits within the rectangle and from the source rectangle and in the source mask.

You know channel A is always non-zero so our logic function becomes:

D = 1 + B + C

or simplified:

D = B + C

Deriving Graphics Minterms

With our logic function determined we can then derive the minterms. Each minterm in our truth table requires both B and C channels to be present. Channel A is always non-zero as stated previously.

Copy Source to Destination

As determined above, the logic function is:

D = B

Even though the C channel is the same as the D channel we still need to add the C term in order to utilize the logic table. This is easily accomplished given 1 = C + NC as follows:

D = B(1)
D = B(C + NC)
D = BC + BNC

Looking in our truth table that means bit 7 (BC) and bit 6 (BNC) are required.

In binary, that looks like this:

11000000

or in hex:

0xC0

Copy Inverted Source to Destination

As determined above, the logic function is:

D = NB

Even though the C channel is the same as the D channel we still need to add the C term in order to utilize the logic table. This is easily accomplished given 1 = C + NC as follows:

D = NB(1)
D = NB(C + NC)
D = NBC + NBNC

Looking in our truth table that means bit 5 (NBC) and bit 4 (NBNC) are required.

In binary, that looks like this:

00110000

or in hex:

0x30

Copy Source and Blit Through Mask

As determined above, the logic function is:

D = B + C

There are not minterms yet so we do some manipulations:

D = B1 + 1C
D = B(C + NC) + (B + NB)C
D = BC + BNC + BC + NBC

removing duplicates:

D = BC + BNC + NBC

Looking in our truth table that means bit 7 (BC), bit 6 (BNC) and bit 5 (NBC) are required.

In binary, that looks like this:

11100000

or in hex:

0xE0

Designing the LF Control Byte with Minterms

One approach to designing the LF control byte uses logic equations. Each of the rows in the truth table corresponds to a "minterm", which is a particular assignment of values to the A, B, and C bits. For instance, the first minterm is usually written:

NANBNC

or "not A and not B and not C". The last is written as ABC.

Blitter logic
Two terms that are adjacent are AND'ed, and two terms that are separated by "+" are OR'ed. AND has a higher precedence, so AB + BC is equal to (AB) + (BC).

Any function can be written as a sum of minterms. If we wanted to calculate the function where D is one when the A bit is set and the C bit is clear, or when the B bit is set, we can write that as:

ANC + B

or "A and not C or B". Since "1 and A" is "A":

D = ANC + B
D = A(1)NC + (1)B(1)

Since either A or NA is true (1 = A + NA), and similarly for B, and C; we can expand the above equation further:

D = A(1)NC + (1)B(1)
D = A(B + NB)NC + (A + NA)B(C + NC)
D = ABNC + ANBNC + AB(C + NC) + NAB(C + NC)
D = ABNC + ANBNC + ABC + ABNC + NABC + NABNC

After eliminating duplicates, we end up with the five minterms:

ANC + B = ABNC + ANBNC + ABC + NABC + NABNC

These correspond to bit positions of 6, 4, 7, 3 and 2 according to our full truth table, which we would then set, and clear the rest.

The wide range of logic operations allow some sophisticated graphics techniques. For instance, you can move the image of a car across some pre-existing building images with a few blits. Producing this effect requires predrawn images of the car, the buildings (or background), and a car "mask" that contains bits set wherever the car image is not transparent. This mask can be visualized as the shadow of the car from a light source at the same position as the viewer.