[comp.sys.amiga] MINTERM_SWAP?

wbnsnsr@nmtsun.nmt.edu (William Norris) (12/03/88)

Is there a simple way to swap two bitmaps without a third temporary bitmap?

I've looked over the MINTERMS, but none seem to do the trick.  How come
the lower nibble in the MINTERM is always 0?  If 0xC0 is a copy, shouldn't
0xCC be a swap?


-- 
wbnsnsr@nmtsun.nmt.edu                             |    /// Seulement
William B. Norris IV                               |\\ ///  l'Amiga peut 
POB #2185 C/S                                      | \\//   vous l'offrir.
Socorro, NM  87801                                 |=-=-=-=-=-=-=-=-=-=-=-=-=

ali@polya.Stanford.EDU (Ali T. Ozer) (12/05/88)

In article <1576@nmtsun.nmt.edu> William Norris writes:
>Is there a simple way to swap two bitmaps without a third temporary bitmap?

Yes, but you need to do multiple blits. To swap A and B:

    A = A XOR B
    B = A XOR B
    A = A XOR B

Here's what I do in IFF2PCS (a puzzle program), when the user specifies
"show me the solution" (which causes what's on the screen to be swapped
with the actual picture, in some bitmap somewhere):

To swap:

   XORFromBMToBM (picbm, 0, 0,       winbm, picx, picy, picw, pich);
   XORFromBMToBM (winbm, picx, picy, picbm, 0, 0, picw, pich);
   XORFromBMToBM (picbm, 0, 0,       winbm, picx, picy, picw, pich);

/* Note that the in picbm, the picture is at 0,0, while in winbm, it's
** at picx, picy. The size is picw by pich.
*/

And the routine XORFromBMToBM is:

XORFromBMToBM (srcbm, srcx, srcy, destbm, destx, desty, sizex, sizey)
struct BitMap *srcbm, *destbm;
int srcx, srcy, destx, desty, sizex, sizey;
{
  BltBitMap (srcbm, srcx, srcy,
             destbm, destx, desty,
             sizex, sizey, 0x0060L /* mode */, 0x00ffL, NULL);
}

Make sure you coerce the args into longs if using Manx with 16 bit ints.

Ali Ozer

ali@polya.Stanford.EDU (Ali T. Ozer) (12/05/88)

I just wrote:
>In article <1576@nmtsun.nmt.edu> William Norris writes:
>>Is there a simple way to swap two bitmaps without a third temporary bitmap?
>Yes, but you need to do multiple blits. ...

Let me point out that on a 4-bitplane, 640x400 screen, swapping the
whole screen using the three-XOR BltBitMap method takes a small but
visible fraction of a second. For my purposes, it doesn't matter;
it might in some real-time game or something. Actually, the visual
effect is kind of neat as the bitmaps are XORed in and out in front 
of your eyes --- some sort of metamorphosis.

Ali Ozer

sns@acp.OZ (Stuart Nixon) (12/08/88)

In article <1576@nmtsun.nmt.edu>, wbnsnsr@nmtsun.nmt.edu (William Norris) writes:
> Is there a simple way to swap two bitmaps without a third temporary bitmap?
> 
> I've looked over the MINTERMS, but none seem to do the trick.  How come
> the lower nibble in the MINTERM is always 0?  If 0xC0 is a copy, shouldn't
> 0xCC be a swap?
>
> wbnsnsr@nmtsun.nmt.edu                             |    /// Seulement

I seem to remember a trick using three (3) XOR's to swap contents of registers.
There should be no reason why the same can not be carried out on Bitmaps using
the blitter. It will require three blits to carry out the swap.

I have not worked out the MINTERMs to do XORs. However, if my memory serves me
correctly, the logic is something like :

	B = A XOR B		; where A & B are regs/bitmaps/bits/whatever
	A = A XOR B
	B = A XOR B		; tada! bits swapped

There may be a still quicker way of doing this with the blitter, as it has
the ability to accept three inputs. Still, this should give you some ideas...

Hope this helps.

sns

sns      Stuart Nixon Software, via Australian Computer Products
Phone :  +61 9 322 6497
Uucp  :  ...{uunet,mcvax,ukc}!munnari!acp.oz!sns 
ACSnet:  sns@acp.oz