home *** CD-ROM | disk | FTP | other *** search
/ The AGA Experience 2 / agavol2.iso / software / utilities / programmers / source / aga_copper / copper.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-06-29  |  14.9 KB  |  457 lines

  1. //************************************************************************
  2. //
  3. //                         AGA COPPER LIST EXAMPLE
  4. //
  5. //************************************************************************
  6. //
  7. //  This listing explains how to code a smashing AGA copper list using C
  8. //  language. Originally it has been written for Emanuele Mainini.
  9. //  Mainini's learning Amiga C and asked me how it's possible to write a
  10. //  full AGA rainbow effect in C or assembly or even in Amos.
  11. //  He had quite a good experience in Amos but never found infos on copper
  12. //  AGA in Rom Kernel and other sources. This is because honestly RKM
  13. //  still refers to ECS programming and Amos does not support AGA chips!
  14. //  Well the question sounds like this: Is it possible write a smooth color
  15. //  range using AGA in C or in Amos Professional ? Is it possible only in
  16. //  assembly ?
  17. //  Answer: Sure things, that's a really simple task in C (or asm!), about
  18. //  Amos, I think it is possible, just poke BPLCON3 and use the normal
  19. //  copper instruction provided by Amos, so you can have copper AGA
  20. //  backgrounds even in ECS-Amos.
  21. //
  22. //  How this is possible: Well, copper hasn't changed a lot from ECS, so
  23. //  registers are word sized and only a bit in BPLCON3 allows you shifting
  24. //  from MSB (default) to LSB.
  25. //  24-bits color is a 8-bits per gun entity, so RGB with 8 bits per component,
  26. //  pure white is FFFFFF, pure red's FF0000, yellow FFFF00 and blue 0000FF.
  27. //  For compatibility purposes, color registers have been split in 2 words:
  28. //  the MSB and the LSB, so the four colors above in the same order will
  29. //  be FFF-FFF, F00-F00, FF0-FF0, 00F-00F, that's, the same 12-bits colors
  30. //  seem to be repeated twice! Well, this it's always TRUE for 12-bits
  31. //  colors but almost never for 24-bits ones.
  32. //  This expedient improves compatibility for an ECS machine will get
  33. //  pure red as F00 while an AGA as F00-F00 (that's FF0000), if you
  34. //  specified a different AGA red, F90000 the AGA will get it as
  35. //  F00-900 (RGB-RGB) while ECS-mode as F00, so, as you can note, for every
  36. //  monochrome ECS coordinate, AGA's can resolve 16 internal levels!
  37. //  So to specify a 24-bits color you have to write 2 words, first the MSB
  38. //  and then the LSB, note that the order it's very important 'coz Amiga
  39. //  automatically duplicates the MSB content into LSB for compatibility.
  40. //  The task is writing a twice long copper list, with doubled MOVE
  41. //  instructions, and between them poking BPLCON3 register.
  42. //  Building a copper list in C it's quite simple for the useful macros
  43. //  ready-made, in Amos I think there are no problems at all, the only
  44. //  thing to do, it's poking to 1 bit 9 in BPLCON3, when this bit's on
  45. //  an access to a normal color register will be on LSB, on the other hand
  46. //  when bit 9 is unset, (default) every color access will be on MSB,
  47. //  so old programs continue to work normaly with 12-bits colors!
  48. //  The correct procedure is:
  49. //  ---------------------------------------------------------
  50. //  ·copper-WAIT for beam coordinates
  51. //  ·unset bit 9 of BPLCON3
  52. //  ·copper-MOVE the 12-bits MSB-RGB into color word register
  53. //  ·set bit 9 of BPLCON3
  54. //  ·copper-MOVE the 12-bits LSB-RGB into color word register
  55. //  ---------------------------------------------------------
  56. //
  57. //  Stefano Peruzzi
  58. //  Medicine Dept.
  59. //  Padova University - Italy
  60. //  email: peru@maya.dei.unipd.it
  61. //
  62. //  PS) Let's support Amiga in scientific world, we need a lot of programs
  63. //      math, physics, molecular biology, genetics ....etc. in spare time
  64. //      I hope I will code something to fill up the gap.
  65. //      Thanx to the author of CPK modeller, go on developing.
  66. //
  67. //  Bye, Steve.
  68. //--------------------------------------------------------------------------
  69.  
  70. //----------  turn off SAS break control ----------
  71.   int CXBRK(void) {return(0);}
  72.   void chkabort(void) {return;}
  73. //---------- Standard Output ----------
  74.   char __stdiowin[]="CON:0/0/300/100/";
  75.   char __stdiov37[]="/AUTO/CLOSE/WAIT";
  76.  
  77. // If you can, use GST file, and compilation will speed up!
  78. #include <exec/types.h>
  79. #include <exec/memory.h>
  80. #include <graphics/gfxbase.h>
  81. #include <graphics/gfxmacros.h>
  82. #include <graphics/copper.h>
  83. #include <graphics/videocontrol.h>
  84. #include <intuition/intuition.h>
  85. #include <intuition/preferences.h>
  86. #include <hardware/custom.h>
  87. #include <libraries/dos.h>
  88. #include <stdlib.h>
  89. #include <clib/exec_protos.h>
  90. #include <clib/graphics_protos.h>
  91. #include <clib/intuition_protos.h>
  92. #include <clib/dos_protos.h>
  93.  
  94. // With "extern" I only declare libraries pointers, so SAS-C automagically
  95. // will open every library and will close on exit!
  96. extern  long  __oslibversion=39;
  97. extern struct GfxBase        *GfxBase;
  98. extern struct IntuitionBase  *IntuitionBase;
  99.  
  100. extern struct Custom far custom;
  101. struct Screen *screen=NULL;
  102. struct ViewPort *viewport;
  103.  
  104. void main(void);
  105. WORD Copper(void);
  106.  
  107. void main(void)
  108. {
  109.   // A simple screen ...
  110.   if(screen=OpenScreenTags(NULL,
  111.                            SA_Title,"That's Amiga Copper!",
  112.                            SA_LikeWorkbench,TRUE,
  113.                            TAG_DONE));
  114.     if(Copper())
  115.     {
  116.       // Let's wait a while ...
  117.       Delay(500);
  118.  
  119.       // OK, we leave ...
  120.       viewport=&screen->ViewPort;
  121.       if (NULL!=viewport->UCopIns)
  122.       {
  123.         FreeVPortCopLists(viewport);
  124.         RemakeDisplay();
  125.       }
  126.     }
  127.     CloseScreen(screen);
  128. }
  129.  
  130. WORD Copper(void)
  131. {
  132. // To build a 256 lines copper we need a pseudo 512 slots copper list,
  133. // 2 copper-MOVE's per color!
  134. #define NUMCOLORS 512
  135.  
  136. // A useful mask for bit 9 of BPLCON3
  137. UWORD loct=1<<9;
  138.  
  139. register USHORT i;
  140. WORD     ret=TRUE;
  141. struct   UCopList *uCopList=NULL;
  142. struct   TagItem  uCopTags[] ={{ VTAG_USERCLIP_SET,NULL},
  143.                                { VTAG_END_CM,NULL}};
  144.  
  145. // This color list has been generated automatically by Chroma.
  146. UWORD spectrum[]= {0xfff, 0xfff,
  147.                    0xfff, 0xffe,
  148.                    0xfff, 0xffd,
  149.                    0xfff, 0xffc,
  150.                    0xfff, 0xffb,
  151.                    0xfff, 0xffa,
  152.                    0xfff, 0xff9,
  153.                    0xfff, 0xff8,
  154.                    0xfff, 0xff7,
  155.                    0xfff, 0xff6,
  156.                    0xfff, 0xff5,
  157.                    0xfff, 0xff4,
  158.                    0xfff, 0xff3,
  159.                    0xfff, 0xff2,
  160.                    0xfff, 0xff1,
  161.                    0xfff, 0xff0,
  162.  
  163.                    0xffe, 0xfff,
  164.                    0xffe, 0xffe,
  165.                    0xffe, 0xffd,
  166.                    0xffe, 0xffc,
  167.                    0xffe, 0xffb,
  168.                    0xffe, 0xffa,
  169.                    0xffe, 0xff9,
  170.                    0xffe, 0xff8,
  171.                    0xffe, 0xff7,
  172.                    0xffe, 0xff6,
  173.                    0xffe, 0xff5,
  174.                    0xffe, 0xff4,
  175.                    0xffe, 0xff3,
  176.                    0xffe, 0xff2,
  177.                    0xffe, 0xff1,
  178.                    0xffe, 0xff0,
  179.  
  180.                    0xffd, 0xfff,
  181.                    0xffd, 0xffe,
  182.                    0xffd, 0xffd,
  183.                    0xffd, 0xffc,
  184.                    0xffd, 0xffb,
  185.                    0xffd, 0xffa,
  186.                    0xffd, 0xff9,
  187.                    0xffd, 0xff8,
  188.                    0xffd, 0xff7,
  189.                    0xffd, 0xff6,
  190.                    0xffd, 0xff5,
  191.                    0xffd, 0xff4,
  192.                    0xffd, 0xff3,
  193.                    0xffd, 0xff2,
  194.                    0xffd, 0xff1,
  195.                    0xffd, 0xff0,
  196.  
  197.                    0xffc, 0xfff,
  198.                    0xffc, 0xffe,
  199.                    0xffc, 0xffd,
  200.                    0xffc, 0xffc,
  201.                    0xffc, 0xffb,
  202.                    0xffc, 0xffa,
  203.                    0xffc, 0xff9,
  204.                    0xffc, 0xff8,
  205.                    0xffc, 0xff7,
  206.                    0xffc, 0xff6,
  207.                    0xffc, 0xff5,
  208.                    0xffc, 0xff4,
  209.                    0xffc, 0xff3,
  210.                    0xffc, 0xff2,
  211.                    0xffc, 0xff1,
  212.                    0xffc, 0xff0,
  213.  
  214.                    0xffb, 0xfff,
  215.                    0xffb, 0xffe,
  216.                    0xffb, 0xffd,
  217.                    0xffb, 0xffc,
  218.                    0xffb, 0xffb,
  219.                    0xffb, 0xffa,
  220.                    0xffb, 0xff9,
  221.                    0xffb, 0xff8,
  222.                    0xffb, 0xff7,
  223.                    0xffb, 0xff6,
  224.                    0xffb, 0xff5,
  225.                    0xffb, 0xff4,
  226.                    0xffb, 0xff3,
  227.                    0xffb, 0xff2,
  228.                    0xffb, 0xff1,
  229.                    0xffb, 0xff0,
  230.  
  231.                    0xffa, 0xfff,
  232.                    0xffa, 0xffe,
  233.                    0xffa, 0xffd,
  234.                    0xffa, 0xffc,
  235.                    0xffa, 0xffb,
  236.                    0xffa, 0xffa,
  237.                    0xffa, 0xff9,
  238.                    0xffa, 0xff8,
  239.                    0xffa, 0xff7,
  240.                    0xffa, 0xff6,
  241.                    0xffa, 0xff5,
  242.                    0xffa, 0xff4,
  243.                    0xffa, 0xff3,
  244.                    0xffa, 0xff2,
  245.                    0xffa, 0xff1,
  246.                    0xffa, 0xff0,
  247.  
  248.                    0xff9, 0xfff,
  249.                    0xff9, 0xffe,
  250.                    0xff9, 0xffd,
  251.                    0xff9, 0xffc,
  252.                    0xff9, 0xffb,
  253.                    0xff9, 0xffa,
  254.                    0xff9, 0xff9,
  255.                    0xff9, 0xff8,
  256.                    0xff9, 0xff7,
  257.                    0xff9, 0xff6,
  258.                    0xff9, 0xff5,
  259.                    0xff9, 0xff4,
  260.                    0xff9, 0xff3,
  261.                    0xff9, 0xff2,
  262.                    0xff9, 0xff1,
  263.                    0xff9, 0xff0,
  264.  
  265.                    0xff8, 0xfff,
  266.                    0xff8, 0xffe,
  267.                    0xff8, 0xffd,
  268.                    0xff8, 0xffc,
  269.                    0xff8, 0xffb,
  270.                    0xff8, 0xffa,
  271.                    0xff8, 0xff9,
  272.                    0xff8, 0xff8,
  273.                    0xff8, 0xff7,
  274.                    0xff8, 0xff6,
  275.                    0xff8, 0xff5,
  276.                    0xff8, 0xff4,
  277.                    0xff8, 0xff3,
  278.                    0xff8, 0xff2,
  279.                    0xff8, 0xff1,
  280.                    0xff8, 0xff0,
  281.  
  282.                    0xff7, 0xfff,
  283.                    0xff7, 0xffe,
  284.                    0xff7, 0xffd,
  285.                    0xff7, 0xffc,
  286.                    0xff7, 0xffb,
  287.                    0xff7, 0xffa,
  288.                    0xff7, 0xff9,
  289.                    0xff7, 0xff8,
  290.                    0xff7, 0xff7,
  291.                    0xff7, 0xff6,
  292.                    0xff7, 0xff5,
  293.                    0xff7, 0xff4,
  294.                    0xff7, 0xff3,
  295.                    0xff7, 0xff2,
  296.                    0xff7, 0xff1,
  297.                    0xff7, 0xff0,
  298.                    
  299.                    0xff6, 0xfff,
  300.                    0xff6, 0xffe,
  301.                    0xff6, 0xffd,
  302.                    0xff6, 0xffc,
  303.                    0xff6, 0xffb,
  304.                    0xff6, 0xffa,
  305.                    0xff6, 0xff9,
  306.                    0xff6, 0xff8,
  307.                    0xff6, 0xff7,
  308.                    0xff6, 0xff6,
  309.                    0xff6, 0xff5,
  310.                    0xff6, 0xff4,
  311.                    0xff6, 0xff3,
  312.                    0xff6, 0xff2,
  313.                    0xff6, 0xff1,
  314.                    0xff6, 0xff0,
  315.  
  316.                    0xff5, 0xfff,
  317.                    0xff5, 0xffe,
  318.                    0xff5, 0xffd,
  319.                    0xff5, 0xffc,
  320.                    0xff5, 0xffb,
  321.                    0xff5, 0xffa,
  322.                    0xff5, 0xff9,
  323.                    0xff5, 0xff8,
  324.                    0xff5, 0xff7,
  325.                    0xff5, 0xff6,
  326.                    0xff5, 0xff5,
  327.                    0xff5, 0xff4,
  328.                    0xff5, 0xff3,
  329.                    0xff5, 0xff2,
  330.                    0xff5, 0xff1,
  331.                    0xff5, 0xff0,
  332.  
  333.                    0xff4, 0xfff,
  334.                    0xff4, 0xffe,
  335.                    0xff4, 0xffd,
  336.                    0xff4, 0xffc,
  337.                    0xff4, 0xffb,
  338.                    0xff4, 0xffa,
  339.                    0xff4, 0xff9,
  340.                    0xff4, 0xff8,
  341.                    0xff4, 0xff7,
  342.                    0xff4, 0xff6,
  343.                    0xff4, 0xff5,
  344.                    0xff4, 0xff4,
  345.                    0xff4, 0xff3,
  346.                    0xff4, 0xff2,
  347.                    0xff4, 0xff1,
  348.                    0xff4, 0xff0,
  349.  
  350.                    0xff3, 0xfff,
  351.                    0xff3, 0xffe,
  352.                    0xff3, 0xffd,
  353.                    0xff3, 0xffc,
  354.                    0xff3, 0xffb,
  355.                    0xff3, 0xffa,
  356.                    0xff3, 0xff9,
  357.                    0xff3, 0xff8,
  358.                    0xff3, 0xff7,
  359.                    0xff3, 0xff6,
  360.                    0xff3, 0xff5,
  361.                    0xff3, 0xff4,
  362.                    0xff3, 0xff3,
  363.                    0xff3, 0xff2,
  364.                    0xff3, 0xff1,
  365.                    0xff3, 0xff0,
  366.  
  367.                    0xff2, 0xfff,
  368.                    0xff2, 0xffe,
  369.                    0xff2, 0xffd,
  370.                    0xff2, 0xffc,
  371.                    0xff2, 0xffb,
  372.                    0xff2, 0xffa,
  373.                    0xff2, 0xff9,
  374.                    0xff2, 0xff8,
  375.                    0xff2, 0xff7,
  376.                    0xff2, 0xff6,
  377.                    0xff2, 0xff5,
  378.                    0xff2, 0xff4,
  379.                    0xff2, 0xff3,
  380.                    0xff2, 0xff2,
  381.                    0xff2, 0xff1,
  382.                    0xff2, 0xff0,
  383.  
  384.                    0xff1, 0xfff,
  385.                    0xff1, 0xffe,
  386.                    0xff1, 0xffd,
  387.                    0xff1, 0xffc,
  388.                    0xff1, 0xffb,
  389.                    0xff1, 0xffa,
  390.                    0xff1, 0xff9,
  391.                    0xff1, 0xff8,
  392.                    0xff1, 0xff7,
  393.                    0xff1, 0xff6,
  394.                    0xff1, 0xff5,
  395.                    0xff1, 0xff4,
  396.                    0xff1, 0xff3,
  397.                    0xff1, 0xff2,
  398.                    0xff1, 0xff1,
  399.                    0xff1, 0xff0,
  400.  
  401.                    0xff0, 0xfff,
  402.                    0xff0, 0xffe,
  403.                    0xff0, 0xffd,
  404.                    0xff0, 0xffc,
  405.                    0xff0, 0xffb,
  406.                    0xff0, 0xffa,
  407.                    0xff0, 0xff9,
  408.                    0xff0, 0xff8,
  409.                    0xff0, 0xff7,
  410.                    0xff0, 0xff6,
  411.                    0xff0, 0xff5,
  412.                    0xff0, 0xff4,
  413.                    0xff0, 0xff3,
  414.                    0xff0, 0xff2,
  415.                    0xff0, 0xff1,
  416.                    0xff0, 0xff0};
  417.  
  418.   uCopList=(struct UCopList *)
  419.     AllocMem(sizeof(struct UCopList), MEMF_PUBLIC|MEMF_CLEAR);
  420.  
  421.   if (NULL == uCopList)
  422.      ret=NULL;
  423.   else
  424.   {
  425.     CINIT(uCopList, NUMCOLORS);
  426.     
  427.     // The core: copper list generation!
  428.     for (i=0; i<NUMCOLORS; i++)
  429.       {
  430.       // copper-WAIT for beam Y coordinate
  431.       CWAIT(uCopList,i,0);
  432.       // unset LOCT bit using copper
  433.       CMOVE(uCopList,custom.bplcon3,0);
  434.       // set 12-bits MSB in color register 0
  435.       CMOVE(uCopList,custom.color[0],spectrum[i]);
  436.       // set LOCT bit in BPLCON3
  437.       CMOVE(uCopList,custom.bplcon3,loct);
  438.       // set 12-bits LSB in color register 0
  439.       CMOVE(uCopList,custom.color[0],spectrum[++i]);
  440.       }
  441.     // that's enough
  442.     CEND(uCopList);
  443.  
  444.     viewport=&screen->ViewPort;
  445.     // Better forbid a while ...
  446.     Forbid();
  447.     viewport->UCopIns=uCopList;
  448.     Permit();
  449.     // We're to go!
  450.     (void) VideoControl(viewport->ColorMap,uCopTags);
  451.     RethinkDisplay();
  452.  
  453.     return(ret);
  454.   }
  455. }
  456.  
  457.