RSzacki

Bob manipulation routines

Jul 22nd, 2018
229
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /* Blitting operations: blit Bob, store and restore background. */
  3.  
  4. #include <hardware/blit.h>
  5. #include <hardware/custom.h>
  6. #include <graphics/gfx.h>
  7. #include <clib/graphics_protos.h>
  8.  
  9. #include "Blit.h"
  10.  
  11. extern __far struct Custom custom;
  12.  
  13. /* Prepare Bob mask. Mask must be cleared. */
  14. void prepBobMask(struct BitMap *bob, UBYTE *mask)
  15. {
  16.     /* Prepare variables */
  17.     /* D = A + B */
  18.     UWORD bltcon0    = SRCA | SRCB | DEST | ABC | ABNC | ANBC | ANBNC | NABC | NABNC;
  19.     UWORD bltcon1    = 0;
  20.     UWORD bpr        = bob->BytesPerRow;
  21.     UWORD bltawm     = 0xffff;
  22.     UWORD bltsizv    = bob->Rows;
  23.     UWORD bltsizh    = bpr >> 1;
  24.     UWORD depth      = bob->Depth;
  25.     UBYTE *bobplane;
  26.  
  27.     UWORD i;
  28.  
  29.     OwnBlitter();
  30.  
  31.     for (i = 0; i < depth; i++)
  32.         {
  33.         bobplane = bob->Planes[i];
  34.         WaitBlit();
  35.         custom.bltcon0 = bltcon0;
  36.         custom.bltcon1 = bltcon1;
  37.         custom.bltapt  = bobplane;
  38.         custom.bltbpt  = mask;
  39.         custom.bltdpt  = mask;
  40.         custom.bltamod = 0;
  41.         custom.bltbmod = 0;
  42.         custom.bltdmod = 0;
  43.         custom.bltafwm = bltawm;
  44.         custom.bltalwm = bltawm;
  45.         custom.bltsize = (bltsizv << HSIZEBITS) | bltsizh;
  46.         }
  47.     DisownBlitter();
  48. }
  49.  
  50. /* Blit Bob into background */
  51. void blitBob(struct BitMap *bob, UBYTE *mask, struct BitMap *back, WORD x, WORD y)
  52. {
  53.     /* Prepare variables */
  54.     UWORD shift      = x & 15; /* Shift value */
  55.     /* D = AB + aC */
  56.     UWORD bltcon0    = SRCA | SRCB | SRCC | DEST | ABC | ABNC | NABC | NANBC | (shift << ASHIFTSHIFT);
  57.     UWORD bltcon1    = (shift << BSHIFTSHIFT);
  58.     UWORD bobbpr     = bob->BytesPerRow;
  59.     UWORD backbpr    = back->BytesPerRow;
  60.     UWORD backoffset = (y * backbpr) + ((x >> 4) << 1); /* Offset to destination place in bitplane */
  61.     WORD  bobmodulo  = -2;
  62.     WORD  backmodulo = backbpr - bobbpr - 2;
  63.     UWORD bltafwm    = 0xffff;
  64.     UWORD bltalwm    = 0x0000;
  65.     UWORD bltsizv    = bob->Rows;
  66.     UWORD bltsizh    = (bobbpr >> 1) + 1;
  67.     UWORD depth      = bob->Depth;
  68.     UBYTE *bobplane,
  69.           *backplane;
  70.  
  71.     UWORD i;
  72.  
  73.     OwnBlitter();
  74.  
  75.     for (i = 0; i < depth; i++)
  76.         {
  77.         bobplane  = bob->Planes[i];
  78.         backplane = back->Planes[i] + backoffset;
  79.         WaitBlit();
  80.         custom.bltcon0 = bltcon0;
  81.         custom.bltcon1 = bltcon1;
  82.         custom.bltapt  = mask;
  83.         custom.bltbpt  = bobplane;
  84.         custom.bltcpt  = backplane;
  85.         custom.bltdpt  = backplane;
  86.         custom.bltamod = bobmodulo;
  87.         custom.bltbmod = bobmodulo;
  88.         custom.bltcmod = backmodulo;
  89.         custom.bltdmod = backmodulo;
  90.         custom.bltafwm = bltafwm;
  91.         custom.bltalwm = bltalwm;
  92.         custom.bltsize = (bltsizv << HSIZEBITS) | bltsizh;
  93.         }
  94.     DisownBlitter();
  95. }
  96.  
  97. /* Store/Re-store Bob background */
  98. void storeBack(struct BitMap *back, WORD x, WORD y, struct BitMap *store, UBYTE op)
  99. {
  100.     /* Prepare variables */
  101.     /* D = A */
  102.     UWORD bltcon0    = SRCA | DEST | ABC | ABNC | ANBC | ANBNC;
  103.     UWORD bltcon1    = 0;
  104.     UWORD backbpr    = back->BytesPerRow;
  105.     UWORD backoffset = (y * backbpr) + ((x >> 4) << 1);
  106.     UWORD storeoff   = 0;
  107.     UWORD storebpr   = store->BytesPerRow;
  108.     WORD  backmodulo = backbpr - storebpr;
  109.     WORD  storemod   = 0;
  110.     UWORD bltawm     = 0xffff;
  111.     UWORD bltsizv    = store->Rows;
  112.     UWORD bltsizh    = storebpr >> 1;
  113.     UWORD depth      = store->Depth;
  114.     UBYTE *backplane,
  115.           *storeplane;
  116.  
  117.     UWORD i;
  118.  
  119.     if (op == RESTORE)
  120.         {
  121.         /* Re-storing: swap pointers and modulos */
  122.         struct BitMap *auxbm;
  123.         WORD          auxmod;
  124.         UWORD         auxoff;
  125.  
  126.         auxbm = back;
  127.         back  = store;
  128.         store = auxbm;
  129.  
  130.         auxmod     = backmodulo;
  131.         backmodulo = storemod;
  132.         storemod   = auxmod;
  133.  
  134.         auxoff     = backoffset;
  135.         backoffset = storeoff;
  136.         storeoff   = auxoff;
  137.         }
  138.  
  139.     OwnBlitter();
  140.  
  141.     for (i = 0; i < depth; i++)
  142.         {
  143.         backplane = back->Planes[i] + backoffset;
  144.         storeplane = store->Planes[i] + storeoff;
  145.         WaitBlit();
  146.         custom.bltcon0 = bltcon0;
  147.         custom.bltcon1 = bltcon1;
  148.         custom.bltapt  = backplane;
  149.         custom.bltdpt  = storeplane;
  150.         custom.bltamod = backmodulo;
  151.         custom.bltdmod = storemod;
  152.         custom.bltafwm = bltawm;
  153.         custom.bltalwm = bltawm;
  154.         custom.bltsize = (bltsizv << HSIZEBITS) | bltsizh;
  155.         }
  156.     DisownBlitter();
  157. }
RAW Paste Data