home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Enigma Amiga Life 109
/
EnigmaAmiga109CD.iso
/
software
/
sviluppo
/
powerd
/
source
/
dmod.d
< prev
next >
Wrap
Text File
|
2000-02-03
|
9KB
|
447 lines
// view powerd binary module (#?.b) generated by powerd v0.12
PROC DisplayMODULE(mem:PTR TO CHAR)
DEF ver,rev,count,nl,ml,namelist:PTR TO CHAR,type,flags,acount,rcount,l,offset,
base:PTR TO CHAR
IF Long(mem)<>"DMOD"
PrintF('\s: unknown filetype','dmod')
RETURN
ENDIF
mem+=4 // skip "DMOD"
ver:=Word(mem)
rev:=Word(mem+2)
mem+=4 // skip ver,rev
PrintF('// requied version of powerd: v\d.\z\d[2]\n\n',ver,rev)
IF Long(mem)="MODS"
PrintF('MODULE\t')
count:=Word(mem+4)
mem+=6
WHILE count
count--
nl:=Word(mem)
mem+=2
PrintF('''\s''',mem)
mem+=nl+1
IF Odd(mem) THEN mem++
IF CtrlC() THEN RETURN
EXITIF count=0 DO PrintF('\n\n')
PrintF(',\n\t\t\t')
ENDWHILE
ENDIF
IF Long(mem)="CNST" // constant list
PrintF('CONST\t')
count:=Word(mem+4) // count of constants
ml:=Long(mem+6)
nl:=Long(mem+10)
mem+=14
namelist:=mem+ml
WHILE count
count--
PrintF('\s=',namelist)
type:=UByte(mem++)
flags:=UByte(mem++)
IF type=$ff
PrintF('0')
ELSEIF type=8 // DT_DOUBLE
PrintF('$\z\h[8].\z\h[8]',Long(mem),Long(mem+4))
mem+=8
ELSEIF flags&%10 // S_TAG
PrintF('$\h',Word(mem)|$80000000)
mem+++
ELSEIF type=3 // DT_WORD
PrintF('\d',Word(mem))
mem+++
ELSE
acount:=Long(mem)
PrintF(IF acount>=-32768 AND acount<=32767 THEN '\d' ELSE '$\h',acount)
// PrintF(IF Long(mem)>=-32768 AND Long(mem)<=32767 THEN '\d' ELSE '$\h',Long(mem))
mem+=4
ENDIF
namelist+=StrLen(namelist)+1
IF namelist[0]="\0" THEN namelist++
IF CtrlC() THEN RETURN
EXITIF count=0 DO PrintF('\n\n')
PrintF(',\n\t\t')
ENDWHILE
IF Odd(namelist) THEN namelist++
mem:=namelist
ENDIF
IF Long(mem)="OBJC" -> object list
ml:=Long(mem+4)
nl:=Long(mem+8)
acount:=Word(mem+12)
count:=Word(mem+14)
mem+=16
namelist:=mem+ml
WHILE acount
mem,namelist:=LoadOBJECT(mem,namelist)
acount--
IF CtrlC() THEN RETURN
ENDWHILE
IF Odd(namelist) THEN namelist++
mem:=namelist
ENDIF
IF Long(mem)="#def" -> #define list
count:=Word(mem+4)
acount:=Word(mem+6)
ml:=Long(mem+8)
nl:=Long(mem+12)
mem+=16
namelist:=mem+ml
WHILE count
count--
PrintF('#define \s',namelist)
namelist+=mem[1]+1
l:=Word(mem+2)
acount:=mem[0]
mem+=4
IF acount
PrintF('(')
WHILE acount
PrintF('\s',namelist)
namelist+=mem[1]+1
mem+++
acount--
EXITIF acount=0 DO PrintF(') ')
PrintF(',')
ENDWHILE
ELSE PrintF(' ')
PrintF('\s\n',namelist)
namelist+=l+1
IF CtrlC() THEN RETURN
ENDWHILE
IF Odd(namelist) THEN namelist++
mem:=mem+nl
ENDIF
IF Long(mem)="LIBR" // function list
count:=Word(mem+4) // count of functions
nl:=Word(mem+6) // base name length
ml:=Long(mem+12) // block length
mem+=16
base:=mem
mem+=nl
IF mem[0]="\0" THEN mem++
namelist:=mem+ml
PrintF('LIBRARY \s\n\t',base)
WHILE count
count--
offset:=Word(mem)
acount:=mem[2]
rcount:=mem[3]
mem+=4
PrintF('\s(',namelist)
namelist+=StrLen(namelist)+1
WHILE acount
acount--
SELECT mem[2]
CASE 0 TO 7; PrintF('d\d',mem[2]&%111)
CASE 8 TO 15; PrintF('a\d',mem[2]&%111)
CASE 16 TO 23; PrintF('fp\d',mem[2]&%111)
ENDSELECT
type:=mem[0]
flags:=mem[1] // means default value set
nl:=mem[3]
mem+=4
IF flags
IF type=8
PrintF('=$\z\h[8].\z\h[8]',Long(mem),Long(mem+4))
mem+=8
ELSE
PrintF('=$\d',Long(mem))
mem+=4
ENDIF
ENDIF
IF type
PrintF(':\s',TypeStr(type))
ENDIF
IF nl
PrintF('\s',namelist)
namelist+=nl+1
ENDIF
EXITIF acount=0
PrintF(',')
ENDWHILE
PrintF(')')
IF rcount
PrintF('(')
WHILE rcount
rcount--
SELECT mem[2]
CASE 0 TO 7; PrintF('d\d',mem[2]&%111)
CASE 8 TO 15; PrintF('a\d',mem[2]&%111)
CASE 16 TO 23; PrintF('fp\d',mem[2]&%111)
ENDSELECT
type:=mem[0]
nl:=mem[3]
mem+=4
IF type
PrintF(':\s',TypeStr(type))
ENDIF
IF nl
PrintF('\s',namelist)
namelist+=nl+1
ENDIF
EXITIF rcount=0 DO PrintF(')')
PrintF(',')
ENDWHILE
ENDIF
PrintF('=\d',offset)
IF CtrlC() THEN RETURN
EXITIF count=0 DO PrintF('\n\n')
PrintF(',\n\t')
ENDWHILE
IF Odd(namelist) THEN namelist++
mem:=namelist
ENDIF
IF Long(mem)="EXPR" // external function list
count:=Word(mem+4)
ml:=Long(mem+10)
nl:=Long(mem+14)
mem+=18
namelist:=mem+ml
WHILE count
count--
SELECT type:=mem[0]
CASE 11; PrintF('EPROC')
CASE 13; PrintF('LPROC')
CASE 14; PrintF('RPROC')
ENDSELECT
PrintF(' \s(',namelist)
namelist+=StrLen(namelist)+1
flags:=mem[1]
acount:=mem[2]
rcount:=mem[3]
mem+=4
offset:=0
IF flags&%01
offset:=namelist
namelist+=StrLen(namelist)+1
ENDIF
IF type=14
IF flags&%10
l:=namelist
namelist+=StrLen(namelist)+1
ENDIF
ENDIF
WHILE acount
acount--
type:=mem[0]
flags:=mem[1]
SELECT mem[3]
CASE 0 TO 7; PrintF('d\d',mem[3]&%111)
CASE 8 TO 15; PrintF('a\d',mem[3]&%111)
CASE 16 TO 23; PrintF('fp\d',mem[3]&%111)
DEFAULT; PrintF('\c',"z"-acount) // stack
ENDSELECT
mem+=4
IF flags&%01
IF type=8 // DT_DOUBLE
PrintF('=$\z\h[8].\z\h[8]',Long(mem),Long(mem+4))
mem+=8
ELSE
PrintF('=\d',Long(mem))
mem+=4
ENDIF
ENDIF
IF type
PrintF(':\s',TypeStr(type))
IF flags&%10
PrintF('\s',namelist)
namelist+=StrLen(namelist)+1
ENDIF
ENDIF
EXITIF acount=0
PrintF(',')
ENDWHILE
PrintF(')')
IF rcount
PrintF('(')
WHILE rcount
rcount--
type:=mem[0]
SELECT mem[1]
CASE 0 TO 7; PrintF('d\d',mem[1]&%111)
CASE 8 TO 15; PrintF('a\d',mem[1]&%111)
CASE 16 TO 23; PrintF('fp\d',mem[1]&%111)
ENDSELECT
mem+++
IF type THEN PrintF(':\s',TypeStr(type))
IF type>=26 AND type<=28
PrintF('\s',namelist)
namelist+=StrLen(namelist)+1
ENDIF
EXITIF rcount=0 DO PrintF(')')
PrintF(',')
ENDWHILE
ENDIF
IF offset THEN PrintF(' OF \s',offset)
IF CtrlC() THEN RETURN
PrintF('\n')
ENDWHILE
PrintF('\n')
IF Odd(namelist) THEN namelist++
mem+=nl
ENDIF
IF Long(mem)="EDEF"
PrintF('EDEF\t')
count:=Word(mem+4)
ml:=Long(mem+6)
nl:=Long(mem+10)
mem+=14
namelist:=mem+ml
WHILE count
count--
PrintF('\s',namelist)
namelist+=StrLen(namelist)+1
IF mem[0] THEN PrintF(':\s',TypeStr(mem[0]))
IF mem[1]
PrintF('\s',namelist)
namelist+=StrLen(namelist)+1
ENDIF
mem+++
EXITIF count=0 DO PrintF('\n\n')
PrintF(',\n\t\t')
ENDWHILE
mem+=nl
ENDIF
IF Long(mem)="LINK"
PrintF('OPT\t')
count:=Word(mem+4)
mem:=mem+6
WHILE count
count--
nl:=Word(mem)
mem+++
PrintF('''\s''',mem)
mem:=mem+nl
IF Odd(nl) THEN mem++
EXITIF count=0 DO PrintF('\n')
PrintF(',\n\t\t')
ENDWHILE
ENDIF
IF Long(mem)="HEAD"
nl:=Word(mem+4)
mem+=6
PrintF('OPT\tHEAD=''\s''\n',mem)
mem+=nl
IF Odd(nl) THEN mem++
ENDIF
ENDPROC
PROC LoadOBJECT(mem:PTR TO CHAR,nmem:PTR TO CHAR)(PTR TO CHAR,PTR TO CHAR)
IF mem[0]=0
PrintF('OBJECT \s',nmem)
nmem+=mem[1]+1
IF mem[2]
PrintF(' OF \s\n',nmem)
nmem+=mem[2]+1
ELSE PrintF('\n')
mem+=8
WHILE mem[0]=1
mem,nmem:=LoadOBJECT(mem,nmem)
EXITIF mem[0]<>1 DO PrintF('\n\n')
PrintF(',\n')
ENDWHILE
ELSEIF mem[0]=1
PrintF('\t\s',nmem)
nmem+=mem[1]+1
IF Word(mem+6) THEN PrintF('[\d]',Word(mem+6))
PrintF(':\s',TypeStr(mem[2]))
IF mem[5]
PrintF('\s',nmem)
nmem+=mem[5]+1
ENDIF
mem+=10
ENDIF
ENDPROC mem,nmem
PROC TypeStr(type)(PTR TO CHAR)
DEF str:PTR TO CHAR
SELECT type
CASE 1; str:='LONG'
CASE 2; str:='ULONG'
CASE 3; str:='WORD'
CASE 4; str:='UWORD'
CASE 5; str:='BYTE'
CASE 6; str:='UBYTE'
CASE 7; str:='FLOAT'
CASE 8; str:='DOUBLE'
CASE 9; str:='BOOL'
CASE 10; str:='PTR TO LONG'
CASE 11; str:='PTR TO ULONG'
CASE 12; str:='PTR TO WORD'
CASE 13; str:='PTR TO UWORD'
CASE 14; str:='PTR TO BYTE'
CASE 15; str:='PTR TO UBYTE'
CASE 16; str:='PTR TO FLOAT'
CASE 17; str:='PTR TO DOUBLE'
CASE 18; str:='PTR TO PTR TO LONG'
CASE 19; str:='PTR TO PTR TO ULONG'
CASE 20; str:='PTR TO PTR TO WORD'
CASE 21; str:='PTR TO PTR TO UWORD'
CASE 22; str:='PTR TO PTR TO BYTE'
CASE 23; str:='PTR TO PTR TO UBYTE'
CASE 24; str:='PTR TO PTR TO FLOAT'
CASE 25; str:='PTR TO PTR TO DOUBLE'
CASE 26; str:=NIL
CASE 27; str:='PTR TO '
CASE 28; str:='PTR TO PTR TO '
CASE 32; str:='PTR'
CASE 33; str:='PTR'
CASE 34; str:='LIST OF '
CASE 35; str:='LIST OF LONG'
CASE 36; str:='LIST OF ULONG'
CASE 37; str:='LIST OF WORD'
CASE 38; str:='LIST OF UWORD'
CASE 39; str:='LIST OF BYTE'
CASE 40; str:='LIST OF UBYTE'
CASE 41; str:='LIST OF FLOAT'
CASE 42; str:='LIST OF DOUBLE'
DEFAULT; str:='VOID'
ENDSELECT
ENDPROC str
MODULE 'exec/memory'
ENUM SOURCE
PROC main()
DEF rda,args=[0,0]:LONG,l,m:PTR TO CHAR,f
IF rda:=ReadArgs('SOURCE/A',args,NIL)
l:=FileLength(args[SOURCE])
IF f:=Open(args[SOURCE],OLDFILE)
IF m:=AllocMem(l+8,MEMF_PUBLIC|MEMF_CLEAR)
IF Read(f,m,l)=l
DisplayMODULE(m)
ELSE PrintFault(IOErr(),'dmod')
FreeMem(m,l+8)
ELSE PrintF('\s: not enough memory\n','dmod')
Close(f)
ELSE PrintFault(IOErr(),'dmod')
FreeArgs(rda)
ELSE PrintFault(IOErr(),'dmod')
ENDPROC