# Denise Amiga Custom Chip ## Sprites ### Programming #### SPRPOS and SPRCTL These are some funky data structures: * http://amiga-dev.wikidot.com/hardware:sprxpos * http://amiga-dev.wikidot.com/hardware:sprxctl ```asm ; @param 1 x value, can be address lookup ; @param 2 y value, can be address lookup ; @param 3 write location, sprite header ; @side-effect destroys D1,D2,advances write position SetSPRPOS MACRO MOVEQ #0,D1 MOVE.W \2,D1 AND.W #$FF,D1 LSL.W #8,D1 MOVE.W \1,D2 AND.W #$1FE,D2 LSR.W #1,D2 ADD.W D2,D1 MOVE.W D1,(\3)+ ENDM ; @param 1 x value, can be address lookup ; @param 2 y value, can be address lookup ; @param 3 y stop value, can be address lookup ; @param 4 1 if attached, 0 if not ; @param 5 write location, sprite header ; @side-effect destroys D1,D2,advances write position SetSPRCTL MACRO MOVEQ #0,D1 MOVE.W \3,D1 AND.W #$FF,D1 LSL.W #8,D1 MOVE.W \2,D2 AND.W #$100,D2 LSR.W #6,D2 ADD.W D2,D1 MOVE.W \3,D2 AND.W #$100,D2 LSR.W #7,D2 ADD.W D2,D1 MOVE.W \1,D2 AND.W #$1,D2 ADD.W D2,D1 MOVE.W #\4,D2 LSL.W #7,D2 ADD.W D2,D1 MOVE.W D1,(\5)+ ENDM ``` ### Building in Linux using Krita, LibreSprite, and Amigeconv #### Tools * Krita: https://krita.org/ * LibreSprite: https://libresprite.github.io/#!/#page-top * Amigeconv: https://github.com/tditlu/amigeconv #### Process * Draw the pixel art in Krita. You can use animation frames if you like. Reference images will scale down properly so you can use a full-size animation as a reference. * Export individual frames of the animation * Import the images into LibreSprite. When you load the first image in a sequence, it will offer to import all of them as animation frames. * Ensure the Sprite > Color Mode is Indexed (No dithering) * Rearrange the palette. It works like moving cells in a spreadsheet: * Click a color * Move the mouse to the color edge. The cursor becomes an arrow cross. * Move the color to the new location. * Click "Remap" * Export the animation as PNG frames * Use Amigeconv to convert each PNG to a sprite. In my case I was making 32 pixel wide attached sprites, so you'll get the multiple bitplanes next to each other. Some splitting in code will be in order. * `~/Downloads/amigeconv-v1.0.8-linux-amd64 -f sprite -w 32 -d 4 -a ../frame0000-out-test.png runner1.spr` * Verify it with Okteta: https://apps.kde.org/okteta/ ## Display Generation TODO: clean this up * http://theamigamuseum.com/the-hardware/the-ocs-chipset/denise/ * http://eab.abime.net/showpost.php?p=1249688&postcount=2 * https://amigadev.elowar.com/read/ADCD_2.1/Hardware_Manual_guide/node0042.html * https://www.techtravels.org/2012/04/progress-on-amiga-vsc-made-this-weekend-vsync-problem-persists/ * https://eab.abime.net/showpost.php?p=446699&postcount=48 * https://github.com/rkrajnc/minimig-mist/blob/master/rtl/minimig/agnus.v#L486 * https://retrocomputing.stackexchange.com/questions/2749/how-does-the-amiga-chipset-rga-bus-work * https://retrocomputing.stackexchange.com/questions/22320/what-made-the-amiga-genlock-able * https://github.com/dirkwhoffmann/vAmiga/blob/7f7446ec3b995695cee71c2de1fa79969cd60a5d/Emulator/Components/Agnus/AgnusEvents.cpp#L489-L503 * https://www.ikod.se/wp-content/uploads/2018/10/Amiga_System_Programmers_Guide_1988_Abacus.pdf Since Agnus always needs the current row and column positions, it also contains the raster and column coun ters. These counters for the beam position also create the horizontal and vertical synchronization signals which signal the start of a new line (H- sync) and that of a new picture (V-sync). * https://www.amigawiki.org/dnl/schematics/A500_R6.pdf * http://eab.abime.net/showpost.php?p=1122812&postcount=4 * https://gamesx.com/wiki/lib/exe/fetch.php?media=amiga:a500_rev.8_-_service_manual.pdf --- * Agnus knows the horizontal and vertical beam positions * Agnus updates VPOS and VHPOS * Agnus sends HSYNC and VSYNC * Agnus sends bitplane data to Denise one word of bitplane bits at a time * Denise doesn't have Chip RAM access * Denise has the color registers * Denise just happens to output the correct color at the time when Agnus changes the register * HSYNC, VSYNC, and colors just happen to work out on video output * HSYNC, VSYNC, and colors are combined together for composite ## Useful bugs ### 7 bitplanes in OCS If you set `BPLCON0` to 7 bitplanes, Agnus thinks this is only 4 bitplanes and will only send those over DMA, but Denise will render 5. You can then set `BPL5DAT` manually * https://ada.untergrund.net/?p=boardthread&id=442#msg4696 * https://youtu.be/ste_ejNVvDk