#IFNDEF INCFILE_BI
#DEFINE INCFILE_BI

#MACRO IncFileEx(label, file, sectionName, attr, share)
    #IF share
            Dim Shared label As Ubyte Ptr
            Dim Shared label##_len As Uinteger
    #else
            Dim label As Ubyte Ptr
            Dim label##_len As Uinteger
    #endif
   
#IF __FB_DEBUG__
    asm    jmp .LT_END_OF_FILE_##label##_DEBUG_JMP
#ELSE
        ' Switch to/Create the specified section
        #IF attr = ""
            asm .section sectionName
        #ELSE
            asm .section sectionName, attr
        #ENDIF
#ENDIF
            ' Assign a label to the beginning of the file
    asm     .LT_START_OF_FILE_##label#:
            ' Include the file
    asm     .incbin ##file
            ' Mark the end of the the file
    asm     .LT_END_OF_FILE_##label:
            ' Pad it with a NULL Integer (harmless, yet useful for text files)
    asm     .LONG 0
            ' Switch back to the .text (code) section
#IF __FB_DEBUG__
    asm     .LT_END_OF_FILE_##label##_DEBUG_JMP:
#ELSE               
    asm     .section .text
    asm     .balign 16
#ENDIF
            'check if this was done before (if you use incfile inside a function)
    asm                mov eax, dword Ptr [label]
    asm         cmp eax, 0
    asm                jne .LT_SKIP_FILE_##label 'no need to go over this again, skip it
   
                    ' Get a pointer to the starting label
    asm     lea eax, .LT_START_OF_FILE_##label#
            ' Store it in a variable
    asm     mov dword Ptr [label], eax
            ' Get a pointer to the ending label
    asm     lea ebx, .LT_END_OF_FILE_##label
            ' Subtract them to get the total length
    asm     Sub ebx, eax
            ' move the result to another variable
    asm     mov dword Ptr [label##_len], ebx
    asm                .LT_SKIP_FILE_##label:
#ENDMACRO

#DEFINE IncFile(label, file, share) IncFileEx(label, file, .data, "", share)        'Use the .data (storage) section

#EndIf