Page 1 of 1
What do I need MacroExpandedCount for?
Posted: Fri Mar 03, 2023 6:13 pm
by jacdelad
Hello,
I know what it does, but I don't know what I could need it for. Has anyone ever used that, and why?
Re: What do I need MacroExpandedCount for?
Posted: Fri Mar 03, 2023 6:33 pm
by skywalk
I use this to auto-generate DataSection elements:
Code: Select all
;-{ MACROS
Macro HASH
#
EndMacro
Macro DQ ; Required in Macros since leading '#' conflicts with #DQ$ constant
"
EndMacro
Macro QM ; Required in Macros
?
EndMacro
Macro PC ; Required in Macros
%
EndMacro
Macro ds_MakeLabel(Label)
QM#Label
EndMacro
Macro ENUM_RESET(n=0)
Enumeration n
EndEnumeration
EndMacro
Macro ds_PtrToLabel_Img(Label_Num)
; Create a pointer to an identical label named later.
; Enables automatically referencing the label in code since PB creates a pointer to the actual label.
nImagesToLoad = MacroExpandedCount ; Running count of images to load.
DataSection
Data.i QM#Label_Num ; ?Label_Num
EndDataSection
EndMacro
Macro ds_InclBin_Img(Label_Num, File)
DataSection
Label_Num: : IncludeBinary File
;Label_Num#Q: ;FYI; No closing label since CatchImage() determines when to stop reading.
EndDataSection
EndMacro
;-} MACROS
;-{ IMAGES:
; May also create #img_xxx constants for referencing if desired. Ex. #img_LOGOe = 3
ds_START(ds_ImagesToLoad) ;-! ds_img()
ds_PtrToLabel_Img(Image_1)
ds_PtrToLabel_Img(Image_2)
; CREATE IMAGE LIST AND LABELS. Image_0 reserved for no image.
ds_InclBin_Img(Image_1, "..\img\blah.ico")
ds_InclBin_Img(Image_2, "..\img\blah2.png")
;-} IMAGES
Re: What do I need MacroExpandedCount for?
Posted: Fri Mar 03, 2023 6:42 pm
by jacdelad
That's...very specific and very cool. Thanks for sharing! Never thought about using datasections dynamically.