# Agnus Amiga Custom Chip {{:amiga:custom_chips:agnus_copypasting_windows.png?200|}} Agnus handles the following on the Amiga: * Reserving Chip (and Slow) RAM * Handling Direct Memory Access (DMA) between all the custom chips * Blitting chunks of Chip RAM data around * Copying * Shifting * Line drawing * Filling * Defining the size of the display * Sending horizontal and vertical sync signals * Co-processor is synchronized to the electron gun position and allows setting registers timed to the gun's position * Genlock ## Blitter [[:amiga:custom_chips:agnus:blitter|Amiga Agnus Blitter]] ## DMA ### Examples #### Enabling copper, bitplane rendering, and blitter You need to control DMACON: http://coppershade.org/articles/Code/Reference/DMACON/ ```asm DMACON.COPPER EQU %0000000010000000 DMACON.BITPLANE EQU %0000000100000000 DMACON.BLITTER EQU %0000000001000000 MOVE.W #%1000000111000000,DMACON MOVE.W #%0000000000111111,DMACON ``` ```c #include // enable custom.dmacon = DMAF_SETCLR | DMAF_COPPER | DMAF_RASTER | DMAF_BLITTER; // disable custom.dmacon = DMAF_AUDIO | DMAF_DISK | DMAF_SPRITE; ``` ## Copper (co-processor) [[:amiga:custom_chips:agnus:copper|Amiga Agnus Copper Co-Processor]] ## Setting up a display There seems to be a real common pattern of setting: * `BPLCON0/1` for bitplanes, resolution, and scroll * `BPL1/2MOD` for dealing with how bitplane data is stored * `DIWSTRT/DIWSTOP` for setting the corners of the display * https://www.amigarealm.com/computing/knowledge/hardref/ch3.htm, SETTING THE DISPLAY WINDOW STOPPING POSITION ``` The normal NTSC DIWSTRT is ($2C81). The normal NTSC DIWSTOP is ($F4C1). The normal PAL DIWSTRT is ($2C81). The normal PAL DIWSTOP is ($2CC1). ``` ### Links * https://www.markwrobel.dk/post/amiga-machine-code-letter4/ ### Examples #### Display Setup PAL Lowres, 5 bitplanes ```asm BPLCON0.COLOR EQU %0000001000000000 BPLCON0.BPU_5 EQU %0101000000000000 MOVE.W #(BPLCON0.COLOR|BPLCON0.BPU_5),BPLCON0 MOVE.W #0,BPLCON1 MOVE.W #0,BPL1MOD MOVE.W #0,BPL2MOD MOVE.W #$2C21,DIWSTRT MOVE.W #$2CC1,DIWSTOP ;MOVE.W #$38C1,DIWSTOP MOVE.W #$0038,DDFSTRT MOVE.W #$00D0,DDFSTOP ``` #### Waiting for a vertical blank on PAL The [code that is everywhere](https://eab.abime.net/showthread.php?t=51928) is: ```asm WaitVBL: MOVE.L $DFF004,D0 AND.L #$1FF00,D0 CMP.L #300<<8,D0 BNE.B WaitVBL ``` ```c void WaitVBL() { while ((custom.vposr & 0x1FF00) != (300 << 8)) {} } ``` This works because you're reading both [`VPOSR`](http://amigadev.elowar.com/read/ADCD_2.1/Hardware_Manual_guide/node0045.html) and [`VHPOSR`](http://amigadev.elowar.com/read/ADCD_2.1/Hardware_Manual_guide/node0044.html) in one operation into D0: ``` VPOSR VHPOSR | | | | | | | | | | | | | | | | | V8 | V7 | V6 | V5 | V4 | V3 | V2 | V1 | V0 | h | h | h | h | h | h | h | h | ``` `AND.L #$1FF000,D0` masks out the `h` and keeps the `V#`. `CMP.L #Height<<8` shifts height over 8 bits to the left, then compares the value to the results of the AND. **If you run this on an NTSC Amiga it will lock up!** There's also http://ada.untergrund.net/?p=boardthread&id=31&page=last --- ## Reference ### DMACON flags * C header `hardware/dmabits.h` -- http://amigadev.elowar.com/read/ADCD_2.1/Includes_and_Autodocs_2._guide/node00C8.html These are bits that are ORed together. Remember, the more you enable, the more contention there is for RAM and CPU timing, especially on even clock cycles. * `0-3 -- DMAF_AUDIO` -- all four Paula audio channels * `DMAF_AUD(0-3)` -- the individual channels * `4 -- DMAF_DISK` -- the floppy disk * There's a funky way to have to enable this: http://amigadev.elowar.com/read/ADCD_2.1/Hardware_Manual_guide/node0192.html#line14 * `5 -- DMAF_SPRITE` -- render sprites * `6 -- DMAF_BLITTER` -- the blitter * `7 -- DMAF_COPPER` -- the copper * `8 -- DMAF_RASTER` -- denise screen rendering * `9 -- DMAF_MASTER` -- enable all of the DMA not related to blitter settings * `10 -- DMAF_BLITHOG` -- blitter wins over CPU * b nasty * `15 -- DMAF_SETCLR` -- enable these flags You can also read some blitter-related flags on `DMACONR`: * `13 -- DMAF_BLTNZERO` -- A blit operation happened and only zeroes were written * `14 -- DMAF_BLTDONE` -- 0 if not working, 1 if busy