home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / software / sviluppo / powerd / source / dmod.d < prev    next >
Text File  |  2000-02-03  |  9KB  |  447 lines

  1. // view powerd binary module (#?.b) generated by powerd v0.12
  2.  
  3. PROC DisplayMODULE(mem:PTR TO CHAR)
  4.     DEF    ver,rev,count,nl,ml,namelist:PTR TO CHAR,type,flags,acount,rcount,l,offset,
  5.             base:PTR TO CHAR
  6.  
  7.     IF Long(mem)<>"DMOD"
  8.         PrintF('\s: unknown filetype','dmod')
  9.         RETURN
  10.     ENDIF
  11.     mem+=4                        // skip "DMOD"
  12.     ver:=Word(mem)
  13.     rev:=Word(mem+2)
  14.     mem+=4                        // skip ver,rev
  15.     PrintF('// requied version of powerd: v\d.\z\d[2]\n\n',ver,rev)
  16.  
  17.     IF Long(mem)="MODS"
  18.         PrintF('MODULE\t')
  19.         count:=Word(mem+4)
  20.         mem+=6
  21.         WHILE count
  22.             count--
  23.             nl:=Word(mem)
  24.             mem+=2
  25.             PrintF('''\s''',mem)
  26.             mem+=nl+1
  27.             IF Odd(mem) THEN mem++
  28.             IF CtrlC() THEN RETURN
  29.         EXITIF count=0 DO PrintF('\n\n')
  30.             PrintF(',\n\t\t\t')
  31.         ENDWHILE
  32.     ENDIF
  33.  
  34.     IF Long(mem)="CNST"                // constant list
  35.         PrintF('CONST\t')
  36.         count:=Word(mem+4)            // count of constants
  37.         ml:=Long(mem+6)
  38.         nl:=Long(mem+10)
  39.         mem+=14
  40.         namelist:=mem+ml
  41.         WHILE count
  42.             count--
  43.             PrintF('\s=',namelist)
  44.             type:=UByte(mem++)
  45.             flags:=UByte(mem++)
  46.             IF type=$ff
  47.                 PrintF('0')
  48.             ELSEIF type=8                // DT_DOUBLE
  49.                 PrintF('$\z\h[8].\z\h[8]',Long(mem),Long(mem+4))
  50.                 mem+=8
  51.             ELSEIF flags&%10            // S_TAG
  52.                 PrintF('$\h',Word(mem)|$80000000)
  53.                 mem+++
  54.             ELSEIF type=3                // DT_WORD
  55.                 PrintF('\d',Word(mem))
  56.                 mem+++
  57.             ELSE
  58.                 acount:=Long(mem)
  59.                 PrintF(IF acount>=-32768 AND acount<=32767 THEN '\d' ELSE '$\h',acount)
  60. //                PrintF(IF Long(mem)>=-32768 AND Long(mem)<=32767 THEN '\d' ELSE '$\h',Long(mem))
  61.                 mem+=4
  62.             ENDIF
  63.             namelist+=StrLen(namelist)+1
  64.             IF namelist[0]="\0" THEN namelist++
  65.             IF CtrlC() THEN RETURN
  66.         EXITIF count=0 DO PrintF('\n\n')
  67.             PrintF(',\n\t\t')
  68.         ENDWHILE
  69.         IF Odd(namelist) THEN namelist++
  70.         mem:=namelist
  71.     ENDIF
  72.  
  73.     IF Long(mem)="OBJC"            -> object list
  74.         ml:=Long(mem+4)
  75.         nl:=Long(mem+8)
  76.         acount:=Word(mem+12)
  77.         count:=Word(mem+14)
  78.         mem+=16
  79.         namelist:=mem+ml
  80.  
  81.         WHILE acount
  82.             mem,namelist:=LoadOBJECT(mem,namelist)
  83.             acount--
  84.             IF CtrlC() THEN RETURN
  85.         ENDWHILE
  86.  
  87.         IF Odd(namelist) THEN namelist++
  88.         mem:=namelist
  89.     ENDIF
  90.  
  91.     IF Long(mem)="#def"            -> #define list
  92.         count:=Word(mem+4)
  93.         acount:=Word(mem+6)
  94.         ml:=Long(mem+8)
  95.         nl:=Long(mem+12)
  96.         mem+=16
  97.         namelist:=mem+ml
  98.  
  99.         WHILE count
  100.             count--
  101.             PrintF('#define \s',namelist)
  102.             namelist+=mem[1]+1
  103.             l:=Word(mem+2)
  104.             acount:=mem[0]
  105.             mem+=4
  106.             IF acount
  107.                 PrintF('(')
  108.                 WHILE acount
  109.                     PrintF('\s',namelist)
  110.                     namelist+=mem[1]+1
  111.                     mem+++
  112.                     acount--
  113.                 EXITIF acount=0 DO PrintF(') ')
  114.                     PrintF(',')
  115.                 ENDWHILE
  116.             ELSE PrintF(' ')
  117.             PrintF('\s\n',namelist)
  118.             namelist+=l+1
  119.             IF CtrlC() THEN RETURN
  120.         ENDWHILE
  121.  
  122.         IF Odd(namelist) THEN namelist++
  123.         mem:=mem+nl
  124.     ENDIF
  125.  
  126.     IF Long(mem)="LIBR"            // function list
  127.         count:=Word(mem+4)        // count of functions
  128.         nl:=Word(mem+6)            // base name length
  129.         ml:=Long(mem+12)            // block length
  130.         mem+=16
  131.         base:=mem
  132.         mem+=nl
  133.         IF mem[0]="\0" THEN mem++
  134.         namelist:=mem+ml
  135.         PrintF('LIBRARY \s\n\t',base)
  136.  
  137.         WHILE count
  138.             count--
  139.             offset:=Word(mem)
  140.             acount:=mem[2]
  141.             rcount:=mem[3]
  142.             mem+=4
  143.             PrintF('\s(',namelist)
  144.             namelist+=StrLen(namelist)+1
  145.             WHILE acount
  146.                 acount--
  147.                 SELECT mem[2]
  148.                 CASE 0 TO 7;    PrintF('d\d',mem[2]&%111)
  149.                 CASE 8 TO 15;    PrintF('a\d',mem[2]&%111)
  150.                 CASE 16 TO 23;    PrintF('fp\d',mem[2]&%111)
  151.                 ENDSELECT
  152.                 type:=mem[0]
  153.                 flags:=mem[1]        // means default value set
  154.                 nl:=mem[3]
  155.                 mem+=4
  156.                 IF flags
  157.                     IF type=8
  158.                         PrintF('=$\z\h[8].\z\h[8]',Long(mem),Long(mem+4))
  159.                         mem+=8
  160.                     ELSE
  161.                         PrintF('=$\d',Long(mem))
  162.                         mem+=4
  163.                     ENDIF
  164.                 ENDIF
  165.                 IF type
  166.                     PrintF(':\s',TypeStr(type))
  167.                 ENDIF
  168.                 IF nl
  169.                     PrintF('\s',namelist)
  170.                     namelist+=nl+1
  171.                 ENDIF
  172.             EXITIF acount=0
  173.                 PrintF(',')
  174.             ENDWHILE
  175.             PrintF(')')
  176.  
  177.             IF rcount
  178.                 PrintF('(')
  179.                 WHILE rcount
  180.                     rcount--
  181.                     SELECT mem[2]
  182.                     CASE 0 TO 7;    PrintF('d\d',mem[2]&%111)
  183.                     CASE 8 TO 15;    PrintF('a\d',mem[2]&%111)
  184.                     CASE 16 TO 23;    PrintF('fp\d',mem[2]&%111)
  185.                     ENDSELECT
  186.                     type:=mem[0]
  187.                     nl:=mem[3]
  188.                     mem+=4
  189.                     IF type
  190.                         PrintF(':\s',TypeStr(type))
  191.                     ENDIF
  192.                     IF nl
  193.                         PrintF('\s',namelist)
  194.                         namelist+=nl+1
  195.                     ENDIF
  196.                 EXITIF rcount=0 DO PrintF(')')
  197.                     PrintF(',')
  198.                 ENDWHILE
  199.             ENDIF
  200.             PrintF('=\d',offset)
  201.             IF CtrlC() THEN RETURN
  202.         EXITIF count=0 DO PrintF('\n\n')
  203.             PrintF(',\n\t')
  204.         ENDWHILE
  205.         IF Odd(namelist) THEN namelist++
  206.         mem:=namelist
  207.     ENDIF
  208.  
  209.     IF Long(mem)="EXPR"            // external function list
  210.         count:=Word(mem+4)
  211.         ml:=Long(mem+10)
  212.         nl:=Long(mem+14)
  213.         mem+=18
  214.         namelist:=mem+ml
  215.  
  216.         WHILE count
  217.             count--
  218.             SELECT type:=mem[0]
  219.             CASE 11;    PrintF('EPROC')
  220.             CASE 13;    PrintF('LPROC')
  221.             CASE 14;    PrintF('RPROC')
  222.             ENDSELECT
  223.             PrintF(' \s(',namelist)
  224.             namelist+=StrLen(namelist)+1
  225.             flags:=mem[1]
  226.             acount:=mem[2]
  227.             rcount:=mem[3]
  228.             mem+=4
  229.             offset:=0
  230.             IF flags&%01
  231.                 offset:=namelist
  232.                 namelist+=StrLen(namelist)+1
  233.             ENDIF
  234.  
  235.             IF type=14
  236.                 IF flags&%10
  237.                     l:=namelist
  238.                     namelist+=StrLen(namelist)+1
  239.                 ENDIF
  240.             ENDIF
  241.  
  242.             WHILE acount
  243.                 acount--
  244.                 type:=mem[0]
  245.                 flags:=mem[1]
  246.                 SELECT mem[3]
  247.                 CASE 0 TO 7;    PrintF('d\d',mem[3]&%111)
  248.                 CASE 8 TO 15;    PrintF('a\d',mem[3]&%111)
  249.                 CASE 16 TO 23;    PrintF('fp\d',mem[3]&%111)
  250.                 DEFAULT;            PrintF('\c',"z"-acount)        // stack
  251.                 ENDSELECT
  252.                 mem+=4
  253.                 IF flags&%01
  254.                     IF type=8    // DT_DOUBLE
  255.                         PrintF('=$\z\h[8].\z\h[8]',Long(mem),Long(mem+4))
  256.                         mem+=8
  257.                     ELSE
  258.                         PrintF('=\d',Long(mem))
  259.                         mem+=4
  260.                     ENDIF
  261.                 ENDIF
  262.                 IF type
  263.                     PrintF(':\s',TypeStr(type))
  264.                     IF flags&%10
  265.                         PrintF('\s',namelist)
  266.                         namelist+=StrLen(namelist)+1
  267.                     ENDIF
  268.                 ENDIF
  269.             EXITIF acount=0
  270.                 PrintF(',')
  271.             ENDWHILE
  272.             PrintF(')')
  273.  
  274.             IF rcount
  275.                 PrintF('(')
  276.                 WHILE rcount
  277.                     rcount--
  278.                     type:=mem[0]
  279.                     SELECT mem[1]
  280.                     CASE 0 TO 7;    PrintF('d\d',mem[1]&%111)
  281.                     CASE 8 TO 15;    PrintF('a\d',mem[1]&%111)
  282.                     CASE 16 TO 23;    PrintF('fp\d',mem[1]&%111)
  283.                     ENDSELECT
  284.                     mem+++
  285.                     IF type THEN PrintF(':\s',TypeStr(type))
  286.                     IF type>=26 AND type<=28
  287.                         PrintF('\s',namelist)
  288.                         namelist+=StrLen(namelist)+1
  289.                     ENDIF
  290.                 EXITIF rcount=0 DO PrintF(')')
  291.                     PrintF(',')
  292.                 ENDWHILE
  293.             ENDIF
  294.  
  295.             IF offset THEN PrintF(' OF \s',offset)
  296.             IF CtrlC() THEN RETURN
  297.             PrintF('\n')
  298.         ENDWHILE
  299.         PrintF('\n')
  300.         IF Odd(namelist) THEN namelist++
  301.         mem+=nl
  302.     ENDIF
  303.  
  304.     IF Long(mem)="EDEF"
  305.         PrintF('EDEF\t')
  306.         count:=Word(mem+4)
  307.         ml:=Long(mem+6)
  308.         nl:=Long(mem+10)
  309.         mem+=14
  310.         namelist:=mem+ml
  311.  
  312.         WHILE count
  313.             count--
  314.             PrintF('\s',namelist)
  315.             namelist+=StrLen(namelist)+1
  316.             IF mem[0] THEN PrintF(':\s',TypeStr(mem[0]))
  317.             IF mem[1]
  318.                 PrintF('\s',namelist)
  319.                 namelist+=StrLen(namelist)+1
  320.             ENDIF
  321.             mem+++
  322.         EXITIF count=0 DO PrintF('\n\n')
  323.             PrintF(',\n\t\t')
  324.         ENDWHILE
  325.         mem+=nl
  326.     ENDIF
  327.  
  328.     IF Long(mem)="LINK"
  329.         PrintF('OPT\t')
  330.         count:=Word(mem+4)
  331.         mem:=mem+6
  332.         WHILE count
  333.             count--
  334.             nl:=Word(mem)
  335.             mem+++
  336.             PrintF('''\s''',mem)
  337.             mem:=mem+nl
  338.             IF Odd(nl) THEN mem++
  339.         EXITIF count=0 DO PrintF('\n')
  340.             PrintF(',\n\t\t')
  341.         ENDWHILE
  342.     ENDIF
  343.  
  344.     IF Long(mem)="HEAD"
  345.         nl:=Word(mem+4)
  346.         mem+=6
  347.         PrintF('OPT\tHEAD=''\s''\n',mem)
  348.         mem+=nl
  349.         IF Odd(nl) THEN mem++
  350.     ENDIF
  351.  
  352. ENDPROC
  353.  
  354. PROC LoadOBJECT(mem:PTR TO CHAR,nmem:PTR TO CHAR)(PTR TO CHAR,PTR TO CHAR)
  355.     IF mem[0]=0
  356.         PrintF('OBJECT \s',nmem)
  357.         nmem+=mem[1]+1
  358.         IF mem[2]
  359.             PrintF(' OF \s\n',nmem)
  360.             nmem+=mem[2]+1
  361.         ELSE PrintF('\n')
  362.         mem+=8
  363.         WHILE mem[0]=1
  364.             mem,nmem:=LoadOBJECT(mem,nmem)
  365.         EXITIF mem[0]<>1 DO PrintF('\n\n')
  366.             PrintF(',\n')
  367.         ENDWHILE
  368.     ELSEIF mem[0]=1
  369.         PrintF('\t\s',nmem)
  370.         nmem+=mem[1]+1
  371.         IF Word(mem+6) THEN PrintF('[\d]',Word(mem+6))
  372.         PrintF(':\s',TypeStr(mem[2]))
  373.         IF mem[5]
  374.             PrintF('\s',nmem)
  375.             nmem+=mem[5]+1
  376.         ENDIF
  377.         mem+=10
  378.     ENDIF
  379. ENDPROC mem,nmem
  380.  
  381. PROC TypeStr(type)(PTR TO CHAR)
  382.     DEF    str:PTR TO CHAR
  383.     SELECT type
  384.     CASE 1;    str:='LONG'
  385.     CASE 2;    str:='ULONG'
  386.     CASE 3;    str:='WORD'
  387.     CASE 4;    str:='UWORD'
  388.     CASE 5;    str:='BYTE'
  389.     CASE 6;    str:='UBYTE'
  390.     CASE 7;    str:='FLOAT'
  391.     CASE 8;    str:='DOUBLE'
  392.     CASE 9;    str:='BOOL'
  393.     CASE 10;    str:='PTR TO LONG'
  394.     CASE 11;    str:='PTR TO ULONG'
  395.     CASE 12;    str:='PTR TO WORD'
  396.     CASE 13;    str:='PTR TO UWORD'
  397.     CASE 14;    str:='PTR TO BYTE'
  398.     CASE 15;    str:='PTR TO UBYTE'
  399.     CASE 16;    str:='PTR TO FLOAT'
  400.     CASE 17;    str:='PTR TO DOUBLE'
  401.     CASE 18;    str:='PTR TO PTR TO LONG'
  402.     CASE 19;    str:='PTR TO PTR TO ULONG'
  403.     CASE 20;    str:='PTR TO PTR TO WORD'
  404.     CASE 21;    str:='PTR TO PTR TO UWORD'
  405.     CASE 22;    str:='PTR TO PTR TO BYTE'
  406.     CASE 23;    str:='PTR TO PTR TO UBYTE'
  407.     CASE 24;    str:='PTR TO PTR TO FLOAT'
  408.     CASE 25;    str:='PTR TO PTR TO DOUBLE'
  409.     CASE 26;    str:=NIL
  410.     CASE 27;    str:='PTR TO '
  411.     CASE 28;    str:='PTR TO PTR TO '
  412.     CASE 32;    str:='PTR'
  413.     CASE 33;    str:='PTR'
  414.     CASE 34;    str:='LIST OF '
  415.     CASE 35;    str:='LIST OF LONG'
  416.     CASE 36;    str:='LIST OF ULONG'
  417.     CASE 37;    str:='LIST OF WORD'
  418.     CASE 38;    str:='LIST OF UWORD'
  419.     CASE 39;    str:='LIST OF BYTE'
  420.     CASE 40;    str:='LIST OF UBYTE'
  421.     CASE 41;    str:='LIST OF FLOAT'
  422.     CASE 42;    str:='LIST OF DOUBLE'
  423.     DEFAULT;    str:='VOID'
  424.     ENDSELECT
  425. ENDPROC str
  426.  
  427. MODULE    'exec/memory'
  428.  
  429. ENUM    SOURCE
  430.  
  431. PROC main()
  432.     DEF    rda,args=[0,0]:LONG,l,m:PTR TO CHAR,f
  433.     IF rda:=ReadArgs('SOURCE/A',args,NIL)
  434.         l:=FileLength(args[SOURCE])
  435.         IF f:=Open(args[SOURCE],OLDFILE)
  436.             IF m:=AllocMem(l+8,MEMF_PUBLIC|MEMF_CLEAR)
  437.                 IF Read(f,m,l)=l
  438.                     DisplayMODULE(m)
  439.                 ELSE PrintFault(IOErr(),'dmod')
  440.                 FreeMem(m,l+8)
  441.             ELSE PrintF('\s: not enough memory\n','dmod')
  442.             Close(f)
  443.         ELSE PrintFault(IOErr(),'dmod')
  444.         FreeArgs(rda)
  445.     ELSE PrintFault(IOErr(),'dmod')
  446. ENDPROC
  447.