[comp.sources.amiga] v02i060: flip - display hack

page@swan.ulowell.edu (Bob Page) (11/11/88)

Submitted-by: rucklidg@svax.cs.cornell.edu (William Rucklidge)
Posting-number: Volume 2, Issue 60
Archive-name: graphics/flip.1

Here's a screen hack I came up with a while ago.

[binary included too, it's small.  ..Bob]

#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar:    Shell Archiver
#	Run the following text with /bin/sh to create:
#	README
#	flip.c
#	flip.uu
# This archive created: Thu Nov 10 16:45:22 1988
cat << \SHAR_EOF > README
    Here's Yet Another Screen Hack I wrote in a moment of boredom.
Type "flip", and observe. Try typing a few other commands, like "list".
Type "flip" again to restore (or do anything which affects screen
ordering/position (e.g. Left-Amiga-N)).

    For some reason or other this doesn't work reliably if you have more
than the Workbench screen open. It won't crash the machine, but it won't
have the desired effect.

				- William Rucklidge
				  rucklidg@svax.cs.cornell.edu
SHAR_EOF
cat << \SHAR_EOF > flip.c
/*
 * flip.c - yet another screen hack
 *
 * William Rucklidge	rucklidg@svax.cs.cornell.edu
 *
 * This code is released into the public domain. What's the point in
 * copyrighting something like this, anyway?
 *
 * Thanks to jimm, for dcop.
 *
 * This will work on simple workbench screens. There seems to be some problem
 * when more than one screen is open: GfxBase->ActiView doesn't seem to contain
 * the right information (the copper lists and the View don't match). I'm
 * probably just not looking in the right place, though.
 *
 * This makes some assumptions about the copper list: that the modulo registers
 * are loaded before the bitplane data pointers, that the bitplane data pointers
 * are loaded in successive instructions, high then low, and that the copper
 * list being mangled is that of a fully displayed screen (not a window into a
 * larger bitmap). These assumptions are all true for automatically generated
 * copper lists.
 *
 * This does seem to work with vscreen'd and morerowed Workbench screen.
 *
 */

#include <graphics/gfxbase.h>
#include <graphics/view.h>
#include <graphics/copper.h>

/* The codes for a few copper instructions */
#define	MOVEBPL1MOD	0x0108
#define	MOVEBPL2MOD	0x010A
#define	MOVEBPL1PT	0x00E0

#define	MAXPLANES	6
#define	PTSKIP		4

#define	MOVEBPLPT(x)	(MOVEBPL1PT + ((x) - 1) * PTSKIP)

extern void *OpenLibrary(), CloseLibrary(), Forbid(), Permit();

struct GfxBase *GfxBase;

typedef	int	boolean;
#undef	FALSE
#undef	TRUE
#define	FALSE	0
#define	TRUE	1

void
mangleCprList(list, isLOF, bpl, vy)
struct cprlist *list;		/* A copper list to be mangled. */
boolean isLOF;			/* Is this a LOF coppper list? */
unsigned short bpl;		/* The number of bytes per line */
unsigned short vy;		/* The number of lines */
{
    register short *cp, inst;
    char *oldbplpt;
    char *newbplpt;
    register int i;
    long offset;
    boolean wasflipped = FALSE;

    if (!list) {
	return;
	}

    for (i = list->MaxCount, cp = (short *)list->start;
	 i > 0;
	 i--, cp += 2) {
	inst = *cp;
	if ((inst == MOVEBPL1MOD) || (inst == MOVEBPL2MOD)) {
	    /* Mangle the modulus */
	    if (*(cp + 1) < 0) {
		wasflipped = TRUE;
		}
	    *(cp + 1) = - (bpl << 1) - *(cp + 1);
	    }
	else if ((inst >= MOVEBPLPT(1)) && (inst < MOVEBPLPT(MAXPLANES + 1))
					&& (!(inst & 3))) {
	    /* This is a load bitplane address register instruction.
	     * Make sure that this instruction is followed by one to
	     * load the other half of the register
	     */
	    if ((*(cp + 2) == inst + 2) && (i > 1)) {
		/* Mangle the bitplane address */
		/* Pick out the address from the operands of the instructions */
		oldbplpt = (char *)((((long)*(cp + 1)) << 16) +
				    (unsigned short)(*(cp + 3)));
		offset = (vy - 1) * (long)bpl +
			 (isLOF ? 0 : -((short)bpl << 1));
		if (!wasflipped) {
		    newbplpt = oldbplpt + offset;
		    }
		else {
		    newbplpt = oldbplpt - offset;
		    }

		/* Install the new address */
		*(cp + 1) = (long)newbplpt >> 16;
		*(cp + 3) = (long)newbplpt & 0xffff;
		}
	    }
	}
    }

int
main()
{
    unsigned short bpl, vy;

    GfxBase = OpenLibrary("graphics.library", 0L);
    
    /* We don't want anyone rebuilding the copper lists while we mangle them */
    Forbid();
    /* Get bytes per line and screen height */
    bpl = ((GfxBase->ActiView->ViewPort->DWidth) >> 3) & ~1;
    vy = GfxBase->ActiView->ViewPort->DHeight;

    mangleCprList(GfxBase->ActiView->LOFCprList, TRUE, bpl, vy);
    mangleCprList(GfxBase->ActiView->SHFCprList, FALSE, bpl, vy);
    Permit();

    CloseLibrary(GfxBase);
    return(0);
    }
SHAR_EOF
cat << \SHAR_EOF > flip.uu

begin 644 flip
M```#\P`````````#``````````(```(>````$@````$```/I```"'D[Z`;!.!
M5?_R2.<,($)M__)*K0`(9@A,WP0P3EU.=2!M``@Z*``((FT`""1I``1@``#<>
M.!*X?`$(9P:X?`$*9B!*:@`";`8[?``!__(P+0`.XT!$0)!J``(U0``"8```O
MJKA\`.!M``"BN'P`^&P``)HP!,!\``-F``"0,`140#(J``2R0&8``(*Z?``!A
M;WHP*@`"2,!R$..@=``T*@`&T((K0/_\,"T`$%-`P.T`#B\`2FT`#&<$<`!@*
M"C(M``[C03`!1$!(P"0?U(`K0O_T2FW_\F8.("W__-"M__0K0/_X8`P@+?_\Y
MD*W_]"M`__@@+?_X<A#BH#5```(@+?_XP+P``/__-4``!E-%6(I*16X`_R)@"
M`/\"3E7__$*G2'H`@DZZ!P103RE`@#H@;(`Z(F@`(BQ1,"X`&.9`"(```#M`O
M__X@;(`Z(F@`(BQ1.VX`&O_\/RW__#\M__X_/``!(&R`.B)H`"(O*0`$3KK^*
MF$_O``H_+?_\/RW__D)G(&R`.B)H`"(O*0`(3KK^>D_O``HO+(`Z3KH&0EA/_
M<`!.74YU9W)A<&AI8W,N;&EB<F%R>0``87!#[(`&1>R`!K7)9@XR/``0:PATF
M`"+"4<G__"E/@`8L>``$*4Z`"DCG@(`(+@`$`2EG$$OZ``A.KO_B8`9"I_-?U
M3G-#^@`@3J[^:"E`@`YF#"X\``.`!TZN_Y1@!$ZZ`!I03TYU9&]S+FQI8G)A2
M<GD`2?D``'_^3G5.50``+PI(>0`!```P+(`"P?P`!B\`3KH%I%!/*4"`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`"+&R`"B)O``0@+P`(3N[]V")O``0L;(`*3N[^AB!O*
M``0L;(`*3N[^@$SO`P``!"QL@#Y.[O^@(&\`!"QL@#Y.[O^F(&\`!"QL@#Y.4
M[O^R```#[`````$````!```")@````````/R```#Z@````$`%``````#\@``D
*`^L````!```#\@$`E
``
end
size 2260
SHAR_EOF
#	End of shell archive
exit 0
-- 
Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
Have five nice days.