私のHPにあるHSP2用を移植してみました。
一部、ツールを使ったので冗長になっています。
tomさんのdllが元になっています。
winwid=640
screen 0,winwid,480
sdim file,261
sdim arg,520: arg=dir_cmdline
if arg!="" { file=arg }
else {
dialog "exe;*.dll",16,"実行ファイル": if stat==0: end
file=refstr
}
exist file: flen=strsize: if flen<0: dialog file+"がありません": end
sdim buf,flen
bload file,buf
;peek c,buf,0: peek d,buf,1
c=peek(buf,0): ;peek d,buf,1
d=peek(buf,1)
if (c!='M')|(d!='Z'): dialog "実行ファイルではありません": end
;wpeek p,buf,60
p=wpeek(buf,60)
;peek c,buf,p: peek d,buf,p+1: wpeek e,buf,p+2
c=peek(buf,p): ;peek d,buf,p+1: wpeek e,buf,p+2
d=peek(buf,p+1): ;wpeek e,buf,p+2
e=wpeek(buf,p+2)
if (c!='P')|(d!='E')|(e!=0) {
dialog "このファイルのフォーマットには対応していません": end
}
;wpeek c,buf,p+140: wpeek d,buf,p+142: c+=d<<16
c=wpeek(buf,p+140): ;wpeek d,buf,p+142: c+=d<<16
d=wpeek(buf,p+142): c+=d<<16
if c<1: dialog "リソースセクションがありません": end
;wpeek vad,buf,p+136: wpeek c,buf,p+138: vad+=c<<16
vad=wpeek(buf,p+136): ;wpeek c,buf,p+138: vad+=c<<16
c=wpeek(buf,p+138): vad+=c<<16
;wpeek nsec,buf,p+6
nsec=wpeek(buf,p+6)
p+=248: i=-1
repeat nsec
;wpeek c,buf,p+12: wpeek d,buf,p+14: c+=d<<16
c=wpeek(buf,p+12): ;wpeek d,buf,p+14: c+=d<<16
d=wpeek(buf,p+14): c+=d<<16
if c==vad: i=cnt: break
p+=40
loop: if i<0: dialog "Not found ImageSectionHeader.": end
;wpeek size,buf,p+16: wpeek c,buf,p+18: size+=c<<16
size=wpeek(buf,p+16): ;wpeek c,buf,p+18: size+=c<<16
c=wpeek(buf,p+18): size+=c<<16
if size<1: dialog "リソースセクションがありません": end
;wpeek prsa,buf,p+20: wpeek c,buf,p+22: prsa+=c<<16 ;ResourceSectionAddress
prsa=wpeek(buf,p+20): ;wpeek c,buf,p+22: prsa+=c<<16 ;ResourceSectionAddress
c=wpeek(buf,p+22): prsa+=c<<16 ;ResourceSectionAddress
;wpeek nres,buf,prsa+12: wpeek c,buf,prsa+14: nres+=c
nres=wpeek(buf,prsa+12): ;wpeek c,buf,prsa+14: nres+=c
c=wpeek(buf,prsa+14): nres+=c
p=prsa+16: pi=0: pg=0
repeat nres
;wpeek c,buf,p
c=wpeek(buf,p)
if c==3 {
;wpeek d,buf,p+4: wpeek e,buf,p+6: d+=e&$7fff<<16: pi=prsa+d
d=wpeek(buf,p+4): ;wpeek e,buf,p+6: d+=e&$7fff<<16: pi=prsa+d
e=wpeek(buf,p+6): d+=(e&$7fff)<<16: pi=prsa+d
}
else { if c==14 {
;wpeek d,buf,p+4: wpeek e,buf,p+6: d+=e&$7fff<<16: pg=prsa+d
d=wpeek(buf,p+4): ;wpeek e,buf,p+6: d+=e&$7fff<<16: pg=prsa+d
e=wpeek(buf,p+6): d+=(e&$7fff)<<16: pg=prsa+d
} }
p+=8
loop
if pi {: ;wpeek num,buf,pi+12: wpeek c,buf,pi+14: num+=c
num=wpeek(buf,pi+12): ;wpeek c,buf,pi+14: num+=c
c=wpeek(buf,pi+14): num+=c
}
if (pi==0)|(pg==0)|(num<1): dialog "アイコンがありません": end
title "number="+num
repeat num
pirde=pi+16+(cnt*8) ;pImgResDirEnt
;wpeek offset,buf,pirde+4: wpeek c,buf,pirde+6: offset+=c&$7fff<<16
offset=wpeek(buf,pirde+4): ;wpeek c,buf,pirde+6: offset+=c&$7fff<<16
c=wpeek(buf,pirde+6): offset+=(c&$7fff)<<16
pirde2=prsa+offset+16 ;OffsetToDirectory
;wpeek offset2,buf,pirde2+4: wpeek c,buf,pirde2+6: offset2=c<<16|offset2
offset2=wpeek(buf,pirde2+4): ;wpeek c,buf,pirde2+6: offset2=c<<16|offset2
c=wpeek(buf,pirde2+6): offset2=(c<<16)|offset2
pDatEnt=prsa+offset2 ;OffsetToData1
;wpeek offset3,buf,pDatEnt: wpeek c,buf,pDatEnt+2: offset3+=c<<16
offset3=wpeek(buf,pDatEnt): ;wpeek c,buf,pDatEnt+2: offset3+=c<<16
c=wpeek(buf,pDatEnt+2): offset3+=c<<16
pnt=prsa+offset3-vad ;OffsetToData2
;wpeek headsize,buf,pnt: wpeek c,buf,pnt+2: headsize+=c<<16
headsize=wpeek(buf,pnt): ;wpeek c,buf,pnt+2: headsize+=c<<16
c=wpeek(buf,pnt+2): headsize+=c<<16
;wpeek wid,buf,pnt+4: wpeek c,buf,pnt+6: wid+=c<<16
wid=wpeek(buf,pnt+4): ;wpeek c,buf,pnt+6: wid+=c<<16
c=wpeek(buf,pnt+6): wid+=c<<16
;wpeek heit,buf,pnt+8: wpeek c,buf,pnt+10: heit=(heit+(c<<16))/2
heit=wpeek(buf,pnt+8): ;wpeek c,buf,pnt+10: heit=(heit+(c<<16))/2
c=wpeek(buf,pnt+10): heit=(heit+(c<<16))/2
;wpeek palnum,buf,pnt+14: palnum=1<<palnum
palnum=wpeek(buf,pnt+14): palnum=1<<palnum
if palnum==16 { xnum=wid/2 }
else { if palnum==256 { xnum=wid }
else { if palnum==2 { xnum=wid/8 }
else {
dialog ""+palnum+"色のアイコンには対応していません": continue
} } }
dim rpal,palnum: dim gpal,palnum: dim bpal,palnum
;wpeek c,buf,pnt+16: wpeek d,buf,pnt+16: c+=d<<16
c=wpeek(buf,pnt+16): ;wpeek d,buf,pnt+16: c+=d<<16
d=wpeek(buf,pnt+16): c+=d<<16
if c: dialog "圧縮形式には対応していません": continue
pp=pnt+headsize
repeat palnum
;peek bpal.cnt,buf,pp: pp++
bpal.cnt=peek(buf,pp): pp++
;peek gpal.cnt,buf,pp: pp++
gpal.cnt=peek(buf,pp): pp++
;peek rpal.cnt,buf,pp: pp++: pp++
rpal.cnt=peek(buf,pp): pp++: pp++
loop
y+=heit: pmask=xnum*heit+pp: mask=$80: ;peek dmask,buf,pmask
dmask=peek(buf,pmask)
redraw 2
repeat heit: y--
repeat xnum
;peek c,buf,pp
c=peek(buf,pp)
if palnum==16 {
if (dmask&mask)==0 {
d=c>>4: color rpal.d,gpal.d,bpal.d: pset x,y
}
x++: mask=mask>>1: c=c&15
}
else { if palnum==2 {
shift=7: bmask=$7f
repeat 7
if (dmask&mask)==0 {
d=c>>shift: color rpal.d,gpal.d,bpal.d: pset x,y
}
x++: mask=mask>>1: c=c&bmask: shift--: bmask=bmask>>1
loop
} }
if (dmask&mask)==0 {
color rpal.c,gpal.c,bpal.c: pset x,y
}
x++: pp++
mask=mask>>1: if mask==0 {: pmask++: mask=$80: ;peek dmask,buf,pmask
dmask=peek(buf,pmask) }
loop: x-=wid
loop: redraw 1: if heit>maxheit: maxheit=heit
x+=wid+4: if x+32>winwid: x=0: y+=maxheit+4: maxheit=0
loop
stop