home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 127.lha / copper.c < prev    next >
C/C++ Source or Header  |  1986-11-20  |  15KB  |  446 lines

  1. /****************************************************************************
  2. *                                        *    
  3. *                              Copper Snooper                    *    
  4. *                                                      *
  5. *                 Copyright 1986 by The 4th Works, Inc.            *
  6. *                                        *    
  7. *                    written by:                    *    
  8. *                    Steve Ahlstrom                    *    
  9. *                    Dan Moore                    *    
  10. *                                        *    
  11. *                                        *    
  12. *     This program may be redistributed only with the permission of        *    
  13. *     one or both of the authors and with this header intact.            *    
  14. *                                        *    
  15. *    --------------------------------------------------------        *    
  16. *                                        *    
  17. *     This program will bring up a high resolution interlaced screen        *    
  18. *     part way down the video display and in front of the WorkBench        *    
  19. *     screen.  It will then write a commented listing of the Copper        *    
  20. *     list for the current display to the currently logged drive.        *    
  21. *     This file is named Copper.Listing.   If you wish to disassemble       *
  22. *     a WorkBench Copper List change the value of the MYSCREEN define       *
  23. *     to 0 (zero).                                *
  24. *                                        *
  25. *     Compiled with Manx Aztec C.  The makefile for this program is        *
  26. *     below -- it presumes you have created a precompiled header file       *
  27. *     named INCLUDES.PRE.                            *
  28. *                                             *
  29. *     ---------------------------------------------------------------       *
  30. *                                             *
  31. *     .c.o:                                    *
  32. *                                             *    
  33. *    cc +IIncludes.pre -o $@ $*.c                        *
  34. *                                        *
  35. *    copper: copper.o                            *
  36. *        ln copper.o -o copper -lc                    *    
  37. *                                        *
  38. *    copper.o: copper.c                            *
  39. *        cc +IIncludes.pre -Z9000 -o copper.o copper.c            *
  40. *                                        *
  41. ****************************************************************************/
  42.  
  43.  
  44. /****************************************************************************
  45. *                                        *    
  46. *                           I N C L U D E S                                 * 
  47. *                                        *
  48. ****************************************************************************/
  49.  
  50. #include "stdio.h"
  51.  
  52. #include "exec/types.h"
  53. #include "intuition/intuition.h"
  54. #include "libraries/dos.h"
  55. #include "defines.h"
  56. #include "graphics/copper.h"
  57.  
  58. /* Set this to non-zero to use a custom screen; 0 for WorkBench screen */
  59. #define MYSCREEN 1
  60.  
  61. /****************************************************************************
  62. *                                        *    
  63. *           I N T U I T I O N   G L O B A L   V A R I A B L E S             *
  64. *                                        *
  65. ****************************************************************************/
  66.  
  67. struct IntuitionBase *IntuitionBase;
  68. struct GfxBase         *GfxBase;
  69. struct Screen *Screen;
  70. struct cprlist *CopList;
  71.  
  72. FILE *dest;
  73.  
  74. char copyright[] = "Copper Snooper\nCopyright 1986 by The 4th Works, Inc.\n";
  75. char nv[] = "NOT VALID";
  76.  
  77. char *regs[] = {"BLTDDAT: Blitter destination early read (dummy address)",
  78.         "DMACONR: DMA ctrl (and blitter status) read",    
  79.         "VPORS:   Read vert most sig. bit (and frame flop)",
  80.         "VHPOSR:  Read vert and horz pos. of beam",
  81.         "DSKDATR: Disk data early read (dummy address)",
  82.         "JOY0DAT: Joystick/mouse 0 data (vert, horz)",
  83.         "JOY1DAT: Joystick/mouse 1 data (vert, horz)",
  84.         "CLXDAT:  Collision data reg. (read and clear)",
  85.         "ADKCONR: Audio, disk ctrl reg. read",
  86.         "POT0DAT: Pot counter pair 0 data (vert, horz)",
  87.         "POT1DAT: Pot counter pair 1 data (vert, horz)",
  88.         "POTINP:  Pot pin data read",
  89.         "SERDATR: Serial port data and status read",
  90.         "DSKBYTR: Disk data byte and status read",
  91.         "INTENAR: Interrupt enable bits read",
  92.         "INTREQR: Interrupt request bits read",
  93.         "DSKPTH:  Disk pointer (high 3 bits)",
  94.         "DSKPTL:  Disk pointer (low 15 bits)",
  95.         "DSKLEN:  Disk length",
  96.         "DSKDAT:  Disk DMA data write",
  97.         "REFPTR:  Refresh pointer",
  98.         "VPOSW:   Write vert most sig. bit (and frame flop)",
  99.         "VHPOSW:  Write vert and horz pos. of beam",
  100.         "COPCON:  Coprocessor ctrl reg. (CDANG)",
  101.         "SERDAT:  Serial port data and stop bits write",
  102.         "SERPER:  Serial port period and ctrl",
  103.         "POTGO:   Pot count start, pot pin drive enable and data",
  104.         "JOYTEST: Write to all 4 joystick/mouse counters at once",
  105.         "STREQU:  Strobe for horz sync with VB and EQU",
  106.         "STRVBL:  Strobe for horz sync with VB (vertical blank)",
  107.         "STRHOR:  Strobe for horz sync",
  108.         "STRLONG: Strobe for identification of long horz line",
  109.         "BLTCON0: Blitter ctrl reg. 0",
  110.         "BLTCON1: Blitter ctrl reg. 1",
  111.         "BLTAFWM: Blitter first word mask for source A",
  112.         "BLTALWM: Blitter last word mask for source A",        
  113.         "BLPCPTH: Blitter pointer to source C (high 3 bits)",
  114.         "BLTCPTL: Blitter pointer to source C (low 15 bits)",
  115.         "BLTBPTH: Blitter pointer to source B (high 3 bits)",
  116.         "BLTBPTL: Blitter pointer to source B (low 15 bits)",
  117.         "BLTAPTH: Blitter pointer to source A (high 3 bits)",
  118.         "BLTAPTL: Blitter pointer to source A (low 15 bits)",
  119.         "BLTDPTH: Blitter pointer to source D (hi 3 bits)",
  120.         "BLTDPTL: Blitter pointer to source D (low 15 bits)",
  121.         "BLTSIZE: Blitter start and size (window width, height",
  122.         nv,    
  123.         nv,    
  124.         nv,
  125.         "BLTCMOD: Blitter modulo for source C",
  126.         "BLTBMOD: Blitter modulo for source B",
  127.         "BLTAMOD: Blitter modulo for source A",
  128.         "BLTDMOD: Blitter modulo for source D",
  129.         nv,    
  130.         nv,    
  131.         nv,    
  132.         nv,
  133.         "BLTCDAT: Blitter source C data reg.",
  134.         "BLTBDAT: Blitter source B data reg.",
  135.         "BLTADAT: Blitter source A data reg.",
  136.         nv,
  137.         nv,
  138.         nv,    
  139.         nv,    
  140.         "DSKSYNC: Disk sync pattern reg. for disk read",
  141.         "COP1LCH: Coprocessor first location reg. (high 3 bits)",
  142.         "COP1LCL: Coprocessor first location reg. (low 15 bits)",
  143.         "COP2LCH: Coprocessor second location reg. (high 3 bits)",
  144.         "COP2LCL: Coprocessor second location reg. (low 15 bits)",        
  145.         "COPJMP1: Coprocessor restart at first location",
  146.         "COPJMP2: Coprocessor restart at second location",
  147.         "COPINS:  Coprocessor instruction fetch identify",
  148.         "DIWSTRT: Display window start (upper left vert-horz pos)",
  149.         "DIWSTOP: Display window stop (lower right vert-horz pos)",
  150.         "DDFSTRT: Display bit plane data fetch start (horz pos)",
  151.         "DDFSTOP: Display bit plane data fetch stop (horz pos)",
  152.         "DMACON:  DMA ctrl write (clear or set)",
  153.         "CLXCON:  Collision ctrl",
  154.         "INTENA:  Interrupt enable bits (clear or set)",
  155.         "INTREQ:  Interrupt request bits (clear or set)",
  156.         "ADKCON:  Audio, disk, UART ctrl",
  157.         "AUD0LCH: Audio channel 0 location (high 3 bits)",
  158.         "AUD0LCL: Audio channel 0 location (low 15 bits)",
  159.         "AUD0LEN: Audio channel 0 length",
  160.         "AUD0PER: Audio channel 0 period",    
  161.         "AUD0VOL: Audio channel 0 volume",
  162.         "AUD0DAT: Audio channel 0 data",
  163.         nv,    
  164.         nv,
  165.         "AUD1LCH: Audio channel 1 location (high 3 bits)",
  166.         "AUD1LCL: Audio channel 1 location (low 15 bits)",
  167.         "AUD1LEN: Audio channel 1 length",
  168.         "AUD1PER: Audio channel 1 period",    
  169.         "AUD1VOL: Audio channel 1 volume",
  170.         "AUD1DAT: Audio channel 1 data",
  171.         nv,    
  172.         nv,
  173.         "AUD2LCH: Audio channel 2 location (high 3 bits)",
  174.         "AUD2LCL: Audio channel 2 location (low 15 bits)",
  175.         "AUD2LEN: Audio channel 2 length",
  176.         "AUD2PER: Audio channel 2 period",    
  177.         "AUD2VOL: Audio channel 2 volume",
  178.         "AUD2DAT: Audio channel 2 data",
  179.         nv,    
  180.         nv,
  181.         "AUD3LCH: Audio channel 3 location (high 3 bits)",
  182.         "AUD3LCL: Audio channel 3 location (low 15 bits)",
  183.         "AUD3LEN: Audio channel 3 length",
  184.         "AUD3PER: Audio channel 3 period",    
  185.         "AUD3VOL: Audio channel 3 volume",
  186.         "AUD3DAT: Audio channel 3 data",
  187.         nv,    
  188.         nv,
  189.         "BPL1PTH: Bit plane 1 pointer (high 3 bits)",
  190.         "BPL1PTL: Bit plane 1 pointer (low 15 bits)",
  191.         "BPL2PTH: Bit plane 2 pointer (high 3 bits)",
  192.         "BPL2PTL: Bit plane 2 pointer (low 15 bits)",
  193.         "BPL3PTH: Bit plane 3 pointer (high 3 bits)",
  194.         "BPL3PTL: Bit plane 3 pointer (low 15 bits)",
  195.         "BPL4PTH: Bit plane 4 pointer (high 3 bits)",
  196.         "BPL4PTL: Bit plane 4 pointer (low 15 bits)",
  197.         "BPL5PTH: Bit plane 5 pointer (high 3 bits)",
  198.         "BPL5PLT: Bit plane 5 pointer (low 15 bits)",
  199.         "BPL6PTH: Bit plane 6 pointer (high 3 bits)",
  200.         "BPL6PTL: Bit plane 6 pointer (low 15 bits)",
  201.         nv,    
  202.         nv,    
  203.         nv,    
  204.         nv,
  205.         "BPLCON0: Bit plane ctrl reg. (misc ctrl bits)",
  206.         "BPLCON1: Bit plane ctrl reg. (scroll value PF1, PF2)",
  207.         "BPLCON2: Bit plane ctrl reg. (priority ctrl)",
  208.         nv,
  209.         "BPL1MOD: Bit plane modulo (odd planes)",
  210.         "BPL2MOD: Bit plane modulo (even planes)",
  211.         nv,    
  212.         nv,
  213.         "BPL1DAT: Bit plane 1 data (parallel to serial convert)",
  214.         "BPL2DAT: Bit plane 2 data (parallel to serial convert)",
  215.         "BPL3DAT: Bit plane 3 data (parallel to serial convert)",
  216.         "BPL4DAT: Bit plane 4 data (parallel to serial convert)",
  217.         "BLP5DAT: Bit plane 5 data (parallel to serial convert)",
  218.         "BPL6DAT: Bit plane 6 data (parallel to serial convert)",
  219.         nv,    
  220.         nv,
  221.         "SPR0PTH: Sprite 0 pointer (high 3 bits)",
  222.         "SPR0PTL: Sprite 0 pointer (low 15 bits)",
  223.         "SPR1PTH: Sprite 1 pointer (high 3 bits)",
  224.         "SPR1PTL: Sprite 1 pointer (low 15 bits)",
  225.         "SPR2PTH: Sprite 2 pointer (high 3 bits)",
  226.         "SPR2PTL: Sprite 2 pointer (low 15 bits)",
  227.         "SPR3PTH: Sprite 3 pointer (high 3 bits)",
  228.         "SPR3PTL: Sprite 3 pointer (low 15 bits)",
  229.         "SPR4PTH: Sprite 4 pointer (high 3 bits)",
  230.         "SPR4PTL: Sprite 4 pointer (low 15 bits)",
  231.         "SPR5PTH: Sprite 5 pointer (high 3 bits)",
  232.         "SPR5PTL: Sprite 5 pointer (low 15 bits)",
  233.         "SPR6PTH: Sprite 6 pointer (high 3 bits)",
  234.         "SPR6PTL: Sprite 6 pointer (low 15 bits)",
  235.         "SPR7PTH: Sprite 7 pointer (high 3 bits)",
  236.         "SPR7PTL: Sprite 7 pointer (low 15 bits)",
  237.         "SPR0POS: Sprite 0 vert-horz start pos. data",
  238.         "SPR0CTL: Sprite 0 vert stop pos. and ctrl data",
  239.         "SPR0DATA:Sprite 0 image data reg. A",
  240.         "SPR0DATB:Sprite 0 image data reg. B",        
  241.         "SPR1POS: Sprite 1 vert-horz start pos. data",
  242.         "SPR1CTL: Sprite 1 vert stop pos. and ctrl data",
  243.         "SPR1DATA:Sprite 1 image data reg. A",
  244.         "SPR1DATB:Sprite 1 image data reg. B",        
  245.         "SPR2POS: Sprite 2 vert-horz start pos. data",
  246.         "SPR2CTL: Sprite 2 vert stop pos. and ctrl data",
  247.         "SPR2DATA:Sprite 2 image data reg. A",
  248.         "SPR2DATB:Sprite 2 image data reg. B",        
  249.         "SPR3POS: Sprite 3 vert-horz start pos. data",
  250.         "SPR3CTL: Sprite 3 vert stop pos. and ctrl data",
  251.         "SPR3DATA:Sprite 3 image data reg. A",
  252.         "SPR3DATB:Sprite 3 image data reg. B",        
  253.         "SPR4POS: Sprite 4 vert-horz start pos. data",
  254.         "SPR4CTL: Sprite 4 vert stop pos. and ctrl data",
  255.         "SPR4DATA:Sprite 4 image data reg. A",
  256.         "SPR4DATB:Sprite 4 image data reg. B",        
  257.         "SPR5POS: Sprite 5 vert-horz start pos. data",
  258.         "SPR5CTL: Sprite 5 vert stop pos. and ctrl data",
  259.         "SPR5DATA:Sprite 5 image data reg. A",
  260.         "SPR5DATB:Sprite 5 image data reg. B",        
  261.         "SPR6POS: Sprite 6 vert-horz start pos. data",
  262.         "SPR6CTL: Sprite 6 vert stop pos. and ctrl data",
  263.         "SPR6DATA:Sprite 6 image data reg. A",
  264.         "SPR6DATB:Sprite 6 image data reg. B",        
  265.         "SPR7POS: Sprite 7 vert-horz start pos.",
  266.         "SPR7CTL: Sprite 7 vert stop pos. and ctrl data",
  267.         "SPR7DATA:Sprite 7 image data reg. A",
  268.         "SPR7DATB:Sprite 7 image data reg. B",        
  269.         "COLOR00: Color table 00",
  270.         "COLOR01: Color table 01",
  271.         "COLOR02: Color table 02",
  272.         "COLOR03: Color table 03",
  273.         "COLOR04: Color table 04",
  274.         "COLOR05: Color table 05",
  275.         "COLOR06: Color table 06",
  276.         "COLOR07: Color table 07",
  277.         "COLOR08: Color table 08",
  278.         "COLOR09: Color table 09",
  279.         "COLOR10: Color table 10",
  280.         "COLOR11: Color table 11",
  281.         "COLOR12: Color table 12",
  282.         "COLOR13: Color table 13",
  283.         "COLOR14: Color table 14",
  284.         "COLOR15: Color table 15",
  285.         "COLOR16: Color table 16",
  286.         "COLOR17: Color table 17",
  287.         "COLOR18: Color table 18",
  288.         "COLOR19: Color table 19",
  289.         "COLOR20: Color table 20", 
  290.         "COLOR21: Color table 21",
  291.         "COLOR22: Color table 22",
  292.         "COLOR23: Color table 23",
  293.         "COLOR24: Color table 24",
  294.         "COLOR25: Color table 25",
  295.         "COLOR26: Color table 26",
  296.         "COLOR27: Color table 27",
  297.         "COLOR28: Color table 28",
  298.         "COLOR29: Color table 29",
  299.         "COLOR30: Color table 30",
  300.         "COLOR31: Color tabel 31"
  301.            };        
  302.  
  303. /***********************************************************************/
  304.  
  305. VOID
  306. Disassemble(clist)
  307. struct cprlist *clist;
  308. {
  309.      register int i = clist->MaxCount;
  310.      register WORD *c_data = (WORD *) clist->start, cmd, vp, hp, ve, he;
  311.  
  312.      while (i--) {
  313.          if (((cmd = *c_data++) & 0x01) == 0) { /* move command */
  314.              cmd &= 0x01fe;
  315.         fprintf(dest,"MOVE $%04x to $%03x (%s)\n", *c_data++, cmd, regs[cmd/2]); 
  316.     }    
  317.         else { /* either a skip or a wait */
  318.         vp = (cmd & 0xff00) >> 8;
  319.         hp = (cmd & 0x00fe) >> 1;
  320.         ve = (*c_data & 0x7f00) >> 8;
  321.         he = (*c_data & 0x00fe) >> 1;
  322.  
  323.         if (*c_data & 0x01) /* wait or skip */
  324.             fprintf(dest,"SKIP");
  325.         else
  326.             fprintf(dest,"WAIT");
  327.  
  328.         if (ve)
  329.             fprintf(dest," vp = %d ($%x)", vp, ve);
  330.  
  331.         if (he)
  332.             fprintf(dest," hp = %d ($%x)", hp, he);
  333.  
  334.         if ((*c_data++ & 0x8000) == 0)
  335.             fprintf(dest," blitter done");
  336.         fprintf(dest,"\n");
  337.     }    
  338.      }
  339. }
  340.  
  341. /****************************************************************************/
  342.  
  343. VOID
  344. Open_The_Screen()
  345. {
  346.      struct NewScreen NS;
  347.      int i;
  348.      
  349.      IntuitionBase = (struct IntuitionBase *)   
  350.                    OpenLibrary("intuition.library", INTUITION_REV);
  351.      if(!IntuitionBase)
  352.           exit(0);
  353.  
  354.      NS.LeftEdge       =   0;
  355.      NS.TopEdge        =   100;
  356.      NS.Width          =   640;
  357.      NS.Height         =   400;
  358.      NS.Depth           =   1;    
  359.      NS.DetailPen      =   0;
  360.      NS.BlockPen       =   1;
  361.      NS.ViewModes      = HIRES | LACE;    
  362.      NS.Type           = CUSTOMSCREEN;
  363.      NS.Font           = NULL;
  364.      NS.DefaultTitle   = (UBYTE *) "Copyright 1986 by The 4th Works, Inc.";
  365.      NS.Gadgets           = NULL;
  366.      NS.CustomBitMap   = NULL;
  367.      
  368.      if((Screen = (struct Screen *) OpenScreen(&NS)) == NULL)
  369.           exit(0);
  370. }
  371.  
  372. /****************************************************************************/
  373.  
  374. VOID
  375. Close_The_Screen()
  376. {
  377.     CloseScreen(Screen);
  378.     CloseLibrary(IntuitionBase);
  379. }
  380.  
  381. /****************************************************************************/
  382.         
  383. int
  384. main()
  385. {
  386.      int i;
  387.  
  388.      puts(copyright);
  389.      
  390.      GfxBase = (struct GfxBase *)
  391.            OpenLibrary("graphics.library", INTUITION_REV);
  392.      if(!GfxBase)
  393.     return(FALSE);
  394.  
  395. #if MYSCREEN
  396.  
  397.                  /*-----------------------------*/
  398.  
  399.      Open_The_Screen(); /* Comment this out if you want to disassemble */
  400.                  /* the Copper List for a Workbench screen      */
  401.  
  402.                  /*-----------------------------*/
  403.  
  404. #endif
  405.  
  406.  
  407.      dest = fopen("copper.listing", "w");
  408.  
  409.      fprintf(dest, copyright);    
  410.  
  411.      CopList = GfxBase->ActiView->LOFCprList;    
  412.      fprintf(dest,"\nCopper dissassembly\nStart Addr = $%lx Size = $%x\n\n", CopList->start, CopList->MaxCount);          
  413.  
  414.      Disassemble(CopList);
  415.      
  416.      CopList = GfxBase->ActiView->SHFCprList;
  417.      
  418.      if (CopList) {
  419.     fprintf(dest,"\n\n *** SECOND COPPER LIST ***\n");
  420.     fprintf(dest,"Start Addr = $%lx Size = $%x\n\n", CopList->start, CopList->MaxCount);
  421.     Disassemble(CopList);
  422.      }
  423.      else
  424.     fprintf(dest,"\n\n *** No second Copper List ***\n\n");
  425.  
  426.      fprintf(dest,"\nEnd of Copper List\n");
  427.     
  428. #if MYSCREEN 
  429.  
  430.                  /*-----------------------------*/
  431.  
  432.      Close_The_Screen(); /* Comment this out if you want to disassemble */
  433.                  /* the Copper List for a Workbench screen      */
  434.  
  435.                  /*-----------------------------*/
  436.                  
  437. #endif
  438.     
  439.     CloseLibrary(GfxBase);
  440.  
  441.     fprintf(dest, "\n\n");
  442.     
  443.     fclose(dest);
  444.  
  445.