Page 1 of 1
Enumerate the addresses of all labels in the DataSection
Posted: Sat May 03, 2025 5:23 pm
by ZX80
Hi everyone.
My question is in the topic title. I want to avoid having to force each label to be specified, like ?Label1, ?Label2, etc., but enum them all. More precisely, get all their addresses.
Is it possible ?
Re: Enumerate the addresses of all labels in the DataSection
Posted: Sat May 03, 2025 5:32 pm
by mk-soft
Not like that...
What are you up to? I'm sure there's another solution.
Re: Enumerate the addresses of all labels in the DataSection
Posted: Sat May 03, 2025 6:19 pm
by ZX80
mk-soft, glad to see you here.
My question was born when I looked at
this topic. And yes, I think it's unprofessional (
AZJIO, I'm sorry).
I'm sure there's another solution.
Yeah, it could be one archive file. But I wonder if there is a solution to my original question ?
Re: Enumerate the addresses of all labels in the DataSection
Posted: Sat May 03, 2025 7:56 pm
by AZJIO
There was already a topic like for CatchImage(), but I didn't find it.
Here is one of the similar topics. But there were actually more answers.
Re: Enumerate the addresses of all labels in the DataSection
Posted: Sun May 04, 2025 1:12 pm
by breeze4me
In the asm backend (fasm x86, x64), similar to enumerating all of the labels, you could do something like this.
Taking AZJIO's code as an example, it could be modified to look like this.
Just make sure that the filename part is a consecutive number starting with 1. In the example below, 1 through 41.
Code: Select all
...
CompilerIf #PB_Compiler_Backend = #PB_Backend_C Or #PB_Compiler_Processor = #PB_Processor_Arm32 Or #PB_Compiler_Processor = #PB_Processor_Arm64 Or #PB_Compiler_OS <> #PB_OS_Windows
CompilerError "FASM Only !"
CompilerEndIf
Macro DQuote
"
EndMacro
Macro SetNextLabel(_next_address_ = @f)
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
!dd _next_address_
CompilerElse
!dq _next_address_
CompilerEndIf
EndMacro
Macro DataIncludeImage
!@@:
SetNextLabel()
IncludeBinary DQuote#images\MacroExpandedCount.png"
EndMacro
Macro DataIncludeImage10
DataIncludeImage
DataIncludeImage
DataIncludeImage
DataIncludeImage
DataIncludeImage
DataIncludeImage
DataIncludeImage
DataIncludeImage
DataIncludeImage
DataIncludeImage
EndMacro
;- DataSection
DataSection
p1:
DataIncludeImage10
DataIncludeImage10
DataIncludeImage10
DataIncludeImage10
DataIncludeImage
!@@:
SetNextLabel(0)
EndDataSection
Define Max, *p = ?p1
Repeat
i + 1
CatchImage(i, *p + SizeOf(Integer))
;Debug i
*p = PeekI(*p)
If PeekI(*p) = 0
Max = i
;Debug "Max " + Max
Break
EndIf
ForEver
...
id_img = Random(Max, 1)
...
Re: Enumerate the addresses of all labels in the DataSection
Posted: Sun May 04, 2025 6:42 pm
by ZX80
AZJIO,
breeze4me, thanks for your answers.
RASHAD's code is concise and simple.
This way I got a more compact notation:
Code: Select all
EnableExplicit
UsePNGImageDecoder()
Define hGUI, w, h, Counter, id_img
Define imageBuffer, img
DataSection
IncludePath "images" + #PS$
p1: :IncludeBinary "1.png"
p2: :IncludeBinary "2.png"
p3: :IncludeBinary "3.png"
p4: :IncludeBinary "4.png"
p5: :IncludeBinary "5.png"
p6: :IncludeBinary "6.png"
p7: :IncludeBinary "7.png"
p8: :IncludeBinary "8.png"
p9: :IncludeBinary "9.png"
p10: :IncludeBinary "10.png"
p11: :IncludeBinary "11.png"
p12: :IncludeBinary "12.png"
p13: :IncludeBinary "13.png"
p14: :IncludeBinary "14.png"
p15: :IncludeBinary "15.png"
p16: :IncludeBinary "16.png"
p17: :IncludeBinary "17.png"
p18: :IncludeBinary "18.png"
p19: :IncludeBinary "19.png"
p20: :IncludeBinary "20.png"
p21: :IncludeBinary "21.png"
p22: :IncludeBinary "22.png"
p23: :IncludeBinary "23.png"
p24: :IncludeBinary "24.png"
p25: :IncludeBinary "25.png"
p26: :IncludeBinary "26.png"
p27: :IncludeBinary "27.png"
p28: :IncludeBinary "28.png"
p29: :IncludeBinary "29.png"
p30: :IncludeBinary "30.png"
p31: :IncludeBinary "31.png"
p32: :IncludeBinary "32.png"
p33: :IncludeBinary "33.png"
p34: :IncludeBinary "34.png"
p35: :IncludeBinary "35.png"
p36: :IncludeBinary "36.png"
p37: :IncludeBinary "37.png"
p38: :IncludeBinary "38.png"
p39: :IncludeBinary "39.png"
p40: :IncludeBinary "40.png"
p41: :IncludeBinary "41.png"
imageBuffer:
Data.i ?p1, ?p2, ?p3, ?p4, ?p5, ?p6, ?p7, ?p8, ?p9, ?p10, ?p11, ?p12, ?p13, ?p14, ?p15, ?p16
Data.i ?p17, ?p18, ?p19, ?p20, ?p21, ?p22, ?p23, ?p24, ?p25, ?p26, ?p27, ?p28, ?p29, ?p30, ?p31, ?p32
Data.i ?p33, ?p34, ?p35, ?p36, ?p37, ?p38, ?p39, ?p40, ?p41
EndDataSection
Restore imageBuffer
For img = 1 To 41
Read.i imageBuffer
CatchImage(img, imageBuffer)
Next
Re: Enumerate the addresses of all labels in the DataSection
Posted: Mon May 05, 2025 1:42 am
by Tenaja
You can make a macro to implement zx80's code to unify individual items. It also helps so you don't have to remember to update all places at once... I can't send a sample, but I'm sure you can find one with a search.
Re: Enumerate the addresses of all labels in the DataSection
Posted: Mon May 05, 2025 3:14 am
by moricode
ZX80 wrote: Sun May 04, 2025 6:42 pm
AZJIO,
breeze4me, thanks for your answers.
RASHAD's code is concise and simple.
This way I got a more compact notation:
Code: Select all
EnableExplicit
UsePNGImageDecoder()
Define hGUI, w, h, Counter, id_img
Define imageBuffer, img
DataSection
IncludePath "images" + #PS$
p1: :IncludeBinary "1.png"
p2: :IncludeBinary "2.png"
p3: :IncludeBinary "3.png"
p4: :IncludeBinary "4.png"
p5: :IncludeBinary "5.png"
p6: :IncludeBinary "6.png"
p7: :IncludeBinary "7.png"
p8: :IncludeBinary "8.png"
p9: :IncludeBinary "9.png"
p10: :IncludeBinary "10.png"
p11: :IncludeBinary "11.png"
p12: :IncludeBinary "12.png"
p13: :IncludeBinary "13.png"
p14: :IncludeBinary "14.png"
p15: :IncludeBinary "15.png"
p16: :IncludeBinary "16.png"
p17: :IncludeBinary "17.png"
p18: :IncludeBinary "18.png"
p19: :IncludeBinary "19.png"
p20: :IncludeBinary "20.png"
p21: :IncludeBinary "21.png"
p22: :IncludeBinary "22.png"
p23: :IncludeBinary "23.png"
p24: :IncludeBinary "24.png"
p25: :IncludeBinary "25.png"
p26: :IncludeBinary "26.png"
p27: :IncludeBinary "27.png"
p28: :IncludeBinary "28.png"
p29: :IncludeBinary "29.png"
p30: :IncludeBinary "30.png"
p31: :IncludeBinary "31.png"
p32: :IncludeBinary "32.png"
p33: :IncludeBinary "33.png"
p34: :IncludeBinary "34.png"
p35: :IncludeBinary "35.png"
p36: :IncludeBinary "36.png"
p37: :IncludeBinary "37.png"
p38: :IncludeBinary "38.png"
p39: :IncludeBinary "39.png"
p40: :IncludeBinary "40.png"
p41: :IncludeBinary "41.png"
imageBuffer:
Data.i ?p1, ?p2, ?p3, ?p4, ?p5, ?p6, ?p7, ?p8, ?p9, ?p10, ?p11, ?p12, ?p13, ?p14, ?p15, ?p16
Data.i ?p17, ?p18, ?p19, ?p20, ?p21, ?p22, ?p23, ?p24, ?p25, ?p26, ?p27, ?p28, ?p29, ?p30, ?p31, ?p32
Data.i ?p33, ?p34, ?p35, ?p36, ?p37, ?p38, ?p39, ?p40, ?p41
EndDataSection
Restore imageBuffer
For img = 1 To 41
Read.i imageBuffer
CatchImage(img, imageBuffer)
Next
Do you looking for this :
Code: Select all
DataSection
IncludePath "images" + #PS$
IncludeBinary "1.png","2.png","3.png","4.png","5.png","6.png","7.png","8.png","9.png","10.png","11.png","12.png","13.png","14.png","15.png","16.png"
EndDataSection
Global A to Z
ForEach IncludeBinary
CatchImage(img, IncludeBinary)
Next
Or even better :
Code: Select all
DataSection
IncludeBinaryFolder "C:\image\*.*" ; include all files found in this folder
EndDataSection
Global A to Z
dim img(100)
ForEach #IncludeFile
CatchImage(img(i), #IncludeFile)
i+1
Next
Re: Enumerate the addresses of all labels in the DataSection
Posted: Mon May 05, 2025 2:51 pm
by breeze4me
moricode wrote: Mon May 05, 2025 3:14 am
Code: Select all
DataSection
IncludePath "images" + #PS$
IncludeBinary "1.png","2.png","3.png","4.png","5.png","6.png","7.png","8.png","9.png","10.png","11.png","12.png","13.png","14.png","15.png","16.png"
EndDataSection
Global A to Z
ForEach IncludeBinary
CatchImage(img, IncludeBinary)
Next
Or even better :
Code: Select all
DataSection
IncludeBinaryFolder "C:\image\*.*" ; include all files found in this folder
EndDataSection
Global A to Z
dim img(100)
ForEach #IncludeFile
CatchImage(img(i), #IncludeFile)
i+1
Next
Another lie from AI.
These are not PB syntax.
When writing PB code, AI sometimes doesn't seem to help at all.
Re: Enumerate the addresses of all labels in the DataSection
Posted: Mon May 05, 2025 3:24 pm
by miso
And now the AI might learn it's own invented code by browsing this

Re: Enumerate the addresses of all labels in the DataSection
Posted: Mon May 05, 2025 3:26 pm
by Michael Vogel
I did use breez4me's method from time to time (when all images need to be initialized at the program start) with no problems so far...
Code: Select all
Enumeration
;
#Progress_GreenLeft
#Progress_GreenMid
#Progress_GreenRight
#Progress_GrayLeft
#Progress_GrayMid
#Progress_GrayRight
;
EndEnumeration
UsePNGImageDecoder()
z=?ImageMem;
For i=#Progress_GreenLeft To #Progress_GrayRight
CatchImage(i,z+SizeOf(Integer));
z=PeekI(z);
Next i
Macro DataMem()
!@@:
; !dd @f 32 Bit
!dq @f; 64 Bit
:
EndMacro
DataSection
ImageMem:
DataMem() IncludeBinary "Data\BL.png"
DataMem() IncludeBinary "Data\BM.png"
DataMem() IncludeBinary "Data\BR.png"
DataMem() IncludeBinary "Data\XL.png"
DataMem() IncludeBinary "Data\XM.png"
DataMem() IncludeBinary "Data\XR.png"
!@@:
EndDataSection
Image=#Progress_GrayRight
OpenWindow(0,0,0,ImageWidth(Image),ImageHeight(Image),"")
ImageGadget(0,0,0,0,0,ImageID(Image))
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow