IncFile() and IncArray() macros [Updated 22-1-2009]
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
-
- Posts: 605
- Joined: Feb 18, 2006 13:30
- Location: Alexandria / Egypt
- Contact:
Yes, you'd have to change the relevant fields in the array descriptor to specify the size of each item (1 for byte, 4 in case of an integer), and how many items there are (total_file_size/item_size, must also be rounded and the buffer padded in case of uneven lengths)..toneboy wrote:No, worries.
So would there be an limitations (like extended ascii characters) in what can be stored and used in the files if each element in the array is a byte?
I tried to just change the data type in the macro from byte to integer but in running the program the result was unsuccessful.
That's what the macro did before, but it looks like something has changed in the way the compiler emits the values into asm blocks... not sure what happened exactly though.
-
- Posts: 8
- Joined: Feb 03, 2010 19:15
Looks like it would use escape sequences. It's pretty much the same as if you would do something like this in FB:
Code: Select all
Print !"\2"
Print "\2"
Sleep
Re: IncFile() and IncArray() macros [Updated 22-1-2009]
Hi,
Is there a way to make these Macro compatible with fbJPEG.bas ?
http://www.freebasic.net/forum/posting. ... =7&t=15284
Is there a way to make these Macro compatible with fbJPEG.bas ?
http://www.freebasic.net/forum/posting. ... =7&t=15284
Re: IncFile() and IncArray() macros [Updated 22-1-2009]
Who else is left on the forum who understands the code GNU ASM ?
Here's the code from the first post does not work on 64-bit compiler:
Who is able to fix the code so that he began to work with 64-bit compiler?
Here's the code from the first post does not work on 64-bit compiler:
Code: Select all
#IFNDEF __INCARRAY_BI__
#DEFINE __INCARRAY_BI__
#macro IncArray(name, filename)
#if __FUNCTION__ <> "__FB_MAINPROC__"
#error "IncArray() cannot be used within a function."
' just to avoid extra pointless errors and keep things cleaner
dim label() as ubyte
#else
extern "c"
extern name() alias #name as ubyte
end extern
asm
#IF __FB_DEBUG__
jmp .LT_END_OF_FILE_##name##_DEBUG_JMP
#ELSE
.section .data
#ENDIF
.balign 1
__##name##__start = .
.incbin filename
__##name##__len = . - __##name##__start
.long 0 ' add one null int as padding
.globl ##name
.balign 4
##name:
.int __##name##__start 'data
.int __##name##__start 'ptr
.int __##name##__len 'size
.int 1 'element_len
.int 1 'dimensions
' dimTB
.int __##name##__len 'elements
.int 0 'lbound
.int __##name##__len-1 'ubound
.LT_END_OF_FILE_##name##_DEBUG_JMP:
.section .text
.balign 16
End asm
#undef Name##size
#endif
#endmacro
#ENDIF '__INCARRAY_BI__
Who is able to fix the code so that he began to work with 64-bit compiler?
Re: IncFile() and IncArray() macros [Updated 22-1-2009]
I've recently reviewed these macros, they were not working not only on 64bis but also on the recent fbc version, still work fine on fbc 0.24
so i've done some evolution
not done the array ... i've never used it.
work on 32/64 bits on windows on 32 gas or gcc also
i was not able to use extern , so for __FB_MAINPROC__ i've used shared vars
so i've done some evolution
Code: Select all
#Macro Macro_IncCommunEx(label , file , sectionName)
dim label##_data as UByte Ptr
dim label##_size as ULong
#If __FB_DEBUG__
asm jmp .LT_END_OF_FILE_##label##_DEBUG_JMP
#Else
asm .section sectionName ' Switch to/Create the specified section
#EndIf
asm .LT_START_OF_FILE_##label##: ' Assign a label to the beginning of the file
asm __##label##__start = . ' Include the file
asm .incbin ##file
asm __##label##__len = . - __##label##__start ' Mark the end of the the file
asm .LT_END_OF_FILE_##label##:
'asm .LONG 0 'Pad it with a NULL Long (harmless, yet useful for text files)
#If __FB_DEBUG__
asm .LT_END_OF_FILE_##label##_DEBUG_JMP:
#Else
asm .section .text ' Switch back to the .text (code) section
asm .balign 16 'was asm .balign 16
#EndIf
asm .LT_SKIP_FILE_##label##:
asm mov dword ptr [label##_data] , offset .LT_START_OF_FILE_##label
asm mov dword ptr [label##_size] , offset __##label##__len
label##_ptr = label##_data
label##_len = label##_size
#EndMacro
#Macro Macro_IncFileEx(label , file , sectionName)
#ifndef __INC__##label##__DEF__
#define __INC__##label##__DEF__
#If __FUNCTION__ = "__FB_MAINPROC__"
dim shared label##_ptr as UByte Ptr
dim shared label##_len as ULong
sub Sub_Inc_##label##()
Macro_IncCommunEx( label , file , sectionName )
end sub
Sub_Inc_##label##()
#else
dim label##_ptr as UByte Ptr
dim label##_len as ULong
Macro_IncCommunEx( label , file , sectionName )
#endif
#else
#error ===> error ##label## already defined
#endif
#EndMacro
sub SubName()
Macro_IncFileEx(EXE2 , "test32.exe" , .Data)
print EXE2_len ,, EXE2_ptr
END SUB
Macro_IncFileEx(EXE , "test32.exe" , .Data)
print EXE_len ,, EXE_ptr
SubName()
SubName()
Macro_IncFileEx(EXE3 , "test32.exe" , .Data)
print EXE3_len ,, EXE3_ptr
sleep
work on 32/64 bits on windows on 32 gas or gcc also
i was not able to use extern , so for __FB_MAINPROC__ i've used shared vars
Re: IncFile() and IncArray() macros [Updated 22-1-2009]
marpon, thank you for your help!
However, I am interested in an example of exactly what I pointed out , that is with an array. In any case, you helped me a lot. I tried to correct Joshy example , and the example seems to work. You could watch it and fix errors if any? I know little about, and therefore asking for outside help.
However, I am interested in an example of exactly what I pointed out , that is with an array. In any case, you helped me a lot. I tried to correct Joshy example , and the example seems to work. You could watch it and fix errors if any? I know little about, and therefore asking for outside help.
Code: Select all
#ifndef __incany_bi__
#define __incany_bi__
#macro incany(strFile,lpAny)
dim shared as Ubyte ptr ##lpAny
dim shared as integer ##lpAny##__len__mem__
#print ##lpAny##__len__mem__
asm
.section .text
jmp .end_##lpAny
.section .data
.align 16
.start_##lpAny:
__##lpAny##__start__ = .
.incbin ##strFile
__##lpAny##__len = . - __##lpAny##__start__
.section .text
.align 16
.end_##lpAny:
lea eax, .start_##lpAny
mov dword ptr [lpAny], eax
mov dword ptr [##lpAny##__len__mem__] , offset __##lpAny##__len
end asm
#endmacro
#endif ' __incany_bi__
incany("/home/user/11.c",pBuf)
? *cast(zstring ptr ,pBuf) , pBuf__len__mem__
sleep
Re: IncFile() and IncArray() macros [Updated 22-1-2009]
VANYA, tested your code
it does work at least on win 10 32 or 64 gas or gcc
but if you ask optimization -gen gcc -O 2 or -gen gcc -O 3 it is blocked -gen gcc -O 0 or -gen gcc -O 1 it is okay
with my code even with -gen gcc -O 2 or -gen gcc -O 3 it is working why? sorry too litle competencies on asm ...
not tested on linux
it does work at least on win 10 32 or 64 gas or gcc
but if you ask optimization -gen gcc -O 2 or -gen gcc -O 3 it is blocked -gen gcc -O 0 or -gen gcc -O 1 it is okay
with my code even with -gen gcc -O 2 or -gen gcc -O 3 it is working why? sorry too litle competencies on asm ...
not tested on linux
Re: IncFile() and IncArray() macros [Updated 22-1-2009]
Okay , thanks for testing.