Copper Magic This is an edited extract from Part 5 of the Amiga Format series Banging The Metal, which appeared in issue 126 of the magazine, on the news-stands in July 1999. Two of the programs written to accompany this series appear on Aminet by agreement of the copyright holders: author Simon N Goodwin and purchaser of first UK publication rights, Future Publishing. The files herein are copyright but may be freely copied by individuals in their entireity, strictly and only for private use. You must contact the author simon@studio.woden.com for permission before publishing edited or derived works. There are two programs in this archive, supplied as ANSI source text and compiled standalone HiSoft BASIC. CopperFile disassembles the current copper list to a file or device. CopperShow disassembles the current copper list to the display. The main document file gives an overview of Copper Lists, condensed from the discussion in the magazine, explaining the software and a simple example list. For more information, consult the Commodore Amiga Hardware Reference Manual or back issues of Amiga Format. Copper Lists Every screen the Amiga displays has an associated Copper List. The contents of that list correspond to the display format - its size, resolution, position and colours. Copper list instructions tell the other custom chips where to find display data and how to display it. Synchronisation means the Amiga can change colours, resolution and other display attributes with pixel accuracy. The Copper can control all the main Amiga custom chips, including the colour palette, scrolling playfields, moving 'sprite' patterns on top of the main display, and the equally important 'Blitter' coprocessor. The Copper is simple but subtly powerful. If the test of a 'RISC' processor is the Reduction of its InStruCtion set, the Amiga's display CO-ProcEssoR or 'Copper' is the risciest around. It's a true processor, capable of loops, conditional tests, memory transfers and logical operations, yet it has just three instructions: MOVE, WAIT and SKIP. These derive power from the other parts of the custom chip set, which are the target for MOVEs. The unique strengths of the Copper come from the SKIPs and WAITs, which allow exact synchronisation of the program, known as a Copper List, with the beam scanning the Amiga display. SKIP allows conditional execution, depending on the beam position. The next instruction is SKIPed if a position has already been passed. Copper Stripes Commodities like Copper Demon and WBVerlauf give AGA screens a smoothly graduated colour background without requiring extra display planes. The command STRIPES does a similar trick for old Amigas, though less smoothly. You can have hundreds of colours on screen, while still using a fast 'four colour' Workbench, consuming just two planes of display memory. The Copper does this by inserting WAIT and MOVE instructions to change the colour of the background on each display line. This consumes negligible processing time, as once the WAIT has been read the Copper snoozes till the beam reaches the required co-ordinates. Processing starts at the beginning of the list as each new display is scanned from the top. The Copper can move new values into 'Jump' registers, changing its own program from one display field to the next. Among other things, this is how interlaced displays are made. The Copper can split screens into areas or 'slices' with contrasting colours and modes. You can see this in many games, and when you drag screens with the mouse. It's particularly impressive when screens differ in resolution and include dragable colour stripes. Multi-player games use the Copper to divide the screen into sections with independently-scrolling contents. They can re-use sprites so that channels used for moving monsters at the top of this screen might form an overlaid scoreboard at the bottom. The Copper re-programs the sprite engine to put up a new pattern, with unique size, colours and location, as soon as the last scan line of the previous usage has passed. The Copper can program the Blitter to start it as soon as a position on the screen has been reached. Thus it ensures that display updates are never disturbed by the beam, giving a jagged display, mixing old and new data. The Copper can also toggle sound and custom Amiga features. It can even trigger interrupts to the main processor, so synchronising complex operations like animation and file handling. Disassembler The Copper list disassembler is written in HiSoft BASIC. It finds and decodes the current Copper list, identifying custom chip registers by name. It formats values as RGB colours, low resolution display co-ordinates, bytes, nybbles or bit patterns depending on their destination. Custom chip register names match those used in Commodore documentation and explained in this series. The disassembler finds the current Copper List from the system GraphicsBase structure. Select other display modes to see the difference. The covermounted AF CD42 includes extensive example output from these programs. Example list The example shows a standard 4 colour AGA Copper List, plus one colour-change part way down the screen. The first instruction WAITs until the beam reaches the 23rd scan line, high in the border shortly before the active part of the display is generated. The next ten instructions set up four screen colours for background, dark, light and active items. Old Amigas use just four instructions to set the colours, but the 24 bit AGA palette is programmed in two steps. Each MOVE can transfer up to 16 bits of data. 16 bit Amigas support 4096 colours, using four bits for each proportion of red, blue and green (0 to 15) in a given hue. AGA supports 16 million colours, which is more than a single MOVE can select, so register BPLCON3 directs colour changes to the most (%110010000011) or least (%111010000011) significant bits. The AGA-only register BPLCON4 selects between sets of colours, as noted in Amiga Format 127, part 6 of the Banging The Metal series. MOVEs that set the Pointer colours have been removed to save space - they're similar to those for the playfield colours, but set other palette registers. The next line sets the display position (DIWSTART), altering as you move the window around with Overscan preferences. MOVEs to BPLCON (BitPLane CONtrol) registers determine the display mode. This value of BPLCON0 selects four colour, SuperHiRes, AGA mode. BPLCON1 and 2 set defaults for compatibility with other modes, and the third MOVE to BPLCON3 again switches the palette bank. The DIsplay Window (DIW) and Display Data Fetch (DDF) are set separately, to allow scrolling displays. The MOVE to DIWSTOP positions the lower right corner of the display, while DDFSTART and DDFSTOP determine the start and end of Display Data Fetches. BPLxMOD settings tell the Amiga the interval between display lines (or MODulo) in bytes. This 88 byte modulo allows bitplanes to be interleaved in memory, which is convenient when blitting. BPLxPTR registers indicate the start address of the display memory for each BitPLane. Again the values are too big for a single 16 bit MOVE, so one sets the High word of the PoinTer (PTH) and another sets the PoinTer's Low word (PTL). Bitplane 1 starts at 3*65536+608 = address 197216, and Bitplane 2 follows 88 bytes later, matching the modulos. DIWHIGH sets extra bits added for bigger ECS displays. FMODE selects 64 bit AGA fetches for the display data, four times faster than OCS or ECS could manage. For the time being, it's enough to know that the Copper controls these. Mixed-mode screens use a WAIT then more MOVEs to change these registers. The penultimate WAIT instruction in the example determines the position of the colour change on the screen, in the border of line 200 (WAIT for Y=200, X=0). After that a COLOUR0 is changed, in two steps for the full 24 bit effect. Copper lists on the AFCD include many such WAIT and MOVE combinations, giving smooth colour stripes like those in the example screen. The last WAIT lets the Copper idle till the end of the field. Simon N Goodwin, simon@studio.woden.com, Warwick, March 2000. EXAMPLE COPPER LIST WAIT for Y=23 X=0 MOVE %0000 1100 1000 0011 to BPLCON3 MOVE R=9 G=9 B=9 to COLOUR 0 MOVE R=0 G=0 B=0 to COLOUR 1 MOVE R=15 G=15 B=15 to COLOUR 2 MOVE R=2 G=5 B=2 to COLOUR 3 MOVE %0000 1110 1000 0011 to BPLCON3 MOVE R=5 G=5 B=5 to COLOUR 0 MOVE R=0 G=0 B=0 to COLOUR 1 MOVE R=15 G=15 B=15 to COLOUR 2 MOVE R=13 G=8 B=9 to COLOUR 3 MOVE 0 , 1 , 1 to BPLCON4 MOVE (X= 81 ,Y= 25 ) to DIWSTART MOVE %0010 0010 0100 0001 to BPLCON0 MOVE %0000 0010 0010 0100 to BPLCON2 MOVE %0000 1100 1000 0011 to BPLCON3 MOVE (X= 245 ,Y= 249 ) to DIWSTOP MOVE (X= 32 ,Y= 0 ) to DDFSTART MOVE (X= 112 ,Y= 0 ) to DDFSTOP MOVE %0 to BPLCON1 MOVE 88 to BPL1MOD MOVE 88 to BPL0MOD MOVE 3 to BPL1PTH MOVE 608 to BPL1PTL MOVE 3 to BPL2PTH MOVE 696 to BPL2PTL MOVE %0000 0001 0000 0000 to DIWHIGH MOVE %1000 0000 0000 0011 to FMODE WAIT for Y=200 X=0 MOVE R = 5 G = 6 B = 4 to COLOUR 0 MOVE %0000 1110 1000 0011 to BPLCON3 MOVE R = 10 G = 9 B = 11 to COLOUR 0 WAIT for Y=255 X=254 Note: Sprite colour settings omitted for clarity